rmnet_ipa.c 127 KB

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