i40e_common.c 102 KB

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