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

etherfabric.c 81KB

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