i40e_common.c 106 KB

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