pc300_drv.c 110 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678
  1. #define USE_PCI_CLOCK
  2. static const char rcsid[] =
  3. "Revision: 3.4.5 Date: 2002/03/07 ";
  4. /*
  5. * pc300.c Cyclades-PC300(tm) Driver.
  6. *
  7. * Author: Ivan Passos <ivan@cyclades.com>
  8. * Maintainer: PC300 Maintainer <pc300@cyclades.com>
  9. *
  10. * Copyright: (c) 1999-2003 Cyclades Corp.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version
  15. * 2 of the License, or (at your option) any later version.
  16. *
  17. * Using tabstop = 4.
  18. *
  19. * $Log: pc300_drv.c,v $
  20. * Revision 3.23 2002/03/20 13:58:40 henrique
  21. * Fixed ortographic mistakes
  22. *
  23. * Revision 3.22 2002/03/13 16:56:56 henrique
  24. * Take out the debug messages
  25. *
  26. * Revision 3.21 2002/03/07 14:17:09 henrique
  27. * License data fixed
  28. *
  29. * Revision 3.20 2002/01/17 17:58:52 ivan
  30. * Support for PC300-TE/M (PMC).
  31. *
  32. * Revision 3.19 2002/01/03 17:08:47 daniela
  33. * Enables DMA reception when the SCA-II disables it improperly.
  34. *
  35. * Revision 3.18 2001/12/03 18:47:50 daniela
  36. * Esthetic changes.
  37. *
  38. * Revision 3.17 2001/10/19 16:50:13 henrique
  39. * Patch to kernel 2.4.12 and new generic hdlc.
  40. *
  41. * Revision 3.16 2001/10/16 15:12:31 regina
  42. * clear statistics
  43. *
  44. * Revision 3.11 to 3.15 2001/10/11 20:26:04 daniela
  45. * More DMA fixes for noisy lines.
  46. * Return the size of bad frames in dma_get_rx_frame_size, so that the Rx buffer
  47. * descriptors can be cleaned by dma_buf_read (called in cpc_net_rx).
  48. * Renamed dma_start routine to rx_dma_start. Improved Rx statistics.
  49. * Fixed BOF interrupt treatment. Created dma_start routine.
  50. * Changed min and max to cpc_min and cpc_max.
  51. *
  52. * Revision 3.10 2001/08/06 12:01:51 regina
  53. * Fixed problem in DSR_DE bit.
  54. *
  55. * Revision 3.9 2001/07/18 19:27:26 daniela
  56. * Added some history comments.
  57. *
  58. * Revision 3.8 2001/07/12 13:11:19 regina
  59. * bug fix - DCD-OFF in pc300 tty driver
  60. *
  61. * Revision 3.3 to 3.7 2001/07/06 15:00:20 daniela
  62. * Removing kernel 2.4.3 and previous support.
  63. * DMA transmission bug fix.
  64. * MTU check in cpc_net_rx fixed.
  65. * Boot messages reviewed.
  66. * New configuration parameters (line code, CRC calculation and clock).
  67. *
  68. * Revision 3.2 2001/06/22 13:13:02 regina
  69. * MLPPP implementation. Changed the header of message trace to include
  70. * the device name. New format : "hdlcX[R/T]: ".
  71. * Default configuration changed.
  72. *
  73. * Revision 3.1 2001/06/15 regina
  74. * in cpc_queue_xmit, netif_stop_queue is called if don't have free descriptor
  75. * upping major version number
  76. *
  77. * Revision 1.1.1.1 2001/06/13 20:25:04 daniela
  78. * PC300 initial CVS version (3.4.0-pre1)
  79. *
  80. * Revision 3.0.1.2 2001/06/08 daniela
  81. * Did some changes in the DMA programming implementation to avoid the
  82. * occurrence of a SCA-II bug when CDA is accessed during a DMA transfer.
  83. *
  84. * Revision 3.0.1.1 2001/05/02 daniela
  85. * Added kernel 2.4.3 support.
  86. *
  87. * Revision 3.0.1.0 2001/03/13 daniela, henrique
  88. * Added Frame Relay Support.
  89. * Driver now uses HDLC generic driver to provide protocol support.
  90. *
  91. * Revision 3.0.0.8 2001/03/02 daniela
  92. * Fixed ram size detection.
  93. * Changed SIOCGPC300CONF ioctl, to give hw information to pc300util.
  94. *
  95. * Revision 3.0.0.7 2001/02/23 daniela
  96. * netif_stop_queue called before the SCA-II transmition commands in
  97. * cpc_queue_xmit, and with interrupts disabled to avoid race conditions with
  98. * transmition interrupts.
  99. * Fixed falc_check_status for Unframed E1.
  100. *
  101. * Revision 3.0.0.6 2000/12/13 daniela
  102. * Implemented pc300util support: trace, statistics, status and loopback
  103. * tests for the PC300 TE boards.
  104. *
  105. * Revision 3.0.0.5 2000/12/12 ivan
  106. * Added support for Unframed E1.
  107. * Implemented monitor mode.
  108. * Fixed DCD sensitivity on the second channel.
  109. * Driver now complies with new PCI kernel architecture.
  110. *
  111. * Revision 3.0.0.4 2000/09/28 ivan
  112. * Implemented DCD sensitivity.
  113. * Moved hardware-specific open to the end of cpc_open, to avoid race
  114. * conditions with early reception interrupts.
  115. * Included code for [request|release]_mem_region().
  116. * Changed location of pc300.h .
  117. * Minor code revision (contrib. of Jeff Garzik).
  118. *
  119. * Revision 3.0.0.3 2000/07/03 ivan
  120. * Previous bugfix for the framing errors with external clock made X21
  121. * boards stop working. This version fixes it.
  122. *
  123. * Revision 3.0.0.2 2000/06/23 ivan
  124. * Revisited cpc_queue_xmit to prevent race conditions on Tx DMA buffer
  125. * handling when Tx timeouts occur.
  126. * Revisited Rx statistics.
  127. * Fixed a bug in the SCA-II programming that would cause framing errors
  128. * when external clock was configured.
  129. *
  130. * Revision 3.0.0.1 2000/05/26 ivan
  131. * Added logic in the SCA interrupt handler so that no board can monopolize
  132. * the driver.
  133. * Request PLX I/O region, although driver doesn't use it, to avoid
  134. * problems with other drivers accessing it.
  135. *
  136. * Revision 3.0.0.0 2000/05/15 ivan
  137. * Did some changes in the DMA programming implementation to avoid the
  138. * occurrence of a SCA-II bug in the second channel.
  139. * Implemented workaround for PLX9050 bug that would cause a system lockup
  140. * in certain systems, depending on the MMIO addresses allocated to the
  141. * board.
  142. * Fixed the FALC chip programming to avoid synchronization problems in the
  143. * second channel (TE only).
  144. * Implemented a cleaner and faster Tx DMA descriptor cleanup procedure in
  145. * cpc_queue_xmit().
  146. * Changed the built-in driver implementation so that the driver can use the
  147. * general 'hdlcN' naming convention instead of proprietary device names.
  148. * Driver load messages are now device-centric, instead of board-centric.
  149. * Dynamic allocation of net_device structures.
  150. * Code is now compliant with the new module interface (module_[init|exit]).
  151. * Make use of the PCI helper functions to access PCI resources.
  152. *
  153. * Revision 2.0.0.0 2000/04/15 ivan
  154. * Added support for the PC300/TE boards (T1/FT1/E1/FE1).
  155. *
  156. * Revision 1.1.0.0 2000/02/28 ivan
  157. * Major changes in the driver architecture.
  158. * Softnet compliancy implemented.
  159. * Driver now reports physical instead of virtual memory addresses.
  160. * Added cpc_change_mtu function.
  161. *
  162. * Revision 1.0.0.0 1999/12/16 ivan
  163. * First official release.
  164. * Support for 1- and 2-channel boards (which use distinct PCI Device ID's).
  165. * Support for monolythic installation (i.e., drv built into the kernel).
  166. * X.25 additional checking when lapb_[dis]connect_request returns an error.
  167. * SCA programming now covers X.21 as well.
  168. *
  169. * Revision 0.3.1.0 1999/11/18 ivan
  170. * Made X.25 support configuration-dependent (as it depends on external
  171. * modules to work).
  172. * Changed X.25-specific function names to comply with adopted convention.
  173. * Fixed typos in X.25 functions that would cause compile errors (Daniela).
  174. * Fixed bug in ch_config that would disable interrupts on a previously
  175. * enabled channel if the other channel on the same board was enabled later.
  176. *
  177. * Revision 0.3.0.0 1999/11/16 daniela
  178. * X.25 support.
  179. *
  180. * Revision 0.2.3.0 1999/11/15 ivan
  181. * Function cpc_ch_status now provides more detailed information.
  182. * Added support for X.21 clock configuration.
  183. * Changed TNR1 setting in order to prevent Tx FIFO overaccesses by the SCA.
  184. * Now using PCI clock instead of internal oscillator clock for the SCA.
  185. *
  186. * Revision 0.2.2.0 1999/11/10 ivan
  187. * Changed the *_dma_buf_check functions so that they would print only
  188. * the useful info instead of the whole buffer descriptor bank.
  189. * Fixed bug in cpc_queue_xmit that would eventually crash the system
  190. * in case of a packet drop.
  191. * Implemented TX underrun handling.
  192. * Improved SCA fine tuning to boost up its performance.
  193. *
  194. * Revision 0.2.1.0 1999/11/03 ivan
  195. * Added functions *dma_buf_pt_init to allow independent initialization
  196. * of the next-descr. and DMA buffer pointers on the DMA descriptors.
  197. * Kernel buffer release and tbusy clearing is now done in the interrupt
  198. * handler.
  199. * Fixed bug in cpc_open that would cause an interface reopen to fail.
  200. * Added a protocol-specific code section in cpc_net_rx.
  201. * Removed printk level defs (they might be added back after the beta phase).
  202. *
  203. * Revision 0.2.0.0 1999/10/28 ivan
  204. * Revisited the code so that new protocols can be easily added / supported.
  205. *
  206. * Revision 0.1.0.1 1999/10/20 ivan
  207. * Mostly "esthetic" changes.
  208. *
  209. * Revision 0.1.0.0 1999/10/11 ivan
  210. * Initial version.
  211. *
  212. */
  213. #include <linux/module.h>
  214. #include <linux/kernel.h>
  215. #include <linux/mm.h>
  216. #include <linux/ioport.h>
  217. #include <linux/pci.h>
  218. #include <linux/errno.h>
  219. #include <linux/string.h>
  220. #include <linux/init.h>
  221. #include <linux/delay.h>
  222. #include <linux/net.h>
  223. #include <linux/skbuff.h>
  224. #include <linux/if_arp.h>
  225. #include <linux/netdevice.h>
  226. #include <linux/etherdevice.h>
  227. #include <linux/spinlock.h>
  228. #include <linux/if.h>
  229. #include <linux/slab.h>
  230. #include <net/arp.h>
  231. #include <asm/io.h>
  232. #include <asm/uaccess.h>
  233. #include "pc300.h"
  234. #define CPC_LOCK(card,flags) \
  235. do { \
  236. spin_lock_irqsave(&card->card_lock, flags); \
  237. } while (0)
  238. #define CPC_UNLOCK(card,flags) \
  239. do { \
  240. spin_unlock_irqrestore(&card->card_lock, flags); \
  241. } while (0)
  242. #undef PC300_DEBUG_PCI
  243. #undef PC300_DEBUG_INTR
  244. #undef PC300_DEBUG_TX
  245. #undef PC300_DEBUG_RX
  246. #undef PC300_DEBUG_OTHER
  247. static DEFINE_PCI_DEVICE_TABLE(cpc_pci_dev_id) = {
  248. /* PC300/RSV or PC300/X21, 2 chan */
  249. {0x120e, 0x300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0x300},
  250. /* PC300/RSV or PC300/X21, 1 chan */
  251. {0x120e, 0x301, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0x301},
  252. /* PC300/TE, 2 chan */
  253. {0x120e, 0x310, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0x310},
  254. /* PC300/TE, 1 chan */
  255. {0x120e, 0x311, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0x311},
  256. /* PC300/TE-M, 2 chan */
  257. {0x120e, 0x320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0x320},
  258. /* PC300/TE-M, 1 chan */
  259. {0x120e, 0x321, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0x321},
  260. /* End of table */
  261. {0,},
  262. };
  263. MODULE_DEVICE_TABLE(pci, cpc_pci_dev_id);
  264. #ifndef cpc_min
  265. #define cpc_min(a,b) (((a)<(b))?(a):(b))
  266. #endif
  267. #ifndef cpc_max
  268. #define cpc_max(a,b) (((a)>(b))?(a):(b))
  269. #endif
  270. /* prototypes */
  271. static void tx_dma_buf_pt_init(pc300_t *, int);
  272. static void tx_dma_buf_init(pc300_t *, int);
  273. static void rx_dma_buf_pt_init(pc300_t *, int);
  274. static void rx_dma_buf_init(pc300_t *, int);
  275. static void tx_dma_buf_check(pc300_t *, int);
  276. static void rx_dma_buf_check(pc300_t *, int);
  277. static irqreturn_t cpc_intr(int, void *);
  278. static int clock_rate_calc(u32, u32, int *);
  279. static u32 detect_ram(pc300_t *);
  280. static void plx_init(pc300_t *);
  281. static void cpc_trace(struct net_device *, struct sk_buff *, char);
  282. static int cpc_attach(struct net_device *, unsigned short, unsigned short);
  283. static int cpc_close(struct net_device *dev);
  284. #ifdef CONFIG_PC300_MLPPP
  285. void cpc_tty_init(pc300dev_t * dev);
  286. void cpc_tty_unregister_service(pc300dev_t * pc300dev);
  287. void cpc_tty_receive(pc300dev_t * pc300dev);
  288. void cpc_tty_trigger_poll(pc300dev_t * pc300dev);
  289. void cpc_tty_reset_var(void);
  290. #endif
  291. /************************/
  292. /*** DMA Routines ***/
  293. /************************/
  294. static void tx_dma_buf_pt_init(pc300_t * card, int ch)
  295. {
  296. int i;
  297. int ch_factor = ch * N_DMA_TX_BUF;
  298. volatile pcsca_bd_t __iomem *ptdescr = (card->hw.rambase
  299. + DMA_TX_BD_BASE + ch_factor * sizeof(pcsca_bd_t));
  300. for (i = 0; i < N_DMA_TX_BUF; i++, ptdescr++) {
  301. cpc_writel(&ptdescr->next, (u32)(DMA_TX_BD_BASE +
  302. (ch_factor + ((i + 1) & (N_DMA_TX_BUF - 1))) * sizeof(pcsca_bd_t)));
  303. cpc_writel(&ptdescr->ptbuf,
  304. (u32)(DMA_TX_BASE + (ch_factor + i) * BD_DEF_LEN));
  305. }
  306. }
  307. static void tx_dma_buf_init(pc300_t * card, int ch)
  308. {
  309. int i;
  310. int ch_factor = ch * N_DMA_TX_BUF;
  311. volatile pcsca_bd_t __iomem *ptdescr = (card->hw.rambase
  312. + DMA_TX_BD_BASE + ch_factor * sizeof(pcsca_bd_t));
  313. for (i = 0; i < N_DMA_TX_BUF; i++, ptdescr++) {
  314. memset_io(ptdescr, 0, sizeof(pcsca_bd_t));
  315. cpc_writew(&ptdescr->len, 0);
  316. cpc_writeb(&ptdescr->status, DST_OSB);
  317. }
  318. tx_dma_buf_pt_init(card, ch);
  319. }
  320. static void rx_dma_buf_pt_init(pc300_t * card, int ch)
  321. {
  322. int i;
  323. int ch_factor = ch * N_DMA_RX_BUF;
  324. volatile pcsca_bd_t __iomem *ptdescr = (card->hw.rambase
  325. + DMA_RX_BD_BASE + ch_factor * sizeof(pcsca_bd_t));
  326. for (i = 0; i < N_DMA_RX_BUF; i++, ptdescr++) {
  327. cpc_writel(&ptdescr->next, (u32)(DMA_RX_BD_BASE +
  328. (ch_factor + ((i + 1) & (N_DMA_RX_BUF - 1))) * sizeof(pcsca_bd_t)));
  329. cpc_writel(&ptdescr->ptbuf,
  330. (u32)(DMA_RX_BASE + (ch_factor + i) * BD_DEF_LEN));
  331. }
  332. }
  333. static void rx_dma_buf_init(pc300_t * card, int ch)
  334. {
  335. int i;
  336. int ch_factor = ch * N_DMA_RX_BUF;
  337. volatile pcsca_bd_t __iomem *ptdescr = (card->hw.rambase
  338. + DMA_RX_BD_BASE + ch_factor * sizeof(pcsca_bd_t));
  339. for (i = 0; i < N_DMA_RX_BUF; i++, ptdescr++) {
  340. memset_io(ptdescr, 0, sizeof(pcsca_bd_t));
  341. cpc_writew(&ptdescr->len, 0);
  342. cpc_writeb(&ptdescr->status, 0);
  343. }
  344. rx_dma_buf_pt_init(card, ch);
  345. }
  346. static void tx_dma_buf_check(pc300_t * card, int ch)
  347. {
  348. volatile pcsca_bd_t __iomem *ptdescr;
  349. int i;
  350. u16 first_bd = card->chan[ch].tx_first_bd;
  351. u16 next_bd = card->chan[ch].tx_next_bd;
  352. printk("#CH%d: f_bd = %d(0x%08zx), n_bd = %d(0x%08zx)\n", ch,
  353. first_bd, TX_BD_ADDR(ch, first_bd),
  354. next_bd, TX_BD_ADDR(ch, next_bd));
  355. for (i = first_bd,
  356. ptdescr = (card->hw.rambase + TX_BD_ADDR(ch, first_bd));
  357. i != ((next_bd + 1) & (N_DMA_TX_BUF - 1));
  358. i = (i + 1) & (N_DMA_TX_BUF - 1),
  359. ptdescr = (card->hw.rambase + TX_BD_ADDR(ch, i))) {
  360. printk("\n CH%d TX%d: next=0x%x, ptbuf=0x%x, ST=0x%x, len=%d",
  361. ch, i, cpc_readl(&ptdescr->next),
  362. cpc_readl(&ptdescr->ptbuf),
  363. cpc_readb(&ptdescr->status), cpc_readw(&ptdescr->len));
  364. }
  365. printk("\n");
  366. }
  367. #ifdef PC300_DEBUG_OTHER
  368. /* Show all TX buffer descriptors */
  369. static void tx1_dma_buf_check(pc300_t * card, int ch)
  370. {
  371. volatile pcsca_bd_t __iomem *ptdescr;
  372. int i;
  373. u16 first_bd = card->chan[ch].tx_first_bd;
  374. u16 next_bd = card->chan[ch].tx_next_bd;
  375. u32 scabase = card->hw.scabase;
  376. printk ("\nnfree_tx_bd = %d\n", card->chan[ch].nfree_tx_bd);
  377. printk("#CH%d: f_bd = %d(0x%08x), n_bd = %d(0x%08x)\n", ch,
  378. first_bd, TX_BD_ADDR(ch, first_bd),
  379. next_bd, TX_BD_ADDR(ch, next_bd));
  380. printk("TX_CDA=0x%08x, TX_EDA=0x%08x\n",
  381. cpc_readl(scabase + DTX_REG(CDAL, ch)),
  382. cpc_readl(scabase + DTX_REG(EDAL, ch)));
  383. for (i = 0; i < N_DMA_TX_BUF; i++) {
  384. ptdescr = (card->hw.rambase + TX_BD_ADDR(ch, i));
  385. printk("\n CH%d TX%d: next=0x%x, ptbuf=0x%x, ST=0x%x, len=%d",
  386. ch, i, cpc_readl(&ptdescr->next),
  387. cpc_readl(&ptdescr->ptbuf),
  388. cpc_readb(&ptdescr->status), cpc_readw(&ptdescr->len));
  389. }
  390. printk("\n");
  391. }
  392. #endif
  393. static void rx_dma_buf_check(pc300_t * card, int ch)
  394. {
  395. volatile pcsca_bd_t __iomem *ptdescr;
  396. int i;
  397. u16 first_bd = card->chan[ch].rx_first_bd;
  398. u16 last_bd = card->chan[ch].rx_last_bd;
  399. int ch_factor;
  400. ch_factor = ch * N_DMA_RX_BUF;
  401. printk("#CH%d: f_bd = %d, l_bd = %d\n", ch, first_bd, last_bd);
  402. for (i = 0, ptdescr = (card->hw.rambase +
  403. DMA_RX_BD_BASE + ch_factor * sizeof(pcsca_bd_t));
  404. i < N_DMA_RX_BUF; i++, ptdescr++) {
  405. if (cpc_readb(&ptdescr->status) & DST_OSB)
  406. printk ("\n CH%d RX%d: next=0x%x, ptbuf=0x%x, ST=0x%x, len=%d",
  407. ch, i, cpc_readl(&ptdescr->next),
  408. cpc_readl(&ptdescr->ptbuf),
  409. cpc_readb(&ptdescr->status),
  410. cpc_readw(&ptdescr->len));
  411. }
  412. printk("\n");
  413. }
  414. static int dma_get_rx_frame_size(pc300_t * card, int ch)
  415. {
  416. volatile pcsca_bd_t __iomem *ptdescr;
  417. u16 first_bd = card->chan[ch].rx_first_bd;
  418. int rcvd = 0;
  419. volatile u8 status;
  420. ptdescr = (card->hw.rambase + RX_BD_ADDR(ch, first_bd));
  421. while ((status = cpc_readb(&ptdescr->status)) & DST_OSB) {
  422. rcvd += cpc_readw(&ptdescr->len);
  423. first_bd = (first_bd + 1) & (N_DMA_RX_BUF - 1);
  424. if ((status & DST_EOM) || (first_bd == card->chan[ch].rx_last_bd)) {
  425. /* Return the size of a good frame or incomplete bad frame
  426. * (dma_buf_read will clean the buffer descriptors in this case). */
  427. return rcvd;
  428. }
  429. ptdescr = (card->hw.rambase + cpc_readl(&ptdescr->next));
  430. }
  431. return -1;
  432. }
  433. /*
  434. * dma_buf_write: writes a frame to the Tx DMA buffers
  435. * NOTE: this function writes one frame at a time.
  436. */
  437. static int dma_buf_write(pc300_t *card, int ch, u8 *ptdata, int len)
  438. {
  439. int i, nchar;
  440. volatile pcsca_bd_t __iomem *ptdescr;
  441. int tosend = len;
  442. u8 nbuf = ((len - 1) / BD_DEF_LEN) + 1;
  443. if (nbuf >= card->chan[ch].nfree_tx_bd) {
  444. return -ENOMEM;
  445. }
  446. for (i = 0; i < nbuf; i++) {
  447. ptdescr = (card->hw.rambase +
  448. TX_BD_ADDR(ch, card->chan[ch].tx_next_bd));
  449. nchar = cpc_min(BD_DEF_LEN, tosend);
  450. if (cpc_readb(&ptdescr->status) & DST_OSB) {
  451. memcpy_toio((card->hw.rambase + cpc_readl(&ptdescr->ptbuf)),
  452. &ptdata[len - tosend], nchar);
  453. cpc_writew(&ptdescr->len, nchar);
  454. card->chan[ch].nfree_tx_bd--;
  455. if ((i + 1) == nbuf) {
  456. /* This must be the last BD to be used */
  457. cpc_writeb(&ptdescr->status, DST_EOM);
  458. } else {
  459. cpc_writeb(&ptdescr->status, 0);
  460. }
  461. } else {
  462. return -ENOMEM;
  463. }
  464. tosend -= nchar;
  465. card->chan[ch].tx_next_bd =
  466. (card->chan[ch].tx_next_bd + 1) & (N_DMA_TX_BUF - 1);
  467. }
  468. /* If it gets to here, it means we have sent the whole frame */
  469. return 0;
  470. }
  471. /*
  472. * dma_buf_read: reads a frame from the Rx DMA buffers
  473. * NOTE: this function reads one frame at a time.
  474. */
  475. static int dma_buf_read(pc300_t * card, int ch, struct sk_buff *skb)
  476. {
  477. int nchar;
  478. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  479. volatile pcsca_bd_t __iomem *ptdescr;
  480. int rcvd = 0;
  481. volatile u8 status;
  482. ptdescr = (card->hw.rambase +
  483. RX_BD_ADDR(ch, chan->rx_first_bd));
  484. while ((status = cpc_readb(&ptdescr->status)) & DST_OSB) {
  485. nchar = cpc_readw(&ptdescr->len);
  486. if ((status & (DST_OVR | DST_CRC | DST_RBIT | DST_SHRT | DST_ABT)) ||
  487. (nchar > BD_DEF_LEN)) {
  488. if (nchar > BD_DEF_LEN)
  489. status |= DST_RBIT;
  490. rcvd = -status;
  491. /* Discard remaining descriptors used by the bad frame */
  492. while (chan->rx_first_bd != chan->rx_last_bd) {
  493. cpc_writeb(&ptdescr->status, 0);
  494. chan->rx_first_bd = (chan->rx_first_bd+1) & (N_DMA_RX_BUF-1);
  495. if (status & DST_EOM)
  496. break;
  497. ptdescr = (card->hw.rambase +
  498. cpc_readl(&ptdescr->next));
  499. status = cpc_readb(&ptdescr->status);
  500. }
  501. break;
  502. }
  503. if (nchar != 0) {
  504. if (skb) {
  505. memcpy_fromio(skb_put(skb, nchar),
  506. (card->hw.rambase+cpc_readl(&ptdescr->ptbuf)),nchar);
  507. }
  508. rcvd += nchar;
  509. }
  510. cpc_writeb(&ptdescr->status, 0);
  511. cpc_writeb(&ptdescr->len, 0);
  512. chan->rx_first_bd = (chan->rx_first_bd + 1) & (N_DMA_RX_BUF - 1);
  513. if (status & DST_EOM)
  514. break;
  515. ptdescr = (card->hw.rambase + cpc_readl(&ptdescr->next));
  516. }
  517. if (rcvd != 0) {
  518. /* Update pointer */
  519. chan->rx_last_bd = (chan->rx_first_bd - 1) & (N_DMA_RX_BUF - 1);
  520. /* Update EDA */
  521. cpc_writel(card->hw.scabase + DRX_REG(EDAL, ch),
  522. RX_BD_ADDR(ch, chan->rx_last_bd));
  523. }
  524. return rcvd;
  525. }
  526. static void tx_dma_stop(pc300_t * card, int ch)
  527. {
  528. void __iomem *scabase = card->hw.scabase;
  529. u8 drr_ena_bit = 1 << (5 + 2 * ch);
  530. u8 drr_rst_bit = 1 << (1 + 2 * ch);
  531. /* Disable DMA */
  532. cpc_writeb(scabase + DRR, drr_ena_bit);
  533. cpc_writeb(scabase + DRR, drr_rst_bit & ~drr_ena_bit);
  534. }
  535. static void rx_dma_stop(pc300_t * card, int ch)
  536. {
  537. void __iomem *scabase = card->hw.scabase;
  538. u8 drr_ena_bit = 1 << (4 + 2 * ch);
  539. u8 drr_rst_bit = 1 << (2 * ch);
  540. /* Disable DMA */
  541. cpc_writeb(scabase + DRR, drr_ena_bit);
  542. cpc_writeb(scabase + DRR, drr_rst_bit & ~drr_ena_bit);
  543. }
  544. static void rx_dma_start(pc300_t * card, int ch)
  545. {
  546. void __iomem *scabase = card->hw.scabase;
  547. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  548. /* Start DMA */
  549. cpc_writel(scabase + DRX_REG(CDAL, ch),
  550. RX_BD_ADDR(ch, chan->rx_first_bd));
  551. if (cpc_readl(scabase + DRX_REG(CDAL,ch)) !=
  552. RX_BD_ADDR(ch, chan->rx_first_bd)) {
  553. cpc_writel(scabase + DRX_REG(CDAL, ch),
  554. RX_BD_ADDR(ch, chan->rx_first_bd));
  555. }
  556. cpc_writel(scabase + DRX_REG(EDAL, ch),
  557. RX_BD_ADDR(ch, chan->rx_last_bd));
  558. cpc_writew(scabase + DRX_REG(BFLL, ch), BD_DEF_LEN);
  559. cpc_writeb(scabase + DSR_RX(ch), DSR_DE);
  560. if (!(cpc_readb(scabase + DSR_RX(ch)) & DSR_DE)) {
  561. cpc_writeb(scabase + DSR_RX(ch), DSR_DE);
  562. }
  563. }
  564. /*************************/
  565. /*** FALC Routines ***/
  566. /*************************/
  567. static void falc_issue_cmd(pc300_t *card, int ch, u8 cmd)
  568. {
  569. void __iomem *falcbase = card->hw.falcbase;
  570. unsigned long i = 0;
  571. while (cpc_readb(falcbase + F_REG(SIS, ch)) & SIS_CEC) {
  572. if (i++ >= PC300_FALC_MAXLOOP) {
  573. printk("%s: FALC command locked(cmd=0x%x).\n",
  574. card->chan[ch].d.name, cmd);
  575. break;
  576. }
  577. }
  578. cpc_writeb(falcbase + F_REG(CMDR, ch), cmd);
  579. }
  580. static void falc_intr_enable(pc300_t * card, int ch)
  581. {
  582. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  583. pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
  584. falc_t *pfalc = (falc_t *) & chan->falc;
  585. void __iomem *falcbase = card->hw.falcbase;
  586. /* Interrupt pins are open-drain */
  587. cpc_writeb(falcbase + F_REG(IPC, ch),
  588. cpc_readb(falcbase + F_REG(IPC, ch)) & ~IPC_IC0);
  589. /* Conters updated each second */
  590. cpc_writeb(falcbase + F_REG(FMR1, ch),
  591. cpc_readb(falcbase + F_REG(FMR1, ch)) | FMR1_ECM);
  592. /* Enable SEC and ES interrupts */
  593. cpc_writeb(falcbase + F_REG(IMR3, ch),
  594. cpc_readb(falcbase + F_REG(IMR3, ch)) & ~(IMR3_SEC | IMR3_ES));
  595. if (conf->fr_mode == PC300_FR_UNFRAMED) {
  596. cpc_writeb(falcbase + F_REG(IMR4, ch),
  597. cpc_readb(falcbase + F_REG(IMR4, ch)) & ~(IMR4_LOS));
  598. } else {
  599. cpc_writeb(falcbase + F_REG(IMR4, ch),
  600. cpc_readb(falcbase + F_REG(IMR4, ch)) &
  601. ~(IMR4_LFA | IMR4_AIS | IMR4_LOS | IMR4_SLIP));
  602. }
  603. if (conf->media == IF_IFACE_T1) {
  604. cpc_writeb(falcbase + F_REG(IMR3, ch),
  605. cpc_readb(falcbase + F_REG(IMR3, ch)) & ~IMR3_LLBSC);
  606. } else {
  607. cpc_writeb(falcbase + F_REG(IPC, ch),
  608. cpc_readb(falcbase + F_REG(IPC, ch)) | IPC_SCI);
  609. if (conf->fr_mode == PC300_FR_UNFRAMED) {
  610. cpc_writeb(falcbase + F_REG(IMR2, ch),
  611. cpc_readb(falcbase + F_REG(IMR2, ch)) & ~(IMR2_LOS));
  612. } else {
  613. cpc_writeb(falcbase + F_REG(IMR2, ch),
  614. cpc_readb(falcbase + F_REG(IMR2, ch)) &
  615. ~(IMR2_FAR | IMR2_LFA | IMR2_AIS | IMR2_LOS));
  616. if (pfalc->multiframe_mode) {
  617. cpc_writeb(falcbase + F_REG(IMR2, ch),
  618. cpc_readb(falcbase + F_REG(IMR2, ch)) &
  619. ~(IMR2_T400MS | IMR2_MFAR));
  620. } else {
  621. cpc_writeb(falcbase + F_REG(IMR2, ch),
  622. cpc_readb(falcbase + F_REG(IMR2, ch)) |
  623. IMR2_T400MS | IMR2_MFAR);
  624. }
  625. }
  626. }
  627. }
  628. static void falc_open_timeslot(pc300_t * card, int ch, int timeslot)
  629. {
  630. void __iomem *falcbase = card->hw.falcbase;
  631. u8 tshf = card->chan[ch].falc.offset;
  632. cpc_writeb(falcbase + F_REG((ICB1 + (timeslot - tshf) / 8), ch),
  633. cpc_readb(falcbase + F_REG((ICB1 + (timeslot - tshf) / 8), ch)) &
  634. ~(0x80 >> ((timeslot - tshf) & 0x07)));
  635. cpc_writeb(falcbase + F_REG((TTR1 + timeslot / 8), ch),
  636. cpc_readb(falcbase + F_REG((TTR1 + timeslot / 8), ch)) |
  637. (0x80 >> (timeslot & 0x07)));
  638. cpc_writeb(falcbase + F_REG((RTR1 + timeslot / 8), ch),
  639. cpc_readb(falcbase + F_REG((RTR1 + timeslot / 8), ch)) |
  640. (0x80 >> (timeslot & 0x07)));
  641. }
  642. static void falc_close_timeslot(pc300_t * card, int ch, int timeslot)
  643. {
  644. void __iomem *falcbase = card->hw.falcbase;
  645. u8 tshf = card->chan[ch].falc.offset;
  646. cpc_writeb(falcbase + F_REG((ICB1 + (timeslot - tshf) / 8), ch),
  647. cpc_readb(falcbase + F_REG((ICB1 + (timeslot - tshf) / 8), ch)) |
  648. (0x80 >> ((timeslot - tshf) & 0x07)));
  649. cpc_writeb(falcbase + F_REG((TTR1 + timeslot / 8), ch),
  650. cpc_readb(falcbase + F_REG((TTR1 + timeslot / 8), ch)) &
  651. ~(0x80 >> (timeslot & 0x07)));
  652. cpc_writeb(falcbase + F_REG((RTR1 + timeslot / 8), ch),
  653. cpc_readb(falcbase + F_REG((RTR1 + timeslot / 8), ch)) &
  654. ~(0x80 >> (timeslot & 0x07)));
  655. }
  656. static void falc_close_all_timeslots(pc300_t * card, int ch)
  657. {
  658. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  659. pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
  660. void __iomem *falcbase = card->hw.falcbase;
  661. cpc_writeb(falcbase + F_REG(ICB1, ch), 0xff);
  662. cpc_writeb(falcbase + F_REG(TTR1, ch), 0);
  663. cpc_writeb(falcbase + F_REG(RTR1, ch), 0);
  664. cpc_writeb(falcbase + F_REG(ICB2, ch), 0xff);
  665. cpc_writeb(falcbase + F_REG(TTR2, ch), 0);
  666. cpc_writeb(falcbase + F_REG(RTR2, ch), 0);
  667. cpc_writeb(falcbase + F_REG(ICB3, ch), 0xff);
  668. cpc_writeb(falcbase + F_REG(TTR3, ch), 0);
  669. cpc_writeb(falcbase + F_REG(RTR3, ch), 0);
  670. if (conf->media == IF_IFACE_E1) {
  671. cpc_writeb(falcbase + F_REG(ICB4, ch), 0xff);
  672. cpc_writeb(falcbase + F_REG(TTR4, ch), 0);
  673. cpc_writeb(falcbase + F_REG(RTR4, ch), 0);
  674. }
  675. }
  676. static void falc_open_all_timeslots(pc300_t * card, int ch)
  677. {
  678. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  679. pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
  680. void __iomem *falcbase = card->hw.falcbase;
  681. cpc_writeb(falcbase + F_REG(ICB1, ch), 0);
  682. if (conf->fr_mode == PC300_FR_UNFRAMED) {
  683. cpc_writeb(falcbase + F_REG(TTR1, ch), 0xff);
  684. cpc_writeb(falcbase + F_REG(RTR1, ch), 0xff);
  685. } else {
  686. /* Timeslot 0 is never enabled */
  687. cpc_writeb(falcbase + F_REG(TTR1, ch), 0x7f);
  688. cpc_writeb(falcbase + F_REG(RTR1, ch), 0x7f);
  689. }
  690. cpc_writeb(falcbase + F_REG(ICB2, ch), 0);
  691. cpc_writeb(falcbase + F_REG(TTR2, ch), 0xff);
  692. cpc_writeb(falcbase + F_REG(RTR2, ch), 0xff);
  693. cpc_writeb(falcbase + F_REG(ICB3, ch), 0);
  694. cpc_writeb(falcbase + F_REG(TTR3, ch), 0xff);
  695. cpc_writeb(falcbase + F_REG(RTR3, ch), 0xff);
  696. if (conf->media == IF_IFACE_E1) {
  697. cpc_writeb(falcbase + F_REG(ICB4, ch), 0);
  698. cpc_writeb(falcbase + F_REG(TTR4, ch), 0xff);
  699. cpc_writeb(falcbase + F_REG(RTR4, ch), 0xff);
  700. } else {
  701. cpc_writeb(falcbase + F_REG(ICB4, ch), 0xff);
  702. cpc_writeb(falcbase + F_REG(TTR4, ch), 0x80);
  703. cpc_writeb(falcbase + F_REG(RTR4, ch), 0x80);
  704. }
  705. }
  706. static void falc_init_timeslot(pc300_t * card, int ch)
  707. {
  708. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  709. pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
  710. falc_t *pfalc = (falc_t *) & chan->falc;
  711. int tslot;
  712. for (tslot = 0; tslot < pfalc->num_channels; tslot++) {
  713. if (conf->tslot_bitmap & (1 << tslot)) {
  714. // Channel enabled
  715. falc_open_timeslot(card, ch, tslot + 1);
  716. } else {
  717. // Channel disabled
  718. falc_close_timeslot(card, ch, tslot + 1);
  719. }
  720. }
  721. }
  722. static void falc_enable_comm(pc300_t * card, int ch)
  723. {
  724. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  725. falc_t *pfalc = (falc_t *) & chan->falc;
  726. if (pfalc->full_bandwidth) {
  727. falc_open_all_timeslots(card, ch);
  728. } else {
  729. falc_init_timeslot(card, ch);
  730. }
  731. // CTS/DCD ON
  732. cpc_writeb(card->hw.falcbase + card->hw.cpld_reg1,
  733. cpc_readb(card->hw.falcbase + card->hw.cpld_reg1) &
  734. ~((CPLD_REG1_FALC_DCD | CPLD_REG1_FALC_CTS) << (2 * ch)));
  735. }
  736. static void falc_disable_comm(pc300_t * card, int ch)
  737. {
  738. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  739. falc_t *pfalc = (falc_t *) & chan->falc;
  740. if (pfalc->loop_active != 2) {
  741. falc_close_all_timeslots(card, ch);
  742. }
  743. // CTS/DCD OFF
  744. cpc_writeb(card->hw.falcbase + card->hw.cpld_reg1,
  745. cpc_readb(card->hw.falcbase + card->hw.cpld_reg1) |
  746. ((CPLD_REG1_FALC_DCD | CPLD_REG1_FALC_CTS) << (2 * ch)));
  747. }
  748. static void falc_init_t1(pc300_t * card, int ch)
  749. {
  750. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  751. pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
  752. falc_t *pfalc = (falc_t *) & chan->falc;
  753. void __iomem *falcbase = card->hw.falcbase;
  754. u8 dja = (ch ? (LIM2_DJA2 | LIM2_DJA1) : 0);
  755. /* Switch to T1 mode (PCM 24) */
  756. cpc_writeb(falcbase + F_REG(FMR1, ch), FMR1_PMOD);
  757. /* Wait 20 us for setup */
  758. udelay(20);
  759. /* Transmit Buffer Size (1 frame) */
  760. cpc_writeb(falcbase + F_REG(SIC1, ch), SIC1_XBS0);
  761. /* Clock mode */
  762. if (conf->phys_settings.clock_type == CLOCK_INT) { /* Master mode */
  763. cpc_writeb(falcbase + F_REG(LIM0, ch),
  764. cpc_readb(falcbase + F_REG(LIM0, ch)) | LIM0_MAS);
  765. } else { /* Slave mode */
  766. cpc_writeb(falcbase + F_REG(LIM0, ch),
  767. cpc_readb(falcbase + F_REG(LIM0, ch)) & ~LIM0_MAS);
  768. cpc_writeb(falcbase + F_REG(LOOP, ch),
  769. cpc_readb(falcbase + F_REG(LOOP, ch)) & ~LOOP_RTM);
  770. }
  771. cpc_writeb(falcbase + F_REG(IPC, ch), IPC_SCI);
  772. cpc_writeb(falcbase + F_REG(FMR0, ch),
  773. cpc_readb(falcbase + F_REG(FMR0, ch)) &
  774. ~(FMR0_XC0 | FMR0_XC1 | FMR0_RC0 | FMR0_RC1));
  775. switch (conf->lcode) {
  776. case PC300_LC_AMI:
  777. cpc_writeb(falcbase + F_REG(FMR0, ch),
  778. cpc_readb(falcbase + F_REG(FMR0, ch)) |
  779. FMR0_XC1 | FMR0_RC1);
  780. /* Clear Channel register to ON for all channels */
  781. cpc_writeb(falcbase + F_REG(CCB1, ch), 0xff);
  782. cpc_writeb(falcbase + F_REG(CCB2, ch), 0xff);
  783. cpc_writeb(falcbase + F_REG(CCB3, ch), 0xff);
  784. break;
  785. case PC300_LC_B8ZS:
  786. cpc_writeb(falcbase + F_REG(FMR0, ch),
  787. cpc_readb(falcbase + F_REG(FMR0, ch)) |
  788. FMR0_XC0 | FMR0_XC1 | FMR0_RC0 | FMR0_RC1);
  789. break;
  790. case PC300_LC_NRZ:
  791. cpc_writeb(falcbase + F_REG(FMR0, ch),
  792. cpc_readb(falcbase + F_REG(FMR0, ch)) | 0x00);
  793. break;
  794. }
  795. cpc_writeb(falcbase + F_REG(LIM0, ch),
  796. cpc_readb(falcbase + F_REG(LIM0, ch)) | LIM0_ELOS);
  797. cpc_writeb(falcbase + F_REG(LIM0, ch),
  798. cpc_readb(falcbase + F_REG(LIM0, ch)) & ~(LIM0_SCL1 | LIM0_SCL0));
  799. /* Set interface mode to 2 MBPS */
  800. cpc_writeb(falcbase + F_REG(FMR1, ch),
  801. cpc_readb(falcbase + F_REG(FMR1, ch)) | FMR1_IMOD);
  802. switch (conf->fr_mode) {
  803. case PC300_FR_ESF:
  804. pfalc->multiframe_mode = 0;
  805. cpc_writeb(falcbase + F_REG(FMR4, ch),
  806. cpc_readb(falcbase + F_REG(FMR4, ch)) | FMR4_FM1);
  807. cpc_writeb(falcbase + F_REG(FMR1, ch),
  808. cpc_readb(falcbase + F_REG(FMR1, ch)) |
  809. FMR1_CRC | FMR1_EDL);
  810. cpc_writeb(falcbase + F_REG(XDL1, ch), 0);
  811. cpc_writeb(falcbase + F_REG(XDL2, ch), 0);
  812. cpc_writeb(falcbase + F_REG(XDL3, ch), 0);
  813. cpc_writeb(falcbase + F_REG(FMR0, ch),
  814. cpc_readb(falcbase + F_REG(FMR0, ch)) & ~FMR0_SRAF);
  815. cpc_writeb(falcbase + F_REG(FMR2, ch),
  816. cpc_readb(falcbase + F_REG(FMR2,ch)) | FMR2_MCSP | FMR2_SSP);
  817. break;
  818. case PC300_FR_D4:
  819. pfalc->multiframe_mode = 1;
  820. cpc_writeb(falcbase + F_REG(FMR4, ch),
  821. cpc_readb(falcbase + F_REG(FMR4, ch)) &
  822. ~(FMR4_FM1 | FMR4_FM0));
  823. cpc_writeb(falcbase + F_REG(FMR0, ch),
  824. cpc_readb(falcbase + F_REG(FMR0, ch)) | FMR0_SRAF);
  825. cpc_writeb(falcbase + F_REG(FMR2, ch),
  826. cpc_readb(falcbase + F_REG(FMR2, ch)) & ~FMR2_SSP);
  827. break;
  828. }
  829. /* Enable Automatic Resynchronization */
  830. cpc_writeb(falcbase + F_REG(FMR4, ch),
  831. cpc_readb(falcbase + F_REG(FMR4, ch)) | FMR4_AUTO);
  832. /* Transmit Automatic Remote Alarm */
  833. cpc_writeb(falcbase + F_REG(FMR2, ch),
  834. cpc_readb(falcbase + F_REG(FMR2, ch)) | FMR2_AXRA);
  835. /* Channel translation mode 1 : one to one */
  836. cpc_writeb(falcbase + F_REG(FMR1, ch),
  837. cpc_readb(falcbase + F_REG(FMR1, ch)) | FMR1_CTM);
  838. /* No signaling */
  839. cpc_writeb(falcbase + F_REG(FMR1, ch),
  840. cpc_readb(falcbase + F_REG(FMR1, ch)) & ~FMR1_SIGM);
  841. cpc_writeb(falcbase + F_REG(FMR5, ch),
  842. cpc_readb(falcbase + F_REG(FMR5, ch)) &
  843. ~(FMR5_EIBR | FMR5_SRS));
  844. cpc_writeb(falcbase + F_REG(CCR1, ch), 0);
  845. cpc_writeb(falcbase + F_REG(LIM1, ch),
  846. cpc_readb(falcbase + F_REG(LIM1, ch)) | LIM1_RIL0 | LIM1_RIL1);
  847. switch (conf->lbo) {
  848. /* Provides proper Line Build Out */
  849. case PC300_LBO_0_DB:
  850. cpc_writeb(falcbase + F_REG(LIM2, ch), (LIM2_LOS1 | dja));
  851. cpc_writeb(falcbase + F_REG(XPM0, ch), 0x5a);
  852. cpc_writeb(falcbase + F_REG(XPM1, ch), 0x8f);
  853. cpc_writeb(falcbase + F_REG(XPM2, ch), 0x20);
  854. break;
  855. case PC300_LBO_7_5_DB:
  856. cpc_writeb(falcbase + F_REG(LIM2, ch), (0x40 | LIM2_LOS1 | dja));
  857. cpc_writeb(falcbase + F_REG(XPM0, ch), 0x11);
  858. cpc_writeb(falcbase + F_REG(XPM1, ch), 0x02);
  859. cpc_writeb(falcbase + F_REG(XPM2, ch), 0x20);
  860. break;
  861. case PC300_LBO_15_DB:
  862. cpc_writeb(falcbase + F_REG(LIM2, ch), (0x80 | LIM2_LOS1 | dja));
  863. cpc_writeb(falcbase + F_REG(XPM0, ch), 0x8e);
  864. cpc_writeb(falcbase + F_REG(XPM1, ch), 0x01);
  865. cpc_writeb(falcbase + F_REG(XPM2, ch), 0x20);
  866. break;
  867. case PC300_LBO_22_5_DB:
  868. cpc_writeb(falcbase + F_REG(LIM2, ch), (0xc0 | LIM2_LOS1 | dja));
  869. cpc_writeb(falcbase + F_REG(XPM0, ch), 0x09);
  870. cpc_writeb(falcbase + F_REG(XPM1, ch), 0x01);
  871. cpc_writeb(falcbase + F_REG(XPM2, ch), 0x20);
  872. break;
  873. }
  874. /* Transmit Clock-Slot Offset */
  875. cpc_writeb(falcbase + F_REG(XC0, ch),
  876. cpc_readb(falcbase + F_REG(XC0, ch)) | 0x01);
  877. /* Transmit Time-slot Offset */
  878. cpc_writeb(falcbase + F_REG(XC1, ch), 0x3e);
  879. /* Receive Clock-Slot offset */
  880. cpc_writeb(falcbase + F_REG(RC0, ch), 0x05);
  881. /* Receive Time-slot offset */
  882. cpc_writeb(falcbase + F_REG(RC1, ch), 0x00);
  883. /* LOS Detection after 176 consecutive 0s */
  884. cpc_writeb(falcbase + F_REG(PCDR, ch), 0x0a);
  885. /* LOS Recovery after 22 ones in the time window of PCD */
  886. cpc_writeb(falcbase + F_REG(PCRR, ch), 0x15);
  887. cpc_writeb(falcbase + F_REG(IDLE, ch), 0x7f);
  888. if (conf->fr_mode == PC300_FR_ESF_JAPAN) {
  889. cpc_writeb(falcbase + F_REG(RC1, ch),
  890. cpc_readb(falcbase + F_REG(RC1, ch)) | 0x80);
  891. }
  892. falc_close_all_timeslots(card, ch);
  893. }
  894. static void falc_init_e1(pc300_t * card, int ch)
  895. {
  896. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  897. pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
  898. falc_t *pfalc = (falc_t *) & chan->falc;
  899. void __iomem *falcbase = card->hw.falcbase;
  900. u8 dja = (ch ? (LIM2_DJA2 | LIM2_DJA1) : 0);
  901. /* Switch to E1 mode (PCM 30) */
  902. cpc_writeb(falcbase + F_REG(FMR1, ch),
  903. cpc_readb(falcbase + F_REG(FMR1, ch)) & ~FMR1_PMOD);
  904. /* Clock mode */
  905. if (conf->phys_settings.clock_type == CLOCK_INT) { /* Master mode */
  906. cpc_writeb(falcbase + F_REG(LIM0, ch),
  907. cpc_readb(falcbase + F_REG(LIM0, ch)) | LIM0_MAS);
  908. } else { /* Slave mode */
  909. cpc_writeb(falcbase + F_REG(LIM0, ch),
  910. cpc_readb(falcbase + F_REG(LIM0, ch)) & ~LIM0_MAS);
  911. }
  912. cpc_writeb(falcbase + F_REG(LOOP, ch),
  913. cpc_readb(falcbase + F_REG(LOOP, ch)) & ~LOOP_SFM);
  914. cpc_writeb(falcbase + F_REG(IPC, ch), IPC_SCI);
  915. cpc_writeb(falcbase + F_REG(FMR0, ch),
  916. cpc_readb(falcbase + F_REG(FMR0, ch)) &
  917. ~(FMR0_XC0 | FMR0_XC1 | FMR0_RC0 | FMR0_RC1));
  918. switch (conf->lcode) {
  919. case PC300_LC_AMI:
  920. cpc_writeb(falcbase + F_REG(FMR0, ch),
  921. cpc_readb(falcbase + F_REG(FMR0, ch)) |
  922. FMR0_XC1 | FMR0_RC1);
  923. break;
  924. case PC300_LC_HDB3:
  925. cpc_writeb(falcbase + F_REG(FMR0, ch),
  926. cpc_readb(falcbase + F_REG(FMR0, ch)) |
  927. FMR0_XC0 | FMR0_XC1 | FMR0_RC0 | FMR0_RC1);
  928. break;
  929. case PC300_LC_NRZ:
  930. break;
  931. }
  932. cpc_writeb(falcbase + F_REG(LIM0, ch),
  933. cpc_readb(falcbase + F_REG(LIM0, ch)) & ~(LIM0_SCL1 | LIM0_SCL0));
  934. /* Set interface mode to 2 MBPS */
  935. cpc_writeb(falcbase + F_REG(FMR1, ch),
  936. cpc_readb(falcbase + F_REG(FMR1, ch)) | FMR1_IMOD);
  937. cpc_writeb(falcbase + F_REG(XPM0, ch), 0x18);
  938. cpc_writeb(falcbase + F_REG(XPM1, ch), 0x03);
  939. cpc_writeb(falcbase + F_REG(XPM2, ch), 0x00);
  940. switch (conf->fr_mode) {
  941. case PC300_FR_MF_CRC4:
  942. pfalc->multiframe_mode = 1;
  943. cpc_writeb(falcbase + F_REG(FMR1, ch),
  944. cpc_readb(falcbase + F_REG(FMR1, ch)) | FMR1_XFS);
  945. cpc_writeb(falcbase + F_REG(FMR2, ch),
  946. cpc_readb(falcbase + F_REG(FMR2, ch)) | FMR2_RFS1);
  947. cpc_writeb(falcbase + F_REG(FMR2, ch),
  948. cpc_readb(falcbase + F_REG(FMR2, ch)) & ~FMR2_RFS0);
  949. cpc_writeb(falcbase + F_REG(FMR3, ch),
  950. cpc_readb(falcbase + F_REG(FMR3, ch)) & ~FMR3_EXTIW);
  951. /* MultiFrame Resynchronization */
  952. cpc_writeb(falcbase + F_REG(FMR1, ch),
  953. cpc_readb(falcbase + F_REG(FMR1, ch)) | FMR1_MFCS);
  954. /* Automatic Loss of Multiframe > 914 CRC errors */
  955. cpc_writeb(falcbase + F_REG(FMR2, ch),
  956. cpc_readb(falcbase + F_REG(FMR2, ch)) | FMR2_ALMF);
  957. /* S1 and SI1/SI2 spare Bits set to 1 */
  958. cpc_writeb(falcbase + F_REG(XSP, ch),
  959. cpc_readb(falcbase + F_REG(XSP, ch)) & ~XSP_AXS);
  960. cpc_writeb(falcbase + F_REG(XSP, ch),
  961. cpc_readb(falcbase + F_REG(XSP, ch)) | XSP_EBP);
  962. cpc_writeb(falcbase + F_REG(XSP, ch),
  963. cpc_readb(falcbase + F_REG(XSP, ch)) | XSP_XS13 | XSP_XS15);
  964. /* Automatic Force Resynchronization */
  965. cpc_writeb(falcbase + F_REG(FMR1, ch),
  966. cpc_readb(falcbase + F_REG(FMR1, ch)) | FMR1_AFR);
  967. /* Transmit Automatic Remote Alarm */
  968. cpc_writeb(falcbase + F_REG(FMR2, ch),
  969. cpc_readb(falcbase + F_REG(FMR2, ch)) | FMR2_AXRA);
  970. /* Transmit Spare Bits for National Use (Y, Sn, Sa) */
  971. cpc_writeb(falcbase + F_REG(XSW, ch),
  972. cpc_readb(falcbase + F_REG(XSW, ch)) |
  973. XSW_XY0 | XSW_XY1 | XSW_XY2 | XSW_XY3 | XSW_XY4);
  974. break;
  975. case PC300_FR_MF_NON_CRC4:
  976. case PC300_FR_D4:
  977. pfalc->multiframe_mode = 0;
  978. cpc_writeb(falcbase + F_REG(FMR1, ch),
  979. cpc_readb(falcbase + F_REG(FMR1, ch)) & ~FMR1_XFS);
  980. cpc_writeb(falcbase + F_REG(FMR2, ch),
  981. cpc_readb(falcbase + F_REG(FMR2, ch)) &
  982. ~(FMR2_RFS1 | FMR2_RFS0));
  983. cpc_writeb(falcbase + F_REG(XSW, ch),
  984. cpc_readb(falcbase + F_REG(XSW, ch)) | XSW_XSIS);
  985. cpc_writeb(falcbase + F_REG(XSP, ch),
  986. cpc_readb(falcbase + F_REG(XSP, ch)) | XSP_XSIF);
  987. /* Automatic Force Resynchronization */
  988. cpc_writeb(falcbase + F_REG(FMR1, ch),
  989. cpc_readb(falcbase + F_REG(FMR1, ch)) | FMR1_AFR);
  990. /* Transmit Automatic Remote Alarm */
  991. cpc_writeb(falcbase + F_REG(FMR2, ch),
  992. cpc_readb(falcbase + F_REG(FMR2, ch)) | FMR2_AXRA);
  993. /* Transmit Spare Bits for National Use (Y, Sn, Sa) */
  994. cpc_writeb(falcbase + F_REG(XSW, ch),
  995. cpc_readb(falcbase + F_REG(XSW, ch)) |
  996. XSW_XY0 | XSW_XY1 | XSW_XY2 | XSW_XY3 | XSW_XY4);
  997. break;
  998. case PC300_FR_UNFRAMED:
  999. pfalc->multiframe_mode = 0;
  1000. cpc_writeb(falcbase + F_REG(FMR1, ch),
  1001. cpc_readb(falcbase + F_REG(FMR1, ch)) & ~FMR1_XFS);
  1002. cpc_writeb(falcbase + F_REG(FMR2, ch),
  1003. cpc_readb(falcbase + F_REG(FMR2, ch)) &
  1004. ~(FMR2_RFS1 | FMR2_RFS0));
  1005. cpc_writeb(falcbase + F_REG(XSP, ch),
  1006. cpc_readb(falcbase + F_REG(XSP, ch)) | XSP_TT0);
  1007. cpc_writeb(falcbase + F_REG(XSW, ch),
  1008. cpc_readb(falcbase + F_REG(XSW, ch)) &
  1009. ~(XSW_XTM|XSW_XY0|XSW_XY1|XSW_XY2|XSW_XY3|XSW_XY4));
  1010. cpc_writeb(falcbase + F_REG(TSWM, ch), 0xff);
  1011. cpc_writeb(falcbase + F_REG(FMR2, ch),
  1012. cpc_readb(falcbase + F_REG(FMR2, ch)) |
  1013. (FMR2_RTM | FMR2_DAIS));
  1014. cpc_writeb(falcbase + F_REG(FMR2, ch),
  1015. cpc_readb(falcbase + F_REG(FMR2, ch)) & ~FMR2_AXRA);
  1016. cpc_writeb(falcbase + F_REG(FMR1, ch),
  1017. cpc_readb(falcbase + F_REG(FMR1, ch)) & ~FMR1_AFR);
  1018. pfalc->sync = 1;
  1019. cpc_writeb(falcbase + card->hw.cpld_reg2,
  1020. cpc_readb(falcbase + card->hw.cpld_reg2) |
  1021. (CPLD_REG2_FALC_LED2 << (2 * ch)));
  1022. break;
  1023. }
  1024. /* No signaling */
  1025. cpc_writeb(falcbase + F_REG(XSP, ch),
  1026. cpc_readb(falcbase + F_REG(XSP, ch)) & ~XSP_CASEN);
  1027. cpc_writeb(falcbase + F_REG(CCR1, ch), 0);
  1028. cpc_writeb(falcbase + F_REG(LIM1, ch),
  1029. cpc_readb(falcbase + F_REG(LIM1, ch)) | LIM1_RIL0 | LIM1_RIL1);
  1030. cpc_writeb(falcbase + F_REG(LIM2, ch), (LIM2_LOS1 | dja));
  1031. /* Transmit Clock-Slot Offset */
  1032. cpc_writeb(falcbase + F_REG(XC0, ch),
  1033. cpc_readb(falcbase + F_REG(XC0, ch)) | 0x01);
  1034. /* Transmit Time-slot Offset */
  1035. cpc_writeb(falcbase + F_REG(XC1, ch), 0x3e);
  1036. /* Receive Clock-Slot offset */
  1037. cpc_writeb(falcbase + F_REG(RC0, ch), 0x05);
  1038. /* Receive Time-slot offset */
  1039. cpc_writeb(falcbase + F_REG(RC1, ch), 0x00);
  1040. /* LOS Detection after 176 consecutive 0s */
  1041. cpc_writeb(falcbase + F_REG(PCDR, ch), 0x0a);
  1042. /* LOS Recovery after 22 ones in the time window of PCD */
  1043. cpc_writeb(falcbase + F_REG(PCRR, ch), 0x15);
  1044. cpc_writeb(falcbase + F_REG(IDLE, ch), 0x7f);
  1045. falc_close_all_timeslots(card, ch);
  1046. }
  1047. static void falc_init_hdlc(pc300_t * card, int ch)
  1048. {
  1049. void __iomem *falcbase = card->hw.falcbase;
  1050. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  1051. pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
  1052. /* Enable transparent data transfer */
  1053. if (conf->fr_mode == PC300_FR_UNFRAMED) {
  1054. cpc_writeb(falcbase + F_REG(MODE, ch), 0);
  1055. } else {
  1056. cpc_writeb(falcbase + F_REG(MODE, ch),
  1057. cpc_readb(falcbase + F_REG(MODE, ch)) |
  1058. (MODE_HRAC | MODE_MDS2));
  1059. cpc_writeb(falcbase + F_REG(RAH2, ch), 0xff);
  1060. cpc_writeb(falcbase + F_REG(RAH1, ch), 0xff);
  1061. cpc_writeb(falcbase + F_REG(RAL2, ch), 0xff);
  1062. cpc_writeb(falcbase + F_REG(RAL1, ch), 0xff);
  1063. }
  1064. /* Tx/Rx reset */
  1065. falc_issue_cmd(card, ch, CMDR_RRES | CMDR_XRES | CMDR_SRES);
  1066. /* Enable interrupt sources */
  1067. falc_intr_enable(card, ch);
  1068. }
  1069. static void te_config(pc300_t * card, int ch)
  1070. {
  1071. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  1072. pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
  1073. falc_t *pfalc = (falc_t *) & chan->falc;
  1074. void __iomem *falcbase = card->hw.falcbase;
  1075. u8 dummy;
  1076. unsigned long flags;
  1077. memset(pfalc, 0, sizeof(falc_t));
  1078. switch (conf->media) {
  1079. case IF_IFACE_T1:
  1080. pfalc->num_channels = NUM_OF_T1_CHANNELS;
  1081. pfalc->offset = 1;
  1082. break;
  1083. case IF_IFACE_E1:
  1084. pfalc->num_channels = NUM_OF_E1_CHANNELS;
  1085. pfalc->offset = 0;
  1086. break;
  1087. }
  1088. if (conf->tslot_bitmap == 0xffffffffUL)
  1089. pfalc->full_bandwidth = 1;
  1090. else
  1091. pfalc->full_bandwidth = 0;
  1092. CPC_LOCK(card, flags);
  1093. /* Reset the FALC chip */
  1094. cpc_writeb(card->hw.falcbase + card->hw.cpld_reg1,
  1095. cpc_readb(card->hw.falcbase + card->hw.cpld_reg1) |
  1096. (CPLD_REG1_FALC_RESET << (2 * ch)));
  1097. udelay(10000);
  1098. cpc_writeb(card->hw.falcbase + card->hw.cpld_reg1,
  1099. cpc_readb(card->hw.falcbase + card->hw.cpld_reg1) &
  1100. ~(CPLD_REG1_FALC_RESET << (2 * ch)));
  1101. if (conf->media == IF_IFACE_T1) {
  1102. falc_init_t1(card, ch);
  1103. } else {
  1104. falc_init_e1(card, ch);
  1105. }
  1106. falc_init_hdlc(card, ch);
  1107. if (conf->rx_sens == PC300_RX_SENS_SH) {
  1108. cpc_writeb(falcbase + F_REG(LIM0, ch),
  1109. cpc_readb(falcbase + F_REG(LIM0, ch)) & ~LIM0_EQON);
  1110. } else {
  1111. cpc_writeb(falcbase + F_REG(LIM0, ch),
  1112. cpc_readb(falcbase + F_REG(LIM0, ch)) | LIM0_EQON);
  1113. }
  1114. cpc_writeb(card->hw.falcbase + card->hw.cpld_reg2,
  1115. cpc_readb(card->hw.falcbase + card->hw.cpld_reg2) |
  1116. ((CPLD_REG2_FALC_TX_CLK | CPLD_REG2_FALC_RX_CLK) << (2 * ch)));
  1117. /* Clear all interrupt registers */
  1118. dummy = cpc_readb(falcbase + F_REG(FISR0, ch)) +
  1119. cpc_readb(falcbase + F_REG(FISR1, ch)) +
  1120. cpc_readb(falcbase + F_REG(FISR2, ch)) +
  1121. cpc_readb(falcbase + F_REG(FISR3, ch));
  1122. CPC_UNLOCK(card, flags);
  1123. }
  1124. static void falc_check_status(pc300_t * card, int ch, unsigned char frs0)
  1125. {
  1126. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  1127. pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
  1128. falc_t *pfalc = (falc_t *) & chan->falc;
  1129. void __iomem *falcbase = card->hw.falcbase;
  1130. /* Verify LOS */
  1131. if (frs0 & FRS0_LOS) {
  1132. if (!pfalc->red_alarm) {
  1133. pfalc->red_alarm = 1;
  1134. pfalc->los++;
  1135. if (!pfalc->blue_alarm) {
  1136. // EVENT_FALC_ABNORMAL
  1137. if (conf->media == IF_IFACE_T1) {
  1138. /* Disable this interrupt as it may otherwise interfere
  1139. * with other working boards. */
  1140. cpc_writeb(falcbase + F_REG(IMR0, ch),
  1141. cpc_readb(falcbase + F_REG(IMR0, ch))
  1142. | IMR0_PDEN);
  1143. }
  1144. falc_disable_comm(card, ch);
  1145. // EVENT_FALC_ABNORMAL
  1146. }
  1147. }
  1148. } else {
  1149. if (pfalc->red_alarm) {
  1150. pfalc->red_alarm = 0;
  1151. pfalc->losr++;
  1152. }
  1153. }
  1154. if (conf->fr_mode != PC300_FR_UNFRAMED) {
  1155. /* Verify AIS alarm */
  1156. if (frs0 & FRS0_AIS) {
  1157. if (!pfalc->blue_alarm) {
  1158. pfalc->blue_alarm = 1;
  1159. pfalc->ais++;
  1160. // EVENT_AIS
  1161. if (conf->media == IF_IFACE_T1) {
  1162. /* Disable this interrupt as it may otherwise interfere with other working boards. */
  1163. cpc_writeb(falcbase + F_REG(IMR0, ch),
  1164. cpc_readb(falcbase + F_REG(IMR0, ch)) | IMR0_PDEN);
  1165. }
  1166. falc_disable_comm(card, ch);
  1167. // EVENT_AIS
  1168. }
  1169. } else {
  1170. pfalc->blue_alarm = 0;
  1171. }
  1172. /* Verify LFA */
  1173. if (frs0 & FRS0_LFA) {
  1174. if (!pfalc->loss_fa) {
  1175. pfalc->loss_fa = 1;
  1176. pfalc->lfa++;
  1177. if (!pfalc->blue_alarm && !pfalc->red_alarm) {
  1178. // EVENT_FALC_ABNORMAL
  1179. if (conf->media == IF_IFACE_T1) {
  1180. /* Disable this interrupt as it may otherwise
  1181. * interfere with other working boards. */
  1182. cpc_writeb(falcbase + F_REG(IMR0, ch),
  1183. cpc_readb(falcbase + F_REG(IMR0, ch))
  1184. | IMR0_PDEN);
  1185. }
  1186. falc_disable_comm(card, ch);
  1187. // EVENT_FALC_ABNORMAL
  1188. }
  1189. }
  1190. } else {
  1191. if (pfalc->loss_fa) {
  1192. pfalc->loss_fa = 0;
  1193. pfalc->farec++;
  1194. }
  1195. }
  1196. /* Verify LMFA */
  1197. if (pfalc->multiframe_mode && (frs0 & FRS0_LMFA)) {
  1198. /* D4 or CRC4 frame mode */
  1199. if (!pfalc->loss_mfa) {
  1200. pfalc->loss_mfa = 1;
  1201. pfalc->lmfa++;
  1202. if (!pfalc->blue_alarm && !pfalc->red_alarm &&
  1203. !pfalc->loss_fa) {
  1204. // EVENT_FALC_ABNORMAL
  1205. if (conf->media == IF_IFACE_T1) {
  1206. /* Disable this interrupt as it may otherwise
  1207. * interfere with other working boards. */
  1208. cpc_writeb(falcbase + F_REG(IMR0, ch),
  1209. cpc_readb(falcbase + F_REG(IMR0, ch))
  1210. | IMR0_PDEN);
  1211. }
  1212. falc_disable_comm(card, ch);
  1213. // EVENT_FALC_ABNORMAL
  1214. }
  1215. }
  1216. } else {
  1217. pfalc->loss_mfa = 0;
  1218. }
  1219. /* Verify Remote Alarm */
  1220. if (frs0 & FRS0_RRA) {
  1221. if (!pfalc->yellow_alarm) {
  1222. pfalc->yellow_alarm = 1;
  1223. pfalc->rai++;
  1224. if (pfalc->sync) {
  1225. // EVENT_RAI
  1226. falc_disable_comm(card, ch);
  1227. // EVENT_RAI
  1228. }
  1229. }
  1230. } else {
  1231. pfalc->yellow_alarm = 0;
  1232. }
  1233. } /* if !PC300_UNFRAMED */
  1234. if (pfalc->red_alarm || pfalc->loss_fa ||
  1235. pfalc->loss_mfa || pfalc->blue_alarm) {
  1236. if (pfalc->sync) {
  1237. pfalc->sync = 0;
  1238. chan->d.line_off++;
  1239. cpc_writeb(falcbase + card->hw.cpld_reg2,
  1240. cpc_readb(falcbase + card->hw.cpld_reg2) &
  1241. ~(CPLD_REG2_FALC_LED2 << (2 * ch)));
  1242. }
  1243. } else {
  1244. if (!pfalc->sync) {
  1245. pfalc->sync = 1;
  1246. chan->d.line_on++;
  1247. cpc_writeb(falcbase + card->hw.cpld_reg2,
  1248. cpc_readb(falcbase + card->hw.cpld_reg2) |
  1249. (CPLD_REG2_FALC_LED2 << (2 * ch)));
  1250. }
  1251. }
  1252. if (pfalc->sync && !pfalc->yellow_alarm) {
  1253. if (!pfalc->active) {
  1254. // EVENT_FALC_NORMAL
  1255. if (pfalc->loop_active) {
  1256. return;
  1257. }
  1258. if (conf->media == IF_IFACE_T1) {
  1259. cpc_writeb(falcbase + F_REG(IMR0, ch),
  1260. cpc_readb(falcbase + F_REG(IMR0, ch)) & ~IMR0_PDEN);
  1261. }
  1262. falc_enable_comm(card, ch);
  1263. // EVENT_FALC_NORMAL
  1264. pfalc->active = 1;
  1265. }
  1266. } else {
  1267. if (pfalc->active) {
  1268. pfalc->active = 0;
  1269. }
  1270. }
  1271. }
  1272. static void falc_update_stats(pc300_t * card, int ch)
  1273. {
  1274. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  1275. pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
  1276. falc_t *pfalc = (falc_t *) & chan->falc;
  1277. void __iomem *falcbase = card->hw.falcbase;
  1278. u16 counter;
  1279. counter = cpc_readb(falcbase + F_REG(FECL, ch));
  1280. counter |= cpc_readb(falcbase + F_REG(FECH, ch)) << 8;
  1281. pfalc->fec += counter;
  1282. counter = cpc_readb(falcbase + F_REG(CVCL, ch));
  1283. counter |= cpc_readb(falcbase + F_REG(CVCH, ch)) << 8;
  1284. pfalc->cvc += counter;
  1285. counter = cpc_readb(falcbase + F_REG(CECL, ch));
  1286. counter |= cpc_readb(falcbase + F_REG(CECH, ch)) << 8;
  1287. pfalc->cec += counter;
  1288. counter = cpc_readb(falcbase + F_REG(EBCL, ch));
  1289. counter |= cpc_readb(falcbase + F_REG(EBCH, ch)) << 8;
  1290. pfalc->ebc += counter;
  1291. if (cpc_readb(falcbase + F_REG(LCR1, ch)) & LCR1_EPRM) {
  1292. mdelay(10);
  1293. counter = cpc_readb(falcbase + F_REG(BECL, ch));
  1294. counter |= cpc_readb(falcbase + F_REG(BECH, ch)) << 8;
  1295. pfalc->bec += counter;
  1296. if (((conf->media == IF_IFACE_T1) &&
  1297. (cpc_readb(falcbase + F_REG(FRS1, ch)) & FRS1_LLBAD) &&
  1298. (!(cpc_readb(falcbase + F_REG(FRS1, ch)) & FRS1_PDEN))) ||
  1299. ((conf->media == IF_IFACE_E1) &&
  1300. (cpc_readb(falcbase + F_REG(RSP, ch)) & RSP_LLBAD))) {
  1301. pfalc->prbs = 2;
  1302. } else {
  1303. pfalc->prbs = 1;
  1304. }
  1305. }
  1306. }
  1307. /*----------------------------------------------------------------------------
  1308. * falc_remote_loop
  1309. *----------------------------------------------------------------------------
  1310. * Description: In the remote loopback mode the clock and data recovered
  1311. * from the line inputs RL1/2 or RDIP/RDIN are routed back
  1312. * to the line outputs XL1/2 or XDOP/XDON via the analog
  1313. * transmitter. As in normal mode they are processed by
  1314. * the synchronizer and then sent to the system interface.
  1315. *----------------------------------------------------------------------------
  1316. */
  1317. static void falc_remote_loop(pc300_t * card, int ch, int loop_on)
  1318. {
  1319. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  1320. pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
  1321. falc_t *pfalc = (falc_t *) & chan->falc;
  1322. void __iomem *falcbase = card->hw.falcbase;
  1323. if (loop_on) {
  1324. // EVENT_FALC_ABNORMAL
  1325. if (conf->media == IF_IFACE_T1) {
  1326. /* Disable this interrupt as it may otherwise interfere with
  1327. * other working boards. */
  1328. cpc_writeb(falcbase + F_REG(IMR0, ch),
  1329. cpc_readb(falcbase + F_REG(IMR0, ch)) | IMR0_PDEN);
  1330. }
  1331. falc_disable_comm(card, ch);
  1332. // EVENT_FALC_ABNORMAL
  1333. cpc_writeb(falcbase + F_REG(LIM1, ch),
  1334. cpc_readb(falcbase + F_REG(LIM1, ch)) | LIM1_RL);
  1335. pfalc->loop_active = 1;
  1336. } else {
  1337. cpc_writeb(falcbase + F_REG(LIM1, ch),
  1338. cpc_readb(falcbase + F_REG(LIM1, ch)) & ~LIM1_RL);
  1339. pfalc->sync = 0;
  1340. cpc_writeb(falcbase + card->hw.cpld_reg2,
  1341. cpc_readb(falcbase + card->hw.cpld_reg2) &
  1342. ~(CPLD_REG2_FALC_LED2 << (2 * ch)));
  1343. pfalc->active = 0;
  1344. falc_issue_cmd(card, ch, CMDR_XRES);
  1345. pfalc->loop_active = 0;
  1346. }
  1347. }
  1348. /*----------------------------------------------------------------------------
  1349. * falc_local_loop
  1350. *----------------------------------------------------------------------------
  1351. * Description: The local loopback mode disconnects the receive lines
  1352. * RL1/RL2 resp. RDIP/RDIN from the receiver. Instead of the
  1353. * signals coming from the line the data provided by system
  1354. * interface are routed through the analog receiver back to
  1355. * the system interface. The unipolar bit stream will be
  1356. * undisturbed transmitted on the line. Receiver and transmitter
  1357. * coding must be identical.
  1358. *----------------------------------------------------------------------------
  1359. */
  1360. static void falc_local_loop(pc300_t * card, int ch, int loop_on)
  1361. {
  1362. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  1363. falc_t *pfalc = (falc_t *) & chan->falc;
  1364. void __iomem *falcbase = card->hw.falcbase;
  1365. if (loop_on) {
  1366. cpc_writeb(falcbase + F_REG(LIM0, ch),
  1367. cpc_readb(falcbase + F_REG(LIM0, ch)) | LIM0_LL);
  1368. pfalc->loop_active = 1;
  1369. } else {
  1370. cpc_writeb(falcbase + F_REG(LIM0, ch),
  1371. cpc_readb(falcbase + F_REG(LIM0, ch)) & ~LIM0_LL);
  1372. pfalc->loop_active = 0;
  1373. }
  1374. }
  1375. /*----------------------------------------------------------------------------
  1376. * falc_payload_loop
  1377. *----------------------------------------------------------------------------
  1378. * Description: This routine allows to enable/disable payload loopback.
  1379. * When the payload loop is activated, the received 192 bits
  1380. * of payload data will be looped back to the transmit
  1381. * direction. The framing bits, CRC6 and DL bits are not
  1382. * looped. They are originated by the FALC-LH transmitter.
  1383. *----------------------------------------------------------------------------
  1384. */
  1385. static void falc_payload_loop(pc300_t * card, int ch, int loop_on)
  1386. {
  1387. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  1388. pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
  1389. falc_t *pfalc = (falc_t *) & chan->falc;
  1390. void __iomem *falcbase = card->hw.falcbase;
  1391. if (loop_on) {
  1392. // EVENT_FALC_ABNORMAL
  1393. if (conf->media == IF_IFACE_T1) {
  1394. /* Disable this interrupt as it may otherwise interfere with
  1395. * other working boards. */
  1396. cpc_writeb(falcbase + F_REG(IMR0, ch),
  1397. cpc_readb(falcbase + F_REG(IMR0, ch)) | IMR0_PDEN);
  1398. }
  1399. falc_disable_comm(card, ch);
  1400. // EVENT_FALC_ABNORMAL
  1401. cpc_writeb(falcbase + F_REG(FMR2, ch),
  1402. cpc_readb(falcbase + F_REG(FMR2, ch)) | FMR2_PLB);
  1403. if (conf->media == IF_IFACE_T1) {
  1404. cpc_writeb(falcbase + F_REG(FMR4, ch),
  1405. cpc_readb(falcbase + F_REG(FMR4, ch)) | FMR4_TM);
  1406. } else {
  1407. cpc_writeb(falcbase + F_REG(FMR5, ch),
  1408. cpc_readb(falcbase + F_REG(FMR5, ch)) | XSP_TT0);
  1409. }
  1410. falc_open_all_timeslots(card, ch);
  1411. pfalc->loop_active = 2;
  1412. } else {
  1413. cpc_writeb(falcbase + F_REG(FMR2, ch),
  1414. cpc_readb(falcbase + F_REG(FMR2, ch)) & ~FMR2_PLB);
  1415. if (conf->media == IF_IFACE_T1) {
  1416. cpc_writeb(falcbase + F_REG(FMR4, ch),
  1417. cpc_readb(falcbase + F_REG(FMR4, ch)) & ~FMR4_TM);
  1418. } else {
  1419. cpc_writeb(falcbase + F_REG(FMR5, ch),
  1420. cpc_readb(falcbase + F_REG(FMR5, ch)) & ~XSP_TT0);
  1421. }
  1422. pfalc->sync = 0;
  1423. cpc_writeb(falcbase + card->hw.cpld_reg2,
  1424. cpc_readb(falcbase + card->hw.cpld_reg2) &
  1425. ~(CPLD_REG2_FALC_LED2 << (2 * ch)));
  1426. pfalc->active = 0;
  1427. falc_issue_cmd(card, ch, CMDR_XRES);
  1428. pfalc->loop_active = 0;
  1429. }
  1430. }
  1431. /*----------------------------------------------------------------------------
  1432. * turn_off_xlu
  1433. *----------------------------------------------------------------------------
  1434. * Description: Turns XLU bit off in the proper register
  1435. *----------------------------------------------------------------------------
  1436. */
  1437. static void turn_off_xlu(pc300_t * card, int ch)
  1438. {
  1439. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  1440. pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
  1441. void __iomem *falcbase = card->hw.falcbase;
  1442. if (conf->media == IF_IFACE_T1) {
  1443. cpc_writeb(falcbase + F_REG(FMR5, ch),
  1444. cpc_readb(falcbase + F_REG(FMR5, ch)) & ~FMR5_XLU);
  1445. } else {
  1446. cpc_writeb(falcbase + F_REG(FMR3, ch),
  1447. cpc_readb(falcbase + F_REG(FMR3, ch)) & ~FMR3_XLU);
  1448. }
  1449. }
  1450. /*----------------------------------------------------------------------------
  1451. * turn_off_xld
  1452. *----------------------------------------------------------------------------
  1453. * Description: Turns XLD bit off in the proper register
  1454. *----------------------------------------------------------------------------
  1455. */
  1456. static void turn_off_xld(pc300_t * card, int ch)
  1457. {
  1458. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  1459. pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
  1460. void __iomem *falcbase = card->hw.falcbase;
  1461. if (conf->media == IF_IFACE_T1) {
  1462. cpc_writeb(falcbase + F_REG(FMR5, ch),
  1463. cpc_readb(falcbase + F_REG(FMR5, ch)) & ~FMR5_XLD);
  1464. } else {
  1465. cpc_writeb(falcbase + F_REG(FMR3, ch),
  1466. cpc_readb(falcbase + F_REG(FMR3, ch)) & ~FMR3_XLD);
  1467. }
  1468. }
  1469. /*----------------------------------------------------------------------------
  1470. * falc_generate_loop_up_code
  1471. *----------------------------------------------------------------------------
  1472. * Description: This routine writes the proper FALC chip register in order
  1473. * to generate a LOOP activation code over a T1/E1 line.
  1474. *----------------------------------------------------------------------------
  1475. */
  1476. static void falc_generate_loop_up_code(pc300_t * card, int ch)
  1477. {
  1478. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  1479. pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
  1480. falc_t *pfalc = (falc_t *) & chan->falc;
  1481. void __iomem *falcbase = card->hw.falcbase;
  1482. if (conf->media == IF_IFACE_T1) {
  1483. cpc_writeb(falcbase + F_REG(FMR5, ch),
  1484. cpc_readb(falcbase + F_REG(FMR5, ch)) | FMR5_XLU);
  1485. } else {
  1486. cpc_writeb(falcbase + F_REG(FMR3, ch),
  1487. cpc_readb(falcbase + F_REG(FMR3, ch)) | FMR3_XLU);
  1488. }
  1489. // EVENT_FALC_ABNORMAL
  1490. if (conf->media == IF_IFACE_T1) {
  1491. /* Disable this interrupt as it may otherwise interfere with
  1492. * other working boards. */
  1493. cpc_writeb(falcbase + F_REG(IMR0, ch),
  1494. cpc_readb(falcbase + F_REG(IMR0, ch)) | IMR0_PDEN);
  1495. }
  1496. falc_disable_comm(card, ch);
  1497. // EVENT_FALC_ABNORMAL
  1498. pfalc->loop_gen = 1;
  1499. }
  1500. /*----------------------------------------------------------------------------
  1501. * falc_generate_loop_down_code
  1502. *----------------------------------------------------------------------------
  1503. * Description: This routine writes the proper FALC chip register in order
  1504. * to generate a LOOP deactivation code over a T1/E1 line.
  1505. *----------------------------------------------------------------------------
  1506. */
  1507. static void falc_generate_loop_down_code(pc300_t * card, int ch)
  1508. {
  1509. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  1510. pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
  1511. falc_t *pfalc = (falc_t *) & chan->falc;
  1512. void __iomem *falcbase = card->hw.falcbase;
  1513. if (conf->media == IF_IFACE_T1) {
  1514. cpc_writeb(falcbase + F_REG(FMR5, ch),
  1515. cpc_readb(falcbase + F_REG(FMR5, ch)) | FMR5_XLD);
  1516. } else {
  1517. cpc_writeb(falcbase + F_REG(FMR3, ch),
  1518. cpc_readb(falcbase + F_REG(FMR3, ch)) | FMR3_XLD);
  1519. }
  1520. pfalc->sync = 0;
  1521. cpc_writeb(falcbase + card->hw.cpld_reg2,
  1522. cpc_readb(falcbase + card->hw.cpld_reg2) &
  1523. ~(CPLD_REG2_FALC_LED2 << (2 * ch)));
  1524. pfalc->active = 0;
  1525. //? falc_issue_cmd(card, ch, CMDR_XRES);
  1526. pfalc->loop_gen = 0;
  1527. }
  1528. /*----------------------------------------------------------------------------
  1529. * falc_pattern_test
  1530. *----------------------------------------------------------------------------
  1531. * Description: This routine generates a pattern code and checks
  1532. * it on the reception side.
  1533. *----------------------------------------------------------------------------
  1534. */
  1535. static void falc_pattern_test(pc300_t * card, int ch, unsigned int activate)
  1536. {
  1537. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  1538. pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
  1539. falc_t *pfalc = (falc_t *) & chan->falc;
  1540. void __iomem *falcbase = card->hw.falcbase;
  1541. if (activate) {
  1542. pfalc->prbs = 1;
  1543. pfalc->bec = 0;
  1544. if (conf->media == IF_IFACE_T1) {
  1545. /* Disable local loop activation/deactivation detect */
  1546. cpc_writeb(falcbase + F_REG(IMR3, ch),
  1547. cpc_readb(falcbase + F_REG(IMR3, ch)) | IMR3_LLBSC);
  1548. } else {
  1549. /* Disable local loop activation/deactivation detect */
  1550. cpc_writeb(falcbase + F_REG(IMR1, ch),
  1551. cpc_readb(falcbase + F_REG(IMR1, ch)) | IMR1_LLBSC);
  1552. }
  1553. /* Activates generation and monitoring of PRBS
  1554. * (Pseudo Random Bit Sequence) */
  1555. cpc_writeb(falcbase + F_REG(LCR1, ch),
  1556. cpc_readb(falcbase + F_REG(LCR1, ch)) | LCR1_EPRM | LCR1_XPRBS);
  1557. } else {
  1558. pfalc->prbs = 0;
  1559. /* Deactivates generation and monitoring of PRBS
  1560. * (Pseudo Random Bit Sequence) */
  1561. cpc_writeb(falcbase + F_REG(LCR1, ch),
  1562. cpc_readb(falcbase+F_REG(LCR1,ch)) & ~(LCR1_EPRM | LCR1_XPRBS));
  1563. if (conf->media == IF_IFACE_T1) {
  1564. /* Enable local loop activation/deactivation detect */
  1565. cpc_writeb(falcbase + F_REG(IMR3, ch),
  1566. cpc_readb(falcbase + F_REG(IMR3, ch)) & ~IMR3_LLBSC);
  1567. } else {
  1568. /* Enable local loop activation/deactivation detect */
  1569. cpc_writeb(falcbase + F_REG(IMR1, ch),
  1570. cpc_readb(falcbase + F_REG(IMR1, ch)) & ~IMR1_LLBSC);
  1571. }
  1572. }
  1573. }
  1574. /*----------------------------------------------------------------------------
  1575. * falc_pattern_test_error
  1576. *----------------------------------------------------------------------------
  1577. * Description: This routine returns the bit error counter value
  1578. *----------------------------------------------------------------------------
  1579. */
  1580. static u16 falc_pattern_test_error(pc300_t * card, int ch)
  1581. {
  1582. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  1583. falc_t *pfalc = (falc_t *) & chan->falc;
  1584. return pfalc->bec;
  1585. }
  1586. /**********************************/
  1587. /*** Net Interface Routines ***/
  1588. /**********************************/
  1589. static void
  1590. cpc_trace(struct net_device *dev, struct sk_buff *skb_main, char rx_tx)
  1591. {
  1592. struct sk_buff *skb;
  1593. if ((skb = dev_alloc_skb(10 + skb_main->len)) == NULL) {
  1594. printk("%s: out of memory\n", dev->name);
  1595. return;
  1596. }
  1597. skb_put(skb, 10 + skb_main->len);
  1598. skb->dev = dev;
  1599. skb->protocol = htons(ETH_P_CUST);
  1600. skb_reset_mac_header(skb);
  1601. skb->pkt_type = PACKET_HOST;
  1602. skb->len = 10 + skb_main->len;
  1603. skb_copy_to_linear_data(skb, dev->name, 5);
  1604. skb->data[5] = '[';
  1605. skb->data[6] = rx_tx;
  1606. skb->data[7] = ']';
  1607. skb->data[8] = ':';
  1608. skb->data[9] = ' ';
  1609. skb_copy_from_linear_data(skb_main, &skb->data[10], skb_main->len);
  1610. netif_rx(skb);
  1611. }
  1612. static void cpc_tx_timeout(struct net_device *dev)
  1613. {
  1614. pc300dev_t *d = (pc300dev_t *) dev_to_hdlc(dev)->priv;
  1615. pc300ch_t *chan = (pc300ch_t *) d->chan;
  1616. pc300_t *card = (pc300_t *) chan->card;
  1617. int ch = chan->channel;
  1618. unsigned long flags;
  1619. u8 ilar;
  1620. dev->stats.tx_errors++;
  1621. dev->stats.tx_aborted_errors++;
  1622. CPC_LOCK(card, flags);
  1623. if ((ilar = cpc_readb(card->hw.scabase + ILAR)) != 0) {
  1624. printk("%s: ILAR=0x%x\n", dev->name, ilar);
  1625. cpc_writeb(card->hw.scabase + ILAR, ilar);
  1626. cpc_writeb(card->hw.scabase + DMER, 0x80);
  1627. }
  1628. if (card->hw.type == PC300_TE) {
  1629. cpc_writeb(card->hw.falcbase + card->hw.cpld_reg2,
  1630. cpc_readb(card->hw.falcbase + card->hw.cpld_reg2) &
  1631. ~(CPLD_REG2_FALC_LED1 << (2 * ch)));
  1632. }
  1633. dev->trans_start = jiffies; /* prevent tx timeout */
  1634. CPC_UNLOCK(card, flags);
  1635. netif_wake_queue(dev);
  1636. }
  1637. static int cpc_queue_xmit(struct sk_buff *skb, struct net_device *dev)
  1638. {
  1639. pc300dev_t *d = (pc300dev_t *) dev_to_hdlc(dev)->priv;
  1640. pc300ch_t *chan = (pc300ch_t *) d->chan;
  1641. pc300_t *card = (pc300_t *) chan->card;
  1642. int ch = chan->channel;
  1643. unsigned long flags;
  1644. #ifdef PC300_DEBUG_TX
  1645. int i;
  1646. #endif
  1647. if (!netif_carrier_ok(dev)) {
  1648. /* DCD must be OFF: drop packet */
  1649. dev_kfree_skb(skb);
  1650. dev->stats.tx_errors++;
  1651. dev->stats.tx_carrier_errors++;
  1652. return 0;
  1653. } else if (cpc_readb(card->hw.scabase + M_REG(ST3, ch)) & ST3_DCD) {
  1654. printk("%s: DCD is OFF. Going administrative down.\n", dev->name);
  1655. dev->stats.tx_errors++;
  1656. dev->stats.tx_carrier_errors++;
  1657. dev_kfree_skb(skb);
  1658. netif_carrier_off(dev);
  1659. CPC_LOCK(card, flags);
  1660. cpc_writeb(card->hw.scabase + M_REG(CMD, ch), CMD_TX_BUF_CLR);
  1661. if (card->hw.type == PC300_TE) {
  1662. cpc_writeb(card->hw.falcbase + card->hw.cpld_reg2,
  1663. cpc_readb(card->hw.falcbase + card->hw.cpld_reg2) &
  1664. ~(CPLD_REG2_FALC_LED1 << (2 * ch)));
  1665. }
  1666. CPC_UNLOCK(card, flags);
  1667. netif_wake_queue(dev);
  1668. return 0;
  1669. }
  1670. /* Write buffer to DMA buffers */
  1671. if (dma_buf_write(card, ch, (u8 *)skb->data, skb->len) != 0) {
  1672. // printk("%s: write error. Dropping TX packet.\n", dev->name);
  1673. netif_stop_queue(dev);
  1674. dev_kfree_skb(skb);
  1675. dev->stats.tx_errors++;
  1676. dev->stats.tx_dropped++;
  1677. return 0;
  1678. }
  1679. #ifdef PC300_DEBUG_TX
  1680. printk("%s T:", dev->name);
  1681. for (i = 0; i < skb->len; i++)
  1682. printk(" %02x", *(skb->data + i));
  1683. printk("\n");
  1684. #endif
  1685. if (d->trace_on) {
  1686. cpc_trace(dev, skb, 'T');
  1687. }
  1688. /* Start transmission */
  1689. CPC_LOCK(card, flags);
  1690. /* verify if it has more than one free descriptor */
  1691. if (card->chan[ch].nfree_tx_bd <= 1) {
  1692. /* don't have so stop the queue */
  1693. netif_stop_queue(dev);
  1694. }
  1695. cpc_writel(card->hw.scabase + DTX_REG(EDAL, ch),
  1696. TX_BD_ADDR(ch, chan->tx_next_bd));
  1697. cpc_writeb(card->hw.scabase + M_REG(CMD, ch), CMD_TX_ENA);
  1698. cpc_writeb(card->hw.scabase + DSR_TX(ch), DSR_DE);
  1699. if (card->hw.type == PC300_TE) {
  1700. cpc_writeb(card->hw.falcbase + card->hw.cpld_reg2,
  1701. cpc_readb(card->hw.falcbase + card->hw.cpld_reg2) |
  1702. (CPLD_REG2_FALC_LED1 << (2 * ch)));
  1703. }
  1704. CPC_UNLOCK(card, flags);
  1705. dev_kfree_skb(skb);
  1706. return 0;
  1707. }
  1708. static void cpc_net_rx(struct net_device *dev)
  1709. {
  1710. pc300dev_t *d = (pc300dev_t *) dev_to_hdlc(dev)->priv;
  1711. pc300ch_t *chan = (pc300ch_t *) d->chan;
  1712. pc300_t *card = (pc300_t *) chan->card;
  1713. int ch = chan->channel;
  1714. #ifdef PC300_DEBUG_RX
  1715. int i;
  1716. #endif
  1717. int rxb;
  1718. struct sk_buff *skb;
  1719. while (1) {
  1720. if ((rxb = dma_get_rx_frame_size(card, ch)) == -1)
  1721. return;
  1722. if (!netif_carrier_ok(dev)) {
  1723. /* DCD must be OFF: drop packet */
  1724. printk("%s : DCD is OFF - drop %d rx bytes\n", dev->name, rxb);
  1725. skb = NULL;
  1726. } else {
  1727. if (rxb > (dev->mtu + 40)) { /* add headers */
  1728. printk("%s : MTU exceeded %d\n", dev->name, rxb);
  1729. skb = NULL;
  1730. } else {
  1731. skb = dev_alloc_skb(rxb);
  1732. if (skb == NULL) {
  1733. printk("%s: Memory squeeze!!\n", dev->name);
  1734. return;
  1735. }
  1736. skb->dev = dev;
  1737. }
  1738. }
  1739. if (((rxb = dma_buf_read(card, ch, skb)) <= 0) || (skb == NULL)) {
  1740. #ifdef PC300_DEBUG_RX
  1741. printk("%s: rxb = %x\n", dev->name, rxb);
  1742. #endif
  1743. if ((skb == NULL) && (rxb > 0)) {
  1744. /* rxb > dev->mtu */
  1745. dev->stats.rx_errors++;
  1746. dev->stats.rx_length_errors++;
  1747. continue;
  1748. }
  1749. if (rxb < 0) { /* Invalid frame */
  1750. rxb = -rxb;
  1751. if (rxb & DST_OVR) {
  1752. dev->stats.rx_errors++;
  1753. dev->stats.rx_fifo_errors++;
  1754. }
  1755. if (rxb & DST_CRC) {
  1756. dev->stats.rx_errors++;
  1757. dev->stats.rx_crc_errors++;
  1758. }
  1759. if (rxb & (DST_RBIT | DST_SHRT | DST_ABT)) {
  1760. dev->stats.rx_errors++;
  1761. dev->stats.rx_frame_errors++;
  1762. }
  1763. }
  1764. if (skb) {
  1765. dev_kfree_skb_irq(skb);
  1766. }
  1767. continue;
  1768. }
  1769. dev->stats.rx_bytes += rxb;
  1770. #ifdef PC300_DEBUG_RX
  1771. printk("%s R:", dev->name);
  1772. for (i = 0; i < skb->len; i++)
  1773. printk(" %02x", *(skb->data + i));
  1774. printk("\n");
  1775. #endif
  1776. if (d->trace_on) {
  1777. cpc_trace(dev, skb, 'R');
  1778. }
  1779. dev->stats.rx_packets++;
  1780. skb->protocol = hdlc_type_trans(skb, dev);
  1781. netif_rx(skb);
  1782. }
  1783. }
  1784. /************************************/
  1785. /*** PC300 Interrupt Routines ***/
  1786. /************************************/
  1787. static void sca_tx_intr(pc300dev_t *dev)
  1788. {
  1789. pc300ch_t *chan = (pc300ch_t *)dev->chan;
  1790. pc300_t *card = (pc300_t *)chan->card;
  1791. int ch = chan->channel;
  1792. volatile pcsca_bd_t __iomem * ptdescr;
  1793. /* Clean up descriptors from previous transmission */
  1794. ptdescr = (card->hw.rambase +
  1795. TX_BD_ADDR(ch,chan->tx_first_bd));
  1796. while ((cpc_readl(card->hw.scabase + DTX_REG(CDAL,ch)) !=
  1797. TX_BD_ADDR(ch,chan->tx_first_bd)) &&
  1798. (cpc_readb(&ptdescr->status) & DST_OSB)) {
  1799. dev->dev->stats.tx_packets++;
  1800. dev->dev->stats.tx_bytes += cpc_readw(&ptdescr->len);
  1801. cpc_writeb(&ptdescr->status, DST_OSB);
  1802. cpc_writew(&ptdescr->len, 0);
  1803. chan->nfree_tx_bd++;
  1804. chan->tx_first_bd = (chan->tx_first_bd + 1) & (N_DMA_TX_BUF - 1);
  1805. ptdescr = (card->hw.rambase + TX_BD_ADDR(ch,chan->tx_first_bd));
  1806. }
  1807. #ifdef CONFIG_PC300_MLPPP
  1808. if (chan->conf.proto == PC300_PROTO_MLPPP) {
  1809. cpc_tty_trigger_poll(dev);
  1810. } else {
  1811. #endif
  1812. /* Tell the upper layer we are ready to transmit more packets */
  1813. netif_wake_queue(dev->dev);
  1814. #ifdef CONFIG_PC300_MLPPP
  1815. }
  1816. #endif
  1817. }
  1818. static void sca_intr(pc300_t * card)
  1819. {
  1820. void __iomem *scabase = card->hw.scabase;
  1821. volatile u32 status;
  1822. int ch;
  1823. int intr_count = 0;
  1824. unsigned char dsr_rx;
  1825. while ((status = cpc_readl(scabase + ISR0)) != 0) {
  1826. for (ch = 0; ch < card->hw.nchan; ch++) {
  1827. pc300ch_t *chan = &card->chan[ch];
  1828. pc300dev_t *d = &chan->d;
  1829. struct net_device *dev = d->dev;
  1830. spin_lock(&card->card_lock);
  1831. /**** Reception ****/
  1832. if (status & IR0_DRX((IR0_DMIA | IR0_DMIB), ch)) {
  1833. u8 drx_stat = cpc_readb(scabase + DSR_RX(ch));
  1834. /* Clear RX interrupts */
  1835. cpc_writeb(scabase + DSR_RX(ch), drx_stat | DSR_DWE);
  1836. #ifdef PC300_DEBUG_INTR
  1837. printk ("sca_intr: RX intr chan[%d] (st=0x%08lx, dsr=0x%02x)\n",
  1838. ch, status, drx_stat);
  1839. #endif
  1840. if (status & IR0_DRX(IR0_DMIA, ch)) {
  1841. if (drx_stat & DSR_BOF) {
  1842. #ifdef CONFIG_PC300_MLPPP
  1843. if (chan->conf.proto == PC300_PROTO_MLPPP) {
  1844. /* verify if driver is TTY */
  1845. if ((cpc_readb(scabase + DSR_RX(ch)) & DSR_DE)) {
  1846. rx_dma_stop(card, ch);
  1847. }
  1848. cpc_tty_receive(d);
  1849. rx_dma_start(card, ch);
  1850. } else
  1851. #endif
  1852. {
  1853. if ((cpc_readb(scabase + DSR_RX(ch)) & DSR_DE)) {
  1854. rx_dma_stop(card, ch);
  1855. }
  1856. cpc_net_rx(dev);
  1857. /* Discard invalid frames */
  1858. dev->stats.rx_errors++;
  1859. dev->stats.rx_over_errors++;
  1860. chan->rx_first_bd = 0;
  1861. chan->rx_last_bd = N_DMA_RX_BUF - 1;
  1862. rx_dma_start(card, ch);
  1863. }
  1864. }
  1865. }
  1866. if (status & IR0_DRX(IR0_DMIB, ch)) {
  1867. if (drx_stat & DSR_EOM) {
  1868. if (card->hw.type == PC300_TE) {
  1869. cpc_writeb(card->hw.falcbase +
  1870. card->hw.cpld_reg2,
  1871. cpc_readb (card->hw.falcbase +
  1872. card->hw.cpld_reg2) |
  1873. (CPLD_REG2_FALC_LED1 << (2 * ch)));
  1874. }
  1875. #ifdef CONFIG_PC300_MLPPP
  1876. if (chan->conf.proto == PC300_PROTO_MLPPP) {
  1877. /* verify if driver is TTY */
  1878. cpc_tty_receive(d);
  1879. } else {
  1880. cpc_net_rx(dev);
  1881. }
  1882. #else
  1883. cpc_net_rx(dev);
  1884. #endif
  1885. if (card->hw.type == PC300_TE) {
  1886. cpc_writeb(card->hw.falcbase +
  1887. card->hw.cpld_reg2,
  1888. cpc_readb (card->hw.falcbase +
  1889. card->hw.cpld_reg2) &
  1890. ~ (CPLD_REG2_FALC_LED1 << (2 * ch)));
  1891. }
  1892. }
  1893. }
  1894. if (!(dsr_rx = cpc_readb(scabase + DSR_RX(ch)) & DSR_DE)) {
  1895. #ifdef PC300_DEBUG_INTR
  1896. printk("%s: RX intr chan[%d] (st=0x%08lx, dsr=0x%02x, dsr2=0x%02x)\n",
  1897. dev->name, ch, status, drx_stat, dsr_rx);
  1898. #endif
  1899. cpc_writeb(scabase + DSR_RX(ch), (dsr_rx | DSR_DE) & 0xfe);
  1900. }
  1901. }
  1902. /**** Transmission ****/
  1903. if (status & IR0_DTX((IR0_EFT | IR0_DMIA | IR0_DMIB), ch)) {
  1904. u8 dtx_stat = cpc_readb(scabase + DSR_TX(ch));
  1905. /* Clear TX interrupts */
  1906. cpc_writeb(scabase + DSR_TX(ch), dtx_stat | DSR_DWE);
  1907. #ifdef PC300_DEBUG_INTR
  1908. printk ("sca_intr: TX intr chan[%d] (st=0x%08lx, dsr=0x%02x)\n",
  1909. ch, status, dtx_stat);
  1910. #endif
  1911. if (status & IR0_DTX(IR0_EFT, ch)) {
  1912. if (dtx_stat & DSR_UDRF) {
  1913. if (cpc_readb (scabase + M_REG(TBN, ch)) != 0) {
  1914. cpc_writeb(scabase + M_REG(CMD,ch), CMD_TX_BUF_CLR);
  1915. }
  1916. if (card->hw.type == PC300_TE) {
  1917. cpc_writeb(card->hw.falcbase + card->hw.cpld_reg2,
  1918. cpc_readb (card->hw.falcbase +
  1919. card->hw.cpld_reg2) &
  1920. ~ (CPLD_REG2_FALC_LED1 << (2 * ch)));
  1921. }
  1922. dev->stats.tx_errors++;
  1923. dev->stats.tx_fifo_errors++;
  1924. sca_tx_intr(d);
  1925. }
  1926. }
  1927. if (status & IR0_DTX(IR0_DMIA, ch)) {
  1928. if (dtx_stat & DSR_BOF) {
  1929. }
  1930. }
  1931. if (status & IR0_DTX(IR0_DMIB, ch)) {
  1932. if (dtx_stat & DSR_EOM) {
  1933. if (card->hw.type == PC300_TE) {
  1934. cpc_writeb(card->hw.falcbase + card->hw.cpld_reg2,
  1935. cpc_readb (card->hw.falcbase +
  1936. card->hw.cpld_reg2) &
  1937. ~ (CPLD_REG2_FALC_LED1 << (2 * ch)));
  1938. }
  1939. sca_tx_intr(d);
  1940. }
  1941. }
  1942. }
  1943. /**** MSCI ****/
  1944. if (status & IR0_M(IR0_RXINTA, ch)) {
  1945. u8 st1 = cpc_readb(scabase + M_REG(ST1, ch));
  1946. /* Clear MSCI interrupts */
  1947. cpc_writeb(scabase + M_REG(ST1, ch), st1);
  1948. #ifdef PC300_DEBUG_INTR
  1949. printk("sca_intr: MSCI intr chan[%d] (st=0x%08lx, st1=0x%02x)\n",
  1950. ch, status, st1);
  1951. #endif
  1952. if (st1 & ST1_CDCD) { /* DCD changed */
  1953. if (cpc_readb(scabase + M_REG(ST3, ch)) & ST3_DCD) {
  1954. printk ("%s: DCD is OFF. Going administrative down.\n",
  1955. dev->name);
  1956. #ifdef CONFIG_PC300_MLPPP
  1957. if (chan->conf.proto != PC300_PROTO_MLPPP) {
  1958. netif_carrier_off(dev);
  1959. }
  1960. #else
  1961. netif_carrier_off(dev);
  1962. #endif
  1963. card->chan[ch].d.line_off++;
  1964. } else { /* DCD = 1 */
  1965. printk ("%s: DCD is ON. Going administrative up.\n",
  1966. dev->name);
  1967. #ifdef CONFIG_PC300_MLPPP
  1968. if (chan->conf.proto != PC300_PROTO_MLPPP)
  1969. /* verify if driver is not TTY */
  1970. #endif
  1971. netif_carrier_on(dev);
  1972. card->chan[ch].d.line_on++;
  1973. }
  1974. }
  1975. }
  1976. spin_unlock(&card->card_lock);
  1977. }
  1978. if (++intr_count == 10)
  1979. /* Too much work at this board. Force exit */
  1980. break;
  1981. }
  1982. }
  1983. static void falc_t1_loop_detection(pc300_t *card, int ch, u8 frs1)
  1984. {
  1985. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  1986. falc_t *pfalc = (falc_t *) & chan->falc;
  1987. void __iomem *falcbase = card->hw.falcbase;
  1988. if (((cpc_readb(falcbase + F_REG(LCR1, ch)) & LCR1_XPRBS) == 0) &&
  1989. !pfalc->loop_gen) {
  1990. if (frs1 & FRS1_LLBDD) {
  1991. // A Line Loop Back Deactivation signal detected
  1992. if (pfalc->loop_active) {
  1993. falc_remote_loop(card, ch, 0);
  1994. }
  1995. } else {
  1996. if ((frs1 & FRS1_LLBAD) &&
  1997. ((cpc_readb(falcbase + F_REG(LCR1, ch)) & LCR1_EPRM) == 0)) {
  1998. // A Line Loop Back Activation signal detected
  1999. if (!pfalc->loop_active) {
  2000. falc_remote_loop(card, ch, 1);
  2001. }
  2002. }
  2003. }
  2004. }
  2005. }
  2006. static void falc_e1_loop_detection(pc300_t *card, int ch, u8 rsp)
  2007. {
  2008. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  2009. falc_t *pfalc = (falc_t *) & chan->falc;
  2010. void __iomem *falcbase = card->hw.falcbase;
  2011. if (((cpc_readb(falcbase + F_REG(LCR1, ch)) & LCR1_XPRBS) == 0) &&
  2012. !pfalc->loop_gen) {
  2013. if (rsp & RSP_LLBDD) {
  2014. // A Line Loop Back Deactivation signal detected
  2015. if (pfalc->loop_active) {
  2016. falc_remote_loop(card, ch, 0);
  2017. }
  2018. } else {
  2019. if ((rsp & RSP_LLBAD) &&
  2020. ((cpc_readb(falcbase + F_REG(LCR1, ch)) & LCR1_EPRM) == 0)) {
  2021. // A Line Loop Back Activation signal detected
  2022. if (!pfalc->loop_active) {
  2023. falc_remote_loop(card, ch, 1);
  2024. }
  2025. }
  2026. }
  2027. }
  2028. }
  2029. static void falc_t1_intr(pc300_t * card, int ch)
  2030. {
  2031. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  2032. falc_t *pfalc = (falc_t *) & chan->falc;
  2033. void __iomem *falcbase = card->hw.falcbase;
  2034. u8 isr0, isr3, gis;
  2035. u8 dummy;
  2036. while ((gis = cpc_readb(falcbase + F_REG(GIS, ch))) != 0) {
  2037. if (gis & GIS_ISR0) {
  2038. isr0 = cpc_readb(falcbase + F_REG(FISR0, ch));
  2039. if (isr0 & FISR0_PDEN) {
  2040. /* Read the bit to clear the situation */
  2041. if (cpc_readb(falcbase + F_REG(FRS1, ch)) &
  2042. FRS1_PDEN) {
  2043. pfalc->pden++;
  2044. }
  2045. }
  2046. }
  2047. if (gis & GIS_ISR1) {
  2048. dummy = cpc_readb(falcbase + F_REG(FISR1, ch));
  2049. }
  2050. if (gis & GIS_ISR2) {
  2051. dummy = cpc_readb(falcbase + F_REG(FISR2, ch));
  2052. }
  2053. if (gis & GIS_ISR3) {
  2054. isr3 = cpc_readb(falcbase + F_REG(FISR3, ch));
  2055. if (isr3 & FISR3_SEC) {
  2056. pfalc->sec++;
  2057. falc_update_stats(card, ch);
  2058. falc_check_status(card, ch,
  2059. cpc_readb(falcbase + F_REG(FRS0, ch)));
  2060. }
  2061. if (isr3 & FISR3_ES) {
  2062. pfalc->es++;
  2063. }
  2064. if (isr3 & FISR3_LLBSC) {
  2065. falc_t1_loop_detection(card, ch,
  2066. cpc_readb(falcbase + F_REG(FRS1, ch)));
  2067. }
  2068. }
  2069. }
  2070. }
  2071. static void falc_e1_intr(pc300_t * card, int ch)
  2072. {
  2073. pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
  2074. falc_t *pfalc = (falc_t *) & chan->falc;
  2075. void __iomem *falcbase = card->hw.falcbase;
  2076. u8 isr1, isr2, isr3, gis, rsp;
  2077. u8 dummy;
  2078. while ((gis = cpc_readb(falcbase + F_REG(GIS, ch))) != 0) {
  2079. rsp = cpc_readb(falcbase + F_REG(RSP, ch));
  2080. if (gis & GIS_ISR0) {
  2081. dummy = cpc_readb(falcbase + F_REG(FISR0, ch));
  2082. }
  2083. if (gis & GIS_ISR1) {
  2084. isr1 = cpc_readb(falcbase + F_REG(FISR1, ch));
  2085. if (isr1 & FISR1_XMB) {
  2086. if ((pfalc->xmb_cause & 2) &&
  2087. pfalc->multiframe_mode) {
  2088. if (cpc_readb (falcbase + F_REG(FRS0, ch)) &
  2089. (FRS0_LOS | FRS0_AIS | FRS0_LFA)) {
  2090. cpc_writeb(falcbase + F_REG(XSP, ch),
  2091. cpc_readb(falcbase + F_REG(XSP, ch))
  2092. & ~XSP_AXS);
  2093. } else {
  2094. cpc_writeb(falcbase + F_REG(XSP, ch),
  2095. cpc_readb(falcbase + F_REG(XSP, ch))
  2096. | XSP_AXS);
  2097. }
  2098. }
  2099. pfalc->xmb_cause = 0;
  2100. cpc_writeb(falcbase + F_REG(IMR1, ch),
  2101. cpc_readb(falcbase + F_REG(IMR1, ch)) | IMR1_XMB);
  2102. }
  2103. if (isr1 & FISR1_LLBSC) {
  2104. falc_e1_loop_detection(card, ch, rsp);
  2105. }
  2106. }
  2107. if (gis & GIS_ISR2) {
  2108. isr2 = cpc_readb(falcbase + F_REG(FISR2, ch));
  2109. if (isr2 & FISR2_T400MS) {
  2110. cpc_writeb(falcbase + F_REG(XSW, ch),
  2111. cpc_readb(falcbase + F_REG(XSW, ch)) | XSW_XRA);
  2112. }
  2113. if (isr2 & FISR2_MFAR) {
  2114. cpc_writeb(falcbase + F_REG(XSW, ch),
  2115. cpc_readb(falcbase + F_REG(XSW, ch)) & ~XSW_XRA);
  2116. }
  2117. if (isr2 & (FISR2_FAR | FISR2_LFA | FISR2_AIS | FISR2_LOS)) {
  2118. pfalc->xmb_cause |= 2;
  2119. cpc_writeb(falcbase + F_REG(IMR1, ch),
  2120. cpc_readb(falcbase + F_REG(IMR1, ch)) & ~IMR1_XMB);
  2121. }
  2122. }
  2123. if (gis & GIS_ISR3) {
  2124. isr3 = cpc_readb(falcbase + F_REG(FISR3, ch));
  2125. if (isr3 & FISR3_SEC) {
  2126. pfalc->sec++;
  2127. falc_update_stats(card, ch);
  2128. falc_check_status(card, ch,
  2129. cpc_readb(falcbase + F_REG(FRS0, ch)));
  2130. }
  2131. if (isr3 & FISR3_ES) {
  2132. pfalc->es++;
  2133. }
  2134. }
  2135. }
  2136. }
  2137. static void falc_intr(pc300_t * card)
  2138. {
  2139. int ch;
  2140. for (ch = 0; ch < card->hw.nchan; ch++) {
  2141. pc300ch_t *chan = &card->chan[ch];
  2142. pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
  2143. if (conf->media == IF_IFACE_T1) {
  2144. falc_t1_intr(card, ch);
  2145. } else {
  2146. falc_e1_intr(card, ch);
  2147. }
  2148. }
  2149. }
  2150. static irqreturn_t cpc_intr(int irq, void *dev_id)
  2151. {
  2152. pc300_t *card = dev_id;
  2153. volatile u8 plx_status;
  2154. if (!card) {
  2155. #ifdef PC300_DEBUG_INTR
  2156. printk("cpc_intr: spurious intr %d\n", irq);
  2157. #endif
  2158. return IRQ_NONE; /* spurious intr */
  2159. }
  2160. if (!card->hw.rambase) {
  2161. #ifdef PC300_DEBUG_INTR
  2162. printk("cpc_intr: spurious intr2 %d\n", irq);
  2163. #endif
  2164. return IRQ_NONE; /* spurious intr */
  2165. }
  2166. switch (card->hw.type) {
  2167. case PC300_RSV:
  2168. case PC300_X21:
  2169. sca_intr(card);
  2170. break;
  2171. case PC300_TE:
  2172. while ( (plx_status = (cpc_readb(card->hw.plxbase + card->hw.intctl_reg) &
  2173. (PLX_9050_LINT1_STATUS | PLX_9050_LINT2_STATUS))) != 0) {
  2174. if (plx_status & PLX_9050_LINT1_STATUS) { /* SCA Interrupt */
  2175. sca_intr(card);
  2176. }
  2177. if (plx_status & PLX_9050_LINT2_STATUS) { /* FALC Interrupt */
  2178. falc_intr(card);
  2179. }
  2180. }
  2181. break;
  2182. }
  2183. return IRQ_HANDLED;
  2184. }
  2185. static void cpc_sca_status(pc300_t * card, int ch)
  2186. {
  2187. u8 ilar;
  2188. void __iomem *scabase = card->hw.scabase;
  2189. unsigned long flags;
  2190. tx_dma_buf_check(card, ch);
  2191. rx_dma_buf_check(card, ch);
  2192. ilar = cpc_readb(scabase + ILAR);
  2193. printk ("ILAR=0x%02x, WCRL=0x%02x, PCR=0x%02x, BTCR=0x%02x, BOLR=0x%02x\n",
  2194. ilar, cpc_readb(scabase + WCRL), cpc_readb(scabase + PCR),
  2195. cpc_readb(scabase + BTCR), cpc_readb(scabase + BOLR));
  2196. printk("TX_CDA=0x%08x, TX_EDA=0x%08x\n",
  2197. cpc_readl(scabase + DTX_REG(CDAL, ch)),
  2198. cpc_readl(scabase + DTX_REG(EDAL, ch)));
  2199. printk("RX_CDA=0x%08x, RX_EDA=0x%08x, BFL=0x%04x\n",
  2200. cpc_readl(scabase + DRX_REG(CDAL, ch)),
  2201. cpc_readl(scabase + DRX_REG(EDAL, ch)),
  2202. cpc_readw(scabase + DRX_REG(BFLL, ch)));
  2203. printk("DMER=0x%02x, DSR_TX=0x%02x, DSR_RX=0x%02x\n",
  2204. cpc_readb(scabase + DMER), cpc_readb(scabase + DSR_TX(ch)),
  2205. cpc_readb(scabase + DSR_RX(ch)));
  2206. printk("DMR_TX=0x%02x, DMR_RX=0x%02x, DIR_TX=0x%02x, DIR_RX=0x%02x\n",
  2207. cpc_readb(scabase + DMR_TX(ch)), cpc_readb(scabase + DMR_RX(ch)),
  2208. cpc_readb(scabase + DIR_TX(ch)),
  2209. cpc_readb(scabase + DIR_RX(ch)));
  2210. printk("DCR_TX=0x%02x, DCR_RX=0x%02x, FCT_TX=0x%02x, FCT_RX=0x%02x\n",
  2211. cpc_readb(scabase + DCR_TX(ch)), cpc_readb(scabase + DCR_RX(ch)),
  2212. cpc_readb(scabase + FCT_TX(ch)),
  2213. cpc_readb(scabase + FCT_RX(ch)));
  2214. printk("MD0=0x%02x, MD1=0x%02x, MD2=0x%02x, MD3=0x%02x, IDL=0x%02x\n",
  2215. cpc_readb(scabase + M_REG(MD0, ch)),
  2216. cpc_readb(scabase + M_REG(MD1, ch)),
  2217. cpc_readb(scabase + M_REG(MD2, ch)),
  2218. cpc_readb(scabase + M_REG(MD3, ch)),
  2219. cpc_readb(scabase + M_REG(IDL, ch)));
  2220. printk("CMD=0x%02x, SA0=0x%02x, SA1=0x%02x, TFN=0x%02x, CTL=0x%02x\n",
  2221. cpc_readb(scabase + M_REG(CMD, ch)),
  2222. cpc_readb(scabase + M_REG(SA0, ch)),
  2223. cpc_readb(scabase + M_REG(SA1, ch)),
  2224. cpc_readb(scabase + M_REG(TFN, ch)),
  2225. cpc_readb(scabase + M_REG(CTL, ch)));
  2226. printk("ST0=0x%02x, ST1=0x%02x, ST2=0x%02x, ST3=0x%02x, ST4=0x%02x\n",
  2227. cpc_readb(scabase + M_REG(ST0, ch)),
  2228. cpc_readb(scabase + M_REG(ST1, ch)),
  2229. cpc_readb(scabase + M_REG(ST2, ch)),
  2230. cpc_readb(scabase + M_REG(ST3, ch)),
  2231. cpc_readb(scabase + M_REG(ST4, ch)));
  2232. printk ("CST0=0x%02x, CST1=0x%02x, CST2=0x%02x, CST3=0x%02x, FST=0x%02x\n",
  2233. cpc_readb(scabase + M_REG(CST0, ch)),
  2234. cpc_readb(scabase + M_REG(CST1, ch)),
  2235. cpc_readb(scabase + M_REG(CST2, ch)),
  2236. cpc_readb(scabase + M_REG(CST3, ch)),
  2237. cpc_readb(scabase + M_REG(FST, ch)));
  2238. printk("TRC0=0x%02x, TRC1=0x%02x, RRC=0x%02x, TBN=0x%02x, RBN=0x%02x\n",
  2239. cpc_readb(scabase + M_REG(TRC0, ch)),
  2240. cpc_readb(scabase + M_REG(TRC1, ch)),
  2241. cpc_readb(scabase + M_REG(RRC, ch)),
  2242. cpc_readb(scabase + M_REG(TBN, ch)),
  2243. cpc_readb(scabase + M_REG(RBN, ch)));
  2244. printk("TFS=0x%02x, TNR0=0x%02x, TNR1=0x%02x, RNR=0x%02x\n",
  2245. cpc_readb(scabase + M_REG(TFS, ch)),
  2246. cpc_readb(scabase + M_REG(TNR0, ch)),
  2247. cpc_readb(scabase + M_REG(TNR1, ch)),
  2248. cpc_readb(scabase + M_REG(RNR, ch)));
  2249. printk("TCR=0x%02x, RCR=0x%02x, TNR1=0x%02x, RNR=0x%02x\n",
  2250. cpc_readb(scabase + M_REG(TCR, ch)),
  2251. cpc_readb(scabase + M_REG(RCR, ch)),
  2252. cpc_readb(scabase + M_REG(TNR1, ch)),
  2253. cpc_readb(scabase + M_REG(RNR, ch)));
  2254. printk("TXS=0x%02x, RXS=0x%02x, EXS=0x%02x, TMCT=0x%02x, TMCR=0x%02x\n",
  2255. cpc_readb(scabase + M_REG(TXS, ch)),
  2256. cpc_readb(scabase + M_REG(RXS, ch)),
  2257. cpc_readb(scabase + M_REG(EXS, ch)),
  2258. cpc_readb(scabase + M_REG(TMCT, ch)),
  2259. cpc_readb(scabase + M_REG(TMCR, ch)));
  2260. printk("IE0=0x%02x, IE1=0x%02x, IE2=0x%02x, IE4=0x%02x, FIE=0x%02x\n",
  2261. cpc_readb(scabase + M_REG(IE0, ch)),
  2262. cpc_readb(scabase + M_REG(IE1, ch)),
  2263. cpc_readb(scabase + M_REG(IE2, ch)),
  2264. cpc_readb(scabase + M_REG(IE4, ch)),
  2265. cpc_readb(scabase + M_REG(FIE, ch)));
  2266. printk("IER0=0x%08x\n", cpc_readl(scabase + IER0));
  2267. if (ilar != 0) {
  2268. CPC_LOCK(card, flags);
  2269. cpc_writeb(scabase + ILAR, ilar);
  2270. cpc_writeb(scabase + DMER, 0x80);
  2271. CPC_UNLOCK(card, flags);
  2272. }
  2273. }
  2274. static void cpc_falc_status(pc300_t * card, int ch)
  2275. {
  2276. pc300ch_t *chan = &card->chan[ch];
  2277. falc_t *pfalc = (falc_t *) & chan->falc;
  2278. unsigned long flags;
  2279. CPC_LOCK(card, flags);
  2280. printk("CH%d: %s %s %d channels\n",
  2281. ch, (pfalc->sync ? "SYNC" : ""), (pfalc->active ? "ACTIVE" : ""),
  2282. pfalc->num_channels);
  2283. printk(" pden=%d, los=%d, losr=%d, lfa=%d, farec=%d\n",
  2284. pfalc->pden, pfalc->los, pfalc->losr, pfalc->lfa, pfalc->farec);
  2285. printk(" lmfa=%d, ais=%d, sec=%d, es=%d, rai=%d\n",
  2286. pfalc->lmfa, pfalc->ais, pfalc->sec, pfalc->es, pfalc->rai);
  2287. printk(" bec=%d, fec=%d, cvc=%d, cec=%d, ebc=%d\n",
  2288. pfalc->bec, pfalc->fec, pfalc->cvc, pfalc->cec, pfalc->ebc);
  2289. printk("\n");
  2290. printk(" STATUS: %s %s %s %s %s %s\n",
  2291. (pfalc->red_alarm ? "RED" : ""),
  2292. (pfalc->blue_alarm ? "BLU" : ""),
  2293. (pfalc->yellow_alarm ? "YEL" : ""),
  2294. (pfalc->loss_fa ? "LFA" : ""),
  2295. (pfalc->loss_mfa ? "LMF" : ""), (pfalc->prbs ? "PRB" : ""));
  2296. CPC_UNLOCK(card, flags);
  2297. }
  2298. static int cpc_change_mtu(struct net_device *dev, int new_mtu)
  2299. {
  2300. if ((new_mtu < 128) || (new_mtu > PC300_DEF_MTU))
  2301. return -EINVAL;
  2302. dev->mtu = new_mtu;
  2303. return 0;
  2304. }
  2305. static int cpc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  2306. {
  2307. pc300dev_t *d = (pc300dev_t *) dev_to_hdlc(dev)->priv;
  2308. pc300ch_t *chan = (pc300ch_t *) d->chan;
  2309. pc300_t *card = (pc300_t *) chan->card;
  2310. pc300conf_t conf_aux;
  2311. pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
  2312. int ch = chan->channel;
  2313. void __user *arg = ifr->ifr_data;
  2314. struct if_settings *settings = &ifr->ifr_settings;
  2315. void __iomem *scabase = card->hw.scabase;
  2316. if (!capable(CAP_NET_ADMIN))
  2317. return -EPERM;
  2318. switch (cmd) {
  2319. case SIOCGPC300CONF:
  2320. #ifdef CONFIG_PC300_MLPPP
  2321. if (conf->proto != PC300_PROTO_MLPPP) {
  2322. conf->proto = /* FIXME hdlc->proto.id */ 0;
  2323. }
  2324. #else
  2325. conf->proto = /* FIXME hdlc->proto.id */ 0;
  2326. #endif
  2327. memcpy(&conf_aux.conf, conf, sizeof(pc300chconf_t));
  2328. memcpy(&conf_aux.hw, &card->hw, sizeof(pc300hw_t));
  2329. if (!arg ||
  2330. copy_to_user(arg, &conf_aux, sizeof(pc300conf_t)))
  2331. return -EINVAL;
  2332. return 0;
  2333. case SIOCSPC300CONF:
  2334. if (!capable(CAP_NET_ADMIN))
  2335. return -EPERM;
  2336. if (!arg ||
  2337. copy_from_user(&conf_aux.conf, arg, sizeof(pc300chconf_t)))
  2338. return -EINVAL;
  2339. if (card->hw.cpld_id < 0x02 &&
  2340. conf_aux.conf.fr_mode == PC300_FR_UNFRAMED) {
  2341. /* CPLD_ID < 0x02 doesn't support Unframed E1 */
  2342. return -EINVAL;
  2343. }
  2344. #ifdef CONFIG_PC300_MLPPP
  2345. if (conf_aux.conf.proto == PC300_PROTO_MLPPP) {
  2346. if (conf->proto != PC300_PROTO_MLPPP) {
  2347. memcpy(conf, &conf_aux.conf, sizeof(pc300chconf_t));
  2348. cpc_tty_init(d); /* init TTY driver */
  2349. }
  2350. } else {
  2351. if (conf_aux.conf.proto == 0xffff) {
  2352. if (conf->proto == PC300_PROTO_MLPPP){
  2353. /* ifdown interface */
  2354. cpc_close(dev);
  2355. }
  2356. } else {
  2357. memcpy(conf, &conf_aux.conf, sizeof(pc300chconf_t));
  2358. /* FIXME hdlc->proto.id = conf->proto; */
  2359. }
  2360. }
  2361. #else
  2362. memcpy(conf, &conf_aux.conf, sizeof(pc300chconf_t));
  2363. /* FIXME hdlc->proto.id = conf->proto; */
  2364. #endif
  2365. return 0;
  2366. case SIOCGPC300STATUS:
  2367. cpc_sca_status(card, ch);
  2368. return 0;
  2369. case SIOCGPC300FALCSTATUS:
  2370. cpc_falc_status(card, ch);
  2371. return 0;
  2372. case SIOCGPC300UTILSTATS:
  2373. {
  2374. if (!arg) { /* clear statistics */
  2375. memset(&dev->stats, 0, sizeof(dev->stats));
  2376. if (card->hw.type == PC300_TE) {
  2377. memset(&chan->falc, 0, sizeof(falc_t));
  2378. }
  2379. } else {
  2380. pc300stats_t pc300stats;
  2381. memset(&pc300stats, 0, sizeof(pc300stats_t));
  2382. pc300stats.hw_type = card->hw.type;
  2383. pc300stats.line_on = card->chan[ch].d.line_on;
  2384. pc300stats.line_off = card->chan[ch].d.line_off;
  2385. memcpy(&pc300stats.gen_stats, &dev->stats,
  2386. sizeof(dev->stats));
  2387. if (card->hw.type == PC300_TE)
  2388. memcpy(&pc300stats.te_stats,&chan->falc,sizeof(falc_t));
  2389. if (copy_to_user(arg, &pc300stats, sizeof(pc300stats_t)))
  2390. return -EFAULT;
  2391. }
  2392. return 0;
  2393. }
  2394. case SIOCGPC300UTILSTATUS:
  2395. {
  2396. struct pc300status pc300status;
  2397. pc300status.hw_type = card->hw.type;
  2398. if (card->hw.type == PC300_TE) {
  2399. pc300status.te_status.sync = chan->falc.sync;
  2400. pc300status.te_status.red_alarm = chan->falc.red_alarm;
  2401. pc300status.te_status.blue_alarm = chan->falc.blue_alarm;
  2402. pc300status.te_status.loss_fa = chan->falc.loss_fa;
  2403. pc300status.te_status.yellow_alarm =chan->falc.yellow_alarm;
  2404. pc300status.te_status.loss_mfa = chan->falc.loss_mfa;
  2405. pc300status.te_status.prbs = chan->falc.prbs;
  2406. } else {
  2407. pc300status.gen_status.dcd =
  2408. !(cpc_readb (scabase + M_REG(ST3, ch)) & ST3_DCD);
  2409. pc300status.gen_status.cts =
  2410. !(cpc_readb (scabase + M_REG(ST3, ch)) & ST3_CTS);
  2411. pc300status.gen_status.rts =
  2412. !(cpc_readb (scabase + M_REG(CTL, ch)) & CTL_RTS);
  2413. pc300status.gen_status.dtr =
  2414. !(cpc_readb (scabase + M_REG(CTL, ch)) & CTL_DTR);
  2415. /* There is no DSR in HD64572 */
  2416. }
  2417. if (!arg ||
  2418. copy_to_user(arg, &pc300status, sizeof(pc300status_t)))
  2419. return -EINVAL;
  2420. return 0;
  2421. }
  2422. case SIOCSPC300TRACE:
  2423. /* Sets/resets a trace_flag for the respective device */
  2424. if (!arg || copy_from_user(&d->trace_on, arg,sizeof(unsigned char)))
  2425. return -EINVAL;
  2426. return 0;
  2427. case SIOCSPC300LOOPBACK:
  2428. {
  2429. struct pc300loopback pc300loop;
  2430. /* TE boards only */
  2431. if (card->hw.type != PC300_TE)
  2432. return -EINVAL;
  2433. if (!arg ||
  2434. copy_from_user(&pc300loop, arg, sizeof(pc300loopback_t)))
  2435. return -EINVAL;
  2436. switch (pc300loop.loop_type) {
  2437. case PC300LOCLOOP: /* Turn the local loop on/off */
  2438. falc_local_loop(card, ch, pc300loop.loop_on);
  2439. return 0;
  2440. case PC300REMLOOP: /* Turn the remote loop on/off */
  2441. falc_remote_loop(card, ch, pc300loop.loop_on);
  2442. return 0;
  2443. case PC300PAYLOADLOOP: /* Turn the payload loop on/off */
  2444. falc_payload_loop(card, ch, pc300loop.loop_on);
  2445. return 0;
  2446. case PC300GENLOOPUP: /* Generate loop UP */
  2447. if (pc300loop.loop_on) {
  2448. falc_generate_loop_up_code (card, ch);
  2449. } else {
  2450. turn_off_xlu(card, ch);
  2451. }
  2452. return 0;
  2453. case PC300GENLOOPDOWN: /* Generate loop DOWN */
  2454. if (pc300loop.loop_on) {
  2455. falc_generate_loop_down_code (card, ch);
  2456. } else {
  2457. turn_off_xld(card, ch);
  2458. }
  2459. return 0;
  2460. default:
  2461. return -EINVAL;
  2462. }
  2463. }
  2464. case SIOCSPC300PATTERNTEST:
  2465. /* Turn the pattern test on/off and show the errors counter */
  2466. {
  2467. struct pc300patterntst pc300patrntst;
  2468. /* TE boards only */
  2469. if (card->hw.type != PC300_TE)
  2470. return -EINVAL;
  2471. if (card->hw.cpld_id < 0x02) {
  2472. /* CPLD_ID < 0x02 doesn't support pattern test */
  2473. return -EINVAL;
  2474. }
  2475. if (!arg ||
  2476. copy_from_user(&pc300patrntst,arg,sizeof(pc300patterntst_t)))
  2477. return -EINVAL;
  2478. if (pc300patrntst.patrntst_on == 2) {
  2479. if (chan->falc.prbs == 0) {
  2480. falc_pattern_test(card, ch, 1);
  2481. }
  2482. pc300patrntst.num_errors =
  2483. falc_pattern_test_error(card, ch);
  2484. if (copy_to_user(arg, &pc300patrntst,
  2485. sizeof(pc300patterntst_t)))
  2486. return -EINVAL;
  2487. } else {
  2488. falc_pattern_test(card, ch, pc300patrntst.patrntst_on);
  2489. }
  2490. return 0;
  2491. }
  2492. case SIOCWANDEV:
  2493. switch (ifr->ifr_settings.type) {
  2494. case IF_GET_IFACE:
  2495. {
  2496. const size_t size = sizeof(sync_serial_settings);
  2497. ifr->ifr_settings.type = conf->media;
  2498. if (ifr->ifr_settings.size < size) {
  2499. /* data size wanted */
  2500. ifr->ifr_settings.size = size;
  2501. return -ENOBUFS;
  2502. }
  2503. if (copy_to_user(settings->ifs_ifsu.sync,
  2504. &conf->phys_settings, size)) {
  2505. return -EFAULT;
  2506. }
  2507. return 0;
  2508. }
  2509. case IF_IFACE_V35:
  2510. case IF_IFACE_V24:
  2511. case IF_IFACE_X21:
  2512. {
  2513. const size_t size = sizeof(sync_serial_settings);
  2514. if (!capable(CAP_NET_ADMIN)) {
  2515. return -EPERM;
  2516. }
  2517. /* incorrect data len? */
  2518. if (ifr->ifr_settings.size != size) {
  2519. return -ENOBUFS;
  2520. }
  2521. if (copy_from_user(&conf->phys_settings,
  2522. settings->ifs_ifsu.sync, size)) {
  2523. return -EFAULT;
  2524. }
  2525. if (conf->phys_settings.loopback) {
  2526. cpc_writeb(card->hw.scabase + M_REG(MD2, ch),
  2527. cpc_readb(card->hw.scabase + M_REG(MD2, ch)) |
  2528. MD2_LOOP_MIR);
  2529. }
  2530. conf->media = ifr->ifr_settings.type;
  2531. return 0;
  2532. }
  2533. case IF_IFACE_T1:
  2534. case IF_IFACE_E1:
  2535. {
  2536. const size_t te_size = sizeof(te1_settings);
  2537. const size_t size = sizeof(sync_serial_settings);
  2538. if (!capable(CAP_NET_ADMIN)) {
  2539. return -EPERM;
  2540. }
  2541. /* incorrect data len? */
  2542. if (ifr->ifr_settings.size != te_size) {
  2543. return -ENOBUFS;
  2544. }
  2545. if (copy_from_user(&conf->phys_settings,
  2546. settings->ifs_ifsu.te1, size)) {
  2547. return -EFAULT;
  2548. }/* Ignoring HDLC slot_map for a while */
  2549. if (conf->phys_settings.loopback) {
  2550. cpc_writeb(card->hw.scabase + M_REG(MD2, ch),
  2551. cpc_readb(card->hw.scabase + M_REG(MD2, ch)) |
  2552. MD2_LOOP_MIR);
  2553. }
  2554. conf->media = ifr->ifr_settings.type;
  2555. return 0;
  2556. }
  2557. default:
  2558. return hdlc_ioctl(dev, ifr, cmd);
  2559. }
  2560. default:
  2561. return hdlc_ioctl(dev, ifr, cmd);
  2562. }
  2563. }
  2564. static int clock_rate_calc(u32 rate, u32 clock, int *br_io)
  2565. {
  2566. int br, tc;
  2567. int br_pwr, error;
  2568. *br_io = 0;
  2569. if (rate == 0)
  2570. return 0;
  2571. for (br = 0, br_pwr = 1; br <= 9; br++, br_pwr <<= 1) {
  2572. if ((tc = clock / br_pwr / rate) <= 0xff) {
  2573. *br_io = br;
  2574. break;
  2575. }
  2576. }
  2577. if (tc <= 0xff) {
  2578. error = ((rate - (clock / br_pwr / rate)) / rate) * 1000;
  2579. /* Errors bigger than +/- 1% won't be tolerated */
  2580. if (error < -10 || error > 10)
  2581. return -1;
  2582. else
  2583. return tc;
  2584. } else {
  2585. return -1;
  2586. }
  2587. }
  2588. static int ch_config(pc300dev_t * d)
  2589. {
  2590. pc300ch_t *chan = (pc300ch_t *) d->chan;
  2591. pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
  2592. pc300_t *card = (pc300_t *) chan->card;
  2593. void __iomem *scabase = card->hw.scabase;
  2594. void __iomem *plxbase = card->hw.plxbase;
  2595. int ch = chan->channel;
  2596. u32 clkrate = chan->conf.phys_settings.clock_rate;
  2597. u32 clktype = chan->conf.phys_settings.clock_type;
  2598. u16 encoding = chan->conf.proto_settings.encoding;
  2599. u16 parity = chan->conf.proto_settings.parity;
  2600. u8 md0, md2;
  2601. /* Reset the channel */
  2602. cpc_writeb(scabase + M_REG(CMD, ch), CMD_CH_RST);
  2603. /* Configure the SCA registers */
  2604. switch (parity) {
  2605. case PARITY_NONE:
  2606. md0 = MD0_BIT_SYNC;
  2607. break;
  2608. case PARITY_CRC16_PR0:
  2609. md0 = MD0_CRC16_0|MD0_CRCC0|MD0_BIT_SYNC;
  2610. break;
  2611. case PARITY_CRC16_PR1:
  2612. md0 = MD0_CRC16_1|MD0_CRCC0|MD0_BIT_SYNC;
  2613. break;
  2614. case PARITY_CRC32_PR1_CCITT:
  2615. md0 = MD0_CRC32|MD0_CRCC0|MD0_BIT_SYNC;
  2616. break;
  2617. case PARITY_CRC16_PR1_CCITT:
  2618. default:
  2619. md0 = MD0_CRC_CCITT|MD0_CRCC0|MD0_BIT_SYNC;
  2620. break;
  2621. }
  2622. switch (encoding) {
  2623. case ENCODING_NRZI:
  2624. md2 = MD2_F_DUPLEX|MD2_ADPLL_X8|MD2_NRZI;
  2625. break;
  2626. case ENCODING_FM_MARK: /* FM1 */
  2627. md2 = MD2_F_DUPLEX|MD2_ADPLL_X8|MD2_FM|MD2_FM1;
  2628. break;
  2629. case ENCODING_FM_SPACE: /* FM0 */
  2630. md2 = MD2_F_DUPLEX|MD2_ADPLL_X8|MD2_FM|MD2_FM0;
  2631. break;
  2632. case ENCODING_MANCHESTER: /* It's not working... */
  2633. md2 = MD2_F_DUPLEX|MD2_ADPLL_X8|MD2_FM|MD2_MANCH;
  2634. break;
  2635. case ENCODING_NRZ:
  2636. default:
  2637. md2 = MD2_F_DUPLEX|MD2_ADPLL_X8|MD2_NRZ;
  2638. break;
  2639. }
  2640. cpc_writeb(scabase + M_REG(MD0, ch), md0);
  2641. cpc_writeb(scabase + M_REG(MD1, ch), 0);
  2642. cpc_writeb(scabase + M_REG(MD2, ch), md2);
  2643. cpc_writeb(scabase + M_REG(IDL, ch), 0x7e);
  2644. cpc_writeb(scabase + M_REG(CTL, ch), CTL_URSKP | CTL_IDLC);
  2645. /* Configure HW media */
  2646. switch (card->hw.type) {
  2647. case PC300_RSV:
  2648. if (conf->media == IF_IFACE_V35) {
  2649. cpc_writel((plxbase + card->hw.gpioc_reg),
  2650. cpc_readl(plxbase + card->hw.gpioc_reg) | PC300_CHMEDIA_MASK(ch));
  2651. } else {
  2652. cpc_writel((plxbase + card->hw.gpioc_reg),
  2653. cpc_readl(plxbase + card->hw.gpioc_reg) & ~PC300_CHMEDIA_MASK(ch));
  2654. }
  2655. break;
  2656. case PC300_X21:
  2657. break;
  2658. case PC300_TE:
  2659. te_config(card, ch);
  2660. break;
  2661. }
  2662. switch (card->hw.type) {
  2663. case PC300_RSV:
  2664. case PC300_X21:
  2665. if (clktype == CLOCK_INT || clktype == CLOCK_TXINT) {
  2666. int tmc, br;
  2667. /* Calculate the clkrate parameters */
  2668. tmc = clock_rate_calc(clkrate, card->hw.clock, &br);
  2669. if (tmc < 0)
  2670. return -EIO;
  2671. cpc_writeb(scabase + M_REG(TMCT, ch), tmc);
  2672. cpc_writeb(scabase + M_REG(TXS, ch),
  2673. (TXS_DTRXC | TXS_IBRG | br));
  2674. if (clktype == CLOCK_INT) {
  2675. cpc_writeb(scabase + M_REG(TMCR, ch), tmc);
  2676. cpc_writeb(scabase + M_REG(RXS, ch),
  2677. (RXS_IBRG | br));
  2678. } else {
  2679. cpc_writeb(scabase + M_REG(TMCR, ch), 1);
  2680. cpc_writeb(scabase + M_REG(RXS, ch), 0);
  2681. }
  2682. if (card->hw.type == PC300_X21) {
  2683. cpc_writeb(scabase + M_REG(GPO, ch), 1);
  2684. cpc_writeb(scabase + M_REG(EXS, ch), EXS_TES1 | EXS_RES1);
  2685. } else {
  2686. cpc_writeb(scabase + M_REG(EXS, ch), EXS_TES1);
  2687. }
  2688. } else {
  2689. cpc_writeb(scabase + M_REG(TMCT, ch), 1);
  2690. if (clktype == CLOCK_EXT) {
  2691. cpc_writeb(scabase + M_REG(TXS, ch),
  2692. TXS_DTRXC);
  2693. } else {
  2694. cpc_writeb(scabase + M_REG(TXS, ch),
  2695. TXS_DTRXC|TXS_RCLK);
  2696. }
  2697. cpc_writeb(scabase + M_REG(TMCR, ch), 1);
  2698. cpc_writeb(scabase + M_REG(RXS, ch), 0);
  2699. if (card->hw.type == PC300_X21) {
  2700. cpc_writeb(scabase + M_REG(GPO, ch), 0);
  2701. cpc_writeb(scabase + M_REG(EXS, ch), EXS_TES1 | EXS_RES1);
  2702. } else {
  2703. cpc_writeb(scabase + M_REG(EXS, ch), EXS_TES1);
  2704. }
  2705. }
  2706. break;
  2707. case PC300_TE:
  2708. /* SCA always receives clock from the FALC chip */
  2709. cpc_writeb(scabase + M_REG(TMCT, ch), 1);
  2710. cpc_writeb(scabase + M_REG(TXS, ch), 0);
  2711. cpc_writeb(scabase + M_REG(TMCR, ch), 1);
  2712. cpc_writeb(scabase + M_REG(RXS, ch), 0);
  2713. cpc_writeb(scabase + M_REG(EXS, ch), 0);
  2714. break;
  2715. }
  2716. /* Enable Interrupts */
  2717. cpc_writel(scabase + IER0,
  2718. cpc_readl(scabase + IER0) |
  2719. IR0_M(IR0_RXINTA, ch) |
  2720. IR0_DRX(IR0_EFT | IR0_DMIA | IR0_DMIB, ch) |
  2721. IR0_DTX(IR0_EFT | IR0_DMIA | IR0_DMIB, ch));
  2722. cpc_writeb(scabase + M_REG(IE0, ch),
  2723. cpc_readl(scabase + M_REG(IE0, ch)) | IE0_RXINTA);
  2724. cpc_writeb(scabase + M_REG(IE1, ch),
  2725. cpc_readl(scabase + M_REG(IE1, ch)) | IE1_CDCD);
  2726. return 0;
  2727. }
  2728. static int rx_config(pc300dev_t * d)
  2729. {
  2730. pc300ch_t *chan = (pc300ch_t *) d->chan;
  2731. pc300_t *card = (pc300_t *) chan->card;
  2732. void __iomem *scabase = card->hw.scabase;
  2733. int ch = chan->channel;
  2734. cpc_writeb(scabase + DSR_RX(ch), 0);
  2735. /* General RX settings */
  2736. cpc_writeb(scabase + M_REG(RRC, ch), 0);
  2737. cpc_writeb(scabase + M_REG(RNR, ch), 16);
  2738. /* Enable reception */
  2739. cpc_writeb(scabase + M_REG(CMD, ch), CMD_RX_CRC_INIT);
  2740. cpc_writeb(scabase + M_REG(CMD, ch), CMD_RX_ENA);
  2741. /* Initialize DMA stuff */
  2742. chan->rx_first_bd = 0;
  2743. chan->rx_last_bd = N_DMA_RX_BUF - 1;
  2744. rx_dma_buf_init(card, ch);
  2745. cpc_writeb(scabase + DCR_RX(ch), DCR_FCT_CLR);
  2746. cpc_writeb(scabase + DMR_RX(ch), (DMR_TMOD | DMR_NF));
  2747. cpc_writeb(scabase + DIR_RX(ch), (DIR_EOM | DIR_BOF));
  2748. /* Start DMA */
  2749. rx_dma_start(card, ch);
  2750. return 0;
  2751. }
  2752. static int tx_config(pc300dev_t * d)
  2753. {
  2754. pc300ch_t *chan = (pc300ch_t *) d->chan;
  2755. pc300_t *card = (pc300_t *) chan->card;
  2756. void __iomem *scabase = card->hw.scabase;
  2757. int ch = chan->channel;
  2758. cpc_writeb(scabase + DSR_TX(ch), 0);
  2759. /* General TX settings */
  2760. cpc_writeb(scabase + M_REG(TRC0, ch), 0);
  2761. cpc_writeb(scabase + M_REG(TFS, ch), 32);
  2762. cpc_writeb(scabase + M_REG(TNR0, ch), 20);
  2763. cpc_writeb(scabase + M_REG(TNR1, ch), 48);
  2764. cpc_writeb(scabase + M_REG(TCR, ch), 8);
  2765. /* Enable transmission */
  2766. cpc_writeb(scabase + M_REG(CMD, ch), CMD_TX_CRC_INIT);
  2767. /* Initialize DMA stuff */
  2768. chan->tx_first_bd = 0;
  2769. chan->tx_next_bd = 0;
  2770. tx_dma_buf_init(card, ch);
  2771. cpc_writeb(scabase + DCR_TX(ch), DCR_FCT_CLR);
  2772. cpc_writeb(scabase + DMR_TX(ch), (DMR_TMOD | DMR_NF));
  2773. cpc_writeb(scabase + DIR_TX(ch), (DIR_EOM | DIR_BOF | DIR_UDRF));
  2774. cpc_writel(scabase + DTX_REG(CDAL, ch), TX_BD_ADDR(ch, chan->tx_first_bd));
  2775. cpc_writel(scabase + DTX_REG(EDAL, ch), TX_BD_ADDR(ch, chan->tx_next_bd));
  2776. return 0;
  2777. }
  2778. static int cpc_attach(struct net_device *dev, unsigned short encoding,
  2779. unsigned short parity)
  2780. {
  2781. pc300dev_t *d = (pc300dev_t *)dev_to_hdlc(dev)->priv;
  2782. pc300ch_t *chan = (pc300ch_t *)d->chan;
  2783. pc300_t *card = (pc300_t *)chan->card;
  2784. pc300chconf_t *conf = (pc300chconf_t *)&chan->conf;
  2785. if (card->hw.type == PC300_TE) {
  2786. if (encoding != ENCODING_NRZ && encoding != ENCODING_NRZI) {
  2787. return -EINVAL;
  2788. }
  2789. } else {
  2790. if (encoding != ENCODING_NRZ && encoding != ENCODING_NRZI &&
  2791. encoding != ENCODING_FM_MARK && encoding != ENCODING_FM_SPACE) {
  2792. /* Driver doesn't support ENCODING_MANCHESTER yet */
  2793. return -EINVAL;
  2794. }
  2795. }
  2796. if (parity != PARITY_NONE && parity != PARITY_CRC16_PR0 &&
  2797. parity != PARITY_CRC16_PR1 && parity != PARITY_CRC32_PR1_CCITT &&
  2798. parity != PARITY_CRC16_PR1_CCITT) {
  2799. return -EINVAL;
  2800. }
  2801. conf->proto_settings.encoding = encoding;
  2802. conf->proto_settings.parity = parity;
  2803. return 0;
  2804. }
  2805. static int cpc_opench(pc300dev_t * d)
  2806. {
  2807. pc300ch_t *chan = (pc300ch_t *) d->chan;
  2808. pc300_t *card = (pc300_t *) chan->card;
  2809. int ch = chan->channel, rc;
  2810. void __iomem *scabase = card->hw.scabase;
  2811. rc = ch_config(d);
  2812. if (rc)
  2813. return rc;
  2814. rx_config(d);
  2815. tx_config(d);
  2816. /* Assert RTS and DTR */
  2817. cpc_writeb(scabase + M_REG(CTL, ch),
  2818. cpc_readb(scabase + M_REG(CTL, ch)) & ~(CTL_RTS | CTL_DTR));
  2819. return 0;
  2820. }
  2821. static void cpc_closech(pc300dev_t * d)
  2822. {
  2823. pc300ch_t *chan = (pc300ch_t *) d->chan;
  2824. pc300_t *card = (pc300_t *) chan->card;
  2825. falc_t *pfalc = (falc_t *) & chan->falc;
  2826. int ch = chan->channel;
  2827. cpc_writeb(card->hw.scabase + M_REG(CMD, ch), CMD_CH_RST);
  2828. rx_dma_stop(card, ch);
  2829. tx_dma_stop(card, ch);
  2830. if (card->hw.type == PC300_TE) {
  2831. memset(pfalc, 0, sizeof(falc_t));
  2832. cpc_writeb(card->hw.falcbase + card->hw.cpld_reg2,
  2833. cpc_readb(card->hw.falcbase + card->hw.cpld_reg2) &
  2834. ~((CPLD_REG2_FALC_TX_CLK | CPLD_REG2_FALC_RX_CLK |
  2835. CPLD_REG2_FALC_LED2) << (2 * ch)));
  2836. /* Reset the FALC chip */
  2837. cpc_writeb(card->hw.falcbase + card->hw.cpld_reg1,
  2838. cpc_readb(card->hw.falcbase + card->hw.cpld_reg1) |
  2839. (CPLD_REG1_FALC_RESET << (2 * ch)));
  2840. udelay(10000);
  2841. cpc_writeb(card->hw.falcbase + card->hw.cpld_reg1,
  2842. cpc_readb(card->hw.falcbase + card->hw.cpld_reg1) &
  2843. ~(CPLD_REG1_FALC_RESET << (2 * ch)));
  2844. }
  2845. }
  2846. int cpc_open(struct net_device *dev)
  2847. {
  2848. pc300dev_t *d = (pc300dev_t *) dev_to_hdlc(dev)->priv;
  2849. struct ifreq ifr;
  2850. int result;
  2851. #ifdef PC300_DEBUG_OTHER
  2852. printk("pc300: cpc_open");
  2853. #endif
  2854. result = hdlc_open(dev);
  2855. if (result)
  2856. return result;
  2857. sprintf(ifr.ifr_name, "%s", dev->name);
  2858. result = cpc_opench(d);
  2859. if (result)
  2860. goto err_out;
  2861. netif_start_queue(dev);
  2862. return 0;
  2863. err_out:
  2864. hdlc_close(dev);
  2865. return result;
  2866. }
  2867. static int cpc_close(struct net_device *dev)
  2868. {
  2869. pc300dev_t *d = (pc300dev_t *) dev_to_hdlc(dev)->priv;
  2870. pc300ch_t *chan = (pc300ch_t *) d->chan;
  2871. pc300_t *card = (pc300_t *) chan->card;
  2872. unsigned long flags;
  2873. #ifdef PC300_DEBUG_OTHER
  2874. printk("pc300: cpc_close");
  2875. #endif
  2876. netif_stop_queue(dev);
  2877. CPC_LOCK(card, flags);
  2878. cpc_closech(d);
  2879. CPC_UNLOCK(card, flags);
  2880. hdlc_close(dev);
  2881. #ifdef CONFIG_PC300_MLPPP
  2882. if (chan->conf.proto == PC300_PROTO_MLPPP) {
  2883. cpc_tty_unregister_service(d);
  2884. chan->conf.proto = 0xffff;
  2885. }
  2886. #endif
  2887. return 0;
  2888. }
  2889. static u32 detect_ram(pc300_t * card)
  2890. {
  2891. u32 i;
  2892. u8 data;
  2893. void __iomem *rambase = card->hw.rambase;
  2894. card->hw.ramsize = PC300_RAMSIZE;
  2895. /* Let's find out how much RAM is present on this board */
  2896. for (i = 0; i < card->hw.ramsize; i++) {
  2897. data = (u8)(i & 0xff);
  2898. cpc_writeb(rambase + i, data);
  2899. if (cpc_readb(rambase + i) != data) {
  2900. break;
  2901. }
  2902. }
  2903. return i;
  2904. }
  2905. static void plx_init(pc300_t * card)
  2906. {
  2907. struct RUNTIME_9050 __iomem *plx_ctl = card->hw.plxbase;
  2908. /* Reset PLX */
  2909. cpc_writel(&plx_ctl->init_ctrl,
  2910. cpc_readl(&plx_ctl->init_ctrl) | 0x40000000);
  2911. udelay(10000L);
  2912. cpc_writel(&plx_ctl->init_ctrl,
  2913. cpc_readl(&plx_ctl->init_ctrl) & ~0x40000000);
  2914. /* Reload Config. Registers from EEPROM */
  2915. cpc_writel(&plx_ctl->init_ctrl,
  2916. cpc_readl(&plx_ctl->init_ctrl) | 0x20000000);
  2917. udelay(10000L);
  2918. cpc_writel(&plx_ctl->init_ctrl,
  2919. cpc_readl(&plx_ctl->init_ctrl) & ~0x20000000);
  2920. }
  2921. static inline void show_version(void)
  2922. {
  2923. char *rcsvers, *rcsdate, *tmp;
  2924. rcsvers = strchr(rcsid, ' ');
  2925. rcsvers++;
  2926. tmp = strchr(rcsvers, ' ');
  2927. *tmp++ = '\0';
  2928. rcsdate = strchr(tmp, ' ');
  2929. rcsdate++;
  2930. tmp = strrchr(rcsdate, ' ');
  2931. *tmp = '\0';
  2932. printk(KERN_INFO "Cyclades-PC300 driver %s %s\n", rcsvers, rcsdate);
  2933. } /* show_version */
  2934. static const struct net_device_ops cpc_netdev_ops = {
  2935. .ndo_open = cpc_open,
  2936. .ndo_stop = cpc_close,
  2937. .ndo_tx_timeout = cpc_tx_timeout,
  2938. .ndo_set_mac_address = NULL,
  2939. .ndo_change_mtu = cpc_change_mtu,
  2940. .ndo_do_ioctl = cpc_ioctl,
  2941. .ndo_validate_addr = eth_validate_addr,
  2942. };
  2943. static void cpc_init_card(pc300_t * card)
  2944. {
  2945. int i, devcount = 0;
  2946. static int board_nbr = 1;
  2947. /* Enable interrupts on the PCI bridge */
  2948. plx_init(card);
  2949. cpc_writew(card->hw.plxbase + card->hw.intctl_reg,
  2950. cpc_readw(card->hw.plxbase + card->hw.intctl_reg) | 0x0040);
  2951. #ifdef USE_PCI_CLOCK
  2952. /* Set board clock to PCI clock */
  2953. cpc_writel(card->hw.plxbase + card->hw.gpioc_reg,
  2954. cpc_readl(card->hw.plxbase + card->hw.gpioc_reg) | 0x00000004UL);
  2955. card->hw.clock = PC300_PCI_CLOCK;
  2956. #else
  2957. /* Set board clock to internal oscillator clock */
  2958. cpc_writel(card->hw.plxbase + card->hw.gpioc_reg,
  2959. cpc_readl(card->hw.plxbase + card->hw.gpioc_reg) & ~0x00000004UL);
  2960. card->hw.clock = PC300_OSC_CLOCK;
  2961. #endif
  2962. /* Detect actual on-board RAM size */
  2963. card->hw.ramsize = detect_ram(card);
  2964. /* Set Global SCA-II registers */
  2965. cpc_writeb(card->hw.scabase + PCR, PCR_PR2);
  2966. cpc_writeb(card->hw.scabase + BTCR, 0x10);
  2967. cpc_writeb(card->hw.scabase + WCRL, 0);
  2968. cpc_writeb(card->hw.scabase + DMER, 0x80);
  2969. if (card->hw.type == PC300_TE) {
  2970. u8 reg1;
  2971. /* Check CPLD version */
  2972. reg1 = cpc_readb(card->hw.falcbase + CPLD_REG1);
  2973. cpc_writeb(card->hw.falcbase + CPLD_REG1, (reg1 + 0x5a));
  2974. if (cpc_readb(card->hw.falcbase + CPLD_REG1) == reg1) {
  2975. /* New CPLD */
  2976. card->hw.cpld_id = cpc_readb(card->hw.falcbase + CPLD_ID_REG);
  2977. card->hw.cpld_reg1 = CPLD_V2_REG1;
  2978. card->hw.cpld_reg2 = CPLD_V2_REG2;
  2979. } else {
  2980. /* old CPLD */
  2981. card->hw.cpld_id = 0;
  2982. card->hw.cpld_reg1 = CPLD_REG1;
  2983. card->hw.cpld_reg2 = CPLD_REG2;
  2984. cpc_writeb(card->hw.falcbase + CPLD_REG1, reg1);
  2985. }
  2986. /* Enable the board's global clock */
  2987. cpc_writeb(card->hw.falcbase + card->hw.cpld_reg1,
  2988. cpc_readb(card->hw.falcbase + card->hw.cpld_reg1) |
  2989. CPLD_REG1_GLOBAL_CLK);
  2990. }
  2991. for (i = 0; i < card->hw.nchan; i++) {
  2992. pc300ch_t *chan = &card->chan[i];
  2993. pc300dev_t *d = &chan->d;
  2994. hdlc_device *hdlc;
  2995. struct net_device *dev;
  2996. chan->card = card;
  2997. chan->channel = i;
  2998. chan->conf.phys_settings.clock_rate = 0;
  2999. chan->conf.phys_settings.clock_type = CLOCK_EXT;
  3000. chan->conf.proto_settings.encoding = ENCODING_NRZ;
  3001. chan->conf.proto_settings.parity = PARITY_CRC16_PR1_CCITT;
  3002. switch (card->hw.type) {
  3003. case PC300_TE:
  3004. chan->conf.media = IF_IFACE_T1;
  3005. chan->conf.lcode = PC300_LC_B8ZS;
  3006. chan->conf.fr_mode = PC300_FR_ESF;
  3007. chan->conf.lbo = PC300_LBO_0_DB;
  3008. chan->conf.rx_sens = PC300_RX_SENS_SH;
  3009. chan->conf.tslot_bitmap = 0xffffffffUL;
  3010. break;
  3011. case PC300_X21:
  3012. chan->conf.media = IF_IFACE_X21;
  3013. break;
  3014. case PC300_RSV:
  3015. default:
  3016. chan->conf.media = IF_IFACE_V35;
  3017. break;
  3018. }
  3019. chan->conf.proto = IF_PROTO_PPP;
  3020. chan->tx_first_bd = 0;
  3021. chan->tx_next_bd = 0;
  3022. chan->rx_first_bd = 0;
  3023. chan->rx_last_bd = N_DMA_RX_BUF - 1;
  3024. chan->nfree_tx_bd = N_DMA_TX_BUF;
  3025. d->chan = chan;
  3026. d->trace_on = 0;
  3027. d->line_on = 0;
  3028. d->line_off = 0;
  3029. dev = alloc_hdlcdev(d);
  3030. if (dev == NULL)
  3031. continue;
  3032. hdlc = dev_to_hdlc(dev);
  3033. hdlc->xmit = cpc_queue_xmit;
  3034. hdlc->attach = cpc_attach;
  3035. d->dev = dev;
  3036. dev->mem_start = card->hw.ramphys;
  3037. dev->mem_end = card->hw.ramphys + card->hw.ramsize - 1;
  3038. dev->irq = card->hw.irq;
  3039. dev->tx_queue_len = PC300_TX_QUEUE_LEN;
  3040. dev->mtu = PC300_DEF_MTU;
  3041. dev->netdev_ops = &cpc_netdev_ops;
  3042. dev->watchdog_timeo = PC300_TX_TIMEOUT;
  3043. if (register_hdlc_device(dev) == 0) {
  3044. printk("%s: Cyclades-PC300/", dev->name);
  3045. switch (card->hw.type) {
  3046. case PC300_TE:
  3047. if (card->hw.bus == PC300_PMC) {
  3048. printk("TE-M");
  3049. } else {
  3050. printk("TE ");
  3051. }
  3052. break;
  3053. case PC300_X21:
  3054. printk("X21 ");
  3055. break;
  3056. case PC300_RSV:
  3057. default:
  3058. printk("RSV ");
  3059. break;
  3060. }
  3061. printk (" #%d, %dKB of RAM at 0x%08x, IRQ%d, channel %d.\n",
  3062. board_nbr, card->hw.ramsize / 1024,
  3063. card->hw.ramphys, card->hw.irq, i + 1);
  3064. devcount++;
  3065. } else {
  3066. printk ("Dev%d on card(0x%08x): unable to allocate i/f name.\n",
  3067. i + 1, card->hw.ramphys);
  3068. free_netdev(dev);
  3069. continue;
  3070. }
  3071. }
  3072. spin_lock_init(&card->card_lock);
  3073. board_nbr++;
  3074. }
  3075. static int __devinit
  3076. cpc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  3077. {
  3078. static int first_time = 1;
  3079. int err, eeprom_outdated = 0;
  3080. u16 device_id;
  3081. pc300_t *card;
  3082. if (first_time) {
  3083. first_time = 0;
  3084. show_version();
  3085. #ifdef CONFIG_PC300_MLPPP
  3086. cpc_tty_reset_var();
  3087. #endif
  3088. }
  3089. if ((err = pci_enable_device(pdev)) < 0)
  3090. return err;
  3091. card = kzalloc(sizeof(pc300_t), GFP_KERNEL);
  3092. if (card == NULL) {
  3093. printk("PC300 found at RAM 0x%016llx, "
  3094. "but could not allocate card structure.\n",
  3095. (unsigned long long)pci_resource_start(pdev, 3));
  3096. err = -ENOMEM;
  3097. goto err_disable_dev;
  3098. }
  3099. err = -ENODEV;
  3100. /* read PCI configuration area */
  3101. device_id = ent->device;
  3102. card->hw.irq = pdev->irq;
  3103. card->hw.iophys = pci_resource_start(pdev, 1);
  3104. card->hw.iosize = pci_resource_len(pdev, 1);
  3105. card->hw.scaphys = pci_resource_start(pdev, 2);
  3106. card->hw.scasize = pci_resource_len(pdev, 2);
  3107. card->hw.ramphys = pci_resource_start(pdev, 3);
  3108. card->hw.alloc_ramsize = pci_resource_len(pdev, 3);
  3109. card->hw.falcphys = pci_resource_start(pdev, 4);
  3110. card->hw.falcsize = pci_resource_len(pdev, 4);
  3111. card->hw.plxphys = pci_resource_start(pdev, 5);
  3112. card->hw.plxsize = pci_resource_len(pdev, 5);
  3113. switch (device_id) {
  3114. case PCI_DEVICE_ID_PC300_RX_1:
  3115. case PCI_DEVICE_ID_PC300_TE_1:
  3116. case PCI_DEVICE_ID_PC300_TE_M_1:
  3117. card->hw.nchan = 1;
  3118. break;
  3119. case PCI_DEVICE_ID_PC300_RX_2:
  3120. case PCI_DEVICE_ID_PC300_TE_2:
  3121. case PCI_DEVICE_ID_PC300_TE_M_2:
  3122. default:
  3123. card->hw.nchan = PC300_MAXCHAN;
  3124. break;
  3125. }
  3126. #ifdef PC300_DEBUG_PCI
  3127. printk("cpc (bus=0x0%x,pci_id=0x%x,", pdev->bus->number, pdev->devfn);
  3128. printk("rev_id=%d) IRQ%d\n", pdev->revision, card->hw.irq);
  3129. printk("cpc:found ramaddr=0x%08lx plxaddr=0x%08lx "
  3130. "ctladdr=0x%08lx falcaddr=0x%08lx\n",
  3131. card->hw.ramphys, card->hw.plxphys, card->hw.scaphys,
  3132. card->hw.falcphys);
  3133. #endif
  3134. /* Although we don't use this I/O region, we should
  3135. * request it from the kernel anyway, to avoid problems
  3136. * with other drivers accessing it. */
  3137. if (!request_region(card->hw.iophys, card->hw.iosize, "PLX Registers")) {
  3138. /* In case we can't allocate it, warn user */
  3139. printk("WARNING: couldn't allocate I/O region for PC300 board "
  3140. "at 0x%08x!\n", card->hw.ramphys);
  3141. }
  3142. if (card->hw.plxphys) {
  3143. pci_write_config_dword(pdev, PCI_BASE_ADDRESS_0, card->hw.plxphys);
  3144. } else {
  3145. eeprom_outdated = 1;
  3146. card->hw.plxphys = pci_resource_start(pdev, 0);
  3147. card->hw.plxsize = pci_resource_len(pdev, 0);
  3148. }
  3149. if (!request_mem_region(card->hw.plxphys, card->hw.plxsize,
  3150. "PLX Registers")) {
  3151. printk("PC300 found at RAM 0x%08x, "
  3152. "but could not allocate PLX mem region.\n",
  3153. card->hw.ramphys);
  3154. goto err_release_io;
  3155. }
  3156. if (!request_mem_region(card->hw.ramphys, card->hw.alloc_ramsize,
  3157. "On-board RAM")) {
  3158. printk("PC300 found at RAM 0x%08x, "
  3159. "but could not allocate RAM mem region.\n",
  3160. card->hw.ramphys);
  3161. goto err_release_plx;
  3162. }
  3163. if (!request_mem_region(card->hw.scaphys, card->hw.scasize,
  3164. "SCA-II Registers")) {
  3165. printk("PC300 found at RAM 0x%08x, "
  3166. "but could not allocate SCA mem region.\n",
  3167. card->hw.ramphys);
  3168. goto err_release_ram;
  3169. }
  3170. card->hw.plxbase = ioremap(card->hw.plxphys, card->hw.plxsize);
  3171. card->hw.rambase = ioremap(card->hw.ramphys, card->hw.alloc_ramsize);
  3172. card->hw.scabase = ioremap(card->hw.scaphys, card->hw.scasize);
  3173. switch (device_id) {
  3174. case PCI_DEVICE_ID_PC300_TE_1:
  3175. case PCI_DEVICE_ID_PC300_TE_2:
  3176. case PCI_DEVICE_ID_PC300_TE_M_1:
  3177. case PCI_DEVICE_ID_PC300_TE_M_2:
  3178. request_mem_region(card->hw.falcphys, card->hw.falcsize,
  3179. "FALC Registers");
  3180. card->hw.falcbase = ioremap(card->hw.falcphys, card->hw.falcsize);
  3181. break;
  3182. case PCI_DEVICE_ID_PC300_RX_1:
  3183. case PCI_DEVICE_ID_PC300_RX_2:
  3184. default:
  3185. card->hw.falcbase = NULL;
  3186. break;
  3187. }
  3188. #ifdef PC300_DEBUG_PCI
  3189. printk("cpc: relocate ramaddr=0x%08lx plxaddr=0x%08lx "
  3190. "ctladdr=0x%08lx falcaddr=0x%08lx\n",
  3191. card->hw.rambase, card->hw.plxbase, card->hw.scabase,
  3192. card->hw.falcbase);
  3193. #endif
  3194. /* Set PCI drv pointer to the card structure */
  3195. pci_set_drvdata(pdev, card);
  3196. /* Set board type */
  3197. switch (device_id) {
  3198. case PCI_DEVICE_ID_PC300_TE_1:
  3199. case PCI_DEVICE_ID_PC300_TE_2:
  3200. case PCI_DEVICE_ID_PC300_TE_M_1:
  3201. case PCI_DEVICE_ID_PC300_TE_M_2:
  3202. card->hw.type = PC300_TE;
  3203. if ((device_id == PCI_DEVICE_ID_PC300_TE_M_1) ||
  3204. (device_id == PCI_DEVICE_ID_PC300_TE_M_2)) {
  3205. card->hw.bus = PC300_PMC;
  3206. /* Set PLX register offsets */
  3207. card->hw.gpioc_reg = 0x54;
  3208. card->hw.intctl_reg = 0x4c;
  3209. } else {
  3210. card->hw.bus = PC300_PCI;
  3211. /* Set PLX register offsets */
  3212. card->hw.gpioc_reg = 0x50;
  3213. card->hw.intctl_reg = 0x4c;
  3214. }
  3215. break;
  3216. case PCI_DEVICE_ID_PC300_RX_1:
  3217. case PCI_DEVICE_ID_PC300_RX_2:
  3218. default:
  3219. card->hw.bus = PC300_PCI;
  3220. /* Set PLX register offsets */
  3221. card->hw.gpioc_reg = 0x50;
  3222. card->hw.intctl_reg = 0x4c;
  3223. if ((cpc_readl(card->hw.plxbase + card->hw.gpioc_reg) & PC300_CTYPE_MASK)) {
  3224. card->hw.type = PC300_X21;
  3225. } else {
  3226. card->hw.type = PC300_RSV;
  3227. }
  3228. break;
  3229. }
  3230. /* Allocate IRQ */
  3231. if (request_irq(card->hw.irq, cpc_intr, IRQF_SHARED, "Cyclades-PC300", card)) {
  3232. printk ("PC300 found at RAM 0x%08x, but could not allocate IRQ%d.\n",
  3233. card->hw.ramphys, card->hw.irq);
  3234. goto err_io_unmap;
  3235. }
  3236. cpc_init_card(card);
  3237. if (eeprom_outdated)
  3238. printk("WARNING: PC300 with outdated EEPROM.\n");
  3239. return 0;
  3240. err_io_unmap:
  3241. iounmap(card->hw.plxbase);
  3242. iounmap(card->hw.scabase);
  3243. iounmap(card->hw.rambase);
  3244. if (card->hw.type == PC300_TE) {
  3245. iounmap(card->hw.falcbase);
  3246. release_mem_region(card->hw.falcphys, card->hw.falcsize);
  3247. }
  3248. release_mem_region(card->hw.scaphys, card->hw.scasize);
  3249. err_release_ram:
  3250. release_mem_region(card->hw.ramphys, card->hw.alloc_ramsize);
  3251. err_release_plx:
  3252. release_mem_region(card->hw.plxphys, card->hw.plxsize);
  3253. err_release_io:
  3254. release_region(card->hw.iophys, card->hw.iosize);
  3255. kfree(card);
  3256. err_disable_dev:
  3257. pci_disable_device(pdev);
  3258. return err;
  3259. }
  3260. static void __devexit cpc_remove_one(struct pci_dev *pdev)
  3261. {
  3262. pc300_t *card = pci_get_drvdata(pdev);
  3263. if (card->hw.rambase) {
  3264. int i;
  3265. /* Disable interrupts on the PCI bridge */
  3266. cpc_writew(card->hw.plxbase + card->hw.intctl_reg,
  3267. cpc_readw(card->hw.plxbase + card->hw.intctl_reg) & ~(0x0040));
  3268. for (i = 0; i < card->hw.nchan; i++) {
  3269. unregister_hdlc_device(card->chan[i].d.dev);
  3270. }
  3271. iounmap(card->hw.plxbase);
  3272. iounmap(card->hw.scabase);
  3273. iounmap(card->hw.rambase);
  3274. release_mem_region(card->hw.plxphys, card->hw.plxsize);
  3275. release_mem_region(card->hw.ramphys, card->hw.alloc_ramsize);
  3276. release_mem_region(card->hw.scaphys, card->hw.scasize);
  3277. release_region(card->hw.iophys, card->hw.iosize);
  3278. if (card->hw.type == PC300_TE) {
  3279. iounmap(card->hw.falcbase);
  3280. release_mem_region(card->hw.falcphys, card->hw.falcsize);
  3281. }
  3282. for (i = 0; i < card->hw.nchan; i++)
  3283. if (card->chan[i].d.dev)
  3284. free_netdev(card->chan[i].d.dev);
  3285. if (card->hw.irq)
  3286. free_irq(card->hw.irq, card);
  3287. kfree(card);
  3288. pci_disable_device(pdev);
  3289. }
  3290. }
  3291. static struct pci_driver cpc_driver = {
  3292. .name = "pc300",
  3293. .id_table = cpc_pci_dev_id,
  3294. .probe = cpc_init_one,
  3295. .remove = __devexit_p(cpc_remove_one),
  3296. };
  3297. static int __init cpc_init(void)
  3298. {
  3299. return pci_register_driver(&cpc_driver);
  3300. }
  3301. static void __exit cpc_cleanup_module(void)
  3302. {
  3303. pci_unregister_driver(&cpc_driver);
  3304. }
  3305. module_init(cpc_init);
  3306. module_exit(cpc_cleanup_module);
  3307. MODULE_DESCRIPTION("Cyclades-PC300 cards driver");
  3308. MODULE_AUTHOR( "Author: Ivan Passos <ivan@cyclades.com>\r\n"
  3309. "Maintainer: PC300 Maintainer <pc300@cyclades.com");
  3310. MODULE_LICENSE("GPL");