hal_halmac.c 110 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2015 - 2017 Realtek Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. *****************************************************************************/
  15. #define _HAL_HALMAC_C_
  16. #include <drv_types.h> /* PADAPTER, struct dvobj_priv, SDIO_ERR_VAL8 and etc. */
  17. #include <hal_data.h> /* efuse, PHAL_DATA_TYPE and etc. */
  18. #include "hal_halmac.h" /* dvobj_to_halmac() and ect. */
  19. #define DEFAULT_INDICATOR_TIMELMT 1000 /* ms */
  20. #define MSG_PREFIX "[HALMAC]"
  21. #define RTW_HALMAC_DLFW_MEM_NO_STOP_TX
  22. /*
  23. * Driver API for HALMAC operations
  24. */
  25. #ifdef CONFIG_SDIO_HCI
  26. #include <rtw_sdio.h>
  27. static u8 _halmac_mac_reg_page0_chk(const char *func, struct dvobj_priv *dvobj, u32 offset)
  28. {
  29. #if defined(CONFIG_IO_CHECK_IN_ANA_LOW_CLK) && defined(CONFIG_LPS_LCLK)
  30. struct pwrctrl_priv *pwrpriv = &dvobj->pwrctl_priv;
  31. u32 mac_reg_offset = 0;
  32. if (pwrpriv->pwr_mode == PS_MODE_ACTIVE)
  33. return _TRUE;
  34. if (pwrpriv->lps_level == LPS_NORMAL)
  35. return _TRUE;
  36. if (pwrpriv->rpwm >= PS_STATE_S2)
  37. return _TRUE;
  38. if (offset & (WLAN_IOREG_DEVICE_ID << 13)) { /*WLAN_IOREG_OFFSET*/
  39. mac_reg_offset = offset & HALMAC_WLAN_MAC_REG_MSK;
  40. if (mac_reg_offset < 0x100) {
  41. RTW_ERR(FUNC_ADPT_FMT
  42. "access MAC REG -0x%04x in PS-mode:0x%02x (rpwm:0x%02x, lps_level:0x%02x)\n",
  43. FUNC_ADPT_ARG(dvobj_get_primary_adapter(dvobj)), mac_reg_offset,
  44. pwrpriv->pwr_mode, pwrpriv->rpwm, pwrpriv->lps_level);
  45. rtw_warn_on(1);
  46. return _FALSE;
  47. }
  48. }
  49. #endif
  50. return _TRUE;
  51. }
  52. static u8 _halmac_sdio_cmd52_read(void *p, u32 offset)
  53. {
  54. struct dvobj_priv *d;
  55. u8 val;
  56. u8 ret;
  57. d = (struct dvobj_priv *)p;
  58. _halmac_mac_reg_page0_chk(__func__, d, offset);
  59. ret = rtw_sdio_read_cmd52(d, offset, &val, 1);
  60. if (_FAIL == ret) {
  61. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  62. return SDIO_ERR_VAL8;
  63. }
  64. return val;
  65. }
  66. static void _halmac_sdio_cmd52_write(void *p, u32 offset, u8 val)
  67. {
  68. struct dvobj_priv *d;
  69. u8 ret;
  70. d = (struct dvobj_priv *)p;
  71. _halmac_mac_reg_page0_chk(__func__, d, offset);
  72. ret = rtw_sdio_write_cmd52(d, offset, &val, 1);
  73. if (_FAIL == ret)
  74. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  75. }
  76. static u8 _halmac_sdio_reg_read_8(void *p, u32 offset)
  77. {
  78. struct dvobj_priv *d;
  79. u8 *pbuf;
  80. u8 val;
  81. u8 ret;
  82. d = (struct dvobj_priv *)p;
  83. val = SDIO_ERR_VAL8;
  84. _halmac_mac_reg_page0_chk(__func__, d, offset);
  85. pbuf = rtw_zmalloc(1);
  86. if (!pbuf)
  87. return val;
  88. ret = rtw_sdio_read_cmd53(d, offset, pbuf, 1);
  89. if (ret == _FAIL) {
  90. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  91. goto exit;
  92. }
  93. val = *pbuf;
  94. exit:
  95. rtw_mfree(pbuf, 1);
  96. return val;
  97. }
  98. static u16 _halmac_sdio_reg_read_16(void *p, u32 offset)
  99. {
  100. struct dvobj_priv *d;
  101. u8 *pbuf;
  102. u16 val;
  103. u8 ret;
  104. d = (struct dvobj_priv *)p;
  105. val = SDIO_ERR_VAL16;
  106. _halmac_mac_reg_page0_chk(__func__, d, offset);
  107. pbuf = rtw_zmalloc(2);
  108. if (!pbuf)
  109. return val;
  110. ret = rtw_sdio_read_cmd53(d, offset, pbuf, 2);
  111. if (ret == _FAIL) {
  112. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  113. goto exit;
  114. }
  115. val = le16_to_cpu(*(u16 *)pbuf);
  116. exit:
  117. rtw_mfree(pbuf, 2);
  118. return val;
  119. }
  120. static u32 _halmac_sdio_reg_read_32(void *p, u32 offset)
  121. {
  122. struct dvobj_priv *d;
  123. u8 *pbuf;
  124. u32 val;
  125. u8 ret;
  126. d = (struct dvobj_priv *)p;
  127. val = SDIO_ERR_VAL32;
  128. _halmac_mac_reg_page0_chk(__func__, d, offset);
  129. pbuf = rtw_zmalloc(4);
  130. if (!pbuf)
  131. return val;
  132. ret = rtw_sdio_read_cmd53(d, offset, pbuf, 4);
  133. if (ret == _FAIL) {
  134. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  135. goto exit;
  136. }
  137. val = le32_to_cpu(*(u32 *)pbuf);
  138. exit:
  139. rtw_mfree(pbuf, 4);
  140. return val;
  141. }
  142. static u8 _halmac_sdio_reg_read_n(void *p, u32 offset, u32 size, u8 *data)
  143. {
  144. struct dvobj_priv *d = (struct dvobj_priv *)p;
  145. u8 *pbuf;
  146. u8 ret;
  147. u8 rst = _FALSE;
  148. u32 sdio_read_size;
  149. sdio_read_size = RND4(size);
  150. sdio_read_size = rtw_sdio_cmd53_align_size(d, sdio_read_size);
  151. pbuf = rtw_zmalloc(sdio_read_size);
  152. if ((!pbuf) || (!data))
  153. return rst;
  154. ret = rtw_sdio_read_cmd53(d, offset, pbuf, sdio_read_size);
  155. if (ret == _FAIL) {
  156. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  157. goto exit;
  158. }
  159. _rtw_memcpy(data, pbuf, size);
  160. rst = _TRUE;
  161. exit:
  162. rtw_mfree(pbuf, sdio_read_size);
  163. return rst;
  164. }
  165. static void _halmac_sdio_reg_write_8(void *p, u32 offset, u8 val)
  166. {
  167. struct dvobj_priv *d;
  168. u8 *pbuf;
  169. u8 ret;
  170. d = (struct dvobj_priv *)p;
  171. _halmac_mac_reg_page0_chk(__func__, d, offset);
  172. pbuf = rtw_zmalloc(1);
  173. if (!pbuf)
  174. return;
  175. _rtw_memcpy(pbuf, &val, 1);
  176. ret = rtw_sdio_write_cmd53(d, offset, pbuf, 1);
  177. if (ret == _FAIL)
  178. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  179. rtw_mfree(pbuf, 1);
  180. }
  181. static void _halmac_sdio_reg_write_16(void *p, u32 offset, u16 val)
  182. {
  183. struct dvobj_priv *d;
  184. u8 *pbuf;
  185. u8 ret;
  186. d = (struct dvobj_priv *)p;
  187. _halmac_mac_reg_page0_chk(__func__, d, offset);
  188. val = cpu_to_le16(val);
  189. pbuf = rtw_zmalloc(2);
  190. if (!pbuf)
  191. return;
  192. _rtw_memcpy(pbuf, &val, 2);
  193. ret = rtw_sdio_write_cmd53(d, offset, pbuf, 2);
  194. if (ret == _FAIL)
  195. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  196. rtw_mfree(pbuf, 2);
  197. }
  198. static void _halmac_sdio_reg_write_32(void *p, u32 offset, u32 val)
  199. {
  200. struct dvobj_priv *d;
  201. u8 *pbuf;
  202. u8 ret;
  203. d = (struct dvobj_priv *)p;
  204. _halmac_mac_reg_page0_chk(__func__, d, offset);
  205. val = cpu_to_le32(val);
  206. pbuf = rtw_zmalloc(4);
  207. if (!pbuf)
  208. return;
  209. _rtw_memcpy(pbuf, &val, 4);
  210. ret = rtw_sdio_write_cmd53(d, offset, pbuf, 4);
  211. if (ret == _FAIL)
  212. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  213. rtw_mfree(pbuf, 4);
  214. }
  215. static u8 _halmac_sdio_read_cia(void *p, u32 offset)
  216. {
  217. struct dvobj_priv *d;
  218. u8 data = 0;
  219. u8 ret;
  220. d = (struct dvobj_priv *)p;
  221. ret = rtw_sdio_f0_read(d, offset, &data, 1);
  222. if (ret == _FAIL)
  223. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  224. return data;
  225. }
  226. #else /* !CONFIG_SDIO_HCI */
  227. static u8 _halmac_reg_read_8(void *p, u32 offset)
  228. {
  229. struct dvobj_priv *d;
  230. PADAPTER adapter;
  231. d = (struct dvobj_priv *)p;
  232. adapter = dvobj_get_primary_adapter(d);
  233. return rtw_read8(adapter, offset);
  234. }
  235. static u16 _halmac_reg_read_16(void *p, u32 offset)
  236. {
  237. struct dvobj_priv *d;
  238. PADAPTER adapter;
  239. d = (struct dvobj_priv *)p;
  240. adapter = dvobj_get_primary_adapter(d);
  241. return rtw_read16(adapter, offset);
  242. }
  243. static u32 _halmac_reg_read_32(void *p, u32 offset)
  244. {
  245. struct dvobj_priv *d;
  246. PADAPTER adapter;
  247. d = (struct dvobj_priv *)p;
  248. adapter = dvobj_get_primary_adapter(d);
  249. return rtw_read32(adapter, offset);
  250. }
  251. static void _halmac_reg_write_8(void *p, u32 offset, u8 val)
  252. {
  253. struct dvobj_priv *d;
  254. PADAPTER adapter;
  255. int err;
  256. d = (struct dvobj_priv *)p;
  257. adapter = dvobj_get_primary_adapter(d);
  258. err = rtw_write8(adapter, offset, val);
  259. if (err == _FAIL)
  260. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  261. }
  262. static void _halmac_reg_write_16(void *p, u32 offset, u16 val)
  263. {
  264. struct dvobj_priv *d;
  265. PADAPTER adapter;
  266. int err;
  267. d = (struct dvobj_priv *)p;
  268. adapter = dvobj_get_primary_adapter(d);
  269. err = rtw_write16(adapter, offset, val);
  270. if (err == _FAIL)
  271. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  272. }
  273. static void _halmac_reg_write_32(void *p, u32 offset, u32 val)
  274. {
  275. struct dvobj_priv *d;
  276. PADAPTER adapter;
  277. int err;
  278. d = (struct dvobj_priv *)p;
  279. adapter = dvobj_get_primary_adapter(d);
  280. err = rtw_write32(adapter, offset, val);
  281. if (err == _FAIL)
  282. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  283. }
  284. #endif /* !CONFIG_SDIO_HCI */
  285. static u8 _halmac_mfree(void *p, void *buffer, u32 size)
  286. {
  287. rtw_mfree(buffer, size);
  288. return _TRUE;
  289. }
  290. static void *_halmac_malloc(void *p, u32 size)
  291. {
  292. return rtw_zmalloc(size);
  293. }
  294. static u8 _halmac_memcpy(void *p, void *dest, void *src, u32 size)
  295. {
  296. _rtw_memcpy(dest, src, size);
  297. return _TRUE;
  298. }
  299. static u8 _halmac_memset(void *p, void *addr, u8 value, u32 size)
  300. {
  301. _rtw_memset(addr, value, size);
  302. return _TRUE;
  303. }
  304. static void _halmac_udelay(void *p, u32 us)
  305. {
  306. /* Most hardware polling wait time < 50us) */
  307. if (us <= 50)
  308. rtw_udelay_os(us);
  309. else if (us <= 1000)
  310. rtw_usleep_os(us);
  311. else
  312. rtw_msleep_os(RTW_DIV_ROUND_UP(us, 1000));
  313. }
  314. static u8 _halmac_mutex_init(void *p, HALMAC_MUTEX *pMutex)
  315. {
  316. _rtw_mutex_init(pMutex);
  317. return _TRUE;
  318. }
  319. static u8 _halmac_mutex_deinit(void *p, HALMAC_MUTEX *pMutex)
  320. {
  321. _rtw_mutex_free(pMutex);
  322. return _TRUE;
  323. }
  324. static u8 _halmac_mutex_lock(void *p, HALMAC_MUTEX *pMutex)
  325. {
  326. int err;
  327. err = _enter_critical_mutex(pMutex, NULL);
  328. if (err)
  329. return _FALSE;
  330. return _TRUE;
  331. }
  332. static u8 _halmac_mutex_unlock(void *p, HALMAC_MUTEX *pMutex)
  333. {
  334. _exit_critical_mutex(pMutex, NULL);
  335. return _TRUE;
  336. }
  337. static u8 _halmac_msg_print(void *p, u32 msg_type, u8 msg_level, s8 *fmt, ...)
  338. {
  339. #define MSG_LEN 100
  340. va_list args;
  341. u8 str[MSG_LEN] = {0};
  342. int err;
  343. u8 ret = _TRUE;
  344. str[0] = '\n';
  345. va_start(args, fmt);
  346. err = vsnprintf(str, MSG_LEN, fmt, args);
  347. va_end(args);
  348. /* An output error is encountered */
  349. if (err < 0)
  350. return _FALSE;
  351. /* Output may be truncated due to size limit */
  352. if ((err == (MSG_LEN - 1)) && (str[MSG_LEN - 2] != '\n'))
  353. ret = _FALSE;
  354. if (msg_level == HALMAC_DBG_ALWAYS)
  355. RTW_PRINT(MSG_PREFIX "%s", str);
  356. else if (msg_level <= HALMAC_DBG_ERR)
  357. RTW_ERR(MSG_PREFIX "%s", str);
  358. else if (msg_level <= HALMAC_DBG_WARN)
  359. RTW_WARN(MSG_PREFIX "%s", str);
  360. else
  361. RTW_DBG(MSG_PREFIX "%s", str);
  362. return ret;
  363. }
  364. static u8 _halmac_buff_print(void *p, u32 msg_type, u8 msg_level, s8 *buf, u32 size)
  365. {
  366. if (msg_level <= HALMAC_DBG_WARN)
  367. RTW_INFO_DUMP(MSG_PREFIX, buf, size);
  368. else
  369. RTW_DBG_DUMP(MSG_PREFIX, buf, size);
  370. return _TRUE;
  371. }
  372. const char *const RTW_HALMAC_FEATURE_NAME[] = {
  373. "HALMAC_FEATURE_CFG_PARA",
  374. "HALMAC_FEATURE_DUMP_PHYSICAL_EFUSE",
  375. "HALMAC_FEATURE_DUMP_LOGICAL_EFUSE",
  376. "HALMAC_FEATURE_UPDATE_PACKET",
  377. "HALMAC_FEATURE_UPDATE_DATAPACK",
  378. "HALMAC_FEATURE_RUN_DATAPACK",
  379. "HALMAC_FEATURE_CHANNEL_SWITCH",
  380. "HALMAC_FEATURE_IQK",
  381. "HALMAC_FEATURE_POWER_TRACKING",
  382. "HALMAC_FEATURE_PSD",
  383. "HALMAC_FEATURE_FW_SNDING",
  384. "HALMAC_FEATURE_ALL"
  385. };
  386. static inline u8 is_valid_id_status(enum halmac_feature_id id, enum halmac_cmd_process_status status)
  387. {
  388. switch (id) {
  389. case HALMAC_FEATURE_CFG_PARA:
  390. RTW_DBG("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
  391. break;
  392. case HALMAC_FEATURE_DUMP_PHYSICAL_EFUSE:
  393. RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
  394. if (HALMAC_CMD_PROCESS_DONE != status)
  395. RTW_INFO("%s: id(%d) unspecified status(%d)!\n",
  396. __FUNCTION__, id, status);
  397. break;
  398. case HALMAC_FEATURE_DUMP_LOGICAL_EFUSE:
  399. RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
  400. if (HALMAC_CMD_PROCESS_DONE != status)
  401. RTW_INFO("%s: id(%d) unspecified status(%d)!\n",
  402. __FUNCTION__, id, status);
  403. break;
  404. case HALMAC_FEATURE_UPDATE_PACKET:
  405. RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
  406. break;
  407. case HALMAC_FEATURE_UPDATE_DATAPACK:
  408. RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
  409. break;
  410. case HALMAC_FEATURE_RUN_DATAPACK:
  411. RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
  412. break;
  413. case HALMAC_FEATURE_CHANNEL_SWITCH:
  414. RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
  415. break;
  416. case HALMAC_FEATURE_IQK:
  417. RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
  418. break;
  419. case HALMAC_FEATURE_POWER_TRACKING:
  420. RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
  421. break;
  422. case HALMAC_FEATURE_PSD:
  423. RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
  424. break;
  425. case HALMAC_FEATURE_FW_SNDING:
  426. RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
  427. break;
  428. case HALMAC_FEATURE_ALL:
  429. RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
  430. break;
  431. default:
  432. RTW_ERR("%s: unknown feature id(%d)\n", __FUNCTION__, id);
  433. return _FALSE;
  434. }
  435. return _TRUE;
  436. }
  437. static int init_halmac_event_with_waittime(struct dvobj_priv *d, enum halmac_feature_id id, u8 *buf, u32 size, u32 time)
  438. {
  439. struct submit_ctx *sctx;
  440. if (!d->hmpriv.indicator[id].sctx) {
  441. sctx = (struct submit_ctx *)rtw_zmalloc(sizeof(*sctx));
  442. if (!sctx)
  443. return -1;
  444. } else {
  445. RTW_WARN("%s: id(%d) sctx is not NULL!!\n", __FUNCTION__, id);
  446. sctx = d->hmpriv.indicator[id].sctx;
  447. d->hmpriv.indicator[id].sctx = NULL;
  448. }
  449. rtw_sctx_init(sctx, time);
  450. d->hmpriv.indicator[id].buffer = buf;
  451. d->hmpriv.indicator[id].buf_size = size;
  452. d->hmpriv.indicator[id].ret_size = 0;
  453. d->hmpriv.indicator[id].status = 0;
  454. /* fill sctx at least to sure other variables are all ready! */
  455. d->hmpriv.indicator[id].sctx = sctx;
  456. return 0;
  457. }
  458. static inline int init_halmac_event(struct dvobj_priv *d, enum halmac_feature_id id, u8 *buf, u32 size)
  459. {
  460. return init_halmac_event_with_waittime(d, id, buf, size, DEFAULT_INDICATOR_TIMELMT);
  461. }
  462. static void free_halmac_event(struct dvobj_priv *d, enum halmac_feature_id id)
  463. {
  464. struct submit_ctx *sctx;
  465. if (!d->hmpriv.indicator[id].sctx)
  466. return;
  467. sctx = d->hmpriv.indicator[id].sctx;
  468. d->hmpriv.indicator[id].sctx = NULL;
  469. rtw_mfree((u8 *)sctx, sizeof(*sctx));
  470. }
  471. static int wait_halmac_event(struct dvobj_priv *d, enum halmac_feature_id id)
  472. {
  473. struct halmac_adapter *mac;
  474. struct halmac_api *api;
  475. struct submit_ctx *sctx;
  476. int ret;
  477. sctx = d->hmpriv.indicator[id].sctx;
  478. if (!sctx)
  479. return -1;
  480. ret = rtw_sctx_wait(sctx, RTW_HALMAC_FEATURE_NAME[id]);
  481. free_halmac_event(d, id);
  482. if (_SUCCESS == ret)
  483. return 0;
  484. /* timeout! We have to reset halmac state */
  485. RTW_ERR("%s: Wait id(%d, %s) TIMEOUT! Reset HALMAC state!\n",
  486. __FUNCTION__, id, RTW_HALMAC_FEATURE_NAME[id]);
  487. mac = dvobj_to_halmac(d);
  488. api = HALMAC_GET_API(mac);
  489. api->halmac_reset_feature(mac, id);
  490. return -1;
  491. }
  492. /*
  493. * Return:
  494. * Always return _TRUE, HALMAC don't care the return value.
  495. */
  496. static u8 _halmac_event_indication(void *p, enum halmac_feature_id feature_id, enum halmac_cmd_process_status process_status, u8 *buf, u32 size)
  497. {
  498. struct dvobj_priv *d;
  499. PADAPTER adapter;
  500. PHAL_DATA_TYPE hal;
  501. struct halmac_indicator *tbl, *indicator;
  502. struct submit_ctx *sctx;
  503. u32 cpsz;
  504. u8 ret;
  505. d = (struct dvobj_priv *)p;
  506. adapter = dvobj_get_primary_adapter(d);
  507. hal = GET_HAL_DATA(adapter);
  508. tbl = d->hmpriv.indicator;
  509. /* Filter(Skip) middle status indication */
  510. ret = is_valid_id_status(feature_id, process_status);
  511. if (_FALSE == ret)
  512. goto exit;
  513. indicator = &tbl[feature_id];
  514. indicator->status = process_status;
  515. indicator->ret_size = size;
  516. if (!indicator->sctx) {
  517. RTW_WARN("%s: No feature id(%d, %s) waiting!!\n", __FUNCTION__, feature_id, RTW_HALMAC_FEATURE_NAME[feature_id]);
  518. goto exit;
  519. }
  520. sctx = indicator->sctx;
  521. if (HALMAC_CMD_PROCESS_ERROR == process_status) {
  522. RTW_ERR("%s: Something wrong id(%d, %s)!!\n", __FUNCTION__, feature_id, RTW_HALMAC_FEATURE_NAME[feature_id]);
  523. rtw_sctx_done_err(&sctx, RTW_SCTX_DONE_UNKNOWN);
  524. goto exit;
  525. }
  526. if (size > indicator->buf_size) {
  527. RTW_WARN("%s: id(%d, %s) buffer is not enough(%d<%d), data will be truncated!\n",
  528. __FUNCTION__, feature_id, RTW_HALMAC_FEATURE_NAME[feature_id], indicator->buf_size, size);
  529. cpsz = indicator->buf_size;
  530. } else {
  531. cpsz = size;
  532. }
  533. if (cpsz && indicator->buffer)
  534. _rtw_memcpy(indicator->buffer, buf, cpsz);
  535. rtw_sctx_done(&sctx);
  536. exit:
  537. return _TRUE;
  538. }
  539. struct halmac_platform_api rtw_halmac_platform_api = {
  540. /* R/W register */
  541. #ifdef CONFIG_SDIO_HCI
  542. .SDIO_CMD52_READ = _halmac_sdio_cmd52_read,
  543. .SDIO_CMD53_READ_8 = _halmac_sdio_reg_read_8,
  544. .SDIO_CMD53_READ_16 = _halmac_sdio_reg_read_16,
  545. .SDIO_CMD53_READ_32 = _halmac_sdio_reg_read_32,
  546. .SDIO_CMD53_READ_N = _halmac_sdio_reg_read_n,
  547. .SDIO_CMD52_WRITE = _halmac_sdio_cmd52_write,
  548. .SDIO_CMD53_WRITE_8 = _halmac_sdio_reg_write_8,
  549. .SDIO_CMD53_WRITE_16 = _halmac_sdio_reg_write_16,
  550. .SDIO_CMD53_WRITE_32 = _halmac_sdio_reg_write_32,
  551. .SDIO_CMD52_CIA_READ = _halmac_sdio_read_cia,
  552. #endif /* CONFIG_SDIO_HCI */
  553. #if defined(CONFIG_USB_HCI) || defined(CONFIG_PCIE_HCI)
  554. .REG_READ_8 = _halmac_reg_read_8,
  555. .REG_READ_16 = _halmac_reg_read_16,
  556. .REG_READ_32 = _halmac_reg_read_32,
  557. .REG_WRITE_8 = _halmac_reg_write_8,
  558. .REG_WRITE_16 = _halmac_reg_write_16,
  559. .REG_WRITE_32 = _halmac_reg_write_32,
  560. #endif /* CONFIG_USB_HCI || CONFIG_PCIE_HCI */
  561. /* Write data */
  562. #if 0
  563. /* impletement in HAL-IC level */
  564. .SEND_RSVD_PAGE = sdio_write_data_rsvd_page,
  565. .SEND_H2C_PKT = sdio_write_data_h2c,
  566. #endif
  567. /* Memory allocate */
  568. .RTL_FREE = _halmac_mfree,
  569. .RTL_MALLOC = _halmac_malloc,
  570. .RTL_MEMCPY = _halmac_memcpy,
  571. .RTL_MEMSET = _halmac_memset,
  572. /* Sleep */
  573. .RTL_DELAY_US = _halmac_udelay,
  574. /* Process Synchronization */
  575. .MUTEX_INIT = _halmac_mutex_init,
  576. .MUTEX_DEINIT = _halmac_mutex_deinit,
  577. .MUTEX_LOCK = _halmac_mutex_lock,
  578. .MUTEX_UNLOCK = _halmac_mutex_unlock,
  579. .MSG_PRINT = _halmac_msg_print,
  580. .BUFF_PRINT = _halmac_buff_print,
  581. .EVENT_INDICATION = _halmac_event_indication,
  582. };
  583. u8 rtw_halmac_read8(struct intf_hdl *pintfhdl, u32 addr)
  584. {
  585. struct halmac_adapter *mac;
  586. struct halmac_api *api;
  587. /* WARNING: pintf_dev should not be null! */
  588. mac = dvobj_to_halmac(pintfhdl->pintf_dev);
  589. api = HALMAC_GET_API(mac);
  590. return api->halmac_reg_read_8(mac, addr);
  591. }
  592. u16 rtw_halmac_read16(struct intf_hdl *pintfhdl, u32 addr)
  593. {
  594. struct halmac_adapter *mac;
  595. struct halmac_api *api;
  596. /* WARNING: pintf_dev should not be null! */
  597. mac = dvobj_to_halmac(pintfhdl->pintf_dev);
  598. api = HALMAC_GET_API(mac);
  599. return api->halmac_reg_read_16(mac, addr);
  600. }
  601. u32 rtw_halmac_read32(struct intf_hdl *pintfhdl, u32 addr)
  602. {
  603. struct halmac_adapter *mac;
  604. struct halmac_api *api;
  605. /* WARNING: pintf_dev should not be null! */
  606. mac = dvobj_to_halmac(pintfhdl->pintf_dev);
  607. api = HALMAC_GET_API(mac);
  608. return api->halmac_reg_read_32(mac, addr);
  609. }
  610. static void _read_register(struct dvobj_priv *d, u32 addr, u32 cnt, u8 *buf)
  611. {
  612. #if 1
  613. struct _ADAPTER *a;
  614. u32 i, n;
  615. u16 val16;
  616. u32 val32;
  617. a = dvobj_get_primary_adapter(d);
  618. i = addr & 0x3;
  619. /* Handle address not start from 4 bytes alignment case */
  620. if (i) {
  621. val32 = cpu_to_le32(rtw_read32(a, addr & ~0x3));
  622. n = 4 - i;
  623. _rtw_memcpy(buf, ((u8 *)&val32) + i, n);
  624. i = n;
  625. cnt -= n;
  626. }
  627. while (cnt) {
  628. if (cnt >= 4)
  629. n = 4;
  630. else if (cnt >= 2)
  631. n = 2;
  632. else
  633. n = 1;
  634. cnt -= n;
  635. switch (n) {
  636. case 1:
  637. buf[i] = rtw_read8(a, addr+i);
  638. i++;
  639. break;
  640. case 2:
  641. val16 = cpu_to_le16(rtw_read16(a, addr+i));
  642. _rtw_memcpy(&buf[i], &val16, 2);
  643. i += 2;
  644. break;
  645. case 4:
  646. val32 = cpu_to_le32(rtw_read32(a, addr+i));
  647. _rtw_memcpy(&buf[i], &val32, 4);
  648. i += 4;
  649. break;
  650. }
  651. }
  652. #else
  653. struct _ADAPTER *a;
  654. u32 i;
  655. a = dvobj_get_primary_adapter(d);
  656. for (i = 0; i < cnt; i++)
  657. buf[i] = rtw_read8(a, addr + i);
  658. #endif
  659. }
  660. #ifdef CONFIG_SDIO_HCI
  661. static int _sdio_read_local(struct dvobj_priv *d, u32 addr, u32 cnt, u8 *buf)
  662. {
  663. struct halmac_adapter *mac;
  664. struct halmac_api *api;
  665. enum halmac_ret_status status;
  666. if (buf == NULL)
  667. return -1;
  668. mac = dvobj_to_halmac(d);
  669. api = HALMAC_GET_API(mac);
  670. status = api->halmac_reg_sdio_cmd53_read_n(mac, addr, cnt, buf);
  671. if (status != HALMAC_RET_SUCCESS) {
  672. RTW_ERR("%s: addr=0x%08x cnt=%d err=%d\n",
  673. __FUNCTION__, addr, cnt, status);
  674. return -1;
  675. }
  676. return 0;
  677. }
  678. #endif /* CONFIG_SDIO_HCI */
  679. void rtw_halmac_read_mem(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem)
  680. {
  681. struct dvobj_priv *d;
  682. if (pmem == NULL) {
  683. RTW_ERR("pmem is NULL\n");
  684. return;
  685. }
  686. d = pintfhdl->pintf_dev;
  687. #ifdef CONFIG_SDIO_HCI
  688. if (addr & 0xFFFF0000) {
  689. int err = 0;
  690. err = _sdio_read_local(d, addr, cnt, pmem);
  691. if (!err)
  692. return;
  693. }
  694. #endif /* CONFIG_SDIO_HCI */
  695. _read_register(d, addr, cnt, pmem);
  696. }
  697. #ifdef CONFIG_SDIO_INDIRECT_ACCESS
  698. u8 rtw_halmac_iread8(struct intf_hdl *pintfhdl, u32 addr)
  699. {
  700. struct halmac_adapter *mac;
  701. struct halmac_api *api;
  702. /* WARNING: pintf_dev should not be null! */
  703. mac = dvobj_to_halmac(pintfhdl->pintf_dev);
  704. api = HALMAC_GET_API(mac);
  705. /*return api->halmac_reg_read_indirect_8(mac, addr);*/
  706. return api->halmac_reg_read_8(mac, addr);
  707. }
  708. u16 rtw_halmac_iread16(struct intf_hdl *pintfhdl, u32 addr)
  709. {
  710. struct halmac_adapter *mac;
  711. struct halmac_api *api;
  712. u16 val16 = 0;
  713. /* WARNING: pintf_dev should not be null! */
  714. mac = dvobj_to_halmac(pintfhdl->pintf_dev);
  715. api = HALMAC_GET_API(mac);
  716. /*return api->halmac_reg_read_indirect_16(mac, addr);*/
  717. return api->halmac_reg_read_16(mac, addr);
  718. }
  719. u32 rtw_halmac_iread32(struct intf_hdl *pintfhdl, u32 addr)
  720. {
  721. struct halmac_adapter *mac;
  722. struct halmac_api *api;
  723. /* WARNING: pintf_dev should not be null! */
  724. mac = dvobj_to_halmac(pintfhdl->pintf_dev);
  725. api = HALMAC_GET_API(mac);
  726. return api->halmac_reg_read_indirect_32(mac, addr);
  727. }
  728. #endif /* CONFIG_SDIO_INDIRECT_ACCESS */
  729. int rtw_halmac_write8(struct intf_hdl *pintfhdl, u32 addr, u8 value)
  730. {
  731. struct halmac_adapter *mac;
  732. struct halmac_api *api;
  733. enum halmac_ret_status status;
  734. /* WARNING: pintf_dev should not be null! */
  735. mac = dvobj_to_halmac(pintfhdl->pintf_dev);
  736. api = HALMAC_GET_API(mac);
  737. status = api->halmac_reg_write_8(mac, addr, value);
  738. if (status == HALMAC_RET_SUCCESS)
  739. return 0;
  740. return -1;
  741. }
  742. int rtw_halmac_write16(struct intf_hdl *pintfhdl, u32 addr, u16 value)
  743. {
  744. struct halmac_adapter *mac;
  745. struct halmac_api *api;
  746. enum halmac_ret_status status;
  747. /* WARNING: pintf_dev should not be null! */
  748. mac = dvobj_to_halmac(pintfhdl->pintf_dev);
  749. api = HALMAC_GET_API(mac);
  750. status = api->halmac_reg_write_16(mac, addr, value);
  751. if (status == HALMAC_RET_SUCCESS)
  752. return 0;
  753. return -1;
  754. }
  755. int rtw_halmac_write32(struct intf_hdl *pintfhdl, u32 addr, u32 value)
  756. {
  757. struct halmac_adapter *mac;
  758. struct halmac_api *api;
  759. enum halmac_ret_status status;
  760. /* WARNING: pintf_dev should not be null! */
  761. mac = dvobj_to_halmac(pintfhdl->pintf_dev);
  762. api = HALMAC_GET_API(mac);
  763. status = api->halmac_reg_write_32(mac, addr, value);
  764. if (status == HALMAC_RET_SUCCESS)
  765. return 0;
  766. return -1;
  767. }
  768. static int init_write_rsvd_page_size(struct dvobj_priv *d)
  769. {
  770. struct halmac_adapter *mac;
  771. struct halmac_api *api;
  772. u32 size = 0;
  773. struct halmac_ofld_func_info ofld_info;
  774. enum halmac_ret_status status;
  775. int err = 0;
  776. #ifdef CONFIG_USB_HCI
  777. /* for USB do not exceed MAX_CMDBUF_SZ */
  778. size = 0x1000;
  779. #elif defined(CONFIG_PCIE_HCI)
  780. size = MAX_CMDBUF_SZ - TXDESC_OFFSET;
  781. #elif defined(CONFIG_SDIO_HCI)
  782. size = 0x7000; /* 28KB */
  783. #endif
  784. /* If size==0, use HALMAC default setting and don't call any function */
  785. if (!size)
  786. return 0;
  787. err = rtw_halmac_set_max_dl_fw_size(d, size);
  788. if (err) {
  789. RTW_ERR("%s: Fail to set max download fw size!\n", __FUNCTION__);
  790. return -1;
  791. }
  792. mac = dvobj_to_halmac(d);
  793. api = HALMAC_GET_API(mac);
  794. _rtw_memset(&ofld_info, 0, sizeof(ofld_info));
  795. ofld_info.halmac_malloc_max_sz = 0xFFFFFFFF;
  796. ofld_info.rsvd_pg_drv_buf_max_sz = size;
  797. status = api->halmac_ofld_func_cfg(mac, &ofld_info);
  798. if (status != HALMAC_RET_SUCCESS) {
  799. RTW_ERR("%s: Fail to config offload parameters!\n", __FUNCTION__);
  800. return -1;
  801. }
  802. return 0;
  803. }
  804. static int init_priv(struct halmacpriv *priv)
  805. {
  806. struct halmac_indicator *indicator;
  807. u32 count, size;
  808. if (priv->indicator)
  809. RTW_WARN("%s: HALMAC private data is not CLEAR!\n", __FUNCTION__);
  810. count = HALMAC_FEATURE_ALL + 1;
  811. size = sizeof(*indicator) * count;
  812. indicator = (struct halmac_indicator *)rtw_zmalloc(size);
  813. if (!indicator)
  814. return -1;
  815. priv->indicator = indicator;
  816. return 0;
  817. }
  818. static void deinit_priv(struct halmacpriv *priv)
  819. {
  820. struct halmac_indicator *indicator;
  821. indicator = priv->indicator;
  822. priv->indicator = NULL;
  823. if (indicator) {
  824. u32 count, size;
  825. count = HALMAC_FEATURE_ALL + 1;
  826. #ifdef CONFIG_RTW_DEBUG
  827. {
  828. struct submit_ctx *sctx;
  829. u32 i;
  830. for (i = 0; i < count; i++) {
  831. if (!indicator[i].sctx)
  832. continue;
  833. RTW_WARN("%s: %s id(%d) sctx still exist!!\n",
  834. __FUNCTION__, RTW_HALMAC_FEATURE_NAME[i], i);
  835. sctx = indicator[i].sctx;
  836. indicator[i].sctx = NULL;
  837. rtw_mfree((u8 *)sctx, sizeof(*sctx));
  838. }
  839. }
  840. #endif /* !CONFIG_RTW_DEBUG */
  841. size = sizeof(*indicator) * count;
  842. rtw_mfree((u8 *)indicator, size);
  843. }
  844. }
  845. #ifdef CONFIG_SDIO_HCI
  846. static enum halmac_sdio_spec_ver _sdio_ver_drv2halmac(struct dvobj_priv *d)
  847. {
  848. bool v3;
  849. enum halmac_sdio_spec_ver ver;
  850. v3 = rtw_is_sdio30(dvobj_get_primary_adapter(d));
  851. if (v3)
  852. ver = HALMAC_SDIO_SPEC_VER_3_00;
  853. else
  854. ver = HALMAC_SDIO_SPEC_VER_2_00;
  855. return ver;
  856. }
  857. #endif /* CONFIG_SDIO_HCI */
  858. void rtw_halmac_get_version(char *str, u32 len)
  859. {
  860. enum halmac_ret_status status;
  861. struct halmac_ver ver;
  862. status = halmac_get_version(&ver);
  863. if (status != HALMAC_RET_SUCCESS)
  864. return;
  865. rtw_sprintf(str, len, "V%d_%02d_%02d",
  866. ver.major_ver, ver.prototype_ver, ver.minor_ver);
  867. }
  868. int rtw_halmac_init_adapter(struct dvobj_priv *d, struct halmac_platform_api *pf_api)
  869. {
  870. struct halmac_adapter *halmac;
  871. struct halmac_api *api;
  872. enum halmac_interface intf;
  873. enum halmac_ret_status status;
  874. int err = 0;
  875. #ifdef CONFIG_SDIO_HCI
  876. struct halmac_sdio_hw_info info;
  877. #endif /* CONFIG_SDIO_HCI */
  878. halmac = dvobj_to_halmac(d);
  879. if (halmac) {
  880. RTW_WARN("%s: initialize already completed!\n", __FUNCTION__);
  881. goto error;
  882. }
  883. err = init_priv(&d->hmpriv);
  884. if (err)
  885. goto error;
  886. #ifdef CONFIG_SDIO_HCI
  887. intf = HALMAC_INTERFACE_SDIO;
  888. #elif defined(CONFIG_USB_HCI)
  889. intf = HALMAC_INTERFACE_USB;
  890. #elif defined(CONFIG_PCIE_HCI)
  891. intf = HALMAC_INTERFACE_PCIE;
  892. #else
  893. #warning "INTERFACE(CONFIG_XXX_HCI) not be defined!!"
  894. intf = HALMAC_INTERFACE_UNDEFINE;
  895. #endif
  896. status = halmac_init_adapter(d, pf_api, intf, &halmac, &api);
  897. if (HALMAC_RET_SUCCESS != status) {
  898. RTW_ERR("%s: halmac_init_adapter fail!(status=%d)\n", __FUNCTION__, status);
  899. err = -1;
  900. if (halmac)
  901. goto deinit;
  902. goto free;
  903. }
  904. dvobj_set_halmac(d, halmac);
  905. status = api->halmac_interface_integration_tuning(halmac);
  906. if (status != HALMAC_RET_SUCCESS) {
  907. RTW_ERR("%s: halmac_interface_integration_tuning fail!(status=%d)\n", __FUNCTION__, status);
  908. err = -1;
  909. goto deinit;
  910. }
  911. status = api->halmac_phy_cfg(halmac, HALMAC_INTF_PHY_PLATFORM_ALL);
  912. if (status != HALMAC_RET_SUCCESS) {
  913. RTW_ERR("%s: halmac_phy_cfg fail!(status=%d)\n", __FUNCTION__, status);
  914. err = -1;
  915. goto deinit;
  916. }
  917. init_write_rsvd_page_size(d);
  918. #ifdef CONFIG_SDIO_HCI
  919. _rtw_memset(&info, 0, sizeof(info));
  920. info.spec_ver = _sdio_ver_drv2halmac(d);
  921. /* Convert clock speed unit to MHz from Hz */
  922. info.clock_speed = RTW_DIV_ROUND_UP(rtw_sdio_get_clock(d), 1000000);
  923. info.block_size = rtw_sdio_get_block_size(d);
  924. RTW_DBG("%s: SDIO ver=%u clock=%uMHz blk_size=%u bytes\n",
  925. __FUNCTION__, info.spec_ver+2, info.clock_speed,
  926. info.block_size);
  927. status = api->halmac_sdio_hw_info(halmac, &info);
  928. if (status != HALMAC_RET_SUCCESS) {
  929. RTW_ERR("%s: halmac_sdio_hw_info fail!(status=%d)\n",
  930. __FUNCTION__, status);
  931. err = -1;
  932. goto deinit;
  933. }
  934. #endif /* CONFIG_SDIO_HCI */
  935. return 0;
  936. deinit:
  937. status = halmac_deinit_adapter(halmac);
  938. dvobj_set_halmac(d, NULL);
  939. if (status != HALMAC_RET_SUCCESS)
  940. RTW_ERR("%s: halmac_deinit_adapter fail!(status=%d)\n",
  941. __FUNCTION__, status);
  942. free:
  943. deinit_priv(&d->hmpriv);
  944. error:
  945. return err;
  946. }
  947. int rtw_halmac_deinit_adapter(struct dvobj_priv *d)
  948. {
  949. struct halmac_adapter *halmac;
  950. enum halmac_ret_status status;
  951. int err = 0;
  952. halmac = dvobj_to_halmac(d);
  953. if (halmac) {
  954. status = halmac_deinit_adapter(halmac);
  955. dvobj_set_halmac(d, NULL);
  956. if (status != HALMAC_RET_SUCCESS)
  957. err = -1;
  958. }
  959. deinit_priv(&d->hmpriv);
  960. return err;
  961. }
  962. static inline enum halmac_portid _hw_port_drv2halmac(enum _hw_port hwport)
  963. {
  964. enum halmac_portid port = HALMAC_PORTID_NUM;
  965. switch (hwport) {
  966. case HW_PORT0:
  967. port = HALMAC_PORTID0;
  968. break;
  969. case HW_PORT1:
  970. port = HALMAC_PORTID1;
  971. break;
  972. case HW_PORT2:
  973. port = HALMAC_PORTID2;
  974. break;
  975. case HW_PORT3:
  976. port = HALMAC_PORTID3;
  977. break;
  978. case HW_PORT4:
  979. port = HALMAC_PORTID4;
  980. break;
  981. default:
  982. break;
  983. }
  984. return port;
  985. }
  986. static enum halmac_network_type_select _network_type_drv2halmac(u8 type)
  987. {
  988. enum halmac_network_type_select network = HALMAC_NETWORK_UNDEFINE;
  989. switch (type) {
  990. case _HW_STATE_NOLINK_:
  991. case _HW_STATE_MONITOR_:
  992. network = HALMAC_NETWORK_NO_LINK;
  993. break;
  994. case _HW_STATE_ADHOC_:
  995. network = HALMAC_NETWORK_ADHOC;
  996. break;
  997. case _HW_STATE_STATION_:
  998. network = HALMAC_NETWORK_INFRASTRUCTURE;
  999. break;
  1000. case _HW_STATE_AP_:
  1001. network = HALMAC_NETWORK_AP;
  1002. break;
  1003. }
  1004. return network;
  1005. }
  1006. static u8 _network_type_halmac2drv(enum halmac_network_type_select network)
  1007. {
  1008. u8 type = _HW_STATE_NOLINK_;
  1009. switch (network) {
  1010. case HALMAC_NETWORK_NO_LINK:
  1011. case HALMAC_NETWORK_UNDEFINE:
  1012. type = _HW_STATE_NOLINK_;
  1013. break;
  1014. case HALMAC_NETWORK_ADHOC:
  1015. type = _HW_STATE_ADHOC_;
  1016. break;
  1017. case HALMAC_NETWORK_INFRASTRUCTURE:
  1018. type = _HW_STATE_STATION_;
  1019. break;
  1020. case HALMAC_NETWORK_AP:
  1021. type = _HW_STATE_AP_;
  1022. break;
  1023. }
  1024. return type;
  1025. }
  1026. static void _beacon_ctrl_halmac2drv(struct halmac_bcn_ctrl *ctrl,
  1027. struct rtw_halmac_bcn_ctrl *drv_ctrl)
  1028. {
  1029. drv_ctrl->rx_bssid_fit = ctrl->dis_rx_bssid_fit ? 0 : 1;
  1030. drv_ctrl->txbcn_rpt = ctrl->en_txbcn_rpt ? 1 : 0;
  1031. drv_ctrl->tsf_update = ctrl->dis_tsf_udt ? 0 : 1;
  1032. drv_ctrl->enable_bcn = ctrl->en_bcn ? 1 : 0;
  1033. drv_ctrl->rxbcn_rpt = ctrl->en_rxbcn_rpt ? 1 : 0;
  1034. drv_ctrl->p2p_ctwin = ctrl->en_p2p_ctwin ? 1 : 0;
  1035. drv_ctrl->p2p_bcn_area = ctrl->en_p2p_bcn_area ? 1 : 0;
  1036. }
  1037. static void _beacon_ctrl_drv2halmac(struct rtw_halmac_bcn_ctrl *drv_ctrl,
  1038. struct halmac_bcn_ctrl *ctrl)
  1039. {
  1040. ctrl->dis_rx_bssid_fit = drv_ctrl->rx_bssid_fit ? 0 : 1;
  1041. ctrl->en_txbcn_rpt = drv_ctrl->txbcn_rpt ? 1 : 0;
  1042. ctrl->dis_tsf_udt = drv_ctrl->tsf_update ? 0 : 1;
  1043. ctrl->en_bcn = drv_ctrl->enable_bcn ? 1 : 0;
  1044. ctrl->en_rxbcn_rpt = drv_ctrl->rxbcn_rpt ? 1 : 0;
  1045. ctrl->en_p2p_ctwin = drv_ctrl->p2p_ctwin ? 1 : 0;
  1046. ctrl->en_p2p_bcn_area = drv_ctrl->p2p_bcn_area ? 1 : 0;
  1047. }
  1048. int rtw_halmac_get_hw_value(struct dvobj_priv *d, enum halmac_hw_id hw_id, void *pvalue)
  1049. {
  1050. struct halmac_adapter *mac;
  1051. struct halmac_api *api;
  1052. enum halmac_ret_status status;
  1053. mac = dvobj_to_halmac(d);
  1054. api = HALMAC_GET_API(mac);
  1055. status = api->halmac_get_hw_value(mac, hw_id, pvalue);
  1056. if (HALMAC_RET_SUCCESS != status)
  1057. return -1;
  1058. return 0;
  1059. }
  1060. /**
  1061. * rtw_halmac_get_tx_fifo_size() - TX FIFO size
  1062. * @d: struct dvobj_priv*
  1063. * @size: TX FIFO size, unit is byte.
  1064. *
  1065. * Get TX FIFO size(byte) from HALMAC.
  1066. *
  1067. * Rteurn 0 for OK, otherwise fail.
  1068. */
  1069. int rtw_halmac_get_tx_fifo_size(struct dvobj_priv *d, u32 *size)
  1070. {
  1071. struct halmac_adapter *halmac;
  1072. struct halmac_api *api;
  1073. enum halmac_ret_status status;
  1074. u32 val = 0;
  1075. halmac = dvobj_to_halmac(d);
  1076. api = HALMAC_GET_API(halmac);
  1077. status = api->halmac_get_hw_value(halmac, HALMAC_HW_TXFIFO_SIZE, &val);
  1078. if (status != HALMAC_RET_SUCCESS)
  1079. return -1;
  1080. *size = val;
  1081. return 0;
  1082. }
  1083. /**
  1084. * rtw_halmac_get_rx_fifo_size() - RX FIFO size
  1085. * @d: struct dvobj_priv*
  1086. * @size: RX FIFO size, unit is byte
  1087. *
  1088. * Get RX FIFO size(byte) from HALMAC.
  1089. *
  1090. * Rteurn 0 for OK, otherwise fail.
  1091. */
  1092. int rtw_halmac_get_rx_fifo_size(struct dvobj_priv *d, u32 *size)
  1093. {
  1094. struct halmac_adapter *halmac;
  1095. struct halmac_api *api;
  1096. enum halmac_ret_status status;
  1097. u32 val = 0;
  1098. halmac = dvobj_to_halmac(d);
  1099. api = HALMAC_GET_API(halmac);
  1100. status = api->halmac_get_hw_value(halmac, HALMAC_HW_RXFIFO_SIZE, &val);
  1101. if (status != HALMAC_RET_SUCCESS)
  1102. return -1;
  1103. *size = val;
  1104. return 0;
  1105. }
  1106. /**
  1107. * rtw_halmac_get_rsvd_drv_pg_bndy() - Reserve page boundary of driver
  1108. * @d: struct dvobj_priv*
  1109. * @size: Page size, unit is byte
  1110. *
  1111. * Get reserve page boundary of driver from HALMAC.
  1112. *
  1113. * Rteurn 0 for OK, otherwise fail.
  1114. */
  1115. int rtw_halmac_get_rsvd_drv_pg_bndy(struct dvobj_priv *d, u16 *bndy)
  1116. {
  1117. struct halmac_adapter *halmac;
  1118. struct halmac_api *api;
  1119. enum halmac_ret_status status;
  1120. u16 val = 0;
  1121. halmac = dvobj_to_halmac(d);
  1122. api = HALMAC_GET_API(halmac);
  1123. status = api->halmac_get_hw_value(halmac, HALMAC_HW_RSVD_PG_BNDY, &val);
  1124. if (status != HALMAC_RET_SUCCESS)
  1125. return -1;
  1126. *bndy = val;
  1127. return 0;
  1128. }
  1129. /**
  1130. * rtw_halmac_get_page_size() - Page size
  1131. * @d: struct dvobj_priv*
  1132. * @size: Page size, unit is byte
  1133. *
  1134. * Get TX/RX page size(byte) from HALMAC.
  1135. *
  1136. * Rteurn 0 for OK, otherwise fail.
  1137. */
  1138. int rtw_halmac_get_page_size(struct dvobj_priv *d, u32 *size)
  1139. {
  1140. struct halmac_adapter *halmac;
  1141. struct halmac_api *api;
  1142. enum halmac_ret_status status;
  1143. u32 val = 0;
  1144. halmac = dvobj_to_halmac(d);
  1145. api = HALMAC_GET_API(halmac);
  1146. status = api->halmac_get_hw_value(halmac, HALMAC_HW_PAGE_SIZE, &val);
  1147. if (status != HALMAC_RET_SUCCESS)
  1148. return -1;
  1149. *size = val;
  1150. return 0;
  1151. }
  1152. /**
  1153. * rtw_halmac_get_tx_agg_align_size() - TX aggregation align size
  1154. * @d: struct dvobj_priv*
  1155. * @size: TX aggregation align size, unit is byte
  1156. *
  1157. * Get TX aggregation align size(byte) from HALMAC.
  1158. *
  1159. * Rteurn 0 for OK, otherwise fail.
  1160. */
  1161. int rtw_halmac_get_tx_agg_align_size(struct dvobj_priv *d, u16 *size)
  1162. {
  1163. struct halmac_adapter *halmac;
  1164. struct halmac_api *api;
  1165. enum halmac_ret_status status;
  1166. u16 val = 0;
  1167. halmac = dvobj_to_halmac(d);
  1168. api = HALMAC_GET_API(halmac);
  1169. status = api->halmac_get_hw_value(halmac, HALMAC_HW_TX_AGG_ALIGN_SIZE, &val);
  1170. if (status != HALMAC_RET_SUCCESS)
  1171. return -1;
  1172. *size = val;
  1173. return 0;
  1174. }
  1175. /**
  1176. * rtw_halmac_get_rx_agg_align_size() - RX aggregation align size
  1177. * @d: struct dvobj_priv*
  1178. * @size: RX aggregation align size, unit is byte
  1179. *
  1180. * Get RX aggregation align size(byte) from HALMAC.
  1181. *
  1182. * Rteurn 0 for OK, otherwise fail.
  1183. */
  1184. int rtw_halmac_get_rx_agg_align_size(struct dvobj_priv *d, u8 *size)
  1185. {
  1186. struct halmac_adapter *halmac;
  1187. struct halmac_api *api;
  1188. enum halmac_ret_status status;
  1189. u8 val = 0;
  1190. halmac = dvobj_to_halmac(d);
  1191. api = HALMAC_GET_API(halmac);
  1192. status = api->halmac_get_hw_value(halmac, HALMAC_HW_RX_AGG_ALIGN_SIZE, &val);
  1193. if (status != HALMAC_RET_SUCCESS)
  1194. return -1;
  1195. *size = val;
  1196. return 0;
  1197. }
  1198. /*
  1199. * Description:
  1200. * Get RX driver info size. RX driver info is a small memory space between
  1201. * scriptor and RX payload.
  1202. *
  1203. * +-------------------------+
  1204. * | RX descriptor |
  1205. * | usually 24 bytes |
  1206. * +-------------------------+
  1207. * | RX driver info |
  1208. * | depends on driver cfg |
  1209. * +-------------------------+
  1210. * | RX paylad |
  1211. * | |
  1212. * +-------------------------+
  1213. *
  1214. * Parameter:
  1215. * d pointer to struct dvobj_priv of driver
  1216. * sz rx driver info size in bytes.
  1217. *
  1218. * Rteurn:
  1219. * 0 Success
  1220. * other Fail
  1221. */
  1222. int rtw_halmac_get_rx_drv_info_sz(struct dvobj_priv *d, u8 *sz)
  1223. {
  1224. enum halmac_ret_status status;
  1225. struct halmac_adapter *halmac = dvobj_to_halmac(d);
  1226. struct halmac_api *api = HALMAC_GET_API(halmac);
  1227. u8 dw = 0;
  1228. status = api->halmac_get_hw_value(halmac, HALMAC_HW_DRV_INFO_SIZE, &dw);
  1229. if (status != HALMAC_RET_SUCCESS)
  1230. return -1;
  1231. *sz = dw * 8;
  1232. return 0;
  1233. }
  1234. /**
  1235. * rtw_halmac_get_tx_desc_size() - TX descriptor size
  1236. * @d: struct dvobj_priv*
  1237. * @size: TX descriptor size, unit is byte.
  1238. *
  1239. * Get TX descriptor size(byte) from HALMAC.
  1240. *
  1241. * Rteurn 0 for OK, otherwise fail.
  1242. */
  1243. int rtw_halmac_get_tx_desc_size(struct dvobj_priv *d, u32 *size)
  1244. {
  1245. struct halmac_adapter *halmac;
  1246. struct halmac_api *api;
  1247. enum halmac_ret_status status;
  1248. u32 val = 0;
  1249. halmac = dvobj_to_halmac(d);
  1250. api = HALMAC_GET_API(halmac);
  1251. status = api->halmac_get_hw_value(halmac, HALMAC_HW_TX_DESC_SIZE, &val);
  1252. if (status != HALMAC_RET_SUCCESS)
  1253. return -1;
  1254. *size = val;
  1255. return 0;
  1256. }
  1257. /**
  1258. * rtw_halmac_get_rx_desc_size() - RX descriptor size
  1259. * @d: struct dvobj_priv*
  1260. * @size: RX descriptor size, unit is byte.
  1261. *
  1262. * Get RX descriptor size(byte) from HALMAC.
  1263. *
  1264. * Rteurn 0 for OK, otherwise fail.
  1265. */
  1266. int rtw_halmac_get_rx_desc_size(struct dvobj_priv *d, u32 *size)
  1267. {
  1268. struct halmac_adapter *halmac;
  1269. struct halmac_api *api;
  1270. enum halmac_ret_status status;
  1271. u32 val = 0;
  1272. halmac = dvobj_to_halmac(d);
  1273. api = HALMAC_GET_API(halmac);
  1274. status = api->halmac_get_hw_value(halmac, HALMAC_HW_RX_DESC_SIZE, &val);
  1275. if (status != HALMAC_RET_SUCCESS)
  1276. return -1;
  1277. *size = val;
  1278. return 0;
  1279. }
  1280. /**
  1281. * rtw_halmac_get_fw_max_size() - Firmware MAX size
  1282. * @d: struct dvobj_priv*
  1283. * @size: MAX Firmware size, unit is byte.
  1284. *
  1285. * Get Firmware MAX size(byte) from HALMAC.
  1286. *
  1287. * Rteurn 0 for OK, otherwise fail.
  1288. */
  1289. static int rtw_halmac_get_fw_max_size(struct dvobj_priv *d, u32 *size)
  1290. {
  1291. struct halmac_adapter *halmac;
  1292. struct halmac_api *api;
  1293. enum halmac_ret_status status;
  1294. u32 val = 0;
  1295. halmac = dvobj_to_halmac(d);
  1296. api = HALMAC_GET_API(halmac);
  1297. status = api->halmac_get_hw_value(halmac, HALMAC_HW_FW_MAX_SIZE, &val);
  1298. if (status != HALMAC_RET_SUCCESS)
  1299. return -1;
  1300. *size = val;
  1301. return 0;
  1302. }
  1303. /**
  1304. * rtw_halmac_get_ori_h2c_size() - Original H2C MAX size
  1305. * @d: struct dvobj_priv*
  1306. * @size: H2C MAX size, unit is byte.
  1307. *
  1308. * Get original H2C MAX size(byte) from HALMAC.
  1309. *
  1310. * Rteurn 0 for OK, otherwise fail.
  1311. */
  1312. int rtw_halmac_get_ori_h2c_size(struct dvobj_priv *d, u32 *size)
  1313. {
  1314. struct halmac_adapter *halmac;
  1315. struct halmac_api *api;
  1316. enum halmac_ret_status status;
  1317. u32 val = 0;
  1318. halmac = dvobj_to_halmac(d);
  1319. api = HALMAC_GET_API(halmac);
  1320. status = api->halmac_get_hw_value(halmac, HALMAC_HW_ORI_H2C_SIZE, &val);
  1321. if (status != HALMAC_RET_SUCCESS)
  1322. return -1;
  1323. *size = val;
  1324. return 0;
  1325. }
  1326. int rtw_halmac_get_oqt_size(struct dvobj_priv *d, u8 *size)
  1327. {
  1328. enum halmac_ret_status status;
  1329. struct halmac_adapter *halmac;
  1330. struct halmac_api *api;
  1331. u8 val;
  1332. if (!size)
  1333. return -1;
  1334. halmac = dvobj_to_halmac(d);
  1335. api = HALMAC_GET_API(halmac);
  1336. status = api->halmac_get_hw_value(halmac, HALMAC_HW_AC_OQT_SIZE, &val);
  1337. if (status != HALMAC_RET_SUCCESS)
  1338. return -1;
  1339. *size = val;
  1340. return 0;
  1341. }
  1342. int rtw_halmac_get_ac_queue_number(struct dvobj_priv *d, u8 *num)
  1343. {
  1344. enum halmac_ret_status status;
  1345. struct halmac_adapter *halmac;
  1346. struct halmac_api *api;
  1347. u8 val;
  1348. if (!num)
  1349. return -1;
  1350. halmac = dvobj_to_halmac(d);
  1351. api = HALMAC_GET_API(halmac);
  1352. status = api->halmac_get_hw_value(halmac, HALMAC_HW_AC_QUEUE_NUM, &val);
  1353. if (status != HALMAC_RET_SUCCESS)
  1354. return -1;
  1355. *num = val;
  1356. return 0;
  1357. }
  1358. /**
  1359. * rtw_halmac_get_mac_address() - Get MAC address of specific port
  1360. * @d: struct dvobj_priv*
  1361. * @hwport: port
  1362. * @addr: buffer for storing MAC address
  1363. *
  1364. * Get MAC address of specific port from HALMAC.
  1365. *
  1366. * Rteurn 0 for OK, otherwise fail.
  1367. */
  1368. int rtw_halmac_get_mac_address(struct dvobj_priv *d, enum _hw_port hwport, u8 *addr)
  1369. {
  1370. struct halmac_adapter *halmac;
  1371. struct halmac_api *api;
  1372. enum halmac_portid port;
  1373. union halmac_wlan_addr hwa;
  1374. enum halmac_ret_status status;
  1375. int err = -1;
  1376. if (!addr)
  1377. goto out;
  1378. halmac = dvobj_to_halmac(d);
  1379. api = HALMAC_GET_API(halmac);
  1380. port = _hw_port_drv2halmac(hwport);
  1381. _rtw_memset(&hwa, 0, sizeof(hwa));
  1382. status = api->halmac_get_mac_addr(halmac, port, &hwa);
  1383. if (status != HALMAC_RET_SUCCESS)
  1384. goto out;
  1385. _rtw_memcpy(addr, hwa.addr, 6);
  1386. err = 0;
  1387. out:
  1388. return err;
  1389. }
  1390. /**
  1391. * rtw_halmac_get_network_type() - Get network type of specific port
  1392. * @d: struct dvobj_priv*
  1393. * @hwport: port
  1394. * @type: buffer to put network type (_HW_STATE_*)
  1395. *
  1396. * Get network type of specific port from HALMAC.
  1397. *
  1398. * Rteurn 0 for OK, otherwise fail.
  1399. */
  1400. int rtw_halmac_get_network_type(struct dvobj_priv *d, enum _hw_port hwport, u8 *type)
  1401. {
  1402. #if 0
  1403. struct halmac_adapter *halmac;
  1404. struct halmac_api *api;
  1405. enum halmac_portid port;
  1406. enum halmac_network_type_select network;
  1407. enum halmac_ret_status status;
  1408. int err = -1;
  1409. halmac = dvobj_to_halmac(d);
  1410. api = HALMAC_GET_API(halmac);
  1411. port = _hw_port_drv2halmac(hwport);
  1412. network = HALMAC_NETWORK_UNDEFINE;
  1413. status = api->halmac_get_net_type(halmac, port, &network);
  1414. if (status != HALMAC_RET_SUCCESS)
  1415. goto out;
  1416. *type = _network_type_halmac2drv(network);
  1417. err = 0;
  1418. out:
  1419. return err;
  1420. #else
  1421. struct _ADAPTER *a;
  1422. enum halmac_portid port;
  1423. enum halmac_network_type_select network;
  1424. u32 val;
  1425. int err = -1;
  1426. a = dvobj_get_primary_adapter(d);
  1427. port = _hw_port_drv2halmac(hwport);
  1428. network = HALMAC_NETWORK_UNDEFINE;
  1429. switch (port) {
  1430. case HALMAC_PORTID0:
  1431. val = rtw_read32(a, REG_CR);
  1432. network = BIT_GET_NETYPE0(val);
  1433. break;
  1434. case HALMAC_PORTID1:
  1435. val = rtw_read32(a, REG_CR);
  1436. network = BIT_GET_NETYPE1(val);
  1437. break;
  1438. case HALMAC_PORTID2:
  1439. val = rtw_read32(a, REG_CR_EXT);
  1440. network = BIT_GET_NETYPE2(val);
  1441. break;
  1442. case HALMAC_PORTID3:
  1443. val = rtw_read32(a, REG_CR_EXT);
  1444. network = BIT_GET_NETYPE3(val);
  1445. break;
  1446. case HALMAC_PORTID4:
  1447. val = rtw_read32(a, REG_CR_EXT);
  1448. network = BIT_GET_NETYPE4(val);
  1449. break;
  1450. default:
  1451. goto out;
  1452. }
  1453. *type = _network_type_halmac2drv(network);
  1454. err = 0;
  1455. out:
  1456. return err;
  1457. #endif
  1458. }
  1459. /**
  1460. * rtw_halmac_get_bcn_ctrl() - Get beacon control setting of specific port
  1461. * @d: struct dvobj_priv*
  1462. * @hwport: port
  1463. * @bcn_ctrl: setting of beacon control
  1464. *
  1465. * Get beacon control setting of specific port from HALMAC.
  1466. *
  1467. * Rteurn 0 for OK, otherwise fail.
  1468. */
  1469. int rtw_halmac_get_bcn_ctrl(struct dvobj_priv *d, enum _hw_port hwport,
  1470. struct rtw_halmac_bcn_ctrl *bcn_ctrl)
  1471. {
  1472. struct halmac_adapter *halmac;
  1473. struct halmac_api *api;
  1474. enum halmac_portid port;
  1475. struct halmac_bcn_ctrl ctrl;
  1476. enum halmac_ret_status status;
  1477. int err = -1;
  1478. halmac = dvobj_to_halmac(d);
  1479. api = HALMAC_GET_API(halmac);
  1480. port = _hw_port_drv2halmac(hwport);
  1481. _rtw_memset(&ctrl, 0, sizeof(ctrl));
  1482. status = api->halmac_rw_bcn_ctrl(halmac, port, 0, &ctrl);
  1483. if (status != HALMAC_RET_SUCCESS)
  1484. goto out;
  1485. _beacon_ctrl_halmac2drv(&ctrl, bcn_ctrl);
  1486. err = 0;
  1487. out:
  1488. return err;
  1489. }
  1490. /*
  1491. * Note:
  1492. * When this function return, the register REG_RCR may be changed.
  1493. */
  1494. int rtw_halmac_config_rx_info(struct dvobj_priv *d, enum halmac_drv_info info)
  1495. {
  1496. struct halmac_adapter *halmac;
  1497. struct halmac_api *api;
  1498. enum halmac_ret_status status;
  1499. int err = -1;
  1500. halmac = dvobj_to_halmac(d);
  1501. api = HALMAC_GET_API(halmac);
  1502. status = api->halmac_cfg_drv_info(halmac, info);
  1503. if (status != HALMAC_RET_SUCCESS)
  1504. goto out;
  1505. err = 0;
  1506. out:
  1507. return err;
  1508. }
  1509. /**
  1510. * rtw_halmac_set_max_dl_fw_size() - Set the MAX download firmware size
  1511. * @d: struct dvobj_priv*
  1512. * @size: the max download firmware size in one I/O
  1513. *
  1514. * Set the max download firmware size in one I/O.
  1515. * Please also consider the max size of the callback function "SEND_RSVD_PAGE"
  1516. * could accept, because download firmware would call "SEND_RSVD_PAGE" to send
  1517. * firmware to IC.
  1518. *
  1519. * If the value of "size" is not even, it would be rounded down to nearest
  1520. * even, and 0 and 1 are both invalid value.
  1521. *
  1522. * Return 0 for setting OK, otherwise fail.
  1523. */
  1524. int rtw_halmac_set_max_dl_fw_size(struct dvobj_priv *d, u32 size)
  1525. {
  1526. struct halmac_adapter *mac;
  1527. struct halmac_api *api;
  1528. enum halmac_ret_status status;
  1529. if (!size || (size == 1))
  1530. return -1;
  1531. mac = dvobj_to_halmac(d);
  1532. if (!mac) {
  1533. RTW_ERR("%s: HALMAC is not ready!!\n", __FUNCTION__);
  1534. return -1;
  1535. }
  1536. api = HALMAC_GET_API(mac);
  1537. size &= ~1; /* round down to even */
  1538. status = api->halmac_cfg_max_dl_size(mac, size);
  1539. if (status != HALMAC_RET_SUCCESS) {
  1540. RTW_WARN("%s: Fail to cfg_max_dl_size(%d), err=%d!!\n",
  1541. __FUNCTION__, size, status);
  1542. return -1;
  1543. }
  1544. return 0;
  1545. }
  1546. /**
  1547. * rtw_halmac_set_mac_address() - Set mac address of specific port
  1548. * @d: struct dvobj_priv*
  1549. * @hwport: port
  1550. * @addr: mac address
  1551. *
  1552. * Set self mac address of specific port to HALMAC.
  1553. *
  1554. * Rteurn 0 for OK, otherwise fail.
  1555. */
  1556. int rtw_halmac_set_mac_address(struct dvobj_priv *d, enum _hw_port hwport, u8 *addr)
  1557. {
  1558. struct halmac_adapter *halmac;
  1559. struct halmac_api *api;
  1560. enum halmac_portid port;
  1561. union halmac_wlan_addr hwa;
  1562. enum halmac_ret_status status;
  1563. int err = -1;
  1564. halmac = dvobj_to_halmac(d);
  1565. api = HALMAC_GET_API(halmac);
  1566. port = _hw_port_drv2halmac(hwport);
  1567. _rtw_memset(&hwa, 0, sizeof(hwa));
  1568. _rtw_memcpy(hwa.addr, addr, 6);
  1569. status = api->halmac_cfg_mac_addr(halmac, port, &hwa);
  1570. if (status != HALMAC_RET_SUCCESS)
  1571. goto out;
  1572. err = 0;
  1573. out:
  1574. return err;
  1575. }
  1576. /**
  1577. * rtw_halmac_set_bssid() - Set BSSID of specific port
  1578. * @d: struct dvobj_priv*
  1579. * @hwport: port
  1580. * @addr: BSSID, mac address of AP
  1581. *
  1582. * Set BSSID of specific port to HALMAC.
  1583. *
  1584. * Rteurn 0 for OK, otherwise fail.
  1585. */
  1586. int rtw_halmac_set_bssid(struct dvobj_priv *d, enum _hw_port hwport, u8 *addr)
  1587. {
  1588. struct halmac_adapter *halmac;
  1589. struct halmac_api *api;
  1590. enum halmac_portid port;
  1591. union halmac_wlan_addr hwa;
  1592. enum halmac_ret_status status;
  1593. int err = -1;
  1594. halmac = dvobj_to_halmac(d);
  1595. api = HALMAC_GET_API(halmac);
  1596. port = _hw_port_drv2halmac(hwport);
  1597. _rtw_memset(&hwa, 0, sizeof(hwa));
  1598. _rtw_memcpy(hwa.addr, addr, 6);
  1599. status = api->halmac_cfg_bssid(halmac, port, &hwa);
  1600. if (status != HALMAC_RET_SUCCESS)
  1601. goto out;
  1602. err = 0;
  1603. out:
  1604. return err;
  1605. }
  1606. /**
  1607. * rtw_halmac_set_tx_address() - Set transmitter address of specific port
  1608. * @d: struct dvobj_priv*
  1609. * @hwport: port
  1610. * @addr: transmitter address
  1611. *
  1612. * Set transmitter address of specific port to HALMAC.
  1613. *
  1614. * Rteurn 0 for OK, otherwise fail.
  1615. */
  1616. int rtw_halmac_set_tx_address(struct dvobj_priv *d, enum _hw_port hwport, u8 *addr)
  1617. {
  1618. struct halmac_adapter *halmac;
  1619. struct halmac_api *api;
  1620. enum halmac_portid port;
  1621. union halmac_wlan_addr hwa;
  1622. enum halmac_ret_status status;
  1623. int err = -1;
  1624. halmac = dvobj_to_halmac(d);
  1625. api = HALMAC_GET_API(halmac);
  1626. port = _hw_port_drv2halmac(hwport);
  1627. _rtw_memset(&hwa, 0, sizeof(hwa));
  1628. _rtw_memcpy(hwa.addr, addr, 6);
  1629. status = api->halmac_cfg_transmitter_addr(halmac, port, &hwa);
  1630. if (status != HALMAC_RET_SUCCESS)
  1631. goto out;
  1632. err = 0;
  1633. out:
  1634. return err;
  1635. }
  1636. /**
  1637. * rtw_halmac_set_network_type() - Set network type of specific port
  1638. * @d: struct dvobj_priv*
  1639. * @hwport: port
  1640. * @type: network type (_HW_STATE_*)
  1641. *
  1642. * Set network type of specific port to HALMAC.
  1643. *
  1644. * Rteurn 0 for OK, otherwise fail.
  1645. */
  1646. int rtw_halmac_set_network_type(struct dvobj_priv *d, enum _hw_port hwport, u8 type)
  1647. {
  1648. struct halmac_adapter *halmac;
  1649. struct halmac_api *api;
  1650. enum halmac_portid port;
  1651. enum halmac_network_type_select network;
  1652. enum halmac_ret_status status;
  1653. int err = -1;
  1654. halmac = dvobj_to_halmac(d);
  1655. api = HALMAC_GET_API(halmac);
  1656. port = _hw_port_drv2halmac(hwport);
  1657. network = _network_type_drv2halmac(type);
  1658. status = api->halmac_cfg_net_type(halmac, port, network);
  1659. if (status != HALMAC_RET_SUCCESS)
  1660. goto out;
  1661. err = 0;
  1662. out:
  1663. return err;
  1664. }
  1665. /**
  1666. * rtw_halmac_reset_tsf() - Reset TSF timer of specific port
  1667. * @d: struct dvobj_priv*
  1668. * @hwport: port
  1669. *
  1670. * Notice HALMAC to reset timing synchronization function(TSF) timer of
  1671. * specific port.
  1672. *
  1673. * Rteurn 0 for OK, otherwise fail.
  1674. */
  1675. int rtw_halmac_reset_tsf(struct dvobj_priv *d, enum _hw_port hwport)
  1676. {
  1677. struct halmac_adapter *halmac;
  1678. struct halmac_api *api;
  1679. enum halmac_portid port;
  1680. enum halmac_ret_status status;
  1681. int err = -1;
  1682. halmac = dvobj_to_halmac(d);
  1683. api = HALMAC_GET_API(halmac);
  1684. port = _hw_port_drv2halmac(hwport);
  1685. status = api->halmac_cfg_tsf_rst(halmac, port);
  1686. if (status != HALMAC_RET_SUCCESS)
  1687. goto out;
  1688. err = 0;
  1689. out:
  1690. return err;
  1691. }
  1692. /**
  1693. * rtw_halmac_set_bcn_interval() - Set beacon interval of each port
  1694. * @d: struct dvobj_priv*
  1695. * @hwport: port
  1696. * @space: beacon interval, unit is ms
  1697. *
  1698. * Set beacon interval of specific port to HALMAC.
  1699. *
  1700. * Rteurn 0 for OK, otherwise fail.
  1701. */
  1702. int rtw_halmac_set_bcn_interval(struct dvobj_priv *d, enum _hw_port hwport,
  1703. u32 interval)
  1704. {
  1705. struct halmac_adapter *halmac;
  1706. struct halmac_api *api;
  1707. enum halmac_portid port;
  1708. enum halmac_ret_status status;
  1709. int err = -1;
  1710. halmac = dvobj_to_halmac(d);
  1711. api = HALMAC_GET_API(halmac);
  1712. port = _hw_port_drv2halmac(hwport);
  1713. status = api->halmac_cfg_bcn_space(halmac, port, interval);
  1714. if (status != HALMAC_RET_SUCCESS)
  1715. goto out;
  1716. err = 0;
  1717. out:
  1718. return err;
  1719. }
  1720. /**
  1721. * rtw_halmac_set_bcn_ctrl() - Set beacon control setting of each port
  1722. * @d: struct dvobj_priv*
  1723. * @hwport: port
  1724. * @bcn_ctrl: setting of beacon control
  1725. *
  1726. * Set beacon control setting of specific port to HALMAC.
  1727. *
  1728. * Rteurn 0 for OK, otherwise fail.
  1729. */
  1730. int rtw_halmac_set_bcn_ctrl(struct dvobj_priv *d, enum _hw_port hwport,
  1731. struct rtw_halmac_bcn_ctrl *bcn_ctrl)
  1732. {
  1733. struct halmac_adapter *halmac;
  1734. struct halmac_api *api;
  1735. enum halmac_portid port;
  1736. struct halmac_bcn_ctrl ctrl;
  1737. enum halmac_ret_status status;
  1738. int err = -1;
  1739. halmac = dvobj_to_halmac(d);
  1740. api = HALMAC_GET_API(halmac);
  1741. port = _hw_port_drv2halmac(hwport);
  1742. _rtw_memset(&ctrl, 0, sizeof(ctrl));
  1743. _beacon_ctrl_drv2halmac(bcn_ctrl, &ctrl);
  1744. status = api->halmac_rw_bcn_ctrl(halmac, port, 1, &ctrl);
  1745. if (status != HALMAC_RET_SUCCESS)
  1746. goto out;
  1747. err = 0;
  1748. out:
  1749. return err;
  1750. }
  1751. /**
  1752. * rtw_halmac_set_aid() - Set association identifier(AID) of specific port
  1753. * @d: struct dvobj_priv*
  1754. * @hwport: port
  1755. * @aid: Association identifier
  1756. *
  1757. * Set association identifier(AID) of specific port to HALMAC.
  1758. *
  1759. * Rteurn 0 for OK, otherwise fail.
  1760. */
  1761. int rtw_halmac_set_aid(struct dvobj_priv *d, enum _hw_port hwport, u16 aid)
  1762. {
  1763. struct halmac_adapter *halmac;
  1764. struct halmac_api *api;
  1765. enum halmac_portid port;
  1766. enum halmac_ret_status status;
  1767. int err = -1;
  1768. halmac = dvobj_to_halmac(d);
  1769. api = HALMAC_GET_API(halmac);
  1770. port = _hw_port_drv2halmac(hwport);
  1771. #if 0
  1772. status = api->halmac_cfg_aid(halmac, port, aid);
  1773. if (status != HALMAC_RET_SUCCESS)
  1774. goto out;
  1775. #else
  1776. {
  1777. struct _ADAPTER *a;
  1778. u32 addr;
  1779. u16 val;
  1780. a = dvobj_get_primary_adapter(d);
  1781. switch (port) {
  1782. case 0:
  1783. addr = REG_BCN_PSR_RPT;
  1784. val = rtw_read16(a, addr);
  1785. val = BIT_SET_PS_AID_0(val, aid);
  1786. rtw_write16(a, addr, val);
  1787. break;
  1788. case 1:
  1789. addr = REG_BCN_PSR_RPT1;
  1790. val = rtw_read16(a, addr);
  1791. val = BIT_SET_PS_AID_1(val, aid);
  1792. rtw_write16(a, addr, val);
  1793. break;
  1794. case 2:
  1795. addr = REG_BCN_PSR_RPT2;
  1796. val = rtw_read16(a, addr);
  1797. val = BIT_SET_PS_AID_2(val, aid);
  1798. rtw_write16(a, addr, val);
  1799. break;
  1800. case 3:
  1801. addr = REG_BCN_PSR_RPT3;
  1802. val = rtw_read16(a, addr);
  1803. val = BIT_SET_PS_AID_3(val, aid);
  1804. rtw_write16(a, addr, val);
  1805. break;
  1806. case 4:
  1807. addr = REG_BCN_PSR_RPT4;
  1808. val = rtw_read16(a, addr);
  1809. val = BIT_SET_PS_AID_4(val, aid);
  1810. rtw_write16(a, addr, val);
  1811. break;
  1812. default:
  1813. goto out;
  1814. }
  1815. }
  1816. #endif
  1817. err = 0;
  1818. out:
  1819. return err;
  1820. }
  1821. int rtw_halmac_set_bandwidth(struct dvobj_priv *d, u8 channel, u8 pri_ch_idx, u8 bw)
  1822. {
  1823. struct halmac_adapter *mac;
  1824. struct halmac_api *api;
  1825. enum halmac_ret_status status;
  1826. mac = dvobj_to_halmac(d);
  1827. api = HALMAC_GET_API(mac);
  1828. status = api->halmac_cfg_ch_bw(mac, channel, pri_ch_idx, bw);
  1829. if (HALMAC_RET_SUCCESS != status)
  1830. return -1;
  1831. return 0;
  1832. }
  1833. /**
  1834. * rtw_halmac_set_edca() - config edca parameter
  1835. * @d: struct dvobj_priv*
  1836. * @queue: XMIT_[VO/VI/BE/BK]_QUEUE
  1837. * @aifs: Arbitration inter-frame space(AIFS)
  1838. * @cw: Contention window(CW)
  1839. * @txop: MAX Transmit Opportunity(TXOP)
  1840. *
  1841. * Return: 0 if process OK, otherwise -1.
  1842. */
  1843. int rtw_halmac_set_edca(struct dvobj_priv *d, u8 queue, u8 aifs, u8 cw, u16 txop)
  1844. {
  1845. struct halmac_adapter *mac;
  1846. struct halmac_api *api;
  1847. enum halmac_acq_id ac;
  1848. struct halmac_edca_para edca;
  1849. enum halmac_ret_status status;
  1850. mac = dvobj_to_halmac(d);
  1851. api = HALMAC_GET_API(mac);
  1852. switch (queue) {
  1853. case XMIT_VO_QUEUE:
  1854. ac = HALMAC_ACQ_ID_VO;
  1855. break;
  1856. case XMIT_VI_QUEUE:
  1857. ac = HALMAC_ACQ_ID_VI;
  1858. break;
  1859. case XMIT_BE_QUEUE:
  1860. ac = HALMAC_ACQ_ID_BE;
  1861. break;
  1862. case XMIT_BK_QUEUE:
  1863. ac = HALMAC_ACQ_ID_BK;
  1864. break;
  1865. default:
  1866. return -1;
  1867. }
  1868. edca.aifs = aifs;
  1869. edca.cw = cw;
  1870. edca.txop_limit = txop;
  1871. status = api->halmac_cfg_edca_para(mac, ac, &edca);
  1872. if (status != HALMAC_RET_SUCCESS)
  1873. return -1;
  1874. return 0;
  1875. }
  1876. /*
  1877. * Description:
  1878. * Power on device hardware.
  1879. * [Notice!] If device's power state is on before,
  1880. * it would be power off first and turn on power again.
  1881. *
  1882. * Return:
  1883. * 0 power on success
  1884. * -1 power on fail
  1885. * -2 power state unchange
  1886. */
  1887. int rtw_halmac_poweron(struct dvobj_priv *d)
  1888. {
  1889. struct halmac_adapter *halmac;
  1890. struct halmac_api *api;
  1891. enum halmac_ret_status status;
  1892. int err = -1;
  1893. halmac = dvobj_to_halmac(d);
  1894. if (!halmac)
  1895. goto out;
  1896. api = HALMAC_GET_API(halmac);
  1897. status = api->halmac_pre_init_system_cfg(halmac);
  1898. if (status != HALMAC_RET_SUCCESS)
  1899. goto out;
  1900. #ifdef CONFIG_SDIO_HCI
  1901. status = api->halmac_sdio_cmd53_4byte(halmac, HALMAC_SDIO_CMD53_4BYTE_MODE_RW);
  1902. if (status != HALMAC_RET_SUCCESS)
  1903. goto out;
  1904. #endif /* CONFIG_SDIO_HCI */
  1905. status = api->halmac_mac_power_switch(halmac, HALMAC_MAC_POWER_ON);
  1906. if (HALMAC_RET_PWR_UNCHANGE == status) {
  1907. /*
  1908. * Work around for warm reboot but device not power off,
  1909. * but it would also fall into this case when auto power on is enabled.
  1910. */
  1911. api->halmac_mac_power_switch(halmac, HALMAC_MAC_POWER_OFF);
  1912. status = api->halmac_mac_power_switch(halmac, HALMAC_MAC_POWER_ON);
  1913. RTW_WARN("%s: Power state abnormal, try to recover...%s\n",
  1914. __FUNCTION__, (HALMAC_RET_SUCCESS == status)?"OK":"FAIL!");
  1915. }
  1916. if (HALMAC_RET_SUCCESS != status) {
  1917. if (HALMAC_RET_PWR_UNCHANGE == status)
  1918. err = -2;
  1919. goto out;
  1920. }
  1921. status = api->halmac_init_system_cfg(halmac);
  1922. if (status != HALMAC_RET_SUCCESS)
  1923. goto out;
  1924. err = 0;
  1925. out:
  1926. return err;
  1927. }
  1928. /*
  1929. * Description:
  1930. * Power off device hardware.
  1931. *
  1932. * Return:
  1933. * 0 Power off success
  1934. * -1 Power off fail
  1935. */
  1936. int rtw_halmac_poweroff(struct dvobj_priv *d)
  1937. {
  1938. struct halmac_adapter *halmac;
  1939. struct halmac_api *api;
  1940. enum halmac_ret_status status;
  1941. int err = -1;
  1942. halmac = dvobj_to_halmac(d);
  1943. if (!halmac)
  1944. goto out;
  1945. api = HALMAC_GET_API(halmac);
  1946. status = api->halmac_mac_power_switch(halmac, HALMAC_MAC_POWER_OFF);
  1947. if ((HALMAC_RET_SUCCESS != status)
  1948. && (HALMAC_RET_PWR_UNCHANGE != status))
  1949. goto out;
  1950. err = 0;
  1951. out:
  1952. return err;
  1953. }
  1954. #ifdef CONFIG_SUPPORT_TRX_SHARED
  1955. static inline enum halmac_rx_fifo_expanding_mode _trx_share_mode_drv2halmac(u8 trx_share_mode)
  1956. {
  1957. if (0 == trx_share_mode)
  1958. return HALMAC_RX_FIFO_EXPANDING_MODE_DISABLE;
  1959. else if (1 == trx_share_mode)
  1960. return HALMAC_RX_FIFO_EXPANDING_MODE_1_BLOCK;
  1961. else if (2 == trx_share_mode)
  1962. return HALMAC_RX_FIFO_EXPANDING_MODE_2_BLOCK;
  1963. else if (3 == trx_share_mode)
  1964. return HALMAC_RX_FIFO_EXPANDING_MODE_3_BLOCK;
  1965. else
  1966. return HALMAC_RX_FIFO_EXPANDING_MODE_DISABLE;
  1967. }
  1968. static enum halmac_rx_fifo_expanding_mode _rtw_get_trx_share_mode(struct _ADAPTER *adapter)
  1969. {
  1970. struct registry_priv *registry_par = &adapter->registrypriv;
  1971. return _trx_share_mode_drv2halmac(registry_par->trx_share_mode);
  1972. }
  1973. void dump_trx_share_mode(void *sel, struct _ADAPTER *adapter)
  1974. {
  1975. struct registry_priv *registry_par = &adapter->registrypriv;
  1976. u8 mode = _trx_share_mode_drv2halmac(registry_par->trx_share_mode);
  1977. if (HALMAC_RX_FIFO_EXPANDING_MODE_1_BLOCK == mode)
  1978. RTW_PRINT_SEL(sel, "TRx share mode : %s\n", "RX_FIFO_EXPANDING_MODE_1");
  1979. else if (HALMAC_RX_FIFO_EXPANDING_MODE_2_BLOCK == mode)
  1980. RTW_PRINT_SEL(sel, "TRx share mode : %s\n", "RX_FIFO_EXPANDING_MODE_2");
  1981. else if (HALMAC_RX_FIFO_EXPANDING_MODE_3_BLOCK == mode)
  1982. RTW_PRINT_SEL(sel, "TRx share mode : %s\n", "RX_FIFO_EXPANDING_MODE_3");
  1983. else
  1984. RTW_PRINT_SEL(sel, "TRx share mode : %s\n", "DISABLE");
  1985. }
  1986. #endif
  1987. static enum halmac_drv_rsvd_pg_num _rsvd_page_num_drv2halmac(u8 num)
  1988. {
  1989. if (num <= 8)
  1990. return HALMAC_RSVD_PG_NUM8;
  1991. if (num <= 16)
  1992. return HALMAC_RSVD_PG_NUM16;
  1993. if (num <= 24)
  1994. return HALMAC_RSVD_PG_NUM24;
  1995. if (num <= 32)
  1996. return HALMAC_RSVD_PG_NUM32;
  1997. if (num <= 64)
  1998. return HALMAC_RSVD_PG_NUM64;
  1999. if (num > 128)
  2000. RTW_WARN("%s: Fail to allocate RSVD page(%d)!!"
  2001. " The MAX RSVD page number is 128...\n",
  2002. __FUNCTION__, num);
  2003. return HALMAC_RSVD_PG_NUM128;
  2004. }
  2005. static u8 _rsvd_page_num_halmac2drv(enum halmac_drv_rsvd_pg_num rsvd_page_number)
  2006. {
  2007. u8 num = 0;
  2008. switch (rsvd_page_number) {
  2009. case HALMAC_RSVD_PG_NUM8:
  2010. num = 8;
  2011. break;
  2012. case HALMAC_RSVD_PG_NUM16:
  2013. num = 16;
  2014. break;
  2015. case HALMAC_RSVD_PG_NUM24:
  2016. num = 24;
  2017. break;
  2018. case HALMAC_RSVD_PG_NUM32:
  2019. num = 32;
  2020. break;
  2021. case HALMAC_RSVD_PG_NUM64:
  2022. num = 64;
  2023. break;
  2024. case HALMAC_RSVD_PG_NUM128:
  2025. num = 128;
  2026. break;
  2027. }
  2028. return num;
  2029. }
  2030. static enum halmac_trx_mode _choose_trx_mode(struct dvobj_priv *d)
  2031. {
  2032. PADAPTER p;
  2033. p = dvobj_get_primary_adapter(d);
  2034. if (p->registrypriv.wifi_spec)
  2035. return HALMAC_TRX_MODE_WMM;
  2036. #ifdef CONFIG_SUPPORT_TRX_SHARED
  2037. if (_rtw_get_trx_share_mode(p))
  2038. return HALMAC_TRX_MODE_TRXSHARE;
  2039. #endif
  2040. return HALMAC_TRX_MODE_NORMAL;
  2041. }
  2042. static inline enum halmac_rf_type _rf_type_drv2halmac(enum rf_type rf_drv)
  2043. {
  2044. enum halmac_rf_type rf_mac;
  2045. switch (rf_drv) {
  2046. case RF_1T1R:
  2047. rf_mac = HALMAC_RF_1T1R;
  2048. break;
  2049. case RF_1T2R:
  2050. rf_mac = HALMAC_RF_1T2R;
  2051. break;
  2052. case RF_2T2R:
  2053. rf_mac = HALMAC_RF_2T2R;
  2054. break;
  2055. case RF_2T3R:
  2056. rf_mac = HALMAC_RF_2T3R;
  2057. break;
  2058. case RF_2T4R:
  2059. rf_mac = HALMAC_RF_2T4R;
  2060. break;
  2061. case RF_3T3R:
  2062. rf_mac = HALMAC_RF_3T3R;
  2063. break;
  2064. case RF_3T4R:
  2065. rf_mac = HALMAC_RF_3T4R;
  2066. break;
  2067. case RF_4T4R:
  2068. rf_mac = HALMAC_RF_4T4R;
  2069. break;
  2070. default:
  2071. rf_mac = HALMAC_RF_MAX_TYPE;
  2072. RTW_ERR("%s: Invalid RF type(0x%x)!\n", __FUNCTION__, rf_drv);
  2073. break;
  2074. }
  2075. return rf_mac;
  2076. }
  2077. static inline enum rf_type _rf_type_halmac2drv(enum halmac_rf_type rf_mac)
  2078. {
  2079. enum rf_type rf_drv;
  2080. switch (rf_mac) {
  2081. case HALMAC_RF_1T2R:
  2082. rf_drv = RF_1T2R;
  2083. break;
  2084. case HALMAC_RF_2T4R:
  2085. rf_drv = RF_2T4R;
  2086. break;
  2087. case HALMAC_RF_2T2R:
  2088. case HALMAC_RF_2T2R_GREEN:
  2089. rf_drv = RF_2T2R;
  2090. break;
  2091. case HALMAC_RF_2T3R:
  2092. rf_drv = RF_2T3R;
  2093. break;
  2094. case HALMAC_RF_1T1R:
  2095. rf_drv = RF_1T1R;
  2096. break;
  2097. case HALMAC_RF_3T3R:
  2098. rf_drv = RF_3T3R;
  2099. break;
  2100. case HALMAC_RF_3T4R:
  2101. rf_drv = RF_3T4R;
  2102. break;
  2103. case HALMAC_RF_4T4R:
  2104. rf_drv = RF_4T4R;
  2105. break;
  2106. default:
  2107. rf_drv = RF_TYPE_MAX;
  2108. RTW_ERR("%s: Invalid RF type(0x%x)!\n", __FUNCTION__, rf_mac);
  2109. break;
  2110. }
  2111. return rf_drv;
  2112. }
  2113. static enum odm_cut_version _cut_version_drv2phydm(
  2114. enum tag_HAL_Cut_Version_Definition cut_drv)
  2115. {
  2116. enum odm_cut_version cut_phydm = ODM_CUT_A;
  2117. u32 diff;
  2118. if (cut_drv > K_CUT_VERSION)
  2119. RTW_WARN("%s: unknown cut_ver=%d !!\n", __FUNCTION__, cut_drv);
  2120. diff = cut_drv - A_CUT_VERSION;
  2121. cut_phydm += diff;
  2122. return cut_phydm;
  2123. }
  2124. static int _send_general_info_by_reg(struct dvobj_priv *d,
  2125. struct halmac_general_info *info)
  2126. {
  2127. struct _ADAPTER *a;
  2128. struct hal_com_data *hal;
  2129. enum tag_HAL_Cut_Version_Definition cut_drv;
  2130. enum rf_type rftype;
  2131. enum odm_cut_version cut_phydm;
  2132. u8 h2c[RTW_HALMAC_H2C_MAX_SIZE] = {0};
  2133. a = dvobj_get_primary_adapter(d);
  2134. hal = GET_HAL_DATA(a);
  2135. rftype = _rf_type_halmac2drv(info->rf_type);
  2136. cut_drv = GET_CVID_CUT_VERSION(hal->version_id);
  2137. cut_phydm = _cut_version_drv2phydm(cut_drv);
  2138. #define CLASS_GENERAL_INFO_REG 0x02
  2139. #define CMD_ID_GENERAL_INFO_REG 0x0C
  2140. #define GENERAL_INFO_REG_SET_CMD_ID(buf, v) SET_BITS_TO_LE_4BYTE(buf, 0, 5, v)
  2141. #define GENERAL_INFO_REG_SET_CLASS(buf, v) SET_BITS_TO_LE_4BYTE(buf, 5, 3, v)
  2142. #define GENERAL_INFO_REG_SET_RFE_TYPE(buf, v) SET_BITS_TO_LE_4BYTE(buf, 8, 8, v)
  2143. #define GENERAL_INFO_REG_SET_RF_TYPE(buf, v) SET_BITS_TO_LE_4BYTE(buf, 16, 8, v)
  2144. #define GENERAL_INFO_REG_SET_CUT_VERSION(buf, v) SET_BITS_TO_LE_4BYTE(buf, 24, 8, v)
  2145. #define GENERAL_INFO_REG_SET_RX_ANT_STATUS(buf, v) SET_BITS_TO_LE_1BYTE(buf+4, 0, 4, v)
  2146. #define GENERAL_INFO_REG_SET_TX_ANT_STATUS(buf, v) SET_BITS_TO_LE_1BYTE(buf+4, 4, 4, v)
  2147. GENERAL_INFO_REG_SET_CMD_ID(h2c, CMD_ID_GENERAL_INFO_REG);
  2148. GENERAL_INFO_REG_SET_CLASS(h2c, CLASS_GENERAL_INFO_REG);
  2149. GENERAL_INFO_REG_SET_RFE_TYPE(h2c, info->rfe_type);
  2150. GENERAL_INFO_REG_SET_RF_TYPE(h2c, rftype);
  2151. GENERAL_INFO_REG_SET_CUT_VERSION(h2c, cut_phydm);
  2152. GENERAL_INFO_REG_SET_RX_ANT_STATUS(h2c, info->rx_ant_status);
  2153. GENERAL_INFO_REG_SET_TX_ANT_STATUS(h2c, info->tx_ant_status);
  2154. return rtw_halmac_send_h2c(d, h2c);
  2155. }
  2156. static int _send_general_info(struct dvobj_priv *d)
  2157. {
  2158. struct _ADAPTER *adapter;
  2159. struct hal_com_data *hal;
  2160. struct halmac_adapter *halmac;
  2161. struct halmac_api *api;
  2162. struct halmac_general_info info;
  2163. enum halmac_ret_status status;
  2164. enum rf_type rf = RF_1T1R;
  2165. enum bb_path txpath = BB_PATH_A;
  2166. enum bb_path rxpath = BB_PATH_A;
  2167. int err;
  2168. adapter = dvobj_get_primary_adapter(d);
  2169. hal = GET_HAL_DATA(adapter);
  2170. halmac = dvobj_to_halmac(d);
  2171. if (!halmac)
  2172. return -1;
  2173. api = HALMAC_GET_API(halmac);
  2174. _rtw_memset(&info, 0, sizeof(info));
  2175. info.rfe_type = (u8)hal->rfe_type;
  2176. rtw_hal_get_rf_path(d, &rf, &txpath, &rxpath);
  2177. info.rf_type = _rf_type_drv2halmac(rf);
  2178. info.tx_ant_status = (u8)txpath;
  2179. info.rx_ant_status = (u8)rxpath;
  2180. status = api->halmac_send_general_info(halmac, &info);
  2181. switch (status) {
  2182. case HALMAC_RET_SUCCESS:
  2183. break;
  2184. case HALMAC_RET_NO_DLFW:
  2185. RTW_WARN("%s: halmac_send_general_info() fail because fw not dl!\n",
  2186. __FUNCTION__);
  2187. /* go through */
  2188. default:
  2189. return -1;
  2190. }
  2191. err = _send_general_info_by_reg(d, &info);
  2192. if (err) {
  2193. RTW_ERR("%s: Fail to send general info by register!\n",
  2194. __FUNCTION__);
  2195. return -1;
  2196. }
  2197. return 0;
  2198. }
  2199. static int _cfg_drv_rsvd_pg_num(struct dvobj_priv *d)
  2200. {
  2201. struct _ADAPTER *a;
  2202. struct hal_com_data *hal;
  2203. struct halmac_adapter *halmac;
  2204. struct halmac_api *api;
  2205. enum halmac_drv_rsvd_pg_num rsvd_page_number;
  2206. enum halmac_ret_status status;
  2207. u8 drv_rsvd_num;
  2208. a = dvobj_get_primary_adapter(d);
  2209. hal = GET_HAL_DATA(a);
  2210. halmac = dvobj_to_halmac(d);
  2211. api = HALMAC_GET_API(halmac);
  2212. drv_rsvd_num = rtw_hal_get_rsvd_page_num(a);
  2213. rsvd_page_number = _rsvd_page_num_drv2halmac(drv_rsvd_num);
  2214. status = api->halmac_cfg_drv_rsvd_pg_num(halmac, rsvd_page_number);
  2215. if (status != HALMAC_RET_SUCCESS)
  2216. return -1;
  2217. hal->drv_rsvd_page_number = _rsvd_page_num_halmac2drv(rsvd_page_number);
  2218. if (drv_rsvd_num != hal->drv_rsvd_page_number)
  2219. RTW_INFO("%s: request %d pages, but allocate %d pages\n",
  2220. __FUNCTION__, drv_rsvd_num, hal->drv_rsvd_page_number);
  2221. return 0;
  2222. }
  2223. static void _debug_dlfw_fail(struct dvobj_priv *d)
  2224. {
  2225. struct _ADAPTER *a;
  2226. u32 addr;
  2227. u32 v32, i, n;
  2228. u8 data[0x100] = {0};
  2229. a = dvobj_get_primary_adapter(d);
  2230. /* read 0x80[15:0], 0x10F8[31:0] once */
  2231. addr = 0x80;
  2232. v32 = rtw_read16(a, addr);
  2233. RTW_PRINT("%s: 0x%X = 0x%04x\n", __FUNCTION__, addr, v32);
  2234. addr = 0x10F8;
  2235. v32 = rtw_read32(a, addr);
  2236. RTW_PRINT("%s: 0x%X = 0x%08x\n", __FUNCTION__, addr, v32);
  2237. /* read 0x10FC[31:0], 5 times */
  2238. addr = 0x10FC;
  2239. n = 5;
  2240. for (i = 0; i < n; i++) {
  2241. v32 = rtw_read32(a, addr);
  2242. RTW_PRINT("%s: 0x%X = 0x%08x (%u/%u)\n",
  2243. __FUNCTION__, addr, v32, i, n);
  2244. }
  2245. /*
  2246. * write 0x3A[7:0]=0x28 and 0xF6[7:0]=0x01
  2247. * and then read 0xC0[31:0] 5 times
  2248. */
  2249. addr = 0x3A;
  2250. v32 = 0x28;
  2251. rtw_write8(a, addr, (u8)v32);
  2252. v32 = rtw_read8(a, addr);
  2253. RTW_PRINT("%s: 0x%X = 0x%02x\n", __FUNCTION__, addr, v32);
  2254. addr = 0xF6;
  2255. v32 = 0x1;
  2256. rtw_write8(a, addr, (u8)v32);
  2257. v32 = rtw_read8(a, addr);
  2258. RTW_PRINT("%s: 0x%X = 0x%02x\n", __FUNCTION__, addr, v32);
  2259. addr = 0xC0;
  2260. n = 5;
  2261. for (i = 0; i < n; i++) {
  2262. v32 = rtw_read32(a, addr);
  2263. RTW_PRINT("%s: 0x%X = 0x%08x (%u/%u)\n",
  2264. __FUNCTION__, addr, v32, i, n);
  2265. }
  2266. /* 0x00~0xFF, 0x1000~0x10FF */
  2267. addr = 0;
  2268. n = 0x100;
  2269. for (i = 0; i < n; i+=4)
  2270. *(u32*)&data[i] = cpu_to_le32(rtw_read32(a, addr+i));
  2271. for (i = 0; i < n; i++) {
  2272. if (i % 16 == 0)
  2273. RTW_PRINT("0x%04x\t", addr+i);
  2274. _RTW_PRINT("0x%02x", data[i]);
  2275. if (i % 16 == 15)
  2276. _RTW_PRINT("\n");
  2277. else
  2278. _RTW_PRINT(" ");
  2279. }
  2280. addr = 0x1000;
  2281. n = 0x100;
  2282. for (i = 0; i < n; i+=4)
  2283. *(u32*)&data[i] = cpu_to_le32(rtw_read32(a, addr+i));
  2284. for (i = 0; i < n; i++) {
  2285. if (i % 16 == 0)
  2286. RTW_PRINT("0x%04x\t", addr+i);
  2287. _RTW_PRINT("0x%02x", data[i]);
  2288. if (i % 16 == 15)
  2289. _RTW_PRINT("\n");
  2290. else
  2291. _RTW_PRINT(" ");
  2292. }
  2293. /* read 0x80 after 10 secs */
  2294. rtw_msleep_os(10000);
  2295. addr = 0x80;
  2296. v32 = rtw_read16(a, addr);
  2297. RTW_PRINT("%s: 0x%X = 0x%04x (after 10 secs)\n",
  2298. __FUNCTION__, addr, v32);
  2299. }
  2300. static enum halmac_ret_status _enter_cpu_sleep_mode(struct dvobj_priv *d)
  2301. {
  2302. struct hal_com_data *hal;
  2303. struct halmac_adapter *mac;
  2304. struct halmac_api *api;
  2305. hal = GET_HAL_DATA(dvobj_get_primary_adapter(d));
  2306. mac = dvobj_to_halmac(d);
  2307. api = HALMAC_GET_API(mac);
  2308. #ifdef CONFIG_RTL8822B
  2309. /* Support after firmware version 21 */
  2310. if (hal->firmware_version < 21)
  2311. return HALMAC_RET_NOT_SUPPORT;
  2312. #elif defined(CONFIG_RTL8821C)
  2313. /* Support after firmware version 13.6 or 16 */
  2314. if (hal->firmware_version == 13) {
  2315. if (hal->firmware_sub_version < 6)
  2316. return HALMAC_RET_NOT_SUPPORT;
  2317. } else if (hal->firmware_version < 16) {
  2318. return HALMAC_RET_NOT_SUPPORT;
  2319. }
  2320. #endif
  2321. return api->halmac_enter_cpu_sleep_mode(mac);
  2322. }
  2323. /*
  2324. * _cpu_sleep() - Let IC CPU enter sleep mode
  2325. * @d: struct dvobj_priv*
  2326. * @timeout: time limit of wait, unit is ms
  2327. * 0 for no limit
  2328. *
  2329. * Rteurn 0 for CPU in sleep mode, otherwise fail to enter sleep mode.
  2330. * Error codes definition are as follow:
  2331. * -1 HALMAC enter sleep return fail
  2332. * -2 HALMAC get CPU mode return fail
  2333. * -110 timeout
  2334. */
  2335. static int _cpu_sleep(struct dvobj_priv *d, u32 timeout)
  2336. {
  2337. struct halmac_adapter *mac;
  2338. struct halmac_api *api;
  2339. enum halmac_ret_status status;
  2340. enum halmac_wlcpu_mode mode = HALMAC_WLCPU_UNDEFINE;
  2341. systime start_t;
  2342. s32 period = 0;
  2343. u32 cnt = 0;
  2344. int err = 0;
  2345. mac = dvobj_to_halmac(d);
  2346. api = HALMAC_GET_API(mac);
  2347. start_t = rtw_get_current_time();
  2348. status = _enter_cpu_sleep_mode(d);
  2349. if (status != HALMAC_RET_SUCCESS) {
  2350. if (status != HALMAC_RET_NOT_SUPPORT)
  2351. err = -1;
  2352. goto exit;
  2353. }
  2354. do {
  2355. cnt++;
  2356. mode = HALMAC_WLCPU_UNDEFINE;
  2357. status = api->halmac_get_cpu_mode(mac, &mode);
  2358. period = rtw_get_passing_time_ms(start_t);
  2359. if (status != HALMAC_RET_SUCCESS) {
  2360. err = -2;
  2361. break;
  2362. }
  2363. if (mode == HALMAC_WLCPU_SLEEP)
  2364. break;
  2365. if (period > timeout) {
  2366. err = -110;
  2367. break;
  2368. }
  2369. rtw_msleep_os(1);
  2370. } while (1);
  2371. exit:
  2372. if (err)
  2373. RTW_ERR("%s: Fail to enter sleep mode! (%d, %d)\n",
  2374. __FUNCTION__, status, mode);
  2375. RTW_INFO("%s: Cost %dms to polling %u times. (err=%d)\n",
  2376. __FUNCTION__, period, cnt, err);
  2377. return err;
  2378. }
  2379. /*
  2380. * Description:
  2381. * Downlaod Firmware Flow
  2382. *
  2383. * Parameters:
  2384. * d pointer of struct dvobj_priv
  2385. * fw firmware array
  2386. * fwsize firmware size
  2387. * re_dl re-download firmware or not
  2388. * 0: run in init hal flow, not re-download
  2389. * 1: it is a stand alone operation, not in init hal flow
  2390. *
  2391. * Return:
  2392. * 0 Success
  2393. * others Fail
  2394. */
  2395. static int download_fw(struct dvobj_priv *d, u8 *fw, u32 fwsize, u8 re_dl)
  2396. {
  2397. PHAL_DATA_TYPE hal;
  2398. struct halmac_adapter *mac;
  2399. struct halmac_api *api;
  2400. struct halmac_fw_version fw_vesion;
  2401. enum halmac_ret_status status;
  2402. int err = 0;
  2403. hal = GET_HAL_DATA(dvobj_get_primary_adapter(d));
  2404. mac = dvobj_to_halmac(d);
  2405. api = HALMAC_GET_API(mac);
  2406. if ((!fw) || (!fwsize))
  2407. return -1;
  2408. /* 1. Driver Stop Tx */
  2409. /* ToDo */
  2410. /* 2. Driver Check Tx FIFO is empty */
  2411. err = rtw_halmac_txfifo_wait_empty(d, 2000); /* wait 2s */
  2412. if (err) {
  2413. err = -1;
  2414. goto resume_tx;
  2415. }
  2416. /* 3. Config MAX download size */
  2417. /*
  2418. * Already done in rtw_halmac_init_adapter() or
  2419. * somewhere calling rtw_halmac_set_max_dl_fw_size().
  2420. */
  2421. if (re_dl) {
  2422. /* 4. Enter IC CPU sleep mode */
  2423. err = _cpu_sleep(d, 2000);
  2424. if (err) {
  2425. RTW_ERR("%s: IC CPU fail to enter sleep mode!(%d)\n",
  2426. __FUNCTION__, err);
  2427. /* skip this error */
  2428. err = 0;
  2429. }
  2430. }
  2431. /* 5. Download Firmware */
  2432. status = api->halmac_download_firmware(mac, fw, fwsize);
  2433. if (status != HALMAC_RET_SUCCESS) {
  2434. RTW_ERR("%s: download firmware FAIL! status=0x%02x\n",
  2435. __FUNCTION__, status);
  2436. _debug_dlfw_fail(d);
  2437. err = -1;
  2438. goto resume_tx;
  2439. }
  2440. /* 5.1. (Driver) Reset driver variables if needed */
  2441. hal->LastHMEBoxNum = 0;
  2442. /* 5.2. (Driver) Get FW version */
  2443. status = api->halmac_get_fw_version(mac, &fw_vesion);
  2444. if (status == HALMAC_RET_SUCCESS) {
  2445. hal->firmware_version = fw_vesion.version;
  2446. hal->firmware_sub_version = fw_vesion.sub_version;
  2447. hal->firmware_size = fwsize;
  2448. }
  2449. resume_tx:
  2450. /* 6. Driver resume TX if needed */
  2451. /* ToDo */
  2452. if (err)
  2453. goto exit;
  2454. if (re_dl) {
  2455. enum halmac_trx_mode mode;
  2456. /* 7. Change reserved page size */
  2457. err = _cfg_drv_rsvd_pg_num(d);
  2458. if (err)
  2459. return -1;
  2460. /* 8. Init TRX Configuration */
  2461. mode = _choose_trx_mode(d);
  2462. status = api->halmac_init_trx_cfg(mac, mode);
  2463. if (HALMAC_RET_SUCCESS != status)
  2464. return -1;
  2465. /* 9. Config RX Aggregation */
  2466. err = rtw_halmac_rx_agg_switch(d, _TRUE);
  2467. if (err)
  2468. return -1;
  2469. /* 10. Send General Info */
  2470. err = _send_general_info(d);
  2471. if (err)
  2472. return -1;
  2473. }
  2474. exit:
  2475. return err;
  2476. }
  2477. static int init_mac_flow(struct dvobj_priv *d)
  2478. {
  2479. PADAPTER p;
  2480. struct hal_com_data *hal;
  2481. struct halmac_adapter *halmac;
  2482. struct halmac_api *api;
  2483. enum halmac_drv_rsvd_pg_num rsvd_page_number;
  2484. union halmac_wlan_addr hwa;
  2485. enum halmac_trx_mode trx_mode;
  2486. enum halmac_ret_status status;
  2487. u8 drv_rsvd_num;
  2488. u8 nettype;
  2489. int err, err_ret = -1;
  2490. p = dvobj_get_primary_adapter(d);
  2491. hal = GET_HAL_DATA(p);
  2492. halmac = dvobj_to_halmac(d);
  2493. api = HALMAC_GET_API(halmac);
  2494. #ifdef CONFIG_SUPPORT_TRX_SHARED
  2495. status = api->halmac_cfg_rxff_expand_mode(halmac,
  2496. _rtw_get_trx_share_mode(p));
  2497. if (status != HALMAC_RET_SUCCESS)
  2498. goto out;
  2499. #endif
  2500. #if 0 /* It is not necessary to call this in normal driver */
  2501. status = api->halmac_cfg_la_mode(halmac, HALMAC_LA_MODE_DISABLE);
  2502. if (status != HALMAC_RET_SUCCESS)
  2503. goto out;
  2504. #endif
  2505. err = _cfg_drv_rsvd_pg_num(d);
  2506. if (err)
  2507. goto out;
  2508. #ifdef CONFIG_USB_HCI
  2509. status = api->halmac_set_bulkout_num(halmac, d->RtNumOutPipes);
  2510. if (status != HALMAC_RET_SUCCESS)
  2511. goto out;
  2512. #endif /* CONFIG_USB_HCI */
  2513. trx_mode = _choose_trx_mode(d);
  2514. status = api->halmac_init_mac_cfg(halmac, trx_mode);
  2515. if (status != HALMAC_RET_SUCCESS)
  2516. goto out;
  2517. err = rtw_halmac_rx_agg_switch(d, _TRUE);
  2518. if (err)
  2519. goto out;
  2520. nettype = dvobj_to_regsty(d)->wireless_mode;
  2521. if (is_supported_vht(nettype) == _TRUE)
  2522. status = api->halmac_cfg_operation_mode(halmac, HALMAC_WIRELESS_MODE_AC);
  2523. else if (is_supported_ht(nettype) == _TRUE)
  2524. status = api->halmac_cfg_operation_mode(halmac, HALMAC_WIRELESS_MODE_N);
  2525. else if (IsSupportedTxOFDM(nettype) == _TRUE)
  2526. status = api->halmac_cfg_operation_mode(halmac, HALMAC_WIRELESS_MODE_G);
  2527. else
  2528. status = api->halmac_cfg_operation_mode(halmac, HALMAC_WIRELESS_MODE_B);
  2529. if (status != HALMAC_RET_SUCCESS)
  2530. goto out;
  2531. err_ret = 0;
  2532. out:
  2533. return err_ret;
  2534. }
  2535. static int _drv_enable_trx(struct dvobj_priv *d)
  2536. {
  2537. struct _ADAPTER *adapter;
  2538. u32 status;
  2539. adapter = dvobj_get_primary_adapter(d);
  2540. if (adapter->bup == _FALSE) {
  2541. status = rtw_start_drv_threads(adapter);
  2542. if (status == _FAIL) {
  2543. RTW_ERR("%s: Start threads Failed!\n", __FUNCTION__);
  2544. return -1;
  2545. }
  2546. }
  2547. rtw_intf_start(adapter);
  2548. return 0;
  2549. }
  2550. /*
  2551. * Notices:
  2552. * Make sure
  2553. * 1. rtw_hal_get_hwreg(HW_VAR_RF_TYPE)
  2554. * 2. HAL_DATA_TYPE.rfe_type
  2555. * already ready for use before calling this function.
  2556. */
  2557. static int _halmac_init_hal(struct dvobj_priv *d, u8 *fw, u32 fwsize)
  2558. {
  2559. PADAPTER adapter;
  2560. struct halmac_adapter *halmac;
  2561. struct halmac_api *api;
  2562. enum halmac_ret_status status;
  2563. u32 ok;
  2564. u8 fw_ok = _FALSE;
  2565. int err, err_ret = -1;
  2566. adapter = dvobj_get_primary_adapter(d);
  2567. halmac = dvobj_to_halmac(d);
  2568. if (!halmac)
  2569. goto out;
  2570. api = HALMAC_GET_API(halmac);
  2571. /* StatePowerOff */
  2572. /* SKIP: halmac_init_adapter (Already done before) */
  2573. /* halmac_pre_Init_system_cfg */
  2574. /* halmac_mac_power_switch(on) */
  2575. /* halmac_Init_system_cfg */
  2576. ok = rtw_hal_power_on(adapter);
  2577. if (_FAIL == ok)
  2578. goto out;
  2579. /* StatePowerOn */
  2580. /* DownloadFW */
  2581. if (fw && fwsize) {
  2582. err = download_fw(d, fw, fwsize, 0);
  2583. if (err)
  2584. goto out;
  2585. fw_ok = _TRUE;
  2586. }
  2587. /* InitMACFlow */
  2588. err = init_mac_flow(d);
  2589. if (err)
  2590. goto out;
  2591. /* Driver insert flow: Enable TR/RX */
  2592. err = _drv_enable_trx(d);
  2593. if (err)
  2594. goto out;
  2595. /* halmac_send_general_info */
  2596. if (_TRUE == fw_ok) {
  2597. err = _send_general_info(d);
  2598. if (err)
  2599. goto out;
  2600. }
  2601. /* Init Phy parameter-MAC */
  2602. ok = rtw_hal_init_mac_register(adapter);
  2603. if (_FALSE == ok)
  2604. goto out;
  2605. /* StateMacInitialized */
  2606. /* halmac_cfg_drv_info */
  2607. err = rtw_halmac_config_rx_info(d, HALMAC_DRV_INFO_PHY_STATUS);
  2608. if (err)
  2609. goto out;
  2610. /* halmac_set_hw_value(HALMAC_HW_EN_BB_RF) */
  2611. /* Init BB, RF */
  2612. ok = rtw_hal_init_phy(adapter);
  2613. if (_FALSE == ok)
  2614. goto out;
  2615. status = api->halmac_init_interface_cfg(halmac);
  2616. if (status != HALMAC_RET_SUCCESS)
  2617. goto out;
  2618. /* SKIP: halmac_verify_platform_api */
  2619. /* SKIP: halmac_h2c_lb */
  2620. /* StateRxIdle */
  2621. err_ret = 0;
  2622. out:
  2623. return err_ret;
  2624. }
  2625. int rtw_halmac_init_hal(struct dvobj_priv *d)
  2626. {
  2627. return _halmac_init_hal(d, NULL, 0);
  2628. }
  2629. /*
  2630. * Notices:
  2631. * Make sure
  2632. * 1. rtw_hal_get_hwreg(HW_VAR_RF_TYPE)
  2633. * 2. HAL_DATA_TYPE.rfe_type
  2634. * already ready for use before calling this function.
  2635. */
  2636. int rtw_halmac_init_hal_fw(struct dvobj_priv *d, u8 *fw, u32 fwsize)
  2637. {
  2638. return _halmac_init_hal(d, fw, fwsize);
  2639. }
  2640. /*
  2641. * Notices:
  2642. * Make sure
  2643. * 1. rtw_hal_get_hwreg(HW_VAR_RF_TYPE)
  2644. * 2. HAL_DATA_TYPE.rfe_type
  2645. * already ready for use before calling this function.
  2646. */
  2647. int rtw_halmac_init_hal_fw_file(struct dvobj_priv *d, u8 *fwpath)
  2648. {
  2649. u8 *fw = NULL;
  2650. u32 fwmaxsize = 0, size = 0;
  2651. int err = 0;
  2652. err = rtw_halmac_get_fw_max_size(d, &fwmaxsize);
  2653. if (err) {
  2654. RTW_ERR("%s: Fail to get Firmware MAX size(err=%d)\n", __FUNCTION__, err);
  2655. return -1;
  2656. }
  2657. fw = rtw_zmalloc(fwmaxsize);
  2658. if (!fw)
  2659. return -1;
  2660. size = rtw_retrieve_from_file(fwpath, fw, fwmaxsize);
  2661. if (!size) {
  2662. err = -1;
  2663. goto exit;
  2664. }
  2665. err = _halmac_init_hal(d, fw, size);
  2666. exit:
  2667. rtw_mfree(fw, fwmaxsize);
  2668. /*fw = NULL;*/
  2669. return err;
  2670. }
  2671. int rtw_halmac_deinit_hal(struct dvobj_priv *d)
  2672. {
  2673. PADAPTER adapter;
  2674. struct halmac_adapter *halmac;
  2675. struct halmac_api *api;
  2676. enum halmac_ret_status status;
  2677. int err = -1;
  2678. adapter = dvobj_get_primary_adapter(d);
  2679. halmac = dvobj_to_halmac(d);
  2680. if (!halmac)
  2681. goto out;
  2682. api = HALMAC_GET_API(halmac);
  2683. status = api->halmac_deinit_interface_cfg(halmac);
  2684. if (status != HALMAC_RET_SUCCESS)
  2685. goto out;
  2686. rtw_hal_power_off(adapter);
  2687. err = 0;
  2688. out:
  2689. return err;
  2690. }
  2691. int rtw_halmac_self_verify(struct dvobj_priv *d)
  2692. {
  2693. struct halmac_adapter *mac;
  2694. struct halmac_api *api;
  2695. enum halmac_ret_status status;
  2696. int err = -1;
  2697. mac = dvobj_to_halmac(d);
  2698. api = HALMAC_GET_API(mac);
  2699. status = api->halmac_verify_platform_api(mac);
  2700. if (status != HALMAC_RET_SUCCESS)
  2701. goto out;
  2702. status = api->halmac_h2c_lb(mac);
  2703. if (status != HALMAC_RET_SUCCESS)
  2704. goto out;
  2705. err = 0;
  2706. out:
  2707. return err;
  2708. }
  2709. static u8 rtw_halmac_txfifo_is_empty(struct dvobj_priv *d)
  2710. {
  2711. struct halmac_adapter *mac;
  2712. struct halmac_api *api;
  2713. enum halmac_ret_status status;
  2714. u32 chk_num = 10;
  2715. u8 rst = _FALSE;
  2716. mac = dvobj_to_halmac(d);
  2717. api = HALMAC_GET_API(mac);
  2718. status = api->halmac_txfifo_is_empty(mac, chk_num);
  2719. if (status == HALMAC_RET_SUCCESS)
  2720. rst = _TRUE;
  2721. return rst;
  2722. }
  2723. /**
  2724. * rtw_halmac_txfifo_wait_empty() - Wait TX FIFO to be emtpy
  2725. * @d: struct dvobj_priv*
  2726. * @timeout: time limit of wait, unit is ms
  2727. * 0 for no limit
  2728. *
  2729. * Wait TX FIFO to be emtpy.
  2730. *
  2731. * Rteurn 0 for TX FIFO is empty, otherwise not empty.
  2732. */
  2733. int rtw_halmac_txfifo_wait_empty(struct dvobj_priv *d, u32 timeout)
  2734. {
  2735. struct _ADAPTER *a;
  2736. u8 empty = _FALSE;
  2737. u32 cnt = 0;
  2738. systime start_time = 0;
  2739. u32 pass_time; /* ms */
  2740. a = dvobj_get_primary_adapter(d);
  2741. start_time = rtw_get_current_time();
  2742. do {
  2743. cnt++;
  2744. empty = rtw_halmac_txfifo_is_empty(d);
  2745. if (empty == _TRUE)
  2746. break;
  2747. if (timeout) {
  2748. pass_time = rtw_get_passing_time_ms(start_time);
  2749. if (pass_time > timeout)
  2750. break;
  2751. }
  2752. if (RTW_CANNOT_IO(a)) {
  2753. RTW_WARN("%s: Interrupted by I/O forbiden!\n", __FUNCTION__);
  2754. break;
  2755. }
  2756. rtw_msleep_os(2);
  2757. } while (1);
  2758. if (empty == _FALSE) {
  2759. #ifdef CONFIG_RTW_DEBUG
  2760. u16 dbg_reg[] = {0x210, 0x230, 0x234, 0x238, 0x23C, 0x240,
  2761. 0x41A, 0x10FC, 0x10F8, 0x11F4, 0x11F8};
  2762. u8 i;
  2763. u32 val;
  2764. if (!RTW_CANNOT_IO(a)) {
  2765. for (i = 0; i < ARRAY_SIZE(dbg_reg); i++) {
  2766. val = rtw_read32(a, dbg_reg[i]);
  2767. RTW_ERR("REG_%X:0x%08x\n", dbg_reg[i], val);
  2768. }
  2769. }
  2770. #endif /* CONFIG_RTW_DEBUG */
  2771. RTW_ERR("%s: Fail to wait txfifo empty!(cnt=%d)\n",
  2772. __FUNCTION__, cnt);
  2773. return -1;
  2774. }
  2775. return 0;
  2776. }
  2777. static enum halmac_dlfw_mem _fw_mem_drv2halmac(enum fw_mem mem, u8 tx_stop)
  2778. {
  2779. enum halmac_dlfw_mem mem_halmac = HALMAC_DLFW_MEM_UNDEFINE;
  2780. switch (mem) {
  2781. case FW_EMEM:
  2782. if (tx_stop == _FALSE)
  2783. mem_halmac = HALMAC_DLFW_MEM_EMEM_RSVD_PG;
  2784. else
  2785. mem_halmac = HALMAC_DLFW_MEM_EMEM;
  2786. break;
  2787. case FW_IMEM:
  2788. case FW_DMEM:
  2789. mem_halmac = HALMAC_DLFW_MEM_UNDEFINE;
  2790. break;
  2791. }
  2792. return mem_halmac;
  2793. }
  2794. int rtw_halmac_dlfw_mem(struct dvobj_priv *d, u8 *fw, u32 fwsize, enum fw_mem mem)
  2795. {
  2796. struct halmac_adapter *mac;
  2797. struct halmac_api *api;
  2798. enum halmac_ret_status status;
  2799. enum halmac_dlfw_mem dlfw_mem;
  2800. u8 tx_stop = _FALSE;
  2801. u32 chk_timeout = 2000; /* unit: ms */
  2802. int err = 0;
  2803. mac = dvobj_to_halmac(d);
  2804. api = HALMAC_GET_API(mac);
  2805. if ((!fw) || (!fwsize))
  2806. return -1;
  2807. #ifndef RTW_HALMAC_DLFW_MEM_NO_STOP_TX
  2808. /* 1. Driver Stop Tx */
  2809. /* ToDo */
  2810. /* 2. Driver Check Tx FIFO is empty */
  2811. err = rtw_halmac_txfifo_wait_empty(d, chk_timeout);
  2812. if (err)
  2813. tx_stop = _FALSE;
  2814. else
  2815. tx_stop = _TRUE;
  2816. #endif /* !RTW_HALMAC_DLFW_MEM_NO_STOP_TX */
  2817. /* 3. Download Firmware MEM */
  2818. dlfw_mem = _fw_mem_drv2halmac(mem, tx_stop);
  2819. if (dlfw_mem == HALMAC_DLFW_MEM_UNDEFINE) {
  2820. err = -1;
  2821. goto resume_tx;
  2822. }
  2823. status = api->halmac_free_download_firmware(mac, dlfw_mem, fw, fwsize);
  2824. if (status != HALMAC_RET_SUCCESS) {
  2825. RTW_ERR("%s: halmac_free_download_firmware fail(err=0x%x)\n",
  2826. __FUNCTION__, status);
  2827. err = -1;
  2828. goto resume_tx;
  2829. }
  2830. resume_tx:
  2831. #ifndef RTW_HALMAC_DLFW_MEM_NO_STOP_TX
  2832. /* 4. Driver resume TX if needed */
  2833. /* ToDo */
  2834. #endif /* !RTW_HALMAC_DLFW_MEM_NO_STOP_TX */
  2835. return err;
  2836. }
  2837. int rtw_halmac_dlfw_mem_from_file(struct dvobj_priv *d, u8 *fwpath, enum fw_mem mem)
  2838. {
  2839. u8 *fw = NULL;
  2840. u32 fwmaxsize = 0, size = 0;
  2841. int err = 0;
  2842. err = rtw_halmac_get_fw_max_size(d, &fwmaxsize);
  2843. if (err) {
  2844. RTW_ERR("%s: Fail to get Firmware MAX size(err=%d)\n", __FUNCTION__, err);
  2845. return -1;
  2846. }
  2847. fw = rtw_zmalloc(fwmaxsize);
  2848. if (!fw)
  2849. return -1;
  2850. size = rtw_retrieve_from_file(fwpath, fw, fwmaxsize);
  2851. if (size)
  2852. err = rtw_halmac_dlfw_mem(d, fw, size, mem);
  2853. else
  2854. err = -1;
  2855. rtw_mfree(fw, fwmaxsize);
  2856. /*fw = NULL;*/
  2857. return err;
  2858. }
  2859. /*
  2860. * Return:
  2861. * 0 Success
  2862. * -22 Invalid arguemnt
  2863. */
  2864. int rtw_halmac_dlfw(struct dvobj_priv *d, u8 *fw, u32 fwsize)
  2865. {
  2866. PADAPTER adapter;
  2867. enum halmac_ret_status status;
  2868. u32 ok;
  2869. int err, err_ret = -1;
  2870. if (!fw || !fwsize)
  2871. return -22;
  2872. adapter = dvobj_get_primary_adapter(d);
  2873. /* re-download firmware */
  2874. if (rtw_is_hw_init_completed(adapter))
  2875. return download_fw(d, fw, fwsize, 1);
  2876. /* Download firmware before hal init */
  2877. /* Power on, download firmware and init mac */
  2878. ok = rtw_hal_power_on(adapter);
  2879. if (_FAIL == ok)
  2880. goto out;
  2881. err = download_fw(d, fw, fwsize, 0);
  2882. if (err) {
  2883. err_ret = err;
  2884. goto out;
  2885. }
  2886. err = init_mac_flow(d);
  2887. if (err)
  2888. goto out;
  2889. err = _send_general_info(d);
  2890. if (err)
  2891. goto out;
  2892. err_ret = 0;
  2893. out:
  2894. return err_ret;
  2895. }
  2896. int rtw_halmac_dlfw_from_file(struct dvobj_priv *d, u8 *fwpath)
  2897. {
  2898. u8 *fw = NULL;
  2899. u32 fwmaxsize = 0, size = 0;
  2900. int err = 0;
  2901. err = rtw_halmac_get_fw_max_size(d, &fwmaxsize);
  2902. if (err) {
  2903. RTW_ERR("%s: Fail to get Firmware MAX size(err=%d)\n", __FUNCTION__, err);
  2904. return -1;
  2905. }
  2906. fw = rtw_zmalloc(fwmaxsize);
  2907. if (!fw)
  2908. return -1;
  2909. size = rtw_retrieve_from_file(fwpath, fw, fwmaxsize);
  2910. if (size)
  2911. err = rtw_halmac_dlfw(d, fw, size);
  2912. else
  2913. err = -1;
  2914. rtw_mfree(fw, fwmaxsize);
  2915. /*fw = NULL;*/
  2916. return err;
  2917. }
  2918. /*
  2919. * Description:
  2920. * Power on/off BB/RF domain.
  2921. *
  2922. * Parameters:
  2923. * enable _TRUE/_FALSE for power on/off
  2924. *
  2925. * Return:
  2926. * 0 Success
  2927. * others Fail
  2928. */
  2929. int rtw_halmac_phy_power_switch(struct dvobj_priv *d, u8 enable)
  2930. {
  2931. PADAPTER adapter;
  2932. struct halmac_adapter *halmac;
  2933. struct halmac_api *api;
  2934. enum halmac_ret_status status;
  2935. adapter = dvobj_get_primary_adapter(d);
  2936. halmac = dvobj_to_halmac(d);
  2937. if (!halmac)
  2938. return -1;
  2939. api = HALMAC_GET_API(halmac);
  2940. status = api->halmac_set_hw_value(halmac, HALMAC_HW_EN_BB_RF, &enable);
  2941. if (status != HALMAC_RET_SUCCESS)
  2942. return -1;
  2943. return 0;
  2944. }
  2945. static u8 _is_fw_read_cmd_down(PADAPTER adapter, u8 msgbox_num)
  2946. {
  2947. u8 read_down = _FALSE;
  2948. int retry_cnts = 100;
  2949. u8 valid;
  2950. do {
  2951. valid = rtw_read8(adapter, REG_HMETFR) & BIT(msgbox_num);
  2952. if (0 == valid)
  2953. read_down = _TRUE;
  2954. else
  2955. rtw_msleep_os(1);
  2956. } while ((!read_down) && (retry_cnts--));
  2957. if (_FALSE == read_down)
  2958. RTW_WARN("%s, reg_1cc(%x), msg_box(%d)...\n", __func__, rtw_read8(adapter, REG_HMETFR), msgbox_num);
  2959. return read_down;
  2960. }
  2961. /**
  2962. * rtw_halmac_send_h2c() - Send H2C to firmware
  2963. * @d: struct dvobj_priv*
  2964. * @h2c: H2C data buffer, suppose to be 8 bytes
  2965. *
  2966. * Send H2C to firmware by message box register(0x1D0~0x1D3 & 0x1F0~0x1F3).
  2967. *
  2968. * Assume firmware be ready to accept H2C here, please check
  2969. * (hal->bFWReady == _TRUE) before call this function or make sure firmware is
  2970. * ready.
  2971. *
  2972. * Return: 0 if process OK, otherwise fail to send this H2C.
  2973. */
  2974. int rtw_halmac_send_h2c(struct dvobj_priv *d, u8 *h2c)
  2975. {
  2976. PADAPTER adapter = dvobj_get_primary_adapter(d);
  2977. PHAL_DATA_TYPE hal = GET_HAL_DATA(adapter);
  2978. u8 h2c_box_num = 0;
  2979. u32 msgbox_addr = 0;
  2980. u32 msgbox_ex_addr = 0;
  2981. u32 h2c_cmd = 0;
  2982. u32 h2c_cmd_ex = 0;
  2983. int err = -1;
  2984. if (!h2c) {
  2985. RTW_WARN("%s: pbuf is NULL\n", __FUNCTION__);
  2986. return err;
  2987. }
  2988. if (rtw_is_surprise_removed(adapter)) {
  2989. RTW_WARN("%s: surprise removed\n", __FUNCTION__);
  2990. return err;
  2991. }
  2992. _enter_critical_mutex(&d->h2c_fwcmd_mutex, NULL);
  2993. /* pay attention to if race condition happened in H2C cmd setting */
  2994. h2c_box_num = hal->LastHMEBoxNum;
  2995. if (!_is_fw_read_cmd_down(adapter, h2c_box_num)) {
  2996. RTW_WARN(" fw read cmd failed...\n");
  2997. #ifdef DBG_CONFIG_ERROR_DETECT
  2998. hal->srestpriv.self_dect_fw = _TRUE;
  2999. hal->srestpriv.self_dect_fw_cnt++;
  3000. #endif /* DBG_CONFIG_ERROR_DETECT */
  3001. goto exit;
  3002. }
  3003. /* Write Ext command (byte 4~7) */
  3004. msgbox_ex_addr = REG_HMEBOX_E0 + (h2c_box_num * EX_MESSAGE_BOX_SIZE);
  3005. _rtw_memcpy((u8 *)(&h2c_cmd_ex), h2c + 4, EX_MESSAGE_BOX_SIZE);
  3006. h2c_cmd_ex = le32_to_cpu(h2c_cmd_ex);
  3007. rtw_write32(adapter, msgbox_ex_addr, h2c_cmd_ex);
  3008. /* Write command (byte 0~3) */
  3009. msgbox_addr = REG_HMEBOX0 + (h2c_box_num * MESSAGE_BOX_SIZE);
  3010. _rtw_memcpy((u8 *)(&h2c_cmd), h2c, 4);
  3011. h2c_cmd = le32_to_cpu(h2c_cmd);
  3012. rtw_write32(adapter, msgbox_addr, h2c_cmd);
  3013. /* update last msg box number */
  3014. hal->LastHMEBoxNum = (h2c_box_num + 1) % MAX_H2C_BOX_NUMS;
  3015. err = 0;
  3016. #ifdef DBG_H2C_CONTENT
  3017. RTW_INFO_DUMP("[H2C] - ", h2c, RTW_HALMAC_H2C_MAX_SIZE);
  3018. #endif
  3019. exit:
  3020. _exit_critical_mutex(&d->h2c_fwcmd_mutex, NULL);
  3021. return err;
  3022. }
  3023. /**
  3024. * rtw_halmac_c2h_handle() - Handle C2H for HALMAC
  3025. * @d: struct dvobj_priv*
  3026. * @c2h: Full C2H packet, including RX description and payload
  3027. * @size: Size(byte) of c2h
  3028. *
  3029. * Send C2H packet to HALMAC to process C2H packets, and the expected C2H ID is
  3030. * 0xFF. This function won't have any I/O, so caller doesn't have to call it in
  3031. * I/O safe place(ex. command thread).
  3032. *
  3033. * Please sure doesn't call this function in the same thread as someone is
  3034. * waiting HALMAC C2H ack, otherwise there is a deadlock happen.
  3035. *
  3036. * Return: 0 if process OK, otherwise no action for this C2H.
  3037. */
  3038. int rtw_halmac_c2h_handle(struct dvobj_priv *d, u8 *c2h, u32 size)
  3039. {
  3040. struct halmac_adapter *mac;
  3041. struct halmac_api *api;
  3042. enum halmac_ret_status status;
  3043. mac = dvobj_to_halmac(d);
  3044. api = HALMAC_GET_API(mac);
  3045. status = api->halmac_get_c2h_info(mac, c2h, size);
  3046. if (HALMAC_RET_SUCCESS != status)
  3047. return -1;
  3048. return 0;
  3049. }
  3050. int rtw_halmac_get_available_efuse_size(struct dvobj_priv *d, u32 *size)
  3051. {
  3052. struct halmac_adapter *mac;
  3053. struct halmac_api *api;
  3054. enum halmac_ret_status status;
  3055. u32 val;
  3056. mac = dvobj_to_halmac(d);
  3057. api = HALMAC_GET_API(mac);
  3058. status = api->halmac_get_efuse_available_size(mac, &val);
  3059. if (HALMAC_RET_SUCCESS != status)
  3060. return -1;
  3061. *size = val;
  3062. return 0;
  3063. }
  3064. int rtw_halmac_get_physical_efuse_size(struct dvobj_priv *d, u32 *size)
  3065. {
  3066. struct halmac_adapter *mac;
  3067. struct halmac_api *api;
  3068. enum halmac_ret_status status;
  3069. u32 val;
  3070. mac = dvobj_to_halmac(d);
  3071. api = HALMAC_GET_API(mac);
  3072. status = api->halmac_get_efuse_size(mac, &val);
  3073. if (HALMAC_RET_SUCCESS != status)
  3074. return -1;
  3075. *size = val;
  3076. return 0;
  3077. }
  3078. int rtw_halmac_read_physical_efuse_map(struct dvobj_priv *d, u8 *map, u32 size)
  3079. {
  3080. struct halmac_adapter *mac;
  3081. struct halmac_api *api;
  3082. enum halmac_ret_status status;
  3083. enum halmac_feature_id id;
  3084. int ret;
  3085. mac = dvobj_to_halmac(d);
  3086. api = HALMAC_GET_API(mac);
  3087. id = HALMAC_FEATURE_DUMP_PHYSICAL_EFUSE;
  3088. ret = init_halmac_event(d, id, map, size);
  3089. if (ret)
  3090. return -1;
  3091. status = api->halmac_dump_efuse_map(mac, HALMAC_EFUSE_R_DRV);
  3092. if (HALMAC_RET_SUCCESS != status) {
  3093. free_halmac_event(d, id);
  3094. return -1;
  3095. }
  3096. ret = wait_halmac_event(d, id);
  3097. if (ret)
  3098. return -1;
  3099. return 0;
  3100. }
  3101. int rtw_halmac_read_physical_efuse(struct dvobj_priv *d, u32 offset, u32 cnt, u8 *data)
  3102. {
  3103. struct halmac_adapter *mac;
  3104. struct halmac_api *api;
  3105. enum halmac_ret_status status;
  3106. u8 v;
  3107. u32 i;
  3108. u8 *efuse = NULL;
  3109. u32 size = 0;
  3110. int err = 0;
  3111. mac = dvobj_to_halmac(d);
  3112. api = HALMAC_GET_API(mac);
  3113. if (api->halmac_read_efuse) {
  3114. for (i = 0; i < cnt; i++) {
  3115. status = api->halmac_read_efuse(mac, offset + i, &v);
  3116. if (HALMAC_RET_SUCCESS != status)
  3117. return -1;
  3118. data[i] = v;
  3119. }
  3120. } else {
  3121. err = rtw_halmac_get_physical_efuse_size(d, &size);
  3122. if (err)
  3123. return -1;
  3124. efuse = rtw_zmalloc(size);
  3125. if (!efuse)
  3126. return -1;
  3127. err = rtw_halmac_read_physical_efuse_map(d, efuse, size);
  3128. if (err)
  3129. err = -1;
  3130. else
  3131. _rtw_memcpy(data, efuse + offset, cnt);
  3132. rtw_mfree(efuse, size);
  3133. }
  3134. return err;
  3135. }
  3136. int rtw_halmac_write_physical_efuse(struct dvobj_priv *d, u32 offset, u32 cnt, u8 *data)
  3137. {
  3138. struct halmac_adapter *mac;
  3139. struct halmac_api *api;
  3140. enum halmac_ret_status status;
  3141. u32 i;
  3142. mac = dvobj_to_halmac(d);
  3143. api = HALMAC_GET_API(mac);
  3144. if (api->halmac_write_efuse == NULL)
  3145. return -1;
  3146. for (i = 0; i < cnt; i++) {
  3147. status = api->halmac_write_efuse(mac, offset + i, data[i]);
  3148. if (HALMAC_RET_SUCCESS != status)
  3149. return -1;
  3150. }
  3151. return 0;
  3152. }
  3153. int rtw_halmac_get_logical_efuse_size(struct dvobj_priv *d, u32 *size)
  3154. {
  3155. struct halmac_adapter *mac;
  3156. struct halmac_api *api;
  3157. enum halmac_ret_status status;
  3158. u32 val;
  3159. mac = dvobj_to_halmac(d);
  3160. api = HALMAC_GET_API(mac);
  3161. status = api->halmac_get_logical_efuse_size(mac, &val);
  3162. if (HALMAC_RET_SUCCESS != status)
  3163. return -1;
  3164. *size = val;
  3165. return 0;
  3166. }
  3167. int rtw_halmac_read_logical_efuse_map(struct dvobj_priv *d, u8 *map, u32 size, u8 *maskmap, u32 masksize)
  3168. {
  3169. struct halmac_adapter *mac;
  3170. struct halmac_api *api;
  3171. enum halmac_ret_status status;
  3172. enum halmac_feature_id id;
  3173. int ret;
  3174. mac = dvobj_to_halmac(d);
  3175. api = HALMAC_GET_API(mac);
  3176. id = HALMAC_FEATURE_DUMP_LOGICAL_EFUSE;
  3177. ret = init_halmac_event(d, id, map, size);
  3178. if (ret)
  3179. return -1;
  3180. status = api->halmac_dump_logical_efuse_map(mac, HALMAC_EFUSE_R_DRV);
  3181. if (HALMAC_RET_SUCCESS != status) {
  3182. free_halmac_event(d, id);
  3183. return -1;
  3184. }
  3185. ret = wait_halmac_event(d, id);
  3186. if (ret)
  3187. return -1;
  3188. if (maskmap && masksize) {
  3189. struct halmac_pg_efuse_info pginfo;
  3190. pginfo.efuse_map = map;
  3191. pginfo.efuse_map_size = size;
  3192. pginfo.efuse_mask = maskmap;
  3193. pginfo.efuse_mask_size = masksize;
  3194. status = api->halmac_mask_logical_efuse(mac, &pginfo);
  3195. if (status != HALMAC_RET_SUCCESS)
  3196. RTW_WARN("%s: mask logical efuse FAIL!\n", __FUNCTION__);
  3197. }
  3198. return 0;
  3199. }
  3200. int rtw_halmac_write_logical_efuse_map(struct dvobj_priv *d, u8 *map, u32 size, u8 *maskmap, u32 masksize)
  3201. {
  3202. struct halmac_adapter *mac;
  3203. struct halmac_api *api;
  3204. struct halmac_pg_efuse_info pginfo;
  3205. enum halmac_ret_status status;
  3206. mac = dvobj_to_halmac(d);
  3207. api = HALMAC_GET_API(mac);
  3208. pginfo.efuse_map = map;
  3209. pginfo.efuse_map_size = size;
  3210. pginfo.efuse_mask = maskmap;
  3211. pginfo.efuse_mask_size = masksize;
  3212. status = api->halmac_pg_efuse_by_map(mac, &pginfo, HALMAC_EFUSE_R_AUTO);
  3213. if (HALMAC_RET_SUCCESS != status)
  3214. return -1;
  3215. return 0;
  3216. }
  3217. int rtw_halmac_read_logical_efuse(struct dvobj_priv *d, u32 offset, u32 cnt, u8 *data)
  3218. {
  3219. struct halmac_adapter *mac;
  3220. struct halmac_api *api;
  3221. enum halmac_ret_status status;
  3222. u8 v;
  3223. u32 i;
  3224. mac = dvobj_to_halmac(d);
  3225. api = HALMAC_GET_API(mac);
  3226. for (i = 0; i < cnt; i++) {
  3227. status = api->halmac_read_logical_efuse(mac, offset + i, &v);
  3228. if (HALMAC_RET_SUCCESS != status)
  3229. return -1;
  3230. data[i] = v;
  3231. }
  3232. return 0;
  3233. }
  3234. int rtw_halmac_write_logical_efuse(struct dvobj_priv *d, u32 offset, u32 cnt, u8 *data)
  3235. {
  3236. struct halmac_adapter *mac;
  3237. struct halmac_api *api;
  3238. enum halmac_ret_status status;
  3239. u32 i;
  3240. mac = dvobj_to_halmac(d);
  3241. api = HALMAC_GET_API(mac);
  3242. for (i = 0; i < cnt; i++) {
  3243. status = api->halmac_write_logical_efuse(mac, offset + i, data[i]);
  3244. if (HALMAC_RET_SUCCESS != status)
  3245. return -1;
  3246. }
  3247. return 0;
  3248. }
  3249. int rtw_halmac_write_bt_physical_efuse(struct dvobj_priv *d, u32 offset, u32 cnt, u8 *data)
  3250. {
  3251. struct halmac_adapter *mac;
  3252. struct halmac_api *api;
  3253. enum halmac_ret_status status;
  3254. u32 i;
  3255. u8 bank = 1;
  3256. mac = dvobj_to_halmac(d);
  3257. api = HALMAC_GET_API(mac);
  3258. for (i = 0; i < cnt; i++) {
  3259. status = api->halmac_write_efuse_bt(mac, offset + i, data[i], bank);
  3260. if (HALMAC_RET_SUCCESS != status) {
  3261. printk("%s: halmac_write_efuse_bt status = %d\n", __FUNCTION__, status);
  3262. return -1;
  3263. }
  3264. }
  3265. printk("%s: halmac_write_efuse_bt status = HALMAC_RET_SUCCESS %d\n", __FUNCTION__, status);
  3266. return 0;
  3267. }
  3268. int rtw_halmac_read_bt_physical_efuse_map(struct dvobj_priv *d, u8 *map, u32 size)
  3269. {
  3270. struct halmac_adapter *mac;
  3271. struct halmac_api *api;
  3272. enum halmac_ret_status status;
  3273. int bank = 1;
  3274. mac = dvobj_to_halmac(d);
  3275. api = HALMAC_GET_API(mac);
  3276. status = api->halmac_dump_efuse_map_bt(mac, bank, size, map);
  3277. if (HALMAC_RET_SUCCESS != status) {
  3278. printk("%s: halmac_dump_efuse_map_bt fail!\n", __FUNCTION__);
  3279. return -1;
  3280. }
  3281. printk("%s: OK!\n", __FUNCTION__);
  3282. return 0;
  3283. }
  3284. static enum hal_fifo_sel _fifo_sel_drv2halmac(u8 fifo_sel)
  3285. {
  3286. switch (fifo_sel) {
  3287. case 0:
  3288. return HAL_FIFO_SEL_TX;
  3289. case 1:
  3290. return HAL_FIFO_SEL_RX;
  3291. case 2:
  3292. return HAL_FIFO_SEL_RSVD_PAGE;
  3293. case 3:
  3294. return HAL_FIFO_SEL_REPORT;
  3295. case 4:
  3296. return HAL_FIFO_SEL_LLT;
  3297. case 5:
  3298. return HAL_FIFO_SEL_RXBUF_FW;
  3299. }
  3300. return HAL_FIFO_SEL_RSVD_PAGE;
  3301. }
  3302. /*#define CONFIG_HALMAC_FIFO_DUMP*/
  3303. int rtw_halmac_dump_fifo(struct dvobj_priv *d, u8 fifo_sel, u32 addr, u32 size, u8 *buffer)
  3304. {
  3305. struct halmac_adapter *mac;
  3306. struct halmac_api *api;
  3307. enum hal_fifo_sel halmac_fifo_sel;
  3308. enum halmac_ret_status status;
  3309. u8 *pfifo_map = NULL;
  3310. u32 fifo_size = 0;
  3311. s8 ret = 0;/* 0:success, -1:error */
  3312. u8 mem_created = _FALSE;
  3313. mac = dvobj_to_halmac(d);
  3314. api = HALMAC_GET_API(mac);
  3315. if ((size != 0) && (buffer == NULL))
  3316. return -1;
  3317. halmac_fifo_sel = _fifo_sel_drv2halmac(fifo_sel);
  3318. if ((size) && (buffer)) {
  3319. pfifo_map = buffer;
  3320. fifo_size = size;
  3321. } else {
  3322. fifo_size = api->halmac_get_fifo_size(mac, halmac_fifo_sel);
  3323. if (fifo_size)
  3324. pfifo_map = rtw_zvmalloc(fifo_size);
  3325. if (pfifo_map == NULL)
  3326. return -1;
  3327. mem_created = _TRUE;
  3328. }
  3329. status = api->halmac_dump_fifo(mac, halmac_fifo_sel, addr, fifo_size, pfifo_map);
  3330. if (HALMAC_RET_SUCCESS != status) {
  3331. ret = -1;
  3332. goto _exit;
  3333. }
  3334. #ifdef CONFIG_HALMAC_FIFO_DUMP
  3335. {
  3336. static const char * const fifo_sel_str[] = {
  3337. "TX", "RX", "RSVD_PAGE", "REPORT", "LLT", "RXBUF_FW"
  3338. };
  3339. RTW_INFO("%s FIFO DUMP [start_addr:0x%04x , size:%d]\n", fifo_sel_str[halmac_fifo_sel], addr, fifo_size);
  3340. RTW_INFO_DUMP("\n", pfifo_map, fifo_size);
  3341. RTW_INFO(" ==================================================\n");
  3342. }
  3343. #endif /* CONFIG_HALMAC_FIFO_DUMP */
  3344. _exit:
  3345. if ((mem_created == _TRUE) && pfifo_map)
  3346. rtw_vmfree(pfifo_map, fifo_size);
  3347. return ret;
  3348. }
  3349. /*
  3350. * rtw_halmac_rx_agg_switch() - Switch RX aggregation function and setting
  3351. * @d struct dvobj_priv *
  3352. * @enable 0/1 for disable/enable RX aggregation function
  3353. *
  3354. * This function could help to on/off bus RX aggregation function, and is only
  3355. * useful for SDIO and USB interface. Although only "enable" flag is brough in,
  3356. * some setting would be taken from other places, and they are from:
  3357. * [DMA aggregation]
  3358. * struct hal_com_data.rxagg_dma_size
  3359. * struct hal_com_data.rxagg_dma_timeout
  3360. * [USB aggregation] (only use for USB interface)
  3361. * struct hal_com_data.rxagg_usb_size
  3362. * struct hal_com_data.rxagg_usb_timeout
  3363. * If above values of size and timeout are both 0 means driver would not
  3364. * control the threshold setting and leave it to HALMAC handle.
  3365. *
  3366. * From HALMAC V1_04_04, driver force the size threshold be hard limit, and the
  3367. * rx size can not exceed the setting.
  3368. *
  3369. * Return 0 for success, otherwise fail.
  3370. */
  3371. int rtw_halmac_rx_agg_switch(struct dvobj_priv *d, u8 enable)
  3372. {
  3373. struct _ADAPTER *adapter;
  3374. struct hal_com_data *hal;
  3375. struct halmac_adapter *halmac;
  3376. struct halmac_api *api;
  3377. struct halmac_rxagg_cfg rxaggcfg;
  3378. enum halmac_ret_status status;
  3379. adapter = dvobj_get_primary_adapter(d);
  3380. hal = GET_HAL_DATA(adapter);
  3381. halmac = dvobj_to_halmac(d);
  3382. api = HALMAC_GET_API(halmac);
  3383. _rtw_memset((void *)&rxaggcfg, 0, sizeof(rxaggcfg));
  3384. rxaggcfg.mode = HALMAC_RX_AGG_MODE_NONE;
  3385. /*
  3386. * Always enable size limit to avoid rx size exceed
  3387. * driver defined size.
  3388. */
  3389. rxaggcfg.threshold.size_limit_en = 1;
  3390. #ifdef RTW_RX_AGGREGATION
  3391. if (_TRUE == enable) {
  3392. #ifdef CONFIG_SDIO_HCI
  3393. rxaggcfg.mode = HALMAC_RX_AGG_MODE_DMA;
  3394. rxaggcfg.threshold.drv_define = 0;
  3395. if (hal->rxagg_dma_size || hal->rxagg_dma_timeout) {
  3396. rxaggcfg.threshold.drv_define = 1;
  3397. rxaggcfg.threshold.timeout = hal->rxagg_dma_timeout;
  3398. rxaggcfg.threshold.size = hal->rxagg_dma_size;
  3399. RTW_INFO("%s: RX aggregation threshold: "
  3400. "timeout=%u size=%u\n",
  3401. __FUNCTION__,
  3402. hal->rxagg_dma_timeout,
  3403. hal->rxagg_dma_size);
  3404. }
  3405. #elif defined(CONFIG_USB_HCI)
  3406. switch (hal->rxagg_mode) {
  3407. case RX_AGG_DISABLE:
  3408. rxaggcfg.mode = HALMAC_RX_AGG_MODE_NONE;
  3409. break;
  3410. case RX_AGG_DMA:
  3411. rxaggcfg.mode = HALMAC_RX_AGG_MODE_DMA;
  3412. if (hal->rxagg_dma_size || hal->rxagg_dma_timeout) {
  3413. rxaggcfg.threshold.drv_define = 1;
  3414. rxaggcfg.threshold.timeout = hal->rxagg_dma_timeout;
  3415. rxaggcfg.threshold.size = hal->rxagg_dma_size;
  3416. }
  3417. break;
  3418. case RX_AGG_USB:
  3419. case RX_AGG_MIX:
  3420. rxaggcfg.mode = HALMAC_RX_AGG_MODE_USB;
  3421. if (hal->rxagg_usb_size || hal->rxagg_usb_timeout) {
  3422. rxaggcfg.threshold.drv_define = 1;
  3423. rxaggcfg.threshold.timeout = hal->rxagg_usb_timeout;
  3424. rxaggcfg.threshold.size = hal->rxagg_usb_size;
  3425. }
  3426. break;
  3427. }
  3428. #endif /* CONFIG_USB_HCI */
  3429. }
  3430. #endif /* RTW_RX_AGGREGATION */
  3431. status = api->halmac_cfg_rx_aggregation(halmac, &rxaggcfg);
  3432. if (status != HALMAC_RET_SUCCESS)
  3433. return -1;
  3434. return 0;
  3435. }
  3436. int rtw_halmac_download_rsvd_page(struct dvobj_priv *dvobj, u8 pg_offset, u8 *pbuf, u32 size)
  3437. {
  3438. enum halmac_ret_status status = HALMAC_RET_SUCCESS;
  3439. struct halmac_adapter *halmac = dvobj_to_halmac(dvobj);
  3440. struct halmac_api *api = HALMAC_GET_API(halmac);
  3441. status = api->halmac_dl_drv_rsvd_page(halmac, pg_offset, pbuf, size);
  3442. if (status != HALMAC_RET_SUCCESS)
  3443. return -1;
  3444. return 0;
  3445. }
  3446. /*
  3447. * Description
  3448. * Fill following spec info from HALMAC API:
  3449. * sec_cam_ent_num
  3450. *
  3451. * Return
  3452. * 0 Success
  3453. * others Fail
  3454. */
  3455. int rtw_halmac_fill_hal_spec(struct dvobj_priv *dvobj, struct hal_spec_t *spec)
  3456. {
  3457. enum halmac_ret_status status;
  3458. struct halmac_adapter *halmac;
  3459. struct halmac_api *api;
  3460. u8 cam = 0; /* Security Cam Entry Number */
  3461. halmac = dvobj_to_halmac(dvobj);
  3462. api = HALMAC_GET_API(halmac);
  3463. /* Prepare data from HALMAC */
  3464. status = api->halmac_get_hw_value(halmac, HALMAC_HW_CAM_ENTRY_NUM, &cam);
  3465. if (status != HALMAC_RET_SUCCESS)
  3466. return -1;
  3467. /* Fill data to hal_spec_t */
  3468. spec->sec_cam_ent_num = cam;
  3469. return 0;
  3470. }
  3471. int rtw_halmac_p2pps(struct dvobj_priv *dvobj, struct hal_p2p_ps_para *pp2p_ps_para)
  3472. {
  3473. enum halmac_ret_status status = HALMAC_RET_SUCCESS;
  3474. struct halmac_adapter *halmac = dvobj_to_halmac(dvobj);
  3475. struct halmac_api *api = HALMAC_GET_API(halmac);
  3476. struct halmac_p2pps halmac_p2p_ps;
  3477. (&halmac_p2p_ps)->offload_en = pp2p_ps_para->offload_en;
  3478. (&halmac_p2p_ps)->role = pp2p_ps_para->role;
  3479. (&halmac_p2p_ps)->ctwindow_en = pp2p_ps_para->ctwindow_en;
  3480. (&halmac_p2p_ps)->noa_en = pp2p_ps_para->noa_en;
  3481. (&halmac_p2p_ps)->noa_sel = pp2p_ps_para->noa_sel;
  3482. (&halmac_p2p_ps)->all_sta_sleep = pp2p_ps_para->all_sta_sleep;
  3483. (&halmac_p2p_ps)->discovery = pp2p_ps_para->discovery;
  3484. (&halmac_p2p_ps)->p2p_port_id = _hw_port_drv2halmac(pp2p_ps_para->p2p_port_id);
  3485. (&halmac_p2p_ps)->p2p_group = pp2p_ps_para->p2p_group;
  3486. (&halmac_p2p_ps)->p2p_macid = pp2p_ps_para->p2p_macid;
  3487. (&halmac_p2p_ps)->ctwindow_length = pp2p_ps_para->ctwindow_length;
  3488. (&halmac_p2p_ps)->noa_duration_para = pp2p_ps_para->noa_duration_para;
  3489. (&halmac_p2p_ps)->noa_interval_para = pp2p_ps_para->noa_interval_para;
  3490. (&halmac_p2p_ps)->noa_start_time_para = pp2p_ps_para->noa_start_time_para;
  3491. (&halmac_p2p_ps)->noa_count_para = pp2p_ps_para->noa_count_para;
  3492. status = api->halmac_p2pps(halmac, (&halmac_p2p_ps));
  3493. if (status != HALMAC_RET_SUCCESS)
  3494. return -1;
  3495. return 0;
  3496. }
  3497. /**
  3498. * rtw_halmac_iqk() - Run IQ Calibration
  3499. * @d: struct dvobj_priv*
  3500. * @clear: IQK parameters
  3501. * @segment: IQK parameters
  3502. *
  3503. * Process IQ Calibration(IQK).
  3504. *
  3505. * Rteurn: 0 for OK, otherwise fail.
  3506. */
  3507. int rtw_halmac_iqk(struct dvobj_priv *d, u8 clear, u8 segment)
  3508. {
  3509. struct halmac_adapter *mac;
  3510. struct halmac_api *api;
  3511. enum halmac_ret_status status;
  3512. enum halmac_feature_id id;
  3513. struct halmac_iqk_para para;
  3514. int ret;
  3515. u8 retry = 3;
  3516. u8 delay = 1; /* ms */
  3517. mac = dvobj_to_halmac(d);
  3518. api = HALMAC_GET_API(mac);
  3519. id = HALMAC_FEATURE_IQK;
  3520. ret = init_halmac_event(d, id, NULL, 0);
  3521. if (ret)
  3522. return -1;
  3523. para.clear = clear;
  3524. para.segment_iqk = segment;
  3525. do {
  3526. status = api->halmac_start_iqk(mac, &para);
  3527. if (status != HALMAC_RET_BUSY_STATE)
  3528. break;
  3529. RTW_WARN("%s: Fail to start IQK, status is BUSY! retry=%d\n", __FUNCTION__, retry);
  3530. if (!retry)
  3531. break;
  3532. retry--;
  3533. rtw_msleep_os(delay);
  3534. } while (1);
  3535. if (status != HALMAC_RET_SUCCESS) {
  3536. free_halmac_event(d, id);
  3537. return -1;
  3538. }
  3539. ret = wait_halmac_event(d, id);
  3540. if (ret)
  3541. return -1;
  3542. return 0;
  3543. }
  3544. static inline u32 _phy_parameter_val_drv2halmac(u32 val, u8 msk_en, u32 msk)
  3545. {
  3546. if (!msk_en)
  3547. return val;
  3548. return (val << bitshift(msk));
  3549. }
  3550. static int _phy_parameter_drv2halmac(struct rtw_phy_parameter *para, struct halmac_phy_parameter_info *info)
  3551. {
  3552. if (!para || !info)
  3553. return -1;
  3554. _rtw_memset(info, 0, sizeof(*info));
  3555. switch (para->cmd) {
  3556. case 0:
  3557. /* MAC register */
  3558. switch (para->data.mac.size) {
  3559. case 1:
  3560. info->cmd_id = HALMAC_PARAMETER_CMD_MAC_W8;
  3561. break;
  3562. case 2:
  3563. info->cmd_id = HALMAC_PARAMETER_CMD_MAC_W16;
  3564. break;
  3565. default:
  3566. info->cmd_id = HALMAC_PARAMETER_CMD_MAC_W32;
  3567. break;
  3568. }
  3569. info->content.MAC_REG_W.value = _phy_parameter_val_drv2halmac(
  3570. para->data.mac.value,
  3571. para->data.mac.msk_en,
  3572. para->data.mac.msk);
  3573. info->content.MAC_REG_W.msk = para->data.mac.msk;
  3574. info->content.MAC_REG_W.offset = para->data.mac.offset;
  3575. info->content.MAC_REG_W.msk_en = para->data.mac.msk_en;
  3576. break;
  3577. case 1:
  3578. /* BB register */
  3579. switch (para->data.bb.size) {
  3580. case 1:
  3581. info->cmd_id = HALMAC_PARAMETER_CMD_BB_W8;
  3582. break;
  3583. case 2:
  3584. info->cmd_id = HALMAC_PARAMETER_CMD_BB_W16;
  3585. break;
  3586. default:
  3587. info->cmd_id = HALMAC_PARAMETER_CMD_BB_W32;
  3588. break;
  3589. }
  3590. info->content.BB_REG_W.value = _phy_parameter_val_drv2halmac(
  3591. para->data.bb.value,
  3592. para->data.bb.msk_en,
  3593. para->data.bb.msk);
  3594. info->content.BB_REG_W.msk = para->data.bb.msk;
  3595. info->content.BB_REG_W.offset = para->data.bb.offset;
  3596. info->content.BB_REG_W.msk_en = para->data.bb.msk_en;
  3597. break;
  3598. case 2:
  3599. /* RF register */
  3600. info->cmd_id = HALMAC_PARAMETER_CMD_RF_W;
  3601. info->content.RF_REG_W.value = _phy_parameter_val_drv2halmac(
  3602. para->data.rf.value,
  3603. para->data.rf.msk_en,
  3604. para->data.rf.msk);
  3605. info->content.RF_REG_W.msk = para->data.rf.msk;
  3606. info->content.RF_REG_W.offset = para->data.rf.offset;
  3607. info->content.RF_REG_W.msk_en = para->data.rf.msk_en;
  3608. info->content.RF_REG_W.rf_path = para->data.rf.path;
  3609. break;
  3610. case 3:
  3611. /* Delay register */
  3612. if (para->data.delay.unit == 0)
  3613. info->cmd_id = HALMAC_PARAMETER_CMD_DELAY_US;
  3614. else
  3615. info->cmd_id = HALMAC_PARAMETER_CMD_DELAY_MS;
  3616. info->content.DELAY_TIME.delay_time = para->data.delay.value;
  3617. break;
  3618. case 0xFF:
  3619. /* Latest(End) command */
  3620. info->cmd_id = HALMAC_PARAMETER_CMD_END;
  3621. break;
  3622. default:
  3623. return -1;
  3624. }
  3625. return 0;
  3626. }
  3627. /**
  3628. * rtw_halmac_cfg_phy_para() - Register(Phy parameter) configuration
  3629. * @d: struct dvobj_priv*
  3630. * @para: phy parameter
  3631. *
  3632. * Configure registers by firmware using H2C/C2H mechanism.
  3633. * The latest command should be para->cmd==0xFF(End command) to finish all
  3634. * processes.
  3635. *
  3636. * Return: 0 for OK, otherwise fail.
  3637. */
  3638. int rtw_halmac_cfg_phy_para(struct dvobj_priv *d, struct rtw_phy_parameter *para)
  3639. {
  3640. struct halmac_adapter *mac;
  3641. struct halmac_api *api;
  3642. enum halmac_ret_status status;
  3643. enum halmac_feature_id id;
  3644. struct halmac_phy_parameter_info info;
  3645. u8 full_fifo;
  3646. int err, ret;
  3647. mac = dvobj_to_halmac(d);
  3648. api = HALMAC_GET_API(mac);
  3649. id = HALMAC_FEATURE_CFG_PARA;
  3650. full_fifo = 1; /* ToDo: How to deciede? */
  3651. ret = 0;
  3652. err = _phy_parameter_drv2halmac(para, &info);
  3653. if (err)
  3654. return -1;
  3655. err = init_halmac_event(d, id, NULL, 0);
  3656. if (err)
  3657. return -1;
  3658. status = api->halmac_cfg_parameter(mac, &info, full_fifo);
  3659. if (info.cmd_id == HALMAC_PARAMETER_CMD_END) {
  3660. if (status == HALMAC_RET_SUCCESS) {
  3661. err = wait_halmac_event(d, id);
  3662. if (err)
  3663. ret = -1;
  3664. } else {
  3665. free_halmac_event(d, id);
  3666. ret = -1;
  3667. RTW_ERR("%s: Fail to send END of cfg parameter, status is 0x%x!\n", __FUNCTION__, status);
  3668. }
  3669. } else {
  3670. if (status == HALMAC_RET_PARA_SENDING) {
  3671. err = wait_halmac_event(d, id);
  3672. if (err)
  3673. ret = -1;
  3674. } else {
  3675. free_halmac_event(d, id);
  3676. if (status != HALMAC_RET_SUCCESS) {
  3677. ret = -1;
  3678. RTW_ERR("%s: Fail to cfg parameter, status is 0x%x!\n", __FUNCTION__, status);
  3679. }
  3680. }
  3681. }
  3682. return ret;
  3683. }
  3684. static enum halmac_wlled_mode _led_mode_drv2halmac(u8 drv_mode)
  3685. {
  3686. enum halmac_wlled_mode halmac_mode;
  3687. switch (drv_mode) {
  3688. case 1:
  3689. halmac_mode = HALMAC_WLLED_MODE_TX;
  3690. break;
  3691. case 2:
  3692. halmac_mode = HALMAC_WLLED_MODE_RX;
  3693. break;
  3694. case 3:
  3695. halmac_mode = HALMAC_WLLED_MODE_SW_CTRL;
  3696. break;
  3697. case 0:
  3698. default:
  3699. halmac_mode = HALMAC_WLLED_MODE_TRX;
  3700. break;
  3701. }
  3702. return halmac_mode;
  3703. }
  3704. /**
  3705. * rtw_halmac_led_cfg() - Configure Hardware LED Mode
  3706. * @d: struct dvobj_priv*
  3707. * @enable: enable or disable LED function
  3708. * 0: disable
  3709. * 1: enable
  3710. * @mode: WLan LED mode (valid when enable==1)
  3711. * 0: Blink when TX(transmit packet) and RX(receive packet)
  3712. * 1: Blink when TX only
  3713. * 2: Blink when RX only
  3714. * 3: Software control
  3715. *
  3716. * Configure hardware WLan LED mode.
  3717. * If want to change LED mode after enabled, need to disable LED first and
  3718. * enable again to set new mode.
  3719. *
  3720. * Rteurn 0 for OK, otherwise fail.
  3721. */
  3722. int rtw_halmac_led_cfg(struct dvobj_priv *d, u8 enable, u8 mode)
  3723. {
  3724. struct halmac_adapter *halmac;
  3725. struct halmac_api *api;
  3726. enum halmac_wlled_mode led_mode;
  3727. enum halmac_ret_status status;
  3728. halmac = dvobj_to_halmac(d);
  3729. api = HALMAC_GET_API(halmac);
  3730. if (enable) {
  3731. status = api->halmac_pinmux_set_func(halmac,
  3732. HALMAC_GPIO_FUNC_WL_LED);
  3733. if (status != HALMAC_RET_SUCCESS) {
  3734. RTW_ERR("%s: pinmux set fail!(0x%x)\n",
  3735. __FUNCTION__, status);
  3736. return -1;
  3737. }
  3738. led_mode = _led_mode_drv2halmac(mode);
  3739. status = api->halmac_pinmux_wl_led_mode(halmac, led_mode);
  3740. if (status != HALMAC_RET_SUCCESS) {
  3741. RTW_ERR("%s: mode set fail!(0x%x)\n",
  3742. __FUNCTION__, status);
  3743. return -1;
  3744. }
  3745. } else {
  3746. /* Change LED to software control and turn off */
  3747. api->halmac_pinmux_wl_led_mode(halmac,
  3748. HALMAC_WLLED_MODE_SW_CTRL);
  3749. api->halmac_pinmux_wl_led_sw_ctrl(halmac, 0);
  3750. status = api->halmac_pinmux_free_func(halmac,
  3751. HALMAC_GPIO_FUNC_WL_LED);
  3752. if (status != HALMAC_RET_SUCCESS) {
  3753. RTW_ERR("%s: pinmux free fail!(0x%x)\n",
  3754. __FUNCTION__, status);
  3755. return -1;
  3756. }
  3757. }
  3758. return 0;
  3759. }
  3760. /**
  3761. * rtw_halmac_led_switch() - Turn Hardware LED on/off
  3762. * @d: struct dvobj_priv*
  3763. * @on: LED light or not
  3764. * 0: Off
  3765. * 1: On(Light)
  3766. *
  3767. * Turn Hardware WLan LED On/Off.
  3768. * Before use this function, user should call rtw_halmac_led_ctrl() to switch
  3769. * mode to "software control(3)" first, otherwise control would fail.
  3770. * The interval between on and off must be longer than 1 ms, or the LED would
  3771. * keep light or dark only.
  3772. * Ex. Turn off LED at first, turn on after 0.5ms and turn off again after
  3773. * 0.5ms. The LED during this flow will only keep dark, and miss the turn on
  3774. * operation between two turn off operations.
  3775. */
  3776. void rtw_halmac_led_switch(struct dvobj_priv *d, u8 on)
  3777. {
  3778. struct halmac_adapter *halmac;
  3779. struct halmac_api *api;
  3780. halmac = dvobj_to_halmac(d);
  3781. api = HALMAC_GET_API(halmac);
  3782. api->halmac_pinmux_wl_led_sw_ctrl(halmac, on);
  3783. }
  3784. #ifdef CONFIG_SDIO_HCI
  3785. /*
  3786. * Description:
  3787. * Update queue allocated page number to driver
  3788. *
  3789. * Parameter:
  3790. * d pointer to struct dvobj_priv of driver
  3791. *
  3792. * Rteurn:
  3793. * 0 Success, "page" is valid.
  3794. * others Fail, "page" is invalid.
  3795. */
  3796. int rtw_halmac_query_tx_page_num(struct dvobj_priv *d)
  3797. {
  3798. PADAPTER adapter;
  3799. struct halmacpriv *hmpriv;
  3800. struct halmac_adapter *halmac;
  3801. struct halmac_api *api;
  3802. struct halmac_rqpn_map rqpn;
  3803. enum halmac_dma_mapping dmaqueue;
  3804. struct halmac_txff_allocation fifosize;
  3805. enum halmac_ret_status status;
  3806. u8 i;
  3807. adapter = dvobj_get_primary_adapter(d);
  3808. hmpriv = &d->hmpriv;
  3809. halmac = dvobj_to_halmac(d);
  3810. api = HALMAC_GET_API(halmac);
  3811. _rtw_memset((void *)&rqpn, 0, sizeof(rqpn));
  3812. _rtw_memset((void *)&fifosize, 0, sizeof(fifosize));
  3813. status = api->halmac_get_hw_value(halmac, HALMAC_HW_RQPN_MAPPING, &rqpn);
  3814. if (status != HALMAC_RET_SUCCESS)
  3815. return -1;
  3816. status = api->halmac_get_hw_value(halmac, HALMAC_HW_TXFF_ALLOCATION, &fifosize);
  3817. if (status != HALMAC_RET_SUCCESS)
  3818. return -1;
  3819. for (i = 0; i < HW_QUEUE_ENTRY; i++) {
  3820. hmpriv->txpage[i] = 0;
  3821. /* Driver index mapping to HALMAC DMA queue */
  3822. dmaqueue = HALMAC_DMA_MAPPING_UNDEFINE;
  3823. switch (i) {
  3824. case VO_QUEUE_INX:
  3825. dmaqueue = rqpn.dma_map_vo;
  3826. break;
  3827. case VI_QUEUE_INX:
  3828. dmaqueue = rqpn.dma_map_vi;
  3829. break;
  3830. case BE_QUEUE_INX:
  3831. dmaqueue = rqpn.dma_map_be;
  3832. break;
  3833. case BK_QUEUE_INX:
  3834. dmaqueue = rqpn.dma_map_bk;
  3835. break;
  3836. case MGT_QUEUE_INX:
  3837. dmaqueue = rqpn.dma_map_mg;
  3838. break;
  3839. case HIGH_QUEUE_INX:
  3840. dmaqueue = rqpn.dma_map_hi;
  3841. break;
  3842. case BCN_QUEUE_INX:
  3843. case TXCMD_QUEUE_INX:
  3844. /* Unlimited */
  3845. hmpriv->txpage[i] = 0xFFFF;
  3846. continue;
  3847. }
  3848. switch (dmaqueue) {
  3849. case HALMAC_DMA_MAPPING_EXTRA:
  3850. hmpriv->txpage[i] = fifosize.extra_queue_pg_num;
  3851. break;
  3852. case HALMAC_DMA_MAPPING_LOW:
  3853. hmpriv->txpage[i] = fifosize.low_queue_pg_num;
  3854. break;
  3855. case HALMAC_DMA_MAPPING_NORMAL:
  3856. hmpriv->txpage[i] = fifosize.normal_queue_pg_num;
  3857. break;
  3858. case HALMAC_DMA_MAPPING_HIGH:
  3859. hmpriv->txpage[i] = fifosize.high_queue_pg_num;
  3860. break;
  3861. case HALMAC_DMA_MAPPING_UNDEFINE:
  3862. break;
  3863. }
  3864. hmpriv->txpage[i] += fifosize.pub_queue_pg_num;
  3865. }
  3866. return 0;
  3867. }
  3868. /*
  3869. * Description:
  3870. * Get specific queue allocated page number
  3871. *
  3872. * Parameter:
  3873. * d pointer to struct dvobj_priv of driver
  3874. * queue target queue to query, VO/VI/BE/BK/.../TXCMD_QUEUE_INX
  3875. * page return allocated page number
  3876. *
  3877. * Rteurn:
  3878. * 0 Success, "page" is valid.
  3879. * others Fail, "page" is invalid.
  3880. */
  3881. int rtw_halmac_get_tx_queue_page_num(struct dvobj_priv *d, u8 queue, u32 *page)
  3882. {
  3883. *page = 0;
  3884. if (queue < HW_QUEUE_ENTRY)
  3885. *page = d->hmpriv.txpage[queue];
  3886. return 0;
  3887. }
  3888. /*
  3889. * Return:
  3890. * address for SDIO command
  3891. */
  3892. u32 rtw_halmac_sdio_get_tx_addr(struct dvobj_priv *d, u8 *desc, u32 size)
  3893. {
  3894. struct halmac_adapter *mac;
  3895. struct halmac_api *api;
  3896. enum halmac_ret_status status;
  3897. u32 addr;
  3898. mac = dvobj_to_halmac(d);
  3899. api = HALMAC_GET_API(mac);
  3900. status = api->halmac_get_sdio_tx_addr(mac, desc, size, &addr);
  3901. if (HALMAC_RET_SUCCESS != status)
  3902. return 0;
  3903. return addr;
  3904. }
  3905. int rtw_halmac_sdio_tx_allowed(struct dvobj_priv *d, u8 *buf, u32 size)
  3906. {
  3907. struct halmac_adapter *mac;
  3908. struct halmac_api *api;
  3909. enum halmac_ret_status status;
  3910. mac = dvobj_to_halmac(d);
  3911. api = HALMAC_GET_API(mac);
  3912. status = api->halmac_tx_allowed_sdio(mac, buf, size);
  3913. if (HALMAC_RET_SUCCESS != status)
  3914. return -1;
  3915. return 0;
  3916. }
  3917. u32 rtw_halmac_sdio_get_rx_addr(struct dvobj_priv *d, u8 *seq)
  3918. {
  3919. u8 id;
  3920. #define RTW_SDIO_ADDR_RX_RX0FF_PRFIX 0x0E000
  3921. #define RTW_SDIO_ADDR_RX_RX0FF_GEN(a) (RTW_SDIO_ADDR_RX_RX0FF_PRFIX|(a&0x3))
  3922. id = *seq;
  3923. (*seq)++;
  3924. return RTW_SDIO_ADDR_RX_RX0FF_GEN(id);
  3925. }
  3926. #endif /* CONFIG_SDIO_HCI */
  3927. #ifdef CONFIG_USB_HCI
  3928. u8 rtw_halmac_usb_get_bulkout_id(struct dvobj_priv *d, u8 *buf, u32 size)
  3929. {
  3930. struct halmac_adapter *mac;
  3931. struct halmac_api *api;
  3932. enum halmac_ret_status status;
  3933. u8 bulkout_id;
  3934. mac = dvobj_to_halmac(d);
  3935. api = HALMAC_GET_API(mac);
  3936. status = api->halmac_get_usb_bulkout_id(mac, buf, size, &bulkout_id);
  3937. if (HALMAC_RET_SUCCESS != status)
  3938. return 0;
  3939. return bulkout_id;
  3940. }
  3941. /**
  3942. * rtw_halmac_usb_get_txagg_desc_num() - MAX descriptor number in one bulk for TX
  3943. * @d: struct dvobj_priv*
  3944. * @size: TX FIFO size, unit is byte.
  3945. *
  3946. * Get MAX descriptor number in one bulk out from HALMAC.
  3947. *
  3948. * Rteurn 0 for OK, otherwise fail.
  3949. */
  3950. int rtw_halmac_usb_get_txagg_desc_num(struct dvobj_priv *d, u8 *num)
  3951. {
  3952. struct halmac_adapter *halmac;
  3953. struct halmac_api *api;
  3954. enum halmac_ret_status status;
  3955. u8 val = 0;
  3956. halmac = dvobj_to_halmac(d);
  3957. api = HALMAC_GET_API(halmac);
  3958. status = api->halmac_get_hw_value(halmac, HALMAC_HW_USB_TXAGG_DESC_NUM, &val);
  3959. if (status != HALMAC_RET_SUCCESS)
  3960. return -1;
  3961. *num = val;
  3962. return 0;
  3963. }
  3964. static inline enum halmac_usb_mode _usb_mode_drv2halmac(enum RTW_USB_SPEED usb_mode)
  3965. {
  3966. enum halmac_usb_mode halmac_usb_mode = HALMAC_USB_MODE_U2;
  3967. switch (usb_mode) {
  3968. case RTW_USB_SPEED_2:
  3969. halmac_usb_mode = HALMAC_USB_MODE_U2;
  3970. break;
  3971. case RTW_USB_SPEED_3:
  3972. halmac_usb_mode = HALMAC_USB_MODE_U3;
  3973. break;
  3974. default:
  3975. halmac_usb_mode = HALMAC_USB_MODE_U2;
  3976. break;
  3977. }
  3978. return halmac_usb_mode;
  3979. }
  3980. u8 rtw_halmac_switch_usb_mode(struct dvobj_priv *d, enum RTW_USB_SPEED usb_mode)
  3981. {
  3982. PADAPTER adapter;
  3983. struct halmac_adapter *mac;
  3984. struct halmac_api *api;
  3985. enum halmac_ret_status status;
  3986. enum halmac_usb_mode halmac_usb_mode;
  3987. adapter = dvobj_get_primary_adapter(d);
  3988. mac = dvobj_to_halmac(d);
  3989. api = HALMAC_GET_API(mac);
  3990. halmac_usb_mode = _usb_mode_drv2halmac(usb_mode);
  3991. status = api->halmac_set_hw_value(mac, HALMAC_HW_USB_MODE, (void *)&halmac_usb_mode);
  3992. if (HALMAC_RET_SUCCESS != status)
  3993. return _FAIL;
  3994. return _SUCCESS;
  3995. }
  3996. #endif /* CONFIG_USB_HCI */
  3997. #ifdef CONFIG_BEAMFORMING
  3998. #ifdef RTW_BEAMFORMING_VERSION_2
  3999. int rtw_halmac_bf_add_mu_bfer(struct dvobj_priv *d, u16 paid, u16 csi_para,
  4000. u16 my_aid, enum halmac_csi_seg_len sel, u8 *addr)
  4001. {
  4002. struct halmac_adapter *mac;
  4003. struct halmac_api *api;
  4004. enum halmac_ret_status status;
  4005. struct halmac_mu_bfer_init_para param;
  4006. mac = dvobj_to_halmac(d);
  4007. api = HALMAC_GET_API(mac);
  4008. _rtw_memset(&param, 0, sizeof(param));
  4009. param.paid = paid;
  4010. param.csi_para = csi_para;
  4011. param.my_aid = my_aid;
  4012. param.csi_length_sel = sel;
  4013. _rtw_memcpy(param.bfer_address.addr, addr, 6);
  4014. status = api->halmac_mu_bfer_entry_init(mac, &param);
  4015. if (status != HALMAC_RET_SUCCESS)
  4016. return -1;
  4017. return 0;
  4018. }
  4019. int rtw_halmac_bf_del_mu_bfer(struct dvobj_priv *d)
  4020. {
  4021. struct halmac_adapter *mac;
  4022. struct halmac_api *api;
  4023. enum halmac_ret_status status;
  4024. mac = dvobj_to_halmac(d);
  4025. api = HALMAC_GET_API(mac);
  4026. status = api->halmac_mu_bfer_entry_del(mac);
  4027. if (status != HALMAC_RET_SUCCESS)
  4028. return -1;
  4029. return 0;
  4030. }
  4031. int rtw_halmac_bf_cfg_sounding(struct dvobj_priv *d,
  4032. enum halmac_snd_role role, enum halmac_data_rate rate)
  4033. {
  4034. struct halmac_adapter *mac;
  4035. struct halmac_api *api;
  4036. enum halmac_ret_status status;
  4037. mac = dvobj_to_halmac(d);
  4038. api = HALMAC_GET_API(mac);
  4039. status = api->halmac_cfg_sounding(mac, role, rate);
  4040. if (status != HALMAC_RET_SUCCESS)
  4041. return -1;
  4042. return 0;
  4043. }
  4044. int rtw_halmac_bf_del_sounding(struct dvobj_priv *d,
  4045. enum halmac_snd_role role)
  4046. {
  4047. struct halmac_adapter *mac;
  4048. struct halmac_api *api;
  4049. enum halmac_ret_status status;
  4050. mac = dvobj_to_halmac(d);
  4051. api = HALMAC_GET_API(mac);
  4052. status = api->halmac_del_sounding(mac, role);
  4053. if (status != HALMAC_RET_SUCCESS)
  4054. return -1;
  4055. return 0;
  4056. }
  4057. int rtw_halmac_bf_cfg_csi_rate(struct dvobj_priv *d,
  4058. u8 rssi, u8 current_rate, u8 fixrate_en,
  4059. u8 *new_rate)
  4060. {
  4061. struct halmac_adapter *mac;
  4062. struct halmac_api *api;
  4063. enum halmac_ret_status status;
  4064. mac = dvobj_to_halmac(d);
  4065. api = HALMAC_GET_API(mac);
  4066. status = api->halmac_cfg_csi_rate(mac,
  4067. rssi, current_rate, fixrate_en, new_rate);
  4068. if (status != HALMAC_RET_SUCCESS)
  4069. return -1;
  4070. return 0;
  4071. }
  4072. int rtw_halmac_bf_cfg_mu_mimo(struct dvobj_priv *d, enum halmac_snd_role role,
  4073. u8 *sounding_sts, u16 grouping_bitmap, u8 mu_tx_en,
  4074. u32 *given_gid_tab, u32 *given_user_pos)
  4075. {
  4076. struct halmac_adapter *mac;
  4077. struct halmac_api *api;
  4078. enum halmac_ret_status status;
  4079. struct halmac_cfg_mumimo_para param;
  4080. mac = dvobj_to_halmac(d);
  4081. api = HALMAC_GET_API(mac);
  4082. _rtw_memset(&param, 0, sizeof(param));
  4083. param.role = role;
  4084. param.grouping_bitmap = grouping_bitmap;
  4085. param.mu_tx_en = mu_tx_en;
  4086. if (sounding_sts)
  4087. _rtw_memcpy(param.sounding_sts, sounding_sts, 6);
  4088. if (given_gid_tab)
  4089. _rtw_memcpy(param.given_gid_tab, given_gid_tab, 8);
  4090. if (given_user_pos)
  4091. _rtw_memcpy(param.given_user_pos, given_user_pos, 16);
  4092. status = api->halmac_cfg_mumimo(mac, &param);
  4093. if (status != HALMAC_RET_SUCCESS)
  4094. return -1;
  4095. return 0;
  4096. }
  4097. #endif /* RTW_BEAMFORMING_VERSION_2 */
  4098. #endif /* CONFIG_BEAMFORMING */