rmnet_ipa.c 127 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2014-2019, The Linux Foundation. All rights reserved.
  4. */
  5. /*
  6. * WWAN Transport Network Driver.
  7. */
  8. #include <linux/completion.h>
  9. #include <linux/errno.h>
  10. #include <linux/if_arp.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/netdevice.h>
  16. #include <linux/of_device.h>
  17. #include <linux/string.h>
  18. #include <linux/skbuff.h>
  19. #include <linux/version.h>
  20. #include <linux/workqueue.h>
  21. #include <linux/debugfs.h>
  22. #include <net/pkt_sched.h>
  23. #include <soc/qcom/subsystem_restart.h>
  24. #include <soc/qcom/subsystem_notif.h>
  25. #include "ipa_qmi_service.h"
  26. #include <linux/rmnet_ipa_fd_ioctl.h>
  27. #include <linux/ipa.h>
  28. #include <uapi/linux/msm_rmnet.h>
  29. #include <net/rmnet_config.h>
  30. #include "ipa_mhi_proxy.h"
  31. #include "ipa_trace.h"
  32. #include "ipa_odl.h"
  33. #define OUTSTANDING_HIGH_DEFAULT 256
  34. #define OUTSTANDING_HIGH_CTL_DEFAULT (OUTSTANDING_HIGH_DEFAULT + 32)
  35. #define OUTSTANDING_LOW_DEFAULT 128
  36. #define WWAN_METADATA_SHFT 24
  37. #define WWAN_METADATA_MASK 0xFF000000
  38. #define WWAN_DATA_LEN 9216
  39. #define HEADROOM_FOR_QMAP 8 /* for mux header */
  40. #define TAILROOM 0 /* for padding by mux layer */
  41. #define MAX_NUM_OF_MUX_CHANNEL 15 /* max mux channels */
  42. #define UL_FILTER_RULE_HANDLE_START 69
  43. #define IPA_WWAN_DEV_NAME "rmnet_ipa%d"
  44. #define IPA_UPSTEAM_WLAN_IFACE_NAME "wlan0"
  45. #define IPA_UPSTEAM_WLAN1_IFACE_NAME "wlan1"
  46. #define IPA_WWAN_RX_SOFTIRQ_THRESH 16
  47. #define INVALID_MUX_ID 0xFF
  48. #define IPA_QUOTA_REACH_ALERT_MAX_SIZE 64
  49. #define IPA_QUOTA_REACH_IF_NAME_MAX_SIZE 64
  50. #define IPA_UEVENT_NUM_EVNP 4 /* number of event pointers */
  51. #define IPA_NETDEV() \
  52. ((rmnet_ipa3_ctx && rmnet_ipa3_ctx->wwan_priv) ? \
  53. rmnet_ipa3_ctx->wwan_priv->net : NULL)
  54. #define IPA_WWAN_CONS_DESC_FIFO_SZ 256
  55. static void rmnet_ipa_free_msg(void *buff, u32 len, u32 type);
  56. static void rmnet_ipa_get_stats_and_update(void);
  57. static int ipa3_wwan_add_ul_flt_rule_to_ipa(void);
  58. static int ipa3_wwan_del_ul_flt_rule_to_ipa(void);
  59. static void ipa3_wwan_msg_free_cb(void*, u32, u32);
  60. static int ipa3_rmnet_poll(struct napi_struct *napi, int budget);
  61. static void ipa3_wake_tx_queue(struct work_struct *work);
  62. static DECLARE_WORK(ipa3_tx_wakequeue_work, ipa3_wake_tx_queue);
  63. static void tethering_stats_poll_queue(struct work_struct *work);
  64. static DECLARE_DELAYED_WORK(ipa_tether_stats_poll_wakequeue_work,
  65. tethering_stats_poll_queue);
  66. static int rmnet_ipa_send_coalesce_notification(uint8_t qmap_id, bool enable,
  67. bool tcp, bool udp);
  68. enum ipa3_wwan_device_status {
  69. WWAN_DEVICE_INACTIVE = 0,
  70. WWAN_DEVICE_ACTIVE = 1
  71. };
  72. struct ipa3_rmnet_plat_drv_res {
  73. bool ipa_rmnet_ssr;
  74. bool ipa_advertise_sg_support;
  75. bool ipa_napi_enable;
  76. u32 wan_rx_desc_size;
  77. };
  78. /**
  79. * struct ipa3_wwan_private - WWAN private data
  80. * @net: network interface struct implemented by this driver
  81. * @stats: iface statistics
  82. * @outstanding_pkts: number of packets sent to IPA without TX complete ACKed
  83. * @ch_id: channel id
  84. * @lock: spinlock for mutual exclusion
  85. * @device_status: holds device status
  86. *
  87. * WWAN private - holds all relevant info about WWAN driver
  88. */
  89. struct ipa3_wwan_private {
  90. struct net_device *net;
  91. struct net_device_stats stats;
  92. atomic_t outstanding_pkts;
  93. uint32_t ch_id;
  94. spinlock_t lock;
  95. struct completion resource_granted_completion;
  96. enum ipa3_wwan_device_status device_status;
  97. struct napi_struct napi;
  98. };
  99. struct rmnet_ipa_debugfs {
  100. struct dentry *dent;
  101. struct dentry *dfile_outstanding_high;
  102. struct dentry *dfile_outstanding_high_ctl;
  103. struct dentry *dfile_outstanding_low;
  104. };
  105. struct rmnet_ipa3_context {
  106. struct ipa3_wwan_private *wwan_priv;
  107. struct ipa_sys_connect_params apps_to_ipa_ep_cfg;
  108. struct ipa_sys_connect_params ipa_to_apps_ep_cfg;
  109. u32 qmap_hdr_hdl;
  110. u32 dflt_v4_wan_rt_hdl;
  111. u32 dflt_v6_wan_rt_hdl;
  112. struct ipa3_rmnet_mux_val mux_channel[MAX_NUM_OF_MUX_CHANNEL];
  113. int num_q6_rules;
  114. int old_num_q6_rules;
  115. int rmnet_index;
  116. bool egress_set;
  117. bool a7_ul_flt_set;
  118. atomic_t is_initialized;
  119. atomic_t is_ssr;
  120. void *lcl_mdm_subsys_notify_handle;
  121. void *rmt_mdm_subsys_notify_handle;
  122. u32 apps_to_ipa3_hdl;
  123. u32 ipa3_to_apps_hdl;
  124. struct mutex pipe_handle_guard;
  125. struct mutex add_mux_channel_lock;
  126. u32 pm_hdl;
  127. u32 q6_pm_hdl;
  128. u32 q6_teth_pm_hdl;
  129. struct mutex per_client_stats_guard;
  130. struct ipa_tether_device_info
  131. tether_device
  132. [IPACM_MAX_CLIENT_DEVICE_TYPES];
  133. u32 outstanding_high;
  134. u32 outstanding_high_ctl;
  135. u32 outstanding_low;
  136. struct rmnet_ipa_debugfs dbgfs;
  137. bool dl_csum_offload_enabled;
  138. atomic_t ap_suspend;
  139. bool ipa_config_is_apq;
  140. bool ipa_mhi_aggr_formet_set;
  141. };
  142. static struct rmnet_ipa3_context *rmnet_ipa3_ctx;
  143. static struct ipa3_rmnet_plat_drv_res ipa3_rmnet_res;
  144. /**
  145. * ipa3_setup_a7_qmap_hdr() - Setup default a7 qmap hdr
  146. *
  147. * Return codes:
  148. * 0: success
  149. * -ENOMEM: failed to allocate memory
  150. * -EPERM: failed to add the tables
  151. */
  152. static int ipa3_setup_a7_qmap_hdr(void)
  153. {
  154. struct ipa_ioc_add_hdr *hdr;
  155. struct ipa_hdr_add *hdr_entry;
  156. u32 pyld_sz;
  157. int ret;
  158. /* install the basic exception header */
  159. pyld_sz = sizeof(struct ipa_ioc_add_hdr) + 1 *
  160. sizeof(struct ipa_hdr_add);
  161. hdr = kzalloc(pyld_sz, GFP_KERNEL);
  162. if (!hdr)
  163. return -ENOMEM;
  164. hdr->num_hdrs = 1;
  165. hdr->commit = 1;
  166. hdr_entry = &hdr->hdr[0];
  167. strlcpy(hdr_entry->name, IPA_A7_QMAP_HDR_NAME,
  168. IPA_RESOURCE_NAME_MAX);
  169. if (ipa3_ctx->ipa_hw_type >= IPA_HW_v4_5 &&
  170. rmnet_ipa3_ctx->dl_csum_offload_enabled) {
  171. hdr_entry->hdr_len = IPA_DL_CHECKSUM_LENGTH; /* 8 bytes */
  172. /* new DL QMAP header format */
  173. hdr_entry->hdr[0] = 0x40;
  174. hdr_entry->hdr[1] = 0;
  175. hdr_entry->hdr[2] = 0;
  176. hdr_entry->hdr[3] = 0;
  177. hdr_entry->hdr[4] = 0x4;
  178. /*
  179. * Need to set csum required/valid bit on which will be replaced
  180. * by HW if checksum is incorrect after validation
  181. */
  182. hdr_entry->hdr[5] = 0x80;
  183. hdr_entry->hdr[6] = 0;
  184. hdr_entry->hdr[7] = 0;
  185. } else
  186. hdr_entry->hdr_len = IPA_QMAP_HEADER_LENGTH; /* 4 bytes */
  187. if (ipa3_add_hdr(hdr)) {
  188. IPAWANERR("fail to add IPA_A7_QMAP hdr\n");
  189. ret = -EPERM;
  190. goto bail;
  191. }
  192. if (hdr_entry->status) {
  193. IPAWANERR("fail to add IPA_A7_QMAP hdr\n");
  194. ret = -EPERM;
  195. goto bail;
  196. }
  197. rmnet_ipa3_ctx->qmap_hdr_hdl = hdr_entry->hdr_hdl;
  198. ret = 0;
  199. bail:
  200. kfree(hdr);
  201. return ret;
  202. }
  203. static void ipa3_del_a7_qmap_hdr(void)
  204. {
  205. struct ipa_ioc_del_hdr *del_hdr;
  206. struct ipa_hdr_del *hdl_entry;
  207. u32 pyld_sz;
  208. int ret;
  209. pyld_sz = sizeof(struct ipa_ioc_del_hdr) + 1 *
  210. sizeof(struct ipa_hdr_del);
  211. del_hdr = kzalloc(pyld_sz, GFP_KERNEL);
  212. if (!del_hdr) {
  213. IPAWANERR("fail to alloc exception hdr_del\n");
  214. return;
  215. }
  216. del_hdr->commit = 1;
  217. del_hdr->num_hdls = 1;
  218. hdl_entry = &del_hdr->hdl[0];
  219. hdl_entry->hdl = rmnet_ipa3_ctx->qmap_hdr_hdl;
  220. ret = ipa3_del_hdr(del_hdr);
  221. if (ret || hdl_entry->status)
  222. IPAWANERR("ipa3_del_hdr failed\n");
  223. else
  224. IPAWANDBG("hdrs deletion done\n");
  225. rmnet_ipa3_ctx->qmap_hdr_hdl = 0;
  226. kfree(del_hdr);
  227. }
  228. static void ipa3_del_qmap_hdr(uint32_t hdr_hdl)
  229. {
  230. struct ipa_ioc_del_hdr *del_hdr;
  231. struct ipa_hdr_del *hdl_entry;
  232. u32 pyld_sz;
  233. int ret;
  234. if (hdr_hdl == 0) {
  235. IPAWANERR("Invalid hdr_hdl provided\n");
  236. return;
  237. }
  238. pyld_sz = sizeof(struct ipa_ioc_del_hdr) + 1 *
  239. sizeof(struct ipa_hdr_del);
  240. del_hdr = kzalloc(pyld_sz, GFP_KERNEL);
  241. if (!del_hdr) {
  242. IPAWANERR("fail to alloc exception hdr_del\n");
  243. return;
  244. }
  245. del_hdr->commit = 1;
  246. del_hdr->num_hdls = 1;
  247. hdl_entry = &del_hdr->hdl[0];
  248. hdl_entry->hdl = hdr_hdl;
  249. ret = ipa3_del_hdr(del_hdr);
  250. if (ret || hdl_entry->status)
  251. IPAWANERR("ipa3_del_hdr failed\n");
  252. else
  253. IPAWANDBG("header deletion done\n");
  254. rmnet_ipa3_ctx->qmap_hdr_hdl = 0;
  255. kfree(del_hdr);
  256. }
  257. static void ipa3_del_mux_qmap_hdrs(void)
  258. {
  259. int index;
  260. for (index = 0; index < rmnet_ipa3_ctx->rmnet_index; index++) {
  261. ipa3_del_qmap_hdr(rmnet_ipa3_ctx->mux_channel[index].hdr_hdl);
  262. rmnet_ipa3_ctx->mux_channel[index].hdr_hdl = 0;
  263. }
  264. }
  265. static int ipa3_add_qmap_hdr(uint32_t mux_id, uint32_t *hdr_hdl)
  266. {
  267. struct ipa_ioc_add_hdr *hdr;
  268. struct ipa_hdr_add *hdr_entry;
  269. char hdr_name[IPA_RESOURCE_NAME_MAX];
  270. u32 pyld_sz;
  271. int ret;
  272. pyld_sz = sizeof(struct ipa_ioc_add_hdr) + 1 *
  273. sizeof(struct ipa_hdr_add);
  274. hdr = kzalloc(pyld_sz, GFP_KERNEL);
  275. if (!hdr)
  276. return -ENOMEM;
  277. hdr->num_hdrs = 1;
  278. hdr->commit = 1;
  279. hdr_entry = &hdr->hdr[0];
  280. snprintf(hdr_name, IPA_RESOURCE_NAME_MAX, "%s%d",
  281. A2_MUX_HDR_NAME_V4_PREF,
  282. mux_id);
  283. strlcpy(hdr_entry->name, hdr_name,
  284. IPA_RESOURCE_NAME_MAX);
  285. if (rmnet_ipa3_ctx->dl_csum_offload_enabled) {
  286. if (rmnet_ipa3_ctx->ipa_config_is_apq ||
  287. ipa3_ctx->ipa_hw_type >= IPA_HW_v4_5) {
  288. hdr_entry->hdr_len =
  289. IPA_DL_CHECKSUM_LENGTH; /* 8 bytes */
  290. /* new DL QMAP header format */
  291. hdr_entry->hdr[0] = 0x40;
  292. hdr_entry->hdr[1] = (uint8_t) mux_id;
  293. hdr_entry->hdr[2] = 0;
  294. hdr_entry->hdr[3] = 0;
  295. hdr_entry->hdr[4] = 0x4;
  296. /*
  297. * Need to set csum required/valid bit on
  298. * which will be replaced by HW if checksum
  299. * is incorrect after validation
  300. */
  301. hdr_entry->hdr[5] = 0x80;
  302. hdr_entry->hdr[6] = 0;
  303. hdr_entry->hdr[7] = 0;
  304. } else {
  305. hdr_entry->hdr_len =
  306. IPA_QMAP_HEADER_LENGTH; /* 4 bytes */
  307. hdr_entry->hdr[1] = (uint8_t) mux_id;
  308. }
  309. } else {
  310. hdr_entry->hdr_len = IPA_QMAP_HEADER_LENGTH; /* 4 bytes */
  311. hdr_entry->hdr[1] = (uint8_t) mux_id;
  312. }
  313. IPAWANDBG("header (%s) with mux-id: (%d)\n",
  314. hdr_name,
  315. hdr_entry->hdr[1]);
  316. if (ipa3_add_hdr(hdr)) {
  317. IPAWANERR("fail to add IPA_QMAP hdr\n");
  318. ret = -EPERM;
  319. goto bail;
  320. }
  321. if (hdr_entry->status) {
  322. IPAWANERR("fail to add IPA_QMAP hdr\n");
  323. ret = -EPERM;
  324. goto bail;
  325. }
  326. ret = 0;
  327. *hdr_hdl = hdr_entry->hdr_hdl;
  328. bail:
  329. kfree(hdr);
  330. return ret;
  331. }
  332. /**
  333. * ipa3_setup_dflt_wan_rt_tables() - Setup default wan routing tables
  334. *
  335. * Return codes:
  336. * 0: success
  337. * -ENOMEM: failed to allocate memory
  338. * -EPERM: failed to add the tables
  339. */
  340. static int ipa3_setup_dflt_wan_rt_tables(void)
  341. {
  342. struct ipa_ioc_add_rt_rule *rt_rule;
  343. struct ipa_rt_rule_add *rt_rule_entry;
  344. rt_rule =
  345. kzalloc(sizeof(struct ipa_ioc_add_rt_rule) + 1 *
  346. sizeof(struct ipa_rt_rule_add), GFP_KERNEL);
  347. if (!rt_rule)
  348. return -ENOMEM;
  349. /* setup a default v4 route to point to Apps */
  350. rt_rule->num_rules = 1;
  351. rt_rule->commit = 1;
  352. rt_rule->ip = IPA_IP_v4;
  353. strlcpy(rt_rule->rt_tbl_name, IPA_DFLT_WAN_RT_TBL_NAME,
  354. IPA_RESOURCE_NAME_MAX);
  355. rt_rule_entry = &rt_rule->rules[0];
  356. rt_rule_entry->at_rear = 1;
  357. rt_rule_entry->rule.dst = IPA_CLIENT_APPS_WAN_CONS;
  358. rt_rule_entry->rule.hdr_hdl = rmnet_ipa3_ctx->qmap_hdr_hdl;
  359. if (ipa3_add_rt_rule(rt_rule)) {
  360. IPAWANERR("fail to add dflt_wan v4 rule\n");
  361. kfree(rt_rule);
  362. return -EPERM;
  363. }
  364. IPAWANDBG("dflt v4 rt rule hdl=%x\n", rt_rule_entry->rt_rule_hdl);
  365. rmnet_ipa3_ctx->dflt_v4_wan_rt_hdl = rt_rule_entry->rt_rule_hdl;
  366. /* setup a default v6 route to point to A5 */
  367. rt_rule->ip = IPA_IP_v6;
  368. if (ipa3_add_rt_rule(rt_rule)) {
  369. IPAWANERR("fail to add dflt_wan v6 rule\n");
  370. kfree(rt_rule);
  371. return -EPERM;
  372. }
  373. IPAWANDBG("dflt v6 rt rule hdl=%x\n", rt_rule_entry->rt_rule_hdl);
  374. rmnet_ipa3_ctx->dflt_v6_wan_rt_hdl = rt_rule_entry->rt_rule_hdl;
  375. kfree(rt_rule);
  376. return 0;
  377. }
  378. static void ipa3_del_dflt_wan_rt_tables(void)
  379. {
  380. struct ipa_ioc_del_rt_rule *rt_rule;
  381. struct ipa_rt_rule_del *rt_rule_entry;
  382. int len;
  383. len = sizeof(struct ipa_ioc_del_rt_rule) + 1 *
  384. sizeof(struct ipa_rt_rule_del);
  385. rt_rule = kzalloc(len, GFP_KERNEL);
  386. if (!rt_rule)
  387. return;
  388. memset(rt_rule, 0, len);
  389. rt_rule->commit = 1;
  390. rt_rule->num_hdls = 1;
  391. rt_rule->ip = IPA_IP_v4;
  392. rt_rule_entry = &rt_rule->hdl[0];
  393. rt_rule_entry->status = -1;
  394. rt_rule_entry->hdl = rmnet_ipa3_ctx->dflt_v4_wan_rt_hdl;
  395. IPAWANERR("Deleting Route hdl:(0x%x) with ip type: %d\n",
  396. rt_rule_entry->hdl, IPA_IP_v4);
  397. if (ipa3_del_rt_rule(rt_rule) ||
  398. (rt_rule_entry->status)) {
  399. IPAWANERR("Routing rule deletion failed\n");
  400. }
  401. rt_rule->ip = IPA_IP_v6;
  402. rt_rule_entry->hdl = rmnet_ipa3_ctx->dflt_v6_wan_rt_hdl;
  403. IPAWANERR("Deleting Route hdl:(0x%x) with ip type: %d\n",
  404. rt_rule_entry->hdl, IPA_IP_v6);
  405. if (ipa3_del_rt_rule(rt_rule) ||
  406. (rt_rule_entry->status)) {
  407. IPAWANERR("Routing rule deletion failed\n");
  408. }
  409. kfree(rt_rule);
  410. }
  411. static void ipa3_copy_qmi_flt_rule_ex(
  412. struct ipa_ioc_ext_intf_prop *q6_ul_flt_rule_ptr,
  413. void *flt_spec_ptr_void)
  414. {
  415. int j;
  416. struct ipa_filter_spec_ex_type_v01 *flt_spec_ptr;
  417. struct ipa_ipfltr_range_eq_16 *q6_ul_filter_nat_ptr;
  418. struct ipa_ipfltr_range_eq_16_type_v01 *filter_spec_nat_ptr;
  419. /*
  420. * pure_ack and tos has the same size and type and we will treat tos
  421. * field as pure_ack in ipa4.5 version
  422. */
  423. flt_spec_ptr = (struct ipa_filter_spec_ex_type_v01 *) flt_spec_ptr_void;
  424. q6_ul_flt_rule_ptr->ip = flt_spec_ptr->ip_type;
  425. q6_ul_flt_rule_ptr->action = flt_spec_ptr->filter_action;
  426. if (flt_spec_ptr->is_routing_table_index_valid == true)
  427. q6_ul_flt_rule_ptr->rt_tbl_idx =
  428. flt_spec_ptr->route_table_index;
  429. if (flt_spec_ptr->is_mux_id_valid == true)
  430. q6_ul_flt_rule_ptr->mux_id =
  431. flt_spec_ptr->mux_id;
  432. q6_ul_flt_rule_ptr->rule_id =
  433. flt_spec_ptr->rule_id;
  434. q6_ul_flt_rule_ptr->is_rule_hashable =
  435. flt_spec_ptr->is_rule_hashable;
  436. q6_ul_flt_rule_ptr->eq_attrib.rule_eq_bitmap =
  437. flt_spec_ptr->filter_rule.rule_eq_bitmap;
  438. q6_ul_flt_rule_ptr->eq_attrib.tos_eq_present =
  439. flt_spec_ptr->filter_rule.tos_eq_present;
  440. q6_ul_flt_rule_ptr->eq_attrib.tos_eq =
  441. flt_spec_ptr->filter_rule.tos_eq;
  442. q6_ul_flt_rule_ptr->eq_attrib.protocol_eq_present =
  443. flt_spec_ptr->filter_rule.protocol_eq_present;
  444. q6_ul_flt_rule_ptr->eq_attrib.protocol_eq =
  445. flt_spec_ptr->filter_rule.protocol_eq;
  446. q6_ul_flt_rule_ptr->eq_attrib.num_ihl_offset_range_16 =
  447. flt_spec_ptr->filter_rule.num_ihl_offset_range_16;
  448. for (j = 0;
  449. j < q6_ul_flt_rule_ptr->eq_attrib.num_ihl_offset_range_16;
  450. j++) {
  451. q6_ul_filter_nat_ptr =
  452. &q6_ul_flt_rule_ptr->eq_attrib.ihl_offset_range_16[j];
  453. filter_spec_nat_ptr =
  454. &flt_spec_ptr->filter_rule.ihl_offset_range_16[j];
  455. q6_ul_filter_nat_ptr->offset =
  456. filter_spec_nat_ptr->offset;
  457. q6_ul_filter_nat_ptr->range_low =
  458. filter_spec_nat_ptr->range_low;
  459. q6_ul_filter_nat_ptr->range_high =
  460. filter_spec_nat_ptr->range_high;
  461. }
  462. q6_ul_flt_rule_ptr->eq_attrib.num_offset_meq_32 =
  463. flt_spec_ptr->filter_rule.num_offset_meq_32;
  464. for (j = 0;
  465. j < q6_ul_flt_rule_ptr->eq_attrib.num_offset_meq_32;
  466. j++) {
  467. q6_ul_flt_rule_ptr->eq_attrib.offset_meq_32[j].offset =
  468. flt_spec_ptr->filter_rule.offset_meq_32[j].offset;
  469. q6_ul_flt_rule_ptr->eq_attrib.offset_meq_32[j].mask =
  470. flt_spec_ptr->filter_rule.offset_meq_32[j].mask;
  471. q6_ul_flt_rule_ptr->eq_attrib.offset_meq_32[j].value =
  472. flt_spec_ptr->filter_rule.offset_meq_32[j].value;
  473. }
  474. q6_ul_flt_rule_ptr->eq_attrib.tc_eq_present =
  475. flt_spec_ptr->filter_rule.tc_eq_present;
  476. q6_ul_flt_rule_ptr->eq_attrib.tc_eq =
  477. flt_spec_ptr->filter_rule.tc_eq;
  478. q6_ul_flt_rule_ptr->eq_attrib.fl_eq_present =
  479. flt_spec_ptr->filter_rule.flow_eq_present;
  480. q6_ul_flt_rule_ptr->eq_attrib.fl_eq =
  481. flt_spec_ptr->filter_rule.flow_eq;
  482. q6_ul_flt_rule_ptr->eq_attrib.ihl_offset_eq_16_present =
  483. flt_spec_ptr->filter_rule.ihl_offset_eq_16_present;
  484. q6_ul_flt_rule_ptr->eq_attrib.ihl_offset_eq_16.offset =
  485. flt_spec_ptr->filter_rule.ihl_offset_eq_16.offset;
  486. q6_ul_flt_rule_ptr->eq_attrib.ihl_offset_eq_16.value =
  487. flt_spec_ptr->filter_rule.ihl_offset_eq_16.value;
  488. q6_ul_flt_rule_ptr->eq_attrib.ihl_offset_eq_32_present =
  489. flt_spec_ptr->filter_rule.ihl_offset_eq_32_present;
  490. q6_ul_flt_rule_ptr->eq_attrib.ihl_offset_eq_32.offset =
  491. flt_spec_ptr->filter_rule.ihl_offset_eq_32.offset;
  492. q6_ul_flt_rule_ptr->eq_attrib.ihl_offset_eq_32.value =
  493. flt_spec_ptr->filter_rule.ihl_offset_eq_32.value;
  494. q6_ul_flt_rule_ptr->eq_attrib.num_ihl_offset_meq_32 =
  495. flt_spec_ptr->filter_rule.num_ihl_offset_meq_32;
  496. for (j = 0;
  497. j < q6_ul_flt_rule_ptr->eq_attrib.num_ihl_offset_meq_32;
  498. j++) {
  499. q6_ul_flt_rule_ptr->eq_attrib.ihl_offset_meq_32[j].offset =
  500. flt_spec_ptr->filter_rule.ihl_offset_meq_32[j].offset;
  501. q6_ul_flt_rule_ptr->eq_attrib.ihl_offset_meq_32[j].mask =
  502. flt_spec_ptr->filter_rule.ihl_offset_meq_32[j].mask;
  503. q6_ul_flt_rule_ptr->eq_attrib.ihl_offset_meq_32[j].value =
  504. flt_spec_ptr->filter_rule.ihl_offset_meq_32[j].value;
  505. }
  506. q6_ul_flt_rule_ptr->eq_attrib.num_offset_meq_128 =
  507. flt_spec_ptr->filter_rule.num_offset_meq_128;
  508. for (j = 0;
  509. j < q6_ul_flt_rule_ptr->eq_attrib.num_offset_meq_128;
  510. j++) {
  511. q6_ul_flt_rule_ptr->eq_attrib.offset_meq_128[j].offset =
  512. flt_spec_ptr->filter_rule.offset_meq_128[j].offset;
  513. memcpy(q6_ul_flt_rule_ptr->eq_attrib.offset_meq_128[j].mask,
  514. flt_spec_ptr->filter_rule.offset_meq_128[j].mask, 16);
  515. memcpy(q6_ul_flt_rule_ptr->eq_attrib.offset_meq_128[j].value,
  516. flt_spec_ptr->filter_rule.offset_meq_128[j].value, 16);
  517. }
  518. q6_ul_flt_rule_ptr->eq_attrib.metadata_meq32_present =
  519. flt_spec_ptr->filter_rule.metadata_meq32_present;
  520. q6_ul_flt_rule_ptr->eq_attrib.metadata_meq32.offset =
  521. flt_spec_ptr->filter_rule.metadata_meq32.offset;
  522. q6_ul_flt_rule_ptr->eq_attrib.metadata_meq32.mask =
  523. flt_spec_ptr->filter_rule.metadata_meq32.mask;
  524. q6_ul_flt_rule_ptr->eq_attrib.metadata_meq32.value =
  525. flt_spec_ptr->filter_rule.metadata_meq32.value;
  526. q6_ul_flt_rule_ptr->eq_attrib.ipv4_frag_eq_present =
  527. flt_spec_ptr->filter_rule.ipv4_frag_eq_present;
  528. }
  529. int ipa3_copy_ul_filter_rule_to_ipa(struct ipa_install_fltr_rule_req_msg_v01
  530. *rule_req)
  531. {
  532. int i;
  533. /* prevent multi-threads accessing rmnet_ipa3_ctx->num_q6_rules */
  534. mutex_lock(&rmnet_ipa3_ctx->add_mux_channel_lock);
  535. if (rule_req->filter_spec_ex_list_valid == true &&
  536. rule_req->filter_spec_ex2_list_valid == false) {
  537. rmnet_ipa3_ctx->num_q6_rules =
  538. rule_req->filter_spec_ex_list_len;
  539. IPAWANDBG("Received (%d) install_flt_req_ex_list\n",
  540. rmnet_ipa3_ctx->num_q6_rules);
  541. } else if (rule_req->filter_spec_ex2_list_valid == true &&
  542. rule_req->filter_spec_ex_list_valid == false) {
  543. rmnet_ipa3_ctx->num_q6_rules =
  544. rule_req->filter_spec_ex2_list_len;
  545. IPAWANDBG("Received (%d) install_flt_req_ex2_list\n",
  546. rmnet_ipa3_ctx->num_q6_rules);
  547. } else {
  548. rmnet_ipa3_ctx->num_q6_rules = 0;
  549. if (rule_req->filter_spec_ex2_list_valid == true)
  550. IPAWANERR(
  551. "both ex and ex2 flt rules are set to valid\n");
  552. else
  553. IPAWANERR("got no UL rules from modem\n");
  554. mutex_unlock(
  555. &rmnet_ipa3_ctx->add_mux_channel_lock);
  556. return -EINVAL;
  557. }
  558. /* copy UL filter rules from Modem*/
  559. for (i = 0; i < rmnet_ipa3_ctx->num_q6_rules; i++) {
  560. /* check if rules overside the cache*/
  561. if (i == MAX_NUM_Q6_RULE) {
  562. IPAWANERR("Reaching (%d) max cache ",
  563. MAX_NUM_Q6_RULE);
  564. IPAWANERR(" however total (%d)\n",
  565. rmnet_ipa3_ctx->num_q6_rules);
  566. goto failure;
  567. }
  568. if (rule_req->filter_spec_ex_list_valid == true)
  569. ipa3_copy_qmi_flt_rule_ex(
  570. &ipa3_qmi_ctx->q6_ul_filter_rule[i],
  571. &rule_req->filter_spec_ex_list[i]);
  572. else if (rule_req->filter_spec_ex2_list_valid == true)
  573. ipa3_copy_qmi_flt_rule_ex(
  574. &ipa3_qmi_ctx->q6_ul_filter_rule[i],
  575. &rule_req->filter_spec_ex2_list[i]);
  576. }
  577. if (rule_req->xlat_filter_indices_list_valid) {
  578. if (rule_req->xlat_filter_indices_list_len >
  579. rmnet_ipa3_ctx->num_q6_rules) {
  580. IPAWANERR("Number of xlat indices is not valid: %d\n",
  581. rule_req->xlat_filter_indices_list_len);
  582. goto failure;
  583. }
  584. IPAWANDBG("Receive %d XLAT indices: ",
  585. rule_req->xlat_filter_indices_list_len);
  586. for (i = 0; i < rule_req->xlat_filter_indices_list_len; i++)
  587. IPAWANDBG("%d ", rule_req->xlat_filter_indices_list[i]);
  588. IPAWANDBG("\n");
  589. for (i = 0; i < rule_req->xlat_filter_indices_list_len; i++) {
  590. if (rule_req->xlat_filter_indices_list[i]
  591. >= rmnet_ipa3_ctx->num_q6_rules) {
  592. IPAWANERR("Xlat rule idx is wrong: %d\n",
  593. rule_req->xlat_filter_indices_list[i]);
  594. goto failure;
  595. } else {
  596. ipa3_qmi_ctx->q6_ul_filter_rule
  597. [rule_req->xlat_filter_indices_list[i]]
  598. .is_xlat_rule = 1;
  599. IPAWANDBG("Rule %d is xlat rule\n",
  600. rule_req->xlat_filter_indices_list[i]);
  601. }
  602. }
  603. }
  604. if (rule_req->ul_firewall_indices_list_valid) {
  605. IPAWANDBG("Receive ul_firewall_indices_list_len = (%d)",
  606. rule_req->ul_firewall_indices_list_len);
  607. if (rule_req->ul_firewall_indices_list_len >
  608. rmnet_ipa3_ctx->num_q6_rules) {
  609. IPAWANERR("UL rule indices are not valid: (%d/%d)\n",
  610. rule_req->xlat_filter_indices_list_len,
  611. rmnet_ipa3_ctx->num_q6_rules);
  612. goto failure;
  613. }
  614. ipa3_qmi_ctx->ul_firewall_indices_list_valid = 1;
  615. ipa3_qmi_ctx->ul_firewall_indices_list_len =
  616. rule_req->ul_firewall_indices_list_len;
  617. for (i = 0; i < rule_req->ul_firewall_indices_list_len; i++) {
  618. ipa3_qmi_ctx->ul_firewall_indices_list[i] =
  619. rule_req->ul_firewall_indices_list[i];
  620. }
  621. for (i = 0; i < rule_req->ul_firewall_indices_list_len; i++) {
  622. if (rule_req->ul_firewall_indices_list[i]
  623. >= rmnet_ipa3_ctx->num_q6_rules) {
  624. IPAWANERR("UL rule idx is wrong: %d\n",
  625. rule_req->ul_firewall_indices_list[i]);
  626. goto failure;
  627. } else {
  628. ipa3_qmi_ctx->q6_ul_filter_rule
  629. [rule_req->ul_firewall_indices_list[i]]
  630. .replicate_needed = 1;
  631. }
  632. }
  633. }
  634. goto success;
  635. failure:
  636. rmnet_ipa3_ctx->num_q6_rules = 0;
  637. memset(ipa3_qmi_ctx->q6_ul_filter_rule, 0,
  638. sizeof(ipa3_qmi_ctx->q6_ul_filter_rule));
  639. mutex_unlock(
  640. &rmnet_ipa3_ctx->add_mux_channel_lock);
  641. return -EINVAL;
  642. success:
  643. mutex_unlock(
  644. &rmnet_ipa3_ctx->add_mux_channel_lock);
  645. return 0;
  646. }
  647. static int ipa3_wwan_add_ul_flt_rule_to_ipa(void)
  648. {
  649. u32 pyld_sz;
  650. int i, retval = 0;
  651. struct ipa_ioc_add_flt_rule *param;
  652. struct ipa_flt_rule_add flt_rule_entry;
  653. struct ipa_fltr_installed_notif_req_msg_v01 *req;
  654. pyld_sz = sizeof(struct ipa_ioc_add_flt_rule) +
  655. sizeof(struct ipa_flt_rule_add);
  656. param = kzalloc(pyld_sz, GFP_KERNEL);
  657. if (!param)
  658. return -ENOMEM;
  659. req = kzalloc(sizeof(struct ipa_fltr_installed_notif_req_msg_v01),
  660. GFP_KERNEL);
  661. if (!req) {
  662. kfree(param);
  663. return -ENOMEM;
  664. }
  665. param->commit = 1;
  666. param->ep = IPA_CLIENT_APPS_WAN_PROD;
  667. param->global = false;
  668. param->num_rules = (uint8_t)1;
  669. memset(req, 0, sizeof(struct ipa_fltr_installed_notif_req_msg_v01));
  670. for (i = 0; i < rmnet_ipa3_ctx->num_q6_rules; i++) {
  671. param->ip = ipa3_qmi_ctx->q6_ul_filter_rule[i].ip;
  672. memset(&flt_rule_entry, 0, sizeof(struct ipa_flt_rule_add));
  673. flt_rule_entry.at_rear = true;
  674. flt_rule_entry.rule.action =
  675. ipa3_qmi_ctx->q6_ul_filter_rule[i].action;
  676. flt_rule_entry.rule.rt_tbl_idx
  677. = ipa3_qmi_ctx->q6_ul_filter_rule[i].rt_tbl_idx;
  678. flt_rule_entry.rule.retain_hdr = true;
  679. flt_rule_entry.rule.hashable =
  680. ipa3_qmi_ctx->q6_ul_filter_rule[i].is_rule_hashable;
  681. flt_rule_entry.rule.rule_id =
  682. ipa3_qmi_ctx->q6_ul_filter_rule[i].rule_id;
  683. /* debug rt-hdl*/
  684. IPAWANDBG("install-IPA index(%d),rt-tbl:(%d)\n",
  685. i, flt_rule_entry.rule.rt_tbl_idx);
  686. flt_rule_entry.rule.eq_attrib_type = true;
  687. memcpy(&(flt_rule_entry.rule.eq_attrib),
  688. &ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib,
  689. sizeof(struct ipa_ipfltri_rule_eq));
  690. memcpy(&(param->rules[0]), &flt_rule_entry,
  691. sizeof(struct ipa_flt_rule_add));
  692. if (ipa3_add_flt_rule((struct ipa_ioc_add_flt_rule *)param)) {
  693. retval = -EFAULT;
  694. IPAWANERR("add A7 UL filter rule(%d) failed\n", i);
  695. } else {
  696. /* store the rule handler */
  697. ipa3_qmi_ctx->q6_ul_filter_rule_hdl[i] =
  698. param->rules[0].flt_rule_hdl;
  699. }
  700. }
  701. /* send ipa_fltr_installed_notif_req_msg_v01 to Q6*/
  702. req->source_pipe_index =
  703. ipa3_get_ep_mapping(IPA_CLIENT_APPS_WAN_PROD);
  704. if (req->source_pipe_index == IPA_EP_NOT_ALLOCATED) {
  705. IPAWANERR("ep mapping failed\n");
  706. retval = -EFAULT;
  707. }
  708. req->install_status = QMI_RESULT_SUCCESS_V01;
  709. req->rule_id_valid = 1;
  710. req->rule_id_len = rmnet_ipa3_ctx->num_q6_rules;
  711. for (i = 0; i < rmnet_ipa3_ctx->num_q6_rules; i++) {
  712. req->rule_id[i] =
  713. ipa3_qmi_ctx->q6_ul_filter_rule[i].rule_id;
  714. }
  715. if (ipa3_qmi_filter_notify_send(req)) {
  716. IPAWANDBG("add filter rule index on A7-RX failed\n");
  717. retval = -EFAULT;
  718. }
  719. rmnet_ipa3_ctx->old_num_q6_rules = rmnet_ipa3_ctx->num_q6_rules;
  720. IPAWANDBG("add (%d) filter rule index on A7-RX\n",
  721. rmnet_ipa3_ctx->old_num_q6_rules);
  722. kfree(param);
  723. kfree(req);
  724. return retval;
  725. }
  726. static int ipa3_wwan_del_ul_flt_rule_to_ipa(void)
  727. {
  728. u32 pyld_sz;
  729. int i, retval = 0;
  730. struct ipa_ioc_del_flt_rule *param;
  731. struct ipa_flt_rule_del flt_rule_entry;
  732. pyld_sz = sizeof(struct ipa_ioc_del_flt_rule) +
  733. sizeof(struct ipa_flt_rule_del);
  734. param = kzalloc(pyld_sz, GFP_KERNEL);
  735. if (!param)
  736. return -ENOMEM;
  737. param->commit = 1;
  738. param->num_hdls = (uint8_t) 1;
  739. for (i = 0; i < rmnet_ipa3_ctx->old_num_q6_rules; i++) {
  740. param->ip = ipa3_qmi_ctx->q6_ul_filter_rule[i].ip;
  741. memset(&flt_rule_entry, 0, sizeof(struct ipa_flt_rule_del));
  742. flt_rule_entry.hdl = ipa3_qmi_ctx->q6_ul_filter_rule_hdl[i];
  743. /* debug rt-hdl*/
  744. IPAWANDBG("delete-IPA rule index(%d)\n", i);
  745. memcpy(&(param->hdl[0]), &flt_rule_entry,
  746. sizeof(struct ipa_flt_rule_del));
  747. if (ipa3_del_flt_rule((struct ipa_ioc_del_flt_rule *)param)) {
  748. IPAWANERR("del A7 UL filter rule(%d) failed\n", i);
  749. kfree(param);
  750. return -EFAULT;
  751. }
  752. }
  753. /* set UL filter-rule add-indication */
  754. rmnet_ipa3_ctx->a7_ul_flt_set = false;
  755. rmnet_ipa3_ctx->old_num_q6_rules = 0;
  756. kfree(param);
  757. return retval;
  758. }
  759. static int ipa3_find_mux_channel_index(uint32_t mux_id)
  760. {
  761. int i;
  762. for (i = 0; i < MAX_NUM_OF_MUX_CHANNEL; i++) {
  763. if (mux_id == rmnet_ipa3_ctx->mux_channel[i].mux_id)
  764. return i;
  765. }
  766. return MAX_NUM_OF_MUX_CHANNEL;
  767. }
  768. static int find_vchannel_name_index(const char *vchannel_name)
  769. {
  770. int i;
  771. for (i = 0; i < rmnet_ipa3_ctx->rmnet_index; i++) {
  772. if (strcmp(rmnet_ipa3_ctx->mux_channel[i].vchannel_name,
  773. vchannel_name) == 0)
  774. return i;
  775. }
  776. return MAX_NUM_OF_MUX_CHANNEL;
  777. }
  778. static enum ipa_upstream_type find_upstream_type(const char *upstreamIface)
  779. {
  780. int i;
  781. for (i = 0; i < MAX_NUM_OF_MUX_CHANNEL; i++) {
  782. if (strcmp(rmnet_ipa3_ctx->mux_channel[i].vchannel_name,
  783. upstreamIface) == 0)
  784. return IPA_UPSTEAM_MODEM;
  785. }
  786. if ((strcmp(IPA_UPSTEAM_WLAN_IFACE_NAME, upstreamIface) == 0) ||
  787. (strcmp(IPA_UPSTEAM_WLAN1_IFACE_NAME, upstreamIface) == 0))
  788. return IPA_UPSTEAM_WLAN;
  789. else
  790. return MAX_NUM_OF_MUX_CHANNEL;
  791. }
  792. static int ipa3_wwan_register_to_ipa(int index)
  793. {
  794. struct ipa_tx_intf tx_properties = {0};
  795. struct ipa_ioc_tx_intf_prop tx_ioc_properties[2] = { {0}, {0} };
  796. struct ipa_ioc_tx_intf_prop *tx_ipv4_property;
  797. struct ipa_ioc_tx_intf_prop *tx_ipv6_property;
  798. struct ipa_rx_intf rx_properties = {0};
  799. struct ipa_ioc_rx_intf_prop rx_ioc_properties[2] = { {0}, {0} };
  800. struct ipa_ioc_rx_intf_prop *rx_ipv4_property;
  801. struct ipa_ioc_rx_intf_prop *rx_ipv6_property;
  802. struct ipa_ext_intf ext_properties = {0};
  803. struct ipa_ioc_ext_intf_prop *ext_ioc_properties;
  804. u32 pyld_sz;
  805. int ret = 0, i;
  806. IPAWANDBG("index(%d) device[%s]:\n", index,
  807. rmnet_ipa3_ctx->mux_channel[index].vchannel_name);
  808. if (!rmnet_ipa3_ctx->mux_channel[index].mux_hdr_set) {
  809. ret = ipa3_add_qmap_hdr(
  810. rmnet_ipa3_ctx->mux_channel[index].mux_id,
  811. &rmnet_ipa3_ctx->mux_channel[index].hdr_hdl);
  812. if (ret) {
  813. IPAWANERR("ipa_add_mux_hdr failed (%d)\n", index);
  814. return ret;
  815. }
  816. rmnet_ipa3_ctx->mux_channel[index].mux_hdr_set = true;
  817. }
  818. tx_properties.prop = tx_ioc_properties;
  819. tx_ipv4_property = &tx_properties.prop[0];
  820. tx_ipv4_property->ip = IPA_IP_v4;
  821. if (rmnet_ipa3_ctx->ipa_config_is_apq)
  822. tx_ipv4_property->dst_pipe = IPA_CLIENT_MHI_PRIME_TETH_CONS;
  823. else
  824. tx_ipv4_property->dst_pipe = IPA_CLIENT_APPS_WAN_CONS;
  825. snprintf(tx_ipv4_property->hdr_name, IPA_RESOURCE_NAME_MAX, "%s%d",
  826. A2_MUX_HDR_NAME_V4_PREF,
  827. rmnet_ipa3_ctx->mux_channel[index].mux_id);
  828. tx_ipv6_property = &tx_properties.prop[1];
  829. tx_ipv6_property->ip = IPA_IP_v6;
  830. if (rmnet_ipa3_ctx->ipa_config_is_apq)
  831. tx_ipv6_property->dst_pipe = IPA_CLIENT_MHI_PRIME_TETH_CONS;
  832. else
  833. tx_ipv6_property->dst_pipe = IPA_CLIENT_APPS_WAN_CONS;
  834. /* no need use A2_MUX_HDR_NAME_V6_PREF, same header */
  835. snprintf(tx_ipv6_property->hdr_name, IPA_RESOURCE_NAME_MAX, "%s%d",
  836. A2_MUX_HDR_NAME_V4_PREF,
  837. rmnet_ipa3_ctx->mux_channel[index].mux_id);
  838. tx_properties.num_props = 2;
  839. rx_properties.prop = rx_ioc_properties;
  840. rx_ipv4_property = &rx_properties.prop[0];
  841. rx_ipv4_property->ip = IPA_IP_v4;
  842. rx_ipv4_property->attrib.attrib_mask |= IPA_FLT_META_DATA;
  843. rx_ipv4_property->attrib.meta_data =
  844. rmnet_ipa3_ctx->mux_channel[index].mux_id << WWAN_METADATA_SHFT;
  845. rx_ipv4_property->attrib.meta_data_mask = WWAN_METADATA_MASK;
  846. if (rmnet_ipa3_ctx->ipa_config_is_apq)
  847. rx_ipv4_property->src_pipe = IPA_CLIENT_MHI_PRIME_TETH_PROD;
  848. else
  849. rx_ipv4_property->src_pipe = IPA_CLIENT_APPS_WAN_PROD;
  850. rx_ipv6_property = &rx_properties.prop[1];
  851. rx_ipv6_property->ip = IPA_IP_v6;
  852. rx_ipv6_property->attrib.attrib_mask |= IPA_FLT_META_DATA;
  853. rx_ipv6_property->attrib.meta_data =
  854. rmnet_ipa3_ctx->mux_channel[index].mux_id << WWAN_METADATA_SHFT;
  855. rx_ipv6_property->attrib.meta_data_mask = WWAN_METADATA_MASK;
  856. if (rmnet_ipa3_ctx->ipa_config_is_apq)
  857. rx_ipv6_property->src_pipe = IPA_CLIENT_MHI_PRIME_TETH_PROD;
  858. else
  859. rx_ipv6_property->src_pipe = IPA_CLIENT_APPS_WAN_PROD;
  860. rx_properties.num_props = 2;
  861. if (rmnet_ipa3_ctx->ipa_config_is_apq) {
  862. /* provide mux-id to ipacm in apq platform*/
  863. pyld_sz = sizeof(struct ipa_ioc_ext_intf_prop);
  864. ext_ioc_properties = kmalloc(pyld_sz, GFP_KERNEL);
  865. if (!ext_ioc_properties)
  866. return -ENOMEM;
  867. ext_properties.prop = ext_ioc_properties;
  868. ext_properties.num_props = 1;
  869. ext_properties.prop[0].mux_id =
  870. rmnet_ipa3_ctx->mux_channel[index].mux_id;
  871. ext_properties.prop[0].ip = IPA_IP_MAX;
  872. IPAWANDBG("ip: %d mux:%d\n",
  873. ext_properties.prop[0].ip,
  874. ext_properties.prop[0].mux_id);
  875. ret = ipa3_register_intf_ext(
  876. rmnet_ipa3_ctx->mux_channel[index].vchannel_name,
  877. &tx_properties,
  878. &rx_properties,
  879. &ext_properties);
  880. if (ret) {
  881. IPAWANERR("[%d]ipa3_register_intf failed %d\n",
  882. index,
  883. ret);
  884. goto fail;
  885. }
  886. goto end;
  887. }
  888. /* non apq case */
  889. pyld_sz = rmnet_ipa3_ctx->num_q6_rules *
  890. sizeof(struct ipa_ioc_ext_intf_prop);
  891. ext_ioc_properties = kmalloc(pyld_sz, GFP_KERNEL);
  892. if (!ext_ioc_properties)
  893. return -ENOMEM;
  894. ext_properties.prop = ext_ioc_properties;
  895. ext_properties.excp_pipe_valid = true;
  896. ext_properties.excp_pipe = IPA_CLIENT_APPS_WAN_CONS;
  897. ext_properties.num_props = rmnet_ipa3_ctx->num_q6_rules;
  898. for (i = 0; i < rmnet_ipa3_ctx->num_q6_rules; i++) {
  899. memcpy(&(ext_properties.prop[i]),
  900. &(ipa3_qmi_ctx->q6_ul_filter_rule[i]),
  901. sizeof(struct ipa_ioc_ext_intf_prop));
  902. ext_properties.prop[i].mux_id =
  903. rmnet_ipa3_ctx->mux_channel[index].mux_id;
  904. IPAWANDBG("index %d ip: %d rt-tbl:%d\n", i,
  905. ext_properties.prop[i].ip,
  906. ext_properties.prop[i].rt_tbl_idx);
  907. IPAWANDBG("action: %d mux:%d\n",
  908. ext_properties.prop[i].action,
  909. ext_properties.prop[i].mux_id);
  910. }
  911. ret = ipa3_register_intf_ext(
  912. rmnet_ipa3_ctx->mux_channel[index].vchannel_name,
  913. &tx_properties,
  914. &rx_properties,
  915. &ext_properties);
  916. if (ret) {
  917. IPAWANERR("[%s]:ipa3_register_intf failed %d\n",
  918. rmnet_ipa3_ctx->mux_channel[index].vchannel_name,
  919. ret);
  920. goto fail;
  921. }
  922. end:
  923. rmnet_ipa3_ctx->mux_channel[index].ul_flt_reg = true;
  924. fail:
  925. kfree(ext_ioc_properties);
  926. return ret;
  927. }
  928. static void ipa3_cleanup_deregister_intf(void)
  929. {
  930. int i;
  931. int ret;
  932. int8_t *v_name;
  933. for (i = 0; i < rmnet_ipa3_ctx->rmnet_index; i++) {
  934. v_name = rmnet_ipa3_ctx->mux_channel[i].vchannel_name;
  935. if (rmnet_ipa3_ctx->mux_channel[i].ul_flt_reg) {
  936. ret = ipa3_deregister_intf(v_name);
  937. if (ret < 0) {
  938. IPAWANERR("de-register device %s(%d) failed\n",
  939. v_name,
  940. i);
  941. return;
  942. }
  943. IPAWANDBG("de-register device %s(%d) success\n",
  944. v_name,
  945. i);
  946. }
  947. rmnet_ipa3_ctx->mux_channel[i].ul_flt_reg = false;
  948. }
  949. }
  950. int ipa3_wwan_update_mux_channel_prop(void)
  951. {
  952. int ret = 0, i;
  953. /* install UL filter rules */
  954. if (rmnet_ipa3_ctx->egress_set) {
  955. if (!ipa3_qmi_ctx->modem_cfg_emb_pipe_flt) {
  956. IPAWANDBG("setup UL filter rules\n");
  957. if (rmnet_ipa3_ctx->a7_ul_flt_set) {
  958. IPAWANDBG("del previous UL filter rules\n");
  959. /* delete rule hdlers */
  960. ret = ipa3_wwan_del_ul_flt_rule_to_ipa();
  961. if (ret) {
  962. IPAWANERR("failed to del old rules\n");
  963. return -EINVAL;
  964. }
  965. IPAWANDBG("deleted old UL rules\n");
  966. }
  967. ret = ipa3_wwan_add_ul_flt_rule_to_ipa();
  968. }
  969. if (ret)
  970. IPAWANERR("failed to install UL rules\n");
  971. else
  972. rmnet_ipa3_ctx->a7_ul_flt_set = true;
  973. }
  974. /* update Tx/Rx/Ext property */
  975. IPAWANDBG("update Tx/Rx/Ext property in IPA\n");
  976. if (rmnet_ipa3_ctx->rmnet_index == 0) {
  977. IPAWANDBG("no Tx/Rx/Ext property registered in IPA\n");
  978. return ret;
  979. }
  980. ipa3_cleanup_deregister_intf();
  981. for (i = 0; i < rmnet_ipa3_ctx->rmnet_index; i++) {
  982. ret = ipa3_wwan_register_to_ipa(i);
  983. if (ret < 0) {
  984. IPAWANERR("failed to re-regist %s, mux %d, index %d\n",
  985. rmnet_ipa3_ctx->mux_channel[i].vchannel_name,
  986. rmnet_ipa3_ctx->mux_channel[i].mux_id,
  987. i);
  988. return -ENODEV;
  989. }
  990. IPAWANERR("dev(%s) has registered to IPA\n",
  991. rmnet_ipa3_ctx->mux_channel[i].vchannel_name);
  992. rmnet_ipa3_ctx->mux_channel[i].ul_flt_reg = true;
  993. }
  994. return ret;
  995. }
  996. #ifdef INIT_COMPLETION
  997. #define reinit_completion(x) INIT_COMPLETION(*(x))
  998. #endif /* INIT_COMPLETION */
  999. static int __ipa_wwan_open(struct net_device *dev)
  1000. {
  1001. struct ipa3_wwan_private *wwan_ptr = netdev_priv(dev);
  1002. IPAWANDBG("[%s] __wwan_open()\n", dev->name);
  1003. if (wwan_ptr->device_status != WWAN_DEVICE_ACTIVE)
  1004. reinit_completion(&wwan_ptr->resource_granted_completion);
  1005. wwan_ptr->device_status = WWAN_DEVICE_ACTIVE;
  1006. if (ipa3_rmnet_res.ipa_napi_enable)
  1007. napi_enable(&(wwan_ptr->napi));
  1008. return 0;
  1009. }
  1010. /**
  1011. * wwan_open() - Opens the wwan network interface. Opens logical
  1012. * channel on A2 MUX driver and starts the network stack queue
  1013. *
  1014. * @dev: network device
  1015. *
  1016. * Return codes:
  1017. * 0: success
  1018. * -ENODEV: Error while opening logical channel on A2 MUX driver
  1019. */
  1020. static int ipa3_wwan_open(struct net_device *dev)
  1021. {
  1022. int rc = 0;
  1023. IPAWANDBG("[%s] wwan_open()\n", dev->name);
  1024. rc = __ipa_wwan_open(dev);
  1025. if (rc == 0)
  1026. netif_start_queue(dev);
  1027. return rc;
  1028. }
  1029. static int __ipa_wwan_close(struct net_device *dev)
  1030. {
  1031. struct ipa3_wwan_private *wwan_ptr = netdev_priv(dev);
  1032. int rc = 0;
  1033. if (wwan_ptr->device_status == WWAN_DEVICE_ACTIVE) {
  1034. wwan_ptr->device_status = WWAN_DEVICE_INACTIVE;
  1035. /* do not close wwan port once up, this causes
  1036. * remote side to hang if tried to open again
  1037. */
  1038. reinit_completion(&wwan_ptr->resource_granted_completion);
  1039. rc = ipa3_deregister_intf(dev->name);
  1040. if (rc) {
  1041. IPAWANERR("[%s]: ipa3_deregister_intf failed %d\n",
  1042. dev->name, rc);
  1043. return rc;
  1044. }
  1045. return rc;
  1046. } else {
  1047. return -EBADF;
  1048. }
  1049. }
  1050. /**
  1051. * ipa3_wwan_stop() - Stops the wwan network interface. Closes
  1052. * logical channel on A2 MUX driver and stops the network stack
  1053. * queue
  1054. *
  1055. * @dev: network device
  1056. *
  1057. * Return codes:
  1058. * 0: success
  1059. * -ENODEV: Error while opening logical channel on A2 MUX driver
  1060. */
  1061. static int ipa3_wwan_stop(struct net_device *dev)
  1062. {
  1063. struct ipa3_wwan_private *wwan_ptr = netdev_priv(dev);
  1064. IPAWANDBG("[%s]\n", dev->name);
  1065. __ipa_wwan_close(dev);
  1066. if (ipa3_rmnet_res.ipa_napi_enable)
  1067. napi_disable(&(wwan_ptr->napi));
  1068. netif_stop_queue(dev);
  1069. return 0;
  1070. }
  1071. static int ipa3_wwan_change_mtu(struct net_device *dev, int new_mtu)
  1072. {
  1073. if (0 > new_mtu || WWAN_DATA_LEN < new_mtu)
  1074. return -EINVAL;
  1075. IPAWANDBG("[%s] MTU change: old=%d new=%d\n",
  1076. dev->name, dev->mtu, new_mtu);
  1077. dev->mtu = new_mtu;
  1078. return 0;
  1079. }
  1080. /**
  1081. * ipa3_wwan_xmit() - Transmits an skb.
  1082. *
  1083. * @skb: skb to be transmitted
  1084. * @dev: network device
  1085. *
  1086. * Return codes:
  1087. * 0: success
  1088. * NETDEV_TX_BUSY: Error while transmitting the skb. Try again
  1089. * later
  1090. * -EFAULT: Error while transmitting the skb
  1091. */
  1092. static int ipa3_wwan_xmit(struct sk_buff *skb, struct net_device *dev)
  1093. {
  1094. int ret = 0;
  1095. bool qmap_check;
  1096. struct ipa3_wwan_private *wwan_ptr = netdev_priv(dev);
  1097. unsigned long flags;
  1098. if (rmnet_ipa3_ctx->ipa_config_is_apq) {
  1099. IPAWANERR_RL("IPA embedded data on APQ platform\n");
  1100. dev_kfree_skb_any(skb);
  1101. dev->stats.tx_dropped++;
  1102. return NETDEV_TX_OK;
  1103. }
  1104. if (skb->protocol != htons(ETH_P_MAP)) {
  1105. IPAWANDBG_LOW
  1106. ("SW filtering out none QMAP packet received from %s",
  1107. current->comm);
  1108. dev_kfree_skb_any(skb);
  1109. dev->stats.tx_dropped++;
  1110. return NETDEV_TX_OK;
  1111. }
  1112. qmap_check = RMNET_MAP_GET_CD_BIT(skb);
  1113. spin_lock_irqsave(&wwan_ptr->lock, flags);
  1114. /* There can be a race between enabling the wake queue and
  1115. * suspend in progress. Check if suspend is pending and
  1116. * return from here itself.
  1117. */
  1118. if (atomic_read(&rmnet_ipa3_ctx->ap_suspend)) {
  1119. netif_stop_queue(dev);
  1120. spin_unlock_irqrestore(&wwan_ptr->lock, flags);
  1121. return NETDEV_TX_BUSY;
  1122. }
  1123. if (netif_queue_stopped(dev)) {
  1124. if (qmap_check &&
  1125. atomic_read(&wwan_ptr->outstanding_pkts) <
  1126. rmnet_ipa3_ctx->outstanding_high_ctl) {
  1127. IPAWANERR("[%s]Queue stop, send ctrl pkts\n",
  1128. dev->name);
  1129. goto send;
  1130. } else {
  1131. IPAWANERR("[%s]fatal: %s stopped\n", dev->name,
  1132. __func__);
  1133. spin_unlock_irqrestore(&wwan_ptr->lock, flags);
  1134. return NETDEV_TX_BUSY;
  1135. }
  1136. }
  1137. /* checking High WM hit */
  1138. if (atomic_read(&wwan_ptr->outstanding_pkts) >=
  1139. rmnet_ipa3_ctx->outstanding_high) {
  1140. if (!qmap_check) {
  1141. IPAWANDBG_LOW("pending(%d)/(%d)- stop(%d)\n",
  1142. atomic_read(&wwan_ptr->outstanding_pkts),
  1143. rmnet_ipa3_ctx->outstanding_high,
  1144. netif_queue_stopped(dev));
  1145. IPAWANDBG_LOW("qmap_chk(%d)\n", qmap_check);
  1146. netif_stop_queue(dev);
  1147. spin_unlock_irqrestore(&wwan_ptr->lock, flags);
  1148. return NETDEV_TX_BUSY;
  1149. }
  1150. }
  1151. send:
  1152. /* IPA_PM checking start */
  1153. /* activate the modem pm for clock scaling */
  1154. ipa_pm_activate(rmnet_ipa3_ctx->q6_pm_hdl);
  1155. ret = ipa_pm_activate(rmnet_ipa3_ctx->pm_hdl);
  1156. if (ret == -EINPROGRESS) {
  1157. netif_stop_queue(dev);
  1158. spin_unlock_irqrestore(&wwan_ptr->lock, flags);
  1159. return NETDEV_TX_BUSY;
  1160. }
  1161. if (ret) {
  1162. IPAWANERR("[%s] fatal: ipa pm activate failed %d\n",
  1163. dev->name, ret);
  1164. dev_kfree_skb_any(skb);
  1165. dev->stats.tx_dropped++;
  1166. spin_unlock_irqrestore(&wwan_ptr->lock, flags);
  1167. return NETDEV_TX_OK;
  1168. }
  1169. /* IPA_PM checking end */
  1170. /*
  1171. * both data packets and command will be routed to
  1172. * IPA_CLIENT_Q6_WAN_CONS based on status configuration
  1173. */
  1174. ret = ipa3_tx_dp(IPA_CLIENT_APPS_WAN_PROD, skb, NULL);
  1175. if (ret) {
  1176. if (ret == -EPIPE) {
  1177. IPAWANERR_RL("[%s] fatal: pipe is not valid\n",
  1178. dev->name);
  1179. dev_kfree_skb_any(skb);
  1180. dev->stats.tx_dropped++;
  1181. spin_unlock_irqrestore(&wwan_ptr->lock, flags);
  1182. return NETDEV_TX_OK;
  1183. }
  1184. ret = NETDEV_TX_BUSY;
  1185. goto out;
  1186. }
  1187. atomic_inc(&wwan_ptr->outstanding_pkts);
  1188. dev->stats.tx_packets++;
  1189. dev->stats.tx_bytes += skb->len;
  1190. ret = NETDEV_TX_OK;
  1191. out:
  1192. if (atomic_read(&wwan_ptr->outstanding_pkts) == 0) {
  1193. ipa_pm_deferred_deactivate(rmnet_ipa3_ctx->pm_hdl);
  1194. ipa_pm_deferred_deactivate(rmnet_ipa3_ctx->q6_pm_hdl);
  1195. }
  1196. spin_unlock_irqrestore(&wwan_ptr->lock, flags);
  1197. return ret;
  1198. }
  1199. static void ipa3_wwan_tx_timeout(struct net_device *dev)
  1200. {
  1201. struct ipa3_wwan_private *wwan_ptr = netdev_priv(dev);
  1202. if (atomic_read(&wwan_ptr->outstanding_pkts) != 0)
  1203. IPAWANERR("[%s] data stall in UL, %d outstanding\n",
  1204. dev->name, atomic_read(&wwan_ptr->outstanding_pkts));
  1205. }
  1206. /**
  1207. * apps_ipa_tx_complete_notify() - Rx notify
  1208. *
  1209. * @priv: driver context
  1210. * @evt: event type
  1211. * @data: data provided with event
  1212. *
  1213. * Check that the packet is the one we sent and release it
  1214. * This function will be called in defered context in IPA wq.
  1215. */
  1216. static void apps_ipa_tx_complete_notify(void *priv,
  1217. enum ipa_dp_evt_type evt,
  1218. unsigned long data)
  1219. {
  1220. struct sk_buff *skb = (struct sk_buff *)data;
  1221. struct net_device *dev = (struct net_device *)priv;
  1222. struct ipa3_wwan_private *wwan_ptr;
  1223. if (dev != IPA_NETDEV()) {
  1224. IPAWANDBG("Received pre-SSR packet completion\n");
  1225. dev_kfree_skb_any(skb);
  1226. return;
  1227. }
  1228. if (evt != IPA_WRITE_DONE) {
  1229. IPAWANERR("unsupported evt on Tx callback, Drop the packet\n");
  1230. dev_kfree_skb_any(skb);
  1231. dev->stats.tx_dropped++;
  1232. return;
  1233. }
  1234. wwan_ptr = netdev_priv(dev);
  1235. atomic_dec(&wwan_ptr->outstanding_pkts);
  1236. __netif_tx_lock_bh(netdev_get_tx_queue(dev, 0));
  1237. if (!atomic_read(&rmnet_ipa3_ctx->is_ssr) &&
  1238. netif_queue_stopped(wwan_ptr->net) &&
  1239. atomic_read(&wwan_ptr->outstanding_pkts) <
  1240. rmnet_ipa3_ctx->outstanding_low) {
  1241. IPAWANDBG_LOW("Outstanding low (%d) - waking up queue\n",
  1242. rmnet_ipa3_ctx->outstanding_low);
  1243. netif_wake_queue(wwan_ptr->net);
  1244. }
  1245. if (atomic_read(&wwan_ptr->outstanding_pkts) == 0) {
  1246. ipa_pm_deferred_deactivate(rmnet_ipa3_ctx->pm_hdl);
  1247. ipa_pm_deferred_deactivate(rmnet_ipa3_ctx->q6_pm_hdl);
  1248. }
  1249. __netif_tx_unlock_bh(netdev_get_tx_queue(dev, 0));
  1250. dev_kfree_skb_any(skb);
  1251. }
  1252. /**
  1253. * apps_ipa_packet_receive_notify() - Rx notify
  1254. *
  1255. * @priv: driver context
  1256. * @evt: event type
  1257. * @data: data provided with event
  1258. *
  1259. * IPA will pass a packet to the Linux network stack with skb->data
  1260. */
  1261. static void apps_ipa_packet_receive_notify(void *priv,
  1262. enum ipa_dp_evt_type evt,
  1263. unsigned long data)
  1264. {
  1265. struct net_device *dev = (struct net_device *)priv;
  1266. if (evt == IPA_RECEIVE) {
  1267. struct sk_buff *skb = (struct sk_buff *)data;
  1268. int result;
  1269. unsigned int packet_len = skb->len;
  1270. IPAWANDBG_LOW("Rx packet was received");
  1271. skb->dev = IPA_NETDEV();
  1272. skb->protocol = htons(ETH_P_MAP);
  1273. if (ipa3_rmnet_res.ipa_napi_enable) {
  1274. trace_rmnet_ipa_netif_rcv_skb3(dev->stats.rx_packets);
  1275. result = netif_receive_skb(skb);
  1276. } else {
  1277. if (dev->stats.rx_packets % IPA_WWAN_RX_SOFTIRQ_THRESH
  1278. == 0) {
  1279. trace_rmnet_ipa_netifni3(dev->stats.rx_packets);
  1280. result = netif_rx_ni(skb);
  1281. } else {
  1282. trace_rmnet_ipa_netifrx3(dev->stats.rx_packets);
  1283. result = netif_rx(skb);
  1284. }
  1285. }
  1286. if (result) {
  1287. pr_err_ratelimited(DEV_NAME " %s:%d fail on netif_receive_skb\n",
  1288. __func__, __LINE__);
  1289. dev->stats.rx_dropped++;
  1290. }
  1291. dev->stats.rx_packets++;
  1292. dev->stats.rx_bytes += packet_len;
  1293. } else {
  1294. IPAWANERR("Invalid evt %d received in wan_ipa_receive\n", evt);
  1295. }
  1296. }
  1297. /* Send RSC endpoint info to modem using QMI indication message */
  1298. static int ipa_send_rsc_pipe_ind_to_modem(void)
  1299. {
  1300. struct ipa_endp_desc_indication_msg_v01 req;
  1301. struct ipa_ep_id_type_v01 *ep_info;
  1302. memset(&req, 0, sizeof(struct ipa_endp_desc_indication_msg_v01));
  1303. req.ep_info_len = 1;
  1304. req.ep_info_valid = true;
  1305. req.num_eps_valid = true;
  1306. req.num_eps = 1;
  1307. ep_info = &req.ep_info[req.ep_info_len - 1];
  1308. ep_info->ep_id = rmnet_ipa3_ctx->ipa3_to_apps_hdl;
  1309. ep_info->ic_type = DATA_IC_TYPE_AP_V01;
  1310. ep_info->ep_type = DATA_EP_DESC_TYPE_RSC_PROD_V01;
  1311. ep_info->ep_status = DATA_EP_STATUS_CONNECTED_V01;
  1312. return ipa3_qmi_send_rsc_pipe_indication(&req);
  1313. }
  1314. static int handle3_ingress_format(struct net_device *dev,
  1315. struct rmnet_ioctl_extended_s *in)
  1316. {
  1317. int ret = 0;
  1318. struct ipa_sys_connect_params *ipa_wan_ep_cfg;
  1319. int ep_idx;
  1320. IPAWANDBG("Get RMNET_IOCTL_SET_INGRESS_DATA_FORMAT\n");
  1321. ep_idx = ipa3_get_ep_mapping(IPA_CLIENT_APPS_WAN_CONS);
  1322. if (ep_idx == IPA_EP_NOT_ALLOCATED) {
  1323. IPAWANDBG("Embedded datapath not supported\n");
  1324. return -EFAULT;
  1325. }
  1326. ipa_wan_ep_cfg = &rmnet_ipa3_ctx->ipa_to_apps_ep_cfg;
  1327. if ((in->u.data) & RMNET_IOCTL_INGRESS_FORMAT_CHECKSUM) {
  1328. if (ipa3_ctx->ipa_hw_type >= IPA_HW_v4_5)
  1329. ipa_wan_ep_cfg->ipa_ep_cfg.cfg.cs_offload_en =
  1330. IPA_ENABLE_CS_DL_QMAP;
  1331. else
  1332. ipa_wan_ep_cfg->ipa_ep_cfg.cfg.cs_offload_en =
  1333. IPA_ENABLE_CS_OFFLOAD_DL;
  1334. IPAWANDBG("DL chksum set\n");
  1335. }
  1336. if ((in->u.data) & RMNET_IOCTL_INGRESS_FORMAT_AGG_DATA) {
  1337. IPAWANDBG("get AGG size %d count %d\n",
  1338. in->u.ingress_format.agg_size,
  1339. in->u.ingress_format.agg_count);
  1340. ret = ipa_disable_apps_wan_cons_deaggr(
  1341. in->u.ingress_format.agg_size,
  1342. in->u.ingress_format.agg_count);
  1343. if (!ret) {
  1344. ipa_wan_ep_cfg->ipa_ep_cfg.aggr.aggr_byte_limit =
  1345. in->u.ingress_format.agg_size;
  1346. ipa_wan_ep_cfg->ipa_ep_cfg.aggr.aggr_pkt_limit =
  1347. in->u.ingress_format.agg_count;
  1348. }
  1349. }
  1350. if (ipa3_ctx->ipa_hw_type >= IPA_HW_v4_5 &&
  1351. (in->u.data) & RMNET_IOCTL_INGRESS_FORMAT_CHECKSUM) {
  1352. ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_len = 8;
  1353. rmnet_ipa3_ctx->dl_csum_offload_enabled = true;
  1354. } else {
  1355. ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_len = 4;
  1356. rmnet_ipa3_ctx->dl_csum_offload_enabled = false;
  1357. }
  1358. ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
  1359. ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_metadata = 1;
  1360. ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
  1361. ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 2;
  1362. ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_total_len_or_pad_valid = true;
  1363. ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_total_len_or_pad = 0;
  1364. ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_payload_len_inc_padding = true;
  1365. ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_total_len_or_pad_offset = 0;
  1366. ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_little_endian = 0;
  1367. ipa_wan_ep_cfg->ipa_ep_cfg.metadata_mask.metadata_mask = 0xFF000000;
  1368. ipa_wan_ep_cfg->client = IPA_CLIENT_APPS_WAN_CONS;
  1369. if (dev->features & NETIF_F_GRO_HW)
  1370. /* Setup coalescing pipes */
  1371. ipa_wan_ep_cfg->client = IPA_CLIENT_APPS_WAN_COAL_CONS;
  1372. ipa_wan_ep_cfg->notify = apps_ipa_packet_receive_notify;
  1373. ipa_wan_ep_cfg->priv = dev;
  1374. if (ipa3_rmnet_res.ipa_napi_enable)
  1375. ipa_wan_ep_cfg->napi_obj = &(rmnet_ipa3_ctx->wwan_priv->napi);
  1376. ipa_wan_ep_cfg->desc_fifo_sz =
  1377. ipa3_rmnet_res.wan_rx_desc_size * IPA_FIFO_ELEMENT_SIZE;
  1378. mutex_lock(&rmnet_ipa3_ctx->pipe_handle_guard);
  1379. if (atomic_read(&rmnet_ipa3_ctx->is_ssr)) {
  1380. IPAWANDBG("In SSR sequence/recovery\n");
  1381. mutex_unlock(&rmnet_ipa3_ctx->pipe_handle_guard);
  1382. return -EFAULT;
  1383. }
  1384. ret = ipa3_setup_sys_pipe(&rmnet_ipa3_ctx->ipa_to_apps_ep_cfg,
  1385. &rmnet_ipa3_ctx->ipa3_to_apps_hdl);
  1386. mutex_unlock(&rmnet_ipa3_ctx->pipe_handle_guard);
  1387. if (ret)
  1388. goto end;
  1389. /* construct default WAN RT tbl for IPACM */
  1390. ret = ipa3_setup_a7_qmap_hdr();
  1391. if (ret)
  1392. goto end;
  1393. ret = ipa3_setup_dflt_wan_rt_tables();
  1394. if (ret)
  1395. ipa3_del_a7_qmap_hdr();
  1396. /* Sending QMI indication message share RSC pipe details*/
  1397. if (dev->features & NETIF_F_GRO_HW)
  1398. ipa_send_rsc_pipe_ind_to_modem();
  1399. end:
  1400. if (ret)
  1401. IPAWANERR("failed to configure ingress\n");
  1402. return ret;
  1403. }
  1404. /**
  1405. * handle3_egress_format() - Egress data format configuration
  1406. *
  1407. * Setup IPA egress system pipe and Configure:
  1408. * header handling, checksum, de-aggregation and fifo size
  1409. *
  1410. * @dev: network device
  1411. * @e: egress configuration
  1412. */
  1413. static int handle3_egress_format(struct net_device *dev,
  1414. struct rmnet_ioctl_extended_s *e)
  1415. {
  1416. int rc;
  1417. struct ipa_sys_connect_params *ipa_wan_ep_cfg;
  1418. int ep_idx;
  1419. IPAWANDBG("get RMNET_IOCTL_SET_EGRESS_DATA_FORMAT %x\n", e->u.data);
  1420. /* in APQ platform, only get QMAP format */
  1421. if (rmnet_ipa3_ctx->ipa_config_is_apq) {
  1422. if ((e->u.data) & RMNET_IOCTL_EGRESS_FORMAT_CHECKSUM) {
  1423. /* QMAPv5 */
  1424. rmnet_ipa3_ctx->dl_csum_offload_enabled = false;
  1425. /* send aggr_info_qmi */
  1426. rc = ipa3_qmi_set_aggr_info(DATA_AGGR_TYPE_QMAP_V01);
  1427. } else {
  1428. /* QMAP */
  1429. rmnet_ipa3_ctx->dl_csum_offload_enabled = false;
  1430. /* send aggr_info_qmi */
  1431. rc = ipa3_qmi_set_aggr_info(DATA_AGGR_TYPE_QMAP_V01);
  1432. }
  1433. rmnet_ipa3_ctx->ipa_mhi_aggr_formet_set = true;
  1434. return rc;
  1435. }
  1436. ep_idx = ipa3_get_ep_mapping(IPA_CLIENT_APPS_WAN_PROD);
  1437. if (ep_idx == IPA_EP_NOT_ALLOCATED) {
  1438. IPAWANDBG("Embedded datapath not supported\n");
  1439. return -EFAULT;
  1440. }
  1441. ipa_wan_ep_cfg = &rmnet_ipa3_ctx->apps_to_ipa_ep_cfg;
  1442. if ((e->u.data) & RMNET_IOCTL_EGRESS_FORMAT_CHECKSUM) {
  1443. IPAWANDBG("UL chksum set\n");
  1444. ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_len = 8;
  1445. ipa_wan_ep_cfg->ipa_ep_cfg.cfg.cs_offload_en =
  1446. IPA_ENABLE_CS_OFFLOAD_UL;
  1447. ipa_wan_ep_cfg->ipa_ep_cfg.cfg.cs_metadata_hdr_offset = 1;
  1448. } else {
  1449. ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_len = 4;
  1450. }
  1451. if ((e->u.data) & RMNET_IOCTL_EGRESS_FORMAT_AGGREGATION) {
  1452. IPAWANDBG("WAN UL Aggregation enabled\n");
  1453. ipa_wan_ep_cfg->ipa_ep_cfg.aggr.aggr_en = IPA_ENABLE_DEAGGR;
  1454. ipa_wan_ep_cfg->ipa_ep_cfg.aggr.aggr = IPA_QCMAP;
  1455. ipa_wan_ep_cfg->ipa_ep_cfg.deaggr.packet_offset_valid = false;
  1456. ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 2;
  1457. ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_total_len_or_pad_valid =
  1458. true;
  1459. ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_total_len_or_pad =
  1460. IPA_HDR_PAD;
  1461. ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_pad_to_alignment =
  1462. 2;
  1463. ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_payload_len_inc_padding =
  1464. true;
  1465. ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_total_len_or_pad_offset =
  1466. 0;
  1467. ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_little_endian =
  1468. false;
  1469. } else {
  1470. IPAWANDBG("WAN UL Aggregation disabled\n");
  1471. ipa_wan_ep_cfg->ipa_ep_cfg.aggr.aggr_en = IPA_BYPASS_AGGR;
  1472. }
  1473. ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
  1474. /* modem want offset at 0! */
  1475. ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_metadata = 0;
  1476. ipa_wan_ep_cfg->ipa_ep_cfg.mode.dst = IPA_CLIENT_APPS_WAN_PROD;
  1477. ipa_wan_ep_cfg->ipa_ep_cfg.mode.mode = IPA_BASIC;
  1478. ipa_wan_ep_cfg->client = IPA_CLIENT_APPS_WAN_PROD;
  1479. ipa_wan_ep_cfg->notify = apps_ipa_tx_complete_notify;
  1480. ipa_wan_ep_cfg->desc_fifo_sz = IPA_SYS_TX_DATA_DESC_FIFO_SZ;
  1481. ipa_wan_ep_cfg->priv = dev;
  1482. mutex_lock(&rmnet_ipa3_ctx->pipe_handle_guard);
  1483. if (atomic_read(&rmnet_ipa3_ctx->is_ssr)) {
  1484. IPAWANDBG("In SSR sequence/recovery\n");
  1485. mutex_unlock(&rmnet_ipa3_ctx->pipe_handle_guard);
  1486. return -EFAULT;
  1487. }
  1488. rc = ipa3_setup_sys_pipe(
  1489. ipa_wan_ep_cfg, &rmnet_ipa3_ctx->apps_to_ipa3_hdl);
  1490. if (rc) {
  1491. IPAWANERR("failed to config egress endpoint\n");
  1492. mutex_unlock(&rmnet_ipa3_ctx->pipe_handle_guard);
  1493. return rc;
  1494. }
  1495. mutex_unlock(&rmnet_ipa3_ctx->pipe_handle_guard);
  1496. if (rmnet_ipa3_ctx->num_q6_rules != 0) {
  1497. /* already got Q6 UL filter rules*/
  1498. if (!ipa3_qmi_ctx->modem_cfg_emb_pipe_flt) {
  1499. /* prevent multi-threads accessing num_q6_rules */
  1500. mutex_lock(&rmnet_ipa3_ctx->add_mux_channel_lock);
  1501. rc = ipa3_wwan_add_ul_flt_rule_to_ipa();
  1502. mutex_unlock(
  1503. &rmnet_ipa3_ctx->add_mux_channel_lock);
  1504. }
  1505. if (rc)
  1506. IPAWANERR("install UL rules failed\n");
  1507. else
  1508. rmnet_ipa3_ctx->a7_ul_flt_set = true;
  1509. } else {
  1510. /* wait Q6 UL filter rules*/
  1511. IPAWANDBG("no UL-rules\n");
  1512. }
  1513. rmnet_ipa3_ctx->egress_set = true;
  1514. return rc;
  1515. }
  1516. /**
  1517. * ipa3_wwan_ioctl() - I/O control for wwan network driver.
  1518. *
  1519. * @dev: network device
  1520. * @ifr: ignored
  1521. * @cmd: cmd to be excecuded. can be one of the following:
  1522. * IPA_WWAN_IOCTL_OPEN - Open the network interface
  1523. * IPA_WWAN_IOCTL_CLOSE - Close the network interface
  1524. *
  1525. * Return codes:
  1526. * 0: success
  1527. * NETDEV_TX_BUSY: Error while transmitting the skb. Try again
  1528. * later
  1529. * -EFAULT: Error while transmitting the skb
  1530. */
  1531. static int ipa3_wwan_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  1532. {
  1533. int rc = 0;
  1534. int mru = 1000, epid = 1, mux_index, len;
  1535. struct ipa_msg_meta msg_meta;
  1536. struct ipa_wan_msg *wan_msg = NULL;
  1537. struct rmnet_ioctl_extended_s ext_ioctl_data;
  1538. struct rmnet_ioctl_data_s ioctl_data;
  1539. struct ipa3_rmnet_mux_val *mux_channel;
  1540. int rmnet_index;
  1541. uint32_t mux_id;
  1542. int8_t *v_name;
  1543. struct mutex *mux_mutex_ptr;
  1544. int wan_ep;
  1545. bool tcp_en = false, udp_en = false;
  1546. IPAWANDBG("rmnet_ipa got ioctl number 0x%08x", cmd);
  1547. switch (cmd) {
  1548. /* Set Ethernet protocol */
  1549. case RMNET_IOCTL_SET_LLP_ETHERNET:
  1550. break;
  1551. /* Set RAWIP protocol */
  1552. case RMNET_IOCTL_SET_LLP_IP:
  1553. break;
  1554. /* Get link protocol */
  1555. case RMNET_IOCTL_GET_LLP:
  1556. ioctl_data.u.operation_mode = RMNET_MODE_LLP_IP;
  1557. if (copy_to_user(ifr->ifr_ifru.ifru_data, &ioctl_data,
  1558. sizeof(struct rmnet_ioctl_data_s)))
  1559. rc = -EFAULT;
  1560. break;
  1561. /* Set QoS header enabled */
  1562. case RMNET_IOCTL_SET_QOS_ENABLE:
  1563. return -EINVAL;
  1564. /* Set QoS header disabled */
  1565. case RMNET_IOCTL_SET_QOS_DISABLE:
  1566. break;
  1567. /* Get QoS header state */
  1568. case RMNET_IOCTL_GET_QOS:
  1569. ioctl_data.u.operation_mode = RMNET_MODE_NONE;
  1570. if (copy_to_user(ifr->ifr_ifru.ifru_data, &ioctl_data,
  1571. sizeof(struct rmnet_ioctl_data_s)))
  1572. rc = -EFAULT;
  1573. break;
  1574. /* Get operation mode */
  1575. case RMNET_IOCTL_GET_OPMODE:
  1576. ioctl_data.u.operation_mode = RMNET_MODE_LLP_IP;
  1577. if (copy_to_user(ifr->ifr_ifru.ifru_data, &ioctl_data,
  1578. sizeof(struct rmnet_ioctl_data_s)))
  1579. rc = -EFAULT;
  1580. break;
  1581. /* Open transport port */
  1582. case RMNET_IOCTL_OPEN:
  1583. break;
  1584. /* Close transport port */
  1585. case RMNET_IOCTL_CLOSE:
  1586. break;
  1587. /* Flow enable */
  1588. case RMNET_IOCTL_FLOW_ENABLE:
  1589. IPAWANERR("RMNET_IOCTL_FLOW_ENABLE not supported\n");
  1590. rc = -EFAULT;
  1591. break;
  1592. /* Flow disable */
  1593. case RMNET_IOCTL_FLOW_DISABLE:
  1594. IPAWANERR("RMNET_IOCTL_FLOW_DISABLE not supported\n");
  1595. rc = -EFAULT;
  1596. break;
  1597. /* Set flow handle */
  1598. case RMNET_IOCTL_FLOW_SET_HNDL:
  1599. break;
  1600. /* Extended IOCTLs */
  1601. case RMNET_IOCTL_EXTENDED:
  1602. if (!ns_capable(dev_net(dev)->user_ns, CAP_NET_ADMIN))
  1603. return -EPERM;
  1604. IPAWANDBG("get ioctl: RMNET_IOCTL_EXTENDED\n");
  1605. if (copy_from_user(&ext_ioctl_data,
  1606. (u8 *)ifr->ifr_ifru.ifru_data,
  1607. sizeof(struct rmnet_ioctl_extended_s))) {
  1608. IPAWANERR("failed to copy extended ioctl data\n");
  1609. rc = -EFAULT;
  1610. break;
  1611. }
  1612. switch (ext_ioctl_data.extended_ioctl) {
  1613. /* Get features */
  1614. case RMNET_IOCTL_GET_SUPPORTED_FEATURES:
  1615. IPAWANDBG("get RMNET_IOCTL_GET_SUPPORTED_FEATURES\n");
  1616. ext_ioctl_data.u.data =
  1617. (RMNET_IOCTL_FEAT_NOTIFY_MUX_CHANNEL |
  1618. RMNET_IOCTL_FEAT_SET_EGRESS_DATA_FORMAT |
  1619. RMNET_IOCTL_FEAT_SET_INGRESS_DATA_FORMAT);
  1620. if (copy_to_user((u8 *)ifr->ifr_ifru.ifru_data,
  1621. &ext_ioctl_data,
  1622. sizeof(struct rmnet_ioctl_extended_s)))
  1623. rc = -EFAULT;
  1624. break;
  1625. /* Set MRU */
  1626. case RMNET_IOCTL_SET_MRU:
  1627. mru = ext_ioctl_data.u.data;
  1628. IPAWANDBG("get MRU size %d\n",
  1629. ext_ioctl_data.u.data);
  1630. break;
  1631. /* Get MRU */
  1632. case RMNET_IOCTL_GET_MRU:
  1633. ext_ioctl_data.u.data = mru;
  1634. if (copy_to_user((u8 *)ifr->ifr_ifru.ifru_data,
  1635. &ext_ioctl_data,
  1636. sizeof(struct rmnet_ioctl_extended_s)))
  1637. rc = -EFAULT;
  1638. break;
  1639. /* GET SG support */
  1640. case RMNET_IOCTL_GET_SG_SUPPORT:
  1641. ext_ioctl_data.u.data =
  1642. ipa3_rmnet_res.ipa_advertise_sg_support;
  1643. if (copy_to_user((u8 *)ifr->ifr_ifru.ifru_data,
  1644. &ext_ioctl_data,
  1645. sizeof(struct rmnet_ioctl_extended_s)))
  1646. rc = -EFAULT;
  1647. break;
  1648. /* Get endpoint ID */
  1649. case RMNET_IOCTL_GET_EPID:
  1650. IPAWANDBG("get ioctl: RMNET_IOCTL_GET_EPID\n");
  1651. ext_ioctl_data.u.data = epid;
  1652. if (copy_to_user((u8 *)ifr->ifr_ifru.ifru_data,
  1653. &ext_ioctl_data,
  1654. sizeof(struct rmnet_ioctl_extended_s)))
  1655. rc = -EFAULT;
  1656. if (copy_from_user(&ext_ioctl_data,
  1657. (u8 *)ifr->ifr_ifru.ifru_data,
  1658. sizeof(struct rmnet_ioctl_extended_s))) {
  1659. IPAWANERR("copy extended ioctl data failed\n");
  1660. rc = -EFAULT;
  1661. break;
  1662. }
  1663. IPAWANDBG("RMNET_IOCTL_GET_EPID return %d\n",
  1664. ext_ioctl_data.u.data);
  1665. break;
  1666. /* Endpoint pair */
  1667. case RMNET_IOCTL_GET_EP_PAIR:
  1668. IPAWANDBG("get ioctl: RMNET_IOCTL_GET_EP_PAIR\n");
  1669. wan_ep = ipa3_get_ep_mapping(IPA_CLIENT_APPS_WAN_CONS);
  1670. if (wan_ep == IPA_EP_NOT_ALLOCATED) {
  1671. IPAWANERR("Embedded datapath not supported\n");
  1672. rc = -EFAULT;
  1673. break;
  1674. }
  1675. ext_ioctl_data.u.ipa_ep_pair.producer_pipe_num =
  1676. wan_ep;
  1677. wan_ep = ipa3_get_ep_mapping(IPA_CLIENT_APPS_WAN_PROD);
  1678. if (wan_ep == IPA_EP_NOT_ALLOCATED) {
  1679. IPAWANERR("Embedded datapath not supported\n");
  1680. rc = -EFAULT;
  1681. break;
  1682. }
  1683. ext_ioctl_data.u.ipa_ep_pair.consumer_pipe_num =
  1684. wan_ep;
  1685. if (copy_to_user((u8 *)ifr->ifr_ifru.ifru_data,
  1686. &ext_ioctl_data,
  1687. sizeof(struct rmnet_ioctl_extended_s)))
  1688. rc = -EFAULT;
  1689. if (copy_from_user(&ext_ioctl_data,
  1690. (u8 *)ifr->ifr_ifru.ifru_data,
  1691. sizeof(struct rmnet_ioctl_extended_s))) {
  1692. IPAWANERR("copy extended ioctl data failed\n");
  1693. rc = -EFAULT;
  1694. break;
  1695. }
  1696. IPAWANDBG("RMNET_IOCTL_GET_EP_PAIR c: %d p: %d\n",
  1697. ext_ioctl_data.u.ipa_ep_pair.consumer_pipe_num,
  1698. ext_ioctl_data.u.ipa_ep_pair.producer_pipe_num);
  1699. break;
  1700. /* Get driver name */
  1701. case RMNET_IOCTL_GET_DRIVER_NAME:
  1702. if (IPA_NETDEV() != NULL) {
  1703. memcpy(&ext_ioctl_data.u.if_name,
  1704. IPA_NETDEV()->name, IFNAMSIZ);
  1705. ext_ioctl_data.u.if_name[IFNAMSIZ - 1] = '\0';
  1706. if (copy_to_user(ifr->ifr_ifru.ifru_data,
  1707. &ext_ioctl_data,
  1708. sizeof(struct rmnet_ioctl_extended_s)))
  1709. rc = -EFAULT;
  1710. } else {
  1711. IPAWANDBG("IPA_NETDEV is NULL\n");
  1712. rc = -EFAULT;
  1713. }
  1714. break;
  1715. /* Add MUX ID */
  1716. case RMNET_IOCTL_ADD_MUX_CHANNEL:
  1717. mux_id = ext_ioctl_data.u.rmnet_mux_val.mux_id;
  1718. mux_index = ipa3_find_mux_channel_index(
  1719. ext_ioctl_data.u.rmnet_mux_val.mux_id);
  1720. if (mux_index < MAX_NUM_OF_MUX_CHANNEL) {
  1721. IPAWANDBG("already setup mux(%d)\n", mux_id);
  1722. return rc;
  1723. }
  1724. mutex_lock(&rmnet_ipa3_ctx->add_mux_channel_lock);
  1725. if (rmnet_ipa3_ctx->rmnet_index
  1726. >= MAX_NUM_OF_MUX_CHANNEL) {
  1727. IPAWANERR("Exceed mux_channel limit(%d)\n",
  1728. rmnet_ipa3_ctx->rmnet_index);
  1729. mutex_unlock(
  1730. &rmnet_ipa3_ctx->add_mux_channel_lock);
  1731. return -EFAULT;
  1732. }
  1733. ext_ioctl_data.u.rmnet_mux_val.vchannel_name
  1734. [IFNAMSIZ-1] = '\0';
  1735. IPAWANDBG("ADD_MUX_CHANNEL(%d, name: %s)\n",
  1736. ext_ioctl_data.u.rmnet_mux_val.mux_id,
  1737. ext_ioctl_data.u.rmnet_mux_val.vchannel_name);
  1738. /* cache the mux name and id */
  1739. mux_channel = rmnet_ipa3_ctx->mux_channel;
  1740. rmnet_index = rmnet_ipa3_ctx->rmnet_index;
  1741. mux_channel[rmnet_index].mux_id =
  1742. ext_ioctl_data.u.rmnet_mux_val.mux_id;
  1743. memcpy(mux_channel[rmnet_index].vchannel_name,
  1744. ext_ioctl_data.u.rmnet_mux_val.vchannel_name,
  1745. sizeof(mux_channel[rmnet_index]
  1746. .vchannel_name));
  1747. mux_channel[rmnet_index].vchannel_name[
  1748. IFNAMSIZ - 1] = '\0';
  1749. IPAWANDBG("cashe device[%s:%d] in IPA_wan[%d]\n",
  1750. mux_channel[rmnet_index].vchannel_name,
  1751. mux_channel[rmnet_index].mux_id,
  1752. rmnet_index);
  1753. /* check if UL filter rules coming*/
  1754. v_name =
  1755. ext_ioctl_data.u.rmnet_mux_val.vchannel_name;
  1756. if (rmnet_ipa3_ctx->num_q6_rules != 0 ||
  1757. (rmnet_ipa3_ctx->ipa_config_is_apq)) {
  1758. mux_mutex_ptr =
  1759. &rmnet_ipa3_ctx->add_mux_channel_lock;
  1760. IPAWANERR_RL("dev(%s) register to IPA\n",
  1761. v_name);
  1762. rc = ipa3_wwan_register_to_ipa(
  1763. rmnet_ipa3_ctx->rmnet_index);
  1764. if (rc < 0) {
  1765. IPAWANERR("device %s reg IPA failed\n",
  1766. v_name);
  1767. mutex_unlock(mux_mutex_ptr);
  1768. return -ENODEV;
  1769. }
  1770. mux_channel[rmnet_index].mux_channel_set =
  1771. true;
  1772. mux_channel[rmnet_index].ul_flt_reg =
  1773. true;
  1774. } else {
  1775. IPAWANDBG("dev(%s) haven't registered to IPA\n",
  1776. v_name);
  1777. mux_channel[rmnet_index].mux_channel_set =
  1778. true;
  1779. mux_channel[rmnet_index].ul_flt_reg =
  1780. false;
  1781. }
  1782. rmnet_ipa3_ctx->rmnet_index++;
  1783. mutex_unlock(&rmnet_ipa3_ctx->add_mux_channel_lock);
  1784. break;
  1785. case RMNET_IOCTL_SET_EGRESS_DATA_FORMAT:
  1786. rc = handle3_egress_format(dev, &ext_ioctl_data);
  1787. break;
  1788. case RMNET_IOCTL_SET_INGRESS_DATA_FORMAT:/* Set IDF */
  1789. rc = handle3_ingress_format(dev, &ext_ioctl_data);
  1790. break;
  1791. case RMNET_IOCTL_SET_XLAT_DEV_INFO:
  1792. wan_msg = kzalloc(sizeof(struct ipa_wan_msg),
  1793. GFP_KERNEL);
  1794. if (!wan_msg)
  1795. return -ENOMEM;
  1796. ext_ioctl_data.u.if_name[IFNAMSIZ-1] = '\0';
  1797. len = sizeof(wan_msg->upstream_ifname) >
  1798. sizeof(ext_ioctl_data.u.if_name) ?
  1799. sizeof(ext_ioctl_data.u.if_name) :
  1800. sizeof(wan_msg->upstream_ifname);
  1801. strlcpy(wan_msg->upstream_ifname,
  1802. ext_ioctl_data.u.if_name, len);
  1803. wan_msg->upstream_ifname[len-1] = '\0';
  1804. memset(&msg_meta, 0, sizeof(struct ipa_msg_meta));
  1805. msg_meta.msg_type = WAN_XLAT_CONNECT;
  1806. msg_meta.msg_len = sizeof(struct ipa_wan_msg);
  1807. rc = ipa3_send_msg(&msg_meta, wan_msg,
  1808. ipa3_wwan_msg_free_cb);
  1809. if (rc) {
  1810. IPAWANERR("Failed to send XLAT_CONNECT msg\n");
  1811. kfree(wan_msg);
  1812. }
  1813. break;
  1814. /* Get agg count */
  1815. case RMNET_IOCTL_GET_AGGREGATION_COUNT:
  1816. break;
  1817. /* Set agg count */
  1818. case RMNET_IOCTL_SET_AGGREGATION_COUNT:
  1819. break;
  1820. /* Get agg size */
  1821. case RMNET_IOCTL_GET_AGGREGATION_SIZE:
  1822. break;
  1823. /* Set agg size */
  1824. case RMNET_IOCTL_SET_AGGREGATION_SIZE:
  1825. break;
  1826. /* Do flow control */
  1827. case RMNET_IOCTL_FLOW_CONTROL:
  1828. break;
  1829. /* For legacy use */
  1830. case RMNET_IOCTL_GET_DFLT_CONTROL_CHANNEL:
  1831. break;
  1832. /* Get HW/SW map */
  1833. case RMNET_IOCTL_GET_HWSW_MAP:
  1834. break;
  1835. /* Set RX Headroom */
  1836. case RMNET_IOCTL_SET_RX_HEADROOM:
  1837. break;
  1838. /* Set RSC/RSB */
  1839. case RMNET_IOCTL_SET_OFFLOAD:
  1840. if (ext_ioctl_data.u.offload_params.flags
  1841. & RMNET_IOCTL_COALESCING_FORMAT_TCP)
  1842. tcp_en = true;
  1843. if (ext_ioctl_data.u.offload_params.flags
  1844. & RMNET_IOCTL_COALESCING_FORMAT_UDP)
  1845. udp_en = true;
  1846. rc = rmnet_ipa_send_coalesce_notification(
  1847. ext_ioctl_data.u.offload_params.mux_id,
  1848. tcp_en || udp_en, tcp_en, udp_en);
  1849. break;
  1850. default:
  1851. IPAWANERR("[%s] unsupported extended cmd[%d]",
  1852. dev->name,
  1853. ext_ioctl_data.extended_ioctl);
  1854. rc = -EINVAL;
  1855. }
  1856. break;
  1857. default:
  1858. IPAWANERR("[%s] unsupported cmd[%d]",
  1859. dev->name, cmd);
  1860. rc = -EINVAL;
  1861. }
  1862. return rc;
  1863. }
  1864. static const struct net_device_ops ipa3_wwan_ops_ip = {
  1865. .ndo_open = ipa3_wwan_open,
  1866. .ndo_stop = ipa3_wwan_stop,
  1867. .ndo_start_xmit = ipa3_wwan_xmit,
  1868. .ndo_tx_timeout = ipa3_wwan_tx_timeout,
  1869. .ndo_do_ioctl = ipa3_wwan_ioctl,
  1870. .ndo_change_mtu = ipa3_wwan_change_mtu,
  1871. .ndo_set_mac_address = 0,
  1872. .ndo_validate_addr = 0,
  1873. };
  1874. /**
  1875. * wwan_setup() - Setups the wwan network driver.
  1876. *
  1877. * @dev: network device
  1878. *
  1879. * Return codes:
  1880. * None
  1881. */
  1882. static void ipa3_wwan_setup(struct net_device *dev)
  1883. {
  1884. dev->netdev_ops = &ipa3_wwan_ops_ip;
  1885. ether_setup(dev);
  1886. /* set this after calling ether_setup */
  1887. dev->header_ops = 0; /* No header */
  1888. dev->type = ARPHRD_RAWIP;
  1889. dev->hard_header_len = 0;
  1890. dev->mtu = WWAN_DATA_LEN;
  1891. dev->addr_len = 0;
  1892. dev->flags &= ~(IFF_BROADCAST | IFF_MULTICAST);
  1893. dev->needed_headroom = HEADROOM_FOR_QMAP;
  1894. dev->needed_tailroom = TAILROOM;
  1895. dev->watchdog_timeo = 1000;
  1896. }
  1897. /**
  1898. * rmnet_ipa_send_coalesce_notification
  1899. * (uint8_t qmap_id, bool enable, bool tcp, bool udp)
  1900. * send RSC notification
  1901. *
  1902. * This function sends the rsc enable/disable notification
  1903. * fot tcp, udp to user-space module
  1904. */
  1905. static int rmnet_ipa_send_coalesce_notification(uint8_t qmap_id,
  1906. bool enable,
  1907. bool tcp,
  1908. bool udp)
  1909. {
  1910. struct ipa_msg_meta msg_meta;
  1911. struct ipa_coalesce_info *coalesce_info;
  1912. int rc;
  1913. memset(&msg_meta, 0, sizeof(struct ipa_msg_meta));
  1914. coalesce_info = kzalloc(sizeof(*coalesce_info), GFP_KERNEL);
  1915. if (!coalesce_info)
  1916. return -ENOMEM;
  1917. if (enable) {
  1918. coalesce_info->qmap_id = qmap_id;
  1919. coalesce_info->tcp_enable = tcp;
  1920. coalesce_info->udp_enable = udp;
  1921. msg_meta.msg_type = IPA_COALESCE_ENABLE;
  1922. msg_meta.msg_len = sizeof(struct ipa_coalesce_info);
  1923. } else {
  1924. msg_meta.msg_type = IPA_COALESCE_DISABLE;
  1925. msg_meta.msg_len = sizeof(struct ipa_coalesce_info);
  1926. }
  1927. rc = ipa_send_msg(&msg_meta, coalesce_info, ipa3_wwan_msg_free_cb);
  1928. if (rc) {
  1929. IPAWANERR("ipa_send_msg failed: %d\n", rc);
  1930. return -EFAULT;
  1931. }
  1932. IPAWANDBG("qmap-id(%d),enable(%d),tcp(%d),udp(%d)\n",
  1933. qmap_id, enable, tcp, udp);
  1934. return 0;
  1935. }
  1936. int ipa3_wwan_set_modem_state(struct wan_ioctl_notify_wan_state *state)
  1937. {
  1938. uint32_t bw_mbps = 0;
  1939. int ret = 0;
  1940. if (!state)
  1941. return -EINVAL;
  1942. if (state->up) {
  1943. if (rmnet_ipa3_ctx->ipa_config_is_apq) {
  1944. bw_mbps = 5200;
  1945. ret = ipa3_vote_for_bus_bw(&bw_mbps);
  1946. if (ret) {
  1947. IPAERR("Failed to vote for bus BW (%u)\n",
  1948. bw_mbps);
  1949. return ret;
  1950. }
  1951. }
  1952. ret = ipa_pm_activate_sync(rmnet_ipa3_ctx->q6_teth_pm_hdl);
  1953. } else {
  1954. if (rmnet_ipa3_ctx->ipa_config_is_apq) {
  1955. bw_mbps = 0;
  1956. ret = ipa3_vote_for_bus_bw(&bw_mbps);
  1957. if (ret) {
  1958. IPAERR("Failed to vote for bus BW (%u)\n",
  1959. bw_mbps);
  1960. return ret;
  1961. }
  1962. }
  1963. ret = ipa_pm_deactivate_sync(rmnet_ipa3_ctx->q6_teth_pm_hdl);
  1964. }
  1965. return ret;
  1966. }
  1967. /**
  1968. * ipa3_q6_register_pm - Register modem clients for PM
  1969. *
  1970. * This function will register 2 client with IPA PM to represent modem
  1971. * in clock scaling calculation:
  1972. * - "EMB MODEM" - this client will be activated with embedded traffic
  1973. - "TETH MODEM" - this client we be activated by IPACM on offload to
  1974. modem.
  1975. */
  1976. static int ipa3_q6_register_pm(void)
  1977. {
  1978. int result;
  1979. struct ipa_pm_register_params pm_reg;
  1980. memset(&pm_reg, 0, sizeof(pm_reg));
  1981. pm_reg.name = "EMB MODEM";
  1982. pm_reg.group = IPA_PM_GROUP_MODEM;
  1983. pm_reg.skip_clk_vote = true;
  1984. result = ipa_pm_register(&pm_reg, &rmnet_ipa3_ctx->q6_pm_hdl);
  1985. if (result) {
  1986. IPAERR("failed to create IPA PM client %d\n", result);
  1987. return result;
  1988. }
  1989. pm_reg.name = "TETH MODEM";
  1990. pm_reg.group = IPA_PM_GROUP_MODEM;
  1991. pm_reg.skip_clk_vote = true;
  1992. result = ipa_pm_register(&pm_reg, &rmnet_ipa3_ctx->q6_teth_pm_hdl);
  1993. if (result) {
  1994. IPAERR("failed to create IPA PM client %d\n", result);
  1995. return result;
  1996. }
  1997. return 0;
  1998. }
  1999. static void ipa3_q6_deregister_pm(void)
  2000. {
  2001. ipa_pm_deactivate_sync(rmnet_ipa3_ctx->q6_pm_hdl);
  2002. ipa_pm_deregister(rmnet_ipa3_ctx->q6_pm_hdl);
  2003. }
  2004. int ipa3_wwan_set_modem_perf_profile(int throughput)
  2005. {
  2006. int ret;
  2007. IPAWANDBG("throughput: %d\n", throughput);
  2008. /* for TETH MODEM on softap/rndis */
  2009. ret = ipa_pm_set_throughput(rmnet_ipa3_ctx->q6_teth_pm_hdl,
  2010. throughput);
  2011. return ret;
  2012. }
  2013. static void ipa3_wake_tx_queue(struct work_struct *work)
  2014. {
  2015. if (IPA_NETDEV()) {
  2016. __netif_tx_lock_bh(netdev_get_tx_queue(IPA_NETDEV(), 0));
  2017. IPAWANDBG("Waking up the workqueue.\n");
  2018. netif_wake_queue(IPA_NETDEV());
  2019. __netif_tx_unlock_bh(netdev_get_tx_queue(IPA_NETDEV(), 0));
  2020. }
  2021. }
  2022. /**
  2023. * ipa3_pm_resource_granted() - Called upon
  2024. * IPA_PM_RESOURCE_GRANTED event. Wakes up the tx workqueue.
  2025. *
  2026. * @work: work object supplied ny workqueue
  2027. *
  2028. * Return codes:
  2029. * None
  2030. */
  2031. static void ipa3_pm_resource_granted(void *dev)
  2032. {
  2033. IPAWANDBG_LOW("Resource Granted - starting queue\n");
  2034. schedule_work(&ipa3_tx_wakequeue_work);
  2035. }
  2036. /* IPA_PM related functions end*/
  2037. static int ipa3_lcl_mdm_ssr_notifier_cb(struct notifier_block *this,
  2038. unsigned long code,
  2039. void *data);
  2040. static int ipa3_rmt_mdm_ssr_notifier_cb(struct notifier_block *this,
  2041. unsigned long code,
  2042. void *data);
  2043. static struct notifier_block ipa3_lcl_mdm_ssr_notifier = {
  2044. .notifier_call = ipa3_lcl_mdm_ssr_notifier_cb,
  2045. };
  2046. static struct notifier_block ipa3_rmt_mdm_ssr_notifier = {
  2047. .notifier_call = ipa3_rmt_mdm_ssr_notifier_cb,
  2048. };
  2049. static int get_ipa_rmnet_dts_configuration(struct platform_device *pdev,
  2050. struct ipa3_rmnet_plat_drv_res *ipa_rmnet_drv_res)
  2051. {
  2052. int result;
  2053. ipa_rmnet_drv_res->wan_rx_desc_size = IPA_WWAN_CONS_DESC_FIFO_SZ;
  2054. ipa_rmnet_drv_res->ipa_rmnet_ssr =
  2055. of_property_read_bool(pdev->dev.of_node,
  2056. "qcom,rmnet-ipa-ssr");
  2057. pr_info("IPA SSR support = %s\n",
  2058. ipa_rmnet_drv_res->ipa_rmnet_ssr ? "True" : "False");
  2059. ipa_rmnet_drv_res->ipa_advertise_sg_support =
  2060. of_property_read_bool(pdev->dev.of_node,
  2061. "qcom,ipa-advertise-sg-support");
  2062. pr_info("IPA SG support = %s\n",
  2063. ipa_rmnet_drv_res->ipa_advertise_sg_support ? "True" : "False");
  2064. ipa_rmnet_drv_res->ipa_napi_enable =
  2065. of_property_read_bool(pdev->dev.of_node,
  2066. "qcom,ipa-napi-enable");
  2067. pr_info("IPA Napi Enable = %s\n",
  2068. ipa_rmnet_drv_res->ipa_napi_enable ? "True" : "False");
  2069. /* Get IPA WAN RX desc fifo size */
  2070. result = of_property_read_u32(pdev->dev.of_node,
  2071. "qcom,wan-rx-desc-size",
  2072. &ipa_rmnet_drv_res->wan_rx_desc_size);
  2073. if (result)
  2074. pr_info("using default for wan-rx-desc-size = %u\n",
  2075. ipa_rmnet_drv_res->wan_rx_desc_size);
  2076. else
  2077. IPAWANDBG(": found ipa_drv_res->wan-rx-desc-size = %u\n",
  2078. ipa_rmnet_drv_res->wan_rx_desc_size);
  2079. return 0;
  2080. }
  2081. struct ipa3_rmnet_context ipa3_rmnet_ctx;
  2082. static int ipa3_wwan_probe(struct platform_device *pdev);
  2083. struct platform_device *m_pdev;
  2084. static void ipa3_delayed_probe(struct work_struct *work)
  2085. {
  2086. (void)ipa3_wwan_probe(m_pdev);
  2087. }
  2088. static DECLARE_WORK(ipa3_scheduled_probe, ipa3_delayed_probe);
  2089. static void ipa3_ready_cb(void *user_data)
  2090. {
  2091. struct platform_device *pdev = (struct platform_device *)(user_data);
  2092. m_pdev = pdev;
  2093. IPAWANDBG("IPA ready callback has been triggered\n");
  2094. schedule_work(&ipa3_scheduled_probe);
  2095. }
  2096. static void ipa_pm_wwan_pm_cb(void *p, enum ipa_pm_cb_event event)
  2097. {
  2098. struct net_device *dev = (struct net_device *)p;
  2099. struct ipa3_wwan_private *wwan_ptr = netdev_priv(dev);
  2100. IPAWANDBG_LOW("event %d\n", event);
  2101. switch (event) {
  2102. case IPA_PM_CLIENT_ACTIVATED:
  2103. if (wwan_ptr->device_status == WWAN_DEVICE_INACTIVE) {
  2104. complete_all(&wwan_ptr->resource_granted_completion);
  2105. break;
  2106. }
  2107. ipa3_pm_resource_granted(dev);
  2108. break;
  2109. default:
  2110. pr_err("%s: unknown event %d\n", __func__, event);
  2111. break;
  2112. }
  2113. }
  2114. static int ipa3_wwan_register_netdev_pm_client(struct net_device *dev)
  2115. {
  2116. int result;
  2117. struct ipa_pm_register_params pm_reg;
  2118. memset(&pm_reg, 0, sizeof(pm_reg));
  2119. pm_reg.name = IPA_NETDEV()->name;
  2120. pm_reg.user_data = dev;
  2121. pm_reg.callback = ipa_pm_wwan_pm_cb;
  2122. pm_reg.group = IPA_PM_GROUP_APPS;
  2123. result = ipa_pm_register(&pm_reg, &rmnet_ipa3_ctx->pm_hdl);
  2124. if (result) {
  2125. IPAERR("failed to create IPA PM client %d\n", result);
  2126. return result;
  2127. }
  2128. return 0;
  2129. }
  2130. static void ipa3_wwan_deregister_netdev_pm_client(void)
  2131. {
  2132. ipa_pm_deactivate_sync(rmnet_ipa3_ctx->pm_hdl);
  2133. ipa_pm_deregister(rmnet_ipa3_ctx->pm_hdl);
  2134. }
  2135. /**
  2136. * ipa3_wwan_probe() - Initialized the module and registers as a
  2137. * network interface to the network stack
  2138. *
  2139. * Note: In case IPA driver hasn't initialized already, the probe function
  2140. * will return immediately after registering a callback to be invoked when
  2141. * IPA driver initialization is complete.
  2142. *
  2143. * Return codes:
  2144. * 0: success
  2145. * -ENOMEM: No memory available
  2146. * -EFAULT: Internal error
  2147. */
  2148. static int ipa3_wwan_probe(struct platform_device *pdev)
  2149. {
  2150. int ret, i;
  2151. struct net_device *dev;
  2152. int wan_cons_ep;
  2153. pr_info("rmnet_ipa3 started initialization\n");
  2154. if (!ipa3_is_ready()) {
  2155. IPAWANDBG("IPA driver not ready, registering callback\n");
  2156. ret = ipa_register_ipa_ready_cb(ipa3_ready_cb, (void *)pdev);
  2157. /*
  2158. * If we received -EEXIST, IPA has initialized. So we need
  2159. * to continue the probing process.
  2160. */
  2161. if (ret != -EEXIST) {
  2162. if (ret)
  2163. IPAWANERR("IPA CB reg failed - %d\n", ret);
  2164. return ret;
  2165. }
  2166. }
  2167. wan_cons_ep = ipa3_get_ep_mapping(IPA_CLIENT_APPS_WAN_CONS);
  2168. ret = get_ipa_rmnet_dts_configuration(pdev, &ipa3_rmnet_res);
  2169. ipa3_rmnet_ctx.ipa_rmnet_ssr = ipa3_rmnet_res.ipa_rmnet_ssr;
  2170. /* check if booting as mhi-prime */
  2171. rmnet_ipa3_ctx->ipa_config_is_apq
  2172. = ipa3_is_apq();
  2173. ret = ipa3_init_q6_smem();
  2174. if (ret) {
  2175. IPAWANERR("ipa3_init_q6_smem failed\n");
  2176. return ret;
  2177. }
  2178. /* initialize tx/rx endpoint setup */
  2179. memset(&rmnet_ipa3_ctx->apps_to_ipa_ep_cfg, 0,
  2180. sizeof(struct ipa_sys_connect_params));
  2181. memset(&rmnet_ipa3_ctx->ipa_to_apps_ep_cfg, 0,
  2182. sizeof(struct ipa_sys_connect_params));
  2183. /* initialize ex property setup */
  2184. rmnet_ipa3_ctx->num_q6_rules = 0;
  2185. rmnet_ipa3_ctx->old_num_q6_rules = 0;
  2186. rmnet_ipa3_ctx->rmnet_index = 0;
  2187. rmnet_ipa3_ctx->egress_set = false;
  2188. rmnet_ipa3_ctx->a7_ul_flt_set = false;
  2189. rmnet_ipa3_ctx->ipa_mhi_aggr_formet_set = false;
  2190. for (i = 0; i < MAX_NUM_OF_MUX_CHANNEL; i++)
  2191. memset(&rmnet_ipa3_ctx->mux_channel[i], 0,
  2192. sizeof(struct ipa3_rmnet_mux_val));
  2193. /* start A7 QMI service/client */
  2194. if (ipa3_ctx->platform_type == IPA_PLAT_TYPE_MSM ||
  2195. ipa3_ctx->platform_type == IPA_PLAT_TYPE_APQ)
  2196. /* Android platform loads uC */
  2197. ipa3_qmi_service_init(QMI_IPA_PLATFORM_TYPE_MSM_ANDROID_V01);
  2198. else if (ipa3_ctx->ipa_config_is_mhi)
  2199. /* LE MHI platform */
  2200. ipa3_qmi_service_init(QMI_IPA_PLATFORM_TYPE_LE_MHI_V01);
  2201. else
  2202. /* LE platform not loads uC */
  2203. ipa3_qmi_service_init(QMI_IPA_PLATFORM_TYPE_LE_V01);
  2204. if (!atomic_read(&rmnet_ipa3_ctx->is_ssr)) {
  2205. /* Start transport-driver fd ioctl for ipacm for first init */
  2206. ret = ipa3_wan_ioctl_init();
  2207. if (ret)
  2208. goto wan_ioctl_init_err;
  2209. } else {
  2210. /* Enable sending QMI messages after SSR */
  2211. ipa3_wan_ioctl_enable_qmi_messages();
  2212. }
  2213. /* initialize wan-driver netdev */
  2214. dev = alloc_netdev(sizeof(struct ipa3_wwan_private),
  2215. IPA_WWAN_DEV_NAME,
  2216. NET_NAME_UNKNOWN,
  2217. ipa3_wwan_setup);
  2218. if (!dev) {
  2219. IPAWANERR("no memory for netdev\n");
  2220. ret = -ENOMEM;
  2221. goto alloc_netdev_err;
  2222. }
  2223. rmnet_ipa3_ctx->wwan_priv = netdev_priv(dev);
  2224. memset(rmnet_ipa3_ctx->wwan_priv, 0,
  2225. sizeof(*(rmnet_ipa3_ctx->wwan_priv)));
  2226. IPAWANDBG("wwan_ptr (private) = %pK", rmnet_ipa3_ctx->wwan_priv);
  2227. rmnet_ipa3_ctx->wwan_priv->net = dev;
  2228. atomic_set(&rmnet_ipa3_ctx->wwan_priv->outstanding_pkts, 0);
  2229. spin_lock_init(&rmnet_ipa3_ctx->wwan_priv->lock);
  2230. init_completion(
  2231. &rmnet_ipa3_ctx->wwan_priv->resource_granted_completion);
  2232. if (!atomic_read(&rmnet_ipa3_ctx->is_ssr)) {
  2233. /* IPA_PM configuration starts */
  2234. ret = ipa3_q6_register_pm();
  2235. if (ret) {
  2236. IPAWANERR("ipa3_q6_register_pm failed, ret: %d\n",
  2237. ret);
  2238. goto q6_init_err;
  2239. }
  2240. }
  2241. ret = ipa3_wwan_register_netdev_pm_client(dev);
  2242. if (ret) {
  2243. IPAWANERR("fail to create/register pm resources\n");
  2244. goto fail_pm;
  2245. }
  2246. /* Enable SG support in netdevice. */
  2247. if (ipa3_rmnet_res.ipa_advertise_sg_support)
  2248. dev->hw_features |= NETIF_F_SG;
  2249. if (ipa3_rmnet_res.ipa_napi_enable)
  2250. netif_napi_add(dev, &(rmnet_ipa3_ctx->wwan_priv->napi),
  2251. ipa3_rmnet_poll, NAPI_WEIGHT);
  2252. ret = register_netdev(dev);
  2253. if (ret) {
  2254. IPAWANERR("unable to register ipa_netdev %d rc=%d\n",
  2255. 0, ret);
  2256. goto set_perf_err;
  2257. }
  2258. IPAWANDBG("IPA-WWAN devices (%s) initialization ok :>>>>\n", dev->name);
  2259. if (ret) {
  2260. IPAWANERR("default configuration failed rc=%d\n",
  2261. ret);
  2262. goto config_err;
  2263. }
  2264. /* for > IPA 4.5, we set the colaescing feature flag on */
  2265. if (ipa3_ctx->ipa_hw_type >= IPA_HW_v4_5)
  2266. dev->hw_features |= NETIF_F_GRO_HW | NETIF_F_RXCSUM;
  2267. /*
  2268. * for IPA 4.0 offline charge is not needed and we need to prevent
  2269. * power collapse until IPA uC is loaded.
  2270. */
  2271. atomic_set(&rmnet_ipa3_ctx->is_initialized, 1);
  2272. if (!atomic_read(&rmnet_ipa3_ctx->is_ssr) && ipa3_ctx->ipa_hw_type !=
  2273. IPA_HW_v4_0) {
  2274. /* offline charging mode */
  2275. ipa3_proxy_clk_unvote();
  2276. }
  2277. atomic_set(&rmnet_ipa3_ctx->is_ssr, 0);
  2278. atomic_set(&rmnet_ipa3_ctx->ap_suspend, 0);
  2279. ipa3_update_ssr_state(false);
  2280. IPAWANERR("rmnet_ipa completed initialization\n");
  2281. return 0;
  2282. config_err:
  2283. if (ipa3_rmnet_res.ipa_napi_enable)
  2284. netif_napi_del(&(rmnet_ipa3_ctx->wwan_priv->napi));
  2285. unregister_netdev(dev);
  2286. set_perf_err:
  2287. ipa3_wwan_deregister_netdev_pm_client();
  2288. fail_pm:
  2289. if (!atomic_read(&rmnet_ipa3_ctx->is_ssr))
  2290. ipa3_q6_deregister_pm();
  2291. q6_init_err:
  2292. free_netdev(dev);
  2293. rmnet_ipa3_ctx->wwan_priv = NULL;
  2294. alloc_netdev_err:
  2295. ipa3_wan_ioctl_deinit();
  2296. wan_ioctl_init_err:
  2297. ipa3_qmi_service_exit();
  2298. atomic_set(&rmnet_ipa3_ctx->is_ssr, 0);
  2299. return ret;
  2300. }
  2301. static int ipa3_wwan_remove(struct platform_device *pdev)
  2302. {
  2303. int ret;
  2304. IPAWANINFO("rmnet_ipa started deinitialization\n");
  2305. mutex_lock(&rmnet_ipa3_ctx->pipe_handle_guard);
  2306. ret = ipa3_teardown_sys_pipe(rmnet_ipa3_ctx->ipa3_to_apps_hdl);
  2307. if (ret < 0)
  2308. IPAWANERR("Failed to teardown IPA->APPS pipe\n");
  2309. else
  2310. rmnet_ipa3_ctx->ipa3_to_apps_hdl = -1;
  2311. ret = ipa3_teardown_sys_pipe(rmnet_ipa3_ctx->apps_to_ipa3_hdl);
  2312. if (ret < 0)
  2313. IPAWANERR("Failed to teardown APPS->IPA pipe\n");
  2314. else
  2315. rmnet_ipa3_ctx->apps_to_ipa3_hdl = -1;
  2316. if (ipa3_rmnet_res.ipa_napi_enable)
  2317. netif_napi_del(&(rmnet_ipa3_ctx->wwan_priv->napi));
  2318. mutex_unlock(&rmnet_ipa3_ctx->pipe_handle_guard);
  2319. IPAWANINFO("rmnet_ipa unregister_netdev\n");
  2320. unregister_netdev(IPA_NETDEV());
  2321. ipa3_wwan_deregister_netdev_pm_client();
  2322. cancel_work_sync(&ipa3_tx_wakequeue_work);
  2323. cancel_delayed_work(&ipa_tether_stats_poll_wakequeue_work);
  2324. if (IPA_NETDEV())
  2325. free_netdev(IPA_NETDEV());
  2326. rmnet_ipa3_ctx->wwan_priv = NULL;
  2327. /* No need to remove wwan_ioctl during SSR */
  2328. if (!atomic_read(&rmnet_ipa3_ctx->is_ssr))
  2329. ipa3_wan_ioctl_deinit();
  2330. if (ipa3_get_ep_mapping(IPA_CLIENT_APPS_WAN_CONS) !=
  2331. IPA_EP_NOT_ALLOCATED) {
  2332. ipa3_del_dflt_wan_rt_tables();
  2333. ipa3_del_a7_qmap_hdr();
  2334. }
  2335. ipa3_del_mux_qmap_hdrs();
  2336. if (!ipa3_qmi_ctx->modem_cfg_emb_pipe_flt)
  2337. ipa3_wwan_del_ul_flt_rule_to_ipa();
  2338. ipa3_cleanup_deregister_intf();
  2339. /* reset dl_csum_offload_enabled */
  2340. rmnet_ipa3_ctx->dl_csum_offload_enabled = false;
  2341. atomic_set(&rmnet_ipa3_ctx->is_initialized, 0);
  2342. IPAWANINFO("rmnet_ipa completed deinitialization\n");
  2343. return 0;
  2344. }
  2345. /**
  2346. * rmnet_ipa_ap_suspend() - suspend callback for runtime_pm
  2347. * @dev: pointer to device
  2348. *
  2349. * This callback will be invoked by the runtime_pm framework when an AP suspend
  2350. * operation is invoked, usually by pressing a suspend button.
  2351. *
  2352. * Returns -EAGAIN to runtime_pm framework in case there are pending packets
  2353. * in the Tx queue. This will postpone the suspend operation until all the
  2354. * pending packets will be transmitted.
  2355. *
  2356. * In case there are no packets to send, releases the WWAN0_PROD entity.
  2357. * As an outcome, the number of IPA active clients should be decremented
  2358. * until IPA clocks can be gated.
  2359. */
  2360. static int rmnet_ipa_ap_suspend(struct device *dev)
  2361. {
  2362. struct net_device *netdev = IPA_NETDEV();
  2363. struct ipa3_wwan_private *wwan_ptr;
  2364. int ret;
  2365. unsigned long flags;
  2366. IPAWANDBG("Enter...\n");
  2367. if (netdev == NULL) {
  2368. IPAWANERR("netdev is NULL.\n");
  2369. ret = 0;
  2370. goto bail;
  2371. }
  2372. wwan_ptr = netdev_priv(netdev);
  2373. if (wwan_ptr == NULL) {
  2374. IPAWANERR("wwan_ptr is NULL.\n");
  2375. ret = 0;
  2376. goto bail;
  2377. }
  2378. /*
  2379. * Rmnert supend and xmit are executing at the same time, In those
  2380. * scenarios observing the data was processed when IPA clock are off.
  2381. * Added changes to synchronize rmnet supend and xmit.
  2382. */
  2383. atomic_set(&rmnet_ipa3_ctx->ap_suspend, 1);
  2384. spin_lock_irqsave(&wwan_ptr->lock, flags);
  2385. /* Do not allow A7 to suspend in case there are outstanding packets */
  2386. if (atomic_read(&wwan_ptr->outstanding_pkts) != 0) {
  2387. IPAWANDBG("Outstanding packets, postponing AP suspend.\n");
  2388. ret = -EAGAIN;
  2389. atomic_set(&rmnet_ipa3_ctx->ap_suspend, 0);
  2390. spin_unlock_irqrestore(&wwan_ptr->lock, flags);
  2391. goto bail;
  2392. }
  2393. /* Make sure that there is no Tx operation ongoing */
  2394. netif_stop_queue(netdev);
  2395. spin_unlock_irqrestore(&wwan_ptr->lock, flags);
  2396. IPAWANDBG("De-activating the PM resource.\n");
  2397. ipa_pm_deactivate_sync(rmnet_ipa3_ctx->pm_hdl);
  2398. ret = 0;
  2399. bail:
  2400. IPAWANDBG("Exit with %d\n", ret);
  2401. return ret;
  2402. }
  2403. /**
  2404. * rmnet_ipa_ap_resume() - resume callback for runtime_pm
  2405. * @dev: pointer to device
  2406. *
  2407. * This callback will be invoked by the runtime_pm framework when an AP resume
  2408. * operation is invoked.
  2409. *
  2410. * Enables the network interface queue and returns success to the
  2411. * runtime_pm framework.
  2412. */
  2413. static int rmnet_ipa_ap_resume(struct device *dev)
  2414. {
  2415. struct net_device *netdev = IPA_NETDEV();
  2416. IPAWANDBG("Enter...\n");
  2417. /* Clear the suspend in progress flag. */
  2418. atomic_set(&rmnet_ipa3_ctx->ap_suspend, 0);
  2419. if (netdev)
  2420. netif_wake_queue(netdev);
  2421. IPAWANDBG("Exit\n");
  2422. return 0;
  2423. }
  2424. static void ipa_stop_polling_stats(void)
  2425. {
  2426. cancel_delayed_work(&ipa_tether_stats_poll_wakequeue_work);
  2427. ipa3_rmnet_ctx.polling_interval = 0;
  2428. }
  2429. static const struct of_device_id rmnet_ipa_dt_match[] = {
  2430. {.compatible = "qcom,rmnet-ipa3"},
  2431. {},
  2432. };
  2433. MODULE_DEVICE_TABLE(of, rmnet_ipa_dt_match);
  2434. static const struct dev_pm_ops rmnet_ipa_pm_ops = {
  2435. .suspend_noirq = rmnet_ipa_ap_suspend,
  2436. .resume_noirq = rmnet_ipa_ap_resume,
  2437. };
  2438. static struct platform_driver rmnet_ipa_driver = {
  2439. .driver = {
  2440. .name = "rmnet_ipa3",
  2441. .pm = &rmnet_ipa_pm_ops,
  2442. .of_match_table = rmnet_ipa_dt_match,
  2443. },
  2444. .probe = ipa3_wwan_probe,
  2445. .remove = ipa3_wwan_remove,
  2446. };
  2447. /**
  2448. * rmnet_ipa_send_ssr_notification(bool ssr_done) - send SSR notification
  2449. *
  2450. * This function sends the SSR notification before modem shutdown and
  2451. * after_powerup from SSR framework, to user-space module
  2452. */
  2453. static void rmnet_ipa_send_ssr_notification(bool ssr_done)
  2454. {
  2455. struct ipa_msg_meta msg_meta;
  2456. int rc;
  2457. memset(&msg_meta, 0, sizeof(struct ipa_msg_meta));
  2458. if (ssr_done)
  2459. msg_meta.msg_type = IPA_SSR_AFTER_POWERUP;
  2460. else
  2461. msg_meta.msg_type = IPA_SSR_BEFORE_SHUTDOWN;
  2462. rc = ipa_send_msg(&msg_meta, NULL, NULL);
  2463. if (rc) {
  2464. IPAWANERR("ipa_send_msg failed: %d\n", rc);
  2465. return;
  2466. }
  2467. }
  2468. static int ipa3_lcl_mdm_ssr_notifier_cb(struct notifier_block *this,
  2469. unsigned long code,
  2470. void *data)
  2471. {
  2472. if (!ipa3_rmnet_ctx.ipa_rmnet_ssr)
  2473. return NOTIFY_DONE;
  2474. if (!ipa3_ctx) {
  2475. IPAWANERR_RL("ipa3_ctx was not initialized\n");
  2476. return NOTIFY_DONE;
  2477. }
  2478. if (rmnet_ipa3_ctx->ipa_config_is_apq) {
  2479. IPAWANERR("Local modem SSR event=%lu on APQ platform\n",
  2480. code);
  2481. return NOTIFY_DONE;
  2482. }
  2483. switch (code) {
  2484. case SUBSYS_BEFORE_SHUTDOWN:
  2485. IPAWANINFO("IPA received MPSS BEFORE_SHUTDOWN\n");
  2486. /* send SSR before-shutdown notification to IPACM */
  2487. rmnet_ipa_send_ssr_notification(false);
  2488. atomic_set(&rmnet_ipa3_ctx->is_ssr, 1);
  2489. ipa3_q6_pre_shutdown_cleanup();
  2490. if (IPA_NETDEV())
  2491. netif_stop_queue(IPA_NETDEV());
  2492. ipa3_qmi_stop_workqueues();
  2493. ipa3_wan_ioctl_stop_qmi_messages();
  2494. ipa_stop_polling_stats();
  2495. if (atomic_read(&rmnet_ipa3_ctx->is_initialized))
  2496. platform_driver_unregister(&rmnet_ipa_driver);
  2497. imp_handle_modem_shutdown();
  2498. if (atomic_read(&rmnet_ipa3_ctx->is_ssr) &&
  2499. ipa3_ctx->ipa_hw_type >= IPA_HW_v4_0)
  2500. ipa3_q6_post_shutdown_cleanup();
  2501. ipa3_odl_pipe_cleanup(true);
  2502. IPAWANINFO("IPA BEFORE_SHUTDOWN handling is complete\n");
  2503. break;
  2504. case SUBSYS_AFTER_SHUTDOWN:
  2505. IPAWANINFO("IPA Received MPSS AFTER_SHUTDOWN\n");
  2506. if (atomic_read(&rmnet_ipa3_ctx->is_ssr) &&
  2507. ipa3_ctx->ipa_hw_type < IPA_HW_v4_0)
  2508. ipa3_q6_post_shutdown_cleanup();
  2509. if (ipa3_ctx->ipa_endp_delay_wa)
  2510. ipa3_client_prod_post_shutdown_cleanup();
  2511. IPAWANINFO("IPA AFTER_SHUTDOWN handling is complete\n");
  2512. break;
  2513. case SUBSYS_BEFORE_POWERUP:
  2514. IPAWANINFO("IPA received MPSS BEFORE_POWERUP\n");
  2515. if (atomic_read(&rmnet_ipa3_ctx->is_ssr)) {
  2516. /* clean up cached QMI msg/handlers */
  2517. ipa3_qmi_service_exit();
  2518. ipa3_q6_pre_powerup_cleanup();
  2519. }
  2520. /* hold a proxy vote for the modem. */
  2521. ipa3_proxy_clk_vote();
  2522. ipa3_reset_freeze_vote();
  2523. IPAWANINFO("IPA BEFORE_POWERUP handling is complete\n");
  2524. break;
  2525. case SUBSYS_AFTER_POWERUP:
  2526. IPAWANINFO("IPA received MPSS AFTER_POWERUP\n");
  2527. if (!atomic_read(&rmnet_ipa3_ctx->is_initialized) &&
  2528. atomic_read(&rmnet_ipa3_ctx->is_ssr))
  2529. platform_driver_register(&rmnet_ipa_driver);
  2530. ipa3_odl_pipe_open();
  2531. IPAWANINFO("IPA AFTER_POWERUP handling is complete\n");
  2532. break;
  2533. default:
  2534. IPAWANDBG("Unsupported subsys notification, IPA received: %lu",
  2535. code);
  2536. break;
  2537. }
  2538. IPAWANDBG_LOW("Exit\n");
  2539. return NOTIFY_DONE;
  2540. }
  2541. static int ipa3_rmt_mdm_ssr_notifier_cb(struct notifier_block *this,
  2542. unsigned long code,
  2543. void *data)
  2544. {
  2545. if (!ipa3_rmnet_ctx.ipa_rmnet_ssr) {
  2546. IPAWANERR("SSR event=%lu while not enabled\n", code);
  2547. return NOTIFY_DONE;
  2548. }
  2549. if (!rmnet_ipa3_ctx->ipa_config_is_apq) {
  2550. IPAWANERR("Remote mdm SSR event=%lu on non-APQ platform=%d\n",
  2551. code, ipa3_ctx->platform_type);
  2552. return NOTIFY_DONE;
  2553. }
  2554. switch (code) {
  2555. case SUBSYS_BEFORE_SHUTDOWN:
  2556. IPAWANINFO("IPA received RMT MPSS BEFORE_SHUTDOWN\n");
  2557. break;
  2558. case SUBSYS_AFTER_SHUTDOWN:
  2559. IPAWANINFO("IPA Received RMT MPSS AFTER_SHUTDOWN\n");
  2560. break;
  2561. case SUBSYS_BEFORE_POWERUP:
  2562. IPAWANINFO("IPA received RMT MPSS BEFORE_POWERUP\n");
  2563. break;
  2564. case SUBSYS_AFTER_POWERUP:
  2565. IPAWANINFO("IPA received RMT MPSS AFTER_POWERUP\n");
  2566. break;
  2567. default:
  2568. IPAWANDBG("IPA received RMT MPSS event %lu", code);
  2569. break;
  2570. }
  2571. return NOTIFY_DONE;
  2572. }
  2573. /**
  2574. * rmnet_ipa_free_msg() - Free the msg sent to user space via ipa_send_msg
  2575. * @buff: pointer to buffer containing the message
  2576. * @len: message len
  2577. * @type: message type
  2578. *
  2579. * This function is invoked when ipa_send_msg is complete (Provided as a
  2580. * free function pointer along with the message).
  2581. */
  2582. static void rmnet_ipa_free_msg(void *buff, u32 len, u32 type)
  2583. {
  2584. if (!buff) {
  2585. IPAWANERR("Null buffer\n");
  2586. return;
  2587. }
  2588. if (type != IPA_TETHERING_STATS_UPDATE_STATS &&
  2589. type != IPA_TETHERING_STATS_UPDATE_NETWORK_STATS &&
  2590. type != IPA_PER_CLIENT_STATS_CONNECT_EVENT &&
  2591. type != IPA_PER_CLIENT_STATS_DISCONNECT_EVENT) {
  2592. IPAWANERR("Wrong type given. buff %pK type %d\n",
  2593. buff, type);
  2594. }
  2595. kfree(buff);
  2596. }
  2597. /**
  2598. * rmnet_ipa_get_stats_and_update() - Gets pipe stats from Modem
  2599. *
  2600. * This function queries the IPA Modem driver for the pipe stats
  2601. * via QMI, and updates the user space IPA entity.
  2602. */
  2603. static void rmnet_ipa_get_stats_and_update(void)
  2604. {
  2605. struct ipa_get_data_stats_req_msg_v01 req;
  2606. struct ipa_get_data_stats_resp_msg_v01 *resp;
  2607. struct ipa_msg_meta msg_meta;
  2608. int rc;
  2609. resp = kzalloc(sizeof(struct ipa_get_data_stats_resp_msg_v01),
  2610. GFP_KERNEL);
  2611. if (!resp)
  2612. return;
  2613. memset(&req, 0, sizeof(struct ipa_get_data_stats_req_msg_v01));
  2614. memset(resp, 0, sizeof(struct ipa_get_data_stats_resp_msg_v01));
  2615. req.ipa_stats_type = QMI_IPA_STATS_TYPE_PIPE_V01;
  2616. rc = ipa3_qmi_get_data_stats(&req, resp);
  2617. if (rc) {
  2618. IPAWANERR("ipa3_qmi_get_data_stats failed: %d\n", rc);
  2619. kfree(resp);
  2620. return;
  2621. }
  2622. memset(&msg_meta, 0, sizeof(struct ipa_msg_meta));
  2623. msg_meta.msg_type = IPA_TETHERING_STATS_UPDATE_STATS;
  2624. msg_meta.msg_len = sizeof(struct ipa_get_data_stats_resp_msg_v01);
  2625. rc = ipa_send_msg(&msg_meta, resp, rmnet_ipa_free_msg);
  2626. if (rc) {
  2627. IPAWANERR("ipa_send_msg failed: %d\n", rc);
  2628. kfree(resp);
  2629. return;
  2630. }
  2631. }
  2632. /**
  2633. * tethering_stats_poll_queue() - Stats polling function
  2634. * @work - Work entry
  2635. *
  2636. * This function is scheduled periodically (per the interval) in
  2637. * order to poll the IPA Modem driver for the pipe stats.
  2638. */
  2639. static void tethering_stats_poll_queue(struct work_struct *work)
  2640. {
  2641. rmnet_ipa_get_stats_and_update();
  2642. /* Schedule again only if there's an active polling interval */
  2643. if (ipa3_rmnet_ctx.polling_interval != 0)
  2644. schedule_delayed_work(&ipa_tether_stats_poll_wakequeue_work,
  2645. msecs_to_jiffies(ipa3_rmnet_ctx.polling_interval*1000));
  2646. }
  2647. /**
  2648. * rmnet_ipa_get_network_stats_and_update() - Get network stats from IPA Modem
  2649. *
  2650. * This function retrieves the data usage (used quota) from the IPA Modem driver
  2651. * via QMI, and updates IPA user space entity.
  2652. */
  2653. static void rmnet_ipa_get_network_stats_and_update(void)
  2654. {
  2655. struct ipa_get_apn_data_stats_req_msg_v01 req;
  2656. struct ipa_get_apn_data_stats_resp_msg_v01 *resp;
  2657. struct ipa_msg_meta msg_meta;
  2658. int rc;
  2659. resp = kzalloc(sizeof(struct ipa_get_apn_data_stats_resp_msg_v01),
  2660. GFP_KERNEL);
  2661. if (!resp)
  2662. return;
  2663. memset(&req, 0, sizeof(struct ipa_get_apn_data_stats_req_msg_v01));
  2664. memset(resp, 0, sizeof(struct ipa_get_apn_data_stats_resp_msg_v01));
  2665. req.mux_id_list_valid = true;
  2666. req.mux_id_list_len = 1;
  2667. req.mux_id_list[0] = ipa3_rmnet_ctx.metered_mux_id;
  2668. rc = ipa3_qmi_get_network_stats(&req, resp);
  2669. if (rc) {
  2670. IPAWANERR("ipa3_qmi_get_network_stats failed: %d\n", rc);
  2671. kfree(resp);
  2672. return;
  2673. }
  2674. memset(&msg_meta, 0, sizeof(struct ipa_msg_meta));
  2675. msg_meta.msg_type = IPA_TETHERING_STATS_UPDATE_NETWORK_STATS;
  2676. msg_meta.msg_len = sizeof(struct ipa_get_apn_data_stats_resp_msg_v01);
  2677. rc = ipa_send_msg(&msg_meta, resp, rmnet_ipa_free_msg);
  2678. if (rc) {
  2679. IPAWANERR("ipa_send_msg failed: %d\n", rc);
  2680. kfree(resp);
  2681. return;
  2682. }
  2683. }
  2684. /**
  2685. * rmnet_ipa_send_quota_reach_ind() - send quota_reach notification from
  2686. * IPA Modem
  2687. * This function sends the quota_reach indication from the IPA Modem driver
  2688. * via QMI, to user-space module
  2689. */
  2690. static void rmnet_ipa_send_quota_reach_ind(void)
  2691. {
  2692. struct ipa_msg_meta msg_meta;
  2693. int rc;
  2694. memset(&msg_meta, 0, sizeof(struct ipa_msg_meta));
  2695. msg_meta.msg_type = IPA_QUOTA_REACH;
  2696. rc = ipa_send_msg(&msg_meta, NULL, NULL);
  2697. if (rc) {
  2698. IPAWANERR("ipa_send_msg failed: %d\n", rc);
  2699. return;
  2700. }
  2701. }
  2702. /**
  2703. * rmnet_ipa3_poll_tethering_stats() - Tethering stats polling IOCTL handler
  2704. * @data - IOCTL data
  2705. *
  2706. * This function handles WAN_IOC_POLL_TETHERING_STATS.
  2707. * In case polling interval received is 0, polling will stop
  2708. * (If there's a polling in progress, it will allow it to finish), and then will
  2709. * fetch network stats, and update the IPA user space.
  2710. *
  2711. * Return codes:
  2712. * 0: Success
  2713. */
  2714. int rmnet_ipa3_poll_tethering_stats(struct wan_ioctl_poll_tethering_stats *data)
  2715. {
  2716. ipa3_rmnet_ctx.polling_interval = data->polling_interval_secs;
  2717. cancel_delayed_work_sync(&ipa_tether_stats_poll_wakequeue_work);
  2718. if (ipa3_rmnet_ctx.polling_interval == 0) {
  2719. ipa3_qmi_stop_data_qouta();
  2720. rmnet_ipa_get_network_stats_and_update();
  2721. rmnet_ipa_get_stats_and_update();
  2722. return 0;
  2723. }
  2724. schedule_delayed_work(&ipa_tether_stats_poll_wakequeue_work, 0);
  2725. return 0;
  2726. }
  2727. /**
  2728. * rmnet_ipa_set_data_quota_modem() - Data quota setting IOCTL handler
  2729. * @data - IOCTL data
  2730. *
  2731. * This function handles WAN_IOC_SET_DATA_QUOTA on modem interface.
  2732. * It translates the given interface name to the Modem MUX ID and
  2733. * sends the request of the quota to the IPA Modem driver via QMI.
  2734. *
  2735. * Return codes:
  2736. * 0: Success
  2737. * -EFAULT: Invalid interface name provided
  2738. * other: See ipa_qmi_set_data_quota
  2739. */
  2740. static int rmnet_ipa3_set_data_quota_modem(
  2741. struct wan_ioctl_set_data_quota *data)
  2742. {
  2743. u32 mux_id;
  2744. int index;
  2745. struct ipa_set_data_usage_quota_req_msg_v01 req;
  2746. /* stop quota */
  2747. if (!data->set_quota)
  2748. ipa3_qmi_stop_data_qouta();
  2749. /* prevent string buffer overflows */
  2750. data->interface_name[IFNAMSIZ-1] = '\0';
  2751. index = find_vchannel_name_index(data->interface_name);
  2752. IPAWANERR("iface name %s, quota %lu\n",
  2753. data->interface_name, (unsigned long) data->quota_mbytes);
  2754. if (index == MAX_NUM_OF_MUX_CHANNEL) {
  2755. IPAWANERR("%s is an invalid iface name\n",
  2756. data->interface_name);
  2757. return -ENODEV;
  2758. }
  2759. mux_id = rmnet_ipa3_ctx->mux_channel[index].mux_id;
  2760. ipa3_rmnet_ctx.metered_mux_id = mux_id;
  2761. memset(&req, 0, sizeof(struct ipa_set_data_usage_quota_req_msg_v01));
  2762. req.apn_quota_list_valid = true;
  2763. req.apn_quota_list_len = 1;
  2764. req.apn_quota_list[0].mux_id = mux_id;
  2765. req.apn_quota_list[0].num_Mbytes = data->quota_mbytes;
  2766. return ipa3_qmi_set_data_quota(&req);
  2767. }
  2768. static int rmnet_ipa3_set_data_quota_wifi(struct wan_ioctl_set_data_quota *data)
  2769. {
  2770. struct ipa_set_wifi_quota wifi_quota;
  2771. int rc = 0;
  2772. memset(&wifi_quota, 0, sizeof(struct ipa_set_wifi_quota));
  2773. wifi_quota.set_quota = data->set_quota;
  2774. wifi_quota.quota_bytes = data->quota_mbytes;
  2775. IPAWANERR("iface name %s, quota %lu\n",
  2776. data->interface_name, (unsigned long) data->quota_mbytes);
  2777. rc = ipa3_set_wlan_quota(&wifi_quota);
  2778. /* check if wlan-fw takes this quota-set */
  2779. if (!wifi_quota.set_valid)
  2780. rc = -EFAULT;
  2781. return rc;
  2782. }
  2783. /**
  2784. * rmnet_ipa_set_data_quota() - Data quota setting IOCTL handler
  2785. * @data - IOCTL data
  2786. *
  2787. * This function handles WAN_IOC_SET_DATA_QUOTA.
  2788. * It translates the given interface name to the Modem MUX ID and
  2789. * sends the request of the quota to the IPA Modem driver via QMI.
  2790. *
  2791. * Return codes:
  2792. * 0: Success
  2793. * -EFAULT: Invalid interface name provided
  2794. * other: See ipa_qmi_set_data_quota
  2795. */
  2796. int rmnet_ipa3_set_data_quota(struct wan_ioctl_set_data_quota *data)
  2797. {
  2798. enum ipa_upstream_type upstream_type;
  2799. int rc = 0;
  2800. /* prevent string buffer overflows */
  2801. data->interface_name[IFNAMSIZ-1] = '\0';
  2802. /* get IPA backhaul type */
  2803. upstream_type = find_upstream_type(data->interface_name);
  2804. if (upstream_type == IPA_UPSTEAM_MAX) {
  2805. IPAWANERR("Wrong interface_name name %s\n",
  2806. data->interface_name);
  2807. } else if (upstream_type == IPA_UPSTEAM_WLAN) {
  2808. rc = rmnet_ipa3_set_data_quota_wifi(data);
  2809. if (rc) {
  2810. IPAWANERR("set quota on wifi failed\n");
  2811. return rc;
  2812. }
  2813. } else {
  2814. rc = rmnet_ipa3_set_data_quota_modem(data);
  2815. if (rc) {
  2816. IPAWANERR("set quota on modem failed\n");
  2817. return rc;
  2818. }
  2819. }
  2820. return rc;
  2821. }
  2822. /* rmnet_ipa_set_tether_client_pipe() -
  2823. * @data - IOCTL data
  2824. *
  2825. * This function handles WAN_IOC_SET_DATA_QUOTA.
  2826. * It translates the given interface name to the Modem MUX ID and
  2827. * sends the request of the quota to the IPA Modem driver via QMI.
  2828. *
  2829. * Return codes:
  2830. * 0: Success
  2831. * -EFAULT: Invalid interface name provided
  2832. * other: See ipa_qmi_set_data_quota
  2833. */
  2834. int rmnet_ipa3_set_tether_client_pipe(
  2835. struct wan_ioctl_set_tether_client_pipe *data)
  2836. {
  2837. int number, i;
  2838. /* error checking if ul_src_pipe_len valid or not*/
  2839. if (data->ul_src_pipe_len > QMI_IPA_MAX_PIPES_V01 ||
  2840. data->ul_src_pipe_len < 0) {
  2841. IPAWANERR("UL src pipes %d exceeding max %d\n",
  2842. data->ul_src_pipe_len,
  2843. QMI_IPA_MAX_PIPES_V01);
  2844. return -EFAULT;
  2845. }
  2846. /* error checking if dl_dst_pipe_len valid or not*/
  2847. if (data->dl_dst_pipe_len > QMI_IPA_MAX_PIPES_V01 ||
  2848. data->dl_dst_pipe_len < 0) {
  2849. IPAWANERR("DL dst pipes %d exceeding max %d\n",
  2850. data->dl_dst_pipe_len,
  2851. QMI_IPA_MAX_PIPES_V01);
  2852. return -EFAULT;
  2853. }
  2854. IPAWANDBG("client %d, UL %d, DL %d, reset %d\n",
  2855. data->ipa_client,
  2856. data->ul_src_pipe_len,
  2857. data->dl_dst_pipe_len,
  2858. data->reset_client);
  2859. number = data->ul_src_pipe_len;
  2860. for (i = 0; i < number; i++) {
  2861. IPAWANDBG("UL index-%d pipe %d\n", i,
  2862. data->ul_src_pipe_list[i]);
  2863. if (data->reset_client)
  2864. ipa3_set_client(data->ul_src_pipe_list[i],
  2865. 0, false);
  2866. else
  2867. ipa3_set_client(data->ul_src_pipe_list[i],
  2868. data->ipa_client, true);
  2869. }
  2870. number = data->dl_dst_pipe_len;
  2871. for (i = 0; i < number; i++) {
  2872. IPAWANDBG("DL index-%d pipe %d\n", i,
  2873. data->dl_dst_pipe_list[i]);
  2874. if (data->reset_client)
  2875. ipa3_set_client(data->dl_dst_pipe_list[i],
  2876. 0, false);
  2877. else
  2878. ipa3_set_client(data->dl_dst_pipe_list[i],
  2879. data->ipa_client, false);
  2880. }
  2881. return 0;
  2882. }
  2883. static int rmnet_ipa3_query_tethering_stats_wifi(
  2884. struct wan_ioctl_query_tether_stats *data, bool reset)
  2885. {
  2886. struct ipa_get_wdi_sap_stats *sap_stats;
  2887. int rc;
  2888. sap_stats = kzalloc(sizeof(struct ipa_get_wdi_sap_stats),
  2889. GFP_KERNEL);
  2890. if (!sap_stats)
  2891. return -ENOMEM;
  2892. memset(sap_stats, 0, sizeof(struct ipa_get_wdi_sap_stats));
  2893. sap_stats->reset_stats = reset;
  2894. IPAWANDBG("reset the pipe stats %d\n", sap_stats->reset_stats);
  2895. rc = ipa3_get_wlan_stats(sap_stats);
  2896. if (rc) {
  2897. IPAWANERR_RL("can't get ipa3_get_wlan_stats\n");
  2898. kfree(sap_stats);
  2899. return rc;
  2900. } else if (data == NULL) {
  2901. IPAWANDBG("only reset wlan stats\n");
  2902. kfree(sap_stats);
  2903. return 0;
  2904. }
  2905. if (sap_stats->stats_valid) {
  2906. data->ipv4_tx_packets = sap_stats->ipv4_tx_packets;
  2907. data->ipv4_tx_bytes = sap_stats->ipv4_tx_bytes;
  2908. data->ipv4_rx_packets = sap_stats->ipv4_rx_packets;
  2909. data->ipv4_rx_bytes = sap_stats->ipv4_rx_bytes;
  2910. data->ipv6_tx_packets = sap_stats->ipv6_tx_packets;
  2911. data->ipv6_tx_bytes = sap_stats->ipv6_tx_bytes;
  2912. data->ipv6_rx_packets = sap_stats->ipv6_rx_packets;
  2913. data->ipv6_rx_bytes = sap_stats->ipv6_rx_bytes;
  2914. }
  2915. IPAWANDBG("v4_rx_p(%lu) v6_rx_p(%lu) v4_rx_b(%lu) v6_rx_b(%lu)\n",
  2916. (unsigned long) data->ipv4_rx_packets,
  2917. (unsigned long) data->ipv6_rx_packets,
  2918. (unsigned long) data->ipv4_rx_bytes,
  2919. (unsigned long) data->ipv6_rx_bytes);
  2920. IPAWANDBG("tx_p_v4(%lu)v6(%lu)tx_b_v4(%lu) v6(%lu)\n",
  2921. (unsigned long) data->ipv4_tx_packets,
  2922. (unsigned long) data->ipv6_tx_packets,
  2923. (unsigned long) data->ipv4_tx_bytes,
  2924. (unsigned long) data->ipv6_tx_bytes);
  2925. kfree(sap_stats);
  2926. return rc;
  2927. }
  2928. static int rmnet_ipa3_query_tethering_stats_modem(
  2929. struct wan_ioctl_query_tether_stats *data, bool reset)
  2930. {
  2931. struct ipa_get_data_stats_req_msg_v01 *req;
  2932. struct ipa_get_data_stats_resp_msg_v01 *resp;
  2933. int pipe_len, rc;
  2934. struct ipa_pipe_stats_info_type_v01 *stat_ptr;
  2935. req = kzalloc(sizeof(struct ipa_get_data_stats_req_msg_v01),
  2936. GFP_KERNEL);
  2937. if (!req)
  2938. return -ENOMEM;
  2939. resp = kzalloc(sizeof(struct ipa_get_data_stats_resp_msg_v01),
  2940. GFP_KERNEL);
  2941. if (!resp) {
  2942. kfree(req);
  2943. return -ENOMEM;
  2944. }
  2945. memset(req, 0, sizeof(struct ipa_get_data_stats_req_msg_v01));
  2946. memset(resp, 0, sizeof(struct ipa_get_data_stats_resp_msg_v01));
  2947. req->ipa_stats_type = QMI_IPA_STATS_TYPE_PIPE_V01;
  2948. if (reset) {
  2949. req->reset_stats_valid = true;
  2950. req->reset_stats = true;
  2951. IPAWANDBG("reset the pipe stats\n");
  2952. }
  2953. rc = ipa3_qmi_get_data_stats(req, resp);
  2954. if (rc) {
  2955. IPAWANERR("can't get ipa_qmi_get_data_stats\n");
  2956. kfree(req);
  2957. kfree(resp);
  2958. return rc;
  2959. } else if (data == NULL) {
  2960. IPAWANDBG("only reset modem stats\n");
  2961. kfree(req);
  2962. kfree(resp);
  2963. return 0;
  2964. }
  2965. if (resp->dl_dst_pipe_stats_list_valid) {
  2966. for (pipe_len = 0; pipe_len < resp->dl_dst_pipe_stats_list_len;
  2967. pipe_len++) {
  2968. stat_ptr =
  2969. &resp->dl_dst_pipe_stats_list[pipe_len];
  2970. IPAWANDBG_LOW("Check entry(%d) dl_dst_pipe(%d)\n",
  2971. pipe_len,
  2972. stat_ptr->pipe_index);
  2973. IPAWANDBG_LOW("dl_p_v4(%lu)v6(%lu)\n",
  2974. (unsigned long) stat_ptr->num_ipv4_packets,
  2975. (unsigned long) stat_ptr->num_ipv6_packets
  2976. );
  2977. IPAWANDBG_LOW("dl_b_v4(%lu)v6(%lu)\n",
  2978. (unsigned long) stat_ptr->num_ipv4_bytes,
  2979. (unsigned long) stat_ptr->num_ipv6_bytes);
  2980. if (ipa_get_client_uplink(
  2981. stat_ptr->pipe_index) == false) {
  2982. if (data->ipa_client == ipa_get_client(
  2983. stat_ptr->pipe_index)) {
  2984. /* update the DL stats */
  2985. data->ipv4_rx_packets +=
  2986. stat_ptr->num_ipv4_packets;
  2987. data->ipv6_rx_packets +=
  2988. stat_ptr->num_ipv6_packets;
  2989. data->ipv4_rx_bytes +=
  2990. stat_ptr->num_ipv4_bytes;
  2991. data->ipv6_rx_bytes +=
  2992. stat_ptr->num_ipv6_bytes;
  2993. }
  2994. }
  2995. }
  2996. }
  2997. IPAWANDBG("v4_rx_p(%lu) v6_rx_p(%lu) v4_rx_b(%lu) v6_rx_b(%lu)\n",
  2998. (unsigned long) data->ipv4_rx_packets,
  2999. (unsigned long) data->ipv6_rx_packets,
  3000. (unsigned long) data->ipv4_rx_bytes,
  3001. (unsigned long) data->ipv6_rx_bytes);
  3002. if (resp->ul_src_pipe_stats_list_valid) {
  3003. for (pipe_len = 0; pipe_len < resp->ul_src_pipe_stats_list_len;
  3004. pipe_len++) {
  3005. stat_ptr =
  3006. &resp->ul_src_pipe_stats_list[pipe_len];
  3007. IPAWANDBG_LOW("Check entry(%d) ul_dst_pipe(%d)\n",
  3008. pipe_len,
  3009. stat_ptr->pipe_index);
  3010. IPAWANDBG_LOW("ul_p_v4(%lu)v6(%lu)\n",
  3011. (unsigned long) stat_ptr->num_ipv4_packets,
  3012. (unsigned long) stat_ptr->num_ipv6_packets
  3013. );
  3014. IPAWANDBG_LOW("ul_b_v4(%lu)v6(%lu)\n",
  3015. (unsigned long)stat_ptr->num_ipv4_bytes,
  3016. (unsigned long) stat_ptr->num_ipv6_bytes);
  3017. if (ipa_get_client_uplink(
  3018. stat_ptr->pipe_index) == true) {
  3019. if (data->ipa_client == ipa_get_client(
  3020. stat_ptr->pipe_index)) {
  3021. /* update the DL stats */
  3022. data->ipv4_tx_packets +=
  3023. stat_ptr->num_ipv4_packets;
  3024. data->ipv6_tx_packets +=
  3025. stat_ptr->num_ipv6_packets;
  3026. data->ipv4_tx_bytes +=
  3027. stat_ptr->num_ipv4_bytes;
  3028. data->ipv6_tx_bytes +=
  3029. stat_ptr->num_ipv6_bytes;
  3030. }
  3031. }
  3032. }
  3033. }
  3034. IPAWANDBG("tx_p_v4(%lu)v6(%lu)tx_b_v4(%lu) v6(%lu)\n",
  3035. (unsigned long) data->ipv4_tx_packets,
  3036. (unsigned long) data->ipv6_tx_packets,
  3037. (unsigned long) data->ipv4_tx_bytes,
  3038. (unsigned long) data->ipv6_tx_bytes);
  3039. kfree(req);
  3040. kfree(resp);
  3041. return 0;
  3042. }
  3043. static int rmnet_ipa3_query_tethering_stats_hw(
  3044. struct wan_ioctl_query_tether_stats *data, bool reset)
  3045. {
  3046. int rc = 0, index = 0;
  3047. struct ipa_quota_stats_all *con_stats;
  3048. enum ipa_client_type wlan_client;
  3049. /* qet HW-stats */
  3050. rc = ipa_get_teth_stats();
  3051. if (rc) {
  3052. IPAWANDBG("ipa_get_teth_stats failed %d,\n", rc);
  3053. return rc;
  3054. }
  3055. /* query DL stats */
  3056. IPAWANDBG("reset the pipe stats? (%d)\n", reset);
  3057. con_stats = kzalloc(sizeof(*con_stats), GFP_KERNEL);
  3058. if (!con_stats) {
  3059. IPAWANERR("no memory\n");
  3060. return -ENOMEM;
  3061. }
  3062. if (rmnet_ipa3_ctx->ipa_config_is_apq) {
  3063. rc = ipa_query_teth_stats(IPA_CLIENT_MHI_PRIME_TETH_PROD,
  3064. con_stats, reset);
  3065. if (rc) {
  3066. IPAERR("MHI_PRIME_TETH_PROD query failed %d,\n", rc);
  3067. kfree(con_stats);
  3068. return rc;
  3069. }
  3070. } else {
  3071. rc = ipa_query_teth_stats(IPA_CLIENT_Q6_WAN_PROD,
  3072. con_stats, reset);
  3073. if (rc) {
  3074. IPAERR("IPA_CLIENT_Q6_WAN_PROD query failed %d,\n", rc);
  3075. kfree(con_stats);
  3076. return rc;
  3077. }
  3078. }
  3079. if (ipa3_ctx->ipa_hw_type == IPA_HW_v4_5)
  3080. wlan_client = IPA_CLIENT_WLAN2_CONS;
  3081. else
  3082. wlan_client = IPA_CLIENT_WLAN1_CONS;
  3083. IPAWANDBG("wlan: v4_rx_p-b(%d,%lld) v6_rx_p-b(%d,%lld),client(%d)\n",
  3084. con_stats->client[wlan_client].num_ipv4_pkts,
  3085. con_stats->client[wlan_client].num_ipv4_bytes,
  3086. con_stats->client[wlan_client].num_ipv6_pkts,
  3087. con_stats->client[wlan_client].num_ipv6_bytes,
  3088. wlan_client);
  3089. IPAWANDBG("usb: v4_rx_p(%d) b(%lld) v6_rx_p(%d) b(%lld)\n",
  3090. con_stats->client[IPA_CLIENT_USB_CONS].num_ipv4_pkts,
  3091. con_stats->client[IPA_CLIENT_USB_CONS].num_ipv4_bytes,
  3092. con_stats->client[IPA_CLIENT_USB_CONS].num_ipv6_pkts,
  3093. con_stats->client[IPA_CLIENT_USB_CONS].num_ipv6_bytes);
  3094. /* update the DL stats */
  3095. data->ipv4_rx_packets =
  3096. con_stats->client[wlan_client].num_ipv4_pkts +
  3097. con_stats->client[IPA_CLIENT_USB_CONS].num_ipv4_pkts;
  3098. data->ipv6_rx_packets =
  3099. con_stats->client[wlan_client].num_ipv6_pkts +
  3100. con_stats->client[IPA_CLIENT_USB_CONS].num_ipv6_pkts;
  3101. data->ipv4_rx_bytes =
  3102. con_stats->client[wlan_client].num_ipv4_bytes +
  3103. con_stats->client[IPA_CLIENT_USB_CONS].num_ipv4_bytes;
  3104. data->ipv6_rx_bytes =
  3105. con_stats->client[wlan_client].num_ipv6_bytes +
  3106. con_stats->client[IPA_CLIENT_USB_CONS].num_ipv6_bytes;
  3107. IPAWANDBG("v4_rx_p(%lu) v6_rx_p(%lu) v4_rx_b(%lu) v6_rx_b(%lu)\n",
  3108. (unsigned long) data->ipv4_rx_packets,
  3109. (unsigned long) data->ipv6_rx_packets,
  3110. (unsigned long) data->ipv4_rx_bytes,
  3111. (unsigned long) data->ipv6_rx_bytes);
  3112. /* query USB UL stats */
  3113. memset(con_stats, 0, sizeof(struct ipa_quota_stats_all));
  3114. rc = ipa_query_teth_stats(IPA_CLIENT_USB_PROD, con_stats, reset);
  3115. if (rc) {
  3116. IPAERR("IPA_CLIENT_USB_PROD query failed %d\n", rc);
  3117. kfree(con_stats);
  3118. return rc;
  3119. }
  3120. if (rmnet_ipa3_ctx->ipa_config_is_apq)
  3121. index = IPA_CLIENT_MHI_PRIME_TETH_CONS;
  3122. else
  3123. index = IPA_CLIENT_Q6_WAN_CONS;
  3124. IPAWANDBG("usb: v4_tx_p(%d) b(%lld) v6_tx_p(%d) b(%lld)\n",
  3125. con_stats->client[index].num_ipv4_pkts,
  3126. con_stats->client[index].num_ipv4_bytes,
  3127. con_stats->client[index].num_ipv6_pkts,
  3128. con_stats->client[index].num_ipv6_bytes);
  3129. /* update the USB UL stats */
  3130. data->ipv4_tx_packets =
  3131. con_stats->client[index].num_ipv4_pkts;
  3132. data->ipv6_tx_packets =
  3133. con_stats->client[index].num_ipv6_pkts;
  3134. data->ipv4_tx_bytes =
  3135. con_stats->client[index].num_ipv4_bytes;
  3136. data->ipv6_tx_bytes =
  3137. con_stats->client[index].num_ipv6_bytes;
  3138. /* query WLAN UL stats */
  3139. memset(con_stats, 0, sizeof(struct ipa_quota_stats_all));
  3140. if (ipa3_ctx->ipa_hw_type == IPA_HW_v4_5)
  3141. rc = ipa_query_teth_stats(IPA_CLIENT_WLAN2_PROD,
  3142. con_stats, reset);
  3143. else
  3144. rc = ipa_query_teth_stats(IPA_CLIENT_WLAN1_PROD,
  3145. con_stats, reset);
  3146. if (rc) {
  3147. IPAERR("IPA_CLIENT_WLAN_PROD query failed %d\n", rc);
  3148. kfree(con_stats);
  3149. return rc;
  3150. }
  3151. if (rmnet_ipa3_ctx->ipa_config_is_apq)
  3152. index = IPA_CLIENT_MHI_PRIME_TETH_CONS;
  3153. else
  3154. index = IPA_CLIENT_Q6_WAN_CONS;
  3155. IPAWANDBG("wlan1: v4_tx_p(%d) b(%lld) v6_tx_p(%d) b(%lld)\n",
  3156. con_stats->client[index].num_ipv4_pkts,
  3157. con_stats->client[index].num_ipv4_bytes,
  3158. con_stats->client[index].num_ipv6_pkts,
  3159. con_stats->client[index].num_ipv6_bytes);
  3160. /* update the wlan UL stats */
  3161. data->ipv4_tx_packets +=
  3162. con_stats->client[index].num_ipv4_pkts;
  3163. data->ipv6_tx_packets +=
  3164. con_stats->client[index].num_ipv6_pkts;
  3165. data->ipv4_tx_bytes +=
  3166. con_stats->client[index].num_ipv4_bytes;
  3167. data->ipv6_tx_bytes +=
  3168. con_stats->client[index].num_ipv6_bytes;
  3169. IPAWANDBG("v4_tx_p(%lu) v6_tx_p(%lu) v4_tx_b(%lu) v6_tx_b(%lu)\n",
  3170. (unsigned long) data->ipv4_tx_packets,
  3171. (unsigned long) data->ipv6_tx_packets,
  3172. (unsigned long) data->ipv4_tx_bytes,
  3173. (unsigned long) data->ipv6_tx_bytes);
  3174. kfree(con_stats);
  3175. return rc;
  3176. }
  3177. int rmnet_ipa3_query_tethering_stats(struct wan_ioctl_query_tether_stats *data,
  3178. bool reset)
  3179. {
  3180. enum ipa_upstream_type upstream_type;
  3181. int rc = 0;
  3182. /* prevent string buffer overflows */
  3183. data->upstreamIface[IFNAMSIZ-1] = '\0';
  3184. data->tetherIface[IFNAMSIZ-1] = '\0';
  3185. /* get IPA backhaul type */
  3186. upstream_type = find_upstream_type(data->upstreamIface);
  3187. if (upstream_type == IPA_UPSTEAM_MAX) {
  3188. IPAWANERR(" Wrong upstreamIface name %s\n",
  3189. data->upstreamIface);
  3190. } else if (upstream_type == IPA_UPSTEAM_WLAN) {
  3191. IPAWANDBG_LOW(" query wifi-backhaul stats\n");
  3192. rc = rmnet_ipa3_query_tethering_stats_wifi(
  3193. data, false);
  3194. if (rc) {
  3195. IPAWANERR("wlan WAN_IOC_QUERY_TETHER_STATS failed\n");
  3196. return rc;
  3197. }
  3198. } else {
  3199. IPAWANDBG_LOW(" query modem-backhaul stats\n");
  3200. rc = rmnet_ipa3_query_tethering_stats_modem(
  3201. data, false);
  3202. if (rc) {
  3203. IPAWANERR("modem WAN_IOC_QUERY_TETHER_STATS failed\n");
  3204. return rc;
  3205. }
  3206. }
  3207. return rc;
  3208. }
  3209. int rmnet_ipa3_query_tethering_stats_all(
  3210. struct wan_ioctl_query_tether_stats_all *data)
  3211. {
  3212. struct wan_ioctl_query_tether_stats tether_stats;
  3213. enum ipa_upstream_type upstream_type;
  3214. int rc = 0;
  3215. memset(&tether_stats, 0, sizeof(struct wan_ioctl_query_tether_stats));
  3216. /* prevent string buffer overflows */
  3217. data->upstreamIface[IFNAMSIZ-1] = '\0';
  3218. /* get IPA backhaul type */
  3219. upstream_type = find_upstream_type(data->upstreamIface);
  3220. if (upstream_type == IPA_UPSTEAM_MAX) {
  3221. IPAWANERR(" Wrong upstreamIface name %s\n",
  3222. data->upstreamIface);
  3223. } else if (upstream_type == IPA_UPSTEAM_WLAN) {
  3224. IPAWANDBG_LOW(" query wifi-backhaul stats\n");
  3225. rc = rmnet_ipa3_query_tethering_stats_wifi(
  3226. &tether_stats, data->reset_stats);
  3227. if (rc) {
  3228. IPAWANERR_RL(
  3229. "wlan WAN_IOC_QUERY_TETHER_STATS failed\n");
  3230. return rc;
  3231. }
  3232. data->tx_bytes = tether_stats.ipv4_tx_bytes
  3233. + tether_stats.ipv6_tx_bytes;
  3234. data->rx_bytes = tether_stats.ipv4_rx_bytes
  3235. + tether_stats.ipv6_rx_bytes;
  3236. } else {
  3237. IPAWANDBG_LOW(" query modem-backhaul stats\n");
  3238. tether_stats.ipa_client = data->ipa_client;
  3239. if (ipa3_ctx->ipa_hw_type < IPA_HW_v4_0 ||
  3240. !ipa3_ctx->hw_stats.enabled) {
  3241. IPAWANDBG("hw version %d,hw_stats.enabled %d\n",
  3242. ipa3_ctx->ipa_hw_type,
  3243. ipa3_ctx->hw_stats.enabled);
  3244. /* get modem stats from QMI */
  3245. rc = rmnet_ipa3_query_tethering_stats_modem(
  3246. &tether_stats, data->reset_stats);
  3247. if (rc) {
  3248. IPAWANERR("modem QUERY_TETHER_STATS failed\n");
  3249. return rc;
  3250. }
  3251. } else {
  3252. /* get modem stats from IPA-HW counters */
  3253. rc = rmnet_ipa3_query_tethering_stats_hw(
  3254. &tether_stats, data->reset_stats);
  3255. if (rc) {
  3256. IPAWANERR("modem QUERY_TETHER_STATS failed\n");
  3257. return rc;
  3258. }
  3259. }
  3260. data->tx_bytes = tether_stats.ipv4_tx_bytes
  3261. + tether_stats.ipv6_tx_bytes;
  3262. data->rx_bytes = tether_stats.ipv4_rx_bytes
  3263. + tether_stats.ipv6_rx_bytes;
  3264. }
  3265. return rc;
  3266. }
  3267. int rmnet_ipa3_reset_tethering_stats(struct wan_ioctl_reset_tether_stats *data)
  3268. {
  3269. enum ipa_upstream_type upstream_type;
  3270. int rc = 0;
  3271. /* prevent string buffer overflows */
  3272. data->upstreamIface[IFNAMSIZ-1] = '\0';
  3273. /* get IPA backhaul type */
  3274. upstream_type = find_upstream_type(data->upstreamIface);
  3275. if (upstream_type == IPA_UPSTEAM_MAX) {
  3276. IPAWANERR(" Wrong upstreamIface name %s\n",
  3277. data->upstreamIface);
  3278. } else if (upstream_type == IPA_UPSTEAM_WLAN) {
  3279. IPAWANERR(" reset wifi-backhaul stats\n");
  3280. rc = rmnet_ipa3_query_tethering_stats_wifi(
  3281. NULL, true);
  3282. if (rc) {
  3283. IPAWANERR("reset WLAN stats failed\n");
  3284. return rc;
  3285. }
  3286. } else {
  3287. IPAWANERR(" reset modem-backhaul stats\n");
  3288. rc = rmnet_ipa3_query_tethering_stats_modem(
  3289. NULL, true);
  3290. if (rc) {
  3291. IPAWANERR("reset MODEM stats failed\n");
  3292. return rc;
  3293. }
  3294. }
  3295. return rc;
  3296. }
  3297. /**
  3298. * ipa3_broadcast_quota_reach_ind() - Send Netlink broadcast on Quota
  3299. * @mux_id - The MUX ID on which the quota has been reached
  3300. *
  3301. * This function broadcasts a Netlink event using the kobject of the
  3302. * rmnet_ipa interface in order to alert the user space that the quota
  3303. * on the specific interface which matches the mux_id has been reached.
  3304. *
  3305. */
  3306. void ipa3_broadcast_quota_reach_ind(u32 mux_id,
  3307. enum ipa_upstream_type upstream_type)
  3308. {
  3309. char alert_msg[IPA_QUOTA_REACH_ALERT_MAX_SIZE];
  3310. char iface_name_m[IPA_QUOTA_REACH_IF_NAME_MAX_SIZE];
  3311. char iface_name_l[IPA_QUOTA_REACH_IF_NAME_MAX_SIZE];
  3312. char *envp[IPA_UEVENT_NUM_EVNP] = {
  3313. alert_msg, iface_name_l, iface_name_m, NULL};
  3314. int res;
  3315. int index;
  3316. /* check upstream_type*/
  3317. if (upstream_type == IPA_UPSTEAM_MAX) {
  3318. IPAWANERR(" Wrong upstreamIface type %d\n", upstream_type);
  3319. return;
  3320. } else if (upstream_type == IPA_UPSTEAM_MODEM) {
  3321. index = ipa3_find_mux_channel_index(mux_id);
  3322. if (index == MAX_NUM_OF_MUX_CHANNEL) {
  3323. IPAWANERR("%u is an mux ID\n", mux_id);
  3324. return;
  3325. }
  3326. }
  3327. res = snprintf(alert_msg, IPA_QUOTA_REACH_ALERT_MAX_SIZE,
  3328. "ALERT_NAME=%s", "quotaReachedAlert");
  3329. if (res >= IPA_QUOTA_REACH_ALERT_MAX_SIZE) {
  3330. IPAWANERR("message too long (%d)", res);
  3331. return;
  3332. }
  3333. /* posting msg for L-release for CNE */
  3334. if (upstream_type == IPA_UPSTEAM_MODEM) {
  3335. res = snprintf(iface_name_l,
  3336. IPA_QUOTA_REACH_IF_NAME_MAX_SIZE,
  3337. "UPSTREAM=%s",
  3338. rmnet_ipa3_ctx->mux_channel[index].vchannel_name);
  3339. } else {
  3340. res = snprintf(iface_name_l, IPA_QUOTA_REACH_IF_NAME_MAX_SIZE,
  3341. "UPSTREAM=%s", IPA_UPSTEAM_WLAN_IFACE_NAME);
  3342. }
  3343. if (res >= IPA_QUOTA_REACH_IF_NAME_MAX_SIZE) {
  3344. IPAWANERR("message too long (%d)", res);
  3345. return;
  3346. }
  3347. /* posting msg for M-release for CNE */
  3348. if (upstream_type == IPA_UPSTEAM_MODEM) {
  3349. res = snprintf(iface_name_m,
  3350. IPA_QUOTA_REACH_IF_NAME_MAX_SIZE,
  3351. "INTERFACE=%s",
  3352. rmnet_ipa3_ctx->mux_channel[index].vchannel_name);
  3353. } else {
  3354. res = snprintf(iface_name_m,
  3355. IPA_QUOTA_REACH_IF_NAME_MAX_SIZE,
  3356. "INTERFACE=%s",
  3357. IPA_UPSTEAM_WLAN_IFACE_NAME);
  3358. }
  3359. if (res >= IPA_QUOTA_REACH_IF_NAME_MAX_SIZE) {
  3360. IPAWANERR("message too long (%d)", res);
  3361. return;
  3362. }
  3363. IPAWANERR("putting nlmsg: <%s> <%s> <%s>\n",
  3364. alert_msg, iface_name_l, iface_name_m);
  3365. kobject_uevent_env(&(IPA_NETDEV()->dev.kobj),
  3366. KOBJ_CHANGE, envp);
  3367. rmnet_ipa_send_quota_reach_ind();
  3368. }
  3369. /**
  3370. * ipa3_q6_handshake_complete() - Perform operations once Q6 is up
  3371. * @ssr_bootup - Indicates whether this is a cold boot-up or post-SSR.
  3372. *
  3373. * This function is invoked once the handshake between the IPA AP driver
  3374. * and IPA Q6 driver is complete. At this point, it is possible to perform
  3375. * operations which can't be performed until IPA Q6 driver is up.
  3376. *
  3377. */
  3378. void ipa3_q6_handshake_complete(bool ssr_bootup)
  3379. {
  3380. /* It is required to recover the network stats after SSR recovery */
  3381. if (ssr_bootup) {
  3382. /*
  3383. * In case the uC is required to be loaded by the Modem,
  3384. * the proxy vote will be removed only when uC loading is
  3385. * complete and indication is received by the AP. After SSR,
  3386. * uC is already loaded. Therefore, proxy vote can be removed
  3387. * once Modem init is complete.
  3388. */
  3389. ipa3_proxy_clk_unvote();
  3390. /* send SSR power-up notification to IPACM */
  3391. rmnet_ipa_send_ssr_notification(true);
  3392. /*
  3393. * It is required to recover the network stats after
  3394. * SSR recovery
  3395. */
  3396. rmnet_ipa_get_network_stats_and_update();
  3397. }
  3398. imp_handle_modem_ready();
  3399. }
  3400. static inline bool rmnet_ipa3_check_any_client_inited
  3401. (
  3402. enum ipacm_per_client_device_type device_type
  3403. )
  3404. {
  3405. int i = 0;
  3406. struct ipa_tether_device_info *teth_ptr = NULL;
  3407. for (; i < IPA_MAX_NUM_HW_PATH_CLIENTS; i++) {
  3408. teth_ptr = &rmnet_ipa3_ctx->tether_device[device_type];
  3409. if (teth_ptr->lan_client[i].client_idx != -1 &&
  3410. teth_ptr->lan_client[i].inited) {
  3411. IPAWANERR("Found client index: %d which is inited\n",
  3412. i);
  3413. return true;
  3414. }
  3415. }
  3416. return false;
  3417. }
  3418. static inline int rmnet_ipa3_get_lan_client_info
  3419. (
  3420. enum ipacm_per_client_device_type device_type,
  3421. uint8_t mac[]
  3422. )
  3423. {
  3424. int i = 0;
  3425. struct ipa_tether_device_info *teth_ptr = NULL;
  3426. IPAWANDBG("Client MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
  3427. mac[0], mac[1], mac[2],
  3428. mac[3], mac[4], mac[5]);
  3429. for (; i < IPA_MAX_NUM_HW_PATH_CLIENTS; i++) {
  3430. teth_ptr = &rmnet_ipa3_ctx->tether_device[device_type];
  3431. if (memcmp(
  3432. teth_ptr->lan_client[i].mac,
  3433. mac,
  3434. IPA_MAC_ADDR_SIZE) == 0) {
  3435. IPAWANDBG("Matched client index: %d\n", i);
  3436. return i;
  3437. }
  3438. }
  3439. return -EINVAL;
  3440. }
  3441. static inline int rmnet_ipa3_delete_lan_client_info
  3442. (
  3443. enum ipacm_per_client_device_type device_type,
  3444. int lan_clnt_idx
  3445. )
  3446. {
  3447. struct ipa_lan_client *lan_client = NULL;
  3448. int i;
  3449. struct ipa_tether_device_info *teth_ptr = NULL;
  3450. IPAWANDBG("Delete lan client info: %d, %d, %d\n",
  3451. rmnet_ipa3_ctx->tether_device[device_type].num_clients,
  3452. lan_clnt_idx, device_type);
  3453. /* Check if Device type is valid. */
  3454. if (device_type >= IPACM_MAX_CLIENT_DEVICE_TYPES ||
  3455. device_type < 0) {
  3456. IPAWANERR("Invalid Device type: %d\n", device_type);
  3457. return -EINVAL;
  3458. }
  3459. /* Check if the request is to clean up all clients. */
  3460. teth_ptr = &rmnet_ipa3_ctx->tether_device[device_type];
  3461. if (lan_clnt_idx == 0xffffffff) {
  3462. /* Reset the complete device info. */
  3463. memset(teth_ptr, 0,
  3464. sizeof(struct ipa_tether_device_info));
  3465. teth_ptr->ul_src_pipe = -1;
  3466. for (i = 0; i < IPA_MAX_NUM_HW_PATH_CLIENTS; i++)
  3467. teth_ptr->lan_client[i].client_idx = -1;
  3468. } else {
  3469. lan_client = &teth_ptr->lan_client[lan_clnt_idx];
  3470. /* Reset the client info before sending the message. */
  3471. memset(lan_client, 0, sizeof(struct ipa_lan_client));
  3472. lan_client->client_idx = -1;
  3473. /* Decrement the number of clients. */
  3474. rmnet_ipa3_ctx->tether_device[device_type].num_clients--;
  3475. }
  3476. return 0;
  3477. }
  3478. /* rmnet_ipa3_set_lan_client_info() -
  3479. * @data - IOCTL data
  3480. *
  3481. * This function handles WAN_IOC_SET_LAN_CLIENT_INFO.
  3482. * It is used to store LAN client information which
  3483. * is used to fetch the packet stats for a client.
  3484. *
  3485. * Return codes:
  3486. * 0: Success
  3487. * -EINVAL: Invalid args provided
  3488. */
  3489. int rmnet_ipa3_set_lan_client_info(
  3490. struct wan_ioctl_lan_client_info *data)
  3491. {
  3492. struct ipa_lan_client *lan_client = NULL;
  3493. struct ipa_tether_device_info *teth_ptr = NULL;
  3494. IPAWANDBG("Client MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
  3495. data->mac[0], data->mac[1], data->mac[2],
  3496. data->mac[3], data->mac[4], data->mac[5]);
  3497. /* Check if Device type is valid. */
  3498. if (data->device_type >= IPACM_MAX_CLIENT_DEVICE_TYPES ||
  3499. data->device_type < 0) {
  3500. IPAWANERR("Invalid Device type: %d\n", data->device_type);
  3501. return -EINVAL;
  3502. }
  3503. /* Check if Client index is valid. */
  3504. if (data->client_idx >= IPA_MAX_NUM_HW_PATH_CLIENTS ||
  3505. data->client_idx < 0) {
  3506. IPAWANERR("Invalid Client Index: %d\n", data->client_idx);
  3507. return -EINVAL;
  3508. }
  3509. mutex_lock(&rmnet_ipa3_ctx->per_client_stats_guard);
  3510. if (data->client_init) {
  3511. /* check if the client is already inited. */
  3512. if (rmnet_ipa3_ctx->tether_device[data->device_type]
  3513. .lan_client[data->client_idx].inited) {
  3514. IPAWANERR("Client already inited: %d:%d\n",
  3515. data->device_type, data->client_idx);
  3516. mutex_unlock(&rmnet_ipa3_ctx->per_client_stats_guard);
  3517. return -EINVAL;
  3518. }
  3519. }
  3520. teth_ptr = &rmnet_ipa3_ctx->tether_device[data->device_type];
  3521. lan_client = &teth_ptr->lan_client[data->client_idx];
  3522. memcpy(lan_client->mac, data->mac, IPA_MAC_ADDR_SIZE);
  3523. lan_client->client_idx = data->client_idx;
  3524. /* Update the Source pipe. */
  3525. rmnet_ipa3_ctx->tether_device[data->device_type].ul_src_pipe =
  3526. ipa3_get_ep_mapping(data->ul_src_pipe);
  3527. /* Update the header length if not set. */
  3528. if (!rmnet_ipa3_ctx->tether_device[data->device_type].hdr_len)
  3529. rmnet_ipa3_ctx->tether_device[data->device_type].hdr_len =
  3530. data->hdr_len;
  3531. lan_client->inited = true;
  3532. rmnet_ipa3_ctx->tether_device[data->device_type].num_clients++;
  3533. IPAWANDBG("Set the lan client info: %d, %d, %d\n",
  3534. lan_client->client_idx,
  3535. rmnet_ipa3_ctx->tether_device[data->device_type].ul_src_pipe,
  3536. rmnet_ipa3_ctx->tether_device[data->device_type].num_clients);
  3537. mutex_unlock(&rmnet_ipa3_ctx->per_client_stats_guard);
  3538. return 0;
  3539. }
  3540. /* rmnet_ipa3_delete_lan_client_info() -
  3541. * @data - IOCTL data
  3542. *
  3543. * This function handles WAN_IOC_DELETE_LAN_CLIENT_INFO.
  3544. * It is used to delete LAN client information which
  3545. * is used to fetch the packet stats for a client.
  3546. *
  3547. * Return codes:
  3548. * 0: Success
  3549. * -EINVAL: Invalid args provided
  3550. */
  3551. int rmnet_ipa3_clear_lan_client_info(
  3552. struct wan_ioctl_lan_client_info *data)
  3553. {
  3554. struct ipa_lan_client *lan_client = NULL;
  3555. struct ipa_tether_device_info *teth_ptr = NULL;
  3556. IPAWANDBG("Client MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
  3557. data->mac[0], data->mac[1], data->mac[2],
  3558. data->mac[3], data->mac[4], data->mac[5]);
  3559. /* Check if Device type is valid. */
  3560. if (data->device_type >= IPACM_MAX_CLIENT_DEVICE_TYPES ||
  3561. data->device_type < 0) {
  3562. IPAWANERR("Invalid Device type: %d\n", data->device_type);
  3563. return -EINVAL;
  3564. }
  3565. /* Check if Client index is valid. */
  3566. if (data->client_idx >= IPA_MAX_NUM_HW_PATH_CLIENTS ||
  3567. data->client_idx < 0) {
  3568. IPAWANERR("Invalid Client Index: %d\n", data->client_idx);
  3569. return -EINVAL;
  3570. }
  3571. IPAWANDBG("Client : %d:%d:%d\n",
  3572. data->device_type, data->client_idx,
  3573. rmnet_ipa3_ctx->tether_device[data->device_type].num_clients);
  3574. teth_ptr = &rmnet_ipa3_ctx->tether_device[data->device_type];
  3575. mutex_lock(&rmnet_ipa3_ctx->per_client_stats_guard);
  3576. lan_client = &teth_ptr->lan_client[data->client_idx];
  3577. if (!data->client_init) {
  3578. /* check if the client is already de-inited. */
  3579. if (!lan_client->inited) {
  3580. IPAWANERR("Client already de-inited: %d:%d\n",
  3581. data->device_type, data->client_idx);
  3582. mutex_unlock(&rmnet_ipa3_ctx->per_client_stats_guard);
  3583. return -EINVAL;
  3584. }
  3585. }
  3586. lan_client->inited = false;
  3587. mutex_unlock(&rmnet_ipa3_ctx->per_client_stats_guard);
  3588. return 0;
  3589. }
  3590. /* rmnet_ipa3_send_lan_client_msg() -
  3591. * @data - IOCTL data
  3592. *
  3593. * This function handles WAN_IOC_SEND_LAN_CLIENT_MSG.
  3594. * It is used to send LAN client information to IPACM.
  3595. *
  3596. * Return codes:
  3597. * 0: Success
  3598. * -EINVAL: Invalid args provided
  3599. */
  3600. int rmnet_ipa3_send_lan_client_msg(
  3601. struct wan_ioctl_send_lan_client_msg *data)
  3602. {
  3603. struct ipa_msg_meta msg_meta;
  3604. int rc;
  3605. struct ipa_lan_client_msg *lan_client;
  3606. /* Notify IPACM to reset the client index. */
  3607. lan_client = kzalloc(sizeof(struct ipa_lan_client_msg),
  3608. GFP_KERNEL);
  3609. if (!lan_client) {
  3610. IPAWANERR("Can't allocate memory for tether_info\n");
  3611. return -ENOMEM;
  3612. }
  3613. if (data->client_event != IPA_PER_CLIENT_STATS_CONNECT_EVENT &&
  3614. data->client_event != IPA_PER_CLIENT_STATS_DISCONNECT_EVENT) {
  3615. IPAWANERR("Wrong event given. Event:- %d\n",
  3616. data->client_event);
  3617. kfree(lan_client);
  3618. return -EINVAL;
  3619. }
  3620. data->lan_client.lanIface[IPA_RESOURCE_NAME_MAX-1] = '\0';
  3621. memset(&msg_meta, 0, sizeof(struct ipa_msg_meta));
  3622. memcpy(lan_client, &data->lan_client,
  3623. sizeof(struct ipa_lan_client_msg));
  3624. msg_meta.msg_type = data->client_event;
  3625. msg_meta.msg_len = sizeof(struct ipa_lan_client_msg);
  3626. rc = ipa_send_msg(&msg_meta, lan_client, rmnet_ipa_free_msg);
  3627. if (rc) {
  3628. IPAWANERR("ipa_send_msg failed: %d\n", rc);
  3629. kfree(lan_client);
  3630. return rc;
  3631. }
  3632. return 0;
  3633. }
  3634. /* rmnet_ipa3_enable_per_client_stats() -
  3635. * @data - IOCTL data
  3636. *
  3637. * This function handles WAN_IOC_ENABLE_PER_CLIENT_STATS.
  3638. * It is used to indicate Q6 to start capturing per client stats.
  3639. *
  3640. * Return codes:
  3641. * 0: Success
  3642. * -EINVAL: Invalid args provided
  3643. */
  3644. int rmnet_ipa3_enable_per_client_stats(
  3645. bool *data)
  3646. {
  3647. struct ipa_enable_per_client_stats_req_msg_v01 *req;
  3648. struct ipa_enable_per_client_stats_resp_msg_v01 *resp;
  3649. int rc;
  3650. req =
  3651. kzalloc(sizeof(struct ipa_enable_per_client_stats_req_msg_v01),
  3652. GFP_KERNEL);
  3653. if (!req) {
  3654. IPAWANERR("Can't allocate memory for stats message\n");
  3655. return -ENOMEM;
  3656. }
  3657. resp =
  3658. kzalloc(sizeof(struct ipa_enable_per_client_stats_resp_msg_v01),
  3659. GFP_KERNEL);
  3660. if (!resp) {
  3661. IPAWANERR("Can't allocate memory for stats message\n");
  3662. kfree(req);
  3663. return -ENOMEM;
  3664. }
  3665. memset(req, 0,
  3666. sizeof(struct ipa_enable_per_client_stats_req_msg_v01));
  3667. memset(resp, 0,
  3668. sizeof(struct ipa_enable_per_client_stats_resp_msg_v01));
  3669. if (*data)
  3670. req->enable_per_client_stats = 1;
  3671. else
  3672. req->enable_per_client_stats = 0;
  3673. rc = ipa3_qmi_enable_per_client_stats(req, resp);
  3674. if (rc) {
  3675. IPAWANERR("can't enable per client stats\n");
  3676. kfree(req);
  3677. kfree(resp);
  3678. return rc;
  3679. }
  3680. kfree(req);
  3681. kfree(resp);
  3682. return 0;
  3683. }
  3684. int rmnet_ipa3_query_per_client_stats(
  3685. struct wan_ioctl_query_per_client_stats *data)
  3686. {
  3687. struct ipa_get_stats_per_client_req_msg_v01 *req;
  3688. struct ipa_get_stats_per_client_resp_msg_v01 *resp;
  3689. int rc, lan_clnt_idx, lan_clnt_idx1, i;
  3690. struct ipa_lan_client *lan_client = NULL;
  3691. struct ipa_tether_device_info *teth_ptr = NULL;
  3692. IPAWANDBG("Client MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
  3693. data->client_info[0].mac[0],
  3694. data->client_info[0].mac[1],
  3695. data->client_info[0].mac[2],
  3696. data->client_info[0].mac[3],
  3697. data->client_info[0].mac[4],
  3698. data->client_info[0].mac[5]);
  3699. /* Check if Device type is valid. */
  3700. if (data->device_type >= IPACM_MAX_CLIENT_DEVICE_TYPES ||
  3701. data->device_type < 0) {
  3702. IPAWANERR("Invalid Device type: %d\n", data->device_type);
  3703. return -EINVAL;
  3704. }
  3705. /* Check if num_clients is valid. */
  3706. if (data->num_clients != IPA_MAX_NUM_HW_PATH_CLIENTS &&
  3707. data->num_clients != 1) {
  3708. IPAWANERR("Invalid number of clients: %d\n", data->num_clients);
  3709. return -EINVAL;
  3710. }
  3711. mutex_lock(&rmnet_ipa3_ctx->per_client_stats_guard);
  3712. /* Check if Source pipe is valid. */
  3713. if (rmnet_ipa3_ctx->tether_device
  3714. [data->device_type].ul_src_pipe == -1) {
  3715. IPAWANERR("Device not initialized: %d\n", data->device_type);
  3716. mutex_unlock(&rmnet_ipa3_ctx->per_client_stats_guard);
  3717. return -EINVAL;
  3718. }
  3719. /* Check if we have clients connected. */
  3720. if (rmnet_ipa3_ctx->tether_device[data->device_type].num_clients == 0) {
  3721. IPAWANERR("No clients connected: %d\n", data->device_type);
  3722. mutex_unlock(&rmnet_ipa3_ctx->per_client_stats_guard);
  3723. return -EINVAL;
  3724. }
  3725. if (data->num_clients == 1) {
  3726. /* Check if the client info is valid.*/
  3727. lan_clnt_idx1 = rmnet_ipa3_get_lan_client_info(
  3728. data->device_type,
  3729. data->client_info[0].mac);
  3730. if (lan_clnt_idx1 < 0) {
  3731. IPAWANERR("Client info not available return.\n");
  3732. mutex_unlock(&rmnet_ipa3_ctx->per_client_stats_guard);
  3733. return -EINVAL;
  3734. }
  3735. teth_ptr = &rmnet_ipa3_ctx->tether_device[data->device_type];
  3736. lan_client = &teth_ptr->lan_client[lan_clnt_idx1];
  3737. /*
  3738. * Check if disconnect flag is set and
  3739. * see if all the clients info are cleared.
  3740. */
  3741. if (data->disconnect_clnt &&
  3742. lan_client->inited) {
  3743. IPAWANERR("Client not inited. Try again.\n");
  3744. mutex_unlock(&rmnet_ipa3_ctx->per_client_stats_guard);
  3745. return -EAGAIN;
  3746. }
  3747. } else {
  3748. /* Max number of clients. */
  3749. /* Check if disconnect flag is set and
  3750. * see if all the clients info are cleared.
  3751. */
  3752. if (data->disconnect_clnt &&
  3753. rmnet_ipa3_check_any_client_inited(data->device_type)) {
  3754. IPAWANERR("CLient not inited. Try again.\n");
  3755. mutex_unlock(&rmnet_ipa3_ctx->per_client_stats_guard);
  3756. return -EAGAIN;
  3757. }
  3758. lan_clnt_idx1 = 0xffffffff;
  3759. }
  3760. req = kzalloc(sizeof(struct ipa_get_stats_per_client_req_msg_v01),
  3761. GFP_KERNEL);
  3762. if (!req) {
  3763. IPAWANERR("Can't allocate memory for stats message\n");
  3764. mutex_unlock(&rmnet_ipa3_ctx->per_client_stats_guard);
  3765. return -ENOMEM;
  3766. }
  3767. resp = kzalloc(sizeof(struct ipa_get_stats_per_client_resp_msg_v01),
  3768. GFP_KERNEL);
  3769. if (!resp) {
  3770. IPAWANERR("Can't allocate memory for stats message\n");
  3771. mutex_unlock(&rmnet_ipa3_ctx->per_client_stats_guard);
  3772. kfree(req);
  3773. return -ENOMEM;
  3774. }
  3775. memset(req, 0, sizeof(struct ipa_get_stats_per_client_req_msg_v01));
  3776. memset(resp, 0, sizeof(struct ipa_get_stats_per_client_resp_msg_v01));
  3777. IPAWANDBG("Reset stats: %s",
  3778. data->reset_stats?"Yes":"No");
  3779. if (data->reset_stats) {
  3780. req->reset_stats_valid = true;
  3781. req->reset_stats = true;
  3782. IPAWANDBG("fetch and reset the client stats\n");
  3783. }
  3784. req->client_id = lan_clnt_idx1;
  3785. req->src_pipe_id =
  3786. rmnet_ipa3_ctx->tether_device[data->device_type].ul_src_pipe;
  3787. IPAWANDBG("fetch the client stats for %d, %d\n", req->client_id,
  3788. req->src_pipe_id);
  3789. rc = ipa3_qmi_get_per_client_packet_stats(req, resp);
  3790. if (rc) {
  3791. IPAWANERR("can't get per client stats\n");
  3792. mutex_unlock(&rmnet_ipa3_ctx->per_client_stats_guard);
  3793. kfree(req);
  3794. kfree(resp);
  3795. return rc;
  3796. }
  3797. if (resp->per_client_stats_list_valid) {
  3798. for (i = 0; i < resp->per_client_stats_list_len
  3799. && i < IPA_MAX_NUM_HW_PATH_CLIENTS; i++) {
  3800. /* Subtract the header bytes from the DL bytes. */
  3801. data->client_info[i].ipv4_rx_bytes =
  3802. (resp->per_client_stats_list[i].num_dl_ipv4_bytes) -
  3803. (teth_ptr->hdr_len *
  3804. resp->per_client_stats_list[i].num_dl_ipv4_pkts);
  3805. /* UL header bytes are subtracted by Q6. */
  3806. data->client_info[i].ipv4_tx_bytes =
  3807. resp->per_client_stats_list[i].num_ul_ipv4_bytes;
  3808. /* Subtract the header bytes from the DL bytes. */
  3809. data->client_info[i].ipv6_rx_bytes =
  3810. (resp->per_client_stats_list[i].num_dl_ipv6_bytes) -
  3811. (teth_ptr->hdr_len *
  3812. resp->per_client_stats_list[i].num_dl_ipv6_pkts);
  3813. /* UL header bytes are subtracted by Q6. */
  3814. data->client_info[i].ipv6_tx_bytes =
  3815. resp->per_client_stats_list[i].num_ul_ipv6_bytes;
  3816. IPAWANDBG("tx_b_v4(%lu)v6(%lu)rx_b_v4(%lu) v6(%lu)\n",
  3817. (unsigned long) data->client_info[i].ipv4_tx_bytes,
  3818. (unsigned long) data->client_info[i].ipv6_tx_bytes,
  3819. (unsigned long) data->client_info[i].ipv4_rx_bytes,
  3820. (unsigned long) data->client_info[i].ipv6_rx_bytes);
  3821. /* Get the lan client index. */
  3822. lan_clnt_idx = resp->per_client_stats_list[i].client_id;
  3823. /* Check if lan_clnt_idx is valid. */
  3824. if (lan_clnt_idx < 0 ||
  3825. lan_clnt_idx >= IPA_MAX_NUM_HW_PATH_CLIENTS) {
  3826. IPAWANERR("Lan client index not valid.\n");
  3827. mutex_unlock(
  3828. &rmnet_ipa3_ctx->per_client_stats_guard);
  3829. kfree(req);
  3830. kfree(resp);
  3831. ipa_assert();
  3832. return -EINVAL;
  3833. }
  3834. memcpy(data->client_info[i].mac,
  3835. teth_ptr->lan_client[lan_clnt_idx].mac,
  3836. IPA_MAC_ADDR_SIZE);
  3837. }
  3838. }
  3839. IPAWANDBG("Disconnect clnt: %s",
  3840. data->disconnect_clnt?"Yes":"No");
  3841. if (data->disconnect_clnt) {
  3842. rmnet_ipa3_delete_lan_client_info(data->device_type,
  3843. lan_clnt_idx1);
  3844. }
  3845. mutex_unlock(&rmnet_ipa3_ctx->per_client_stats_guard);
  3846. kfree(req);
  3847. kfree(resp);
  3848. return 0;
  3849. }
  3850. #ifdef CONFIG_DEBUG_FS
  3851. static void rmnet_ipa_debugfs_init(void)
  3852. {
  3853. const mode_t read_write_mode = 0664;
  3854. struct rmnet_ipa_debugfs *dbgfs = &rmnet_ipa3_ctx->dbgfs;
  3855. dbgfs->dent = debugfs_create_dir("rmnet_ipa", 0);
  3856. if (IS_ERR(dbgfs->dent)) {
  3857. pr_err("fail to create folder in debug_fs\n");
  3858. return;
  3859. }
  3860. dbgfs->dfile_outstanding_high = debugfs_create_u32("outstanding_high",
  3861. read_write_mode, dbgfs->dent,
  3862. &rmnet_ipa3_ctx->outstanding_high);
  3863. if (!dbgfs->dfile_outstanding_high ||
  3864. IS_ERR(dbgfs->dfile_outstanding_high)) {
  3865. pr_err("failed to create file for outstanding_high\n");
  3866. goto fail;
  3867. }
  3868. dbgfs->dfile_outstanding_high_ctl =
  3869. debugfs_create_u32("outstanding_high_ctl",
  3870. read_write_mode, dbgfs->dent,
  3871. &rmnet_ipa3_ctx->outstanding_high_ctl);
  3872. if (!dbgfs->dfile_outstanding_high_ctl ||
  3873. IS_ERR(dbgfs->dfile_outstanding_high_ctl)) {
  3874. pr_err("failed to create file for outstanding_high_ctl\n");
  3875. goto fail;
  3876. }
  3877. dbgfs->dfile_outstanding_low = debugfs_create_u32("outstanding_low",
  3878. read_write_mode, dbgfs->dent,
  3879. &rmnet_ipa3_ctx->outstanding_low);
  3880. if (!dbgfs->dfile_outstanding_low ||
  3881. IS_ERR(dbgfs->dfile_outstanding_low)) {
  3882. pr_err("failed to create file for outstanding_low\n");
  3883. goto fail;
  3884. }
  3885. return;
  3886. fail:
  3887. debugfs_remove_recursive(dbgfs->dent);
  3888. memset(dbgfs, 0, sizeof(struct rmnet_ipa_debugfs));
  3889. }
  3890. static void rmnet_ipa_debugfs_remove(void)
  3891. {
  3892. if (IS_ERR(rmnet_ipa3_ctx->dbgfs.dent))
  3893. return;
  3894. debugfs_remove_recursive(rmnet_ipa3_ctx->dbgfs.dent);
  3895. memset(&rmnet_ipa3_ctx->dbgfs, 0, sizeof(struct rmnet_ipa_debugfs));
  3896. }
  3897. #else /* CONFIG_DEBUG_FS */
  3898. static void rmnet_ipa_debugfs_init(void){}
  3899. static void rmnet_ipa_debugfs_remove(void){}
  3900. #endif /* CONFIG_DEBUG_FS */
  3901. static int __init ipa3_wwan_init(void)
  3902. {
  3903. int i, j;
  3904. struct ipa_tether_device_info *teth_ptr = NULL;
  3905. void *ssr_hdl;
  3906. int rc = 0;
  3907. if (!ipa3_ctx) {
  3908. IPAWANERR_RL("ipa3_ctx was not initialized\n");
  3909. return -EINVAL;
  3910. }
  3911. rmnet_ipa3_ctx = kzalloc(sizeof(*rmnet_ipa3_ctx), GFP_KERNEL);
  3912. if (!rmnet_ipa3_ctx)
  3913. return -ENOMEM;
  3914. atomic_set(&rmnet_ipa3_ctx->is_initialized, 0);
  3915. atomic_set(&rmnet_ipa3_ctx->is_ssr, 0);
  3916. mutex_init(&rmnet_ipa3_ctx->pipe_handle_guard);
  3917. mutex_init(&rmnet_ipa3_ctx->add_mux_channel_lock);
  3918. mutex_init(&rmnet_ipa3_ctx->per_client_stats_guard);
  3919. /* Reset the Lan Stats. */
  3920. for (i = 0; i < IPACM_MAX_CLIENT_DEVICE_TYPES; i++) {
  3921. teth_ptr = &rmnet_ipa3_ctx->tether_device[i];
  3922. teth_ptr->ul_src_pipe = -1;
  3923. for (j = 0; j < IPA_MAX_NUM_HW_PATH_CLIENTS; j++)
  3924. teth_ptr->lan_client[j].client_idx = -1;
  3925. }
  3926. rmnet_ipa3_ctx->ipa3_to_apps_hdl = -1;
  3927. rmnet_ipa3_ctx->apps_to_ipa3_hdl = -1;
  3928. ipa3_qmi_init();
  3929. rmnet_ipa3_ctx->outstanding_high = OUTSTANDING_HIGH_DEFAULT;
  3930. rmnet_ipa3_ctx->outstanding_high_ctl = OUTSTANDING_HIGH_CTL_DEFAULT;
  3931. rmnet_ipa3_ctx->outstanding_low = OUTSTANDING_LOW_DEFAULT;
  3932. rmnet_ipa_debugfs_init();
  3933. /* Register for Local Modem SSR */
  3934. ssr_hdl = subsys_notif_register_notifier(SUBSYS_LOCAL_MODEM,
  3935. &ipa3_lcl_mdm_ssr_notifier);
  3936. if (!IS_ERR(ssr_hdl))
  3937. rmnet_ipa3_ctx->lcl_mdm_subsys_notify_handle = ssr_hdl;
  3938. else if (!rmnet_ipa3_ctx->ipa_config_is_apq) {
  3939. rc = PTR_ERR(ssr_hdl);
  3940. goto fail_dbgfs_rm;
  3941. }
  3942. if (rmnet_ipa3_ctx->ipa_config_is_apq) {
  3943. /* Register for Remote Modem SSR */
  3944. ssr_hdl = subsys_notif_register_notifier(SUBSYS_REMOTE_MODEM,
  3945. &ipa3_rmt_mdm_ssr_notifier);
  3946. if (IS_ERR(ssr_hdl)) {
  3947. rc = PTR_ERR(ssr_hdl);
  3948. goto fail_unreg_lcl_mdm_ssr;
  3949. }
  3950. rmnet_ipa3_ctx->rmt_mdm_subsys_notify_handle = ssr_hdl;
  3951. }
  3952. rc = platform_driver_register(&rmnet_ipa_driver);
  3953. if (rc)
  3954. goto fail_unreg_rmt_mdm_ssr;
  3955. return 0;
  3956. fail_unreg_rmt_mdm_ssr:
  3957. if (ipa3_ctx->platform_type == IPA_PLAT_TYPE_APQ) {
  3958. subsys_notif_unregister_notifier(
  3959. rmnet_ipa3_ctx->rmt_mdm_subsys_notify_handle,
  3960. &ipa3_rmt_mdm_ssr_notifier);
  3961. rmnet_ipa3_ctx->rmt_mdm_subsys_notify_handle = NULL;
  3962. }
  3963. fail_unreg_lcl_mdm_ssr:
  3964. if (rmnet_ipa3_ctx->lcl_mdm_subsys_notify_handle) {
  3965. subsys_notif_unregister_notifier(
  3966. rmnet_ipa3_ctx->lcl_mdm_subsys_notify_handle,
  3967. &ipa3_lcl_mdm_ssr_notifier);
  3968. rmnet_ipa3_ctx->lcl_mdm_subsys_notify_handle = NULL;
  3969. }
  3970. fail_dbgfs_rm:
  3971. rmnet_ipa_debugfs_remove();
  3972. return rc;
  3973. }
  3974. static void __exit ipa3_wwan_cleanup(void)
  3975. {
  3976. int ret;
  3977. platform_driver_unregister(&rmnet_ipa_driver);
  3978. if (rmnet_ipa3_ctx->lcl_mdm_subsys_notify_handle) {
  3979. ret = subsys_notif_unregister_notifier(
  3980. rmnet_ipa3_ctx->lcl_mdm_subsys_notify_handle,
  3981. &ipa3_lcl_mdm_ssr_notifier);
  3982. if (ret)
  3983. IPAWANERR(
  3984. "Failed to unregister subsys %s notifier ret=%d\n",
  3985. SUBSYS_LOCAL_MODEM, ret);
  3986. }
  3987. if (rmnet_ipa3_ctx->rmt_mdm_subsys_notify_handle) {
  3988. ret = subsys_notif_unregister_notifier(
  3989. rmnet_ipa3_ctx->rmt_mdm_subsys_notify_handle,
  3990. &ipa3_rmt_mdm_ssr_notifier);
  3991. if (ret)
  3992. IPAWANERR(
  3993. "Failed to unregister subsys %s notifier ret=%d\n",
  3994. SUBSYS_REMOTE_MODEM, ret);
  3995. }
  3996. rmnet_ipa_debugfs_remove();
  3997. ipa3_qmi_cleanup();
  3998. mutex_destroy(&rmnet_ipa3_ctx->per_client_stats_guard);
  3999. mutex_destroy(&rmnet_ipa3_ctx->add_mux_channel_lock);
  4000. mutex_destroy(&rmnet_ipa3_ctx->pipe_handle_guard);
  4001. kfree(rmnet_ipa3_ctx);
  4002. rmnet_ipa3_ctx = NULL;
  4003. }
  4004. static void ipa3_wwan_msg_free_cb(void *buff, u32 len, u32 type)
  4005. {
  4006. kfree(buff);
  4007. }
  4008. static int ipa3_rmnet_poll(struct napi_struct *napi, int budget)
  4009. {
  4010. int rcvd_pkts = 0;
  4011. rcvd_pkts = ipa_rx_poll(rmnet_ipa3_ctx->ipa3_to_apps_hdl,
  4012. NAPI_WEIGHT);
  4013. IPAWANDBG_LOW("rcvd packets: %d\n", rcvd_pkts);
  4014. return rcvd_pkts;
  4015. }
  4016. late_initcall(ipa3_wwan_init);
  4017. module_exit(ipa3_wwan_cleanup);
  4018. MODULE_DESCRIPTION("WWAN Network Interface");
  4019. MODULE_LICENSE("GPL v2");