ice_common.c 77 KB

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