synopGMAC_Dev.c 124 KB

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