ice_common.c 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235
  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_NIC_FLX_ENTRY(hw, mdid, idx) \
  8. wr32((hw), GLFLXP_RXDID_FLX_WRD_##idx(ICE_RXDID_FLEX_NIC), \
  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_NIC_FLX_FLG_ENTRY(hw, flg_0, flg_1, flg_2, flg_3, idx) \
  15. wr32((hw), GLFLXP_RXDID_FLAGS(ICE_RXDID_FLEX_NIC, 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. enum ice_status ice_clear_pf_cfg(struct ice_hw *hw)
  43. {
  44. struct ice_aq_desc desc;
  45. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_clear_pf_cfg);
  46. return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  47. }
  48. /**
  49. * ice_aq_manage_mac_read - manage MAC address read command
  50. * @hw: pointer to the hw struct
  51. * @buf: a virtual buffer to hold the manage MAC read response
  52. * @buf_size: Size of the virtual buffer
  53. * @cd: pointer to command details structure or NULL
  54. *
  55. * This function is used to return per PF station MAC address (0x0107).
  56. * NOTE: Upon successful completion of this command, MAC address information
  57. * is returned in user specified buffer. Please interpret user specified
  58. * buffer as "manage_mac_read" response.
  59. * Response such as various MAC addresses are stored in HW struct (port.mac)
  60. * ice_aq_discover_caps is expected to be called before this function is called.
  61. */
  62. static enum ice_status
  63. ice_aq_manage_mac_read(struct ice_hw *hw, void *buf, u16 buf_size,
  64. struct ice_sq_cd *cd)
  65. {
  66. struct ice_aqc_manage_mac_read_resp *resp;
  67. struct ice_aqc_manage_mac_read *cmd;
  68. struct ice_aq_desc desc;
  69. enum ice_status status;
  70. u16 flags;
  71. cmd = &desc.params.mac_read;
  72. if (buf_size < sizeof(*resp))
  73. return ICE_ERR_BUF_TOO_SHORT;
  74. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_manage_mac_read);
  75. status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
  76. if (status)
  77. return status;
  78. resp = (struct ice_aqc_manage_mac_read_resp *)buf;
  79. flags = le16_to_cpu(cmd->flags) & ICE_AQC_MAN_MAC_READ_M;
  80. if (!(flags & ICE_AQC_MAN_MAC_LAN_ADDR_VALID)) {
  81. ice_debug(hw, ICE_DBG_LAN, "got invalid MAC address\n");
  82. return ICE_ERR_CFG;
  83. }
  84. ether_addr_copy(hw->port_info->mac.lan_addr, resp->mac_addr);
  85. ether_addr_copy(hw->port_info->mac.perm_addr, resp->mac_addr);
  86. return 0;
  87. }
  88. /**
  89. * ice_aq_get_phy_caps - returns PHY capabilities
  90. * @pi: port information structure
  91. * @qual_mods: report qualified modules
  92. * @report_mode: report mode capabilities
  93. * @pcaps: structure for PHY capabilities to be filled
  94. * @cd: pointer to command details structure or NULL
  95. *
  96. * Returns the various PHY capabilities supported on the Port (0x0600)
  97. */
  98. static enum ice_status
  99. ice_aq_get_phy_caps(struct ice_port_info *pi, bool qual_mods, u8 report_mode,
  100. struct ice_aqc_get_phy_caps_data *pcaps,
  101. struct ice_sq_cd *cd)
  102. {
  103. struct ice_aqc_get_phy_caps *cmd;
  104. u16 pcaps_size = sizeof(*pcaps);
  105. struct ice_aq_desc desc;
  106. enum ice_status status;
  107. cmd = &desc.params.get_phy;
  108. if (!pcaps || (report_mode & ~ICE_AQC_REPORT_MODE_M) || !pi)
  109. return ICE_ERR_PARAM;
  110. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_phy_caps);
  111. if (qual_mods)
  112. cmd->param0 |= cpu_to_le16(ICE_AQC_GET_PHY_RQM);
  113. cmd->param0 |= cpu_to_le16(report_mode);
  114. status = ice_aq_send_cmd(pi->hw, &desc, pcaps, pcaps_size, cd);
  115. if (!status && report_mode == ICE_AQC_REPORT_TOPO_CAP)
  116. pi->phy.phy_type_low = le64_to_cpu(pcaps->phy_type_low);
  117. return status;
  118. }
  119. /**
  120. * ice_get_media_type - Gets media type
  121. * @pi: port information structure
  122. */
  123. static enum ice_media_type ice_get_media_type(struct ice_port_info *pi)
  124. {
  125. struct ice_link_status *hw_link_info;
  126. if (!pi)
  127. return ICE_MEDIA_UNKNOWN;
  128. hw_link_info = &pi->phy.link_info;
  129. if (hw_link_info->phy_type_low) {
  130. switch (hw_link_info->phy_type_low) {
  131. case ICE_PHY_TYPE_LOW_1000BASE_SX:
  132. case ICE_PHY_TYPE_LOW_1000BASE_LX:
  133. case ICE_PHY_TYPE_LOW_10GBASE_SR:
  134. case ICE_PHY_TYPE_LOW_10GBASE_LR:
  135. case ICE_PHY_TYPE_LOW_10G_SFI_C2C:
  136. case ICE_PHY_TYPE_LOW_25GBASE_SR:
  137. case ICE_PHY_TYPE_LOW_25GBASE_LR:
  138. case ICE_PHY_TYPE_LOW_25G_AUI_C2C:
  139. case ICE_PHY_TYPE_LOW_40GBASE_SR4:
  140. case ICE_PHY_TYPE_LOW_40GBASE_LR4:
  141. return ICE_MEDIA_FIBER;
  142. case ICE_PHY_TYPE_LOW_100BASE_TX:
  143. case ICE_PHY_TYPE_LOW_1000BASE_T:
  144. case ICE_PHY_TYPE_LOW_2500BASE_T:
  145. case ICE_PHY_TYPE_LOW_5GBASE_T:
  146. case ICE_PHY_TYPE_LOW_10GBASE_T:
  147. case ICE_PHY_TYPE_LOW_25GBASE_T:
  148. return ICE_MEDIA_BASET;
  149. case ICE_PHY_TYPE_LOW_10G_SFI_DA:
  150. case ICE_PHY_TYPE_LOW_25GBASE_CR:
  151. case ICE_PHY_TYPE_LOW_25GBASE_CR_S:
  152. case ICE_PHY_TYPE_LOW_25GBASE_CR1:
  153. case ICE_PHY_TYPE_LOW_40GBASE_CR4:
  154. return ICE_MEDIA_DA;
  155. case ICE_PHY_TYPE_LOW_1000BASE_KX:
  156. case ICE_PHY_TYPE_LOW_2500BASE_KX:
  157. case ICE_PHY_TYPE_LOW_2500BASE_X:
  158. case ICE_PHY_TYPE_LOW_5GBASE_KR:
  159. case ICE_PHY_TYPE_LOW_10GBASE_KR_CR1:
  160. case ICE_PHY_TYPE_LOW_25GBASE_KR:
  161. case ICE_PHY_TYPE_LOW_25GBASE_KR1:
  162. case ICE_PHY_TYPE_LOW_25GBASE_KR_S:
  163. case ICE_PHY_TYPE_LOW_40GBASE_KR4:
  164. return ICE_MEDIA_BACKPLANE;
  165. }
  166. }
  167. return ICE_MEDIA_UNKNOWN;
  168. }
  169. /**
  170. * ice_aq_get_link_info
  171. * @pi: port information structure
  172. * @ena_lse: enable/disable LinkStatusEvent reporting
  173. * @link: pointer to link status structure - optional
  174. * @cd: pointer to command details structure or NULL
  175. *
  176. * Get Link Status (0x607). Returns the link status of the adapter.
  177. */
  178. enum ice_status
  179. ice_aq_get_link_info(struct ice_port_info *pi, bool ena_lse,
  180. struct ice_link_status *link, struct ice_sq_cd *cd)
  181. {
  182. struct ice_link_status *hw_link_info_old, *hw_link_info;
  183. struct ice_aqc_get_link_status_data link_data = { 0 };
  184. struct ice_aqc_get_link_status *resp;
  185. enum ice_media_type *hw_media_type;
  186. struct ice_fc_info *hw_fc_info;
  187. bool tx_pause, rx_pause;
  188. struct ice_aq_desc desc;
  189. enum ice_status status;
  190. u16 cmd_flags;
  191. if (!pi)
  192. return ICE_ERR_PARAM;
  193. hw_link_info_old = &pi->phy.link_info_old;
  194. hw_media_type = &pi->phy.media_type;
  195. hw_link_info = &pi->phy.link_info;
  196. hw_fc_info = &pi->fc;
  197. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_link_status);
  198. cmd_flags = (ena_lse) ? ICE_AQ_LSE_ENA : ICE_AQ_LSE_DIS;
  199. resp = &desc.params.get_link_status;
  200. resp->cmd_flags = cpu_to_le16(cmd_flags);
  201. resp->lport_num = pi->lport;
  202. status = ice_aq_send_cmd(pi->hw, &desc, &link_data, sizeof(link_data),
  203. cd);
  204. if (status)
  205. return status;
  206. /* save off old link status information */
  207. *hw_link_info_old = *hw_link_info;
  208. /* update current link status information */
  209. hw_link_info->link_speed = le16_to_cpu(link_data.link_speed);
  210. hw_link_info->phy_type_low = le64_to_cpu(link_data.phy_type_low);
  211. *hw_media_type = ice_get_media_type(pi);
  212. hw_link_info->link_info = link_data.link_info;
  213. hw_link_info->an_info = link_data.an_info;
  214. hw_link_info->ext_info = link_data.ext_info;
  215. hw_link_info->max_frame_size = le16_to_cpu(link_data.max_frame_size);
  216. hw_link_info->pacing = link_data.cfg & ICE_AQ_CFG_PACING_M;
  217. /* update fc info */
  218. tx_pause = !!(link_data.an_info & ICE_AQ_LINK_PAUSE_TX);
  219. rx_pause = !!(link_data.an_info & ICE_AQ_LINK_PAUSE_RX);
  220. if (tx_pause && rx_pause)
  221. hw_fc_info->current_mode = ICE_FC_FULL;
  222. else if (tx_pause)
  223. hw_fc_info->current_mode = ICE_FC_TX_PAUSE;
  224. else if (rx_pause)
  225. hw_fc_info->current_mode = ICE_FC_RX_PAUSE;
  226. else
  227. hw_fc_info->current_mode = ICE_FC_NONE;
  228. hw_link_info->lse_ena =
  229. !!(resp->cmd_flags & cpu_to_le16(ICE_AQ_LSE_IS_ENABLED));
  230. /* save link status information */
  231. if (link)
  232. *link = *hw_link_info;
  233. /* flag cleared so calling functions don't call AQ again */
  234. pi->phy.get_link_info = false;
  235. return status;
  236. }
  237. /**
  238. * ice_init_flex_parser - initialize rx flex parser
  239. * @hw: pointer to the hardware structure
  240. *
  241. * Function to initialize flex descriptors
  242. */
  243. static void ice_init_flex_parser(struct ice_hw *hw)
  244. {
  245. u8 idx = 0;
  246. ICE_NIC_FLX_ENTRY(hw, ICE_RX_MDID_HASH_LOW, 0);
  247. ICE_NIC_FLX_ENTRY(hw, ICE_RX_MDID_HASH_HIGH, 1);
  248. ICE_NIC_FLX_ENTRY(hw, ICE_RX_MDID_FLOW_ID_LOWER, 2);
  249. ICE_NIC_FLX_ENTRY(hw, ICE_RX_MDID_FLOW_ID_HIGH, 3);
  250. ICE_NIC_FLX_FLG_ENTRY(hw, ICE_RXFLG_PKT_FRG, ICE_RXFLG_UDP_GRE,
  251. ICE_RXFLG_PKT_DSI, ICE_RXFLG_FIN, idx++);
  252. ICE_NIC_FLX_FLG_ENTRY(hw, ICE_RXFLG_SYN, ICE_RXFLG_RST,
  253. ICE_RXFLG_PKT_DSI, ICE_RXFLG_PKT_DSI, idx++);
  254. ICE_NIC_FLX_FLG_ENTRY(hw, ICE_RXFLG_PKT_DSI, ICE_RXFLG_PKT_DSI,
  255. ICE_RXFLG_EVLAN_x8100, ICE_RXFLG_EVLAN_x9100,
  256. idx++);
  257. ICE_NIC_FLX_FLG_ENTRY(hw, ICE_RXFLG_VLAN_x8100, ICE_RXFLG_TNL_VLAN,
  258. ICE_RXFLG_TNL_MAC, ICE_RXFLG_TNL0, idx++);
  259. ICE_NIC_FLX_FLG_ENTRY(hw, ICE_RXFLG_TNL1, ICE_RXFLG_TNL2,
  260. ICE_RXFLG_PKT_DSI, ICE_RXFLG_PKT_DSI, idx);
  261. }
  262. /**
  263. * ice_init_fltr_mgmt_struct - initializes filter management list and locks
  264. * @hw: pointer to the hw struct
  265. */
  266. static enum ice_status ice_init_fltr_mgmt_struct(struct ice_hw *hw)
  267. {
  268. struct ice_switch_info *sw;
  269. hw->switch_info = devm_kzalloc(ice_hw_to_dev(hw),
  270. sizeof(*hw->switch_info), GFP_KERNEL);
  271. sw = hw->switch_info;
  272. if (!sw)
  273. return ICE_ERR_NO_MEMORY;
  274. INIT_LIST_HEAD(&sw->vsi_list_map_head);
  275. mutex_init(&sw->mac_list_lock);
  276. INIT_LIST_HEAD(&sw->mac_list_head);
  277. mutex_init(&sw->vlan_list_lock);
  278. INIT_LIST_HEAD(&sw->vlan_list_head);
  279. mutex_init(&sw->eth_m_list_lock);
  280. INIT_LIST_HEAD(&sw->eth_m_list_head);
  281. mutex_init(&sw->promisc_list_lock);
  282. INIT_LIST_HEAD(&sw->promisc_list_head);
  283. mutex_init(&sw->mac_vlan_list_lock);
  284. INIT_LIST_HEAD(&sw->mac_vlan_list_head);
  285. return 0;
  286. }
  287. /**
  288. * ice_cleanup_fltr_mgmt_struct - cleanup filter management list and locks
  289. * @hw: pointer to the hw struct
  290. */
  291. static void ice_cleanup_fltr_mgmt_struct(struct ice_hw *hw)
  292. {
  293. struct ice_switch_info *sw = hw->switch_info;
  294. struct ice_vsi_list_map_info *v_pos_map;
  295. struct ice_vsi_list_map_info *v_tmp_map;
  296. list_for_each_entry_safe(v_pos_map, v_tmp_map, &sw->vsi_list_map_head,
  297. list_entry) {
  298. list_del(&v_pos_map->list_entry);
  299. devm_kfree(ice_hw_to_dev(hw), v_pos_map);
  300. }
  301. mutex_destroy(&sw->mac_list_lock);
  302. mutex_destroy(&sw->vlan_list_lock);
  303. mutex_destroy(&sw->eth_m_list_lock);
  304. mutex_destroy(&sw->promisc_list_lock);
  305. mutex_destroy(&sw->mac_vlan_list_lock);
  306. devm_kfree(ice_hw_to_dev(hw), sw);
  307. }
  308. /**
  309. * ice_init_hw - main hardware initialization routine
  310. * @hw: pointer to the hardware structure
  311. */
  312. enum ice_status ice_init_hw(struct ice_hw *hw)
  313. {
  314. struct ice_aqc_get_phy_caps_data *pcaps;
  315. enum ice_status status;
  316. u16 mac_buf_len;
  317. void *mac_buf;
  318. /* Set MAC type based on DeviceID */
  319. status = ice_set_mac_type(hw);
  320. if (status)
  321. return status;
  322. hw->pf_id = (u8)(rd32(hw, PF_FUNC_RID) &
  323. PF_FUNC_RID_FUNC_NUM_M) >>
  324. PF_FUNC_RID_FUNC_NUM_S;
  325. status = ice_reset(hw, ICE_RESET_PFR);
  326. if (status)
  327. return status;
  328. /* set these values to minimum allowed */
  329. hw->itr_gran_200 = ICE_ITR_GRAN_MIN_200;
  330. hw->itr_gran_100 = ICE_ITR_GRAN_MIN_100;
  331. hw->itr_gran_50 = ICE_ITR_GRAN_MIN_50;
  332. hw->itr_gran_25 = ICE_ITR_GRAN_MIN_25;
  333. status = ice_init_all_ctrlq(hw);
  334. if (status)
  335. goto err_unroll_cqinit;
  336. status = ice_clear_pf_cfg(hw);
  337. if (status)
  338. goto err_unroll_cqinit;
  339. ice_clear_pxe_mode(hw);
  340. status = ice_init_nvm(hw);
  341. if (status)
  342. goto err_unroll_cqinit;
  343. status = ice_get_caps(hw);
  344. if (status)
  345. goto err_unroll_cqinit;
  346. hw->port_info = devm_kzalloc(ice_hw_to_dev(hw),
  347. sizeof(*hw->port_info), GFP_KERNEL);
  348. if (!hw->port_info) {
  349. status = ICE_ERR_NO_MEMORY;
  350. goto err_unroll_cqinit;
  351. }
  352. /* set the back pointer to hw */
  353. hw->port_info->hw = hw;
  354. /* Initialize port_info struct with switch configuration data */
  355. status = ice_get_initial_sw_cfg(hw);
  356. if (status)
  357. goto err_unroll_alloc;
  358. hw->evb_veb = true;
  359. /* Query the allocated resources for tx scheduler */
  360. status = ice_sched_query_res_alloc(hw);
  361. if (status) {
  362. ice_debug(hw, ICE_DBG_SCHED,
  363. "Failed to get scheduler allocated resources\n");
  364. goto err_unroll_alloc;
  365. }
  366. /* Initialize port_info struct with scheduler data */
  367. status = ice_sched_init_port(hw->port_info);
  368. if (status)
  369. goto err_unroll_sched;
  370. pcaps = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*pcaps), GFP_KERNEL);
  371. if (!pcaps) {
  372. status = ICE_ERR_NO_MEMORY;
  373. goto err_unroll_sched;
  374. }
  375. /* Initialize port_info struct with PHY capabilities */
  376. status = ice_aq_get_phy_caps(hw->port_info, false,
  377. ICE_AQC_REPORT_TOPO_CAP, pcaps, NULL);
  378. devm_kfree(ice_hw_to_dev(hw), pcaps);
  379. if (status)
  380. goto err_unroll_sched;
  381. /* Initialize port_info struct with link information */
  382. status = ice_aq_get_link_info(hw->port_info, false, NULL, NULL);
  383. if (status)
  384. goto err_unroll_sched;
  385. status = ice_init_fltr_mgmt_struct(hw);
  386. if (status)
  387. goto err_unroll_sched;
  388. /* Get port MAC information */
  389. mac_buf_len = sizeof(struct ice_aqc_manage_mac_read_resp);
  390. mac_buf = devm_kzalloc(ice_hw_to_dev(hw), mac_buf_len, GFP_KERNEL);
  391. if (!mac_buf) {
  392. status = ICE_ERR_NO_MEMORY;
  393. goto err_unroll_fltr_mgmt_struct;
  394. }
  395. status = ice_aq_manage_mac_read(hw, mac_buf, mac_buf_len, NULL);
  396. devm_kfree(ice_hw_to_dev(hw), mac_buf);
  397. if (status)
  398. goto err_unroll_fltr_mgmt_struct;
  399. ice_init_flex_parser(hw);
  400. return 0;
  401. err_unroll_fltr_mgmt_struct:
  402. ice_cleanup_fltr_mgmt_struct(hw);
  403. err_unroll_sched:
  404. ice_sched_cleanup_all(hw);
  405. err_unroll_alloc:
  406. devm_kfree(ice_hw_to_dev(hw), hw->port_info);
  407. err_unroll_cqinit:
  408. ice_shutdown_all_ctrlq(hw);
  409. return status;
  410. }
  411. /**
  412. * ice_deinit_hw - unroll initialization operations done by ice_init_hw
  413. * @hw: pointer to the hardware structure
  414. */
  415. void ice_deinit_hw(struct ice_hw *hw)
  416. {
  417. ice_sched_cleanup_all(hw);
  418. ice_shutdown_all_ctrlq(hw);
  419. if (hw->port_info) {
  420. devm_kfree(ice_hw_to_dev(hw), hw->port_info);
  421. hw->port_info = NULL;
  422. }
  423. ice_cleanup_fltr_mgmt_struct(hw);
  424. }
  425. /**
  426. * ice_check_reset - Check to see if a global reset is complete
  427. * @hw: pointer to the hardware structure
  428. */
  429. enum ice_status ice_check_reset(struct ice_hw *hw)
  430. {
  431. u32 cnt, reg = 0, grst_delay;
  432. /* Poll for Device Active state in case a recent CORER, GLOBR,
  433. * or EMPR has occurred. The grst delay value is in 100ms units.
  434. * Add 1sec for outstanding AQ commands that can take a long time.
  435. */
  436. grst_delay = ((rd32(hw, GLGEN_RSTCTL) & GLGEN_RSTCTL_GRSTDEL_M) >>
  437. GLGEN_RSTCTL_GRSTDEL_S) + 10;
  438. for (cnt = 0; cnt < grst_delay; cnt++) {
  439. mdelay(100);
  440. reg = rd32(hw, GLGEN_RSTAT);
  441. if (!(reg & GLGEN_RSTAT_DEVSTATE_M))
  442. break;
  443. }
  444. if (cnt == grst_delay) {
  445. ice_debug(hw, ICE_DBG_INIT,
  446. "Global reset polling failed to complete.\n");
  447. return ICE_ERR_RESET_FAILED;
  448. }
  449. #define ICE_RESET_DONE_MASK (GLNVM_ULD_CORER_DONE_M | \
  450. GLNVM_ULD_GLOBR_DONE_M)
  451. /* Device is Active; check Global Reset processes are done */
  452. for (cnt = 0; cnt < ICE_PF_RESET_WAIT_COUNT; cnt++) {
  453. reg = rd32(hw, GLNVM_ULD) & ICE_RESET_DONE_MASK;
  454. if (reg == ICE_RESET_DONE_MASK) {
  455. ice_debug(hw, ICE_DBG_INIT,
  456. "Global reset processes done. %d\n", cnt);
  457. break;
  458. }
  459. mdelay(10);
  460. }
  461. if (cnt == ICE_PF_RESET_WAIT_COUNT) {
  462. ice_debug(hw, ICE_DBG_INIT,
  463. "Wait for Reset Done timed out. GLNVM_ULD = 0x%x\n",
  464. reg);
  465. return ICE_ERR_RESET_FAILED;
  466. }
  467. return 0;
  468. }
  469. /**
  470. * ice_pf_reset - Reset the PF
  471. * @hw: pointer to the hardware structure
  472. *
  473. * If a global reset has been triggered, this function checks
  474. * for its completion and then issues the PF reset
  475. */
  476. static enum ice_status ice_pf_reset(struct ice_hw *hw)
  477. {
  478. u32 cnt, reg;
  479. /* If at function entry a global reset was already in progress, i.e.
  480. * state is not 'device active' or any of the reset done bits are not
  481. * set in GLNVM_ULD, there is no need for a PF Reset; poll until the
  482. * global reset is done.
  483. */
  484. if ((rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_DEVSTATE_M) ||
  485. (rd32(hw, GLNVM_ULD) & ICE_RESET_DONE_MASK) ^ ICE_RESET_DONE_MASK) {
  486. /* poll on global reset currently in progress until done */
  487. if (ice_check_reset(hw))
  488. return ICE_ERR_RESET_FAILED;
  489. return 0;
  490. }
  491. /* Reset the PF */
  492. reg = rd32(hw, PFGEN_CTRL);
  493. wr32(hw, PFGEN_CTRL, (reg | PFGEN_CTRL_PFSWR_M));
  494. for (cnt = 0; cnt < ICE_PF_RESET_WAIT_COUNT; cnt++) {
  495. reg = rd32(hw, PFGEN_CTRL);
  496. if (!(reg & PFGEN_CTRL_PFSWR_M))
  497. break;
  498. mdelay(1);
  499. }
  500. if (cnt == ICE_PF_RESET_WAIT_COUNT) {
  501. ice_debug(hw, ICE_DBG_INIT,
  502. "PF reset polling failed to complete.\n");
  503. return ICE_ERR_RESET_FAILED;
  504. }
  505. return 0;
  506. }
  507. /**
  508. * ice_reset - Perform different types of reset
  509. * @hw: pointer to the hardware structure
  510. * @req: reset request
  511. *
  512. * This function triggers a reset as specified by the req parameter.
  513. *
  514. * Note:
  515. * If anything other than a PF reset is triggered, PXE mode is restored.
  516. * This has to be cleared using ice_clear_pxe_mode again, once the AQ
  517. * interface has been restored in the rebuild flow.
  518. */
  519. enum ice_status ice_reset(struct ice_hw *hw, enum ice_reset_req req)
  520. {
  521. u32 val = 0;
  522. switch (req) {
  523. case ICE_RESET_PFR:
  524. return ice_pf_reset(hw);
  525. case ICE_RESET_CORER:
  526. ice_debug(hw, ICE_DBG_INIT, "CoreR requested\n");
  527. val = GLGEN_RTRIG_CORER_M;
  528. break;
  529. case ICE_RESET_GLOBR:
  530. ice_debug(hw, ICE_DBG_INIT, "GlobalR requested\n");
  531. val = GLGEN_RTRIG_GLOBR_M;
  532. break;
  533. }
  534. val |= rd32(hw, GLGEN_RTRIG);
  535. wr32(hw, GLGEN_RTRIG, val);
  536. ice_flush(hw);
  537. /* wait for the FW to be ready */
  538. return ice_check_reset(hw);
  539. }
  540. /**
  541. * ice_copy_rxq_ctx_to_hw
  542. * @hw: pointer to the hardware structure
  543. * @ice_rxq_ctx: pointer to the rxq context
  544. * @rxq_index: the index of the rx queue
  545. *
  546. * Copies rxq context from dense structure to hw register space
  547. */
  548. static enum ice_status
  549. ice_copy_rxq_ctx_to_hw(struct ice_hw *hw, u8 *ice_rxq_ctx, u32 rxq_index)
  550. {
  551. u8 i;
  552. if (!ice_rxq_ctx)
  553. return ICE_ERR_BAD_PTR;
  554. if (rxq_index > QRX_CTRL_MAX_INDEX)
  555. return ICE_ERR_PARAM;
  556. /* Copy each dword separately to hw */
  557. for (i = 0; i < ICE_RXQ_CTX_SIZE_DWORDS; i++) {
  558. wr32(hw, QRX_CONTEXT(i, rxq_index),
  559. *((u32 *)(ice_rxq_ctx + (i * sizeof(u32)))));
  560. ice_debug(hw, ICE_DBG_QCTX, "qrxdata[%d]: %08X\n", i,
  561. *((u32 *)(ice_rxq_ctx + (i * sizeof(u32)))));
  562. }
  563. return 0;
  564. }
  565. /* LAN Rx Queue Context */
  566. static const struct ice_ctx_ele ice_rlan_ctx_info[] = {
  567. /* Field Width LSB */
  568. ICE_CTX_STORE(ice_rlan_ctx, head, 13, 0),
  569. ICE_CTX_STORE(ice_rlan_ctx, cpuid, 8, 13),
  570. ICE_CTX_STORE(ice_rlan_ctx, base, 57, 32),
  571. ICE_CTX_STORE(ice_rlan_ctx, qlen, 13, 89),
  572. ICE_CTX_STORE(ice_rlan_ctx, dbuf, 7, 102),
  573. ICE_CTX_STORE(ice_rlan_ctx, hbuf, 5, 109),
  574. ICE_CTX_STORE(ice_rlan_ctx, dtype, 2, 114),
  575. ICE_CTX_STORE(ice_rlan_ctx, dsize, 1, 116),
  576. ICE_CTX_STORE(ice_rlan_ctx, crcstrip, 1, 117),
  577. ICE_CTX_STORE(ice_rlan_ctx, l2tsel, 1, 119),
  578. ICE_CTX_STORE(ice_rlan_ctx, hsplit_0, 4, 120),
  579. ICE_CTX_STORE(ice_rlan_ctx, hsplit_1, 2, 124),
  580. ICE_CTX_STORE(ice_rlan_ctx, showiv, 1, 127),
  581. ICE_CTX_STORE(ice_rlan_ctx, rxmax, 14, 174),
  582. ICE_CTX_STORE(ice_rlan_ctx, tphrdesc_ena, 1, 193),
  583. ICE_CTX_STORE(ice_rlan_ctx, tphwdesc_ena, 1, 194),
  584. ICE_CTX_STORE(ice_rlan_ctx, tphdata_ena, 1, 195),
  585. ICE_CTX_STORE(ice_rlan_ctx, tphhead_ena, 1, 196),
  586. ICE_CTX_STORE(ice_rlan_ctx, lrxqthresh, 3, 198),
  587. { 0 }
  588. };
  589. /**
  590. * ice_write_rxq_ctx
  591. * @hw: pointer to the hardware structure
  592. * @rlan_ctx: pointer to the rxq context
  593. * @rxq_index: the index of the rx queue
  594. *
  595. * Converts rxq context from sparse to dense structure and then writes
  596. * it to hw register space
  597. */
  598. enum ice_status
  599. ice_write_rxq_ctx(struct ice_hw *hw, struct ice_rlan_ctx *rlan_ctx,
  600. u32 rxq_index)
  601. {
  602. u8 ctx_buf[ICE_RXQ_CTX_SZ] = { 0 };
  603. ice_set_ctx((u8 *)rlan_ctx, ctx_buf, ice_rlan_ctx_info);
  604. return ice_copy_rxq_ctx_to_hw(hw, ctx_buf, rxq_index);
  605. }
  606. /* LAN Tx Queue Context */
  607. const struct ice_ctx_ele ice_tlan_ctx_info[] = {
  608. /* Field Width LSB */
  609. ICE_CTX_STORE(ice_tlan_ctx, base, 57, 0),
  610. ICE_CTX_STORE(ice_tlan_ctx, port_num, 3, 57),
  611. ICE_CTX_STORE(ice_tlan_ctx, cgd_num, 5, 60),
  612. ICE_CTX_STORE(ice_tlan_ctx, pf_num, 3, 65),
  613. ICE_CTX_STORE(ice_tlan_ctx, vmvf_num, 10, 68),
  614. ICE_CTX_STORE(ice_tlan_ctx, vmvf_type, 2, 78),
  615. ICE_CTX_STORE(ice_tlan_ctx, src_vsi, 10, 80),
  616. ICE_CTX_STORE(ice_tlan_ctx, tsyn_ena, 1, 90),
  617. ICE_CTX_STORE(ice_tlan_ctx, alt_vlan, 1, 92),
  618. ICE_CTX_STORE(ice_tlan_ctx, cpuid, 8, 93),
  619. ICE_CTX_STORE(ice_tlan_ctx, wb_mode, 1, 101),
  620. ICE_CTX_STORE(ice_tlan_ctx, tphrd_desc, 1, 102),
  621. ICE_CTX_STORE(ice_tlan_ctx, tphrd, 1, 103),
  622. ICE_CTX_STORE(ice_tlan_ctx, tphwr_desc, 1, 104),
  623. ICE_CTX_STORE(ice_tlan_ctx, cmpq_id, 9, 105),
  624. ICE_CTX_STORE(ice_tlan_ctx, qnum_in_func, 14, 114),
  625. ICE_CTX_STORE(ice_tlan_ctx, itr_notification_mode, 1, 128),
  626. ICE_CTX_STORE(ice_tlan_ctx, adjust_prof_id, 6, 129),
  627. ICE_CTX_STORE(ice_tlan_ctx, qlen, 13, 135),
  628. ICE_CTX_STORE(ice_tlan_ctx, quanta_prof_idx, 4, 148),
  629. ICE_CTX_STORE(ice_tlan_ctx, tso_ena, 1, 152),
  630. ICE_CTX_STORE(ice_tlan_ctx, tso_qnum, 11, 153),
  631. ICE_CTX_STORE(ice_tlan_ctx, legacy_int, 1, 164),
  632. ICE_CTX_STORE(ice_tlan_ctx, drop_ena, 1, 165),
  633. ICE_CTX_STORE(ice_tlan_ctx, cache_prof_idx, 2, 166),
  634. ICE_CTX_STORE(ice_tlan_ctx, pkt_shaper_prof_idx, 3, 168),
  635. ICE_CTX_STORE(ice_tlan_ctx, int_q_state, 110, 171),
  636. { 0 }
  637. };
  638. /**
  639. * ice_debug_cq
  640. * @hw: pointer to the hardware structure
  641. * @mask: debug mask
  642. * @desc: pointer to control queue descriptor
  643. * @buf: pointer to command buffer
  644. * @buf_len: max length of buf
  645. *
  646. * Dumps debug log about control command with descriptor contents.
  647. */
  648. void ice_debug_cq(struct ice_hw *hw, u32 __maybe_unused mask, void *desc,
  649. void *buf, u16 buf_len)
  650. {
  651. struct ice_aq_desc *cq_desc = (struct ice_aq_desc *)desc;
  652. u16 len;
  653. #ifndef CONFIG_DYNAMIC_DEBUG
  654. if (!(mask & hw->debug_mask))
  655. return;
  656. #endif
  657. if (!desc)
  658. return;
  659. len = le16_to_cpu(cq_desc->datalen);
  660. ice_debug(hw, mask,
  661. "CQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
  662. le16_to_cpu(cq_desc->opcode),
  663. le16_to_cpu(cq_desc->flags),
  664. le16_to_cpu(cq_desc->datalen), le16_to_cpu(cq_desc->retval));
  665. ice_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
  666. le32_to_cpu(cq_desc->cookie_high),
  667. le32_to_cpu(cq_desc->cookie_low));
  668. ice_debug(hw, mask, "\tparam (0,1) 0x%08X 0x%08X\n",
  669. le32_to_cpu(cq_desc->params.generic.param0),
  670. le32_to_cpu(cq_desc->params.generic.param1));
  671. ice_debug(hw, mask, "\taddr (h,l) 0x%08X 0x%08X\n",
  672. le32_to_cpu(cq_desc->params.generic.addr_high),
  673. le32_to_cpu(cq_desc->params.generic.addr_low));
  674. if (buf && cq_desc->datalen != 0) {
  675. ice_debug(hw, mask, "Buffer:\n");
  676. if (buf_len < len)
  677. len = buf_len;
  678. ice_debug_array(hw, mask, 16, 1, (u8 *)buf, len);
  679. }
  680. }
  681. /* FW Admin Queue command wrappers */
  682. /**
  683. * ice_aq_send_cmd - send FW Admin Queue command to FW Admin Queue
  684. * @hw: pointer to the hw struct
  685. * @desc: descriptor describing the command
  686. * @buf: buffer to use for indirect commands (NULL for direct commands)
  687. * @buf_size: size of buffer for indirect commands (0 for direct commands)
  688. * @cd: pointer to command details structure
  689. *
  690. * Helper function to send FW Admin Queue commands to the FW Admin Queue.
  691. */
  692. enum ice_status
  693. ice_aq_send_cmd(struct ice_hw *hw, struct ice_aq_desc *desc, void *buf,
  694. u16 buf_size, struct ice_sq_cd *cd)
  695. {
  696. return ice_sq_send_cmd(hw, &hw->adminq, desc, buf, buf_size, cd);
  697. }
  698. /**
  699. * ice_aq_get_fw_ver
  700. * @hw: pointer to the hw struct
  701. * @cd: pointer to command details structure or NULL
  702. *
  703. * Get the firmware version (0x0001) from the admin queue commands
  704. */
  705. enum ice_status ice_aq_get_fw_ver(struct ice_hw *hw, struct ice_sq_cd *cd)
  706. {
  707. struct ice_aqc_get_ver *resp;
  708. struct ice_aq_desc desc;
  709. enum ice_status status;
  710. resp = &desc.params.get_ver;
  711. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_ver);
  712. status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
  713. if (!status) {
  714. hw->fw_branch = resp->fw_branch;
  715. hw->fw_maj_ver = resp->fw_major;
  716. hw->fw_min_ver = resp->fw_minor;
  717. hw->fw_patch = resp->fw_patch;
  718. hw->fw_build = le32_to_cpu(resp->fw_build);
  719. hw->api_branch = resp->api_branch;
  720. hw->api_maj_ver = resp->api_major;
  721. hw->api_min_ver = resp->api_minor;
  722. hw->api_patch = resp->api_patch;
  723. }
  724. return status;
  725. }
  726. /**
  727. * ice_aq_q_shutdown
  728. * @hw: pointer to the hw struct
  729. * @unloading: is the driver unloading itself
  730. *
  731. * Tell the Firmware that we're shutting down the AdminQ and whether
  732. * or not the driver is unloading as well (0x0003).
  733. */
  734. enum ice_status ice_aq_q_shutdown(struct ice_hw *hw, bool unloading)
  735. {
  736. struct ice_aqc_q_shutdown *cmd;
  737. struct ice_aq_desc desc;
  738. cmd = &desc.params.q_shutdown;
  739. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_q_shutdown);
  740. if (unloading)
  741. cmd->driver_unloading = cpu_to_le32(ICE_AQC_DRIVER_UNLOADING);
  742. return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  743. }
  744. /**
  745. * ice_aq_req_res
  746. * @hw: pointer to the hw struct
  747. * @res: resource id
  748. * @access: access type
  749. * @sdp_number: resource number
  750. * @timeout: the maximum time in ms that the driver may hold the resource
  751. * @cd: pointer to command details structure or NULL
  752. *
  753. * requests common resource using the admin queue commands (0x0008)
  754. */
  755. static enum ice_status
  756. ice_aq_req_res(struct ice_hw *hw, enum ice_aq_res_ids res,
  757. enum ice_aq_res_access_type access, u8 sdp_number, u32 *timeout,
  758. struct ice_sq_cd *cd)
  759. {
  760. struct ice_aqc_req_res *cmd_resp;
  761. struct ice_aq_desc desc;
  762. enum ice_status status;
  763. cmd_resp = &desc.params.res_owner;
  764. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_req_res);
  765. cmd_resp->res_id = cpu_to_le16(res);
  766. cmd_resp->access_type = cpu_to_le16(access);
  767. cmd_resp->res_number = cpu_to_le32(sdp_number);
  768. status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
  769. /* The completion specifies the maximum time in ms that the driver
  770. * may hold the resource in the Timeout field.
  771. * If the resource is held by someone else, the command completes with
  772. * busy return value and the timeout field indicates the maximum time
  773. * the current owner of the resource has to free it.
  774. */
  775. if (!status || hw->adminq.sq_last_status == ICE_AQ_RC_EBUSY)
  776. *timeout = le32_to_cpu(cmd_resp->timeout);
  777. return status;
  778. }
  779. /**
  780. * ice_aq_release_res
  781. * @hw: pointer to the hw struct
  782. * @res: resource id
  783. * @sdp_number: resource number
  784. * @cd: pointer to command details structure or NULL
  785. *
  786. * release common resource using the admin queue commands (0x0009)
  787. */
  788. static enum ice_status
  789. ice_aq_release_res(struct ice_hw *hw, enum ice_aq_res_ids res, u8 sdp_number,
  790. struct ice_sq_cd *cd)
  791. {
  792. struct ice_aqc_req_res *cmd;
  793. struct ice_aq_desc desc;
  794. cmd = &desc.params.res_owner;
  795. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_release_res);
  796. cmd->res_id = cpu_to_le16(res);
  797. cmd->res_number = cpu_to_le32(sdp_number);
  798. return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
  799. }
  800. /**
  801. * ice_acquire_res
  802. * @hw: pointer to the HW structure
  803. * @res: resource id
  804. * @access: access type (read or write)
  805. *
  806. * This function will attempt to acquire the ownership of a resource.
  807. */
  808. enum ice_status
  809. ice_acquire_res(struct ice_hw *hw, enum ice_aq_res_ids res,
  810. enum ice_aq_res_access_type access)
  811. {
  812. #define ICE_RES_POLLING_DELAY_MS 10
  813. u32 delay = ICE_RES_POLLING_DELAY_MS;
  814. enum ice_status status;
  815. u32 time_left = 0;
  816. u32 timeout;
  817. status = ice_aq_req_res(hw, res, access, 0, &time_left, NULL);
  818. /* An admin queue return code of ICE_AQ_RC_EEXIST means that another
  819. * driver has previously acquired the resource and performed any
  820. * necessary updates; in this case the caller does not obtain the
  821. * resource and has no further work to do.
  822. */
  823. if (hw->adminq.sq_last_status == ICE_AQ_RC_EEXIST) {
  824. status = ICE_ERR_AQ_NO_WORK;
  825. goto ice_acquire_res_exit;
  826. }
  827. if (status)
  828. ice_debug(hw, ICE_DBG_RES,
  829. "resource %d acquire type %d failed.\n", res, access);
  830. /* If necessary, poll until the current lock owner timeouts */
  831. timeout = time_left;
  832. while (status && timeout && time_left) {
  833. mdelay(delay);
  834. timeout = (timeout > delay) ? timeout - delay : 0;
  835. status = ice_aq_req_res(hw, res, access, 0, &time_left, NULL);
  836. if (hw->adminq.sq_last_status == ICE_AQ_RC_EEXIST) {
  837. /* lock free, but no work to do */
  838. status = ICE_ERR_AQ_NO_WORK;
  839. break;
  840. }
  841. if (!status)
  842. /* lock acquired */
  843. break;
  844. }
  845. if (status && status != ICE_ERR_AQ_NO_WORK)
  846. ice_debug(hw, ICE_DBG_RES, "resource acquire timed out.\n");
  847. ice_acquire_res_exit:
  848. if (status == ICE_ERR_AQ_NO_WORK) {
  849. if (access == ICE_RES_WRITE)
  850. ice_debug(hw, ICE_DBG_RES,
  851. "resource indicates no work to do.\n");
  852. else
  853. ice_debug(hw, ICE_DBG_RES,
  854. "Warning: ICE_ERR_AQ_NO_WORK not expected\n");
  855. }
  856. return status;
  857. }
  858. /**
  859. * ice_release_res
  860. * @hw: pointer to the HW structure
  861. * @res: resource id
  862. *
  863. * This function will release a resource using the proper Admin Command.
  864. */
  865. void ice_release_res(struct ice_hw *hw, enum ice_aq_res_ids res)
  866. {
  867. enum ice_status status;
  868. u32 total_delay = 0;
  869. status = ice_aq_release_res(hw, res, 0, NULL);
  870. /* there are some rare cases when trying to release the resource
  871. * results in an admin Q timeout, so handle them correctly
  872. */
  873. while ((status == ICE_ERR_AQ_TIMEOUT) &&
  874. (total_delay < hw->adminq.sq_cmd_timeout)) {
  875. mdelay(1);
  876. status = ice_aq_release_res(hw, res, 0, NULL);
  877. total_delay++;
  878. }
  879. }
  880. /**
  881. * ice_parse_caps - parse function/device capabilities
  882. * @hw: pointer to the hw struct
  883. * @buf: pointer to a buffer containing function/device capability records
  884. * @cap_count: number of capability records in the list
  885. * @opc: type of capabilities list to parse
  886. *
  887. * Helper function to parse function(0x000a)/device(0x000b) capabilities list.
  888. */
  889. static void
  890. ice_parse_caps(struct ice_hw *hw, void *buf, u32 cap_count,
  891. enum ice_adminq_opc opc)
  892. {
  893. struct ice_aqc_list_caps_elem *cap_resp;
  894. struct ice_hw_func_caps *func_p = NULL;
  895. struct ice_hw_dev_caps *dev_p = NULL;
  896. struct ice_hw_common_caps *caps;
  897. u32 i;
  898. if (!buf)
  899. return;
  900. cap_resp = (struct ice_aqc_list_caps_elem *)buf;
  901. if (opc == ice_aqc_opc_list_dev_caps) {
  902. dev_p = &hw->dev_caps;
  903. caps = &dev_p->common_cap;
  904. } else if (opc == ice_aqc_opc_list_func_caps) {
  905. func_p = &hw->func_caps;
  906. caps = &func_p->common_cap;
  907. } else {
  908. ice_debug(hw, ICE_DBG_INIT, "wrong opcode\n");
  909. return;
  910. }
  911. for (i = 0; caps && i < cap_count; i++, cap_resp++) {
  912. u32 logical_id = le32_to_cpu(cap_resp->logical_id);
  913. u32 phys_id = le32_to_cpu(cap_resp->phys_id);
  914. u32 number = le32_to_cpu(cap_resp->number);
  915. u16 cap = le16_to_cpu(cap_resp->cap);
  916. switch (cap) {
  917. case ICE_AQC_CAPS_VSI:
  918. if (dev_p) {
  919. dev_p->num_vsi_allocd_to_host = number;
  920. ice_debug(hw, ICE_DBG_INIT,
  921. "HW caps: Dev.VSI cnt = %d\n",
  922. dev_p->num_vsi_allocd_to_host);
  923. } else if (func_p) {
  924. func_p->guaranteed_num_vsi = number;
  925. ice_debug(hw, ICE_DBG_INIT,
  926. "HW caps: Func.VSI cnt = %d\n",
  927. func_p->guaranteed_num_vsi);
  928. }
  929. break;
  930. case ICE_AQC_CAPS_RSS:
  931. caps->rss_table_size = number;
  932. caps->rss_table_entry_width = logical_id;
  933. ice_debug(hw, ICE_DBG_INIT,
  934. "HW caps: RSS table size = %d\n",
  935. caps->rss_table_size);
  936. ice_debug(hw, ICE_DBG_INIT,
  937. "HW caps: RSS table width = %d\n",
  938. caps->rss_table_entry_width);
  939. break;
  940. case ICE_AQC_CAPS_RXQS:
  941. caps->num_rxq = number;
  942. caps->rxq_first_id = phys_id;
  943. ice_debug(hw, ICE_DBG_INIT,
  944. "HW caps: Num Rx Qs = %d\n", caps->num_rxq);
  945. ice_debug(hw, ICE_DBG_INIT,
  946. "HW caps: Rx first queue ID = %d\n",
  947. caps->rxq_first_id);
  948. break;
  949. case ICE_AQC_CAPS_TXQS:
  950. caps->num_txq = number;
  951. caps->txq_first_id = phys_id;
  952. ice_debug(hw, ICE_DBG_INIT,
  953. "HW caps: Num Tx Qs = %d\n", caps->num_txq);
  954. ice_debug(hw, ICE_DBG_INIT,
  955. "HW caps: Tx first queue ID = %d\n",
  956. caps->txq_first_id);
  957. break;
  958. case ICE_AQC_CAPS_MSIX:
  959. caps->num_msix_vectors = number;
  960. caps->msix_vector_first_id = phys_id;
  961. ice_debug(hw, ICE_DBG_INIT,
  962. "HW caps: MSIX vector count = %d\n",
  963. caps->num_msix_vectors);
  964. ice_debug(hw, ICE_DBG_INIT,
  965. "HW caps: MSIX first vector index = %d\n",
  966. caps->msix_vector_first_id);
  967. break;
  968. case ICE_AQC_CAPS_MAX_MTU:
  969. caps->max_mtu = number;
  970. if (dev_p)
  971. ice_debug(hw, ICE_DBG_INIT,
  972. "HW caps: Dev.MaxMTU = %d\n",
  973. caps->max_mtu);
  974. else if (func_p)
  975. ice_debug(hw, ICE_DBG_INIT,
  976. "HW caps: func.MaxMTU = %d\n",
  977. caps->max_mtu);
  978. break;
  979. default:
  980. ice_debug(hw, ICE_DBG_INIT,
  981. "HW caps: Unknown capability[%d]: 0x%x\n", i,
  982. cap);
  983. break;
  984. }
  985. }
  986. }
  987. /**
  988. * ice_aq_discover_caps - query function/device capabilities
  989. * @hw: pointer to the hw struct
  990. * @buf: a virtual buffer to hold the capabilities
  991. * @buf_size: Size of the virtual buffer
  992. * @data_size: Size of the returned data, or buf size needed if AQ err==ENOMEM
  993. * @opc: capabilities type to discover - pass in the command opcode
  994. * @cd: pointer to command details structure or NULL
  995. *
  996. * Get the function(0x000a)/device(0x000b) capabilities description from
  997. * the firmware.
  998. */
  999. static enum ice_status
  1000. ice_aq_discover_caps(struct ice_hw *hw, void *buf, u16 buf_size, u16 *data_size,
  1001. enum ice_adminq_opc opc, struct ice_sq_cd *cd)
  1002. {
  1003. struct ice_aqc_list_caps *cmd;
  1004. struct ice_aq_desc desc;
  1005. enum ice_status status;
  1006. cmd = &desc.params.get_cap;
  1007. if (opc != ice_aqc_opc_list_func_caps &&
  1008. opc != ice_aqc_opc_list_dev_caps)
  1009. return ICE_ERR_PARAM;
  1010. ice_fill_dflt_direct_cmd_desc(&desc, opc);
  1011. status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
  1012. if (!status)
  1013. ice_parse_caps(hw, buf, le32_to_cpu(cmd->count), opc);
  1014. *data_size = le16_to_cpu(desc.datalen);
  1015. return status;
  1016. }
  1017. /**
  1018. * ice_get_caps - get info about the HW
  1019. * @hw: pointer to the hardware structure
  1020. */
  1021. enum ice_status ice_get_caps(struct ice_hw *hw)
  1022. {
  1023. enum ice_status status;
  1024. u16 data_size = 0;
  1025. u16 cbuf_len;
  1026. u8 retries;
  1027. /* The driver doesn't know how many capabilities the device will return
  1028. * so the buffer size required isn't known ahead of time. The driver
  1029. * starts with cbuf_len and if this turns out to be insufficient, the
  1030. * device returns ICE_AQ_RC_ENOMEM and also the buffer size it needs.
  1031. * The driver then allocates the buffer of this size and retries the
  1032. * operation. So it follows that the retry count is 2.
  1033. */
  1034. #define ICE_GET_CAP_BUF_COUNT 40
  1035. #define ICE_GET_CAP_RETRY_COUNT 2
  1036. cbuf_len = ICE_GET_CAP_BUF_COUNT *
  1037. sizeof(struct ice_aqc_list_caps_elem);
  1038. retries = ICE_GET_CAP_RETRY_COUNT;
  1039. do {
  1040. void *cbuf;
  1041. cbuf = devm_kzalloc(ice_hw_to_dev(hw), cbuf_len, GFP_KERNEL);
  1042. if (!cbuf)
  1043. return ICE_ERR_NO_MEMORY;
  1044. status = ice_aq_discover_caps(hw, cbuf, cbuf_len, &data_size,
  1045. ice_aqc_opc_list_func_caps, NULL);
  1046. devm_kfree(ice_hw_to_dev(hw), cbuf);
  1047. if (!status || hw->adminq.sq_last_status != ICE_AQ_RC_ENOMEM)
  1048. break;
  1049. /* If ENOMEM is returned, try again with bigger buffer */
  1050. cbuf_len = data_size;
  1051. } while (--retries);
  1052. return status;
  1053. }
  1054. /**
  1055. * ice_aq_manage_mac_write - manage MAC address write command
  1056. * @hw: pointer to the hw struct
  1057. * @mac_addr: MAC address to be written as LAA/LAA+WoL/Port address
  1058. * @flags: flags to control write behavior
  1059. * @cd: pointer to command details structure or NULL
  1060. *
  1061. * This function is used to write MAC address to the NVM (0x0108).
  1062. */
  1063. enum ice_status
  1064. ice_aq_manage_mac_write(struct ice_hw *hw, u8 *mac_addr, u8 flags,
  1065. struct ice_sq_cd *cd)
  1066. {
  1067. struct ice_aqc_manage_mac_write *cmd;
  1068. struct ice_aq_desc desc;
  1069. cmd = &desc.params.mac_write;
  1070. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_manage_mac_write);
  1071. cmd->flags = flags;
  1072. /* Prep values for flags, sah, sal */
  1073. cmd->sah = htons(*((u16 *)mac_addr));
  1074. cmd->sal = htonl(*((u32 *)(mac_addr + 2)));
  1075. return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
  1076. }
  1077. /**
  1078. * ice_aq_clear_pxe_mode
  1079. * @hw: pointer to the hw struct
  1080. *
  1081. * Tell the firmware that the driver is taking over from PXE (0x0110).
  1082. */
  1083. static enum ice_status ice_aq_clear_pxe_mode(struct ice_hw *hw)
  1084. {
  1085. struct ice_aq_desc desc;
  1086. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_clear_pxe_mode);
  1087. desc.params.clear_pxe.rx_cnt = ICE_AQC_CLEAR_PXE_RX_CNT;
  1088. return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  1089. }
  1090. /**
  1091. * ice_clear_pxe_mode - clear pxe operations mode
  1092. * @hw: pointer to the hw struct
  1093. *
  1094. * Make sure all PXE mode settings are cleared, including things
  1095. * like descriptor fetch/write-back mode.
  1096. */
  1097. void ice_clear_pxe_mode(struct ice_hw *hw)
  1098. {
  1099. if (ice_check_sq_alive(hw, &hw->adminq))
  1100. ice_aq_clear_pxe_mode(hw);
  1101. }
  1102. /**
  1103. * ice_aq_set_phy_cfg
  1104. * @hw: pointer to the hw struct
  1105. * @lport: logical port number
  1106. * @cfg: structure with PHY configuration data to be set
  1107. * @cd: pointer to command details structure or NULL
  1108. *
  1109. * Set the various PHY configuration parameters supported on the Port.
  1110. * One or more of the Set PHY config parameters may be ignored in an MFP
  1111. * mode as the PF may not have the privilege to set some of the PHY Config
  1112. * parameters. This status will be indicated by the command response (0x0601).
  1113. */
  1114. static enum ice_status
  1115. ice_aq_set_phy_cfg(struct ice_hw *hw, u8 lport,
  1116. struct ice_aqc_set_phy_cfg_data *cfg, struct ice_sq_cd *cd)
  1117. {
  1118. struct ice_aqc_set_phy_cfg *cmd;
  1119. struct ice_aq_desc desc;
  1120. if (!cfg)
  1121. return ICE_ERR_PARAM;
  1122. cmd = &desc.params.set_phy;
  1123. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_phy_cfg);
  1124. cmd->lport_num = lport;
  1125. return ice_aq_send_cmd(hw, &desc, cfg, sizeof(*cfg), cd);
  1126. }
  1127. /**
  1128. * ice_update_link_info - update status of the HW network link
  1129. * @pi: port info structure of the interested logical port
  1130. */
  1131. static enum ice_status
  1132. ice_update_link_info(struct ice_port_info *pi)
  1133. {
  1134. struct ice_aqc_get_phy_caps_data *pcaps;
  1135. struct ice_phy_info *phy_info;
  1136. enum ice_status status;
  1137. struct ice_hw *hw;
  1138. if (!pi)
  1139. return ICE_ERR_PARAM;
  1140. hw = pi->hw;
  1141. pcaps = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*pcaps), GFP_KERNEL);
  1142. if (!pcaps)
  1143. return ICE_ERR_NO_MEMORY;
  1144. phy_info = &pi->phy;
  1145. status = ice_aq_get_link_info(pi, true, NULL, NULL);
  1146. if (status)
  1147. goto out;
  1148. if (phy_info->link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) {
  1149. status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG,
  1150. pcaps, NULL);
  1151. if (status)
  1152. goto out;
  1153. memcpy(phy_info->link_info.module_type, &pcaps->module_type,
  1154. sizeof(phy_info->link_info.module_type));
  1155. }
  1156. out:
  1157. devm_kfree(ice_hw_to_dev(hw), pcaps);
  1158. return status;
  1159. }
  1160. /**
  1161. * ice_set_fc
  1162. * @pi: port information structure
  1163. * @aq_failures: pointer to status code, specific to ice_set_fc routine
  1164. * @atomic_restart: enable automatic link update
  1165. *
  1166. * Set the requested flow control mode.
  1167. */
  1168. enum ice_status
  1169. ice_set_fc(struct ice_port_info *pi, u8 *aq_failures, bool atomic_restart)
  1170. {
  1171. struct ice_aqc_set_phy_cfg_data cfg = { 0 };
  1172. struct ice_aqc_get_phy_caps_data *pcaps;
  1173. enum ice_status status;
  1174. u8 pause_mask = 0x0;
  1175. struct ice_hw *hw;
  1176. if (!pi)
  1177. return ICE_ERR_PARAM;
  1178. hw = pi->hw;
  1179. *aq_failures = ICE_SET_FC_AQ_FAIL_NONE;
  1180. switch (pi->fc.req_mode) {
  1181. case ICE_FC_FULL:
  1182. pause_mask |= ICE_AQC_PHY_EN_TX_LINK_PAUSE;
  1183. pause_mask |= ICE_AQC_PHY_EN_RX_LINK_PAUSE;
  1184. break;
  1185. case ICE_FC_RX_PAUSE:
  1186. pause_mask |= ICE_AQC_PHY_EN_RX_LINK_PAUSE;
  1187. break;
  1188. case ICE_FC_TX_PAUSE:
  1189. pause_mask |= ICE_AQC_PHY_EN_TX_LINK_PAUSE;
  1190. break;
  1191. default:
  1192. break;
  1193. }
  1194. pcaps = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*pcaps), GFP_KERNEL);
  1195. if (!pcaps)
  1196. return ICE_ERR_NO_MEMORY;
  1197. /* Get the current phy config */
  1198. status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps,
  1199. NULL);
  1200. if (status) {
  1201. *aq_failures = ICE_SET_FC_AQ_FAIL_GET;
  1202. goto out;
  1203. }
  1204. /* clear the old pause settings */
  1205. cfg.caps = pcaps->caps & ~(ICE_AQC_PHY_EN_TX_LINK_PAUSE |
  1206. ICE_AQC_PHY_EN_RX_LINK_PAUSE);
  1207. /* set the new capabilities */
  1208. cfg.caps |= pause_mask;
  1209. /* If the capabilities have changed, then set the new config */
  1210. if (cfg.caps != pcaps->caps) {
  1211. int retry_count, retry_max = 10;
  1212. /* Auto restart link so settings take effect */
  1213. if (atomic_restart)
  1214. cfg.caps |= ICE_AQ_PHY_ENA_ATOMIC_LINK;
  1215. /* Copy over all the old settings */
  1216. cfg.phy_type_low = pcaps->phy_type_low;
  1217. cfg.low_power_ctrl = pcaps->low_power_ctrl;
  1218. cfg.eee_cap = pcaps->eee_cap;
  1219. cfg.eeer_value = pcaps->eeer_value;
  1220. cfg.link_fec_opt = pcaps->link_fec_options;
  1221. status = ice_aq_set_phy_cfg(hw, pi->lport, &cfg, NULL);
  1222. if (status) {
  1223. *aq_failures = ICE_SET_FC_AQ_FAIL_SET;
  1224. goto out;
  1225. }
  1226. /* Update the link info
  1227. * It sometimes takes a really long time for link to
  1228. * come back from the atomic reset. Thus, we wait a
  1229. * little bit.
  1230. */
  1231. for (retry_count = 0; retry_count < retry_max; retry_count++) {
  1232. status = ice_update_link_info(pi);
  1233. if (!status)
  1234. break;
  1235. mdelay(100);
  1236. }
  1237. if (status)
  1238. *aq_failures = ICE_SET_FC_AQ_FAIL_UPDATE;
  1239. }
  1240. out:
  1241. devm_kfree(ice_hw_to_dev(hw), pcaps);
  1242. return status;
  1243. }
  1244. /**
  1245. * ice_get_link_status - get status of the HW network link
  1246. * @pi: port information structure
  1247. * @link_up: pointer to bool (true/false = linkup/linkdown)
  1248. *
  1249. * Variable link_up is true if link is up, false if link is down.
  1250. * The variable link_up is invalid if status is non zero. As a
  1251. * result of this call, link status reporting becomes enabled
  1252. */
  1253. enum ice_status ice_get_link_status(struct ice_port_info *pi, bool *link_up)
  1254. {
  1255. struct ice_phy_info *phy_info;
  1256. enum ice_status status = 0;
  1257. if (!pi)
  1258. return ICE_ERR_PARAM;
  1259. phy_info = &pi->phy;
  1260. if (phy_info->get_link_info) {
  1261. status = ice_update_link_info(pi);
  1262. if (status)
  1263. ice_debug(pi->hw, ICE_DBG_LINK,
  1264. "get link status error, status = %d\n",
  1265. status);
  1266. }
  1267. *link_up = phy_info->link_info.link_info & ICE_AQ_LINK_UP;
  1268. return status;
  1269. }
  1270. /**
  1271. * ice_aq_set_link_restart_an
  1272. * @pi: pointer to the port information structure
  1273. * @ena_link: if true: enable link, if false: disable link
  1274. * @cd: pointer to command details structure or NULL
  1275. *
  1276. * Sets up the link and restarts the Auto-Negotiation over the link.
  1277. */
  1278. enum ice_status
  1279. ice_aq_set_link_restart_an(struct ice_port_info *pi, bool ena_link,
  1280. struct ice_sq_cd *cd)
  1281. {
  1282. struct ice_aqc_restart_an *cmd;
  1283. struct ice_aq_desc desc;
  1284. cmd = &desc.params.restart_an;
  1285. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_restart_an);
  1286. cmd->cmd_flags = ICE_AQC_RESTART_AN_LINK_RESTART;
  1287. cmd->lport_num = pi->lport;
  1288. if (ena_link)
  1289. cmd->cmd_flags |= ICE_AQC_RESTART_AN_LINK_ENABLE;
  1290. else
  1291. cmd->cmd_flags &= ~ICE_AQC_RESTART_AN_LINK_ENABLE;
  1292. return ice_aq_send_cmd(pi->hw, &desc, NULL, 0, cd);
  1293. }
  1294. /**
  1295. * ice_aq_set_event_mask
  1296. * @hw: pointer to the hw struct
  1297. * @port_num: port number of the physical function
  1298. * @mask: event mask to be set
  1299. * @cd: pointer to command details structure or NULL
  1300. *
  1301. * Set event mask (0x0613)
  1302. */
  1303. enum ice_status
  1304. ice_aq_set_event_mask(struct ice_hw *hw, u8 port_num, u16 mask,
  1305. struct ice_sq_cd *cd)
  1306. {
  1307. struct ice_aqc_set_event_mask *cmd;
  1308. struct ice_aq_desc desc;
  1309. cmd = &desc.params.set_event_mask;
  1310. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_event_mask);
  1311. cmd->lport_num = port_num;
  1312. cmd->event_mask = cpu_to_le16(mask);
  1313. return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
  1314. }
  1315. /**
  1316. * __ice_aq_get_set_rss_lut
  1317. * @hw: pointer to the hardware structure
  1318. * @vsi_id: VSI FW index
  1319. * @lut_type: LUT table type
  1320. * @lut: pointer to the LUT buffer provided by the caller
  1321. * @lut_size: size of the LUT buffer
  1322. * @glob_lut_idx: global LUT index
  1323. * @set: set true to set the table, false to get the table
  1324. *
  1325. * Internal function to get (0x0B05) or set (0x0B03) RSS look up table
  1326. */
  1327. static enum ice_status
  1328. __ice_aq_get_set_rss_lut(struct ice_hw *hw, u16 vsi_id, u8 lut_type, u8 *lut,
  1329. u16 lut_size, u8 glob_lut_idx, bool set)
  1330. {
  1331. struct ice_aqc_get_set_rss_lut *cmd_resp;
  1332. struct ice_aq_desc desc;
  1333. enum ice_status status;
  1334. u16 flags = 0;
  1335. cmd_resp = &desc.params.get_set_rss_lut;
  1336. if (set) {
  1337. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_rss_lut);
  1338. desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
  1339. } else {
  1340. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_rss_lut);
  1341. }
  1342. cmd_resp->vsi_id = cpu_to_le16(((vsi_id <<
  1343. ICE_AQC_GSET_RSS_LUT_VSI_ID_S) &
  1344. ICE_AQC_GSET_RSS_LUT_VSI_ID_M) |
  1345. ICE_AQC_GSET_RSS_LUT_VSI_VALID);
  1346. switch (lut_type) {
  1347. case ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_VSI:
  1348. case ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF:
  1349. case ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_GLOBAL:
  1350. flags |= ((lut_type << ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_S) &
  1351. ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_M);
  1352. break;
  1353. default:
  1354. status = ICE_ERR_PARAM;
  1355. goto ice_aq_get_set_rss_lut_exit;
  1356. }
  1357. if (lut_type == ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_GLOBAL) {
  1358. flags |= ((glob_lut_idx << ICE_AQC_GSET_RSS_LUT_GLOBAL_IDX_S) &
  1359. ICE_AQC_GSET_RSS_LUT_GLOBAL_IDX_M);
  1360. if (!set)
  1361. goto ice_aq_get_set_rss_lut_send;
  1362. } else if (lut_type == ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF) {
  1363. if (!set)
  1364. goto ice_aq_get_set_rss_lut_send;
  1365. } else {
  1366. goto ice_aq_get_set_rss_lut_send;
  1367. }
  1368. /* LUT size is only valid for Global and PF table types */
  1369. if (lut_size == ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_128) {
  1370. flags |= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_128_FLAG <<
  1371. ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S) &
  1372. ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M;
  1373. } else if (lut_size == ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512) {
  1374. flags |= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512_FLAG <<
  1375. ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S) &
  1376. ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M;
  1377. } else if ((lut_size == ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K) &&
  1378. (lut_type == ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF)) {
  1379. flags |= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K_FLAG <<
  1380. ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S) &
  1381. ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M;
  1382. } else {
  1383. status = ICE_ERR_PARAM;
  1384. goto ice_aq_get_set_rss_lut_exit;
  1385. }
  1386. ice_aq_get_set_rss_lut_send:
  1387. cmd_resp->flags = cpu_to_le16(flags);
  1388. status = ice_aq_send_cmd(hw, &desc, lut, lut_size, NULL);
  1389. ice_aq_get_set_rss_lut_exit:
  1390. return status;
  1391. }
  1392. /**
  1393. * ice_aq_get_rss_lut
  1394. * @hw: pointer to the hardware structure
  1395. * @vsi_id: VSI FW index
  1396. * @lut_type: LUT table type
  1397. * @lut: pointer to the LUT buffer provided by the caller
  1398. * @lut_size: size of the LUT buffer
  1399. *
  1400. * get the RSS lookup table, PF or VSI type
  1401. */
  1402. enum ice_status
  1403. ice_aq_get_rss_lut(struct ice_hw *hw, u16 vsi_id, u8 lut_type, u8 *lut,
  1404. u16 lut_size)
  1405. {
  1406. return __ice_aq_get_set_rss_lut(hw, vsi_id, lut_type, lut, lut_size, 0,
  1407. false);
  1408. }
  1409. /**
  1410. * ice_aq_set_rss_lut
  1411. * @hw: pointer to the hardware structure
  1412. * @vsi_id: VSI FW index
  1413. * @lut_type: LUT table type
  1414. * @lut: pointer to the LUT buffer provided by the caller
  1415. * @lut_size: size of the LUT buffer
  1416. *
  1417. * set the RSS lookup table, PF or VSI type
  1418. */
  1419. enum ice_status
  1420. ice_aq_set_rss_lut(struct ice_hw *hw, u16 vsi_id, u8 lut_type, u8 *lut,
  1421. u16 lut_size)
  1422. {
  1423. return __ice_aq_get_set_rss_lut(hw, vsi_id, lut_type, lut, lut_size, 0,
  1424. true);
  1425. }
  1426. /**
  1427. * __ice_aq_get_set_rss_key
  1428. * @hw: pointer to the hw struct
  1429. * @vsi_id: VSI FW index
  1430. * @key: pointer to key info struct
  1431. * @set: set true to set the key, false to get the key
  1432. *
  1433. * get (0x0B04) or set (0x0B02) the RSS key per VSI
  1434. */
  1435. static enum
  1436. ice_status __ice_aq_get_set_rss_key(struct ice_hw *hw, u16 vsi_id,
  1437. struct ice_aqc_get_set_rss_keys *key,
  1438. bool set)
  1439. {
  1440. struct ice_aqc_get_set_rss_key *cmd_resp;
  1441. u16 key_size = sizeof(*key);
  1442. struct ice_aq_desc desc;
  1443. cmd_resp = &desc.params.get_set_rss_key;
  1444. if (set) {
  1445. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_rss_key);
  1446. desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
  1447. } else {
  1448. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_rss_key);
  1449. }
  1450. cmd_resp->vsi_id = cpu_to_le16(((vsi_id <<
  1451. ICE_AQC_GSET_RSS_KEY_VSI_ID_S) &
  1452. ICE_AQC_GSET_RSS_KEY_VSI_ID_M) |
  1453. ICE_AQC_GSET_RSS_KEY_VSI_VALID);
  1454. return ice_aq_send_cmd(hw, &desc, key, key_size, NULL);
  1455. }
  1456. /**
  1457. * ice_aq_get_rss_key
  1458. * @hw: pointer to the hw struct
  1459. * @vsi_id: VSI FW index
  1460. * @key: pointer to key info struct
  1461. *
  1462. * get the RSS key per VSI
  1463. */
  1464. enum ice_status
  1465. ice_aq_get_rss_key(struct ice_hw *hw, u16 vsi_id,
  1466. struct ice_aqc_get_set_rss_keys *key)
  1467. {
  1468. return __ice_aq_get_set_rss_key(hw, vsi_id, key, false);
  1469. }
  1470. /**
  1471. * ice_aq_set_rss_key
  1472. * @hw: pointer to the hw struct
  1473. * @vsi_id: VSI FW index
  1474. * @keys: pointer to key info struct
  1475. *
  1476. * set the RSS key per VSI
  1477. */
  1478. enum ice_status
  1479. ice_aq_set_rss_key(struct ice_hw *hw, u16 vsi_id,
  1480. struct ice_aqc_get_set_rss_keys *keys)
  1481. {
  1482. return __ice_aq_get_set_rss_key(hw, vsi_id, keys, true);
  1483. }
  1484. /**
  1485. * ice_aq_add_lan_txq
  1486. * @hw: pointer to the hardware structure
  1487. * @num_qgrps: Number of added queue groups
  1488. * @qg_list: list of queue groups to be added
  1489. * @buf_size: size of buffer for indirect command
  1490. * @cd: pointer to command details structure or NULL
  1491. *
  1492. * Add Tx LAN queue (0x0C30)
  1493. *
  1494. * NOTE:
  1495. * Prior to calling add Tx LAN queue:
  1496. * Initialize the following as part of the Tx queue context:
  1497. * Completion queue ID if the queue uses Completion queue, Quanta profile,
  1498. * Cache profile and Packet shaper profile.
  1499. *
  1500. * After add Tx LAN queue AQ command is completed:
  1501. * Interrupts should be associated with specific queues,
  1502. * Association of Tx queue to Doorbell queue is not part of Add LAN Tx queue
  1503. * flow.
  1504. */
  1505. static enum ice_status
  1506. ice_aq_add_lan_txq(struct ice_hw *hw, u8 num_qgrps,
  1507. struct ice_aqc_add_tx_qgrp *qg_list, u16 buf_size,
  1508. struct ice_sq_cd *cd)
  1509. {
  1510. u16 i, sum_header_size, sum_q_size = 0;
  1511. struct ice_aqc_add_tx_qgrp *list;
  1512. struct ice_aqc_add_txqs *cmd;
  1513. struct ice_aq_desc desc;
  1514. cmd = &desc.params.add_txqs;
  1515. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_add_txqs);
  1516. if (!qg_list)
  1517. return ICE_ERR_PARAM;
  1518. if (num_qgrps > ICE_LAN_TXQ_MAX_QGRPS)
  1519. return ICE_ERR_PARAM;
  1520. sum_header_size = num_qgrps *
  1521. (sizeof(*qg_list) - sizeof(*qg_list->txqs));
  1522. list = qg_list;
  1523. for (i = 0; i < num_qgrps; i++) {
  1524. struct ice_aqc_add_txqs_perq *q = list->txqs;
  1525. sum_q_size += list->num_txqs * sizeof(*q);
  1526. list = (struct ice_aqc_add_tx_qgrp *)(q + list->num_txqs);
  1527. }
  1528. if (buf_size != (sum_header_size + sum_q_size))
  1529. return ICE_ERR_PARAM;
  1530. desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
  1531. cmd->num_qgrps = num_qgrps;
  1532. return ice_aq_send_cmd(hw, &desc, qg_list, buf_size, cd);
  1533. }
  1534. /**
  1535. * ice_aq_dis_lan_txq
  1536. * @hw: pointer to the hardware structure
  1537. * @num_qgrps: number of groups in the list
  1538. * @qg_list: the list of groups to disable
  1539. * @buf_size: the total size of the qg_list buffer in bytes
  1540. * @cd: pointer to command details structure or NULL
  1541. *
  1542. * Disable LAN Tx queue (0x0C31)
  1543. */
  1544. static enum ice_status
  1545. ice_aq_dis_lan_txq(struct ice_hw *hw, u8 num_qgrps,
  1546. struct ice_aqc_dis_txq_item *qg_list, u16 buf_size,
  1547. struct ice_sq_cd *cd)
  1548. {
  1549. struct ice_aqc_dis_txqs *cmd;
  1550. struct ice_aq_desc desc;
  1551. u16 i, sz = 0;
  1552. cmd = &desc.params.dis_txqs;
  1553. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_dis_txqs);
  1554. if (!qg_list)
  1555. return ICE_ERR_PARAM;
  1556. if (num_qgrps > ICE_LAN_TXQ_MAX_QGRPS)
  1557. return ICE_ERR_PARAM;
  1558. desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
  1559. cmd->num_entries = num_qgrps;
  1560. for (i = 0; i < num_qgrps; ++i) {
  1561. /* Calculate the size taken up by the queue IDs in this group */
  1562. sz += qg_list[i].num_qs * sizeof(qg_list[i].q_id);
  1563. /* Add the size of the group header */
  1564. sz += sizeof(qg_list[i]) - sizeof(qg_list[i].q_id);
  1565. /* If the num of queues is even, add 2 bytes of padding */
  1566. if ((qg_list[i].num_qs % 2) == 0)
  1567. sz += 2;
  1568. }
  1569. if (buf_size != sz)
  1570. return ICE_ERR_PARAM;
  1571. return ice_aq_send_cmd(hw, &desc, qg_list, buf_size, cd);
  1572. }
  1573. /* End of FW Admin Queue command wrappers */
  1574. /**
  1575. * ice_write_byte - write a byte to a packed context structure
  1576. * @src_ctx: the context structure to read from
  1577. * @dest_ctx: the context to be written to
  1578. * @ce_info: a description of the struct to be filled
  1579. */
  1580. static void ice_write_byte(u8 *src_ctx, u8 *dest_ctx,
  1581. const struct ice_ctx_ele *ce_info)
  1582. {
  1583. u8 src_byte, dest_byte, mask;
  1584. u8 *from, *dest;
  1585. u16 shift_width;
  1586. /* copy from the next struct field */
  1587. from = src_ctx + ce_info->offset;
  1588. /* prepare the bits and mask */
  1589. shift_width = ce_info->lsb % 8;
  1590. mask = (u8)(BIT(ce_info->width) - 1);
  1591. src_byte = *from;
  1592. src_byte &= mask;
  1593. /* shift to correct alignment */
  1594. mask <<= shift_width;
  1595. src_byte <<= shift_width;
  1596. /* get the current bits from the target bit string */
  1597. dest = dest_ctx + (ce_info->lsb / 8);
  1598. memcpy(&dest_byte, dest, sizeof(dest_byte));
  1599. dest_byte &= ~mask; /* get the bits not changing */
  1600. dest_byte |= src_byte; /* add in the new bits */
  1601. /* put it all back */
  1602. memcpy(dest, &dest_byte, sizeof(dest_byte));
  1603. }
  1604. /**
  1605. * ice_write_word - write a word to a packed context structure
  1606. * @src_ctx: the context structure to read from
  1607. * @dest_ctx: the context to be written to
  1608. * @ce_info: a description of the struct to be filled
  1609. */
  1610. static void ice_write_word(u8 *src_ctx, u8 *dest_ctx,
  1611. const struct ice_ctx_ele *ce_info)
  1612. {
  1613. u16 src_word, mask;
  1614. __le16 dest_word;
  1615. u8 *from, *dest;
  1616. u16 shift_width;
  1617. /* copy from the next struct field */
  1618. from = src_ctx + ce_info->offset;
  1619. /* prepare the bits and mask */
  1620. shift_width = ce_info->lsb % 8;
  1621. mask = BIT(ce_info->width) - 1;
  1622. /* don't swizzle the bits until after the mask because the mask bits
  1623. * will be in a different bit position on big endian machines
  1624. */
  1625. src_word = *(u16 *)from;
  1626. src_word &= mask;
  1627. /* shift to correct alignment */
  1628. mask <<= shift_width;
  1629. src_word <<= shift_width;
  1630. /* get the current bits from the target bit string */
  1631. dest = dest_ctx + (ce_info->lsb / 8);
  1632. memcpy(&dest_word, dest, sizeof(dest_word));
  1633. dest_word &= ~(cpu_to_le16(mask)); /* get the bits not changing */
  1634. dest_word |= cpu_to_le16(src_word); /* add in the new bits */
  1635. /* put it all back */
  1636. memcpy(dest, &dest_word, sizeof(dest_word));
  1637. }
  1638. /**
  1639. * ice_write_dword - write a dword to a packed context structure
  1640. * @src_ctx: the context structure to read from
  1641. * @dest_ctx: the context to be written to
  1642. * @ce_info: a description of the struct to be filled
  1643. */
  1644. static void ice_write_dword(u8 *src_ctx, u8 *dest_ctx,
  1645. const struct ice_ctx_ele *ce_info)
  1646. {
  1647. u32 src_dword, mask;
  1648. __le32 dest_dword;
  1649. u8 *from, *dest;
  1650. u16 shift_width;
  1651. /* copy from the next struct field */
  1652. from = src_ctx + ce_info->offset;
  1653. /* prepare the bits and mask */
  1654. shift_width = ce_info->lsb % 8;
  1655. /* if the field width is exactly 32 on an x86 machine, then the shift
  1656. * operation will not work because the SHL instructions count is masked
  1657. * to 5 bits so the shift will do nothing
  1658. */
  1659. if (ce_info->width < 32)
  1660. mask = BIT(ce_info->width) - 1;
  1661. else
  1662. mask = (u32)~0;
  1663. /* don't swizzle the bits until after the mask because the mask bits
  1664. * will be in a different bit position on big endian machines
  1665. */
  1666. src_dword = *(u32 *)from;
  1667. src_dword &= mask;
  1668. /* shift to correct alignment */
  1669. mask <<= shift_width;
  1670. src_dword <<= shift_width;
  1671. /* get the current bits from the target bit string */
  1672. dest = dest_ctx + (ce_info->lsb / 8);
  1673. memcpy(&dest_dword, dest, sizeof(dest_dword));
  1674. dest_dword &= ~(cpu_to_le32(mask)); /* get the bits not changing */
  1675. dest_dword |= cpu_to_le32(src_dword); /* add in the new bits */
  1676. /* put it all back */
  1677. memcpy(dest, &dest_dword, sizeof(dest_dword));
  1678. }
  1679. /**
  1680. * ice_write_qword - write a qword to a packed context structure
  1681. * @src_ctx: the context structure to read from
  1682. * @dest_ctx: the context to be written to
  1683. * @ce_info: a description of the struct to be filled
  1684. */
  1685. static void ice_write_qword(u8 *src_ctx, u8 *dest_ctx,
  1686. const struct ice_ctx_ele *ce_info)
  1687. {
  1688. u64 src_qword, mask;
  1689. __le64 dest_qword;
  1690. u8 *from, *dest;
  1691. u16 shift_width;
  1692. /* copy from the next struct field */
  1693. from = src_ctx + ce_info->offset;
  1694. /* prepare the bits and mask */
  1695. shift_width = ce_info->lsb % 8;
  1696. /* if the field width is exactly 64 on an x86 machine, then the shift
  1697. * operation will not work because the SHL instructions count is masked
  1698. * to 6 bits so the shift will do nothing
  1699. */
  1700. if (ce_info->width < 64)
  1701. mask = BIT_ULL(ce_info->width) - 1;
  1702. else
  1703. mask = (u64)~0;
  1704. /* don't swizzle the bits until after the mask because the mask bits
  1705. * will be in a different bit position on big endian machines
  1706. */
  1707. src_qword = *(u64 *)from;
  1708. src_qword &= mask;
  1709. /* shift to correct alignment */
  1710. mask <<= shift_width;
  1711. src_qword <<= shift_width;
  1712. /* get the current bits from the target bit string */
  1713. dest = dest_ctx + (ce_info->lsb / 8);
  1714. memcpy(&dest_qword, dest, sizeof(dest_qword));
  1715. dest_qword &= ~(cpu_to_le64(mask)); /* get the bits not changing */
  1716. dest_qword |= cpu_to_le64(src_qword); /* add in the new bits */
  1717. /* put it all back */
  1718. memcpy(dest, &dest_qword, sizeof(dest_qword));
  1719. }
  1720. /**
  1721. * ice_set_ctx - set context bits in packed structure
  1722. * @src_ctx: pointer to a generic non-packed context structure
  1723. * @dest_ctx: pointer to memory for the packed structure
  1724. * @ce_info: a description of the structure to be transformed
  1725. */
  1726. enum ice_status
  1727. ice_set_ctx(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
  1728. {
  1729. int f;
  1730. for (f = 0; ce_info[f].width; f++) {
  1731. /* We have to deal with each element of the FW response
  1732. * using the correct size so that we are correct regardless
  1733. * of the endianness of the machine.
  1734. */
  1735. switch (ce_info[f].size_of) {
  1736. case sizeof(u8):
  1737. ice_write_byte(src_ctx, dest_ctx, &ce_info[f]);
  1738. break;
  1739. case sizeof(u16):
  1740. ice_write_word(src_ctx, dest_ctx, &ce_info[f]);
  1741. break;
  1742. case sizeof(u32):
  1743. ice_write_dword(src_ctx, dest_ctx, &ce_info[f]);
  1744. break;
  1745. case sizeof(u64):
  1746. ice_write_qword(src_ctx, dest_ctx, &ce_info[f]);
  1747. break;
  1748. default:
  1749. return ICE_ERR_INVAL_SIZE;
  1750. }
  1751. }
  1752. return 0;
  1753. }
  1754. /**
  1755. * ice_ena_vsi_txq
  1756. * @pi: port information structure
  1757. * @vsi_id: VSI id
  1758. * @tc: tc number
  1759. * @num_qgrps: Number of added queue groups
  1760. * @buf: list of queue groups to be added
  1761. * @buf_size: size of buffer for indirect command
  1762. * @cd: pointer to command details structure or NULL
  1763. *
  1764. * This function adds one lan q
  1765. */
  1766. enum ice_status
  1767. ice_ena_vsi_txq(struct ice_port_info *pi, u16 vsi_id, u8 tc, u8 num_qgrps,
  1768. struct ice_aqc_add_tx_qgrp *buf, u16 buf_size,
  1769. struct ice_sq_cd *cd)
  1770. {
  1771. struct ice_aqc_txsched_elem_data node = { 0 };
  1772. struct ice_sched_node *parent;
  1773. enum ice_status status;
  1774. struct ice_hw *hw;
  1775. if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
  1776. return ICE_ERR_CFG;
  1777. if (num_qgrps > 1 || buf->num_txqs > 1)
  1778. return ICE_ERR_MAX_LIMIT;
  1779. hw = pi->hw;
  1780. mutex_lock(&pi->sched_lock);
  1781. /* find a parent node */
  1782. parent = ice_sched_get_free_qparent(pi, vsi_id, tc,
  1783. ICE_SCHED_NODE_OWNER_LAN);
  1784. if (!parent) {
  1785. status = ICE_ERR_PARAM;
  1786. goto ena_txq_exit;
  1787. }
  1788. buf->parent_teid = parent->info.node_teid;
  1789. node.parent_teid = parent->info.node_teid;
  1790. /* Mark that the values in the "generic" section as valid. The default
  1791. * value in the "generic" section is zero. This means that :
  1792. * - Scheduling mode is Bytes Per Second (BPS), indicated by Bit 0.
  1793. * - 0 priority among siblings, indicated by Bit 1-3.
  1794. * - WFQ, indicated by Bit 4.
  1795. * - 0 Adjustment value is used in PSM credit update flow, indicated by
  1796. * Bit 5-6.
  1797. * - Bit 7 is reserved.
  1798. * Without setting the generic section as valid in valid_sections, the
  1799. * Admin Q command will fail with error code ICE_AQ_RC_EINVAL.
  1800. */
  1801. buf->txqs[0].info.valid_sections = ICE_AQC_ELEM_VALID_GENERIC;
  1802. /* add the lan q */
  1803. status = ice_aq_add_lan_txq(hw, num_qgrps, buf, buf_size, cd);
  1804. if (status)
  1805. goto ena_txq_exit;
  1806. node.node_teid = buf->txqs[0].q_teid;
  1807. node.data.elem_type = ICE_AQC_ELEM_TYPE_LEAF;
  1808. /* add a leaf node into schduler tree q layer */
  1809. status = ice_sched_add_node(pi, hw->num_tx_sched_layers - 1, &node);
  1810. ena_txq_exit:
  1811. mutex_unlock(&pi->sched_lock);
  1812. return status;
  1813. }
  1814. /**
  1815. * ice_dis_vsi_txq
  1816. * @pi: port information structure
  1817. * @num_queues: number of queues
  1818. * @q_ids: pointer to the q_id array
  1819. * @q_teids: pointer to queue node teids
  1820. * @cd: pointer to command details structure or NULL
  1821. *
  1822. * This function removes queues and their corresponding nodes in SW DB
  1823. */
  1824. enum ice_status
  1825. ice_dis_vsi_txq(struct ice_port_info *pi, u8 num_queues, u16 *q_ids,
  1826. u32 *q_teids, struct ice_sq_cd *cd)
  1827. {
  1828. enum ice_status status = ICE_ERR_DOES_NOT_EXIST;
  1829. struct ice_aqc_dis_txq_item qg_list;
  1830. u16 i;
  1831. if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
  1832. return ICE_ERR_CFG;
  1833. mutex_lock(&pi->sched_lock);
  1834. for (i = 0; i < num_queues; i++) {
  1835. struct ice_sched_node *node;
  1836. node = ice_sched_find_node_by_teid(pi->root, q_teids[i]);
  1837. if (!node)
  1838. continue;
  1839. qg_list.parent_teid = node->info.parent_teid;
  1840. qg_list.num_qs = 1;
  1841. qg_list.q_id[0] = cpu_to_le16(q_ids[i]);
  1842. status = ice_aq_dis_lan_txq(pi->hw, 1, &qg_list,
  1843. sizeof(qg_list), cd);
  1844. if (status)
  1845. break;
  1846. ice_free_sched_node(pi, node);
  1847. }
  1848. mutex_unlock(&pi->sched_lock);
  1849. return status;
  1850. }
  1851. /**
  1852. * ice_cfg_vsi_qs - configure the new/exisiting VSI queues
  1853. * @pi: port information structure
  1854. * @vsi_id: VSI Id
  1855. * @tc_bitmap: TC bitmap
  1856. * @maxqs: max queues array per TC
  1857. * @owner: lan or rdma
  1858. *
  1859. * This function adds/updates the VSI queues per TC.
  1860. */
  1861. static enum ice_status
  1862. ice_cfg_vsi_qs(struct ice_port_info *pi, u16 vsi_id, u8 tc_bitmap,
  1863. u16 *maxqs, u8 owner)
  1864. {
  1865. enum ice_status status = 0;
  1866. u8 i;
  1867. if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
  1868. return ICE_ERR_CFG;
  1869. mutex_lock(&pi->sched_lock);
  1870. for (i = 0; i < ICE_MAX_TRAFFIC_CLASS; i++) {
  1871. /* configuration is possible only if TC node is present */
  1872. if (!ice_sched_get_tc_node(pi, i))
  1873. continue;
  1874. status = ice_sched_cfg_vsi(pi, vsi_id, i, maxqs[i], owner,
  1875. ice_is_tc_ena(tc_bitmap, i));
  1876. if (status)
  1877. break;
  1878. }
  1879. mutex_unlock(&pi->sched_lock);
  1880. return status;
  1881. }
  1882. /**
  1883. * ice_cfg_vsi_lan - configure VSI lan queues
  1884. * @pi: port information structure
  1885. * @vsi_id: VSI Id
  1886. * @tc_bitmap: TC bitmap
  1887. * @max_lanqs: max lan queues array per TC
  1888. *
  1889. * This function adds/updates the VSI lan queues per TC.
  1890. */
  1891. enum ice_status
  1892. ice_cfg_vsi_lan(struct ice_port_info *pi, u16 vsi_id, u8 tc_bitmap,
  1893. u16 *max_lanqs)
  1894. {
  1895. return ice_cfg_vsi_qs(pi, vsi_id, tc_bitmap, max_lanqs,
  1896. ICE_SCHED_NODE_OWNER_LAN);
  1897. }