i40e_common.c 120 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2015 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. * Contact Information:
  22. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. ******************************************************************************/
  26. #include "i40e_type.h"
  27. #include "i40e_adminq.h"
  28. #include "i40e_prototype.h"
  29. #include "i40e_virtchnl.h"
  30. /**
  31. * i40e_set_mac_type - Sets MAC type
  32. * @hw: pointer to the HW structure
  33. *
  34. * This function sets the mac type of the adapter based on the
  35. * vendor ID and device ID stored in the hw structure.
  36. **/
  37. static i40e_status i40e_set_mac_type(struct i40e_hw *hw)
  38. {
  39. i40e_status status = 0;
  40. if (hw->vendor_id == PCI_VENDOR_ID_INTEL) {
  41. switch (hw->device_id) {
  42. case I40E_DEV_ID_SFP_XL710:
  43. case I40E_DEV_ID_QEMU:
  44. case I40E_DEV_ID_KX_A:
  45. case I40E_DEV_ID_KX_B:
  46. case I40E_DEV_ID_KX_C:
  47. case I40E_DEV_ID_QSFP_A:
  48. case I40E_DEV_ID_QSFP_B:
  49. case I40E_DEV_ID_QSFP_C:
  50. case I40E_DEV_ID_10G_BASE_T:
  51. case I40E_DEV_ID_10G_BASE_T4:
  52. case I40E_DEV_ID_20G_KR2:
  53. case I40E_DEV_ID_20G_KR2_A:
  54. hw->mac.type = I40E_MAC_XL710;
  55. break;
  56. case I40E_DEV_ID_SFP_X722:
  57. case I40E_DEV_ID_1G_BASE_T_X722:
  58. case I40E_DEV_ID_10G_BASE_T_X722:
  59. hw->mac.type = I40E_MAC_X722;
  60. break;
  61. case I40E_DEV_ID_X722_VF:
  62. case I40E_DEV_ID_X722_VF_HV:
  63. hw->mac.type = I40E_MAC_X722_VF;
  64. break;
  65. case I40E_DEV_ID_VF:
  66. case I40E_DEV_ID_VF_HV:
  67. hw->mac.type = I40E_MAC_VF;
  68. break;
  69. default:
  70. hw->mac.type = I40E_MAC_GENERIC;
  71. break;
  72. }
  73. } else {
  74. status = I40E_ERR_DEVICE_NOT_SUPPORTED;
  75. }
  76. hw_dbg(hw, "i40e_set_mac_type found mac: %d, returns: %d\n",
  77. hw->mac.type, status);
  78. return status;
  79. }
  80. /**
  81. * i40e_aq_str - convert AQ err code to a string
  82. * @hw: pointer to the HW structure
  83. * @aq_err: the AQ error code to convert
  84. **/
  85. const char *i40e_aq_str(struct i40e_hw *hw, enum i40e_admin_queue_err aq_err)
  86. {
  87. switch (aq_err) {
  88. case I40E_AQ_RC_OK:
  89. return "OK";
  90. case I40E_AQ_RC_EPERM:
  91. return "I40E_AQ_RC_EPERM";
  92. case I40E_AQ_RC_ENOENT:
  93. return "I40E_AQ_RC_ENOENT";
  94. case I40E_AQ_RC_ESRCH:
  95. return "I40E_AQ_RC_ESRCH";
  96. case I40E_AQ_RC_EINTR:
  97. return "I40E_AQ_RC_EINTR";
  98. case I40E_AQ_RC_EIO:
  99. return "I40E_AQ_RC_EIO";
  100. case I40E_AQ_RC_ENXIO:
  101. return "I40E_AQ_RC_ENXIO";
  102. case I40E_AQ_RC_E2BIG:
  103. return "I40E_AQ_RC_E2BIG";
  104. case I40E_AQ_RC_EAGAIN:
  105. return "I40E_AQ_RC_EAGAIN";
  106. case I40E_AQ_RC_ENOMEM:
  107. return "I40E_AQ_RC_ENOMEM";
  108. case I40E_AQ_RC_EACCES:
  109. return "I40E_AQ_RC_EACCES";
  110. case I40E_AQ_RC_EFAULT:
  111. return "I40E_AQ_RC_EFAULT";
  112. case I40E_AQ_RC_EBUSY:
  113. return "I40E_AQ_RC_EBUSY";
  114. case I40E_AQ_RC_EEXIST:
  115. return "I40E_AQ_RC_EEXIST";
  116. case I40E_AQ_RC_EINVAL:
  117. return "I40E_AQ_RC_EINVAL";
  118. case I40E_AQ_RC_ENOTTY:
  119. return "I40E_AQ_RC_ENOTTY";
  120. case I40E_AQ_RC_ENOSPC:
  121. return "I40E_AQ_RC_ENOSPC";
  122. case I40E_AQ_RC_ENOSYS:
  123. return "I40E_AQ_RC_ENOSYS";
  124. case I40E_AQ_RC_ERANGE:
  125. return "I40E_AQ_RC_ERANGE";
  126. case I40E_AQ_RC_EFLUSHED:
  127. return "I40E_AQ_RC_EFLUSHED";
  128. case I40E_AQ_RC_BAD_ADDR:
  129. return "I40E_AQ_RC_BAD_ADDR";
  130. case I40E_AQ_RC_EMODE:
  131. return "I40E_AQ_RC_EMODE";
  132. case I40E_AQ_RC_EFBIG:
  133. return "I40E_AQ_RC_EFBIG";
  134. }
  135. snprintf(hw->err_str, sizeof(hw->err_str), "%d", aq_err);
  136. return hw->err_str;
  137. }
  138. /**
  139. * i40e_stat_str - convert status err code to a string
  140. * @hw: pointer to the HW structure
  141. * @stat_err: the status error code to convert
  142. **/
  143. const char *i40e_stat_str(struct i40e_hw *hw, i40e_status stat_err)
  144. {
  145. switch (stat_err) {
  146. case 0:
  147. return "OK";
  148. case I40E_ERR_NVM:
  149. return "I40E_ERR_NVM";
  150. case I40E_ERR_NVM_CHECKSUM:
  151. return "I40E_ERR_NVM_CHECKSUM";
  152. case I40E_ERR_PHY:
  153. return "I40E_ERR_PHY";
  154. case I40E_ERR_CONFIG:
  155. return "I40E_ERR_CONFIG";
  156. case I40E_ERR_PARAM:
  157. return "I40E_ERR_PARAM";
  158. case I40E_ERR_MAC_TYPE:
  159. return "I40E_ERR_MAC_TYPE";
  160. case I40E_ERR_UNKNOWN_PHY:
  161. return "I40E_ERR_UNKNOWN_PHY";
  162. case I40E_ERR_LINK_SETUP:
  163. return "I40E_ERR_LINK_SETUP";
  164. case I40E_ERR_ADAPTER_STOPPED:
  165. return "I40E_ERR_ADAPTER_STOPPED";
  166. case I40E_ERR_INVALID_MAC_ADDR:
  167. return "I40E_ERR_INVALID_MAC_ADDR";
  168. case I40E_ERR_DEVICE_NOT_SUPPORTED:
  169. return "I40E_ERR_DEVICE_NOT_SUPPORTED";
  170. case I40E_ERR_MASTER_REQUESTS_PENDING:
  171. return "I40E_ERR_MASTER_REQUESTS_PENDING";
  172. case I40E_ERR_INVALID_LINK_SETTINGS:
  173. return "I40E_ERR_INVALID_LINK_SETTINGS";
  174. case I40E_ERR_AUTONEG_NOT_COMPLETE:
  175. return "I40E_ERR_AUTONEG_NOT_COMPLETE";
  176. case I40E_ERR_RESET_FAILED:
  177. return "I40E_ERR_RESET_FAILED";
  178. case I40E_ERR_SWFW_SYNC:
  179. return "I40E_ERR_SWFW_SYNC";
  180. case I40E_ERR_NO_AVAILABLE_VSI:
  181. return "I40E_ERR_NO_AVAILABLE_VSI";
  182. case I40E_ERR_NO_MEMORY:
  183. return "I40E_ERR_NO_MEMORY";
  184. case I40E_ERR_BAD_PTR:
  185. return "I40E_ERR_BAD_PTR";
  186. case I40E_ERR_RING_FULL:
  187. return "I40E_ERR_RING_FULL";
  188. case I40E_ERR_INVALID_PD_ID:
  189. return "I40E_ERR_INVALID_PD_ID";
  190. case I40E_ERR_INVALID_QP_ID:
  191. return "I40E_ERR_INVALID_QP_ID";
  192. case I40E_ERR_INVALID_CQ_ID:
  193. return "I40E_ERR_INVALID_CQ_ID";
  194. case I40E_ERR_INVALID_CEQ_ID:
  195. return "I40E_ERR_INVALID_CEQ_ID";
  196. case I40E_ERR_INVALID_AEQ_ID:
  197. return "I40E_ERR_INVALID_AEQ_ID";
  198. case I40E_ERR_INVALID_SIZE:
  199. return "I40E_ERR_INVALID_SIZE";
  200. case I40E_ERR_INVALID_ARP_INDEX:
  201. return "I40E_ERR_INVALID_ARP_INDEX";
  202. case I40E_ERR_INVALID_FPM_FUNC_ID:
  203. return "I40E_ERR_INVALID_FPM_FUNC_ID";
  204. case I40E_ERR_QP_INVALID_MSG_SIZE:
  205. return "I40E_ERR_QP_INVALID_MSG_SIZE";
  206. case I40E_ERR_QP_TOOMANY_WRS_POSTED:
  207. return "I40E_ERR_QP_TOOMANY_WRS_POSTED";
  208. case I40E_ERR_INVALID_FRAG_COUNT:
  209. return "I40E_ERR_INVALID_FRAG_COUNT";
  210. case I40E_ERR_QUEUE_EMPTY:
  211. return "I40E_ERR_QUEUE_EMPTY";
  212. case I40E_ERR_INVALID_ALIGNMENT:
  213. return "I40E_ERR_INVALID_ALIGNMENT";
  214. case I40E_ERR_FLUSHED_QUEUE:
  215. return "I40E_ERR_FLUSHED_QUEUE";
  216. case I40E_ERR_INVALID_PUSH_PAGE_INDEX:
  217. return "I40E_ERR_INVALID_PUSH_PAGE_INDEX";
  218. case I40E_ERR_INVALID_IMM_DATA_SIZE:
  219. return "I40E_ERR_INVALID_IMM_DATA_SIZE";
  220. case I40E_ERR_TIMEOUT:
  221. return "I40E_ERR_TIMEOUT";
  222. case I40E_ERR_OPCODE_MISMATCH:
  223. return "I40E_ERR_OPCODE_MISMATCH";
  224. case I40E_ERR_CQP_COMPL_ERROR:
  225. return "I40E_ERR_CQP_COMPL_ERROR";
  226. case I40E_ERR_INVALID_VF_ID:
  227. return "I40E_ERR_INVALID_VF_ID";
  228. case I40E_ERR_INVALID_HMCFN_ID:
  229. return "I40E_ERR_INVALID_HMCFN_ID";
  230. case I40E_ERR_BACKING_PAGE_ERROR:
  231. return "I40E_ERR_BACKING_PAGE_ERROR";
  232. case I40E_ERR_NO_PBLCHUNKS_AVAILABLE:
  233. return "I40E_ERR_NO_PBLCHUNKS_AVAILABLE";
  234. case I40E_ERR_INVALID_PBLE_INDEX:
  235. return "I40E_ERR_INVALID_PBLE_INDEX";
  236. case I40E_ERR_INVALID_SD_INDEX:
  237. return "I40E_ERR_INVALID_SD_INDEX";
  238. case I40E_ERR_INVALID_PAGE_DESC_INDEX:
  239. return "I40E_ERR_INVALID_PAGE_DESC_INDEX";
  240. case I40E_ERR_INVALID_SD_TYPE:
  241. return "I40E_ERR_INVALID_SD_TYPE";
  242. case I40E_ERR_MEMCPY_FAILED:
  243. return "I40E_ERR_MEMCPY_FAILED";
  244. case I40E_ERR_INVALID_HMC_OBJ_INDEX:
  245. return "I40E_ERR_INVALID_HMC_OBJ_INDEX";
  246. case I40E_ERR_INVALID_HMC_OBJ_COUNT:
  247. return "I40E_ERR_INVALID_HMC_OBJ_COUNT";
  248. case I40E_ERR_INVALID_SRQ_ARM_LIMIT:
  249. return "I40E_ERR_INVALID_SRQ_ARM_LIMIT";
  250. case I40E_ERR_SRQ_ENABLED:
  251. return "I40E_ERR_SRQ_ENABLED";
  252. case I40E_ERR_ADMIN_QUEUE_ERROR:
  253. return "I40E_ERR_ADMIN_QUEUE_ERROR";
  254. case I40E_ERR_ADMIN_QUEUE_TIMEOUT:
  255. return "I40E_ERR_ADMIN_QUEUE_TIMEOUT";
  256. case I40E_ERR_BUF_TOO_SHORT:
  257. return "I40E_ERR_BUF_TOO_SHORT";
  258. case I40E_ERR_ADMIN_QUEUE_FULL:
  259. return "I40E_ERR_ADMIN_QUEUE_FULL";
  260. case I40E_ERR_ADMIN_QUEUE_NO_WORK:
  261. return "I40E_ERR_ADMIN_QUEUE_NO_WORK";
  262. case I40E_ERR_BAD_IWARP_CQE:
  263. return "I40E_ERR_BAD_IWARP_CQE";
  264. case I40E_ERR_NVM_BLANK_MODE:
  265. return "I40E_ERR_NVM_BLANK_MODE";
  266. case I40E_ERR_NOT_IMPLEMENTED:
  267. return "I40E_ERR_NOT_IMPLEMENTED";
  268. case I40E_ERR_PE_DOORBELL_NOT_ENABLED:
  269. return "I40E_ERR_PE_DOORBELL_NOT_ENABLED";
  270. case I40E_ERR_DIAG_TEST_FAILED:
  271. return "I40E_ERR_DIAG_TEST_FAILED";
  272. case I40E_ERR_NOT_READY:
  273. return "I40E_ERR_NOT_READY";
  274. case I40E_NOT_SUPPORTED:
  275. return "I40E_NOT_SUPPORTED";
  276. case I40E_ERR_FIRMWARE_API_VERSION:
  277. return "I40E_ERR_FIRMWARE_API_VERSION";
  278. }
  279. snprintf(hw->err_str, sizeof(hw->err_str), "%d", stat_err);
  280. return hw->err_str;
  281. }
  282. /**
  283. * i40e_debug_aq
  284. * @hw: debug mask related to admin queue
  285. * @mask: debug mask
  286. * @desc: pointer to admin queue descriptor
  287. * @buffer: pointer to command buffer
  288. * @buf_len: max length of buffer
  289. *
  290. * Dumps debug log about adminq command with descriptor contents.
  291. **/
  292. void i40e_debug_aq(struct i40e_hw *hw, enum i40e_debug_mask mask, void *desc,
  293. void *buffer, u16 buf_len)
  294. {
  295. struct i40e_aq_desc *aq_desc = (struct i40e_aq_desc *)desc;
  296. u16 len = le16_to_cpu(aq_desc->datalen);
  297. u8 *buf = (u8 *)buffer;
  298. u16 i = 0;
  299. if ((!(mask & hw->debug_mask)) || (desc == NULL))
  300. return;
  301. i40e_debug(hw, mask,
  302. "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
  303. le16_to_cpu(aq_desc->opcode),
  304. le16_to_cpu(aq_desc->flags),
  305. le16_to_cpu(aq_desc->datalen),
  306. le16_to_cpu(aq_desc->retval));
  307. i40e_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
  308. le32_to_cpu(aq_desc->cookie_high),
  309. le32_to_cpu(aq_desc->cookie_low));
  310. i40e_debug(hw, mask, "\tparam (0,1) 0x%08X 0x%08X\n",
  311. le32_to_cpu(aq_desc->params.internal.param0),
  312. le32_to_cpu(aq_desc->params.internal.param1));
  313. i40e_debug(hw, mask, "\taddr (h,l) 0x%08X 0x%08X\n",
  314. le32_to_cpu(aq_desc->params.external.addr_high),
  315. le32_to_cpu(aq_desc->params.external.addr_low));
  316. if ((buffer != NULL) && (aq_desc->datalen != 0)) {
  317. i40e_debug(hw, mask, "AQ CMD Buffer:\n");
  318. if (buf_len < len)
  319. len = buf_len;
  320. /* write the full 16-byte chunks */
  321. for (i = 0; i < (len - 16); i += 16)
  322. i40e_debug(hw, mask, "\t0x%04X %16ph\n", i, buf + i);
  323. /* write whatever's left over without overrunning the buffer */
  324. if (i < len)
  325. i40e_debug(hw, mask, "\t0x%04X %*ph\n",
  326. i, len - i, buf + i);
  327. }
  328. }
  329. /**
  330. * i40e_check_asq_alive
  331. * @hw: pointer to the hw struct
  332. *
  333. * Returns true if Queue is enabled else false.
  334. **/
  335. bool i40e_check_asq_alive(struct i40e_hw *hw)
  336. {
  337. if (hw->aq.asq.len)
  338. return !!(rd32(hw, hw->aq.asq.len) &
  339. I40E_PF_ATQLEN_ATQENABLE_MASK);
  340. else
  341. return false;
  342. }
  343. /**
  344. * i40e_aq_queue_shutdown
  345. * @hw: pointer to the hw struct
  346. * @unloading: is the driver unloading itself
  347. *
  348. * Tell the Firmware that we're shutting down the AdminQ and whether
  349. * or not the driver is unloading as well.
  350. **/
  351. i40e_status i40e_aq_queue_shutdown(struct i40e_hw *hw,
  352. bool unloading)
  353. {
  354. struct i40e_aq_desc desc;
  355. struct i40e_aqc_queue_shutdown *cmd =
  356. (struct i40e_aqc_queue_shutdown *)&desc.params.raw;
  357. i40e_status status;
  358. i40e_fill_default_direct_cmd_desc(&desc,
  359. i40e_aqc_opc_queue_shutdown);
  360. if (unloading)
  361. cmd->driver_unloading = cpu_to_le32(I40E_AQ_DRIVER_UNLOADING);
  362. status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
  363. return status;
  364. }
  365. /**
  366. * i40e_aq_get_set_rss_lut
  367. * @hw: pointer to the hardware structure
  368. * @vsi_id: vsi fw index
  369. * @pf_lut: for PF table set true, for VSI table set false
  370. * @lut: pointer to the lut buffer provided by the caller
  371. * @lut_size: size of the lut buffer
  372. * @set: set true to set the table, false to get the table
  373. *
  374. * Internal function to get or set RSS look up table
  375. **/
  376. static i40e_status i40e_aq_get_set_rss_lut(struct i40e_hw *hw,
  377. u16 vsi_id, bool pf_lut,
  378. u8 *lut, u16 lut_size,
  379. bool set)
  380. {
  381. i40e_status status;
  382. struct i40e_aq_desc desc;
  383. struct i40e_aqc_get_set_rss_lut *cmd_resp =
  384. (struct i40e_aqc_get_set_rss_lut *)&desc.params.raw;
  385. if (set)
  386. i40e_fill_default_direct_cmd_desc(&desc,
  387. i40e_aqc_opc_set_rss_lut);
  388. else
  389. i40e_fill_default_direct_cmd_desc(&desc,
  390. i40e_aqc_opc_get_rss_lut);
  391. /* Indirect command */
  392. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  393. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
  394. cmd_resp->vsi_id =
  395. cpu_to_le16((u16)((vsi_id <<
  396. I40E_AQC_SET_RSS_LUT_VSI_ID_SHIFT) &
  397. I40E_AQC_SET_RSS_LUT_VSI_ID_MASK));
  398. cmd_resp->vsi_id |= cpu_to_le16((u16)I40E_AQC_SET_RSS_LUT_VSI_VALID);
  399. if (pf_lut)
  400. cmd_resp->flags |= cpu_to_le16((u16)
  401. ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_PF <<
  402. I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
  403. I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
  404. else
  405. cmd_resp->flags |= cpu_to_le16((u16)
  406. ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_VSI <<
  407. I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
  408. I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
  409. status = i40e_asq_send_command(hw, &desc, lut, lut_size, NULL);
  410. return status;
  411. }
  412. /**
  413. * i40e_aq_get_rss_lut
  414. * @hw: pointer to the hardware structure
  415. * @vsi_id: vsi fw index
  416. * @pf_lut: for PF table set true, for VSI table set false
  417. * @lut: pointer to the lut buffer provided by the caller
  418. * @lut_size: size of the lut buffer
  419. *
  420. * get the RSS lookup table, PF or VSI type
  421. **/
  422. i40e_status i40e_aq_get_rss_lut(struct i40e_hw *hw, u16 vsi_id,
  423. bool pf_lut, u8 *lut, u16 lut_size)
  424. {
  425. return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size,
  426. false);
  427. }
  428. /**
  429. * i40e_aq_set_rss_lut
  430. * @hw: pointer to the hardware structure
  431. * @vsi_id: vsi fw index
  432. * @pf_lut: for PF table set true, for VSI table set false
  433. * @lut: pointer to the lut buffer provided by the caller
  434. * @lut_size: size of the lut buffer
  435. *
  436. * set the RSS lookup table, PF or VSI type
  437. **/
  438. i40e_status i40e_aq_set_rss_lut(struct i40e_hw *hw, u16 vsi_id,
  439. bool pf_lut, u8 *lut, u16 lut_size)
  440. {
  441. return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size, true);
  442. }
  443. /**
  444. * i40e_aq_get_set_rss_key
  445. * @hw: pointer to the hw struct
  446. * @vsi_id: vsi fw index
  447. * @key: pointer to key info struct
  448. * @set: set true to set the key, false to get the key
  449. *
  450. * get the RSS key per VSI
  451. **/
  452. static i40e_status i40e_aq_get_set_rss_key(struct i40e_hw *hw,
  453. u16 vsi_id,
  454. struct i40e_aqc_get_set_rss_key_data *key,
  455. bool set)
  456. {
  457. i40e_status status;
  458. struct i40e_aq_desc desc;
  459. struct i40e_aqc_get_set_rss_key *cmd_resp =
  460. (struct i40e_aqc_get_set_rss_key *)&desc.params.raw;
  461. u16 key_size = sizeof(struct i40e_aqc_get_set_rss_key_data);
  462. if (set)
  463. i40e_fill_default_direct_cmd_desc(&desc,
  464. i40e_aqc_opc_set_rss_key);
  465. else
  466. i40e_fill_default_direct_cmd_desc(&desc,
  467. i40e_aqc_opc_get_rss_key);
  468. /* Indirect command */
  469. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  470. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
  471. cmd_resp->vsi_id =
  472. cpu_to_le16((u16)((vsi_id <<
  473. I40E_AQC_SET_RSS_KEY_VSI_ID_SHIFT) &
  474. I40E_AQC_SET_RSS_KEY_VSI_ID_MASK));
  475. cmd_resp->vsi_id |= cpu_to_le16((u16)I40E_AQC_SET_RSS_KEY_VSI_VALID);
  476. status = i40e_asq_send_command(hw, &desc, key, key_size, NULL);
  477. return status;
  478. }
  479. /**
  480. * i40e_aq_get_rss_key
  481. * @hw: pointer to the hw struct
  482. * @vsi_id: vsi fw index
  483. * @key: pointer to key info struct
  484. *
  485. **/
  486. i40e_status i40e_aq_get_rss_key(struct i40e_hw *hw,
  487. u16 vsi_id,
  488. struct i40e_aqc_get_set_rss_key_data *key)
  489. {
  490. return i40e_aq_get_set_rss_key(hw, vsi_id, key, false);
  491. }
  492. /**
  493. * i40e_aq_set_rss_key
  494. * @hw: pointer to the hw struct
  495. * @vsi_id: vsi fw index
  496. * @key: pointer to key info struct
  497. *
  498. * set the RSS key per VSI
  499. **/
  500. i40e_status i40e_aq_set_rss_key(struct i40e_hw *hw,
  501. u16 vsi_id,
  502. struct i40e_aqc_get_set_rss_key_data *key)
  503. {
  504. return i40e_aq_get_set_rss_key(hw, vsi_id, key, true);
  505. }
  506. /* The i40e_ptype_lookup table is used to convert from the 8-bit ptype in the
  507. * hardware to a bit-field that can be used by SW to more easily determine the
  508. * packet type.
  509. *
  510. * Macros are used to shorten the table lines and make this table human
  511. * readable.
  512. *
  513. * We store the PTYPE in the top byte of the bit field - this is just so that
  514. * we can check that the table doesn't have a row missing, as the index into
  515. * the table should be the PTYPE.
  516. *
  517. * Typical work flow:
  518. *
  519. * IF NOT i40e_ptype_lookup[ptype].known
  520. * THEN
  521. * Packet is unknown
  522. * ELSE IF i40e_ptype_lookup[ptype].outer_ip == I40E_RX_PTYPE_OUTER_IP
  523. * Use the rest of the fields to look at the tunnels, inner protocols, etc
  524. * ELSE
  525. * Use the enum i40e_rx_l2_ptype to decode the packet type
  526. * ENDIF
  527. */
  528. /* macro to make the table lines short */
  529. #define I40E_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
  530. { PTYPE, \
  531. 1, \
  532. I40E_RX_PTYPE_OUTER_##OUTER_IP, \
  533. I40E_RX_PTYPE_OUTER_##OUTER_IP_VER, \
  534. I40E_RX_PTYPE_##OUTER_FRAG, \
  535. I40E_RX_PTYPE_TUNNEL_##T, \
  536. I40E_RX_PTYPE_TUNNEL_END_##TE, \
  537. I40E_RX_PTYPE_##TEF, \
  538. I40E_RX_PTYPE_INNER_PROT_##I, \
  539. I40E_RX_PTYPE_PAYLOAD_LAYER_##PL }
  540. #define I40E_PTT_UNUSED_ENTRY(PTYPE) \
  541. { PTYPE, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  542. /* shorter macros makes the table fit but are terse */
  543. #define I40E_RX_PTYPE_NOF I40E_RX_PTYPE_NOT_FRAG
  544. #define I40E_RX_PTYPE_FRG I40E_RX_PTYPE_FRAG
  545. #define I40E_RX_PTYPE_INNER_PROT_TS I40E_RX_PTYPE_INNER_PROT_TIMESYNC
  546. /* Lookup table mapping the HW PTYPE to the bit field for decoding */
  547. struct i40e_rx_ptype_decoded i40e_ptype_lookup[] = {
  548. /* L2 Packet types */
  549. I40E_PTT_UNUSED_ENTRY(0),
  550. I40E_PTT(1, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  551. I40E_PTT(2, L2, NONE, NOF, NONE, NONE, NOF, TS, PAY2),
  552. I40E_PTT(3, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  553. I40E_PTT_UNUSED_ENTRY(4),
  554. I40E_PTT_UNUSED_ENTRY(5),
  555. I40E_PTT(6, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  556. I40E_PTT(7, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  557. I40E_PTT_UNUSED_ENTRY(8),
  558. I40E_PTT_UNUSED_ENTRY(9),
  559. I40E_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  560. I40E_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
  561. I40E_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  562. I40E_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  563. I40E_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  564. I40E_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  565. I40E_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  566. I40E_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  567. I40E_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  568. I40E_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  569. I40E_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  570. I40E_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  571. /* Non Tunneled IPv4 */
  572. I40E_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
  573. I40E_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
  574. I40E_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP, PAY4),
  575. I40E_PTT_UNUSED_ENTRY(25),
  576. I40E_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP, PAY4),
  577. I40E_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
  578. I40E_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
  579. /* IPv4 --> IPv4 */
  580. I40E_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
  581. I40E_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
  582. I40E_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
  583. I40E_PTT_UNUSED_ENTRY(32),
  584. I40E_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
  585. I40E_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
  586. I40E_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
  587. /* IPv4 --> IPv6 */
  588. I40E_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
  589. I40E_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
  590. I40E_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
  591. I40E_PTT_UNUSED_ENTRY(39),
  592. I40E_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
  593. I40E_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
  594. I40E_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
  595. /* IPv4 --> GRE/NAT */
  596. I40E_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
  597. /* IPv4 --> GRE/NAT --> IPv4 */
  598. I40E_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
  599. I40E_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
  600. I40E_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
  601. I40E_PTT_UNUSED_ENTRY(47),
  602. I40E_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
  603. I40E_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
  604. I40E_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
  605. /* IPv4 --> GRE/NAT --> IPv6 */
  606. I40E_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
  607. I40E_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
  608. I40E_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
  609. I40E_PTT_UNUSED_ENTRY(54),
  610. I40E_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
  611. I40E_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
  612. I40E_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
  613. /* IPv4 --> GRE/NAT --> MAC */
  614. I40E_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
  615. /* IPv4 --> GRE/NAT --> MAC --> IPv4 */
  616. I40E_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
  617. I40E_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
  618. I40E_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
  619. I40E_PTT_UNUSED_ENTRY(62),
  620. I40E_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
  621. I40E_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
  622. I40E_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
  623. /* IPv4 --> GRE/NAT -> MAC --> IPv6 */
  624. I40E_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
  625. I40E_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
  626. I40E_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
  627. I40E_PTT_UNUSED_ENTRY(69),
  628. I40E_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
  629. I40E_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
  630. I40E_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
  631. /* IPv4 --> GRE/NAT --> MAC/VLAN */
  632. I40E_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
  633. /* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
  634. I40E_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
  635. I40E_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
  636. I40E_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
  637. I40E_PTT_UNUSED_ENTRY(77),
  638. I40E_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
  639. I40E_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
  640. I40E_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
  641. /* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
  642. I40E_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
  643. I40E_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
  644. I40E_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
  645. I40E_PTT_UNUSED_ENTRY(84),
  646. I40E_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
  647. I40E_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
  648. I40E_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
  649. /* Non Tunneled IPv6 */
  650. I40E_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
  651. I40E_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
  652. I40E_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP, PAY3),
  653. I40E_PTT_UNUSED_ENTRY(91),
  654. I40E_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP, PAY4),
  655. I40E_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
  656. I40E_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
  657. /* IPv6 --> IPv4 */
  658. I40E_PTT(95, IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
  659. I40E_PTT(96, IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
  660. I40E_PTT(97, IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
  661. I40E_PTT_UNUSED_ENTRY(98),
  662. I40E_PTT(99, IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
  663. I40E_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
  664. I40E_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
  665. /* IPv6 --> IPv6 */
  666. I40E_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
  667. I40E_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
  668. I40E_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
  669. I40E_PTT_UNUSED_ENTRY(105),
  670. I40E_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
  671. I40E_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
  672. I40E_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
  673. /* IPv6 --> GRE/NAT */
  674. I40E_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
  675. /* IPv6 --> GRE/NAT -> IPv4 */
  676. I40E_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
  677. I40E_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
  678. I40E_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
  679. I40E_PTT_UNUSED_ENTRY(113),
  680. I40E_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
  681. I40E_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
  682. I40E_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
  683. /* IPv6 --> GRE/NAT -> IPv6 */
  684. I40E_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
  685. I40E_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
  686. I40E_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
  687. I40E_PTT_UNUSED_ENTRY(120),
  688. I40E_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
  689. I40E_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
  690. I40E_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
  691. /* IPv6 --> GRE/NAT -> MAC */
  692. I40E_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
  693. /* IPv6 --> GRE/NAT -> MAC -> IPv4 */
  694. I40E_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
  695. I40E_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
  696. I40E_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
  697. I40E_PTT_UNUSED_ENTRY(128),
  698. I40E_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
  699. I40E_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
  700. I40E_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
  701. /* IPv6 --> GRE/NAT -> MAC -> IPv6 */
  702. I40E_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
  703. I40E_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
  704. I40E_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
  705. I40E_PTT_UNUSED_ENTRY(135),
  706. I40E_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
  707. I40E_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
  708. I40E_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
  709. /* IPv6 --> GRE/NAT -> MAC/VLAN */
  710. I40E_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
  711. /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
  712. I40E_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
  713. I40E_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
  714. I40E_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
  715. I40E_PTT_UNUSED_ENTRY(143),
  716. I40E_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
  717. I40E_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
  718. I40E_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
  719. /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
  720. I40E_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
  721. I40E_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
  722. I40E_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
  723. I40E_PTT_UNUSED_ENTRY(150),
  724. I40E_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
  725. I40E_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
  726. I40E_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
  727. /* unused entries */
  728. I40E_PTT_UNUSED_ENTRY(154),
  729. I40E_PTT_UNUSED_ENTRY(155),
  730. I40E_PTT_UNUSED_ENTRY(156),
  731. I40E_PTT_UNUSED_ENTRY(157),
  732. I40E_PTT_UNUSED_ENTRY(158),
  733. I40E_PTT_UNUSED_ENTRY(159),
  734. I40E_PTT_UNUSED_ENTRY(160),
  735. I40E_PTT_UNUSED_ENTRY(161),
  736. I40E_PTT_UNUSED_ENTRY(162),
  737. I40E_PTT_UNUSED_ENTRY(163),
  738. I40E_PTT_UNUSED_ENTRY(164),
  739. I40E_PTT_UNUSED_ENTRY(165),
  740. I40E_PTT_UNUSED_ENTRY(166),
  741. I40E_PTT_UNUSED_ENTRY(167),
  742. I40E_PTT_UNUSED_ENTRY(168),
  743. I40E_PTT_UNUSED_ENTRY(169),
  744. I40E_PTT_UNUSED_ENTRY(170),
  745. I40E_PTT_UNUSED_ENTRY(171),
  746. I40E_PTT_UNUSED_ENTRY(172),
  747. I40E_PTT_UNUSED_ENTRY(173),
  748. I40E_PTT_UNUSED_ENTRY(174),
  749. I40E_PTT_UNUSED_ENTRY(175),
  750. I40E_PTT_UNUSED_ENTRY(176),
  751. I40E_PTT_UNUSED_ENTRY(177),
  752. I40E_PTT_UNUSED_ENTRY(178),
  753. I40E_PTT_UNUSED_ENTRY(179),
  754. I40E_PTT_UNUSED_ENTRY(180),
  755. I40E_PTT_UNUSED_ENTRY(181),
  756. I40E_PTT_UNUSED_ENTRY(182),
  757. I40E_PTT_UNUSED_ENTRY(183),
  758. I40E_PTT_UNUSED_ENTRY(184),
  759. I40E_PTT_UNUSED_ENTRY(185),
  760. I40E_PTT_UNUSED_ENTRY(186),
  761. I40E_PTT_UNUSED_ENTRY(187),
  762. I40E_PTT_UNUSED_ENTRY(188),
  763. I40E_PTT_UNUSED_ENTRY(189),
  764. I40E_PTT_UNUSED_ENTRY(190),
  765. I40E_PTT_UNUSED_ENTRY(191),
  766. I40E_PTT_UNUSED_ENTRY(192),
  767. I40E_PTT_UNUSED_ENTRY(193),
  768. I40E_PTT_UNUSED_ENTRY(194),
  769. I40E_PTT_UNUSED_ENTRY(195),
  770. I40E_PTT_UNUSED_ENTRY(196),
  771. I40E_PTT_UNUSED_ENTRY(197),
  772. I40E_PTT_UNUSED_ENTRY(198),
  773. I40E_PTT_UNUSED_ENTRY(199),
  774. I40E_PTT_UNUSED_ENTRY(200),
  775. I40E_PTT_UNUSED_ENTRY(201),
  776. I40E_PTT_UNUSED_ENTRY(202),
  777. I40E_PTT_UNUSED_ENTRY(203),
  778. I40E_PTT_UNUSED_ENTRY(204),
  779. I40E_PTT_UNUSED_ENTRY(205),
  780. I40E_PTT_UNUSED_ENTRY(206),
  781. I40E_PTT_UNUSED_ENTRY(207),
  782. I40E_PTT_UNUSED_ENTRY(208),
  783. I40E_PTT_UNUSED_ENTRY(209),
  784. I40E_PTT_UNUSED_ENTRY(210),
  785. I40E_PTT_UNUSED_ENTRY(211),
  786. I40E_PTT_UNUSED_ENTRY(212),
  787. I40E_PTT_UNUSED_ENTRY(213),
  788. I40E_PTT_UNUSED_ENTRY(214),
  789. I40E_PTT_UNUSED_ENTRY(215),
  790. I40E_PTT_UNUSED_ENTRY(216),
  791. I40E_PTT_UNUSED_ENTRY(217),
  792. I40E_PTT_UNUSED_ENTRY(218),
  793. I40E_PTT_UNUSED_ENTRY(219),
  794. I40E_PTT_UNUSED_ENTRY(220),
  795. I40E_PTT_UNUSED_ENTRY(221),
  796. I40E_PTT_UNUSED_ENTRY(222),
  797. I40E_PTT_UNUSED_ENTRY(223),
  798. I40E_PTT_UNUSED_ENTRY(224),
  799. I40E_PTT_UNUSED_ENTRY(225),
  800. I40E_PTT_UNUSED_ENTRY(226),
  801. I40E_PTT_UNUSED_ENTRY(227),
  802. I40E_PTT_UNUSED_ENTRY(228),
  803. I40E_PTT_UNUSED_ENTRY(229),
  804. I40E_PTT_UNUSED_ENTRY(230),
  805. I40E_PTT_UNUSED_ENTRY(231),
  806. I40E_PTT_UNUSED_ENTRY(232),
  807. I40E_PTT_UNUSED_ENTRY(233),
  808. I40E_PTT_UNUSED_ENTRY(234),
  809. I40E_PTT_UNUSED_ENTRY(235),
  810. I40E_PTT_UNUSED_ENTRY(236),
  811. I40E_PTT_UNUSED_ENTRY(237),
  812. I40E_PTT_UNUSED_ENTRY(238),
  813. I40E_PTT_UNUSED_ENTRY(239),
  814. I40E_PTT_UNUSED_ENTRY(240),
  815. I40E_PTT_UNUSED_ENTRY(241),
  816. I40E_PTT_UNUSED_ENTRY(242),
  817. I40E_PTT_UNUSED_ENTRY(243),
  818. I40E_PTT_UNUSED_ENTRY(244),
  819. I40E_PTT_UNUSED_ENTRY(245),
  820. I40E_PTT_UNUSED_ENTRY(246),
  821. I40E_PTT_UNUSED_ENTRY(247),
  822. I40E_PTT_UNUSED_ENTRY(248),
  823. I40E_PTT_UNUSED_ENTRY(249),
  824. I40E_PTT_UNUSED_ENTRY(250),
  825. I40E_PTT_UNUSED_ENTRY(251),
  826. I40E_PTT_UNUSED_ENTRY(252),
  827. I40E_PTT_UNUSED_ENTRY(253),
  828. I40E_PTT_UNUSED_ENTRY(254),
  829. I40E_PTT_UNUSED_ENTRY(255)
  830. };
  831. /**
  832. * i40e_init_shared_code - Initialize the shared code
  833. * @hw: pointer to hardware structure
  834. *
  835. * This assigns the MAC type and PHY code and inits the NVM.
  836. * Does not touch the hardware. This function must be called prior to any
  837. * other function in the shared code. The i40e_hw structure should be
  838. * memset to 0 prior to calling this function. The following fields in
  839. * hw structure should be filled in prior to calling this function:
  840. * hw_addr, back, device_id, vendor_id, subsystem_device_id,
  841. * subsystem_vendor_id, and revision_id
  842. **/
  843. i40e_status i40e_init_shared_code(struct i40e_hw *hw)
  844. {
  845. i40e_status status = 0;
  846. u32 port, ari, func_rid;
  847. i40e_set_mac_type(hw);
  848. switch (hw->mac.type) {
  849. case I40E_MAC_XL710:
  850. case I40E_MAC_X722:
  851. break;
  852. default:
  853. return I40E_ERR_DEVICE_NOT_SUPPORTED;
  854. }
  855. hw->phy.get_link_info = true;
  856. /* Determine port number and PF number*/
  857. port = (rd32(hw, I40E_PFGEN_PORTNUM) & I40E_PFGEN_PORTNUM_PORT_NUM_MASK)
  858. >> I40E_PFGEN_PORTNUM_PORT_NUM_SHIFT;
  859. hw->port = (u8)port;
  860. ari = (rd32(hw, I40E_GLPCI_CAPSUP) & I40E_GLPCI_CAPSUP_ARI_EN_MASK) >>
  861. I40E_GLPCI_CAPSUP_ARI_EN_SHIFT;
  862. func_rid = rd32(hw, I40E_PF_FUNC_RID);
  863. if (ari)
  864. hw->pf_id = (u8)(func_rid & 0xff);
  865. else
  866. hw->pf_id = (u8)(func_rid & 0x7);
  867. if (hw->mac.type == I40E_MAC_X722)
  868. hw->flags |= I40E_HW_FLAG_AQ_SRCTL_ACCESS_ENABLE;
  869. status = i40e_init_nvm(hw);
  870. return status;
  871. }
  872. /**
  873. * i40e_aq_mac_address_read - Retrieve the MAC addresses
  874. * @hw: pointer to the hw struct
  875. * @flags: a return indicator of what addresses were added to the addr store
  876. * @addrs: the requestor's mac addr store
  877. * @cmd_details: pointer to command details structure or NULL
  878. **/
  879. static i40e_status i40e_aq_mac_address_read(struct i40e_hw *hw,
  880. u16 *flags,
  881. struct i40e_aqc_mac_address_read_data *addrs,
  882. struct i40e_asq_cmd_details *cmd_details)
  883. {
  884. struct i40e_aq_desc desc;
  885. struct i40e_aqc_mac_address_read *cmd_data =
  886. (struct i40e_aqc_mac_address_read *)&desc.params.raw;
  887. i40e_status status;
  888. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_mac_address_read);
  889. desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF);
  890. status = i40e_asq_send_command(hw, &desc, addrs,
  891. sizeof(*addrs), cmd_details);
  892. *flags = le16_to_cpu(cmd_data->command_flags);
  893. return status;
  894. }
  895. /**
  896. * i40e_aq_mac_address_write - Change the MAC addresses
  897. * @hw: pointer to the hw struct
  898. * @flags: indicates which MAC to be written
  899. * @mac_addr: address to write
  900. * @cmd_details: pointer to command details structure or NULL
  901. **/
  902. i40e_status i40e_aq_mac_address_write(struct i40e_hw *hw,
  903. u16 flags, u8 *mac_addr,
  904. struct i40e_asq_cmd_details *cmd_details)
  905. {
  906. struct i40e_aq_desc desc;
  907. struct i40e_aqc_mac_address_write *cmd_data =
  908. (struct i40e_aqc_mac_address_write *)&desc.params.raw;
  909. i40e_status status;
  910. i40e_fill_default_direct_cmd_desc(&desc,
  911. i40e_aqc_opc_mac_address_write);
  912. cmd_data->command_flags = cpu_to_le16(flags);
  913. cmd_data->mac_sah = cpu_to_le16((u16)mac_addr[0] << 8 | mac_addr[1]);
  914. cmd_data->mac_sal = cpu_to_le32(((u32)mac_addr[2] << 24) |
  915. ((u32)mac_addr[3] << 16) |
  916. ((u32)mac_addr[4] << 8) |
  917. mac_addr[5]);
  918. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  919. return status;
  920. }
  921. /**
  922. * i40e_get_mac_addr - get MAC address
  923. * @hw: pointer to the HW structure
  924. * @mac_addr: pointer to MAC address
  925. *
  926. * Reads the adapter's MAC address from register
  927. **/
  928. i40e_status i40e_get_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
  929. {
  930. struct i40e_aqc_mac_address_read_data addrs;
  931. i40e_status status;
  932. u16 flags = 0;
  933. status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
  934. if (flags & I40E_AQC_LAN_ADDR_VALID)
  935. ether_addr_copy(mac_addr, addrs.pf_lan_mac);
  936. return status;
  937. }
  938. /**
  939. * i40e_get_port_mac_addr - get Port MAC address
  940. * @hw: pointer to the HW structure
  941. * @mac_addr: pointer to Port MAC address
  942. *
  943. * Reads the adapter's Port MAC address
  944. **/
  945. i40e_status i40e_get_port_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
  946. {
  947. struct i40e_aqc_mac_address_read_data addrs;
  948. i40e_status status;
  949. u16 flags = 0;
  950. status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
  951. if (status)
  952. return status;
  953. if (flags & I40E_AQC_PORT_ADDR_VALID)
  954. ether_addr_copy(mac_addr, addrs.port_mac);
  955. else
  956. status = I40E_ERR_INVALID_MAC_ADDR;
  957. return status;
  958. }
  959. /**
  960. * i40e_pre_tx_queue_cfg - pre tx queue configure
  961. * @hw: pointer to the HW structure
  962. * @queue: target PF queue index
  963. * @enable: state change request
  964. *
  965. * Handles hw requirement to indicate intention to enable
  966. * or disable target queue.
  967. **/
  968. void i40e_pre_tx_queue_cfg(struct i40e_hw *hw, u32 queue, bool enable)
  969. {
  970. u32 abs_queue_idx = hw->func_caps.base_queue + queue;
  971. u32 reg_block = 0;
  972. u32 reg_val;
  973. if (abs_queue_idx >= 128) {
  974. reg_block = abs_queue_idx / 128;
  975. abs_queue_idx %= 128;
  976. }
  977. reg_val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
  978. reg_val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
  979. reg_val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
  980. if (enable)
  981. reg_val |= I40E_GLLAN_TXPRE_QDIS_CLEAR_QDIS_MASK;
  982. else
  983. reg_val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
  984. wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), reg_val);
  985. }
  986. #ifdef I40E_FCOE
  987. /**
  988. * i40e_get_san_mac_addr - get SAN MAC address
  989. * @hw: pointer to the HW structure
  990. * @mac_addr: pointer to SAN MAC address
  991. *
  992. * Reads the adapter's SAN MAC address from NVM
  993. **/
  994. i40e_status i40e_get_san_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
  995. {
  996. struct i40e_aqc_mac_address_read_data addrs;
  997. i40e_status status;
  998. u16 flags = 0;
  999. status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
  1000. if (status)
  1001. return status;
  1002. if (flags & I40E_AQC_SAN_ADDR_VALID)
  1003. ether_addr_copy(mac_addr, addrs.pf_san_mac);
  1004. else
  1005. status = I40E_ERR_INVALID_MAC_ADDR;
  1006. return status;
  1007. }
  1008. #endif
  1009. /**
  1010. * i40e_read_pba_string - Reads part number string from EEPROM
  1011. * @hw: pointer to hardware structure
  1012. * @pba_num: stores the part number string from the EEPROM
  1013. * @pba_num_size: part number string buffer length
  1014. *
  1015. * Reads the part number string from the EEPROM.
  1016. **/
  1017. i40e_status i40e_read_pba_string(struct i40e_hw *hw, u8 *pba_num,
  1018. u32 pba_num_size)
  1019. {
  1020. i40e_status status = 0;
  1021. u16 pba_word = 0;
  1022. u16 pba_size = 0;
  1023. u16 pba_ptr = 0;
  1024. u16 i = 0;
  1025. status = i40e_read_nvm_word(hw, I40E_SR_PBA_FLAGS, &pba_word);
  1026. if (status || (pba_word != 0xFAFA)) {
  1027. hw_dbg(hw, "Failed to read PBA flags or flag is invalid.\n");
  1028. return status;
  1029. }
  1030. status = i40e_read_nvm_word(hw, I40E_SR_PBA_BLOCK_PTR, &pba_ptr);
  1031. if (status) {
  1032. hw_dbg(hw, "Failed to read PBA Block pointer.\n");
  1033. return status;
  1034. }
  1035. status = i40e_read_nvm_word(hw, pba_ptr, &pba_size);
  1036. if (status) {
  1037. hw_dbg(hw, "Failed to read PBA Block size.\n");
  1038. return status;
  1039. }
  1040. /* Subtract one to get PBA word count (PBA Size word is included in
  1041. * total size)
  1042. */
  1043. pba_size--;
  1044. if (pba_num_size < (((u32)pba_size * 2) + 1)) {
  1045. hw_dbg(hw, "Buffer to small for PBA data.\n");
  1046. return I40E_ERR_PARAM;
  1047. }
  1048. for (i = 0; i < pba_size; i++) {
  1049. status = i40e_read_nvm_word(hw, (pba_ptr + 1) + i, &pba_word);
  1050. if (status) {
  1051. hw_dbg(hw, "Failed to read PBA Block word %d.\n", i);
  1052. return status;
  1053. }
  1054. pba_num[(i * 2)] = (pba_word >> 8) & 0xFF;
  1055. pba_num[(i * 2) + 1] = pba_word & 0xFF;
  1056. }
  1057. pba_num[(pba_size * 2)] = '\0';
  1058. return status;
  1059. }
  1060. /**
  1061. * i40e_get_media_type - Gets media type
  1062. * @hw: pointer to the hardware structure
  1063. **/
  1064. static enum i40e_media_type i40e_get_media_type(struct i40e_hw *hw)
  1065. {
  1066. enum i40e_media_type media;
  1067. switch (hw->phy.link_info.phy_type) {
  1068. case I40E_PHY_TYPE_10GBASE_SR:
  1069. case I40E_PHY_TYPE_10GBASE_LR:
  1070. case I40E_PHY_TYPE_1000BASE_SX:
  1071. case I40E_PHY_TYPE_1000BASE_LX:
  1072. case I40E_PHY_TYPE_40GBASE_SR4:
  1073. case I40E_PHY_TYPE_40GBASE_LR4:
  1074. media = I40E_MEDIA_TYPE_FIBER;
  1075. break;
  1076. case I40E_PHY_TYPE_100BASE_TX:
  1077. case I40E_PHY_TYPE_1000BASE_T:
  1078. case I40E_PHY_TYPE_10GBASE_T:
  1079. media = I40E_MEDIA_TYPE_BASET;
  1080. break;
  1081. case I40E_PHY_TYPE_10GBASE_CR1_CU:
  1082. case I40E_PHY_TYPE_40GBASE_CR4_CU:
  1083. case I40E_PHY_TYPE_10GBASE_CR1:
  1084. case I40E_PHY_TYPE_40GBASE_CR4:
  1085. case I40E_PHY_TYPE_10GBASE_SFPP_CU:
  1086. case I40E_PHY_TYPE_40GBASE_AOC:
  1087. case I40E_PHY_TYPE_10GBASE_AOC:
  1088. media = I40E_MEDIA_TYPE_DA;
  1089. break;
  1090. case I40E_PHY_TYPE_1000BASE_KX:
  1091. case I40E_PHY_TYPE_10GBASE_KX4:
  1092. case I40E_PHY_TYPE_10GBASE_KR:
  1093. case I40E_PHY_TYPE_40GBASE_KR4:
  1094. case I40E_PHY_TYPE_20GBASE_KR2:
  1095. media = I40E_MEDIA_TYPE_BACKPLANE;
  1096. break;
  1097. case I40E_PHY_TYPE_SGMII:
  1098. case I40E_PHY_TYPE_XAUI:
  1099. case I40E_PHY_TYPE_XFI:
  1100. case I40E_PHY_TYPE_XLAUI:
  1101. case I40E_PHY_TYPE_XLPPI:
  1102. default:
  1103. media = I40E_MEDIA_TYPE_UNKNOWN;
  1104. break;
  1105. }
  1106. return media;
  1107. }
  1108. #define I40E_PF_RESET_WAIT_COUNT_A0 200
  1109. #define I40E_PF_RESET_WAIT_COUNT 200
  1110. /**
  1111. * i40e_pf_reset - Reset the PF
  1112. * @hw: pointer to the hardware structure
  1113. *
  1114. * Assuming someone else has triggered a global reset,
  1115. * assure the global reset is complete and then reset the PF
  1116. **/
  1117. i40e_status i40e_pf_reset(struct i40e_hw *hw)
  1118. {
  1119. u32 cnt = 0;
  1120. u32 cnt1 = 0;
  1121. u32 reg = 0;
  1122. u32 grst_del;
  1123. /* Poll for Global Reset steady state in case of recent GRST.
  1124. * The grst delay value is in 100ms units, and we'll wait a
  1125. * couple counts longer to be sure we don't just miss the end.
  1126. */
  1127. grst_del = (rd32(hw, I40E_GLGEN_RSTCTL) &
  1128. I40E_GLGEN_RSTCTL_GRSTDEL_MASK) >>
  1129. I40E_GLGEN_RSTCTL_GRSTDEL_SHIFT;
  1130. for (cnt = 0; cnt < grst_del + 10; cnt++) {
  1131. reg = rd32(hw, I40E_GLGEN_RSTAT);
  1132. if (!(reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK))
  1133. break;
  1134. msleep(100);
  1135. }
  1136. if (reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
  1137. hw_dbg(hw, "Global reset polling failed to complete.\n");
  1138. return I40E_ERR_RESET_FAILED;
  1139. }
  1140. /* Now Wait for the FW to be ready */
  1141. for (cnt1 = 0; cnt1 < I40E_PF_RESET_WAIT_COUNT; cnt1++) {
  1142. reg = rd32(hw, I40E_GLNVM_ULD);
  1143. reg &= (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
  1144. I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK);
  1145. if (reg == (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
  1146. I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK)) {
  1147. hw_dbg(hw, "Core and Global modules ready %d\n", cnt1);
  1148. break;
  1149. }
  1150. usleep_range(10000, 20000);
  1151. }
  1152. if (!(reg & (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
  1153. I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK))) {
  1154. hw_dbg(hw, "wait for FW Reset complete timedout\n");
  1155. hw_dbg(hw, "I40E_GLNVM_ULD = 0x%x\n", reg);
  1156. return I40E_ERR_RESET_FAILED;
  1157. }
  1158. /* If there was a Global Reset in progress when we got here,
  1159. * we don't need to do the PF Reset
  1160. */
  1161. if (!cnt) {
  1162. if (hw->revision_id == 0)
  1163. cnt = I40E_PF_RESET_WAIT_COUNT_A0;
  1164. else
  1165. cnt = I40E_PF_RESET_WAIT_COUNT;
  1166. reg = rd32(hw, I40E_PFGEN_CTRL);
  1167. wr32(hw, I40E_PFGEN_CTRL,
  1168. (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
  1169. for (; cnt; cnt--) {
  1170. reg = rd32(hw, I40E_PFGEN_CTRL);
  1171. if (!(reg & I40E_PFGEN_CTRL_PFSWR_MASK))
  1172. break;
  1173. usleep_range(1000, 2000);
  1174. }
  1175. if (reg & I40E_PFGEN_CTRL_PFSWR_MASK) {
  1176. hw_dbg(hw, "PF reset polling failed to complete.\n");
  1177. return I40E_ERR_RESET_FAILED;
  1178. }
  1179. }
  1180. i40e_clear_pxe_mode(hw);
  1181. return 0;
  1182. }
  1183. /**
  1184. * i40e_clear_hw - clear out any left over hw state
  1185. * @hw: pointer to the hw struct
  1186. *
  1187. * Clear queues and interrupts, typically called at init time,
  1188. * but after the capabilities have been found so we know how many
  1189. * queues and msix vectors have been allocated.
  1190. **/
  1191. void i40e_clear_hw(struct i40e_hw *hw)
  1192. {
  1193. u32 num_queues, base_queue;
  1194. u32 num_pf_int;
  1195. u32 num_vf_int;
  1196. u32 num_vfs;
  1197. u32 i, j;
  1198. u32 val;
  1199. u32 eol = 0x7ff;
  1200. /* get number of interrupts, queues, and VFs */
  1201. val = rd32(hw, I40E_GLPCI_CNF2);
  1202. num_pf_int = (val & I40E_GLPCI_CNF2_MSI_X_PF_N_MASK) >>
  1203. I40E_GLPCI_CNF2_MSI_X_PF_N_SHIFT;
  1204. num_vf_int = (val & I40E_GLPCI_CNF2_MSI_X_VF_N_MASK) >>
  1205. I40E_GLPCI_CNF2_MSI_X_VF_N_SHIFT;
  1206. val = rd32(hw, I40E_PFLAN_QALLOC);
  1207. base_queue = (val & I40E_PFLAN_QALLOC_FIRSTQ_MASK) >>
  1208. I40E_PFLAN_QALLOC_FIRSTQ_SHIFT;
  1209. j = (val & I40E_PFLAN_QALLOC_LASTQ_MASK) >>
  1210. I40E_PFLAN_QALLOC_LASTQ_SHIFT;
  1211. if (val & I40E_PFLAN_QALLOC_VALID_MASK)
  1212. num_queues = (j - base_queue) + 1;
  1213. else
  1214. num_queues = 0;
  1215. val = rd32(hw, I40E_PF_VT_PFALLOC);
  1216. i = (val & I40E_PF_VT_PFALLOC_FIRSTVF_MASK) >>
  1217. I40E_PF_VT_PFALLOC_FIRSTVF_SHIFT;
  1218. j = (val & I40E_PF_VT_PFALLOC_LASTVF_MASK) >>
  1219. I40E_PF_VT_PFALLOC_LASTVF_SHIFT;
  1220. if (val & I40E_PF_VT_PFALLOC_VALID_MASK)
  1221. num_vfs = (j - i) + 1;
  1222. else
  1223. num_vfs = 0;
  1224. /* stop all the interrupts */
  1225. wr32(hw, I40E_PFINT_ICR0_ENA, 0);
  1226. val = 0x3 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT;
  1227. for (i = 0; i < num_pf_int - 2; i++)
  1228. wr32(hw, I40E_PFINT_DYN_CTLN(i), val);
  1229. /* Set the FIRSTQ_INDX field to 0x7FF in PFINT_LNKLSTx */
  1230. val = eol << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
  1231. wr32(hw, I40E_PFINT_LNKLST0, val);
  1232. for (i = 0; i < num_pf_int - 2; i++)
  1233. wr32(hw, I40E_PFINT_LNKLSTN(i), val);
  1234. val = eol << I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT;
  1235. for (i = 0; i < num_vfs; i++)
  1236. wr32(hw, I40E_VPINT_LNKLST0(i), val);
  1237. for (i = 0; i < num_vf_int - 2; i++)
  1238. wr32(hw, I40E_VPINT_LNKLSTN(i), val);
  1239. /* warn the HW of the coming Tx disables */
  1240. for (i = 0; i < num_queues; i++) {
  1241. u32 abs_queue_idx = base_queue + i;
  1242. u32 reg_block = 0;
  1243. if (abs_queue_idx >= 128) {
  1244. reg_block = abs_queue_idx / 128;
  1245. abs_queue_idx %= 128;
  1246. }
  1247. val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
  1248. val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
  1249. val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
  1250. val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
  1251. wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), val);
  1252. }
  1253. udelay(400);
  1254. /* stop all the queues */
  1255. for (i = 0; i < num_queues; i++) {
  1256. wr32(hw, I40E_QINT_TQCTL(i), 0);
  1257. wr32(hw, I40E_QTX_ENA(i), 0);
  1258. wr32(hw, I40E_QINT_RQCTL(i), 0);
  1259. wr32(hw, I40E_QRX_ENA(i), 0);
  1260. }
  1261. /* short wait for all queue disables to settle */
  1262. udelay(50);
  1263. }
  1264. /**
  1265. * i40e_clear_pxe_mode - clear pxe operations mode
  1266. * @hw: pointer to the hw struct
  1267. *
  1268. * Make sure all PXE mode settings are cleared, including things
  1269. * like descriptor fetch/write-back mode.
  1270. **/
  1271. void i40e_clear_pxe_mode(struct i40e_hw *hw)
  1272. {
  1273. u32 reg;
  1274. if (i40e_check_asq_alive(hw))
  1275. i40e_aq_clear_pxe_mode(hw, NULL);
  1276. /* Clear single descriptor fetch/write-back mode */
  1277. reg = rd32(hw, I40E_GLLAN_RCTL_0);
  1278. if (hw->revision_id == 0) {
  1279. /* As a work around clear PXE_MODE instead of setting it */
  1280. wr32(hw, I40E_GLLAN_RCTL_0, (reg & (~I40E_GLLAN_RCTL_0_PXE_MODE_MASK)));
  1281. } else {
  1282. wr32(hw, I40E_GLLAN_RCTL_0, (reg | I40E_GLLAN_RCTL_0_PXE_MODE_MASK));
  1283. }
  1284. }
  1285. /**
  1286. * i40e_led_is_mine - helper to find matching led
  1287. * @hw: pointer to the hw struct
  1288. * @idx: index into GPIO registers
  1289. *
  1290. * returns: 0 if no match, otherwise the value of the GPIO_CTL register
  1291. */
  1292. static u32 i40e_led_is_mine(struct i40e_hw *hw, int idx)
  1293. {
  1294. u32 gpio_val = 0;
  1295. u32 port;
  1296. if (!hw->func_caps.led[idx])
  1297. return 0;
  1298. gpio_val = rd32(hw, I40E_GLGEN_GPIO_CTL(idx));
  1299. port = (gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_MASK) >>
  1300. I40E_GLGEN_GPIO_CTL_PRT_NUM_SHIFT;
  1301. /* if PRT_NUM_NA is 1 then this LED is not port specific, OR
  1302. * if it is not our port then ignore
  1303. */
  1304. if ((gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_NA_MASK) ||
  1305. (port != hw->port))
  1306. return 0;
  1307. return gpio_val;
  1308. }
  1309. #define I40E_COMBINED_ACTIVITY 0xA
  1310. #define I40E_FILTER_ACTIVITY 0xE
  1311. #define I40E_LINK_ACTIVITY 0xC
  1312. #define I40E_MAC_ACTIVITY 0xD
  1313. #define I40E_LED0 22
  1314. /**
  1315. * i40e_led_get - return current on/off mode
  1316. * @hw: pointer to the hw struct
  1317. *
  1318. * The value returned is the 'mode' field as defined in the
  1319. * GPIO register definitions: 0x0 = off, 0xf = on, and other
  1320. * values are variations of possible behaviors relating to
  1321. * blink, link, and wire.
  1322. **/
  1323. u32 i40e_led_get(struct i40e_hw *hw)
  1324. {
  1325. u32 current_mode = 0;
  1326. u32 mode = 0;
  1327. int i;
  1328. /* as per the documentation GPIO 22-29 are the LED
  1329. * GPIO pins named LED0..LED7
  1330. */
  1331. for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
  1332. u32 gpio_val = i40e_led_is_mine(hw, i);
  1333. if (!gpio_val)
  1334. continue;
  1335. /* ignore gpio LED src mode entries related to the activity
  1336. * LEDs
  1337. */
  1338. current_mode = ((gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK)
  1339. >> I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT);
  1340. switch (current_mode) {
  1341. case I40E_COMBINED_ACTIVITY:
  1342. case I40E_FILTER_ACTIVITY:
  1343. case I40E_MAC_ACTIVITY:
  1344. continue;
  1345. default:
  1346. break;
  1347. }
  1348. mode = (gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK) >>
  1349. I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT;
  1350. break;
  1351. }
  1352. return mode;
  1353. }
  1354. /**
  1355. * i40e_led_set - set new on/off mode
  1356. * @hw: pointer to the hw struct
  1357. * @mode: 0=off, 0xf=on (else see manual for mode details)
  1358. * @blink: true if the LED should blink when on, false if steady
  1359. *
  1360. * if this function is used to turn on the blink it should
  1361. * be used to disable the blink when restoring the original state.
  1362. **/
  1363. void i40e_led_set(struct i40e_hw *hw, u32 mode, bool blink)
  1364. {
  1365. u32 current_mode = 0;
  1366. int i;
  1367. if (mode & 0xfffffff0)
  1368. hw_dbg(hw, "invalid mode passed in %X\n", mode);
  1369. /* as per the documentation GPIO 22-29 are the LED
  1370. * GPIO pins named LED0..LED7
  1371. */
  1372. for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
  1373. u32 gpio_val = i40e_led_is_mine(hw, i);
  1374. if (!gpio_val)
  1375. continue;
  1376. /* ignore gpio LED src mode entries related to the activity
  1377. * LEDs
  1378. */
  1379. current_mode = ((gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK)
  1380. >> I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT);
  1381. switch (current_mode) {
  1382. case I40E_COMBINED_ACTIVITY:
  1383. case I40E_FILTER_ACTIVITY:
  1384. case I40E_MAC_ACTIVITY:
  1385. continue;
  1386. default:
  1387. break;
  1388. }
  1389. gpio_val &= ~I40E_GLGEN_GPIO_CTL_LED_MODE_MASK;
  1390. /* this & is a bit of paranoia, but serves as a range check */
  1391. gpio_val |= ((mode << I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT) &
  1392. I40E_GLGEN_GPIO_CTL_LED_MODE_MASK);
  1393. if (mode == I40E_LINK_ACTIVITY)
  1394. blink = false;
  1395. if (blink)
  1396. gpio_val |= BIT(I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
  1397. else
  1398. gpio_val &= ~BIT(I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
  1399. wr32(hw, I40E_GLGEN_GPIO_CTL(i), gpio_val);
  1400. break;
  1401. }
  1402. }
  1403. /* Admin command wrappers */
  1404. /**
  1405. * i40e_aq_get_phy_capabilities
  1406. * @hw: pointer to the hw struct
  1407. * @abilities: structure for PHY capabilities to be filled
  1408. * @qualified_modules: report Qualified Modules
  1409. * @report_init: report init capabilities (active are default)
  1410. * @cmd_details: pointer to command details structure or NULL
  1411. *
  1412. * Returns the various PHY abilities supported on the Port.
  1413. **/
  1414. i40e_status i40e_aq_get_phy_capabilities(struct i40e_hw *hw,
  1415. bool qualified_modules, bool report_init,
  1416. struct i40e_aq_get_phy_abilities_resp *abilities,
  1417. struct i40e_asq_cmd_details *cmd_details)
  1418. {
  1419. struct i40e_aq_desc desc;
  1420. i40e_status status;
  1421. u16 abilities_size = sizeof(struct i40e_aq_get_phy_abilities_resp);
  1422. if (!abilities)
  1423. return I40E_ERR_PARAM;
  1424. i40e_fill_default_direct_cmd_desc(&desc,
  1425. i40e_aqc_opc_get_phy_abilities);
  1426. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  1427. if (abilities_size > I40E_AQ_LARGE_BUF)
  1428. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1429. if (qualified_modules)
  1430. desc.params.external.param0 |=
  1431. cpu_to_le32(I40E_AQ_PHY_REPORT_QUALIFIED_MODULES);
  1432. if (report_init)
  1433. desc.params.external.param0 |=
  1434. cpu_to_le32(I40E_AQ_PHY_REPORT_INITIAL_VALUES);
  1435. status = i40e_asq_send_command(hw, &desc, abilities, abilities_size,
  1436. cmd_details);
  1437. if (hw->aq.asq_last_status == I40E_AQ_RC_EIO)
  1438. status = I40E_ERR_UNKNOWN_PHY;
  1439. if (report_init)
  1440. hw->phy.phy_types = le32_to_cpu(abilities->phy_type);
  1441. return status;
  1442. }
  1443. /**
  1444. * i40e_aq_set_phy_config
  1445. * @hw: pointer to the hw struct
  1446. * @config: structure with PHY configuration to be set
  1447. * @cmd_details: pointer to command details structure or NULL
  1448. *
  1449. * Set the various PHY configuration parameters
  1450. * supported on the Port.One or more of the Set PHY config parameters may be
  1451. * ignored in an MFP mode as the PF may not have the privilege to set some
  1452. * of the PHY Config parameters. This status will be indicated by the
  1453. * command response.
  1454. **/
  1455. enum i40e_status_code i40e_aq_set_phy_config(struct i40e_hw *hw,
  1456. struct i40e_aq_set_phy_config *config,
  1457. struct i40e_asq_cmd_details *cmd_details)
  1458. {
  1459. struct i40e_aq_desc desc;
  1460. struct i40e_aq_set_phy_config *cmd =
  1461. (struct i40e_aq_set_phy_config *)&desc.params.raw;
  1462. enum i40e_status_code status;
  1463. if (!config)
  1464. return I40E_ERR_PARAM;
  1465. i40e_fill_default_direct_cmd_desc(&desc,
  1466. i40e_aqc_opc_set_phy_config);
  1467. *cmd = *config;
  1468. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1469. return status;
  1470. }
  1471. /**
  1472. * i40e_set_fc
  1473. * @hw: pointer to the hw struct
  1474. *
  1475. * Set the requested flow control mode using set_phy_config.
  1476. **/
  1477. enum i40e_status_code i40e_set_fc(struct i40e_hw *hw, u8 *aq_failures,
  1478. bool atomic_restart)
  1479. {
  1480. enum i40e_fc_mode fc_mode = hw->fc.requested_mode;
  1481. struct i40e_aq_get_phy_abilities_resp abilities;
  1482. struct i40e_aq_set_phy_config config;
  1483. enum i40e_status_code status;
  1484. u8 pause_mask = 0x0;
  1485. *aq_failures = 0x0;
  1486. switch (fc_mode) {
  1487. case I40E_FC_FULL:
  1488. pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
  1489. pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
  1490. break;
  1491. case I40E_FC_RX_PAUSE:
  1492. pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
  1493. break;
  1494. case I40E_FC_TX_PAUSE:
  1495. pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
  1496. break;
  1497. default:
  1498. break;
  1499. }
  1500. /* Get the current phy config */
  1501. status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
  1502. NULL);
  1503. if (status) {
  1504. *aq_failures |= I40E_SET_FC_AQ_FAIL_GET;
  1505. return status;
  1506. }
  1507. memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
  1508. /* clear the old pause settings */
  1509. config.abilities = abilities.abilities & ~(I40E_AQ_PHY_FLAG_PAUSE_TX) &
  1510. ~(I40E_AQ_PHY_FLAG_PAUSE_RX);
  1511. /* set the new abilities */
  1512. config.abilities |= pause_mask;
  1513. /* If the abilities have changed, then set the new config */
  1514. if (config.abilities != abilities.abilities) {
  1515. /* Auto restart link so settings take effect */
  1516. if (atomic_restart)
  1517. config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
  1518. /* Copy over all the old settings */
  1519. config.phy_type = abilities.phy_type;
  1520. config.link_speed = abilities.link_speed;
  1521. config.eee_capability = abilities.eee_capability;
  1522. config.eeer = abilities.eeer_val;
  1523. config.low_power_ctrl = abilities.d3_lpan;
  1524. status = i40e_aq_set_phy_config(hw, &config, NULL);
  1525. if (status)
  1526. *aq_failures |= I40E_SET_FC_AQ_FAIL_SET;
  1527. }
  1528. /* Update the link info */
  1529. status = i40e_update_link_info(hw);
  1530. if (status) {
  1531. /* Wait a little bit (on 40G cards it sometimes takes a really
  1532. * long time for link to come back from the atomic reset)
  1533. * and try once more
  1534. */
  1535. msleep(1000);
  1536. status = i40e_update_link_info(hw);
  1537. }
  1538. if (status)
  1539. *aq_failures |= I40E_SET_FC_AQ_FAIL_UPDATE;
  1540. return status;
  1541. }
  1542. /**
  1543. * i40e_aq_clear_pxe_mode
  1544. * @hw: pointer to the hw struct
  1545. * @cmd_details: pointer to command details structure or NULL
  1546. *
  1547. * Tell the firmware that the driver is taking over from PXE
  1548. **/
  1549. i40e_status i40e_aq_clear_pxe_mode(struct i40e_hw *hw,
  1550. struct i40e_asq_cmd_details *cmd_details)
  1551. {
  1552. i40e_status status;
  1553. struct i40e_aq_desc desc;
  1554. struct i40e_aqc_clear_pxe *cmd =
  1555. (struct i40e_aqc_clear_pxe *)&desc.params.raw;
  1556. i40e_fill_default_direct_cmd_desc(&desc,
  1557. i40e_aqc_opc_clear_pxe_mode);
  1558. cmd->rx_cnt = 0x2;
  1559. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1560. wr32(hw, I40E_GLLAN_RCTL_0, 0x1);
  1561. return status;
  1562. }
  1563. /**
  1564. * i40e_aq_set_link_restart_an
  1565. * @hw: pointer to the hw struct
  1566. * @enable_link: if true: enable link, if false: disable link
  1567. * @cmd_details: pointer to command details structure or NULL
  1568. *
  1569. * Sets up the link and restarts the Auto-Negotiation over the link.
  1570. **/
  1571. i40e_status i40e_aq_set_link_restart_an(struct i40e_hw *hw,
  1572. bool enable_link,
  1573. struct i40e_asq_cmd_details *cmd_details)
  1574. {
  1575. struct i40e_aq_desc desc;
  1576. struct i40e_aqc_set_link_restart_an *cmd =
  1577. (struct i40e_aqc_set_link_restart_an *)&desc.params.raw;
  1578. i40e_status status;
  1579. i40e_fill_default_direct_cmd_desc(&desc,
  1580. i40e_aqc_opc_set_link_restart_an);
  1581. cmd->command = I40E_AQ_PHY_RESTART_AN;
  1582. if (enable_link)
  1583. cmd->command |= I40E_AQ_PHY_LINK_ENABLE;
  1584. else
  1585. cmd->command &= ~I40E_AQ_PHY_LINK_ENABLE;
  1586. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1587. return status;
  1588. }
  1589. /**
  1590. * i40e_aq_get_link_info
  1591. * @hw: pointer to the hw struct
  1592. * @enable_lse: enable/disable LinkStatusEvent reporting
  1593. * @link: pointer to link status structure - optional
  1594. * @cmd_details: pointer to command details structure or NULL
  1595. *
  1596. * Returns the link status of the adapter.
  1597. **/
  1598. i40e_status i40e_aq_get_link_info(struct i40e_hw *hw,
  1599. bool enable_lse, struct i40e_link_status *link,
  1600. struct i40e_asq_cmd_details *cmd_details)
  1601. {
  1602. struct i40e_aq_desc desc;
  1603. struct i40e_aqc_get_link_status *resp =
  1604. (struct i40e_aqc_get_link_status *)&desc.params.raw;
  1605. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  1606. i40e_status status;
  1607. bool tx_pause, rx_pause;
  1608. u16 command_flags;
  1609. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_link_status);
  1610. if (enable_lse)
  1611. command_flags = I40E_AQ_LSE_ENABLE;
  1612. else
  1613. command_flags = I40E_AQ_LSE_DISABLE;
  1614. resp->command_flags = cpu_to_le16(command_flags);
  1615. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1616. if (status)
  1617. goto aq_get_link_info_exit;
  1618. /* save off old link status information */
  1619. hw->phy.link_info_old = *hw_link_info;
  1620. /* update link status */
  1621. hw_link_info->phy_type = (enum i40e_aq_phy_type)resp->phy_type;
  1622. hw->phy.media_type = i40e_get_media_type(hw);
  1623. hw_link_info->link_speed = (enum i40e_aq_link_speed)resp->link_speed;
  1624. hw_link_info->link_info = resp->link_info;
  1625. hw_link_info->an_info = resp->an_info;
  1626. hw_link_info->ext_info = resp->ext_info;
  1627. hw_link_info->loopback = resp->loopback;
  1628. hw_link_info->max_frame_size = le16_to_cpu(resp->max_frame_size);
  1629. hw_link_info->pacing = resp->config & I40E_AQ_CONFIG_PACING_MASK;
  1630. /* update fc info */
  1631. tx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_TX);
  1632. rx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_RX);
  1633. if (tx_pause & rx_pause)
  1634. hw->fc.current_mode = I40E_FC_FULL;
  1635. else if (tx_pause)
  1636. hw->fc.current_mode = I40E_FC_TX_PAUSE;
  1637. else if (rx_pause)
  1638. hw->fc.current_mode = I40E_FC_RX_PAUSE;
  1639. else
  1640. hw->fc.current_mode = I40E_FC_NONE;
  1641. if (resp->config & I40E_AQ_CONFIG_CRC_ENA)
  1642. hw_link_info->crc_enable = true;
  1643. else
  1644. hw_link_info->crc_enable = false;
  1645. if (resp->command_flags & cpu_to_le16(I40E_AQ_LSE_ENABLE))
  1646. hw_link_info->lse_enable = true;
  1647. else
  1648. hw_link_info->lse_enable = false;
  1649. if ((hw->aq.fw_maj_ver < 4 || (hw->aq.fw_maj_ver == 4 &&
  1650. hw->aq.fw_min_ver < 40)) && hw_link_info->phy_type == 0xE)
  1651. hw_link_info->phy_type = I40E_PHY_TYPE_10GBASE_SFPP_CU;
  1652. /* save link status information */
  1653. if (link)
  1654. *link = *hw_link_info;
  1655. /* flag cleared so helper functions don't call AQ again */
  1656. hw->phy.get_link_info = false;
  1657. aq_get_link_info_exit:
  1658. return status;
  1659. }
  1660. /**
  1661. * i40e_aq_set_phy_int_mask
  1662. * @hw: pointer to the hw struct
  1663. * @mask: interrupt mask to be set
  1664. * @cmd_details: pointer to command details structure or NULL
  1665. *
  1666. * Set link interrupt mask.
  1667. **/
  1668. i40e_status i40e_aq_set_phy_int_mask(struct i40e_hw *hw,
  1669. u16 mask,
  1670. struct i40e_asq_cmd_details *cmd_details)
  1671. {
  1672. struct i40e_aq_desc desc;
  1673. struct i40e_aqc_set_phy_int_mask *cmd =
  1674. (struct i40e_aqc_set_phy_int_mask *)&desc.params.raw;
  1675. i40e_status status;
  1676. i40e_fill_default_direct_cmd_desc(&desc,
  1677. i40e_aqc_opc_set_phy_int_mask);
  1678. cmd->event_mask = cpu_to_le16(mask);
  1679. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1680. return status;
  1681. }
  1682. /**
  1683. * i40e_aq_add_vsi
  1684. * @hw: pointer to the hw struct
  1685. * @vsi_ctx: pointer to a vsi context struct
  1686. * @cmd_details: pointer to command details structure or NULL
  1687. *
  1688. * Add a VSI context to the hardware.
  1689. **/
  1690. i40e_status i40e_aq_add_vsi(struct i40e_hw *hw,
  1691. struct i40e_vsi_context *vsi_ctx,
  1692. struct i40e_asq_cmd_details *cmd_details)
  1693. {
  1694. struct i40e_aq_desc desc;
  1695. struct i40e_aqc_add_get_update_vsi *cmd =
  1696. (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
  1697. struct i40e_aqc_add_get_update_vsi_completion *resp =
  1698. (struct i40e_aqc_add_get_update_vsi_completion *)
  1699. &desc.params.raw;
  1700. i40e_status status;
  1701. i40e_fill_default_direct_cmd_desc(&desc,
  1702. i40e_aqc_opc_add_vsi);
  1703. cmd->uplink_seid = cpu_to_le16(vsi_ctx->uplink_seid);
  1704. cmd->connection_type = vsi_ctx->connection_type;
  1705. cmd->vf_id = vsi_ctx->vf_num;
  1706. cmd->vsi_flags = cpu_to_le16(vsi_ctx->flags);
  1707. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  1708. status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
  1709. sizeof(vsi_ctx->info), cmd_details);
  1710. if (status)
  1711. goto aq_add_vsi_exit;
  1712. vsi_ctx->seid = le16_to_cpu(resp->seid);
  1713. vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
  1714. vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
  1715. vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
  1716. aq_add_vsi_exit:
  1717. return status;
  1718. }
  1719. /**
  1720. * i40e_aq_set_vsi_unicast_promiscuous
  1721. * @hw: pointer to the hw struct
  1722. * @seid: vsi number
  1723. * @set: set unicast promiscuous enable/disable
  1724. * @cmd_details: pointer to command details structure or NULL
  1725. **/
  1726. i40e_status i40e_aq_set_vsi_unicast_promiscuous(struct i40e_hw *hw,
  1727. u16 seid, bool set,
  1728. struct i40e_asq_cmd_details *cmd_details)
  1729. {
  1730. struct i40e_aq_desc desc;
  1731. struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
  1732. (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
  1733. i40e_status status;
  1734. u16 flags = 0;
  1735. i40e_fill_default_direct_cmd_desc(&desc,
  1736. i40e_aqc_opc_set_vsi_promiscuous_modes);
  1737. if (set)
  1738. flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
  1739. cmd->promiscuous_flags = cpu_to_le16(flags);
  1740. cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
  1741. cmd->seid = cpu_to_le16(seid);
  1742. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1743. return status;
  1744. }
  1745. /**
  1746. * i40e_aq_set_vsi_multicast_promiscuous
  1747. * @hw: pointer to the hw struct
  1748. * @seid: vsi number
  1749. * @set: set multicast promiscuous enable/disable
  1750. * @cmd_details: pointer to command details structure or NULL
  1751. **/
  1752. i40e_status i40e_aq_set_vsi_multicast_promiscuous(struct i40e_hw *hw,
  1753. u16 seid, bool set, struct i40e_asq_cmd_details *cmd_details)
  1754. {
  1755. struct i40e_aq_desc desc;
  1756. struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
  1757. (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
  1758. i40e_status status;
  1759. u16 flags = 0;
  1760. i40e_fill_default_direct_cmd_desc(&desc,
  1761. i40e_aqc_opc_set_vsi_promiscuous_modes);
  1762. if (set)
  1763. flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
  1764. cmd->promiscuous_flags = cpu_to_le16(flags);
  1765. cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
  1766. cmd->seid = cpu_to_le16(seid);
  1767. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1768. return status;
  1769. }
  1770. /**
  1771. * i40e_aq_set_vsi_broadcast
  1772. * @hw: pointer to the hw struct
  1773. * @seid: vsi number
  1774. * @set_filter: true to set filter, false to clear filter
  1775. * @cmd_details: pointer to command details structure or NULL
  1776. *
  1777. * Set or clear the broadcast promiscuous flag (filter) for a given VSI.
  1778. **/
  1779. i40e_status i40e_aq_set_vsi_broadcast(struct i40e_hw *hw,
  1780. u16 seid, bool set_filter,
  1781. struct i40e_asq_cmd_details *cmd_details)
  1782. {
  1783. struct i40e_aq_desc desc;
  1784. struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
  1785. (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
  1786. i40e_status status;
  1787. i40e_fill_default_direct_cmd_desc(&desc,
  1788. i40e_aqc_opc_set_vsi_promiscuous_modes);
  1789. if (set_filter)
  1790. cmd->promiscuous_flags
  1791. |= cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
  1792. else
  1793. cmd->promiscuous_flags
  1794. &= cpu_to_le16(~I40E_AQC_SET_VSI_PROMISC_BROADCAST);
  1795. cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
  1796. cmd->seid = cpu_to_le16(seid);
  1797. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1798. return status;
  1799. }
  1800. /**
  1801. * i40e_get_vsi_params - get VSI configuration info
  1802. * @hw: pointer to the hw struct
  1803. * @vsi_ctx: pointer to a vsi context struct
  1804. * @cmd_details: pointer to command details structure or NULL
  1805. **/
  1806. i40e_status i40e_aq_get_vsi_params(struct i40e_hw *hw,
  1807. struct i40e_vsi_context *vsi_ctx,
  1808. struct i40e_asq_cmd_details *cmd_details)
  1809. {
  1810. struct i40e_aq_desc desc;
  1811. struct i40e_aqc_add_get_update_vsi *cmd =
  1812. (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
  1813. struct i40e_aqc_add_get_update_vsi_completion *resp =
  1814. (struct i40e_aqc_add_get_update_vsi_completion *)
  1815. &desc.params.raw;
  1816. i40e_status status;
  1817. i40e_fill_default_direct_cmd_desc(&desc,
  1818. i40e_aqc_opc_get_vsi_parameters);
  1819. cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
  1820. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  1821. status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
  1822. sizeof(vsi_ctx->info), NULL);
  1823. if (status)
  1824. goto aq_get_vsi_params_exit;
  1825. vsi_ctx->seid = le16_to_cpu(resp->seid);
  1826. vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
  1827. vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
  1828. vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
  1829. aq_get_vsi_params_exit:
  1830. return status;
  1831. }
  1832. /**
  1833. * i40e_aq_update_vsi_params
  1834. * @hw: pointer to the hw struct
  1835. * @vsi_ctx: pointer to a vsi context struct
  1836. * @cmd_details: pointer to command details structure or NULL
  1837. *
  1838. * Update a VSI context.
  1839. **/
  1840. i40e_status i40e_aq_update_vsi_params(struct i40e_hw *hw,
  1841. struct i40e_vsi_context *vsi_ctx,
  1842. struct i40e_asq_cmd_details *cmd_details)
  1843. {
  1844. struct i40e_aq_desc desc;
  1845. struct i40e_aqc_add_get_update_vsi *cmd =
  1846. (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
  1847. i40e_status status;
  1848. i40e_fill_default_direct_cmd_desc(&desc,
  1849. i40e_aqc_opc_update_vsi_parameters);
  1850. cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
  1851. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  1852. status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
  1853. sizeof(vsi_ctx->info), cmd_details);
  1854. return status;
  1855. }
  1856. /**
  1857. * i40e_aq_get_switch_config
  1858. * @hw: pointer to the hardware structure
  1859. * @buf: pointer to the result buffer
  1860. * @buf_size: length of input buffer
  1861. * @start_seid: seid to start for the report, 0 == beginning
  1862. * @cmd_details: pointer to command details structure or NULL
  1863. *
  1864. * Fill the buf with switch configuration returned from AdminQ command
  1865. **/
  1866. i40e_status i40e_aq_get_switch_config(struct i40e_hw *hw,
  1867. struct i40e_aqc_get_switch_config_resp *buf,
  1868. u16 buf_size, u16 *start_seid,
  1869. struct i40e_asq_cmd_details *cmd_details)
  1870. {
  1871. struct i40e_aq_desc desc;
  1872. struct i40e_aqc_switch_seid *scfg =
  1873. (struct i40e_aqc_switch_seid *)&desc.params.raw;
  1874. i40e_status status;
  1875. i40e_fill_default_direct_cmd_desc(&desc,
  1876. i40e_aqc_opc_get_switch_config);
  1877. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  1878. if (buf_size > I40E_AQ_LARGE_BUF)
  1879. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1880. scfg->seid = cpu_to_le16(*start_seid);
  1881. status = i40e_asq_send_command(hw, &desc, buf, buf_size, cmd_details);
  1882. *start_seid = le16_to_cpu(scfg->seid);
  1883. return status;
  1884. }
  1885. /**
  1886. * i40e_aq_get_firmware_version
  1887. * @hw: pointer to the hw struct
  1888. * @fw_major_version: firmware major version
  1889. * @fw_minor_version: firmware minor version
  1890. * @fw_build: firmware build number
  1891. * @api_major_version: major queue version
  1892. * @api_minor_version: minor queue version
  1893. * @cmd_details: pointer to command details structure or NULL
  1894. *
  1895. * Get the firmware version from the admin queue commands
  1896. **/
  1897. i40e_status i40e_aq_get_firmware_version(struct i40e_hw *hw,
  1898. u16 *fw_major_version, u16 *fw_minor_version,
  1899. u32 *fw_build,
  1900. u16 *api_major_version, u16 *api_minor_version,
  1901. struct i40e_asq_cmd_details *cmd_details)
  1902. {
  1903. struct i40e_aq_desc desc;
  1904. struct i40e_aqc_get_version *resp =
  1905. (struct i40e_aqc_get_version *)&desc.params.raw;
  1906. i40e_status status;
  1907. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_version);
  1908. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1909. if (!status) {
  1910. if (fw_major_version)
  1911. *fw_major_version = le16_to_cpu(resp->fw_major);
  1912. if (fw_minor_version)
  1913. *fw_minor_version = le16_to_cpu(resp->fw_minor);
  1914. if (fw_build)
  1915. *fw_build = le32_to_cpu(resp->fw_build);
  1916. if (api_major_version)
  1917. *api_major_version = le16_to_cpu(resp->api_major);
  1918. if (api_minor_version)
  1919. *api_minor_version = le16_to_cpu(resp->api_minor);
  1920. }
  1921. return status;
  1922. }
  1923. /**
  1924. * i40e_aq_send_driver_version
  1925. * @hw: pointer to the hw struct
  1926. * @dv: driver's major, minor version
  1927. * @cmd_details: pointer to command details structure or NULL
  1928. *
  1929. * Send the driver version to the firmware
  1930. **/
  1931. i40e_status i40e_aq_send_driver_version(struct i40e_hw *hw,
  1932. struct i40e_driver_version *dv,
  1933. struct i40e_asq_cmd_details *cmd_details)
  1934. {
  1935. struct i40e_aq_desc desc;
  1936. struct i40e_aqc_driver_version *cmd =
  1937. (struct i40e_aqc_driver_version *)&desc.params.raw;
  1938. i40e_status status;
  1939. u16 len;
  1940. if (dv == NULL)
  1941. return I40E_ERR_PARAM;
  1942. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_driver_version);
  1943. desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
  1944. cmd->driver_major_ver = dv->major_version;
  1945. cmd->driver_minor_ver = dv->minor_version;
  1946. cmd->driver_build_ver = dv->build_version;
  1947. cmd->driver_subbuild_ver = dv->subbuild_version;
  1948. len = 0;
  1949. while (len < sizeof(dv->driver_string) &&
  1950. (dv->driver_string[len] < 0x80) &&
  1951. dv->driver_string[len])
  1952. len++;
  1953. status = i40e_asq_send_command(hw, &desc, dv->driver_string,
  1954. len, cmd_details);
  1955. return status;
  1956. }
  1957. /**
  1958. * i40e_get_link_status - get status of the HW network link
  1959. * @hw: pointer to the hw struct
  1960. * @link_up: pointer to bool (true/false = linkup/linkdown)
  1961. *
  1962. * Variable link_up true if link is up, false if link is down.
  1963. * The variable link_up is invalid if returned value of status != 0
  1964. *
  1965. * Side effect: LinkStatusEvent reporting becomes enabled
  1966. **/
  1967. i40e_status i40e_get_link_status(struct i40e_hw *hw, bool *link_up)
  1968. {
  1969. i40e_status status = 0;
  1970. if (hw->phy.get_link_info) {
  1971. status = i40e_update_link_info(hw);
  1972. if (status)
  1973. i40e_debug(hw, I40E_DEBUG_LINK, "get link failed: status %d\n",
  1974. status);
  1975. }
  1976. *link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
  1977. return status;
  1978. }
  1979. /**
  1980. * i40e_updatelink_status - update status of the HW network link
  1981. * @hw: pointer to the hw struct
  1982. **/
  1983. i40e_status i40e_update_link_info(struct i40e_hw *hw)
  1984. {
  1985. struct i40e_aq_get_phy_abilities_resp abilities;
  1986. i40e_status status = 0;
  1987. status = i40e_aq_get_link_info(hw, true, NULL, NULL);
  1988. if (status)
  1989. return status;
  1990. if (hw->phy.link_info.link_info & I40E_AQ_MEDIA_AVAILABLE) {
  1991. status = i40e_aq_get_phy_capabilities(hw, false, false,
  1992. &abilities, NULL);
  1993. if (status)
  1994. return status;
  1995. memcpy(hw->phy.link_info.module_type, &abilities.module_type,
  1996. sizeof(hw->phy.link_info.module_type));
  1997. }
  1998. return status;
  1999. }
  2000. /**
  2001. * i40e_aq_add_veb - Insert a VEB between the VSI and the MAC
  2002. * @hw: pointer to the hw struct
  2003. * @uplink_seid: the MAC or other gizmo SEID
  2004. * @downlink_seid: the VSI SEID
  2005. * @enabled_tc: bitmap of TCs to be enabled
  2006. * @default_port: true for default port VSI, false for control port
  2007. * @enable_l2_filtering: true to add L2 filter table rules to regular forwarding rules for cloud support
  2008. * @veb_seid: pointer to where to put the resulting VEB SEID
  2009. * @cmd_details: pointer to command details structure or NULL
  2010. *
  2011. * This asks the FW to add a VEB between the uplink and downlink
  2012. * elements. If the uplink SEID is 0, this will be a floating VEB.
  2013. **/
  2014. i40e_status i40e_aq_add_veb(struct i40e_hw *hw, u16 uplink_seid,
  2015. u16 downlink_seid, u8 enabled_tc,
  2016. bool default_port, bool enable_l2_filtering,
  2017. u16 *veb_seid,
  2018. struct i40e_asq_cmd_details *cmd_details)
  2019. {
  2020. struct i40e_aq_desc desc;
  2021. struct i40e_aqc_add_veb *cmd =
  2022. (struct i40e_aqc_add_veb *)&desc.params.raw;
  2023. struct i40e_aqc_add_veb_completion *resp =
  2024. (struct i40e_aqc_add_veb_completion *)&desc.params.raw;
  2025. i40e_status status;
  2026. u16 veb_flags = 0;
  2027. /* SEIDs need to either both be set or both be 0 for floating VEB */
  2028. if (!!uplink_seid != !!downlink_seid)
  2029. return I40E_ERR_PARAM;
  2030. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_veb);
  2031. cmd->uplink_seid = cpu_to_le16(uplink_seid);
  2032. cmd->downlink_seid = cpu_to_le16(downlink_seid);
  2033. cmd->enable_tcs = enabled_tc;
  2034. if (!uplink_seid)
  2035. veb_flags |= I40E_AQC_ADD_VEB_FLOATING;
  2036. if (default_port)
  2037. veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DEFAULT;
  2038. else
  2039. veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DATA;
  2040. if (enable_l2_filtering)
  2041. veb_flags |= I40E_AQC_ADD_VEB_ENABLE_L2_FILTER;
  2042. cmd->veb_flags = cpu_to_le16(veb_flags);
  2043. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2044. if (!status && veb_seid)
  2045. *veb_seid = le16_to_cpu(resp->veb_seid);
  2046. return status;
  2047. }
  2048. /**
  2049. * i40e_aq_get_veb_parameters - Retrieve VEB parameters
  2050. * @hw: pointer to the hw struct
  2051. * @veb_seid: the SEID of the VEB to query
  2052. * @switch_id: the uplink switch id
  2053. * @floating: set to true if the VEB is floating
  2054. * @statistic_index: index of the stats counter block for this VEB
  2055. * @vebs_used: number of VEB's used by function
  2056. * @vebs_free: total VEB's not reserved by any function
  2057. * @cmd_details: pointer to command details structure or NULL
  2058. *
  2059. * This retrieves the parameters for a particular VEB, specified by
  2060. * uplink_seid, and returns them to the caller.
  2061. **/
  2062. i40e_status i40e_aq_get_veb_parameters(struct i40e_hw *hw,
  2063. u16 veb_seid, u16 *switch_id,
  2064. bool *floating, u16 *statistic_index,
  2065. u16 *vebs_used, u16 *vebs_free,
  2066. struct i40e_asq_cmd_details *cmd_details)
  2067. {
  2068. struct i40e_aq_desc desc;
  2069. struct i40e_aqc_get_veb_parameters_completion *cmd_resp =
  2070. (struct i40e_aqc_get_veb_parameters_completion *)
  2071. &desc.params.raw;
  2072. i40e_status status;
  2073. if (veb_seid == 0)
  2074. return I40E_ERR_PARAM;
  2075. i40e_fill_default_direct_cmd_desc(&desc,
  2076. i40e_aqc_opc_get_veb_parameters);
  2077. cmd_resp->seid = cpu_to_le16(veb_seid);
  2078. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2079. if (status)
  2080. goto get_veb_exit;
  2081. if (switch_id)
  2082. *switch_id = le16_to_cpu(cmd_resp->switch_id);
  2083. if (statistic_index)
  2084. *statistic_index = le16_to_cpu(cmd_resp->statistic_index);
  2085. if (vebs_used)
  2086. *vebs_used = le16_to_cpu(cmd_resp->vebs_used);
  2087. if (vebs_free)
  2088. *vebs_free = le16_to_cpu(cmd_resp->vebs_free);
  2089. if (floating) {
  2090. u16 flags = le16_to_cpu(cmd_resp->veb_flags);
  2091. if (flags & I40E_AQC_ADD_VEB_FLOATING)
  2092. *floating = true;
  2093. else
  2094. *floating = false;
  2095. }
  2096. get_veb_exit:
  2097. return status;
  2098. }
  2099. /**
  2100. * i40e_aq_add_macvlan
  2101. * @hw: pointer to the hw struct
  2102. * @seid: VSI for the mac address
  2103. * @mv_list: list of macvlans to be added
  2104. * @count: length of the list
  2105. * @cmd_details: pointer to command details structure or NULL
  2106. *
  2107. * Add MAC/VLAN addresses to the HW filtering
  2108. **/
  2109. i40e_status i40e_aq_add_macvlan(struct i40e_hw *hw, u16 seid,
  2110. struct i40e_aqc_add_macvlan_element_data *mv_list,
  2111. u16 count, struct i40e_asq_cmd_details *cmd_details)
  2112. {
  2113. struct i40e_aq_desc desc;
  2114. struct i40e_aqc_macvlan *cmd =
  2115. (struct i40e_aqc_macvlan *)&desc.params.raw;
  2116. i40e_status status;
  2117. u16 buf_size;
  2118. if (count == 0 || !mv_list || !hw)
  2119. return I40E_ERR_PARAM;
  2120. buf_size = count * sizeof(*mv_list);
  2121. /* prep the rest of the request */
  2122. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_macvlan);
  2123. cmd->num_addresses = cpu_to_le16(count);
  2124. cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
  2125. cmd->seid[1] = 0;
  2126. cmd->seid[2] = 0;
  2127. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  2128. if (buf_size > I40E_AQ_LARGE_BUF)
  2129. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2130. status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
  2131. cmd_details);
  2132. return status;
  2133. }
  2134. /**
  2135. * i40e_aq_remove_macvlan
  2136. * @hw: pointer to the hw struct
  2137. * @seid: VSI for the mac address
  2138. * @mv_list: list of macvlans to be removed
  2139. * @count: length of the list
  2140. * @cmd_details: pointer to command details structure or NULL
  2141. *
  2142. * Remove MAC/VLAN addresses from the HW filtering
  2143. **/
  2144. i40e_status i40e_aq_remove_macvlan(struct i40e_hw *hw, u16 seid,
  2145. struct i40e_aqc_remove_macvlan_element_data *mv_list,
  2146. u16 count, struct i40e_asq_cmd_details *cmd_details)
  2147. {
  2148. struct i40e_aq_desc desc;
  2149. struct i40e_aqc_macvlan *cmd =
  2150. (struct i40e_aqc_macvlan *)&desc.params.raw;
  2151. i40e_status status;
  2152. u16 buf_size;
  2153. if (count == 0 || !mv_list || !hw)
  2154. return I40E_ERR_PARAM;
  2155. buf_size = count * sizeof(*mv_list);
  2156. /* prep the rest of the request */
  2157. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_macvlan);
  2158. cmd->num_addresses = cpu_to_le16(count);
  2159. cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
  2160. cmd->seid[1] = 0;
  2161. cmd->seid[2] = 0;
  2162. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  2163. if (buf_size > I40E_AQ_LARGE_BUF)
  2164. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2165. status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
  2166. cmd_details);
  2167. return status;
  2168. }
  2169. /**
  2170. * i40e_aq_send_msg_to_vf
  2171. * @hw: pointer to the hardware structure
  2172. * @vfid: VF id to send msg
  2173. * @v_opcode: opcodes for VF-PF communication
  2174. * @v_retval: return error code
  2175. * @msg: pointer to the msg buffer
  2176. * @msglen: msg length
  2177. * @cmd_details: pointer to command details
  2178. *
  2179. * send msg to vf
  2180. **/
  2181. i40e_status i40e_aq_send_msg_to_vf(struct i40e_hw *hw, u16 vfid,
  2182. u32 v_opcode, u32 v_retval, u8 *msg, u16 msglen,
  2183. struct i40e_asq_cmd_details *cmd_details)
  2184. {
  2185. struct i40e_aq_desc desc;
  2186. struct i40e_aqc_pf_vf_message *cmd =
  2187. (struct i40e_aqc_pf_vf_message *)&desc.params.raw;
  2188. i40e_status status;
  2189. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_vf);
  2190. cmd->id = cpu_to_le32(vfid);
  2191. desc.cookie_high = cpu_to_le32(v_opcode);
  2192. desc.cookie_low = cpu_to_le32(v_retval);
  2193. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_SI);
  2194. if (msglen) {
  2195. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
  2196. I40E_AQ_FLAG_RD));
  2197. if (msglen > I40E_AQ_LARGE_BUF)
  2198. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2199. desc.datalen = cpu_to_le16(msglen);
  2200. }
  2201. status = i40e_asq_send_command(hw, &desc, msg, msglen, cmd_details);
  2202. return status;
  2203. }
  2204. /**
  2205. * i40e_aq_debug_read_register
  2206. * @hw: pointer to the hw struct
  2207. * @reg_addr: register address
  2208. * @reg_val: register value
  2209. * @cmd_details: pointer to command details structure or NULL
  2210. *
  2211. * Read the register using the admin queue commands
  2212. **/
  2213. i40e_status i40e_aq_debug_read_register(struct i40e_hw *hw,
  2214. u32 reg_addr, u64 *reg_val,
  2215. struct i40e_asq_cmd_details *cmd_details)
  2216. {
  2217. struct i40e_aq_desc desc;
  2218. struct i40e_aqc_debug_reg_read_write *cmd_resp =
  2219. (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
  2220. i40e_status status;
  2221. if (reg_val == NULL)
  2222. return I40E_ERR_PARAM;
  2223. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_read_reg);
  2224. cmd_resp->address = cpu_to_le32(reg_addr);
  2225. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2226. if (!status) {
  2227. *reg_val = ((u64)le32_to_cpu(cmd_resp->value_high) << 32) |
  2228. (u64)le32_to_cpu(cmd_resp->value_low);
  2229. }
  2230. return status;
  2231. }
  2232. /**
  2233. * i40e_aq_debug_write_register
  2234. * @hw: pointer to the hw struct
  2235. * @reg_addr: register address
  2236. * @reg_val: register value
  2237. * @cmd_details: pointer to command details structure or NULL
  2238. *
  2239. * Write to a register using the admin queue commands
  2240. **/
  2241. i40e_status i40e_aq_debug_write_register(struct i40e_hw *hw,
  2242. u32 reg_addr, u64 reg_val,
  2243. struct i40e_asq_cmd_details *cmd_details)
  2244. {
  2245. struct i40e_aq_desc desc;
  2246. struct i40e_aqc_debug_reg_read_write *cmd =
  2247. (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
  2248. i40e_status status;
  2249. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_write_reg);
  2250. cmd->address = cpu_to_le32(reg_addr);
  2251. cmd->value_high = cpu_to_le32((u32)(reg_val >> 32));
  2252. cmd->value_low = cpu_to_le32((u32)(reg_val & 0xFFFFFFFF));
  2253. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2254. return status;
  2255. }
  2256. /**
  2257. * i40e_aq_set_hmc_resource_profile
  2258. * @hw: pointer to the hw struct
  2259. * @profile: type of profile the HMC is to be set as
  2260. * @pe_vf_enabled_count: the number of PE enabled VFs the system has
  2261. * @cmd_details: pointer to command details structure or NULL
  2262. *
  2263. * set the HMC profile of the device.
  2264. **/
  2265. i40e_status i40e_aq_set_hmc_resource_profile(struct i40e_hw *hw,
  2266. enum i40e_aq_hmc_profile profile,
  2267. u8 pe_vf_enabled_count,
  2268. struct i40e_asq_cmd_details *cmd_details)
  2269. {
  2270. struct i40e_aq_desc desc;
  2271. struct i40e_aq_get_set_hmc_resource_profile *cmd =
  2272. (struct i40e_aq_get_set_hmc_resource_profile *)&desc.params.raw;
  2273. i40e_status status;
  2274. i40e_fill_default_direct_cmd_desc(&desc,
  2275. i40e_aqc_opc_set_hmc_resource_profile);
  2276. cmd->pm_profile = (u8)profile;
  2277. cmd->pe_vf_enabled = pe_vf_enabled_count;
  2278. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2279. return status;
  2280. }
  2281. /**
  2282. * i40e_aq_request_resource
  2283. * @hw: pointer to the hw struct
  2284. * @resource: resource id
  2285. * @access: access type
  2286. * @sdp_number: resource number
  2287. * @timeout: the maximum time in ms that the driver may hold the resource
  2288. * @cmd_details: pointer to command details structure or NULL
  2289. *
  2290. * requests common resource using the admin queue commands
  2291. **/
  2292. i40e_status i40e_aq_request_resource(struct i40e_hw *hw,
  2293. enum i40e_aq_resources_ids resource,
  2294. enum i40e_aq_resource_access_type access,
  2295. u8 sdp_number, u64 *timeout,
  2296. struct i40e_asq_cmd_details *cmd_details)
  2297. {
  2298. struct i40e_aq_desc desc;
  2299. struct i40e_aqc_request_resource *cmd_resp =
  2300. (struct i40e_aqc_request_resource *)&desc.params.raw;
  2301. i40e_status status;
  2302. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_request_resource);
  2303. cmd_resp->resource_id = cpu_to_le16(resource);
  2304. cmd_resp->access_type = cpu_to_le16(access);
  2305. cmd_resp->resource_number = cpu_to_le32(sdp_number);
  2306. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2307. /* The completion specifies the maximum time in ms that the driver
  2308. * may hold the resource in the Timeout field.
  2309. * If the resource is held by someone else, the command completes with
  2310. * busy return value and the timeout field indicates the maximum time
  2311. * the current owner of the resource has to free it.
  2312. */
  2313. if (!status || hw->aq.asq_last_status == I40E_AQ_RC_EBUSY)
  2314. *timeout = le32_to_cpu(cmd_resp->timeout);
  2315. return status;
  2316. }
  2317. /**
  2318. * i40e_aq_release_resource
  2319. * @hw: pointer to the hw struct
  2320. * @resource: resource id
  2321. * @sdp_number: resource number
  2322. * @cmd_details: pointer to command details structure or NULL
  2323. *
  2324. * release common resource using the admin queue commands
  2325. **/
  2326. i40e_status i40e_aq_release_resource(struct i40e_hw *hw,
  2327. enum i40e_aq_resources_ids resource,
  2328. u8 sdp_number,
  2329. struct i40e_asq_cmd_details *cmd_details)
  2330. {
  2331. struct i40e_aq_desc desc;
  2332. struct i40e_aqc_request_resource *cmd =
  2333. (struct i40e_aqc_request_resource *)&desc.params.raw;
  2334. i40e_status status;
  2335. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_release_resource);
  2336. cmd->resource_id = cpu_to_le16(resource);
  2337. cmd->resource_number = cpu_to_le32(sdp_number);
  2338. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2339. return status;
  2340. }
  2341. /**
  2342. * i40e_aq_read_nvm
  2343. * @hw: pointer to the hw struct
  2344. * @module_pointer: module pointer location in words from the NVM beginning
  2345. * @offset: byte offset from the module beginning
  2346. * @length: length of the section to be read (in bytes from the offset)
  2347. * @data: command buffer (size [bytes] = length)
  2348. * @last_command: tells if this is the last command in a series
  2349. * @cmd_details: pointer to command details structure or NULL
  2350. *
  2351. * Read the NVM using the admin queue commands
  2352. **/
  2353. i40e_status i40e_aq_read_nvm(struct i40e_hw *hw, u8 module_pointer,
  2354. u32 offset, u16 length, void *data,
  2355. bool last_command,
  2356. struct i40e_asq_cmd_details *cmd_details)
  2357. {
  2358. struct i40e_aq_desc desc;
  2359. struct i40e_aqc_nvm_update *cmd =
  2360. (struct i40e_aqc_nvm_update *)&desc.params.raw;
  2361. i40e_status status;
  2362. /* In offset the highest byte must be zeroed. */
  2363. if (offset & 0xFF000000) {
  2364. status = I40E_ERR_PARAM;
  2365. goto i40e_aq_read_nvm_exit;
  2366. }
  2367. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_read);
  2368. /* If this is the last command in a series, set the proper flag. */
  2369. if (last_command)
  2370. cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
  2371. cmd->module_pointer = module_pointer;
  2372. cmd->offset = cpu_to_le32(offset);
  2373. cmd->length = cpu_to_le16(length);
  2374. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2375. if (length > I40E_AQ_LARGE_BUF)
  2376. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2377. status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
  2378. i40e_aq_read_nvm_exit:
  2379. return status;
  2380. }
  2381. /**
  2382. * i40e_aq_erase_nvm
  2383. * @hw: pointer to the hw struct
  2384. * @module_pointer: module pointer location in words from the NVM beginning
  2385. * @offset: offset in the module (expressed in 4 KB from module's beginning)
  2386. * @length: length of the section to be erased (expressed in 4 KB)
  2387. * @last_command: tells if this is the last command in a series
  2388. * @cmd_details: pointer to command details structure or NULL
  2389. *
  2390. * Erase the NVM sector using the admin queue commands
  2391. **/
  2392. i40e_status i40e_aq_erase_nvm(struct i40e_hw *hw, u8 module_pointer,
  2393. u32 offset, u16 length, bool last_command,
  2394. struct i40e_asq_cmd_details *cmd_details)
  2395. {
  2396. struct i40e_aq_desc desc;
  2397. struct i40e_aqc_nvm_update *cmd =
  2398. (struct i40e_aqc_nvm_update *)&desc.params.raw;
  2399. i40e_status status;
  2400. /* In offset the highest byte must be zeroed. */
  2401. if (offset & 0xFF000000) {
  2402. status = I40E_ERR_PARAM;
  2403. goto i40e_aq_erase_nvm_exit;
  2404. }
  2405. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_erase);
  2406. /* If this is the last command in a series, set the proper flag. */
  2407. if (last_command)
  2408. cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
  2409. cmd->module_pointer = module_pointer;
  2410. cmd->offset = cpu_to_le32(offset);
  2411. cmd->length = cpu_to_le16(length);
  2412. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2413. i40e_aq_erase_nvm_exit:
  2414. return status;
  2415. }
  2416. #define I40E_DEV_FUNC_CAP_SWITCH_MODE 0x01
  2417. #define I40E_DEV_FUNC_CAP_MGMT_MODE 0x02
  2418. #define I40E_DEV_FUNC_CAP_NPAR 0x03
  2419. #define I40E_DEV_FUNC_CAP_OS2BMC 0x04
  2420. #define I40E_DEV_FUNC_CAP_VALID_FUNC 0x05
  2421. #define I40E_DEV_FUNC_CAP_SRIOV_1_1 0x12
  2422. #define I40E_DEV_FUNC_CAP_VF 0x13
  2423. #define I40E_DEV_FUNC_CAP_VMDQ 0x14
  2424. #define I40E_DEV_FUNC_CAP_802_1_QBG 0x15
  2425. #define I40E_DEV_FUNC_CAP_802_1_QBH 0x16
  2426. #define I40E_DEV_FUNC_CAP_VSI 0x17
  2427. #define I40E_DEV_FUNC_CAP_DCB 0x18
  2428. #define I40E_DEV_FUNC_CAP_FCOE 0x21
  2429. #define I40E_DEV_FUNC_CAP_ISCSI 0x22
  2430. #define I40E_DEV_FUNC_CAP_RSS 0x40
  2431. #define I40E_DEV_FUNC_CAP_RX_QUEUES 0x41
  2432. #define I40E_DEV_FUNC_CAP_TX_QUEUES 0x42
  2433. #define I40E_DEV_FUNC_CAP_MSIX 0x43
  2434. #define I40E_DEV_FUNC_CAP_MSIX_VF 0x44
  2435. #define I40E_DEV_FUNC_CAP_FLOW_DIRECTOR 0x45
  2436. #define I40E_DEV_FUNC_CAP_IEEE_1588 0x46
  2437. #define I40E_DEV_FUNC_CAP_FLEX10 0xF1
  2438. #define I40E_DEV_FUNC_CAP_CEM 0xF2
  2439. #define I40E_DEV_FUNC_CAP_IWARP 0x51
  2440. #define I40E_DEV_FUNC_CAP_LED 0x61
  2441. #define I40E_DEV_FUNC_CAP_SDP 0x62
  2442. #define I40E_DEV_FUNC_CAP_MDIO 0x63
  2443. #define I40E_DEV_FUNC_CAP_WR_CSR_PROT 0x64
  2444. /**
  2445. * i40e_parse_discover_capabilities
  2446. * @hw: pointer to the hw struct
  2447. * @buff: pointer to a buffer containing device/function capability records
  2448. * @cap_count: number of capability records in the list
  2449. * @list_type_opc: type of capabilities list to parse
  2450. *
  2451. * Parse the device/function capabilities list.
  2452. **/
  2453. static void i40e_parse_discover_capabilities(struct i40e_hw *hw, void *buff,
  2454. u32 cap_count,
  2455. enum i40e_admin_queue_opc list_type_opc)
  2456. {
  2457. struct i40e_aqc_list_capabilities_element_resp *cap;
  2458. u32 valid_functions, num_functions;
  2459. u32 number, logical_id, phys_id;
  2460. struct i40e_hw_capabilities *p;
  2461. u8 major_rev;
  2462. u32 i = 0;
  2463. u16 id;
  2464. cap = (struct i40e_aqc_list_capabilities_element_resp *) buff;
  2465. if (list_type_opc == i40e_aqc_opc_list_dev_capabilities)
  2466. p = &hw->dev_caps;
  2467. else if (list_type_opc == i40e_aqc_opc_list_func_capabilities)
  2468. p = &hw->func_caps;
  2469. else
  2470. return;
  2471. for (i = 0; i < cap_count; i++, cap++) {
  2472. id = le16_to_cpu(cap->id);
  2473. number = le32_to_cpu(cap->number);
  2474. logical_id = le32_to_cpu(cap->logical_id);
  2475. phys_id = le32_to_cpu(cap->phys_id);
  2476. major_rev = cap->major_rev;
  2477. switch (id) {
  2478. case I40E_DEV_FUNC_CAP_SWITCH_MODE:
  2479. p->switch_mode = number;
  2480. break;
  2481. case I40E_DEV_FUNC_CAP_MGMT_MODE:
  2482. p->management_mode = number;
  2483. break;
  2484. case I40E_DEV_FUNC_CAP_NPAR:
  2485. p->npar_enable = number;
  2486. break;
  2487. case I40E_DEV_FUNC_CAP_OS2BMC:
  2488. p->os2bmc = number;
  2489. break;
  2490. case I40E_DEV_FUNC_CAP_VALID_FUNC:
  2491. p->valid_functions = number;
  2492. break;
  2493. case I40E_DEV_FUNC_CAP_SRIOV_1_1:
  2494. if (number == 1)
  2495. p->sr_iov_1_1 = true;
  2496. break;
  2497. case I40E_DEV_FUNC_CAP_VF:
  2498. p->num_vfs = number;
  2499. p->vf_base_id = logical_id;
  2500. break;
  2501. case I40E_DEV_FUNC_CAP_VMDQ:
  2502. if (number == 1)
  2503. p->vmdq = true;
  2504. break;
  2505. case I40E_DEV_FUNC_CAP_802_1_QBG:
  2506. if (number == 1)
  2507. p->evb_802_1_qbg = true;
  2508. break;
  2509. case I40E_DEV_FUNC_CAP_802_1_QBH:
  2510. if (number == 1)
  2511. p->evb_802_1_qbh = true;
  2512. break;
  2513. case I40E_DEV_FUNC_CAP_VSI:
  2514. p->num_vsis = number;
  2515. break;
  2516. case I40E_DEV_FUNC_CAP_DCB:
  2517. if (number == 1) {
  2518. p->dcb = true;
  2519. p->enabled_tcmap = logical_id;
  2520. p->maxtc = phys_id;
  2521. }
  2522. break;
  2523. case I40E_DEV_FUNC_CAP_FCOE:
  2524. if (number == 1)
  2525. p->fcoe = true;
  2526. break;
  2527. case I40E_DEV_FUNC_CAP_ISCSI:
  2528. if (number == 1)
  2529. p->iscsi = true;
  2530. break;
  2531. case I40E_DEV_FUNC_CAP_RSS:
  2532. p->rss = true;
  2533. p->rss_table_size = number;
  2534. p->rss_table_entry_width = logical_id;
  2535. break;
  2536. case I40E_DEV_FUNC_CAP_RX_QUEUES:
  2537. p->num_rx_qp = number;
  2538. p->base_queue = phys_id;
  2539. break;
  2540. case I40E_DEV_FUNC_CAP_TX_QUEUES:
  2541. p->num_tx_qp = number;
  2542. p->base_queue = phys_id;
  2543. break;
  2544. case I40E_DEV_FUNC_CAP_MSIX:
  2545. p->num_msix_vectors = number;
  2546. break;
  2547. case I40E_DEV_FUNC_CAP_MSIX_VF:
  2548. p->num_msix_vectors_vf = number;
  2549. break;
  2550. case I40E_DEV_FUNC_CAP_FLEX10:
  2551. if (major_rev == 1) {
  2552. if (number == 1) {
  2553. p->flex10_enable = true;
  2554. p->flex10_capable = true;
  2555. }
  2556. } else {
  2557. /* Capability revision >= 2 */
  2558. if (number & 1)
  2559. p->flex10_enable = true;
  2560. if (number & 2)
  2561. p->flex10_capable = true;
  2562. }
  2563. p->flex10_mode = logical_id;
  2564. p->flex10_status = phys_id;
  2565. break;
  2566. case I40E_DEV_FUNC_CAP_CEM:
  2567. if (number == 1)
  2568. p->mgmt_cem = true;
  2569. break;
  2570. case I40E_DEV_FUNC_CAP_IWARP:
  2571. if (number == 1)
  2572. p->iwarp = true;
  2573. break;
  2574. case I40E_DEV_FUNC_CAP_LED:
  2575. if (phys_id < I40E_HW_CAP_MAX_GPIO)
  2576. p->led[phys_id] = true;
  2577. break;
  2578. case I40E_DEV_FUNC_CAP_SDP:
  2579. if (phys_id < I40E_HW_CAP_MAX_GPIO)
  2580. p->sdp[phys_id] = true;
  2581. break;
  2582. case I40E_DEV_FUNC_CAP_MDIO:
  2583. if (number == 1) {
  2584. p->mdio_port_num = phys_id;
  2585. p->mdio_port_mode = logical_id;
  2586. }
  2587. break;
  2588. case I40E_DEV_FUNC_CAP_IEEE_1588:
  2589. if (number == 1)
  2590. p->ieee_1588 = true;
  2591. break;
  2592. case I40E_DEV_FUNC_CAP_FLOW_DIRECTOR:
  2593. p->fd = true;
  2594. p->fd_filters_guaranteed = number;
  2595. p->fd_filters_best_effort = logical_id;
  2596. break;
  2597. case I40E_DEV_FUNC_CAP_WR_CSR_PROT:
  2598. p->wr_csr_prot = (u64)number;
  2599. p->wr_csr_prot |= (u64)logical_id << 32;
  2600. break;
  2601. default:
  2602. break;
  2603. }
  2604. }
  2605. if (p->fcoe)
  2606. i40e_debug(hw, I40E_DEBUG_ALL, "device is FCoE capable\n");
  2607. /* Software override ensuring FCoE is disabled if npar or mfp
  2608. * mode because it is not supported in these modes.
  2609. */
  2610. if (p->npar_enable || p->flex10_enable)
  2611. p->fcoe = false;
  2612. /* count the enabled ports (aka the "not disabled" ports) */
  2613. hw->num_ports = 0;
  2614. for (i = 0; i < 4; i++) {
  2615. u32 port_cfg_reg = I40E_PRTGEN_CNF + (4 * i);
  2616. u64 port_cfg = 0;
  2617. /* use AQ read to get the physical register offset instead
  2618. * of the port relative offset
  2619. */
  2620. i40e_aq_debug_read_register(hw, port_cfg_reg, &port_cfg, NULL);
  2621. if (!(port_cfg & I40E_PRTGEN_CNF_PORT_DIS_MASK))
  2622. hw->num_ports++;
  2623. }
  2624. valid_functions = p->valid_functions;
  2625. num_functions = 0;
  2626. while (valid_functions) {
  2627. if (valid_functions & 1)
  2628. num_functions++;
  2629. valid_functions >>= 1;
  2630. }
  2631. /* partition id is 1-based, and functions are evenly spread
  2632. * across the ports as partitions
  2633. */
  2634. hw->partition_id = (hw->pf_id / hw->num_ports) + 1;
  2635. hw->num_partitions = num_functions / hw->num_ports;
  2636. /* additional HW specific goodies that might
  2637. * someday be HW version specific
  2638. */
  2639. p->rx_buf_chain_len = I40E_MAX_CHAINED_RX_BUFFERS;
  2640. }
  2641. /**
  2642. * i40e_aq_discover_capabilities
  2643. * @hw: pointer to the hw struct
  2644. * @buff: a virtual buffer to hold the capabilities
  2645. * @buff_size: Size of the virtual buffer
  2646. * @data_size: Size of the returned data, or buff size needed if AQ err==ENOMEM
  2647. * @list_type_opc: capabilities type to discover - pass in the command opcode
  2648. * @cmd_details: pointer to command details structure or NULL
  2649. *
  2650. * Get the device capabilities descriptions from the firmware
  2651. **/
  2652. i40e_status i40e_aq_discover_capabilities(struct i40e_hw *hw,
  2653. void *buff, u16 buff_size, u16 *data_size,
  2654. enum i40e_admin_queue_opc list_type_opc,
  2655. struct i40e_asq_cmd_details *cmd_details)
  2656. {
  2657. struct i40e_aqc_list_capabilites *cmd;
  2658. struct i40e_aq_desc desc;
  2659. i40e_status status = 0;
  2660. cmd = (struct i40e_aqc_list_capabilites *)&desc.params.raw;
  2661. if (list_type_opc != i40e_aqc_opc_list_func_capabilities &&
  2662. list_type_opc != i40e_aqc_opc_list_dev_capabilities) {
  2663. status = I40E_ERR_PARAM;
  2664. goto exit;
  2665. }
  2666. i40e_fill_default_direct_cmd_desc(&desc, list_type_opc);
  2667. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2668. if (buff_size > I40E_AQ_LARGE_BUF)
  2669. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2670. status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  2671. *data_size = le16_to_cpu(desc.datalen);
  2672. if (status)
  2673. goto exit;
  2674. i40e_parse_discover_capabilities(hw, buff, le32_to_cpu(cmd->count),
  2675. list_type_opc);
  2676. exit:
  2677. return status;
  2678. }
  2679. /**
  2680. * i40e_aq_update_nvm
  2681. * @hw: pointer to the hw struct
  2682. * @module_pointer: module pointer location in words from the NVM beginning
  2683. * @offset: byte offset from the module beginning
  2684. * @length: length of the section to be written (in bytes from the offset)
  2685. * @data: command buffer (size [bytes] = length)
  2686. * @last_command: tells if this is the last command in a series
  2687. * @cmd_details: pointer to command details structure or NULL
  2688. *
  2689. * Update the NVM using the admin queue commands
  2690. **/
  2691. i40e_status i40e_aq_update_nvm(struct i40e_hw *hw, u8 module_pointer,
  2692. u32 offset, u16 length, void *data,
  2693. bool last_command,
  2694. struct i40e_asq_cmd_details *cmd_details)
  2695. {
  2696. struct i40e_aq_desc desc;
  2697. struct i40e_aqc_nvm_update *cmd =
  2698. (struct i40e_aqc_nvm_update *)&desc.params.raw;
  2699. i40e_status status;
  2700. /* In offset the highest byte must be zeroed. */
  2701. if (offset & 0xFF000000) {
  2702. status = I40E_ERR_PARAM;
  2703. goto i40e_aq_update_nvm_exit;
  2704. }
  2705. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_update);
  2706. /* If this is the last command in a series, set the proper flag. */
  2707. if (last_command)
  2708. cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
  2709. cmd->module_pointer = module_pointer;
  2710. cmd->offset = cpu_to_le32(offset);
  2711. cmd->length = cpu_to_le16(length);
  2712. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  2713. if (length > I40E_AQ_LARGE_BUF)
  2714. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2715. status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
  2716. i40e_aq_update_nvm_exit:
  2717. return status;
  2718. }
  2719. /**
  2720. * i40e_aq_get_lldp_mib
  2721. * @hw: pointer to the hw struct
  2722. * @bridge_type: type of bridge requested
  2723. * @mib_type: Local, Remote or both Local and Remote MIBs
  2724. * @buff: pointer to a user supplied buffer to store the MIB block
  2725. * @buff_size: size of the buffer (in bytes)
  2726. * @local_len : length of the returned Local LLDP MIB
  2727. * @remote_len: length of the returned Remote LLDP MIB
  2728. * @cmd_details: pointer to command details structure or NULL
  2729. *
  2730. * Requests the complete LLDP MIB (entire packet).
  2731. **/
  2732. i40e_status i40e_aq_get_lldp_mib(struct i40e_hw *hw, u8 bridge_type,
  2733. u8 mib_type, void *buff, u16 buff_size,
  2734. u16 *local_len, u16 *remote_len,
  2735. struct i40e_asq_cmd_details *cmd_details)
  2736. {
  2737. struct i40e_aq_desc desc;
  2738. struct i40e_aqc_lldp_get_mib *cmd =
  2739. (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
  2740. struct i40e_aqc_lldp_get_mib *resp =
  2741. (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
  2742. i40e_status status;
  2743. if (buff_size == 0 || !buff)
  2744. return I40E_ERR_PARAM;
  2745. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_get_mib);
  2746. /* Indirect Command */
  2747. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2748. cmd->type = mib_type & I40E_AQ_LLDP_MIB_TYPE_MASK;
  2749. cmd->type |= ((bridge_type << I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) &
  2750. I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
  2751. desc.datalen = cpu_to_le16(buff_size);
  2752. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2753. if (buff_size > I40E_AQ_LARGE_BUF)
  2754. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2755. status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  2756. if (!status) {
  2757. if (local_len != NULL)
  2758. *local_len = le16_to_cpu(resp->local_len);
  2759. if (remote_len != NULL)
  2760. *remote_len = le16_to_cpu(resp->remote_len);
  2761. }
  2762. return status;
  2763. }
  2764. /**
  2765. * i40e_aq_cfg_lldp_mib_change_event
  2766. * @hw: pointer to the hw struct
  2767. * @enable_update: Enable or Disable event posting
  2768. * @cmd_details: pointer to command details structure or NULL
  2769. *
  2770. * Enable or Disable posting of an event on ARQ when LLDP MIB
  2771. * associated with the interface changes
  2772. **/
  2773. i40e_status i40e_aq_cfg_lldp_mib_change_event(struct i40e_hw *hw,
  2774. bool enable_update,
  2775. struct i40e_asq_cmd_details *cmd_details)
  2776. {
  2777. struct i40e_aq_desc desc;
  2778. struct i40e_aqc_lldp_update_mib *cmd =
  2779. (struct i40e_aqc_lldp_update_mib *)&desc.params.raw;
  2780. i40e_status status;
  2781. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_update_mib);
  2782. if (!enable_update)
  2783. cmd->command |= I40E_AQ_LLDP_MIB_UPDATE_DISABLE;
  2784. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2785. return status;
  2786. }
  2787. /**
  2788. * i40e_aq_stop_lldp
  2789. * @hw: pointer to the hw struct
  2790. * @shutdown_agent: True if LLDP Agent needs to be Shutdown
  2791. * @cmd_details: pointer to command details structure or NULL
  2792. *
  2793. * Stop or Shutdown the embedded LLDP Agent
  2794. **/
  2795. i40e_status i40e_aq_stop_lldp(struct i40e_hw *hw, bool shutdown_agent,
  2796. struct i40e_asq_cmd_details *cmd_details)
  2797. {
  2798. struct i40e_aq_desc desc;
  2799. struct i40e_aqc_lldp_stop *cmd =
  2800. (struct i40e_aqc_lldp_stop *)&desc.params.raw;
  2801. i40e_status status;
  2802. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_stop);
  2803. if (shutdown_agent)
  2804. cmd->command |= I40E_AQ_LLDP_AGENT_SHUTDOWN;
  2805. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2806. return status;
  2807. }
  2808. /**
  2809. * i40e_aq_start_lldp
  2810. * @hw: pointer to the hw struct
  2811. * @cmd_details: pointer to command details structure or NULL
  2812. *
  2813. * Start the embedded LLDP Agent on all ports.
  2814. **/
  2815. i40e_status i40e_aq_start_lldp(struct i40e_hw *hw,
  2816. struct i40e_asq_cmd_details *cmd_details)
  2817. {
  2818. struct i40e_aq_desc desc;
  2819. struct i40e_aqc_lldp_start *cmd =
  2820. (struct i40e_aqc_lldp_start *)&desc.params.raw;
  2821. i40e_status status;
  2822. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_start);
  2823. cmd->command = I40E_AQ_LLDP_AGENT_START;
  2824. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2825. return status;
  2826. }
  2827. /**
  2828. * i40e_aq_get_cee_dcb_config
  2829. * @hw: pointer to the hw struct
  2830. * @buff: response buffer that stores CEE operational configuration
  2831. * @buff_size: size of the buffer passed
  2832. * @cmd_details: pointer to command details structure or NULL
  2833. *
  2834. * Get CEE DCBX mode operational configuration from firmware
  2835. **/
  2836. i40e_status i40e_aq_get_cee_dcb_config(struct i40e_hw *hw,
  2837. void *buff, u16 buff_size,
  2838. struct i40e_asq_cmd_details *cmd_details)
  2839. {
  2840. struct i40e_aq_desc desc;
  2841. i40e_status status;
  2842. if (buff_size == 0 || !buff)
  2843. return I40E_ERR_PARAM;
  2844. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_cee_dcb_cfg);
  2845. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2846. status = i40e_asq_send_command(hw, &desc, (void *)buff, buff_size,
  2847. cmd_details);
  2848. return status;
  2849. }
  2850. /**
  2851. * i40e_aq_add_udp_tunnel
  2852. * @hw: pointer to the hw struct
  2853. * @udp_port: the UDP port to add
  2854. * @header_len: length of the tunneling header length in DWords
  2855. * @protocol_index: protocol index type
  2856. * @filter_index: pointer to filter index
  2857. * @cmd_details: pointer to command details structure or NULL
  2858. **/
  2859. i40e_status i40e_aq_add_udp_tunnel(struct i40e_hw *hw,
  2860. u16 udp_port, u8 protocol_index,
  2861. u8 *filter_index,
  2862. struct i40e_asq_cmd_details *cmd_details)
  2863. {
  2864. struct i40e_aq_desc desc;
  2865. struct i40e_aqc_add_udp_tunnel *cmd =
  2866. (struct i40e_aqc_add_udp_tunnel *)&desc.params.raw;
  2867. struct i40e_aqc_del_udp_tunnel_completion *resp =
  2868. (struct i40e_aqc_del_udp_tunnel_completion *)&desc.params.raw;
  2869. i40e_status status;
  2870. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_udp_tunnel);
  2871. cmd->udp_port = cpu_to_le16(udp_port);
  2872. cmd->protocol_type = protocol_index;
  2873. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2874. if (!status && filter_index)
  2875. *filter_index = resp->index;
  2876. return status;
  2877. }
  2878. /**
  2879. * i40e_aq_del_udp_tunnel
  2880. * @hw: pointer to the hw struct
  2881. * @index: filter index
  2882. * @cmd_details: pointer to command details structure or NULL
  2883. **/
  2884. i40e_status i40e_aq_del_udp_tunnel(struct i40e_hw *hw, u8 index,
  2885. struct i40e_asq_cmd_details *cmd_details)
  2886. {
  2887. struct i40e_aq_desc desc;
  2888. struct i40e_aqc_remove_udp_tunnel *cmd =
  2889. (struct i40e_aqc_remove_udp_tunnel *)&desc.params.raw;
  2890. i40e_status status;
  2891. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_del_udp_tunnel);
  2892. cmd->index = index;
  2893. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2894. return status;
  2895. }
  2896. /**
  2897. * i40e_aq_delete_element - Delete switch element
  2898. * @hw: pointer to the hw struct
  2899. * @seid: the SEID to delete from the switch
  2900. * @cmd_details: pointer to command details structure or NULL
  2901. *
  2902. * This deletes a switch element from the switch.
  2903. **/
  2904. i40e_status i40e_aq_delete_element(struct i40e_hw *hw, u16 seid,
  2905. struct i40e_asq_cmd_details *cmd_details)
  2906. {
  2907. struct i40e_aq_desc desc;
  2908. struct i40e_aqc_switch_seid *cmd =
  2909. (struct i40e_aqc_switch_seid *)&desc.params.raw;
  2910. i40e_status status;
  2911. if (seid == 0)
  2912. return I40E_ERR_PARAM;
  2913. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_delete_element);
  2914. cmd->seid = cpu_to_le16(seid);
  2915. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2916. return status;
  2917. }
  2918. /**
  2919. * i40e_aq_dcb_updated - DCB Updated Command
  2920. * @hw: pointer to the hw struct
  2921. * @cmd_details: pointer to command details structure or NULL
  2922. *
  2923. * EMP will return when the shared RPB settings have been
  2924. * recomputed and modified. The retval field in the descriptor
  2925. * will be set to 0 when RPB is modified.
  2926. **/
  2927. i40e_status i40e_aq_dcb_updated(struct i40e_hw *hw,
  2928. struct i40e_asq_cmd_details *cmd_details)
  2929. {
  2930. struct i40e_aq_desc desc;
  2931. i40e_status status;
  2932. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_dcb_updated);
  2933. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2934. return status;
  2935. }
  2936. /**
  2937. * i40e_aq_tx_sched_cmd - generic Tx scheduler AQ command handler
  2938. * @hw: pointer to the hw struct
  2939. * @seid: seid for the physical port/switching component/vsi
  2940. * @buff: Indirect buffer to hold data parameters and response
  2941. * @buff_size: Indirect buffer size
  2942. * @opcode: Tx scheduler AQ command opcode
  2943. * @cmd_details: pointer to command details structure or NULL
  2944. *
  2945. * Generic command handler for Tx scheduler AQ commands
  2946. **/
  2947. static i40e_status i40e_aq_tx_sched_cmd(struct i40e_hw *hw, u16 seid,
  2948. void *buff, u16 buff_size,
  2949. enum i40e_admin_queue_opc opcode,
  2950. struct i40e_asq_cmd_details *cmd_details)
  2951. {
  2952. struct i40e_aq_desc desc;
  2953. struct i40e_aqc_tx_sched_ind *cmd =
  2954. (struct i40e_aqc_tx_sched_ind *)&desc.params.raw;
  2955. i40e_status status;
  2956. bool cmd_param_flag = false;
  2957. switch (opcode) {
  2958. case i40e_aqc_opc_configure_vsi_ets_sla_bw_limit:
  2959. case i40e_aqc_opc_configure_vsi_tc_bw:
  2960. case i40e_aqc_opc_enable_switching_comp_ets:
  2961. case i40e_aqc_opc_modify_switching_comp_ets:
  2962. case i40e_aqc_opc_disable_switching_comp_ets:
  2963. case i40e_aqc_opc_configure_switching_comp_ets_bw_limit:
  2964. case i40e_aqc_opc_configure_switching_comp_bw_config:
  2965. cmd_param_flag = true;
  2966. break;
  2967. case i40e_aqc_opc_query_vsi_bw_config:
  2968. case i40e_aqc_opc_query_vsi_ets_sla_config:
  2969. case i40e_aqc_opc_query_switching_comp_ets_config:
  2970. case i40e_aqc_opc_query_port_ets_config:
  2971. case i40e_aqc_opc_query_switching_comp_bw_config:
  2972. cmd_param_flag = false;
  2973. break;
  2974. default:
  2975. return I40E_ERR_PARAM;
  2976. }
  2977. i40e_fill_default_direct_cmd_desc(&desc, opcode);
  2978. /* Indirect command */
  2979. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2980. if (cmd_param_flag)
  2981. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
  2982. if (buff_size > I40E_AQ_LARGE_BUF)
  2983. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2984. desc.datalen = cpu_to_le16(buff_size);
  2985. cmd->vsi_seid = cpu_to_le16(seid);
  2986. status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  2987. return status;
  2988. }
  2989. /**
  2990. * i40e_aq_config_vsi_bw_limit - Configure VSI BW Limit
  2991. * @hw: pointer to the hw struct
  2992. * @seid: VSI seid
  2993. * @credit: BW limit credits (0 = disabled)
  2994. * @max_credit: Max BW limit credits
  2995. * @cmd_details: pointer to command details structure or NULL
  2996. **/
  2997. i40e_status i40e_aq_config_vsi_bw_limit(struct i40e_hw *hw,
  2998. u16 seid, u16 credit, u8 max_credit,
  2999. struct i40e_asq_cmd_details *cmd_details)
  3000. {
  3001. struct i40e_aq_desc desc;
  3002. struct i40e_aqc_configure_vsi_bw_limit *cmd =
  3003. (struct i40e_aqc_configure_vsi_bw_limit *)&desc.params.raw;
  3004. i40e_status status;
  3005. i40e_fill_default_direct_cmd_desc(&desc,
  3006. i40e_aqc_opc_configure_vsi_bw_limit);
  3007. cmd->vsi_seid = cpu_to_le16(seid);
  3008. cmd->credit = cpu_to_le16(credit);
  3009. cmd->max_credit = max_credit;
  3010. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  3011. return status;
  3012. }
  3013. /**
  3014. * i40e_aq_config_vsi_tc_bw - Config VSI BW Allocation per TC
  3015. * @hw: pointer to the hw struct
  3016. * @seid: VSI seid
  3017. * @bw_data: Buffer holding enabled TCs, relative TC BW limit/credits
  3018. * @cmd_details: pointer to command details structure or NULL
  3019. **/
  3020. i40e_status i40e_aq_config_vsi_tc_bw(struct i40e_hw *hw,
  3021. u16 seid,
  3022. struct i40e_aqc_configure_vsi_tc_bw_data *bw_data,
  3023. struct i40e_asq_cmd_details *cmd_details)
  3024. {
  3025. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  3026. i40e_aqc_opc_configure_vsi_tc_bw,
  3027. cmd_details);
  3028. }
  3029. /**
  3030. * i40e_aq_config_switch_comp_ets - Enable/Disable/Modify ETS on the port
  3031. * @hw: pointer to the hw struct
  3032. * @seid: seid of the switching component connected to Physical Port
  3033. * @ets_data: Buffer holding ETS parameters
  3034. * @cmd_details: pointer to command details structure or NULL
  3035. **/
  3036. i40e_status i40e_aq_config_switch_comp_ets(struct i40e_hw *hw,
  3037. u16 seid,
  3038. struct i40e_aqc_configure_switching_comp_ets_data *ets_data,
  3039. enum i40e_admin_queue_opc opcode,
  3040. struct i40e_asq_cmd_details *cmd_details)
  3041. {
  3042. return i40e_aq_tx_sched_cmd(hw, seid, (void *)ets_data,
  3043. sizeof(*ets_data), opcode, cmd_details);
  3044. }
  3045. /**
  3046. * i40e_aq_config_switch_comp_bw_config - Config Switch comp BW Alloc per TC
  3047. * @hw: pointer to the hw struct
  3048. * @seid: seid of the switching component
  3049. * @bw_data: Buffer holding enabled TCs, relative/absolute TC BW limit/credits
  3050. * @cmd_details: pointer to command details structure or NULL
  3051. **/
  3052. i40e_status i40e_aq_config_switch_comp_bw_config(struct i40e_hw *hw,
  3053. u16 seid,
  3054. struct i40e_aqc_configure_switching_comp_bw_config_data *bw_data,
  3055. struct i40e_asq_cmd_details *cmd_details)
  3056. {
  3057. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  3058. i40e_aqc_opc_configure_switching_comp_bw_config,
  3059. cmd_details);
  3060. }
  3061. /**
  3062. * i40e_aq_query_vsi_bw_config - Query VSI BW configuration
  3063. * @hw: pointer to the hw struct
  3064. * @seid: seid of the VSI
  3065. * @bw_data: Buffer to hold VSI BW configuration
  3066. * @cmd_details: pointer to command details structure or NULL
  3067. **/
  3068. i40e_status i40e_aq_query_vsi_bw_config(struct i40e_hw *hw,
  3069. u16 seid,
  3070. struct i40e_aqc_query_vsi_bw_config_resp *bw_data,
  3071. struct i40e_asq_cmd_details *cmd_details)
  3072. {
  3073. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  3074. i40e_aqc_opc_query_vsi_bw_config,
  3075. cmd_details);
  3076. }
  3077. /**
  3078. * i40e_aq_query_vsi_ets_sla_config - Query VSI BW configuration per TC
  3079. * @hw: pointer to the hw struct
  3080. * @seid: seid of the VSI
  3081. * @bw_data: Buffer to hold VSI BW configuration per TC
  3082. * @cmd_details: pointer to command details structure or NULL
  3083. **/
  3084. i40e_status i40e_aq_query_vsi_ets_sla_config(struct i40e_hw *hw,
  3085. u16 seid,
  3086. struct i40e_aqc_query_vsi_ets_sla_config_resp *bw_data,
  3087. struct i40e_asq_cmd_details *cmd_details)
  3088. {
  3089. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  3090. i40e_aqc_opc_query_vsi_ets_sla_config,
  3091. cmd_details);
  3092. }
  3093. /**
  3094. * i40e_aq_query_switch_comp_ets_config - Query Switch comp BW config per TC
  3095. * @hw: pointer to the hw struct
  3096. * @seid: seid of the switching component
  3097. * @bw_data: Buffer to hold switching component's per TC BW config
  3098. * @cmd_details: pointer to command details structure or NULL
  3099. **/
  3100. i40e_status i40e_aq_query_switch_comp_ets_config(struct i40e_hw *hw,
  3101. u16 seid,
  3102. struct i40e_aqc_query_switching_comp_ets_config_resp *bw_data,
  3103. struct i40e_asq_cmd_details *cmd_details)
  3104. {
  3105. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  3106. i40e_aqc_opc_query_switching_comp_ets_config,
  3107. cmd_details);
  3108. }
  3109. /**
  3110. * i40e_aq_query_port_ets_config - Query Physical Port ETS configuration
  3111. * @hw: pointer to the hw struct
  3112. * @seid: seid of the VSI or switching component connected to Physical Port
  3113. * @bw_data: Buffer to hold current ETS configuration for the Physical Port
  3114. * @cmd_details: pointer to command details structure or NULL
  3115. **/
  3116. i40e_status i40e_aq_query_port_ets_config(struct i40e_hw *hw,
  3117. u16 seid,
  3118. struct i40e_aqc_query_port_ets_config_resp *bw_data,
  3119. struct i40e_asq_cmd_details *cmd_details)
  3120. {
  3121. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  3122. i40e_aqc_opc_query_port_ets_config,
  3123. cmd_details);
  3124. }
  3125. /**
  3126. * i40e_aq_query_switch_comp_bw_config - Query Switch comp BW configuration
  3127. * @hw: pointer to the hw struct
  3128. * @seid: seid of the switching component
  3129. * @bw_data: Buffer to hold switching component's BW configuration
  3130. * @cmd_details: pointer to command details structure or NULL
  3131. **/
  3132. i40e_status i40e_aq_query_switch_comp_bw_config(struct i40e_hw *hw,
  3133. u16 seid,
  3134. struct i40e_aqc_query_switching_comp_bw_config_resp *bw_data,
  3135. struct i40e_asq_cmd_details *cmd_details)
  3136. {
  3137. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  3138. i40e_aqc_opc_query_switching_comp_bw_config,
  3139. cmd_details);
  3140. }
  3141. /**
  3142. * i40e_validate_filter_settings
  3143. * @hw: pointer to the hardware structure
  3144. * @settings: Filter control settings
  3145. *
  3146. * Check and validate the filter control settings passed.
  3147. * The function checks for the valid filter/context sizes being
  3148. * passed for FCoE and PE.
  3149. *
  3150. * Returns 0 if the values passed are valid and within
  3151. * range else returns an error.
  3152. **/
  3153. static i40e_status i40e_validate_filter_settings(struct i40e_hw *hw,
  3154. struct i40e_filter_control_settings *settings)
  3155. {
  3156. u32 fcoe_cntx_size, fcoe_filt_size;
  3157. u32 pe_cntx_size, pe_filt_size;
  3158. u32 fcoe_fmax;
  3159. u32 val;
  3160. /* Validate FCoE settings passed */
  3161. switch (settings->fcoe_filt_num) {
  3162. case I40E_HASH_FILTER_SIZE_1K:
  3163. case I40E_HASH_FILTER_SIZE_2K:
  3164. case I40E_HASH_FILTER_SIZE_4K:
  3165. case I40E_HASH_FILTER_SIZE_8K:
  3166. case I40E_HASH_FILTER_SIZE_16K:
  3167. case I40E_HASH_FILTER_SIZE_32K:
  3168. fcoe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
  3169. fcoe_filt_size <<= (u32)settings->fcoe_filt_num;
  3170. break;
  3171. default:
  3172. return I40E_ERR_PARAM;
  3173. }
  3174. switch (settings->fcoe_cntx_num) {
  3175. case I40E_DMA_CNTX_SIZE_512:
  3176. case I40E_DMA_CNTX_SIZE_1K:
  3177. case I40E_DMA_CNTX_SIZE_2K:
  3178. case I40E_DMA_CNTX_SIZE_4K:
  3179. fcoe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
  3180. fcoe_cntx_size <<= (u32)settings->fcoe_cntx_num;
  3181. break;
  3182. default:
  3183. return I40E_ERR_PARAM;
  3184. }
  3185. /* Validate PE settings passed */
  3186. switch (settings->pe_filt_num) {
  3187. case I40E_HASH_FILTER_SIZE_1K:
  3188. case I40E_HASH_FILTER_SIZE_2K:
  3189. case I40E_HASH_FILTER_SIZE_4K:
  3190. case I40E_HASH_FILTER_SIZE_8K:
  3191. case I40E_HASH_FILTER_SIZE_16K:
  3192. case I40E_HASH_FILTER_SIZE_32K:
  3193. case I40E_HASH_FILTER_SIZE_64K:
  3194. case I40E_HASH_FILTER_SIZE_128K:
  3195. case I40E_HASH_FILTER_SIZE_256K:
  3196. case I40E_HASH_FILTER_SIZE_512K:
  3197. case I40E_HASH_FILTER_SIZE_1M:
  3198. pe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
  3199. pe_filt_size <<= (u32)settings->pe_filt_num;
  3200. break;
  3201. default:
  3202. return I40E_ERR_PARAM;
  3203. }
  3204. switch (settings->pe_cntx_num) {
  3205. case I40E_DMA_CNTX_SIZE_512:
  3206. case I40E_DMA_CNTX_SIZE_1K:
  3207. case I40E_DMA_CNTX_SIZE_2K:
  3208. case I40E_DMA_CNTX_SIZE_4K:
  3209. case I40E_DMA_CNTX_SIZE_8K:
  3210. case I40E_DMA_CNTX_SIZE_16K:
  3211. case I40E_DMA_CNTX_SIZE_32K:
  3212. case I40E_DMA_CNTX_SIZE_64K:
  3213. case I40E_DMA_CNTX_SIZE_128K:
  3214. case I40E_DMA_CNTX_SIZE_256K:
  3215. pe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
  3216. pe_cntx_size <<= (u32)settings->pe_cntx_num;
  3217. break;
  3218. default:
  3219. return I40E_ERR_PARAM;
  3220. }
  3221. /* FCHSIZE + FCDSIZE should not be greater than PMFCOEFMAX */
  3222. val = rd32(hw, I40E_GLHMC_FCOEFMAX);
  3223. fcoe_fmax = (val & I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_MASK)
  3224. >> I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_SHIFT;
  3225. if (fcoe_filt_size + fcoe_cntx_size > fcoe_fmax)
  3226. return I40E_ERR_INVALID_SIZE;
  3227. return 0;
  3228. }
  3229. /**
  3230. * i40e_set_filter_control
  3231. * @hw: pointer to the hardware structure
  3232. * @settings: Filter control settings
  3233. *
  3234. * Set the Queue Filters for PE/FCoE and enable filters required
  3235. * for a single PF. It is expected that these settings are programmed
  3236. * at the driver initialization time.
  3237. **/
  3238. i40e_status i40e_set_filter_control(struct i40e_hw *hw,
  3239. struct i40e_filter_control_settings *settings)
  3240. {
  3241. i40e_status ret = 0;
  3242. u32 hash_lut_size = 0;
  3243. u32 val;
  3244. if (!settings)
  3245. return I40E_ERR_PARAM;
  3246. /* Validate the input settings */
  3247. ret = i40e_validate_filter_settings(hw, settings);
  3248. if (ret)
  3249. return ret;
  3250. /* Read the PF Queue Filter control register */
  3251. val = rd32(hw, I40E_PFQF_CTL_0);
  3252. /* Program required PE hash buckets for the PF */
  3253. val &= ~I40E_PFQF_CTL_0_PEHSIZE_MASK;
  3254. val |= ((u32)settings->pe_filt_num << I40E_PFQF_CTL_0_PEHSIZE_SHIFT) &
  3255. I40E_PFQF_CTL_0_PEHSIZE_MASK;
  3256. /* Program required PE contexts for the PF */
  3257. val &= ~I40E_PFQF_CTL_0_PEDSIZE_MASK;
  3258. val |= ((u32)settings->pe_cntx_num << I40E_PFQF_CTL_0_PEDSIZE_SHIFT) &
  3259. I40E_PFQF_CTL_0_PEDSIZE_MASK;
  3260. /* Program required FCoE hash buckets for the PF */
  3261. val &= ~I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
  3262. val |= ((u32)settings->fcoe_filt_num <<
  3263. I40E_PFQF_CTL_0_PFFCHSIZE_SHIFT) &
  3264. I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
  3265. /* Program required FCoE DDP contexts for the PF */
  3266. val &= ~I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
  3267. val |= ((u32)settings->fcoe_cntx_num <<
  3268. I40E_PFQF_CTL_0_PFFCDSIZE_SHIFT) &
  3269. I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
  3270. /* Program Hash LUT size for the PF */
  3271. val &= ~I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
  3272. if (settings->hash_lut_size == I40E_HASH_LUT_SIZE_512)
  3273. hash_lut_size = 1;
  3274. val |= (hash_lut_size << I40E_PFQF_CTL_0_HASHLUTSIZE_SHIFT) &
  3275. I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
  3276. /* Enable FDIR, Ethertype and MACVLAN filters for PF and VFs */
  3277. if (settings->enable_fdir)
  3278. val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
  3279. if (settings->enable_ethtype)
  3280. val |= I40E_PFQF_CTL_0_ETYPE_ENA_MASK;
  3281. if (settings->enable_macvlan)
  3282. val |= I40E_PFQF_CTL_0_MACVLAN_ENA_MASK;
  3283. wr32(hw, I40E_PFQF_CTL_0, val);
  3284. return 0;
  3285. }
  3286. /**
  3287. * i40e_aq_add_rem_control_packet_filter - Add or Remove Control Packet Filter
  3288. * @hw: pointer to the hw struct
  3289. * @mac_addr: MAC address to use in the filter
  3290. * @ethtype: Ethertype to use in the filter
  3291. * @flags: Flags that needs to be applied to the filter
  3292. * @vsi_seid: seid of the control VSI
  3293. * @queue: VSI queue number to send the packet to
  3294. * @is_add: Add control packet filter if True else remove
  3295. * @stats: Structure to hold information on control filter counts
  3296. * @cmd_details: pointer to command details structure or NULL
  3297. *
  3298. * This command will Add or Remove control packet filter for a control VSI.
  3299. * In return it will update the total number of perfect filter count in
  3300. * the stats member.
  3301. **/
  3302. i40e_status i40e_aq_add_rem_control_packet_filter(struct i40e_hw *hw,
  3303. u8 *mac_addr, u16 ethtype, u16 flags,
  3304. u16 vsi_seid, u16 queue, bool is_add,
  3305. struct i40e_control_filter_stats *stats,
  3306. struct i40e_asq_cmd_details *cmd_details)
  3307. {
  3308. struct i40e_aq_desc desc;
  3309. struct i40e_aqc_add_remove_control_packet_filter *cmd =
  3310. (struct i40e_aqc_add_remove_control_packet_filter *)
  3311. &desc.params.raw;
  3312. struct i40e_aqc_add_remove_control_packet_filter_completion *resp =
  3313. (struct i40e_aqc_add_remove_control_packet_filter_completion *)
  3314. &desc.params.raw;
  3315. i40e_status status;
  3316. if (vsi_seid == 0)
  3317. return I40E_ERR_PARAM;
  3318. if (is_add) {
  3319. i40e_fill_default_direct_cmd_desc(&desc,
  3320. i40e_aqc_opc_add_control_packet_filter);
  3321. cmd->queue = cpu_to_le16(queue);
  3322. } else {
  3323. i40e_fill_default_direct_cmd_desc(&desc,
  3324. i40e_aqc_opc_remove_control_packet_filter);
  3325. }
  3326. if (mac_addr)
  3327. ether_addr_copy(cmd->mac, mac_addr);
  3328. cmd->etype = cpu_to_le16(ethtype);
  3329. cmd->flags = cpu_to_le16(flags);
  3330. cmd->seid = cpu_to_le16(vsi_seid);
  3331. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  3332. if (!status && stats) {
  3333. stats->mac_etype_used = le16_to_cpu(resp->mac_etype_used);
  3334. stats->etype_used = le16_to_cpu(resp->etype_used);
  3335. stats->mac_etype_free = le16_to_cpu(resp->mac_etype_free);
  3336. stats->etype_free = le16_to_cpu(resp->etype_free);
  3337. }
  3338. return status;
  3339. }
  3340. /**
  3341. * i40e_add_filter_to_drop_tx_flow_control_frames- filter to drop flow control
  3342. * @hw: pointer to the hw struct
  3343. * @seid: VSI seid to add ethertype filter from
  3344. **/
  3345. #define I40E_FLOW_CONTROL_ETHTYPE 0x8808
  3346. void i40e_add_filter_to_drop_tx_flow_control_frames(struct i40e_hw *hw,
  3347. u16 seid)
  3348. {
  3349. u16 flag = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
  3350. I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
  3351. I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
  3352. u16 ethtype = I40E_FLOW_CONTROL_ETHTYPE;
  3353. i40e_status status;
  3354. status = i40e_aq_add_rem_control_packet_filter(hw, NULL, ethtype, flag,
  3355. seid, 0, true, NULL,
  3356. NULL);
  3357. if (status)
  3358. hw_dbg(hw, "Ethtype Filter Add failed: Error pruning Tx flow control frames\n");
  3359. }
  3360. /**
  3361. * i40e_aq_alternate_read
  3362. * @hw: pointer to the hardware structure
  3363. * @reg_addr0: address of first dword to be read
  3364. * @reg_val0: pointer for data read from 'reg_addr0'
  3365. * @reg_addr1: address of second dword to be read
  3366. * @reg_val1: pointer for data read from 'reg_addr1'
  3367. *
  3368. * Read one or two dwords from alternate structure. Fields are indicated
  3369. * by 'reg_addr0' and 'reg_addr1' register numbers. If 'reg_val1' pointer
  3370. * is not passed then only register at 'reg_addr0' is read.
  3371. *
  3372. **/
  3373. static i40e_status i40e_aq_alternate_read(struct i40e_hw *hw,
  3374. u32 reg_addr0, u32 *reg_val0,
  3375. u32 reg_addr1, u32 *reg_val1)
  3376. {
  3377. struct i40e_aq_desc desc;
  3378. struct i40e_aqc_alternate_write *cmd_resp =
  3379. (struct i40e_aqc_alternate_write *)&desc.params.raw;
  3380. i40e_status status;
  3381. if (!reg_val0)
  3382. return I40E_ERR_PARAM;
  3383. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_alternate_read);
  3384. cmd_resp->address0 = cpu_to_le32(reg_addr0);
  3385. cmd_resp->address1 = cpu_to_le32(reg_addr1);
  3386. status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
  3387. if (!status) {
  3388. *reg_val0 = le32_to_cpu(cmd_resp->data0);
  3389. if (reg_val1)
  3390. *reg_val1 = le32_to_cpu(cmd_resp->data1);
  3391. }
  3392. return status;
  3393. }
  3394. /**
  3395. * i40e_aq_resume_port_tx
  3396. * @hw: pointer to the hardware structure
  3397. * @cmd_details: pointer to command details structure or NULL
  3398. *
  3399. * Resume port's Tx traffic
  3400. **/
  3401. i40e_status i40e_aq_resume_port_tx(struct i40e_hw *hw,
  3402. struct i40e_asq_cmd_details *cmd_details)
  3403. {
  3404. struct i40e_aq_desc desc;
  3405. i40e_status status;
  3406. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_resume_port_tx);
  3407. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  3408. return status;
  3409. }
  3410. /**
  3411. * i40e_set_pci_config_data - store PCI bus info
  3412. * @hw: pointer to hardware structure
  3413. * @link_status: the link status word from PCI config space
  3414. *
  3415. * Stores the PCI bus info (speed, width, type) within the i40e_hw structure
  3416. **/
  3417. void i40e_set_pci_config_data(struct i40e_hw *hw, u16 link_status)
  3418. {
  3419. hw->bus.type = i40e_bus_type_pci_express;
  3420. switch (link_status & PCI_EXP_LNKSTA_NLW) {
  3421. case PCI_EXP_LNKSTA_NLW_X1:
  3422. hw->bus.width = i40e_bus_width_pcie_x1;
  3423. break;
  3424. case PCI_EXP_LNKSTA_NLW_X2:
  3425. hw->bus.width = i40e_bus_width_pcie_x2;
  3426. break;
  3427. case PCI_EXP_LNKSTA_NLW_X4:
  3428. hw->bus.width = i40e_bus_width_pcie_x4;
  3429. break;
  3430. case PCI_EXP_LNKSTA_NLW_X8:
  3431. hw->bus.width = i40e_bus_width_pcie_x8;
  3432. break;
  3433. default:
  3434. hw->bus.width = i40e_bus_width_unknown;
  3435. break;
  3436. }
  3437. switch (link_status & PCI_EXP_LNKSTA_CLS) {
  3438. case PCI_EXP_LNKSTA_CLS_2_5GB:
  3439. hw->bus.speed = i40e_bus_speed_2500;
  3440. break;
  3441. case PCI_EXP_LNKSTA_CLS_5_0GB:
  3442. hw->bus.speed = i40e_bus_speed_5000;
  3443. break;
  3444. case PCI_EXP_LNKSTA_CLS_8_0GB:
  3445. hw->bus.speed = i40e_bus_speed_8000;
  3446. break;
  3447. default:
  3448. hw->bus.speed = i40e_bus_speed_unknown;
  3449. break;
  3450. }
  3451. }
  3452. /**
  3453. * i40e_aq_debug_dump
  3454. * @hw: pointer to the hardware structure
  3455. * @cluster_id: specific cluster to dump
  3456. * @table_id: table id within cluster
  3457. * @start_index: index of line in the block to read
  3458. * @buff_size: dump buffer size
  3459. * @buff: dump buffer
  3460. * @ret_buff_size: actual buffer size returned
  3461. * @ret_next_table: next block to read
  3462. * @ret_next_index: next index to read
  3463. *
  3464. * Dump internal FW/HW data for debug purposes.
  3465. *
  3466. **/
  3467. i40e_status i40e_aq_debug_dump(struct i40e_hw *hw, u8 cluster_id,
  3468. u8 table_id, u32 start_index, u16 buff_size,
  3469. void *buff, u16 *ret_buff_size,
  3470. u8 *ret_next_table, u32 *ret_next_index,
  3471. struct i40e_asq_cmd_details *cmd_details)
  3472. {
  3473. struct i40e_aq_desc desc;
  3474. struct i40e_aqc_debug_dump_internals *cmd =
  3475. (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
  3476. struct i40e_aqc_debug_dump_internals *resp =
  3477. (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
  3478. i40e_status status;
  3479. if (buff_size == 0 || !buff)
  3480. return I40E_ERR_PARAM;
  3481. i40e_fill_default_direct_cmd_desc(&desc,
  3482. i40e_aqc_opc_debug_dump_internals);
  3483. /* Indirect Command */
  3484. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  3485. if (buff_size > I40E_AQ_LARGE_BUF)
  3486. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  3487. cmd->cluster_id = cluster_id;
  3488. cmd->table_id = table_id;
  3489. cmd->idx = cpu_to_le32(start_index);
  3490. desc.datalen = cpu_to_le16(buff_size);
  3491. status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  3492. if (!status) {
  3493. if (ret_buff_size)
  3494. *ret_buff_size = le16_to_cpu(desc.datalen);
  3495. if (ret_next_table)
  3496. *ret_next_table = resp->table_id;
  3497. if (ret_next_index)
  3498. *ret_next_index = le32_to_cpu(resp->idx);
  3499. }
  3500. return status;
  3501. }
  3502. /**
  3503. * i40e_read_bw_from_alt_ram
  3504. * @hw: pointer to the hardware structure
  3505. * @max_bw: pointer for max_bw read
  3506. * @min_bw: pointer for min_bw read
  3507. * @min_valid: pointer for bool that is true if min_bw is a valid value
  3508. * @max_valid: pointer for bool that is true if max_bw is a valid value
  3509. *
  3510. * Read bw from the alternate ram for the given pf
  3511. **/
  3512. i40e_status i40e_read_bw_from_alt_ram(struct i40e_hw *hw,
  3513. u32 *max_bw, u32 *min_bw,
  3514. bool *min_valid, bool *max_valid)
  3515. {
  3516. i40e_status status;
  3517. u32 max_bw_addr, min_bw_addr;
  3518. /* Calculate the address of the min/max bw registers */
  3519. max_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
  3520. I40E_ALT_STRUCT_MAX_BW_OFFSET +
  3521. (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
  3522. min_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
  3523. I40E_ALT_STRUCT_MIN_BW_OFFSET +
  3524. (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
  3525. /* Read the bandwidths from alt ram */
  3526. status = i40e_aq_alternate_read(hw, max_bw_addr, max_bw,
  3527. min_bw_addr, min_bw);
  3528. if (*min_bw & I40E_ALT_BW_VALID_MASK)
  3529. *min_valid = true;
  3530. else
  3531. *min_valid = false;
  3532. if (*max_bw & I40E_ALT_BW_VALID_MASK)
  3533. *max_valid = true;
  3534. else
  3535. *max_valid = false;
  3536. return status;
  3537. }
  3538. /**
  3539. * i40e_aq_configure_partition_bw
  3540. * @hw: pointer to the hardware structure
  3541. * @bw_data: Buffer holding valid pfs and bw limits
  3542. * @cmd_details: pointer to command details
  3543. *
  3544. * Configure partitions guaranteed/max bw
  3545. **/
  3546. i40e_status i40e_aq_configure_partition_bw(struct i40e_hw *hw,
  3547. struct i40e_aqc_configure_partition_bw_data *bw_data,
  3548. struct i40e_asq_cmd_details *cmd_details)
  3549. {
  3550. i40e_status status;
  3551. struct i40e_aq_desc desc;
  3552. u16 bwd_size = sizeof(*bw_data);
  3553. i40e_fill_default_direct_cmd_desc(&desc,
  3554. i40e_aqc_opc_configure_partition_bw);
  3555. /* Indirect command */
  3556. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  3557. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
  3558. if (bwd_size > I40E_AQ_LARGE_BUF)
  3559. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  3560. desc.datalen = cpu_to_le16(bwd_size);
  3561. status = i40e_asq_send_command(hw, &desc, bw_data, bwd_size,
  3562. cmd_details);
  3563. return status;
  3564. }