i40e_common.c 96 KB

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