18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/* Copyright (C) 2018-2020, Intel Corporation. */
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#include "ice_common.h"
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci/* These are training packet headers used to program flow director filters. */
78c2ecf20Sopenharmony_cistatic const u8 ice_fdir_tcpv4_pkt[] = {
88c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
98c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
108c2ecf20Sopenharmony_ci	0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x40, 0x06,
118c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
128c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
138c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x00,
148c2ecf20Sopenharmony_ci	0x20, 0x00, 0x00, 0x00, 0x00, 0x00
158c2ecf20Sopenharmony_ci};
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_cistatic const u8 ice_fdir_udpv4_pkt[] = {
188c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
198c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
208c2ecf20Sopenharmony_ci	0x00, 0x1C, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11,
218c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
228c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
238c2ecf20Sopenharmony_ci	0x00, 0x00,
248c2ecf20Sopenharmony_ci};
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cistatic const u8 ice_fdir_sctpv4_pkt[] = {
278c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
288c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
298c2ecf20Sopenharmony_ci	0x00, 0x20, 0x00, 0x00, 0x40, 0x00, 0x40, 0x84,
308c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
318c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
328c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
338c2ecf20Sopenharmony_ci};
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_cistatic const u8 ice_fdir_ipv4_pkt[] = {
368c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
378c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
388c2ecf20Sopenharmony_ci	0x00, 0x14, 0x00, 0x00, 0x40, 0x00, 0x40, 0x10,
398c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
408c2ecf20Sopenharmony_ci	0x00, 0x00
418c2ecf20Sopenharmony_ci};
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_cistatic const u8 ice_fdir_tcpv6_pkt[] = {
448c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
458c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x86, 0xDD, 0x60, 0x00,
468c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x14, 0x06, 0x40, 0x00, 0x00,
478c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
488c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
498c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
508c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
518c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
528c2ecf20Sopenharmony_ci	0x00, 0x00, 0x50, 0x00, 0x20, 0x00, 0x00, 0x00,
538c2ecf20Sopenharmony_ci	0x00, 0x00,
548c2ecf20Sopenharmony_ci};
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cistatic const u8 ice_fdir_udpv6_pkt[] = {
578c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
588c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x86, 0xDD, 0x60, 0x00,
598c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x08, 0x11, 0x40, 0x00, 0x00,
608c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
618c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
628c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
638c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
648c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x08, 0x00, 0x00,
658c2ecf20Sopenharmony_ci};
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_cistatic const u8 ice_fdir_sctpv6_pkt[] = {
688c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
698c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x86, 0xDD, 0x60, 0x00,
708c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x0C, 0x84, 0x40, 0x00, 0x00,
718c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
728c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
738c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
748c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
758c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
768c2ecf20Sopenharmony_ci	0x00, 0x00,
778c2ecf20Sopenharmony_ci};
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_cistatic const u8 ice_fdir_ipv6_pkt[] = {
808c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
818c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x86, 0xDD, 0x60, 0x00,
828c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x3B, 0x40, 0x00, 0x00,
838c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
848c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
858c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
868c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
878c2ecf20Sopenharmony_ci};
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_cistatic const u8 ice_fdir_tcp4_tun_pkt[] = {
908c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
918c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
928c2ecf20Sopenharmony_ci	0x00, 0x5a, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11,
938c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
948c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
958c2ecf20Sopenharmony_ci	0x00, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x00,
968c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
978c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00,
988c2ecf20Sopenharmony_ci	0x45, 0x00, 0x00, 0x28, 0x00, 0x00, 0x40, 0x00,
998c2ecf20Sopenharmony_ci	0x40, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1008c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1018c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1028c2ecf20Sopenharmony_ci	0x50, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
1038c2ecf20Sopenharmony_ci};
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_cistatic const u8 ice_fdir_udp4_tun_pkt[] = {
1068c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1078c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
1088c2ecf20Sopenharmony_ci	0x00, 0x4e, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11,
1098c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1108c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1118c2ecf20Sopenharmony_ci	0x00, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x00,
1128c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1138c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00,
1148c2ecf20Sopenharmony_ci	0x45, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x40, 0x00,
1158c2ecf20Sopenharmony_ci	0x40, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1168c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1178c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00,
1188c2ecf20Sopenharmony_ci};
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_cistatic const u8 ice_fdir_sctp4_tun_pkt[] = {
1218c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1228c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
1238c2ecf20Sopenharmony_ci	0x00, 0x52, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11,
1248c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1258c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1268c2ecf20Sopenharmony_ci	0x00, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x00,
1278c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1288c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00,
1298c2ecf20Sopenharmony_ci	0x45, 0x00, 0x00, 0x20, 0x00, 0x01, 0x00, 0x00,
1308c2ecf20Sopenharmony_ci	0x40, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1318c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1328c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1338c2ecf20Sopenharmony_ci};
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_cistatic const u8 ice_fdir_ip4_tun_pkt[] = {
1368c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1378c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
1388c2ecf20Sopenharmony_ci	0x00, 0x46, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11,
1398c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1408c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1418c2ecf20Sopenharmony_ci	0x00, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x00,
1428c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1438c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00,
1448c2ecf20Sopenharmony_ci	0x45, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00,
1458c2ecf20Sopenharmony_ci	0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1468c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00,
1478c2ecf20Sopenharmony_ci};
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_cistatic const u8 ice_fdir_tcp6_tun_pkt[] = {
1508c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1518c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
1528c2ecf20Sopenharmony_ci	0x00, 0x6e, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11,
1538c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1548c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1558c2ecf20Sopenharmony_ci	0x00, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x00,
1568c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1578c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0xdd,
1588c2ecf20Sopenharmony_ci	0x60, 0x00, 0x00, 0x00, 0x00, 0x14, 0x06, 0x40,
1598c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1608c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1618c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1628c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1638c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1648c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x50, 0x00, 0x20, 0x00,
1658c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00,
1668c2ecf20Sopenharmony_ci};
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_cistatic const u8 ice_fdir_udp6_tun_pkt[] = {
1698c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1708c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
1718c2ecf20Sopenharmony_ci	0x00, 0x62, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11,
1728c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1738c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1748c2ecf20Sopenharmony_ci	0x00, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x00,
1758c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1768c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0xdd,
1778c2ecf20Sopenharmony_ci	0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x11, 0x40,
1788c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1798c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1808c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1818c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1828c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1838c2ecf20Sopenharmony_ci};
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_cistatic const u8 ice_fdir_sctp6_tun_pkt[] = {
1868c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1878c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
1888c2ecf20Sopenharmony_ci	0x00, 0x66, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11,
1898c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1908c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1918c2ecf20Sopenharmony_ci	0x00, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x00,
1928c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1938c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0xdd,
1948c2ecf20Sopenharmony_ci	0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x84, 0x40,
1958c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1968c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1978c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1988c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1998c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2008c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00,
2018c2ecf20Sopenharmony_ci};
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_cistatic const u8 ice_fdir_ip6_tun_pkt[] = {
2048c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2058c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
2068c2ecf20Sopenharmony_ci	0x00, 0x5a, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11,
2078c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2088c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2098c2ecf20Sopenharmony_ci	0x00, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x00,
2108c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2118c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0xdd,
2128c2ecf20Sopenharmony_ci	0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3b, 0x40,
2138c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2148c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2158c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2168c2ecf20Sopenharmony_ci	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2178c2ecf20Sopenharmony_ci};
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci/* Flow Director no-op training packet table */
2208c2ecf20Sopenharmony_cistatic const struct ice_fdir_base_pkt ice_fdir_pkt[] = {
2218c2ecf20Sopenharmony_ci	{
2228c2ecf20Sopenharmony_ci		ICE_FLTR_PTYPE_NONF_IPV4_TCP,
2238c2ecf20Sopenharmony_ci		sizeof(ice_fdir_tcpv4_pkt), ice_fdir_tcpv4_pkt,
2248c2ecf20Sopenharmony_ci		sizeof(ice_fdir_tcp4_tun_pkt), ice_fdir_tcp4_tun_pkt,
2258c2ecf20Sopenharmony_ci	},
2268c2ecf20Sopenharmony_ci	{
2278c2ecf20Sopenharmony_ci		ICE_FLTR_PTYPE_NONF_IPV4_UDP,
2288c2ecf20Sopenharmony_ci		sizeof(ice_fdir_udpv4_pkt), ice_fdir_udpv4_pkt,
2298c2ecf20Sopenharmony_ci		sizeof(ice_fdir_udp4_tun_pkt), ice_fdir_udp4_tun_pkt,
2308c2ecf20Sopenharmony_ci	},
2318c2ecf20Sopenharmony_ci	{
2328c2ecf20Sopenharmony_ci		ICE_FLTR_PTYPE_NONF_IPV4_SCTP,
2338c2ecf20Sopenharmony_ci		sizeof(ice_fdir_sctpv4_pkt), ice_fdir_sctpv4_pkt,
2348c2ecf20Sopenharmony_ci		sizeof(ice_fdir_sctp4_tun_pkt), ice_fdir_sctp4_tun_pkt,
2358c2ecf20Sopenharmony_ci	},
2368c2ecf20Sopenharmony_ci	{
2378c2ecf20Sopenharmony_ci		ICE_FLTR_PTYPE_NONF_IPV4_OTHER,
2388c2ecf20Sopenharmony_ci		sizeof(ice_fdir_ipv4_pkt), ice_fdir_ipv4_pkt,
2398c2ecf20Sopenharmony_ci		sizeof(ice_fdir_ip4_tun_pkt), ice_fdir_ip4_tun_pkt,
2408c2ecf20Sopenharmony_ci	},
2418c2ecf20Sopenharmony_ci	{
2428c2ecf20Sopenharmony_ci		ICE_FLTR_PTYPE_NONF_IPV6_TCP,
2438c2ecf20Sopenharmony_ci		sizeof(ice_fdir_tcpv6_pkt), ice_fdir_tcpv6_pkt,
2448c2ecf20Sopenharmony_ci		sizeof(ice_fdir_tcp6_tun_pkt), ice_fdir_tcp6_tun_pkt,
2458c2ecf20Sopenharmony_ci	},
2468c2ecf20Sopenharmony_ci	{
2478c2ecf20Sopenharmony_ci		ICE_FLTR_PTYPE_NONF_IPV6_UDP,
2488c2ecf20Sopenharmony_ci		sizeof(ice_fdir_udpv6_pkt), ice_fdir_udpv6_pkt,
2498c2ecf20Sopenharmony_ci		sizeof(ice_fdir_udp6_tun_pkt), ice_fdir_udp6_tun_pkt,
2508c2ecf20Sopenharmony_ci	},
2518c2ecf20Sopenharmony_ci	{
2528c2ecf20Sopenharmony_ci		ICE_FLTR_PTYPE_NONF_IPV6_SCTP,
2538c2ecf20Sopenharmony_ci		sizeof(ice_fdir_sctpv6_pkt), ice_fdir_sctpv6_pkt,
2548c2ecf20Sopenharmony_ci		sizeof(ice_fdir_sctp6_tun_pkt), ice_fdir_sctp6_tun_pkt,
2558c2ecf20Sopenharmony_ci	},
2568c2ecf20Sopenharmony_ci	{
2578c2ecf20Sopenharmony_ci		ICE_FLTR_PTYPE_NONF_IPV6_OTHER,
2588c2ecf20Sopenharmony_ci		sizeof(ice_fdir_ipv6_pkt), ice_fdir_ipv6_pkt,
2598c2ecf20Sopenharmony_ci		sizeof(ice_fdir_ip6_tun_pkt), ice_fdir_ip6_tun_pkt,
2608c2ecf20Sopenharmony_ci	},
2618c2ecf20Sopenharmony_ci};
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_ci#define ICE_FDIR_NUM_PKT ARRAY_SIZE(ice_fdir_pkt)
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci/**
2668c2ecf20Sopenharmony_ci * ice_set_dflt_val_fd_desc
2678c2ecf20Sopenharmony_ci * @fd_fltr_ctx: pointer to fd filter descriptor
2688c2ecf20Sopenharmony_ci */
2698c2ecf20Sopenharmony_cistatic void ice_set_dflt_val_fd_desc(struct ice_fd_fltr_desc_ctx *fd_fltr_ctx)
2708c2ecf20Sopenharmony_ci{
2718c2ecf20Sopenharmony_ci	fd_fltr_ctx->comp_q = ICE_FXD_FLTR_QW0_COMP_Q_ZERO;
2728c2ecf20Sopenharmony_ci	fd_fltr_ctx->comp_report = ICE_FXD_FLTR_QW0_COMP_REPORT_SW_FAIL;
2738c2ecf20Sopenharmony_ci	fd_fltr_ctx->fd_space = ICE_FXD_FLTR_QW0_FD_SPACE_GUAR_BEST;
2748c2ecf20Sopenharmony_ci	fd_fltr_ctx->cnt_ena = ICE_FXD_FLTR_QW0_STAT_ENA_PKTS;
2758c2ecf20Sopenharmony_ci	fd_fltr_ctx->evict_ena = ICE_FXD_FLTR_QW0_EVICT_ENA_TRUE;
2768c2ecf20Sopenharmony_ci	fd_fltr_ctx->toq = ICE_FXD_FLTR_QW0_TO_Q_EQUALS_QINDEX;
2778c2ecf20Sopenharmony_ci	fd_fltr_ctx->toq_prio = ICE_FXD_FLTR_QW0_TO_Q_PRIO1;
2788c2ecf20Sopenharmony_ci	fd_fltr_ctx->dpu_recipe = ICE_FXD_FLTR_QW0_DPU_RECIPE_DFLT;
2798c2ecf20Sopenharmony_ci	fd_fltr_ctx->drop = ICE_FXD_FLTR_QW0_DROP_NO;
2808c2ecf20Sopenharmony_ci	fd_fltr_ctx->flex_prio = ICE_FXD_FLTR_QW0_FLEX_PRI_NONE;
2818c2ecf20Sopenharmony_ci	fd_fltr_ctx->flex_mdid = ICE_FXD_FLTR_QW0_FLEX_MDID0;
2828c2ecf20Sopenharmony_ci	fd_fltr_ctx->flex_val = ICE_FXD_FLTR_QW0_FLEX_VAL0;
2838c2ecf20Sopenharmony_ci	fd_fltr_ctx->dtype = ICE_TX_DESC_DTYPE_FLTR_PROG;
2848c2ecf20Sopenharmony_ci	fd_fltr_ctx->desc_prof_prio = ICE_FXD_FLTR_QW1_PROF_PRIO_ZERO;
2858c2ecf20Sopenharmony_ci	fd_fltr_ctx->desc_prof = ICE_FXD_FLTR_QW1_PROF_ZERO;
2868c2ecf20Sopenharmony_ci	fd_fltr_ctx->swap = ICE_FXD_FLTR_QW1_SWAP_SET;
2878c2ecf20Sopenharmony_ci	fd_fltr_ctx->fdid_prio = ICE_FXD_FLTR_QW1_FDID_PRI_ONE;
2888c2ecf20Sopenharmony_ci	fd_fltr_ctx->fdid_mdid = ICE_FXD_FLTR_QW1_FDID_MDID_FD;
2898c2ecf20Sopenharmony_ci	fd_fltr_ctx->fdid = ICE_FXD_FLTR_QW1_FDID_ZERO;
2908c2ecf20Sopenharmony_ci}
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci/**
2938c2ecf20Sopenharmony_ci * ice_set_fd_desc_val
2948c2ecf20Sopenharmony_ci * @ctx: pointer to fd filter descriptor context
2958c2ecf20Sopenharmony_ci * @fdir_desc: populated with fd filter descriptor values
2968c2ecf20Sopenharmony_ci */
2978c2ecf20Sopenharmony_cistatic void
2988c2ecf20Sopenharmony_ciice_set_fd_desc_val(struct ice_fd_fltr_desc_ctx *ctx,
2998c2ecf20Sopenharmony_ci		    struct ice_fltr_desc *fdir_desc)
3008c2ecf20Sopenharmony_ci{
3018c2ecf20Sopenharmony_ci	u64 qword;
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_ci	/* prep QW0 of FD filter programming desc */
3048c2ecf20Sopenharmony_ci	qword = ((u64)ctx->qindex << ICE_FXD_FLTR_QW0_QINDEX_S) &
3058c2ecf20Sopenharmony_ci		ICE_FXD_FLTR_QW0_QINDEX_M;
3068c2ecf20Sopenharmony_ci	qword |= ((u64)ctx->comp_q << ICE_FXD_FLTR_QW0_COMP_Q_S) &
3078c2ecf20Sopenharmony_ci		 ICE_FXD_FLTR_QW0_COMP_Q_M;
3088c2ecf20Sopenharmony_ci	qword |= ((u64)ctx->comp_report << ICE_FXD_FLTR_QW0_COMP_REPORT_S) &
3098c2ecf20Sopenharmony_ci		 ICE_FXD_FLTR_QW0_COMP_REPORT_M;
3108c2ecf20Sopenharmony_ci	qword |= ((u64)ctx->fd_space << ICE_FXD_FLTR_QW0_FD_SPACE_S) &
3118c2ecf20Sopenharmony_ci		 ICE_FXD_FLTR_QW0_FD_SPACE_M;
3128c2ecf20Sopenharmony_ci	qword |= ((u64)ctx->cnt_index << ICE_FXD_FLTR_QW0_STAT_CNT_S) &
3138c2ecf20Sopenharmony_ci		 ICE_FXD_FLTR_QW0_STAT_CNT_M;
3148c2ecf20Sopenharmony_ci	qword |= ((u64)ctx->cnt_ena << ICE_FXD_FLTR_QW0_STAT_ENA_S) &
3158c2ecf20Sopenharmony_ci		 ICE_FXD_FLTR_QW0_STAT_ENA_M;
3168c2ecf20Sopenharmony_ci	qword |= ((u64)ctx->evict_ena << ICE_FXD_FLTR_QW0_EVICT_ENA_S) &
3178c2ecf20Sopenharmony_ci		 ICE_FXD_FLTR_QW0_EVICT_ENA_M;
3188c2ecf20Sopenharmony_ci	qword |= ((u64)ctx->toq << ICE_FXD_FLTR_QW0_TO_Q_S) &
3198c2ecf20Sopenharmony_ci		 ICE_FXD_FLTR_QW0_TO_Q_M;
3208c2ecf20Sopenharmony_ci	qword |= ((u64)ctx->toq_prio << ICE_FXD_FLTR_QW0_TO_Q_PRI_S) &
3218c2ecf20Sopenharmony_ci		 ICE_FXD_FLTR_QW0_TO_Q_PRI_M;
3228c2ecf20Sopenharmony_ci	qword |= ((u64)ctx->dpu_recipe << ICE_FXD_FLTR_QW0_DPU_RECIPE_S) &
3238c2ecf20Sopenharmony_ci		 ICE_FXD_FLTR_QW0_DPU_RECIPE_M;
3248c2ecf20Sopenharmony_ci	qword |= ((u64)ctx->drop << ICE_FXD_FLTR_QW0_DROP_S) &
3258c2ecf20Sopenharmony_ci		 ICE_FXD_FLTR_QW0_DROP_M;
3268c2ecf20Sopenharmony_ci	qword |= ((u64)ctx->flex_prio << ICE_FXD_FLTR_QW0_FLEX_PRI_S) &
3278c2ecf20Sopenharmony_ci		 ICE_FXD_FLTR_QW0_FLEX_PRI_M;
3288c2ecf20Sopenharmony_ci	qword |= ((u64)ctx->flex_mdid << ICE_FXD_FLTR_QW0_FLEX_MDID_S) &
3298c2ecf20Sopenharmony_ci		 ICE_FXD_FLTR_QW0_FLEX_MDID_M;
3308c2ecf20Sopenharmony_ci	qword |= ((u64)ctx->flex_val << ICE_FXD_FLTR_QW0_FLEX_VAL_S) &
3318c2ecf20Sopenharmony_ci		 ICE_FXD_FLTR_QW0_FLEX_VAL_M;
3328c2ecf20Sopenharmony_ci	fdir_desc->qidx_compq_space_stat = cpu_to_le64(qword);
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_ci	/* prep QW1 of FD filter programming desc */
3358c2ecf20Sopenharmony_ci	qword = ((u64)ctx->dtype << ICE_FXD_FLTR_QW1_DTYPE_S) &
3368c2ecf20Sopenharmony_ci		ICE_FXD_FLTR_QW1_DTYPE_M;
3378c2ecf20Sopenharmony_ci	qword |= ((u64)ctx->pcmd << ICE_FXD_FLTR_QW1_PCMD_S) &
3388c2ecf20Sopenharmony_ci		 ICE_FXD_FLTR_QW1_PCMD_M;
3398c2ecf20Sopenharmony_ci	qword |= ((u64)ctx->desc_prof_prio << ICE_FXD_FLTR_QW1_PROF_PRI_S) &
3408c2ecf20Sopenharmony_ci		 ICE_FXD_FLTR_QW1_PROF_PRI_M;
3418c2ecf20Sopenharmony_ci	qword |= ((u64)ctx->desc_prof << ICE_FXD_FLTR_QW1_PROF_S) &
3428c2ecf20Sopenharmony_ci		 ICE_FXD_FLTR_QW1_PROF_M;
3438c2ecf20Sopenharmony_ci	qword |= ((u64)ctx->fd_vsi << ICE_FXD_FLTR_QW1_FD_VSI_S) &
3448c2ecf20Sopenharmony_ci		 ICE_FXD_FLTR_QW1_FD_VSI_M;
3458c2ecf20Sopenharmony_ci	qword |= ((u64)ctx->swap << ICE_FXD_FLTR_QW1_SWAP_S) &
3468c2ecf20Sopenharmony_ci		 ICE_FXD_FLTR_QW1_SWAP_M;
3478c2ecf20Sopenharmony_ci	qword |= ((u64)ctx->fdid_prio << ICE_FXD_FLTR_QW1_FDID_PRI_S) &
3488c2ecf20Sopenharmony_ci		 ICE_FXD_FLTR_QW1_FDID_PRI_M;
3498c2ecf20Sopenharmony_ci	qword |= ((u64)ctx->fdid_mdid << ICE_FXD_FLTR_QW1_FDID_MDID_S) &
3508c2ecf20Sopenharmony_ci		 ICE_FXD_FLTR_QW1_FDID_MDID_M;
3518c2ecf20Sopenharmony_ci	qword |= ((u64)ctx->fdid << ICE_FXD_FLTR_QW1_FDID_S) &
3528c2ecf20Sopenharmony_ci		 ICE_FXD_FLTR_QW1_FDID_M;
3538c2ecf20Sopenharmony_ci	fdir_desc->dtype_cmd_vsi_fdid = cpu_to_le64(qword);
3548c2ecf20Sopenharmony_ci}
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_ci/**
3578c2ecf20Sopenharmony_ci * ice_fdir_get_prgm_desc - set a fdir descriptor from a fdir filter struct
3588c2ecf20Sopenharmony_ci * @hw: pointer to the hardware structure
3598c2ecf20Sopenharmony_ci * @input: filter
3608c2ecf20Sopenharmony_ci * @fdesc: filter descriptor
3618c2ecf20Sopenharmony_ci * @add: if add is true, this is an add operation, false implies delete
3628c2ecf20Sopenharmony_ci */
3638c2ecf20Sopenharmony_civoid
3648c2ecf20Sopenharmony_ciice_fdir_get_prgm_desc(struct ice_hw *hw, struct ice_fdir_fltr *input,
3658c2ecf20Sopenharmony_ci		       struct ice_fltr_desc *fdesc, bool add)
3668c2ecf20Sopenharmony_ci{
3678c2ecf20Sopenharmony_ci	struct ice_fd_fltr_desc_ctx fdir_fltr_ctx = { 0 };
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_ci	/* set default context info */
3708c2ecf20Sopenharmony_ci	ice_set_dflt_val_fd_desc(&fdir_fltr_ctx);
3718c2ecf20Sopenharmony_ci
3728c2ecf20Sopenharmony_ci	/* change sideband filtering values */
3738c2ecf20Sopenharmony_ci	fdir_fltr_ctx.fdid = input->fltr_id;
3748c2ecf20Sopenharmony_ci	if (input->dest_ctl == ICE_FLTR_PRGM_DESC_DEST_DROP_PKT) {
3758c2ecf20Sopenharmony_ci		fdir_fltr_ctx.drop = ICE_FXD_FLTR_QW0_DROP_YES;
3768c2ecf20Sopenharmony_ci		fdir_fltr_ctx.qindex = 0;
3778c2ecf20Sopenharmony_ci	} else {
3788c2ecf20Sopenharmony_ci		fdir_fltr_ctx.drop = ICE_FXD_FLTR_QW0_DROP_NO;
3798c2ecf20Sopenharmony_ci		fdir_fltr_ctx.qindex = input->q_index;
3808c2ecf20Sopenharmony_ci	}
3818c2ecf20Sopenharmony_ci	fdir_fltr_ctx.cnt_ena = ICE_FXD_FLTR_QW0_STAT_ENA_PKTS;
3828c2ecf20Sopenharmony_ci	fdir_fltr_ctx.cnt_index = input->cnt_index;
3838c2ecf20Sopenharmony_ci	fdir_fltr_ctx.fd_vsi = ice_get_hw_vsi_num(hw, input->dest_vsi);
3848c2ecf20Sopenharmony_ci	fdir_fltr_ctx.evict_ena = ICE_FXD_FLTR_QW0_EVICT_ENA_FALSE;
3858c2ecf20Sopenharmony_ci	fdir_fltr_ctx.toq_prio = 3;
3868c2ecf20Sopenharmony_ci	fdir_fltr_ctx.pcmd = add ? ICE_FXD_FLTR_QW1_PCMD_ADD :
3878c2ecf20Sopenharmony_ci		ICE_FXD_FLTR_QW1_PCMD_REMOVE;
3888c2ecf20Sopenharmony_ci	fdir_fltr_ctx.swap = ICE_FXD_FLTR_QW1_SWAP_NOT_SET;
3898c2ecf20Sopenharmony_ci	fdir_fltr_ctx.comp_q = ICE_FXD_FLTR_QW0_COMP_Q_ZERO;
3908c2ecf20Sopenharmony_ci	fdir_fltr_ctx.comp_report = ICE_FXD_FLTR_QW0_COMP_REPORT_SW_FAIL;
3918c2ecf20Sopenharmony_ci	fdir_fltr_ctx.fdid_prio = 3;
3928c2ecf20Sopenharmony_ci	fdir_fltr_ctx.desc_prof = 1;
3938c2ecf20Sopenharmony_ci	fdir_fltr_ctx.desc_prof_prio = 3;
3948c2ecf20Sopenharmony_ci	ice_set_fd_desc_val(&fdir_fltr_ctx, fdesc);
3958c2ecf20Sopenharmony_ci}
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci/**
3988c2ecf20Sopenharmony_ci * ice_alloc_fd_res_cntr - obtain counter resource for FD type
3998c2ecf20Sopenharmony_ci * @hw: pointer to the hardware structure
4008c2ecf20Sopenharmony_ci * @cntr_id: returns counter index
4018c2ecf20Sopenharmony_ci */
4028c2ecf20Sopenharmony_cienum ice_status ice_alloc_fd_res_cntr(struct ice_hw *hw, u16 *cntr_id)
4038c2ecf20Sopenharmony_ci{
4048c2ecf20Sopenharmony_ci	return ice_alloc_res_cntr(hw, ICE_AQC_RES_TYPE_FDIR_COUNTER_BLOCK,
4058c2ecf20Sopenharmony_ci				  ICE_AQC_RES_TYPE_FLAG_DEDICATED, 1, cntr_id);
4068c2ecf20Sopenharmony_ci}
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_ci/**
4098c2ecf20Sopenharmony_ci * ice_free_fd_res_cntr - Free counter resource for FD type
4108c2ecf20Sopenharmony_ci * @hw: pointer to the hardware structure
4118c2ecf20Sopenharmony_ci * @cntr_id: counter index to be freed
4128c2ecf20Sopenharmony_ci */
4138c2ecf20Sopenharmony_cienum ice_status ice_free_fd_res_cntr(struct ice_hw *hw, u16 cntr_id)
4148c2ecf20Sopenharmony_ci{
4158c2ecf20Sopenharmony_ci	return ice_free_res_cntr(hw, ICE_AQC_RES_TYPE_FDIR_COUNTER_BLOCK,
4168c2ecf20Sopenharmony_ci				 ICE_AQC_RES_TYPE_FLAG_DEDICATED, 1, cntr_id);
4178c2ecf20Sopenharmony_ci}
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ci/**
4208c2ecf20Sopenharmony_ci * ice_alloc_fd_guar_item - allocate resource for FD guaranteed entries
4218c2ecf20Sopenharmony_ci * @hw: pointer to the hardware structure
4228c2ecf20Sopenharmony_ci * @cntr_id: returns counter index
4238c2ecf20Sopenharmony_ci * @num_fltr: number of filter entries to be allocated
4248c2ecf20Sopenharmony_ci */
4258c2ecf20Sopenharmony_cienum ice_status
4268c2ecf20Sopenharmony_ciice_alloc_fd_guar_item(struct ice_hw *hw, u16 *cntr_id, u16 num_fltr)
4278c2ecf20Sopenharmony_ci{
4288c2ecf20Sopenharmony_ci	return ice_alloc_res_cntr(hw, ICE_AQC_RES_TYPE_FDIR_GUARANTEED_ENTRIES,
4298c2ecf20Sopenharmony_ci				  ICE_AQC_RES_TYPE_FLAG_DEDICATED, num_fltr,
4308c2ecf20Sopenharmony_ci				  cntr_id);
4318c2ecf20Sopenharmony_ci}
4328c2ecf20Sopenharmony_ci
4338c2ecf20Sopenharmony_ci/**
4348c2ecf20Sopenharmony_ci * ice_alloc_fd_shrd_item - allocate resource for flow director shared entries
4358c2ecf20Sopenharmony_ci * @hw: pointer to the hardware structure
4368c2ecf20Sopenharmony_ci * @cntr_id: returns counter index
4378c2ecf20Sopenharmony_ci * @num_fltr: number of filter entries to be allocated
4388c2ecf20Sopenharmony_ci */
4398c2ecf20Sopenharmony_cienum ice_status
4408c2ecf20Sopenharmony_ciice_alloc_fd_shrd_item(struct ice_hw *hw, u16 *cntr_id, u16 num_fltr)
4418c2ecf20Sopenharmony_ci{
4428c2ecf20Sopenharmony_ci	return ice_alloc_res_cntr(hw, ICE_AQC_RES_TYPE_FDIR_SHARED_ENTRIES,
4438c2ecf20Sopenharmony_ci				  ICE_AQC_RES_TYPE_FLAG_DEDICATED, num_fltr,
4448c2ecf20Sopenharmony_ci				  cntr_id);
4458c2ecf20Sopenharmony_ci}
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_ci/**
4488c2ecf20Sopenharmony_ci * ice_get_fdir_cnt_all - get the number of Flow Director filters
4498c2ecf20Sopenharmony_ci * @hw: hardware data structure
4508c2ecf20Sopenharmony_ci *
4518c2ecf20Sopenharmony_ci * Returns the number of filters available on device
4528c2ecf20Sopenharmony_ci */
4538c2ecf20Sopenharmony_ciint ice_get_fdir_cnt_all(struct ice_hw *hw)
4548c2ecf20Sopenharmony_ci{
4558c2ecf20Sopenharmony_ci	return hw->func_caps.fd_fltr_guar + hw->func_caps.fd_fltr_best_effort;
4568c2ecf20Sopenharmony_ci}
4578c2ecf20Sopenharmony_ci
4588c2ecf20Sopenharmony_ci/**
4598c2ecf20Sopenharmony_ci * ice_pkt_insert_ipv6_addr - insert a be32 IPv6 address into a memory buffer
4608c2ecf20Sopenharmony_ci * @pkt: packet buffer
4618c2ecf20Sopenharmony_ci * @offset: offset into buffer
4628c2ecf20Sopenharmony_ci * @addr: IPv6 address to convert and insert into pkt at offset
4638c2ecf20Sopenharmony_ci */
4648c2ecf20Sopenharmony_cistatic void ice_pkt_insert_ipv6_addr(u8 *pkt, int offset, __be32 *addr)
4658c2ecf20Sopenharmony_ci{
4668c2ecf20Sopenharmony_ci	int idx;
4678c2ecf20Sopenharmony_ci
4688c2ecf20Sopenharmony_ci	for (idx = 0; idx < ICE_IPV6_ADDR_LEN_AS_U32; idx++)
4698c2ecf20Sopenharmony_ci		memcpy(pkt + offset + idx * sizeof(*addr), &addr[idx],
4708c2ecf20Sopenharmony_ci		       sizeof(*addr));
4718c2ecf20Sopenharmony_ci}
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_ci/**
4748c2ecf20Sopenharmony_ci * ice_pkt_insert_u16 - insert a be16 value into a memory buffer
4758c2ecf20Sopenharmony_ci * @pkt: packet buffer
4768c2ecf20Sopenharmony_ci * @offset: offset into buffer
4778c2ecf20Sopenharmony_ci * @data: 16 bit value to convert and insert into pkt at offset
4788c2ecf20Sopenharmony_ci */
4798c2ecf20Sopenharmony_cistatic void ice_pkt_insert_u16(u8 *pkt, int offset, __be16 data)
4808c2ecf20Sopenharmony_ci{
4818c2ecf20Sopenharmony_ci	memcpy(pkt + offset, &data, sizeof(data));
4828c2ecf20Sopenharmony_ci}
4838c2ecf20Sopenharmony_ci
4848c2ecf20Sopenharmony_ci/**
4858c2ecf20Sopenharmony_ci * ice_pkt_insert_u32 - insert a be32 value into a memory buffer
4868c2ecf20Sopenharmony_ci * @pkt: packet buffer
4878c2ecf20Sopenharmony_ci * @offset: offset into buffer
4888c2ecf20Sopenharmony_ci * @data: 32 bit value to convert and insert into pkt at offset
4898c2ecf20Sopenharmony_ci */
4908c2ecf20Sopenharmony_cistatic void ice_pkt_insert_u32(u8 *pkt, int offset, __be32 data)
4918c2ecf20Sopenharmony_ci{
4928c2ecf20Sopenharmony_ci	memcpy(pkt + offset, &data, sizeof(data));
4938c2ecf20Sopenharmony_ci}
4948c2ecf20Sopenharmony_ci
4958c2ecf20Sopenharmony_ci/**
4968c2ecf20Sopenharmony_ci * ice_fdir_get_gen_prgm_pkt - generate a training packet
4978c2ecf20Sopenharmony_ci * @hw: pointer to the hardware structure
4988c2ecf20Sopenharmony_ci * @input: flow director filter data structure
4998c2ecf20Sopenharmony_ci * @pkt: pointer to return filter packet
5008c2ecf20Sopenharmony_ci * @frag: generate a fragment packet
5018c2ecf20Sopenharmony_ci * @tun: true implies generate a tunnel packet
5028c2ecf20Sopenharmony_ci */
5038c2ecf20Sopenharmony_cienum ice_status
5048c2ecf20Sopenharmony_ciice_fdir_get_gen_prgm_pkt(struct ice_hw *hw, struct ice_fdir_fltr *input,
5058c2ecf20Sopenharmony_ci			  u8 *pkt, bool frag, bool tun)
5068c2ecf20Sopenharmony_ci{
5078c2ecf20Sopenharmony_ci	enum ice_fltr_ptype flow;
5088c2ecf20Sopenharmony_ci	u16 tnl_port;
5098c2ecf20Sopenharmony_ci	u8 *loc;
5108c2ecf20Sopenharmony_ci	u16 idx;
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_ci	if (input->flow_type == ICE_FLTR_PTYPE_NONF_IPV4_OTHER) {
5138c2ecf20Sopenharmony_ci		switch (input->ip.v4.proto) {
5148c2ecf20Sopenharmony_ci		case IPPROTO_TCP:
5158c2ecf20Sopenharmony_ci			flow = ICE_FLTR_PTYPE_NONF_IPV4_TCP;
5168c2ecf20Sopenharmony_ci			break;
5178c2ecf20Sopenharmony_ci		case IPPROTO_UDP:
5188c2ecf20Sopenharmony_ci			flow = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
5198c2ecf20Sopenharmony_ci			break;
5208c2ecf20Sopenharmony_ci		case IPPROTO_SCTP:
5218c2ecf20Sopenharmony_ci			flow = ICE_FLTR_PTYPE_NONF_IPV4_SCTP;
5228c2ecf20Sopenharmony_ci			break;
5238c2ecf20Sopenharmony_ci		case IPPROTO_IP:
5248c2ecf20Sopenharmony_ci			flow = ICE_FLTR_PTYPE_NONF_IPV4_OTHER;
5258c2ecf20Sopenharmony_ci			break;
5268c2ecf20Sopenharmony_ci		default:
5278c2ecf20Sopenharmony_ci			return ICE_ERR_PARAM;
5288c2ecf20Sopenharmony_ci		}
5298c2ecf20Sopenharmony_ci	} else if (input->flow_type == ICE_FLTR_PTYPE_NONF_IPV6_OTHER) {
5308c2ecf20Sopenharmony_ci		switch (input->ip.v6.proto) {
5318c2ecf20Sopenharmony_ci		case IPPROTO_TCP:
5328c2ecf20Sopenharmony_ci			flow = ICE_FLTR_PTYPE_NONF_IPV6_TCP;
5338c2ecf20Sopenharmony_ci			break;
5348c2ecf20Sopenharmony_ci		case IPPROTO_UDP:
5358c2ecf20Sopenharmony_ci			flow = ICE_FLTR_PTYPE_NONF_IPV6_UDP;
5368c2ecf20Sopenharmony_ci			break;
5378c2ecf20Sopenharmony_ci		case IPPROTO_SCTP:
5388c2ecf20Sopenharmony_ci			flow = ICE_FLTR_PTYPE_NONF_IPV6_SCTP;
5398c2ecf20Sopenharmony_ci			break;
5408c2ecf20Sopenharmony_ci		case IPPROTO_IP:
5418c2ecf20Sopenharmony_ci			flow = ICE_FLTR_PTYPE_NONF_IPV6_OTHER;
5428c2ecf20Sopenharmony_ci			break;
5438c2ecf20Sopenharmony_ci		default:
5448c2ecf20Sopenharmony_ci			return ICE_ERR_PARAM;
5458c2ecf20Sopenharmony_ci		}
5468c2ecf20Sopenharmony_ci	} else {
5478c2ecf20Sopenharmony_ci		flow = input->flow_type;
5488c2ecf20Sopenharmony_ci	}
5498c2ecf20Sopenharmony_ci
5508c2ecf20Sopenharmony_ci	for (idx = 0; idx < ICE_FDIR_NUM_PKT; idx++)
5518c2ecf20Sopenharmony_ci		if (ice_fdir_pkt[idx].flow == flow)
5528c2ecf20Sopenharmony_ci			break;
5538c2ecf20Sopenharmony_ci	if (idx == ICE_FDIR_NUM_PKT)
5548c2ecf20Sopenharmony_ci		return ICE_ERR_PARAM;
5558c2ecf20Sopenharmony_ci	if (!tun) {
5568c2ecf20Sopenharmony_ci		memcpy(pkt, ice_fdir_pkt[idx].pkt, ice_fdir_pkt[idx].pkt_len);
5578c2ecf20Sopenharmony_ci		loc = pkt;
5588c2ecf20Sopenharmony_ci	} else {
5598c2ecf20Sopenharmony_ci		if (!ice_get_open_tunnel_port(hw, &tnl_port))
5608c2ecf20Sopenharmony_ci			return ICE_ERR_DOES_NOT_EXIST;
5618c2ecf20Sopenharmony_ci		if (!ice_fdir_pkt[idx].tun_pkt)
5628c2ecf20Sopenharmony_ci			return ICE_ERR_PARAM;
5638c2ecf20Sopenharmony_ci		memcpy(pkt, ice_fdir_pkt[idx].tun_pkt,
5648c2ecf20Sopenharmony_ci		       ice_fdir_pkt[idx].tun_pkt_len);
5658c2ecf20Sopenharmony_ci		ice_pkt_insert_u16(pkt, ICE_IPV4_UDP_DST_PORT_OFFSET,
5668c2ecf20Sopenharmony_ci				   htons(tnl_port));
5678c2ecf20Sopenharmony_ci		loc = &pkt[ICE_FDIR_TUN_PKT_OFF];
5688c2ecf20Sopenharmony_ci	}
5698c2ecf20Sopenharmony_ci
5708c2ecf20Sopenharmony_ci	/* Reverse the src and dst, since the HW expects them to be from Tx
5718c2ecf20Sopenharmony_ci	 * perspective. The input from user is from Rx filter perspective.
5728c2ecf20Sopenharmony_ci	 */
5738c2ecf20Sopenharmony_ci	switch (flow) {
5748c2ecf20Sopenharmony_ci	case ICE_FLTR_PTYPE_NONF_IPV4_TCP:
5758c2ecf20Sopenharmony_ci		ice_pkt_insert_u32(loc, ICE_IPV4_DST_ADDR_OFFSET,
5768c2ecf20Sopenharmony_ci				   input->ip.v4.src_ip);
5778c2ecf20Sopenharmony_ci		ice_pkt_insert_u16(loc, ICE_IPV4_TCP_DST_PORT_OFFSET,
5788c2ecf20Sopenharmony_ci				   input->ip.v4.src_port);
5798c2ecf20Sopenharmony_ci		ice_pkt_insert_u32(loc, ICE_IPV4_SRC_ADDR_OFFSET,
5808c2ecf20Sopenharmony_ci				   input->ip.v4.dst_ip);
5818c2ecf20Sopenharmony_ci		ice_pkt_insert_u16(loc, ICE_IPV4_TCP_SRC_PORT_OFFSET,
5828c2ecf20Sopenharmony_ci				   input->ip.v4.dst_port);
5838c2ecf20Sopenharmony_ci		if (frag)
5848c2ecf20Sopenharmony_ci			loc[20] = ICE_FDIR_IPV4_PKT_FLAG_DF;
5858c2ecf20Sopenharmony_ci		break;
5868c2ecf20Sopenharmony_ci	case ICE_FLTR_PTYPE_NONF_IPV4_UDP:
5878c2ecf20Sopenharmony_ci		ice_pkt_insert_u32(loc, ICE_IPV4_DST_ADDR_OFFSET,
5888c2ecf20Sopenharmony_ci				   input->ip.v4.src_ip);
5898c2ecf20Sopenharmony_ci		ice_pkt_insert_u16(loc, ICE_IPV4_UDP_DST_PORT_OFFSET,
5908c2ecf20Sopenharmony_ci				   input->ip.v4.src_port);
5918c2ecf20Sopenharmony_ci		ice_pkt_insert_u32(loc, ICE_IPV4_SRC_ADDR_OFFSET,
5928c2ecf20Sopenharmony_ci				   input->ip.v4.dst_ip);
5938c2ecf20Sopenharmony_ci		ice_pkt_insert_u16(loc, ICE_IPV4_UDP_SRC_PORT_OFFSET,
5948c2ecf20Sopenharmony_ci				   input->ip.v4.dst_port);
5958c2ecf20Sopenharmony_ci		break;
5968c2ecf20Sopenharmony_ci	case ICE_FLTR_PTYPE_NONF_IPV4_SCTP:
5978c2ecf20Sopenharmony_ci		ice_pkt_insert_u32(loc, ICE_IPV4_DST_ADDR_OFFSET,
5988c2ecf20Sopenharmony_ci				   input->ip.v4.src_ip);
5998c2ecf20Sopenharmony_ci		ice_pkt_insert_u16(loc, ICE_IPV4_SCTP_DST_PORT_OFFSET,
6008c2ecf20Sopenharmony_ci				   input->ip.v4.src_port);
6018c2ecf20Sopenharmony_ci		ice_pkt_insert_u32(loc, ICE_IPV4_SRC_ADDR_OFFSET,
6028c2ecf20Sopenharmony_ci				   input->ip.v4.dst_ip);
6038c2ecf20Sopenharmony_ci		ice_pkt_insert_u16(loc, ICE_IPV4_SCTP_SRC_PORT_OFFSET,
6048c2ecf20Sopenharmony_ci				   input->ip.v4.dst_port);
6058c2ecf20Sopenharmony_ci		break;
6068c2ecf20Sopenharmony_ci	case ICE_FLTR_PTYPE_NONF_IPV4_OTHER:
6078c2ecf20Sopenharmony_ci		ice_pkt_insert_u32(loc, ICE_IPV4_DST_ADDR_OFFSET,
6088c2ecf20Sopenharmony_ci				   input->ip.v4.src_ip);
6098c2ecf20Sopenharmony_ci		ice_pkt_insert_u32(loc, ICE_IPV4_SRC_ADDR_OFFSET,
6108c2ecf20Sopenharmony_ci				   input->ip.v4.dst_ip);
6118c2ecf20Sopenharmony_ci		ice_pkt_insert_u16(loc, ICE_IPV4_PROTO_OFFSET, 0);
6128c2ecf20Sopenharmony_ci		break;
6138c2ecf20Sopenharmony_ci	case ICE_FLTR_PTYPE_NONF_IPV6_TCP:
6148c2ecf20Sopenharmony_ci		ice_pkt_insert_ipv6_addr(loc, ICE_IPV6_DST_ADDR_OFFSET,
6158c2ecf20Sopenharmony_ci					 input->ip.v6.src_ip);
6168c2ecf20Sopenharmony_ci		ice_pkt_insert_ipv6_addr(loc, ICE_IPV6_SRC_ADDR_OFFSET,
6178c2ecf20Sopenharmony_ci					 input->ip.v6.dst_ip);
6188c2ecf20Sopenharmony_ci		ice_pkt_insert_u16(loc, ICE_IPV6_TCP_DST_PORT_OFFSET,
6198c2ecf20Sopenharmony_ci				   input->ip.v6.src_port);
6208c2ecf20Sopenharmony_ci		ice_pkt_insert_u16(loc, ICE_IPV6_TCP_SRC_PORT_OFFSET,
6218c2ecf20Sopenharmony_ci				   input->ip.v6.dst_port);
6228c2ecf20Sopenharmony_ci		break;
6238c2ecf20Sopenharmony_ci	case ICE_FLTR_PTYPE_NONF_IPV6_UDP:
6248c2ecf20Sopenharmony_ci		ice_pkt_insert_ipv6_addr(loc, ICE_IPV6_DST_ADDR_OFFSET,
6258c2ecf20Sopenharmony_ci					 input->ip.v6.src_ip);
6268c2ecf20Sopenharmony_ci		ice_pkt_insert_ipv6_addr(loc, ICE_IPV6_SRC_ADDR_OFFSET,
6278c2ecf20Sopenharmony_ci					 input->ip.v6.dst_ip);
6288c2ecf20Sopenharmony_ci		ice_pkt_insert_u16(loc, ICE_IPV6_UDP_DST_PORT_OFFSET,
6298c2ecf20Sopenharmony_ci				   input->ip.v6.src_port);
6308c2ecf20Sopenharmony_ci		ice_pkt_insert_u16(loc, ICE_IPV6_UDP_SRC_PORT_OFFSET,
6318c2ecf20Sopenharmony_ci				   input->ip.v6.dst_port);
6328c2ecf20Sopenharmony_ci		break;
6338c2ecf20Sopenharmony_ci	case ICE_FLTR_PTYPE_NONF_IPV6_SCTP:
6348c2ecf20Sopenharmony_ci		ice_pkt_insert_ipv6_addr(loc, ICE_IPV6_DST_ADDR_OFFSET,
6358c2ecf20Sopenharmony_ci					 input->ip.v6.src_ip);
6368c2ecf20Sopenharmony_ci		ice_pkt_insert_ipv6_addr(loc, ICE_IPV6_SRC_ADDR_OFFSET,
6378c2ecf20Sopenharmony_ci					 input->ip.v6.dst_ip);
6388c2ecf20Sopenharmony_ci		ice_pkt_insert_u16(loc, ICE_IPV6_SCTP_DST_PORT_OFFSET,
6398c2ecf20Sopenharmony_ci				   input->ip.v6.src_port);
6408c2ecf20Sopenharmony_ci		ice_pkt_insert_u16(loc, ICE_IPV6_SCTP_SRC_PORT_OFFSET,
6418c2ecf20Sopenharmony_ci				   input->ip.v6.dst_port);
6428c2ecf20Sopenharmony_ci		break;
6438c2ecf20Sopenharmony_ci	case ICE_FLTR_PTYPE_NONF_IPV6_OTHER:
6448c2ecf20Sopenharmony_ci		ice_pkt_insert_ipv6_addr(loc, ICE_IPV6_DST_ADDR_OFFSET,
6458c2ecf20Sopenharmony_ci					 input->ip.v6.src_ip);
6468c2ecf20Sopenharmony_ci		ice_pkt_insert_ipv6_addr(loc, ICE_IPV6_SRC_ADDR_OFFSET,
6478c2ecf20Sopenharmony_ci					 input->ip.v6.dst_ip);
6488c2ecf20Sopenharmony_ci		break;
6498c2ecf20Sopenharmony_ci	default:
6508c2ecf20Sopenharmony_ci		return ICE_ERR_PARAM;
6518c2ecf20Sopenharmony_ci	}
6528c2ecf20Sopenharmony_ci
6538c2ecf20Sopenharmony_ci	if (input->flex_fltr)
6548c2ecf20Sopenharmony_ci		ice_pkt_insert_u16(loc, input->flex_offset, input->flex_word);
6558c2ecf20Sopenharmony_ci
6568c2ecf20Sopenharmony_ci	return 0;
6578c2ecf20Sopenharmony_ci}
6588c2ecf20Sopenharmony_ci
6598c2ecf20Sopenharmony_ci/**
6608c2ecf20Sopenharmony_ci * ice_fdir_has_frag - does flow type have 2 ptypes
6618c2ecf20Sopenharmony_ci * @flow: flow ptype
6628c2ecf20Sopenharmony_ci *
6638c2ecf20Sopenharmony_ci * returns true is there is a fragment packet for this ptype
6648c2ecf20Sopenharmony_ci */
6658c2ecf20Sopenharmony_cibool ice_fdir_has_frag(enum ice_fltr_ptype flow)
6668c2ecf20Sopenharmony_ci{
6678c2ecf20Sopenharmony_ci	if (flow == ICE_FLTR_PTYPE_NONF_IPV4_OTHER)
6688c2ecf20Sopenharmony_ci		return true;
6698c2ecf20Sopenharmony_ci	else
6708c2ecf20Sopenharmony_ci		return false;
6718c2ecf20Sopenharmony_ci}
6728c2ecf20Sopenharmony_ci
6738c2ecf20Sopenharmony_ci/**
6748c2ecf20Sopenharmony_ci * ice_fdir_find_by_idx - find filter with idx
6758c2ecf20Sopenharmony_ci * @hw: pointer to hardware structure
6768c2ecf20Sopenharmony_ci * @fltr_idx: index to find.
6778c2ecf20Sopenharmony_ci *
6788c2ecf20Sopenharmony_ci * Returns pointer to filter if found or null
6798c2ecf20Sopenharmony_ci */
6808c2ecf20Sopenharmony_cistruct ice_fdir_fltr *
6818c2ecf20Sopenharmony_ciice_fdir_find_fltr_by_idx(struct ice_hw *hw, u32 fltr_idx)
6828c2ecf20Sopenharmony_ci{
6838c2ecf20Sopenharmony_ci	struct ice_fdir_fltr *rule;
6848c2ecf20Sopenharmony_ci
6858c2ecf20Sopenharmony_ci	list_for_each_entry(rule, &hw->fdir_list_head, fltr_node) {
6868c2ecf20Sopenharmony_ci		/* rule ID found in the list */
6878c2ecf20Sopenharmony_ci		if (fltr_idx == rule->fltr_id)
6888c2ecf20Sopenharmony_ci			return rule;
6898c2ecf20Sopenharmony_ci		if (fltr_idx < rule->fltr_id)
6908c2ecf20Sopenharmony_ci			break;
6918c2ecf20Sopenharmony_ci	}
6928c2ecf20Sopenharmony_ci	return NULL;
6938c2ecf20Sopenharmony_ci}
6948c2ecf20Sopenharmony_ci
6958c2ecf20Sopenharmony_ci/**
6968c2ecf20Sopenharmony_ci * ice_fdir_list_add_fltr - add a new node to the flow director filter list
6978c2ecf20Sopenharmony_ci * @hw: hardware structure
6988c2ecf20Sopenharmony_ci * @fltr: filter node to add to structure
6998c2ecf20Sopenharmony_ci */
7008c2ecf20Sopenharmony_civoid ice_fdir_list_add_fltr(struct ice_hw *hw, struct ice_fdir_fltr *fltr)
7018c2ecf20Sopenharmony_ci{
7028c2ecf20Sopenharmony_ci	struct ice_fdir_fltr *rule, *parent = NULL;
7038c2ecf20Sopenharmony_ci
7048c2ecf20Sopenharmony_ci	list_for_each_entry(rule, &hw->fdir_list_head, fltr_node) {
7058c2ecf20Sopenharmony_ci		/* rule ID found or pass its spot in the list */
7068c2ecf20Sopenharmony_ci		if (rule->fltr_id >= fltr->fltr_id)
7078c2ecf20Sopenharmony_ci			break;
7088c2ecf20Sopenharmony_ci		parent = rule;
7098c2ecf20Sopenharmony_ci	}
7108c2ecf20Sopenharmony_ci
7118c2ecf20Sopenharmony_ci	if (parent)
7128c2ecf20Sopenharmony_ci		list_add(&fltr->fltr_node, &parent->fltr_node);
7138c2ecf20Sopenharmony_ci	else
7148c2ecf20Sopenharmony_ci		list_add(&fltr->fltr_node, &hw->fdir_list_head);
7158c2ecf20Sopenharmony_ci}
7168c2ecf20Sopenharmony_ci
7178c2ecf20Sopenharmony_ci/**
7188c2ecf20Sopenharmony_ci * ice_fdir_update_cntrs - increment / decrement filter counter
7198c2ecf20Sopenharmony_ci * @hw: pointer to hardware structure
7208c2ecf20Sopenharmony_ci * @flow: filter flow type
7218c2ecf20Sopenharmony_ci * @add: true implies filters added
7228c2ecf20Sopenharmony_ci */
7238c2ecf20Sopenharmony_civoid
7248c2ecf20Sopenharmony_ciice_fdir_update_cntrs(struct ice_hw *hw, enum ice_fltr_ptype flow, bool add)
7258c2ecf20Sopenharmony_ci{
7268c2ecf20Sopenharmony_ci	int incr;
7278c2ecf20Sopenharmony_ci
7288c2ecf20Sopenharmony_ci	incr = add ? 1 : -1;
7298c2ecf20Sopenharmony_ci	hw->fdir_active_fltr += incr;
7308c2ecf20Sopenharmony_ci
7318c2ecf20Sopenharmony_ci	if (flow == ICE_FLTR_PTYPE_NONF_NONE || flow >= ICE_FLTR_PTYPE_MAX)
7328c2ecf20Sopenharmony_ci		ice_debug(hw, ICE_DBG_SW, "Unknown filter type %d\n", flow);
7338c2ecf20Sopenharmony_ci	else
7348c2ecf20Sopenharmony_ci		hw->fdir_fltr_cnt[flow] += incr;
7358c2ecf20Sopenharmony_ci}
7368c2ecf20Sopenharmony_ci
7378c2ecf20Sopenharmony_ci/**
7388c2ecf20Sopenharmony_ci * ice_cmp_ipv6_addr - compare 2 IP v6 addresses
7398c2ecf20Sopenharmony_ci * @a: IP v6 address
7408c2ecf20Sopenharmony_ci * @b: IP v6 address
7418c2ecf20Sopenharmony_ci *
7428c2ecf20Sopenharmony_ci * Returns 0 on equal, returns non-0 if different
7438c2ecf20Sopenharmony_ci */
7448c2ecf20Sopenharmony_cistatic int ice_cmp_ipv6_addr(__be32 *a, __be32 *b)
7458c2ecf20Sopenharmony_ci{
7468c2ecf20Sopenharmony_ci	return memcmp(a, b, 4 * sizeof(__be32));
7478c2ecf20Sopenharmony_ci}
7488c2ecf20Sopenharmony_ci
7498c2ecf20Sopenharmony_ci/**
7508c2ecf20Sopenharmony_ci * ice_fdir_comp_rules - compare 2 filters
7518c2ecf20Sopenharmony_ci * @a: a Flow Director filter data structure
7528c2ecf20Sopenharmony_ci * @b: a Flow Director filter data structure
7538c2ecf20Sopenharmony_ci * @v6: bool true if v6 filter
7548c2ecf20Sopenharmony_ci *
7558c2ecf20Sopenharmony_ci * Returns true if the filters match
7568c2ecf20Sopenharmony_ci */
7578c2ecf20Sopenharmony_cistatic bool
7588c2ecf20Sopenharmony_ciice_fdir_comp_rules(struct ice_fdir_fltr *a,  struct ice_fdir_fltr *b, bool v6)
7598c2ecf20Sopenharmony_ci{
7608c2ecf20Sopenharmony_ci	enum ice_fltr_ptype flow_type = a->flow_type;
7618c2ecf20Sopenharmony_ci
7628c2ecf20Sopenharmony_ci	/* The calling function already checks that the two filters have the
7638c2ecf20Sopenharmony_ci	 * same flow_type.
7648c2ecf20Sopenharmony_ci	 */
7658c2ecf20Sopenharmony_ci	if (!v6) {
7668c2ecf20Sopenharmony_ci		if (flow_type == ICE_FLTR_PTYPE_NONF_IPV4_TCP ||
7678c2ecf20Sopenharmony_ci		    flow_type == ICE_FLTR_PTYPE_NONF_IPV4_UDP ||
7688c2ecf20Sopenharmony_ci		    flow_type == ICE_FLTR_PTYPE_NONF_IPV4_SCTP) {
7698c2ecf20Sopenharmony_ci			if (a->ip.v4.dst_ip == b->ip.v4.dst_ip &&
7708c2ecf20Sopenharmony_ci			    a->ip.v4.src_ip == b->ip.v4.src_ip &&
7718c2ecf20Sopenharmony_ci			    a->ip.v4.dst_port == b->ip.v4.dst_port &&
7728c2ecf20Sopenharmony_ci			    a->ip.v4.src_port == b->ip.v4.src_port)
7738c2ecf20Sopenharmony_ci				return true;
7748c2ecf20Sopenharmony_ci		} else if (flow_type == ICE_FLTR_PTYPE_NONF_IPV4_OTHER) {
7758c2ecf20Sopenharmony_ci			if (a->ip.v4.dst_ip == b->ip.v4.dst_ip &&
7768c2ecf20Sopenharmony_ci			    a->ip.v4.src_ip == b->ip.v4.src_ip &&
7778c2ecf20Sopenharmony_ci			    a->ip.v4.l4_header == b->ip.v4.l4_header &&
7788c2ecf20Sopenharmony_ci			    a->ip.v4.proto == b->ip.v4.proto &&
7798c2ecf20Sopenharmony_ci			    a->ip.v4.ip_ver == b->ip.v4.ip_ver &&
7808c2ecf20Sopenharmony_ci			    a->ip.v4.tos == b->ip.v4.tos)
7818c2ecf20Sopenharmony_ci				return true;
7828c2ecf20Sopenharmony_ci		}
7838c2ecf20Sopenharmony_ci	} else {
7848c2ecf20Sopenharmony_ci		if (flow_type == ICE_FLTR_PTYPE_NONF_IPV6_UDP ||
7858c2ecf20Sopenharmony_ci		    flow_type == ICE_FLTR_PTYPE_NONF_IPV6_TCP ||
7868c2ecf20Sopenharmony_ci		    flow_type == ICE_FLTR_PTYPE_NONF_IPV6_SCTP) {
7878c2ecf20Sopenharmony_ci			if (a->ip.v6.dst_port == b->ip.v6.dst_port &&
7888c2ecf20Sopenharmony_ci			    a->ip.v6.src_port == b->ip.v6.src_port &&
7898c2ecf20Sopenharmony_ci			    !ice_cmp_ipv6_addr(a->ip.v6.dst_ip,
7908c2ecf20Sopenharmony_ci					       b->ip.v6.dst_ip) &&
7918c2ecf20Sopenharmony_ci			    !ice_cmp_ipv6_addr(a->ip.v6.src_ip,
7928c2ecf20Sopenharmony_ci					       b->ip.v6.src_ip))
7938c2ecf20Sopenharmony_ci				return true;
7948c2ecf20Sopenharmony_ci		} else if (flow_type == ICE_FLTR_PTYPE_NONF_IPV6_OTHER) {
7958c2ecf20Sopenharmony_ci			if (a->ip.v6.dst_port == b->ip.v6.dst_port &&
7968c2ecf20Sopenharmony_ci			    a->ip.v6.src_port == b->ip.v6.src_port)
7978c2ecf20Sopenharmony_ci				return true;
7988c2ecf20Sopenharmony_ci		}
7998c2ecf20Sopenharmony_ci	}
8008c2ecf20Sopenharmony_ci
8018c2ecf20Sopenharmony_ci	return false;
8028c2ecf20Sopenharmony_ci}
8038c2ecf20Sopenharmony_ci
8048c2ecf20Sopenharmony_ci/**
8058c2ecf20Sopenharmony_ci * ice_fdir_is_dup_fltr - test if filter is already in list for PF
8068c2ecf20Sopenharmony_ci * @hw: hardware data structure
8078c2ecf20Sopenharmony_ci * @input: Flow Director filter data structure
8088c2ecf20Sopenharmony_ci *
8098c2ecf20Sopenharmony_ci * Returns true if the filter is found in the list
8108c2ecf20Sopenharmony_ci */
8118c2ecf20Sopenharmony_cibool ice_fdir_is_dup_fltr(struct ice_hw *hw, struct ice_fdir_fltr *input)
8128c2ecf20Sopenharmony_ci{
8138c2ecf20Sopenharmony_ci	struct ice_fdir_fltr *rule;
8148c2ecf20Sopenharmony_ci	bool ret = false;
8158c2ecf20Sopenharmony_ci
8168c2ecf20Sopenharmony_ci	list_for_each_entry(rule, &hw->fdir_list_head, fltr_node) {
8178c2ecf20Sopenharmony_ci		enum ice_fltr_ptype flow_type;
8188c2ecf20Sopenharmony_ci
8198c2ecf20Sopenharmony_ci		if (rule->flow_type != input->flow_type)
8208c2ecf20Sopenharmony_ci			continue;
8218c2ecf20Sopenharmony_ci
8228c2ecf20Sopenharmony_ci		flow_type = input->flow_type;
8238c2ecf20Sopenharmony_ci		if (flow_type == ICE_FLTR_PTYPE_NONF_IPV4_TCP ||
8248c2ecf20Sopenharmony_ci		    flow_type == ICE_FLTR_PTYPE_NONF_IPV4_UDP ||
8258c2ecf20Sopenharmony_ci		    flow_type == ICE_FLTR_PTYPE_NONF_IPV4_SCTP ||
8268c2ecf20Sopenharmony_ci		    flow_type == ICE_FLTR_PTYPE_NONF_IPV4_OTHER)
8278c2ecf20Sopenharmony_ci			ret = ice_fdir_comp_rules(rule, input, false);
8288c2ecf20Sopenharmony_ci		else
8298c2ecf20Sopenharmony_ci			ret = ice_fdir_comp_rules(rule, input, true);
8308c2ecf20Sopenharmony_ci		if (ret) {
8318c2ecf20Sopenharmony_ci			if (rule->fltr_id == input->fltr_id &&
8328c2ecf20Sopenharmony_ci			    rule->q_index != input->q_index)
8338c2ecf20Sopenharmony_ci				ret = false;
8348c2ecf20Sopenharmony_ci			else
8358c2ecf20Sopenharmony_ci				break;
8368c2ecf20Sopenharmony_ci		}
8378c2ecf20Sopenharmony_ci	}
8388c2ecf20Sopenharmony_ci
8398c2ecf20Sopenharmony_ci	return ret;
8408c2ecf20Sopenharmony_ci}
841