ice_common.c 63 KB

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