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 92KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437
  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 "etherboot.h"
  19. #include "nic.h"
  20. #include <errno.h>
  21. #include <gpxe/pci.h>
  22. #include <gpxe/bitbash.h>
  23. #include <gpxe/i2c.h>
  24. #include <gpxe/spi.h>
  25. #include <gpxe/nvo.h>
  26. #include "timer.h"
  27. #define dma_addr_t unsigned long
  28. #include "etherfabric.h"
  29. /**************************************************************************
  30. *
  31. * Constants and macros
  32. *
  33. **************************************************************************
  34. */
  35. #define EFAB_ASSERT(x) \
  36. do { \
  37. if ( ! (x) ) { \
  38. DBG ( "ASSERT(%s) failed at %s line %d [%s]\n", #x, \
  39. __FILE__, __LINE__, __FUNCTION__ ); \
  40. } \
  41. } while (0)
  42. #define EFAB_TRACE(...) DBG ( __VA_ARGS__ )
  43. #define EFAB_REGDUMP(...)
  44. #define EFAB_LOG(...) printf ( __VA_ARGS__ )
  45. #define EFAB_ERR(...) printf ( __VA_ARGS__ )
  46. #define FALCON_USE_IO_BAR 1
  47. /*
  48. * EtherFabric constants
  49. *
  50. */
  51. /* PCI Definitions */
  52. #define EFAB_VENDID_LEVEL5 0x1924
  53. #define FALCON_P_DEVID 0x0703 /* Temporary PCI ID */
  54. #define EF1002_DEVID 0xC101
  55. /**************************************************************************
  56. *
  57. * Data structures
  58. *
  59. **************************************************************************
  60. */
  61. /*
  62. * Buffers used for TX, RX and event queue
  63. *
  64. */
  65. #define EFAB_BUF_ALIGN 4096
  66. #define EFAB_DATA_BUF_SIZE 2048
  67. #define EFAB_RX_BUFS 16
  68. #define EFAB_RXD_SIZE 512
  69. #define EFAB_TXD_SIZE 512
  70. #define EFAB_EVQ_SIZE 512
  71. struct efab_buffers {
  72. uint8_t eventq[4096];
  73. uint8_t rxd[4096];
  74. uint8_t txd[4096];
  75. uint8_t tx_buf[EFAB_DATA_BUF_SIZE];
  76. uint8_t rx_buf[EFAB_RX_BUFS][EFAB_DATA_BUF_SIZE];
  77. uint8_t padding[EFAB_BUF_ALIGN-1];
  78. };
  79. static struct efab_buffers efab_buffers;
  80. /** An RX buffer */
  81. struct efab_rx_buf {
  82. uint8_t *addr;
  83. unsigned int len;
  84. int id;
  85. };
  86. /** A TX buffer */
  87. struct efab_tx_buf {
  88. uint8_t *addr;
  89. unsigned int len;
  90. int id;
  91. };
  92. /** Etherfabric event type */
  93. enum efab_event_type {
  94. EFAB_EV_NONE = 0,
  95. EFAB_EV_TX,
  96. EFAB_EV_RX,
  97. };
  98. /** Etherfabric event */
  99. struct efab_event {
  100. /** Event type */
  101. enum efab_event_type type;
  102. /** RX buffer ID */
  103. int rx_id;
  104. /** RX length */
  105. unsigned int rx_len;
  106. /** Packet should be dropped */
  107. int drop;
  108. };
  109. /*
  110. * Etherfabric abstraction layer
  111. *
  112. */
  113. struct efab_nic;
  114. struct efab_operations {
  115. void ( * get_membase ) ( struct efab_nic *efab );
  116. int ( * reset ) ( struct efab_nic *efab );
  117. int ( * init_nic ) ( struct efab_nic *efab );
  118. int ( * read_eeprom ) ( struct efab_nic *efab );
  119. void ( * build_rx_desc ) ( struct efab_nic *efab,
  120. struct efab_rx_buf *rx_buf );
  121. void ( * notify_rx_desc ) ( struct efab_nic *efab );
  122. void ( * build_tx_desc ) ( struct efab_nic *efab,
  123. struct efab_tx_buf *tx_buf );
  124. void ( * notify_tx_desc ) ( struct efab_nic *efab );
  125. int ( * fetch_event ) ( struct efab_nic *efab,
  126. struct efab_event *event );
  127. void ( * mask_irq ) ( struct efab_nic *efab, int enabled );
  128. void ( * generate_irq ) ( struct efab_nic *efab );
  129. void ( * mdio_write ) ( struct efab_nic *efab, int location,
  130. int value );
  131. int ( * mdio_read ) ( struct efab_nic *efab, int location );
  132. };
  133. struct efab_mac_operations {
  134. void ( * mac_writel ) ( struct efab_nic *efab, efab_dword_t *value,
  135. unsigned int mac_reg );
  136. void ( * mac_readl ) ( struct efab_nic *efab, efab_dword_t *value,
  137. unsigned int mac_reg );
  138. int ( * init ) ( struct efab_nic *efab );
  139. int ( * reset ) ( struct efab_nic *efab );
  140. };
  141. /*
  142. * Driver private data structure
  143. *
  144. */
  145. struct efab_nic {
  146. /** PCI device */
  147. struct pci_device *pci;
  148. /** Operations table */
  149. struct efab_operations *op;
  150. /** MAC operations table */
  151. struct efab_mac_operations *mac_op;
  152. /** Memory base */
  153. void *membase;
  154. /** I/O base */
  155. unsigned int iobase;
  156. /** Buffers */
  157. uint8_t *eventq; /* Falcon only */
  158. uint8_t *txd; /* Falcon only */
  159. uint8_t *rxd; /* Falcon only */
  160. struct efab_tx_buf tx_buf;
  161. struct efab_rx_buf rx_bufs[EFAB_RX_BUFS];
  162. /** Buffer pointers */
  163. unsigned int eventq_read_ptr; /* Falcon only */
  164. unsigned int tx_write_ptr;
  165. unsigned int rx_write_ptr;
  166. /** Port 0/1 on the NIC */
  167. int port;
  168. /** MAC address */
  169. uint8_t mac_addr[ETH_ALEN];
  170. /** GMII link options */
  171. unsigned int link_options;
  172. /** Link status */
  173. int link_up;
  174. /* Nic type fields */
  175. int has_flash : 1;
  176. int has_eeprom : 1;
  177. int is_10g : 1;
  178. int is_dual : 1;
  179. int is_asic : 1;
  180. /** INT_REG_KER for Falcon */
  181. efab_oword_t int_ker __attribute__ (( aligned ( 16 ) ));
  182. /** I2C access */
  183. struct i2c_bit_basher ef1002_i2c;
  184. unsigned long ef1002_i2c_outputs;
  185. struct i2c_device ef1002_eeprom;
  186. /** SPI access */
  187. struct spi_bus spi;
  188. struct spi_device falcon_flash;
  189. struct spi_device falcon_eeprom;
  190. /** Non-volatile options */
  191. struct nvo_block nvo;
  192. };
  193. /**************************************************************************
  194. *
  195. * GMII routines
  196. *
  197. **************************************************************************
  198. */
  199. /* GMII registers */
  200. #define MII_BMSR 0x01 /* Basic mode status register */
  201. #define MII_ADVERTISE 0x04 /* Advertisement control register */
  202. #define MII_LPA 0x05 /* Link partner ability register*/
  203. #define GMII_GTCR 0x09 /* 1000BASE-T control register */
  204. #define GMII_GTSR 0x0a /* 1000BASE-T status register */
  205. #define GMII_PSSR 0x11 /* PHY-specific status register */
  206. /* Basic mode status register. */
  207. #define BMSR_LSTATUS 0x0004 /* Link status */
  208. /* Link partner ability register. */
  209. #define LPA_10HALF 0x0020 /* Can do 10mbps half-duplex */
  210. #define LPA_10FULL 0x0040 /* Can do 10mbps full-duplex */
  211. #define LPA_100HALF 0x0080 /* Can do 100mbps half-duplex */
  212. #define LPA_100FULL 0x0100 /* Can do 100mbps full-duplex */
  213. #define LPA_100BASE4 0x0200 /* Can do 100mbps 4k packets */
  214. #define LPA_PAUSE 0x0400 /* Bit 10 - MAC pause */
  215. /* Pseudo extensions to the link partner ability register */
  216. #define LPA_1000FULL 0x00020000
  217. #define LPA_1000HALF 0x00010000
  218. #define LPA_10000FULL 0x00040000
  219. #define LPA_10000HALF 0x00080000
  220. #define LPA_100 (LPA_100FULL | LPA_100HALF | LPA_100BASE4)
  221. #define LPA_1000 ( LPA_1000FULL | LPA_1000HALF )
  222. #define LPA_10000 ( LPA_10000FULL | LPA_10000HALF )
  223. #define LPA_DUPLEX ( LPA_10FULL | LPA_100FULL | LPA_1000FULL )
  224. /* Mask of bits not associated with speed or duplexity. */
  225. #define LPA_OTHER ~( LPA_10FULL | LPA_10HALF | LPA_100FULL | \
  226. LPA_100HALF | LPA_1000FULL | LPA_1000HALF )
  227. /* PHY-specific status register */
  228. #define PSSR_LSTATUS 0x0400 /* Bit 10 - link status */
  229. /**
  230. * Retrieve GMII autonegotiation advertised abilities
  231. *
  232. */
  233. static unsigned int gmii_autoneg_advertised ( struct efab_nic *efab ) {
  234. unsigned int mii_advertise;
  235. unsigned int gmii_advertise;
  236. /* Extended bits are in bits 8 and 9 of GMII_GTCR */
  237. mii_advertise = efab->op->mdio_read ( efab, MII_ADVERTISE );
  238. gmii_advertise = ( ( efab->op->mdio_read ( efab, GMII_GTCR ) >> 8 )
  239. & 0x03 );
  240. return ( ( gmii_advertise << 16 ) | mii_advertise );
  241. }
  242. /**
  243. * Retrieve GMII autonegotiation link partner abilities
  244. *
  245. */
  246. static unsigned int gmii_autoneg_lpa ( struct efab_nic *efab ) {
  247. unsigned int mii_lpa;
  248. unsigned int gmii_lpa;
  249. /* Extended bits are in bits 10 and 11 of GMII_GTSR */
  250. mii_lpa = efab->op->mdio_read ( efab, MII_LPA );
  251. gmii_lpa = ( efab->op->mdio_read ( efab, GMII_GTSR ) >> 10 ) & 0x03;
  252. return ( ( gmii_lpa << 16 ) | mii_lpa );
  253. }
  254. /**
  255. * Calculate GMII autonegotiated link technology
  256. *
  257. */
  258. static unsigned int gmii_nway_result ( unsigned int negotiated ) {
  259. unsigned int other_bits;
  260. /* Mask out the speed and duplexity bits */
  261. other_bits = negotiated & LPA_OTHER;
  262. if ( negotiated & LPA_1000FULL )
  263. return ( other_bits | LPA_1000FULL );
  264. else if ( negotiated & LPA_1000HALF )
  265. return ( other_bits | LPA_1000HALF );
  266. else if ( negotiated & LPA_100FULL )
  267. return ( other_bits | LPA_100FULL );
  268. else if ( negotiated & LPA_100BASE4 )
  269. return ( other_bits | LPA_100BASE4 );
  270. else if ( negotiated & LPA_100HALF )
  271. return ( other_bits | LPA_100HALF );
  272. else if ( negotiated & LPA_10FULL )
  273. return ( other_bits | LPA_10FULL );
  274. else return ( other_bits | LPA_10HALF );
  275. }
  276. /**
  277. * Check GMII PHY link status
  278. *
  279. */
  280. static int gmii_link_ok ( struct efab_nic *efab ) {
  281. int status;
  282. int phy_status;
  283. /* BMSR is latching - it returns "link down" if the link has
  284. * been down at any point since the last read. To get a
  285. * real-time status, we therefore read the register twice and
  286. * use the result of the second read.
  287. */
  288. efab->op->mdio_read ( efab, MII_BMSR );
  289. status = efab->op->mdio_read ( efab, MII_BMSR );
  290. /* Read the PHY-specific Status Register. This is
  291. * non-latching, so we need do only a single read.
  292. */
  293. phy_status = efab->op->mdio_read ( efab, GMII_PSSR );
  294. return ( ( status & BMSR_LSTATUS ) && ( phy_status & PSSR_LSTATUS ) );
  295. }
  296. /**************************************************************************
  297. *
  298. * Alaska PHY
  299. *
  300. **************************************************************************
  301. */
  302. /**
  303. * Initialise Alaska PHY
  304. *
  305. */
  306. static void alaska_init ( struct efab_nic *efab ) {
  307. unsigned int advertised, lpa;
  308. /* Read link up status */
  309. efab->link_up = gmii_link_ok ( efab );
  310. if ( ! efab->link_up )
  311. return;
  312. /* Determine link options from PHY. */
  313. advertised = gmii_autoneg_advertised ( efab );
  314. lpa = gmii_autoneg_lpa ( efab );
  315. efab->link_options = gmii_nway_result ( advertised & lpa );
  316. /* print out the link speed */
  317. EFAB_LOG ( "%dMbps %s-duplex (%04x,%04x)\n",
  318. ( efab->link_options & LPA_10000 ? 1000 :
  319. ( efab->link_options & LPA_1000 ? 1000 :
  320. ( efab->link_options & LPA_100 ? 100 : 10 ) ) ),
  321. ( efab->link_options & LPA_DUPLEX ? "full" : "half" ),
  322. advertised, lpa );
  323. }
  324. /**************************************************************************
  325. *
  326. * Mentor MAC
  327. *
  328. **************************************************************************
  329. */
  330. /* GMAC configuration register 1 */
  331. #define GM_CFG1_REG_MAC 0x00
  332. #define GM_SW_RST_LBN 31
  333. #define GM_SW_RST_WIDTH 1
  334. #define GM_RX_FC_EN_LBN 5
  335. #define GM_RX_FC_EN_WIDTH 1
  336. #define GM_TX_FC_EN_LBN 4
  337. #define GM_TX_FC_EN_WIDTH 1
  338. #define GM_RX_EN_LBN 2
  339. #define GM_RX_EN_WIDTH 1
  340. #define GM_TX_EN_LBN 0
  341. #define GM_TX_EN_WIDTH 1
  342. /* GMAC configuration register 2 */
  343. #define GM_CFG2_REG_MAC 0x01
  344. #define GM_PAMBL_LEN_LBN 12
  345. #define GM_PAMBL_LEN_WIDTH 4
  346. #define GM_IF_MODE_LBN 8
  347. #define GM_IF_MODE_WIDTH 2
  348. #define GM_PAD_CRC_EN_LBN 2
  349. #define GM_PAD_CRC_EN_WIDTH 1
  350. #define GM_FD_LBN 0
  351. #define GM_FD_WIDTH 1
  352. /* GMAC maximum frame length register */
  353. #define GM_MAX_FLEN_REG_MAC 0x04
  354. #define GM_MAX_FLEN_LBN 0
  355. #define GM_MAX_FLEN_WIDTH 16
  356. /* GMAC MII management configuration register */
  357. #define GM_MII_MGMT_CFG_REG_MAC 0x08
  358. #define GM_MGMT_CLK_SEL_LBN 0
  359. #define GM_MGMT_CLK_SEL_WIDTH 3
  360. /* GMAC MII management command register */
  361. #define GM_MII_MGMT_CMD_REG_MAC 0x09
  362. #define GM_MGMT_SCAN_CYC_LBN 1
  363. #define GM_MGMT_SCAN_CYC_WIDTH 1
  364. #define GM_MGMT_RD_CYC_LBN 0
  365. #define GM_MGMT_RD_CYC_WIDTH 1
  366. /* GMAC MII management address register */
  367. #define GM_MII_MGMT_ADR_REG_MAC 0x0a
  368. #define GM_MGMT_PHY_ADDR_LBN 8
  369. #define GM_MGMT_PHY_ADDR_WIDTH 5
  370. #define GM_MGMT_REG_ADDR_LBN 0
  371. #define GM_MGMT_REG_ADDR_WIDTH 5
  372. /* GMAC MII management control register */
  373. #define GM_MII_MGMT_CTL_REG_MAC 0x0b
  374. #define GM_MGMT_CTL_LBN 0
  375. #define GM_MGMT_CTL_WIDTH 16
  376. /* GMAC MII management status register */
  377. #define GM_MII_MGMT_STAT_REG_MAC 0x0c
  378. #define GM_MGMT_STAT_LBN 0
  379. #define GM_MGMT_STAT_WIDTH 16
  380. /* GMAC MII management indicators register */
  381. #define GM_MII_MGMT_IND_REG_MAC 0x0d
  382. #define GM_MGMT_BUSY_LBN 0
  383. #define GM_MGMT_BUSY_WIDTH 1
  384. /* GMAC station address register 1 */
  385. #define GM_ADR1_REG_MAC 0x10
  386. #define GM_HWADDR_5_LBN 24
  387. #define GM_HWADDR_5_WIDTH 8
  388. #define GM_HWADDR_4_LBN 16
  389. #define GM_HWADDR_4_WIDTH 8
  390. #define GM_HWADDR_3_LBN 8
  391. #define GM_HWADDR_3_WIDTH 8
  392. #define GM_HWADDR_2_LBN 0
  393. #define GM_HWADDR_2_WIDTH 8
  394. /* GMAC station address register 2 */
  395. #define GM_ADR2_REG_MAC 0x11
  396. #define GM_HWADDR_1_LBN 24
  397. #define GM_HWADDR_1_WIDTH 8
  398. #define GM_HWADDR_0_LBN 16
  399. #define GM_HWADDR_0_WIDTH 8
  400. /* GMAC FIFO configuration register 0 */
  401. #define GMF_CFG0_REG_MAC 0x12
  402. #define GMF_FTFENREQ_LBN 12
  403. #define GMF_FTFENREQ_WIDTH 1
  404. #define GMF_STFENREQ_LBN 11
  405. #define GMF_STFENREQ_WIDTH 1
  406. #define GMF_FRFENREQ_LBN 10
  407. #define GMF_FRFENREQ_WIDTH 1
  408. #define GMF_SRFENREQ_LBN 9
  409. #define GMF_SRFENREQ_WIDTH 1
  410. #define GMF_WTMENREQ_LBN 8
  411. #define GMF_WTMENREQ_WIDTH 1
  412. /* GMAC FIFO configuration register 1 */
  413. #define GMF_CFG1_REG_MAC 0x13
  414. #define GMF_CFGFRTH_LBN 16
  415. #define GMF_CFGFRTH_WIDTH 5
  416. #define GMF_CFGXOFFRTX_LBN 0
  417. #define GMF_CFGXOFFRTX_WIDTH 16
  418. /* GMAC FIFO configuration register 2 */
  419. #define GMF_CFG2_REG_MAC 0x14
  420. #define GMF_CFGHWM_LBN 16
  421. #define GMF_CFGHWM_WIDTH 6
  422. #define GMF_CFGLWM_LBN 0
  423. #define GMF_CFGLWM_WIDTH 6
  424. /* GMAC FIFO configuration register 3 */
  425. #define GMF_CFG3_REG_MAC 0x15
  426. #define GMF_CFGHWMFT_LBN 16
  427. #define GMF_CFGHWMFT_WIDTH 6
  428. #define GMF_CFGFTTH_LBN 0
  429. #define GMF_CFGFTTH_WIDTH 6
  430. /* GMAC FIFO configuration register 4 */
  431. #define GMF_CFG4_REG_MAC 0x16
  432. #define GMF_HSTFLTRFRM_PAUSE_LBN 12
  433. #define GMF_HSTFLTRFRM_PAUSE_WIDTH 12
  434. /* GMAC FIFO configuration register 5 */
  435. #define GMF_CFG5_REG_MAC 0x17
  436. #define GMF_CFGHDPLX_LBN 22
  437. #define GMF_CFGHDPLX_WIDTH 1
  438. #define GMF_CFGBYTMODE_LBN 19
  439. #define GMF_CFGBYTMODE_WIDTH 1
  440. #define GMF_HSTDRPLT64_LBN 18
  441. #define GMF_HSTDRPLT64_WIDTH 1
  442. #define GMF_HSTFLTRFRMDC_PAUSE_LBN 12
  443. #define GMF_HSTFLTRFRMDC_PAUSE_WIDTH 1
  444. struct efab_mentormac_parameters {
  445. int gmf_cfgfrth;
  446. int gmf_cfgftth;
  447. int gmf_cfghwmft;
  448. int gmf_cfghwm;
  449. int gmf_cfglwm;
  450. };
  451. /**
  452. * Reset Mentor MAC
  453. *
  454. */
  455. static void mentormac_reset ( struct efab_nic *efab ) {
  456. efab_dword_t reg;
  457. int save_port;
  458. /* Take into reset */
  459. EFAB_POPULATE_DWORD_1 ( reg, GM_SW_RST, 1 );
  460. efab->mac_op->mac_writel ( efab, &reg, GM_CFG1_REG_MAC );
  461. udelay ( 1000 );
  462. /* Take out of reset */
  463. EFAB_POPULATE_DWORD_1 ( reg, GM_SW_RST, 0 );
  464. efab->mac_op->mac_writel ( efab, &reg, GM_CFG1_REG_MAC );
  465. udelay ( 1000 );
  466. /* Mentor MAC connects both PHYs to MAC 0 */
  467. save_port = efab->port;
  468. efab->port = 0;
  469. /* Configure GMII interface so PHY is accessible. Note that
  470. * GMII interface is connected only to port 0, and that on
  471. * Falcon this is a no-op.
  472. */
  473. EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_CLK_SEL, 0x4 );
  474. efab->mac_op->mac_writel ( efab, &reg, GM_MII_MGMT_CFG_REG_MAC );
  475. udelay ( 10 );
  476. efab->port = save_port;
  477. }
  478. /**
  479. * Initialise Mentor MAC
  480. *
  481. */
  482. static void mentormac_init ( struct efab_nic *efab,
  483. struct efab_mentormac_parameters *params ) {
  484. int pause, if_mode, full_duplex, bytemode, half_duplex;
  485. efab_dword_t reg;
  486. /* Configuration register 1 */
  487. pause = ( efab->link_options & LPA_PAUSE ) ? 1 : 0;
  488. if ( ! ( efab->link_options & LPA_DUPLEX ) ) {
  489. /* Half-duplex operation requires TX flow control */
  490. pause = 1;
  491. }
  492. EFAB_POPULATE_DWORD_4 ( reg,
  493. GM_TX_EN, 1,
  494. GM_TX_FC_EN, pause,
  495. GM_RX_EN, 1,
  496. GM_RX_FC_EN, 1 );
  497. efab->mac_op->mac_writel ( efab, &reg, GM_CFG1_REG_MAC );
  498. udelay ( 10 );
  499. /* Configuration register 2 */
  500. if_mode = ( efab->link_options & LPA_1000 ) ? 2 : 1;
  501. full_duplex = ( efab->link_options & LPA_DUPLEX ) ? 1 : 0;
  502. EFAB_POPULATE_DWORD_4 ( reg,
  503. GM_IF_MODE, if_mode,
  504. GM_PAD_CRC_EN, 1,
  505. GM_FD, full_duplex,
  506. GM_PAMBL_LEN, 0x7 /* ? */ );
  507. efab->mac_op->mac_writel ( efab, &reg, GM_CFG2_REG_MAC );
  508. udelay ( 10 );
  509. /* Max frame len register */
  510. EFAB_POPULATE_DWORD_1 ( reg, GM_MAX_FLEN, ETH_FRAME_LEN + 4 /* FCS */);
  511. efab->mac_op->mac_writel ( efab, &reg, GM_MAX_FLEN_REG_MAC );
  512. udelay ( 10 );
  513. /* FIFO configuration register 0 */
  514. EFAB_POPULATE_DWORD_5 ( reg,
  515. GMF_FTFENREQ, 1,
  516. GMF_STFENREQ, 1,
  517. GMF_FRFENREQ, 1,
  518. GMF_SRFENREQ, 1,
  519. GMF_WTMENREQ, 1 );
  520. efab->mac_op->mac_writel ( efab, &reg, GMF_CFG0_REG_MAC );
  521. udelay ( 10 );
  522. /* FIFO configuration register 1 */
  523. EFAB_POPULATE_DWORD_2 ( reg,
  524. GMF_CFGFRTH, params->gmf_cfgfrth,
  525. GMF_CFGXOFFRTX, 0xffff );
  526. efab->mac_op->mac_writel ( efab, &reg, GMF_CFG1_REG_MAC );
  527. udelay ( 10 );
  528. /* FIFO configuration register 2 */
  529. EFAB_POPULATE_DWORD_2 ( reg,
  530. GMF_CFGHWM, params->gmf_cfghwm,
  531. GMF_CFGLWM, params->gmf_cfglwm );
  532. efab->mac_op->mac_writel ( efab, &reg, GMF_CFG2_REG_MAC );
  533. udelay ( 10 );
  534. /* FIFO configuration register 3 */
  535. EFAB_POPULATE_DWORD_2 ( reg,
  536. GMF_CFGHWMFT, params->gmf_cfghwmft,
  537. GMF_CFGFTTH, params->gmf_cfgftth );
  538. efab->mac_op->mac_writel ( efab, &reg, GMF_CFG3_REG_MAC );
  539. udelay ( 10 );
  540. /* FIFO configuration register 4 */
  541. EFAB_POPULATE_DWORD_1 ( reg, GMF_HSTFLTRFRM_PAUSE, 1 );
  542. efab->mac_op->mac_writel ( efab, &reg, GMF_CFG4_REG_MAC );
  543. udelay ( 10 );
  544. /* FIFO configuration register 5 */
  545. bytemode = ( efab->link_options & LPA_1000 ) ? 1 : 0;
  546. half_duplex = ( efab->link_options & LPA_DUPLEX ) ? 0 : 1;
  547. efab->mac_op->mac_readl ( efab, &reg, GMF_CFG5_REG_MAC );
  548. EFAB_SET_DWORD_FIELD ( reg, GMF_CFGBYTMODE, bytemode );
  549. EFAB_SET_DWORD_FIELD ( reg, GMF_CFGHDPLX, half_duplex );
  550. EFAB_SET_DWORD_FIELD ( reg, GMF_HSTDRPLT64, half_duplex );
  551. EFAB_SET_DWORD_FIELD ( reg, GMF_HSTFLTRFRMDC_PAUSE, 0 );
  552. efab->mac_op->mac_writel ( efab, &reg, GMF_CFG5_REG_MAC );
  553. udelay ( 10 );
  554. /* MAC address */
  555. EFAB_POPULATE_DWORD_4 ( reg,
  556. GM_HWADDR_5, efab->mac_addr[5],
  557. GM_HWADDR_4, efab->mac_addr[4],
  558. GM_HWADDR_3, efab->mac_addr[3],
  559. GM_HWADDR_2, efab->mac_addr[2] );
  560. efab->mac_op->mac_writel ( efab, &reg, GM_ADR1_REG_MAC );
  561. udelay ( 10 );
  562. EFAB_POPULATE_DWORD_2 ( reg,
  563. GM_HWADDR_1, efab->mac_addr[1],
  564. GM_HWADDR_0, efab->mac_addr[0] );
  565. efab->mac_op->mac_writel ( efab, &reg, GM_ADR2_REG_MAC );
  566. udelay ( 10 );
  567. }
  568. /**
  569. * Wait for GMII access to complete
  570. *
  571. */
  572. static int mentormac_gmii_wait ( struct efab_nic *efab ) {
  573. int count;
  574. efab_dword_t indicator;
  575. for ( count = 0 ; count < 1000 ; count++ ) {
  576. udelay ( 10 );
  577. efab->mac_op->mac_readl ( efab, &indicator,
  578. GM_MII_MGMT_IND_REG_MAC );
  579. if ( EFAB_DWORD_FIELD ( indicator, GM_MGMT_BUSY ) == 0 )
  580. return 1;
  581. }
  582. EFAB_ERR ( "Timed out waiting for GMII\n" );
  583. return 0;
  584. }
  585. /**
  586. * Write a GMII register
  587. *
  588. */
  589. static void mentormac_mdio_write ( struct efab_nic *efab, int phy_id,
  590. int location, int value ) {
  591. efab_dword_t reg;
  592. int save_port;
  593. EFAB_TRACE ( "Writing GMII %d register %02x with %04x\n", phy_id,
  594. location, value );
  595. /* Mentor MAC connects both PHYs to MAC 0 */
  596. save_port = efab->port;
  597. efab->port = 0;
  598. /* Check MII not currently being accessed */
  599. if ( ! mentormac_gmii_wait ( efab ) )
  600. goto out;
  601. /* Write the address register */
  602. EFAB_POPULATE_DWORD_2 ( reg,
  603. GM_MGMT_PHY_ADDR, phy_id,
  604. GM_MGMT_REG_ADDR, location );
  605. efab->mac_op->mac_writel ( efab, &reg, GM_MII_MGMT_ADR_REG_MAC );
  606. udelay ( 10 );
  607. /* Write data */
  608. EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_CTL, value );
  609. efab->mac_op->mac_writel ( efab, &reg, GM_MII_MGMT_CTL_REG_MAC );
  610. /* Wait for data to be written */
  611. mentormac_gmii_wait ( efab );
  612. out:
  613. /* Restore efab->port */
  614. efab->port = save_port;
  615. }
  616. /**
  617. * Read a GMII register
  618. *
  619. */
  620. static int mentormac_mdio_read ( struct efab_nic *efab, int phy_id,
  621. int location ) {
  622. efab_dword_t reg;
  623. int value = 0xffff;
  624. int save_port;
  625. /* Mentor MAC connects both PHYs to MAC 0 */
  626. save_port = efab->port;
  627. efab->port = 0;
  628. /* Check MII not currently being accessed */
  629. if ( ! mentormac_gmii_wait ( efab ) )
  630. goto out;
  631. /* Write the address register */
  632. EFAB_POPULATE_DWORD_2 ( reg,
  633. GM_MGMT_PHY_ADDR, phy_id,
  634. GM_MGMT_REG_ADDR, location );
  635. efab->mac_op->mac_writel ( efab, &reg, GM_MII_MGMT_ADR_REG_MAC );
  636. udelay ( 10 );
  637. /* Request data to be read */
  638. EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_RD_CYC, 1 );
  639. efab->mac_op->mac_writel ( efab, &reg, GM_MII_MGMT_CMD_REG_MAC );
  640. /* Wait for data to be become available */
  641. if ( mentormac_gmii_wait ( efab ) ) {
  642. /* Read data */
  643. efab->mac_op->mac_readl ( efab, &reg, GM_MII_MGMT_STAT_REG_MAC );
  644. value = EFAB_DWORD_FIELD ( reg, GM_MGMT_STAT );
  645. EFAB_TRACE ( "Read from GMII %d register %02x, got %04x\n",
  646. phy_id, location, value );
  647. }
  648. /* Signal completion */
  649. EFAB_ZERO_DWORD ( reg );
  650. efab->mac_op->mac_writel ( efab, &reg, GM_MII_MGMT_CMD_REG_MAC );
  651. udelay ( 10 );
  652. out:
  653. /* Restore efab->port */
  654. efab->port = save_port;
  655. return value;
  656. }
  657. /**************************************************************************
  658. *
  659. * EF1002 routines
  660. *
  661. **************************************************************************
  662. */
  663. /** Control and General Status */
  664. #define EF1_CTR_GEN_STATUS0_REG 0x0
  665. #define EF1_MASTER_EVENTS_LBN 12
  666. #define EF1_MASTER_EVENTS_WIDTH 1
  667. #define EF1_TX_ENGINE_EN_LBN 19
  668. #define EF1_TX_ENGINE_EN_WIDTH 1
  669. #define EF1_RX_ENGINE_EN_LBN 18
  670. #define EF1_RX_ENGINE_EN_WIDTH 1
  671. #define EF1_TURBO2_LBN 17
  672. #define EF1_TURBO2_WIDTH 1
  673. #define EF1_TURBO1_LBN 16
  674. #define EF1_TURBO1_WIDTH 1
  675. #define EF1_TURBO3_LBN 14
  676. #define EF1_TURBO3_WIDTH 1
  677. #define EF1_LB_RESET_LBN 3
  678. #define EF1_LB_RESET_WIDTH 1
  679. #define EF1_MAC_RESET_LBN 2
  680. #define EF1_MAC_RESET_WIDTH 1
  681. #define EF1_CAM_ENABLE_LBN 1
  682. #define EF1_CAM_ENABLE_WIDTH 1
  683. /** IRQ sources */
  684. #define EF1_IRQ_SRC_REG 0x0008
  685. /** IRQ mask */
  686. #define EF1_IRQ_MASK_REG 0x000c
  687. #define EF1_IRQ_PHY1_LBN 11
  688. #define EF1_IRQ_PHY1_WIDTH 1
  689. #define EF1_IRQ_PHY0_LBN 10
  690. #define EF1_IRQ_PHY0_WIDTH 1
  691. #define EF1_IRQ_SERR_LBN 7
  692. #define EF1_IRQ_SERR_WIDTH 1
  693. #define EF1_IRQ_EVQ_LBN 3
  694. #define EF1_IRQ_EVQ_WIDTH 1
  695. /** Event generation */
  696. #define EF1_EVT3_REG 0x38
  697. /** EEPROMaccess */
  698. #define EF1_EEPROM_REG 0x40
  699. #define EF1_EEPROM_SDA_LBN 31
  700. #define EF1_EEPROM_SDA_WIDTH 1
  701. #define EF1_EEPROM_SCL_LBN 30
  702. #define EF1_EEPROM_SCL_WIDTH 1
  703. #define EF1_JTAG_DISCONNECT_LBN 17
  704. #define EF1_JTAG_DISCONNECT_WIDTH 1
  705. #define EF1_EEPROM_LBN 0
  706. #define EF1_EEPROM_WIDTH 32
  707. /** Control register 2 */
  708. #define EF1_CTL2_REG 0x4c
  709. #define EF1_PLL_TRAP_LBN 31
  710. #define EF1_PLL_TRAP_WIDTH 1
  711. #define EF1_MEM_MAP_4MB_LBN 11
  712. #define EF1_MEM_MAP_4MB_WIDTH 1
  713. #define EF1_EV_INTR_CLR_WRITE_LBN 6
  714. #define EF1_EV_INTR_CLR_WRITE_WIDTH 1
  715. #define EF1_BURST_MERGE_LBN 5
  716. #define EF1_BURST_MERGE_WIDTH 1
  717. #define EF1_CLEAR_NULL_PAD_LBN 4
  718. #define EF1_CLEAR_NULL_PAD_WIDTH 1
  719. #define EF1_SW_RESET_LBN 2
  720. #define EF1_SW_RESET_WIDTH 1
  721. #define EF1_INTR_AFTER_EVENT_LBN 1
  722. #define EF1_INTR_AFTER_EVENT_WIDTH 1
  723. /** Event FIFO */
  724. #define EF1_EVENT_FIFO_REG 0x50
  725. /** Event FIFO count */
  726. #define EF1_EVENT_FIFO_COUNT_REG 0x5c
  727. #define EF1_EV_COUNT_LBN 0
  728. #define EF1_EV_COUNT_WIDTH 16
  729. /** TX DMA control and status */
  730. #define EF1_DMA_TX_CSR_REG 0x80
  731. #define EF1_DMA_TX_CSR_CHAIN_EN_LBN 8
  732. #define EF1_DMA_TX_CSR_CHAIN_EN_WIDTH 1
  733. #define EF1_DMA_TX_CSR_ENABLE_LBN 4
  734. #define EF1_DMA_TX_CSR_ENABLE_WIDTH 1
  735. #define EF1_DMA_TX_CSR_INT_EN_LBN 0
  736. #define EF1_DMA_TX_CSR_INT_EN_WIDTH 1
  737. /** RX DMA control and status */
  738. #define EF1_DMA_RX_CSR_REG 0xa0
  739. #define EF1_DMA_RX_ABOVE_1GB_EN_LBN 6
  740. #define EF1_DMA_RX_ABOVE_1GB_EN_WIDTH 1
  741. #define EF1_DMA_RX_BELOW_1MB_EN_LBN 5
  742. #define EF1_DMA_RX_BELOW_1MB_EN_WIDTH 1
  743. #define EF1_DMA_RX_CSR_ENABLE_LBN 0
  744. #define EF1_DMA_RX_CSR_ENABLE_WIDTH 1
  745. /** Level 5 watermark register (in MAC space) */
  746. #define EF1_GMF_L5WM_REG_MAC 0x20
  747. #define EF1_L5WM_LBN 0
  748. #define EF1_L5WM_WIDTH 32
  749. /** MAC clock */
  750. #define EF1_GM_MAC_CLK_REG 0x112000
  751. #define EF1_GM_PORT0_MAC_CLK_LBN 0
  752. #define EF1_GM_PORT0_MAC_CLK_WIDTH 1
  753. #define EF1_GM_PORT1_MAC_CLK_LBN 1
  754. #define EF1_GM_PORT1_MAC_CLK_WIDTH 1
  755. /** TX descriptor FIFO */
  756. #define EF1_TX_DESC_FIFO 0x141000
  757. #define EF1_TX_KER_EVQ_LBN 80
  758. #define EF1_TX_KER_EVQ_WIDTH 12
  759. #define EF1_TX_KER_IDX_LBN 64
  760. #define EF1_TX_KER_IDX_WIDTH 16
  761. #define EF1_TX_KER_MODE_LBN 63
  762. #define EF1_TX_KER_MODE_WIDTH 1
  763. #define EF1_TX_KER_PORT_LBN 60
  764. #define EF1_TX_KER_PORT_WIDTH 1
  765. #define EF1_TX_KER_CONT_LBN 56
  766. #define EF1_TX_KER_CONT_WIDTH 1
  767. #define EF1_TX_KER_BYTE_CNT_LBN 32
  768. #define EF1_TX_KER_BYTE_CNT_WIDTH 24
  769. #define EF1_TX_KER_BUF_ADR_LBN 0
  770. #define EF1_TX_KER_BUF_ADR_WIDTH 32
  771. /** TX descriptor FIFO flush */
  772. #define EF1_TX_DESC_FIFO_FLUSH 0x141ffc
  773. /** RX descriptor FIFO */
  774. #define EF1_RX_DESC_FIFO 0x145000
  775. #define EF1_RX_KER_EVQ_LBN 48
  776. #define EF1_RX_KER_EVQ_WIDTH 12
  777. #define EF1_RX_KER_IDX_LBN 32
  778. #define EF1_RX_KER_IDX_WIDTH 16
  779. #define EF1_RX_KER_BUF_ADR_LBN 0
  780. #define EF1_RX_KER_BUF_ADR_WIDTH 32
  781. /** RX descriptor FIFO flush */
  782. #define EF1_RX_DESC_FIFO_FLUSH 0x145ffc
  783. /** CAM */
  784. #define EF1_CAM_BASE 0x1c0000
  785. #define EF1_CAM_WTF_DOES_THIS_DO_LBN 0
  786. #define EF1_CAM_WTF_DOES_THIS_DO_WIDTH 32
  787. /** Event queue pointers */
  788. #define EF1_EVQ_PTR_BASE 0x260000
  789. #define EF1_EVQ_SIZE_LBN 29
  790. #define EF1_EVQ_SIZE_WIDTH 2
  791. #define EF1_EVQ_SIZE_4K 3
  792. #define EF1_EVQ_SIZE_2K 2
  793. #define EF1_EVQ_SIZE_1K 1
  794. #define EF1_EVQ_SIZE_512 0
  795. #define EF1_EVQ_BUF_BASE_ID_LBN 0
  796. #define EF1_EVQ_BUF_BASE_ID_WIDTH 29
  797. /* MAC registers */
  798. #define EF1002_MAC_REGBANK 0x110000
  799. #define EF1002_MAC_REGBANK_SIZE 0x1000
  800. #define EF1002_MAC_REG_SIZE 0x08
  801. /** Offset of a MAC register within EF1002 */
  802. #define EF1002_MAC_REG( efab, mac_reg ) \
  803. ( EF1002_MAC_REGBANK + \
  804. ( (efab)->port * EF1002_MAC_REGBANK_SIZE ) + \
  805. ( (mac_reg) * EF1002_MAC_REG_SIZE ) )
  806. /* Event queue entries */
  807. #define EF1_EV_CODE_LBN 20
  808. #define EF1_EV_CODE_WIDTH 8
  809. #define EF1_RX_EV_DECODE 0x01
  810. #define EF1_TX_EV_DECODE 0x02
  811. #define EF1_TIMER_EV_DECODE 0x0b
  812. #define EF1_DRV_GEN_EV_DECODE 0x0f
  813. /* Receive events */
  814. #define EF1_RX_EV_LEN_LBN 48
  815. #define EF1_RX_EV_LEN_WIDTH 16
  816. #define EF1_RX_EV_PORT_LBN 17
  817. #define EF1_RX_EV_PORT_WIDTH 3
  818. #define EF1_RX_EV_OK_LBN 16
  819. #define EF1_RX_EV_OK_WIDTH 1
  820. #define EF1_RX_EV_IDX_LBN 0
  821. #define EF1_RX_EV_IDX_WIDTH 16
  822. /* Transmit events */
  823. #define EF1_TX_EV_PORT_LBN 17
  824. #define EF1_TX_EV_PORT_WIDTH 3
  825. #define EF1_TX_EV_OK_LBN 16
  826. #define EF1_TX_EV_OK_WIDTH 1
  827. #define EF1_TX_EV_IDX_LBN 0
  828. #define EF1_TX_EV_IDX_WIDTH 16
  829. /* forward decleration */
  830. static struct efab_mac_operations ef1002_mac_operations;
  831. /* I2C ID of the EEPROM */
  832. #define EF1_EEPROM_I2C_ID 0x50
  833. /* Offset of MAC address within EEPROM */
  834. #define EF1_EEPROM_HWADDR_OFFSET 0x0
  835. /**
  836. * Write dword to EF1002 register
  837. *
  838. */
  839. static inline void ef1002_writel ( struct efab_nic *efab, efab_dword_t *value,
  840. unsigned int reg ) {
  841. EFAB_REGDUMP ( "Writing register %x with " EFAB_DWORD_FMT "\n",
  842. reg, EFAB_DWORD_VAL ( *value ) );
  843. writel ( value->u32[0], efab->membase + reg );
  844. }
  845. /**
  846. * Read dword from an EF1002 register
  847. *
  848. */
  849. static inline void ef1002_readl ( struct efab_nic *efab, efab_dword_t *value,
  850. unsigned int reg ) {
  851. value->u32[0] = readl ( efab->membase + reg );
  852. EFAB_REGDUMP ( "Read from register %x, got " EFAB_DWORD_FMT "\n",
  853. reg, EFAB_DWORD_VAL ( *value ) );
  854. }
  855. /**
  856. * Read dword from an EF1002 register, silently
  857. *
  858. */
  859. static inline void ef1002_readl_silent ( struct efab_nic *efab,
  860. efab_dword_t *value,
  861. unsigned int reg ) {
  862. value->u32[0] = readl ( efab->membase + reg );
  863. }
  864. /**
  865. * Get memory base
  866. *
  867. */
  868. static void ef1002_get_membase ( struct efab_nic *efab ) {
  869. unsigned long membase_phys;
  870. membase_phys = pci_bar_start ( efab->pci, PCI_BASE_ADDRESS_0 );
  871. efab->membase = ioremap ( membase_phys, 0x800000 );
  872. }
  873. /** PCI registers to backup/restore over a device reset */
  874. static const unsigned int efab_pci_reg_addr[] = {
  875. PCI_COMMAND, 0x0c /* PCI_CACHE_LINE_SIZE */,
  876. PCI_BASE_ADDRESS_0, PCI_BASE_ADDRESS_1, PCI_BASE_ADDRESS_2,
  877. PCI_BASE_ADDRESS_3, PCI_ROM_ADDRESS, PCI_INTERRUPT_LINE,
  878. };
  879. /** Number of registers in efab_pci_reg_addr */
  880. #define EFAB_NUM_PCI_REG \
  881. ( sizeof ( efab_pci_reg_addr ) / sizeof ( efab_pci_reg_addr[0] ) )
  882. /** PCI configuration space backup */
  883. struct efab_pci_reg {
  884. uint32_t reg[EFAB_NUM_PCI_REG];
  885. };
  886. /*
  887. * I2C interface and EEPROM
  888. *
  889. */
  890. static unsigned long ef1002_i2c_bits[] = {
  891. [I2C_BIT_SCL] = ( 1 << 30 ),
  892. [I2C_BIT_SDA] = ( 1 << 31 ),
  893. };
  894. static void ef1002_i2c_write_bit ( struct bit_basher *basher,
  895. unsigned int bit_id, unsigned long data ) {
  896. struct efab_nic *efab = container_of ( basher, struct efab_nic,
  897. ef1002_i2c.basher );
  898. unsigned long mask;
  899. efab_dword_t reg;
  900. mask = ef1002_i2c_bits[bit_id];
  901. efab->ef1002_i2c_outputs &= ~mask;
  902. efab->ef1002_i2c_outputs |= ( data & mask );
  903. EFAB_POPULATE_DWORD_1 ( reg, EF1_EEPROM, efab->ef1002_i2c_outputs );
  904. ef1002_writel ( efab, &reg, EF1_EEPROM_REG );
  905. }
  906. static int ef1002_i2c_read_bit ( struct bit_basher *basher,
  907. unsigned int bit_id ) {
  908. struct efab_nic *efab = container_of ( basher, struct efab_nic,
  909. ef1002_i2c.basher );
  910. unsigned long mask;
  911. efab_dword_t reg;
  912. mask = ef1002_i2c_bits[bit_id];
  913. ef1002_readl ( efab, &reg, EF1_EEPROM_REG );
  914. return ( EFAB_DWORD_FIELD ( reg, EF1_EEPROM ) & mask );
  915. }
  916. static struct bit_basher_operations ef1002_basher_ops = {
  917. .read = ef1002_i2c_read_bit,
  918. .write = ef1002_i2c_write_bit,
  919. };
  920. static void ef1002_init_eeprom ( struct efab_nic *efab ) {
  921. efab->ef1002_i2c.basher.op = &ef1002_basher_ops;
  922. init_i2c_bit_basher ( &efab->ef1002_i2c );
  923. efab->ef1002_eeprom.address = EF1_EEPROM_I2C_ID;
  924. }
  925. /**
  926. * Reset device
  927. *
  928. */
  929. static int ef1002_reset ( struct efab_nic *efab ) {
  930. struct efab_pci_reg pci_reg;
  931. struct pci_device *pci_dev = efab->pci;
  932. efab_dword_t reg;
  933. unsigned int i;
  934. uint32_t tmp;
  935. /* Back up PCI configuration registers */
  936. for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
  937. pci_read_config_dword ( pci_dev, efab_pci_reg_addr[i],
  938. &pci_reg.reg[i] );
  939. }
  940. /* Reset the whole device. */
  941. EFAB_POPULATE_DWORD_1 ( reg, EF1_SW_RESET, 1 );
  942. ef1002_writel ( efab, &reg, EF1_CTL2_REG );
  943. mdelay ( 200 );
  944. /* Restore PCI configuration space */
  945. for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
  946. pci_write_config_dword ( pci_dev, efab_pci_reg_addr[i],
  947. pci_reg.reg[i] );
  948. }
  949. /* Verify PCI configuration space */
  950. for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
  951. pci_read_config_dword ( pci_dev, efab_pci_reg_addr[i], &tmp );
  952. if ( tmp != pci_reg.reg[i] ) {
  953. EFAB_LOG ( "PCI restore failed on register %02x "
  954. "(is %08lx, should be %08lx); reboot\n",
  955. i, tmp, pci_reg.reg[i] );
  956. return 0;
  957. }
  958. }
  959. /* Verify device reset complete */
  960. ef1002_readl ( efab, &reg, EF1_CTR_GEN_STATUS0_REG );
  961. if ( EFAB_DWORD_IS_ALL_ONES ( reg ) ) {
  962. EFAB_ERR ( "Reset failed\n" );
  963. return 0;
  964. }
  965. return 1;
  966. }
  967. /**
  968. * Initialise NIC
  969. *
  970. */
  971. static int ef1002_init_nic ( struct efab_nic *efab ) {
  972. efab_dword_t reg;
  973. /* patch in the MAC operations */
  974. efab->mac_op = &ef1002_mac_operations;
  975. /* No idea what CAM is, but the 'datasheet' says that we have
  976. * to write these values in at start of day
  977. */
  978. EFAB_POPULATE_DWORD_1 ( reg, EF1_CAM_WTF_DOES_THIS_DO, 0x6 );
  979. ef1002_writel ( efab, &reg, EF1_CAM_BASE + 0x20018 );
  980. udelay ( 1000 );
  981. EFAB_POPULATE_DWORD_1 ( reg, EF1_CAM_WTF_DOES_THIS_DO, 0x01000000 );
  982. ef1002_writel ( efab, &reg, EF1_CAM_BASE + 0x00018 );
  983. udelay ( 1000 );
  984. /* General control register 0 */
  985. ef1002_readl ( efab, &reg, EF1_CTR_GEN_STATUS0_REG );
  986. EFAB_SET_DWORD_FIELD ( reg, EF1_MASTER_EVENTS, 0 );
  987. EFAB_SET_DWORD_FIELD ( reg, EF1_TX_ENGINE_EN, 0 );
  988. EFAB_SET_DWORD_FIELD ( reg, EF1_RX_ENGINE_EN, 0 );
  989. EFAB_SET_DWORD_FIELD ( reg, EF1_TURBO2, 1 );
  990. EFAB_SET_DWORD_FIELD ( reg, EF1_TURBO1, 1 );
  991. EFAB_SET_DWORD_FIELD ( reg, EF1_TURBO3, 1 );
  992. EFAB_SET_DWORD_FIELD ( reg, EF1_CAM_ENABLE, 1 );
  993. ef1002_writel ( efab, &reg, EF1_CTR_GEN_STATUS0_REG );
  994. udelay ( 1000 );
  995. /* General control register 2 */
  996. ef1002_readl ( efab, &reg, EF1_CTL2_REG );
  997. EFAB_SET_DWORD_FIELD ( reg, EF1_PLL_TRAP, 1 );
  998. EFAB_SET_DWORD_FIELD ( reg, EF1_MEM_MAP_4MB, 0 );
  999. EFAB_SET_DWORD_FIELD ( reg, EF1_EV_INTR_CLR_WRITE, 0 );
  1000. EFAB_SET_DWORD_FIELD ( reg, EF1_BURST_MERGE, 0 );
  1001. EFAB_SET_DWORD_FIELD ( reg, EF1_CLEAR_NULL_PAD, 1 );
  1002. EFAB_SET_DWORD_FIELD ( reg, EF1_INTR_AFTER_EVENT, 1 );
  1003. ef1002_writel ( efab, &reg, EF1_CTL2_REG );
  1004. udelay ( 1000 );
  1005. /* Enable RX DMA */
  1006. ef1002_readl ( efab, &reg, EF1_DMA_RX_CSR_REG );
  1007. EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_CSR_ENABLE, 1 );
  1008. EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_BELOW_1MB_EN, 1 );
  1009. EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_ABOVE_1GB_EN, 1 );
  1010. ef1002_writel ( efab, &reg, EF1_DMA_RX_CSR_REG );
  1011. udelay ( 1000 );
  1012. /* Enable TX DMA */
  1013. ef1002_readl ( efab, &reg, EF1_DMA_TX_CSR_REG );
  1014. EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_CHAIN_EN, 1 );
  1015. EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_ENABLE, 0 /* ?? */ );
  1016. EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_INT_EN, 0 /* ?? */ );
  1017. ef1002_writel ( efab, &reg, EF1_DMA_TX_CSR_REG );
  1018. udelay ( 1000 );
  1019. /* Disconnect the JTAG chain. Read-modify-write is impossible
  1020. * on the I2C control bits, since reading gives the state of
  1021. * the line inputs rather than the last written state.
  1022. */
  1023. ef1002_readl ( efab, &reg, EF1_EEPROM_REG );
  1024. EFAB_SET_DWORD_FIELD ( reg, EF1_EEPROM_SDA, 1 );
  1025. EFAB_SET_DWORD_FIELD ( reg, EF1_EEPROM_SCL, 1 );
  1026. EFAB_SET_DWORD_FIELD ( reg, EF1_JTAG_DISCONNECT, 1 );
  1027. ef1002_writel ( efab, &reg, EF1_EEPROM_REG );
  1028. udelay ( 10 );
  1029. /* Flush descriptor queues */
  1030. EFAB_ZERO_DWORD ( reg );
  1031. ef1002_writel ( efab, &reg, EF1_RX_DESC_FIFO_FLUSH );
  1032. ef1002_writel ( efab, &reg, EF1_TX_DESC_FIFO_FLUSH );
  1033. wmb();
  1034. udelay ( 10000 );
  1035. /* Reset MAC */
  1036. efab->mac_op->reset ( efab );
  1037. /* Attach I2C bus */
  1038. ef1002_init_eeprom ( efab );
  1039. return 1;
  1040. }
  1041. /**
  1042. * Read MAC address from EEPROM
  1043. *
  1044. */
  1045. static int ef1002_read_eeprom ( struct efab_nic *efab ) {
  1046. struct i2c_interface *i2c = &efab->ef1002_i2c.i2c;
  1047. struct i2c_device *i2cdev = &efab->ef1002_eeprom;
  1048. if ( i2c->read ( i2c, i2cdev, EF1_EEPROM_HWADDR_OFFSET,
  1049. efab->mac_addr, sizeof ( efab->mac_addr ) ) != 0 )
  1050. return 0;
  1051. efab->mac_addr[ETH_ALEN-1] += efab->port;
  1052. return 1;
  1053. }
  1054. /** RX descriptor */
  1055. typedef efab_qword_t ef1002_rx_desc_t;
  1056. /**
  1057. * Build RX descriptor
  1058. *
  1059. */
  1060. static void ef1002_build_rx_desc ( struct efab_nic *efab,
  1061. struct efab_rx_buf *rx_buf ) {
  1062. ef1002_rx_desc_t rxd;
  1063. EFAB_POPULATE_QWORD_3 ( rxd,
  1064. EF1_RX_KER_EVQ, 0,
  1065. EF1_RX_KER_IDX, rx_buf->id,
  1066. EF1_RX_KER_BUF_ADR,
  1067. virt_to_bus ( rx_buf->addr ) );
  1068. ef1002_writel ( efab, &rxd.dword[0], EF1_RX_DESC_FIFO + 0 );
  1069. wmb();
  1070. ef1002_writel ( efab, &rxd.dword[1], EF1_RX_DESC_FIFO + 4 );
  1071. udelay ( 10 );
  1072. }
  1073. /**
  1074. * Update RX descriptor write pointer
  1075. *
  1076. */
  1077. static void ef1002_notify_rx_desc ( struct efab_nic *efab __unused ) {
  1078. /* Nothing to do */
  1079. }
  1080. /** TX descriptor */
  1081. typedef efab_oword_t ef1002_tx_desc_t;
  1082. /**
  1083. * Build TX descriptor
  1084. *
  1085. */
  1086. static void ef1002_build_tx_desc ( struct efab_nic *efab,
  1087. struct efab_tx_buf *tx_buf ) {
  1088. ef1002_tx_desc_t txd;
  1089. EFAB_POPULATE_OWORD_7 ( txd,
  1090. EF1_TX_KER_EVQ, 0,
  1091. EF1_TX_KER_IDX, tx_buf->id,
  1092. EF1_TX_KER_MODE, 0 /* IP mode */,
  1093. EF1_TX_KER_PORT, efab->port,
  1094. EF1_TX_KER_CONT, 0,
  1095. EF1_TX_KER_BYTE_CNT, tx_buf->len,
  1096. EF1_TX_KER_BUF_ADR,
  1097. virt_to_bus ( tx_buf->addr ) );
  1098. ef1002_writel ( efab, &txd.dword[0], EF1_TX_DESC_FIFO + 0 );
  1099. ef1002_writel ( efab, &txd.dword[1], EF1_TX_DESC_FIFO + 4 );
  1100. wmb();
  1101. ef1002_writel ( efab, &txd.dword[2], EF1_TX_DESC_FIFO + 8 );
  1102. udelay ( 10 );
  1103. }
  1104. /**
  1105. * Update TX descriptor write pointer
  1106. *
  1107. */
  1108. static void ef1002_notify_tx_desc ( struct efab_nic *efab __unused ) {
  1109. /* Nothing to do */
  1110. }
  1111. /** An event */
  1112. typedef efab_qword_t ef1002_event_t;
  1113. /**
  1114. * Retrieve event from event queue
  1115. *
  1116. */
  1117. static int ef1002_fetch_event ( struct efab_nic *efab,
  1118. struct efab_event *event ) {
  1119. efab_dword_t reg;
  1120. int ev_code;
  1121. int words;
  1122. /* Check event FIFO depth */
  1123. ef1002_readl_silent ( efab, &reg, EF1_EVENT_FIFO_COUNT_REG );
  1124. words = EFAB_DWORD_FIELD ( reg, EF1_EV_COUNT );
  1125. if ( ! words )
  1126. return 0;
  1127. /* Read event data */
  1128. ef1002_readl ( efab, &reg, EF1_EVENT_FIFO_REG );
  1129. DBG ( "Event is " EFAB_DWORD_FMT "\n", EFAB_DWORD_VAL ( reg ) );
  1130. /* Decode event */
  1131. ev_code = EFAB_DWORD_FIELD ( reg, EF1_EV_CODE );
  1132. event->drop = 0;
  1133. switch ( ev_code ) {
  1134. case EF1_TX_EV_DECODE:
  1135. event->type = EFAB_EV_TX;
  1136. break;
  1137. case EF1_RX_EV_DECODE:
  1138. event->type = EFAB_EV_RX;
  1139. event->rx_id = EFAB_DWORD_FIELD ( reg, EF1_RX_EV_IDX );
  1140. /* RX len not available via event FIFO */
  1141. event->rx_len = ETH_FRAME_LEN;
  1142. break;
  1143. case EF1_TIMER_EV_DECODE:
  1144. /* These are safe to ignore. We seem to get some at
  1145. * start of day, presumably due to the timers starting
  1146. * up with random contents.
  1147. */
  1148. event->type = EFAB_EV_NONE;
  1149. break;
  1150. default:
  1151. EFAB_ERR ( "Unknown event type %d\n", ev_code );
  1152. event->type = EFAB_EV_NONE;
  1153. }
  1154. /* Clear any pending interrupts */
  1155. ef1002_readl ( efab, &reg, EF1_IRQ_SRC_REG );
  1156. return 1;
  1157. }
  1158. /**
  1159. * Enable/disable interrupts
  1160. *
  1161. */
  1162. static void ef1002_mask_irq ( struct efab_nic *efab, int enabled ) {
  1163. efab_dword_t irq_mask;
  1164. EFAB_POPULATE_DWORD_2 ( irq_mask,
  1165. EF1_IRQ_SERR, enabled,
  1166. EF1_IRQ_EVQ, enabled );
  1167. ef1002_writel ( efab, &irq_mask, EF1_IRQ_MASK_REG );
  1168. }
  1169. /**
  1170. * Generate interrupt
  1171. *
  1172. */
  1173. static void ef1002_generate_irq ( struct efab_nic *efab ) {
  1174. ef1002_event_t test_event;
  1175. EFAB_POPULATE_QWORD_1 ( test_event,
  1176. EF1_EV_CODE, EF1_DRV_GEN_EV_DECODE );
  1177. ef1002_writel ( efab, &test_event.dword[0], EF1_EVT3_REG );
  1178. }
  1179. /**
  1180. * Write dword to an EF1002 MAC register
  1181. *
  1182. */
  1183. static void ef1002_mac_writel ( struct efab_nic *efab,
  1184. efab_dword_t *value, unsigned int mac_reg ) {
  1185. ef1002_writel ( efab, value, EF1002_MAC_REG ( efab, mac_reg ) );
  1186. }
  1187. /**
  1188. * Read dword from an EF1002 MAC register
  1189. *
  1190. */
  1191. static void ef1002_mac_readl ( struct efab_nic *efab,
  1192. efab_dword_t *value, unsigned int mac_reg ) {
  1193. ef1002_readl ( efab, value, EF1002_MAC_REG ( efab, mac_reg ) );
  1194. }
  1195. /**
  1196. * Initialise MAC
  1197. *
  1198. */
  1199. static int ef1002_init_mac ( struct efab_nic *efab ) {
  1200. static struct efab_mentormac_parameters ef1002_mentormac_params = {
  1201. .gmf_cfgfrth = 0x13,
  1202. .gmf_cfgftth = 0x10,
  1203. .gmf_cfghwmft = 0x555,
  1204. .gmf_cfghwm = 0x2a,
  1205. .gmf_cfglwm = 0x15,
  1206. };
  1207. efab_dword_t reg;
  1208. unsigned int mac_clk;
  1209. /* Initialise PHY */
  1210. alaska_init ( efab );
  1211. /* Initialise MAC */
  1212. mentormac_init ( efab, &ef1002_mentormac_params );
  1213. /* Write Level 5 watermark register */
  1214. EFAB_POPULATE_DWORD_1 ( reg, EF1_L5WM, 0x10040000 );
  1215. efab->mac_op->mac_writel ( efab, &reg, EF1_GMF_L5WM_REG_MAC );
  1216. udelay ( 10 );
  1217. /* Set MAC clock speed */
  1218. ef1002_readl ( efab, &reg, EF1_GM_MAC_CLK_REG );
  1219. mac_clk = ( efab->link_options & LPA_1000 ) ? 0 : 1;
  1220. if ( efab->port == 0 ) {
  1221. EFAB_SET_DWORD_FIELD ( reg, EF1_GM_PORT0_MAC_CLK, mac_clk );
  1222. } else {
  1223. EFAB_SET_DWORD_FIELD ( reg, EF1_GM_PORT1_MAC_CLK, mac_clk );
  1224. }
  1225. ef1002_writel ( efab, &reg, EF1_GM_MAC_CLK_REG );
  1226. udelay ( 10 );
  1227. return 1;
  1228. }
  1229. /**
  1230. * Reset MAC
  1231. *
  1232. */
  1233. static int ef1002_reset_mac ( struct efab_nic *efab ) {
  1234. mentormac_reset ( efab );
  1235. return 1;
  1236. }
  1237. /** MDIO write */
  1238. static void ef1002_mdio_write ( struct efab_nic *efab, int location,
  1239. int value ) {
  1240. mentormac_mdio_write ( efab, efab->port + 2, location, value );
  1241. }
  1242. /** MDIO read */
  1243. static int ef1002_mdio_read ( struct efab_nic *efab, int location ) {
  1244. return mentormac_mdio_read ( efab, efab->port + 2, location );
  1245. }
  1246. static struct efab_operations ef1002_operations = {
  1247. .get_membase = ef1002_get_membase,
  1248. .reset = ef1002_reset,
  1249. .init_nic = ef1002_init_nic,
  1250. .read_eeprom = ef1002_read_eeprom,
  1251. .build_rx_desc = ef1002_build_rx_desc,
  1252. .notify_rx_desc = ef1002_notify_rx_desc,
  1253. .build_tx_desc = ef1002_build_tx_desc,
  1254. .notify_tx_desc = ef1002_notify_tx_desc,
  1255. .fetch_event = ef1002_fetch_event,
  1256. .mask_irq = ef1002_mask_irq,
  1257. .generate_irq = ef1002_generate_irq,
  1258. .mdio_write = ef1002_mdio_write,
  1259. .mdio_read = ef1002_mdio_read,
  1260. };
  1261. static struct efab_mac_operations ef1002_mac_operations = {
  1262. .mac_writel = ef1002_mac_writel,
  1263. .mac_readl = ef1002_mac_readl,
  1264. .init = ef1002_init_mac,
  1265. .reset = ef1002_reset_mac,
  1266. };
  1267. /**************************************************************************
  1268. *
  1269. * Falcon routines
  1270. *
  1271. **************************************************************************
  1272. */
  1273. /* I/O BAR address register */
  1274. #define FCN_IOM_IND_ADR_REG 0x0
  1275. /* I/O BAR data register */
  1276. #define FCN_IOM_IND_DAT_REG 0x4
  1277. /* Interrupt enable register */
  1278. #define FCN_INT_EN_REG_KER 0x0010
  1279. #define FCN_MEM_PERR_INT_EN_KER_LBN 5
  1280. #define FCN_MEM_PERR_INT_EN_KER_WIDTH 1
  1281. #define FCN_KER_INT_CHAR_LBN 4
  1282. #define FCN_KER_INT_CHAR_WIDTH 1
  1283. #define FCN_KER_INT_KER_LBN 3
  1284. #define FCN_KER_INT_KER_WIDTH 1
  1285. #define FCN_ILL_ADR_ERR_INT_EN_KER_LBN 2
  1286. #define FCN_ILL_ADR_ERR_INT_EN_KER_WIDTH 1
  1287. #define FCN_SRM_PERR_INT_EN_KER_LBN 1
  1288. #define FCN_SRM_PERR_INT_EN_KER_WIDTH 1
  1289. #define FCN_DRV_INT_EN_KER_LBN 0
  1290. #define FCN_DRV_INT_EN_KER_WIDTH 1
  1291. /* Interrupt status register */
  1292. #define FCN_INT_ADR_REG_KER 0x0030
  1293. #define FCN_INT_ADR_KER_LBN 0
  1294. #define FCN_INT_ADR_KER_WIDTH EFAB_DMA_TYPE_WIDTH ( 64 )
  1295. /* Interrupt acknowledge register */
  1296. #define FCN_INT_ACK_KER_REG 0x0050
  1297. /* SPI host command register */
  1298. #define FCN_EE_SPI_HCMD_REG_KER 0x0100
  1299. #define FCN_EE_SPI_HCMD_CMD_EN_LBN 31
  1300. #define FCN_EE_SPI_HCMD_CMD_EN_WIDTH 1
  1301. #define FCN_EE_WR_TIMER_ACTIVE_LBN 28
  1302. #define FCN_EE_WR_TIMER_ACTIVE_WIDTH 1
  1303. #define FCN_EE_SPI_HCMD_SF_SEL_LBN 24
  1304. #define FCN_EE_SPI_HCMD_SF_SEL_WIDTH 1
  1305. #define FCN_EE_SPI_EEPROM 0
  1306. #define FCN_EE_SPI_FLASH 1
  1307. #define FCN_EE_SPI_HCMD_DABCNT_LBN 16
  1308. #define FCN_EE_SPI_HCMD_DABCNT_WIDTH 5
  1309. #define FCN_EE_SPI_HCMD_READ_LBN 15
  1310. #define FCN_EE_SPI_HCMD_READ_WIDTH 1
  1311. #define FCN_EE_SPI_READ 1
  1312. #define FCN_EE_SPI_WRITE 0
  1313. #define FCN_EE_SPI_HCMD_DUBCNT_LBN 12
  1314. #define FCN_EE_SPI_HCMD_DUBCNT_WIDTH 2
  1315. #define FCN_EE_SPI_HCMD_ADBCNT_LBN 8
  1316. #define FCN_EE_SPI_HCMD_ADBCNT_WIDTH 2
  1317. #define FCN_EE_SPI_HCMD_ENC_LBN 0
  1318. #define FCN_EE_SPI_HCMD_ENC_WIDTH 8
  1319. /* SPI host address register */
  1320. #define FCN_EE_SPI_HADR_REG_KER 0x0110
  1321. #define FCN_EE_SPI_HADR_DUBYTE_LBN 24
  1322. #define FCN_EE_SPI_HADR_DUBYTE_WIDTH 8
  1323. #define FCN_EE_SPI_HADR_ADR_LBN 0
  1324. #define FCN_EE_SPI_HADR_ADR_WIDTH 24
  1325. /* SPI host data register */
  1326. #define FCN_EE_SPI_HDATA_REG_KER 0x0120
  1327. #define FCN_EE_SPI_HDATA3_LBN 96
  1328. #define FCN_EE_SPI_HDATA3_WIDTH 32
  1329. #define FCN_EE_SPI_HDATA2_LBN 64
  1330. #define FCN_EE_SPI_HDATA2_WIDTH 32
  1331. #define FCN_EE_SPI_HDATA1_LBN 32
  1332. #define FCN_EE_SPI_HDATA1_WIDTH 32
  1333. #define FCN_EE_SPI_HDATA0_LBN 0
  1334. #define FCN_EE_SPI_HDATA0_WIDTH 32
  1335. /* VPI configuration register */
  1336. #define FCN_VPD_CONFIG_REG_KER 0x0140
  1337. #define FCN_VPD_9BIT_LBN 1
  1338. #define FCN_VPD_9BIT_WIDTH 1
  1339. /* NIC status register */
  1340. #define FCN_NIC_STAT_REG 0x0200
  1341. #define ONCHIP_SRAM_LBN 16
  1342. #define ONCHIP_SRAM_WIDTH 1
  1343. #define SF_PRST_LBN 9
  1344. #define SF_PRST_WIDTH 1
  1345. #define EE_PRST_LBN 8
  1346. #define EE_PRST_WIDTH 1
  1347. #define EE_STRAP_LBN 7
  1348. #define EE_STRAP_WIDTH 1
  1349. #define PCI_PCIX_MODE_LBN 4
  1350. #define PCI_PCIX_MODE_WIDTH 3
  1351. #define PCI_PCIX_MODE_PCI33_DECODE 0
  1352. #define PCI_PCIX_MODE_PCI66_DECODE 1
  1353. #define PCI_PCIX_MODE_PCIX66_DECODE 5
  1354. #define PCI_PCIX_MODE_PCIX100_DECODE 6
  1355. #define PCI_PCIX_MODE_PCIX133_DECODE 7
  1356. #define STRAP_ISCSI_EN_LBN 3
  1357. #define STRAP_ISCSI_EN_WIDTH 1
  1358. #define STRAP_PINS_LBN 0
  1359. #define STRAP_PINS_WIDTH 3
  1360. /* These bit definitions are extrapolated from the list of numerical
  1361. * values for STRAP_PINS. If you want a laugh, read the datasheet's
  1362. * definition for when bits 2:0 are set to 7.
  1363. */
  1364. #define STRAP_10G_LBN 2
  1365. #define STRAP_10G_WIDTH 1
  1366. #define STRAP_DUAL_PORT_LBN 1
  1367. #define STRAP_DUAL_PORT_WIDTH 1
  1368. #define STRAP_PCIE_LBN 0
  1369. #define STRAP_PCIE_WIDTH 1
  1370. /* GPIO control register */
  1371. #define FCN_GPIO_CTL_REG_KER 0x0210
  1372. #define FCN_FLASH_PRESENT_LBN 7
  1373. #define FCN_FLASH_PRESENT_WIDTH 1
  1374. #define FCN_EEPROM_PRESENT_LBN 6
  1375. #define FCN_EEPROM_PRESENT_WIDTH 1
  1376. /* Global control register */
  1377. #define FCN_GLB_CTL_REG_KER 0x0220
  1378. #define EXT_PHY_RST_CTL_LBN 63
  1379. #define EXT_PHY_RST_CTL_WIDTH 1
  1380. #define PCIE_SD_RST_CTL_LBN 61
  1381. #define PCIE_SD_RST_CTL_WIDTH 1
  1382. #define PCIX_RST_CTL_LBN 60
  1383. #define PCIX_RST_CTL_WIDTH 1
  1384. #define PCIE_STCK_RST_CTL_LBN 59
  1385. #define PCIE_STCK_RST_CTL_WIDTH 1
  1386. #define PCIE_NSTCK_RST_CTL_LBN 58
  1387. #define PCIE_NSTCK_RST_CTL_WIDTH 1
  1388. #define PCIE_CORE_RST_CTL_LBN 57
  1389. #define PCIE_CORE_RST_CTL_WIDTH 1
  1390. #define EE_RST_CTL_LBN 49
  1391. #define EE_RST_CTL_WIDTH 1
  1392. #define CS_RST_CTL_LBN 48
  1393. #define CS_RST_CTL_WIDTH 1
  1394. #define RST_EXT_PHY_LBN 31
  1395. #define RST_EXT_PHY_WIDTH 1
  1396. #define INT_RST_DUR_LBN 4
  1397. #define INT_RST_DUR_WIDTH 3
  1398. #define EXT_PHY_RST_DUR_LBN 1
  1399. #define EXT_PHY_RST_DUR_WIDTH 3
  1400. #define SWRST_LBN 0
  1401. #define SWRST_WIDTH 1
  1402. #define INCLUDE_IN_RESET 0
  1403. #define EXCLUDE_FROM_RESET 1
  1404. /* FPGA build version */
  1405. #define ALTERA_BUILD_REG_KER 0x0300
  1406. #define VER_MAJOR_LBN 24
  1407. #define VER_MAJOR_WIDTH 8
  1408. #define VER_MINOR_LBN 16
  1409. #define VER_MINOR_WIDTH 8
  1410. #define VER_BUILD_LBN 0
  1411. #define VER_BUILD_WIDTH 16
  1412. #define VER_ALL_LBN 0
  1413. #define VER_ALL_WIDTH 32
  1414. /* Timer table for kernel access */
  1415. #define FCN_TIMER_CMD_REG_KER 0x420
  1416. #define FCN_TIMER_MODE_LBN 12
  1417. #define FCN_TIMER_MODE_WIDTH 2
  1418. #define FCN_TIMER_MODE_DIS 0
  1419. #define FCN_TIMER_MODE_INT_HLDOFF 1
  1420. #define FCN_TIMER_VAL_LBN 0
  1421. #define FCN_TIMER_VAL_WIDTH 12
  1422. /* Receive configuration register */
  1423. #define FCN_RX_CFG_REG_KER 0x800
  1424. #define FCN_RX_XOFF_EN_LBN 0
  1425. #define FCN_RX_XOFF_EN_WIDTH 1
  1426. /* SRAM receive descriptor cache configuration register */
  1427. #define FCN_SRM_RX_DC_CFG_REG_KER 0x610
  1428. #define FCN_SRM_RX_DC_BASE_ADR_LBN 0
  1429. #define FCN_SRM_RX_DC_BASE_ADR_WIDTH 21
  1430. /* SRAM transmit descriptor cache configuration register */
  1431. #define FCN_SRM_TX_DC_CFG_REG_KER 0x620
  1432. #define FCN_SRM_TX_DC_BASE_ADR_LBN 0
  1433. #define FCN_SRM_TX_DC_BASE_ADR_WIDTH 21
  1434. /* Receive filter control register */
  1435. #define FCN_RX_FILTER_CTL_REG_KER 0x810
  1436. #define FCN_NUM_KER_LBN 24
  1437. #define FCN_NUM_KER_WIDTH 2
  1438. /* Receive descriptor update register */
  1439. #define FCN_RX_DESC_UPD_REG_KER 0x0830
  1440. #define FCN_RX_DESC_WPTR_LBN 96
  1441. #define FCN_RX_DESC_WPTR_WIDTH 12
  1442. #define FCN_RX_DESC_UPD_REG_KER_DWORD ( FCN_RX_DESC_UPD_REG_KER + 12 )
  1443. #define FCN_RX_DESC_WPTR_DWORD_LBN 0
  1444. #define FCN_RX_DESC_WPTR_DWORD_WIDTH 12
  1445. /* Receive descriptor cache configuration register */
  1446. #define FCN_RX_DC_CFG_REG_KER 0x840
  1447. #define FCN_RX_DC_SIZE_LBN 0
  1448. #define FCN_RX_DC_SIZE_WIDTH 2
  1449. /* Transmit descriptor update register */
  1450. #define FCN_TX_DESC_UPD_REG_KER 0x0a10
  1451. #define FCN_TX_DESC_WPTR_LBN 96
  1452. #define FCN_TX_DESC_WPTR_WIDTH 12
  1453. #define FCN_TX_DESC_UPD_REG_KER_DWORD ( FCN_TX_DESC_UPD_REG_KER + 12 )
  1454. #define FCN_TX_DESC_WPTR_DWORD_LBN 0
  1455. #define FCN_TX_DESC_WPTR_DWORD_WIDTH 12
  1456. /* Transmit descriptor cache configuration register */
  1457. #define FCN_TX_DC_CFG_REG_KER 0xa20
  1458. #define FCN_TX_DC_SIZE_LBN 0
  1459. #define FCN_TX_DC_SIZE_WIDTH 2
  1460. /* PHY management transmit data register */
  1461. #define FCN_MD_TXD_REG_KER 0xc00
  1462. #define FCN_MD_TXD_LBN 0
  1463. #define FCN_MD_TXD_WIDTH 16
  1464. /* PHY management receive data register */
  1465. #define FCN_MD_RXD_REG_KER 0xc10
  1466. #define FCN_MD_RXD_LBN 0
  1467. #define FCN_MD_RXD_WIDTH 16
  1468. /* PHY management configuration & status register */
  1469. #define FCN_MD_CS_REG_KER 0xc20
  1470. #define FCN_MD_GC_LBN 4
  1471. #define FCN_MD_GC_WIDTH 1
  1472. #define FCN_MD_RIC_LBN 2
  1473. #define FCN_MD_RIC_WIDTH 1
  1474. #define FCN_MD_WRC_LBN 0
  1475. #define FCN_MD_WRC_WIDTH 1
  1476. /* PHY management PHY address register */
  1477. #define FCN_MD_PHY_ADR_REG_KER 0xc30
  1478. #define FCN_MD_PHY_ADR_LBN 0
  1479. #define FCN_MD_PHY_ADR_WIDTH 16
  1480. /* PHY management ID register */
  1481. #define FCN_MD_ID_REG_KER 0xc40
  1482. #define FCN_MD_PRT_ADR_LBN 11
  1483. #define FCN_MD_PRT_ADR_WIDTH 5
  1484. #define FCN_MD_DEV_ADR_LBN 6
  1485. #define FCN_MD_DEV_ADR_WIDTH 5
  1486. /* PHY management status & mask register */
  1487. #define FCN_MD_STAT_REG_KER 0xc50
  1488. #define FCN_MD_BSY_LBN 0
  1489. #define FCN_MD_BSY_WIDTH 1
  1490. /* Port 0 and 1 MAC control registers */
  1491. #define FCN_MAC0_CTRL_REG_KER 0xc80
  1492. #define FCN_MAC1_CTRL_REG_KER 0xc90
  1493. #define FCN_MAC_XOFF_VAL_LBN 16
  1494. #define FCN_MAC_XOFF_VAL_WIDTH 16
  1495. #define FCN_MAC_BCAD_ACPT_LBN 4
  1496. #define FCN_MAC_BCAD_ACPT_WIDTH 1
  1497. #define FCN_MAC_UC_PROM_LBN 3
  1498. #define FCN_MAC_UC_PROM_WIDTH 1
  1499. #define FCN_MAC_LINK_STATUS_LBN 2
  1500. #define FCN_MAC_LINK_STATUS_WIDTH 1
  1501. #define FCN_MAC_SPEED_LBN 0
  1502. #define FCN_MAC_SPEED_WIDTH 2
  1503. /* GMAC registers */
  1504. #define FALCON_GMAC_REGBANK 0xe00
  1505. #define FALCON_GMAC_REGBANK_SIZE 0x200
  1506. #define FALCON_GMAC_REG_SIZE 0x10
  1507. /* XGMAC registers */
  1508. #define FALCON_XMAC_REGBANK 0x1200
  1509. #define FALCON_XMAC_REGBANK_SIZE 0x200
  1510. #define FALCON_XMAC_REG_SIZE 0x10
  1511. /* XGMAC address register low */
  1512. #define FCN_XM_ADR_LO_REG_MAC 0x00
  1513. #define FCN_XM_ADR_3_LBN 24
  1514. #define FCN_XM_ADR_3_WIDTH 8
  1515. #define FCN_XM_ADR_2_LBN 16
  1516. #define FCN_XM_ADR_2_WIDTH 8
  1517. #define FCN_XM_ADR_1_LBN 8
  1518. #define FCN_XM_ADR_1_WIDTH 8
  1519. #define FCN_XM_ADR_0_LBN 0
  1520. #define FCN_XM_ADR_0_WIDTH 8
  1521. /* XGMAC address register high */
  1522. #define FCN_XM_ADR_HI_REG_MAC 0x01
  1523. #define FCN_XM_ADR_5_LBN 8
  1524. #define FCN_XM_ADR_5_WIDTH 8
  1525. #define FCN_XM_ADR_4_LBN 0
  1526. #define FCN_XM_ADR_4_WIDTH 8
  1527. /* XGMAC global configuration - port 0*/
  1528. #define FCN_XM_GLB_CFG_REG_MAC 0x02
  1529. #define FCN_XM_RX_STAT_EN_LBN 11
  1530. #define FCN_XM_RX_STAT_EN_WIDTH 1
  1531. #define FCN_XM_TX_STAT_EN_LBN 10
  1532. #define FCN_XM_TX_STAT_EN_WIDTH 1
  1533. #define FCN_XM_RX_JUMBO_MODE_LBN 6
  1534. #define FCN_XM_RX_JUMBO_MODE_WIDTH 1
  1535. #define FCN_XM_CORE_RST_LBN 0
  1536. #define FCN_XM_CORE_RST_WIDTH 1
  1537. /* XGMAC transmit configuration - port 0 */
  1538. #define FCN_XM_TX_CFG_REG_MAC 0x03
  1539. #define FCN_XM_IPG_LBN 16
  1540. #define FCN_XM_IPG_WIDTH 4
  1541. #define FCN_XM_FCNTL_LBN 10
  1542. #define FCN_XM_FCNTL_WIDTH 1
  1543. #define FCN_XM_TXCRC_LBN 8
  1544. #define FCN_XM_TXCRC_WIDTH 1
  1545. #define FCN_XM_AUTO_PAD_LBN 5
  1546. #define FCN_XM_AUTO_PAD_WIDTH 1
  1547. #define FCN_XM_TX_PRMBL_LBN 2
  1548. #define FCN_XM_TX_PRMBL_WIDTH 1
  1549. #define FCN_XM_TXEN_LBN 1
  1550. #define FCN_XM_TXEN_WIDTH 1
  1551. /* XGMAC receive configuration - port 0 */
  1552. #define FCN_XM_RX_CFG_REG_MAC 0x04
  1553. #define FCN_XM_PASS_CRC_ERR_LBN 25
  1554. #define FCN_XM_PASS_CRC_ERR_WIDTH 1
  1555. #define FCN_XM_AUTO_DEPAD_LBN 8
  1556. #define FCN_XM_AUTO_DEPAD_WIDTH 1
  1557. #define FCN_XM_RXEN_LBN 1
  1558. #define FCN_XM_RXEN_WIDTH 1
  1559. /* XGMAC transmit parameter register */
  1560. #define FCN_XM_TX_PARAM_REG_MAC 0x0d
  1561. #define FCN_XM_TX_JUMBO_MODE_LBN 31
  1562. #define FCN_XM_TX_JUMBO_MODE_WIDTH 1
  1563. #define FCN_XM_MAX_TX_FRM_SIZE_LBN 16
  1564. #define FCN_XM_MAX_TX_FRM_SIZE_WIDTH 14
  1565. /* XGMAC receive parameter register */
  1566. #define FCN_XM_RX_PARAM_REG_MAC 0x0e
  1567. #define FCN_XM_MAX_RX_FRM_SIZE_LBN 0
  1568. #define FCN_XM_MAX_RX_FRM_SIZE_WIDTH 14
  1569. /* XAUI XGXS core status register */
  1570. #define FCN_XX_ALIGN_DONE_LBN 20
  1571. #define FCN_XX_ALIGN_DONE_WIDTH 1
  1572. #define FCN_XX_CORE_STAT_REG_MAC 0x16
  1573. #define FCN_XX_SYNC_STAT_LBN 16
  1574. #define FCN_XX_SYNC_STAT_WIDTH 4
  1575. #define FCN_XX_SYNC_STAT_DECODE_SYNCED 0xf
  1576. #define FCN_XX_COMMA_DET_LBN 12
  1577. #define FCN_XX_COMMA_DET_WIDTH 4
  1578. #define FCN_XX_COMMA_DET_RESET 0xf
  1579. /* XGXS/XAUI powerdown/reset register */
  1580. #define FCN_XX_PWR_RST_REG_MAC 0x10
  1581. #define FCN_XX_RSTXGXSRX_EN_LBN 2
  1582. #define FCN_XX_RSTXGXSRX_EN_WIDTH 1
  1583. #define FCN_XX_RSTXGXSTX_EN_LBN 1
  1584. #define FCN_XX_RSTXGXSTX_EN_WIDTH 1
  1585. #define FCN_XX_RST_XX_EN_LBN 0
  1586. #define FCN_XX_RST_XX_EN_WIDTH 1
  1587. /* Receive descriptor pointer table */
  1588. #define FCN_RX_DESC_PTR_TBL_KER 0x11800
  1589. #define FCN_RX_DESCQ_BUF_BASE_ID_LBN 36
  1590. #define FCN_RX_DESCQ_BUF_BASE_ID_WIDTH 20
  1591. #define FCN_RX_DESCQ_EVQ_ID_LBN 24
  1592. #define FCN_RX_DESCQ_EVQ_ID_WIDTH 12
  1593. #define FCN_RX_DESCQ_OWNER_ID_LBN 10
  1594. #define FCN_RX_DESCQ_OWNER_ID_WIDTH 14
  1595. #define FCN_RX_DESCQ_SIZE_LBN 3
  1596. #define FCN_RX_DESCQ_SIZE_WIDTH 2
  1597. #define FCN_RX_DESCQ_SIZE_4K 3
  1598. #define FCN_RX_DESCQ_SIZE_2K 2
  1599. #define FCN_RX_DESCQ_SIZE_1K 1
  1600. #define FCN_RX_DESCQ_SIZE_512 0
  1601. #define FCN_RX_DESCQ_TYPE_LBN 2
  1602. #define FCN_RX_DESCQ_TYPE_WIDTH 1
  1603. #define FCN_RX_DESCQ_JUMBO_LBN 1
  1604. #define FCN_RX_DESCQ_JUMBO_WIDTH 1
  1605. #define FCN_RX_DESCQ_EN_LBN 0
  1606. #define FCN_RX_DESCQ_EN_WIDTH 1
  1607. /* Transmit descriptor pointer table */
  1608. #define FCN_TX_DESC_PTR_TBL_KER 0x11900
  1609. #define FCN_TX_DESCQ_EN_LBN 88
  1610. #define FCN_TX_DESCQ_EN_WIDTH 1
  1611. #define FCN_TX_DESCQ_BUF_BASE_ID_LBN 36
  1612. #define FCN_TX_DESCQ_BUF_BASE_ID_WIDTH 20
  1613. #define FCN_TX_DESCQ_EVQ_ID_LBN 24
  1614. #define FCN_TX_DESCQ_EVQ_ID_WIDTH 12
  1615. #define FCN_TX_DESCQ_OWNER_ID_LBN 10
  1616. #define FCN_TX_DESCQ_OWNER_ID_WIDTH 14
  1617. #define FCN_TX_DESCQ_SIZE_LBN 3
  1618. #define FCN_TX_DESCQ_SIZE_WIDTH 2
  1619. #define FCN_TX_DESCQ_SIZE_4K 3
  1620. #define FCN_TX_DESCQ_SIZE_2K 2
  1621. #define FCN_TX_DESCQ_SIZE_1K 1
  1622. #define FCN_TX_DESCQ_SIZE_512 0
  1623. #define FCN_TX_DESCQ_TYPE_LBN 1
  1624. #define FCN_TX_DESCQ_TYPE_WIDTH 2
  1625. #define FCN_TX_DESCQ_FLUSH_LBN 0
  1626. #define FCN_TX_DESCQ_FLUSH_WIDTH 1
  1627. /* Event queue pointer */
  1628. #define FCN_EVQ_PTR_TBL_KER 0x11a00
  1629. #define FCN_EVQ_EN_LBN 23
  1630. #define FCN_EVQ_EN_WIDTH 1
  1631. #define FCN_EVQ_SIZE_LBN 20
  1632. #define FCN_EVQ_SIZE_WIDTH 3
  1633. #define FCN_EVQ_SIZE_32K 6
  1634. #define FCN_EVQ_SIZE_16K 5
  1635. #define FCN_EVQ_SIZE_8K 4
  1636. #define FCN_EVQ_SIZE_4K 3
  1637. #define FCN_EVQ_SIZE_2K 2
  1638. #define FCN_EVQ_SIZE_1K 1
  1639. #define FCN_EVQ_SIZE_512 0
  1640. #define FCN_EVQ_BUF_BASE_ID_LBN 0
  1641. #define FCN_EVQ_BUF_BASE_ID_WIDTH 20
  1642. /* Event queue read pointer */
  1643. #define FCN_EVQ_RPTR_REG_KER 0x11b00
  1644. #define FCN_EVQ_RPTR_LBN 0
  1645. #define FCN_EVQ_RPTR_WIDTH 14
  1646. #define FCN_EVQ_RPTR_REG_KER_DWORD ( FCN_EVQ_RPTR_REG_KER + 0 )
  1647. #define FCN_EVQ_RPTR_DWORD_LBN 0
  1648. #define FCN_EVQ_RPTR_DWORD_WIDTH 14
  1649. /* Special buffer descriptors */
  1650. #define FCN_BUF_FULL_TBL_KER 0x18000
  1651. #define FCN_IP_DAT_BUF_SIZE_LBN 50
  1652. #define FCN_IP_DAT_BUF_SIZE_WIDTH 1
  1653. #define FCN_IP_DAT_BUF_SIZE_8K 1
  1654. #define FCN_IP_DAT_BUF_SIZE_4K 0
  1655. #define FCN_BUF_ADR_FBUF_LBN 14
  1656. #define FCN_BUF_ADR_FBUF_WIDTH 34
  1657. #define FCN_BUF_OWNER_ID_FBUF_LBN 0
  1658. #define FCN_BUF_OWNER_ID_FBUF_WIDTH 14
  1659. /** Offset of a GMAC register within Falcon */
  1660. #define FALCON_GMAC_REG( efab, mac_reg ) \
  1661. ( FALCON_GMAC_REGBANK + \
  1662. ( (efab)->port * FALCON_GMAC_REGBANK_SIZE ) + \
  1663. ( (mac_reg) * FALCON_GMAC_REG_SIZE ) )
  1664. /** Offset of an XMAC register within Falcon */
  1665. #define FALCON_XMAC_REG( efab_port, mac_reg ) \
  1666. ( FALCON_XMAC_REGBANK + \
  1667. ( (efab_port)->port * FALCON_XMAC_REGBANK_SIZE ) + \
  1668. ( (mac_reg) * FALCON_XMAC_REG_SIZE ) )
  1669. #define FCN_MAC_DATA_LBN 0
  1670. #define FCN_MAC_DATA_WIDTH 32
  1671. /* Transmit descriptor */
  1672. #define FCN_TX_KER_PORT_LBN 63
  1673. #define FCN_TX_KER_PORT_WIDTH 1
  1674. #define FCN_TX_KER_BYTE_CNT_LBN 48
  1675. #define FCN_TX_KER_BYTE_CNT_WIDTH 14
  1676. #define FCN_TX_KER_BUF_ADR_LBN 0
  1677. #define FCN_TX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
  1678. /* Receive descriptor */
  1679. #define FCN_RX_KER_BUF_SIZE_LBN 48
  1680. #define FCN_RX_KER_BUF_SIZE_WIDTH 14
  1681. #define FCN_RX_KER_BUF_ADR_LBN 0
  1682. #define FCN_RX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
  1683. /* Event queue entries */
  1684. #define FCN_EV_CODE_LBN 60
  1685. #define FCN_EV_CODE_WIDTH 4
  1686. #define FCN_RX_IP_EV_DECODE 0
  1687. #define FCN_TX_IP_EV_DECODE 2
  1688. #define FCN_DRIVER_EV_DECODE 5
  1689. /* Receive events */
  1690. #define FCN_RX_EV_PKT_OK_LBN 56
  1691. #define FCN_RX_EV_PKT_OK_WIDTH 1
  1692. #define FCN_RX_PORT_LBN 30
  1693. #define FCN_RX_PORT_WIDTH 1
  1694. #define FCN_RX_EV_BYTE_CNT_LBN 16
  1695. #define FCN_RX_EV_BYTE_CNT_WIDTH 14
  1696. #define FCN_RX_EV_DESC_PTR_LBN 0
  1697. #define FCN_RX_EV_DESC_PTR_WIDTH 12
  1698. /* Transmit events */
  1699. #define FCN_TX_EV_DESC_PTR_LBN 0
  1700. #define FCN_TX_EV_DESC_PTR_WIDTH 12
  1701. /* Fixed special buffer numbers to use */
  1702. #define FALCON_EVQ_ID 0
  1703. #define FALCON_TXD_ID 1
  1704. #define FALCON_RXD_ID 2
  1705. #if FALCON_USE_IO_BAR
  1706. /* Write dword via the I/O BAR */
  1707. static inline void _falcon_writel ( struct efab_nic *efab, uint32_t value,
  1708. unsigned int reg ) {
  1709. outl ( reg, efab->iobase + FCN_IOM_IND_ADR_REG );
  1710. outl ( value, efab->iobase + FCN_IOM_IND_DAT_REG );
  1711. }
  1712. /* Read dword via the I/O BAR */
  1713. static inline uint32_t _falcon_readl ( struct efab_nic *efab,
  1714. unsigned int reg ) {
  1715. outl ( reg, efab->iobase + FCN_IOM_IND_ADR_REG );
  1716. return inl ( efab->iobase + FCN_IOM_IND_DAT_REG );
  1717. }
  1718. #else /* FALCON_USE_IO_BAR */
  1719. #define _falcon_writel( efab, value, reg ) \
  1720. writel ( (value), (efab)->membase + (reg) )
  1721. #define _falcon_readl( efab, reg ) readl ( (efab)->membase + (reg) )
  1722. #endif /* FALCON_USE_IO_BAR */
  1723. /**
  1724. * Write to a Falcon register
  1725. *
  1726. */
  1727. static inline void falcon_write ( struct efab_nic *efab, efab_oword_t *value,
  1728. unsigned int reg ) {
  1729. EFAB_REGDUMP ( "Writing register %x with " EFAB_OWORD_FMT "\n",
  1730. reg, EFAB_OWORD_VAL ( *value ) );
  1731. _falcon_writel ( efab, value->u32[0], reg + 0 );
  1732. _falcon_writel ( efab, value->u32[1], reg + 4 );
  1733. _falcon_writel ( efab, value->u32[2], reg + 8 );
  1734. _falcon_writel ( efab, value->u32[3], reg + 12 );
  1735. wmb();
  1736. }
  1737. /**
  1738. * Write to Falcon SRAM
  1739. *
  1740. */
  1741. static inline void falcon_write_sram ( struct efab_nic *efab,
  1742. efab_qword_t *value,
  1743. unsigned int index ) {
  1744. unsigned int reg = ( FCN_BUF_FULL_TBL_KER +
  1745. ( index * sizeof ( *value ) ) );
  1746. EFAB_REGDUMP ( "Writing SRAM register %x with " EFAB_QWORD_FMT "\n",
  1747. reg, EFAB_QWORD_VAL ( *value ) );
  1748. _falcon_writel ( efab, value->u32[0], reg + 0 );
  1749. _falcon_writel ( efab, value->u32[1], reg + 4 );
  1750. wmb();
  1751. }
  1752. /**
  1753. * Write dword to Falcon register that allows partial writes
  1754. *
  1755. */
  1756. static inline void falcon_writel ( struct efab_nic *efab, efab_dword_t *value,
  1757. unsigned int reg ) {
  1758. EFAB_REGDUMP ( "Writing partial register %x with " EFAB_DWORD_FMT "\n",
  1759. reg, EFAB_DWORD_VAL ( *value ) );
  1760. _falcon_writel ( efab, value->u32[0], reg );
  1761. }
  1762. /**
  1763. * Read from a Falcon register
  1764. *
  1765. */
  1766. static inline void falcon_read ( struct efab_nic *efab, efab_oword_t *value,
  1767. unsigned int reg ) {
  1768. value->u32[0] = _falcon_readl ( efab, reg + 0 );
  1769. value->u32[1] = _falcon_readl ( efab, reg + 4 );
  1770. value->u32[2] = _falcon_readl ( efab, reg + 8 );
  1771. value->u32[3] = _falcon_readl ( efab, reg + 12 );
  1772. EFAB_REGDUMP ( "Read from register %x, got " EFAB_OWORD_FMT "\n",
  1773. reg, EFAB_OWORD_VAL ( *value ) );
  1774. }
  1775. /**
  1776. * Read from Falcon SRAM
  1777. *
  1778. */
  1779. static inline void falcon_read_sram ( struct efab_nic *efab,
  1780. efab_qword_t *value,
  1781. unsigned int index ) {
  1782. unsigned int reg = ( FCN_BUF_FULL_TBL_KER +
  1783. ( index * sizeof ( *value ) ) );
  1784. value->u32[0] = _falcon_readl ( efab, reg + 0 );
  1785. value->u32[1] = _falcon_readl ( efab, reg + 4 );
  1786. EFAB_REGDUMP ( "Read from SRAM register %x, got " EFAB_QWORD_FMT "\n",
  1787. reg, EFAB_QWORD_VAL ( *value ) );
  1788. }
  1789. /**
  1790. * Read dword from a portion of a Falcon register
  1791. *
  1792. */
  1793. static inline void falcon_readl ( struct efab_nic *efab, efab_dword_t *value,
  1794. unsigned int reg ) {
  1795. value->u32[0] = _falcon_readl ( efab, reg );
  1796. EFAB_REGDUMP ( "Read from register %x, got " EFAB_DWORD_FMT "\n",
  1797. reg, EFAB_DWORD_VAL ( *value ) );
  1798. }
  1799. /**
  1800. * Verified write to Falcon SRAM
  1801. *
  1802. */
  1803. static inline void falcon_write_sram_verify ( struct efab_nic *efab,
  1804. efab_qword_t *value,
  1805. unsigned int index ) {
  1806. efab_qword_t verify;
  1807. falcon_write_sram ( efab, value, index );
  1808. udelay ( 1000 );
  1809. falcon_read_sram ( efab, &verify, index );
  1810. if ( memcmp ( &verify, value, sizeof ( verify ) ) != 0 ) {
  1811. EFAB_ERR ( "SRAM index %x failure: wrote " EFAB_QWORD_FMT
  1812. " got " EFAB_QWORD_FMT "\n", index,
  1813. EFAB_QWORD_VAL ( *value ),
  1814. EFAB_QWORD_VAL ( verify ) );
  1815. }
  1816. }
  1817. /**
  1818. * Get memory base
  1819. *
  1820. */
  1821. static void falcon_get_membase ( struct efab_nic *efab ) {
  1822. unsigned long membase_phys;
  1823. membase_phys = pci_bar_start ( efab->pci, PCI_BASE_ADDRESS_2 );
  1824. efab->membase = ioremap ( membase_phys, 0x20000 );
  1825. }
  1826. #define FCN_DUMP_REG( efab, _reg ) do { \
  1827. efab_oword_t reg; \
  1828. falcon_read ( efab, &reg, _reg ); \
  1829. EFAB_LOG ( #_reg " = " EFAB_OWORD_FMT "\n", \
  1830. EFAB_OWORD_VAL ( reg ) ); \
  1831. } while ( 0 );
  1832. #define FCN_DUMP_MAC_REG( efab, _mac_reg ) do { \
  1833. efab_dword_t reg; \
  1834. efab->mac_op->mac_readl ( efab, &reg, _mac_reg ); \
  1835. EFAB_LOG ( #_mac_reg " = " EFAB_DWORD_FMT "\n", \
  1836. EFAB_DWORD_VAL ( reg ) ); \
  1837. } while ( 0 );
  1838. /**
  1839. * Dump register contents (for debugging)
  1840. *
  1841. * Marked as static inline so that it will not be compiled in if not
  1842. * used.
  1843. */
  1844. static inline void falcon_dump_regs ( struct efab_nic *efab ) {
  1845. FCN_DUMP_REG ( efab, FCN_INT_EN_REG_KER );
  1846. FCN_DUMP_REG ( efab, FCN_INT_ADR_REG_KER );
  1847. FCN_DUMP_REG ( efab, FCN_GLB_CTL_REG_KER );
  1848. FCN_DUMP_REG ( efab, FCN_TIMER_CMD_REG_KER );
  1849. FCN_DUMP_REG ( efab, FCN_SRM_RX_DC_CFG_REG_KER );
  1850. FCN_DUMP_REG ( efab, FCN_SRM_TX_DC_CFG_REG_KER );
  1851. FCN_DUMP_REG ( efab, FCN_RX_FILTER_CTL_REG_KER );
  1852. FCN_DUMP_REG ( efab, FCN_RX_DC_CFG_REG_KER );
  1853. FCN_DUMP_REG ( efab, FCN_TX_DC_CFG_REG_KER );
  1854. FCN_DUMP_REG ( efab, FCN_MAC0_CTRL_REG_KER );
  1855. FCN_DUMP_REG ( efab, FCN_MAC1_CTRL_REG_KER );
  1856. FCN_DUMP_REG ( efab, FCN_RX_DESC_PTR_TBL_KER );
  1857. FCN_DUMP_REG ( efab, FCN_TX_DESC_PTR_TBL_KER );
  1858. FCN_DUMP_REG ( efab, FCN_EVQ_PTR_TBL_KER );
  1859. FCN_DUMP_MAC_REG ( efab, GM_CFG1_REG_MAC );
  1860. FCN_DUMP_MAC_REG ( efab, GM_CFG2_REG_MAC );
  1861. FCN_DUMP_MAC_REG ( efab, GM_MAX_FLEN_REG_MAC );
  1862. FCN_DUMP_MAC_REG ( efab, GM_MII_MGMT_CFG_REG_MAC );
  1863. FCN_DUMP_MAC_REG ( efab, GM_ADR1_REG_MAC );
  1864. FCN_DUMP_MAC_REG ( efab, GM_ADR2_REG_MAC );
  1865. FCN_DUMP_MAC_REG ( efab, GMF_CFG0_REG_MAC );
  1866. FCN_DUMP_MAC_REG ( efab, GMF_CFG1_REG_MAC );
  1867. FCN_DUMP_MAC_REG ( efab, GMF_CFG2_REG_MAC );
  1868. FCN_DUMP_MAC_REG ( efab, GMF_CFG3_REG_MAC );
  1869. FCN_DUMP_MAC_REG ( efab, GMF_CFG4_REG_MAC );
  1870. FCN_DUMP_MAC_REG ( efab, GMF_CFG5_REG_MAC );
  1871. }
  1872. /**
  1873. * Create special buffer
  1874. *
  1875. */
  1876. static void falcon_create_special_buffer ( struct efab_nic *efab,
  1877. void *addr, unsigned int index ) {
  1878. efab_qword_t buf_desc;
  1879. unsigned long dma_addr;
  1880. memset ( addr, 0, 4096 );
  1881. dma_addr = virt_to_bus ( addr );
  1882. EFAB_ASSERT ( ( dma_addr & ( EFAB_BUF_ALIGN - 1 ) ) == 0 );
  1883. EFAB_POPULATE_QWORD_3 ( buf_desc,
  1884. FCN_IP_DAT_BUF_SIZE, FCN_IP_DAT_BUF_SIZE_4K,
  1885. FCN_BUF_ADR_FBUF, ( dma_addr >> 12 ),
  1886. FCN_BUF_OWNER_ID_FBUF, 0 );
  1887. falcon_write_sram_verify ( efab, &buf_desc, index );
  1888. }
  1889. /**
  1890. * Update event queue read pointer
  1891. *
  1892. */
  1893. static void falcon_eventq_read_ack ( struct efab_nic *efab ) {
  1894. efab_dword_t reg;
  1895. EFAB_ASSERT ( efab->eventq_read_ptr < EFAB_EVQ_SIZE );
  1896. EFAB_POPULATE_DWORD_1 ( reg, FCN_EVQ_RPTR_DWORD,
  1897. efab->eventq_read_ptr );
  1898. falcon_writel ( efab, &reg, FCN_EVQ_RPTR_REG_KER_DWORD );
  1899. }
  1900. /**
  1901. * Reset device
  1902. *
  1903. */
  1904. static int falcon_reset ( struct efab_nic *efab ) {
  1905. efab_oword_t glb_ctl_reg_ker;
  1906. /* Initiate software reset */
  1907. EFAB_POPULATE_OWORD_7 ( glb_ctl_reg_ker,
  1908. PCIE_CORE_RST_CTL, EXCLUDE_FROM_RESET,
  1909. PCIE_NSTCK_RST_CTL, EXCLUDE_FROM_RESET,
  1910. PCIE_SD_RST_CTL, EXCLUDE_FROM_RESET,
  1911. EE_RST_CTL, EXCLUDE_FROM_RESET,
  1912. PCIX_RST_CTL, EXCLUDE_FROM_RESET,
  1913. EXT_PHY_RST_DUR, 0x7 /* datasheet recommended */,
  1914. SWRST, 1 );
  1915. falcon_write ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
  1916. /* Allow 20ms for reset */
  1917. mdelay ( 20 );
  1918. /* Check for device reset complete */
  1919. falcon_read ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
  1920. if ( EFAB_OWORD_FIELD ( glb_ctl_reg_ker, SWRST ) != 0 ) {
  1921. EFAB_ERR ( "Reset failed\n" );
  1922. return 0;
  1923. }
  1924. return 1;
  1925. }
  1926. /**
  1927. * Wait for SPI command completion
  1928. *
  1929. */
  1930. static int falcon_spi_wait ( struct efab_nic *efab ) {
  1931. efab_oword_t reg;
  1932. int count;
  1933. count = 0;
  1934. do {
  1935. udelay ( 100 );
  1936. falcon_read ( efab, &reg, FCN_EE_SPI_HCMD_REG_KER );
  1937. if ( EFAB_OWORD_FIELD ( reg, FCN_EE_SPI_HCMD_CMD_EN ) == 0 )
  1938. return 1;
  1939. } while ( ++count < 1000 );
  1940. printf ( "Timed out waiting for SPI\n" );
  1941. return 0;
  1942. }
  1943. /**
  1944. * Perform SPI read/write
  1945. *
  1946. */
  1947. static int falcon_spi_rw ( struct spi_bus *bus, struct spi_device *device,
  1948. unsigned int command, int address,
  1949. const void *data_out, void *data_in, size_t len ) {
  1950. struct efab_nic *efab = container_of ( bus, struct efab_nic, spi );
  1951. efab_oword_t reg;
  1952. /* Program address register */
  1953. EFAB_POPULATE_OWORD_1 ( reg, FCN_EE_SPI_HADR_ADR, address );
  1954. falcon_write ( efab, &reg, FCN_EE_SPI_HADR_REG_KER );
  1955. /* Program data register, if applicable */
  1956. if ( data_out ) {
  1957. memcpy ( &reg, data_out, len );
  1958. falcon_write ( efab, &reg, FCN_EE_SPI_HDATA_REG_KER );
  1959. }
  1960. /* Issue command */
  1961. EFAB_POPULATE_OWORD_7 ( reg,
  1962. FCN_EE_SPI_HCMD_CMD_EN, 1,
  1963. FCN_EE_SPI_HCMD_SF_SEL, device->slave,
  1964. FCN_EE_SPI_HCMD_DABCNT, len,
  1965. FCN_EE_SPI_HCMD_READ, ( data_out ?
  1966. FCN_EE_SPI_WRITE : FCN_EE_SPI_READ ),
  1967. FCN_EE_SPI_HCMD_DUBCNT, 0,
  1968. FCN_EE_SPI_HCMD_ADBCNT,
  1969. ( device->address_len / 8 ),
  1970. FCN_EE_SPI_HCMD_ENC, command );
  1971. falcon_write ( efab, &reg, FCN_EE_SPI_HCMD_REG_KER );
  1972. /* Wait for operation to complete */
  1973. if ( ! falcon_spi_wait ( efab ) )
  1974. return 0;
  1975. /* Read data, if applicable */
  1976. if ( data_in ) {
  1977. falcon_read ( efab, &reg, FCN_EE_SPI_HDATA_REG_KER );
  1978. memcpy ( data_in, &reg, len );
  1979. }
  1980. return 0;
  1981. }
  1982. /**
  1983. * Initialise SPI bus and devices
  1984. *
  1985. */
  1986. static void falcon_init_spi ( struct efab_nic *efab ) {
  1987. efab_oword_t reg;
  1988. int eeprom_9bit;
  1989. /* Initialise SPI bus */
  1990. efab->spi.rw = falcon_spi_rw;
  1991. efab->falcon_eeprom.bus = &efab->spi;
  1992. efab->falcon_eeprom.slave = FCN_EE_SPI_EEPROM;
  1993. efab->falcon_flash.bus = &efab->spi;
  1994. efab->falcon_flash.slave = FCN_EE_SPI_FLASH;
  1995. /* Initialise flash if present */
  1996. if ( efab->has_flash ) {
  1997. DBG ( "Flash is present\n" );
  1998. init_at25f1024 ( &efab->falcon_flash );
  1999. }
  2000. /* Initialise EEPROM if present */
  2001. if ( efab->has_eeprom ) {
  2002. if ( efab->is_asic ) {
  2003. falcon_read ( efab, &reg, FCN_VPD_CONFIG_REG_KER );
  2004. eeprom_9bit = EFAB_OWORD_FIELD ( reg, FCN_VPD_9BIT );
  2005. } else {
  2006. eeprom_9bit = 1;
  2007. }
  2008. if ( eeprom_9bit ) {
  2009. DBG ( "Small EEPROM is present\n" );
  2010. init_at25040 ( &efab->falcon_eeprom );
  2011. } else {
  2012. DBG ( "Large EEPROM is present\n" );
  2013. init_mc25xx640 ( &efab->falcon_eeprom );
  2014. /* Falcon's SPI interface cannot support a block
  2015. size larger than 16, so forcibly reduce it
  2016. */
  2017. efab->falcon_eeprom.nvs.block_size = 16;
  2018. }
  2019. }
  2020. }
  2021. /** Offset of MAC address within EEPROM or Flash */
  2022. #define FALCON_MAC_ADDRESS_OFFSET(port) ( 0x310 + 0x08 * (port) )
  2023. static struct nvo_fragment falcon_eeprom_fragments[] = {
  2024. { 0x100, 0x100 },
  2025. { 0, 0 }
  2026. };
  2027. /**
  2028. * Read MAC address from EEPROM
  2029. *
  2030. */
  2031. static int falcon_read_eeprom ( struct efab_nic *efab ) {
  2032. struct nvs_device *nvs;
  2033. /* Determine the NVS device containing the MAC address */
  2034. nvs = ( efab->has_flash ?
  2035. &efab->falcon_flash.nvs : &efab->falcon_eeprom.nvs );
  2036. return ( nvs_read ( nvs, FALCON_MAC_ADDRESS_OFFSET ( efab->port ),
  2037. efab->mac_addr, sizeof ( efab->mac_addr ) ) == 0 );
  2038. }
  2039. /** RX descriptor */
  2040. typedef efab_qword_t falcon_rx_desc_t;
  2041. /**
  2042. * Build RX descriptor
  2043. *
  2044. */
  2045. static void falcon_build_rx_desc ( struct efab_nic *efab,
  2046. struct efab_rx_buf *rx_buf ) {
  2047. falcon_rx_desc_t *rxd;
  2048. rxd = ( ( falcon_rx_desc_t * ) efab->rxd ) + rx_buf->id;
  2049. EFAB_POPULATE_QWORD_2 ( *rxd,
  2050. FCN_RX_KER_BUF_SIZE, EFAB_DATA_BUF_SIZE,
  2051. FCN_RX_KER_BUF_ADR,
  2052. virt_to_bus ( rx_buf->addr ) );
  2053. }
  2054. /**
  2055. * Update RX descriptor write pointer
  2056. *
  2057. */
  2058. static void falcon_notify_rx_desc ( struct efab_nic *efab ) {
  2059. efab_dword_t reg;
  2060. EFAB_POPULATE_DWORD_1 ( reg, FCN_RX_DESC_WPTR_DWORD,
  2061. efab->rx_write_ptr );
  2062. falcon_writel ( efab, &reg, FCN_RX_DESC_UPD_REG_KER_DWORD );
  2063. }
  2064. /** TX descriptor */
  2065. typedef efab_qword_t falcon_tx_desc_t;
  2066. /**
  2067. * Build TX descriptor
  2068. *
  2069. */
  2070. static void falcon_build_tx_desc ( struct efab_nic *efab,
  2071. struct efab_tx_buf *tx_buf ) {
  2072. falcon_rx_desc_t *txd;
  2073. txd = ( ( falcon_rx_desc_t * ) efab->txd ) + tx_buf->id;
  2074. EFAB_POPULATE_QWORD_3 ( *txd,
  2075. FCN_TX_KER_PORT, efab->port,
  2076. FCN_TX_KER_BYTE_CNT, tx_buf->len,
  2077. FCN_TX_KER_BUF_ADR,
  2078. virt_to_bus ( tx_buf->addr ) );
  2079. }
  2080. /**
  2081. * Update TX descriptor write pointer
  2082. *
  2083. */
  2084. static void falcon_notify_tx_desc ( struct efab_nic *efab ) {
  2085. efab_dword_t reg;
  2086. EFAB_POPULATE_DWORD_1 ( reg, FCN_TX_DESC_WPTR_DWORD,
  2087. efab->tx_write_ptr );
  2088. falcon_writel ( efab, &reg, FCN_TX_DESC_UPD_REG_KER_DWORD );
  2089. }
  2090. /** An event */
  2091. typedef efab_qword_t falcon_event_t;
  2092. /**
  2093. * See if an event is present
  2094. *
  2095. * @v event Falcon event structure
  2096. * @ret True An event is pending
  2097. * @ret False No event is pending
  2098. *
  2099. * We check both the high and low dword of the event for all ones. We
  2100. * wrote all ones when we cleared the event, and no valid event can
  2101. * have all ones in either its high or low dwords. This approach is
  2102. * robust against reordering.
  2103. *
  2104. * Note that using a single 64-bit comparison is incorrect; even
  2105. * though the CPU read will be atomic, the DMA write may not be.
  2106. */
  2107. static inline int falcon_event_present ( falcon_event_t* event ) {
  2108. return ( ! ( EFAB_DWORD_IS_ALL_ONES ( event->dword[0] ) |
  2109. EFAB_DWORD_IS_ALL_ONES ( event->dword[1] ) ) );
  2110. }
  2111. /**
  2112. * Retrieve event from event queue
  2113. *
  2114. */
  2115. static int falcon_fetch_event ( struct efab_nic *efab,
  2116. struct efab_event *event ) {
  2117. falcon_event_t *evt;
  2118. int ev_code;
  2119. int rx_port;
  2120. /* Check for event */
  2121. evt = ( ( falcon_event_t * ) efab->eventq ) + efab->eventq_read_ptr;
  2122. if ( !falcon_event_present ( evt ) ) {
  2123. /* No event */
  2124. return 0;
  2125. }
  2126. DBG ( "Event is " EFAB_QWORD_FMT "\n", EFAB_QWORD_VAL ( *evt ) );
  2127. /* Decode event */
  2128. ev_code = EFAB_QWORD_FIELD ( *evt, FCN_EV_CODE );
  2129. event->drop = 0;
  2130. switch ( ev_code ) {
  2131. case FCN_TX_IP_EV_DECODE:
  2132. event->type = EFAB_EV_TX;
  2133. break;
  2134. case FCN_RX_IP_EV_DECODE:
  2135. event->type = EFAB_EV_RX;
  2136. event->rx_id = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_DESC_PTR );
  2137. event->rx_len = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_BYTE_CNT );
  2138. event->drop = !EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_PKT_OK );
  2139. rx_port = EFAB_QWORD_FIELD ( *evt, FCN_RX_PORT );
  2140. if ( rx_port != efab->port ) {
  2141. /* Ignore packets on the wrong port. We can't
  2142. * just set event->type = EFAB_EV_NONE,
  2143. * because then the descriptor ring won't get
  2144. * refilled.
  2145. */
  2146. event->rx_len = 0;
  2147. }
  2148. break;
  2149. case FCN_DRIVER_EV_DECODE:
  2150. /* Ignore start-of-day events */
  2151. event->type = EFAB_EV_NONE;
  2152. break;
  2153. default:
  2154. EFAB_ERR ( "Unknown event type %d data %08lx\n", ev_code,
  2155. EFAB_DWORD_FIELD ( *evt, EFAB_DWORD_0 ) );
  2156. event->type = EFAB_EV_NONE;
  2157. }
  2158. /* Clear event and any pending interrupts */
  2159. EFAB_SET_QWORD ( *evt );
  2160. falcon_writel ( efab, 0, FCN_INT_ACK_KER_REG );
  2161. udelay ( 10 );
  2162. /* Increment and update event queue read pointer */
  2163. efab->eventq_read_ptr = ( ( efab->eventq_read_ptr + 1 )
  2164. % EFAB_EVQ_SIZE );
  2165. falcon_eventq_read_ack ( efab );
  2166. return 1;
  2167. }
  2168. /**
  2169. * Enable/disable/generate interrupt
  2170. *
  2171. */
  2172. static inline void falcon_interrupts ( struct efab_nic *efab, int enabled,
  2173. int force ) {
  2174. efab_oword_t int_en_reg_ker;
  2175. EFAB_POPULATE_OWORD_2 ( int_en_reg_ker,
  2176. FCN_KER_INT_KER, force,
  2177. FCN_DRV_INT_EN_KER, enabled );
  2178. falcon_write ( efab, &int_en_reg_ker, FCN_INT_EN_REG_KER );
  2179. }
  2180. /**
  2181. * Enable/disable interrupts
  2182. *
  2183. */
  2184. static void falcon_mask_irq ( struct efab_nic *efab, int enabled ) {
  2185. falcon_interrupts ( efab, enabled, 0 );
  2186. if ( enabled ) {
  2187. /* Events won't trigger interrupts until we do this */
  2188. falcon_eventq_read_ack ( efab );
  2189. }
  2190. }
  2191. /**
  2192. * Generate interrupt
  2193. *
  2194. */
  2195. static void falcon_generate_irq ( struct efab_nic *efab ) {
  2196. falcon_interrupts ( efab, 1, 1 );
  2197. }
  2198. /**
  2199. * Reconfigure MAC wrapper
  2200. *
  2201. */
  2202. static void falcon_reconfigure_mac_wrapper ( struct efab_nic *efab ) {
  2203. efab_oword_t reg;
  2204. int link_speed;
  2205. if ( efab->link_options & LPA_10000 ) {
  2206. link_speed = 0x3;
  2207. } else if ( efab->link_options & LPA_1000 ) {
  2208. link_speed = 0x2;
  2209. } else if ( efab->link_options & LPA_100 ) {
  2210. link_speed = 0x1;
  2211. } else {
  2212. link_speed = 0x0;
  2213. }
  2214. EFAB_POPULATE_OWORD_5 ( reg,
  2215. FCN_MAC_XOFF_VAL, 0xffff /* datasheet */,
  2216. FCN_MAC_BCAD_ACPT, 1,
  2217. FCN_MAC_UC_PROM, 0,
  2218. FCN_MAC_LINK_STATUS, 1,
  2219. FCN_MAC_SPEED, link_speed );
  2220. falcon_write ( efab, &reg,
  2221. ( efab->port == 0 ?
  2222. FCN_MAC0_CTRL_REG_KER : FCN_MAC1_CTRL_REG_KER ) );
  2223. /* Disable flow-control (i.e. never generate pause frames) */
  2224. falcon_read ( efab, &reg, FCN_RX_CFG_REG_KER );
  2225. EFAB_SET_OWORD_FIELD ( reg, FCN_RX_XOFF_EN, 0 );
  2226. falcon_write ( efab, &reg, FCN_RX_CFG_REG_KER );
  2227. }
  2228. /**
  2229. * Write dword to a Falcon MAC register
  2230. *
  2231. */
  2232. static void falcon_gmac_writel ( struct efab_nic *efab,
  2233. efab_dword_t *value, unsigned int mac_reg ) {
  2234. efab_oword_t temp;
  2235. EFAB_POPULATE_OWORD_1 ( temp, FCN_MAC_DATA,
  2236. EFAB_DWORD_FIELD ( *value, FCN_MAC_DATA ) );
  2237. falcon_write ( efab, &temp, FALCON_GMAC_REG ( efab, mac_reg ) );
  2238. }
  2239. /**
  2240. * Read dword from a Falcon GMAC register
  2241. *
  2242. */
  2243. static void falcon_gmac_readl ( struct efab_nic *efab, efab_dword_t *value,
  2244. unsigned int mac_reg ) {
  2245. efab_oword_t temp;
  2246. falcon_read ( efab, &temp, FALCON_GMAC_REG ( efab, mac_reg ) );
  2247. EFAB_POPULATE_DWORD_1 ( *value, FCN_MAC_DATA,
  2248. EFAB_OWORD_FIELD ( temp, FCN_MAC_DATA ) );
  2249. }
  2250. /**
  2251. * Write dword to a Falcon XMAC register
  2252. *
  2253. */
  2254. static void falcon_xmac_writel ( struct efab_nic *efab,
  2255. efab_dword_t *value, unsigned int mac_reg ) {
  2256. efab_oword_t temp;
  2257. EFAB_POPULATE_OWORD_1 ( temp, FCN_MAC_DATA,
  2258. EFAB_DWORD_FIELD ( *value, FCN_MAC_DATA ) );
  2259. falcon_write ( efab, &temp,
  2260. FALCON_XMAC_REG ( efab, mac_reg ) );
  2261. }
  2262. /**
  2263. * Read dword from a Falcon XMAC register
  2264. *
  2265. */
  2266. static void falcon_xmac_readl ( struct efab_nic *efab,
  2267. efab_dword_t *value,
  2268. unsigned int mac_reg ) {
  2269. efab_oword_t temp;
  2270. falcon_read ( efab, &temp,
  2271. FALCON_XMAC_REG ( efab, mac_reg ) );
  2272. EFAB_POPULATE_DWORD_1 ( *value, FCN_MAC_DATA,
  2273. EFAB_OWORD_FIELD ( temp, FCN_MAC_DATA ) );
  2274. }
  2275. /**
  2276. * Initialise GMAC
  2277. *
  2278. */
  2279. static int falcon_init_gmac ( struct efab_nic *efab ) {
  2280. static struct efab_mentormac_parameters falcon_mentormac_params = {
  2281. .gmf_cfgfrth = 0x12,
  2282. .gmf_cfgftth = 0x08,
  2283. .gmf_cfghwmft = 0x1c,
  2284. .gmf_cfghwm = 0x3f,
  2285. .gmf_cfglwm = 0xa,
  2286. };
  2287. /* Initialise PHY */
  2288. alaska_init ( efab );
  2289. /* check the link is up */
  2290. if ( !efab->link_up )
  2291. return 0;
  2292. /* Initialise MAC */
  2293. mentormac_init ( efab, &falcon_mentormac_params );
  2294. /* reconfigure the MAC wrapper */
  2295. falcon_reconfigure_mac_wrapper ( efab );
  2296. return 1;
  2297. }
  2298. /**
  2299. * Reset GMAC
  2300. *
  2301. */
  2302. static int falcon_reset_gmac ( struct efab_nic *efab ) {
  2303. mentormac_reset ( efab );
  2304. return 1;
  2305. }
  2306. /**
  2307. * Reset XAUI/XGXS block
  2308. *
  2309. */
  2310. static int falcon_reset_xaui ( struct efab_nic *efab )
  2311. {
  2312. efab_dword_t reg;
  2313. int count;
  2314. EFAB_POPULATE_DWORD_1 ( reg, FCN_XX_RST_XX_EN, 1 );
  2315. efab->mac_op->mac_writel ( efab, &reg, FCN_XX_PWR_RST_REG_MAC );
  2316. for ( count = 0 ; count < 1000 ; count++ ) {
  2317. udelay ( 10 );
  2318. efab->mac_op->mac_readl ( efab, &reg,
  2319. FCN_XX_PWR_RST_REG_MAC );
  2320. if ( EFAB_DWORD_FIELD ( reg, FCN_XX_RST_XX_EN ) == 0 )
  2321. return 1;
  2322. }
  2323. /* an error of some kind */
  2324. return 0;
  2325. }
  2326. /**
  2327. * Reset 10G MAC connected to port
  2328. *
  2329. */
  2330. static int falcon_reset_xmac ( struct efab_nic *efab ) {
  2331. efab_dword_t reg;
  2332. int count;
  2333. EFAB_POPULATE_DWORD_1 ( reg, FCN_XM_CORE_RST, 1 );
  2334. efab->mac_op->mac_writel ( efab, &reg, FCN_XM_GLB_CFG_REG_MAC );
  2335. for ( count = 0 ; count < 1000 ; count++ ) {
  2336. udelay ( 10 );
  2337. efab->mac_op->mac_readl ( efab, &reg,
  2338. FCN_XM_GLB_CFG_REG_MAC );
  2339. if ( EFAB_DWORD_FIELD ( reg, FCN_XM_CORE_RST ) == 0 )
  2340. return 1;
  2341. }
  2342. return 0;
  2343. }
  2344. /**
  2345. * Get status of 10G link
  2346. *
  2347. */
  2348. static int falcon_xaui_link_ok ( struct efab_nic *efab ) {
  2349. efab_dword_t reg;
  2350. int align_done;
  2351. int sync_status;
  2352. int link_ok = 0;
  2353. /* Read link status */
  2354. efab->mac_op->mac_readl ( efab, &reg, FCN_XX_CORE_STAT_REG_MAC );
  2355. align_done = EFAB_DWORD_FIELD ( reg, FCN_XX_ALIGN_DONE );
  2356. sync_status = EFAB_DWORD_FIELD ( reg, FCN_XX_SYNC_STAT );
  2357. if ( align_done && ( sync_status == FCN_XX_SYNC_STAT_DECODE_SYNCED ) ) {
  2358. link_ok = 1;
  2359. }
  2360. /* Clear link status ready for next read */
  2361. EFAB_SET_DWORD_FIELD ( reg, FCN_XX_COMMA_DET, FCN_XX_COMMA_DET_RESET );
  2362. efab->mac_op->mac_writel ( efab, &reg, FCN_XX_CORE_STAT_REG_MAC );
  2363. return link_ok;
  2364. }
  2365. /**
  2366. * Initialise XMAC
  2367. *
  2368. */
  2369. static int falcon_init_xmac ( struct efab_nic *efab ) {
  2370. efab_dword_t reg;
  2371. int count;
  2372. if ( !falcon_reset_xmac ( efab ) ) {
  2373. EFAB_ERR ( "failed resetting XMAC\n" );
  2374. return 0;
  2375. }
  2376. if ( !falcon_reset_xaui ( efab ) ) {
  2377. EFAB_ERR ( "failed resetting XAUI\n");
  2378. return 0;
  2379. }
  2380. /* CX4 is always 10000FD only */
  2381. efab->link_options = LPA_10000FULL;
  2382. /* Configure MAC */
  2383. EFAB_POPULATE_DWORD_3 ( reg,
  2384. FCN_XM_RX_JUMBO_MODE, 1,
  2385. FCN_XM_TX_STAT_EN, 1,
  2386. FCN_XM_RX_STAT_EN, 1);
  2387. efab->mac_op->mac_writel ( efab, &reg, FCN_XM_GLB_CFG_REG_MAC );
  2388. /* Configure TX */
  2389. EFAB_POPULATE_DWORD_6 ( reg,
  2390. FCN_XM_TXEN, 1,
  2391. FCN_XM_TX_PRMBL, 1,
  2392. FCN_XM_AUTO_PAD, 1,
  2393. FCN_XM_TXCRC, 1,
  2394. FCN_XM_FCNTL, 1,
  2395. FCN_XM_IPG, 0x3 );
  2396. efab->mac_op->mac_writel ( efab, &reg, FCN_XM_TX_CFG_REG_MAC );
  2397. /* Configure RX */
  2398. EFAB_POPULATE_DWORD_3 ( reg,
  2399. FCN_XM_RXEN, 1,
  2400. FCN_XM_AUTO_DEPAD, 1,
  2401. FCN_XM_PASS_CRC_ERR, 1 );
  2402. efab->mac_op->mac_writel ( efab, &reg, FCN_XM_RX_CFG_REG_MAC );
  2403. /* Set frame length */
  2404. EFAB_POPULATE_DWORD_1 ( reg,
  2405. FCN_XM_MAX_RX_FRM_SIZE, ETH_FRAME_LEN );
  2406. efab->mac_op->mac_writel ( efab, &reg, FCN_XM_RX_PARAM_REG_MAC );
  2407. EFAB_POPULATE_DWORD_2 ( reg,
  2408. FCN_XM_MAX_TX_FRM_SIZE, ETH_FRAME_LEN,
  2409. FCN_XM_TX_JUMBO_MODE, 1 );
  2410. efab->mac_op->mac_writel ( efab, &reg, FCN_XM_TX_PARAM_REG_MAC );
  2411. /* Set MAC address */
  2412. EFAB_POPULATE_DWORD_4 ( reg,
  2413. FCN_XM_ADR_0, efab->mac_addr[0],
  2414. FCN_XM_ADR_1, efab->mac_addr[1],
  2415. FCN_XM_ADR_2, efab->mac_addr[2],
  2416. FCN_XM_ADR_3, efab->mac_addr[3] );
  2417. efab->mac_op->mac_writel ( efab, &reg, FCN_XM_ADR_LO_REG_MAC );
  2418. EFAB_POPULATE_DWORD_2 ( reg,
  2419. FCN_XM_ADR_4, efab->mac_addr[4],
  2420. FCN_XM_ADR_5, efab->mac_addr[5] );
  2421. efab->mac_op->mac_writel ( efab, &reg, FCN_XM_ADR_HI_REG_MAC );
  2422. /* Reconfigure MAC wrapper */
  2423. falcon_reconfigure_mac_wrapper ( efab );
  2424. /**
  2425. * Try resetting XAUI on its own waiting for the link
  2426. * to come up
  2427. */
  2428. for(count=0; count<5; count++) {
  2429. /* Check link status */
  2430. efab->link_up = falcon_xaui_link_ok ( efab );
  2431. if ( efab->link_up ) {
  2432. /**
  2433. * Print out a speed message since we don't have a PHY
  2434. */
  2435. EFAB_LOG ( "%dMbps %s-duplex\n",
  2436. ( efab->link_options & LPA_10000 ? 1000 :
  2437. ( efab->link_options & LPA_1000 ? 1000 :
  2438. ( efab->link_options & LPA_100 ? 100 : 10 ) ) ),
  2439. ( efab->link_options & LPA_DUPLEX ? "full" : "half" ) );
  2440. break;
  2441. }
  2442. if ( !falcon_reset_xaui ( efab ) ) {
  2443. EFAB_ERR ( "failed resetting xaui\n" );
  2444. return 0;
  2445. }
  2446. udelay(100);
  2447. }
  2448. return 1;
  2449. }
  2450. /**
  2451. * Wait for GMII access to complete
  2452. *
  2453. */
  2454. static int falcon_gmii_wait ( struct efab_nic *efab ) {
  2455. efab_oword_t md_stat;
  2456. int count;
  2457. for ( count = 0 ; count < 1000 ; count++ ) {
  2458. udelay ( 10 );
  2459. falcon_read ( efab, &md_stat, FCN_MD_STAT_REG_KER );
  2460. if ( EFAB_OWORD_FIELD ( md_stat, FCN_MD_BSY ) == 0 )
  2461. return 1;
  2462. }
  2463. EFAB_ERR ( "Timed out waiting for GMII\n" );
  2464. return 0;
  2465. }
  2466. static struct efab_mac_operations falcon_xmac_operations = {
  2467. .mac_readl = falcon_xmac_readl,
  2468. .mac_writel = falcon_xmac_writel,
  2469. .init = falcon_init_xmac,
  2470. .reset = falcon_reset_xmac,
  2471. };
  2472. static struct efab_mac_operations falcon_gmac_operations = {
  2473. .mac_readl = falcon_gmac_readl,
  2474. .mac_writel = falcon_gmac_writel,
  2475. .init = falcon_init_gmac,
  2476. .reset = falcon_reset_gmac,
  2477. };
  2478. /**
  2479. * Initialise NIC
  2480. *
  2481. */
  2482. static int falcon_init_nic ( struct efab_nic *efab ) {
  2483. efab_oword_t reg;
  2484. efab_dword_t timer_cmd;
  2485. int version, minor;
  2486. /* use card in internal SRAM mode */
  2487. falcon_read ( efab, &reg, FCN_NIC_STAT_REG );
  2488. EFAB_SET_OWORD_FIELD ( reg, ONCHIP_SRAM, 1 );
  2489. falcon_write ( efab, &reg, FCN_NIC_STAT_REG );
  2490. wmb();
  2491. /* identify FPGA/ASIC, and strapping mode */
  2492. falcon_read ( efab, &reg, ALTERA_BUILD_REG_KER );
  2493. version = EFAB_OWORD_FIELD ( reg, VER_ALL );
  2494. efab->is_asic = version ? 0 : 1;
  2495. if ( efab->is_asic ) {
  2496. falcon_read ( efab, &reg, FCN_NIC_STAT_REG );
  2497. if ( EFAB_OWORD_FIELD ( reg, STRAP_10G ) ) {
  2498. efab->is_10g = 1;
  2499. }
  2500. if ( EFAB_OWORD_FIELD ( reg, STRAP_DUAL_PORT ) ) {
  2501. efab->is_dual = 1;
  2502. }
  2503. }
  2504. else {
  2505. falcon_read ( efab, &reg, ALTERA_BUILD_REG_KER );
  2506. minor = EFAB_OWORD_FIELD ( reg, VER_MINOR );
  2507. if ( minor == 0x14 ) {
  2508. efab->is_10g = 1;
  2509. } else if ( minor == 0x13 ) {
  2510. efab->is_dual = 1;
  2511. }
  2512. }
  2513. DBG ( "NIC type: %s %dx%s\n",
  2514. efab->is_asic ? "ASIC" : "FPGA",
  2515. efab->is_dual ? 2 : 1,
  2516. efab->is_10g ? "10G" : "1G" );
  2517. /* patch in MAC operations */
  2518. if ( efab->is_10g )
  2519. efab->mac_op = &falcon_xmac_operations;
  2520. else
  2521. efab->mac_op = &falcon_gmac_operations;
  2522. if ( !efab->is_dual && ( efab->port == 1 ) ) {
  2523. /* device doesn't exist */
  2524. return 0;
  2525. }
  2526. /* determine EEPROM / FLASH */
  2527. if ( efab->is_asic ) {
  2528. falcon_read ( efab, &reg, FCN_NIC_STAT_REG );
  2529. efab->has_flash = EFAB_OWORD_FIELD ( reg, SF_PRST );
  2530. efab->has_eeprom = EFAB_OWORD_FIELD ( reg, EE_PRST );
  2531. } else {
  2532. falcon_read ( efab, &reg, FCN_GPIO_CTL_REG_KER );
  2533. efab->has_flash = EFAB_OWORD_FIELD ( reg, FCN_FLASH_PRESENT );
  2534. efab->has_eeprom = EFAB_OWORD_FIELD ( reg, FCN_EEPROM_PRESENT);
  2535. }
  2536. DBG ( "flash is %s, EEPROM is %s\n",
  2537. ( efab->has_flash ? "present" : "absent" ),
  2538. ( efab->has_eeprom ? "present" : "absent" ) );
  2539. falcon_init_spi ( efab );
  2540. /* Set up TX and RX descriptor caches in SRAM */
  2541. EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_TX_DC_BASE_ADR,
  2542. 0x130000 /* recommended in datasheet */ );
  2543. falcon_write ( efab, &reg, FCN_SRM_TX_DC_CFG_REG_KER );
  2544. EFAB_POPULATE_OWORD_1 ( reg, FCN_TX_DC_SIZE, 2 /* 32 descriptors */ );
  2545. falcon_write ( efab, &reg, FCN_TX_DC_CFG_REG_KER );
  2546. EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_RX_DC_BASE_ADR,
  2547. 0x100000 /* recommended in datasheet */ );
  2548. falcon_write ( efab, &reg, FCN_SRM_RX_DC_CFG_REG_KER );
  2549. EFAB_POPULATE_OWORD_1 ( reg, FCN_RX_DC_SIZE, 2 /* 32 descriptors */ );
  2550. falcon_write ( efab, &reg, FCN_RX_DC_CFG_REG_KER );
  2551. /* Set number of RSS CPUs */
  2552. EFAB_POPULATE_OWORD_1 ( reg, FCN_NUM_KER, 0 );
  2553. falcon_write ( efab, &reg, FCN_RX_FILTER_CTL_REG_KER );
  2554. udelay ( 1000 );
  2555. /* Reset the MAC */
  2556. mentormac_reset ( efab );
  2557. /* Set up event queue */
  2558. falcon_create_special_buffer ( efab, efab->eventq, FALCON_EVQ_ID );
  2559. /* Fill eventq with all ones ( empty events ) */
  2560. memset(efab->eventq, 0xff, 4096);
  2561. /* push eventq to card */
  2562. EFAB_POPULATE_OWORD_3 ( reg,
  2563. FCN_EVQ_EN, 1,
  2564. FCN_EVQ_SIZE, FCN_EVQ_SIZE_512,
  2565. FCN_EVQ_BUF_BASE_ID, FALCON_EVQ_ID );
  2566. falcon_write ( efab, &reg, FCN_EVQ_PTR_TBL_KER );
  2567. udelay ( 1000 );
  2568. /* Set timer register */
  2569. EFAB_POPULATE_DWORD_2 ( timer_cmd,
  2570. FCN_TIMER_MODE, FCN_TIMER_MODE_DIS,
  2571. FCN_TIMER_VAL, 0 );
  2572. falcon_writel ( efab, &timer_cmd, FCN_TIMER_CMD_REG_KER );
  2573. udelay ( 1000 );
  2574. /* Initialise event queue read pointer */
  2575. falcon_eventq_read_ack ( efab );
  2576. /* Set up TX descriptor ring */
  2577. falcon_create_special_buffer ( efab, efab->txd, FALCON_TXD_ID );
  2578. EFAB_POPULATE_OWORD_5 ( reg,
  2579. FCN_TX_DESCQ_EN, 1,
  2580. FCN_TX_DESCQ_BUF_BASE_ID, FALCON_TXD_ID,
  2581. FCN_TX_DESCQ_EVQ_ID, 0,
  2582. FCN_TX_DESCQ_SIZE, FCN_TX_DESCQ_SIZE_512,
  2583. FCN_TX_DESCQ_TYPE, 0 /* kernel queue */ );
  2584. falcon_write ( efab, &reg, FCN_TX_DESC_PTR_TBL_KER );
  2585. /* Set up RX descriptor ring */
  2586. falcon_create_special_buffer ( efab, efab->rxd, FALCON_RXD_ID );
  2587. EFAB_POPULATE_OWORD_6 ( reg,
  2588. FCN_RX_DESCQ_BUF_BASE_ID, FALCON_RXD_ID,
  2589. FCN_RX_DESCQ_EVQ_ID, 0,
  2590. FCN_RX_DESCQ_SIZE, FCN_RX_DESCQ_SIZE_512,
  2591. FCN_RX_DESCQ_TYPE, 0 /* kernel queue */,
  2592. FCN_RX_DESCQ_JUMBO, 1,
  2593. FCN_RX_DESCQ_EN, 1 );
  2594. falcon_write ( efab, &reg, FCN_RX_DESC_PTR_TBL_KER );
  2595. /* Program INT_ADR_REG_KER */
  2596. EFAB_POPULATE_OWORD_1 ( reg,
  2597. FCN_INT_ADR_KER,
  2598. virt_to_bus ( &efab->int_ker ) );
  2599. falcon_write ( efab, &reg, FCN_INT_ADR_REG_KER );
  2600. udelay ( 1000 );
  2601. /* Register non-volatile storage */
  2602. if ( efab->has_eeprom ) {
  2603. efab->nvo.nvs = &efab->falcon_eeprom.nvs;
  2604. efab->nvo.fragments = falcon_eeprom_fragments;
  2605. if ( nvo_register ( &efab->nvo ) != 0 )
  2606. return 0;
  2607. }
  2608. return 1;
  2609. }
  2610. /** MDIO write */
  2611. static void falcon_mdio_write ( struct efab_nic *efab, int location,
  2612. int value ) {
  2613. int phy_id = efab->port + 2;
  2614. efab_oword_t reg;
  2615. EFAB_TRACE ( "Writing GMII %d register %02x with %04x\n",
  2616. phy_id, location, value );
  2617. /* Check MII not currently being accessed */
  2618. if ( ! falcon_gmii_wait ( efab ) )
  2619. return;
  2620. /* Write the address registers */
  2621. EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_PHY_ADR, 0 /* phy_id ? */ );
  2622. falcon_write ( efab, &reg, FCN_MD_PHY_ADR_REG_KER );
  2623. udelay ( 10 );
  2624. EFAB_POPULATE_OWORD_2 ( reg,
  2625. FCN_MD_PRT_ADR, phy_id,
  2626. FCN_MD_DEV_ADR, location );
  2627. falcon_write ( efab, &reg, FCN_MD_ID_REG_KER );
  2628. udelay ( 10 );
  2629. /* Write data */
  2630. EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_TXD, value );
  2631. falcon_write ( efab, &reg, FCN_MD_TXD_REG_KER );
  2632. udelay ( 10 );
  2633. EFAB_POPULATE_OWORD_2 ( reg,
  2634. FCN_MD_WRC, 1,
  2635. FCN_MD_GC, 1 );
  2636. falcon_write ( efab, &reg, FCN_MD_CS_REG_KER );
  2637. udelay ( 10 );
  2638. /* Wait for data to be written */
  2639. falcon_gmii_wait ( efab );
  2640. }
  2641. /** MDIO read */
  2642. static int falcon_mdio_read ( struct efab_nic *efab, int location ) {
  2643. int phy_id = efab->port + 2;
  2644. efab_oword_t reg;
  2645. int value;
  2646. /* Check MII not currently being accessed */
  2647. if ( ! falcon_gmii_wait ( efab ) )
  2648. return 0xffff;
  2649. /* Write the address registers */
  2650. EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_PHY_ADR, 0 /* phy_id ? */ );
  2651. falcon_write ( efab, &reg, FCN_MD_PHY_ADR_REG_KER );
  2652. udelay ( 10 );
  2653. EFAB_POPULATE_OWORD_2 ( reg,
  2654. FCN_MD_PRT_ADR, phy_id,
  2655. FCN_MD_DEV_ADR, location );
  2656. falcon_write ( efab, &reg, FCN_MD_ID_REG_KER );
  2657. udelay ( 10 );
  2658. /* Request data to be read */
  2659. EFAB_POPULATE_OWORD_2 ( reg,
  2660. FCN_MD_RIC, 1,
  2661. FCN_MD_GC, 1 );
  2662. falcon_write ( efab, &reg, FCN_MD_CS_REG_KER );
  2663. udelay ( 10 );
  2664. /* Wait for data to become available */
  2665. falcon_gmii_wait ( efab );
  2666. /* Read the data */
  2667. falcon_read ( efab, &reg, FCN_MD_RXD_REG_KER );
  2668. value = EFAB_OWORD_FIELD ( reg, FCN_MD_RXD );
  2669. EFAB_TRACE ( "Read from GMII %d register %02x, got %04x\n",
  2670. phy_id, location, value );
  2671. return value;
  2672. }
  2673. static struct efab_operations falcon_operations = {
  2674. .get_membase = falcon_get_membase,
  2675. .reset = falcon_reset,
  2676. .init_nic = falcon_init_nic,
  2677. .read_eeprom = falcon_read_eeprom,
  2678. .build_rx_desc = falcon_build_rx_desc,
  2679. .notify_rx_desc = falcon_notify_rx_desc,
  2680. .build_tx_desc = falcon_build_tx_desc,
  2681. .notify_tx_desc = falcon_notify_tx_desc,
  2682. .fetch_event = falcon_fetch_event,
  2683. .mask_irq = falcon_mask_irq,
  2684. .generate_irq = falcon_generate_irq,
  2685. .mdio_write = falcon_mdio_write,
  2686. .mdio_read = falcon_mdio_read,
  2687. };
  2688. /**************************************************************************
  2689. *
  2690. * Etherfabric abstraction layer
  2691. *
  2692. **************************************************************************
  2693. */
  2694. /**
  2695. * Push RX buffer to RXD ring
  2696. *
  2697. */
  2698. static inline void efab_push_rx_buffer ( struct efab_nic *efab,
  2699. struct efab_rx_buf *rx_buf ) {
  2700. /* Create RX descriptor */
  2701. rx_buf->id = efab->rx_write_ptr;
  2702. efab->op->build_rx_desc ( efab, rx_buf );
  2703. /* Update RX write pointer */
  2704. efab->rx_write_ptr = ( efab->rx_write_ptr + 1 ) % EFAB_RXD_SIZE;
  2705. efab->op->notify_rx_desc ( efab );
  2706. DBG ( "Added RX id %x\n", rx_buf->id );
  2707. }
  2708. /**
  2709. * Push TX buffer to TXD ring
  2710. *
  2711. */
  2712. static inline void efab_push_tx_buffer ( struct efab_nic *efab,
  2713. struct efab_tx_buf *tx_buf ) {
  2714. /* Create TX descriptor */
  2715. tx_buf->id = efab->tx_write_ptr;
  2716. efab->op->build_tx_desc ( efab, tx_buf );
  2717. /* Update TX write pointer */
  2718. efab->tx_write_ptr = ( efab->tx_write_ptr + 1 ) % EFAB_TXD_SIZE;
  2719. efab->op->notify_tx_desc ( efab );
  2720. DBG ( "Added TX id %x\n", tx_buf->id );
  2721. }
  2722. /**
  2723. * Initialise MAC and wait for link up
  2724. *
  2725. */
  2726. static int efab_init_mac ( struct efab_nic *efab ) {
  2727. int count;
  2728. /* This can take several seconds */
  2729. EFAB_LOG ( "Waiting for link.." );
  2730. for ( count=0; count<5; count++ ) {
  2731. putchar ( '.' );
  2732. if ( ! efab->mac_op->init ( efab ) ) {
  2733. EFAB_ERR ( "Failed reinitialising MAC\n" );
  2734. return 0;
  2735. }
  2736. if ( efab->link_up ) {
  2737. /* PHY init printed the message for us */
  2738. return 1;
  2739. }
  2740. EFAB_ERR( "link is down" );
  2741. sleep ( 1 );
  2742. }
  2743. EFAB_ERR ( " timed initialising MAC\n " );
  2744. return 0;
  2745. }
  2746. /**
  2747. * Initialise NIC
  2748. *
  2749. */
  2750. static int efab_init_nic ( struct efab_nic *efab ) {
  2751. int i;
  2752. /* Initialise NIC */
  2753. if ( ! efab->op->init_nic ( efab ) )
  2754. return 0;
  2755. /* Push RX descriptors */
  2756. for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
  2757. efab_push_rx_buffer ( efab, &efab->rx_bufs[i] );
  2758. }
  2759. /* Read MAC address from EEPROM */
  2760. if ( ! efab->op->read_eeprom ( efab ) )
  2761. return 0;
  2762. /* Initialise MAC and wait for link up */
  2763. if ( ! efab_init_mac ( efab ) )
  2764. return 0;
  2765. return 1;
  2766. }
  2767. /**************************************************************************
  2768. *
  2769. * Etherboot interface
  2770. *
  2771. **************************************************************************
  2772. */
  2773. /**************************************************************************
  2774. POLL - Wait for a frame
  2775. ***************************************************************************/
  2776. static int etherfabric_poll ( struct nic *nic, int retrieve ) {
  2777. struct efab_nic *efab = nic->priv_data;
  2778. struct efab_event event;
  2779. static struct efab_rx_buf *rx_buf = NULL;
  2780. int i, drop = 0;
  2781. /* Process the event queue until we hit either a packet
  2782. * received event or an empty event slot.
  2783. */
  2784. while ( ( rx_buf == NULL ) &&
  2785. efab->op->fetch_event ( efab, &event ) ) {
  2786. drop = event.drop;
  2787. if ( event.type == EFAB_EV_TX ) {
  2788. /* TX completed - mark as done */
  2789. DBG ( "TX id %x complete\n",
  2790. efab->tx_buf.id );
  2791. } else if ( event.type == EFAB_EV_RX ) {
  2792. /* RX - find corresponding buffer */
  2793. for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
  2794. if ( efab->rx_bufs[i].id == event.rx_id ) {
  2795. rx_buf = &efab->rx_bufs[i];
  2796. rx_buf->len = event.rx_len;
  2797. DBG ( "RX id %x (len %x) received\n",
  2798. rx_buf->id, rx_buf->len );
  2799. break;
  2800. }
  2801. }
  2802. if ( ! rx_buf ) {
  2803. EFAB_ERR ( "Invalid RX ID %x\n", event.rx_id );
  2804. }
  2805. } else if ( event.type == EFAB_EV_NONE ) {
  2806. DBG ( "Ignorable event\n" );
  2807. } else {
  2808. DBG ( "Unknown event\n" );
  2809. }
  2810. }
  2811. /* If there is no packet, return 0 */
  2812. if ( ! rx_buf )
  2813. return 0;
  2814. /* drop this event if necessary */
  2815. if ( drop ) {
  2816. DBG( "discarding RX event\n" );
  2817. return 0;
  2818. }
  2819. /* If we don't want to retrieve it just yet, return 1 */
  2820. if ( ! retrieve )
  2821. return 1;
  2822. /* There seems to be a hardware race. The event can show up
  2823. * on the event FIFO before the DMA has completed, so we
  2824. * insert a tiny delay. If this proves unreliable, we should
  2825. * switch to using event DMA rather than the event FIFO, since
  2826. * event DMA ordering is guaranteed.
  2827. */
  2828. udelay ( 2 );
  2829. /* Copy packet contents */
  2830. nic->packetlen = rx_buf->len;
  2831. memcpy ( nic->packet, rx_buf->addr, nic->packetlen );
  2832. /* Give this buffer back to the NIC */
  2833. efab_push_rx_buffer ( efab, rx_buf );
  2834. /* Prepare to receive next packet */
  2835. rx_buf = NULL;
  2836. return 1;
  2837. }
  2838. /**************************************************************************
  2839. TRANSMIT - Transmit a frame
  2840. ***************************************************************************/
  2841. static void etherfabric_transmit ( struct nic *nic, const char *dest,
  2842. unsigned int type, unsigned int size,
  2843. const char *data ) {
  2844. struct efab_nic *efab = nic->priv_data;
  2845. unsigned int nstype = htons ( type );
  2846. /* Fill TX buffer, pad to ETH_ZLEN */
  2847. memcpy ( efab->tx_buf.addr, dest, ETH_ALEN );
  2848. memcpy ( efab->tx_buf.addr + ETH_ALEN, nic->node_addr, ETH_ALEN );
  2849. memcpy ( efab->tx_buf.addr + 2 * ETH_ALEN, &nstype, 2 );
  2850. memcpy ( efab->tx_buf.addr + ETH_HLEN, data, size );
  2851. size += ETH_HLEN;
  2852. while ( size < ETH_ZLEN ) {
  2853. efab->tx_buf.addr[size++] = '\0';
  2854. }
  2855. efab->tx_buf.len = size;
  2856. /* Push TX descriptor */
  2857. efab_push_tx_buffer ( efab, &efab->tx_buf );
  2858. /* Allow enough time for the packet to be transmitted. This
  2859. * is a temporary hack until we update to the new driver API.
  2860. */
  2861. udelay ( 20 );
  2862. return;
  2863. }
  2864. /**************************************************************************
  2865. DISABLE - Turn off ethernet interface
  2866. ***************************************************************************/
  2867. static void etherfabric_disable ( struct nic *nic ) {
  2868. struct efab_nic *efab = nic->priv_data;
  2869. efab->op->reset ( efab );
  2870. if ( efab->membase )
  2871. iounmap ( efab->membase );
  2872. }
  2873. /**************************************************************************
  2874. IRQ - handle interrupts
  2875. ***************************************************************************/
  2876. static void etherfabric_irq ( struct nic *nic, irq_action_t action ) {
  2877. struct efab_nic *efab = nic->priv_data;
  2878. switch ( action ) {
  2879. case DISABLE :
  2880. efab->op->mask_irq ( efab, 1 );
  2881. break;
  2882. case ENABLE :
  2883. efab->op->mask_irq ( efab, 0 );
  2884. break;
  2885. case FORCE :
  2886. /* Force NIC to generate a receive interrupt */
  2887. efab->op->generate_irq ( efab );
  2888. break;
  2889. }
  2890. return;
  2891. }
  2892. static struct nic_operations etherfabric_operations = {
  2893. .connect = dummy_connect,
  2894. .poll = etherfabric_poll,
  2895. .transmit = etherfabric_transmit,
  2896. .irq = etherfabric_irq,
  2897. };
  2898. /**************************************************************************
  2899. PROBE - Look for an adapter, this routine's visible to the outside
  2900. ***************************************************************************/
  2901. static int etherfabric_probe ( struct nic *nic, struct pci_device *pci ) {
  2902. static struct efab_nic efab;
  2903. static int nic_port = 1;
  2904. struct efab_buffers *buffers;
  2905. int i;
  2906. /* Set up our private data structure */
  2907. nic->priv_data = &efab;
  2908. memset ( &efab, 0, sizeof ( efab ) );
  2909. memset ( &efab_buffers, 0, sizeof ( efab_buffers ) );
  2910. /* Hook in appropriate operations table. Do this early. */
  2911. if ( pci->device == EF1002_DEVID ) {
  2912. efab.op = &ef1002_operations;
  2913. } else {
  2914. efab.op = &falcon_operations;
  2915. }
  2916. /* Initialise efab data structure */
  2917. efab.pci = pci;
  2918. buffers = ( ( struct efab_buffers * )
  2919. ( ( ( void * ) &efab_buffers ) +
  2920. ( - virt_to_bus ( &efab_buffers ) ) % EFAB_BUF_ALIGN ) );
  2921. efab.eventq = buffers->eventq;
  2922. efab.txd = buffers->txd;
  2923. efab.rxd = buffers->rxd;
  2924. efab.tx_buf.addr = buffers->tx_buf;
  2925. for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
  2926. efab.rx_bufs[i].addr = buffers->rx_buf[i];
  2927. }
  2928. /* Enable the PCI device */
  2929. adjust_pci_device ( pci );
  2930. nic->ioaddr = pci->ioaddr & ~3;
  2931. nic->irqno = pci->irq;
  2932. /* Get iobase/membase */
  2933. efab.iobase = nic->ioaddr;
  2934. efab.op->get_membase ( &efab );
  2935. /* Switch NIC ports (i.e. try different ports on each probe) */
  2936. nic_port = 1 - nic_port;
  2937. efab.port = nic_port;
  2938. /* Initialise hardware */
  2939. if ( ! efab_init_nic ( &efab ) )
  2940. return 0;
  2941. memcpy ( nic->node_addr, efab.mac_addr, ETH_ALEN );
  2942. /* point to NIC specific routines */
  2943. nic->nic_op = &etherfabric_operations;
  2944. return 1;
  2945. }
  2946. static struct pci_device_id etherfabric_nics[] = {
  2947. PCI_ROM(0x1924, 0xC101, "ef1002", "EtherFabric EF1002"),
  2948. PCI_ROM(0x1924, 0x0703, "falcon", "EtherFabric Falcon"),
  2949. };
  2950. PCI_DRIVER ( etherfabric_driver, etherfabric_nics, PCI_NO_CLASS );
  2951. DRIVER ( "EFAB", nic_driver, pci_driver, etherfabric_driver,
  2952. etherfabric_probe, etherfabric_disable );
  2953. /*
  2954. * Local variables:
  2955. * c-basic-offset: 8
  2956. * c-indent-level: 8
  2957. * tab-width: 8
  2958. * End:
  2959. */