You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

etherfabric.c 111KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225
  1. /**************************************************************************
  2. *
  3. * Etherboot driver for Level 5 Etherfabric network cards
  4. *
  5. * Written by Michael Brown <mbrown@fensystems.co.uk>
  6. *
  7. * Copyright Fen Systems Ltd. 2005
  8. * Copyright Level 5 Networks Inc. 2005
  9. *
  10. * This software may be used and distributed according to the terms of
  11. * the GNU General Public License (GPL), incorporated herein by
  12. * reference. Drivers based on or derived from this code fall under
  13. * the GPL and must retain the authorship, copyright and license
  14. * notice.
  15. *
  16. **************************************************************************
  17. */
  18. FILE_LICENCE ( GPL_ANY );
  19. #include <stdint.h>
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <unistd.h>
  23. #include <errno.h>
  24. #include <assert.h>
  25. #include <byteswap.h>
  26. #include <ipxe/io.h>
  27. #include <ipxe/pci.h>
  28. #include <ipxe/malloc.h>
  29. #include <ipxe/ethernet.h>
  30. #include <ipxe/iobuf.h>
  31. #include <ipxe/netdevice.h>
  32. #include <ipxe/timer.h>
  33. #include <mii.h>
  34. #include "etherfabric.h"
  35. #include "etherfabric_nic.h"
  36. /**************************************************************************
  37. *
  38. * Constants and macros
  39. *
  40. **************************************************************************
  41. */
  42. #define EFAB_REGDUMP(...)
  43. #define EFAB_TRACE(...) DBGP(__VA_ARGS__)
  44. // printf() is not allowed within drivers. Use DBG() instead.
  45. #define EFAB_LOG(...) DBG(__VA_ARGS__)
  46. #define EFAB_ERR(...) DBG(__VA_ARGS__)
  47. #define FALCON_USE_IO_BAR 0
  48. #define HZ 100
  49. #define EFAB_BYTE 1
  50. /**************************************************************************
  51. *
  52. * Hardware data structures and sizing
  53. *
  54. **************************************************************************
  55. */
  56. extern int __invalid_queue_size;
  57. #define FQS(_prefix, _x) \
  58. ( ( (_x) == 512 ) ? _prefix ## _SIZE_512 : \
  59. ( ( (_x) == 1024 ) ? _prefix ## _SIZE_1K : \
  60. ( ( (_x) == 2048 ) ? _prefix ## _SIZE_2K : \
  61. ( ( (_x) == 4096) ? _prefix ## _SIZE_4K : \
  62. __invalid_queue_size ) ) ) )
  63. #define EFAB_MAX_FRAME_LEN(mtu) \
  64. ( ( ( ( mtu ) + 4/* FCS */ ) + 7 ) & ~7 )
  65. /**************************************************************************
  66. *
  67. * GMII routines
  68. *
  69. **************************************************************************
  70. */
  71. static void falcon_mdio_write (struct efab_nic *efab, int device,
  72. int location, int value );
  73. static int falcon_mdio_read ( struct efab_nic *efab, int device, int location );
  74. /* GMII registers */
  75. #define GMII_PSSR 0x11 /* PHY-specific status register */
  76. /* Pseudo extensions to the link partner ability register */
  77. #define LPA_EF_1000FULL 0x00020000
  78. #define LPA_EF_1000HALF 0x00010000
  79. #define LPA_EF_10000FULL 0x00040000
  80. #define LPA_EF_10000HALF 0x00080000
  81. #define LPA_100 (LPA_100FULL | LPA_100HALF | LPA_100BASE4)
  82. #define LPA_EF_1000 ( LPA_EF_1000FULL | LPA_EF_1000HALF )
  83. #define LPA_EF_10000 ( LPA_EF_10000FULL | LPA_EF_10000HALF )
  84. #define LPA_EF_DUPLEX ( LPA_10FULL | LPA_100FULL | LPA_EF_1000FULL | \
  85. LPA_EF_10000FULL )
  86. /* Mask of bits not associated with speed or duplexity. */
  87. #define LPA_OTHER ~( LPA_10FULL | LPA_10HALF | LPA_100FULL | \
  88. LPA_100HALF | LPA_EF_1000FULL | LPA_EF_1000HALF )
  89. /* PHY-specific status register */
  90. #define PSSR_LSTATUS 0x0400 /* Bit 10 - link status */
  91. /**
  92. * Retrieve GMII autonegotiation advertised abilities
  93. *
  94. */
  95. static unsigned int
  96. gmii_autoneg_advertised ( struct efab_nic *efab )
  97. {
  98. unsigned int mii_advertise;
  99. unsigned int gmii_advertise;
  100. /* Extended bits are in bits 8 and 9 of MII_CTRL1000 */
  101. mii_advertise = falcon_mdio_read ( efab, 0, MII_ADVERTISE );
  102. gmii_advertise = ( ( falcon_mdio_read ( efab, 0, MII_CTRL1000 ) >> 8 )
  103. & 0x03 );
  104. return ( ( gmii_advertise << 16 ) | mii_advertise );
  105. }
  106. /**
  107. * Retrieve GMII autonegotiation link partner abilities
  108. *
  109. */
  110. static unsigned int
  111. gmii_autoneg_lpa ( struct efab_nic *efab )
  112. {
  113. unsigned int mii_lpa;
  114. unsigned int gmii_lpa;
  115. /* Extended bits are in bits 10 and 11 of MII_STAT1000 */
  116. mii_lpa = falcon_mdio_read ( efab, 0, MII_LPA );
  117. gmii_lpa = ( falcon_mdio_read ( efab, 0, MII_STAT1000 ) >> 10 ) & 0x03;
  118. return ( ( gmii_lpa << 16 ) | mii_lpa );
  119. }
  120. /**
  121. * Calculate GMII autonegotiated link technology
  122. *
  123. */
  124. static unsigned int
  125. gmii_nway_result ( unsigned int negotiated )
  126. {
  127. unsigned int other_bits;
  128. /* Mask out the speed and duplexity bits */
  129. other_bits = negotiated & LPA_OTHER;
  130. if ( negotiated & LPA_EF_1000FULL )
  131. return ( other_bits | LPA_EF_1000FULL );
  132. else if ( negotiated & LPA_EF_1000HALF )
  133. return ( other_bits | LPA_EF_1000HALF );
  134. else if ( negotiated & LPA_100FULL )
  135. return ( other_bits | LPA_100FULL );
  136. else if ( negotiated & LPA_100BASE4 )
  137. return ( other_bits | LPA_100BASE4 );
  138. else if ( negotiated & LPA_100HALF )
  139. return ( other_bits | LPA_100HALF );
  140. else if ( negotiated & LPA_10FULL )
  141. return ( other_bits | LPA_10FULL );
  142. else return ( other_bits | LPA_10HALF );
  143. }
  144. /**
  145. * Check GMII PHY link status
  146. *
  147. */
  148. static int
  149. gmii_link_ok ( struct efab_nic *efab )
  150. {
  151. int status;
  152. int phy_status;
  153. /* BMSR is latching - it returns "link down" if the link has
  154. * been down at any point since the last read. To get a
  155. * real-time status, we therefore read the register twice and
  156. * use the result of the second read.
  157. */
  158. (void) falcon_mdio_read ( efab, 0, MII_BMSR );
  159. status = falcon_mdio_read ( efab, 0, MII_BMSR );
  160. /* Read the PHY-specific Status Register. This is
  161. * non-latching, so we need do only a single read.
  162. */
  163. phy_status = falcon_mdio_read ( efab, 0, GMII_PSSR );
  164. return ( ( status & BMSR_LSTATUS ) && ( phy_status & PSSR_LSTATUS ) );
  165. }
  166. /**************************************************************************
  167. *
  168. * MDIO routines
  169. *
  170. **************************************************************************
  171. */
  172. /* Numbering of the MDIO Manageable Devices (MMDs) */
  173. /* Physical Medium Attachment/ Physical Medium Dependent sublayer */
  174. #define MDIO_MMD_PMAPMD (1)
  175. /* WAN Interface Sublayer */
  176. #define MDIO_MMD_WIS (2)
  177. /* Physical Coding Sublayer */
  178. #define MDIO_MMD_PCS (3)
  179. /* PHY Extender Sublayer */
  180. #define MDIO_MMD_PHYXS (4)
  181. /* Extender Sublayer */
  182. #define MDIO_MMD_DTEXS (5)
  183. /* Transmission convergence */
  184. #define MDIO_MMD_TC (6)
  185. /* Auto negotiation */
  186. #define MDIO_MMD_AN (7)
  187. /* Generic register locations */
  188. #define MDIO_MMDREG_CTRL1 (0)
  189. #define MDIO_MMDREG_STAT1 (1)
  190. #define MDIO_MMDREG_DEVS0 (5)
  191. #define MDIO_MMDREG_STAT2 (8)
  192. /* Bits in MMDREG_CTRL1 */
  193. /* Reset */
  194. #define MDIO_MMDREG_CTRL1_RESET_LBN (15)
  195. #define MDIO_MMDREG_CTRL1_RESET_WIDTH (1)
  196. /* Bits in MMDREG_STAT1 */
  197. #define MDIO_MMDREG_STAT1_FAULT_LBN (7)
  198. #define MDIO_MMDREG_STAT1_FAULT_WIDTH (1)
  199. /* Link state */
  200. #define MDIO_MMDREG_STAT1_LINK_LBN (2)
  201. #define MDIO_MMDREG_STAT1_LINK_WIDTH (1)
  202. /* Bits in MMDREG_DEVS0. */
  203. #define DEV_PRESENT_BIT(_b) (1 << _b)
  204. #define MDIO_MMDREG_DEVS0_DTEXS DEV_PRESENT_BIT(MDIO_MMD_DTEXS)
  205. #define MDIO_MMDREG_DEVS0_PHYXS DEV_PRESENT_BIT(MDIO_MMD_PHYXS)
  206. #define MDIO_MMDREG_DEVS0_PCS DEV_PRESENT_BIT(MDIO_MMD_PCS)
  207. #define MDIO_MMDREG_DEVS0_WIS DEV_PRESENT_BIT(MDIO_MMD_WIS)
  208. #define MDIO_MMDREG_DEVS0_PMAPMD DEV_PRESENT_BIT(MDIO_MMD_PMAPMD)
  209. #define MDIO_MMDREG_DEVS0_AN DEV_PRESENT_BIT(MDIO_MMD_AN)
  210. /* Bits in MMDREG_STAT2 */
  211. #define MDIO_MMDREG_STAT2_PRESENT_VAL (2)
  212. #define MDIO_MMDREG_STAT2_PRESENT_LBN (14)
  213. #define MDIO_MMDREG_STAT2_PRESENT_WIDTH (2)
  214. /* PHY XGXS lane state */
  215. #define MDIO_PHYXS_LANE_STATE (0x18)
  216. #define MDIO_PHYXS_LANE_ALIGNED_LBN (12)
  217. #define MDIO_PHYXS_LANE_SYNC0_LBN (0)
  218. #define MDIO_PHYXS_LANE_SYNC1_LBN (1)
  219. #define MDIO_PHYXS_LANE_SYNC2_LBN (2)
  220. #define MDIO_PHYXS_LANE_SYNC3_LBN (3)
  221. /* This ought to be ridiculous overkill. We expect it to fail rarely */
  222. #define MDIO45_RESET_TRIES 100
  223. #define MDIO45_RESET_SPINTIME 10
  224. static int
  225. mdio_clause45_wait_reset_mmds ( struct efab_nic* efab )
  226. {
  227. int tries = MDIO45_RESET_TRIES;
  228. int in_reset;
  229. while(tries) {
  230. int mask = efab->phy_op->mmds;
  231. int mmd = 0;
  232. in_reset = 0;
  233. while(mask) {
  234. if (mask & 1) {
  235. int stat = falcon_mdio_read ( efab, mmd,
  236. MDIO_MMDREG_CTRL1 );
  237. if (stat < 0) {
  238. EFAB_ERR("Failed to read status of MMD %d\n",
  239. mmd );
  240. in_reset = 1;
  241. break;
  242. }
  243. if (stat & (1 << MDIO_MMDREG_CTRL1_RESET_LBN))
  244. in_reset |= (1 << mmd);
  245. }
  246. mask = mask >> 1;
  247. mmd++;
  248. }
  249. if (!in_reset)
  250. break;
  251. tries--;
  252. mdelay ( MDIO45_RESET_SPINTIME );
  253. }
  254. if (in_reset != 0) {
  255. EFAB_ERR("Not all MMDs came out of reset in time. MMDs "
  256. "still in reset: %x\n", in_reset);
  257. return -ETIMEDOUT;
  258. }
  259. return 0;
  260. }
  261. static int
  262. mdio_clause45_reset_mmd ( struct efab_nic *efab, int mmd )
  263. {
  264. int tries = MDIO45_RESET_TRIES;
  265. int ctrl;
  266. falcon_mdio_write ( efab, mmd, MDIO_MMDREG_CTRL1,
  267. ( 1 << MDIO_MMDREG_CTRL1_RESET_LBN ) );
  268. /* Wait for the reset bit to clear. */
  269. do {
  270. mdelay ( MDIO45_RESET_SPINTIME );
  271. ctrl = falcon_mdio_read ( efab, mmd, MDIO_MMDREG_CTRL1 );
  272. if ( ~ctrl & ( 1 << MDIO_MMDREG_CTRL1_RESET_LBN ) )
  273. return 0;
  274. } while ( --tries );
  275. EFAB_ERR ( "Failed to reset mmd %d\n", mmd );
  276. return -ETIMEDOUT;
  277. }
  278. static int
  279. mdio_clause45_links_ok(struct efab_nic *efab )
  280. {
  281. int status, good;
  282. int ok = 1;
  283. int mmd = 0;
  284. int mmd_mask = efab->phy_op->mmds;
  285. while (mmd_mask) {
  286. if (mmd_mask & 1) {
  287. /* Double reads because link state is latched, and a
  288. * read moves the current state into the register */
  289. status = falcon_mdio_read ( efab, mmd,
  290. MDIO_MMDREG_STAT1 );
  291. status = falcon_mdio_read ( efab, mmd,
  292. MDIO_MMDREG_STAT1 );
  293. good = status & (1 << MDIO_MMDREG_STAT1_LINK_LBN);
  294. ok = ok && good;
  295. }
  296. mmd_mask = (mmd_mask >> 1);
  297. mmd++;
  298. }
  299. return ok;
  300. }
  301. static int
  302. mdio_clause45_check_mmds ( struct efab_nic *efab )
  303. {
  304. int mmd = 0;
  305. int devices = falcon_mdio_read ( efab, MDIO_MMD_PHYXS,
  306. MDIO_MMDREG_DEVS0 );
  307. int mmd_mask = efab->phy_op->mmds;
  308. /* Check all the expected MMDs are present */
  309. if ( devices < 0 ) {
  310. EFAB_ERR ( "Failed to read devices present\n" );
  311. return -EIO;
  312. }
  313. if ( ( devices & mmd_mask ) != mmd_mask ) {
  314. EFAB_ERR ( "required MMDs not present: got %x, wanted %x\n",
  315. devices, mmd_mask );
  316. return -EIO;
  317. }
  318. /* Check all required MMDs are responding and happy. */
  319. while ( mmd_mask ) {
  320. if ( mmd_mask & 1 ) {
  321. efab_dword_t reg;
  322. int status;
  323. reg.opaque = falcon_mdio_read ( efab, mmd,
  324. MDIO_MMDREG_STAT2 );
  325. status = EFAB_DWORD_FIELD ( reg,
  326. MDIO_MMDREG_STAT2_PRESENT );
  327. if ( status != MDIO_MMDREG_STAT2_PRESENT_VAL ) {
  328. return -EIO;
  329. }
  330. }
  331. mmd_mask >>= 1;
  332. mmd++;
  333. }
  334. return 0;
  335. }
  336. /* I/O BAR address register */
  337. #define FCN_IOM_IND_ADR_REG 0x0
  338. /* I/O BAR data register */
  339. #define FCN_IOM_IND_DAT_REG 0x4
  340. /* Address region register */
  341. #define FCN_ADR_REGION_REG_KER 0x00
  342. #define FCN_ADR_REGION0_LBN 0
  343. #define FCN_ADR_REGION0_WIDTH 18
  344. #define FCN_ADR_REGION1_LBN 32
  345. #define FCN_ADR_REGION1_WIDTH 18
  346. #define FCN_ADR_REGION2_LBN 64
  347. #define FCN_ADR_REGION2_WIDTH 18
  348. #define FCN_ADR_REGION3_LBN 96
  349. #define FCN_ADR_REGION3_WIDTH 18
  350. /* Interrupt enable register */
  351. #define FCN_INT_EN_REG_KER 0x0010
  352. #define FCN_MEM_PERR_INT_EN_KER_LBN 5
  353. #define FCN_MEM_PERR_INT_EN_KER_WIDTH 1
  354. #define FCN_KER_INT_CHAR_LBN 4
  355. #define FCN_KER_INT_CHAR_WIDTH 1
  356. #define FCN_KER_INT_KER_LBN 3
  357. #define FCN_KER_INT_KER_WIDTH 1
  358. #define FCN_ILL_ADR_ERR_INT_EN_KER_LBN 2
  359. #define FCN_ILL_ADR_ERR_INT_EN_KER_WIDTH 1
  360. #define FCN_SRM_PERR_INT_EN_KER_LBN 1
  361. #define FCN_SRM_PERR_INT_EN_KER_WIDTH 1
  362. #define FCN_DRV_INT_EN_KER_LBN 0
  363. #define FCN_DRV_INT_EN_KER_WIDTH 1
  364. /* Interrupt status register */
  365. #define FCN_INT_ADR_REG_KER 0x0030
  366. #define FCN_INT_ADR_KER_LBN 0
  367. #define FCN_INT_ADR_KER_WIDTH EFAB_DMA_TYPE_WIDTH ( 64 )
  368. /* Interrupt status register (B0 only) */
  369. #define INT_ISR0_B0 0x90
  370. #define INT_ISR1_B0 0xA0
  371. /* Interrupt acknowledge register (A0/A1 only) */
  372. #define FCN_INT_ACK_KER_REG_A1 0x0050
  373. #define INT_ACK_DUMMY_DATA_LBN 0
  374. #define INT_ACK_DUMMY_DATA_WIDTH 32
  375. /* Interrupt acknowledge work-around register (A0/A1 only )*/
  376. #define WORK_AROUND_BROKEN_PCI_READS_REG_KER_A1 0x0070
  377. /* Hardware initialisation register */
  378. #define FCN_HW_INIT_REG_KER 0x00c0
  379. #define FCN_BCSR_TARGET_MASK_LBN 101
  380. #define FCN_BCSR_TARGET_MASK_WIDTH 4
  381. /* SPI host command register */
  382. #define FCN_EE_SPI_HCMD_REG 0x0100
  383. #define FCN_EE_SPI_HCMD_CMD_EN_LBN 31
  384. #define FCN_EE_SPI_HCMD_CMD_EN_WIDTH 1
  385. #define FCN_EE_WR_TIMER_ACTIVE_LBN 28
  386. #define FCN_EE_WR_TIMER_ACTIVE_WIDTH 1
  387. #define FCN_EE_SPI_HCMD_SF_SEL_LBN 24
  388. #define FCN_EE_SPI_HCMD_SF_SEL_WIDTH 1
  389. #define FCN_EE_SPI_EEPROM 0
  390. #define FCN_EE_SPI_FLASH 1
  391. #define FCN_EE_SPI_HCMD_DABCNT_LBN 16
  392. #define FCN_EE_SPI_HCMD_DABCNT_WIDTH 5
  393. #define FCN_EE_SPI_HCMD_READ_LBN 15
  394. #define FCN_EE_SPI_HCMD_READ_WIDTH 1
  395. #define FCN_EE_SPI_READ 1
  396. #define FCN_EE_SPI_WRITE 0
  397. #define FCN_EE_SPI_HCMD_DUBCNT_LBN 12
  398. #define FCN_EE_SPI_HCMD_DUBCNT_WIDTH 2
  399. #define FCN_EE_SPI_HCMD_ADBCNT_LBN 8
  400. #define FCN_EE_SPI_HCMD_ADBCNT_WIDTH 2
  401. #define FCN_EE_SPI_HCMD_ENC_LBN 0
  402. #define FCN_EE_SPI_HCMD_ENC_WIDTH 8
  403. /* SPI host address register */
  404. #define FCN_EE_SPI_HADR_REG 0x0110
  405. #define FCN_EE_SPI_HADR_DUBYTE_LBN 24
  406. #define FCN_EE_SPI_HADR_DUBYTE_WIDTH 8
  407. #define FCN_EE_SPI_HADR_ADR_LBN 0
  408. #define FCN_EE_SPI_HADR_ADR_WIDTH 24
  409. /* SPI host data register */
  410. #define FCN_EE_SPI_HDATA_REG 0x0120
  411. #define FCN_EE_SPI_HDATA3_LBN 96
  412. #define FCN_EE_SPI_HDATA3_WIDTH 32
  413. #define FCN_EE_SPI_HDATA2_LBN 64
  414. #define FCN_EE_SPI_HDATA2_WIDTH 32
  415. #define FCN_EE_SPI_HDATA1_LBN 32
  416. #define FCN_EE_SPI_HDATA1_WIDTH 32
  417. #define FCN_EE_SPI_HDATA0_LBN 0
  418. #define FCN_EE_SPI_HDATA0_WIDTH 32
  419. /* VPD Config 0 Register register */
  420. #define FCN_EE_VPD_CFG_REG 0x0140
  421. #define FCN_EE_VPD_EN_LBN 0
  422. #define FCN_EE_VPD_EN_WIDTH 1
  423. #define FCN_EE_VPD_EN_AD9_MODE_LBN 1
  424. #define FCN_EE_VPD_EN_AD9_MODE_WIDTH 1
  425. #define FCN_EE_EE_CLOCK_DIV_LBN 112
  426. #define FCN_EE_EE_CLOCK_DIV_WIDTH 7
  427. #define FCN_EE_SF_CLOCK_DIV_LBN 120
  428. #define FCN_EE_SF_CLOCK_DIV_WIDTH 7
  429. /* NIC status register */
  430. #define FCN_NIC_STAT_REG 0x0200
  431. #define FCN_ONCHIP_SRAM_LBN 16
  432. #define FCN_ONCHIP_SRAM_WIDTH 1
  433. #define FCN_SF_PRST_LBN 9
  434. #define FCN_SF_PRST_WIDTH 1
  435. #define FCN_EE_PRST_LBN 8
  436. #define FCN_EE_PRST_WIDTH 1
  437. #define FCN_EE_STRAP_LBN 7
  438. #define FCN_EE_STRAP_WIDTH 1
  439. #define FCN_PCI_PCIX_MODE_LBN 4
  440. #define FCN_PCI_PCIX_MODE_WIDTH 3
  441. #define FCN_PCI_PCIX_MODE_PCI33_DECODE 0
  442. #define FCN_PCI_PCIX_MODE_PCI66_DECODE 1
  443. #define FCN_PCI_PCIX_MODE_PCIX66_DECODE 5
  444. #define FCN_PCI_PCIX_MODE_PCIX100_DECODE 6
  445. #define FCN_PCI_PCIX_MODE_PCIX133_DECODE 7
  446. #define FCN_STRAP_ISCSI_EN_LBN 3
  447. #define FCN_STRAP_ISCSI_EN_WIDTH 1
  448. #define FCN_STRAP_PINS_LBN 0
  449. #define FCN_STRAP_PINS_WIDTH 3
  450. #define FCN_STRAP_10G_LBN 2
  451. #define FCN_STRAP_10G_WIDTH 1
  452. #define FCN_STRAP_DUAL_PORT_LBN 1
  453. #define FCN_STRAP_DUAL_PORT_WIDTH 1
  454. #define FCN_STRAP_PCIE_LBN 0
  455. #define FCN_STRAP_PCIE_WIDTH 1
  456. /* Falcon revisions */
  457. #define FALCON_REV_A0 0
  458. #define FALCON_REV_A1 1
  459. #define FALCON_REV_B0 2
  460. /* GPIO control register */
  461. #define FCN_GPIO_CTL_REG_KER 0x0210
  462. #define FCN_GPIO_CTL_REG_KER 0x0210
  463. #define FCN_GPIO3_OEN_LBN 27
  464. #define FCN_GPIO3_OEN_WIDTH 1
  465. #define FCN_GPIO2_OEN_LBN 26
  466. #define FCN_GPIO2_OEN_WIDTH 1
  467. #define FCN_GPIO1_OEN_LBN 25
  468. #define FCN_GPIO1_OEN_WIDTH 1
  469. #define FCN_GPIO0_OEN_LBN 24
  470. #define FCN_GPIO0_OEN_WIDTH 1
  471. #define FCN_GPIO3_OUT_LBN 19
  472. #define FCN_GPIO3_OUT_WIDTH 1
  473. #define FCN_GPIO2_OUT_LBN 18
  474. #define FCN_GPIO2_OUT_WIDTH 1
  475. #define FCN_GPIO1_OUT_LBN 17
  476. #define FCN_GPIO1_OUT_WIDTH 1
  477. #define FCN_GPIO0_OUT_LBN 16
  478. #define FCN_GPIO0_OUT_WIDTH 1
  479. #define FCN_GPIO3_IN_LBN 11
  480. #define FCN_GPIO3_IN_WIDTH 1
  481. #define FCN_GPIO2_IN_LBN 10
  482. #define FCN_GPIO2_IN_WIDTH 1
  483. #define FCN_GPIO1_IN_LBN 9
  484. #define FCN_GPIO1_IN_WIDTH 1
  485. #define FCN_GPIO0_IN_LBN 8
  486. #define FCN_GPIO0_IN_WIDTH 1
  487. #define FCN_FLASH_PRESENT_LBN 7
  488. #define FCN_FLASH_PRESENT_WIDTH 1
  489. #define FCN_EEPROM_PRESENT_LBN 6
  490. #define FCN_EEPROM_PRESENT_WIDTH 1
  491. #define FCN_BOOTED_USING_NVDEVICE_LBN 3
  492. #define FCN_BOOTED_USING_NVDEVICE_WIDTH 1
  493. /* Defines for extra non-volatile storage */
  494. #define FCN_NV_MAGIC_NUMBER 0xFA1C
  495. /* Global control register */
  496. #define FCN_GLB_CTL_REG_KER 0x0220
  497. #define FCN_EXT_PHY_RST_CTL_LBN 63
  498. #define FCN_EXT_PHY_RST_CTL_WIDTH 1
  499. #define FCN_PCIE_SD_RST_CTL_LBN 61
  500. #define FCN_PCIE_SD_RST_CTL_WIDTH 1
  501. #define FCN_PCIE_STCK_RST_CTL_LBN 59
  502. #define FCN_PCIE_STCK_RST_CTL_WIDTH 1
  503. #define FCN_PCIE_NSTCK_RST_CTL_LBN 58
  504. #define FCN_PCIE_NSTCK_RST_CTL_WIDTH 1
  505. #define FCN_PCIE_CORE_RST_CTL_LBN 57
  506. #define FCN_PCIE_CORE_RST_CTL_WIDTH 1
  507. #define FCN_EE_RST_CTL_LBN 49
  508. #define FCN_EE_RST_CTL_WIDTH 1
  509. #define FCN_RST_EXT_PHY_LBN 31
  510. #define FCN_RST_EXT_PHY_WIDTH 1
  511. #define FCN_EXT_PHY_RST_DUR_LBN 1
  512. #define FCN_EXT_PHY_RST_DUR_WIDTH 3
  513. #define FCN_SWRST_LBN 0
  514. #define FCN_SWRST_WIDTH 1
  515. #define INCLUDE_IN_RESET 0
  516. #define EXCLUDE_FROM_RESET 1
  517. /* FPGA build version */
  518. #define FCN_ALTERA_BUILD_REG_KER 0x0300
  519. #define FCN_VER_MAJOR_LBN 24
  520. #define FCN_VER_MAJOR_WIDTH 8
  521. #define FCN_VER_MINOR_LBN 16
  522. #define FCN_VER_MINOR_WIDTH 8
  523. #define FCN_VER_BUILD_LBN 0
  524. #define FCN_VER_BUILD_WIDTH 16
  525. #define FCN_VER_ALL_LBN 0
  526. #define FCN_VER_ALL_WIDTH 32
  527. /* Spare EEPROM bits register (flash 0x390) */
  528. #define FCN_SPARE_REG_KER 0x310
  529. #define FCN_MEM_PERR_EN_TX_DATA_LBN 72
  530. #define FCN_MEM_PERR_EN_TX_DATA_WIDTH 2
  531. /* Timer table for kernel access */
  532. #define FCN_TIMER_CMD_REG_KER 0x420
  533. #define FCN_TIMER_MODE_LBN 12
  534. #define FCN_TIMER_MODE_WIDTH 2
  535. #define FCN_TIMER_MODE_DIS 0
  536. #define FCN_TIMER_MODE_INT_HLDOFF 1
  537. #define FCN_TIMER_VAL_LBN 0
  538. #define FCN_TIMER_VAL_WIDTH 12
  539. /* Receive configuration register */
  540. #define FCN_RX_CFG_REG_KER 0x800
  541. #define FCN_RX_XOFF_EN_LBN 0
  542. #define FCN_RX_XOFF_EN_WIDTH 1
  543. /* SRAM receive descriptor cache configuration register */
  544. #define FCN_SRM_RX_DC_CFG_REG_KER 0x610
  545. #define FCN_SRM_RX_DC_BASE_ADR_LBN 0
  546. #define FCN_SRM_RX_DC_BASE_ADR_WIDTH 21
  547. /* SRAM transmit descriptor cache configuration register */
  548. #define FCN_SRM_TX_DC_CFG_REG_KER 0x620
  549. #define FCN_SRM_TX_DC_BASE_ADR_LBN 0
  550. #define FCN_SRM_TX_DC_BASE_ADR_WIDTH 21
  551. /* SRAM configuration register */
  552. #define FCN_SRM_CFG_REG_KER 0x630
  553. #define FCN_SRAM_OOB_ADR_INTEN_LBN 5
  554. #define FCN_SRAM_OOB_ADR_INTEN_WIDTH 1
  555. #define FCN_SRAM_OOB_BUF_INTEN_LBN 4
  556. #define FCN_SRAM_OOB_BUF_INTEN_WIDTH 1
  557. #define FCN_SRAM_OOB_BT_INIT_EN_LBN 3
  558. #define FCN_SRAM_OOB_BT_INIT_EN_WIDTH 1
  559. #define FCN_SRM_NUM_BANK_LBN 2
  560. #define FCN_SRM_NUM_BANK_WIDTH 1
  561. #define FCN_SRM_BANK_SIZE_LBN 0
  562. #define FCN_SRM_BANK_SIZE_WIDTH 2
  563. #define FCN_SRM_NUM_BANKS_AND_BANK_SIZE_LBN 0
  564. #define FCN_SRM_NUM_BANKS_AND_BANK_SIZE_WIDTH 3
  565. #define FCN_RX_CFG_REG_KER 0x800
  566. #define FCN_RX_INGR_EN_B0_LBN 47
  567. #define FCN_RX_INGR_EN_B0_WIDTH 1
  568. #define FCN_RX_USR_BUF_SIZE_B0_LBN 19
  569. #define FCN_RX_USR_BUF_SIZE_B0_WIDTH 9
  570. #define FCN_RX_XON_MAC_TH_B0_LBN 10
  571. #define FCN_RX_XON_MAC_TH_B0_WIDTH 9
  572. #define FCN_RX_XOFF_MAC_TH_B0_LBN 1
  573. #define FCN_RX_XOFF_MAC_TH_B0_WIDTH 9
  574. #define FCN_RX_XOFF_MAC_EN_B0_LBN 0
  575. #define FCN_RX_XOFF_MAC_EN_B0_WIDTH 1
  576. #define FCN_RX_USR_BUF_SIZE_A1_LBN 11
  577. #define FCN_RX_USR_BUF_SIZE_A1_WIDTH 9
  578. #define FCN_RX_XON_MAC_TH_A1_LBN 6
  579. #define FCN_RX_XON_MAC_TH_A1_WIDTH 5
  580. #define FCN_RX_XOFF_MAC_TH_A1_LBN 1
  581. #define FCN_RX_XOFF_MAC_TH_A1_WIDTH 5
  582. #define FCN_RX_XOFF_MAC_EN_A1_LBN 0
  583. #define FCN_RX_XOFF_MAC_EN_A1_WIDTH 1
  584. #define FCN_RX_USR_BUF_SIZE_A1_LBN 11
  585. #define FCN_RX_USR_BUF_SIZE_A1_WIDTH 9
  586. #define FCN_RX_XOFF_MAC_EN_A1_LBN 0
  587. #define FCN_RX_XOFF_MAC_EN_A1_WIDTH 1
  588. /* Receive filter control register */
  589. #define FCN_RX_FILTER_CTL_REG_KER 0x810
  590. #define FCN_UDP_FULL_SRCH_LIMIT_LBN 32
  591. #define FCN_UDP_FULL_SRCH_LIMIT_WIDTH 8
  592. #define FCN_NUM_KER_LBN 24
  593. #define FCN_NUM_KER_WIDTH 2
  594. #define FCN_UDP_WILD_SRCH_LIMIT_LBN 16
  595. #define FCN_UDP_WILD_SRCH_LIMIT_WIDTH 8
  596. #define FCN_TCP_WILD_SRCH_LIMIT_LBN 8
  597. #define FCN_TCP_WILD_SRCH_LIMIT_WIDTH 8
  598. #define FCN_TCP_FULL_SRCH_LIMIT_LBN 0
  599. #define FCN_TCP_FULL_SRCH_LIMIT_WIDTH 8
  600. /* RX queue flush register */
  601. #define FCN_RX_FLUSH_DESCQ_REG_KER 0x0820
  602. #define FCN_RX_FLUSH_DESCQ_CMD_LBN 24
  603. #define FCN_RX_FLUSH_DESCQ_CMD_WIDTH 1
  604. #define FCN_RX_FLUSH_DESCQ_LBN 0
  605. #define FCN_RX_FLUSH_DESCQ_WIDTH 12
  606. /* Receive descriptor update register */
  607. #define FCN_RX_DESC_UPD_REG_KER 0x0830
  608. #define FCN_RX_DESC_WPTR_LBN 96
  609. #define FCN_RX_DESC_WPTR_WIDTH 12
  610. #define FCN_RX_DESC_UPD_REG_KER_DWORD ( FCN_RX_DESC_UPD_REG_KER + 12 )
  611. #define FCN_RX_DESC_WPTR_DWORD_LBN 0
  612. #define FCN_RX_DESC_WPTR_DWORD_WIDTH 12
  613. /* Receive descriptor cache configuration register */
  614. #define FCN_RX_DC_CFG_REG_KER 0x840
  615. #define FCN_RX_DC_SIZE_LBN 0
  616. #define FCN_RX_DC_SIZE_WIDTH 2
  617. #define FCN_RX_SELF_RST_REG_KER 0x890
  618. #define FCN_RX_ISCSI_DIS_LBN 17
  619. #define FCN_RX_ISCSI_DIS_WIDTH 1
  620. #define FCN_RX_NODESC_WAIT_DIS_LBN 9
  621. #define FCN_RX_NODESC_WAIT_DIS_WIDTH 1
  622. #define FCN_RX_RECOVERY_EN_LBN 8
  623. #define FCN_RX_RECOVERY_EN_WIDTH 1
  624. /* TX queue flush register */
  625. #define FCN_TX_FLUSH_DESCQ_REG_KER 0x0a00
  626. #define FCN_TX_FLUSH_DESCQ_CMD_LBN 12
  627. #define FCN_TX_FLUSH_DESCQ_CMD_WIDTH 1
  628. #define FCN_TX_FLUSH_DESCQ_LBN 0
  629. #define FCN_TX_FLUSH_DESCQ_WIDTH 12
  630. /* Transmit configuration register 2 */
  631. #define FCN_TX_CFG2_REG_KER 0xa80
  632. #define FCN_TX_DIS_NON_IP_EV_LBN 17
  633. #define FCN_TX_DIS_NON_IP_EV_WIDTH 1
  634. /* Transmit descriptor update register */
  635. #define FCN_TX_DESC_UPD_REG_KER 0x0a10
  636. #define FCN_TX_DESC_WPTR_LBN 96
  637. #define FCN_TX_DESC_WPTR_WIDTH 12
  638. #define FCN_TX_DESC_UPD_REG_KER_DWORD ( FCN_TX_DESC_UPD_REG_KER + 12 )
  639. #define FCN_TX_DESC_WPTR_DWORD_LBN 0
  640. #define FCN_TX_DESC_WPTR_DWORD_WIDTH 12
  641. /* Transmit descriptor cache configuration register */
  642. #define FCN_TX_DC_CFG_REG_KER 0xa20
  643. #define FCN_TX_DC_SIZE_LBN 0
  644. #define FCN_TX_DC_SIZE_WIDTH 2
  645. /* PHY management transmit data register */
  646. #define FCN_MD_TXD_REG_KER 0xc00
  647. #define FCN_MD_TXD_LBN 0
  648. #define FCN_MD_TXD_WIDTH 16
  649. /* PHY management receive data register */
  650. #define FCN_MD_RXD_REG_KER 0xc10
  651. #define FCN_MD_RXD_LBN 0
  652. #define FCN_MD_RXD_WIDTH 16
  653. /* PHY management configuration & status register */
  654. #define FCN_MD_CS_REG_KER 0xc20
  655. #define FCN_MD_GC_LBN 4
  656. #define FCN_MD_GC_WIDTH 1
  657. #define FCN_MD_RIC_LBN 2
  658. #define FCN_MD_RIC_WIDTH 1
  659. #define FCN_MD_RDC_LBN 1
  660. #define FCN_MD_RDC_WIDTH 1
  661. #define FCN_MD_WRC_LBN 0
  662. #define FCN_MD_WRC_WIDTH 1
  663. /* PHY management PHY address register */
  664. #define FCN_MD_PHY_ADR_REG_KER 0xc30
  665. #define FCN_MD_PHY_ADR_LBN 0
  666. #define FCN_MD_PHY_ADR_WIDTH 16
  667. /* PHY management ID register */
  668. #define FCN_MD_ID_REG_KER 0xc40
  669. #define FCN_MD_PRT_ADR_LBN 11
  670. #define FCN_MD_PRT_ADR_WIDTH 5
  671. #define FCN_MD_DEV_ADR_LBN 6
  672. #define FCN_MD_DEV_ADR_WIDTH 5
  673. /* PHY management status & mask register */
  674. #define FCN_MD_STAT_REG_KER 0xc50
  675. #define FCN_MD_PINT_LBN 4
  676. #define FCN_MD_PINT_WIDTH 1
  677. #define FCN_MD_DONE_LBN 3
  678. #define FCN_MD_DONE_WIDTH 1
  679. #define FCN_MD_BSERR_LBN 2
  680. #define FCN_MD_BSERR_WIDTH 1
  681. #define FCN_MD_LNFL_LBN 1
  682. #define FCN_MD_LNFL_WIDTH 1
  683. #define FCN_MD_BSY_LBN 0
  684. #define FCN_MD_BSY_WIDTH 1
  685. /* Port 0 and 1 MAC control registers */
  686. #define FCN_MAC0_CTRL_REG_KER 0xc80
  687. #define FCN_MAC1_CTRL_REG_KER 0xc90
  688. #define FCN_MAC_XOFF_VAL_LBN 16
  689. #define FCN_MAC_XOFF_VAL_WIDTH 16
  690. #define FCN_MAC_BCAD_ACPT_LBN 4
  691. #define FCN_MAC_BCAD_ACPT_WIDTH 1
  692. #define FCN_MAC_UC_PROM_LBN 3
  693. #define FCN_MAC_UC_PROM_WIDTH 1
  694. #define FCN_MAC_LINK_STATUS_LBN 2
  695. #define FCN_MAC_LINK_STATUS_WIDTH 1
  696. #define FCN_MAC_SPEED_LBN 0
  697. #define FCN_MAC_SPEED_WIDTH 2
  698. /* 10Gig Xaui XGXS Default Values */
  699. #define XX_TXDRV_DEQ_DEFAULT 0xe /* deq=.6 */
  700. #define XX_TXDRV_DTX_DEFAULT 0x5 /* 1.25 */
  701. #define XX_SD_CTL_DRV_DEFAULT 0 /* 20mA */
  702. /* GMAC registers */
  703. #define FALCON_GMAC_REGBANK 0xe00
  704. #define FALCON_GMAC_REGBANK_SIZE 0x200
  705. #define FALCON_GMAC_REG_SIZE 0x10
  706. /* XGMAC registers */
  707. #define FALCON_XMAC_REGBANK 0x1200
  708. #define FALCON_XMAC_REGBANK_SIZE 0x200
  709. #define FALCON_XMAC_REG_SIZE 0x10
  710. /* XGMAC address register low */
  711. #define FCN_XM_ADR_LO_REG_MAC 0x00
  712. #define FCN_XM_ADR_3_LBN 24
  713. #define FCN_XM_ADR_3_WIDTH 8
  714. #define FCN_XM_ADR_2_LBN 16
  715. #define FCN_XM_ADR_2_WIDTH 8
  716. #define FCN_XM_ADR_1_LBN 8
  717. #define FCN_XM_ADR_1_WIDTH 8
  718. #define FCN_XM_ADR_0_LBN 0
  719. #define FCN_XM_ADR_0_WIDTH 8
  720. /* XGMAC address register high */
  721. #define FCN_XM_ADR_HI_REG_MAC 0x01
  722. #define FCN_XM_ADR_5_LBN 8
  723. #define FCN_XM_ADR_5_WIDTH 8
  724. #define FCN_XM_ADR_4_LBN 0
  725. #define FCN_XM_ADR_4_WIDTH 8
  726. /* XGMAC global configuration - port 0*/
  727. #define FCN_XM_GLB_CFG_REG_MAC 0x02
  728. #define FCN_XM_RX_STAT_EN_LBN 11
  729. #define FCN_XM_RX_STAT_EN_WIDTH 1
  730. #define FCN_XM_TX_STAT_EN_LBN 10
  731. #define FCN_XM_TX_STAT_EN_WIDTH 1
  732. #define FCN_XM_RX_JUMBO_MODE_LBN 6
  733. #define FCN_XM_RX_JUMBO_MODE_WIDTH 1
  734. #define FCN_XM_CORE_RST_LBN 0
  735. #define FCN_XM_CORE_RST_WIDTH 1
  736. /* XGMAC transmit configuration - port 0 */
  737. #define FCN_XM_TX_CFG_REG_MAC 0x03
  738. #define FCN_XM_IPG_LBN 16
  739. #define FCN_XM_IPG_WIDTH 4
  740. #define FCN_XM_FCNTL_LBN 10
  741. #define FCN_XM_FCNTL_WIDTH 1
  742. #define FCN_XM_TXCRC_LBN 8
  743. #define FCN_XM_TXCRC_WIDTH 1
  744. #define FCN_XM_AUTO_PAD_LBN 5
  745. #define FCN_XM_AUTO_PAD_WIDTH 1
  746. #define FCN_XM_TX_PRMBL_LBN 2
  747. #define FCN_XM_TX_PRMBL_WIDTH 1
  748. #define FCN_XM_TXEN_LBN 1
  749. #define FCN_XM_TXEN_WIDTH 1
  750. /* XGMAC receive configuration - port 0 */
  751. #define FCN_XM_RX_CFG_REG_MAC 0x04
  752. #define FCN_XM_PASS_CRC_ERR_LBN 25
  753. #define FCN_XM_PASS_CRC_ERR_WIDTH 1
  754. #define FCN_XM_AUTO_DEPAD_LBN 8
  755. #define FCN_XM_AUTO_DEPAD_WIDTH 1
  756. #define FCN_XM_RXEN_LBN 1
  757. #define FCN_XM_RXEN_WIDTH 1
  758. /* XGMAC management interrupt mask register */
  759. #define FCN_XM_MGT_INT_MSK_REG_MAC_B0 0x5
  760. #define FCN_XM_MSK_PRMBLE_ERR_LBN 2
  761. #define FCN_XM_MSK_PRMBLE_ERR_WIDTH 1
  762. #define FCN_XM_MSK_RMTFLT_LBN 1
  763. #define FCN_XM_MSK_RMTFLT_WIDTH 1
  764. #define FCN_XM_MSK_LCLFLT_LBN 0
  765. #define FCN_XM_MSK_LCLFLT_WIDTH 1
  766. /* XGMAC flow control register */
  767. #define FCN_XM_FC_REG_MAC 0x7
  768. #define FCN_XM_PAUSE_TIME_LBN 16
  769. #define FCN_XM_PAUSE_TIME_WIDTH 16
  770. #define FCN_XM_DIS_FCNTL_LBN 0
  771. #define FCN_XM_DIS_FCNTL_WIDTH 1
  772. /* XGMAC transmit parameter register */
  773. #define FCN_XM_TX_PARAM_REG_MAC 0x0d
  774. #define FCN_XM_TX_JUMBO_MODE_LBN 31
  775. #define FCN_XM_TX_JUMBO_MODE_WIDTH 1
  776. #define FCN_XM_MAX_TX_FRM_SIZE_LBN 16
  777. #define FCN_XM_MAX_TX_FRM_SIZE_WIDTH 14
  778. #define FCN_XM_ACPT_ALL_MCAST_LBN 11
  779. #define FCN_XM_ACPT_ALL_MCAST_WIDTH 1
  780. /* XGMAC receive parameter register */
  781. #define FCN_XM_RX_PARAM_REG_MAC 0x0e
  782. #define FCN_XM_MAX_RX_FRM_SIZE_LBN 0
  783. #define FCN_XM_MAX_RX_FRM_SIZE_WIDTH 14
  784. /* XGMAC management interrupt status register */
  785. #define FCN_XM_MGT_INT_REG_MAC_B0 0x0f
  786. #define FCN_XM_PRMBLE_ERR 2
  787. #define FCN_XM_PRMBLE_WIDTH 1
  788. #define FCN_XM_RMTFLT_LBN 1
  789. #define FCN_XM_RMTFLT_WIDTH 1
  790. #define FCN_XM_LCLFLT_LBN 0
  791. #define FCN_XM_LCLFLT_WIDTH 1
  792. /* XAUI XGXS core status register */
  793. #define FCN_XX_ALIGN_DONE_LBN 20
  794. #define FCN_XX_ALIGN_DONE_WIDTH 1
  795. #define FCN_XX_CORE_STAT_REG_MAC 0x16
  796. #define FCN_XX_SYNC_STAT_LBN 16
  797. #define FCN_XX_SYNC_STAT_WIDTH 4
  798. #define FCN_XX_SYNC_STAT_DECODE_SYNCED 0xf
  799. #define FCN_XX_COMMA_DET_LBN 12
  800. #define FCN_XX_COMMA_DET_WIDTH 4
  801. #define FCN_XX_COMMA_DET_RESET 0xf
  802. #define FCN_XX_CHARERR_LBN 4
  803. #define FCN_XX_CHARERR_WIDTH 4
  804. #define FCN_XX_CHARERR_RESET 0xf
  805. #define FCN_XX_DISPERR_LBN 0
  806. #define FCN_XX_DISPERR_WIDTH 4
  807. #define FCN_XX_DISPERR_RESET 0xf
  808. /* XGXS/XAUI powerdown/reset register */
  809. #define FCN_XX_PWR_RST_REG_MAC 0x10
  810. #define FCN_XX_PWRDND_EN_LBN 15
  811. #define FCN_XX_PWRDND_EN_WIDTH 1
  812. #define FCN_XX_PWRDNC_EN_LBN 14
  813. #define FCN_XX_PWRDNC_EN_WIDTH 1
  814. #define FCN_XX_PWRDNB_EN_LBN 13
  815. #define FCN_XX_PWRDNB_EN_WIDTH 1
  816. #define FCN_XX_PWRDNA_EN_LBN 12
  817. #define FCN_XX_PWRDNA_EN_WIDTH 1
  818. #define FCN_XX_RSTPLLCD_EN_LBN 9
  819. #define FCN_XX_RSTPLLCD_EN_WIDTH 1
  820. #define FCN_XX_RSTPLLAB_EN_LBN 8
  821. #define FCN_XX_RSTPLLAB_EN_WIDTH 1
  822. #define FCN_XX_RESETD_EN_LBN 7
  823. #define FCN_XX_RESETD_EN_WIDTH 1
  824. #define FCN_XX_RESETC_EN_LBN 6
  825. #define FCN_XX_RESETC_EN_WIDTH 1
  826. #define FCN_XX_RESETB_EN_LBN 5
  827. #define FCN_XX_RESETB_EN_WIDTH 1
  828. #define FCN_XX_RESETA_EN_LBN 4
  829. #define FCN_XX_RESETA_EN_WIDTH 1
  830. #define FCN_XX_RSTXGXSRX_EN_LBN 2
  831. #define FCN_XX_RSTXGXSRX_EN_WIDTH 1
  832. #define FCN_XX_RSTXGXSTX_EN_LBN 1
  833. #define FCN_XX_RSTXGXSTX_EN_WIDTH 1
  834. #define FCN_XX_RST_XX_EN_LBN 0
  835. #define FCN_XX_RST_XX_EN_WIDTH 1
  836. /* XGXS/XAUI powerdown/reset control register */
  837. #define FCN_XX_SD_CTL_REG_MAC 0x11
  838. #define FCN_XX_TERMADJ1_LBN 17
  839. #define FCN_XX_TERMADJ1_WIDTH 1
  840. #define FCN_XX_TERMADJ0_LBN 16
  841. #define FCN_XX_TERMADJ0_WIDTH 1
  842. #define FCN_XX_HIDRVD_LBN 15
  843. #define FCN_XX_HIDRVD_WIDTH 1
  844. #define FCN_XX_LODRVD_LBN 14
  845. #define FCN_XX_LODRVD_WIDTH 1
  846. #define FCN_XX_HIDRVC_LBN 13
  847. #define FCN_XX_HIDRVC_WIDTH 1
  848. #define FCN_XX_LODRVC_LBN 12
  849. #define FCN_XX_LODRVC_WIDTH 1
  850. #define FCN_XX_HIDRVB_LBN 11
  851. #define FCN_XX_HIDRVB_WIDTH 1
  852. #define FCN_XX_LODRVB_LBN 10
  853. #define FCN_XX_LODRVB_WIDTH 1
  854. #define FCN_XX_HIDRVA_LBN 9
  855. #define FCN_XX_HIDRVA_WIDTH 1
  856. #define FCN_XX_LODRVA_LBN 8
  857. #define FCN_XX_LODRVA_WIDTH 1
  858. #define FCN_XX_LPBKD_LBN 3
  859. #define FCN_XX_LPBKD_WIDTH 1
  860. #define FCN_XX_LPBKC_LBN 2
  861. #define FCN_XX_LPBKC_WIDTH 1
  862. #define FCN_XX_LPBKB_LBN 1
  863. #define FCN_XX_LPBKB_WIDTH 1
  864. #define FCN_XX_LPBKA_LBN 0
  865. #define FCN_XX_LPBKA_WIDTH 1
  866. #define FCN_XX_TXDRV_CTL_REG_MAC 0x12
  867. #define FCN_XX_DEQD_LBN 28
  868. #define FCN_XX_DEQD_WIDTH 4
  869. #define FCN_XX_DEQC_LBN 24
  870. #define FCN_XX_DEQC_WIDTH 4
  871. #define FCN_XX_DEQB_LBN 20
  872. #define FCN_XX_DEQB_WIDTH 4
  873. #define FCN_XX_DEQA_LBN 16
  874. #define FCN_XX_DEQA_WIDTH 4
  875. #define FCN_XX_DTXD_LBN 12
  876. #define FCN_XX_DTXD_WIDTH 4
  877. #define FCN_XX_DTXC_LBN 8
  878. #define FCN_XX_DTXC_WIDTH 4
  879. #define FCN_XX_DTXB_LBN 4
  880. #define FCN_XX_DTXB_WIDTH 4
  881. #define FCN_XX_DTXA_LBN 0
  882. #define FCN_XX_DTXA_WIDTH 4
  883. /* Receive filter table */
  884. #define FCN_RX_FILTER_TBL0 0xF00000
  885. /* Receive descriptor pointer table */
  886. #define FCN_RX_DESC_PTR_TBL_KER_A1 0x11800
  887. #define FCN_RX_DESC_PTR_TBL_KER_B0 0xF40000
  888. #define FCN_RX_ISCSI_DDIG_EN_LBN 88
  889. #define FCN_RX_ISCSI_DDIG_EN_WIDTH 1
  890. #define FCN_RX_ISCSI_HDIG_EN_LBN 87
  891. #define FCN_RX_ISCSI_HDIG_EN_WIDTH 1
  892. #define FCN_RX_DESCQ_BUF_BASE_ID_LBN 36
  893. #define FCN_RX_DESCQ_BUF_BASE_ID_WIDTH 20
  894. #define FCN_RX_DESCQ_EVQ_ID_LBN 24
  895. #define FCN_RX_DESCQ_EVQ_ID_WIDTH 12
  896. #define FCN_RX_DESCQ_OWNER_ID_LBN 10
  897. #define FCN_RX_DESCQ_OWNER_ID_WIDTH 14
  898. #define FCN_RX_DESCQ_SIZE_LBN 3
  899. #define FCN_RX_DESCQ_SIZE_WIDTH 2
  900. #define FCN_RX_DESCQ_SIZE_4K 3
  901. #define FCN_RX_DESCQ_SIZE_2K 2
  902. #define FCN_RX_DESCQ_SIZE_1K 1
  903. #define FCN_RX_DESCQ_SIZE_512 0
  904. #define FCN_RX_DESCQ_TYPE_LBN 2
  905. #define FCN_RX_DESCQ_TYPE_WIDTH 1
  906. #define FCN_RX_DESCQ_JUMBO_LBN 1
  907. #define FCN_RX_DESCQ_JUMBO_WIDTH 1
  908. #define FCN_RX_DESCQ_EN_LBN 0
  909. #define FCN_RX_DESCQ_EN_WIDTH 1
  910. /* Transmit descriptor pointer table */
  911. #define FCN_TX_DESC_PTR_TBL_KER_A1 0x11900
  912. #define FCN_TX_DESC_PTR_TBL_KER_B0 0xF50000
  913. #define FCN_TX_NON_IP_DROP_DIS_B0_LBN 91
  914. #define FCN_TX_NON_IP_DROP_DIS_B0_WIDTH 1
  915. #define FCN_TX_DESCQ_EN_LBN 88
  916. #define FCN_TX_DESCQ_EN_WIDTH 1
  917. #define FCN_TX_ISCSI_DDIG_EN_LBN 87
  918. #define FCN_TX_ISCSI_DDIG_EN_WIDTH 1
  919. #define FCN_TX_ISCSI_HDIG_EN_LBN 86
  920. #define FCN_TX_ISCSI_HDIG_EN_WIDTH 1
  921. #define FCN_TX_DESCQ_BUF_BASE_ID_LBN 36
  922. #define FCN_TX_DESCQ_BUF_BASE_ID_WIDTH 20
  923. #define FCN_TX_DESCQ_EVQ_ID_LBN 24
  924. #define FCN_TX_DESCQ_EVQ_ID_WIDTH 12
  925. #define FCN_TX_DESCQ_OWNER_ID_LBN 10
  926. #define FCN_TX_DESCQ_OWNER_ID_WIDTH 14
  927. #define FCN_TX_DESCQ_SIZE_LBN 3
  928. #define FCN_TX_DESCQ_SIZE_WIDTH 2
  929. #define FCN_TX_DESCQ_SIZE_4K 3
  930. #define FCN_TX_DESCQ_SIZE_2K 2
  931. #define FCN_TX_DESCQ_SIZE_1K 1
  932. #define FCN_TX_DESCQ_SIZE_512 0
  933. #define FCN_TX_DESCQ_TYPE_LBN 1
  934. #define FCN_TX_DESCQ_TYPE_WIDTH 2
  935. #define FCN_TX_DESCQ_FLUSH_LBN 0
  936. #define FCN_TX_DESCQ_FLUSH_WIDTH 1
  937. /* Event queue pointer */
  938. #define FCN_EVQ_PTR_TBL_KER_A1 0x11a00
  939. #define FCN_EVQ_PTR_TBL_KER_B0 0xf60000
  940. #define FCN_EVQ_EN_LBN 23
  941. #define FCN_EVQ_EN_WIDTH 1
  942. #define FCN_EVQ_SIZE_LBN 20
  943. #define FCN_EVQ_SIZE_WIDTH 3
  944. #define FCN_EVQ_SIZE_32K 6
  945. #define FCN_EVQ_SIZE_16K 5
  946. #define FCN_EVQ_SIZE_8K 4
  947. #define FCN_EVQ_SIZE_4K 3
  948. #define FCN_EVQ_SIZE_2K 2
  949. #define FCN_EVQ_SIZE_1K 1
  950. #define FCN_EVQ_SIZE_512 0
  951. #define FCN_EVQ_BUF_BASE_ID_LBN 0
  952. #define FCN_EVQ_BUF_BASE_ID_WIDTH 20
  953. /* RSS indirection table */
  954. #define FCN_RX_RSS_INDIR_TBL_B0 0xFB0000
  955. /* Event queue read pointer */
  956. #define FCN_EVQ_RPTR_REG_KER_A1 0x11b00
  957. #define FCN_EVQ_RPTR_REG_KER_B0 0xfa0000
  958. #define FCN_EVQ_RPTR_LBN 0
  959. #define FCN_EVQ_RPTR_WIDTH 14
  960. #define FCN_EVQ_RPTR_REG_KER_DWORD_A1 ( FCN_EVQ_RPTR_REG_KER_A1 + 0 )
  961. #define FCN_EVQ_RPTR_REG_KER_DWORD_B0 ( FCN_EVQ_RPTR_REG_KER_B0 + 0 )
  962. #define FCN_EVQ_RPTR_DWORD_LBN 0
  963. #define FCN_EVQ_RPTR_DWORD_WIDTH 14
  964. /* Special buffer descriptors */
  965. #define FCN_BUF_FULL_TBL_KER_A1 0x18000
  966. #define FCN_BUF_FULL_TBL_KER_B0 0x800000
  967. #define FCN_IP_DAT_BUF_SIZE_LBN 50
  968. #define FCN_IP_DAT_BUF_SIZE_WIDTH 1
  969. #define FCN_IP_DAT_BUF_SIZE_8K 1
  970. #define FCN_IP_DAT_BUF_SIZE_4K 0
  971. #define FCN_BUF_ADR_FBUF_LBN 14
  972. #define FCN_BUF_ADR_FBUF_WIDTH 34
  973. #define FCN_BUF_OWNER_ID_FBUF_LBN 0
  974. #define FCN_BUF_OWNER_ID_FBUF_WIDTH 14
  975. /** Offset of a GMAC register within Falcon */
  976. #define FALCON_GMAC_REG( efab, mac_reg ) \
  977. ( FALCON_GMAC_REGBANK + \
  978. ( (mac_reg) * FALCON_GMAC_REG_SIZE ) )
  979. /** Offset of an XMAC register within Falcon */
  980. #define FALCON_XMAC_REG( efab_port, mac_reg ) \
  981. ( FALCON_XMAC_REGBANK + \
  982. ( (mac_reg) * FALCON_XMAC_REG_SIZE ) )
  983. #define FCN_MAC_DATA_LBN 0
  984. #define FCN_MAC_DATA_WIDTH 32
  985. /* Transmit descriptor */
  986. #define FCN_TX_KER_PORT_LBN 63
  987. #define FCN_TX_KER_PORT_WIDTH 1
  988. #define FCN_TX_KER_BYTE_CNT_LBN 48
  989. #define FCN_TX_KER_BYTE_CNT_WIDTH 14
  990. #define FCN_TX_KER_BUF_ADR_LBN 0
  991. #define FCN_TX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
  992. /* Receive descriptor */
  993. #define FCN_RX_KER_BUF_SIZE_LBN 48
  994. #define FCN_RX_KER_BUF_SIZE_WIDTH 14
  995. #define FCN_RX_KER_BUF_ADR_LBN 0
  996. #define FCN_RX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
  997. /* Event queue entries */
  998. #define FCN_EV_CODE_LBN 60
  999. #define FCN_EV_CODE_WIDTH 4
  1000. #define FCN_RX_IP_EV_DECODE 0
  1001. #define FCN_TX_IP_EV_DECODE 2
  1002. #define FCN_DRIVER_EV_DECODE 5
  1003. /* Receive events */
  1004. #define FCN_RX_EV_PKT_OK_LBN 56
  1005. #define FCN_RX_EV_PKT_OK_WIDTH 1
  1006. #define FCN_RX_PORT_LBN 30
  1007. #define FCN_RX_PORT_WIDTH 1
  1008. #define FCN_RX_EV_BYTE_CNT_LBN 16
  1009. #define FCN_RX_EV_BYTE_CNT_WIDTH 14
  1010. #define FCN_RX_EV_DESC_PTR_LBN 0
  1011. #define FCN_RX_EV_DESC_PTR_WIDTH 12
  1012. /* Transmit events */
  1013. #define FCN_TX_EV_DESC_PTR_LBN 0
  1014. #define FCN_TX_EV_DESC_PTR_WIDTH 12
  1015. /*******************************************************************************
  1016. *
  1017. *
  1018. * Low-level hardware access
  1019. *
  1020. *
  1021. *******************************************************************************/
  1022. #define FCN_REVISION_REG(efab, reg) \
  1023. ( ( efab->pci_revision == FALCON_REV_B0 ) ? reg ## _B0 : reg ## _A1 )
  1024. #define EFAB_SET_OWORD_FIELD_VER(efab, reg, field, val) \
  1025. if ( efab->pci_revision == FALCON_REV_B0 ) \
  1026. EFAB_SET_OWORD_FIELD ( reg, field ## _B0, val ); \
  1027. else \
  1028. EFAB_SET_OWORD_FIELD ( reg, field ## _A1, val );
  1029. #if FALCON_USE_IO_BAR
  1030. /* Write dword via the I/O BAR */
  1031. static inline void _falcon_writel ( struct efab_nic *efab, uint32_t value,
  1032. unsigned int reg ) {
  1033. outl ( reg, efab->iobase + FCN_IOM_IND_ADR_REG );
  1034. outl ( value, efab->iobase + FCN_IOM_IND_DAT_REG );
  1035. }
  1036. /* Read dword via the I/O BAR */
  1037. static inline uint32_t _falcon_readl ( struct efab_nic *efab,
  1038. unsigned int reg ) {
  1039. outl ( reg, efab->iobase + FCN_IOM_IND_ADR_REG );
  1040. return inl ( efab->iobase + FCN_IOM_IND_DAT_REG );
  1041. }
  1042. #else /* FALCON_USE_IO_BAR */
  1043. #define _falcon_writel( efab, value, reg ) \
  1044. writel ( (value), (efab)->membase + (reg) )
  1045. #define _falcon_readl( efab, reg ) readl ( (efab)->membase + (reg) )
  1046. #endif /* FALCON_USE_IO_BAR */
  1047. /**
  1048. * Write to a Falcon register
  1049. *
  1050. */
  1051. static inline void
  1052. falcon_write ( struct efab_nic *efab, efab_oword_t *value, unsigned int reg )
  1053. {
  1054. EFAB_REGDUMP ( "Writing register %x with " EFAB_OWORD_FMT "\n",
  1055. reg, EFAB_OWORD_VAL ( *value ) );
  1056. _falcon_writel ( efab, value->u32[0], reg + 0 );
  1057. _falcon_writel ( efab, value->u32[1], reg + 4 );
  1058. _falcon_writel ( efab, value->u32[2], reg + 8 );
  1059. wmb();
  1060. _falcon_writel ( efab, value->u32[3], reg + 12 );
  1061. wmb();
  1062. }
  1063. /**
  1064. * Write to Falcon SRAM
  1065. *
  1066. */
  1067. static inline void
  1068. falcon_write_sram ( struct efab_nic *efab, efab_qword_t *value,
  1069. unsigned int index )
  1070. {
  1071. unsigned int reg = ( FCN_REVISION_REG ( efab, FCN_BUF_FULL_TBL_KER ) +
  1072. ( index * sizeof ( *value ) ) );
  1073. EFAB_REGDUMP ( "Writing SRAM register %x with " EFAB_QWORD_FMT "\n",
  1074. reg, EFAB_QWORD_VAL ( *value ) );
  1075. _falcon_writel ( efab, value->u32[0], reg + 0 );
  1076. _falcon_writel ( efab, value->u32[1], reg + 4 );
  1077. wmb();
  1078. }
  1079. /**
  1080. * Write dword to Falcon register that allows partial writes
  1081. *
  1082. */
  1083. static inline void
  1084. falcon_writel ( struct efab_nic *efab, efab_dword_t *value, unsigned int reg )
  1085. {
  1086. EFAB_REGDUMP ( "Writing partial register %x with " EFAB_DWORD_FMT "\n",
  1087. reg, EFAB_DWORD_VAL ( *value ) );
  1088. _falcon_writel ( efab, value->u32[0], reg );
  1089. }
  1090. /**
  1091. * Read from a Falcon register
  1092. *
  1093. */
  1094. static inline void
  1095. falcon_read ( struct efab_nic *efab, efab_oword_t *value, unsigned int reg )
  1096. {
  1097. value->u32[0] = _falcon_readl ( efab, reg + 0 );
  1098. wmb();
  1099. value->u32[1] = _falcon_readl ( efab, reg + 4 );
  1100. value->u32[2] = _falcon_readl ( efab, reg + 8 );
  1101. value->u32[3] = _falcon_readl ( efab, reg + 12 );
  1102. EFAB_REGDUMP ( "Read from register %x, got " EFAB_OWORD_FMT "\n",
  1103. reg, EFAB_OWORD_VAL ( *value ) );
  1104. }
  1105. /**
  1106. * Read from Falcon SRAM
  1107. *
  1108. */
  1109. static inline void
  1110. falcon_read_sram ( struct efab_nic *efab, efab_qword_t *value,
  1111. unsigned int index )
  1112. {
  1113. unsigned int reg = ( FCN_REVISION_REG ( efab, FCN_BUF_FULL_TBL_KER ) +
  1114. ( index * sizeof ( *value ) ) );
  1115. value->u32[0] = _falcon_readl ( efab, reg + 0 );
  1116. value->u32[1] = _falcon_readl ( efab, reg + 4 );
  1117. EFAB_REGDUMP ( "Read from SRAM register %x, got " EFAB_QWORD_FMT "\n",
  1118. reg, EFAB_QWORD_VAL ( *value ) );
  1119. }
  1120. /**
  1121. * Read dword from a portion of a Falcon register
  1122. *
  1123. */
  1124. static inline void
  1125. falcon_readl ( struct efab_nic *efab, efab_dword_t *value, unsigned int reg )
  1126. {
  1127. value->u32[0] = _falcon_readl ( efab, reg );
  1128. EFAB_REGDUMP ( "Read from register %x, got " EFAB_DWORD_FMT "\n",
  1129. reg, EFAB_DWORD_VAL ( *value ) );
  1130. }
  1131. #define FCN_DUMP_REG( efab, _reg ) do { \
  1132. efab_oword_t reg; \
  1133. falcon_read ( efab, &reg, _reg ); \
  1134. EFAB_LOG ( #_reg " = " EFAB_OWORD_FMT "\n", \
  1135. EFAB_OWORD_VAL ( reg ) ); \
  1136. } while ( 0 );
  1137. #define FCN_DUMP_MAC_REG( efab, _mac_reg ) do { \
  1138. efab_dword_t reg; \
  1139. efab->mac_op->mac_readl ( efab, &reg, _mac_reg ); \
  1140. EFAB_LOG ( #_mac_reg " = " EFAB_DWORD_FMT "\n", \
  1141. EFAB_DWORD_VAL ( reg ) ); \
  1142. } while ( 0 );
  1143. /**
  1144. * See if an event is present
  1145. *
  1146. * @v event Falcon event structure
  1147. * @ret True An event is pending
  1148. * @ret False No event is pending
  1149. *
  1150. * We check both the high and low dword of the event for all ones. We
  1151. * wrote all ones when we cleared the event, and no valid event can
  1152. * have all ones in either its high or low dwords. This approach is
  1153. * robust against reordering.
  1154. *
  1155. * Note that using a single 64-bit comparison is incorrect; even
  1156. * though the CPU read will be atomic, the DMA write may not be.
  1157. */
  1158. static inline int
  1159. falcon_event_present ( falcon_event_t* event )
  1160. {
  1161. return ( ! ( EFAB_DWORD_IS_ALL_ONES ( event->dword[0] ) |
  1162. EFAB_DWORD_IS_ALL_ONES ( event->dword[1] ) ) );
  1163. }
  1164. static void
  1165. falcon_eventq_read_ack ( struct efab_nic *efab, struct efab_ev_queue *ev_queue )
  1166. {
  1167. efab_dword_t reg;
  1168. EFAB_POPULATE_DWORD_1 ( reg, FCN_EVQ_RPTR_DWORD, ev_queue->read_ptr );
  1169. falcon_writel ( efab, &reg,
  1170. FCN_REVISION_REG ( efab, FCN_EVQ_RPTR_REG_KER_DWORD ) );
  1171. }
  1172. #if 0
  1173. /**
  1174. * Dump register contents (for debugging)
  1175. *
  1176. * Marked as static inline so that it will not be compiled in if not
  1177. * used.
  1178. */
  1179. static inline void
  1180. falcon_dump_regs ( struct efab_nic *efab )
  1181. {
  1182. FCN_DUMP_REG ( efab, FCN_INT_EN_REG_KER );
  1183. FCN_DUMP_REG ( efab, FCN_INT_ADR_REG_KER );
  1184. FCN_DUMP_REG ( efab, FCN_GLB_CTL_REG_KER );
  1185. FCN_DUMP_REG ( efab, FCN_TIMER_CMD_REG_KER );
  1186. FCN_DUMP_REG ( efab, FCN_SRM_RX_DC_CFG_REG_KER );
  1187. FCN_DUMP_REG ( efab, FCN_SRM_TX_DC_CFG_REG_KER );
  1188. FCN_DUMP_REG ( efab, FCN_RX_FILTER_CTL_REG_KER );
  1189. FCN_DUMP_REG ( efab, FCN_RX_DC_CFG_REG_KER );
  1190. FCN_DUMP_REG ( efab, FCN_TX_DC_CFG_REG_KER );
  1191. FCN_DUMP_REG ( efab, FCN_MAC0_CTRL_REG_KER );
  1192. FCN_DUMP_REG ( efab, FCN_MAC1_CTRL_REG_KER );
  1193. FCN_DUMP_REG ( efab, FCN_REVISION_REG ( efab, FCN_RX_DESC_PTR_TBL_KER ) );
  1194. FCN_DUMP_REG ( efab, FCN_REVISION_REG ( efab, FCN_TX_DESC_PTR_TBL_KER ) );
  1195. FCN_DUMP_REG ( efab, FCN_REVISION_REG ( efab, FCN_EVQ_PTR_TBL_KER ) );
  1196. FCN_DUMP_MAC_REG ( efab, GM_CFG1_REG_MAC );
  1197. FCN_DUMP_MAC_REG ( efab, GM_CFG2_REG_MAC );
  1198. FCN_DUMP_MAC_REG ( efab, GM_MAX_FLEN_REG_MAC );
  1199. FCN_DUMP_MAC_REG ( efab, GM_MII_MGMT_CFG_REG_MAC );
  1200. FCN_DUMP_MAC_REG ( efab, GM_ADR1_REG_MAC );
  1201. FCN_DUMP_MAC_REG ( efab, GM_ADR2_REG_MAC );
  1202. FCN_DUMP_MAC_REG ( efab, GMF_CFG0_REG_MAC );
  1203. FCN_DUMP_MAC_REG ( efab, GMF_CFG1_REG_MAC );
  1204. FCN_DUMP_MAC_REG ( efab, GMF_CFG2_REG_MAC );
  1205. FCN_DUMP_MAC_REG ( efab, GMF_CFG3_REG_MAC );
  1206. FCN_DUMP_MAC_REG ( efab, GMF_CFG4_REG_MAC );
  1207. FCN_DUMP_MAC_REG ( efab, GMF_CFG5_REG_MAC );
  1208. }
  1209. #endif
  1210. static void
  1211. falcon_interrupts ( struct efab_nic *efab, int enabled, int force )
  1212. {
  1213. efab_oword_t int_en_reg_ker;
  1214. EFAB_POPULATE_OWORD_2 ( int_en_reg_ker,
  1215. FCN_KER_INT_KER, force,
  1216. FCN_DRV_INT_EN_KER, enabled );
  1217. falcon_write ( efab, &int_en_reg_ker, FCN_INT_EN_REG_KER );
  1218. }
  1219. /*******************************************************************************
  1220. *
  1221. *
  1222. * SPI access
  1223. *
  1224. *
  1225. *******************************************************************************/
  1226. /** Maximum length for a single SPI transaction */
  1227. #define FALCON_SPI_MAX_LEN 16
  1228. static int
  1229. falcon_spi_wait ( struct efab_nic *efab )
  1230. {
  1231. efab_oword_t reg;
  1232. int count;
  1233. count = 0;
  1234. do {
  1235. udelay ( 100 );
  1236. falcon_read ( efab, &reg, FCN_EE_SPI_HCMD_REG );
  1237. if ( EFAB_OWORD_FIELD ( reg, FCN_EE_SPI_HCMD_CMD_EN ) == 0 )
  1238. return 0;
  1239. } while ( ++count < 1000 );
  1240. EFAB_ERR ( "Timed out waiting for SPI\n" );
  1241. return -ETIMEDOUT;
  1242. }
  1243. static int
  1244. falcon_spi_rw ( struct spi_bus* bus, struct spi_device *device,
  1245. unsigned int command, int address,
  1246. const void* data_out, void *data_in, size_t len )
  1247. {
  1248. struct efab_nic *efab = container_of ( bus, struct efab_nic, spi_bus );
  1249. int address_len, rc, device_id, read_cmd;
  1250. efab_oword_t reg;
  1251. /* falcon_init_spi_device() should have reduced the block size
  1252. * down so this constraint holds */
  1253. assert ( len <= FALCON_SPI_MAX_LEN );
  1254. /* Is this the FLASH or EEPROM device? */
  1255. if ( device == &efab->spi_flash )
  1256. device_id = FCN_EE_SPI_FLASH;
  1257. else if ( device == &efab->spi_eeprom )
  1258. device_id = FCN_EE_SPI_EEPROM;
  1259. else {
  1260. EFAB_ERR ( "Unknown device %p\n", device );
  1261. return -EINVAL;
  1262. }
  1263. EFAB_TRACE ( "Executing spi command %d on device %d at %d for %zd bytes\n",
  1264. command, device_id, address, len );
  1265. /* The bus must be idle */
  1266. rc = falcon_spi_wait ( efab );
  1267. if ( rc )
  1268. goto fail1;
  1269. /* Copy data out */
  1270. if ( data_out ) {
  1271. memcpy ( &reg, data_out, len );
  1272. falcon_write ( efab, &reg, FCN_EE_SPI_HDATA_REG );
  1273. }
  1274. /* Program address register */
  1275. if ( address >= 0 ) {
  1276. EFAB_POPULATE_OWORD_1 ( reg, FCN_EE_SPI_HADR_ADR, address );
  1277. falcon_write ( efab, &reg, FCN_EE_SPI_HADR_REG );
  1278. }
  1279. /* Issue command */
  1280. address_len = ( address >= 0 ) ? device->address_len / 8 : 0;
  1281. read_cmd = ( data_in ? FCN_EE_SPI_READ : FCN_EE_SPI_WRITE );
  1282. EFAB_POPULATE_OWORD_7 ( reg,
  1283. FCN_EE_SPI_HCMD_CMD_EN, 1,
  1284. FCN_EE_SPI_HCMD_SF_SEL, device_id,
  1285. FCN_EE_SPI_HCMD_DABCNT, len,
  1286. FCN_EE_SPI_HCMD_READ, read_cmd,
  1287. FCN_EE_SPI_HCMD_DUBCNT, 0,
  1288. FCN_EE_SPI_HCMD_ADBCNT, address_len,
  1289. FCN_EE_SPI_HCMD_ENC, command );
  1290. falcon_write ( efab, &reg, FCN_EE_SPI_HCMD_REG );
  1291. /* Wait for the command to complete */
  1292. rc = falcon_spi_wait ( efab );
  1293. if ( rc )
  1294. goto fail2;
  1295. /* Copy data in */
  1296. if ( data_in ) {
  1297. falcon_read ( efab, &reg, FCN_EE_SPI_HDATA_REG );
  1298. memcpy ( data_in, &reg, len );
  1299. }
  1300. return 0;
  1301. fail2:
  1302. fail1:
  1303. EFAB_ERR ( "Failed SPI command %d to device %d address 0x%x len 0x%zx\n",
  1304. command, device_id, address, len );
  1305. return rc;
  1306. }
  1307. /*******************************************************************************
  1308. *
  1309. *
  1310. * Falcon bit-bashed I2C interface
  1311. *
  1312. *
  1313. *******************************************************************************/
  1314. static void
  1315. falcon_i2c_bit_write ( struct bit_basher *basher, unsigned int bit_id,
  1316. unsigned long data )
  1317. {
  1318. struct efab_nic *efab = container_of ( basher, struct efab_nic,
  1319. i2c_bb.basher );
  1320. efab_oword_t reg;
  1321. falcon_read ( efab, &reg, FCN_GPIO_CTL_REG_KER );
  1322. switch ( bit_id ) {
  1323. case I2C_BIT_SCL:
  1324. EFAB_SET_OWORD_FIELD ( reg, FCN_GPIO0_OEN, ( data ? 0 : 1 ) );
  1325. break;
  1326. case I2C_BIT_SDA:
  1327. EFAB_SET_OWORD_FIELD ( reg, FCN_GPIO3_OEN, ( data ? 0 : 1 ) );
  1328. break;
  1329. default:
  1330. EFAB_ERR ( "%s bit=%d\n", __func__, bit_id );
  1331. break;
  1332. }
  1333. falcon_write ( efab, &reg, FCN_GPIO_CTL_REG_KER );
  1334. }
  1335. static int
  1336. falcon_i2c_bit_read ( struct bit_basher *basher, unsigned int bit_id )
  1337. {
  1338. struct efab_nic *efab = container_of ( basher, struct efab_nic,
  1339. i2c_bb.basher );
  1340. efab_oword_t reg;
  1341. falcon_read ( efab, &reg, FCN_GPIO_CTL_REG_KER );
  1342. switch ( bit_id ) {
  1343. case I2C_BIT_SCL:
  1344. return EFAB_OWORD_FIELD ( reg, FCN_GPIO0_IN );
  1345. break;
  1346. case I2C_BIT_SDA:
  1347. return EFAB_OWORD_FIELD ( reg, FCN_GPIO3_IN );
  1348. break;
  1349. default:
  1350. EFAB_ERR ( "%s bit=%d\n", __func__, bit_id );
  1351. break;
  1352. }
  1353. return -1;
  1354. }
  1355. static struct bit_basher_operations falcon_i2c_bit_ops = {
  1356. .read = falcon_i2c_bit_read,
  1357. .write = falcon_i2c_bit_write,
  1358. };
  1359. /*******************************************************************************
  1360. *
  1361. *
  1362. * MDIO access
  1363. *
  1364. *
  1365. *******************************************************************************/
  1366. static int
  1367. falcon_gmii_wait ( struct efab_nic *efab )
  1368. {
  1369. efab_dword_t md_stat;
  1370. int count;
  1371. /* wait upto 10ms */
  1372. for (count = 0; count < 1000; count++) {
  1373. falcon_readl ( efab, &md_stat, FCN_MD_STAT_REG_KER );
  1374. if ( EFAB_DWORD_FIELD ( md_stat, FCN_MD_BSY ) == 0 ) {
  1375. if ( EFAB_DWORD_FIELD ( md_stat, FCN_MD_LNFL ) != 0 ||
  1376. EFAB_DWORD_FIELD ( md_stat, FCN_MD_BSERR ) != 0 ) {
  1377. EFAB_ERR ( "Error from GMII access "
  1378. EFAB_DWORD_FMT"\n",
  1379. EFAB_DWORD_VAL ( md_stat ));
  1380. return -EIO;
  1381. }
  1382. return 0;
  1383. }
  1384. udelay(10);
  1385. }
  1386. EFAB_ERR ( "Timed out waiting for GMII\n" );
  1387. return -ETIMEDOUT;
  1388. }
  1389. static void
  1390. falcon_mdio_write ( struct efab_nic *efab, int device,
  1391. int location, int value )
  1392. {
  1393. efab_oword_t reg;
  1394. EFAB_TRACE ( "Writing GMII %d register %02x with %04x\n",
  1395. device, location, value );
  1396. /* Check MII not currently being accessed */
  1397. if ( falcon_gmii_wait ( efab ) )
  1398. return;
  1399. /* Write the address/ID register */
  1400. EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_PHY_ADR, location );
  1401. falcon_write ( efab, &reg, FCN_MD_PHY_ADR_REG_KER );
  1402. if ( efab->phy_10g ) {
  1403. /* clause45 */
  1404. EFAB_POPULATE_OWORD_2 ( reg,
  1405. FCN_MD_PRT_ADR, efab->phy_addr,
  1406. FCN_MD_DEV_ADR, device );
  1407. }
  1408. else {
  1409. /* clause22 */
  1410. assert ( device == 0 );
  1411. EFAB_POPULATE_OWORD_2 ( reg,
  1412. FCN_MD_PRT_ADR, efab->phy_addr,
  1413. FCN_MD_DEV_ADR, location );
  1414. }
  1415. falcon_write ( efab, &reg, FCN_MD_ID_REG_KER );
  1416. /* Write data */
  1417. EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_TXD, value );
  1418. falcon_write ( efab, &reg, FCN_MD_TXD_REG_KER );
  1419. EFAB_POPULATE_OWORD_2 ( reg,
  1420. FCN_MD_WRC, 1,
  1421. FCN_MD_GC, ( efab->phy_10g ? 0 : 1 ) );
  1422. falcon_write ( efab, &reg, FCN_MD_CS_REG_KER );
  1423. /* Wait for data to be written */
  1424. if ( falcon_gmii_wait ( efab ) ) {
  1425. /* Abort the write operation */
  1426. EFAB_POPULATE_OWORD_2 ( reg,
  1427. FCN_MD_WRC, 0,
  1428. FCN_MD_GC, 1);
  1429. falcon_write ( efab, &reg, FCN_MD_CS_REG_KER );
  1430. udelay(10);
  1431. }
  1432. }
  1433. static int
  1434. falcon_mdio_read ( struct efab_nic *efab, int device, int location )
  1435. {
  1436. efab_oword_t reg;
  1437. int value;
  1438. /* Check MII not currently being accessed */
  1439. if ( falcon_gmii_wait ( efab ) )
  1440. return -1;
  1441. if ( efab->phy_10g ) {
  1442. /* clause45 */
  1443. EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_PHY_ADR, location );
  1444. falcon_write ( efab, &reg, FCN_MD_PHY_ADR_REG_KER );
  1445. EFAB_POPULATE_OWORD_2 ( reg,
  1446. FCN_MD_PRT_ADR, efab->phy_addr,
  1447. FCN_MD_DEV_ADR, device );
  1448. falcon_write ( efab, &reg, FCN_MD_ID_REG_KER);
  1449. /* request data to be read */
  1450. EFAB_POPULATE_OWORD_2 ( reg,
  1451. FCN_MD_RDC, 1,
  1452. FCN_MD_GC, 0 );
  1453. }
  1454. else {
  1455. /* clause22 */
  1456. assert ( device == 0 );
  1457. EFAB_POPULATE_OWORD_2 ( reg,
  1458. FCN_MD_PRT_ADR, efab->phy_addr,
  1459. FCN_MD_DEV_ADR, location );
  1460. falcon_write ( efab, &reg, FCN_MD_ID_REG_KER );
  1461. /* Request data to be read */
  1462. EFAB_POPULATE_OWORD_2 ( reg,
  1463. FCN_MD_RIC, 1,
  1464. FCN_MD_GC, 1 );
  1465. }
  1466. falcon_write ( efab, &reg, FCN_MD_CS_REG_KER );
  1467. /* Wait for data to become available */
  1468. if ( falcon_gmii_wait ( efab ) ) {
  1469. /* Abort the read operation */
  1470. EFAB_POPULATE_OWORD_2 ( reg,
  1471. FCN_MD_RIC, 0,
  1472. FCN_MD_GC, 1 );
  1473. falcon_write ( efab, &reg, FCN_MD_CS_REG_KER );
  1474. udelay ( 10 );
  1475. value = -1;
  1476. }
  1477. else {
  1478. /* Read the data */
  1479. falcon_read ( efab, &reg, FCN_MD_RXD_REG_KER );
  1480. value = EFAB_OWORD_FIELD ( reg, FCN_MD_RXD );
  1481. }
  1482. EFAB_TRACE ( "Read from GMII %d register %02x, got %04x\n",
  1483. device, location, value );
  1484. return value;
  1485. }
  1486. /*******************************************************************************
  1487. *
  1488. *
  1489. * MAC wrapper
  1490. *
  1491. *
  1492. *******************************************************************************/
  1493. static void
  1494. falcon_reconfigure_mac_wrapper ( struct efab_nic *efab )
  1495. {
  1496. efab_oword_t reg;
  1497. int link_speed;
  1498. if ( efab->link_options & LPA_EF_10000 ) {
  1499. link_speed = 0x3;
  1500. } else if ( efab->link_options & LPA_EF_1000 ) {
  1501. link_speed = 0x2;
  1502. } else if ( efab->link_options & LPA_100 ) {
  1503. link_speed = 0x1;
  1504. } else {
  1505. link_speed = 0x0;
  1506. }
  1507. EFAB_POPULATE_OWORD_5 ( reg,
  1508. FCN_MAC_XOFF_VAL, 0xffff /* datasheet */,
  1509. FCN_MAC_BCAD_ACPT, 1,
  1510. FCN_MAC_UC_PROM, 0,
  1511. FCN_MAC_LINK_STATUS, 1,
  1512. FCN_MAC_SPEED, link_speed );
  1513. falcon_write ( efab, &reg, FCN_MAC0_CTRL_REG_KER );
  1514. }
  1515. /*******************************************************************************
  1516. *
  1517. *
  1518. * GMAC handling
  1519. *
  1520. *
  1521. *******************************************************************************/
  1522. /* GMAC configuration register 1 */
  1523. #define GM_CFG1_REG_MAC 0x00
  1524. #define GM_SW_RST_LBN 31
  1525. #define GM_SW_RST_WIDTH 1
  1526. #define GM_RX_FC_EN_LBN 5
  1527. #define GM_RX_FC_EN_WIDTH 1
  1528. #define GM_TX_FC_EN_LBN 4
  1529. #define GM_TX_FC_EN_WIDTH 1
  1530. #define GM_RX_EN_LBN 2
  1531. #define GM_RX_EN_WIDTH 1
  1532. #define GM_TX_EN_LBN 0
  1533. #define GM_TX_EN_WIDTH 1
  1534. /* GMAC configuration register 2 */
  1535. #define GM_CFG2_REG_MAC 0x01
  1536. #define GM_PAMBL_LEN_LBN 12
  1537. #define GM_PAMBL_LEN_WIDTH 4
  1538. #define GM_IF_MODE_LBN 8
  1539. #define GM_IF_MODE_WIDTH 2
  1540. #define GM_PAD_CRC_EN_LBN 2
  1541. #define GM_PAD_CRC_EN_WIDTH 1
  1542. #define GM_FD_LBN 0
  1543. #define GM_FD_WIDTH 1
  1544. /* GMAC maximum frame length register */
  1545. #define GM_MAX_FLEN_REG_MAC 0x04
  1546. #define GM_MAX_FLEN_LBN 0
  1547. #define GM_MAX_FLEN_WIDTH 16
  1548. /* GMAC MII management configuration register */
  1549. #define GM_MII_MGMT_CFG_REG_MAC 0x08
  1550. #define GM_MGMT_CLK_SEL_LBN 0
  1551. #define GM_MGMT_CLK_SEL_WIDTH 3
  1552. /* GMAC MII management command register */
  1553. #define GM_MII_MGMT_CMD_REG_MAC 0x09
  1554. #define GM_MGMT_SCAN_CYC_LBN 1
  1555. #define GM_MGMT_SCAN_CYC_WIDTH 1
  1556. #define GM_MGMT_RD_CYC_LBN 0
  1557. #define GM_MGMT_RD_CYC_WIDTH 1
  1558. /* GMAC MII management address register */
  1559. #define GM_MII_MGMT_ADR_REG_MAC 0x0a
  1560. #define GM_MGMT_PHY_ADDR_LBN 8
  1561. #define GM_MGMT_PHY_ADDR_WIDTH 5
  1562. #define GM_MGMT_REG_ADDR_LBN 0
  1563. #define GM_MGMT_REG_ADDR_WIDTH 5
  1564. /* GMAC MII management control register */
  1565. #define GM_MII_MGMT_CTL_REG_MAC 0x0b
  1566. #define GM_MGMT_CTL_LBN 0
  1567. #define GM_MGMT_CTL_WIDTH 16
  1568. /* GMAC MII management status register */
  1569. #define GM_MII_MGMT_STAT_REG_MAC 0x0c
  1570. #define GM_MGMT_STAT_LBN 0
  1571. #define GM_MGMT_STAT_WIDTH 16
  1572. /* GMAC MII management indicators register */
  1573. #define GM_MII_MGMT_IND_REG_MAC 0x0d
  1574. #define GM_MGMT_BUSY_LBN 0
  1575. #define GM_MGMT_BUSY_WIDTH 1
  1576. /* GMAC station address register 1 */
  1577. #define GM_ADR1_REG_MAC 0x10
  1578. #define GM_HWADDR_5_LBN 24
  1579. #define GM_HWADDR_5_WIDTH 8
  1580. #define GM_HWADDR_4_LBN 16
  1581. #define GM_HWADDR_4_WIDTH 8
  1582. #define GM_HWADDR_3_LBN 8
  1583. #define GM_HWADDR_3_WIDTH 8
  1584. #define GM_HWADDR_2_LBN 0
  1585. #define GM_HWADDR_2_WIDTH 8
  1586. /* GMAC station address register 2 */
  1587. #define GM_ADR2_REG_MAC 0x11
  1588. #define GM_HWADDR_1_LBN 24
  1589. #define GM_HWADDR_1_WIDTH 8
  1590. #define GM_HWADDR_0_LBN 16
  1591. #define GM_HWADDR_0_WIDTH 8
  1592. /* GMAC FIFO configuration register 0 */
  1593. #define GMF_CFG0_REG_MAC 0x12
  1594. #define GMF_FTFENREQ_LBN 12
  1595. #define GMF_FTFENREQ_WIDTH 1
  1596. #define GMF_STFENREQ_LBN 11
  1597. #define GMF_STFENREQ_WIDTH 1
  1598. #define GMF_FRFENREQ_LBN 10
  1599. #define GMF_FRFENREQ_WIDTH 1
  1600. #define GMF_SRFENREQ_LBN 9
  1601. #define GMF_SRFENREQ_WIDTH 1
  1602. #define GMF_WTMENREQ_LBN 8
  1603. #define GMF_WTMENREQ_WIDTH 1
  1604. /* GMAC FIFO configuration register 1 */
  1605. #define GMF_CFG1_REG_MAC 0x13
  1606. #define GMF_CFGFRTH_LBN 16
  1607. #define GMF_CFGFRTH_WIDTH 5
  1608. #define GMF_CFGXOFFRTX_LBN 0
  1609. #define GMF_CFGXOFFRTX_WIDTH 16
  1610. /* GMAC FIFO configuration register 2 */
  1611. #define GMF_CFG2_REG_MAC 0x14
  1612. #define GMF_CFGHWM_LBN 16
  1613. #define GMF_CFGHWM_WIDTH 6
  1614. #define GMF_CFGLWM_LBN 0
  1615. #define GMF_CFGLWM_WIDTH 6
  1616. /* GMAC FIFO configuration register 3 */
  1617. #define GMF_CFG3_REG_MAC 0x15
  1618. #define GMF_CFGHWMFT_LBN 16
  1619. #define GMF_CFGHWMFT_WIDTH 6
  1620. #define GMF_CFGFTTH_LBN 0
  1621. #define GMF_CFGFTTH_WIDTH 6
  1622. /* GMAC FIFO configuration register 4 */
  1623. #define GMF_CFG4_REG_MAC 0x16
  1624. #define GMF_HSTFLTRFRM_PAUSE_LBN 12
  1625. #define GMF_HSTFLTRFRM_PAUSE_WIDTH 12
  1626. /* GMAC FIFO configuration register 5 */
  1627. #define GMF_CFG5_REG_MAC 0x17
  1628. #define GMF_CFGHDPLX_LBN 22
  1629. #define GMF_CFGHDPLX_WIDTH 1
  1630. #define GMF_CFGBYTMODE_LBN 19
  1631. #define GMF_CFGBYTMODE_WIDTH 1
  1632. #define GMF_HSTDRPLT64_LBN 18
  1633. #define GMF_HSTDRPLT64_WIDTH 1
  1634. #define GMF_HSTFLTRFRMDC_PAUSE_LBN 12
  1635. #define GMF_HSTFLTRFRMDC_PAUSE_WIDTH 1
  1636. static void
  1637. falcon_gmac_writel ( struct efab_nic *efab, efab_dword_t *value,
  1638. unsigned int mac_reg )
  1639. {
  1640. efab_oword_t temp;
  1641. EFAB_POPULATE_OWORD_1 ( temp, FCN_MAC_DATA,
  1642. EFAB_DWORD_FIELD ( *value, FCN_MAC_DATA ) );
  1643. falcon_write ( efab, &temp, FALCON_GMAC_REG ( efab, mac_reg ) );
  1644. }
  1645. static void
  1646. falcon_gmac_readl ( struct efab_nic *efab, efab_dword_t *value,
  1647. unsigned int mac_reg )
  1648. {
  1649. efab_oword_t temp;
  1650. falcon_read ( efab, &temp, FALCON_GMAC_REG ( efab, mac_reg ) );
  1651. EFAB_POPULATE_DWORD_1 ( *value, FCN_MAC_DATA,
  1652. EFAB_OWORD_FIELD ( temp, FCN_MAC_DATA ) );
  1653. }
  1654. static void
  1655. mentormac_reset ( struct efab_nic *efab )
  1656. {
  1657. efab_dword_t reg;
  1658. /* Take into reset */
  1659. EFAB_POPULATE_DWORD_1 ( reg, GM_SW_RST, 1 );
  1660. falcon_gmac_writel ( efab, &reg, GM_CFG1_REG_MAC );
  1661. udelay ( 1000 );
  1662. /* Take out of reset */
  1663. EFAB_POPULATE_DWORD_1 ( reg, GM_SW_RST, 0 );
  1664. falcon_gmac_writel ( efab, &reg, GM_CFG1_REG_MAC );
  1665. udelay ( 1000 );
  1666. /* Configure GMII interface so PHY is accessible. Note that
  1667. * GMII interface is connected only to port 0, and that on
  1668. * Falcon this is a no-op.
  1669. */
  1670. EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_CLK_SEL, 0x4 );
  1671. falcon_gmac_writel ( efab, &reg, GM_MII_MGMT_CFG_REG_MAC );
  1672. udelay ( 10 );
  1673. }
  1674. static void
  1675. mentormac_init ( struct efab_nic *efab )
  1676. {
  1677. int pause, if_mode, full_duplex, bytemode, half_duplex;
  1678. efab_dword_t reg;
  1679. /* Configuration register 1 */
  1680. pause = ( efab->link_options & LPA_PAUSE_CAP ) ? 1 : 0;
  1681. if ( ! ( efab->link_options & LPA_EF_DUPLEX ) ) {
  1682. /* Half-duplex operation requires TX flow control */
  1683. pause = 1;
  1684. }
  1685. EFAB_POPULATE_DWORD_4 ( reg,
  1686. GM_TX_EN, 1,
  1687. GM_TX_FC_EN, pause,
  1688. GM_RX_EN, 1,
  1689. GM_RX_FC_EN, 1 );
  1690. falcon_gmac_writel ( efab, &reg, GM_CFG1_REG_MAC );
  1691. udelay ( 10 );
  1692. /* Configuration register 2 */
  1693. if_mode = ( efab->link_options & LPA_EF_1000 ) ? 2 : 1;
  1694. full_duplex = ( efab->link_options & LPA_EF_DUPLEX ) ? 1 : 0;
  1695. EFAB_POPULATE_DWORD_4 ( reg,
  1696. GM_IF_MODE, if_mode,
  1697. GM_PAD_CRC_EN, 1,
  1698. GM_FD, full_duplex,
  1699. GM_PAMBL_LEN, 0x7 /* ? */ );
  1700. falcon_gmac_writel ( efab, &reg, GM_CFG2_REG_MAC );
  1701. udelay ( 10 );
  1702. /* Max frame len register */
  1703. EFAB_POPULATE_DWORD_1 ( reg, GM_MAX_FLEN,
  1704. EFAB_MAX_FRAME_LEN ( ETH_FRAME_LEN ) );
  1705. falcon_gmac_writel ( efab, &reg, GM_MAX_FLEN_REG_MAC );
  1706. udelay ( 10 );
  1707. /* FIFO configuration register 0 */
  1708. EFAB_POPULATE_DWORD_5 ( reg,
  1709. GMF_FTFENREQ, 1,
  1710. GMF_STFENREQ, 1,
  1711. GMF_FRFENREQ, 1,
  1712. GMF_SRFENREQ, 1,
  1713. GMF_WTMENREQ, 1 );
  1714. falcon_gmac_writel ( efab, &reg, GMF_CFG0_REG_MAC );
  1715. udelay ( 10 );
  1716. /* FIFO configuration register 1 */
  1717. EFAB_POPULATE_DWORD_2 ( reg,
  1718. GMF_CFGFRTH, 0x12,
  1719. GMF_CFGXOFFRTX, 0xffff );
  1720. falcon_gmac_writel ( efab, &reg, GMF_CFG1_REG_MAC );
  1721. udelay ( 10 );
  1722. /* FIFO configuration register 2 */
  1723. EFAB_POPULATE_DWORD_2 ( reg,
  1724. GMF_CFGHWM, 0x3f,
  1725. GMF_CFGLWM, 0xa );
  1726. falcon_gmac_writel ( efab, &reg, GMF_CFG2_REG_MAC );
  1727. udelay ( 10 );
  1728. /* FIFO configuration register 3 */
  1729. EFAB_POPULATE_DWORD_2 ( reg,
  1730. GMF_CFGHWMFT, 0x1c,
  1731. GMF_CFGFTTH, 0x08 );
  1732. falcon_gmac_writel ( efab, &reg, GMF_CFG3_REG_MAC );
  1733. udelay ( 10 );
  1734. /* FIFO configuration register 4 */
  1735. EFAB_POPULATE_DWORD_1 ( reg, GMF_HSTFLTRFRM_PAUSE, 1 );
  1736. falcon_gmac_writel ( efab, &reg, GMF_CFG4_REG_MAC );
  1737. udelay ( 10 );
  1738. /* FIFO configuration register 5 */
  1739. bytemode = ( efab->link_options & LPA_EF_1000 ) ? 1 : 0;
  1740. half_duplex = ( efab->link_options & LPA_EF_DUPLEX ) ? 0 : 1;
  1741. falcon_gmac_readl ( efab, &reg, GMF_CFG5_REG_MAC );
  1742. EFAB_SET_DWORD_FIELD ( reg, GMF_CFGBYTMODE, bytemode );
  1743. EFAB_SET_DWORD_FIELD ( reg, GMF_CFGHDPLX, half_duplex );
  1744. EFAB_SET_DWORD_FIELD ( reg, GMF_HSTDRPLT64, half_duplex );
  1745. EFAB_SET_DWORD_FIELD ( reg, GMF_HSTFLTRFRMDC_PAUSE, 0 );
  1746. falcon_gmac_writel ( efab, &reg, GMF_CFG5_REG_MAC );
  1747. udelay ( 10 );
  1748. /* MAC address */
  1749. EFAB_POPULATE_DWORD_4 ( reg,
  1750. GM_HWADDR_5, efab->mac_addr[5],
  1751. GM_HWADDR_4, efab->mac_addr[4],
  1752. GM_HWADDR_3, efab->mac_addr[3],
  1753. GM_HWADDR_2, efab->mac_addr[2] );
  1754. falcon_gmac_writel ( efab, &reg, GM_ADR1_REG_MAC );
  1755. udelay ( 10 );
  1756. EFAB_POPULATE_DWORD_2 ( reg,
  1757. GM_HWADDR_1, efab->mac_addr[1],
  1758. GM_HWADDR_0, efab->mac_addr[0] );
  1759. falcon_gmac_writel ( efab, &reg, GM_ADR2_REG_MAC );
  1760. udelay ( 10 );
  1761. }
  1762. static int
  1763. falcon_init_gmac ( struct efab_nic *efab )
  1764. {
  1765. /* Reset the MAC */
  1766. mentormac_reset ( efab );
  1767. /* Initialise PHY */
  1768. efab->phy_op->init ( efab );
  1769. /* check the link is up */
  1770. if ( !efab->link_up )
  1771. return -EAGAIN;
  1772. /* Initialise MAC */
  1773. mentormac_init ( efab );
  1774. /* reconfigure the MAC wrapper */
  1775. falcon_reconfigure_mac_wrapper ( efab );
  1776. return 0;
  1777. }
  1778. static struct efab_mac_operations falcon_gmac_operations = {
  1779. .init = falcon_init_gmac,
  1780. };
  1781. /*******************************************************************************
  1782. *
  1783. *
  1784. * XMAC handling
  1785. *
  1786. *
  1787. *******************************************************************************/
  1788. /**
  1789. * Write dword to a Falcon XMAC register
  1790. *
  1791. */
  1792. static void
  1793. falcon_xmac_writel ( struct efab_nic *efab, efab_dword_t *value,
  1794. unsigned int mac_reg )
  1795. {
  1796. efab_oword_t temp;
  1797. EFAB_POPULATE_OWORD_1 ( temp, FCN_MAC_DATA,
  1798. EFAB_DWORD_FIELD ( *value, FCN_MAC_DATA ) );
  1799. falcon_write ( efab, &temp,
  1800. FALCON_XMAC_REG ( efab, mac_reg ) );
  1801. }
  1802. /**
  1803. * Read dword from a Falcon XMAC register
  1804. *
  1805. */
  1806. static void
  1807. falcon_xmac_readl ( struct efab_nic *efab, efab_dword_t *value,
  1808. unsigned int mac_reg )
  1809. {
  1810. efab_oword_t temp;
  1811. falcon_read ( efab, &temp,
  1812. FALCON_XMAC_REG ( efab, mac_reg ) );
  1813. EFAB_POPULATE_DWORD_1 ( *value, FCN_MAC_DATA,
  1814. EFAB_OWORD_FIELD ( temp, FCN_MAC_DATA ) );
  1815. }
  1816. /**
  1817. * Configure Falcon XAUI output
  1818. */
  1819. static void
  1820. falcon_setup_xaui ( struct efab_nic *efab )
  1821. {
  1822. efab_dword_t sdctl, txdrv;
  1823. falcon_xmac_readl ( efab, &sdctl, FCN_XX_SD_CTL_REG_MAC );
  1824. EFAB_SET_DWORD_FIELD ( sdctl, FCN_XX_HIDRVD, XX_SD_CTL_DRV_DEFAULT );
  1825. EFAB_SET_DWORD_FIELD ( sdctl, FCN_XX_LODRVD, XX_SD_CTL_DRV_DEFAULT );
  1826. EFAB_SET_DWORD_FIELD ( sdctl, FCN_XX_HIDRVC, XX_SD_CTL_DRV_DEFAULT );
  1827. EFAB_SET_DWORD_FIELD ( sdctl, FCN_XX_LODRVC, XX_SD_CTL_DRV_DEFAULT );
  1828. EFAB_SET_DWORD_FIELD ( sdctl, FCN_XX_HIDRVB, XX_SD_CTL_DRV_DEFAULT );
  1829. EFAB_SET_DWORD_FIELD ( sdctl, FCN_XX_LODRVB, XX_SD_CTL_DRV_DEFAULT );
  1830. EFAB_SET_DWORD_FIELD ( sdctl, FCN_XX_HIDRVA, XX_SD_CTL_DRV_DEFAULT );
  1831. EFAB_SET_DWORD_FIELD ( sdctl, FCN_XX_LODRVA, XX_SD_CTL_DRV_DEFAULT );
  1832. falcon_xmac_writel ( efab, &sdctl, FCN_XX_SD_CTL_REG_MAC );
  1833. EFAB_POPULATE_DWORD_8 ( txdrv,
  1834. FCN_XX_DEQD, XX_TXDRV_DEQ_DEFAULT,
  1835. FCN_XX_DEQC, XX_TXDRV_DEQ_DEFAULT,
  1836. FCN_XX_DEQB, XX_TXDRV_DEQ_DEFAULT,
  1837. FCN_XX_DEQA, XX_TXDRV_DEQ_DEFAULT,
  1838. FCN_XX_DTXD, XX_TXDRV_DTX_DEFAULT,
  1839. FCN_XX_DTXC, XX_TXDRV_DTX_DEFAULT,
  1840. FCN_XX_DTXB, XX_TXDRV_DTX_DEFAULT,
  1841. FCN_XX_DTXA, XX_TXDRV_DTX_DEFAULT);
  1842. falcon_xmac_writel ( efab, &txdrv, FCN_XX_TXDRV_CTL_REG_MAC);
  1843. }
  1844. static int
  1845. falcon_xgmii_status ( struct efab_nic *efab )
  1846. {
  1847. efab_dword_t reg;
  1848. if ( efab->pci_revision < FALCON_REV_B0 )
  1849. return 1;
  1850. /* The ISR latches, so clear it and re-read */
  1851. falcon_xmac_readl ( efab, &reg, FCN_XM_MGT_INT_REG_MAC_B0 );
  1852. falcon_xmac_readl ( efab, &reg, FCN_XM_MGT_INT_REG_MAC_B0 );
  1853. if ( EFAB_DWORD_FIELD ( reg, FCN_XM_LCLFLT ) ||
  1854. EFAB_DWORD_FIELD ( reg, FCN_XM_RMTFLT ) ) {
  1855. EFAB_TRACE ( "MGT_INT: "EFAB_DWORD_FMT"\n",
  1856. EFAB_DWORD_VAL ( reg ) );
  1857. return 0;
  1858. }
  1859. return 1;
  1860. }
  1861. static void
  1862. falcon_mask_status_intr ( struct efab_nic *efab, int enable )
  1863. {
  1864. efab_dword_t reg;
  1865. if ( efab->pci_revision < FALCON_REV_B0 )
  1866. return;
  1867. /* Flush the ISR */
  1868. if ( enable )
  1869. falcon_xmac_readl ( efab, &reg, FCN_XM_MGT_INT_REG_MAC_B0 );
  1870. EFAB_POPULATE_DWORD_2 ( reg,
  1871. FCN_XM_MSK_RMTFLT, !enable,
  1872. FCN_XM_MSK_LCLFLT, !enable);
  1873. falcon_xmac_readl ( efab, &reg, FCN_XM_MGT_INT_MSK_REG_MAC_B0 );
  1874. }
  1875. /**
  1876. * Reset 10G MAC connected to port
  1877. *
  1878. */
  1879. static int
  1880. falcon_reset_xmac ( struct efab_nic *efab )
  1881. {
  1882. efab_dword_t reg;
  1883. int count;
  1884. EFAB_POPULATE_DWORD_1 ( reg, FCN_XM_CORE_RST, 1 );
  1885. falcon_xmac_writel ( efab, &reg, FCN_XM_GLB_CFG_REG_MAC );
  1886. for ( count = 0 ; count < 1000 ; count++ ) {
  1887. udelay ( 10 );
  1888. falcon_xmac_readl ( efab, &reg,
  1889. FCN_XM_GLB_CFG_REG_MAC );
  1890. if ( EFAB_DWORD_FIELD ( reg, FCN_XM_CORE_RST ) == 0 )
  1891. return 0;
  1892. }
  1893. return -ETIMEDOUT;
  1894. }
  1895. static int
  1896. falcon_reset_xaui ( struct efab_nic *efab )
  1897. {
  1898. efab_dword_t reg;
  1899. int count;
  1900. if (!efab->is_asic)
  1901. return 0;
  1902. EFAB_POPULATE_DWORD_1 ( reg, FCN_XX_RST_XX_EN, 1 );
  1903. falcon_xmac_writel ( efab, &reg, FCN_XX_PWR_RST_REG_MAC );
  1904. /* Give some time for the link to establish */
  1905. for (count = 0; count < 1000; count++) { /* wait upto 10ms */
  1906. falcon_xmac_readl ( efab, &reg, FCN_XX_PWR_RST_REG_MAC );
  1907. if ( EFAB_DWORD_FIELD ( reg, FCN_XX_RST_XX_EN ) == 0 ) {
  1908. falcon_setup_xaui ( efab );
  1909. return 0;
  1910. }
  1911. udelay(10);
  1912. }
  1913. EFAB_ERR ( "timed out waiting for XAUI/XGXS reset\n" );
  1914. return -ETIMEDOUT;
  1915. }
  1916. static int
  1917. falcon_xaui_link_ok ( struct efab_nic *efab )
  1918. {
  1919. efab_dword_t reg;
  1920. int align_done, lane_status, sync;
  1921. int has_phyxs;
  1922. int link_ok = 1;
  1923. /* Read Falcon XAUI side */
  1924. if ( efab->is_asic ) {
  1925. /* Read link status */
  1926. falcon_xmac_readl ( efab, &reg, FCN_XX_CORE_STAT_REG_MAC );
  1927. align_done = EFAB_DWORD_FIELD ( reg, FCN_XX_ALIGN_DONE );
  1928. sync = EFAB_DWORD_FIELD ( reg, FCN_XX_SYNC_STAT );
  1929. sync = ( sync == FCN_XX_SYNC_STAT_DECODE_SYNCED );
  1930. link_ok = align_done && sync;
  1931. }
  1932. /* Clear link status ready for next read */
  1933. EFAB_SET_DWORD_FIELD ( reg, FCN_XX_COMMA_DET, FCN_XX_COMMA_DET_RESET );
  1934. EFAB_SET_DWORD_FIELD ( reg, FCN_XX_CHARERR, FCN_XX_CHARERR_RESET);
  1935. EFAB_SET_DWORD_FIELD ( reg, FCN_XX_DISPERR, FCN_XX_DISPERR_RESET);
  1936. falcon_xmac_writel ( efab, &reg, FCN_XX_CORE_STAT_REG_MAC );
  1937. has_phyxs = ( efab->phy_op->mmds & ( 1 << MDIO_MMD_PHYXS ) );
  1938. if ( link_ok && has_phyxs ) {
  1939. lane_status = falcon_mdio_read ( efab, MDIO_MMD_PHYXS,
  1940. MDIO_PHYXS_LANE_STATE );
  1941. link_ok = ( lane_status & ( 1 << MDIO_PHYXS_LANE_ALIGNED_LBN ) );
  1942. if (!link_ok )
  1943. EFAB_LOG ( "XGXS lane status: %x\n", lane_status );
  1944. }
  1945. return link_ok;
  1946. }
  1947. /**
  1948. * Initialise XMAC
  1949. *
  1950. */
  1951. static void
  1952. falcon_reconfigure_xmac ( struct efab_nic *efab )
  1953. {
  1954. efab_dword_t reg;
  1955. int max_frame_len;
  1956. /* Configure MAC - cut-thru mode is hard wired on */
  1957. EFAB_POPULATE_DWORD_3 ( reg,
  1958. FCN_XM_RX_JUMBO_MODE, 1,
  1959. FCN_XM_TX_STAT_EN, 1,
  1960. FCN_XM_RX_STAT_EN, 1);
  1961. falcon_xmac_writel ( efab, &reg, FCN_XM_GLB_CFG_REG_MAC );
  1962. /* Configure TX */
  1963. EFAB_POPULATE_DWORD_6 ( reg,
  1964. FCN_XM_TXEN, 1,
  1965. FCN_XM_TX_PRMBL, 1,
  1966. FCN_XM_AUTO_PAD, 1,
  1967. FCN_XM_TXCRC, 1,
  1968. FCN_XM_FCNTL, 1,
  1969. FCN_XM_IPG, 0x3 );
  1970. falcon_xmac_writel ( efab, &reg, FCN_XM_TX_CFG_REG_MAC );
  1971. /* Configure RX */
  1972. EFAB_POPULATE_DWORD_4 ( reg,
  1973. FCN_XM_RXEN, 1,
  1974. FCN_XM_AUTO_DEPAD, 0,
  1975. FCN_XM_ACPT_ALL_MCAST, 1,
  1976. FCN_XM_PASS_CRC_ERR, 1 );
  1977. falcon_xmac_writel ( efab, &reg, FCN_XM_RX_CFG_REG_MAC );
  1978. /* Set frame length */
  1979. max_frame_len = EFAB_MAX_FRAME_LEN ( ETH_FRAME_LEN );
  1980. EFAB_POPULATE_DWORD_1 ( reg,
  1981. FCN_XM_MAX_RX_FRM_SIZE, max_frame_len );
  1982. falcon_xmac_writel ( efab, &reg, FCN_XM_RX_PARAM_REG_MAC );
  1983. EFAB_POPULATE_DWORD_2 ( reg,
  1984. FCN_XM_MAX_TX_FRM_SIZE, max_frame_len,
  1985. FCN_XM_TX_JUMBO_MODE, 1 );
  1986. falcon_xmac_writel ( efab, &reg, FCN_XM_TX_PARAM_REG_MAC );
  1987. /* Enable flow control receipt */
  1988. EFAB_POPULATE_DWORD_2 ( reg,
  1989. FCN_XM_PAUSE_TIME, 0xfffe,
  1990. FCN_XM_DIS_FCNTL, 0 );
  1991. falcon_xmac_writel ( efab, &reg, FCN_XM_FC_REG_MAC );
  1992. /* Set MAC address */
  1993. EFAB_POPULATE_DWORD_4 ( reg,
  1994. FCN_XM_ADR_0, efab->mac_addr[0],
  1995. FCN_XM_ADR_1, efab->mac_addr[1],
  1996. FCN_XM_ADR_2, efab->mac_addr[2],
  1997. FCN_XM_ADR_3, efab->mac_addr[3] );
  1998. falcon_xmac_writel ( efab, &reg, FCN_XM_ADR_LO_REG_MAC );
  1999. EFAB_POPULATE_DWORD_2 ( reg,
  2000. FCN_XM_ADR_4, efab->mac_addr[4],
  2001. FCN_XM_ADR_5, efab->mac_addr[5] );
  2002. falcon_xmac_writel ( efab, &reg, FCN_XM_ADR_HI_REG_MAC );
  2003. }
  2004. static int
  2005. falcon_init_xmac ( struct efab_nic *efab )
  2006. {
  2007. int count, rc;
  2008. /* Mask the PHY management interrupt */
  2009. falcon_mask_status_intr ( efab, 0 );
  2010. /* Initialise the PHY to instantiate the clock. */
  2011. rc = efab->phy_op->init ( efab );
  2012. if ( rc ) {
  2013. EFAB_ERR ( "unable to initialise PHY\n" );
  2014. goto fail1;
  2015. }
  2016. falcon_reset_xaui ( efab );
  2017. /* Give the PHY and MAC time to faff */
  2018. mdelay ( 100 );
  2019. /* Reset and reconfigure the XMAC */
  2020. rc = falcon_reset_xmac ( efab );
  2021. if ( rc )
  2022. goto fail2;
  2023. falcon_reconfigure_xmac ( efab );
  2024. falcon_reconfigure_mac_wrapper ( efab );
  2025. /**
  2026. * Now wait for the link to come up. This may take a while
  2027. * for some slower PHY's.
  2028. */
  2029. for (count=0; count<50; count++) {
  2030. int link_ok = 1;
  2031. /* Wait a while for the link to come up. */
  2032. mdelay ( 100 );
  2033. if ((count % 5) == 0)
  2034. putchar ( '.' );
  2035. /* Does the PHY think the wire-side link is up? */
  2036. link_ok = mdio_clause45_links_ok ( efab );
  2037. /* Ensure the XAUI link to the PHY is good */
  2038. if ( link_ok ) {
  2039. link_ok = falcon_xaui_link_ok ( efab );
  2040. if ( !link_ok )
  2041. falcon_reset_xaui ( efab );
  2042. }
  2043. /* Check fault indication */
  2044. if ( link_ok )
  2045. link_ok = falcon_xgmii_status ( efab );
  2046. efab->link_up = link_ok;
  2047. if ( link_ok ) {
  2048. /* unmask the status interrupt */
  2049. falcon_mask_status_intr ( efab, 1 );
  2050. return 0;
  2051. }
  2052. }
  2053. /* Link failed to come up, but initialisation was fine. */
  2054. rc = -ETIMEDOUT;
  2055. fail2:
  2056. fail1:
  2057. return rc;
  2058. }
  2059. static struct efab_mac_operations falcon_xmac_operations = {
  2060. .init = falcon_init_xmac,
  2061. };
  2062. /*******************************************************************************
  2063. *
  2064. *
  2065. * Null PHY handling
  2066. *
  2067. *
  2068. *******************************************************************************/
  2069. static int
  2070. falcon_xaui_phy_init ( struct efab_nic *efab )
  2071. {
  2072. /* CX4 is always 10000FD only */
  2073. efab->link_options = LPA_EF_10000FULL;
  2074. /* There is no PHY! */
  2075. return 0;
  2076. }
  2077. static struct efab_phy_operations falcon_xaui_phy_ops = {
  2078. .init = falcon_xaui_phy_init,
  2079. .mmds = 0,
  2080. };
  2081. /*******************************************************************************
  2082. *
  2083. *
  2084. * Alaska PHY
  2085. *
  2086. *
  2087. *******************************************************************************/
  2088. /**
  2089. * Initialise Alaska PHY
  2090. *
  2091. */
  2092. static int
  2093. alaska_init ( struct efab_nic *efab )
  2094. {
  2095. unsigned int advertised, lpa;
  2096. /* Read link up status */
  2097. efab->link_up = gmii_link_ok ( efab );
  2098. if ( ! efab->link_up )
  2099. return -EIO;
  2100. /* Determine link options from PHY. */
  2101. advertised = gmii_autoneg_advertised ( efab );
  2102. lpa = gmii_autoneg_lpa ( efab );
  2103. efab->link_options = gmii_nway_result ( advertised & lpa );
  2104. return 0;
  2105. }
  2106. static struct efab_phy_operations falcon_alaska_phy_ops = {
  2107. .init = alaska_init,
  2108. };
  2109. /*******************************************************************************
  2110. *
  2111. *
  2112. * xfp
  2113. *
  2114. *
  2115. *******************************************************************************/
  2116. #define XFP_REQUIRED_DEVS ( MDIO_MMDREG_DEVS0_PCS | \
  2117. MDIO_MMDREG_DEVS0_PMAPMD | \
  2118. MDIO_MMDREG_DEVS0_PHYXS )
  2119. static int
  2120. falcon_xfp_phy_init ( struct efab_nic *efab )
  2121. {
  2122. int rc;
  2123. /* Optical link is always 10000FD only */
  2124. efab->link_options = LPA_EF_10000FULL;
  2125. /* Reset the PHY */
  2126. rc = mdio_clause45_reset_mmd ( efab, MDIO_MMD_PHYXS );
  2127. if ( rc )
  2128. return rc;
  2129. return 0;
  2130. }
  2131. static struct efab_phy_operations falcon_xfp_phy_ops = {
  2132. .init = falcon_xfp_phy_init,
  2133. .mmds = XFP_REQUIRED_DEVS,
  2134. };
  2135. /*******************************************************************************
  2136. *
  2137. *
  2138. * txc43128
  2139. *
  2140. *
  2141. *******************************************************************************/
  2142. /* Command register */
  2143. #define TXC_GLRGS_GLCMD (0xc004)
  2144. #define TXC_GLCMD_LMTSWRST_LBN (14)
  2145. /* Amplitude on lanes 0+1, 2+3 */
  2146. #define TXC_ALRGS_ATXAMP0 (0xc041)
  2147. #define TXC_ALRGS_ATXAMP1 (0xc042)
  2148. /* Bit position of value for lane 0+2, 1+3 */
  2149. #define TXC_ATXAMP_LANE02_LBN (3)
  2150. #define TXC_ATXAMP_LANE13_LBN (11)
  2151. #define TXC_ATXAMP_1280_mV (0)
  2152. #define TXC_ATXAMP_1200_mV (8)
  2153. #define TXC_ATXAMP_1120_mV (12)
  2154. #define TXC_ATXAMP_1060_mV (14)
  2155. #define TXC_ATXAMP_0820_mV (25)
  2156. #define TXC_ATXAMP_0720_mV (26)
  2157. #define TXC_ATXAMP_0580_mV (27)
  2158. #define TXC_ATXAMP_0440_mV (28)
  2159. #define TXC_ATXAMP_0820_BOTH ( (TXC_ATXAMP_0820_mV << TXC_ATXAMP_LANE02_LBN) | \
  2160. (TXC_ATXAMP_0820_mV << TXC_ATXAMP_LANE13_LBN) )
  2161. #define TXC_ATXAMP_DEFAULT (0x6060) /* From databook */
  2162. /* Preemphasis on lanes 0+1, 2+3 */
  2163. #define TXC_ALRGS_ATXPRE0 (0xc043)
  2164. #define TXC_ALRGS_ATXPRE1 (0xc044)
  2165. #define TXC_ATXPRE_NONE (0)
  2166. #define TXC_ATXPRE_DEFAULT (0x1010) /* From databook */
  2167. #define TXC_REQUIRED_DEVS ( MDIO_MMDREG_DEVS0_PCS | \
  2168. MDIO_MMDREG_DEVS0_PMAPMD | \
  2169. MDIO_MMDREG_DEVS0_PHYXS )
  2170. static int
  2171. falcon_txc_logic_reset ( struct efab_nic *efab )
  2172. {
  2173. int val;
  2174. int tries = 50;
  2175. val = falcon_mdio_read ( efab, MDIO_MMD_PCS, TXC_GLRGS_GLCMD );
  2176. val |= (1 << TXC_GLCMD_LMTSWRST_LBN);
  2177. falcon_mdio_write ( efab, MDIO_MMD_PCS, TXC_GLRGS_GLCMD, val );
  2178. while ( tries--) {
  2179. val = falcon_mdio_read ( efab, MDIO_MMD_PCS, TXC_GLRGS_GLCMD );
  2180. if ( ~val & ( 1 << TXC_GLCMD_LMTSWRST_LBN ) )
  2181. return 0;
  2182. udelay(1);
  2183. }
  2184. EFAB_ERR ( "logic reset failed\n" );
  2185. return -ETIMEDOUT;
  2186. }
  2187. static int
  2188. falcon_txc_phy_init ( struct efab_nic *efab )
  2189. {
  2190. int rc;
  2191. /* CX4 is always 10000FD only */
  2192. efab->link_options = LPA_EF_10000FULL;
  2193. /* reset the phy */
  2194. rc = mdio_clause45_reset_mmd ( efab, MDIO_MMD_PMAPMD );
  2195. if ( rc )
  2196. goto fail1;
  2197. rc = mdio_clause45_check_mmds ( efab );
  2198. if ( rc )
  2199. goto fail2;
  2200. /* Turn amplitude down and preemphasis off on the host side
  2201. * (PHY<->MAC) as this is believed less likely to upset falcon
  2202. * and no adverse effects have been noted. It probably also
  2203. * saves a picowatt or two */
  2204. /* Turn off preemphasis */
  2205. falcon_mdio_write ( efab, MDIO_MMD_PHYXS, TXC_ALRGS_ATXPRE0,
  2206. TXC_ATXPRE_NONE );
  2207. falcon_mdio_write ( efab, MDIO_MMD_PHYXS, TXC_ALRGS_ATXPRE1,
  2208. TXC_ATXPRE_NONE );
  2209. /* Turn down the amplitude */
  2210. falcon_mdio_write ( efab, MDIO_MMD_PHYXS, TXC_ALRGS_ATXAMP0,
  2211. TXC_ATXAMP_0820_BOTH );
  2212. falcon_mdio_write ( efab, MDIO_MMD_PHYXS, TXC_ALRGS_ATXAMP1,
  2213. TXC_ATXAMP_0820_BOTH );
  2214. /* Set the line side amplitude and preemphasis to the databook
  2215. * defaults as an erratum causes them to be 0 on at least some
  2216. * PHY rev.s */
  2217. falcon_mdio_write ( efab, MDIO_MMD_PMAPMD, TXC_ALRGS_ATXPRE0,
  2218. TXC_ATXPRE_DEFAULT );
  2219. falcon_mdio_write ( efab, MDIO_MMD_PMAPMD, TXC_ALRGS_ATXPRE1,
  2220. TXC_ATXPRE_DEFAULT );
  2221. falcon_mdio_write ( efab, MDIO_MMD_PMAPMD, TXC_ALRGS_ATXAMP0,
  2222. TXC_ATXAMP_DEFAULT );
  2223. falcon_mdio_write ( efab, MDIO_MMD_PMAPMD, TXC_ALRGS_ATXAMP1,
  2224. TXC_ATXAMP_DEFAULT );
  2225. rc = falcon_txc_logic_reset ( efab );
  2226. if ( rc )
  2227. goto fail3;
  2228. return 0;
  2229. fail3:
  2230. fail2:
  2231. fail1:
  2232. return rc;
  2233. }
  2234. static struct efab_phy_operations falcon_txc_phy_ops = {
  2235. .init = falcon_txc_phy_init,
  2236. .mmds = TXC_REQUIRED_DEVS,
  2237. };
  2238. /*******************************************************************************
  2239. *
  2240. *
  2241. * tenxpress
  2242. *
  2243. *
  2244. *******************************************************************************/
  2245. #define TENXPRESS_REQUIRED_DEVS ( MDIO_MMDREG_DEVS0_PMAPMD | \
  2246. MDIO_MMDREG_DEVS0_PCS | \
  2247. MDIO_MMDREG_DEVS0_PHYXS )
  2248. #define PCS_TEST_SELECT_REG 0xd807 /* PRM 10.5.8 */
  2249. #define CLK312_EN_LBN 3
  2250. #define CLK312_EN_WIDTH 1
  2251. #define PCS_CLOCK_CTRL_REG 0xd801
  2252. #define PLL312_RST_N_LBN 2
  2253. /* Special Software reset register */
  2254. #define PMA_PMD_EXT_CTRL_REG 49152
  2255. #define PMA_PMD_EXT_SSR_LBN 15
  2256. /* Boot status register */
  2257. #define PCS_BOOT_STATUS_REG 0xd000
  2258. #define PCS_BOOT_FATAL_ERR_LBN 0
  2259. #define PCS_BOOT_PROGRESS_LBN 1
  2260. #define PCS_BOOT_PROGRESS_WIDTH 2
  2261. #define PCS_BOOT_COMPLETE_LBN 3
  2262. #define PCS_SOFT_RST2_REG 0xd806
  2263. #define SERDES_RST_N_LBN 13
  2264. #define XGXS_RST_N_LBN 12
  2265. static int
  2266. falcon_tenxpress_check_c11 ( struct efab_nic *efab )
  2267. {
  2268. int count;
  2269. uint32_t boot_stat;
  2270. /* Check that the C11 CPU has booted */
  2271. for (count=0; count<10; count++) {
  2272. boot_stat = falcon_mdio_read ( efab, MDIO_MMD_PCS,
  2273. PCS_BOOT_STATUS_REG );
  2274. if ( boot_stat & ( 1 << PCS_BOOT_COMPLETE_LBN ) )
  2275. return 0;
  2276. udelay(10);
  2277. }
  2278. EFAB_ERR ( "C11 failed to boot\n" );
  2279. return -ETIMEDOUT;
  2280. }
  2281. static int
  2282. falcon_tenxpress_phy_init ( struct efab_nic *efab )
  2283. {
  2284. int rc, reg;
  2285. /* 10XPRESS is always 10000FD (at the moment) */
  2286. efab->link_options = LPA_EF_10000FULL;
  2287. /* Wait for the blocks to come out of reset */
  2288. rc = mdio_clause45_wait_reset_mmds ( efab );
  2289. if ( rc )
  2290. goto fail1;
  2291. rc = mdio_clause45_check_mmds ( efab );
  2292. if ( rc )
  2293. goto fail2;
  2294. /* Turn on the clock */
  2295. reg = (1 << CLK312_EN_LBN);
  2296. falcon_mdio_write ( efab, MDIO_MMD_PCS, PCS_TEST_SELECT_REG, reg);
  2297. /* Wait 200ms for the PHY to boot */
  2298. mdelay(200);
  2299. rc = falcon_tenxpress_check_c11 ( efab );
  2300. if ( rc )
  2301. goto fail3;
  2302. return 0;
  2303. fail3:
  2304. fail2:
  2305. fail1:
  2306. return rc;
  2307. }
  2308. static struct efab_phy_operations falcon_tenxpress_phy_ops = {
  2309. .init = falcon_tenxpress_phy_init,
  2310. .mmds = TENXPRESS_REQUIRED_DEVS,
  2311. };
  2312. /*******************************************************************************
  2313. *
  2314. *
  2315. * PM8358
  2316. *
  2317. *
  2318. *******************************************************************************/
  2319. /* The PM8358 just presents a DTE XS */
  2320. #define PM8358_REQUIRED_DEVS (MDIO_MMDREG_DEVS0_DTEXS)
  2321. /* PHY-specific definitions */
  2322. /* Master ID and Global Performance Monitor Update */
  2323. #define PMC_MASTER_REG (0xd000)
  2324. /* Analog Tx Rx settings under software control */
  2325. #define PMC_MASTER_ANLG_CTRL (1<< 11)
  2326. /* Master Configuration register 2 */
  2327. #define PMC_MCONF2_REG (0xd002)
  2328. /* Drive Tx off centre of data eye (1) vs. clock edge (0) */
  2329. #define PMC_MCONF2_TEDGE (1 << 2)
  2330. /* Drive Rx off centre of data eye (1) vs. clock edge (0) */
  2331. #define PMC_MCONF2_REDGE (1 << 3)
  2332. /* Analog Rx settings */
  2333. #define PMC_ANALOG_RX_CFG0 (0xd025)
  2334. #define PMC_ANALOG_RX_CFG1 (0xd02d)
  2335. #define PMC_ANALOG_RX_CFG2 (0xd035)
  2336. #define PMC_ANALOG_RX_CFG3 (0xd03d)
  2337. #define PMC_ANALOG_RX_TERM (1 << 15) /* Bit 15 of RX CFG: 0 for 100 ohms float,
  2338. 1 for 50 to 1.2V */
  2339. #define PMC_ANALOG_RX_EQ_MASK (3 << 8)
  2340. #define PMC_ANALOG_RX_EQ_NONE (0 << 8)
  2341. #define PMC_ANALOG_RX_EQ_HALF (1 << 8)
  2342. #define PMC_ANALOG_RX_EQ_FULL (2 << 8)
  2343. #define PMC_ANALOG_RX_EQ_RSVD (3 << 8)
  2344. static int
  2345. falcon_pm8358_phy_init ( struct efab_nic *efab )
  2346. {
  2347. int rc, reg, i;
  2348. /* This is a XAUI retimer part */
  2349. efab->link_options = LPA_EF_10000FULL;
  2350. rc = mdio_clause45_reset_mmd ( efab, MDIO_MMDREG_DEVS0_DTEXS );
  2351. if ( rc )
  2352. return rc;
  2353. /* Enable software control of analogue settings */
  2354. reg = falcon_mdio_read ( efab, MDIO_MMD_DTEXS, PMC_MASTER_REG );
  2355. reg |= PMC_MASTER_ANLG_CTRL;
  2356. falcon_mdio_write ( efab, MDIO_MMD_DTEXS, PMC_MASTER_REG, reg );
  2357. /* Turn rx eq on for all channels */
  2358. for (i=0; i< 3; i++) {
  2359. /* The analog CFG registers are evenly spaced 8 apart */
  2360. uint16_t addr = PMC_ANALOG_RX_CFG0 + 8*i;
  2361. reg = falcon_mdio_read ( efab, MDIO_MMD_DTEXS, addr );
  2362. reg = ( reg & ~PMC_ANALOG_RX_EQ_MASK ) | PMC_ANALOG_RX_EQ_FULL;
  2363. falcon_mdio_write ( efab, MDIO_MMD_DTEXS, addr, reg );
  2364. }
  2365. /* Set TEDGE, clear REDGE */
  2366. reg = falcon_mdio_read ( efab, MDIO_MMD_DTEXS, PMC_MCONF2_REG );
  2367. reg = ( reg & ~PMC_MCONF2_REDGE) | PMC_MCONF2_TEDGE;
  2368. falcon_mdio_write ( efab, MDIO_MMD_DTEXS, PMC_MCONF2_REG, reg );
  2369. return 0;
  2370. }
  2371. static struct efab_phy_operations falcon_pm8358_phy_ops = {
  2372. .init = falcon_pm8358_phy_init,
  2373. .mmds = PM8358_REQUIRED_DEVS,
  2374. };
  2375. /*******************************************************************************
  2376. *
  2377. *
  2378. * SFE4001 support
  2379. *
  2380. *
  2381. *******************************************************************************/
  2382. #define MAX_TEMP_THRESH 90
  2383. /* I2C Expander */
  2384. #define PCA9539 0x74
  2385. #define P0_IN 0x00
  2386. #define P0_OUT 0x02
  2387. #define P0_CONFIG 0x06
  2388. #define P0_EN_1V0X_LBN 0
  2389. #define P0_EN_1V0X_WIDTH 1
  2390. #define P0_EN_1V2_LBN 1
  2391. #define P0_EN_1V2_WIDTH 1
  2392. #define P0_EN_2V5_LBN 2
  2393. #define P0_EN_2V5_WIDTH 1
  2394. #define P0_EN_3V3X_LBN 3
  2395. #define P0_EN_3V3X_WIDTH 1
  2396. #define P0_EN_5V_LBN 4
  2397. #define P0_EN_5V_WIDTH 1
  2398. #define P0_X_TRST_LBN 6
  2399. #define P0_X_TRST_WIDTH 1
  2400. #define P1_IN 0x01
  2401. #define P1_CONFIG 0x07
  2402. #define P1_AFE_PWD_LBN 0
  2403. #define P1_AFE_PWD_WIDTH 1
  2404. #define P1_DSP_PWD25_LBN 1
  2405. #define P1_DSP_PWD25_WIDTH 1
  2406. #define P1_SPARE_LBN 4
  2407. #define P1_SPARE_WIDTH 4
  2408. /* Temperature Sensor */
  2409. #define MAX6647 0x4e
  2410. #define RSL 0x02
  2411. #define RLHN 0x05
  2412. #define WLHO 0x0b
  2413. static struct i2c_device i2c_pca9539 = {
  2414. .dev_addr = PCA9539,
  2415. .dev_addr_len = 1,
  2416. .word_addr_len = 1,
  2417. };
  2418. static struct i2c_device i2c_max6647 = {
  2419. .dev_addr = MAX6647,
  2420. .dev_addr_len = 1,
  2421. .word_addr_len = 1,
  2422. };
  2423. static int
  2424. sfe4001_init ( struct efab_nic *efab )
  2425. {
  2426. struct i2c_interface *i2c = &efab->i2c_bb.i2c;
  2427. efab_dword_t reg;
  2428. uint8_t in, cfg, out;
  2429. int count, rc;
  2430. EFAB_LOG ( "Initialise SFE4001 board\n" );
  2431. /* Ensure XGXS and XAUI SerDes are held in reset */
  2432. EFAB_POPULATE_DWORD_7 ( reg,
  2433. FCN_XX_PWRDNA_EN, 1,
  2434. FCN_XX_PWRDNB_EN, 1,
  2435. FCN_XX_RSTPLLAB_EN, 1,
  2436. FCN_XX_RESETA_EN, 1,
  2437. FCN_XX_RESETB_EN, 1,
  2438. FCN_XX_RSTXGXSRX_EN, 1,
  2439. FCN_XX_RSTXGXSTX_EN, 1 );
  2440. falcon_xmac_writel ( efab, &reg, FCN_XX_PWR_RST_REG_MAC);
  2441. udelay(10);
  2442. /* Set DSP over-temperature alert threshold */
  2443. cfg = MAX_TEMP_THRESH;
  2444. rc = i2c->write ( i2c, &i2c_max6647, WLHO, &cfg, EFAB_BYTE );
  2445. if ( rc )
  2446. goto fail1;
  2447. /* Read it back and verify */
  2448. rc = i2c->read ( i2c, &i2c_max6647, RLHN, &in, EFAB_BYTE );
  2449. if ( rc )
  2450. goto fail2;
  2451. if ( in != MAX_TEMP_THRESH ) {
  2452. EFAB_ERR ( "Unable to verify MAX6647 limit (requested=%d "
  2453. "confirmed=%d)\n", cfg, in );
  2454. rc = -EIO;
  2455. goto fail3;
  2456. }
  2457. /* Clear any previous over-temperature alert */
  2458. rc = i2c->read ( i2c, &i2c_max6647, RSL, &in, EFAB_BYTE );
  2459. if ( rc )
  2460. goto fail4;
  2461. /* Enable port 0 and 1 outputs on IO expander */
  2462. cfg = 0x00;
  2463. rc = i2c->write ( i2c, &i2c_pca9539, P0_CONFIG, &cfg, EFAB_BYTE );
  2464. if ( rc )
  2465. goto fail5;
  2466. cfg = 0xff & ~(1 << P1_SPARE_LBN);
  2467. rc = i2c->write ( i2c, &i2c_pca9539, P1_CONFIG, &cfg, EFAB_BYTE );
  2468. if ( rc )
  2469. goto fail6;
  2470. /* Turn all power off then wait 1 sec. This ensures PHY is reset */
  2471. out = 0xff & ~((0 << P0_EN_1V2_LBN) | (0 << P0_EN_2V5_LBN) |
  2472. (0 << P0_EN_3V3X_LBN) | (0 << P0_EN_5V_LBN) |
  2473. (0 << P0_EN_1V0X_LBN));
  2474. rc = i2c->write ( i2c, &i2c_pca9539, P0_OUT, &out, EFAB_BYTE );
  2475. if ( rc )
  2476. goto fail7;
  2477. mdelay(1000);
  2478. for (count=0; count<20; count++) {
  2479. /* Turn on 1.2V, 2.5V, 3.3V and 5V power rails */
  2480. out = 0xff & ~( (1 << P0_EN_1V2_LBN) | (1 << P0_EN_2V5_LBN) |
  2481. (1 << P0_EN_3V3X_LBN) | (1 << P0_EN_5V_LBN) |
  2482. (1 << P0_X_TRST_LBN) );
  2483. rc = i2c->write ( i2c, &i2c_pca9539, P0_OUT, &out, EFAB_BYTE );
  2484. if ( rc )
  2485. goto fail8;
  2486. mdelay ( 10 );
  2487. /* Turn on the 1V power rail */
  2488. out &= ~( 1 << P0_EN_1V0X_LBN );
  2489. rc = i2c->write ( i2c, &i2c_pca9539, P0_OUT, &out, EFAB_BYTE );
  2490. if ( rc )
  2491. goto fail9;
  2492. EFAB_LOG ( "Waiting for power...(attempt %d)\n", count);
  2493. mdelay ( 1000 );
  2494. /* Check DSP is powered */
  2495. rc = i2c->read ( i2c, &i2c_pca9539, P1_IN, &in, EFAB_BYTE );
  2496. if ( rc )
  2497. goto fail10;
  2498. if ( in & ( 1 << P1_AFE_PWD_LBN ) )
  2499. return 0;
  2500. }
  2501. rc = -ETIMEDOUT;
  2502. fail10:
  2503. fail9:
  2504. fail8:
  2505. fail7:
  2506. /* Turn off power rails */
  2507. out = 0xff;
  2508. (void) i2c->write ( i2c, &i2c_pca9539, P0_OUT, &out, EFAB_BYTE );
  2509. /* Disable port 1 outputs on IO expander */
  2510. out = 0xff;
  2511. (void) i2c->write ( i2c, &i2c_pca9539, P1_CONFIG, &out, EFAB_BYTE );
  2512. fail6:
  2513. /* Disable port 0 outputs */
  2514. out = 0xff;
  2515. (void) i2c->write ( i2c, &i2c_pca9539, P1_CONFIG, &out, EFAB_BYTE );
  2516. fail5:
  2517. fail4:
  2518. fail3:
  2519. fail2:
  2520. fail1:
  2521. EFAB_ERR ( "Failed initialising SFE4001 board\n" );
  2522. return rc;
  2523. }
  2524. static void
  2525. sfe4001_fini ( struct efab_nic *efab )
  2526. {
  2527. struct i2c_interface *i2c = &efab->i2c_bb.i2c;
  2528. uint8_t in, cfg, out;
  2529. EFAB_ERR ( "Turning off SFE4001\n" );
  2530. /* Turn off all power rails */
  2531. out = 0xff;
  2532. (void) i2c->write ( i2c, &i2c_pca9539, P0_OUT, &out, EFAB_BYTE );
  2533. /* Disable port 1 outputs on IO expander */
  2534. cfg = 0xff;
  2535. (void) i2c->write ( i2c, &i2c_pca9539, P1_CONFIG, &cfg, EFAB_BYTE );
  2536. /* Disable port 0 outputs on IO expander */
  2537. cfg = 0xff;
  2538. (void) i2c->write ( i2c, &i2c_pca9539, P0_CONFIG, &cfg, EFAB_BYTE );
  2539. /* Clear any over-temperature alert */
  2540. (void) i2c->read ( i2c, &i2c_max6647, RSL, &in, EFAB_BYTE );
  2541. }
  2542. struct efab_board_operations sfe4001_ops = {
  2543. .init = sfe4001_init,
  2544. .fini = sfe4001_fini,
  2545. };
  2546. static int sfe4002_init ( struct efab_nic *efab __attribute__((unused)) )
  2547. {
  2548. return 0;
  2549. }
  2550. static void sfe4002_fini ( struct efab_nic *efab __attribute__((unused)) )
  2551. {
  2552. }
  2553. struct efab_board_operations sfe4002_ops = {
  2554. .init = sfe4002_init,
  2555. .fini = sfe4002_fini,
  2556. };
  2557. static int sfe4003_init ( struct efab_nic *efab __attribute__((unused)) )
  2558. {
  2559. return 0;
  2560. }
  2561. static void sfe4003_fini ( struct efab_nic *efab __attribute__((unused)) )
  2562. {
  2563. }
  2564. struct efab_board_operations sfe4003_ops = {
  2565. .init = sfe4003_init,
  2566. .fini = sfe4003_fini,
  2567. };
  2568. /*******************************************************************************
  2569. *
  2570. *
  2571. * Hardware initialisation
  2572. *
  2573. *
  2574. *******************************************************************************/
  2575. static void
  2576. falcon_free_special_buffer ( void *p )
  2577. {
  2578. /* We don't bother cleaning up the buffer table entries -
  2579. * we're hardly limited */
  2580. free_dma ( p, EFAB_BUF_ALIGN );
  2581. }
  2582. static void*
  2583. falcon_alloc_special_buffer ( struct efab_nic *efab, int bytes,
  2584. struct efab_special_buffer *entry )
  2585. {
  2586. void* buffer;
  2587. int remaining;
  2588. efab_qword_t buf_desc;
  2589. unsigned long dma_addr;
  2590. /* Allocate the buffer, aligned on a buffer address boundary */
  2591. buffer = malloc_dma ( bytes, EFAB_BUF_ALIGN );
  2592. if ( ! buffer )
  2593. return NULL;
  2594. /* Push buffer table entries to back the buffer */
  2595. entry->id = efab->buffer_head;
  2596. entry->dma_addr = dma_addr = virt_to_bus ( buffer );
  2597. assert ( ( dma_addr & ( EFAB_BUF_ALIGN - 1 ) ) == 0 );
  2598. remaining = bytes;
  2599. while ( remaining > 0 ) {
  2600. EFAB_POPULATE_QWORD_3 ( buf_desc,
  2601. FCN_IP_DAT_BUF_SIZE, FCN_IP_DAT_BUF_SIZE_4K,
  2602. FCN_BUF_ADR_FBUF, ( dma_addr >> 12 ),
  2603. FCN_BUF_OWNER_ID_FBUF, 0 );
  2604. falcon_write_sram ( efab, &buf_desc, efab->buffer_head );
  2605. ++efab->buffer_head;
  2606. dma_addr += EFAB_BUF_ALIGN;
  2607. remaining -= EFAB_BUF_ALIGN;
  2608. }
  2609. EFAB_TRACE ( "Allocated 0x%x bytes at %p backed by buffer table "
  2610. "entries 0x%x..0x%x\n", bytes, buffer, entry->id,
  2611. efab->buffer_head - 1 );
  2612. return buffer;
  2613. }
  2614. static void
  2615. clear_b0_fpga_memories ( struct efab_nic *efab)
  2616. {
  2617. efab_oword_t blanko, temp;
  2618. int offset;
  2619. EFAB_ZERO_OWORD ( blanko );
  2620. /* Clear the address region register */
  2621. EFAB_POPULATE_OWORD_4 ( temp,
  2622. FCN_ADR_REGION0, 0,
  2623. FCN_ADR_REGION1, ( 1 << 16 ),
  2624. FCN_ADR_REGION2, ( 2 << 16 ),
  2625. FCN_ADR_REGION3, ( 3 << 16 ) );
  2626. falcon_write ( efab, &temp, FCN_ADR_REGION_REG_KER );
  2627. EFAB_TRACE ( "Clearing filter and RSS tables\n" );
  2628. for ( offset = FCN_RX_FILTER_TBL0 ;
  2629. offset < FCN_RX_RSS_INDIR_TBL_B0+0x800 ;
  2630. offset += 0x10 ) {
  2631. falcon_write ( efab, &blanko, offset );
  2632. }
  2633. EFAB_TRACE ( "Wiping buffer tables\n" );
  2634. /* Notice the 8 byte access mode */
  2635. for ( offset = 0x2800000 ;
  2636. offset < 0x3000000 ;
  2637. offset += 0x8) {
  2638. _falcon_writel ( efab, 0, offset );
  2639. _falcon_writel ( efab, 0, offset + 4 );
  2640. wmb();
  2641. }
  2642. }
  2643. static int
  2644. falcon_reset ( struct efab_nic *efab )
  2645. {
  2646. efab_oword_t glb_ctl_reg_ker;
  2647. /* Initiate software reset */
  2648. EFAB_POPULATE_OWORD_6 ( glb_ctl_reg_ker,
  2649. FCN_PCIE_CORE_RST_CTL, EXCLUDE_FROM_RESET,
  2650. FCN_PCIE_NSTCK_RST_CTL, EXCLUDE_FROM_RESET,
  2651. FCN_PCIE_SD_RST_CTL, EXCLUDE_FROM_RESET,
  2652. FCN_EE_RST_CTL, EXCLUDE_FROM_RESET,
  2653. FCN_EXT_PHY_RST_DUR, 0x7, /* 10ms */
  2654. FCN_SWRST, 1 );
  2655. falcon_write ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
  2656. /* Allow 50ms for reset */
  2657. mdelay ( 50 );
  2658. /* Check for device reset complete */
  2659. falcon_read ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
  2660. if ( EFAB_OWORD_FIELD ( glb_ctl_reg_ker, FCN_SWRST ) != 0 ) {
  2661. EFAB_ERR ( "Reset failed\n" );
  2662. return -ETIMEDOUT;
  2663. }
  2664. if ( ( efab->pci_revision == FALCON_REV_B0 ) && !efab->is_asic ) {
  2665. clear_b0_fpga_memories ( efab );
  2666. }
  2667. return 0;
  2668. }
  2669. /** Offset of MAC address within EEPROM or Flash */
  2670. #define FALCON_MAC_ADDRESS_OFFSET 0x310
  2671. /*
  2672. * Falcon EEPROM structure
  2673. */
  2674. #define SF_NV_CONFIG_BASE 0x300
  2675. #define SF_NV_CONFIG_EXTRA 0xA0
  2676. struct falcon_nv_config_ver2 {
  2677. uint16_t nports;
  2678. uint8_t port0_phy_addr;
  2679. uint8_t port0_phy_type;
  2680. uint8_t port1_phy_addr;
  2681. uint8_t port1_phy_type;
  2682. uint16_t asic_sub_revision;
  2683. uint16_t board_revision;
  2684. uint8_t mac_location;
  2685. };
  2686. struct falcon_nv_extra {
  2687. uint16_t magicnumber;
  2688. uint16_t structure_version;
  2689. uint16_t checksum;
  2690. union {
  2691. struct falcon_nv_config_ver2 ver2;
  2692. } ver_specific;
  2693. };
  2694. #define BOARD_TYPE(_rev) (_rev >> 8)
  2695. static void
  2696. falcon_probe_nic_variant ( struct efab_nic *efab, struct pci_device *pci )
  2697. {
  2698. efab_oword_t altera_build, nic_stat;
  2699. int fpga_version;
  2700. uint8_t revision;
  2701. /* PCI revision */
  2702. pci_read_config_byte ( pci, PCI_CLASS_REVISION, &revision );
  2703. efab->pci_revision = revision;
  2704. /* Asic vs FPGA */
  2705. falcon_read ( efab, &altera_build, FCN_ALTERA_BUILD_REG_KER );
  2706. fpga_version = EFAB_OWORD_FIELD ( altera_build, FCN_VER_ALL );
  2707. efab->is_asic = (fpga_version == 0);
  2708. /* MAC and PCI type */
  2709. falcon_read ( efab, &nic_stat, FCN_NIC_STAT_REG );
  2710. if ( efab->pci_revision == FALCON_REV_B0 ) {
  2711. efab->phy_10g = EFAB_OWORD_FIELD ( nic_stat, FCN_STRAP_10G );
  2712. }
  2713. else if ( efab->is_asic ) {
  2714. efab->phy_10g = EFAB_OWORD_FIELD ( nic_stat, FCN_STRAP_10G );
  2715. }
  2716. else {
  2717. int minor = EFAB_OWORD_FIELD ( altera_build, FCN_VER_MINOR );
  2718. efab->phy_10g = ( minor == 0x14 );
  2719. }
  2720. }
  2721. static void
  2722. falcon_init_spi_device ( struct efab_nic *efab, struct spi_device *spi )
  2723. {
  2724. /* Falcon's SPI interface only supports reads/writes of up to 16 bytes.
  2725. * Reduce the nvs block size down to satisfy this - which means callers
  2726. * should use the nvs_* functions rather than spi_*. */
  2727. if ( spi->nvs.block_size > FALCON_SPI_MAX_LEN )
  2728. spi->nvs.block_size = FALCON_SPI_MAX_LEN;
  2729. spi->bus = &efab->spi_bus;
  2730. efab->spi = spi;
  2731. }
  2732. static int
  2733. falcon_probe_spi ( struct efab_nic *efab )
  2734. {
  2735. efab_oword_t nic_stat, gpio_ctl, ee_vpd_cfg;
  2736. int has_flash, has_eeprom, ad9bit;
  2737. falcon_read ( efab, &nic_stat, FCN_NIC_STAT_REG );
  2738. falcon_read ( efab, &gpio_ctl, FCN_GPIO_CTL_REG_KER );
  2739. falcon_read ( efab, &ee_vpd_cfg, FCN_EE_VPD_CFG_REG );
  2740. /* determine if FLASH / EEPROM is present */
  2741. if ( ( efab->pci_revision >= FALCON_REV_B0 ) || efab->is_asic ) {
  2742. has_flash = EFAB_OWORD_FIELD ( nic_stat, FCN_SF_PRST );
  2743. has_eeprom = EFAB_OWORD_FIELD ( nic_stat, FCN_EE_PRST );
  2744. } else {
  2745. has_flash = EFAB_OWORD_FIELD ( gpio_ctl, FCN_FLASH_PRESENT );
  2746. has_eeprom = EFAB_OWORD_FIELD ( gpio_ctl, FCN_EEPROM_PRESENT );
  2747. }
  2748. ad9bit = EFAB_OWORD_FIELD ( ee_vpd_cfg, FCN_EE_VPD_EN_AD9_MODE );
  2749. /* Configure the SPI and I2C bus */
  2750. efab->spi_bus.rw = falcon_spi_rw;
  2751. init_i2c_bit_basher ( &efab->i2c_bb, &falcon_i2c_bit_ops );
  2752. /* Configure the EEPROM SPI device. Generally, an Atmel 25040
  2753. * (or similar) is used, but this is only possible if there is also
  2754. * a flash device present to store the boot-time chip configuration.
  2755. */
  2756. if ( has_eeprom ) {
  2757. if ( has_flash && ad9bit )
  2758. init_at25040 ( &efab->spi_eeprom );
  2759. else
  2760. init_mc25xx640 ( &efab->spi_eeprom );
  2761. falcon_init_spi_device ( efab, &efab->spi_eeprom );
  2762. }
  2763. /* Configure the FLASH SPI device */
  2764. if ( has_flash ) {
  2765. init_at25f1024 ( &efab->spi_flash );
  2766. falcon_init_spi_device ( efab, &efab->spi_flash );
  2767. }
  2768. EFAB_LOG ( "flash is %s, EEPROM is %s%s\n",
  2769. ( has_flash ? "present" : "absent" ),
  2770. ( has_eeprom ? "present " : "absent" ),
  2771. ( has_eeprom ? (ad9bit ? "(9bit)" : "(16bit)") : "") );
  2772. /* The device MUST have flash or eeprom */
  2773. if ( ! efab->spi ) {
  2774. EFAB_ERR ( "Device appears to have no flash or eeprom\n" );
  2775. return -EIO;
  2776. }
  2777. /* If the device has EEPROM attached, then advertise NVO space */
  2778. if ( has_eeprom ) {
  2779. nvo_init ( &efab->nvo, &efab->spi_eeprom.nvs, 0x100, 0xf0,
  2780. NULL, &efab->netdev->refcnt );
  2781. }
  2782. return 0;
  2783. }
  2784. static int
  2785. falcon_probe_nvram ( struct efab_nic *efab )
  2786. {
  2787. struct nvs_device *nvs = &efab->spi->nvs;
  2788. struct falcon_nv_extra nv;
  2789. int rc, board_revision;
  2790. /* Read the MAC address */
  2791. rc = nvs_read ( nvs, FALCON_MAC_ADDRESS_OFFSET,
  2792. efab->mac_addr, ETH_ALEN );
  2793. if ( rc )
  2794. return rc;
  2795. /* Poke through the NVRAM structure for the PHY type. */
  2796. rc = nvs_read ( nvs, SF_NV_CONFIG_BASE + SF_NV_CONFIG_EXTRA,
  2797. &nv, sizeof ( nv ) );
  2798. if ( rc )
  2799. return rc;
  2800. /* Handle each supported NVRAM version */
  2801. if ( ( le16_to_cpu ( nv.magicnumber ) == FCN_NV_MAGIC_NUMBER ) &&
  2802. ( le16_to_cpu ( nv.structure_version ) >= 2 ) ) {
  2803. struct falcon_nv_config_ver2* ver2 = &nv.ver_specific.ver2;
  2804. /* Get the PHY type */
  2805. efab->phy_addr = le16_to_cpu ( ver2->port0_phy_addr );
  2806. efab->phy_type = le16_to_cpu ( ver2->port0_phy_type );
  2807. board_revision = le16_to_cpu ( ver2->board_revision );
  2808. }
  2809. else {
  2810. EFAB_ERR ( "NVram is not recognised\n" );
  2811. return -EINVAL;
  2812. }
  2813. efab->board_type = BOARD_TYPE ( board_revision );
  2814. EFAB_TRACE ( "Falcon board %d phy %d @ addr %d\n",
  2815. efab->board_type, efab->phy_type, efab->phy_addr );
  2816. /* Patch in the board operations */
  2817. switch ( efab->board_type ) {
  2818. case EFAB_BOARD_SFE4001:
  2819. efab->board_op = &sfe4001_ops;
  2820. break;
  2821. case EFAB_BOARD_SFE4002:
  2822. efab->board_op = &sfe4002_ops;
  2823. break;
  2824. case EFAB_BOARD_SFE4003:
  2825. efab->board_op = &sfe4003_ops;
  2826. break;
  2827. default:
  2828. EFAB_ERR ( "Unrecognised board type\n" );
  2829. return -EINVAL;
  2830. }
  2831. /* Patch in MAC operations */
  2832. if ( efab->phy_10g )
  2833. efab->mac_op = &falcon_xmac_operations;
  2834. else
  2835. efab->mac_op = &falcon_gmac_operations;
  2836. /* Hook in the PHY ops */
  2837. switch ( efab->phy_type ) {
  2838. case PHY_TYPE_10XPRESS:
  2839. efab->phy_op = &falcon_tenxpress_phy_ops;
  2840. break;
  2841. case PHY_TYPE_CX4:
  2842. efab->phy_op = &falcon_xaui_phy_ops;
  2843. break;
  2844. case PHY_TYPE_XFP:
  2845. efab->phy_op = &falcon_xfp_phy_ops;
  2846. break;
  2847. case PHY_TYPE_CX4_RTMR:
  2848. efab->phy_op = &falcon_txc_phy_ops;
  2849. break;
  2850. case PHY_TYPE_PM8358:
  2851. efab->phy_op = &falcon_pm8358_phy_ops;
  2852. break;
  2853. case PHY_TYPE_1GIG_ALASKA:
  2854. efab->phy_op = &falcon_alaska_phy_ops;
  2855. break;
  2856. default:
  2857. EFAB_ERR ( "Unknown PHY type: %d\n", efab->phy_type );
  2858. return -EINVAL;
  2859. }
  2860. return 0;
  2861. }
  2862. static int
  2863. falcon_init_sram ( struct efab_nic *efab )
  2864. {
  2865. efab_oword_t reg;
  2866. int count;
  2867. /* use card in internal SRAM mode */
  2868. falcon_read ( efab, &reg, FCN_NIC_STAT_REG );
  2869. EFAB_SET_OWORD_FIELD ( reg, FCN_ONCHIP_SRAM, 1 );
  2870. falcon_write ( efab, &reg, FCN_NIC_STAT_REG );
  2871. /* Deactivate any external SRAM that might be present */
  2872. EFAB_POPULATE_OWORD_2 ( reg,
  2873. FCN_GPIO1_OEN, 1,
  2874. FCN_GPIO1_OUT, 1 );
  2875. falcon_write ( efab, &reg, FCN_GPIO_CTL_REG_KER );
  2876. /* Initiate SRAM reset */
  2877. EFAB_POPULATE_OWORD_2 ( reg,
  2878. FCN_SRAM_OOB_BT_INIT_EN, 1,
  2879. FCN_SRM_NUM_BANKS_AND_BANK_SIZE, 0 );
  2880. falcon_write ( efab, &reg, FCN_SRM_CFG_REG_KER );
  2881. /* Wait for SRAM reset to complete */
  2882. count = 0;
  2883. do {
  2884. /* SRAM reset is slow; expect around 16ms */
  2885. mdelay ( 20 );
  2886. /* Check for reset complete */
  2887. falcon_read ( efab, &reg, FCN_SRM_CFG_REG_KER );
  2888. if ( !EFAB_OWORD_FIELD ( reg, FCN_SRAM_OOB_BT_INIT_EN ) )
  2889. return 0;
  2890. } while (++count < 20); /* wait upto 0.4 sec */
  2891. EFAB_ERR ( "timed out waiting for SRAM reset\n");
  2892. return -ETIMEDOUT;
  2893. }
  2894. static void
  2895. falcon_setup_nic ( struct efab_nic *efab )
  2896. {
  2897. efab_dword_t timer_cmd;
  2898. efab_oword_t reg;
  2899. int tx_fc, xoff_thresh, xon_thresh;
  2900. /* bug5129: Clear the parity enables on the TX data fifos as
  2901. * they produce false parity errors because of timing issues
  2902. */
  2903. falcon_read ( efab, &reg, FCN_SPARE_REG_KER );
  2904. EFAB_SET_OWORD_FIELD ( reg, FCN_MEM_PERR_EN_TX_DATA, 0 );
  2905. falcon_write ( efab, &reg, FCN_SPARE_REG_KER );
  2906. /* Set up TX and RX descriptor caches in SRAM */
  2907. EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_TX_DC_BASE_ADR, 0x130000 );
  2908. falcon_write ( efab, &reg, FCN_SRM_TX_DC_CFG_REG_KER );
  2909. EFAB_POPULATE_OWORD_1 ( reg, FCN_TX_DC_SIZE, 1 /* 16 descriptors */ );
  2910. falcon_write ( efab, &reg, FCN_TX_DC_CFG_REG_KER );
  2911. EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_RX_DC_BASE_ADR, 0x100000 );
  2912. falcon_write ( efab, &reg, FCN_SRM_RX_DC_CFG_REG_KER );
  2913. EFAB_POPULATE_OWORD_1 ( reg, FCN_RX_DC_SIZE, 2 /* 32 descriptors */ );
  2914. falcon_write ( efab, &reg, FCN_RX_DC_CFG_REG_KER );
  2915. /* Set number of RSS CPUs
  2916. * bug7244: Increase filter depth to reduce RX_RESET likelyhood
  2917. */
  2918. EFAB_POPULATE_OWORD_5 ( reg,
  2919. FCN_NUM_KER, 0,
  2920. FCN_UDP_FULL_SRCH_LIMIT, 8,
  2921. FCN_UDP_WILD_SRCH_LIMIT, 8,
  2922. FCN_TCP_WILD_SRCH_LIMIT, 8,
  2923. FCN_TCP_FULL_SRCH_LIMIT, 8);
  2924. falcon_write ( efab, &reg, FCN_RX_FILTER_CTL_REG_KER );
  2925. udelay ( 1000 );
  2926. /* Setup RX. Wait for descriptor is broken and must
  2927. * be disabled. RXDP recovery shouldn't be needed, but is.
  2928. * disable ISCSI parsing because we don't need it
  2929. */
  2930. falcon_read ( efab, &reg, FCN_RX_SELF_RST_REG_KER );
  2931. EFAB_SET_OWORD_FIELD ( reg, FCN_RX_NODESC_WAIT_DIS, 1 );
  2932. EFAB_SET_OWORD_FIELD ( reg, FCN_RX_RECOVERY_EN, 1 );
  2933. EFAB_SET_OWORD_FIELD ( reg, FCN_RX_ISCSI_DIS, 1 );
  2934. falcon_write ( efab, &reg, FCN_RX_SELF_RST_REG_KER );
  2935. /* Determine recommended flow control settings. *
  2936. * Flow control is qualified on B0 and A1/1G, not on A1/10G */
  2937. if ( efab->pci_revision == FALCON_REV_B0 ) {
  2938. tx_fc = 1;
  2939. xoff_thresh = 54272; /* ~80Kb - 3*max MTU */
  2940. xon_thresh = 27648; /* ~3*max MTU */
  2941. }
  2942. else if ( !efab->phy_10g ) {
  2943. tx_fc = 1;
  2944. xoff_thresh = 2048;
  2945. xon_thresh = 512;
  2946. }
  2947. else {
  2948. tx_fc = xoff_thresh = xon_thresh = 0;
  2949. }
  2950. /* Setup TX and RX */
  2951. falcon_read ( efab, &reg, FCN_TX_CFG2_REG_KER );
  2952. EFAB_SET_OWORD_FIELD ( reg, FCN_TX_DIS_NON_IP_EV, 1 );
  2953. falcon_write ( efab, &reg, FCN_TX_CFG2_REG_KER );
  2954. falcon_read ( efab, &reg, FCN_RX_CFG_REG_KER );
  2955. EFAB_SET_OWORD_FIELD_VER ( efab, reg, FCN_RX_USR_BUF_SIZE,
  2956. (3*4096) / 32 );
  2957. if ( efab->pci_revision == FALCON_REV_B0)
  2958. EFAB_SET_OWORD_FIELD ( reg, FCN_RX_INGR_EN_B0, 1 );
  2959. EFAB_SET_OWORD_FIELD_VER ( efab, reg, FCN_RX_XON_MAC_TH,
  2960. xon_thresh / 256);
  2961. EFAB_SET_OWORD_FIELD_VER ( efab, reg, FCN_RX_XOFF_MAC_TH,
  2962. xoff_thresh / 256);
  2963. EFAB_SET_OWORD_FIELD_VER ( efab, reg, FCN_RX_XOFF_MAC_EN, tx_fc);
  2964. falcon_write ( efab, &reg, FCN_RX_CFG_REG_KER );
  2965. /* Set timer register */
  2966. EFAB_POPULATE_DWORD_2 ( timer_cmd,
  2967. FCN_TIMER_MODE, FCN_TIMER_MODE_DIS,
  2968. FCN_TIMER_VAL, 0 );
  2969. falcon_writel ( efab, &timer_cmd, FCN_TIMER_CMD_REG_KER );
  2970. }
  2971. static void
  2972. falcon_init_resources ( struct efab_nic *efab )
  2973. {
  2974. struct efab_ev_queue *ev_queue = &efab->ev_queue;
  2975. struct efab_rx_queue *rx_queue = &efab->rx_queue;
  2976. struct efab_tx_queue *tx_queue = &efab->tx_queue;
  2977. efab_oword_t reg;
  2978. int jumbo;
  2979. /* Initialise the ptrs */
  2980. tx_queue->read_ptr = tx_queue->write_ptr = 0;
  2981. rx_queue->read_ptr = rx_queue->write_ptr = 0;
  2982. ev_queue->read_ptr = 0;
  2983. /* Push the event queue to the hardware */
  2984. EFAB_POPULATE_OWORD_3 ( reg,
  2985. FCN_EVQ_EN, 1,
  2986. FCN_EVQ_SIZE, FQS(FCN_EVQ, EFAB_EVQ_SIZE),
  2987. FCN_EVQ_BUF_BASE_ID, ev_queue->entry.id );
  2988. falcon_write ( efab, &reg,
  2989. FCN_REVISION_REG ( efab, FCN_EVQ_PTR_TBL_KER ) );
  2990. /* Push the tx queue to the hardware */
  2991. EFAB_POPULATE_OWORD_8 ( reg,
  2992. FCN_TX_DESCQ_EN, 1,
  2993. FCN_TX_ISCSI_DDIG_EN, 0,
  2994. FCN_TX_ISCSI_DDIG_EN, 0,
  2995. FCN_TX_DESCQ_BUF_BASE_ID, tx_queue->entry.id,
  2996. FCN_TX_DESCQ_EVQ_ID, 0,
  2997. FCN_TX_DESCQ_SIZE, FQS(FCN_TX_DESCQ, EFAB_TXD_SIZE),
  2998. FCN_TX_DESCQ_TYPE, 0 /* kernel queue */,
  2999. FCN_TX_NON_IP_DROP_DIS_B0, 1 );
  3000. falcon_write ( efab, &reg,
  3001. FCN_REVISION_REG ( efab, FCN_TX_DESC_PTR_TBL_KER ) );
  3002. /* Push the rx queue to the hardware */
  3003. jumbo = ( efab->pci_revision == FALCON_REV_B0 ) ? 0 : 1;
  3004. EFAB_POPULATE_OWORD_8 ( reg,
  3005. FCN_RX_ISCSI_DDIG_EN, 0,
  3006. FCN_RX_ISCSI_HDIG_EN, 0,
  3007. FCN_RX_DESCQ_BUF_BASE_ID, rx_queue->entry.id,
  3008. FCN_RX_DESCQ_EVQ_ID, 0,
  3009. FCN_RX_DESCQ_SIZE, FQS(FCN_RX_DESCQ, EFAB_RXD_SIZE),
  3010. FCN_RX_DESCQ_TYPE, 0 /* kernel queue */,
  3011. FCN_RX_DESCQ_JUMBO, jumbo,
  3012. FCN_RX_DESCQ_EN, 1 );
  3013. falcon_write ( efab, &reg,
  3014. FCN_REVISION_REG ( efab, FCN_RX_DESC_PTR_TBL_KER ) );
  3015. /* Program INT_ADR_REG_KER */
  3016. EFAB_POPULATE_OWORD_1 ( reg,
  3017. FCN_INT_ADR_KER, virt_to_bus ( &efab->int_ker ) );
  3018. falcon_write ( efab, &reg, FCN_INT_ADR_REG_KER );
  3019. /* Ack the event queue */
  3020. falcon_eventq_read_ack ( efab, ev_queue );
  3021. }
  3022. static void
  3023. falcon_fini_resources ( struct efab_nic *efab )
  3024. {
  3025. efab_oword_t cmd;
  3026. /* Disable interrupts */
  3027. falcon_interrupts ( efab, 0, 0 );
  3028. /* Flush the dma queues */
  3029. EFAB_POPULATE_OWORD_2 ( cmd,
  3030. FCN_TX_FLUSH_DESCQ_CMD, 1,
  3031. FCN_TX_FLUSH_DESCQ, 0 );
  3032. falcon_write ( efab, &cmd,
  3033. FCN_REVISION_REG ( efab, FCN_TX_DESC_PTR_TBL_KER ) );
  3034. EFAB_POPULATE_OWORD_2 ( cmd,
  3035. FCN_RX_FLUSH_DESCQ_CMD, 1,
  3036. FCN_RX_FLUSH_DESCQ, 0 );
  3037. falcon_write ( efab, &cmd,
  3038. FCN_REVISION_REG ( efab, FCN_RX_DESC_PTR_TBL_KER ) );
  3039. mdelay ( 100 );
  3040. /* Remove descriptor rings from card */
  3041. EFAB_ZERO_OWORD ( cmd );
  3042. falcon_write ( efab, &cmd,
  3043. FCN_REVISION_REG ( efab, FCN_TX_DESC_PTR_TBL_KER ) );
  3044. falcon_write ( efab, &cmd,
  3045. FCN_REVISION_REG ( efab, FCN_RX_DESC_PTR_TBL_KER ) );
  3046. falcon_write ( efab, &cmd,
  3047. FCN_REVISION_REG ( efab, FCN_EVQ_PTR_TBL_KER ) );
  3048. }
  3049. /*******************************************************************************
  3050. *
  3051. *
  3052. * Hardware rx path
  3053. *
  3054. *
  3055. *******************************************************************************/
  3056. static void
  3057. falcon_build_rx_desc ( falcon_rx_desc_t *rxd, struct io_buffer *iob )
  3058. {
  3059. EFAB_POPULATE_QWORD_2 ( *rxd,
  3060. FCN_RX_KER_BUF_SIZE, EFAB_RX_BUF_SIZE,
  3061. FCN_RX_KER_BUF_ADR, virt_to_bus ( iob->data ) );
  3062. }
  3063. static void
  3064. falcon_notify_rx_desc ( struct efab_nic *efab, struct efab_rx_queue *rx_queue )
  3065. {
  3066. efab_dword_t reg;
  3067. int ptr = rx_queue->write_ptr % EFAB_RXD_SIZE;
  3068. EFAB_POPULATE_DWORD_1 ( reg, FCN_RX_DESC_WPTR_DWORD, ptr );
  3069. falcon_writel ( efab, &reg, FCN_RX_DESC_UPD_REG_KER_DWORD );
  3070. }
  3071. /*******************************************************************************
  3072. *
  3073. *
  3074. * Hardware tx path
  3075. *
  3076. *
  3077. *******************************************************************************/
  3078. static void
  3079. falcon_build_tx_desc ( falcon_tx_desc_t *txd, struct io_buffer *iob )
  3080. {
  3081. EFAB_POPULATE_QWORD_2 ( *txd,
  3082. FCN_TX_KER_BYTE_CNT, iob_len ( iob ),
  3083. FCN_TX_KER_BUF_ADR, virt_to_bus ( iob->data ) );
  3084. }
  3085. static void
  3086. falcon_notify_tx_desc ( struct efab_nic *efab,
  3087. struct efab_tx_queue *tx_queue )
  3088. {
  3089. efab_dword_t reg;
  3090. int ptr = tx_queue->write_ptr % EFAB_TXD_SIZE;
  3091. EFAB_POPULATE_DWORD_1 ( reg, FCN_TX_DESC_WPTR_DWORD, ptr );
  3092. falcon_writel ( efab, &reg, FCN_TX_DESC_UPD_REG_KER_DWORD );
  3093. }
  3094. /*******************************************************************************
  3095. *
  3096. *
  3097. * Software receive interface
  3098. *
  3099. *
  3100. *******************************************************************************/
  3101. static int
  3102. efab_fill_rx_queue ( struct efab_nic *efab,
  3103. struct efab_rx_queue *rx_queue )
  3104. {
  3105. int fill_level = rx_queue->write_ptr - rx_queue->read_ptr;
  3106. int space = EFAB_NUM_RX_DESC - fill_level - 1;
  3107. int pushed = 0;
  3108. while ( space ) {
  3109. int buf_id = rx_queue->write_ptr % EFAB_NUM_RX_DESC;
  3110. int desc_id = rx_queue->write_ptr % EFAB_RXD_SIZE;
  3111. struct io_buffer *iob;
  3112. falcon_rx_desc_t *rxd;
  3113. assert ( rx_queue->buf[buf_id] == NULL );
  3114. iob = alloc_iob ( EFAB_RX_BUF_SIZE );
  3115. if ( !iob )
  3116. break;
  3117. EFAB_TRACE ( "pushing rx_buf[%d] iob %p data %p\n",
  3118. buf_id, iob, iob->data );
  3119. rx_queue->buf[buf_id] = iob;
  3120. rxd = rx_queue->ring + desc_id;
  3121. falcon_build_rx_desc ( rxd, iob );
  3122. ++rx_queue->write_ptr;
  3123. ++pushed;
  3124. --space;
  3125. }
  3126. if ( pushed ) {
  3127. /* Push the ptr to hardware */
  3128. falcon_notify_rx_desc ( efab, rx_queue );
  3129. fill_level = rx_queue->write_ptr - rx_queue->read_ptr;
  3130. EFAB_TRACE ( "pushed %d rx buffers to fill level %d\n",
  3131. pushed, fill_level );
  3132. }
  3133. if ( fill_level == 0 )
  3134. return -ENOMEM;
  3135. return 0;
  3136. }
  3137. static void
  3138. efab_receive ( struct efab_nic *efab, unsigned int id, int len, int drop )
  3139. {
  3140. struct efab_rx_queue *rx_queue = &efab->rx_queue;
  3141. struct io_buffer *iob;
  3142. unsigned int read_ptr = rx_queue->read_ptr % EFAB_RXD_SIZE;
  3143. unsigned int buf_ptr = rx_queue->read_ptr % EFAB_NUM_RX_DESC;
  3144. assert ( id == read_ptr );
  3145. /* Pop this rx buffer out of the software ring */
  3146. iob = rx_queue->buf[buf_ptr];
  3147. rx_queue->buf[buf_ptr] = NULL;
  3148. EFAB_TRACE ( "popping rx_buf[%d] iob %p data %p with %d bytes %s\n",
  3149. id, iob, iob->data, len, drop ? "bad" : "ok" );
  3150. /* Pass the packet up if required */
  3151. if ( drop )
  3152. free_iob ( iob );
  3153. else {
  3154. iob_put ( iob, len );
  3155. netdev_rx ( efab->netdev, iob );
  3156. }
  3157. ++rx_queue->read_ptr;
  3158. }
  3159. /*******************************************************************************
  3160. *
  3161. *
  3162. * Software transmit interface
  3163. *
  3164. *
  3165. *******************************************************************************/
  3166. static int
  3167. efab_transmit ( struct net_device *netdev, struct io_buffer *iob )
  3168. {
  3169. struct efab_nic *efab = netdev_priv ( netdev );
  3170. struct efab_tx_queue *tx_queue = &efab->tx_queue;
  3171. int fill_level, space;
  3172. falcon_tx_desc_t *txd;
  3173. int buf_id;
  3174. fill_level = tx_queue->write_ptr - tx_queue->read_ptr;
  3175. space = EFAB_TXD_SIZE - fill_level - 1;
  3176. if ( space < 1 )
  3177. return -ENOBUFS;
  3178. /* Save the iobuffer for later completion */
  3179. buf_id = tx_queue->write_ptr % EFAB_TXD_SIZE;
  3180. assert ( tx_queue->buf[buf_id] == NULL );
  3181. tx_queue->buf[buf_id] = iob;
  3182. EFAB_TRACE ( "tx_buf[%d] for iob %p data %p len %zd\n",
  3183. buf_id, iob, iob->data, iob_len ( iob ) );
  3184. /* Form the descriptor, and push it to hardware */
  3185. txd = tx_queue->ring + buf_id;
  3186. falcon_build_tx_desc ( txd, iob );
  3187. ++tx_queue->write_ptr;
  3188. falcon_notify_tx_desc ( efab, tx_queue );
  3189. return 0;
  3190. }
  3191. static int
  3192. efab_transmit_done ( struct efab_nic *efab, int id )
  3193. {
  3194. struct efab_tx_queue *tx_queue = &efab->tx_queue;
  3195. unsigned int read_ptr, stop;
  3196. /* Complete all buffers from read_ptr up to and including id */
  3197. read_ptr = tx_queue->read_ptr % EFAB_TXD_SIZE;
  3198. stop = ( id + 1 ) % EFAB_TXD_SIZE;
  3199. while ( read_ptr != stop ) {
  3200. struct io_buffer *iob = tx_queue->buf[read_ptr];
  3201. assert ( iob );
  3202. /* Complete the tx buffer */
  3203. if ( iob )
  3204. netdev_tx_complete ( efab->netdev, iob );
  3205. tx_queue->buf[read_ptr] = NULL;
  3206. ++tx_queue->read_ptr;
  3207. read_ptr = tx_queue->read_ptr % EFAB_TXD_SIZE;
  3208. }
  3209. return 0;
  3210. }
  3211. /*******************************************************************************
  3212. *
  3213. *
  3214. * Hardware event path
  3215. *
  3216. *
  3217. *******************************************************************************/
  3218. static void
  3219. falcon_clear_interrupts ( struct efab_nic *efab )
  3220. {
  3221. efab_dword_t reg;
  3222. if ( efab->pci_revision == FALCON_REV_B0 ) {
  3223. /* read the ISR */
  3224. falcon_readl( efab, &reg, INT_ISR0_B0 );
  3225. }
  3226. else {
  3227. /* write to the INT_ACK register */
  3228. falcon_writel ( efab, 0, FCN_INT_ACK_KER_REG_A1 );
  3229. mb();
  3230. falcon_readl ( efab, &reg,
  3231. WORK_AROUND_BROKEN_PCI_READS_REG_KER_A1 );
  3232. }
  3233. }
  3234. static void
  3235. falcon_handle_event ( struct efab_nic *efab, falcon_event_t *evt )
  3236. {
  3237. int ev_code, desc_ptr, len, drop;
  3238. /* Decode event */
  3239. ev_code = EFAB_QWORD_FIELD ( *evt, FCN_EV_CODE );
  3240. switch ( ev_code ) {
  3241. case FCN_TX_IP_EV_DECODE:
  3242. desc_ptr = EFAB_QWORD_FIELD ( *evt, FCN_TX_EV_DESC_PTR );
  3243. efab_transmit_done ( efab, desc_ptr );
  3244. break;
  3245. case FCN_RX_IP_EV_DECODE:
  3246. desc_ptr = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_DESC_PTR );
  3247. len = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_BYTE_CNT );
  3248. drop = !EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_PKT_OK );
  3249. efab_receive ( efab, desc_ptr, len, drop );
  3250. break;
  3251. default:
  3252. EFAB_TRACE ( "Unknown event type %d\n", ev_code );
  3253. break;
  3254. }
  3255. }
  3256. /*******************************************************************************
  3257. *
  3258. *
  3259. * Software (polling) interrupt handler
  3260. *
  3261. *
  3262. *******************************************************************************/
  3263. static void
  3264. efab_poll ( struct net_device *netdev )
  3265. {
  3266. struct efab_nic *efab = netdev_priv ( netdev );
  3267. struct efab_ev_queue *ev_queue = &efab->ev_queue;
  3268. struct efab_rx_queue *rx_queue = &efab->rx_queue;
  3269. falcon_event_t *evt;
  3270. /* Read the event queue by directly looking for events
  3271. * (we don't even bother to read the eventq write ptr) */
  3272. evt = ev_queue->ring + ev_queue->read_ptr;
  3273. while ( falcon_event_present ( evt ) ) {
  3274. EFAB_TRACE ( "Event at index 0x%x address %p is "
  3275. EFAB_QWORD_FMT "\n", ev_queue->read_ptr,
  3276. evt, EFAB_QWORD_VAL ( *evt ) );
  3277. falcon_handle_event ( efab, evt );
  3278. /* Clear the event */
  3279. EFAB_SET_QWORD ( *evt );
  3280. /* Move to the next event. We don't ack the event
  3281. * queue until the end */
  3282. ev_queue->read_ptr = ( ( ev_queue->read_ptr + 1 ) %
  3283. EFAB_EVQ_SIZE );
  3284. evt = ev_queue->ring + ev_queue->read_ptr;
  3285. }
  3286. /* Push more buffers if needed */
  3287. (void) efab_fill_rx_queue ( efab, rx_queue );
  3288. /* Clear any pending interrupts */
  3289. falcon_clear_interrupts ( efab );
  3290. /* Ack the event queue */
  3291. falcon_eventq_read_ack ( efab, ev_queue );
  3292. }
  3293. static void
  3294. efab_irq ( struct net_device *netdev, int enable )
  3295. {
  3296. struct efab_nic *efab = netdev_priv ( netdev );
  3297. struct efab_ev_queue *ev_queue = &efab->ev_queue;
  3298. switch ( enable ) {
  3299. case 0:
  3300. falcon_interrupts ( efab, 0, 0 );
  3301. break;
  3302. case 1:
  3303. falcon_interrupts ( efab, 1, 0 );
  3304. falcon_eventq_read_ack ( efab, ev_queue );
  3305. break;
  3306. case 2:
  3307. falcon_interrupts ( efab, 1, 1 );
  3308. break;
  3309. }
  3310. }
  3311. /*******************************************************************************
  3312. *
  3313. *
  3314. * Software open/close
  3315. *
  3316. *
  3317. *******************************************************************************/
  3318. static void
  3319. efab_free_resources ( struct efab_nic *efab )
  3320. {
  3321. struct efab_ev_queue *ev_queue = &efab->ev_queue;
  3322. struct efab_rx_queue *rx_queue = &efab->rx_queue;
  3323. struct efab_tx_queue *tx_queue = &efab->tx_queue;
  3324. int i;
  3325. for ( i = 0; i < EFAB_NUM_RX_DESC; i++ ) {
  3326. if ( rx_queue->buf[i] )
  3327. free_iob ( rx_queue->buf[i] );
  3328. }
  3329. for ( i = 0; i < EFAB_TXD_SIZE; i++ ) {
  3330. if ( tx_queue->buf[i] )
  3331. netdev_tx_complete ( efab->netdev, tx_queue->buf[i] );
  3332. }
  3333. if ( rx_queue->ring )
  3334. falcon_free_special_buffer ( rx_queue->ring );
  3335. if ( tx_queue->ring )
  3336. falcon_free_special_buffer ( tx_queue->ring );
  3337. if ( ev_queue->ring )
  3338. falcon_free_special_buffer ( ev_queue->ring );
  3339. memset ( rx_queue, 0, sizeof ( *rx_queue ) );
  3340. memset ( tx_queue, 0, sizeof ( *tx_queue ) );
  3341. memset ( ev_queue, 0, sizeof ( *ev_queue ) );
  3342. /* Ensure subsequent buffer allocations start at id 0 */
  3343. efab->buffer_head = 0;
  3344. }
  3345. static int
  3346. efab_alloc_resources ( struct efab_nic *efab )
  3347. {
  3348. struct efab_ev_queue *ev_queue = &efab->ev_queue;
  3349. struct efab_rx_queue *rx_queue = &efab->rx_queue;
  3350. struct efab_tx_queue *tx_queue = &efab->tx_queue;
  3351. size_t bytes;
  3352. /* Allocate the hardware event queue */
  3353. bytes = sizeof ( falcon_event_t ) * EFAB_TXD_SIZE;
  3354. ev_queue->ring = falcon_alloc_special_buffer ( efab, bytes,
  3355. &ev_queue->entry );
  3356. if ( !ev_queue->ring )
  3357. goto fail1;
  3358. /* Initialise the hardware event queue */
  3359. memset ( ev_queue->ring, 0xff, bytes );
  3360. /* Allocate the hardware tx queue */
  3361. bytes = sizeof ( falcon_tx_desc_t ) * EFAB_TXD_SIZE;
  3362. tx_queue->ring = falcon_alloc_special_buffer ( efab, bytes,
  3363. &tx_queue->entry );
  3364. if ( ! tx_queue->ring )
  3365. goto fail2;
  3366. /* Allocate the hardware rx queue */
  3367. bytes = sizeof ( falcon_rx_desc_t ) * EFAB_RXD_SIZE;
  3368. rx_queue->ring = falcon_alloc_special_buffer ( efab, bytes,
  3369. &rx_queue->entry );
  3370. if ( ! rx_queue->ring )
  3371. goto fail3;
  3372. return 0;
  3373. fail3:
  3374. falcon_free_special_buffer ( tx_queue->ring );
  3375. tx_queue->ring = NULL;
  3376. fail2:
  3377. falcon_free_special_buffer ( ev_queue->ring );
  3378. ev_queue->ring = NULL;
  3379. fail1:
  3380. return -ENOMEM;
  3381. }
  3382. static int
  3383. efab_init_mac ( struct efab_nic *efab )
  3384. {
  3385. int count, rc;
  3386. /* This can take several seconds */
  3387. EFAB_LOG ( "Waiting for link..\n" );
  3388. for ( count=0; count<5; count++ ) {
  3389. rc = efab->mac_op->init ( efab );
  3390. if ( rc ) {
  3391. EFAB_ERR ( "Failed reinitialising MAC, error %s\n",
  3392. strerror ( rc ));
  3393. return rc;
  3394. }
  3395. /* Sleep for 2s to wait for the link to settle, either
  3396. * because we want to use it, or because we're about
  3397. * to reset the mac anyway
  3398. */
  3399. sleep ( 2 );
  3400. if ( ! efab->link_up ) {
  3401. EFAB_ERR ( "!\n" );
  3402. continue;
  3403. }
  3404. EFAB_LOG ( "\n%dMbps %s-duplex\n",
  3405. ( efab->link_options & LPA_EF_10000 ? 10000 :
  3406. ( efab->link_options & LPA_EF_1000 ? 1000 :
  3407. ( efab->link_options & LPA_100 ? 100 : 10 ) ) ),
  3408. ( efab->link_options & LPA_EF_DUPLEX ?
  3409. "full" : "half" ) );
  3410. /* TODO: Move link state handling to the poll() routine */
  3411. netdev_link_up ( efab->netdev );
  3412. return 0;
  3413. }
  3414. EFAB_ERR ( "timed initialising MAC\n" );
  3415. return -ETIMEDOUT;
  3416. }
  3417. static void
  3418. efab_close ( struct net_device *netdev )
  3419. {
  3420. struct efab_nic *efab = netdev_priv ( netdev );
  3421. falcon_fini_resources ( efab );
  3422. efab_free_resources ( efab );
  3423. efab->board_op->fini ( efab );
  3424. falcon_reset ( efab );
  3425. }
  3426. static int
  3427. efab_open ( struct net_device *netdev )
  3428. {
  3429. struct efab_nic *efab = netdev_priv ( netdev );
  3430. struct efab_rx_queue *rx_queue = &efab->rx_queue;
  3431. int rc;
  3432. rc = falcon_reset ( efab );
  3433. if ( rc )
  3434. goto fail1;
  3435. rc = efab->board_op->init ( efab );
  3436. if ( rc )
  3437. goto fail2;
  3438. rc = falcon_init_sram ( efab );
  3439. if ( rc )
  3440. goto fail3;
  3441. /* Configure descriptor caches before pushing hardware queues */
  3442. falcon_setup_nic ( efab );
  3443. rc = efab_alloc_resources ( efab );
  3444. if ( rc )
  3445. goto fail4;
  3446. falcon_init_resources ( efab );
  3447. /* Push rx buffers */
  3448. rc = efab_fill_rx_queue ( efab, rx_queue );
  3449. if ( rc )
  3450. goto fail5;
  3451. /* Try and bring the interface up */
  3452. rc = efab_init_mac ( efab );
  3453. if ( rc )
  3454. goto fail6;
  3455. return 0;
  3456. fail6:
  3457. fail5:
  3458. efab_free_resources ( efab );
  3459. fail4:
  3460. fail3:
  3461. efab->board_op->fini ( efab );
  3462. fail2:
  3463. falcon_reset ( efab );
  3464. fail1:
  3465. return rc;
  3466. }
  3467. static struct net_device_operations efab_operations = {
  3468. .open = efab_open,
  3469. .close = efab_close,
  3470. .transmit = efab_transmit,
  3471. .poll = efab_poll,
  3472. .irq = efab_irq,
  3473. };
  3474. static void
  3475. efab_remove ( struct pci_device *pci )
  3476. {
  3477. struct net_device *netdev = pci_get_drvdata ( pci );
  3478. struct efab_nic *efab = netdev_priv ( netdev );
  3479. if ( efab->membase ) {
  3480. falcon_reset ( efab );
  3481. iounmap ( efab->membase );
  3482. efab->membase = NULL;
  3483. }
  3484. if ( efab->nvo.nvs ) {
  3485. unregister_nvo ( &efab->nvo );
  3486. efab->nvo.nvs = NULL;
  3487. }
  3488. unregister_netdev ( netdev );
  3489. netdev_nullify ( netdev );
  3490. netdev_put ( netdev );
  3491. }
  3492. static int
  3493. efab_probe ( struct pci_device *pci )
  3494. {
  3495. struct net_device *netdev;
  3496. struct efab_nic *efab;
  3497. unsigned long mmio_start, mmio_len;
  3498. int rc;
  3499. /* Create the network adapter */
  3500. netdev = alloc_etherdev ( sizeof ( struct efab_nic ) );
  3501. if ( ! netdev ) {
  3502. rc = -ENOMEM;
  3503. goto fail1;
  3504. }
  3505. /* Initialise the network adapter, and initialise private storage */
  3506. netdev_init ( netdev, &efab_operations );
  3507. pci_set_drvdata ( pci, netdev );
  3508. netdev->dev = &pci->dev;
  3509. efab = netdev_priv ( netdev );
  3510. memset ( efab, 0, sizeof ( *efab ) );
  3511. efab->netdev = netdev;
  3512. /* Get iobase/membase */
  3513. mmio_start = pci_bar_start ( pci, PCI_BASE_ADDRESS_2 );
  3514. mmio_len = pci_bar_size ( pci, PCI_BASE_ADDRESS_2 );
  3515. efab->membase = ioremap ( mmio_start, mmio_len );
  3516. EFAB_TRACE ( "BAR of %lx bytes at phys %lx mapped at %p\n",
  3517. mmio_len, mmio_start, efab->membase );
  3518. /* Enable the PCI device */
  3519. adjust_pci_device ( pci );
  3520. efab->iobase = pci->ioaddr & ~3;
  3521. /* Determine the NIC variant */
  3522. falcon_probe_nic_variant ( efab, pci );
  3523. /* Read the SPI interface and determine the MAC address,
  3524. * and the board and phy variant. Hook in the op tables */
  3525. rc = falcon_probe_spi ( efab );
  3526. if ( rc )
  3527. goto fail2;
  3528. rc = falcon_probe_nvram ( efab );
  3529. if ( rc )
  3530. goto fail3;
  3531. memcpy ( netdev->hw_addr, efab->mac_addr, ETH_ALEN );
  3532. rc = register_netdev ( netdev );
  3533. if ( rc )
  3534. goto fail4;
  3535. netdev_link_up ( netdev );
  3536. /* Advertise non-volatile storage */
  3537. if ( efab->nvo.nvs ) {
  3538. rc = register_nvo ( &efab->nvo, netdev_settings ( netdev ) );
  3539. if ( rc )
  3540. goto fail5;
  3541. }
  3542. EFAB_LOG ( "Found %s EtherFabric %s %s revision %d\n", pci->id->name,
  3543. efab->is_asic ? "ASIC" : "FPGA",
  3544. efab->phy_10g ? "10G" : "1G",
  3545. efab->pci_revision );
  3546. return 0;
  3547. fail5:
  3548. unregister_netdev ( netdev );
  3549. fail4:
  3550. fail3:
  3551. fail2:
  3552. iounmap ( efab->membase );
  3553. efab->membase = NULL;
  3554. netdev_put ( netdev );
  3555. fail1:
  3556. return rc;
  3557. }
  3558. static struct pci_device_id efab_nics[] = {
  3559. PCI_ROM(0x1924, 0x0703, "falcon", "EtherFabric Falcon", 0),
  3560. PCI_ROM(0x1924, 0x0710, "falconb0", "EtherFabric FalconB0", 0),
  3561. };
  3562. struct pci_driver etherfabric_driver __pci_driver = {
  3563. .ids = efab_nics,
  3564. .id_count = sizeof ( efab_nics ) / sizeof ( efab_nics[0] ),
  3565. .probe = efab_probe,
  3566. .remove = efab_remove,
  3567. };
  3568. /*
  3569. * Local variables:
  3570. * c-basic-offset: 8
  3571. * c-indent-level: 8
  3572. * tab-width: 8
  3573. * End:
  3574. */