idt77252.c 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804
  1. /*******************************************************************
  2. *
  3. * Copyright (c) 2000 ATecoM GmbH
  4. *
  5. * The author may be reached at ecd@atecom.com.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  13. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  14. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  15. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  16. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  17. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  18. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  19. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  20. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  21. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. *
  23. * You should have received a copy of the GNU General Public License along
  24. * with this program; if not, write to the Free Software Foundation, Inc.,
  25. * 675 Mass Ave, Cambridge, MA 02139, USA.
  26. *
  27. *******************************************************************/
  28. #include <linux/module.h>
  29. #include <linux/pci.h>
  30. #include <linux/poison.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/kernel.h>
  33. #include <linux/vmalloc.h>
  34. #include <linux/netdevice.h>
  35. #include <linux/atmdev.h>
  36. #include <linux/atm.h>
  37. #include <linux/delay.h>
  38. #include <linux/init.h>
  39. #include <linux/interrupt.h>
  40. #include <linux/bitops.h>
  41. #include <linux/wait.h>
  42. #include <linux/jiffies.h>
  43. #include <linux/mutex.h>
  44. #include <linux/slab.h>
  45. #include <asm/io.h>
  46. #include <asm/uaccess.h>
  47. #include <linux/atomic.h>
  48. #include <asm/byteorder.h>
  49. #ifdef CONFIG_ATM_IDT77252_USE_SUNI
  50. #include "suni.h"
  51. #endif /* CONFIG_ATM_IDT77252_USE_SUNI */
  52. #include "idt77252.h"
  53. #include "idt77252_tables.h"
  54. static unsigned int vpibits = 1;
  55. #define ATM_IDT77252_SEND_IDLE 1
  56. /*
  57. * Debug HACKs.
  58. */
  59. #define DEBUG_MODULE 1
  60. #undef HAVE_EEPROM /* does not work, yet. */
  61. #ifdef CONFIG_ATM_IDT77252_DEBUG
  62. static unsigned long debug = DBG_GENERAL;
  63. #endif
  64. #define SAR_RX_DELAY (SAR_CFG_RXINT_NODELAY)
  65. /*
  66. * SCQ Handling.
  67. */
  68. static struct scq_info *alloc_scq(struct idt77252_dev *, int);
  69. static void free_scq(struct idt77252_dev *, struct scq_info *);
  70. static int queue_skb(struct idt77252_dev *, struct vc_map *,
  71. struct sk_buff *, int oam);
  72. static void drain_scq(struct idt77252_dev *, struct vc_map *);
  73. static unsigned long get_free_scd(struct idt77252_dev *, struct vc_map *);
  74. static void fill_scd(struct idt77252_dev *, struct scq_info *, int);
  75. /*
  76. * FBQ Handling.
  77. */
  78. static int push_rx_skb(struct idt77252_dev *,
  79. struct sk_buff *, int queue);
  80. static void recycle_rx_skb(struct idt77252_dev *, struct sk_buff *);
  81. static void flush_rx_pool(struct idt77252_dev *, struct rx_pool *);
  82. static void recycle_rx_pool_skb(struct idt77252_dev *,
  83. struct rx_pool *);
  84. static void add_rx_skb(struct idt77252_dev *, int queue,
  85. unsigned int size, unsigned int count);
  86. /*
  87. * RSQ Handling.
  88. */
  89. static int init_rsq(struct idt77252_dev *);
  90. static void deinit_rsq(struct idt77252_dev *);
  91. static void idt77252_rx(struct idt77252_dev *);
  92. /*
  93. * TSQ handling.
  94. */
  95. static int init_tsq(struct idt77252_dev *);
  96. static void deinit_tsq(struct idt77252_dev *);
  97. static void idt77252_tx(struct idt77252_dev *);
  98. /*
  99. * ATM Interface.
  100. */
  101. static void idt77252_dev_close(struct atm_dev *dev);
  102. static int idt77252_open(struct atm_vcc *vcc);
  103. static void idt77252_close(struct atm_vcc *vcc);
  104. static int idt77252_send(struct atm_vcc *vcc, struct sk_buff *skb);
  105. static int idt77252_send_oam(struct atm_vcc *vcc, void *cell,
  106. int flags);
  107. static void idt77252_phy_put(struct atm_dev *dev, unsigned char value,
  108. unsigned long addr);
  109. static unsigned char idt77252_phy_get(struct atm_dev *dev, unsigned long addr);
  110. static int idt77252_change_qos(struct atm_vcc *vcc, struct atm_qos *qos,
  111. int flags);
  112. static int idt77252_proc_read(struct atm_dev *dev, loff_t * pos,
  113. char *page);
  114. static void idt77252_softint(struct work_struct *work);
  115. static struct atmdev_ops idt77252_ops =
  116. {
  117. .dev_close = idt77252_dev_close,
  118. .open = idt77252_open,
  119. .close = idt77252_close,
  120. .send = idt77252_send,
  121. .send_oam = idt77252_send_oam,
  122. .phy_put = idt77252_phy_put,
  123. .phy_get = idt77252_phy_get,
  124. .change_qos = idt77252_change_qos,
  125. .proc_read = idt77252_proc_read,
  126. .owner = THIS_MODULE
  127. };
  128. static struct idt77252_dev *idt77252_chain = NULL;
  129. static unsigned int idt77252_sram_write_errors = 0;
  130. /*****************************************************************************/
  131. /* */
  132. /* I/O and Utility Bus */
  133. /* */
  134. /*****************************************************************************/
  135. static void
  136. waitfor_idle(struct idt77252_dev *card)
  137. {
  138. u32 stat;
  139. stat = readl(SAR_REG_STAT);
  140. while (stat & SAR_STAT_CMDBZ)
  141. stat = readl(SAR_REG_STAT);
  142. }
  143. static u32
  144. read_sram(struct idt77252_dev *card, unsigned long addr)
  145. {
  146. unsigned long flags;
  147. u32 value;
  148. spin_lock_irqsave(&card->cmd_lock, flags);
  149. writel(SAR_CMD_READ_SRAM | (addr << 2), SAR_REG_CMD);
  150. waitfor_idle(card);
  151. value = readl(SAR_REG_DR0);
  152. spin_unlock_irqrestore(&card->cmd_lock, flags);
  153. return value;
  154. }
  155. static void
  156. write_sram(struct idt77252_dev *card, unsigned long addr, u32 value)
  157. {
  158. unsigned long flags;
  159. if ((idt77252_sram_write_errors == 0) &&
  160. (((addr > card->tst[0] + card->tst_size - 2) &&
  161. (addr < card->tst[0] + card->tst_size)) ||
  162. ((addr > card->tst[1] + card->tst_size - 2) &&
  163. (addr < card->tst[1] + card->tst_size)))) {
  164. printk("%s: ERROR: TST JMP section at %08lx written: %08x\n",
  165. card->name, addr, value);
  166. }
  167. spin_lock_irqsave(&card->cmd_lock, flags);
  168. writel(value, SAR_REG_DR0);
  169. writel(SAR_CMD_WRITE_SRAM | (addr << 2), SAR_REG_CMD);
  170. waitfor_idle(card);
  171. spin_unlock_irqrestore(&card->cmd_lock, flags);
  172. }
  173. static u8
  174. read_utility(void *dev, unsigned long ubus_addr)
  175. {
  176. struct idt77252_dev *card = dev;
  177. unsigned long flags;
  178. u8 value;
  179. if (!card) {
  180. printk("Error: No such device.\n");
  181. return -1;
  182. }
  183. spin_lock_irqsave(&card->cmd_lock, flags);
  184. writel(SAR_CMD_READ_UTILITY + ubus_addr, SAR_REG_CMD);
  185. waitfor_idle(card);
  186. value = readl(SAR_REG_DR0);
  187. spin_unlock_irqrestore(&card->cmd_lock, flags);
  188. return value;
  189. }
  190. static void
  191. write_utility(void *dev, unsigned long ubus_addr, u8 value)
  192. {
  193. struct idt77252_dev *card = dev;
  194. unsigned long flags;
  195. if (!card) {
  196. printk("Error: No such device.\n");
  197. return;
  198. }
  199. spin_lock_irqsave(&card->cmd_lock, flags);
  200. writel((u32) value, SAR_REG_DR0);
  201. writel(SAR_CMD_WRITE_UTILITY + ubus_addr, SAR_REG_CMD);
  202. waitfor_idle(card);
  203. spin_unlock_irqrestore(&card->cmd_lock, flags);
  204. }
  205. #ifdef HAVE_EEPROM
  206. static u32 rdsrtab[] =
  207. {
  208. SAR_GP_EECS | SAR_GP_EESCLK,
  209. 0,
  210. SAR_GP_EESCLK, /* 0 */
  211. 0,
  212. SAR_GP_EESCLK, /* 0 */
  213. 0,
  214. SAR_GP_EESCLK, /* 0 */
  215. 0,
  216. SAR_GP_EESCLK, /* 0 */
  217. 0,
  218. SAR_GP_EESCLK, /* 0 */
  219. SAR_GP_EEDO,
  220. SAR_GP_EESCLK | SAR_GP_EEDO, /* 1 */
  221. 0,
  222. SAR_GP_EESCLK, /* 0 */
  223. SAR_GP_EEDO,
  224. SAR_GP_EESCLK | SAR_GP_EEDO /* 1 */
  225. };
  226. static u32 wrentab[] =
  227. {
  228. SAR_GP_EECS | SAR_GP_EESCLK,
  229. 0,
  230. SAR_GP_EESCLK, /* 0 */
  231. 0,
  232. SAR_GP_EESCLK, /* 0 */
  233. 0,
  234. SAR_GP_EESCLK, /* 0 */
  235. 0,
  236. SAR_GP_EESCLK, /* 0 */
  237. SAR_GP_EEDO,
  238. SAR_GP_EESCLK | SAR_GP_EEDO, /* 1 */
  239. SAR_GP_EEDO,
  240. SAR_GP_EESCLK | SAR_GP_EEDO, /* 1 */
  241. 0,
  242. SAR_GP_EESCLK, /* 0 */
  243. 0,
  244. SAR_GP_EESCLK /* 0 */
  245. };
  246. static u32 rdtab[] =
  247. {
  248. SAR_GP_EECS | SAR_GP_EESCLK,
  249. 0,
  250. SAR_GP_EESCLK, /* 0 */
  251. 0,
  252. SAR_GP_EESCLK, /* 0 */
  253. 0,
  254. SAR_GP_EESCLK, /* 0 */
  255. 0,
  256. SAR_GP_EESCLK, /* 0 */
  257. 0,
  258. SAR_GP_EESCLK, /* 0 */
  259. 0,
  260. SAR_GP_EESCLK, /* 0 */
  261. SAR_GP_EEDO,
  262. SAR_GP_EESCLK | SAR_GP_EEDO, /* 1 */
  263. SAR_GP_EEDO,
  264. SAR_GP_EESCLK | SAR_GP_EEDO /* 1 */
  265. };
  266. static u32 wrtab[] =
  267. {
  268. SAR_GP_EECS | SAR_GP_EESCLK,
  269. 0,
  270. SAR_GP_EESCLK, /* 0 */
  271. 0,
  272. SAR_GP_EESCLK, /* 0 */
  273. 0,
  274. SAR_GP_EESCLK, /* 0 */
  275. 0,
  276. SAR_GP_EESCLK, /* 0 */
  277. 0,
  278. SAR_GP_EESCLK, /* 0 */
  279. 0,
  280. SAR_GP_EESCLK, /* 0 */
  281. SAR_GP_EEDO,
  282. SAR_GP_EESCLK | SAR_GP_EEDO, /* 1 */
  283. 0,
  284. SAR_GP_EESCLK /* 0 */
  285. };
  286. static u32 clktab[] =
  287. {
  288. 0,
  289. SAR_GP_EESCLK,
  290. 0,
  291. SAR_GP_EESCLK,
  292. 0,
  293. SAR_GP_EESCLK,
  294. 0,
  295. SAR_GP_EESCLK,
  296. 0,
  297. SAR_GP_EESCLK,
  298. 0,
  299. SAR_GP_EESCLK,
  300. 0,
  301. SAR_GP_EESCLK,
  302. 0,
  303. SAR_GP_EESCLK,
  304. 0
  305. };
  306. static u32
  307. idt77252_read_gp(struct idt77252_dev *card)
  308. {
  309. u32 gp;
  310. gp = readl(SAR_REG_GP);
  311. #if 0
  312. printk("RD: %s\n", gp & SAR_GP_EEDI ? "1" : "0");
  313. #endif
  314. return gp;
  315. }
  316. static void
  317. idt77252_write_gp(struct idt77252_dev *card, u32 value)
  318. {
  319. unsigned long flags;
  320. #if 0
  321. printk("WR: %s %s %s\n", value & SAR_GP_EECS ? " " : "/CS",
  322. value & SAR_GP_EESCLK ? "HIGH" : "LOW ",
  323. value & SAR_GP_EEDO ? "1" : "0");
  324. #endif
  325. spin_lock_irqsave(&card->cmd_lock, flags);
  326. waitfor_idle(card);
  327. writel(value, SAR_REG_GP);
  328. spin_unlock_irqrestore(&card->cmd_lock, flags);
  329. }
  330. static u8
  331. idt77252_eeprom_read_status(struct idt77252_dev *card)
  332. {
  333. u8 byte;
  334. u32 gp;
  335. int i, j;
  336. gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO);
  337. for (i = 0; i < ARRAY_SIZE(rdsrtab); i++) {
  338. idt77252_write_gp(card, gp | rdsrtab[i]);
  339. udelay(5);
  340. }
  341. idt77252_write_gp(card, gp | SAR_GP_EECS);
  342. udelay(5);
  343. byte = 0;
  344. for (i = 0, j = 0; i < 8; i++) {
  345. byte <<= 1;
  346. idt77252_write_gp(card, gp | clktab[j++]);
  347. udelay(5);
  348. byte |= idt77252_read_gp(card) & SAR_GP_EEDI ? 1 : 0;
  349. idt77252_write_gp(card, gp | clktab[j++]);
  350. udelay(5);
  351. }
  352. idt77252_write_gp(card, gp | SAR_GP_EECS);
  353. udelay(5);
  354. return byte;
  355. }
  356. static u8
  357. idt77252_eeprom_read_byte(struct idt77252_dev *card, u8 offset)
  358. {
  359. u8 byte;
  360. u32 gp;
  361. int i, j;
  362. gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO);
  363. for (i = 0; i < ARRAY_SIZE(rdtab); i++) {
  364. idt77252_write_gp(card, gp | rdtab[i]);
  365. udelay(5);
  366. }
  367. idt77252_write_gp(card, gp | SAR_GP_EECS);
  368. udelay(5);
  369. for (i = 0, j = 0; i < 8; i++) {
  370. idt77252_write_gp(card, gp | clktab[j++] |
  371. (offset & 1 ? SAR_GP_EEDO : 0));
  372. udelay(5);
  373. idt77252_write_gp(card, gp | clktab[j++] |
  374. (offset & 1 ? SAR_GP_EEDO : 0));
  375. udelay(5);
  376. offset >>= 1;
  377. }
  378. idt77252_write_gp(card, gp | SAR_GP_EECS);
  379. udelay(5);
  380. byte = 0;
  381. for (i = 0, j = 0; i < 8; i++) {
  382. byte <<= 1;
  383. idt77252_write_gp(card, gp | clktab[j++]);
  384. udelay(5);
  385. byte |= idt77252_read_gp(card) & SAR_GP_EEDI ? 1 : 0;
  386. idt77252_write_gp(card, gp | clktab[j++]);
  387. udelay(5);
  388. }
  389. idt77252_write_gp(card, gp | SAR_GP_EECS);
  390. udelay(5);
  391. return byte;
  392. }
  393. static void
  394. idt77252_eeprom_write_byte(struct idt77252_dev *card, u8 offset, u8 data)
  395. {
  396. u32 gp;
  397. int i, j;
  398. gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO);
  399. for (i = 0; i < ARRAY_SIZE(wrentab); i++) {
  400. idt77252_write_gp(card, gp | wrentab[i]);
  401. udelay(5);
  402. }
  403. idt77252_write_gp(card, gp | SAR_GP_EECS);
  404. udelay(5);
  405. for (i = 0; i < ARRAY_SIZE(wrtab); i++) {
  406. idt77252_write_gp(card, gp | wrtab[i]);
  407. udelay(5);
  408. }
  409. idt77252_write_gp(card, gp | SAR_GP_EECS);
  410. udelay(5);
  411. for (i = 0, j = 0; i < 8; i++) {
  412. idt77252_write_gp(card, gp | clktab[j++] |
  413. (offset & 1 ? SAR_GP_EEDO : 0));
  414. udelay(5);
  415. idt77252_write_gp(card, gp | clktab[j++] |
  416. (offset & 1 ? SAR_GP_EEDO : 0));
  417. udelay(5);
  418. offset >>= 1;
  419. }
  420. idt77252_write_gp(card, gp | SAR_GP_EECS);
  421. udelay(5);
  422. for (i = 0, j = 0; i < 8; i++) {
  423. idt77252_write_gp(card, gp | clktab[j++] |
  424. (data & 1 ? SAR_GP_EEDO : 0));
  425. udelay(5);
  426. idt77252_write_gp(card, gp | clktab[j++] |
  427. (data & 1 ? SAR_GP_EEDO : 0));
  428. udelay(5);
  429. data >>= 1;
  430. }
  431. idt77252_write_gp(card, gp | SAR_GP_EECS);
  432. udelay(5);
  433. }
  434. static void
  435. idt77252_eeprom_init(struct idt77252_dev *card)
  436. {
  437. u32 gp;
  438. gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO);
  439. idt77252_write_gp(card, gp | SAR_GP_EECS | SAR_GP_EESCLK);
  440. udelay(5);
  441. idt77252_write_gp(card, gp | SAR_GP_EECS);
  442. udelay(5);
  443. idt77252_write_gp(card, gp | SAR_GP_EECS | SAR_GP_EESCLK);
  444. udelay(5);
  445. idt77252_write_gp(card, gp | SAR_GP_EECS);
  446. udelay(5);
  447. }
  448. #endif /* HAVE_EEPROM */
  449. #ifdef CONFIG_ATM_IDT77252_DEBUG
  450. static void
  451. dump_tct(struct idt77252_dev *card, int index)
  452. {
  453. unsigned long tct;
  454. int i;
  455. tct = (unsigned long) (card->tct_base + index * SAR_SRAM_TCT_SIZE);
  456. printk("%s: TCT %x:", card->name, index);
  457. for (i = 0; i < 8; i++) {
  458. printk(" %08x", read_sram(card, tct + i));
  459. }
  460. printk("\n");
  461. }
  462. static void
  463. idt77252_tx_dump(struct idt77252_dev *card)
  464. {
  465. struct atm_vcc *vcc;
  466. struct vc_map *vc;
  467. int i;
  468. printk("%s\n", __func__);
  469. for (i = 0; i < card->tct_size; i++) {
  470. vc = card->vcs[i];
  471. if (!vc)
  472. continue;
  473. vcc = NULL;
  474. if (vc->rx_vcc)
  475. vcc = vc->rx_vcc;
  476. else if (vc->tx_vcc)
  477. vcc = vc->tx_vcc;
  478. if (!vcc)
  479. continue;
  480. printk("%s: Connection %d:\n", card->name, vc->index);
  481. dump_tct(card, vc->index);
  482. }
  483. }
  484. #endif
  485. /*****************************************************************************/
  486. /* */
  487. /* SCQ Handling */
  488. /* */
  489. /*****************************************************************************/
  490. static int
  491. sb_pool_add(struct idt77252_dev *card, struct sk_buff *skb, int queue)
  492. {
  493. struct sb_pool *pool = &card->sbpool[queue];
  494. int index;
  495. index = pool->index;
  496. while (pool->skb[index]) {
  497. index = (index + 1) & FBQ_MASK;
  498. if (index == pool->index)
  499. return -ENOBUFS;
  500. }
  501. pool->skb[index] = skb;
  502. IDT77252_PRV_POOL(skb) = POOL_HANDLE(queue, index);
  503. pool->index = (index + 1) & FBQ_MASK;
  504. return 0;
  505. }
  506. static void
  507. sb_pool_remove(struct idt77252_dev *card, struct sk_buff *skb)
  508. {
  509. unsigned int queue, index;
  510. u32 handle;
  511. handle = IDT77252_PRV_POOL(skb);
  512. queue = POOL_QUEUE(handle);
  513. if (queue > 3)
  514. return;
  515. index = POOL_INDEX(handle);
  516. if (index > FBQ_SIZE - 1)
  517. return;
  518. card->sbpool[queue].skb[index] = NULL;
  519. }
  520. static struct sk_buff *
  521. sb_pool_skb(struct idt77252_dev *card, u32 handle)
  522. {
  523. unsigned int queue, index;
  524. queue = POOL_QUEUE(handle);
  525. if (queue > 3)
  526. return NULL;
  527. index = POOL_INDEX(handle);
  528. if (index > FBQ_SIZE - 1)
  529. return NULL;
  530. return card->sbpool[queue].skb[index];
  531. }
  532. static struct scq_info *
  533. alloc_scq(struct idt77252_dev *card, int class)
  534. {
  535. struct scq_info *scq;
  536. scq = kzalloc(sizeof(struct scq_info), GFP_KERNEL);
  537. if (!scq)
  538. return NULL;
  539. scq->base = dma_zalloc_coherent(&card->pcidev->dev, SCQ_SIZE,
  540. &scq->paddr, GFP_KERNEL);
  541. if (scq->base == NULL) {
  542. kfree(scq);
  543. return NULL;
  544. }
  545. scq->next = scq->base;
  546. scq->last = scq->base + (SCQ_ENTRIES - 1);
  547. atomic_set(&scq->used, 0);
  548. spin_lock_init(&scq->lock);
  549. spin_lock_init(&scq->skblock);
  550. skb_queue_head_init(&scq->transmit);
  551. skb_queue_head_init(&scq->pending);
  552. TXPRINTK("idt77252: SCQ: base 0x%p, next 0x%p, last 0x%p, paddr %08llx\n",
  553. scq->base, scq->next, scq->last, (unsigned long long)scq->paddr);
  554. return scq;
  555. }
  556. static void
  557. free_scq(struct idt77252_dev *card, struct scq_info *scq)
  558. {
  559. struct sk_buff *skb;
  560. struct atm_vcc *vcc;
  561. dma_free_coherent(&card->pcidev->dev, SCQ_SIZE,
  562. scq->base, scq->paddr);
  563. while ((skb = skb_dequeue(&scq->transmit))) {
  564. dma_unmap_single(&card->pcidev->dev, IDT77252_PRV_PADDR(skb),
  565. skb->len, DMA_TO_DEVICE);
  566. vcc = ATM_SKB(skb)->vcc;
  567. if (vcc->pop)
  568. vcc->pop(vcc, skb);
  569. else
  570. dev_kfree_skb(skb);
  571. }
  572. while ((skb = skb_dequeue(&scq->pending))) {
  573. dma_unmap_single(&card->pcidev->dev, IDT77252_PRV_PADDR(skb),
  574. skb->len, DMA_TO_DEVICE);
  575. vcc = ATM_SKB(skb)->vcc;
  576. if (vcc->pop)
  577. vcc->pop(vcc, skb);
  578. else
  579. dev_kfree_skb(skb);
  580. }
  581. kfree(scq);
  582. }
  583. static int
  584. push_on_scq(struct idt77252_dev *card, struct vc_map *vc, struct sk_buff *skb)
  585. {
  586. struct scq_info *scq = vc->scq;
  587. unsigned long flags;
  588. struct scqe *tbd;
  589. int entries;
  590. TXPRINTK("%s: SCQ: next 0x%p\n", card->name, scq->next);
  591. atomic_inc(&scq->used);
  592. entries = atomic_read(&scq->used);
  593. if (entries > (SCQ_ENTRIES - 1)) {
  594. atomic_dec(&scq->used);
  595. goto out;
  596. }
  597. skb_queue_tail(&scq->transmit, skb);
  598. spin_lock_irqsave(&vc->lock, flags);
  599. if (vc->estimator) {
  600. struct atm_vcc *vcc = vc->tx_vcc;
  601. struct sock *sk = sk_atm(vcc);
  602. vc->estimator->cells += (skb->len + 47) / 48;
  603. if (atomic_read(&sk->sk_wmem_alloc) >
  604. (sk->sk_sndbuf >> 1)) {
  605. u32 cps = vc->estimator->maxcps;
  606. vc->estimator->cps = cps;
  607. vc->estimator->avcps = cps << 5;
  608. if (vc->lacr < vc->init_er) {
  609. vc->lacr = vc->init_er;
  610. writel(TCMDQ_LACR | (vc->lacr << 16) |
  611. vc->index, SAR_REG_TCMDQ);
  612. }
  613. }
  614. }
  615. spin_unlock_irqrestore(&vc->lock, flags);
  616. tbd = &IDT77252_PRV_TBD(skb);
  617. spin_lock_irqsave(&scq->lock, flags);
  618. scq->next->word_1 = cpu_to_le32(tbd->word_1 |
  619. SAR_TBD_TSIF | SAR_TBD_GTSI);
  620. scq->next->word_2 = cpu_to_le32(tbd->word_2);
  621. scq->next->word_3 = cpu_to_le32(tbd->word_3);
  622. scq->next->word_4 = cpu_to_le32(tbd->word_4);
  623. if (scq->next == scq->last)
  624. scq->next = scq->base;
  625. else
  626. scq->next++;
  627. write_sram(card, scq->scd,
  628. scq->paddr +
  629. (u32)((unsigned long)scq->next - (unsigned long)scq->base));
  630. spin_unlock_irqrestore(&scq->lock, flags);
  631. scq->trans_start = jiffies;
  632. if (test_and_clear_bit(VCF_IDLE, &vc->flags)) {
  633. writel(TCMDQ_START_LACR | (vc->lacr << 16) | vc->index,
  634. SAR_REG_TCMDQ);
  635. }
  636. TXPRINTK("%d entries in SCQ used (push).\n", atomic_read(&scq->used));
  637. XPRINTK("%s: SCQ (after push %2d) head = 0x%x, next = 0x%p.\n",
  638. card->name, atomic_read(&scq->used),
  639. read_sram(card, scq->scd + 1), scq->next);
  640. return 0;
  641. out:
  642. if (time_after(jiffies, scq->trans_start + HZ)) {
  643. printk("%s: Error pushing TBD for %d.%d\n",
  644. card->name, vc->tx_vcc->vpi, vc->tx_vcc->vci);
  645. #ifdef CONFIG_ATM_IDT77252_DEBUG
  646. idt77252_tx_dump(card);
  647. #endif
  648. scq->trans_start = jiffies;
  649. }
  650. return -ENOBUFS;
  651. }
  652. static void
  653. drain_scq(struct idt77252_dev *card, struct vc_map *vc)
  654. {
  655. struct scq_info *scq = vc->scq;
  656. struct sk_buff *skb;
  657. struct atm_vcc *vcc;
  658. TXPRINTK("%s: SCQ (before drain %2d) next = 0x%p.\n",
  659. card->name, atomic_read(&scq->used), scq->next);
  660. skb = skb_dequeue(&scq->transmit);
  661. if (skb) {
  662. TXPRINTK("%s: freeing skb at %p.\n", card->name, skb);
  663. dma_unmap_single(&card->pcidev->dev, IDT77252_PRV_PADDR(skb),
  664. skb->len, DMA_TO_DEVICE);
  665. vcc = ATM_SKB(skb)->vcc;
  666. if (vcc->pop)
  667. vcc->pop(vcc, skb);
  668. else
  669. dev_kfree_skb(skb);
  670. atomic_inc(&vcc->stats->tx);
  671. }
  672. atomic_dec(&scq->used);
  673. spin_lock(&scq->skblock);
  674. while ((skb = skb_dequeue(&scq->pending))) {
  675. if (push_on_scq(card, vc, skb)) {
  676. skb_queue_head(&vc->scq->pending, skb);
  677. break;
  678. }
  679. }
  680. spin_unlock(&scq->skblock);
  681. }
  682. static int
  683. queue_skb(struct idt77252_dev *card, struct vc_map *vc,
  684. struct sk_buff *skb, int oam)
  685. {
  686. struct atm_vcc *vcc;
  687. struct scqe *tbd;
  688. unsigned long flags;
  689. int error;
  690. int aal;
  691. if (skb->len == 0) {
  692. printk("%s: invalid skb->len (%d)\n", card->name, skb->len);
  693. return -EINVAL;
  694. }
  695. TXPRINTK("%s: Sending %d bytes of data.\n",
  696. card->name, skb->len);
  697. tbd = &IDT77252_PRV_TBD(skb);
  698. vcc = ATM_SKB(skb)->vcc;
  699. IDT77252_PRV_PADDR(skb) = dma_map_single(&card->pcidev->dev, skb->data,
  700. skb->len, DMA_TO_DEVICE);
  701. error = -EINVAL;
  702. if (oam) {
  703. if (skb->len != 52)
  704. goto errout;
  705. tbd->word_1 = SAR_TBD_OAM | ATM_CELL_PAYLOAD | SAR_TBD_EPDU;
  706. tbd->word_2 = IDT77252_PRV_PADDR(skb) + 4;
  707. tbd->word_3 = 0x00000000;
  708. tbd->word_4 = (skb->data[0] << 24) | (skb->data[1] << 16) |
  709. (skb->data[2] << 8) | (skb->data[3] << 0);
  710. if (test_bit(VCF_RSV, &vc->flags))
  711. vc = card->vcs[0];
  712. goto done;
  713. }
  714. if (test_bit(VCF_RSV, &vc->flags)) {
  715. printk("%s: Trying to transmit on reserved VC\n", card->name);
  716. goto errout;
  717. }
  718. aal = vcc->qos.aal;
  719. switch (aal) {
  720. case ATM_AAL0:
  721. case ATM_AAL34:
  722. if (skb->len > 52)
  723. goto errout;
  724. if (aal == ATM_AAL0)
  725. tbd->word_1 = SAR_TBD_EPDU | SAR_TBD_AAL0 |
  726. ATM_CELL_PAYLOAD;
  727. else
  728. tbd->word_1 = SAR_TBD_EPDU | SAR_TBD_AAL34 |
  729. ATM_CELL_PAYLOAD;
  730. tbd->word_2 = IDT77252_PRV_PADDR(skb) + 4;
  731. tbd->word_3 = 0x00000000;
  732. tbd->word_4 = (skb->data[0] << 24) | (skb->data[1] << 16) |
  733. (skb->data[2] << 8) | (skb->data[3] << 0);
  734. break;
  735. case ATM_AAL5:
  736. tbd->word_1 = SAR_TBD_EPDU | SAR_TBD_AAL5 | skb->len;
  737. tbd->word_2 = IDT77252_PRV_PADDR(skb);
  738. tbd->word_3 = skb->len;
  739. tbd->word_4 = (vcc->vpi << SAR_TBD_VPI_SHIFT) |
  740. (vcc->vci << SAR_TBD_VCI_SHIFT);
  741. break;
  742. case ATM_AAL1:
  743. case ATM_AAL2:
  744. default:
  745. printk("%s: Traffic type not supported.\n", card->name);
  746. error = -EPROTONOSUPPORT;
  747. goto errout;
  748. }
  749. done:
  750. spin_lock_irqsave(&vc->scq->skblock, flags);
  751. skb_queue_tail(&vc->scq->pending, skb);
  752. while ((skb = skb_dequeue(&vc->scq->pending))) {
  753. if (push_on_scq(card, vc, skb)) {
  754. skb_queue_head(&vc->scq->pending, skb);
  755. break;
  756. }
  757. }
  758. spin_unlock_irqrestore(&vc->scq->skblock, flags);
  759. return 0;
  760. errout:
  761. dma_unmap_single(&card->pcidev->dev, IDT77252_PRV_PADDR(skb),
  762. skb->len, DMA_TO_DEVICE);
  763. return error;
  764. }
  765. static unsigned long
  766. get_free_scd(struct idt77252_dev *card, struct vc_map *vc)
  767. {
  768. int i;
  769. for (i = 0; i < card->scd_size; i++) {
  770. if (!card->scd2vc[i]) {
  771. card->scd2vc[i] = vc;
  772. vc->scd_index = i;
  773. return card->scd_base + i * SAR_SRAM_SCD_SIZE;
  774. }
  775. }
  776. return 0;
  777. }
  778. static void
  779. fill_scd(struct idt77252_dev *card, struct scq_info *scq, int class)
  780. {
  781. write_sram(card, scq->scd, scq->paddr);
  782. write_sram(card, scq->scd + 1, 0x00000000);
  783. write_sram(card, scq->scd + 2, 0xffffffff);
  784. write_sram(card, scq->scd + 3, 0x00000000);
  785. }
  786. static void
  787. clear_scd(struct idt77252_dev *card, struct scq_info *scq, int class)
  788. {
  789. return;
  790. }
  791. /*****************************************************************************/
  792. /* */
  793. /* RSQ Handling */
  794. /* */
  795. /*****************************************************************************/
  796. static int
  797. init_rsq(struct idt77252_dev *card)
  798. {
  799. struct rsq_entry *rsqe;
  800. card->rsq.base = dma_zalloc_coherent(&card->pcidev->dev, RSQSIZE,
  801. &card->rsq.paddr, GFP_KERNEL);
  802. if (card->rsq.base == NULL) {
  803. printk("%s: can't allocate RSQ.\n", card->name);
  804. return -1;
  805. }
  806. card->rsq.last = card->rsq.base + RSQ_NUM_ENTRIES - 1;
  807. card->rsq.next = card->rsq.last;
  808. for (rsqe = card->rsq.base; rsqe <= card->rsq.last; rsqe++)
  809. rsqe->word_4 = 0;
  810. writel((unsigned long) card->rsq.last - (unsigned long) card->rsq.base,
  811. SAR_REG_RSQH);
  812. writel(card->rsq.paddr, SAR_REG_RSQB);
  813. IPRINTK("%s: RSQ base at 0x%lx (0x%x).\n", card->name,
  814. (unsigned long) card->rsq.base,
  815. readl(SAR_REG_RSQB));
  816. IPRINTK("%s: RSQ head = 0x%x, base = 0x%x, tail = 0x%x.\n",
  817. card->name,
  818. readl(SAR_REG_RSQH),
  819. readl(SAR_REG_RSQB),
  820. readl(SAR_REG_RSQT));
  821. return 0;
  822. }
  823. static void
  824. deinit_rsq(struct idt77252_dev *card)
  825. {
  826. dma_free_coherent(&card->pcidev->dev, RSQSIZE,
  827. card->rsq.base, card->rsq.paddr);
  828. }
  829. static void
  830. dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
  831. {
  832. struct atm_vcc *vcc;
  833. struct sk_buff *skb;
  834. struct rx_pool *rpp;
  835. struct vc_map *vc;
  836. u32 header, vpi, vci;
  837. u32 stat;
  838. int i;
  839. stat = le32_to_cpu(rsqe->word_4);
  840. if (stat & SAR_RSQE_IDLE) {
  841. RXPRINTK("%s: message about inactive connection.\n",
  842. card->name);
  843. return;
  844. }
  845. skb = sb_pool_skb(card, le32_to_cpu(rsqe->word_2));
  846. if (skb == NULL) {
  847. printk("%s: NULL skb in %s, rsqe: %08x %08x %08x %08x\n",
  848. card->name, __func__,
  849. le32_to_cpu(rsqe->word_1), le32_to_cpu(rsqe->word_2),
  850. le32_to_cpu(rsqe->word_3), le32_to_cpu(rsqe->word_4));
  851. return;
  852. }
  853. header = le32_to_cpu(rsqe->word_1);
  854. vpi = (header >> 16) & 0x00ff;
  855. vci = (header >> 0) & 0xffff;
  856. RXPRINTK("%s: SDU for %d.%d received in buffer 0x%p (data 0x%p).\n",
  857. card->name, vpi, vci, skb, skb->data);
  858. if ((vpi >= (1 << card->vpibits)) || (vci != (vci & card->vcimask))) {
  859. printk("%s: SDU received for out-of-range vc %u.%u\n",
  860. card->name, vpi, vci);
  861. recycle_rx_skb(card, skb);
  862. return;
  863. }
  864. vc = card->vcs[VPCI2VC(card, vpi, vci)];
  865. if (!vc || !test_bit(VCF_RX, &vc->flags)) {
  866. printk("%s: SDU received on non RX vc %u.%u\n",
  867. card->name, vpi, vci);
  868. recycle_rx_skb(card, skb);
  869. return;
  870. }
  871. vcc = vc->rx_vcc;
  872. dma_sync_single_for_cpu(&card->pcidev->dev, IDT77252_PRV_PADDR(skb),
  873. skb_end_pointer(skb) - skb->data,
  874. DMA_FROM_DEVICE);
  875. if ((vcc->qos.aal == ATM_AAL0) ||
  876. (vcc->qos.aal == ATM_AAL34)) {
  877. struct sk_buff *sb;
  878. unsigned char *cell;
  879. u32 aal0;
  880. cell = skb->data;
  881. for (i = (stat & SAR_RSQE_CELLCNT); i; i--) {
  882. if ((sb = dev_alloc_skb(64)) == NULL) {
  883. printk("%s: Can't allocate buffers for aal0.\n",
  884. card->name);
  885. atomic_add(i, &vcc->stats->rx_drop);
  886. break;
  887. }
  888. if (!atm_charge(vcc, sb->truesize)) {
  889. RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
  890. card->name);
  891. atomic_add(i - 1, &vcc->stats->rx_drop);
  892. dev_kfree_skb(sb);
  893. break;
  894. }
  895. aal0 = (vpi << ATM_HDR_VPI_SHIFT) |
  896. (vci << ATM_HDR_VCI_SHIFT);
  897. aal0 |= (stat & SAR_RSQE_EPDU) ? 0x00000002 : 0;
  898. aal0 |= (stat & SAR_RSQE_CLP) ? 0x00000001 : 0;
  899. *((u32 *) sb->data) = aal0;
  900. skb_put(sb, sizeof(u32));
  901. memcpy(skb_put(sb, ATM_CELL_PAYLOAD),
  902. cell, ATM_CELL_PAYLOAD);
  903. ATM_SKB(sb)->vcc = vcc;
  904. __net_timestamp(sb);
  905. vcc->push(vcc, sb);
  906. atomic_inc(&vcc->stats->rx);
  907. cell += ATM_CELL_PAYLOAD;
  908. }
  909. recycle_rx_skb(card, skb);
  910. return;
  911. }
  912. if (vcc->qos.aal != ATM_AAL5) {
  913. printk("%s: Unexpected AAL type in dequeue_rx(): %d.\n",
  914. card->name, vcc->qos.aal);
  915. recycle_rx_skb(card, skb);
  916. return;
  917. }
  918. skb->len = (stat & SAR_RSQE_CELLCNT) * ATM_CELL_PAYLOAD;
  919. rpp = &vc->rcv.rx_pool;
  920. __skb_queue_tail(&rpp->queue, skb);
  921. rpp->len += skb->len;
  922. if (stat & SAR_RSQE_EPDU) {
  923. unsigned char *l1l2;
  924. unsigned int len;
  925. l1l2 = (unsigned char *) ((unsigned long) skb->data + skb->len - 6);
  926. len = (l1l2[0] << 8) | l1l2[1];
  927. len = len ? len : 0x10000;
  928. RXPRINTK("%s: PDU has %d bytes.\n", card->name, len);
  929. if ((len + 8 > rpp->len) || (len + (47 + 8) < rpp->len)) {
  930. RXPRINTK("%s: AAL5 PDU size mismatch: %d != %d. "
  931. "(CDC: %08x)\n",
  932. card->name, len, rpp->len, readl(SAR_REG_CDC));
  933. recycle_rx_pool_skb(card, rpp);
  934. atomic_inc(&vcc->stats->rx_err);
  935. return;
  936. }
  937. if (stat & SAR_RSQE_CRC) {
  938. RXPRINTK("%s: AAL5 CRC error.\n", card->name);
  939. recycle_rx_pool_skb(card, rpp);
  940. atomic_inc(&vcc->stats->rx_err);
  941. return;
  942. }
  943. if (skb_queue_len(&rpp->queue) > 1) {
  944. struct sk_buff *sb;
  945. skb = dev_alloc_skb(rpp->len);
  946. if (!skb) {
  947. RXPRINTK("%s: Can't alloc RX skb.\n",
  948. card->name);
  949. recycle_rx_pool_skb(card, rpp);
  950. atomic_inc(&vcc->stats->rx_err);
  951. return;
  952. }
  953. if (!atm_charge(vcc, skb->truesize)) {
  954. recycle_rx_pool_skb(card, rpp);
  955. dev_kfree_skb(skb);
  956. return;
  957. }
  958. skb_queue_walk(&rpp->queue, sb)
  959. memcpy(skb_put(skb, sb->len),
  960. sb->data, sb->len);
  961. recycle_rx_pool_skb(card, rpp);
  962. skb_trim(skb, len);
  963. ATM_SKB(skb)->vcc = vcc;
  964. __net_timestamp(skb);
  965. vcc->push(vcc, skb);
  966. atomic_inc(&vcc->stats->rx);
  967. return;
  968. }
  969. flush_rx_pool(card, rpp);
  970. if (!atm_charge(vcc, skb->truesize)) {
  971. recycle_rx_skb(card, skb);
  972. return;
  973. }
  974. dma_unmap_single(&card->pcidev->dev, IDT77252_PRV_PADDR(skb),
  975. skb_end_pointer(skb) - skb->data,
  976. DMA_FROM_DEVICE);
  977. sb_pool_remove(card, skb);
  978. skb_trim(skb, len);
  979. ATM_SKB(skb)->vcc = vcc;
  980. __net_timestamp(skb);
  981. vcc->push(vcc, skb);
  982. atomic_inc(&vcc->stats->rx);
  983. if (skb->truesize > SAR_FB_SIZE_3)
  984. add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
  985. else if (skb->truesize > SAR_FB_SIZE_2)
  986. add_rx_skb(card, 2, SAR_FB_SIZE_2, 1);
  987. else if (skb->truesize > SAR_FB_SIZE_1)
  988. add_rx_skb(card, 1, SAR_FB_SIZE_1, 1);
  989. else
  990. add_rx_skb(card, 0, SAR_FB_SIZE_0, 1);
  991. return;
  992. }
  993. }
  994. static void
  995. idt77252_rx(struct idt77252_dev *card)
  996. {
  997. struct rsq_entry *rsqe;
  998. if (card->rsq.next == card->rsq.last)
  999. rsqe = card->rsq.base;
  1000. else
  1001. rsqe = card->rsq.next + 1;
  1002. if (!(le32_to_cpu(rsqe->word_4) & SAR_RSQE_VALID)) {
  1003. RXPRINTK("%s: no entry in RSQ.\n", card->name);
  1004. return;
  1005. }
  1006. do {
  1007. dequeue_rx(card, rsqe);
  1008. rsqe->word_4 = 0;
  1009. card->rsq.next = rsqe;
  1010. if (card->rsq.next == card->rsq.last)
  1011. rsqe = card->rsq.base;
  1012. else
  1013. rsqe = card->rsq.next + 1;
  1014. } while (le32_to_cpu(rsqe->word_4) & SAR_RSQE_VALID);
  1015. writel((unsigned long) card->rsq.next - (unsigned long) card->rsq.base,
  1016. SAR_REG_RSQH);
  1017. }
  1018. static void
  1019. idt77252_rx_raw(struct idt77252_dev *card)
  1020. {
  1021. struct sk_buff *queue;
  1022. u32 head, tail;
  1023. struct atm_vcc *vcc;
  1024. struct vc_map *vc;
  1025. struct sk_buff *sb;
  1026. if (card->raw_cell_head == NULL) {
  1027. u32 handle = le32_to_cpu(*(card->raw_cell_hnd + 1));
  1028. card->raw_cell_head = sb_pool_skb(card, handle);
  1029. }
  1030. queue = card->raw_cell_head;
  1031. if (!queue)
  1032. return;
  1033. head = IDT77252_PRV_PADDR(queue) + (queue->data - queue->head - 16);
  1034. tail = readl(SAR_REG_RAWCT);
  1035. dma_sync_single_for_cpu(&card->pcidev->dev, IDT77252_PRV_PADDR(queue),
  1036. skb_end_offset(queue) - 16,
  1037. DMA_FROM_DEVICE);
  1038. while (head != tail) {
  1039. unsigned int vpi, vci;
  1040. u32 header;
  1041. header = le32_to_cpu(*(u32 *) &queue->data[0]);
  1042. vpi = (header & ATM_HDR_VPI_MASK) >> ATM_HDR_VPI_SHIFT;
  1043. vci = (header & ATM_HDR_VCI_MASK) >> ATM_HDR_VCI_SHIFT;
  1044. #ifdef CONFIG_ATM_IDT77252_DEBUG
  1045. if (debug & DBG_RAW_CELL) {
  1046. int i;
  1047. printk("%s: raw cell %x.%02x.%04x.%x.%x\n",
  1048. card->name, (header >> 28) & 0x000f,
  1049. (header >> 20) & 0x00ff,
  1050. (header >> 4) & 0xffff,
  1051. (header >> 1) & 0x0007,
  1052. (header >> 0) & 0x0001);
  1053. for (i = 16; i < 64; i++)
  1054. printk(" %02x", queue->data[i]);
  1055. printk("\n");
  1056. }
  1057. #endif
  1058. if (vpi >= (1<<card->vpibits) || vci >= (1<<card->vcibits)) {
  1059. RPRINTK("%s: SDU received for out-of-range vc %u.%u\n",
  1060. card->name, vpi, vci);
  1061. goto drop;
  1062. }
  1063. vc = card->vcs[VPCI2VC(card, vpi, vci)];
  1064. if (!vc || !test_bit(VCF_RX, &vc->flags)) {
  1065. RPRINTK("%s: SDU received on non RX vc %u.%u\n",
  1066. card->name, vpi, vci);
  1067. goto drop;
  1068. }
  1069. vcc = vc->rx_vcc;
  1070. if (vcc->qos.aal != ATM_AAL0) {
  1071. RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
  1072. card->name, vpi, vci);
  1073. atomic_inc(&vcc->stats->rx_drop);
  1074. goto drop;
  1075. }
  1076. if ((sb = dev_alloc_skb(64)) == NULL) {
  1077. printk("%s: Can't allocate buffers for AAL0.\n",
  1078. card->name);
  1079. atomic_inc(&vcc->stats->rx_err);
  1080. goto drop;
  1081. }
  1082. if (!atm_charge(vcc, sb->truesize)) {
  1083. RXPRINTK("%s: atm_charge() dropped AAL0 packets.\n",
  1084. card->name);
  1085. dev_kfree_skb(sb);
  1086. goto drop;
  1087. }
  1088. *((u32 *) sb->data) = header;
  1089. skb_put(sb, sizeof(u32));
  1090. memcpy(skb_put(sb, ATM_CELL_PAYLOAD), &(queue->data[16]),
  1091. ATM_CELL_PAYLOAD);
  1092. ATM_SKB(sb)->vcc = vcc;
  1093. __net_timestamp(sb);
  1094. vcc->push(vcc, sb);
  1095. atomic_inc(&vcc->stats->rx);
  1096. drop:
  1097. skb_pull(queue, 64);
  1098. head = IDT77252_PRV_PADDR(queue)
  1099. + (queue->data - queue->head - 16);
  1100. if (queue->len < 128) {
  1101. struct sk_buff *next;
  1102. u32 handle;
  1103. head = le32_to_cpu(*(u32 *) &queue->data[0]);
  1104. handle = le32_to_cpu(*(u32 *) &queue->data[4]);
  1105. next = sb_pool_skb(card, handle);
  1106. recycle_rx_skb(card, queue);
  1107. if (next) {
  1108. card->raw_cell_head = next;
  1109. queue = card->raw_cell_head;
  1110. dma_sync_single_for_cpu(&card->pcidev->dev,
  1111. IDT77252_PRV_PADDR(queue),
  1112. (skb_end_pointer(queue) -
  1113. queue->data),
  1114. DMA_FROM_DEVICE);
  1115. } else {
  1116. card->raw_cell_head = NULL;
  1117. printk("%s: raw cell queue overrun\n",
  1118. card->name);
  1119. break;
  1120. }
  1121. }
  1122. }
  1123. }
  1124. /*****************************************************************************/
  1125. /* */
  1126. /* TSQ Handling */
  1127. /* */
  1128. /*****************************************************************************/
  1129. static int
  1130. init_tsq(struct idt77252_dev *card)
  1131. {
  1132. struct tsq_entry *tsqe;
  1133. card->tsq.base = dma_alloc_coherent(&card->pcidev->dev, RSQSIZE,
  1134. &card->tsq.paddr, GFP_KERNEL);
  1135. if (card->tsq.base == NULL) {
  1136. printk("%s: can't allocate TSQ.\n", card->name);
  1137. return -1;
  1138. }
  1139. memset(card->tsq.base, 0, TSQSIZE);
  1140. card->tsq.last = card->tsq.base + TSQ_NUM_ENTRIES - 1;
  1141. card->tsq.next = card->tsq.last;
  1142. for (tsqe = card->tsq.base; tsqe <= card->tsq.last; tsqe++)
  1143. tsqe->word_2 = cpu_to_le32(SAR_TSQE_INVALID);
  1144. writel(card->tsq.paddr, SAR_REG_TSQB);
  1145. writel((unsigned long) card->tsq.next - (unsigned long) card->tsq.base,
  1146. SAR_REG_TSQH);
  1147. return 0;
  1148. }
  1149. static void
  1150. deinit_tsq(struct idt77252_dev *card)
  1151. {
  1152. dma_free_coherent(&card->pcidev->dev, TSQSIZE,
  1153. card->tsq.base, card->tsq.paddr);
  1154. }
  1155. static void
  1156. idt77252_tx(struct idt77252_dev *card)
  1157. {
  1158. struct tsq_entry *tsqe;
  1159. unsigned int vpi, vci;
  1160. struct vc_map *vc;
  1161. u32 conn, stat;
  1162. if (card->tsq.next == card->tsq.last)
  1163. tsqe = card->tsq.base;
  1164. else
  1165. tsqe = card->tsq.next + 1;
  1166. TXPRINTK("idt77252_tx: tsq %p: base %p, next %p, last %p\n", tsqe,
  1167. card->tsq.base, card->tsq.next, card->tsq.last);
  1168. TXPRINTK("idt77252_tx: tsqb %08x, tsqt %08x, tsqh %08x, \n",
  1169. readl(SAR_REG_TSQB),
  1170. readl(SAR_REG_TSQT),
  1171. readl(SAR_REG_TSQH));
  1172. stat = le32_to_cpu(tsqe->word_2);
  1173. if (stat & SAR_TSQE_INVALID)
  1174. return;
  1175. do {
  1176. TXPRINTK("tsqe: 0x%p [0x%08x 0x%08x]\n", tsqe,
  1177. le32_to_cpu(tsqe->word_1),
  1178. le32_to_cpu(tsqe->word_2));
  1179. switch (stat & SAR_TSQE_TYPE) {
  1180. case SAR_TSQE_TYPE_TIMER:
  1181. TXPRINTK("%s: Timer RollOver detected.\n", card->name);
  1182. break;
  1183. case SAR_TSQE_TYPE_IDLE:
  1184. conn = le32_to_cpu(tsqe->word_1);
  1185. if (SAR_TSQE_TAG(stat) == 0x10) {
  1186. #ifdef NOTDEF
  1187. printk("%s: Connection %d halted.\n",
  1188. card->name,
  1189. le32_to_cpu(tsqe->word_1) & 0x1fff);
  1190. #endif
  1191. break;
  1192. }
  1193. vc = card->vcs[conn & 0x1fff];
  1194. if (!vc) {
  1195. printk("%s: could not find VC from conn %d\n",
  1196. card->name, conn & 0x1fff);
  1197. break;
  1198. }
  1199. printk("%s: Connection %d IDLE.\n",
  1200. card->name, vc->index);
  1201. set_bit(VCF_IDLE, &vc->flags);
  1202. break;
  1203. case SAR_TSQE_TYPE_TSR:
  1204. conn = le32_to_cpu(tsqe->word_1);
  1205. vc = card->vcs[conn & 0x1fff];
  1206. if (!vc) {
  1207. printk("%s: no VC at index %d\n",
  1208. card->name,
  1209. le32_to_cpu(tsqe->word_1) & 0x1fff);
  1210. break;
  1211. }
  1212. drain_scq(card, vc);
  1213. break;
  1214. case SAR_TSQE_TYPE_TBD_COMP:
  1215. conn = le32_to_cpu(tsqe->word_1);
  1216. vpi = (conn >> SAR_TBD_VPI_SHIFT) & 0x00ff;
  1217. vci = (conn >> SAR_TBD_VCI_SHIFT) & 0xffff;
  1218. if (vpi >= (1 << card->vpibits) ||
  1219. vci >= (1 << card->vcibits)) {
  1220. printk("%s: TBD complete: "
  1221. "out of range VPI.VCI %u.%u\n",
  1222. card->name, vpi, vci);
  1223. break;
  1224. }
  1225. vc = card->vcs[VPCI2VC(card, vpi, vci)];
  1226. if (!vc) {
  1227. printk("%s: TBD complete: "
  1228. "no VC at VPI.VCI %u.%u\n",
  1229. card->name, vpi, vci);
  1230. break;
  1231. }
  1232. drain_scq(card, vc);
  1233. break;
  1234. }
  1235. tsqe->word_2 = cpu_to_le32(SAR_TSQE_INVALID);
  1236. card->tsq.next = tsqe;
  1237. if (card->tsq.next == card->tsq.last)
  1238. tsqe = card->tsq.base;
  1239. else
  1240. tsqe = card->tsq.next + 1;
  1241. TXPRINTK("tsqe: %p: base %p, next %p, last %p\n", tsqe,
  1242. card->tsq.base, card->tsq.next, card->tsq.last);
  1243. stat = le32_to_cpu(tsqe->word_2);
  1244. } while (!(stat & SAR_TSQE_INVALID));
  1245. writel((unsigned long)card->tsq.next - (unsigned long)card->tsq.base,
  1246. SAR_REG_TSQH);
  1247. XPRINTK("idt77252_tx-after writel%d: TSQ head = 0x%x, tail = 0x%x, next = 0x%p.\n",
  1248. card->index, readl(SAR_REG_TSQH),
  1249. readl(SAR_REG_TSQT), card->tsq.next);
  1250. }
  1251. static void
  1252. tst_timer(unsigned long data)
  1253. {
  1254. struct idt77252_dev *card = (struct idt77252_dev *)data;
  1255. unsigned long base, idle, jump;
  1256. unsigned long flags;
  1257. u32 pc;
  1258. int e;
  1259. spin_lock_irqsave(&card->tst_lock, flags);
  1260. base = card->tst[card->tst_index];
  1261. idle = card->tst[card->tst_index ^ 1];
  1262. if (test_bit(TST_SWITCH_WAIT, &card->tst_state)) {
  1263. jump = base + card->tst_size - 2;
  1264. pc = readl(SAR_REG_NOW) >> 2;
  1265. if ((pc ^ idle) & ~(card->tst_size - 1)) {
  1266. mod_timer(&card->tst_timer, jiffies + 1);
  1267. goto out;
  1268. }
  1269. clear_bit(TST_SWITCH_WAIT, &card->tst_state);
  1270. card->tst_index ^= 1;
  1271. write_sram(card, jump, TSTE_OPC_JMP | (base << 2));
  1272. base = card->tst[card->tst_index];
  1273. idle = card->tst[card->tst_index ^ 1];
  1274. for (e = 0; e < card->tst_size - 2; e++) {
  1275. if (card->soft_tst[e].tste & TSTE_PUSH_IDLE) {
  1276. write_sram(card, idle + e,
  1277. card->soft_tst[e].tste & TSTE_MASK);
  1278. card->soft_tst[e].tste &= ~(TSTE_PUSH_IDLE);
  1279. }
  1280. }
  1281. }
  1282. if (test_and_clear_bit(TST_SWITCH_PENDING, &card->tst_state)) {
  1283. for (e = 0; e < card->tst_size - 2; e++) {
  1284. if (card->soft_tst[e].tste & TSTE_PUSH_ACTIVE) {
  1285. write_sram(card, idle + e,
  1286. card->soft_tst[e].tste & TSTE_MASK);
  1287. card->soft_tst[e].tste &= ~(TSTE_PUSH_ACTIVE);
  1288. card->soft_tst[e].tste |= TSTE_PUSH_IDLE;
  1289. }
  1290. }
  1291. jump = base + card->tst_size - 2;
  1292. write_sram(card, jump, TSTE_OPC_NULL);
  1293. set_bit(TST_SWITCH_WAIT, &card->tst_state);
  1294. mod_timer(&card->tst_timer, jiffies + 1);
  1295. }
  1296. out:
  1297. spin_unlock_irqrestore(&card->tst_lock, flags);
  1298. }
  1299. static int
  1300. __fill_tst(struct idt77252_dev *card, struct vc_map *vc,
  1301. int n, unsigned int opc)
  1302. {
  1303. unsigned long cl, avail;
  1304. unsigned long idle;
  1305. int e, r;
  1306. u32 data;
  1307. avail = card->tst_size - 2;
  1308. for (e = 0; e < avail; e++) {
  1309. if (card->soft_tst[e].vc == NULL)
  1310. break;
  1311. }
  1312. if (e >= avail) {
  1313. printk("%s: No free TST entries found\n", card->name);
  1314. return -1;
  1315. }
  1316. NPRINTK("%s: conn %d: first TST entry at %d.\n",
  1317. card->name, vc ? vc->index : -1, e);
  1318. r = n;
  1319. cl = avail;
  1320. data = opc & TSTE_OPC_MASK;
  1321. if (vc && (opc != TSTE_OPC_NULL))
  1322. data = opc | vc->index;
  1323. idle = card->tst[card->tst_index ^ 1];
  1324. /*
  1325. * Fill Soft TST.
  1326. */
  1327. while (r > 0) {
  1328. if ((cl >= avail) && (card->soft_tst[e].vc == NULL)) {
  1329. if (vc)
  1330. card->soft_tst[e].vc = vc;
  1331. else
  1332. card->soft_tst[e].vc = (void *)-1;
  1333. card->soft_tst[e].tste = data;
  1334. if (timer_pending(&card->tst_timer))
  1335. card->soft_tst[e].tste |= TSTE_PUSH_ACTIVE;
  1336. else {
  1337. write_sram(card, idle + e, data);
  1338. card->soft_tst[e].tste |= TSTE_PUSH_IDLE;
  1339. }
  1340. cl -= card->tst_size;
  1341. r--;
  1342. }
  1343. if (++e == avail)
  1344. e = 0;
  1345. cl += n;
  1346. }
  1347. return 0;
  1348. }
  1349. static int
  1350. fill_tst(struct idt77252_dev *card, struct vc_map *vc, int n, unsigned int opc)
  1351. {
  1352. unsigned long flags;
  1353. int res;
  1354. spin_lock_irqsave(&card->tst_lock, flags);
  1355. res = __fill_tst(card, vc, n, opc);
  1356. set_bit(TST_SWITCH_PENDING, &card->tst_state);
  1357. if (!timer_pending(&card->tst_timer))
  1358. mod_timer(&card->tst_timer, jiffies + 1);
  1359. spin_unlock_irqrestore(&card->tst_lock, flags);
  1360. return res;
  1361. }
  1362. static int
  1363. __clear_tst(struct idt77252_dev *card, struct vc_map *vc)
  1364. {
  1365. unsigned long idle;
  1366. int e;
  1367. idle = card->tst[card->tst_index ^ 1];
  1368. for (e = 0; e < card->tst_size - 2; e++) {
  1369. if (card->soft_tst[e].vc == vc) {
  1370. card->soft_tst[e].vc = NULL;
  1371. card->soft_tst[e].tste = TSTE_OPC_VAR;
  1372. if (timer_pending(&card->tst_timer))
  1373. card->soft_tst[e].tste |= TSTE_PUSH_ACTIVE;
  1374. else {
  1375. write_sram(card, idle + e, TSTE_OPC_VAR);
  1376. card->soft_tst[e].tste |= TSTE_PUSH_IDLE;
  1377. }
  1378. }
  1379. }
  1380. return 0;
  1381. }
  1382. static int
  1383. clear_tst(struct idt77252_dev *card, struct vc_map *vc)
  1384. {
  1385. unsigned long flags;
  1386. int res;
  1387. spin_lock_irqsave(&card->tst_lock, flags);
  1388. res = __clear_tst(card, vc);
  1389. set_bit(TST_SWITCH_PENDING, &card->tst_state);
  1390. if (!timer_pending(&card->tst_timer))
  1391. mod_timer(&card->tst_timer, jiffies + 1);
  1392. spin_unlock_irqrestore(&card->tst_lock, flags);
  1393. return res;
  1394. }
  1395. static int
  1396. change_tst(struct idt77252_dev *card, struct vc_map *vc,
  1397. int n, unsigned int opc)
  1398. {
  1399. unsigned long flags;
  1400. int res;
  1401. spin_lock_irqsave(&card->tst_lock, flags);
  1402. __clear_tst(card, vc);
  1403. res = __fill_tst(card, vc, n, opc);
  1404. set_bit(TST_SWITCH_PENDING, &card->tst_state);
  1405. if (!timer_pending(&card->tst_timer))
  1406. mod_timer(&card->tst_timer, jiffies + 1);
  1407. spin_unlock_irqrestore(&card->tst_lock, flags);
  1408. return res;
  1409. }
  1410. static int
  1411. set_tct(struct idt77252_dev *card, struct vc_map *vc)
  1412. {
  1413. unsigned long tct;
  1414. tct = (unsigned long) (card->tct_base + vc->index * SAR_SRAM_TCT_SIZE);
  1415. switch (vc->class) {
  1416. case SCHED_CBR:
  1417. OPRINTK("%s: writing TCT at 0x%lx, SCD 0x%lx.\n",
  1418. card->name, tct, vc->scq->scd);
  1419. write_sram(card, tct + 0, TCT_CBR | vc->scq->scd);
  1420. write_sram(card, tct + 1, 0);
  1421. write_sram(card, tct + 2, 0);
  1422. write_sram(card, tct + 3, 0);
  1423. write_sram(card, tct + 4, 0);
  1424. write_sram(card, tct + 5, 0);
  1425. write_sram(card, tct + 6, 0);
  1426. write_sram(card, tct + 7, 0);
  1427. break;
  1428. case SCHED_UBR:
  1429. OPRINTK("%s: writing TCT at 0x%lx, SCD 0x%lx.\n",
  1430. card->name, tct, vc->scq->scd);
  1431. write_sram(card, tct + 0, TCT_UBR | vc->scq->scd);
  1432. write_sram(card, tct + 1, 0);
  1433. write_sram(card, tct + 2, TCT_TSIF);
  1434. write_sram(card, tct + 3, TCT_HALT | TCT_IDLE);
  1435. write_sram(card, tct + 4, 0);
  1436. write_sram(card, tct + 5, vc->init_er);
  1437. write_sram(card, tct + 6, 0);
  1438. write_sram(card, tct + 7, TCT_FLAG_UBR);
  1439. break;
  1440. case SCHED_VBR:
  1441. case SCHED_ABR:
  1442. default:
  1443. return -ENOSYS;
  1444. }
  1445. return 0;
  1446. }
  1447. /*****************************************************************************/
  1448. /* */
  1449. /* FBQ Handling */
  1450. /* */
  1451. /*****************************************************************************/
  1452. static __inline__ int
  1453. idt77252_fbq_level(struct idt77252_dev *card, int queue)
  1454. {
  1455. return (readl(SAR_REG_STAT) >> (16 + (queue << 2))) & 0x0f;
  1456. }
  1457. static __inline__ int
  1458. idt77252_fbq_full(struct idt77252_dev *card, int queue)
  1459. {
  1460. return (readl(SAR_REG_STAT) >> (16 + (queue << 2))) == 0x0f;
  1461. }
  1462. static int
  1463. push_rx_skb(struct idt77252_dev *card, struct sk_buff *skb, int queue)
  1464. {
  1465. unsigned long flags;
  1466. u32 handle;
  1467. u32 addr;
  1468. skb->data = skb->head;
  1469. skb_reset_tail_pointer(skb);
  1470. skb->len = 0;
  1471. skb_reserve(skb, 16);
  1472. switch (queue) {
  1473. case 0:
  1474. skb_put(skb, SAR_FB_SIZE_0);
  1475. break;
  1476. case 1:
  1477. skb_put(skb, SAR_FB_SIZE_1);
  1478. break;
  1479. case 2:
  1480. skb_put(skb, SAR_FB_SIZE_2);
  1481. break;
  1482. case 3:
  1483. skb_put(skb, SAR_FB_SIZE_3);
  1484. break;
  1485. default:
  1486. return -1;
  1487. }
  1488. if (idt77252_fbq_full(card, queue))
  1489. return -1;
  1490. memset(&skb->data[(skb->len & ~(0x3f)) - 64], 0, 2 * sizeof(u32));
  1491. handle = IDT77252_PRV_POOL(skb);
  1492. addr = IDT77252_PRV_PADDR(skb);
  1493. spin_lock_irqsave(&card->cmd_lock, flags);
  1494. writel(handle, card->fbq[queue]);
  1495. writel(addr, card->fbq[queue]);
  1496. spin_unlock_irqrestore(&card->cmd_lock, flags);
  1497. return 0;
  1498. }
  1499. static void
  1500. add_rx_skb(struct idt77252_dev *card, int queue,
  1501. unsigned int size, unsigned int count)
  1502. {
  1503. struct sk_buff *skb;
  1504. dma_addr_t paddr;
  1505. u32 handle;
  1506. while (count--) {
  1507. skb = dev_alloc_skb(size);
  1508. if (!skb)
  1509. return;
  1510. if (sb_pool_add(card, skb, queue)) {
  1511. printk("%s: SB POOL full\n", __func__);
  1512. goto outfree;
  1513. }
  1514. paddr = dma_map_single(&card->pcidev->dev, skb->data,
  1515. skb_end_pointer(skb) - skb->data,
  1516. DMA_FROM_DEVICE);
  1517. IDT77252_PRV_PADDR(skb) = paddr;
  1518. if (push_rx_skb(card, skb, queue)) {
  1519. printk("%s: FB QUEUE full\n", __func__);
  1520. goto outunmap;
  1521. }
  1522. }
  1523. return;
  1524. outunmap:
  1525. dma_unmap_single(&card->pcidev->dev, IDT77252_PRV_PADDR(skb),
  1526. skb_end_pointer(skb) - skb->data, DMA_FROM_DEVICE);
  1527. handle = IDT77252_PRV_POOL(skb);
  1528. card->sbpool[POOL_QUEUE(handle)].skb[POOL_INDEX(handle)] = NULL;
  1529. outfree:
  1530. dev_kfree_skb(skb);
  1531. }
  1532. static void
  1533. recycle_rx_skb(struct idt77252_dev *card, struct sk_buff *skb)
  1534. {
  1535. u32 handle = IDT77252_PRV_POOL(skb);
  1536. int err;
  1537. dma_sync_single_for_device(&card->pcidev->dev, IDT77252_PRV_PADDR(skb),
  1538. skb_end_pointer(skb) - skb->data,
  1539. DMA_FROM_DEVICE);
  1540. err = push_rx_skb(card, skb, POOL_QUEUE(handle));
  1541. if (err) {
  1542. dma_unmap_single(&card->pcidev->dev, IDT77252_PRV_PADDR(skb),
  1543. skb_end_pointer(skb) - skb->data,
  1544. DMA_FROM_DEVICE);
  1545. sb_pool_remove(card, skb);
  1546. dev_kfree_skb(skb);
  1547. }
  1548. }
  1549. static void
  1550. flush_rx_pool(struct idt77252_dev *card, struct rx_pool *rpp)
  1551. {
  1552. skb_queue_head_init(&rpp->queue);
  1553. rpp->len = 0;
  1554. }
  1555. static void
  1556. recycle_rx_pool_skb(struct idt77252_dev *card, struct rx_pool *rpp)
  1557. {
  1558. struct sk_buff *skb, *tmp;
  1559. skb_queue_walk_safe(&rpp->queue, skb, tmp)
  1560. recycle_rx_skb(card, skb);
  1561. flush_rx_pool(card, rpp);
  1562. }
  1563. /*****************************************************************************/
  1564. /* */
  1565. /* ATM Interface */
  1566. /* */
  1567. /*****************************************************************************/
  1568. static void
  1569. idt77252_phy_put(struct atm_dev *dev, unsigned char value, unsigned long addr)
  1570. {
  1571. write_utility(dev->dev_data, 0x100 + (addr & 0x1ff), value);
  1572. }
  1573. static unsigned char
  1574. idt77252_phy_get(struct atm_dev *dev, unsigned long addr)
  1575. {
  1576. return read_utility(dev->dev_data, 0x100 + (addr & 0x1ff));
  1577. }
  1578. static inline int
  1579. idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
  1580. {
  1581. struct atm_dev *dev = vcc->dev;
  1582. struct idt77252_dev *card = dev->dev_data;
  1583. struct vc_map *vc = vcc->dev_data;
  1584. int err;
  1585. if (vc == NULL) {
  1586. printk("%s: NULL connection in send().\n", card->name);
  1587. atomic_inc(&vcc->stats->tx_err);
  1588. dev_kfree_skb(skb);
  1589. return -EINVAL;
  1590. }
  1591. if (!test_bit(VCF_TX, &vc->flags)) {
  1592. printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
  1593. atomic_inc(&vcc->stats->tx_err);
  1594. dev_kfree_skb(skb);
  1595. return -EINVAL;
  1596. }
  1597. switch (vcc->qos.aal) {
  1598. case ATM_AAL0:
  1599. case ATM_AAL1:
  1600. case ATM_AAL5:
  1601. break;
  1602. default:
  1603. printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
  1604. atomic_inc(&vcc->stats->tx_err);
  1605. dev_kfree_skb(skb);
  1606. return -EINVAL;
  1607. }
  1608. if (skb_shinfo(skb)->nr_frags != 0) {
  1609. printk("%s: No scatter-gather yet.\n", card->name);
  1610. atomic_inc(&vcc->stats->tx_err);
  1611. dev_kfree_skb(skb);
  1612. return -EINVAL;
  1613. }
  1614. ATM_SKB(skb)->vcc = vcc;
  1615. err = queue_skb(card, vc, skb, oam);
  1616. if (err) {
  1617. atomic_inc(&vcc->stats->tx_err);
  1618. dev_kfree_skb(skb);
  1619. return err;
  1620. }
  1621. return 0;
  1622. }
  1623. static int idt77252_send(struct atm_vcc *vcc, struct sk_buff *skb)
  1624. {
  1625. return idt77252_send_skb(vcc, skb, 0);
  1626. }
  1627. static int
  1628. idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
  1629. {
  1630. struct atm_dev *dev = vcc->dev;
  1631. struct idt77252_dev *card = dev->dev_data;
  1632. struct sk_buff *skb;
  1633. skb = dev_alloc_skb(64);
  1634. if (!skb) {
  1635. printk("%s: Out of memory in send_oam().\n", card->name);
  1636. atomic_inc(&vcc->stats->tx_err);
  1637. return -ENOMEM;
  1638. }
  1639. atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
  1640. memcpy(skb_put(skb, 52), cell, 52);
  1641. return idt77252_send_skb(vcc, skb, 1);
  1642. }
  1643. static __inline__ unsigned int
  1644. idt77252_fls(unsigned int x)
  1645. {
  1646. int r = 1;
  1647. if (x == 0)
  1648. return 0;
  1649. if (x & 0xffff0000) {
  1650. x >>= 16;
  1651. r += 16;
  1652. }
  1653. if (x & 0xff00) {
  1654. x >>= 8;
  1655. r += 8;
  1656. }
  1657. if (x & 0xf0) {
  1658. x >>= 4;
  1659. r += 4;
  1660. }
  1661. if (x & 0xc) {
  1662. x >>= 2;
  1663. r += 2;
  1664. }
  1665. if (x & 0x2)
  1666. r += 1;
  1667. return r;
  1668. }
  1669. static u16
  1670. idt77252_int_to_atmfp(unsigned int rate)
  1671. {
  1672. u16 m, e;
  1673. if (rate == 0)
  1674. return 0;
  1675. e = idt77252_fls(rate) - 1;
  1676. if (e < 9)
  1677. m = (rate - (1 << e)) << (9 - e);
  1678. else if (e == 9)
  1679. m = (rate - (1 << e));
  1680. else /* e > 9 */
  1681. m = (rate - (1 << e)) >> (e - 9);
  1682. return 0x4000 | (e << 9) | m;
  1683. }
  1684. static u8
  1685. idt77252_rate_logindex(struct idt77252_dev *card, int pcr)
  1686. {
  1687. u16 afp;
  1688. afp = idt77252_int_to_atmfp(pcr < 0 ? -pcr : pcr);
  1689. if (pcr < 0)
  1690. return rate_to_log[(afp >> 5) & 0x1ff];
  1691. return rate_to_log[((afp >> 5) + 1) & 0x1ff];
  1692. }
  1693. static void
  1694. idt77252_est_timer(unsigned long data)
  1695. {
  1696. struct vc_map *vc = (struct vc_map *)data;
  1697. struct idt77252_dev *card = vc->card;
  1698. struct rate_estimator *est;
  1699. unsigned long flags;
  1700. u32 rate, cps;
  1701. u64 ncells;
  1702. u8 lacr;
  1703. spin_lock_irqsave(&vc->lock, flags);
  1704. est = vc->estimator;
  1705. if (!est)
  1706. goto out;
  1707. ncells = est->cells;
  1708. rate = ((u32)(ncells - est->last_cells)) << (7 - est->interval);
  1709. est->last_cells = ncells;
  1710. est->avcps += ((long)rate - (long)est->avcps) >> est->ewma_log;
  1711. est->cps = (est->avcps + 0x1f) >> 5;
  1712. cps = est->cps;
  1713. if (cps < (est->maxcps >> 4))
  1714. cps = est->maxcps >> 4;
  1715. lacr = idt77252_rate_logindex(card, cps);
  1716. if (lacr > vc->max_er)
  1717. lacr = vc->max_er;
  1718. if (lacr != vc->lacr) {
  1719. vc->lacr = lacr;
  1720. writel(TCMDQ_LACR|(vc->lacr << 16)|vc->index, SAR_REG_TCMDQ);
  1721. }
  1722. est->timer.expires = jiffies + ((HZ / 4) << est->interval);
  1723. add_timer(&est->timer);
  1724. out:
  1725. spin_unlock_irqrestore(&vc->lock, flags);
  1726. }
  1727. static struct rate_estimator *
  1728. idt77252_init_est(struct vc_map *vc, int pcr)
  1729. {
  1730. struct rate_estimator *est;
  1731. est = kzalloc(sizeof(struct rate_estimator), GFP_KERNEL);
  1732. if (!est)
  1733. return NULL;
  1734. est->maxcps = pcr < 0 ? -pcr : pcr;
  1735. est->cps = est->maxcps;
  1736. est->avcps = est->cps << 5;
  1737. est->interval = 2; /* XXX: make this configurable */
  1738. est->ewma_log = 2; /* XXX: make this configurable */
  1739. init_timer(&est->timer);
  1740. est->timer.data = (unsigned long)vc;
  1741. est->timer.function = idt77252_est_timer;
  1742. est->timer.expires = jiffies + ((HZ / 4) << est->interval);
  1743. add_timer(&est->timer);
  1744. return est;
  1745. }
  1746. static int
  1747. idt77252_init_cbr(struct idt77252_dev *card, struct vc_map *vc,
  1748. struct atm_vcc *vcc, struct atm_qos *qos)
  1749. {
  1750. int tst_free, tst_used, tst_entries;
  1751. unsigned long tmpl, modl;
  1752. int tcr, tcra;
  1753. if ((qos->txtp.max_pcr == 0) &&
  1754. (qos->txtp.pcr == 0) && (qos->txtp.min_pcr == 0)) {
  1755. printk("%s: trying to open a CBR VC with cell rate = 0\n",
  1756. card->name);
  1757. return -EINVAL;
  1758. }
  1759. tst_used = 0;
  1760. tst_free = card->tst_free;
  1761. if (test_bit(VCF_TX, &vc->flags))
  1762. tst_used = vc->ntste;
  1763. tst_free += tst_used;
  1764. tcr = atm_pcr_goal(&qos->txtp);
  1765. tcra = tcr >= 0 ? tcr : -tcr;
  1766. TXPRINTK("%s: CBR target cell rate = %d\n", card->name, tcra);
  1767. tmpl = (unsigned long) tcra * ((unsigned long) card->tst_size - 2);
  1768. modl = tmpl % (unsigned long)card->utopia_pcr;
  1769. tst_entries = (int) (tmpl / card->utopia_pcr);
  1770. if (tcr > 0) {
  1771. if (modl > 0)
  1772. tst_entries++;
  1773. } else if (tcr == 0) {
  1774. tst_entries = tst_free - SAR_TST_RESERVED;
  1775. if (tst_entries <= 0) {
  1776. printk("%s: no CBR bandwidth free.\n", card->name);
  1777. return -ENOSR;
  1778. }
  1779. }
  1780. if (tst_entries == 0) {
  1781. printk("%s: selected CBR bandwidth < granularity.\n",
  1782. card->name);
  1783. return -EINVAL;
  1784. }
  1785. if (tst_entries > (tst_free - SAR_TST_RESERVED)) {
  1786. printk("%s: not enough CBR bandwidth free.\n", card->name);
  1787. return -ENOSR;
  1788. }
  1789. vc->ntste = tst_entries;
  1790. card->tst_free = tst_free - tst_entries;
  1791. if (test_bit(VCF_TX, &vc->flags)) {
  1792. if (tst_used == tst_entries)
  1793. return 0;
  1794. OPRINTK("%s: modify %d -> %d entries in TST.\n",
  1795. card->name, tst_used, tst_entries);
  1796. change_tst(card, vc, tst_entries, TSTE_OPC_CBR);
  1797. return 0;
  1798. }
  1799. OPRINTK("%s: setting %d entries in TST.\n", card->name, tst_entries);
  1800. fill_tst(card, vc, tst_entries, TSTE_OPC_CBR);
  1801. return 0;
  1802. }
  1803. static int
  1804. idt77252_init_ubr(struct idt77252_dev *card, struct vc_map *vc,
  1805. struct atm_vcc *vcc, struct atm_qos *qos)
  1806. {
  1807. unsigned long flags;
  1808. int tcr;
  1809. spin_lock_irqsave(&vc->lock, flags);
  1810. if (vc->estimator) {
  1811. del_timer(&vc->estimator->timer);
  1812. kfree(vc->estimator);
  1813. vc->estimator = NULL;
  1814. }
  1815. spin_unlock_irqrestore(&vc->lock, flags);
  1816. tcr = atm_pcr_goal(&qos->txtp);
  1817. if (tcr == 0)
  1818. tcr = card->link_pcr;
  1819. vc->estimator = idt77252_init_est(vc, tcr);
  1820. vc->class = SCHED_UBR;
  1821. vc->init_er = idt77252_rate_logindex(card, tcr);
  1822. vc->lacr = vc->init_er;
  1823. if (tcr < 0)
  1824. vc->max_er = vc->init_er;
  1825. else
  1826. vc->max_er = 0xff;
  1827. return 0;
  1828. }
  1829. static int
  1830. idt77252_init_tx(struct idt77252_dev *card, struct vc_map *vc,
  1831. struct atm_vcc *vcc, struct atm_qos *qos)
  1832. {
  1833. int error;
  1834. if (test_bit(VCF_TX, &vc->flags))
  1835. return -EBUSY;
  1836. switch (qos->txtp.traffic_class) {
  1837. case ATM_CBR:
  1838. vc->class = SCHED_CBR;
  1839. break;
  1840. case ATM_UBR:
  1841. vc->class = SCHED_UBR;
  1842. break;
  1843. case ATM_VBR:
  1844. case ATM_ABR:
  1845. default:
  1846. return -EPROTONOSUPPORT;
  1847. }
  1848. vc->scq = alloc_scq(card, vc->class);
  1849. if (!vc->scq) {
  1850. printk("%s: can't get SCQ.\n", card->name);
  1851. return -ENOMEM;
  1852. }
  1853. vc->scq->scd = get_free_scd(card, vc);
  1854. if (vc->scq->scd == 0) {
  1855. printk("%s: no SCD available.\n", card->name);
  1856. free_scq(card, vc->scq);
  1857. return -ENOMEM;
  1858. }
  1859. fill_scd(card, vc->scq, vc->class);
  1860. if (set_tct(card, vc)) {
  1861. printk("%s: class %d not supported.\n",
  1862. card->name, qos->txtp.traffic_class);
  1863. card->scd2vc[vc->scd_index] = NULL;
  1864. free_scq(card, vc->scq);
  1865. return -EPROTONOSUPPORT;
  1866. }
  1867. switch (vc->class) {
  1868. case SCHED_CBR:
  1869. error = idt77252_init_cbr(card, vc, vcc, qos);
  1870. if (error) {
  1871. card->scd2vc[vc->scd_index] = NULL;
  1872. free_scq(card, vc->scq);
  1873. return error;
  1874. }
  1875. clear_bit(VCF_IDLE, &vc->flags);
  1876. writel(TCMDQ_START | vc->index, SAR_REG_TCMDQ);
  1877. break;
  1878. case SCHED_UBR:
  1879. error = idt77252_init_ubr(card, vc, vcc, qos);
  1880. if (error) {
  1881. card->scd2vc[vc->scd_index] = NULL;
  1882. free_scq(card, vc->scq);
  1883. return error;
  1884. }
  1885. set_bit(VCF_IDLE, &vc->flags);
  1886. break;
  1887. }
  1888. vc->tx_vcc = vcc;
  1889. set_bit(VCF_TX, &vc->flags);
  1890. return 0;
  1891. }
  1892. static int
  1893. idt77252_init_rx(struct idt77252_dev *card, struct vc_map *vc,
  1894. struct atm_vcc *vcc, struct atm_qos *qos)
  1895. {
  1896. unsigned long flags;
  1897. unsigned long addr;
  1898. u32 rcte = 0;
  1899. if (test_bit(VCF_RX, &vc->flags))
  1900. return -EBUSY;
  1901. vc->rx_vcc = vcc;
  1902. set_bit(VCF_RX, &vc->flags);
  1903. if ((vcc->vci == 3) || (vcc->vci == 4))
  1904. return 0;
  1905. flush_rx_pool(card, &vc->rcv.rx_pool);
  1906. rcte |= SAR_RCTE_CONNECTOPEN;
  1907. rcte |= SAR_RCTE_RAWCELLINTEN;
  1908. switch (qos->aal) {
  1909. case ATM_AAL0:
  1910. rcte |= SAR_RCTE_RCQ;
  1911. break;
  1912. case ATM_AAL1:
  1913. rcte |= SAR_RCTE_OAM; /* Let SAR drop Video */
  1914. break;
  1915. case ATM_AAL34:
  1916. rcte |= SAR_RCTE_AAL34;
  1917. break;
  1918. case ATM_AAL5:
  1919. rcte |= SAR_RCTE_AAL5;
  1920. break;
  1921. default:
  1922. rcte |= SAR_RCTE_RCQ;
  1923. break;
  1924. }
  1925. if (qos->aal != ATM_AAL5)
  1926. rcte |= SAR_RCTE_FBP_1;
  1927. else if (qos->rxtp.max_sdu > SAR_FB_SIZE_2)
  1928. rcte |= SAR_RCTE_FBP_3;
  1929. else if (qos->rxtp.max_sdu > SAR_FB_SIZE_1)
  1930. rcte |= SAR_RCTE_FBP_2;
  1931. else if (qos->rxtp.max_sdu > SAR_FB_SIZE_0)
  1932. rcte |= SAR_RCTE_FBP_1;
  1933. else
  1934. rcte |= SAR_RCTE_FBP_01;
  1935. addr = card->rct_base + (vc->index << 2);
  1936. OPRINTK("%s: writing RCT at 0x%lx\n", card->name, addr);
  1937. write_sram(card, addr, rcte);
  1938. spin_lock_irqsave(&card->cmd_lock, flags);
  1939. writel(SAR_CMD_OPEN_CONNECTION | (addr << 2), SAR_REG_CMD);
  1940. waitfor_idle(card);
  1941. spin_unlock_irqrestore(&card->cmd_lock, flags);
  1942. return 0;
  1943. }
  1944. static int
  1945. idt77252_open(struct atm_vcc *vcc)
  1946. {
  1947. struct atm_dev *dev = vcc->dev;
  1948. struct idt77252_dev *card = dev->dev_data;
  1949. struct vc_map *vc;
  1950. unsigned int index;
  1951. unsigned int inuse;
  1952. int error;
  1953. int vci = vcc->vci;
  1954. short vpi = vcc->vpi;
  1955. if (vpi == ATM_VPI_UNSPEC || vci == ATM_VCI_UNSPEC)
  1956. return 0;
  1957. if (vpi >= (1 << card->vpibits)) {
  1958. printk("%s: unsupported VPI: %d\n", card->name, vpi);
  1959. return -EINVAL;
  1960. }
  1961. if (vci >= (1 << card->vcibits)) {
  1962. printk("%s: unsupported VCI: %d\n", card->name, vci);
  1963. return -EINVAL;
  1964. }
  1965. set_bit(ATM_VF_ADDR, &vcc->flags);
  1966. mutex_lock(&card->mutex);
  1967. OPRINTK("%s: opening vpi.vci: %d.%d\n", card->name, vpi, vci);
  1968. switch (vcc->qos.aal) {
  1969. case ATM_AAL0:
  1970. case ATM_AAL1:
  1971. case ATM_AAL5:
  1972. break;
  1973. default:
  1974. printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
  1975. mutex_unlock(&card->mutex);
  1976. return -EPROTONOSUPPORT;
  1977. }
  1978. index = VPCI2VC(card, vpi, vci);
  1979. if (!card->vcs[index]) {
  1980. card->vcs[index] = kzalloc(sizeof(struct vc_map), GFP_KERNEL);
  1981. if (!card->vcs[index]) {
  1982. printk("%s: can't alloc vc in open()\n", card->name);
  1983. mutex_unlock(&card->mutex);
  1984. return -ENOMEM;
  1985. }
  1986. card->vcs[index]->card = card;
  1987. card->vcs[index]->index = index;
  1988. spin_lock_init(&card->vcs[index]->lock);
  1989. }
  1990. vc = card->vcs[index];
  1991. vcc->dev_data = vc;
  1992. IPRINTK("%s: idt77252_open: vc = %d (%d.%d) %s/%s (max RX SDU: %u)\n",
  1993. card->name, vc->index, vcc->vpi, vcc->vci,
  1994. vcc->qos.rxtp.traffic_class != ATM_NONE ? "rx" : "--",
  1995. vcc->qos.txtp.traffic_class != ATM_NONE ? "tx" : "--",
  1996. vcc->qos.rxtp.max_sdu);
  1997. inuse = 0;
  1998. if (vcc->qos.txtp.traffic_class != ATM_NONE &&
  1999. test_bit(VCF_TX, &vc->flags))
  2000. inuse = 1;
  2001. if (vcc->qos.rxtp.traffic_class != ATM_NONE &&
  2002. test_bit(VCF_RX, &vc->flags))
  2003. inuse += 2;
  2004. if (inuse) {
  2005. printk("%s: %s vci already in use.\n", card->name,
  2006. inuse == 1 ? "tx" : inuse == 2 ? "rx" : "tx and rx");
  2007. mutex_unlock(&card->mutex);
  2008. return -EADDRINUSE;
  2009. }
  2010. if (vcc->qos.txtp.traffic_class != ATM_NONE) {
  2011. error = idt77252_init_tx(card, vc, vcc, &vcc->qos);
  2012. if (error) {
  2013. mutex_unlock(&card->mutex);
  2014. return error;
  2015. }
  2016. }
  2017. if (vcc->qos.rxtp.traffic_class != ATM_NONE) {
  2018. error = idt77252_init_rx(card, vc, vcc, &vcc->qos);
  2019. if (error) {
  2020. mutex_unlock(&card->mutex);
  2021. return error;
  2022. }
  2023. }
  2024. set_bit(ATM_VF_READY, &vcc->flags);
  2025. mutex_unlock(&card->mutex);
  2026. return 0;
  2027. }
  2028. static void
  2029. idt77252_close(struct atm_vcc *vcc)
  2030. {
  2031. struct atm_dev *dev = vcc->dev;
  2032. struct idt77252_dev *card = dev->dev_data;
  2033. struct vc_map *vc = vcc->dev_data;
  2034. unsigned long flags;
  2035. unsigned long addr;
  2036. unsigned long timeout;
  2037. mutex_lock(&card->mutex);
  2038. IPRINTK("%s: idt77252_close: vc = %d (%d.%d)\n",
  2039. card->name, vc->index, vcc->vpi, vcc->vci);
  2040. clear_bit(ATM_VF_READY, &vcc->flags);
  2041. if (vcc->qos.rxtp.traffic_class != ATM_NONE) {
  2042. spin_lock_irqsave(&vc->lock, flags);
  2043. clear_bit(VCF_RX, &vc->flags);
  2044. vc->rx_vcc = NULL;
  2045. spin_unlock_irqrestore(&vc->lock, flags);
  2046. if ((vcc->vci == 3) || (vcc->vci == 4))
  2047. goto done;
  2048. addr = card->rct_base + vc->index * SAR_SRAM_RCT_SIZE;
  2049. spin_lock_irqsave(&card->cmd_lock, flags);
  2050. writel(SAR_CMD_CLOSE_CONNECTION | (addr << 2), SAR_REG_CMD);
  2051. waitfor_idle(card);
  2052. spin_unlock_irqrestore(&card->cmd_lock, flags);
  2053. if (skb_queue_len(&vc->rcv.rx_pool.queue) != 0) {
  2054. DPRINTK("%s: closing a VC with pending rx buffers.\n",
  2055. card->name);
  2056. recycle_rx_pool_skb(card, &vc->rcv.rx_pool);
  2057. }
  2058. }
  2059. done:
  2060. if (vcc->qos.txtp.traffic_class != ATM_NONE) {
  2061. spin_lock_irqsave(&vc->lock, flags);
  2062. clear_bit(VCF_TX, &vc->flags);
  2063. clear_bit(VCF_IDLE, &vc->flags);
  2064. clear_bit(VCF_RSV, &vc->flags);
  2065. vc->tx_vcc = NULL;
  2066. if (vc->estimator) {
  2067. del_timer(&vc->estimator->timer);
  2068. kfree(vc->estimator);
  2069. vc->estimator = NULL;
  2070. }
  2071. spin_unlock_irqrestore(&vc->lock, flags);
  2072. timeout = 5 * 1000;
  2073. while (atomic_read(&vc->scq->used) > 0) {
  2074. timeout = msleep_interruptible(timeout);
  2075. if (!timeout) {
  2076. pr_warn("%s: SCQ drain timeout: %u used\n",
  2077. card->name, atomic_read(&vc->scq->used));
  2078. break;
  2079. }
  2080. }
  2081. writel(TCMDQ_HALT | vc->index, SAR_REG_TCMDQ);
  2082. clear_scd(card, vc->scq, vc->class);
  2083. if (vc->class == SCHED_CBR) {
  2084. clear_tst(card, vc);
  2085. card->tst_free += vc->ntste;
  2086. vc->ntste = 0;
  2087. }
  2088. card->scd2vc[vc->scd_index] = NULL;
  2089. free_scq(card, vc->scq);
  2090. }
  2091. mutex_unlock(&card->mutex);
  2092. }
  2093. static int
  2094. idt77252_change_qos(struct atm_vcc *vcc, struct atm_qos *qos, int flags)
  2095. {
  2096. struct atm_dev *dev = vcc->dev;
  2097. struct idt77252_dev *card = dev->dev_data;
  2098. struct vc_map *vc = vcc->dev_data;
  2099. int error = 0;
  2100. mutex_lock(&card->mutex);
  2101. if (qos->txtp.traffic_class != ATM_NONE) {
  2102. if (!test_bit(VCF_TX, &vc->flags)) {
  2103. error = idt77252_init_tx(card, vc, vcc, qos);
  2104. if (error)
  2105. goto out;
  2106. } else {
  2107. switch (qos->txtp.traffic_class) {
  2108. case ATM_CBR:
  2109. error = idt77252_init_cbr(card, vc, vcc, qos);
  2110. if (error)
  2111. goto out;
  2112. break;
  2113. case ATM_UBR:
  2114. error = idt77252_init_ubr(card, vc, vcc, qos);
  2115. if (error)
  2116. goto out;
  2117. if (!test_bit(VCF_IDLE, &vc->flags)) {
  2118. writel(TCMDQ_LACR | (vc->lacr << 16) |
  2119. vc->index, SAR_REG_TCMDQ);
  2120. }
  2121. break;
  2122. case ATM_VBR:
  2123. case ATM_ABR:
  2124. error = -EOPNOTSUPP;
  2125. goto out;
  2126. }
  2127. }
  2128. }
  2129. if ((qos->rxtp.traffic_class != ATM_NONE) &&
  2130. !test_bit(VCF_RX, &vc->flags)) {
  2131. error = idt77252_init_rx(card, vc, vcc, qos);
  2132. if (error)
  2133. goto out;
  2134. }
  2135. memcpy(&vcc->qos, qos, sizeof(struct atm_qos));
  2136. set_bit(ATM_VF_HASQOS, &vcc->flags);
  2137. out:
  2138. mutex_unlock(&card->mutex);
  2139. return error;
  2140. }
  2141. static int
  2142. idt77252_proc_read(struct atm_dev *dev, loff_t * pos, char *page)
  2143. {
  2144. struct idt77252_dev *card = dev->dev_data;
  2145. int i, left;
  2146. left = (int) *pos;
  2147. if (!left--)
  2148. return sprintf(page, "IDT77252 Interrupts:\n");
  2149. if (!left--)
  2150. return sprintf(page, "TSIF: %lu\n", card->irqstat[15]);
  2151. if (!left--)
  2152. return sprintf(page, "TXICP: %lu\n", card->irqstat[14]);
  2153. if (!left--)
  2154. return sprintf(page, "TSQF: %lu\n", card->irqstat[12]);
  2155. if (!left--)
  2156. return sprintf(page, "TMROF: %lu\n", card->irqstat[11]);
  2157. if (!left--)
  2158. return sprintf(page, "PHYI: %lu\n", card->irqstat[10]);
  2159. if (!left--)
  2160. return sprintf(page, "FBQ3A: %lu\n", card->irqstat[8]);
  2161. if (!left--)
  2162. return sprintf(page, "FBQ2A: %lu\n", card->irqstat[7]);
  2163. if (!left--)
  2164. return sprintf(page, "RSQF: %lu\n", card->irqstat[6]);
  2165. if (!left--)
  2166. return sprintf(page, "EPDU: %lu\n", card->irqstat[5]);
  2167. if (!left--)
  2168. return sprintf(page, "RAWCF: %lu\n", card->irqstat[4]);
  2169. if (!left--)
  2170. return sprintf(page, "FBQ1A: %lu\n", card->irqstat[3]);
  2171. if (!left--)
  2172. return sprintf(page, "FBQ0A: %lu\n", card->irqstat[2]);
  2173. if (!left--)
  2174. return sprintf(page, "RSQAF: %lu\n", card->irqstat[1]);
  2175. if (!left--)
  2176. return sprintf(page, "IDT77252 Transmit Connection Table:\n");
  2177. for (i = 0; i < card->tct_size; i++) {
  2178. unsigned long tct;
  2179. struct atm_vcc *vcc;
  2180. struct vc_map *vc;
  2181. char *p;
  2182. vc = card->vcs[i];
  2183. if (!vc)
  2184. continue;
  2185. vcc = NULL;
  2186. if (vc->tx_vcc)
  2187. vcc = vc->tx_vcc;
  2188. if (!vcc)
  2189. continue;
  2190. if (left--)
  2191. continue;
  2192. p = page;
  2193. p += sprintf(p, " %4u: %u.%u: ", i, vcc->vpi, vcc->vci);
  2194. tct = (unsigned long) (card->tct_base + i * SAR_SRAM_TCT_SIZE);
  2195. for (i = 0; i < 8; i++)
  2196. p += sprintf(p, " %08x", read_sram(card, tct + i));
  2197. p += sprintf(p, "\n");
  2198. return p - page;
  2199. }
  2200. return 0;
  2201. }
  2202. /*****************************************************************************/
  2203. /* */
  2204. /* Interrupt handler */
  2205. /* */
  2206. /*****************************************************************************/
  2207. static void
  2208. idt77252_collect_stat(struct idt77252_dev *card)
  2209. {
  2210. (void) readl(SAR_REG_CDC);
  2211. (void) readl(SAR_REG_VPEC);
  2212. (void) readl(SAR_REG_ICC);
  2213. }
  2214. static irqreturn_t
  2215. idt77252_interrupt(int irq, void *dev_id)
  2216. {
  2217. struct idt77252_dev *card = dev_id;
  2218. u32 stat;
  2219. stat = readl(SAR_REG_STAT) & 0xffff;
  2220. if (!stat) /* no interrupt for us */
  2221. return IRQ_NONE;
  2222. if (test_and_set_bit(IDT77252_BIT_INTERRUPT, &card->flags)) {
  2223. printk("%s: Re-entering irq_handler()\n", card->name);
  2224. goto out;
  2225. }
  2226. writel(stat, SAR_REG_STAT); /* reset interrupt */
  2227. if (stat & SAR_STAT_TSIF) { /* entry written to TSQ */
  2228. INTPRINTK("%s: TSIF\n", card->name);
  2229. card->irqstat[15]++;
  2230. idt77252_tx(card);
  2231. }
  2232. if (stat & SAR_STAT_TXICP) { /* Incomplete CS-PDU has */
  2233. INTPRINTK("%s: TXICP\n", card->name);
  2234. card->irqstat[14]++;
  2235. #ifdef CONFIG_ATM_IDT77252_DEBUG
  2236. idt77252_tx_dump(card);
  2237. #endif
  2238. }
  2239. if (stat & SAR_STAT_TSQF) { /* TSQ 7/8 full */
  2240. INTPRINTK("%s: TSQF\n", card->name);
  2241. card->irqstat[12]++;
  2242. idt77252_tx(card);
  2243. }
  2244. if (stat & SAR_STAT_TMROF) { /* Timer overflow */
  2245. INTPRINTK("%s: TMROF\n", card->name);
  2246. card->irqstat[11]++;
  2247. idt77252_collect_stat(card);
  2248. }
  2249. if (stat & SAR_STAT_EPDU) { /* Got complete CS-PDU */
  2250. INTPRINTK("%s: EPDU\n", card->name);
  2251. card->irqstat[5]++;
  2252. idt77252_rx(card);
  2253. }
  2254. if (stat & SAR_STAT_RSQAF) { /* RSQ is 7/8 full */
  2255. INTPRINTK("%s: RSQAF\n", card->name);
  2256. card->irqstat[1]++;
  2257. idt77252_rx(card);
  2258. }
  2259. if (stat & SAR_STAT_RSQF) { /* RSQ is full */
  2260. INTPRINTK("%s: RSQF\n", card->name);
  2261. card->irqstat[6]++;
  2262. idt77252_rx(card);
  2263. }
  2264. if (stat & SAR_STAT_RAWCF) { /* Raw cell received */
  2265. INTPRINTK("%s: RAWCF\n", card->name);
  2266. card->irqstat[4]++;
  2267. idt77252_rx_raw(card);
  2268. }
  2269. if (stat & SAR_STAT_PHYI) { /* PHY device interrupt */
  2270. INTPRINTK("%s: PHYI", card->name);
  2271. card->irqstat[10]++;
  2272. if (card->atmdev->phy && card->atmdev->phy->interrupt)
  2273. card->atmdev->phy->interrupt(card->atmdev);
  2274. }
  2275. if (stat & (SAR_STAT_FBQ0A | SAR_STAT_FBQ1A |
  2276. SAR_STAT_FBQ2A | SAR_STAT_FBQ3A)) {
  2277. writel(readl(SAR_REG_CFG) & ~(SAR_CFG_FBIE), SAR_REG_CFG);
  2278. INTPRINTK("%s: FBQA: %04x\n", card->name, stat);
  2279. if (stat & SAR_STAT_FBQ0A)
  2280. card->irqstat[2]++;
  2281. if (stat & SAR_STAT_FBQ1A)
  2282. card->irqstat[3]++;
  2283. if (stat & SAR_STAT_FBQ2A)
  2284. card->irqstat[7]++;
  2285. if (stat & SAR_STAT_FBQ3A)
  2286. card->irqstat[8]++;
  2287. schedule_work(&card->tqueue);
  2288. }
  2289. out:
  2290. clear_bit(IDT77252_BIT_INTERRUPT, &card->flags);
  2291. return IRQ_HANDLED;
  2292. }
  2293. static void
  2294. idt77252_softint(struct work_struct *work)
  2295. {
  2296. struct idt77252_dev *card =
  2297. container_of(work, struct idt77252_dev, tqueue);
  2298. u32 stat;
  2299. int done;
  2300. for (done = 1; ; done = 1) {
  2301. stat = readl(SAR_REG_STAT) >> 16;
  2302. if ((stat & 0x0f) < SAR_FBQ0_HIGH) {
  2303. add_rx_skb(card, 0, SAR_FB_SIZE_0, 32);
  2304. done = 0;
  2305. }
  2306. stat >>= 4;
  2307. if ((stat & 0x0f) < SAR_FBQ1_HIGH) {
  2308. add_rx_skb(card, 1, SAR_FB_SIZE_1, 32);
  2309. done = 0;
  2310. }
  2311. stat >>= 4;
  2312. if ((stat & 0x0f) < SAR_FBQ2_HIGH) {
  2313. add_rx_skb(card, 2, SAR_FB_SIZE_2, 32);
  2314. done = 0;
  2315. }
  2316. stat >>= 4;
  2317. if ((stat & 0x0f) < SAR_FBQ3_HIGH) {
  2318. add_rx_skb(card, 3, SAR_FB_SIZE_3, 32);
  2319. done = 0;
  2320. }
  2321. if (done)
  2322. break;
  2323. }
  2324. writel(readl(SAR_REG_CFG) | SAR_CFG_FBIE, SAR_REG_CFG);
  2325. }
  2326. static int
  2327. open_card_oam(struct idt77252_dev *card)
  2328. {
  2329. unsigned long flags;
  2330. unsigned long addr;
  2331. struct vc_map *vc;
  2332. int vpi, vci;
  2333. int index;
  2334. u32 rcte;
  2335. for (vpi = 0; vpi < (1 << card->vpibits); vpi++) {
  2336. for (vci = 3; vci < 5; vci++) {
  2337. index = VPCI2VC(card, vpi, vci);
  2338. vc = kzalloc(sizeof(struct vc_map), GFP_KERNEL);
  2339. if (!vc) {
  2340. printk("%s: can't alloc vc\n", card->name);
  2341. return -ENOMEM;
  2342. }
  2343. vc->index = index;
  2344. card->vcs[index] = vc;
  2345. flush_rx_pool(card, &vc->rcv.rx_pool);
  2346. rcte = SAR_RCTE_CONNECTOPEN |
  2347. SAR_RCTE_RAWCELLINTEN |
  2348. SAR_RCTE_RCQ |
  2349. SAR_RCTE_FBP_1;
  2350. addr = card->rct_base + (vc->index << 2);
  2351. write_sram(card, addr, rcte);
  2352. spin_lock_irqsave(&card->cmd_lock, flags);
  2353. writel(SAR_CMD_OPEN_CONNECTION | (addr << 2),
  2354. SAR_REG_CMD);
  2355. waitfor_idle(card);
  2356. spin_unlock_irqrestore(&card->cmd_lock, flags);
  2357. }
  2358. }
  2359. return 0;
  2360. }
  2361. static void
  2362. close_card_oam(struct idt77252_dev *card)
  2363. {
  2364. unsigned long flags;
  2365. unsigned long addr;
  2366. struct vc_map *vc;
  2367. int vpi, vci;
  2368. int index;
  2369. for (vpi = 0; vpi < (1 << card->vpibits); vpi++) {
  2370. for (vci = 3; vci < 5; vci++) {
  2371. index = VPCI2VC(card, vpi, vci);
  2372. vc = card->vcs[index];
  2373. addr = card->rct_base + vc->index * SAR_SRAM_RCT_SIZE;
  2374. spin_lock_irqsave(&card->cmd_lock, flags);
  2375. writel(SAR_CMD_CLOSE_CONNECTION | (addr << 2),
  2376. SAR_REG_CMD);
  2377. waitfor_idle(card);
  2378. spin_unlock_irqrestore(&card->cmd_lock, flags);
  2379. if (skb_queue_len(&vc->rcv.rx_pool.queue) != 0) {
  2380. DPRINTK("%s: closing a VC "
  2381. "with pending rx buffers.\n",
  2382. card->name);
  2383. recycle_rx_pool_skb(card, &vc->rcv.rx_pool);
  2384. }
  2385. }
  2386. }
  2387. }
  2388. static int
  2389. open_card_ubr0(struct idt77252_dev *card)
  2390. {
  2391. struct vc_map *vc;
  2392. vc = kzalloc(sizeof(struct vc_map), GFP_KERNEL);
  2393. if (!vc) {
  2394. printk("%s: can't alloc vc\n", card->name);
  2395. return -ENOMEM;
  2396. }
  2397. card->vcs[0] = vc;
  2398. vc->class = SCHED_UBR0;
  2399. vc->scq = alloc_scq(card, vc->class);
  2400. if (!vc->scq) {
  2401. printk("%s: can't get SCQ.\n", card->name);
  2402. return -ENOMEM;
  2403. }
  2404. card->scd2vc[0] = vc;
  2405. vc->scd_index = 0;
  2406. vc->scq->scd = card->scd_base;
  2407. fill_scd(card, vc->scq, vc->class);
  2408. write_sram(card, card->tct_base + 0, TCT_UBR | card->scd_base);
  2409. write_sram(card, card->tct_base + 1, 0);
  2410. write_sram(card, card->tct_base + 2, 0);
  2411. write_sram(card, card->tct_base + 3, 0);
  2412. write_sram(card, card->tct_base + 4, 0);
  2413. write_sram(card, card->tct_base + 5, 0);
  2414. write_sram(card, card->tct_base + 6, 0);
  2415. write_sram(card, card->tct_base + 7, TCT_FLAG_UBR);
  2416. clear_bit(VCF_IDLE, &vc->flags);
  2417. writel(TCMDQ_START | 0, SAR_REG_TCMDQ);
  2418. return 0;
  2419. }
  2420. static int
  2421. idt77252_dev_open(struct idt77252_dev *card)
  2422. {
  2423. u32 conf;
  2424. if (!test_bit(IDT77252_BIT_INIT, &card->flags)) {
  2425. printk("%s: SAR not yet initialized.\n", card->name);
  2426. return -1;
  2427. }
  2428. conf = SAR_CFG_RXPTH| /* enable receive path */
  2429. SAR_RX_DELAY | /* interrupt on complete PDU */
  2430. SAR_CFG_RAWIE | /* interrupt enable on raw cells */
  2431. SAR_CFG_RQFIE | /* interrupt on RSQ almost full */
  2432. SAR_CFG_TMOIE | /* interrupt on timer overflow */
  2433. SAR_CFG_FBIE | /* interrupt on low free buffers */
  2434. SAR_CFG_TXEN | /* transmit operation enable */
  2435. SAR_CFG_TXINT | /* interrupt on transmit status */
  2436. SAR_CFG_TXUIE | /* interrupt on transmit underrun */
  2437. SAR_CFG_TXSFI | /* interrupt on TSQ almost full */
  2438. SAR_CFG_PHYIE /* enable PHY interrupts */
  2439. ;
  2440. #ifdef CONFIG_ATM_IDT77252_RCV_ALL
  2441. /* Test RAW cell receive. */
  2442. conf |= SAR_CFG_VPECA;
  2443. #endif
  2444. writel(readl(SAR_REG_CFG) | conf, SAR_REG_CFG);
  2445. if (open_card_oam(card)) {
  2446. printk("%s: Error initializing OAM.\n", card->name);
  2447. return -1;
  2448. }
  2449. if (open_card_ubr0(card)) {
  2450. printk("%s: Error initializing UBR0.\n", card->name);
  2451. return -1;
  2452. }
  2453. IPRINTK("%s: opened IDT77252 ABR SAR.\n", card->name);
  2454. return 0;
  2455. }
  2456. static void idt77252_dev_close(struct atm_dev *dev)
  2457. {
  2458. struct idt77252_dev *card = dev->dev_data;
  2459. u32 conf;
  2460. close_card_oam(card);
  2461. conf = SAR_CFG_RXPTH | /* enable receive path */
  2462. SAR_RX_DELAY | /* interrupt on complete PDU */
  2463. SAR_CFG_RAWIE | /* interrupt enable on raw cells */
  2464. SAR_CFG_RQFIE | /* interrupt on RSQ almost full */
  2465. SAR_CFG_TMOIE | /* interrupt on timer overflow */
  2466. SAR_CFG_FBIE | /* interrupt on low free buffers */
  2467. SAR_CFG_TXEN | /* transmit operation enable */
  2468. SAR_CFG_TXINT | /* interrupt on transmit status */
  2469. SAR_CFG_TXUIE | /* interrupt on xmit underrun */
  2470. SAR_CFG_TXSFI /* interrupt on TSQ almost full */
  2471. ;
  2472. writel(readl(SAR_REG_CFG) & ~(conf), SAR_REG_CFG);
  2473. DIPRINTK("%s: closed IDT77252 ABR SAR.\n", card->name);
  2474. }
  2475. /*****************************************************************************/
  2476. /* */
  2477. /* Initialisation and Deinitialization of IDT77252 */
  2478. /* */
  2479. /*****************************************************************************/
  2480. static void
  2481. deinit_card(struct idt77252_dev *card)
  2482. {
  2483. struct sk_buff *skb;
  2484. int i, j;
  2485. if (!test_bit(IDT77252_BIT_INIT, &card->flags)) {
  2486. printk("%s: SAR not yet initialized.\n", card->name);
  2487. return;
  2488. }
  2489. DIPRINTK("idt77252: deinitialize card %u\n", card->index);
  2490. writel(0, SAR_REG_CFG);
  2491. if (card->atmdev)
  2492. atm_dev_deregister(card->atmdev);
  2493. for (i = 0; i < 4; i++) {
  2494. for (j = 0; j < FBQ_SIZE; j++) {
  2495. skb = card->sbpool[i].skb[j];
  2496. if (skb) {
  2497. dma_unmap_single(&card->pcidev->dev,
  2498. IDT77252_PRV_PADDR(skb),
  2499. (skb_end_pointer(skb) -
  2500. skb->data),
  2501. DMA_FROM_DEVICE);
  2502. card->sbpool[i].skb[j] = NULL;
  2503. dev_kfree_skb(skb);
  2504. }
  2505. }
  2506. }
  2507. vfree(card->soft_tst);
  2508. vfree(card->scd2vc);
  2509. vfree(card->vcs);
  2510. if (card->raw_cell_hnd) {
  2511. dma_free_coherent(&card->pcidev->dev, 2 * sizeof(u32),
  2512. card->raw_cell_hnd, card->raw_cell_paddr);
  2513. }
  2514. if (card->rsq.base) {
  2515. DIPRINTK("%s: Release RSQ ...\n", card->name);
  2516. deinit_rsq(card);
  2517. }
  2518. if (card->tsq.base) {
  2519. DIPRINTK("%s: Release TSQ ...\n", card->name);
  2520. deinit_tsq(card);
  2521. }
  2522. DIPRINTK("idt77252: Release IRQ.\n");
  2523. free_irq(card->pcidev->irq, card);
  2524. for (i = 0; i < 4; i++) {
  2525. if (card->fbq[i])
  2526. iounmap(card->fbq[i]);
  2527. }
  2528. if (card->membase)
  2529. iounmap(card->membase);
  2530. clear_bit(IDT77252_BIT_INIT, &card->flags);
  2531. DIPRINTK("%s: Card deinitialized.\n", card->name);
  2532. }
  2533. static void init_sram(struct idt77252_dev *card)
  2534. {
  2535. int i;
  2536. for (i = 0; i < card->sramsize; i += 4)
  2537. write_sram(card, (i >> 2), 0);
  2538. /* set SRAM layout for THIS card */
  2539. if (card->sramsize == (512 * 1024)) {
  2540. card->tct_base = SAR_SRAM_TCT_128_BASE;
  2541. card->tct_size = (SAR_SRAM_TCT_128_TOP - card->tct_base + 1)
  2542. / SAR_SRAM_TCT_SIZE;
  2543. card->rct_base = SAR_SRAM_RCT_128_BASE;
  2544. card->rct_size = (SAR_SRAM_RCT_128_TOP - card->rct_base + 1)
  2545. / SAR_SRAM_RCT_SIZE;
  2546. card->rt_base = SAR_SRAM_RT_128_BASE;
  2547. card->scd_base = SAR_SRAM_SCD_128_BASE;
  2548. card->scd_size = (SAR_SRAM_SCD_128_TOP - card->scd_base + 1)
  2549. / SAR_SRAM_SCD_SIZE;
  2550. card->tst[0] = SAR_SRAM_TST1_128_BASE;
  2551. card->tst[1] = SAR_SRAM_TST2_128_BASE;
  2552. card->tst_size = SAR_SRAM_TST1_128_TOP - card->tst[0] + 1;
  2553. card->abrst_base = SAR_SRAM_ABRSTD_128_BASE;
  2554. card->abrst_size = SAR_ABRSTD_SIZE_8K;
  2555. card->fifo_base = SAR_SRAM_FIFO_128_BASE;
  2556. card->fifo_size = SAR_RXFD_SIZE_32K;
  2557. } else {
  2558. card->tct_base = SAR_SRAM_TCT_32_BASE;
  2559. card->tct_size = (SAR_SRAM_TCT_32_TOP - card->tct_base + 1)
  2560. / SAR_SRAM_TCT_SIZE;
  2561. card->rct_base = SAR_SRAM_RCT_32_BASE;
  2562. card->rct_size = (SAR_SRAM_RCT_32_TOP - card->rct_base + 1)
  2563. / SAR_SRAM_RCT_SIZE;
  2564. card->rt_base = SAR_SRAM_RT_32_BASE;
  2565. card->scd_base = SAR_SRAM_SCD_32_BASE;
  2566. card->scd_size = (SAR_SRAM_SCD_32_TOP - card->scd_base + 1)
  2567. / SAR_SRAM_SCD_SIZE;
  2568. card->tst[0] = SAR_SRAM_TST1_32_BASE;
  2569. card->tst[1] = SAR_SRAM_TST2_32_BASE;
  2570. card->tst_size = (SAR_SRAM_TST1_32_TOP - card->tst[0] + 1);
  2571. card->abrst_base = SAR_SRAM_ABRSTD_32_BASE;
  2572. card->abrst_size = SAR_ABRSTD_SIZE_1K;
  2573. card->fifo_base = SAR_SRAM_FIFO_32_BASE;
  2574. card->fifo_size = SAR_RXFD_SIZE_4K;
  2575. }
  2576. /* Initialize TCT */
  2577. for (i = 0; i < card->tct_size; i++) {
  2578. write_sram(card, i * SAR_SRAM_TCT_SIZE + 0, 0);
  2579. write_sram(card, i * SAR_SRAM_TCT_SIZE + 1, 0);
  2580. write_sram(card, i * SAR_SRAM_TCT_SIZE + 2, 0);
  2581. write_sram(card, i * SAR_SRAM_TCT_SIZE + 3, 0);
  2582. write_sram(card, i * SAR_SRAM_TCT_SIZE + 4, 0);
  2583. write_sram(card, i * SAR_SRAM_TCT_SIZE + 5, 0);
  2584. write_sram(card, i * SAR_SRAM_TCT_SIZE + 6, 0);
  2585. write_sram(card, i * SAR_SRAM_TCT_SIZE + 7, 0);
  2586. }
  2587. /* Initialize RCT */
  2588. for (i = 0; i < card->rct_size; i++) {
  2589. write_sram(card, card->rct_base + i * SAR_SRAM_RCT_SIZE,
  2590. (u32) SAR_RCTE_RAWCELLINTEN);
  2591. write_sram(card, card->rct_base + i * SAR_SRAM_RCT_SIZE + 1,
  2592. (u32) 0);
  2593. write_sram(card, card->rct_base + i * SAR_SRAM_RCT_SIZE + 2,
  2594. (u32) 0);
  2595. write_sram(card, card->rct_base + i * SAR_SRAM_RCT_SIZE + 3,
  2596. (u32) 0xffffffff);
  2597. }
  2598. writel((SAR_FBQ0_LOW << 28) | 0x00000000 | 0x00000000 |
  2599. (SAR_FB_SIZE_0 / 48), SAR_REG_FBQS0);
  2600. writel((SAR_FBQ1_LOW << 28) | 0x00000000 | 0x00000000 |
  2601. (SAR_FB_SIZE_1 / 48), SAR_REG_FBQS1);
  2602. writel((SAR_FBQ2_LOW << 28) | 0x00000000 | 0x00000000 |
  2603. (SAR_FB_SIZE_2 / 48), SAR_REG_FBQS2);
  2604. writel((SAR_FBQ3_LOW << 28) | 0x00000000 | 0x00000000 |
  2605. (SAR_FB_SIZE_3 / 48), SAR_REG_FBQS3);
  2606. /* Initialize rate table */
  2607. for (i = 0; i < 256; i++) {
  2608. write_sram(card, card->rt_base + i, log_to_rate[i]);
  2609. }
  2610. for (i = 0; i < 128; i++) {
  2611. unsigned int tmp;
  2612. tmp = rate_to_log[(i << 2) + 0] << 0;
  2613. tmp |= rate_to_log[(i << 2) + 1] << 8;
  2614. tmp |= rate_to_log[(i << 2) + 2] << 16;
  2615. tmp |= rate_to_log[(i << 2) + 3] << 24;
  2616. write_sram(card, card->rt_base + 256 + i, tmp);
  2617. }
  2618. #if 0 /* Fill RDF and AIR tables. */
  2619. for (i = 0; i < 128; i++) {
  2620. unsigned int tmp;
  2621. tmp = RDF[0][(i << 1) + 0] << 16;
  2622. tmp |= RDF[0][(i << 1) + 1] << 0;
  2623. write_sram(card, card->rt_base + 512 + i, tmp);
  2624. }
  2625. for (i = 0; i < 128; i++) {
  2626. unsigned int tmp;
  2627. tmp = AIR[0][(i << 1) + 0] << 16;
  2628. tmp |= AIR[0][(i << 1) + 1] << 0;
  2629. write_sram(card, card->rt_base + 640 + i, tmp);
  2630. }
  2631. #endif
  2632. IPRINTK("%s: initialize rate table ...\n", card->name);
  2633. writel(card->rt_base << 2, SAR_REG_RTBL);
  2634. /* Initialize TSTs */
  2635. IPRINTK("%s: initialize TST ...\n", card->name);
  2636. card->tst_free = card->tst_size - 2; /* last two are jumps */
  2637. for (i = card->tst[0]; i < card->tst[0] + card->tst_size - 2; i++)
  2638. write_sram(card, i, TSTE_OPC_VAR);
  2639. write_sram(card, i++, TSTE_OPC_JMP | (card->tst[0] << 2));
  2640. idt77252_sram_write_errors = 1;
  2641. write_sram(card, i++, TSTE_OPC_JMP | (card->tst[1] << 2));
  2642. idt77252_sram_write_errors = 0;
  2643. for (i = card->tst[1]; i < card->tst[1] + card->tst_size - 2; i++)
  2644. write_sram(card, i, TSTE_OPC_VAR);
  2645. write_sram(card, i++, TSTE_OPC_JMP | (card->tst[1] << 2));
  2646. idt77252_sram_write_errors = 1;
  2647. write_sram(card, i++, TSTE_OPC_JMP | (card->tst[0] << 2));
  2648. idt77252_sram_write_errors = 0;
  2649. card->tst_index = 0;
  2650. writel(card->tst[0] << 2, SAR_REG_TSTB);
  2651. /* Initialize ABRSTD and Receive FIFO */
  2652. IPRINTK("%s: initialize ABRSTD ...\n", card->name);
  2653. writel(card->abrst_size | (card->abrst_base << 2),
  2654. SAR_REG_ABRSTD);
  2655. IPRINTK("%s: initialize receive fifo ...\n", card->name);
  2656. writel(card->fifo_size | (card->fifo_base << 2),
  2657. SAR_REG_RXFD);
  2658. IPRINTK("%s: SRAM initialization complete.\n", card->name);
  2659. }
  2660. static int init_card(struct atm_dev *dev)
  2661. {
  2662. struct idt77252_dev *card = dev->dev_data;
  2663. struct pci_dev *pcidev = card->pcidev;
  2664. unsigned long tmpl, modl;
  2665. unsigned int linkrate, rsvdcr;
  2666. unsigned int tst_entries;
  2667. struct net_device *tmp;
  2668. char tname[10];
  2669. u32 size;
  2670. u_char pci_byte;
  2671. u32 conf;
  2672. int i, k;
  2673. if (test_bit(IDT77252_BIT_INIT, &card->flags)) {
  2674. printk("Error: SAR already initialized.\n");
  2675. return -1;
  2676. }
  2677. /*****************************************************************/
  2678. /* P C I C O N F I G U R A T I O N */
  2679. /*****************************************************************/
  2680. /* Set PCI Retry-Timeout and TRDY timeout */
  2681. IPRINTK("%s: Checking PCI retries.\n", card->name);
  2682. if (pci_read_config_byte(pcidev, 0x40, &pci_byte) != 0) {
  2683. printk("%s: can't read PCI retry timeout.\n", card->name);
  2684. deinit_card(card);
  2685. return -1;
  2686. }
  2687. if (pci_byte != 0) {
  2688. IPRINTK("%s: PCI retry timeout: %d, set to 0.\n",
  2689. card->name, pci_byte);
  2690. if (pci_write_config_byte(pcidev, 0x40, 0) != 0) {
  2691. printk("%s: can't set PCI retry timeout.\n",
  2692. card->name);
  2693. deinit_card(card);
  2694. return -1;
  2695. }
  2696. }
  2697. IPRINTK("%s: Checking PCI TRDY.\n", card->name);
  2698. if (pci_read_config_byte(pcidev, 0x41, &pci_byte) != 0) {
  2699. printk("%s: can't read PCI TRDY timeout.\n", card->name);
  2700. deinit_card(card);
  2701. return -1;
  2702. }
  2703. if (pci_byte != 0) {
  2704. IPRINTK("%s: PCI TRDY timeout: %d, set to 0.\n",
  2705. card->name, pci_byte);
  2706. if (pci_write_config_byte(pcidev, 0x41, 0) != 0) {
  2707. printk("%s: can't set PCI TRDY timeout.\n", card->name);
  2708. deinit_card(card);
  2709. return -1;
  2710. }
  2711. }
  2712. /* Reset Timer register */
  2713. if (readl(SAR_REG_STAT) & SAR_STAT_TMROF) {
  2714. printk("%s: resetting timer overflow.\n", card->name);
  2715. writel(SAR_STAT_TMROF, SAR_REG_STAT);
  2716. }
  2717. IPRINTK("%s: Request IRQ ... ", card->name);
  2718. if (request_irq(pcidev->irq, idt77252_interrupt, IRQF_SHARED,
  2719. card->name, card) != 0) {
  2720. printk("%s: can't allocate IRQ.\n", card->name);
  2721. deinit_card(card);
  2722. return -1;
  2723. }
  2724. IPRINTK("got %d.\n", pcidev->irq);
  2725. /*****************************************************************/
  2726. /* C H E C K A N D I N I T S R A M */
  2727. /*****************************************************************/
  2728. IPRINTK("%s: Initializing SRAM\n", card->name);
  2729. /* preset size of connecton table, so that init_sram() knows about it */
  2730. conf = SAR_CFG_TX_FIFO_SIZE_9 | /* Use maximum fifo size */
  2731. SAR_CFG_RXSTQ_SIZE_8k | /* Receive Status Queue is 8k */
  2732. SAR_CFG_IDLE_CLP | /* Set CLP on idle cells */
  2733. #ifndef ATM_IDT77252_SEND_IDLE
  2734. SAR_CFG_NO_IDLE | /* Do not send idle cells */
  2735. #endif
  2736. 0;
  2737. if (card->sramsize == (512 * 1024))
  2738. conf |= SAR_CFG_CNTBL_1k;
  2739. else
  2740. conf |= SAR_CFG_CNTBL_512;
  2741. switch (vpibits) {
  2742. case 0:
  2743. conf |= SAR_CFG_VPVCS_0;
  2744. break;
  2745. default:
  2746. case 1:
  2747. conf |= SAR_CFG_VPVCS_1;
  2748. break;
  2749. case 2:
  2750. conf |= SAR_CFG_VPVCS_2;
  2751. break;
  2752. case 8:
  2753. conf |= SAR_CFG_VPVCS_8;
  2754. break;
  2755. }
  2756. writel(readl(SAR_REG_CFG) | conf, SAR_REG_CFG);
  2757. init_sram(card);
  2758. /********************************************************************/
  2759. /* A L L O C R A M A N D S E T V A R I O U S T H I N G S */
  2760. /********************************************************************/
  2761. /* Initialize TSQ */
  2762. if (0 != init_tsq(card)) {
  2763. deinit_card(card);
  2764. return -1;
  2765. }
  2766. /* Initialize RSQ */
  2767. if (0 != init_rsq(card)) {
  2768. deinit_card(card);
  2769. return -1;
  2770. }
  2771. card->vpibits = vpibits;
  2772. if (card->sramsize == (512 * 1024)) {
  2773. card->vcibits = 10 - card->vpibits;
  2774. } else {
  2775. card->vcibits = 9 - card->vpibits;
  2776. }
  2777. card->vcimask = 0;
  2778. for (k = 0, i = 1; k < card->vcibits; k++) {
  2779. card->vcimask |= i;
  2780. i <<= 1;
  2781. }
  2782. IPRINTK("%s: Setting VPI/VCI mask to zero.\n", card->name);
  2783. writel(0, SAR_REG_VPM);
  2784. /* Little Endian Order */
  2785. writel(0, SAR_REG_GP);
  2786. /* Initialize RAW Cell Handle Register */
  2787. card->raw_cell_hnd = dma_zalloc_coherent(&card->pcidev->dev,
  2788. 2 * sizeof(u32),
  2789. &card->raw_cell_paddr,
  2790. GFP_KERNEL);
  2791. if (!card->raw_cell_hnd) {
  2792. printk("%s: memory allocation failure.\n", card->name);
  2793. deinit_card(card);
  2794. return -1;
  2795. }
  2796. writel(card->raw_cell_paddr, SAR_REG_RAWHND);
  2797. IPRINTK("%s: raw cell handle is at 0x%p.\n", card->name,
  2798. card->raw_cell_hnd);
  2799. size = sizeof(struct vc_map *) * card->tct_size;
  2800. IPRINTK("%s: allocate %d byte for VC map.\n", card->name, size);
  2801. card->vcs = vzalloc(size);
  2802. if (!card->vcs) {
  2803. printk("%s: memory allocation failure.\n", card->name);
  2804. deinit_card(card);
  2805. return -1;
  2806. }
  2807. size = sizeof(struct vc_map *) * card->scd_size;
  2808. IPRINTK("%s: allocate %d byte for SCD to VC mapping.\n",
  2809. card->name, size);
  2810. card->scd2vc = vzalloc(size);
  2811. if (!card->scd2vc) {
  2812. printk("%s: memory allocation failure.\n", card->name);
  2813. deinit_card(card);
  2814. return -1;
  2815. }
  2816. size = sizeof(struct tst_info) * (card->tst_size - 2);
  2817. IPRINTK("%s: allocate %d byte for TST to VC mapping.\n",
  2818. card->name, size);
  2819. card->soft_tst = vmalloc(size);
  2820. if (!card->soft_tst) {
  2821. printk("%s: memory allocation failure.\n", card->name);
  2822. deinit_card(card);
  2823. return -1;
  2824. }
  2825. for (i = 0; i < card->tst_size - 2; i++) {
  2826. card->soft_tst[i].tste = TSTE_OPC_VAR;
  2827. card->soft_tst[i].vc = NULL;
  2828. }
  2829. if (dev->phy == NULL) {
  2830. printk("%s: No LT device defined.\n", card->name);
  2831. deinit_card(card);
  2832. return -1;
  2833. }
  2834. if (dev->phy->ioctl == NULL) {
  2835. printk("%s: LT had no IOCTL function defined.\n", card->name);
  2836. deinit_card(card);
  2837. return -1;
  2838. }
  2839. #ifdef CONFIG_ATM_IDT77252_USE_SUNI
  2840. /*
  2841. * this is a jhs hack to get around special functionality in the
  2842. * phy driver for the atecom hardware; the functionality doesn't
  2843. * exist in the linux atm suni driver
  2844. *
  2845. * it isn't the right way to do things, but as the guy from NIST
  2846. * said, talking about their measurement of the fine structure
  2847. * constant, "it's good enough for government work."
  2848. */
  2849. linkrate = 149760000;
  2850. #endif
  2851. card->link_pcr = (linkrate / 8 / 53);
  2852. printk("%s: Linkrate on ATM line : %u bit/s, %u cell/s.\n",
  2853. card->name, linkrate, card->link_pcr);
  2854. #ifdef ATM_IDT77252_SEND_IDLE
  2855. card->utopia_pcr = card->link_pcr;
  2856. #else
  2857. card->utopia_pcr = (160000000 / 8 / 54);
  2858. #endif
  2859. rsvdcr = 0;
  2860. if (card->utopia_pcr > card->link_pcr)
  2861. rsvdcr = card->utopia_pcr - card->link_pcr;
  2862. tmpl = (unsigned long) rsvdcr * ((unsigned long) card->tst_size - 2);
  2863. modl = tmpl % (unsigned long)card->utopia_pcr;
  2864. tst_entries = (int) (tmpl / (unsigned long)card->utopia_pcr);
  2865. if (modl)
  2866. tst_entries++;
  2867. card->tst_free -= tst_entries;
  2868. fill_tst(card, NULL, tst_entries, TSTE_OPC_NULL);
  2869. #ifdef HAVE_EEPROM
  2870. idt77252_eeprom_init(card);
  2871. printk("%s: EEPROM: %02x:", card->name,
  2872. idt77252_eeprom_read_status(card));
  2873. for (i = 0; i < 0x80; i++) {
  2874. printk(" %02x",
  2875. idt77252_eeprom_read_byte(card, i)
  2876. );
  2877. }
  2878. printk("\n");
  2879. #endif /* HAVE_EEPROM */
  2880. /*
  2881. * XXX: <hack>
  2882. */
  2883. sprintf(tname, "eth%d", card->index);
  2884. tmp = dev_get_by_name(&init_net, tname); /* jhs: was "tmp = dev_get(tname);" */
  2885. if (tmp) {
  2886. memcpy(card->atmdev->esi, tmp->dev_addr, 6);
  2887. dev_put(tmp);
  2888. printk("%s: ESI %pM\n", card->name, card->atmdev->esi);
  2889. }
  2890. /*
  2891. * XXX: </hack>
  2892. */
  2893. /* Set Maximum Deficit Count for now. */
  2894. writel(0xffff, SAR_REG_MDFCT);
  2895. set_bit(IDT77252_BIT_INIT, &card->flags);
  2896. XPRINTK("%s: IDT77252 ABR SAR initialization complete.\n", card->name);
  2897. return 0;
  2898. }
  2899. /*****************************************************************************/
  2900. /* */
  2901. /* Probing of IDT77252 ABR SAR */
  2902. /* */
  2903. /*****************************************************************************/
  2904. static int idt77252_preset(struct idt77252_dev *card)
  2905. {
  2906. u16 pci_command;
  2907. /*****************************************************************/
  2908. /* P C I C O N F I G U R A T I O N */
  2909. /*****************************************************************/
  2910. XPRINTK("%s: Enable PCI master and memory access for SAR.\n",
  2911. card->name);
  2912. if (pci_read_config_word(card->pcidev, PCI_COMMAND, &pci_command)) {
  2913. printk("%s: can't read PCI_COMMAND.\n", card->name);
  2914. deinit_card(card);
  2915. return -1;
  2916. }
  2917. if (!(pci_command & PCI_COMMAND_IO)) {
  2918. printk("%s: PCI_COMMAND: %04x (???)\n",
  2919. card->name, pci_command);
  2920. deinit_card(card);
  2921. return (-1);
  2922. }
  2923. pci_command |= (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
  2924. if (pci_write_config_word(card->pcidev, PCI_COMMAND, pci_command)) {
  2925. printk("%s: can't write PCI_COMMAND.\n", card->name);
  2926. deinit_card(card);
  2927. return -1;
  2928. }
  2929. /*****************************************************************/
  2930. /* G E N E R I C R E S E T */
  2931. /*****************************************************************/
  2932. /* Software reset */
  2933. writel(SAR_CFG_SWRST, SAR_REG_CFG);
  2934. mdelay(1);
  2935. writel(0, SAR_REG_CFG);
  2936. IPRINTK("%s: Software resetted.\n", card->name);
  2937. return 0;
  2938. }
  2939. static unsigned long probe_sram(struct idt77252_dev *card)
  2940. {
  2941. u32 data, addr;
  2942. writel(0, SAR_REG_DR0);
  2943. writel(SAR_CMD_WRITE_SRAM | (0 << 2), SAR_REG_CMD);
  2944. for (addr = 0x4000; addr < 0x80000; addr += 0x4000) {
  2945. writel(ATM_POISON, SAR_REG_DR0);
  2946. writel(SAR_CMD_WRITE_SRAM | (addr << 2), SAR_REG_CMD);
  2947. writel(SAR_CMD_READ_SRAM | (0 << 2), SAR_REG_CMD);
  2948. data = readl(SAR_REG_DR0);
  2949. if (data != 0)
  2950. break;
  2951. }
  2952. return addr * sizeof(u32);
  2953. }
  2954. static int idt77252_init_one(struct pci_dev *pcidev,
  2955. const struct pci_device_id *id)
  2956. {
  2957. static struct idt77252_dev **last = &idt77252_chain;
  2958. static int index = 0;
  2959. unsigned long membase, srambase;
  2960. struct idt77252_dev *card;
  2961. struct atm_dev *dev;
  2962. int i, err;
  2963. if ((err = pci_enable_device(pcidev))) {
  2964. printk("idt77252: can't enable PCI device at %s\n", pci_name(pcidev));
  2965. return err;
  2966. }
  2967. if ((err = dma_set_mask_and_coherent(&pcidev->dev, DMA_BIT_MASK(32)))) {
  2968. printk("idt77252: can't enable DMA for PCI device at %s\n", pci_name(pcidev));
  2969. return err;
  2970. }
  2971. card = kzalloc(sizeof(struct idt77252_dev), GFP_KERNEL);
  2972. if (!card) {
  2973. printk("idt77252-%d: can't allocate private data\n", index);
  2974. err = -ENOMEM;
  2975. goto err_out_disable_pdev;
  2976. }
  2977. card->revision = pcidev->revision;
  2978. card->index = index;
  2979. card->pcidev = pcidev;
  2980. sprintf(card->name, "idt77252-%d", card->index);
  2981. INIT_WORK(&card->tqueue, idt77252_softint);
  2982. membase = pci_resource_start(pcidev, 1);
  2983. srambase = pci_resource_start(pcidev, 2);
  2984. mutex_init(&card->mutex);
  2985. spin_lock_init(&card->cmd_lock);
  2986. spin_lock_init(&card->tst_lock);
  2987. init_timer(&card->tst_timer);
  2988. card->tst_timer.data = (unsigned long)card;
  2989. card->tst_timer.function = tst_timer;
  2990. /* Do the I/O remapping... */
  2991. card->membase = ioremap(membase, 1024);
  2992. if (!card->membase) {
  2993. printk("%s: can't ioremap() membase\n", card->name);
  2994. err = -EIO;
  2995. goto err_out_free_card;
  2996. }
  2997. if (idt77252_preset(card)) {
  2998. printk("%s: preset failed\n", card->name);
  2999. err = -EIO;
  3000. goto err_out_iounmap;
  3001. }
  3002. dev = atm_dev_register("idt77252", &pcidev->dev, &idt77252_ops, -1,
  3003. NULL);
  3004. if (!dev) {
  3005. printk("%s: can't register atm device\n", card->name);
  3006. err = -EIO;
  3007. goto err_out_iounmap;
  3008. }
  3009. dev->dev_data = card;
  3010. card->atmdev = dev;
  3011. #ifdef CONFIG_ATM_IDT77252_USE_SUNI
  3012. suni_init(dev);
  3013. if (!dev->phy) {
  3014. printk("%s: can't init SUNI\n", card->name);
  3015. err = -EIO;
  3016. goto err_out_deinit_card;
  3017. }
  3018. #endif /* CONFIG_ATM_IDT77252_USE_SUNI */
  3019. card->sramsize = probe_sram(card);
  3020. for (i = 0; i < 4; i++) {
  3021. card->fbq[i] = ioremap(srambase | 0x200000 | (i << 18), 4);
  3022. if (!card->fbq[i]) {
  3023. printk("%s: can't ioremap() FBQ%d\n", card->name, i);
  3024. err = -EIO;
  3025. goto err_out_deinit_card;
  3026. }
  3027. }
  3028. printk("%s: ABR SAR (Rev %c): MEM %08lx SRAM %08lx [%u KB]\n",
  3029. card->name, ((card->revision > 1) && (card->revision < 25)) ?
  3030. 'A' + card->revision - 1 : '?', membase, srambase,
  3031. card->sramsize / 1024);
  3032. if (init_card(dev)) {
  3033. printk("%s: init_card failed\n", card->name);
  3034. err = -EIO;
  3035. goto err_out_deinit_card;
  3036. }
  3037. dev->ci_range.vpi_bits = card->vpibits;
  3038. dev->ci_range.vci_bits = card->vcibits;
  3039. dev->link_rate = card->link_pcr;
  3040. if (dev->phy->start)
  3041. dev->phy->start(dev);
  3042. if (idt77252_dev_open(card)) {
  3043. printk("%s: dev_open failed\n", card->name);
  3044. err = -EIO;
  3045. goto err_out_stop;
  3046. }
  3047. *last = card;
  3048. last = &card->next;
  3049. index++;
  3050. return 0;
  3051. err_out_stop:
  3052. if (dev->phy->stop)
  3053. dev->phy->stop(dev);
  3054. err_out_deinit_card:
  3055. deinit_card(card);
  3056. err_out_iounmap:
  3057. iounmap(card->membase);
  3058. err_out_free_card:
  3059. kfree(card);
  3060. err_out_disable_pdev:
  3061. pci_disable_device(pcidev);
  3062. return err;
  3063. }
  3064. static struct pci_device_id idt77252_pci_tbl[] =
  3065. {
  3066. { PCI_VDEVICE(IDT, PCI_DEVICE_ID_IDT_IDT77252), 0 },
  3067. { 0, }
  3068. };
  3069. MODULE_DEVICE_TABLE(pci, idt77252_pci_tbl);
  3070. static struct pci_driver idt77252_driver = {
  3071. .name = "idt77252",
  3072. .id_table = idt77252_pci_tbl,
  3073. .probe = idt77252_init_one,
  3074. };
  3075. static int __init idt77252_init(void)
  3076. {
  3077. struct sk_buff *skb;
  3078. printk("%s: at %p\n", __func__, idt77252_init);
  3079. if (sizeof(skb->cb) < sizeof(struct atm_skb_data) +
  3080. sizeof(struct idt77252_skb_prv)) {
  3081. printk(KERN_ERR "%s: skb->cb is too small (%lu < %lu)\n",
  3082. __func__, (unsigned long) sizeof(skb->cb),
  3083. (unsigned long) sizeof(struct atm_skb_data) +
  3084. sizeof(struct idt77252_skb_prv));
  3085. return -EIO;
  3086. }
  3087. return pci_register_driver(&idt77252_driver);
  3088. }
  3089. static void __exit idt77252_exit(void)
  3090. {
  3091. struct idt77252_dev *card;
  3092. struct atm_dev *dev;
  3093. pci_unregister_driver(&idt77252_driver);
  3094. while (idt77252_chain) {
  3095. card = idt77252_chain;
  3096. dev = card->atmdev;
  3097. idt77252_chain = card->next;
  3098. if (dev->phy->stop)
  3099. dev->phy->stop(dev);
  3100. deinit_card(card);
  3101. pci_disable_device(card->pcidev);
  3102. kfree(card);
  3103. }
  3104. DIPRINTK("idt77252: finished cleanup-module().\n");
  3105. }
  3106. module_init(idt77252_init);
  3107. module_exit(idt77252_exit);
  3108. MODULE_LICENSE("GPL");
  3109. module_param(vpibits, uint, 0);
  3110. MODULE_PARM_DESC(vpibits, "number of VPI bits supported (0, 1, or 2)");
  3111. #ifdef CONFIG_ATM_IDT77252_DEBUG
  3112. module_param(debug, ulong, 0644);
  3113. MODULE_PARM_DESC(debug, "debug bitmap, see drivers/atm/idt77252.h");
  3114. #endif
  3115. MODULE_AUTHOR("Eddie C. Dost <ecd@atecom.com>");
  3116. MODULE_DESCRIPTION("IDT77252 ABR SAR Driver");