i40e_common.c 119 KB

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