i40e_common.c 98 KB

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