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

etherfabric.c 112KB

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