mv_eth.c 103 KB

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