Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

etherfabric.c 111KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230
  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 <unistd.h>
  22. #include <errno.h>
  23. #include <assert.h>
  24. #include <byteswap.h>
  25. #include <ipxe/console.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. efab_dword_t blankd;
  2619. int offset;
  2620. EFAB_ZERO_OWORD ( blanko );
  2621. EFAB_ZERO_DWORD ( blankd );
  2622. /* Clear the address region register */
  2623. EFAB_POPULATE_OWORD_4 ( temp,
  2624. FCN_ADR_REGION0, 0,
  2625. FCN_ADR_REGION1, ( 1 << 16 ),
  2626. FCN_ADR_REGION2, ( 2 << 16 ),
  2627. FCN_ADR_REGION3, ( 3 << 16 ) );
  2628. falcon_write ( efab, &temp, FCN_ADR_REGION_REG_KER );
  2629. EFAB_TRACE ( "Clearing filter and RSS tables\n" );
  2630. for ( offset = FCN_RX_FILTER_TBL0 ;
  2631. offset < FCN_RX_RSS_INDIR_TBL_B0+0x800 ;
  2632. offset += 0x10 ) {
  2633. falcon_write ( efab, &blanko, offset );
  2634. }
  2635. EFAB_TRACE ( "Wiping buffer tables\n" );
  2636. /* Notice the 8 byte access mode */
  2637. for ( offset = 0x2800000 ;
  2638. offset < 0x3000000 ;
  2639. offset += 0x8) {
  2640. _falcon_writel ( efab, 0, offset );
  2641. _falcon_writel ( efab, 0, offset + 4 );
  2642. wmb();
  2643. }
  2644. }
  2645. static int
  2646. falcon_reset ( struct efab_nic *efab )
  2647. {
  2648. efab_oword_t glb_ctl_reg_ker;
  2649. /* Initiate software reset */
  2650. EFAB_POPULATE_OWORD_6 ( glb_ctl_reg_ker,
  2651. FCN_PCIE_CORE_RST_CTL, EXCLUDE_FROM_RESET,
  2652. FCN_PCIE_NSTCK_RST_CTL, EXCLUDE_FROM_RESET,
  2653. FCN_PCIE_SD_RST_CTL, EXCLUDE_FROM_RESET,
  2654. FCN_EE_RST_CTL, EXCLUDE_FROM_RESET,
  2655. FCN_EXT_PHY_RST_DUR, 0x7, /* 10ms */
  2656. FCN_SWRST, 1 );
  2657. falcon_write ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
  2658. /* Allow 50ms for reset */
  2659. mdelay ( 50 );
  2660. /* Check for device reset complete */
  2661. falcon_read ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
  2662. if ( EFAB_OWORD_FIELD ( glb_ctl_reg_ker, FCN_SWRST ) != 0 ) {
  2663. EFAB_ERR ( "Reset failed\n" );
  2664. return -ETIMEDOUT;
  2665. }
  2666. if ( ( efab->pci_revision == FALCON_REV_B0 ) && !efab->is_asic ) {
  2667. clear_b0_fpga_memories ( efab );
  2668. }
  2669. return 0;
  2670. }
  2671. /** Offset of MAC address within EEPROM or Flash */
  2672. #define FALCON_MAC_ADDRESS_OFFSET 0x310
  2673. /*
  2674. * Falcon EEPROM structure
  2675. */
  2676. #define SF_NV_CONFIG_BASE 0x300
  2677. #define SF_NV_CONFIG_EXTRA 0xA0
  2678. struct falcon_nv_config_ver2 {
  2679. uint16_t nports;
  2680. uint8_t port0_phy_addr;
  2681. uint8_t port0_phy_type;
  2682. uint8_t port1_phy_addr;
  2683. uint8_t port1_phy_type;
  2684. uint16_t asic_sub_revision;
  2685. uint16_t board_revision;
  2686. uint8_t mac_location;
  2687. };
  2688. struct falcon_nv_extra {
  2689. uint16_t magicnumber;
  2690. uint16_t structure_version;
  2691. uint16_t checksum;
  2692. union {
  2693. struct falcon_nv_config_ver2 ver2;
  2694. } ver_specific;
  2695. };
  2696. #define BOARD_TYPE(_rev) (_rev >> 8)
  2697. static void
  2698. falcon_probe_nic_variant ( struct efab_nic *efab, struct pci_device *pci )
  2699. {
  2700. efab_oword_t altera_build, nic_stat;
  2701. int is_pcie, fpga_version;
  2702. uint8_t revision;
  2703. /* PCI revision */
  2704. pci_read_config_byte ( pci, PCI_CLASS_REVISION, &revision );
  2705. efab->pci_revision = revision;
  2706. /* Asic vs FPGA */
  2707. falcon_read ( efab, &altera_build, FCN_ALTERA_BUILD_REG_KER );
  2708. fpga_version = EFAB_OWORD_FIELD ( altera_build, FCN_VER_ALL );
  2709. efab->is_asic = (fpga_version == 0);
  2710. /* MAC and PCI type */
  2711. falcon_read ( efab, &nic_stat, FCN_NIC_STAT_REG );
  2712. if ( efab->pci_revision == FALCON_REV_B0 ) {
  2713. is_pcie = 1;
  2714. efab->phy_10g = EFAB_OWORD_FIELD ( nic_stat, FCN_STRAP_10G );
  2715. }
  2716. else if ( efab->is_asic ) {
  2717. is_pcie = EFAB_OWORD_FIELD ( nic_stat, FCN_STRAP_PCIE );
  2718. efab->phy_10g = EFAB_OWORD_FIELD ( nic_stat, FCN_STRAP_10G );
  2719. }
  2720. else {
  2721. int minor = EFAB_OWORD_FIELD ( altera_build, FCN_VER_MINOR );
  2722. is_pcie = 0;
  2723. efab->phy_10g = ( minor == 0x14 );
  2724. }
  2725. }
  2726. static void
  2727. falcon_init_spi_device ( struct efab_nic *efab, struct spi_device *spi )
  2728. {
  2729. /* Falcon's SPI interface only supports reads/writes of up to 16 bytes.
  2730. * Reduce the nvs block size down to satisfy this - which means callers
  2731. * should use the nvs_* functions rather than spi_*. */
  2732. if ( spi->nvs.block_size > FALCON_SPI_MAX_LEN )
  2733. spi->nvs.block_size = FALCON_SPI_MAX_LEN;
  2734. spi->bus = &efab->spi_bus;
  2735. efab->spi = spi;
  2736. }
  2737. static int
  2738. falcon_probe_spi ( struct efab_nic *efab )
  2739. {
  2740. efab_oword_t nic_stat, gpio_ctl, ee_vpd_cfg;
  2741. int has_flash, has_eeprom, ad9bit;
  2742. falcon_read ( efab, &nic_stat, FCN_NIC_STAT_REG );
  2743. falcon_read ( efab, &gpio_ctl, FCN_GPIO_CTL_REG_KER );
  2744. falcon_read ( efab, &ee_vpd_cfg, FCN_EE_VPD_CFG_REG );
  2745. /* determine if FLASH / EEPROM is present */
  2746. if ( ( efab->pci_revision >= FALCON_REV_B0 ) || efab->is_asic ) {
  2747. has_flash = EFAB_OWORD_FIELD ( nic_stat, FCN_SF_PRST );
  2748. has_eeprom = EFAB_OWORD_FIELD ( nic_stat, FCN_EE_PRST );
  2749. } else {
  2750. has_flash = EFAB_OWORD_FIELD ( gpio_ctl, FCN_FLASH_PRESENT );
  2751. has_eeprom = EFAB_OWORD_FIELD ( gpio_ctl, FCN_EEPROM_PRESENT );
  2752. }
  2753. ad9bit = EFAB_OWORD_FIELD ( ee_vpd_cfg, FCN_EE_VPD_EN_AD9_MODE );
  2754. /* Configure the SPI and I2C bus */
  2755. efab->spi_bus.rw = falcon_spi_rw;
  2756. init_i2c_bit_basher ( &efab->i2c_bb, &falcon_i2c_bit_ops );
  2757. /* Configure the EEPROM SPI device. Generally, an Atmel 25040
  2758. * (or similar) is used, but this is only possible if there is also
  2759. * a flash device present to store the boot-time chip configuration.
  2760. */
  2761. if ( has_eeprom ) {
  2762. if ( has_flash && ad9bit )
  2763. init_at25040 ( &efab->spi_eeprom );
  2764. else
  2765. init_mc25xx640 ( &efab->spi_eeprom );
  2766. falcon_init_spi_device ( efab, &efab->spi_eeprom );
  2767. }
  2768. /* Configure the FLASH SPI device */
  2769. if ( has_flash ) {
  2770. init_at25f1024 ( &efab->spi_flash );
  2771. falcon_init_spi_device ( efab, &efab->spi_flash );
  2772. }
  2773. EFAB_LOG ( "flash is %s, EEPROM is %s%s\n",
  2774. ( has_flash ? "present" : "absent" ),
  2775. ( has_eeprom ? "present " : "absent" ),
  2776. ( has_eeprom ? (ad9bit ? "(9bit)" : "(16bit)") : "") );
  2777. /* The device MUST have flash or eeprom */
  2778. if ( ! efab->spi ) {
  2779. EFAB_ERR ( "Device appears to have no flash or eeprom\n" );
  2780. return -EIO;
  2781. }
  2782. /* If the device has EEPROM attached, then advertise NVO space */
  2783. if ( has_eeprom ) {
  2784. nvo_init ( &efab->nvo, &efab->spi_eeprom.nvs, 0x100, 0xf0,
  2785. NULL, &efab->netdev->refcnt );
  2786. }
  2787. return 0;
  2788. }
  2789. static int
  2790. falcon_probe_nvram ( struct efab_nic *efab )
  2791. {
  2792. struct nvs_device *nvs = &efab->spi->nvs;
  2793. struct falcon_nv_extra nv;
  2794. int rc, board_revision;
  2795. /* Read the MAC address */
  2796. rc = nvs_read ( nvs, FALCON_MAC_ADDRESS_OFFSET,
  2797. efab->mac_addr, ETH_ALEN );
  2798. if ( rc )
  2799. return rc;
  2800. /* Poke through the NVRAM structure for the PHY type. */
  2801. rc = nvs_read ( nvs, SF_NV_CONFIG_BASE + SF_NV_CONFIG_EXTRA,
  2802. &nv, sizeof ( nv ) );
  2803. if ( rc )
  2804. return rc;
  2805. /* Handle each supported NVRAM version */
  2806. if ( ( le16_to_cpu ( nv.magicnumber ) == FCN_NV_MAGIC_NUMBER ) &&
  2807. ( le16_to_cpu ( nv.structure_version ) >= 2 ) ) {
  2808. struct falcon_nv_config_ver2* ver2 = &nv.ver_specific.ver2;
  2809. /* Get the PHY type */
  2810. efab->phy_addr = le16_to_cpu ( ver2->port0_phy_addr );
  2811. efab->phy_type = le16_to_cpu ( ver2->port0_phy_type );
  2812. board_revision = le16_to_cpu ( ver2->board_revision );
  2813. }
  2814. else {
  2815. EFAB_ERR ( "NVram is not recognised\n" );
  2816. return -EINVAL;
  2817. }
  2818. efab->board_type = BOARD_TYPE ( board_revision );
  2819. EFAB_TRACE ( "Falcon board %d phy %d @ addr %d\n",
  2820. efab->board_type, efab->phy_type, efab->phy_addr );
  2821. /* Patch in the board operations */
  2822. switch ( efab->board_type ) {
  2823. case EFAB_BOARD_SFE4001:
  2824. efab->board_op = &sfe4001_ops;
  2825. break;
  2826. case EFAB_BOARD_SFE4002:
  2827. efab->board_op = &sfe4002_ops;
  2828. break;
  2829. case EFAB_BOARD_SFE4003:
  2830. efab->board_op = &sfe4003_ops;
  2831. break;
  2832. default:
  2833. EFAB_ERR ( "Unrecognised board type\n" );
  2834. return -EINVAL;
  2835. }
  2836. /* Patch in MAC operations */
  2837. if ( efab->phy_10g )
  2838. efab->mac_op = &falcon_xmac_operations;
  2839. else
  2840. efab->mac_op = &falcon_gmac_operations;
  2841. /* Hook in the PHY ops */
  2842. switch ( efab->phy_type ) {
  2843. case PHY_TYPE_10XPRESS:
  2844. efab->phy_op = &falcon_tenxpress_phy_ops;
  2845. break;
  2846. case PHY_TYPE_CX4:
  2847. efab->phy_op = &falcon_xaui_phy_ops;
  2848. break;
  2849. case PHY_TYPE_XFP:
  2850. efab->phy_op = &falcon_xfp_phy_ops;
  2851. break;
  2852. case PHY_TYPE_CX4_RTMR:
  2853. efab->phy_op = &falcon_txc_phy_ops;
  2854. break;
  2855. case PHY_TYPE_PM8358:
  2856. efab->phy_op = &falcon_pm8358_phy_ops;
  2857. break;
  2858. case PHY_TYPE_1GIG_ALASKA:
  2859. efab->phy_op = &falcon_alaska_phy_ops;
  2860. break;
  2861. default:
  2862. EFAB_ERR ( "Unknown PHY type: %d\n", efab->phy_type );
  2863. return -EINVAL;
  2864. }
  2865. return 0;
  2866. }
  2867. static int
  2868. falcon_init_sram ( struct efab_nic *efab )
  2869. {
  2870. efab_oword_t reg;
  2871. int count;
  2872. /* use card in internal SRAM mode */
  2873. falcon_read ( efab, &reg, FCN_NIC_STAT_REG );
  2874. EFAB_SET_OWORD_FIELD ( reg, FCN_ONCHIP_SRAM, 1 );
  2875. falcon_write ( efab, &reg, FCN_NIC_STAT_REG );
  2876. /* Deactivate any external SRAM that might be present */
  2877. EFAB_POPULATE_OWORD_2 ( reg,
  2878. FCN_GPIO1_OEN, 1,
  2879. FCN_GPIO1_OUT, 1 );
  2880. falcon_write ( efab, &reg, FCN_GPIO_CTL_REG_KER );
  2881. /* Initiate SRAM reset */
  2882. EFAB_POPULATE_OWORD_2 ( reg,
  2883. FCN_SRAM_OOB_BT_INIT_EN, 1,
  2884. FCN_SRM_NUM_BANKS_AND_BANK_SIZE, 0 );
  2885. falcon_write ( efab, &reg, FCN_SRM_CFG_REG_KER );
  2886. /* Wait for SRAM reset to complete */
  2887. count = 0;
  2888. do {
  2889. /* SRAM reset is slow; expect around 16ms */
  2890. mdelay ( 20 );
  2891. /* Check for reset complete */
  2892. falcon_read ( efab, &reg, FCN_SRM_CFG_REG_KER );
  2893. if ( !EFAB_OWORD_FIELD ( reg, FCN_SRAM_OOB_BT_INIT_EN ) )
  2894. return 0;
  2895. } while (++count < 20); /* wait upto 0.4 sec */
  2896. EFAB_ERR ( "timed out waiting for SRAM reset\n");
  2897. return -ETIMEDOUT;
  2898. }
  2899. static void
  2900. falcon_setup_nic ( struct efab_nic *efab )
  2901. {
  2902. efab_dword_t timer_cmd;
  2903. efab_oword_t reg;
  2904. int tx_fc, xoff_thresh, xon_thresh;
  2905. /* bug5129: Clear the parity enables on the TX data fifos as
  2906. * they produce false parity errors because of timing issues
  2907. */
  2908. falcon_read ( efab, &reg, FCN_SPARE_REG_KER );
  2909. EFAB_SET_OWORD_FIELD ( reg, FCN_MEM_PERR_EN_TX_DATA, 0 );
  2910. falcon_write ( efab, &reg, FCN_SPARE_REG_KER );
  2911. /* Set up TX and RX descriptor caches in SRAM */
  2912. EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_TX_DC_BASE_ADR, 0x130000 );
  2913. falcon_write ( efab, &reg, FCN_SRM_TX_DC_CFG_REG_KER );
  2914. EFAB_POPULATE_OWORD_1 ( reg, FCN_TX_DC_SIZE, 1 /* 16 descriptors */ );
  2915. falcon_write ( efab, &reg, FCN_TX_DC_CFG_REG_KER );
  2916. EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_RX_DC_BASE_ADR, 0x100000 );
  2917. falcon_write ( efab, &reg, FCN_SRM_RX_DC_CFG_REG_KER );
  2918. EFAB_POPULATE_OWORD_1 ( reg, FCN_RX_DC_SIZE, 2 /* 32 descriptors */ );
  2919. falcon_write ( efab, &reg, FCN_RX_DC_CFG_REG_KER );
  2920. /* Set number of RSS CPUs
  2921. * bug7244: Increase filter depth to reduce RX_RESET likelyhood
  2922. */
  2923. EFAB_POPULATE_OWORD_5 ( reg,
  2924. FCN_NUM_KER, 0,
  2925. FCN_UDP_FULL_SRCH_LIMIT, 8,
  2926. FCN_UDP_WILD_SRCH_LIMIT, 8,
  2927. FCN_TCP_WILD_SRCH_LIMIT, 8,
  2928. FCN_TCP_FULL_SRCH_LIMIT, 8);
  2929. falcon_write ( efab, &reg, FCN_RX_FILTER_CTL_REG_KER );
  2930. udelay ( 1000 );
  2931. /* Setup RX. Wait for descriptor is broken and must
  2932. * be disabled. RXDP recovery shouldn't be needed, but is.
  2933. * disable ISCSI parsing because we don't need it
  2934. */
  2935. falcon_read ( efab, &reg, FCN_RX_SELF_RST_REG_KER );
  2936. EFAB_SET_OWORD_FIELD ( reg, FCN_RX_NODESC_WAIT_DIS, 1 );
  2937. EFAB_SET_OWORD_FIELD ( reg, FCN_RX_RECOVERY_EN, 1 );
  2938. EFAB_SET_OWORD_FIELD ( reg, FCN_RX_ISCSI_DIS, 1 );
  2939. falcon_write ( efab, &reg, FCN_RX_SELF_RST_REG_KER );
  2940. /* Determine recommended flow control settings. *
  2941. * Flow control is qualified on B0 and A1/1G, not on A1/10G */
  2942. if ( efab->pci_revision == FALCON_REV_B0 ) {
  2943. tx_fc = 1;
  2944. xoff_thresh = 54272; /* ~80Kb - 3*max MTU */
  2945. xon_thresh = 27648; /* ~3*max MTU */
  2946. }
  2947. else if ( !efab->phy_10g ) {
  2948. tx_fc = 1;
  2949. xoff_thresh = 2048;
  2950. xon_thresh = 512;
  2951. }
  2952. else {
  2953. tx_fc = xoff_thresh = xon_thresh = 0;
  2954. }
  2955. /* Setup TX and RX */
  2956. falcon_read ( efab, &reg, FCN_TX_CFG2_REG_KER );
  2957. EFAB_SET_OWORD_FIELD ( reg, FCN_TX_DIS_NON_IP_EV, 1 );
  2958. falcon_write ( efab, &reg, FCN_TX_CFG2_REG_KER );
  2959. falcon_read ( efab, &reg, FCN_RX_CFG_REG_KER );
  2960. EFAB_SET_OWORD_FIELD_VER ( efab, reg, FCN_RX_USR_BUF_SIZE,
  2961. (3*4096) / 32 );
  2962. if ( efab->pci_revision == FALCON_REV_B0)
  2963. EFAB_SET_OWORD_FIELD ( reg, FCN_RX_INGR_EN_B0, 1 );
  2964. EFAB_SET_OWORD_FIELD_VER ( efab, reg, FCN_RX_XON_MAC_TH,
  2965. xon_thresh / 256);
  2966. EFAB_SET_OWORD_FIELD_VER ( efab, reg, FCN_RX_XOFF_MAC_TH,
  2967. xoff_thresh / 256);
  2968. EFAB_SET_OWORD_FIELD_VER ( efab, reg, FCN_RX_XOFF_MAC_EN, tx_fc);
  2969. falcon_write ( efab, &reg, FCN_RX_CFG_REG_KER );
  2970. /* Set timer register */
  2971. EFAB_POPULATE_DWORD_2 ( timer_cmd,
  2972. FCN_TIMER_MODE, FCN_TIMER_MODE_DIS,
  2973. FCN_TIMER_VAL, 0 );
  2974. falcon_writel ( efab, &timer_cmd, FCN_TIMER_CMD_REG_KER );
  2975. }
  2976. static void
  2977. falcon_init_resources ( struct efab_nic *efab )
  2978. {
  2979. struct efab_ev_queue *ev_queue = &efab->ev_queue;
  2980. struct efab_rx_queue *rx_queue = &efab->rx_queue;
  2981. struct efab_tx_queue *tx_queue = &efab->tx_queue;
  2982. efab_oword_t reg;
  2983. int jumbo;
  2984. /* Initialise the ptrs */
  2985. tx_queue->read_ptr = tx_queue->write_ptr = 0;
  2986. rx_queue->read_ptr = rx_queue->write_ptr = 0;
  2987. ev_queue->read_ptr = 0;
  2988. /* Push the event queue to the hardware */
  2989. EFAB_POPULATE_OWORD_3 ( reg,
  2990. FCN_EVQ_EN, 1,
  2991. FCN_EVQ_SIZE, FQS(FCN_EVQ, EFAB_EVQ_SIZE),
  2992. FCN_EVQ_BUF_BASE_ID, ev_queue->entry.id );
  2993. falcon_write ( efab, &reg,
  2994. FCN_REVISION_REG ( efab, FCN_EVQ_PTR_TBL_KER ) );
  2995. /* Push the tx queue to the hardware */
  2996. EFAB_POPULATE_OWORD_8 ( reg,
  2997. FCN_TX_DESCQ_EN, 1,
  2998. FCN_TX_ISCSI_DDIG_EN, 0,
  2999. FCN_TX_ISCSI_DDIG_EN, 0,
  3000. FCN_TX_DESCQ_BUF_BASE_ID, tx_queue->entry.id,
  3001. FCN_TX_DESCQ_EVQ_ID, 0,
  3002. FCN_TX_DESCQ_SIZE, FQS(FCN_TX_DESCQ, EFAB_TXD_SIZE),
  3003. FCN_TX_DESCQ_TYPE, 0 /* kernel queue */,
  3004. FCN_TX_NON_IP_DROP_DIS_B0, 1 );
  3005. falcon_write ( efab, &reg,
  3006. FCN_REVISION_REG ( efab, FCN_TX_DESC_PTR_TBL_KER ) );
  3007. /* Push the rx queue to the hardware */
  3008. jumbo = ( efab->pci_revision == FALCON_REV_B0 ) ? 0 : 1;
  3009. EFAB_POPULATE_OWORD_8 ( reg,
  3010. FCN_RX_ISCSI_DDIG_EN, 0,
  3011. FCN_RX_ISCSI_HDIG_EN, 0,
  3012. FCN_RX_DESCQ_BUF_BASE_ID, rx_queue->entry.id,
  3013. FCN_RX_DESCQ_EVQ_ID, 0,
  3014. FCN_RX_DESCQ_SIZE, FQS(FCN_RX_DESCQ, EFAB_RXD_SIZE),
  3015. FCN_RX_DESCQ_TYPE, 0 /* kernel queue */,
  3016. FCN_RX_DESCQ_JUMBO, jumbo,
  3017. FCN_RX_DESCQ_EN, 1 );
  3018. falcon_write ( efab, &reg,
  3019. FCN_REVISION_REG ( efab, FCN_RX_DESC_PTR_TBL_KER ) );
  3020. /* Program INT_ADR_REG_KER */
  3021. EFAB_POPULATE_OWORD_1 ( reg,
  3022. FCN_INT_ADR_KER, virt_to_bus ( &efab->int_ker ) );
  3023. falcon_write ( efab, &reg, FCN_INT_ADR_REG_KER );
  3024. /* Ack the event queue */
  3025. falcon_eventq_read_ack ( efab, ev_queue );
  3026. }
  3027. static void
  3028. falcon_fini_resources ( struct efab_nic *efab )
  3029. {
  3030. efab_oword_t cmd;
  3031. /* Disable interrupts */
  3032. falcon_interrupts ( efab, 0, 0 );
  3033. /* Flush the dma queues */
  3034. EFAB_POPULATE_OWORD_2 ( cmd,
  3035. FCN_TX_FLUSH_DESCQ_CMD, 1,
  3036. FCN_TX_FLUSH_DESCQ, 0 );
  3037. falcon_write ( efab, &cmd,
  3038. FCN_REVISION_REG ( efab, FCN_TX_DESC_PTR_TBL_KER ) );
  3039. EFAB_POPULATE_OWORD_2 ( cmd,
  3040. FCN_RX_FLUSH_DESCQ_CMD, 1,
  3041. FCN_RX_FLUSH_DESCQ, 0 );
  3042. falcon_write ( efab, &cmd,
  3043. FCN_REVISION_REG ( efab, FCN_RX_DESC_PTR_TBL_KER ) );
  3044. mdelay ( 100 );
  3045. /* Remove descriptor rings from card */
  3046. EFAB_ZERO_OWORD ( cmd );
  3047. falcon_write ( efab, &cmd,
  3048. FCN_REVISION_REG ( efab, FCN_TX_DESC_PTR_TBL_KER ) );
  3049. falcon_write ( efab, &cmd,
  3050. FCN_REVISION_REG ( efab, FCN_RX_DESC_PTR_TBL_KER ) );
  3051. falcon_write ( efab, &cmd,
  3052. FCN_REVISION_REG ( efab, FCN_EVQ_PTR_TBL_KER ) );
  3053. }
  3054. /*******************************************************************************
  3055. *
  3056. *
  3057. * Hardware rx path
  3058. *
  3059. *
  3060. *******************************************************************************/
  3061. static void
  3062. falcon_build_rx_desc ( falcon_rx_desc_t *rxd, struct io_buffer *iob )
  3063. {
  3064. EFAB_POPULATE_QWORD_2 ( *rxd,
  3065. FCN_RX_KER_BUF_SIZE, EFAB_RX_BUF_SIZE,
  3066. FCN_RX_KER_BUF_ADR, virt_to_bus ( iob->data ) );
  3067. }
  3068. static void
  3069. falcon_notify_rx_desc ( struct efab_nic *efab, struct efab_rx_queue *rx_queue )
  3070. {
  3071. efab_dword_t reg;
  3072. int ptr = rx_queue->write_ptr % EFAB_RXD_SIZE;
  3073. EFAB_POPULATE_DWORD_1 ( reg, FCN_RX_DESC_WPTR_DWORD, ptr );
  3074. falcon_writel ( efab, &reg, FCN_RX_DESC_UPD_REG_KER_DWORD );
  3075. }
  3076. /*******************************************************************************
  3077. *
  3078. *
  3079. * Hardware tx path
  3080. *
  3081. *
  3082. *******************************************************************************/
  3083. static void
  3084. falcon_build_tx_desc ( falcon_tx_desc_t *txd, struct io_buffer *iob )
  3085. {
  3086. EFAB_POPULATE_QWORD_2 ( *txd,
  3087. FCN_TX_KER_BYTE_CNT, iob_len ( iob ),
  3088. FCN_TX_KER_BUF_ADR, virt_to_bus ( iob->data ) );
  3089. }
  3090. static void
  3091. falcon_notify_tx_desc ( struct efab_nic *efab,
  3092. struct efab_tx_queue *tx_queue )
  3093. {
  3094. efab_dword_t reg;
  3095. int ptr = tx_queue->write_ptr % EFAB_TXD_SIZE;
  3096. EFAB_POPULATE_DWORD_1 ( reg, FCN_TX_DESC_WPTR_DWORD, ptr );
  3097. falcon_writel ( efab, &reg, FCN_TX_DESC_UPD_REG_KER_DWORD );
  3098. }
  3099. /*******************************************************************************
  3100. *
  3101. *
  3102. * Software receive interface
  3103. *
  3104. *
  3105. *******************************************************************************/
  3106. static int
  3107. efab_fill_rx_queue ( struct efab_nic *efab,
  3108. struct efab_rx_queue *rx_queue )
  3109. {
  3110. int fill_level = rx_queue->write_ptr - rx_queue->read_ptr;
  3111. int space = EFAB_NUM_RX_DESC - fill_level - 1;
  3112. int pushed = 0;
  3113. while ( space ) {
  3114. int buf_id = rx_queue->write_ptr % EFAB_NUM_RX_DESC;
  3115. int desc_id = rx_queue->write_ptr % EFAB_RXD_SIZE;
  3116. struct io_buffer *iob;
  3117. falcon_rx_desc_t *rxd;
  3118. assert ( rx_queue->buf[buf_id] == NULL );
  3119. iob = alloc_iob ( EFAB_RX_BUF_SIZE );
  3120. if ( !iob )
  3121. break;
  3122. EFAB_TRACE ( "pushing rx_buf[%d] iob %p data %p\n",
  3123. buf_id, iob, iob->data );
  3124. rx_queue->buf[buf_id] = iob;
  3125. rxd = rx_queue->ring + desc_id;
  3126. falcon_build_rx_desc ( rxd, iob );
  3127. ++rx_queue->write_ptr;
  3128. ++pushed;
  3129. --space;
  3130. }
  3131. if ( pushed ) {
  3132. /* Push the ptr to hardware */
  3133. falcon_notify_rx_desc ( efab, rx_queue );
  3134. fill_level = rx_queue->write_ptr - rx_queue->read_ptr;
  3135. EFAB_TRACE ( "pushed %d rx buffers to fill level %d\n",
  3136. pushed, fill_level );
  3137. }
  3138. if ( fill_level == 0 )
  3139. return -ENOMEM;
  3140. return 0;
  3141. }
  3142. static void
  3143. efab_receive ( struct efab_nic *efab, unsigned int id, int len, int drop )
  3144. {
  3145. struct efab_rx_queue *rx_queue = &efab->rx_queue;
  3146. struct io_buffer *iob;
  3147. unsigned int read_ptr = rx_queue->read_ptr % EFAB_RXD_SIZE;
  3148. unsigned int buf_ptr = rx_queue->read_ptr % EFAB_NUM_RX_DESC;
  3149. assert ( id == read_ptr );
  3150. /* Pop this rx buffer out of the software ring */
  3151. iob = rx_queue->buf[buf_ptr];
  3152. rx_queue->buf[buf_ptr] = NULL;
  3153. EFAB_TRACE ( "popping rx_buf[%d] iob %p data %p with %d bytes %s\n",
  3154. id, iob, iob->data, len, drop ? "bad" : "ok" );
  3155. /* Pass the packet up if required */
  3156. if ( drop )
  3157. free_iob ( iob );
  3158. else {
  3159. iob_put ( iob, len );
  3160. netdev_rx ( efab->netdev, iob );
  3161. }
  3162. ++rx_queue->read_ptr;
  3163. }
  3164. /*******************************************************************************
  3165. *
  3166. *
  3167. * Software transmit interface
  3168. *
  3169. *
  3170. *******************************************************************************/
  3171. static int
  3172. efab_transmit ( struct net_device *netdev, struct io_buffer *iob )
  3173. {
  3174. struct efab_nic *efab = netdev_priv ( netdev );
  3175. struct efab_tx_queue *tx_queue = &efab->tx_queue;
  3176. int fill_level, space;
  3177. falcon_tx_desc_t *txd;
  3178. int buf_id;
  3179. fill_level = tx_queue->write_ptr - tx_queue->read_ptr;
  3180. space = EFAB_TXD_SIZE - fill_level - 1;
  3181. if ( space < 1 )
  3182. return -ENOBUFS;
  3183. /* Save the iobuffer for later completion */
  3184. buf_id = tx_queue->write_ptr % EFAB_TXD_SIZE;
  3185. assert ( tx_queue->buf[buf_id] == NULL );
  3186. tx_queue->buf[buf_id] = iob;
  3187. EFAB_TRACE ( "tx_buf[%d] for iob %p data %p len %zd\n",
  3188. buf_id, iob, iob->data, iob_len ( iob ) );
  3189. /* Form the descriptor, and push it to hardware */
  3190. txd = tx_queue->ring + buf_id;
  3191. falcon_build_tx_desc ( txd, iob );
  3192. ++tx_queue->write_ptr;
  3193. falcon_notify_tx_desc ( efab, tx_queue );
  3194. return 0;
  3195. }
  3196. static int
  3197. efab_transmit_done ( struct efab_nic *efab, int id )
  3198. {
  3199. struct efab_tx_queue *tx_queue = &efab->tx_queue;
  3200. unsigned int read_ptr, stop;
  3201. /* Complete all buffers from read_ptr up to and including id */
  3202. read_ptr = tx_queue->read_ptr % EFAB_TXD_SIZE;
  3203. stop = ( id + 1 ) % EFAB_TXD_SIZE;
  3204. while ( read_ptr != stop ) {
  3205. struct io_buffer *iob = tx_queue->buf[read_ptr];
  3206. assert ( iob );
  3207. /* Complete the tx buffer */
  3208. if ( iob )
  3209. netdev_tx_complete ( efab->netdev, iob );
  3210. tx_queue->buf[read_ptr] = NULL;
  3211. ++tx_queue->read_ptr;
  3212. read_ptr = tx_queue->read_ptr % EFAB_TXD_SIZE;
  3213. }
  3214. return 0;
  3215. }
  3216. /*******************************************************************************
  3217. *
  3218. *
  3219. * Hardware event path
  3220. *
  3221. *
  3222. *******************************************************************************/
  3223. static void
  3224. falcon_clear_interrupts ( struct efab_nic *efab )
  3225. {
  3226. efab_dword_t reg;
  3227. if ( efab->pci_revision == FALCON_REV_B0 ) {
  3228. /* read the ISR */
  3229. falcon_readl( efab, &reg, INT_ISR0_B0 );
  3230. }
  3231. else {
  3232. /* write to the INT_ACK register */
  3233. falcon_writel ( efab, 0, FCN_INT_ACK_KER_REG_A1 );
  3234. mb();
  3235. falcon_readl ( efab, &reg,
  3236. WORK_AROUND_BROKEN_PCI_READS_REG_KER_A1 );
  3237. }
  3238. }
  3239. static void
  3240. falcon_handle_event ( struct efab_nic *efab, falcon_event_t *evt )
  3241. {
  3242. int ev_code, desc_ptr, len, drop;
  3243. /* Decode event */
  3244. ev_code = EFAB_QWORD_FIELD ( *evt, FCN_EV_CODE );
  3245. switch ( ev_code ) {
  3246. case FCN_TX_IP_EV_DECODE:
  3247. desc_ptr = EFAB_QWORD_FIELD ( *evt, FCN_TX_EV_DESC_PTR );
  3248. efab_transmit_done ( efab, desc_ptr );
  3249. break;
  3250. case FCN_RX_IP_EV_DECODE:
  3251. desc_ptr = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_DESC_PTR );
  3252. len = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_BYTE_CNT );
  3253. drop = !EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_PKT_OK );
  3254. efab_receive ( efab, desc_ptr, len, drop );
  3255. break;
  3256. default:
  3257. EFAB_TRACE ( "Unknown event type %d\n", ev_code );
  3258. break;
  3259. }
  3260. }
  3261. /*******************************************************************************
  3262. *
  3263. *
  3264. * Software (polling) interrupt handler
  3265. *
  3266. *
  3267. *******************************************************************************/
  3268. static void
  3269. efab_poll ( struct net_device *netdev )
  3270. {
  3271. struct efab_nic *efab = netdev_priv ( netdev );
  3272. struct efab_ev_queue *ev_queue = &efab->ev_queue;
  3273. struct efab_rx_queue *rx_queue = &efab->rx_queue;
  3274. falcon_event_t *evt;
  3275. /* Read the event queue by directly looking for events
  3276. * (we don't even bother to read the eventq write ptr) */
  3277. evt = ev_queue->ring + ev_queue->read_ptr;
  3278. while ( falcon_event_present ( evt ) ) {
  3279. EFAB_TRACE ( "Event at index 0x%x address %p is "
  3280. EFAB_QWORD_FMT "\n", ev_queue->read_ptr,
  3281. evt, EFAB_QWORD_VAL ( *evt ) );
  3282. falcon_handle_event ( efab, evt );
  3283. /* Clear the event */
  3284. EFAB_SET_QWORD ( *evt );
  3285. /* Move to the next event. We don't ack the event
  3286. * queue until the end */
  3287. ev_queue->read_ptr = ( ( ev_queue->read_ptr + 1 ) %
  3288. EFAB_EVQ_SIZE );
  3289. evt = ev_queue->ring + ev_queue->read_ptr;
  3290. }
  3291. /* Push more buffers if needed */
  3292. (void) efab_fill_rx_queue ( efab, rx_queue );
  3293. /* Clear any pending interrupts */
  3294. falcon_clear_interrupts ( efab );
  3295. /* Ack the event queue */
  3296. falcon_eventq_read_ack ( efab, ev_queue );
  3297. }
  3298. static void
  3299. efab_irq ( struct net_device *netdev, int enable )
  3300. {
  3301. struct efab_nic *efab = netdev_priv ( netdev );
  3302. struct efab_ev_queue *ev_queue = &efab->ev_queue;
  3303. switch ( enable ) {
  3304. case 0:
  3305. falcon_interrupts ( efab, 0, 0 );
  3306. break;
  3307. case 1:
  3308. falcon_interrupts ( efab, 1, 0 );
  3309. falcon_eventq_read_ack ( efab, ev_queue );
  3310. break;
  3311. case 2:
  3312. falcon_interrupts ( efab, 1, 1 );
  3313. break;
  3314. }
  3315. }
  3316. /*******************************************************************************
  3317. *
  3318. *
  3319. * Software open/close
  3320. *
  3321. *
  3322. *******************************************************************************/
  3323. static void
  3324. efab_free_resources ( struct efab_nic *efab )
  3325. {
  3326. struct efab_ev_queue *ev_queue = &efab->ev_queue;
  3327. struct efab_rx_queue *rx_queue = &efab->rx_queue;
  3328. struct efab_tx_queue *tx_queue = &efab->tx_queue;
  3329. int i;
  3330. for ( i = 0; i < EFAB_NUM_RX_DESC; i++ ) {
  3331. if ( rx_queue->buf[i] )
  3332. free_iob ( rx_queue->buf[i] );
  3333. }
  3334. for ( i = 0; i < EFAB_TXD_SIZE; i++ ) {
  3335. if ( tx_queue->buf[i] )
  3336. netdev_tx_complete ( efab->netdev, tx_queue->buf[i] );
  3337. }
  3338. if ( rx_queue->ring )
  3339. falcon_free_special_buffer ( rx_queue->ring );
  3340. if ( tx_queue->ring )
  3341. falcon_free_special_buffer ( tx_queue->ring );
  3342. if ( ev_queue->ring )
  3343. falcon_free_special_buffer ( ev_queue->ring );
  3344. memset ( rx_queue, 0, sizeof ( *rx_queue ) );
  3345. memset ( tx_queue, 0, sizeof ( *tx_queue ) );
  3346. memset ( ev_queue, 0, sizeof ( *ev_queue ) );
  3347. /* Ensure subsequent buffer allocations start at id 0 */
  3348. efab->buffer_head = 0;
  3349. }
  3350. static int
  3351. efab_alloc_resources ( struct efab_nic *efab )
  3352. {
  3353. struct efab_ev_queue *ev_queue = &efab->ev_queue;
  3354. struct efab_rx_queue *rx_queue = &efab->rx_queue;
  3355. struct efab_tx_queue *tx_queue = &efab->tx_queue;
  3356. size_t bytes;
  3357. /* Allocate the hardware event queue */
  3358. bytes = sizeof ( falcon_event_t ) * EFAB_TXD_SIZE;
  3359. ev_queue->ring = falcon_alloc_special_buffer ( efab, bytes,
  3360. &ev_queue->entry );
  3361. if ( !ev_queue->ring )
  3362. goto fail1;
  3363. /* Initialise the hardware event queue */
  3364. memset ( ev_queue->ring, 0xff, bytes );
  3365. /* Allocate the hardware tx queue */
  3366. bytes = sizeof ( falcon_tx_desc_t ) * EFAB_TXD_SIZE;
  3367. tx_queue->ring = falcon_alloc_special_buffer ( efab, bytes,
  3368. &tx_queue->entry );
  3369. if ( ! tx_queue->ring )
  3370. goto fail2;
  3371. /* Allocate the hardware rx queue */
  3372. bytes = sizeof ( falcon_rx_desc_t ) * EFAB_RXD_SIZE;
  3373. rx_queue->ring = falcon_alloc_special_buffer ( efab, bytes,
  3374. &rx_queue->entry );
  3375. if ( ! rx_queue->ring )
  3376. goto fail3;
  3377. return 0;
  3378. fail3:
  3379. falcon_free_special_buffer ( tx_queue->ring );
  3380. tx_queue->ring = NULL;
  3381. fail2:
  3382. falcon_free_special_buffer ( ev_queue->ring );
  3383. ev_queue->ring = NULL;
  3384. fail1:
  3385. return -ENOMEM;
  3386. }
  3387. static int
  3388. efab_init_mac ( struct efab_nic *efab )
  3389. {
  3390. int count, rc;
  3391. /* This can take several seconds */
  3392. EFAB_LOG ( "Waiting for link..\n" );
  3393. for ( count=0; count<5; count++ ) {
  3394. rc = efab->mac_op->init ( efab );
  3395. if ( rc ) {
  3396. EFAB_ERR ( "Failed reinitialising MAC, error %s\n",
  3397. strerror ( rc ));
  3398. return rc;
  3399. }
  3400. /* Sleep for 2s to wait for the link to settle, either
  3401. * because we want to use it, or because we're about
  3402. * to reset the mac anyway
  3403. */
  3404. sleep ( 2 );
  3405. if ( ! efab->link_up ) {
  3406. EFAB_ERR ( "!\n" );
  3407. continue;
  3408. }
  3409. EFAB_LOG ( "\n%dMbps %s-duplex\n",
  3410. ( efab->link_options & LPA_EF_10000 ? 10000 :
  3411. ( efab->link_options & LPA_EF_1000 ? 1000 :
  3412. ( efab->link_options & LPA_100 ? 100 : 10 ) ) ),
  3413. ( efab->link_options & LPA_EF_DUPLEX ?
  3414. "full" : "half" ) );
  3415. /* TODO: Move link state handling to the poll() routine */
  3416. netdev_link_up ( efab->netdev );
  3417. return 0;
  3418. }
  3419. EFAB_ERR ( "timed initialising MAC\n" );
  3420. return -ETIMEDOUT;
  3421. }
  3422. static void
  3423. efab_close ( struct net_device *netdev )
  3424. {
  3425. struct efab_nic *efab = netdev_priv ( netdev );
  3426. falcon_fini_resources ( efab );
  3427. efab_free_resources ( efab );
  3428. efab->board_op->fini ( efab );
  3429. falcon_reset ( efab );
  3430. }
  3431. static int
  3432. efab_open ( struct net_device *netdev )
  3433. {
  3434. struct efab_nic *efab = netdev_priv ( netdev );
  3435. struct efab_rx_queue *rx_queue = &efab->rx_queue;
  3436. int rc;
  3437. rc = falcon_reset ( efab );
  3438. if ( rc )
  3439. goto fail1;
  3440. rc = efab->board_op->init ( efab );
  3441. if ( rc )
  3442. goto fail2;
  3443. rc = falcon_init_sram ( efab );
  3444. if ( rc )
  3445. goto fail3;
  3446. /* Configure descriptor caches before pushing hardware queues */
  3447. falcon_setup_nic ( efab );
  3448. rc = efab_alloc_resources ( efab );
  3449. if ( rc )
  3450. goto fail4;
  3451. falcon_init_resources ( efab );
  3452. /* Push rx buffers */
  3453. rc = efab_fill_rx_queue ( efab, rx_queue );
  3454. if ( rc )
  3455. goto fail5;
  3456. /* Try and bring the interface up */
  3457. rc = efab_init_mac ( efab );
  3458. if ( rc )
  3459. goto fail6;
  3460. return 0;
  3461. fail6:
  3462. fail5:
  3463. efab_free_resources ( efab );
  3464. fail4:
  3465. fail3:
  3466. efab->board_op->fini ( efab );
  3467. fail2:
  3468. falcon_reset ( efab );
  3469. fail1:
  3470. return rc;
  3471. }
  3472. static struct net_device_operations efab_operations = {
  3473. .open = efab_open,
  3474. .close = efab_close,
  3475. .transmit = efab_transmit,
  3476. .poll = efab_poll,
  3477. .irq = efab_irq,
  3478. };
  3479. static void
  3480. efab_remove ( struct pci_device *pci )
  3481. {
  3482. struct net_device *netdev = pci_get_drvdata ( pci );
  3483. struct efab_nic *efab = netdev_priv ( netdev );
  3484. if ( efab->membase ) {
  3485. falcon_reset ( efab );
  3486. iounmap ( efab->membase );
  3487. efab->membase = NULL;
  3488. }
  3489. if ( efab->nvo.nvs ) {
  3490. unregister_nvo ( &efab->nvo );
  3491. efab->nvo.nvs = NULL;
  3492. }
  3493. unregister_netdev ( netdev );
  3494. netdev_nullify ( netdev );
  3495. netdev_put ( netdev );
  3496. }
  3497. static int
  3498. efab_probe ( struct pci_device *pci )
  3499. {
  3500. struct net_device *netdev;
  3501. struct efab_nic *efab;
  3502. unsigned long mmio_start, mmio_len;
  3503. int rc;
  3504. /* Create the network adapter */
  3505. netdev = alloc_etherdev ( sizeof ( struct efab_nic ) );
  3506. if ( ! netdev ) {
  3507. rc = -ENOMEM;
  3508. goto fail1;
  3509. }
  3510. /* Initialise the network adapter, and initialise private storage */
  3511. netdev_init ( netdev, &efab_operations );
  3512. pci_set_drvdata ( pci, netdev );
  3513. netdev->dev = &pci->dev;
  3514. efab = netdev_priv ( netdev );
  3515. memset ( efab, 0, sizeof ( *efab ) );
  3516. efab->netdev = netdev;
  3517. /* Get iobase/membase */
  3518. mmio_start = pci_bar_start ( pci, PCI_BASE_ADDRESS_2 );
  3519. mmio_len = pci_bar_size ( pci, PCI_BASE_ADDRESS_2 );
  3520. efab->membase = ioremap ( mmio_start, mmio_len );
  3521. EFAB_TRACE ( "BAR of %lx bytes at phys %lx mapped at %p\n",
  3522. mmio_len, mmio_start, efab->membase );
  3523. /* Enable the PCI device */
  3524. adjust_pci_device ( pci );
  3525. efab->iobase = pci->ioaddr & ~3;
  3526. /* Determine the NIC variant */
  3527. falcon_probe_nic_variant ( efab, pci );
  3528. /* Read the SPI interface and determine the MAC address,
  3529. * and the board and phy variant. Hook in the op tables */
  3530. rc = falcon_probe_spi ( efab );
  3531. if ( rc )
  3532. goto fail2;
  3533. rc = falcon_probe_nvram ( efab );
  3534. if ( rc )
  3535. goto fail3;
  3536. memcpy ( netdev->hw_addr, efab->mac_addr, ETH_ALEN );
  3537. rc = register_netdev ( netdev );
  3538. if ( rc )
  3539. goto fail4;
  3540. netdev_link_up ( netdev );
  3541. /* Advertise non-volatile storage */
  3542. if ( efab->nvo.nvs ) {
  3543. rc = register_nvo ( &efab->nvo, netdev_settings ( netdev ) );
  3544. if ( rc )
  3545. goto fail5;
  3546. }
  3547. EFAB_LOG ( "Found %s EtherFabric %s %s revision %d\n", pci->id->name,
  3548. efab->is_asic ? "ASIC" : "FPGA",
  3549. efab->phy_10g ? "10G" : "1G",
  3550. efab->pci_revision );
  3551. return 0;
  3552. fail5:
  3553. unregister_netdev ( netdev );
  3554. fail4:
  3555. fail3:
  3556. fail2:
  3557. iounmap ( efab->membase );
  3558. efab->membase = NULL;
  3559. netdev_put ( netdev );
  3560. fail1:
  3561. return rc;
  3562. }
  3563. static struct pci_device_id efab_nics[] = {
  3564. PCI_ROM(0x1924, 0x0703, "falcon", "EtherFabric Falcon", 0),
  3565. PCI_ROM(0x1924, 0x0710, "falconb0", "EtherFabric FalconB0", 0),
  3566. };
  3567. struct pci_driver etherfabric_driver __pci_driver = {
  3568. .ids = efab_nics,
  3569. .id_count = sizeof ( efab_nics ) / sizeof ( efab_nics[0] ),
  3570. .probe = efab_probe,
  3571. .remove = efab_remove,
  3572. };
  3573. /*
  3574. * Local variables:
  3575. * c-basic-offset: 8
  3576. * c-indent-level: 8
  3577. * tab-width: 8
  3578. * End:
  3579. */