ice_common.c 79 KB

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