fore200e.c 89 KB

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