ice_common.c 61 KB

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