he.c 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090
  1. /* $Id: he.c,v 1.18 2003/05/06 22:57:15 chas Exp $ */
  2. /*
  3. he.c
  4. ForeRunnerHE ATM Adapter driver for ATM on Linux
  5. Copyright (C) 1999-2001 Naval Research Laboratory
  6. This library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Lesser General Public
  8. License as published by the Free Software Foundation; either
  9. version 2.1 of the License, or (at your option) any later version.
  10. This library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with this library; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. /*
  19. he.c
  20. ForeRunnerHE ATM Adapter driver for ATM on Linux
  21. Copyright (C) 1999-2001 Naval Research Laboratory
  22. Permission to use, copy, modify and distribute this software and its
  23. documentation is hereby granted, provided that both the copyright
  24. notice and this permission notice appear in all copies of the software,
  25. derivative works or modified versions, and any portions thereof, and
  26. that both notices appear in supporting documentation.
  27. NRL ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
  28. DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
  29. RESULTING FROM THE USE OF THIS SOFTWARE.
  30. This driver was written using the "Programmer's Reference Manual for
  31. ForeRunnerHE(tm)", MANU0361-01 - Rev. A, 08/21/98.
  32. AUTHORS:
  33. chas williams <chas@cmf.nrl.navy.mil>
  34. eric kinzie <ekinzie@cmf.nrl.navy.mil>
  35. NOTES:
  36. 4096 supported 'connections'
  37. group 0 is used for all traffic
  38. interrupt queue 0 is used for all interrupts
  39. aal0 support (based on work from ulrich.u.muller@nokia.com)
  40. */
  41. #include <linux/config.h>
  42. #include <linux/module.h>
  43. #include <linux/version.h>
  44. #include <linux/kernel.h>
  45. #include <linux/skbuff.h>
  46. #include <linux/pci.h>
  47. #include <linux/errno.h>
  48. #include <linux/types.h>
  49. #include <linux/string.h>
  50. #include <linux/delay.h>
  51. #include <linux/init.h>
  52. #include <linux/mm.h>
  53. #include <linux/sched.h>
  54. #include <linux/timer.h>
  55. #include <linux/interrupt.h>
  56. #include <linux/dma-mapping.h>
  57. #include <asm/io.h>
  58. #include <asm/byteorder.h>
  59. #include <asm/uaccess.h>
  60. #include <linux/atmdev.h>
  61. #include <linux/atm.h>
  62. #include <linux/sonet.h>
  63. #define USE_TASKLET
  64. #undef USE_SCATTERGATHER
  65. #undef USE_CHECKSUM_HW /* still confused about this */
  66. #define USE_RBPS
  67. #undef USE_RBPS_POOL /* if memory is tight try this */
  68. #undef USE_RBPL_POOL /* if memory is tight try this */
  69. #define USE_TPD_POOL
  70. /* #undef CONFIG_ATM_HE_USE_SUNI */
  71. /* #undef HE_DEBUG */
  72. #include "he.h"
  73. #include "suni.h"
  74. #include <linux/atm_he.h>
  75. #define hprintk(fmt,args...) printk(KERN_ERR DEV_LABEL "%d: " fmt, he_dev->number , ##args)
  76. #ifdef HE_DEBUG
  77. #define HPRINTK(fmt,args...) printk(KERN_DEBUG DEV_LABEL "%d: " fmt, he_dev->number , ##args)
  78. #else /* !HE_DEBUG */
  79. #define HPRINTK(fmt,args...) do { } while (0)
  80. #endif /* HE_DEBUG */
  81. /* version definition */
  82. static char *version = "$Id: he.c,v 1.18 2003/05/06 22:57:15 chas Exp $";
  83. /* declarations */
  84. static int he_open(struct atm_vcc *vcc);
  85. static void he_close(struct atm_vcc *vcc);
  86. static int he_send(struct atm_vcc *vcc, struct sk_buff *skb);
  87. static int he_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg);
  88. static irqreturn_t he_irq_handler(int irq, void *dev_id, struct pt_regs *regs);
  89. static void he_tasklet(unsigned long data);
  90. static int he_proc_read(struct atm_dev *dev,loff_t *pos,char *page);
  91. static int he_start(struct atm_dev *dev);
  92. static void he_stop(struct he_dev *dev);
  93. static void he_phy_put(struct atm_dev *, unsigned char, unsigned long);
  94. static unsigned char he_phy_get(struct atm_dev *, unsigned long);
  95. static u8 read_prom_byte(struct he_dev *he_dev, int addr);
  96. /* globals */
  97. static struct he_dev *he_devs;
  98. static int disable64;
  99. static short nvpibits = -1;
  100. static short nvcibits = -1;
  101. static short rx_skb_reserve = 16;
  102. static int irq_coalesce = 1;
  103. static int sdh = 0;
  104. /* Read from EEPROM = 0000 0011b */
  105. static unsigned int readtab[] = {
  106. CS_HIGH | CLK_HIGH,
  107. CS_LOW | CLK_LOW,
  108. CLK_HIGH, /* 0 */
  109. CLK_LOW,
  110. CLK_HIGH, /* 0 */
  111. CLK_LOW,
  112. CLK_HIGH, /* 0 */
  113. CLK_LOW,
  114. CLK_HIGH, /* 0 */
  115. CLK_LOW,
  116. CLK_HIGH, /* 0 */
  117. CLK_LOW,
  118. CLK_HIGH, /* 0 */
  119. CLK_LOW | SI_HIGH,
  120. CLK_HIGH | SI_HIGH, /* 1 */
  121. CLK_LOW | SI_HIGH,
  122. CLK_HIGH | SI_HIGH /* 1 */
  123. };
  124. /* Clock to read from/write to the EEPROM */
  125. static unsigned int clocktab[] = {
  126. CLK_LOW,
  127. CLK_HIGH,
  128. CLK_LOW,
  129. CLK_HIGH,
  130. CLK_LOW,
  131. CLK_HIGH,
  132. CLK_LOW,
  133. CLK_HIGH,
  134. CLK_LOW,
  135. CLK_HIGH,
  136. CLK_LOW,
  137. CLK_HIGH,
  138. CLK_LOW,
  139. CLK_HIGH,
  140. CLK_LOW,
  141. CLK_HIGH,
  142. CLK_LOW
  143. };
  144. static struct atmdev_ops he_ops =
  145. {
  146. .open = he_open,
  147. .close = he_close,
  148. .ioctl = he_ioctl,
  149. .send = he_send,
  150. .phy_put = he_phy_put,
  151. .phy_get = he_phy_get,
  152. .proc_read = he_proc_read,
  153. .owner = THIS_MODULE
  154. };
  155. #define he_writel(dev, val, reg) do { writel(val, (dev)->membase + (reg)); wmb(); } while (0)
  156. #define he_readl(dev, reg) readl((dev)->membase + (reg))
  157. /* section 2.12 connection memory access */
  158. static __inline__ void
  159. he_writel_internal(struct he_dev *he_dev, unsigned val, unsigned addr,
  160. unsigned flags)
  161. {
  162. he_writel(he_dev, val, CON_DAT);
  163. (void) he_readl(he_dev, CON_DAT); /* flush posted writes */
  164. he_writel(he_dev, flags | CON_CTL_WRITE | CON_CTL_ADDR(addr), CON_CTL);
  165. while (he_readl(he_dev, CON_CTL) & CON_CTL_BUSY);
  166. }
  167. #define he_writel_rcm(dev, val, reg) \
  168. he_writel_internal(dev, val, reg, CON_CTL_RCM)
  169. #define he_writel_tcm(dev, val, reg) \
  170. he_writel_internal(dev, val, reg, CON_CTL_TCM)
  171. #define he_writel_mbox(dev, val, reg) \
  172. he_writel_internal(dev, val, reg, CON_CTL_MBOX)
  173. static unsigned
  174. he_readl_internal(struct he_dev *he_dev, unsigned addr, unsigned flags)
  175. {
  176. he_writel(he_dev, flags | CON_CTL_READ | CON_CTL_ADDR(addr), CON_CTL);
  177. while (he_readl(he_dev, CON_CTL) & CON_CTL_BUSY);
  178. return he_readl(he_dev, CON_DAT);
  179. }
  180. #define he_readl_rcm(dev, reg) \
  181. he_readl_internal(dev, reg, CON_CTL_RCM)
  182. #define he_readl_tcm(dev, reg) \
  183. he_readl_internal(dev, reg, CON_CTL_TCM)
  184. #define he_readl_mbox(dev, reg) \
  185. he_readl_internal(dev, reg, CON_CTL_MBOX)
  186. /* figure 2.2 connection id */
  187. #define he_mkcid(dev, vpi, vci) (((vpi << (dev)->vcibits) | vci) & 0x1fff)
  188. /* 2.5.1 per connection transmit state registers */
  189. #define he_writel_tsr0(dev, val, cid) \
  190. he_writel_tcm(dev, val, CONFIG_TSRA | (cid << 3) | 0)
  191. #define he_readl_tsr0(dev, cid) \
  192. he_readl_tcm(dev, CONFIG_TSRA | (cid << 3) | 0)
  193. #define he_writel_tsr1(dev, val, cid) \
  194. he_writel_tcm(dev, val, CONFIG_TSRA | (cid << 3) | 1)
  195. #define he_writel_tsr2(dev, val, cid) \
  196. he_writel_tcm(dev, val, CONFIG_TSRA | (cid << 3) | 2)
  197. #define he_writel_tsr3(dev, val, cid) \
  198. he_writel_tcm(dev, val, CONFIG_TSRA | (cid << 3) | 3)
  199. #define he_writel_tsr4(dev, val, cid) \
  200. he_writel_tcm(dev, val, CONFIG_TSRA | (cid << 3) | 4)
  201. /* from page 2-20
  202. *
  203. * NOTE While the transmit connection is active, bits 23 through 0
  204. * of this register must not be written by the host. Byte
  205. * enables should be used during normal operation when writing
  206. * the most significant byte.
  207. */
  208. #define he_writel_tsr4_upper(dev, val, cid) \
  209. he_writel_internal(dev, val, CONFIG_TSRA | (cid << 3) | 4, \
  210. CON_CTL_TCM \
  211. | CON_BYTE_DISABLE_2 \
  212. | CON_BYTE_DISABLE_1 \
  213. | CON_BYTE_DISABLE_0)
  214. #define he_readl_tsr4(dev, cid) \
  215. he_readl_tcm(dev, CONFIG_TSRA | (cid << 3) | 4)
  216. #define he_writel_tsr5(dev, val, cid) \
  217. he_writel_tcm(dev, val, CONFIG_TSRA | (cid << 3) | 5)
  218. #define he_writel_tsr6(dev, val, cid) \
  219. he_writel_tcm(dev, val, CONFIG_TSRA | (cid << 3) | 6)
  220. #define he_writel_tsr7(dev, val, cid) \
  221. he_writel_tcm(dev, val, CONFIG_TSRA | (cid << 3) | 7)
  222. #define he_writel_tsr8(dev, val, cid) \
  223. he_writel_tcm(dev, val, CONFIG_TSRB | (cid << 2) | 0)
  224. #define he_writel_tsr9(dev, val, cid) \
  225. he_writel_tcm(dev, val, CONFIG_TSRB | (cid << 2) | 1)
  226. #define he_writel_tsr10(dev, val, cid) \
  227. he_writel_tcm(dev, val, CONFIG_TSRB | (cid << 2) | 2)
  228. #define he_writel_tsr11(dev, val, cid) \
  229. he_writel_tcm(dev, val, CONFIG_TSRB | (cid << 2) | 3)
  230. #define he_writel_tsr12(dev, val, cid) \
  231. he_writel_tcm(dev, val, CONFIG_TSRC | (cid << 1) | 0)
  232. #define he_writel_tsr13(dev, val, cid) \
  233. he_writel_tcm(dev, val, CONFIG_TSRC | (cid << 1) | 1)
  234. #define he_writel_tsr14(dev, val, cid) \
  235. he_writel_tcm(dev, val, CONFIG_TSRD | cid)
  236. #define he_writel_tsr14_upper(dev, val, cid) \
  237. he_writel_internal(dev, val, CONFIG_TSRD | cid, \
  238. CON_CTL_TCM \
  239. | CON_BYTE_DISABLE_2 \
  240. | CON_BYTE_DISABLE_1 \
  241. | CON_BYTE_DISABLE_0)
  242. /* 2.7.1 per connection receive state registers */
  243. #define he_writel_rsr0(dev, val, cid) \
  244. he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 0)
  245. #define he_readl_rsr0(dev, cid) \
  246. he_readl_rcm(dev, 0x00000 | (cid << 3) | 0)
  247. #define he_writel_rsr1(dev, val, cid) \
  248. he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 1)
  249. #define he_writel_rsr2(dev, val, cid) \
  250. he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 2)
  251. #define he_writel_rsr3(dev, val, cid) \
  252. he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 3)
  253. #define he_writel_rsr4(dev, val, cid) \
  254. he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 4)
  255. #define he_writel_rsr5(dev, val, cid) \
  256. he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 5)
  257. #define he_writel_rsr6(dev, val, cid) \
  258. he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 6)
  259. #define he_writel_rsr7(dev, val, cid) \
  260. he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 7)
  261. static __inline__ struct atm_vcc*
  262. __find_vcc(struct he_dev *he_dev, unsigned cid)
  263. {
  264. struct hlist_head *head;
  265. struct atm_vcc *vcc;
  266. struct hlist_node *node;
  267. struct sock *s;
  268. short vpi;
  269. int vci;
  270. vpi = cid >> he_dev->vcibits;
  271. vci = cid & ((1 << he_dev->vcibits) - 1);
  272. head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
  273. sk_for_each(s, node, head) {
  274. vcc = atm_sk(s);
  275. if (vcc->dev == he_dev->atm_dev &&
  276. vcc->vci == vci && vcc->vpi == vpi &&
  277. vcc->qos.rxtp.traffic_class != ATM_NONE) {
  278. return vcc;
  279. }
  280. }
  281. return NULL;
  282. }
  283. static int __devinit
  284. he_init_one(struct pci_dev *pci_dev, const struct pci_device_id *pci_ent)
  285. {
  286. struct atm_dev *atm_dev = NULL;
  287. struct he_dev *he_dev = NULL;
  288. int err = 0;
  289. printk(KERN_INFO "he: %s\n", version);
  290. if (pci_enable_device(pci_dev))
  291. return -EIO;
  292. if (pci_set_dma_mask(pci_dev, DMA_32BIT_MASK) != 0) {
  293. printk(KERN_WARNING "he: no suitable dma available\n");
  294. err = -EIO;
  295. goto init_one_failure;
  296. }
  297. atm_dev = atm_dev_register(DEV_LABEL, &he_ops, -1, NULL);
  298. if (!atm_dev) {
  299. err = -ENODEV;
  300. goto init_one_failure;
  301. }
  302. pci_set_drvdata(pci_dev, atm_dev);
  303. he_dev = (struct he_dev *) kmalloc(sizeof(struct he_dev),
  304. GFP_KERNEL);
  305. if (!he_dev) {
  306. err = -ENOMEM;
  307. goto init_one_failure;
  308. }
  309. memset(he_dev, 0, sizeof(struct he_dev));
  310. he_dev->pci_dev = pci_dev;
  311. he_dev->atm_dev = atm_dev;
  312. he_dev->atm_dev->dev_data = he_dev;
  313. atm_dev->dev_data = he_dev;
  314. he_dev->number = atm_dev->number;
  315. if (he_start(atm_dev)) {
  316. he_stop(he_dev);
  317. err = -ENODEV;
  318. goto init_one_failure;
  319. }
  320. he_dev->next = NULL;
  321. if (he_devs)
  322. he_dev->next = he_devs;
  323. he_devs = he_dev;
  324. return 0;
  325. init_one_failure:
  326. if (atm_dev)
  327. atm_dev_deregister(atm_dev);
  328. kfree(he_dev);
  329. pci_disable_device(pci_dev);
  330. return err;
  331. }
  332. static void __devexit
  333. he_remove_one (struct pci_dev *pci_dev)
  334. {
  335. struct atm_dev *atm_dev;
  336. struct he_dev *he_dev;
  337. atm_dev = pci_get_drvdata(pci_dev);
  338. he_dev = HE_DEV(atm_dev);
  339. /* need to remove from he_devs */
  340. he_stop(he_dev);
  341. atm_dev_deregister(atm_dev);
  342. kfree(he_dev);
  343. pci_set_drvdata(pci_dev, NULL);
  344. pci_disable_device(pci_dev);
  345. }
  346. static unsigned
  347. rate_to_atmf(unsigned rate) /* cps to atm forum format */
  348. {
  349. #define NONZERO (1 << 14)
  350. unsigned exp = 0;
  351. if (rate == 0)
  352. return 0;
  353. rate <<= 9;
  354. while (rate > 0x3ff) {
  355. ++exp;
  356. rate >>= 1;
  357. }
  358. return (NONZERO | (exp << 9) | (rate & 0x1ff));
  359. }
  360. static void __init
  361. he_init_rx_lbfp0(struct he_dev *he_dev)
  362. {
  363. unsigned i, lbm_offset, lbufd_index, lbuf_addr, lbuf_count;
  364. unsigned lbufs_per_row = he_dev->cells_per_row / he_dev->cells_per_lbuf;
  365. unsigned lbuf_bufsize = he_dev->cells_per_lbuf * ATM_CELL_PAYLOAD;
  366. unsigned row_offset = he_dev->r0_startrow * he_dev->bytes_per_row;
  367. lbufd_index = 0;
  368. lbm_offset = he_readl(he_dev, RCMLBM_BA);
  369. he_writel(he_dev, lbufd_index, RLBF0_H);
  370. for (i = 0, lbuf_count = 0; i < he_dev->r0_numbuffs; ++i) {
  371. lbufd_index += 2;
  372. lbuf_addr = (row_offset + (lbuf_count * lbuf_bufsize)) / 32;
  373. he_writel_rcm(he_dev, lbuf_addr, lbm_offset);
  374. he_writel_rcm(he_dev, lbufd_index, lbm_offset + 1);
  375. if (++lbuf_count == lbufs_per_row) {
  376. lbuf_count = 0;
  377. row_offset += he_dev->bytes_per_row;
  378. }
  379. lbm_offset += 4;
  380. }
  381. he_writel(he_dev, lbufd_index - 2, RLBF0_T);
  382. he_writel(he_dev, he_dev->r0_numbuffs, RLBF0_C);
  383. }
  384. static void __init
  385. he_init_rx_lbfp1(struct he_dev *he_dev)
  386. {
  387. unsigned i, lbm_offset, lbufd_index, lbuf_addr, lbuf_count;
  388. unsigned lbufs_per_row = he_dev->cells_per_row / he_dev->cells_per_lbuf;
  389. unsigned lbuf_bufsize = he_dev->cells_per_lbuf * ATM_CELL_PAYLOAD;
  390. unsigned row_offset = he_dev->r1_startrow * he_dev->bytes_per_row;
  391. lbufd_index = 1;
  392. lbm_offset = he_readl(he_dev, RCMLBM_BA) + (2 * lbufd_index);
  393. he_writel(he_dev, lbufd_index, RLBF1_H);
  394. for (i = 0, lbuf_count = 0; i < he_dev->r1_numbuffs; ++i) {
  395. lbufd_index += 2;
  396. lbuf_addr = (row_offset + (lbuf_count * lbuf_bufsize)) / 32;
  397. he_writel_rcm(he_dev, lbuf_addr, lbm_offset);
  398. he_writel_rcm(he_dev, lbufd_index, lbm_offset + 1);
  399. if (++lbuf_count == lbufs_per_row) {
  400. lbuf_count = 0;
  401. row_offset += he_dev->bytes_per_row;
  402. }
  403. lbm_offset += 4;
  404. }
  405. he_writel(he_dev, lbufd_index - 2, RLBF1_T);
  406. he_writel(he_dev, he_dev->r1_numbuffs, RLBF1_C);
  407. }
  408. static void __init
  409. he_init_tx_lbfp(struct he_dev *he_dev)
  410. {
  411. unsigned i, lbm_offset, lbufd_index, lbuf_addr, lbuf_count;
  412. unsigned lbufs_per_row = he_dev->cells_per_row / he_dev->cells_per_lbuf;
  413. unsigned lbuf_bufsize = he_dev->cells_per_lbuf * ATM_CELL_PAYLOAD;
  414. unsigned row_offset = he_dev->tx_startrow * he_dev->bytes_per_row;
  415. lbufd_index = he_dev->r0_numbuffs + he_dev->r1_numbuffs;
  416. lbm_offset = he_readl(he_dev, RCMLBM_BA) + (2 * lbufd_index);
  417. he_writel(he_dev, lbufd_index, TLBF_H);
  418. for (i = 0, lbuf_count = 0; i < he_dev->tx_numbuffs; ++i) {
  419. lbufd_index += 1;
  420. lbuf_addr = (row_offset + (lbuf_count * lbuf_bufsize)) / 32;
  421. he_writel_rcm(he_dev, lbuf_addr, lbm_offset);
  422. he_writel_rcm(he_dev, lbufd_index, lbm_offset + 1);
  423. if (++lbuf_count == lbufs_per_row) {
  424. lbuf_count = 0;
  425. row_offset += he_dev->bytes_per_row;
  426. }
  427. lbm_offset += 2;
  428. }
  429. he_writel(he_dev, lbufd_index - 1, TLBF_T);
  430. }
  431. static int __init
  432. he_init_tpdrq(struct he_dev *he_dev)
  433. {
  434. he_dev->tpdrq_base = pci_alloc_consistent(he_dev->pci_dev,
  435. CONFIG_TPDRQ_SIZE * sizeof(struct he_tpdrq), &he_dev->tpdrq_phys);
  436. if (he_dev->tpdrq_base == NULL) {
  437. hprintk("failed to alloc tpdrq\n");
  438. return -ENOMEM;
  439. }
  440. memset(he_dev->tpdrq_base, 0,
  441. CONFIG_TPDRQ_SIZE * sizeof(struct he_tpdrq));
  442. he_dev->tpdrq_tail = he_dev->tpdrq_base;
  443. he_dev->tpdrq_head = he_dev->tpdrq_base;
  444. he_writel(he_dev, he_dev->tpdrq_phys, TPDRQ_B_H);
  445. he_writel(he_dev, 0, TPDRQ_T);
  446. he_writel(he_dev, CONFIG_TPDRQ_SIZE - 1, TPDRQ_S);
  447. return 0;
  448. }
  449. static void __init
  450. he_init_cs_block(struct he_dev *he_dev)
  451. {
  452. unsigned clock, rate, delta;
  453. int reg;
  454. /* 5.1.7 cs block initialization */
  455. for (reg = 0; reg < 0x20; ++reg)
  456. he_writel_mbox(he_dev, 0x0, CS_STTIM0 + reg);
  457. /* rate grid timer reload values */
  458. clock = he_is622(he_dev) ? 66667000 : 50000000;
  459. rate = he_dev->atm_dev->link_rate;
  460. delta = rate / 16 / 2;
  461. for (reg = 0; reg < 0x10; ++reg) {
  462. /* 2.4 internal transmit function
  463. *
  464. * we initialize the first row in the rate grid.
  465. * values are period (in clock cycles) of timer
  466. */
  467. unsigned period = clock / rate;
  468. he_writel_mbox(he_dev, period, CS_TGRLD0 + reg);
  469. rate -= delta;
  470. }
  471. if (he_is622(he_dev)) {
  472. /* table 5.2 (4 cells per lbuf) */
  473. he_writel_mbox(he_dev, 0x000800fa, CS_ERTHR0);
  474. he_writel_mbox(he_dev, 0x000c33cb, CS_ERTHR1);
  475. he_writel_mbox(he_dev, 0x0010101b, CS_ERTHR2);
  476. he_writel_mbox(he_dev, 0x00181dac, CS_ERTHR3);
  477. he_writel_mbox(he_dev, 0x00280600, CS_ERTHR4);
  478. /* table 5.3, 5.4, 5.5, 5.6, 5.7 */
  479. he_writel_mbox(he_dev, 0x023de8b3, CS_ERCTL0);
  480. he_writel_mbox(he_dev, 0x1801, CS_ERCTL1);
  481. he_writel_mbox(he_dev, 0x68b3, CS_ERCTL2);
  482. he_writel_mbox(he_dev, 0x1280, CS_ERSTAT0);
  483. he_writel_mbox(he_dev, 0x68b3, CS_ERSTAT1);
  484. he_writel_mbox(he_dev, 0x14585, CS_RTFWR);
  485. he_writel_mbox(he_dev, 0x4680, CS_RTATR);
  486. /* table 5.8 */
  487. he_writel_mbox(he_dev, 0x00159ece, CS_TFBSET);
  488. he_writel_mbox(he_dev, 0x68b3, CS_WCRMAX);
  489. he_writel_mbox(he_dev, 0x5eb3, CS_WCRMIN);
  490. he_writel_mbox(he_dev, 0xe8b3, CS_WCRINC);
  491. he_writel_mbox(he_dev, 0xdeb3, CS_WCRDEC);
  492. he_writel_mbox(he_dev, 0x68b3, CS_WCRCEIL);
  493. /* table 5.9 */
  494. he_writel_mbox(he_dev, 0x5, CS_OTPPER);
  495. he_writel_mbox(he_dev, 0x14, CS_OTWPER);
  496. } else {
  497. /* table 5.1 (4 cells per lbuf) */
  498. he_writel_mbox(he_dev, 0x000400ea, CS_ERTHR0);
  499. he_writel_mbox(he_dev, 0x00063388, CS_ERTHR1);
  500. he_writel_mbox(he_dev, 0x00081018, CS_ERTHR2);
  501. he_writel_mbox(he_dev, 0x000c1dac, CS_ERTHR3);
  502. he_writel_mbox(he_dev, 0x0014051a, CS_ERTHR4);
  503. /* table 5.3, 5.4, 5.5, 5.6, 5.7 */
  504. he_writel_mbox(he_dev, 0x0235e4b1, CS_ERCTL0);
  505. he_writel_mbox(he_dev, 0x4701, CS_ERCTL1);
  506. he_writel_mbox(he_dev, 0x64b1, CS_ERCTL2);
  507. he_writel_mbox(he_dev, 0x1280, CS_ERSTAT0);
  508. he_writel_mbox(he_dev, 0x64b1, CS_ERSTAT1);
  509. he_writel_mbox(he_dev, 0xf424, CS_RTFWR);
  510. he_writel_mbox(he_dev, 0x4680, CS_RTATR);
  511. /* table 5.8 */
  512. he_writel_mbox(he_dev, 0x000563b7, CS_TFBSET);
  513. he_writel_mbox(he_dev, 0x64b1, CS_WCRMAX);
  514. he_writel_mbox(he_dev, 0x5ab1, CS_WCRMIN);
  515. he_writel_mbox(he_dev, 0xe4b1, CS_WCRINC);
  516. he_writel_mbox(he_dev, 0xdab1, CS_WCRDEC);
  517. he_writel_mbox(he_dev, 0x64b1, CS_WCRCEIL);
  518. /* table 5.9 */
  519. he_writel_mbox(he_dev, 0x6, CS_OTPPER);
  520. he_writel_mbox(he_dev, 0x1e, CS_OTWPER);
  521. }
  522. he_writel_mbox(he_dev, 0x8, CS_OTTLIM);
  523. for (reg = 0; reg < 0x8; ++reg)
  524. he_writel_mbox(he_dev, 0x0, CS_HGRRT0 + reg);
  525. }
  526. static int __init
  527. he_init_cs_block_rcm(struct he_dev *he_dev)
  528. {
  529. unsigned (*rategrid)[16][16];
  530. unsigned rate, delta;
  531. int i, j, reg;
  532. unsigned rate_atmf, exp, man;
  533. unsigned long long rate_cps;
  534. int mult, buf, buf_limit = 4;
  535. rategrid = kmalloc( sizeof(unsigned) * 16 * 16, GFP_KERNEL);
  536. if (!rategrid)
  537. return -ENOMEM;
  538. /* initialize rate grid group table */
  539. for (reg = 0x0; reg < 0xff; ++reg)
  540. he_writel_rcm(he_dev, 0x0, CONFIG_RCMABR + reg);
  541. /* initialize rate controller groups */
  542. for (reg = 0x100; reg < 0x1ff; ++reg)
  543. he_writel_rcm(he_dev, 0x0, CONFIG_RCMABR + reg);
  544. /* initialize tNrm lookup table */
  545. /* the manual makes reference to a routine in a sample driver
  546. for proper configuration; fortunately, we only need this
  547. in order to support abr connection */
  548. /* initialize rate to group table */
  549. rate = he_dev->atm_dev->link_rate;
  550. delta = rate / 32;
  551. /*
  552. * 2.4 transmit internal functions
  553. *
  554. * we construct a copy of the rate grid used by the scheduler
  555. * in order to construct the rate to group table below
  556. */
  557. for (j = 0; j < 16; j++) {
  558. (*rategrid)[0][j] = rate;
  559. rate -= delta;
  560. }
  561. for (i = 1; i < 16; i++)
  562. for (j = 0; j < 16; j++)
  563. if (i > 14)
  564. (*rategrid)[i][j] = (*rategrid)[i - 1][j] / 4;
  565. else
  566. (*rategrid)[i][j] = (*rategrid)[i - 1][j] / 2;
  567. /*
  568. * 2.4 transmit internal function
  569. *
  570. * this table maps the upper 5 bits of exponent and mantissa
  571. * of the atm forum representation of the rate into an index
  572. * on rate grid
  573. */
  574. rate_atmf = 0;
  575. while (rate_atmf < 0x400) {
  576. man = (rate_atmf & 0x1f) << 4;
  577. exp = rate_atmf >> 5;
  578. /*
  579. instead of '/ 512', use '>> 9' to prevent a call
  580. to divdu3 on x86 platforms
  581. */
  582. rate_cps = (unsigned long long) (1 << exp) * (man + 512) >> 9;
  583. if (rate_cps < 10)
  584. rate_cps = 10; /* 2.2.1 minimum payload rate is 10 cps */
  585. for (i = 255; i > 0; i--)
  586. if ((*rategrid)[i/16][i%16] >= rate_cps)
  587. break; /* pick nearest rate instead? */
  588. /*
  589. * each table entry is 16 bits: (rate grid index (8 bits)
  590. * and a buffer limit (8 bits)
  591. * there are two table entries in each 32-bit register
  592. */
  593. #ifdef notdef
  594. buf = rate_cps * he_dev->tx_numbuffs /
  595. (he_dev->atm_dev->link_rate * 2);
  596. #else
  597. /* this is pretty, but avoids _divdu3 and is mostly correct */
  598. mult = he_dev->atm_dev->link_rate / ATM_OC3_PCR;
  599. if (rate_cps > (272 * mult))
  600. buf = 4;
  601. else if (rate_cps > (204 * mult))
  602. buf = 3;
  603. else if (rate_cps > (136 * mult))
  604. buf = 2;
  605. else if (rate_cps > (68 * mult))
  606. buf = 1;
  607. else
  608. buf = 0;
  609. #endif
  610. if (buf > buf_limit)
  611. buf = buf_limit;
  612. reg = (reg << 16) | ((i << 8) | buf);
  613. #define RTGTBL_OFFSET 0x400
  614. if (rate_atmf & 0x1)
  615. he_writel_rcm(he_dev, reg,
  616. CONFIG_RCMABR + RTGTBL_OFFSET + (rate_atmf >> 1));
  617. ++rate_atmf;
  618. }
  619. kfree(rategrid);
  620. return 0;
  621. }
  622. static int __init
  623. he_init_group(struct he_dev *he_dev, int group)
  624. {
  625. int i;
  626. #ifdef USE_RBPS
  627. /* small buffer pool */
  628. #ifdef USE_RBPS_POOL
  629. he_dev->rbps_pool = pci_pool_create("rbps", he_dev->pci_dev,
  630. CONFIG_RBPS_BUFSIZE, 8, 0);
  631. if (he_dev->rbps_pool == NULL) {
  632. hprintk("unable to create rbps pages\n");
  633. return -ENOMEM;
  634. }
  635. #else /* !USE_RBPS_POOL */
  636. he_dev->rbps_pages = pci_alloc_consistent(he_dev->pci_dev,
  637. CONFIG_RBPS_SIZE * CONFIG_RBPS_BUFSIZE, &he_dev->rbps_pages_phys);
  638. if (he_dev->rbps_pages == NULL) {
  639. hprintk("unable to create rbps page pool\n");
  640. return -ENOMEM;
  641. }
  642. #endif /* USE_RBPS_POOL */
  643. he_dev->rbps_base = pci_alloc_consistent(he_dev->pci_dev,
  644. CONFIG_RBPS_SIZE * sizeof(struct he_rbp), &he_dev->rbps_phys);
  645. if (he_dev->rbps_base == NULL) {
  646. hprintk("failed to alloc rbps\n");
  647. return -ENOMEM;
  648. }
  649. memset(he_dev->rbps_base, 0, CONFIG_RBPS_SIZE * sizeof(struct he_rbp));
  650. he_dev->rbps_virt = kmalloc(CONFIG_RBPS_SIZE * sizeof(struct he_virt), GFP_KERNEL);
  651. for (i = 0; i < CONFIG_RBPS_SIZE; ++i) {
  652. dma_addr_t dma_handle;
  653. void *cpuaddr;
  654. #ifdef USE_RBPS_POOL
  655. cpuaddr = pci_pool_alloc(he_dev->rbps_pool, SLAB_KERNEL|SLAB_DMA, &dma_handle);
  656. if (cpuaddr == NULL)
  657. return -ENOMEM;
  658. #else
  659. cpuaddr = he_dev->rbps_pages + (i * CONFIG_RBPS_BUFSIZE);
  660. dma_handle = he_dev->rbps_pages_phys + (i * CONFIG_RBPS_BUFSIZE);
  661. #endif
  662. he_dev->rbps_virt[i].virt = cpuaddr;
  663. he_dev->rbps_base[i].status = RBP_LOANED | RBP_SMALLBUF | (i << RBP_INDEX_OFF);
  664. he_dev->rbps_base[i].phys = dma_handle;
  665. }
  666. he_dev->rbps_tail = &he_dev->rbps_base[CONFIG_RBPS_SIZE - 1];
  667. he_writel(he_dev, he_dev->rbps_phys, G0_RBPS_S + (group * 32));
  668. he_writel(he_dev, RBPS_MASK(he_dev->rbps_tail),
  669. G0_RBPS_T + (group * 32));
  670. he_writel(he_dev, CONFIG_RBPS_BUFSIZE/4,
  671. G0_RBPS_BS + (group * 32));
  672. he_writel(he_dev,
  673. RBP_THRESH(CONFIG_RBPS_THRESH) |
  674. RBP_QSIZE(CONFIG_RBPS_SIZE - 1) |
  675. RBP_INT_ENB,
  676. G0_RBPS_QI + (group * 32));
  677. #else /* !USE_RBPS */
  678. he_writel(he_dev, 0x0, G0_RBPS_S + (group * 32));
  679. he_writel(he_dev, 0x0, G0_RBPS_T + (group * 32));
  680. he_writel(he_dev, 0x0, G0_RBPS_QI + (group * 32));
  681. he_writel(he_dev, RBP_THRESH(0x1) | RBP_QSIZE(0x0),
  682. G0_RBPS_BS + (group * 32));
  683. #endif /* USE_RBPS */
  684. /* large buffer pool */
  685. #ifdef USE_RBPL_POOL
  686. he_dev->rbpl_pool = pci_pool_create("rbpl", he_dev->pci_dev,
  687. CONFIG_RBPL_BUFSIZE, 8, 0);
  688. if (he_dev->rbpl_pool == NULL) {
  689. hprintk("unable to create rbpl pool\n");
  690. return -ENOMEM;
  691. }
  692. #else /* !USE_RBPL_POOL */
  693. he_dev->rbpl_pages = (void *) pci_alloc_consistent(he_dev->pci_dev,
  694. CONFIG_RBPL_SIZE * CONFIG_RBPL_BUFSIZE, &he_dev->rbpl_pages_phys);
  695. if (he_dev->rbpl_pages == NULL) {
  696. hprintk("unable to create rbpl pages\n");
  697. return -ENOMEM;
  698. }
  699. #endif /* USE_RBPL_POOL */
  700. he_dev->rbpl_base = pci_alloc_consistent(he_dev->pci_dev,
  701. CONFIG_RBPL_SIZE * sizeof(struct he_rbp), &he_dev->rbpl_phys);
  702. if (he_dev->rbpl_base == NULL) {
  703. hprintk("failed to alloc rbpl\n");
  704. return -ENOMEM;
  705. }
  706. memset(he_dev->rbpl_base, 0, CONFIG_RBPL_SIZE * sizeof(struct he_rbp));
  707. he_dev->rbpl_virt = kmalloc(CONFIG_RBPL_SIZE * sizeof(struct he_virt), GFP_KERNEL);
  708. for (i = 0; i < CONFIG_RBPL_SIZE; ++i) {
  709. dma_addr_t dma_handle;
  710. void *cpuaddr;
  711. #ifdef USE_RBPL_POOL
  712. cpuaddr = pci_pool_alloc(he_dev->rbpl_pool, SLAB_KERNEL|SLAB_DMA, &dma_handle);
  713. if (cpuaddr == NULL)
  714. return -ENOMEM;
  715. #else
  716. cpuaddr = he_dev->rbpl_pages + (i * CONFIG_RBPL_BUFSIZE);
  717. dma_handle = he_dev->rbpl_pages_phys + (i * CONFIG_RBPL_BUFSIZE);
  718. #endif
  719. he_dev->rbpl_virt[i].virt = cpuaddr;
  720. he_dev->rbpl_base[i].status = RBP_LOANED | (i << RBP_INDEX_OFF);
  721. he_dev->rbpl_base[i].phys = dma_handle;
  722. }
  723. he_dev->rbpl_tail = &he_dev->rbpl_base[CONFIG_RBPL_SIZE - 1];
  724. he_writel(he_dev, he_dev->rbpl_phys, G0_RBPL_S + (group * 32));
  725. he_writel(he_dev, RBPL_MASK(he_dev->rbpl_tail),
  726. G0_RBPL_T + (group * 32));
  727. he_writel(he_dev, CONFIG_RBPL_BUFSIZE/4,
  728. G0_RBPL_BS + (group * 32));
  729. he_writel(he_dev,
  730. RBP_THRESH(CONFIG_RBPL_THRESH) |
  731. RBP_QSIZE(CONFIG_RBPL_SIZE - 1) |
  732. RBP_INT_ENB,
  733. G0_RBPL_QI + (group * 32));
  734. /* rx buffer ready queue */
  735. he_dev->rbrq_base = pci_alloc_consistent(he_dev->pci_dev,
  736. CONFIG_RBRQ_SIZE * sizeof(struct he_rbrq), &he_dev->rbrq_phys);
  737. if (he_dev->rbrq_base == NULL) {
  738. hprintk("failed to allocate rbrq\n");
  739. return -ENOMEM;
  740. }
  741. memset(he_dev->rbrq_base, 0, CONFIG_RBRQ_SIZE * sizeof(struct he_rbrq));
  742. he_dev->rbrq_head = he_dev->rbrq_base;
  743. he_writel(he_dev, he_dev->rbrq_phys, G0_RBRQ_ST + (group * 16));
  744. he_writel(he_dev, 0, G0_RBRQ_H + (group * 16));
  745. he_writel(he_dev,
  746. RBRQ_THRESH(CONFIG_RBRQ_THRESH) | RBRQ_SIZE(CONFIG_RBRQ_SIZE - 1),
  747. G0_RBRQ_Q + (group * 16));
  748. if (irq_coalesce) {
  749. hprintk("coalescing interrupts\n");
  750. he_writel(he_dev, RBRQ_TIME(768) | RBRQ_COUNT(7),
  751. G0_RBRQ_I + (group * 16));
  752. } else
  753. he_writel(he_dev, RBRQ_TIME(0) | RBRQ_COUNT(1),
  754. G0_RBRQ_I + (group * 16));
  755. /* tx buffer ready queue */
  756. he_dev->tbrq_base = pci_alloc_consistent(he_dev->pci_dev,
  757. CONFIG_TBRQ_SIZE * sizeof(struct he_tbrq), &he_dev->tbrq_phys);
  758. if (he_dev->tbrq_base == NULL) {
  759. hprintk("failed to allocate tbrq\n");
  760. return -ENOMEM;
  761. }
  762. memset(he_dev->tbrq_base, 0, CONFIG_TBRQ_SIZE * sizeof(struct he_tbrq));
  763. he_dev->tbrq_head = he_dev->tbrq_base;
  764. he_writel(he_dev, he_dev->tbrq_phys, G0_TBRQ_B_T + (group * 16));
  765. he_writel(he_dev, 0, G0_TBRQ_H + (group * 16));
  766. he_writel(he_dev, CONFIG_TBRQ_SIZE - 1, G0_TBRQ_S + (group * 16));
  767. he_writel(he_dev, CONFIG_TBRQ_THRESH, G0_TBRQ_THRESH + (group * 16));
  768. return 0;
  769. }
  770. static int __init
  771. he_init_irq(struct he_dev *he_dev)
  772. {
  773. int i;
  774. /* 2.9.3.5 tail offset for each interrupt queue is located after the
  775. end of the interrupt queue */
  776. he_dev->irq_base = pci_alloc_consistent(he_dev->pci_dev,
  777. (CONFIG_IRQ_SIZE+1) * sizeof(struct he_irq), &he_dev->irq_phys);
  778. if (he_dev->irq_base == NULL) {
  779. hprintk("failed to allocate irq\n");
  780. return -ENOMEM;
  781. }
  782. he_dev->irq_tailoffset = (unsigned *)
  783. &he_dev->irq_base[CONFIG_IRQ_SIZE];
  784. *he_dev->irq_tailoffset = 0;
  785. he_dev->irq_head = he_dev->irq_base;
  786. he_dev->irq_tail = he_dev->irq_base;
  787. for (i = 0; i < CONFIG_IRQ_SIZE; ++i)
  788. he_dev->irq_base[i].isw = ITYPE_INVALID;
  789. he_writel(he_dev, he_dev->irq_phys, IRQ0_BASE);
  790. he_writel(he_dev,
  791. IRQ_SIZE(CONFIG_IRQ_SIZE) | IRQ_THRESH(CONFIG_IRQ_THRESH),
  792. IRQ0_HEAD);
  793. he_writel(he_dev, IRQ_INT_A | IRQ_TYPE_LINE, IRQ0_CNTL);
  794. he_writel(he_dev, 0x0, IRQ0_DATA);
  795. he_writel(he_dev, 0x0, IRQ1_BASE);
  796. he_writel(he_dev, 0x0, IRQ1_HEAD);
  797. he_writel(he_dev, 0x0, IRQ1_CNTL);
  798. he_writel(he_dev, 0x0, IRQ1_DATA);
  799. he_writel(he_dev, 0x0, IRQ2_BASE);
  800. he_writel(he_dev, 0x0, IRQ2_HEAD);
  801. he_writel(he_dev, 0x0, IRQ2_CNTL);
  802. he_writel(he_dev, 0x0, IRQ2_DATA);
  803. he_writel(he_dev, 0x0, IRQ3_BASE);
  804. he_writel(he_dev, 0x0, IRQ3_HEAD);
  805. he_writel(he_dev, 0x0, IRQ3_CNTL);
  806. he_writel(he_dev, 0x0, IRQ3_DATA);
  807. /* 2.9.3.2 interrupt queue mapping registers */
  808. he_writel(he_dev, 0x0, GRP_10_MAP);
  809. he_writel(he_dev, 0x0, GRP_32_MAP);
  810. he_writel(he_dev, 0x0, GRP_54_MAP);
  811. he_writel(he_dev, 0x0, GRP_76_MAP);
  812. if (request_irq(he_dev->pci_dev->irq, he_irq_handler, SA_INTERRUPT|SA_SHIRQ, DEV_LABEL, he_dev)) {
  813. hprintk("irq %d already in use\n", he_dev->pci_dev->irq);
  814. return -EINVAL;
  815. }
  816. he_dev->irq = he_dev->pci_dev->irq;
  817. return 0;
  818. }
  819. static int __init
  820. he_start(struct atm_dev *dev)
  821. {
  822. struct he_dev *he_dev;
  823. struct pci_dev *pci_dev;
  824. unsigned long membase;
  825. u16 command;
  826. u32 gen_cntl_0, host_cntl, lb_swap;
  827. u8 cache_size, timer;
  828. unsigned err;
  829. unsigned int status, reg;
  830. int i, group;
  831. he_dev = HE_DEV(dev);
  832. pci_dev = he_dev->pci_dev;
  833. membase = pci_resource_start(pci_dev, 0);
  834. HPRINTK("membase = 0x%lx irq = %d.\n", membase, pci_dev->irq);
  835. /*
  836. * pci bus controller initialization
  837. */
  838. /* 4.3 pci bus controller-specific initialization */
  839. if (pci_read_config_dword(pci_dev, GEN_CNTL_0, &gen_cntl_0) != 0) {
  840. hprintk("can't read GEN_CNTL_0\n");
  841. return -EINVAL;
  842. }
  843. gen_cntl_0 |= (MRL_ENB | MRM_ENB | IGNORE_TIMEOUT);
  844. if (pci_write_config_dword(pci_dev, GEN_CNTL_0, gen_cntl_0) != 0) {
  845. hprintk("can't write GEN_CNTL_0.\n");
  846. return -EINVAL;
  847. }
  848. if (pci_read_config_word(pci_dev, PCI_COMMAND, &command) != 0) {
  849. hprintk("can't read PCI_COMMAND.\n");
  850. return -EINVAL;
  851. }
  852. command |= (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE);
  853. if (pci_write_config_word(pci_dev, PCI_COMMAND, command) != 0) {
  854. hprintk("can't enable memory.\n");
  855. return -EINVAL;
  856. }
  857. if (pci_read_config_byte(pci_dev, PCI_CACHE_LINE_SIZE, &cache_size)) {
  858. hprintk("can't read cache line size?\n");
  859. return -EINVAL;
  860. }
  861. if (cache_size < 16) {
  862. cache_size = 16;
  863. if (pci_write_config_byte(pci_dev, PCI_CACHE_LINE_SIZE, cache_size))
  864. hprintk("can't set cache line size to %d\n", cache_size);
  865. }
  866. if (pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &timer)) {
  867. hprintk("can't read latency timer?\n");
  868. return -EINVAL;
  869. }
  870. /* from table 3.9
  871. *
  872. * LAT_TIMER = 1 + AVG_LAT + BURST_SIZE/BUS_SIZE
  873. *
  874. * AVG_LAT: The average first data read/write latency [maximum 16 clock cycles]
  875. * BURST_SIZE: 1536 bytes (read) for 622, 768 bytes (read) for 155 [192 clock cycles]
  876. *
  877. */
  878. #define LAT_TIMER 209
  879. if (timer < LAT_TIMER) {
  880. HPRINTK("latency timer was %d, setting to %d\n", timer, LAT_TIMER);
  881. timer = LAT_TIMER;
  882. if (pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, timer))
  883. hprintk("can't set latency timer to %d\n", timer);
  884. }
  885. if (!(he_dev->membase = ioremap(membase, HE_REGMAP_SIZE))) {
  886. hprintk("can't set up page mapping\n");
  887. return -EINVAL;
  888. }
  889. /* 4.4 card reset */
  890. he_writel(he_dev, 0x0, RESET_CNTL);
  891. he_writel(he_dev, 0xff, RESET_CNTL);
  892. udelay(16*1000); /* 16 ms */
  893. status = he_readl(he_dev, RESET_CNTL);
  894. if ((status & BOARD_RST_STATUS) == 0) {
  895. hprintk("reset failed\n");
  896. return -EINVAL;
  897. }
  898. /* 4.5 set bus width */
  899. host_cntl = he_readl(he_dev, HOST_CNTL);
  900. if (host_cntl & PCI_BUS_SIZE64)
  901. gen_cntl_0 |= ENBL_64;
  902. else
  903. gen_cntl_0 &= ~ENBL_64;
  904. if (disable64 == 1) {
  905. hprintk("disabling 64-bit pci bus transfers\n");
  906. gen_cntl_0 &= ~ENBL_64;
  907. }
  908. if (gen_cntl_0 & ENBL_64)
  909. hprintk("64-bit transfers enabled\n");
  910. pci_write_config_dword(pci_dev, GEN_CNTL_0, gen_cntl_0);
  911. /* 4.7 read prom contents */
  912. for (i = 0; i < PROD_ID_LEN; ++i)
  913. he_dev->prod_id[i] = read_prom_byte(he_dev, PROD_ID + i);
  914. he_dev->media = read_prom_byte(he_dev, MEDIA);
  915. for (i = 0; i < 6; ++i)
  916. dev->esi[i] = read_prom_byte(he_dev, MAC_ADDR + i);
  917. hprintk("%s%s, %x:%x:%x:%x:%x:%x\n",
  918. he_dev->prod_id,
  919. he_dev->media & 0x40 ? "SM" : "MM",
  920. dev->esi[0],
  921. dev->esi[1],
  922. dev->esi[2],
  923. dev->esi[3],
  924. dev->esi[4],
  925. dev->esi[5]);
  926. he_dev->atm_dev->link_rate = he_is622(he_dev) ?
  927. ATM_OC12_PCR : ATM_OC3_PCR;
  928. /* 4.6 set host endianess */
  929. lb_swap = he_readl(he_dev, LB_SWAP);
  930. if (he_is622(he_dev))
  931. lb_swap &= ~XFER_SIZE; /* 4 cells */
  932. else
  933. lb_swap |= XFER_SIZE; /* 8 cells */
  934. #ifdef __BIG_ENDIAN
  935. lb_swap |= DESC_WR_SWAP | INTR_SWAP | BIG_ENDIAN_HOST;
  936. #else
  937. lb_swap &= ~(DESC_WR_SWAP | INTR_SWAP | BIG_ENDIAN_HOST |
  938. DATA_WR_SWAP | DATA_RD_SWAP | DESC_RD_SWAP);
  939. #endif /* __BIG_ENDIAN */
  940. he_writel(he_dev, lb_swap, LB_SWAP);
  941. /* 4.8 sdram controller initialization */
  942. he_writel(he_dev, he_is622(he_dev) ? LB_64_ENB : 0x0, SDRAM_CTL);
  943. /* 4.9 initialize rnum value */
  944. lb_swap |= SWAP_RNUM_MAX(0xf);
  945. he_writel(he_dev, lb_swap, LB_SWAP);
  946. /* 4.10 initialize the interrupt queues */
  947. if ((err = he_init_irq(he_dev)) != 0)
  948. return err;
  949. #ifdef USE_TASKLET
  950. tasklet_init(&he_dev->tasklet, he_tasklet, (unsigned long) he_dev);
  951. #endif
  952. spin_lock_init(&he_dev->global_lock);
  953. /* 4.11 enable pci bus controller state machines */
  954. host_cntl |= (OUTFF_ENB | CMDFF_ENB |
  955. QUICK_RD_RETRY | QUICK_WR_RETRY | PERR_INT_ENB);
  956. he_writel(he_dev, host_cntl, HOST_CNTL);
  957. gen_cntl_0 |= INT_PROC_ENBL|INIT_ENB;
  958. pci_write_config_dword(pci_dev, GEN_CNTL_0, gen_cntl_0);
  959. /*
  960. * atm network controller initialization
  961. */
  962. /* 5.1.1 generic configuration state */
  963. /*
  964. * local (cell) buffer memory map
  965. *
  966. * HE155 HE622
  967. *
  968. * 0 ____________1023 bytes 0 _______________________2047 bytes
  969. * | | | | |
  970. * | utility | | rx0 | |
  971. * 5|____________| 255|___________________| u |
  972. * 6| | 256| | t |
  973. * | | | | i |
  974. * | rx0 | row | tx | l |
  975. * | | | | i |
  976. * | | 767|___________________| t |
  977. * 517|____________| 768| | y |
  978. * row 518| | | rx1 | |
  979. * | | 1023|___________________|___|
  980. * | |
  981. * | tx |
  982. * | |
  983. * | |
  984. * 1535|____________|
  985. * 1536| |
  986. * | rx1 |
  987. * 2047|____________|
  988. *
  989. */
  990. /* total 4096 connections */
  991. he_dev->vcibits = CONFIG_DEFAULT_VCIBITS;
  992. he_dev->vpibits = CONFIG_DEFAULT_VPIBITS;
  993. if (nvpibits != -1 && nvcibits != -1 && nvpibits+nvcibits != HE_MAXCIDBITS) {
  994. hprintk("nvpibits + nvcibits != %d\n", HE_MAXCIDBITS);
  995. return -ENODEV;
  996. }
  997. if (nvpibits != -1) {
  998. he_dev->vpibits = nvpibits;
  999. he_dev->vcibits = HE_MAXCIDBITS - nvpibits;
  1000. }
  1001. if (nvcibits != -1) {
  1002. he_dev->vcibits = nvcibits;
  1003. he_dev->vpibits = HE_MAXCIDBITS - nvcibits;
  1004. }
  1005. if (he_is622(he_dev)) {
  1006. he_dev->cells_per_row = 40;
  1007. he_dev->bytes_per_row = 2048;
  1008. he_dev->r0_numrows = 256;
  1009. he_dev->tx_numrows = 512;
  1010. he_dev->r1_numrows = 256;
  1011. he_dev->r0_startrow = 0;
  1012. he_dev->tx_startrow = 256;
  1013. he_dev->r1_startrow = 768;
  1014. } else {
  1015. he_dev->cells_per_row = 20;
  1016. he_dev->bytes_per_row = 1024;
  1017. he_dev->r0_numrows = 512;
  1018. he_dev->tx_numrows = 1018;
  1019. he_dev->r1_numrows = 512;
  1020. he_dev->r0_startrow = 6;
  1021. he_dev->tx_startrow = 518;
  1022. he_dev->r1_startrow = 1536;
  1023. }
  1024. he_dev->cells_per_lbuf = 4;
  1025. he_dev->buffer_limit = 4;
  1026. he_dev->r0_numbuffs = he_dev->r0_numrows *
  1027. he_dev->cells_per_row / he_dev->cells_per_lbuf;
  1028. if (he_dev->r0_numbuffs > 2560)
  1029. he_dev->r0_numbuffs = 2560;
  1030. he_dev->r1_numbuffs = he_dev->r1_numrows *
  1031. he_dev->cells_per_row / he_dev->cells_per_lbuf;
  1032. if (he_dev->r1_numbuffs > 2560)
  1033. he_dev->r1_numbuffs = 2560;
  1034. he_dev->tx_numbuffs = he_dev->tx_numrows *
  1035. he_dev->cells_per_row / he_dev->cells_per_lbuf;
  1036. if (he_dev->tx_numbuffs > 5120)
  1037. he_dev->tx_numbuffs = 5120;
  1038. /* 5.1.2 configure hardware dependent registers */
  1039. he_writel(he_dev,
  1040. SLICE_X(0x2) | ARB_RNUM_MAX(0xf) | TH_PRTY(0x3) |
  1041. RH_PRTY(0x3) | TL_PRTY(0x2) | RL_PRTY(0x1) |
  1042. (he_is622(he_dev) ? BUS_MULTI(0x28) : BUS_MULTI(0x46)) |
  1043. (he_is622(he_dev) ? NET_PREF(0x50) : NET_PREF(0x8c)),
  1044. LBARB);
  1045. he_writel(he_dev, BANK_ON |
  1046. (he_is622(he_dev) ? (REF_RATE(0x384) | WIDE_DATA) : REF_RATE(0x150)),
  1047. SDRAMCON);
  1048. he_writel(he_dev,
  1049. (he_is622(he_dev) ? RM_BANK_WAIT(1) : RM_BANK_WAIT(0)) |
  1050. RM_RW_WAIT(1), RCMCONFIG);
  1051. he_writel(he_dev,
  1052. (he_is622(he_dev) ? TM_BANK_WAIT(2) : TM_BANK_WAIT(1)) |
  1053. TM_RW_WAIT(1), TCMCONFIG);
  1054. he_writel(he_dev, he_dev->cells_per_lbuf * ATM_CELL_PAYLOAD, LB_CONFIG);
  1055. he_writel(he_dev,
  1056. (he_is622(he_dev) ? UT_RD_DELAY(8) : UT_RD_DELAY(0)) |
  1057. (he_is622(he_dev) ? RC_UT_MODE(0) : RC_UT_MODE(1)) |
  1058. RX_VALVP(he_dev->vpibits) |
  1059. RX_VALVC(he_dev->vcibits), RC_CONFIG);
  1060. he_writel(he_dev, DRF_THRESH(0x20) |
  1061. (he_is622(he_dev) ? TX_UT_MODE(0) : TX_UT_MODE(1)) |
  1062. TX_VCI_MASK(he_dev->vcibits) |
  1063. LBFREE_CNT(he_dev->tx_numbuffs), TX_CONFIG);
  1064. he_writel(he_dev, 0x0, TXAAL5_PROTO);
  1065. he_writel(he_dev, PHY_INT_ENB |
  1066. (he_is622(he_dev) ? PTMR_PRE(67 - 1) : PTMR_PRE(50 - 1)),
  1067. RH_CONFIG);
  1068. /* 5.1.3 initialize connection memory */
  1069. for (i = 0; i < TCM_MEM_SIZE; ++i)
  1070. he_writel_tcm(he_dev, 0, i);
  1071. for (i = 0; i < RCM_MEM_SIZE; ++i)
  1072. he_writel_rcm(he_dev, 0, i);
  1073. /*
  1074. * transmit connection memory map
  1075. *
  1076. * tx memory
  1077. * 0x0 ___________________
  1078. * | |
  1079. * | |
  1080. * | TSRa |
  1081. * | |
  1082. * | |
  1083. * 0x8000|___________________|
  1084. * | |
  1085. * | TSRb |
  1086. * 0xc000|___________________|
  1087. * | |
  1088. * | TSRc |
  1089. * 0xe000|___________________|
  1090. * | TSRd |
  1091. * 0xf000|___________________|
  1092. * | tmABR |
  1093. * 0x10000|___________________|
  1094. * | |
  1095. * | tmTPD |
  1096. * |___________________|
  1097. * | |
  1098. * ....
  1099. * 0x1ffff|___________________|
  1100. *
  1101. *
  1102. */
  1103. he_writel(he_dev, CONFIG_TSRB, TSRB_BA);
  1104. he_writel(he_dev, CONFIG_TSRC, TSRC_BA);
  1105. he_writel(he_dev, CONFIG_TSRD, TSRD_BA);
  1106. he_writel(he_dev, CONFIG_TMABR, TMABR_BA);
  1107. he_writel(he_dev, CONFIG_TPDBA, TPD_BA);
  1108. /*
  1109. * receive connection memory map
  1110. *
  1111. * 0x0 ___________________
  1112. * | |
  1113. * | |
  1114. * | RSRa |
  1115. * | |
  1116. * | |
  1117. * 0x8000|___________________|
  1118. * | |
  1119. * | rx0/1 |
  1120. * | LBM | link lists of local
  1121. * | tx | buffer memory
  1122. * | |
  1123. * 0xd000|___________________|
  1124. * | |
  1125. * | rmABR |
  1126. * 0xe000|___________________|
  1127. * | |
  1128. * | RSRb |
  1129. * |___________________|
  1130. * | |
  1131. * ....
  1132. * 0xffff|___________________|
  1133. */
  1134. he_writel(he_dev, 0x08000, RCMLBM_BA);
  1135. he_writel(he_dev, 0x0e000, RCMRSRB_BA);
  1136. he_writel(he_dev, 0x0d800, RCMABR_BA);
  1137. /* 5.1.4 initialize local buffer free pools linked lists */
  1138. he_init_rx_lbfp0(he_dev);
  1139. he_init_rx_lbfp1(he_dev);
  1140. he_writel(he_dev, 0x0, RLBC_H);
  1141. he_writel(he_dev, 0x0, RLBC_T);
  1142. he_writel(he_dev, 0x0, RLBC_H2);
  1143. he_writel(he_dev, 512, RXTHRSH); /* 10% of r0+r1 buffers */
  1144. he_writel(he_dev, 256, LITHRSH); /* 5% of r0+r1 buffers */
  1145. he_init_tx_lbfp(he_dev);
  1146. he_writel(he_dev, he_is622(he_dev) ? 0x104780 : 0x800, UBUFF_BA);
  1147. /* 5.1.5 initialize intermediate receive queues */
  1148. if (he_is622(he_dev)) {
  1149. he_writel(he_dev, 0x000f, G0_INMQ_S);
  1150. he_writel(he_dev, 0x200f, G0_INMQ_L);
  1151. he_writel(he_dev, 0x001f, G1_INMQ_S);
  1152. he_writel(he_dev, 0x201f, G1_INMQ_L);
  1153. he_writel(he_dev, 0x002f, G2_INMQ_S);
  1154. he_writel(he_dev, 0x202f, G2_INMQ_L);
  1155. he_writel(he_dev, 0x003f, G3_INMQ_S);
  1156. he_writel(he_dev, 0x203f, G3_INMQ_L);
  1157. he_writel(he_dev, 0x004f, G4_INMQ_S);
  1158. he_writel(he_dev, 0x204f, G4_INMQ_L);
  1159. he_writel(he_dev, 0x005f, G5_INMQ_S);
  1160. he_writel(he_dev, 0x205f, G5_INMQ_L);
  1161. he_writel(he_dev, 0x006f, G6_INMQ_S);
  1162. he_writel(he_dev, 0x206f, G6_INMQ_L);
  1163. he_writel(he_dev, 0x007f, G7_INMQ_S);
  1164. he_writel(he_dev, 0x207f, G7_INMQ_L);
  1165. } else {
  1166. he_writel(he_dev, 0x0000, G0_INMQ_S);
  1167. he_writel(he_dev, 0x0008, G0_INMQ_L);
  1168. he_writel(he_dev, 0x0001, G1_INMQ_S);
  1169. he_writel(he_dev, 0x0009, G1_INMQ_L);
  1170. he_writel(he_dev, 0x0002, G2_INMQ_S);
  1171. he_writel(he_dev, 0x000a, G2_INMQ_L);
  1172. he_writel(he_dev, 0x0003, G3_INMQ_S);
  1173. he_writel(he_dev, 0x000b, G3_INMQ_L);
  1174. he_writel(he_dev, 0x0004, G4_INMQ_S);
  1175. he_writel(he_dev, 0x000c, G4_INMQ_L);
  1176. he_writel(he_dev, 0x0005, G5_INMQ_S);
  1177. he_writel(he_dev, 0x000d, G5_INMQ_L);
  1178. he_writel(he_dev, 0x0006, G6_INMQ_S);
  1179. he_writel(he_dev, 0x000e, G6_INMQ_L);
  1180. he_writel(he_dev, 0x0007, G7_INMQ_S);
  1181. he_writel(he_dev, 0x000f, G7_INMQ_L);
  1182. }
  1183. /* 5.1.6 application tunable parameters */
  1184. he_writel(he_dev, 0x0, MCC);
  1185. he_writel(he_dev, 0x0, OEC);
  1186. he_writel(he_dev, 0x0, DCC);
  1187. he_writel(he_dev, 0x0, CEC);
  1188. /* 5.1.7 cs block initialization */
  1189. he_init_cs_block(he_dev);
  1190. /* 5.1.8 cs block connection memory initialization */
  1191. if (he_init_cs_block_rcm(he_dev) < 0)
  1192. return -ENOMEM;
  1193. /* 5.1.10 initialize host structures */
  1194. he_init_tpdrq(he_dev);
  1195. #ifdef USE_TPD_POOL
  1196. he_dev->tpd_pool = pci_pool_create("tpd", he_dev->pci_dev,
  1197. sizeof(struct he_tpd), TPD_ALIGNMENT, 0);
  1198. if (he_dev->tpd_pool == NULL) {
  1199. hprintk("unable to create tpd pci_pool\n");
  1200. return -ENOMEM;
  1201. }
  1202. INIT_LIST_HEAD(&he_dev->outstanding_tpds);
  1203. #else
  1204. he_dev->tpd_base = (void *) pci_alloc_consistent(he_dev->pci_dev,
  1205. CONFIG_NUMTPDS * sizeof(struct he_tpd), &he_dev->tpd_base_phys);
  1206. if (!he_dev->tpd_base)
  1207. return -ENOMEM;
  1208. for (i = 0; i < CONFIG_NUMTPDS; ++i) {
  1209. he_dev->tpd_base[i].status = (i << TPD_ADDR_SHIFT);
  1210. he_dev->tpd_base[i].inuse = 0;
  1211. }
  1212. he_dev->tpd_head = he_dev->tpd_base;
  1213. he_dev->tpd_end = &he_dev->tpd_base[CONFIG_NUMTPDS - 1];
  1214. #endif
  1215. if (he_init_group(he_dev, 0) != 0)
  1216. return -ENOMEM;
  1217. for (group = 1; group < HE_NUM_GROUPS; ++group) {
  1218. he_writel(he_dev, 0x0, G0_RBPS_S + (group * 32));
  1219. he_writel(he_dev, 0x0, G0_RBPS_T + (group * 32));
  1220. he_writel(he_dev, 0x0, G0_RBPS_QI + (group * 32));
  1221. he_writel(he_dev, RBP_THRESH(0x1) | RBP_QSIZE(0x0),
  1222. G0_RBPS_BS + (group * 32));
  1223. he_writel(he_dev, 0x0, G0_RBPL_S + (group * 32));
  1224. he_writel(he_dev, 0x0, G0_RBPL_T + (group * 32));
  1225. he_writel(he_dev, RBP_THRESH(0x1) | RBP_QSIZE(0x0),
  1226. G0_RBPL_QI + (group * 32));
  1227. he_writel(he_dev, 0x0, G0_RBPL_BS + (group * 32));
  1228. he_writel(he_dev, 0x0, G0_RBRQ_ST + (group * 16));
  1229. he_writel(he_dev, 0x0, G0_RBRQ_H + (group * 16));
  1230. he_writel(he_dev, RBRQ_THRESH(0x1) | RBRQ_SIZE(0x0),
  1231. G0_RBRQ_Q + (group * 16));
  1232. he_writel(he_dev, 0x0, G0_RBRQ_I + (group * 16));
  1233. he_writel(he_dev, 0x0, G0_TBRQ_B_T + (group * 16));
  1234. he_writel(he_dev, 0x0, G0_TBRQ_H + (group * 16));
  1235. he_writel(he_dev, TBRQ_THRESH(0x1),
  1236. G0_TBRQ_THRESH + (group * 16));
  1237. he_writel(he_dev, 0x0, G0_TBRQ_S + (group * 16));
  1238. }
  1239. /* host status page */
  1240. he_dev->hsp = pci_alloc_consistent(he_dev->pci_dev,
  1241. sizeof(struct he_hsp), &he_dev->hsp_phys);
  1242. if (he_dev->hsp == NULL) {
  1243. hprintk("failed to allocate host status page\n");
  1244. return -ENOMEM;
  1245. }
  1246. memset(he_dev->hsp, 0, sizeof(struct he_hsp));
  1247. he_writel(he_dev, he_dev->hsp_phys, HSP_BA);
  1248. /* initialize framer */
  1249. #ifdef CONFIG_ATM_HE_USE_SUNI
  1250. suni_init(he_dev->atm_dev);
  1251. if (he_dev->atm_dev->phy && he_dev->atm_dev->phy->start)
  1252. he_dev->atm_dev->phy->start(he_dev->atm_dev);
  1253. #endif /* CONFIG_ATM_HE_USE_SUNI */
  1254. if (sdh) {
  1255. /* this really should be in suni.c but for now... */
  1256. int val;
  1257. val = he_phy_get(he_dev->atm_dev, SUNI_TPOP_APM);
  1258. val = (val & ~SUNI_TPOP_APM_S) | (SUNI_TPOP_S_SDH << SUNI_TPOP_APM_S_SHIFT);
  1259. he_phy_put(he_dev->atm_dev, val, SUNI_TPOP_APM);
  1260. }
  1261. /* 5.1.12 enable transmit and receive */
  1262. reg = he_readl_mbox(he_dev, CS_ERCTL0);
  1263. reg |= TX_ENABLE|ER_ENABLE;
  1264. he_writel_mbox(he_dev, reg, CS_ERCTL0);
  1265. reg = he_readl(he_dev, RC_CONFIG);
  1266. reg |= RX_ENABLE;
  1267. he_writel(he_dev, reg, RC_CONFIG);
  1268. for (i = 0; i < HE_NUM_CS_STPER; ++i) {
  1269. he_dev->cs_stper[i].inuse = 0;
  1270. he_dev->cs_stper[i].pcr = -1;
  1271. }
  1272. he_dev->total_bw = 0;
  1273. /* atm linux initialization */
  1274. he_dev->atm_dev->ci_range.vpi_bits = he_dev->vpibits;
  1275. he_dev->atm_dev->ci_range.vci_bits = he_dev->vcibits;
  1276. he_dev->irq_peak = 0;
  1277. he_dev->rbrq_peak = 0;
  1278. he_dev->rbpl_peak = 0;
  1279. he_dev->tbrq_peak = 0;
  1280. HPRINTK("hell bent for leather!\n");
  1281. return 0;
  1282. }
  1283. static void
  1284. he_stop(struct he_dev *he_dev)
  1285. {
  1286. u16 command;
  1287. u32 gen_cntl_0, reg;
  1288. struct pci_dev *pci_dev;
  1289. pci_dev = he_dev->pci_dev;
  1290. /* disable interrupts */
  1291. if (he_dev->membase) {
  1292. pci_read_config_dword(pci_dev, GEN_CNTL_0, &gen_cntl_0);
  1293. gen_cntl_0 &= ~(INT_PROC_ENBL | INIT_ENB);
  1294. pci_write_config_dword(pci_dev, GEN_CNTL_0, gen_cntl_0);
  1295. #ifdef USE_TASKLET
  1296. tasklet_disable(&he_dev->tasklet);
  1297. #endif
  1298. /* disable recv and transmit */
  1299. reg = he_readl_mbox(he_dev, CS_ERCTL0);
  1300. reg &= ~(TX_ENABLE|ER_ENABLE);
  1301. he_writel_mbox(he_dev, reg, CS_ERCTL0);
  1302. reg = he_readl(he_dev, RC_CONFIG);
  1303. reg &= ~(RX_ENABLE);
  1304. he_writel(he_dev, reg, RC_CONFIG);
  1305. }
  1306. #ifdef CONFIG_ATM_HE_USE_SUNI
  1307. if (he_dev->atm_dev->phy && he_dev->atm_dev->phy->stop)
  1308. he_dev->atm_dev->phy->stop(he_dev->atm_dev);
  1309. #endif /* CONFIG_ATM_HE_USE_SUNI */
  1310. if (he_dev->irq)
  1311. free_irq(he_dev->irq, he_dev);
  1312. if (he_dev->irq_base)
  1313. pci_free_consistent(he_dev->pci_dev, (CONFIG_IRQ_SIZE+1)
  1314. * sizeof(struct he_irq), he_dev->irq_base, he_dev->irq_phys);
  1315. if (he_dev->hsp)
  1316. pci_free_consistent(he_dev->pci_dev, sizeof(struct he_hsp),
  1317. he_dev->hsp, he_dev->hsp_phys);
  1318. if (he_dev->rbpl_base) {
  1319. #ifdef USE_RBPL_POOL
  1320. for (i = 0; i < CONFIG_RBPL_SIZE; ++i) {
  1321. void *cpuaddr = he_dev->rbpl_virt[i].virt;
  1322. dma_addr_t dma_handle = he_dev->rbpl_base[i].phys;
  1323. pci_pool_free(he_dev->rbpl_pool, cpuaddr, dma_handle);
  1324. }
  1325. #else
  1326. pci_free_consistent(he_dev->pci_dev, CONFIG_RBPL_SIZE
  1327. * CONFIG_RBPL_BUFSIZE, he_dev->rbpl_pages, he_dev->rbpl_pages_phys);
  1328. #endif
  1329. pci_free_consistent(he_dev->pci_dev, CONFIG_RBPL_SIZE
  1330. * sizeof(struct he_rbp), he_dev->rbpl_base, he_dev->rbpl_phys);
  1331. }
  1332. #ifdef USE_RBPL_POOL
  1333. if (he_dev->rbpl_pool)
  1334. pci_pool_destroy(he_dev->rbpl_pool);
  1335. #endif
  1336. #ifdef USE_RBPS
  1337. if (he_dev->rbps_base) {
  1338. #ifdef USE_RBPS_POOL
  1339. for (i = 0; i < CONFIG_RBPS_SIZE; ++i) {
  1340. void *cpuaddr = he_dev->rbps_virt[i].virt;
  1341. dma_addr_t dma_handle = he_dev->rbps_base[i].phys;
  1342. pci_pool_free(he_dev->rbps_pool, cpuaddr, dma_handle);
  1343. }
  1344. #else
  1345. pci_free_consistent(he_dev->pci_dev, CONFIG_RBPS_SIZE
  1346. * CONFIG_RBPS_BUFSIZE, he_dev->rbps_pages, he_dev->rbps_pages_phys);
  1347. #endif
  1348. pci_free_consistent(he_dev->pci_dev, CONFIG_RBPS_SIZE
  1349. * sizeof(struct he_rbp), he_dev->rbps_base, he_dev->rbps_phys);
  1350. }
  1351. #ifdef USE_RBPS_POOL
  1352. if (he_dev->rbps_pool)
  1353. pci_pool_destroy(he_dev->rbps_pool);
  1354. #endif
  1355. #endif /* USE_RBPS */
  1356. if (he_dev->rbrq_base)
  1357. pci_free_consistent(he_dev->pci_dev, CONFIG_RBRQ_SIZE * sizeof(struct he_rbrq),
  1358. he_dev->rbrq_base, he_dev->rbrq_phys);
  1359. if (he_dev->tbrq_base)
  1360. pci_free_consistent(he_dev->pci_dev, CONFIG_TBRQ_SIZE * sizeof(struct he_tbrq),
  1361. he_dev->tbrq_base, he_dev->tbrq_phys);
  1362. if (he_dev->tpdrq_base)
  1363. pci_free_consistent(he_dev->pci_dev, CONFIG_TBRQ_SIZE * sizeof(struct he_tbrq),
  1364. he_dev->tpdrq_base, he_dev->tpdrq_phys);
  1365. #ifdef USE_TPD_POOL
  1366. if (he_dev->tpd_pool)
  1367. pci_pool_destroy(he_dev->tpd_pool);
  1368. #else
  1369. if (he_dev->tpd_base)
  1370. pci_free_consistent(he_dev->pci_dev, CONFIG_NUMTPDS * sizeof(struct he_tpd),
  1371. he_dev->tpd_base, he_dev->tpd_base_phys);
  1372. #endif
  1373. if (he_dev->pci_dev) {
  1374. pci_read_config_word(he_dev->pci_dev, PCI_COMMAND, &command);
  1375. command &= ~(PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
  1376. pci_write_config_word(he_dev->pci_dev, PCI_COMMAND, command);
  1377. }
  1378. if (he_dev->membase)
  1379. iounmap(he_dev->membase);
  1380. }
  1381. static struct he_tpd *
  1382. __alloc_tpd(struct he_dev *he_dev)
  1383. {
  1384. #ifdef USE_TPD_POOL
  1385. struct he_tpd *tpd;
  1386. dma_addr_t dma_handle;
  1387. tpd = pci_pool_alloc(he_dev->tpd_pool, SLAB_ATOMIC|SLAB_DMA, &dma_handle);
  1388. if (tpd == NULL)
  1389. return NULL;
  1390. tpd->status = TPD_ADDR(dma_handle);
  1391. tpd->reserved = 0;
  1392. tpd->iovec[0].addr = 0; tpd->iovec[0].len = 0;
  1393. tpd->iovec[1].addr = 0; tpd->iovec[1].len = 0;
  1394. tpd->iovec[2].addr = 0; tpd->iovec[2].len = 0;
  1395. return tpd;
  1396. #else
  1397. int i;
  1398. for (i = 0; i < CONFIG_NUMTPDS; ++i) {
  1399. ++he_dev->tpd_head;
  1400. if (he_dev->tpd_head > he_dev->tpd_end) {
  1401. he_dev->tpd_head = he_dev->tpd_base;
  1402. }
  1403. if (!he_dev->tpd_head->inuse) {
  1404. he_dev->tpd_head->inuse = 1;
  1405. he_dev->tpd_head->status &= TPD_MASK;
  1406. he_dev->tpd_head->iovec[0].addr = 0; he_dev->tpd_head->iovec[0].len = 0;
  1407. he_dev->tpd_head->iovec[1].addr = 0; he_dev->tpd_head->iovec[1].len = 0;
  1408. he_dev->tpd_head->iovec[2].addr = 0; he_dev->tpd_head->iovec[2].len = 0;
  1409. return he_dev->tpd_head;
  1410. }
  1411. }
  1412. hprintk("out of tpds -- increase CONFIG_NUMTPDS (%d)\n", CONFIG_NUMTPDS);
  1413. return NULL;
  1414. #endif
  1415. }
  1416. #define AAL5_LEN(buf,len) \
  1417. ((((unsigned char *)(buf))[(len)-6] << 8) | \
  1418. (((unsigned char *)(buf))[(len)-5]))
  1419. /* 2.10.1.2 receive
  1420. *
  1421. * aal5 packets can optionally return the tcp checksum in the lower
  1422. * 16 bits of the crc (RSR0_TCP_CKSUM)
  1423. */
  1424. #define TCP_CKSUM(buf,len) \
  1425. ((((unsigned char *)(buf))[(len)-2] << 8) | \
  1426. (((unsigned char *)(buf))[(len-1)]))
  1427. static int
  1428. he_service_rbrq(struct he_dev *he_dev, int group)
  1429. {
  1430. struct he_rbrq *rbrq_tail = (struct he_rbrq *)
  1431. ((unsigned long)he_dev->rbrq_base |
  1432. he_dev->hsp->group[group].rbrq_tail);
  1433. struct he_rbp *rbp = NULL;
  1434. unsigned cid, lastcid = -1;
  1435. unsigned buf_len = 0;
  1436. struct sk_buff *skb;
  1437. struct atm_vcc *vcc = NULL;
  1438. struct he_vcc *he_vcc;
  1439. struct he_iovec *iov;
  1440. int pdus_assembled = 0;
  1441. int updated = 0;
  1442. read_lock(&vcc_sklist_lock);
  1443. while (he_dev->rbrq_head != rbrq_tail) {
  1444. ++updated;
  1445. HPRINTK("%p rbrq%d 0x%x len=%d cid=0x%x %s%s%s%s%s%s\n",
  1446. he_dev->rbrq_head, group,
  1447. RBRQ_ADDR(he_dev->rbrq_head),
  1448. RBRQ_BUFLEN(he_dev->rbrq_head),
  1449. RBRQ_CID(he_dev->rbrq_head),
  1450. RBRQ_CRC_ERR(he_dev->rbrq_head) ? " CRC_ERR" : "",
  1451. RBRQ_LEN_ERR(he_dev->rbrq_head) ? " LEN_ERR" : "",
  1452. RBRQ_END_PDU(he_dev->rbrq_head) ? " END_PDU" : "",
  1453. RBRQ_AAL5_PROT(he_dev->rbrq_head) ? " AAL5_PROT" : "",
  1454. RBRQ_CON_CLOSED(he_dev->rbrq_head) ? " CON_CLOSED" : "",
  1455. RBRQ_HBUF_ERR(he_dev->rbrq_head) ? " HBUF_ERR" : "");
  1456. #ifdef USE_RBPS
  1457. if (RBRQ_ADDR(he_dev->rbrq_head) & RBP_SMALLBUF)
  1458. rbp = &he_dev->rbps_base[RBP_INDEX(RBRQ_ADDR(he_dev->rbrq_head))];
  1459. else
  1460. #endif
  1461. rbp = &he_dev->rbpl_base[RBP_INDEX(RBRQ_ADDR(he_dev->rbrq_head))];
  1462. buf_len = RBRQ_BUFLEN(he_dev->rbrq_head) * 4;
  1463. cid = RBRQ_CID(he_dev->rbrq_head);
  1464. if (cid != lastcid)
  1465. vcc = __find_vcc(he_dev, cid);
  1466. lastcid = cid;
  1467. if (vcc == NULL) {
  1468. hprintk("vcc == NULL (cid 0x%x)\n", cid);
  1469. if (!RBRQ_HBUF_ERR(he_dev->rbrq_head))
  1470. rbp->status &= ~RBP_LOANED;
  1471. goto next_rbrq_entry;
  1472. }
  1473. he_vcc = HE_VCC(vcc);
  1474. if (he_vcc == NULL) {
  1475. hprintk("he_vcc == NULL (cid 0x%x)\n", cid);
  1476. if (!RBRQ_HBUF_ERR(he_dev->rbrq_head))
  1477. rbp->status &= ~RBP_LOANED;
  1478. goto next_rbrq_entry;
  1479. }
  1480. if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
  1481. hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
  1482. atomic_inc(&vcc->stats->rx_drop);
  1483. goto return_host_buffers;
  1484. }
  1485. he_vcc->iov_tail->iov_base = RBRQ_ADDR(he_dev->rbrq_head);
  1486. he_vcc->iov_tail->iov_len = buf_len;
  1487. he_vcc->pdu_len += buf_len;
  1488. ++he_vcc->iov_tail;
  1489. if (RBRQ_CON_CLOSED(he_dev->rbrq_head)) {
  1490. lastcid = -1;
  1491. HPRINTK("wake_up rx_waitq (cid 0x%x)\n", cid);
  1492. wake_up(&he_vcc->rx_waitq);
  1493. goto return_host_buffers;
  1494. }
  1495. #ifdef notdef
  1496. if ((he_vcc->iov_tail - he_vcc->iov_head) > HE_MAXIOV) {
  1497. hprintk("iovec full! cid 0x%x\n", cid);
  1498. goto return_host_buffers;
  1499. }
  1500. #endif
  1501. if (!RBRQ_END_PDU(he_dev->rbrq_head))
  1502. goto next_rbrq_entry;
  1503. if (RBRQ_LEN_ERR(he_dev->rbrq_head)
  1504. || RBRQ_CRC_ERR(he_dev->rbrq_head)) {
  1505. HPRINTK("%s%s (%d.%d)\n",
  1506. RBRQ_CRC_ERR(he_dev->rbrq_head)
  1507. ? "CRC_ERR " : "",
  1508. RBRQ_LEN_ERR(he_dev->rbrq_head)
  1509. ? "LEN_ERR" : "",
  1510. vcc->vpi, vcc->vci);
  1511. atomic_inc(&vcc->stats->rx_err);
  1512. goto return_host_buffers;
  1513. }
  1514. skb = atm_alloc_charge(vcc, he_vcc->pdu_len + rx_skb_reserve,
  1515. GFP_ATOMIC);
  1516. if (!skb) {
  1517. HPRINTK("charge failed (%d.%d)\n", vcc->vpi, vcc->vci);
  1518. goto return_host_buffers;
  1519. }
  1520. if (rx_skb_reserve > 0)
  1521. skb_reserve(skb, rx_skb_reserve);
  1522. do_gettimeofday(&skb->stamp);
  1523. for (iov = he_vcc->iov_head;
  1524. iov < he_vcc->iov_tail; ++iov) {
  1525. #ifdef USE_RBPS
  1526. if (iov->iov_base & RBP_SMALLBUF)
  1527. memcpy(skb_put(skb, iov->iov_len),
  1528. he_dev->rbps_virt[RBP_INDEX(iov->iov_base)].virt, iov->iov_len);
  1529. else
  1530. #endif
  1531. memcpy(skb_put(skb, iov->iov_len),
  1532. he_dev->rbpl_virt[RBP_INDEX(iov->iov_base)].virt, iov->iov_len);
  1533. }
  1534. switch (vcc->qos.aal) {
  1535. case ATM_AAL0:
  1536. /* 2.10.1.5 raw cell receive */
  1537. skb->len = ATM_AAL0_SDU;
  1538. skb->tail = skb->data + skb->len;
  1539. break;
  1540. case ATM_AAL5:
  1541. /* 2.10.1.2 aal5 receive */
  1542. skb->len = AAL5_LEN(skb->data, he_vcc->pdu_len);
  1543. skb->tail = skb->data + skb->len;
  1544. #ifdef USE_CHECKSUM_HW
  1545. if (vcc->vpi == 0 && vcc->vci >= ATM_NOT_RSV_VCI) {
  1546. skb->ip_summed = CHECKSUM_HW;
  1547. skb->csum = TCP_CKSUM(skb->data,
  1548. he_vcc->pdu_len);
  1549. }
  1550. #endif
  1551. break;
  1552. }
  1553. #ifdef should_never_happen
  1554. if (skb->len > vcc->qos.rxtp.max_sdu)
  1555. hprintk("pdu_len (%d) > vcc->qos.rxtp.max_sdu (%d)! cid 0x%x\n", skb->len, vcc->qos.rxtp.max_sdu, cid);
  1556. #endif
  1557. #ifdef notdef
  1558. ATM_SKB(skb)->vcc = vcc;
  1559. #endif
  1560. vcc->push(vcc, skb);
  1561. atomic_inc(&vcc->stats->rx);
  1562. return_host_buffers:
  1563. ++pdus_assembled;
  1564. for (iov = he_vcc->iov_head;
  1565. iov < he_vcc->iov_tail; ++iov) {
  1566. #ifdef USE_RBPS
  1567. if (iov->iov_base & RBP_SMALLBUF)
  1568. rbp = &he_dev->rbps_base[RBP_INDEX(iov->iov_base)];
  1569. else
  1570. #endif
  1571. rbp = &he_dev->rbpl_base[RBP_INDEX(iov->iov_base)];
  1572. rbp->status &= ~RBP_LOANED;
  1573. }
  1574. he_vcc->iov_tail = he_vcc->iov_head;
  1575. he_vcc->pdu_len = 0;
  1576. next_rbrq_entry:
  1577. he_dev->rbrq_head = (struct he_rbrq *)
  1578. ((unsigned long) he_dev->rbrq_base |
  1579. RBRQ_MASK(++he_dev->rbrq_head));
  1580. }
  1581. read_unlock(&vcc_sklist_lock);
  1582. if (updated) {
  1583. if (updated > he_dev->rbrq_peak)
  1584. he_dev->rbrq_peak = updated;
  1585. he_writel(he_dev, RBRQ_MASK(he_dev->rbrq_head),
  1586. G0_RBRQ_H + (group * 16));
  1587. }
  1588. return pdus_assembled;
  1589. }
  1590. static void
  1591. he_service_tbrq(struct he_dev *he_dev, int group)
  1592. {
  1593. struct he_tbrq *tbrq_tail = (struct he_tbrq *)
  1594. ((unsigned long)he_dev->tbrq_base |
  1595. he_dev->hsp->group[group].tbrq_tail);
  1596. struct he_tpd *tpd;
  1597. int slot, updated = 0;
  1598. #ifdef USE_TPD_POOL
  1599. struct he_tpd *__tpd;
  1600. #endif
  1601. /* 2.1.6 transmit buffer return queue */
  1602. while (he_dev->tbrq_head != tbrq_tail) {
  1603. ++updated;
  1604. HPRINTK("tbrq%d 0x%x%s%s\n",
  1605. group,
  1606. TBRQ_TPD(he_dev->tbrq_head),
  1607. TBRQ_EOS(he_dev->tbrq_head) ? " EOS" : "",
  1608. TBRQ_MULTIPLE(he_dev->tbrq_head) ? " MULTIPLE" : "");
  1609. #ifdef USE_TPD_POOL
  1610. tpd = NULL;
  1611. list_for_each_entry(__tpd, &he_dev->outstanding_tpds, entry) {
  1612. if (TPD_ADDR(__tpd->status) == TBRQ_TPD(he_dev->tbrq_head)) {
  1613. tpd = __tpd;
  1614. list_del(&__tpd->entry);
  1615. break;
  1616. }
  1617. }
  1618. if (tpd == NULL) {
  1619. hprintk("unable to locate tpd for dma buffer %x\n",
  1620. TBRQ_TPD(he_dev->tbrq_head));
  1621. goto next_tbrq_entry;
  1622. }
  1623. #else
  1624. tpd = &he_dev->tpd_base[ TPD_INDEX(TBRQ_TPD(he_dev->tbrq_head)) ];
  1625. #endif
  1626. if (TBRQ_EOS(he_dev->tbrq_head)) {
  1627. HPRINTK("wake_up(tx_waitq) cid 0x%x\n",
  1628. he_mkcid(he_dev, tpd->vcc->vpi, tpd->vcc->vci));
  1629. if (tpd->vcc)
  1630. wake_up(&HE_VCC(tpd->vcc)->tx_waitq);
  1631. goto next_tbrq_entry;
  1632. }
  1633. for (slot = 0; slot < TPD_MAXIOV; ++slot) {
  1634. if (tpd->iovec[slot].addr)
  1635. pci_unmap_single(he_dev->pci_dev,
  1636. tpd->iovec[slot].addr,
  1637. tpd->iovec[slot].len & TPD_LEN_MASK,
  1638. PCI_DMA_TODEVICE);
  1639. if (tpd->iovec[slot].len & TPD_LST)
  1640. break;
  1641. }
  1642. if (tpd->skb) { /* && !TBRQ_MULTIPLE(he_dev->tbrq_head) */
  1643. if (tpd->vcc && tpd->vcc->pop)
  1644. tpd->vcc->pop(tpd->vcc, tpd->skb);
  1645. else
  1646. dev_kfree_skb_any(tpd->skb);
  1647. }
  1648. next_tbrq_entry:
  1649. #ifdef USE_TPD_POOL
  1650. if (tpd)
  1651. pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
  1652. #else
  1653. tpd->inuse = 0;
  1654. #endif
  1655. he_dev->tbrq_head = (struct he_tbrq *)
  1656. ((unsigned long) he_dev->tbrq_base |
  1657. TBRQ_MASK(++he_dev->tbrq_head));
  1658. }
  1659. if (updated) {
  1660. if (updated > he_dev->tbrq_peak)
  1661. he_dev->tbrq_peak = updated;
  1662. he_writel(he_dev, TBRQ_MASK(he_dev->tbrq_head),
  1663. G0_TBRQ_H + (group * 16));
  1664. }
  1665. }
  1666. static void
  1667. he_service_rbpl(struct he_dev *he_dev, int group)
  1668. {
  1669. struct he_rbp *newtail;
  1670. struct he_rbp *rbpl_head;
  1671. int moved = 0;
  1672. rbpl_head = (struct he_rbp *) ((unsigned long)he_dev->rbpl_base |
  1673. RBPL_MASK(he_readl(he_dev, G0_RBPL_S)));
  1674. for (;;) {
  1675. newtail = (struct he_rbp *) ((unsigned long)he_dev->rbpl_base |
  1676. RBPL_MASK(he_dev->rbpl_tail+1));
  1677. /* table 3.42 -- rbpl_tail should never be set to rbpl_head */
  1678. if ((newtail == rbpl_head) || (newtail->status & RBP_LOANED))
  1679. break;
  1680. newtail->status |= RBP_LOANED;
  1681. he_dev->rbpl_tail = newtail;
  1682. ++moved;
  1683. }
  1684. if (moved)
  1685. he_writel(he_dev, RBPL_MASK(he_dev->rbpl_tail), G0_RBPL_T);
  1686. }
  1687. #ifdef USE_RBPS
  1688. static void
  1689. he_service_rbps(struct he_dev *he_dev, int group)
  1690. {
  1691. struct he_rbp *newtail;
  1692. struct he_rbp *rbps_head;
  1693. int moved = 0;
  1694. rbps_head = (struct he_rbp *) ((unsigned long)he_dev->rbps_base |
  1695. RBPS_MASK(he_readl(he_dev, G0_RBPS_S)));
  1696. for (;;) {
  1697. newtail = (struct he_rbp *) ((unsigned long)he_dev->rbps_base |
  1698. RBPS_MASK(he_dev->rbps_tail+1));
  1699. /* table 3.42 -- rbps_tail should never be set to rbps_head */
  1700. if ((newtail == rbps_head) || (newtail->status & RBP_LOANED))
  1701. break;
  1702. newtail->status |= RBP_LOANED;
  1703. he_dev->rbps_tail = newtail;
  1704. ++moved;
  1705. }
  1706. if (moved)
  1707. he_writel(he_dev, RBPS_MASK(he_dev->rbps_tail), G0_RBPS_T);
  1708. }
  1709. #endif /* USE_RBPS */
  1710. static void
  1711. he_tasklet(unsigned long data)
  1712. {
  1713. unsigned long flags;
  1714. struct he_dev *he_dev = (struct he_dev *) data;
  1715. int group, type;
  1716. int updated = 0;
  1717. HPRINTK("tasklet (0x%lx)\n", data);
  1718. #ifdef USE_TASKLET
  1719. spin_lock_irqsave(&he_dev->global_lock, flags);
  1720. #endif
  1721. while (he_dev->irq_head != he_dev->irq_tail) {
  1722. ++updated;
  1723. type = ITYPE_TYPE(he_dev->irq_head->isw);
  1724. group = ITYPE_GROUP(he_dev->irq_head->isw);
  1725. switch (type) {
  1726. case ITYPE_RBRQ_THRESH:
  1727. HPRINTK("rbrq%d threshold\n", group);
  1728. /* fall through */
  1729. case ITYPE_RBRQ_TIMER:
  1730. if (he_service_rbrq(he_dev, group)) {
  1731. he_service_rbpl(he_dev, group);
  1732. #ifdef USE_RBPS
  1733. he_service_rbps(he_dev, group);
  1734. #endif /* USE_RBPS */
  1735. }
  1736. break;
  1737. case ITYPE_TBRQ_THRESH:
  1738. HPRINTK("tbrq%d threshold\n", group);
  1739. /* fall through */
  1740. case ITYPE_TPD_COMPLETE:
  1741. he_service_tbrq(he_dev, group);
  1742. break;
  1743. case ITYPE_RBPL_THRESH:
  1744. he_service_rbpl(he_dev, group);
  1745. break;
  1746. case ITYPE_RBPS_THRESH:
  1747. #ifdef USE_RBPS
  1748. he_service_rbps(he_dev, group);
  1749. #endif /* USE_RBPS */
  1750. break;
  1751. case ITYPE_PHY:
  1752. HPRINTK("phy interrupt\n");
  1753. #ifdef CONFIG_ATM_HE_USE_SUNI
  1754. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  1755. if (he_dev->atm_dev->phy && he_dev->atm_dev->phy->interrupt)
  1756. he_dev->atm_dev->phy->interrupt(he_dev->atm_dev);
  1757. spin_lock_irqsave(&he_dev->global_lock, flags);
  1758. #endif
  1759. break;
  1760. case ITYPE_OTHER:
  1761. switch (type|group) {
  1762. case ITYPE_PARITY:
  1763. hprintk("parity error\n");
  1764. break;
  1765. case ITYPE_ABORT:
  1766. hprintk("abort 0x%x\n", he_readl(he_dev, ABORT_ADDR));
  1767. break;
  1768. }
  1769. break;
  1770. case ITYPE_TYPE(ITYPE_INVALID):
  1771. /* see 8.1.1 -- check all queues */
  1772. HPRINTK("isw not updated 0x%x\n", he_dev->irq_head->isw);
  1773. he_service_rbrq(he_dev, 0);
  1774. he_service_rbpl(he_dev, 0);
  1775. #ifdef USE_RBPS
  1776. he_service_rbps(he_dev, 0);
  1777. #endif /* USE_RBPS */
  1778. he_service_tbrq(he_dev, 0);
  1779. break;
  1780. default:
  1781. hprintk("bad isw 0x%x?\n", he_dev->irq_head->isw);
  1782. }
  1783. he_dev->irq_head->isw = ITYPE_INVALID;
  1784. he_dev->irq_head = (struct he_irq *) NEXT_ENTRY(he_dev->irq_base, he_dev->irq_head, IRQ_MASK);
  1785. }
  1786. if (updated) {
  1787. if (updated > he_dev->irq_peak)
  1788. he_dev->irq_peak = updated;
  1789. he_writel(he_dev,
  1790. IRQ_SIZE(CONFIG_IRQ_SIZE) |
  1791. IRQ_THRESH(CONFIG_IRQ_THRESH) |
  1792. IRQ_TAIL(he_dev->irq_tail), IRQ0_HEAD);
  1793. (void) he_readl(he_dev, INT_FIFO); /* 8.1.2 controller errata; flush posted writes */
  1794. }
  1795. #ifdef USE_TASKLET
  1796. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  1797. #endif
  1798. }
  1799. static irqreturn_t
  1800. he_irq_handler(int irq, void *dev_id, struct pt_regs *regs)
  1801. {
  1802. unsigned long flags;
  1803. struct he_dev *he_dev = (struct he_dev * )dev_id;
  1804. int handled = 0;
  1805. if (he_dev == NULL)
  1806. return IRQ_NONE;
  1807. spin_lock_irqsave(&he_dev->global_lock, flags);
  1808. he_dev->irq_tail = (struct he_irq *) (((unsigned long)he_dev->irq_base) |
  1809. (*he_dev->irq_tailoffset << 2));
  1810. if (he_dev->irq_tail == he_dev->irq_head) {
  1811. HPRINTK("tailoffset not updated?\n");
  1812. he_dev->irq_tail = (struct he_irq *) ((unsigned long)he_dev->irq_base |
  1813. ((he_readl(he_dev, IRQ0_BASE) & IRQ_MASK) << 2));
  1814. (void) he_readl(he_dev, INT_FIFO); /* 8.1.2 controller errata */
  1815. }
  1816. #ifdef DEBUG
  1817. if (he_dev->irq_head == he_dev->irq_tail /* && !IRQ_PENDING */)
  1818. hprintk("spurious (or shared) interrupt?\n");
  1819. #endif
  1820. if (he_dev->irq_head != he_dev->irq_tail) {
  1821. handled = 1;
  1822. #ifdef USE_TASKLET
  1823. tasklet_schedule(&he_dev->tasklet);
  1824. #else
  1825. he_tasklet((unsigned long) he_dev);
  1826. #endif
  1827. he_writel(he_dev, INT_CLEAR_A, INT_FIFO); /* clear interrupt */
  1828. (void) he_readl(he_dev, INT_FIFO); /* flush posted writes */
  1829. }
  1830. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  1831. return IRQ_RETVAL(handled);
  1832. }
  1833. static __inline__ void
  1834. __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
  1835. {
  1836. struct he_tpdrq *new_tail;
  1837. HPRINTK("tpdrq %p cid 0x%x -> tpdrq_tail %p\n",
  1838. tpd, cid, he_dev->tpdrq_tail);
  1839. /* new_tail = he_dev->tpdrq_tail; */
  1840. new_tail = (struct he_tpdrq *) ((unsigned long) he_dev->tpdrq_base |
  1841. TPDRQ_MASK(he_dev->tpdrq_tail+1));
  1842. /*
  1843. * check to see if we are about to set the tail == head
  1844. * if true, update the head pointer from the adapter
  1845. * to see if this is really the case (reading the queue
  1846. * head for every enqueue would be unnecessarily slow)
  1847. */
  1848. if (new_tail == he_dev->tpdrq_head) {
  1849. he_dev->tpdrq_head = (struct he_tpdrq *)
  1850. (((unsigned long)he_dev->tpdrq_base) |
  1851. TPDRQ_MASK(he_readl(he_dev, TPDRQ_B_H)));
  1852. if (new_tail == he_dev->tpdrq_head) {
  1853. hprintk("tpdrq full (cid 0x%x)\n", cid);
  1854. /*
  1855. * FIXME
  1856. * push tpd onto a transmit backlog queue
  1857. * after service_tbrq, service the backlog
  1858. * for now, we just drop the pdu
  1859. */
  1860. if (tpd->skb) {
  1861. if (tpd->vcc->pop)
  1862. tpd->vcc->pop(tpd->vcc, tpd->skb);
  1863. else
  1864. dev_kfree_skb_any(tpd->skb);
  1865. atomic_inc(&tpd->vcc->stats->tx_err);
  1866. }
  1867. #ifdef USE_TPD_POOL
  1868. pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
  1869. #else
  1870. tpd->inuse = 0;
  1871. #endif
  1872. return;
  1873. }
  1874. }
  1875. /* 2.1.5 transmit packet descriptor ready queue */
  1876. #ifdef USE_TPD_POOL
  1877. list_add_tail(&tpd->entry, &he_dev->outstanding_tpds);
  1878. he_dev->tpdrq_tail->tpd = TPD_ADDR(tpd->status);
  1879. #else
  1880. he_dev->tpdrq_tail->tpd = he_dev->tpd_base_phys +
  1881. (TPD_INDEX(tpd->status) * sizeof(struct he_tpd));
  1882. #endif
  1883. he_dev->tpdrq_tail->cid = cid;
  1884. wmb();
  1885. he_dev->tpdrq_tail = new_tail;
  1886. he_writel(he_dev, TPDRQ_MASK(he_dev->tpdrq_tail), TPDRQ_T);
  1887. (void) he_readl(he_dev, TPDRQ_T); /* flush posted writes */
  1888. }
  1889. static int
  1890. he_open(struct atm_vcc *vcc)
  1891. {
  1892. unsigned long flags;
  1893. struct he_dev *he_dev = HE_DEV(vcc->dev);
  1894. struct he_vcc *he_vcc;
  1895. int err = 0;
  1896. unsigned cid, rsr0, rsr1, rsr4, tsr0, tsr0_aal, tsr4, period, reg, clock;
  1897. short vpi = vcc->vpi;
  1898. int vci = vcc->vci;
  1899. if (vci == ATM_VCI_UNSPEC || vpi == ATM_VPI_UNSPEC)
  1900. return 0;
  1901. HPRINTK("open vcc %p %d.%d\n", vcc, vpi, vci);
  1902. set_bit(ATM_VF_ADDR, &vcc->flags);
  1903. cid = he_mkcid(he_dev, vpi, vci);
  1904. he_vcc = (struct he_vcc *) kmalloc(sizeof(struct he_vcc), GFP_ATOMIC);
  1905. if (he_vcc == NULL) {
  1906. hprintk("unable to allocate he_vcc during open\n");
  1907. return -ENOMEM;
  1908. }
  1909. he_vcc->iov_tail = he_vcc->iov_head;
  1910. he_vcc->pdu_len = 0;
  1911. he_vcc->rc_index = -1;
  1912. init_waitqueue_head(&he_vcc->rx_waitq);
  1913. init_waitqueue_head(&he_vcc->tx_waitq);
  1914. vcc->dev_data = he_vcc;
  1915. if (vcc->qos.txtp.traffic_class != ATM_NONE) {
  1916. int pcr_goal;
  1917. pcr_goal = atm_pcr_goal(&vcc->qos.txtp);
  1918. if (pcr_goal == 0)
  1919. pcr_goal = he_dev->atm_dev->link_rate;
  1920. if (pcr_goal < 0) /* means round down, technically */
  1921. pcr_goal = -pcr_goal;
  1922. HPRINTK("open tx cid 0x%x pcr_goal %d\n", cid, pcr_goal);
  1923. switch (vcc->qos.aal) {
  1924. case ATM_AAL5:
  1925. tsr0_aal = TSR0_AAL5;
  1926. tsr4 = TSR4_AAL5;
  1927. break;
  1928. case ATM_AAL0:
  1929. tsr0_aal = TSR0_AAL0_SDU;
  1930. tsr4 = TSR4_AAL0_SDU;
  1931. break;
  1932. default:
  1933. err = -EINVAL;
  1934. goto open_failed;
  1935. }
  1936. spin_lock_irqsave(&he_dev->global_lock, flags);
  1937. tsr0 = he_readl_tsr0(he_dev, cid);
  1938. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  1939. if (TSR0_CONN_STATE(tsr0) != 0) {
  1940. hprintk("cid 0x%x not idle (tsr0 = 0x%x)\n", cid, tsr0);
  1941. err = -EBUSY;
  1942. goto open_failed;
  1943. }
  1944. switch (vcc->qos.txtp.traffic_class) {
  1945. case ATM_UBR:
  1946. /* 2.3.3.1 open connection ubr */
  1947. tsr0 = TSR0_UBR | TSR0_GROUP(0) | tsr0_aal |
  1948. TSR0_USE_WMIN | TSR0_UPDATE_GER;
  1949. break;
  1950. case ATM_CBR:
  1951. /* 2.3.3.2 open connection cbr */
  1952. /* 8.2.3 cbr scheduler wrap problem -- limit to 90% total link rate */
  1953. if ((he_dev->total_bw + pcr_goal)
  1954. > (he_dev->atm_dev->link_rate * 9 / 10))
  1955. {
  1956. err = -EBUSY;
  1957. goto open_failed;
  1958. }
  1959. spin_lock_irqsave(&he_dev->global_lock, flags); /* also protects he_dev->cs_stper[] */
  1960. /* find an unused cs_stper register */
  1961. for (reg = 0; reg < HE_NUM_CS_STPER; ++reg)
  1962. if (he_dev->cs_stper[reg].inuse == 0 ||
  1963. he_dev->cs_stper[reg].pcr == pcr_goal)
  1964. break;
  1965. if (reg == HE_NUM_CS_STPER) {
  1966. err = -EBUSY;
  1967. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  1968. goto open_failed;
  1969. }
  1970. he_dev->total_bw += pcr_goal;
  1971. he_vcc->rc_index = reg;
  1972. ++he_dev->cs_stper[reg].inuse;
  1973. he_dev->cs_stper[reg].pcr = pcr_goal;
  1974. clock = he_is622(he_dev) ? 66667000 : 50000000;
  1975. period = clock / pcr_goal;
  1976. HPRINTK("rc_index = %d period = %d\n",
  1977. reg, period);
  1978. he_writel_mbox(he_dev, rate_to_atmf(period/2),
  1979. CS_STPER0 + reg);
  1980. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  1981. tsr0 = TSR0_CBR | TSR0_GROUP(0) | tsr0_aal |
  1982. TSR0_RC_INDEX(reg);
  1983. break;
  1984. default:
  1985. err = -EINVAL;
  1986. goto open_failed;
  1987. }
  1988. spin_lock_irqsave(&he_dev->global_lock, flags);
  1989. he_writel_tsr0(he_dev, tsr0, cid);
  1990. he_writel_tsr4(he_dev, tsr4 | 1, cid);
  1991. he_writel_tsr1(he_dev, TSR1_MCR(rate_to_atmf(0)) |
  1992. TSR1_PCR(rate_to_atmf(pcr_goal)), cid);
  1993. he_writel_tsr2(he_dev, TSR2_ACR(rate_to_atmf(pcr_goal)), cid);
  1994. he_writel_tsr9(he_dev, TSR9_OPEN_CONN, cid);
  1995. he_writel_tsr3(he_dev, 0x0, cid);
  1996. he_writel_tsr5(he_dev, 0x0, cid);
  1997. he_writel_tsr6(he_dev, 0x0, cid);
  1998. he_writel_tsr7(he_dev, 0x0, cid);
  1999. he_writel_tsr8(he_dev, 0x0, cid);
  2000. he_writel_tsr10(he_dev, 0x0, cid);
  2001. he_writel_tsr11(he_dev, 0x0, cid);
  2002. he_writel_tsr12(he_dev, 0x0, cid);
  2003. he_writel_tsr13(he_dev, 0x0, cid);
  2004. he_writel_tsr14(he_dev, 0x0, cid);
  2005. (void) he_readl_tsr0(he_dev, cid); /* flush posted writes */
  2006. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  2007. }
  2008. if (vcc->qos.rxtp.traffic_class != ATM_NONE) {
  2009. unsigned aal;
  2010. HPRINTK("open rx cid 0x%x (rx_waitq %p)\n", cid,
  2011. &HE_VCC(vcc)->rx_waitq);
  2012. switch (vcc->qos.aal) {
  2013. case ATM_AAL5:
  2014. aal = RSR0_AAL5;
  2015. break;
  2016. case ATM_AAL0:
  2017. aal = RSR0_RAWCELL;
  2018. break;
  2019. default:
  2020. err = -EINVAL;
  2021. goto open_failed;
  2022. }
  2023. spin_lock_irqsave(&he_dev->global_lock, flags);
  2024. rsr0 = he_readl_rsr0(he_dev, cid);
  2025. if (rsr0 & RSR0_OPEN_CONN) {
  2026. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  2027. hprintk("cid 0x%x not idle (rsr0 = 0x%x)\n", cid, rsr0);
  2028. err = -EBUSY;
  2029. goto open_failed;
  2030. }
  2031. #ifdef USE_RBPS
  2032. rsr1 = RSR1_GROUP(0);
  2033. rsr4 = RSR4_GROUP(0);
  2034. #else /* !USE_RBPS */
  2035. rsr1 = RSR1_GROUP(0)|RSR1_RBPL_ONLY;
  2036. rsr4 = RSR4_GROUP(0)|RSR4_RBPL_ONLY;
  2037. #endif /* USE_RBPS */
  2038. rsr0 = vcc->qos.rxtp.traffic_class == ATM_UBR ?
  2039. (RSR0_EPD_ENABLE|RSR0_PPD_ENABLE) : 0;
  2040. #ifdef USE_CHECKSUM_HW
  2041. if (vpi == 0 && vci >= ATM_NOT_RSV_VCI)
  2042. rsr0 |= RSR0_TCP_CKSUM;
  2043. #endif
  2044. he_writel_rsr4(he_dev, rsr4, cid);
  2045. he_writel_rsr1(he_dev, rsr1, cid);
  2046. /* 5.1.11 last parameter initialized should be
  2047. the open/closed indication in rsr0 */
  2048. he_writel_rsr0(he_dev,
  2049. rsr0 | RSR0_START_PDU | RSR0_OPEN_CONN | aal, cid);
  2050. (void) he_readl_rsr0(he_dev, cid); /* flush posted writes */
  2051. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  2052. }
  2053. open_failed:
  2054. if (err) {
  2055. kfree(he_vcc);
  2056. clear_bit(ATM_VF_ADDR, &vcc->flags);
  2057. }
  2058. else
  2059. set_bit(ATM_VF_READY, &vcc->flags);
  2060. return err;
  2061. }
  2062. static void
  2063. he_close(struct atm_vcc *vcc)
  2064. {
  2065. unsigned long flags;
  2066. DECLARE_WAITQUEUE(wait, current);
  2067. struct he_dev *he_dev = HE_DEV(vcc->dev);
  2068. struct he_tpd *tpd;
  2069. unsigned cid;
  2070. struct he_vcc *he_vcc = HE_VCC(vcc);
  2071. #define MAX_RETRY 30
  2072. int retry = 0, sleep = 1, tx_inuse;
  2073. HPRINTK("close vcc %p %d.%d\n", vcc, vcc->vpi, vcc->vci);
  2074. clear_bit(ATM_VF_READY, &vcc->flags);
  2075. cid = he_mkcid(he_dev, vcc->vpi, vcc->vci);
  2076. if (vcc->qos.rxtp.traffic_class != ATM_NONE) {
  2077. int timeout;
  2078. HPRINTK("close rx cid 0x%x\n", cid);
  2079. /* 2.7.2.2 close receive operation */
  2080. /* wait for previous close (if any) to finish */
  2081. spin_lock_irqsave(&he_dev->global_lock, flags);
  2082. while (he_readl(he_dev, RCC_STAT) & RCC_BUSY) {
  2083. HPRINTK("close cid 0x%x RCC_BUSY\n", cid);
  2084. udelay(250);
  2085. }
  2086. set_current_state(TASK_UNINTERRUPTIBLE);
  2087. add_wait_queue(&he_vcc->rx_waitq, &wait);
  2088. he_writel_rsr0(he_dev, RSR0_CLOSE_CONN, cid);
  2089. (void) he_readl_rsr0(he_dev, cid); /* flush posted writes */
  2090. he_writel_mbox(he_dev, cid, RXCON_CLOSE);
  2091. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  2092. timeout = schedule_timeout(30*HZ);
  2093. remove_wait_queue(&he_vcc->rx_waitq, &wait);
  2094. set_current_state(TASK_RUNNING);
  2095. if (timeout == 0)
  2096. hprintk("close rx timeout cid 0x%x\n", cid);
  2097. HPRINTK("close rx cid 0x%x complete\n", cid);
  2098. }
  2099. if (vcc->qos.txtp.traffic_class != ATM_NONE) {
  2100. volatile unsigned tsr4, tsr0;
  2101. int timeout;
  2102. HPRINTK("close tx cid 0x%x\n", cid);
  2103. /* 2.1.2
  2104. *
  2105. * ... the host must first stop queueing packets to the TPDRQ
  2106. * on the connection to be closed, then wait for all outstanding
  2107. * packets to be transmitted and their buffers returned to the
  2108. * TBRQ. When the last packet on the connection arrives in the
  2109. * TBRQ, the host issues the close command to the adapter.
  2110. */
  2111. while (((tx_inuse = atomic_read(&sk_atm(vcc)->sk_wmem_alloc)) > 0) &&
  2112. (retry < MAX_RETRY)) {
  2113. msleep(sleep);
  2114. if (sleep < 250)
  2115. sleep = sleep * 2;
  2116. ++retry;
  2117. }
  2118. if (tx_inuse)
  2119. hprintk("close tx cid 0x%x tx_inuse = %d\n", cid, tx_inuse);
  2120. /* 2.3.1.1 generic close operations with flush */
  2121. spin_lock_irqsave(&he_dev->global_lock, flags);
  2122. he_writel_tsr4_upper(he_dev, TSR4_FLUSH_CONN, cid);
  2123. /* also clears TSR4_SESSION_ENDED */
  2124. switch (vcc->qos.txtp.traffic_class) {
  2125. case ATM_UBR:
  2126. he_writel_tsr1(he_dev,
  2127. TSR1_MCR(rate_to_atmf(200000))
  2128. | TSR1_PCR(0), cid);
  2129. break;
  2130. case ATM_CBR:
  2131. he_writel_tsr14_upper(he_dev, TSR14_DELETE, cid);
  2132. break;
  2133. }
  2134. (void) he_readl_tsr4(he_dev, cid); /* flush posted writes */
  2135. tpd = __alloc_tpd(he_dev);
  2136. if (tpd == NULL) {
  2137. hprintk("close tx he_alloc_tpd failed cid 0x%x\n", cid);
  2138. goto close_tx_incomplete;
  2139. }
  2140. tpd->status |= TPD_EOS | TPD_INT;
  2141. tpd->skb = NULL;
  2142. tpd->vcc = vcc;
  2143. wmb();
  2144. set_current_state(TASK_UNINTERRUPTIBLE);
  2145. add_wait_queue(&he_vcc->tx_waitq, &wait);
  2146. __enqueue_tpd(he_dev, tpd, cid);
  2147. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  2148. timeout = schedule_timeout(30*HZ);
  2149. remove_wait_queue(&he_vcc->tx_waitq, &wait);
  2150. set_current_state(TASK_RUNNING);
  2151. spin_lock_irqsave(&he_dev->global_lock, flags);
  2152. if (timeout == 0) {
  2153. hprintk("close tx timeout cid 0x%x\n", cid);
  2154. goto close_tx_incomplete;
  2155. }
  2156. while (!((tsr4 = he_readl_tsr4(he_dev, cid)) & TSR4_SESSION_ENDED)) {
  2157. HPRINTK("close tx cid 0x%x !TSR4_SESSION_ENDED (tsr4 = 0x%x)\n", cid, tsr4);
  2158. udelay(250);
  2159. }
  2160. while (TSR0_CONN_STATE(tsr0 = he_readl_tsr0(he_dev, cid)) != 0) {
  2161. HPRINTK("close tx cid 0x%x TSR0_CONN_STATE != 0 (tsr0 = 0x%x)\n", cid, tsr0);
  2162. udelay(250);
  2163. }
  2164. close_tx_incomplete:
  2165. if (vcc->qos.txtp.traffic_class == ATM_CBR) {
  2166. int reg = he_vcc->rc_index;
  2167. HPRINTK("cs_stper reg = %d\n", reg);
  2168. if (he_dev->cs_stper[reg].inuse == 0)
  2169. hprintk("cs_stper[%d].inuse = 0!\n", reg);
  2170. else
  2171. --he_dev->cs_stper[reg].inuse;
  2172. he_dev->total_bw -= he_dev->cs_stper[reg].pcr;
  2173. }
  2174. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  2175. HPRINTK("close tx cid 0x%x complete\n", cid);
  2176. }
  2177. kfree(he_vcc);
  2178. clear_bit(ATM_VF_ADDR, &vcc->flags);
  2179. }
  2180. static int
  2181. he_send(struct atm_vcc *vcc, struct sk_buff *skb)
  2182. {
  2183. unsigned long flags;
  2184. struct he_dev *he_dev = HE_DEV(vcc->dev);
  2185. unsigned cid = he_mkcid(he_dev, vcc->vpi, vcc->vci);
  2186. struct he_tpd *tpd;
  2187. #ifdef USE_SCATTERGATHER
  2188. int i, slot = 0;
  2189. #endif
  2190. #define HE_TPD_BUFSIZE 0xffff
  2191. HPRINTK("send %d.%d\n", vcc->vpi, vcc->vci);
  2192. if ((skb->len > HE_TPD_BUFSIZE) ||
  2193. ((vcc->qos.aal == ATM_AAL0) && (skb->len != ATM_AAL0_SDU))) {
  2194. hprintk("buffer too large (or small) -- %d bytes\n", skb->len );
  2195. if (vcc->pop)
  2196. vcc->pop(vcc, skb);
  2197. else
  2198. dev_kfree_skb_any(skb);
  2199. atomic_inc(&vcc->stats->tx_err);
  2200. return -EINVAL;
  2201. }
  2202. #ifndef USE_SCATTERGATHER
  2203. if (skb_shinfo(skb)->nr_frags) {
  2204. hprintk("no scatter/gather support\n");
  2205. if (vcc->pop)
  2206. vcc->pop(vcc, skb);
  2207. else
  2208. dev_kfree_skb_any(skb);
  2209. atomic_inc(&vcc->stats->tx_err);
  2210. return -EINVAL;
  2211. }
  2212. #endif
  2213. spin_lock_irqsave(&he_dev->global_lock, flags);
  2214. tpd = __alloc_tpd(he_dev);
  2215. if (tpd == NULL) {
  2216. if (vcc->pop)
  2217. vcc->pop(vcc, skb);
  2218. else
  2219. dev_kfree_skb_any(skb);
  2220. atomic_inc(&vcc->stats->tx_err);
  2221. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  2222. return -ENOMEM;
  2223. }
  2224. if (vcc->qos.aal == ATM_AAL5)
  2225. tpd->status |= TPD_CELLTYPE(TPD_USERCELL);
  2226. else {
  2227. char *pti_clp = (void *) (skb->data + 3);
  2228. int clp, pti;
  2229. pti = (*pti_clp & ATM_HDR_PTI_MASK) >> ATM_HDR_PTI_SHIFT;
  2230. clp = (*pti_clp & ATM_HDR_CLP);
  2231. tpd->status |= TPD_CELLTYPE(pti);
  2232. if (clp)
  2233. tpd->status |= TPD_CLP;
  2234. skb_pull(skb, ATM_AAL0_SDU - ATM_CELL_PAYLOAD);
  2235. }
  2236. #ifdef USE_SCATTERGATHER
  2237. tpd->iovec[slot].addr = pci_map_single(he_dev->pci_dev, skb->data,
  2238. skb->len - skb->data_len, PCI_DMA_TODEVICE);
  2239. tpd->iovec[slot].len = skb->len - skb->data_len;
  2240. ++slot;
  2241. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  2242. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  2243. if (slot == TPD_MAXIOV) { /* queue tpd; start new tpd */
  2244. tpd->vcc = vcc;
  2245. tpd->skb = NULL; /* not the last fragment
  2246. so dont ->push() yet */
  2247. wmb();
  2248. __enqueue_tpd(he_dev, tpd, cid);
  2249. tpd = __alloc_tpd(he_dev);
  2250. if (tpd == NULL) {
  2251. if (vcc->pop)
  2252. vcc->pop(vcc, skb);
  2253. else
  2254. dev_kfree_skb_any(skb);
  2255. atomic_inc(&vcc->stats->tx_err);
  2256. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  2257. return -ENOMEM;
  2258. }
  2259. tpd->status |= TPD_USERCELL;
  2260. slot = 0;
  2261. }
  2262. tpd->iovec[slot].addr = pci_map_single(he_dev->pci_dev,
  2263. (void *) page_address(frag->page) + frag->page_offset,
  2264. frag->size, PCI_DMA_TODEVICE);
  2265. tpd->iovec[slot].len = frag->size;
  2266. ++slot;
  2267. }
  2268. tpd->iovec[slot - 1].len |= TPD_LST;
  2269. #else
  2270. tpd->address0 = pci_map_single(he_dev->pci_dev, skb->data, skb->len, PCI_DMA_TODEVICE);
  2271. tpd->length0 = skb->len | TPD_LST;
  2272. #endif
  2273. tpd->status |= TPD_INT;
  2274. tpd->vcc = vcc;
  2275. tpd->skb = skb;
  2276. wmb();
  2277. ATM_SKB(skb)->vcc = vcc;
  2278. __enqueue_tpd(he_dev, tpd, cid);
  2279. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  2280. atomic_inc(&vcc->stats->tx);
  2281. return 0;
  2282. }
  2283. static int
  2284. he_ioctl(struct atm_dev *atm_dev, unsigned int cmd, void __user *arg)
  2285. {
  2286. unsigned long flags;
  2287. struct he_dev *he_dev = HE_DEV(atm_dev);
  2288. struct he_ioctl_reg reg;
  2289. int err = 0;
  2290. switch (cmd) {
  2291. case HE_GET_REG:
  2292. if (!capable(CAP_NET_ADMIN))
  2293. return -EPERM;
  2294. if (copy_from_user(&reg, arg,
  2295. sizeof(struct he_ioctl_reg)))
  2296. return -EFAULT;
  2297. spin_lock_irqsave(&he_dev->global_lock, flags);
  2298. switch (reg.type) {
  2299. case HE_REGTYPE_PCI:
  2300. reg.val = he_readl(he_dev, reg.addr);
  2301. break;
  2302. case HE_REGTYPE_RCM:
  2303. reg.val =
  2304. he_readl_rcm(he_dev, reg.addr);
  2305. break;
  2306. case HE_REGTYPE_TCM:
  2307. reg.val =
  2308. he_readl_tcm(he_dev, reg.addr);
  2309. break;
  2310. case HE_REGTYPE_MBOX:
  2311. reg.val =
  2312. he_readl_mbox(he_dev, reg.addr);
  2313. break;
  2314. default:
  2315. err = -EINVAL;
  2316. break;
  2317. }
  2318. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  2319. if (err == 0)
  2320. if (copy_to_user(arg, &reg,
  2321. sizeof(struct he_ioctl_reg)))
  2322. return -EFAULT;
  2323. break;
  2324. default:
  2325. #ifdef CONFIG_ATM_HE_USE_SUNI
  2326. if (atm_dev->phy && atm_dev->phy->ioctl)
  2327. err = atm_dev->phy->ioctl(atm_dev, cmd, arg);
  2328. #else /* CONFIG_ATM_HE_USE_SUNI */
  2329. err = -EINVAL;
  2330. #endif /* CONFIG_ATM_HE_USE_SUNI */
  2331. break;
  2332. }
  2333. return err;
  2334. }
  2335. static void
  2336. he_phy_put(struct atm_dev *atm_dev, unsigned char val, unsigned long addr)
  2337. {
  2338. unsigned long flags;
  2339. struct he_dev *he_dev = HE_DEV(atm_dev);
  2340. HPRINTK("phy_put(val 0x%x, addr 0x%lx)\n", val, addr);
  2341. spin_lock_irqsave(&he_dev->global_lock, flags);
  2342. he_writel(he_dev, val, FRAMER + (addr*4));
  2343. (void) he_readl(he_dev, FRAMER + (addr*4)); /* flush posted writes */
  2344. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  2345. }
  2346. static unsigned char
  2347. he_phy_get(struct atm_dev *atm_dev, unsigned long addr)
  2348. {
  2349. unsigned long flags;
  2350. struct he_dev *he_dev = HE_DEV(atm_dev);
  2351. unsigned reg;
  2352. spin_lock_irqsave(&he_dev->global_lock, flags);
  2353. reg = he_readl(he_dev, FRAMER + (addr*4));
  2354. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  2355. HPRINTK("phy_get(addr 0x%lx) =0x%x\n", addr, reg);
  2356. return reg;
  2357. }
  2358. static int
  2359. he_proc_read(struct atm_dev *dev, loff_t *pos, char *page)
  2360. {
  2361. unsigned long flags;
  2362. struct he_dev *he_dev = HE_DEV(dev);
  2363. int left, i;
  2364. #ifdef notdef
  2365. struct he_rbrq *rbrq_tail;
  2366. struct he_tpdrq *tpdrq_head;
  2367. int rbpl_head, rbpl_tail;
  2368. #endif
  2369. static long mcc = 0, oec = 0, dcc = 0, cec = 0;
  2370. left = *pos;
  2371. if (!left--)
  2372. return sprintf(page, "%s\n", version);
  2373. if (!left--)
  2374. return sprintf(page, "%s%s\n\n",
  2375. he_dev->prod_id, he_dev->media & 0x40 ? "SM" : "MM");
  2376. if (!left--)
  2377. return sprintf(page, "Mismatched Cells VPI/VCI Not Open Dropped Cells RCM Dropped Cells\n");
  2378. spin_lock_irqsave(&he_dev->global_lock, flags);
  2379. mcc += he_readl(he_dev, MCC);
  2380. oec += he_readl(he_dev, OEC);
  2381. dcc += he_readl(he_dev, DCC);
  2382. cec += he_readl(he_dev, CEC);
  2383. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  2384. if (!left--)
  2385. return sprintf(page, "%16ld %16ld %13ld %17ld\n\n",
  2386. mcc, oec, dcc, cec);
  2387. if (!left--)
  2388. return sprintf(page, "irq_size = %d inuse = ? peak = %d\n",
  2389. CONFIG_IRQ_SIZE, he_dev->irq_peak);
  2390. if (!left--)
  2391. return sprintf(page, "tpdrq_size = %d inuse = ?\n",
  2392. CONFIG_TPDRQ_SIZE);
  2393. if (!left--)
  2394. return sprintf(page, "rbrq_size = %d inuse = ? peak = %d\n",
  2395. CONFIG_RBRQ_SIZE, he_dev->rbrq_peak);
  2396. if (!left--)
  2397. return sprintf(page, "tbrq_size = %d peak = %d\n",
  2398. CONFIG_TBRQ_SIZE, he_dev->tbrq_peak);
  2399. #ifdef notdef
  2400. rbpl_head = RBPL_MASK(he_readl(he_dev, G0_RBPL_S));
  2401. rbpl_tail = RBPL_MASK(he_readl(he_dev, G0_RBPL_T));
  2402. inuse = rbpl_head - rbpl_tail;
  2403. if (inuse < 0)
  2404. inuse += CONFIG_RBPL_SIZE * sizeof(struct he_rbp);
  2405. inuse /= sizeof(struct he_rbp);
  2406. if (!left--)
  2407. return sprintf(page, "rbpl_size = %d inuse = %d\n\n",
  2408. CONFIG_RBPL_SIZE, inuse);
  2409. #endif
  2410. if (!left--)
  2411. return sprintf(page, "rate controller periods (cbr)\n pcr #vc\n");
  2412. for (i = 0; i < HE_NUM_CS_STPER; ++i)
  2413. if (!left--)
  2414. return sprintf(page, "cs_stper%-2d %8ld %3d\n", i,
  2415. he_dev->cs_stper[i].pcr,
  2416. he_dev->cs_stper[i].inuse);
  2417. if (!left--)
  2418. return sprintf(page, "total bw (cbr): %d (limit %d)\n",
  2419. he_dev->total_bw, he_dev->atm_dev->link_rate * 10 / 9);
  2420. return 0;
  2421. }
  2422. /* eeprom routines -- see 4.7 */
  2423. u8
  2424. read_prom_byte(struct he_dev *he_dev, int addr)
  2425. {
  2426. u32 val = 0, tmp_read = 0;
  2427. int i, j = 0;
  2428. u8 byte_read = 0;
  2429. val = readl(he_dev->membase + HOST_CNTL);
  2430. val &= 0xFFFFE0FF;
  2431. /* Turn on write enable */
  2432. val |= 0x800;
  2433. he_writel(he_dev, val, HOST_CNTL);
  2434. /* Send READ instruction */
  2435. for (i = 0; i < sizeof(readtab)/sizeof(readtab[0]); i++) {
  2436. he_writel(he_dev, val | readtab[i], HOST_CNTL);
  2437. udelay(EEPROM_DELAY);
  2438. }
  2439. /* Next, we need to send the byte address to read from */
  2440. for (i = 7; i >= 0; i--) {
  2441. he_writel(he_dev, val | clocktab[j++] | (((addr >> i) & 1) << 9), HOST_CNTL);
  2442. udelay(EEPROM_DELAY);
  2443. he_writel(he_dev, val | clocktab[j++] | (((addr >> i) & 1) << 9), HOST_CNTL);
  2444. udelay(EEPROM_DELAY);
  2445. }
  2446. j = 0;
  2447. val &= 0xFFFFF7FF; /* Turn off write enable */
  2448. he_writel(he_dev, val, HOST_CNTL);
  2449. /* Now, we can read data from the EEPROM by clocking it in */
  2450. for (i = 7; i >= 0; i--) {
  2451. he_writel(he_dev, val | clocktab[j++], HOST_CNTL);
  2452. udelay(EEPROM_DELAY);
  2453. tmp_read = he_readl(he_dev, HOST_CNTL);
  2454. byte_read |= (unsigned char)
  2455. ((tmp_read & ID_DOUT) >> ID_DOFFSET << i);
  2456. he_writel(he_dev, val | clocktab[j++], HOST_CNTL);
  2457. udelay(EEPROM_DELAY);
  2458. }
  2459. he_writel(he_dev, val | ID_CS, HOST_CNTL);
  2460. udelay(EEPROM_DELAY);
  2461. return byte_read;
  2462. }
  2463. MODULE_LICENSE("GPL");
  2464. MODULE_AUTHOR("chas williams <chas@cmf.nrl.navy.mil>");
  2465. MODULE_DESCRIPTION("ForeRunnerHE ATM Adapter driver");
  2466. module_param(disable64, bool, 0);
  2467. MODULE_PARM_DESC(disable64, "disable 64-bit pci bus transfers");
  2468. module_param(nvpibits, short, 0);
  2469. MODULE_PARM_DESC(nvpibits, "numbers of bits for vpi (default 0)");
  2470. module_param(nvcibits, short, 0);
  2471. MODULE_PARM_DESC(nvcibits, "numbers of bits for vci (default 12)");
  2472. module_param(rx_skb_reserve, short, 0);
  2473. MODULE_PARM_DESC(rx_skb_reserve, "padding for receive skb (default 16)");
  2474. module_param(irq_coalesce, bool, 0);
  2475. MODULE_PARM_DESC(irq_coalesce, "use interrupt coalescing (default 1)");
  2476. module_param(sdh, bool, 0);
  2477. MODULE_PARM_DESC(sdh, "use SDH framing (default 0)");
  2478. static struct pci_device_id he_pci_tbl[] = {
  2479. { PCI_VENDOR_ID_FORE, PCI_DEVICE_ID_FORE_HE, PCI_ANY_ID, PCI_ANY_ID,
  2480. 0, 0, 0 },
  2481. { 0, }
  2482. };
  2483. MODULE_DEVICE_TABLE(pci, he_pci_tbl);
  2484. static struct pci_driver he_driver = {
  2485. .name = "he",
  2486. .probe = he_init_one,
  2487. .remove = __devexit_p(he_remove_one),
  2488. .id_table = he_pci_tbl,
  2489. };
  2490. static int __init he_init(void)
  2491. {
  2492. return pci_register_driver(&he_driver);
  2493. }
  2494. static void __exit he_cleanup(void)
  2495. {
  2496. pci_unregister_driver(&he_driver);
  2497. }
  2498. module_init(he_init);
  2499. module_exit(he_cleanup);