modem_cldma.c 140 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927
  1. /*
  2. * this is a CLDMA modem driver.
  3. *
  4. * V0.1: Xiao Wang <xiao.wang@mediatek.com>
  5. */
  6. #include <linux/list.h>
  7. #include <linux/device.h>
  8. #include <linux/module.h>
  9. #include <linux/kernel.h>
  10. #include <linux/err.h>
  11. #include <linux/kdev_t.h>
  12. #include <linux/slab.h>
  13. #include <linux/wait.h>
  14. #include <linux/sched.h>
  15. #include <linux/kthread.h>
  16. #include <linux/delay.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/timer.h>
  19. #include <linux/fs.h>
  20. #include <linux/netdevice.h>
  21. #include <linux/random.h>
  22. #include <linux/platform_device.h>
  23. #if defined(CONFIG_MTK_AEE_FEATURE)
  24. #include <mt-plat/aee.h>
  25. #endif
  26. #include <mt_spm_sleep.h>
  27. #include <mt-plat/mt_boot.h>
  28. #include "ccci_config.h"
  29. #include "ccci_core.h"
  30. #include "ccci_bm.h"
  31. #include "ccci_platform.h"
  32. #include "modem_cldma.h"
  33. #include "cldma_platform.h"
  34. #include "cldma_reg.h"
  35. #include "modem_reg_base.h"
  36. #include <mach/mt_pbm.h>
  37. #if defined(CLDMA_TRACE) || defined(CCCI_SKB_TRACE)
  38. #define CREATE_TRACE_POINTS
  39. #include "modem_cldma_events.h"
  40. #endif
  41. #ifdef CONFIG_OF
  42. #include <linux/of.h>
  43. #include <linux/of_fdt.h>
  44. #include <linux/of_irq.h>
  45. #include <linux/of_address.h>
  46. #endif
  47. #ifdef ENABLE_CLDMA_AP_SIDE
  48. #include <linux/syscore_ops.h>
  49. #endif
  50. #if defined(ENABLE_32K_CLK_LESS)
  51. #include <mt-plat/mtk_rtc.h>
  52. #endif
  53. static unsigned int trace_sample_time = 200000000;
  54. static int md_cd_ccif_send(struct ccci_modem *md, int channel_id);
  55. /* CLDMA setting */
  56. /* always keep this in mind: what if there are more than 1 modems using CLDMA... */
  57. /*
  58. * we use this as rgpd->data_allow_len, so skb length must be >= this size, check ccci_bm.c's skb pool design.
  59. * channel 3 is for network in normal mode, but for mdlogger_ctrl in exception mode, so choose the max packet size.
  60. */
  61. static int net_rx_queue_buffer_size[CLDMA_RXQ_NUM] = { 0, 0, 0, NET_RX_BUF, NET_RX_BUF, NET_RX_BUF, 0, 0 };
  62. static int normal_rx_queue_buffer_size[CLDMA_RXQ_NUM] = { SKB_4K, SKB_4K, SKB_4K, SKB_4K, 0, 0, SKB_4K, SKB_16 };
  63. #if 0 /* for debug log dump convenience */
  64. static int net_rx_queue_buffer_number[CLDMA_RXQ_NUM] = { 0, 0, 0, 16, 16, 16, 0, 0 };
  65. static int net_tx_queue_buffer_number[CLDMA_TXQ_NUM] = { 0, 0, 0, 16, 16, 16, 0, 0 };
  66. #else
  67. static int net_rx_queue_buffer_number[CLDMA_RXQ_NUM] = { 0, 0, 0, 256, 256, 64, 0, 0 };
  68. static int net_tx_queue_buffer_number[CLDMA_TXQ_NUM] = { 0, 0, 0, 256, 256, 64, 0, 0 };
  69. #endif
  70. static int normal_rx_queue_buffer_number[CLDMA_RXQ_NUM] = { 16, 16, 16, 16, 0, 0, 16, 2 };
  71. static int normal_tx_queue_buffer_number[CLDMA_TXQ_NUM] = { 16, 16, 16, 16, 0, 0, 16, 2 };
  72. static int net_rx_queue2ring[CLDMA_RXQ_NUM] = { -1, -1, -1, 0, 1, 2, -1, -1 };
  73. static int net_tx_queue2ring[CLDMA_TXQ_NUM] = { -1, -1, -1, 0, 1, 2, -1, -1 };
  74. static int normal_rx_queue2ring[CLDMA_RXQ_NUM] = { 0, 1, 2, 3, -1, -1, 4, 5 };
  75. static int normal_tx_queue2ring[CLDMA_TXQ_NUM] = { 0, 1, 2, 3, -1, -1, 4, 5 };
  76. static int net_rx_ring2queue[NET_RXQ_NUM] = { 3, 4, 5 };
  77. static int net_tx_ring2queue[NET_TXQ_NUM] = { 3, 4, 5 };
  78. static int normal_rx_ring2queue[NORMAL_RXQ_NUM] = { 0, 1, 2, 3, 6, 7 };
  79. static int normal_tx_ring2queue[NORMAL_TXQ_NUM] = { 0, 1, 2, 3, 6, 7 };
  80. static const unsigned char high_priority_queue_mask = 0x00;
  81. #define NET_TX_QUEUE_MASK 0x38 /* 3, 4, 5 */
  82. #define NET_RX_QUEUE_MASK 0x38 /* 3, 4, 5 */
  83. #define NAPI_QUEUE_MASK NET_RX_QUEUE_MASK /* Rx, only Rx-exclusive port can enable NAPI */
  84. #define NORMAL_TX_QUEUE_MASK 0xCF /* 0, 1, 2, 3, 6, 7 */
  85. #define NORMAL_RX_QUEUE_MASK 0xCF /* 0, 1, 2, 3, 6, 7 */
  86. #define NONSTOP_QUEUE_MASK 0xF0 /* Rx, for convenience, queue 0,1,2,3 are non-stop */
  87. #define NONSTOP_QUEUE_MASK_32 0xF0F0F0F0
  88. #define CLDMA_CG_POLL 6
  89. #define CLDMA_ACTIVE_T 20
  90. #define BOOT_TIMER_ON 20/*10*/
  91. #define LOW_PRIORITY_QUEUE (0x4)
  92. #define TAG "mcd"
  93. #define IS_NET_QUE(md, qno) \
  94. ((md->md_state != EXCEPTION || md->ex_stage != EX_INIT_DONE) && ((1<<qno) & NET_RX_QUEUE_MASK))
  95. static void cldma_dump_gpd_queue(struct ccci_modem *md, unsigned int qno)
  96. {
  97. unsigned int *tmp;
  98. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  99. struct cldma_request *req = NULL;
  100. #ifdef CLDMA_DUMP_BD
  101. struct cldma_request *req_bd = NULL;
  102. #endif
  103. /* use request's link head to traverse */
  104. CCCI_INF_MSG(md->index, TAG, " dump txq %d request\n", qno);
  105. list_for_each_entry(req, &md_ctrl->txq[qno].tr_ring->gpd_ring, entry) {
  106. tmp = (unsigned int *)req->gpd;
  107. CCCI_INF_MSG(md->index, TAG, " 0x%p: %X %X %X %X\n", req->gpd,
  108. *tmp, *(tmp + 1), *(tmp + 2), *(tmp + 3));
  109. #ifdef CLDMA_DUMP_BD
  110. list_for_each_entry(req_bd, &req->bd, entry) {
  111. tmp = (unsigned int *)req_bd->gpd;
  112. CCCI_INF_MSG(md->index, TAG, "-0x%p: %X %X %X %X\n", req_bd->gpd,
  113. *tmp, *(tmp + 1), *(tmp + 2), *(tmp + 3));
  114. }
  115. #endif
  116. }
  117. /* use request's link head to traverse */
  118. CCCI_INF_MSG(md->index, TAG, " dump rxq %d, tr_ring=%p -> gpd_ring=0x%p\n", qno, md_ctrl->rxq[qno].tr_ring,
  119. &md_ctrl->rxq[qno].tr_ring->gpd_ring);
  120. list_for_each_entry(req, &md_ctrl->rxq[qno].tr_ring->gpd_ring, entry) {
  121. tmp = (unsigned int *)req->gpd;
  122. CCCI_INF_MSG(md->index, TAG, " 0x%p/0x%p: %X %X %X %X\n", req->gpd, req->skb,
  123. *tmp, *(tmp + 1), *(tmp + 2), *(tmp + 3));
  124. }
  125. }
  126. static void cldma_dump_all_gpd(struct ccci_modem *md)
  127. {
  128. int i;
  129. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  130. for (i = 0; i < QUEUE_LEN(md_ctrl->txq); i++)
  131. cldma_dump_gpd_queue(md, i);
  132. }
  133. #if TRAFFIC_MONITOR_INTERVAL
  134. void md_cd_traffic_monitor_func(unsigned long data)
  135. {
  136. struct ccci_modem *md = (struct ccci_modem *)data;
  137. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  138. struct ccci_port *port;
  139. unsigned long long port_full = 0; /* hardcode, port number should not be larger than 64 */
  140. unsigned int i;
  141. for (i = 0; i < md->port_number; i++) {
  142. port = md->ports + i;
  143. if (port->flags & PORT_F_RX_FULLED)
  144. port_full |= (1 << i);
  145. if (port->tx_busy_count != 0 || port->rx_busy_count != 0) {
  146. CCCI_INF_MSG(md->index, TAG, "port %s busy count %d/%d\n", port->name,
  147. port->tx_busy_count, port->rx_busy_count);
  148. port->tx_busy_count = 0;
  149. port->rx_busy_count = 0;
  150. }
  151. if (port->ops->dump_info)
  152. port->ops->dump_info(port, 0);
  153. }
  154. for (i = 0; i < QUEUE_LEN(md_ctrl->txq); i++) {
  155. if (md_ctrl->txq[i].busy_count != 0) {
  156. CCCI_INF_MSG(md->index, TAG, "Txq%d busy count %d\n", i, md_ctrl->txq[i].busy_count);
  157. md_ctrl->txq[i].busy_count = 0;
  158. }
  159. }
  160. #ifdef ENABLE_CLDMA_TIMER
  161. CCCI_INF_MSG(md->index, TAG, "traffic(tx_timer): [3]%llu %llu, [4]%llu %llu, [5]%llu %llu\n",
  162. md_ctrl->txq[3].timeout_start, md_ctrl->txq[3].timeout_end,
  163. md_ctrl->txq[4].timeout_start, md_ctrl->txq[4].timeout_end,
  164. md_ctrl->txq[5].timeout_start, md_ctrl->txq[5].timeout_end);
  165. md_cd_lock_cldma_clock_src(1);
  166. CCCI_INF_MSG(md->index, TAG,
  167. "traffic(tx_done_timer): CLDMA_AP_L2TIMR0=0x%x [3]%d %llu, [4]%d %llu, [5]%d %llu\n",
  168. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2TIMR0),
  169. md_ctrl->tx_done_last_count[3], md_ctrl->tx_done_last_start_time[3],
  170. md_ctrl->tx_done_last_count[4], md_ctrl->tx_done_last_start_time[4],
  171. md_ctrl->tx_done_last_count[5], md_ctrl->tx_done_last_start_time[5]
  172. );
  173. md_cd_lock_cldma_clock_src(0);
  174. #endif
  175. CCCI_INF_MSG(md->index, TAG,
  176. "traffic(%d/%llx):Tx(%x)%d-%d,%d-%d,%d-%d,%d-%d,%d-%d,%d-%d,%d-%d,%d-%d:Rx(%x)%d,%d,%d,%d,%d,%d,%d,%d\n",
  177. md->md_state, port_full,
  178. md_ctrl->txq_active,
  179. md_ctrl->tx_pre_traffic_monitor[0], md_ctrl->tx_traffic_monitor[0],
  180. md_ctrl->tx_pre_traffic_monitor[1], md_ctrl->tx_traffic_monitor[1],
  181. md_ctrl->tx_pre_traffic_monitor[2], md_ctrl->tx_traffic_monitor[2],
  182. md_ctrl->tx_pre_traffic_monitor[3], md_ctrl->tx_traffic_monitor[3],
  183. md_ctrl->tx_pre_traffic_monitor[4], md_ctrl->tx_traffic_monitor[4],
  184. md_ctrl->tx_pre_traffic_monitor[5], md_ctrl->tx_traffic_monitor[5],
  185. md_ctrl->tx_pre_traffic_monitor[6], md_ctrl->tx_traffic_monitor[6],
  186. md_ctrl->tx_pre_traffic_monitor[7], md_ctrl->tx_traffic_monitor[7],
  187. md_ctrl->rxq_active,
  188. md_ctrl->rx_traffic_monitor[0], md_ctrl->rx_traffic_monitor[1],
  189. md_ctrl->rx_traffic_monitor[2], md_ctrl->rx_traffic_monitor[3],
  190. md_ctrl->rx_traffic_monitor[4], md_ctrl->rx_traffic_monitor[5],
  191. md_ctrl->rx_traffic_monitor[6], md_ctrl->rx_traffic_monitor[7]);
  192. CCCI_DBG_MSG(md->index, TAG, "net Rx skb queue:%u %u %u / %u %u %u\n",
  193. md_ctrl->rxq[3].skb_list.max_history, md_ctrl->rxq[4].skb_list.max_history,
  194. md_ctrl->rxq[5].skb_list.max_history, md_ctrl->rxq[3].skb_list.skb_list.qlen,
  195. md_ctrl->rxq[4].skb_list.skb_list.qlen, md_ctrl->rxq[5].skb_list.skb_list.qlen);
  196. ccci_channel_dump_packet_counter(md);
  197. }
  198. #endif
  199. static void cldma_dump_packet_history(struct ccci_modem *md)
  200. {
  201. int i;
  202. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  203. for (i = 0; i < QUEUE_LEN(md_ctrl->txq); i++) {
  204. CCCI_INF_MSG(md->index, TAG, "Current txq%d pos: tr_done=%x, tx_xmit=%x\n", i,
  205. (unsigned int)md_ctrl->txq[i].tr_done->gpd_addr,
  206. (unsigned int)md_ctrl->txq[i].tx_xmit->gpd_addr);
  207. }
  208. for (i = 0; i < QUEUE_LEN(md_ctrl->rxq); i++) {
  209. CCCI_INF_MSG(md->index, TAG, "Current rxq%d pos: tr_done=%x, rx_refill=%x\n", i,
  210. (unsigned int)md_ctrl->rxq[i].tr_done->gpd_addr,
  211. (unsigned int)md_ctrl->rxq[i].rx_refill->gpd_addr);
  212. }
  213. ccci_dump_log_history(md, 1, QUEUE_LEN(md_ctrl->txq), QUEUE_LEN(md_ctrl->rxq));
  214. }
  215. static void cldma_dump_queue_history(struct ccci_modem *md, unsigned int qno)
  216. {
  217. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  218. CCCI_INF_MSG(md->index, TAG, "Current txq%d pos: tr_done=%x, tx_xmit=%x\n", qno,
  219. (unsigned int)md_ctrl->txq[qno].tr_done->gpd_addr, (unsigned int)md_ctrl->txq[qno].tx_xmit->gpd_addr);
  220. CCCI_INF_MSG(md->index, TAG, "Current rxq%d pos: tr_done=%x, rx_refill=%x\n", qno,
  221. (unsigned int)md_ctrl->rxq[qno].tr_done->gpd_addr, (unsigned int)md_ctrl->rxq[qno].rx_refill->gpd_addr);
  222. ccci_dump_log_history(md, 0, qno, qno);
  223. }
  224. #if CHECKSUM_SIZE
  225. static inline void caculate_checksum(char *address, char first_byte)
  226. {
  227. int i;
  228. char sum = first_byte;
  229. for (i = 2; i < CHECKSUM_SIZE; i++)
  230. sum += *(address + i);
  231. *(address + 1) = 0xFF - sum;
  232. }
  233. #else
  234. #define caculate_checksum(address, first_byte)
  235. #endif
  236. static int cldma_queue_broadcast_state(struct ccci_modem *md, MD_STATE state, DIRECTION dir, int index)
  237. {
  238. struct ccci_port *port;
  239. int i, match = 0;
  240. for (i = 0; i < md->port_number; i++) {
  241. port = md->ports + i;
  242. /* consider network data/ack queue design */
  243. if (md->md_state == EXCEPTION)
  244. match = dir == OUT ? index == port->txq_exp_index : index == port->rxq_exp_index;
  245. else
  246. match = dir == OUT ? index == port->txq_index
  247. || index == (port->txq_exp_index & 0x0F) : index == port->rxq_index;
  248. if (match && port->ops->md_state_notice)
  249. port->ops->md_state_notice(port, state);
  250. }
  251. return 0;
  252. }
  253. #ifdef ENABLE_CLDMA_TIMER
  254. static void cldma_timeout_timer_func(unsigned long data)
  255. {
  256. struct md_cd_queue *queue = (struct md_cd_queue *)data;
  257. struct ccci_modem *md = queue->modem;
  258. struct ccci_port *port;
  259. unsigned long long port_full = 0, i;
  260. if (MD_IN_DEBUG(md))
  261. return;
  262. for (i = 0; i < md->port_number; i++) {
  263. port = md->ports + i;
  264. if (port->flags & PORT_F_RX_FULLED)
  265. port_full |= (1 << i);
  266. }
  267. CCCI_ERR_MSG(md->index, TAG, "CLDMA txq%d no response for %d seconds, ports=%llx\n", queue->index,
  268. CLDMA_ACTIVE_T, port_full);
  269. md_cd_traffic_monitor_func((unsigned long)md);
  270. md->ops->dump_info(md, DUMP_FLAG_CLDMA, NULL, queue->index);
  271. CCCI_ERR_MSG(md->index, TAG, "CLDMA no response, force assert md by CCIF_INTERRUPT\n");
  272. md->ops->force_assert(md, CCIF_INTERRUPT);
  273. }
  274. #endif
  275. static int cldma_gpd_rx_refill(struct md_cd_queue *queue)
  276. {
  277. struct ccci_modem *md = queue->modem;
  278. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  279. struct cldma_request *req;
  280. struct cldma_rgpd *rgpd;
  281. struct sk_buff *new_skb = NULL;
  282. int count = 0;
  283. unsigned long flags;
  284. char is_net_queue = IS_NET_QUE(md, queue->index);
  285. while (1) {
  286. spin_lock_irqsave(&queue->ring_lock, flags);
  287. req = queue->rx_refill;
  288. if (req->skb != NULL) {
  289. spin_unlock_irqrestore(&queue->ring_lock, flags);
  290. break;
  291. }
  292. spin_unlock_irqrestore(&queue->ring_lock, flags);
  293. /* allocate a new skb outside of lock */
  294. new_skb = ccci_alloc_skb(queue->tr_ring->pkt_size, !is_net_queue, 1);
  295. if (likely(new_skb)) {
  296. rgpd = (struct cldma_rgpd *)req->gpd;
  297. req->data_buffer_ptr_saved =
  298. dma_map_single(&md->plat_dev->dev, new_skb->data, skb_data_size(new_skb), DMA_FROM_DEVICE);
  299. rgpd->data_buff_bd_ptr = (u32) (req->data_buffer_ptr_saved);
  300. rgpd->data_buff_len = 0;
  301. /* checksum of GPD */
  302. caculate_checksum((char *)rgpd, 0x81);
  303. /* set HWO and mark cldma_request as available*/
  304. spin_lock_irqsave(&queue->ring_lock, flags);
  305. spin_lock(&md_ctrl->cldma_timeout_lock);
  306. cldma_write8(&rgpd->gpd_flags, 0, 0x81);
  307. spin_unlock(&md_ctrl->cldma_timeout_lock);
  308. req->skb = new_skb;
  309. spin_unlock_irqrestore(&queue->ring_lock, flags);
  310. /* step forward */
  311. queue->rx_refill = cldma_ring_step_forward(queue->tr_ring, req);
  312. count++;
  313. } else {
  314. CCCI_ERR_MSG(md->index, TAG, "alloc skb fail on q%d\n", queue->index);
  315. #ifdef CLDMA_TRACE
  316. trace_cldma_error(queue->index, 0, NO_SKB, __LINE__);
  317. #endif
  318. /* don not break out, run again */
  319. msleep(100);
  320. }
  321. }
  322. return count;
  323. }
  324. static int cldma_gpd_rx_collect(struct md_cd_queue *queue, int budget, int blocking, int *result,
  325. int *rxbytes)
  326. {
  327. struct ccci_modem *md = queue->modem;
  328. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  329. struct cldma_request *req;
  330. struct cldma_rgpd *rgpd;
  331. struct ccci_request *new_req = NULL;
  332. struct ccci_header ccci_h;
  333. struct sk_buff *skb = NULL;
  334. #ifdef CLDMA_TRACE
  335. unsigned long long req_alloc_time = 0;
  336. unsigned long long port_recv_time = 0;
  337. unsigned long long total_handle_time = 0;
  338. #endif
  339. int ret = 0, count = 0;
  340. unsigned long long skb_bytes = 0;
  341. unsigned long flags;
  342. *result = UNDER_BUDGET;
  343. *rxbytes = 0;
  344. while (1) {
  345. #ifdef CLDMA_TRACE
  346. total_handle_time = sched_clock();
  347. #endif
  348. spin_lock_irqsave(&queue->ring_lock, flags);
  349. req = queue->tr_done;
  350. rgpd = (struct cldma_rgpd *)req->gpd;
  351. if (!((rgpd->gpd_flags & 0x1) == 0 && req->skb)) {
  352. spin_unlock_irqrestore(&queue->ring_lock, flags);
  353. break;
  354. }
  355. spin_unlock_irqrestore(&queue->ring_lock, flags);
  356. skb = req->skb;
  357. /* update skb */
  358. dma_unmap_single(&md->plat_dev->dev, req->data_buffer_ptr_saved,
  359. skb_data_size(req->skb), DMA_FROM_DEVICE);
  360. skb_put(skb, rgpd->data_buff_len);
  361. skb_bytes = skb->len;
  362. ccci_h = *((struct ccci_header *)skb->data);
  363. /* check wakeup source */
  364. if (atomic_cmpxchg(&md->wakeup_src, 1, 0) == 1)
  365. CCCI_INF_MSG(md->index, TAG, "CLDMA_MD wakeup source:(%d/%d)\n", queue->index, ccci_h.channel);
  366. CCCI_DBG_MSG(md->index, TAG, "recv Rx msg (%x %x %x %x) rxq=%d len=%d\n",
  367. ccci_h.data[0], ccci_h.data[1], *(((u32 *)&ccci_h) + 2), ccci_h.reserved, queue->index,
  368. rgpd->data_buff_len);
  369. /*
  370. * allocate a new wrapper, do nothing if this failed, just wait someone to collect this queue again,
  371. * if lucky enough. for network queue, no wrapper is used, here we assume CCMNI port must can
  372. * handle skb directly.
  373. */
  374. #ifdef CLDMA_TRACE
  375. req_alloc_time = sched_clock();
  376. #endif
  377. new_req = ccci_alloc_req(IN, -1, blocking, 0);
  378. #ifdef CLDMA_TRACE
  379. port_recv_time = sched_clock();
  380. req_alloc_time = port_recv_time - req_alloc_time;
  381. #endif
  382. if (unlikely(!new_req)) {
  383. CCCI_ERR_MSG(md->index, TAG, "alloc req fail on q%d\n", queue->index);
  384. *result = NO_REQ;
  385. #ifdef CLDMA_TRACE
  386. trace_cldma_error(queue->index, ccci_h.channel, NO_REQ, __LINE__);
  387. #endif
  388. goto leave_skb_in_ring;
  389. }
  390. new_req->skb = skb;
  391. INIT_LIST_HEAD(&new_req->entry); /* as port will run list_del */
  392. ret = ccci_port_recv_request(md, new_req, skb);
  393. #ifdef CLDMA_TRACE
  394. port_recv_time = (sched_clock() - port_recv_time);
  395. #endif
  396. CCCI_DBG_MSG(md->index, TAG, "Rx port recv req ret=%d\n", ret);
  397. spin_lock_irqsave(&queue->ring_lock, flags);
  398. if (ret >= 0 || ret == -CCCI_ERR_DROP_PACKET) {
  399. /* mark cldma_request as available */
  400. req->skb = NULL;
  401. rgpd->data_buff_bd_ptr = 0;
  402. /* step forward */
  403. queue->tr_done = cldma_ring_step_forward(queue->tr_ring, req);
  404. spin_unlock_irqrestore(&queue->ring_lock, flags);
  405. /* update log */
  406. ccci_chk_rx_seq_num(md, &ccci_h, queue->index);
  407. #if TRAFFIC_MONITOR_INTERVAL
  408. md_ctrl->rx_traffic_monitor[queue->index]++;
  409. #endif
  410. *rxbytes += skb_bytes;
  411. ccci_dump_log_add(md, IN, (int)queue->index, &ccci_h, (ret >= 0 ? 0 : 1));
  412. ccci_channel_update_packet_counter(md, &ccci_h);
  413. /*
  414. * here must queue work for each packet, think this flow:
  415. collect work sets 1st req->skb to NULL; refill work runs;
  416. * refill work sees next req->skb is not null and quits!;
  417. collect works set 2nd seq->skb to NULL. if we don't queue
  418. * work for the 2nd req, it will not be refilled,
  419. and calls assert if md_cd_clear_all_queue runs after.
  420. */
  421. queue_work(queue->refill_worker, &queue->cldma_refill_work);
  422. } else {
  423. spin_unlock_irqrestore(&queue->ring_lock, flags);
  424. *result = PORT_REFUSE;
  425. #ifdef CLDMA_TRACE
  426. trace_cldma_error(queue->index, ccci_h.channel, PORT_REFUSE, __LINE__);
  427. #endif
  428. leave_skb_in_ring:
  429. /* undo skb, as it remains in buffer and will be handled later */
  430. skb_reset_tail_pointer(skb);
  431. skb->len = 0;
  432. if (new_req) {
  433. /* free the wrapper */
  434. list_del(&new_req->entry);
  435. new_req->policy = NOOP;
  436. ccci_free_req(new_req);
  437. }
  438. break;
  439. }
  440. #ifdef CLDMA_TRACE
  441. total_handle_time = (sched_clock() - total_handle_time);
  442. trace_cldma_rx(queue->index, ccci_h.channel, req_alloc_time, port_recv_time, count,
  443. total_handle_time, skb_bytes);
  444. #endif
  445. /* check budget */
  446. if (count++ >= budget)
  447. *result = REACH_BUDGET;
  448. }
  449. /*
  450. * do not use if(count == RING_BUFFER_SIZE) to resume Rx queue.
  451. * resume Rx queue every time. we may not handle all RX ring buffer at one time due to
  452. * user can refuse to receive patckets. so when a queue is stopped after it consumes all
  453. * GPD, there is a chance that "count" never reaches ring buffer size and the queue is stopped
  454. * permanentely.
  455. *
  456. * resume after all RGPD handled also makes budget useless when it is less than ring buffer length.
  457. */
  458. /* if result == 0, that means all skb have been handled */
  459. CCCI_DBG_MSG(md->index, TAG, "CLDMA Rxq%d collected, result=%d, count=%d\n", queue->index, *result, count);
  460. return count;
  461. }
  462. /*
  463. * a no lock version for net queue, as net queue does not support flow control,
  464. * may be called from workqueue or NAPI context
  465. */
  466. static int cldma_gpd_net_rx_collect(struct md_cd_queue *queue, int budget, int blocking, int *result,
  467. int *rxbytes)
  468. {
  469. struct ccci_modem *md = queue->modem;
  470. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  471. struct cldma_request *req;
  472. struct cldma_rgpd *rgpd;
  473. struct sk_buff *skb = NULL;
  474. struct sk_buff *new_skb = NULL;
  475. #ifdef CLDMA_TRACE
  476. unsigned long long port_recv_time = 0;
  477. unsigned long long skb_alloc_time = 0;
  478. unsigned long long total_handle_time = 0;
  479. unsigned long long temp_time = 0;
  480. #endif
  481. int count = 0;
  482. unsigned long long skb_bytes = 0;
  483. char using_napi = md->capability & MODEM_CAP_NAPI;
  484. unsigned long flags;
  485. *result = UNDER_BUDGET;
  486. *rxbytes = 0;
  487. while (1) {
  488. #ifdef CLDMA_TRACE
  489. total_handle_time = port_recv_time = sched_clock();
  490. #endif
  491. req = queue->tr_done;
  492. rgpd = (struct cldma_rgpd *)req->gpd;
  493. if (!((rgpd->gpd_flags & 0x1) == 0 && req->skb))
  494. break;
  495. skb = req->skb;
  496. /* mark cldma_request as available */
  497. req->skb = NULL;
  498. rgpd->data_buff_bd_ptr = 0;
  499. /* update skb */
  500. dma_unmap_single(&md->plat_dev->dev, req->data_buffer_ptr_saved, skb_data_size(skb), DMA_FROM_DEVICE);
  501. skb_put(skb, rgpd->data_buff_len);
  502. skb_bytes = skb->len;
  503. *rxbytes += skb_bytes;
  504. ccci_chk_rx_seq_num(md, (struct ccci_header *)skb->data, queue->index);
  505. /* upload skb */
  506. if (using_napi) {
  507. ccci_port_recv_request(md, NULL, skb);
  508. } else {
  509. ccci_skb_enqueue(&queue->skb_list, skb);
  510. wake_up_all(&queue->rx_wq);
  511. }
  512. /* step forward */
  513. queue->tr_done = cldma_ring_step_forward(queue->tr_ring, req);
  514. #ifdef CLDMA_TRACE
  515. port_recv_time = ((skb_alloc_time = sched_clock()) - port_recv_time);
  516. #endif
  517. /* refill */
  518. req = queue->rx_refill;
  519. if (!req->skb) {
  520. new_skb = ccci_alloc_skb(queue->tr_ring->pkt_size, 0, blocking);
  521. if (likely(new_skb)) {
  522. rgpd = (struct cldma_rgpd *)req->gpd;
  523. req->data_buffer_ptr_saved =
  524. dma_map_single(&md->plat_dev->dev, new_skb->data, skb_data_size(new_skb),
  525. DMA_FROM_DEVICE);
  526. rgpd->data_buff_bd_ptr = (u32) (req->data_buffer_ptr_saved);
  527. rgpd->data_buff_len = 0;
  528. /* checksum of GPD */
  529. caculate_checksum((char *)rgpd, 0x81);
  530. /* set HWO, no need to hold ring_lock as no racer */
  531. spin_lock_irqsave(&md_ctrl->cldma_timeout_lock, flags);
  532. cldma_write8(&rgpd->gpd_flags, 0, 0x81);
  533. spin_unlock_irqrestore(&md_ctrl->cldma_timeout_lock, flags);
  534. /* mark cldma_request as available */
  535. req->skb = new_skb;
  536. /* step forward */
  537. queue->rx_refill = cldma_ring_step_forward(queue->tr_ring, req);
  538. } else {
  539. *result = NO_SKB;
  540. CCCI_ERR_MSG(md->index, TAG, "alloc skb fail on q%d\n", queue->index);
  541. }
  542. }
  543. #ifdef CLDMA_TRACE
  544. temp_time = sched_clock();
  545. skb_alloc_time = temp_time - skb_alloc_time;
  546. total_handle_time = temp_time - total_handle_time;
  547. trace_cldma_rx(queue->index, 0, count, port_recv_time, skb_alloc_time, total_handle_time, skb_bytes);
  548. #endif
  549. /* check budget */
  550. if (count++ >= budget) {
  551. *result = REACH_BUDGET;
  552. break;
  553. }
  554. }
  555. md_cd_lock_cldma_clock_src(1);
  556. spin_lock_irqsave(&md_ctrl->cldma_timeout_lock, flags);
  557. if (md_ctrl->rxq_active & (1 << queue->index)) {
  558. /* resume Rx queue */
  559. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_SO_RESUME_CMD,
  560. CLDMA_BM_ALL_QUEUE & (1 << queue->index));
  561. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_SO_RESUME_CMD); /* dummy read */
  562. }
  563. spin_unlock_irqrestore(&md_ctrl->cldma_timeout_lock, flags);
  564. md_cd_lock_cldma_clock_src(0);
  565. return count;
  566. }
  567. static int cldma_net_rx_push_thread(void *arg)
  568. {
  569. struct sk_buff *skb = NULL;
  570. struct md_cd_queue *queue = (struct md_cd_queue *)arg;
  571. struct ccci_modem *md = queue->modem;
  572. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  573. struct ccci_header *ccci_h;
  574. int count = 0;
  575. int ret;
  576. while (1) {
  577. if (skb_queue_empty(&queue->skb_list.skb_list)) {
  578. count = 0;
  579. ret = wait_event_interruptible(queue->rx_wq, !skb_queue_empty(&queue->skb_list.skb_list));
  580. if (ret == -ERESTARTSYS)
  581. continue; /* FIXME */
  582. }
  583. if (kthread_should_stop())
  584. break;
  585. #ifdef CCCI_SKB_TRACE
  586. md->netif_rx_profile[4] = sched_clock();
  587. #endif
  588. skb = ccci_skb_dequeue(&queue->skb_list);
  589. if (!skb)
  590. continue;
  591. ccci_h = (struct ccci_header *)skb->data;
  592. /* check wakeup source */
  593. if (atomic_cmpxchg(&md->wakeup_src, 1, 0) == 1)
  594. CCCI_INF_MSG(md->index, TAG, "CLDMA_MD wakeup source:(%d/%d)\n", queue->index, ccci_h->channel);
  595. CCCI_DBG_MSG(md->index, TAG, "recv Rx msg (%x %x %x %x) rxq=%d len=%d\n",
  596. ccci_h->data[0], ccci_h->data[1], *(((u32 *)ccci_h) + 2), ccci_h->reserved, queue->index,
  597. skb->len);
  598. /* update log */
  599. #if TRAFFIC_MONITOR_INTERVAL
  600. md_ctrl->rx_traffic_monitor[queue->index]++;
  601. #endif
  602. ccci_dump_log_add(md, IN, (int)queue->index, ccci_h, 0);
  603. ccci_channel_update_packet_counter(md, ccci_h);
  604. ccci_port_recv_request(md, NULL, skb);
  605. count++;
  606. #ifdef CCCI_SKB_TRACE
  607. md->netif_rx_profile[4] = sched_clock() - md->netif_rx_profile[4];
  608. md->netif_rx_profile[5] = count;
  609. trace_ccci_skb_rx(md->netif_rx_profile);
  610. #endif
  611. }
  612. return 0;
  613. }
  614. static void cldma_rx_refill(struct work_struct *work)
  615. {
  616. struct md_cd_queue *queue = container_of(work, struct md_cd_queue, cldma_refill_work);
  617. struct ccci_modem *md = queue->modem;
  618. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  619. unsigned long flags;
  620. int count;
  621. #ifdef CLDMA_TRACE
  622. unsigned long long total_time = sched_clock();
  623. #endif
  624. count = queue->tr_ring->handle_rx_refill(queue);
  625. CCCI_DBG_MSG(md->index, TAG, "CLDMA Rxq%d refilled, count=%d\n", queue->index, count);
  626. md_cd_lock_cldma_clock_src(1);
  627. spin_lock_irqsave(&md_ctrl->cldma_timeout_lock, flags);
  628. if (md_ctrl->rxq_active & (1 << queue->index)) {
  629. /* resume Rx queue */
  630. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_SO_RESUME_CMD,
  631. CLDMA_BM_ALL_QUEUE & (1 << queue->index));
  632. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_SO_RESUME_CMD); /* dummy read */
  633. }
  634. spin_unlock_irqrestore(&md_ctrl->cldma_timeout_lock, flags);
  635. md_cd_lock_cldma_clock_src(0);
  636. #ifdef CLDMA_TRACE
  637. total_time = sched_clock() - total_time;
  638. trace_cldma_rx_done(queue->index, 30, total_time, count, 0, 0, 0);
  639. #endif
  640. }
  641. static void cldma_rx_done(struct work_struct *work)
  642. {
  643. struct md_cd_queue *queue = container_of(work, struct md_cd_queue, cldma_rx_work);
  644. struct ccci_modem *md = queue->modem;
  645. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  646. int result, rx_bytes;
  647. int rx_total = 0;
  648. int count = 0;
  649. int retry = 0;
  650. unsigned long flags;
  651. unsigned int L2RISAR0 = 0;
  652. unsigned int cldma_rx_active = 0;
  653. #ifdef CLDMA_TRACE
  654. unsigned long long total_time = 0;
  655. unsigned int rx_interal;
  656. static unsigned long long last_leave_time[CLDMA_RXQ_NUM] = { 0 };
  657. static unsigned int sample_time[CLDMA_RXQ_NUM] = { 0 };
  658. static unsigned int sample_bytes[CLDMA_RXQ_NUM] = { 0 };
  659. total_time = sched_clock();
  660. if (last_leave_time[queue->index] == 0)
  661. rx_interal = 0;
  662. else
  663. rx_interal = total_time - last_leave_time[queue->index];
  664. #endif
  665. again:
  666. result = rx_bytes = 0;
  667. count += queue->tr_ring->handle_rx_done(queue, queue->budget, 1, &result, &rx_bytes);
  668. rx_total += rx_bytes;
  669. md_cd_lock_cldma_clock_src(1);
  670. spin_lock_irqsave(&md_ctrl->cldma_timeout_lock, flags);
  671. if (md_ctrl->rxq_active & (1 << queue->index)) {
  672. L2RISAR0 = cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2RISAR0);
  673. cldma_rx_active = cldma_read32(md_ctrl->cldma_md_pdn_base, CLDMA_AP_UL_STATUS);
  674. if (retry < 10000 &&
  675. ((L2RISAR0 & CLDMA_BM_INT_DONE & (1 << queue->index)) ||
  676. (cldma_rx_active & CLDMA_BM_INT_DONE & (1 << queue->index)))) {
  677. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2RISAR0, (1 << queue->index));
  678. #ifdef ENABLE_CLDMA_AP_SIDE
  679. /* clear IP busy register wake up cpu case */
  680. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_CLDMA_IP_BUSY,
  681. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_CLDMA_IP_BUSY));
  682. #endif
  683. spin_unlock_irqrestore(&md_ctrl->cldma_timeout_lock, flags);
  684. md_cd_lock_cldma_clock_src(0);
  685. retry++;
  686. goto again;
  687. }
  688. /* enable RX_DONE interrupt */
  689. cldma_write32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_L2RIMCR0, CLDMA_BM_ALL_QUEUE & (1 << queue->index));
  690. }
  691. spin_unlock_irqrestore(&md_ctrl->cldma_timeout_lock, flags);
  692. md_cd_lock_cldma_clock_src(0);
  693. #ifdef CLDMA_TRACE
  694. if (count) {
  695. last_leave_time[queue->index] = sched_clock();
  696. total_time = last_leave_time[queue->index] - total_time;
  697. sample_time[queue->index] += (total_time + rx_interal);
  698. sample_bytes[queue->index] += rx_total;
  699. trace_cldma_rx_done(queue->index, rx_interal, total_time, count, rx_total, 0, 0);
  700. if (sample_time[queue->index] >= trace_sample_time) {
  701. trace_cldma_rx_done(queue->index, 0, 0, 0, 0,
  702. sample_time[queue->index], sample_bytes[queue->index]);
  703. sample_time[queue->index] = 0;
  704. sample_bytes[queue->index] = 0;
  705. }
  706. } else {
  707. trace_cldma_error(queue->index, -1, 0, __LINE__);
  708. }
  709. #endif
  710. }
  711. /* this function may be called from both workqueue and ISR (timer) */
  712. static int cldma_gpd_bd_tx_collect(struct md_cd_queue *queue, int budget, int blocking, int *result)
  713. {
  714. struct ccci_modem *md = queue->modem;
  715. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  716. unsigned long flags;
  717. struct cldma_request *req;
  718. struct cldma_request *req_bd;
  719. struct cldma_tgpd *tgpd;
  720. struct cldma_tbd *tbd;
  721. struct ccci_header *ccci_h;
  722. int count = 0;
  723. struct sk_buff *skb_free;
  724. DATA_POLICY skb_free_p;
  725. while (1) {
  726. spin_lock_irqsave(&queue->ring_lock, flags);
  727. req = queue->tr_done;
  728. tgpd = (struct cldma_tgpd *)req->gpd;
  729. if (!((tgpd->gpd_flags & 0x1) == 0 && req->skb)) {
  730. spin_unlock_irqrestore(&queue->ring_lock, flags);
  731. break;
  732. }
  733. /* network does not has IOC override needs */
  734. tgpd->non_used = 2;
  735. /* update counter */
  736. queue->budget++;
  737. dma_unmap_single(&md->plat_dev->dev, req->data_buffer_ptr_saved, tgpd->data_buff_len, DMA_TO_DEVICE);
  738. /* update BD */
  739. list_for_each_entry(req_bd, &req->bd, entry) {
  740. tbd = req_bd->gpd;
  741. if (tbd->non_used == 1) {
  742. tbd->non_used = 2;
  743. dma_unmap_single(&md->plat_dev->dev, req_bd->data_buffer_ptr_saved, tbd->data_buff_len,
  744. DMA_TO_DEVICE);
  745. }
  746. }
  747. /* save skb reference */
  748. skb_free = req->skb;
  749. skb_free_p = req->policy;
  750. /* mark cldma_request as available */
  751. req->skb = NULL;
  752. /* step forward */
  753. queue->tr_done = cldma_ring_step_forward(queue->tr_ring, req);
  754. if (likely(md->capability & MODEM_CAP_TXBUSY_STOP))
  755. cldma_queue_broadcast_state(md, TX_IRQ, OUT, queue->index);
  756. spin_unlock_irqrestore(&queue->ring_lock, flags);
  757. count++;
  758. ccci_h = (struct ccci_header *)skb_free->data;
  759. CCCI_DBG_MSG(md->index, TAG, "harvest Tx msg (%x %x %x %x) txq=%d len=%d\n",
  760. ccci_h->data[0], ccci_h->data[1], *(((u32 *) ccci_h) + 2), ccci_h->reserved, queue->index,
  761. tgpd->data_buff_len);
  762. ccci_channel_update_packet_counter(md, ccci_h);
  763. ccci_free_skb(skb_free, skb_free_p);
  764. #if TRAFFIC_MONITOR_INTERVAL
  765. md_ctrl->tx_traffic_monitor[queue->index]++;
  766. #endif
  767. }
  768. if (count)
  769. wake_up_nr(&queue->req_wq, count);
  770. return count;
  771. }
  772. /* this function may be called from both workqueue and ISR (timer) */
  773. static int cldma_gpd_tx_collect(struct md_cd_queue *queue, int budget, int blocking, int *result)
  774. {
  775. struct ccci_modem *md = queue->modem;
  776. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  777. unsigned long flags;
  778. struct cldma_request *req;
  779. struct cldma_tgpd *tgpd;
  780. struct ccci_header *ccci_h;
  781. int count = 0;
  782. struct sk_buff *skb_free;
  783. DATA_POLICY skb_free_p;
  784. dma_addr_t dma_free;
  785. unsigned int dma_len;
  786. while (1) {
  787. spin_lock_irqsave(&queue->ring_lock, flags);
  788. req = queue->tr_done;
  789. tgpd = (struct cldma_tgpd *)req->gpd;
  790. if (!((tgpd->gpd_flags & 0x1) == 0 && req->skb)) {
  791. spin_unlock_irqrestore(&queue->ring_lock, flags);
  792. break;
  793. }
  794. /* restore IOC setting */
  795. if (req->ioc_override & 0x80) {
  796. if (req->ioc_override & 0x1)
  797. tgpd->gpd_flags |= 0x80;
  798. else
  799. tgpd->gpd_flags &= 0x7F;
  800. CCCI_INF_MSG(md->index, TAG, "TX_collect: qno%d, req->ioc_override=0x%x,tgpd->gpd_flags=0x%x\n",
  801. queue->index, req->ioc_override, tgpd->gpd_flags);
  802. }
  803. tgpd->non_used = 2;
  804. /* update counter */
  805. queue->budget++;
  806. /* save skb reference */
  807. dma_free = req->data_buffer_ptr_saved;
  808. dma_len = tgpd->data_buff_len;
  809. skb_free = req->skb;
  810. skb_free_p = req->policy;
  811. /* mark cldma_request as available */
  812. req->skb = NULL;
  813. /* step forward */
  814. queue->tr_done = cldma_ring_step_forward(queue->tr_ring, req);
  815. if (likely(md->capability & MODEM_CAP_TXBUSY_STOP))
  816. cldma_queue_broadcast_state(md, TX_IRQ, OUT, queue->index);
  817. spin_unlock_irqrestore(&queue->ring_lock, flags);
  818. count++;
  819. /*
  820. * After enabled NAPI, when free skb, cosume_skb() will eventually called nf_nat_cleanup_conntrack(),
  821. * which will call spin_unlock_bh() to let softirq to run.
  822. so there is a chance a Rx softirq is triggered (cldma_rx_collect)
  823. * and if it's a TCP packet, it will send ACK
  824. -- another Tx is scheduled which will require queue->ring_lock,
  825. * cause a deadlock!
  826. *
  827. * This should not be an issue any more,
  828. after we start using dev_kfree_skb_any() instead of dev_kfree_skb().
  829. */
  830. dma_unmap_single(&md->plat_dev->dev, dma_free, dma_len, DMA_TO_DEVICE);
  831. ccci_h = (struct ccci_header *)skb_free->data;
  832. CCCI_DBG_MSG(md->index, TAG, "harvest Tx msg (%x %x %x %x) txq=%d len=%d\n",
  833. ccci_h->data[0], ccci_h->data[1], *(((u32 *) ccci_h) + 2), ccci_h->reserved, queue->index,
  834. skb_free->len);
  835. ccci_channel_update_packet_counter(md, ccci_h);
  836. ccci_free_skb(skb_free, skb_free_p);
  837. #if TRAFFIC_MONITOR_INTERVAL
  838. md_ctrl->tx_traffic_monitor[queue->index]++;
  839. #endif
  840. }
  841. if (count)
  842. wake_up_nr(&queue->req_wq, count);
  843. return count;
  844. }
  845. static void cldma_tx_done(struct work_struct *work)
  846. {
  847. struct delayed_work *dwork = to_delayed_work(work);
  848. struct md_cd_queue *queue = container_of(dwork, struct md_cd_queue, cldma_tx_work);
  849. struct ccci_modem *md = queue->modem;
  850. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  851. int result, count;
  852. #ifdef CLDMA_TRACE
  853. unsigned long long total_time = 0;
  854. unsigned int tx_interal;
  855. static unsigned long long leave_time[CLDMA_TXQ_NUM] = { 0 };
  856. total_time = sched_clock();
  857. leave_time[queue->index] = total_time;
  858. if (leave_time[queue->index] == 0)
  859. tx_interal = 0;
  860. else
  861. tx_interal = total_time - leave_time[queue->index];
  862. #endif
  863. #if TRAFFIC_MONITOR_INTERVAL
  864. md_ctrl->tx_done_last_start_time[queue->index] = local_clock();
  865. #endif
  866. count = queue->tr_ring->handle_tx_done(queue, 0, 0, &result);
  867. #if TRAFFIC_MONITOR_INTERVAL
  868. md_ctrl->tx_done_last_count[queue->index] = count;
  869. #endif
  870. if (count) {
  871. queue_delayed_work(queue->worker, &queue->cldma_tx_work, msecs_to_jiffies(10));
  872. } else {
  873. #ifndef CLDMA_NO_TX_IRQ
  874. unsigned long flags;
  875. /* enable TX_DONE interrupt */
  876. md_cd_lock_cldma_clock_src(1);
  877. spin_lock_irqsave(&md_ctrl->cldma_timeout_lock, flags);
  878. if (md_ctrl->txq_active & (1 << queue->index))
  879. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2TIMCR0,
  880. CLDMA_BM_ALL_QUEUE & (1 << queue->index));
  881. spin_unlock_irqrestore(&md_ctrl->cldma_timeout_lock, flags);
  882. md_cd_lock_cldma_clock_src(0);
  883. #endif
  884. }
  885. #ifdef CLDMA_TRACE
  886. if (count) {
  887. leave_time[queue->index] = sched_clock();
  888. total_time = leave_time[queue->index] - total_time;
  889. trace_cldma_tx_done(queue->index, tx_interal, total_time, count);
  890. } else {
  891. trace_cldma_error(queue->index, -1, 0, __LINE__);
  892. }
  893. #endif
  894. }
  895. static void cldma_rx_ring_init(struct ccci_modem *md, struct cldma_ring *ring)
  896. {
  897. int i;
  898. struct cldma_request *item, *first_item = NULL;
  899. struct cldma_rgpd *gpd = NULL, *prev_gpd = NULL;
  900. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  901. if (ring->type == RING_GPD) {
  902. for (i = 0; i < ring->length; i++) {
  903. item = kzalloc(sizeof(struct cldma_request), GFP_KERNEL);
  904. item->gpd = dma_pool_alloc(md_ctrl->gpd_dmapool, GFP_KERNEL, &item->gpd_addr);
  905. item->skb = ccci_alloc_skb(ring->pkt_size, 1, 1);
  906. gpd = (struct cldma_rgpd *)item->gpd;
  907. memset(gpd, 0, sizeof(struct cldma_rgpd));
  908. item->data_buffer_ptr_saved = dma_map_single(&md->plat_dev->dev, item->skb->data,
  909. skb_data_size(item->skb), DMA_FROM_DEVICE);
  910. gpd->data_buff_bd_ptr = (u32) (item->data_buffer_ptr_saved);
  911. gpd->data_allow_len = ring->pkt_size;
  912. gpd->gpd_flags = 0x81; /* IOC|HWO */
  913. if (i == 0) {
  914. first_item = item;
  915. } else {
  916. prev_gpd->next_gpd_ptr = item->gpd_addr;
  917. caculate_checksum((char *)prev_gpd, 0x81);
  918. }
  919. INIT_LIST_HEAD(&item->entry);
  920. list_add_tail(&item->entry, &ring->gpd_ring);
  921. prev_gpd = gpd;
  922. }
  923. gpd->next_gpd_ptr = first_item->gpd_addr;
  924. caculate_checksum((char *)gpd, 0x81);
  925. }
  926. if (ring->type == RING_SPD)
  927. /* TODO: */;
  928. }
  929. static void cldma_tx_ring_init(struct ccci_modem *md, struct cldma_ring *ring)
  930. {
  931. int i, j;
  932. struct cldma_request *item = NULL, *bd_item = NULL, *first_item = NULL;
  933. struct cldma_tgpd *gpd = NULL, *prev_gpd = NULL;
  934. struct cldma_tbd *bd = NULL, *prev_bd = NULL;
  935. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  936. if (ring->type == RING_GPD) {
  937. for (i = 0; i < ring->length; i++) {
  938. item = kzalloc(sizeof(struct cldma_request), GFP_KERNEL);
  939. item->gpd = dma_pool_alloc(md_ctrl->gpd_dmapool, GFP_KERNEL, &item->gpd_addr);
  940. gpd = (struct cldma_tgpd *)item->gpd;
  941. memset(gpd, 0, sizeof(struct cldma_tgpd));
  942. gpd->gpd_flags = 0x80; /* IOC */
  943. if (i == 0)
  944. first_item = item;
  945. else
  946. prev_gpd->next_gpd_ptr = item->gpd_addr;
  947. INIT_LIST_HEAD(&item->bd);
  948. INIT_LIST_HEAD(&item->entry);
  949. list_add_tail(&item->entry, &ring->gpd_ring);
  950. prev_gpd = gpd;
  951. }
  952. gpd->next_gpd_ptr = first_item->gpd_addr;
  953. }
  954. if (ring->type == RING_GPD_BD) {
  955. for (i = 0; i < ring->length; i++) {
  956. item = kzalloc(sizeof(struct cldma_request), GFP_KERNEL);
  957. item->gpd = dma_pool_alloc(md_ctrl->gpd_dmapool, GFP_KERNEL, &item->gpd_addr);
  958. gpd = (struct cldma_tgpd *)item->gpd;
  959. memset(gpd, 0, sizeof(struct cldma_tgpd));
  960. gpd->gpd_flags = 0x82; /* IOC|BDP */
  961. if (i == 0)
  962. first_item = item;
  963. else
  964. prev_gpd->next_gpd_ptr = item->gpd_addr;
  965. INIT_LIST_HEAD(&item->bd);
  966. INIT_LIST_HEAD(&item->entry);
  967. list_add_tail(&item->entry, &ring->gpd_ring);
  968. prev_gpd = gpd;
  969. /* add BD */
  970. for (j = 0; j < MAX_BD_NUM + 1; j++) { /* extra 1 BD for skb head */
  971. bd_item = kzalloc(sizeof(struct cldma_request), GFP_KERNEL);
  972. bd_item->gpd = dma_pool_alloc(md_ctrl->gpd_dmapool, GFP_KERNEL, &bd_item->gpd_addr);
  973. bd = (struct cldma_tbd *)bd_item->gpd;
  974. memset(bd, 0, sizeof(struct cldma_tbd));
  975. if (j == 0)
  976. gpd->data_buff_bd_ptr = bd_item->gpd_addr;
  977. else
  978. prev_bd->next_bd_ptr = bd_item->gpd_addr;
  979. INIT_LIST_HEAD(&bd_item->entry);
  980. list_add_tail(&bd_item->entry, &item->bd);
  981. prev_bd = bd;
  982. }
  983. bd->bd_flags |= 0x1; /* EOL */
  984. }
  985. gpd->next_gpd_ptr = first_item->gpd_addr;
  986. }
  987. }
  988. static void cldma_queue_switch_ring(struct md_cd_queue *queue)
  989. {
  990. struct ccci_modem *md = queue->modem;
  991. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  992. struct cldma_request *req;
  993. if (queue->dir == OUT) {
  994. if ((1 << queue->index) & NET_TX_QUEUE_MASK) {
  995. if (md->ex_stage != EX_INIT_DONE) /* normal mode */
  996. queue->tr_ring = &md_ctrl->net_tx_ring[net_tx_queue2ring[queue->index]];
  997. else if ((1 << queue->index) & NORMAL_TX_QUEUE_MASK) /* if this queue has exception mode */
  998. queue->tr_ring = &md_ctrl->normal_tx_ring[normal_tx_queue2ring[queue->index]];
  999. } else {
  1000. queue->tr_ring = &md_ctrl->normal_tx_ring[normal_tx_queue2ring[queue->index]];
  1001. }
  1002. req = list_first_entry(&queue->tr_ring->gpd_ring, struct cldma_request, entry);
  1003. queue->tr_done = req;
  1004. queue->tx_xmit = req;
  1005. queue->budget = queue->tr_ring->length;
  1006. } else if (queue->dir == IN) {
  1007. if ((1 << queue->index) & NET_TX_QUEUE_MASK) {
  1008. if (md->ex_stage != EX_INIT_DONE) /* normal mode */
  1009. queue->tr_ring = &md_ctrl->net_rx_ring[net_rx_queue2ring[queue->index]];
  1010. else if ((1 << queue->index) & NORMAL_TX_QUEUE_MASK) /* if this queue has exception mode */
  1011. queue->tr_ring = &md_ctrl->normal_rx_ring[normal_rx_queue2ring[queue->index]];
  1012. } else {
  1013. queue->tr_ring = &md_ctrl->normal_rx_ring[normal_rx_queue2ring[queue->index]];
  1014. }
  1015. req = list_first_entry(&queue->tr_ring->gpd_ring, struct cldma_request, entry);
  1016. queue->tr_done = req;
  1017. queue->rx_refill = req;
  1018. queue->budget = queue->tr_ring->length;
  1019. }
  1020. /* work should be flushed by then */
  1021. INIT_WORK(&queue->cldma_rx_work, cldma_rx_done);
  1022. INIT_WORK(&queue->cldma_refill_work, cldma_rx_refill);
  1023. CCCI_DBG_MSG(md->index, TAG, "queue %d/%d switch ring to %p\n", queue->index, queue->dir, queue->tr_ring);
  1024. }
  1025. static void cldma_rx_queue_init(struct md_cd_queue *queue)
  1026. {
  1027. struct ccci_modem *md = queue->modem;
  1028. cldma_queue_switch_ring(queue);
  1029. /*
  1030. * we hope work item of different CLDMA queue can work concurrently, but work items of the same
  1031. * CLDMA queue must be work sequentially as wo didn't implement any lock in rx_done or tx_done.
  1032. */
  1033. if ((1 << queue->index) & LOW_PRIORITY_QUEUE) {
  1034. /* modem logger queue: priority normal */
  1035. queue->worker = alloc_workqueue("md%d_rx%d_worker", WQ_UNBOUND | WQ_MEM_RECLAIM, 1,
  1036. md->index + 1, queue->index);
  1037. queue->refill_worker = alloc_workqueue("md%d_rx%d_refill_worker", WQ_UNBOUND | WQ_MEM_RECLAIM, 1,
  1038. md->index + 1, queue->index);
  1039. } else {
  1040. queue->worker = alloc_workqueue("md%d_rx%d_worker", WQ_UNBOUND | WQ_MEM_RECLAIM | WQ_HIGHPRI, 1,
  1041. md->index + 1, queue->index);
  1042. queue->refill_worker = alloc_workqueue("md%d_rx%d_refill_worker",
  1043. WQ_UNBOUND | WQ_MEM_RECLAIM | WQ_HIGHPRI, 1, md->index + 1, queue->index);
  1044. }
  1045. ccci_skb_queue_init(&queue->skb_list, queue->tr_ring->pkt_size, SKB_RX_QUEUE_MAX_LEN, 0);
  1046. init_waitqueue_head(&queue->rx_wq);
  1047. if (IS_NET_QUE(md, queue->index))
  1048. queue->rx_thread = kthread_run(cldma_net_rx_push_thread, queue, "cldma_rxq%d", queue->index);
  1049. CCCI_DBG_MSG(md->index, TAG, "rxq%d work=%p\n", queue->index, &queue->cldma_rx_work);
  1050. }
  1051. static void cldma_tx_queue_init(struct md_cd_queue *queue)
  1052. {
  1053. struct ccci_modem *md = queue->modem;
  1054. cldma_queue_switch_ring(queue);
  1055. queue->worker =
  1056. alloc_workqueue("md%d_tx%d_worker", WQ_UNBOUND | WQ_MEM_RECLAIM | WQ_HIGHPRI, 1, md->index + 1,
  1057. queue->index);
  1058. INIT_DELAYED_WORK(&queue->cldma_tx_work, cldma_tx_done);
  1059. CCCI_DBG_MSG(md->index, TAG, "txq%d work=%p\n", queue->index, &queue->cldma_tx_work);
  1060. #ifdef ENABLE_CLDMA_TIMER
  1061. init_timer(&queue->timeout_timer);
  1062. queue->timeout_timer.function = cldma_timeout_timer_func;
  1063. queue->timeout_timer.data = (unsigned long)queue;
  1064. queue->timeout_start = 0;
  1065. queue->timeout_end = 0;
  1066. #endif
  1067. }
  1068. void cldma_enable_irq(struct md_cd_ctrl *md_ctrl)
  1069. {
  1070. if (atomic_read(&md_ctrl->cldma_irq_enabled) == 0) {
  1071. enable_irq(md_ctrl->cldma_irq_id);
  1072. atomic_inc(&md_ctrl->cldma_irq_enabled);
  1073. }
  1074. }
  1075. void cldma_disable_irq(struct md_cd_ctrl *md_ctrl)
  1076. {
  1077. if (atomic_read(&md_ctrl->cldma_irq_enabled) == 1) {
  1078. disable_irq(md_ctrl->cldma_irq_id);
  1079. atomic_dec(&md_ctrl->cldma_irq_enabled);
  1080. }
  1081. }
  1082. void cldma_disable_irq_nosync(struct md_cd_ctrl *md_ctrl)
  1083. {
  1084. if (atomic_read(&md_ctrl->cldma_irq_enabled) == 1) {
  1085. /*may be called in isr, so use disable_irq_nosync.
  1086. if use disable_irq in isr, system will hang */
  1087. disable_irq_nosync(md_ctrl->cldma_irq_id);
  1088. atomic_dec(&md_ctrl->cldma_irq_enabled);
  1089. }
  1090. }
  1091. static void cldma_irq_work_cb(struct ccci_modem *md)
  1092. {
  1093. int i, ret;
  1094. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  1095. unsigned int L2TIMR0, L2RIMR0, L2TISAR0, L2RISAR0;
  1096. unsigned int L3TIMR0, L3RIMR0, L3TISAR0, L3RISAR0;
  1097. unsigned int coda_version;
  1098. md_cd_lock_cldma_clock_src(1);
  1099. /* get L2 interrupt status */
  1100. L2TISAR0 = cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2TISAR0);
  1101. L2RISAR0 = cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2RISAR0);
  1102. L2TIMR0 = cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2TIMR0);
  1103. L2RIMR0 = cldma_read32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_L2RIMR0);
  1104. /* get L3 interrupt status */
  1105. L3TISAR0 = cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3TISAR0);
  1106. L3RISAR0 = cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3RISAR0);
  1107. L3TIMR0 = cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3TIMR0);
  1108. L3RIMR0 = cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3RIMR0);
  1109. if (atomic_read(&md->wakeup_src) == 1)
  1110. CCCI_INF_MSG(md->index, TAG, "wake up by CLDMA_MD L2(%x/%x) L3(%x/%x)!\n", L2TISAR0, L2RISAR0, L3TISAR0,
  1111. L3RISAR0);
  1112. else
  1113. CCCI_DBG_MSG(md->index, TAG, "CLDMA IRQ L2(%x/%x) L3(%x/%x)!\n", L2TISAR0, L2RISAR0, L3TISAR0,
  1114. L3RISAR0);
  1115. #ifndef CLDMA_NO_TX_IRQ
  1116. L2TISAR0 &= (~L2TIMR0);
  1117. L3TISAR0 &= (~L3TIMR0);
  1118. #endif
  1119. L2RISAR0 &= (~L2RIMR0);
  1120. L3RISAR0 &= (~L3RIMR0);
  1121. if (L2TISAR0 & CLDMA_BM_INT_ERROR)
  1122. /* TODO: */;
  1123. if (L2RISAR0 & CLDMA_BM_INT_ERROR)
  1124. /* TODO: */;
  1125. if (unlikely(!(L2RISAR0 & CLDMA_BM_INT_DONE) && !(L2TISAR0 & CLDMA_BM_INT_DONE))) {
  1126. coda_version = cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_CLDMA_CODA_VERSION);
  1127. if (unlikely(coda_version == 0)) {
  1128. CCCI_ERR_MSG(md->index, TAG,
  1129. "no Tx or Rx, L2TISAR0=%X, L3TISAR0=%X, L2RISAR0=%X, L3RISAR0=%X, L2TIMR0=%X, L2RIMR0=%X, CODA_VERSION=%X\n",
  1130. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2TISAR0),
  1131. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3TISAR0),
  1132. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2RISAR0),
  1133. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3RISAR0),
  1134. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2TIMR0),
  1135. cldma_read32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_L2RIMR0),
  1136. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_CLDMA_CODA_VERSION));
  1137. md_cd_check_md_DCM(md);
  1138. }
  1139. }
  1140. /* ack Tx interrupt */
  1141. if (L2TISAR0) {
  1142. #ifdef CLDMA_TRACE
  1143. trace_cldma_irq(CCCI_TRACE_TX_IRQ, (L2TISAR0 & CLDMA_BM_INT_DONE));
  1144. #endif
  1145. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2TISAR0, L2TISAR0);
  1146. for (i = 0; i < QUEUE_LEN(md_ctrl->txq); i++) {
  1147. if (L2TISAR0 & CLDMA_BM_INT_DONE & (1 << i)) {
  1148. #ifdef ENABLE_CLDMA_TIMER
  1149. if (IS_NET_QUE(md, i)) {
  1150. md_ctrl->txq[i].timeout_end = local_clock();
  1151. ret = del_timer(&md_ctrl->txq[i].timeout_timer);
  1152. CCCI_DBG_MSG(md->index, TAG, "qno%d del_timer %d ptr=0x%p\n", i, ret,
  1153. &md_ctrl->txq[i].timeout_timer);
  1154. }
  1155. #endif
  1156. /* disable TX_DONE interrupt */
  1157. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2TIMSR0,
  1158. CLDMA_BM_ALL_QUEUE & (1 << i));
  1159. if (IS_NET_QUE(md, i))
  1160. ret = queue_delayed_work(md_ctrl->txq[i].worker, &md_ctrl->txq[i].cldma_tx_work,
  1161. msecs_to_jiffies(10));
  1162. else
  1163. ret = queue_delayed_work(md_ctrl->txq[i].worker, &md_ctrl->txq[i].cldma_tx_work,
  1164. msecs_to_jiffies(0));
  1165. CCCI_DBG_MSG(md->index, TAG, "qno%d queue_delayed_work=%d\n", i, ret);
  1166. }
  1167. }
  1168. }
  1169. /* ack Rx interrupt */
  1170. if (L2RISAR0) {
  1171. #ifdef CLDMA_TRACE
  1172. trace_cldma_irq(CCCI_TRACE_RX_IRQ, (L2RISAR0 & CLDMA_BM_INT_DONE));
  1173. #endif
  1174. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2RISAR0, L2RISAR0);
  1175. /* clear MD2AP_PEER_WAKEUP when get RX_DONE */
  1176. #ifdef MD_PEER_WAKEUP
  1177. if (L2RISAR0 & CLDMA_BM_INT_DONE)
  1178. cldma_write32(md_ctrl->md_peer_wakeup, 0, cldma_read32(md_ctrl->md_peer_wakeup, 0) & ~0x01);
  1179. #endif
  1180. #ifdef ENABLE_CLDMA_AP_SIDE
  1181. /* clear IP busy register wake up cpu case */
  1182. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_CLDMA_IP_BUSY,
  1183. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_CLDMA_IP_BUSY));
  1184. #endif
  1185. for (i = 0; i < QUEUE_LEN(md_ctrl->rxq); i++) {
  1186. if (L2RISAR0 & CLDMA_BM_INT_DONE & (1 << i)) {
  1187. /* disable RX_DONE interrupt */
  1188. cldma_write32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_L2RIMSR0,
  1189. CLDMA_BM_ALL_QUEUE & (1 << i));
  1190. cldma_read32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_L2RIMSR0); /* dummy read */
  1191. if (md->md_state != EXCEPTION && md_ctrl->rxq[i].napi_port) {
  1192. md_ctrl->rxq[i].napi_port->ops->md_state_notice(md_ctrl->rxq[i].napi_port,
  1193. RX_IRQ);
  1194. } else {
  1195. ret = queue_work(md_ctrl->rxq[i].worker,
  1196. &md_ctrl->rxq[i].cldma_rx_work);
  1197. }
  1198. }
  1199. }
  1200. }
  1201. md_cd_lock_cldma_clock_src(0);
  1202. #ifndef ENABLE_CLDMA_AP_SIDE
  1203. cldma_enable_irq(md_ctrl);
  1204. #endif
  1205. }
  1206. static irqreturn_t cldma_isr(int irq, void *data)
  1207. {
  1208. struct ccci_modem *md = (struct ccci_modem *)data;
  1209. #ifndef ENABLE_CLDMA_AP_SIDE
  1210. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  1211. #endif
  1212. CCCI_DBG_MSG(md->index, TAG, "CLDMA IRQ!\n");
  1213. #ifdef ENABLE_CLDMA_AP_SIDE
  1214. cldma_irq_work_cb(md);
  1215. #else
  1216. cldma_disable_irq_nosync(md_ctrl)
  1217. queue_work(md_ctrl->cldma_irq_worker, &md_ctrl->cldma_irq_work);
  1218. #endif
  1219. return IRQ_HANDLED;
  1220. }
  1221. static void cldma_irq_work(struct work_struct *work)
  1222. {
  1223. struct md_cd_ctrl *md_ctrl = container_of(work, struct md_cd_ctrl, cldma_irq_work);
  1224. struct ccci_modem *md = md_ctrl->modem;
  1225. cldma_irq_work_cb(md);
  1226. }
  1227. static inline void cldma_stop(struct ccci_modem *md)
  1228. {
  1229. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  1230. int ret, count, i;
  1231. unsigned long flags;
  1232. #ifdef ENABLE_CLDMA_TIMER
  1233. int qno;
  1234. #endif
  1235. CCCI_INF_MSG(md->index, TAG, "%s from %ps\n", __func__, __builtin_return_address(0));
  1236. spin_lock_irqsave(&md_ctrl->cldma_timeout_lock, flags);
  1237. /* stop all Tx and Rx queues */
  1238. count = 0;
  1239. md_ctrl->txq_active &= (~CLDMA_BM_ALL_QUEUE);
  1240. do {
  1241. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_UL_STOP_CMD, CLDMA_BM_ALL_QUEUE);
  1242. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_UL_STOP_CMD); /* dummy read */
  1243. ret = cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_UL_STATUS);
  1244. if ((++count) % 100000 == 0) {
  1245. CCCI_INF_MSG(md->index, TAG, "stop Tx CLDMA, status=%x, count=%d\n", ret, count);
  1246. CCCI_INF_MSG(md->index, KERN, "Dump MD EX log\n");
  1247. ccci_mem_dump(md->index, md->smem_layout.ccci_exp_smem_base_vir,
  1248. md->smem_layout.ccci_exp_dump_size);
  1249. md_cd_dump_debug_register(md);
  1250. cldma_dump_register(md);
  1251. #if defined(CONFIG_MTK_AEE_FEATURE)
  1252. if (count >= 1600000) {
  1253. aed_md_exception_api(NULL, 0, NULL, 0,
  1254. "md1:\nUNKNOWN Exception\nstop Tx CLDMA failed.\n", DB_OPT_DEFAULT);
  1255. break;
  1256. }
  1257. #endif
  1258. }
  1259. } while (ret != 0);
  1260. count = 0;
  1261. md_ctrl->rxq_active &= (~CLDMA_BM_ALL_QUEUE);
  1262. do {
  1263. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_SO_STOP_CMD, CLDMA_BM_ALL_QUEUE);
  1264. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_SO_STOP_CMD); /* dummy read */
  1265. ret = cldma_read32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_SO_STATUS);
  1266. if ((++count) % 100000 == 0) {
  1267. CCCI_INF_MSG(md->index, TAG, "stop Rx CLDMA, status=%x, count=%d\n", ret, count);
  1268. #if defined(CONFIG_MTK_AEE_FEATURE)
  1269. aee_kernel_dal_show("stop Rx CLDMA failed.\n");
  1270. #endif
  1271. CCCI_INF_MSG(md->index, KERN, "Dump MD EX log\n");
  1272. if ((count < 500000) || (count > 1200000))
  1273. ccci_mem_dump(md->index, md->smem_layout.ccci_exp_smem_base_vir,
  1274. md->smem_layout.ccci_exp_dump_size);
  1275. md_cd_dump_debug_register(md);
  1276. cldma_dump_register(md);
  1277. #if defined(CONFIG_MTK_AEE_FEATURE)
  1278. if (count >= 1600000) {
  1279. aed_md_exception_api(NULL, 0, NULL, 0,
  1280. "md1:\nUNKNOWN Exception\nstop Rx CLDMA failed.\n", DB_OPT_DEFAULT);
  1281. break;
  1282. }
  1283. #endif
  1284. }
  1285. } while (ret != 0);
  1286. /* clear all L2 and L3 interrupts */
  1287. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2TISAR0, CLDMA_BM_INT_ALL);
  1288. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2TISAR1, CLDMA_BM_INT_ALL);
  1289. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2RISAR0, CLDMA_BM_INT_ALL);
  1290. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2RISAR1, CLDMA_BM_INT_ALL);
  1291. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3TISAR0, CLDMA_BM_INT_ALL);
  1292. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3TISAR1, CLDMA_BM_INT_ALL);
  1293. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3RISAR0, CLDMA_BM_INT_ALL);
  1294. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3RISAR1, CLDMA_BM_INT_ALL);
  1295. /* disable all L2 and L3 interrupts */
  1296. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2TIMSR0, CLDMA_BM_INT_ALL);
  1297. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2TIMSR1, CLDMA_BM_INT_ALL);
  1298. cldma_write32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_L2RIMSR0, CLDMA_BM_INT_ALL);
  1299. cldma_write32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_L2RIMSR1, CLDMA_BM_INT_ALL);
  1300. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3TIMSR0, CLDMA_BM_INT_ALL);
  1301. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3TIMSR1, CLDMA_BM_INT_ALL);
  1302. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3RIMSR0, CLDMA_BM_INT_ALL);
  1303. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3RIMSR1, CLDMA_BM_INT_ALL);
  1304. /* stop timer */
  1305. #ifdef ENABLE_CLDMA_TIMER
  1306. for (qno = 0; qno < CLDMA_TXQ_NUM; qno++)
  1307. del_timer(&md_ctrl->txq[qno].timeout_timer);
  1308. #endif
  1309. spin_unlock_irqrestore(&md_ctrl->cldma_timeout_lock, flags);
  1310. /* flush work */
  1311. cldma_disable_irq(md_ctrl);
  1312. flush_work(&md_ctrl->cldma_irq_work);
  1313. for (i = 0; i < QUEUE_LEN(md_ctrl->txq); i++)
  1314. flush_delayed_work(&md_ctrl->txq[i].cldma_tx_work);
  1315. for (i = 0; i < QUEUE_LEN(md_ctrl->rxq); i++) {
  1316. flush_work(&md_ctrl->rxq[i].cldma_rx_work);
  1317. flush_work(&md_ctrl->rxq[i].cldma_refill_work);
  1318. }
  1319. }
  1320. static inline void cldma_stop_for_ee(struct ccci_modem *md)
  1321. {
  1322. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  1323. int ret, count;
  1324. unsigned long flags;
  1325. CCCI_INF_MSG(md->index, TAG, "%s from %ps\n", __func__, __builtin_return_address(0));
  1326. spin_lock_irqsave(&md_ctrl->cldma_timeout_lock, flags);
  1327. /* stop all Tx and Rx queues, but non-stop Rx ones */
  1328. count = 0;
  1329. md_ctrl->txq_active &= (~CLDMA_BM_ALL_QUEUE);
  1330. do {
  1331. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_UL_STOP_CMD, CLDMA_BM_ALL_QUEUE);
  1332. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_UL_STOP_CMD); /* dummy read */
  1333. ret = cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_UL_STATUS);
  1334. if ((++count) % 100000 == 0) {
  1335. CCCI_INF_MSG(md->index, TAG, "stop Tx CLDMA E, status=%x, count=%d\n", ret, count);
  1336. CCCI_INF_MSG(md->index, TAG, "Dump MD EX log\n");
  1337. ccci_mem_dump(md->index, md->smem_layout.ccci_exp_smem_base_vir,
  1338. md->smem_layout.ccci_exp_dump_size);
  1339. md_cd_dump_debug_register(md);
  1340. cldma_dump_register(md);
  1341. #if defined(CONFIG_MTK_AEE_FEATURE)
  1342. if (count >= 1600000) {
  1343. aed_md_exception_api(NULL, 0, NULL, 0,
  1344. "md1:\nUNKNOWN Exception\nstop Tx CLDMA for EE failed.\n", DB_OPT_DEFAULT);
  1345. break;
  1346. }
  1347. #endif
  1348. }
  1349. } while (ret != 0);
  1350. count = 0;
  1351. md_ctrl->rxq_active &= (~(CLDMA_BM_ALL_QUEUE & NONSTOP_QUEUE_MASK));
  1352. do {
  1353. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_SO_STOP_CMD,
  1354. CLDMA_BM_ALL_QUEUE & NONSTOP_QUEUE_MASK);
  1355. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_SO_STOP_CMD); /* dummy read */
  1356. ret = cldma_read32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_SO_STATUS) & NONSTOP_QUEUE_MASK;
  1357. if ((++count) % 100000 == 0) {
  1358. CCCI_INF_MSG(md->index, TAG, "stop Rx CLDMA E, status=%x, count=%d\n", ret, count);
  1359. CCCI_INF_MSG(md->index, TAG, "Dump MD EX log\n");
  1360. ccci_mem_dump(md->index, md->smem_layout.ccci_exp_smem_base_vir,
  1361. md->smem_layout.ccci_exp_dump_size);
  1362. md_cd_dump_debug_register(md);
  1363. cldma_dump_register(md);
  1364. #if defined(CONFIG_MTK_AEE_FEATURE)
  1365. if (count >= 1600000) {
  1366. aed_md_exception_api(NULL, 0, NULL, 0,
  1367. "md1:\nUNKNOWN Exception\nstop Rx CLDMA for EE failed.\n", DB_OPT_DEFAULT);
  1368. break;
  1369. }
  1370. #endif
  1371. }
  1372. } while (ret != 0);
  1373. /* clear all L2 and L3 interrupts, but non-stop Rx ones */
  1374. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2TISAR0, CLDMA_BM_INT_ALL);
  1375. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2TISAR1, CLDMA_BM_INT_ALL);
  1376. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2RISAR0, CLDMA_BM_INT_ALL & NONSTOP_QUEUE_MASK_32);
  1377. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2RISAR1, CLDMA_BM_INT_ALL & NONSTOP_QUEUE_MASK_32);
  1378. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3TISAR0, CLDMA_BM_INT_ALL);
  1379. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3TISAR1, CLDMA_BM_INT_ALL);
  1380. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3RISAR0, CLDMA_BM_INT_ALL & NONSTOP_QUEUE_MASK_32);
  1381. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3RISAR1, CLDMA_BM_INT_ALL & NONSTOP_QUEUE_MASK_32);
  1382. /* disable all L2 and L3 interrupts, but non-stop Rx ones */
  1383. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2TIMSR0, CLDMA_BM_INT_ALL);
  1384. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2TIMSR1, CLDMA_BM_INT_ALL);
  1385. cldma_write32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_L2RIMSR0,
  1386. (CLDMA_BM_INT_DONE | CLDMA_BM_INT_ERROR) & NONSTOP_QUEUE_MASK_32);
  1387. cldma_write32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_L2RIMSR1, CLDMA_BM_INT_ALL);
  1388. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3TIMSR0, CLDMA_BM_INT_ALL);
  1389. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3TIMSR1, CLDMA_BM_INT_ALL);
  1390. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3RIMSR0, CLDMA_BM_INT_ALL & NONSTOP_QUEUE_MASK_32);
  1391. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3RIMSR1, CLDMA_BM_INT_ALL & NONSTOP_QUEUE_MASK_32);
  1392. spin_unlock_irqrestore(&md_ctrl->cldma_timeout_lock, flags);
  1393. }
  1394. static inline void cldma_reset(struct ccci_modem *md)
  1395. {
  1396. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  1397. CCCI_INF_MSG(md->index, TAG, "%s from %ps\n", __func__, __builtin_return_address(0));
  1398. /* enable OUT DMA & wait RGPD write transaction repsonse */
  1399. cldma_write32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_SO_CFG,
  1400. cldma_read32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_SO_CFG) | 0x5);
  1401. /* enable SPLIT_EN */
  1402. cldma_write32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_BUS_CFG,
  1403. cldma_read32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_BUS_CFG) | 0x02);
  1404. /* set high priority queue */
  1405. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_HPQR, high_priority_queue_mask);
  1406. /* TODO: traffic control value */
  1407. /* set checksum */
  1408. switch (CHECKSUM_SIZE) {
  1409. case 0:
  1410. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_UL_CHECKSUM_CHANNEL_ENABLE, 0);
  1411. cldma_write32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_SO_CHECKSUM_CHANNEL_ENABLE, 0);
  1412. break;
  1413. case 12:
  1414. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_UL_CHECKSUM_CHANNEL_ENABLE, CLDMA_BM_ALL_QUEUE);
  1415. cldma_write32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_SO_CHECKSUM_CHANNEL_ENABLE, CLDMA_BM_ALL_QUEUE);
  1416. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_UL_CFG,
  1417. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_UL_CFG) & ~0x10);
  1418. cldma_write32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_SO_CFG,
  1419. cldma_read32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_SO_CFG) & ~0x10);
  1420. break;
  1421. case 16:
  1422. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_UL_CHECKSUM_CHANNEL_ENABLE, CLDMA_BM_ALL_QUEUE);
  1423. cldma_write32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_SO_CHECKSUM_CHANNEL_ENABLE, CLDMA_BM_ALL_QUEUE);
  1424. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_UL_CFG,
  1425. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_UL_CFG) | 0x10);
  1426. cldma_write32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_SO_CFG,
  1427. cldma_read32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_SO_CFG) | 0x10);
  1428. break;
  1429. }
  1430. /* TODO: enable debug ID? */
  1431. #ifdef MD_CACHE_TO_NONECACHE
  1432. cldma_write32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_ADDR_REMAP_FROM, 0xA0000000);
  1433. #endif
  1434. }
  1435. static inline void cldma_start(struct ccci_modem *md)
  1436. {
  1437. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  1438. int i;
  1439. unsigned long flags;
  1440. CCCI_INF_MSG(md->index, TAG, "%s from %ps\n", __func__, __builtin_return_address(0));
  1441. cldma_enable_irq(md_ctrl);
  1442. spin_lock_irqsave(&md_ctrl->cldma_timeout_lock, flags);
  1443. /* set start address */
  1444. for (i = 0; i < QUEUE_LEN(md_ctrl->txq); i++) {
  1445. cldma_queue_switch_ring(&md_ctrl->txq[i]);
  1446. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_TQSAR(md_ctrl->txq[i].index),
  1447. md_ctrl->txq[i].tr_done->gpd_addr);
  1448. #ifdef ENABLE_CLDMA_AP_SIDE
  1449. cldma_write32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_TQSABAK(md_ctrl->txq[i].index),
  1450. md_ctrl->txq[i].tr_done->gpd_addr);
  1451. #endif
  1452. }
  1453. for (i = 0; i < QUEUE_LEN(md_ctrl->rxq); i++) {
  1454. cldma_queue_switch_ring(&md_ctrl->rxq[i]);
  1455. cldma_write32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_RQSAR(md_ctrl->rxq[i].index),
  1456. md_ctrl->rxq[i].tr_done->gpd_addr);
  1457. }
  1458. /* wait write done */
  1459. wmb();
  1460. /* start all Tx and Rx queues */
  1461. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_UL_START_CMD, CLDMA_BM_ALL_QUEUE);
  1462. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_UL_START_CMD); /* dummy read */
  1463. #ifdef NO_START_ON_SUSPEND_RESUME
  1464. md_ctrl->txq_started = 1;
  1465. #endif
  1466. md_ctrl->txq_active |= CLDMA_BM_ALL_QUEUE;
  1467. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_SO_START_CMD, CLDMA_BM_ALL_QUEUE);
  1468. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_SO_START_CMD); /* dummy read */
  1469. md_ctrl->rxq_active |= CLDMA_BM_ALL_QUEUE;
  1470. /* enable L2 DONE and ERROR interrupts */
  1471. #ifndef CLDMA_NO_TX_IRQ
  1472. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2TIMCR0, CLDMA_BM_INT_DONE | CLDMA_BM_INT_ERROR);
  1473. #endif
  1474. cldma_write32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_L2RIMCR0, CLDMA_BM_INT_DONE | CLDMA_BM_INT_ERROR);
  1475. /* enable all L3 interrupts */
  1476. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3TIMCR0, CLDMA_BM_INT_ALL);
  1477. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3TIMCR1, CLDMA_BM_INT_ALL);
  1478. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3RIMCR0, CLDMA_BM_INT_ALL);
  1479. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L3RIMCR1, CLDMA_BM_INT_ALL);
  1480. spin_unlock_irqrestore(&md_ctrl->cldma_timeout_lock, flags);
  1481. }
  1482. /* only allowed when cldma is stopped */
  1483. static void md_cd_clear_all_queue(struct ccci_modem *md, DIRECTION dir)
  1484. {
  1485. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  1486. int i;
  1487. struct cldma_request *req = NULL;
  1488. struct cldma_tgpd *tgpd;
  1489. unsigned long flags;
  1490. if (dir == OUT) {
  1491. for (i = 0; i < QUEUE_LEN(md_ctrl->txq); i++) {
  1492. spin_lock_irqsave(&md_ctrl->txq[i].ring_lock, flags);
  1493. req = list_first_entry(&md_ctrl->txq[i].tr_ring->gpd_ring, struct cldma_request, entry);
  1494. md_ctrl->txq[i].tr_done = req;
  1495. md_ctrl->txq[i].tx_xmit = req;
  1496. md_ctrl->txq[i].budget = md_ctrl->txq[i].tr_ring->length;
  1497. md_ctrl->txq[i].debug_id = 0;
  1498. #if PACKET_HISTORY_DEPTH
  1499. md->tx_history_ptr[i] = 0;
  1500. #endif
  1501. list_for_each_entry(req, &md_ctrl->txq[i].tr_ring->gpd_ring, entry) {
  1502. tgpd = (struct cldma_tgpd *)req->gpd;
  1503. cldma_write8(&tgpd->gpd_flags, 0, cldma_read8(&tgpd->gpd_flags, 0) & ~0x1);
  1504. if (md_ctrl->txq[i].tr_ring->type != RING_GPD_BD)
  1505. cldma_write32(&tgpd->data_buff_bd_ptr, 0, 0);
  1506. cldma_write16(&tgpd->data_buff_len, 0, 0);
  1507. if (req->skb) {
  1508. ccci_free_skb(req->skb, req->policy);
  1509. req->skb = NULL;
  1510. }
  1511. }
  1512. spin_unlock_irqrestore(&md_ctrl->txq[i].ring_lock, flags);
  1513. }
  1514. } else if (dir == IN) {
  1515. struct cldma_rgpd *rgpd;
  1516. for (i = 0; i < QUEUE_LEN(md_ctrl->rxq); i++) {
  1517. spin_lock_irqsave(&md_ctrl->rxq[i].ring_lock, flags);
  1518. req = list_first_entry(&md_ctrl->rxq[i].tr_ring->gpd_ring, struct cldma_request, entry);
  1519. md_ctrl->rxq[i].tr_done = req;
  1520. md_ctrl->rxq[i].rx_refill = req;
  1521. #if PACKET_HISTORY_DEPTH
  1522. md->rx_history_ptr[i] = 0;
  1523. #endif
  1524. list_for_each_entry(req, &md_ctrl->rxq[i].tr_ring->gpd_ring, entry) {
  1525. rgpd = (struct cldma_rgpd *)req->gpd;
  1526. cldma_write8(&rgpd->gpd_flags, 0, 0x81);
  1527. cldma_write16(&rgpd->data_buff_len, 0, 0);
  1528. caculate_checksum((char *)rgpd, 0x81);
  1529. if (req->skb != NULL) {
  1530. req->skb->len = 0;
  1531. skb_reset_tail_pointer(req->skb);
  1532. }
  1533. }
  1534. spin_unlock_irqrestore(&md_ctrl->rxq[i].ring_lock, flags);
  1535. list_for_each_entry(req, &md_ctrl->rxq[i].tr_ring->gpd_ring, entry) {
  1536. rgpd = (struct cldma_rgpd *)req->gpd;
  1537. if (req->skb == NULL) {
  1538. struct md_cd_queue *queue = &md_ctrl->rxq[i];
  1539. /*which queue*/
  1540. CCCI_INF_MSG(md->index, TAG, "skb NULL in Rx queue %d/%d\n",
  1541. i, queue->index);
  1542. /*if ((1 << queue->index) & NET_TX_QUEUE_MASK)
  1543. req->skb = ccci_alloc_skb(queue->tr_ring->pkt_size, 0, 1);
  1544. else */
  1545. req->skb = ccci_alloc_skb(queue->tr_ring->pkt_size, 1, 1);
  1546. req->data_buffer_ptr_saved =
  1547. dma_map_single(&md->plat_dev->dev, req->skb->data,
  1548. skb_data_size(req->skb), DMA_FROM_DEVICE);
  1549. rgpd->data_buff_bd_ptr = (u32) (req->data_buffer_ptr_saved);
  1550. caculate_checksum((char *)rgpd, 0x81);
  1551. }
  1552. }
  1553. }
  1554. }
  1555. }
  1556. static int md_cd_stop_queue(struct ccci_modem *md, unsigned char qno, DIRECTION dir)
  1557. {
  1558. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  1559. int count, ret;
  1560. unsigned long flags;
  1561. if (dir == OUT && qno >= QUEUE_LEN(md_ctrl->txq))
  1562. return -CCCI_ERR_INVALID_QUEUE_INDEX;
  1563. if (dir == IN && qno >= QUEUE_LEN(md_ctrl->rxq))
  1564. return -CCCI_ERR_INVALID_QUEUE_INDEX;
  1565. if (dir == IN) {
  1566. /* disable RX_DONE queue and interrupt */
  1567. md_cd_lock_cldma_clock_src(1);
  1568. spin_lock_irqsave(&md_ctrl->cldma_timeout_lock, flags);
  1569. cldma_write32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_L2RIMSR0, CLDMA_BM_ALL_QUEUE & (1 << qno));
  1570. count = 0;
  1571. md_ctrl->rxq_active &= (~(CLDMA_BM_ALL_QUEUE & (1 << qno)));
  1572. do {
  1573. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_SO_STOP_CMD,
  1574. CLDMA_BM_ALL_QUEUE & (1 << qno));
  1575. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_SO_STOP_CMD); /* dummy read */
  1576. ret = cldma_read32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_SO_STATUS) & (1 << qno);
  1577. CCCI_INF_MSG(md->index, TAG, "stop Rx CLDMA queue %d, status=%x, count=%d\n", qno, ret,
  1578. count++);
  1579. } while (ret != 0);
  1580. spin_unlock_irqrestore(&md_ctrl->cldma_timeout_lock, flags);
  1581. md_cd_lock_cldma_clock_src(0);
  1582. }
  1583. return 0;
  1584. }
  1585. static int md_cd_start_queue(struct ccci_modem *md, unsigned char qno, DIRECTION dir)
  1586. {
  1587. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  1588. struct cldma_request *req = NULL;
  1589. struct cldma_rgpd *rgpd;
  1590. unsigned long flags;
  1591. if (dir == OUT && qno >= QUEUE_LEN(md_ctrl->txq))
  1592. return -CCCI_ERR_INVALID_QUEUE_INDEX;
  1593. if (dir == IN && qno >= QUEUE_LEN(md_ctrl->rxq))
  1594. return -CCCI_ERR_INVALID_QUEUE_INDEX;
  1595. if (dir == IN) {
  1596. /* reset Rx ring buffer */
  1597. req = list_first_entry(&md_ctrl->rxq[qno].tr_ring->gpd_ring, struct cldma_request, entry);
  1598. md_ctrl->rxq[qno].tr_done = req;
  1599. md_ctrl->rxq[qno].rx_refill = req;
  1600. #if PACKET_HISTORY_DEPTH
  1601. md->rx_history_ptr[qno] = 0;
  1602. #endif
  1603. list_for_each_entry(req, &md_ctrl->txq[qno].tr_ring->gpd_ring, entry) {
  1604. rgpd = (struct cldma_rgpd *)req->gpd;
  1605. cldma_write8(&rgpd->gpd_flags, 0, 0x81);
  1606. cldma_write16(&rgpd->data_buff_len, 0, 0);
  1607. req->skb->len = 0;
  1608. skb_reset_tail_pointer(req->skb);
  1609. }
  1610. /* enable queue and RX_DONE interrupt */
  1611. md_cd_lock_cldma_clock_src(1);
  1612. spin_lock_irqsave(&md_ctrl->cldma_timeout_lock, flags);
  1613. if (md->md_state != RESET && md->md_state != GATED && md->md_state != INVALID) {
  1614. cldma_write32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_RQSAR(md_ctrl->rxq[qno].index),
  1615. md_ctrl->rxq[qno].tr_done->gpd_addr);
  1616. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_SO_START_CMD,
  1617. CLDMA_BM_ALL_QUEUE & (1 << qno));
  1618. cldma_write32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_L2RIMCR0, CLDMA_BM_ALL_QUEUE & (1 << qno));
  1619. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_SO_START_CMD); /* dummy read */
  1620. md_ctrl->rxq_active |= (CLDMA_BM_ALL_QUEUE & (1 << qno));
  1621. }
  1622. spin_unlock_irqrestore(&md_ctrl->cldma_timeout_lock, flags);
  1623. md_cd_lock_cldma_clock_src(0);
  1624. }
  1625. return 0;
  1626. }
  1627. void ccif_enable_irq(struct ccci_modem *md)
  1628. {
  1629. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  1630. if (atomic_read(&md_ctrl->ccif_irq_enabled) == 0) {
  1631. enable_irq(md_ctrl->ap_ccif_irq_id);
  1632. atomic_inc(&md_ctrl->ccif_irq_enabled);
  1633. CCCI_INF_MSG(md->index, TAG, "enable ccif irq\n");
  1634. }
  1635. }
  1636. void ccif_disable_irq(struct ccci_modem *md)
  1637. {
  1638. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  1639. if (atomic_read(&md_ctrl->ccif_irq_enabled) == 1) {
  1640. disable_irq_nosync(md_ctrl->ap_ccif_irq_id);
  1641. atomic_dec(&md_ctrl->ccif_irq_enabled);
  1642. CCCI_INF_MSG(md->index, TAG, "Disable ccif irq\n");
  1643. }
  1644. }
  1645. void wdt_enable_irq(struct ccci_modem *md)
  1646. {
  1647. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  1648. if (atomic_read(&md_ctrl->wdt_enabled) == 0) {
  1649. enable_irq(md_ctrl->md_wdt_irq_id);
  1650. atomic_inc(&md_ctrl->wdt_enabled);
  1651. CCCI_INF_MSG(md->index, TAG, "enable wdt irq\n");
  1652. }
  1653. }
  1654. void wdt_disable_irq(struct ccci_modem *md)
  1655. {
  1656. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  1657. if (atomic_read(&md_ctrl->wdt_enabled) == 1) {
  1658. /*may be called in isr, so use disable_irq_nosync.
  1659. if use disable_irq in isr, system will hang */
  1660. disable_irq_nosync(md_ctrl->md_wdt_irq_id);
  1661. atomic_dec(&md_ctrl->wdt_enabled);
  1662. CCCI_INF_MSG(md->index, TAG, "disable wdt irq\n");
  1663. }
  1664. }
  1665. static int wdt_executed = 0;
  1666. static void md_cd_wdt_work(struct work_struct *work)
  1667. {
  1668. struct md_cd_ctrl *md_ctrl = container_of(work, struct md_cd_ctrl, wdt_work);
  1669. struct ccci_modem *md = md_ctrl->modem;
  1670. int ret = 0;
  1671. mutex_lock(&md_ctrl->ccif_wdt_mutex);
  1672. wdt_executed = 1;
  1673. mutex_unlock(&md_ctrl->ccif_wdt_mutex);
  1674. /* 1. dump RGU reg */
  1675. CCCI_INF_MSG(md->index, TAG, "Dump MD RGU registers\n");
  1676. md_cd_lock_modem_clock_src(1);
  1677. #ifdef BASE_ADDR_MDRSTCTL
  1678. ccci_write32(md_ctrl->md_pll_base->md_busreg1, 0x94, 0xE7C5);/* pre-action */
  1679. ccci_mem_dump(md->index, md_ctrl->md_rgu_base, 0x8B);
  1680. ccci_mem_dump(md->index, (md_ctrl->md_rgu_base + 0x200), 0x60);
  1681. #else
  1682. ccci_mem_dump(md->index, md_ctrl->md_rgu_base, 0x30);
  1683. #endif
  1684. md_cd_lock_modem_clock_src(0);
  1685. if (md->md_state == INVALID) {
  1686. CCCI_ERR_MSG(md->index, TAG, "md_cd_wdt_work: md_state is INVALID\n");
  1687. return;
  1688. }
  1689. /* 2. wakelock */
  1690. wake_lock_timeout(&md_ctrl->trm_wake_lock, 10 * HZ);
  1691. #if 1
  1692. #ifdef MD_UMOLY_EE_SUPPORT
  1693. if (*((int *)(md->mem_layout.smem_region_vir +
  1694. CCCI_SMEM_OFFSET_MDSS_DEBUG + CCCI_SMEM_OFFSET_EPON_UMOLY)) == 0xBAEBAE10) { /* hardcode */
  1695. #else
  1696. if (*((int *)(md->mem_layout.smem_region_vir + CCCI_SMEM_OFFSET_EPON)) == 0xBAEBAE10) { /* hardcode */
  1697. #endif
  1698. /* 3. reset */
  1699. ret = md->ops->reset(md);
  1700. CCCI_INF_MSG(md->index, TAG, "reset MD after SW WDT %d\n", ret);
  1701. /* 4. send message, only reset MD on non-eng load */
  1702. ccci_send_virtual_md_msg(md, CCCI_MONITOR_CH, CCCI_MD_MSG_RESET, 0);
  1703. #ifdef CONFIG_MTK_ECCCI_C2K
  1704. exec_ccci_kern_func_by_md_id(MD_SYS3, ID_RESET_MD, NULL, 0);
  1705. #else
  1706. #ifdef CONFIG_MTK_SVLTE_SUPPORT
  1707. c2k_reset_modem();
  1708. #endif
  1709. #endif
  1710. } else {
  1711. if (md->critical_user_active[2] == 0) {
  1712. ret = md->ops->reset(md);
  1713. CCCI_INF_MSG(md->index, TAG, "mdlogger closed,reset MD after WDT %d\n", ret);
  1714. /* 4. send message, only reset MD on non-eng load */
  1715. ccci_send_virtual_md_msg(md, CCCI_MONITOR_CH, CCCI_MD_MSG_RESET, 0);
  1716. #ifdef CONFIG_MTK_ECCCI_C2K
  1717. exec_ccci_kern_func_by_md_id(MD_SYS3, ID_RESET_MD, NULL, 0);
  1718. #else
  1719. #ifdef CONFIG_MTK_SVLTE_SUPPORT
  1720. c2k_reset_modem();
  1721. #endif
  1722. #endif
  1723. } else {
  1724. md_cd_dump_debug_register(md);
  1725. ccci_md_exception_notify(md, MD_WDT);
  1726. }
  1727. }
  1728. #endif /* Mask by chao for build error */
  1729. }
  1730. static irqreturn_t md_cd_wdt_isr(int irq, void *data)
  1731. {
  1732. struct ccci_modem *md = (struct ccci_modem *)data;
  1733. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  1734. if (md->boot_stage == MD_BOOT_STAGE_0 && md->md_state != EXCEPTION && md->md_state != BOOT_FAIL) {
  1735. CCCI_ERR_MSG(md->index, TAG, "Ignore MD WDT IRQ which cann't be handled.\n");
  1736. return IRQ_HANDLED;
  1737. }
  1738. CCCI_ERR_MSG(md->index, TAG, "MD WDT IRQ\n");
  1739. ccif_disable_irq(md);
  1740. #ifndef DISABLE_MD_WDT_PROCESS
  1741. #ifdef ENABLE_DSP_SMEM_SHARE_MPU_REGION
  1742. ccci_set_exp_region_protection(md);
  1743. #endif
  1744. /* 1. disable MD WDT */
  1745. del_timer(&md_ctrl->bus_timeout_timer);
  1746. #ifdef ENABLE_MD_WDT_DBG
  1747. unsigned int state;
  1748. state = cldma_read32(md_ctrl->md_rgu_base, WDT_MD_STA);
  1749. cldma_write32(md_ctrl->md_rgu_base, WDT_MD_MODE, WDT_MD_MODE_KEY);
  1750. CCCI_INF_MSG(md->index, TAG, "WDT IRQ disabled for debug, state=%X\n", state);
  1751. #ifdef L1_BASE_ADDR_L1RGU
  1752. state = cldma_read32(md_ctrl->l1_rgu_base, REG_L1RSTCTL_WDT_STA);
  1753. cldma_write32(md_ctrl->l1_rgu_base, REG_L1RSTCTL_WDT_MODE, L1_WDT_MD_MODE_KEY);
  1754. CCCI_INF_MSG(md->index, TAG, "WDT IRQ disabled for debug, L1 state=%X\n", state);
  1755. #endif
  1756. #endif
  1757. /* 2. start a work queue to do the reset, because we used flush_work which is not designed for ISR */
  1758. schedule_work(&md_ctrl->wdt_work);
  1759. #endif
  1760. return IRQ_HANDLED;
  1761. }
  1762. void md_cd_ap2md_bus_timeout_timer_func(unsigned long data)
  1763. {
  1764. struct ccci_modem *md = (struct ccci_modem *)data;
  1765. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  1766. CCCI_INF_MSG(md->index, TAG, "MD bus timeout but no WDT IRQ\n");
  1767. /* same as WDT ISR */
  1768. schedule_work(&md_ctrl->wdt_work);
  1769. }
  1770. #if 0
  1771. static irqreturn_t md_cd_ap2md_bus_timeout_isr(int irq, void *data)
  1772. {
  1773. struct ccci_modem *md = (struct ccci_modem *)data;
  1774. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  1775. CCCI_INF_MSG(md->index, TAG, "MD bus timeout IRQ\n");
  1776. mod_timer(&md_ctrl->bus_timeout_timer, jiffies + 5 * HZ);
  1777. return IRQ_HANDLED;
  1778. }
  1779. #endif
  1780. static int md_cd_ccif_send(struct ccci_modem *md, int channel_id)
  1781. {
  1782. int busy = 0;
  1783. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  1784. busy = cldma_read32(md_ctrl->ap_ccif_base, APCCIF_BUSY);
  1785. if (busy & (1 << channel_id))
  1786. return -1;
  1787. cldma_write32(md_ctrl->ap_ccif_base, APCCIF_BUSY, 1 << channel_id);
  1788. cldma_write32(md_ctrl->ap_ccif_base, APCCIF_TCHNUM, channel_id);
  1789. return 0;
  1790. }
  1791. static void md_cd_ccif_delayed_work(struct ccci_modem *md)
  1792. {
  1793. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  1794. int i;
  1795. #if defined(CONFIG_MTK_AEE_FEATURE)
  1796. aee_kernel_dal_show("Modem exception dump start, please wait up to 5 minutes.\n");
  1797. #endif
  1798. /* stop CLDMA, we don't want to get CLDMA IRQ when MD is resetting CLDMA after it got cleaq_ack */
  1799. cldma_stop(md);
  1800. for (i = 0; i < QUEUE_LEN(md_ctrl->txq); i++)
  1801. flush_delayed_work(&md_ctrl->txq[i].cldma_tx_work);
  1802. for (i = 0; i < QUEUE_LEN(md_ctrl->rxq); i++) {
  1803. flush_work(&md_ctrl->rxq[i].cldma_rx_work);
  1804. flush_work(&md_ctrl->rxq[i].cldma_refill_work);
  1805. }
  1806. /* tell MD to reset CLDMA */
  1807. md_cd_ccif_send(md, H2D_EXCEPTION_CLEARQ_ACK);
  1808. CCCI_INF_MSG(md->index, TAG, "send clearq_ack to MD\n");
  1809. }
  1810. static void md_cd_exception(struct ccci_modem *md, HIF_EX_STAGE stage)
  1811. {
  1812. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  1813. volatile unsigned int SO_CFG;
  1814. CCCI_ERR_MSG(md->index, TAG, "MD exception HIF %d\n", stage);
  1815. wake_lock_timeout(&md_ctrl->trm_wake_lock, 50 * HZ);
  1816. /* in exception mode, MD won't sleep, so we do not need to request MD resource first */
  1817. switch (stage) {
  1818. case HIF_EX_INIT:
  1819. #ifdef ENABLE_DSP_SMEM_SHARE_MPU_REGION
  1820. ccci_set_exp_region_protection(md);
  1821. #endif
  1822. if (*((int *)(md->mem_layout.smem_region_vir + CCCI_SMEM_OFFSET_SEQERR)) != 0) {
  1823. CCCI_ERR_MSG(md->index, KERN, "MD found wrong sequence number\n");
  1824. md->ops->dump_info(md, DUMP_FLAG_CLDMA, NULL, -1);
  1825. }
  1826. ccci_md_exception_notify(md, EX_INIT);
  1827. /* disable CLDMA except un-stop queues */
  1828. cldma_stop_for_ee(md);
  1829. /* purge Tx queue */
  1830. md_cd_clear_all_queue(md, OUT);
  1831. /* Rx dispatch does NOT depend on queue index in port structure, so it still can find right port. */
  1832. md_cd_ccif_send(md, H2D_EXCEPTION_ACK);
  1833. break;
  1834. case HIF_EX_INIT_DONE:
  1835. ccci_md_exception_notify(md, EX_DHL_DL_RDY);
  1836. break;
  1837. case HIF_EX_CLEARQ_DONE:
  1838. /* give DHL some time to flush data */
  1839. msleep(2000);
  1840. md_cd_ccif_delayed_work(md);
  1841. break;
  1842. case HIF_EX_ALLQ_RESET:
  1843. /* re-start CLDMA */
  1844. cldma_reset(md);
  1845. /* md_cd_clear_all_queue(md, IN); move to delay work for request skb in it*/ /* purge Rx queue */
  1846. ccci_md_exception_notify(md, EX_INIT_DONE);
  1847. cldma_start(md);
  1848. SO_CFG = cldma_read32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_SO_CFG);
  1849. if ((SO_CFG & 0x1) == 0) { /* write function didn't work */
  1850. CCCI_ERR_MSG(md->index, TAG,
  1851. "Enable AP OUTCLDMA failed. Register can't be wrote. SO_CFG=0x%x\n", SO_CFG);
  1852. cldma_dump_register(md);
  1853. cldma_write32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_SO_CFG,
  1854. cldma_read32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_SO_CFG) | 0x05);
  1855. }
  1856. break;
  1857. default:
  1858. break;
  1859. };
  1860. }
  1861. static void polling_ready(struct ccci_modem *md, int step)
  1862. {
  1863. int cnt = 500; /*MD timeout is 10s*/
  1864. int time_once = 20;
  1865. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  1866. while (cnt > 0) {
  1867. md_ctrl->channel_id = cldma_read32(md_ctrl->ap_ccif_base, APCCIF_RCHNUM);
  1868. if (md_ctrl->channel_id & (1 << step)) {
  1869. cldma_write32(md_ctrl->ap_ccif_base, APCCIF_ACK, (1 << step));
  1870. return;
  1871. }
  1872. msleep(time_once);
  1873. cnt--;
  1874. }
  1875. CCCI_ERR_MSG(md->index, TAG, "poll EE HS timeout, RCHNUM %d\n", md_ctrl->channel_id);
  1876. }
  1877. static void md_cd_ccif_work(struct work_struct *work)
  1878. {
  1879. struct md_cd_ctrl *md_ctrl = container_of(work, struct md_cd_ctrl, ccif_work);
  1880. struct ccci_modem *md = md_ctrl->modem;
  1881. mutex_lock(&md_ctrl->ccif_wdt_mutex);
  1882. if (!wdt_executed) {
  1883. wake_lock_timeout(&md_ctrl->trm_wake_lock, 20 * HZ);/* Avoid sleep at polling */
  1884. /* polling_ready(md, D2H_EXCEPTION_INIT); */
  1885. md_cd_exception(md, HIF_EX_INIT);
  1886. wake_lock_timeout(&md_ctrl->trm_wake_lock, 20 * HZ);/* Avoid sleep at polling */
  1887. polling_ready(md, D2H_EXCEPTION_INIT_DONE);
  1888. md_cd_exception(md, HIF_EX_INIT_DONE);
  1889. wake_lock_timeout(&md_ctrl->trm_wake_lock, 20 * HZ);/* Avoid sleep at polling */
  1890. polling_ready(md, D2H_EXCEPTION_CLEARQ_DONE);
  1891. md_cd_exception(md, HIF_EX_CLEARQ_DONE);
  1892. wake_lock_timeout(&md_ctrl->trm_wake_lock, 20 * HZ);/* Avoid sleep at polling */
  1893. polling_ready(md, D2H_EXCEPTION_ALLQ_RESET);
  1894. md_cd_exception(md, HIF_EX_ALLQ_RESET);
  1895. if (md_ctrl->channel_id & (1<<AP_MD_PEER_WAKEUP))
  1896. wake_lock_timeout(&md_ctrl->peer_wake_lock, HZ);
  1897. if (md_ctrl->channel_id & (1<<AP_MD_SEQ_ERROR)) {
  1898. CCCI_ERR_MSG(md->index, TAG, "MD check seq fail\n");
  1899. md->ops->dump_info(md, DUMP_FLAG_CCIF, NULL, 0);
  1900. }
  1901. }
  1902. mutex_unlock(&md_ctrl->ccif_wdt_mutex);
  1903. }
  1904. static irqreturn_t md_cd_ccif_isr(int irq, void *data)
  1905. {
  1906. struct ccci_modem *md = (struct ccci_modem *)data;
  1907. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  1908. wdt_disable_irq(md);
  1909. /* must ack first, otherwise IRQ will rush in */
  1910. md_ctrl->channel_id = cldma_read32(md_ctrl->ap_ccif_base, APCCIF_RCHNUM);
  1911. CCCI_DBG_MSG(md->index, TAG, "MD CCIF IRQ 0x%X\n", md_ctrl->channel_id);
  1912. cldma_write32(md_ctrl->ap_ccif_base, APCCIF_ACK, md_ctrl->channel_id);
  1913. /* only schedule tasklet in EXCEPTION HIF 1 */
  1914. if (md_ctrl->channel_id & (1 << D2H_EXCEPTION_INIT))
  1915. tasklet_hi_schedule(&md_ctrl->ccif_irq_task);
  1916. return IRQ_HANDLED;
  1917. }
  1918. static inline int cldma_sw_init(struct ccci_modem *md)
  1919. {
  1920. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  1921. int ret;
  1922. /* do NOT touch CLDMA HW after power on MD */
  1923. /* Copy HW info */
  1924. md_ctrl->ap_ccif_base = (void __iomem *)md_ctrl->hw_info->ap_ccif_base;
  1925. md_ctrl->md_ccif_base = (void __iomem *)md_ctrl->hw_info->md_ccif_base;
  1926. md_ctrl->cldma_irq_id = md_ctrl->hw_info->cldma_irq_id;
  1927. md_ctrl->ap_ccif_irq_id = md_ctrl->hw_info->ap_ccif_irq_id;
  1928. md_ctrl->md_wdt_irq_id = md_ctrl->hw_info->md_wdt_irq_id;
  1929. md_ctrl->ap2md_bus_timeout_irq_id = md_ctrl->hw_info->ap2md_bus_timeout_irq_id;
  1930. /* do NOT touch CLDMA HW after power on MD */
  1931. /* ioremap CLDMA register region */
  1932. md_cd_io_remap_md_side_register(md);
  1933. /* request IRQ */
  1934. ret = request_irq(md_ctrl->hw_info->cldma_irq_id, cldma_isr, md_ctrl->hw_info->cldma_irq_flags, "CLDMA_AP", md);
  1935. if (ret) {
  1936. CCCI_ERR_MSG(md->index, TAG, "request CLDMA_AP IRQ(%d) error %d\n", md_ctrl->hw_info->cldma_irq_id,
  1937. ret);
  1938. return ret;
  1939. }
  1940. cldma_disable_irq(md_ctrl);
  1941. #ifndef FEATURE_FPGA_PORTING
  1942. ret =
  1943. request_irq(md_ctrl->hw_info->md_wdt_irq_id, md_cd_wdt_isr, md_ctrl->hw_info->md_wdt_irq_flags, "MD_WDT",
  1944. md);
  1945. if (ret) {
  1946. CCCI_ERR_MSG(md->index, TAG, "request MD_WDT IRQ(%d) error %d\n", md_ctrl->hw_info->md_wdt_irq_id, ret);
  1947. return ret;
  1948. }
  1949. /* IRQ is enabled after requested, so call enable_irq after request_irq will get a unbalance warning */
  1950. ret =
  1951. request_irq(md_ctrl->hw_info->ap_ccif_irq_id, md_cd_ccif_isr, md_ctrl->hw_info->ap_ccif_irq_flags,
  1952. "CCIF0_AP", md);
  1953. if (ret) {
  1954. CCCI_ERR_MSG(md->index, TAG, "request CCIF0_AP IRQ(%d) error %d\n", md_ctrl->hw_info->ap_ccif_irq_id,
  1955. ret);
  1956. return ret;
  1957. }
  1958. #endif
  1959. return 0;
  1960. }
  1961. static int md_cd_broadcast_state(struct ccci_modem *md, MD_STATE state)
  1962. {
  1963. int i;
  1964. struct ccci_port *port;
  1965. /* only for thoes states which are updated by port_kernel.c */
  1966. switch (state) {
  1967. case READY:
  1968. md_cd_bootup_cleanup(md, 1);
  1969. /* Update time to modem here, to cover case that user set time between HS1 and IPC channel ready. */
  1970. /* only modem 1 need. so add here. */
  1971. notify_time_update();
  1972. break;
  1973. case BOOT_FAIL:
  1974. if (md->md_state != BOOT_FAIL) /* bootup timeout may comes before MD EE */
  1975. md_cd_bootup_cleanup(md, 0);
  1976. return 0;
  1977. case RX_IRQ:
  1978. case TX_IRQ:
  1979. case TX_FULL:
  1980. CCCI_ERR_MSG(md->index, TAG, "%ps broadcast %d to ports!\n", __builtin_return_address(0), state);
  1981. return 0;
  1982. default:
  1983. break;
  1984. };
  1985. if (md->md_state == state) /* must have, due to we broadcast EXCEPTION both in MD_EX and EX_INIT */
  1986. return 1;
  1987. md->md_state = state;
  1988. for (i = 0; i < md->port_number; i++) {
  1989. port = md->ports + i;
  1990. if (port->ops->md_state_notice)
  1991. port->ops->md_state_notice(port, state);
  1992. }
  1993. return 0;
  1994. }
  1995. static int md_cd_init(struct ccci_modem *md)
  1996. {
  1997. int i;
  1998. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  1999. struct ccci_port *port = NULL;
  2000. CCCI_INF_MSG(md->index, TAG, "CLDMA modem is initializing\n");
  2001. /* init CLMDA, must before queue init as we set start address there */
  2002. cldma_sw_init(md);
  2003. /* init queue */
  2004. for (i = 0; i < QUEUE_LEN(md_ctrl->txq); i++) {
  2005. md_cd_queue_struct_init(&md_ctrl->txq[i], md, OUT, i);
  2006. cldma_tx_queue_init(&md_ctrl->txq[i]);
  2007. }
  2008. for (i = 0; i < QUEUE_LEN(md_ctrl->rxq); i++) {
  2009. md_cd_queue_struct_init(&md_ctrl->rxq[i], md, IN, i);
  2010. cldma_rx_queue_init(&md_ctrl->rxq[i]);
  2011. }
  2012. /* init port */
  2013. for (i = 0; i < md->port_number; i++) {
  2014. port = md->ports + i;
  2015. ccci_port_struct_init(port, md);
  2016. port->ops->init(port);
  2017. if ((port->flags & PORT_F_RX_EXCLUSIVE) && (port->modem->capability & MODEM_CAP_NAPI) &&
  2018. ((1 << port->rxq_index) & NAPI_QUEUE_MASK) && port->rxq_index != 0xFF) {
  2019. md_ctrl->rxq[port->rxq_index].napi_port = port;
  2020. CCCI_DBG_MSG(md->index, TAG, "queue%d add NAPI port %s\n", port->rxq_index, port->name);
  2021. }
  2022. /* be careful, port->rxq_index may be 0xFF! */
  2023. }
  2024. ccci_setup_channel_mapping(md);
  2025. /* update state */
  2026. md->md_state = GATED;
  2027. return 0;
  2028. }
  2029. #if TRAFFIC_MONITOR_INTERVAL
  2030. static void md_cd_clear_traffic_data(struct ccci_modem *md)
  2031. {
  2032. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  2033. memset(md_ctrl->tx_traffic_monitor, 0, sizeof(md_ctrl->tx_traffic_monitor));
  2034. memset(md_ctrl->rx_traffic_monitor, 0, sizeof(md_ctrl->rx_traffic_monitor));
  2035. memset(md_ctrl->tx_pre_traffic_monitor, 0, sizeof(md_ctrl->tx_pre_traffic_monitor));
  2036. }
  2037. #endif
  2038. static void md_ccif_irq_tasklet(unsigned long data)
  2039. {
  2040. struct ccci_modem *md = (struct ccci_modem *)data;
  2041. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  2042. ccif_disable_irq(md);
  2043. schedule_work(&md_ctrl->ccif_work);
  2044. }
  2045. static int md_cd_start(struct ccci_modem *md)
  2046. {
  2047. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  2048. char img_err_str[IMG_ERR_STR_LEN];
  2049. int ret = 0;
  2050. #ifndef ENABLE_CLDMA_AP_SIDE
  2051. int retry, cldma_on = 0;
  2052. #endif
  2053. /* 0. init security, as security depends on dummy_char, which is ready very late. */
  2054. ccci_init_security();
  2055. CCCI_NOTICE_MSG(md->index, TAG, "CLDMA modem is starting\n");
  2056. /* 1. load modem image */
  2057. if (1/*md->config.setting&MD_SETTING_FIRST_BOOT || md->config.setting&MD_SETTING_RELOAD */) {
  2058. ccci_clear_md_region_protection(md);
  2059. ccci_clear_dsp_region_protection(md);
  2060. ret = ccci_load_firmware(md->index, &md->img_info[IMG_MD], img_err_str, md->post_fix);
  2061. if (ret < 0) {
  2062. CCCI_ERR_MSG(md->index, TAG, "load MD firmware fail, %s\n", img_err_str);
  2063. goto out;
  2064. }
  2065. if (md->img_info[IMG_MD].dsp_size != 0 && md->img_info[IMG_MD].dsp_offset != 0xCDCDCDAA) {
  2066. md->img_info[IMG_DSP].address = md->img_info[IMG_MD].address + md->img_info[IMG_MD].dsp_offset;
  2067. ret = ccci_load_firmware(md->index, &md->img_info[IMG_DSP], img_err_str, md->post_fix);
  2068. if (ret < 0) {
  2069. CCCI_ERR_MSG(md->index, TAG, "load DSP firmware fail, %s\n", img_err_str);
  2070. goto out;
  2071. }
  2072. if (md->img_info[IMG_DSP].size > md->img_info[IMG_MD].dsp_size) {
  2073. CCCI_ERR_MSG(md->index, TAG, "DSP image real size too large %d\n",
  2074. md->img_info[IMG_DSP].size);
  2075. goto out;
  2076. }
  2077. md->mem_layout.dsp_region_phy = md->img_info[IMG_DSP].address;
  2078. md->mem_layout.dsp_region_vir = md->mem_layout.md_region_vir + md->img_info[IMG_MD].dsp_offset;
  2079. md->mem_layout.dsp_region_size = ret;
  2080. }
  2081. CCCI_ERR_MSG(md->index, TAG, "load ARMV7 firmware begin[0x%x]<0x%x>\n",
  2082. md->img_info[IMG_MD].arm7_size, md->img_info[IMG_MD].arm7_offset);
  2083. if ((md->img_info[IMG_MD].arm7_size != 0) && (md->img_info[IMG_MD].arm7_offset != 0)) {
  2084. md->img_info[IMG_ARMV7].address = md->img_info[IMG_MD].address+md->img_info[IMG_MD].arm7_offset;
  2085. ret = ccci_load_firmware(md->index, &md->img_info[IMG_ARMV7], img_err_str, md->post_fix);
  2086. if (ret < 0) {
  2087. CCCI_ERR_MSG(md->index, TAG, "load ARMV7 firmware fail, %s\n", img_err_str);
  2088. goto out;
  2089. }
  2090. if (md->img_info[IMG_ARMV7].size > md->img_info[IMG_MD].arm7_size) {
  2091. CCCI_ERR_MSG(md->index, TAG, "ARMV7 image real size too large %d\n",
  2092. md->img_info[IMG_ARMV7].size);
  2093. goto out;
  2094. }
  2095. }
  2096. ret = 0; /* load_std_firmware returns MD image size */
  2097. md->config.setting &= ~MD_SETTING_RELOAD;
  2098. }
  2099. /* 2. clear share memory and ring buffer */
  2100. #if 0 /* no need now, MD will clear share memory itself */
  2101. memset(md->mem_layout.smem_region_vir, 0, md->mem_layout.smem_region_size);
  2102. #endif
  2103. #if 1 /* just in case */
  2104. md_cd_clear_all_queue(md, OUT);
  2105. md_cd_clear_all_queue(md, IN);
  2106. ccci_reset_seq_num(md);
  2107. #endif
  2108. /* 3. enable MPU */
  2109. ccci_set_mem_access_protection(md);
  2110. if (md->mem_layout.dsp_region_phy != 0)
  2111. ccci_set_dsp_region_protection(md, 0);
  2112. /* 4. power on modem, do NOT touch MD register before this */
  2113. if (md->config.setting & MD_SETTING_FIRST_BOOT) {
  2114. #if defined(CONFIG_MTK_LEGACY)
  2115. #ifndef NO_POWER_OFF_ON_STARTMD
  2116. ret = md_cd_power_off(md, 0);
  2117. CCCI_INF_MSG(md->index, TAG, "power off MD first %d\n", ret);
  2118. #endif
  2119. #endif
  2120. md->config.setting &= ~MD_SETTING_FIRST_BOOT;
  2121. }
  2122. #if TRAFFIC_MONITOR_INTERVAL
  2123. md_cd_clear_traffic_data(md);
  2124. #endif
  2125. /* clear all ccif irq before enable it.*/
  2126. cldma_write32(md_ctrl->md_ccif_base, APCCIF_ACK, cldma_read32(md_ctrl->md_ccif_base, APCCIF_RCHNUM));
  2127. cldma_write32(md_ctrl->ap_ccif_base, APCCIF_ACK, cldma_read32(md_ctrl->ap_ccif_base, APCCIF_RCHNUM));
  2128. wdt_executed = 0;
  2129. #ifdef ENABLE_CLDMA_AP_SIDE
  2130. md_cldma_hw_reset(md);
  2131. #endif
  2132. ret = md_cd_power_on(md);
  2133. if (ret) {
  2134. CCCI_ERR_MSG(md->index, TAG, "power on MD fail %d\n", ret);
  2135. goto out;
  2136. }
  2137. #ifdef SET_EMI_STEP_BY_STAGE
  2138. ccci_set_mem_access_protection_1st_stage(md);
  2139. #endif
  2140. /* 5. update mutex */
  2141. atomic_set(&md_ctrl->reset_on_going, 0);
  2142. /* 6. start timer */
  2143. if (!MD_IN_DEBUG(md))
  2144. mod_timer(&md->bootup_timer, jiffies + BOOT_TIMER_ON * HZ);
  2145. /* 7. let modem go */
  2146. md_cd_let_md_go(md);
  2147. wdt_enable_irq(md);
  2148. ccif_enable_irq(md);
  2149. /* 8. start CLDMA */
  2150. #ifdef ENABLE_CLDMA_AP_SIDE
  2151. CCCI_INF_MSG(md->index, TAG, "CLDMA AP side clock is always on\n");
  2152. #else
  2153. retry = CLDMA_CG_POLL;
  2154. while (retry-- > 0) {
  2155. if (!(ccci_read32(md_ctrl->md_global_con0, 0) & (1 << MD_GLOBAL_CON0_CLDMA_BIT))) {
  2156. CCCI_INF_MSG(md->index, TAG, "CLDMA clock is on, retry=%d\n", retry);
  2157. cldma_on = 1;
  2158. break;
  2159. }
  2160. CCCI_INF_MSG(md->index, TAG, "CLDMA clock is still off, retry=%d\n", retry);
  2161. mdelay(1000);
  2162. CCCI_INF_MSG(md->index, TAG, "CLDMA clock is still off, retry=%d\n", retry);
  2163. mdelay(1000);
  2164. }
  2165. if (!cldma_on) {
  2166. ret = -CCCI_ERR_HIF_NOT_POWER_ON;
  2167. CCCI_ERR_MSG(md->index, TAG, "CLDMA clock is off, retry=%d\n", retry);
  2168. goto out;
  2169. }
  2170. #endif
  2171. cldma_reset(md);
  2172. md->ops->broadcast_state(md, BOOTING);
  2173. md->boot_stage = MD_BOOT_STAGE_0;
  2174. md->ex_stage = EX_NONE;
  2175. md->is_forced_assert = 0;
  2176. cldma_start(md);
  2177. out:
  2178. CCCI_NOTICE_MSG(md->index, TAG, "CLDMA modem started %d\n", ret);
  2179. /* used for throttling feature - start */
  2180. ccci_modem_boot_count[md->index]++;
  2181. /* used for throttling feature - end */
  2182. return ret;
  2183. }
  2184. /* only run this in thread context, as we use flush_work in it */
  2185. static void md_cldma_clear(struct ccci_modem *md)
  2186. {
  2187. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  2188. int i;
  2189. unsigned int ret;
  2190. unsigned long flags;
  2191. int retry = 100;
  2192. #ifdef ENABLE_CLDMA_AP_SIDE /* touch MD CLDMA to flush all data from MD to AP */
  2193. ret = cldma_read32(md_ctrl->cldma_md_pdn_base, CLDMA_AP_UL_STATUS);
  2194. for (i = 0; (CLDMA_BM_ALL_QUEUE & ret) && i < QUEUE_LEN(md_ctrl->rxq); i++) {
  2195. if ((CLDMA_BM_ALL_QUEUE & ret) & (1 << i)) {
  2196. CCCI_INF_MSG(md->index, TAG, "MD CLDMA txq=%d is active, need AP rx collect!", i);
  2197. md->ops->give_more(md, i);
  2198. }
  2199. }
  2200. while (retry > 0) {
  2201. ret = cldma_read32(md_ctrl->cldma_md_pdn_base, CLDMA_AP_UL_STATUS);
  2202. if ((CLDMA_BM_ALL_QUEUE & ret) == 0
  2203. && cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_CLDMA_IP_BUSY) == 0) {
  2204. CCCI_INF_MSG(md->index, TAG,
  2205. "MD CLDMA tx status is off, retry=%d, AP_CLDMA_IP_BUSY=0x%x, MD_TX_STATUS=0x%x, AP_RX_STATUS=0x%x\n",
  2206. retry, cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_CLDMA_IP_BUSY),
  2207. cldma_read32(md_ctrl->cldma_md_pdn_base, CLDMA_AP_UL_STATUS),
  2208. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_SO_STATUS));
  2209. break;
  2210. }
  2211. if ((retry % 10) == 0)
  2212. CCCI_INF_MSG(md->index, TAG,
  2213. "MD CLDMA tx is active, retry=%d, AP_CLDMA_IP_BUSY=0x%x, MD_TX_STATUS=0x%x, AP_RX_STATUS=0x%x\n",
  2214. retry, cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_CLDMA_IP_BUSY),
  2215. cldma_read32(md_ctrl->cldma_md_pdn_base, CLDMA_AP_UL_STATUS),
  2216. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_SO_STATUS));
  2217. mdelay(20);
  2218. retry--;
  2219. }
  2220. if (retry == 0 && cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_CLDMA_IP_BUSY) != 0) {
  2221. CCCI_ERR_MSG(md->index, TAG, "md_cldma_clear: wait md tx done failed.\n");
  2222. md_cd_traffic_monitor_func((unsigned long)md);
  2223. cldma_dump_register(md);
  2224. } else {
  2225. CCCI_INF_MSG(md->index, TAG, "md_cldma_clear: md tx done\n");
  2226. }
  2227. #endif
  2228. md_cd_lock_cldma_clock_src(1);
  2229. cldma_stop(md);
  2230. md_cd_lock_cldma_clock_src(0);
  2231. /* 4. reset EE flag */
  2232. spin_lock_irqsave(&md->ctrl_lock, flags);
  2233. md->ee_info_flag = 0; /* must be after broadcast_state(RESET), check port_kernel.c */
  2234. spin_unlock_irqrestore(&md->ctrl_lock, flags);
  2235. /* 5. update state */
  2236. del_timer(&md->bootup_timer);
  2237. /* 6. reset ring buffer */
  2238. md_cd_clear_all_queue(md, OUT);
  2239. /*
  2240. * there is a race condition between md_power_off and CLDMA IRQ. after we get a CLDMA IRQ,
  2241. * if we power off MD before CLDMA tasklet is scheduled, the tasklet will get 0 when reading CLDMA
  2242. * register, and not schedule workqueue to check RGPD. this will leave an HWO=0 RGPD in ring
  2243. * buffer and cause a queue being stopped. so we flush RGPD here to kill this missing RX_DONE interrupt.
  2244. */
  2245. md_cd_clear_all_queue(md, IN);
  2246. #ifdef ENABLE_CLDMA_AP_SIDE
  2247. md_cldma_hw_reset(md);
  2248. #endif
  2249. }
  2250. static int md_cd_reset(struct ccci_modem *md)
  2251. {
  2252. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  2253. /* 1. mutex check */
  2254. if (atomic_add_return(1, &md_ctrl->reset_on_going) > 1) {
  2255. CCCI_INF_MSG(md->index, TAG, "One reset flow is on-going\n");
  2256. return -CCCI_ERR_MD_IN_RESET;
  2257. }
  2258. CCCI_INF_MSG(md->index, TAG, "md_cd_reset:CLDMA modem is resetting\n");
  2259. /* 2. disable WDT IRQ */
  2260. wdt_disable_irq(md);
  2261. /* 3, stop CLDMA */
  2262. md->ops->broadcast_state(md, RESET); /* to block port's write operation */
  2263. md->boot_stage = MD_BOOT_STAGE_0;
  2264. return 0;
  2265. }
  2266. static int check_power_off_en(struct ccci_modem *md)
  2267. {
  2268. #ifdef ENABLE_MD_POWER_OFF_CHECK
  2269. int smem_val;
  2270. if (md->index != MD_SYS1)
  2271. return 1;
  2272. smem_val = *((int *)((long)md->mem_layout.smem_region_vir + 8*1024+31*4));
  2273. CCCI_INF_MSG(md->index, TAG, "share for power off:%x\n", smem_val);
  2274. if (smem_val != 0) {
  2275. CCCI_INF_MSG(md->index, TAG, "[ccci]enable power off check\n");
  2276. return 1;
  2277. }
  2278. CCCI_INF_MSG(md->index, TAG, "disable power off check\n");
  2279. return 0;
  2280. #else
  2281. return 1;
  2282. #endif
  2283. }
  2284. static int md_cd_stop(struct ccci_modem *md, unsigned int timeout)
  2285. {
  2286. int ret = 0, count = 0;
  2287. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  2288. u32 pending;
  2289. int en_power_check;
  2290. int i;
  2291. unsigned int rx_ch_bitmap;
  2292. CCCI_INF_MSG(md->index, TAG, "CLDMA modem is power off, timeout=%d\n", timeout);
  2293. md->sim_type = 0xEEEEEEEE; /* reset sim_type(MCC/MNC) to 0xEEEEEEEE */
  2294. /* flush work before new start */
  2295. flush_work(&md_ctrl->ccif_work);
  2296. flush_work(&md_ctrl->wdt_work);
  2297. del_timer(&md->ex_monitor);
  2298. del_timer(&md->ex_monitor2);
  2299. md_cd_check_emi_state(md, 1); /* Check EMI before */
  2300. en_power_check = check_power_off_en(md);
  2301. if (timeout) { /* only debug in Flight mode */
  2302. count = 5;
  2303. while (spm_is_md1_sleep() == 0) {
  2304. count--;
  2305. if (count == 0) {
  2306. if (en_power_check) {
  2307. CCCI_INF_MSG(md->index, TAG, "MD is not in sleep mode, dump md status!\n");
  2308. CCCI_INF_MSG(md->index, KERN, "Dump MD EX log\n");
  2309. ccci_mem_dump(md->index, md->smem_layout.ccci_exp_smem_base_vir,
  2310. md->smem_layout.ccci_exp_dump_size);
  2311. md_cd_dump_debug_register(md);
  2312. cldma_dump_register(md);
  2313. #if defined(CONFIG_MTK_AEE_FEATURE)
  2314. #ifdef MD_UMOLY_EE_SUPPORT
  2315. aed_md_exception_api(md->smem_layout.ccci_exp_smem_mdss_debug_vir,
  2316. md->smem_layout.ccci_exp_smem_mdss_debug_size, NULL, 0,
  2317. "After AP send EPOF, MD didn't go to sleep in 4 seconds.",
  2318. DB_OPT_DEFAULT);
  2319. #else
  2320. aed_md_exception_api(NULL, 0, NULL, 0,
  2321. "After AP send EPOF, MD didn't go to sleep in 4 seconds.",
  2322. DB_OPT_DEFAULT);
  2323. #endif
  2324. #endif
  2325. }
  2326. break;
  2327. }
  2328. md_cd_lock_cldma_clock_src(1);
  2329. msleep(1000);
  2330. md_cd_lock_cldma_clock_src(0);
  2331. msleep(20);
  2332. }
  2333. pending = mt_irq_get_pending(md_ctrl->hw_info->md_wdt_irq_id);
  2334. if (pending) {
  2335. CCCI_INF_MSG(md->index, TAG, "WDT IRQ occur.");
  2336. CCCI_INF_MSG(md->index, KERN, "Dump MD EX log\n");
  2337. ccci_mem_dump(md->index, md->smem_layout.ccci_exp_smem_base_vir,
  2338. md->smem_layout.ccci_exp_dump_size);
  2339. md_cd_dump_debug_register(md);
  2340. cldma_dump_register(md);
  2341. #if defined(CONFIG_MTK_AEE_FEATURE)
  2342. aed_md_exception_api(NULL, 0, NULL, 0, "WDT IRQ occur.", DB_OPT_DEFAULT);
  2343. #endif
  2344. }
  2345. }
  2346. #ifndef ENABLE_CLDMA_AP_SIDE
  2347. md_cldma_clear(md);
  2348. #endif
  2349. /* power off MD */
  2350. ret = md_cd_power_off(md, timeout);
  2351. CCCI_INF_MSG(md->index, TAG, "CLDMA modem is power off done, %d\n", ret);
  2352. md->ops->broadcast_state(md, GATED);
  2353. #ifdef ENABLE_CLDMA_AP_SIDE
  2354. md_cldma_clear(md);
  2355. #endif
  2356. /* ACK CCIF for MD. while entering flight mode, we may send something after MD slept */
  2357. rx_ch_bitmap = cldma_read32(md_ctrl->md_ccif_base, APCCIF_RCHNUM);
  2358. if (rx_ch_bitmap) {
  2359. CCCI_INF_MSG(md->index, TAG, "CCIF rx bitmap: 0x%x\n", rx_ch_bitmap);
  2360. for (i = 0; i < 16; i++) {
  2361. /* Ack one by one */
  2362. if (rx_ch_bitmap & (1<<i))
  2363. cldma_write32(md_ctrl->md_ccif_base, APCCIF_ACK, (1<<i));
  2364. }
  2365. rx_ch_bitmap = cldma_read32(md_ctrl->md_ccif_base, APCCIF_RCHNUM);
  2366. CCCI_INF_MSG(md->index, TAG, "CCIF rx bitmap: 0x%x(after ack)\n", rx_ch_bitmap);
  2367. }
  2368. md_cd_check_emi_state(md, 0); /* Check EMI after */
  2369. return 0;
  2370. }
  2371. static int md_cd_write_room(struct ccci_modem *md, unsigned char qno)
  2372. {
  2373. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  2374. if (qno >= QUEUE_LEN(md_ctrl->txq))
  2375. return -CCCI_ERR_INVALID_QUEUE_INDEX;
  2376. return md_ctrl->txq[qno].budget;
  2377. }
  2378. /* this is called inside queue->ring_lock */
  2379. static int cldma_gpd_bd_handle_tx_request(struct md_cd_queue *queue, struct cldma_request *tx_req,
  2380. struct sk_buff *skb, DATA_POLICY policy, unsigned int ioc_override)
  2381. {
  2382. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)queue->modem->private_data;
  2383. struct cldma_tgpd *tgpd;
  2384. struct skb_shared_info *info = skb_shinfo(skb);
  2385. int cur_frag;
  2386. struct cldma_tbd *tbd;
  2387. struct cldma_request *tx_req_bd;
  2388. /* network does not has IOC override needs */
  2389. CCCI_DBG_MSG(queue->modem->index, TAG, "SGIO, GPD=%p, frags=%d, len=%d, headlen=%d\n", tx_req->gpd,
  2390. info->nr_frags, skb->len, skb_headlen(skb));
  2391. /* link firt BD to skb's data */
  2392. tx_req_bd = list_first_entry(&tx_req->bd, struct cldma_request, entry);
  2393. /* link rest BD to frags' data */
  2394. for (cur_frag = -1; cur_frag < info->nr_frags; cur_frag++) {
  2395. unsigned int frag_len;
  2396. void *frag_addr;
  2397. if (cur_frag == -1) {
  2398. frag_len = skb_headlen(skb);
  2399. frag_addr = skb->data;
  2400. } else {
  2401. skb_frag_t *frag = info->frags + cur_frag;
  2402. frag_len = skb_frag_size(frag);
  2403. frag_addr = skb_frag_address(frag);
  2404. }
  2405. tbd = tx_req_bd->gpd;
  2406. CCCI_DBG_MSG(queue->modem->index, TAG, "SGIO, BD=%p, frag%d, frag_len=%d\n", tbd, cur_frag, frag_len);
  2407. /* update BD */
  2408. tx_req_bd->data_buffer_ptr_saved =
  2409. dma_map_single(&queue->modem->plat_dev->dev, frag_addr, frag_len, DMA_TO_DEVICE);
  2410. tbd->data_buff_ptr = (u32) (tx_req_bd->data_buffer_ptr_saved);
  2411. tbd->data_buff_len = frag_len;
  2412. tbd->non_used = 1;
  2413. tbd->bd_flags &= ~0x1; /* clear EOL */
  2414. /* checksum of BD */
  2415. caculate_checksum((char *)tbd, tbd->bd_flags);
  2416. /* step forward */
  2417. tx_req_bd = list_entry(tx_req_bd->entry.next, struct cldma_request, entry);
  2418. }
  2419. tbd->bd_flags |= 0x1; /* set EOL */
  2420. caculate_checksum((char *)tbd, tbd->bd_flags);
  2421. tgpd = tx_req->gpd;
  2422. /* update GPD */
  2423. tgpd->data_buff_len = skb->len;
  2424. tgpd->debug_id = queue->debug_id++;
  2425. tgpd->non_used = 1;
  2426. /* checksum of GPD */
  2427. caculate_checksum((char *)tgpd, tgpd->gpd_flags | 0x1);
  2428. /* set HWO */
  2429. spin_lock(&md_ctrl->cldma_timeout_lock);
  2430. if (md_ctrl->txq_active & (1 << queue->index))
  2431. cldma_write8(&tgpd->gpd_flags, 0, cldma_read8(&tgpd->gpd_flags, 0) | 0x1);
  2432. spin_unlock(&md_ctrl->cldma_timeout_lock);
  2433. /* mark cldma_request as available */
  2434. tx_req->skb = skb;
  2435. tx_req->policy = policy;
  2436. return 0;
  2437. }
  2438. /* this is called inside queue->ring_lock */
  2439. static int cldma_gpd_handle_tx_request(struct md_cd_queue *queue, struct cldma_request *tx_req,
  2440. struct sk_buff *skb, DATA_POLICY policy, unsigned int ioc_override)
  2441. {
  2442. struct cldma_tgpd *tgpd;
  2443. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)queue->modem->private_data;
  2444. tgpd = tx_req->gpd;
  2445. /* override current IOC setting */
  2446. if (ioc_override & 0x80) {
  2447. tx_req->ioc_override = 0x80 | (!!(tgpd->gpd_flags & 0x80)); /* backup current IOC setting */
  2448. if (ioc_override & 0x1)
  2449. tgpd->gpd_flags |= 0x80;
  2450. else
  2451. tgpd->gpd_flags &= 0x7F;
  2452. }
  2453. /* update GPD */
  2454. tx_req->data_buffer_ptr_saved =
  2455. dma_map_single(&queue->modem->plat_dev->dev, skb->data, skb->len, DMA_TO_DEVICE);
  2456. tgpd->data_buff_bd_ptr = (u32) (tx_req->data_buffer_ptr_saved);
  2457. tgpd->data_buff_len = skb->len;
  2458. tgpd->debug_id = queue->debug_id++;
  2459. tgpd->non_used = 1;
  2460. /* checksum of GPD */
  2461. caculate_checksum((char *)tgpd, tgpd->gpd_flags | 0x1);
  2462. /*
  2463. * set HWO
  2464. * use cldma_timeout_lock to avoid race conditon with cldma_stop. this lock must cover TGPD setting, as even
  2465. * without a resume operation, CLDMA still can start sending next HWO=1 TGPD if last TGPD was just finished.
  2466. */
  2467. spin_lock(&md_ctrl->cldma_timeout_lock);
  2468. if (md_ctrl->txq_active & (1 << queue->index))
  2469. cldma_write8(&tgpd->gpd_flags, 0, cldma_read8(&tgpd->gpd_flags, 0) | 0x1);
  2470. spin_unlock(&md_ctrl->cldma_timeout_lock);
  2471. /* mark cldma_request as available */
  2472. tx_req->skb = skb;
  2473. tx_req->policy = policy;
  2474. return 0;
  2475. }
  2476. static int md_cd_send_request(struct ccci_modem *md, unsigned char qno, struct ccci_request *req, struct sk_buff *skb)
  2477. {
  2478. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  2479. struct md_cd_queue *queue;
  2480. struct cldma_request *tx_req;
  2481. int ret = 0;
  2482. int blocking;
  2483. struct ccci_header ccci_h;
  2484. unsigned int ioc_override = 0;
  2485. unsigned long flags;
  2486. unsigned int tx_bytes = 0;
  2487. DATA_POLICY policy;
  2488. #ifdef CLDMA_TRACE
  2489. static unsigned long long last_leave_time[CLDMA_TXQ_NUM] = { 0 };
  2490. static unsigned int sample_time[CLDMA_TXQ_NUM] = { 0 };
  2491. static unsigned int sample_bytes[CLDMA_TXQ_NUM] = { 0 };
  2492. unsigned long long total_time = 0;
  2493. unsigned int tx_interal;
  2494. #endif
  2495. #ifdef CLDMA_TRACE
  2496. total_time = sched_clock();
  2497. if (last_leave_time[qno] == 0)
  2498. tx_interal = 0;
  2499. else
  2500. tx_interal = total_time - last_leave_time[qno];
  2501. #endif
  2502. memset(&ccci_h, 0, sizeof(struct ccci_header));
  2503. #if TRAFFIC_MONITOR_INTERVAL
  2504. if ((jiffies - md_ctrl->traffic_stamp) / HZ >= TRAFFIC_MONITOR_INTERVAL) {
  2505. md_ctrl->traffic_stamp = jiffies;
  2506. mod_timer(&md_ctrl->traffic_monitor, jiffies);
  2507. }
  2508. #endif
  2509. if (qno >= QUEUE_LEN(md_ctrl->txq)) {
  2510. ret = -CCCI_ERR_INVALID_QUEUE_INDEX;
  2511. goto __EXIT_FUN;
  2512. }
  2513. if (req) {
  2514. skb = req->skb;
  2515. policy = req->policy;
  2516. ioc_override = req->ioc_override;
  2517. blocking = req->blocking;
  2518. } else {
  2519. policy = FREE; /* here we assume only network use this kind of API */
  2520. ioc_override = 0;
  2521. blocking = 0;
  2522. }
  2523. ccci_h = *(struct ccci_header *)skb->data;
  2524. queue = &md_ctrl->txq[qno];
  2525. tx_bytes = skb->len;
  2526. retry:
  2527. spin_lock_irqsave(&queue->ring_lock, flags);
  2528. /* we use irqsave as network require a lock in softirq, cause a potential deadlock */
  2529. CCCI_DBG_MSG(md->index, TAG, "get a Tx req on q%d free=%d, tx_bytes = %X\n", qno, queue->budget, tx_bytes);
  2530. tx_req = queue->tx_xmit;
  2531. if (tx_req->skb == NULL) {
  2532. ccci_inc_tx_seq_num(md, (struct ccci_header *)skb->data);
  2533. /* wait write done */
  2534. wmb();
  2535. queue->budget--;
  2536. queue->tr_ring->handle_tx_request(queue, tx_req, skb, policy, ioc_override);
  2537. /* step forward */
  2538. queue->tx_xmit = cldma_ring_step_forward(queue->tr_ring, tx_req);
  2539. spin_unlock_irqrestore(&queue->ring_lock, flags);
  2540. /* update log */
  2541. #if TRAFFIC_MONITOR_INTERVAL
  2542. md_ctrl->tx_pre_traffic_monitor[queue->index]++;
  2543. #endif
  2544. ccci_dump_log_add(md, OUT, (int)queue->index, &ccci_h, 0);
  2545. /*
  2546. * make sure TGPD is ready by here, otherwise there is race conditon between ports over the same queue.
  2547. * one port is just setting TGPD, another port may have resumed the queue.
  2548. */
  2549. md_cd_lock_cldma_clock_src(1);
  2550. /* put it outside of spin_lock_irqsave to avoid disabling IRQ too long */
  2551. spin_lock_irqsave(&md_ctrl->cldma_timeout_lock, flags);
  2552. if (md_ctrl->txq_active & (1 << qno)) {
  2553. #ifdef ENABLE_CLDMA_TIMER
  2554. if (IS_NET_QUE(md, qno)) {
  2555. queue->timeout_start = local_clock();
  2556. ret = mod_timer(&queue->timeout_timer, jiffies + CLDMA_ACTIVE_T * HZ);
  2557. CCCI_DBG_MSG(md->index, TAG, "md_ctrl->txq_active=%d, qno%d ,ch%d, start_timer=%d\n",
  2558. md_ctrl->txq_active, qno, ccci_h.channel, ret);
  2559. ret = 0;
  2560. }
  2561. #endif
  2562. #ifdef NO_START_ON_SUSPEND_RESUME
  2563. if (md_ctrl->txq_started) {
  2564. #endif
  2565. /* resume Tx queue */
  2566. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_UL_RESUME_CMD,
  2567. CLDMA_BM_ALL_QUEUE & (1 << qno));
  2568. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_UL_RESUME_CMD);
  2569. /* dummy read to create a non-buffable write */
  2570. #ifdef NO_START_ON_SUSPEND_RESUME
  2571. } else {
  2572. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_UL_START_CMD, CLDMA_BM_ALL_QUEUE);
  2573. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_UL_START_CMD); /* dummy read */
  2574. md_ctrl->txq_started = 1;
  2575. }
  2576. #endif
  2577. #ifndef ENABLE_CLDMA_AP_SIDE
  2578. md_cd_ccif_send(md, AP_MD_PEER_WAKEUP);
  2579. #endif
  2580. } else {
  2581. /*
  2582. * [NOTICE] Dont return error
  2583. * SKB has been put into cldma chain,
  2584. * However, if txq_active is disable, that means cldma_stop for some case,
  2585. * and cldma no need resume again.
  2586. * This package will be dropped by cldma.
  2587. */
  2588. CCCI_INF_MSG(md->index, TAG, "ch=%d qno=%d cldma maybe stop, this package will be dropped!\n",
  2589. ccci_h.channel, qno);
  2590. }
  2591. spin_unlock_irqrestore(&md_ctrl->cldma_timeout_lock, flags);
  2592. md_cd_lock_cldma_clock_src(0);
  2593. } else {
  2594. if (likely(md->capability & MODEM_CAP_TXBUSY_STOP))
  2595. cldma_queue_broadcast_state(md, TX_FULL, OUT, queue->index);
  2596. spin_unlock_irqrestore(&queue->ring_lock, flags);
  2597. /* check CLDMA status */
  2598. md_cd_lock_cldma_clock_src(1);
  2599. if (cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_UL_STATUS) & (1 << qno)) {
  2600. CCCI_DBG_MSG(md->index, TAG, "ch=%d qno=%d free slot 0, CLDMA_AP_UL_STATUS=0x%x\n",
  2601. ccci_h.channel, qno, cldma_read32(md_ctrl->cldma_ap_pdn_base,
  2602. CLDMA_AP_UL_STATUS));
  2603. queue->busy_count++;
  2604. } else {
  2605. if (cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2TIMR0) & (1 << qno))
  2606. CCCI_INF_MSG(md->index, TAG, "ch=%d qno=%d free slot 0, CLDMA_AP_L2TIMR0=0x%x\n",
  2607. ccci_h.channel, qno, cldma_read32(md_ctrl->cldma_ap_pdn_base,
  2608. CLDMA_AP_L2TIMR0));
  2609. }
  2610. md_cd_lock_cldma_clock_src(0);
  2611. #ifdef CLDMA_NO_TX_IRQ
  2612. queue->tr_ring->handle_tx_done(queue, 0, 0, &ret);
  2613. #endif
  2614. if (blocking) {
  2615. ret = wait_event_interruptible_exclusive(queue->req_wq, (queue->budget > 0));
  2616. if (ret == -ERESTARTSYS) {
  2617. ret = -EINTR;
  2618. goto __EXIT_FUN;
  2619. }
  2620. #ifdef CLDMA_TRACE
  2621. trace_cldma_error(qno, ccci_h.channel, ret, __LINE__);
  2622. #endif
  2623. goto retry;
  2624. } else {
  2625. ret = -EBUSY;
  2626. goto __EXIT_FUN;
  2627. }
  2628. }
  2629. __EXIT_FUN:
  2630. if (req && !ret) {
  2631. /* free old request as wrapper, only when we've ate this request */
  2632. req->policy = NOOP;
  2633. ccci_free_req(req);
  2634. }
  2635. #ifdef CLDMA_TRACE
  2636. if (unlikely(ret)) {
  2637. CCCI_DBG_MSG(md->index, TAG, "txq_active=%d, qno=%d is 0,drop ch%d package,ret=%d\n",
  2638. md_ctrl->txq_active, qno, ccci_h.channel, ret);
  2639. trace_cldma_error(qno, ccci_h.channel, ret, __LINE__);
  2640. } else {
  2641. last_leave_time[qno] = sched_clock();
  2642. total_time = last_leave_time[qno] - total_time;
  2643. sample_time[queue->index] += (total_time + tx_interal);
  2644. sample_bytes[queue->index] += tx_bytes;
  2645. trace_cldma_tx(qno, ccci_h.channel, md_ctrl->txq[qno].budget, tx_interal, total_time,
  2646. tx_bytes, 0, 0);
  2647. if (sample_time[queue->index] >= trace_sample_time) {
  2648. trace_cldma_tx(qno, ccci_h.channel, 0, 0, 0, 0,
  2649. sample_time[queue->index], sample_bytes[queue->index]);
  2650. sample_time[queue->index] = 0;
  2651. sample_bytes[queue->index] = 0;
  2652. }
  2653. }
  2654. #endif
  2655. return ret;
  2656. }
  2657. static int md_cd_give_more(struct ccci_modem *md, unsigned char qno)
  2658. {
  2659. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  2660. int ret;
  2661. if (qno >= QUEUE_LEN(md_ctrl->rxq))
  2662. return -CCCI_ERR_INVALID_QUEUE_INDEX;
  2663. CCCI_DBG_MSG(md->index, TAG, "give more on queue %d work %p\n", qno, &md_ctrl->rxq[qno].cldma_rx_work);
  2664. ret = queue_work(md_ctrl->rxq[qno].worker, &md_ctrl->rxq[qno].cldma_rx_work);
  2665. return 0;
  2666. }
  2667. static int md_cd_napi_poll(struct ccci_modem *md, unsigned char qno, struct napi_struct *napi, int weight)
  2668. {
  2669. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  2670. int ret, result, rx_bytes, all_clr = 0;
  2671. unsigned long flags;
  2672. struct md_cd_queue *queue;
  2673. unsigned int L2RISAR0 = 0;
  2674. if (qno >= QUEUE_LEN(md_ctrl->rxq))
  2675. return -CCCI_ERR_INVALID_QUEUE_INDEX;
  2676. queue = &md_ctrl->rxq[qno];
  2677. ret = queue->tr_ring->handle_rx_done(queue, weight, 0, &result, &rx_bytes);
  2678. if (likely(weight < queue->budget))
  2679. all_clr = ret == 0 ? 1 : 0;
  2680. else
  2681. all_clr = ret < queue->budget ? 1 : 0;
  2682. if (likely(all_clr && result != NO_SKB))
  2683. all_clr = 1;
  2684. else
  2685. all_clr = 0;
  2686. md_cd_lock_cldma_clock_src(1);
  2687. L2RISAR0 = cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2RISAR0);
  2688. if (L2RISAR0 & CLDMA_BM_INT_DONE & (1 << queue->index)) {
  2689. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_L2RISAR0, (1 << queue->index));
  2690. all_clr = 0;
  2691. }
  2692. if (all_clr)
  2693. napi_complete(napi);
  2694. spin_lock_irqsave(&md_ctrl->cldma_timeout_lock, flags);
  2695. if (md_ctrl->rxq_active & (1 << qno)) {
  2696. /* resume Rx queue */
  2697. cldma_write32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_SO_RESUME_CMD, CLDMA_BM_ALL_QUEUE & (1 << qno));
  2698. cldma_read32(md_ctrl->cldma_ap_pdn_base, CLDMA_AP_SO_RESUME_CMD); /* dummy read */
  2699. /* enable RX_DONE interrupt */
  2700. if (all_clr)
  2701. cldma_write32(md_ctrl->cldma_ap_ao_base, CLDMA_AP_L2RIMCR0, CLDMA_BM_ALL_QUEUE & (1 << qno));
  2702. }
  2703. spin_unlock_irqrestore(&md_ctrl->cldma_timeout_lock, flags);
  2704. md_cd_lock_cldma_clock_src(0);
  2705. CCCI_DBG_MSG(md->index, TAG, "NAPI poll on queue %d, %d->%d->%d\n", qno, weight, ret, all_clr);
  2706. return ret;
  2707. }
  2708. static struct ccci_port *md_cd_get_port_by_minor(struct ccci_modem *md, int minor)
  2709. {
  2710. int i;
  2711. struct ccci_port *port;
  2712. for (i = 0; i < md->port_number; i++) {
  2713. port = md->ports + i;
  2714. if (port->minor == minor)
  2715. return port;
  2716. }
  2717. return NULL;
  2718. }
  2719. static struct ccci_port *md_cd_get_port_by_channel(struct ccci_modem *md, CCCI_CH ch)
  2720. {
  2721. int i;
  2722. struct ccci_port *port;
  2723. for (i = 0; i < md->port_number; i++) {
  2724. port = md->ports + i;
  2725. if (port->rx_ch == ch || port->tx_ch == ch)
  2726. return port;
  2727. }
  2728. return NULL;
  2729. }
  2730. static void dump_runtime_data_v2(struct ccci_modem *md, struct ap_query_md_feature *ap_feature)
  2731. {
  2732. u8 i = 0;
  2733. CCCI_INF_MSG(md->index, KERN, "head_pattern 0x%x\n", ap_feature->head_pattern);
  2734. for (i = BOOT_INFO; i < AP_RUNTIME_FEATURE_ID_MAX; i++) {
  2735. CCCI_NOTICE_MSG(md->index, KERN, "feature %u: mask %u, version %u\n",
  2736. i, ap_feature->feature_set[i].support_mask, ap_feature->feature_set[i].version);
  2737. }
  2738. CCCI_INF_MSG(md->index, KERN, "share_memory_support 0x%x\n", ap_feature->share_memory_support);
  2739. CCCI_INF_MSG(md->index, KERN, "ap_runtime_data_addr 0x%x\n", ap_feature->ap_runtime_data_addr);
  2740. CCCI_INF_MSG(md->index, KERN, "ap_runtime_data_size 0x%x\n", ap_feature->ap_runtime_data_size);
  2741. CCCI_INF_MSG(md->index, KERN, "md_runtime_data_addr 0x%x\n", ap_feature->md_runtime_data_addr);
  2742. CCCI_INF_MSG(md->index, KERN, "md_runtime_data_size 0x%x\n", ap_feature->md_runtime_data_size);
  2743. CCCI_INF_MSG(md->index, KERN, "set_md_mpu_start_addr 0x%x\n", ap_feature->set_md_mpu_start_addr);
  2744. CCCI_INF_MSG(md->index, KERN, "set_md_mpu_total_size 0x%x\n", ap_feature->set_md_mpu_total_size);
  2745. CCCI_INF_MSG(md->index, KERN, "tail_pattern 0x%x\n", ap_feature->tail_pattern);
  2746. }
  2747. static void dump_runtime_data(struct ccci_modem *md, struct modem_runtime *runtime)
  2748. {
  2749. char ctmp[12];
  2750. int *p;
  2751. p = (int *)ctmp;
  2752. *p = runtime->Prefix;
  2753. p++;
  2754. *p = runtime->Platform_L;
  2755. p++;
  2756. *p = runtime->Platform_H;
  2757. CCCI_INF_MSG(md->index, TAG, "**********************************************\n");
  2758. CCCI_INF_MSG(md->index, TAG, "Prefix %c%c%c%c\n", ctmp[0], ctmp[1],
  2759. ctmp[2], ctmp[3]);
  2760. CCCI_INF_MSG(md->index, TAG, "Platform_L %c%c%c%c\n", ctmp[4], ctmp[5],
  2761. ctmp[6], ctmp[7]);
  2762. CCCI_INF_MSG(md->index, TAG, "Platform_H %c%c%c%c\n", ctmp[8], ctmp[9],
  2763. ctmp[10], ctmp[11]);
  2764. CCCI_INF_MSG(md->index, TAG, "DriverVersion 0x%x\n", runtime->DriverVersion);
  2765. CCCI_INF_MSG(md->index, TAG, "BootChannel %d\n", runtime->BootChannel);
  2766. CCCI_INF_MSG(md->index, TAG, "BootingStartID(Mode) 0x%x\n", runtime->BootingStartID);
  2767. CCCI_INF_MSG(md->index, TAG, "BootAttributes %d\n", runtime->BootAttributes);
  2768. CCCI_INF_MSG(md->index, TAG, "BootReadyID %d\n", runtime->BootReadyID);
  2769. CCCI_INF_MSG(md->index, TAG, "ExceShareMemBase 0x%x\n", runtime->ExceShareMemBase);
  2770. CCCI_INF_MSG(md->index, TAG, "ExceShareMemSize 0x%x\n", runtime->ExceShareMemSize);
  2771. CCCI_INF_MSG(md->index, TAG, "TotalShareMemBase 0x%x\n", runtime->TotalShareMemBase);
  2772. CCCI_INF_MSG(md->index, TAG, "TotalShareMemSize 0x%x\n", runtime->TotalShareMemSize);
  2773. CCCI_INF_MSG(md->index, TAG, "CheckSum %d\n", runtime->CheckSum);
  2774. p = (int *)ctmp;
  2775. *p = runtime->Postfix;
  2776. CCCI_INF_MSG(md->index, TAG, "Postfix %c%c%c%c\n", ctmp[0], ctmp[1], ctmp[2],
  2777. ctmp[3]);
  2778. CCCI_INF_MSG(md->index, TAG, "**********************************************\n");
  2779. p = (int *)ctmp;
  2780. *p = runtime->misc_prefix;
  2781. CCCI_INF_MSG(md->index, TAG, "Prefix %c%c%c%c\n", ctmp[0], ctmp[1],
  2782. ctmp[2], ctmp[3]);
  2783. CCCI_INF_MSG(md->index, TAG, "SupportMask 0x%x\n", runtime->support_mask);
  2784. CCCI_INF_MSG(md->index, TAG, "Index 0x%x\n", runtime->index);
  2785. CCCI_INF_MSG(md->index, TAG, "Next 0x%x\n", runtime->next);
  2786. CCCI_INF_MSG(md->index, TAG, "Feature0 0x%x 0x%x 0x%x 0x%x\n", runtime->feature_0_val[0],
  2787. runtime->feature_0_val[1], runtime->feature_0_val[2], runtime->feature_0_val[3]);
  2788. CCCI_INF_MSG(md->index, TAG, "Feature1 0x%x 0x%x 0x%x 0x%x\n", runtime->feature_1_val[0],
  2789. runtime->feature_1_val[1], runtime->feature_1_val[2], runtime->feature_1_val[3]);
  2790. CCCI_INF_MSG(md->index, TAG, "Feature2 0x%x 0x%x 0x%x 0x%x\n", runtime->feature_2_val[0],
  2791. runtime->feature_2_val[1], runtime->feature_2_val[2], runtime->feature_2_val[3]);
  2792. CCCI_INF_MSG(md->index, TAG, "Feature3 0x%x 0x%x 0x%x 0x%x\n", runtime->feature_3_val[0],
  2793. runtime->feature_3_val[1], runtime->feature_3_val[2], runtime->feature_3_val[3]);
  2794. CCCI_INF_MSG(md->index, TAG, "Feature4 0x%x 0x%x 0x%x 0x%x\n", runtime->feature_4_val[0],
  2795. runtime->feature_4_val[1], runtime->feature_4_val[2], runtime->feature_4_val[3]);
  2796. CCCI_INF_MSG(md->index, TAG, "Feature5 0x%x 0x%x 0x%x 0x%x\n", runtime->feature_5_val[0],
  2797. runtime->feature_5_val[1], runtime->feature_5_val[2], runtime->feature_5_val[3]);
  2798. CCCI_INF_MSG(md->index, TAG, "Feature6 0x%x 0x%x 0x%x 0x%x\n", runtime->feature_6_val[0],
  2799. runtime->feature_6_val[1], runtime->feature_6_val[2], runtime->feature_6_val[3]);
  2800. CCCI_INF_MSG(md->index, TAG, "Feature7 0x%x 0x%x 0x%x 0x%x\n", runtime->feature_7_val[0],
  2801. runtime->feature_7_val[1], runtime->feature_7_val[2], runtime->feature_7_val[3]);
  2802. p = (int *)ctmp;
  2803. *p = runtime->misc_postfix;
  2804. CCCI_INF_MSG(md->index, TAG, "Postfix %c%c%c%c\n", ctmp[0], ctmp[1], ctmp[2],
  2805. ctmp[3]);
  2806. CCCI_INF_MSG(md->index, TAG, "----------------------------------------------\n");
  2807. }
  2808. #ifdef FEATURE_DBM_SUPPORT
  2809. static void eccci_smem_sub_region_init(struct ccci_modem *md)
  2810. {
  2811. volatile int __iomem *addr;
  2812. int i;
  2813. /* Region 0, dbm */
  2814. addr = (volatile int __iomem *)(md->mem_layout.smem_region_vir+CCCI_SMEM_MD1_DBM_OFFSET);
  2815. addr[0] = 0x44444444; /* Guard pattern 1 header */
  2816. addr[1] = 0x44444444; /* Guard pattern 2 header */
  2817. #ifdef DISABLE_PBM_FEATURE
  2818. for (i = 2; i < (10+2); i++)
  2819. addr[i] = 0xFFFFFFFF;
  2820. #else
  2821. for (i = 2; i < (10+2); i++)
  2822. addr[i] = 0x00000000;
  2823. #endif
  2824. addr[i++] = 0x44444444; /* Guard pattern 1 tail */
  2825. addr[i++] = 0x44444444; /* Guard pattern 2 tail */
  2826. /* Notify PBM */
  2827. #ifndef DISABLE_PBM_FEATURE
  2828. init_md_section_level(KR_MD1);
  2829. #endif
  2830. }
  2831. #endif
  2832. static void config_ap_runtime_data(struct ccci_modem *md, struct ap_query_md_feature *ap_feature)
  2833. {
  2834. ap_feature->head_pattern = AP_FEATURE_QUERY_PATTERN;
  2835. /*AP query MD feature set */
  2836. ap_feature->share_memory_support = 1;
  2837. ap_feature->ap_runtime_data_addr = md->smem_layout.ccci_rt_smem_base_phy - md->mem_layout.smem_offset_AP_to_MD;
  2838. ap_feature->ap_runtime_data_size = CCCI_SMEM_SIZE_RUNTIME_AP;
  2839. ap_feature->md_runtime_data_addr = ap_feature->ap_runtime_data_addr + CCCI_SMEM_SIZE_RUNTIME_AP;
  2840. ap_feature->md_runtime_data_size = CCCI_SMEM_SIZE_RUNTIME_MD;
  2841. ap_feature->set_md_mpu_start_addr = md->mem_layout.smem_region_phy - md->mem_layout.smem_offset_AP_to_MD;
  2842. ap_feature->set_md_mpu_total_size = md->mem_layout.smem_region_size;
  2843. ap_feature->tail_pattern = AP_FEATURE_QUERY_PATTERN;
  2844. }
  2845. static int md_cd_send_runtime_data_v2(struct ccci_modem *md, unsigned int sbp_code)
  2846. {
  2847. int packet_size = sizeof(struct ap_query_md_feature) + sizeof(struct ccci_header);
  2848. struct ccci_request *req = NULL;
  2849. struct ccci_header *ccci_h;
  2850. struct ap_query_md_feature *ap_rt_data;
  2851. int ret;
  2852. req = ccci_alloc_req(OUT, packet_size, 1, 1);
  2853. if (!req)
  2854. return -CCCI_ERR_ALLOCATE_MEMORY_FAIL;
  2855. ccci_h = (struct ccci_header *)req->skb->data;
  2856. ap_rt_data = (struct ap_query_md_feature *)(req->skb->data + sizeof(struct ccci_header));
  2857. CCCI_NOTICE_MSG(md->index, KERN, "new api for sending rt data, sbp_code %u\n", sbp_code);
  2858. ccci_set_ap_region_protection(md);
  2859. /*header */
  2860. ccci_h->data[0] = 0x00;
  2861. ccci_h->data[1] = packet_size;
  2862. ccci_h->reserved = MD_INIT_CHK_ID;
  2863. ccci_h->channel = CCCI_CONTROL_TX;
  2864. memset(ap_rt_data, 0, sizeof(struct ap_query_md_feature));
  2865. config_ap_runtime_data(md, ap_rt_data);
  2866. dump_runtime_data_v2(md, ap_rt_data);
  2867. #ifdef FEATURE_DBM_SUPPORT
  2868. eccci_smem_sub_region_init(md);
  2869. #endif
  2870. skb_put(req->skb, packet_size);
  2871. ret = md->ops->send_request(md, 0, req, NULL); /*hardcode to queue 0 */
  2872. return ret;
  2873. }
  2874. static int md_cd_send_runtime_data(struct ccci_modem *md, unsigned int sbp_code)
  2875. {
  2876. int packet_size = sizeof(struct modem_runtime) + sizeof(struct ccci_header);
  2877. struct ccci_request *req = NULL;
  2878. struct ccci_header *ccci_h;
  2879. struct modem_runtime *runtime;
  2880. struct file *filp = NULL;
  2881. LOGGING_MODE mdlog_flag = MODE_IDLE;
  2882. int ret;
  2883. char str[16];
  2884. char md_logger_cfg_file[32];
  2885. unsigned int random_seed = 0;
  2886. #ifdef FEATURE_MD_GET_CLIB_TIME
  2887. struct timeval t;
  2888. #endif
  2889. if (md->runtime_version == AP_MD_HS_V2) {
  2890. ret = md_cd_send_runtime_data_v2(md, sbp_code);
  2891. return ret;
  2892. }
  2893. snprintf(str, sizeof(str), "%s", AP_PLATFORM_INFO);
  2894. req = ccci_alloc_req(OUT, packet_size, 1, 1);
  2895. if (!req)
  2896. return -CCCI_ERR_ALLOCATE_MEMORY_FAIL;
  2897. ccci_h = (struct ccci_header *)req->skb->data;
  2898. runtime = (struct modem_runtime *)(req->skb->data + sizeof(struct ccci_header));
  2899. ccci_set_ap_region_protection(md);
  2900. /* header */
  2901. ccci_h->data[0] = 0x00;
  2902. ccci_h->data[1] = packet_size;
  2903. ccci_h->reserved = MD_INIT_CHK_ID;
  2904. ccci_h->channel = CCCI_CONTROL_TX;
  2905. memset(runtime, 0, sizeof(struct modem_runtime));
  2906. /* runtime data, little endian for string */
  2907. runtime->Prefix = 0x46494343; /* "CCIF" */
  2908. runtime->Postfix = 0x46494343; /* "CCIF" */
  2909. runtime->Platform_L = *((int *)str);
  2910. runtime->Platform_H = *((int *)&str[4]);
  2911. runtime->BootChannel = CCCI_CONTROL_RX;
  2912. runtime->DriverVersion = CCCI_DRIVER_VER;
  2913. if (md->index == 0)
  2914. snprintf(md_logger_cfg_file, 32, "%s", MD1_LOGGER_FILE_PATH);
  2915. else
  2916. snprintf(md_logger_cfg_file, 32, "%s", MD2_LOGGER_FILE_PATH);
  2917. filp = filp_open(md_logger_cfg_file, O_RDONLY, 0777);
  2918. if (!IS_ERR(filp)) {
  2919. ret = kernel_read(filp, 0, (char *)&mdlog_flag, sizeof(int));
  2920. if (ret != sizeof(int))
  2921. mdlog_flag = MODE_IDLE;
  2922. } else {
  2923. CCCI_ERR_MSG(md->index, TAG, "open %s fail", md_logger_cfg_file);
  2924. filp = NULL;
  2925. }
  2926. if (filp != NULL)
  2927. filp_close(filp, NULL);
  2928. if (is_meta_mode() || is_advanced_meta_mode())
  2929. runtime->BootingStartID = ((char)mdlog_flag << 8 | META_BOOT_ID);
  2930. else
  2931. runtime->BootingStartID = ((char)mdlog_flag << 8 | NORMAL_BOOT_ID);
  2932. /* share memory layout */
  2933. runtime->ExceShareMemBase = md->mem_layout.smem_region_phy - md->mem_layout.smem_offset_AP_to_MD;
  2934. runtime->ExceShareMemSize = md->mem_layout.smem_region_size;
  2935. #ifdef FEATURE_MD1MD3_SHARE_MEM
  2936. runtime->TotalShareMemBase = md->mem_layout.smem_region_phy - md->mem_layout.smem_offset_AP_to_MD;
  2937. runtime->TotalShareMemSize = md->mem_layout.smem_region_size + md->mem_layout.md1_md3_smem_size;
  2938. runtime->MD1MD3ShareMemBase = md->mem_layout.md1_md3_smem_phy - md->mem_layout.smem_offset_AP_to_MD;
  2939. runtime->MD1MD3ShareMemSize = md->mem_layout.md1_md3_smem_size;
  2940. #else
  2941. runtime->TotalShareMemBase = md->mem_layout.smem_region_phy - md->mem_layout.smem_offset_AP_to_MD;
  2942. runtime->TotalShareMemSize = md->mem_layout.smem_region_size;
  2943. #endif
  2944. /* misc region, little endian for string */
  2945. runtime->misc_prefix = 0x4353494D; /* "MISC" */
  2946. runtime->misc_postfix = 0x4353494D; /* "MISC" */
  2947. runtime->index = 0;
  2948. runtime->next = 0;
  2949. /* 32K clock less */
  2950. #if defined(ENABLE_32K_CLK_LESS)
  2951. if (crystal_exist_status()) {
  2952. CCCI_DBG_MSG(md->index, TAG, "MISC_32K_LESS no support, crystal_exist_status 1\n");
  2953. runtime->support_mask |= (FEATURE_NOT_SUPPORT << (MISC_32K_LESS * 2));
  2954. } else {
  2955. CCCI_DBG_MSG(md->index, TAG, "MISC_32K_LESS support\n");
  2956. runtime->support_mask |= (FEATURE_SUPPORT << (MISC_32K_LESS * 2));
  2957. }
  2958. #else
  2959. CCCI_DBG_MSG(md->index, TAG, "ENABLE_32K_CLK_LESS disabled\n");
  2960. runtime->support_mask |= (FEATURE_NOT_SUPPORT << (MISC_32K_LESS * 2));
  2961. #endif
  2962. /* random seed */
  2963. get_random_bytes(&random_seed, sizeof(int));
  2964. runtime->feature_2_val[0] = random_seed;
  2965. runtime->support_mask |= (FEATURE_SUPPORT << (MISC_RAND_SEED * 2));
  2966. /* SBP + WM_ID */
  2967. if ((sbp_code > 0) || (md->config.load_type)) {
  2968. runtime->support_mask |= (FEATURE_SUPPORT << (MISC_MD_SBP_SETTING * 2));
  2969. runtime->feature_4_val[0] = sbp_code;
  2970. if (md->config.load_type < modem_ultg)
  2971. runtime->feature_4_val[1] = 0;
  2972. else
  2973. runtime->feature_4_val[1] = get_md_wm_id_map(md->config.load_type);
  2974. }
  2975. /* CCCI debug */
  2976. #if defined(FEATURE_SEQ_CHECK_EN) || defined(FEATURE_POLL_MD_EN)
  2977. runtime->support_mask |= (FEATURE_SUPPORT << (MISC_MD_SEQ_CHECK * 2));
  2978. runtime->feature_5_val[0] = 0;
  2979. #ifdef FEATURE_SEQ_CHECK_EN
  2980. runtime->feature_5_val[0] |= (1 << 0);
  2981. #endif
  2982. #ifdef FEATURE_POLL_MD_EN
  2983. runtime->feature_5_val[0] |= (1 << 1);
  2984. #endif
  2985. #endif
  2986. #ifdef FEATURE_MD_GET_CLIB_TIME
  2987. CCCI_DBG_MSG(md->index, TAG, "FEATURE_MD_GET_CLIB_TIME is on\n");
  2988. runtime->support_mask |= (FEATURE_SUPPORT << (MISC_MD_CLIB_TIME * 2));
  2989. do_gettimeofday(&t);
  2990. /* set seconds information */
  2991. runtime->feature_6_val[0] = ((unsigned int *)&t.tv_sec)[0];
  2992. runtime->feature_6_val[1] = ((unsigned int *)&t.tv_sec)[1];
  2993. runtime->feature_6_val[2] = current_time_zone; /* sys_tz.tz_minuteswest; */
  2994. runtime->feature_6_val[3] = sys_tz.tz_dsttime; /* not used for now */
  2995. #endif
  2996. #ifdef FEATURE_C2K_ALWAYS_ON
  2997. runtime->support_mask |= (FEATURE_SUPPORT << (MISC_MD_C2K_ON * 2));
  2998. runtime->feature_7_val[0] = (0
  2999. #ifdef CONFIG_MTK_C2K_SUPPORT
  3000. | (1 << 0)
  3001. #endif
  3002. #ifdef CONFIG_MTK_SVLTE_SUPPORT
  3003. | (1 << 1)
  3004. #endif
  3005. #ifdef CONFIG_MTK_SRLTE_SUPPORT
  3006. | (1 << 2)
  3007. #endif
  3008. #ifdef CONFIG_MTK_C2K_OM_SOLUTION1
  3009. | (1 << 3)
  3010. #endif
  3011. #ifdef CONFIG_CT6M_SUPPORT
  3012. | (1 << 4)
  3013. #endif
  3014. );
  3015. #endif
  3016. dump_runtime_data(md, runtime);
  3017. #ifdef FEATURE_DBM_SUPPORT
  3018. eccci_smem_sub_region_init(md);
  3019. #endif
  3020. skb_put(req->skb, packet_size);
  3021. ret = md->ops->send_request(md, 0, req, NULL); /* hardcode to queue 0 */
  3022. return ret;
  3023. }
  3024. static int md_cd_force_assert(struct ccci_modem *md, MD_COMM_TYPE type)
  3025. {
  3026. struct ccci_request *req = NULL;
  3027. struct ccci_header *ccci_h;
  3028. if (md->is_forced_assert == 1) {
  3029. CCCI_ERR_MSG(md->index, TAG, "MD has been forced assert, no need again using %d\n", type);
  3030. return 0;
  3031. }
  3032. CCCI_INF_MSG(md->index, TAG, "force assert MD using %d\n", type);
  3033. switch (type) {
  3034. case CCCI_MESSAGE:
  3035. req = ccci_alloc_req(OUT, sizeof(struct ccci_header), 1, 1);
  3036. if (req) {
  3037. req->policy = RECYCLE;
  3038. ccci_h = (struct ccci_header *)skb_put(req->skb, sizeof(struct ccci_header));
  3039. ccci_h->data[0] = 0xFFFFFFFF;
  3040. ccci_h->data[1] = 0x5A5A5A5A;
  3041. /* ccci_h->channel = CCCI_FORCE_ASSERT_CH; */
  3042. *(((u32 *) ccci_h) + 2) = CCCI_FORCE_ASSERT_CH;
  3043. ccci_h->reserved = 0xA5A5A5A5;
  3044. return md->ops->send_request(md, 0, req, NULL); /* hardcode to queue 0 */
  3045. }
  3046. return -CCCI_ERR_ALLOCATE_MEMORY_FAIL;
  3047. case CCIF_INTERRUPT:
  3048. md_cd_ccif_send(md, H2D_FORCE_MD_ASSERT);
  3049. break;
  3050. case CCIF_INTR_SEQ:
  3051. md_cd_ccif_send(md, AP_MD_SEQ_ERROR);
  3052. break;
  3053. };
  3054. md->is_forced_assert = 1;
  3055. return 0;
  3056. }
  3057. static void md_cd_dump_ccif_reg(struct ccci_modem *md)
  3058. {
  3059. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  3060. CCCI_INF_MSG(md->index, TAG, "AP_CON(%p)=%x\n", md_ctrl->ap_ccif_base + APCCIF_CON,
  3061. cldma_read32(md_ctrl->ap_ccif_base, APCCIF_CON));
  3062. CCCI_INF_MSG(md->index, TAG, "AP_BUSY(%p)=%x\n", md_ctrl->ap_ccif_base + APCCIF_BUSY,
  3063. cldma_read32(md_ctrl->ap_ccif_base, APCCIF_BUSY));
  3064. CCCI_INF_MSG(md->index, TAG, "AP_START(%p)=%x\n", md_ctrl->ap_ccif_base + APCCIF_START,
  3065. cldma_read32(md_ctrl->ap_ccif_base, APCCIF_START));
  3066. CCCI_INF_MSG(md->index, TAG, "AP_TCHNUM(%p)=%x\n", md_ctrl->ap_ccif_base + APCCIF_TCHNUM,
  3067. cldma_read32(md_ctrl->ap_ccif_base, APCCIF_TCHNUM));
  3068. CCCI_INF_MSG(md->index, TAG, "AP_RCHNUM(%p)=%x\n", md_ctrl->ap_ccif_base + APCCIF_RCHNUM,
  3069. cldma_read32(md_ctrl->ap_ccif_base, APCCIF_RCHNUM));
  3070. CCCI_INF_MSG(md->index, TAG, "AP_ACK(%p)=%x\n", md_ctrl->ap_ccif_base + APCCIF_ACK,
  3071. cldma_read32(md_ctrl->ap_ccif_base, APCCIF_ACK));
  3072. CCCI_INF_MSG(md->index, TAG, "MD_CON(%p)=%x\n", md_ctrl->md_ccif_base + APCCIF_CON,
  3073. cldma_read32(md_ctrl->md_ccif_base, APCCIF_CON));
  3074. CCCI_INF_MSG(md->index, TAG, "MD_BUSY(%p)=%x\n", md_ctrl->md_ccif_base + APCCIF_BUSY,
  3075. cldma_read32(md_ctrl->md_ccif_base, APCCIF_BUSY));
  3076. CCCI_INF_MSG(md->index, TAG, "MD_START(%p)=%x\n", md_ctrl->md_ccif_base + APCCIF_START,
  3077. cldma_read32(md_ctrl->md_ccif_base, APCCIF_START));
  3078. CCCI_INF_MSG(md->index, TAG, "MD_TCHNUM(%p)=%x\n", md_ctrl->md_ccif_base + APCCIF_TCHNUM,
  3079. cldma_read32(md_ctrl->md_ccif_base, APCCIF_TCHNUM));
  3080. CCCI_INF_MSG(md->index, TAG, "MD_RCHNUM(%p)=%x\n", md_ctrl->md_ccif_base + APCCIF_RCHNUM,
  3081. cldma_read32(md_ctrl->md_ccif_base, APCCIF_RCHNUM));
  3082. CCCI_INF_MSG(md->index, TAG, "MD_ACK(%p)=%x\n", md_ctrl->md_ccif_base + APCCIF_ACK,
  3083. cldma_read32(md_ctrl->md_ccif_base, APCCIF_ACK));
  3084. }
  3085. static int md_cd_dump_info(struct ccci_modem *md, MODEM_DUMP_FLAG flag, void *buff, int length)
  3086. {
  3087. struct md_cd_ctrl *md_ctrl = (struct md_cd_ctrl *)md->private_data;
  3088. if (flag & DUMP_FLAG_CCIF_REG) {
  3089. CCCI_INF_MSG(md->index, TAG, "Dump CCIF REG\n");
  3090. md_cd_dump_ccif_reg(md);
  3091. }
  3092. if (flag & DUMP_FLAG_CCIF) {
  3093. int i;
  3094. unsigned int *dest_buff = NULL;
  3095. unsigned char ccif_sram[CCCC_SMEM_CCIF_SRAM_SIZE] = { 0 };
  3096. int sram_size = md_ctrl->hw_info->sram_size;
  3097. if (buff)
  3098. dest_buff = (unsigned int *)buff;
  3099. else
  3100. dest_buff = (unsigned int *)ccif_sram;
  3101. if (length < sizeof(ccif_sram) && length > 0) {
  3102. CCCI_ERR_MSG(md->index, TAG, "dump CCIF SRAM length illegal %d/%zu\n", length,
  3103. sizeof(ccif_sram));
  3104. dest_buff = (unsigned int *)ccif_sram;
  3105. } else {
  3106. length = sizeof(ccif_sram);
  3107. }
  3108. for (i = 0; i < length / sizeof(unsigned int); i++) {
  3109. *(dest_buff + i) = cldma_read32(md_ctrl->ap_ccif_base,
  3110. APCCIF_CHDATA + (sram_size - length) +
  3111. i * sizeof(unsigned int));
  3112. }
  3113. CCCI_INF_MSG(md->index, TAG, "Dump CCIF SRAM (last 16bytes)\n");
  3114. ccci_mem_dump(md->index, dest_buff, length);
  3115. }
  3116. if (flag & DUMP_FLAG_CLDMA) {
  3117. cldma_dump_register(md);
  3118. if (length == -1) {
  3119. cldma_dump_packet_history(md);
  3120. cldma_dump_all_gpd(md);
  3121. }
  3122. if (length >= 0 && length < CLDMA_TXQ_NUM) {
  3123. cldma_dump_queue_history(md, length);
  3124. cldma_dump_gpd_queue(md, length);
  3125. }
  3126. }
  3127. if (flag & DUMP_FLAG_REG)
  3128. md_cd_dump_debug_register(md);
  3129. if (flag & DUMP_FLAG_SMEM) {
  3130. CCCI_INF_MSG(md->index, TAG, "Dump share memory\n");
  3131. ccci_mem_dump(md->index, md->smem_layout.ccci_exp_smem_base_vir, md->smem_layout.ccci_exp_dump_size);
  3132. }
  3133. if (flag & DUMP_FLAG_IMAGE) {
  3134. CCCI_INF_MSG(md->index, KERN, "Dump MD image memory\n");
  3135. ccci_mem_dump(md->index, (void *)md->mem_layout.md_region_vir, MD_IMG_DUMP_SIZE);
  3136. }
  3137. if (flag & DUMP_FLAG_LAYOUT) {
  3138. CCCI_INF_MSG(md->index, KERN, "Dump MD layout struct\n");
  3139. ccci_mem_dump(md->index, &md->mem_layout, sizeof(struct ccci_mem_layout));
  3140. }
  3141. if (flag & DUMP_FLAG_QUEUE_0) {
  3142. cldma_dump_register(md);
  3143. cldma_dump_queue_history(md, 0);
  3144. cldma_dump_gpd_queue(md, 0);
  3145. }
  3146. if (flag & DUMP_FLAG_QUEUE_0_1) {
  3147. cldma_dump_register(md);
  3148. cldma_dump_queue_history(md, 0);
  3149. cldma_dump_queue_history(md, 1);
  3150. cldma_dump_gpd_queue(md, 0);
  3151. cldma_dump_gpd_queue(md, 1);
  3152. }
  3153. if (flag & DUMP_FLAG_SMEM_MDSLP) {
  3154. ccci_cmpt_mem_dump(md->index, md->smem_layout.ccci_exp_smem_sleep_debug_vir,
  3155. md->smem_layout.ccci_exp_smem_sleep_debug_size);
  3156. }
  3157. if (flag & DUMP_FLAG_MD_WDT) {
  3158. CCCI_INF_MSG(md->index, KERN, "Dump MD RGU registers\n");
  3159. md_cd_lock_modem_clock_src(1);
  3160. #ifdef BASE_ADDR_MDRSTCTL
  3161. ccci_mem_dump(md->index, md_ctrl->md_rgu_base, 0x88);
  3162. ccci_mem_dump(md->index, (md_ctrl->md_rgu_base + 0x200), 0x5c);
  3163. #else
  3164. ccci_mem_dump(md->index, md_ctrl->md_rgu_base, 0x30);
  3165. #endif
  3166. md_cd_lock_modem_clock_src(0);
  3167. CCCI_INF_MSG(md->index, KERN, "wdt_enabled=%d\n", atomic_read(&md_ctrl->wdt_enabled));
  3168. mt_irq_dump_status(md_ctrl->hw_info->md_wdt_irq_id);
  3169. }
  3170. return length;
  3171. }
  3172. static int md_cd_ee_callback(struct ccci_modem *md, MODEM_EE_FLAG flag)
  3173. {
  3174. if (flag & EE_FLAG_ENABLE_WDT)
  3175. wdt_enable_irq(md);
  3176. if (flag & EE_FLAG_DISABLE_WDT)
  3177. wdt_disable_irq(md);
  3178. return 0;
  3179. }
  3180. static struct ccci_modem_ops md_cd_ops = {
  3181. .init = &md_cd_init,
  3182. .start = &md_cd_start,
  3183. .stop = &md_cd_stop,
  3184. .reset = &md_cd_reset,
  3185. .send_request = &md_cd_send_request,
  3186. .give_more = &md_cd_give_more,
  3187. .napi_poll = &md_cd_napi_poll,
  3188. .send_runtime_data = &md_cd_send_runtime_data,
  3189. .broadcast_state = &md_cd_broadcast_state,
  3190. .force_assert = &md_cd_force_assert,
  3191. .dump_info = &md_cd_dump_info,
  3192. .write_room = &md_cd_write_room,
  3193. .stop_queue = &md_cd_stop_queue,
  3194. .start_queue = &md_cd_start_queue,
  3195. .get_port_by_minor = &md_cd_get_port_by_minor,
  3196. .get_port_by_channel = &md_cd_get_port_by_channel,
  3197. /* .low_power_notify = &md_cd_low_power_notify, */
  3198. .ee_callback = &md_cd_ee_callback,
  3199. };
  3200. static ssize_t md_cd_dump_show(struct ccci_modem *md, char *buf)
  3201. {
  3202. int count = 0;
  3203. count = snprintf(buf, 256, "support: ccif cldma register smem image layout\n");
  3204. return count;
  3205. }
  3206. static ssize_t md_cd_dump_store(struct ccci_modem *md, const char *buf, size_t count)
  3207. {
  3208. /* echo will bring "xxx\n" here, so we eliminate the "\n" during comparing */
  3209. if (strncmp(buf, "ccif", count - 1) == 0)
  3210. md->ops->dump_info(md, DUMP_FLAG_CCIF_REG | DUMP_FLAG_CCIF, NULL, 0);
  3211. if (strncmp(buf, "cldma", count - 1) == 0)
  3212. md->ops->dump_info(md, DUMP_FLAG_CLDMA, NULL, -1);
  3213. if (strncmp(buf, "register", count - 1) == 0)
  3214. md->ops->dump_info(md, DUMP_FLAG_REG, NULL, 0);
  3215. if (strncmp(buf, "smem", count - 1) == 0)
  3216. md->ops->dump_info(md, DUMP_FLAG_SMEM, NULL, 0);
  3217. if (strncmp(buf, "image", count - 1) == 0)
  3218. md->ops->dump_info(md, DUMP_FLAG_IMAGE, NULL, 0);
  3219. if (strncmp(buf, "layout", count - 1) == 0)
  3220. md->ops->dump_info(md, DUMP_FLAG_LAYOUT, NULL, 0);
  3221. if (strncmp(buf, "mdslp", count - 1) == 0)
  3222. md->ops->dump_info(md, DUMP_FLAG_SMEM_MDSLP, NULL, 0);
  3223. return count;
  3224. }
  3225. static ssize_t md_cd_control_show(struct ccci_modem *md, char *buf)
  3226. {
  3227. int count = 0;
  3228. count = snprintf(buf, 256, "support: cldma_reset cldma_stop ccif_assert md_type trace_sample\n");
  3229. return count;
  3230. }
  3231. static ssize_t md_cd_control_store(struct ccci_modem *md, const char *buf, size_t count)
  3232. {
  3233. int size = 0;
  3234. if (strncmp(buf, "cldma_reset", count - 1) == 0) {
  3235. CCCI_INF_MSG(md->index, TAG, "reset CLDMA\n");
  3236. md_cd_lock_cldma_clock_src(1);
  3237. cldma_stop(md);
  3238. md_cd_clear_all_queue(md, OUT);
  3239. md_cd_clear_all_queue(md, IN);
  3240. cldma_reset(md);
  3241. cldma_start(md);
  3242. md_cd_lock_cldma_clock_src(0);
  3243. }
  3244. if (strncmp(buf, "cldma_stop", count - 1) == 0) {
  3245. CCCI_INF_MSG(md->index, TAG, "stop CLDMA\n");
  3246. md_cd_lock_cldma_clock_src(1);
  3247. cldma_stop(md);
  3248. md_cd_lock_cldma_clock_src(0);
  3249. }
  3250. if (strncmp(buf, "ccif_assert", count - 1) == 0) {
  3251. CCCI_INF_MSG(md->index, TAG, "use CCIF to force MD assert\n");
  3252. md->ops->force_assert(md, CCIF_INTERRUPT);
  3253. }
  3254. if (strncmp(buf, "ccci_trm", count - 1) == 0) {
  3255. CCCI_INF_MSG(md->index, TAG, "TRM triggered\n");
  3256. if (md->ops->reset(md) == 0)
  3257. ccci_send_virtual_md_msg(md, CCCI_MONITOR_CH, CCCI_MD_MSG_RESET, 0);
  3258. }
  3259. size = strlen("md_type=");
  3260. if (strncmp(buf, "md_type=", size) == 0) {
  3261. md->config.load_type_saving = buf[size] - '0';
  3262. CCCI_INF_MSG(md->index, TAG, "md_type_store %d\n", md->config.load_type_saving);
  3263. ccci_send_virtual_md_msg(md, CCCI_MONITOR_CH, CCCI_MD_MSG_STORE_NVRAM_MD_TYPE, 0);
  3264. }
  3265. size = strlen("trace_sample=");
  3266. if (strncmp(buf, "trace_sample=", size) == 0) {
  3267. trace_sample_time = (buf[size] - '0') * 100000000;
  3268. CCCI_INF_MSG(md->index, TAG, "trace_sample_time %u\n", trace_sample_time);
  3269. }
  3270. return count;
  3271. }
  3272. static ssize_t md_cd_filter_show(struct ccci_modem *md, char *buf)
  3273. {
  3274. int count = 0;
  3275. int i;
  3276. count += snprintf(buf + count, 128, "register port:");
  3277. for (i = 0; i < GF_PORT_LIST_MAX; i++) {
  3278. if (gf_port_list_reg[i] != 0)
  3279. count += snprintf(buf + count, 128, "%d,", gf_port_list_reg[i]);
  3280. else
  3281. break;
  3282. }
  3283. count += snprintf(buf + count, 128, "\n");
  3284. count += snprintf(buf + count, 128, "unregister port:");
  3285. for (i = 0; i < GF_PORT_LIST_MAX; i++) {
  3286. if (gf_port_list_unreg[i] != 0)
  3287. count += snprintf(buf + count, 128, "%d,", gf_port_list_unreg[i]);
  3288. else
  3289. break;
  3290. }
  3291. count += snprintf(buf + count, 128, "\n");
  3292. return count;
  3293. }
  3294. static ssize_t md_cd_filter_store(struct ccci_modem *md, const char *buf, size_t count)
  3295. {
  3296. char command[16];
  3297. int start_id = 0, end_id = 0, i, temp_valu;
  3298. temp_valu = sscanf(buf, "%s %d %d%*s", command, &start_id, &end_id);
  3299. if (temp_valu < 0)
  3300. CCCI_ERR_MSG(md->index, TAG, "sscanf retrun fail: %d\n", temp_valu);
  3301. CCCI_INF_MSG(md->index, TAG, "%s from %d to %d\n", command, start_id, end_id);
  3302. if (strncmp(command, "add", sizeof(command)) == 0) {
  3303. memset(gf_port_list_reg, 0, sizeof(gf_port_list_reg));
  3304. for (i = 0; i < GF_PORT_LIST_MAX && i <= (end_id - start_id); i++)
  3305. gf_port_list_reg[i] = start_id + i;
  3306. ccci_ipc_set_garbage_filter(md, 1);
  3307. }
  3308. if (strncmp(command, "remove", sizeof(command)) == 0) {
  3309. memset(gf_port_list_unreg, 0, sizeof(gf_port_list_unreg));
  3310. for (i = 0; i < GF_PORT_LIST_MAX && i <= (end_id - start_id); i++)
  3311. gf_port_list_unreg[i] = start_id + i;
  3312. ccci_ipc_set_garbage_filter(md, 0);
  3313. }
  3314. return count;
  3315. }
  3316. static ssize_t md_cd_parameter_show(struct ccci_modem *md, char *buf)
  3317. {
  3318. int count = 0;
  3319. count += snprintf(buf + count, 128, "CHECKSUM_SIZE=%d\n", CHECKSUM_SIZE);
  3320. count += snprintf(buf + count, 128, "PACKET_HISTORY_DEPTH=%d\n", PACKET_HISTORY_DEPTH);
  3321. count += snprintf(buf + count, 128, "BD_NUM=%ld\n", MAX_BD_NUM);
  3322. count += snprintf(buf + count, 128, "NET_buffer_number=(%d, %d)\n",
  3323. net_tx_queue_buffer_number[3], net_rx_queue_buffer_number[3]);
  3324. return count;
  3325. }
  3326. static ssize_t md_cd_parameter_store(struct ccci_modem *md, const char *buf, size_t count)
  3327. {
  3328. return count;
  3329. }
  3330. static unsigned int md_rxd_switcher;
  3331. static ssize_t md_cd_rxd_show(struct ccci_modem *md, char *buf)
  3332. {
  3333. ssize_t count = 0;
  3334. count += snprintf(buf, 128, "md_rxd=%d\n", md_rxd_switcher);
  3335. return count;
  3336. }
  3337. static ssize_t md_cd_rxd_store(struct ccci_modem *md, const char *buf, size_t count)
  3338. {
  3339. int ret;
  3340. ret = kstrtoint(buf, 10, &md_rxd_switcher);
  3341. if (ret < 0)
  3342. CCCI_ERR_MSG(md->index, TAG, "sscanf retrun fail: %d\n", ret);
  3343. return count;
  3344. }
  3345. CCCI_MD_ATTR(NULL, dump, 0660, md_cd_dump_show, md_cd_dump_store);
  3346. CCCI_MD_ATTR(NULL, control, 0660, md_cd_control_show, md_cd_control_store);
  3347. CCCI_MD_ATTR(NULL, filter, 0660, md_cd_filter_show, md_cd_filter_store);
  3348. CCCI_MD_ATTR(NULL, parameter, 0660, md_cd_parameter_show, md_cd_parameter_store);
  3349. CCCI_MD_ATTR(NULL, md_rxd, 0660, md_cd_rxd_show, md_cd_rxd_store);
  3350. static void md_cd_sysfs_init(struct ccci_modem *md)
  3351. {
  3352. int ret;
  3353. ccci_md_attr_dump.modem = md;
  3354. ret = sysfs_create_file(&md->kobj, &ccci_md_attr_dump.attr);
  3355. if (ret)
  3356. CCCI_ERR_MSG(md->index, TAG, "fail to add sysfs node %s %d\n", ccci_md_attr_dump.attr.name, ret);
  3357. ccci_md_attr_control.modem = md;
  3358. ret = sysfs_create_file(&md->kobj, &ccci_md_attr_control.attr);
  3359. if (ret)
  3360. CCCI_ERR_MSG(md->index, TAG, "fail to add sysfs node %s %d\n", ccci_md_attr_control.attr.name, ret);
  3361. ccci_md_attr_parameter.modem = md;
  3362. ret = sysfs_create_file(&md->kobj, &ccci_md_attr_parameter.attr);
  3363. if (ret)
  3364. CCCI_ERR_MSG(md->index, TAG, "fail to add sysfs node %s %d\n", ccci_md_attr_parameter.attr.name, ret);
  3365. ccci_md_attr_filter.modem = md;
  3366. ret = sysfs_create_file(&md->kobj, &ccci_md_attr_filter.attr);
  3367. if (ret)
  3368. CCCI_ERR_MSG(md->index, TAG, "fail to add sysfs node %s %d\n", ccci_md_attr_filter.attr.name, ret);
  3369. ccci_md_attr_md_rxd.modem = md;
  3370. ret = sysfs_create_file(&md->kobj, &ccci_md_attr_md_rxd.attr);
  3371. if (ret)
  3372. CCCI_ERR_MSG(md->index, TAG, "fail to add sysfs node %s %d\n", ccci_md_attr_md_rxd.attr.name, ret);
  3373. }
  3374. #ifdef ENABLE_CLDMA_AP_SIDE
  3375. static struct syscore_ops md_cldma_sysops = {
  3376. .suspend = ccci_modem_syssuspend,
  3377. .resume = ccci_modem_sysresume,
  3378. };
  3379. #endif
  3380. #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
  3381. static u64 cldma_dmamask = DMA_BIT_MASK((sizeof(unsigned long) << 3));
  3382. static int ccci_modem_probe(struct platform_device *plat_dev)
  3383. {
  3384. struct ccci_modem *md;
  3385. struct md_cd_ctrl *md_ctrl;
  3386. int md_id, i;
  3387. struct ccci_dev_cfg dev_cfg;
  3388. int ret;
  3389. int sram_size;
  3390. struct md_hw_info *md_hw;
  3391. /* Allocate modem hardware info structure memory */
  3392. md_hw = kzalloc(sizeof(struct md_hw_info), GFP_KERNEL);
  3393. if (md_hw == NULL) {
  3394. CCCI_ERR_MSG(-1, TAG, "md_cldma_probe:alloc md hw mem fail\n");
  3395. return -1;
  3396. }
  3397. ret = md_cd_get_modem_hw_info(plat_dev, &dev_cfg, md_hw);
  3398. if (ret != 0) {
  3399. CCCI_ERR_MSG(-1, TAG, "md_cldma_probe:get hw info fail(%d)\n", ret);
  3400. kfree(md_hw);
  3401. md_hw = NULL;
  3402. return -1;
  3403. }
  3404. /* Allocate md ctrl memory and do initialize */
  3405. md = ccci_allocate_modem(sizeof(struct md_cd_ctrl));
  3406. if (md == NULL) {
  3407. CCCI_ERR_MSG(-1, TAG, "md_cldma_probe:alloc modem ctrl mem fail\n");
  3408. kfree(md_hw);
  3409. md_hw = NULL;
  3410. return -1;
  3411. }
  3412. md->index = md_id = dev_cfg.index;
  3413. md->major = dev_cfg.major;
  3414. md->minor_base = dev_cfg.minor_base;
  3415. md->capability = dev_cfg.capability;
  3416. md->plat_dev = plat_dev;
  3417. md->plat_dev->dev.dma_mask = &cldma_dmamask;
  3418. md->plat_dev->dev.coherent_dma_mask = cldma_dmamask;
  3419. md->ops = &md_cd_ops;
  3420. CCCI_INF_MSG(md_id, TAG, "md_cldma_probe:md=%p,md->private_data=%p\n", md, md->private_data);
  3421. /* init modem private data */
  3422. md_ctrl = (struct md_cd_ctrl *)md->private_data;
  3423. md_ctrl->modem = md;
  3424. md_ctrl->hw_info = md_hw;
  3425. md_ctrl->txq_active = 0;
  3426. md_ctrl->rxq_active = 0;
  3427. snprintf(md_ctrl->trm_wakelock_name, sizeof(md_ctrl->trm_wakelock_name), "md%d_cldma_trm", md_id + 1);
  3428. wake_lock_init(&md_ctrl->trm_wake_lock, WAKE_LOCK_SUSPEND, md_ctrl->trm_wakelock_name);
  3429. snprintf(md_ctrl->peer_wakelock_name, sizeof(md_ctrl->peer_wakelock_name), "md%d_cldma_peer", md_id + 1);
  3430. wake_lock_init(&md_ctrl->peer_wake_lock, WAKE_LOCK_SUSPEND, md_ctrl->peer_wakelock_name);
  3431. INIT_WORK(&md_ctrl->ccif_work, md_cd_ccif_work);
  3432. tasklet_init(&md_ctrl->ccif_irq_task, md_ccif_irq_tasklet,
  3433. (unsigned long)md);
  3434. mutex_init(&md_ctrl->ccif_wdt_mutex);
  3435. init_timer(&md_ctrl->bus_timeout_timer);
  3436. md_ctrl->bus_timeout_timer.function = md_cd_ap2md_bus_timeout_timer_func;
  3437. md_ctrl->bus_timeout_timer.data = (unsigned long)md;
  3438. spin_lock_init(&md_ctrl->cldma_timeout_lock);
  3439. md_ctrl->gpd_dmapool = dma_pool_create("cldma_request_DMA", &plat_dev->dev, sizeof(struct cldma_tgpd), 16, 0);
  3440. for (i = 0; i < NET_TXQ_NUM; i++) {
  3441. INIT_LIST_HEAD(&md_ctrl->net_tx_ring[i].gpd_ring);
  3442. md_ctrl->net_tx_ring[i].length = net_tx_queue_buffer_number[net_tx_ring2queue[i]];
  3443. #ifdef CLDMA_NET_TX_BD
  3444. md_ctrl->net_tx_ring[i].type = RING_GPD_BD;
  3445. md_ctrl->net_tx_ring[i].handle_tx_request = &cldma_gpd_bd_handle_tx_request;
  3446. md_ctrl->net_tx_ring[i].handle_tx_done = &cldma_gpd_bd_tx_collect;
  3447. #else
  3448. md_ctrl->net_tx_ring[i].type = RING_GPD;
  3449. md_ctrl->net_tx_ring[i].handle_tx_request = &cldma_gpd_handle_tx_request;
  3450. md_ctrl->net_tx_ring[i].handle_tx_done = &cldma_gpd_tx_collect;
  3451. #endif
  3452. cldma_tx_ring_init(md, &md_ctrl->net_tx_ring[i]);
  3453. CCCI_DBG_MSG(md->index, TAG, "net_tx_ring %d: %p\n", i, &md_ctrl->net_tx_ring[i]);
  3454. }
  3455. for (i = 0; i < NET_RXQ_NUM; i++) {
  3456. INIT_LIST_HEAD(&md_ctrl->net_rx_ring[i].gpd_ring);
  3457. md_ctrl->net_rx_ring[i].length = net_rx_queue_buffer_number[net_rx_ring2queue[i]];
  3458. md_ctrl->net_rx_ring[i].pkt_size = net_rx_queue_buffer_size[net_rx_ring2queue[i]];
  3459. md_ctrl->net_rx_ring[i].type = RING_GPD;
  3460. md_ctrl->net_rx_ring[i].handle_rx_done = &cldma_gpd_net_rx_collect;
  3461. md_ctrl->net_rx_ring[i].handle_rx_refill = &cldma_gpd_rx_refill;
  3462. cldma_rx_ring_init(md, &md_ctrl->net_rx_ring[i]);
  3463. CCCI_DBG_MSG(md->index, TAG, "net_rx_ring %d: %p\n", i, &md_ctrl->net_rx_ring[i]);
  3464. }
  3465. for (i = 0; i < NORMAL_TXQ_NUM; i++) {
  3466. INIT_LIST_HEAD(&md_ctrl->normal_tx_ring[i].gpd_ring);
  3467. md_ctrl->normal_tx_ring[i].length = normal_tx_queue_buffer_number[normal_tx_ring2queue[i]];
  3468. #if 0
  3469. md_ctrl->normal_tx_ring[i].type = RING_GPD_BD;
  3470. md_ctrl->normal_tx_ring[i].handle_tx_request = &cldma_gpd_bd_handle_tx_request;
  3471. md_ctrl->normal_tx_ring[i].handle_tx_done = &cldma_gpd_bd_tx_collect;
  3472. #else
  3473. md_ctrl->normal_tx_ring[i].type = RING_GPD;
  3474. md_ctrl->normal_tx_ring[i].handle_tx_request = &cldma_gpd_handle_tx_request;
  3475. md_ctrl->normal_tx_ring[i].handle_tx_done = &cldma_gpd_tx_collect;
  3476. #endif
  3477. cldma_tx_ring_init(md, &md_ctrl->normal_tx_ring[i]);
  3478. CCCI_DBG_MSG(md->index, TAG, "normal_tx_ring %d: %p\n", i, &md_ctrl->normal_tx_ring[i]);
  3479. }
  3480. for (i = 0; i < NORMAL_RXQ_NUM; i++) {
  3481. INIT_LIST_HEAD(&md_ctrl->normal_rx_ring[i].gpd_ring);
  3482. md_ctrl->normal_rx_ring[i].length = normal_rx_queue_buffer_number[normal_rx_ring2queue[i]];
  3483. md_ctrl->normal_rx_ring[i].pkt_size = normal_rx_queue_buffer_size[normal_rx_ring2queue[i]];
  3484. md_ctrl->normal_rx_ring[i].type = RING_GPD;
  3485. md_ctrl->normal_rx_ring[i].handle_rx_done = &cldma_gpd_rx_collect;
  3486. md_ctrl->normal_rx_ring[i].handle_rx_refill = &cldma_gpd_rx_refill;
  3487. cldma_rx_ring_init(md, &md_ctrl->normal_rx_ring[i]);
  3488. CCCI_DBG_MSG(md->index, TAG, "normal_rx_ring %d: %p\n", i, &md_ctrl->normal_rx_ring[i]);
  3489. }
  3490. md_ctrl->cldma_irq_worker =
  3491. alloc_workqueue("md%d_cldma_worker", WQ_UNBOUND | WQ_MEM_RECLAIM | WQ_HIGHPRI, 1, md->index + 1);
  3492. INIT_WORK(&md_ctrl->cldma_irq_work, cldma_irq_work);
  3493. md_ctrl->channel_id = 0;
  3494. atomic_set(&md_ctrl->reset_on_going, 0);
  3495. /* IRQ is default enabled after request_irq, so set init 1 */
  3496. atomic_set(&md_ctrl->wdt_enabled, 1);
  3497. atomic_set(&md_ctrl->cldma_irq_enabled, 1);
  3498. atomic_set(&md_ctrl->ccif_irq_enabled, 1);
  3499. INIT_WORK(&md_ctrl->wdt_work, md_cd_wdt_work);
  3500. #if TRAFFIC_MONITOR_INTERVAL
  3501. init_timer(&md_ctrl->traffic_monitor);
  3502. md_ctrl->traffic_monitor.function = md_cd_traffic_monitor_func;
  3503. md_ctrl->traffic_monitor.data = (unsigned long)md;
  3504. #endif
  3505. /* register modem */
  3506. ccci_register_modem(md);
  3507. #ifdef ENABLE_CLDMA_AP_SIDE
  3508. /* register SYS CORE suspend resume call back */
  3509. register_syscore_ops(&md_cldma_sysops);
  3510. #endif
  3511. /* add sysfs entries */
  3512. md_cd_sysfs_init(md);
  3513. /* hook up to device */
  3514. plat_dev->dev.platform_data = md;
  3515. #ifndef FEATURE_FPGA_PORTING
  3516. /* init CCIF */
  3517. sram_size = md_ctrl->hw_info->sram_size;
  3518. cldma_write32(md_ctrl->ap_ccif_base, APCCIF_CON, 0x01); /* arbitration */
  3519. cldma_write32(md_ctrl->ap_ccif_base, APCCIF_ACK, 0xFFFF);
  3520. for (i = 0; i < sram_size / sizeof(u32); i++)
  3521. cldma_write32(md_ctrl->ap_ccif_base, APCCIF_CHDATA + i * sizeof(u32), 0);
  3522. #endif
  3523. #ifdef FEATURE_FPGA_PORTING
  3524. md_cd_clear_all_queue(md, OUT);
  3525. md_cd_clear_all_queue(md, IN);
  3526. ccci_reset_seq_num(md);
  3527. CCCI_INF_MSG(md_id, TAG, "cldma_reset\n");
  3528. cldma_reset(md);
  3529. CCCI_INF_MSG(md_id, TAG, "cldma_start\n");
  3530. cldma_start(md);
  3531. CCCI_INF_MSG(md_id, TAG, "wait md package...\n");
  3532. {
  3533. struct cldma_tgpd *md_tgpd;
  3534. struct ccci_header *md_ccci_h;
  3535. unsigned int md_tgpd_addr;
  3536. CCCI_INF_MSG(md_id, TAG, "Write md check sum\n");
  3537. cldma_write32(md_ctrl->cldma_md_pdn_base, CLDMA_AP_UL_CHECKSUM_CHANNEL_ENABLE, 0);
  3538. cldma_write32(md_ctrl->cldma_md_ao_base, CLDMA_AP_SO_CHECKSUM_CHANNEL_ENABLE, 0);
  3539. CCCI_INF_MSG(md_id, TAG, "Build md ccif_header\n");
  3540. md_ccci_h = (struct ccci_header *)md->mem_layout.md_region_vir;
  3541. memset(md_ccci_h, 0, sizeof(struct ccci_header));
  3542. md_ccci_h->reserved = MD_INIT_CHK_ID;
  3543. CCCI_INF_MSG(md_id, TAG, "Build md cldma_tgpd\n");
  3544. md_tgpd = (struct cldma_tgpd *)(md->mem_layout.md_region_vir + sizeof(struct ccci_header));
  3545. memset(md_tgpd, 0, sizeof(struct cldma_tgpd));
  3546. /* update GPD */
  3547. md_tgpd->data_buff_bd_ptr = 0;
  3548. md_tgpd->data_buff_len = sizeof(struct ccci_header);
  3549. md_tgpd->debug_id = 0;
  3550. /* checksum of GPD */
  3551. caculate_checksum((char *)md_tgpd, md_tgpd->gpd_flags | 0x1);
  3552. /* resume Tx queue */
  3553. cldma_write8(&md_tgpd->gpd_flags, 0, cldma_read8(&md_tgpd->gpd_flags, 0) | 0x1);
  3554. md_tgpd_addr = 0 + sizeof(struct ccci_header);
  3555. cldma_write32(md_ctrl->cldma_md_pdn_base, CLDMA_AP_UL_START_ADDR_0, md_tgpd_addr);
  3556. #ifdef ENABLE_CLDMA_AP_SIDE
  3557. cldma_write32(md_ctrl->cldma_md_ao_base, CLDMA_AP_UL_START_ADDR_BK_0, md_tgpd_addr);
  3558. #endif
  3559. CCCI_INF_MSG(md_id, TAG, "Start md_tgpd_addr = 0x%x\n",
  3560. cldma_read32(md_ctrl->cldma_md_pdn_base, CLDMA_AP_UL_START_ADDR_0));
  3561. cldma_write32(md_ctrl->cldma_md_pdn_base, CLDMA_AP_UL_START_CMD, CLDMA_BM_ALL_QUEUE & (1 << 0));
  3562. CCCI_INF_MSG(md_id, TAG, "Start md_tgpd_start cmd = 0x%x\n",
  3563. cldma_read32(md_ctrl->cldma_md_pdn_base, CLDMA_AP_UL_START_CMD));
  3564. CCCI_INF_MSG(md_id, TAG, "Start md cldma_tgpd done\n");
  3565. #ifdef NO_START_ON_SUSPEND_RESUME
  3566. md_ctrl->txq_started = 1;
  3567. #endif
  3568. }
  3569. #endif
  3570. return 0;
  3571. }
  3572. static const struct dev_pm_ops ccci_modem_pm_ops = {
  3573. .suspend = ccci_modem_pm_suspend,
  3574. .resume = ccci_modem_pm_resume,
  3575. .freeze = ccci_modem_pm_suspend,
  3576. .thaw = ccci_modem_pm_resume,
  3577. .poweroff = ccci_modem_pm_suspend,
  3578. .restore = ccci_modem_pm_resume,
  3579. .restore_noirq = ccci_modem_pm_restore_noirq,
  3580. };
  3581. #ifdef CONFIG_OF
  3582. static const struct of_device_id mdcldma_of_ids[] = {
  3583. {.compatible = "mediatek,mdcldma",},
  3584. {}
  3585. };
  3586. #endif
  3587. static struct platform_driver modem_cldma_driver = {
  3588. .driver = {
  3589. .name = "cldma_modem",
  3590. #ifdef CONFIG_OF
  3591. .of_match_table = mdcldma_of_ids,
  3592. #endif
  3593. #ifdef CONFIG_PM
  3594. .pm = &ccci_modem_pm_ops,
  3595. #endif
  3596. },
  3597. .probe = ccci_modem_probe,
  3598. .remove = ccci_modem_remove,
  3599. .shutdown = ccci_modem_shutdown,
  3600. .suspend = ccci_modem_suspend,
  3601. .resume = ccci_modem_resume,
  3602. };
  3603. static int __init modem_cd_init(void)
  3604. {
  3605. int ret;
  3606. #ifdef TEST_MESSAGE_FOR_BRINGUP
  3607. /* temp for bringup */
  3608. register_ccci_sys_call_back(0, TEST_MSG_ID_MD2AP, ccci_sysmsg_echo_test);
  3609. register_ccci_sys_call_back(0, TEST_MSG_ID_L1CORE_MD2AP, ccci_sysmsg_echo_test_l1core);
  3610. /* */
  3611. #endif
  3612. ret = platform_driver_register(&modem_cldma_driver);
  3613. if (ret) {
  3614. CCCI_ERR_MSG(-1, TAG, "clmda modem platform driver register fail(%d)\n", ret);
  3615. return ret;
  3616. }
  3617. return 0;
  3618. }
  3619. module_init(modem_cd_init);
  3620. MODULE_AUTHOR("Xiao Wang <xiao.wang@mediatek.com>");
  3621. MODULE_DESCRIPTION("CLDMA modem driver v0.1");
  3622. MODULE_LICENSE("GPL");