mv_eth.c 104 KB

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