rmnet_ipa.c 125 KB

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