ice_common.c 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright (c) 2018, Intel Corporation. */
  3. #include "ice_common.h"
  4. #include "ice_sched.h"
  5. #include "ice_adminq_cmd.h"
  6. #define ICE_PF_RESET_WAIT_COUNT 200
  7. #define ICE_PROG_FLEX_ENTRY(hw, rxdid, mdid, idx) \
  8. wr32((hw), GLFLXP_RXDID_FLX_WRD_##idx(rxdid), \
  9. ((ICE_RX_OPC_MDID << \
  10. GLFLXP_RXDID_FLX_WRD_##idx##_RXDID_OPCODE_S) & \
  11. GLFLXP_RXDID_FLX_WRD_##idx##_RXDID_OPCODE_M) | \
  12. (((mdid) << GLFLXP_RXDID_FLX_WRD_##idx##_PROT_MDID_S) & \
  13. GLFLXP_RXDID_FLX_WRD_##idx##_PROT_MDID_M))
  14. #define ICE_PROG_FLG_ENTRY(hw, rxdid, flg_0, flg_1, flg_2, flg_3, idx) \
  15. wr32((hw), GLFLXP_RXDID_FLAGS(rxdid, idx), \
  16. (((flg_0) << GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_S) & \
  17. GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_M) | \
  18. (((flg_1) << GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_1_S) & \
  19. GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_1_M) | \
  20. (((flg_2) << GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_2_S) & \
  21. GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_2_M) | \
  22. (((flg_3) << GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_3_S) & \
  23. GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_3_M))
  24. /**
  25. * ice_set_mac_type - Sets MAC type
  26. * @hw: pointer to the HW structure
  27. *
  28. * This function sets the MAC type of the adapter based on the
  29. * vendor ID and device ID stored in the hw structure.
  30. */
  31. static enum ice_status ice_set_mac_type(struct ice_hw *hw)
  32. {
  33. if (hw->vendor_id != PCI_VENDOR_ID_INTEL)
  34. return ICE_ERR_DEVICE_NOT_SUPPORTED;
  35. hw->mac_type = ICE_MAC_GENERIC;
  36. return 0;
  37. }
  38. /**
  39. * ice_dev_onetime_setup - Temporary HW/FW workarounds
  40. * @hw: pointer to the HW structure
  41. *
  42. * This function provides temporary workarounds for certain issues
  43. * that are expected to be fixed in the HW/FW.
  44. */
  45. void ice_dev_onetime_setup(struct ice_hw *hw)
  46. {
  47. /* configure Rx - set non pxe mode */
  48. wr32(hw, GLLAN_RCTL_0, 0x1);
  49. #define MBX_PF_VT_PFALLOC 0x00231E80
  50. /* set VFs per PF */
  51. wr32(hw, MBX_PF_VT_PFALLOC, rd32(hw, PF_VT_PFALLOC_HIF));
  52. }
  53. /**
  54. * ice_clear_pf_cfg - Clear PF configuration
  55. * @hw: pointer to the hardware structure
  56. *
  57. * Clears any existing PF configuration (VSIs, VSI lists, switch rules, port
  58. * configuration, flow director filters, etc.).
  59. */
  60. enum ice_status ice_clear_pf_cfg(struct ice_hw *hw)
  61. {
  62. struct ice_aq_desc desc;
  63. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_clear_pf_cfg);
  64. return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  65. }
  66. /**
  67. * ice_aq_manage_mac_read - manage MAC address read command
  68. * @hw: pointer to the hw struct
  69. * @buf: a virtual buffer to hold the manage MAC read response
  70. * @buf_size: Size of the virtual buffer
  71. * @cd: pointer to command details structure or NULL
  72. *
  73. * This function is used to return per PF station MAC address (0x0107).
  74. * NOTE: Upon successful completion of this command, MAC address information
  75. * is returned in user specified buffer. Please interpret user specified
  76. * buffer as "manage_mac_read" response.
  77. * Response such as various MAC addresses are stored in HW struct (port.mac)
  78. * ice_aq_discover_caps is expected to be called before this function is called.
  79. */
  80. static enum ice_status
  81. ice_aq_manage_mac_read(struct ice_hw *hw, void *buf, u16 buf_size,
  82. struct ice_sq_cd *cd)
  83. {
  84. struct ice_aqc_manage_mac_read_resp *resp;
  85. struct ice_aqc_manage_mac_read *cmd;
  86. struct ice_aq_desc desc;
  87. enum ice_status status;
  88. u16 flags;
  89. u8 i;
  90. cmd = &desc.params.mac_read;
  91. if (buf_size < sizeof(*resp))
  92. return ICE_ERR_BUF_TOO_SHORT;
  93. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_manage_mac_read);
  94. status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
  95. if (status)
  96. return status;
  97. resp = (struct ice_aqc_manage_mac_read_resp *)buf;
  98. flags = le16_to_cpu(cmd->flags) & ICE_AQC_MAN_MAC_READ_M;
  99. if (!(flags & ICE_AQC_MAN_MAC_LAN_ADDR_VALID)) {
  100. ice_debug(hw, ICE_DBG_LAN, "got invalid MAC address\n");
  101. return ICE_ERR_CFG;
  102. }
  103. /* A single port can report up to two (LAN and WoL) addresses */
  104. for (i = 0; i < cmd->num_addr; i++)
  105. if (resp[i].addr_type == ICE_AQC_MAN_MAC_ADDR_TYPE_LAN) {
  106. ether_addr_copy(hw->port_info->mac.lan_addr,
  107. resp[i].mac_addr);
  108. ether_addr_copy(hw->port_info->mac.perm_addr,
  109. resp[i].mac_addr);
  110. break;
  111. }
  112. return 0;
  113. }
  114. /**
  115. * ice_aq_get_phy_caps - returns PHY capabilities
  116. * @pi: port information structure
  117. * @qual_mods: report qualified modules
  118. * @report_mode: report mode capabilities
  119. * @pcaps: structure for PHY capabilities to be filled
  120. * @cd: pointer to command details structure or NULL
  121. *
  122. * Returns the various PHY capabilities supported on the Port (0x0600)
  123. */
  124. enum ice_status
  125. ice_aq_get_phy_caps(struct ice_port_info *pi, bool qual_mods, u8 report_mode,
  126. struct ice_aqc_get_phy_caps_data *pcaps,
  127. struct ice_sq_cd *cd)
  128. {
  129. struct ice_aqc_get_phy_caps *cmd;
  130. u16 pcaps_size = sizeof(*pcaps);
  131. struct ice_aq_desc desc;
  132. enum ice_status status;
  133. cmd = &desc.params.get_phy;
  134. if (!pcaps || (report_mode & ~ICE_AQC_REPORT_MODE_M) || !pi)
  135. return ICE_ERR_PARAM;
  136. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_phy_caps);
  137. if (qual_mods)
  138. cmd->param0 |= cpu_to_le16(ICE_AQC_GET_PHY_RQM);
  139. cmd->param0 |= cpu_to_le16(report_mode);
  140. status = ice_aq_send_cmd(pi->hw, &desc, pcaps, pcaps_size, cd);
  141. if (!status && report_mode == ICE_AQC_REPORT_TOPO_CAP)
  142. pi->phy.phy_type_low = le64_to_cpu(pcaps->phy_type_low);
  143. return status;
  144. }
  145. /**
  146. * ice_get_media_type - Gets media type
  147. * @pi: port information structure
  148. */
  149. static enum ice_media_type ice_get_media_type(struct ice_port_info *pi)
  150. {
  151. struct ice_link_status *hw_link_info;
  152. if (!pi)
  153. return ICE_MEDIA_UNKNOWN;
  154. hw_link_info = &pi->phy.link_info;
  155. if (hw_link_info->phy_type_low) {
  156. switch (hw_link_info->phy_type_low) {
  157. case ICE_PHY_TYPE_LOW_1000BASE_SX:
  158. case ICE_PHY_TYPE_LOW_1000BASE_LX:
  159. case ICE_PHY_TYPE_LOW_10GBASE_SR:
  160. case ICE_PHY_TYPE_LOW_10GBASE_LR:
  161. case ICE_PHY_TYPE_LOW_10G_SFI_C2C:
  162. case ICE_PHY_TYPE_LOW_25GBASE_SR:
  163. case ICE_PHY_TYPE_LOW_25GBASE_LR:
  164. case ICE_PHY_TYPE_LOW_25G_AUI_C2C:
  165. case ICE_PHY_TYPE_LOW_40GBASE_SR4:
  166. case ICE_PHY_TYPE_LOW_40GBASE_LR4:
  167. return ICE_MEDIA_FIBER;
  168. case ICE_PHY_TYPE_LOW_100BASE_TX:
  169. case ICE_PHY_TYPE_LOW_1000BASE_T:
  170. case ICE_PHY_TYPE_LOW_2500BASE_T:
  171. case ICE_PHY_TYPE_LOW_5GBASE_T:
  172. case ICE_PHY_TYPE_LOW_10GBASE_T:
  173. case ICE_PHY_TYPE_LOW_25GBASE_T:
  174. return ICE_MEDIA_BASET;
  175. case ICE_PHY_TYPE_LOW_10G_SFI_DA:
  176. case ICE_PHY_TYPE_LOW_25GBASE_CR:
  177. case ICE_PHY_TYPE_LOW_25GBASE_CR_S:
  178. case ICE_PHY_TYPE_LOW_25GBASE_CR1:
  179. case ICE_PHY_TYPE_LOW_40GBASE_CR4:
  180. return ICE_MEDIA_DA;
  181. case ICE_PHY_TYPE_LOW_1000BASE_KX:
  182. case ICE_PHY_TYPE_LOW_2500BASE_KX:
  183. case ICE_PHY_TYPE_LOW_2500BASE_X:
  184. case ICE_PHY_TYPE_LOW_5GBASE_KR:
  185. case ICE_PHY_TYPE_LOW_10GBASE_KR_CR1:
  186. case ICE_PHY_TYPE_LOW_25GBASE_KR:
  187. case ICE_PHY_TYPE_LOW_25GBASE_KR1:
  188. case ICE_PHY_TYPE_LOW_25GBASE_KR_S:
  189. case ICE_PHY_TYPE_LOW_40GBASE_KR4:
  190. return ICE_MEDIA_BACKPLANE;
  191. }
  192. }
  193. return ICE_MEDIA_UNKNOWN;
  194. }
  195. /**
  196. * ice_aq_get_link_info
  197. * @pi: port information structure
  198. * @ena_lse: enable/disable LinkStatusEvent reporting
  199. * @link: pointer to link status structure - optional
  200. * @cd: pointer to command details structure or NULL
  201. *
  202. * Get Link Status (0x607). Returns the link status of the adapter.
  203. */
  204. static enum ice_status
  205. ice_aq_get_link_info(struct ice_port_info *pi, bool ena_lse,
  206. struct ice_link_status *link, struct ice_sq_cd *cd)
  207. {
  208. struct ice_link_status *hw_link_info_old, *hw_link_info;
  209. struct ice_aqc_get_link_status_data link_data = { 0 };
  210. struct ice_aqc_get_link_status *resp;
  211. enum ice_media_type *hw_media_type;
  212. struct ice_fc_info *hw_fc_info;
  213. bool tx_pause, rx_pause;
  214. struct ice_aq_desc desc;
  215. enum ice_status status;
  216. u16 cmd_flags;
  217. if (!pi)
  218. return ICE_ERR_PARAM;
  219. hw_link_info_old = &pi->phy.link_info_old;
  220. hw_media_type = &pi->phy.media_type;
  221. hw_link_info = &pi->phy.link_info;
  222. hw_fc_info = &pi->fc;
  223. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_link_status);
  224. cmd_flags = (ena_lse) ? ICE_AQ_LSE_ENA : ICE_AQ_LSE_DIS;
  225. resp = &desc.params.get_link_status;
  226. resp->cmd_flags = cpu_to_le16(cmd_flags);
  227. resp->lport_num = pi->lport;
  228. status = ice_aq_send_cmd(pi->hw, &desc, &link_data, sizeof(link_data),
  229. cd);
  230. if (status)
  231. return status;
  232. /* save off old link status information */
  233. *hw_link_info_old = *hw_link_info;
  234. /* update current link status information */
  235. hw_link_info->link_speed = le16_to_cpu(link_data.link_speed);
  236. hw_link_info->phy_type_low = le64_to_cpu(link_data.phy_type_low);
  237. *hw_media_type = ice_get_media_type(pi);
  238. hw_link_info->link_info = link_data.link_info;
  239. hw_link_info->an_info = link_data.an_info;
  240. hw_link_info->ext_info = link_data.ext_info;
  241. hw_link_info->max_frame_size = le16_to_cpu(link_data.max_frame_size);
  242. hw_link_info->pacing = link_data.cfg & ICE_AQ_CFG_PACING_M;
  243. /* update fc info */
  244. tx_pause = !!(link_data.an_info & ICE_AQ_LINK_PAUSE_TX);
  245. rx_pause = !!(link_data.an_info & ICE_AQ_LINK_PAUSE_RX);
  246. if (tx_pause && rx_pause)
  247. hw_fc_info->current_mode = ICE_FC_FULL;
  248. else if (tx_pause)
  249. hw_fc_info->current_mode = ICE_FC_TX_PAUSE;
  250. else if (rx_pause)
  251. hw_fc_info->current_mode = ICE_FC_RX_PAUSE;
  252. else
  253. hw_fc_info->current_mode = ICE_FC_NONE;
  254. hw_link_info->lse_ena =
  255. !!(resp->cmd_flags & cpu_to_le16(ICE_AQ_LSE_IS_ENABLED));
  256. /* save link status information */
  257. if (link)
  258. *link = *hw_link_info;
  259. /* flag cleared so calling functions don't call AQ again */
  260. pi->phy.get_link_info = false;
  261. return status;
  262. }
  263. /**
  264. * ice_init_flex_flags
  265. * @hw: pointer to the hardware structure
  266. * @prof_id: Rx Descriptor Builder profile ID
  267. *
  268. * Function to initialize Rx flex flags
  269. */
  270. static void ice_init_flex_flags(struct ice_hw *hw, enum ice_rxdid prof_id)
  271. {
  272. u8 idx = 0;
  273. /* Flex-flag fields (0-2) are programmed with FLG64 bits with layout:
  274. * flexiflags0[5:0] - TCP flags, is_packet_fragmented, is_packet_UDP_GRE
  275. * flexiflags1[3:0] - Not used for flag programming
  276. * flexiflags2[7:0] - Tunnel and VLAN types
  277. * 2 invalid fields in last index
  278. */
  279. switch (prof_id) {
  280. /* Rx flex flags are currently programmed for the NIC profiles only.
  281. * Different flag bit programming configurations can be added per
  282. * profile as needed.
  283. */
  284. case ICE_RXDID_FLEX_NIC:
  285. case ICE_RXDID_FLEX_NIC_2:
  286. ICE_PROG_FLG_ENTRY(hw, prof_id, ICE_RXFLG_PKT_FRG,
  287. ICE_RXFLG_UDP_GRE, ICE_RXFLG_PKT_DSI,
  288. ICE_RXFLG_FIN, idx++);
  289. /* flex flag 1 is not used for flexi-flag programming, skipping
  290. * these four FLG64 bits.
  291. */
  292. ICE_PROG_FLG_ENTRY(hw, prof_id, ICE_RXFLG_SYN, ICE_RXFLG_RST,
  293. ICE_RXFLG_PKT_DSI, ICE_RXFLG_PKT_DSI, idx++);
  294. ICE_PROG_FLG_ENTRY(hw, prof_id, ICE_RXFLG_PKT_DSI,
  295. ICE_RXFLG_PKT_DSI, ICE_RXFLG_EVLAN_x8100,
  296. ICE_RXFLG_EVLAN_x9100, idx++);
  297. ICE_PROG_FLG_ENTRY(hw, prof_id, ICE_RXFLG_VLAN_x8100,
  298. ICE_RXFLG_TNL_VLAN, ICE_RXFLG_TNL_MAC,
  299. ICE_RXFLG_TNL0, idx++);
  300. ICE_PROG_FLG_ENTRY(hw, prof_id, ICE_RXFLG_TNL1, ICE_RXFLG_TNL2,
  301. ICE_RXFLG_PKT_DSI, ICE_RXFLG_PKT_DSI, idx);
  302. break;
  303. default:
  304. ice_debug(hw, ICE_DBG_INIT,
  305. "Flag programming for profile ID %d not supported\n",
  306. prof_id);
  307. }
  308. }
  309. /**
  310. * ice_init_flex_flds
  311. * @hw: pointer to the hardware structure
  312. * @prof_id: Rx Descriptor Builder profile ID
  313. *
  314. * Function to initialize flex descriptors
  315. */
  316. static void ice_init_flex_flds(struct ice_hw *hw, enum ice_rxdid prof_id)
  317. {
  318. enum ice_flex_rx_mdid mdid;
  319. switch (prof_id) {
  320. case ICE_RXDID_FLEX_NIC:
  321. case ICE_RXDID_FLEX_NIC_2:
  322. ICE_PROG_FLEX_ENTRY(hw, prof_id, ICE_RX_MDID_HASH_LOW, 0);
  323. ICE_PROG_FLEX_ENTRY(hw, prof_id, ICE_RX_MDID_HASH_HIGH, 1);
  324. ICE_PROG_FLEX_ENTRY(hw, prof_id, ICE_RX_MDID_FLOW_ID_LOWER, 2);
  325. mdid = (prof_id == ICE_RXDID_FLEX_NIC_2) ?
  326. ICE_RX_MDID_SRC_VSI : ICE_RX_MDID_FLOW_ID_HIGH;
  327. ICE_PROG_FLEX_ENTRY(hw, prof_id, mdid, 3);
  328. ice_init_flex_flags(hw, prof_id);
  329. break;
  330. default:
  331. ice_debug(hw, ICE_DBG_INIT,
  332. "Field init for profile ID %d not supported\n",
  333. prof_id);
  334. }
  335. }
  336. /**
  337. * ice_init_fltr_mgmt_struct - initializes filter management list and locks
  338. * @hw: pointer to the hw struct
  339. */
  340. static enum ice_status ice_init_fltr_mgmt_struct(struct ice_hw *hw)
  341. {
  342. struct ice_switch_info *sw;
  343. hw->switch_info = devm_kzalloc(ice_hw_to_dev(hw),
  344. sizeof(*hw->switch_info), GFP_KERNEL);
  345. sw = hw->switch_info;
  346. if (!sw)
  347. return ICE_ERR_NO_MEMORY;
  348. INIT_LIST_HEAD(&sw->vsi_list_map_head);
  349. ice_init_def_sw_recp(hw);
  350. return 0;
  351. }
  352. /**
  353. * ice_cleanup_fltr_mgmt_struct - cleanup filter management list and locks
  354. * @hw: pointer to the hw struct
  355. */
  356. static void ice_cleanup_fltr_mgmt_struct(struct ice_hw *hw)
  357. {
  358. struct ice_switch_info *sw = hw->switch_info;
  359. struct ice_vsi_list_map_info *v_pos_map;
  360. struct ice_vsi_list_map_info *v_tmp_map;
  361. struct ice_sw_recipe *recps;
  362. u8 i;
  363. list_for_each_entry_safe(v_pos_map, v_tmp_map, &sw->vsi_list_map_head,
  364. list_entry) {
  365. list_del(&v_pos_map->list_entry);
  366. devm_kfree(ice_hw_to_dev(hw), v_pos_map);
  367. }
  368. recps = hw->switch_info->recp_list;
  369. for (i = 0; i < ICE_SW_LKUP_LAST; i++) {
  370. struct ice_fltr_mgmt_list_entry *lst_itr, *tmp_entry;
  371. recps[i].root_rid = i;
  372. mutex_destroy(&recps[i].filt_rule_lock);
  373. list_for_each_entry_safe(lst_itr, tmp_entry,
  374. &recps[i].filt_rules, list_entry) {
  375. list_del(&lst_itr->list_entry);
  376. devm_kfree(ice_hw_to_dev(hw), lst_itr);
  377. }
  378. }
  379. ice_rm_all_sw_replay_rule_info(hw);
  380. devm_kfree(ice_hw_to_dev(hw), sw->recp_list);
  381. devm_kfree(ice_hw_to_dev(hw), sw);
  382. }
  383. #define ICE_FW_LOG_DESC_SIZE(n) (sizeof(struct ice_aqc_fw_logging_data) + \
  384. (((n) - 1) * sizeof(((struct ice_aqc_fw_logging_data *)0)->entry)))
  385. #define ICE_FW_LOG_DESC_SIZE_MAX \
  386. ICE_FW_LOG_DESC_SIZE(ICE_AQC_FW_LOG_ID_MAX)
  387. /**
  388. * ice_cfg_fw_log - configure FW logging
  389. * @hw: pointer to the hw struct
  390. * @enable: enable certain FW logging events if true, disable all if false
  391. *
  392. * This function enables/disables the FW logging via Rx CQ events and a UART
  393. * port based on predetermined configurations. FW logging via the Rx CQ can be
  394. * enabled/disabled for individual PF's. However, FW logging via the UART can
  395. * only be enabled/disabled for all PFs on the same device.
  396. *
  397. * To enable overall FW logging, the "cq_en" and "uart_en" enable bits in
  398. * hw->fw_log need to be set accordingly, e.g. based on user-provided input,
  399. * before initializing the device.
  400. *
  401. * When re/configuring FW logging, callers need to update the "cfg" elements of
  402. * the hw->fw_log.evnts array with the desired logging event configurations for
  403. * modules of interest. When disabling FW logging completely, the callers can
  404. * just pass false in the "enable" parameter. On completion, the function will
  405. * update the "cur" element of the hw->fw_log.evnts array with the resulting
  406. * logging event configurations of the modules that are being re/configured. FW
  407. * logging modules that are not part of a reconfiguration operation retain their
  408. * previous states.
  409. *
  410. * Before resetting the device, it is recommended that the driver disables FW
  411. * logging before shutting down the control queue. When disabling FW logging
  412. * ("enable" = false), the latest configurations of FW logging events stored in
  413. * hw->fw_log.evnts[] are not overridden to allow them to be reconfigured after
  414. * a device reset.
  415. *
  416. * When enabling FW logging to emit log messages via the Rx CQ during the
  417. * device's initialization phase, a mechanism alternative to interrupt handlers
  418. * needs to be used to extract FW log messages from the Rx CQ periodically and
  419. * to prevent the Rx CQ from being full and stalling other types of control
  420. * messages from FW to SW. Interrupts are typically disabled during the device's
  421. * initialization phase.
  422. */
  423. static enum ice_status ice_cfg_fw_log(struct ice_hw *hw, bool enable)
  424. {
  425. struct ice_aqc_fw_logging_data *data = NULL;
  426. struct ice_aqc_fw_logging *cmd;
  427. enum ice_status status = 0;
  428. u16 i, chgs = 0, len = 0;
  429. struct ice_aq_desc desc;
  430. u8 actv_evnts = 0;
  431. void *buf = NULL;
  432. if (!hw->fw_log.cq_en && !hw->fw_log.uart_en)
  433. return 0;
  434. /* Disable FW logging only when the control queue is still responsive */
  435. if (!enable &&
  436. (!hw->fw_log.actv_evnts || !ice_check_sq_alive(hw, &hw->adminq)))
  437. return 0;
  438. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_fw_logging);
  439. cmd = &desc.params.fw_logging;
  440. /* Indicate which controls are valid */
  441. if (hw->fw_log.cq_en)
  442. cmd->log_ctrl_valid |= ICE_AQC_FW_LOG_AQ_VALID;
  443. if (hw->fw_log.uart_en)
  444. cmd->log_ctrl_valid |= ICE_AQC_FW_LOG_UART_VALID;
  445. if (enable) {
  446. /* Fill in an array of entries with FW logging modules and
  447. * logging events being reconfigured.
  448. */
  449. for (i = 0; i < ICE_AQC_FW_LOG_ID_MAX; i++) {
  450. u16 val;
  451. /* Keep track of enabled event types */
  452. actv_evnts |= hw->fw_log.evnts[i].cfg;
  453. if (hw->fw_log.evnts[i].cfg == hw->fw_log.evnts[i].cur)
  454. continue;
  455. if (!data) {
  456. data = devm_kzalloc(ice_hw_to_dev(hw),
  457. ICE_FW_LOG_DESC_SIZE_MAX,
  458. GFP_KERNEL);
  459. if (!data)
  460. return ICE_ERR_NO_MEMORY;
  461. }
  462. val = i << ICE_AQC_FW_LOG_ID_S;
  463. val |= hw->fw_log.evnts[i].cfg << ICE_AQC_FW_LOG_EN_S;
  464. data->entry[chgs++] = cpu_to_le16(val);
  465. }
  466. /* Only enable FW logging if at least one module is specified.
  467. * If FW logging is currently enabled but all modules are not
  468. * enabled to emit log messages, disable FW logging altogether.
  469. */
  470. if (actv_evnts) {
  471. /* Leave if there is effectively no change */
  472. if (!chgs)
  473. goto out;
  474. if (hw->fw_log.cq_en)
  475. cmd->log_ctrl |= ICE_AQC_FW_LOG_AQ_EN;
  476. if (hw->fw_log.uart_en)
  477. cmd->log_ctrl |= ICE_AQC_FW_LOG_UART_EN;
  478. buf = data;
  479. len = ICE_FW_LOG_DESC_SIZE(chgs);
  480. desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
  481. }
  482. }
  483. status = ice_aq_send_cmd(hw, &desc, buf, len, NULL);
  484. if (!status) {
  485. /* Update the current configuration to reflect events enabled.
  486. * hw->fw_log.cq_en and hw->fw_log.uart_en indicate if the FW
  487. * logging mode is enabled for the device. They do not reflect
  488. * actual modules being enabled to emit log messages. So, their
  489. * values remain unchanged even when all modules are disabled.
  490. */
  491. u16 cnt = enable ? chgs : (u16)ICE_AQC_FW_LOG_ID_MAX;
  492. hw->fw_log.actv_evnts = actv_evnts;
  493. for (i = 0; i < cnt; i++) {
  494. u16 v, m;
  495. if (!enable) {
  496. /* When disabling all FW logging events as part
  497. * of device's de-initialization, the original
  498. * configurations are retained, and can be used
  499. * to reconfigure FW logging later if the device
  500. * is re-initialized.
  501. */
  502. hw->fw_log.evnts[i].cur = 0;
  503. continue;
  504. }
  505. v = le16_to_cpu(data->entry[i]);
  506. m = (v & ICE_AQC_FW_LOG_ID_M) >> ICE_AQC_FW_LOG_ID_S;
  507. hw->fw_log.evnts[m].cur = hw->fw_log.evnts[m].cfg;
  508. }
  509. }
  510. out:
  511. if (data)
  512. devm_kfree(ice_hw_to_dev(hw), data);
  513. return status;
  514. }
  515. /**
  516. * ice_output_fw_log
  517. * @hw: pointer to the hw struct
  518. * @desc: pointer to the AQ message descriptor
  519. * @buf: pointer to the buffer accompanying the AQ message
  520. *
  521. * Formats a FW Log message and outputs it via the standard driver logs.
  522. */
  523. void ice_output_fw_log(struct ice_hw *hw, struct ice_aq_desc *desc, void *buf)
  524. {
  525. ice_debug(hw, ICE_DBG_AQ_MSG, "[ FW Log Msg Start ]\n");
  526. ice_debug_array(hw, ICE_DBG_AQ_MSG, 16, 1, (u8 *)buf,
  527. le16_to_cpu(desc->datalen));
  528. ice_debug(hw, ICE_DBG_AQ_MSG, "[ FW Log Msg End ]\n");
  529. }
  530. /**
  531. * ice_get_itr_intrl_gran - determine int/intrl granularity
  532. * @hw: pointer to the hw struct
  533. *
  534. * Determines the itr/intrl granularities based on the maximum aggregate
  535. * bandwidth according to the device's configuration during power-on.
  536. */
  537. static enum ice_status ice_get_itr_intrl_gran(struct ice_hw *hw)
  538. {
  539. u8 max_agg_bw = (rd32(hw, GL_PWR_MODE_CTL) &
  540. GL_PWR_MODE_CTL_CAR_MAX_BW_M) >>
  541. GL_PWR_MODE_CTL_CAR_MAX_BW_S;
  542. switch (max_agg_bw) {
  543. case ICE_MAX_AGG_BW_200G:
  544. case ICE_MAX_AGG_BW_100G:
  545. case ICE_MAX_AGG_BW_50G:
  546. hw->itr_gran = ICE_ITR_GRAN_ABOVE_25;
  547. hw->intrl_gran = ICE_INTRL_GRAN_ABOVE_25;
  548. break;
  549. case ICE_MAX_AGG_BW_25G:
  550. hw->itr_gran = ICE_ITR_GRAN_MAX_25;
  551. hw->intrl_gran = ICE_INTRL_GRAN_MAX_25;
  552. break;
  553. default:
  554. ice_debug(hw, ICE_DBG_INIT,
  555. "Failed to determine itr/intrl granularity\n");
  556. return ICE_ERR_CFG;
  557. }
  558. return 0;
  559. }
  560. /**
  561. * ice_init_hw - main hardware initialization routine
  562. * @hw: pointer to the hardware structure
  563. */
  564. enum ice_status ice_init_hw(struct ice_hw *hw)
  565. {
  566. struct ice_aqc_get_phy_caps_data *pcaps;
  567. enum ice_status status;
  568. u16 mac_buf_len;
  569. void *mac_buf;
  570. /* Set MAC type based on DeviceID */
  571. status = ice_set_mac_type(hw);
  572. if (status)
  573. return status;
  574. hw->pf_id = (u8)(rd32(hw, PF_FUNC_RID) &
  575. PF_FUNC_RID_FUNC_NUM_M) >>
  576. PF_FUNC_RID_FUNC_NUM_S;
  577. status = ice_reset(hw, ICE_RESET_PFR);
  578. if (status)
  579. return status;
  580. status = ice_get_itr_intrl_gran(hw);
  581. if (status)
  582. return status;
  583. status = ice_init_all_ctrlq(hw);
  584. if (status)
  585. goto err_unroll_cqinit;
  586. /* Enable FW logging. Not fatal if this fails. */
  587. status = ice_cfg_fw_log(hw, true);
  588. if (status)
  589. ice_debug(hw, ICE_DBG_INIT, "Failed to enable FW logging.\n");
  590. status = ice_clear_pf_cfg(hw);
  591. if (status)
  592. goto err_unroll_cqinit;
  593. ice_clear_pxe_mode(hw);
  594. status = ice_init_nvm(hw);
  595. if (status)
  596. goto err_unroll_cqinit;
  597. status = ice_get_caps(hw);
  598. if (status)
  599. goto err_unroll_cqinit;
  600. hw->port_info = devm_kzalloc(ice_hw_to_dev(hw),
  601. sizeof(*hw->port_info), GFP_KERNEL);
  602. if (!hw->port_info) {
  603. status = ICE_ERR_NO_MEMORY;
  604. goto err_unroll_cqinit;
  605. }
  606. /* set the back pointer to hw */
  607. hw->port_info->hw = hw;
  608. /* Initialize port_info struct with switch configuration data */
  609. status = ice_get_initial_sw_cfg(hw);
  610. if (status)
  611. goto err_unroll_alloc;
  612. hw->evb_veb = true;
  613. /* Query the allocated resources for tx scheduler */
  614. status = ice_sched_query_res_alloc(hw);
  615. if (status) {
  616. ice_debug(hw, ICE_DBG_SCHED,
  617. "Failed to get scheduler allocated resources\n");
  618. goto err_unroll_alloc;
  619. }
  620. /* Initialize port_info struct with scheduler data */
  621. status = ice_sched_init_port(hw->port_info);
  622. if (status)
  623. goto err_unroll_sched;
  624. pcaps = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*pcaps), GFP_KERNEL);
  625. if (!pcaps) {
  626. status = ICE_ERR_NO_MEMORY;
  627. goto err_unroll_sched;
  628. }
  629. /* Initialize port_info struct with PHY capabilities */
  630. status = ice_aq_get_phy_caps(hw->port_info, false,
  631. ICE_AQC_REPORT_TOPO_CAP, pcaps, NULL);
  632. devm_kfree(ice_hw_to_dev(hw), pcaps);
  633. if (status)
  634. goto err_unroll_sched;
  635. /* Initialize port_info struct with link information */
  636. status = ice_aq_get_link_info(hw->port_info, false, NULL, NULL);
  637. if (status)
  638. goto err_unroll_sched;
  639. /* need a valid SW entry point to build a Tx tree */
  640. if (!hw->sw_entry_point_layer) {
  641. ice_debug(hw, ICE_DBG_SCHED, "invalid sw entry point\n");
  642. status = ICE_ERR_CFG;
  643. goto err_unroll_sched;
  644. }
  645. status = ice_init_fltr_mgmt_struct(hw);
  646. if (status)
  647. goto err_unroll_sched;
  648. ice_dev_onetime_setup(hw);
  649. /* Get MAC information */
  650. /* A single port can report up to two (LAN and WoL) addresses */
  651. mac_buf = devm_kcalloc(ice_hw_to_dev(hw), 2,
  652. sizeof(struct ice_aqc_manage_mac_read_resp),
  653. GFP_KERNEL);
  654. mac_buf_len = 2 * sizeof(struct ice_aqc_manage_mac_read_resp);
  655. if (!mac_buf) {
  656. status = ICE_ERR_NO_MEMORY;
  657. goto err_unroll_fltr_mgmt_struct;
  658. }
  659. status = ice_aq_manage_mac_read(hw, mac_buf, mac_buf_len, NULL);
  660. devm_kfree(ice_hw_to_dev(hw), mac_buf);
  661. if (status)
  662. goto err_unroll_fltr_mgmt_struct;
  663. ice_init_flex_flds(hw, ICE_RXDID_FLEX_NIC);
  664. ice_init_flex_flds(hw, ICE_RXDID_FLEX_NIC_2);
  665. return 0;
  666. err_unroll_fltr_mgmt_struct:
  667. ice_cleanup_fltr_mgmt_struct(hw);
  668. err_unroll_sched:
  669. ice_sched_cleanup_all(hw);
  670. err_unroll_alloc:
  671. devm_kfree(ice_hw_to_dev(hw), hw->port_info);
  672. err_unroll_cqinit:
  673. ice_shutdown_all_ctrlq(hw);
  674. return status;
  675. }
  676. /**
  677. * ice_deinit_hw - unroll initialization operations done by ice_init_hw
  678. * @hw: pointer to the hardware structure
  679. */
  680. void ice_deinit_hw(struct ice_hw *hw)
  681. {
  682. ice_cleanup_fltr_mgmt_struct(hw);
  683. ice_sched_cleanup_all(hw);
  684. if (hw->port_info) {
  685. devm_kfree(ice_hw_to_dev(hw), hw->port_info);
  686. hw->port_info = NULL;
  687. }
  688. /* Attempt to disable FW logging before shutting down control queues */
  689. ice_cfg_fw_log(hw, false);
  690. ice_shutdown_all_ctrlq(hw);
  691. /* Clear VSI contexts if not already cleared */
  692. ice_clear_all_vsi_ctx(hw);
  693. }
  694. /**
  695. * ice_check_reset - Check to see if a global reset is complete
  696. * @hw: pointer to the hardware structure
  697. */
  698. enum ice_status ice_check_reset(struct ice_hw *hw)
  699. {
  700. u32 cnt, reg = 0, grst_delay;
  701. /* Poll for Device Active state in case a recent CORER, GLOBR,
  702. * or EMPR has occurred. The grst delay value is in 100ms units.
  703. * Add 1sec for outstanding AQ commands that can take a long time.
  704. */
  705. grst_delay = ((rd32(hw, GLGEN_RSTCTL) & GLGEN_RSTCTL_GRSTDEL_M) >>
  706. GLGEN_RSTCTL_GRSTDEL_S) + 10;
  707. for (cnt = 0; cnt < grst_delay; cnt++) {
  708. mdelay(100);
  709. reg = rd32(hw, GLGEN_RSTAT);
  710. if (!(reg & GLGEN_RSTAT_DEVSTATE_M))
  711. break;
  712. }
  713. if (cnt == grst_delay) {
  714. ice_debug(hw, ICE_DBG_INIT,
  715. "Global reset polling failed to complete.\n");
  716. return ICE_ERR_RESET_FAILED;
  717. }
  718. #define ICE_RESET_DONE_MASK (GLNVM_ULD_CORER_DONE_M | \
  719. GLNVM_ULD_GLOBR_DONE_M)
  720. /* Device is Active; check Global Reset processes are done */
  721. for (cnt = 0; cnt < ICE_PF_RESET_WAIT_COUNT; cnt++) {
  722. reg = rd32(hw, GLNVM_ULD) & ICE_RESET_DONE_MASK;
  723. if (reg == ICE_RESET_DONE_MASK) {
  724. ice_debug(hw, ICE_DBG_INIT,
  725. "Global reset processes done. %d\n", cnt);
  726. break;
  727. }
  728. mdelay(10);
  729. }
  730. if (cnt == ICE_PF_RESET_WAIT_COUNT) {
  731. ice_debug(hw, ICE_DBG_INIT,
  732. "Wait for Reset Done timed out. GLNVM_ULD = 0x%x\n",
  733. reg);
  734. return ICE_ERR_RESET_FAILED;
  735. }
  736. return 0;
  737. }
  738. /**
  739. * ice_pf_reset - Reset the PF
  740. * @hw: pointer to the hardware structure
  741. *
  742. * If a global reset has been triggered, this function checks
  743. * for its completion and then issues the PF reset
  744. */
  745. static enum ice_status ice_pf_reset(struct ice_hw *hw)
  746. {
  747. u32 cnt, reg;
  748. /* If at function entry a global reset was already in progress, i.e.
  749. * state is not 'device active' or any of the reset done bits are not
  750. * set in GLNVM_ULD, there is no need for a PF Reset; poll until the
  751. * global reset is done.
  752. */
  753. if ((rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_DEVSTATE_M) ||
  754. (rd32(hw, GLNVM_ULD) & ICE_RESET_DONE_MASK) ^ ICE_RESET_DONE_MASK) {
  755. /* poll on global reset currently in progress until done */
  756. if (ice_check_reset(hw))
  757. return ICE_ERR_RESET_FAILED;
  758. return 0;
  759. }
  760. /* Reset the PF */
  761. reg = rd32(hw, PFGEN_CTRL);
  762. wr32(hw, PFGEN_CTRL, (reg | PFGEN_CTRL_PFSWR_M));
  763. for (cnt = 0; cnt < ICE_PF_RESET_WAIT_COUNT; cnt++) {
  764. reg = rd32(hw, PFGEN_CTRL);
  765. if (!(reg & PFGEN_CTRL_PFSWR_M))
  766. break;
  767. mdelay(1);
  768. }
  769. if (cnt == ICE_PF_RESET_WAIT_COUNT) {
  770. ice_debug(hw, ICE_DBG_INIT,
  771. "PF reset polling failed to complete.\n");
  772. return ICE_ERR_RESET_FAILED;
  773. }
  774. return 0;
  775. }
  776. /**
  777. * ice_reset - Perform different types of reset
  778. * @hw: pointer to the hardware structure
  779. * @req: reset request
  780. *
  781. * This function triggers a reset as specified by the req parameter.
  782. *
  783. * Note:
  784. * If anything other than a PF reset is triggered, PXE mode is restored.
  785. * This has to be cleared using ice_clear_pxe_mode again, once the AQ
  786. * interface has been restored in the rebuild flow.
  787. */
  788. enum ice_status ice_reset(struct ice_hw *hw, enum ice_reset_req req)
  789. {
  790. u32 val = 0;
  791. switch (req) {
  792. case ICE_RESET_PFR:
  793. return ice_pf_reset(hw);
  794. case ICE_RESET_CORER:
  795. ice_debug(hw, ICE_DBG_INIT, "CoreR requested\n");
  796. val = GLGEN_RTRIG_CORER_M;
  797. break;
  798. case ICE_RESET_GLOBR:
  799. ice_debug(hw, ICE_DBG_INIT, "GlobalR requested\n");
  800. val = GLGEN_RTRIG_GLOBR_M;
  801. break;
  802. default:
  803. return ICE_ERR_PARAM;
  804. }
  805. val |= rd32(hw, GLGEN_RTRIG);
  806. wr32(hw, GLGEN_RTRIG, val);
  807. ice_flush(hw);
  808. /* wait for the FW to be ready */
  809. return ice_check_reset(hw);
  810. }
  811. /**
  812. * ice_copy_rxq_ctx_to_hw
  813. * @hw: pointer to the hardware structure
  814. * @ice_rxq_ctx: pointer to the rxq context
  815. * @rxq_index: the index of the rx queue
  816. *
  817. * Copies rxq context from dense structure to hw register space
  818. */
  819. static enum ice_status
  820. ice_copy_rxq_ctx_to_hw(struct ice_hw *hw, u8 *ice_rxq_ctx, u32 rxq_index)
  821. {
  822. u8 i;
  823. if (!ice_rxq_ctx)
  824. return ICE_ERR_BAD_PTR;
  825. if (rxq_index > QRX_CTRL_MAX_INDEX)
  826. return ICE_ERR_PARAM;
  827. /* Copy each dword separately to hw */
  828. for (i = 0; i < ICE_RXQ_CTX_SIZE_DWORDS; i++) {
  829. wr32(hw, QRX_CONTEXT(i, rxq_index),
  830. *((u32 *)(ice_rxq_ctx + (i * sizeof(u32)))));
  831. ice_debug(hw, ICE_DBG_QCTX, "qrxdata[%d]: %08X\n", i,
  832. *((u32 *)(ice_rxq_ctx + (i * sizeof(u32)))));
  833. }
  834. return 0;
  835. }
  836. /* LAN Rx Queue Context */
  837. static const struct ice_ctx_ele ice_rlan_ctx_info[] = {
  838. /* Field Width LSB */
  839. ICE_CTX_STORE(ice_rlan_ctx, head, 13, 0),
  840. ICE_CTX_STORE(ice_rlan_ctx, cpuid, 8, 13),
  841. ICE_CTX_STORE(ice_rlan_ctx, base, 57, 32),
  842. ICE_CTX_STORE(ice_rlan_ctx, qlen, 13, 89),
  843. ICE_CTX_STORE(ice_rlan_ctx, dbuf, 7, 102),
  844. ICE_CTX_STORE(ice_rlan_ctx, hbuf, 5, 109),
  845. ICE_CTX_STORE(ice_rlan_ctx, dtype, 2, 114),
  846. ICE_CTX_STORE(ice_rlan_ctx, dsize, 1, 116),
  847. ICE_CTX_STORE(ice_rlan_ctx, crcstrip, 1, 117),
  848. ICE_CTX_STORE(ice_rlan_ctx, l2tsel, 1, 119),
  849. ICE_CTX_STORE(ice_rlan_ctx, hsplit_0, 4, 120),
  850. ICE_CTX_STORE(ice_rlan_ctx, hsplit_1, 2, 124),
  851. ICE_CTX_STORE(ice_rlan_ctx, showiv, 1, 127),
  852. ICE_CTX_STORE(ice_rlan_ctx, rxmax, 14, 174),
  853. ICE_CTX_STORE(ice_rlan_ctx, tphrdesc_ena, 1, 193),
  854. ICE_CTX_STORE(ice_rlan_ctx, tphwdesc_ena, 1, 194),
  855. ICE_CTX_STORE(ice_rlan_ctx, tphdata_ena, 1, 195),
  856. ICE_CTX_STORE(ice_rlan_ctx, tphhead_ena, 1, 196),
  857. ICE_CTX_STORE(ice_rlan_ctx, lrxqthresh, 3, 198),
  858. { 0 }
  859. };
  860. /**
  861. * ice_write_rxq_ctx
  862. * @hw: pointer to the hardware structure
  863. * @rlan_ctx: pointer to the rxq context
  864. * @rxq_index: the index of the rx queue
  865. *
  866. * Converts rxq context from sparse to dense structure and then writes
  867. * it to hw register space
  868. */
  869. enum ice_status
  870. ice_write_rxq_ctx(struct ice_hw *hw, struct ice_rlan_ctx *rlan_ctx,
  871. u32 rxq_index)
  872. {
  873. u8 ctx_buf[ICE_RXQ_CTX_SZ] = { 0 };
  874. ice_set_ctx((u8 *)rlan_ctx, ctx_buf, ice_rlan_ctx_info);
  875. return ice_copy_rxq_ctx_to_hw(hw, ctx_buf, rxq_index);
  876. }
  877. /* LAN Tx Queue Context */
  878. const struct ice_ctx_ele ice_tlan_ctx_info[] = {
  879. /* Field Width LSB */
  880. ICE_CTX_STORE(ice_tlan_ctx, base, 57, 0),
  881. ICE_CTX_STORE(ice_tlan_ctx, port_num, 3, 57),
  882. ICE_CTX_STORE(ice_tlan_ctx, cgd_num, 5, 60),
  883. ICE_CTX_STORE(ice_tlan_ctx, pf_num, 3, 65),
  884. ICE_CTX_STORE(ice_tlan_ctx, vmvf_num, 10, 68),
  885. ICE_CTX_STORE(ice_tlan_ctx, vmvf_type, 2, 78),
  886. ICE_CTX_STORE(ice_tlan_ctx, src_vsi, 10, 80),
  887. ICE_CTX_STORE(ice_tlan_ctx, tsyn_ena, 1, 90),
  888. ICE_CTX_STORE(ice_tlan_ctx, alt_vlan, 1, 92),
  889. ICE_CTX_STORE(ice_tlan_ctx, cpuid, 8, 93),
  890. ICE_CTX_STORE(ice_tlan_ctx, wb_mode, 1, 101),
  891. ICE_CTX_STORE(ice_tlan_ctx, tphrd_desc, 1, 102),
  892. ICE_CTX_STORE(ice_tlan_ctx, tphrd, 1, 103),
  893. ICE_CTX_STORE(ice_tlan_ctx, tphwr_desc, 1, 104),
  894. ICE_CTX_STORE(ice_tlan_ctx, cmpq_id, 9, 105),
  895. ICE_CTX_STORE(ice_tlan_ctx, qnum_in_func, 14, 114),
  896. ICE_CTX_STORE(ice_tlan_ctx, itr_notification_mode, 1, 128),
  897. ICE_CTX_STORE(ice_tlan_ctx, adjust_prof_id, 6, 129),
  898. ICE_CTX_STORE(ice_tlan_ctx, qlen, 13, 135),
  899. ICE_CTX_STORE(ice_tlan_ctx, quanta_prof_idx, 4, 148),
  900. ICE_CTX_STORE(ice_tlan_ctx, tso_ena, 1, 152),
  901. ICE_CTX_STORE(ice_tlan_ctx, tso_qnum, 11, 153),
  902. ICE_CTX_STORE(ice_tlan_ctx, legacy_int, 1, 164),
  903. ICE_CTX_STORE(ice_tlan_ctx, drop_ena, 1, 165),
  904. ICE_CTX_STORE(ice_tlan_ctx, cache_prof_idx, 2, 166),
  905. ICE_CTX_STORE(ice_tlan_ctx, pkt_shaper_prof_idx, 3, 168),
  906. ICE_CTX_STORE(ice_tlan_ctx, int_q_state, 110, 171),
  907. { 0 }
  908. };
  909. /**
  910. * ice_debug_cq
  911. * @hw: pointer to the hardware structure
  912. * @mask: debug mask
  913. * @desc: pointer to control queue descriptor
  914. * @buf: pointer to command buffer
  915. * @buf_len: max length of buf
  916. *
  917. * Dumps debug log about control command with descriptor contents.
  918. */
  919. void ice_debug_cq(struct ice_hw *hw, u32 __maybe_unused mask, void *desc,
  920. void *buf, u16 buf_len)
  921. {
  922. struct ice_aq_desc *cq_desc = (struct ice_aq_desc *)desc;
  923. u16 len;
  924. #ifndef CONFIG_DYNAMIC_DEBUG
  925. if (!(mask & hw->debug_mask))
  926. return;
  927. #endif
  928. if (!desc)
  929. return;
  930. len = le16_to_cpu(cq_desc->datalen);
  931. ice_debug(hw, mask,
  932. "CQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
  933. le16_to_cpu(cq_desc->opcode),
  934. le16_to_cpu(cq_desc->flags),
  935. le16_to_cpu(cq_desc->datalen), le16_to_cpu(cq_desc->retval));
  936. ice_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
  937. le32_to_cpu(cq_desc->cookie_high),
  938. le32_to_cpu(cq_desc->cookie_low));
  939. ice_debug(hw, mask, "\tparam (0,1) 0x%08X 0x%08X\n",
  940. le32_to_cpu(cq_desc->params.generic.param0),
  941. le32_to_cpu(cq_desc->params.generic.param1));
  942. ice_debug(hw, mask, "\taddr (h,l) 0x%08X 0x%08X\n",
  943. le32_to_cpu(cq_desc->params.generic.addr_high),
  944. le32_to_cpu(cq_desc->params.generic.addr_low));
  945. if (buf && cq_desc->datalen != 0) {
  946. ice_debug(hw, mask, "Buffer:\n");
  947. if (buf_len < len)
  948. len = buf_len;
  949. ice_debug_array(hw, mask, 16, 1, (u8 *)buf, len);
  950. }
  951. }
  952. /* FW Admin Queue command wrappers */
  953. /**
  954. * ice_aq_send_cmd - send FW Admin Queue command to FW Admin Queue
  955. * @hw: pointer to the hw struct
  956. * @desc: descriptor describing the command
  957. * @buf: buffer to use for indirect commands (NULL for direct commands)
  958. * @buf_size: size of buffer for indirect commands (0 for direct commands)
  959. * @cd: pointer to command details structure
  960. *
  961. * Helper function to send FW Admin Queue commands to the FW Admin Queue.
  962. */
  963. enum ice_status
  964. ice_aq_send_cmd(struct ice_hw *hw, struct ice_aq_desc *desc, void *buf,
  965. u16 buf_size, struct ice_sq_cd *cd)
  966. {
  967. return ice_sq_send_cmd(hw, &hw->adminq, desc, buf, buf_size, cd);
  968. }
  969. /**
  970. * ice_aq_get_fw_ver
  971. * @hw: pointer to the hw struct
  972. * @cd: pointer to command details structure or NULL
  973. *
  974. * Get the firmware version (0x0001) from the admin queue commands
  975. */
  976. enum ice_status ice_aq_get_fw_ver(struct ice_hw *hw, struct ice_sq_cd *cd)
  977. {
  978. struct ice_aqc_get_ver *resp;
  979. struct ice_aq_desc desc;
  980. enum ice_status status;
  981. resp = &desc.params.get_ver;
  982. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_ver);
  983. status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
  984. if (!status) {
  985. hw->fw_branch = resp->fw_branch;
  986. hw->fw_maj_ver = resp->fw_major;
  987. hw->fw_min_ver = resp->fw_minor;
  988. hw->fw_patch = resp->fw_patch;
  989. hw->fw_build = le32_to_cpu(resp->fw_build);
  990. hw->api_branch = resp->api_branch;
  991. hw->api_maj_ver = resp->api_major;
  992. hw->api_min_ver = resp->api_minor;
  993. hw->api_patch = resp->api_patch;
  994. }
  995. return status;
  996. }
  997. /**
  998. * ice_aq_q_shutdown
  999. * @hw: pointer to the hw struct
  1000. * @unloading: is the driver unloading itself
  1001. *
  1002. * Tell the Firmware that we're shutting down the AdminQ and whether
  1003. * or not the driver is unloading as well (0x0003).
  1004. */
  1005. enum ice_status ice_aq_q_shutdown(struct ice_hw *hw, bool unloading)
  1006. {
  1007. struct ice_aqc_q_shutdown *cmd;
  1008. struct ice_aq_desc desc;
  1009. cmd = &desc.params.q_shutdown;
  1010. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_q_shutdown);
  1011. if (unloading)
  1012. cmd->driver_unloading = cpu_to_le32(ICE_AQC_DRIVER_UNLOADING);
  1013. return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  1014. }
  1015. /**
  1016. * ice_aq_req_res
  1017. * @hw: pointer to the hw struct
  1018. * @res: resource id
  1019. * @access: access type
  1020. * @sdp_number: resource number
  1021. * @timeout: the maximum time in ms that the driver may hold the resource
  1022. * @cd: pointer to command details structure or NULL
  1023. *
  1024. * Requests common resource using the admin queue commands (0x0008).
  1025. * When attempting to acquire the Global Config Lock, the driver can
  1026. * learn of three states:
  1027. * 1) ICE_SUCCESS - acquired lock, and can perform download package
  1028. * 2) ICE_ERR_AQ_ERROR - did not get lock, driver should fail to load
  1029. * 3) ICE_ERR_AQ_NO_WORK - did not get lock, but another driver has
  1030. * successfully downloaded the package; the driver does
  1031. * not have to download the package and can continue
  1032. * loading
  1033. *
  1034. * Note that if the caller is in an acquire lock, perform action, release lock
  1035. * phase of operation, it is possible that the FW may detect a timeout and issue
  1036. * a CORER. In this case, the driver will receive a CORER interrupt and will
  1037. * have to determine its cause. The calling thread that is handling this flow
  1038. * will likely get an error propagated back to it indicating the Download
  1039. * Package, Update Package or the Release Resource AQ commands timed out.
  1040. */
  1041. static enum ice_status
  1042. ice_aq_req_res(struct ice_hw *hw, enum ice_aq_res_ids res,
  1043. enum ice_aq_res_access_type access, u8 sdp_number, u32 *timeout,
  1044. struct ice_sq_cd *cd)
  1045. {
  1046. struct ice_aqc_req_res *cmd_resp;
  1047. struct ice_aq_desc desc;
  1048. enum ice_status status;
  1049. cmd_resp = &desc.params.res_owner;
  1050. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_req_res);
  1051. cmd_resp->res_id = cpu_to_le16(res);
  1052. cmd_resp->access_type = cpu_to_le16(access);
  1053. cmd_resp->res_number = cpu_to_le32(sdp_number);
  1054. cmd_resp->timeout = cpu_to_le32(*timeout);
  1055. *timeout = 0;
  1056. status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
  1057. /* The completion specifies the maximum time in ms that the driver
  1058. * may hold the resource in the Timeout field.
  1059. */
  1060. /* Global config lock response utilizes an additional status field.
  1061. *
  1062. * If the Global config lock resource is held by some other driver, the
  1063. * command completes with ICE_AQ_RES_GLBL_IN_PROG in the status field
  1064. * and the timeout field indicates the maximum time the current owner
  1065. * of the resource has to free it.
  1066. */
  1067. if (res == ICE_GLOBAL_CFG_LOCK_RES_ID) {
  1068. if (le16_to_cpu(cmd_resp->status) == ICE_AQ_RES_GLBL_SUCCESS) {
  1069. *timeout = le32_to_cpu(cmd_resp->timeout);
  1070. return 0;
  1071. } else if (le16_to_cpu(cmd_resp->status) ==
  1072. ICE_AQ_RES_GLBL_IN_PROG) {
  1073. *timeout = le32_to_cpu(cmd_resp->timeout);
  1074. return ICE_ERR_AQ_ERROR;
  1075. } else if (le16_to_cpu(cmd_resp->status) ==
  1076. ICE_AQ_RES_GLBL_DONE) {
  1077. return ICE_ERR_AQ_NO_WORK;
  1078. }
  1079. /* invalid FW response, force a timeout immediately */
  1080. *timeout = 0;
  1081. return ICE_ERR_AQ_ERROR;
  1082. }
  1083. /* If the resource is held by some other driver, the command completes
  1084. * with a busy return value and the timeout field indicates the maximum
  1085. * time the current owner of the resource has to free it.
  1086. */
  1087. if (!status || hw->adminq.sq_last_status == ICE_AQ_RC_EBUSY)
  1088. *timeout = le32_to_cpu(cmd_resp->timeout);
  1089. return status;
  1090. }
  1091. /**
  1092. * ice_aq_release_res
  1093. * @hw: pointer to the hw struct
  1094. * @res: resource id
  1095. * @sdp_number: resource number
  1096. * @cd: pointer to command details structure or NULL
  1097. *
  1098. * release common resource using the admin queue commands (0x0009)
  1099. */
  1100. static enum ice_status
  1101. ice_aq_release_res(struct ice_hw *hw, enum ice_aq_res_ids res, u8 sdp_number,
  1102. struct ice_sq_cd *cd)
  1103. {
  1104. struct ice_aqc_req_res *cmd;
  1105. struct ice_aq_desc desc;
  1106. cmd = &desc.params.res_owner;
  1107. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_release_res);
  1108. cmd->res_id = cpu_to_le16(res);
  1109. cmd->res_number = cpu_to_le32(sdp_number);
  1110. return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
  1111. }
  1112. /**
  1113. * ice_acquire_res
  1114. * @hw: pointer to the HW structure
  1115. * @res: resource id
  1116. * @access: access type (read or write)
  1117. * @timeout: timeout in milliseconds
  1118. *
  1119. * This function will attempt to acquire the ownership of a resource.
  1120. */
  1121. enum ice_status
  1122. ice_acquire_res(struct ice_hw *hw, enum ice_aq_res_ids res,
  1123. enum ice_aq_res_access_type access, u32 timeout)
  1124. {
  1125. #define ICE_RES_POLLING_DELAY_MS 10
  1126. u32 delay = ICE_RES_POLLING_DELAY_MS;
  1127. u32 time_left = timeout;
  1128. enum ice_status status;
  1129. status = ice_aq_req_res(hw, res, access, 0, &time_left, NULL);
  1130. /* A return code of ICE_ERR_AQ_NO_WORK means that another driver has
  1131. * previously acquired the resource and performed any necessary updates;
  1132. * in this case the caller does not obtain the resource and has no
  1133. * further work to do.
  1134. */
  1135. if (status == ICE_ERR_AQ_NO_WORK)
  1136. goto ice_acquire_res_exit;
  1137. if (status)
  1138. ice_debug(hw, ICE_DBG_RES,
  1139. "resource %d acquire type %d failed.\n", res, access);
  1140. /* If necessary, poll until the current lock owner timeouts */
  1141. timeout = time_left;
  1142. while (status && timeout && time_left) {
  1143. mdelay(delay);
  1144. timeout = (timeout > delay) ? timeout - delay : 0;
  1145. status = ice_aq_req_res(hw, res, access, 0, &time_left, NULL);
  1146. if (status == ICE_ERR_AQ_NO_WORK)
  1147. /* lock free, but no work to do */
  1148. break;
  1149. if (!status)
  1150. /* lock acquired */
  1151. break;
  1152. }
  1153. if (status && status != ICE_ERR_AQ_NO_WORK)
  1154. ice_debug(hw, ICE_DBG_RES, "resource acquire timed out.\n");
  1155. ice_acquire_res_exit:
  1156. if (status == ICE_ERR_AQ_NO_WORK) {
  1157. if (access == ICE_RES_WRITE)
  1158. ice_debug(hw, ICE_DBG_RES,
  1159. "resource indicates no work to do.\n");
  1160. else
  1161. ice_debug(hw, ICE_DBG_RES,
  1162. "Warning: ICE_ERR_AQ_NO_WORK not expected\n");
  1163. }
  1164. return status;
  1165. }
  1166. /**
  1167. * ice_release_res
  1168. * @hw: pointer to the HW structure
  1169. * @res: resource id
  1170. *
  1171. * This function will release a resource using the proper Admin Command.
  1172. */
  1173. void ice_release_res(struct ice_hw *hw, enum ice_aq_res_ids res)
  1174. {
  1175. enum ice_status status;
  1176. u32 total_delay = 0;
  1177. status = ice_aq_release_res(hw, res, 0, NULL);
  1178. /* there are some rare cases when trying to release the resource
  1179. * results in an admin Q timeout, so handle them correctly
  1180. */
  1181. while ((status == ICE_ERR_AQ_TIMEOUT) &&
  1182. (total_delay < hw->adminq.sq_cmd_timeout)) {
  1183. mdelay(1);
  1184. status = ice_aq_release_res(hw, res, 0, NULL);
  1185. total_delay++;
  1186. }
  1187. }
  1188. /**
  1189. * ice_parse_caps - parse function/device capabilities
  1190. * @hw: pointer to the hw struct
  1191. * @buf: pointer to a buffer containing function/device capability records
  1192. * @cap_count: number of capability records in the list
  1193. * @opc: type of capabilities list to parse
  1194. *
  1195. * Helper function to parse function(0x000a)/device(0x000b) capabilities list.
  1196. */
  1197. static void
  1198. ice_parse_caps(struct ice_hw *hw, void *buf, u32 cap_count,
  1199. enum ice_adminq_opc opc)
  1200. {
  1201. struct ice_aqc_list_caps_elem *cap_resp;
  1202. struct ice_hw_func_caps *func_p = NULL;
  1203. struct ice_hw_dev_caps *dev_p = NULL;
  1204. struct ice_hw_common_caps *caps;
  1205. u32 i;
  1206. if (!buf)
  1207. return;
  1208. cap_resp = (struct ice_aqc_list_caps_elem *)buf;
  1209. if (opc == ice_aqc_opc_list_dev_caps) {
  1210. dev_p = &hw->dev_caps;
  1211. caps = &dev_p->common_cap;
  1212. } else if (opc == ice_aqc_opc_list_func_caps) {
  1213. func_p = &hw->func_caps;
  1214. caps = &func_p->common_cap;
  1215. } else {
  1216. ice_debug(hw, ICE_DBG_INIT, "wrong opcode\n");
  1217. return;
  1218. }
  1219. for (i = 0; caps && i < cap_count; i++, cap_resp++) {
  1220. u32 logical_id = le32_to_cpu(cap_resp->logical_id);
  1221. u32 phys_id = le32_to_cpu(cap_resp->phys_id);
  1222. u32 number = le32_to_cpu(cap_resp->number);
  1223. u16 cap = le16_to_cpu(cap_resp->cap);
  1224. switch (cap) {
  1225. case ICE_AQC_CAPS_SRIOV:
  1226. caps->sr_iov_1_1 = (number == 1);
  1227. ice_debug(hw, ICE_DBG_INIT,
  1228. "HW caps: SR-IOV = %d\n", caps->sr_iov_1_1);
  1229. break;
  1230. case ICE_AQC_CAPS_VF:
  1231. if (dev_p) {
  1232. dev_p->num_vfs_exposed = number;
  1233. ice_debug(hw, ICE_DBG_INIT,
  1234. "HW caps: VFs exposed = %d\n",
  1235. dev_p->num_vfs_exposed);
  1236. } else if (func_p) {
  1237. func_p->num_allocd_vfs = number;
  1238. func_p->vf_base_id = logical_id;
  1239. ice_debug(hw, ICE_DBG_INIT,
  1240. "HW caps: VFs allocated = %d\n",
  1241. func_p->num_allocd_vfs);
  1242. ice_debug(hw, ICE_DBG_INIT,
  1243. "HW caps: VF base_id = %d\n",
  1244. func_p->vf_base_id);
  1245. }
  1246. break;
  1247. case ICE_AQC_CAPS_VSI:
  1248. if (dev_p) {
  1249. dev_p->num_vsi_allocd_to_host = number;
  1250. ice_debug(hw, ICE_DBG_INIT,
  1251. "HW caps: Dev.VSI cnt = %d\n",
  1252. dev_p->num_vsi_allocd_to_host);
  1253. } else if (func_p) {
  1254. func_p->guaranteed_num_vsi = number;
  1255. ice_debug(hw, ICE_DBG_INIT,
  1256. "HW caps: Func.VSI cnt = %d\n",
  1257. func_p->guaranteed_num_vsi);
  1258. }
  1259. break;
  1260. case ICE_AQC_CAPS_RSS:
  1261. caps->rss_table_size = number;
  1262. caps->rss_table_entry_width = logical_id;
  1263. ice_debug(hw, ICE_DBG_INIT,
  1264. "HW caps: RSS table size = %d\n",
  1265. caps->rss_table_size);
  1266. ice_debug(hw, ICE_DBG_INIT,
  1267. "HW caps: RSS table width = %d\n",
  1268. caps->rss_table_entry_width);
  1269. break;
  1270. case ICE_AQC_CAPS_RXQS:
  1271. caps->num_rxq = number;
  1272. caps->rxq_first_id = phys_id;
  1273. ice_debug(hw, ICE_DBG_INIT,
  1274. "HW caps: Num Rx Qs = %d\n", caps->num_rxq);
  1275. ice_debug(hw, ICE_DBG_INIT,
  1276. "HW caps: Rx first queue ID = %d\n",
  1277. caps->rxq_first_id);
  1278. break;
  1279. case ICE_AQC_CAPS_TXQS:
  1280. caps->num_txq = number;
  1281. caps->txq_first_id = phys_id;
  1282. ice_debug(hw, ICE_DBG_INIT,
  1283. "HW caps: Num Tx Qs = %d\n", caps->num_txq);
  1284. ice_debug(hw, ICE_DBG_INIT,
  1285. "HW caps: Tx first queue ID = %d\n",
  1286. caps->txq_first_id);
  1287. break;
  1288. case ICE_AQC_CAPS_MSIX:
  1289. caps->num_msix_vectors = number;
  1290. caps->msix_vector_first_id = phys_id;
  1291. ice_debug(hw, ICE_DBG_INIT,
  1292. "HW caps: MSIX vector count = %d\n",
  1293. caps->num_msix_vectors);
  1294. ice_debug(hw, ICE_DBG_INIT,
  1295. "HW caps: MSIX first vector index = %d\n",
  1296. caps->msix_vector_first_id);
  1297. break;
  1298. case ICE_AQC_CAPS_MAX_MTU:
  1299. caps->max_mtu = number;
  1300. if (dev_p)
  1301. ice_debug(hw, ICE_DBG_INIT,
  1302. "HW caps: Dev.MaxMTU = %d\n",
  1303. caps->max_mtu);
  1304. else if (func_p)
  1305. ice_debug(hw, ICE_DBG_INIT,
  1306. "HW caps: func.MaxMTU = %d\n",
  1307. caps->max_mtu);
  1308. break;
  1309. default:
  1310. ice_debug(hw, ICE_DBG_INIT,
  1311. "HW caps: Unknown capability[%d]: 0x%x\n", i,
  1312. cap);
  1313. break;
  1314. }
  1315. }
  1316. }
  1317. /**
  1318. * ice_aq_discover_caps - query function/device capabilities
  1319. * @hw: pointer to the hw struct
  1320. * @buf: a virtual buffer to hold the capabilities
  1321. * @buf_size: Size of the virtual buffer
  1322. * @cap_count: cap count needed if AQ err==ENOMEM
  1323. * @opc: capabilities type to discover - pass in the command opcode
  1324. * @cd: pointer to command details structure or NULL
  1325. *
  1326. * Get the function(0x000a)/device(0x000b) capabilities description from
  1327. * the firmware.
  1328. */
  1329. static enum ice_status
  1330. ice_aq_discover_caps(struct ice_hw *hw, void *buf, u16 buf_size, u32 *cap_count,
  1331. enum ice_adminq_opc opc, struct ice_sq_cd *cd)
  1332. {
  1333. struct ice_aqc_list_caps *cmd;
  1334. struct ice_aq_desc desc;
  1335. enum ice_status status;
  1336. cmd = &desc.params.get_cap;
  1337. if (opc != ice_aqc_opc_list_func_caps &&
  1338. opc != ice_aqc_opc_list_dev_caps)
  1339. return ICE_ERR_PARAM;
  1340. ice_fill_dflt_direct_cmd_desc(&desc, opc);
  1341. status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
  1342. if (!status)
  1343. ice_parse_caps(hw, buf, le32_to_cpu(cmd->count), opc);
  1344. else if (hw->adminq.sq_last_status == ICE_AQ_RC_ENOMEM)
  1345. *cap_count = le32_to_cpu(cmd->count);
  1346. return status;
  1347. }
  1348. /**
  1349. * ice_discover_caps - get info about the HW
  1350. * @hw: pointer to the hardware structure
  1351. * @opc: capabilities type to discover - pass in the command opcode
  1352. */
  1353. static enum ice_status ice_discover_caps(struct ice_hw *hw,
  1354. enum ice_adminq_opc opc)
  1355. {
  1356. enum ice_status status;
  1357. u32 cap_count;
  1358. u16 cbuf_len;
  1359. u8 retries;
  1360. /* The driver doesn't know how many capabilities the device will return
  1361. * so the buffer size required isn't known ahead of time. The driver
  1362. * starts with cbuf_len and if this turns out to be insufficient, the
  1363. * device returns ICE_AQ_RC_ENOMEM and also the cap_count it needs.
  1364. * The driver then allocates the buffer based on the count and retries
  1365. * the operation. So it follows that the retry count is 2.
  1366. */
  1367. #define ICE_GET_CAP_BUF_COUNT 40
  1368. #define ICE_GET_CAP_RETRY_COUNT 2
  1369. cap_count = ICE_GET_CAP_BUF_COUNT;
  1370. retries = ICE_GET_CAP_RETRY_COUNT;
  1371. do {
  1372. void *cbuf;
  1373. cbuf_len = (u16)(cap_count *
  1374. sizeof(struct ice_aqc_list_caps_elem));
  1375. cbuf = devm_kzalloc(ice_hw_to_dev(hw), cbuf_len, GFP_KERNEL);
  1376. if (!cbuf)
  1377. return ICE_ERR_NO_MEMORY;
  1378. status = ice_aq_discover_caps(hw, cbuf, cbuf_len, &cap_count,
  1379. opc, NULL);
  1380. devm_kfree(ice_hw_to_dev(hw), cbuf);
  1381. if (!status || hw->adminq.sq_last_status != ICE_AQ_RC_ENOMEM)
  1382. break;
  1383. /* If ENOMEM is returned, try again with bigger buffer */
  1384. } while (--retries);
  1385. return status;
  1386. }
  1387. /**
  1388. * ice_get_caps - get info about the HW
  1389. * @hw: pointer to the hardware structure
  1390. */
  1391. enum ice_status ice_get_caps(struct ice_hw *hw)
  1392. {
  1393. enum ice_status status;
  1394. status = ice_discover_caps(hw, ice_aqc_opc_list_dev_caps);
  1395. if (!status)
  1396. status = ice_discover_caps(hw, ice_aqc_opc_list_func_caps);
  1397. return status;
  1398. }
  1399. /**
  1400. * ice_aq_manage_mac_write - manage MAC address write command
  1401. * @hw: pointer to the hw struct
  1402. * @mac_addr: MAC address to be written as LAA/LAA+WoL/Port address
  1403. * @flags: flags to control write behavior
  1404. * @cd: pointer to command details structure or NULL
  1405. *
  1406. * This function is used to write MAC address to the NVM (0x0108).
  1407. */
  1408. enum ice_status
  1409. ice_aq_manage_mac_write(struct ice_hw *hw, u8 *mac_addr, u8 flags,
  1410. struct ice_sq_cd *cd)
  1411. {
  1412. struct ice_aqc_manage_mac_write *cmd;
  1413. struct ice_aq_desc desc;
  1414. cmd = &desc.params.mac_write;
  1415. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_manage_mac_write);
  1416. cmd->flags = flags;
  1417. /* Prep values for flags, sah, sal */
  1418. cmd->sah = htons(*((u16 *)mac_addr));
  1419. cmd->sal = htonl(*((u32 *)(mac_addr + 2)));
  1420. return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
  1421. }
  1422. /**
  1423. * ice_aq_clear_pxe_mode
  1424. * @hw: pointer to the hw struct
  1425. *
  1426. * Tell the firmware that the driver is taking over from PXE (0x0110).
  1427. */
  1428. static enum ice_status ice_aq_clear_pxe_mode(struct ice_hw *hw)
  1429. {
  1430. struct ice_aq_desc desc;
  1431. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_clear_pxe_mode);
  1432. desc.params.clear_pxe.rx_cnt = ICE_AQC_CLEAR_PXE_RX_CNT;
  1433. return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  1434. }
  1435. /**
  1436. * ice_clear_pxe_mode - clear pxe operations mode
  1437. * @hw: pointer to the hw struct
  1438. *
  1439. * Make sure all PXE mode settings are cleared, including things
  1440. * like descriptor fetch/write-back mode.
  1441. */
  1442. void ice_clear_pxe_mode(struct ice_hw *hw)
  1443. {
  1444. if (ice_check_sq_alive(hw, &hw->adminq))
  1445. ice_aq_clear_pxe_mode(hw);
  1446. }
  1447. /**
  1448. * ice_get_link_speed_based_on_phy_type - returns link speed
  1449. * @phy_type_low: lower part of phy_type
  1450. *
  1451. * This helper function will convert a phy_type_low to its corresponding link
  1452. * speed.
  1453. * Note: In the structure of phy_type_low, there should be one bit set, as
  1454. * this function will convert one phy type to its speed.
  1455. * If no bit gets set, ICE_LINK_SPEED_UNKNOWN will be returned
  1456. * If more than one bit gets set, ICE_LINK_SPEED_UNKNOWN will be returned
  1457. */
  1458. static u16
  1459. ice_get_link_speed_based_on_phy_type(u64 phy_type_low)
  1460. {
  1461. u16 speed_phy_type_low = ICE_AQ_LINK_SPEED_UNKNOWN;
  1462. switch (phy_type_low) {
  1463. case ICE_PHY_TYPE_LOW_100BASE_TX:
  1464. case ICE_PHY_TYPE_LOW_100M_SGMII:
  1465. speed_phy_type_low = ICE_AQ_LINK_SPEED_100MB;
  1466. break;
  1467. case ICE_PHY_TYPE_LOW_1000BASE_T:
  1468. case ICE_PHY_TYPE_LOW_1000BASE_SX:
  1469. case ICE_PHY_TYPE_LOW_1000BASE_LX:
  1470. case ICE_PHY_TYPE_LOW_1000BASE_KX:
  1471. case ICE_PHY_TYPE_LOW_1G_SGMII:
  1472. speed_phy_type_low = ICE_AQ_LINK_SPEED_1000MB;
  1473. break;
  1474. case ICE_PHY_TYPE_LOW_2500BASE_T:
  1475. case ICE_PHY_TYPE_LOW_2500BASE_X:
  1476. case ICE_PHY_TYPE_LOW_2500BASE_KX:
  1477. speed_phy_type_low = ICE_AQ_LINK_SPEED_2500MB;
  1478. break;
  1479. case ICE_PHY_TYPE_LOW_5GBASE_T:
  1480. case ICE_PHY_TYPE_LOW_5GBASE_KR:
  1481. speed_phy_type_low = ICE_AQ_LINK_SPEED_5GB;
  1482. break;
  1483. case ICE_PHY_TYPE_LOW_10GBASE_T:
  1484. case ICE_PHY_TYPE_LOW_10G_SFI_DA:
  1485. case ICE_PHY_TYPE_LOW_10GBASE_SR:
  1486. case ICE_PHY_TYPE_LOW_10GBASE_LR:
  1487. case ICE_PHY_TYPE_LOW_10GBASE_KR_CR1:
  1488. case ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC:
  1489. case ICE_PHY_TYPE_LOW_10G_SFI_C2C:
  1490. speed_phy_type_low = ICE_AQ_LINK_SPEED_10GB;
  1491. break;
  1492. case ICE_PHY_TYPE_LOW_25GBASE_T:
  1493. case ICE_PHY_TYPE_LOW_25GBASE_CR:
  1494. case ICE_PHY_TYPE_LOW_25GBASE_CR_S:
  1495. case ICE_PHY_TYPE_LOW_25GBASE_CR1:
  1496. case ICE_PHY_TYPE_LOW_25GBASE_SR:
  1497. case ICE_PHY_TYPE_LOW_25GBASE_LR:
  1498. case ICE_PHY_TYPE_LOW_25GBASE_KR:
  1499. case ICE_PHY_TYPE_LOW_25GBASE_KR_S:
  1500. case ICE_PHY_TYPE_LOW_25GBASE_KR1:
  1501. case ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC:
  1502. case ICE_PHY_TYPE_LOW_25G_AUI_C2C:
  1503. speed_phy_type_low = ICE_AQ_LINK_SPEED_25GB;
  1504. break;
  1505. case ICE_PHY_TYPE_LOW_40GBASE_CR4:
  1506. case ICE_PHY_TYPE_LOW_40GBASE_SR4:
  1507. case ICE_PHY_TYPE_LOW_40GBASE_LR4:
  1508. case ICE_PHY_TYPE_LOW_40GBASE_KR4:
  1509. case ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC:
  1510. case ICE_PHY_TYPE_LOW_40G_XLAUI:
  1511. speed_phy_type_low = ICE_AQ_LINK_SPEED_40GB;
  1512. break;
  1513. default:
  1514. speed_phy_type_low = ICE_AQ_LINK_SPEED_UNKNOWN;
  1515. break;
  1516. }
  1517. return speed_phy_type_low;
  1518. }
  1519. /**
  1520. * ice_update_phy_type
  1521. * @phy_type_low: pointer to the lower part of phy_type
  1522. * @link_speeds_bitmap: targeted link speeds bitmap
  1523. *
  1524. * Note: For the link_speeds_bitmap structure, you can check it at
  1525. * [ice_aqc_get_link_status->link_speed]. Caller can pass in
  1526. * link_speeds_bitmap include multiple speeds.
  1527. *
  1528. * The value of phy_type_low will present a certain link speed. This helper
  1529. * function will turn on bits in the phy_type_low based on the value of
  1530. * link_speeds_bitmap input parameter.
  1531. */
  1532. void ice_update_phy_type(u64 *phy_type_low, u16 link_speeds_bitmap)
  1533. {
  1534. u16 speed = ICE_AQ_LINK_SPEED_UNKNOWN;
  1535. u64 pt_low;
  1536. int index;
  1537. /* We first check with low part of phy_type */
  1538. for (index = 0; index <= ICE_PHY_TYPE_LOW_MAX_INDEX; index++) {
  1539. pt_low = BIT_ULL(index);
  1540. speed = ice_get_link_speed_based_on_phy_type(pt_low);
  1541. if (link_speeds_bitmap & speed)
  1542. *phy_type_low |= BIT_ULL(index);
  1543. }
  1544. }
  1545. /**
  1546. * ice_aq_set_phy_cfg
  1547. * @hw: pointer to the hw struct
  1548. * @lport: logical port number
  1549. * @cfg: structure with PHY configuration data to be set
  1550. * @cd: pointer to command details structure or NULL
  1551. *
  1552. * Set the various PHY configuration parameters supported on the Port.
  1553. * One or more of the Set PHY config parameters may be ignored in an MFP
  1554. * mode as the PF may not have the privilege to set some of the PHY Config
  1555. * parameters. This status will be indicated by the command response (0x0601).
  1556. */
  1557. enum ice_status
  1558. ice_aq_set_phy_cfg(struct ice_hw *hw, u8 lport,
  1559. struct ice_aqc_set_phy_cfg_data *cfg, struct ice_sq_cd *cd)
  1560. {
  1561. struct ice_aq_desc desc;
  1562. if (!cfg)
  1563. return ICE_ERR_PARAM;
  1564. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_phy_cfg);
  1565. desc.params.set_phy.lport_num = lport;
  1566. desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
  1567. return ice_aq_send_cmd(hw, &desc, cfg, sizeof(*cfg), cd);
  1568. }
  1569. /**
  1570. * ice_update_link_info - update status of the HW network link
  1571. * @pi: port info structure of the interested logical port
  1572. */
  1573. enum ice_status ice_update_link_info(struct ice_port_info *pi)
  1574. {
  1575. struct ice_aqc_get_phy_caps_data *pcaps;
  1576. struct ice_phy_info *phy_info;
  1577. enum ice_status status;
  1578. struct ice_hw *hw;
  1579. if (!pi)
  1580. return ICE_ERR_PARAM;
  1581. hw = pi->hw;
  1582. pcaps = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*pcaps), GFP_KERNEL);
  1583. if (!pcaps)
  1584. return ICE_ERR_NO_MEMORY;
  1585. phy_info = &pi->phy;
  1586. status = ice_aq_get_link_info(pi, true, NULL, NULL);
  1587. if (status)
  1588. goto out;
  1589. if (phy_info->link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) {
  1590. status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG,
  1591. pcaps, NULL);
  1592. if (status)
  1593. goto out;
  1594. memcpy(phy_info->link_info.module_type, &pcaps->module_type,
  1595. sizeof(phy_info->link_info.module_type));
  1596. }
  1597. out:
  1598. devm_kfree(ice_hw_to_dev(hw), pcaps);
  1599. return status;
  1600. }
  1601. /**
  1602. * ice_set_fc
  1603. * @pi: port information structure
  1604. * @aq_failures: pointer to status code, specific to ice_set_fc routine
  1605. * @ena_auto_link_update: enable automatic link update
  1606. *
  1607. * Set the requested flow control mode.
  1608. */
  1609. enum ice_status
  1610. ice_set_fc(struct ice_port_info *pi, u8 *aq_failures, bool ena_auto_link_update)
  1611. {
  1612. struct ice_aqc_set_phy_cfg_data cfg = { 0 };
  1613. struct ice_aqc_get_phy_caps_data *pcaps;
  1614. enum ice_status status;
  1615. u8 pause_mask = 0x0;
  1616. struct ice_hw *hw;
  1617. if (!pi)
  1618. return ICE_ERR_PARAM;
  1619. hw = pi->hw;
  1620. *aq_failures = ICE_SET_FC_AQ_FAIL_NONE;
  1621. switch (pi->fc.req_mode) {
  1622. case ICE_FC_FULL:
  1623. pause_mask |= ICE_AQC_PHY_EN_TX_LINK_PAUSE;
  1624. pause_mask |= ICE_AQC_PHY_EN_RX_LINK_PAUSE;
  1625. break;
  1626. case ICE_FC_RX_PAUSE:
  1627. pause_mask |= ICE_AQC_PHY_EN_RX_LINK_PAUSE;
  1628. break;
  1629. case ICE_FC_TX_PAUSE:
  1630. pause_mask |= ICE_AQC_PHY_EN_TX_LINK_PAUSE;
  1631. break;
  1632. default:
  1633. break;
  1634. }
  1635. pcaps = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*pcaps), GFP_KERNEL);
  1636. if (!pcaps)
  1637. return ICE_ERR_NO_MEMORY;
  1638. /* Get the current phy config */
  1639. status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps,
  1640. NULL);
  1641. if (status) {
  1642. *aq_failures = ICE_SET_FC_AQ_FAIL_GET;
  1643. goto out;
  1644. }
  1645. /* clear the old pause settings */
  1646. cfg.caps = pcaps->caps & ~(ICE_AQC_PHY_EN_TX_LINK_PAUSE |
  1647. ICE_AQC_PHY_EN_RX_LINK_PAUSE);
  1648. /* set the new capabilities */
  1649. cfg.caps |= pause_mask;
  1650. /* If the capabilities have changed, then set the new config */
  1651. if (cfg.caps != pcaps->caps) {
  1652. int retry_count, retry_max = 10;
  1653. /* Auto restart link so settings take effect */
  1654. if (ena_auto_link_update)
  1655. cfg.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
  1656. /* Copy over all the old settings */
  1657. cfg.phy_type_low = pcaps->phy_type_low;
  1658. cfg.low_power_ctrl = pcaps->low_power_ctrl;
  1659. cfg.eee_cap = pcaps->eee_cap;
  1660. cfg.eeer_value = pcaps->eeer_value;
  1661. cfg.link_fec_opt = pcaps->link_fec_options;
  1662. status = ice_aq_set_phy_cfg(hw, pi->lport, &cfg, NULL);
  1663. if (status) {
  1664. *aq_failures = ICE_SET_FC_AQ_FAIL_SET;
  1665. goto out;
  1666. }
  1667. /* Update the link info
  1668. * It sometimes takes a really long time for link to
  1669. * come back from the atomic reset. Thus, we wait a
  1670. * little bit.
  1671. */
  1672. for (retry_count = 0; retry_count < retry_max; retry_count++) {
  1673. status = ice_update_link_info(pi);
  1674. if (!status)
  1675. break;
  1676. mdelay(100);
  1677. }
  1678. if (status)
  1679. *aq_failures = ICE_SET_FC_AQ_FAIL_UPDATE;
  1680. }
  1681. out:
  1682. devm_kfree(ice_hw_to_dev(hw), pcaps);
  1683. return status;
  1684. }
  1685. /**
  1686. * ice_get_link_status - get status of the HW network link
  1687. * @pi: port information structure
  1688. * @link_up: pointer to bool (true/false = linkup/linkdown)
  1689. *
  1690. * Variable link_up is true if link is up, false if link is down.
  1691. * The variable link_up is invalid if status is non zero. As a
  1692. * result of this call, link status reporting becomes enabled
  1693. */
  1694. enum ice_status ice_get_link_status(struct ice_port_info *pi, bool *link_up)
  1695. {
  1696. struct ice_phy_info *phy_info;
  1697. enum ice_status status = 0;
  1698. if (!pi || !link_up)
  1699. return ICE_ERR_PARAM;
  1700. phy_info = &pi->phy;
  1701. if (phy_info->get_link_info) {
  1702. status = ice_update_link_info(pi);
  1703. if (status)
  1704. ice_debug(pi->hw, ICE_DBG_LINK,
  1705. "get link status error, status = %d\n",
  1706. status);
  1707. }
  1708. *link_up = phy_info->link_info.link_info & ICE_AQ_LINK_UP;
  1709. return status;
  1710. }
  1711. /**
  1712. * ice_aq_set_link_restart_an
  1713. * @pi: pointer to the port information structure
  1714. * @ena_link: if true: enable link, if false: disable link
  1715. * @cd: pointer to command details structure or NULL
  1716. *
  1717. * Sets up the link and restarts the Auto-Negotiation over the link.
  1718. */
  1719. enum ice_status
  1720. ice_aq_set_link_restart_an(struct ice_port_info *pi, bool ena_link,
  1721. struct ice_sq_cd *cd)
  1722. {
  1723. struct ice_aqc_restart_an *cmd;
  1724. struct ice_aq_desc desc;
  1725. cmd = &desc.params.restart_an;
  1726. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_restart_an);
  1727. cmd->cmd_flags = ICE_AQC_RESTART_AN_LINK_RESTART;
  1728. cmd->lport_num = pi->lport;
  1729. if (ena_link)
  1730. cmd->cmd_flags |= ICE_AQC_RESTART_AN_LINK_ENABLE;
  1731. else
  1732. cmd->cmd_flags &= ~ICE_AQC_RESTART_AN_LINK_ENABLE;
  1733. return ice_aq_send_cmd(pi->hw, &desc, NULL, 0, cd);
  1734. }
  1735. /**
  1736. * __ice_aq_get_set_rss_lut
  1737. * @hw: pointer to the hardware structure
  1738. * @vsi_id: VSI FW index
  1739. * @lut_type: LUT table type
  1740. * @lut: pointer to the LUT buffer provided by the caller
  1741. * @lut_size: size of the LUT buffer
  1742. * @glob_lut_idx: global LUT index
  1743. * @set: set true to set the table, false to get the table
  1744. *
  1745. * Internal function to get (0x0B05) or set (0x0B03) RSS look up table
  1746. */
  1747. static enum ice_status
  1748. __ice_aq_get_set_rss_lut(struct ice_hw *hw, u16 vsi_id, u8 lut_type, u8 *lut,
  1749. u16 lut_size, u8 glob_lut_idx, bool set)
  1750. {
  1751. struct ice_aqc_get_set_rss_lut *cmd_resp;
  1752. struct ice_aq_desc desc;
  1753. enum ice_status status;
  1754. u16 flags = 0;
  1755. cmd_resp = &desc.params.get_set_rss_lut;
  1756. if (set) {
  1757. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_rss_lut);
  1758. desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
  1759. } else {
  1760. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_rss_lut);
  1761. }
  1762. cmd_resp->vsi_id = cpu_to_le16(((vsi_id <<
  1763. ICE_AQC_GSET_RSS_LUT_VSI_ID_S) &
  1764. ICE_AQC_GSET_RSS_LUT_VSI_ID_M) |
  1765. ICE_AQC_GSET_RSS_LUT_VSI_VALID);
  1766. switch (lut_type) {
  1767. case ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_VSI:
  1768. case ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF:
  1769. case ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_GLOBAL:
  1770. flags |= ((lut_type << ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_S) &
  1771. ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_M);
  1772. break;
  1773. default:
  1774. status = ICE_ERR_PARAM;
  1775. goto ice_aq_get_set_rss_lut_exit;
  1776. }
  1777. if (lut_type == ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_GLOBAL) {
  1778. flags |= ((glob_lut_idx << ICE_AQC_GSET_RSS_LUT_GLOBAL_IDX_S) &
  1779. ICE_AQC_GSET_RSS_LUT_GLOBAL_IDX_M);
  1780. if (!set)
  1781. goto ice_aq_get_set_rss_lut_send;
  1782. } else if (lut_type == ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF) {
  1783. if (!set)
  1784. goto ice_aq_get_set_rss_lut_send;
  1785. } else {
  1786. goto ice_aq_get_set_rss_lut_send;
  1787. }
  1788. /* LUT size is only valid for Global and PF table types */
  1789. switch (lut_size) {
  1790. case ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_128:
  1791. break;
  1792. case ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512:
  1793. flags |= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512_FLAG <<
  1794. ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S) &
  1795. ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M;
  1796. break;
  1797. case ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K:
  1798. if (lut_type == ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF) {
  1799. flags |= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K_FLAG <<
  1800. ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S) &
  1801. ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M;
  1802. break;
  1803. }
  1804. /* fall-through */
  1805. default:
  1806. status = ICE_ERR_PARAM;
  1807. goto ice_aq_get_set_rss_lut_exit;
  1808. }
  1809. ice_aq_get_set_rss_lut_send:
  1810. cmd_resp->flags = cpu_to_le16(flags);
  1811. status = ice_aq_send_cmd(hw, &desc, lut, lut_size, NULL);
  1812. ice_aq_get_set_rss_lut_exit:
  1813. return status;
  1814. }
  1815. /**
  1816. * ice_aq_get_rss_lut
  1817. * @hw: pointer to the hardware structure
  1818. * @vsi_handle: software VSI handle
  1819. * @lut_type: LUT table type
  1820. * @lut: pointer to the LUT buffer provided by the caller
  1821. * @lut_size: size of the LUT buffer
  1822. *
  1823. * get the RSS lookup table, PF or VSI type
  1824. */
  1825. enum ice_status
  1826. ice_aq_get_rss_lut(struct ice_hw *hw, u16 vsi_handle, u8 lut_type,
  1827. u8 *lut, u16 lut_size)
  1828. {
  1829. if (!ice_is_vsi_valid(hw, vsi_handle) || !lut)
  1830. return ICE_ERR_PARAM;
  1831. return __ice_aq_get_set_rss_lut(hw, ice_get_hw_vsi_num(hw, vsi_handle),
  1832. lut_type, lut, lut_size, 0, false);
  1833. }
  1834. /**
  1835. * ice_aq_set_rss_lut
  1836. * @hw: pointer to the hardware structure
  1837. * @vsi_handle: software VSI handle
  1838. * @lut_type: LUT table type
  1839. * @lut: pointer to the LUT buffer provided by the caller
  1840. * @lut_size: size of the LUT buffer
  1841. *
  1842. * set the RSS lookup table, PF or VSI type
  1843. */
  1844. enum ice_status
  1845. ice_aq_set_rss_lut(struct ice_hw *hw, u16 vsi_handle, u8 lut_type,
  1846. u8 *lut, u16 lut_size)
  1847. {
  1848. if (!ice_is_vsi_valid(hw, vsi_handle) || !lut)
  1849. return ICE_ERR_PARAM;
  1850. return __ice_aq_get_set_rss_lut(hw, ice_get_hw_vsi_num(hw, vsi_handle),
  1851. lut_type, lut, lut_size, 0, true);
  1852. }
  1853. /**
  1854. * __ice_aq_get_set_rss_key
  1855. * @hw: pointer to the hw struct
  1856. * @vsi_id: VSI FW index
  1857. * @key: pointer to key info struct
  1858. * @set: set true to set the key, false to get the key
  1859. *
  1860. * get (0x0B04) or set (0x0B02) the RSS key per VSI
  1861. */
  1862. static enum
  1863. ice_status __ice_aq_get_set_rss_key(struct ice_hw *hw, u16 vsi_id,
  1864. struct ice_aqc_get_set_rss_keys *key,
  1865. bool set)
  1866. {
  1867. struct ice_aqc_get_set_rss_key *cmd_resp;
  1868. u16 key_size = sizeof(*key);
  1869. struct ice_aq_desc desc;
  1870. cmd_resp = &desc.params.get_set_rss_key;
  1871. if (set) {
  1872. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_rss_key);
  1873. desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
  1874. } else {
  1875. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_rss_key);
  1876. }
  1877. cmd_resp->vsi_id = cpu_to_le16(((vsi_id <<
  1878. ICE_AQC_GSET_RSS_KEY_VSI_ID_S) &
  1879. ICE_AQC_GSET_RSS_KEY_VSI_ID_M) |
  1880. ICE_AQC_GSET_RSS_KEY_VSI_VALID);
  1881. return ice_aq_send_cmd(hw, &desc, key, key_size, NULL);
  1882. }
  1883. /**
  1884. * ice_aq_get_rss_key
  1885. * @hw: pointer to the hw struct
  1886. * @vsi_handle: software VSI handle
  1887. * @key: pointer to key info struct
  1888. *
  1889. * get the RSS key per VSI
  1890. */
  1891. enum ice_status
  1892. ice_aq_get_rss_key(struct ice_hw *hw, u16 vsi_handle,
  1893. struct ice_aqc_get_set_rss_keys *key)
  1894. {
  1895. if (!ice_is_vsi_valid(hw, vsi_handle) || !key)
  1896. return ICE_ERR_PARAM;
  1897. return __ice_aq_get_set_rss_key(hw, ice_get_hw_vsi_num(hw, vsi_handle),
  1898. key, false);
  1899. }
  1900. /**
  1901. * ice_aq_set_rss_key
  1902. * @hw: pointer to the hw struct
  1903. * @vsi_handle: software VSI handle
  1904. * @keys: pointer to key info struct
  1905. *
  1906. * set the RSS key per VSI
  1907. */
  1908. enum ice_status
  1909. ice_aq_set_rss_key(struct ice_hw *hw, u16 vsi_handle,
  1910. struct ice_aqc_get_set_rss_keys *keys)
  1911. {
  1912. if (!ice_is_vsi_valid(hw, vsi_handle) || !keys)
  1913. return ICE_ERR_PARAM;
  1914. return __ice_aq_get_set_rss_key(hw, ice_get_hw_vsi_num(hw, vsi_handle),
  1915. keys, true);
  1916. }
  1917. /**
  1918. * ice_aq_add_lan_txq
  1919. * @hw: pointer to the hardware structure
  1920. * @num_qgrps: Number of added queue groups
  1921. * @qg_list: list of queue groups to be added
  1922. * @buf_size: size of buffer for indirect command
  1923. * @cd: pointer to command details structure or NULL
  1924. *
  1925. * Add Tx LAN queue (0x0C30)
  1926. *
  1927. * NOTE:
  1928. * Prior to calling add Tx LAN queue:
  1929. * Initialize the following as part of the Tx queue context:
  1930. * Completion queue ID if the queue uses Completion queue, Quanta profile,
  1931. * Cache profile and Packet shaper profile.
  1932. *
  1933. * After add Tx LAN queue AQ command is completed:
  1934. * Interrupts should be associated with specific queues,
  1935. * Association of Tx queue to Doorbell queue is not part of Add LAN Tx queue
  1936. * flow.
  1937. */
  1938. static enum ice_status
  1939. ice_aq_add_lan_txq(struct ice_hw *hw, u8 num_qgrps,
  1940. struct ice_aqc_add_tx_qgrp *qg_list, u16 buf_size,
  1941. struct ice_sq_cd *cd)
  1942. {
  1943. u16 i, sum_header_size, sum_q_size = 0;
  1944. struct ice_aqc_add_tx_qgrp *list;
  1945. struct ice_aqc_add_txqs *cmd;
  1946. struct ice_aq_desc desc;
  1947. cmd = &desc.params.add_txqs;
  1948. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_add_txqs);
  1949. if (!qg_list)
  1950. return ICE_ERR_PARAM;
  1951. if (num_qgrps > ICE_LAN_TXQ_MAX_QGRPS)
  1952. return ICE_ERR_PARAM;
  1953. sum_header_size = num_qgrps *
  1954. (sizeof(*qg_list) - sizeof(*qg_list->txqs));
  1955. list = qg_list;
  1956. for (i = 0; i < num_qgrps; i++) {
  1957. struct ice_aqc_add_txqs_perq *q = list->txqs;
  1958. sum_q_size += list->num_txqs * sizeof(*q);
  1959. list = (struct ice_aqc_add_tx_qgrp *)(q + list->num_txqs);
  1960. }
  1961. if (buf_size != (sum_header_size + sum_q_size))
  1962. return ICE_ERR_PARAM;
  1963. desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
  1964. cmd->num_qgrps = num_qgrps;
  1965. return ice_aq_send_cmd(hw, &desc, qg_list, buf_size, cd);
  1966. }
  1967. /**
  1968. * ice_aq_dis_lan_txq
  1969. * @hw: pointer to the hardware structure
  1970. * @num_qgrps: number of groups in the list
  1971. * @qg_list: the list of groups to disable
  1972. * @buf_size: the total size of the qg_list buffer in bytes
  1973. * @rst_src: if called due to reset, specifies the RST source
  1974. * @vmvf_num: the relative VM or VF number that is undergoing the reset
  1975. * @cd: pointer to command details structure or NULL
  1976. *
  1977. * Disable LAN Tx queue (0x0C31)
  1978. */
  1979. static enum ice_status
  1980. ice_aq_dis_lan_txq(struct ice_hw *hw, u8 num_qgrps,
  1981. struct ice_aqc_dis_txq_item *qg_list, u16 buf_size,
  1982. enum ice_disq_rst_src rst_src, u16 vmvf_num,
  1983. struct ice_sq_cd *cd)
  1984. {
  1985. struct ice_aqc_dis_txqs *cmd;
  1986. struct ice_aq_desc desc;
  1987. u16 i, sz = 0;
  1988. cmd = &desc.params.dis_txqs;
  1989. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_dis_txqs);
  1990. /* qg_list can be NULL only in VM/VF reset flow */
  1991. if (!qg_list && !rst_src)
  1992. return ICE_ERR_PARAM;
  1993. if (num_qgrps > ICE_LAN_TXQ_MAX_QGRPS)
  1994. return ICE_ERR_PARAM;
  1995. cmd->num_entries = num_qgrps;
  1996. cmd->vmvf_and_timeout = cpu_to_le16((5 << ICE_AQC_Q_DIS_TIMEOUT_S) &
  1997. ICE_AQC_Q_DIS_TIMEOUT_M);
  1998. switch (rst_src) {
  1999. case ICE_VM_RESET:
  2000. cmd->cmd_type = ICE_AQC_Q_DIS_CMD_VM_RESET;
  2001. cmd->vmvf_and_timeout |=
  2002. cpu_to_le16(vmvf_num & ICE_AQC_Q_DIS_VMVF_NUM_M);
  2003. break;
  2004. case ICE_VF_RESET:
  2005. cmd->cmd_type = ICE_AQC_Q_DIS_CMD_VF_RESET;
  2006. /* In this case, FW expects vmvf_num to be absolute VF id */
  2007. cmd->vmvf_and_timeout |=
  2008. cpu_to_le16((vmvf_num + hw->func_caps.vf_base_id) &
  2009. ICE_AQC_Q_DIS_VMVF_NUM_M);
  2010. break;
  2011. case ICE_NO_RESET:
  2012. default:
  2013. break;
  2014. }
  2015. /* If no queue group info, we are in a reset flow. Issue the AQ */
  2016. if (!qg_list)
  2017. goto do_aq;
  2018. /* set RD bit to indicate that command buffer is provided by the driver
  2019. * and it needs to be read by the firmware
  2020. */
  2021. desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
  2022. for (i = 0; i < num_qgrps; ++i) {
  2023. /* Calculate the size taken up by the queue IDs in this group */
  2024. sz += qg_list[i].num_qs * sizeof(qg_list[i].q_id);
  2025. /* Add the size of the group header */
  2026. sz += sizeof(qg_list[i]) - sizeof(qg_list[i].q_id);
  2027. /* If the num of queues is even, add 2 bytes of padding */
  2028. if ((qg_list[i].num_qs % 2) == 0)
  2029. sz += 2;
  2030. }
  2031. if (buf_size != sz)
  2032. return ICE_ERR_PARAM;
  2033. do_aq:
  2034. return ice_aq_send_cmd(hw, &desc, qg_list, buf_size, cd);
  2035. }
  2036. /* End of FW Admin Queue command wrappers */
  2037. /**
  2038. * ice_write_byte - write a byte to a packed context structure
  2039. * @src_ctx: the context structure to read from
  2040. * @dest_ctx: the context to be written to
  2041. * @ce_info: a description of the struct to be filled
  2042. */
  2043. static void ice_write_byte(u8 *src_ctx, u8 *dest_ctx,
  2044. const struct ice_ctx_ele *ce_info)
  2045. {
  2046. u8 src_byte, dest_byte, mask;
  2047. u8 *from, *dest;
  2048. u16 shift_width;
  2049. /* copy from the next struct field */
  2050. from = src_ctx + ce_info->offset;
  2051. /* prepare the bits and mask */
  2052. shift_width = ce_info->lsb % 8;
  2053. mask = (u8)(BIT(ce_info->width) - 1);
  2054. src_byte = *from;
  2055. src_byte &= mask;
  2056. /* shift to correct alignment */
  2057. mask <<= shift_width;
  2058. src_byte <<= shift_width;
  2059. /* get the current bits from the target bit string */
  2060. dest = dest_ctx + (ce_info->lsb / 8);
  2061. memcpy(&dest_byte, dest, sizeof(dest_byte));
  2062. dest_byte &= ~mask; /* get the bits not changing */
  2063. dest_byte |= src_byte; /* add in the new bits */
  2064. /* put it all back */
  2065. memcpy(dest, &dest_byte, sizeof(dest_byte));
  2066. }
  2067. /**
  2068. * ice_write_word - write a word to a packed context structure
  2069. * @src_ctx: the context structure to read from
  2070. * @dest_ctx: the context to be written to
  2071. * @ce_info: a description of the struct to be filled
  2072. */
  2073. static void ice_write_word(u8 *src_ctx, u8 *dest_ctx,
  2074. const struct ice_ctx_ele *ce_info)
  2075. {
  2076. u16 src_word, mask;
  2077. __le16 dest_word;
  2078. u8 *from, *dest;
  2079. u16 shift_width;
  2080. /* copy from the next struct field */
  2081. from = src_ctx + ce_info->offset;
  2082. /* prepare the bits and mask */
  2083. shift_width = ce_info->lsb % 8;
  2084. mask = BIT(ce_info->width) - 1;
  2085. /* don't swizzle the bits until after the mask because the mask bits
  2086. * will be in a different bit position on big endian machines
  2087. */
  2088. src_word = *(u16 *)from;
  2089. src_word &= mask;
  2090. /* shift to correct alignment */
  2091. mask <<= shift_width;
  2092. src_word <<= shift_width;
  2093. /* get the current bits from the target bit string */
  2094. dest = dest_ctx + (ce_info->lsb / 8);
  2095. memcpy(&dest_word, dest, sizeof(dest_word));
  2096. dest_word &= ~(cpu_to_le16(mask)); /* get the bits not changing */
  2097. dest_word |= cpu_to_le16(src_word); /* add in the new bits */
  2098. /* put it all back */
  2099. memcpy(dest, &dest_word, sizeof(dest_word));
  2100. }
  2101. /**
  2102. * ice_write_dword - write a dword to a packed context structure
  2103. * @src_ctx: the context structure to read from
  2104. * @dest_ctx: the context to be written to
  2105. * @ce_info: a description of the struct to be filled
  2106. */
  2107. static void ice_write_dword(u8 *src_ctx, u8 *dest_ctx,
  2108. const struct ice_ctx_ele *ce_info)
  2109. {
  2110. u32 src_dword, mask;
  2111. __le32 dest_dword;
  2112. u8 *from, *dest;
  2113. u16 shift_width;
  2114. /* copy from the next struct field */
  2115. from = src_ctx + ce_info->offset;
  2116. /* prepare the bits and mask */
  2117. shift_width = ce_info->lsb % 8;
  2118. /* if the field width is exactly 32 on an x86 machine, then the shift
  2119. * operation will not work because the SHL instructions count is masked
  2120. * to 5 bits so the shift will do nothing
  2121. */
  2122. if (ce_info->width < 32)
  2123. mask = BIT(ce_info->width) - 1;
  2124. else
  2125. mask = (u32)~0;
  2126. /* don't swizzle the bits until after the mask because the mask bits
  2127. * will be in a different bit position on big endian machines
  2128. */
  2129. src_dword = *(u32 *)from;
  2130. src_dword &= mask;
  2131. /* shift to correct alignment */
  2132. mask <<= shift_width;
  2133. src_dword <<= shift_width;
  2134. /* get the current bits from the target bit string */
  2135. dest = dest_ctx + (ce_info->lsb / 8);
  2136. memcpy(&dest_dword, dest, sizeof(dest_dword));
  2137. dest_dword &= ~(cpu_to_le32(mask)); /* get the bits not changing */
  2138. dest_dword |= cpu_to_le32(src_dword); /* add in the new bits */
  2139. /* put it all back */
  2140. memcpy(dest, &dest_dword, sizeof(dest_dword));
  2141. }
  2142. /**
  2143. * ice_write_qword - write a qword to a packed context structure
  2144. * @src_ctx: the context structure to read from
  2145. * @dest_ctx: the context to be written to
  2146. * @ce_info: a description of the struct to be filled
  2147. */
  2148. static void ice_write_qword(u8 *src_ctx, u8 *dest_ctx,
  2149. const struct ice_ctx_ele *ce_info)
  2150. {
  2151. u64 src_qword, mask;
  2152. __le64 dest_qword;
  2153. u8 *from, *dest;
  2154. u16 shift_width;
  2155. /* copy from the next struct field */
  2156. from = src_ctx + ce_info->offset;
  2157. /* prepare the bits and mask */
  2158. shift_width = ce_info->lsb % 8;
  2159. /* if the field width is exactly 64 on an x86 machine, then the shift
  2160. * operation will not work because the SHL instructions count is masked
  2161. * to 6 bits so the shift will do nothing
  2162. */
  2163. if (ce_info->width < 64)
  2164. mask = BIT_ULL(ce_info->width) - 1;
  2165. else
  2166. mask = (u64)~0;
  2167. /* don't swizzle the bits until after the mask because the mask bits
  2168. * will be in a different bit position on big endian machines
  2169. */
  2170. src_qword = *(u64 *)from;
  2171. src_qword &= mask;
  2172. /* shift to correct alignment */
  2173. mask <<= shift_width;
  2174. src_qword <<= shift_width;
  2175. /* get the current bits from the target bit string */
  2176. dest = dest_ctx + (ce_info->lsb / 8);
  2177. memcpy(&dest_qword, dest, sizeof(dest_qword));
  2178. dest_qword &= ~(cpu_to_le64(mask)); /* get the bits not changing */
  2179. dest_qword |= cpu_to_le64(src_qword); /* add in the new bits */
  2180. /* put it all back */
  2181. memcpy(dest, &dest_qword, sizeof(dest_qword));
  2182. }
  2183. /**
  2184. * ice_set_ctx - set context bits in packed structure
  2185. * @src_ctx: pointer to a generic non-packed context structure
  2186. * @dest_ctx: pointer to memory for the packed structure
  2187. * @ce_info: a description of the structure to be transformed
  2188. */
  2189. enum ice_status
  2190. ice_set_ctx(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
  2191. {
  2192. int f;
  2193. for (f = 0; ce_info[f].width; f++) {
  2194. /* We have to deal with each element of the FW response
  2195. * using the correct size so that we are correct regardless
  2196. * of the endianness of the machine.
  2197. */
  2198. switch (ce_info[f].size_of) {
  2199. case sizeof(u8):
  2200. ice_write_byte(src_ctx, dest_ctx, &ce_info[f]);
  2201. break;
  2202. case sizeof(u16):
  2203. ice_write_word(src_ctx, dest_ctx, &ce_info[f]);
  2204. break;
  2205. case sizeof(u32):
  2206. ice_write_dword(src_ctx, dest_ctx, &ce_info[f]);
  2207. break;
  2208. case sizeof(u64):
  2209. ice_write_qword(src_ctx, dest_ctx, &ce_info[f]);
  2210. break;
  2211. default:
  2212. return ICE_ERR_INVAL_SIZE;
  2213. }
  2214. }
  2215. return 0;
  2216. }
  2217. /**
  2218. * ice_ena_vsi_txq
  2219. * @pi: port information structure
  2220. * @vsi_handle: software VSI handle
  2221. * @tc: tc number
  2222. * @num_qgrps: Number of added queue groups
  2223. * @buf: list of queue groups to be added
  2224. * @buf_size: size of buffer for indirect command
  2225. * @cd: pointer to command details structure or NULL
  2226. *
  2227. * This function adds one lan q
  2228. */
  2229. enum ice_status
  2230. ice_ena_vsi_txq(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u8 num_qgrps,
  2231. struct ice_aqc_add_tx_qgrp *buf, u16 buf_size,
  2232. struct ice_sq_cd *cd)
  2233. {
  2234. struct ice_aqc_txsched_elem_data node = { 0 };
  2235. struct ice_sched_node *parent;
  2236. enum ice_status status;
  2237. struct ice_hw *hw;
  2238. if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
  2239. return ICE_ERR_CFG;
  2240. if (num_qgrps > 1 || buf->num_txqs > 1)
  2241. return ICE_ERR_MAX_LIMIT;
  2242. hw = pi->hw;
  2243. if (!ice_is_vsi_valid(hw, vsi_handle))
  2244. return ICE_ERR_PARAM;
  2245. mutex_lock(&pi->sched_lock);
  2246. /* find a parent node */
  2247. parent = ice_sched_get_free_qparent(pi, vsi_handle, tc,
  2248. ICE_SCHED_NODE_OWNER_LAN);
  2249. if (!parent) {
  2250. status = ICE_ERR_PARAM;
  2251. goto ena_txq_exit;
  2252. }
  2253. buf->parent_teid = parent->info.node_teid;
  2254. node.parent_teid = parent->info.node_teid;
  2255. /* Mark that the values in the "generic" section as valid. The default
  2256. * value in the "generic" section is zero. This means that :
  2257. * - Scheduling mode is Bytes Per Second (BPS), indicated by Bit 0.
  2258. * - 0 priority among siblings, indicated by Bit 1-3.
  2259. * - WFQ, indicated by Bit 4.
  2260. * - 0 Adjustment value is used in PSM credit update flow, indicated by
  2261. * Bit 5-6.
  2262. * - Bit 7 is reserved.
  2263. * Without setting the generic section as valid in valid_sections, the
  2264. * Admin Q command will fail with error code ICE_AQ_RC_EINVAL.
  2265. */
  2266. buf->txqs[0].info.valid_sections = ICE_AQC_ELEM_VALID_GENERIC;
  2267. /* add the lan q */
  2268. status = ice_aq_add_lan_txq(hw, num_qgrps, buf, buf_size, cd);
  2269. if (status)
  2270. goto ena_txq_exit;
  2271. node.node_teid = buf->txqs[0].q_teid;
  2272. node.data.elem_type = ICE_AQC_ELEM_TYPE_LEAF;
  2273. /* add a leaf node into schduler tree q layer */
  2274. status = ice_sched_add_node(pi, hw->num_tx_sched_layers - 1, &node);
  2275. ena_txq_exit:
  2276. mutex_unlock(&pi->sched_lock);
  2277. return status;
  2278. }
  2279. /**
  2280. * ice_dis_vsi_txq
  2281. * @pi: port information structure
  2282. * @num_queues: number of queues
  2283. * @q_ids: pointer to the q_id array
  2284. * @q_teids: pointer to queue node teids
  2285. * @rst_src: if called due to reset, specifies the RST source
  2286. * @vmvf_num: the relative VM or VF number that is undergoing the reset
  2287. * @cd: pointer to command details structure or NULL
  2288. *
  2289. * This function removes queues and their corresponding nodes in SW DB
  2290. */
  2291. enum ice_status
  2292. ice_dis_vsi_txq(struct ice_port_info *pi, u8 num_queues, u16 *q_ids,
  2293. u32 *q_teids, enum ice_disq_rst_src rst_src, u16 vmvf_num,
  2294. struct ice_sq_cd *cd)
  2295. {
  2296. enum ice_status status = ICE_ERR_DOES_NOT_EXIST;
  2297. struct ice_aqc_dis_txq_item qg_list;
  2298. u16 i;
  2299. if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
  2300. return ICE_ERR_CFG;
  2301. /* if queue is disabled already yet the disable queue command has to be
  2302. * sent to complete the VF reset, then call ice_aq_dis_lan_txq without
  2303. * any queue information
  2304. */
  2305. if (!num_queues && rst_src)
  2306. return ice_aq_dis_lan_txq(pi->hw, 0, NULL, 0, rst_src, vmvf_num,
  2307. NULL);
  2308. mutex_lock(&pi->sched_lock);
  2309. for (i = 0; i < num_queues; i++) {
  2310. struct ice_sched_node *node;
  2311. node = ice_sched_find_node_by_teid(pi->root, q_teids[i]);
  2312. if (!node)
  2313. continue;
  2314. qg_list.parent_teid = node->info.parent_teid;
  2315. qg_list.num_qs = 1;
  2316. qg_list.q_id[0] = cpu_to_le16(q_ids[i]);
  2317. status = ice_aq_dis_lan_txq(pi->hw, 1, &qg_list,
  2318. sizeof(qg_list), rst_src, vmvf_num,
  2319. cd);
  2320. if (status)
  2321. break;
  2322. ice_free_sched_node(pi, node);
  2323. }
  2324. mutex_unlock(&pi->sched_lock);
  2325. return status;
  2326. }
  2327. /**
  2328. * ice_cfg_vsi_qs - configure the new/exisiting VSI queues
  2329. * @pi: port information structure
  2330. * @vsi_handle: software VSI handle
  2331. * @tc_bitmap: TC bitmap
  2332. * @maxqs: max queues array per TC
  2333. * @owner: lan or rdma
  2334. *
  2335. * This function adds/updates the VSI queues per TC.
  2336. */
  2337. static enum ice_status
  2338. ice_cfg_vsi_qs(struct ice_port_info *pi, u16 vsi_handle, u8 tc_bitmap,
  2339. u16 *maxqs, u8 owner)
  2340. {
  2341. enum ice_status status = 0;
  2342. u8 i;
  2343. if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
  2344. return ICE_ERR_CFG;
  2345. if (!ice_is_vsi_valid(pi->hw, vsi_handle))
  2346. return ICE_ERR_PARAM;
  2347. mutex_lock(&pi->sched_lock);
  2348. for (i = 0; i < ICE_MAX_TRAFFIC_CLASS; i++) {
  2349. /* configuration is possible only if TC node is present */
  2350. if (!ice_sched_get_tc_node(pi, i))
  2351. continue;
  2352. status = ice_sched_cfg_vsi(pi, vsi_handle, i, maxqs[i], owner,
  2353. ice_is_tc_ena(tc_bitmap, i));
  2354. if (status)
  2355. break;
  2356. }
  2357. mutex_unlock(&pi->sched_lock);
  2358. return status;
  2359. }
  2360. /**
  2361. * ice_cfg_vsi_lan - configure VSI lan queues
  2362. * @pi: port information structure
  2363. * @vsi_handle: software VSI handle
  2364. * @tc_bitmap: TC bitmap
  2365. * @max_lanqs: max lan queues array per TC
  2366. *
  2367. * This function adds/updates the VSI lan queues per TC.
  2368. */
  2369. enum ice_status
  2370. ice_cfg_vsi_lan(struct ice_port_info *pi, u16 vsi_handle, u8 tc_bitmap,
  2371. u16 *max_lanqs)
  2372. {
  2373. return ice_cfg_vsi_qs(pi, vsi_handle, tc_bitmap, max_lanqs,
  2374. ICE_SCHED_NODE_OWNER_LAN);
  2375. }
  2376. /**
  2377. * ice_replay_pre_init - replay pre initialization
  2378. * @hw: pointer to the hw struct
  2379. *
  2380. * Initializes required config data for VSI, FD, ACL, and RSS before replay.
  2381. */
  2382. static enum ice_status ice_replay_pre_init(struct ice_hw *hw)
  2383. {
  2384. struct ice_switch_info *sw = hw->switch_info;
  2385. u8 i;
  2386. /* Delete old entries from replay filter list head if there is any */
  2387. ice_rm_all_sw_replay_rule_info(hw);
  2388. /* In start of replay, move entries into replay_rules list, it
  2389. * will allow adding rules entries back to filt_rules list,
  2390. * which is operational list.
  2391. */
  2392. for (i = 0; i < ICE_SW_LKUP_LAST; i++)
  2393. list_replace_init(&sw->recp_list[i].filt_rules,
  2394. &sw->recp_list[i].filt_replay_rules);
  2395. return 0;
  2396. }
  2397. /**
  2398. * ice_replay_vsi - replay VSI configuration
  2399. * @hw: pointer to the hw struct
  2400. * @vsi_handle: driver VSI handle
  2401. *
  2402. * Restore all VSI configuration after reset. It is required to call this
  2403. * function with main VSI first.
  2404. */
  2405. enum ice_status ice_replay_vsi(struct ice_hw *hw, u16 vsi_handle)
  2406. {
  2407. enum ice_status status;
  2408. if (!ice_is_vsi_valid(hw, vsi_handle))
  2409. return ICE_ERR_PARAM;
  2410. /* Replay pre-initialization if there is any */
  2411. if (vsi_handle == ICE_MAIN_VSI_HANDLE) {
  2412. status = ice_replay_pre_init(hw);
  2413. if (status)
  2414. return status;
  2415. }
  2416. /* Replay per VSI all filters */
  2417. status = ice_replay_vsi_all_fltr(hw, vsi_handle);
  2418. return status;
  2419. }
  2420. /**
  2421. * ice_replay_post - post replay configuration cleanup
  2422. * @hw: pointer to the hw struct
  2423. *
  2424. * Post replay cleanup.
  2425. */
  2426. void ice_replay_post(struct ice_hw *hw)
  2427. {
  2428. /* Delete old entries from replay filter list head */
  2429. ice_rm_all_sw_replay_rule_info(hw);
  2430. }
  2431. /**
  2432. * ice_stat_update40 - read 40 bit stat from the chip and update stat values
  2433. * @hw: ptr to the hardware info
  2434. * @hireg: high 32 bit HW register to read from
  2435. * @loreg: low 32 bit HW register to read from
  2436. * @prev_stat_loaded: bool to specify if previous stats are loaded
  2437. * @prev_stat: ptr to previous loaded stat value
  2438. * @cur_stat: ptr to current stat value
  2439. */
  2440. void ice_stat_update40(struct ice_hw *hw, u32 hireg, u32 loreg,
  2441. bool prev_stat_loaded, u64 *prev_stat, u64 *cur_stat)
  2442. {
  2443. u64 new_data;
  2444. new_data = rd32(hw, loreg);
  2445. new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
  2446. /* device stats are not reset at PFR, they likely will not be zeroed
  2447. * when the driver starts. So save the first values read and use them as
  2448. * offsets to be subtracted from the raw values in order to report stats
  2449. * that count from zero.
  2450. */
  2451. if (!prev_stat_loaded)
  2452. *prev_stat = new_data;
  2453. if (new_data >= *prev_stat)
  2454. *cur_stat = new_data - *prev_stat;
  2455. else
  2456. /* to manage the potential roll-over */
  2457. *cur_stat = (new_data + BIT_ULL(40)) - *prev_stat;
  2458. *cur_stat &= 0xFFFFFFFFFFULL;
  2459. }
  2460. /**
  2461. * ice_stat_update32 - read 32 bit stat from the chip and update stat values
  2462. * @hw: ptr to the hardware info
  2463. * @reg: HW register to read from
  2464. * @prev_stat_loaded: bool to specify if previous stats are loaded
  2465. * @prev_stat: ptr to previous loaded stat value
  2466. * @cur_stat: ptr to current stat value
  2467. */
  2468. void ice_stat_update32(struct ice_hw *hw, u32 reg, bool prev_stat_loaded,
  2469. u64 *prev_stat, u64 *cur_stat)
  2470. {
  2471. u32 new_data;
  2472. new_data = rd32(hw, reg);
  2473. /* device stats are not reset at PFR, they likely will not be zeroed
  2474. * when the driver starts. So save the first values read and use them as
  2475. * offsets to be subtracted from the raw values in order to report stats
  2476. * that count from zero.
  2477. */
  2478. if (!prev_stat_loaded)
  2479. *prev_stat = new_data;
  2480. if (new_data >= *prev_stat)
  2481. *cur_stat = new_data - *prev_stat;
  2482. else
  2483. /* to manage the potential roll-over */
  2484. *cur_stat = (new_data + BIT_ULL(32)) - *prev_stat;
  2485. }