synopGMAC_Dev.c 125 KB

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