mv_eth.c 103 KB

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