mv_eth.c 112 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418
  1. /*
  2. * (C) Copyright 2003
  3. * Ingo Assmus <ingo.assmus@keymile.com>
  4. *
  5. * based on - Driver for MV64460X ethernet ports
  6. * Copyright (C) 2002 rabeeh@galileo.co.il
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. 3 the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. /*
  27. * mv_eth.c - header file for the polled mode GT ethernet driver
  28. */
  29. #include <common.h>
  30. #include <net.h>
  31. #include <malloc.h>
  32. #include <miiphy.h>
  33. #include "mv_eth.h"
  34. /* enable Debug outputs */
  35. #undef DEBUG_MV_ETH
  36. #ifdef DEBUG_MV_ETH
  37. #define DEBUG
  38. #define DP(x) x
  39. #else
  40. #define DP(x)
  41. #endif
  42. /* PHY DFCDL Registers */
  43. #define ETH_PHY_DFCDL_CONFIG0_REG 0x2100
  44. #define ETH_PHY_DFCDL_CONFIG1_REG 0x2104
  45. #define ETH_PHY_DFCDL_ADDR_REG 0x2110
  46. #define ETH_PHY_DFCDL_DATA0_REG 0x2114
  47. #define PHY_AUTONEGOTIATE_TIMEOUT 4000 /* 4000 ms autonegotiate timeout */
  48. #define PHY_UPDATE_TIMEOUT 10000
  49. #undef MV64460_CHECKSUM_OFFLOAD
  50. /*************************************************************************
  51. **************************************************************************
  52. **************************************************************************
  53. * The first part is the high level driver of the gigE ethernet ports. *
  54. **************************************************************************
  55. **************************************************************************
  56. *************************************************************************/
  57. /* Definition for configuring driver */
  58. /* #define UPDATE_STATS_BY_SOFTWARE */
  59. #undef MV64460_RX_QUEUE_FILL_ON_TASK
  60. /* Constants */
  61. #define MAGIC_ETH_RUNNING 8031971
  62. #define MV64460_INTERNAL_SRAM_SIZE _256K
  63. #define EXTRA_BYTES 32
  64. #define WRAP ETH_HLEN + 2 + 4 + 16
  65. #define BUFFER_MTU dev->mtu + WRAP
  66. #define INT_CAUSE_UNMASK_ALL 0x0007ffff
  67. #define INT_CAUSE_UNMASK_ALL_EXT 0x0011ffff
  68. #ifdef MV64460_RX_FILL_ON_TASK
  69. #define INT_CAUSE_MASK_ALL 0x00000000
  70. #define INT_CAUSE_CHECK_BITS INT_CAUSE_UNMASK_ALL
  71. #define INT_CAUSE_CHECK_BITS_EXT INT_CAUSE_UNMASK_ALL_EXT
  72. #endif
  73. /* Read/Write to/from MV64460 internal registers */
  74. #define MV_REG_READ(offset) my_le32_to_cpu(* (volatile unsigned int *) (INTERNAL_REG_BASE_ADDR + offset))
  75. #define MV_REG_WRITE(offset,data) *(volatile unsigned int *) (INTERNAL_REG_BASE_ADDR + offset) = my_cpu_to_le32 (data)
  76. #define MV_SET_REG_BITS(regOffset,bits) ((*((volatile unsigned int*)((INTERNAL_REG_BASE_ADDR) + (regOffset)))) |= ((unsigned int)my_cpu_to_le32(bits)))
  77. #define MV_RESET_REG_BITS(regOffset,bits) ((*((volatile unsigned int*)((INTERNAL_REG_BASE_ADDR) + (regOffset)))) &= ~((unsigned int)my_cpu_to_le32(bits)))
  78. #define my_cpu_to_le32(x) my_le32_to_cpu((x))
  79. /* Static function declarations */
  80. static int mv64460_eth_real_open (struct eth_device *eth);
  81. static int mv64460_eth_real_stop (struct eth_device *eth);
  82. static struct net_device_stats *mv64460_eth_get_stats (struct eth_device
  83. *dev);
  84. static void eth_port_init_mac_tables (ETH_PORT eth_port_num);
  85. static void mv64460_eth_update_stat (struct eth_device *dev);
  86. bool db64460_eth_start (struct eth_device *eth);
  87. unsigned int eth_read_mib_counter (ETH_PORT eth_port_num,
  88. unsigned int mib_offset);
  89. int mv64460_eth_receive (struct eth_device *dev);
  90. int mv64460_eth_xmit (struct eth_device *, volatile void *packet, int length);
  91. int mv_miiphy_read(char *devname, unsigned char phy_addr,
  92. unsigned char phy_reg, unsigned short *value);
  93. int mv_miiphy_write(char *devname, unsigned char phy_addr,
  94. unsigned char phy_reg, unsigned short value);
  95. int phy_setup_aneg (char *devname, unsigned char addr);
  96. #ifndef UPDATE_STATS_BY_SOFTWARE
  97. static void mv64460_eth_print_stat (struct eth_device *dev);
  98. #endif
  99. /* Processes a received packet */
  100. extern void NetReceive (volatile uchar *, int);
  101. extern unsigned int INTERNAL_REG_BASE_ADDR;
  102. unsigned long my_le32_to_cpu (unsigned long x)
  103. {
  104. return (((x & 0x000000ffU) << 24) |
  105. ((x & 0x0000ff00U) << 8) |
  106. ((x & 0x00ff0000U) >> 8) | ((x & 0xff000000U) >> 24));
  107. }
  108. /*************************************************
  109. *Helper functions - used inside the driver only *
  110. *************************************************/
  111. #ifdef DEBUG_MV_ETH
  112. void print_globals (struct eth_device *dev)
  113. {
  114. printf ("Ethernet PRINT_Globals-Debug function\n");
  115. printf ("Base Address for ETH_PORT_INFO: %08x\n",
  116. (unsigned int) dev->priv);
  117. printf ("Base Address for mv64460_eth_priv: %08x\n",
  118. (unsigned int) &(((ETH_PORT_INFO *) dev->priv)->
  119. port_private));
  120. printf ("GT Internal Base Address: %08x\n",
  121. INTERNAL_REG_BASE_ADDR);
  122. printf ("Base Address for TX-DESCs: %08x Number of allocated Buffers %d\n", (unsigned int) ((ETH_PORT_INFO *) dev->priv)->p_tx_desc_area_base[0], MV64460_TX_QUEUE_SIZE);
  123. printf ("Base Address for RX-DESCs: %08x Number of allocated Buffers %d\n", (unsigned int) ((ETH_PORT_INFO *) dev->priv)->p_rx_desc_area_base[0], MV64460_RX_QUEUE_SIZE);
  124. printf ("Base Address for RX-Buffer: %08x allocated Bytes %d\n",
  125. (unsigned int) ((ETH_PORT_INFO *) dev->priv)->
  126. p_rx_buffer_base[0],
  127. (MV64460_RX_QUEUE_SIZE * MV64460_RX_BUFFER_SIZE) + 32);
  128. printf ("Base Address for TX-Buffer: %08x allocated Bytes %d\n",
  129. (unsigned int) ((ETH_PORT_INFO *) dev->priv)->
  130. p_tx_buffer_base[0],
  131. (MV64460_TX_QUEUE_SIZE * MV64460_TX_BUFFER_SIZE) + 32);
  132. }
  133. #endif
  134. /**********************************************************************
  135. * mv64460_eth_print_phy_status
  136. *
  137. * Prints gigabit ethenret phy status
  138. *
  139. * Input : pointer to ethernet interface network device structure
  140. * Output : N/A
  141. **********************************************************************/
  142. void mv64460_eth_print_phy_status (struct eth_device *dev)
  143. {
  144. struct mv64460_eth_priv *port_private;
  145. unsigned int port_num;
  146. ETH_PORT_INFO *ethernet_private = (ETH_PORT_INFO *) dev->priv;
  147. unsigned int port_status, phy_reg_data;
  148. port_private =
  149. (struct mv64460_eth_priv *) ethernet_private->port_private;
  150. port_num = port_private->port_num;
  151. /* Check Link status on phy */
  152. eth_port_read_smi_reg (port_num, 1, &phy_reg_data);
  153. if (!(phy_reg_data & 0x20)) {
  154. printf ("Ethernet port changed link status to DOWN\n");
  155. } else {
  156. port_status =
  157. MV_REG_READ (MV64460_ETH_PORT_STATUS_REG (port_num));
  158. printf ("Ethernet status port %d: Link up", port_num);
  159. printf (", %s",
  160. (port_status & BIT2) ? "Full Duplex" : "Half Duplex");
  161. if (port_status & BIT4)
  162. printf (", Speed 1 Gbps");
  163. else
  164. printf (", %s",
  165. (port_status & BIT5) ? "Speed 100 Mbps" :
  166. "Speed 10 Mbps");
  167. printf ("\n");
  168. }
  169. }
  170. /**********************************************************************
  171. * u-boot entry functions for mv64460_eth
  172. *
  173. **********************************************************************/
  174. int db64460_eth_probe (struct eth_device *dev)
  175. {
  176. return ((int) db64460_eth_start (dev));
  177. }
  178. int db64460_eth_poll (struct eth_device *dev)
  179. {
  180. return mv64460_eth_receive (dev);
  181. }
  182. int db64460_eth_transmit (struct eth_device *dev, volatile void *packet,
  183. int length)
  184. {
  185. mv64460_eth_xmit (dev, packet, length);
  186. return 0;
  187. }
  188. void db64460_eth_disable (struct eth_device *dev)
  189. {
  190. mv64460_eth_stop (dev);
  191. }
  192. #define DFCDL(write,read) ((write << 6) | read)
  193. unsigned int ethDfcdls[] = { DFCDL(0,0),
  194. DFCDL(1,1),
  195. DFCDL(2,2),
  196. DFCDL(3,3),
  197. DFCDL(4,4),
  198. DFCDL(5,5),
  199. DFCDL(6,6),
  200. DFCDL(7,7),
  201. DFCDL(8,8),
  202. DFCDL(9,9),
  203. DFCDL(10,10),
  204. DFCDL(11,11),
  205. DFCDL(12,12),
  206. DFCDL(13,13),
  207. DFCDL(14,14),
  208. DFCDL(15,15),
  209. DFCDL(16,16),
  210. DFCDL(17,17),
  211. DFCDL(18,18),
  212. DFCDL(19,19),
  213. DFCDL(20,20),
  214. DFCDL(21,21),
  215. DFCDL(22,22),
  216. DFCDL(23,23),
  217. DFCDL(24,24),
  218. DFCDL(25,25),
  219. DFCDL(26,26),
  220. DFCDL(27,27),
  221. DFCDL(28,28),
  222. DFCDL(29,29),
  223. DFCDL(30,30),
  224. DFCDL(31,31),
  225. DFCDL(32,32),
  226. DFCDL(33,33),
  227. DFCDL(34,34),
  228. DFCDL(35,35),
  229. DFCDL(36,36),
  230. DFCDL(37,37),
  231. DFCDL(38,38),
  232. DFCDL(39,39),
  233. DFCDL(40,40),
  234. DFCDL(41,41),
  235. DFCDL(42,42),
  236. DFCDL(43,43),
  237. DFCDL(44,44),
  238. DFCDL(45,45),
  239. DFCDL(46,46),
  240. DFCDL(47,47),
  241. DFCDL(48,48),
  242. DFCDL(49,49),
  243. DFCDL(50,50),
  244. DFCDL(51,51),
  245. DFCDL(52,52),
  246. DFCDL(53,53),
  247. DFCDL(54,54),
  248. DFCDL(55,55),
  249. DFCDL(56,56),
  250. DFCDL(57,57),
  251. DFCDL(58,58),
  252. DFCDL(59,59),
  253. DFCDL(60,60),
  254. DFCDL(61,61),
  255. DFCDL(62,62),
  256. DFCDL(63,63) };
  257. void mv_eth_phy_init(void)
  258. {
  259. int i;
  260. MV_REG_WRITE(ETH_PHY_DFCDL_ADDR_REG, 0);
  261. for (i = 0 ; i < 64; i++) {
  262. MV_REG_WRITE(ETH_PHY_DFCDL_DATA0_REG, ethDfcdls[i]);
  263. }
  264. MV_REG_WRITE(ETH_PHY_DFCDL_CONFIG0_REG,0x300000);
  265. }
  266. void mv6446x_eth_initialize (bd_t * bis)
  267. {
  268. struct eth_device *dev;
  269. ETH_PORT_INFO *ethernet_private;
  270. struct mv64460_eth_priv *port_private;
  271. int devnum, x, temp;
  272. char *s, *e, buf[64];
  273. /* P3M750 only
  274. * Set RGMII clock drives strength
  275. */
  276. temp = MV_REG_READ(0x20A0);
  277. temp |= 0x04000080;
  278. MV_REG_WRITE(0x20A0, temp);
  279. mv_eth_phy_init();
  280. for (devnum = 0; devnum < MV_ETH_DEVS; devnum++) {
  281. dev = calloc (sizeof (*dev), 1);
  282. if (!dev) {
  283. printf ("%s: mv_enet%d allocation failure, %s\n",
  284. __FUNCTION__, devnum, "eth_device structure");
  285. return;
  286. }
  287. /* must be less than NAMESIZE (16) */
  288. sprintf (dev->name, "mv_enet%d", devnum);
  289. #ifdef DEBUG
  290. printf ("Initializing %s\n", dev->name);
  291. #endif
  292. /* Extract the MAC address from the environment */
  293. switch (devnum) {
  294. case 0:
  295. s = "ethaddr";
  296. break;
  297. case 1:
  298. s = "eth1addr";
  299. break;
  300. case 2:
  301. s = "eth2addr";
  302. break;
  303. default: /* this should never happen */
  304. printf ("%s: Invalid device number %d\n",
  305. __FUNCTION__, devnum);
  306. return;
  307. }
  308. temp = getenv_r (s, buf, sizeof (buf));
  309. s = (temp > 0) ? buf : NULL;
  310. #ifdef DEBUG
  311. printf ("Setting MAC %d to %s\n", devnum, s);
  312. #endif
  313. for (x = 0; x < 6; ++x) {
  314. dev->enetaddr[x] = s ? simple_strtoul (s, &e, 16) : 0;
  315. if (s)
  316. s = (*e) ? e + 1 : e;
  317. }
  318. /* ronen - set the MAC addr in the HW */
  319. eth_port_uc_addr_set (devnum, dev->enetaddr, 0);
  320. dev->init = (void *) db64460_eth_probe;
  321. dev->halt = (void *) ethernet_phy_reset;
  322. dev->send = (void *) db64460_eth_transmit;
  323. dev->recv = (void *) db64460_eth_poll;
  324. ethernet_private = calloc (sizeof (*ethernet_private), 1);
  325. dev->priv = (void *)ethernet_private;
  326. if (!ethernet_private) {
  327. printf ("%s: %s allocation failure, %s\n",
  328. __FUNCTION__, dev->name,
  329. "Private Device Structure");
  330. free (dev);
  331. return;
  332. }
  333. /* start with an zeroed ETH_PORT_INFO */
  334. memset (ethernet_private, 0, sizeof (ETH_PORT_INFO));
  335. memcpy (ethernet_private->port_mac_addr, dev->enetaddr, 6);
  336. /* set pointer to memory for stats data structure etc... */
  337. port_private = calloc (sizeof (*ethernet_private), 1);
  338. ethernet_private->port_private = (void *)port_private;
  339. if (!port_private) {
  340. printf ("%s: %s allocation failure, %s\n",
  341. __FUNCTION__, dev->name,
  342. "Port Private Device Structure");
  343. free (ethernet_private);
  344. free (dev);
  345. return;
  346. }
  347. port_private->stats =
  348. calloc (sizeof (struct net_device_stats), 1);
  349. if (!port_private->stats) {
  350. printf ("%s: %s allocation failure, %s\n",
  351. __FUNCTION__, dev->name,
  352. "Net stat Structure");
  353. free (port_private);
  354. free (ethernet_private);
  355. free (dev);
  356. return;
  357. }
  358. memset (ethernet_private->port_private, 0,
  359. sizeof (struct mv64460_eth_priv));
  360. switch (devnum) {
  361. case 0:
  362. ethernet_private->port_num = ETH_0;
  363. break;
  364. case 1:
  365. ethernet_private->port_num = ETH_1;
  366. break;
  367. case 2:
  368. ethernet_private->port_num = ETH_2;
  369. break;
  370. default:
  371. printf ("Invalid device number %d\n", devnum);
  372. break;
  373. };
  374. port_private->port_num = devnum;
  375. /*
  376. * Read MIB counter on the GT in order to reset them,
  377. * then zero all the stats fields in memory
  378. */
  379. mv64460_eth_update_stat (dev);
  380. memset (port_private->stats, 0,
  381. sizeof (struct net_device_stats));
  382. /* Extract the MAC address from the environment */
  383. switch (devnum) {
  384. case 0:
  385. s = "ethaddr";
  386. break;
  387. case 1:
  388. s = "eth1addr";
  389. break;
  390. case 2:
  391. s = "eth2addr";
  392. break;
  393. default: /* this should never happen */
  394. printf ("%s: Invalid device number %d\n",
  395. __FUNCTION__, devnum);
  396. return;
  397. }
  398. temp = getenv_r (s, buf, sizeof (buf));
  399. s = (temp > 0) ? buf : NULL;
  400. #ifdef DEBUG
  401. printf ("Setting MAC %d to %s\n", devnum, s);
  402. #endif
  403. for (x = 0; x < 6; ++x) {
  404. dev->enetaddr[x] = s ? simple_strtoul (s, &e, 16) : 0;
  405. if (s)
  406. s = (*e) ? e + 1 : e;
  407. }
  408. DP (printf ("Allocating descriptor and buffer rings\n"));
  409. ethernet_private->p_rx_desc_area_base[0] =
  410. (ETH_RX_DESC *) memalign (16,
  411. RX_DESC_ALIGNED_SIZE *
  412. MV64460_RX_QUEUE_SIZE + 1);
  413. ethernet_private->p_tx_desc_area_base[0] =
  414. (ETH_TX_DESC *) memalign (16,
  415. TX_DESC_ALIGNED_SIZE *
  416. MV64460_TX_QUEUE_SIZE + 1);
  417. ethernet_private->p_rx_buffer_base[0] =
  418. (char *) memalign (16,
  419. MV64460_RX_QUEUE_SIZE *
  420. MV64460_TX_BUFFER_SIZE + 1);
  421. ethernet_private->p_tx_buffer_base[0] =
  422. (char *) memalign (16,
  423. MV64460_RX_QUEUE_SIZE *
  424. MV64460_TX_BUFFER_SIZE + 1);
  425. #ifdef DEBUG_MV_ETH
  426. /* DEBUG OUTPUT prints adresses of globals */
  427. print_globals (dev);
  428. #endif
  429. eth_register (dev);
  430. miiphy_register(dev->name, mv_miiphy_read, mv_miiphy_write);
  431. }
  432. DP (printf ("%s: exit\n", __FUNCTION__));
  433. }
  434. /**********************************************************************
  435. * mv64460_eth_open
  436. *
  437. * This function is called when openning the network device. The function
  438. * should initialize all the hardware, initialize cyclic Rx/Tx
  439. * descriptors chain and buffers and allocate an IRQ to the network
  440. * device.
  441. *
  442. * Input : a pointer to the network device structure
  443. * / / ronen - changed the output to match net/eth.c needs
  444. * Output : nonzero of success , zero if fails.
  445. * under construction
  446. **********************************************************************/
  447. int mv64460_eth_open (struct eth_device *dev)
  448. {
  449. return (mv64460_eth_real_open (dev));
  450. }
  451. /* Helper function for mv64460_eth_open */
  452. static int mv64460_eth_real_open (struct eth_device *dev)
  453. {
  454. unsigned int queue;
  455. ETH_PORT_INFO *ethernet_private;
  456. struct mv64460_eth_priv *port_private;
  457. unsigned int port_num;
  458. u32 port_status;
  459. ushort reg_short;
  460. int speed;
  461. int duplex;
  462. int i;
  463. int reg;
  464. ethernet_private = (ETH_PORT_INFO *) dev->priv;
  465. /* ronen - when we update the MAC env params we only update dev->enetaddr
  466. see ./net/eth.c eth_set_enetaddr() */
  467. memcpy (ethernet_private->port_mac_addr, dev->enetaddr, 6);
  468. port_private =
  469. (struct mv64460_eth_priv *) ethernet_private->port_private;
  470. port_num = port_private->port_num;
  471. /* Stop RX Queues */
  472. MV_REG_WRITE (MV64460_ETH_RECEIVE_QUEUE_COMMAND_REG (port_num),
  473. 0x0000ff00);
  474. /* Clear the ethernet port interrupts */
  475. MV_REG_WRITE (MV64460_ETH_INTERRUPT_CAUSE_REG (port_num), 0);
  476. MV_REG_WRITE (MV64460_ETH_INTERRUPT_CAUSE_EXTEND_REG (port_num), 0);
  477. /* Unmask RX buffer and TX end interrupt */
  478. MV_REG_WRITE (MV64460_ETH_INTERRUPT_MASK_REG (port_num),
  479. INT_CAUSE_UNMASK_ALL);
  480. /* Unmask phy and link status changes interrupts */
  481. MV_REG_WRITE (MV64460_ETH_INTERRUPT_EXTEND_MASK_REG (port_num),
  482. INT_CAUSE_UNMASK_ALL_EXT);
  483. /* Set phy address of the port */
  484. ethernet_private->port_phy_addr = 0x1 + (port_num << 1);
  485. reg = ethernet_private->port_phy_addr;
  486. /* Activate the DMA channels etc */
  487. eth_port_init (ethernet_private);
  488. /* "Allocate" setup TX rings */
  489. for (queue = 0; queue < MV64460_TX_QUEUE_NUM; queue++) {
  490. unsigned int size;
  491. port_private->tx_ring_size[queue] = MV64460_TX_QUEUE_SIZE;
  492. size = (port_private->tx_ring_size[queue] * TX_DESC_ALIGNED_SIZE); /*size = no of DESCs times DESC-size */
  493. ethernet_private->tx_desc_area_size[queue] = size;
  494. /* first clear desc area completely */
  495. memset ((void *) ethernet_private->p_tx_desc_area_base[queue],
  496. 0, ethernet_private->tx_desc_area_size[queue]);
  497. /* initialize tx desc ring with low level driver */
  498. if (ether_init_tx_desc_ring
  499. (ethernet_private, ETH_Q0,
  500. port_private->tx_ring_size[queue],
  501. MV64460_TX_BUFFER_SIZE /* Each Buffer is 1600 Byte */ ,
  502. (unsigned int) ethernet_private->
  503. p_tx_desc_area_base[queue],
  504. (unsigned int) ethernet_private->
  505. p_tx_buffer_base[queue]) == false)
  506. printf ("### Error initializing TX Ring\n");
  507. }
  508. /* "Allocate" setup RX rings */
  509. for (queue = 0; queue < MV64460_RX_QUEUE_NUM; queue++) {
  510. unsigned int size;
  511. /* Meantime RX Ring are fixed - but must be configurable by user */
  512. port_private->rx_ring_size[queue] = MV64460_RX_QUEUE_SIZE;
  513. size = (port_private->rx_ring_size[queue] *
  514. RX_DESC_ALIGNED_SIZE);
  515. ethernet_private->rx_desc_area_size[queue] = size;
  516. /* first clear desc area completely */
  517. memset ((void *) ethernet_private->p_rx_desc_area_base[queue],
  518. 0, ethernet_private->rx_desc_area_size[queue]);
  519. if ((ether_init_rx_desc_ring
  520. (ethernet_private, ETH_Q0,
  521. port_private->rx_ring_size[queue],
  522. MV64460_RX_BUFFER_SIZE /* Each Buffer is 1600 Byte */ ,
  523. (unsigned int) ethernet_private->
  524. p_rx_desc_area_base[queue],
  525. (unsigned int) ethernet_private->
  526. p_rx_buffer_base[queue])) == false)
  527. printf ("### Error initializing RX Ring\n");
  528. }
  529. eth_port_start (ethernet_private);
  530. /* Set maximum receive buffer to 9700 bytes */
  531. MV_REG_WRITE (MV64460_ETH_PORT_SERIAL_CONTROL_REG (port_num),
  532. (0x5 << 17) |
  533. (MV_REG_READ
  534. (MV64460_ETH_PORT_SERIAL_CONTROL_REG (port_num))
  535. & 0xfff1ffff));
  536. /*
  537. * Set ethernet MTU for leaky bucket mechanism to 0 - this will
  538. * disable the leaky bucket mechanism .
  539. */
  540. MV_REG_WRITE (MV64460_ETH_MAXIMUM_TRANSMIT_UNIT (port_num), 0);
  541. port_status = MV_REG_READ (MV64460_ETH_PORT_STATUS_REG (port_num));
  542. #if defined(CONFIG_PHY_RESET)
  543. /*
  544. * Reset the phy, only if its the first time through
  545. * otherwise, just check the speeds & feeds
  546. */
  547. if (port_private->first_init == 0) {
  548. port_private->first_init = 1;
  549. ethernet_phy_reset (port_num);
  550. /* Start/Restart autonegotiation */
  551. phy_setup_aneg (dev->name, reg);
  552. udelay (1000);
  553. }
  554. #endif /* defined(CONFIG_PHY_RESET) */
  555. miiphy_read (dev->name, reg, PHY_BMSR, &reg_short);
  556. /*
  557. * Wait if PHY is capable of autonegotiation and autonegotiation is not complete
  558. */
  559. if ((reg_short & PHY_BMSR_AUTN_ABLE)
  560. && !(reg_short & PHY_BMSR_AUTN_COMP)) {
  561. puts ("Waiting for PHY auto negotiation to complete");
  562. i = 0;
  563. while (!(reg_short & PHY_BMSR_AUTN_COMP)) {
  564. /*
  565. * Timeout reached ?
  566. */
  567. if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
  568. puts (" TIMEOUT !\n");
  569. break;
  570. }
  571. if ((i++ % 1000) == 0) {
  572. putc ('.');
  573. }
  574. udelay (1000); /* 1 ms */
  575. miiphy_read (dev->name, reg, PHY_BMSR, &reg_short);
  576. }
  577. puts (" done\n");
  578. udelay (500000); /* another 500 ms (results in faster booting) */
  579. }
  580. speed = miiphy_speed (dev->name, reg);
  581. duplex = miiphy_duplex (dev->name, reg);
  582. printf ("ENET Speed is %d Mbps - %s duplex connection\n",
  583. (int) speed, (duplex == HALF) ? "HALF" : "FULL");
  584. port_private->eth_running = MAGIC_ETH_RUNNING;
  585. return 1;
  586. }
  587. static int mv64460_eth_free_tx_rings (struct eth_device *dev)
  588. {
  589. unsigned int queue;
  590. ETH_PORT_INFO *ethernet_private;
  591. struct mv64460_eth_priv *port_private;
  592. unsigned int port_num;
  593. volatile ETH_TX_DESC *p_tx_curr_desc;
  594. ethernet_private = (ETH_PORT_INFO *) dev->priv;
  595. port_private =
  596. (struct mv64460_eth_priv *) ethernet_private->port_private;
  597. port_num = port_private->port_num;
  598. /* Stop Tx Queues */
  599. MV_REG_WRITE (MV64460_ETH_TRANSMIT_QUEUE_COMMAND_REG (port_num),
  600. 0x0000ff00);
  601. /* Free TX rings */
  602. DP (printf ("Clearing previously allocated TX queues... "));
  603. for (queue = 0; queue < MV64460_TX_QUEUE_NUM; queue++) {
  604. /* Free on TX rings */
  605. for (p_tx_curr_desc =
  606. ethernet_private->p_tx_desc_area_base[queue];
  607. ((unsigned int) p_tx_curr_desc <= (unsigned int)
  608. ethernet_private->p_tx_desc_area_base[queue] +
  609. ethernet_private->tx_desc_area_size[queue]);
  610. p_tx_curr_desc =
  611. (ETH_TX_DESC *) ((unsigned int) p_tx_curr_desc +
  612. TX_DESC_ALIGNED_SIZE)) {
  613. /* this is inside for loop */
  614. if (p_tx_curr_desc->return_info != 0) {
  615. p_tx_curr_desc->return_info = 0;
  616. DP (printf ("freed\n"));
  617. }
  618. }
  619. DP (printf ("Done\n"));
  620. }
  621. return 0;
  622. }
  623. static int mv64460_eth_free_rx_rings (struct eth_device *dev)
  624. {
  625. unsigned int queue;
  626. ETH_PORT_INFO *ethernet_private;
  627. struct mv64460_eth_priv *port_private;
  628. unsigned int port_num;
  629. volatile ETH_RX_DESC *p_rx_curr_desc;
  630. ethernet_private = (ETH_PORT_INFO *) dev->priv;
  631. port_private =
  632. (struct mv64460_eth_priv *) ethernet_private->port_private;
  633. port_num = port_private->port_num;
  634. /* Stop RX Queues */
  635. MV_REG_WRITE (MV64460_ETH_RECEIVE_QUEUE_COMMAND_REG (port_num),
  636. 0x0000ff00);
  637. /* Free RX rings */
  638. DP (printf ("Clearing previously allocated RX queues... "));
  639. for (queue = 0; queue < MV64460_RX_QUEUE_NUM; queue++) {
  640. /* Free preallocated skb's on RX rings */
  641. for (p_rx_curr_desc =
  642. ethernet_private->p_rx_desc_area_base[queue];
  643. (((unsigned int) p_rx_curr_desc <
  644. ((unsigned int) ethernet_private->
  645. p_rx_desc_area_base[queue] +
  646. ethernet_private->rx_desc_area_size[queue])));
  647. p_rx_curr_desc =
  648. (ETH_RX_DESC *) ((unsigned int) p_rx_curr_desc +
  649. RX_DESC_ALIGNED_SIZE)) {
  650. if (p_rx_curr_desc->return_info != 0) {
  651. p_rx_curr_desc->return_info = 0;
  652. DP (printf ("freed\n"));
  653. }
  654. }
  655. DP (printf ("Done\n"));
  656. }
  657. return 0;
  658. }
  659. /**********************************************************************
  660. * mv64460_eth_stop
  661. *
  662. * This function is used when closing the network device.
  663. * It updates the hardware,
  664. * release all memory that holds buffers and descriptors and release the IRQ.
  665. * Input : a pointer to the device structure
  666. * Output : zero if success , nonzero if fails
  667. *********************************************************************/
  668. int mv64460_eth_stop (struct eth_device *dev)
  669. {
  670. ETH_PORT_INFO *ethernet_private;
  671. struct mv64460_eth_priv *port_private;
  672. unsigned int port_num;
  673. ethernet_private = (ETH_PORT_INFO *) dev->priv;
  674. port_private =
  675. (struct mv64460_eth_priv *) ethernet_private->port_private;
  676. port_num = port_private->port_num;
  677. /* Disable all gigE address decoder */
  678. MV_REG_WRITE (MV64460_ETH_BASE_ADDR_ENABLE_REG, 0x3f);
  679. DP (printf ("%s Ethernet stop called ... \n", __FUNCTION__));
  680. mv64460_eth_real_stop (dev);
  681. return 0;
  682. };
  683. /* Helper function for mv64460_eth_stop */
  684. static int mv64460_eth_real_stop (struct eth_device *dev)
  685. {
  686. ETH_PORT_INFO *ethernet_private;
  687. struct mv64460_eth_priv *port_private;
  688. unsigned int port_num;
  689. ethernet_private = (ETH_PORT_INFO *) dev->priv;
  690. port_private =
  691. (struct mv64460_eth_priv *) ethernet_private->port_private;
  692. port_num = port_private->port_num;
  693. mv64460_eth_free_tx_rings (dev);
  694. mv64460_eth_free_rx_rings (dev);
  695. eth_port_reset (ethernet_private->port_num);
  696. /* Disable ethernet port interrupts */
  697. MV_REG_WRITE (MV64460_ETH_INTERRUPT_CAUSE_REG (port_num), 0);
  698. MV_REG_WRITE (MV64460_ETH_INTERRUPT_CAUSE_EXTEND_REG (port_num), 0);
  699. /* Mask RX buffer and TX end interrupt */
  700. MV_REG_WRITE (MV64460_ETH_INTERRUPT_MASK_REG (port_num), 0);
  701. /* Mask phy and link status changes interrupts */
  702. MV_REG_WRITE (MV64460_ETH_INTERRUPT_EXTEND_MASK_REG (port_num), 0);
  703. MV_RESET_REG_BITS (MV64460_CPU_INTERRUPT0_MASK_HIGH,
  704. BIT0 << port_num);
  705. /* Print Network statistics */
  706. #ifndef UPDATE_STATS_BY_SOFTWARE
  707. /*
  708. * Print statistics (only if ethernet is running),
  709. * then zero all the stats fields in memory
  710. */
  711. if (port_private->eth_running == MAGIC_ETH_RUNNING) {
  712. port_private->eth_running = 0;
  713. mv64460_eth_print_stat (dev);
  714. }
  715. memset (port_private->stats, 0, sizeof (struct net_device_stats));
  716. #endif
  717. DP (printf ("\nEthernet stopped ... \n"));
  718. return 0;
  719. }
  720. /**********************************************************************
  721. * mv64460_eth_start_xmit
  722. *
  723. * This function is queues a packet in the Tx descriptor for
  724. * required port.
  725. *
  726. * Input : skb - a pointer to socket buffer
  727. * dev - a pointer to the required port
  728. *
  729. * Output : zero upon success
  730. **********************************************************************/
  731. int mv64460_eth_xmit (struct eth_device *dev, volatile void *dataPtr,
  732. int dataSize)
  733. {
  734. ETH_PORT_INFO *ethernet_private;
  735. struct mv64460_eth_priv *port_private;
  736. unsigned int port_num;
  737. PKT_INFO pkt_info;
  738. ETH_FUNC_RET_STATUS status;
  739. struct net_device_stats *stats;
  740. ETH_FUNC_RET_STATUS release_result;
  741. ethernet_private = (ETH_PORT_INFO *) dev->priv;
  742. port_private =
  743. (struct mv64460_eth_priv *) ethernet_private->port_private;
  744. port_num = port_private->port_num;
  745. stats = port_private->stats;
  746. /* Update packet info data structure */
  747. pkt_info.cmd_sts = ETH_TX_FIRST_DESC | ETH_TX_LAST_DESC; /* DMA owned, first last */
  748. pkt_info.byte_cnt = dataSize;
  749. pkt_info.buf_ptr = (unsigned int) dataPtr;
  750. pkt_info.return_info = 0;
  751. status = eth_port_send (ethernet_private, ETH_Q0, &pkt_info);
  752. if ((status == ETH_ERROR) || (status == ETH_QUEUE_FULL)) {
  753. printf ("Error on transmitting packet ..");
  754. if (status == ETH_QUEUE_FULL)
  755. printf ("ETH Queue is full. \n");
  756. if (status == ETH_QUEUE_LAST_RESOURCE)
  757. printf ("ETH Queue: using last available resource. \n");
  758. goto error;
  759. }
  760. /* Update statistics and start of transmittion time */
  761. stats->tx_bytes += dataSize;
  762. stats->tx_packets++;
  763. /* Check if packet(s) is(are) transmitted correctly (release everything) */
  764. do {
  765. release_result =
  766. eth_tx_return_desc (ethernet_private, ETH_Q0,
  767. &pkt_info);
  768. switch (release_result) {
  769. case ETH_OK:
  770. DP (printf ("descriptor released\n"));
  771. if (pkt_info.cmd_sts & BIT0) {
  772. printf ("Error in TX\n");
  773. stats->tx_errors++;
  774. }
  775. break;
  776. case ETH_RETRY:
  777. DP (printf ("transmission still in process\n"));
  778. break;
  779. case ETH_ERROR:
  780. printf ("routine can not access Tx desc ring\n");
  781. break;
  782. case ETH_END_OF_JOB:
  783. DP (printf ("the routine has nothing to release\n"));
  784. break;
  785. default: /* should not happen */
  786. break;
  787. }
  788. } while (release_result == ETH_OK);
  789. return 0; /* success */
  790. error:
  791. return 1; /* Failed - higher layers will free the skb */
  792. }
  793. /**********************************************************************
  794. * mv64460_eth_receive
  795. *
  796. * This function is forward packets that are received from the port's
  797. * queues toward kernel core or FastRoute them to another interface.
  798. *
  799. * Input : dev - a pointer to the required interface
  800. * max - maximum number to receive (0 means unlimted)
  801. *
  802. * Output : number of served packets
  803. **********************************************************************/
  804. int mv64460_eth_receive (struct eth_device *dev)
  805. {
  806. ETH_PORT_INFO *ethernet_private;
  807. struct mv64460_eth_priv *port_private;
  808. unsigned int port_num;
  809. PKT_INFO pkt_info;
  810. struct net_device_stats *stats;
  811. ethernet_private = (ETH_PORT_INFO *) dev->priv;
  812. port_private = (struct mv64460_eth_priv *) ethernet_private->port_private;
  813. port_num = port_private->port_num;
  814. stats = port_private->stats;
  815. while ((eth_port_receive (ethernet_private, ETH_Q0, &pkt_info) == ETH_OK)) {
  816. #ifdef DEBUG_MV_ETH
  817. if (pkt_info.byte_cnt != 0) {
  818. printf ("%s: Received %d byte Packet @ 0x%x\n",
  819. __FUNCTION__, pkt_info.byte_cnt,
  820. pkt_info.buf_ptr);
  821. if(pkt_info.buf_ptr != 0){
  822. for(i=0; i < pkt_info.byte_cnt; i++){
  823. if((i % 4) == 0){
  824. printf("\n0x");
  825. }
  826. printf("%02x", ((char*)pkt_info.buf_ptr)[i]);
  827. }
  828. printf("\n");
  829. }
  830. }
  831. #endif
  832. /* Update statistics. Note byte count includes 4 byte CRC count */
  833. stats->rx_packets++;
  834. stats->rx_bytes += pkt_info.byte_cnt;
  835. /*
  836. * In case received a packet without first / last bits on OR the error
  837. * summary bit is on, the packets needs to be dropeed.
  838. */
  839. if (((pkt_info.
  840. cmd_sts & (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC)) !=
  841. (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC))
  842. || (pkt_info.cmd_sts & ETH_ERROR_SUMMARY)) {
  843. stats->rx_dropped++;
  844. printf ("Received packet spread on multiple descriptors\n");
  845. /* Is this caused by an error ? */
  846. if (pkt_info.cmd_sts & ETH_ERROR_SUMMARY) {
  847. stats->rx_errors++;
  848. }
  849. /* free these descriptors again without forwarding them to the higher layers */
  850. pkt_info.buf_ptr &= ~0x7; /* realign buffer again */
  851. pkt_info.byte_cnt = 0x0000; /* Reset Byte count */
  852. if (eth_rx_return_buff
  853. (ethernet_private, ETH_Q0, &pkt_info) != ETH_OK) {
  854. printf ("Error while returning the RX Desc to Ring\n");
  855. } else {
  856. DP (printf ("RX Desc returned to Ring\n"));
  857. }
  858. /* /free these descriptors again */
  859. } else {
  860. /* !!! call higher layer processing */
  861. #ifdef DEBUG_MV_ETH
  862. printf ("\nNow send it to upper layer protocols (NetReceive) ...\n");
  863. #endif
  864. /* let the upper layer handle the packet */
  865. NetReceive ((uchar *) pkt_info.buf_ptr,
  866. (int) pkt_info.byte_cnt);
  867. /* **************************************************************** */
  868. /* free descriptor */
  869. pkt_info.buf_ptr &= ~0x7; /* realign buffer again */
  870. pkt_info.byte_cnt = 0x0000; /* Reset Byte count */
  871. DP (printf ("RX: pkt_info.buf_ptr = %x\n", pkt_info.buf_ptr));
  872. if (eth_rx_return_buff
  873. (ethernet_private, ETH_Q0, &pkt_info) != ETH_OK) {
  874. printf ("Error while returning the RX Desc to Ring\n");
  875. } else {
  876. DP (printf ("RX: Desc returned to Ring\n"));
  877. }
  878. /* **************************************************************** */
  879. }
  880. }
  881. mv64460_eth_get_stats (dev); /* update statistics */
  882. return 1;
  883. }
  884. /**********************************************************************
  885. * mv64460_eth_get_stats
  886. *
  887. * Returns a pointer to the interface statistics.
  888. *
  889. * Input : dev - a pointer to the required interface
  890. *
  891. * Output : a pointer to the interface's statistics
  892. **********************************************************************/
  893. static struct net_device_stats *mv64460_eth_get_stats (struct eth_device *dev)
  894. {
  895. ETH_PORT_INFO *ethernet_private;
  896. struct mv64460_eth_priv *port_private;
  897. unsigned int port_num;
  898. ethernet_private = (ETH_PORT_INFO *) dev->priv;
  899. port_private =
  900. (struct mv64460_eth_priv *) ethernet_private->port_private;
  901. port_num = port_private->port_num;
  902. mv64460_eth_update_stat (dev);
  903. return port_private->stats;
  904. }
  905. /**********************************************************************
  906. * mv64460_eth_update_stat
  907. *
  908. * Update the statistics structure in the private data structure
  909. *
  910. * Input : pointer to ethernet interface network device structure
  911. * Output : N/A
  912. **********************************************************************/
  913. static void mv64460_eth_update_stat (struct eth_device *dev)
  914. {
  915. ETH_PORT_INFO *ethernet_private;
  916. struct mv64460_eth_priv *port_private;
  917. struct net_device_stats *stats;
  918. unsigned int port_num;
  919. volatile unsigned int dummy;
  920. ethernet_private = (ETH_PORT_INFO *) dev->priv;
  921. port_private =
  922. (struct mv64460_eth_priv *) ethernet_private->port_private;
  923. port_num = port_private->port_num;
  924. stats = port_private->stats;
  925. /* These are false updates */
  926. stats->rx_packets += (unsigned long)
  927. eth_read_mib_counter (ethernet_private->port_num,
  928. ETH_MIB_GOOD_FRAMES_RECEIVED);
  929. stats->tx_packets += (unsigned long)
  930. eth_read_mib_counter (ethernet_private->port_num,
  931. ETH_MIB_GOOD_FRAMES_SENT);
  932. stats->rx_bytes += (unsigned long)
  933. eth_read_mib_counter (ethernet_private->port_num,
  934. ETH_MIB_GOOD_OCTETS_RECEIVED_LOW);
  935. /*
  936. * Ideally this should be as follows -
  937. *
  938. * stats->rx_bytes += stats->rx_bytes +
  939. * ((unsigned long) ethReadMibCounter (ethernet_private->port_num ,
  940. * ETH_MIB_GOOD_OCTETS_RECEIVED_HIGH) << 32);
  941. *
  942. * But the unsigned long in PowerPC and MIPS are 32bit. So the next read
  943. * is just a dummy read for proper work of the GigE port
  944. */
  945. dummy = eth_read_mib_counter (ethernet_private->port_num,
  946. ETH_MIB_GOOD_OCTETS_RECEIVED_HIGH);
  947. stats->tx_bytes += (unsigned long)
  948. eth_read_mib_counter (ethernet_private->port_num,
  949. ETH_MIB_GOOD_OCTETS_SENT_LOW);
  950. dummy = eth_read_mib_counter (ethernet_private->port_num,
  951. ETH_MIB_GOOD_OCTETS_SENT_HIGH);
  952. stats->rx_errors += (unsigned long)
  953. eth_read_mib_counter (ethernet_private->port_num,
  954. ETH_MIB_MAC_RECEIVE_ERROR);
  955. /* Rx dropped is for received packet with CRC error */
  956. stats->rx_dropped +=
  957. (unsigned long) eth_read_mib_counter (ethernet_private->
  958. port_num,
  959. ETH_MIB_BAD_CRC_EVENT);
  960. stats->multicast += (unsigned long)
  961. eth_read_mib_counter (ethernet_private->port_num,
  962. ETH_MIB_MULTICAST_FRAMES_RECEIVED);
  963. stats->collisions +=
  964. (unsigned long) eth_read_mib_counter (ethernet_private->
  965. port_num,
  966. ETH_MIB_COLLISION) +
  967. (unsigned long) eth_read_mib_counter (ethernet_private->
  968. port_num,
  969. ETH_MIB_LATE_COLLISION);
  970. /* detailed rx errors */
  971. stats->rx_length_errors +=
  972. (unsigned long) eth_read_mib_counter (ethernet_private->
  973. port_num,
  974. ETH_MIB_UNDERSIZE_RECEIVED)
  975. +
  976. (unsigned long) eth_read_mib_counter (ethernet_private->
  977. port_num,
  978. ETH_MIB_OVERSIZE_RECEIVED);
  979. /* detailed tx errors */
  980. }
  981. #ifndef UPDATE_STATS_BY_SOFTWARE
  982. /**********************************************************************
  983. * mv64460_eth_print_stat
  984. *
  985. * Update the statistics structure in the private data structure
  986. *
  987. * Input : pointer to ethernet interface network device structure
  988. * Output : N/A
  989. **********************************************************************/
  990. static void mv64460_eth_print_stat (struct eth_device *dev)
  991. {
  992. ETH_PORT_INFO *ethernet_private;
  993. struct mv64460_eth_priv *port_private;
  994. struct net_device_stats *stats;
  995. unsigned int port_num;
  996. ethernet_private = (ETH_PORT_INFO *) dev->priv;
  997. port_private =
  998. (struct mv64460_eth_priv *) ethernet_private->port_private;
  999. port_num = port_private->port_num;
  1000. stats = port_private->stats;
  1001. /* These are false updates */
  1002. printf ("\n### Network statistics: ###\n");
  1003. printf ("--------------------------\n");
  1004. printf (" Packets received: %ld\n", stats->rx_packets);
  1005. printf (" Packets send: %ld\n", stats->tx_packets);
  1006. printf (" Received bytes: %ld\n", stats->rx_bytes);
  1007. printf (" Send bytes: %ld\n", stats->tx_bytes);
  1008. if (stats->rx_errors != 0)
  1009. printf (" Rx Errors: %ld\n",
  1010. stats->rx_errors);
  1011. if (stats->rx_dropped != 0)
  1012. printf (" Rx dropped (CRC Errors): %ld\n",
  1013. stats->rx_dropped);
  1014. if (stats->multicast != 0)
  1015. printf (" Rx mulicast frames: %ld\n",
  1016. stats->multicast);
  1017. if (stats->collisions != 0)
  1018. printf (" No. of collisions: %ld\n",
  1019. stats->collisions);
  1020. if (stats->rx_length_errors != 0)
  1021. printf (" Rx length errors: %ld\n",
  1022. stats->rx_length_errors);
  1023. }
  1024. #endif
  1025. /**************************************************************************
  1026. *network_start - Network Kick Off Routine UBoot
  1027. *Inputs :
  1028. *Outputs :
  1029. **************************************************************************/
  1030. bool db64460_eth_start (struct eth_device *dev)
  1031. {
  1032. return (mv64460_eth_open (dev)); /* calls real open */
  1033. }
  1034. /*************************************************************************
  1035. **************************************************************************
  1036. **************************************************************************
  1037. * The second part is the low level driver of the gigE ethernet ports. *
  1038. **************************************************************************
  1039. **************************************************************************
  1040. *************************************************************************/
  1041. /*
  1042. * based on Linux code
  1043. * arch/ppc/galileo/EVB64460/mv64460_eth.c - Driver for MV64460X ethernet ports
  1044. * Copyright (C) 2002 rabeeh@galileo.co.il
  1045. * This program is free software; you can redistribute it and/or
  1046. * modify it under the terms of the GNU General Public License
  1047. * as published by the Free Software Foundation; either version 2
  1048. * of the License, or (at your option) any later version.
  1049. * This program is distributed in the hope that it will be useful,
  1050. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1051. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1052. * GNU General Public License for more details.
  1053. * You should have received a copy of the GNU General Public License
  1054. * along with this program; if not, write to the Free Software
  1055. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  1056. *
  1057. */
  1058. /********************************************************************************
  1059. * Marvell's Gigabit Ethernet controller low level driver
  1060. *
  1061. * DESCRIPTION:
  1062. * This file introduce low level API to Marvell's Gigabit Ethernet
  1063. * controller. This Gigabit Ethernet Controller driver API controls
  1064. * 1) Operations (i.e. port init, start, reset etc').
  1065. * 2) Data flow (i.e. port send, receive etc').
  1066. * Each Gigabit Ethernet port is controlled via ETH_PORT_INFO
  1067. * struct.
  1068. * This struct includes user configuration information as well as
  1069. * driver internal data needed for its operations.
  1070. *
  1071. * Supported Features:
  1072. * - This low level driver is OS independent. Allocating memory for
  1073. * the descriptor rings and buffers are not within the scope of
  1074. * this driver.
  1075. * - The user is free from Rx/Tx queue managing.
  1076. * - This low level driver introduce functionality API that enable
  1077. * the to operate Marvell's Gigabit Ethernet Controller in a
  1078. * convenient way.
  1079. * - Simple Gigabit Ethernet port operation API.
  1080. * - Simple Gigabit Ethernet port data flow API.
  1081. * - Data flow and operation API support per queue functionality.
  1082. * - Support cached descriptors for better performance.
  1083. * - Enable access to all four DRAM banks and internal SRAM memory
  1084. * spaces.
  1085. * - PHY access and control API.
  1086. * - Port control register configuration API.
  1087. * - Full control over Unicast and Multicast MAC configurations.
  1088. *
  1089. * Operation flow:
  1090. *
  1091. * Initialization phase
  1092. * This phase complete the initialization of the ETH_PORT_INFO
  1093. * struct.
  1094. * User information regarding port configuration has to be set
  1095. * prior to calling the port initialization routine. For example,
  1096. * the user has to assign the port_phy_addr field which is board
  1097. * depended parameter.
  1098. * In this phase any port Tx/Rx activity is halted, MIB counters
  1099. * are cleared, PHY address is set according to user parameter and
  1100. * access to DRAM and internal SRAM memory spaces.
  1101. *
  1102. * Driver ring initialization
  1103. * Allocating memory for the descriptor rings and buffers is not
  1104. * within the scope of this driver. Thus, the user is required to
  1105. * allocate memory for the descriptors ring and buffers. Those
  1106. * memory parameters are used by the Rx and Tx ring initialization
  1107. * routines in order to curve the descriptor linked list in a form
  1108. * of a ring.
  1109. * Note: Pay special attention to alignment issues when using
  1110. * cached descriptors/buffers. In this phase the driver store
  1111. * information in the ETH_PORT_INFO struct regarding each queue
  1112. * ring.
  1113. *
  1114. * Driver start
  1115. * This phase prepares the Ethernet port for Rx and Tx activity.
  1116. * It uses the information stored in the ETH_PORT_INFO struct to
  1117. * initialize the various port registers.
  1118. *
  1119. * Data flow:
  1120. * All packet references to/from the driver are done using PKT_INFO
  1121. * struct.
  1122. * This struct is a unified struct used with Rx and Tx operations.
  1123. * This way the user is not required to be familiar with neither
  1124. * Tx nor Rx descriptors structures.
  1125. * The driver's descriptors rings are management by indexes.
  1126. * Those indexes controls the ring resources and used to indicate
  1127. * a SW resource error:
  1128. * 'current'
  1129. * This index points to the current available resource for use. For
  1130. * example in Rx process this index will point to the descriptor
  1131. * that will be passed to the user upon calling the receive routine.
  1132. * In Tx process, this index will point to the descriptor
  1133. * that will be assigned with the user packet info and transmitted.
  1134. * 'used'
  1135. * This index points to the descriptor that need to restore its
  1136. * resources. For example in Rx process, using the Rx buffer return
  1137. * API will attach the buffer returned in packet info to the
  1138. * descriptor pointed by 'used'. In Tx process, using the Tx
  1139. * descriptor return will merely return the user packet info with
  1140. * the command status of the transmitted buffer pointed by the
  1141. * 'used' index. Nevertheless, it is essential to use this routine
  1142. * to update the 'used' index.
  1143. * 'first'
  1144. * This index supports Tx Scatter-Gather. It points to the first
  1145. * descriptor of a packet assembled of multiple buffers. For example
  1146. * when in middle of Such packet we have a Tx resource error the
  1147. * 'curr' index get the value of 'first' to indicate that the ring
  1148. * returned to its state before trying to transmit this packet.
  1149. *
  1150. * Receive operation:
  1151. * The eth_port_receive API set the packet information struct,
  1152. * passed by the caller, with received information from the
  1153. * 'current' SDMA descriptor.
  1154. * It is the user responsibility to return this resource back
  1155. * to the Rx descriptor ring to enable the reuse of this source.
  1156. * Return Rx resource is done using the eth_rx_return_buff API.
  1157. *
  1158. * Transmit operation:
  1159. * The eth_port_send API supports Scatter-Gather which enables to
  1160. * send a packet spanned over multiple buffers. This means that
  1161. * for each packet info structure given by the user and put into
  1162. * the Tx descriptors ring, will be transmitted only if the 'LAST'
  1163. * bit will be set in the packet info command status field. This
  1164. * API also consider restriction regarding buffer alignments and
  1165. * sizes.
  1166. * The user must return a Tx resource after ensuring the buffer
  1167. * has been transmitted to enable the Tx ring indexes to update.
  1168. *
  1169. * BOARD LAYOUT
  1170. * This device is on-board. No jumper diagram is necessary.
  1171. *
  1172. * EXTERNAL INTERFACE
  1173. *
  1174. * Prior to calling the initialization routine eth_port_init() the user
  1175. * must set the following fields under ETH_PORT_INFO struct:
  1176. * port_num User Ethernet port number.
  1177. * port_phy_addr User PHY address of Ethernet port.
  1178. * port_mac_addr[6] User defined port MAC address.
  1179. * port_config User port configuration value.
  1180. * port_config_extend User port config extend value.
  1181. * port_sdma_config User port SDMA config value.
  1182. * port_serial_control User port serial control value.
  1183. * *port_virt_to_phys () User function to cast virtual addr to CPU bus addr.
  1184. * *port_private User scratch pad for user specific data structures.
  1185. *
  1186. * This driver introduce a set of default values:
  1187. * PORT_CONFIG_VALUE Default port configuration value
  1188. * PORT_CONFIG_EXTEND_VALUE Default port extend configuration value
  1189. * PORT_SDMA_CONFIG_VALUE Default sdma control value
  1190. * PORT_SERIAL_CONTROL_VALUE Default port serial control value
  1191. *
  1192. * This driver data flow is done using the PKT_INFO struct which is
  1193. * a unified struct for Rx and Tx operations:
  1194. * byte_cnt Tx/Rx descriptor buffer byte count.
  1195. * l4i_chk CPU provided TCP Checksum. For Tx operation only.
  1196. * cmd_sts Tx/Rx descriptor command status.
  1197. * buf_ptr Tx/Rx descriptor buffer pointer.
  1198. * return_info Tx/Rx user resource return information.
  1199. *
  1200. *
  1201. * EXTERNAL SUPPORT REQUIREMENTS
  1202. *
  1203. * This driver requires the following external support:
  1204. *
  1205. * D_CACHE_FLUSH_LINE (address, address offset)
  1206. *
  1207. * This macro applies assembly code to flush and invalidate cache
  1208. * line.
  1209. * address - address base.
  1210. * address offset - address offset
  1211. *
  1212. *
  1213. * CPU_PIPE_FLUSH
  1214. *
  1215. * This macro applies assembly code to flush the CPU pipeline.
  1216. *
  1217. *******************************************************************************/
  1218. /* includes */
  1219. /* defines */
  1220. /* SDMA command macros */
  1221. #define ETH_ENABLE_TX_QUEUE(tx_queue, eth_port) \
  1222. MV_REG_WRITE(MV64460_ETH_TRANSMIT_QUEUE_COMMAND_REG(eth_port), (1 << tx_queue))
  1223. #define ETH_DISABLE_TX_QUEUE(tx_queue, eth_port) \
  1224. MV_REG_WRITE(MV64460_ETH_TRANSMIT_QUEUE_COMMAND_REG(eth_port),\
  1225. (1 << (8 + tx_queue)))
  1226. #define ETH_ENABLE_RX_QUEUE(rx_queue, eth_port) \
  1227. MV_REG_WRITE(MV64460_ETH_RECEIVE_QUEUE_COMMAND_REG(eth_port), (1 << rx_queue))
  1228. #define ETH_DISABLE_RX_QUEUE(rx_queue, eth_port) \
  1229. MV_REG_WRITE(MV64460_ETH_RECEIVE_QUEUE_COMMAND_REG(eth_port), (1 << (8 + rx_queue)))
  1230. #define CURR_RFD_GET(p_curr_desc, queue) \
  1231. ((p_curr_desc) = p_eth_port_ctrl->p_rx_curr_desc_q[queue])
  1232. #define CURR_RFD_SET(p_curr_desc, queue) \
  1233. (p_eth_port_ctrl->p_rx_curr_desc_q[queue] = (p_curr_desc))
  1234. #define USED_RFD_GET(p_used_desc, queue) \
  1235. ((p_used_desc) = p_eth_port_ctrl->p_rx_used_desc_q[queue])
  1236. #define USED_RFD_SET(p_used_desc, queue)\
  1237. (p_eth_port_ctrl->p_rx_used_desc_q[queue] = (p_used_desc))
  1238. #define CURR_TFD_GET(p_curr_desc, queue) \
  1239. ((p_curr_desc) = p_eth_port_ctrl->p_tx_curr_desc_q[queue])
  1240. #define CURR_TFD_SET(p_curr_desc, queue) \
  1241. (p_eth_port_ctrl->p_tx_curr_desc_q[queue] = (p_curr_desc))
  1242. #define USED_TFD_GET(p_used_desc, queue) \
  1243. ((p_used_desc) = p_eth_port_ctrl->p_tx_used_desc_q[queue])
  1244. #define USED_TFD_SET(p_used_desc, queue) \
  1245. (p_eth_port_ctrl->p_tx_used_desc_q[queue] = (p_used_desc))
  1246. #define FIRST_TFD_GET(p_first_desc, queue) \
  1247. ((p_first_desc) = p_eth_port_ctrl->p_tx_first_desc_q[queue])
  1248. #define FIRST_TFD_SET(p_first_desc, queue) \
  1249. (p_eth_port_ctrl->p_tx_first_desc_q[queue] = (p_first_desc))
  1250. /* Macros that save access to desc in order to find next desc pointer */
  1251. #define RX_NEXT_DESC_PTR(p_rx_desc, queue) (ETH_RX_DESC*)(((((unsigned int)p_rx_desc - (unsigned int)p_eth_port_ctrl->p_rx_desc_area_base[queue]) + RX_DESC_ALIGNED_SIZE) % p_eth_port_ctrl->rx_desc_area_size[queue]) + (unsigned int)p_eth_port_ctrl->p_rx_desc_area_base[queue])
  1252. #define TX_NEXT_DESC_PTR(p_tx_desc, queue) (ETH_TX_DESC*)(((((unsigned int)p_tx_desc - (unsigned int)p_eth_port_ctrl->p_tx_desc_area_base[queue]) + TX_DESC_ALIGNED_SIZE) % p_eth_port_ctrl->tx_desc_area_size[queue]) + (unsigned int)p_eth_port_ctrl->p_tx_desc_area_base[queue])
  1253. #define LINK_UP_TIMEOUT 100000
  1254. #define PHY_BUSY_TIMEOUT 10000000
  1255. /* locals */
  1256. /* PHY routines */
  1257. static void ethernet_phy_set (ETH_PORT eth_port_num, int phy_addr);
  1258. static int ethernet_phy_get (ETH_PORT eth_port_num);
  1259. /* Ethernet Port routines */
  1260. static void eth_set_access_control (ETH_PORT eth_port_num,
  1261. ETH_WIN_PARAM * param);
  1262. static bool eth_port_uc_addr (ETH_PORT eth_port_num, unsigned char uc_nibble,
  1263. ETH_QUEUE queue, int option);
  1264. #if 0 /* FIXME */
  1265. static bool eth_port_smc_addr (ETH_PORT eth_port_num,
  1266. unsigned char mc_byte,
  1267. ETH_QUEUE queue, int option);
  1268. static bool eth_port_omc_addr (ETH_PORT eth_port_num,
  1269. unsigned char crc8,
  1270. ETH_QUEUE queue, int option);
  1271. #endif
  1272. static void eth_b_copy (unsigned int src_addr, unsigned int dst_addr,
  1273. int byte_count);
  1274. void eth_dbg (ETH_PORT_INFO * p_eth_port_ctrl);
  1275. typedef enum _memory_bank { BANK0, BANK1, BANK2, BANK3 } MEMORY_BANK;
  1276. u32 mv_get_dram_bank_base_addr (MEMORY_BANK bank)
  1277. {
  1278. u32 result = 0;
  1279. u32 enable = MV_REG_READ (MV64460_BASE_ADDR_ENABLE);
  1280. if (enable & (1 << bank))
  1281. return 0;
  1282. if (bank == BANK0)
  1283. result = MV_REG_READ (MV64460_CS_0_BASE_ADDR);
  1284. if (bank == BANK1)
  1285. result = MV_REG_READ (MV64460_CS_1_BASE_ADDR);
  1286. if (bank == BANK2)
  1287. result = MV_REG_READ (MV64460_CS_2_BASE_ADDR);
  1288. if (bank == BANK3)
  1289. result = MV_REG_READ (MV64460_CS_3_BASE_ADDR);
  1290. result &= 0x0000ffff;
  1291. result = result << 16;
  1292. return result;
  1293. }
  1294. u32 mv_get_dram_bank_size (MEMORY_BANK bank)
  1295. {
  1296. u32 result = 0;
  1297. u32 enable = MV_REG_READ (MV64460_BASE_ADDR_ENABLE);
  1298. if (enable & (1 << bank))
  1299. return 0;
  1300. if (bank == BANK0)
  1301. result = MV_REG_READ (MV64460_CS_0_SIZE);
  1302. if (bank == BANK1)
  1303. result = MV_REG_READ (MV64460_CS_1_SIZE);
  1304. if (bank == BANK2)
  1305. result = MV_REG_READ (MV64460_CS_2_SIZE);
  1306. if (bank == BANK3)
  1307. result = MV_REG_READ (MV64460_CS_3_SIZE);
  1308. result += 1;
  1309. result &= 0x0000ffff;
  1310. result = result << 16;
  1311. return result;
  1312. }
  1313. u32 mv_get_internal_sram_base (void)
  1314. {
  1315. u32 result;
  1316. result = MV_REG_READ (MV64460_INTEGRATED_SRAM_BASE_ADDR);
  1317. result &= 0x0000ffff;
  1318. result = result << 16;
  1319. return result;
  1320. }
  1321. /*******************************************************************************
  1322. * eth_port_init - Initialize the Ethernet port driver
  1323. *
  1324. * DESCRIPTION:
  1325. * This function prepares the ethernet port to start its activity:
  1326. * 1) Completes the ethernet port driver struct initialization toward port
  1327. * start routine.
  1328. * 2) Resets the device to a quiescent state in case of warm reboot.
  1329. * 3) Enable SDMA access to all four DRAM banks as well as internal SRAM.
  1330. * 4) Clean MAC tables. The reset status of those tables is unknown.
  1331. * 5) Set PHY address.
  1332. * Note: Call this routine prior to eth_port_start routine and after setting
  1333. * user values in the user fields of Ethernet port control struct (i.e.
  1334. * port_phy_addr).
  1335. *
  1336. * INPUT:
  1337. * ETH_PORT_INFO *p_eth_port_ctrl Ethernet port control struct
  1338. *
  1339. * OUTPUT:
  1340. * See description.
  1341. *
  1342. * RETURN:
  1343. * None.
  1344. *
  1345. *******************************************************************************/
  1346. static void eth_port_init (ETH_PORT_INFO * p_eth_port_ctrl)
  1347. {
  1348. int queue;
  1349. ETH_WIN_PARAM win_param;
  1350. p_eth_port_ctrl->port_config = PORT_CONFIG_VALUE;
  1351. p_eth_port_ctrl->port_config_extend = PORT_CONFIG_EXTEND_VALUE;
  1352. p_eth_port_ctrl->port_sdma_config = PORT_SDMA_CONFIG_VALUE;
  1353. p_eth_port_ctrl->port_serial_control = PORT_SERIAL_CONTROL_VALUE;
  1354. p_eth_port_ctrl->port_rx_queue_command = 0;
  1355. p_eth_port_ctrl->port_tx_queue_command = 0;
  1356. /* Zero out SW structs */
  1357. for (queue = 0; queue < MAX_RX_QUEUE_NUM; queue++) {
  1358. CURR_RFD_SET ((ETH_RX_DESC *) 0x00000000, queue);
  1359. USED_RFD_SET ((ETH_RX_DESC *) 0x00000000, queue);
  1360. p_eth_port_ctrl->rx_resource_err[queue] = false;
  1361. }
  1362. for (queue = 0; queue < MAX_TX_QUEUE_NUM; queue++) {
  1363. CURR_TFD_SET ((ETH_TX_DESC *) 0x00000000, queue);
  1364. USED_TFD_SET ((ETH_TX_DESC *) 0x00000000, queue);
  1365. FIRST_TFD_SET ((ETH_TX_DESC *) 0x00000000, queue);
  1366. p_eth_port_ctrl->tx_resource_err[queue] = false;
  1367. }
  1368. eth_port_reset (p_eth_port_ctrl->port_num);
  1369. /* Set access parameters for DRAM bank 0 */
  1370. win_param.win = ETH_WIN0; /* Use Ethernet window 0 */
  1371. win_param.target = ETH_TARGET_DRAM; /* Window target - DDR */
  1372. win_param.attributes = EBAR_ATTR_DRAM_CS0; /* Enable DRAM bank */
  1373. #ifndef CONFIG_NOT_COHERENT_CACHE
  1374. win_param.attributes |= EBAR_ATTR_DRAM_CACHE_COHERENCY_WB;
  1375. #endif
  1376. win_param.high_addr = 0;
  1377. /* Get bank base */
  1378. win_param.base_addr = mv_get_dram_bank_base_addr (BANK0);
  1379. win_param.size = mv_get_dram_bank_size (BANK0); /* Get bank size */
  1380. if (win_param.size == 0)
  1381. win_param.enable = 0;
  1382. else
  1383. win_param.enable = 1; /* Enable the access */
  1384. win_param.access_ctrl = EWIN_ACCESS_FULL; /* Enable full access */
  1385. /* Set the access control for address window (EPAPR) READ & WRITE */
  1386. eth_set_access_control (p_eth_port_ctrl->port_num, &win_param);
  1387. /* Set access parameters for DRAM bank 1 */
  1388. win_param.win = ETH_WIN1; /* Use Ethernet window 1 */
  1389. win_param.target = ETH_TARGET_DRAM; /* Window target - DDR */
  1390. win_param.attributes = EBAR_ATTR_DRAM_CS1; /* Enable DRAM bank */
  1391. #ifndef CONFIG_NOT_COHERENT_CACHE
  1392. win_param.attributes |= EBAR_ATTR_DRAM_CACHE_COHERENCY_WB;
  1393. #endif
  1394. win_param.high_addr = 0;
  1395. /* Get bank base */
  1396. win_param.base_addr = mv_get_dram_bank_base_addr (BANK1);
  1397. win_param.size = mv_get_dram_bank_size (BANK1); /* Get bank size */
  1398. if (win_param.size == 0)
  1399. win_param.enable = 0;
  1400. else
  1401. win_param.enable = 1; /* Enable the access */
  1402. win_param.access_ctrl = EWIN_ACCESS_FULL; /* Enable full access */
  1403. /* Set the access control for address window (EPAPR) READ & WRITE */
  1404. eth_set_access_control (p_eth_port_ctrl->port_num, &win_param);
  1405. /* Set access parameters for DRAM bank 2 */
  1406. win_param.win = ETH_WIN2; /* Use Ethernet window 2 */
  1407. win_param.target = ETH_TARGET_DRAM; /* Window target - DDR */
  1408. win_param.attributes = EBAR_ATTR_DRAM_CS2; /* Enable DRAM bank */
  1409. #ifndef CONFIG_NOT_COHERENT_CACHE
  1410. win_param.attributes |= EBAR_ATTR_DRAM_CACHE_COHERENCY_WB;
  1411. #endif
  1412. win_param.high_addr = 0;
  1413. /* Get bank base */
  1414. win_param.base_addr = mv_get_dram_bank_base_addr (BANK2);
  1415. win_param.size = mv_get_dram_bank_size (BANK2); /* Get bank size */
  1416. if (win_param.size == 0)
  1417. win_param.enable = 0;
  1418. else
  1419. win_param.enable = 1; /* Enable the access */
  1420. win_param.access_ctrl = EWIN_ACCESS_FULL; /* Enable full access */
  1421. /* Set the access control for address window (EPAPR) READ & WRITE */
  1422. eth_set_access_control (p_eth_port_ctrl->port_num, &win_param);
  1423. /* Set access parameters for DRAM bank 3 */
  1424. win_param.win = ETH_WIN3; /* Use Ethernet window 3 */
  1425. win_param.target = ETH_TARGET_DRAM; /* Window target - DDR */
  1426. win_param.attributes = EBAR_ATTR_DRAM_CS3; /* Enable DRAM bank */
  1427. #ifndef CONFIG_NOT_COHERENT_CACHE
  1428. win_param.attributes |= EBAR_ATTR_DRAM_CACHE_COHERENCY_WB;
  1429. #endif
  1430. win_param.high_addr = 0;
  1431. /* Get bank base */
  1432. win_param.base_addr = mv_get_dram_bank_base_addr (BANK3);
  1433. win_param.size = mv_get_dram_bank_size (BANK3); /* Get bank size */
  1434. if (win_param.size == 0)
  1435. win_param.enable = 0;
  1436. else
  1437. win_param.enable = 1; /* Enable the access */
  1438. win_param.access_ctrl = EWIN_ACCESS_FULL; /* Enable full access */
  1439. /* Set the access control for address window (EPAPR) READ & WRITE */
  1440. eth_set_access_control (p_eth_port_ctrl->port_num, &win_param);
  1441. /* Set access parameters for Internal SRAM */
  1442. win_param.win = ETH_WIN4; /* Use Ethernet window 0 */
  1443. win_param.target = EBAR_TARGET_CBS; /* Target - Internal SRAM */
  1444. win_param.attributes = EBAR_ATTR_CBS_SRAM | EBAR_ATTR_CBS_SRAM_BLOCK0;
  1445. win_param.high_addr = 0;
  1446. win_param.base_addr = mv_get_internal_sram_base (); /* Get base addr */
  1447. win_param.size = MV64460_INTERNAL_SRAM_SIZE; /* Get bank size */
  1448. win_param.enable = 1; /* Enable the access */
  1449. win_param.access_ctrl = EWIN_ACCESS_FULL; /* Enable full access */
  1450. /* Set the access control for address window (EPAPR) READ & WRITE */
  1451. eth_set_access_control (p_eth_port_ctrl->port_num, &win_param);
  1452. eth_port_init_mac_tables (p_eth_port_ctrl->port_num);
  1453. ethernet_phy_set (p_eth_port_ctrl->port_num,
  1454. p_eth_port_ctrl->port_phy_addr);
  1455. return;
  1456. }
  1457. /*******************************************************************************
  1458. * eth_port_start - Start the Ethernet port activity.
  1459. *
  1460. * DESCRIPTION:
  1461. * This routine prepares the Ethernet port for Rx and Tx activity:
  1462. * 1. Initialize Tx and Rx Current Descriptor Pointer for each queue that
  1463. * has been initialized a descriptor's ring (using ether_init_tx_desc_ring
  1464. * for Tx and ether_init_rx_desc_ring for Rx)
  1465. * 2. Initialize and enable the Ethernet configuration port by writing to
  1466. * the port's configuration and command registers.
  1467. * 3. Initialize and enable the SDMA by writing to the SDMA's
  1468. * configuration and command registers.
  1469. * After completing these steps, the ethernet port SDMA can starts to
  1470. * perform Rx and Tx activities.
  1471. *
  1472. * Note: Each Rx and Tx queue descriptor's list must be initialized prior
  1473. * to calling this function (use ether_init_tx_desc_ring for Tx queues and
  1474. * ether_init_rx_desc_ring for Rx queues).
  1475. *
  1476. * INPUT:
  1477. * ETH_PORT_INFO *p_eth_port_ctrl Ethernet port control struct
  1478. *
  1479. * OUTPUT:
  1480. * Ethernet port is ready to receive and transmit.
  1481. *
  1482. * RETURN:
  1483. * false if the port PHY is not up.
  1484. * true otherwise.
  1485. *
  1486. *******************************************************************************/
  1487. static bool eth_port_start (ETH_PORT_INFO * p_eth_port_ctrl)
  1488. {
  1489. int queue;
  1490. volatile ETH_TX_DESC *p_tx_curr_desc;
  1491. volatile ETH_RX_DESC *p_rx_curr_desc;
  1492. unsigned int phy_reg_data;
  1493. ETH_PORT eth_port_num = p_eth_port_ctrl->port_num;
  1494. /* Assignment of Tx CTRP of given queue */
  1495. for (queue = 0; queue < MAX_TX_QUEUE_NUM; queue++) {
  1496. CURR_TFD_GET (p_tx_curr_desc, queue);
  1497. MV_REG_WRITE ((MV64460_ETH_TX_CURRENT_QUEUE_DESC_PTR_0
  1498. (eth_port_num)
  1499. + (4 * queue)),
  1500. ((unsigned int) p_tx_curr_desc));
  1501. }
  1502. /* Assignment of Rx CRDP of given queue */
  1503. for (queue = 0; queue < MAX_RX_QUEUE_NUM; queue++) {
  1504. CURR_RFD_GET (p_rx_curr_desc, queue);
  1505. MV_REG_WRITE ((MV64460_ETH_RX_CURRENT_QUEUE_DESC_PTR_0
  1506. (eth_port_num)
  1507. + (4 * queue)),
  1508. ((unsigned int) p_rx_curr_desc));
  1509. if (p_rx_curr_desc != NULL)
  1510. /* Add the assigned Ethernet address to the port's address table */
  1511. eth_port_uc_addr_set (p_eth_port_ctrl->port_num,
  1512. p_eth_port_ctrl->port_mac_addr,
  1513. queue);
  1514. }
  1515. /* Assign port configuration and command. */
  1516. MV_REG_WRITE (MV64460_ETH_PORT_CONFIG_REG (eth_port_num),
  1517. p_eth_port_ctrl->port_config);
  1518. MV_REG_WRITE (MV64460_ETH_PORT_CONFIG_EXTEND_REG (eth_port_num),
  1519. p_eth_port_ctrl->port_config_extend);
  1520. MV_REG_WRITE (MV64460_ETH_PORT_SERIAL_CONTROL_REG (eth_port_num),
  1521. p_eth_port_ctrl->port_serial_control);
  1522. MV_SET_REG_BITS (MV64460_ETH_PORT_SERIAL_CONTROL_REG (eth_port_num),
  1523. ETH_SERIAL_PORT_ENABLE);
  1524. /* Assign port SDMA configuration */
  1525. MV_REG_WRITE (MV64460_ETH_SDMA_CONFIG_REG (eth_port_num),
  1526. p_eth_port_ctrl->port_sdma_config);
  1527. MV_REG_WRITE (MV64460_ETH_TX_QUEUE_0_TOKEN_BUCKET_COUNT
  1528. (eth_port_num), 0x3fffffff);
  1529. MV_REG_WRITE (MV64460_ETH_TX_QUEUE_0_TOKEN_BUCKET_CONFIG
  1530. (eth_port_num), 0x03fffcff);
  1531. /* Turn off the port/queue bandwidth limitation */
  1532. MV_REG_WRITE (MV64460_ETH_MAXIMUM_TRANSMIT_UNIT (eth_port_num), 0x0);
  1533. /* Enable port Rx. */
  1534. MV_REG_WRITE (MV64460_ETH_RECEIVE_QUEUE_COMMAND_REG (eth_port_num),
  1535. p_eth_port_ctrl->port_rx_queue_command);
  1536. /* Check if link is up */
  1537. eth_port_read_smi_reg (eth_port_num, 1, &phy_reg_data);
  1538. if (!(phy_reg_data & 0x20))
  1539. return false;
  1540. return true;
  1541. }
  1542. /*******************************************************************************
  1543. * eth_port_uc_addr_set - This function Set the port Unicast address.
  1544. *
  1545. * DESCRIPTION:
  1546. * This function Set the port Ethernet MAC address.
  1547. *
  1548. * INPUT:
  1549. * ETH_PORT eth_port_num Port number.
  1550. * char * p_addr Address to be set
  1551. * ETH_QUEUE queue Rx queue number for this MAC address.
  1552. *
  1553. * OUTPUT:
  1554. * Set MAC address low and high registers. also calls eth_port_uc_addr()
  1555. * To set the unicast table with the proper information.
  1556. *
  1557. * RETURN:
  1558. * N/A.
  1559. *
  1560. *******************************************************************************/
  1561. static void eth_port_uc_addr_set (ETH_PORT eth_port_num,
  1562. unsigned char *p_addr, ETH_QUEUE queue)
  1563. {
  1564. unsigned int mac_h;
  1565. unsigned int mac_l;
  1566. mac_l = (p_addr[4] << 8) | (p_addr[5]);
  1567. mac_h = (p_addr[0] << 24) | (p_addr[1] << 16) |
  1568. (p_addr[2] << 8) | (p_addr[3] << 0);
  1569. MV_REG_WRITE (MV64460_ETH_MAC_ADDR_LOW (eth_port_num), mac_l);
  1570. MV_REG_WRITE (MV64460_ETH_MAC_ADDR_HIGH (eth_port_num), mac_h);
  1571. /* Accept frames of this address */
  1572. eth_port_uc_addr (eth_port_num, p_addr[5], queue, ACCEPT_MAC_ADDR);
  1573. return;
  1574. }
  1575. /*******************************************************************************
  1576. * eth_port_uc_addr - This function Set the port unicast address table
  1577. *
  1578. * DESCRIPTION:
  1579. * This function locates the proper entry in the Unicast table for the
  1580. * specified MAC nibble and sets its properties according to function
  1581. * parameters.
  1582. *
  1583. * INPUT:
  1584. * ETH_PORT eth_port_num Port number.
  1585. * unsigned char uc_nibble Unicast MAC Address last nibble.
  1586. * ETH_QUEUE queue Rx queue number for this MAC address.
  1587. * int option 0 = Add, 1 = remove address.
  1588. *
  1589. * OUTPUT:
  1590. * This function add/removes MAC addresses from the port unicast address
  1591. * table.
  1592. *
  1593. * RETURN:
  1594. * true is output succeeded.
  1595. * false if option parameter is invalid.
  1596. *
  1597. *******************************************************************************/
  1598. static bool eth_port_uc_addr (ETH_PORT eth_port_num,
  1599. unsigned char uc_nibble,
  1600. ETH_QUEUE queue, int option)
  1601. {
  1602. unsigned int unicast_reg;
  1603. unsigned int tbl_offset;
  1604. unsigned int reg_offset;
  1605. /* Locate the Unicast table entry */
  1606. uc_nibble = (0xf & uc_nibble);
  1607. tbl_offset = (uc_nibble / 4) * 4; /* Register offset from unicast table base */
  1608. reg_offset = uc_nibble % 4; /* Entry offset within the above register */
  1609. switch (option) {
  1610. case REJECT_MAC_ADDR:
  1611. /* Clear accepts frame bit at specified unicast DA table entry */
  1612. unicast_reg =
  1613. MV_REG_READ ((MV64460_ETH_DA_FILTER_UNICAST_TABLE_BASE
  1614. (eth_port_num)
  1615. + tbl_offset));
  1616. unicast_reg &= (0x0E << (8 * reg_offset));
  1617. MV_REG_WRITE ((MV64460_ETH_DA_FILTER_UNICAST_TABLE_BASE
  1618. (eth_port_num)
  1619. + tbl_offset), unicast_reg);
  1620. break;
  1621. case ACCEPT_MAC_ADDR:
  1622. /* Set accepts frame bit at unicast DA filter table entry */
  1623. unicast_reg =
  1624. MV_REG_READ ((MV64460_ETH_DA_FILTER_UNICAST_TABLE_BASE
  1625. (eth_port_num)
  1626. + tbl_offset));
  1627. unicast_reg |= ((0x01 | queue) << (8 * reg_offset));
  1628. MV_REG_WRITE ((MV64460_ETH_DA_FILTER_UNICAST_TABLE_BASE
  1629. (eth_port_num)
  1630. + tbl_offset), unicast_reg);
  1631. break;
  1632. default:
  1633. return false;
  1634. }
  1635. return true;
  1636. }
  1637. #if 0 /* FIXME */
  1638. /*******************************************************************************
  1639. * eth_port_mc_addr - Multicast address settings.
  1640. *
  1641. * DESCRIPTION:
  1642. * This API controls the MV device MAC multicast support.
  1643. * The MV device supports multicast using two tables:
  1644. * 1) Special Multicast Table for MAC addresses of the form
  1645. * 0x01-00-5E-00-00-XX (where XX is between 0x00 and 0x_fF).
  1646. * The MAC DA[7:0] bits are used as a pointer to the Special Multicast
  1647. * Table entries in the DA-Filter table.
  1648. * In this case, the function calls eth_port_smc_addr() routine to set the
  1649. * Special Multicast Table.
  1650. * 2) Other Multicast Table for multicast of another type. A CRC-8bit
  1651. * is used as an index to the Other Multicast Table entries in the
  1652. * DA-Filter table.
  1653. * In this case, the function calculates the CRC-8bit value and calls
  1654. * eth_port_omc_addr() routine to set the Other Multicast Table.
  1655. * INPUT:
  1656. * ETH_PORT eth_port_num Port number.
  1657. * unsigned char *p_addr Unicast MAC Address.
  1658. * ETH_QUEUE queue Rx queue number for this MAC address.
  1659. * int option 0 = Add, 1 = remove address.
  1660. *
  1661. * OUTPUT:
  1662. * See description.
  1663. *
  1664. * RETURN:
  1665. * true is output succeeded.
  1666. * false if add_address_table_entry( ) failed.
  1667. *
  1668. *******************************************************************************/
  1669. static void eth_port_mc_addr (ETH_PORT eth_port_num,
  1670. unsigned char *p_addr,
  1671. ETH_QUEUE queue, int option)
  1672. {
  1673. unsigned int mac_h;
  1674. unsigned int mac_l;
  1675. unsigned char crc_result = 0;
  1676. int mac_array[48];
  1677. int crc[8];
  1678. int i;
  1679. if ((p_addr[0] == 0x01) &&
  1680. (p_addr[1] == 0x00) &&
  1681. (p_addr[2] == 0x5E) && (p_addr[3] == 0x00) && (p_addr[4] == 0x00))
  1682. eth_port_smc_addr (eth_port_num, p_addr[5], queue, option);
  1683. else {
  1684. /* Calculate CRC-8 out of the given address */
  1685. mac_h = (p_addr[0] << 8) | (p_addr[1]);
  1686. mac_l = (p_addr[2] << 24) | (p_addr[3] << 16) |
  1687. (p_addr[4] << 8) | (p_addr[5] << 0);
  1688. for (i = 0; i < 32; i++)
  1689. mac_array[i] = (mac_l >> i) & 0x1;
  1690. for (i = 32; i < 48; i++)
  1691. mac_array[i] = (mac_h >> (i - 32)) & 0x1;
  1692. crc[0] = mac_array[45] ^ mac_array[43] ^ mac_array[40] ^
  1693. mac_array[39] ^ mac_array[35] ^ mac_array[34] ^
  1694. mac_array[31] ^ mac_array[30] ^ mac_array[28] ^
  1695. mac_array[23] ^ mac_array[21] ^ mac_array[19] ^
  1696. mac_array[18] ^ mac_array[16] ^ mac_array[14] ^
  1697. mac_array[12] ^ mac_array[8] ^ mac_array[7] ^
  1698. mac_array[6] ^ mac_array[0];
  1699. crc[1] = mac_array[46] ^ mac_array[45] ^ mac_array[44] ^
  1700. mac_array[43] ^ mac_array[41] ^ mac_array[39] ^
  1701. mac_array[36] ^ mac_array[34] ^ mac_array[32] ^
  1702. mac_array[30] ^ mac_array[29] ^ mac_array[28] ^
  1703. mac_array[24] ^ mac_array[23] ^ mac_array[22] ^
  1704. mac_array[21] ^ mac_array[20] ^ mac_array[18] ^
  1705. mac_array[17] ^ mac_array[16] ^ mac_array[15] ^
  1706. mac_array[14] ^ mac_array[13] ^ mac_array[12] ^
  1707. mac_array[9] ^ mac_array[6] ^ mac_array[1] ^
  1708. mac_array[0];
  1709. crc[2] = mac_array[47] ^ mac_array[46] ^ mac_array[44] ^
  1710. mac_array[43] ^ mac_array[42] ^ mac_array[39] ^
  1711. mac_array[37] ^ mac_array[34] ^ mac_array[33] ^
  1712. mac_array[29] ^ mac_array[28] ^ mac_array[25] ^
  1713. mac_array[24] ^ mac_array[22] ^ mac_array[17] ^
  1714. mac_array[15] ^ mac_array[13] ^ mac_array[12] ^
  1715. mac_array[10] ^ mac_array[8] ^ mac_array[6] ^
  1716. mac_array[2] ^ mac_array[1] ^ mac_array[0];
  1717. crc[3] = mac_array[47] ^ mac_array[45] ^ mac_array[44] ^
  1718. mac_array[43] ^ mac_array[40] ^ mac_array[38] ^
  1719. mac_array[35] ^ mac_array[34] ^ mac_array[30] ^
  1720. mac_array[29] ^ mac_array[26] ^ mac_array[25] ^
  1721. mac_array[23] ^ mac_array[18] ^ mac_array[16] ^
  1722. mac_array[14] ^ mac_array[13] ^ mac_array[11] ^
  1723. mac_array[9] ^ mac_array[7] ^ mac_array[3] ^
  1724. mac_array[2] ^ mac_array[1];
  1725. crc[4] = mac_array[46] ^ mac_array[45] ^ mac_array[44] ^
  1726. mac_array[41] ^ mac_array[39] ^ mac_array[36] ^
  1727. mac_array[35] ^ mac_array[31] ^ mac_array[30] ^
  1728. mac_array[27] ^ mac_array[26] ^ mac_array[24] ^
  1729. mac_array[19] ^ mac_array[17] ^ mac_array[15] ^
  1730. mac_array[14] ^ mac_array[12] ^ mac_array[10] ^
  1731. mac_array[8] ^ mac_array[4] ^ mac_array[3] ^
  1732. mac_array[2];
  1733. crc[5] = mac_array[47] ^ mac_array[46] ^ mac_array[45] ^
  1734. mac_array[42] ^ mac_array[40] ^ mac_array[37] ^
  1735. mac_array[36] ^ mac_array[32] ^ mac_array[31] ^
  1736. mac_array[28] ^ mac_array[27] ^ mac_array[25] ^
  1737. mac_array[20] ^ mac_array[18] ^ mac_array[16] ^
  1738. mac_array[15] ^ mac_array[13] ^ mac_array[11] ^
  1739. mac_array[9] ^ mac_array[5] ^ mac_array[4] ^
  1740. mac_array[3];
  1741. crc[6] = mac_array[47] ^ mac_array[46] ^ mac_array[43] ^
  1742. mac_array[41] ^ mac_array[38] ^ mac_array[37] ^
  1743. mac_array[33] ^ mac_array[32] ^ mac_array[29] ^
  1744. mac_array[28] ^ mac_array[26] ^ mac_array[21] ^
  1745. mac_array[19] ^ mac_array[17] ^ mac_array[16] ^
  1746. mac_array[14] ^ mac_array[12] ^ mac_array[10] ^
  1747. mac_array[6] ^ mac_array[5] ^ mac_array[4];
  1748. crc[7] = mac_array[47] ^ mac_array[44] ^ mac_array[42] ^
  1749. mac_array[39] ^ mac_array[38] ^ mac_array[34] ^
  1750. mac_array[33] ^ mac_array[30] ^ mac_array[29] ^
  1751. mac_array[27] ^ mac_array[22] ^ mac_array[20] ^
  1752. mac_array[18] ^ mac_array[17] ^ mac_array[15] ^
  1753. mac_array[13] ^ mac_array[11] ^ mac_array[7] ^
  1754. mac_array[6] ^ mac_array[5];
  1755. for (i = 0; i < 8; i++)
  1756. crc_result = crc_result | (crc[i] << i);
  1757. eth_port_omc_addr (eth_port_num, crc_result, queue, option);
  1758. }
  1759. return;
  1760. }
  1761. /*******************************************************************************
  1762. * eth_port_smc_addr - Special Multicast address settings.
  1763. *
  1764. * DESCRIPTION:
  1765. * This routine controls the MV device special MAC multicast support.
  1766. * The Special Multicast Table for MAC addresses supports MAC of the form
  1767. * 0x01-00-5E-00-00-XX (where XX is between 0x00 and 0x_fF).
  1768. * The MAC DA[7:0] bits are used as a pointer to the Special Multicast
  1769. * Table entries in the DA-Filter table.
  1770. * This function set the Special Multicast Table appropriate entry
  1771. * according to the argument given.
  1772. *
  1773. * INPUT:
  1774. * ETH_PORT eth_port_num Port number.
  1775. * unsigned char mc_byte Multicast addr last byte (MAC DA[7:0] bits).
  1776. * ETH_QUEUE queue Rx queue number for this MAC address.
  1777. * int option 0 = Add, 1 = remove address.
  1778. *
  1779. * OUTPUT:
  1780. * See description.
  1781. *
  1782. * RETURN:
  1783. * true is output succeeded.
  1784. * false if option parameter is invalid.
  1785. *
  1786. *******************************************************************************/
  1787. static bool eth_port_smc_addr (ETH_PORT eth_port_num,
  1788. unsigned char mc_byte,
  1789. ETH_QUEUE queue, int option)
  1790. {
  1791. unsigned int smc_table_reg;
  1792. unsigned int tbl_offset;
  1793. unsigned int reg_offset;
  1794. /* Locate the SMC table entry */
  1795. tbl_offset = (mc_byte / 4) * 4; /* Register offset from SMC table base */
  1796. reg_offset = mc_byte % 4; /* Entry offset within the above register */
  1797. queue &= 0x7;
  1798. switch (option) {
  1799. case REJECT_MAC_ADDR:
  1800. /* Clear accepts frame bit at specified Special DA table entry */
  1801. smc_table_reg =
  1802. MV_REG_READ ((MV64460_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset));
  1803. smc_table_reg &= (0x0E << (8 * reg_offset));
  1804. MV_REG_WRITE ((MV64460_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset), smc_table_reg);
  1805. break;
  1806. case ACCEPT_MAC_ADDR:
  1807. /* Set accepts frame bit at specified Special DA table entry */
  1808. smc_table_reg =
  1809. MV_REG_READ ((MV64460_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset));
  1810. smc_table_reg |= ((0x01 | queue) << (8 * reg_offset));
  1811. MV_REG_WRITE ((MV64460_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset), smc_table_reg);
  1812. break;
  1813. default:
  1814. return false;
  1815. }
  1816. return true;
  1817. }
  1818. /*******************************************************************************
  1819. * eth_port_omc_addr - Multicast address settings.
  1820. *
  1821. * DESCRIPTION:
  1822. * This routine controls the MV device Other MAC multicast support.
  1823. * The Other Multicast Table is used for multicast of another type.
  1824. * A CRC-8bit is used as an index to the Other Multicast Table entries
  1825. * in the DA-Filter table.
  1826. * The function gets the CRC-8bit value from the calling routine and
  1827. * set the Other Multicast Table appropriate entry according to the
  1828. * CRC-8 argument given.
  1829. *
  1830. * INPUT:
  1831. * ETH_PORT eth_port_num Port number.
  1832. * unsigned char crc8 A CRC-8bit (Polynomial: x^8+x^2+x^1+1).
  1833. * ETH_QUEUE queue Rx queue number for this MAC address.
  1834. * int option 0 = Add, 1 = remove address.
  1835. *
  1836. * OUTPUT:
  1837. * See description.
  1838. *
  1839. * RETURN:
  1840. * true is output succeeded.
  1841. * false if option parameter is invalid.
  1842. *
  1843. *******************************************************************************/
  1844. static bool eth_port_omc_addr (ETH_PORT eth_port_num,
  1845. unsigned char crc8,
  1846. ETH_QUEUE queue, int option)
  1847. {
  1848. unsigned int omc_table_reg;
  1849. unsigned int tbl_offset;
  1850. unsigned int reg_offset;
  1851. /* Locate the OMC table entry */
  1852. tbl_offset = (crc8 / 4) * 4; /* Register offset from OMC table base */
  1853. reg_offset = crc8 % 4; /* Entry offset within the above register */
  1854. queue &= 0x7;
  1855. switch (option) {
  1856. case REJECT_MAC_ADDR:
  1857. /* Clear accepts frame bit at specified Other DA table entry */
  1858. omc_table_reg =
  1859. MV_REG_READ ((MV64460_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset));
  1860. omc_table_reg &= (0x0E << (8 * reg_offset));
  1861. MV_REG_WRITE ((MV64460_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset), omc_table_reg);
  1862. break;
  1863. case ACCEPT_MAC_ADDR:
  1864. /* Set accepts frame bit at specified Other DA table entry */
  1865. omc_table_reg =
  1866. MV_REG_READ ((MV64460_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset));
  1867. omc_table_reg |= ((0x01 | queue) << (8 * reg_offset));
  1868. MV_REG_WRITE ((MV64460_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset), omc_table_reg);
  1869. break;
  1870. default:
  1871. return false;
  1872. }
  1873. return true;
  1874. }
  1875. #endif
  1876. /*******************************************************************************
  1877. * eth_port_init_mac_tables - Clear all entrance in the UC, SMC and OMC tables
  1878. *
  1879. * DESCRIPTION:
  1880. * Go through all the DA filter tables (Unicast, Special Multicast & Other
  1881. * Multicast) and set each entry to 0.
  1882. *
  1883. * INPUT:
  1884. * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
  1885. *
  1886. * OUTPUT:
  1887. * Multicast and Unicast packets are rejected.
  1888. *
  1889. * RETURN:
  1890. * None.
  1891. *
  1892. *******************************************************************************/
  1893. static void eth_port_init_mac_tables (ETH_PORT eth_port_num)
  1894. {
  1895. int table_index;
  1896. /* Clear DA filter unicast table (Ex_dFUT) */
  1897. for (table_index = 0; table_index <= 0xC; table_index += 4)
  1898. MV_REG_WRITE ((MV64460_ETH_DA_FILTER_UNICAST_TABLE_BASE
  1899. (eth_port_num) + table_index), 0);
  1900. for (table_index = 0; table_index <= 0xFC; table_index += 4) {
  1901. /* Clear DA filter special multicast table (Ex_dFSMT) */
  1902. MV_REG_WRITE ((MV64460_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE (eth_port_num) + table_index), 0);
  1903. /* Clear DA filter other multicast table (Ex_dFOMT) */
  1904. MV_REG_WRITE ((MV64460_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE (eth_port_num) + table_index), 0);
  1905. }
  1906. }
  1907. /*******************************************************************************
  1908. * eth_clear_mib_counters - Clear all MIB counters
  1909. *
  1910. * DESCRIPTION:
  1911. * This function clears all MIB counters of a specific ethernet port.
  1912. * A read from the MIB counter will reset the counter.
  1913. *
  1914. * INPUT:
  1915. * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
  1916. *
  1917. * OUTPUT:
  1918. * After reading all MIB counters, the counters resets.
  1919. *
  1920. * RETURN:
  1921. * MIB counter value.
  1922. *
  1923. *******************************************************************************/
  1924. static void eth_clear_mib_counters (ETH_PORT eth_port_num)
  1925. {
  1926. int i;
  1927. unsigned int dummy;
  1928. /* Perform dummy reads from MIB counters */
  1929. for (i = ETH_MIB_GOOD_OCTETS_RECEIVED_LOW; i < ETH_MIB_LATE_COLLISION;
  1930. i += 4)
  1931. dummy = MV_REG_READ ((MV64460_ETH_MIB_COUNTERS_BASE
  1932. (eth_port_num) + i));
  1933. return;
  1934. }
  1935. /*******************************************************************************
  1936. * eth_read_mib_counter - Read a MIB counter
  1937. *
  1938. * DESCRIPTION:
  1939. * This function reads a MIB counter of a specific ethernet port.
  1940. * NOTE - If read from ETH_MIB_GOOD_OCTETS_RECEIVED_LOW, then the
  1941. * following read must be from ETH_MIB_GOOD_OCTETS_RECEIVED_HIGH
  1942. * register. The same applies for ETH_MIB_GOOD_OCTETS_SENT_LOW and
  1943. * ETH_MIB_GOOD_OCTETS_SENT_HIGH
  1944. *
  1945. * INPUT:
  1946. * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
  1947. * unsigned int mib_offset MIB counter offset (use ETH_MIB_... macros).
  1948. *
  1949. * OUTPUT:
  1950. * After reading the MIB counter, the counter resets.
  1951. *
  1952. * RETURN:
  1953. * MIB counter value.
  1954. *
  1955. *******************************************************************************/
  1956. unsigned int eth_read_mib_counter (ETH_PORT eth_port_num,
  1957. unsigned int mib_offset)
  1958. {
  1959. return (MV_REG_READ (MV64460_ETH_MIB_COUNTERS_BASE (eth_port_num)
  1960. + mib_offset));
  1961. }
  1962. /*******************************************************************************
  1963. * ethernet_phy_set - Set the ethernet port PHY address.
  1964. *
  1965. * DESCRIPTION:
  1966. * This routine set the ethernet port PHY address according to given
  1967. * parameter.
  1968. *
  1969. * INPUT:
  1970. * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
  1971. *
  1972. * OUTPUT:
  1973. * Set PHY Address Register with given PHY address parameter.
  1974. *
  1975. * RETURN:
  1976. * None.
  1977. *
  1978. *******************************************************************************/
  1979. static void ethernet_phy_set (ETH_PORT eth_port_num, int phy_addr)
  1980. {
  1981. unsigned int reg_data;
  1982. reg_data = MV_REG_READ (MV64460_ETH_PHY_ADDR_REG);
  1983. reg_data &= ~(0x1F << (5 * eth_port_num));
  1984. reg_data |= (phy_addr << (5 * eth_port_num));
  1985. MV_REG_WRITE (MV64460_ETH_PHY_ADDR_REG, reg_data);
  1986. return;
  1987. }
  1988. /*******************************************************************************
  1989. * ethernet_phy_get - Get the ethernet port PHY address.
  1990. *
  1991. * DESCRIPTION:
  1992. * This routine returns the given ethernet port PHY address.
  1993. *
  1994. * INPUT:
  1995. * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
  1996. *
  1997. * OUTPUT:
  1998. * None.
  1999. *
  2000. * RETURN:
  2001. * PHY address.
  2002. *
  2003. *******************************************************************************/
  2004. static int ethernet_phy_get (ETH_PORT eth_port_num)
  2005. {
  2006. unsigned int reg_data;
  2007. reg_data = MV_REG_READ (MV64460_ETH_PHY_ADDR_REG);
  2008. return ((reg_data >> (5 * eth_port_num)) & 0x1f);
  2009. }
  2010. /***********************************************************/
  2011. /* (Re)start autonegotiation */
  2012. /***********************************************************/
  2013. int phy_setup_aneg (char *devname, unsigned char addr)
  2014. {
  2015. unsigned short ctl, adv;
  2016. /* Setup standard advertise */
  2017. miiphy_read (devname, addr, PHY_ANAR, &adv);
  2018. adv |= (PHY_ANLPAR_ACK | PHY_ANLPAR_RF | PHY_ANLPAR_T4 |
  2019. PHY_ANLPAR_TXFD | PHY_ANLPAR_TX | PHY_ANLPAR_10FD |
  2020. PHY_ANLPAR_10);
  2021. miiphy_write (devname, addr, PHY_ANAR, adv);
  2022. miiphy_read (devname, addr, PHY_1000BTCR, &adv);
  2023. adv |= (0x0300);
  2024. miiphy_write (devname, addr, PHY_1000BTCR, adv);
  2025. /* Start/Restart aneg */
  2026. miiphy_read (devname, addr, PHY_BMCR, &ctl);
  2027. ctl |= (PHY_BMCR_AUTON | PHY_BMCR_RST_NEG);
  2028. miiphy_write (devname, addr, PHY_BMCR, ctl);
  2029. return 0;
  2030. }
  2031. /*******************************************************************************
  2032. * ethernet_phy_reset - Reset Ethernet port PHY.
  2033. *
  2034. * DESCRIPTION:
  2035. * This routine utilize the SMI interface to reset the ethernet port PHY.
  2036. * The routine waits until the link is up again or link up is timeout.
  2037. *
  2038. * INPUT:
  2039. * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
  2040. *
  2041. * OUTPUT:
  2042. * The ethernet port PHY renew its link.
  2043. *
  2044. * RETURN:
  2045. * None.
  2046. *
  2047. *******************************************************************************/
  2048. static bool ethernet_phy_reset (ETH_PORT eth_port_num)
  2049. {
  2050. unsigned int time_out = 50;
  2051. unsigned int phy_reg_data;
  2052. eth_port_read_smi_reg (eth_port_num, 20, &phy_reg_data);
  2053. phy_reg_data |= 0x0083; /* Set bit 7 to 1 for different RGMII timing */
  2054. eth_port_write_smi_reg (eth_port_num, 20, phy_reg_data);
  2055. /* Reset the PHY */
  2056. eth_port_read_smi_reg (eth_port_num, 0, &phy_reg_data);
  2057. phy_reg_data |= 0x8000; /* Set bit 15 to reset the PHY */
  2058. eth_port_write_smi_reg (eth_port_num, 0, phy_reg_data);
  2059. /* Poll on the PHY LINK */
  2060. do {
  2061. eth_port_read_smi_reg (eth_port_num, 1, &phy_reg_data);
  2062. if (time_out-- == 0)
  2063. return false;
  2064. }
  2065. while (!(phy_reg_data & 0x20));
  2066. return true;
  2067. }
  2068. /*******************************************************************************
  2069. * eth_port_reset - Reset Ethernet port
  2070. *
  2071. * DESCRIPTION:
  2072. * This routine resets the chip by aborting any SDMA engine activity and
  2073. * clearing the MIB counters. The Receiver and the Transmit unit are in
  2074. * idle state after this command is performed and the port is disabled.
  2075. *
  2076. * INPUT:
  2077. * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
  2078. *
  2079. * OUTPUT:
  2080. * Channel activity is halted.
  2081. *
  2082. * RETURN:
  2083. * None.
  2084. *
  2085. *******************************************************************************/
  2086. static void eth_port_reset (ETH_PORT eth_port_num)
  2087. {
  2088. unsigned int reg_data;
  2089. /* Stop Tx port activity. Check port Tx activity. */
  2090. reg_data =
  2091. MV_REG_READ (MV64460_ETH_TRANSMIT_QUEUE_COMMAND_REG
  2092. (eth_port_num));
  2093. if (reg_data & 0xFF) {
  2094. /* Issue stop command for active channels only */
  2095. MV_REG_WRITE (MV64460_ETH_TRANSMIT_QUEUE_COMMAND_REG
  2096. (eth_port_num), (reg_data << 8));
  2097. /* Wait for all Tx activity to terminate. */
  2098. do {
  2099. /* Check port cause register that all Tx queues are stopped */
  2100. reg_data =
  2101. MV_REG_READ
  2102. (MV64460_ETH_TRANSMIT_QUEUE_COMMAND_REG
  2103. (eth_port_num));
  2104. }
  2105. while (reg_data & 0xFF);
  2106. }
  2107. /* Stop Rx port activity. Check port Rx activity. */
  2108. reg_data =
  2109. MV_REG_READ (MV64460_ETH_RECEIVE_QUEUE_COMMAND_REG
  2110. (eth_port_num));
  2111. if (reg_data & 0xFF) {
  2112. /* Issue stop command for active channels only */
  2113. MV_REG_WRITE (MV64460_ETH_RECEIVE_QUEUE_COMMAND_REG
  2114. (eth_port_num), (reg_data << 8));
  2115. /* Wait for all Rx activity to terminate. */
  2116. do {
  2117. /* Check port cause register that all Rx queues are stopped */
  2118. reg_data =
  2119. MV_REG_READ
  2120. (MV64460_ETH_RECEIVE_QUEUE_COMMAND_REG
  2121. (eth_port_num));
  2122. }
  2123. while (reg_data & 0xFF);
  2124. }
  2125. /* Clear all MIB counters */
  2126. eth_clear_mib_counters (eth_port_num);
  2127. /* Reset the Enable bit in the Configuration Register */
  2128. reg_data =
  2129. MV_REG_READ (MV64460_ETH_PORT_SERIAL_CONTROL_REG
  2130. (eth_port_num));
  2131. reg_data &= ~ETH_SERIAL_PORT_ENABLE;
  2132. MV_REG_WRITE (MV64460_ETH_PORT_SERIAL_CONTROL_REG (eth_port_num),
  2133. reg_data);
  2134. return;
  2135. }
  2136. #if 0 /* Not needed here */
  2137. /*******************************************************************************
  2138. * ethernet_set_config_reg - Set specified bits in configuration register.
  2139. *
  2140. * DESCRIPTION:
  2141. * This function sets specified bits in the given ethernet
  2142. * configuration register.
  2143. *
  2144. * INPUT:
  2145. * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
  2146. * unsigned int value 32 bit value.
  2147. *
  2148. * OUTPUT:
  2149. * The set bits in the value parameter are set in the configuration
  2150. * register.
  2151. *
  2152. * RETURN:
  2153. * None.
  2154. *
  2155. *******************************************************************************/
  2156. static void ethernet_set_config_reg (ETH_PORT eth_port_num,
  2157. unsigned int value)
  2158. {
  2159. unsigned int eth_config_reg;
  2160. eth_config_reg =
  2161. MV_REG_READ (MV64460_ETH_PORT_CONFIG_REG (eth_port_num));
  2162. eth_config_reg |= value;
  2163. MV_REG_WRITE (MV64460_ETH_PORT_CONFIG_REG (eth_port_num),
  2164. eth_config_reg);
  2165. return;
  2166. }
  2167. #endif
  2168. #if 0 /* FIXME */
  2169. /*******************************************************************************
  2170. * ethernet_reset_config_reg - Reset specified bits in configuration register.
  2171. *
  2172. * DESCRIPTION:
  2173. * This function resets specified bits in the given Ethernet
  2174. * configuration register.
  2175. *
  2176. * INPUT:
  2177. * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
  2178. * unsigned int value 32 bit value.
  2179. *
  2180. * OUTPUT:
  2181. * The set bits in the value parameter are reset in the configuration
  2182. * register.
  2183. *
  2184. * RETURN:
  2185. * None.
  2186. *
  2187. *******************************************************************************/
  2188. static void ethernet_reset_config_reg (ETH_PORT eth_port_num,
  2189. unsigned int value)
  2190. {
  2191. unsigned int eth_config_reg;
  2192. eth_config_reg = MV_REG_READ (MV64460_ETH_PORT_CONFIG_EXTEND_REG
  2193. (eth_port_num));
  2194. eth_config_reg &= ~value;
  2195. MV_REG_WRITE (MV64460_ETH_PORT_CONFIG_EXTEND_REG (eth_port_num),
  2196. eth_config_reg);
  2197. return;
  2198. }
  2199. #endif
  2200. #if 0 /* Not needed here */
  2201. /*******************************************************************************
  2202. * ethernet_get_config_reg - Get the port configuration register
  2203. *
  2204. * DESCRIPTION:
  2205. * This function returns the configuration register value of the given
  2206. * ethernet port.
  2207. *
  2208. * INPUT:
  2209. * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
  2210. *
  2211. * OUTPUT:
  2212. * None.
  2213. *
  2214. * RETURN:
  2215. * Port configuration register value.
  2216. *
  2217. *******************************************************************************/
  2218. static unsigned int ethernet_get_config_reg (ETH_PORT eth_port_num)
  2219. {
  2220. unsigned int eth_config_reg;
  2221. eth_config_reg = MV_REG_READ (MV64460_ETH_PORT_CONFIG_EXTEND_REG
  2222. (eth_port_num));
  2223. return eth_config_reg;
  2224. }
  2225. #endif
  2226. /*******************************************************************************
  2227. * eth_port_read_smi_reg - Read PHY registers
  2228. *
  2229. * DESCRIPTION:
  2230. * This routine utilize the SMI interface to interact with the PHY in
  2231. * order to perform PHY register read.
  2232. *
  2233. * INPUT:
  2234. * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
  2235. * unsigned int phy_reg PHY register address offset.
  2236. * unsigned int *value Register value buffer.
  2237. *
  2238. * OUTPUT:
  2239. * Write the value of a specified PHY register into given buffer.
  2240. *
  2241. * RETURN:
  2242. * false if the PHY is busy or read data is not in valid state.
  2243. * true otherwise.
  2244. *
  2245. *******************************************************************************/
  2246. static bool eth_port_read_smi_reg (ETH_PORT eth_port_num,
  2247. unsigned int phy_reg, unsigned int *value)
  2248. {
  2249. unsigned int reg_value;
  2250. unsigned int time_out = PHY_BUSY_TIMEOUT;
  2251. int phy_addr;
  2252. phy_addr = ethernet_phy_get (eth_port_num);
  2253. /* first check that it is not busy */
  2254. do {
  2255. reg_value = MV_REG_READ (MV64460_ETH_SMI_REG);
  2256. if (time_out-- == 0) {
  2257. return false;
  2258. }
  2259. }
  2260. while (reg_value & ETH_SMI_BUSY);
  2261. /* not busy */
  2262. MV_REG_WRITE (MV64460_ETH_SMI_REG,
  2263. (phy_addr << 16) | (phy_reg << 21) |
  2264. ETH_SMI_OPCODE_READ);
  2265. time_out = PHY_BUSY_TIMEOUT; /* initialize the time out var again */
  2266. do {
  2267. reg_value = MV_REG_READ (MV64460_ETH_SMI_REG);
  2268. if (time_out-- == 0) {
  2269. return false;
  2270. }
  2271. }
  2272. while ((reg_value & ETH_SMI_READ_VALID) != ETH_SMI_READ_VALID); /* Bit set equ operation done */
  2273. /* Wait for the data to update in the SMI register */
  2274. #define PHY_UPDATE_TIMEOUT 10000
  2275. for (time_out = 0; time_out < PHY_UPDATE_TIMEOUT; time_out++);
  2276. reg_value = MV_REG_READ (MV64460_ETH_SMI_REG);
  2277. *value = reg_value & 0xffff;
  2278. return true;
  2279. }
  2280. int mv_miiphy_read(char *devname, unsigned char phy_addr,
  2281. unsigned char phy_reg, unsigned short *value)
  2282. {
  2283. unsigned int reg_value;
  2284. unsigned int time_out = PHY_BUSY_TIMEOUT;
  2285. /* first check that it is not busy */
  2286. do {
  2287. reg_value = MV_REG_READ (MV64460_ETH_SMI_REG);
  2288. if (time_out-- == 0) {
  2289. return false;
  2290. }
  2291. }
  2292. while (reg_value & ETH_SMI_BUSY);
  2293. /* not busy */
  2294. MV_REG_WRITE (MV64460_ETH_SMI_REG,
  2295. (phy_addr << 16) | (phy_reg << 21) |
  2296. ETH_SMI_OPCODE_READ);
  2297. time_out = PHY_BUSY_TIMEOUT; /* initialize the time out var again */
  2298. do {
  2299. reg_value = MV_REG_READ (MV64460_ETH_SMI_REG);
  2300. if (time_out-- == 0) {
  2301. return false;
  2302. }
  2303. }
  2304. while ((reg_value & ETH_SMI_READ_VALID) != ETH_SMI_READ_VALID); /* Bit set equ operation done */
  2305. /* Wait for the data to update in the SMI register */
  2306. for (time_out = 0; time_out < PHY_UPDATE_TIMEOUT; time_out++);
  2307. reg_value = MV_REG_READ (MV64460_ETH_SMI_REG);
  2308. *value = reg_value & 0xffff;
  2309. return 0;
  2310. }
  2311. /*******************************************************************************
  2312. * eth_port_write_smi_reg - Write to PHY registers
  2313. *
  2314. * DESCRIPTION:
  2315. * This routine utilize the SMI interface to interact with the PHY in
  2316. * order to perform writes to PHY registers.
  2317. *
  2318. * INPUT:
  2319. * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
  2320. * unsigned int phy_reg PHY register address offset.
  2321. * unsigned int value Register value.
  2322. *
  2323. * OUTPUT:
  2324. * Write the given value to the specified PHY register.
  2325. *
  2326. * RETURN:
  2327. * false if the PHY is busy.
  2328. * true otherwise.
  2329. *
  2330. *******************************************************************************/
  2331. static bool eth_port_write_smi_reg (ETH_PORT eth_port_num,
  2332. unsigned int phy_reg, unsigned int value)
  2333. {
  2334. unsigned int reg_value;
  2335. unsigned int time_out = PHY_BUSY_TIMEOUT;
  2336. int phy_addr;
  2337. phy_addr = ethernet_phy_get (eth_port_num);
  2338. /* first check that it is not busy */
  2339. do {
  2340. reg_value = MV_REG_READ (MV64460_ETH_SMI_REG);
  2341. if (time_out-- == 0) {
  2342. return false;
  2343. }
  2344. }
  2345. while (reg_value & ETH_SMI_BUSY);
  2346. /* not busy */
  2347. MV_REG_WRITE (MV64460_ETH_SMI_REG,
  2348. (phy_addr << 16) | (phy_reg << 21) |
  2349. ETH_SMI_OPCODE_WRITE | (value & 0xffff));
  2350. return true;
  2351. }
  2352. int mv_miiphy_write(char *devname, unsigned char phy_addr,
  2353. unsigned char phy_reg, unsigned short value)
  2354. {
  2355. unsigned int reg_value;
  2356. unsigned int time_out = PHY_BUSY_TIMEOUT;
  2357. /* first check that it is not busy */
  2358. do {
  2359. reg_value = MV_REG_READ (MV64460_ETH_SMI_REG);
  2360. if (time_out-- == 0) {
  2361. return false;
  2362. }
  2363. }
  2364. while (reg_value & ETH_SMI_BUSY);
  2365. /* not busy */
  2366. MV_REG_WRITE (MV64460_ETH_SMI_REG,
  2367. (phy_addr << 16) | (phy_reg << 21) |
  2368. ETH_SMI_OPCODE_WRITE | (value & 0xffff));
  2369. return 0;
  2370. }
  2371. /*******************************************************************************
  2372. * eth_set_access_control - Config address decode parameters for Ethernet unit
  2373. *
  2374. * DESCRIPTION:
  2375. * This function configures the address decode parameters for the Gigabit
  2376. * Ethernet Controller according the given parameters struct.
  2377. *
  2378. * INPUT:
  2379. * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
  2380. * ETH_WIN_PARAM *param Address decode parameter struct.
  2381. *
  2382. * OUTPUT:
  2383. * An access window is opened using the given access parameters.
  2384. *
  2385. * RETURN:
  2386. * None.
  2387. *
  2388. *******************************************************************************/
  2389. static void eth_set_access_control (ETH_PORT eth_port_num,
  2390. ETH_WIN_PARAM * param)
  2391. {
  2392. unsigned int access_prot_reg;
  2393. /* Set access control register */
  2394. access_prot_reg = MV_REG_READ (MV64460_ETH_ACCESS_PROTECTION_REG
  2395. (eth_port_num));
  2396. access_prot_reg &= (~(3 << (param->win * 2))); /* clear window permission */
  2397. access_prot_reg |= (param->access_ctrl << (param->win * 2));
  2398. MV_REG_WRITE (MV64460_ETH_ACCESS_PROTECTION_REG (eth_port_num),
  2399. access_prot_reg);
  2400. /* Set window Size reg (SR) */
  2401. MV_REG_WRITE ((MV64460_ETH_SIZE_REG_0 +
  2402. (ETH_SIZE_REG_GAP * param->win)),
  2403. (((param->size / 0x10000) - 1) << 16));
  2404. /* Set window Base address reg (BA) */
  2405. MV_REG_WRITE ((MV64460_ETH_BAR_0 + (ETH_BAR_GAP * param->win)),
  2406. (param->target | param->attributes | param->base_addr));
  2407. /* High address remap reg (HARR) */
  2408. if (param->win < 4)
  2409. MV_REG_WRITE ((MV64460_ETH_HIGH_ADDR_REMAP_REG_0 +
  2410. (ETH_HIGH_ADDR_REMAP_REG_GAP * param->win)),
  2411. param->high_addr);
  2412. /* Base address enable reg (BARER) */
  2413. if (param->enable == 1)
  2414. MV_RESET_REG_BITS (MV64460_ETH_BASE_ADDR_ENABLE_REG,
  2415. (1 << param->win));
  2416. else
  2417. MV_SET_REG_BITS (MV64460_ETH_BASE_ADDR_ENABLE_REG,
  2418. (1 << param->win));
  2419. }
  2420. /*******************************************************************************
  2421. * ether_init_rx_desc_ring - Curve a Rx chain desc list and buffer in memory.
  2422. *
  2423. * DESCRIPTION:
  2424. * This function prepares a Rx chained list of descriptors and packet
  2425. * buffers in a form of a ring. The routine must be called after port
  2426. * initialization routine and before port start routine.
  2427. * The Ethernet SDMA engine uses CPU bus addresses to access the various
  2428. * devices in the system (i.e. DRAM). This function uses the ethernet
  2429. * struct 'virtual to physical' routine (set by the user) to set the ring
  2430. * with physical addresses.
  2431. *
  2432. * INPUT:
  2433. * ETH_PORT_INFO *p_eth_port_ctrl Ethernet Port Control srtuct.
  2434. * ETH_QUEUE rx_queue Number of Rx queue.
  2435. * int rx_desc_num Number of Rx descriptors
  2436. * int rx_buff_size Size of Rx buffer
  2437. * unsigned int rx_desc_base_addr Rx descriptors memory area base addr.
  2438. * unsigned int rx_buff_base_addr Rx buffer memory area base addr.
  2439. *
  2440. * OUTPUT:
  2441. * The routine updates the Ethernet port control struct with information
  2442. * regarding the Rx descriptors and buffers.
  2443. *
  2444. * RETURN:
  2445. * false if the given descriptors memory area is not aligned according to
  2446. * Ethernet SDMA specifications.
  2447. * true otherwise.
  2448. *
  2449. *******************************************************************************/
  2450. static bool ether_init_rx_desc_ring (ETH_PORT_INFO * p_eth_port_ctrl,
  2451. ETH_QUEUE rx_queue,
  2452. int rx_desc_num,
  2453. int rx_buff_size,
  2454. unsigned int rx_desc_base_addr,
  2455. unsigned int rx_buff_base_addr)
  2456. {
  2457. ETH_RX_DESC *p_rx_desc;
  2458. ETH_RX_DESC *p_rx_prev_desc; /* pointer to link with the last descriptor */
  2459. unsigned int buffer_addr;
  2460. int ix; /* a counter */
  2461. p_rx_desc = (ETH_RX_DESC *) rx_desc_base_addr;
  2462. p_rx_prev_desc = p_rx_desc;
  2463. buffer_addr = rx_buff_base_addr;
  2464. /* Rx desc Must be 4LW aligned (i.e. Descriptor_Address[3:0]=0000). */
  2465. if (rx_buff_base_addr & 0xF)
  2466. return false;
  2467. /* Rx buffers are limited to 64K bytes and Minimum size is 8 bytes */
  2468. if ((rx_buff_size < 8) || (rx_buff_size > RX_BUFFER_MAX_SIZE))
  2469. return false;
  2470. /* Rx buffers must be 64-bit aligned. */
  2471. if ((rx_buff_base_addr + rx_buff_size) & 0x7)
  2472. return false;
  2473. /* initialize the Rx descriptors ring */
  2474. for (ix = 0; ix < rx_desc_num; ix++) {
  2475. p_rx_desc->buf_size = rx_buff_size;
  2476. p_rx_desc->byte_cnt = 0x0000;
  2477. p_rx_desc->cmd_sts =
  2478. ETH_BUFFER_OWNED_BY_DMA | ETH_RX_ENABLE_INTERRUPT;
  2479. p_rx_desc->next_desc_ptr =
  2480. ((unsigned int) p_rx_desc) + RX_DESC_ALIGNED_SIZE;
  2481. p_rx_desc->buf_ptr = buffer_addr;
  2482. p_rx_desc->return_info = 0x00000000;
  2483. D_CACHE_FLUSH_LINE (p_rx_desc, 0);
  2484. buffer_addr += rx_buff_size;
  2485. p_rx_prev_desc = p_rx_desc;
  2486. p_rx_desc = (ETH_RX_DESC *)
  2487. ((unsigned int) p_rx_desc + RX_DESC_ALIGNED_SIZE);
  2488. }
  2489. /* Closing Rx descriptors ring */
  2490. p_rx_prev_desc->next_desc_ptr = (rx_desc_base_addr);
  2491. D_CACHE_FLUSH_LINE (p_rx_prev_desc, 0);
  2492. /* Save Rx desc pointer to driver struct. */
  2493. CURR_RFD_SET ((ETH_RX_DESC *) rx_desc_base_addr, rx_queue);
  2494. USED_RFD_SET ((ETH_RX_DESC *) rx_desc_base_addr, rx_queue);
  2495. p_eth_port_ctrl->p_rx_desc_area_base[rx_queue] =
  2496. (ETH_RX_DESC *) rx_desc_base_addr;
  2497. p_eth_port_ctrl->rx_desc_area_size[rx_queue] =
  2498. rx_desc_num * RX_DESC_ALIGNED_SIZE;
  2499. p_eth_port_ctrl->port_rx_queue_command |= (1 << rx_queue);
  2500. return true;
  2501. }
  2502. /*******************************************************************************
  2503. * ether_init_tx_desc_ring - Curve a Tx chain desc list and buffer in memory.
  2504. *
  2505. * DESCRIPTION:
  2506. * This function prepares a Tx chained list of descriptors and packet
  2507. * buffers in a form of a ring. The routine must be called after port
  2508. * initialization routine and before port start routine.
  2509. * The Ethernet SDMA engine uses CPU bus addresses to access the various
  2510. * devices in the system (i.e. DRAM). This function uses the ethernet
  2511. * struct 'virtual to physical' routine (set by the user) to set the ring
  2512. * with physical addresses.
  2513. *
  2514. * INPUT:
  2515. * ETH_PORT_INFO *p_eth_port_ctrl Ethernet Port Control srtuct.
  2516. * ETH_QUEUE tx_queue Number of Tx queue.
  2517. * int tx_desc_num Number of Tx descriptors
  2518. * int tx_buff_size Size of Tx buffer
  2519. * unsigned int tx_desc_base_addr Tx descriptors memory area base addr.
  2520. * unsigned int tx_buff_base_addr Tx buffer memory area base addr.
  2521. *
  2522. * OUTPUT:
  2523. * The routine updates the Ethernet port control struct with information
  2524. * regarding the Tx descriptors and buffers.
  2525. *
  2526. * RETURN:
  2527. * false if the given descriptors memory area is not aligned according to
  2528. * Ethernet SDMA specifications.
  2529. * true otherwise.
  2530. *
  2531. *******************************************************************************/
  2532. static bool ether_init_tx_desc_ring (ETH_PORT_INFO * p_eth_port_ctrl,
  2533. ETH_QUEUE tx_queue,
  2534. int tx_desc_num,
  2535. int tx_buff_size,
  2536. unsigned int tx_desc_base_addr,
  2537. unsigned int tx_buff_base_addr)
  2538. {
  2539. ETH_TX_DESC *p_tx_desc;
  2540. ETH_TX_DESC *p_tx_prev_desc;
  2541. unsigned int buffer_addr;
  2542. int ix; /* a counter */
  2543. /* save the first desc pointer to link with the last descriptor */
  2544. p_tx_desc = (ETH_TX_DESC *) tx_desc_base_addr;
  2545. p_tx_prev_desc = p_tx_desc;
  2546. buffer_addr = tx_buff_base_addr;
  2547. /* Tx desc Must be 4LW aligned (i.e. Descriptor_Address[3:0]=0000). */
  2548. if (tx_buff_base_addr & 0xF)
  2549. return false;
  2550. /* Tx buffers are limited to 64K bytes and Minimum size is 8 bytes */
  2551. if ((tx_buff_size > TX_BUFFER_MAX_SIZE)
  2552. || (tx_buff_size < TX_BUFFER_MIN_SIZE))
  2553. return false;
  2554. /* Initialize the Tx descriptors ring */
  2555. for (ix = 0; ix < tx_desc_num; ix++) {
  2556. p_tx_desc->byte_cnt = 0x0000;
  2557. p_tx_desc->l4i_chk = 0x0000;
  2558. p_tx_desc->cmd_sts = 0x00000000;
  2559. p_tx_desc->next_desc_ptr =
  2560. ((unsigned int) p_tx_desc) + TX_DESC_ALIGNED_SIZE;
  2561. p_tx_desc->buf_ptr = buffer_addr;
  2562. p_tx_desc->return_info = 0x00000000;
  2563. D_CACHE_FLUSH_LINE (p_tx_desc, 0);
  2564. buffer_addr += tx_buff_size;
  2565. p_tx_prev_desc = p_tx_desc;
  2566. p_tx_desc = (ETH_TX_DESC *)
  2567. ((unsigned int) p_tx_desc + TX_DESC_ALIGNED_SIZE);
  2568. }
  2569. /* Closing Tx descriptors ring */
  2570. p_tx_prev_desc->next_desc_ptr = tx_desc_base_addr;
  2571. D_CACHE_FLUSH_LINE (p_tx_prev_desc, 0);
  2572. /* Set Tx desc pointer in driver struct. */
  2573. CURR_TFD_SET ((ETH_TX_DESC *) tx_desc_base_addr, tx_queue);
  2574. USED_TFD_SET ((ETH_TX_DESC *) tx_desc_base_addr, tx_queue);
  2575. /* Init Tx ring base and size parameters */
  2576. p_eth_port_ctrl->p_tx_desc_area_base[tx_queue] =
  2577. (ETH_TX_DESC *) tx_desc_base_addr;
  2578. p_eth_port_ctrl->tx_desc_area_size[tx_queue] =
  2579. (tx_desc_num * TX_DESC_ALIGNED_SIZE);
  2580. /* Add the queue to the list of Tx queues of this port */
  2581. p_eth_port_ctrl->port_tx_queue_command |= (1 << tx_queue);
  2582. return true;
  2583. }
  2584. /*******************************************************************************
  2585. * eth_port_send - Send an Ethernet packet
  2586. *
  2587. * DESCRIPTION:
  2588. * This routine send a given packet described by p_pktinfo parameter. It
  2589. * supports transmitting of a packet spaned over multiple buffers. The
  2590. * routine updates 'curr' and 'first' indexes according to the packet
  2591. * segment passed to the routine. In case the packet segment is first,
  2592. * the 'first' index is update. In any case, the 'curr' index is updated.
  2593. * If the routine get into Tx resource error it assigns 'curr' index as
  2594. * 'first'. This way the function can abort Tx process of multiple
  2595. * descriptors per packet.
  2596. *
  2597. * INPUT:
  2598. * ETH_PORT_INFO *p_eth_port_ctrl Ethernet Port Control srtuct.
  2599. * ETH_QUEUE tx_queue Number of Tx queue.
  2600. * PKT_INFO *p_pkt_info User packet buffer.
  2601. *
  2602. * OUTPUT:
  2603. * Tx ring 'curr' and 'first' indexes are updated.
  2604. *
  2605. * RETURN:
  2606. * ETH_QUEUE_FULL in case of Tx resource error.
  2607. * ETH_ERROR in case the routine can not access Tx desc ring.
  2608. * ETH_QUEUE_LAST_RESOURCE if the routine uses the last Tx resource.
  2609. * ETH_OK otherwise.
  2610. *
  2611. *******************************************************************************/
  2612. static ETH_FUNC_RET_STATUS eth_port_send (ETH_PORT_INFO * p_eth_port_ctrl,
  2613. ETH_QUEUE tx_queue,
  2614. PKT_INFO * p_pkt_info)
  2615. {
  2616. volatile ETH_TX_DESC *p_tx_desc_first;
  2617. volatile ETH_TX_DESC *p_tx_desc_curr;
  2618. volatile ETH_TX_DESC *p_tx_next_desc_curr;
  2619. volatile ETH_TX_DESC *p_tx_desc_used;
  2620. unsigned int command_status;
  2621. /* Do not process Tx ring in case of Tx ring resource error */
  2622. if (p_eth_port_ctrl->tx_resource_err[tx_queue] == true)
  2623. return ETH_QUEUE_FULL;
  2624. /* Get the Tx Desc ring indexes */
  2625. CURR_TFD_GET (p_tx_desc_curr, tx_queue);
  2626. USED_TFD_GET (p_tx_desc_used, tx_queue);
  2627. if (p_tx_desc_curr == NULL)
  2628. return ETH_ERROR;
  2629. /* The following parameters are used to save readings from memory */
  2630. p_tx_next_desc_curr = TX_NEXT_DESC_PTR (p_tx_desc_curr, tx_queue);
  2631. command_status = p_pkt_info->cmd_sts | ETH_ZERO_PADDING | ETH_GEN_CRC;
  2632. if (command_status & (ETH_TX_FIRST_DESC)) {
  2633. /* Update first desc */
  2634. FIRST_TFD_SET (p_tx_desc_curr, tx_queue);
  2635. p_tx_desc_first = p_tx_desc_curr;
  2636. } else {
  2637. FIRST_TFD_GET (p_tx_desc_first, tx_queue);
  2638. command_status |= ETH_BUFFER_OWNED_BY_DMA;
  2639. }
  2640. /* Buffers with a payload smaller than 8 bytes must be aligned to 64-bit */
  2641. /* boundary. We use the memory allocated for Tx descriptor. This memory */
  2642. /* located in TX_BUF_OFFSET_IN_DESC offset within the Tx descriptor. */
  2643. if (p_pkt_info->byte_cnt <= 8) {
  2644. printf ("You have failed in the < 8 bytes errata - fixme\n"); /* RABEEH - TBD */
  2645. return ETH_ERROR;
  2646. p_tx_desc_curr->buf_ptr =
  2647. (unsigned int) p_tx_desc_curr + TX_BUF_OFFSET_IN_DESC;
  2648. eth_b_copy (p_pkt_info->buf_ptr, p_tx_desc_curr->buf_ptr,
  2649. p_pkt_info->byte_cnt);
  2650. } else
  2651. p_tx_desc_curr->buf_ptr = p_pkt_info->buf_ptr;
  2652. p_tx_desc_curr->byte_cnt = p_pkt_info->byte_cnt;
  2653. p_tx_desc_curr->return_info = p_pkt_info->return_info;
  2654. if (p_pkt_info->cmd_sts & (ETH_TX_LAST_DESC)) {
  2655. /* Set last desc with DMA ownership and interrupt enable. */
  2656. p_tx_desc_curr->cmd_sts = command_status |
  2657. ETH_BUFFER_OWNED_BY_DMA | ETH_TX_ENABLE_INTERRUPT;
  2658. if (p_tx_desc_curr != p_tx_desc_first)
  2659. p_tx_desc_first->cmd_sts |= ETH_BUFFER_OWNED_BY_DMA;
  2660. /* Flush CPU pipe */
  2661. D_CACHE_FLUSH_LINE ((unsigned int) p_tx_desc_curr, 0);
  2662. D_CACHE_FLUSH_LINE ((unsigned int) p_tx_desc_first, 0);
  2663. CPU_PIPE_FLUSH;
  2664. /* Apply send command */
  2665. ETH_ENABLE_TX_QUEUE (tx_queue, p_eth_port_ctrl->port_num);
  2666. /* Finish Tx packet. Update first desc in case of Tx resource error */
  2667. p_tx_desc_first = p_tx_next_desc_curr;
  2668. FIRST_TFD_SET (p_tx_desc_first, tx_queue);
  2669. } else {
  2670. p_tx_desc_curr->cmd_sts = command_status;
  2671. D_CACHE_FLUSH_LINE ((unsigned int) p_tx_desc_curr, 0);
  2672. }
  2673. /* Check for ring index overlap in the Tx desc ring */
  2674. if (p_tx_next_desc_curr == p_tx_desc_used) {
  2675. /* Update the current descriptor */
  2676. CURR_TFD_SET (p_tx_desc_first, tx_queue);
  2677. p_eth_port_ctrl->tx_resource_err[tx_queue] = true;
  2678. return ETH_QUEUE_LAST_RESOURCE;
  2679. } else {
  2680. /* Update the current descriptor */
  2681. CURR_TFD_SET (p_tx_next_desc_curr, tx_queue);
  2682. return ETH_OK;
  2683. }
  2684. }
  2685. /*******************************************************************************
  2686. * eth_tx_return_desc - Free all used Tx descriptors
  2687. *
  2688. * DESCRIPTION:
  2689. * This routine returns the transmitted packet information to the caller.
  2690. * It uses the 'first' index to support Tx desc return in case a transmit
  2691. * of a packet spanned over multiple buffer still in process.
  2692. * In case the Tx queue was in "resource error" condition, where there are
  2693. * no available Tx resources, the function resets the resource error flag.
  2694. *
  2695. * INPUT:
  2696. * ETH_PORT_INFO *p_eth_port_ctrl Ethernet Port Control srtuct.
  2697. * ETH_QUEUE tx_queue Number of Tx queue.
  2698. * PKT_INFO *p_pkt_info User packet buffer.
  2699. *
  2700. * OUTPUT:
  2701. * Tx ring 'first' and 'used' indexes are updated.
  2702. *
  2703. * RETURN:
  2704. * ETH_ERROR in case the routine can not access Tx desc ring.
  2705. * ETH_RETRY in case there is transmission in process.
  2706. * ETH_END_OF_JOB if the routine has nothing to release.
  2707. * ETH_OK otherwise.
  2708. *
  2709. *******************************************************************************/
  2710. static ETH_FUNC_RET_STATUS eth_tx_return_desc (ETH_PORT_INFO *
  2711. p_eth_port_ctrl,
  2712. ETH_QUEUE tx_queue,
  2713. PKT_INFO * p_pkt_info)
  2714. {
  2715. volatile ETH_TX_DESC *p_tx_desc_used = NULL;
  2716. volatile ETH_TX_DESC *p_tx_desc_first = NULL;
  2717. unsigned int command_status;
  2718. /* Get the Tx Desc ring indexes */
  2719. USED_TFD_GET (p_tx_desc_used, tx_queue);
  2720. FIRST_TFD_GET (p_tx_desc_first, tx_queue);
  2721. /* Sanity check */
  2722. if (p_tx_desc_used == NULL)
  2723. return ETH_ERROR;
  2724. command_status = p_tx_desc_used->cmd_sts;
  2725. /* Still transmitting... */
  2726. if (command_status & (ETH_BUFFER_OWNED_BY_DMA)) {
  2727. D_CACHE_FLUSH_LINE ((unsigned int) p_tx_desc_used, 0);
  2728. return ETH_RETRY;
  2729. }
  2730. /* Stop release. About to overlap the current available Tx descriptor */
  2731. if ((p_tx_desc_used == p_tx_desc_first) &&
  2732. (p_eth_port_ctrl->tx_resource_err[tx_queue] == false)) {
  2733. D_CACHE_FLUSH_LINE ((unsigned int) p_tx_desc_used, 0);
  2734. return ETH_END_OF_JOB;
  2735. }
  2736. /* Pass the packet information to the caller */
  2737. p_pkt_info->cmd_sts = command_status;
  2738. p_pkt_info->return_info = p_tx_desc_used->return_info;
  2739. p_tx_desc_used->return_info = 0;
  2740. /* Update the next descriptor to release. */
  2741. USED_TFD_SET (TX_NEXT_DESC_PTR (p_tx_desc_used, tx_queue), tx_queue);
  2742. /* Any Tx return cancels the Tx resource error status */
  2743. if (p_eth_port_ctrl->tx_resource_err[tx_queue] == true)
  2744. p_eth_port_ctrl->tx_resource_err[tx_queue] = false;
  2745. D_CACHE_FLUSH_LINE ((unsigned int) p_tx_desc_used, 0);
  2746. return ETH_OK;
  2747. }
  2748. /*******************************************************************************
  2749. * eth_port_receive - Get received information from Rx ring.
  2750. *
  2751. * DESCRIPTION:
  2752. * This routine returns the received data to the caller. There is no
  2753. * data copying during routine operation. All information is returned
  2754. * using pointer to packet information struct passed from the caller.
  2755. * If the routine exhausts Rx ring resources then the resource error flag
  2756. * is set.
  2757. *
  2758. * INPUT:
  2759. * ETH_PORT_INFO *p_eth_port_ctrl Ethernet Port Control srtuct.
  2760. * ETH_QUEUE rx_queue Number of Rx queue.
  2761. * PKT_INFO *p_pkt_info User packet buffer.
  2762. *
  2763. * OUTPUT:
  2764. * Rx ring current and used indexes are updated.
  2765. *
  2766. * RETURN:
  2767. * ETH_ERROR in case the routine can not access Rx desc ring.
  2768. * ETH_QUEUE_FULL if Rx ring resources are exhausted.
  2769. * ETH_END_OF_JOB if there is no received data.
  2770. * ETH_OK otherwise.
  2771. *
  2772. *******************************************************************************/
  2773. static ETH_FUNC_RET_STATUS eth_port_receive (ETH_PORT_INFO * p_eth_port_ctrl,
  2774. ETH_QUEUE rx_queue,
  2775. PKT_INFO * p_pkt_info)
  2776. {
  2777. volatile ETH_RX_DESC *p_rx_curr_desc;
  2778. volatile ETH_RX_DESC *p_rx_next_curr_desc;
  2779. volatile ETH_RX_DESC *p_rx_used_desc;
  2780. unsigned int command_status;
  2781. /* Do not process Rx ring in case of Rx ring resource error */
  2782. if (p_eth_port_ctrl->rx_resource_err[rx_queue] == true) {
  2783. printf ("\nRx Queue is full ...\n");
  2784. return ETH_QUEUE_FULL;
  2785. }
  2786. /* Get the Rx Desc ring 'curr and 'used' indexes */
  2787. CURR_RFD_GET (p_rx_curr_desc, rx_queue);
  2788. USED_RFD_GET (p_rx_used_desc, rx_queue);
  2789. /* Sanity check */
  2790. if (p_rx_curr_desc == NULL)
  2791. return ETH_ERROR;
  2792. /* The following parameters are used to save readings from memory */
  2793. p_rx_next_curr_desc = RX_NEXT_DESC_PTR (p_rx_curr_desc, rx_queue);
  2794. command_status = p_rx_curr_desc->cmd_sts;
  2795. /* Nothing to receive... */
  2796. if (command_status & (ETH_BUFFER_OWNED_BY_DMA)) {
  2797. /* DP(printf("Rx: command_status: %08x\n", command_status)); */
  2798. D_CACHE_FLUSH_LINE ((unsigned int) p_rx_curr_desc, 0);
  2799. /* DP(printf("\nETH_END_OF_JOB ...\n"));*/
  2800. return ETH_END_OF_JOB;
  2801. }
  2802. p_pkt_info->byte_cnt = (p_rx_curr_desc->byte_cnt) - RX_BUF_OFFSET;
  2803. p_pkt_info->cmd_sts = command_status;
  2804. p_pkt_info->buf_ptr = (p_rx_curr_desc->buf_ptr) + RX_BUF_OFFSET;
  2805. p_pkt_info->return_info = p_rx_curr_desc->return_info;
  2806. p_pkt_info->l4i_chk = p_rx_curr_desc->buf_size; /* IP fragment indicator */
  2807. /* Clean the return info field to indicate that the packet has been */
  2808. /* moved to the upper layers */
  2809. p_rx_curr_desc->return_info = 0;
  2810. /* Update 'curr' in data structure */
  2811. CURR_RFD_SET (p_rx_next_curr_desc, rx_queue);
  2812. /* Rx descriptors resource exhausted. Set the Rx ring resource error flag */
  2813. if (p_rx_next_curr_desc == p_rx_used_desc)
  2814. p_eth_port_ctrl->rx_resource_err[rx_queue] = true;
  2815. D_CACHE_FLUSH_LINE ((unsigned int) p_rx_curr_desc, 0);
  2816. CPU_PIPE_FLUSH;
  2817. return ETH_OK;
  2818. }
  2819. /*******************************************************************************
  2820. * eth_rx_return_buff - Returns a Rx buffer back to the Rx ring.
  2821. *
  2822. * DESCRIPTION:
  2823. * This routine returns a Rx buffer back to the Rx ring. It retrieves the
  2824. * next 'used' descriptor and attached the returned buffer to it.
  2825. * In case the Rx ring was in "resource error" condition, where there are
  2826. * no available Rx resources, the function resets the resource error flag.
  2827. *
  2828. * INPUT:
  2829. * ETH_PORT_INFO *p_eth_port_ctrl Ethernet Port Control srtuct.
  2830. * ETH_QUEUE rx_queue Number of Rx queue.
  2831. * PKT_INFO *p_pkt_info Information on the returned buffer.
  2832. *
  2833. * OUTPUT:
  2834. * New available Rx resource in Rx descriptor ring.
  2835. *
  2836. * RETURN:
  2837. * ETH_ERROR in case the routine can not access Rx desc ring.
  2838. * ETH_OK otherwise.
  2839. *
  2840. *******************************************************************************/
  2841. static ETH_FUNC_RET_STATUS eth_rx_return_buff (ETH_PORT_INFO *
  2842. p_eth_port_ctrl,
  2843. ETH_QUEUE rx_queue,
  2844. PKT_INFO * p_pkt_info)
  2845. {
  2846. volatile ETH_RX_DESC *p_used_rx_desc; /* Where to return Rx resource */
  2847. /* Get 'used' Rx descriptor */
  2848. USED_RFD_GET (p_used_rx_desc, rx_queue);
  2849. /* Sanity check */
  2850. if (p_used_rx_desc == NULL)
  2851. return ETH_ERROR;
  2852. p_used_rx_desc->buf_ptr = p_pkt_info->buf_ptr;
  2853. p_used_rx_desc->return_info = p_pkt_info->return_info;
  2854. p_used_rx_desc->byte_cnt = p_pkt_info->byte_cnt;
  2855. p_used_rx_desc->buf_size = MV64460_RX_BUFFER_SIZE; /* Reset Buffer size */
  2856. /* Flush the write pipe */
  2857. CPU_PIPE_FLUSH;
  2858. /* Return the descriptor to DMA ownership */
  2859. p_used_rx_desc->cmd_sts =
  2860. ETH_BUFFER_OWNED_BY_DMA | ETH_RX_ENABLE_INTERRUPT;
  2861. /* Flush descriptor and CPU pipe */
  2862. D_CACHE_FLUSH_LINE ((unsigned int) p_used_rx_desc, 0);
  2863. CPU_PIPE_FLUSH;
  2864. /* Move the used descriptor pointer to the next descriptor */
  2865. USED_RFD_SET (RX_NEXT_DESC_PTR (p_used_rx_desc, rx_queue), rx_queue);
  2866. /* Any Rx return cancels the Rx resource error status */
  2867. if (p_eth_port_ctrl->rx_resource_err[rx_queue] == true)
  2868. p_eth_port_ctrl->rx_resource_err[rx_queue] = false;
  2869. return ETH_OK;
  2870. }
  2871. /*******************************************************************************
  2872. * eth_port_set_rx_coal - Sets coalescing interrupt mechanism on RX path
  2873. *
  2874. * DESCRIPTION:
  2875. * This routine sets the RX coalescing interrupt mechanism parameter.
  2876. * This parameter is a timeout counter, that counts in 64 t_clk
  2877. * chunks ; that when timeout event occurs a maskable interrupt
  2878. * occurs.
  2879. * The parameter is calculated using the tClk of the MV-643xx chip
  2880. * , and the required delay of the interrupt in usec.
  2881. *
  2882. * INPUT:
  2883. * ETH_PORT eth_port_num Ethernet port number
  2884. * unsigned int t_clk t_clk of the MV-643xx chip in HZ units
  2885. * unsigned int delay Delay in usec
  2886. *
  2887. * OUTPUT:
  2888. * Interrupt coalescing mechanism value is set in MV-643xx chip.
  2889. *
  2890. * RETURN:
  2891. * The interrupt coalescing value set in the gigE port.
  2892. *
  2893. *******************************************************************************/
  2894. #if 0 /* FIXME */
  2895. static unsigned int eth_port_set_rx_coal (ETH_PORT eth_port_num,
  2896. unsigned int t_clk,
  2897. unsigned int delay)
  2898. {
  2899. unsigned int coal;
  2900. coal = ((t_clk / 1000000) * delay) / 64;
  2901. /* Set RX Coalescing mechanism */
  2902. MV_REG_WRITE (MV64460_ETH_SDMA_CONFIG_REG (eth_port_num),
  2903. ((coal & 0x3fff) << 8) |
  2904. (MV_REG_READ
  2905. (MV64460_ETH_SDMA_CONFIG_REG (eth_port_num))
  2906. & 0xffc000ff));
  2907. return coal;
  2908. }
  2909. #endif
  2910. /*******************************************************************************
  2911. * eth_port_set_tx_coal - Sets coalescing interrupt mechanism on TX path
  2912. *
  2913. * DESCRIPTION:
  2914. * This routine sets the TX coalescing interrupt mechanism parameter.
  2915. * This parameter is a timeout counter, that counts in 64 t_clk
  2916. * chunks ; that when timeout event occurs a maskable interrupt
  2917. * occurs.
  2918. * The parameter is calculated using the t_cLK frequency of the
  2919. * MV-643xx chip and the required delay in the interrupt in uSec
  2920. *
  2921. * INPUT:
  2922. * ETH_PORT eth_port_num Ethernet port number
  2923. * unsigned int t_clk t_clk of the MV-643xx chip in HZ units
  2924. * unsigned int delay Delay in uSeconds
  2925. *
  2926. * OUTPUT:
  2927. * Interrupt coalescing mechanism value is set in MV-643xx chip.
  2928. *
  2929. * RETURN:
  2930. * The interrupt coalescing value set in the gigE port.
  2931. *
  2932. *******************************************************************************/
  2933. #if 0 /* FIXME */
  2934. static unsigned int eth_port_set_tx_coal (ETH_PORT eth_port_num,
  2935. unsigned int t_clk,
  2936. unsigned int delay)
  2937. {
  2938. unsigned int coal;
  2939. coal = ((t_clk / 1000000) * delay) / 64;
  2940. /* Set TX Coalescing mechanism */
  2941. MV_REG_WRITE (MV64460_ETH_TX_FIFO_URGENT_THRESHOLD_REG (eth_port_num),
  2942. coal << 4);
  2943. return coal;
  2944. }
  2945. #endif
  2946. /*******************************************************************************
  2947. * eth_b_copy - Copy bytes from source to destination
  2948. *
  2949. * DESCRIPTION:
  2950. * This function supports the eight bytes limitation on Tx buffer size.
  2951. * The routine will zero eight bytes starting from the destination address
  2952. * followed by copying bytes from the source address to the destination.
  2953. *
  2954. * INPUT:
  2955. * unsigned int src_addr 32 bit source address.
  2956. * unsigned int dst_addr 32 bit destination address.
  2957. * int byte_count Number of bytes to copy.
  2958. *
  2959. * OUTPUT:
  2960. * See description.
  2961. *
  2962. * RETURN:
  2963. * None.
  2964. *
  2965. *******************************************************************************/
  2966. static void eth_b_copy (unsigned int src_addr, unsigned int dst_addr,
  2967. int byte_count)
  2968. {
  2969. /* Zero the dst_addr area */
  2970. *(unsigned int *) dst_addr = 0x0;
  2971. while (byte_count != 0) {
  2972. *(char *) dst_addr = *(char *) src_addr;
  2973. dst_addr++;
  2974. src_addr++;
  2975. byte_count--;
  2976. }
  2977. }