i40e_common.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
  4. * Copyright(c) 2013 - 2014 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. * Contact Information:
  22. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. ******************************************************************************/
  26. #include "i40e_type.h"
  27. #include "i40e_adminq.h"
  28. #include "i40e_prototype.h"
  29. #include "i40e_virtchnl.h"
  30. /**
  31. * i40e_set_mac_type - Sets MAC type
  32. * @hw: pointer to the HW structure
  33. *
  34. * This function sets the mac type of the adapter based on the
  35. * vendor ID and device ID stored in the hw structure.
  36. **/
  37. i40e_status i40e_set_mac_type(struct i40e_hw *hw)
  38. {
  39. i40e_status status = 0;
  40. if (hw->vendor_id == PCI_VENDOR_ID_INTEL) {
  41. switch (hw->device_id) {
  42. case I40E_DEV_ID_SFP_XL710:
  43. case I40E_DEV_ID_QEMU:
  44. case I40E_DEV_ID_KX_B:
  45. case I40E_DEV_ID_KX_C:
  46. case I40E_DEV_ID_QSFP_A:
  47. case I40E_DEV_ID_QSFP_B:
  48. case I40E_DEV_ID_QSFP_C:
  49. case I40E_DEV_ID_10G_BASE_T:
  50. case I40E_DEV_ID_10G_BASE_T4:
  51. case I40E_DEV_ID_20G_KR2:
  52. case I40E_DEV_ID_20G_KR2_A:
  53. hw->mac.type = I40E_MAC_XL710;
  54. break;
  55. case I40E_DEV_ID_SFP_X722:
  56. case I40E_DEV_ID_1G_BASE_T_X722:
  57. case I40E_DEV_ID_10G_BASE_T_X722:
  58. case I40E_DEV_ID_SFP_I_X722:
  59. hw->mac.type = I40E_MAC_X722;
  60. break;
  61. case I40E_DEV_ID_X722_VF:
  62. case I40E_DEV_ID_X722_VF_HV:
  63. hw->mac.type = I40E_MAC_X722_VF;
  64. break;
  65. case I40E_DEV_ID_VF:
  66. case I40E_DEV_ID_VF_HV:
  67. hw->mac.type = I40E_MAC_VF;
  68. break;
  69. default:
  70. hw->mac.type = I40E_MAC_GENERIC;
  71. break;
  72. }
  73. } else {
  74. status = I40E_ERR_DEVICE_NOT_SUPPORTED;
  75. }
  76. hw_dbg(hw, "i40e_set_mac_type found mac: %d, returns: %d\n",
  77. hw->mac.type, status);
  78. return status;
  79. }
  80. /**
  81. * i40evf_aq_str - convert AQ err code to a string
  82. * @hw: pointer to the HW structure
  83. * @aq_err: the AQ error code to convert
  84. **/
  85. const char *i40evf_aq_str(struct i40e_hw *hw, enum i40e_admin_queue_err aq_err)
  86. {
  87. switch (aq_err) {
  88. case I40E_AQ_RC_OK:
  89. return "OK";
  90. case I40E_AQ_RC_EPERM:
  91. return "I40E_AQ_RC_EPERM";
  92. case I40E_AQ_RC_ENOENT:
  93. return "I40E_AQ_RC_ENOENT";
  94. case I40E_AQ_RC_ESRCH:
  95. return "I40E_AQ_RC_ESRCH";
  96. case I40E_AQ_RC_EINTR:
  97. return "I40E_AQ_RC_EINTR";
  98. case I40E_AQ_RC_EIO:
  99. return "I40E_AQ_RC_EIO";
  100. case I40E_AQ_RC_ENXIO:
  101. return "I40E_AQ_RC_ENXIO";
  102. case I40E_AQ_RC_E2BIG:
  103. return "I40E_AQ_RC_E2BIG";
  104. case I40E_AQ_RC_EAGAIN:
  105. return "I40E_AQ_RC_EAGAIN";
  106. case I40E_AQ_RC_ENOMEM:
  107. return "I40E_AQ_RC_ENOMEM";
  108. case I40E_AQ_RC_EACCES:
  109. return "I40E_AQ_RC_EACCES";
  110. case I40E_AQ_RC_EFAULT:
  111. return "I40E_AQ_RC_EFAULT";
  112. case I40E_AQ_RC_EBUSY:
  113. return "I40E_AQ_RC_EBUSY";
  114. case I40E_AQ_RC_EEXIST:
  115. return "I40E_AQ_RC_EEXIST";
  116. case I40E_AQ_RC_EINVAL:
  117. return "I40E_AQ_RC_EINVAL";
  118. case I40E_AQ_RC_ENOTTY:
  119. return "I40E_AQ_RC_ENOTTY";
  120. case I40E_AQ_RC_ENOSPC:
  121. return "I40E_AQ_RC_ENOSPC";
  122. case I40E_AQ_RC_ENOSYS:
  123. return "I40E_AQ_RC_ENOSYS";
  124. case I40E_AQ_RC_ERANGE:
  125. return "I40E_AQ_RC_ERANGE";
  126. case I40E_AQ_RC_EFLUSHED:
  127. return "I40E_AQ_RC_EFLUSHED";
  128. case I40E_AQ_RC_BAD_ADDR:
  129. return "I40E_AQ_RC_BAD_ADDR";
  130. case I40E_AQ_RC_EMODE:
  131. return "I40E_AQ_RC_EMODE";
  132. case I40E_AQ_RC_EFBIG:
  133. return "I40E_AQ_RC_EFBIG";
  134. }
  135. snprintf(hw->err_str, sizeof(hw->err_str), "%d", aq_err);
  136. return hw->err_str;
  137. }
  138. /**
  139. * i40evf_stat_str - convert status err code to a string
  140. * @hw: pointer to the HW structure
  141. * @stat_err: the status error code to convert
  142. **/
  143. const char *i40evf_stat_str(struct i40e_hw *hw, i40e_status stat_err)
  144. {
  145. switch (stat_err) {
  146. case 0:
  147. return "OK";
  148. case I40E_ERR_NVM:
  149. return "I40E_ERR_NVM";
  150. case I40E_ERR_NVM_CHECKSUM:
  151. return "I40E_ERR_NVM_CHECKSUM";
  152. case I40E_ERR_PHY:
  153. return "I40E_ERR_PHY";
  154. case I40E_ERR_CONFIG:
  155. return "I40E_ERR_CONFIG";
  156. case I40E_ERR_PARAM:
  157. return "I40E_ERR_PARAM";
  158. case I40E_ERR_MAC_TYPE:
  159. return "I40E_ERR_MAC_TYPE";
  160. case I40E_ERR_UNKNOWN_PHY:
  161. return "I40E_ERR_UNKNOWN_PHY";
  162. case I40E_ERR_LINK_SETUP:
  163. return "I40E_ERR_LINK_SETUP";
  164. case I40E_ERR_ADAPTER_STOPPED:
  165. return "I40E_ERR_ADAPTER_STOPPED";
  166. case I40E_ERR_INVALID_MAC_ADDR:
  167. return "I40E_ERR_INVALID_MAC_ADDR";
  168. case I40E_ERR_DEVICE_NOT_SUPPORTED:
  169. return "I40E_ERR_DEVICE_NOT_SUPPORTED";
  170. case I40E_ERR_MASTER_REQUESTS_PENDING:
  171. return "I40E_ERR_MASTER_REQUESTS_PENDING";
  172. case I40E_ERR_INVALID_LINK_SETTINGS:
  173. return "I40E_ERR_INVALID_LINK_SETTINGS";
  174. case I40E_ERR_AUTONEG_NOT_COMPLETE:
  175. return "I40E_ERR_AUTONEG_NOT_COMPLETE";
  176. case I40E_ERR_RESET_FAILED:
  177. return "I40E_ERR_RESET_FAILED";
  178. case I40E_ERR_SWFW_SYNC:
  179. return "I40E_ERR_SWFW_SYNC";
  180. case I40E_ERR_NO_AVAILABLE_VSI:
  181. return "I40E_ERR_NO_AVAILABLE_VSI";
  182. case I40E_ERR_NO_MEMORY:
  183. return "I40E_ERR_NO_MEMORY";
  184. case I40E_ERR_BAD_PTR:
  185. return "I40E_ERR_BAD_PTR";
  186. case I40E_ERR_RING_FULL:
  187. return "I40E_ERR_RING_FULL";
  188. case I40E_ERR_INVALID_PD_ID:
  189. return "I40E_ERR_INVALID_PD_ID";
  190. case I40E_ERR_INVALID_QP_ID:
  191. return "I40E_ERR_INVALID_QP_ID";
  192. case I40E_ERR_INVALID_CQ_ID:
  193. return "I40E_ERR_INVALID_CQ_ID";
  194. case I40E_ERR_INVALID_CEQ_ID:
  195. return "I40E_ERR_INVALID_CEQ_ID";
  196. case I40E_ERR_INVALID_AEQ_ID:
  197. return "I40E_ERR_INVALID_AEQ_ID";
  198. case I40E_ERR_INVALID_SIZE:
  199. return "I40E_ERR_INVALID_SIZE";
  200. case I40E_ERR_INVALID_ARP_INDEX:
  201. return "I40E_ERR_INVALID_ARP_INDEX";
  202. case I40E_ERR_INVALID_FPM_FUNC_ID:
  203. return "I40E_ERR_INVALID_FPM_FUNC_ID";
  204. case I40E_ERR_QP_INVALID_MSG_SIZE:
  205. return "I40E_ERR_QP_INVALID_MSG_SIZE";
  206. case I40E_ERR_QP_TOOMANY_WRS_POSTED:
  207. return "I40E_ERR_QP_TOOMANY_WRS_POSTED";
  208. case I40E_ERR_INVALID_FRAG_COUNT:
  209. return "I40E_ERR_INVALID_FRAG_COUNT";
  210. case I40E_ERR_QUEUE_EMPTY:
  211. return "I40E_ERR_QUEUE_EMPTY";
  212. case I40E_ERR_INVALID_ALIGNMENT:
  213. return "I40E_ERR_INVALID_ALIGNMENT";
  214. case I40E_ERR_FLUSHED_QUEUE:
  215. return "I40E_ERR_FLUSHED_QUEUE";
  216. case I40E_ERR_INVALID_PUSH_PAGE_INDEX:
  217. return "I40E_ERR_INVALID_PUSH_PAGE_INDEX";
  218. case I40E_ERR_INVALID_IMM_DATA_SIZE:
  219. return "I40E_ERR_INVALID_IMM_DATA_SIZE";
  220. case I40E_ERR_TIMEOUT:
  221. return "I40E_ERR_TIMEOUT";
  222. case I40E_ERR_OPCODE_MISMATCH:
  223. return "I40E_ERR_OPCODE_MISMATCH";
  224. case I40E_ERR_CQP_COMPL_ERROR:
  225. return "I40E_ERR_CQP_COMPL_ERROR";
  226. case I40E_ERR_INVALID_VF_ID:
  227. return "I40E_ERR_INVALID_VF_ID";
  228. case I40E_ERR_INVALID_HMCFN_ID:
  229. return "I40E_ERR_INVALID_HMCFN_ID";
  230. case I40E_ERR_BACKING_PAGE_ERROR:
  231. return "I40E_ERR_BACKING_PAGE_ERROR";
  232. case I40E_ERR_NO_PBLCHUNKS_AVAILABLE:
  233. return "I40E_ERR_NO_PBLCHUNKS_AVAILABLE";
  234. case I40E_ERR_INVALID_PBLE_INDEX:
  235. return "I40E_ERR_INVALID_PBLE_INDEX";
  236. case I40E_ERR_INVALID_SD_INDEX:
  237. return "I40E_ERR_INVALID_SD_INDEX";
  238. case I40E_ERR_INVALID_PAGE_DESC_INDEX:
  239. return "I40E_ERR_INVALID_PAGE_DESC_INDEX";
  240. case I40E_ERR_INVALID_SD_TYPE:
  241. return "I40E_ERR_INVALID_SD_TYPE";
  242. case I40E_ERR_MEMCPY_FAILED:
  243. return "I40E_ERR_MEMCPY_FAILED";
  244. case I40E_ERR_INVALID_HMC_OBJ_INDEX:
  245. return "I40E_ERR_INVALID_HMC_OBJ_INDEX";
  246. case I40E_ERR_INVALID_HMC_OBJ_COUNT:
  247. return "I40E_ERR_INVALID_HMC_OBJ_COUNT";
  248. case I40E_ERR_INVALID_SRQ_ARM_LIMIT:
  249. return "I40E_ERR_INVALID_SRQ_ARM_LIMIT";
  250. case I40E_ERR_SRQ_ENABLED:
  251. return "I40E_ERR_SRQ_ENABLED";
  252. case I40E_ERR_ADMIN_QUEUE_ERROR:
  253. return "I40E_ERR_ADMIN_QUEUE_ERROR";
  254. case I40E_ERR_ADMIN_QUEUE_TIMEOUT:
  255. return "I40E_ERR_ADMIN_QUEUE_TIMEOUT";
  256. case I40E_ERR_BUF_TOO_SHORT:
  257. return "I40E_ERR_BUF_TOO_SHORT";
  258. case I40E_ERR_ADMIN_QUEUE_FULL:
  259. return "I40E_ERR_ADMIN_QUEUE_FULL";
  260. case I40E_ERR_ADMIN_QUEUE_NO_WORK:
  261. return "I40E_ERR_ADMIN_QUEUE_NO_WORK";
  262. case I40E_ERR_BAD_IWARP_CQE:
  263. return "I40E_ERR_BAD_IWARP_CQE";
  264. case I40E_ERR_NVM_BLANK_MODE:
  265. return "I40E_ERR_NVM_BLANK_MODE";
  266. case I40E_ERR_NOT_IMPLEMENTED:
  267. return "I40E_ERR_NOT_IMPLEMENTED";
  268. case I40E_ERR_PE_DOORBELL_NOT_ENABLED:
  269. return "I40E_ERR_PE_DOORBELL_NOT_ENABLED";
  270. case I40E_ERR_DIAG_TEST_FAILED:
  271. return "I40E_ERR_DIAG_TEST_FAILED";
  272. case I40E_ERR_NOT_READY:
  273. return "I40E_ERR_NOT_READY";
  274. case I40E_NOT_SUPPORTED:
  275. return "I40E_NOT_SUPPORTED";
  276. case I40E_ERR_FIRMWARE_API_VERSION:
  277. return "I40E_ERR_FIRMWARE_API_VERSION";
  278. }
  279. snprintf(hw->err_str, sizeof(hw->err_str), "%d", stat_err);
  280. return hw->err_str;
  281. }
  282. /**
  283. * i40evf_debug_aq
  284. * @hw: debug mask related to admin queue
  285. * @mask: debug mask
  286. * @desc: pointer to admin queue descriptor
  287. * @buffer: pointer to command buffer
  288. * @buf_len: max length of buffer
  289. *
  290. * Dumps debug log about adminq command with descriptor contents.
  291. **/
  292. void i40evf_debug_aq(struct i40e_hw *hw, enum i40e_debug_mask mask, void *desc,
  293. void *buffer, u16 buf_len)
  294. {
  295. struct i40e_aq_desc *aq_desc = (struct i40e_aq_desc *)desc;
  296. u8 *buf = (u8 *)buffer;
  297. u16 i = 0;
  298. if ((!(mask & hw->debug_mask)) || (desc == NULL))
  299. return;
  300. i40e_debug(hw, mask,
  301. "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
  302. le16_to_cpu(aq_desc->opcode),
  303. le16_to_cpu(aq_desc->flags),
  304. le16_to_cpu(aq_desc->datalen),
  305. le16_to_cpu(aq_desc->retval));
  306. i40e_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
  307. le32_to_cpu(aq_desc->cookie_high),
  308. le32_to_cpu(aq_desc->cookie_low));
  309. i40e_debug(hw, mask, "\tparam (0,1) 0x%08X 0x%08X\n",
  310. le32_to_cpu(aq_desc->params.internal.param0),
  311. le32_to_cpu(aq_desc->params.internal.param1));
  312. i40e_debug(hw, mask, "\taddr (h,l) 0x%08X 0x%08X\n",
  313. le32_to_cpu(aq_desc->params.external.addr_high),
  314. le32_to_cpu(aq_desc->params.external.addr_low));
  315. if ((buffer != NULL) && (aq_desc->datalen != 0)) {
  316. u16 len = le16_to_cpu(aq_desc->datalen);
  317. i40e_debug(hw, mask, "AQ CMD Buffer:\n");
  318. if (buf_len < len)
  319. len = buf_len;
  320. /* write the full 16-byte chunks */
  321. for (i = 0; i < (len - 16); i += 16)
  322. i40e_debug(hw, mask, "\t0x%04X %16ph\n", i, buf + i);
  323. /* write whatever's left over without overrunning the buffer */
  324. if (i < len)
  325. i40e_debug(hw, mask, "\t0x%04X %*ph\n",
  326. i, len - i, buf + i);
  327. }
  328. }
  329. /**
  330. * i40evf_check_asq_alive
  331. * @hw: pointer to the hw struct
  332. *
  333. * Returns true if Queue is enabled else false.
  334. **/
  335. bool i40evf_check_asq_alive(struct i40e_hw *hw)
  336. {
  337. if (hw->aq.asq.len)
  338. return !!(rd32(hw, hw->aq.asq.len) &
  339. I40E_VF_ATQLEN1_ATQENABLE_MASK);
  340. else
  341. return false;
  342. }
  343. /**
  344. * i40evf_aq_queue_shutdown
  345. * @hw: pointer to the hw struct
  346. * @unloading: is the driver unloading itself
  347. *
  348. * Tell the Firmware that we're shutting down the AdminQ and whether
  349. * or not the driver is unloading as well.
  350. **/
  351. i40e_status i40evf_aq_queue_shutdown(struct i40e_hw *hw,
  352. bool unloading)
  353. {
  354. struct i40e_aq_desc desc;
  355. struct i40e_aqc_queue_shutdown *cmd =
  356. (struct i40e_aqc_queue_shutdown *)&desc.params.raw;
  357. i40e_status status;
  358. i40evf_fill_default_direct_cmd_desc(&desc,
  359. i40e_aqc_opc_queue_shutdown);
  360. if (unloading)
  361. cmd->driver_unloading = cpu_to_le32(I40E_AQ_DRIVER_UNLOADING);
  362. status = i40evf_asq_send_command(hw, &desc, NULL, 0, NULL);
  363. return status;
  364. }
  365. /**
  366. * i40e_aq_get_set_rss_lut
  367. * @hw: pointer to the hardware structure
  368. * @vsi_id: vsi fw index
  369. * @pf_lut: for PF table set true, for VSI table set false
  370. * @lut: pointer to the lut buffer provided by the caller
  371. * @lut_size: size of the lut buffer
  372. * @set: set true to set the table, false to get the table
  373. *
  374. * Internal function to get or set RSS look up table
  375. **/
  376. static i40e_status i40e_aq_get_set_rss_lut(struct i40e_hw *hw,
  377. u16 vsi_id, bool pf_lut,
  378. u8 *lut, u16 lut_size,
  379. bool set)
  380. {
  381. i40e_status status;
  382. struct i40e_aq_desc desc;
  383. struct i40e_aqc_get_set_rss_lut *cmd_resp =
  384. (struct i40e_aqc_get_set_rss_lut *)&desc.params.raw;
  385. if (set)
  386. i40evf_fill_default_direct_cmd_desc(&desc,
  387. i40e_aqc_opc_set_rss_lut);
  388. else
  389. i40evf_fill_default_direct_cmd_desc(&desc,
  390. i40e_aqc_opc_get_rss_lut);
  391. /* Indirect command */
  392. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  393. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
  394. cmd_resp->vsi_id =
  395. cpu_to_le16((u16)((vsi_id <<
  396. I40E_AQC_SET_RSS_LUT_VSI_ID_SHIFT) &
  397. I40E_AQC_SET_RSS_LUT_VSI_ID_MASK));
  398. cmd_resp->vsi_id |= cpu_to_le16((u16)I40E_AQC_SET_RSS_LUT_VSI_VALID);
  399. if (pf_lut)
  400. cmd_resp->flags |= cpu_to_le16((u16)
  401. ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_PF <<
  402. I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
  403. I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
  404. else
  405. cmd_resp->flags |= cpu_to_le16((u16)
  406. ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_VSI <<
  407. I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
  408. I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
  409. status = i40evf_asq_send_command(hw, &desc, lut, lut_size, NULL);
  410. return status;
  411. }
  412. /**
  413. * i40evf_aq_get_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. * get the RSS lookup table, PF or VSI type
  421. **/
  422. i40e_status i40evf_aq_get_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,
  426. false);
  427. }
  428. /**
  429. * i40evf_aq_set_rss_lut
  430. * @hw: pointer to the hardware structure
  431. * @vsi_id: vsi fw index
  432. * @pf_lut: for PF table set true, for VSI table set false
  433. * @lut: pointer to the lut buffer provided by the caller
  434. * @lut_size: size of the lut buffer
  435. *
  436. * set the RSS lookup table, PF or VSI type
  437. **/
  438. i40e_status i40evf_aq_set_rss_lut(struct i40e_hw *hw, u16 vsi_id,
  439. bool pf_lut, u8 *lut, u16 lut_size)
  440. {
  441. return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size, true);
  442. }
  443. /**
  444. * i40e_aq_get_set_rss_key
  445. * @hw: pointer to the hw struct
  446. * @vsi_id: vsi fw index
  447. * @key: pointer to key info struct
  448. * @set: set true to set the key, false to get the key
  449. *
  450. * get the RSS key per VSI
  451. **/
  452. static i40e_status i40e_aq_get_set_rss_key(struct i40e_hw *hw,
  453. u16 vsi_id,
  454. struct i40e_aqc_get_set_rss_key_data *key,
  455. bool set)
  456. {
  457. i40e_status status;
  458. struct i40e_aq_desc desc;
  459. struct i40e_aqc_get_set_rss_key *cmd_resp =
  460. (struct i40e_aqc_get_set_rss_key *)&desc.params.raw;
  461. u16 key_size = sizeof(struct i40e_aqc_get_set_rss_key_data);
  462. if (set)
  463. i40evf_fill_default_direct_cmd_desc(&desc,
  464. i40e_aqc_opc_set_rss_key);
  465. else
  466. i40evf_fill_default_direct_cmd_desc(&desc,
  467. i40e_aqc_opc_get_rss_key);
  468. /* Indirect command */
  469. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  470. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
  471. cmd_resp->vsi_id =
  472. cpu_to_le16((u16)((vsi_id <<
  473. I40E_AQC_SET_RSS_KEY_VSI_ID_SHIFT) &
  474. I40E_AQC_SET_RSS_KEY_VSI_ID_MASK));
  475. cmd_resp->vsi_id |= cpu_to_le16((u16)I40E_AQC_SET_RSS_KEY_VSI_VALID);
  476. status = i40evf_asq_send_command(hw, &desc, key, key_size, NULL);
  477. return status;
  478. }
  479. /**
  480. * i40evf_aq_get_rss_key
  481. * @hw: pointer to the hw struct
  482. * @vsi_id: vsi fw index
  483. * @key: pointer to key info struct
  484. *
  485. **/
  486. i40e_status i40evf_aq_get_rss_key(struct i40e_hw *hw,
  487. u16 vsi_id,
  488. struct i40e_aqc_get_set_rss_key_data *key)
  489. {
  490. return i40e_aq_get_set_rss_key(hw, vsi_id, key, false);
  491. }
  492. /**
  493. * i40evf_aq_set_rss_key
  494. * @hw: pointer to the hw struct
  495. * @vsi_id: vsi fw index
  496. * @key: pointer to key info struct
  497. *
  498. * set the RSS key per VSI
  499. **/
  500. i40e_status i40evf_aq_set_rss_key(struct i40e_hw *hw,
  501. u16 vsi_id,
  502. struct i40e_aqc_get_set_rss_key_data *key)
  503. {
  504. return i40e_aq_get_set_rss_key(hw, vsi_id, key, true);
  505. }
  506. /* The i40evf_ptype_lookup table is used to convert from the 8-bit ptype in the
  507. * hardware to a bit-field that can be used by SW to more easily determine the
  508. * packet type.
  509. *
  510. * Macros are used to shorten the table lines and make this table human
  511. * readable.
  512. *
  513. * We store the PTYPE in the top byte of the bit field - this is just so that
  514. * we can check that the table doesn't have a row missing, as the index into
  515. * the table should be the PTYPE.
  516. *
  517. * Typical work flow:
  518. *
  519. * IF NOT i40evf_ptype_lookup[ptype].known
  520. * THEN
  521. * Packet is unknown
  522. * ELSE IF i40evf_ptype_lookup[ptype].outer_ip == I40E_RX_PTYPE_OUTER_IP
  523. * Use the rest of the fields to look at the tunnels, inner protocols, etc
  524. * ELSE
  525. * Use the enum i40e_rx_l2_ptype to decode the packet type
  526. * ENDIF
  527. */
  528. /* macro to make the table lines short */
  529. #define I40E_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
  530. { PTYPE, \
  531. 1, \
  532. I40E_RX_PTYPE_OUTER_##OUTER_IP, \
  533. I40E_RX_PTYPE_OUTER_##OUTER_IP_VER, \
  534. I40E_RX_PTYPE_##OUTER_FRAG, \
  535. I40E_RX_PTYPE_TUNNEL_##T, \
  536. I40E_RX_PTYPE_TUNNEL_END_##TE, \
  537. I40E_RX_PTYPE_##TEF, \
  538. I40E_RX_PTYPE_INNER_PROT_##I, \
  539. I40E_RX_PTYPE_PAYLOAD_LAYER_##PL }
  540. #define I40E_PTT_UNUSED_ENTRY(PTYPE) \
  541. { PTYPE, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  542. /* shorter macros makes the table fit but are terse */
  543. #define I40E_RX_PTYPE_NOF I40E_RX_PTYPE_NOT_FRAG
  544. #define I40E_RX_PTYPE_FRG I40E_RX_PTYPE_FRAG
  545. #define I40E_RX_PTYPE_INNER_PROT_TS I40E_RX_PTYPE_INNER_PROT_TIMESYNC
  546. /* Lookup table mapping the HW PTYPE to the bit field for decoding */
  547. struct i40e_rx_ptype_decoded i40evf_ptype_lookup[] = {
  548. /* L2 Packet types */
  549. I40E_PTT_UNUSED_ENTRY(0),
  550. I40E_PTT(1, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  551. I40E_PTT(2, L2, NONE, NOF, NONE, NONE, NOF, TS, PAY2),
  552. I40E_PTT(3, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  553. I40E_PTT_UNUSED_ENTRY(4),
  554. I40E_PTT_UNUSED_ENTRY(5),
  555. I40E_PTT(6, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  556. I40E_PTT(7, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  557. I40E_PTT_UNUSED_ENTRY(8),
  558. I40E_PTT_UNUSED_ENTRY(9),
  559. I40E_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  560. I40E_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
  561. I40E_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  562. I40E_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  563. I40E_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  564. I40E_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  565. I40E_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  566. I40E_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  567. I40E_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  568. I40E_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  569. I40E_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  570. I40E_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  571. /* Non Tunneled IPv4 */
  572. I40E_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
  573. I40E_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
  574. I40E_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP, PAY4),
  575. I40E_PTT_UNUSED_ENTRY(25),
  576. I40E_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP, PAY4),
  577. I40E_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
  578. I40E_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
  579. /* IPv4 --> IPv4 */
  580. I40E_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
  581. I40E_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
  582. I40E_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
  583. I40E_PTT_UNUSED_ENTRY(32),
  584. I40E_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
  585. I40E_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
  586. I40E_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
  587. /* IPv4 --> IPv6 */
  588. I40E_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
  589. I40E_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
  590. I40E_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
  591. I40E_PTT_UNUSED_ENTRY(39),
  592. I40E_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
  593. I40E_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
  594. I40E_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
  595. /* IPv4 --> GRE/NAT */
  596. I40E_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
  597. /* IPv4 --> GRE/NAT --> IPv4 */
  598. I40E_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
  599. I40E_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
  600. I40E_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
  601. I40E_PTT_UNUSED_ENTRY(47),
  602. I40E_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
  603. I40E_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
  604. I40E_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
  605. /* IPv4 --> GRE/NAT --> IPv6 */
  606. I40E_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
  607. I40E_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
  608. I40E_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
  609. I40E_PTT_UNUSED_ENTRY(54),
  610. I40E_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
  611. I40E_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
  612. I40E_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
  613. /* IPv4 --> GRE/NAT --> MAC */
  614. I40E_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
  615. /* IPv4 --> GRE/NAT --> MAC --> IPv4 */
  616. I40E_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
  617. I40E_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
  618. I40E_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
  619. I40E_PTT_UNUSED_ENTRY(62),
  620. I40E_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
  621. I40E_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
  622. I40E_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
  623. /* IPv4 --> GRE/NAT -> MAC --> IPv6 */
  624. I40E_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
  625. I40E_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
  626. I40E_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
  627. I40E_PTT_UNUSED_ENTRY(69),
  628. I40E_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
  629. I40E_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
  630. I40E_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
  631. /* IPv4 --> GRE/NAT --> MAC/VLAN */
  632. I40E_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
  633. /* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
  634. I40E_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
  635. I40E_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
  636. I40E_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
  637. I40E_PTT_UNUSED_ENTRY(77),
  638. I40E_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
  639. I40E_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
  640. I40E_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
  641. /* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
  642. I40E_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
  643. I40E_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
  644. I40E_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
  645. I40E_PTT_UNUSED_ENTRY(84),
  646. I40E_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
  647. I40E_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
  648. I40E_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
  649. /* Non Tunneled IPv6 */
  650. I40E_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
  651. I40E_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
  652. I40E_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP, PAY3),
  653. I40E_PTT_UNUSED_ENTRY(91),
  654. I40E_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP, PAY4),
  655. I40E_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
  656. I40E_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
  657. /* IPv6 --> IPv4 */
  658. I40E_PTT(95, IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
  659. I40E_PTT(96, IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
  660. I40E_PTT(97, IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
  661. I40E_PTT_UNUSED_ENTRY(98),
  662. I40E_PTT(99, IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
  663. I40E_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
  664. I40E_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
  665. /* IPv6 --> IPv6 */
  666. I40E_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
  667. I40E_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
  668. I40E_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
  669. I40E_PTT_UNUSED_ENTRY(105),
  670. I40E_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
  671. I40E_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
  672. I40E_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
  673. /* IPv6 --> GRE/NAT */
  674. I40E_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
  675. /* IPv6 --> GRE/NAT -> IPv4 */
  676. I40E_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
  677. I40E_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
  678. I40E_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
  679. I40E_PTT_UNUSED_ENTRY(113),
  680. I40E_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
  681. I40E_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
  682. I40E_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
  683. /* IPv6 --> GRE/NAT -> IPv6 */
  684. I40E_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
  685. I40E_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
  686. I40E_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
  687. I40E_PTT_UNUSED_ENTRY(120),
  688. I40E_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
  689. I40E_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
  690. I40E_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
  691. /* IPv6 --> GRE/NAT -> MAC */
  692. I40E_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
  693. /* IPv6 --> GRE/NAT -> MAC -> IPv4 */
  694. I40E_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
  695. I40E_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
  696. I40E_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
  697. I40E_PTT_UNUSED_ENTRY(128),
  698. I40E_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
  699. I40E_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
  700. I40E_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
  701. /* IPv6 --> GRE/NAT -> MAC -> IPv6 */
  702. I40E_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
  703. I40E_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
  704. I40E_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
  705. I40E_PTT_UNUSED_ENTRY(135),
  706. I40E_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
  707. I40E_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
  708. I40E_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
  709. /* IPv6 --> GRE/NAT -> MAC/VLAN */
  710. I40E_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
  711. /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
  712. I40E_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
  713. I40E_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
  714. I40E_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
  715. I40E_PTT_UNUSED_ENTRY(143),
  716. I40E_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
  717. I40E_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
  718. I40E_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
  719. /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
  720. I40E_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
  721. I40E_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
  722. I40E_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
  723. I40E_PTT_UNUSED_ENTRY(150),
  724. I40E_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
  725. I40E_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
  726. I40E_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
  727. /* unused entries */
  728. I40E_PTT_UNUSED_ENTRY(154),
  729. I40E_PTT_UNUSED_ENTRY(155),
  730. I40E_PTT_UNUSED_ENTRY(156),
  731. I40E_PTT_UNUSED_ENTRY(157),
  732. I40E_PTT_UNUSED_ENTRY(158),
  733. I40E_PTT_UNUSED_ENTRY(159),
  734. I40E_PTT_UNUSED_ENTRY(160),
  735. I40E_PTT_UNUSED_ENTRY(161),
  736. I40E_PTT_UNUSED_ENTRY(162),
  737. I40E_PTT_UNUSED_ENTRY(163),
  738. I40E_PTT_UNUSED_ENTRY(164),
  739. I40E_PTT_UNUSED_ENTRY(165),
  740. I40E_PTT_UNUSED_ENTRY(166),
  741. I40E_PTT_UNUSED_ENTRY(167),
  742. I40E_PTT_UNUSED_ENTRY(168),
  743. I40E_PTT_UNUSED_ENTRY(169),
  744. I40E_PTT_UNUSED_ENTRY(170),
  745. I40E_PTT_UNUSED_ENTRY(171),
  746. I40E_PTT_UNUSED_ENTRY(172),
  747. I40E_PTT_UNUSED_ENTRY(173),
  748. I40E_PTT_UNUSED_ENTRY(174),
  749. I40E_PTT_UNUSED_ENTRY(175),
  750. I40E_PTT_UNUSED_ENTRY(176),
  751. I40E_PTT_UNUSED_ENTRY(177),
  752. I40E_PTT_UNUSED_ENTRY(178),
  753. I40E_PTT_UNUSED_ENTRY(179),
  754. I40E_PTT_UNUSED_ENTRY(180),
  755. I40E_PTT_UNUSED_ENTRY(181),
  756. I40E_PTT_UNUSED_ENTRY(182),
  757. I40E_PTT_UNUSED_ENTRY(183),
  758. I40E_PTT_UNUSED_ENTRY(184),
  759. I40E_PTT_UNUSED_ENTRY(185),
  760. I40E_PTT_UNUSED_ENTRY(186),
  761. I40E_PTT_UNUSED_ENTRY(187),
  762. I40E_PTT_UNUSED_ENTRY(188),
  763. I40E_PTT_UNUSED_ENTRY(189),
  764. I40E_PTT_UNUSED_ENTRY(190),
  765. I40E_PTT_UNUSED_ENTRY(191),
  766. I40E_PTT_UNUSED_ENTRY(192),
  767. I40E_PTT_UNUSED_ENTRY(193),
  768. I40E_PTT_UNUSED_ENTRY(194),
  769. I40E_PTT_UNUSED_ENTRY(195),
  770. I40E_PTT_UNUSED_ENTRY(196),
  771. I40E_PTT_UNUSED_ENTRY(197),
  772. I40E_PTT_UNUSED_ENTRY(198),
  773. I40E_PTT_UNUSED_ENTRY(199),
  774. I40E_PTT_UNUSED_ENTRY(200),
  775. I40E_PTT_UNUSED_ENTRY(201),
  776. I40E_PTT_UNUSED_ENTRY(202),
  777. I40E_PTT_UNUSED_ENTRY(203),
  778. I40E_PTT_UNUSED_ENTRY(204),
  779. I40E_PTT_UNUSED_ENTRY(205),
  780. I40E_PTT_UNUSED_ENTRY(206),
  781. I40E_PTT_UNUSED_ENTRY(207),
  782. I40E_PTT_UNUSED_ENTRY(208),
  783. I40E_PTT_UNUSED_ENTRY(209),
  784. I40E_PTT_UNUSED_ENTRY(210),
  785. I40E_PTT_UNUSED_ENTRY(211),
  786. I40E_PTT_UNUSED_ENTRY(212),
  787. I40E_PTT_UNUSED_ENTRY(213),
  788. I40E_PTT_UNUSED_ENTRY(214),
  789. I40E_PTT_UNUSED_ENTRY(215),
  790. I40E_PTT_UNUSED_ENTRY(216),
  791. I40E_PTT_UNUSED_ENTRY(217),
  792. I40E_PTT_UNUSED_ENTRY(218),
  793. I40E_PTT_UNUSED_ENTRY(219),
  794. I40E_PTT_UNUSED_ENTRY(220),
  795. I40E_PTT_UNUSED_ENTRY(221),
  796. I40E_PTT_UNUSED_ENTRY(222),
  797. I40E_PTT_UNUSED_ENTRY(223),
  798. I40E_PTT_UNUSED_ENTRY(224),
  799. I40E_PTT_UNUSED_ENTRY(225),
  800. I40E_PTT_UNUSED_ENTRY(226),
  801. I40E_PTT_UNUSED_ENTRY(227),
  802. I40E_PTT_UNUSED_ENTRY(228),
  803. I40E_PTT_UNUSED_ENTRY(229),
  804. I40E_PTT_UNUSED_ENTRY(230),
  805. I40E_PTT_UNUSED_ENTRY(231),
  806. I40E_PTT_UNUSED_ENTRY(232),
  807. I40E_PTT_UNUSED_ENTRY(233),
  808. I40E_PTT_UNUSED_ENTRY(234),
  809. I40E_PTT_UNUSED_ENTRY(235),
  810. I40E_PTT_UNUSED_ENTRY(236),
  811. I40E_PTT_UNUSED_ENTRY(237),
  812. I40E_PTT_UNUSED_ENTRY(238),
  813. I40E_PTT_UNUSED_ENTRY(239),
  814. I40E_PTT_UNUSED_ENTRY(240),
  815. I40E_PTT_UNUSED_ENTRY(241),
  816. I40E_PTT_UNUSED_ENTRY(242),
  817. I40E_PTT_UNUSED_ENTRY(243),
  818. I40E_PTT_UNUSED_ENTRY(244),
  819. I40E_PTT_UNUSED_ENTRY(245),
  820. I40E_PTT_UNUSED_ENTRY(246),
  821. I40E_PTT_UNUSED_ENTRY(247),
  822. I40E_PTT_UNUSED_ENTRY(248),
  823. I40E_PTT_UNUSED_ENTRY(249),
  824. I40E_PTT_UNUSED_ENTRY(250),
  825. I40E_PTT_UNUSED_ENTRY(251),
  826. I40E_PTT_UNUSED_ENTRY(252),
  827. I40E_PTT_UNUSED_ENTRY(253),
  828. I40E_PTT_UNUSED_ENTRY(254),
  829. I40E_PTT_UNUSED_ENTRY(255)
  830. };
  831. /**
  832. * i40evf_aq_rx_ctl_read_register - use FW to read from an Rx control register
  833. * @hw: pointer to the hw struct
  834. * @reg_addr: register address
  835. * @reg_val: ptr to register value
  836. * @cmd_details: pointer to command details structure or NULL
  837. *
  838. * Use the firmware to read the Rx control register,
  839. * especially useful if the Rx unit is under heavy pressure
  840. **/
  841. i40e_status i40evf_aq_rx_ctl_read_register(struct i40e_hw *hw,
  842. u32 reg_addr, u32 *reg_val,
  843. struct i40e_asq_cmd_details *cmd_details)
  844. {
  845. struct i40e_aq_desc desc;
  846. struct i40e_aqc_rx_ctl_reg_read_write *cmd_resp =
  847. (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
  848. i40e_status status;
  849. if (!reg_val)
  850. return I40E_ERR_PARAM;
  851. i40evf_fill_default_direct_cmd_desc(&desc,
  852. i40e_aqc_opc_rx_ctl_reg_read);
  853. cmd_resp->address = cpu_to_le32(reg_addr);
  854. status = i40evf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  855. if (status == 0)
  856. *reg_val = le32_to_cpu(cmd_resp->value);
  857. return status;
  858. }
  859. /**
  860. * i40evf_read_rx_ctl - read from an Rx control register
  861. * @hw: pointer to the hw struct
  862. * @reg_addr: register address
  863. **/
  864. u32 i40evf_read_rx_ctl(struct i40e_hw *hw, u32 reg_addr)
  865. {
  866. i40e_status status = 0;
  867. bool use_register;
  868. int retry = 5;
  869. u32 val = 0;
  870. use_register = (hw->aq.api_maj_ver == 1) && (hw->aq.api_min_ver < 5);
  871. if (!use_register) {
  872. do_retry:
  873. status = i40evf_aq_rx_ctl_read_register(hw, reg_addr,
  874. &val, NULL);
  875. if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
  876. usleep_range(1000, 2000);
  877. retry--;
  878. goto do_retry;
  879. }
  880. }
  881. /* if the AQ access failed, try the old-fashioned way */
  882. if (status || use_register)
  883. val = rd32(hw, reg_addr);
  884. return val;
  885. }
  886. /**
  887. * i40evf_aq_rx_ctl_write_register
  888. * @hw: pointer to the hw struct
  889. * @reg_addr: register address
  890. * @reg_val: register value
  891. * @cmd_details: pointer to command details structure or NULL
  892. *
  893. * Use the firmware to write to an Rx control register,
  894. * especially useful if the Rx unit is under heavy pressure
  895. **/
  896. i40e_status i40evf_aq_rx_ctl_write_register(struct i40e_hw *hw,
  897. u32 reg_addr, u32 reg_val,
  898. struct i40e_asq_cmd_details *cmd_details)
  899. {
  900. struct i40e_aq_desc desc;
  901. struct i40e_aqc_rx_ctl_reg_read_write *cmd =
  902. (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
  903. i40e_status status;
  904. i40evf_fill_default_direct_cmd_desc(&desc,
  905. i40e_aqc_opc_rx_ctl_reg_write);
  906. cmd->address = cpu_to_le32(reg_addr);
  907. cmd->value = cpu_to_le32(reg_val);
  908. status = i40evf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
  909. return status;
  910. }
  911. /**
  912. * i40evf_write_rx_ctl - write to an Rx control register
  913. * @hw: pointer to the hw struct
  914. * @reg_addr: register address
  915. * @reg_val: register value
  916. **/
  917. void i40evf_write_rx_ctl(struct i40e_hw *hw, u32 reg_addr, u32 reg_val)
  918. {
  919. i40e_status status = 0;
  920. bool use_register;
  921. int retry = 5;
  922. use_register = (hw->aq.api_maj_ver == 1) && (hw->aq.api_min_ver < 5);
  923. if (!use_register) {
  924. do_retry:
  925. status = i40evf_aq_rx_ctl_write_register(hw, reg_addr,
  926. reg_val, NULL);
  927. if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
  928. usleep_range(1000, 2000);
  929. retry--;
  930. goto do_retry;
  931. }
  932. }
  933. /* if the AQ access failed, try the old-fashioned way */
  934. if (status || use_register)
  935. wr32(hw, reg_addr, reg_val);
  936. }
  937. /**
  938. * i40e_aq_send_msg_to_pf
  939. * @hw: pointer to the hardware structure
  940. * @v_opcode: opcodes for VF-PF communication
  941. * @v_retval: return error code
  942. * @msg: pointer to the msg buffer
  943. * @msglen: msg length
  944. * @cmd_details: pointer to command details
  945. *
  946. * Send message to PF driver using admin queue. By default, this message
  947. * is sent asynchronously, i.e. i40evf_asq_send_command() does not wait for
  948. * completion before returning.
  949. **/
  950. i40e_status i40e_aq_send_msg_to_pf(struct i40e_hw *hw,
  951. enum i40e_virtchnl_ops v_opcode,
  952. i40e_status v_retval,
  953. u8 *msg, u16 msglen,
  954. struct i40e_asq_cmd_details *cmd_details)
  955. {
  956. struct i40e_aq_desc desc;
  957. struct i40e_asq_cmd_details details;
  958. i40e_status status;
  959. i40evf_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_pf);
  960. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_SI);
  961. desc.cookie_high = cpu_to_le32(v_opcode);
  962. desc.cookie_low = cpu_to_le32(v_retval);
  963. if (msglen) {
  964. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF
  965. | I40E_AQ_FLAG_RD));
  966. if (msglen > I40E_AQ_LARGE_BUF)
  967. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  968. desc.datalen = cpu_to_le16(msglen);
  969. }
  970. if (!cmd_details) {
  971. memset(&details, 0, sizeof(details));
  972. details.async = true;
  973. cmd_details = &details;
  974. }
  975. status = i40evf_asq_send_command(hw, &desc, msg, msglen, cmd_details);
  976. return status;
  977. }
  978. /**
  979. * i40e_vf_parse_hw_config
  980. * @hw: pointer to the hardware structure
  981. * @msg: pointer to the virtual channel VF resource structure
  982. *
  983. * Given a VF resource message from the PF, populate the hw struct
  984. * with appropriate information.
  985. **/
  986. void i40e_vf_parse_hw_config(struct i40e_hw *hw,
  987. struct i40e_virtchnl_vf_resource *msg)
  988. {
  989. struct i40e_virtchnl_vsi_resource *vsi_res;
  990. int i;
  991. vsi_res = &msg->vsi_res[0];
  992. hw->dev_caps.num_vsis = msg->num_vsis;
  993. hw->dev_caps.num_rx_qp = msg->num_queue_pairs;
  994. hw->dev_caps.num_tx_qp = msg->num_queue_pairs;
  995. hw->dev_caps.num_msix_vectors_vf = msg->max_vectors;
  996. hw->dev_caps.dcb = msg->vf_offload_flags &
  997. I40E_VIRTCHNL_VF_OFFLOAD_L2;
  998. hw->dev_caps.fcoe = (msg->vf_offload_flags &
  999. I40E_VIRTCHNL_VF_OFFLOAD_FCOE) ? 1 : 0;
  1000. for (i = 0; i < msg->num_vsis; i++) {
  1001. if (vsi_res->vsi_type == I40E_VSI_SRIOV) {
  1002. ether_addr_copy(hw->mac.perm_addr,
  1003. vsi_res->default_mac_addr);
  1004. ether_addr_copy(hw->mac.addr,
  1005. vsi_res->default_mac_addr);
  1006. }
  1007. vsi_res++;
  1008. }
  1009. }
  1010. /**
  1011. * i40e_vf_reset
  1012. * @hw: pointer to the hardware structure
  1013. *
  1014. * Send a VF_RESET message to the PF. Does not wait for response from PF
  1015. * as none will be forthcoming. Immediately after calling this function,
  1016. * the admin queue should be shut down and (optionally) reinitialized.
  1017. **/
  1018. i40e_status i40e_vf_reset(struct i40e_hw *hw)
  1019. {
  1020. return i40e_aq_send_msg_to_pf(hw, I40E_VIRTCHNL_OP_RESET_VF,
  1021. 0, NULL, 0, NULL);
  1022. }