mv_eth.c 104 KB

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