fore200e.c 83 KB

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