i40e_common.c 43 KB

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