i40e_common.c 59 KB

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