synopGMAC_Dev.c 121 KB

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