synopGMAC_Dev.c 121 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705
  1. /** \file
  2. * This file defines the synopsys GMAC device dependent functions.
  3. * Most of the operations on the GMAC device are available in this file.
  4. * Functions for initiliasing and accessing MAC/DMA/PHY registers and the DMA descriptors
  5. * are encapsulated in this file. The functions are platform/host/OS independent.
  6. * These functions in turn use the low level device dependent (HAL) functions to
  7. * access the register space.
  8. * \internal
  9. * ------------------------REVISION HISTORY---------------------------------
  10. * Synopsys 01/Aug/2007 Created
  11. */
  12. /*
  13. * File : synopGMAC_Dev.c
  14. * This file is part of RT-Thread RTOS
  15. * COPYRIGHT (C) chinesebear
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 2 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License along
  28. * with this program; if not, write to the Free Software Foundation, Inc.,
  29. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  30. *
  31. * Change Logs:
  32. * Date Author Notes
  33. * 2017-08-24 chinesebear first version
  34. */
  35. #include "synopGMAC_Dev.h"
  36. #include <rthw.h>
  37. #include <rtthread.h>
  38. #define UNUSED 1
  39. /**
  40. * Function to set the MDC clock for mdio transactiona
  41. *
  42. * @param[in] pointer to device structure.
  43. * @param[in] clk divider value.
  44. * \return Reuturns 0 on success else return the error value.
  45. */
  46. s32 synopGMAC_set_mdc_clk_div(synopGMACdevice *gmacdev,u32 clk_div_val)
  47. {
  48. u32 orig_data;
  49. orig_data = synopGMACReadReg(gmacdev->MacBase,GmacGmiiAddr); //set the mdc clock to the user defined value
  50. orig_data &= (~ GmiiCsrClkMask);
  51. orig_data |= clk_div_val;
  52. synopGMACWriteReg(gmacdev->MacBase, GmacGmiiAddr ,orig_data);
  53. return 0;
  54. }
  55. /**
  56. * Returns the current MDC divider value programmed in the ip.
  57. *
  58. * @param[in] pointer to device structure.
  59. * @param[in] clk divider value.
  60. * \return Returns the MDC divider value read.
  61. */
  62. u32 synopGMAC_get_mdc_clk_div(synopGMACdevice *gmacdev)
  63. {
  64. u32 data;
  65. data = synopGMACReadReg(gmacdev->MacBase,GmacGmiiAddr);
  66. data &= GmiiCsrClkMask;
  67. return data;
  68. }
  69. /**
  70. * Function to read the Phy register. The access to phy register
  71. * is a slow process as the data is moved accross MDI/MDO interface
  72. * @param[in] pointer to Register Base (It is the mac base in our case) .
  73. * @param[in] PhyBase register is the index of one of supported 32 PHY devices.
  74. * @param[in] Register offset is the index of one of the 32 phy register.
  75. * @param[out] u16 data read from the respective phy register (only valid iff return value is 0).
  76. * \return Returns 0 on success else return the error status.
  77. */
  78. s32 synopGMAC_read_phy_reg(u32 RegBase,u32 PhyBase, u32 RegOffset, u16 * data )
  79. {
  80. u32 addr;
  81. u32 loop_variable;
  82. addr = ((PhyBase << GmiiDevShift) & GmiiDevMask) | ((RegOffset << GmiiRegShift) & GmiiRegMask)
  83. | GmiiCsrClk3; //sw: add GmiiCsrClk
  84. addr = addr | GmiiBusy ; //Gmii busy bit
  85. synopGMACWriteReg(RegBase,GmacGmiiAddr,addr);
  86. //write the address from where the data to be read in GmiiGmiiAddr register of synopGMAC ip
  87. for(loop_variable = 0; loop_variable < DEFAULT_LOOP_VARIABLE; loop_variable++){
  88. //Wait till the busy bit gets cleared within a certain amount of time
  89. if (!(synopGMACReadReg(RegBase,GmacGmiiAddr) & GmiiBusy)){
  90. break;
  91. }
  92. plat_delay(DEFAULT_DELAY_VARIABLE);
  93. }
  94. if(loop_variable < DEFAULT_LOOP_VARIABLE)
  95. * data = (u16)(synopGMACReadReg(RegBase,GmacGmiiData) & 0xFFFF);
  96. else{
  97. TR("Error::: PHY not responding Busy bit didnot get cleared !!!!!!\n");
  98. return -ESYNOPGMACPHYERR;
  99. }
  100. //sw
  101. #if SYNOP_REG_DEBUG
  102. printf("read phy reg: offset = 0x%x\tdata = 0x%x\n",RegOffset,*data);
  103. #endif
  104. return -ESYNOPGMACNOERR;
  105. }
  106. /**
  107. * Function to write to the Phy register. The access to phy register
  108. * is a slow process as the data is moved accross MDI/MDO interface
  109. * @param[in] pointer to Register Base (It is the mac base in our case) .
  110. * @param[in] PhyBase register is the index of one of supported 32 PHY devices.
  111. * @param[in] Register offset is the index of one of the 32 phy register.
  112. * @param[in] data to be written to the respective phy register.
  113. * \return Returns 0 on success else return the error status.
  114. */
  115. s32 synopGMAC_write_phy_reg(u32 RegBase, u32 PhyBase, u32 RegOffset, u16 data)
  116. {
  117. u32 addr;
  118. u32 loop_variable;
  119. synopGMACWriteReg(RegBase,GmacGmiiData,data); // write the data in to GmacGmiiData register of synopGMAC ip
  120. addr = ((PhyBase << GmiiDevShift) & GmiiDevMask) | ((RegOffset << GmiiRegShift) & GmiiRegMask) | GmiiWrite | GmiiCsrClk3; //sw: add GmiiCsrclk
  121. addr = addr | GmiiBusy ; //set Gmii clk to 20-35 Mhz and Gmii busy bit
  122. synopGMACWriteReg(RegBase,GmacGmiiAddr,addr);
  123. for(loop_variable = 0; loop_variable < DEFAULT_LOOP_VARIABLE; loop_variable++){
  124. if (!(synopGMACReadReg(RegBase,GmacGmiiAddr) & GmiiBusy)){
  125. break;
  126. }
  127. plat_delay(DEFAULT_DELAY_VARIABLE);
  128. }
  129. if(loop_variable < DEFAULT_LOOP_VARIABLE){
  130. return -ESYNOPGMACNOERR;
  131. }
  132. else{
  133. TR("Error::: PHY not responding Busy bit didnot get cleared !!!!!!\n");
  134. return -ESYNOPGMACPHYERR;
  135. }
  136. #if SYNOP_REG_DEBUG
  137. printf("write phy reg: offset = 0x%x\tdata = 0x%x",RegOffset,data);
  138. #endif
  139. }
  140. /**
  141. * Function to configure the phy in loopback mode.
  142. *
  143. * @param[in] pointer to synopGMACdevice.
  144. * @param[in] enable or disable the loopback.
  145. * \return 0 on success else return the error status.
  146. * \note Don't get confused with mac loop-back synopGMAC_loopback_on(synopGMACdevice *)
  147. * and synopGMAC_loopback_off(synopGMACdevice *) functions.
  148. */
  149. #if UNUSED
  150. s32 synopGMAC_phy_loopback(synopGMACdevice *gmacdev, bool loopback)
  151. {
  152. s32 status = -ESYNOPGMACNOERR;
  153. u16 *temp;
  154. status = synopGMAC_read_phy_reg(gmacdev->MacBase, gmacdev->PhyBase, PHY_CONTROL_REG,temp);
  155. if(loopback)
  156. *temp |= 0x4000;
  157. else
  158. *temp = *temp;
  159. status = synopGMAC_write_phy_reg(gmacdev->MacBase, gmacdev->PhyBase, PHY_CONTROL_REG, *temp);
  160. return status;
  161. }
  162. #endif
  163. /**
  164. * Function to read the GMAC IP Version and populates the same in device data structure.
  165. * @param[in] pointer to synopGMACdevice.
  166. * \return Always return 0.
  167. */
  168. s32 synopGMAC_read_version (synopGMACdevice * gmacdev)
  169. {
  170. u32 data = 0;
  171. data = synopGMACReadReg(gmacdev->MacBase, GmacVersion );
  172. gmacdev->Version = data;
  173. return 0;
  174. }
  175. /**
  176. * Function to reset the GMAC core.
  177. * This reests the DMA and GMAC core. After reset all the registers holds their respective reset value
  178. * @param[in] pointer to synopGMACdevice.
  179. * \return 0 on success else return the error status.
  180. */
  181. s32 synopGMAC_reset (synopGMACdevice * gmacdev)
  182. {
  183. u32 data = 0;
  184. synopGMACWriteReg(gmacdev->DmaBase, DmaBusMode ,DmaResetOn);
  185. plat_delay(DEFAULT_LOOP_VARIABLE);
  186. data = synopGMACReadReg(gmacdev->DmaBase, DmaBusMode);
  187. TR("DATA after Reset = %08x\n",data);
  188. return 0;
  189. }
  190. /**
  191. * Function to program DMA bus mode register.
  192. *
  193. * The Bus Mode register is programmed with the value given. The bits to be set are
  194. * bit wise or'ed and sent as the second argument to this function.
  195. * @param[in] pointer to synopGMACdevice.
  196. * @param[in] the data to be programmed.
  197. * \return 0 on success else return the error status.
  198. */
  199. s32 synopGMAC_dma_bus_mode_init(synopGMACdevice * gmacdev, u32 init_value )
  200. {
  201. synopGMACWriteReg(gmacdev->DmaBase, DmaBusMode ,init_value );
  202. return 0;
  203. }
  204. /**
  205. * Function to program DMA Control register.
  206. *
  207. * The Dma Control register is programmed with the value given. The bits to be set are
  208. * bit wise or'ed and sent as the second argument to this function.
  209. * @param[in] pointer to synopGMACdevice.
  210. * @param[in] the data to be programmed.
  211. * \return 0 on success else return the error status.
  212. */
  213. s32 synopGMAC_dma_control_init(synopGMACdevice * gmacdev, u32 init_value )
  214. {
  215. synopGMACWriteReg(gmacdev->DmaBase, DmaControl, init_value);
  216. return 0;
  217. }
  218. /*Gmac configuration functions*/
  219. /**
  220. * Enable the watchdog timer on the receiver.
  221. * When enabled, Gmac enables Watchdog timer, and GMAC allows no more than
  222. * 2048 bytes of data (10,240 if Jumbo frame enabled).
  223. * @param[in] pointer to synopGMACdevice.
  224. * \return returns void.
  225. */
  226. void synopGMAC_wd_enable(synopGMACdevice * gmacdev)
  227. {
  228. synopGMACClearBits(gmacdev->MacBase, GmacConfig, GmacWatchdog);
  229. return;
  230. }
  231. /**
  232. * Disable the watchdog timer on the receiver.
  233. * When disabled, Gmac disabled watchdog timer, and can receive frames up to
  234. * 16,384 bytes.
  235. * @param[in] pointer to synopGMACdevice.
  236. * \return returns void.
  237. */
  238. void synopGMAC_wd_disable(synopGMACdevice * gmacdev)
  239. {
  240. synopGMACSetBits(gmacdev->MacBase, GmacConfig, GmacWatchdog);
  241. return;
  242. }
  243. /**
  244. * Enables the Jabber frame support.
  245. * When enabled, GMAC disabled the jabber timer, and can transfer 16,384 byte frames.
  246. * @param[in] pointer to synopGMACdevice.
  247. * \return returns void.
  248. */
  249. void synopGMAC_jab_enable(synopGMACdevice * gmacdev)
  250. {
  251. synopGMACSetBits(gmacdev->MacBase, GmacConfig, GmacJabber);
  252. return;
  253. }
  254. /**
  255. * Disables the Jabber frame support.
  256. * When disabled, GMAC enables jabber timer. It cuts of transmitter if application
  257. * sends more than 2048 bytes of data (10240 if Jumbo frame enabled).
  258. * @param[in] pointer to synopGMACdevice.
  259. * \return returns void.
  260. */
  261. #if UNUSED
  262. void synopGMAC_jab_disable(synopGMACdevice * gmacdev)
  263. {
  264. synopGMACClearBits(gmacdev->MacBase, GmacConfig, GmacJabber);
  265. return;
  266. }
  267. #endif
  268. /**
  269. * Enables Frame bursting (Only in Half Duplex Mode).
  270. * When enabled, GMAC allows frame bursting in GMII Half Duplex mode.
  271. * Reserved in 10/100 and Full-Duplex configurations.
  272. * @param[in] pointer to synopGMACdevice.
  273. * \return returns void.
  274. */
  275. void synopGMAC_frame_burst_enable(synopGMACdevice * gmacdev)
  276. {
  277. synopGMACSetBits(gmacdev->MacBase, GmacConfig, GmacFrameBurst);
  278. return;
  279. }
  280. /**
  281. * Disables Frame bursting.
  282. * When Disabled, frame bursting is not supported.
  283. * @param[in] pointer to synopGMACdevice.
  284. * \return returns void.
  285. */
  286. #if UNUSED
  287. void synopGMAC_frame_burst_disable(synopGMACdevice * gmacdev)
  288. {
  289. synopGMACClearBits(gmacdev->MacBase, GmacConfig, GmacFrameBurst);
  290. return;
  291. }
  292. #endif
  293. /**
  294. * Enable Jumbo frame support.
  295. * When Enabled GMAC supports jumbo frames of 9018/9022(VLAN tagged).
  296. * Giant frame error is not reported in receive frame status.
  297. * @param[in] pointer to synopGMACdevice.
  298. * \return returns void.
  299. */
  300. #if UNUSED
  301. void synopGMAC_jumbo_frame_enable(synopGMACdevice * gmacdev)
  302. {
  303. synopGMACSetBits(gmacdev->MacBase, GmacConfig, GmacJumboFrame);
  304. return;
  305. }
  306. #endif
  307. /**
  308. * Disable Jumbo frame support.
  309. * When Disabled GMAC does not supports jumbo frames.
  310. * Giant frame error is reported in receive frame status.
  311. * @param[in] pointer to synopGMACdevice.
  312. * \return returns void.
  313. */
  314. void synopGMAC_jumbo_frame_disable(synopGMACdevice * gmacdev)
  315. {
  316. synopGMACClearBits(gmacdev->MacBase, GmacConfig, GmacJumboFrame);
  317. return;
  318. }
  319. /**
  320. * Disable Carrier sense.
  321. * When Disabled GMAC ignores CRS signal during frame transmission
  322. * in half duplex mode.
  323. * @param[in] pointer to synopGMACdevice.
  324. * \return void.
  325. */
  326. #if UNUSED
  327. void synopGMAC_disable_crs(synopGMACdevice * gmacdev)
  328. {
  329. synopGMACSetBits(gmacdev->MacBase, GmacConfig, GmacDisableCrs);
  330. return;
  331. }
  332. #endif
  333. /**
  334. * Selects the GMII port.
  335. * When called GMII (1000Mbps) port is selected (programmable only in 10/100/1000 Mbps configuration).
  336. * @param[in] pointer to synopGMACdevice.
  337. * \return returns void.
  338. */
  339. void synopGMAC_select_gmii(synopGMACdevice * gmacdev)
  340. {
  341. synopGMACClearBits(gmacdev->MacBase, GmacConfig, GmacMiiGmii);
  342. return;
  343. }
  344. /**
  345. * Selects the MII port.
  346. * When called MII (10/100Mbps) port is selected (programmable only in 10/100/1000 Mbps configuration).
  347. * @param[in] pointer to synopGMACdevice.
  348. * \return returns void.
  349. */
  350. void synopGMAC_select_mii(synopGMACdevice * gmacdev)
  351. {
  352. synopGMACSetBits(gmacdev->MacBase, GmacConfig, GmacMiiGmii);
  353. return;
  354. }
  355. /**
  356. * Enables Receive Own bit (Only in Half Duplex Mode).
  357. * When enaled GMAC receives all the packets given by phy while transmitting.
  358. * @param[in] pointer to synopGMACdevice.
  359. * \return returns void.
  360. */
  361. void synopGMAC_rx_own_enable(synopGMACdevice * gmacdev)
  362. {
  363. synopGMACClearBits(gmacdev->MacBase, GmacConfig, GmacRxOwn);
  364. return;
  365. }
  366. /**
  367. * Disables Receive Own bit (Only in Half Duplex Mode).
  368. * When enaled GMAC disables the reception of frames when gmii_txen_o is asserted.
  369. * @param[in] pointer to synopGMACdevice.
  370. * \return returns void.
  371. */
  372. #if UNUSED
  373. void synopGMAC_rx_own_disable(synopGMACdevice * gmacdev)
  374. {
  375. synopGMACSetBits(gmacdev->MacBase, GmacConfig, GmacRxOwn);
  376. return;
  377. }
  378. #endif
  379. /**
  380. * Sets the GMAC in loopback mode.
  381. * When on GMAC operates in loop-back mode at GMII/MII.
  382. * @param[in] pointer to synopGMACdevice.
  383. * \return returns void.
  384. * \note (G)MII Receive clock is required for loopback to work properly, as transmit clock is
  385. * not looped back internally.
  386. */
  387. void synopGMAC_loopback_on(synopGMACdevice * gmacdev)
  388. {
  389. synopGMACSetBits(gmacdev->MacBase, GmacConfig, GmacLoopback);
  390. return;
  391. }
  392. /**
  393. * Sets the GMAC in Normal mode.
  394. * @param[in] pointer to synopGMACdevice.
  395. * \return returns void.
  396. */
  397. void synopGMAC_loopback_off(synopGMACdevice * gmacdev)
  398. {
  399. synopGMACClearBits(gmacdev->MacBase, GmacConfig, GmacLoopback);
  400. return;
  401. }
  402. /**
  403. * Sets the GMAC core in Full-Duplex mode.
  404. * @param[in] pointer to synopGMACdevice.
  405. * \return returns void.
  406. */
  407. void synopGMAC_set_full_duplex(synopGMACdevice * gmacdev)
  408. {
  409. synopGMACSetBits(gmacdev->MacBase, GmacConfig, GmacDuplex);
  410. return;
  411. }
  412. /**
  413. * Sets the GMAC core in Half-Duplex mode.
  414. * @param[in] pointer to synopGMACdevice.
  415. * \return returns void.
  416. */
  417. void synopGMAC_set_half_duplex(synopGMACdevice * gmacdev)
  418. {
  419. synopGMACClearBits(gmacdev->MacBase, GmacConfig, GmacDuplex);
  420. return;
  421. }
  422. /**
  423. * GMAC tries retransmission (Only in Half Duplex mode).
  424. * If collision occurs on the GMII/MII, GMAC attempt retries based on the
  425. * back off limit configured.
  426. * @param[in] pointer to synopGMACdevice.
  427. * \return returns void.
  428. * \note This function is tightly coupled with synopGMAC_back_off_limit(synopGMACdev *, u32).
  429. */
  430. void synopGMAC_retry_enable(synopGMACdevice * gmacdev)
  431. {
  432. synopGMACClearBits(gmacdev->MacBase, GmacConfig, GmacRetry);
  433. return;
  434. }
  435. /**
  436. * GMAC tries only one transmission (Only in Half Duplex mode).
  437. * If collision occurs on the GMII/MII, GMAC will ignore the current frami
  438. * transmission and report a frame abort with excessive collision in tranmit frame status.
  439. * @param[in] pointer to synopGMACdevice.
  440. * \return returns void.
  441. */
  442. #if UNUSED
  443. void synopGMAC_retry_disable(synopGMACdevice * gmacdev)
  444. {
  445. synopGMACSetBits(gmacdev->MacBase, GmacConfig, GmacRetry);
  446. return;
  447. }
  448. #endif
  449. /**
  450. * GMAC strips the Pad/FCS field of incoming frames.
  451. * This is true only if the length field value is less than or equal to
  452. * 1500 bytes. All received frames with length field greater than or equal to
  453. * 1501 bytes are passed to the application without stripping the Pad/FCS field.
  454. * @param[in] pointer to synopGMACdevice.
  455. * \return returns void.
  456. */
  457. #if UNUSED
  458. void synopGMAC_pad_crc_strip_enable(synopGMACdevice * gmacdev)
  459. {
  460. synopGMACSetBits(gmacdev->MacBase, GmacConfig, GmacPadCrcStrip);
  461. return;
  462. }
  463. #endif
  464. /**
  465. * GMAC doesnot strips the Pad/FCS field of incoming frames.
  466. * GMAC will pass all the incoming frames to Host unmodified.
  467. * @param[in] pointer to synopGMACdevice.
  468. * \return returns void.
  469. */
  470. void synopGMAC_pad_crc_strip_disable(synopGMACdevice * gmacdev)
  471. {
  472. synopGMACClearBits(gmacdev->MacBase, GmacConfig, GmacPadCrcStrip);
  473. u32 status = synopGMACReadReg(gmacdev->MacBase, GmacConfig);
  474. DEBUG_MES("strips status : %u\n", status & GmacPadCrcStrip);
  475. return;
  476. }
  477. /**
  478. * GMAC programmed with the back off limit value.
  479. * @param[in] pointer to synopGMACdevice.
  480. * \return returns void.
  481. * \note This function is tightly coupled with synopGMAC_retry_enable(synopGMACdevice * gmacdev)
  482. */
  483. void synopGMAC_back_off_limit(synopGMACdevice * gmacdev, u32 value)
  484. {
  485. u32 data;
  486. data = synopGMACReadReg(gmacdev->MacBase, GmacConfig);
  487. data &= (~GmacBackoffLimit);
  488. data |= value;
  489. synopGMACWriteReg(gmacdev->MacBase, GmacConfig,data);
  490. return;
  491. }
  492. /**
  493. * Enables the Deferral check in GMAC (Only in Half Duplex mode)
  494. * GMAC issues a Frame Abort Status, along with the excessive deferral error bit set in the
  495. * transmit frame status when transmit state machine is deferred for more than
  496. * - 24,288 bit times in 10/100Mbps mode
  497. * - 155,680 bit times in 1000Mbps mode or Jumbo frame mode in 10/100Mbps operation.
  498. * @param[in] pointer to synopGMACdevice.
  499. * \return returns void.
  500. * \note Deferral begins when transmitter is ready to transmit, but is prevented because of
  501. * an active CRS (carrier sense)
  502. */
  503. #if UNUSED
  504. void synopGMAC_deferral_check_enable(synopGMACdevice * gmacdev)
  505. {
  506. synopGMACSetBits(gmacdev->MacBase, GmacConfig, GmacDeferralCheck);
  507. return;
  508. }
  509. #endif
  510. /**
  511. * Disables the Deferral check in GMAC (Only in Half Duplex mode).
  512. * GMAC defers until the CRS signal goes inactive.
  513. * @param[in] pointer to synopGMACdevice.
  514. * \return returns void.
  515. */
  516. void synopGMAC_deferral_check_disable(synopGMACdevice * gmacdev)
  517. {
  518. synopGMACClearBits(gmacdev->MacBase, GmacConfig, GmacDeferralCheck);
  519. return;
  520. }
  521. /**
  522. * Enable the reception of frames on GMII/MII.
  523. * @param[in] pointer to synopGMACdevice.
  524. * \return returns void.
  525. */
  526. void synopGMAC_rx_enable(synopGMACdevice * gmacdev)
  527. {
  528. synopGMACSetBits(gmacdev->MacBase, GmacConfig, GmacRx);
  529. return;
  530. }
  531. /**
  532. * Disable the reception of frames on GMII/MII.
  533. * GMAC receive state machine is disabled after completion of reception of current frame.
  534. * @param[in] pointer to synopGMACdevice.
  535. * \return returns void.
  536. */
  537. #if UNUSED
  538. void synopGMAC_rx_disable(synopGMACdevice * gmacdev)
  539. {
  540. synopGMACClearBits(gmacdev->MacBase, GmacConfig, GmacRx);
  541. return;
  542. }
  543. #endif
  544. /**
  545. * Enable the transmission of frames on GMII/MII.
  546. * @param[in] pointer to synopGMACdevice.
  547. * \return returns void.
  548. */
  549. void synopGMAC_tx_enable(synopGMACdevice * gmacdev)
  550. {
  551. synopGMACSetBits(gmacdev->MacBase, GmacConfig, GmacTx);
  552. return;
  553. }
  554. /**
  555. * Disable the transmission of frames on GMII/MII.
  556. * GMAC transmit state machine is disabled after completion of transmission of current frame.
  557. * @param[in] pointer to synopGMACdevice.
  558. * \return returns void.
  559. */
  560. #if UNUSED
  561. void synopGMAC_tx_disable(synopGMACdevice * gmacdev)
  562. {
  563. synopGMACClearBits(gmacdev->MacBase, GmacConfig, GmacTx);
  564. return;
  565. }
  566. #endif
  567. /*Receive frame filter configuration functions*/
  568. /**
  569. * Enables reception of all the frames to application.
  570. * GMAC passes all the frames received to application irrespective of whether they
  571. * pass SA/DA address filtering or not.
  572. * @param[in] pointer to synopGMACdevice.
  573. * \return returns void.
  574. */
  575. void synopGMAC_frame_filter_enable(synopGMACdevice * gmacdev)
  576. {
  577. synopGMACClearBits(gmacdev->MacBase, GmacFrameFilter, GmacFilter);
  578. return;
  579. }
  580. /**
  581. * Disables reception of all the frames to application.
  582. * GMAC passes only those received frames to application which
  583. * pass SA/DA address filtering.
  584. * @param[in] pointer to synopGMACdevice.
  585. * \return void.
  586. */
  587. void synopGMAC_frame_filter_disable(synopGMACdevice * gmacdev)
  588. {
  589. synopGMACSetBits(gmacdev->MacBase, GmacFrameFilter, GmacFilter);
  590. return;
  591. }
  592. /**
  593. * Populates the Hash High register with the data supplied.
  594. * This function is called when the Hash filtering is to be enabled.
  595. * @param[in] pointer to synopGMACdevice.
  596. * @param[in] data to be written to hash table high register.
  597. * \return void.
  598. */
  599. #if UNUSED
  600. void synopGMAC_write_hash_table_high(synopGMACdevice * gmacdev, u32 data)
  601. {
  602. synopGMACWriteReg(gmacdev->MacBase,GmacHashHigh,data);
  603. return;
  604. }
  605. #endif
  606. /**
  607. * Populates the Hash Low register with the data supplied.
  608. * This function is called when the Hash filtering is to be enabled.
  609. * @param[in] pointer to synopGMACdevice.
  610. * @param[in] data to be written to hash table low register.
  611. * \return void.
  612. */
  613. #if UNUSED
  614. void synopGMAC_write_hash_table_low(synopGMACdevice * gmacdev, u32 data)
  615. {
  616. synopGMACWriteReg(gmacdev->MacBase,GmacHashLow,data);
  617. return;
  618. }
  619. #endif
  620. /**
  621. * Enables Hash or Perfect filter (only if Hash filter is enabled in H/W).
  622. * Only frames matching either perfect filtering or Hash Filtering as per HMC and HUC
  623. * configuration are sent to application.
  624. * @param[in] pointer to synopGMACdevice.
  625. * \return void.
  626. */
  627. #if UNUSED
  628. void synopGMAC_hash_perfect_filter_enable(synopGMACdevice * gmacdev)
  629. {
  630. synopGMACSetBits(gmacdev->MacBase, GmacFrameFilter, GmacHashPerfectFilter);
  631. return;
  632. }
  633. #endif
  634. /**
  635. * Enables only Hash(only if Hash filter is enabled in H/W).
  636. * Only frames matching Hash Filtering as per HMC and HUC
  637. * configuration are sent to application.
  638. * @param[in] pointer to synopGMACdevice.
  639. * \return void.
  640. */
  641. #if UNUSED
  642. void synopGMAC_Hash_filter_only_enable(synopGMACdevice * gmacdev)
  643. {
  644. synopGMACSetBits(gmacdev->MacBase, GmacFrameFilter, GmacHashPerfectFilter);
  645. return;
  646. }
  647. #endif
  648. /**
  649. * Enables Source address filtering.
  650. * When enabled source address filtering is performed. Only frames matching SA filtering are passed to application with
  651. * SAMatch bit of RxStatus is set. GMAC drops failed frames.
  652. * @param[in] pointer to synopGMACdevice.
  653. * \return void.
  654. * \note This function is overriden by synopGMAC_frame_filter_disable(synopGMACdevice *)
  655. */
  656. #if UNUSED
  657. void synopGMAC_src_addr_filter_enable(synopGMACdevice * gmacdev)
  658. {
  659. synopGMACSetBits(gmacdev->MacBase, GmacFrameFilter, GmacSrcAddrFilter);
  660. return;
  661. }
  662. #endif
  663. /**
  664. * Disables Source address filtering.
  665. * When disabled GMAC forwards the received frames with updated SAMatch bit in RxStatus.
  666. * @param[in] pointer to synopGMACdevice.
  667. * \return void.
  668. */
  669. void synopGMAC_src_addr_filter_disable(synopGMACdevice * gmacdev)
  670. {
  671. synopGMACClearBits(gmacdev->MacBase, GmacFrameFilter, GmacSrcAddrFilter);
  672. return;
  673. }
  674. /**
  675. * Enables Inverse Destination address filtering.
  676. * @param[in] pointer to synopGMACdevice.
  677. * \return void.
  678. */
  679. #if UNUSED
  680. void synopGMAC_dst_addr_filter_inverse(synopGMACdevice * gmacdev)
  681. {
  682. synopGMACSetBits(gmacdev->MacBase, GmacFrameFilter, GmacDestAddrFilterNor);
  683. return;
  684. }
  685. #endif
  686. /**
  687. * Enables the normal Destination address filtering.
  688. * @param[in] pointer to synopGMACdevice.
  689. * \return void.
  690. */
  691. void synopGMAC_dst_addr_filter_normal(synopGMACdevice * gmacdev)
  692. {
  693. synopGMACClearBits(gmacdev->MacBase, GmacFrameFilter, GmacDestAddrFilterNor);
  694. return;
  695. }
  696. /**
  697. * Enables forwarding of control frames.
  698. * When set forwards all the control frames (incl. unicast and multicast PAUSE frames).
  699. * @param[in] pointer to synopGMACdevice.
  700. * \return void.
  701. * \note Depends on RFE of FlowControlRegister[2]
  702. */
  703. void synopGMAC_set_pass_control(synopGMACdevice * gmacdev,u32 passcontrol)
  704. {
  705. u32 data;
  706. data = synopGMACReadReg(gmacdev->MacBase, GmacFrameFilter);
  707. data &= (~GmacPassControl);
  708. data |= passcontrol;
  709. synopGMACWriteReg(gmacdev->MacBase,GmacFrameFilter,data);
  710. return;
  711. }
  712. /**
  713. * Enables Broadcast frames.
  714. * When enabled Address filtering module passes all incoming broadcast frames.
  715. * @param[in] pointer to synopGMACdevice.
  716. * \return void.
  717. */
  718. void synopGMAC_broadcast_enable(synopGMACdevice * gmacdev)
  719. {
  720. synopGMACClearBits(gmacdev->MacBase, GmacFrameFilter, GmacBroadcast );
  721. return;
  722. }
  723. /**
  724. * Disable Broadcast frames.
  725. * When disabled Address filtering module filters all incoming broadcast frames.
  726. * @param[in] pointer to synopGMACdevice.
  727. * \return void.
  728. */
  729. #if UNUSED
  730. void synopGMAC_broadcast_disable(synopGMACdevice * gmacdev)
  731. {
  732. synopGMACSetBits(gmacdev->MacBase, GmacFrameFilter, GmacBroadcast);
  733. return;
  734. }
  735. #endif
  736. /**
  737. * Enables Multicast frames.
  738. * When enabled all multicast frames are passed.
  739. * @param[in] pointer to synopGMACdevice.
  740. * \return void.
  741. */
  742. #if UNUSED
  743. void synopGMAC_multicast_enable(synopGMACdevice * gmacdev)
  744. {
  745. synopGMACSetBits(gmacdev->MacBase, GmacFrameFilter, GmacMulticastFilter);
  746. return;
  747. }
  748. #endif
  749. /**
  750. * Disable Multicast frames.
  751. * When disabled multicast frame filtering depends on HMC bit.
  752. * @param[in] pointer to synopGMACdevice.
  753. * \return void.
  754. */
  755. void synopGMAC_multicast_disable(synopGMACdevice * gmacdev)
  756. {
  757. synopGMACClearBits(gmacdev->MacBase, GmacFrameFilter, GmacMulticastFilter);
  758. return;
  759. }
  760. /**
  761. * Enables multicast hash filtering.
  762. * When enabled GMAC performs teh destination address filtering according to the hash table.
  763. * @param[in] pointer to synopGMACdevice.
  764. * \return void.
  765. */
  766. #if UNUSED
  767. void synopGMAC_multicast_hash_filter_enable(synopGMACdevice * gmacdev)
  768. {
  769. synopGMACSetBits(gmacdev->MacBase, GmacFrameFilter, GmacMcastHashFilter);
  770. return;
  771. }
  772. #endif
  773. /**
  774. * Disables multicast hash filtering.
  775. * When disabled GMAC performs perfect destination address filtering for multicast frames, it compares
  776. * DA field with the value programmed in DA register.
  777. * @param[in] pointer to synopGMACdevice.
  778. * \return void.
  779. */
  780. void synopGMAC_multicast_hash_filter_disable(synopGMACdevice * gmacdev)
  781. {
  782. synopGMACClearBits(gmacdev->MacBase, GmacFrameFilter, GmacMcastHashFilter);
  783. return;
  784. }
  785. /**
  786. * Enables promiscous mode.
  787. * When enabled Address filter modules pass all incoming frames regardless of their Destination
  788. * and source addresses.
  789. * @param[in] pointer to synopGMACdevice.
  790. * \return void.
  791. */
  792. #if UNUSED
  793. void synopGMAC_promisc_enable(synopGMACdevice * gmacdev)
  794. {
  795. synopGMACSetBits(gmacdev->MacBase, GmacFrameFilter, GmacPromiscuousMode);
  796. return;
  797. }
  798. #endif
  799. /**
  800. * Clears promiscous mode.
  801. * When called the GMAC falls back to normal operation from promiscous mode.
  802. * @param[in] pointer to synopGMACdevice.
  803. * \return void.
  804. */
  805. void synopGMAC_promisc_disable(synopGMACdevice * gmacdev)
  806. {
  807. synopGMACClearBits(gmacdev->MacBase, GmacFrameFilter, GmacPromiscuousMode);
  808. return;
  809. }
  810. /**
  811. * Enables unicast hash filtering.
  812. * When enabled GMAC performs the destination address filtering of unicast frames according to the hash table.
  813. * @param[in] pointer to synopGMACdevice.
  814. * \return void.
  815. */
  816. #if UNUSED
  817. void synopGMAC_unicast_hash_filter_enable(synopGMACdevice * gmacdev)
  818. {
  819. synopGMACSetBits(gmacdev->MacBase, GmacFrameFilter, GmacUcastHashFilter);
  820. return;
  821. }
  822. #endif
  823. /**
  824. * Disables multicast hash filtering.
  825. * When disabled GMAC performs perfect destination address filtering for unicast frames, it compares
  826. * DA field with the value programmed in DA register.
  827. * @param[in] pointer to synopGMACdevice.
  828. * \return void.
  829. */
  830. void synopGMAC_unicast_hash_filter_disable(synopGMACdevice * gmacdev)
  831. {
  832. synopGMACClearBits(gmacdev->MacBase, GmacFrameFilter, GmacUcastHashFilter);
  833. return;
  834. }
  835. /*Flow control configuration functions*/
  836. /**
  837. * Enables detection of pause frames with stations unicast address.
  838. * When enabled GMAC detects the pause frames with stations unicast address in addition to the
  839. * detection of pause frames with unique multicast address.
  840. * @param[in] pointer to synopGMACdevice.
  841. * \return void.
  842. */
  843. #if UNUSED
  844. void synopGMAC_unicast_pause_frame_detect_enable(synopGMACdevice * gmacdev)
  845. {
  846. synopGMACSetBits(gmacdev->MacBase, GmacFlowControl, GmacUnicastPauseFrame);
  847. return;
  848. }
  849. #endif
  850. /**
  851. * Disables detection of pause frames with stations unicast address.
  852. * When disabled GMAC only detects with the unique multicast address (802.3x).
  853. * @param[in] pointer to synopGMACdevice.
  854. * \return void.
  855. */
  856. void synopGMAC_unicast_pause_frame_detect_disable(synopGMACdevice * gmacdev)
  857. {
  858. synopGMACClearBits(gmacdev->MacBase, GmacFlowControl, GmacUnicastPauseFrame);
  859. return;
  860. }
  861. /**
  862. * Rx flow control enable.
  863. * When Enabled GMAC will decode the rx pause frame and disable the tx for a specified time.
  864. * @param[in] pointer to synopGMACdevice.
  865. * \return void.
  866. */
  867. void synopGMAC_rx_flow_control_enable(synopGMACdevice * gmacdev)
  868. {
  869. synopGMACSetBits(gmacdev->MacBase, GmacFlowControl, GmacRxFlowControl);
  870. return;
  871. }
  872. /**
  873. * Rx flow control disable.
  874. * When disabled GMAC will not decode pause frame.
  875. * @param[in] pointer to synopGMACdevice.
  876. * \return void.
  877. */
  878. void synopGMAC_rx_flow_control_disable(synopGMACdevice * gmacdev)
  879. {
  880. synopGMACClearBits(gmacdev->MacBase, GmacFlowControl, GmacRxFlowControl);
  881. return;
  882. }
  883. /**
  884. * Tx flow control enable.
  885. * When Enabled
  886. * - In full duplex GMAC enables flow control operation to transmit pause frames.
  887. * - In Half duplex GMAC enables the back pressure operation
  888. * @param[in] pointer to synopGMACdevice.
  889. * \return void.
  890. */
  891. void synopGMAC_tx_flow_control_enable(synopGMACdevice * gmacdev)
  892. {
  893. synopGMACSetBits(gmacdev->MacBase, GmacFlowControl, GmacTxFlowControl);
  894. return;
  895. }
  896. /**
  897. * Tx flow control disable.
  898. * When Disabled
  899. * - In full duplex GMAC will not transmit any pause frames.
  900. * - In Half duplex GMAC disables the back pressure feature.
  901. * @param[in] pointer to synopGMACdevice.
  902. * \return void.
  903. */
  904. void synopGMAC_tx_flow_control_disable(synopGMACdevice * gmacdev)
  905. {
  906. synopGMACClearBits(gmacdev->MacBase, GmacFlowControl, GmacTxFlowControl);
  907. return;
  908. }
  909. /**
  910. * Initiate Flowcontrol operation.
  911. * When Set
  912. * - In full duplex GMAC initiates pause control frame.
  913. * - In Half duplex GMAC initiates back pressure function.
  914. * @param[in] pointer to synopGMACdevice.
  915. * \return void.
  916. */
  917. #if UNUSED
  918. void synopGMAC_tx_activate_flow_control(synopGMACdevice * gmacdev)
  919. {
  920. //In case of full duplex check for this bit to b'0. if it is read as b'1 indicates that
  921. //control frame transmission is in progress.
  922. if(gmacdev->Speed == FULLDUPLEX){
  923. if(!synopGMACCheckBits(gmacdev->MacBase, GmacFlowControl, GmacFlowControlBackPressure))
  924. synopGMACSetBits(gmacdev->MacBase, GmacFlowControl, GmacFlowControlBackPressure);
  925. }
  926. else{ //if half duplex mode
  927. synopGMACSetBits(gmacdev->MacBase, GmacFlowControl, GmacFlowControlBackPressure);
  928. }
  929. return;
  930. }
  931. #endif
  932. /**
  933. * stops Flowcontrol operation.
  934. * @param[in] pointer to synopGMACdevice.
  935. * \return void.
  936. */
  937. #if UNUSED
  938. void synopGMAC_tx_deactivate_flow_control(synopGMACdevice * gmacdev)
  939. {
  940. //In full duplex this bit is automatically cleared after transmitting a pause control frame.
  941. if(gmacdev->Speed == HALFDUPLEX){
  942. synopGMACSetBits(gmacdev->MacBase, GmacFlowControl, GmacFlowControlBackPressure);
  943. }
  944. return;
  945. }
  946. #endif
  947. /**
  948. * This enables the pause frame generation after programming the appropriate registers.
  949. * presently activation is set at 3k and deactivation set at 4k. These may have to tweaked
  950. * if found any issues
  951. * @param[in] pointer to synopGMACdevice.
  952. * \return void.
  953. */
  954. void synopGMAC_pause_control(synopGMACdevice *gmacdev)
  955. {
  956. u32 omr_reg;
  957. u32 mac_flow_control_reg;
  958. omr_reg = synopGMACReadReg(gmacdev->DmaBase,DmaControl);
  959. omr_reg |= DmaRxFlowCtrlAct4K | DmaRxFlowCtrlDeact5K |DmaEnHwFlowCtrl;
  960. synopGMACWriteReg(gmacdev->DmaBase, DmaControl, omr_reg);
  961. mac_flow_control_reg = synopGMACReadReg(gmacdev->MacBase,GmacFlowControl);
  962. mac_flow_control_reg |= GmacRxFlowControl | GmacTxFlowControl | 0xFFFF0000;
  963. synopGMACWriteReg(gmacdev->MacBase,GmacFlowControl,mac_flow_control_reg);
  964. return;
  965. }
  966. /**
  967. * Example mac initialization sequence.
  968. * This function calls the initialization routines to initialize the GMAC register.
  969. * One can change the functions invoked here to have different configuration as per the requirement
  970. * @param[in] pointer to synopGMACdevice.
  971. * \return Returns 0 on success.
  972. */
  973. s32 synopGMAC_mac_init(synopGMACdevice * gmacdev)
  974. {
  975. u32 PHYreg;
  976. if(gmacdev->DuplexMode == FULLDUPLEX){
  977. TR("\n===phy FULLDUPLEX MODE\n"); //sw: debug
  978. synopGMAC_wd_enable(gmacdev);
  979. synopGMAC_jab_enable(gmacdev);
  980. synopGMAC_frame_burst_enable(gmacdev);
  981. synopGMAC_jumbo_frame_disable(gmacdev);
  982. synopGMAC_rx_own_enable(gmacdev);
  983. #if SYNOP_LOOPBACK_MODE
  984. synopGMAC_loopback_on(gmacdev);
  985. #else
  986. synopGMAC_loopback_off(gmacdev);
  987. #endif
  988. synopGMAC_set_full_duplex(gmacdev); //1
  989. synopGMAC_retry_enable(gmacdev);
  990. synopGMAC_pad_crc_strip_disable(gmacdev);
  991. synopGMAC_back_off_limit(gmacdev,GmacBackoffLimit0);
  992. synopGMAC_deferral_check_disable(gmacdev);
  993. synopGMAC_tx_enable(gmacdev); //according to Tang Dan's commitment
  994. synopGMAC_rx_enable(gmacdev);
  995. synopGMACSetBits(gmacdev->DmaBase,DmaControl, DmaStoreAndForward );//3
  996. synopGMACSetBits(gmacdev->DmaBase,DmaControl, DmaFwdErrorFrames );
  997. if(gmacdev->Speed == SPEED1000)
  998. synopGMAC_select_gmii(gmacdev);
  999. else{
  1000. synopGMAC_select_mii(gmacdev);
  1001. if(gmacdev->Speed == SPEED100)
  1002. synopGMACSetBits(gmacdev->MacBase, GmacConfig, GmacFESpeed100);
  1003. else
  1004. synopGMACSetBits(gmacdev->MacBase, GmacConfig, GmacFESpeed10);
  1005. }
  1006. /*Frame Filter Configuration*/
  1007. synopGMAC_frame_filter_enable(gmacdev); //2
  1008. //synopGMAC_frame_filter_disable(gmacdev); //2
  1009. synopGMAC_set_pass_control(gmacdev,GmacPassControl0);
  1010. synopGMAC_broadcast_enable(gmacdev);
  1011. synopGMAC_src_addr_filter_disable(gmacdev);
  1012. synopGMAC_multicast_disable(gmacdev);
  1013. //synopGMAC_dst_addr_filter_normal(gmacdev); //scl
  1014. synopGMAC_dst_addr_filter_inverse(gmacdev);
  1015. synopGMAC_multicast_hash_filter_disable(gmacdev);
  1016. synopGMAC_promisc_disable(gmacdev);
  1017. synopGMAC_unicast_hash_filter_disable(gmacdev);
  1018. /*Flow Control Configuration*/
  1019. synopGMAC_unicast_pause_frame_detect_disable(gmacdev);
  1020. synopGMAC_rx_flow_control_enable(gmacdev);
  1021. synopGMAC_tx_flow_control_enable(gmacdev);
  1022. }
  1023. else{//for Half Duplex configuration
  1024. TR("\n===phy HALFDUPLEX MODE\n"); //sw: debug
  1025. synopGMAC_wd_enable(gmacdev );
  1026. synopGMAC_jab_enable(gmacdev);
  1027. synopGMAC_frame_burst_enable(gmacdev);
  1028. synopGMAC_jumbo_frame_disable(gmacdev);
  1029. synopGMAC_rx_own_enable(gmacdev);
  1030. #if SYNOP_LOOPBACK_MODE
  1031. synopGMAC_loopback_on(gmacdev);
  1032. #else
  1033. synopGMAC_loopback_off(gmacdev);
  1034. #endif
  1035. synopGMAC_set_half_duplex(gmacdev);
  1036. synopGMAC_retry_enable(gmacdev);
  1037. synopGMAC_pad_crc_strip_disable(gmacdev);
  1038. synopGMAC_back_off_limit(gmacdev,GmacBackoffLimit0);
  1039. synopGMAC_deferral_check_disable(gmacdev);
  1040. //sw: set efe & tsf
  1041. synopGMACSetBits(gmacdev->DmaBase,DmaControl, DmaStoreAndForward );
  1042. synopGMACSetBits(gmacdev->DmaBase,DmaControl, DmaFwdErrorFrames );
  1043. //sw: put it in the end
  1044. synopGMAC_tx_enable(gmacdev);
  1045. synopGMAC_rx_enable(gmacdev);
  1046. if(gmacdev->Speed == SPEED1000)
  1047. synopGMAC_select_gmii(gmacdev);
  1048. else{
  1049. synopGMAC_select_mii(gmacdev );
  1050. if(gmacdev->Speed == SPEED100)
  1051. synopGMACSetBits(gmacdev->MacBase, GmacConfig, GmacFESpeed100 );
  1052. else
  1053. synopGMACSetBits(gmacdev->MacBase, GmacConfig, GmacFESpeed10 );
  1054. }
  1055. // synopGMACSetBits(gmacdev->MacBase, GmacConfig, GmacDisableCrs);
  1056. // synopGMAC_select_gmii(gmacdev);
  1057. /*Frame Filter Configuration*/
  1058. synopGMAC_frame_filter_enable(gmacdev);
  1059. // synopGMAC_frame_filter_disable(gmacdev);
  1060. synopGMAC_set_pass_control(gmacdev,GmacPassControl0);
  1061. synopGMAC_broadcast_enable(gmacdev);
  1062. synopGMAC_src_addr_filter_disable(gmacdev);
  1063. synopGMAC_multicast_disable(gmacdev);
  1064. synopGMAC_dst_addr_filter_normal(gmacdev);
  1065. synopGMAC_multicast_hash_filter_disable(gmacdev);
  1066. synopGMAC_promisc_disable(gmacdev);
  1067. // synopGMAC_promisc_enable(gmacdev);
  1068. synopGMAC_unicast_hash_filter_disable(gmacdev);
  1069. //sw: loopback mode
  1070. // synopGMAC_loopback_on(gmacdev);
  1071. /*Flow Control Configuration*/
  1072. synopGMAC_unicast_pause_frame_detect_disable(gmacdev);
  1073. synopGMAC_rx_flow_control_disable(gmacdev);
  1074. synopGMAC_tx_flow_control_disable(gmacdev);
  1075. /*To set PHY register to enable CRS on Transmit*/
  1076. }
  1077. return 0;
  1078. }
  1079. /**
  1080. * Sets the Mac address in to GMAC register.
  1081. * This function sets the MAC address to the MAC register in question.
  1082. * @param[in] pointer to synopGMACdevice to populate mac dma and phy addresses.
  1083. * @param[in] Register offset for Mac address high
  1084. * @param[in] Register offset for Mac address low
  1085. * @param[in] buffer containing mac address to be programmed.
  1086. * \return 0 upon success. Error code upon failure.
  1087. */
  1088. s32 synopGMAC_set_mac_addr(synopGMACdevice *gmacdev, u32 MacHigh, u32 MacLow, u8 *MacAddr)
  1089. {
  1090. u32 data;
  1091. data = (MacAddr[5] << 8) | MacAddr[4];
  1092. synopGMACWriteReg(gmacdev->MacBase,MacHigh,data);
  1093. data = (MacAddr[3] << 24) | (MacAddr[2] << 16) | (MacAddr[1] << 8) | MacAddr[0] ;
  1094. synopGMACWriteReg(gmacdev->MacBase,MacLow,data);
  1095. return 0;
  1096. }
  1097. /**
  1098. * Get the Mac address in to the address specified.
  1099. * The mac register contents are read and written to buffer passed.
  1100. * @param[in] pointer to synopGMACdevice to populate mac dma and phy addresses.
  1101. * @param[in] Register offset for Mac address high
  1102. * @param[in] Register offset for Mac address low
  1103. * @param[out] buffer containing the device mac address.
  1104. * \return 0 upon success. Error code upon failure.
  1105. */
  1106. s32 synopGMAC_get_mac_addr(synopGMACdevice *gmacdev, u32 MacHigh, u32 MacLow, u8 *MacAddr)
  1107. {
  1108. u32 data;
  1109. data = synopGMACReadReg(gmacdev->MacBase,MacHigh);
  1110. MacAddr[5] = (data >> 8) & 0xff;
  1111. MacAddr[4] = (data) & 0xff;
  1112. data = synopGMACReadReg(gmacdev->MacBase,MacLow);
  1113. MacAddr[3] = (data >> 24) & 0xff;
  1114. MacAddr[2] = (data >> 16) & 0xff;
  1115. MacAddr[1] = (data >> 8 ) & 0xff;
  1116. MacAddr[0] = (data ) & 0xff;
  1117. // rt_kprintf("MacAddr = 0x%x\t0x%x\t0x%x\t0x%x\t0x%x\t0x%x\n",MacAddr[0],MacAddr[1],MacAddr[2],MacAddr[3],MacAddr[4],MacAddr[5]);
  1118. return 0;
  1119. }
  1120. /**
  1121. * Attaches the synopGMAC device structure to the hardware.
  1122. * Device structure is populated with MAC/DMA and PHY base addresses.
  1123. * @param[in] pointer to synopGMACdevice to populate mac dma and phy addresses.
  1124. * @param[in] GMAC IP mac base address.
  1125. * @param[in] GMAC IP dma base address.
  1126. * @param[in] GMAC IP phy base address.
  1127. * \return 0 upon success. Error code upon failure.
  1128. * \note This is important function. No kernel api provided by Synopsys
  1129. */
  1130. s32 synopGMAC_attach (synopGMACdevice * gmacdev, u32 macBase, u32 dmaBase, u32 phyBase,u8 *mac_addr)
  1131. {
  1132. /*Make sure the Device data strucure is cleared before we proceed further*/
  1133. rt_memset((void *) gmacdev,0,sizeof(synopGMACdevice));
  1134. /*Populate the mac and dma base addresses*/
  1135. gmacdev->MacBase = macBase;
  1136. gmacdev->DmaBase = dmaBase;
  1137. gmacdev->PhyBase = phyBase;
  1138. // rt_kprintf("gmacdev->DmaBase = 0x%x\n", gmacdev->DmaBase);
  1139. // rt_kprintf("dmaBase = 0x%x\n", dmaBase);
  1140. {
  1141. int i,j;
  1142. u16 data;
  1143. for (i = phyBase,j=0;j<32;i=(i+1)&0x1f,j++)
  1144. {
  1145. synopGMAC_read_phy_reg(gmacdev->MacBase,i,2,&data);
  1146. if(data != 0 && data != 0xffff) break;
  1147. synopGMAC_read_phy_reg(gmacdev->MacBase,i,3,&data);
  1148. if(data != 0 && data != 0xffff) break;
  1149. }
  1150. if(j==32) {
  1151. rt_kprintf("phy_detect: can't find PHY!\n");
  1152. }
  1153. gmacdev->PhyBase = i;
  1154. }
  1155. // synopGMAC_get_mac_addr(gmacdev, GmacAddr0High, GmacAddr0Low, mac_addr);
  1156. /* Program/flash in the station/IP's Mac address */
  1157. synopGMAC_set_mac_addr(gmacdev,GmacAddr0High,GmacAddr0Low, mac_addr);
  1158. return 0;
  1159. }
  1160. /**
  1161. * Initialize the rx descriptors for ring or chain mode operation.
  1162. * - Status field is initialized to 0.
  1163. * - EndOfRing set for the last descriptor.
  1164. * - buffer1 and buffer2 set to 0 for ring mode of operation. (note)
  1165. * - data1 and data2 set to 0. (note)
  1166. * @param[in] pointer to DmaDesc structure.
  1167. * @param[in] whether end of ring
  1168. * \return void.
  1169. * \note Initialization of the buffer1, buffer2, data1,data2 and status are not done here. This only initializes whether one wants to use this descriptor
  1170. * in chain mode or ring mode. For chain mode of operation the buffer2 and data2 are programmed before calling this function.
  1171. */
  1172. void synopGMAC_rx_desc_init_ring(DmaDesc *desc, bool last_ring_desc)
  1173. {
  1174. desc->status = 0;
  1175. desc->length = last_ring_desc ? RxDescEndOfRing : 0;
  1176. desc->buffer1 = 0;
  1177. desc->buffer2 = 0;
  1178. desc->data1 = 0;
  1179. desc->data2 = 0;
  1180. desc->dummy1 = 0;
  1181. desc->dummy2 = 0;
  1182. return;
  1183. }
  1184. void synopGMAC_rx_desc_recycle(DmaDesc *desc, bool last_ring_desc)
  1185. {
  1186. desc->status = DescOwnByDma;
  1187. desc->length = last_ring_desc ? RxDescEndOfRing : 0;
  1188. //desc->buffer1 = 0;
  1189. //desc->buffer2 = 0;
  1190. //desc->data1 = 0;
  1191. //desc->data2 = 0;
  1192. desc->dummy1 = 0;
  1193. desc->dummy2 = 0;
  1194. return;
  1195. }
  1196. /**
  1197. * Initialize the tx descriptors for ring or chain mode operation.
  1198. * - Status field is initialized to 0.
  1199. * - EndOfRing set for the last descriptor.
  1200. * - buffer1 and buffer2 set to 0 for ring mode of operation. (note)
  1201. * - data1 and data2 set to 0. (note)
  1202. * @param[in] pointer to DmaDesc structure.
  1203. * @param[in] whether end of ring
  1204. * \return void.
  1205. * \note Initialization of the buffer1, buffer2, data1,data2 and status are not done here. This only initializes whether one wants to use this descriptor
  1206. * in chain mode or ring mode. For chain mode of operation the buffer2 and data2 are programmed before calling this function.
  1207. */
  1208. void synopGMAC_tx_desc_init_ring(DmaDesc *desc, bool last_ring_desc)
  1209. {
  1210. #ifdef ENH_DESC
  1211. desc->status = last_ring_desc? TxDescEndOfRing : 0;
  1212. desc->length = 0;
  1213. #else
  1214. desc->length = last_ring_desc? TxDescEndOfRing : 0;
  1215. #endif
  1216. //sw
  1217. desc->status = 0;
  1218. desc->buffer1 = 0;
  1219. desc->buffer2 = 0;
  1220. desc->data1 = 0;
  1221. desc->data2 = 0;
  1222. desc->dummy1 = 0;
  1223. desc->dummy2 = 0;
  1224. return;
  1225. }
  1226. /**
  1227. * Initialize the rx descriptors for chain mode of operation.
  1228. * - Status field is initialized to 0.
  1229. * - EndOfRing set for the last descriptor.
  1230. * - buffer1 and buffer2 set to 0.
  1231. * - data1 and data2 set to 0.
  1232. * @param[in] pointer to DmaDesc structure.
  1233. * @param[in] whether end of ring
  1234. * \return void.
  1235. */
  1236. void synopGMAC_rx_desc_init_chain(DmaDesc * desc)
  1237. {
  1238. desc->status = 0;
  1239. desc->length = RxDescChain;
  1240. desc->buffer1 = 0;
  1241. desc->data1 = 0;
  1242. return;
  1243. }
  1244. /**
  1245. * Initialize the rx descriptors for chain mode of operation.
  1246. * - Status field is initialized to 0.
  1247. * - EndOfRing set for the last descriptor.
  1248. * - buffer1 and buffer2 set to 0.
  1249. * - data1 and data2 set to 0.
  1250. * @param[in] pointer to DmaDesc structure.
  1251. * @param[in] whether end of ring
  1252. * \return void.
  1253. */
  1254. void synopGMAC_tx_desc_init_chain(DmaDesc * desc)
  1255. {
  1256. #ifdef ENH_DESC
  1257. desc->status = TxDescChain;
  1258. desc->length = 0;
  1259. #else
  1260. desc->length = TxDescChain;
  1261. #endif
  1262. desc->buffer1 = 0;
  1263. desc->data1 = 0;
  1264. return;
  1265. }
  1266. s32 synopGMAC_init_tx_rx_desc_queue(synopGMACdevice *gmacdev)
  1267. {
  1268. s32 i;
  1269. for(i =0; i < gmacdev -> TxDescCount; i++){
  1270. synopGMAC_tx_desc_init_ring(gmacdev->TxDesc + i, i == gmacdev->TxDescCount-1);
  1271. }
  1272. TR("At line %d\n",__LINE__);
  1273. for(i =0; i < gmacdev -> RxDescCount; i++){
  1274. synopGMAC_rx_desc_init_ring(gmacdev->RxDesc + i, i == gmacdev->RxDescCount-1);
  1275. }
  1276. gmacdev->TxNext = 0;
  1277. gmacdev->TxBusy = 0;
  1278. gmacdev->RxNext = 0;
  1279. gmacdev->RxBusy = 0;
  1280. return -ESYNOPGMACNOERR;
  1281. }
  1282. /**
  1283. * Programs the DmaRxBaseAddress with the Rx descriptor base address.
  1284. * Rx Descriptor's base address is available in the gmacdev structure. This function progrms the
  1285. * Dma Rx Base address with the starting address of the descriptor ring or chain.
  1286. * @param[in] pointer to synopGMACdevice.
  1287. * \return returns void.
  1288. */
  1289. void synopGMAC_init_rx_desc_base(synopGMACdevice *gmacdev)
  1290. {
  1291. DEBUG_MES("gmacdev->RxDescDma = %08x\n", gmacdev->RxDescDma);
  1292. synopGMACWriteReg(gmacdev->DmaBase,DmaRxBaseAddr,(u32)gmacdev->RxDescDma );
  1293. return;
  1294. }
  1295. /**
  1296. * Programs the DmaTxBaseAddress with the Tx descriptor base address.
  1297. * Tx Descriptor's base address is available in the gmacdev structure. This function progrms the
  1298. * Dma Tx Base address with the starting address of the descriptor ring or chain.
  1299. * @param[in] pointer to synopGMACdevice.
  1300. * \return returns void.
  1301. */
  1302. void synopGMAC_init_tx_desc_base(synopGMACdevice *gmacdev)
  1303. {
  1304. synopGMACWriteReg(gmacdev->DmaBase,DmaTxBaseAddr,(u32)gmacdev->TxDescDma);
  1305. return;
  1306. }
  1307. /**
  1308. * Makes the Dma as owner for this descriptor.
  1309. * This function sets the own bit of status field of the DMA descriptor,
  1310. * indicating the DMA is the owner for this descriptor.
  1311. * @param[in] pointer to DmaDesc structure.
  1312. * \return returns void.
  1313. */
  1314. void synopGMAC_set_owner_dma(DmaDesc *desc)
  1315. {
  1316. desc->status |= DescOwnByDma;
  1317. }
  1318. /**
  1319. * set tx descriptor to indicate SOF.
  1320. * This Descriptor contains the start of ethernet frame.
  1321. * @param[in] pointer to DmaDesc structure.
  1322. * \return returns void.
  1323. */
  1324. void synopGMAC_set_desc_sof(DmaDesc *desc)
  1325. {
  1326. #ifdef ENH_DESC
  1327. desc->status |= DescTxFirst;//ENH_DESC
  1328. #else
  1329. desc->length |= DescTxFirst;
  1330. #endif
  1331. }
  1332. /**
  1333. * set tx descriptor to indicate EOF.
  1334. * This descriptor contains the End of ethernet frame.
  1335. * @param[in] pointer to DmaDesc structure.
  1336. * \return returns void.
  1337. */
  1338. void synopGMAC_set_desc_eof(DmaDesc *desc)
  1339. {
  1340. #ifdef ENH_DESC
  1341. desc->status |= DescTxLast;//ENH_DESC
  1342. #else
  1343. desc->length |= DescTxLast;
  1344. #endif
  1345. }
  1346. /**
  1347. * checks whether this descriptor contains start of frame.
  1348. * This function is to check whether the descriptor's data buffer
  1349. * contains a fresh ethernet frame?
  1350. * @param[in] pointer to DmaDesc structure.
  1351. * \return returns true if SOF in current descriptor, else returns fail.
  1352. */
  1353. bool synopGMAC_is_sof_in_rx_desc(DmaDesc *desc)
  1354. {
  1355. return ((desc->status & DescRxFirst) == DescRxFirst);
  1356. }
  1357. /**
  1358. * checks whether this descriptor contains end of frame.
  1359. * This function is to check whether the descriptor's data buffer
  1360. * contains end of ethernet frame?
  1361. * @param[in] pointer to DmaDesc structure.
  1362. * \return returns true if SOF in current descriptor, else returns fail.
  1363. */
  1364. bool synopGMAC_is_eof_in_rx_desc(DmaDesc *desc)
  1365. {
  1366. return ((desc->status & DescRxLast) == DescRxLast);
  1367. }
  1368. /**
  1369. * checks whether destination address filter failed in the rx frame.
  1370. * @param[in] pointer to DmaDesc structure.
  1371. * \return returns true if Failed, false if not.
  1372. */
  1373. bool synopGMAC_is_da_filter_failed(DmaDesc *desc)
  1374. {
  1375. return ((desc->status & DescDAFilterFail) == DescDAFilterFail);
  1376. }
  1377. /**
  1378. * checks whether source address filter failed in the rx frame.
  1379. * @param[in] pointer to DmaDesc structure.
  1380. * \return returns true if Failed, false if not.
  1381. */
  1382. bool synopGMAC_is_sa_filter_failed(DmaDesc *desc)
  1383. {
  1384. return ((desc->status & DescSAFilterFail) == DescSAFilterFail);
  1385. }
  1386. /**
  1387. * Checks whether the descriptor is owned by DMA.
  1388. * If descriptor is owned by DMA then the OWN bit is set to 1. This API is same for both ring and chain mode.
  1389. * @param[in] pointer to DmaDesc structure.
  1390. * \return returns true if Dma owns descriptor and false if not.
  1391. */
  1392. bool synopGMAC_is_desc_owned_by_dma(DmaDesc *desc)
  1393. {
  1394. return ((desc->status & DescOwnByDma) == DescOwnByDma );
  1395. }
  1396. /**
  1397. * returns the byte length of received frame including CRC.
  1398. * This returns the no of bytes received in the received ethernet frame including CRC(FCS).
  1399. * @param[in] pointer to DmaDesc structure.
  1400. * \return returns the length of received frame lengths in bytes.
  1401. */
  1402. u32 synopGMAC_get_rx_desc_frame_length(u32 status)
  1403. {
  1404. return ((status & DescFrameLengthMask) >> DescFrameLengthShift);
  1405. }
  1406. /**
  1407. * Checks whether the descriptor is valid
  1408. * if no errors such as CRC/Receive Error/Watchdog Timeout/Late collision/Giant Frame/Overflow/Descriptor
  1409. * error the descritpor is said to be a valid descriptor.
  1410. * @param[in] pointer to DmaDesc structure.
  1411. * \return True if desc valid. false if error.
  1412. */
  1413. bool synopGMAC_is_desc_valid(u32 status)
  1414. {
  1415. return ((status & DescError) == 0);
  1416. }
  1417. /**
  1418. * Checks whether the descriptor is empty.
  1419. * If the buffer1 and buffer2 lengths are zero in ring mode descriptor is empty.
  1420. * In chain mode buffer2 length is 0 but buffer2 itself contains the next descriptor address.
  1421. * @param[in] pointer to DmaDesc structure.
  1422. * \return returns true if descriptor is empty, false if not empty.
  1423. */
  1424. bool synopGMAC_is_desc_empty(DmaDesc *desc)
  1425. {
  1426. //if both the buffer1 length and buffer2 length are zero desc is empty
  1427. return(((desc->length & DescSize1Mask) == 0) && ((desc->length & DescSize2Mask) == 0) );
  1428. }
  1429. /**
  1430. * Checks whether the rx descriptor is valid.
  1431. * if rx descripor is not in error and complete frame is available in the same descriptor
  1432. * @param[in] pointer to DmaDesc structure.
  1433. * \return returns true if no error and first and last desc bits are set, otherwise it returns false.
  1434. */
  1435. bool synopGMAC_is_rx_desc_valid(u32 status)
  1436. {
  1437. return ((status & DescError) == 0) && ((status & DescRxFirst) == DescRxFirst) && ((status & DescRxLast) == DescRxLast);
  1438. }
  1439. /**
  1440. * Checks whether the tx is aborted due to collisions.
  1441. * @param[in] pointer to DmaDesc structure.
  1442. * \return returns true if collisions, else returns false.
  1443. */
  1444. bool synopGMAC_is_tx_aborted(u32 status)
  1445. {
  1446. return (((status & DescTxLateCollision) == DescTxLateCollision) | ((status & DescTxExcCollisions) == DescTxExcCollisions));
  1447. }
  1448. /**
  1449. * Checks whether the tx carrier error.
  1450. * @param[in] pointer to DmaDesc structure.
  1451. * \return returns true if carrier error occured, else returns falser.
  1452. */
  1453. bool synopGMAC_is_tx_carrier_error(u32 status)
  1454. {
  1455. return (((status & DescTxLostCarrier) == DescTxLostCarrier) | ((status & DescTxNoCarrier) == DescTxNoCarrier));
  1456. }
  1457. /**
  1458. * Gives the transmission collision count.
  1459. * returns the transmission collision count indicating number of collisions occured before the frame was transmitted.
  1460. * Make sure to check excessive collision didnot happen to ensure the count is valid.
  1461. * @param[in] pointer to DmaDesc structure.
  1462. * \return returns the count value of collision.
  1463. */
  1464. u32 synopGMAC_get_tx_collision_count(u32 status)
  1465. {
  1466. return ((status & DescTxCollMask) >> DescTxCollShift);
  1467. }
  1468. u32 synopGMAC_is_exc_tx_collisions(u32 status)
  1469. {
  1470. return ((status & DescTxExcCollisions) == DescTxExcCollisions);
  1471. }
  1472. /**
  1473. * Check for damaged frame due to overflow or collision.
  1474. * Retruns true if rx frame was damaged due to buffer overflow in MTL or late collision in half duplex mode.
  1475. * @param[in] pointer to DmaDesc structure.
  1476. * \return returns true if error else returns false.
  1477. */
  1478. bool synopGMAC_is_rx_frame_damaged(u32 status)
  1479. {
  1480. //bool synopGMAC_dma_rx_collisions(u32 status)
  1481. return (((status & DescRxDamaged) == DescRxDamaged) | ((status & DescRxCollision) == DescRxCollision));
  1482. }
  1483. /**
  1484. * Check for damaged frame due to collision.
  1485. * Retruns true if rx frame was damaged due to late collision in half duplex mode.
  1486. * @param[in] pointer to DmaDesc structure.
  1487. * \return returns true if error else returns false.
  1488. */
  1489. bool synopGMAC_is_rx_frame_collision(u32 status)
  1490. {
  1491. //bool synopGMAC_dma_rx_collisions(u32 status)
  1492. return ((status & DescRxCollision) == DescRxCollision);
  1493. }
  1494. /**
  1495. * Check for receive CRC error.
  1496. * Retruns true if rx frame CRC error occured.
  1497. * @param[in] pointer to DmaDesc structure.
  1498. * \return returns true if error else returns false.
  1499. */
  1500. bool synopGMAC_is_rx_crc(u32 status)
  1501. {
  1502. //u32 synopGMAC_dma_rx_crc(u32 status)
  1503. return ((status & DescRxCrc) == DescRxCrc);
  1504. }
  1505. /**
  1506. * Indicates rx frame has non integer multiple of bytes. (odd nibbles).
  1507. * Retruns true if dribbling error in rx frame.
  1508. * @param[in] pointer to DmaDesc structure.
  1509. * \return returns true if error else returns false.
  1510. */
  1511. bool synopGMAC_is_frame_dribbling_errors(u32 status)
  1512. {
  1513. //u32 synopGMAC_dma_rx_frame_errors(u32 status)
  1514. return ((status & DescRxDribbling) == DescRxDribbling);
  1515. }
  1516. /**
  1517. * Indicates error in rx frame length.
  1518. * Retruns true if received frame length doesnot match with the length field
  1519. * @param[in] pointer to DmaDesc structure.
  1520. * \return returns true if error else returns false.
  1521. */
  1522. bool synopGMAC_is_rx_frame_length_errors(u32 status)
  1523. {
  1524. //u32 synopGMAC_dma_rx_length_errors(u32 status)
  1525. return((status & DescRxLengthError) == DescRxLengthError);
  1526. }
  1527. /**
  1528. * Checks whether this rx descriptor is last rx descriptor.
  1529. * This returns true if it is last descriptor either in ring mode or in chain mode.
  1530. * @param[in] pointer to devic structure.
  1531. * @param[in] pointer to DmaDesc structure.
  1532. * \return returns true if it is last descriptor, false if not.
  1533. * \note This function should not be called before initializing the descriptor using synopGMAC_desc_init().
  1534. */
  1535. bool synopGMAC_is_last_rx_desc(synopGMACdevice * gmacdev,DmaDesc *desc)
  1536. {
  1537. //bool synopGMAC_is_last_desc(DmaDesc *desc)
  1538. return (((desc->length & RxDescEndOfRing) == RxDescEndOfRing) || ((u32)gmacdev->RxDesc == desc->data2));
  1539. }
  1540. /**
  1541. * Checks whether this tx descriptor is last tx descriptor.
  1542. * This returns true if it is last descriptor either in ring mode or in chain mode.
  1543. * @param[in] pointer to devic structure.
  1544. * @param[in] pointer to DmaDesc structure.
  1545. * \return returns true if it is last descriptor, false if not.
  1546. * \note This function should not be called before initializing the descriptor using synopGMAC_desc_init().
  1547. */
  1548. bool synopGMAC_is_last_tx_desc(synopGMACdevice * gmacdev,DmaDesc *desc)
  1549. {
  1550. //bool synopGMAC_is_last_desc(DmaDesc *desc)
  1551. #ifdef ENH_DESC
  1552. return (((desc->status & TxDescEndOfRing) == TxDescEndOfRing) || ((u32)gmacdev->TxDesc == desc->data2));
  1553. #else
  1554. return (((desc->length & TxDescEndOfRing) == TxDescEndOfRing) || ((u32)gmacdev->TxDesc == desc->data2));
  1555. #endif
  1556. }
  1557. /**
  1558. * Checks whether this rx descriptor is in chain mode.
  1559. * This returns true if it is this descriptor is in chain mode.
  1560. * @param[in] pointer to DmaDesc structure.
  1561. * \return returns true if chain mode is set, false if not.
  1562. */
  1563. bool synopGMAC_is_rx_desc_chained(DmaDesc * desc)
  1564. {
  1565. return((desc->length & RxDescChain) == RxDescChain);
  1566. }
  1567. /**
  1568. * Checks whether this tx descriptor is in chain mode.
  1569. * This returns true if it is this descriptor is in chain mode.
  1570. * @param[in] pointer to DmaDesc structure.
  1571. * \return returns true if chain mode is set, false if not.
  1572. */
  1573. bool synopGMAC_is_tx_desc_chained(DmaDesc * desc)
  1574. {
  1575. #ifdef ENH_DESC
  1576. return((desc->status & TxDescChain) == TxDescChain);
  1577. #else
  1578. return((desc->length & TxDescChain) == TxDescChain);
  1579. #endif
  1580. }
  1581. /**
  1582. * Driver Api to get the descriptor field information.
  1583. * This returns the status, dma-able address of buffer1, the length of buffer1, virtual address of buffer1
  1584. * dma-able address of buffer2, length of buffer2, virtural adddress of buffer2.
  1585. * @param[in] pointer to DmaDesc structure.
  1586. * @param[out] pointer to status field fo descriptor.
  1587. * @param[out] dma-able address of buffer1.
  1588. * @param[out] length of buffer1.
  1589. * @param[out] virtual address of buffer1.
  1590. * @param[out] dma-able address of buffer2.
  1591. * @param[out] length of buffer2.
  1592. * @param[out] virtual address of buffer2.
  1593. * \return returns void.
  1594. */
  1595. void synopGMAC_get_desc_data(DmaDesc * desc, u32 * Status, u32 * Buffer1, u32 * Length1, u32 * Data1, u32 * Buffer2, u32 * Length2, u32 * Data2)
  1596. {
  1597. if(Status != 0)
  1598. *Status = desc->status;
  1599. if(Buffer1 != 0)
  1600. *Buffer1 = desc->buffer1;
  1601. if(Length1 != 0)
  1602. *Length1 = (desc->length & DescSize1Mask) >> DescSize1Shift;
  1603. if(Data1 != 0)
  1604. *Data1 = desc->data1;
  1605. if(Buffer2 != 0)
  1606. *Buffer2 = desc->buffer2;
  1607. if(Length2 != 0)
  1608. *Length2 = (desc->length & DescSize2Mask) >> DescSize2Shift;
  1609. if(Data1 != 0)
  1610. *Data2 = desc->data2;
  1611. return;
  1612. }
  1613. #ifdef ENH_DESC_8W
  1614. /**
  1615. * This function is defined two times. Once when the code is compiled for ENHANCED DESCRIPTOR SUPPORT and Once for Normal descriptor
  1616. * Get the index and address of Tx desc.
  1617. * This api is same for both ring mode and chain mode.
  1618. * This function tracks the tx descriptor the DMA just closed after the transmission of data from this descriptor is
  1619. * over. This returns the descriptor fields to the caller.
  1620. * @param[in] pointer to synopGMACdevice.
  1621. * @param[out] status field of the descriptor.
  1622. * @param[out] Dma-able buffer1 pointer.
  1623. * @param[out] length of buffer1 (Max is 2048).
  1624. * @param[out] virtual pointer for buffer1.
  1625. * @param[out] Dma-able buffer2 pointer.
  1626. * @param[out] length of buffer2 (Max is 2048).
  1627. * @param[out] virtual pointer for buffer2.
  1628. * @param[out] u32 data indicating whether the descriptor is in ring mode or chain mode.
  1629. * \return returns present tx descriptor index on success. Negative value if error.
  1630. */
  1631. s32 synopGMAC_get_tx_qptr(synopGMACdevice * gmacdev, u32 * Status, u32 * Buffer1, u32 * Length1, u32 * Data1, u32 * Buffer2, u32 * Length2, u32 * Data2,
  1632. u32 * Ext_Status, u32 * Time_Stamp_High, u32 * Time_Stamp_Low)
  1633. {
  1634. u32 txover = gmacdev->TxBusy;
  1635. DmaDesc * txdesc = gmacdev->TxBusyDesc;
  1636. if(synopGMAC_is_desc_owned_by_dma(txdesc))
  1637. return -1;
  1638. if(synopGMAC_is_desc_empty(txdesc))
  1639. return -1;
  1640. (gmacdev->BusyTxDesc)--; //busy tx descriptor is reduced by one as it will be handed over to Processor now
  1641. if(Status != 0)
  1642. *Status = txdesc->status;
  1643. if(Ext_Status != 0)
  1644. *Ext_Status = txdesc->extstatus;
  1645. if(Time_Stamp_High != 0)
  1646. *Time_Stamp_High = txdesc->timestamphigh;
  1647. if(Time_Stamp_Low != 0)
  1648. *Time_Stamp_High = txdesc->timestamplow;
  1649. if(Buffer1 != 0)
  1650. *Buffer1 = txdesc->buffer1;
  1651. if(Length1 != 0)
  1652. *Length1 = (txdesc->length & DescSize1Mask) >> DescSize1Shift;
  1653. if(Data1 != 0)
  1654. *Data1 = txdesc->data1;
  1655. if(Buffer2 != 0)
  1656. *Buffer2 = txdesc->buffer2;
  1657. if(Length2 != 0)
  1658. *Length2 = (txdesc->length & DescSize2Mask) >> DescSize2Shift;
  1659. if(Data1 != 0)
  1660. *Data2 = txdesc->data2;
  1661. gmacdev->TxBusy = synopGMAC_is_last_tx_desc(gmacdev,txdesc) ? 0 : txover + 1;
  1662. if(synopGMAC_is_tx_desc_chained(txdesc)){
  1663. gmacdev->TxBusyDesc = (DmaDesc *)txdesc->data2;
  1664. synopGMAC_tx_desc_init_chain(txdesc);
  1665. }
  1666. else{
  1667. gmacdev->TxBusyDesc = synopGMAC_is_last_tx_desc(gmacdev,txdesc) ? gmacdev->TxDesc : (txdesc + 1);
  1668. synopGMAC_tx_desc_init_ring(txdesc, synopGMAC_is_last_tx_desc(gmacdev,txdesc));
  1669. }
  1670. TR("%02d %08x %08x %08x %08x %08x %08x %08x\n",txover,(u32)txdesc,txdesc->status,txdesc->length,txdesc->buffer1,txdesc->buffer2,txdesc->data1,txdesc->data2);
  1671. return txover;
  1672. }
  1673. #else
  1674. /**
  1675. * Get the index and address of Tx desc.
  1676. * This api is same for both ring mode and chain mode.
  1677. * This function tracks the tx descriptor the DMA just closed after the transmission of data from this descriptor is
  1678. * over. This returns the descriptor fields to the caller.
  1679. * @param[in] pointer to synopGMACdevice.
  1680. * @param[out] status field of the descriptor.
  1681. * @param[out] Dma-able buffer1 pointer.
  1682. * @param[out] length of buffer1 (Max is 2048).
  1683. * @param[out] virtual pointer for buffer1.
  1684. * @param[out] Dma-able buffer2 pointer.
  1685. * @param[out] length of buffer2 (Max is 2048).
  1686. * @param[out] virtual pointer for buffer2.
  1687. * @param[out] u32 data indicating whether the descriptor is in ring mode or chain mode.
  1688. * \return returns present tx descriptor index on success. Negative value if error.
  1689. */
  1690. s32 synopGMAC_get_tx_qptr(synopGMACdevice * gmacdev, u32 * Status, u32 * Buffer1, u32 * Length1, u32 * Data1, u32 * Buffer2, u32 * Length2, u32 * Data2 )
  1691. {
  1692. u32 txover = gmacdev->TxBusy;
  1693. DmaDesc * txdesc = gmacdev->TxBusyDesc;
  1694. int i;
  1695. //sw: dbg
  1696. //pci_sync_cache(0, (vm_offset_t)txdesc, 64, SYNC_R);
  1697. //pci_sync_cache(0, (vm_offset_t)txdesc, 64, SYNC_W);
  1698. #if SYNOP_TX_DEBUG
  1699. printf("Cache sync before get a used tx dma desc!\n");
  1700. printf("\n==%02d %08x %08x %08x %08x %08x %08x %08x\n",txover,(u32)txdesc,txdesc->status,txdesc->length,txdesc->buffer1,txdesc->buffer2,txdesc->data1,txdesc->data2);
  1701. #endif
  1702. if(synopGMAC_is_desc_owned_by_dma(txdesc))
  1703. {
  1704. return -1;
  1705. }
  1706. // gmacdev->TxBusy = synopGMAC_is_last_tx_desc(gmacdev,txdesc) ? 0 : txover + 1;
  1707. // gmacdev->TxBusyDesc = synopGMAC_is_last_tx_desc(gmacdev,txdesc) ? gmacdev->TxDesc : (txdesc + 1);
  1708. if(synopGMAC_is_desc_empty(txdesc))
  1709. {
  1710. return -1;
  1711. }
  1712. (gmacdev->BusyTxDesc)--; //busy tx descriptor is reduced by one as it will be handed over to Processor now
  1713. if(Status != 0)
  1714. *Status = txdesc->status;
  1715. if(Buffer1 != 0)
  1716. *Buffer1 = txdesc->buffer1;
  1717. if(Length1 != 0)
  1718. *Length1 = (txdesc->length & DescSize1Mask) >> DescSize1Shift;
  1719. if(Data1 != 0)
  1720. *Data1 = txdesc->data1;
  1721. if(Buffer2 != 0)
  1722. *Buffer2 = txdesc->buffer2;
  1723. if(Length2 != 0)
  1724. *Length2 = (txdesc->length & DescSize2Mask) >> DescSize2Shift;
  1725. if(Data1 != 0)
  1726. *Data2 = txdesc->data2;
  1727. gmacdev->TxBusy = synopGMAC_is_last_tx_desc(gmacdev,txdesc) ? 0 : txover + 1;
  1728. if(synopGMAC_is_tx_desc_chained(txdesc)){
  1729. gmacdev->TxBusyDesc = (DmaDesc *)txdesc->data2;
  1730. synopGMAC_tx_desc_init_chain(txdesc);
  1731. }
  1732. else{
  1733. gmacdev->TxBusyDesc = synopGMAC_is_last_tx_desc(gmacdev,txdesc) ? gmacdev->TxDesc : (txdesc + 1);
  1734. synopGMAC_tx_desc_init_ring(txdesc, synopGMAC_is_last_tx_desc(gmacdev,txdesc));
  1735. }
  1736. //printf("%02d %08x %08x %08x %08x %08x %08x %08x\n",txover,(u32)txdesc,txdesc->status,txdesc->length,txdesc->buffer1,txdesc->buffer2,txdesc->data1,txdesc->data2);
  1737. //pci_sync_cache(0, (vm_offset_t)txdesc, 64, SYNC_W);
  1738. #if SYNOP_TX_DEBUG
  1739. printf("Cache sync after re-init a tx dma desc!\n");
  1740. #endif
  1741. return txover;
  1742. }
  1743. #endif
  1744. /**
  1745. * Populate the tx desc structure with the buffer address.
  1746. * Once the driver has a packet ready to be transmitted, this function is called with the
  1747. * valid dma-able buffer addresses and their lengths. This function populates the descriptor
  1748. * and make the DMA the owner for the descriptor. This function also controls whetther Checksum
  1749. * offloading to be done in hardware or not.
  1750. * This api is same for both ring mode and chain mode.
  1751. * @param[in] pointer to synopGMACdevice.
  1752. * @param[in] Dma-able buffer1 pointer.
  1753. * @param[in] length of buffer1 (Max is 2048).
  1754. * @param[in] virtual pointer for buffer1.
  1755. * @param[in] Dma-able buffer2 pointer.
  1756. * @param[in] length of buffer2 (Max is 2048).
  1757. * @param[in] virtual pointer for buffer2.
  1758. * @param[in] u32 data indicating whether the descriptor is in ring mode or chain mode.
  1759. * @param[in] u32 indicating whether the checksum offloading in HW/SW.
  1760. * \return returns present tx descriptor index on success. Negative value if error.
  1761. */
  1762. u32 len;
  1763. s32 synopGMAC_set_tx_qptr(synopGMACdevice * gmacdev, u32 Buffer1, u32 Length1, u32 Data1, u32 Buffer2, u32 Length2, u32 Data2,u32 offload_needed,u32 * index, DmaDesc * Dpr)
  1764. {
  1765. u32 txnext = gmacdev->TxNext;
  1766. DmaDesc * txdesc = gmacdev->TxNextDesc;
  1767. *index = txnext;
  1768. Dpr = txdesc;
  1769. if(!synopGMAC_is_desc_empty(txdesc))
  1770. {
  1771. TR("set tx qptr: desc empty!\n");
  1772. return -1;
  1773. }
  1774. (gmacdev->BusyTxDesc)++; //busy tx descriptor is reduced by one as it will be handed over to Processor now
  1775. if(synopGMAC_is_tx_desc_chained(txdesc)){
  1776. txdesc->length |= ((Length1 <<DescSize1Shift) & DescSize1Mask);
  1777. #ifdef ENH_DESC
  1778. txdesc->status |= (DescTxFirst | DescTxLast | DescTxIntEnable); //ENH_DESC
  1779. #else
  1780. txdesc->length |= (DescTxFirst | DescTxLast | DescTxIntEnable); //Its always assumed that complete data will fit in to one descriptor
  1781. #endif
  1782. txdesc->buffer1 = Buffer1;
  1783. txdesc->data1 = Data1;
  1784. if(offload_needed){
  1785. /*
  1786. Make sure that the OS you are running supports the IP and TCP checkusm offloaidng,
  1787. before calling any of the functions given below.
  1788. */
  1789. synopGMAC_tx_checksum_offload_ipv4hdr(gmacdev, txdesc);
  1790. synopGMAC_tx_checksum_offload_tcponly(gmacdev, txdesc);
  1791. // synopGMAC_tx_checksum_offload_tcp_pseudo(gmacdev, txdesc);
  1792. }
  1793. #ifdef ENH_DESC
  1794. txdesc->status |= DescOwnByDma;//ENH_DESC
  1795. #else
  1796. txdesc->status = DescOwnByDma;
  1797. #endif
  1798. gmacdev->TxNext = synopGMAC_is_last_tx_desc(gmacdev,txdesc) ? 0 : txnext + 1;
  1799. gmacdev->TxNextDesc = (DmaDesc *)txdesc->data2;
  1800. }
  1801. else{
  1802. // printf("synopGMAC_set_tx_qptr:in ring mode\n");
  1803. txdesc->length |= (((Length1 <<DescSize1Shift) & DescSize1Mask) | ((Length2 <<DescSize2Shift) & DescSize2Mask));
  1804. #ifdef ENH_DESC
  1805. txdesc->status |= (DescTxFirst | DescTxLast | DescTxIntEnable); //ENH_DESC
  1806. #else
  1807. txdesc->length |= (DescTxFirst | DescTxLast | DescTxIntEnable); //Its always assumed that complete data will fit in to one descriptor
  1808. #endif
  1809. txdesc->buffer1 = Buffer1;
  1810. txdesc->data1 = Data1;
  1811. txdesc->buffer2 = Buffer2;
  1812. txdesc->data2 = Data2;
  1813. if(offload_needed){
  1814. /*
  1815. Make sure that the OS you are running supports the IP and TCP checkusm offloaidng,
  1816. before calling any of the functions given below.
  1817. */
  1818. //sw: i am not sure about the checksum.so i omit it in the outside
  1819. synopGMAC_tx_checksum_offload_ipv4hdr(gmacdev, txdesc);
  1820. synopGMAC_tx_checksum_offload_tcponly(gmacdev, txdesc);
  1821. // synopGMAC_tx_checksum_offload_tcp_pseudo(gmacdev, txdesc);
  1822. }
  1823. #ifdef ENH_DESC
  1824. txdesc->status |= DescOwnByDma;//ENH_DESC
  1825. #else
  1826. // printf("synopGMAC_set_tx_qptr:give the tx descroptor to dma\n");
  1827. txdesc->status = DescOwnByDma;
  1828. #endif
  1829. gmacdev->TxNext = synopGMAC_is_last_tx_desc(gmacdev,txdesc) ? 0 : txnext + 1;
  1830. gmacdev->TxNextDesc = synopGMAC_is_last_tx_desc(gmacdev,txdesc) ? gmacdev->TxDesc : (txdesc + 1);
  1831. }
  1832. #if SYNOP_TX_DEBUG
  1833. printf("%02d %08x %08x %08x %08x %08x %08x %08x\n",txnext,(u32)txdesc,txdesc->status,txdesc->length,txdesc->buffer1,txdesc->buffer2,txdesc->data1,txdesc->data2);
  1834. #endif
  1835. //pci_sync_cache(0, (vm_offset_t)txdesc, 64, SYNC_W);
  1836. #if SYNOP_TX_DEBUG
  1837. printf("Cache sync to set a tx desc!\n");
  1838. #endif
  1839. //pci_sync_cache(0, (vm_offset_t)(txdesc->data1), 32, SYNC_W);
  1840. #if SYNOP_TX_DEBUG
  1841. //printf("Cache sync for data in the buf of the tx desc!\n");
  1842. #endif
  1843. return txnext;
  1844. }
  1845. #ifdef ENH_DESC_8W
  1846. /**
  1847. * Prepares the descriptor to receive packets.
  1848. * The descriptor is allocated with the valid buffer addresses (sk_buff address) and the length fields
  1849. * and handed over to DMA by setting the ownership. After successful return from this function the
  1850. * descriptor is added to the receive descriptor pool/queue.
  1851. * This api is same for both ring mode and chain mode.
  1852. * @param[in] pointer to synopGMACdevice.
  1853. * @param[in] Dma-able buffer1 pointer.
  1854. * @param[in] length of buffer1 (Max is 2048).
  1855. * @param[in] Dma-able buffer2 pointer.
  1856. * @param[in] length of buffer2 (Max is 2048).
  1857. * @param[in] u32 data indicating whether the descriptor is in ring mode or chain mode.
  1858. * \return returns present rx descriptor index on success. Negative value if error.
  1859. */
  1860. // dma_addr RX_BUF_SIZE skb
  1861. s32 synopGMAC_set_rx_qptr(synopGMACdevice * gmacdev, u32 Buffer1, u32 Length1, u32 Data1, u32 Buffer2, u32 Length2, u32 Data2)
  1862. {
  1863. u32 rxnext = gmacdev->RxNext;
  1864. DmaDesc * rxdesc = gmacdev->RxNextDesc;
  1865. if(!synopGMAC_is_desc_empty(rxdesc))
  1866. return -1;
  1867. if(synopGMAC_is_rx_desc_chained(rxdesc)){
  1868. rxdesc->length |= ((Length1 <<DescSize1Shift) & DescSize1Mask);
  1869. rxdesc->buffer1 = Buffer1;
  1870. rxdesc->data1 = Data1;
  1871. rxdesc->extstatus = 0;
  1872. rxdesc->reserved1 = 0;
  1873. rxdesc->timestamplow = 0;
  1874. rxdesc->timestamphigh = 0;
  1875. if((rxnext % MODULO_INTERRUPT) !=0)
  1876. rxdesc->length |= RxDisIntCompl;
  1877. rxdesc->status = DescOwnByDma;
  1878. gmacdev->RxNext = synopGMAC_is_last_rx_desc(gmacdev,rxdesc) ? 0 : rxnext + 1;
  1879. gmacdev->RxNextDesc = (DmaDesc *)rxdesc->data2;
  1880. }
  1881. else{
  1882. rxdesc->length |= (((Length1 <<DescSize1Shift) & DescSize1Mask) | ((Length2 << DescSize2Shift) & DescSize2Mask));
  1883. rxdesc->buffer1 = Buffer1;
  1884. rxdesc->data1 = Data1;
  1885. rxdesc->extstatus = 0;
  1886. rxdesc->reserved1 = 0;
  1887. rxdesc->timestamplow = 0;
  1888. rxdesc->timestamphigh = 0;
  1889. rxdesc->buffer2 = Buffer2;
  1890. rxdesc->data2 = Data2;
  1891. if((rxnext % MODULO_INTERRUPT) !=0)
  1892. rxdesc->length |= RxDisIntCompl;
  1893. rxdesc->status = DescOwnByDma;
  1894. gmacdev->RxNext = synopGMAC_is_last_rx_desc(gmacdev,rxdesc) ? 0 : rxnext + 1;
  1895. gmacdev->RxNextDesc = synopGMAC_is_last_rx_desc(gmacdev,rxdesc) ? gmacdev->RxDesc : (rxdesc + 1);
  1896. }
  1897. #if SYNOP_RX_DEBUG
  1898. TR("%02d %08x %08x %08x %08x %08x %08x %08x %08x %08x\n",rxnext,(u32)rxdesc,rxdesc->status,rxdesc->length,rxdesc->buffer1,rxdesc->buffer2,rxdesc->data1,rxdesc->data2,rxdesc->dummy1,rxdesc->dummy2);
  1899. #endif
  1900. (gmacdev->BusyRxDesc)++; //One descriptor will be given to Hardware. So busy count incremented by one
  1901. //pci_sync_cache(0, (vm_offset_t)rxdesc,64, SYNC_W);
  1902. return rxnext;
  1903. }
  1904. #else
  1905. /**
  1906. * Prepares the descriptor to receive packets.
  1907. * The descriptor is allocated with the valid buffer addresses (sk_buff address) and the length fields
  1908. * and handed over to DMA by setting the ownership. After successful return from this function the
  1909. * descriptor is added to the receive descriptor pool/queue.
  1910. * This api is same for both ring mode and chain mode.
  1911. * @param[in] pointer to synopGMACdevice.
  1912. * @param[in] Dma-able buffer1 pointer.
  1913. * @param[in] length of buffer1 (Max is 2048).
  1914. * @param[in] Dma-able buffer2 pointer.
  1915. * @param[in] length of buffer2 (Max is 2048).
  1916. * @param[in] u32 data indicating whether the descriptor is in ring mode or chain mode.
  1917. * \return returns present rx descriptor index on success. Negative value if error.
  1918. */
  1919. s32 synopGMAC_set_rx_qptr(synopGMACdevice * gmacdev, u32 Buffer1, u32 Length1, u32 Data1, u32 Buffer2, u32 Length2, u32 Data2)
  1920. {
  1921. u32 rxnext = gmacdev->RxNext;
  1922. DmaDesc * rxdesc = gmacdev->RxNextDesc;
  1923. if(!synopGMAC_is_desc_empty(rxdesc))
  1924. return -1;
  1925. if(synopGMAC_is_rx_desc_chained(rxdesc)){
  1926. rxdesc->length |= ((Length1 <<DescSize1Shift) & DescSize1Mask);
  1927. rxdesc->buffer1 = Buffer1;
  1928. rxdesc->data1 = Data1;
  1929. if((rxnext % MODULO_INTERRUPT) !=0)
  1930. rxdesc->length |= RxDisIntCompl;
  1931. rxdesc->status = DescOwnByDma;
  1932. gmacdev->RxNext = synopGMAC_is_last_rx_desc(gmacdev,rxdesc) ? 0 : rxnext + 1;
  1933. gmacdev->RxNextDesc = (DmaDesc *)rxdesc->data2;
  1934. }
  1935. else{
  1936. rxdesc->length |= (((Length1 <<DescSize1Shift) & DescSize1Mask) | ((Length2 << DescSize2Shift) & DescSize2Mask));
  1937. rxdesc->buffer1 = Buffer1;
  1938. rxdesc->data1 = Data1;
  1939. rxdesc->buffer2 = Buffer2;
  1940. rxdesc->data2 = Data2;
  1941. if((rxnext % MODULO_INTERRUPT) !=0)
  1942. rxdesc->length |= RxDisIntCompl;
  1943. rxdesc->status = DescOwnByDma;
  1944. gmacdev->RxNext = synopGMAC_is_last_rx_desc(gmacdev,rxdesc) ? 0 : rxnext + 1;
  1945. gmacdev->RxNextDesc = synopGMAC_is_last_rx_desc(gmacdev,rxdesc) ? gmacdev->RxDesc : (rxdesc + 1);
  1946. }
  1947. #if SYNOP_RX_DEBUG
  1948. TR("%02d %08x %08x %08x %08x %08x %08x %08x\n",rxnext,(u32)rxdesc,rxdesc->status,rxdesc->length,rxdesc->buffer1,rxdesc->buffer2,rxdesc->data1,rxdesc->data2);
  1949. #endif
  1950. (gmacdev->BusyRxDesc)++; //One descriptor will be given to Hardware. So busy count incremented by one
  1951. return rxnext;
  1952. }
  1953. s32 synopGMAC_set_rx_qptr_init(synopGMACdevice * gmacdev, u32 Buffer1, u32 Length1, u32 Data1, u32 Buffer2, u32 Length2, u32 Data2)
  1954. {
  1955. u32 rxnext = gmacdev->RxNext;
  1956. DmaDesc * rxdesc = gmacdev->RxNextDesc;
  1957. /* sw
  1958. if(synopGMAC_is_desc_owned_by_dma(rxdesc))
  1959. return -1;
  1960. */
  1961. if(!synopGMAC_is_desc_empty(rxdesc))
  1962. return -1;
  1963. if(synopGMAC_is_rx_desc_chained(rxdesc)){
  1964. rxdesc->length |= ((Length1 <<DescSize1Shift) & DescSize1Mask);
  1965. rxdesc->buffer1 = Buffer1;
  1966. rxdesc->data1 = Data1;
  1967. if((rxnext % MODULO_INTERRUPT) !=0)
  1968. rxdesc->length |= RxDisIntCompl;
  1969. rxdesc->status = DescOwnByDma;
  1970. rxdesc->status = 0;
  1971. gmacdev->RxNext = synopGMAC_is_last_rx_desc(gmacdev,rxdesc) ? 0 : rxnext + 1;
  1972. gmacdev->RxNextDesc = (DmaDesc *)rxdesc->data2;
  1973. }
  1974. else{
  1975. rxdesc->length |= (((Length1 <<DescSize1Shift) & DescSize1Mask) | ((Length2 << DescSize2Shift) & DescSize2Mask));
  1976. rxdesc->buffer1 = Buffer1;
  1977. rxdesc->data1 = Data1;
  1978. rxdesc->buffer2 = Buffer2;
  1979. rxdesc->data2 = Data2;
  1980. if((rxnext % MODULO_INTERRUPT) !=0)
  1981. rxdesc->length |= RxDisIntCompl;
  1982. rxdesc->status = DescOwnByDma;
  1983. rxdesc->status = 0;
  1984. gmacdev->RxNext = synopGMAC_is_last_rx_desc(gmacdev,rxdesc) ? 0 : rxnext + 1;
  1985. gmacdev->RxNextDesc = synopGMAC_is_last_rx_desc(gmacdev,rxdesc) ? gmacdev->RxDesc : (rxdesc + 1);
  1986. }
  1987. TR("%02d %08x %08x %08x %08x %08x %08x %08x\n",rxnext,(u32)rxdesc,rxdesc->status,rxdesc->length,rxdesc->buffer1,rxdesc->buffer2,rxdesc->data1,rxdesc->data2);
  1988. (gmacdev->BusyRxDesc)++; //One descriptor will be given to Hardware. So busy count incremented by one
  1989. return rxnext;
  1990. }
  1991. #endif
  1992. #ifdef ENH_DESC_8W
  1993. /**
  1994. * This function is defined two times. Once when the code is compiled for ENHANCED DESCRIPTOR SUPPORT and Once for Normal descriptor
  1995. * Get back the descriptor from DMA after data has been received.
  1996. * When the DMA indicates that the data is received (interrupt is generated), this function should be
  1997. * called to get the descriptor and hence the data buffers received. With successful return from this
  1998. * function caller gets the descriptor fields for processing. check the parameters to understand the
  1999. * fields returned.`
  2000. * @param[in] pointer to synopGMACdevice.
  2001. * @param[out] pointer to hold the status of DMA.
  2002. * @param[out] Dma-able buffer1 pointer.
  2003. * @param[out] pointer to hold length of buffer1 (Max is 2048).
  2004. * @param[out] virtual pointer for buffer1.
  2005. * @param[out] Dma-able buffer2 pointer.
  2006. * @param[out] pointer to hold length of buffer2 (Max is 2048).
  2007. * @param[out] virtual pointer for buffer2.
  2008. * \return returns present rx descriptor index on success. Negative value if error.
  2009. */
  2010. s32 synopGMAC_get_rx_qptr(synopGMACdevice * gmacdev, u32 * Status, u32 * Buffer1, u32 * Length1, u32 * Data1, u32 * Buffer2, u32 * Length2, u32 * Data2,
  2011. u32 * Ext_Status, u32 * Time_Stamp_High, u32 * Time_Stamp_Low)
  2012. {
  2013. u32 rxnext = gmacdev->RxBusy; // index of descriptor the DMA just completed. May be useful when data
  2014. //is spread over multiple buffers/descriptors
  2015. DmaDesc * rxdesc = gmacdev->RxBusyDesc;
  2016. if(synopGMAC_is_desc_owned_by_dma(rxdesc))
  2017. return -1;
  2018. if(synopGMAC_is_desc_empty(rxdesc))
  2019. return -1;
  2020. if(Status != 0)
  2021. *Status = rxdesc->status;// send the status of this descriptor
  2022. if(Ext_Status != 0)
  2023. *Ext_Status = rxdesc->extstatus;
  2024. if(Time_Stamp_High != 0)
  2025. *Time_Stamp_High = rxdesc->timestamphigh;
  2026. if(Time_Stamp_Low != 0)
  2027. *Time_Stamp_Low = rxdesc->timestamplow;
  2028. if(Length1 != 0)
  2029. *Length1 = (rxdesc->length & DescSize1Mask) >> DescSize1Shift;
  2030. if(Buffer1 != 0)
  2031. *Buffer1 = rxdesc->buffer1;
  2032. if(Data1 != 0)
  2033. *Data1 = rxdesc->data1;
  2034. if(Length2 != 0)
  2035. *Length2 = (rxdesc->length & DescSize2Mask) >> DescSize2Shift;
  2036. if(Buffer2 != 0)
  2037. *Buffer2 = rxdesc->buffer2;
  2038. if(Data1 != 0)
  2039. *Data2 = rxdesc->data2;
  2040. gmacdev->RxBusy = synopGMAC_is_last_rx_desc(gmacdev,rxdesc) ? 0 : rxnext + 1;
  2041. if(synopGMAC_is_rx_desc_chained(rxdesc)){
  2042. gmacdev->RxBusyDesc = (DmaDesc *)rxdesc->data2;
  2043. synopGMAC_rx_desc_init_chain(rxdesc);
  2044. //synopGMAC_desc_init_chain(rxdesc, synopGMAC_is_last_rx_desc(gmacdev,rxdesc),0,0);
  2045. }
  2046. else{
  2047. gmacdev->RxBusyDesc = synopGMAC_is_last_rx_desc(gmacdev,rxdesc) ? gmacdev->RxDesc : (rxdesc + 1);
  2048. synopGMAC_rx_desc_init_ring(rxdesc, synopGMAC_is_last_rx_desc(gmacdev,rxdesc));
  2049. }
  2050. TR("%02d %08x %08x %08x %08x %08x %08x %08x\n",rxnext,(u32)rxdesc,rxdesc->status,rxdesc->length,rxdesc->buffer1,rxdesc->buffer2,rxdesc->data1,rxdesc->data2);
  2051. (gmacdev->BusyRxDesc)--; //busy tx descriptor is reduced by one as it will be handed over to Processor now
  2052. return(rxnext);
  2053. }
  2054. #else
  2055. /**
  2056. * Get back the descriptor from DMA after data has been received.
  2057. * When the DMA indicates that the data is received (interrupt is generated), this function should be
  2058. * called to get the descriptor and hence the data buffers received. With successful return from this
  2059. * function caller gets the descriptor fields for processing. check the parameters to understand the
  2060. * fields returned.`
  2061. * @param[in] pointer to synopGMACdevice.
  2062. * @param[out] pointer to hold the status of DMA.
  2063. * @param[out] Dma-able buffer1 pointer.
  2064. * @param[out] pointer to hold length of buffer1 (Max is 2048).
  2065. * @param[out] virtual pointer for buffer1.
  2066. * @param[out] Dma-able buffer2 pointer.
  2067. * @param[out] pointer to hold length of buffer2 (Max is 2048).
  2068. * @param[out] virtual pointer for buffer2.
  2069. * \return returns present rx descriptor index on success. Negative value if error.
  2070. */
  2071. s32 synopGMAC_get_rx_qptr(synopGMACdevice * gmacdev, u32 * Status, u32 * Buffer1, u32 * Length1, u32 * Data1, u32 * Buffer2, u32 * Length2, u32 * Data2)
  2072. {
  2073. u32 rxnext = gmacdev->RxBusy; // index of descriptor the DMA just completed. May be useful when data
  2074. //is spread over multiple buffers/descriptors
  2075. DmaDesc * rxdesc = gmacdev->RxBusyDesc;
  2076. u32 len;
  2077. if(synopGMAC_is_desc_owned_by_dma(rxdesc))
  2078. {
  2079. DEBUG_MES("synopGMAC_get_rx_qptr:DMA descriptor is owned by GMAC!\n");
  2080. return -1;
  2081. }
  2082. if(synopGMAC_is_desc_empty(rxdesc))
  2083. {
  2084. DEBUG_MES("synopGMAC_get_rx_qptr:rx desc is empty!\n");
  2085. return -1;
  2086. }
  2087. if(Status != 0)
  2088. *Status = rxdesc->status;// send the status of this descriptor
  2089. if(Length1 != 0)
  2090. *Length1 = (rxdesc->length & DescSize1Mask) >> DescSize1Shift;
  2091. if(Buffer1 != 0)
  2092. *Buffer1 = rxdesc->buffer1;
  2093. if(Data1 != 0)
  2094. *Data1 = rxdesc->data1;
  2095. if(Length2 != 0)
  2096. *Length2 = (rxdesc->length & DescSize2Mask) >> DescSize2Shift;
  2097. if(Buffer2 != 0)
  2098. *Buffer2 = rxdesc->buffer2;
  2099. if(Data1 != 0)
  2100. *Data2 = rxdesc->data2;
  2101. len = synopGMAC_get_rx_desc_frame_length(*Status);
  2102. DEBUG_MES("Cache sync for data buffer in rx dma desc: length = 0x%x\n",len);
  2103. gmacdev->RxBusy = synopGMAC_is_last_rx_desc(gmacdev,rxdesc) ? 0 : rxnext + 1;
  2104. if(synopGMAC_is_rx_desc_chained(rxdesc)){
  2105. gmacdev->RxBusyDesc = (DmaDesc *)rxdesc->data2;
  2106. synopGMAC_rx_desc_init_chain(rxdesc);
  2107. }
  2108. else{
  2109. gmacdev->RxBusyDesc = synopGMAC_is_last_rx_desc(gmacdev,rxdesc) ? gmacdev->RxDesc : (rxdesc + 1);
  2110. //sw: raw data
  2111. #if SYNOP_RX_DEBUG
  2112. DEBUG_MES("%02d %08x %08x %08x %08x %08x %08x %08x\n",rxnext,(u32)rxdesc,rxdesc->status,rxdesc->length,rxdesc->buffer1,rxdesc->buffer2,rxdesc->data1,rxdesc->data2);
  2113. #endif
  2114. synopGMAC_rx_desc_init_ring(rxdesc, synopGMAC_is_last_rx_desc(gmacdev,rxdesc));
  2115. }
  2116. #if SYNOP_RX_DEBUG
  2117. DEBUG_MES("%02d %08x %08x %08x %08x %08x %08x %08x\n",rxnext,(u32)rxdesc,rxdesc->status,rxdesc->length,rxdesc->buffer1,rxdesc->buffer2,rxdesc->data1,rxdesc->data2);
  2118. #endif
  2119. (gmacdev->BusyRxDesc)--; //This returns one descriptor to processor. So busy count will be decremented by one
  2120. return(rxnext);
  2121. }
  2122. #endif
  2123. /**
  2124. * Clears all the pending interrupts.
  2125. * If the Dma status register is read then all the interrupts gets cleared
  2126. * @param[in] pointer to synopGMACdevice.
  2127. * \return returns void.
  2128. */
  2129. void synopGMAC_clear_interrupt(synopGMACdevice *gmacdev)
  2130. {
  2131. u32 data;
  2132. data = synopGMACReadReg(gmacdev->DmaBase, DmaStatus);
  2133. TR("DMA status reg = 0x%x before cleared!\n",data);
  2134. synopGMACWriteReg(gmacdev->DmaBase, DmaStatus ,data);
  2135. // plat_delay(DEFAULT_LOOP_VARIABLE);
  2136. // data = synopGMACReadReg(gmacdev->DmaBase, DmaStatus);
  2137. TR("DMA status reg = 0x%x after cleared!\n",data);
  2138. }
  2139. /**
  2140. * Returns the all unmasked interrupt status after reading the DmaStatus register.
  2141. * @param[in] pointer to synopGMACdevice.
  2142. * \return 0 upon success. Error code upon failure.
  2143. */
  2144. u32 synopGMAC_get_interrupt_type(synopGMACdevice *gmacdev)
  2145. {
  2146. u32 data;
  2147. u32 interrupts = 0;
  2148. data = synopGMACReadReg(gmacdev->DmaBase, DmaStatus);
  2149. //data = data & ~0x84; //sw: some bits shoud not be cleaned
  2150. synopGMACWriteReg(gmacdev->DmaBase, DmaStatus ,data); //manju: I think this is the appropriate location to clear the interrupts
  2151. plat_delay(DEFAULT_LOOP_VARIABLE);
  2152. if(data & DmaIntErrorMask) interrupts |= synopGMACDmaError;
  2153. if(data & DmaIntRxNormMask) interrupts |= synopGMACDmaRxNormal;
  2154. if(data & DmaIntRxAbnMask) interrupts |= synopGMACDmaRxAbnormal;
  2155. if(data & DmaIntRxStoppedMask) interrupts |= synopGMACDmaRxStopped;
  2156. if(data & DmaIntTxNormMask) interrupts |= synopGMACDmaTxNormal;
  2157. if(data & DmaIntTxAbnMask) interrupts |= synopGMACDmaTxAbnormal;
  2158. if(data & DmaIntTxStoppedMask) interrupts |= synopGMACDmaTxStopped;
  2159. return interrupts;
  2160. }
  2161. /**
  2162. * Returns the interrupt mask.
  2163. * @param[in] pointer to synopGMACdevice.
  2164. * \return 0 upon success. Error code upon failure.
  2165. */
  2166. #if UNUSED
  2167. u32 synopGMAC_get_interrupt_mask(synopGMACdevice *gmacdev)
  2168. {
  2169. return(synopGMACReadReg(gmacdev->DmaBase, DmaInterrupt));
  2170. }
  2171. #endif
  2172. /**
  2173. * Enable all the interrupts.
  2174. * Enables the DMA interrupt as specified by the bit mask.
  2175. * @param[in] pointer to synopGMACdevice.
  2176. * @param[in] bit mask of interrupts to be enabled.
  2177. * \return returns void.
  2178. */
  2179. #if UNUSED
  2180. void synopGMAC_enable_interrupt(synopGMACdevice *gmacdev, u32 interrupts)
  2181. {
  2182. synopGMACWriteReg(gmacdev->DmaBase, DmaInterrupt, interrupts);
  2183. return;
  2184. }
  2185. #endif
  2186. /**
  2187. * Disable all the interrupts.
  2188. * Disables all DMA interrupts.
  2189. * @param[in] pointer to synopGMACdevice.
  2190. * \return returns void.
  2191. * \note This function disabled all the interrupts, if you want to disable a particular interrupt then
  2192. * use synopGMAC_disable_interrupt().
  2193. */
  2194. void synopGMAC_disable_interrupt_all(synopGMACdevice *gmacdev)
  2195. {
  2196. // rt_kprintf("dmabase = 0x%x\n",gmacdev->DmaBase);
  2197. synopGMACWriteReg(gmacdev->DmaBase, DmaInterrupt, DmaIntDisable);
  2198. // synopGMACReadReg(gmacdev->DmaBase, DmaInterrupt);
  2199. return;
  2200. }
  2201. /**
  2202. * Disable interrupt according to the bitfield supplied.
  2203. * Disables only those interrupts specified in the bit mask in second argument.
  2204. * @param[in] pointer to synopGMACdevice.
  2205. * @param[in] bit mask for interrupts to be disabled.
  2206. * \return returns void.
  2207. */
  2208. #if UNUSED
  2209. void synopGMAC_disable_interrupt(synopGMACdevice *gmacdev, u32 interrupts)
  2210. {
  2211. synopGMACClearBits(gmacdev->DmaBase, DmaInterrupt, interrupts);
  2212. return;
  2213. }
  2214. #endif
  2215. /**
  2216. * Enable the DMA Reception.
  2217. * @param[in] pointer to synopGMACdevice.
  2218. * \return returns void.
  2219. */
  2220. void synopGMAC_enable_dma_rx(synopGMACdevice * gmacdev)
  2221. {
  2222. // synopGMACSetBits(gmacdev->DmaBase, DmaControl, DmaRxStart);
  2223. u32 data;
  2224. data = synopGMACReadReg(gmacdev->DmaBase, DmaControl);
  2225. data |= DmaRxStart;
  2226. TR0(" ===33334\n");
  2227. synopGMACWriteReg(gmacdev->DmaBase, DmaControl ,data);
  2228. TR0(" ===33344\n");
  2229. }
  2230. /**
  2231. * Enable the DMA Transmission.
  2232. * @param[in] pointer to synopGMACdevice.
  2233. * \return returns void.
  2234. */
  2235. void synopGMAC_enable_dma_tx(synopGMACdevice * gmacdev)
  2236. {
  2237. // synopGMACSetBits(gmacdev->DmaBase, DmaControl, DmaTxStart);
  2238. u32 data;
  2239. data = synopGMACReadReg(gmacdev->DmaBase, DmaControl);
  2240. data |= DmaTxStart;
  2241. synopGMACWriteReg(gmacdev->DmaBase, DmaControl ,data);
  2242. }
  2243. /**
  2244. * Resumes the DMA Transmission.
  2245. * the DmaTxPollDemand is written. (the data writeen could be anything).
  2246. * This forces the DMA to resume transmission.
  2247. * @param[in] pointer to synopGMACdevice.
  2248. * \return returns void.
  2249. */
  2250. void synopGMAC_resume_dma_tx(synopGMACdevice * gmacdev)
  2251. {
  2252. synopGMACWriteReg(gmacdev->DmaBase, DmaTxPollDemand, 1);
  2253. }
  2254. /**
  2255. * Resumes the DMA Reception.
  2256. * the DmaRxPollDemand is written. (the data writeen could be anything).
  2257. * This forces the DMA to resume reception.
  2258. * @param[in] pointer to synopGMACdevice.
  2259. * \return returns void.
  2260. */
  2261. void synopGMAC_resume_dma_rx(synopGMACdevice * gmacdev)
  2262. {
  2263. synopGMACWriteReg(gmacdev->DmaBase, DmaRxPollDemand, 0);
  2264. }
  2265. /**
  2266. * Take ownership of this Descriptor.
  2267. * The function is same for both the ring mode and the chain mode DMA structures.
  2268. * @param[in] pointer to synopGMACdevice.
  2269. * \return returns void.
  2270. */
  2271. void synopGMAC_take_desc_ownership(DmaDesc * desc)
  2272. {
  2273. if(desc){
  2274. desc->status &= ~DescOwnByDma; //Clear the DMA own bit
  2275. // desc->status |= DescError; // Set the error to indicate this descriptor is bad
  2276. }
  2277. }
  2278. /**
  2279. * Take ownership of all the rx Descriptors.
  2280. * This function is called when there is fatal error in DMA transmission.
  2281. * When called it takes the ownership of all the rx descriptor in rx descriptor pool/queue from DMA.
  2282. * The function is same for both the ring mode and the chain mode DMA structures.
  2283. * @param[in] pointer to synopGMACdevice.
  2284. * \return returns void.
  2285. * \note Make sure to disable the transmission before calling this function, otherwise may result in racing situation.
  2286. */
  2287. void synopGMAC_take_desc_ownership_rx(synopGMACdevice * gmacdev)
  2288. {
  2289. s32 i;
  2290. DmaDesc *desc;
  2291. desc = gmacdev->RxDesc;
  2292. for(i = 0; i < gmacdev->RxDescCount; i++){
  2293. if(synopGMAC_is_rx_desc_chained(desc)){ //This descriptor is in chain mode
  2294. synopGMAC_take_desc_ownership(desc);
  2295. desc = (DmaDesc *)desc->data2;
  2296. }
  2297. else{
  2298. synopGMAC_take_desc_ownership(desc + i);
  2299. }
  2300. }
  2301. }
  2302. /**
  2303. * Take ownership of all the rx Descriptors.
  2304. * This function is called when there is fatal error in DMA transmission.
  2305. * When called it takes the ownership of all the tx descriptor in tx descriptor pool/queue from DMA.
  2306. * The function is same for both the ring mode and the chain mode DMA structures.
  2307. * @param[in] pointer to synopGMACdevice.
  2308. * \return returns void.
  2309. * \note Make sure to disable the transmission before calling this function, otherwise may result in racing situation.
  2310. */
  2311. void synopGMAC_take_desc_ownership_tx(synopGMACdevice * gmacdev)
  2312. {
  2313. s32 i;
  2314. DmaDesc *desc;
  2315. desc = gmacdev->TxDesc;
  2316. for(i = 0; i < gmacdev->TxDescCount; i++){
  2317. if(synopGMAC_is_tx_desc_chained(desc)){ //This descriptor is in chain mode
  2318. synopGMAC_take_desc_ownership(desc);
  2319. desc = (DmaDesc *)desc->data2;
  2320. }
  2321. else{
  2322. synopGMAC_take_desc_ownership(desc + i);
  2323. }
  2324. }
  2325. }
  2326. /**
  2327. * Disable the DMA for Transmission.
  2328. * @param[in] pointer to synopGMACdevice.
  2329. * \return returns void.
  2330. */
  2331. void synopGMAC_disable_dma_tx(synopGMACdevice * gmacdev)
  2332. {
  2333. // synopGMACClearBits(gmacdev->DmaBase, DmaControl, DmaTxStart);
  2334. u32 data;
  2335. data = synopGMACReadReg(gmacdev->DmaBase, DmaControl);
  2336. data &= (~DmaTxStart);
  2337. synopGMACWriteReg(gmacdev->DmaBase, DmaControl ,data);
  2338. }
  2339. /**
  2340. * Disable the DMA for Reception.
  2341. * @param[in] pointer to synopGMACdevice.
  2342. * \return returns void.
  2343. */
  2344. void synopGMAC_disable_dma_rx(synopGMACdevice * gmacdev)
  2345. {
  2346. // synopGMACClearBits(gmacdev->DmaBase, DmaControl, DmaRxStart);
  2347. u32 data;
  2348. data = synopGMACReadReg(gmacdev->DmaBase, DmaControl);
  2349. data &= (~DmaRxStart);
  2350. synopGMACWriteReg(gmacdev->DmaBase, DmaControl ,data);
  2351. }
  2352. /*******************PMT APIs***************************************/
  2353. /**
  2354. * Enables the assertion of PMT interrupt.
  2355. * This enables the assertion of PMT interrupt due to Magic Pkt or Wakeup frame
  2356. * reception.
  2357. * @param[in] pointer to synopGMACdevice.
  2358. * \return returns void.
  2359. */
  2360. #if UNUSED
  2361. void synopGMAC_pmt_int_enable(synopGMACdevice *gmacdev)
  2362. {
  2363. synopGMACClearBits(gmacdev->MacBase,GmacInterruptMask,GmacPmtIntMask);
  2364. return;
  2365. }
  2366. #endif
  2367. /**
  2368. * Disables the assertion of PMT interrupt.
  2369. * This disables the assertion of PMT interrupt due to Magic Pkt or Wakeup frame
  2370. * reception.
  2371. * @param[in] pointer to synopGMACdevice.
  2372. * \return returns void.
  2373. */
  2374. void synopGMAC_pmt_int_disable(synopGMACdevice *gmacdev)
  2375. {
  2376. synopGMACSetBits(gmacdev->MacBase,GmacInterruptMask,GmacPmtIntMask);
  2377. return;
  2378. }
  2379. /**
  2380. * Enables the power down mode of GMAC.
  2381. * This function puts the Gmac in power down mode.
  2382. * @param[in] pointer to synopGMACdevice.
  2383. * \return returns void.
  2384. */
  2385. #if UNUSED
  2386. void synopGMAC_power_down_enable(synopGMACdevice *gmacdev)
  2387. {
  2388. synopGMACSetBits(gmacdev->MacBase,GmacPmtCtrlStatus,GmacPmtPowerDown);
  2389. return;
  2390. }
  2391. #endif
  2392. /**
  2393. * Disables the powerd down setting of GMAC.
  2394. * If the driver wants to bring up the GMAC from powerdown mode, even though the magic packet or the
  2395. * wake up frames received from the network, this function should be called.
  2396. * @param[in] pointer to synopGMACdevice.
  2397. * \return returns void.
  2398. */
  2399. #if UNUSED
  2400. void synopGMAC_power_down_disable(synopGMACdevice *gmacdev)
  2401. {
  2402. synopGMACClearBits(gmacdev->MacBase,GmacPmtCtrlStatus,GmacPmtPowerDown);
  2403. return;
  2404. }
  2405. #endif
  2406. /**
  2407. * Enables the pmt interrupt generation in powerdown mode.
  2408. * @param[in] pointer to synopGMACdevice.
  2409. * \return returns void.
  2410. */
  2411. #if UNUSED
  2412. void synopGMAC_enable_pmt_interrupt(synopGMACdevice *gmacdev)
  2413. {
  2414. synopGMACClearBits(gmacdev->MacBase,GmacInterruptMask,GmacPmtIntMask);
  2415. }
  2416. #endif
  2417. /**
  2418. * Disables the pmt interrupt generation in powerdown mode.
  2419. * @param[in] pointer to synopGMACdevice.
  2420. * \return returns void.
  2421. */
  2422. #if UNUSED
  2423. void synopGMAC_disable_pmt_interrupt(synopGMACdevice *gmacdev)
  2424. {
  2425. synopGMACSetBits(gmacdev->MacBase,GmacInterruptMask,GmacPmtIntMask);
  2426. }
  2427. #endif
  2428. /**
  2429. * Enables GMAC to look for Magic packet.
  2430. * @param[in] pointer to synopGMACdevice.
  2431. * \return returns void.
  2432. */
  2433. #if UNUSED
  2434. void synopGMAC_magic_packet_enable(synopGMACdevice *gmacdev)
  2435. {
  2436. synopGMACSetBits(gmacdev->MacBase,GmacPmtCtrlStatus,GmacPmtMagicPktEnable);
  2437. return;
  2438. }
  2439. #endif
  2440. /**
  2441. * Enables GMAC to look for wake up frame.
  2442. * Wake up frame is defined by the user.
  2443. * @param[in] pointer to synopGMACdevice.
  2444. * \return returns void.
  2445. */
  2446. #if UNUSED
  2447. void synopGMAC_wakeup_frame_enable(synopGMACdevice *gmacdev)
  2448. {
  2449. synopGMACSetBits(gmacdev->MacBase,GmacPmtCtrlStatus,GmacPmtWakeupFrameEnable);
  2450. return;
  2451. }
  2452. #endif
  2453. /**
  2454. * Enables wake-up frame filter to handle unicast packets.
  2455. * @param[in] pointer to synopGMACdevice.
  2456. * \return returns void.
  2457. */
  2458. #if UNUSED
  2459. void synopGMAC_pmt_unicast_enable(synopGMACdevice *gmacdev)
  2460. {
  2461. synopGMACSetBits(gmacdev->MacBase,GmacPmtCtrlStatus,GmacPmtGlobalUnicast);
  2462. return;
  2463. }
  2464. #endif
  2465. /**
  2466. * Checks whether the packet received is a magic packet?.
  2467. * @param[in] pointer to synopGMACdevice.
  2468. * \return returns True if magic packet received else returns false.
  2469. */
  2470. bool synopGMAC_is_magic_packet_received(synopGMACdevice *gmacdev)
  2471. {
  2472. u32 data;
  2473. data = synopGMACReadReg(gmacdev->MacBase,GmacPmtCtrlStatus);
  2474. return((data & GmacPmtMagicPktReceived) == GmacPmtMagicPktReceived);
  2475. }
  2476. /**
  2477. * Checks whether the packet received is a wakeup frame?.
  2478. * @param[in] pointer to synopGMACdevice.
  2479. * \return returns true if wakeup frame received else returns false.
  2480. */
  2481. bool synopGMAC_is_wakeup_frame_received(synopGMACdevice *gmacdev)
  2482. {
  2483. u32 data;
  2484. data = synopGMACReadReg(gmacdev->MacBase,GmacPmtCtrlStatus);
  2485. return((data & GmacPmtWakeupFrameReceived) == GmacPmtWakeupFrameReceived);
  2486. }
  2487. /**
  2488. * Populates the remote wakeup frame registers.
  2489. * Consecutive 8 writes to GmacWakeupAddr writes the wakeup frame filter registers.
  2490. * Before commensing a new write, frame filter pointer is reset to 0x0000.
  2491. * A small delay is introduced to allow frame filter pointer reset operation.
  2492. * @param[in] pointer to synopGMACdevice.
  2493. * @param[in] pointer to frame filter contents array.
  2494. * \return returns void.
  2495. */
  2496. #if UNUSED
  2497. void synopGMAC_write_wakeup_frame_register(synopGMACdevice *gmacdev, u32 * filter_contents)
  2498. {
  2499. s32 i;
  2500. synopGMACSetBits(gmacdev->MacBase,GmacPmtCtrlStatus,GmacPmtFrmFilterPtrReset);
  2501. plat_delay(10);
  2502. for(i =0; i<WAKEUP_REG_LENGTH; i++)
  2503. synopGMACWriteReg(gmacdev->MacBase, GmacWakeupAddr, *(filter_contents + i));
  2504. return;
  2505. }
  2506. #endif
  2507. /*******************PMT APIs***************************************/
  2508. /*******************MMC APIs***************************************/
  2509. /**
  2510. * Freezes the MMC counters.
  2511. * This function call freezes the MMC counters. None of the MMC counters are updated
  2512. * due to any tx or rx frames until synopGMAC_mmc_counters_resume is called.
  2513. * @param[in] pointer to synopGMACdevice.
  2514. * \return returns void.
  2515. */
  2516. #if UNUSED
  2517. void synopGMAC_mmc_counters_stop(synopGMACdevice *gmacdev)
  2518. {
  2519. synopGMACSetBits(gmacdev->MacBase,GmacMmcCntrl,GmacMmcCounterFreeze);
  2520. return;
  2521. }
  2522. #endif
  2523. /**
  2524. * Resumes the MMC counter updation.
  2525. * @param[in] pointer to synopGMACdevice.
  2526. * \return returns void.
  2527. */
  2528. #if UNUSED
  2529. void synopGMAC_mmc_counters_resume(synopGMACdevice *gmacdev)
  2530. {
  2531. synopGMACClearBits(gmacdev->MacBase,GmacMmcCntrl,GmacMmcCounterFreeze);
  2532. return;
  2533. }
  2534. #endif
  2535. /**
  2536. * Configures the MMC in Self clearing mode.
  2537. * Programs MMC interface so that counters are cleared when the counters are read.
  2538. * @param[in] pointer to synopGMACdevice.
  2539. * \return returns void.
  2540. */
  2541. #if UNUSED
  2542. void synopGMAC_mmc_counters_set_selfclear(synopGMACdevice *gmacdev)
  2543. {
  2544. synopGMACSetBits(gmacdev->MacBase,GmacMmcCntrl,GmacMmcCounterResetOnRead);
  2545. return;
  2546. }
  2547. #endif
  2548. /**
  2549. * Configures the MMC in non-Self clearing mode.
  2550. * Programs MMC interface so that counters are cleared when the counters are read.
  2551. * @param[in] pointer to synopGMACdevice.
  2552. * \return returns void.
  2553. */
  2554. #if UNUSED
  2555. void synopGMAC_mmc_counters_reset_selfclear(synopGMACdevice *gmacdev)
  2556. {
  2557. synopGMACClearBits(gmacdev->MacBase,GmacMmcCntrl,GmacMmcCounterResetOnRead);
  2558. return;
  2559. }
  2560. #endif
  2561. /**
  2562. * Configures the MMC to stop rollover.
  2563. * Programs MMC interface so that counters will not rollover after reaching maximum value.
  2564. * @param[in] pointer to synopGMACdevice.
  2565. * \return returns void.
  2566. */
  2567. #if UNUSED
  2568. void synopGMAC_mmc_counters_disable_rollover(synopGMACdevice *gmacdev)
  2569. {
  2570. synopGMACSetBits(gmacdev->MacBase,GmacMmcCntrl,GmacMmcCounterStopRollover);
  2571. return;
  2572. }
  2573. /**
  2574. * Configures the MMC to rollover.
  2575. * Programs MMC interface so that counters will rollover after reaching maximum value.
  2576. * @param[in] pointer to synopGMACdevice.
  2577. * \return returns void.
  2578. */
  2579. void synopGMAC_mmc_counters_enable_rollover(synopGMACdevice *gmacdev)
  2580. {
  2581. synopGMACClearBits(gmacdev->MacBase,GmacMmcCntrl,GmacMmcCounterStopRollover);
  2582. return;
  2583. }
  2584. /**
  2585. * Read the MMC Counter.
  2586. * @param[in] pointer to synopGMACdevice.
  2587. * @param[in] the counter to be read.
  2588. * \return returns the read count value.
  2589. */
  2590. u32 synopGMAC_read_mmc_counter(synopGMACdevice *gmacdev, u32 counter)
  2591. {
  2592. return( synopGMACReadReg(gmacdev->MacBase,counter));
  2593. }
  2594. #endif
  2595. /**
  2596. * Read the MMC Rx interrupt status.
  2597. * @param[in] pointer to synopGMACdevice.
  2598. * \return returns the Rx interrupt status.
  2599. */
  2600. u32 synopGMAC_read_mmc_rx_int_status(synopGMACdevice *gmacdev)
  2601. {
  2602. return( synopGMACReadReg(gmacdev->MacBase,GmacMmcIntrRx));
  2603. }
  2604. /**
  2605. * Read the MMC Tx interrupt status.
  2606. * @param[in] pointer to synopGMACdevice.
  2607. * \return returns the Tx interrupt status.
  2608. */
  2609. u32 synopGMAC_read_mmc_tx_int_status(synopGMACdevice *gmacdev)
  2610. {
  2611. return( synopGMACReadReg(gmacdev->MacBase,GmacMmcIntrTx));
  2612. }
  2613. /**
  2614. * Disable the MMC Tx interrupt.
  2615. * The MMC tx interrupts are masked out as per the mask specified.
  2616. * @param[in] pointer to synopGMACdevice.
  2617. * @param[in] tx interrupt bit mask for which interrupts needs to be disabled.
  2618. * \return returns void.
  2619. */
  2620. void synopGMAC_disable_mmc_tx_interrupt(synopGMACdevice *gmacdev, u32 mask)
  2621. {
  2622. synopGMACSetBits(gmacdev->MacBase,GmacMmcIntrMaskTx,mask);
  2623. return;
  2624. }
  2625. /**
  2626. * Enable the MMC Tx interrupt.
  2627. * The MMC tx interrupts are enabled as per the mask specified.
  2628. * @param[in] pointer to synopGMACdevice.
  2629. * @param[in] tx interrupt bit mask for which interrupts needs to be enabled.
  2630. * \return returns void.
  2631. */
  2632. #if UNUSED
  2633. void synopGMAC_enable_mmc_tx_interrupt(synopGMACdevice *gmacdev, u32 mask)
  2634. {
  2635. synopGMACClearBits(gmacdev->MacBase,GmacMmcIntrMaskTx,mask);
  2636. }
  2637. #endif
  2638. /**
  2639. * Disable the MMC Rx interrupt.
  2640. * The MMC rx interrupts are masked out as per the mask specified.
  2641. * @param[in] pointer to synopGMACdevice.
  2642. * @param[in] rx interrupt bit mask for which interrupts needs to be disabled.
  2643. * \return returns void.
  2644. */
  2645. void synopGMAC_disable_mmc_rx_interrupt(synopGMACdevice *gmacdev, u32 mask)
  2646. {
  2647. synopGMACSetBits(gmacdev->MacBase,GmacMmcIntrMaskRx,mask);
  2648. return;
  2649. }
  2650. /**
  2651. * Enable the MMC Rx interrupt.
  2652. * The MMC rx interrupts are enabled as per the mask specified.
  2653. * @param[in] pointer to synopGMACdevice.
  2654. * @param[in] rx interrupt bit mask for which interrupts needs to be enabled.
  2655. * \return returns void.
  2656. */
  2657. #if UNUSED
  2658. void synopGMAC_enable_mmc_rx_interrupt(synopGMACdevice *gmacdev, u32 mask)
  2659. {
  2660. synopGMACClearBits(gmacdev->MacBase,GmacMmcIntrMaskRx,mask);
  2661. return;
  2662. }
  2663. #endif
  2664. /**
  2665. * Disable the MMC ipc rx checksum offload interrupt.
  2666. * The MMC ipc rx checksum offload interrupts are masked out as per the mask specified.
  2667. * @param[in] pointer to synopGMACdevice.
  2668. * @param[in] rx interrupt bit mask for which interrupts needs to be disabled.
  2669. * \return returns void.
  2670. */
  2671. void synopGMAC_disable_mmc_ipc_rx_interrupt(synopGMACdevice *gmacdev, u32 mask)
  2672. {
  2673. synopGMACSetBits(gmacdev->MacBase,GmacMmcRxIpcIntrMask,mask);
  2674. return;
  2675. }
  2676. /**
  2677. * Enable the MMC ipc rx checksum offload interrupt.
  2678. * The MMC ipc rx checksum offload interrupts are enabled as per the mask specified.
  2679. * @param[in] pointer to synopGMACdevice.
  2680. * @param[in] rx interrupt bit mask for which interrupts needs to be enabled.
  2681. * \return returns void.
  2682. */
  2683. #if UNUSED
  2684. void synopGMAC_enable_mmc_ipc_rx_interrupt(synopGMACdevice *gmacdev, u32 mask)
  2685. {
  2686. synopGMACClearBits(gmacdev->MacBase,GmacMmcRxIpcIntrMask,mask);
  2687. return;
  2688. }
  2689. #endif
  2690. /*******************MMC APIs***************************************/
  2691. /*******************Ip checksum offloading APIs***************************************/
  2692. /**
  2693. * Enables the ip checksum offloading in receive path.
  2694. * When set GMAC calculates 16 bit 1's complement of all received ethernet frame payload.
  2695. * It also checks IPv4 Header checksum is correct. GMAC core appends the 16 bit checksum calculated
  2696. * for payload of IP datagram and appends it to Ethernet frame transferred to the application.
  2697. * @param[in] pointer to synopGMACdevice.
  2698. * \return returns void.
  2699. */
  2700. #if UNUSED
  2701. void synopGMAC_enable_rx_chksum_offload(synopGMACdevice *gmacdev)
  2702. {
  2703. synopGMACSetBits(gmacdev->MacBase,GmacConfig,GmacRxIpcOffload);
  2704. return;
  2705. }
  2706. /**
  2707. * Disable the ip checksum offloading in receive path.
  2708. * Ip checksum offloading is disabled in the receive path.
  2709. * @param[in] pointer to synopGMACdevice.
  2710. * \return returns void.
  2711. */
  2712. void synopGMAC_disable_rx_Ipchecksum_offload(synopGMACdevice *gmacdev)
  2713. {
  2714. synopGMACClearBits(gmacdev->MacBase,GmacConfig,GmacRxIpcOffload);
  2715. }
  2716. /**
  2717. * Instruct the DMA to drop the packets fails tcp ip checksum.
  2718. * This is to instruct the receive DMA engine to drop the recevied packet if they
  2719. * fails the tcp/ip checksum in hardware. Valid only when full checksum offloading is enabled(type-2).
  2720. * @param[in] pointer to synopGMACdevice.
  2721. * \return returns void.
  2722. */
  2723. void synopGMAC_rx_tcpip_chksum_drop_enable(synopGMACdevice *gmacdev)
  2724. {
  2725. synopGMACClearBits(gmacdev->DmaBase,DmaControl,DmaDisableDropTcpCs);
  2726. return;
  2727. }
  2728. /**
  2729. * Instruct the DMA not to drop the packets even if it fails tcp ip checksum.
  2730. * This is to instruct the receive DMA engine to allow the packets even if recevied packet
  2731. * fails the tcp/ip checksum in hardware. Valid only when full checksum offloading is enabled(type-2).
  2732. * @param[in] pointer to synopGMACdevice.
  2733. * \return returns void.
  2734. */
  2735. void synopGMAC_rx_tcpip_chksum_drop_disable(synopGMACdevice *gmacdev)
  2736. {
  2737. synopGMACSetBits(gmacdev->DmaBase,DmaControl,DmaDisableDropTcpCs);
  2738. return;
  2739. }
  2740. #endif
  2741. /**
  2742. * When the Enhanced Descriptor is enabled then the bit 0 of RDES0 indicates whether the
  2743. * Extended Status is available (RDES4). Time Stamp feature and the Checksum Offload Engine2
  2744. * makes use of this extended status to provide the status of the received packet.
  2745. * @param[in] pointer to synopGMACdevice
  2746. * \return returns TRUE or FALSE
  2747. */
  2748. #ifdef ENH_DESC_8W
  2749. /**
  2750. * This function indicates whether extended status is available in the RDES0.
  2751. * Any function which accesses the fields of extended status register must ensure a check on this has been made
  2752. * This is valid only for Enhanced Descriptor.
  2753. * @param[in] pointer to synopGMACdevice.
  2754. * @param[in] u32 status field of the corresponding descriptor.
  2755. * \return returns TRUE or FALSE.
  2756. */
  2757. bool synopGMAC_is_ext_status(synopGMACdevice *gmacdev,u32 status) // extended status present indicates that the RDES4 need to be probed
  2758. {
  2759. return((status & DescRxEXTsts ) != 0 ); // if extstatus set then it returns 1
  2760. }
  2761. /**
  2762. * This function returns true if the IP header checksum bit is set in the extended status.
  2763. * Valid only when enhaced status available is set in RDES0 bit 0.
  2764. * This is valid only for Enhanced Descriptor.
  2765. * @param[in] pointer to synopGMACdevice.
  2766. * @param[in] u32 status field of the corresponding descriptor.
  2767. * \return returns TRUE or FALSE.
  2768. */
  2769. bool synopGMAC_ES_is_IP_header_error(synopGMACdevice *gmacdev,u32 ext_status) // IP header (IPV4) checksum error
  2770. {
  2771. return((ext_status & DescRxIpHeaderError) != 0 ); // if IPV4 header error return 1
  2772. }
  2773. /**
  2774. * This function returns true if the Checksum is bypassed in the hardware.
  2775. * Valid only when enhaced status available is set in RDES0 bit 0.
  2776. * This is valid only for Enhanced Descriptor.
  2777. * @param[in] pointer to synopGMACdevice.
  2778. * @param[in] u32 status field of the corresponding descriptor.
  2779. * \return returns TRUE or FALSE.
  2780. */
  2781. bool synopGMAC_ES_is_rx_checksum_bypassed(synopGMACdevice *gmacdev,u32 ext_status) // Hardware engine bypassed the checksum computation/checking
  2782. {
  2783. return((ext_status & DescRxChkSumBypass ) != 0 ); // if checksum offloading bypassed return 1
  2784. }
  2785. /**
  2786. * This function returns true if payload checksum error is set in the extended status.
  2787. * Valid only when enhaced status available is set in RDES0 bit 0.
  2788. * This is valid only for Enhanced Descriptor.
  2789. * @param[in] pointer to synopGMACdevice.
  2790. * @param[in] u32 status field of the corresponding descriptor.
  2791. * \return returns TRUE or FALSE.
  2792. */
  2793. bool synopGMAC_ES_is_IP_payload_error(synopGMACdevice *gmacdev,u32 ext_status) // IP payload checksum is in error (UDP/TCP/ICMP checksum error)
  2794. {
  2795. return((ext_status & DescRxIpPayloadError) != 0 ); // if IP payload error return 1
  2796. }
  2797. #endif
  2798. /**
  2799. * Decodes the Rx Descriptor status to various checksum error conditions.
  2800. * @param[in] pointer to synopGMACdevice.
  2801. * @param[in] u32 status field of the corresponding descriptor.
  2802. * \return returns decoded enum (u32) indicating the status.
  2803. */
  2804. u32 synopGMAC_is_rx_checksum_error(synopGMACdevice *gmacdev, u32 status)
  2805. {
  2806. if (((status & DescRxChkBit5) == 0) && ((status & DescRxChkBit7) == 0) && ((status & DescRxChkBit0) == 0))
  2807. return RxLenLT600;
  2808. else if(((status & DescRxChkBit5) == 0) && ((status & DescRxChkBit7) == 0) && ((status & DescRxChkBit0) != 0))
  2809. return RxIpHdrPayLoadChkBypass;
  2810. else if(((status & DescRxChkBit5) == 0) && ((status & DescRxChkBit7) != 0) && ((status & DescRxChkBit0) != 0))
  2811. return RxChkBypass;
  2812. else if(((status & DescRxChkBit5) != 0) && ((status & DescRxChkBit7) == 0) && ((status & DescRxChkBit0) == 0))
  2813. return RxNoChkError;
  2814. else if(((status & DescRxChkBit5) != 0) && ((status & DescRxChkBit7) == 0) && ((status & DescRxChkBit0) != 0))
  2815. return RxPayLoadChkError;
  2816. else if(((status & DescRxChkBit5) != 0) && ((status & DescRxChkBit7) != 0) && ((status & DescRxChkBit0) == 0))
  2817. return RxIpHdrChkError;
  2818. else if(((status & DescRxChkBit5) != 0) && ((status & DescRxChkBit7) != 0) && ((status & DescRxChkBit0) != 0))
  2819. return RxIpHdrPayLoadChkError;
  2820. else
  2821. return RxIpHdrPayLoadRes;
  2822. }
  2823. /**
  2824. * Checks if any Ipv4 header checksum error in the frame just transmitted.
  2825. * This serves as indication that error occureed in the IPv4 header checksum insertion.
  2826. * The sent out frame doesnot carry any ipv4 header checksum inserted by the hardware.
  2827. * @param[in] pointer to synopGMACdevice.
  2828. * @param[in] u32 status field of the corresponding descriptor.
  2829. * \return returns true if error in ipv4 header checksum, else returns false.
  2830. */
  2831. bool synopGMAC_is_tx_ipv4header_checksum_error(synopGMACdevice *gmacdev, u32 status)
  2832. {
  2833. return((status & DescTxIpv4ChkError) == DescTxIpv4ChkError);
  2834. }
  2835. /**
  2836. * Checks if any payload checksum error in the frame just transmitted.
  2837. * This serves as indication that error occureed in the payload checksum insertion.
  2838. * The sent out frame doesnot carry any payload checksum inserted by the hardware.
  2839. * @param[in] pointer to synopGMACdevice.
  2840. * @param[in] u32 status field of the corresponding descriptor.
  2841. * \return returns true if error in ipv4 header checksum, else returns false.
  2842. */
  2843. bool synopGMAC_is_tx_payload_checksum_error(synopGMACdevice *gmacdev, u32 status)
  2844. {
  2845. return((status & DescTxPayChkError) == DescTxPayChkError);
  2846. }
  2847. /**
  2848. * The check summ offload engine is bypassed in the tx path.
  2849. * Checksum is not computed in the Hardware.
  2850. * @param[in] pointer to synopGMACdevice.
  2851. * @param[in] Pointer to tx descriptor for which ointer to synopGMACdevice.
  2852. * \return returns void.
  2853. */
  2854. void synopGMAC_tx_checksum_offload_bypass(synopGMACdevice *gmacdev, DmaDesc *desc)
  2855. {
  2856. #ifdef ENH_DESC
  2857. desc->status = (desc->length & (~DescTxCisMask));//ENH_DESC
  2858. #else
  2859. desc->length = (desc->length & (~DescTxCisMask));
  2860. #endif
  2861. }
  2862. /**
  2863. * The check summ offload engine is enabled to do only IPV4 header checksum.
  2864. * IPV4 header Checksum is computed in the Hardware.
  2865. * @param[in] pointer to synopGMACdevice.
  2866. * @param[in] Pointer to tx descriptor for which ointer to synopGMACdevice.
  2867. * \return returns void.
  2868. */
  2869. void synopGMAC_tx_checksum_offload_ipv4hdr(synopGMACdevice *gmacdev, DmaDesc *desc)
  2870. {
  2871. #ifdef ENH_DESC
  2872. desc->status = ((desc->status & (~DescTxCisMask)) | DescTxCisIpv4HdrCs);//ENH_DESC
  2873. #else
  2874. desc->length = ((desc->length & (~DescTxCisMask)) | DescTxCisIpv4HdrCs);
  2875. #endif
  2876. }
  2877. /**
  2878. * The check summ offload engine is enabled to do TCPIP checsum assuming Pseudo header is available.
  2879. * Hardware computes the tcp ip checksum assuming pseudo header checksum is computed in software.
  2880. * Ipv4 header checksum is also inserted.
  2881. * @param[in] pointer to synopGMACdevice.
  2882. * @param[in] Pointer to tx descriptor for which ointer to synopGMACdevice.
  2883. * \return returns void.
  2884. */
  2885. void synopGMAC_tx_checksum_offload_tcponly(synopGMACdevice *gmacdev, DmaDesc *desc)
  2886. {
  2887. #ifdef ENH_DESC
  2888. desc->status = ((desc->status & (~DescTxCisMask)) | DescTxCisTcpOnlyCs);//ENH_DESC
  2889. #else
  2890. desc->length = ((desc->length & (~DescTxCisMask)) | DescTxCisTcpOnlyCs);
  2891. #endif
  2892. }
  2893. /**
  2894. * The check summ offload engine is enabled to do complete checksum computation.
  2895. * Hardware computes the tcp ip checksum including the pseudo header checksum.
  2896. * Here the tcp payload checksum field should be set to 0000.
  2897. * Ipv4 header checksum is also inserted.
  2898. * @param[in] pointer to synopGMACdevice.
  2899. * @param[in] Pointer to tx descriptor for which ointer to synopGMACdevice.
  2900. * \return returns void.
  2901. */
  2902. void synopGMAC_tx_checksum_offload_tcp_pseudo(synopGMACdevice *gmacdev, DmaDesc *desc)
  2903. {
  2904. #ifdef ENH_DESC
  2905. desc->status = ((desc->length & (~DescTxCisMask)) | DescTxCisTcpPseudoCs);
  2906. #else
  2907. desc->length = ((desc->length & (~DescTxCisMask)) | DescTxCisTcpPseudoCs);
  2908. #endif
  2909. }
  2910. /*******************Ip checksum offloading APIs***************************************/
  2911. /*******************IEEE 1588 Timestamping API***************************************/
  2912. /*
  2913. * At this time the driver supports the IEEE time stamping feature when the Enhanced Descriptors are enabled.
  2914. * For normal descriptor and the IEEE time stamp (version 1), driver support is not proviced
  2915. * Please make sure you have enabled the Advanced timestamp feature in the hardware and the driver should
  2916. * be compiled with the ADV_TME_STAMP feature.
  2917. * Some of the APIs provided here may not be valid for all configurations. Please make sure you call the
  2918. * API with due care.
  2919. */
  2920. /**
  2921. * This function enables the timestamping. This enables the timestamping for transmit and receive frames.
  2922. * When disabled timestamp is not added to tx and receive frames and timestamp generator is suspended.
  2923. * @param[in] pointer to synopGMACdevice
  2924. * \return returns void
  2925. */
  2926. #if UNUSED
  2927. void synopGMAC_TS_enable(synopGMACdevice *gmacdev)
  2928. {
  2929. synopGMACSetBits(gmacdev->MacBase,GmacTSControl,GmacTSENA);
  2930. return;
  2931. }
  2932. /**
  2933. * This function disables the timestamping.
  2934. * When disabled timestamp is not added to tx and receive frames and timestamp generator is suspended.
  2935. * @param[in] pointer to synopGMACdevice
  2936. * \return returns void
  2937. */
  2938. void synopGMAC_TS_disable(synopGMACdevice *gmacdev)
  2939. {
  2940. synopGMACClearBits(gmacdev->MacBase,GmacInterruptMask, GmacTSIntMask);
  2941. return;
  2942. }
  2943. /**
  2944. * Enable the interrupt to get timestamping interrupt.
  2945. * This enables the host to get the interrupt when (1) system time is greater or equal to the
  2946. * target time high and low register or (2) there is a overflow in th esecond register.
  2947. * @param[in] pointer to synopGMACdevice
  2948. * \return returns void
  2949. */
  2950. void synopGMAC_TS_int_enable(synopGMACdevice *gmacdev)
  2951. {
  2952. synopGMACClearBits(gmacdev->MacBase,GmacInterruptMask,GmacPmtIntMask);
  2953. return;
  2954. }
  2955. /**
  2956. * Disable the interrupt to get timestamping interrupt.
  2957. * @param[in] pointer to synopGMACdevice
  2958. * \return returns void
  2959. */
  2960. void synopGMAC_TS_int_disable(synopGMACdevice *gmacdev)
  2961. {
  2962. synopGMACSetBits(gmacdev->MacBase,GmacInterruptMask,GmacPmtIntMask);
  2963. return;
  2964. }
  2965. /**
  2966. * Enable MAC address for PTP frame filtering.
  2967. * When enabled, uses MAC address (apart from MAC address 0) to filter the PTP frames when
  2968. * PTP is sent directly over Ethernet.
  2969. * @param[in] pointer to synopGMACdevice
  2970. * \return returns void
  2971. */
  2972. void synopGMAC_TS_mac_addr_filt_enable(synopGMACdevice *gmacdev)
  2973. {
  2974. synopGMACSetBits(gmacdev->MacBase,GmacTSControl,GmacTSENMACADDR);
  2975. return;
  2976. }
  2977. /**
  2978. * Disables MAC address for PTP frame filtering.
  2979. * @param[in] pointer to synopGMACdevice
  2980. * \return returns void
  2981. */
  2982. void synopGMAC_TS_mac_addr_filt_disable(synopGMACdevice *gmacdev)
  2983. {
  2984. synopGMACClearBits(gmacdev->MacBase,GmacTSControl,GmacTSENMACADDR);
  2985. return;
  2986. }
  2987. /**
  2988. * Selet the type of clock mode for PTP.
  2989. * Please note to use one of the follwoing as the clk_type argument.
  2990. * GmacTSOrdClk = 0x00000000, 00=> Ordinary clock
  2991. * GmacTSBouClk = 0x00010000, 01=> Boundary clock
  2992. * GmacTSEtoEClk = 0x00020000, 10=> End-to-End transparent clock
  2993. * GmacTSPtoPClk = 0x00030000, 11=> P-to-P transparent clock
  2994. * @param[in] pointer to synopGMACdevice
  2995. * @param[in] u32 value representing one of the above clk value
  2996. * \return returns void
  2997. */
  2998. void synopGMAC_TS_set_clk_type(synopGMACdevice *gmacdev, u32 clk_type)
  2999. {
  3000. u32 clkval;
  3001. clkval = synopGMACReadReg(gmacdev->MacBase,GmacTSControl); //set the mdc clock to the user defined value
  3002. clkval = clkval | clk_type;
  3003. synopGMACWriteReg(gmacdev->MacBase,GmacTSControl,clkval);
  3004. return;
  3005. }
  3006. /**
  3007. * Enable Snapshot for messages relevant to Master.
  3008. * When enabled, snapshot is taken for messages relevant to master mode only, else snapshot is taken for messages relevant
  3009. * to slave node.
  3010. * Valid only for Ordinary clock and Boundary clock
  3011. * Reserved when "Advanced Time Stamp" is not selected
  3012. * @param[in] pointer to synopGMACdevice
  3013. * \return returns void
  3014. */
  3015. void synopGMAC_TS_master_enable(synopGMACdevice *gmacdev)
  3016. {
  3017. synopGMACSetBits(gmacdev->MacBase,GmacTSControl,GmacTSMSTRENA);
  3018. return;
  3019. }
  3020. /**
  3021. * Disable Snapshot for messages relevant to Master.
  3022. * When disabled, snapshot is taken for messages relevant
  3023. * to slave node.
  3024. * Valid only for Ordinary clock and Boundary clock
  3025. * Reserved when "Advanced Time Stamp" is not selected
  3026. * @param[in] pointer to synopGMACdevice
  3027. * \return returns void
  3028. */
  3029. void synopGMAC_TS_master_disable(synopGMACdevice *gmacdev)
  3030. {
  3031. synopGMACClearBits(gmacdev->MacBase,GmacTSControl,GmacTSMSTRENA);
  3032. return;
  3033. }
  3034. /**
  3035. * Enable Snapshot for Event messages.
  3036. * When enabled, snapshot is taken for event messages only (SYNC, Delay_Req, Pdelay_Req or Pdelay_Resp)
  3037. * When disabled, snapshot is taken for all messages except Announce, Management and Signaling.
  3038. * Reserved when "Advanced Time Stamp" is not selected
  3039. * @param[in] pointer to synopGMACdevice
  3040. * \return returns void
  3041. */
  3042. void synopGMAC_TS_event_enable(synopGMACdevice *gmacdev)
  3043. {
  3044. synopGMACSetBits(gmacdev->MacBase,GmacTSControl,GmacTSEVNTENA);
  3045. return;
  3046. }
  3047. /**
  3048. * Disable Snapshot for Event messages.
  3049. * When disabled, snapshot is taken for all messages except Announce, Management and Signaling.
  3050. * Reserved when "Advanced Time Stamp" is not selected
  3051. * @param[in] pointer to synopGMACdevice
  3052. * \return returns void
  3053. */
  3054. void synopGMAC_TS_event_disable(synopGMACdevice *gmacdev)
  3055. {
  3056. synopGMACClearBits(gmacdev->MacBase,GmacTSControl,GmacTSEVNTENA);
  3057. return;
  3058. }
  3059. /**
  3060. * Enable time stamp snapshot for IPV4 frames.
  3061. * When enabled, time stamp snapshot is taken for IPV4 frames
  3062. * Reserved when "Advanced Time Stamp" is not selected
  3063. * @param[in] pointer to synopGMACdevice
  3064. * \return returns void
  3065. */
  3066. void synopGMAC_TS_IPV4_enable(synopGMACdevice *gmacdev)
  3067. {
  3068. synopGMACSetBits(gmacdev->MacBase,GmacTSControl,GmacTSIPV4ENA);
  3069. return;
  3070. }
  3071. /**
  3072. * Disable time stamp snapshot for IPV4 frames.
  3073. * When disabled, time stamp snapshot is not taken for IPV4 frames
  3074. * Reserved when "Advanced Time Stamp" is not selected
  3075. * @param[in] pointer to synopGMACdevice
  3076. * \return returns void
  3077. */
  3078. void synopGMAC_TS_IPV4_disable(synopGMACdevice *gmacdev)
  3079. {
  3080. synopGMACClearBits(gmacdev->MacBase,GmacTSControl,GmacTSIPV4ENA);
  3081. return;
  3082. } // Only for "Advanced Time Stamp"
  3083. /**
  3084. * Enable time stamp snapshot for IPV6 frames.
  3085. * When enabled, time stamp snapshot is taken for IPV6 frames
  3086. * Reserved when "Advanced Time Stamp" is not selected
  3087. * @param[in] pointer to synopGMACdevice
  3088. * \return returns void
  3089. */
  3090. void synopGMAC_TS_IPV6_enable(synopGMACdevice *gmacdev)
  3091. {
  3092. synopGMACSetBits(gmacdev->MacBase,GmacTSControl,GmacTSIPV6ENA);
  3093. return;
  3094. }
  3095. /**
  3096. * Disable time stamp snapshot for IPV6 frames.
  3097. * When disabled, time stamp snapshot is not taken for IPV6 frames
  3098. * Reserved when "Advanced Time Stamp" is not selected
  3099. * @param[in] pointer to synopGMACdevice
  3100. * \return returns void
  3101. */
  3102. void synopGMAC_TS_IPV6_disable(synopGMACdevice *gmacdev)
  3103. {
  3104. synopGMACClearBits(gmacdev->MacBase,GmacTSControl,GmacTSIPV6ENA);
  3105. return;
  3106. }
  3107. /**
  3108. * Enable time stamp snapshot for PTP over Ethernet frames.
  3109. * When enabled, time stamp snapshot is taken for PTP over Ethernet frames
  3110. * Reserved when "Advanced Time Stamp" is not selected
  3111. * @param[in] pointer to synopGMACdevice
  3112. * \return returns void
  3113. */
  3114. void synopGMAC_TS_ptp_over_ethernet_enable(synopGMACdevice *gmacdev)
  3115. {
  3116. synopGMACSetBits(gmacdev->MacBase,GmacTSControl,GmacTSIPENA);
  3117. return;
  3118. }
  3119. /**
  3120. * Disable time stamp snapshot for PTP over Ethernet frames.
  3121. * When disabled, time stamp snapshot is not taken for PTP over Ethernet frames
  3122. * Reserved when "Advanced Time Stamp" is not selected
  3123. * @param[in] pointer to synopGMACdevice
  3124. * \return returns void
  3125. */
  3126. void synopGMAC_TS_ptp_over_ethernet_disable(synopGMACdevice *gmacdev)
  3127. {
  3128. synopGMACClearBits(gmacdev->MacBase,GmacTSControl,GmacTSIPENA);
  3129. return;
  3130. }
  3131. /**
  3132. * Snoop PTP packet for version 2 format
  3133. * When set the PTP packets are snooped using the version 2 format.
  3134. * @param[in] pointer to synopGMACdevice
  3135. * \return returns void
  3136. */
  3137. void synopGMAC_TS_pkt_snoop_ver2(synopGMACdevice *gmacdev)
  3138. {
  3139. synopGMACSetBits(gmacdev->MacBase,GmacTSControl,GmacTSVER2ENA);
  3140. return;
  3141. }
  3142. /**
  3143. * Snoop PTP packet for version 2 format
  3144. * When set the PTP packets are snooped using the version 2 format.
  3145. * @param[in] pointer to synopGMACdevice
  3146. * \return returns void
  3147. */
  3148. void synopGMAC_TS_pkt_snoop_ver1(synopGMACdevice *gmacdev)
  3149. {
  3150. synopGMACClearBits(gmacdev->MacBase,GmacTSControl,GmacTSVER2ENA);
  3151. return;
  3152. }
  3153. /**
  3154. * Timestamp digital rollover
  3155. * When set the timestamp low register rolls over after 0x3B9A_C9FF value.
  3156. * @param[in] pointer to synopGMACdevice
  3157. * \return returns void
  3158. */
  3159. void synopGMAC_TS_digital_rollover_enable(synopGMACdevice *gmacdev)
  3160. {
  3161. synopGMACSetBits(gmacdev->MacBase,GmacTSControl,GmacTSCTRLSSR);
  3162. return;
  3163. }
  3164. /**
  3165. * Timestamp binary rollover
  3166. * When set the timestamp low register rolls over after 0x7FFF_FFFF value.
  3167. * @param[in] pointer to synopGMACdevice
  3168. * \return returns void
  3169. */
  3170. void synopGMAC_TS_binary_rollover_enable(synopGMACdevice *gmacdev)
  3171. {
  3172. synopGMACClearBits(gmacdev->MacBase,GmacTSControl,GmacTSCTRLSSR);
  3173. return;
  3174. }
  3175. /**
  3176. * Enable Time Stamp for All frames
  3177. * When set the timestamp snap shot is enabled for all frames received by the core.
  3178. * Reserved when "Advanced Time Stamp" is not selected
  3179. * @param[in] pointer to synopGMACdevice
  3180. * \return returns void
  3181. */
  3182. void synopGMAC_TS_all_frames_enable(synopGMACdevice *gmacdev)
  3183. {
  3184. synopGMACSetBits(gmacdev->MacBase,GmacTSControl,GmacTSENALL);
  3185. return;
  3186. }
  3187. /**
  3188. * Disable Time Stamp for All frames
  3189. * When reset the timestamp snap shot is not enabled for all frames received by the core.
  3190. * Reserved when "Advanced Time Stamp" is not selected
  3191. * @param[in] pointer to synopGMACdevice
  3192. * \return returns void
  3193. */
  3194. void synopGMAC_TS_all_frames_disable(synopGMACdevice *gmacdev)
  3195. {
  3196. synopGMACClearBits(gmacdev->MacBase,GmacTSControl,GmacTSENALL);
  3197. return;
  3198. }
  3199. /**
  3200. * Addend Register Update
  3201. * This function loads the contents of Time stamp addend register with the supplied 32 value.
  3202. * This is reserved function when only coarse correction option is selected
  3203. * @param[in] pointer to synopGMACdevice
  3204. * @param[in] 32 bit addend value
  3205. * \return returns 0 for Success or else Failure
  3206. */
  3207. s32 synopGMAC_TS_addend_update(synopGMACdevice *gmacdev, u32 addend_value)
  3208. {
  3209. u32 loop_variable;
  3210. synopGMACWriteReg(gmacdev->MacBase,GmacTSAddend,addend_value);// Load the addend_value in to Addend register
  3211. for(loop_variable = 0; loop_variable < DEFAULT_LOOP_VARIABLE; loop_variable++){ //Wait till the busy bit gets cleared with in a certain amount of time
  3212. if(!((synopGMACReadReg(gmacdev->MacBase,GmacTSControl)) & GmacTSADDREG)){ // if it is cleared then break
  3213. break;
  3214. }
  3215. plat_delay(DEFAULT_DELAY_VARIABLE);
  3216. }
  3217. if(loop_variable < DEFAULT_LOOP_VARIABLE)
  3218. synopGMACSetBits(gmacdev->MacBase,GmacTSControl,GmacTSADDREG);
  3219. else{
  3220. TR("Error::: The TSADDREG bit is not getting cleared !!!!!!\n");
  3221. return -ESYNOPGMACPHYERR;
  3222. }
  3223. return -ESYNOPGMACNOERR;
  3224. }
  3225. /**
  3226. * time stamp Update
  3227. * This function updates (adds/subtracts) with the value specified in the Timestamp High Update and
  3228. * Timestamp Low Update register.
  3229. * @param[in] pointer to synopGMACdevice
  3230. * @param[in] Timestamp High Update value
  3231. * @param[in] Timestamp Low Update value
  3232. * \return returns 0 for Success or else Failure
  3233. */
  3234. s32 synopGMAC_TS_timestamp_update(synopGMACdevice *gmacdev, u32 high_value, u32 low_value)
  3235. {
  3236. u32 loop_variable;
  3237. synopGMACWriteReg(gmacdev->MacBase,GmacTSHighUpdate,high_value);// Load the high value to Timestamp High register
  3238. synopGMACWriteReg(gmacdev->MacBase,GmacTSLowUpdate,low_value);// Load the high value to Timestamp High register
  3239. for(loop_variable = 0; loop_variable < DEFAULT_LOOP_VARIABLE; loop_variable++){ //Wait till the busy bit gets cleared with in a certain amount of time
  3240. if(!((synopGMACReadReg(gmacdev->MacBase,GmacTSControl)) & GmacTSUPDT)){ // if it is cleared then break
  3241. break;
  3242. }
  3243. plat_delay(DEFAULT_DELAY_VARIABLE);
  3244. }
  3245. if(loop_variable < DEFAULT_LOOP_VARIABLE)
  3246. synopGMACSetBits(gmacdev->MacBase,GmacTSControl,GmacTSUPDT);
  3247. else{
  3248. TR("Error::: The TSADDREG bit is not getting cleared !!!!!!\n");
  3249. return -ESYNOPGMACPHYERR;
  3250. }
  3251. return -ESYNOPGMACNOERR;
  3252. }
  3253. /**
  3254. * time stamp Initialize
  3255. * This function Loads/Initializes h the value specified in the Timestamp High Update and
  3256. * Timestamp Low Update register.
  3257. * @param[in] pointer to synopGMACdevice
  3258. * @param[in] Timestamp High Load value
  3259. * @param[in] Timestamp Low Load value
  3260. * \return returns 0 for Success or else Failure
  3261. */
  3262. s32 synopGMAC_TS_timestamp_init(synopGMACdevice *gmacdev, u32 high_value, u32 low_value)
  3263. {
  3264. u32 loop_variable;
  3265. synopGMACWriteReg(gmacdev->MacBase,GmacTSHighUpdate,high_value);// Load the high value to Timestamp High register
  3266. synopGMACWriteReg(gmacdev->MacBase,GmacTSLowUpdate,low_value);// Load the high value to Timestamp High register
  3267. for(loop_variable = 0; loop_variable < DEFAULT_LOOP_VARIABLE; loop_variable++){ //Wait till the busy bit gets cleared with in a certain amount of time
  3268. if(!((synopGMACReadReg(gmacdev->MacBase,GmacTSControl)) & GmacTSINT)){ // if it is cleared then break
  3269. break;
  3270. }
  3271. plat_delay(DEFAULT_DELAY_VARIABLE);
  3272. }
  3273. if(loop_variable < DEFAULT_LOOP_VARIABLE)
  3274. synopGMACSetBits(gmacdev->MacBase,GmacTSControl,GmacTSINT);
  3275. else{
  3276. TR("Error::: The TSADDREG bit is not getting cleared !!!!!!\n");
  3277. return -ESYNOPGMACPHYERR;
  3278. }
  3279. return -ESYNOPGMACNOERR;
  3280. }
  3281. /**
  3282. * Time Stamp Update Coarse
  3283. * When reset the timestamp update is done using coarse method.
  3284. * @param[in] pointer to synopGMACdevice
  3285. * \return returns void
  3286. */
  3287. void synopGMAC_TS_coarse_update(synopGMACdevice *gmacdev)
  3288. {
  3289. synopGMACClearBits(gmacdev->MacBase,GmacTSControl,GmacTSCFUPDT);
  3290. return;
  3291. }
  3292. /**
  3293. * Time Stamp Update Fine
  3294. * When reset the timestamp update is done using Fine method.
  3295. * @param[in] pointer to synopGMACdevice
  3296. * \return returns void
  3297. */
  3298. void synopGMAC_TS_fine_update(synopGMACdevice *gmacdev)
  3299. {
  3300. synopGMACSetBits(gmacdev->MacBase,GmacTSControl,GmacTSCFUPDT);
  3301. return;
  3302. }
  3303. /**
  3304. * Load the Sub Second Increment value in to Sub Second increment register
  3305. * @param[in] pointer to synopGMACdevice
  3306. * \return returns void
  3307. */
  3308. void synopGMAC_TS_subsecond_init(synopGMACdevice *gmacdev, u32 sub_sec_inc_value)
  3309. {
  3310. synopGMACWriteReg(gmacdev->MacBase,GmacTSSubSecIncr,(sub_sec_inc_value & GmacSSINCMsk));
  3311. return;
  3312. }
  3313. /**
  3314. * Reads the time stamp contents in to the respective pointers
  3315. * These registers are readonly.
  3316. * This function returns the 48 bit time stamp assuming Version 2 timestamp with higher word is selected.
  3317. * @param[in] pointer to synopGMACdevice
  3318. * @param[in] pointer to hold 16 higher bit second register contents
  3319. * @param[in] pointer to hold 32 bit second register contents
  3320. * @param[in] pointer to hold 32 bit subnanosecond register contents
  3321. * \return returns void
  3322. * \note Please note that since the atomic access to the timestamp registers is not possible,
  3323. * the contents read may be different from the actual time stamp.
  3324. */
  3325. void synopGMAC_TS_read_timestamp(synopGMACdevice *gmacdev, u16 * higher_sec_val, u32 * sec_val, u32 * sub_sec_val)
  3326. {
  3327. * higher_sec_val = (u16)(synopGMACReadReg(gmacdev->MacBase,GmacTSHighWord) & GmacTSHighWordMask);
  3328. * sec_val = synopGMACReadReg(gmacdev->MacBase,GmacTSHigh);
  3329. * sub_sec_val = synopGMACReadReg(gmacdev->MacBase,GmacTSLow);
  3330. return;
  3331. }
  3332. /**
  3333. * Loads the time stamp higher sec value from the value supplied
  3334. * @param[in] pointer to synopGMACdevice
  3335. * @param[in] 16 higher bit second register contents passed as 32 bit value
  3336. * \return returns void
  3337. */
  3338. void synopGMAC_TS_load_timestamp_higher_val(synopGMACdevice *gmacdev, u32 higher_sec_val)
  3339. {
  3340. synopGMACWriteReg(gmacdev->MacBase,GmacTSHighWord, (higher_sec_val & GmacTSHighWordMask));
  3341. return;
  3342. }
  3343. /**
  3344. * Reads the time stamp higher sec value to respective pointers
  3345. * @param[in] pointer to synopGMACdevice
  3346. * @param[in] pointer to hold 16 higher bit second register contents
  3347. * \return returns void
  3348. */
  3349. void synopGMAC_TS_read_timestamp_higher_val(synopGMACdevice *gmacdev, u16 * higher_sec_val)
  3350. {
  3351. * higher_sec_val = (u16)(synopGMACReadReg(gmacdev->MacBase,GmacTSHighWord) & GmacTSHighWordMask);
  3352. return;
  3353. }
  3354. /**
  3355. * Load the Target time stamp registers
  3356. * This function Loads the target time stamp registers with the values proviced
  3357. * @param[in] pointer to synopGMACdevice
  3358. * @param[in] target Timestamp High value
  3359. * @param[in] target Timestamp Low value
  3360. * \return returns 0 for Success or else Failure
  3361. */
  3362. void synopGMAC_TS_load_target_timestamp(synopGMACdevice *gmacdev, u32 sec_val, u32 sub_sec_val)
  3363. {
  3364. synopGMACWriteReg(gmacdev->MacBase,GmacTSTargetTimeHigh,sec_val);
  3365. synopGMACWriteReg(gmacdev->MacBase,GmacTSTargetTimeLow,sub_sec_val);
  3366. return;
  3367. }
  3368. /**
  3369. * Reads the Target time stamp registers
  3370. * This function Loads the target time stamp registers with the values proviced
  3371. * @param[in] pointer to synopGMACdevice
  3372. * @param[in] pointer to hold target Timestamp High value
  3373. * @param[in] pointer to hold target Timestamp Low value
  3374. * \return returns 0 for Success or else Failure
  3375. */
  3376. void synopGMAC_TS_read_target_timestamp(synopGMACdevice *gmacdev, u32 * sec_val, u32 * sub_sec_val)
  3377. {
  3378. * sec_val = synopGMACReadReg(gmacdev->MacBase,GmacTSTargetTimeHigh);
  3379. * sub_sec_val = synopGMACReadReg(gmacdev->MacBase,GmacTSTargetTimeLow);
  3380. return;
  3381. }
  3382. #endif