i40e_common.c 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441
  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. if (blink)
  1010. gpio_val |= (1 << I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
  1011. else
  1012. gpio_val &= ~(1 << I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
  1013. wr32(hw, I40E_GLGEN_GPIO_CTL(i), gpio_val);
  1014. break;
  1015. }
  1016. }
  1017. /* Admin command wrappers */
  1018. /**
  1019. * i40e_aq_get_phy_capabilities
  1020. * @hw: pointer to the hw struct
  1021. * @abilities: structure for PHY capabilities to be filled
  1022. * @qualified_modules: report Qualified Modules
  1023. * @report_init: report init capabilities (active are default)
  1024. * @cmd_details: pointer to command details structure or NULL
  1025. *
  1026. * Returns the various PHY abilities supported on the Port.
  1027. **/
  1028. i40e_status i40e_aq_get_phy_capabilities(struct i40e_hw *hw,
  1029. bool qualified_modules, bool report_init,
  1030. struct i40e_aq_get_phy_abilities_resp *abilities,
  1031. struct i40e_asq_cmd_details *cmd_details)
  1032. {
  1033. struct i40e_aq_desc desc;
  1034. i40e_status status;
  1035. u16 abilities_size = sizeof(struct i40e_aq_get_phy_abilities_resp);
  1036. if (!abilities)
  1037. return I40E_ERR_PARAM;
  1038. i40e_fill_default_direct_cmd_desc(&desc,
  1039. i40e_aqc_opc_get_phy_abilities);
  1040. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  1041. if (abilities_size > I40E_AQ_LARGE_BUF)
  1042. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1043. if (qualified_modules)
  1044. desc.params.external.param0 |=
  1045. cpu_to_le32(I40E_AQ_PHY_REPORT_QUALIFIED_MODULES);
  1046. if (report_init)
  1047. desc.params.external.param0 |=
  1048. cpu_to_le32(I40E_AQ_PHY_REPORT_INITIAL_VALUES);
  1049. status = i40e_asq_send_command(hw, &desc, abilities, abilities_size,
  1050. cmd_details);
  1051. if (hw->aq.asq_last_status == I40E_AQ_RC_EIO)
  1052. status = I40E_ERR_UNKNOWN_PHY;
  1053. return status;
  1054. }
  1055. /**
  1056. * i40e_aq_set_phy_config
  1057. * @hw: pointer to the hw struct
  1058. * @config: structure with PHY configuration to be set
  1059. * @cmd_details: pointer to command details structure or NULL
  1060. *
  1061. * Set the various PHY configuration parameters
  1062. * supported on the Port.One or more of the Set PHY config parameters may be
  1063. * ignored in an MFP mode as the PF may not have the privilege to set some
  1064. * of the PHY Config parameters. This status will be indicated by the
  1065. * command response.
  1066. **/
  1067. enum i40e_status_code i40e_aq_set_phy_config(struct i40e_hw *hw,
  1068. struct i40e_aq_set_phy_config *config,
  1069. struct i40e_asq_cmd_details *cmd_details)
  1070. {
  1071. struct i40e_aq_desc desc;
  1072. struct i40e_aq_set_phy_config *cmd =
  1073. (struct i40e_aq_set_phy_config *)&desc.params.raw;
  1074. enum i40e_status_code status;
  1075. if (!config)
  1076. return I40E_ERR_PARAM;
  1077. i40e_fill_default_direct_cmd_desc(&desc,
  1078. i40e_aqc_opc_set_phy_config);
  1079. *cmd = *config;
  1080. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1081. return status;
  1082. }
  1083. /**
  1084. * i40e_set_fc
  1085. * @hw: pointer to the hw struct
  1086. *
  1087. * Set the requested flow control mode using set_phy_config.
  1088. **/
  1089. enum i40e_status_code i40e_set_fc(struct i40e_hw *hw, u8 *aq_failures,
  1090. bool atomic_restart)
  1091. {
  1092. enum i40e_fc_mode fc_mode = hw->fc.requested_mode;
  1093. struct i40e_aq_get_phy_abilities_resp abilities;
  1094. struct i40e_aq_set_phy_config config;
  1095. enum i40e_status_code status;
  1096. u8 pause_mask = 0x0;
  1097. *aq_failures = 0x0;
  1098. switch (fc_mode) {
  1099. case I40E_FC_FULL:
  1100. pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
  1101. pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
  1102. break;
  1103. case I40E_FC_RX_PAUSE:
  1104. pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
  1105. break;
  1106. case I40E_FC_TX_PAUSE:
  1107. pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
  1108. break;
  1109. default:
  1110. break;
  1111. }
  1112. /* Get the current phy config */
  1113. status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
  1114. NULL);
  1115. if (status) {
  1116. *aq_failures |= I40E_SET_FC_AQ_FAIL_GET;
  1117. return status;
  1118. }
  1119. memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
  1120. /* clear the old pause settings */
  1121. config.abilities = abilities.abilities & ~(I40E_AQ_PHY_FLAG_PAUSE_TX) &
  1122. ~(I40E_AQ_PHY_FLAG_PAUSE_RX);
  1123. /* set the new abilities */
  1124. config.abilities |= pause_mask;
  1125. /* If the abilities have changed, then set the new config */
  1126. if (config.abilities != abilities.abilities) {
  1127. /* Auto restart link so settings take effect */
  1128. if (atomic_restart)
  1129. config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
  1130. /* Copy over all the old settings */
  1131. config.phy_type = abilities.phy_type;
  1132. config.link_speed = abilities.link_speed;
  1133. config.eee_capability = abilities.eee_capability;
  1134. config.eeer = abilities.eeer_val;
  1135. config.low_power_ctrl = abilities.d3_lpan;
  1136. status = i40e_aq_set_phy_config(hw, &config, NULL);
  1137. if (status)
  1138. *aq_failures |= I40E_SET_FC_AQ_FAIL_SET;
  1139. }
  1140. /* Update the link info */
  1141. status = i40e_update_link_info(hw, true);
  1142. if (status) {
  1143. /* Wait a little bit (on 40G cards it sometimes takes a really
  1144. * long time for link to come back from the atomic reset)
  1145. * and try once more
  1146. */
  1147. msleep(1000);
  1148. status = i40e_update_link_info(hw, true);
  1149. }
  1150. if (status)
  1151. *aq_failures |= I40E_SET_FC_AQ_FAIL_UPDATE;
  1152. return status;
  1153. }
  1154. /**
  1155. * i40e_aq_clear_pxe_mode
  1156. * @hw: pointer to the hw struct
  1157. * @cmd_details: pointer to command details structure or NULL
  1158. *
  1159. * Tell the firmware that the driver is taking over from PXE
  1160. **/
  1161. i40e_status i40e_aq_clear_pxe_mode(struct i40e_hw *hw,
  1162. struct i40e_asq_cmd_details *cmd_details)
  1163. {
  1164. i40e_status status;
  1165. struct i40e_aq_desc desc;
  1166. struct i40e_aqc_clear_pxe *cmd =
  1167. (struct i40e_aqc_clear_pxe *)&desc.params.raw;
  1168. i40e_fill_default_direct_cmd_desc(&desc,
  1169. i40e_aqc_opc_clear_pxe_mode);
  1170. cmd->rx_cnt = 0x2;
  1171. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1172. wr32(hw, I40E_GLLAN_RCTL_0, 0x1);
  1173. return status;
  1174. }
  1175. /**
  1176. * i40e_aq_set_link_restart_an
  1177. * @hw: pointer to the hw struct
  1178. * @enable_link: if true: enable link, if false: disable link
  1179. * @cmd_details: pointer to command details structure or NULL
  1180. *
  1181. * Sets up the link and restarts the Auto-Negotiation over the link.
  1182. **/
  1183. i40e_status i40e_aq_set_link_restart_an(struct i40e_hw *hw,
  1184. bool enable_link,
  1185. struct i40e_asq_cmd_details *cmd_details)
  1186. {
  1187. struct i40e_aq_desc desc;
  1188. struct i40e_aqc_set_link_restart_an *cmd =
  1189. (struct i40e_aqc_set_link_restart_an *)&desc.params.raw;
  1190. i40e_status status;
  1191. i40e_fill_default_direct_cmd_desc(&desc,
  1192. i40e_aqc_opc_set_link_restart_an);
  1193. cmd->command = I40E_AQ_PHY_RESTART_AN;
  1194. if (enable_link)
  1195. cmd->command |= I40E_AQ_PHY_LINK_ENABLE;
  1196. else
  1197. cmd->command &= ~I40E_AQ_PHY_LINK_ENABLE;
  1198. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1199. return status;
  1200. }
  1201. /**
  1202. * i40e_aq_get_link_info
  1203. * @hw: pointer to the hw struct
  1204. * @enable_lse: enable/disable LinkStatusEvent reporting
  1205. * @link: pointer to link status structure - optional
  1206. * @cmd_details: pointer to command details structure or NULL
  1207. *
  1208. * Returns the link status of the adapter.
  1209. **/
  1210. i40e_status i40e_aq_get_link_info(struct i40e_hw *hw,
  1211. bool enable_lse, struct i40e_link_status *link,
  1212. struct i40e_asq_cmd_details *cmd_details)
  1213. {
  1214. struct i40e_aq_desc desc;
  1215. struct i40e_aqc_get_link_status *resp =
  1216. (struct i40e_aqc_get_link_status *)&desc.params.raw;
  1217. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  1218. i40e_status status;
  1219. bool tx_pause, rx_pause;
  1220. u16 command_flags;
  1221. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_link_status);
  1222. if (enable_lse)
  1223. command_flags = I40E_AQ_LSE_ENABLE;
  1224. else
  1225. command_flags = I40E_AQ_LSE_DISABLE;
  1226. resp->command_flags = cpu_to_le16(command_flags);
  1227. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1228. if (status)
  1229. goto aq_get_link_info_exit;
  1230. /* save off old link status information */
  1231. hw->phy.link_info_old = *hw_link_info;
  1232. /* update link status */
  1233. hw_link_info->phy_type = (enum i40e_aq_phy_type)resp->phy_type;
  1234. hw->phy.media_type = i40e_get_media_type(hw);
  1235. hw_link_info->link_speed = (enum i40e_aq_link_speed)resp->link_speed;
  1236. hw_link_info->link_info = resp->link_info;
  1237. hw_link_info->an_info = resp->an_info;
  1238. hw_link_info->ext_info = resp->ext_info;
  1239. hw_link_info->loopback = resp->loopback;
  1240. hw_link_info->max_frame_size = le16_to_cpu(resp->max_frame_size);
  1241. hw_link_info->pacing = resp->config & I40E_AQ_CONFIG_PACING_MASK;
  1242. /* update fc info */
  1243. tx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_TX);
  1244. rx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_RX);
  1245. if (tx_pause & rx_pause)
  1246. hw->fc.current_mode = I40E_FC_FULL;
  1247. else if (tx_pause)
  1248. hw->fc.current_mode = I40E_FC_TX_PAUSE;
  1249. else if (rx_pause)
  1250. hw->fc.current_mode = I40E_FC_RX_PAUSE;
  1251. else
  1252. hw->fc.current_mode = I40E_FC_NONE;
  1253. if (resp->config & I40E_AQ_CONFIG_CRC_ENA)
  1254. hw_link_info->crc_enable = true;
  1255. else
  1256. hw_link_info->crc_enable = false;
  1257. if (resp->command_flags & cpu_to_le16(I40E_AQ_LSE_ENABLE))
  1258. hw_link_info->lse_enable = true;
  1259. else
  1260. hw_link_info->lse_enable = false;
  1261. /* save link status information */
  1262. if (link)
  1263. *link = *hw_link_info;
  1264. /* flag cleared so helper functions don't call AQ again */
  1265. hw->phy.get_link_info = false;
  1266. aq_get_link_info_exit:
  1267. return status;
  1268. }
  1269. /**
  1270. * i40e_update_link_info
  1271. * @hw: pointer to the hw struct
  1272. * @enable_lse: enable/disable LinkStatusEvent reporting
  1273. *
  1274. * Returns the link status of the adapter
  1275. **/
  1276. i40e_status i40e_update_link_info(struct i40e_hw *hw, bool enable_lse)
  1277. {
  1278. struct i40e_aq_get_phy_abilities_resp abilities;
  1279. i40e_status status;
  1280. status = i40e_aq_get_link_info(hw, enable_lse, NULL, NULL);
  1281. if (status)
  1282. return status;
  1283. status = i40e_aq_get_phy_capabilities(hw, false, false,
  1284. &abilities, NULL);
  1285. if (status)
  1286. return status;
  1287. if (abilities.abilities & I40E_AQ_PHY_AN_ENABLED)
  1288. hw->phy.link_info.an_enabled = true;
  1289. else
  1290. hw->phy.link_info.an_enabled = false;
  1291. return status;
  1292. }
  1293. /**
  1294. * i40e_aq_set_phy_int_mask
  1295. * @hw: pointer to the hw struct
  1296. * @mask: interrupt mask to be set
  1297. * @cmd_details: pointer to command details structure or NULL
  1298. *
  1299. * Set link interrupt mask.
  1300. **/
  1301. i40e_status i40e_aq_set_phy_int_mask(struct i40e_hw *hw,
  1302. u16 mask,
  1303. struct i40e_asq_cmd_details *cmd_details)
  1304. {
  1305. struct i40e_aq_desc desc;
  1306. struct i40e_aqc_set_phy_int_mask *cmd =
  1307. (struct i40e_aqc_set_phy_int_mask *)&desc.params.raw;
  1308. i40e_status status;
  1309. i40e_fill_default_direct_cmd_desc(&desc,
  1310. i40e_aqc_opc_set_phy_int_mask);
  1311. cmd->event_mask = cpu_to_le16(mask);
  1312. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1313. return status;
  1314. }
  1315. /**
  1316. * i40e_aq_add_vsi
  1317. * @hw: pointer to the hw struct
  1318. * @vsi_ctx: pointer to a vsi context struct
  1319. * @cmd_details: pointer to command details structure or NULL
  1320. *
  1321. * Add a VSI context to the hardware.
  1322. **/
  1323. i40e_status i40e_aq_add_vsi(struct i40e_hw *hw,
  1324. struct i40e_vsi_context *vsi_ctx,
  1325. struct i40e_asq_cmd_details *cmd_details)
  1326. {
  1327. struct i40e_aq_desc desc;
  1328. struct i40e_aqc_add_get_update_vsi *cmd =
  1329. (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
  1330. struct i40e_aqc_add_get_update_vsi_completion *resp =
  1331. (struct i40e_aqc_add_get_update_vsi_completion *)
  1332. &desc.params.raw;
  1333. i40e_status status;
  1334. i40e_fill_default_direct_cmd_desc(&desc,
  1335. i40e_aqc_opc_add_vsi);
  1336. cmd->uplink_seid = cpu_to_le16(vsi_ctx->uplink_seid);
  1337. cmd->connection_type = vsi_ctx->connection_type;
  1338. cmd->vf_id = vsi_ctx->vf_num;
  1339. cmd->vsi_flags = cpu_to_le16(vsi_ctx->flags);
  1340. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  1341. status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
  1342. sizeof(vsi_ctx->info), cmd_details);
  1343. if (status)
  1344. goto aq_add_vsi_exit;
  1345. vsi_ctx->seid = le16_to_cpu(resp->seid);
  1346. vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
  1347. vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
  1348. vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
  1349. aq_add_vsi_exit:
  1350. return status;
  1351. }
  1352. /**
  1353. * i40e_aq_set_vsi_unicast_promiscuous
  1354. * @hw: pointer to the hw struct
  1355. * @seid: vsi number
  1356. * @set: set unicast promiscuous enable/disable
  1357. * @cmd_details: pointer to command details structure or NULL
  1358. **/
  1359. i40e_status i40e_aq_set_vsi_unicast_promiscuous(struct i40e_hw *hw,
  1360. u16 seid, bool set,
  1361. struct i40e_asq_cmd_details *cmd_details)
  1362. {
  1363. struct i40e_aq_desc desc;
  1364. struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
  1365. (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
  1366. i40e_status status;
  1367. u16 flags = 0;
  1368. i40e_fill_default_direct_cmd_desc(&desc,
  1369. i40e_aqc_opc_set_vsi_promiscuous_modes);
  1370. if (set)
  1371. flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
  1372. cmd->promiscuous_flags = cpu_to_le16(flags);
  1373. cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
  1374. cmd->seid = cpu_to_le16(seid);
  1375. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1376. return status;
  1377. }
  1378. /**
  1379. * i40e_aq_set_vsi_multicast_promiscuous
  1380. * @hw: pointer to the hw struct
  1381. * @seid: vsi number
  1382. * @set: set multicast promiscuous enable/disable
  1383. * @cmd_details: pointer to command details structure or NULL
  1384. **/
  1385. i40e_status i40e_aq_set_vsi_multicast_promiscuous(struct i40e_hw *hw,
  1386. u16 seid, bool set, struct i40e_asq_cmd_details *cmd_details)
  1387. {
  1388. struct i40e_aq_desc desc;
  1389. struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
  1390. (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
  1391. i40e_status status;
  1392. u16 flags = 0;
  1393. i40e_fill_default_direct_cmd_desc(&desc,
  1394. i40e_aqc_opc_set_vsi_promiscuous_modes);
  1395. if (set)
  1396. flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
  1397. cmd->promiscuous_flags = cpu_to_le16(flags);
  1398. cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
  1399. cmd->seid = cpu_to_le16(seid);
  1400. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1401. return status;
  1402. }
  1403. /**
  1404. * i40e_aq_set_vsi_broadcast
  1405. * @hw: pointer to the hw struct
  1406. * @seid: vsi number
  1407. * @set_filter: true to set filter, false to clear filter
  1408. * @cmd_details: pointer to command details structure or NULL
  1409. *
  1410. * Set or clear the broadcast promiscuous flag (filter) for a given VSI.
  1411. **/
  1412. i40e_status i40e_aq_set_vsi_broadcast(struct i40e_hw *hw,
  1413. u16 seid, bool set_filter,
  1414. struct i40e_asq_cmd_details *cmd_details)
  1415. {
  1416. struct i40e_aq_desc desc;
  1417. struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
  1418. (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
  1419. i40e_status status;
  1420. i40e_fill_default_direct_cmd_desc(&desc,
  1421. i40e_aqc_opc_set_vsi_promiscuous_modes);
  1422. if (set_filter)
  1423. cmd->promiscuous_flags
  1424. |= cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
  1425. else
  1426. cmd->promiscuous_flags
  1427. &= cpu_to_le16(~I40E_AQC_SET_VSI_PROMISC_BROADCAST);
  1428. cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
  1429. cmd->seid = cpu_to_le16(seid);
  1430. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1431. return status;
  1432. }
  1433. /**
  1434. * i40e_get_vsi_params - get VSI configuration info
  1435. * @hw: pointer to the hw struct
  1436. * @vsi_ctx: pointer to a vsi context struct
  1437. * @cmd_details: pointer to command details structure or NULL
  1438. **/
  1439. i40e_status i40e_aq_get_vsi_params(struct i40e_hw *hw,
  1440. struct i40e_vsi_context *vsi_ctx,
  1441. struct i40e_asq_cmd_details *cmd_details)
  1442. {
  1443. struct i40e_aq_desc desc;
  1444. struct i40e_aqc_add_get_update_vsi *cmd =
  1445. (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
  1446. struct i40e_aqc_add_get_update_vsi_completion *resp =
  1447. (struct i40e_aqc_add_get_update_vsi_completion *)
  1448. &desc.params.raw;
  1449. i40e_status status;
  1450. i40e_fill_default_direct_cmd_desc(&desc,
  1451. i40e_aqc_opc_get_vsi_parameters);
  1452. cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
  1453. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  1454. status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
  1455. sizeof(vsi_ctx->info), NULL);
  1456. if (status)
  1457. goto aq_get_vsi_params_exit;
  1458. vsi_ctx->seid = le16_to_cpu(resp->seid);
  1459. vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
  1460. vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
  1461. vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
  1462. aq_get_vsi_params_exit:
  1463. return status;
  1464. }
  1465. /**
  1466. * i40e_aq_update_vsi_params
  1467. * @hw: pointer to the hw struct
  1468. * @vsi_ctx: pointer to a vsi context struct
  1469. * @cmd_details: pointer to command details structure or NULL
  1470. *
  1471. * Update a VSI context.
  1472. **/
  1473. i40e_status i40e_aq_update_vsi_params(struct i40e_hw *hw,
  1474. struct i40e_vsi_context *vsi_ctx,
  1475. struct i40e_asq_cmd_details *cmd_details)
  1476. {
  1477. struct i40e_aq_desc desc;
  1478. struct i40e_aqc_add_get_update_vsi *cmd =
  1479. (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
  1480. i40e_status status;
  1481. i40e_fill_default_direct_cmd_desc(&desc,
  1482. i40e_aqc_opc_update_vsi_parameters);
  1483. cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
  1484. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  1485. status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
  1486. sizeof(vsi_ctx->info), cmd_details);
  1487. return status;
  1488. }
  1489. /**
  1490. * i40e_aq_get_switch_config
  1491. * @hw: pointer to the hardware structure
  1492. * @buf: pointer to the result buffer
  1493. * @buf_size: length of input buffer
  1494. * @start_seid: seid to start for the report, 0 == beginning
  1495. * @cmd_details: pointer to command details structure or NULL
  1496. *
  1497. * Fill the buf with switch configuration returned from AdminQ command
  1498. **/
  1499. i40e_status i40e_aq_get_switch_config(struct i40e_hw *hw,
  1500. struct i40e_aqc_get_switch_config_resp *buf,
  1501. u16 buf_size, u16 *start_seid,
  1502. struct i40e_asq_cmd_details *cmd_details)
  1503. {
  1504. struct i40e_aq_desc desc;
  1505. struct i40e_aqc_switch_seid *scfg =
  1506. (struct i40e_aqc_switch_seid *)&desc.params.raw;
  1507. i40e_status status;
  1508. i40e_fill_default_direct_cmd_desc(&desc,
  1509. i40e_aqc_opc_get_switch_config);
  1510. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  1511. if (buf_size > I40E_AQ_LARGE_BUF)
  1512. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1513. scfg->seid = cpu_to_le16(*start_seid);
  1514. status = i40e_asq_send_command(hw, &desc, buf, buf_size, cmd_details);
  1515. *start_seid = le16_to_cpu(scfg->seid);
  1516. return status;
  1517. }
  1518. /**
  1519. * i40e_aq_get_firmware_version
  1520. * @hw: pointer to the hw struct
  1521. * @fw_major_version: firmware major version
  1522. * @fw_minor_version: firmware minor version
  1523. * @api_major_version: major queue version
  1524. * @api_minor_version: minor queue version
  1525. * @cmd_details: pointer to command details structure or NULL
  1526. *
  1527. * Get the firmware version from the admin queue commands
  1528. **/
  1529. i40e_status i40e_aq_get_firmware_version(struct i40e_hw *hw,
  1530. u16 *fw_major_version, u16 *fw_minor_version,
  1531. u16 *api_major_version, u16 *api_minor_version,
  1532. struct i40e_asq_cmd_details *cmd_details)
  1533. {
  1534. struct i40e_aq_desc desc;
  1535. struct i40e_aqc_get_version *resp =
  1536. (struct i40e_aqc_get_version *)&desc.params.raw;
  1537. i40e_status status;
  1538. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_version);
  1539. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1540. if (!status) {
  1541. if (fw_major_version != NULL)
  1542. *fw_major_version = le16_to_cpu(resp->fw_major);
  1543. if (fw_minor_version != NULL)
  1544. *fw_minor_version = le16_to_cpu(resp->fw_minor);
  1545. if (api_major_version != NULL)
  1546. *api_major_version = le16_to_cpu(resp->api_major);
  1547. if (api_minor_version != NULL)
  1548. *api_minor_version = le16_to_cpu(resp->api_minor);
  1549. }
  1550. return status;
  1551. }
  1552. /**
  1553. * i40e_aq_send_driver_version
  1554. * @hw: pointer to the hw struct
  1555. * @dv: driver's major, minor version
  1556. * @cmd_details: pointer to command details structure or NULL
  1557. *
  1558. * Send the driver version to the firmware
  1559. **/
  1560. i40e_status i40e_aq_send_driver_version(struct i40e_hw *hw,
  1561. struct i40e_driver_version *dv,
  1562. struct i40e_asq_cmd_details *cmd_details)
  1563. {
  1564. struct i40e_aq_desc desc;
  1565. struct i40e_aqc_driver_version *cmd =
  1566. (struct i40e_aqc_driver_version *)&desc.params.raw;
  1567. i40e_status status;
  1568. u16 len;
  1569. if (dv == NULL)
  1570. return I40E_ERR_PARAM;
  1571. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_driver_version);
  1572. desc.flags |= cpu_to_le16(I40E_AQ_FLAG_SI);
  1573. cmd->driver_major_ver = dv->major_version;
  1574. cmd->driver_minor_ver = dv->minor_version;
  1575. cmd->driver_build_ver = dv->build_version;
  1576. cmd->driver_subbuild_ver = dv->subbuild_version;
  1577. len = 0;
  1578. while (len < sizeof(dv->driver_string) &&
  1579. (dv->driver_string[len] < 0x80) &&
  1580. dv->driver_string[len])
  1581. len++;
  1582. status = i40e_asq_send_command(hw, &desc, dv->driver_string,
  1583. len, cmd_details);
  1584. return status;
  1585. }
  1586. /**
  1587. * i40e_get_link_status - get status of the HW network link
  1588. * @hw: pointer to the hw struct
  1589. *
  1590. * Returns true if link is up, false if link is down.
  1591. *
  1592. * Side effect: LinkStatusEvent reporting becomes enabled
  1593. **/
  1594. bool i40e_get_link_status(struct i40e_hw *hw)
  1595. {
  1596. i40e_status status = 0;
  1597. bool link_status = false;
  1598. if (hw->phy.get_link_info) {
  1599. status = i40e_aq_get_link_info(hw, true, NULL, NULL);
  1600. if (status)
  1601. goto i40e_get_link_status_exit;
  1602. }
  1603. link_status = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
  1604. i40e_get_link_status_exit:
  1605. return link_status;
  1606. }
  1607. /**
  1608. * i40e_aq_add_veb - Insert a VEB between the VSI and the MAC
  1609. * @hw: pointer to the hw struct
  1610. * @uplink_seid: the MAC or other gizmo SEID
  1611. * @downlink_seid: the VSI SEID
  1612. * @enabled_tc: bitmap of TCs to be enabled
  1613. * @default_port: true for default port VSI, false for control port
  1614. * @enable_l2_filtering: true to add L2 filter table rules to regular forwarding rules for cloud support
  1615. * @veb_seid: pointer to where to put the resulting VEB SEID
  1616. * @cmd_details: pointer to command details structure or NULL
  1617. *
  1618. * This asks the FW to add a VEB between the uplink and downlink
  1619. * elements. If the uplink SEID is 0, this will be a floating VEB.
  1620. **/
  1621. i40e_status i40e_aq_add_veb(struct i40e_hw *hw, u16 uplink_seid,
  1622. u16 downlink_seid, u8 enabled_tc,
  1623. bool default_port, bool enable_l2_filtering,
  1624. u16 *veb_seid,
  1625. struct i40e_asq_cmd_details *cmd_details)
  1626. {
  1627. struct i40e_aq_desc desc;
  1628. struct i40e_aqc_add_veb *cmd =
  1629. (struct i40e_aqc_add_veb *)&desc.params.raw;
  1630. struct i40e_aqc_add_veb_completion *resp =
  1631. (struct i40e_aqc_add_veb_completion *)&desc.params.raw;
  1632. i40e_status status;
  1633. u16 veb_flags = 0;
  1634. /* SEIDs need to either both be set or both be 0 for floating VEB */
  1635. if (!!uplink_seid != !!downlink_seid)
  1636. return I40E_ERR_PARAM;
  1637. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_veb);
  1638. cmd->uplink_seid = cpu_to_le16(uplink_seid);
  1639. cmd->downlink_seid = cpu_to_le16(downlink_seid);
  1640. cmd->enable_tcs = enabled_tc;
  1641. if (!uplink_seid)
  1642. veb_flags |= I40E_AQC_ADD_VEB_FLOATING;
  1643. if (default_port)
  1644. veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DEFAULT;
  1645. else
  1646. veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DATA;
  1647. if (enable_l2_filtering)
  1648. veb_flags |= I40E_AQC_ADD_VEB_ENABLE_L2_FILTER;
  1649. cmd->veb_flags = cpu_to_le16(veb_flags);
  1650. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1651. if (!status && veb_seid)
  1652. *veb_seid = le16_to_cpu(resp->veb_seid);
  1653. return status;
  1654. }
  1655. /**
  1656. * i40e_aq_get_veb_parameters - Retrieve VEB parameters
  1657. * @hw: pointer to the hw struct
  1658. * @veb_seid: the SEID of the VEB to query
  1659. * @switch_id: the uplink switch id
  1660. * @floating: set to true if the VEB is floating
  1661. * @statistic_index: index of the stats counter block for this VEB
  1662. * @vebs_used: number of VEB's used by function
  1663. * @vebs_free: total VEB's not reserved by any function
  1664. * @cmd_details: pointer to command details structure or NULL
  1665. *
  1666. * This retrieves the parameters for a particular VEB, specified by
  1667. * uplink_seid, and returns them to the caller.
  1668. **/
  1669. i40e_status i40e_aq_get_veb_parameters(struct i40e_hw *hw,
  1670. u16 veb_seid, u16 *switch_id,
  1671. bool *floating, u16 *statistic_index,
  1672. u16 *vebs_used, u16 *vebs_free,
  1673. struct i40e_asq_cmd_details *cmd_details)
  1674. {
  1675. struct i40e_aq_desc desc;
  1676. struct i40e_aqc_get_veb_parameters_completion *cmd_resp =
  1677. (struct i40e_aqc_get_veb_parameters_completion *)
  1678. &desc.params.raw;
  1679. i40e_status status;
  1680. if (veb_seid == 0)
  1681. return I40E_ERR_PARAM;
  1682. i40e_fill_default_direct_cmd_desc(&desc,
  1683. i40e_aqc_opc_get_veb_parameters);
  1684. cmd_resp->seid = cpu_to_le16(veb_seid);
  1685. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1686. if (status)
  1687. goto get_veb_exit;
  1688. if (switch_id)
  1689. *switch_id = le16_to_cpu(cmd_resp->switch_id);
  1690. if (statistic_index)
  1691. *statistic_index = le16_to_cpu(cmd_resp->statistic_index);
  1692. if (vebs_used)
  1693. *vebs_used = le16_to_cpu(cmd_resp->vebs_used);
  1694. if (vebs_free)
  1695. *vebs_free = le16_to_cpu(cmd_resp->vebs_free);
  1696. if (floating) {
  1697. u16 flags = le16_to_cpu(cmd_resp->veb_flags);
  1698. if (flags & I40E_AQC_ADD_VEB_FLOATING)
  1699. *floating = true;
  1700. else
  1701. *floating = false;
  1702. }
  1703. get_veb_exit:
  1704. return status;
  1705. }
  1706. /**
  1707. * i40e_aq_add_macvlan
  1708. * @hw: pointer to the hw struct
  1709. * @seid: VSI for the mac address
  1710. * @mv_list: list of macvlans to be added
  1711. * @count: length of the list
  1712. * @cmd_details: pointer to command details structure or NULL
  1713. *
  1714. * Add MAC/VLAN addresses to the HW filtering
  1715. **/
  1716. i40e_status i40e_aq_add_macvlan(struct i40e_hw *hw, u16 seid,
  1717. struct i40e_aqc_add_macvlan_element_data *mv_list,
  1718. u16 count, struct i40e_asq_cmd_details *cmd_details)
  1719. {
  1720. struct i40e_aq_desc desc;
  1721. struct i40e_aqc_macvlan *cmd =
  1722. (struct i40e_aqc_macvlan *)&desc.params.raw;
  1723. i40e_status status;
  1724. u16 buf_size;
  1725. if (count == 0 || !mv_list || !hw)
  1726. return I40E_ERR_PARAM;
  1727. buf_size = count * sizeof(struct i40e_aqc_add_macvlan_element_data);
  1728. /* prep the rest of the request */
  1729. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_macvlan);
  1730. cmd->num_addresses = cpu_to_le16(count);
  1731. cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
  1732. cmd->seid[1] = 0;
  1733. cmd->seid[2] = 0;
  1734. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  1735. if (buf_size > I40E_AQ_LARGE_BUF)
  1736. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1737. status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
  1738. cmd_details);
  1739. return status;
  1740. }
  1741. /**
  1742. * i40e_aq_remove_macvlan
  1743. * @hw: pointer to the hw struct
  1744. * @seid: VSI for the mac address
  1745. * @mv_list: list of macvlans to be removed
  1746. * @count: length of the list
  1747. * @cmd_details: pointer to command details structure or NULL
  1748. *
  1749. * Remove MAC/VLAN addresses from the HW filtering
  1750. **/
  1751. i40e_status i40e_aq_remove_macvlan(struct i40e_hw *hw, u16 seid,
  1752. struct i40e_aqc_remove_macvlan_element_data *mv_list,
  1753. u16 count, struct i40e_asq_cmd_details *cmd_details)
  1754. {
  1755. struct i40e_aq_desc desc;
  1756. struct i40e_aqc_macvlan *cmd =
  1757. (struct i40e_aqc_macvlan *)&desc.params.raw;
  1758. i40e_status status;
  1759. u16 buf_size;
  1760. if (count == 0 || !mv_list || !hw)
  1761. return I40E_ERR_PARAM;
  1762. buf_size = count * sizeof(struct i40e_aqc_remove_macvlan_element_data);
  1763. /* prep the rest of the request */
  1764. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_macvlan);
  1765. cmd->num_addresses = cpu_to_le16(count);
  1766. cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
  1767. cmd->seid[1] = 0;
  1768. cmd->seid[2] = 0;
  1769. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  1770. if (buf_size > I40E_AQ_LARGE_BUF)
  1771. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1772. status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
  1773. cmd_details);
  1774. return status;
  1775. }
  1776. /**
  1777. * i40e_aq_send_msg_to_vf
  1778. * @hw: pointer to the hardware structure
  1779. * @vfid: vf id to send msg
  1780. * @v_opcode: opcodes for VF-PF communication
  1781. * @v_retval: return error code
  1782. * @msg: pointer to the msg buffer
  1783. * @msglen: msg length
  1784. * @cmd_details: pointer to command details
  1785. *
  1786. * send msg to vf
  1787. **/
  1788. i40e_status i40e_aq_send_msg_to_vf(struct i40e_hw *hw, u16 vfid,
  1789. u32 v_opcode, u32 v_retval, u8 *msg, u16 msglen,
  1790. struct i40e_asq_cmd_details *cmd_details)
  1791. {
  1792. struct i40e_aq_desc desc;
  1793. struct i40e_aqc_pf_vf_message *cmd =
  1794. (struct i40e_aqc_pf_vf_message *)&desc.params.raw;
  1795. i40e_status status;
  1796. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_vf);
  1797. cmd->id = cpu_to_le32(vfid);
  1798. desc.cookie_high = cpu_to_le32(v_opcode);
  1799. desc.cookie_low = cpu_to_le32(v_retval);
  1800. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_SI);
  1801. if (msglen) {
  1802. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
  1803. I40E_AQ_FLAG_RD));
  1804. if (msglen > I40E_AQ_LARGE_BUF)
  1805. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1806. desc.datalen = cpu_to_le16(msglen);
  1807. }
  1808. status = i40e_asq_send_command(hw, &desc, msg, msglen, cmd_details);
  1809. return status;
  1810. }
  1811. /**
  1812. * i40e_aq_debug_read_register
  1813. * @hw: pointer to the hw struct
  1814. * @reg_addr: register address
  1815. * @reg_val: register value
  1816. * @cmd_details: pointer to command details structure or NULL
  1817. *
  1818. * Read the register using the admin queue commands
  1819. **/
  1820. i40e_status i40e_aq_debug_read_register(struct i40e_hw *hw,
  1821. u32 reg_addr, u64 *reg_val,
  1822. struct i40e_asq_cmd_details *cmd_details)
  1823. {
  1824. struct i40e_aq_desc desc;
  1825. struct i40e_aqc_debug_reg_read_write *cmd_resp =
  1826. (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
  1827. i40e_status status;
  1828. if (reg_val == NULL)
  1829. return I40E_ERR_PARAM;
  1830. i40e_fill_default_direct_cmd_desc(&desc,
  1831. i40e_aqc_opc_debug_read_reg);
  1832. cmd_resp->address = cpu_to_le32(reg_addr);
  1833. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1834. if (!status) {
  1835. *reg_val = ((u64)cmd_resp->value_high << 32) |
  1836. (u64)cmd_resp->value_low;
  1837. *reg_val = le64_to_cpu(*reg_val);
  1838. }
  1839. return status;
  1840. }
  1841. /**
  1842. * i40e_aq_debug_write_register
  1843. * @hw: pointer to the hw struct
  1844. * @reg_addr: register address
  1845. * @reg_val: register value
  1846. * @cmd_details: pointer to command details structure or NULL
  1847. *
  1848. * Write to a register using the admin queue commands
  1849. **/
  1850. i40e_status i40e_aq_debug_write_register(struct i40e_hw *hw,
  1851. u32 reg_addr, u64 reg_val,
  1852. struct i40e_asq_cmd_details *cmd_details)
  1853. {
  1854. struct i40e_aq_desc desc;
  1855. struct i40e_aqc_debug_reg_read_write *cmd =
  1856. (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
  1857. i40e_status status;
  1858. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_write_reg);
  1859. cmd->address = cpu_to_le32(reg_addr);
  1860. cmd->value_high = cpu_to_le32((u32)(reg_val >> 32));
  1861. cmd->value_low = cpu_to_le32((u32)(reg_val & 0xFFFFFFFF));
  1862. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1863. return status;
  1864. }
  1865. /**
  1866. * i40e_aq_set_hmc_resource_profile
  1867. * @hw: pointer to the hw struct
  1868. * @profile: type of profile the HMC is to be set as
  1869. * @pe_vf_enabled_count: the number of PE enabled VFs the system has
  1870. * @cmd_details: pointer to command details structure or NULL
  1871. *
  1872. * set the HMC profile of the device.
  1873. **/
  1874. i40e_status i40e_aq_set_hmc_resource_profile(struct i40e_hw *hw,
  1875. enum i40e_aq_hmc_profile profile,
  1876. u8 pe_vf_enabled_count,
  1877. struct i40e_asq_cmd_details *cmd_details)
  1878. {
  1879. struct i40e_aq_desc desc;
  1880. struct i40e_aq_get_set_hmc_resource_profile *cmd =
  1881. (struct i40e_aq_get_set_hmc_resource_profile *)&desc.params.raw;
  1882. i40e_status status;
  1883. i40e_fill_default_direct_cmd_desc(&desc,
  1884. i40e_aqc_opc_set_hmc_resource_profile);
  1885. cmd->pm_profile = (u8)profile;
  1886. cmd->pe_vf_enabled = pe_vf_enabled_count;
  1887. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1888. return status;
  1889. }
  1890. /**
  1891. * i40e_aq_request_resource
  1892. * @hw: pointer to the hw struct
  1893. * @resource: resource id
  1894. * @access: access type
  1895. * @sdp_number: resource number
  1896. * @timeout: the maximum time in ms that the driver may hold the resource
  1897. * @cmd_details: pointer to command details structure or NULL
  1898. *
  1899. * requests common resource using the admin queue commands
  1900. **/
  1901. i40e_status i40e_aq_request_resource(struct i40e_hw *hw,
  1902. enum i40e_aq_resources_ids resource,
  1903. enum i40e_aq_resource_access_type access,
  1904. u8 sdp_number, u64 *timeout,
  1905. struct i40e_asq_cmd_details *cmd_details)
  1906. {
  1907. struct i40e_aq_desc desc;
  1908. struct i40e_aqc_request_resource *cmd_resp =
  1909. (struct i40e_aqc_request_resource *)&desc.params.raw;
  1910. i40e_status status;
  1911. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_request_resource);
  1912. cmd_resp->resource_id = cpu_to_le16(resource);
  1913. cmd_resp->access_type = cpu_to_le16(access);
  1914. cmd_resp->resource_number = cpu_to_le32(sdp_number);
  1915. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1916. /* The completion specifies the maximum time in ms that the driver
  1917. * may hold the resource in the Timeout field.
  1918. * If the resource is held by someone else, the command completes with
  1919. * busy return value and the timeout field indicates the maximum time
  1920. * the current owner of the resource has to free it.
  1921. */
  1922. if (!status || hw->aq.asq_last_status == I40E_AQ_RC_EBUSY)
  1923. *timeout = le32_to_cpu(cmd_resp->timeout);
  1924. return status;
  1925. }
  1926. /**
  1927. * i40e_aq_release_resource
  1928. * @hw: pointer to the hw struct
  1929. * @resource: resource id
  1930. * @sdp_number: resource number
  1931. * @cmd_details: pointer to command details structure or NULL
  1932. *
  1933. * release common resource using the admin queue commands
  1934. **/
  1935. i40e_status i40e_aq_release_resource(struct i40e_hw *hw,
  1936. enum i40e_aq_resources_ids resource,
  1937. u8 sdp_number,
  1938. struct i40e_asq_cmd_details *cmd_details)
  1939. {
  1940. struct i40e_aq_desc desc;
  1941. struct i40e_aqc_request_resource *cmd =
  1942. (struct i40e_aqc_request_resource *)&desc.params.raw;
  1943. i40e_status status;
  1944. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_release_resource);
  1945. cmd->resource_id = cpu_to_le16(resource);
  1946. cmd->resource_number = cpu_to_le32(sdp_number);
  1947. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1948. return status;
  1949. }
  1950. /**
  1951. * i40e_aq_read_nvm
  1952. * @hw: pointer to the hw struct
  1953. * @module_pointer: module pointer location in words from the NVM beginning
  1954. * @offset: byte offset from the module beginning
  1955. * @length: length of the section to be read (in bytes from the offset)
  1956. * @data: command buffer (size [bytes] = length)
  1957. * @last_command: tells if this is the last command in a series
  1958. * @cmd_details: pointer to command details structure or NULL
  1959. *
  1960. * Read the NVM using the admin queue commands
  1961. **/
  1962. i40e_status i40e_aq_read_nvm(struct i40e_hw *hw, u8 module_pointer,
  1963. u32 offset, u16 length, void *data,
  1964. bool last_command,
  1965. struct i40e_asq_cmd_details *cmd_details)
  1966. {
  1967. struct i40e_aq_desc desc;
  1968. struct i40e_aqc_nvm_update *cmd =
  1969. (struct i40e_aqc_nvm_update *)&desc.params.raw;
  1970. i40e_status status;
  1971. /* In offset the highest byte must be zeroed. */
  1972. if (offset & 0xFF000000) {
  1973. status = I40E_ERR_PARAM;
  1974. goto i40e_aq_read_nvm_exit;
  1975. }
  1976. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_read);
  1977. /* If this is the last command in a series, set the proper flag. */
  1978. if (last_command)
  1979. cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
  1980. cmd->module_pointer = module_pointer;
  1981. cmd->offset = cpu_to_le32(offset);
  1982. cmd->length = cpu_to_le16(length);
  1983. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  1984. if (length > I40E_AQ_LARGE_BUF)
  1985. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1986. status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
  1987. i40e_aq_read_nvm_exit:
  1988. return status;
  1989. }
  1990. /**
  1991. * i40e_aq_erase_nvm
  1992. * @hw: pointer to the hw struct
  1993. * @module_pointer: module pointer location in words from the NVM beginning
  1994. * @offset: offset in the module (expressed in 4 KB from module's beginning)
  1995. * @length: length of the section to be erased (expressed in 4 KB)
  1996. * @last_command: tells if this is the last command in a series
  1997. * @cmd_details: pointer to command details structure or NULL
  1998. *
  1999. * Erase the NVM sector using the admin queue commands
  2000. **/
  2001. i40e_status i40e_aq_erase_nvm(struct i40e_hw *hw, u8 module_pointer,
  2002. u32 offset, u16 length, bool last_command,
  2003. struct i40e_asq_cmd_details *cmd_details)
  2004. {
  2005. struct i40e_aq_desc desc;
  2006. struct i40e_aqc_nvm_update *cmd =
  2007. (struct i40e_aqc_nvm_update *)&desc.params.raw;
  2008. i40e_status status;
  2009. /* In offset the highest byte must be zeroed. */
  2010. if (offset & 0xFF000000) {
  2011. status = I40E_ERR_PARAM;
  2012. goto i40e_aq_erase_nvm_exit;
  2013. }
  2014. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_erase);
  2015. /* If this is the last command in a series, set the proper flag. */
  2016. if (last_command)
  2017. cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
  2018. cmd->module_pointer = module_pointer;
  2019. cmd->offset = cpu_to_le32(offset);
  2020. cmd->length = cpu_to_le16(length);
  2021. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2022. i40e_aq_erase_nvm_exit:
  2023. return status;
  2024. }
  2025. #define I40E_DEV_FUNC_CAP_SWITCH_MODE 0x01
  2026. #define I40E_DEV_FUNC_CAP_MGMT_MODE 0x02
  2027. #define I40E_DEV_FUNC_CAP_NPAR 0x03
  2028. #define I40E_DEV_FUNC_CAP_OS2BMC 0x04
  2029. #define I40E_DEV_FUNC_CAP_VALID_FUNC 0x05
  2030. #define I40E_DEV_FUNC_CAP_SRIOV_1_1 0x12
  2031. #define I40E_DEV_FUNC_CAP_VF 0x13
  2032. #define I40E_DEV_FUNC_CAP_VMDQ 0x14
  2033. #define I40E_DEV_FUNC_CAP_802_1_QBG 0x15
  2034. #define I40E_DEV_FUNC_CAP_802_1_QBH 0x16
  2035. #define I40E_DEV_FUNC_CAP_VSI 0x17
  2036. #define I40E_DEV_FUNC_CAP_DCB 0x18
  2037. #define I40E_DEV_FUNC_CAP_FCOE 0x21
  2038. #define I40E_DEV_FUNC_CAP_ISCSI 0x22
  2039. #define I40E_DEV_FUNC_CAP_RSS 0x40
  2040. #define I40E_DEV_FUNC_CAP_RX_QUEUES 0x41
  2041. #define I40E_DEV_FUNC_CAP_TX_QUEUES 0x42
  2042. #define I40E_DEV_FUNC_CAP_MSIX 0x43
  2043. #define I40E_DEV_FUNC_CAP_MSIX_VF 0x44
  2044. #define I40E_DEV_FUNC_CAP_FLOW_DIRECTOR 0x45
  2045. #define I40E_DEV_FUNC_CAP_IEEE_1588 0x46
  2046. #define I40E_DEV_FUNC_CAP_MFP_MODE_1 0xF1
  2047. #define I40E_DEV_FUNC_CAP_CEM 0xF2
  2048. #define I40E_DEV_FUNC_CAP_IWARP 0x51
  2049. #define I40E_DEV_FUNC_CAP_LED 0x61
  2050. #define I40E_DEV_FUNC_CAP_SDP 0x62
  2051. #define I40E_DEV_FUNC_CAP_MDIO 0x63
  2052. /**
  2053. * i40e_parse_discover_capabilities
  2054. * @hw: pointer to the hw struct
  2055. * @buff: pointer to a buffer containing device/function capability records
  2056. * @cap_count: number of capability records in the list
  2057. * @list_type_opc: type of capabilities list to parse
  2058. *
  2059. * Parse the device/function capabilities list.
  2060. **/
  2061. static void i40e_parse_discover_capabilities(struct i40e_hw *hw, void *buff,
  2062. u32 cap_count,
  2063. enum i40e_admin_queue_opc list_type_opc)
  2064. {
  2065. struct i40e_aqc_list_capabilities_element_resp *cap;
  2066. u32 valid_functions, num_functions;
  2067. u32 number, logical_id, phys_id;
  2068. struct i40e_hw_capabilities *p;
  2069. u32 i = 0;
  2070. u16 id;
  2071. cap = (struct i40e_aqc_list_capabilities_element_resp *) buff;
  2072. if (list_type_opc == i40e_aqc_opc_list_dev_capabilities)
  2073. p = &hw->dev_caps;
  2074. else if (list_type_opc == i40e_aqc_opc_list_func_capabilities)
  2075. p = &hw->func_caps;
  2076. else
  2077. return;
  2078. for (i = 0; i < cap_count; i++, cap++) {
  2079. id = le16_to_cpu(cap->id);
  2080. number = le32_to_cpu(cap->number);
  2081. logical_id = le32_to_cpu(cap->logical_id);
  2082. phys_id = le32_to_cpu(cap->phys_id);
  2083. switch (id) {
  2084. case I40E_DEV_FUNC_CAP_SWITCH_MODE:
  2085. p->switch_mode = number;
  2086. break;
  2087. case I40E_DEV_FUNC_CAP_MGMT_MODE:
  2088. p->management_mode = number;
  2089. break;
  2090. case I40E_DEV_FUNC_CAP_NPAR:
  2091. p->npar_enable = number;
  2092. break;
  2093. case I40E_DEV_FUNC_CAP_OS2BMC:
  2094. p->os2bmc = number;
  2095. break;
  2096. case I40E_DEV_FUNC_CAP_VALID_FUNC:
  2097. p->valid_functions = number;
  2098. break;
  2099. case I40E_DEV_FUNC_CAP_SRIOV_1_1:
  2100. if (number == 1)
  2101. p->sr_iov_1_1 = true;
  2102. break;
  2103. case I40E_DEV_FUNC_CAP_VF:
  2104. p->num_vfs = number;
  2105. p->vf_base_id = logical_id;
  2106. break;
  2107. case I40E_DEV_FUNC_CAP_VMDQ:
  2108. if (number == 1)
  2109. p->vmdq = true;
  2110. break;
  2111. case I40E_DEV_FUNC_CAP_802_1_QBG:
  2112. if (number == 1)
  2113. p->evb_802_1_qbg = true;
  2114. break;
  2115. case I40E_DEV_FUNC_CAP_802_1_QBH:
  2116. if (number == 1)
  2117. p->evb_802_1_qbh = true;
  2118. break;
  2119. case I40E_DEV_FUNC_CAP_VSI:
  2120. p->num_vsis = number;
  2121. break;
  2122. case I40E_DEV_FUNC_CAP_DCB:
  2123. if (number == 1) {
  2124. p->dcb = true;
  2125. p->enabled_tcmap = logical_id;
  2126. p->maxtc = phys_id;
  2127. }
  2128. break;
  2129. case I40E_DEV_FUNC_CAP_FCOE:
  2130. if (number == 1)
  2131. p->fcoe = true;
  2132. break;
  2133. case I40E_DEV_FUNC_CAP_ISCSI:
  2134. if (number == 1)
  2135. p->iscsi = true;
  2136. break;
  2137. case I40E_DEV_FUNC_CAP_RSS:
  2138. p->rss = true;
  2139. p->rss_table_size = number;
  2140. p->rss_table_entry_width = logical_id;
  2141. break;
  2142. case I40E_DEV_FUNC_CAP_RX_QUEUES:
  2143. p->num_rx_qp = number;
  2144. p->base_queue = phys_id;
  2145. break;
  2146. case I40E_DEV_FUNC_CAP_TX_QUEUES:
  2147. p->num_tx_qp = number;
  2148. p->base_queue = phys_id;
  2149. break;
  2150. case I40E_DEV_FUNC_CAP_MSIX:
  2151. p->num_msix_vectors = number;
  2152. break;
  2153. case I40E_DEV_FUNC_CAP_MSIX_VF:
  2154. p->num_msix_vectors_vf = number;
  2155. break;
  2156. case I40E_DEV_FUNC_CAP_MFP_MODE_1:
  2157. if (number == 1)
  2158. p->mfp_mode_1 = true;
  2159. break;
  2160. case I40E_DEV_FUNC_CAP_CEM:
  2161. if (number == 1)
  2162. p->mgmt_cem = true;
  2163. break;
  2164. case I40E_DEV_FUNC_CAP_IWARP:
  2165. if (number == 1)
  2166. p->iwarp = true;
  2167. break;
  2168. case I40E_DEV_FUNC_CAP_LED:
  2169. if (phys_id < I40E_HW_CAP_MAX_GPIO)
  2170. p->led[phys_id] = true;
  2171. break;
  2172. case I40E_DEV_FUNC_CAP_SDP:
  2173. if (phys_id < I40E_HW_CAP_MAX_GPIO)
  2174. p->sdp[phys_id] = true;
  2175. break;
  2176. case I40E_DEV_FUNC_CAP_MDIO:
  2177. if (number == 1) {
  2178. p->mdio_port_num = phys_id;
  2179. p->mdio_port_mode = logical_id;
  2180. }
  2181. break;
  2182. case I40E_DEV_FUNC_CAP_IEEE_1588:
  2183. if (number == 1)
  2184. p->ieee_1588 = true;
  2185. break;
  2186. case I40E_DEV_FUNC_CAP_FLOW_DIRECTOR:
  2187. p->fd = true;
  2188. p->fd_filters_guaranteed = number;
  2189. p->fd_filters_best_effort = logical_id;
  2190. break;
  2191. default:
  2192. break;
  2193. }
  2194. }
  2195. /* Software override ensuring FCoE is disabled if npar or mfp
  2196. * mode because it is not supported in these modes.
  2197. */
  2198. if (p->npar_enable || p->mfp_mode_1)
  2199. p->fcoe = false;
  2200. /* count the enabled ports (aka the "not disabled" ports) */
  2201. hw->num_ports = 0;
  2202. for (i = 0; i < 4; i++) {
  2203. u32 port_cfg_reg = I40E_PRTGEN_CNF + (4 * i);
  2204. u64 port_cfg = 0;
  2205. /* use AQ read to get the physical register offset instead
  2206. * of the port relative offset
  2207. */
  2208. i40e_aq_debug_read_register(hw, port_cfg_reg, &port_cfg, NULL);
  2209. if (!(port_cfg & I40E_PRTGEN_CNF_PORT_DIS_MASK))
  2210. hw->num_ports++;
  2211. }
  2212. valid_functions = p->valid_functions;
  2213. num_functions = 0;
  2214. while (valid_functions) {
  2215. if (valid_functions & 1)
  2216. num_functions++;
  2217. valid_functions >>= 1;
  2218. }
  2219. /* partition id is 1-based, and functions are evenly spread
  2220. * across the ports as partitions
  2221. */
  2222. hw->partition_id = (hw->pf_id / hw->num_ports) + 1;
  2223. hw->num_partitions = num_functions / hw->num_ports;
  2224. /* additional HW specific goodies that might
  2225. * someday be HW version specific
  2226. */
  2227. p->rx_buf_chain_len = I40E_MAX_CHAINED_RX_BUFFERS;
  2228. }
  2229. /**
  2230. * i40e_aq_discover_capabilities
  2231. * @hw: pointer to the hw struct
  2232. * @buff: a virtual buffer to hold the capabilities
  2233. * @buff_size: Size of the virtual buffer
  2234. * @data_size: Size of the returned data, or buff size needed if AQ err==ENOMEM
  2235. * @list_type_opc: capabilities type to discover - pass in the command opcode
  2236. * @cmd_details: pointer to command details structure or NULL
  2237. *
  2238. * Get the device capabilities descriptions from the firmware
  2239. **/
  2240. i40e_status i40e_aq_discover_capabilities(struct i40e_hw *hw,
  2241. void *buff, u16 buff_size, u16 *data_size,
  2242. enum i40e_admin_queue_opc list_type_opc,
  2243. struct i40e_asq_cmd_details *cmd_details)
  2244. {
  2245. struct i40e_aqc_list_capabilites *cmd;
  2246. struct i40e_aq_desc desc;
  2247. i40e_status status = 0;
  2248. cmd = (struct i40e_aqc_list_capabilites *)&desc.params.raw;
  2249. if (list_type_opc != i40e_aqc_opc_list_func_capabilities &&
  2250. list_type_opc != i40e_aqc_opc_list_dev_capabilities) {
  2251. status = I40E_ERR_PARAM;
  2252. goto exit;
  2253. }
  2254. i40e_fill_default_direct_cmd_desc(&desc, list_type_opc);
  2255. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2256. if (buff_size > I40E_AQ_LARGE_BUF)
  2257. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2258. status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  2259. *data_size = le16_to_cpu(desc.datalen);
  2260. if (status)
  2261. goto exit;
  2262. i40e_parse_discover_capabilities(hw, buff, le32_to_cpu(cmd->count),
  2263. list_type_opc);
  2264. exit:
  2265. return status;
  2266. }
  2267. /**
  2268. * i40e_aq_update_nvm
  2269. * @hw: pointer to the hw struct
  2270. * @module_pointer: module pointer location in words from the NVM beginning
  2271. * @offset: byte offset from the module beginning
  2272. * @length: length of the section to be written (in bytes from the offset)
  2273. * @data: command buffer (size [bytes] = length)
  2274. * @last_command: tells if this is the last command in a series
  2275. * @cmd_details: pointer to command details structure or NULL
  2276. *
  2277. * Update the NVM using the admin queue commands
  2278. **/
  2279. i40e_status i40e_aq_update_nvm(struct i40e_hw *hw, u8 module_pointer,
  2280. u32 offset, u16 length, void *data,
  2281. bool last_command,
  2282. struct i40e_asq_cmd_details *cmd_details)
  2283. {
  2284. struct i40e_aq_desc desc;
  2285. struct i40e_aqc_nvm_update *cmd =
  2286. (struct i40e_aqc_nvm_update *)&desc.params.raw;
  2287. i40e_status status;
  2288. /* In offset the highest byte must be zeroed. */
  2289. if (offset & 0xFF000000) {
  2290. status = I40E_ERR_PARAM;
  2291. goto i40e_aq_update_nvm_exit;
  2292. }
  2293. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_update);
  2294. /* If this is the last command in a series, set the proper flag. */
  2295. if (last_command)
  2296. cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
  2297. cmd->module_pointer = module_pointer;
  2298. cmd->offset = cpu_to_le32(offset);
  2299. cmd->length = cpu_to_le16(length);
  2300. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  2301. if (length > I40E_AQ_LARGE_BUF)
  2302. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2303. status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
  2304. i40e_aq_update_nvm_exit:
  2305. return status;
  2306. }
  2307. /**
  2308. * i40e_aq_get_lldp_mib
  2309. * @hw: pointer to the hw struct
  2310. * @bridge_type: type of bridge requested
  2311. * @mib_type: Local, Remote or both Local and Remote MIBs
  2312. * @buff: pointer to a user supplied buffer to store the MIB block
  2313. * @buff_size: size of the buffer (in bytes)
  2314. * @local_len : length of the returned Local LLDP MIB
  2315. * @remote_len: length of the returned Remote LLDP MIB
  2316. * @cmd_details: pointer to command details structure or NULL
  2317. *
  2318. * Requests the complete LLDP MIB (entire packet).
  2319. **/
  2320. i40e_status i40e_aq_get_lldp_mib(struct i40e_hw *hw, u8 bridge_type,
  2321. u8 mib_type, void *buff, u16 buff_size,
  2322. u16 *local_len, u16 *remote_len,
  2323. struct i40e_asq_cmd_details *cmd_details)
  2324. {
  2325. struct i40e_aq_desc desc;
  2326. struct i40e_aqc_lldp_get_mib *cmd =
  2327. (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
  2328. struct i40e_aqc_lldp_get_mib *resp =
  2329. (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
  2330. i40e_status status;
  2331. if (buff_size == 0 || !buff)
  2332. return I40E_ERR_PARAM;
  2333. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_get_mib);
  2334. /* Indirect Command */
  2335. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2336. cmd->type = mib_type & I40E_AQ_LLDP_MIB_TYPE_MASK;
  2337. cmd->type |= ((bridge_type << I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) &
  2338. I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
  2339. desc.datalen = cpu_to_le16(buff_size);
  2340. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2341. if (buff_size > I40E_AQ_LARGE_BUF)
  2342. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2343. status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  2344. if (!status) {
  2345. if (local_len != NULL)
  2346. *local_len = le16_to_cpu(resp->local_len);
  2347. if (remote_len != NULL)
  2348. *remote_len = le16_to_cpu(resp->remote_len);
  2349. }
  2350. return status;
  2351. }
  2352. /**
  2353. * i40e_aq_cfg_lldp_mib_change_event
  2354. * @hw: pointer to the hw struct
  2355. * @enable_update: Enable or Disable event posting
  2356. * @cmd_details: pointer to command details structure or NULL
  2357. *
  2358. * Enable or Disable posting of an event on ARQ when LLDP MIB
  2359. * associated with the interface changes
  2360. **/
  2361. i40e_status i40e_aq_cfg_lldp_mib_change_event(struct i40e_hw *hw,
  2362. bool enable_update,
  2363. struct i40e_asq_cmd_details *cmd_details)
  2364. {
  2365. struct i40e_aq_desc desc;
  2366. struct i40e_aqc_lldp_update_mib *cmd =
  2367. (struct i40e_aqc_lldp_update_mib *)&desc.params.raw;
  2368. i40e_status status;
  2369. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_update_mib);
  2370. if (!enable_update)
  2371. cmd->command |= I40E_AQ_LLDP_MIB_UPDATE_DISABLE;
  2372. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2373. return status;
  2374. }
  2375. /**
  2376. * i40e_aq_stop_lldp
  2377. * @hw: pointer to the hw struct
  2378. * @shutdown_agent: True if LLDP Agent needs to be Shutdown
  2379. * @cmd_details: pointer to command details structure or NULL
  2380. *
  2381. * Stop or Shutdown the embedded LLDP Agent
  2382. **/
  2383. i40e_status i40e_aq_stop_lldp(struct i40e_hw *hw, bool shutdown_agent,
  2384. struct i40e_asq_cmd_details *cmd_details)
  2385. {
  2386. struct i40e_aq_desc desc;
  2387. struct i40e_aqc_lldp_stop *cmd =
  2388. (struct i40e_aqc_lldp_stop *)&desc.params.raw;
  2389. i40e_status status;
  2390. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_stop);
  2391. if (shutdown_agent)
  2392. cmd->command |= I40E_AQ_LLDP_AGENT_SHUTDOWN;
  2393. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2394. return status;
  2395. }
  2396. /**
  2397. * i40e_aq_start_lldp
  2398. * @hw: pointer to the hw struct
  2399. * @cmd_details: pointer to command details structure or NULL
  2400. *
  2401. * Start the embedded LLDP Agent on all ports.
  2402. **/
  2403. i40e_status i40e_aq_start_lldp(struct i40e_hw *hw,
  2404. struct i40e_asq_cmd_details *cmd_details)
  2405. {
  2406. struct i40e_aq_desc desc;
  2407. struct i40e_aqc_lldp_start *cmd =
  2408. (struct i40e_aqc_lldp_start *)&desc.params.raw;
  2409. i40e_status status;
  2410. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_start);
  2411. cmd->command = I40E_AQ_LLDP_AGENT_START;
  2412. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2413. return status;
  2414. }
  2415. /**
  2416. * i40e_aq_get_cee_dcb_config
  2417. * @hw: pointer to the hw struct
  2418. * @buff: response buffer that stores CEE operational configuration
  2419. * @buff_size: size of the buffer passed
  2420. * @cmd_details: pointer to command details structure or NULL
  2421. *
  2422. * Get CEE DCBX mode operational configuration from firmware
  2423. **/
  2424. i40e_status i40e_aq_get_cee_dcb_config(struct i40e_hw *hw,
  2425. void *buff, u16 buff_size,
  2426. struct i40e_asq_cmd_details *cmd_details)
  2427. {
  2428. struct i40e_aq_desc desc;
  2429. i40e_status status;
  2430. if (buff_size == 0 || !buff)
  2431. return I40E_ERR_PARAM;
  2432. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_cee_dcb_cfg);
  2433. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2434. status = i40e_asq_send_command(hw, &desc, (void *)buff, buff_size,
  2435. cmd_details);
  2436. return status;
  2437. }
  2438. /**
  2439. * i40e_aq_add_udp_tunnel
  2440. * @hw: pointer to the hw struct
  2441. * @udp_port: the UDP port to add
  2442. * @header_len: length of the tunneling header length in DWords
  2443. * @protocol_index: protocol index type
  2444. * @filter_index: pointer to filter index
  2445. * @cmd_details: pointer to command details structure or NULL
  2446. **/
  2447. i40e_status i40e_aq_add_udp_tunnel(struct i40e_hw *hw,
  2448. u16 udp_port, u8 protocol_index,
  2449. u8 *filter_index,
  2450. struct i40e_asq_cmd_details *cmd_details)
  2451. {
  2452. struct i40e_aq_desc desc;
  2453. struct i40e_aqc_add_udp_tunnel *cmd =
  2454. (struct i40e_aqc_add_udp_tunnel *)&desc.params.raw;
  2455. struct i40e_aqc_del_udp_tunnel_completion *resp =
  2456. (struct i40e_aqc_del_udp_tunnel_completion *)&desc.params.raw;
  2457. i40e_status status;
  2458. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_udp_tunnel);
  2459. cmd->udp_port = cpu_to_le16(udp_port);
  2460. cmd->protocol_type = protocol_index;
  2461. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2462. if (!status)
  2463. *filter_index = resp->index;
  2464. return status;
  2465. }
  2466. /**
  2467. * i40e_aq_del_udp_tunnel
  2468. * @hw: pointer to the hw struct
  2469. * @index: filter index
  2470. * @cmd_details: pointer to command details structure or NULL
  2471. **/
  2472. i40e_status i40e_aq_del_udp_tunnel(struct i40e_hw *hw, u8 index,
  2473. struct i40e_asq_cmd_details *cmd_details)
  2474. {
  2475. struct i40e_aq_desc desc;
  2476. struct i40e_aqc_remove_udp_tunnel *cmd =
  2477. (struct i40e_aqc_remove_udp_tunnel *)&desc.params.raw;
  2478. i40e_status status;
  2479. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_del_udp_tunnel);
  2480. cmd->index = index;
  2481. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2482. return status;
  2483. }
  2484. /**
  2485. * i40e_aq_delete_element - Delete switch element
  2486. * @hw: pointer to the hw struct
  2487. * @seid: the SEID to delete from the switch
  2488. * @cmd_details: pointer to command details structure or NULL
  2489. *
  2490. * This deletes a switch element from the switch.
  2491. **/
  2492. i40e_status i40e_aq_delete_element(struct i40e_hw *hw, u16 seid,
  2493. struct i40e_asq_cmd_details *cmd_details)
  2494. {
  2495. struct i40e_aq_desc desc;
  2496. struct i40e_aqc_switch_seid *cmd =
  2497. (struct i40e_aqc_switch_seid *)&desc.params.raw;
  2498. i40e_status status;
  2499. if (seid == 0)
  2500. return I40E_ERR_PARAM;
  2501. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_delete_element);
  2502. cmd->seid = cpu_to_le16(seid);
  2503. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2504. return status;
  2505. }
  2506. /**
  2507. * i40e_aq_dcb_updated - DCB Updated Command
  2508. * @hw: pointer to the hw struct
  2509. * @cmd_details: pointer to command details structure or NULL
  2510. *
  2511. * EMP will return when the shared RPB settings have been
  2512. * recomputed and modified. The retval field in the descriptor
  2513. * will be set to 0 when RPB is modified.
  2514. **/
  2515. i40e_status i40e_aq_dcb_updated(struct i40e_hw *hw,
  2516. struct i40e_asq_cmd_details *cmd_details)
  2517. {
  2518. struct i40e_aq_desc desc;
  2519. i40e_status status;
  2520. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_dcb_updated);
  2521. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2522. return status;
  2523. }
  2524. /**
  2525. * i40e_aq_tx_sched_cmd - generic Tx scheduler AQ command handler
  2526. * @hw: pointer to the hw struct
  2527. * @seid: seid for the physical port/switching component/vsi
  2528. * @buff: Indirect buffer to hold data parameters and response
  2529. * @buff_size: Indirect buffer size
  2530. * @opcode: Tx scheduler AQ command opcode
  2531. * @cmd_details: pointer to command details structure or NULL
  2532. *
  2533. * Generic command handler for Tx scheduler AQ commands
  2534. **/
  2535. static i40e_status i40e_aq_tx_sched_cmd(struct i40e_hw *hw, u16 seid,
  2536. void *buff, u16 buff_size,
  2537. enum i40e_admin_queue_opc opcode,
  2538. struct i40e_asq_cmd_details *cmd_details)
  2539. {
  2540. struct i40e_aq_desc desc;
  2541. struct i40e_aqc_tx_sched_ind *cmd =
  2542. (struct i40e_aqc_tx_sched_ind *)&desc.params.raw;
  2543. i40e_status status;
  2544. bool cmd_param_flag = false;
  2545. switch (opcode) {
  2546. case i40e_aqc_opc_configure_vsi_ets_sla_bw_limit:
  2547. case i40e_aqc_opc_configure_vsi_tc_bw:
  2548. case i40e_aqc_opc_enable_switching_comp_ets:
  2549. case i40e_aqc_opc_modify_switching_comp_ets:
  2550. case i40e_aqc_opc_disable_switching_comp_ets:
  2551. case i40e_aqc_opc_configure_switching_comp_ets_bw_limit:
  2552. case i40e_aqc_opc_configure_switching_comp_bw_config:
  2553. cmd_param_flag = true;
  2554. break;
  2555. case i40e_aqc_opc_query_vsi_bw_config:
  2556. case i40e_aqc_opc_query_vsi_ets_sla_config:
  2557. case i40e_aqc_opc_query_switching_comp_ets_config:
  2558. case i40e_aqc_opc_query_port_ets_config:
  2559. case i40e_aqc_opc_query_switching_comp_bw_config:
  2560. cmd_param_flag = false;
  2561. break;
  2562. default:
  2563. return I40E_ERR_PARAM;
  2564. }
  2565. i40e_fill_default_direct_cmd_desc(&desc, opcode);
  2566. /* Indirect command */
  2567. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  2568. if (cmd_param_flag)
  2569. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
  2570. if (buff_size > I40E_AQ_LARGE_BUF)
  2571. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  2572. desc.datalen = cpu_to_le16(buff_size);
  2573. cmd->vsi_seid = cpu_to_le16(seid);
  2574. status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  2575. return status;
  2576. }
  2577. /**
  2578. * i40e_aq_config_vsi_bw_limit - Configure VSI BW Limit
  2579. * @hw: pointer to the hw struct
  2580. * @seid: VSI seid
  2581. * @credit: BW limit credits (0 = disabled)
  2582. * @max_credit: Max BW limit credits
  2583. * @cmd_details: pointer to command details structure or NULL
  2584. **/
  2585. i40e_status i40e_aq_config_vsi_bw_limit(struct i40e_hw *hw,
  2586. u16 seid, u16 credit, u8 max_credit,
  2587. struct i40e_asq_cmd_details *cmd_details)
  2588. {
  2589. struct i40e_aq_desc desc;
  2590. struct i40e_aqc_configure_vsi_bw_limit *cmd =
  2591. (struct i40e_aqc_configure_vsi_bw_limit *)&desc.params.raw;
  2592. i40e_status status;
  2593. i40e_fill_default_direct_cmd_desc(&desc,
  2594. i40e_aqc_opc_configure_vsi_bw_limit);
  2595. cmd->vsi_seid = cpu_to_le16(seid);
  2596. cmd->credit = cpu_to_le16(credit);
  2597. cmd->max_credit = max_credit;
  2598. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2599. return status;
  2600. }
  2601. /**
  2602. * i40e_aq_config_vsi_tc_bw - Config VSI BW Allocation per TC
  2603. * @hw: pointer to the hw struct
  2604. * @seid: VSI seid
  2605. * @bw_data: Buffer holding enabled TCs, relative TC BW limit/credits
  2606. * @cmd_details: pointer to command details structure or NULL
  2607. **/
  2608. i40e_status i40e_aq_config_vsi_tc_bw(struct i40e_hw *hw,
  2609. u16 seid,
  2610. struct i40e_aqc_configure_vsi_tc_bw_data *bw_data,
  2611. struct i40e_asq_cmd_details *cmd_details)
  2612. {
  2613. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  2614. i40e_aqc_opc_configure_vsi_tc_bw,
  2615. cmd_details);
  2616. }
  2617. /**
  2618. * i40e_aq_config_switch_comp_ets - Enable/Disable/Modify ETS on the port
  2619. * @hw: pointer to the hw struct
  2620. * @seid: seid of the switching component connected to Physical Port
  2621. * @ets_data: Buffer holding ETS parameters
  2622. * @cmd_details: pointer to command details structure or NULL
  2623. **/
  2624. i40e_status i40e_aq_config_switch_comp_ets(struct i40e_hw *hw,
  2625. u16 seid,
  2626. struct i40e_aqc_configure_switching_comp_ets_data *ets_data,
  2627. enum i40e_admin_queue_opc opcode,
  2628. struct i40e_asq_cmd_details *cmd_details)
  2629. {
  2630. return i40e_aq_tx_sched_cmd(hw, seid, (void *)ets_data,
  2631. sizeof(*ets_data), opcode, cmd_details);
  2632. }
  2633. /**
  2634. * i40e_aq_config_switch_comp_bw_config - Config Switch comp BW Alloc per TC
  2635. * @hw: pointer to the hw struct
  2636. * @seid: seid of the switching component
  2637. * @bw_data: Buffer holding enabled TCs, relative/absolute TC BW limit/credits
  2638. * @cmd_details: pointer to command details structure or NULL
  2639. **/
  2640. i40e_status i40e_aq_config_switch_comp_bw_config(struct i40e_hw *hw,
  2641. u16 seid,
  2642. struct i40e_aqc_configure_switching_comp_bw_config_data *bw_data,
  2643. struct i40e_asq_cmd_details *cmd_details)
  2644. {
  2645. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  2646. i40e_aqc_opc_configure_switching_comp_bw_config,
  2647. cmd_details);
  2648. }
  2649. /**
  2650. * i40e_aq_query_vsi_bw_config - Query VSI BW configuration
  2651. * @hw: pointer to the hw struct
  2652. * @seid: seid of the VSI
  2653. * @bw_data: Buffer to hold VSI BW configuration
  2654. * @cmd_details: pointer to command details structure or NULL
  2655. **/
  2656. i40e_status i40e_aq_query_vsi_bw_config(struct i40e_hw *hw,
  2657. u16 seid,
  2658. struct i40e_aqc_query_vsi_bw_config_resp *bw_data,
  2659. struct i40e_asq_cmd_details *cmd_details)
  2660. {
  2661. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  2662. i40e_aqc_opc_query_vsi_bw_config,
  2663. cmd_details);
  2664. }
  2665. /**
  2666. * i40e_aq_query_vsi_ets_sla_config - Query VSI BW configuration per TC
  2667. * @hw: pointer to the hw struct
  2668. * @seid: seid of the VSI
  2669. * @bw_data: Buffer to hold VSI BW configuration per TC
  2670. * @cmd_details: pointer to command details structure or NULL
  2671. **/
  2672. i40e_status i40e_aq_query_vsi_ets_sla_config(struct i40e_hw *hw,
  2673. u16 seid,
  2674. struct i40e_aqc_query_vsi_ets_sla_config_resp *bw_data,
  2675. struct i40e_asq_cmd_details *cmd_details)
  2676. {
  2677. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  2678. i40e_aqc_opc_query_vsi_ets_sla_config,
  2679. cmd_details);
  2680. }
  2681. /**
  2682. * i40e_aq_query_switch_comp_ets_config - Query Switch comp BW config per TC
  2683. * @hw: pointer to the hw struct
  2684. * @seid: seid of the switching component
  2685. * @bw_data: Buffer to hold switching component's per TC BW config
  2686. * @cmd_details: pointer to command details structure or NULL
  2687. **/
  2688. i40e_status i40e_aq_query_switch_comp_ets_config(struct i40e_hw *hw,
  2689. u16 seid,
  2690. struct i40e_aqc_query_switching_comp_ets_config_resp *bw_data,
  2691. struct i40e_asq_cmd_details *cmd_details)
  2692. {
  2693. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  2694. i40e_aqc_opc_query_switching_comp_ets_config,
  2695. cmd_details);
  2696. }
  2697. /**
  2698. * i40e_aq_query_port_ets_config - Query Physical Port ETS configuration
  2699. * @hw: pointer to the hw struct
  2700. * @seid: seid of the VSI or switching component connected to Physical Port
  2701. * @bw_data: Buffer to hold current ETS configuration for the Physical Port
  2702. * @cmd_details: pointer to command details structure or NULL
  2703. **/
  2704. i40e_status i40e_aq_query_port_ets_config(struct i40e_hw *hw,
  2705. u16 seid,
  2706. struct i40e_aqc_query_port_ets_config_resp *bw_data,
  2707. struct i40e_asq_cmd_details *cmd_details)
  2708. {
  2709. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  2710. i40e_aqc_opc_query_port_ets_config,
  2711. cmd_details);
  2712. }
  2713. /**
  2714. * i40e_aq_query_switch_comp_bw_config - Query Switch comp BW configuration
  2715. * @hw: pointer to the hw struct
  2716. * @seid: seid of the switching component
  2717. * @bw_data: Buffer to hold switching component's BW configuration
  2718. * @cmd_details: pointer to command details structure or NULL
  2719. **/
  2720. i40e_status i40e_aq_query_switch_comp_bw_config(struct i40e_hw *hw,
  2721. u16 seid,
  2722. struct i40e_aqc_query_switching_comp_bw_config_resp *bw_data,
  2723. struct i40e_asq_cmd_details *cmd_details)
  2724. {
  2725. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  2726. i40e_aqc_opc_query_switching_comp_bw_config,
  2727. cmd_details);
  2728. }
  2729. /**
  2730. * i40e_validate_filter_settings
  2731. * @hw: pointer to the hardware structure
  2732. * @settings: Filter control settings
  2733. *
  2734. * Check and validate the filter control settings passed.
  2735. * The function checks for the valid filter/context sizes being
  2736. * passed for FCoE and PE.
  2737. *
  2738. * Returns 0 if the values passed are valid and within
  2739. * range else returns an error.
  2740. **/
  2741. static i40e_status i40e_validate_filter_settings(struct i40e_hw *hw,
  2742. struct i40e_filter_control_settings *settings)
  2743. {
  2744. u32 fcoe_cntx_size, fcoe_filt_size;
  2745. u32 pe_cntx_size, pe_filt_size;
  2746. u32 fcoe_fmax;
  2747. u32 val;
  2748. /* Validate FCoE settings passed */
  2749. switch (settings->fcoe_filt_num) {
  2750. case I40E_HASH_FILTER_SIZE_1K:
  2751. case I40E_HASH_FILTER_SIZE_2K:
  2752. case I40E_HASH_FILTER_SIZE_4K:
  2753. case I40E_HASH_FILTER_SIZE_8K:
  2754. case I40E_HASH_FILTER_SIZE_16K:
  2755. case I40E_HASH_FILTER_SIZE_32K:
  2756. fcoe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
  2757. fcoe_filt_size <<= (u32)settings->fcoe_filt_num;
  2758. break;
  2759. default:
  2760. return I40E_ERR_PARAM;
  2761. }
  2762. switch (settings->fcoe_cntx_num) {
  2763. case I40E_DMA_CNTX_SIZE_512:
  2764. case I40E_DMA_CNTX_SIZE_1K:
  2765. case I40E_DMA_CNTX_SIZE_2K:
  2766. case I40E_DMA_CNTX_SIZE_4K:
  2767. fcoe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
  2768. fcoe_cntx_size <<= (u32)settings->fcoe_cntx_num;
  2769. break;
  2770. default:
  2771. return I40E_ERR_PARAM;
  2772. }
  2773. /* Validate PE settings passed */
  2774. switch (settings->pe_filt_num) {
  2775. case I40E_HASH_FILTER_SIZE_1K:
  2776. case I40E_HASH_FILTER_SIZE_2K:
  2777. case I40E_HASH_FILTER_SIZE_4K:
  2778. case I40E_HASH_FILTER_SIZE_8K:
  2779. case I40E_HASH_FILTER_SIZE_16K:
  2780. case I40E_HASH_FILTER_SIZE_32K:
  2781. case I40E_HASH_FILTER_SIZE_64K:
  2782. case I40E_HASH_FILTER_SIZE_128K:
  2783. case I40E_HASH_FILTER_SIZE_256K:
  2784. case I40E_HASH_FILTER_SIZE_512K:
  2785. case I40E_HASH_FILTER_SIZE_1M:
  2786. pe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
  2787. pe_filt_size <<= (u32)settings->pe_filt_num;
  2788. break;
  2789. default:
  2790. return I40E_ERR_PARAM;
  2791. }
  2792. switch (settings->pe_cntx_num) {
  2793. case I40E_DMA_CNTX_SIZE_512:
  2794. case I40E_DMA_CNTX_SIZE_1K:
  2795. case I40E_DMA_CNTX_SIZE_2K:
  2796. case I40E_DMA_CNTX_SIZE_4K:
  2797. case I40E_DMA_CNTX_SIZE_8K:
  2798. case I40E_DMA_CNTX_SIZE_16K:
  2799. case I40E_DMA_CNTX_SIZE_32K:
  2800. case I40E_DMA_CNTX_SIZE_64K:
  2801. case I40E_DMA_CNTX_SIZE_128K:
  2802. case I40E_DMA_CNTX_SIZE_256K:
  2803. pe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
  2804. pe_cntx_size <<= (u32)settings->pe_cntx_num;
  2805. break;
  2806. default:
  2807. return I40E_ERR_PARAM;
  2808. }
  2809. /* FCHSIZE + FCDSIZE should not be greater than PMFCOEFMAX */
  2810. val = rd32(hw, I40E_GLHMC_FCOEFMAX);
  2811. fcoe_fmax = (val & I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_MASK)
  2812. >> I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_SHIFT;
  2813. if (fcoe_filt_size + fcoe_cntx_size > fcoe_fmax)
  2814. return I40E_ERR_INVALID_SIZE;
  2815. return 0;
  2816. }
  2817. /**
  2818. * i40e_set_filter_control
  2819. * @hw: pointer to the hardware structure
  2820. * @settings: Filter control settings
  2821. *
  2822. * Set the Queue Filters for PE/FCoE and enable filters required
  2823. * for a single PF. It is expected that these settings are programmed
  2824. * at the driver initialization time.
  2825. **/
  2826. i40e_status i40e_set_filter_control(struct i40e_hw *hw,
  2827. struct i40e_filter_control_settings *settings)
  2828. {
  2829. i40e_status ret = 0;
  2830. u32 hash_lut_size = 0;
  2831. u32 val;
  2832. if (!settings)
  2833. return I40E_ERR_PARAM;
  2834. /* Validate the input settings */
  2835. ret = i40e_validate_filter_settings(hw, settings);
  2836. if (ret)
  2837. return ret;
  2838. /* Read the PF Queue Filter control register */
  2839. val = rd32(hw, I40E_PFQF_CTL_0);
  2840. /* Program required PE hash buckets for the PF */
  2841. val &= ~I40E_PFQF_CTL_0_PEHSIZE_MASK;
  2842. val |= ((u32)settings->pe_filt_num << I40E_PFQF_CTL_0_PEHSIZE_SHIFT) &
  2843. I40E_PFQF_CTL_0_PEHSIZE_MASK;
  2844. /* Program required PE contexts for the PF */
  2845. val &= ~I40E_PFQF_CTL_0_PEDSIZE_MASK;
  2846. val |= ((u32)settings->pe_cntx_num << I40E_PFQF_CTL_0_PEDSIZE_SHIFT) &
  2847. I40E_PFQF_CTL_0_PEDSIZE_MASK;
  2848. /* Program required FCoE hash buckets for the PF */
  2849. val &= ~I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
  2850. val |= ((u32)settings->fcoe_filt_num <<
  2851. I40E_PFQF_CTL_0_PFFCHSIZE_SHIFT) &
  2852. I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
  2853. /* Program required FCoE DDP contexts for the PF */
  2854. val &= ~I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
  2855. val |= ((u32)settings->fcoe_cntx_num <<
  2856. I40E_PFQF_CTL_0_PFFCDSIZE_SHIFT) &
  2857. I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
  2858. /* Program Hash LUT size for the PF */
  2859. val &= ~I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
  2860. if (settings->hash_lut_size == I40E_HASH_LUT_SIZE_512)
  2861. hash_lut_size = 1;
  2862. val |= (hash_lut_size << I40E_PFQF_CTL_0_HASHLUTSIZE_SHIFT) &
  2863. I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
  2864. /* Enable FDIR, Ethertype and MACVLAN filters for PF and VFs */
  2865. if (settings->enable_fdir)
  2866. val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
  2867. if (settings->enable_ethtype)
  2868. val |= I40E_PFQF_CTL_0_ETYPE_ENA_MASK;
  2869. if (settings->enable_macvlan)
  2870. val |= I40E_PFQF_CTL_0_MACVLAN_ENA_MASK;
  2871. wr32(hw, I40E_PFQF_CTL_0, val);
  2872. return 0;
  2873. }
  2874. /**
  2875. * i40e_aq_add_rem_control_packet_filter - Add or Remove Control Packet Filter
  2876. * @hw: pointer to the hw struct
  2877. * @mac_addr: MAC address to use in the filter
  2878. * @ethtype: Ethertype to use in the filter
  2879. * @flags: Flags that needs to be applied to the filter
  2880. * @vsi_seid: seid of the control VSI
  2881. * @queue: VSI queue number to send the packet to
  2882. * @is_add: Add control packet filter if True else remove
  2883. * @stats: Structure to hold information on control filter counts
  2884. * @cmd_details: pointer to command details structure or NULL
  2885. *
  2886. * This command will Add or Remove control packet filter for a control VSI.
  2887. * In return it will update the total number of perfect filter count in
  2888. * the stats member.
  2889. **/
  2890. i40e_status i40e_aq_add_rem_control_packet_filter(struct i40e_hw *hw,
  2891. u8 *mac_addr, u16 ethtype, u16 flags,
  2892. u16 vsi_seid, u16 queue, bool is_add,
  2893. struct i40e_control_filter_stats *stats,
  2894. struct i40e_asq_cmd_details *cmd_details)
  2895. {
  2896. struct i40e_aq_desc desc;
  2897. struct i40e_aqc_add_remove_control_packet_filter *cmd =
  2898. (struct i40e_aqc_add_remove_control_packet_filter *)
  2899. &desc.params.raw;
  2900. struct i40e_aqc_add_remove_control_packet_filter_completion *resp =
  2901. (struct i40e_aqc_add_remove_control_packet_filter_completion *)
  2902. &desc.params.raw;
  2903. i40e_status status;
  2904. if (vsi_seid == 0)
  2905. return I40E_ERR_PARAM;
  2906. if (is_add) {
  2907. i40e_fill_default_direct_cmd_desc(&desc,
  2908. i40e_aqc_opc_add_control_packet_filter);
  2909. cmd->queue = cpu_to_le16(queue);
  2910. } else {
  2911. i40e_fill_default_direct_cmd_desc(&desc,
  2912. i40e_aqc_opc_remove_control_packet_filter);
  2913. }
  2914. if (mac_addr)
  2915. memcpy(cmd->mac, mac_addr, ETH_ALEN);
  2916. cmd->etype = cpu_to_le16(ethtype);
  2917. cmd->flags = cpu_to_le16(flags);
  2918. cmd->seid = cpu_to_le16(vsi_seid);
  2919. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2920. if (!status && stats) {
  2921. stats->mac_etype_used = le16_to_cpu(resp->mac_etype_used);
  2922. stats->etype_used = le16_to_cpu(resp->etype_used);
  2923. stats->mac_etype_free = le16_to_cpu(resp->mac_etype_free);
  2924. stats->etype_free = le16_to_cpu(resp->etype_free);
  2925. }
  2926. return status;
  2927. }
  2928. /**
  2929. * i40e_aq_resume_port_tx
  2930. * @hw: pointer to the hardware structure
  2931. * @cmd_details: pointer to command details structure or NULL
  2932. *
  2933. * Resume port's Tx traffic
  2934. **/
  2935. i40e_status i40e_aq_resume_port_tx(struct i40e_hw *hw,
  2936. struct i40e_asq_cmd_details *cmd_details)
  2937. {
  2938. struct i40e_aq_desc desc;
  2939. i40e_status status;
  2940. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_resume_port_tx);
  2941. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  2942. return status;
  2943. }
  2944. /**
  2945. * i40e_set_pci_config_data - store PCI bus info
  2946. * @hw: pointer to hardware structure
  2947. * @link_status: the link status word from PCI config space
  2948. *
  2949. * Stores the PCI bus info (speed, width, type) within the i40e_hw structure
  2950. **/
  2951. void i40e_set_pci_config_data(struct i40e_hw *hw, u16 link_status)
  2952. {
  2953. hw->bus.type = i40e_bus_type_pci_express;
  2954. switch (link_status & PCI_EXP_LNKSTA_NLW) {
  2955. case PCI_EXP_LNKSTA_NLW_X1:
  2956. hw->bus.width = i40e_bus_width_pcie_x1;
  2957. break;
  2958. case PCI_EXP_LNKSTA_NLW_X2:
  2959. hw->bus.width = i40e_bus_width_pcie_x2;
  2960. break;
  2961. case PCI_EXP_LNKSTA_NLW_X4:
  2962. hw->bus.width = i40e_bus_width_pcie_x4;
  2963. break;
  2964. case PCI_EXP_LNKSTA_NLW_X8:
  2965. hw->bus.width = i40e_bus_width_pcie_x8;
  2966. break;
  2967. default:
  2968. hw->bus.width = i40e_bus_width_unknown;
  2969. break;
  2970. }
  2971. switch (link_status & PCI_EXP_LNKSTA_CLS) {
  2972. case PCI_EXP_LNKSTA_CLS_2_5GB:
  2973. hw->bus.speed = i40e_bus_speed_2500;
  2974. break;
  2975. case PCI_EXP_LNKSTA_CLS_5_0GB:
  2976. hw->bus.speed = i40e_bus_speed_5000;
  2977. break;
  2978. case PCI_EXP_LNKSTA_CLS_8_0GB:
  2979. hw->bus.speed = i40e_bus_speed_8000;
  2980. break;
  2981. default:
  2982. hw->bus.speed = i40e_bus_speed_unknown;
  2983. break;
  2984. }
  2985. }