ice_ethtool_fdir.c 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright (C) 2018-2023, Intel Corporation. */
  3. /* flow director ethtool support for ice */
  4. #include "ice.h"
  5. #include "ice_lib.h"
  6. #include "ice_fdir.h"
  7. #include "ice_flow.h"
  8. static struct in6_addr full_ipv6_addr_mask = {
  9. .in6_u = {
  10. .u6_addr8 = {
  11. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  12. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  13. }
  14. }
  15. };
  16. static struct in6_addr zero_ipv6_addr_mask = {
  17. .in6_u = {
  18. .u6_addr8 = {
  19. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  20. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  21. }
  22. }
  23. };
  24. /* calls to ice_flow_add_prof require the number of segments in the array
  25. * for segs_cnt. In this code that is one more than the index.
  26. */
  27. #define TNL_SEG_CNT(_TNL_) ((_TNL_) + 1)
  28. /**
  29. * ice_fltr_to_ethtool_flow - convert filter type values to ethtool
  30. * flow type values
  31. * @flow: filter type to be converted
  32. *
  33. * Returns the corresponding ethtool flow type.
  34. */
  35. static int ice_fltr_to_ethtool_flow(enum ice_fltr_ptype flow)
  36. {
  37. switch (flow) {
  38. case ICE_FLTR_PTYPE_NONF_ETH:
  39. return ETHER_FLOW;
  40. case ICE_FLTR_PTYPE_NONF_IPV4_TCP:
  41. return TCP_V4_FLOW;
  42. case ICE_FLTR_PTYPE_NONF_IPV4_UDP:
  43. return UDP_V4_FLOW;
  44. case ICE_FLTR_PTYPE_NONF_IPV4_SCTP:
  45. return SCTP_V4_FLOW;
  46. case ICE_FLTR_PTYPE_NONF_IPV4_OTHER:
  47. return IPV4_USER_FLOW;
  48. case ICE_FLTR_PTYPE_NONF_IPV6_TCP:
  49. return TCP_V6_FLOW;
  50. case ICE_FLTR_PTYPE_NONF_IPV6_UDP:
  51. return UDP_V6_FLOW;
  52. case ICE_FLTR_PTYPE_NONF_IPV6_SCTP:
  53. return SCTP_V6_FLOW;
  54. case ICE_FLTR_PTYPE_NONF_IPV6_OTHER:
  55. return IPV6_USER_FLOW;
  56. default:
  57. /* 0 is undefined ethtool flow */
  58. return 0;
  59. }
  60. }
  61. /**
  62. * ice_ethtool_flow_to_fltr - convert ethtool flow type to filter enum
  63. * @eth: Ethtool flow type to be converted
  64. *
  65. * Returns flow enum
  66. */
  67. static enum ice_fltr_ptype ice_ethtool_flow_to_fltr(int eth)
  68. {
  69. switch (eth) {
  70. case ETHER_FLOW:
  71. return ICE_FLTR_PTYPE_NONF_ETH;
  72. case TCP_V4_FLOW:
  73. return ICE_FLTR_PTYPE_NONF_IPV4_TCP;
  74. case UDP_V4_FLOW:
  75. return ICE_FLTR_PTYPE_NONF_IPV4_UDP;
  76. case SCTP_V4_FLOW:
  77. return ICE_FLTR_PTYPE_NONF_IPV4_SCTP;
  78. case IPV4_USER_FLOW:
  79. return ICE_FLTR_PTYPE_NONF_IPV4_OTHER;
  80. case TCP_V6_FLOW:
  81. return ICE_FLTR_PTYPE_NONF_IPV6_TCP;
  82. case UDP_V6_FLOW:
  83. return ICE_FLTR_PTYPE_NONF_IPV6_UDP;
  84. case SCTP_V6_FLOW:
  85. return ICE_FLTR_PTYPE_NONF_IPV6_SCTP;
  86. case IPV6_USER_FLOW:
  87. return ICE_FLTR_PTYPE_NONF_IPV6_OTHER;
  88. default:
  89. return ICE_FLTR_PTYPE_NONF_NONE;
  90. }
  91. }
  92. /**
  93. * ice_is_mask_valid - check mask field set
  94. * @mask: full mask to check
  95. * @field: field for which mask should be valid
  96. *
  97. * If the mask is fully set return true. If it is not valid for field return
  98. * false.
  99. */
  100. static bool ice_is_mask_valid(u64 mask, u64 field)
  101. {
  102. return (mask & field) == field;
  103. }
  104. /**
  105. * ice_get_ethtool_fdir_entry - fill ethtool structure with fdir filter data
  106. * @hw: hardware structure that contains filter list
  107. * @cmd: ethtool command data structure to receive the filter data
  108. *
  109. * Returns 0 on success and -EINVAL on failure
  110. */
  111. int ice_get_ethtool_fdir_entry(struct ice_hw *hw, struct ethtool_rxnfc *cmd)
  112. {
  113. struct ethtool_rx_flow_spec *fsp;
  114. struct ice_fdir_fltr *rule;
  115. int ret = 0;
  116. u16 idx;
  117. fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
  118. mutex_lock(&hw->fdir_fltr_lock);
  119. rule = ice_fdir_find_fltr_by_idx(hw, fsp->location);
  120. if (!rule || fsp->location != rule->fltr_id) {
  121. ret = -EINVAL;
  122. goto release_lock;
  123. }
  124. fsp->flow_type = ice_fltr_to_ethtool_flow(rule->flow_type);
  125. memset(&fsp->m_u, 0, sizeof(fsp->m_u));
  126. memset(&fsp->m_ext, 0, sizeof(fsp->m_ext));
  127. switch (fsp->flow_type) {
  128. case ETHER_FLOW:
  129. fsp->h_u.ether_spec = rule->eth;
  130. fsp->m_u.ether_spec = rule->eth_mask;
  131. break;
  132. case IPV4_USER_FLOW:
  133. fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
  134. fsp->h_u.usr_ip4_spec.proto = 0;
  135. fsp->h_u.usr_ip4_spec.l4_4_bytes = rule->ip.v4.l4_header;
  136. fsp->h_u.usr_ip4_spec.tos = rule->ip.v4.tos;
  137. fsp->h_u.usr_ip4_spec.ip4src = rule->ip.v4.src_ip;
  138. fsp->h_u.usr_ip4_spec.ip4dst = rule->ip.v4.dst_ip;
  139. fsp->m_u.usr_ip4_spec.ip4src = rule->mask.v4.src_ip;
  140. fsp->m_u.usr_ip4_spec.ip4dst = rule->mask.v4.dst_ip;
  141. fsp->m_u.usr_ip4_spec.ip_ver = 0xFF;
  142. fsp->m_u.usr_ip4_spec.proto = 0;
  143. fsp->m_u.usr_ip4_spec.l4_4_bytes = rule->mask.v4.l4_header;
  144. fsp->m_u.usr_ip4_spec.tos = rule->mask.v4.tos;
  145. break;
  146. case TCP_V4_FLOW:
  147. case UDP_V4_FLOW:
  148. case SCTP_V4_FLOW:
  149. fsp->h_u.tcp_ip4_spec.psrc = rule->ip.v4.src_port;
  150. fsp->h_u.tcp_ip4_spec.pdst = rule->ip.v4.dst_port;
  151. fsp->h_u.tcp_ip4_spec.ip4src = rule->ip.v4.src_ip;
  152. fsp->h_u.tcp_ip4_spec.ip4dst = rule->ip.v4.dst_ip;
  153. fsp->m_u.tcp_ip4_spec.psrc = rule->mask.v4.src_port;
  154. fsp->m_u.tcp_ip4_spec.pdst = rule->mask.v4.dst_port;
  155. fsp->m_u.tcp_ip4_spec.ip4src = rule->mask.v4.src_ip;
  156. fsp->m_u.tcp_ip4_spec.ip4dst = rule->mask.v4.dst_ip;
  157. break;
  158. case IPV6_USER_FLOW:
  159. fsp->h_u.usr_ip6_spec.l4_4_bytes = rule->ip.v6.l4_header;
  160. fsp->h_u.usr_ip6_spec.tclass = rule->ip.v6.tc;
  161. fsp->h_u.usr_ip6_spec.l4_proto = rule->ip.v6.proto;
  162. memcpy(fsp->h_u.tcp_ip6_spec.ip6src, rule->ip.v6.src_ip,
  163. sizeof(struct in6_addr));
  164. memcpy(fsp->h_u.tcp_ip6_spec.ip6dst, rule->ip.v6.dst_ip,
  165. sizeof(struct in6_addr));
  166. memcpy(fsp->m_u.tcp_ip6_spec.ip6src, rule->mask.v6.src_ip,
  167. sizeof(struct in6_addr));
  168. memcpy(fsp->m_u.tcp_ip6_spec.ip6dst, rule->mask.v6.dst_ip,
  169. sizeof(struct in6_addr));
  170. fsp->m_u.usr_ip6_spec.l4_4_bytes = rule->mask.v6.l4_header;
  171. fsp->m_u.usr_ip6_spec.tclass = rule->mask.v6.tc;
  172. fsp->m_u.usr_ip6_spec.l4_proto = rule->mask.v6.proto;
  173. break;
  174. case TCP_V6_FLOW:
  175. case UDP_V6_FLOW:
  176. case SCTP_V6_FLOW:
  177. memcpy(fsp->h_u.tcp_ip6_spec.ip6src, rule->ip.v6.src_ip,
  178. sizeof(struct in6_addr));
  179. memcpy(fsp->h_u.tcp_ip6_spec.ip6dst, rule->ip.v6.dst_ip,
  180. sizeof(struct in6_addr));
  181. fsp->h_u.tcp_ip6_spec.psrc = rule->ip.v6.src_port;
  182. fsp->h_u.tcp_ip6_spec.pdst = rule->ip.v6.dst_port;
  183. memcpy(fsp->m_u.tcp_ip6_spec.ip6src,
  184. rule->mask.v6.src_ip,
  185. sizeof(struct in6_addr));
  186. memcpy(fsp->m_u.tcp_ip6_spec.ip6dst,
  187. rule->mask.v6.dst_ip,
  188. sizeof(struct in6_addr));
  189. fsp->m_u.tcp_ip6_spec.psrc = rule->mask.v6.src_port;
  190. fsp->m_u.tcp_ip6_spec.pdst = rule->mask.v6.dst_port;
  191. fsp->h_u.tcp_ip6_spec.tclass = rule->ip.v6.tc;
  192. fsp->m_u.tcp_ip6_spec.tclass = rule->mask.v6.tc;
  193. break;
  194. default:
  195. break;
  196. }
  197. if (rule->dest_ctl == ICE_FLTR_PRGM_DESC_DEST_DROP_PKT)
  198. fsp->ring_cookie = RX_CLS_FLOW_DISC;
  199. else
  200. fsp->ring_cookie = rule->orig_q_index;
  201. idx = ice_ethtool_flow_to_fltr(fsp->flow_type);
  202. if (idx == ICE_FLTR_PTYPE_NONF_NONE) {
  203. dev_err(ice_hw_to_dev(hw), "Missing input index for flow_type %d\n",
  204. rule->flow_type);
  205. ret = -EINVAL;
  206. }
  207. release_lock:
  208. mutex_unlock(&hw->fdir_fltr_lock);
  209. return ret;
  210. }
  211. /**
  212. * ice_get_fdir_fltr_ids - fill buffer with filter IDs of active filters
  213. * @hw: hardware structure containing the filter list
  214. * @cmd: ethtool command data structure
  215. * @rule_locs: ethtool array passed in from OS to receive filter IDs
  216. *
  217. * Returns 0 as expected for success by ethtool
  218. */
  219. int
  220. ice_get_fdir_fltr_ids(struct ice_hw *hw, struct ethtool_rxnfc *cmd,
  221. u32 *rule_locs)
  222. {
  223. struct ice_fdir_fltr *f_rule;
  224. unsigned int cnt = 0;
  225. int val = 0;
  226. /* report total rule count */
  227. cmd->data = ice_get_fdir_cnt_all(hw);
  228. mutex_lock(&hw->fdir_fltr_lock);
  229. list_for_each_entry(f_rule, &hw->fdir_list_head, fltr_node) {
  230. if (cnt == cmd->rule_cnt) {
  231. val = -EMSGSIZE;
  232. goto release_lock;
  233. }
  234. rule_locs[cnt] = f_rule->fltr_id;
  235. cnt++;
  236. }
  237. release_lock:
  238. mutex_unlock(&hw->fdir_fltr_lock);
  239. if (!val)
  240. cmd->rule_cnt = cnt;
  241. return val;
  242. }
  243. /**
  244. * ice_fdir_remap_entries - update the FDir entries in profile
  245. * @prof: FDir structure pointer
  246. * @tun: tunneled or non-tunneled packet
  247. * @idx: FDir entry index
  248. */
  249. static void
  250. ice_fdir_remap_entries(struct ice_fd_hw_prof *prof, int tun, int idx)
  251. {
  252. if (idx != prof->cnt && tun < ICE_FD_HW_SEG_MAX) {
  253. int i;
  254. for (i = idx; i < (prof->cnt - 1); i++) {
  255. u64 old_entry_h;
  256. old_entry_h = prof->entry_h[i + 1][tun];
  257. prof->entry_h[i][tun] = old_entry_h;
  258. prof->vsi_h[i] = prof->vsi_h[i + 1];
  259. }
  260. prof->entry_h[i][tun] = 0;
  261. prof->vsi_h[i] = 0;
  262. }
  263. }
  264. /**
  265. * ice_fdir_rem_adq_chnl - remove an ADQ channel from HW filter rules
  266. * @hw: hardware structure containing filter list
  267. * @vsi_idx: VSI handle
  268. */
  269. void ice_fdir_rem_adq_chnl(struct ice_hw *hw, u16 vsi_idx)
  270. {
  271. int status, flow;
  272. if (!hw->fdir_prof)
  273. return;
  274. for (flow = 0; flow < ICE_FLTR_PTYPE_MAX; flow++) {
  275. struct ice_fd_hw_prof *prof = hw->fdir_prof[flow];
  276. int tun, i;
  277. if (!prof || !prof->cnt)
  278. continue;
  279. for (tun = 0; tun < ICE_FD_HW_SEG_MAX; tun++) {
  280. u64 prof_id = prof->prof_id[tun];
  281. for (i = 0; i < prof->cnt; i++) {
  282. if (prof->vsi_h[i] != vsi_idx)
  283. continue;
  284. prof->entry_h[i][tun] = 0;
  285. prof->vsi_h[i] = 0;
  286. break;
  287. }
  288. /* after clearing FDir entries update the remaining */
  289. ice_fdir_remap_entries(prof, tun, i);
  290. /* find flow profile corresponding to prof_id and clear
  291. * vsi_idx from bitmap.
  292. */
  293. status = ice_flow_rem_vsi_prof(hw, vsi_idx, prof_id);
  294. if (status) {
  295. dev_err(ice_hw_to_dev(hw), "ice_flow_rem_vsi_prof() failed status=%d\n",
  296. status);
  297. }
  298. }
  299. prof->cnt--;
  300. }
  301. }
  302. /**
  303. * ice_fdir_get_hw_prof - return the ice_fd_hw_proc associated with a flow
  304. * @hw: hardware structure containing the filter list
  305. * @blk: hardware block
  306. * @flow: FDir flow type to release
  307. */
  308. static struct ice_fd_hw_prof *
  309. ice_fdir_get_hw_prof(struct ice_hw *hw, enum ice_block blk, int flow)
  310. {
  311. if (blk == ICE_BLK_FD && hw->fdir_prof)
  312. return hw->fdir_prof[flow];
  313. return NULL;
  314. }
  315. /**
  316. * ice_fdir_erase_flow_from_hw - remove a flow from the HW profile tables
  317. * @hw: hardware structure containing the filter list
  318. * @blk: hardware block
  319. * @flow: FDir flow type to release
  320. */
  321. static void
  322. ice_fdir_erase_flow_from_hw(struct ice_hw *hw, enum ice_block blk, int flow)
  323. {
  324. struct ice_fd_hw_prof *prof = ice_fdir_get_hw_prof(hw, blk, flow);
  325. int tun;
  326. if (!prof)
  327. return;
  328. for (tun = 0; tun < ICE_FD_HW_SEG_MAX; tun++) {
  329. u64 prof_id = prof->prof_id[tun];
  330. int j;
  331. for (j = 0; j < prof->cnt; j++) {
  332. u16 vsi_num;
  333. if (!prof->entry_h[j][tun] || !prof->vsi_h[j])
  334. continue;
  335. vsi_num = ice_get_hw_vsi_num(hw, prof->vsi_h[j]);
  336. ice_rem_prof_id_flow(hw, blk, vsi_num, prof_id);
  337. ice_flow_rem_entry(hw, blk, prof->entry_h[j][tun]);
  338. prof->entry_h[j][tun] = 0;
  339. }
  340. ice_flow_rem_prof(hw, blk, prof_id);
  341. }
  342. }
  343. /**
  344. * ice_fdir_rem_flow - release the ice_flow structures for a filter type
  345. * @hw: hardware structure containing the filter list
  346. * @blk: hardware block
  347. * @flow_type: FDir flow type to release
  348. */
  349. static void
  350. ice_fdir_rem_flow(struct ice_hw *hw, enum ice_block blk,
  351. enum ice_fltr_ptype flow_type)
  352. {
  353. int flow = (int)flow_type & ~FLOW_EXT;
  354. struct ice_fd_hw_prof *prof;
  355. int tun, i;
  356. prof = ice_fdir_get_hw_prof(hw, blk, flow);
  357. if (!prof)
  358. return;
  359. ice_fdir_erase_flow_from_hw(hw, blk, flow);
  360. for (i = 0; i < prof->cnt; i++)
  361. prof->vsi_h[i] = 0;
  362. for (tun = 0; tun < ICE_FD_HW_SEG_MAX; tun++) {
  363. if (!prof->fdir_seg[tun])
  364. continue;
  365. devm_kfree(ice_hw_to_dev(hw), prof->fdir_seg[tun]);
  366. prof->fdir_seg[tun] = NULL;
  367. }
  368. prof->cnt = 0;
  369. }
  370. /**
  371. * ice_fdir_release_flows - release all flows in use for later replay
  372. * @hw: pointer to HW instance
  373. */
  374. void ice_fdir_release_flows(struct ice_hw *hw)
  375. {
  376. int flow;
  377. /* release Flow Director HW table entries */
  378. for (flow = 0; flow < ICE_FLTR_PTYPE_MAX; flow++)
  379. ice_fdir_erase_flow_from_hw(hw, ICE_BLK_FD, flow);
  380. }
  381. /**
  382. * ice_fdir_replay_flows - replay HW Flow Director filter info
  383. * @hw: pointer to HW instance
  384. */
  385. void ice_fdir_replay_flows(struct ice_hw *hw)
  386. {
  387. int flow;
  388. for (flow = 0; flow < ICE_FLTR_PTYPE_MAX; flow++) {
  389. int tun;
  390. if (!hw->fdir_prof[flow] || !hw->fdir_prof[flow]->cnt)
  391. continue;
  392. for (tun = 0; tun < ICE_FD_HW_SEG_MAX; tun++) {
  393. struct ice_flow_prof *hw_prof;
  394. struct ice_fd_hw_prof *prof;
  395. int j;
  396. prof = hw->fdir_prof[flow];
  397. ice_flow_add_prof(hw, ICE_BLK_FD, ICE_FLOW_RX,
  398. prof->fdir_seg[tun], TNL_SEG_CNT(tun),
  399. false, &hw_prof);
  400. for (j = 0; j < prof->cnt; j++) {
  401. enum ice_flow_priority prio;
  402. u64 entry_h = 0;
  403. int err;
  404. prio = ICE_FLOW_PRIO_NORMAL;
  405. err = ice_flow_add_entry(hw, ICE_BLK_FD,
  406. hw_prof->id,
  407. prof->vsi_h[0],
  408. prof->vsi_h[j],
  409. prio, prof->fdir_seg,
  410. &entry_h);
  411. if (err) {
  412. dev_err(ice_hw_to_dev(hw), "Could not replay Flow Director, flow type %d\n",
  413. flow);
  414. continue;
  415. }
  416. prof->prof_id[tun] = hw_prof->id;
  417. prof->entry_h[j][tun] = entry_h;
  418. }
  419. }
  420. }
  421. }
  422. /**
  423. * ice_parse_rx_flow_user_data - deconstruct user-defined data
  424. * @fsp: pointer to ethtool Rx flow specification
  425. * @data: pointer to userdef data structure for storage
  426. *
  427. * Returns 0 on success, negative error value on failure
  428. */
  429. static int
  430. ice_parse_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
  431. struct ice_rx_flow_userdef *data)
  432. {
  433. u64 value, mask;
  434. memset(data, 0, sizeof(*data));
  435. if (!(fsp->flow_type & FLOW_EXT))
  436. return 0;
  437. value = be64_to_cpu(*((__force __be64 *)fsp->h_ext.data));
  438. mask = be64_to_cpu(*((__force __be64 *)fsp->m_ext.data));
  439. if (!mask)
  440. return 0;
  441. #define ICE_USERDEF_FLEX_WORD_M GENMASK_ULL(15, 0)
  442. #define ICE_USERDEF_FLEX_OFFS_S 16
  443. #define ICE_USERDEF_FLEX_OFFS_M GENMASK_ULL(31, ICE_USERDEF_FLEX_OFFS_S)
  444. #define ICE_USERDEF_FLEX_FLTR_M GENMASK_ULL(31, 0)
  445. /* 0x1fe is the maximum value for offsets stored in the internal
  446. * filtering tables.
  447. */
  448. #define ICE_USERDEF_FLEX_MAX_OFFS_VAL 0x1fe
  449. if (!ice_is_mask_valid(mask, ICE_USERDEF_FLEX_FLTR_M) ||
  450. value > ICE_USERDEF_FLEX_FLTR_M)
  451. return -EINVAL;
  452. data->flex_word = value & ICE_USERDEF_FLEX_WORD_M;
  453. data->flex_offset = FIELD_GET(ICE_USERDEF_FLEX_OFFS_M, value);
  454. if (data->flex_offset > ICE_USERDEF_FLEX_MAX_OFFS_VAL)
  455. return -EINVAL;
  456. data->flex_fltr = true;
  457. return 0;
  458. }
  459. /**
  460. * ice_fdir_num_avail_fltr - return the number of unused flow director filters
  461. * @hw: pointer to hardware structure
  462. * @vsi: software VSI structure
  463. *
  464. * There are 2 filter pools: guaranteed and best effort(shared). Each VSI can
  465. * use filters from either pool. The guaranteed pool is divided between VSIs.
  466. * The best effort filter pool is common to all VSIs and is a device shared
  467. * resource pool. The number of filters available to this VSI is the sum of
  468. * the VSIs guaranteed filter pool and the global available best effort
  469. * filter pool.
  470. *
  471. * Returns the number of available flow director filters to this VSI
  472. */
  473. int ice_fdir_num_avail_fltr(struct ice_hw *hw, struct ice_vsi *vsi)
  474. {
  475. u16 vsi_num = ice_get_hw_vsi_num(hw, vsi->idx);
  476. u16 num_guar;
  477. u16 num_be;
  478. /* total guaranteed filters assigned to this VSI */
  479. num_guar = vsi->num_gfltr;
  480. /* total global best effort filters */
  481. num_be = hw->func_caps.fd_fltr_best_effort;
  482. /* Subtract the number of programmed filters from the global values */
  483. switch (hw->mac_type) {
  484. case ICE_MAC_E830:
  485. num_guar -= FIELD_GET(E830_VSIQF_FD_CNT_FD_GCNT_M,
  486. rd32(hw, VSIQF_FD_CNT(vsi_num)));
  487. num_be -= FIELD_GET(E830_GLQF_FD_CNT_FD_BCNT_M,
  488. rd32(hw, GLQF_FD_CNT));
  489. break;
  490. case ICE_MAC_E810:
  491. default:
  492. num_guar -= FIELD_GET(E800_VSIQF_FD_CNT_FD_GCNT_M,
  493. rd32(hw, VSIQF_FD_CNT(vsi_num)));
  494. num_be -= FIELD_GET(E800_GLQF_FD_CNT_FD_BCNT_M,
  495. rd32(hw, GLQF_FD_CNT));
  496. }
  497. return num_guar + num_be;
  498. }
  499. /**
  500. * ice_fdir_alloc_flow_prof - allocate FDir flow profile structure(s)
  501. * @hw: HW structure containing the FDir flow profile structure(s)
  502. * @flow: flow type to allocate the flow profile for
  503. *
  504. * Allocate the fdir_prof and fdir_prof[flow] if not already created. Return 0
  505. * on success and negative on error.
  506. */
  507. static int
  508. ice_fdir_alloc_flow_prof(struct ice_hw *hw, enum ice_fltr_ptype flow)
  509. {
  510. if (!hw)
  511. return -EINVAL;
  512. if (!hw->fdir_prof) {
  513. hw->fdir_prof = devm_kcalloc(ice_hw_to_dev(hw),
  514. ICE_FLTR_PTYPE_MAX,
  515. sizeof(*hw->fdir_prof),
  516. GFP_KERNEL);
  517. if (!hw->fdir_prof)
  518. return -ENOMEM;
  519. }
  520. if (!hw->fdir_prof[flow]) {
  521. hw->fdir_prof[flow] = devm_kzalloc(ice_hw_to_dev(hw),
  522. sizeof(**hw->fdir_prof),
  523. GFP_KERNEL);
  524. if (!hw->fdir_prof[flow])
  525. return -ENOMEM;
  526. }
  527. return 0;
  528. }
  529. /**
  530. * ice_fdir_prof_vsi_idx - find or insert a vsi_idx in structure
  531. * @prof: pointer to flow director HW profile
  532. * @vsi_idx: vsi_idx to locate
  533. *
  534. * return the index of the vsi_idx. if vsi_idx is not found insert it
  535. * into the vsi_h table.
  536. */
  537. static u16
  538. ice_fdir_prof_vsi_idx(struct ice_fd_hw_prof *prof, int vsi_idx)
  539. {
  540. u16 idx = 0;
  541. for (idx = 0; idx < prof->cnt; idx++)
  542. if (prof->vsi_h[idx] == vsi_idx)
  543. return idx;
  544. if (idx == prof->cnt)
  545. prof->vsi_h[prof->cnt++] = vsi_idx;
  546. return idx;
  547. }
  548. /**
  549. * ice_fdir_set_hw_fltr_rule - Configure HW tables to generate a FDir rule
  550. * @pf: pointer to the PF structure
  551. * @seg: protocol header description pointer
  552. * @flow: filter enum
  553. * @tun: FDir segment to program
  554. */
  555. static int
  556. ice_fdir_set_hw_fltr_rule(struct ice_pf *pf, struct ice_flow_seg_info *seg,
  557. enum ice_fltr_ptype flow, enum ice_fd_hw_seg tun)
  558. {
  559. struct device *dev = ice_pf_to_dev(pf);
  560. struct ice_vsi *main_vsi, *ctrl_vsi;
  561. struct ice_flow_seg_info *old_seg;
  562. struct ice_flow_prof *prof = NULL;
  563. struct ice_fd_hw_prof *hw_prof;
  564. struct ice_hw *hw = &pf->hw;
  565. u64 entry1_h = 0;
  566. u64 entry2_h = 0;
  567. bool del_last;
  568. int err;
  569. int idx;
  570. main_vsi = ice_get_main_vsi(pf);
  571. if (!main_vsi)
  572. return -EINVAL;
  573. ctrl_vsi = ice_get_ctrl_vsi(pf);
  574. if (!ctrl_vsi)
  575. return -EINVAL;
  576. err = ice_fdir_alloc_flow_prof(hw, flow);
  577. if (err)
  578. return err;
  579. hw_prof = hw->fdir_prof[flow];
  580. old_seg = hw_prof->fdir_seg[tun];
  581. if (old_seg) {
  582. /* This flow_type already has a changed input set.
  583. * If it matches the requested input set then we are
  584. * done. Or, if it's different then it's an error.
  585. */
  586. if (!memcmp(old_seg, seg, sizeof(*seg)))
  587. return -EEXIST;
  588. /* if there are FDir filters using this flow,
  589. * then return error.
  590. */
  591. if (hw->fdir_fltr_cnt[flow]) {
  592. dev_err(dev, "Failed to add filter. Flow director filters on each port must have the same input set.\n");
  593. return -EINVAL;
  594. }
  595. if (ice_is_arfs_using_perfect_flow(hw, flow)) {
  596. dev_err(dev, "aRFS using perfect flow type %d, cannot change input set\n",
  597. flow);
  598. return -EINVAL;
  599. }
  600. /* remove HW filter definition */
  601. ice_fdir_rem_flow(hw, ICE_BLK_FD, flow);
  602. }
  603. /* Adding a profile, but there is only one header supported.
  604. * That is the final parameters are 1 header (segment), no
  605. * actions (NULL) and zero actions 0.
  606. */
  607. err = ice_flow_add_prof(hw, ICE_BLK_FD, ICE_FLOW_RX, seg,
  608. TNL_SEG_CNT(tun), false, &prof);
  609. if (err)
  610. return err;
  611. err = ice_flow_add_entry(hw, ICE_BLK_FD, prof->id, main_vsi->idx,
  612. main_vsi->idx, ICE_FLOW_PRIO_NORMAL,
  613. seg, &entry1_h);
  614. if (err)
  615. goto err_prof;
  616. err = ice_flow_add_entry(hw, ICE_BLK_FD, prof->id, main_vsi->idx,
  617. ctrl_vsi->idx, ICE_FLOW_PRIO_NORMAL,
  618. seg, &entry2_h);
  619. if (err)
  620. goto err_entry;
  621. hw_prof->fdir_seg[tun] = seg;
  622. hw_prof->prof_id[tun] = prof->id;
  623. hw_prof->entry_h[0][tun] = entry1_h;
  624. hw_prof->entry_h[1][tun] = entry2_h;
  625. hw_prof->vsi_h[0] = main_vsi->idx;
  626. hw_prof->vsi_h[1] = ctrl_vsi->idx;
  627. if (!hw_prof->cnt)
  628. hw_prof->cnt = 2;
  629. for (idx = 1; idx < ICE_CHNL_MAX_TC; idx++) {
  630. u16 vsi_idx;
  631. u16 vsi_h;
  632. if (!ice_is_adq_active(pf) || !main_vsi->tc_map_vsi[idx])
  633. continue;
  634. entry1_h = 0;
  635. vsi_h = main_vsi->tc_map_vsi[idx]->idx;
  636. err = ice_flow_add_entry(hw, ICE_BLK_FD, prof->id,
  637. main_vsi->idx, vsi_h,
  638. ICE_FLOW_PRIO_NORMAL, seg,
  639. &entry1_h);
  640. if (err) {
  641. dev_err(dev, "Could not add Channel VSI %d to flow group\n",
  642. idx);
  643. goto err_unroll;
  644. }
  645. vsi_idx = ice_fdir_prof_vsi_idx(hw_prof,
  646. main_vsi->tc_map_vsi[idx]->idx);
  647. hw_prof->entry_h[vsi_idx][tun] = entry1_h;
  648. }
  649. return 0;
  650. err_unroll:
  651. entry1_h = 0;
  652. hw_prof->fdir_seg[tun] = NULL;
  653. /* The variable del_last will be used to determine when to clean up
  654. * the VSI group data. The VSI data is not needed if there are no
  655. * segments.
  656. */
  657. del_last = true;
  658. for (idx = 0; idx < ICE_FD_HW_SEG_MAX; idx++)
  659. if (hw_prof->fdir_seg[idx]) {
  660. del_last = false;
  661. break;
  662. }
  663. for (idx = 0; idx < hw_prof->cnt; idx++) {
  664. u16 vsi_num = ice_get_hw_vsi_num(hw, hw_prof->vsi_h[idx]);
  665. if (!hw_prof->entry_h[idx][tun])
  666. continue;
  667. ice_rem_prof_id_flow(hw, ICE_BLK_FD, vsi_num, prof->id);
  668. ice_flow_rem_entry(hw, ICE_BLK_FD, hw_prof->entry_h[idx][tun]);
  669. hw_prof->entry_h[idx][tun] = 0;
  670. if (del_last)
  671. hw_prof->vsi_h[idx] = 0;
  672. }
  673. if (del_last)
  674. hw_prof->cnt = 0;
  675. err_entry:
  676. ice_rem_prof_id_flow(hw, ICE_BLK_FD,
  677. ice_get_hw_vsi_num(hw, main_vsi->idx), prof->id);
  678. ice_flow_rem_entry(hw, ICE_BLK_FD, entry1_h);
  679. err_prof:
  680. ice_flow_rem_prof(hw, ICE_BLK_FD, prof->id);
  681. dev_err(dev, "Failed to add filter. Flow director filters on each port must have the same input set.\n");
  682. return err;
  683. }
  684. /**
  685. * ice_set_init_fdir_seg
  686. * @seg: flow segment for programming
  687. * @l3_proto: ICE_FLOW_SEG_HDR_IPV4 or ICE_FLOW_SEG_HDR_IPV6
  688. * @l4_proto: ICE_FLOW_SEG_HDR_TCP or ICE_FLOW_SEG_HDR_UDP
  689. *
  690. * Set the configuration for perfect filters to the provided flow segment for
  691. * programming the HW filter. This is to be called only when initializing
  692. * filters as this function it assumes no filters exist.
  693. */
  694. static int
  695. ice_set_init_fdir_seg(struct ice_flow_seg_info *seg,
  696. enum ice_flow_seg_hdr l3_proto,
  697. enum ice_flow_seg_hdr l4_proto)
  698. {
  699. enum ice_flow_field src_addr, dst_addr, src_port, dst_port;
  700. if (!seg)
  701. return -EINVAL;
  702. if (l3_proto == ICE_FLOW_SEG_HDR_IPV4) {
  703. src_addr = ICE_FLOW_FIELD_IDX_IPV4_SA;
  704. dst_addr = ICE_FLOW_FIELD_IDX_IPV4_DA;
  705. } else if (l3_proto == ICE_FLOW_SEG_HDR_IPV6) {
  706. src_addr = ICE_FLOW_FIELD_IDX_IPV6_SA;
  707. dst_addr = ICE_FLOW_FIELD_IDX_IPV6_DA;
  708. } else {
  709. return -EINVAL;
  710. }
  711. if (l4_proto == ICE_FLOW_SEG_HDR_TCP) {
  712. src_port = ICE_FLOW_FIELD_IDX_TCP_SRC_PORT;
  713. dst_port = ICE_FLOW_FIELD_IDX_TCP_DST_PORT;
  714. } else if (l4_proto == ICE_FLOW_SEG_HDR_UDP) {
  715. src_port = ICE_FLOW_FIELD_IDX_UDP_SRC_PORT;
  716. dst_port = ICE_FLOW_FIELD_IDX_UDP_DST_PORT;
  717. } else {
  718. return -EINVAL;
  719. }
  720. ICE_FLOW_SET_HDRS(seg, l3_proto | l4_proto);
  721. /* IP source address */
  722. ice_flow_set_fld(seg, src_addr, ICE_FLOW_FLD_OFF_INVAL,
  723. ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL, false);
  724. /* IP destination address */
  725. ice_flow_set_fld(seg, dst_addr, ICE_FLOW_FLD_OFF_INVAL,
  726. ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL, false);
  727. /* Layer 4 source port */
  728. ice_flow_set_fld(seg, src_port, ICE_FLOW_FLD_OFF_INVAL,
  729. ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL, false);
  730. /* Layer 4 destination port */
  731. ice_flow_set_fld(seg, dst_port, ICE_FLOW_FLD_OFF_INVAL,
  732. ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL, false);
  733. return 0;
  734. }
  735. /**
  736. * ice_create_init_fdir_rule
  737. * @pf: PF structure
  738. * @flow: filter enum
  739. *
  740. * Return error value or 0 on success.
  741. */
  742. static int
  743. ice_create_init_fdir_rule(struct ice_pf *pf, enum ice_fltr_ptype flow)
  744. {
  745. struct ice_flow_seg_info *seg, *tun_seg;
  746. struct device *dev = ice_pf_to_dev(pf);
  747. struct ice_hw *hw = &pf->hw;
  748. int ret;
  749. /* if there is already a filter rule for kind return -EINVAL */
  750. if (hw->fdir_prof && hw->fdir_prof[flow] &&
  751. hw->fdir_prof[flow]->fdir_seg[0])
  752. return -EINVAL;
  753. seg = devm_kzalloc(dev, sizeof(*seg), GFP_KERNEL);
  754. if (!seg)
  755. return -ENOMEM;
  756. tun_seg = devm_kcalloc(dev, ICE_FD_HW_SEG_MAX, sizeof(*tun_seg),
  757. GFP_KERNEL);
  758. if (!tun_seg) {
  759. devm_kfree(dev, seg);
  760. return -ENOMEM;
  761. }
  762. if (flow == ICE_FLTR_PTYPE_NONF_IPV4_TCP)
  763. ret = ice_set_init_fdir_seg(seg, ICE_FLOW_SEG_HDR_IPV4,
  764. ICE_FLOW_SEG_HDR_TCP);
  765. else if (flow == ICE_FLTR_PTYPE_NONF_IPV4_UDP)
  766. ret = ice_set_init_fdir_seg(seg, ICE_FLOW_SEG_HDR_IPV4,
  767. ICE_FLOW_SEG_HDR_UDP);
  768. else if (flow == ICE_FLTR_PTYPE_NONF_IPV6_TCP)
  769. ret = ice_set_init_fdir_seg(seg, ICE_FLOW_SEG_HDR_IPV6,
  770. ICE_FLOW_SEG_HDR_TCP);
  771. else if (flow == ICE_FLTR_PTYPE_NONF_IPV6_UDP)
  772. ret = ice_set_init_fdir_seg(seg, ICE_FLOW_SEG_HDR_IPV6,
  773. ICE_FLOW_SEG_HDR_UDP);
  774. else
  775. ret = -EINVAL;
  776. if (ret)
  777. goto err_exit;
  778. /* add filter for outer headers */
  779. ret = ice_fdir_set_hw_fltr_rule(pf, seg, flow, ICE_FD_HW_SEG_NON_TUN);
  780. if (ret)
  781. /* could not write filter, free memory */
  782. goto err_exit;
  783. /* make tunneled filter HW entries if possible */
  784. memcpy(&tun_seg[1], seg, sizeof(*seg));
  785. ret = ice_fdir_set_hw_fltr_rule(pf, tun_seg, flow, ICE_FD_HW_SEG_TUN);
  786. if (ret)
  787. /* could not write tunnel filter, but outer header filter
  788. * exists
  789. */
  790. devm_kfree(dev, tun_seg);
  791. set_bit(flow, hw->fdir_perfect_fltr);
  792. return ret;
  793. err_exit:
  794. devm_kfree(dev, tun_seg);
  795. devm_kfree(dev, seg);
  796. return -EOPNOTSUPP;
  797. }
  798. /**
  799. * ice_set_fdir_ip4_seg
  800. * @seg: flow segment for programming
  801. * @tcp_ip4_spec: mask data from ethtool
  802. * @l4_proto: Layer 4 protocol to program
  803. * @perfect_fltr: only valid on success; returns true if perfect filter,
  804. * false if not
  805. *
  806. * Set the mask data into the flow segment to be used to program HW
  807. * table based on provided L4 protocol for IPv4
  808. */
  809. static int
  810. ice_set_fdir_ip4_seg(struct ice_flow_seg_info *seg,
  811. struct ethtool_tcpip4_spec *tcp_ip4_spec,
  812. enum ice_flow_seg_hdr l4_proto, bool *perfect_fltr)
  813. {
  814. enum ice_flow_field src_port, dst_port;
  815. /* make sure we don't have any empty rule */
  816. if (!tcp_ip4_spec->psrc && !tcp_ip4_spec->ip4src &&
  817. !tcp_ip4_spec->pdst && !tcp_ip4_spec->ip4dst)
  818. return -EINVAL;
  819. /* filtering on TOS not supported */
  820. if (tcp_ip4_spec->tos)
  821. return -EOPNOTSUPP;
  822. if (l4_proto == ICE_FLOW_SEG_HDR_TCP) {
  823. src_port = ICE_FLOW_FIELD_IDX_TCP_SRC_PORT;
  824. dst_port = ICE_FLOW_FIELD_IDX_TCP_DST_PORT;
  825. } else if (l4_proto == ICE_FLOW_SEG_HDR_UDP) {
  826. src_port = ICE_FLOW_FIELD_IDX_UDP_SRC_PORT;
  827. dst_port = ICE_FLOW_FIELD_IDX_UDP_DST_PORT;
  828. } else if (l4_proto == ICE_FLOW_SEG_HDR_SCTP) {
  829. src_port = ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT;
  830. dst_port = ICE_FLOW_FIELD_IDX_SCTP_DST_PORT;
  831. } else {
  832. return -EOPNOTSUPP;
  833. }
  834. *perfect_fltr = true;
  835. ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_IPV4 | l4_proto);
  836. /* IP source address */
  837. if (tcp_ip4_spec->ip4src == htonl(0xFFFFFFFF))
  838. ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_IPV4_SA,
  839. ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL,
  840. ICE_FLOW_FLD_OFF_INVAL, false);
  841. else if (!tcp_ip4_spec->ip4src)
  842. *perfect_fltr = false;
  843. else
  844. return -EOPNOTSUPP;
  845. /* IP destination address */
  846. if (tcp_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
  847. ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_IPV4_DA,
  848. ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL,
  849. ICE_FLOW_FLD_OFF_INVAL, false);
  850. else if (!tcp_ip4_spec->ip4dst)
  851. *perfect_fltr = false;
  852. else
  853. return -EOPNOTSUPP;
  854. /* Layer 4 source port */
  855. if (tcp_ip4_spec->psrc == htons(0xFFFF))
  856. ice_flow_set_fld(seg, src_port, ICE_FLOW_FLD_OFF_INVAL,
  857. ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL,
  858. false);
  859. else if (!tcp_ip4_spec->psrc)
  860. *perfect_fltr = false;
  861. else
  862. return -EOPNOTSUPP;
  863. /* Layer 4 destination port */
  864. if (tcp_ip4_spec->pdst == htons(0xFFFF))
  865. ice_flow_set_fld(seg, dst_port, ICE_FLOW_FLD_OFF_INVAL,
  866. ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL,
  867. false);
  868. else if (!tcp_ip4_spec->pdst)
  869. *perfect_fltr = false;
  870. else
  871. return -EOPNOTSUPP;
  872. return 0;
  873. }
  874. /**
  875. * ice_set_fdir_ip4_usr_seg
  876. * @seg: flow segment for programming
  877. * @usr_ip4_spec: ethtool userdef packet offset
  878. * @perfect_fltr: only valid on success; returns true if perfect filter,
  879. * false if not
  880. *
  881. * Set the offset data into the flow segment to be used to program HW
  882. * table for IPv4
  883. */
  884. static int
  885. ice_set_fdir_ip4_usr_seg(struct ice_flow_seg_info *seg,
  886. struct ethtool_usrip4_spec *usr_ip4_spec,
  887. bool *perfect_fltr)
  888. {
  889. /* first 4 bytes of Layer 4 header */
  890. if (usr_ip4_spec->l4_4_bytes)
  891. return -EINVAL;
  892. if (usr_ip4_spec->tos)
  893. return -EINVAL;
  894. if (usr_ip4_spec->ip_ver)
  895. return -EINVAL;
  896. /* Filtering on Layer 4 protocol not supported */
  897. if (usr_ip4_spec->proto)
  898. return -EOPNOTSUPP;
  899. /* empty rules are not valid */
  900. if (!usr_ip4_spec->ip4src && !usr_ip4_spec->ip4dst)
  901. return -EINVAL;
  902. *perfect_fltr = true;
  903. ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_IPV4);
  904. /* IP source address */
  905. if (usr_ip4_spec->ip4src == htonl(0xFFFFFFFF))
  906. ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_IPV4_SA,
  907. ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL,
  908. ICE_FLOW_FLD_OFF_INVAL, false);
  909. else if (!usr_ip4_spec->ip4src)
  910. *perfect_fltr = false;
  911. else
  912. return -EOPNOTSUPP;
  913. /* IP destination address */
  914. if (usr_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
  915. ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_IPV4_DA,
  916. ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL,
  917. ICE_FLOW_FLD_OFF_INVAL, false);
  918. else if (!usr_ip4_spec->ip4dst)
  919. *perfect_fltr = false;
  920. else
  921. return -EOPNOTSUPP;
  922. return 0;
  923. }
  924. /**
  925. * ice_set_fdir_ip6_seg
  926. * @seg: flow segment for programming
  927. * @tcp_ip6_spec: mask data from ethtool
  928. * @l4_proto: Layer 4 protocol to program
  929. * @perfect_fltr: only valid on success; returns true if perfect filter,
  930. * false if not
  931. *
  932. * Set the mask data into the flow segment to be used to program HW
  933. * table based on provided L4 protocol for IPv6
  934. */
  935. static int
  936. ice_set_fdir_ip6_seg(struct ice_flow_seg_info *seg,
  937. struct ethtool_tcpip6_spec *tcp_ip6_spec,
  938. enum ice_flow_seg_hdr l4_proto, bool *perfect_fltr)
  939. {
  940. enum ice_flow_field src_port, dst_port;
  941. /* make sure we don't have any empty rule */
  942. if (!memcmp(tcp_ip6_spec->ip6src, &zero_ipv6_addr_mask,
  943. sizeof(struct in6_addr)) &&
  944. !memcmp(tcp_ip6_spec->ip6dst, &zero_ipv6_addr_mask,
  945. sizeof(struct in6_addr)) &&
  946. !tcp_ip6_spec->psrc && !tcp_ip6_spec->pdst)
  947. return -EINVAL;
  948. /* filtering on TC not supported */
  949. if (tcp_ip6_spec->tclass)
  950. return -EOPNOTSUPP;
  951. if (l4_proto == ICE_FLOW_SEG_HDR_TCP) {
  952. src_port = ICE_FLOW_FIELD_IDX_TCP_SRC_PORT;
  953. dst_port = ICE_FLOW_FIELD_IDX_TCP_DST_PORT;
  954. } else if (l4_proto == ICE_FLOW_SEG_HDR_UDP) {
  955. src_port = ICE_FLOW_FIELD_IDX_UDP_SRC_PORT;
  956. dst_port = ICE_FLOW_FIELD_IDX_UDP_DST_PORT;
  957. } else if (l4_proto == ICE_FLOW_SEG_HDR_SCTP) {
  958. src_port = ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT;
  959. dst_port = ICE_FLOW_FIELD_IDX_SCTP_DST_PORT;
  960. } else {
  961. return -EINVAL;
  962. }
  963. *perfect_fltr = true;
  964. ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_IPV6 | l4_proto);
  965. if (!memcmp(tcp_ip6_spec->ip6src, &full_ipv6_addr_mask,
  966. sizeof(struct in6_addr)))
  967. ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_IPV6_SA,
  968. ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL,
  969. ICE_FLOW_FLD_OFF_INVAL, false);
  970. else if (!memcmp(tcp_ip6_spec->ip6src, &zero_ipv6_addr_mask,
  971. sizeof(struct in6_addr)))
  972. *perfect_fltr = false;
  973. else
  974. return -EOPNOTSUPP;
  975. if (!memcmp(tcp_ip6_spec->ip6dst, &full_ipv6_addr_mask,
  976. sizeof(struct in6_addr)))
  977. ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_IPV6_DA,
  978. ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL,
  979. ICE_FLOW_FLD_OFF_INVAL, false);
  980. else if (!memcmp(tcp_ip6_spec->ip6dst, &zero_ipv6_addr_mask,
  981. sizeof(struct in6_addr)))
  982. *perfect_fltr = false;
  983. else
  984. return -EOPNOTSUPP;
  985. /* Layer 4 source port */
  986. if (tcp_ip6_spec->psrc == htons(0xFFFF))
  987. ice_flow_set_fld(seg, src_port, ICE_FLOW_FLD_OFF_INVAL,
  988. ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL,
  989. false);
  990. else if (!tcp_ip6_spec->psrc)
  991. *perfect_fltr = false;
  992. else
  993. return -EOPNOTSUPP;
  994. /* Layer 4 destination port */
  995. if (tcp_ip6_spec->pdst == htons(0xFFFF))
  996. ice_flow_set_fld(seg, dst_port, ICE_FLOW_FLD_OFF_INVAL,
  997. ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL,
  998. false);
  999. else if (!tcp_ip6_spec->pdst)
  1000. *perfect_fltr = false;
  1001. else
  1002. return -EOPNOTSUPP;
  1003. return 0;
  1004. }
  1005. /**
  1006. * ice_set_fdir_ip6_usr_seg
  1007. * @seg: flow segment for programming
  1008. * @usr_ip6_spec: ethtool userdef packet offset
  1009. * @perfect_fltr: only valid on success; returns true if perfect filter,
  1010. * false if not
  1011. *
  1012. * Set the offset data into the flow segment to be used to program HW
  1013. * table for IPv6
  1014. */
  1015. static int
  1016. ice_set_fdir_ip6_usr_seg(struct ice_flow_seg_info *seg,
  1017. struct ethtool_usrip6_spec *usr_ip6_spec,
  1018. bool *perfect_fltr)
  1019. {
  1020. /* filtering on Layer 4 bytes not supported */
  1021. if (usr_ip6_spec->l4_4_bytes)
  1022. return -EOPNOTSUPP;
  1023. /* filtering on TC not supported */
  1024. if (usr_ip6_spec->tclass)
  1025. return -EOPNOTSUPP;
  1026. /* filtering on Layer 4 protocol not supported */
  1027. if (usr_ip6_spec->l4_proto)
  1028. return -EOPNOTSUPP;
  1029. /* empty rules are not valid */
  1030. if (!memcmp(usr_ip6_spec->ip6src, &zero_ipv6_addr_mask,
  1031. sizeof(struct in6_addr)) &&
  1032. !memcmp(usr_ip6_spec->ip6dst, &zero_ipv6_addr_mask,
  1033. sizeof(struct in6_addr)))
  1034. return -EINVAL;
  1035. *perfect_fltr = true;
  1036. ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_IPV6);
  1037. if (!memcmp(usr_ip6_spec->ip6src, &full_ipv6_addr_mask,
  1038. sizeof(struct in6_addr)))
  1039. ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_IPV6_SA,
  1040. ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL,
  1041. ICE_FLOW_FLD_OFF_INVAL, false);
  1042. else if (!memcmp(usr_ip6_spec->ip6src, &zero_ipv6_addr_mask,
  1043. sizeof(struct in6_addr)))
  1044. *perfect_fltr = false;
  1045. else
  1046. return -EOPNOTSUPP;
  1047. if (!memcmp(usr_ip6_spec->ip6dst, &full_ipv6_addr_mask,
  1048. sizeof(struct in6_addr)))
  1049. ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_IPV6_DA,
  1050. ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL,
  1051. ICE_FLOW_FLD_OFF_INVAL, false);
  1052. else if (!memcmp(usr_ip6_spec->ip6dst, &zero_ipv6_addr_mask,
  1053. sizeof(struct in6_addr)))
  1054. *perfect_fltr = false;
  1055. else
  1056. return -EOPNOTSUPP;
  1057. return 0;
  1058. }
  1059. /**
  1060. * ice_fdir_vlan_valid - validate VLAN data for Flow Director rule
  1061. * @dev: network interface device structure
  1062. * @fsp: pointer to ethtool Rx flow specification
  1063. *
  1064. * Return: true if vlan data is valid, false otherwise
  1065. */
  1066. static bool ice_fdir_vlan_valid(struct device *dev,
  1067. struct ethtool_rx_flow_spec *fsp)
  1068. {
  1069. if (fsp->m_ext.vlan_etype && !eth_type_vlan(fsp->h_ext.vlan_etype))
  1070. return false;
  1071. if (fsp->m_ext.vlan_tci && ntohs(fsp->h_ext.vlan_tci) >= VLAN_N_VID)
  1072. return false;
  1073. /* proto and vlan must have vlan-etype defined */
  1074. if (fsp->m_u.ether_spec.h_proto && fsp->m_ext.vlan_tci &&
  1075. !fsp->m_ext.vlan_etype) {
  1076. dev_warn(dev, "Filter with proto and vlan require also vlan-etype");
  1077. return false;
  1078. }
  1079. return true;
  1080. }
  1081. /**
  1082. * ice_set_ether_flow_seg - set address and protocol segments for ether flow
  1083. * @dev: network interface device structure
  1084. * @seg: flow segment for programming
  1085. * @eth_spec: mask data from ethtool
  1086. *
  1087. * Return: 0 on success and errno in case of error.
  1088. */
  1089. static int ice_set_ether_flow_seg(struct device *dev,
  1090. struct ice_flow_seg_info *seg,
  1091. struct ethhdr *eth_spec)
  1092. {
  1093. ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_ETH);
  1094. /* empty rules are not valid */
  1095. if (is_zero_ether_addr(eth_spec->h_source) &&
  1096. is_zero_ether_addr(eth_spec->h_dest) &&
  1097. !eth_spec->h_proto)
  1098. return -EINVAL;
  1099. /* Ethertype */
  1100. if (eth_spec->h_proto == htons(0xFFFF)) {
  1101. ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_ETH_TYPE,
  1102. ICE_FLOW_FLD_OFF_INVAL,
  1103. ICE_FLOW_FLD_OFF_INVAL,
  1104. ICE_FLOW_FLD_OFF_INVAL, false);
  1105. } else if (eth_spec->h_proto) {
  1106. dev_warn(dev, "Only 0x0000 or 0xffff proto mask is allowed for flow-type ether");
  1107. return -EOPNOTSUPP;
  1108. }
  1109. /* Source MAC address */
  1110. if (is_broadcast_ether_addr(eth_spec->h_source))
  1111. ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_ETH_SA,
  1112. ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL,
  1113. ICE_FLOW_FLD_OFF_INVAL, false);
  1114. else if (!is_zero_ether_addr(eth_spec->h_source))
  1115. goto err_mask;
  1116. /* Destination MAC address */
  1117. if (is_broadcast_ether_addr(eth_spec->h_dest))
  1118. ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_ETH_DA,
  1119. ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL,
  1120. ICE_FLOW_FLD_OFF_INVAL, false);
  1121. else if (!is_zero_ether_addr(eth_spec->h_dest))
  1122. goto err_mask;
  1123. return 0;
  1124. err_mask:
  1125. dev_warn(dev, "Only 00:00:00:00:00:00 or ff:ff:ff:ff:ff:ff MAC address mask is allowed for flow-type ether");
  1126. return -EOPNOTSUPP;
  1127. }
  1128. /**
  1129. * ice_set_fdir_vlan_seg - set vlan segments for ether flow
  1130. * @seg: flow segment for programming
  1131. * @ext_masks: masks for additional RX flow fields
  1132. *
  1133. * Return: 0 on success and errno in case of error.
  1134. */
  1135. static int
  1136. ice_set_fdir_vlan_seg(struct ice_flow_seg_info *seg,
  1137. struct ethtool_flow_ext *ext_masks)
  1138. {
  1139. ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_VLAN);
  1140. if (ext_masks->vlan_etype) {
  1141. if (ext_masks->vlan_etype != htons(0xFFFF))
  1142. return -EOPNOTSUPP;
  1143. ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_S_VLAN,
  1144. ICE_FLOW_FLD_OFF_INVAL,
  1145. ICE_FLOW_FLD_OFF_INVAL,
  1146. ICE_FLOW_FLD_OFF_INVAL, false);
  1147. }
  1148. if (ext_masks->vlan_tci) {
  1149. if (ext_masks->vlan_tci != htons(0xFFFF))
  1150. return -EOPNOTSUPP;
  1151. ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_C_VLAN,
  1152. ICE_FLOW_FLD_OFF_INVAL,
  1153. ICE_FLOW_FLD_OFF_INVAL,
  1154. ICE_FLOW_FLD_OFF_INVAL, false);
  1155. }
  1156. return 0;
  1157. }
  1158. /**
  1159. * ice_cfg_fdir_xtrct_seq - Configure extraction sequence for the given filter
  1160. * @pf: PF structure
  1161. * @fsp: pointer to ethtool Rx flow specification
  1162. * @user: user defined data from flow specification
  1163. *
  1164. * Returns 0 on success.
  1165. */
  1166. static int
  1167. ice_cfg_fdir_xtrct_seq(struct ice_pf *pf, struct ethtool_rx_flow_spec *fsp,
  1168. struct ice_rx_flow_userdef *user)
  1169. {
  1170. struct ice_flow_seg_info *seg, *tun_seg;
  1171. struct device *dev = ice_pf_to_dev(pf);
  1172. enum ice_fltr_ptype fltr_idx;
  1173. struct ice_hw *hw = &pf->hw;
  1174. bool perfect_filter = false;
  1175. int ret;
  1176. seg = devm_kzalloc(dev, sizeof(*seg), GFP_KERNEL);
  1177. if (!seg)
  1178. return -ENOMEM;
  1179. tun_seg = devm_kcalloc(dev, ICE_FD_HW_SEG_MAX, sizeof(*tun_seg),
  1180. GFP_KERNEL);
  1181. if (!tun_seg) {
  1182. devm_kfree(dev, seg);
  1183. return -ENOMEM;
  1184. }
  1185. switch (fsp->flow_type & ~FLOW_EXT) {
  1186. case TCP_V4_FLOW:
  1187. ret = ice_set_fdir_ip4_seg(seg, &fsp->m_u.tcp_ip4_spec,
  1188. ICE_FLOW_SEG_HDR_TCP,
  1189. &perfect_filter);
  1190. break;
  1191. case UDP_V4_FLOW:
  1192. ret = ice_set_fdir_ip4_seg(seg, &fsp->m_u.tcp_ip4_spec,
  1193. ICE_FLOW_SEG_HDR_UDP,
  1194. &perfect_filter);
  1195. break;
  1196. case SCTP_V4_FLOW:
  1197. ret = ice_set_fdir_ip4_seg(seg, &fsp->m_u.tcp_ip4_spec,
  1198. ICE_FLOW_SEG_HDR_SCTP,
  1199. &perfect_filter);
  1200. break;
  1201. case IPV4_USER_FLOW:
  1202. ret = ice_set_fdir_ip4_usr_seg(seg, &fsp->m_u.usr_ip4_spec,
  1203. &perfect_filter);
  1204. break;
  1205. case TCP_V6_FLOW:
  1206. ret = ice_set_fdir_ip6_seg(seg, &fsp->m_u.tcp_ip6_spec,
  1207. ICE_FLOW_SEG_HDR_TCP,
  1208. &perfect_filter);
  1209. break;
  1210. case UDP_V6_FLOW:
  1211. ret = ice_set_fdir_ip6_seg(seg, &fsp->m_u.tcp_ip6_spec,
  1212. ICE_FLOW_SEG_HDR_UDP,
  1213. &perfect_filter);
  1214. break;
  1215. case SCTP_V6_FLOW:
  1216. ret = ice_set_fdir_ip6_seg(seg, &fsp->m_u.tcp_ip6_spec,
  1217. ICE_FLOW_SEG_HDR_SCTP,
  1218. &perfect_filter);
  1219. break;
  1220. case IPV6_USER_FLOW:
  1221. ret = ice_set_fdir_ip6_usr_seg(seg, &fsp->m_u.usr_ip6_spec,
  1222. &perfect_filter);
  1223. break;
  1224. case ETHER_FLOW:
  1225. ret = ice_set_ether_flow_seg(dev, seg, &fsp->m_u.ether_spec);
  1226. if (!ret && (fsp->m_ext.vlan_etype || fsp->m_ext.vlan_tci)) {
  1227. if (!ice_fdir_vlan_valid(dev, fsp)) {
  1228. ret = -EINVAL;
  1229. break;
  1230. }
  1231. ret = ice_set_fdir_vlan_seg(seg, &fsp->m_ext);
  1232. }
  1233. break;
  1234. default:
  1235. ret = -EINVAL;
  1236. }
  1237. if (ret)
  1238. goto err_exit;
  1239. /* tunnel segments are shifted up one. */
  1240. memcpy(&tun_seg[1], seg, sizeof(*seg));
  1241. if (user && user->flex_fltr) {
  1242. perfect_filter = false;
  1243. ice_flow_add_fld_raw(seg, user->flex_offset,
  1244. ICE_FLTR_PRGM_FLEX_WORD_SIZE,
  1245. ICE_FLOW_FLD_OFF_INVAL,
  1246. ICE_FLOW_FLD_OFF_INVAL);
  1247. ice_flow_add_fld_raw(&tun_seg[1], user->flex_offset,
  1248. ICE_FLTR_PRGM_FLEX_WORD_SIZE,
  1249. ICE_FLOW_FLD_OFF_INVAL,
  1250. ICE_FLOW_FLD_OFF_INVAL);
  1251. }
  1252. fltr_idx = ice_ethtool_flow_to_fltr(fsp->flow_type & ~FLOW_EXT);
  1253. assign_bit(fltr_idx, hw->fdir_perfect_fltr, perfect_filter);
  1254. /* add filter for outer headers */
  1255. ret = ice_fdir_set_hw_fltr_rule(pf, seg, fltr_idx,
  1256. ICE_FD_HW_SEG_NON_TUN);
  1257. if (ret == -EEXIST) {
  1258. /* Rule already exists, free memory and count as success */
  1259. ret = 0;
  1260. goto err_exit;
  1261. } else if (ret) {
  1262. /* could not write filter, free memory */
  1263. goto err_exit;
  1264. }
  1265. /* make tunneled filter HW entries if possible */
  1266. memcpy(&tun_seg[1], seg, sizeof(*seg));
  1267. ret = ice_fdir_set_hw_fltr_rule(pf, tun_seg, fltr_idx,
  1268. ICE_FD_HW_SEG_TUN);
  1269. if (ret == -EEXIST) {
  1270. /* Rule already exists, free memory and count as success */
  1271. devm_kfree(dev, tun_seg);
  1272. ret = 0;
  1273. } else if (ret) {
  1274. /* could not write tunnel filter, but outer filter exists */
  1275. devm_kfree(dev, tun_seg);
  1276. }
  1277. return ret;
  1278. err_exit:
  1279. devm_kfree(dev, tun_seg);
  1280. devm_kfree(dev, seg);
  1281. return ret;
  1282. }
  1283. /**
  1284. * ice_update_per_q_fltr
  1285. * @vsi: ptr to VSI
  1286. * @q_index: queue index
  1287. * @inc: true to increment or false to decrement per queue filter count
  1288. *
  1289. * This function is used to keep track of per queue sideband filters
  1290. */
  1291. static void ice_update_per_q_fltr(struct ice_vsi *vsi, u32 q_index, bool inc)
  1292. {
  1293. struct ice_rx_ring *rx_ring;
  1294. if (!vsi->num_rxq || q_index >= vsi->num_rxq)
  1295. return;
  1296. rx_ring = vsi->rx_rings[q_index];
  1297. if (!rx_ring || !rx_ring->ch)
  1298. return;
  1299. if (inc)
  1300. atomic_inc(&rx_ring->ch->num_sb_fltr);
  1301. else
  1302. atomic_dec_if_positive(&rx_ring->ch->num_sb_fltr);
  1303. }
  1304. /**
  1305. * ice_fdir_write_fltr - send a flow director filter to the hardware
  1306. * @pf: PF data structure
  1307. * @input: filter structure
  1308. * @add: true adds filter and false removed filter
  1309. * @is_tun: true adds inner filter on tunnel and false outer headers
  1310. *
  1311. * returns 0 on success and negative value on error
  1312. */
  1313. int
  1314. ice_fdir_write_fltr(struct ice_pf *pf, struct ice_fdir_fltr *input, bool add,
  1315. bool is_tun)
  1316. {
  1317. struct device *dev = ice_pf_to_dev(pf);
  1318. struct ice_hw *hw = &pf->hw;
  1319. struct ice_fltr_desc desc;
  1320. struct ice_vsi *ctrl_vsi;
  1321. u8 *pkt, *frag_pkt;
  1322. bool has_frag;
  1323. int err;
  1324. ctrl_vsi = ice_get_ctrl_vsi(pf);
  1325. if (!ctrl_vsi)
  1326. return -EINVAL;
  1327. pkt = devm_kzalloc(dev, ICE_FDIR_MAX_RAW_PKT_SIZE, GFP_KERNEL);
  1328. if (!pkt)
  1329. return -ENOMEM;
  1330. frag_pkt = devm_kzalloc(dev, ICE_FDIR_MAX_RAW_PKT_SIZE, GFP_KERNEL);
  1331. if (!frag_pkt) {
  1332. err = -ENOMEM;
  1333. goto err_free;
  1334. }
  1335. ice_fdir_get_prgm_desc(hw, input, &desc, add);
  1336. err = ice_fdir_get_gen_prgm_pkt(hw, input, pkt, false, is_tun);
  1337. if (err)
  1338. goto err_free_all;
  1339. err = ice_prgm_fdir_fltr(ctrl_vsi, &desc, pkt);
  1340. if (err)
  1341. goto err_free_all;
  1342. /* repeat for fragment packet */
  1343. has_frag = ice_fdir_has_frag(input->flow_type);
  1344. if (has_frag) {
  1345. /* does not return error */
  1346. ice_fdir_get_prgm_desc(hw, input, &desc, add);
  1347. err = ice_fdir_get_gen_prgm_pkt(hw, input, frag_pkt, true,
  1348. is_tun);
  1349. if (err)
  1350. goto err_frag;
  1351. err = ice_prgm_fdir_fltr(ctrl_vsi, &desc, frag_pkt);
  1352. if (err)
  1353. goto err_frag;
  1354. } else {
  1355. devm_kfree(dev, frag_pkt);
  1356. }
  1357. return 0;
  1358. err_free_all:
  1359. devm_kfree(dev, frag_pkt);
  1360. err_free:
  1361. devm_kfree(dev, pkt);
  1362. return err;
  1363. err_frag:
  1364. devm_kfree(dev, frag_pkt);
  1365. return err;
  1366. }
  1367. /**
  1368. * ice_fdir_write_all_fltr - send a flow director filter to the hardware
  1369. * @pf: PF data structure
  1370. * @input: filter structure
  1371. * @add: true adds filter and false removed filter
  1372. *
  1373. * returns 0 on success and negative value on error
  1374. */
  1375. static int
  1376. ice_fdir_write_all_fltr(struct ice_pf *pf, struct ice_fdir_fltr *input,
  1377. bool add)
  1378. {
  1379. u16 port_num;
  1380. int tun;
  1381. for (tun = 0; tun < ICE_FD_HW_SEG_MAX; tun++) {
  1382. bool is_tun = tun == ICE_FD_HW_SEG_TUN;
  1383. int err;
  1384. if (is_tun && !ice_get_open_tunnel_port(&pf->hw, &port_num, TNL_ALL))
  1385. continue;
  1386. err = ice_fdir_write_fltr(pf, input, add, is_tun);
  1387. if (err)
  1388. return err;
  1389. }
  1390. return 0;
  1391. }
  1392. /**
  1393. * ice_fdir_replay_fltrs - replay filters from the HW filter list
  1394. * @pf: board private structure
  1395. */
  1396. void ice_fdir_replay_fltrs(struct ice_pf *pf)
  1397. {
  1398. struct ice_fdir_fltr *f_rule;
  1399. struct ice_hw *hw = &pf->hw;
  1400. list_for_each_entry(f_rule, &hw->fdir_list_head, fltr_node) {
  1401. int err = ice_fdir_write_all_fltr(pf, f_rule, true);
  1402. if (err)
  1403. dev_dbg(ice_pf_to_dev(pf), "Flow Director error %d, could not reprogram filter %d\n",
  1404. err, f_rule->fltr_id);
  1405. }
  1406. }
  1407. /**
  1408. * ice_fdir_create_dflt_rules - create default perfect filters
  1409. * @pf: PF data structure
  1410. *
  1411. * Returns 0 for success or error.
  1412. */
  1413. int ice_fdir_create_dflt_rules(struct ice_pf *pf)
  1414. {
  1415. int err;
  1416. /* Create perfect TCP and UDP rules in hardware. */
  1417. err = ice_create_init_fdir_rule(pf, ICE_FLTR_PTYPE_NONF_IPV4_TCP);
  1418. if (err)
  1419. return err;
  1420. err = ice_create_init_fdir_rule(pf, ICE_FLTR_PTYPE_NONF_IPV4_UDP);
  1421. if (err)
  1422. return err;
  1423. err = ice_create_init_fdir_rule(pf, ICE_FLTR_PTYPE_NONF_IPV6_TCP);
  1424. if (err)
  1425. return err;
  1426. err = ice_create_init_fdir_rule(pf, ICE_FLTR_PTYPE_NONF_IPV6_UDP);
  1427. return err;
  1428. }
  1429. /**
  1430. * ice_fdir_del_all_fltrs - Delete all flow director filters
  1431. * @vsi: the VSI being changed
  1432. *
  1433. * This function needs to be called while holding hw->fdir_fltr_lock
  1434. */
  1435. void ice_fdir_del_all_fltrs(struct ice_vsi *vsi)
  1436. {
  1437. struct ice_fdir_fltr *f_rule, *tmp;
  1438. struct ice_pf *pf = vsi->back;
  1439. struct ice_hw *hw = &pf->hw;
  1440. list_for_each_entry_safe(f_rule, tmp, &hw->fdir_list_head, fltr_node) {
  1441. ice_fdir_write_all_fltr(pf, f_rule, false);
  1442. ice_fdir_update_cntrs(hw, f_rule->flow_type, false);
  1443. list_del(&f_rule->fltr_node);
  1444. devm_kfree(ice_pf_to_dev(pf), f_rule);
  1445. }
  1446. }
  1447. /**
  1448. * ice_vsi_manage_fdir - turn on/off flow director
  1449. * @vsi: the VSI being changed
  1450. * @ena: boolean value indicating if this is an enable or disable request
  1451. */
  1452. void ice_vsi_manage_fdir(struct ice_vsi *vsi, bool ena)
  1453. {
  1454. struct ice_pf *pf = vsi->back;
  1455. struct ice_hw *hw = &pf->hw;
  1456. enum ice_fltr_ptype flow;
  1457. if (ena) {
  1458. set_bit(ICE_FLAG_FD_ENA, pf->flags);
  1459. ice_fdir_create_dflt_rules(pf);
  1460. return;
  1461. }
  1462. mutex_lock(&hw->fdir_fltr_lock);
  1463. if (!test_and_clear_bit(ICE_FLAG_FD_ENA, pf->flags))
  1464. goto release_lock;
  1465. ice_fdir_del_all_fltrs(vsi);
  1466. if (hw->fdir_prof)
  1467. for (flow = ICE_FLTR_PTYPE_NONF_NONE; flow < ICE_FLTR_PTYPE_MAX;
  1468. flow++)
  1469. if (hw->fdir_prof[flow])
  1470. ice_fdir_rem_flow(hw, ICE_BLK_FD, flow);
  1471. release_lock:
  1472. mutex_unlock(&hw->fdir_fltr_lock);
  1473. }
  1474. /**
  1475. * ice_fdir_do_rem_flow - delete flow and possibly add perfect flow
  1476. * @pf: PF structure
  1477. * @flow_type: FDir flow type to release
  1478. */
  1479. static void
  1480. ice_fdir_do_rem_flow(struct ice_pf *pf, enum ice_fltr_ptype flow_type)
  1481. {
  1482. struct ice_hw *hw = &pf->hw;
  1483. bool need_perfect = false;
  1484. if (flow_type == ICE_FLTR_PTYPE_NONF_IPV4_TCP ||
  1485. flow_type == ICE_FLTR_PTYPE_NONF_IPV4_UDP ||
  1486. flow_type == ICE_FLTR_PTYPE_NONF_IPV6_TCP ||
  1487. flow_type == ICE_FLTR_PTYPE_NONF_IPV6_UDP)
  1488. need_perfect = true;
  1489. if (need_perfect && test_bit(flow_type, hw->fdir_perfect_fltr))
  1490. return;
  1491. ice_fdir_rem_flow(hw, ICE_BLK_FD, flow_type);
  1492. if (need_perfect)
  1493. ice_create_init_fdir_rule(pf, flow_type);
  1494. }
  1495. /**
  1496. * ice_fdir_update_list_entry - add or delete a filter from the filter list
  1497. * @pf: PF structure
  1498. * @input: filter structure
  1499. * @fltr_idx: ethtool index of filter to modify
  1500. *
  1501. * returns 0 on success and negative on errors
  1502. */
  1503. static int
  1504. ice_fdir_update_list_entry(struct ice_pf *pf, struct ice_fdir_fltr *input,
  1505. int fltr_idx)
  1506. {
  1507. struct ice_fdir_fltr *old_fltr;
  1508. struct ice_hw *hw = &pf->hw;
  1509. struct ice_vsi *vsi;
  1510. int err = -ENOENT;
  1511. /* Do not update filters during reset */
  1512. if (ice_is_reset_in_progress(pf->state))
  1513. return -EBUSY;
  1514. vsi = ice_get_main_vsi(pf);
  1515. if (!vsi)
  1516. return -EINVAL;
  1517. old_fltr = ice_fdir_find_fltr_by_idx(hw, fltr_idx);
  1518. if (old_fltr) {
  1519. err = ice_fdir_write_all_fltr(pf, old_fltr, false);
  1520. if (err)
  1521. return err;
  1522. ice_fdir_update_cntrs(hw, old_fltr->flow_type, false);
  1523. /* update sb-filters count, specific to ring->channel */
  1524. ice_update_per_q_fltr(vsi, old_fltr->orig_q_index, false);
  1525. if (!input && !hw->fdir_fltr_cnt[old_fltr->flow_type])
  1526. /* we just deleted the last filter of flow_type so we
  1527. * should also delete the HW filter info.
  1528. */
  1529. ice_fdir_do_rem_flow(pf, old_fltr->flow_type);
  1530. list_del(&old_fltr->fltr_node);
  1531. devm_kfree(ice_hw_to_dev(hw), old_fltr);
  1532. }
  1533. if (!input)
  1534. return err;
  1535. ice_fdir_list_add_fltr(hw, input);
  1536. /* update sb-filters count, specific to ring->channel */
  1537. ice_update_per_q_fltr(vsi, input->orig_q_index, true);
  1538. ice_fdir_update_cntrs(hw, input->flow_type, true);
  1539. return 0;
  1540. }
  1541. /**
  1542. * ice_del_fdir_ethtool - delete Flow Director filter
  1543. * @vsi: pointer to target VSI
  1544. * @cmd: command to add or delete Flow Director filter
  1545. *
  1546. * Returns 0 on success and negative values for failure
  1547. */
  1548. int ice_del_fdir_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd)
  1549. {
  1550. struct ethtool_rx_flow_spec *fsp =
  1551. (struct ethtool_rx_flow_spec *)&cmd->fs;
  1552. struct ice_pf *pf = vsi->back;
  1553. struct ice_hw *hw = &pf->hw;
  1554. int val;
  1555. if (!test_bit(ICE_FLAG_FD_ENA, pf->flags))
  1556. return -EOPNOTSUPP;
  1557. /* Do not delete filters during reset */
  1558. if (ice_is_reset_in_progress(pf->state)) {
  1559. dev_err(ice_pf_to_dev(pf), "Device is resetting - deleting Flow Director filters not supported during reset\n");
  1560. return -EBUSY;
  1561. }
  1562. if (test_bit(ICE_FD_FLUSH_REQ, pf->state))
  1563. return -EBUSY;
  1564. mutex_lock(&hw->fdir_fltr_lock);
  1565. val = ice_fdir_update_list_entry(pf, NULL, fsp->location);
  1566. mutex_unlock(&hw->fdir_fltr_lock);
  1567. return val;
  1568. }
  1569. /**
  1570. * ice_update_ring_dest_vsi - update dest ring and dest VSI
  1571. * @vsi: pointer to target VSI
  1572. * @dest_vsi: ptr to dest VSI index
  1573. * @ring: ptr to dest ring
  1574. *
  1575. * This function updates destination VSI and queue if user specifies
  1576. * target queue which falls in channel's (aka ADQ) queue region
  1577. */
  1578. static void
  1579. ice_update_ring_dest_vsi(struct ice_vsi *vsi, u16 *dest_vsi, u32 *ring)
  1580. {
  1581. struct ice_channel *ch;
  1582. list_for_each_entry(ch, &vsi->ch_list, list) {
  1583. if (!ch->ch_vsi)
  1584. continue;
  1585. /* make sure to locate corresponding channel based on "queue"
  1586. * specified
  1587. */
  1588. if ((*ring < ch->base_q) ||
  1589. (*ring >= (ch->base_q + ch->num_rxq)))
  1590. continue;
  1591. /* update the dest_vsi based on channel */
  1592. *dest_vsi = ch->ch_vsi->idx;
  1593. /* update the "ring" to be correct based on channel */
  1594. *ring -= ch->base_q;
  1595. }
  1596. }
  1597. /**
  1598. * ice_set_fdir_input_set - Set the input set for Flow Director
  1599. * @vsi: pointer to target VSI
  1600. * @fsp: pointer to ethtool Rx flow specification
  1601. * @input: filter structure
  1602. */
  1603. static int
  1604. ice_set_fdir_input_set(struct ice_vsi *vsi, struct ethtool_rx_flow_spec *fsp,
  1605. struct ice_fdir_fltr *input)
  1606. {
  1607. s16 q_index = ICE_FDIR_NO_QUEUE_IDX;
  1608. u16 orig_q_index = 0;
  1609. struct ice_pf *pf;
  1610. struct ice_hw *hw;
  1611. int flow_type;
  1612. u16 dest_vsi;
  1613. u8 dest_ctl;
  1614. if (!vsi || !fsp || !input)
  1615. return -EINVAL;
  1616. pf = vsi->back;
  1617. hw = &pf->hw;
  1618. dest_vsi = vsi->idx;
  1619. if (fsp->ring_cookie == RX_CLS_FLOW_DISC) {
  1620. dest_ctl = ICE_FLTR_PRGM_DESC_DEST_DROP_PKT;
  1621. } else {
  1622. u32 ring = ethtool_get_flow_spec_ring(fsp->ring_cookie);
  1623. u8 vf = ethtool_get_flow_spec_ring_vf(fsp->ring_cookie);
  1624. if (vf) {
  1625. dev_err(ice_pf_to_dev(pf), "Failed to add filter. Flow director filters are not supported on VF queues.\n");
  1626. return -EINVAL;
  1627. }
  1628. if (ring >= vsi->num_rxq)
  1629. return -EINVAL;
  1630. orig_q_index = ring;
  1631. ice_update_ring_dest_vsi(vsi, &dest_vsi, &ring);
  1632. dest_ctl = ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QINDEX;
  1633. q_index = ring;
  1634. }
  1635. input->fltr_id = fsp->location;
  1636. input->q_index = q_index;
  1637. flow_type = fsp->flow_type & ~FLOW_EXT;
  1638. /* Record the original queue index as specified by user.
  1639. * with channel configuration 'q_index' becomes relative
  1640. * to TC (channel).
  1641. */
  1642. input->orig_q_index = orig_q_index;
  1643. input->dest_vsi = dest_vsi;
  1644. input->dest_ctl = dest_ctl;
  1645. input->fltr_status = ICE_FLTR_PRGM_DESC_FD_STATUS_FD_ID;
  1646. input->cnt_index = ICE_FD_SB_STAT_IDX(hw->fd_ctr_base);
  1647. input->flow_type = ice_ethtool_flow_to_fltr(flow_type);
  1648. if (fsp->flow_type & FLOW_EXT) {
  1649. memcpy(input->ext_data.usr_def, fsp->h_ext.data,
  1650. sizeof(input->ext_data.usr_def));
  1651. input->ext_data.vlan_type = fsp->h_ext.vlan_etype;
  1652. input->ext_data.vlan_tag = fsp->h_ext.vlan_tci;
  1653. memcpy(input->ext_mask.usr_def, fsp->m_ext.data,
  1654. sizeof(input->ext_mask.usr_def));
  1655. input->ext_mask.vlan_type = fsp->m_ext.vlan_etype;
  1656. input->ext_mask.vlan_tag = fsp->m_ext.vlan_tci;
  1657. }
  1658. switch (flow_type) {
  1659. case TCP_V4_FLOW:
  1660. case UDP_V4_FLOW:
  1661. case SCTP_V4_FLOW:
  1662. input->ip.v4.dst_port = fsp->h_u.tcp_ip4_spec.pdst;
  1663. input->ip.v4.src_port = fsp->h_u.tcp_ip4_spec.psrc;
  1664. input->ip.v4.dst_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
  1665. input->ip.v4.src_ip = fsp->h_u.tcp_ip4_spec.ip4src;
  1666. input->mask.v4.dst_port = fsp->m_u.tcp_ip4_spec.pdst;
  1667. input->mask.v4.src_port = fsp->m_u.tcp_ip4_spec.psrc;
  1668. input->mask.v4.dst_ip = fsp->m_u.tcp_ip4_spec.ip4dst;
  1669. input->mask.v4.src_ip = fsp->m_u.tcp_ip4_spec.ip4src;
  1670. break;
  1671. case IPV4_USER_FLOW:
  1672. input->ip.v4.dst_ip = fsp->h_u.usr_ip4_spec.ip4dst;
  1673. input->ip.v4.src_ip = fsp->h_u.usr_ip4_spec.ip4src;
  1674. input->ip.v4.l4_header = fsp->h_u.usr_ip4_spec.l4_4_bytes;
  1675. input->ip.v4.proto = fsp->h_u.usr_ip4_spec.proto;
  1676. input->ip.v4.ip_ver = fsp->h_u.usr_ip4_spec.ip_ver;
  1677. input->ip.v4.tos = fsp->h_u.usr_ip4_spec.tos;
  1678. input->mask.v4.dst_ip = fsp->m_u.usr_ip4_spec.ip4dst;
  1679. input->mask.v4.src_ip = fsp->m_u.usr_ip4_spec.ip4src;
  1680. input->mask.v4.l4_header = fsp->m_u.usr_ip4_spec.l4_4_bytes;
  1681. input->mask.v4.proto = fsp->m_u.usr_ip4_spec.proto;
  1682. input->mask.v4.ip_ver = fsp->m_u.usr_ip4_spec.ip_ver;
  1683. input->mask.v4.tos = fsp->m_u.usr_ip4_spec.tos;
  1684. break;
  1685. case TCP_V6_FLOW:
  1686. case UDP_V6_FLOW:
  1687. case SCTP_V6_FLOW:
  1688. memcpy(input->ip.v6.dst_ip, fsp->h_u.usr_ip6_spec.ip6dst,
  1689. sizeof(struct in6_addr));
  1690. memcpy(input->ip.v6.src_ip, fsp->h_u.usr_ip6_spec.ip6src,
  1691. sizeof(struct in6_addr));
  1692. input->ip.v6.dst_port = fsp->h_u.tcp_ip6_spec.pdst;
  1693. input->ip.v6.src_port = fsp->h_u.tcp_ip6_spec.psrc;
  1694. input->ip.v6.tc = fsp->h_u.tcp_ip6_spec.tclass;
  1695. memcpy(input->mask.v6.dst_ip, fsp->m_u.tcp_ip6_spec.ip6dst,
  1696. sizeof(struct in6_addr));
  1697. memcpy(input->mask.v6.src_ip, fsp->m_u.tcp_ip6_spec.ip6src,
  1698. sizeof(struct in6_addr));
  1699. input->mask.v6.dst_port = fsp->m_u.tcp_ip6_spec.pdst;
  1700. input->mask.v6.src_port = fsp->m_u.tcp_ip6_spec.psrc;
  1701. input->mask.v6.tc = fsp->m_u.tcp_ip6_spec.tclass;
  1702. break;
  1703. case IPV6_USER_FLOW:
  1704. memcpy(input->ip.v6.dst_ip, fsp->h_u.usr_ip6_spec.ip6dst,
  1705. sizeof(struct in6_addr));
  1706. memcpy(input->ip.v6.src_ip, fsp->h_u.usr_ip6_spec.ip6src,
  1707. sizeof(struct in6_addr));
  1708. input->ip.v6.l4_header = fsp->h_u.usr_ip6_spec.l4_4_bytes;
  1709. input->ip.v6.tc = fsp->h_u.usr_ip6_spec.tclass;
  1710. /* if no protocol requested, use IPPROTO_NONE */
  1711. if (!fsp->m_u.usr_ip6_spec.l4_proto)
  1712. input->ip.v6.proto = IPPROTO_NONE;
  1713. else
  1714. input->ip.v6.proto = fsp->h_u.usr_ip6_spec.l4_proto;
  1715. memcpy(input->mask.v6.dst_ip, fsp->m_u.usr_ip6_spec.ip6dst,
  1716. sizeof(struct in6_addr));
  1717. memcpy(input->mask.v6.src_ip, fsp->m_u.usr_ip6_spec.ip6src,
  1718. sizeof(struct in6_addr));
  1719. input->mask.v6.l4_header = fsp->m_u.usr_ip6_spec.l4_4_bytes;
  1720. input->mask.v6.tc = fsp->m_u.usr_ip6_spec.tclass;
  1721. input->mask.v6.proto = fsp->m_u.usr_ip6_spec.l4_proto;
  1722. break;
  1723. case ETHER_FLOW:
  1724. input->eth = fsp->h_u.ether_spec;
  1725. input->eth_mask = fsp->m_u.ether_spec;
  1726. break;
  1727. default:
  1728. /* not doing un-parsed flow types */
  1729. return -EINVAL;
  1730. }
  1731. return 0;
  1732. }
  1733. /**
  1734. * ice_add_fdir_ethtool - Add/Remove Flow Director filter
  1735. * @vsi: pointer to target VSI
  1736. * @cmd: command to add or delete Flow Director filter
  1737. *
  1738. * Returns 0 on success and negative values for failure
  1739. */
  1740. int ice_add_fdir_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd)
  1741. {
  1742. struct ice_rx_flow_userdef userdata;
  1743. struct ethtool_rx_flow_spec *fsp;
  1744. struct ice_fdir_fltr *input;
  1745. struct device *dev;
  1746. struct ice_pf *pf;
  1747. struct ice_hw *hw;
  1748. int fltrs_needed;
  1749. u32 max_location;
  1750. u16 tunnel_port;
  1751. int ret;
  1752. if (!vsi)
  1753. return -EINVAL;
  1754. pf = vsi->back;
  1755. hw = &pf->hw;
  1756. dev = ice_pf_to_dev(pf);
  1757. if (!test_bit(ICE_FLAG_FD_ENA, pf->flags))
  1758. return -EOPNOTSUPP;
  1759. /* Do not program filters during reset */
  1760. if (ice_is_reset_in_progress(pf->state)) {
  1761. dev_err(dev, "Device is resetting - adding Flow Director filters not supported during reset\n");
  1762. return -EBUSY;
  1763. }
  1764. fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
  1765. if (ice_parse_rx_flow_user_data(fsp, &userdata))
  1766. return -EINVAL;
  1767. if (fsp->flow_type & FLOW_MAC_EXT)
  1768. return -EINVAL;
  1769. ret = ice_cfg_fdir_xtrct_seq(pf, fsp, &userdata);
  1770. if (ret)
  1771. return ret;
  1772. max_location = ice_get_fdir_cnt_all(hw);
  1773. if (fsp->location >= max_location) {
  1774. dev_err(dev, "Failed to add filter. The number of ntuple filters or provided location exceed max %d.\n",
  1775. max_location);
  1776. return -ENOSPC;
  1777. }
  1778. /* return error if not an update and no available filters */
  1779. fltrs_needed = ice_get_open_tunnel_port(hw, &tunnel_port, TNL_ALL) ? 2 : 1;
  1780. if (!ice_fdir_find_fltr_by_idx(hw, fsp->location) &&
  1781. ice_fdir_num_avail_fltr(hw, pf->vsi[vsi->idx]) < fltrs_needed) {
  1782. dev_err(dev, "Failed to add filter. The maximum number of flow director filters has been reached.\n");
  1783. return -ENOSPC;
  1784. }
  1785. input = devm_kzalloc(dev, sizeof(*input), GFP_KERNEL);
  1786. if (!input)
  1787. return -ENOMEM;
  1788. ret = ice_set_fdir_input_set(vsi, fsp, input);
  1789. if (ret)
  1790. goto free_input;
  1791. mutex_lock(&hw->fdir_fltr_lock);
  1792. if (ice_fdir_is_dup_fltr(hw, input)) {
  1793. ret = -EINVAL;
  1794. goto release_lock;
  1795. }
  1796. if (userdata.flex_fltr) {
  1797. input->flex_fltr = true;
  1798. input->flex_word = cpu_to_be16(userdata.flex_word);
  1799. input->flex_offset = userdata.flex_offset;
  1800. }
  1801. input->cnt_ena = ICE_FXD_FLTR_QW0_STAT_ENA_PKTS;
  1802. input->fdid_prio = ICE_FXD_FLTR_QW1_FDID_PRI_THREE;
  1803. input->comp_report = ICE_FXD_FLTR_QW0_COMP_REPORT_SW_FAIL;
  1804. /* input struct is added to the HW filter list */
  1805. ret = ice_fdir_update_list_entry(pf, input, fsp->location);
  1806. if (ret)
  1807. goto release_lock;
  1808. ret = ice_fdir_write_all_fltr(pf, input, true);
  1809. if (ret)
  1810. goto remove_sw_rule;
  1811. goto release_lock;
  1812. remove_sw_rule:
  1813. ice_fdir_update_cntrs(hw, input->flow_type, false);
  1814. /* update sb-filters count, specific to ring->channel */
  1815. ice_update_per_q_fltr(vsi, input->orig_q_index, false);
  1816. list_del(&input->fltr_node);
  1817. release_lock:
  1818. mutex_unlock(&hw->fdir_fltr_lock);
  1819. free_input:
  1820. if (ret)
  1821. devm_kfree(dev, input);
  1822. return ret;
  1823. }