synopGMAC_Dev.c 125 KB

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