ice_common.c 79 KB

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