ice_common.c 82 KB

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