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

etherfabric.c 79KB

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