i40e_common.c 96 KB

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