i40e_common.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  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_A:
  45. case I40E_DEV_ID_KX_B:
  46. case I40E_DEV_ID_KX_C:
  47. case I40E_DEV_ID_QSFP_A:
  48. case I40E_DEV_ID_QSFP_B:
  49. case I40E_DEV_ID_QSFP_C:
  50. case I40E_DEV_ID_10G_BASE_T:
  51. case I40E_DEV_ID_20G_KR2:
  52. hw->mac.type = I40E_MAC_XL710;
  53. break;
  54. case I40E_DEV_ID_VF:
  55. case I40E_DEV_ID_VF_HV:
  56. hw->mac.type = I40E_MAC_VF;
  57. break;
  58. default:
  59. hw->mac.type = I40E_MAC_GENERIC;
  60. break;
  61. }
  62. } else {
  63. status = I40E_ERR_DEVICE_NOT_SUPPORTED;
  64. }
  65. hw_dbg(hw, "i40e_set_mac_type found mac: %d, returns: %d\n",
  66. hw->mac.type, status);
  67. return status;
  68. }
  69. /**
  70. * i40evf_debug_aq
  71. * @hw: debug mask related to admin queue
  72. * @mask: debug mask
  73. * @desc: pointer to admin queue descriptor
  74. * @buffer: pointer to command buffer
  75. * @buf_len: max length of buffer
  76. *
  77. * Dumps debug log about adminq command with descriptor contents.
  78. **/
  79. void i40evf_debug_aq(struct i40e_hw *hw, enum i40e_debug_mask mask, void *desc,
  80. void *buffer, u16 buf_len)
  81. {
  82. struct i40e_aq_desc *aq_desc = (struct i40e_aq_desc *)desc;
  83. u16 len = le16_to_cpu(aq_desc->datalen);
  84. u8 *buf = (u8 *)buffer;
  85. u16 i = 0;
  86. if ((!(mask & hw->debug_mask)) || (desc == NULL))
  87. return;
  88. i40e_debug(hw, mask,
  89. "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
  90. le16_to_cpu(aq_desc->opcode),
  91. le16_to_cpu(aq_desc->flags),
  92. le16_to_cpu(aq_desc->datalen),
  93. le16_to_cpu(aq_desc->retval));
  94. i40e_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
  95. le32_to_cpu(aq_desc->cookie_high),
  96. le32_to_cpu(aq_desc->cookie_low));
  97. i40e_debug(hw, mask, "\tparam (0,1) 0x%08X 0x%08X\n",
  98. le32_to_cpu(aq_desc->params.internal.param0),
  99. le32_to_cpu(aq_desc->params.internal.param1));
  100. i40e_debug(hw, mask, "\taddr (h,l) 0x%08X 0x%08X\n",
  101. le32_to_cpu(aq_desc->params.external.addr_high),
  102. le32_to_cpu(aq_desc->params.external.addr_low));
  103. if ((buffer != NULL) && (aq_desc->datalen != 0)) {
  104. i40e_debug(hw, mask, "AQ CMD Buffer:\n");
  105. if (buf_len < len)
  106. len = buf_len;
  107. /* write the full 16-byte chunks */
  108. for (i = 0; i < (len - 16); i += 16)
  109. i40e_debug(hw, mask,
  110. "\t0x%04X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n",
  111. i, buf[i], buf[i + 1], buf[i + 2],
  112. buf[i + 3], buf[i + 4], buf[i + 5],
  113. buf[i + 6], buf[i + 7], buf[i + 8],
  114. buf[i + 9], buf[i + 10], buf[i + 11],
  115. buf[i + 12], buf[i + 13], buf[i + 14],
  116. buf[i + 15]);
  117. /* write whatever's left over without overrunning the buffer */
  118. if (i < len) {
  119. char d_buf[80];
  120. int j = 0;
  121. memset(d_buf, 0, sizeof(d_buf));
  122. j += sprintf(d_buf, "\t0x%04X ", i);
  123. while (i < len)
  124. j += sprintf(&d_buf[j], " %02X", buf[i++]);
  125. i40e_debug(hw, mask, "%s\n", d_buf);
  126. }
  127. }
  128. }
  129. /**
  130. * i40evf_check_asq_alive
  131. * @hw: pointer to the hw struct
  132. *
  133. * Returns true if Queue is enabled else false.
  134. **/
  135. bool i40evf_check_asq_alive(struct i40e_hw *hw)
  136. {
  137. if (hw->aq.asq.len)
  138. return !!(rd32(hw, hw->aq.asq.len) &
  139. I40E_PF_ATQLEN_ATQENABLE_MASK);
  140. else
  141. return false;
  142. }
  143. /**
  144. * i40evf_aq_queue_shutdown
  145. * @hw: pointer to the hw struct
  146. * @unloading: is the driver unloading itself
  147. *
  148. * Tell the Firmware that we're shutting down the AdminQ and whether
  149. * or not the driver is unloading as well.
  150. **/
  151. i40e_status i40evf_aq_queue_shutdown(struct i40e_hw *hw,
  152. bool unloading)
  153. {
  154. struct i40e_aq_desc desc;
  155. struct i40e_aqc_queue_shutdown *cmd =
  156. (struct i40e_aqc_queue_shutdown *)&desc.params.raw;
  157. i40e_status status;
  158. i40evf_fill_default_direct_cmd_desc(&desc,
  159. i40e_aqc_opc_queue_shutdown);
  160. if (unloading)
  161. cmd->driver_unloading = cpu_to_le32(I40E_AQ_DRIVER_UNLOADING);
  162. status = i40evf_asq_send_command(hw, &desc, NULL, 0, NULL);
  163. return status;
  164. }
  165. /* The i40evf_ptype_lookup table is used to convert from the 8-bit ptype in the
  166. * hardware to a bit-field that can be used by SW to more easily determine the
  167. * packet type.
  168. *
  169. * Macros are used to shorten the table lines and make this table human
  170. * readable.
  171. *
  172. * We store the PTYPE in the top byte of the bit field - this is just so that
  173. * we can check that the table doesn't have a row missing, as the index into
  174. * the table should be the PTYPE.
  175. *
  176. * Typical work flow:
  177. *
  178. * IF NOT i40evf_ptype_lookup[ptype].known
  179. * THEN
  180. * Packet is unknown
  181. * ELSE IF i40evf_ptype_lookup[ptype].outer_ip == I40E_RX_PTYPE_OUTER_IP
  182. * Use the rest of the fields to look at the tunnels, inner protocols, etc
  183. * ELSE
  184. * Use the enum i40e_rx_l2_ptype to decode the packet type
  185. * ENDIF
  186. */
  187. /* macro to make the table lines short */
  188. #define I40E_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
  189. { PTYPE, \
  190. 1, \
  191. I40E_RX_PTYPE_OUTER_##OUTER_IP, \
  192. I40E_RX_PTYPE_OUTER_##OUTER_IP_VER, \
  193. I40E_RX_PTYPE_##OUTER_FRAG, \
  194. I40E_RX_PTYPE_TUNNEL_##T, \
  195. I40E_RX_PTYPE_TUNNEL_END_##TE, \
  196. I40E_RX_PTYPE_##TEF, \
  197. I40E_RX_PTYPE_INNER_PROT_##I, \
  198. I40E_RX_PTYPE_PAYLOAD_LAYER_##PL }
  199. #define I40E_PTT_UNUSED_ENTRY(PTYPE) \
  200. { PTYPE, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  201. /* shorter macros makes the table fit but are terse */
  202. #define I40E_RX_PTYPE_NOF I40E_RX_PTYPE_NOT_FRAG
  203. #define I40E_RX_PTYPE_FRG I40E_RX_PTYPE_FRAG
  204. #define I40E_RX_PTYPE_INNER_PROT_TS I40E_RX_PTYPE_INNER_PROT_TIMESYNC
  205. /* Lookup table mapping the HW PTYPE to the bit field for decoding */
  206. struct i40e_rx_ptype_decoded i40evf_ptype_lookup[] = {
  207. /* L2 Packet types */
  208. I40E_PTT_UNUSED_ENTRY(0),
  209. I40E_PTT(1, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  210. I40E_PTT(2, L2, NONE, NOF, NONE, NONE, NOF, TS, PAY2),
  211. I40E_PTT(3, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  212. I40E_PTT_UNUSED_ENTRY(4),
  213. I40E_PTT_UNUSED_ENTRY(5),
  214. I40E_PTT(6, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  215. I40E_PTT(7, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  216. I40E_PTT_UNUSED_ENTRY(8),
  217. I40E_PTT_UNUSED_ENTRY(9),
  218. I40E_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
  219. I40E_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
  220. I40E_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  221. I40E_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  222. I40E_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  223. I40E_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  224. I40E_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  225. I40E_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  226. I40E_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  227. I40E_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  228. I40E_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  229. I40E_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
  230. /* Non Tunneled IPv4 */
  231. I40E_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
  232. I40E_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
  233. I40E_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP, PAY4),
  234. I40E_PTT_UNUSED_ENTRY(25),
  235. I40E_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP, PAY4),
  236. I40E_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
  237. I40E_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
  238. /* IPv4 --> IPv4 */
  239. I40E_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
  240. I40E_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
  241. I40E_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
  242. I40E_PTT_UNUSED_ENTRY(32),
  243. I40E_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
  244. I40E_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
  245. I40E_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
  246. /* IPv4 --> IPv6 */
  247. I40E_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
  248. I40E_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
  249. I40E_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
  250. I40E_PTT_UNUSED_ENTRY(39),
  251. I40E_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
  252. I40E_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
  253. I40E_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
  254. /* IPv4 --> GRE/NAT */
  255. I40E_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
  256. /* IPv4 --> GRE/NAT --> IPv4 */
  257. I40E_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
  258. I40E_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
  259. I40E_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
  260. I40E_PTT_UNUSED_ENTRY(47),
  261. I40E_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
  262. I40E_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
  263. I40E_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
  264. /* IPv4 --> GRE/NAT --> IPv6 */
  265. I40E_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
  266. I40E_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
  267. I40E_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
  268. I40E_PTT_UNUSED_ENTRY(54),
  269. I40E_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
  270. I40E_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
  271. I40E_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
  272. /* IPv4 --> GRE/NAT --> MAC */
  273. I40E_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
  274. /* IPv4 --> GRE/NAT --> MAC --> IPv4 */
  275. I40E_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
  276. I40E_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
  277. I40E_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
  278. I40E_PTT_UNUSED_ENTRY(62),
  279. I40E_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
  280. I40E_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
  281. I40E_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
  282. /* IPv4 --> GRE/NAT -> MAC --> IPv6 */
  283. I40E_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
  284. I40E_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
  285. I40E_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
  286. I40E_PTT_UNUSED_ENTRY(69),
  287. I40E_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
  288. I40E_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
  289. I40E_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
  290. /* IPv4 --> GRE/NAT --> MAC/VLAN */
  291. I40E_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
  292. /* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
  293. I40E_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
  294. I40E_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
  295. I40E_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
  296. I40E_PTT_UNUSED_ENTRY(77),
  297. I40E_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
  298. I40E_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
  299. I40E_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
  300. /* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
  301. I40E_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
  302. I40E_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
  303. I40E_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
  304. I40E_PTT_UNUSED_ENTRY(84),
  305. I40E_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
  306. I40E_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
  307. I40E_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
  308. /* Non Tunneled IPv6 */
  309. I40E_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
  310. I40E_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
  311. I40E_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP, PAY3),
  312. I40E_PTT_UNUSED_ENTRY(91),
  313. I40E_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP, PAY4),
  314. I40E_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
  315. I40E_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
  316. /* IPv6 --> IPv4 */
  317. I40E_PTT(95, IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
  318. I40E_PTT(96, IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
  319. I40E_PTT(97, IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
  320. I40E_PTT_UNUSED_ENTRY(98),
  321. I40E_PTT(99, IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
  322. I40E_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
  323. I40E_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
  324. /* IPv6 --> IPv6 */
  325. I40E_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
  326. I40E_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
  327. I40E_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
  328. I40E_PTT_UNUSED_ENTRY(105),
  329. I40E_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
  330. I40E_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
  331. I40E_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
  332. /* IPv6 --> GRE/NAT */
  333. I40E_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
  334. /* IPv6 --> GRE/NAT -> IPv4 */
  335. I40E_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
  336. I40E_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
  337. I40E_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
  338. I40E_PTT_UNUSED_ENTRY(113),
  339. I40E_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
  340. I40E_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
  341. I40E_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
  342. /* IPv6 --> GRE/NAT -> IPv6 */
  343. I40E_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
  344. I40E_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
  345. I40E_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
  346. I40E_PTT_UNUSED_ENTRY(120),
  347. I40E_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
  348. I40E_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
  349. I40E_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
  350. /* IPv6 --> GRE/NAT -> MAC */
  351. I40E_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
  352. /* IPv6 --> GRE/NAT -> MAC -> IPv4 */
  353. I40E_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
  354. I40E_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
  355. I40E_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
  356. I40E_PTT_UNUSED_ENTRY(128),
  357. I40E_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
  358. I40E_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
  359. I40E_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
  360. /* IPv6 --> GRE/NAT -> MAC -> IPv6 */
  361. I40E_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
  362. I40E_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
  363. I40E_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
  364. I40E_PTT_UNUSED_ENTRY(135),
  365. I40E_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
  366. I40E_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
  367. I40E_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
  368. /* IPv6 --> GRE/NAT -> MAC/VLAN */
  369. I40E_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
  370. /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
  371. I40E_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
  372. I40E_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
  373. I40E_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
  374. I40E_PTT_UNUSED_ENTRY(143),
  375. I40E_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
  376. I40E_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
  377. I40E_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
  378. /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
  379. I40E_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
  380. I40E_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
  381. I40E_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
  382. I40E_PTT_UNUSED_ENTRY(150),
  383. I40E_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
  384. I40E_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
  385. I40E_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
  386. /* unused entries */
  387. I40E_PTT_UNUSED_ENTRY(154),
  388. I40E_PTT_UNUSED_ENTRY(155),
  389. I40E_PTT_UNUSED_ENTRY(156),
  390. I40E_PTT_UNUSED_ENTRY(157),
  391. I40E_PTT_UNUSED_ENTRY(158),
  392. I40E_PTT_UNUSED_ENTRY(159),
  393. I40E_PTT_UNUSED_ENTRY(160),
  394. I40E_PTT_UNUSED_ENTRY(161),
  395. I40E_PTT_UNUSED_ENTRY(162),
  396. I40E_PTT_UNUSED_ENTRY(163),
  397. I40E_PTT_UNUSED_ENTRY(164),
  398. I40E_PTT_UNUSED_ENTRY(165),
  399. I40E_PTT_UNUSED_ENTRY(166),
  400. I40E_PTT_UNUSED_ENTRY(167),
  401. I40E_PTT_UNUSED_ENTRY(168),
  402. I40E_PTT_UNUSED_ENTRY(169),
  403. I40E_PTT_UNUSED_ENTRY(170),
  404. I40E_PTT_UNUSED_ENTRY(171),
  405. I40E_PTT_UNUSED_ENTRY(172),
  406. I40E_PTT_UNUSED_ENTRY(173),
  407. I40E_PTT_UNUSED_ENTRY(174),
  408. I40E_PTT_UNUSED_ENTRY(175),
  409. I40E_PTT_UNUSED_ENTRY(176),
  410. I40E_PTT_UNUSED_ENTRY(177),
  411. I40E_PTT_UNUSED_ENTRY(178),
  412. I40E_PTT_UNUSED_ENTRY(179),
  413. I40E_PTT_UNUSED_ENTRY(180),
  414. I40E_PTT_UNUSED_ENTRY(181),
  415. I40E_PTT_UNUSED_ENTRY(182),
  416. I40E_PTT_UNUSED_ENTRY(183),
  417. I40E_PTT_UNUSED_ENTRY(184),
  418. I40E_PTT_UNUSED_ENTRY(185),
  419. I40E_PTT_UNUSED_ENTRY(186),
  420. I40E_PTT_UNUSED_ENTRY(187),
  421. I40E_PTT_UNUSED_ENTRY(188),
  422. I40E_PTT_UNUSED_ENTRY(189),
  423. I40E_PTT_UNUSED_ENTRY(190),
  424. I40E_PTT_UNUSED_ENTRY(191),
  425. I40E_PTT_UNUSED_ENTRY(192),
  426. I40E_PTT_UNUSED_ENTRY(193),
  427. I40E_PTT_UNUSED_ENTRY(194),
  428. I40E_PTT_UNUSED_ENTRY(195),
  429. I40E_PTT_UNUSED_ENTRY(196),
  430. I40E_PTT_UNUSED_ENTRY(197),
  431. I40E_PTT_UNUSED_ENTRY(198),
  432. I40E_PTT_UNUSED_ENTRY(199),
  433. I40E_PTT_UNUSED_ENTRY(200),
  434. I40E_PTT_UNUSED_ENTRY(201),
  435. I40E_PTT_UNUSED_ENTRY(202),
  436. I40E_PTT_UNUSED_ENTRY(203),
  437. I40E_PTT_UNUSED_ENTRY(204),
  438. I40E_PTT_UNUSED_ENTRY(205),
  439. I40E_PTT_UNUSED_ENTRY(206),
  440. I40E_PTT_UNUSED_ENTRY(207),
  441. I40E_PTT_UNUSED_ENTRY(208),
  442. I40E_PTT_UNUSED_ENTRY(209),
  443. I40E_PTT_UNUSED_ENTRY(210),
  444. I40E_PTT_UNUSED_ENTRY(211),
  445. I40E_PTT_UNUSED_ENTRY(212),
  446. I40E_PTT_UNUSED_ENTRY(213),
  447. I40E_PTT_UNUSED_ENTRY(214),
  448. I40E_PTT_UNUSED_ENTRY(215),
  449. I40E_PTT_UNUSED_ENTRY(216),
  450. I40E_PTT_UNUSED_ENTRY(217),
  451. I40E_PTT_UNUSED_ENTRY(218),
  452. I40E_PTT_UNUSED_ENTRY(219),
  453. I40E_PTT_UNUSED_ENTRY(220),
  454. I40E_PTT_UNUSED_ENTRY(221),
  455. I40E_PTT_UNUSED_ENTRY(222),
  456. I40E_PTT_UNUSED_ENTRY(223),
  457. I40E_PTT_UNUSED_ENTRY(224),
  458. I40E_PTT_UNUSED_ENTRY(225),
  459. I40E_PTT_UNUSED_ENTRY(226),
  460. I40E_PTT_UNUSED_ENTRY(227),
  461. I40E_PTT_UNUSED_ENTRY(228),
  462. I40E_PTT_UNUSED_ENTRY(229),
  463. I40E_PTT_UNUSED_ENTRY(230),
  464. I40E_PTT_UNUSED_ENTRY(231),
  465. I40E_PTT_UNUSED_ENTRY(232),
  466. I40E_PTT_UNUSED_ENTRY(233),
  467. I40E_PTT_UNUSED_ENTRY(234),
  468. I40E_PTT_UNUSED_ENTRY(235),
  469. I40E_PTT_UNUSED_ENTRY(236),
  470. I40E_PTT_UNUSED_ENTRY(237),
  471. I40E_PTT_UNUSED_ENTRY(238),
  472. I40E_PTT_UNUSED_ENTRY(239),
  473. I40E_PTT_UNUSED_ENTRY(240),
  474. I40E_PTT_UNUSED_ENTRY(241),
  475. I40E_PTT_UNUSED_ENTRY(242),
  476. I40E_PTT_UNUSED_ENTRY(243),
  477. I40E_PTT_UNUSED_ENTRY(244),
  478. I40E_PTT_UNUSED_ENTRY(245),
  479. I40E_PTT_UNUSED_ENTRY(246),
  480. I40E_PTT_UNUSED_ENTRY(247),
  481. I40E_PTT_UNUSED_ENTRY(248),
  482. I40E_PTT_UNUSED_ENTRY(249),
  483. I40E_PTT_UNUSED_ENTRY(250),
  484. I40E_PTT_UNUSED_ENTRY(251),
  485. I40E_PTT_UNUSED_ENTRY(252),
  486. I40E_PTT_UNUSED_ENTRY(253),
  487. I40E_PTT_UNUSED_ENTRY(254),
  488. I40E_PTT_UNUSED_ENTRY(255)
  489. };
  490. /**
  491. * i40e_aq_send_msg_to_pf
  492. * @hw: pointer to the hardware structure
  493. * @v_opcode: opcodes for VF-PF communication
  494. * @v_retval: return error code
  495. * @msg: pointer to the msg buffer
  496. * @msglen: msg length
  497. * @cmd_details: pointer to command details
  498. *
  499. * Send message to PF driver using admin queue. By default, this message
  500. * is sent asynchronously, i.e. i40evf_asq_send_command() does not wait for
  501. * completion before returning.
  502. **/
  503. i40e_status i40e_aq_send_msg_to_pf(struct i40e_hw *hw,
  504. enum i40e_virtchnl_ops v_opcode,
  505. i40e_status v_retval,
  506. u8 *msg, u16 msglen,
  507. struct i40e_asq_cmd_details *cmd_details)
  508. {
  509. struct i40e_aq_desc desc;
  510. struct i40e_asq_cmd_details details;
  511. i40e_status status;
  512. i40evf_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_pf);
  513. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_SI);
  514. desc.cookie_high = cpu_to_le32(v_opcode);
  515. desc.cookie_low = cpu_to_le32(v_retval);
  516. if (msglen) {
  517. desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF
  518. | I40E_AQ_FLAG_RD));
  519. if (msglen > I40E_AQ_LARGE_BUF)
  520. desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
  521. desc.datalen = cpu_to_le16(msglen);
  522. }
  523. if (!cmd_details) {
  524. memset(&details, 0, sizeof(details));
  525. details.async = true;
  526. cmd_details = &details;
  527. }
  528. status = i40evf_asq_send_command(hw, &desc, msg, msglen, cmd_details);
  529. return status;
  530. }
  531. /**
  532. * i40e_vf_parse_hw_config
  533. * @hw: pointer to the hardware structure
  534. * @msg: pointer to the virtual channel VF resource structure
  535. *
  536. * Given a VF resource message from the PF, populate the hw struct
  537. * with appropriate information.
  538. **/
  539. void i40e_vf_parse_hw_config(struct i40e_hw *hw,
  540. struct i40e_virtchnl_vf_resource *msg)
  541. {
  542. struct i40e_virtchnl_vsi_resource *vsi_res;
  543. int i;
  544. vsi_res = &msg->vsi_res[0];
  545. hw->dev_caps.num_vsis = msg->num_vsis;
  546. hw->dev_caps.num_rx_qp = msg->num_queue_pairs;
  547. hw->dev_caps.num_tx_qp = msg->num_queue_pairs;
  548. hw->dev_caps.num_msix_vectors_vf = msg->max_vectors;
  549. hw->dev_caps.dcb = msg->vf_offload_flags &
  550. I40E_VIRTCHNL_VF_OFFLOAD_L2;
  551. hw->dev_caps.fcoe = (msg->vf_offload_flags &
  552. I40E_VIRTCHNL_VF_OFFLOAD_FCOE) ? 1 : 0;
  553. for (i = 0; i < msg->num_vsis; i++) {
  554. if (vsi_res->vsi_type == I40E_VSI_SRIOV) {
  555. memcpy(hw->mac.perm_addr, vsi_res->default_mac_addr,
  556. ETH_ALEN);
  557. memcpy(hw->mac.addr, vsi_res->default_mac_addr,
  558. ETH_ALEN);
  559. }
  560. vsi_res++;
  561. }
  562. }
  563. /**
  564. * i40e_vf_reset
  565. * @hw: pointer to the hardware structure
  566. *
  567. * Send a VF_RESET message to the PF. Does not wait for response from PF
  568. * as none will be forthcoming. Immediately after calling this function,
  569. * the admin queue should be shut down and (optionally) reinitialized.
  570. **/
  571. i40e_status i40e_vf_reset(struct i40e_hw *hw)
  572. {
  573. return i40e_aq_send_msg_to_pf(hw, I40E_VIRTCHNL_OP_RESET_VF,
  574. 0, NULL, 0, NULL);
  575. }