Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

etherfabric.c 81KB

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