i40e_common.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. * The full GNU General Public License is included in this distribution in
  20. * the file called "COPYING".
  21. *
  22. * Contact Information:
  23. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  24. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  25. *
  26. ******************************************************************************/
  27. #include "i40e_type.h"
  28. #include "i40e_adminq.h"
  29. #include "i40e_prototype.h"
  30. #include "i40e_virtchnl.h"
  31. /**
  32. * i40e_set_mac_type - Sets MAC type
  33. * @hw: pointer to the HW structure
  34. *
  35. * This function sets the mac type of the adapter based on the
  36. * vendor ID and device ID stored in the hw structure.
  37. **/
  38. static i40e_status i40e_set_mac_type(struct i40e_hw *hw)
  39. {
  40. i40e_status status = 0;
  41. if (hw->vendor_id == PCI_VENDOR_ID_INTEL) {
  42. switch (hw->device_id) {
  43. case I40E_SFP_XL710_DEVICE_ID:
  44. case I40E_SFP_X710_DEVICE_ID:
  45. case I40E_QEMU_DEVICE_ID:
  46. case I40E_KX_A_DEVICE_ID:
  47. case I40E_KX_B_DEVICE_ID:
  48. case I40E_KX_C_DEVICE_ID:
  49. case I40E_KX_D_DEVICE_ID:
  50. case I40E_QSFP_A_DEVICE_ID:
  51. case I40E_QSFP_B_DEVICE_ID:
  52. case I40E_QSFP_C_DEVICE_ID:
  53. hw->mac.type = I40E_MAC_XL710;
  54. break;
  55. case I40E_VF_DEVICE_ID:
  56. case I40E_VF_HV_DEVICE_ID:
  57. hw->mac.type = I40E_MAC_VF;
  58. break;
  59. default:
  60. hw->mac.type = I40E_MAC_GENERIC;
  61. break;
  62. }
  63. } else {
  64. status = I40E_ERR_DEVICE_NOT_SUPPORTED;
  65. }
  66. hw_dbg(hw, "i40e_set_mac_type found mac: %d, returns: %d\n",
  67. hw->mac.type, status);
  68. return status;
  69. }
  70. /**
  71. * i40e_debug_aq
  72. * @hw: debug mask related to admin queue
  73. * @cap: pointer to adminq command descriptor
  74. * @buffer: pointer to command buffer
  75. *
  76. * Dumps debug log about adminq command with descriptor contents.
  77. **/
  78. void i40e_debug_aq(struct i40e_hw *hw, enum i40e_debug_mask mask, void *desc,
  79. void *buffer)
  80. {
  81. struct i40e_aq_desc *aq_desc = (struct i40e_aq_desc *)desc;
  82. u8 *aq_buffer = (u8 *)buffer;
  83. u32 data[4];
  84. u32 i = 0;
  85. if ((!(mask & hw->debug_mask)) || (desc == NULL))
  86. return;
  87. i40e_debug(hw, mask,
  88. "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
  89. aq_desc->opcode, aq_desc->flags, aq_desc->datalen,
  90. aq_desc->retval);
  91. i40e_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
  92. aq_desc->cookie_high, aq_desc->cookie_low);
  93. i40e_debug(hw, mask, "\tparam (0,1) 0x%08X 0x%08X\n",
  94. aq_desc->params.internal.param0,
  95. aq_desc->params.internal.param1);
  96. i40e_debug(hw, mask, "\taddr (h,l) 0x%08X 0x%08X\n",
  97. aq_desc->params.external.addr_high,
  98. aq_desc->params.external.addr_low);
  99. if ((buffer != NULL) && (aq_desc->datalen != 0)) {
  100. memset(data, 0, sizeof(data));
  101. i40e_debug(hw, mask, "AQ CMD Buffer:\n");
  102. for (i = 0; i < le16_to_cpu(aq_desc->datalen); i++) {
  103. data[((i % 16) / 4)] |=
  104. ((u32)aq_buffer[i]) << (8 * (i % 4));
  105. if ((i % 16) == 15) {
  106. i40e_debug(hw, mask,
  107. "\t0x%04X %08X %08X %08X %08X\n",
  108. i - 15, data[0], data[1], data[2],
  109. data[3]);
  110. memset(data, 0, sizeof(data));
  111. }
  112. }
  113. if ((i % 16) != 0)
  114. i40e_debug(hw, mask, "\t0x%04X %08X %08X %08X %08X\n",
  115. i - (i % 16), data[0], data[1], data[2],
  116. data[3]);
  117. }
  118. }
  119. /**
  120. * i40e_init_shared_code - Initialize the shared code
  121. * @hw: pointer to hardware structure
  122. *
  123. * This assigns the MAC type and PHY code and inits the NVM.
  124. * Does not touch the hardware. This function must be called prior to any
  125. * other function in the shared code. The i40e_hw structure should be
  126. * memset to 0 prior to calling this function. The following fields in
  127. * hw structure should be filled in prior to calling this function:
  128. * hw_addr, back, device_id, vendor_id, subsystem_device_id,
  129. * subsystem_vendor_id, and revision_id
  130. **/
  131. i40e_status i40e_init_shared_code(struct i40e_hw *hw)
  132. {
  133. i40e_status status = 0;
  134. u32 reg;
  135. hw->phy.get_link_info = true;
  136. /* Determine port number */
  137. reg = rd32(hw, I40E_PFGEN_PORTNUM);
  138. reg = ((reg & I40E_PFGEN_PORTNUM_PORT_NUM_MASK) >>
  139. I40E_PFGEN_PORTNUM_PORT_NUM_SHIFT);
  140. hw->port = (u8)reg;
  141. i40e_set_mac_type(hw);
  142. switch (hw->mac.type) {
  143. case I40E_MAC_XL710:
  144. break;
  145. default:
  146. return I40E_ERR_DEVICE_NOT_SUPPORTED;
  147. break;
  148. }
  149. status = i40e_init_nvm(hw);
  150. return status;
  151. }
  152. /**
  153. * i40e_aq_mac_address_read - Retrieve the MAC addresses
  154. * @hw: pointer to the hw struct
  155. * @flags: a return indicator of what addresses were added to the addr store
  156. * @addrs: the requestor's mac addr store
  157. * @cmd_details: pointer to command details structure or NULL
  158. **/
  159. static i40e_status i40e_aq_mac_address_read(struct i40e_hw *hw,
  160. u16 *flags,
  161. struct i40e_aqc_mac_address_read_data *addrs,
  162. struct i40e_asq_cmd_details *cmd_details)
  163. {
  164. struct i40e_aq_desc desc;
  165. struct i40e_aqc_mac_address_read *cmd_data =
  166. (struct i40e_aqc_mac_address_read *)&desc.params.raw;
  167. i40e_status status;
  168. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_mac_address_read);
  169. desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF);
  170. status = i40e_asq_send_command(hw, &desc, addrs,
  171. sizeof(*addrs), cmd_details);
  172. *flags = le16_to_cpu(cmd_data->command_flags);
  173. return status;
  174. }
  175. /**
  176. * i40e_aq_mac_address_write - Change the MAC addresses
  177. * @hw: pointer to the hw struct
  178. * @flags: indicates which MAC to be written
  179. * @mac_addr: address to write
  180. * @cmd_details: pointer to command details structure or NULL
  181. **/
  182. i40e_status i40e_aq_mac_address_write(struct i40e_hw *hw,
  183. u16 flags, u8 *mac_addr,
  184. struct i40e_asq_cmd_details *cmd_details)
  185. {
  186. struct i40e_aq_desc desc;
  187. struct i40e_aqc_mac_address_write *cmd_data =
  188. (struct i40e_aqc_mac_address_write *)&desc.params.raw;
  189. i40e_status status;
  190. i40e_fill_default_direct_cmd_desc(&desc,
  191. i40e_aqc_opc_mac_address_write);
  192. cmd_data->command_flags = cpu_to_le16(flags);
  193. memcpy(&cmd_data->mac_sal, &mac_addr[0], 4);
  194. memcpy(&cmd_data->mac_sah, &mac_addr[4], 2);
  195. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  196. return status;
  197. }
  198. /**
  199. * i40e_get_mac_addr - get MAC address
  200. * @hw: pointer to the HW structure
  201. * @mac_addr: pointer to MAC address
  202. *
  203. * Reads the adapter's MAC address from register
  204. **/
  205. i40e_status i40e_get_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
  206. {
  207. struct i40e_aqc_mac_address_read_data addrs;
  208. i40e_status status;
  209. u16 flags = 0;
  210. status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
  211. if (flags & I40E_AQC_LAN_ADDR_VALID)
  212. memcpy(mac_addr, &addrs.pf_lan_mac, sizeof(addrs.pf_lan_mac));
  213. return status;
  214. }
  215. /**
  216. * i40e_validate_mac_addr - Validate MAC address
  217. * @mac_addr: pointer to MAC address
  218. *
  219. * Tests a MAC address to ensure it is a valid Individual Address
  220. **/
  221. i40e_status i40e_validate_mac_addr(u8 *mac_addr)
  222. {
  223. i40e_status status = 0;
  224. /* Make sure it is not a multicast address */
  225. if (I40E_IS_MULTICAST(mac_addr)) {
  226. hw_dbg(hw, "MAC address is multicast\n");
  227. status = I40E_ERR_INVALID_MAC_ADDR;
  228. /* Not a broadcast address */
  229. } else if (I40E_IS_BROADCAST(mac_addr)) {
  230. hw_dbg(hw, "MAC address is broadcast\n");
  231. status = I40E_ERR_INVALID_MAC_ADDR;
  232. /* Reject the zero address */
  233. } else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
  234. mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0) {
  235. hw_dbg(hw, "MAC address is all zeros\n");
  236. status = I40E_ERR_INVALID_MAC_ADDR;
  237. }
  238. return status;
  239. }
  240. /**
  241. * i40e_get_media_type - Gets media type
  242. * @hw: pointer to the hardware structure
  243. **/
  244. static enum i40e_media_type i40e_get_media_type(struct i40e_hw *hw)
  245. {
  246. enum i40e_media_type media;
  247. switch (hw->phy.link_info.phy_type) {
  248. case I40E_PHY_TYPE_10GBASE_SR:
  249. case I40E_PHY_TYPE_10GBASE_LR:
  250. case I40E_PHY_TYPE_40GBASE_SR4:
  251. case I40E_PHY_TYPE_40GBASE_LR4:
  252. media = I40E_MEDIA_TYPE_FIBER;
  253. break;
  254. case I40E_PHY_TYPE_100BASE_TX:
  255. case I40E_PHY_TYPE_1000BASE_T:
  256. case I40E_PHY_TYPE_10GBASE_T:
  257. media = I40E_MEDIA_TYPE_BASET;
  258. break;
  259. case I40E_PHY_TYPE_10GBASE_CR1_CU:
  260. case I40E_PHY_TYPE_40GBASE_CR4_CU:
  261. case I40E_PHY_TYPE_10GBASE_CR1:
  262. case I40E_PHY_TYPE_40GBASE_CR4:
  263. case I40E_PHY_TYPE_10GBASE_SFPP_CU:
  264. media = I40E_MEDIA_TYPE_DA;
  265. break;
  266. case I40E_PHY_TYPE_1000BASE_KX:
  267. case I40E_PHY_TYPE_10GBASE_KX4:
  268. case I40E_PHY_TYPE_10GBASE_KR:
  269. case I40E_PHY_TYPE_40GBASE_KR4:
  270. media = I40E_MEDIA_TYPE_BACKPLANE;
  271. break;
  272. case I40E_PHY_TYPE_SGMII:
  273. case I40E_PHY_TYPE_XAUI:
  274. case I40E_PHY_TYPE_XFI:
  275. case I40E_PHY_TYPE_XLAUI:
  276. case I40E_PHY_TYPE_XLPPI:
  277. default:
  278. media = I40E_MEDIA_TYPE_UNKNOWN;
  279. break;
  280. }
  281. return media;
  282. }
  283. #define I40E_PF_RESET_WAIT_COUNT_A0 200
  284. #define I40E_PF_RESET_WAIT_COUNT 10
  285. /**
  286. * i40e_pf_reset - Reset the PF
  287. * @hw: pointer to the hardware structure
  288. *
  289. * Assuming someone else has triggered a global reset,
  290. * assure the global reset is complete and then reset the PF
  291. **/
  292. i40e_status i40e_pf_reset(struct i40e_hw *hw)
  293. {
  294. u32 cnt = 0;
  295. u32 reg = 0;
  296. u32 grst_del;
  297. /* Poll for Global Reset steady state in case of recent GRST.
  298. * The grst delay value is in 100ms units, and we'll wait a
  299. * couple counts longer to be sure we don't just miss the end.
  300. */
  301. grst_del = rd32(hw, I40E_GLGEN_RSTCTL) & I40E_GLGEN_RSTCTL_GRSTDEL_MASK
  302. >> I40E_GLGEN_RSTCTL_GRSTDEL_SHIFT;
  303. for (cnt = 0; cnt < grst_del + 2; cnt++) {
  304. reg = rd32(hw, I40E_GLGEN_RSTAT);
  305. if (!(reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK))
  306. break;
  307. msleep(100);
  308. }
  309. if (reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
  310. hw_dbg(hw, "Global reset polling failed to complete.\n");
  311. return I40E_ERR_RESET_FAILED;
  312. }
  313. /* Determine the PF number based on the PCI fn */
  314. reg = rd32(hw, I40E_GLPCI_CAPSUP);
  315. if (reg & I40E_GLPCI_CAPSUP_ARI_EN_MASK)
  316. hw->pf_id = (u8)((hw->bus.device << 3) | hw->bus.func);
  317. else
  318. hw->pf_id = (u8)hw->bus.func;
  319. /* If there was a Global Reset in progress when we got here,
  320. * we don't need to do the PF Reset
  321. */
  322. if (!cnt) {
  323. if (hw->revision_id == 0)
  324. cnt = I40E_PF_RESET_WAIT_COUNT_A0;
  325. else
  326. cnt = I40E_PF_RESET_WAIT_COUNT;
  327. reg = rd32(hw, I40E_PFGEN_CTRL);
  328. wr32(hw, I40E_PFGEN_CTRL,
  329. (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
  330. for (; cnt; cnt--) {
  331. reg = rd32(hw, I40E_PFGEN_CTRL);
  332. if (!(reg & I40E_PFGEN_CTRL_PFSWR_MASK))
  333. break;
  334. usleep_range(1000, 2000);
  335. }
  336. if (reg & I40E_PFGEN_CTRL_PFSWR_MASK) {
  337. hw_dbg(hw, "PF reset polling failed to complete.\n");
  338. return I40E_ERR_RESET_FAILED;
  339. }
  340. }
  341. i40e_clear_pxe_mode(hw);
  342. return 0;
  343. }
  344. /**
  345. * i40e_clear_pxe_mode - clear pxe operations mode
  346. * @hw: pointer to the hw struct
  347. *
  348. * Make sure all PXE mode settings are cleared, including things
  349. * like descriptor fetch/write-back mode.
  350. **/
  351. void i40e_clear_pxe_mode(struct i40e_hw *hw)
  352. {
  353. u32 reg;
  354. /* Clear single descriptor fetch/write-back mode */
  355. reg = rd32(hw, I40E_GLLAN_RCTL_0);
  356. if (hw->revision_id == 0) {
  357. /* As a work around clear PXE_MODE instead of setting it */
  358. wr32(hw, I40E_GLLAN_RCTL_0, (reg & (~I40E_GLLAN_RCTL_0_PXE_MODE_MASK)));
  359. } else {
  360. wr32(hw, I40E_GLLAN_RCTL_0, (reg | I40E_GLLAN_RCTL_0_PXE_MODE_MASK));
  361. }
  362. }
  363. /**
  364. * i40e_led_get - return current on/off mode
  365. * @hw: pointer to the hw struct
  366. *
  367. * The value returned is the 'mode' field as defined in the
  368. * GPIO register definitions: 0x0 = off, 0xf = on, and other
  369. * values are variations of possible behaviors relating to
  370. * blink, link, and wire.
  371. **/
  372. u32 i40e_led_get(struct i40e_hw *hw)
  373. {
  374. u32 gpio_val = 0;
  375. u32 mode = 0;
  376. u32 port;
  377. int i;
  378. for (i = 0; i < I40E_HW_CAP_MAX_GPIO; i++) {
  379. if (!hw->func_caps.led[i])
  380. continue;
  381. gpio_val = rd32(hw, I40E_GLGEN_GPIO_CTL(i));
  382. port = (gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_MASK)
  383. >> I40E_GLGEN_GPIO_CTL_PRT_NUM_SHIFT;
  384. if (port != hw->port)
  385. continue;
  386. mode = (gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK)
  387. >> I40E_GLGEN_GPIO_CTL_INT_MODE_SHIFT;
  388. break;
  389. }
  390. return mode;
  391. }
  392. /**
  393. * i40e_led_set - set new on/off mode
  394. * @hw: pointer to the hw struct
  395. * @mode: 0=off, else on (see EAS for mode details)
  396. **/
  397. void i40e_led_set(struct i40e_hw *hw, u32 mode)
  398. {
  399. u32 gpio_val = 0;
  400. u32 led_mode = 0;
  401. u32 port;
  402. int i;
  403. for (i = 0; i < I40E_HW_CAP_MAX_GPIO; i++) {
  404. if (!hw->func_caps.led[i])
  405. continue;
  406. gpio_val = rd32(hw, I40E_GLGEN_GPIO_CTL(i));
  407. port = (gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_MASK)
  408. >> I40E_GLGEN_GPIO_CTL_PRT_NUM_SHIFT;
  409. if (port != hw->port)
  410. continue;
  411. led_mode = (mode << I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT) &
  412. I40E_GLGEN_GPIO_CTL_LED_MODE_MASK;
  413. gpio_val &= ~I40E_GLGEN_GPIO_CTL_LED_MODE_MASK;
  414. gpio_val |= led_mode;
  415. wr32(hw, I40E_GLGEN_GPIO_CTL(i), gpio_val);
  416. }
  417. }
  418. /* Admin command wrappers */
  419. /**
  420. * i40e_aq_queue_shutdown
  421. * @hw: pointer to the hw struct
  422. * @unloading: is the driver unloading itself
  423. *
  424. * Tell the Firmware that we're shutting down the AdminQ and whether
  425. * or not the driver is unloading as well.
  426. **/
  427. i40e_status i40e_aq_queue_shutdown(struct i40e_hw *hw,
  428. bool unloading)
  429. {
  430. struct i40e_aq_desc desc;
  431. struct i40e_aqc_queue_shutdown *cmd =
  432. (struct i40e_aqc_queue_shutdown *)&desc.params.raw;
  433. i40e_status status;
  434. i40e_fill_default_direct_cmd_desc(&desc,
  435. i40e_aqc_opc_queue_shutdown);
  436. if (unloading)
  437. cmd->driver_unloading = cpu_to_le32(I40E_AQ_DRIVER_UNLOADING);
  438. status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
  439. return status;
  440. }
  441. /**
  442. * i40e_aq_set_link_restart_an
  443. * @hw: pointer to the hw struct
  444. * @cmd_details: pointer to command details structure or NULL
  445. *
  446. * Sets up the link and restarts the Auto-Negotiation over the link.
  447. **/
  448. i40e_status i40e_aq_set_link_restart_an(struct i40e_hw *hw,
  449. struct i40e_asq_cmd_details *cmd_details)
  450. {
  451. struct i40e_aq_desc desc;
  452. struct i40e_aqc_set_link_restart_an *cmd =
  453. (struct i40e_aqc_set_link_restart_an *)&desc.params.raw;
  454. i40e_status status;
  455. i40e_fill_default_direct_cmd_desc(&desc,
  456. i40e_aqc_opc_set_link_restart_an);
  457. cmd->command = I40E_AQ_PHY_RESTART_AN;
  458. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  459. return status;
  460. }
  461. /**
  462. * i40e_aq_get_link_info
  463. * @hw: pointer to the hw struct
  464. * @enable_lse: enable/disable LinkStatusEvent reporting
  465. * @link: pointer to link status structure - optional
  466. * @cmd_details: pointer to command details structure or NULL
  467. *
  468. * Returns the link status of the adapter.
  469. **/
  470. i40e_status i40e_aq_get_link_info(struct i40e_hw *hw,
  471. bool enable_lse, struct i40e_link_status *link,
  472. struct i40e_asq_cmd_details *cmd_details)
  473. {
  474. struct i40e_aq_desc desc;
  475. struct i40e_aqc_get_link_status *resp =
  476. (struct i40e_aqc_get_link_status *)&desc.params.raw;
  477. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  478. i40e_status status;
  479. u16 command_flags;
  480. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_link_status);
  481. if (enable_lse)
  482. command_flags = I40E_AQ_LSE_ENABLE;
  483. else
  484. command_flags = I40E_AQ_LSE_DISABLE;
  485. resp->command_flags = cpu_to_le16(command_flags);
  486. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  487. if (status)
  488. goto aq_get_link_info_exit;
  489. /* save off old link status information */
  490. memcpy(&hw->phy.link_info_old, hw_link_info,
  491. sizeof(struct i40e_link_status));
  492. /* update link status */
  493. hw_link_info->phy_type = (enum i40e_aq_phy_type)resp->phy_type;
  494. hw->phy.media_type = i40e_get_media_type(hw);
  495. hw_link_info->link_speed = (enum i40e_aq_link_speed)resp->link_speed;
  496. hw_link_info->link_info = resp->link_info;
  497. hw_link_info->an_info = resp->an_info;
  498. hw_link_info->ext_info = resp->ext_info;
  499. hw_link_info->loopback = resp->loopback;
  500. if (resp->command_flags & cpu_to_le16(I40E_AQ_LSE_ENABLE))
  501. hw_link_info->lse_enable = true;
  502. else
  503. hw_link_info->lse_enable = false;
  504. /* save link status information */
  505. if (link)
  506. *link = *hw_link_info;
  507. /* flag cleared so helper functions don't call AQ again */
  508. hw->phy.get_link_info = false;
  509. aq_get_link_info_exit:
  510. return status;
  511. }
  512. /**
  513. * i40e_aq_add_vsi
  514. * @hw: pointer to the hw struct
  515. * @vsi: pointer to a vsi context struct
  516. * @cmd_details: pointer to command details structure or NULL
  517. *
  518. * Add a VSI context to the hardware.
  519. **/
  520. i40e_status i40e_aq_add_vsi(struct i40e_hw *hw,
  521. struct i40e_vsi_context *vsi_ctx,
  522. struct i40e_asq_cmd_details *cmd_details)
  523. {
  524. struct i40e_aq_desc desc;
  525. struct i40e_aqc_add_get_update_vsi *cmd =
  526. (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
  527. struct i40e_aqc_add_get_update_vsi_completion *resp =
  528. (struct i40e_aqc_add_get_update_vsi_completion *)
  529. &desc.params.raw;
  530. i40e_status status;
  531. i40e_fill_default_direct_cmd_desc(&desc,
  532. i40e_aqc_opc_add_vsi);
  533. cmd->uplink_seid = cpu_to_le16(vsi_ctx->uplink_seid);
  534. cmd->connection_type = vsi_ctx->connection_type;
  535. cmd->vf_id = vsi_ctx->vf_num;
  536. cmd->vsi_flags = cpu_to_le16(vsi_ctx->flags);
  537. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  538. if (sizeof(vsi_ctx->info) > I40E_AQ_LARGE_BUF)
  539. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  540. status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
  541. sizeof(vsi_ctx->info), cmd_details);
  542. if (status)
  543. goto aq_add_vsi_exit;
  544. vsi_ctx->seid = le16_to_cpu(resp->seid);
  545. vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
  546. vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
  547. vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
  548. aq_add_vsi_exit:
  549. return status;
  550. }
  551. /**
  552. * i40e_aq_set_vsi_unicast_promiscuous
  553. * @hw: pointer to the hw struct
  554. * @seid: vsi number
  555. * @set: set unicast promiscuous enable/disable
  556. * @cmd_details: pointer to command details structure or NULL
  557. **/
  558. i40e_status i40e_aq_set_vsi_unicast_promiscuous(struct i40e_hw *hw,
  559. u16 seid, bool set, struct i40e_asq_cmd_details *cmd_details)
  560. {
  561. struct i40e_aq_desc desc;
  562. struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
  563. (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
  564. i40e_status status;
  565. u16 flags = 0;
  566. i40e_fill_default_direct_cmd_desc(&desc,
  567. i40e_aqc_opc_set_vsi_promiscuous_modes);
  568. if (set)
  569. flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
  570. cmd->promiscuous_flags = cpu_to_le16(flags);
  571. cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
  572. cmd->seid = cpu_to_le16(seid);
  573. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  574. return status;
  575. }
  576. /**
  577. * i40e_aq_set_vsi_multicast_promiscuous
  578. * @hw: pointer to the hw struct
  579. * @seid: vsi number
  580. * @set: set multicast promiscuous enable/disable
  581. * @cmd_details: pointer to command details structure or NULL
  582. **/
  583. i40e_status i40e_aq_set_vsi_multicast_promiscuous(struct i40e_hw *hw,
  584. u16 seid, bool set, struct i40e_asq_cmd_details *cmd_details)
  585. {
  586. struct i40e_aq_desc desc;
  587. struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
  588. (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
  589. i40e_status status;
  590. u16 flags = 0;
  591. i40e_fill_default_direct_cmd_desc(&desc,
  592. i40e_aqc_opc_set_vsi_promiscuous_modes);
  593. if (set)
  594. flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
  595. cmd->promiscuous_flags = cpu_to_le16(flags);
  596. cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
  597. cmd->seid = cpu_to_le16(seid);
  598. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  599. return status;
  600. }
  601. /**
  602. * i40e_aq_set_vsi_broadcast
  603. * @hw: pointer to the hw struct
  604. * @seid: vsi number
  605. * @set_filter: true to set filter, false to clear filter
  606. * @cmd_details: pointer to command details structure or NULL
  607. *
  608. * Set or clear the broadcast promiscuous flag (filter) for a given VSI.
  609. **/
  610. i40e_status i40e_aq_set_vsi_broadcast(struct i40e_hw *hw,
  611. u16 seid, bool set_filter,
  612. struct i40e_asq_cmd_details *cmd_details)
  613. {
  614. struct i40e_aq_desc desc;
  615. struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
  616. (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
  617. i40e_status status;
  618. i40e_fill_default_direct_cmd_desc(&desc,
  619. i40e_aqc_opc_set_vsi_promiscuous_modes);
  620. if (set_filter)
  621. cmd->promiscuous_flags
  622. |= cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
  623. else
  624. cmd->promiscuous_flags
  625. &= cpu_to_le16(~I40E_AQC_SET_VSI_PROMISC_BROADCAST);
  626. cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
  627. cmd->seid = cpu_to_le16(seid);
  628. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  629. return status;
  630. }
  631. /**
  632. * i40e_get_vsi_params - get VSI configuration info
  633. * @hw: pointer to the hw struct
  634. * @vsi: pointer to a vsi context struct
  635. * @cmd_details: pointer to command details structure or NULL
  636. **/
  637. i40e_status i40e_aq_get_vsi_params(struct i40e_hw *hw,
  638. struct i40e_vsi_context *vsi_ctx,
  639. struct i40e_asq_cmd_details *cmd_details)
  640. {
  641. struct i40e_aq_desc desc;
  642. struct i40e_aqc_switch_seid *cmd =
  643. (struct i40e_aqc_switch_seid *)&desc.params.raw;
  644. struct i40e_aqc_add_get_update_vsi_completion *resp =
  645. (struct i40e_aqc_add_get_update_vsi_completion *)
  646. &desc.params.raw;
  647. i40e_status status;
  648. i40e_fill_default_direct_cmd_desc(&desc,
  649. i40e_aqc_opc_get_vsi_parameters);
  650. cmd->seid = cpu_to_le16(vsi_ctx->seid);
  651. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  652. if (sizeof(vsi_ctx->info) > I40E_AQ_LARGE_BUF)
  653. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  654. status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
  655. sizeof(vsi_ctx->info), NULL);
  656. if (status)
  657. goto aq_get_vsi_params_exit;
  658. vsi_ctx->seid = le16_to_cpu(resp->seid);
  659. vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
  660. vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
  661. vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
  662. aq_get_vsi_params_exit:
  663. return status;
  664. }
  665. /**
  666. * i40e_aq_update_vsi_params
  667. * @hw: pointer to the hw struct
  668. * @vsi: pointer to a vsi context struct
  669. * @cmd_details: pointer to command details structure or NULL
  670. *
  671. * Update a VSI context.
  672. **/
  673. i40e_status i40e_aq_update_vsi_params(struct i40e_hw *hw,
  674. struct i40e_vsi_context *vsi_ctx,
  675. struct i40e_asq_cmd_details *cmd_details)
  676. {
  677. struct i40e_aq_desc desc;
  678. struct i40e_aqc_switch_seid *cmd =
  679. (struct i40e_aqc_switch_seid *)&desc.params.raw;
  680. i40e_status status;
  681. i40e_fill_default_direct_cmd_desc(&desc,
  682. i40e_aqc_opc_update_vsi_parameters);
  683. cmd->seid = cpu_to_le16(vsi_ctx->seid);
  684. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  685. if (sizeof(vsi_ctx->info) > I40E_AQ_LARGE_BUF)
  686. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  687. status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
  688. sizeof(vsi_ctx->info), cmd_details);
  689. return status;
  690. }
  691. /**
  692. * i40e_aq_get_switch_config
  693. * @hw: pointer to the hardware structure
  694. * @buf: pointer to the result buffer
  695. * @buf_size: length of input buffer
  696. * @start_seid: seid to start for the report, 0 == beginning
  697. * @cmd_details: pointer to command details structure or NULL
  698. *
  699. * Fill the buf with switch configuration returned from AdminQ command
  700. **/
  701. i40e_status i40e_aq_get_switch_config(struct i40e_hw *hw,
  702. struct i40e_aqc_get_switch_config_resp *buf,
  703. u16 buf_size, u16 *start_seid,
  704. struct i40e_asq_cmd_details *cmd_details)
  705. {
  706. struct i40e_aq_desc desc;
  707. struct i40e_aqc_switch_seid *scfg =
  708. (struct i40e_aqc_switch_seid *)&desc.params.raw;
  709. i40e_status status;
  710. i40e_fill_default_direct_cmd_desc(&desc,
  711. i40e_aqc_opc_get_switch_config);
  712. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  713. if (buf_size > I40E_AQ_LARGE_BUF)
  714. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  715. scfg->seid = cpu_to_le16(*start_seid);
  716. status = i40e_asq_send_command(hw, &desc, buf, buf_size, cmd_details);
  717. *start_seid = le16_to_cpu(scfg->seid);
  718. return status;
  719. }
  720. /**
  721. * i40e_aq_get_firmware_version
  722. * @hw: pointer to the hw struct
  723. * @fw_major_version: firmware major version
  724. * @fw_minor_version: firmware minor version
  725. * @api_major_version: major queue version
  726. * @api_minor_version: minor queue version
  727. * @cmd_details: pointer to command details structure or NULL
  728. *
  729. * Get the firmware version from the admin queue commands
  730. **/
  731. i40e_status i40e_aq_get_firmware_version(struct i40e_hw *hw,
  732. u16 *fw_major_version, u16 *fw_minor_version,
  733. u16 *api_major_version, u16 *api_minor_version,
  734. struct i40e_asq_cmd_details *cmd_details)
  735. {
  736. struct i40e_aq_desc desc;
  737. struct i40e_aqc_get_version *resp =
  738. (struct i40e_aqc_get_version *)&desc.params.raw;
  739. i40e_status status;
  740. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_version);
  741. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  742. if (!status) {
  743. if (fw_major_version != NULL)
  744. *fw_major_version = le16_to_cpu(resp->fw_major);
  745. if (fw_minor_version != NULL)
  746. *fw_minor_version = le16_to_cpu(resp->fw_minor);
  747. if (api_major_version != NULL)
  748. *api_major_version = le16_to_cpu(resp->api_major);
  749. if (api_minor_version != NULL)
  750. *api_minor_version = le16_to_cpu(resp->api_minor);
  751. }
  752. return status;
  753. }
  754. /**
  755. * i40e_aq_send_driver_version
  756. * @hw: pointer to the hw struct
  757. * @event: driver event: driver ok, start or stop
  758. * @dv: driver's major, minor version
  759. * @cmd_details: pointer to command details structure or NULL
  760. *
  761. * Send the driver version to the firmware
  762. **/
  763. i40e_status i40e_aq_send_driver_version(struct i40e_hw *hw,
  764. struct i40e_driver_version *dv,
  765. struct i40e_asq_cmd_details *cmd_details)
  766. {
  767. struct i40e_aq_desc desc;
  768. struct i40e_aqc_driver_version *cmd =
  769. (struct i40e_aqc_driver_version *)&desc.params.raw;
  770. i40e_status status;
  771. if (dv == NULL)
  772. return I40E_ERR_PARAM;
  773. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_driver_version);
  774. desc.flags |= cpu_to_le16(I40E_AQ_FLAG_SI);
  775. cmd->driver_major_ver = dv->major_version;
  776. cmd->driver_minor_ver = dv->minor_version;
  777. cmd->driver_build_ver = dv->build_version;
  778. cmd->driver_subbuild_ver = dv->subbuild_version;
  779. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  780. return status;
  781. }
  782. /**
  783. * i40e_get_link_status - get status of the HW network link
  784. * @hw: pointer to the hw struct
  785. *
  786. * Returns true if link is up, false if link is down.
  787. *
  788. * Side effect: LinkStatusEvent reporting becomes enabled
  789. **/
  790. bool i40e_get_link_status(struct i40e_hw *hw)
  791. {
  792. i40e_status status = 0;
  793. bool link_status = false;
  794. if (hw->phy.get_link_info) {
  795. status = i40e_aq_get_link_info(hw, true, NULL, NULL);
  796. if (status)
  797. goto i40e_get_link_status_exit;
  798. }
  799. link_status = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
  800. i40e_get_link_status_exit:
  801. return link_status;
  802. }
  803. /**
  804. * i40e_aq_add_veb - Insert a VEB between the VSI and the MAC
  805. * @hw: pointer to the hw struct
  806. * @uplink_seid: the MAC or other gizmo SEID
  807. * @downlink_seid: the VSI SEID
  808. * @enabled_tc: bitmap of TCs to be enabled
  809. * @default_port: true for default port VSI, false for control port
  810. * @enable_l2_filtering: true to add L2 filter table rules to regular forwarding rules for cloud support
  811. * @veb_seid: pointer to where to put the resulting VEB SEID
  812. * @cmd_details: pointer to command details structure or NULL
  813. *
  814. * This asks the FW to add a VEB between the uplink and downlink
  815. * elements. If the uplink SEID is 0, this will be a floating VEB.
  816. **/
  817. i40e_status i40e_aq_add_veb(struct i40e_hw *hw, u16 uplink_seid,
  818. u16 downlink_seid, u8 enabled_tc,
  819. bool default_port, bool enable_l2_filtering,
  820. u16 *veb_seid,
  821. struct i40e_asq_cmd_details *cmd_details)
  822. {
  823. struct i40e_aq_desc desc;
  824. struct i40e_aqc_add_veb *cmd =
  825. (struct i40e_aqc_add_veb *)&desc.params.raw;
  826. struct i40e_aqc_add_veb_completion *resp =
  827. (struct i40e_aqc_add_veb_completion *)&desc.params.raw;
  828. i40e_status status;
  829. u16 veb_flags = 0;
  830. /* SEIDs need to either both be set or both be 0 for floating VEB */
  831. if (!!uplink_seid != !!downlink_seid)
  832. return I40E_ERR_PARAM;
  833. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_veb);
  834. cmd->uplink_seid = cpu_to_le16(uplink_seid);
  835. cmd->downlink_seid = cpu_to_le16(downlink_seid);
  836. cmd->enable_tcs = enabled_tc;
  837. if (!uplink_seid)
  838. veb_flags |= I40E_AQC_ADD_VEB_FLOATING;
  839. if (default_port)
  840. veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DEFAULT;
  841. else
  842. veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DATA;
  843. if (enable_l2_filtering)
  844. veb_flags |= I40E_AQC_ADD_VEB_ENABLE_L2_FILTER;
  845. cmd->veb_flags = cpu_to_le16(veb_flags);
  846. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  847. if (!status && veb_seid)
  848. *veb_seid = le16_to_cpu(resp->veb_seid);
  849. return status;
  850. }
  851. /**
  852. * i40e_aq_get_veb_parameters - Retrieve VEB parameters
  853. * @hw: pointer to the hw struct
  854. * @veb_seid: the SEID of the VEB to query
  855. * @switch_id: the uplink switch id
  856. * @floating_veb: set to true if the VEB is floating
  857. * @statistic_index: index of the stats counter block for this VEB
  858. * @vebs_used: number of VEB's used by function
  859. * @vebs_unallocated: total VEB's not reserved by any function
  860. * @cmd_details: pointer to command details structure or NULL
  861. *
  862. * This retrieves the parameters for a particular VEB, specified by
  863. * uplink_seid, and returns them to the caller.
  864. **/
  865. i40e_status i40e_aq_get_veb_parameters(struct i40e_hw *hw,
  866. u16 veb_seid, u16 *switch_id,
  867. bool *floating, u16 *statistic_index,
  868. u16 *vebs_used, u16 *vebs_free,
  869. struct i40e_asq_cmd_details *cmd_details)
  870. {
  871. struct i40e_aq_desc desc;
  872. struct i40e_aqc_get_veb_parameters_completion *cmd_resp =
  873. (struct i40e_aqc_get_veb_parameters_completion *)
  874. &desc.params.raw;
  875. i40e_status status;
  876. if (veb_seid == 0)
  877. return I40E_ERR_PARAM;
  878. i40e_fill_default_direct_cmd_desc(&desc,
  879. i40e_aqc_opc_get_veb_parameters);
  880. cmd_resp->seid = cpu_to_le16(veb_seid);
  881. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  882. if (status)
  883. goto get_veb_exit;
  884. if (switch_id)
  885. *switch_id = le16_to_cpu(cmd_resp->switch_id);
  886. if (statistic_index)
  887. *statistic_index = le16_to_cpu(cmd_resp->statistic_index);
  888. if (vebs_used)
  889. *vebs_used = le16_to_cpu(cmd_resp->vebs_used);
  890. if (vebs_free)
  891. *vebs_free = le16_to_cpu(cmd_resp->vebs_free);
  892. if (floating) {
  893. u16 flags = le16_to_cpu(cmd_resp->veb_flags);
  894. if (flags & I40E_AQC_ADD_VEB_FLOATING)
  895. *floating = true;
  896. else
  897. *floating = false;
  898. }
  899. get_veb_exit:
  900. return status;
  901. }
  902. /**
  903. * i40e_aq_add_macvlan
  904. * @hw: pointer to the hw struct
  905. * @seid: VSI for the mac address
  906. * @mv_list: list of macvlans to be added
  907. * @count: length of the list
  908. * @cmd_details: pointer to command details structure or NULL
  909. *
  910. * Add MAC/VLAN addresses to the HW filtering
  911. **/
  912. i40e_status i40e_aq_add_macvlan(struct i40e_hw *hw, u16 seid,
  913. struct i40e_aqc_add_macvlan_element_data *mv_list,
  914. u16 count, struct i40e_asq_cmd_details *cmd_details)
  915. {
  916. struct i40e_aq_desc desc;
  917. struct i40e_aqc_macvlan *cmd =
  918. (struct i40e_aqc_macvlan *)&desc.params.raw;
  919. i40e_status status;
  920. u16 buf_size;
  921. if (count == 0 || !mv_list || !hw)
  922. return I40E_ERR_PARAM;
  923. buf_size = count * sizeof(struct i40e_aqc_add_macvlan_element_data);
  924. /* prep the rest of the request */
  925. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_macvlan);
  926. cmd->num_addresses = cpu_to_le16(count);
  927. cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
  928. cmd->seid[1] = 0;
  929. cmd->seid[2] = 0;
  930. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  931. if (buf_size > I40E_AQ_LARGE_BUF)
  932. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  933. status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
  934. cmd_details);
  935. return status;
  936. }
  937. /**
  938. * i40e_aq_remove_macvlan
  939. * @hw: pointer to the hw struct
  940. * @seid: VSI for the mac address
  941. * @mv_list: list of macvlans to be removed
  942. * @count: length of the list
  943. * @cmd_details: pointer to command details structure or NULL
  944. *
  945. * Remove MAC/VLAN addresses from the HW filtering
  946. **/
  947. i40e_status i40e_aq_remove_macvlan(struct i40e_hw *hw, u16 seid,
  948. struct i40e_aqc_remove_macvlan_element_data *mv_list,
  949. u16 count, struct i40e_asq_cmd_details *cmd_details)
  950. {
  951. struct i40e_aq_desc desc;
  952. struct i40e_aqc_macvlan *cmd =
  953. (struct i40e_aqc_macvlan *)&desc.params.raw;
  954. i40e_status status;
  955. u16 buf_size;
  956. if (count == 0 || !mv_list || !hw)
  957. return I40E_ERR_PARAM;
  958. buf_size = count * sizeof(struct i40e_aqc_remove_macvlan_element_data);
  959. /* prep the rest of the request */
  960. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_macvlan);
  961. cmd->num_addresses = cpu_to_le16(count);
  962. cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
  963. cmd->seid[1] = 0;
  964. cmd->seid[2] = 0;
  965. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  966. if (buf_size > I40E_AQ_LARGE_BUF)
  967. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  968. status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
  969. cmd_details);
  970. return status;
  971. }
  972. /**
  973. * i40e_aq_add_vlan - Add VLAN ids to the HW filtering
  974. * @hw: pointer to the hw struct
  975. * @seid: VSI for the vlan filters
  976. * @v_list: list of vlan filters to be added
  977. * @count: length of the list
  978. * @cmd_details: pointer to command details structure or NULL
  979. **/
  980. i40e_status i40e_aq_add_vlan(struct i40e_hw *hw, u16 seid,
  981. struct i40e_aqc_add_remove_vlan_element_data *v_list,
  982. u8 count, struct i40e_asq_cmd_details *cmd_details)
  983. {
  984. struct i40e_aq_desc desc;
  985. struct i40e_aqc_macvlan *cmd =
  986. (struct i40e_aqc_macvlan *)&desc.params.raw;
  987. i40e_status status;
  988. u16 buf_size;
  989. if (count == 0 || !v_list || !hw)
  990. return I40E_ERR_PARAM;
  991. buf_size = count * sizeof(struct i40e_aqc_add_remove_vlan_element_data);
  992. /* prep the rest of the request */
  993. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_vlan);
  994. cmd->num_addresses = cpu_to_le16(count);
  995. cmd->seid[0] = cpu_to_le16(seid | I40E_AQC_MACVLAN_CMD_SEID_VALID);
  996. cmd->seid[1] = 0;
  997. cmd->seid[2] = 0;
  998. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  999. if (buf_size > I40E_AQ_LARGE_BUF)
  1000. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1001. status = i40e_asq_send_command(hw, &desc, v_list, buf_size,
  1002. cmd_details);
  1003. return status;
  1004. }
  1005. /**
  1006. * i40e_aq_remove_vlan - Remove VLANs from the HW filtering
  1007. * @hw: pointer to the hw struct
  1008. * @seid: VSI for the vlan filters
  1009. * @v_list: list of macvlans to be removed
  1010. * @count: length of the list
  1011. * @cmd_details: pointer to command details structure or NULL
  1012. **/
  1013. i40e_status i40e_aq_remove_vlan(struct i40e_hw *hw, u16 seid,
  1014. struct i40e_aqc_add_remove_vlan_element_data *v_list,
  1015. u8 count, struct i40e_asq_cmd_details *cmd_details)
  1016. {
  1017. struct i40e_aq_desc desc;
  1018. struct i40e_aqc_macvlan *cmd =
  1019. (struct i40e_aqc_macvlan *)&desc.params.raw;
  1020. i40e_status status;
  1021. u16 buf_size;
  1022. if (count == 0 || !v_list || !hw)
  1023. return I40E_ERR_PARAM;
  1024. buf_size = count * sizeof(struct i40e_aqc_add_remove_vlan_element_data);
  1025. /* prep the rest of the request */
  1026. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_vlan);
  1027. cmd->num_addresses = cpu_to_le16(count);
  1028. cmd->seid[0] = cpu_to_le16(seid | I40E_AQC_MACVLAN_CMD_SEID_VALID);
  1029. cmd->seid[1] = 0;
  1030. cmd->seid[2] = 0;
  1031. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
  1032. if (buf_size > I40E_AQ_LARGE_BUF)
  1033. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1034. status = i40e_asq_send_command(hw, &desc, v_list, buf_size,
  1035. cmd_details);
  1036. return status;
  1037. }
  1038. /**
  1039. * i40e_aq_send_msg_to_vf
  1040. * @hw: pointer to the hardware structure
  1041. * @vfid: vf id to send msg
  1042. * @msg: pointer to the msg buffer
  1043. * @msglen: msg length
  1044. * @cmd_details: pointer to command details
  1045. *
  1046. * send msg to vf
  1047. **/
  1048. i40e_status i40e_aq_send_msg_to_vf(struct i40e_hw *hw, u16 vfid,
  1049. u32 v_opcode, u32 v_retval, u8 *msg, u16 msglen,
  1050. struct i40e_asq_cmd_details *cmd_details)
  1051. {
  1052. struct i40e_aq_desc desc;
  1053. struct i40e_aqc_pf_vf_message *cmd =
  1054. (struct i40e_aqc_pf_vf_message *)&desc.params.raw;
  1055. i40e_status status;
  1056. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_vf);
  1057. cmd->id = cpu_to_le32(vfid);
  1058. desc.cookie_high = cpu_to_le32(v_opcode);
  1059. desc.cookie_low = cpu_to_le32(v_retval);
  1060. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_SI);
  1061. if (msglen) {
  1062. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
  1063. I40E_AQ_FLAG_RD));
  1064. if (msglen > I40E_AQ_LARGE_BUF)
  1065. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1066. desc.datalen = cpu_to_le16(msglen);
  1067. }
  1068. status = i40e_asq_send_command(hw, &desc, msg, msglen, cmd_details);
  1069. return status;
  1070. }
  1071. /**
  1072. * i40e_aq_set_hmc_resource_profile
  1073. * @hw: pointer to the hw struct
  1074. * @profile: type of profile the HMC is to be set as
  1075. * @pe_vf_enabled_count: the number of PE enabled VFs the system has
  1076. * @cmd_details: pointer to command details structure or NULL
  1077. *
  1078. * set the HMC profile of the device.
  1079. **/
  1080. i40e_status i40e_aq_set_hmc_resource_profile(struct i40e_hw *hw,
  1081. enum i40e_aq_hmc_profile profile,
  1082. u8 pe_vf_enabled_count,
  1083. struct i40e_asq_cmd_details *cmd_details)
  1084. {
  1085. struct i40e_aq_desc desc;
  1086. struct i40e_aq_get_set_hmc_resource_profile *cmd =
  1087. (struct i40e_aq_get_set_hmc_resource_profile *)&desc.params.raw;
  1088. i40e_status status;
  1089. i40e_fill_default_direct_cmd_desc(&desc,
  1090. i40e_aqc_opc_set_hmc_resource_profile);
  1091. cmd->pm_profile = (u8)profile;
  1092. cmd->pe_vf_enabled = pe_vf_enabled_count;
  1093. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1094. return status;
  1095. }
  1096. /**
  1097. * i40e_aq_request_resource
  1098. * @hw: pointer to the hw struct
  1099. * @resource: resource id
  1100. * @access: access type
  1101. * @sdp_number: resource number
  1102. * @timeout: the maximum time in ms that the driver may hold the resource
  1103. * @cmd_details: pointer to command details structure or NULL
  1104. *
  1105. * requests common resource using the admin queue commands
  1106. **/
  1107. i40e_status i40e_aq_request_resource(struct i40e_hw *hw,
  1108. enum i40e_aq_resources_ids resource,
  1109. enum i40e_aq_resource_access_type access,
  1110. u8 sdp_number, u64 *timeout,
  1111. struct i40e_asq_cmd_details *cmd_details)
  1112. {
  1113. struct i40e_aq_desc desc;
  1114. struct i40e_aqc_request_resource *cmd_resp =
  1115. (struct i40e_aqc_request_resource *)&desc.params.raw;
  1116. i40e_status status;
  1117. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_request_resource);
  1118. cmd_resp->resource_id = cpu_to_le16(resource);
  1119. cmd_resp->access_type = cpu_to_le16(access);
  1120. cmd_resp->resource_number = cpu_to_le32(sdp_number);
  1121. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1122. /* The completion specifies the maximum time in ms that the driver
  1123. * may hold the resource in the Timeout field.
  1124. * If the resource is held by someone else, the command completes with
  1125. * busy return value and the timeout field indicates the maximum time
  1126. * the current owner of the resource has to free it.
  1127. */
  1128. if (!status || hw->aq.asq_last_status == I40E_AQ_RC_EBUSY)
  1129. *timeout = le32_to_cpu(cmd_resp->timeout);
  1130. return status;
  1131. }
  1132. /**
  1133. * i40e_aq_release_resource
  1134. * @hw: pointer to the hw struct
  1135. * @resource: resource id
  1136. * @sdp_number: resource number
  1137. * @cmd_details: pointer to command details structure or NULL
  1138. *
  1139. * release common resource using the admin queue commands
  1140. **/
  1141. i40e_status i40e_aq_release_resource(struct i40e_hw *hw,
  1142. enum i40e_aq_resources_ids resource,
  1143. u8 sdp_number,
  1144. struct i40e_asq_cmd_details *cmd_details)
  1145. {
  1146. struct i40e_aq_desc desc;
  1147. struct i40e_aqc_request_resource *cmd =
  1148. (struct i40e_aqc_request_resource *)&desc.params.raw;
  1149. i40e_status status;
  1150. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_release_resource);
  1151. cmd->resource_id = cpu_to_le16(resource);
  1152. cmd->resource_number = cpu_to_le32(sdp_number);
  1153. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1154. return status;
  1155. }
  1156. /**
  1157. * i40e_aq_read_nvm
  1158. * @hw: pointer to the hw struct
  1159. * @module_pointer: module pointer location in words from the NVM beginning
  1160. * @offset: byte offset from the module beginning
  1161. * @length: length of the section to be read (in bytes from the offset)
  1162. * @data: command buffer (size [bytes] = length)
  1163. * @last_command: tells if this is the last command in a series
  1164. * @cmd_details: pointer to command details structure or NULL
  1165. *
  1166. * Read the NVM using the admin queue commands
  1167. **/
  1168. i40e_status i40e_aq_read_nvm(struct i40e_hw *hw, u8 module_pointer,
  1169. u32 offset, u16 length, void *data,
  1170. bool last_command,
  1171. struct i40e_asq_cmd_details *cmd_details)
  1172. {
  1173. struct i40e_aq_desc desc;
  1174. struct i40e_aqc_nvm_update *cmd =
  1175. (struct i40e_aqc_nvm_update *)&desc.params.raw;
  1176. i40e_status status;
  1177. /* In offset the highest byte must be zeroed. */
  1178. if (offset & 0xFF000000) {
  1179. status = I40E_ERR_PARAM;
  1180. goto i40e_aq_read_nvm_exit;
  1181. }
  1182. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_read);
  1183. /* If this is the last command in a series, set the proper flag. */
  1184. if (last_command)
  1185. cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
  1186. cmd->module_pointer = module_pointer;
  1187. cmd->offset = cpu_to_le32(offset);
  1188. cmd->length = cpu_to_le16(length);
  1189. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  1190. if (length > I40E_AQ_LARGE_BUF)
  1191. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1192. status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
  1193. i40e_aq_read_nvm_exit:
  1194. return status;
  1195. }
  1196. #define I40E_DEV_FUNC_CAP_SWITCH_MODE 0x01
  1197. #define I40E_DEV_FUNC_CAP_MGMT_MODE 0x02
  1198. #define I40E_DEV_FUNC_CAP_NPAR 0x03
  1199. #define I40E_DEV_FUNC_CAP_OS2BMC 0x04
  1200. #define I40E_DEV_FUNC_CAP_VALID_FUNC 0x05
  1201. #define I40E_DEV_FUNC_CAP_SRIOV_1_1 0x12
  1202. #define I40E_DEV_FUNC_CAP_VF 0x13
  1203. #define I40E_DEV_FUNC_CAP_VMDQ 0x14
  1204. #define I40E_DEV_FUNC_CAP_802_1_QBG 0x15
  1205. #define I40E_DEV_FUNC_CAP_802_1_QBH 0x16
  1206. #define I40E_DEV_FUNC_CAP_VSI 0x17
  1207. #define I40E_DEV_FUNC_CAP_DCB 0x18
  1208. #define I40E_DEV_FUNC_CAP_FCOE 0x21
  1209. #define I40E_DEV_FUNC_CAP_RSS 0x40
  1210. #define I40E_DEV_FUNC_CAP_RX_QUEUES 0x41
  1211. #define I40E_DEV_FUNC_CAP_TX_QUEUES 0x42
  1212. #define I40E_DEV_FUNC_CAP_MSIX 0x43
  1213. #define I40E_DEV_FUNC_CAP_MSIX_VF 0x44
  1214. #define I40E_DEV_FUNC_CAP_FLOW_DIRECTOR 0x45
  1215. #define I40E_DEV_FUNC_CAP_IEEE_1588 0x46
  1216. #define I40E_DEV_FUNC_CAP_MFP_MODE_1 0xF1
  1217. #define I40E_DEV_FUNC_CAP_CEM 0xF2
  1218. #define I40E_DEV_FUNC_CAP_IWARP 0x51
  1219. #define I40E_DEV_FUNC_CAP_LED 0x61
  1220. #define I40E_DEV_FUNC_CAP_SDP 0x62
  1221. #define I40E_DEV_FUNC_CAP_MDIO 0x63
  1222. /**
  1223. * i40e_parse_discover_capabilities
  1224. * @hw: pointer to the hw struct
  1225. * @buff: pointer to a buffer containing device/function capability records
  1226. * @cap_count: number of capability records in the list
  1227. * @list_type_opc: type of capabilities list to parse
  1228. *
  1229. * Parse the device/function capabilities list.
  1230. **/
  1231. static void i40e_parse_discover_capabilities(struct i40e_hw *hw, void *buff,
  1232. u32 cap_count,
  1233. enum i40e_admin_queue_opc list_type_opc)
  1234. {
  1235. struct i40e_aqc_list_capabilities_element_resp *cap;
  1236. u32 number, logical_id, phys_id;
  1237. struct i40e_hw_capabilities *p;
  1238. u32 reg_val;
  1239. u32 i = 0;
  1240. u16 id;
  1241. cap = (struct i40e_aqc_list_capabilities_element_resp *) buff;
  1242. if (list_type_opc == i40e_aqc_opc_list_dev_capabilities)
  1243. p = (struct i40e_hw_capabilities *)&hw->dev_caps;
  1244. else if (list_type_opc == i40e_aqc_opc_list_func_capabilities)
  1245. p = (struct i40e_hw_capabilities *)&hw->func_caps;
  1246. else
  1247. return;
  1248. for (i = 0; i < cap_count; i++, cap++) {
  1249. id = le16_to_cpu(cap->id);
  1250. number = le32_to_cpu(cap->number);
  1251. logical_id = le32_to_cpu(cap->logical_id);
  1252. phys_id = le32_to_cpu(cap->phys_id);
  1253. switch (id) {
  1254. case I40E_DEV_FUNC_CAP_SWITCH_MODE:
  1255. p->switch_mode = number;
  1256. break;
  1257. case I40E_DEV_FUNC_CAP_MGMT_MODE:
  1258. p->management_mode = number;
  1259. break;
  1260. case I40E_DEV_FUNC_CAP_NPAR:
  1261. p->npar_enable = number;
  1262. break;
  1263. case I40E_DEV_FUNC_CAP_OS2BMC:
  1264. p->os2bmc = number;
  1265. break;
  1266. case I40E_DEV_FUNC_CAP_VALID_FUNC:
  1267. p->valid_functions = number;
  1268. break;
  1269. case I40E_DEV_FUNC_CAP_SRIOV_1_1:
  1270. if (number == 1)
  1271. p->sr_iov_1_1 = true;
  1272. break;
  1273. case I40E_DEV_FUNC_CAP_VF:
  1274. p->num_vfs = number;
  1275. p->vf_base_id = logical_id;
  1276. break;
  1277. case I40E_DEV_FUNC_CAP_VMDQ:
  1278. if (number == 1)
  1279. p->vmdq = true;
  1280. break;
  1281. case I40E_DEV_FUNC_CAP_802_1_QBG:
  1282. if (number == 1)
  1283. p->evb_802_1_qbg = true;
  1284. break;
  1285. case I40E_DEV_FUNC_CAP_802_1_QBH:
  1286. if (number == 1)
  1287. p->evb_802_1_qbh = true;
  1288. break;
  1289. case I40E_DEV_FUNC_CAP_VSI:
  1290. p->num_vsis = number;
  1291. break;
  1292. case I40E_DEV_FUNC_CAP_DCB:
  1293. if (number == 1) {
  1294. p->dcb = true;
  1295. p->enabled_tcmap = logical_id;
  1296. p->maxtc = phys_id;
  1297. }
  1298. break;
  1299. case I40E_DEV_FUNC_CAP_FCOE:
  1300. if (number == 1)
  1301. p->fcoe = true;
  1302. break;
  1303. case I40E_DEV_FUNC_CAP_RSS:
  1304. p->rss = true;
  1305. reg_val = rd32(hw, I40E_PFQF_CTL_0);
  1306. if (reg_val & I40E_PFQF_CTL_0_HASHLUTSIZE_MASK)
  1307. p->rss_table_size = number;
  1308. else
  1309. p->rss_table_size = 128;
  1310. p->rss_table_entry_width = logical_id;
  1311. break;
  1312. case I40E_DEV_FUNC_CAP_RX_QUEUES:
  1313. p->num_rx_qp = number;
  1314. p->base_queue = phys_id;
  1315. break;
  1316. case I40E_DEV_FUNC_CAP_TX_QUEUES:
  1317. p->num_tx_qp = number;
  1318. p->base_queue = phys_id;
  1319. break;
  1320. case I40E_DEV_FUNC_CAP_MSIX:
  1321. p->num_msix_vectors = number;
  1322. break;
  1323. case I40E_DEV_FUNC_CAP_MSIX_VF:
  1324. p->num_msix_vectors_vf = number;
  1325. break;
  1326. case I40E_DEV_FUNC_CAP_MFP_MODE_1:
  1327. if (number == 1)
  1328. p->mfp_mode_1 = true;
  1329. break;
  1330. case I40E_DEV_FUNC_CAP_CEM:
  1331. if (number == 1)
  1332. p->mgmt_cem = true;
  1333. break;
  1334. case I40E_DEV_FUNC_CAP_IWARP:
  1335. if (number == 1)
  1336. p->iwarp = true;
  1337. break;
  1338. case I40E_DEV_FUNC_CAP_LED:
  1339. if (phys_id < I40E_HW_CAP_MAX_GPIO)
  1340. p->led[phys_id] = true;
  1341. break;
  1342. case I40E_DEV_FUNC_CAP_SDP:
  1343. if (phys_id < I40E_HW_CAP_MAX_GPIO)
  1344. p->sdp[phys_id] = true;
  1345. break;
  1346. case I40E_DEV_FUNC_CAP_MDIO:
  1347. if (number == 1) {
  1348. p->mdio_port_num = phys_id;
  1349. p->mdio_port_mode = logical_id;
  1350. }
  1351. break;
  1352. case I40E_DEV_FUNC_CAP_IEEE_1588:
  1353. if (number == 1)
  1354. p->ieee_1588 = true;
  1355. break;
  1356. case I40E_DEV_FUNC_CAP_FLOW_DIRECTOR:
  1357. p->fd = true;
  1358. p->fd_filters_guaranteed = number;
  1359. p->fd_filters_best_effort = logical_id;
  1360. break;
  1361. default:
  1362. break;
  1363. }
  1364. }
  1365. /* additional HW specific goodies that might
  1366. * someday be HW version specific
  1367. */
  1368. p->rx_buf_chain_len = I40E_MAX_CHAINED_RX_BUFFERS;
  1369. }
  1370. /**
  1371. * i40e_aq_discover_capabilities
  1372. * @hw: pointer to the hw struct
  1373. * @buff: a virtual buffer to hold the capabilities
  1374. * @buff_size: Size of the virtual buffer
  1375. * @data_size: Size of the returned data, or buff size needed if AQ err==ENOMEM
  1376. * @list_type_opc: capabilities type to discover - pass in the command opcode
  1377. * @cmd_details: pointer to command details structure or NULL
  1378. *
  1379. * Get the device capabilities descriptions from the firmware
  1380. **/
  1381. i40e_status i40e_aq_discover_capabilities(struct i40e_hw *hw,
  1382. void *buff, u16 buff_size, u16 *data_size,
  1383. enum i40e_admin_queue_opc list_type_opc,
  1384. struct i40e_asq_cmd_details *cmd_details)
  1385. {
  1386. struct i40e_aqc_list_capabilites *cmd;
  1387. i40e_status status = 0;
  1388. struct i40e_aq_desc desc;
  1389. cmd = (struct i40e_aqc_list_capabilites *)&desc.params.raw;
  1390. if (list_type_opc != i40e_aqc_opc_list_func_capabilities &&
  1391. list_type_opc != i40e_aqc_opc_list_dev_capabilities) {
  1392. status = I40E_ERR_PARAM;
  1393. goto exit;
  1394. }
  1395. i40e_fill_default_direct_cmd_desc(&desc, list_type_opc);
  1396. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  1397. if (buff_size > I40E_AQ_LARGE_BUF)
  1398. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1399. status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  1400. *data_size = le16_to_cpu(desc.datalen);
  1401. if (status)
  1402. goto exit;
  1403. i40e_parse_discover_capabilities(hw, buff, le32_to_cpu(cmd->count),
  1404. list_type_opc);
  1405. exit:
  1406. return status;
  1407. }
  1408. /**
  1409. * i40e_aq_get_lldp_mib
  1410. * @hw: pointer to the hw struct
  1411. * @bridge_type: type of bridge requested
  1412. * @mib_type: Local, Remote or both Local and Remote MIBs
  1413. * @buff: pointer to a user supplied buffer to store the MIB block
  1414. * @buff_size: size of the buffer (in bytes)
  1415. * @local_len : length of the returned Local LLDP MIB
  1416. * @remote_len: length of the returned Remote LLDP MIB
  1417. * @cmd_details: pointer to command details structure or NULL
  1418. *
  1419. * Requests the complete LLDP MIB (entire packet).
  1420. **/
  1421. i40e_status i40e_aq_get_lldp_mib(struct i40e_hw *hw, u8 bridge_type,
  1422. u8 mib_type, void *buff, u16 buff_size,
  1423. u16 *local_len, u16 *remote_len,
  1424. struct i40e_asq_cmd_details *cmd_details)
  1425. {
  1426. struct i40e_aq_desc desc;
  1427. struct i40e_aqc_lldp_get_mib *cmd =
  1428. (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
  1429. struct i40e_aqc_lldp_get_mib *resp =
  1430. (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
  1431. i40e_status status;
  1432. if (buff_size == 0 || !buff)
  1433. return I40E_ERR_PARAM;
  1434. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_get_mib);
  1435. /* Indirect Command */
  1436. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  1437. cmd->type = mib_type & I40E_AQ_LLDP_MIB_TYPE_MASK;
  1438. cmd->type |= ((bridge_type << I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) &
  1439. I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
  1440. desc.datalen = cpu_to_le16(buff_size);
  1441. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  1442. if (buff_size > I40E_AQ_LARGE_BUF)
  1443. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1444. status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  1445. if (!status) {
  1446. if (local_len != NULL)
  1447. *local_len = le16_to_cpu(resp->local_len);
  1448. if (remote_len != NULL)
  1449. *remote_len = le16_to_cpu(resp->remote_len);
  1450. }
  1451. return status;
  1452. }
  1453. /**
  1454. * i40e_aq_cfg_lldp_mib_change_event
  1455. * @hw: pointer to the hw struct
  1456. * @enable_update: Enable or Disable event posting
  1457. * @cmd_details: pointer to command details structure or NULL
  1458. *
  1459. * Enable or Disable posting of an event on ARQ when LLDP MIB
  1460. * associated with the interface changes
  1461. **/
  1462. i40e_status i40e_aq_cfg_lldp_mib_change_event(struct i40e_hw *hw,
  1463. bool enable_update,
  1464. struct i40e_asq_cmd_details *cmd_details)
  1465. {
  1466. struct i40e_aq_desc desc;
  1467. struct i40e_aqc_lldp_update_mib *cmd =
  1468. (struct i40e_aqc_lldp_update_mib *)&desc.params.raw;
  1469. i40e_status status;
  1470. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_update_mib);
  1471. if (!enable_update)
  1472. cmd->command |= I40E_AQ_LLDP_MIB_UPDATE_DISABLE;
  1473. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1474. return status;
  1475. }
  1476. /**
  1477. * i40e_aq_stop_lldp
  1478. * @hw: pointer to the hw struct
  1479. * @shutdown_agent: True if LLDP Agent needs to be Shutdown
  1480. * @cmd_details: pointer to command details structure or NULL
  1481. *
  1482. * Stop or Shutdown the embedded LLDP Agent
  1483. **/
  1484. i40e_status i40e_aq_stop_lldp(struct i40e_hw *hw, bool shutdown_agent,
  1485. struct i40e_asq_cmd_details *cmd_details)
  1486. {
  1487. struct i40e_aq_desc desc;
  1488. struct i40e_aqc_lldp_stop *cmd =
  1489. (struct i40e_aqc_lldp_stop *)&desc.params.raw;
  1490. i40e_status status;
  1491. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_stop);
  1492. if (shutdown_agent)
  1493. cmd->command |= I40E_AQ_LLDP_AGENT_SHUTDOWN;
  1494. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1495. return status;
  1496. }
  1497. /**
  1498. * i40e_aq_start_lldp
  1499. * @hw: pointer to the hw struct
  1500. * @cmd_details: pointer to command details structure or NULL
  1501. *
  1502. * Start the embedded LLDP Agent on all ports.
  1503. **/
  1504. i40e_status i40e_aq_start_lldp(struct i40e_hw *hw,
  1505. struct i40e_asq_cmd_details *cmd_details)
  1506. {
  1507. struct i40e_aq_desc desc;
  1508. struct i40e_aqc_lldp_start *cmd =
  1509. (struct i40e_aqc_lldp_start *)&desc.params.raw;
  1510. i40e_status status;
  1511. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_start);
  1512. cmd->command = I40E_AQ_LLDP_AGENT_START;
  1513. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1514. return status;
  1515. }
  1516. /**
  1517. * i40e_aq_delete_element - Delete switch element
  1518. * @hw: pointer to the hw struct
  1519. * @seid: the SEID to delete from the switch
  1520. * @cmd_details: pointer to command details structure or NULL
  1521. *
  1522. * This deletes a switch element from the switch.
  1523. **/
  1524. i40e_status i40e_aq_delete_element(struct i40e_hw *hw, u16 seid,
  1525. struct i40e_asq_cmd_details *cmd_details)
  1526. {
  1527. struct i40e_aq_desc desc;
  1528. struct i40e_aqc_switch_seid *cmd =
  1529. (struct i40e_aqc_switch_seid *)&desc.params.raw;
  1530. i40e_status status;
  1531. if (seid == 0)
  1532. return I40E_ERR_PARAM;
  1533. i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_delete_element);
  1534. cmd->seid = cpu_to_le16(seid);
  1535. status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1536. return status;
  1537. }
  1538. /**
  1539. * i40e_aq_tx_sched_cmd - generic Tx scheduler AQ command handler
  1540. * @hw: pointer to the hw struct
  1541. * @seid: seid for the physical port/switching component/vsi
  1542. * @buff: Indirect buffer to hold data parameters and response
  1543. * @buff_size: Indirect buffer size
  1544. * @opcode: Tx scheduler AQ command opcode
  1545. * @cmd_details: pointer to command details structure or NULL
  1546. *
  1547. * Generic command handler for Tx scheduler AQ commands
  1548. **/
  1549. static i40e_status i40e_aq_tx_sched_cmd(struct i40e_hw *hw, u16 seid,
  1550. void *buff, u16 buff_size,
  1551. enum i40e_admin_queue_opc opcode,
  1552. struct i40e_asq_cmd_details *cmd_details)
  1553. {
  1554. struct i40e_aq_desc desc;
  1555. struct i40e_aqc_tx_sched_ind *cmd =
  1556. (struct i40e_aqc_tx_sched_ind *)&desc.params.raw;
  1557. i40e_status status;
  1558. bool cmd_param_flag = false;
  1559. switch (opcode) {
  1560. case i40e_aqc_opc_configure_vsi_ets_sla_bw_limit:
  1561. case i40e_aqc_opc_configure_vsi_tc_bw:
  1562. case i40e_aqc_opc_enable_switching_comp_ets:
  1563. case i40e_aqc_opc_modify_switching_comp_ets:
  1564. case i40e_aqc_opc_disable_switching_comp_ets:
  1565. case i40e_aqc_opc_configure_switching_comp_ets_bw_limit:
  1566. case i40e_aqc_opc_configure_switching_comp_bw_config:
  1567. cmd_param_flag = true;
  1568. break;
  1569. case i40e_aqc_opc_query_vsi_bw_config:
  1570. case i40e_aqc_opc_query_vsi_ets_sla_config:
  1571. case i40e_aqc_opc_query_switching_comp_ets_config:
  1572. case i40e_aqc_opc_query_port_ets_config:
  1573. case i40e_aqc_opc_query_switching_comp_bw_config:
  1574. cmd_param_flag = false;
  1575. break;
  1576. default:
  1577. return I40E_ERR_PARAM;
  1578. }
  1579. i40e_fill_default_direct_cmd_desc(&desc, opcode);
  1580. /* Indirect command */
  1581. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  1582. if (cmd_param_flag)
  1583. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
  1584. if (buff_size > I40E_AQ_LARGE_BUF)
  1585. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1586. desc.datalen = cpu_to_le16(buff_size);
  1587. cmd->vsi_seid = cpu_to_le16(seid);
  1588. status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  1589. return status;
  1590. }
  1591. /**
  1592. * i40e_aq_config_vsi_tc_bw - Config VSI BW Allocation per TC
  1593. * @hw: pointer to the hw struct
  1594. * @seid: VSI seid
  1595. * @bw_data: Buffer holding enabled TCs, relative TC BW limit/credits
  1596. * @cmd_details: pointer to command details structure or NULL
  1597. **/
  1598. i40e_status i40e_aq_config_vsi_tc_bw(struct i40e_hw *hw,
  1599. u16 seid,
  1600. struct i40e_aqc_configure_vsi_tc_bw_data *bw_data,
  1601. struct i40e_asq_cmd_details *cmd_details)
  1602. {
  1603. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  1604. i40e_aqc_opc_configure_vsi_tc_bw,
  1605. cmd_details);
  1606. }
  1607. /**
  1608. * i40e_aq_query_vsi_bw_config - Query VSI BW configuration
  1609. * @hw: pointer to the hw struct
  1610. * @seid: seid of the VSI
  1611. * @bw_data: Buffer to hold VSI BW configuration
  1612. * @cmd_details: pointer to command details structure or NULL
  1613. **/
  1614. i40e_status i40e_aq_query_vsi_bw_config(struct i40e_hw *hw,
  1615. u16 seid,
  1616. struct i40e_aqc_query_vsi_bw_config_resp *bw_data,
  1617. struct i40e_asq_cmd_details *cmd_details)
  1618. {
  1619. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  1620. i40e_aqc_opc_query_vsi_bw_config,
  1621. cmd_details);
  1622. }
  1623. /**
  1624. * i40e_aq_query_vsi_ets_sla_config - Query VSI BW configuration per TC
  1625. * @hw: pointer to the hw struct
  1626. * @seid: seid of the VSI
  1627. * @bw_data: Buffer to hold VSI BW configuration per TC
  1628. * @cmd_details: pointer to command details structure or NULL
  1629. **/
  1630. i40e_status i40e_aq_query_vsi_ets_sla_config(struct i40e_hw *hw,
  1631. u16 seid,
  1632. struct i40e_aqc_query_vsi_ets_sla_config_resp *bw_data,
  1633. struct i40e_asq_cmd_details *cmd_details)
  1634. {
  1635. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  1636. i40e_aqc_opc_query_vsi_ets_sla_config,
  1637. cmd_details);
  1638. }
  1639. /**
  1640. * i40e_aq_query_switch_comp_ets_config - Query Switch comp BW config per TC
  1641. * @hw: pointer to the hw struct
  1642. * @seid: seid of the switching component
  1643. * @bw_data: Buffer to hold switching component's per TC BW config
  1644. * @cmd_details: pointer to command details structure or NULL
  1645. **/
  1646. i40e_status i40e_aq_query_switch_comp_ets_config(struct i40e_hw *hw,
  1647. u16 seid,
  1648. struct i40e_aqc_query_switching_comp_ets_config_resp *bw_data,
  1649. struct i40e_asq_cmd_details *cmd_details)
  1650. {
  1651. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  1652. i40e_aqc_opc_query_switching_comp_ets_config,
  1653. cmd_details);
  1654. }
  1655. /**
  1656. * i40e_aq_query_port_ets_config - Query Physical Port ETS configuration
  1657. * @hw: pointer to the hw struct
  1658. * @seid: seid of the VSI or switching component connected to Physical Port
  1659. * @bw_data: Buffer to hold current ETS configuration for the Physical Port
  1660. * @cmd_details: pointer to command details structure or NULL
  1661. **/
  1662. i40e_status i40e_aq_query_port_ets_config(struct i40e_hw *hw,
  1663. u16 seid,
  1664. struct i40e_aqc_query_port_ets_config_resp *bw_data,
  1665. struct i40e_asq_cmd_details *cmd_details)
  1666. {
  1667. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  1668. i40e_aqc_opc_query_port_ets_config,
  1669. cmd_details);
  1670. }
  1671. /**
  1672. * i40e_aq_query_switch_comp_bw_config - Query Switch comp BW configuration
  1673. * @hw: pointer to the hw struct
  1674. * @seid: seid of the switching component
  1675. * @bw_data: Buffer to hold switching component's BW configuration
  1676. * @cmd_details: pointer to command details structure or NULL
  1677. **/
  1678. i40e_status i40e_aq_query_switch_comp_bw_config(struct i40e_hw *hw,
  1679. u16 seid,
  1680. struct i40e_aqc_query_switching_comp_bw_config_resp *bw_data,
  1681. struct i40e_asq_cmd_details *cmd_details)
  1682. {
  1683. return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
  1684. i40e_aqc_opc_query_switching_comp_bw_config,
  1685. cmd_details);
  1686. }
  1687. /**
  1688. * i40e_validate_filter_settings
  1689. * @hw: pointer to the hardware structure
  1690. * @settings: Filter control settings
  1691. *
  1692. * Check and validate the filter control settings passed.
  1693. * The function checks for the valid filter/context sizes being
  1694. * passed for FCoE and PE.
  1695. *
  1696. * Returns 0 if the values passed are valid and within
  1697. * range else returns an error.
  1698. **/
  1699. static i40e_status i40e_validate_filter_settings(struct i40e_hw *hw,
  1700. struct i40e_filter_control_settings *settings)
  1701. {
  1702. u32 fcoe_cntx_size, fcoe_filt_size;
  1703. u32 pe_cntx_size, pe_filt_size;
  1704. u32 fcoe_fmax, pe_fmax;
  1705. u32 val;
  1706. /* Validate FCoE settings passed */
  1707. switch (settings->fcoe_filt_num) {
  1708. case I40E_HASH_FILTER_SIZE_1K:
  1709. case I40E_HASH_FILTER_SIZE_2K:
  1710. case I40E_HASH_FILTER_SIZE_4K:
  1711. case I40E_HASH_FILTER_SIZE_8K:
  1712. case I40E_HASH_FILTER_SIZE_16K:
  1713. case I40E_HASH_FILTER_SIZE_32K:
  1714. fcoe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
  1715. fcoe_filt_size <<= (u32)settings->fcoe_filt_num;
  1716. break;
  1717. default:
  1718. return I40E_ERR_PARAM;
  1719. }
  1720. switch (settings->fcoe_cntx_num) {
  1721. case I40E_DMA_CNTX_SIZE_512:
  1722. case I40E_DMA_CNTX_SIZE_1K:
  1723. case I40E_DMA_CNTX_SIZE_2K:
  1724. case I40E_DMA_CNTX_SIZE_4K:
  1725. fcoe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
  1726. fcoe_cntx_size <<= (u32)settings->fcoe_cntx_num;
  1727. break;
  1728. default:
  1729. return I40E_ERR_PARAM;
  1730. }
  1731. /* Validate PE settings passed */
  1732. switch (settings->pe_filt_num) {
  1733. case I40E_HASH_FILTER_SIZE_1K:
  1734. case I40E_HASH_FILTER_SIZE_2K:
  1735. case I40E_HASH_FILTER_SIZE_4K:
  1736. case I40E_HASH_FILTER_SIZE_8K:
  1737. case I40E_HASH_FILTER_SIZE_16K:
  1738. case I40E_HASH_FILTER_SIZE_32K:
  1739. case I40E_HASH_FILTER_SIZE_64K:
  1740. case I40E_HASH_FILTER_SIZE_128K:
  1741. case I40E_HASH_FILTER_SIZE_256K:
  1742. case I40E_HASH_FILTER_SIZE_512K:
  1743. case I40E_HASH_FILTER_SIZE_1M:
  1744. pe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
  1745. pe_filt_size <<= (u32)settings->pe_filt_num;
  1746. break;
  1747. default:
  1748. return I40E_ERR_PARAM;
  1749. }
  1750. switch (settings->pe_cntx_num) {
  1751. case I40E_DMA_CNTX_SIZE_512:
  1752. case I40E_DMA_CNTX_SIZE_1K:
  1753. case I40E_DMA_CNTX_SIZE_2K:
  1754. case I40E_DMA_CNTX_SIZE_4K:
  1755. case I40E_DMA_CNTX_SIZE_8K:
  1756. case I40E_DMA_CNTX_SIZE_16K:
  1757. case I40E_DMA_CNTX_SIZE_32K:
  1758. case I40E_DMA_CNTX_SIZE_64K:
  1759. case I40E_DMA_CNTX_SIZE_128K:
  1760. case I40E_DMA_CNTX_SIZE_256K:
  1761. pe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
  1762. pe_cntx_size <<= (u32)settings->pe_cntx_num;
  1763. break;
  1764. default:
  1765. return I40E_ERR_PARAM;
  1766. }
  1767. /* FCHSIZE + FCDSIZE should not be greater than PMFCOEFMAX */
  1768. val = rd32(hw, I40E_GLHMC_FCOEFMAX);
  1769. fcoe_fmax = (val & I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_MASK)
  1770. >> I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_SHIFT;
  1771. if (fcoe_filt_size + fcoe_cntx_size > fcoe_fmax)
  1772. return I40E_ERR_INVALID_SIZE;
  1773. /* PEHSIZE + PEDSIZE should not be greater than PMPEXFMAX */
  1774. val = rd32(hw, I40E_GLHMC_PEXFMAX);
  1775. pe_fmax = (val & I40E_GLHMC_PEXFMAX_PMPEXFMAX_MASK)
  1776. >> I40E_GLHMC_PEXFMAX_PMPEXFMAX_SHIFT;
  1777. if (pe_filt_size + pe_cntx_size > pe_fmax)
  1778. return I40E_ERR_INVALID_SIZE;
  1779. return 0;
  1780. }
  1781. /**
  1782. * i40e_set_filter_control
  1783. * @hw: pointer to the hardware structure
  1784. * @settings: Filter control settings
  1785. *
  1786. * Set the Queue Filters for PE/FCoE and enable filters required
  1787. * for a single PF. It is expected that these settings are programmed
  1788. * at the driver initialization time.
  1789. **/
  1790. i40e_status i40e_set_filter_control(struct i40e_hw *hw,
  1791. struct i40e_filter_control_settings *settings)
  1792. {
  1793. i40e_status ret = 0;
  1794. u32 hash_lut_size = 0;
  1795. u32 val;
  1796. if (!settings)
  1797. return I40E_ERR_PARAM;
  1798. /* Validate the input settings */
  1799. ret = i40e_validate_filter_settings(hw, settings);
  1800. if (ret)
  1801. return ret;
  1802. /* Read the PF Queue Filter control register */
  1803. val = rd32(hw, I40E_PFQF_CTL_0);
  1804. /* Program required PE hash buckets for the PF */
  1805. val &= ~I40E_PFQF_CTL_0_PEHSIZE_MASK;
  1806. val |= ((u32)settings->pe_filt_num << I40E_PFQF_CTL_0_PEHSIZE_SHIFT) &
  1807. I40E_PFQF_CTL_0_PEHSIZE_MASK;
  1808. /* Program required PE contexts for the PF */
  1809. val &= ~I40E_PFQF_CTL_0_PEDSIZE_MASK;
  1810. val |= ((u32)settings->pe_cntx_num << I40E_PFQF_CTL_0_PEDSIZE_SHIFT) &
  1811. I40E_PFQF_CTL_0_PEDSIZE_MASK;
  1812. /* Program required FCoE hash buckets for the PF */
  1813. val &= ~I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
  1814. val |= ((u32)settings->fcoe_filt_num <<
  1815. I40E_PFQF_CTL_0_PFFCHSIZE_SHIFT) &
  1816. I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
  1817. /* Program required FCoE DDP contexts for the PF */
  1818. val &= ~I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
  1819. val |= ((u32)settings->fcoe_cntx_num <<
  1820. I40E_PFQF_CTL_0_PFFCDSIZE_SHIFT) &
  1821. I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
  1822. /* Program Hash LUT size for the PF */
  1823. val &= ~I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
  1824. if (settings->hash_lut_size == I40E_HASH_LUT_SIZE_512)
  1825. hash_lut_size = 1;
  1826. val |= (hash_lut_size << I40E_PFQF_CTL_0_HASHLUTSIZE_SHIFT) &
  1827. I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
  1828. /* Enable FDIR, Ethertype and MACVLAN filters for PF and VFs */
  1829. if (settings->enable_fdir)
  1830. val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
  1831. if (settings->enable_ethtype)
  1832. val |= I40E_PFQF_CTL_0_ETYPE_ENA_MASK;
  1833. if (settings->enable_macvlan)
  1834. val |= I40E_PFQF_CTL_0_MACVLAN_ENA_MASK;
  1835. wr32(hw, I40E_PFQF_CTL_0, val);
  1836. return 0;
  1837. }