fore200e.c 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207
  1. /*
  2. $Id: fore200e.c,v 1.5 2000/04/14 10:10:34 davem Exp $
  3. A FORE Systems 200E-series driver for ATM on Linux.
  4. Christophe Lizzi (lizzi@cnam.fr), October 1999-March 2003.
  5. Based on the PCA-200E driver from Uwe Dannowski (Uwe.Dannowski@inf.tu-dresden.de).
  6. This driver simultaneously supports PCA-200E and SBA-200E adapters
  7. on i386, alpha (untested), powerpc, sparc and sparc64 architectures.
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/slab.h>
  22. #include <linux/init.h>
  23. #include <linux/capability.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/bitops.h>
  26. #include <linux/pci.h>
  27. #include <linux/module.h>
  28. #include <linux/atmdev.h>
  29. #include <linux/sonet.h>
  30. #include <linux/atm_suni.h>
  31. #include <linux/dma-mapping.h>
  32. #include <linux/delay.h>
  33. #include <asm/io.h>
  34. #include <asm/string.h>
  35. #include <asm/page.h>
  36. #include <asm/irq.h>
  37. #include <asm/dma.h>
  38. #include <asm/byteorder.h>
  39. #include <asm/uaccess.h>
  40. #include <asm/atomic.h>
  41. #ifdef CONFIG_ATM_FORE200E_SBA
  42. #include <asm/idprom.h>
  43. #include <asm/sbus.h>
  44. #include <asm/openprom.h>
  45. #include <asm/oplib.h>
  46. #include <asm/pgtable.h>
  47. #endif
  48. #if defined(CONFIG_ATM_FORE200E_USE_TASKLET) /* defer interrupt work to a tasklet */
  49. #define FORE200E_USE_TASKLET
  50. #endif
  51. #if 0 /* enable the debugging code of the buffer supply queues */
  52. #define FORE200E_BSQ_DEBUG
  53. #endif
  54. #if 1 /* ensure correct handling of 52-byte AAL0 SDUs expected by atmdump-like apps */
  55. #define FORE200E_52BYTE_AAL0_SDU
  56. #endif
  57. #include "fore200e.h"
  58. #include "suni.h"
  59. #define FORE200E_VERSION "0.3e"
  60. #define FORE200E "fore200e: "
  61. #if 0 /* override .config */
  62. #define CONFIG_ATM_FORE200E_DEBUG 1
  63. #endif
  64. #if defined(CONFIG_ATM_FORE200E_DEBUG) && (CONFIG_ATM_FORE200E_DEBUG > 0)
  65. #define DPRINTK(level, format, args...) do { if (CONFIG_ATM_FORE200E_DEBUG >= (level)) \
  66. printk(FORE200E format, ##args); } while (0)
  67. #else
  68. #define DPRINTK(level, format, args...) do {} while (0)
  69. #endif
  70. #define FORE200E_ALIGN(addr, alignment) \
  71. ((((unsigned long)(addr) + (alignment - 1)) & ~(alignment - 1)) - (unsigned long)(addr))
  72. #define FORE200E_DMA_INDEX(dma_addr, type, index) ((dma_addr) + (index) * sizeof(type))
  73. #define FORE200E_INDEX(virt_addr, type, index) (&((type *)(virt_addr))[ index ])
  74. #define FORE200E_NEXT_ENTRY(index, modulo) (index = ++(index) % (modulo))
  75. #if 1
  76. #define ASSERT(expr) if (!(expr)) { \
  77. printk(FORE200E "assertion failed! %s[%d]: %s\n", \
  78. __FUNCTION__, __LINE__, #expr); \
  79. panic(FORE200E "%s", __FUNCTION__); \
  80. }
  81. #else
  82. #define ASSERT(expr) do {} while (0)
  83. #endif
  84. static const struct atmdev_ops fore200e_ops;
  85. static const struct fore200e_bus fore200e_bus[];
  86. static LIST_HEAD(fore200e_boards);
  87. MODULE_AUTHOR("Christophe Lizzi - credits to Uwe Dannowski and Heikki Vatiainen");
  88. MODULE_DESCRIPTION("FORE Systems 200E-series ATM driver - version " FORE200E_VERSION);
  89. MODULE_SUPPORTED_DEVICE("PCA-200E, SBA-200E");
  90. static const int fore200e_rx_buf_nbr[ BUFFER_SCHEME_NBR ][ BUFFER_MAGN_NBR ] = {
  91. { BUFFER_S1_NBR, BUFFER_L1_NBR },
  92. { BUFFER_S2_NBR, BUFFER_L2_NBR }
  93. };
  94. static const int fore200e_rx_buf_size[ BUFFER_SCHEME_NBR ][ BUFFER_MAGN_NBR ] = {
  95. { BUFFER_S1_SIZE, BUFFER_L1_SIZE },
  96. { BUFFER_S2_SIZE, BUFFER_L2_SIZE }
  97. };
  98. #if defined(CONFIG_ATM_FORE200E_DEBUG) && (CONFIG_ATM_FORE200E_DEBUG > 0)
  99. static const char* fore200e_traffic_class[] = { "NONE", "UBR", "CBR", "VBR", "ABR", "ANY" };
  100. #endif
  101. #if 0 /* currently unused */
  102. static int
  103. fore200e_fore2atm_aal(enum fore200e_aal aal)
  104. {
  105. switch(aal) {
  106. case FORE200E_AAL0: return ATM_AAL0;
  107. case FORE200E_AAL34: return ATM_AAL34;
  108. case FORE200E_AAL5: return ATM_AAL5;
  109. }
  110. return -EINVAL;
  111. }
  112. #endif
  113. static enum fore200e_aal
  114. fore200e_atm2fore_aal(int aal)
  115. {
  116. switch(aal) {
  117. case ATM_AAL0: return FORE200E_AAL0;
  118. case ATM_AAL34: return FORE200E_AAL34;
  119. case ATM_AAL1:
  120. case ATM_AAL2:
  121. case ATM_AAL5: return FORE200E_AAL5;
  122. }
  123. return -EINVAL;
  124. }
  125. static char*
  126. fore200e_irq_itoa(int irq)
  127. {
  128. static char str[8];
  129. sprintf(str, "%d", irq);
  130. return str;
  131. }
  132. /* allocate and align a chunk of memory intended to hold the data behing exchanged
  133. between the driver and the adapter (using streaming DVMA) */
  134. static int
  135. fore200e_chunk_alloc(struct fore200e* fore200e, struct chunk* chunk, int size, int alignment, int direction)
  136. {
  137. unsigned long offset = 0;
  138. if (alignment <= sizeof(int))
  139. alignment = 0;
  140. chunk->alloc_size = size + alignment;
  141. chunk->align_size = size;
  142. chunk->direction = direction;
  143. chunk->alloc_addr = kzalloc(chunk->alloc_size, GFP_KERNEL | GFP_DMA);
  144. if (chunk->alloc_addr == NULL)
  145. return -ENOMEM;
  146. if (alignment > 0)
  147. offset = FORE200E_ALIGN(chunk->alloc_addr, alignment);
  148. chunk->align_addr = chunk->alloc_addr + offset;
  149. chunk->dma_addr = fore200e->bus->dma_map(fore200e, chunk->align_addr, chunk->align_size, direction);
  150. return 0;
  151. }
  152. /* free a chunk of memory */
  153. static void
  154. fore200e_chunk_free(struct fore200e* fore200e, struct chunk* chunk)
  155. {
  156. fore200e->bus->dma_unmap(fore200e, chunk->dma_addr, chunk->dma_size, chunk->direction);
  157. kfree(chunk->alloc_addr);
  158. }
  159. static void
  160. fore200e_spin(int msecs)
  161. {
  162. unsigned long timeout = jiffies + msecs_to_jiffies(msecs);
  163. while (time_before(jiffies, timeout));
  164. }
  165. static int
  166. fore200e_poll(struct fore200e* fore200e, volatile u32* addr, u32 val, int msecs)
  167. {
  168. unsigned long timeout = jiffies + msecs_to_jiffies(msecs);
  169. int ok;
  170. mb();
  171. do {
  172. if ((ok = (*addr == val)) || (*addr & STATUS_ERROR))
  173. break;
  174. } while (time_before(jiffies, timeout));
  175. #if 1
  176. if (!ok) {
  177. printk(FORE200E "cmd polling failed, got status 0x%08x, expected 0x%08x\n",
  178. *addr, val);
  179. }
  180. #endif
  181. return ok;
  182. }
  183. static int
  184. fore200e_io_poll(struct fore200e* fore200e, volatile u32 __iomem *addr, u32 val, int msecs)
  185. {
  186. unsigned long timeout = jiffies + msecs_to_jiffies(msecs);
  187. int ok;
  188. do {
  189. if ((ok = (fore200e->bus->read(addr) == val)))
  190. break;
  191. } while (time_before(jiffies, timeout));
  192. #if 1
  193. if (!ok) {
  194. printk(FORE200E "I/O polling failed, got status 0x%08x, expected 0x%08x\n",
  195. fore200e->bus->read(addr), val);
  196. }
  197. #endif
  198. return ok;
  199. }
  200. static void
  201. fore200e_free_rx_buf(struct fore200e* fore200e)
  202. {
  203. int scheme, magn, nbr;
  204. struct buffer* buffer;
  205. for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
  206. for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
  207. if ((buffer = fore200e->host_bsq[ scheme ][ magn ].buffer) != NULL) {
  208. for (nbr = 0; nbr < fore200e_rx_buf_nbr[ scheme ][ magn ]; nbr++) {
  209. struct chunk* data = &buffer[ nbr ].data;
  210. if (data->alloc_addr != NULL)
  211. fore200e_chunk_free(fore200e, data);
  212. }
  213. }
  214. }
  215. }
  216. }
  217. static void
  218. fore200e_uninit_bs_queue(struct fore200e* fore200e)
  219. {
  220. int scheme, magn;
  221. for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
  222. for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
  223. struct chunk* status = &fore200e->host_bsq[ scheme ][ magn ].status;
  224. struct chunk* rbd_block = &fore200e->host_bsq[ scheme ][ magn ].rbd_block;
  225. if (status->alloc_addr)
  226. fore200e->bus->dma_chunk_free(fore200e, status);
  227. if (rbd_block->alloc_addr)
  228. fore200e->bus->dma_chunk_free(fore200e, rbd_block);
  229. }
  230. }
  231. }
  232. static int
  233. fore200e_reset(struct fore200e* fore200e, int diag)
  234. {
  235. int ok;
  236. fore200e->cp_monitor = fore200e->virt_base + FORE200E_CP_MONITOR_OFFSET;
  237. fore200e->bus->write(BSTAT_COLD_START, &fore200e->cp_monitor->bstat);
  238. fore200e->bus->reset(fore200e);
  239. if (diag) {
  240. ok = fore200e_io_poll(fore200e, &fore200e->cp_monitor->bstat, BSTAT_SELFTEST_OK, 1000);
  241. if (ok == 0) {
  242. printk(FORE200E "device %s self-test failed\n", fore200e->name);
  243. return -ENODEV;
  244. }
  245. printk(FORE200E "device %s self-test passed\n", fore200e->name);
  246. fore200e->state = FORE200E_STATE_RESET;
  247. }
  248. return 0;
  249. }
  250. static void
  251. fore200e_shutdown(struct fore200e* fore200e)
  252. {
  253. printk(FORE200E "removing device %s at 0x%lx, IRQ %s\n",
  254. fore200e->name, fore200e->phys_base,
  255. fore200e_irq_itoa(fore200e->irq));
  256. if (fore200e->state > FORE200E_STATE_RESET) {
  257. /* first, reset the board to prevent further interrupts or data transfers */
  258. fore200e_reset(fore200e, 0);
  259. }
  260. /* then, release all allocated resources */
  261. switch(fore200e->state) {
  262. case FORE200E_STATE_COMPLETE:
  263. kfree(fore200e->stats);
  264. case FORE200E_STATE_IRQ:
  265. free_irq(fore200e->irq, fore200e->atm_dev);
  266. case FORE200E_STATE_ALLOC_BUF:
  267. fore200e_free_rx_buf(fore200e);
  268. case FORE200E_STATE_INIT_BSQ:
  269. fore200e_uninit_bs_queue(fore200e);
  270. case FORE200E_STATE_INIT_RXQ:
  271. fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_rxq.status);
  272. fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_rxq.rpd);
  273. case FORE200E_STATE_INIT_TXQ:
  274. fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_txq.status);
  275. fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_txq.tpd);
  276. case FORE200E_STATE_INIT_CMDQ:
  277. fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_cmdq.status);
  278. case FORE200E_STATE_INITIALIZE:
  279. /* nothing to do for that state */
  280. case FORE200E_STATE_START_FW:
  281. /* nothing to do for that state */
  282. case FORE200E_STATE_LOAD_FW:
  283. /* nothing to do for that state */
  284. case FORE200E_STATE_RESET:
  285. /* nothing to do for that state */
  286. case FORE200E_STATE_MAP:
  287. fore200e->bus->unmap(fore200e);
  288. case FORE200E_STATE_CONFIGURE:
  289. /* nothing to do for that state */
  290. case FORE200E_STATE_REGISTER:
  291. /* XXX shouldn't we *start* by deregistering the device? */
  292. atm_dev_deregister(fore200e->atm_dev);
  293. case FORE200E_STATE_BLANK:
  294. /* nothing to do for that state */
  295. break;
  296. }
  297. }
  298. #ifdef CONFIG_ATM_FORE200E_PCA
  299. static u32 fore200e_pca_read(volatile u32 __iomem *addr)
  300. {
  301. /* on big-endian hosts, the board is configured to convert
  302. the endianess of slave RAM accesses */
  303. return le32_to_cpu(readl(addr));
  304. }
  305. static void fore200e_pca_write(u32 val, volatile u32 __iomem *addr)
  306. {
  307. /* on big-endian hosts, the board is configured to convert
  308. the endianess of slave RAM accesses */
  309. writel(cpu_to_le32(val), addr);
  310. }
  311. static u32
  312. fore200e_pca_dma_map(struct fore200e* fore200e, void* virt_addr, int size, int direction)
  313. {
  314. u32 dma_addr = pci_map_single((struct pci_dev*)fore200e->bus_dev, virt_addr, size, direction);
  315. DPRINTK(3, "PCI DVMA mapping: virt_addr = 0x%p, size = %d, direction = %d, --> dma_addr = 0x%08x\n",
  316. virt_addr, size, direction, dma_addr);
  317. return dma_addr;
  318. }
  319. static void
  320. fore200e_pca_dma_unmap(struct fore200e* fore200e, u32 dma_addr, int size, int direction)
  321. {
  322. DPRINTK(3, "PCI DVMA unmapping: dma_addr = 0x%08x, size = %d, direction = %d\n",
  323. dma_addr, size, direction);
  324. pci_unmap_single((struct pci_dev*)fore200e->bus_dev, dma_addr, size, direction);
  325. }
  326. static void
  327. fore200e_pca_dma_sync_for_cpu(struct fore200e* fore200e, u32 dma_addr, int size, int direction)
  328. {
  329. DPRINTK(3, "PCI DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr, size, direction);
  330. pci_dma_sync_single_for_cpu((struct pci_dev*)fore200e->bus_dev, dma_addr, size, direction);
  331. }
  332. static void
  333. fore200e_pca_dma_sync_for_device(struct fore200e* fore200e, u32 dma_addr, int size, int direction)
  334. {
  335. DPRINTK(3, "PCI DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr, size, direction);
  336. pci_dma_sync_single_for_device((struct pci_dev*)fore200e->bus_dev, dma_addr, size, direction);
  337. }
  338. /* allocate a DMA consistent chunk of memory intended to act as a communication mechanism
  339. (to hold descriptors, status, queues, etc.) shared by the driver and the adapter */
  340. static int
  341. fore200e_pca_dma_chunk_alloc(struct fore200e* fore200e, struct chunk* chunk,
  342. int size, int nbr, int alignment)
  343. {
  344. /* returned chunks are page-aligned */
  345. chunk->alloc_size = size * nbr;
  346. chunk->alloc_addr = pci_alloc_consistent((struct pci_dev*)fore200e->bus_dev,
  347. chunk->alloc_size,
  348. &chunk->dma_addr);
  349. if ((chunk->alloc_addr == NULL) || (chunk->dma_addr == 0))
  350. return -ENOMEM;
  351. chunk->align_addr = chunk->alloc_addr;
  352. return 0;
  353. }
  354. /* free a DMA consistent chunk of memory */
  355. static void
  356. fore200e_pca_dma_chunk_free(struct fore200e* fore200e, struct chunk* chunk)
  357. {
  358. pci_free_consistent((struct pci_dev*)fore200e->bus_dev,
  359. chunk->alloc_size,
  360. chunk->alloc_addr,
  361. chunk->dma_addr);
  362. }
  363. static int
  364. fore200e_pca_irq_check(struct fore200e* fore200e)
  365. {
  366. /* this is a 1 bit register */
  367. int irq_posted = readl(fore200e->regs.pca.psr);
  368. #if defined(CONFIG_ATM_FORE200E_DEBUG) && (CONFIG_ATM_FORE200E_DEBUG == 2)
  369. if (irq_posted && (readl(fore200e->regs.pca.hcr) & PCA200E_HCR_OUTFULL)) {
  370. DPRINTK(2,"FIFO OUT full, device %d\n", fore200e->atm_dev->number);
  371. }
  372. #endif
  373. return irq_posted;
  374. }
  375. static void
  376. fore200e_pca_irq_ack(struct fore200e* fore200e)
  377. {
  378. writel(PCA200E_HCR_CLRINTR, fore200e->regs.pca.hcr);
  379. }
  380. static void
  381. fore200e_pca_reset(struct fore200e* fore200e)
  382. {
  383. writel(PCA200E_HCR_RESET, fore200e->regs.pca.hcr);
  384. fore200e_spin(10);
  385. writel(0, fore200e->regs.pca.hcr);
  386. }
  387. static int __devinit
  388. fore200e_pca_map(struct fore200e* fore200e)
  389. {
  390. DPRINTK(2, "device %s being mapped in memory\n", fore200e->name);
  391. fore200e->virt_base = ioremap(fore200e->phys_base, PCA200E_IOSPACE_LENGTH);
  392. if (fore200e->virt_base == NULL) {
  393. printk(FORE200E "can't map device %s\n", fore200e->name);
  394. return -EFAULT;
  395. }
  396. DPRINTK(1, "device %s mapped to 0x%p\n", fore200e->name, fore200e->virt_base);
  397. /* gain access to the PCA specific registers */
  398. fore200e->regs.pca.hcr = fore200e->virt_base + PCA200E_HCR_OFFSET;
  399. fore200e->regs.pca.imr = fore200e->virt_base + PCA200E_IMR_OFFSET;
  400. fore200e->regs.pca.psr = fore200e->virt_base + PCA200E_PSR_OFFSET;
  401. fore200e->state = FORE200E_STATE_MAP;
  402. return 0;
  403. }
  404. static void
  405. fore200e_pca_unmap(struct fore200e* fore200e)
  406. {
  407. DPRINTK(2, "device %s being unmapped from memory\n", fore200e->name);
  408. if (fore200e->virt_base != NULL)
  409. iounmap(fore200e->virt_base);
  410. }
  411. static int __devinit
  412. fore200e_pca_configure(struct fore200e* fore200e)
  413. {
  414. struct pci_dev* pci_dev = (struct pci_dev*)fore200e->bus_dev;
  415. u8 master_ctrl, latency;
  416. DPRINTK(2, "device %s being configured\n", fore200e->name);
  417. if ((pci_dev->irq == 0) || (pci_dev->irq == 0xFF)) {
  418. printk(FORE200E "incorrect IRQ setting - misconfigured PCI-PCI bridge?\n");
  419. return -EIO;
  420. }
  421. pci_read_config_byte(pci_dev, PCA200E_PCI_MASTER_CTRL, &master_ctrl);
  422. master_ctrl = master_ctrl
  423. #if defined(__BIG_ENDIAN)
  424. /* request the PCA board to convert the endianess of slave RAM accesses */
  425. | PCA200E_CTRL_CONVERT_ENDIAN
  426. #endif
  427. #if 0
  428. | PCA200E_CTRL_DIS_CACHE_RD
  429. | PCA200E_CTRL_DIS_WRT_INVAL
  430. | PCA200E_CTRL_ENA_CONT_REQ_MODE
  431. | PCA200E_CTRL_2_CACHE_WRT_INVAL
  432. #endif
  433. | PCA200E_CTRL_LARGE_PCI_BURSTS;
  434. pci_write_config_byte(pci_dev, PCA200E_PCI_MASTER_CTRL, master_ctrl);
  435. /* raise latency from 32 (default) to 192, as this seems to prevent NIC
  436. lockups (under heavy rx loads) due to continuous 'FIFO OUT full' condition.
  437. this may impact the performances of other PCI devices on the same bus, though */
  438. latency = 192;
  439. pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, latency);
  440. fore200e->state = FORE200E_STATE_CONFIGURE;
  441. return 0;
  442. }
  443. static int __init
  444. fore200e_pca_prom_read(struct fore200e* fore200e, struct prom_data* prom)
  445. {
  446. struct host_cmdq* cmdq = &fore200e->host_cmdq;
  447. struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
  448. struct prom_opcode opcode;
  449. int ok;
  450. u32 prom_dma;
  451. FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
  452. opcode.opcode = OPCODE_GET_PROM;
  453. opcode.pad = 0;
  454. prom_dma = fore200e->bus->dma_map(fore200e, prom, sizeof(struct prom_data), DMA_FROM_DEVICE);
  455. fore200e->bus->write(prom_dma, &entry->cp_entry->cmd.prom_block.prom_haddr);
  456. *entry->status = STATUS_PENDING;
  457. fore200e->bus->write(*(u32*)&opcode, (u32 __iomem *)&entry->cp_entry->cmd.prom_block.opcode);
  458. ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
  459. *entry->status = STATUS_FREE;
  460. fore200e->bus->dma_unmap(fore200e, prom_dma, sizeof(struct prom_data), DMA_FROM_DEVICE);
  461. if (ok == 0) {
  462. printk(FORE200E "unable to get PROM data from device %s\n", fore200e->name);
  463. return -EIO;
  464. }
  465. #if defined(__BIG_ENDIAN)
  466. #define swap_here(addr) (*((u32*)(addr)) = swab32( *((u32*)(addr)) ))
  467. /* MAC address is stored as little-endian */
  468. swap_here(&prom->mac_addr[0]);
  469. swap_here(&prom->mac_addr[4]);
  470. #endif
  471. return 0;
  472. }
  473. static int
  474. fore200e_pca_proc_read(struct fore200e* fore200e, char *page)
  475. {
  476. struct pci_dev* pci_dev = (struct pci_dev*)fore200e->bus_dev;
  477. return sprintf(page, " PCI bus/slot/function:\t%d/%d/%d\n",
  478. pci_dev->bus->number, PCI_SLOT(pci_dev->devfn), PCI_FUNC(pci_dev->devfn));
  479. }
  480. #endif /* CONFIG_ATM_FORE200E_PCA */
  481. #ifdef CONFIG_ATM_FORE200E_SBA
  482. static u32
  483. fore200e_sba_read(volatile u32 __iomem *addr)
  484. {
  485. return sbus_readl(addr);
  486. }
  487. static void
  488. fore200e_sba_write(u32 val, volatile u32 __iomem *addr)
  489. {
  490. sbus_writel(val, addr);
  491. }
  492. static u32
  493. fore200e_sba_dma_map(struct fore200e* fore200e, void* virt_addr, int size, int direction)
  494. {
  495. u32 dma_addr = sbus_map_single((struct sbus_dev*)fore200e->bus_dev, virt_addr, size, direction);
  496. DPRINTK(3, "SBUS DVMA mapping: virt_addr = 0x%p, size = %d, direction = %d --> dma_addr = 0x%08x\n",
  497. virt_addr, size, direction, dma_addr);
  498. return dma_addr;
  499. }
  500. static void
  501. fore200e_sba_dma_unmap(struct fore200e* fore200e, u32 dma_addr, int size, int direction)
  502. {
  503. DPRINTK(3, "SBUS DVMA unmapping: dma_addr = 0x%08x, size = %d, direction = %d,\n",
  504. dma_addr, size, direction);
  505. sbus_unmap_single((struct sbus_dev*)fore200e->bus_dev, dma_addr, size, direction);
  506. }
  507. static void
  508. fore200e_sba_dma_sync_for_cpu(struct fore200e* fore200e, u32 dma_addr, int size, int direction)
  509. {
  510. DPRINTK(3, "SBUS DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr, size, direction);
  511. sbus_dma_sync_single_for_cpu((struct sbus_dev*)fore200e->bus_dev, dma_addr, size, direction);
  512. }
  513. static void
  514. fore200e_sba_dma_sync_for_device(struct fore200e* fore200e, u32 dma_addr, int size, int direction)
  515. {
  516. DPRINTK(3, "SBUS DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr, size, direction);
  517. sbus_dma_sync_single_for_device((struct sbus_dev*)fore200e->bus_dev, dma_addr, size, direction);
  518. }
  519. /* allocate a DVMA consistent chunk of memory intended to act as a communication mechanism
  520. (to hold descriptors, status, queues, etc.) shared by the driver and the adapter */
  521. static int
  522. fore200e_sba_dma_chunk_alloc(struct fore200e* fore200e, struct chunk* chunk,
  523. int size, int nbr, int alignment)
  524. {
  525. chunk->alloc_size = chunk->align_size = size * nbr;
  526. /* returned chunks are page-aligned */
  527. chunk->alloc_addr = sbus_alloc_consistent((struct sbus_dev*)fore200e->bus_dev,
  528. chunk->alloc_size,
  529. &chunk->dma_addr);
  530. if ((chunk->alloc_addr == NULL) || (chunk->dma_addr == 0))
  531. return -ENOMEM;
  532. chunk->align_addr = chunk->alloc_addr;
  533. return 0;
  534. }
  535. /* free a DVMA consistent chunk of memory */
  536. static void
  537. fore200e_sba_dma_chunk_free(struct fore200e* fore200e, struct chunk* chunk)
  538. {
  539. sbus_free_consistent((struct sbus_dev*)fore200e->bus_dev,
  540. chunk->alloc_size,
  541. chunk->alloc_addr,
  542. chunk->dma_addr);
  543. }
  544. static void
  545. fore200e_sba_irq_enable(struct fore200e* fore200e)
  546. {
  547. u32 hcr = fore200e->bus->read(fore200e->regs.sba.hcr) & SBA200E_HCR_STICKY;
  548. fore200e->bus->write(hcr | SBA200E_HCR_INTR_ENA, fore200e->regs.sba.hcr);
  549. }
  550. static int
  551. fore200e_sba_irq_check(struct fore200e* fore200e)
  552. {
  553. return fore200e->bus->read(fore200e->regs.sba.hcr) & SBA200E_HCR_INTR_REQ;
  554. }
  555. static void
  556. fore200e_sba_irq_ack(struct fore200e* fore200e)
  557. {
  558. u32 hcr = fore200e->bus->read(fore200e->regs.sba.hcr) & SBA200E_HCR_STICKY;
  559. fore200e->bus->write(hcr | SBA200E_HCR_INTR_CLR, fore200e->regs.sba.hcr);
  560. }
  561. static void
  562. fore200e_sba_reset(struct fore200e* fore200e)
  563. {
  564. fore200e->bus->write(SBA200E_HCR_RESET, fore200e->regs.sba.hcr);
  565. fore200e_spin(10);
  566. fore200e->bus->write(0, fore200e->regs.sba.hcr);
  567. }
  568. static int __init
  569. fore200e_sba_map(struct fore200e* fore200e)
  570. {
  571. struct sbus_dev* sbus_dev = (struct sbus_dev*)fore200e->bus_dev;
  572. unsigned int bursts;
  573. /* gain access to the SBA specific registers */
  574. fore200e->regs.sba.hcr = sbus_ioremap(&sbus_dev->resource[0], 0, SBA200E_HCR_LENGTH, "SBA HCR");
  575. fore200e->regs.sba.bsr = sbus_ioremap(&sbus_dev->resource[1], 0, SBA200E_BSR_LENGTH, "SBA BSR");
  576. fore200e->regs.sba.isr = sbus_ioremap(&sbus_dev->resource[2], 0, SBA200E_ISR_LENGTH, "SBA ISR");
  577. fore200e->virt_base = sbus_ioremap(&sbus_dev->resource[3], 0, SBA200E_RAM_LENGTH, "SBA RAM");
  578. if (fore200e->virt_base == NULL) {
  579. printk(FORE200E "unable to map RAM of device %s\n", fore200e->name);
  580. return -EFAULT;
  581. }
  582. DPRINTK(1, "device %s mapped to 0x%p\n", fore200e->name, fore200e->virt_base);
  583. fore200e->bus->write(0x02, fore200e->regs.sba.isr); /* XXX hardwired interrupt level */
  584. /* get the supported DVMA burst sizes */
  585. bursts = prom_getintdefault(sbus_dev->bus->prom_node, "burst-sizes", 0x00);
  586. if (sbus_can_dma_64bit(sbus_dev))
  587. sbus_set_sbus64(sbus_dev, bursts);
  588. fore200e->state = FORE200E_STATE_MAP;
  589. return 0;
  590. }
  591. static void
  592. fore200e_sba_unmap(struct fore200e* fore200e)
  593. {
  594. sbus_iounmap(fore200e->regs.sba.hcr, SBA200E_HCR_LENGTH);
  595. sbus_iounmap(fore200e->regs.sba.bsr, SBA200E_BSR_LENGTH);
  596. sbus_iounmap(fore200e->regs.sba.isr, SBA200E_ISR_LENGTH);
  597. sbus_iounmap(fore200e->virt_base, SBA200E_RAM_LENGTH);
  598. }
  599. static int __init
  600. fore200e_sba_configure(struct fore200e* fore200e)
  601. {
  602. fore200e->state = FORE200E_STATE_CONFIGURE;
  603. return 0;
  604. }
  605. static struct fore200e* __init
  606. fore200e_sba_detect(const struct fore200e_bus* bus, int index)
  607. {
  608. struct fore200e* fore200e;
  609. struct sbus_bus* sbus_bus;
  610. struct sbus_dev* sbus_dev = NULL;
  611. unsigned int count = 0;
  612. for_each_sbus (sbus_bus) {
  613. for_each_sbusdev (sbus_dev, sbus_bus) {
  614. if (strcmp(sbus_dev->prom_name, SBA200E_PROM_NAME) == 0) {
  615. if (count >= index)
  616. goto found;
  617. count++;
  618. }
  619. }
  620. }
  621. return NULL;
  622. found:
  623. if (sbus_dev->num_registers != 4) {
  624. printk(FORE200E "this %s device has %d instead of 4 registers\n",
  625. bus->model_name, sbus_dev->num_registers);
  626. return NULL;
  627. }
  628. fore200e = kzalloc(sizeof(struct fore200e), GFP_KERNEL);
  629. if (fore200e == NULL)
  630. return NULL;
  631. fore200e->bus = bus;
  632. fore200e->bus_dev = sbus_dev;
  633. fore200e->irq = sbus_dev->irqs[ 0 ];
  634. fore200e->phys_base = (unsigned long)sbus_dev;
  635. sprintf(fore200e->name, "%s-%d", bus->model_name, index - 1);
  636. return fore200e;
  637. }
  638. static int __init
  639. fore200e_sba_prom_read(struct fore200e* fore200e, struct prom_data* prom)
  640. {
  641. struct sbus_dev* sbus_dev = (struct sbus_dev*) fore200e->bus_dev;
  642. int len;
  643. len = prom_getproperty(sbus_dev->prom_node, "macaddrlo2", &prom->mac_addr[ 4 ], 4);
  644. if (len < 0)
  645. return -EBUSY;
  646. len = prom_getproperty(sbus_dev->prom_node, "macaddrhi4", &prom->mac_addr[ 2 ], 4);
  647. if (len < 0)
  648. return -EBUSY;
  649. prom_getproperty(sbus_dev->prom_node, "serialnumber",
  650. (char*)&prom->serial_number, sizeof(prom->serial_number));
  651. prom_getproperty(sbus_dev->prom_node, "promversion",
  652. (char*)&prom->hw_revision, sizeof(prom->hw_revision));
  653. return 0;
  654. }
  655. static int
  656. fore200e_sba_proc_read(struct fore200e* fore200e, char *page)
  657. {
  658. struct sbus_dev* sbus_dev = (struct sbus_dev*)fore200e->bus_dev;
  659. return sprintf(page, " SBUS slot/device:\t\t%d/'%s'\n", sbus_dev->slot, sbus_dev->prom_name);
  660. }
  661. #endif /* CONFIG_ATM_FORE200E_SBA */
  662. static void
  663. fore200e_tx_irq(struct fore200e* fore200e)
  664. {
  665. struct host_txq* txq = &fore200e->host_txq;
  666. struct host_txq_entry* entry;
  667. struct atm_vcc* vcc;
  668. struct fore200e_vc_map* vc_map;
  669. if (fore200e->host_txq.txing == 0)
  670. return;
  671. for (;;) {
  672. entry = &txq->host_entry[ txq->tail ];
  673. if ((*entry->status & STATUS_COMPLETE) == 0) {
  674. break;
  675. }
  676. DPRINTK(3, "TX COMPLETED: entry = %p [tail = %d], vc_map = %p, skb = %p\n",
  677. entry, txq->tail, entry->vc_map, entry->skb);
  678. /* free copy of misaligned data */
  679. kfree(entry->data);
  680. /* remove DMA mapping */
  681. fore200e->bus->dma_unmap(fore200e, entry->tpd->tsd[ 0 ].buffer, entry->tpd->tsd[ 0 ].length,
  682. DMA_TO_DEVICE);
  683. vc_map = entry->vc_map;
  684. /* vcc closed since the time the entry was submitted for tx? */
  685. if ((vc_map->vcc == NULL) ||
  686. (test_bit(ATM_VF_READY, &vc_map->vcc->flags) == 0)) {
  687. DPRINTK(1, "no ready vcc found for PDU sent on device %d\n",
  688. fore200e->atm_dev->number);
  689. dev_kfree_skb_any(entry->skb);
  690. }
  691. else {
  692. ASSERT(vc_map->vcc);
  693. /* vcc closed then immediately re-opened? */
  694. if (vc_map->incarn != entry->incarn) {
  695. /* when a vcc is closed, some PDUs may be still pending in the tx queue.
  696. if the same vcc is immediately re-opened, those pending PDUs must
  697. not be popped after the completion of their emission, as they refer
  698. to the prior incarnation of that vcc. otherwise, sk_atm(vcc)->sk_wmem_alloc
  699. would be decremented by the size of the (unrelated) skb, possibly
  700. leading to a negative sk->sk_wmem_alloc count, ultimately freezing the vcc.
  701. we thus bind the tx entry to the current incarnation of the vcc
  702. when the entry is submitted for tx. When the tx later completes,
  703. if the incarnation number of the tx entry does not match the one
  704. of the vcc, then this implies that the vcc has been closed then re-opened.
  705. we thus just drop the skb here. */
  706. DPRINTK(1, "vcc closed-then-re-opened; dropping PDU sent on device %d\n",
  707. fore200e->atm_dev->number);
  708. dev_kfree_skb_any(entry->skb);
  709. }
  710. else {
  711. vcc = vc_map->vcc;
  712. ASSERT(vcc);
  713. /* notify tx completion */
  714. if (vcc->pop) {
  715. vcc->pop(vcc, entry->skb);
  716. }
  717. else {
  718. dev_kfree_skb_any(entry->skb);
  719. }
  720. #if 1
  721. /* race fixed by the above incarnation mechanism, but... */
  722. if (atomic_read(&sk_atm(vcc)->sk_wmem_alloc) < 0) {
  723. atomic_set(&sk_atm(vcc)->sk_wmem_alloc, 0);
  724. }
  725. #endif
  726. /* check error condition */
  727. if (*entry->status & STATUS_ERROR)
  728. atomic_inc(&vcc->stats->tx_err);
  729. else
  730. atomic_inc(&vcc->stats->tx);
  731. }
  732. }
  733. *entry->status = STATUS_FREE;
  734. fore200e->host_txq.txing--;
  735. FORE200E_NEXT_ENTRY(txq->tail, QUEUE_SIZE_TX);
  736. }
  737. }
  738. #ifdef FORE200E_BSQ_DEBUG
  739. int bsq_audit(int where, struct host_bsq* bsq, int scheme, int magn)
  740. {
  741. struct buffer* buffer;
  742. int count = 0;
  743. buffer = bsq->freebuf;
  744. while (buffer) {
  745. if (buffer->supplied) {
  746. printk(FORE200E "bsq_audit(%d): queue %d.%d, buffer %ld supplied but in free list!\n",
  747. where, scheme, magn, buffer->index);
  748. }
  749. if (buffer->magn != magn) {
  750. printk(FORE200E "bsq_audit(%d): queue %d.%d, buffer %ld, unexpected magn = %d\n",
  751. where, scheme, magn, buffer->index, buffer->magn);
  752. }
  753. if (buffer->scheme != scheme) {
  754. printk(FORE200E "bsq_audit(%d): queue %d.%d, buffer %ld, unexpected scheme = %d\n",
  755. where, scheme, magn, buffer->index, buffer->scheme);
  756. }
  757. if ((buffer->index < 0) || (buffer->index >= fore200e_rx_buf_nbr[ scheme ][ magn ])) {
  758. printk(FORE200E "bsq_audit(%d): queue %d.%d, out of range buffer index = %ld !\n",
  759. where, scheme, magn, buffer->index);
  760. }
  761. count++;
  762. buffer = buffer->next;
  763. }
  764. if (count != bsq->freebuf_count) {
  765. printk(FORE200E "bsq_audit(%d): queue %d.%d, %d bufs in free list, but freebuf_count = %d\n",
  766. where, scheme, magn, count, bsq->freebuf_count);
  767. }
  768. return 0;
  769. }
  770. #endif
  771. static void
  772. fore200e_supply(struct fore200e* fore200e)
  773. {
  774. int scheme, magn, i;
  775. struct host_bsq* bsq;
  776. struct host_bsq_entry* entry;
  777. struct buffer* buffer;
  778. for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
  779. for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
  780. bsq = &fore200e->host_bsq[ scheme ][ magn ];
  781. #ifdef FORE200E_BSQ_DEBUG
  782. bsq_audit(1, bsq, scheme, magn);
  783. #endif
  784. while (bsq->freebuf_count >= RBD_BLK_SIZE) {
  785. DPRINTK(2, "supplying %d rx buffers to queue %d / %d, freebuf_count = %d\n",
  786. RBD_BLK_SIZE, scheme, magn, bsq->freebuf_count);
  787. entry = &bsq->host_entry[ bsq->head ];
  788. for (i = 0; i < RBD_BLK_SIZE; i++) {
  789. /* take the first buffer in the free buffer list */
  790. buffer = bsq->freebuf;
  791. if (!buffer) {
  792. printk(FORE200E "no more free bufs in queue %d.%d, but freebuf_count = %d\n",
  793. scheme, magn, bsq->freebuf_count);
  794. return;
  795. }
  796. bsq->freebuf = buffer->next;
  797. #ifdef FORE200E_BSQ_DEBUG
  798. if (buffer->supplied)
  799. printk(FORE200E "queue %d.%d, buffer %lu already supplied\n",
  800. scheme, magn, buffer->index);
  801. buffer->supplied = 1;
  802. #endif
  803. entry->rbd_block->rbd[ i ].buffer_haddr = buffer->data.dma_addr;
  804. entry->rbd_block->rbd[ i ].handle = FORE200E_BUF2HDL(buffer);
  805. }
  806. FORE200E_NEXT_ENTRY(bsq->head, QUEUE_SIZE_BS);
  807. /* decrease accordingly the number of free rx buffers */
  808. bsq->freebuf_count -= RBD_BLK_SIZE;
  809. *entry->status = STATUS_PENDING;
  810. fore200e->bus->write(entry->rbd_block_dma, &entry->cp_entry->rbd_block_haddr);
  811. }
  812. }
  813. }
  814. }
  815. static int
  816. fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rpd)
  817. {
  818. struct sk_buff* skb;
  819. struct buffer* buffer;
  820. struct fore200e_vcc* fore200e_vcc;
  821. int i, pdu_len = 0;
  822. #ifdef FORE200E_52BYTE_AAL0_SDU
  823. u32 cell_header = 0;
  824. #endif
  825. ASSERT(vcc);
  826. fore200e_vcc = FORE200E_VCC(vcc);
  827. ASSERT(fore200e_vcc);
  828. #ifdef FORE200E_52BYTE_AAL0_SDU
  829. if ((vcc->qos.aal == ATM_AAL0) && (vcc->qos.rxtp.max_sdu == ATM_AAL0_SDU)) {
  830. cell_header = (rpd->atm_header.gfc << ATM_HDR_GFC_SHIFT) |
  831. (rpd->atm_header.vpi << ATM_HDR_VPI_SHIFT) |
  832. (rpd->atm_header.vci << ATM_HDR_VCI_SHIFT) |
  833. (rpd->atm_header.plt << ATM_HDR_PTI_SHIFT) |
  834. rpd->atm_header.clp;
  835. pdu_len = 4;
  836. }
  837. #endif
  838. /* compute total PDU length */
  839. for (i = 0; i < rpd->nseg; i++)
  840. pdu_len += rpd->rsd[ i ].length;
  841. skb = alloc_skb(pdu_len, GFP_ATOMIC);
  842. if (skb == NULL) {
  843. DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
  844. atomic_inc(&vcc->stats->rx_drop);
  845. return -ENOMEM;
  846. }
  847. __net_timestamp(skb);
  848. #ifdef FORE200E_52BYTE_AAL0_SDU
  849. if (cell_header) {
  850. *((u32*)skb_put(skb, 4)) = cell_header;
  851. }
  852. #endif
  853. /* reassemble segments */
  854. for (i = 0; i < rpd->nseg; i++) {
  855. /* rebuild rx buffer address from rsd handle */
  856. buffer = FORE200E_HDL2BUF(rpd->rsd[ i ].handle);
  857. /* Make device DMA transfer visible to CPU. */
  858. fore200e->bus->dma_sync_for_cpu(fore200e, buffer->data.dma_addr, rpd->rsd[ i ].length, DMA_FROM_DEVICE);
  859. memcpy(skb_put(skb, rpd->rsd[ i ].length), buffer->data.align_addr, rpd->rsd[ i ].length);
  860. /* Now let the device get at it again. */
  861. fore200e->bus->dma_sync_for_device(fore200e, buffer->data.dma_addr, rpd->rsd[ i ].length, DMA_FROM_DEVICE);
  862. }
  863. DPRINTK(3, "rx skb: len = %d, truesize = %d\n", skb->len, skb->truesize);
  864. if (pdu_len < fore200e_vcc->rx_min_pdu)
  865. fore200e_vcc->rx_min_pdu = pdu_len;
  866. if (pdu_len > fore200e_vcc->rx_max_pdu)
  867. fore200e_vcc->rx_max_pdu = pdu_len;
  868. fore200e_vcc->rx_pdu++;
  869. /* push PDU */
  870. if (atm_charge(vcc, skb->truesize) == 0) {
  871. DPRINTK(2, "receive buffers saturated for %d.%d.%d - PDU dropped\n",
  872. vcc->itf, vcc->vpi, vcc->vci);
  873. dev_kfree_skb_any(skb);
  874. atomic_inc(&vcc->stats->rx_drop);
  875. return -ENOMEM;
  876. }
  877. ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
  878. vcc->push(vcc, skb);
  879. atomic_inc(&vcc->stats->rx);
  880. ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
  881. return 0;
  882. }
  883. static void
  884. fore200e_collect_rpd(struct fore200e* fore200e, struct rpd* rpd)
  885. {
  886. struct host_bsq* bsq;
  887. struct buffer* buffer;
  888. int i;
  889. for (i = 0; i < rpd->nseg; i++) {
  890. /* rebuild rx buffer address from rsd handle */
  891. buffer = FORE200E_HDL2BUF(rpd->rsd[ i ].handle);
  892. bsq = &fore200e->host_bsq[ buffer->scheme ][ buffer->magn ];
  893. #ifdef FORE200E_BSQ_DEBUG
  894. bsq_audit(2, bsq, buffer->scheme, buffer->magn);
  895. if (buffer->supplied == 0)
  896. printk(FORE200E "queue %d.%d, buffer %ld was not supplied\n",
  897. buffer->scheme, buffer->magn, buffer->index);
  898. buffer->supplied = 0;
  899. #endif
  900. /* re-insert the buffer into the free buffer list */
  901. buffer->next = bsq->freebuf;
  902. bsq->freebuf = buffer;
  903. /* then increment the number of free rx buffers */
  904. bsq->freebuf_count++;
  905. }
  906. }
  907. static void
  908. fore200e_rx_irq(struct fore200e* fore200e)
  909. {
  910. struct host_rxq* rxq = &fore200e->host_rxq;
  911. struct host_rxq_entry* entry;
  912. struct atm_vcc* vcc;
  913. struct fore200e_vc_map* vc_map;
  914. for (;;) {
  915. entry = &rxq->host_entry[ rxq->head ];
  916. /* no more received PDUs */
  917. if ((*entry->status & STATUS_COMPLETE) == 0)
  918. break;
  919. vc_map = FORE200E_VC_MAP(fore200e, entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
  920. if ((vc_map->vcc == NULL) ||
  921. (test_bit(ATM_VF_READY, &vc_map->vcc->flags) == 0)) {
  922. DPRINTK(1, "no ready VC found for PDU received on %d.%d.%d\n",
  923. fore200e->atm_dev->number,
  924. entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
  925. }
  926. else {
  927. vcc = vc_map->vcc;
  928. ASSERT(vcc);
  929. if ((*entry->status & STATUS_ERROR) == 0) {
  930. fore200e_push_rpd(fore200e, vcc, entry->rpd);
  931. }
  932. else {
  933. DPRINTK(2, "damaged PDU on %d.%d.%d\n",
  934. fore200e->atm_dev->number,
  935. entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
  936. atomic_inc(&vcc->stats->rx_err);
  937. }
  938. }
  939. FORE200E_NEXT_ENTRY(rxq->head, QUEUE_SIZE_RX);
  940. fore200e_collect_rpd(fore200e, entry->rpd);
  941. /* rewrite the rpd address to ack the received PDU */
  942. fore200e->bus->write(entry->rpd_dma, &entry->cp_entry->rpd_haddr);
  943. *entry->status = STATUS_FREE;
  944. fore200e_supply(fore200e);
  945. }
  946. }
  947. #ifndef FORE200E_USE_TASKLET
  948. static void
  949. fore200e_irq(struct fore200e* fore200e)
  950. {
  951. unsigned long flags;
  952. spin_lock_irqsave(&fore200e->q_lock, flags);
  953. fore200e_rx_irq(fore200e);
  954. spin_unlock_irqrestore(&fore200e->q_lock, flags);
  955. spin_lock_irqsave(&fore200e->q_lock, flags);
  956. fore200e_tx_irq(fore200e);
  957. spin_unlock_irqrestore(&fore200e->q_lock, flags);
  958. }
  959. #endif
  960. static irqreturn_t
  961. fore200e_interrupt(int irq, void* dev)
  962. {
  963. struct fore200e* fore200e = FORE200E_DEV((struct atm_dev*)dev);
  964. if (fore200e->bus->irq_check(fore200e) == 0) {
  965. DPRINTK(3, "interrupt NOT triggered by device %d\n", fore200e->atm_dev->number);
  966. return IRQ_NONE;
  967. }
  968. DPRINTK(3, "interrupt triggered by device %d\n", fore200e->atm_dev->number);
  969. #ifdef FORE200E_USE_TASKLET
  970. tasklet_schedule(&fore200e->tx_tasklet);
  971. tasklet_schedule(&fore200e->rx_tasklet);
  972. #else
  973. fore200e_irq(fore200e);
  974. #endif
  975. fore200e->bus->irq_ack(fore200e);
  976. return IRQ_HANDLED;
  977. }
  978. #ifdef FORE200E_USE_TASKLET
  979. static void
  980. fore200e_tx_tasklet(unsigned long data)
  981. {
  982. struct fore200e* fore200e = (struct fore200e*) data;
  983. unsigned long flags;
  984. DPRINTK(3, "tx tasklet scheduled for device %d\n", fore200e->atm_dev->number);
  985. spin_lock_irqsave(&fore200e->q_lock, flags);
  986. fore200e_tx_irq(fore200e);
  987. spin_unlock_irqrestore(&fore200e->q_lock, flags);
  988. }
  989. static void
  990. fore200e_rx_tasklet(unsigned long data)
  991. {
  992. struct fore200e* fore200e = (struct fore200e*) data;
  993. unsigned long flags;
  994. DPRINTK(3, "rx tasklet scheduled for device %d\n", fore200e->atm_dev->number);
  995. spin_lock_irqsave(&fore200e->q_lock, flags);
  996. fore200e_rx_irq((struct fore200e*) data);
  997. spin_unlock_irqrestore(&fore200e->q_lock, flags);
  998. }
  999. #endif
  1000. static int
  1001. fore200e_select_scheme(struct atm_vcc* vcc)
  1002. {
  1003. /* fairly balance the VCs over (identical) buffer schemes */
  1004. int scheme = vcc->vci % 2 ? BUFFER_SCHEME_ONE : BUFFER_SCHEME_TWO;
  1005. DPRINTK(1, "VC %d.%d.%d uses buffer scheme %d\n",
  1006. vcc->itf, vcc->vpi, vcc->vci, scheme);
  1007. return scheme;
  1008. }
  1009. static int
  1010. fore200e_activate_vcin(struct fore200e* fore200e, int activate, struct atm_vcc* vcc, int mtu)
  1011. {
  1012. struct host_cmdq* cmdq = &fore200e->host_cmdq;
  1013. struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
  1014. struct activate_opcode activ_opcode;
  1015. struct deactivate_opcode deactiv_opcode;
  1016. struct vpvc vpvc;
  1017. int ok;
  1018. enum fore200e_aal aal = fore200e_atm2fore_aal(vcc->qos.aal);
  1019. FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
  1020. if (activate) {
  1021. FORE200E_VCC(vcc)->scheme = fore200e_select_scheme(vcc);
  1022. activ_opcode.opcode = OPCODE_ACTIVATE_VCIN;
  1023. activ_opcode.aal = aal;
  1024. activ_opcode.scheme = FORE200E_VCC(vcc)->scheme;
  1025. activ_opcode.pad = 0;
  1026. }
  1027. else {
  1028. deactiv_opcode.opcode = OPCODE_DEACTIVATE_VCIN;
  1029. deactiv_opcode.pad = 0;
  1030. }
  1031. vpvc.vci = vcc->vci;
  1032. vpvc.vpi = vcc->vpi;
  1033. *entry->status = STATUS_PENDING;
  1034. if (activate) {
  1035. #ifdef FORE200E_52BYTE_AAL0_SDU
  1036. mtu = 48;
  1037. #endif
  1038. /* the MTU is not used by the cp, except in the case of AAL0 */
  1039. fore200e->bus->write(mtu, &entry->cp_entry->cmd.activate_block.mtu);
  1040. fore200e->bus->write(*(u32*)&vpvc, (u32 __iomem *)&entry->cp_entry->cmd.activate_block.vpvc);
  1041. fore200e->bus->write(*(u32*)&activ_opcode, (u32 __iomem *)&entry->cp_entry->cmd.activate_block.opcode);
  1042. }
  1043. else {
  1044. fore200e->bus->write(*(u32*)&vpvc, (u32 __iomem *)&entry->cp_entry->cmd.deactivate_block.vpvc);
  1045. fore200e->bus->write(*(u32*)&deactiv_opcode, (u32 __iomem *)&entry->cp_entry->cmd.deactivate_block.opcode);
  1046. }
  1047. ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
  1048. *entry->status = STATUS_FREE;
  1049. if (ok == 0) {
  1050. printk(FORE200E "unable to %s VC %d.%d.%d\n",
  1051. activate ? "open" : "close", vcc->itf, vcc->vpi, vcc->vci);
  1052. return -EIO;
  1053. }
  1054. DPRINTK(1, "VC %d.%d.%d %sed\n", vcc->itf, vcc->vpi, vcc->vci,
  1055. activate ? "open" : "clos");
  1056. return 0;
  1057. }
  1058. #define FORE200E_MAX_BACK2BACK_CELLS 255 /* XXX depends on CDVT */
  1059. static void
  1060. fore200e_rate_ctrl(struct atm_qos* qos, struct tpd_rate* rate)
  1061. {
  1062. if (qos->txtp.max_pcr < ATM_OC3_PCR) {
  1063. /* compute the data cells to idle cells ratio from the tx PCR */
  1064. rate->data_cells = qos->txtp.max_pcr * FORE200E_MAX_BACK2BACK_CELLS / ATM_OC3_PCR;
  1065. rate->idle_cells = FORE200E_MAX_BACK2BACK_CELLS - rate->data_cells;
  1066. }
  1067. else {
  1068. /* disable rate control */
  1069. rate->data_cells = rate->idle_cells = 0;
  1070. }
  1071. }
  1072. static int
  1073. fore200e_open(struct atm_vcc *vcc)
  1074. {
  1075. struct fore200e* fore200e = FORE200E_DEV(vcc->dev);
  1076. struct fore200e_vcc* fore200e_vcc;
  1077. struct fore200e_vc_map* vc_map;
  1078. unsigned long flags;
  1079. int vci = vcc->vci;
  1080. short vpi = vcc->vpi;
  1081. ASSERT((vpi >= 0) && (vpi < 1<<FORE200E_VPI_BITS));
  1082. ASSERT((vci >= 0) && (vci < 1<<FORE200E_VCI_BITS));
  1083. spin_lock_irqsave(&fore200e->q_lock, flags);
  1084. vc_map = FORE200E_VC_MAP(fore200e, vpi, vci);
  1085. if (vc_map->vcc) {
  1086. spin_unlock_irqrestore(&fore200e->q_lock, flags);
  1087. printk(FORE200E "VC %d.%d.%d already in use\n",
  1088. fore200e->atm_dev->number, vpi, vci);
  1089. return -EINVAL;
  1090. }
  1091. vc_map->vcc = vcc;
  1092. spin_unlock_irqrestore(&fore200e->q_lock, flags);
  1093. fore200e_vcc = kzalloc(sizeof(struct fore200e_vcc), GFP_ATOMIC);
  1094. if (fore200e_vcc == NULL) {
  1095. vc_map->vcc = NULL;
  1096. return -ENOMEM;
  1097. }
  1098. DPRINTK(2, "opening %d.%d.%d:%d QoS = (tx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d; "
  1099. "rx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d)\n",
  1100. vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
  1101. fore200e_traffic_class[ vcc->qos.txtp.traffic_class ],
  1102. vcc->qos.txtp.min_pcr, vcc->qos.txtp.max_pcr, vcc->qos.txtp.max_cdv, vcc->qos.txtp.max_sdu,
  1103. fore200e_traffic_class[ vcc->qos.rxtp.traffic_class ],
  1104. vcc->qos.rxtp.min_pcr, vcc->qos.rxtp.max_pcr, vcc->qos.rxtp.max_cdv, vcc->qos.rxtp.max_sdu);
  1105. /* pseudo-CBR bandwidth requested? */
  1106. if ((vcc->qos.txtp.traffic_class == ATM_CBR) && (vcc->qos.txtp.max_pcr > 0)) {
  1107. down(&fore200e->rate_sf);
  1108. if (fore200e->available_cell_rate < vcc->qos.txtp.max_pcr) {
  1109. up(&fore200e->rate_sf);
  1110. kfree(fore200e_vcc);
  1111. vc_map->vcc = NULL;
  1112. return -EAGAIN;
  1113. }
  1114. /* reserve bandwidth */
  1115. fore200e->available_cell_rate -= vcc->qos.txtp.max_pcr;
  1116. up(&fore200e->rate_sf);
  1117. }
  1118. vcc->itf = vcc->dev->number;
  1119. set_bit(ATM_VF_PARTIAL,&vcc->flags);
  1120. set_bit(ATM_VF_ADDR, &vcc->flags);
  1121. vcc->dev_data = fore200e_vcc;
  1122. if (fore200e_activate_vcin(fore200e, 1, vcc, vcc->qos.rxtp.max_sdu) < 0) {
  1123. vc_map->vcc = NULL;
  1124. clear_bit(ATM_VF_ADDR, &vcc->flags);
  1125. clear_bit(ATM_VF_PARTIAL,&vcc->flags);
  1126. vcc->dev_data = NULL;
  1127. fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
  1128. kfree(fore200e_vcc);
  1129. return -EINVAL;
  1130. }
  1131. /* compute rate control parameters */
  1132. if ((vcc->qos.txtp.traffic_class == ATM_CBR) && (vcc->qos.txtp.max_pcr > 0)) {
  1133. fore200e_rate_ctrl(&vcc->qos, &fore200e_vcc->rate);
  1134. set_bit(ATM_VF_HASQOS, &vcc->flags);
  1135. DPRINTK(3, "tx on %d.%d.%d:%d, tx PCR = %d, rx PCR = %d, data_cells = %u, idle_cells = %u\n",
  1136. vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
  1137. vcc->qos.txtp.max_pcr, vcc->qos.rxtp.max_pcr,
  1138. fore200e_vcc->rate.data_cells, fore200e_vcc->rate.idle_cells);
  1139. }
  1140. fore200e_vcc->tx_min_pdu = fore200e_vcc->rx_min_pdu = MAX_PDU_SIZE + 1;
  1141. fore200e_vcc->tx_max_pdu = fore200e_vcc->rx_max_pdu = 0;
  1142. fore200e_vcc->tx_pdu = fore200e_vcc->rx_pdu = 0;
  1143. /* new incarnation of the vcc */
  1144. vc_map->incarn = ++fore200e->incarn_count;
  1145. /* VC unusable before this flag is set */
  1146. set_bit(ATM_VF_READY, &vcc->flags);
  1147. return 0;
  1148. }
  1149. static void
  1150. fore200e_close(struct atm_vcc* vcc)
  1151. {
  1152. struct fore200e* fore200e = FORE200E_DEV(vcc->dev);
  1153. struct fore200e_vcc* fore200e_vcc;
  1154. struct fore200e_vc_map* vc_map;
  1155. unsigned long flags;
  1156. ASSERT(vcc);
  1157. ASSERT((vcc->vpi >= 0) && (vcc->vpi < 1<<FORE200E_VPI_BITS));
  1158. ASSERT((vcc->vci >= 0) && (vcc->vci < 1<<FORE200E_VCI_BITS));
  1159. DPRINTK(2, "closing %d.%d.%d:%d\n", vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal));
  1160. clear_bit(ATM_VF_READY, &vcc->flags);
  1161. fore200e_activate_vcin(fore200e, 0, vcc, 0);
  1162. spin_lock_irqsave(&fore200e->q_lock, flags);
  1163. vc_map = FORE200E_VC_MAP(fore200e, vcc->vpi, vcc->vci);
  1164. /* the vc is no longer considered as "in use" by fore200e_open() */
  1165. vc_map->vcc = NULL;
  1166. vcc->itf = vcc->vci = vcc->vpi = 0;
  1167. fore200e_vcc = FORE200E_VCC(vcc);
  1168. vcc->dev_data = NULL;
  1169. spin_unlock_irqrestore(&fore200e->q_lock, flags);
  1170. /* release reserved bandwidth, if any */
  1171. if ((vcc->qos.txtp.traffic_class == ATM_CBR) && (vcc->qos.txtp.max_pcr > 0)) {
  1172. down(&fore200e->rate_sf);
  1173. fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
  1174. up(&fore200e->rate_sf);
  1175. clear_bit(ATM_VF_HASQOS, &vcc->flags);
  1176. }
  1177. clear_bit(ATM_VF_ADDR, &vcc->flags);
  1178. clear_bit(ATM_VF_PARTIAL,&vcc->flags);
  1179. ASSERT(fore200e_vcc);
  1180. kfree(fore200e_vcc);
  1181. }
  1182. static int
  1183. fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
  1184. {
  1185. struct fore200e* fore200e = FORE200E_DEV(vcc->dev);
  1186. struct fore200e_vcc* fore200e_vcc = FORE200E_VCC(vcc);
  1187. struct fore200e_vc_map* vc_map;
  1188. struct host_txq* txq = &fore200e->host_txq;
  1189. struct host_txq_entry* entry;
  1190. struct tpd* tpd;
  1191. struct tpd_haddr tpd_haddr;
  1192. int retry = CONFIG_ATM_FORE200E_TX_RETRY;
  1193. int tx_copy = 0;
  1194. int tx_len = skb->len;
  1195. u32* cell_header = NULL;
  1196. unsigned char* skb_data;
  1197. int skb_len;
  1198. unsigned char* data;
  1199. unsigned long flags;
  1200. ASSERT(vcc);
  1201. ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
  1202. ASSERT(fore200e);
  1203. ASSERT(fore200e_vcc);
  1204. if (!test_bit(ATM_VF_READY, &vcc->flags)) {
  1205. DPRINTK(1, "VC %d.%d.%d not ready for tx\n", vcc->itf, vcc->vpi, vcc->vpi);
  1206. dev_kfree_skb_any(skb);
  1207. return -EINVAL;
  1208. }
  1209. #ifdef FORE200E_52BYTE_AAL0_SDU
  1210. if ((vcc->qos.aal == ATM_AAL0) && (vcc->qos.txtp.max_sdu == ATM_AAL0_SDU)) {
  1211. cell_header = (u32*) skb->data;
  1212. skb_data = skb->data + 4; /* skip 4-byte cell header */
  1213. skb_len = tx_len = skb->len - 4;
  1214. DPRINTK(3, "user-supplied cell header = 0x%08x\n", *cell_header);
  1215. }
  1216. else
  1217. #endif
  1218. {
  1219. skb_data = skb->data;
  1220. skb_len = skb->len;
  1221. }
  1222. if (((unsigned long)skb_data) & 0x3) {
  1223. DPRINTK(2, "misaligned tx PDU on device %s\n", fore200e->name);
  1224. tx_copy = 1;
  1225. tx_len = skb_len;
  1226. }
  1227. if ((vcc->qos.aal == ATM_AAL0) && (skb_len % ATM_CELL_PAYLOAD)) {
  1228. /* this simply NUKES the PCA board */
  1229. DPRINTK(2, "incomplete tx AAL0 PDU on device %s\n", fore200e->name);
  1230. tx_copy = 1;
  1231. tx_len = ((skb_len / ATM_CELL_PAYLOAD) + 1) * ATM_CELL_PAYLOAD;
  1232. }
  1233. if (tx_copy) {
  1234. data = kmalloc(tx_len, GFP_ATOMIC | GFP_DMA);
  1235. if (data == NULL) {
  1236. if (vcc->pop) {
  1237. vcc->pop(vcc, skb);
  1238. }
  1239. else {
  1240. dev_kfree_skb_any(skb);
  1241. }
  1242. return -ENOMEM;
  1243. }
  1244. memcpy(data, skb_data, skb_len);
  1245. if (skb_len < tx_len)
  1246. memset(data + skb_len, 0x00, tx_len - skb_len);
  1247. }
  1248. else {
  1249. data = skb_data;
  1250. }
  1251. vc_map = FORE200E_VC_MAP(fore200e, vcc->vpi, vcc->vci);
  1252. ASSERT(vc_map->vcc == vcc);
  1253. retry_here:
  1254. spin_lock_irqsave(&fore200e->q_lock, flags);
  1255. entry = &txq->host_entry[ txq->head ];
  1256. if ((*entry->status != STATUS_FREE) || (txq->txing >= QUEUE_SIZE_TX - 2)) {
  1257. /* try to free completed tx queue entries */
  1258. fore200e_tx_irq(fore200e);
  1259. if (*entry->status != STATUS_FREE) {
  1260. spin_unlock_irqrestore(&fore200e->q_lock, flags);
  1261. /* retry once again? */
  1262. if (--retry > 0) {
  1263. udelay(50);
  1264. goto retry_here;
  1265. }
  1266. atomic_inc(&vcc->stats->tx_err);
  1267. fore200e->tx_sat++;
  1268. DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
  1269. fore200e->name, fore200e->cp_queues->heartbeat);
  1270. if (vcc->pop) {
  1271. vcc->pop(vcc, skb);
  1272. }
  1273. else {
  1274. dev_kfree_skb_any(skb);
  1275. }
  1276. if (tx_copy)
  1277. kfree(data);
  1278. return -ENOBUFS;
  1279. }
  1280. }
  1281. entry->incarn = vc_map->incarn;
  1282. entry->vc_map = vc_map;
  1283. entry->skb = skb;
  1284. entry->data = tx_copy ? data : NULL;
  1285. tpd = entry->tpd;
  1286. tpd->tsd[ 0 ].buffer = fore200e->bus->dma_map(fore200e, data, tx_len, DMA_TO_DEVICE);
  1287. tpd->tsd[ 0 ].length = tx_len;
  1288. FORE200E_NEXT_ENTRY(txq->head, QUEUE_SIZE_TX);
  1289. txq->txing++;
  1290. /* The dma_map call above implies a dma_sync so the device can use it,
  1291. * thus no explicit dma_sync call is necessary here.
  1292. */
  1293. DPRINTK(3, "tx on %d.%d.%d:%d, len = %u (%u)\n",
  1294. vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
  1295. tpd->tsd[0].length, skb_len);
  1296. if (skb_len < fore200e_vcc->tx_min_pdu)
  1297. fore200e_vcc->tx_min_pdu = skb_len;
  1298. if (skb_len > fore200e_vcc->tx_max_pdu)
  1299. fore200e_vcc->tx_max_pdu = skb_len;
  1300. fore200e_vcc->tx_pdu++;
  1301. /* set tx rate control information */
  1302. tpd->rate.data_cells = fore200e_vcc->rate.data_cells;
  1303. tpd->rate.idle_cells = fore200e_vcc->rate.idle_cells;
  1304. if (cell_header) {
  1305. tpd->atm_header.clp = (*cell_header & ATM_HDR_CLP);
  1306. tpd->atm_header.plt = (*cell_header & ATM_HDR_PTI_MASK) >> ATM_HDR_PTI_SHIFT;
  1307. tpd->atm_header.vci = (*cell_header & ATM_HDR_VCI_MASK) >> ATM_HDR_VCI_SHIFT;
  1308. tpd->atm_header.vpi = (*cell_header & ATM_HDR_VPI_MASK) >> ATM_HDR_VPI_SHIFT;
  1309. tpd->atm_header.gfc = (*cell_header & ATM_HDR_GFC_MASK) >> ATM_HDR_GFC_SHIFT;
  1310. }
  1311. else {
  1312. /* set the ATM header, common to all cells conveying the PDU */
  1313. tpd->atm_header.clp = 0;
  1314. tpd->atm_header.plt = 0;
  1315. tpd->atm_header.vci = vcc->vci;
  1316. tpd->atm_header.vpi = vcc->vpi;
  1317. tpd->atm_header.gfc = 0;
  1318. }
  1319. tpd->spec.length = tx_len;
  1320. tpd->spec.nseg = 1;
  1321. tpd->spec.aal = fore200e_atm2fore_aal(vcc->qos.aal);
  1322. tpd->spec.intr = 1;
  1323. tpd_haddr.size = sizeof(struct tpd) / (1<<TPD_HADDR_SHIFT); /* size is expressed in 32 byte blocks */
  1324. tpd_haddr.pad = 0;
  1325. tpd_haddr.haddr = entry->tpd_dma >> TPD_HADDR_SHIFT; /* shift the address, as we are in a bitfield */
  1326. *entry->status = STATUS_PENDING;
  1327. fore200e->bus->write(*(u32*)&tpd_haddr, (u32 __iomem *)&entry->cp_entry->tpd_haddr);
  1328. spin_unlock_irqrestore(&fore200e->q_lock, flags);
  1329. return 0;
  1330. }
  1331. static int
  1332. fore200e_getstats(struct fore200e* fore200e)
  1333. {
  1334. struct host_cmdq* cmdq = &fore200e->host_cmdq;
  1335. struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
  1336. struct stats_opcode opcode;
  1337. int ok;
  1338. u32 stats_dma_addr;
  1339. if (fore200e->stats == NULL) {
  1340. fore200e->stats = kzalloc(sizeof(struct stats), GFP_KERNEL | GFP_DMA);
  1341. if (fore200e->stats == NULL)
  1342. return -ENOMEM;
  1343. }
  1344. stats_dma_addr = fore200e->bus->dma_map(fore200e, fore200e->stats,
  1345. sizeof(struct stats), DMA_FROM_DEVICE);
  1346. FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
  1347. opcode.opcode = OPCODE_GET_STATS;
  1348. opcode.pad = 0;
  1349. fore200e->bus->write(stats_dma_addr, &entry->cp_entry->cmd.stats_block.stats_haddr);
  1350. *entry->status = STATUS_PENDING;
  1351. fore200e->bus->write(*(u32*)&opcode, (u32 __iomem *)&entry->cp_entry->cmd.stats_block.opcode);
  1352. ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
  1353. *entry->status = STATUS_FREE;
  1354. fore200e->bus->dma_unmap(fore200e, stats_dma_addr, sizeof(struct stats), DMA_FROM_DEVICE);
  1355. if (ok == 0) {
  1356. printk(FORE200E "unable to get statistics from device %s\n", fore200e->name);
  1357. return -EIO;
  1358. }
  1359. return 0;
  1360. }
  1361. static int
  1362. fore200e_getsockopt(struct atm_vcc* vcc, int level, int optname, void __user *optval, int optlen)
  1363. {
  1364. /* struct fore200e* fore200e = FORE200E_DEV(vcc->dev); */
  1365. DPRINTK(2, "getsockopt %d.%d.%d, level = %d, optname = 0x%x, optval = 0x%p, optlen = %d\n",
  1366. vcc->itf, vcc->vpi, vcc->vci, level, optname, optval, optlen);
  1367. return -EINVAL;
  1368. }
  1369. static int
  1370. fore200e_setsockopt(struct atm_vcc* vcc, int level, int optname, void __user *optval, int optlen)
  1371. {
  1372. /* struct fore200e* fore200e = FORE200E_DEV(vcc->dev); */
  1373. DPRINTK(2, "setsockopt %d.%d.%d, level = %d, optname = 0x%x, optval = 0x%p, optlen = %d\n",
  1374. vcc->itf, vcc->vpi, vcc->vci, level, optname, optval, optlen);
  1375. return -EINVAL;
  1376. }
  1377. #if 0 /* currently unused */
  1378. static int
  1379. fore200e_get_oc3(struct fore200e* fore200e, struct oc3_regs* regs)
  1380. {
  1381. struct host_cmdq* cmdq = &fore200e->host_cmdq;
  1382. struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
  1383. struct oc3_opcode opcode;
  1384. int ok;
  1385. u32 oc3_regs_dma_addr;
  1386. oc3_regs_dma_addr = fore200e->bus->dma_map(fore200e, regs, sizeof(struct oc3_regs), DMA_FROM_DEVICE);
  1387. FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
  1388. opcode.opcode = OPCODE_GET_OC3;
  1389. opcode.reg = 0;
  1390. opcode.value = 0;
  1391. opcode.mask = 0;
  1392. fore200e->bus->write(oc3_regs_dma_addr, &entry->cp_entry->cmd.oc3_block.regs_haddr);
  1393. *entry->status = STATUS_PENDING;
  1394. fore200e->bus->write(*(u32*)&opcode, (u32*)&entry->cp_entry->cmd.oc3_block.opcode);
  1395. ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
  1396. *entry->status = STATUS_FREE;
  1397. fore200e->bus->dma_unmap(fore200e, oc3_regs_dma_addr, sizeof(struct oc3_regs), DMA_FROM_DEVICE);
  1398. if (ok == 0) {
  1399. printk(FORE200E "unable to get OC-3 regs of device %s\n", fore200e->name);
  1400. return -EIO;
  1401. }
  1402. return 0;
  1403. }
  1404. #endif
  1405. static int
  1406. fore200e_set_oc3(struct fore200e* fore200e, u32 reg, u32 value, u32 mask)
  1407. {
  1408. struct host_cmdq* cmdq = &fore200e->host_cmdq;
  1409. struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
  1410. struct oc3_opcode opcode;
  1411. int ok;
  1412. DPRINTK(2, "set OC-3 reg = 0x%02x, value = 0x%02x, mask = 0x%02x\n", reg, value, mask);
  1413. FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
  1414. opcode.opcode = OPCODE_SET_OC3;
  1415. opcode.reg = reg;
  1416. opcode.value = value;
  1417. opcode.mask = mask;
  1418. fore200e->bus->write(0, &entry->cp_entry->cmd.oc3_block.regs_haddr);
  1419. *entry->status = STATUS_PENDING;
  1420. fore200e->bus->write(*(u32*)&opcode, (u32 __iomem *)&entry->cp_entry->cmd.oc3_block.opcode);
  1421. ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
  1422. *entry->status = STATUS_FREE;
  1423. if (ok == 0) {
  1424. printk(FORE200E "unable to set OC-3 reg 0x%02x of device %s\n", reg, fore200e->name);
  1425. return -EIO;
  1426. }
  1427. return 0;
  1428. }
  1429. static int
  1430. fore200e_setloop(struct fore200e* fore200e, int loop_mode)
  1431. {
  1432. u32 mct_value, mct_mask;
  1433. int error;
  1434. if (!capable(CAP_NET_ADMIN))
  1435. return -EPERM;
  1436. switch (loop_mode) {
  1437. case ATM_LM_NONE:
  1438. mct_value = 0;
  1439. mct_mask = SUNI_MCT_DLE | SUNI_MCT_LLE;
  1440. break;
  1441. case ATM_LM_LOC_PHY:
  1442. mct_value = mct_mask = SUNI_MCT_DLE;
  1443. break;
  1444. case ATM_LM_RMT_PHY:
  1445. mct_value = mct_mask = SUNI_MCT_LLE;
  1446. break;
  1447. default:
  1448. return -EINVAL;
  1449. }
  1450. error = fore200e_set_oc3(fore200e, SUNI_MCT, mct_value, mct_mask);
  1451. if (error == 0)
  1452. fore200e->loop_mode = loop_mode;
  1453. return error;
  1454. }
  1455. static int
  1456. fore200e_fetch_stats(struct fore200e* fore200e, struct sonet_stats __user *arg)
  1457. {
  1458. struct sonet_stats tmp;
  1459. if (fore200e_getstats(fore200e) < 0)
  1460. return -EIO;
  1461. tmp.section_bip = cpu_to_be32(fore200e->stats->oc3.section_bip8_errors);
  1462. tmp.line_bip = cpu_to_be32(fore200e->stats->oc3.line_bip24_errors);
  1463. tmp.path_bip = cpu_to_be32(fore200e->stats->oc3.path_bip8_errors);
  1464. tmp.line_febe = cpu_to_be32(fore200e->stats->oc3.line_febe_errors);
  1465. tmp.path_febe = cpu_to_be32(fore200e->stats->oc3.path_febe_errors);
  1466. tmp.corr_hcs = cpu_to_be32(fore200e->stats->oc3.corr_hcs_errors);
  1467. tmp.uncorr_hcs = cpu_to_be32(fore200e->stats->oc3.ucorr_hcs_errors);
  1468. tmp.tx_cells = cpu_to_be32(fore200e->stats->aal0.cells_transmitted) +
  1469. cpu_to_be32(fore200e->stats->aal34.cells_transmitted) +
  1470. cpu_to_be32(fore200e->stats->aal5.cells_transmitted);
  1471. tmp.rx_cells = cpu_to_be32(fore200e->stats->aal0.cells_received) +
  1472. cpu_to_be32(fore200e->stats->aal34.cells_received) +
  1473. cpu_to_be32(fore200e->stats->aal5.cells_received);
  1474. if (arg)
  1475. return copy_to_user(arg, &tmp, sizeof(struct sonet_stats)) ? -EFAULT : 0;
  1476. return 0;
  1477. }
  1478. static int
  1479. fore200e_ioctl(struct atm_dev* dev, unsigned int cmd, void __user * arg)
  1480. {
  1481. struct fore200e* fore200e = FORE200E_DEV(dev);
  1482. DPRINTK(2, "ioctl cmd = 0x%x (%u), arg = 0x%p (%lu)\n", cmd, cmd, arg, (unsigned long)arg);
  1483. switch (cmd) {
  1484. case SONET_GETSTAT:
  1485. return fore200e_fetch_stats(fore200e, (struct sonet_stats __user *)arg);
  1486. case SONET_GETDIAG:
  1487. return put_user(0, (int __user *)arg) ? -EFAULT : 0;
  1488. case ATM_SETLOOP:
  1489. return fore200e_setloop(fore200e, (int)(unsigned long)arg);
  1490. case ATM_GETLOOP:
  1491. return put_user(fore200e->loop_mode, (int __user *)arg) ? -EFAULT : 0;
  1492. case ATM_QUERYLOOP:
  1493. return put_user(ATM_LM_LOC_PHY | ATM_LM_RMT_PHY, (int __user *)arg) ? -EFAULT : 0;
  1494. }
  1495. return -ENOSYS; /* not implemented */
  1496. }
  1497. static int
  1498. fore200e_change_qos(struct atm_vcc* vcc,struct atm_qos* qos, int flags)
  1499. {
  1500. struct fore200e_vcc* fore200e_vcc = FORE200E_VCC(vcc);
  1501. struct fore200e* fore200e = FORE200E_DEV(vcc->dev);
  1502. if (!test_bit(ATM_VF_READY, &vcc->flags)) {
  1503. DPRINTK(1, "VC %d.%d.%d not ready for QoS change\n", vcc->itf, vcc->vpi, vcc->vpi);
  1504. return -EINVAL;
  1505. }
  1506. DPRINTK(2, "change_qos %d.%d.%d, "
  1507. "(tx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d; "
  1508. "rx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d), flags = 0x%x\n"
  1509. "available_cell_rate = %u",
  1510. vcc->itf, vcc->vpi, vcc->vci,
  1511. fore200e_traffic_class[ qos->txtp.traffic_class ],
  1512. qos->txtp.min_pcr, qos->txtp.max_pcr, qos->txtp.max_cdv, qos->txtp.max_sdu,
  1513. fore200e_traffic_class[ qos->rxtp.traffic_class ],
  1514. qos->rxtp.min_pcr, qos->rxtp.max_pcr, qos->rxtp.max_cdv, qos->rxtp.max_sdu,
  1515. flags, fore200e->available_cell_rate);
  1516. if ((qos->txtp.traffic_class == ATM_CBR) && (qos->txtp.max_pcr > 0)) {
  1517. down(&fore200e->rate_sf);
  1518. if (fore200e->available_cell_rate + vcc->qos.txtp.max_pcr < qos->txtp.max_pcr) {
  1519. up(&fore200e->rate_sf);
  1520. return -EAGAIN;
  1521. }
  1522. fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
  1523. fore200e->available_cell_rate -= qos->txtp.max_pcr;
  1524. up(&fore200e->rate_sf);
  1525. memcpy(&vcc->qos, qos, sizeof(struct atm_qos));
  1526. /* update rate control parameters */
  1527. fore200e_rate_ctrl(qos, &fore200e_vcc->rate);
  1528. set_bit(ATM_VF_HASQOS, &vcc->flags);
  1529. return 0;
  1530. }
  1531. return -EINVAL;
  1532. }
  1533. static int __devinit
  1534. fore200e_irq_request(struct fore200e* fore200e)
  1535. {
  1536. if (request_irq(fore200e->irq, fore200e_interrupt, IRQF_SHARED, fore200e->name, fore200e->atm_dev) < 0) {
  1537. printk(FORE200E "unable to reserve IRQ %s for device %s\n",
  1538. fore200e_irq_itoa(fore200e->irq), fore200e->name);
  1539. return -EBUSY;
  1540. }
  1541. printk(FORE200E "IRQ %s reserved for device %s\n",
  1542. fore200e_irq_itoa(fore200e->irq), fore200e->name);
  1543. #ifdef FORE200E_USE_TASKLET
  1544. tasklet_init(&fore200e->tx_tasklet, fore200e_tx_tasklet, (unsigned long)fore200e);
  1545. tasklet_init(&fore200e->rx_tasklet, fore200e_rx_tasklet, (unsigned long)fore200e);
  1546. #endif
  1547. fore200e->state = FORE200E_STATE_IRQ;
  1548. return 0;
  1549. }
  1550. static int __devinit
  1551. fore200e_get_esi(struct fore200e* fore200e)
  1552. {
  1553. struct prom_data* prom = kzalloc(sizeof(struct prom_data), GFP_KERNEL | GFP_DMA);
  1554. int ok, i;
  1555. if (!prom)
  1556. return -ENOMEM;
  1557. ok = fore200e->bus->prom_read(fore200e, prom);
  1558. if (ok < 0) {
  1559. kfree(prom);
  1560. return -EBUSY;
  1561. }
  1562. printk(FORE200E "device %s, rev. %c, S/N: %d, ESI: %02x:%02x:%02x:%02x:%02x:%02x\n",
  1563. fore200e->name,
  1564. (prom->hw_revision & 0xFF) + '@', /* probably meaningless with SBA boards */
  1565. prom->serial_number & 0xFFFF,
  1566. prom->mac_addr[ 2 ], prom->mac_addr[ 3 ], prom->mac_addr[ 4 ],
  1567. prom->mac_addr[ 5 ], prom->mac_addr[ 6 ], prom->mac_addr[ 7 ]);
  1568. for (i = 0; i < ESI_LEN; i++) {
  1569. fore200e->esi[ i ] = fore200e->atm_dev->esi[ i ] = prom->mac_addr[ i + 2 ];
  1570. }
  1571. kfree(prom);
  1572. return 0;
  1573. }
  1574. static int __devinit
  1575. fore200e_alloc_rx_buf(struct fore200e* fore200e)
  1576. {
  1577. int scheme, magn, nbr, size, i;
  1578. struct host_bsq* bsq;
  1579. struct buffer* buffer;
  1580. for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
  1581. for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
  1582. bsq = &fore200e->host_bsq[ scheme ][ magn ];
  1583. nbr = fore200e_rx_buf_nbr[ scheme ][ magn ];
  1584. size = fore200e_rx_buf_size[ scheme ][ magn ];
  1585. DPRINTK(2, "rx buffers %d / %d are being allocated\n", scheme, magn);
  1586. /* allocate the array of receive buffers */
  1587. buffer = bsq->buffer = kzalloc(nbr * sizeof(struct buffer), GFP_KERNEL);
  1588. if (buffer == NULL)
  1589. return -ENOMEM;
  1590. bsq->freebuf = NULL;
  1591. for (i = 0; i < nbr; i++) {
  1592. buffer[ i ].scheme = scheme;
  1593. buffer[ i ].magn = magn;
  1594. #ifdef FORE200E_BSQ_DEBUG
  1595. buffer[ i ].index = i;
  1596. buffer[ i ].supplied = 0;
  1597. #endif
  1598. /* allocate the receive buffer body */
  1599. if (fore200e_chunk_alloc(fore200e,
  1600. &buffer[ i ].data, size, fore200e->bus->buffer_alignment,
  1601. DMA_FROM_DEVICE) < 0) {
  1602. while (i > 0)
  1603. fore200e_chunk_free(fore200e, &buffer[ --i ].data);
  1604. kfree(buffer);
  1605. return -ENOMEM;
  1606. }
  1607. /* insert the buffer into the free buffer list */
  1608. buffer[ i ].next = bsq->freebuf;
  1609. bsq->freebuf = &buffer[ i ];
  1610. }
  1611. /* all the buffers are free, initially */
  1612. bsq->freebuf_count = nbr;
  1613. #ifdef FORE200E_BSQ_DEBUG
  1614. bsq_audit(3, bsq, scheme, magn);
  1615. #endif
  1616. }
  1617. }
  1618. fore200e->state = FORE200E_STATE_ALLOC_BUF;
  1619. return 0;
  1620. }
  1621. static int __devinit
  1622. fore200e_init_bs_queue(struct fore200e* fore200e)
  1623. {
  1624. int scheme, magn, i;
  1625. struct host_bsq* bsq;
  1626. struct cp_bsq_entry __iomem * cp_entry;
  1627. for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
  1628. for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
  1629. DPRINTK(2, "buffer supply queue %d / %d is being initialized\n", scheme, magn);
  1630. bsq = &fore200e->host_bsq[ scheme ][ magn ];
  1631. /* allocate and align the array of status words */
  1632. if (fore200e->bus->dma_chunk_alloc(fore200e,
  1633. &bsq->status,
  1634. sizeof(enum status),
  1635. QUEUE_SIZE_BS,
  1636. fore200e->bus->status_alignment) < 0) {
  1637. return -ENOMEM;
  1638. }
  1639. /* allocate and align the array of receive buffer descriptors */
  1640. if (fore200e->bus->dma_chunk_alloc(fore200e,
  1641. &bsq->rbd_block,
  1642. sizeof(struct rbd_block),
  1643. QUEUE_SIZE_BS,
  1644. fore200e->bus->descr_alignment) < 0) {
  1645. fore200e->bus->dma_chunk_free(fore200e, &bsq->status);
  1646. return -ENOMEM;
  1647. }
  1648. /* get the base address of the cp resident buffer supply queue entries */
  1649. cp_entry = fore200e->virt_base +
  1650. fore200e->bus->read(&fore200e->cp_queues->cp_bsq[ scheme ][ magn ]);
  1651. /* fill the host resident and cp resident buffer supply queue entries */
  1652. for (i = 0; i < QUEUE_SIZE_BS; i++) {
  1653. bsq->host_entry[ i ].status =
  1654. FORE200E_INDEX(bsq->status.align_addr, enum status, i);
  1655. bsq->host_entry[ i ].rbd_block =
  1656. FORE200E_INDEX(bsq->rbd_block.align_addr, struct rbd_block, i);
  1657. bsq->host_entry[ i ].rbd_block_dma =
  1658. FORE200E_DMA_INDEX(bsq->rbd_block.dma_addr, struct rbd_block, i);
  1659. bsq->host_entry[ i ].cp_entry = &cp_entry[ i ];
  1660. *bsq->host_entry[ i ].status = STATUS_FREE;
  1661. fore200e->bus->write(FORE200E_DMA_INDEX(bsq->status.dma_addr, enum status, i),
  1662. &cp_entry[ i ].status_haddr);
  1663. }
  1664. }
  1665. }
  1666. fore200e->state = FORE200E_STATE_INIT_BSQ;
  1667. return 0;
  1668. }
  1669. static int __devinit
  1670. fore200e_init_rx_queue(struct fore200e* fore200e)
  1671. {
  1672. struct host_rxq* rxq = &fore200e->host_rxq;
  1673. struct cp_rxq_entry __iomem * cp_entry;
  1674. int i;
  1675. DPRINTK(2, "receive queue is being initialized\n");
  1676. /* allocate and align the array of status words */
  1677. if (fore200e->bus->dma_chunk_alloc(fore200e,
  1678. &rxq->status,
  1679. sizeof(enum status),
  1680. QUEUE_SIZE_RX,
  1681. fore200e->bus->status_alignment) < 0) {
  1682. return -ENOMEM;
  1683. }
  1684. /* allocate and align the array of receive PDU descriptors */
  1685. if (fore200e->bus->dma_chunk_alloc(fore200e,
  1686. &rxq->rpd,
  1687. sizeof(struct rpd),
  1688. QUEUE_SIZE_RX,
  1689. fore200e->bus->descr_alignment) < 0) {
  1690. fore200e->bus->dma_chunk_free(fore200e, &rxq->status);
  1691. return -ENOMEM;
  1692. }
  1693. /* get the base address of the cp resident rx queue entries */
  1694. cp_entry = fore200e->virt_base + fore200e->bus->read(&fore200e->cp_queues->cp_rxq);
  1695. /* fill the host resident and cp resident rx entries */
  1696. for (i=0; i < QUEUE_SIZE_RX; i++) {
  1697. rxq->host_entry[ i ].status =
  1698. FORE200E_INDEX(rxq->status.align_addr, enum status, i);
  1699. rxq->host_entry[ i ].rpd =
  1700. FORE200E_INDEX(rxq->rpd.align_addr, struct rpd, i);
  1701. rxq->host_entry[ i ].rpd_dma =
  1702. FORE200E_DMA_INDEX(rxq->rpd.dma_addr, struct rpd, i);
  1703. rxq->host_entry[ i ].cp_entry = &cp_entry[ i ];
  1704. *rxq->host_entry[ i ].status = STATUS_FREE;
  1705. fore200e->bus->write(FORE200E_DMA_INDEX(rxq->status.dma_addr, enum status, i),
  1706. &cp_entry[ i ].status_haddr);
  1707. fore200e->bus->write(FORE200E_DMA_INDEX(rxq->rpd.dma_addr, struct rpd, i),
  1708. &cp_entry[ i ].rpd_haddr);
  1709. }
  1710. /* set the head entry of the queue */
  1711. rxq->head = 0;
  1712. fore200e->state = FORE200E_STATE_INIT_RXQ;
  1713. return 0;
  1714. }
  1715. static int __devinit
  1716. fore200e_init_tx_queue(struct fore200e* fore200e)
  1717. {
  1718. struct host_txq* txq = &fore200e->host_txq;
  1719. struct cp_txq_entry __iomem * cp_entry;
  1720. int i;
  1721. DPRINTK(2, "transmit queue is being initialized\n");
  1722. /* allocate and align the array of status words */
  1723. if (fore200e->bus->dma_chunk_alloc(fore200e,
  1724. &txq->status,
  1725. sizeof(enum status),
  1726. QUEUE_SIZE_TX,
  1727. fore200e->bus->status_alignment) < 0) {
  1728. return -ENOMEM;
  1729. }
  1730. /* allocate and align the array of transmit PDU descriptors */
  1731. if (fore200e->bus->dma_chunk_alloc(fore200e,
  1732. &txq->tpd,
  1733. sizeof(struct tpd),
  1734. QUEUE_SIZE_TX,
  1735. fore200e->bus->descr_alignment) < 0) {
  1736. fore200e->bus->dma_chunk_free(fore200e, &txq->status);
  1737. return -ENOMEM;
  1738. }
  1739. /* get the base address of the cp resident tx queue entries */
  1740. cp_entry = fore200e->virt_base + fore200e->bus->read(&fore200e->cp_queues->cp_txq);
  1741. /* fill the host resident and cp resident tx entries */
  1742. for (i=0; i < QUEUE_SIZE_TX; i++) {
  1743. txq->host_entry[ i ].status =
  1744. FORE200E_INDEX(txq->status.align_addr, enum status, i);
  1745. txq->host_entry[ i ].tpd =
  1746. FORE200E_INDEX(txq->tpd.align_addr, struct tpd, i);
  1747. txq->host_entry[ i ].tpd_dma =
  1748. FORE200E_DMA_INDEX(txq->tpd.dma_addr, struct tpd, i);
  1749. txq->host_entry[ i ].cp_entry = &cp_entry[ i ];
  1750. *txq->host_entry[ i ].status = STATUS_FREE;
  1751. fore200e->bus->write(FORE200E_DMA_INDEX(txq->status.dma_addr, enum status, i),
  1752. &cp_entry[ i ].status_haddr);
  1753. /* although there is a one-to-one mapping of tx queue entries and tpds,
  1754. we do not write here the DMA (physical) base address of each tpd into
  1755. the related cp resident entry, because the cp relies on this write
  1756. operation to detect that a new pdu has been submitted for tx */
  1757. }
  1758. /* set the head and tail entries of the queue */
  1759. txq->head = 0;
  1760. txq->tail = 0;
  1761. fore200e->state = FORE200E_STATE_INIT_TXQ;
  1762. return 0;
  1763. }
  1764. static int __devinit
  1765. fore200e_init_cmd_queue(struct fore200e* fore200e)
  1766. {
  1767. struct host_cmdq* cmdq = &fore200e->host_cmdq;
  1768. struct cp_cmdq_entry __iomem * cp_entry;
  1769. int i;
  1770. DPRINTK(2, "command queue is being initialized\n");
  1771. /* allocate and align the array of status words */
  1772. if (fore200e->bus->dma_chunk_alloc(fore200e,
  1773. &cmdq->status,
  1774. sizeof(enum status),
  1775. QUEUE_SIZE_CMD,
  1776. fore200e->bus->status_alignment) < 0) {
  1777. return -ENOMEM;
  1778. }
  1779. /* get the base address of the cp resident cmd queue entries */
  1780. cp_entry = fore200e->virt_base + fore200e->bus->read(&fore200e->cp_queues->cp_cmdq);
  1781. /* fill the host resident and cp resident cmd entries */
  1782. for (i=0; i < QUEUE_SIZE_CMD; i++) {
  1783. cmdq->host_entry[ i ].status =
  1784. FORE200E_INDEX(cmdq->status.align_addr, enum status, i);
  1785. cmdq->host_entry[ i ].cp_entry = &cp_entry[ i ];
  1786. *cmdq->host_entry[ i ].status = STATUS_FREE;
  1787. fore200e->bus->write(FORE200E_DMA_INDEX(cmdq->status.dma_addr, enum status, i),
  1788. &cp_entry[ i ].status_haddr);
  1789. }
  1790. /* set the head entry of the queue */
  1791. cmdq->head = 0;
  1792. fore200e->state = FORE200E_STATE_INIT_CMDQ;
  1793. return 0;
  1794. }
  1795. static void __init
  1796. fore200e_param_bs_queue(struct fore200e* fore200e,
  1797. enum buffer_scheme scheme, enum buffer_magn magn,
  1798. int queue_length, int pool_size, int supply_blksize)
  1799. {
  1800. struct bs_spec __iomem * bs_spec = &fore200e->cp_queues->init.bs_spec[ scheme ][ magn ];
  1801. fore200e->bus->write(queue_length, &bs_spec->queue_length);
  1802. fore200e->bus->write(fore200e_rx_buf_size[ scheme ][ magn ], &bs_spec->buffer_size);
  1803. fore200e->bus->write(pool_size, &bs_spec->pool_size);
  1804. fore200e->bus->write(supply_blksize, &bs_spec->supply_blksize);
  1805. }
  1806. static int __devinit
  1807. fore200e_initialize(struct fore200e* fore200e)
  1808. {
  1809. struct cp_queues __iomem * cpq;
  1810. int ok, scheme, magn;
  1811. DPRINTK(2, "device %s being initialized\n", fore200e->name);
  1812. init_MUTEX(&fore200e->rate_sf);
  1813. spin_lock_init(&fore200e->q_lock);
  1814. cpq = fore200e->cp_queues = fore200e->virt_base + FORE200E_CP_QUEUES_OFFSET;
  1815. /* enable cp to host interrupts */
  1816. fore200e->bus->write(1, &cpq->imask);
  1817. if (fore200e->bus->irq_enable)
  1818. fore200e->bus->irq_enable(fore200e);
  1819. fore200e->bus->write(NBR_CONNECT, &cpq->init.num_connect);
  1820. fore200e->bus->write(QUEUE_SIZE_CMD, &cpq->init.cmd_queue_len);
  1821. fore200e->bus->write(QUEUE_SIZE_RX, &cpq->init.rx_queue_len);
  1822. fore200e->bus->write(QUEUE_SIZE_TX, &cpq->init.tx_queue_len);
  1823. fore200e->bus->write(RSD_EXTENSION, &cpq->init.rsd_extension);
  1824. fore200e->bus->write(TSD_EXTENSION, &cpq->init.tsd_extension);
  1825. for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++)
  1826. for (magn = 0; magn < BUFFER_MAGN_NBR; magn++)
  1827. fore200e_param_bs_queue(fore200e, scheme, magn,
  1828. QUEUE_SIZE_BS,
  1829. fore200e_rx_buf_nbr[ scheme ][ magn ],
  1830. RBD_BLK_SIZE);
  1831. /* issue the initialize command */
  1832. fore200e->bus->write(STATUS_PENDING, &cpq->init.status);
  1833. fore200e->bus->write(OPCODE_INITIALIZE, &cpq->init.opcode);
  1834. ok = fore200e_io_poll(fore200e, &cpq->init.status, STATUS_COMPLETE, 3000);
  1835. if (ok == 0) {
  1836. printk(FORE200E "device %s initialization failed\n", fore200e->name);
  1837. return -ENODEV;
  1838. }
  1839. printk(FORE200E "device %s initialized\n", fore200e->name);
  1840. fore200e->state = FORE200E_STATE_INITIALIZE;
  1841. return 0;
  1842. }
  1843. static void __devinit
  1844. fore200e_monitor_putc(struct fore200e* fore200e, char c)
  1845. {
  1846. struct cp_monitor __iomem * monitor = fore200e->cp_monitor;
  1847. #if 0
  1848. printk("%c", c);
  1849. #endif
  1850. fore200e->bus->write(((u32) c) | FORE200E_CP_MONITOR_UART_AVAIL, &monitor->soft_uart.send);
  1851. }
  1852. static int __devinit
  1853. fore200e_monitor_getc(struct fore200e* fore200e)
  1854. {
  1855. struct cp_monitor __iomem * monitor = fore200e->cp_monitor;
  1856. unsigned long timeout = jiffies + msecs_to_jiffies(50);
  1857. int c;
  1858. while (time_before(jiffies, timeout)) {
  1859. c = (int) fore200e->bus->read(&monitor->soft_uart.recv);
  1860. if (c & FORE200E_CP_MONITOR_UART_AVAIL) {
  1861. fore200e->bus->write(FORE200E_CP_MONITOR_UART_FREE, &monitor->soft_uart.recv);
  1862. #if 0
  1863. printk("%c", c & 0xFF);
  1864. #endif
  1865. return c & 0xFF;
  1866. }
  1867. }
  1868. return -1;
  1869. }
  1870. static void __devinit
  1871. fore200e_monitor_puts(struct fore200e* fore200e, char* str)
  1872. {
  1873. while (*str) {
  1874. /* the i960 monitor doesn't accept any new character if it has something to say */
  1875. while (fore200e_monitor_getc(fore200e) >= 0);
  1876. fore200e_monitor_putc(fore200e, *str++);
  1877. }
  1878. while (fore200e_monitor_getc(fore200e) >= 0);
  1879. }
  1880. static int __devinit
  1881. fore200e_start_fw(struct fore200e* fore200e)
  1882. {
  1883. int ok;
  1884. char cmd[ 48 ];
  1885. struct fw_header* fw_header = (struct fw_header*) fore200e->bus->fw_data;
  1886. DPRINTK(2, "device %s firmware being started\n", fore200e->name);
  1887. #if defined(__sparc_v9__)
  1888. /* reported to be required by SBA cards on some sparc64 hosts */
  1889. fore200e_spin(100);
  1890. #endif
  1891. sprintf(cmd, "\rgo %x\r", le32_to_cpu(fw_header->start_offset));
  1892. fore200e_monitor_puts(fore200e, cmd);
  1893. ok = fore200e_io_poll(fore200e, &fore200e->cp_monitor->bstat, BSTAT_CP_RUNNING, 1000);
  1894. if (ok == 0) {
  1895. printk(FORE200E "device %s firmware didn't start\n", fore200e->name);
  1896. return -ENODEV;
  1897. }
  1898. printk(FORE200E "device %s firmware started\n", fore200e->name);
  1899. fore200e->state = FORE200E_STATE_START_FW;
  1900. return 0;
  1901. }
  1902. static int __devinit
  1903. fore200e_load_fw(struct fore200e* fore200e)
  1904. {
  1905. u32* fw_data = (u32*) fore200e->bus->fw_data;
  1906. u32 fw_size = (u32) *fore200e->bus->fw_size / sizeof(u32);
  1907. struct fw_header* fw_header = (struct fw_header*) fw_data;
  1908. u32 __iomem *load_addr = fore200e->virt_base + le32_to_cpu(fw_header->load_offset);
  1909. DPRINTK(2, "device %s firmware being loaded at 0x%p (%d words)\n",
  1910. fore200e->name, load_addr, fw_size);
  1911. if (le32_to_cpu(fw_header->magic) != FW_HEADER_MAGIC) {
  1912. printk(FORE200E "corrupted %s firmware image\n", fore200e->bus->model_name);
  1913. return -ENODEV;
  1914. }
  1915. for (; fw_size--; fw_data++, load_addr++)
  1916. fore200e->bus->write(le32_to_cpu(*fw_data), load_addr);
  1917. fore200e->state = FORE200E_STATE_LOAD_FW;
  1918. return 0;
  1919. }
  1920. static int __devinit
  1921. fore200e_register(struct fore200e* fore200e)
  1922. {
  1923. struct atm_dev* atm_dev;
  1924. DPRINTK(2, "device %s being registered\n", fore200e->name);
  1925. atm_dev = atm_dev_register(fore200e->bus->proc_name, &fore200e_ops, -1,
  1926. NULL);
  1927. if (atm_dev == NULL) {
  1928. printk(FORE200E "unable to register device %s\n", fore200e->name);
  1929. return -ENODEV;
  1930. }
  1931. atm_dev->dev_data = fore200e;
  1932. fore200e->atm_dev = atm_dev;
  1933. atm_dev->ci_range.vpi_bits = FORE200E_VPI_BITS;
  1934. atm_dev->ci_range.vci_bits = FORE200E_VCI_BITS;
  1935. fore200e->available_cell_rate = ATM_OC3_PCR;
  1936. fore200e->state = FORE200E_STATE_REGISTER;
  1937. return 0;
  1938. }
  1939. static int __devinit
  1940. fore200e_init(struct fore200e* fore200e)
  1941. {
  1942. if (fore200e_register(fore200e) < 0)
  1943. return -ENODEV;
  1944. if (fore200e->bus->configure(fore200e) < 0)
  1945. return -ENODEV;
  1946. if (fore200e->bus->map(fore200e) < 0)
  1947. return -ENODEV;
  1948. if (fore200e_reset(fore200e, 1) < 0)
  1949. return -ENODEV;
  1950. if (fore200e_load_fw(fore200e) < 0)
  1951. return -ENODEV;
  1952. if (fore200e_start_fw(fore200e) < 0)
  1953. return -ENODEV;
  1954. if (fore200e_initialize(fore200e) < 0)
  1955. return -ENODEV;
  1956. if (fore200e_init_cmd_queue(fore200e) < 0)
  1957. return -ENOMEM;
  1958. if (fore200e_init_tx_queue(fore200e) < 0)
  1959. return -ENOMEM;
  1960. if (fore200e_init_rx_queue(fore200e) < 0)
  1961. return -ENOMEM;
  1962. if (fore200e_init_bs_queue(fore200e) < 0)
  1963. return -ENOMEM;
  1964. if (fore200e_alloc_rx_buf(fore200e) < 0)
  1965. return -ENOMEM;
  1966. if (fore200e_get_esi(fore200e) < 0)
  1967. return -EIO;
  1968. if (fore200e_irq_request(fore200e) < 0)
  1969. return -EBUSY;
  1970. fore200e_supply(fore200e);
  1971. /* all done, board initialization is now complete */
  1972. fore200e->state = FORE200E_STATE_COMPLETE;
  1973. return 0;
  1974. }
  1975. static int __devinit
  1976. fore200e_pca_detect(struct pci_dev *pci_dev, const struct pci_device_id *pci_ent)
  1977. {
  1978. const struct fore200e_bus* bus = (struct fore200e_bus*) pci_ent->driver_data;
  1979. struct fore200e* fore200e;
  1980. int err = 0;
  1981. static int index = 0;
  1982. if (pci_enable_device(pci_dev)) {
  1983. err = -EINVAL;
  1984. goto out;
  1985. }
  1986. fore200e = kzalloc(sizeof(struct fore200e), GFP_KERNEL);
  1987. if (fore200e == NULL) {
  1988. err = -ENOMEM;
  1989. goto out_disable;
  1990. }
  1991. fore200e->bus = bus;
  1992. fore200e->bus_dev = pci_dev;
  1993. fore200e->irq = pci_dev->irq;
  1994. fore200e->phys_base = pci_resource_start(pci_dev, 0);
  1995. sprintf(fore200e->name, "%s-%d", bus->model_name, index - 1);
  1996. pci_set_master(pci_dev);
  1997. printk(FORE200E "device %s found at 0x%lx, IRQ %s\n",
  1998. fore200e->bus->model_name,
  1999. fore200e->phys_base, fore200e_irq_itoa(fore200e->irq));
  2000. sprintf(fore200e->name, "%s-%d", bus->model_name, index);
  2001. err = fore200e_init(fore200e);
  2002. if (err < 0) {
  2003. fore200e_shutdown(fore200e);
  2004. goto out_free;
  2005. }
  2006. ++index;
  2007. pci_set_drvdata(pci_dev, fore200e);
  2008. out:
  2009. return err;
  2010. out_free:
  2011. kfree(fore200e);
  2012. out_disable:
  2013. pci_disable_device(pci_dev);
  2014. goto out;
  2015. }
  2016. static void __devexit fore200e_pca_remove_one(struct pci_dev *pci_dev)
  2017. {
  2018. struct fore200e *fore200e;
  2019. fore200e = pci_get_drvdata(pci_dev);
  2020. fore200e_shutdown(fore200e);
  2021. kfree(fore200e);
  2022. pci_disable_device(pci_dev);
  2023. }
  2024. #ifdef CONFIG_ATM_FORE200E_PCA
  2025. static struct pci_device_id fore200e_pca_tbl[] = {
  2026. { PCI_VENDOR_ID_FORE, PCI_DEVICE_ID_FORE_PCA200E, PCI_ANY_ID, PCI_ANY_ID,
  2027. 0, 0, (unsigned long) &fore200e_bus[0] },
  2028. { 0, }
  2029. };
  2030. MODULE_DEVICE_TABLE(pci, fore200e_pca_tbl);
  2031. static struct pci_driver fore200e_pca_driver = {
  2032. .name = "fore_200e",
  2033. .probe = fore200e_pca_detect,
  2034. .remove = __devexit_p(fore200e_pca_remove_one),
  2035. .id_table = fore200e_pca_tbl,
  2036. };
  2037. #endif
  2038. static int __init
  2039. fore200e_module_init(void)
  2040. {
  2041. const struct fore200e_bus* bus;
  2042. struct fore200e* fore200e;
  2043. int index;
  2044. printk(FORE200E "FORE Systems 200E-series ATM driver - version " FORE200E_VERSION "\n");
  2045. /* for each configured bus interface */
  2046. for (bus = fore200e_bus; bus->model_name; bus++) {
  2047. /* detect all boards present on that bus */
  2048. for (index = 0; bus->detect && (fore200e = bus->detect(bus, index)); index++) {
  2049. printk(FORE200E "device %s found at 0x%lx, IRQ %s\n",
  2050. fore200e->bus->model_name,
  2051. fore200e->phys_base, fore200e_irq_itoa(fore200e->irq));
  2052. sprintf(fore200e->name, "%s-%d", bus->model_name, index);
  2053. if (fore200e_init(fore200e) < 0) {
  2054. fore200e_shutdown(fore200e);
  2055. break;
  2056. }
  2057. list_add(&fore200e->entry, &fore200e_boards);
  2058. }
  2059. }
  2060. #ifdef CONFIG_ATM_FORE200E_PCA
  2061. if (!pci_register_driver(&fore200e_pca_driver))
  2062. return 0;
  2063. #endif
  2064. if (!list_empty(&fore200e_boards))
  2065. return 0;
  2066. return -ENODEV;
  2067. }
  2068. static void __exit
  2069. fore200e_module_cleanup(void)
  2070. {
  2071. struct fore200e *fore200e, *next;
  2072. #ifdef CONFIG_ATM_FORE200E_PCA
  2073. pci_unregister_driver(&fore200e_pca_driver);
  2074. #endif
  2075. list_for_each_entry_safe(fore200e, next, &fore200e_boards, entry) {
  2076. fore200e_shutdown(fore200e);
  2077. kfree(fore200e);
  2078. }
  2079. DPRINTK(1, "module being removed\n");
  2080. }
  2081. static int
  2082. fore200e_proc_read(struct atm_dev *dev, loff_t* pos, char* page)
  2083. {
  2084. struct fore200e* fore200e = FORE200E_DEV(dev);
  2085. struct fore200e_vcc* fore200e_vcc;
  2086. struct atm_vcc* vcc;
  2087. int i, len, left = *pos;
  2088. unsigned long flags;
  2089. if (!left--) {
  2090. if (fore200e_getstats(fore200e) < 0)
  2091. return -EIO;
  2092. len = sprintf(page,"\n"
  2093. " device:\n"
  2094. " internal name:\t\t%s\n", fore200e->name);
  2095. /* print bus-specific information */
  2096. if (fore200e->bus->proc_read)
  2097. len += fore200e->bus->proc_read(fore200e, page + len);
  2098. len += sprintf(page + len,
  2099. " interrupt line:\t\t%s\n"
  2100. " physical base address:\t0x%p\n"
  2101. " virtual base address:\t0x%p\n"
  2102. " factory address (ESI):\t%02x:%02x:%02x:%02x:%02x:%02x\n"
  2103. " board serial number:\t\t%d\n\n",
  2104. fore200e_irq_itoa(fore200e->irq),
  2105. (void*)fore200e->phys_base,
  2106. fore200e->virt_base,
  2107. fore200e->esi[0], fore200e->esi[1], fore200e->esi[2],
  2108. fore200e->esi[3], fore200e->esi[4], fore200e->esi[5],
  2109. fore200e->esi[4] * 256 + fore200e->esi[5]);
  2110. return len;
  2111. }
  2112. if (!left--)
  2113. return sprintf(page,
  2114. " free small bufs, scheme 1:\t%d\n"
  2115. " free large bufs, scheme 1:\t%d\n"
  2116. " free small bufs, scheme 2:\t%d\n"
  2117. " free large bufs, scheme 2:\t%d\n",
  2118. fore200e->host_bsq[ BUFFER_SCHEME_ONE ][ BUFFER_MAGN_SMALL ].freebuf_count,
  2119. fore200e->host_bsq[ BUFFER_SCHEME_ONE ][ BUFFER_MAGN_LARGE ].freebuf_count,
  2120. fore200e->host_bsq[ BUFFER_SCHEME_TWO ][ BUFFER_MAGN_SMALL ].freebuf_count,
  2121. fore200e->host_bsq[ BUFFER_SCHEME_TWO ][ BUFFER_MAGN_LARGE ].freebuf_count);
  2122. if (!left--) {
  2123. u32 hb = fore200e->bus->read(&fore200e->cp_queues->heartbeat);
  2124. len = sprintf(page,"\n\n"
  2125. " cell processor:\n"
  2126. " heartbeat state:\t\t");
  2127. if (hb >> 16 != 0xDEAD)
  2128. len += sprintf(page + len, "0x%08x\n", hb);
  2129. else
  2130. len += sprintf(page + len, "*** FATAL ERROR %04x ***\n", hb & 0xFFFF);
  2131. return len;
  2132. }
  2133. if (!left--) {
  2134. static const char* media_name[] = {
  2135. "unshielded twisted pair",
  2136. "multimode optical fiber ST",
  2137. "multimode optical fiber SC",
  2138. "single-mode optical fiber ST",
  2139. "single-mode optical fiber SC",
  2140. "unknown"
  2141. };
  2142. static const char* oc3_mode[] = {
  2143. "normal operation",
  2144. "diagnostic loopback",
  2145. "line loopback",
  2146. "unknown"
  2147. };
  2148. u32 fw_release = fore200e->bus->read(&fore200e->cp_queues->fw_release);
  2149. u32 mon960_release = fore200e->bus->read(&fore200e->cp_queues->mon960_release);
  2150. u32 oc3_revision = fore200e->bus->read(&fore200e->cp_queues->oc3_revision);
  2151. u32 media_index = FORE200E_MEDIA_INDEX(fore200e->bus->read(&fore200e->cp_queues->media_type));
  2152. u32 oc3_index;
  2153. if ((media_index < 0) || (media_index > 4))
  2154. media_index = 5;
  2155. switch (fore200e->loop_mode) {
  2156. case ATM_LM_NONE: oc3_index = 0;
  2157. break;
  2158. case ATM_LM_LOC_PHY: oc3_index = 1;
  2159. break;
  2160. case ATM_LM_RMT_PHY: oc3_index = 2;
  2161. break;
  2162. default: oc3_index = 3;
  2163. }
  2164. return sprintf(page,
  2165. " firmware release:\t\t%d.%d.%d\n"
  2166. " monitor release:\t\t%d.%d\n"
  2167. " media type:\t\t\t%s\n"
  2168. " OC-3 revision:\t\t0x%x\n"
  2169. " OC-3 mode:\t\t\t%s",
  2170. fw_release >> 16, fw_release << 16 >> 24, fw_release << 24 >> 24,
  2171. mon960_release >> 16, mon960_release << 16 >> 16,
  2172. media_name[ media_index ],
  2173. oc3_revision,
  2174. oc3_mode[ oc3_index ]);
  2175. }
  2176. if (!left--) {
  2177. struct cp_monitor __iomem * cp_monitor = fore200e->cp_monitor;
  2178. return sprintf(page,
  2179. "\n\n"
  2180. " monitor:\n"
  2181. " version number:\t\t%d\n"
  2182. " boot status word:\t\t0x%08x\n",
  2183. fore200e->bus->read(&cp_monitor->mon_version),
  2184. fore200e->bus->read(&cp_monitor->bstat));
  2185. }
  2186. if (!left--)
  2187. return sprintf(page,
  2188. "\n"
  2189. " device statistics:\n"
  2190. " 4b5b:\n"
  2191. " crc_header_errors:\t\t%10u\n"
  2192. " framing_errors:\t\t%10u\n",
  2193. cpu_to_be32(fore200e->stats->phy.crc_header_errors),
  2194. cpu_to_be32(fore200e->stats->phy.framing_errors));
  2195. if (!left--)
  2196. return sprintf(page, "\n"
  2197. " OC-3:\n"
  2198. " section_bip8_errors:\t%10u\n"
  2199. " path_bip8_errors:\t\t%10u\n"
  2200. " line_bip24_errors:\t\t%10u\n"
  2201. " line_febe_errors:\t\t%10u\n"
  2202. " path_febe_errors:\t\t%10u\n"
  2203. " corr_hcs_errors:\t\t%10u\n"
  2204. " ucorr_hcs_errors:\t\t%10u\n",
  2205. cpu_to_be32(fore200e->stats->oc3.section_bip8_errors),
  2206. cpu_to_be32(fore200e->stats->oc3.path_bip8_errors),
  2207. cpu_to_be32(fore200e->stats->oc3.line_bip24_errors),
  2208. cpu_to_be32(fore200e->stats->oc3.line_febe_errors),
  2209. cpu_to_be32(fore200e->stats->oc3.path_febe_errors),
  2210. cpu_to_be32(fore200e->stats->oc3.corr_hcs_errors),
  2211. cpu_to_be32(fore200e->stats->oc3.ucorr_hcs_errors));
  2212. if (!left--)
  2213. return sprintf(page,"\n"
  2214. " ATM:\t\t\t\t cells\n"
  2215. " TX:\t\t\t%10u\n"
  2216. " RX:\t\t\t%10u\n"
  2217. " vpi out of range:\t\t%10u\n"
  2218. " vpi no conn:\t\t%10u\n"
  2219. " vci out of range:\t\t%10u\n"
  2220. " vci no conn:\t\t%10u\n",
  2221. cpu_to_be32(fore200e->stats->atm.cells_transmitted),
  2222. cpu_to_be32(fore200e->stats->atm.cells_received),
  2223. cpu_to_be32(fore200e->stats->atm.vpi_bad_range),
  2224. cpu_to_be32(fore200e->stats->atm.vpi_no_conn),
  2225. cpu_to_be32(fore200e->stats->atm.vci_bad_range),
  2226. cpu_to_be32(fore200e->stats->atm.vci_no_conn));
  2227. if (!left--)
  2228. return sprintf(page,"\n"
  2229. " AAL0:\t\t\t cells\n"
  2230. " TX:\t\t\t%10u\n"
  2231. " RX:\t\t\t%10u\n"
  2232. " dropped:\t\t\t%10u\n",
  2233. cpu_to_be32(fore200e->stats->aal0.cells_transmitted),
  2234. cpu_to_be32(fore200e->stats->aal0.cells_received),
  2235. cpu_to_be32(fore200e->stats->aal0.cells_dropped));
  2236. if (!left--)
  2237. return sprintf(page,"\n"
  2238. " AAL3/4:\n"
  2239. " SAR sublayer:\t\t cells\n"
  2240. " TX:\t\t\t%10u\n"
  2241. " RX:\t\t\t%10u\n"
  2242. " dropped:\t\t\t%10u\n"
  2243. " CRC errors:\t\t%10u\n"
  2244. " protocol errors:\t\t%10u\n\n"
  2245. " CS sublayer:\t\t PDUs\n"
  2246. " TX:\t\t\t%10u\n"
  2247. " RX:\t\t\t%10u\n"
  2248. " dropped:\t\t\t%10u\n"
  2249. " protocol errors:\t\t%10u\n",
  2250. cpu_to_be32(fore200e->stats->aal34.cells_transmitted),
  2251. cpu_to_be32(fore200e->stats->aal34.cells_received),
  2252. cpu_to_be32(fore200e->stats->aal34.cells_dropped),
  2253. cpu_to_be32(fore200e->stats->aal34.cells_crc_errors),
  2254. cpu_to_be32(fore200e->stats->aal34.cells_protocol_errors),
  2255. cpu_to_be32(fore200e->stats->aal34.cspdus_transmitted),
  2256. cpu_to_be32(fore200e->stats->aal34.cspdus_received),
  2257. cpu_to_be32(fore200e->stats->aal34.cspdus_dropped),
  2258. cpu_to_be32(fore200e->stats->aal34.cspdus_protocol_errors));
  2259. if (!left--)
  2260. return sprintf(page,"\n"
  2261. " AAL5:\n"
  2262. " SAR sublayer:\t\t cells\n"
  2263. " TX:\t\t\t%10u\n"
  2264. " RX:\t\t\t%10u\n"
  2265. " dropped:\t\t\t%10u\n"
  2266. " congestions:\t\t%10u\n\n"
  2267. " CS sublayer:\t\t PDUs\n"
  2268. " TX:\t\t\t%10u\n"
  2269. " RX:\t\t\t%10u\n"
  2270. " dropped:\t\t\t%10u\n"
  2271. " CRC errors:\t\t%10u\n"
  2272. " protocol errors:\t\t%10u\n",
  2273. cpu_to_be32(fore200e->stats->aal5.cells_transmitted),
  2274. cpu_to_be32(fore200e->stats->aal5.cells_received),
  2275. cpu_to_be32(fore200e->stats->aal5.cells_dropped),
  2276. cpu_to_be32(fore200e->stats->aal5.congestion_experienced),
  2277. cpu_to_be32(fore200e->stats->aal5.cspdus_transmitted),
  2278. cpu_to_be32(fore200e->stats->aal5.cspdus_received),
  2279. cpu_to_be32(fore200e->stats->aal5.cspdus_dropped),
  2280. cpu_to_be32(fore200e->stats->aal5.cspdus_crc_errors),
  2281. cpu_to_be32(fore200e->stats->aal5.cspdus_protocol_errors));
  2282. if (!left--)
  2283. return sprintf(page,"\n"
  2284. " AUX:\t\t allocation failures\n"
  2285. " small b1:\t\t\t%10u\n"
  2286. " large b1:\t\t\t%10u\n"
  2287. " small b2:\t\t\t%10u\n"
  2288. " large b2:\t\t\t%10u\n"
  2289. " RX PDUs:\t\t\t%10u\n"
  2290. " TX PDUs:\t\t\t%10lu\n",
  2291. cpu_to_be32(fore200e->stats->aux.small_b1_failed),
  2292. cpu_to_be32(fore200e->stats->aux.large_b1_failed),
  2293. cpu_to_be32(fore200e->stats->aux.small_b2_failed),
  2294. cpu_to_be32(fore200e->stats->aux.large_b2_failed),
  2295. cpu_to_be32(fore200e->stats->aux.rpd_alloc_failed),
  2296. fore200e->tx_sat);
  2297. if (!left--)
  2298. return sprintf(page,"\n"
  2299. " receive carrier:\t\t\t%s\n",
  2300. fore200e->stats->aux.receive_carrier ? "ON" : "OFF!");
  2301. if (!left--) {
  2302. return sprintf(page,"\n"
  2303. " VCCs:\n address VPI VCI AAL "
  2304. "TX PDUs TX min/max size RX PDUs RX min/max size\n");
  2305. }
  2306. for (i = 0; i < NBR_CONNECT; i++) {
  2307. vcc = fore200e->vc_map[i].vcc;
  2308. if (vcc == NULL)
  2309. continue;
  2310. spin_lock_irqsave(&fore200e->q_lock, flags);
  2311. if (vcc && test_bit(ATM_VF_READY, &vcc->flags) && !left--) {
  2312. fore200e_vcc = FORE200E_VCC(vcc);
  2313. ASSERT(fore200e_vcc);
  2314. len = sprintf(page,
  2315. " %08x %03d %05d %1d %09lu %05d/%05d %09lu %05d/%05d\n",
  2316. (u32)(unsigned long)vcc,
  2317. vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
  2318. fore200e_vcc->tx_pdu,
  2319. fore200e_vcc->tx_min_pdu > 0xFFFF ? 0 : fore200e_vcc->tx_min_pdu,
  2320. fore200e_vcc->tx_max_pdu,
  2321. fore200e_vcc->rx_pdu,
  2322. fore200e_vcc->rx_min_pdu > 0xFFFF ? 0 : fore200e_vcc->rx_min_pdu,
  2323. fore200e_vcc->rx_max_pdu);
  2324. spin_unlock_irqrestore(&fore200e->q_lock, flags);
  2325. return len;
  2326. }
  2327. spin_unlock_irqrestore(&fore200e->q_lock, flags);
  2328. }
  2329. return 0;
  2330. }
  2331. module_init(fore200e_module_init);
  2332. module_exit(fore200e_module_cleanup);
  2333. static const struct atmdev_ops fore200e_ops =
  2334. {
  2335. .open = fore200e_open,
  2336. .close = fore200e_close,
  2337. .ioctl = fore200e_ioctl,
  2338. .getsockopt = fore200e_getsockopt,
  2339. .setsockopt = fore200e_setsockopt,
  2340. .send = fore200e_send,
  2341. .change_qos = fore200e_change_qos,
  2342. .proc_read = fore200e_proc_read,
  2343. .owner = THIS_MODULE
  2344. };
  2345. #ifdef CONFIG_ATM_FORE200E_PCA
  2346. extern const unsigned char _fore200e_pca_fw_data[];
  2347. extern const unsigned int _fore200e_pca_fw_size;
  2348. #endif
  2349. #ifdef CONFIG_ATM_FORE200E_SBA
  2350. extern const unsigned char _fore200e_sba_fw_data[];
  2351. extern const unsigned int _fore200e_sba_fw_size;
  2352. #endif
  2353. static const struct fore200e_bus fore200e_bus[] = {
  2354. #ifdef CONFIG_ATM_FORE200E_PCA
  2355. { "PCA-200E", "pca200e", 32, 4, 32,
  2356. _fore200e_pca_fw_data, &_fore200e_pca_fw_size,
  2357. fore200e_pca_read,
  2358. fore200e_pca_write,
  2359. fore200e_pca_dma_map,
  2360. fore200e_pca_dma_unmap,
  2361. fore200e_pca_dma_sync_for_cpu,
  2362. fore200e_pca_dma_sync_for_device,
  2363. fore200e_pca_dma_chunk_alloc,
  2364. fore200e_pca_dma_chunk_free,
  2365. NULL,
  2366. fore200e_pca_configure,
  2367. fore200e_pca_map,
  2368. fore200e_pca_reset,
  2369. fore200e_pca_prom_read,
  2370. fore200e_pca_unmap,
  2371. NULL,
  2372. fore200e_pca_irq_check,
  2373. fore200e_pca_irq_ack,
  2374. fore200e_pca_proc_read,
  2375. },
  2376. #endif
  2377. #ifdef CONFIG_ATM_FORE200E_SBA
  2378. { "SBA-200E", "sba200e", 32, 64, 32,
  2379. _fore200e_sba_fw_data, &_fore200e_sba_fw_size,
  2380. fore200e_sba_read,
  2381. fore200e_sba_write,
  2382. fore200e_sba_dma_map,
  2383. fore200e_sba_dma_unmap,
  2384. fore200e_sba_dma_sync_for_cpu,
  2385. fore200e_sba_dma_sync_for_device,
  2386. fore200e_sba_dma_chunk_alloc,
  2387. fore200e_sba_dma_chunk_free,
  2388. fore200e_sba_detect,
  2389. fore200e_sba_configure,
  2390. fore200e_sba_map,
  2391. fore200e_sba_reset,
  2392. fore200e_sba_prom_read,
  2393. fore200e_sba_unmap,
  2394. fore200e_sba_irq_enable,
  2395. fore200e_sba_irq_check,
  2396. fore200e_sba_irq_ack,
  2397. fore200e_sba_proc_read,
  2398. },
  2399. #endif
  2400. {}
  2401. };
  2402. #ifdef MODULE_LICENSE
  2403. MODULE_LICENSE("GPL");
  2404. #endif