i40e_common.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*******************************************************************************
  3. *
  4. * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
  5. * Copyright(c) 2013 - 2014 Intel Corporation.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms and conditions of the GNU General Public License,
  9. * version 2, as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program. If not, see <http://www.gnu.org/licenses/>.
  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 <linux/avf/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. 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_DEV_ID_SFP_XL710:
  44. case I40E_DEV_ID_QEMU:
  45. case I40E_DEV_ID_KX_B:
  46. case I40E_DEV_ID_KX_C:
  47. case I40E_DEV_ID_QSFP_A:
  48. case I40E_DEV_ID_QSFP_B:
  49. case I40E_DEV_ID_QSFP_C:
  50. case I40E_DEV_ID_10G_BASE_T:
  51. case I40E_DEV_ID_10G_BASE_T4:
  52. case I40E_DEV_ID_20G_KR2:
  53. case I40E_DEV_ID_20G_KR2_A:
  54. case I40E_DEV_ID_25G_B:
  55. case I40E_DEV_ID_25G_SFP28:
  56. hw->mac.type = I40E_MAC_XL710;
  57. break;
  58. case I40E_DEV_ID_SFP_X722:
  59. case I40E_DEV_ID_1G_BASE_T_X722:
  60. case I40E_DEV_ID_10G_BASE_T_X722:
  61. case I40E_DEV_ID_SFP_I_X722:
  62. hw->mac.type = I40E_MAC_X722;
  63. break;
  64. case I40E_DEV_ID_X722_VF:
  65. hw->mac.type = I40E_MAC_X722_VF;
  66. break;
  67. case I40E_DEV_ID_VF:
  68. case I40E_DEV_ID_VF_HV:
  69. case I40E_DEV_ID_ADAPTIVE_VF:
  70. hw->mac.type = I40E_MAC_VF;
  71. break;
  72. default:
  73. hw->mac.type = I40E_MAC_GENERIC;
  74. break;
  75. }
  76. } else {
  77. status = I40E_ERR_DEVICE_NOT_SUPPORTED;
  78. }
  79. hw_dbg(hw, "i40e_set_mac_type found mac: %d, returns: %d\n",
  80. hw->mac.type, status);
  81. return status;
  82. }
  83. /**
  84. * i40evf_aq_str - convert AQ err code to a string
  85. * @hw: pointer to the HW structure
  86. * @aq_err: the AQ error code to convert
  87. **/
  88. const char *i40evf_aq_str(struct i40e_hw *hw, enum i40e_admin_queue_err aq_err)
  89. {
  90. switch (aq_err) {
  91. case I40E_AQ_RC_OK:
  92. return "OK";
  93. case I40E_AQ_RC_EPERM:
  94. return "I40E_AQ_RC_EPERM";
  95. case I40E_AQ_RC_ENOENT:
  96. return "I40E_AQ_RC_ENOENT";
  97. case I40E_AQ_RC_ESRCH:
  98. return "I40E_AQ_RC_ESRCH";
  99. case I40E_AQ_RC_EINTR:
  100. return "I40E_AQ_RC_EINTR";
  101. case I40E_AQ_RC_EIO:
  102. return "I40E_AQ_RC_EIO";
  103. case I40E_AQ_RC_ENXIO:
  104. return "I40E_AQ_RC_ENXIO";
  105. case I40E_AQ_RC_E2BIG:
  106. return "I40E_AQ_RC_E2BIG";
  107. case I40E_AQ_RC_EAGAIN:
  108. return "I40E_AQ_RC_EAGAIN";
  109. case I40E_AQ_RC_ENOMEM:
  110. return "I40E_AQ_RC_ENOMEM";
  111. case I40E_AQ_RC_EACCES:
  112. return "I40E_AQ_RC_EACCES";
  113. case I40E_AQ_RC_EFAULT:
  114. return "I40E_AQ_RC_EFAULT";
  115. case I40E_AQ_RC_EBUSY:
  116. return "I40E_AQ_RC_EBUSY";
  117. case I40E_AQ_RC_EEXIST:
  118. return "I40E_AQ_RC_EEXIST";
  119. case I40E_AQ_RC_EINVAL:
  120. return "I40E_AQ_RC_EINVAL";
  121. case I40E_AQ_RC_ENOTTY:
  122. return "I40E_AQ_RC_ENOTTY";
  123. case I40E_AQ_RC_ENOSPC:
  124. return "I40E_AQ_RC_ENOSPC";
  125. case I40E_AQ_RC_ENOSYS:
  126. return "I40E_AQ_RC_ENOSYS";
  127. case I40E_AQ_RC_ERANGE:
  128. return "I40E_AQ_RC_ERANGE";
  129. case I40E_AQ_RC_EFLUSHED:
  130. return "I40E_AQ_RC_EFLUSHED";
  131. case I40E_AQ_RC_BAD_ADDR:
  132. return "I40E_AQ_RC_BAD_ADDR";
  133. case I40E_AQ_RC_EMODE:
  134. return "I40E_AQ_RC_EMODE";
  135. case I40E_AQ_RC_EFBIG:
  136. return "I40E_AQ_RC_EFBIG";
  137. }
  138. snprintf(hw->err_str, sizeof(hw->err_str), "%d", aq_err);
  139. return hw->err_str;
  140. }
  141. /**
  142. * i40evf_stat_str - convert status err code to a string
  143. * @hw: pointer to the HW structure
  144. * @stat_err: the status error code to convert
  145. **/
  146. const char *i40evf_stat_str(struct i40e_hw *hw, i40e_status stat_err)
  147. {
  148. switch (stat_err) {
  149. case 0:
  150. return "OK";
  151. case I40E_ERR_NVM:
  152. return "I40E_ERR_NVM";
  153. case I40E_ERR_NVM_CHECKSUM:
  154. return "I40E_ERR_NVM_CHECKSUM";
  155. case I40E_ERR_PHY:
  156. return "I40E_ERR_PHY";
  157. case I40E_ERR_CONFIG:
  158. return "I40E_ERR_CONFIG";
  159. case I40E_ERR_PARAM:
  160. return "I40E_ERR_PARAM";
  161. case I40E_ERR_MAC_TYPE:
  162. return "I40E_ERR_MAC_TYPE";
  163. case I40E_ERR_UNKNOWN_PHY:
  164. return "I40E_ERR_UNKNOWN_PHY";
  165. case I40E_ERR_LINK_SETUP:
  166. return "I40E_ERR_LINK_SETUP";
  167. case I40E_ERR_ADAPTER_STOPPED:
  168. return "I40E_ERR_ADAPTER_STOPPED";
  169. case I40E_ERR_INVALID_MAC_ADDR:
  170. return "I40E_ERR_INVALID_MAC_ADDR";
  171. case I40E_ERR_DEVICE_NOT_SUPPORTED:
  172. return "I40E_ERR_DEVICE_NOT_SUPPORTED";
  173. case I40E_ERR_MASTER_REQUESTS_PENDING:
  174. return "I40E_ERR_MASTER_REQUESTS_PENDING";
  175. case I40E_ERR_INVALID_LINK_SETTINGS:
  176. return "I40E_ERR_INVALID_LINK_SETTINGS";
  177. case I40E_ERR_AUTONEG_NOT_COMPLETE:
  178. return "I40E_ERR_AUTONEG_NOT_COMPLETE";
  179. case I40E_ERR_RESET_FAILED:
  180. return "I40E_ERR_RESET_FAILED";
  181. case I40E_ERR_SWFW_SYNC:
  182. return "I40E_ERR_SWFW_SYNC";
  183. case I40E_ERR_NO_AVAILABLE_VSI:
  184. return "I40E_ERR_NO_AVAILABLE_VSI";
  185. case I40E_ERR_NO_MEMORY:
  186. return "I40E_ERR_NO_MEMORY";
  187. case I40E_ERR_BAD_PTR:
  188. return "I40E_ERR_BAD_PTR";
  189. case I40E_ERR_RING_FULL:
  190. return "I40E_ERR_RING_FULL";
  191. case I40E_ERR_INVALID_PD_ID:
  192. return "I40E_ERR_INVALID_PD_ID";
  193. case I40E_ERR_INVALID_QP_ID:
  194. return "I40E_ERR_INVALID_QP_ID";
  195. case I40E_ERR_INVALID_CQ_ID:
  196. return "I40E_ERR_INVALID_CQ_ID";
  197. case I40E_ERR_INVALID_CEQ_ID:
  198. return "I40E_ERR_INVALID_CEQ_ID";
  199. case I40E_ERR_INVALID_AEQ_ID:
  200. return "I40E_ERR_INVALID_AEQ_ID";
  201. case I40E_ERR_INVALID_SIZE:
  202. return "I40E_ERR_INVALID_SIZE";
  203. case I40E_ERR_INVALID_ARP_INDEX:
  204. return "I40E_ERR_INVALID_ARP_INDEX";
  205. case I40E_ERR_INVALID_FPM_FUNC_ID:
  206. return "I40E_ERR_INVALID_FPM_FUNC_ID";
  207. case I40E_ERR_QP_INVALID_MSG_SIZE:
  208. return "I40E_ERR_QP_INVALID_MSG_SIZE";
  209. case I40E_ERR_QP_TOOMANY_WRS_POSTED:
  210. return "I40E_ERR_QP_TOOMANY_WRS_POSTED";
  211. case I40E_ERR_INVALID_FRAG_COUNT:
  212. return "I40E_ERR_INVALID_FRAG_COUNT";
  213. case I40E_ERR_QUEUE_EMPTY:
  214. return "I40E_ERR_QUEUE_EMPTY";
  215. case I40E_ERR_INVALID_ALIGNMENT:
  216. return "I40E_ERR_INVALID_ALIGNMENT";
  217. case I40E_ERR_FLUSHED_QUEUE:
  218. return "I40E_ERR_FLUSHED_QUEUE";
  219. case I40E_ERR_INVALID_PUSH_PAGE_INDEX:
  220. return "I40E_ERR_INVALID_PUSH_PAGE_INDEX";
  221. case I40E_ERR_INVALID_IMM_DATA_SIZE:
  222. return "I40E_ERR_INVALID_IMM_DATA_SIZE";
  223. case I40E_ERR_TIMEOUT:
  224. return "I40E_ERR_TIMEOUT";
  225. case I40E_ERR_OPCODE_MISMATCH:
  226. return "I40E_ERR_OPCODE_MISMATCH";
  227. case I40E_ERR_CQP_COMPL_ERROR:
  228. return "I40E_ERR_CQP_COMPL_ERROR";
  229. case I40E_ERR_INVALID_VF_ID:
  230. return "I40E_ERR_INVALID_VF_ID";
  231. case I40E_ERR_INVALID_HMCFN_ID:
  232. return "I40E_ERR_INVALID_HMCFN_ID";
  233. case I40E_ERR_BACKING_PAGE_ERROR:
  234. return "I40E_ERR_BACKING_PAGE_ERROR";
  235. case I40E_ERR_NO_PBLCHUNKS_AVAILABLE:
  236. return "I40E_ERR_NO_PBLCHUNKS_AVAILABLE";
  237. case I40E_ERR_INVALID_PBLE_INDEX:
  238. return "I40E_ERR_INVALID_PBLE_INDEX";
  239. case I40E_ERR_INVALID_SD_INDEX:
  240. return "I40E_ERR_INVALID_SD_INDEX";
  241. case I40E_ERR_INVALID_PAGE_DESC_INDEX:
  242. return "I40E_ERR_INVALID_PAGE_DESC_INDEX";
  243. case I40E_ERR_INVALID_SD_TYPE:
  244. return "I40E_ERR_INVALID_SD_TYPE";
  245. case I40E_ERR_MEMCPY_FAILED:
  246. return "I40E_ERR_MEMCPY_FAILED";
  247. case I40E_ERR_INVALID_HMC_OBJ_INDEX:
  248. return "I40E_ERR_INVALID_HMC_OBJ_INDEX";
  249. case I40E_ERR_INVALID_HMC_OBJ_COUNT:
  250. return "I40E_ERR_INVALID_HMC_OBJ_COUNT";
  251. case I40E_ERR_INVALID_SRQ_ARM_LIMIT:
  252. return "I40E_ERR_INVALID_SRQ_ARM_LIMIT";
  253. case I40E_ERR_SRQ_ENABLED:
  254. return "I40E_ERR_SRQ_ENABLED";
  255. case I40E_ERR_ADMIN_QUEUE_ERROR:
  256. return "I40E_ERR_ADMIN_QUEUE_ERROR";
  257. case I40E_ERR_ADMIN_QUEUE_TIMEOUT:
  258. return "I40E_ERR_ADMIN_QUEUE_TIMEOUT";
  259. case I40E_ERR_BUF_TOO_SHORT:
  260. return "I40E_ERR_BUF_TOO_SHORT";
  261. case I40E_ERR_ADMIN_QUEUE_FULL:
  262. return "I40E_ERR_ADMIN_QUEUE_FULL";
  263. case I40E_ERR_ADMIN_QUEUE_NO_WORK:
  264. return "I40E_ERR_ADMIN_QUEUE_NO_WORK";
  265. case I40E_ERR_BAD_IWARP_CQE:
  266. return "I40E_ERR_BAD_IWARP_CQE";
  267. case I40E_ERR_NVM_BLANK_MODE:
  268. return "I40E_ERR_NVM_BLANK_MODE";
  269. case I40E_ERR_NOT_IMPLEMENTED:
  270. return "I40E_ERR_NOT_IMPLEMENTED";
  271. case I40E_ERR_PE_DOORBELL_NOT_ENABLED:
  272. return "I40E_ERR_PE_DOORBELL_NOT_ENABLED";
  273. case I40E_ERR_DIAG_TEST_FAILED:
  274. return "I40E_ERR_DIAG_TEST_FAILED";
  275. case I40E_ERR_NOT_READY:
  276. return "I40E_ERR_NOT_READY";
  277. case I40E_NOT_SUPPORTED:
  278. return "I40E_NOT_SUPPORTED";
  279. case I40E_ERR_FIRMWARE_API_VERSION:
  280. return "I40E_ERR_FIRMWARE_API_VERSION";
  281. case I40E_ERR_ADMIN_QUEUE_CRITICAL_ERROR:
  282. return "I40E_ERR_ADMIN_QUEUE_CRITICAL_ERROR";
  283. }
  284. snprintf(hw->err_str, sizeof(hw->err_str), "%d", stat_err);
  285. return hw->err_str;
  286. }
  287. /**
  288. * i40evf_debug_aq
  289. * @hw: debug mask related to admin queue
  290. * @mask: debug mask
  291. * @desc: pointer to admin queue descriptor
  292. * @buffer: pointer to command buffer
  293. * @buf_len: max length of buffer
  294. *
  295. * Dumps debug log about adminq command with descriptor contents.
  296. **/
  297. void i40evf_debug_aq(struct i40e_hw *hw, enum i40e_debug_mask mask, void *desc,
  298. void *buffer, u16 buf_len)
  299. {
  300. struct i40e_aq_desc *aq_desc = (struct i40e_aq_desc *)desc;
  301. u8 *buf = (u8 *)buffer;
  302. if ((!(mask & hw->debug_mask)) || (desc == NULL))
  303. return;
  304. i40e_debug(hw, mask,
  305. "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
  306. le16_to_cpu(aq_desc->opcode),
  307. le16_to_cpu(aq_desc->flags),
  308. le16_to_cpu(aq_desc->datalen),
  309. le16_to_cpu(aq_desc->retval));
  310. i40e_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
  311. le32_to_cpu(aq_desc->cookie_high),
  312. le32_to_cpu(aq_desc->cookie_low));
  313. i40e_debug(hw, mask, "\tparam (0,1) 0x%08X 0x%08X\n",
  314. le32_to_cpu(aq_desc->params.internal.param0),
  315. le32_to_cpu(aq_desc->params.internal.param1));
  316. i40e_debug(hw, mask, "\taddr (h,l) 0x%08X 0x%08X\n",
  317. le32_to_cpu(aq_desc->params.external.addr_high),
  318. le32_to_cpu(aq_desc->params.external.addr_low));
  319. if ((buffer != NULL) && (aq_desc->datalen != 0)) {
  320. u16 len = le16_to_cpu(aq_desc->datalen);
  321. i40e_debug(hw, mask, "AQ CMD Buffer:\n");
  322. if (buf_len < len)
  323. len = buf_len;
  324. /* write the full 16-byte chunks */
  325. if (hw->debug_mask & mask) {
  326. char prefix[27];
  327. snprintf(prefix, sizeof(prefix),
  328. "i40evf %02x:%02x.%x: \t0x",
  329. hw->bus.bus_id,
  330. hw->bus.device,
  331. hw->bus.func);
  332. print_hex_dump(KERN_INFO, prefix, DUMP_PREFIX_OFFSET,
  333. 16, 1, buf, len, false);
  334. }
  335. }
  336. }
  337. /**
  338. * i40evf_check_asq_alive
  339. * @hw: pointer to the hw struct
  340. *
  341. * Returns true if Queue is enabled else false.
  342. **/
  343. bool i40evf_check_asq_alive(struct i40e_hw *hw)
  344. {
  345. if (hw->aq.asq.len)
  346. return !!(rd32(hw, hw->aq.asq.len) &
  347. I40E_VF_ATQLEN1_ATQENABLE_MASK);
  348. else
  349. return false;
  350. }
  351. /**
  352. * i40evf_aq_queue_shutdown
  353. * @hw: pointer to the hw struct
  354. * @unloading: is the driver unloading itself
  355. *
  356. * Tell the Firmware that we're shutting down the AdminQ and whether
  357. * or not the driver is unloading as well.
  358. **/
  359. i40e_status i40evf_aq_queue_shutdown(struct i40e_hw *hw,
  360. bool unloading)
  361. {
  362. struct i40e_aq_desc desc;
  363. struct i40e_aqc_queue_shutdown *cmd =
  364. (struct i40e_aqc_queue_shutdown *)&desc.params.raw;
  365. i40e_status status;
  366. i40evf_fill_default_direct_cmd_desc(&desc,
  367. i40e_aqc_opc_queue_shutdown);
  368. if (unloading)
  369. cmd->driver_unloading = cpu_to_le32(I40E_AQ_DRIVER_UNLOADING);
  370. status = i40evf_asq_send_command(hw, &desc, NULL, 0, NULL);
  371. return status;
  372. }
  373. /**
  374. * i40e_aq_get_set_rss_lut
  375. * @hw: pointer to the hardware structure
  376. * @vsi_id: vsi fw index
  377. * @pf_lut: for PF table set true, for VSI table set false
  378. * @lut: pointer to the lut buffer provided by the caller
  379. * @lut_size: size of the lut buffer
  380. * @set: set true to set the table, false to get the table
  381. *
  382. * Internal function to get or set RSS look up table
  383. **/
  384. static i40e_status i40e_aq_get_set_rss_lut(struct i40e_hw *hw,
  385. u16 vsi_id, bool pf_lut,
  386. u8 *lut, u16 lut_size,
  387. bool set)
  388. {
  389. i40e_status status;
  390. struct i40e_aq_desc desc;
  391. struct i40e_aqc_get_set_rss_lut *cmd_resp =
  392. (struct i40e_aqc_get_set_rss_lut *)&desc.params.raw;
  393. if (set)
  394. i40evf_fill_default_direct_cmd_desc(&desc,
  395. i40e_aqc_opc_set_rss_lut);
  396. else
  397. i40evf_fill_default_direct_cmd_desc(&desc,
  398. i40e_aqc_opc_get_rss_lut);
  399. /* Indirect command */
  400. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  401. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
  402. cmd_resp->vsi_id =
  403. cpu_to_le16((u16)((vsi_id <<
  404. I40E_AQC_SET_RSS_LUT_VSI_ID_SHIFT) &
  405. I40E_AQC_SET_RSS_LUT_VSI_ID_MASK));
  406. cmd_resp->vsi_id |= cpu_to_le16((u16)I40E_AQC_SET_RSS_LUT_VSI_VALID);
  407. if (pf_lut)
  408. cmd_resp->flags |= cpu_to_le16((u16)
  409. ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_PF <<
  410. I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
  411. I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
  412. else
  413. cmd_resp->flags |= cpu_to_le16((u16)
  414. ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_VSI <<
  415. I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
  416. I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
  417. status = i40evf_asq_send_command(hw, &desc, lut, lut_size, NULL);
  418. return status;
  419. }
  420. /**
  421. * i40evf_aq_get_rss_lut
  422. * @hw: pointer to the hardware structure
  423. * @vsi_id: vsi fw index
  424. * @pf_lut: for PF table set true, for VSI table set false
  425. * @lut: pointer to the lut buffer provided by the caller
  426. * @lut_size: size of the lut buffer
  427. *
  428. * get the RSS lookup table, PF or VSI type
  429. **/
  430. i40e_status i40evf_aq_get_rss_lut(struct i40e_hw *hw, u16 vsi_id,
  431. bool pf_lut, u8 *lut, u16 lut_size)
  432. {
  433. return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size,
  434. false);
  435. }
  436. /**
  437. * i40evf_aq_set_rss_lut
  438. * @hw: pointer to the hardware structure
  439. * @vsi_id: vsi fw index
  440. * @pf_lut: for PF table set true, for VSI table set false
  441. * @lut: pointer to the lut buffer provided by the caller
  442. * @lut_size: size of the lut buffer
  443. *
  444. * set the RSS lookup table, PF or VSI type
  445. **/
  446. i40e_status i40evf_aq_set_rss_lut(struct i40e_hw *hw, u16 vsi_id,
  447. bool pf_lut, u8 *lut, u16 lut_size)
  448. {
  449. return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size, true);
  450. }
  451. /**
  452. * i40e_aq_get_set_rss_key
  453. * @hw: pointer to the hw struct
  454. * @vsi_id: vsi fw index
  455. * @key: pointer to key info struct
  456. * @set: set true to set the key, false to get the key
  457. *
  458. * get the RSS key per VSI
  459. **/
  460. static i40e_status i40e_aq_get_set_rss_key(struct i40e_hw *hw,
  461. u16 vsi_id,
  462. struct i40e_aqc_get_set_rss_key_data *key,
  463. bool set)
  464. {
  465. i40e_status status;
  466. struct i40e_aq_desc desc;
  467. struct i40e_aqc_get_set_rss_key *cmd_resp =
  468. (struct i40e_aqc_get_set_rss_key *)&desc.params.raw;
  469. u16 key_size = sizeof(struct i40e_aqc_get_set_rss_key_data);
  470. if (set)
  471. i40evf_fill_default_direct_cmd_desc(&desc,
  472. i40e_aqc_opc_set_rss_key);
  473. else
  474. i40evf_fill_default_direct_cmd_desc(&desc,
  475. i40e_aqc_opc_get_rss_key);
  476. /* Indirect command */
  477. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  478. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
  479. cmd_resp->vsi_id =
  480. cpu_to_le16((u16)((vsi_id <<
  481. I40E_AQC_SET_RSS_KEY_VSI_ID_SHIFT) &
  482. I40E_AQC_SET_RSS_KEY_VSI_ID_MASK));
  483. cmd_resp->vsi_id |= cpu_to_le16((u16)I40E_AQC_SET_RSS_KEY_VSI_VALID);
  484. status = i40evf_asq_send_command(hw, &desc, key, key_size, NULL);
  485. return status;
  486. }
  487. /**
  488. * i40evf_aq_get_rss_key
  489. * @hw: pointer to the hw struct
  490. * @vsi_id: vsi fw index
  491. * @key: pointer to key info struct
  492. *
  493. **/
  494. i40e_status i40evf_aq_get_rss_key(struct i40e_hw *hw,
  495. u16 vsi_id,
  496. struct i40e_aqc_get_set_rss_key_data *key)
  497. {
  498. return i40e_aq_get_set_rss_key(hw, vsi_id, key, false);
  499. }
  500. /**
  501. * i40evf_aq_set_rss_key
  502. * @hw: pointer to the hw struct
  503. * @vsi_id: vsi fw index
  504. * @key: pointer to key info struct
  505. *
  506. * set the RSS key per VSI
  507. **/
  508. i40e_status i40evf_aq_set_rss_key(struct i40e_hw *hw,
  509. u16 vsi_id,
  510. struct i40e_aqc_get_set_rss_key_data *key)
  511. {
  512. return i40e_aq_get_set_rss_key(hw, vsi_id, key, true);
  513. }
  514. /* The i40evf_ptype_lookup table is used to convert from the 8-bit ptype in the
  515. * hardware to a bit-field that can be used by SW to more easily determine the
  516. * packet type.
  517. *
  518. * Macros are used to shorten the table lines and make this table human
  519. * readable.
  520. *
  521. * We store the PTYPE in the top byte of the bit field - this is just so that
  522. * we can check that the table doesn't have a row missing, as the index into
  523. * the table should be the PTYPE.
  524. *
  525. * Typical work flow:
  526. *
  527. * IF NOT i40evf_ptype_lookup[ptype].known
  528. * THEN
  529. * Packet is unknown
  530. * ELSE IF i40evf_ptype_lookup[ptype].outer_ip == I40E_RX_PTYPE_OUTER_IP
  531. * Use the rest of the fields to look at the tunnels, inner protocols, etc
  532. * ELSE
  533. * Use the enum i40e_rx_l2_ptype to decode the packet type
  534. * ENDIF
  535. */
  536. /* macro to make the table lines short */
  537. #define I40E_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
  538. { PTYPE, \
  539. 1, \
  540. I40E_RX_PTYPE_OUTER_##OUTER_IP, \
  541. I40E_RX_PTYPE_OUTER_##OUTER_IP_VER, \
  542. I40E_RX_PTYPE_##OUTER_FRAG, \
  543. I40E_RX_PTYPE_TUNNEL_##T, \
  544. I40E_RX_PTYPE_TUNNEL_END_##TE, \
  545. I40E_RX_PTYPE_##TEF, \
  546. I40E_RX_PTYPE_INNER_PROT_##I, \
  547. I40E_RX_PTYPE_PAYLOAD_LAYER_##PL }
  548. #define I40E_PTT_UNUSED_ENTRY(PTYPE) \
  549. { PTYPE, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  550. /* shorter macros makes the table fit but are terse */
  551. #define I40E_RX_PTYPE_NOF I40E_RX_PTYPE_NOT_FRAG
  552. #define I40E_RX_PTYPE_FRG I40E_RX_PTYPE_FRAG
  553. #define I40E_RX_PTYPE_INNER_PROT_TS I40E_RX_PTYPE_INNER_PROT_TIMESYNC
  554. /* Lookup table mapping the HW PTYPE to the bit field for decoding */
  555. struct i40e_rx_ptype_decoded i40evf_ptype_lookup[] = {
  556. /* L2 Packet types */
  557. I40E_PTT_UNUSED_ENTRY(0),
  558. I40E_PTT(1, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  559. I40E_PTT(2, L2, NONE, NOF, NONE, NONE, NOF, TS, PAY2),
  560. I40E_PTT(3, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  561. I40E_PTT_UNUSED_ENTRY(4),
  562. I40E_PTT_UNUSED_ENTRY(5),
  563. I40E_PTT(6, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  564. I40E_PTT(7, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  565. I40E_PTT_UNUSED_ENTRY(8),
  566. I40E_PTT_UNUSED_ENTRY(9),
  567. I40E_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  568. I40E_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
  569. I40E_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  570. I40E_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  571. I40E_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  572. I40E_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  573. I40E_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  574. I40E_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  575. I40E_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  576. I40E_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  577. I40E_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  578. I40E_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  579. /* Non Tunneled IPv4 */
  580. I40E_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
  581. I40E_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
  582. I40E_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP, PAY4),
  583. I40E_PTT_UNUSED_ENTRY(25),
  584. I40E_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP, PAY4),
  585. I40E_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
  586. I40E_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
  587. /* IPv4 --> IPv4 */
  588. I40E_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
  589. I40E_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
  590. I40E_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
  591. I40E_PTT_UNUSED_ENTRY(32),
  592. I40E_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
  593. I40E_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
  594. I40E_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
  595. /* IPv4 --> IPv6 */
  596. I40E_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
  597. I40E_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
  598. I40E_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
  599. I40E_PTT_UNUSED_ENTRY(39),
  600. I40E_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
  601. I40E_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
  602. I40E_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
  603. /* IPv4 --> GRE/NAT */
  604. I40E_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
  605. /* IPv4 --> GRE/NAT --> IPv4 */
  606. I40E_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
  607. I40E_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
  608. I40E_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
  609. I40E_PTT_UNUSED_ENTRY(47),
  610. I40E_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
  611. I40E_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
  612. I40E_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
  613. /* IPv4 --> GRE/NAT --> IPv6 */
  614. I40E_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
  615. I40E_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
  616. I40E_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
  617. I40E_PTT_UNUSED_ENTRY(54),
  618. I40E_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
  619. I40E_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
  620. I40E_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
  621. /* IPv4 --> GRE/NAT --> MAC */
  622. I40E_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
  623. /* IPv4 --> GRE/NAT --> MAC --> IPv4 */
  624. I40E_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
  625. I40E_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
  626. I40E_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
  627. I40E_PTT_UNUSED_ENTRY(62),
  628. I40E_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
  629. I40E_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
  630. I40E_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
  631. /* IPv4 --> GRE/NAT -> MAC --> IPv6 */
  632. I40E_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
  633. I40E_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
  634. I40E_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
  635. I40E_PTT_UNUSED_ENTRY(69),
  636. I40E_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
  637. I40E_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
  638. I40E_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
  639. /* IPv4 --> GRE/NAT --> MAC/VLAN */
  640. I40E_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
  641. /* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
  642. I40E_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
  643. I40E_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
  644. I40E_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
  645. I40E_PTT_UNUSED_ENTRY(77),
  646. I40E_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
  647. I40E_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
  648. I40E_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
  649. /* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
  650. I40E_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
  651. I40E_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
  652. I40E_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
  653. I40E_PTT_UNUSED_ENTRY(84),
  654. I40E_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
  655. I40E_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
  656. I40E_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
  657. /* Non Tunneled IPv6 */
  658. I40E_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
  659. I40E_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
  660. I40E_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP, PAY3),
  661. I40E_PTT_UNUSED_ENTRY(91),
  662. I40E_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP, PAY4),
  663. I40E_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
  664. I40E_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
  665. /* IPv6 --> IPv4 */
  666. I40E_PTT(95, IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
  667. I40E_PTT(96, IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
  668. I40E_PTT(97, IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
  669. I40E_PTT_UNUSED_ENTRY(98),
  670. I40E_PTT(99, IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
  671. I40E_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
  672. I40E_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
  673. /* IPv6 --> IPv6 */
  674. I40E_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
  675. I40E_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
  676. I40E_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
  677. I40E_PTT_UNUSED_ENTRY(105),
  678. I40E_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
  679. I40E_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
  680. I40E_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
  681. /* IPv6 --> GRE/NAT */
  682. I40E_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
  683. /* IPv6 --> GRE/NAT -> IPv4 */
  684. I40E_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
  685. I40E_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
  686. I40E_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
  687. I40E_PTT_UNUSED_ENTRY(113),
  688. I40E_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
  689. I40E_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
  690. I40E_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
  691. /* IPv6 --> GRE/NAT -> IPv6 */
  692. I40E_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
  693. I40E_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
  694. I40E_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
  695. I40E_PTT_UNUSED_ENTRY(120),
  696. I40E_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
  697. I40E_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
  698. I40E_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
  699. /* IPv6 --> GRE/NAT -> MAC */
  700. I40E_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
  701. /* IPv6 --> GRE/NAT -> MAC -> IPv4 */
  702. I40E_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
  703. I40E_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
  704. I40E_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
  705. I40E_PTT_UNUSED_ENTRY(128),
  706. I40E_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
  707. I40E_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
  708. I40E_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
  709. /* IPv6 --> GRE/NAT -> MAC -> IPv6 */
  710. I40E_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
  711. I40E_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
  712. I40E_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
  713. I40E_PTT_UNUSED_ENTRY(135),
  714. I40E_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
  715. I40E_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
  716. I40E_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
  717. /* IPv6 --> GRE/NAT -> MAC/VLAN */
  718. I40E_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
  719. /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
  720. I40E_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
  721. I40E_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
  722. I40E_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
  723. I40E_PTT_UNUSED_ENTRY(143),
  724. I40E_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
  725. I40E_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
  726. I40E_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
  727. /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
  728. I40E_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
  729. I40E_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
  730. I40E_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
  731. I40E_PTT_UNUSED_ENTRY(150),
  732. I40E_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
  733. I40E_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
  734. I40E_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
  735. /* unused entries */
  736. I40E_PTT_UNUSED_ENTRY(154),
  737. I40E_PTT_UNUSED_ENTRY(155),
  738. I40E_PTT_UNUSED_ENTRY(156),
  739. I40E_PTT_UNUSED_ENTRY(157),
  740. I40E_PTT_UNUSED_ENTRY(158),
  741. I40E_PTT_UNUSED_ENTRY(159),
  742. I40E_PTT_UNUSED_ENTRY(160),
  743. I40E_PTT_UNUSED_ENTRY(161),
  744. I40E_PTT_UNUSED_ENTRY(162),
  745. I40E_PTT_UNUSED_ENTRY(163),
  746. I40E_PTT_UNUSED_ENTRY(164),
  747. I40E_PTT_UNUSED_ENTRY(165),
  748. I40E_PTT_UNUSED_ENTRY(166),
  749. I40E_PTT_UNUSED_ENTRY(167),
  750. I40E_PTT_UNUSED_ENTRY(168),
  751. I40E_PTT_UNUSED_ENTRY(169),
  752. I40E_PTT_UNUSED_ENTRY(170),
  753. I40E_PTT_UNUSED_ENTRY(171),
  754. I40E_PTT_UNUSED_ENTRY(172),
  755. I40E_PTT_UNUSED_ENTRY(173),
  756. I40E_PTT_UNUSED_ENTRY(174),
  757. I40E_PTT_UNUSED_ENTRY(175),
  758. I40E_PTT_UNUSED_ENTRY(176),
  759. I40E_PTT_UNUSED_ENTRY(177),
  760. I40E_PTT_UNUSED_ENTRY(178),
  761. I40E_PTT_UNUSED_ENTRY(179),
  762. I40E_PTT_UNUSED_ENTRY(180),
  763. I40E_PTT_UNUSED_ENTRY(181),
  764. I40E_PTT_UNUSED_ENTRY(182),
  765. I40E_PTT_UNUSED_ENTRY(183),
  766. I40E_PTT_UNUSED_ENTRY(184),
  767. I40E_PTT_UNUSED_ENTRY(185),
  768. I40E_PTT_UNUSED_ENTRY(186),
  769. I40E_PTT_UNUSED_ENTRY(187),
  770. I40E_PTT_UNUSED_ENTRY(188),
  771. I40E_PTT_UNUSED_ENTRY(189),
  772. I40E_PTT_UNUSED_ENTRY(190),
  773. I40E_PTT_UNUSED_ENTRY(191),
  774. I40E_PTT_UNUSED_ENTRY(192),
  775. I40E_PTT_UNUSED_ENTRY(193),
  776. I40E_PTT_UNUSED_ENTRY(194),
  777. I40E_PTT_UNUSED_ENTRY(195),
  778. I40E_PTT_UNUSED_ENTRY(196),
  779. I40E_PTT_UNUSED_ENTRY(197),
  780. I40E_PTT_UNUSED_ENTRY(198),
  781. I40E_PTT_UNUSED_ENTRY(199),
  782. I40E_PTT_UNUSED_ENTRY(200),
  783. I40E_PTT_UNUSED_ENTRY(201),
  784. I40E_PTT_UNUSED_ENTRY(202),
  785. I40E_PTT_UNUSED_ENTRY(203),
  786. I40E_PTT_UNUSED_ENTRY(204),
  787. I40E_PTT_UNUSED_ENTRY(205),
  788. I40E_PTT_UNUSED_ENTRY(206),
  789. I40E_PTT_UNUSED_ENTRY(207),
  790. I40E_PTT_UNUSED_ENTRY(208),
  791. I40E_PTT_UNUSED_ENTRY(209),
  792. I40E_PTT_UNUSED_ENTRY(210),
  793. I40E_PTT_UNUSED_ENTRY(211),
  794. I40E_PTT_UNUSED_ENTRY(212),
  795. I40E_PTT_UNUSED_ENTRY(213),
  796. I40E_PTT_UNUSED_ENTRY(214),
  797. I40E_PTT_UNUSED_ENTRY(215),
  798. I40E_PTT_UNUSED_ENTRY(216),
  799. I40E_PTT_UNUSED_ENTRY(217),
  800. I40E_PTT_UNUSED_ENTRY(218),
  801. I40E_PTT_UNUSED_ENTRY(219),
  802. I40E_PTT_UNUSED_ENTRY(220),
  803. I40E_PTT_UNUSED_ENTRY(221),
  804. I40E_PTT_UNUSED_ENTRY(222),
  805. I40E_PTT_UNUSED_ENTRY(223),
  806. I40E_PTT_UNUSED_ENTRY(224),
  807. I40E_PTT_UNUSED_ENTRY(225),
  808. I40E_PTT_UNUSED_ENTRY(226),
  809. I40E_PTT_UNUSED_ENTRY(227),
  810. I40E_PTT_UNUSED_ENTRY(228),
  811. I40E_PTT_UNUSED_ENTRY(229),
  812. I40E_PTT_UNUSED_ENTRY(230),
  813. I40E_PTT_UNUSED_ENTRY(231),
  814. I40E_PTT_UNUSED_ENTRY(232),
  815. I40E_PTT_UNUSED_ENTRY(233),
  816. I40E_PTT_UNUSED_ENTRY(234),
  817. I40E_PTT_UNUSED_ENTRY(235),
  818. I40E_PTT_UNUSED_ENTRY(236),
  819. I40E_PTT_UNUSED_ENTRY(237),
  820. I40E_PTT_UNUSED_ENTRY(238),
  821. I40E_PTT_UNUSED_ENTRY(239),
  822. I40E_PTT_UNUSED_ENTRY(240),
  823. I40E_PTT_UNUSED_ENTRY(241),
  824. I40E_PTT_UNUSED_ENTRY(242),
  825. I40E_PTT_UNUSED_ENTRY(243),
  826. I40E_PTT_UNUSED_ENTRY(244),
  827. I40E_PTT_UNUSED_ENTRY(245),
  828. I40E_PTT_UNUSED_ENTRY(246),
  829. I40E_PTT_UNUSED_ENTRY(247),
  830. I40E_PTT_UNUSED_ENTRY(248),
  831. I40E_PTT_UNUSED_ENTRY(249),
  832. I40E_PTT_UNUSED_ENTRY(250),
  833. I40E_PTT_UNUSED_ENTRY(251),
  834. I40E_PTT_UNUSED_ENTRY(252),
  835. I40E_PTT_UNUSED_ENTRY(253),
  836. I40E_PTT_UNUSED_ENTRY(254),
  837. I40E_PTT_UNUSED_ENTRY(255)
  838. };
  839. /**
  840. * i40evf_aq_rx_ctl_read_register - use FW to read from an Rx control register
  841. * @hw: pointer to the hw struct
  842. * @reg_addr: register address
  843. * @reg_val: ptr to register value
  844. * @cmd_details: pointer to command details structure or NULL
  845. *
  846. * Use the firmware to read the Rx control register,
  847. * especially useful if the Rx unit is under heavy pressure
  848. **/
  849. i40e_status i40evf_aq_rx_ctl_read_register(struct i40e_hw *hw,
  850. u32 reg_addr, u32 *reg_val,
  851. struct i40e_asq_cmd_details *cmd_details)
  852. {
  853. struct i40e_aq_desc desc;
  854. struct i40e_aqc_rx_ctl_reg_read_write *cmd_resp =
  855. (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
  856. i40e_status status;
  857. if (!reg_val)
  858. return I40E_ERR_PARAM;
  859. i40evf_fill_default_direct_cmd_desc(&desc,
  860. i40e_aqc_opc_rx_ctl_reg_read);
  861. cmd_resp->address = cpu_to_le32(reg_addr);
  862. status = i40evf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  863. if (status == 0)
  864. *reg_val = le32_to_cpu(cmd_resp->value);
  865. return status;
  866. }
  867. /**
  868. * i40evf_read_rx_ctl - read from an Rx control register
  869. * @hw: pointer to the hw struct
  870. * @reg_addr: register address
  871. **/
  872. u32 i40evf_read_rx_ctl(struct i40e_hw *hw, u32 reg_addr)
  873. {
  874. i40e_status status = 0;
  875. bool use_register;
  876. int retry = 5;
  877. u32 val = 0;
  878. use_register = (((hw->aq.api_maj_ver == 1) &&
  879. (hw->aq.api_min_ver < 5)) ||
  880. (hw->mac.type == I40E_MAC_X722));
  881. if (!use_register) {
  882. do_retry:
  883. status = i40evf_aq_rx_ctl_read_register(hw, reg_addr,
  884. &val, NULL);
  885. if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
  886. usleep_range(1000, 2000);
  887. retry--;
  888. goto do_retry;
  889. }
  890. }
  891. /* if the AQ access failed, try the old-fashioned way */
  892. if (status || use_register)
  893. val = rd32(hw, reg_addr);
  894. return val;
  895. }
  896. /**
  897. * i40evf_aq_rx_ctl_write_register
  898. * @hw: pointer to the hw struct
  899. * @reg_addr: register address
  900. * @reg_val: register value
  901. * @cmd_details: pointer to command details structure or NULL
  902. *
  903. * Use the firmware to write to an Rx control register,
  904. * especially useful if the Rx unit is under heavy pressure
  905. **/
  906. i40e_status i40evf_aq_rx_ctl_write_register(struct i40e_hw *hw,
  907. u32 reg_addr, u32 reg_val,
  908. struct i40e_asq_cmd_details *cmd_details)
  909. {
  910. struct i40e_aq_desc desc;
  911. struct i40e_aqc_rx_ctl_reg_read_write *cmd =
  912. (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
  913. i40e_status status;
  914. i40evf_fill_default_direct_cmd_desc(&desc,
  915. i40e_aqc_opc_rx_ctl_reg_write);
  916. cmd->address = cpu_to_le32(reg_addr);
  917. cmd->value = cpu_to_le32(reg_val);
  918. status = i40evf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  919. return status;
  920. }
  921. /**
  922. * i40evf_write_rx_ctl - write to an Rx control register
  923. * @hw: pointer to the hw struct
  924. * @reg_addr: register address
  925. * @reg_val: register value
  926. **/
  927. void i40evf_write_rx_ctl(struct i40e_hw *hw, u32 reg_addr, u32 reg_val)
  928. {
  929. i40e_status status = 0;
  930. bool use_register;
  931. int retry = 5;
  932. use_register = (((hw->aq.api_maj_ver == 1) &&
  933. (hw->aq.api_min_ver < 5)) ||
  934. (hw->mac.type == I40E_MAC_X722));
  935. if (!use_register) {
  936. do_retry:
  937. status = i40evf_aq_rx_ctl_write_register(hw, reg_addr,
  938. reg_val, NULL);
  939. if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
  940. usleep_range(1000, 2000);
  941. retry--;
  942. goto do_retry;
  943. }
  944. }
  945. /* if the AQ access failed, try the old-fashioned way */
  946. if (status || use_register)
  947. wr32(hw, reg_addr, reg_val);
  948. }
  949. /**
  950. * i40evf_aq_set_phy_register
  951. * @hw: pointer to the hw struct
  952. * @phy_select: select which phy should be accessed
  953. * @dev_addr: PHY device address
  954. * @reg_addr: PHY register address
  955. * @reg_val: new register value
  956. * @cmd_details: pointer to command details structure or NULL
  957. *
  958. * Reset the external PHY.
  959. **/
  960. i40e_status i40evf_aq_set_phy_register(struct i40e_hw *hw,
  961. u8 phy_select, u8 dev_addr,
  962. u32 reg_addr, u32 reg_val,
  963. struct i40e_asq_cmd_details *cmd_details)
  964. {
  965. struct i40e_aq_desc desc;
  966. struct i40e_aqc_phy_register_access *cmd =
  967. (struct i40e_aqc_phy_register_access *)&desc.params.raw;
  968. i40e_status status;
  969. i40evf_fill_default_direct_cmd_desc(&desc,
  970. i40e_aqc_opc_set_phy_register);
  971. cmd->phy_interface = phy_select;
  972. cmd->dev_address = dev_addr;
  973. cmd->reg_address = cpu_to_le32(reg_addr);
  974. cmd->reg_value = cpu_to_le32(reg_val);
  975. status = i40evf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  976. return status;
  977. }
  978. /**
  979. * i40evf_aq_get_phy_register
  980. * @hw: pointer to the hw struct
  981. * @phy_select: select which phy should be accessed
  982. * @dev_addr: PHY device address
  983. * @reg_addr: PHY register address
  984. * @reg_val: read register value
  985. * @cmd_details: pointer to command details structure or NULL
  986. *
  987. * Reset the external PHY.
  988. **/
  989. i40e_status i40evf_aq_get_phy_register(struct i40e_hw *hw,
  990. u8 phy_select, u8 dev_addr,
  991. u32 reg_addr, u32 *reg_val,
  992. struct i40e_asq_cmd_details *cmd_details)
  993. {
  994. struct i40e_aq_desc desc;
  995. struct i40e_aqc_phy_register_access *cmd =
  996. (struct i40e_aqc_phy_register_access *)&desc.params.raw;
  997. i40e_status status;
  998. i40evf_fill_default_direct_cmd_desc(&desc,
  999. i40e_aqc_opc_get_phy_register);
  1000. cmd->phy_interface = phy_select;
  1001. cmd->dev_address = dev_addr;
  1002. cmd->reg_address = cpu_to_le32(reg_addr);
  1003. status = i40evf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  1004. if (!status)
  1005. *reg_val = le32_to_cpu(cmd->reg_value);
  1006. return status;
  1007. }
  1008. /**
  1009. * i40e_aq_send_msg_to_pf
  1010. * @hw: pointer to the hardware structure
  1011. * @v_opcode: opcodes for VF-PF communication
  1012. * @v_retval: return error code
  1013. * @msg: pointer to the msg buffer
  1014. * @msglen: msg length
  1015. * @cmd_details: pointer to command details
  1016. *
  1017. * Send message to PF driver using admin queue. By default, this message
  1018. * is sent asynchronously, i.e. i40evf_asq_send_command() does not wait for
  1019. * completion before returning.
  1020. **/
  1021. i40e_status i40e_aq_send_msg_to_pf(struct i40e_hw *hw,
  1022. enum virtchnl_ops v_opcode,
  1023. i40e_status v_retval,
  1024. u8 *msg, u16 msglen,
  1025. struct i40e_asq_cmd_details *cmd_details)
  1026. {
  1027. struct i40e_aq_desc desc;
  1028. struct i40e_asq_cmd_details details;
  1029. i40e_status status;
  1030. i40evf_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_pf);
  1031. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_SI);
  1032. desc.cookie_high = cpu_to_le32(v_opcode);
  1033. desc.cookie_low = cpu_to_le32(v_retval);
  1034. if (msglen) {
  1035. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF
  1036. | I40E_AQ_FLAG_RD));
  1037. if (msglen > I40E_AQ_LARGE_BUF)
  1038. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1039. desc.datalen = cpu_to_le16(msglen);
  1040. }
  1041. if (!cmd_details) {
  1042. memset(&details, 0, sizeof(details));
  1043. details.async = true;
  1044. cmd_details = &details;
  1045. }
  1046. status = i40evf_asq_send_command(hw, &desc, msg, msglen, cmd_details);
  1047. return status;
  1048. }
  1049. /**
  1050. * i40e_vf_parse_hw_config
  1051. * @hw: pointer to the hardware structure
  1052. * @msg: pointer to the virtual channel VF resource structure
  1053. *
  1054. * Given a VF resource message from the PF, populate the hw struct
  1055. * with appropriate information.
  1056. **/
  1057. void i40e_vf_parse_hw_config(struct i40e_hw *hw,
  1058. struct virtchnl_vf_resource *msg)
  1059. {
  1060. struct virtchnl_vsi_resource *vsi_res;
  1061. int i;
  1062. vsi_res = &msg->vsi_res[0];
  1063. hw->dev_caps.num_vsis = msg->num_vsis;
  1064. hw->dev_caps.num_rx_qp = msg->num_queue_pairs;
  1065. hw->dev_caps.num_tx_qp = msg->num_queue_pairs;
  1066. hw->dev_caps.num_msix_vectors_vf = msg->max_vectors;
  1067. hw->dev_caps.dcb = msg->vf_cap_flags &
  1068. VIRTCHNL_VF_OFFLOAD_L2;
  1069. hw->dev_caps.fcoe = 0;
  1070. for (i = 0; i < msg->num_vsis; i++) {
  1071. if (vsi_res->vsi_type == VIRTCHNL_VSI_SRIOV) {
  1072. ether_addr_copy(hw->mac.perm_addr,
  1073. vsi_res->default_mac_addr);
  1074. ether_addr_copy(hw->mac.addr,
  1075. vsi_res->default_mac_addr);
  1076. }
  1077. vsi_res++;
  1078. }
  1079. }
  1080. /**
  1081. * i40e_vf_reset
  1082. * @hw: pointer to the hardware structure
  1083. *
  1084. * Send a VF_RESET message to the PF. Does not wait for response from PF
  1085. * as none will be forthcoming. Immediately after calling this function,
  1086. * the admin queue should be shut down and (optionally) reinitialized.
  1087. **/
  1088. i40e_status i40e_vf_reset(struct i40e_hw *hw)
  1089. {
  1090. return i40e_aq_send_msg_to_pf(hw, VIRTCHNL_OP_RESET_VF,
  1091. 0, NULL, 0, NULL);
  1092. }
  1093. /**
  1094. * i40evf_aq_write_ddp - Write dynamic device personalization (ddp)
  1095. * @hw: pointer to the hw struct
  1096. * @buff: command buffer (size in bytes = buff_size)
  1097. * @buff_size: buffer size in bytes
  1098. * @track_id: package tracking id
  1099. * @error_offset: returns error offset
  1100. * @error_info: returns error information
  1101. * @cmd_details: pointer to command details structure or NULL
  1102. **/
  1103. enum
  1104. i40e_status_code i40evf_aq_write_ddp(struct i40e_hw *hw, void *buff,
  1105. u16 buff_size, u32 track_id,
  1106. u32 *error_offset, u32 *error_info,
  1107. struct i40e_asq_cmd_details *cmd_details)
  1108. {
  1109. struct i40e_aq_desc desc;
  1110. struct i40e_aqc_write_personalization_profile *cmd =
  1111. (struct i40e_aqc_write_personalization_profile *)
  1112. &desc.params.raw;
  1113. struct i40e_aqc_write_ddp_resp *resp;
  1114. i40e_status status;
  1115. i40evf_fill_default_direct_cmd_desc(&desc,
  1116. i40e_aqc_opc_write_personalization_profile);
  1117. desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
  1118. if (buff_size > I40E_AQ_LARGE_BUF)
  1119. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1120. desc.datalen = cpu_to_le16(buff_size);
  1121. cmd->profile_track_id = cpu_to_le32(track_id);
  1122. status = i40evf_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  1123. if (!status) {
  1124. resp = (struct i40e_aqc_write_ddp_resp *)&desc.params.raw;
  1125. if (error_offset)
  1126. *error_offset = le32_to_cpu(resp->error_offset);
  1127. if (error_info)
  1128. *error_info = le32_to_cpu(resp->error_info);
  1129. }
  1130. return status;
  1131. }
  1132. /**
  1133. * i40evf_aq_get_ddp_list - Read dynamic device personalization (ddp)
  1134. * @hw: pointer to the hw struct
  1135. * @buff: command buffer (size in bytes = buff_size)
  1136. * @buff_size: buffer size in bytes
  1137. * @cmd_details: pointer to command details structure or NULL
  1138. **/
  1139. enum
  1140. i40e_status_code i40evf_aq_get_ddp_list(struct i40e_hw *hw, void *buff,
  1141. u16 buff_size, u8 flags,
  1142. struct i40e_asq_cmd_details *cmd_details)
  1143. {
  1144. struct i40e_aq_desc desc;
  1145. struct i40e_aqc_get_applied_profiles *cmd =
  1146. (struct i40e_aqc_get_applied_profiles *)&desc.params.raw;
  1147. i40e_status status;
  1148. i40evf_fill_default_direct_cmd_desc(&desc,
  1149. i40e_aqc_opc_get_personalization_profile_list);
  1150. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  1151. if (buff_size > I40E_AQ_LARGE_BUF)
  1152. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  1153. desc.datalen = cpu_to_le16(buff_size);
  1154. cmd->flags = flags;
  1155. status = i40evf_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
  1156. return status;
  1157. }
  1158. /**
  1159. * i40evf_find_segment_in_package
  1160. * @segment_type: the segment type to search for (i.e., SEGMENT_TYPE_I40E)
  1161. * @pkg_hdr: pointer to the package header to be searched
  1162. *
  1163. * This function searches a package file for a particular segment type. On
  1164. * success it returns a pointer to the segment header, otherwise it will
  1165. * return NULL.
  1166. **/
  1167. struct i40e_generic_seg_header *
  1168. i40evf_find_segment_in_package(u32 segment_type,
  1169. struct i40e_package_header *pkg_hdr)
  1170. {
  1171. struct i40e_generic_seg_header *segment;
  1172. u32 i;
  1173. /* Search all package segments for the requested segment type */
  1174. for (i = 0; i < pkg_hdr->segment_count; i++) {
  1175. segment =
  1176. (struct i40e_generic_seg_header *)((u8 *)pkg_hdr +
  1177. pkg_hdr->segment_offset[i]);
  1178. if (segment->type == segment_type)
  1179. return segment;
  1180. }
  1181. return NULL;
  1182. }
  1183. /**
  1184. * i40evf_write_profile
  1185. * @hw: pointer to the hardware structure
  1186. * @profile: pointer to the profile segment of the package to be downloaded
  1187. * @track_id: package tracking id
  1188. *
  1189. * Handles the download of a complete package.
  1190. */
  1191. enum i40e_status_code
  1192. i40evf_write_profile(struct i40e_hw *hw, struct i40e_profile_segment *profile,
  1193. u32 track_id)
  1194. {
  1195. i40e_status status = 0;
  1196. struct i40e_section_table *sec_tbl;
  1197. struct i40e_profile_section_header *sec = NULL;
  1198. u32 dev_cnt;
  1199. u32 vendor_dev_id;
  1200. u32 *nvm;
  1201. u32 section_size = 0;
  1202. u32 offset = 0, info = 0;
  1203. u32 i;
  1204. dev_cnt = profile->device_table_count;
  1205. for (i = 0; i < dev_cnt; i++) {
  1206. vendor_dev_id = profile->device_table[i].vendor_dev_id;
  1207. if ((vendor_dev_id >> 16) == PCI_VENDOR_ID_INTEL)
  1208. if (hw->device_id == (vendor_dev_id & 0xFFFF))
  1209. break;
  1210. }
  1211. if (i == dev_cnt) {
  1212. i40e_debug(hw, I40E_DEBUG_PACKAGE, "Device doesn't support DDP");
  1213. return I40E_ERR_DEVICE_NOT_SUPPORTED;
  1214. }
  1215. nvm = (u32 *)&profile->device_table[dev_cnt];
  1216. sec_tbl = (struct i40e_section_table *)&nvm[nvm[0] + 1];
  1217. for (i = 0; i < sec_tbl->section_count; i++) {
  1218. sec = (struct i40e_profile_section_header *)((u8 *)profile +
  1219. sec_tbl->section_offset[i]);
  1220. /* Skip 'AQ', 'note' and 'name' sections */
  1221. if (sec->section.type != SECTION_TYPE_MMIO)
  1222. continue;
  1223. section_size = sec->section.size +
  1224. sizeof(struct i40e_profile_section_header);
  1225. /* Write profile */
  1226. status = i40evf_aq_write_ddp(hw, (void *)sec, (u16)section_size,
  1227. track_id, &offset, &info, NULL);
  1228. if (status) {
  1229. i40e_debug(hw, I40E_DEBUG_PACKAGE,
  1230. "Failed to write profile: offset %d, info %d",
  1231. offset, info);
  1232. break;
  1233. }
  1234. }
  1235. return status;
  1236. }
  1237. /**
  1238. * i40evf_add_pinfo_to_list
  1239. * @hw: pointer to the hardware structure
  1240. * @profile: pointer to the profile segment of the package
  1241. * @profile_info_sec: buffer for information section
  1242. * @track_id: package tracking id
  1243. *
  1244. * Register a profile to the list of loaded profiles.
  1245. */
  1246. enum i40e_status_code
  1247. i40evf_add_pinfo_to_list(struct i40e_hw *hw,
  1248. struct i40e_profile_segment *profile,
  1249. u8 *profile_info_sec, u32 track_id)
  1250. {
  1251. i40e_status status = 0;
  1252. struct i40e_profile_section_header *sec = NULL;
  1253. struct i40e_profile_info *pinfo;
  1254. u32 offset = 0, info = 0;
  1255. sec = (struct i40e_profile_section_header *)profile_info_sec;
  1256. sec->tbl_size = 1;
  1257. sec->data_end = sizeof(struct i40e_profile_section_header) +
  1258. sizeof(struct i40e_profile_info);
  1259. sec->section.type = SECTION_TYPE_INFO;
  1260. sec->section.offset = sizeof(struct i40e_profile_section_header);
  1261. sec->section.size = sizeof(struct i40e_profile_info);
  1262. pinfo = (struct i40e_profile_info *)(profile_info_sec +
  1263. sec->section.offset);
  1264. pinfo->track_id = track_id;
  1265. pinfo->version = profile->version;
  1266. pinfo->op = I40E_DDP_ADD_TRACKID;
  1267. memcpy(pinfo->name, profile->name, I40E_DDP_NAME_SIZE);
  1268. status = i40evf_aq_write_ddp(hw, (void *)sec, sec->data_end,
  1269. track_id, &offset, &info, NULL);
  1270. return status;
  1271. }