ice_flow.c 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright (c) 2019, Intel Corporation. */
  3. #include "ice_common.h"
  4. #include "ice_flow.h"
  5. #include <net/gre.h>
  6. /* Describe properties of a protocol header field */
  7. struct ice_flow_field_info {
  8. enum ice_flow_seg_hdr hdr;
  9. s16 off; /* Offset from start of a protocol header, in bits */
  10. u16 size; /* Size of fields in bits */
  11. u16 mask; /* 16-bit mask for field */
  12. };
  13. #define ICE_FLOW_FLD_INFO(_hdr, _offset_bytes, _size_bytes) { \
  14. .hdr = _hdr, \
  15. .off = (_offset_bytes) * BITS_PER_BYTE, \
  16. .size = (_size_bytes) * BITS_PER_BYTE, \
  17. .mask = 0, \
  18. }
  19. #define ICE_FLOW_FLD_INFO_MSK(_hdr, _offset_bytes, _size_bytes, _mask) { \
  20. .hdr = _hdr, \
  21. .off = (_offset_bytes) * BITS_PER_BYTE, \
  22. .size = (_size_bytes) * BITS_PER_BYTE, \
  23. .mask = _mask, \
  24. }
  25. /* Table containing properties of supported protocol header fields */
  26. static const
  27. struct ice_flow_field_info ice_flds_info[ICE_FLOW_FIELD_IDX_MAX] = {
  28. /* Ether */
  29. /* ICE_FLOW_FIELD_IDX_ETH_DA */
  30. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_ETH, 0, ETH_ALEN),
  31. /* ICE_FLOW_FIELD_IDX_ETH_SA */
  32. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_ETH, ETH_ALEN, ETH_ALEN),
  33. /* ICE_FLOW_FIELD_IDX_S_VLAN */
  34. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_VLAN, 12, sizeof(__be16)),
  35. /* ICE_FLOW_FIELD_IDX_C_VLAN */
  36. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_VLAN, 14, sizeof(__be16)),
  37. /* ICE_FLOW_FIELD_IDX_ETH_TYPE */
  38. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_ETH, 0, sizeof(__be16)),
  39. /* IPv4 / IPv6 */
  40. /* ICE_FLOW_FIELD_IDX_IPV4_DSCP */
  41. ICE_FLOW_FLD_INFO_MSK(ICE_FLOW_SEG_HDR_IPV4, 0, 1, 0x00fc),
  42. /* ICE_FLOW_FIELD_IDX_IPV6_DSCP */
  43. ICE_FLOW_FLD_INFO_MSK(ICE_FLOW_SEG_HDR_IPV6, 0, 1, 0x0ff0),
  44. /* ICE_FLOW_FIELD_IDX_IPV4_TTL */
  45. ICE_FLOW_FLD_INFO_MSK(ICE_FLOW_SEG_HDR_NONE, 8, 1, 0xff00),
  46. /* ICE_FLOW_FIELD_IDX_IPV4_PROT */
  47. ICE_FLOW_FLD_INFO_MSK(ICE_FLOW_SEG_HDR_NONE, 8, 1, 0x00ff),
  48. /* ICE_FLOW_FIELD_IDX_IPV6_TTL */
  49. ICE_FLOW_FLD_INFO_MSK(ICE_FLOW_SEG_HDR_NONE, 6, 1, 0x00ff),
  50. /* ICE_FLOW_FIELD_IDX_IPV6_PROT */
  51. ICE_FLOW_FLD_INFO_MSK(ICE_FLOW_SEG_HDR_NONE, 6, 1, 0xff00),
  52. /* ICE_FLOW_FIELD_IDX_IPV4_SA */
  53. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_IPV4, 12, sizeof(struct in_addr)),
  54. /* ICE_FLOW_FIELD_IDX_IPV4_DA */
  55. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_IPV4, 16, sizeof(struct in_addr)),
  56. /* ICE_FLOW_FIELD_IDX_IPV6_SA */
  57. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_IPV6, 8, sizeof(struct in6_addr)),
  58. /* ICE_FLOW_FIELD_IDX_IPV6_DA */
  59. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_IPV6, 24, sizeof(struct in6_addr)),
  60. /* Transport */
  61. /* ICE_FLOW_FIELD_IDX_TCP_SRC_PORT */
  62. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_TCP, 0, sizeof(__be16)),
  63. /* ICE_FLOW_FIELD_IDX_TCP_DST_PORT */
  64. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_TCP, 2, sizeof(__be16)),
  65. /* ICE_FLOW_FIELD_IDX_UDP_SRC_PORT */
  66. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_UDP, 0, sizeof(__be16)),
  67. /* ICE_FLOW_FIELD_IDX_UDP_DST_PORT */
  68. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_UDP, 2, sizeof(__be16)),
  69. /* ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT */
  70. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_SCTP, 0, sizeof(__be16)),
  71. /* ICE_FLOW_FIELD_IDX_SCTP_DST_PORT */
  72. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_SCTP, 2, sizeof(__be16)),
  73. /* ICE_FLOW_FIELD_IDX_TCP_FLAGS */
  74. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_TCP, 13, 1),
  75. /* ARP */
  76. /* ICE_FLOW_FIELD_IDX_ARP_SIP */
  77. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_ARP, 14, sizeof(struct in_addr)),
  78. /* ICE_FLOW_FIELD_IDX_ARP_DIP */
  79. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_ARP, 24, sizeof(struct in_addr)),
  80. /* ICE_FLOW_FIELD_IDX_ARP_SHA */
  81. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_ARP, 8, ETH_ALEN),
  82. /* ICE_FLOW_FIELD_IDX_ARP_DHA */
  83. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_ARP, 18, ETH_ALEN),
  84. /* ICE_FLOW_FIELD_IDX_ARP_OP */
  85. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_ARP, 6, sizeof(__be16)),
  86. /* ICMP */
  87. /* ICE_FLOW_FIELD_IDX_ICMP_TYPE */
  88. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_ICMP, 0, 1),
  89. /* ICE_FLOW_FIELD_IDX_ICMP_CODE */
  90. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_ICMP, 1, 1),
  91. /* GRE */
  92. /* ICE_FLOW_FIELD_IDX_GRE_KEYID */
  93. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_GRE, 12,
  94. sizeof_field(struct gre_full_hdr, key)),
  95. /* GTP */
  96. /* ICE_FLOW_FIELD_IDX_GTPC_TEID */
  97. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_GTPC_TEID, 12, sizeof(__be32)),
  98. /* ICE_FLOW_FIELD_IDX_GTPU_IP_TEID */
  99. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_GTPU_IP, 12, sizeof(__be32)),
  100. /* ICE_FLOW_FIELD_IDX_GTPU_EH_TEID */
  101. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_GTPU_EH, 12, sizeof(__be32)),
  102. /* ICE_FLOW_FIELD_IDX_GTPU_EH_QFI */
  103. ICE_FLOW_FLD_INFO_MSK(ICE_FLOW_SEG_HDR_GTPU_EH, 22, sizeof(__be16),
  104. 0x3f00),
  105. /* ICE_FLOW_FIELD_IDX_GTPU_UP_TEID */
  106. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_GTPU_UP, 12, sizeof(__be32)),
  107. /* ICE_FLOW_FIELD_IDX_GTPU_DWN_TEID */
  108. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_GTPU_DWN, 12, sizeof(__be32)),
  109. /* PPPoE */
  110. /* ICE_FLOW_FIELD_IDX_PPPOE_SESS_ID */
  111. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_PPPOE, 2, sizeof(__be16)),
  112. /* PFCP */
  113. /* ICE_FLOW_FIELD_IDX_PFCP_SEID */
  114. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_PFCP_SESSION, 12, sizeof(__be64)),
  115. /* L2TPv3 */
  116. /* ICE_FLOW_FIELD_IDX_L2TPV3_SESS_ID */
  117. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_L2TPV3, 0, sizeof(__be32)),
  118. /* ESP */
  119. /* ICE_FLOW_FIELD_IDX_ESP_SPI */
  120. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_ESP, 0, sizeof(__be32)),
  121. /* AH */
  122. /* ICE_FLOW_FIELD_IDX_AH_SPI */
  123. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_AH, 4, sizeof(__be32)),
  124. /* NAT_T_ESP */
  125. /* ICE_FLOW_FIELD_IDX_NAT_T_ESP_SPI */
  126. ICE_FLOW_FLD_INFO(ICE_FLOW_SEG_HDR_NAT_T_ESP, 8, sizeof(__be32)),
  127. };
  128. /* Bitmaps indicating relevant packet types for a particular protocol header
  129. *
  130. * Packet types for packets with an Outer/First/Single MAC header
  131. */
  132. static const u32 ice_ptypes_mac_ofos[] = {
  133. 0xFDC00846, 0xBFBF7F7E, 0xF70001DF, 0xFEFDFDFB,
  134. 0x0000077E, 0x00000000, 0x00000000, 0x00000000,
  135. 0x00400000, 0x03FFF000, 0x7FFFFFE0, 0x00000000,
  136. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  137. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  138. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  139. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  140. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  141. };
  142. /* Packet types for packets with an Innermost/Last MAC VLAN header */
  143. static const u32 ice_ptypes_macvlan_il[] = {
  144. 0x00000000, 0xBC000000, 0x000001DF, 0xF0000000,
  145. 0x0000077E, 0x00000000, 0x00000000, 0x00000000,
  146. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  147. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  148. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  149. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  150. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  151. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  152. };
  153. /* Packet types for packets with an Outer/First/Single IPv4 header, does NOT
  154. * include IPv4 other PTYPEs
  155. */
  156. static const u32 ice_ptypes_ipv4_ofos[] = {
  157. 0x1DC00000, 0x04000800, 0x00000000, 0x00000000,
  158. 0x00000000, 0x00000155, 0x00000000, 0x00000000,
  159. 0x00000000, 0x000FC000, 0x00000000, 0x00000000,
  160. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  161. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  162. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  163. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  164. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  165. };
  166. /* Packet types for packets with an Outer/First/Single IPv4 header, includes
  167. * IPv4 other PTYPEs
  168. */
  169. static const u32 ice_ptypes_ipv4_ofos_all[] = {
  170. 0x1DC00000, 0x04000800, 0x00000000, 0x00000000,
  171. 0x00000000, 0x00000155, 0x00000000, 0x00000000,
  172. 0x00000000, 0x000FC000, 0x83E0F800, 0x00000101,
  173. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  174. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  175. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  176. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  177. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  178. };
  179. /* Packet types for packets with an Innermost/Last IPv4 header */
  180. static const u32 ice_ptypes_ipv4_il[] = {
  181. 0xE0000000, 0xB807700E, 0x80000003, 0xE01DC03B,
  182. 0x0000000E, 0x00000000, 0x00000000, 0x00000000,
  183. 0x00000000, 0x00000000, 0x001FF800, 0x00000000,
  184. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  185. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  186. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  187. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  188. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  189. };
  190. /* Packet types for packets with an Outer/First/Single IPv6 header, does NOT
  191. * include IPv6 other PTYPEs
  192. */
  193. static const u32 ice_ptypes_ipv6_ofos[] = {
  194. 0x00000000, 0x00000000, 0x77000000, 0x10002000,
  195. 0x00000000, 0x000002AA, 0x00000000, 0x00000000,
  196. 0x00000000, 0x03F00000, 0x00000000, 0x00000000,
  197. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  198. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  199. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  200. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  201. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  202. };
  203. /* Packet types for packets with an Outer/First/Single IPv6 header, includes
  204. * IPv6 other PTYPEs
  205. */
  206. static const u32 ice_ptypes_ipv6_ofos_all[] = {
  207. 0x00000000, 0x00000000, 0x77000000, 0x10002000,
  208. 0x00000000, 0x000002AA, 0x00000000, 0x00000000,
  209. 0x00080F00, 0x03F00000, 0x7C1F0000, 0x00000206,
  210. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  211. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  212. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  213. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  214. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  215. };
  216. /* Packet types for packets with an Innermost/Last IPv6 header */
  217. static const u32 ice_ptypes_ipv6_il[] = {
  218. 0x00000000, 0x03B80770, 0x000001DC, 0x0EE00000,
  219. 0x00000770, 0x00000000, 0x00000000, 0x00000000,
  220. 0x00000000, 0x00000000, 0x7FE00000, 0x00000000,
  221. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  222. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  223. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  224. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  225. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  226. };
  227. /* Packet types for packets with an Outer/First/Single IPv4 header - no L4 */
  228. static const u32 ice_ptypes_ipv4_ofos_no_l4[] = {
  229. 0x10C00000, 0x04000800, 0x00000000, 0x00000000,
  230. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  231. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  232. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  233. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  234. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  235. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  236. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  237. };
  238. /* Packet types for packets with an Outermost/First ARP header */
  239. static const u32 ice_ptypes_arp_of[] = {
  240. 0x00000800, 0x00000000, 0x00000000, 0x00000000,
  241. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  242. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  243. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  244. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  245. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  246. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  247. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  248. };
  249. /* Packet types for packets with an Innermost/Last IPv4 header - no L4 */
  250. static const u32 ice_ptypes_ipv4_il_no_l4[] = {
  251. 0x60000000, 0x18043008, 0x80000002, 0x6010c021,
  252. 0x00000008, 0x00000000, 0x00000000, 0x00000000,
  253. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  254. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  255. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  256. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  257. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  258. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  259. };
  260. /* Packet types for packets with an Outer/First/Single IPv6 header - no L4 */
  261. static const u32 ice_ptypes_ipv6_ofos_no_l4[] = {
  262. 0x00000000, 0x00000000, 0x43000000, 0x10002000,
  263. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  264. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  265. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  266. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  267. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  268. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  269. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  270. };
  271. /* Packet types for packets with an Innermost/Last IPv6 header - no L4 */
  272. static const u32 ice_ptypes_ipv6_il_no_l4[] = {
  273. 0x00000000, 0x02180430, 0x0000010c, 0x086010c0,
  274. 0x00000430, 0x00000000, 0x00000000, 0x00000000,
  275. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  276. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  277. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  278. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  279. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  280. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  281. };
  282. /* UDP Packet types for non-tunneled packets or tunneled
  283. * packets with inner UDP.
  284. */
  285. static const u32 ice_ptypes_udp_il[] = {
  286. 0x81000000, 0x20204040, 0x04000010, 0x80810102,
  287. 0x00000040, 0x00000000, 0x00000000, 0x00000000,
  288. 0x00000000, 0x00410000, 0x90842000, 0x00000007,
  289. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  290. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  291. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  292. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  293. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  294. };
  295. /* Packet types for packets with an Innermost/Last TCP header */
  296. static const u32 ice_ptypes_tcp_il[] = {
  297. 0x04000000, 0x80810102, 0x10000040, 0x02040408,
  298. 0x00000102, 0x00000000, 0x00000000, 0x00000000,
  299. 0x00000000, 0x00820000, 0x21084000, 0x00000000,
  300. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  301. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  302. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  303. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  304. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  305. };
  306. /* Packet types for packets with an Innermost/Last SCTP header */
  307. static const u32 ice_ptypes_sctp_il[] = {
  308. 0x08000000, 0x01020204, 0x20000081, 0x04080810,
  309. 0x00000204, 0x00000000, 0x00000000, 0x00000000,
  310. 0x00000000, 0x01040000, 0x00000000, 0x00000000,
  311. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  312. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  313. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  314. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  315. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  316. };
  317. /* Packet types for packets with an Outermost/First ICMP header */
  318. static const u32 ice_ptypes_icmp_of[] = {
  319. 0x10000000, 0x00000000, 0x00000000, 0x00000000,
  320. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  321. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  322. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  323. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  324. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  325. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  326. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  327. };
  328. /* Packet types for packets with an Innermost/Last ICMP header */
  329. static const u32 ice_ptypes_icmp_il[] = {
  330. 0x00000000, 0x02040408, 0x40000102, 0x08101020,
  331. 0x00000408, 0x00000000, 0x00000000, 0x00000000,
  332. 0x00000000, 0x00000000, 0x42108000, 0x00000000,
  333. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  334. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  335. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  336. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  337. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  338. };
  339. /* Packet types for packets with an Outermost/First GRE header */
  340. static const u32 ice_ptypes_gre_of[] = {
  341. 0x00000000, 0xBFBF7800, 0x000001DF, 0xFEFDE000,
  342. 0x0000017E, 0x00000000, 0x00000000, 0x00000000,
  343. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  344. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  345. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  346. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  347. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  348. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  349. };
  350. /* Packet types for packets with an Innermost/Last MAC header */
  351. static const u32 ice_ptypes_mac_il[] = {
  352. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  353. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  354. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  355. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  356. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  357. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  358. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  359. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  360. };
  361. /* Packet types for GTPC */
  362. static const u32 ice_ptypes_gtpc[] = {
  363. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  364. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  365. 0x00000000, 0x00000000, 0x00000180, 0x00000000,
  366. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  367. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  368. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  369. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  370. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  371. };
  372. /* Packet types for GTPC with TEID */
  373. static const u32 ice_ptypes_gtpc_tid[] = {
  374. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  375. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  376. 0x00000000, 0x00000000, 0x00000060, 0x00000000,
  377. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  378. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  379. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  380. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  381. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  382. };
  383. /* Packet types for GTPU */
  384. static const struct ice_ptype_attributes ice_attr_gtpu_session[] = {
  385. { ICE_MAC_IPV4_GTPU_IPV4_FRAG, ICE_PTYPE_ATTR_GTP_SESSION },
  386. { ICE_MAC_IPV4_GTPU_IPV4_PAY, ICE_PTYPE_ATTR_GTP_SESSION },
  387. { ICE_MAC_IPV4_GTPU_IPV4_UDP_PAY, ICE_PTYPE_ATTR_GTP_SESSION },
  388. { ICE_MAC_IPV4_GTPU_IPV4_TCP, ICE_PTYPE_ATTR_GTP_SESSION },
  389. { ICE_MAC_IPV4_GTPU_IPV4_ICMP, ICE_PTYPE_ATTR_GTP_SESSION },
  390. { ICE_MAC_IPV6_GTPU_IPV4_FRAG, ICE_PTYPE_ATTR_GTP_SESSION },
  391. { ICE_MAC_IPV6_GTPU_IPV4_PAY, ICE_PTYPE_ATTR_GTP_SESSION },
  392. { ICE_MAC_IPV6_GTPU_IPV4_UDP_PAY, ICE_PTYPE_ATTR_GTP_SESSION },
  393. { ICE_MAC_IPV6_GTPU_IPV4_TCP, ICE_PTYPE_ATTR_GTP_SESSION },
  394. { ICE_MAC_IPV6_GTPU_IPV4_ICMP, ICE_PTYPE_ATTR_GTP_SESSION },
  395. { ICE_MAC_IPV4_GTPU_IPV6_FRAG, ICE_PTYPE_ATTR_GTP_SESSION },
  396. { ICE_MAC_IPV4_GTPU_IPV6_PAY, ICE_PTYPE_ATTR_GTP_SESSION },
  397. { ICE_MAC_IPV4_GTPU_IPV6_UDP_PAY, ICE_PTYPE_ATTR_GTP_SESSION },
  398. { ICE_MAC_IPV4_GTPU_IPV6_TCP, ICE_PTYPE_ATTR_GTP_SESSION },
  399. { ICE_MAC_IPV4_GTPU_IPV6_ICMPV6, ICE_PTYPE_ATTR_GTP_SESSION },
  400. { ICE_MAC_IPV6_GTPU_IPV6_FRAG, ICE_PTYPE_ATTR_GTP_SESSION },
  401. { ICE_MAC_IPV6_GTPU_IPV6_PAY, ICE_PTYPE_ATTR_GTP_SESSION },
  402. { ICE_MAC_IPV6_GTPU_IPV6_UDP_PAY, ICE_PTYPE_ATTR_GTP_SESSION },
  403. { ICE_MAC_IPV6_GTPU_IPV6_TCP, ICE_PTYPE_ATTR_GTP_SESSION },
  404. { ICE_MAC_IPV6_GTPU_IPV6_ICMPV6, ICE_PTYPE_ATTR_GTP_SESSION },
  405. };
  406. static const struct ice_ptype_attributes ice_attr_gtpu_eh[] = {
  407. { ICE_MAC_IPV4_GTPU_IPV4_FRAG, ICE_PTYPE_ATTR_GTP_PDU_EH },
  408. { ICE_MAC_IPV4_GTPU_IPV4_PAY, ICE_PTYPE_ATTR_GTP_PDU_EH },
  409. { ICE_MAC_IPV4_GTPU_IPV4_UDP_PAY, ICE_PTYPE_ATTR_GTP_PDU_EH },
  410. { ICE_MAC_IPV4_GTPU_IPV4_TCP, ICE_PTYPE_ATTR_GTP_PDU_EH },
  411. { ICE_MAC_IPV4_GTPU_IPV4_ICMP, ICE_PTYPE_ATTR_GTP_PDU_EH },
  412. { ICE_MAC_IPV6_GTPU_IPV4_FRAG, ICE_PTYPE_ATTR_GTP_PDU_EH },
  413. { ICE_MAC_IPV6_GTPU_IPV4_PAY, ICE_PTYPE_ATTR_GTP_PDU_EH },
  414. { ICE_MAC_IPV6_GTPU_IPV4_UDP_PAY, ICE_PTYPE_ATTR_GTP_PDU_EH },
  415. { ICE_MAC_IPV6_GTPU_IPV4_TCP, ICE_PTYPE_ATTR_GTP_PDU_EH },
  416. { ICE_MAC_IPV6_GTPU_IPV4_ICMP, ICE_PTYPE_ATTR_GTP_PDU_EH },
  417. { ICE_MAC_IPV4_GTPU_IPV6_FRAG, ICE_PTYPE_ATTR_GTP_PDU_EH },
  418. { ICE_MAC_IPV4_GTPU_IPV6_PAY, ICE_PTYPE_ATTR_GTP_PDU_EH },
  419. { ICE_MAC_IPV4_GTPU_IPV6_UDP_PAY, ICE_PTYPE_ATTR_GTP_PDU_EH },
  420. { ICE_MAC_IPV4_GTPU_IPV6_TCP, ICE_PTYPE_ATTR_GTP_PDU_EH },
  421. { ICE_MAC_IPV4_GTPU_IPV6_ICMPV6, ICE_PTYPE_ATTR_GTP_PDU_EH },
  422. { ICE_MAC_IPV6_GTPU_IPV6_FRAG, ICE_PTYPE_ATTR_GTP_PDU_EH },
  423. { ICE_MAC_IPV6_GTPU_IPV6_PAY, ICE_PTYPE_ATTR_GTP_PDU_EH },
  424. { ICE_MAC_IPV6_GTPU_IPV6_UDP_PAY, ICE_PTYPE_ATTR_GTP_PDU_EH },
  425. { ICE_MAC_IPV6_GTPU_IPV6_TCP, ICE_PTYPE_ATTR_GTP_PDU_EH },
  426. { ICE_MAC_IPV6_GTPU_IPV6_ICMPV6, ICE_PTYPE_ATTR_GTP_PDU_EH },
  427. };
  428. static const struct ice_ptype_attributes ice_attr_gtpu_down[] = {
  429. { ICE_MAC_IPV4_GTPU_IPV4_FRAG, ICE_PTYPE_ATTR_GTP_DOWNLINK },
  430. { ICE_MAC_IPV4_GTPU_IPV4_PAY, ICE_PTYPE_ATTR_GTP_DOWNLINK },
  431. { ICE_MAC_IPV4_GTPU_IPV4_UDP_PAY, ICE_PTYPE_ATTR_GTP_DOWNLINK },
  432. { ICE_MAC_IPV4_GTPU_IPV4_TCP, ICE_PTYPE_ATTR_GTP_DOWNLINK },
  433. { ICE_MAC_IPV4_GTPU_IPV4_ICMP, ICE_PTYPE_ATTR_GTP_DOWNLINK },
  434. { ICE_MAC_IPV6_GTPU_IPV4_FRAG, ICE_PTYPE_ATTR_GTP_DOWNLINK },
  435. { ICE_MAC_IPV6_GTPU_IPV4_PAY, ICE_PTYPE_ATTR_GTP_DOWNLINK },
  436. { ICE_MAC_IPV6_GTPU_IPV4_UDP_PAY, ICE_PTYPE_ATTR_GTP_DOWNLINK },
  437. { ICE_MAC_IPV6_GTPU_IPV4_TCP, ICE_PTYPE_ATTR_GTP_DOWNLINK },
  438. { ICE_MAC_IPV6_GTPU_IPV4_ICMP, ICE_PTYPE_ATTR_GTP_DOWNLINK },
  439. { ICE_MAC_IPV4_GTPU_IPV6_FRAG, ICE_PTYPE_ATTR_GTP_DOWNLINK },
  440. { ICE_MAC_IPV4_GTPU_IPV6_PAY, ICE_PTYPE_ATTR_GTP_DOWNLINK },
  441. { ICE_MAC_IPV4_GTPU_IPV6_UDP_PAY, ICE_PTYPE_ATTR_GTP_DOWNLINK },
  442. { ICE_MAC_IPV4_GTPU_IPV6_TCP, ICE_PTYPE_ATTR_GTP_DOWNLINK },
  443. { ICE_MAC_IPV4_GTPU_IPV6_ICMPV6, ICE_PTYPE_ATTR_GTP_DOWNLINK },
  444. { ICE_MAC_IPV6_GTPU_IPV6_FRAG, ICE_PTYPE_ATTR_GTP_DOWNLINK },
  445. { ICE_MAC_IPV6_GTPU_IPV6_PAY, ICE_PTYPE_ATTR_GTP_DOWNLINK },
  446. { ICE_MAC_IPV6_GTPU_IPV6_UDP_PAY, ICE_PTYPE_ATTR_GTP_DOWNLINK },
  447. { ICE_MAC_IPV6_GTPU_IPV6_TCP, ICE_PTYPE_ATTR_GTP_DOWNLINK },
  448. { ICE_MAC_IPV6_GTPU_IPV6_ICMPV6, ICE_PTYPE_ATTR_GTP_DOWNLINK },
  449. };
  450. static const struct ice_ptype_attributes ice_attr_gtpu_up[] = {
  451. { ICE_MAC_IPV4_GTPU_IPV4_FRAG, ICE_PTYPE_ATTR_GTP_UPLINK },
  452. { ICE_MAC_IPV4_GTPU_IPV4_PAY, ICE_PTYPE_ATTR_GTP_UPLINK },
  453. { ICE_MAC_IPV4_GTPU_IPV4_UDP_PAY, ICE_PTYPE_ATTR_GTP_UPLINK },
  454. { ICE_MAC_IPV4_GTPU_IPV4_TCP, ICE_PTYPE_ATTR_GTP_UPLINK },
  455. { ICE_MAC_IPV4_GTPU_IPV4_ICMP, ICE_PTYPE_ATTR_GTP_UPLINK },
  456. { ICE_MAC_IPV6_GTPU_IPV4_FRAG, ICE_PTYPE_ATTR_GTP_UPLINK },
  457. { ICE_MAC_IPV6_GTPU_IPV4_PAY, ICE_PTYPE_ATTR_GTP_UPLINK },
  458. { ICE_MAC_IPV6_GTPU_IPV4_UDP_PAY, ICE_PTYPE_ATTR_GTP_UPLINK },
  459. { ICE_MAC_IPV6_GTPU_IPV4_TCP, ICE_PTYPE_ATTR_GTP_UPLINK },
  460. { ICE_MAC_IPV6_GTPU_IPV4_ICMP, ICE_PTYPE_ATTR_GTP_UPLINK },
  461. { ICE_MAC_IPV4_GTPU_IPV6_FRAG, ICE_PTYPE_ATTR_GTP_UPLINK },
  462. { ICE_MAC_IPV4_GTPU_IPV6_PAY, ICE_PTYPE_ATTR_GTP_UPLINK },
  463. { ICE_MAC_IPV4_GTPU_IPV6_UDP_PAY, ICE_PTYPE_ATTR_GTP_UPLINK },
  464. { ICE_MAC_IPV4_GTPU_IPV6_TCP, ICE_PTYPE_ATTR_GTP_UPLINK },
  465. { ICE_MAC_IPV4_GTPU_IPV6_ICMPV6, ICE_PTYPE_ATTR_GTP_UPLINK },
  466. { ICE_MAC_IPV6_GTPU_IPV6_FRAG, ICE_PTYPE_ATTR_GTP_UPLINK },
  467. { ICE_MAC_IPV6_GTPU_IPV6_PAY, ICE_PTYPE_ATTR_GTP_UPLINK },
  468. { ICE_MAC_IPV6_GTPU_IPV6_UDP_PAY, ICE_PTYPE_ATTR_GTP_UPLINK },
  469. { ICE_MAC_IPV6_GTPU_IPV6_TCP, ICE_PTYPE_ATTR_GTP_UPLINK },
  470. { ICE_MAC_IPV6_GTPU_IPV6_ICMPV6, ICE_PTYPE_ATTR_GTP_UPLINK },
  471. };
  472. static const u32 ice_ptypes_gtpu[] = {
  473. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  474. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  475. 0x00000000, 0x00000000, 0x7FFFFE00, 0x00000000,
  476. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  477. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  478. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  479. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  480. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  481. };
  482. /* Packet types for PPPoE */
  483. static const u32 ice_ptypes_pppoe[] = {
  484. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  485. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  486. 0x00000000, 0x03ffe000, 0x00000000, 0x00000000,
  487. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  488. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  489. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  490. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  491. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  492. };
  493. /* Packet types for packets with PFCP NODE header */
  494. static const u32 ice_ptypes_pfcp_node[] = {
  495. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  496. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  497. 0x00000000, 0x00000000, 0x80000000, 0x00000002,
  498. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  499. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  500. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  501. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  502. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  503. };
  504. /* Packet types for packets with PFCP SESSION header */
  505. static const u32 ice_ptypes_pfcp_session[] = {
  506. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  507. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  508. 0x00000000, 0x00000000, 0x00000000, 0x00000005,
  509. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  510. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  511. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  512. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  513. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  514. };
  515. /* Packet types for L2TPv3 */
  516. static const u32 ice_ptypes_l2tpv3[] = {
  517. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  518. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  519. 0x00000000, 0x00000000, 0x00000000, 0x00000300,
  520. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  521. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  522. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  523. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  524. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  525. };
  526. /* Packet types for ESP */
  527. static const u32 ice_ptypes_esp[] = {
  528. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  529. 0x00000000, 0x00000003, 0x00000000, 0x00000000,
  530. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  531. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  532. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  533. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  534. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  535. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  536. };
  537. /* Packet types for AH */
  538. static const u32 ice_ptypes_ah[] = {
  539. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  540. 0x00000000, 0x0000000C, 0x00000000, 0x00000000,
  541. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  542. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  543. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  544. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  545. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  546. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  547. };
  548. /* Packet types for packets with NAT_T ESP header */
  549. static const u32 ice_ptypes_nat_t_esp[] = {
  550. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  551. 0x00000000, 0x00000030, 0x00000000, 0x00000000,
  552. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  553. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  554. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  555. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  556. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  557. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  558. };
  559. static const u32 ice_ptypes_mac_non_ip_ofos[] = {
  560. 0x00000846, 0x00000000, 0x00000000, 0x00000000,
  561. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  562. 0x00400000, 0x03FFF000, 0x00000000, 0x00000000,
  563. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  564. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  565. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  566. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  567. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  568. };
  569. /* Manage parameters and info. used during the creation of a flow profile */
  570. struct ice_flow_prof_params {
  571. enum ice_block blk;
  572. u16 entry_length; /* # of bytes formatted entry will require */
  573. u8 es_cnt;
  574. struct ice_flow_prof *prof;
  575. /* For ACL, the es[0] will have the data of ICE_RX_MDID_PKT_FLAGS_15_0
  576. * This will give us the direction flags.
  577. */
  578. struct ice_fv_word es[ICE_MAX_FV_WORDS];
  579. /* attributes can be used to add attributes to a particular PTYPE */
  580. const struct ice_ptype_attributes *attr;
  581. u16 attr_cnt;
  582. u16 mask[ICE_MAX_FV_WORDS];
  583. DECLARE_BITMAP(ptypes, ICE_FLOW_PTYPE_MAX);
  584. };
  585. #define ICE_FLOW_RSS_HDRS_INNER_MASK \
  586. (ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_GTPC | \
  587. ICE_FLOW_SEG_HDR_GTPC_TEID | ICE_FLOW_SEG_HDR_GTPU | \
  588. ICE_FLOW_SEG_HDR_PFCP_SESSION | ICE_FLOW_SEG_HDR_L2TPV3 | \
  589. ICE_FLOW_SEG_HDR_ESP | ICE_FLOW_SEG_HDR_AH | \
  590. ICE_FLOW_SEG_HDR_NAT_T_ESP)
  591. #define ICE_FLOW_SEG_HDRS_L3_MASK \
  592. (ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_ARP)
  593. #define ICE_FLOW_SEG_HDRS_L4_MASK \
  594. (ICE_FLOW_SEG_HDR_ICMP | ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_UDP | \
  595. ICE_FLOW_SEG_HDR_SCTP)
  596. /* mask for L4 protocols that are NOT part of IPv4/6 OTHER PTYPE groups */
  597. #define ICE_FLOW_SEG_HDRS_L4_MASK_NO_OTHER \
  598. (ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_SCTP)
  599. /**
  600. * ice_flow_val_hdrs - validates packet segments for valid protocol headers
  601. * @segs: array of one or more packet segments that describe the flow
  602. * @segs_cnt: number of packet segments provided
  603. */
  604. static int ice_flow_val_hdrs(struct ice_flow_seg_info *segs, u8 segs_cnt)
  605. {
  606. u8 i;
  607. for (i = 0; i < segs_cnt; i++) {
  608. /* Multiple L3 headers */
  609. if (segs[i].hdrs & ICE_FLOW_SEG_HDRS_L3_MASK &&
  610. !is_power_of_2(segs[i].hdrs & ICE_FLOW_SEG_HDRS_L3_MASK))
  611. return -EINVAL;
  612. /* Multiple L4 headers */
  613. if (segs[i].hdrs & ICE_FLOW_SEG_HDRS_L4_MASK &&
  614. !is_power_of_2(segs[i].hdrs & ICE_FLOW_SEG_HDRS_L4_MASK))
  615. return -EINVAL;
  616. }
  617. return 0;
  618. }
  619. /* Sizes of fixed known protocol headers without header options */
  620. #define ICE_FLOW_PROT_HDR_SZ_MAC 14
  621. #define ICE_FLOW_PROT_HDR_SZ_MAC_VLAN (ICE_FLOW_PROT_HDR_SZ_MAC + 2)
  622. #define ICE_FLOW_PROT_HDR_SZ_IPV4 20
  623. #define ICE_FLOW_PROT_HDR_SZ_IPV6 40
  624. #define ICE_FLOW_PROT_HDR_SZ_ARP 28
  625. #define ICE_FLOW_PROT_HDR_SZ_ICMP 8
  626. #define ICE_FLOW_PROT_HDR_SZ_TCP 20
  627. #define ICE_FLOW_PROT_HDR_SZ_UDP 8
  628. #define ICE_FLOW_PROT_HDR_SZ_SCTP 12
  629. /**
  630. * ice_flow_calc_seg_sz - calculates size of a packet segment based on headers
  631. * @params: information about the flow to be processed
  632. * @seg: index of packet segment whose header size is to be determined
  633. */
  634. static u16 ice_flow_calc_seg_sz(struct ice_flow_prof_params *params, u8 seg)
  635. {
  636. u16 sz;
  637. /* L2 headers */
  638. sz = (params->prof->segs[seg].hdrs & ICE_FLOW_SEG_HDR_VLAN) ?
  639. ICE_FLOW_PROT_HDR_SZ_MAC_VLAN : ICE_FLOW_PROT_HDR_SZ_MAC;
  640. /* L3 headers */
  641. if (params->prof->segs[seg].hdrs & ICE_FLOW_SEG_HDR_IPV4)
  642. sz += ICE_FLOW_PROT_HDR_SZ_IPV4;
  643. else if (params->prof->segs[seg].hdrs & ICE_FLOW_SEG_HDR_IPV6)
  644. sz += ICE_FLOW_PROT_HDR_SZ_IPV6;
  645. else if (params->prof->segs[seg].hdrs & ICE_FLOW_SEG_HDR_ARP)
  646. sz += ICE_FLOW_PROT_HDR_SZ_ARP;
  647. else if (params->prof->segs[seg].hdrs & ICE_FLOW_SEG_HDRS_L4_MASK)
  648. /* An L3 header is required if L4 is specified */
  649. return 0;
  650. /* L4 headers */
  651. if (params->prof->segs[seg].hdrs & ICE_FLOW_SEG_HDR_ICMP)
  652. sz += ICE_FLOW_PROT_HDR_SZ_ICMP;
  653. else if (params->prof->segs[seg].hdrs & ICE_FLOW_SEG_HDR_TCP)
  654. sz += ICE_FLOW_PROT_HDR_SZ_TCP;
  655. else if (params->prof->segs[seg].hdrs & ICE_FLOW_SEG_HDR_UDP)
  656. sz += ICE_FLOW_PROT_HDR_SZ_UDP;
  657. else if (params->prof->segs[seg].hdrs & ICE_FLOW_SEG_HDR_SCTP)
  658. sz += ICE_FLOW_PROT_HDR_SZ_SCTP;
  659. return sz;
  660. }
  661. /**
  662. * ice_flow_proc_seg_hdrs - process protocol headers present in pkt segments
  663. * @params: information about the flow to be processed
  664. *
  665. * This function identifies the packet types associated with the protocol
  666. * headers being present in packet segments of the specified flow profile.
  667. */
  668. static int ice_flow_proc_seg_hdrs(struct ice_flow_prof_params *params)
  669. {
  670. struct ice_flow_prof *prof;
  671. u8 i;
  672. memset(params->ptypes, 0xff, sizeof(params->ptypes));
  673. prof = params->prof;
  674. for (i = 0; i < params->prof->segs_cnt; i++) {
  675. const unsigned long *src;
  676. u32 hdrs;
  677. hdrs = prof->segs[i].hdrs;
  678. if (hdrs & ICE_FLOW_SEG_HDR_ETH) {
  679. src = !i ? (const unsigned long *)ice_ptypes_mac_ofos :
  680. (const unsigned long *)ice_ptypes_mac_il;
  681. bitmap_and(params->ptypes, params->ptypes, src,
  682. ICE_FLOW_PTYPE_MAX);
  683. }
  684. if (i && hdrs & ICE_FLOW_SEG_HDR_VLAN) {
  685. src = (const unsigned long *)ice_ptypes_macvlan_il;
  686. bitmap_and(params->ptypes, params->ptypes, src,
  687. ICE_FLOW_PTYPE_MAX);
  688. }
  689. if (!i && hdrs & ICE_FLOW_SEG_HDR_ARP) {
  690. bitmap_and(params->ptypes, params->ptypes,
  691. (const unsigned long *)ice_ptypes_arp_of,
  692. ICE_FLOW_PTYPE_MAX);
  693. }
  694. if ((hdrs & ICE_FLOW_SEG_HDR_IPV4) &&
  695. (hdrs & ICE_FLOW_SEG_HDR_IPV_OTHER)) {
  696. src = i ? (const unsigned long *)ice_ptypes_ipv4_il :
  697. (const unsigned long *)ice_ptypes_ipv4_ofos_all;
  698. bitmap_and(params->ptypes, params->ptypes, src,
  699. ICE_FLOW_PTYPE_MAX);
  700. } else if ((hdrs & ICE_FLOW_SEG_HDR_IPV6) &&
  701. (hdrs & ICE_FLOW_SEG_HDR_IPV_OTHER)) {
  702. src = i ? (const unsigned long *)ice_ptypes_ipv6_il :
  703. (const unsigned long *)ice_ptypes_ipv6_ofos_all;
  704. bitmap_and(params->ptypes, params->ptypes, src,
  705. ICE_FLOW_PTYPE_MAX);
  706. } else if ((hdrs & ICE_FLOW_SEG_HDR_IPV4) &&
  707. !(hdrs & ICE_FLOW_SEG_HDRS_L4_MASK_NO_OTHER)) {
  708. src = !i ? (const unsigned long *)ice_ptypes_ipv4_ofos_no_l4 :
  709. (const unsigned long *)ice_ptypes_ipv4_il_no_l4;
  710. bitmap_and(params->ptypes, params->ptypes, src,
  711. ICE_FLOW_PTYPE_MAX);
  712. } else if (hdrs & ICE_FLOW_SEG_HDR_IPV4) {
  713. src = !i ? (const unsigned long *)ice_ptypes_ipv4_ofos :
  714. (const unsigned long *)ice_ptypes_ipv4_il;
  715. bitmap_and(params->ptypes, params->ptypes, src,
  716. ICE_FLOW_PTYPE_MAX);
  717. } else if ((hdrs & ICE_FLOW_SEG_HDR_IPV6) &&
  718. !(hdrs & ICE_FLOW_SEG_HDRS_L4_MASK_NO_OTHER)) {
  719. src = !i ? (const unsigned long *)ice_ptypes_ipv6_ofos_no_l4 :
  720. (const unsigned long *)ice_ptypes_ipv6_il_no_l4;
  721. bitmap_and(params->ptypes, params->ptypes, src,
  722. ICE_FLOW_PTYPE_MAX);
  723. } else if (hdrs & ICE_FLOW_SEG_HDR_IPV6) {
  724. src = !i ? (const unsigned long *)ice_ptypes_ipv6_ofos :
  725. (const unsigned long *)ice_ptypes_ipv6_il;
  726. bitmap_and(params->ptypes, params->ptypes, src,
  727. ICE_FLOW_PTYPE_MAX);
  728. }
  729. if (hdrs & ICE_FLOW_SEG_HDR_ETH_NON_IP) {
  730. src = (const unsigned long *)ice_ptypes_mac_non_ip_ofos;
  731. bitmap_and(params->ptypes, params->ptypes, src,
  732. ICE_FLOW_PTYPE_MAX);
  733. } else if (hdrs & ICE_FLOW_SEG_HDR_PPPOE) {
  734. src = (const unsigned long *)ice_ptypes_pppoe;
  735. bitmap_and(params->ptypes, params->ptypes, src,
  736. ICE_FLOW_PTYPE_MAX);
  737. } else {
  738. src = (const unsigned long *)ice_ptypes_pppoe;
  739. bitmap_andnot(params->ptypes, params->ptypes, src,
  740. ICE_FLOW_PTYPE_MAX);
  741. }
  742. if (hdrs & ICE_FLOW_SEG_HDR_UDP) {
  743. src = (const unsigned long *)ice_ptypes_udp_il;
  744. bitmap_and(params->ptypes, params->ptypes, src,
  745. ICE_FLOW_PTYPE_MAX);
  746. } else if (hdrs & ICE_FLOW_SEG_HDR_TCP) {
  747. bitmap_and(params->ptypes, params->ptypes,
  748. (const unsigned long *)ice_ptypes_tcp_il,
  749. ICE_FLOW_PTYPE_MAX);
  750. } else if (hdrs & ICE_FLOW_SEG_HDR_SCTP) {
  751. src = (const unsigned long *)ice_ptypes_sctp_il;
  752. bitmap_and(params->ptypes, params->ptypes, src,
  753. ICE_FLOW_PTYPE_MAX);
  754. }
  755. if (hdrs & ICE_FLOW_SEG_HDR_ICMP) {
  756. src = !i ? (const unsigned long *)ice_ptypes_icmp_of :
  757. (const unsigned long *)ice_ptypes_icmp_il;
  758. bitmap_and(params->ptypes, params->ptypes, src,
  759. ICE_FLOW_PTYPE_MAX);
  760. } else if (hdrs & ICE_FLOW_SEG_HDR_GRE) {
  761. if (!i) {
  762. src = (const unsigned long *)ice_ptypes_gre_of;
  763. bitmap_and(params->ptypes, params->ptypes,
  764. src, ICE_FLOW_PTYPE_MAX);
  765. }
  766. } else if (hdrs & ICE_FLOW_SEG_HDR_GTPC) {
  767. src = (const unsigned long *)ice_ptypes_gtpc;
  768. bitmap_and(params->ptypes, params->ptypes, src,
  769. ICE_FLOW_PTYPE_MAX);
  770. } else if (hdrs & ICE_FLOW_SEG_HDR_GTPC_TEID) {
  771. src = (const unsigned long *)ice_ptypes_gtpc_tid;
  772. bitmap_and(params->ptypes, params->ptypes, src,
  773. ICE_FLOW_PTYPE_MAX);
  774. } else if (hdrs & ICE_FLOW_SEG_HDR_GTPU_DWN) {
  775. src = (const unsigned long *)ice_ptypes_gtpu;
  776. bitmap_and(params->ptypes, params->ptypes, src,
  777. ICE_FLOW_PTYPE_MAX);
  778. /* Attributes for GTP packet with downlink */
  779. params->attr = ice_attr_gtpu_down;
  780. params->attr_cnt = ARRAY_SIZE(ice_attr_gtpu_down);
  781. } else if (hdrs & ICE_FLOW_SEG_HDR_GTPU_UP) {
  782. src = (const unsigned long *)ice_ptypes_gtpu;
  783. bitmap_and(params->ptypes, params->ptypes, src,
  784. ICE_FLOW_PTYPE_MAX);
  785. /* Attributes for GTP packet with uplink */
  786. params->attr = ice_attr_gtpu_up;
  787. params->attr_cnt = ARRAY_SIZE(ice_attr_gtpu_up);
  788. } else if (hdrs & ICE_FLOW_SEG_HDR_GTPU_EH) {
  789. src = (const unsigned long *)ice_ptypes_gtpu;
  790. bitmap_and(params->ptypes, params->ptypes, src,
  791. ICE_FLOW_PTYPE_MAX);
  792. /* Attributes for GTP packet with Extension Header */
  793. params->attr = ice_attr_gtpu_eh;
  794. params->attr_cnt = ARRAY_SIZE(ice_attr_gtpu_eh);
  795. } else if (hdrs & ICE_FLOW_SEG_HDR_GTPU_IP) {
  796. src = (const unsigned long *)ice_ptypes_gtpu;
  797. bitmap_and(params->ptypes, params->ptypes, src,
  798. ICE_FLOW_PTYPE_MAX);
  799. } else if (hdrs & ICE_FLOW_SEG_HDR_L2TPV3) {
  800. src = (const unsigned long *)ice_ptypes_l2tpv3;
  801. bitmap_and(params->ptypes, params->ptypes, src,
  802. ICE_FLOW_PTYPE_MAX);
  803. } else if (hdrs & ICE_FLOW_SEG_HDR_ESP) {
  804. src = (const unsigned long *)ice_ptypes_esp;
  805. bitmap_and(params->ptypes, params->ptypes, src,
  806. ICE_FLOW_PTYPE_MAX);
  807. } else if (hdrs & ICE_FLOW_SEG_HDR_AH) {
  808. src = (const unsigned long *)ice_ptypes_ah;
  809. bitmap_and(params->ptypes, params->ptypes, src,
  810. ICE_FLOW_PTYPE_MAX);
  811. } else if (hdrs & ICE_FLOW_SEG_HDR_NAT_T_ESP) {
  812. src = (const unsigned long *)ice_ptypes_nat_t_esp;
  813. bitmap_and(params->ptypes, params->ptypes, src,
  814. ICE_FLOW_PTYPE_MAX);
  815. }
  816. if (hdrs & ICE_FLOW_SEG_HDR_PFCP) {
  817. if (hdrs & ICE_FLOW_SEG_HDR_PFCP_NODE)
  818. src = (const unsigned long *)ice_ptypes_pfcp_node;
  819. else
  820. src = (const unsigned long *)ice_ptypes_pfcp_session;
  821. bitmap_and(params->ptypes, params->ptypes, src,
  822. ICE_FLOW_PTYPE_MAX);
  823. } else {
  824. src = (const unsigned long *)ice_ptypes_pfcp_node;
  825. bitmap_andnot(params->ptypes, params->ptypes, src,
  826. ICE_FLOW_PTYPE_MAX);
  827. src = (const unsigned long *)ice_ptypes_pfcp_session;
  828. bitmap_andnot(params->ptypes, params->ptypes, src,
  829. ICE_FLOW_PTYPE_MAX);
  830. }
  831. }
  832. return 0;
  833. }
  834. /**
  835. * ice_flow_xtract_fld - Create an extraction sequence entry for the given field
  836. * @hw: pointer to the HW struct
  837. * @params: information about the flow to be processed
  838. * @seg: packet segment index of the field to be extracted
  839. * @fld: ID of field to be extracted
  840. * @match: bit field of all fields
  841. *
  842. * This function determines the protocol ID, offset, and size of the given
  843. * field. It then allocates one or more extraction sequence entries for the
  844. * given field, and fill the entries with protocol ID and offset information.
  845. */
  846. static int
  847. ice_flow_xtract_fld(struct ice_hw *hw, struct ice_flow_prof_params *params,
  848. u8 seg, enum ice_flow_field fld, u64 match)
  849. {
  850. enum ice_flow_field sib = ICE_FLOW_FIELD_IDX_MAX;
  851. enum ice_prot_id prot_id = ICE_PROT_ID_INVAL;
  852. u8 fv_words = hw->blk[params->blk].es.fvw;
  853. struct ice_flow_fld_info *flds;
  854. u16 cnt, ese_bits, i;
  855. u16 sib_mask = 0;
  856. u16 mask;
  857. u16 off;
  858. flds = params->prof->segs[seg].fields;
  859. switch (fld) {
  860. case ICE_FLOW_FIELD_IDX_ETH_DA:
  861. case ICE_FLOW_FIELD_IDX_ETH_SA:
  862. case ICE_FLOW_FIELD_IDX_S_VLAN:
  863. case ICE_FLOW_FIELD_IDX_C_VLAN:
  864. prot_id = seg == 0 ? ICE_PROT_MAC_OF_OR_S : ICE_PROT_MAC_IL;
  865. break;
  866. case ICE_FLOW_FIELD_IDX_ETH_TYPE:
  867. prot_id = seg == 0 ? ICE_PROT_ETYPE_OL : ICE_PROT_ETYPE_IL;
  868. break;
  869. case ICE_FLOW_FIELD_IDX_IPV4_DSCP:
  870. prot_id = seg == 0 ? ICE_PROT_IPV4_OF_OR_S : ICE_PROT_IPV4_IL;
  871. break;
  872. case ICE_FLOW_FIELD_IDX_IPV6_DSCP:
  873. prot_id = seg == 0 ? ICE_PROT_IPV6_OF_OR_S : ICE_PROT_IPV6_IL;
  874. break;
  875. case ICE_FLOW_FIELD_IDX_IPV4_TTL:
  876. case ICE_FLOW_FIELD_IDX_IPV4_PROT:
  877. prot_id = seg == 0 ? ICE_PROT_IPV4_OF_OR_S : ICE_PROT_IPV4_IL;
  878. /* TTL and PROT share the same extraction seq. entry.
  879. * Each is considered a sibling to the other in terms of sharing
  880. * the same extraction sequence entry.
  881. */
  882. if (fld == ICE_FLOW_FIELD_IDX_IPV4_TTL)
  883. sib = ICE_FLOW_FIELD_IDX_IPV4_PROT;
  884. else if (fld == ICE_FLOW_FIELD_IDX_IPV4_PROT)
  885. sib = ICE_FLOW_FIELD_IDX_IPV4_TTL;
  886. /* If the sibling field is also included, that field's
  887. * mask needs to be included.
  888. */
  889. if (match & BIT(sib))
  890. sib_mask = ice_flds_info[sib].mask;
  891. break;
  892. case ICE_FLOW_FIELD_IDX_IPV6_TTL:
  893. case ICE_FLOW_FIELD_IDX_IPV6_PROT:
  894. prot_id = seg == 0 ? ICE_PROT_IPV6_OF_OR_S : ICE_PROT_IPV6_IL;
  895. /* TTL and PROT share the same extraction seq. entry.
  896. * Each is considered a sibling to the other in terms of sharing
  897. * the same extraction sequence entry.
  898. */
  899. if (fld == ICE_FLOW_FIELD_IDX_IPV6_TTL)
  900. sib = ICE_FLOW_FIELD_IDX_IPV6_PROT;
  901. else if (fld == ICE_FLOW_FIELD_IDX_IPV6_PROT)
  902. sib = ICE_FLOW_FIELD_IDX_IPV6_TTL;
  903. /* If the sibling field is also included, that field's
  904. * mask needs to be included.
  905. */
  906. if (match & BIT(sib))
  907. sib_mask = ice_flds_info[sib].mask;
  908. break;
  909. case ICE_FLOW_FIELD_IDX_IPV4_SA:
  910. case ICE_FLOW_FIELD_IDX_IPV4_DA:
  911. prot_id = seg == 0 ? ICE_PROT_IPV4_OF_OR_S : ICE_PROT_IPV4_IL;
  912. break;
  913. case ICE_FLOW_FIELD_IDX_IPV6_SA:
  914. case ICE_FLOW_FIELD_IDX_IPV6_DA:
  915. prot_id = seg == 0 ? ICE_PROT_IPV6_OF_OR_S : ICE_PROT_IPV6_IL;
  916. break;
  917. case ICE_FLOW_FIELD_IDX_TCP_SRC_PORT:
  918. case ICE_FLOW_FIELD_IDX_TCP_DST_PORT:
  919. case ICE_FLOW_FIELD_IDX_TCP_FLAGS:
  920. prot_id = ICE_PROT_TCP_IL;
  921. break;
  922. case ICE_FLOW_FIELD_IDX_UDP_SRC_PORT:
  923. case ICE_FLOW_FIELD_IDX_UDP_DST_PORT:
  924. prot_id = ICE_PROT_UDP_IL_OR_S;
  925. break;
  926. case ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT:
  927. case ICE_FLOW_FIELD_IDX_SCTP_DST_PORT:
  928. prot_id = ICE_PROT_SCTP_IL;
  929. break;
  930. case ICE_FLOW_FIELD_IDX_GTPC_TEID:
  931. case ICE_FLOW_FIELD_IDX_GTPU_IP_TEID:
  932. case ICE_FLOW_FIELD_IDX_GTPU_UP_TEID:
  933. case ICE_FLOW_FIELD_IDX_GTPU_DWN_TEID:
  934. case ICE_FLOW_FIELD_IDX_GTPU_EH_TEID:
  935. case ICE_FLOW_FIELD_IDX_GTPU_EH_QFI:
  936. /* GTP is accessed through UDP OF protocol */
  937. prot_id = ICE_PROT_UDP_OF;
  938. break;
  939. case ICE_FLOW_FIELD_IDX_PPPOE_SESS_ID:
  940. prot_id = ICE_PROT_PPPOE;
  941. break;
  942. case ICE_FLOW_FIELD_IDX_PFCP_SEID:
  943. prot_id = ICE_PROT_UDP_IL_OR_S;
  944. break;
  945. case ICE_FLOW_FIELD_IDX_L2TPV3_SESS_ID:
  946. prot_id = ICE_PROT_L2TPV3;
  947. break;
  948. case ICE_FLOW_FIELD_IDX_ESP_SPI:
  949. prot_id = ICE_PROT_ESP_F;
  950. break;
  951. case ICE_FLOW_FIELD_IDX_AH_SPI:
  952. prot_id = ICE_PROT_ESP_2;
  953. break;
  954. case ICE_FLOW_FIELD_IDX_NAT_T_ESP_SPI:
  955. prot_id = ICE_PROT_UDP_IL_OR_S;
  956. break;
  957. case ICE_FLOW_FIELD_IDX_ARP_SIP:
  958. case ICE_FLOW_FIELD_IDX_ARP_DIP:
  959. case ICE_FLOW_FIELD_IDX_ARP_SHA:
  960. case ICE_FLOW_FIELD_IDX_ARP_DHA:
  961. case ICE_FLOW_FIELD_IDX_ARP_OP:
  962. prot_id = ICE_PROT_ARP_OF;
  963. break;
  964. case ICE_FLOW_FIELD_IDX_ICMP_TYPE:
  965. case ICE_FLOW_FIELD_IDX_ICMP_CODE:
  966. /* ICMP type and code share the same extraction seq. entry */
  967. prot_id = (params->prof->segs[seg].hdrs & ICE_FLOW_SEG_HDR_IPV4) ?
  968. ICE_PROT_ICMP_IL : ICE_PROT_ICMPV6_IL;
  969. sib = fld == ICE_FLOW_FIELD_IDX_ICMP_TYPE ?
  970. ICE_FLOW_FIELD_IDX_ICMP_CODE :
  971. ICE_FLOW_FIELD_IDX_ICMP_TYPE;
  972. break;
  973. case ICE_FLOW_FIELD_IDX_GRE_KEYID:
  974. prot_id = ICE_PROT_GRE_OF;
  975. break;
  976. default:
  977. return -EOPNOTSUPP;
  978. }
  979. /* Each extraction sequence entry is a word in size, and extracts a
  980. * word-aligned offset from a protocol header.
  981. */
  982. ese_bits = ICE_FLOW_FV_EXTRACT_SZ * BITS_PER_BYTE;
  983. flds[fld].xtrct.prot_id = prot_id;
  984. flds[fld].xtrct.off = (ice_flds_info[fld].off / ese_bits) *
  985. ICE_FLOW_FV_EXTRACT_SZ;
  986. flds[fld].xtrct.disp = (u8)(ice_flds_info[fld].off % ese_bits);
  987. flds[fld].xtrct.idx = params->es_cnt;
  988. flds[fld].xtrct.mask = ice_flds_info[fld].mask;
  989. /* Adjust the next field-entry index after accommodating the number of
  990. * entries this field consumes
  991. */
  992. cnt = DIV_ROUND_UP(flds[fld].xtrct.disp + ice_flds_info[fld].size,
  993. ese_bits);
  994. /* Fill in the extraction sequence entries needed for this field */
  995. off = flds[fld].xtrct.off;
  996. mask = flds[fld].xtrct.mask;
  997. for (i = 0; i < cnt; i++) {
  998. /* Only consume an extraction sequence entry if there is no
  999. * sibling field associated with this field or the sibling entry
  1000. * already extracts the word shared with this field.
  1001. */
  1002. if (sib == ICE_FLOW_FIELD_IDX_MAX ||
  1003. flds[sib].xtrct.prot_id == ICE_PROT_ID_INVAL ||
  1004. flds[sib].xtrct.off != off) {
  1005. u8 idx;
  1006. /* Make sure the number of extraction sequence required
  1007. * does not exceed the block's capability
  1008. */
  1009. if (params->es_cnt >= fv_words)
  1010. return -ENOSPC;
  1011. /* some blocks require a reversed field vector layout */
  1012. if (hw->blk[params->blk].es.reverse)
  1013. idx = fv_words - params->es_cnt - 1;
  1014. else
  1015. idx = params->es_cnt;
  1016. params->es[idx].prot_id = prot_id;
  1017. params->es[idx].off = off;
  1018. params->mask[idx] = mask | sib_mask;
  1019. params->es_cnt++;
  1020. }
  1021. off += ICE_FLOW_FV_EXTRACT_SZ;
  1022. }
  1023. return 0;
  1024. }
  1025. /**
  1026. * ice_flow_xtract_raws - Create extract sequence entries for raw bytes
  1027. * @hw: pointer to the HW struct
  1028. * @params: information about the flow to be processed
  1029. * @seg: index of packet segment whose raw fields are to be extracted
  1030. */
  1031. static int
  1032. ice_flow_xtract_raws(struct ice_hw *hw, struct ice_flow_prof_params *params,
  1033. u8 seg)
  1034. {
  1035. u16 fv_words;
  1036. u16 hdrs_sz;
  1037. u8 i;
  1038. if (!params->prof->segs[seg].raws_cnt)
  1039. return 0;
  1040. if (params->prof->segs[seg].raws_cnt >
  1041. ARRAY_SIZE(params->prof->segs[seg].raws))
  1042. return -ENOSPC;
  1043. /* Offsets within the segment headers are not supported */
  1044. hdrs_sz = ice_flow_calc_seg_sz(params, seg);
  1045. if (!hdrs_sz)
  1046. return -EINVAL;
  1047. fv_words = hw->blk[params->blk].es.fvw;
  1048. for (i = 0; i < params->prof->segs[seg].raws_cnt; i++) {
  1049. struct ice_flow_seg_fld_raw *raw;
  1050. u16 off, cnt, j;
  1051. raw = &params->prof->segs[seg].raws[i];
  1052. /* Storing extraction information */
  1053. raw->info.xtrct.prot_id = ICE_PROT_MAC_OF_OR_S;
  1054. raw->info.xtrct.off = (raw->off / ICE_FLOW_FV_EXTRACT_SZ) *
  1055. ICE_FLOW_FV_EXTRACT_SZ;
  1056. raw->info.xtrct.disp = (raw->off % ICE_FLOW_FV_EXTRACT_SZ) *
  1057. BITS_PER_BYTE;
  1058. raw->info.xtrct.idx = params->es_cnt;
  1059. /* Determine the number of field vector entries this raw field
  1060. * consumes.
  1061. */
  1062. cnt = DIV_ROUND_UP(raw->info.xtrct.disp +
  1063. (raw->info.src.last * BITS_PER_BYTE),
  1064. (ICE_FLOW_FV_EXTRACT_SZ * BITS_PER_BYTE));
  1065. off = raw->info.xtrct.off;
  1066. for (j = 0; j < cnt; j++) {
  1067. u16 idx;
  1068. /* Make sure the number of extraction sequence required
  1069. * does not exceed the block's capability
  1070. */
  1071. if (params->es_cnt >= hw->blk[params->blk].es.count ||
  1072. params->es_cnt >= ICE_MAX_FV_WORDS)
  1073. return -ENOSPC;
  1074. /* some blocks require a reversed field vector layout */
  1075. if (hw->blk[params->blk].es.reverse)
  1076. idx = fv_words - params->es_cnt - 1;
  1077. else
  1078. idx = params->es_cnt;
  1079. params->es[idx].prot_id = raw->info.xtrct.prot_id;
  1080. params->es[idx].off = off;
  1081. params->es_cnt++;
  1082. off += ICE_FLOW_FV_EXTRACT_SZ;
  1083. }
  1084. }
  1085. return 0;
  1086. }
  1087. /**
  1088. * ice_flow_create_xtrct_seq - Create an extraction sequence for given segments
  1089. * @hw: pointer to the HW struct
  1090. * @params: information about the flow to be processed
  1091. *
  1092. * This function iterates through all matched fields in the given segments, and
  1093. * creates an extraction sequence for the fields.
  1094. */
  1095. static int
  1096. ice_flow_create_xtrct_seq(struct ice_hw *hw,
  1097. struct ice_flow_prof_params *params)
  1098. {
  1099. struct ice_flow_prof *prof = params->prof;
  1100. int status = 0;
  1101. u8 i;
  1102. for (i = 0; i < prof->segs_cnt; i++) {
  1103. u64 match = params->prof->segs[i].match;
  1104. enum ice_flow_field j;
  1105. for_each_set_bit(j, (unsigned long *)&match,
  1106. ICE_FLOW_FIELD_IDX_MAX) {
  1107. status = ice_flow_xtract_fld(hw, params, i, j, match);
  1108. if (status)
  1109. return status;
  1110. clear_bit(j, (unsigned long *)&match);
  1111. }
  1112. /* Process raw matching bytes */
  1113. status = ice_flow_xtract_raws(hw, params, i);
  1114. if (status)
  1115. return status;
  1116. }
  1117. return status;
  1118. }
  1119. /**
  1120. * ice_flow_proc_segs - process all packet segments associated with a profile
  1121. * @hw: pointer to the HW struct
  1122. * @params: information about the flow to be processed
  1123. */
  1124. static int
  1125. ice_flow_proc_segs(struct ice_hw *hw, struct ice_flow_prof_params *params)
  1126. {
  1127. int status;
  1128. status = ice_flow_proc_seg_hdrs(params);
  1129. if (status)
  1130. return status;
  1131. status = ice_flow_create_xtrct_seq(hw, params);
  1132. if (status)
  1133. return status;
  1134. switch (params->blk) {
  1135. case ICE_BLK_FD:
  1136. case ICE_BLK_RSS:
  1137. status = 0;
  1138. break;
  1139. default:
  1140. return -EOPNOTSUPP;
  1141. }
  1142. return status;
  1143. }
  1144. #define ICE_FLOW_FIND_PROF_CHK_FLDS 0x00000001
  1145. #define ICE_FLOW_FIND_PROF_CHK_VSI 0x00000002
  1146. #define ICE_FLOW_FIND_PROF_NOT_CHK_DIR 0x00000004
  1147. #define ICE_FLOW_FIND_PROF_CHK_SYMM 0x00000008
  1148. /**
  1149. * ice_flow_find_prof_conds - Find a profile matching headers and conditions
  1150. * @hw: pointer to the HW struct
  1151. * @blk: classification stage
  1152. * @dir: flow direction
  1153. * @segs: array of one or more packet segments that describe the flow
  1154. * @segs_cnt: number of packet segments provided
  1155. * @symm: symmetric setting for RSS profiles
  1156. * @vsi_handle: software VSI handle to check VSI (ICE_FLOW_FIND_PROF_CHK_VSI)
  1157. * @conds: additional conditions to be checked (ICE_FLOW_FIND_PROF_CHK_*)
  1158. */
  1159. static struct ice_flow_prof *
  1160. ice_flow_find_prof_conds(struct ice_hw *hw, enum ice_block blk,
  1161. enum ice_flow_dir dir, struct ice_flow_seg_info *segs,
  1162. u8 segs_cnt, bool symm, u16 vsi_handle, u32 conds)
  1163. {
  1164. struct ice_flow_prof *p, *prof = NULL;
  1165. mutex_lock(&hw->fl_profs_locks[blk]);
  1166. list_for_each_entry(p, &hw->fl_profs[blk], l_entry)
  1167. if ((p->dir == dir || conds & ICE_FLOW_FIND_PROF_NOT_CHK_DIR) &&
  1168. segs_cnt && segs_cnt == p->segs_cnt) {
  1169. u8 i;
  1170. /* Check for profile-VSI association if specified */
  1171. if ((conds & ICE_FLOW_FIND_PROF_CHK_VSI) &&
  1172. ice_is_vsi_valid(hw, vsi_handle) &&
  1173. !test_bit(vsi_handle, p->vsis))
  1174. continue;
  1175. /* Check for symmetric settings */
  1176. if ((conds & ICE_FLOW_FIND_PROF_CHK_SYMM) &&
  1177. p->symm != symm)
  1178. continue;
  1179. /* Protocol headers must be checked. Matched fields are
  1180. * checked if specified.
  1181. */
  1182. for (i = 0; i < segs_cnt; i++)
  1183. if (segs[i].hdrs != p->segs[i].hdrs ||
  1184. ((conds & ICE_FLOW_FIND_PROF_CHK_FLDS) &&
  1185. segs[i].match != p->segs[i].match))
  1186. break;
  1187. /* A match is found if all segments are matched */
  1188. if (i == segs_cnt) {
  1189. prof = p;
  1190. break;
  1191. }
  1192. }
  1193. mutex_unlock(&hw->fl_profs_locks[blk]);
  1194. return prof;
  1195. }
  1196. /**
  1197. * ice_flow_find_prof_id - Look up a profile with given profile ID
  1198. * @hw: pointer to the HW struct
  1199. * @blk: classification stage
  1200. * @prof_id: unique ID to identify this flow profile
  1201. */
  1202. static struct ice_flow_prof *
  1203. ice_flow_find_prof_id(struct ice_hw *hw, enum ice_block blk, u64 prof_id)
  1204. {
  1205. struct ice_flow_prof *p;
  1206. list_for_each_entry(p, &hw->fl_profs[blk], l_entry)
  1207. if (p->id == prof_id)
  1208. return p;
  1209. return NULL;
  1210. }
  1211. /**
  1212. * ice_flow_rem_entry_sync - Remove a flow entry
  1213. * @hw: pointer to the HW struct
  1214. * @blk: classification stage
  1215. * @entry: flow entry to be removed
  1216. */
  1217. static int
  1218. ice_flow_rem_entry_sync(struct ice_hw *hw, enum ice_block __always_unused blk,
  1219. struct ice_flow_entry *entry)
  1220. {
  1221. if (!entry)
  1222. return -EINVAL;
  1223. list_del(&entry->l_entry);
  1224. devm_kfree(ice_hw_to_dev(hw), entry);
  1225. return 0;
  1226. }
  1227. /**
  1228. * ice_flow_add_prof_sync - Add a flow profile for packet segments and fields
  1229. * @hw: pointer to the HW struct
  1230. * @blk: classification stage
  1231. * @dir: flow direction
  1232. * @segs: array of one or more packet segments that describe the flow
  1233. * @segs_cnt: number of packet segments provided
  1234. * @symm: symmetric setting for RSS profiles
  1235. * @prof: stores the returned flow profile added
  1236. *
  1237. * Assumption: the caller has acquired the lock to the profile list
  1238. */
  1239. static int
  1240. ice_flow_add_prof_sync(struct ice_hw *hw, enum ice_block blk,
  1241. enum ice_flow_dir dir,
  1242. struct ice_flow_seg_info *segs, u8 segs_cnt,
  1243. bool symm, struct ice_flow_prof **prof)
  1244. {
  1245. struct ice_flow_prof_params *params;
  1246. struct ice_prof_id *ids;
  1247. int status;
  1248. u64 prof_id;
  1249. u8 i;
  1250. if (!prof)
  1251. return -EINVAL;
  1252. ids = &hw->blk[blk].prof_id;
  1253. prof_id = find_first_zero_bit(ids->id, ids->count);
  1254. if (prof_id >= ids->count)
  1255. return -ENOSPC;
  1256. params = kzalloc(sizeof(*params), GFP_KERNEL);
  1257. if (!params)
  1258. return -ENOMEM;
  1259. params->prof = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*params->prof),
  1260. GFP_KERNEL);
  1261. if (!params->prof) {
  1262. status = -ENOMEM;
  1263. goto free_params;
  1264. }
  1265. /* initialize extraction sequence to all invalid (0xff) */
  1266. for (i = 0; i < ICE_MAX_FV_WORDS; i++) {
  1267. params->es[i].prot_id = ICE_PROT_INVALID;
  1268. params->es[i].off = ICE_FV_OFFSET_INVAL;
  1269. }
  1270. params->blk = blk;
  1271. params->prof->id = prof_id;
  1272. params->prof->dir = dir;
  1273. params->prof->segs_cnt = segs_cnt;
  1274. params->prof->symm = symm;
  1275. /* Make a copy of the segments that need to be persistent in the flow
  1276. * profile instance
  1277. */
  1278. for (i = 0; i < segs_cnt; i++)
  1279. memcpy(&params->prof->segs[i], &segs[i], sizeof(*segs));
  1280. status = ice_flow_proc_segs(hw, params);
  1281. if (status) {
  1282. ice_debug(hw, ICE_DBG_FLOW, "Error processing a flow's packet segments\n");
  1283. goto out;
  1284. }
  1285. /* Add a HW profile for this flow profile */
  1286. status = ice_add_prof(hw, blk, prof_id, (u8 *)params->ptypes,
  1287. params->attr, params->attr_cnt, params->es,
  1288. params->mask, symm, true);
  1289. if (status) {
  1290. ice_debug(hw, ICE_DBG_FLOW, "Error adding a HW flow profile\n");
  1291. goto out;
  1292. }
  1293. INIT_LIST_HEAD(&params->prof->entries);
  1294. mutex_init(&params->prof->entries_lock);
  1295. set_bit(prof_id, ids->id);
  1296. *prof = params->prof;
  1297. out:
  1298. if (status)
  1299. devm_kfree(ice_hw_to_dev(hw), params->prof);
  1300. free_params:
  1301. kfree(params);
  1302. return status;
  1303. }
  1304. /**
  1305. * ice_flow_rem_prof_sync - remove a flow profile
  1306. * @hw: pointer to the hardware structure
  1307. * @blk: classification stage
  1308. * @prof: pointer to flow profile to remove
  1309. *
  1310. * Assumption: the caller has acquired the lock to the profile list
  1311. */
  1312. static int
  1313. ice_flow_rem_prof_sync(struct ice_hw *hw, enum ice_block blk,
  1314. struct ice_flow_prof *prof)
  1315. {
  1316. int status;
  1317. /* Remove all remaining flow entries before removing the flow profile */
  1318. if (!list_empty(&prof->entries)) {
  1319. struct ice_flow_entry *e, *t;
  1320. mutex_lock(&prof->entries_lock);
  1321. list_for_each_entry_safe(e, t, &prof->entries, l_entry) {
  1322. status = ice_flow_rem_entry_sync(hw, blk, e);
  1323. if (status)
  1324. break;
  1325. }
  1326. mutex_unlock(&prof->entries_lock);
  1327. }
  1328. /* Remove all hardware profiles associated with this flow profile */
  1329. status = ice_rem_prof(hw, blk, prof->id);
  1330. if (!status) {
  1331. clear_bit(prof->id, hw->blk[blk].prof_id.id);
  1332. list_del(&prof->l_entry);
  1333. mutex_destroy(&prof->entries_lock);
  1334. devm_kfree(ice_hw_to_dev(hw), prof);
  1335. }
  1336. return status;
  1337. }
  1338. /**
  1339. * ice_flow_assoc_prof - associate a VSI with a flow profile
  1340. * @hw: pointer to the hardware structure
  1341. * @blk: classification stage
  1342. * @prof: pointer to flow profile
  1343. * @vsi_handle: software VSI handle
  1344. *
  1345. * Assumption: the caller has acquired the lock to the profile list
  1346. * and the software VSI handle has been validated
  1347. */
  1348. static int
  1349. ice_flow_assoc_prof(struct ice_hw *hw, enum ice_block blk,
  1350. struct ice_flow_prof *prof, u16 vsi_handle)
  1351. {
  1352. int status = 0;
  1353. if (!test_bit(vsi_handle, prof->vsis)) {
  1354. status = ice_add_prof_id_flow(hw, blk,
  1355. ice_get_hw_vsi_num(hw,
  1356. vsi_handle),
  1357. prof->id);
  1358. if (!status)
  1359. set_bit(vsi_handle, prof->vsis);
  1360. else
  1361. ice_debug(hw, ICE_DBG_FLOW, "HW profile add failed, %d\n",
  1362. status);
  1363. }
  1364. return status;
  1365. }
  1366. /**
  1367. * ice_flow_disassoc_prof - disassociate a VSI from a flow profile
  1368. * @hw: pointer to the hardware structure
  1369. * @blk: classification stage
  1370. * @prof: pointer to flow profile
  1371. * @vsi_handle: software VSI handle
  1372. *
  1373. * Assumption: the caller has acquired the lock to the profile list
  1374. * and the software VSI handle has been validated
  1375. */
  1376. static int
  1377. ice_flow_disassoc_prof(struct ice_hw *hw, enum ice_block blk,
  1378. struct ice_flow_prof *prof, u16 vsi_handle)
  1379. {
  1380. int status = 0;
  1381. if (test_bit(vsi_handle, prof->vsis)) {
  1382. status = ice_rem_prof_id_flow(hw, blk,
  1383. ice_get_hw_vsi_num(hw,
  1384. vsi_handle),
  1385. prof->id);
  1386. if (!status)
  1387. clear_bit(vsi_handle, prof->vsis);
  1388. else
  1389. ice_debug(hw, ICE_DBG_FLOW, "HW profile remove failed, %d\n",
  1390. status);
  1391. }
  1392. return status;
  1393. }
  1394. #define FLAG_GTP_EH_PDU_LINK BIT_ULL(13)
  1395. #define FLAG_GTP_EH_PDU BIT_ULL(14)
  1396. #define HI_BYTE_IN_WORD GENMASK(15, 8)
  1397. #define LO_BYTE_IN_WORD GENMASK(7, 0)
  1398. #define FLAG_GTPU_MSK \
  1399. (FLAG_GTP_EH_PDU | FLAG_GTP_EH_PDU_LINK)
  1400. #define FLAG_GTPU_UP \
  1401. (FLAG_GTP_EH_PDU | FLAG_GTP_EH_PDU_LINK)
  1402. #define FLAG_GTPU_DW FLAG_GTP_EH_PDU
  1403. /**
  1404. * ice_flow_set_parser_prof - Set flow profile based on the parsed profile info
  1405. * @hw: pointer to the HW struct
  1406. * @dest_vsi: dest VSI
  1407. * @fdir_vsi: fdir programming VSI
  1408. * @prof: stores parsed profile info from raw flow
  1409. * @blk: classification blk
  1410. *
  1411. * Return: 0 on success or negative errno on failure.
  1412. */
  1413. int
  1414. ice_flow_set_parser_prof(struct ice_hw *hw, u16 dest_vsi, u16 fdir_vsi,
  1415. struct ice_parser_profile *prof, enum ice_block blk)
  1416. {
  1417. u64 id = find_first_bit(prof->ptypes, ICE_FLOW_PTYPE_MAX);
  1418. struct ice_flow_prof_params *params __free(kfree);
  1419. u8 fv_words = hw->blk[blk].es.fvw;
  1420. int status;
  1421. int i, idx;
  1422. params = kzalloc(sizeof(*params), GFP_KERNEL);
  1423. if (!params)
  1424. return -ENOMEM;
  1425. for (i = 0; i < ICE_MAX_FV_WORDS; i++) {
  1426. params->es[i].prot_id = ICE_PROT_INVALID;
  1427. params->es[i].off = ICE_FV_OFFSET_INVAL;
  1428. }
  1429. for (i = 0; i < prof->fv_num; i++) {
  1430. if (hw->blk[blk].es.reverse)
  1431. idx = fv_words - i - 1;
  1432. else
  1433. idx = i;
  1434. params->es[idx].prot_id = prof->fv[i].proto_id;
  1435. params->es[idx].off = prof->fv[i].offset;
  1436. params->mask[idx] = (((prof->fv[i].msk) << BITS_PER_BYTE) &
  1437. HI_BYTE_IN_WORD) |
  1438. (((prof->fv[i].msk) >> BITS_PER_BYTE) &
  1439. LO_BYTE_IN_WORD);
  1440. }
  1441. switch (prof->flags) {
  1442. case FLAG_GTPU_DW:
  1443. params->attr = ice_attr_gtpu_down;
  1444. params->attr_cnt = ARRAY_SIZE(ice_attr_gtpu_down);
  1445. break;
  1446. case FLAG_GTPU_UP:
  1447. params->attr = ice_attr_gtpu_up;
  1448. params->attr_cnt = ARRAY_SIZE(ice_attr_gtpu_up);
  1449. break;
  1450. default:
  1451. if (prof->flags_msk & FLAG_GTPU_MSK) {
  1452. params->attr = ice_attr_gtpu_session;
  1453. params->attr_cnt = ARRAY_SIZE(ice_attr_gtpu_session);
  1454. }
  1455. break;
  1456. }
  1457. status = ice_add_prof(hw, blk, id, (u8 *)prof->ptypes,
  1458. params->attr, params->attr_cnt,
  1459. params->es, params->mask, false, false);
  1460. if (status)
  1461. return status;
  1462. status = ice_flow_assoc_fdir_prof(hw, blk, dest_vsi, fdir_vsi, id);
  1463. if (status)
  1464. ice_rem_prof(hw, blk, id);
  1465. return status;
  1466. }
  1467. /**
  1468. * ice_flow_add_prof - Add a flow profile for packet segments and matched fields
  1469. * @hw: pointer to the HW struct
  1470. * @blk: classification stage
  1471. * @dir: flow direction
  1472. * @segs: array of one or more packet segments that describe the flow
  1473. * @segs_cnt: number of packet segments provided
  1474. * @symm: symmetric setting for RSS profiles
  1475. * @prof: stores the returned flow profile added
  1476. */
  1477. int
  1478. ice_flow_add_prof(struct ice_hw *hw, enum ice_block blk, enum ice_flow_dir dir,
  1479. struct ice_flow_seg_info *segs, u8 segs_cnt,
  1480. bool symm, struct ice_flow_prof **prof)
  1481. {
  1482. int status;
  1483. if (segs_cnt > ICE_FLOW_SEG_MAX)
  1484. return -ENOSPC;
  1485. if (!segs_cnt)
  1486. return -EINVAL;
  1487. if (!segs)
  1488. return -EINVAL;
  1489. status = ice_flow_val_hdrs(segs, segs_cnt);
  1490. if (status)
  1491. return status;
  1492. mutex_lock(&hw->fl_profs_locks[blk]);
  1493. status = ice_flow_add_prof_sync(hw, blk, dir, segs, segs_cnt,
  1494. symm, prof);
  1495. if (!status)
  1496. list_add(&(*prof)->l_entry, &hw->fl_profs[blk]);
  1497. mutex_unlock(&hw->fl_profs_locks[blk]);
  1498. return status;
  1499. }
  1500. /**
  1501. * ice_flow_rem_prof - Remove a flow profile and all entries associated with it
  1502. * @hw: pointer to the HW struct
  1503. * @blk: the block for which the flow profile is to be removed
  1504. * @prof_id: unique ID of the flow profile to be removed
  1505. */
  1506. int ice_flow_rem_prof(struct ice_hw *hw, enum ice_block blk, u64 prof_id)
  1507. {
  1508. struct ice_flow_prof *prof;
  1509. int status;
  1510. mutex_lock(&hw->fl_profs_locks[blk]);
  1511. prof = ice_flow_find_prof_id(hw, blk, prof_id);
  1512. if (!prof) {
  1513. status = -ENOENT;
  1514. goto out;
  1515. }
  1516. /* prof becomes invalid after the call */
  1517. status = ice_flow_rem_prof_sync(hw, blk, prof);
  1518. out:
  1519. mutex_unlock(&hw->fl_profs_locks[blk]);
  1520. return status;
  1521. }
  1522. /**
  1523. * ice_flow_add_entry - Add a flow entry
  1524. * @hw: pointer to the HW struct
  1525. * @blk: classification stage
  1526. * @prof_id: ID of the profile to add a new flow entry to
  1527. * @entry_id: unique ID to identify this flow entry
  1528. * @vsi_handle: software VSI handle for the flow entry
  1529. * @prio: priority of the flow entry
  1530. * @data: pointer to a data buffer containing flow entry's match values/masks
  1531. * @entry_h: pointer to buffer that receives the new flow entry's handle
  1532. */
  1533. int
  1534. ice_flow_add_entry(struct ice_hw *hw, enum ice_block blk, u64 prof_id,
  1535. u64 entry_id, u16 vsi_handle, enum ice_flow_priority prio,
  1536. void *data, u64 *entry_h)
  1537. {
  1538. struct ice_flow_entry *e = NULL;
  1539. struct ice_flow_prof *prof;
  1540. int status;
  1541. /* No flow entry data is expected for RSS */
  1542. if (!entry_h || (!data && blk != ICE_BLK_RSS))
  1543. return -EINVAL;
  1544. if (!ice_is_vsi_valid(hw, vsi_handle))
  1545. return -EINVAL;
  1546. mutex_lock(&hw->fl_profs_locks[blk]);
  1547. prof = ice_flow_find_prof_id(hw, blk, prof_id);
  1548. if (!prof) {
  1549. status = -ENOENT;
  1550. } else {
  1551. /* Allocate memory for the entry being added and associate
  1552. * the VSI to the found flow profile
  1553. */
  1554. e = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*e), GFP_KERNEL);
  1555. if (!e)
  1556. status = -ENOMEM;
  1557. else
  1558. status = ice_flow_assoc_prof(hw, blk, prof, vsi_handle);
  1559. }
  1560. mutex_unlock(&hw->fl_profs_locks[blk]);
  1561. if (status)
  1562. goto out;
  1563. e->id = entry_id;
  1564. e->vsi_handle = vsi_handle;
  1565. e->prof = prof;
  1566. e->priority = prio;
  1567. switch (blk) {
  1568. case ICE_BLK_FD:
  1569. case ICE_BLK_RSS:
  1570. break;
  1571. default:
  1572. status = -EOPNOTSUPP;
  1573. goto out;
  1574. }
  1575. mutex_lock(&prof->entries_lock);
  1576. list_add(&e->l_entry, &prof->entries);
  1577. mutex_unlock(&prof->entries_lock);
  1578. *entry_h = ICE_FLOW_ENTRY_HNDL(e);
  1579. out:
  1580. if (status)
  1581. devm_kfree(ice_hw_to_dev(hw), e);
  1582. return status;
  1583. }
  1584. /**
  1585. * ice_flow_rem_entry - Remove a flow entry
  1586. * @hw: pointer to the HW struct
  1587. * @blk: classification stage
  1588. * @entry_h: handle to the flow entry to be removed
  1589. */
  1590. int ice_flow_rem_entry(struct ice_hw *hw, enum ice_block blk, u64 entry_h)
  1591. {
  1592. struct ice_flow_entry *entry;
  1593. struct ice_flow_prof *prof;
  1594. int status = 0;
  1595. if (entry_h == ICE_FLOW_ENTRY_HANDLE_INVAL)
  1596. return -EINVAL;
  1597. entry = ICE_FLOW_ENTRY_PTR(entry_h);
  1598. /* Retain the pointer to the flow profile as the entry will be freed */
  1599. prof = entry->prof;
  1600. if (prof) {
  1601. mutex_lock(&prof->entries_lock);
  1602. status = ice_flow_rem_entry_sync(hw, blk, entry);
  1603. mutex_unlock(&prof->entries_lock);
  1604. }
  1605. return status;
  1606. }
  1607. /**
  1608. * ice_flow_set_fld_ext - specifies locations of field from entry's input buffer
  1609. * @seg: packet segment the field being set belongs to
  1610. * @fld: field to be set
  1611. * @field_type: type of the field
  1612. * @val_loc: if not ICE_FLOW_FLD_OFF_INVAL, location of the value to match from
  1613. * entry's input buffer
  1614. * @mask_loc: if not ICE_FLOW_FLD_OFF_INVAL, location of mask value from entry's
  1615. * input buffer
  1616. * @last_loc: if not ICE_FLOW_FLD_OFF_INVAL, location of last/upper value from
  1617. * entry's input buffer
  1618. *
  1619. * This helper function stores information of a field being matched, including
  1620. * the type of the field and the locations of the value to match, the mask, and
  1621. * the upper-bound value in the start of the input buffer for a flow entry.
  1622. * This function should only be used for fixed-size data structures.
  1623. *
  1624. * This function also opportunistically determines the protocol headers to be
  1625. * present based on the fields being set. Some fields cannot be used alone to
  1626. * determine the protocol headers present. Sometimes, fields for particular
  1627. * protocol headers are not matched. In those cases, the protocol headers
  1628. * must be explicitly set.
  1629. */
  1630. static void
  1631. ice_flow_set_fld_ext(struct ice_flow_seg_info *seg, enum ice_flow_field fld,
  1632. enum ice_flow_fld_match_type field_type, u16 val_loc,
  1633. u16 mask_loc, u16 last_loc)
  1634. {
  1635. u64 bit = BIT_ULL(fld);
  1636. seg->match |= bit;
  1637. if (field_type == ICE_FLOW_FLD_TYPE_RANGE)
  1638. seg->range |= bit;
  1639. seg->fields[fld].type = field_type;
  1640. seg->fields[fld].src.val = val_loc;
  1641. seg->fields[fld].src.mask = mask_loc;
  1642. seg->fields[fld].src.last = last_loc;
  1643. ICE_FLOW_SET_HDRS(seg, ice_flds_info[fld].hdr);
  1644. }
  1645. /**
  1646. * ice_flow_set_fld - specifies locations of field from entry's input buffer
  1647. * @seg: packet segment the field being set belongs to
  1648. * @fld: field to be set
  1649. * @val_loc: if not ICE_FLOW_FLD_OFF_INVAL, location of the value to match from
  1650. * entry's input buffer
  1651. * @mask_loc: if not ICE_FLOW_FLD_OFF_INVAL, location of mask value from entry's
  1652. * input buffer
  1653. * @last_loc: if not ICE_FLOW_FLD_OFF_INVAL, location of last/upper value from
  1654. * entry's input buffer
  1655. * @range: indicate if field being matched is to be in a range
  1656. *
  1657. * This function specifies the locations, in the form of byte offsets from the
  1658. * start of the input buffer for a flow entry, from where the value to match,
  1659. * the mask value, and upper value can be extracted. These locations are then
  1660. * stored in the flow profile. When adding a flow entry associated with the
  1661. * flow profile, these locations will be used to quickly extract the values and
  1662. * create the content of a match entry. This function should only be used for
  1663. * fixed-size data structures.
  1664. */
  1665. void
  1666. ice_flow_set_fld(struct ice_flow_seg_info *seg, enum ice_flow_field fld,
  1667. u16 val_loc, u16 mask_loc, u16 last_loc, bool range)
  1668. {
  1669. enum ice_flow_fld_match_type t = range ?
  1670. ICE_FLOW_FLD_TYPE_RANGE : ICE_FLOW_FLD_TYPE_REG;
  1671. ice_flow_set_fld_ext(seg, fld, t, val_loc, mask_loc, last_loc);
  1672. }
  1673. /**
  1674. * ice_flow_add_fld_raw - sets locations of a raw field from entry's input buf
  1675. * @seg: packet segment the field being set belongs to
  1676. * @off: offset of the raw field from the beginning of the segment in bytes
  1677. * @len: length of the raw pattern to be matched
  1678. * @val_loc: location of the value to match from entry's input buffer
  1679. * @mask_loc: location of mask value from entry's input buffer
  1680. *
  1681. * This function specifies the offset of the raw field to be match from the
  1682. * beginning of the specified packet segment, and the locations, in the form of
  1683. * byte offsets from the start of the input buffer for a flow entry, from where
  1684. * the value to match and the mask value to be extracted. These locations are
  1685. * then stored in the flow profile. When adding flow entries to the associated
  1686. * flow profile, these locations can be used to quickly extract the values to
  1687. * create the content of a match entry. This function should only be used for
  1688. * fixed-size data structures.
  1689. */
  1690. void
  1691. ice_flow_add_fld_raw(struct ice_flow_seg_info *seg, u16 off, u8 len,
  1692. u16 val_loc, u16 mask_loc)
  1693. {
  1694. if (seg->raws_cnt < ICE_FLOW_SEG_RAW_FLD_MAX) {
  1695. seg->raws[seg->raws_cnt].off = off;
  1696. seg->raws[seg->raws_cnt].info.type = ICE_FLOW_FLD_TYPE_SIZE;
  1697. seg->raws[seg->raws_cnt].info.src.val = val_loc;
  1698. seg->raws[seg->raws_cnt].info.src.mask = mask_loc;
  1699. /* The "last" field is used to store the length of the field */
  1700. seg->raws[seg->raws_cnt].info.src.last = len;
  1701. }
  1702. /* Overflows of "raws" will be handled as an error condition later in
  1703. * the flow when this information is processed.
  1704. */
  1705. seg->raws_cnt++;
  1706. }
  1707. /**
  1708. * ice_flow_rem_vsi_prof - remove VSI from flow profile
  1709. * @hw: pointer to the hardware structure
  1710. * @vsi_handle: software VSI handle
  1711. * @prof_id: unique ID to identify this flow profile
  1712. *
  1713. * This function removes the flow entries associated to the input
  1714. * VSI handle and disassociate the VSI from the flow profile.
  1715. */
  1716. int ice_flow_rem_vsi_prof(struct ice_hw *hw, u16 vsi_handle, u64 prof_id)
  1717. {
  1718. struct ice_flow_prof *prof;
  1719. int status = 0;
  1720. if (!ice_is_vsi_valid(hw, vsi_handle))
  1721. return -EINVAL;
  1722. /* find flow profile pointer with input package block and profile ID */
  1723. prof = ice_flow_find_prof_id(hw, ICE_BLK_FD, prof_id);
  1724. if (!prof) {
  1725. ice_debug(hw, ICE_DBG_PKG, "Cannot find flow profile id=%llu\n",
  1726. prof_id);
  1727. return -ENOENT;
  1728. }
  1729. /* Remove all remaining flow entries before removing the flow profile */
  1730. if (!list_empty(&prof->entries)) {
  1731. struct ice_flow_entry *e, *t;
  1732. mutex_lock(&prof->entries_lock);
  1733. list_for_each_entry_safe(e, t, &prof->entries, l_entry) {
  1734. if (e->vsi_handle != vsi_handle)
  1735. continue;
  1736. status = ice_flow_rem_entry_sync(hw, ICE_BLK_FD, e);
  1737. if (status)
  1738. break;
  1739. }
  1740. mutex_unlock(&prof->entries_lock);
  1741. }
  1742. if (status)
  1743. return status;
  1744. /* disassociate the flow profile from sw VSI handle */
  1745. status = ice_flow_disassoc_prof(hw, ICE_BLK_FD, prof, vsi_handle);
  1746. if (status)
  1747. ice_debug(hw, ICE_DBG_PKG, "ice_flow_disassoc_prof() failed with status=%d\n",
  1748. status);
  1749. return status;
  1750. }
  1751. #define ICE_FLOW_RSS_SEG_HDR_L2_MASKS \
  1752. (ICE_FLOW_SEG_HDR_ETH | ICE_FLOW_SEG_HDR_VLAN)
  1753. #define ICE_FLOW_RSS_SEG_HDR_L3_MASKS \
  1754. (ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV6)
  1755. #define ICE_FLOW_RSS_SEG_HDR_L4_MASKS \
  1756. (ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_SCTP)
  1757. #define ICE_FLOW_RSS_SEG_HDR_VAL_MASKS \
  1758. (ICE_FLOW_RSS_SEG_HDR_L2_MASKS | \
  1759. ICE_FLOW_RSS_SEG_HDR_L3_MASKS | \
  1760. ICE_FLOW_RSS_SEG_HDR_L4_MASKS)
  1761. /**
  1762. * ice_flow_set_rss_seg_info - setup packet segments for RSS
  1763. * @segs: pointer to the flow field segment(s)
  1764. * @seg_cnt: segment count
  1765. * @cfg: configure parameters
  1766. *
  1767. * Helper function to extract fields from hash bitmap and use flow
  1768. * header value to set flow field segment for further use in flow
  1769. * profile entry or removal.
  1770. */
  1771. static int
  1772. ice_flow_set_rss_seg_info(struct ice_flow_seg_info *segs, u8 seg_cnt,
  1773. const struct ice_rss_hash_cfg *cfg)
  1774. {
  1775. struct ice_flow_seg_info *seg;
  1776. u64 val;
  1777. u16 i;
  1778. /* set inner most segment */
  1779. seg = &segs[seg_cnt - 1];
  1780. for_each_set_bit(i, (const unsigned long *)&cfg->hash_flds,
  1781. (u16)ICE_FLOW_FIELD_IDX_MAX)
  1782. ice_flow_set_fld(seg, (enum ice_flow_field)i,
  1783. ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL,
  1784. ICE_FLOW_FLD_OFF_INVAL, false);
  1785. ICE_FLOW_SET_HDRS(seg, cfg->addl_hdrs);
  1786. /* set outer most header */
  1787. if (cfg->hdr_type == ICE_RSS_INNER_HEADERS_W_OUTER_IPV4)
  1788. segs[ICE_RSS_OUTER_HEADERS].hdrs |= ICE_FLOW_SEG_HDR_IPV4 |
  1789. ICE_FLOW_SEG_HDR_IPV_OTHER;
  1790. else if (cfg->hdr_type == ICE_RSS_INNER_HEADERS_W_OUTER_IPV6)
  1791. segs[ICE_RSS_OUTER_HEADERS].hdrs |= ICE_FLOW_SEG_HDR_IPV6 |
  1792. ICE_FLOW_SEG_HDR_IPV_OTHER;
  1793. if (seg->hdrs & ~ICE_FLOW_RSS_SEG_HDR_VAL_MASKS &
  1794. ~ICE_FLOW_RSS_HDRS_INNER_MASK & ~ICE_FLOW_SEG_HDR_IPV_OTHER)
  1795. return -EINVAL;
  1796. val = (u64)(seg->hdrs & ICE_FLOW_RSS_SEG_HDR_L3_MASKS);
  1797. if (val && !is_power_of_2(val))
  1798. return -EIO;
  1799. val = (u64)(seg->hdrs & ICE_FLOW_RSS_SEG_HDR_L4_MASKS);
  1800. if (val && !is_power_of_2(val))
  1801. return -EIO;
  1802. return 0;
  1803. }
  1804. /**
  1805. * ice_rem_vsi_rss_list - remove VSI from RSS list
  1806. * @hw: pointer to the hardware structure
  1807. * @vsi_handle: software VSI handle
  1808. *
  1809. * Remove the VSI from all RSS configurations in the list.
  1810. */
  1811. void ice_rem_vsi_rss_list(struct ice_hw *hw, u16 vsi_handle)
  1812. {
  1813. struct ice_rss_cfg *r, *tmp;
  1814. if (list_empty(&hw->rss_list_head))
  1815. return;
  1816. mutex_lock(&hw->rss_locks);
  1817. list_for_each_entry_safe(r, tmp, &hw->rss_list_head, l_entry)
  1818. if (test_and_clear_bit(vsi_handle, r->vsis))
  1819. if (bitmap_empty(r->vsis, ICE_MAX_VSI)) {
  1820. list_del(&r->l_entry);
  1821. devm_kfree(ice_hw_to_dev(hw), r);
  1822. }
  1823. mutex_unlock(&hw->rss_locks);
  1824. }
  1825. /**
  1826. * ice_rem_vsi_rss_cfg - remove RSS configurations associated with VSI
  1827. * @hw: pointer to the hardware structure
  1828. * @vsi_handle: software VSI handle
  1829. *
  1830. * This function will iterate through all flow profiles and disassociate
  1831. * the VSI from that profile. If the flow profile has no VSIs it will
  1832. * be removed.
  1833. */
  1834. int ice_rem_vsi_rss_cfg(struct ice_hw *hw, u16 vsi_handle)
  1835. {
  1836. const enum ice_block blk = ICE_BLK_RSS;
  1837. struct ice_flow_prof *p, *t;
  1838. int status = 0;
  1839. if (!ice_is_vsi_valid(hw, vsi_handle))
  1840. return -EINVAL;
  1841. if (list_empty(&hw->fl_profs[blk]))
  1842. return 0;
  1843. mutex_lock(&hw->rss_locks);
  1844. list_for_each_entry_safe(p, t, &hw->fl_profs[blk], l_entry)
  1845. if (test_bit(vsi_handle, p->vsis)) {
  1846. status = ice_flow_disassoc_prof(hw, blk, p, vsi_handle);
  1847. if (status)
  1848. break;
  1849. if (bitmap_empty(p->vsis, ICE_MAX_VSI)) {
  1850. status = ice_flow_rem_prof(hw, blk, p->id);
  1851. if (status)
  1852. break;
  1853. }
  1854. }
  1855. mutex_unlock(&hw->rss_locks);
  1856. return status;
  1857. }
  1858. /**
  1859. * ice_get_rss_hdr_type - get a RSS profile's header type
  1860. * @prof: RSS flow profile
  1861. */
  1862. static enum ice_rss_cfg_hdr_type
  1863. ice_get_rss_hdr_type(struct ice_flow_prof *prof)
  1864. {
  1865. if (prof->segs_cnt == ICE_FLOW_SEG_SINGLE) {
  1866. return ICE_RSS_OUTER_HEADERS;
  1867. } else if (prof->segs_cnt == ICE_FLOW_SEG_MAX) {
  1868. const struct ice_flow_seg_info *s;
  1869. s = &prof->segs[ICE_RSS_OUTER_HEADERS];
  1870. if (s->hdrs == ICE_FLOW_SEG_HDR_NONE)
  1871. return ICE_RSS_INNER_HEADERS;
  1872. if (s->hdrs & ICE_FLOW_SEG_HDR_IPV4)
  1873. return ICE_RSS_INNER_HEADERS_W_OUTER_IPV4;
  1874. if (s->hdrs & ICE_FLOW_SEG_HDR_IPV6)
  1875. return ICE_RSS_INNER_HEADERS_W_OUTER_IPV6;
  1876. }
  1877. return ICE_RSS_ANY_HEADERS;
  1878. }
  1879. static bool
  1880. ice_rss_match_prof(struct ice_rss_cfg *r, struct ice_flow_prof *prof,
  1881. enum ice_rss_cfg_hdr_type hdr_type)
  1882. {
  1883. return (r->hash.hdr_type == hdr_type &&
  1884. r->hash.hash_flds == prof->segs[prof->segs_cnt - 1].match &&
  1885. r->hash.addl_hdrs == prof->segs[prof->segs_cnt - 1].hdrs);
  1886. }
  1887. /**
  1888. * ice_rem_rss_list - remove RSS configuration from list
  1889. * @hw: pointer to the hardware structure
  1890. * @vsi_handle: software VSI handle
  1891. * @prof: pointer to flow profile
  1892. *
  1893. * Assumption: lock has already been acquired for RSS list
  1894. */
  1895. static void
  1896. ice_rem_rss_list(struct ice_hw *hw, u16 vsi_handle, struct ice_flow_prof *prof)
  1897. {
  1898. enum ice_rss_cfg_hdr_type hdr_type;
  1899. struct ice_rss_cfg *r, *tmp;
  1900. /* Search for RSS hash fields associated to the VSI that match the
  1901. * hash configurations associated to the flow profile. If found
  1902. * remove from the RSS entry list of the VSI context and delete entry.
  1903. */
  1904. hdr_type = ice_get_rss_hdr_type(prof);
  1905. list_for_each_entry_safe(r, tmp, &hw->rss_list_head, l_entry)
  1906. if (ice_rss_match_prof(r, prof, hdr_type)) {
  1907. clear_bit(vsi_handle, r->vsis);
  1908. if (bitmap_empty(r->vsis, ICE_MAX_VSI)) {
  1909. list_del(&r->l_entry);
  1910. devm_kfree(ice_hw_to_dev(hw), r);
  1911. }
  1912. return;
  1913. }
  1914. }
  1915. /**
  1916. * ice_add_rss_list - add RSS configuration to list
  1917. * @hw: pointer to the hardware structure
  1918. * @vsi_handle: software VSI handle
  1919. * @prof: pointer to flow profile
  1920. *
  1921. * Assumption: lock has already been acquired for RSS list
  1922. */
  1923. static int
  1924. ice_add_rss_list(struct ice_hw *hw, u16 vsi_handle, struct ice_flow_prof *prof)
  1925. {
  1926. enum ice_rss_cfg_hdr_type hdr_type;
  1927. struct ice_rss_cfg *r, *rss_cfg;
  1928. hdr_type = ice_get_rss_hdr_type(prof);
  1929. list_for_each_entry(r, &hw->rss_list_head, l_entry)
  1930. if (ice_rss_match_prof(r, prof, hdr_type)) {
  1931. set_bit(vsi_handle, r->vsis);
  1932. return 0;
  1933. }
  1934. rss_cfg = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*rss_cfg),
  1935. GFP_KERNEL);
  1936. if (!rss_cfg)
  1937. return -ENOMEM;
  1938. rss_cfg->hash.hash_flds = prof->segs[prof->segs_cnt - 1].match;
  1939. rss_cfg->hash.addl_hdrs = prof->segs[prof->segs_cnt - 1].hdrs;
  1940. rss_cfg->hash.hdr_type = hdr_type;
  1941. rss_cfg->hash.symm = prof->symm;
  1942. set_bit(vsi_handle, rss_cfg->vsis);
  1943. list_add_tail(&rss_cfg->l_entry, &hw->rss_list_head);
  1944. return 0;
  1945. }
  1946. /**
  1947. * ice_rss_config_xor_word - set the HSYMM registers for one input set word
  1948. * @hw: pointer to the hardware structure
  1949. * @prof_id: RSS hardware profile id
  1950. * @src: the FV index used by the protocol's source field
  1951. * @dst: the FV index used by the protocol's destination field
  1952. *
  1953. * Write to the HSYMM register with the index of @src FV the value of the @dst
  1954. * FV index. This will tell the hardware to XOR HSYMM[src] with INSET[dst]
  1955. * while calculating the RSS input set.
  1956. */
  1957. static void
  1958. ice_rss_config_xor_word(struct ice_hw *hw, u8 prof_id, u8 src, u8 dst)
  1959. {
  1960. u32 val, reg, bits_shift;
  1961. u8 reg_idx;
  1962. reg_idx = src / GLQF_HSYMM_REG_SIZE;
  1963. bits_shift = ((src % GLQF_HSYMM_REG_SIZE) << 3);
  1964. val = dst | GLQF_HSYMM_ENABLE_BIT;
  1965. reg = rd32(hw, GLQF_HSYMM(prof_id, reg_idx));
  1966. reg = (reg & ~(0xff << bits_shift)) | (val << bits_shift);
  1967. wr32(hw, GLQF_HSYMM(prof_id, reg_idx), reg);
  1968. }
  1969. /**
  1970. * ice_rss_config_xor - set the symmetric registers for a profile's protocol
  1971. * @hw: pointer to the hardware structure
  1972. * @prof_id: RSS hardware profile id
  1973. * @src: the FV index used by the protocol's source field
  1974. * @dst: the FV index used by the protocol's destination field
  1975. * @len: length of the source/destination fields in words
  1976. */
  1977. static void
  1978. ice_rss_config_xor(struct ice_hw *hw, u8 prof_id, u8 src, u8 dst, u8 len)
  1979. {
  1980. int fv_last_word =
  1981. ICE_FLOW_SW_FIELD_VECTOR_MAX / ICE_FLOW_FV_EXTRACT_SZ - 1;
  1982. int i;
  1983. for (i = 0; i < len; i++) {
  1984. ice_rss_config_xor_word(hw, prof_id,
  1985. /* Yes, field vector in GLQF_HSYMM and
  1986. * GLQF_HINSET is inversed!
  1987. */
  1988. fv_last_word - (src + i),
  1989. fv_last_word - (dst + i));
  1990. ice_rss_config_xor_word(hw, prof_id,
  1991. fv_last_word - (dst + i),
  1992. fv_last_word - (src + i));
  1993. }
  1994. }
  1995. /**
  1996. * ice_rss_set_symm - set the symmetric settings for an RSS profile
  1997. * @hw: pointer to the hardware structure
  1998. * @prof: pointer to flow profile
  1999. *
  2000. * The symmetric hash will result from XORing the protocol's fields with
  2001. * indexes in GLQF_HSYMM and GLQF_HINSET. This function configures the profile's
  2002. * GLQF_HSYMM registers.
  2003. */
  2004. static void ice_rss_set_symm(struct ice_hw *hw, struct ice_flow_prof *prof)
  2005. {
  2006. struct ice_prof_map *map;
  2007. u8 prof_id, m;
  2008. mutex_lock(&hw->blk[ICE_BLK_RSS].es.prof_map_lock);
  2009. map = ice_search_prof_id(hw, ICE_BLK_RSS, prof->id);
  2010. if (map)
  2011. prof_id = map->prof_id;
  2012. mutex_unlock(&hw->blk[ICE_BLK_RSS].es.prof_map_lock);
  2013. if (!map)
  2014. return;
  2015. /* clear to default */
  2016. for (m = 0; m < GLQF_HSYMM_REG_PER_PROF; m++)
  2017. wr32(hw, GLQF_HSYMM(prof_id, m), 0);
  2018. if (prof->symm) {
  2019. struct ice_flow_seg_xtrct *ipv4_src, *ipv4_dst;
  2020. struct ice_flow_seg_xtrct *ipv6_src, *ipv6_dst;
  2021. struct ice_flow_seg_xtrct *sctp_src, *sctp_dst;
  2022. struct ice_flow_seg_xtrct *tcp_src, *tcp_dst;
  2023. struct ice_flow_seg_xtrct *udp_src, *udp_dst;
  2024. struct ice_flow_seg_info *seg;
  2025. seg = &prof->segs[prof->segs_cnt - 1];
  2026. ipv4_src = &seg->fields[ICE_FLOW_FIELD_IDX_IPV4_SA].xtrct;
  2027. ipv4_dst = &seg->fields[ICE_FLOW_FIELD_IDX_IPV4_DA].xtrct;
  2028. ipv6_src = &seg->fields[ICE_FLOW_FIELD_IDX_IPV6_SA].xtrct;
  2029. ipv6_dst = &seg->fields[ICE_FLOW_FIELD_IDX_IPV6_DA].xtrct;
  2030. tcp_src = &seg->fields[ICE_FLOW_FIELD_IDX_TCP_SRC_PORT].xtrct;
  2031. tcp_dst = &seg->fields[ICE_FLOW_FIELD_IDX_TCP_DST_PORT].xtrct;
  2032. udp_src = &seg->fields[ICE_FLOW_FIELD_IDX_UDP_SRC_PORT].xtrct;
  2033. udp_dst = &seg->fields[ICE_FLOW_FIELD_IDX_UDP_DST_PORT].xtrct;
  2034. sctp_src = &seg->fields[ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT].xtrct;
  2035. sctp_dst = &seg->fields[ICE_FLOW_FIELD_IDX_SCTP_DST_PORT].xtrct;
  2036. /* xor IPv4 */
  2037. if (ipv4_src->prot_id != 0 && ipv4_dst->prot_id != 0)
  2038. ice_rss_config_xor(hw, prof_id,
  2039. ipv4_src->idx, ipv4_dst->idx, 2);
  2040. /* xor IPv6 */
  2041. if (ipv6_src->prot_id != 0 && ipv6_dst->prot_id != 0)
  2042. ice_rss_config_xor(hw, prof_id,
  2043. ipv6_src->idx, ipv6_dst->idx, 8);
  2044. /* xor TCP */
  2045. if (tcp_src->prot_id != 0 && tcp_dst->prot_id != 0)
  2046. ice_rss_config_xor(hw, prof_id,
  2047. tcp_src->idx, tcp_dst->idx, 1);
  2048. /* xor UDP */
  2049. if (udp_src->prot_id != 0 && udp_dst->prot_id != 0)
  2050. ice_rss_config_xor(hw, prof_id,
  2051. udp_src->idx, udp_dst->idx, 1);
  2052. /* xor SCTP */
  2053. if (sctp_src->prot_id != 0 && sctp_dst->prot_id != 0)
  2054. ice_rss_config_xor(hw, prof_id,
  2055. sctp_src->idx, sctp_dst->idx, 1);
  2056. }
  2057. }
  2058. /**
  2059. * ice_add_rss_cfg_sync - add an RSS configuration
  2060. * @hw: pointer to the hardware structure
  2061. * @vsi_handle: software VSI handle
  2062. * @cfg: configure parameters
  2063. *
  2064. * Assumption: lock has already been acquired for RSS list
  2065. */
  2066. static int
  2067. ice_add_rss_cfg_sync(struct ice_hw *hw, u16 vsi_handle,
  2068. const struct ice_rss_hash_cfg *cfg)
  2069. {
  2070. const enum ice_block blk = ICE_BLK_RSS;
  2071. struct ice_flow_prof *prof = NULL;
  2072. struct ice_flow_seg_info *segs;
  2073. u8 segs_cnt;
  2074. int status;
  2075. segs_cnt = (cfg->hdr_type == ICE_RSS_OUTER_HEADERS) ?
  2076. ICE_FLOW_SEG_SINGLE : ICE_FLOW_SEG_MAX;
  2077. segs = kcalloc(segs_cnt, sizeof(*segs), GFP_KERNEL);
  2078. if (!segs)
  2079. return -ENOMEM;
  2080. /* Construct the packet segment info from the hashed fields */
  2081. status = ice_flow_set_rss_seg_info(segs, segs_cnt, cfg);
  2082. if (status)
  2083. goto exit;
  2084. /* Search for a flow profile that has matching headers, hash fields,
  2085. * symm and has the input VSI associated to it. If found, no further
  2086. * operations required and exit.
  2087. */
  2088. prof = ice_flow_find_prof_conds(hw, blk, ICE_FLOW_RX, segs, segs_cnt,
  2089. cfg->symm, vsi_handle,
  2090. ICE_FLOW_FIND_PROF_CHK_FLDS |
  2091. ICE_FLOW_FIND_PROF_CHK_SYMM |
  2092. ICE_FLOW_FIND_PROF_CHK_VSI);
  2093. if (prof)
  2094. goto exit;
  2095. /* Check if a flow profile exists with the same protocol headers and
  2096. * associated with the input VSI. If so disassociate the VSI from
  2097. * this profile. The VSI will be added to a new profile created with
  2098. * the protocol header and new hash field configuration.
  2099. */
  2100. prof = ice_flow_find_prof_conds(hw, blk, ICE_FLOW_RX, segs, segs_cnt,
  2101. cfg->symm, vsi_handle,
  2102. ICE_FLOW_FIND_PROF_CHK_VSI);
  2103. if (prof) {
  2104. status = ice_flow_disassoc_prof(hw, blk, prof, vsi_handle);
  2105. if (!status)
  2106. ice_rem_rss_list(hw, vsi_handle, prof);
  2107. else
  2108. goto exit;
  2109. /* Remove profile if it has no VSIs associated */
  2110. if (bitmap_empty(prof->vsis, ICE_MAX_VSI)) {
  2111. status = ice_flow_rem_prof(hw, blk, prof->id);
  2112. if (status)
  2113. goto exit;
  2114. }
  2115. }
  2116. /* Search for a profile that has the same match fields and symmetric
  2117. * setting. If this exists then associate the VSI to this profile.
  2118. */
  2119. prof = ice_flow_find_prof_conds(hw, blk, ICE_FLOW_RX, segs, segs_cnt,
  2120. cfg->symm, vsi_handle,
  2121. ICE_FLOW_FIND_PROF_CHK_SYMM |
  2122. ICE_FLOW_FIND_PROF_CHK_FLDS);
  2123. if (prof) {
  2124. status = ice_flow_assoc_prof(hw, blk, prof, vsi_handle);
  2125. if (!status)
  2126. status = ice_add_rss_list(hw, vsi_handle, prof);
  2127. goto exit;
  2128. }
  2129. /* Create a new flow profile with packet segment information. */
  2130. status = ice_flow_add_prof(hw, blk, ICE_FLOW_RX,
  2131. segs, segs_cnt, cfg->symm, &prof);
  2132. if (status)
  2133. goto exit;
  2134. prof->symm = cfg->symm;
  2135. ice_rss_set_symm(hw, prof);
  2136. status = ice_flow_assoc_prof(hw, blk, prof, vsi_handle);
  2137. /* If association to a new flow profile failed then this profile can
  2138. * be removed.
  2139. */
  2140. if (status) {
  2141. ice_flow_rem_prof(hw, blk, prof->id);
  2142. goto exit;
  2143. }
  2144. status = ice_add_rss_list(hw, vsi_handle, prof);
  2145. exit:
  2146. kfree(segs);
  2147. return status;
  2148. }
  2149. /**
  2150. * ice_add_rss_cfg - add an RSS configuration with specified hashed fields
  2151. * @hw: pointer to the hardware structure
  2152. * @vsi: VSI to add the RSS configuration to
  2153. * @cfg: configure parameters
  2154. *
  2155. * This function will generate a flow profile based on fields associated with
  2156. * the input fields to hash on, the flow type and use the VSI number to add
  2157. * a flow entry to the profile.
  2158. */
  2159. int
  2160. ice_add_rss_cfg(struct ice_hw *hw, struct ice_vsi *vsi,
  2161. const struct ice_rss_hash_cfg *cfg)
  2162. {
  2163. struct ice_rss_hash_cfg local_cfg;
  2164. u16 vsi_handle;
  2165. int status;
  2166. if (!vsi)
  2167. return -EINVAL;
  2168. vsi_handle = vsi->idx;
  2169. if (!ice_is_vsi_valid(hw, vsi_handle) ||
  2170. !cfg || cfg->hdr_type > ICE_RSS_ANY_HEADERS ||
  2171. cfg->hash_flds == ICE_HASH_INVALID)
  2172. return -EINVAL;
  2173. mutex_lock(&hw->rss_locks);
  2174. local_cfg = *cfg;
  2175. if (cfg->hdr_type < ICE_RSS_ANY_HEADERS) {
  2176. status = ice_add_rss_cfg_sync(hw, vsi_handle, &local_cfg);
  2177. } else {
  2178. local_cfg.hdr_type = ICE_RSS_OUTER_HEADERS;
  2179. status = ice_add_rss_cfg_sync(hw, vsi_handle, &local_cfg);
  2180. if (!status) {
  2181. local_cfg.hdr_type = ICE_RSS_INNER_HEADERS;
  2182. status = ice_add_rss_cfg_sync(hw, vsi_handle,
  2183. &local_cfg);
  2184. }
  2185. }
  2186. mutex_unlock(&hw->rss_locks);
  2187. return status;
  2188. }
  2189. /**
  2190. * ice_rem_rss_cfg_sync - remove an existing RSS configuration
  2191. * @hw: pointer to the hardware structure
  2192. * @vsi_handle: software VSI handle
  2193. * @cfg: configure parameters
  2194. *
  2195. * Assumption: lock has already been acquired for RSS list
  2196. */
  2197. static int
  2198. ice_rem_rss_cfg_sync(struct ice_hw *hw, u16 vsi_handle,
  2199. const struct ice_rss_hash_cfg *cfg)
  2200. {
  2201. const enum ice_block blk = ICE_BLK_RSS;
  2202. struct ice_flow_seg_info *segs;
  2203. struct ice_flow_prof *prof;
  2204. u8 segs_cnt;
  2205. int status;
  2206. segs_cnt = (cfg->hdr_type == ICE_RSS_OUTER_HEADERS) ?
  2207. ICE_FLOW_SEG_SINGLE : ICE_FLOW_SEG_MAX;
  2208. segs = kcalloc(segs_cnt, sizeof(*segs), GFP_KERNEL);
  2209. if (!segs)
  2210. return -ENOMEM;
  2211. /* Construct the packet segment info from the hashed fields */
  2212. status = ice_flow_set_rss_seg_info(segs, segs_cnt, cfg);
  2213. if (status)
  2214. goto out;
  2215. prof = ice_flow_find_prof_conds(hw, blk, ICE_FLOW_RX, segs, segs_cnt,
  2216. cfg->symm, vsi_handle,
  2217. ICE_FLOW_FIND_PROF_CHK_FLDS);
  2218. if (!prof) {
  2219. status = -ENOENT;
  2220. goto out;
  2221. }
  2222. status = ice_flow_disassoc_prof(hw, blk, prof, vsi_handle);
  2223. if (status)
  2224. goto out;
  2225. /* Remove RSS configuration from VSI context before deleting
  2226. * the flow profile.
  2227. */
  2228. ice_rem_rss_list(hw, vsi_handle, prof);
  2229. if (bitmap_empty(prof->vsis, ICE_MAX_VSI))
  2230. status = ice_flow_rem_prof(hw, blk, prof->id);
  2231. out:
  2232. kfree(segs);
  2233. return status;
  2234. }
  2235. /**
  2236. * ice_rem_rss_cfg - remove an existing RSS config with matching hashed fields
  2237. * @hw: pointer to the hardware structure
  2238. * @vsi_handle: software VSI handle
  2239. * @cfg: configure parameters
  2240. *
  2241. * This function will lookup the flow profile based on the input
  2242. * hash field bitmap, iterate through the profile entry list of
  2243. * that profile and find entry associated with input VSI to be
  2244. * removed. Calls are made to underlying flow apis which will in
  2245. * turn build or update buffers for RSS XLT1 section.
  2246. */
  2247. int
  2248. ice_rem_rss_cfg(struct ice_hw *hw, u16 vsi_handle,
  2249. const struct ice_rss_hash_cfg *cfg)
  2250. {
  2251. struct ice_rss_hash_cfg local_cfg;
  2252. int status;
  2253. if (!ice_is_vsi_valid(hw, vsi_handle) ||
  2254. !cfg || cfg->hdr_type > ICE_RSS_ANY_HEADERS ||
  2255. cfg->hash_flds == ICE_HASH_INVALID)
  2256. return -EINVAL;
  2257. mutex_lock(&hw->rss_locks);
  2258. local_cfg = *cfg;
  2259. if (cfg->hdr_type < ICE_RSS_ANY_HEADERS) {
  2260. status = ice_rem_rss_cfg_sync(hw, vsi_handle, &local_cfg);
  2261. } else {
  2262. local_cfg.hdr_type = ICE_RSS_OUTER_HEADERS;
  2263. status = ice_rem_rss_cfg_sync(hw, vsi_handle, &local_cfg);
  2264. if (!status) {
  2265. local_cfg.hdr_type = ICE_RSS_INNER_HEADERS;
  2266. status = ice_rem_rss_cfg_sync(hw, vsi_handle,
  2267. &local_cfg);
  2268. }
  2269. }
  2270. mutex_unlock(&hw->rss_locks);
  2271. return status;
  2272. }
  2273. /* Mapping of AVF hash bit fields to an L3-L4 hash combination.
  2274. * As the ice_flow_avf_hdr_field represent individual bit shifts in a hash,
  2275. * convert its values to their appropriate flow L3, L4 values.
  2276. */
  2277. #define ICE_FLOW_AVF_RSS_IPV4_MASKS \
  2278. (BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_OTHER) | \
  2279. BIT_ULL(ICE_AVF_FLOW_FIELD_FRAG_IPV4))
  2280. #define ICE_FLOW_AVF_RSS_TCP_IPV4_MASKS \
  2281. (BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_TCP_SYN_NO_ACK) | \
  2282. BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_TCP))
  2283. #define ICE_FLOW_AVF_RSS_UDP_IPV4_MASKS \
  2284. (BIT_ULL(ICE_AVF_FLOW_FIELD_UNICAST_IPV4_UDP) | \
  2285. BIT_ULL(ICE_AVF_FLOW_FIELD_MULTICAST_IPV4_UDP) | \
  2286. BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_UDP))
  2287. #define ICE_FLOW_AVF_RSS_ALL_IPV4_MASKS \
  2288. (ICE_FLOW_AVF_RSS_TCP_IPV4_MASKS | ICE_FLOW_AVF_RSS_UDP_IPV4_MASKS | \
  2289. ICE_FLOW_AVF_RSS_IPV4_MASKS | BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_SCTP))
  2290. #define ICE_FLOW_AVF_RSS_IPV6_MASKS \
  2291. (BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_OTHER) | \
  2292. BIT_ULL(ICE_AVF_FLOW_FIELD_FRAG_IPV6))
  2293. #define ICE_FLOW_AVF_RSS_UDP_IPV6_MASKS \
  2294. (BIT_ULL(ICE_AVF_FLOW_FIELD_UNICAST_IPV6_UDP) | \
  2295. BIT_ULL(ICE_AVF_FLOW_FIELD_MULTICAST_IPV6_UDP) | \
  2296. BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_UDP))
  2297. #define ICE_FLOW_AVF_RSS_TCP_IPV6_MASKS \
  2298. (BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_TCP_SYN_NO_ACK) | \
  2299. BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_TCP))
  2300. #define ICE_FLOW_AVF_RSS_ALL_IPV6_MASKS \
  2301. (ICE_FLOW_AVF_RSS_TCP_IPV6_MASKS | ICE_FLOW_AVF_RSS_UDP_IPV6_MASKS | \
  2302. ICE_FLOW_AVF_RSS_IPV6_MASKS | BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_SCTP))
  2303. /**
  2304. * ice_add_avf_rss_cfg - add an RSS configuration for AVF driver
  2305. * @hw: pointer to the hardware structure
  2306. * @vsi: VF's VSI
  2307. * @avf_hash: hash bit fields (ICE_AVF_FLOW_FIELD_*) to configure
  2308. *
  2309. * This function will take the hash bitmap provided by the AVF driver via a
  2310. * message, convert it to ICE-compatible values, and configure RSS flow
  2311. * profiles.
  2312. */
  2313. int ice_add_avf_rss_cfg(struct ice_hw *hw, struct ice_vsi *vsi, u64 avf_hash)
  2314. {
  2315. struct ice_rss_hash_cfg hcfg;
  2316. u16 vsi_handle;
  2317. int status = 0;
  2318. u64 hash_flds;
  2319. if (!vsi)
  2320. return -EINVAL;
  2321. vsi_handle = vsi->idx;
  2322. if (avf_hash == ICE_AVF_FLOW_FIELD_INVALID ||
  2323. !ice_is_vsi_valid(hw, vsi_handle))
  2324. return -EINVAL;
  2325. /* Make sure no unsupported bits are specified */
  2326. if (avf_hash & ~(ICE_FLOW_AVF_RSS_ALL_IPV4_MASKS |
  2327. ICE_FLOW_AVF_RSS_ALL_IPV6_MASKS))
  2328. return -EIO;
  2329. hash_flds = avf_hash;
  2330. /* Always create an L3 RSS configuration for any L4 RSS configuration */
  2331. if (hash_flds & ICE_FLOW_AVF_RSS_ALL_IPV4_MASKS)
  2332. hash_flds |= ICE_FLOW_AVF_RSS_IPV4_MASKS;
  2333. if (hash_flds & ICE_FLOW_AVF_RSS_ALL_IPV6_MASKS)
  2334. hash_flds |= ICE_FLOW_AVF_RSS_IPV6_MASKS;
  2335. /* Create the corresponding RSS configuration for each valid hash bit */
  2336. while (hash_flds) {
  2337. u64 rss_hash = ICE_HASH_INVALID;
  2338. if (hash_flds & ICE_FLOW_AVF_RSS_ALL_IPV4_MASKS) {
  2339. if (hash_flds & ICE_FLOW_AVF_RSS_IPV4_MASKS) {
  2340. rss_hash = ICE_FLOW_HASH_IPV4;
  2341. hash_flds &= ~ICE_FLOW_AVF_RSS_IPV4_MASKS;
  2342. } else if (hash_flds &
  2343. ICE_FLOW_AVF_RSS_TCP_IPV4_MASKS) {
  2344. rss_hash = ICE_FLOW_HASH_IPV4 |
  2345. ICE_FLOW_HASH_TCP_PORT;
  2346. hash_flds &= ~ICE_FLOW_AVF_RSS_TCP_IPV4_MASKS;
  2347. } else if (hash_flds &
  2348. ICE_FLOW_AVF_RSS_UDP_IPV4_MASKS) {
  2349. rss_hash = ICE_FLOW_HASH_IPV4 |
  2350. ICE_FLOW_HASH_UDP_PORT;
  2351. hash_flds &= ~ICE_FLOW_AVF_RSS_UDP_IPV4_MASKS;
  2352. } else if (hash_flds &
  2353. BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_SCTP)) {
  2354. rss_hash = ICE_FLOW_HASH_IPV4 |
  2355. ICE_FLOW_HASH_SCTP_PORT;
  2356. hash_flds &=
  2357. ~BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_SCTP);
  2358. }
  2359. } else if (hash_flds & ICE_FLOW_AVF_RSS_ALL_IPV6_MASKS) {
  2360. if (hash_flds & ICE_FLOW_AVF_RSS_IPV6_MASKS) {
  2361. rss_hash = ICE_FLOW_HASH_IPV6;
  2362. hash_flds &= ~ICE_FLOW_AVF_RSS_IPV6_MASKS;
  2363. } else if (hash_flds &
  2364. ICE_FLOW_AVF_RSS_TCP_IPV6_MASKS) {
  2365. rss_hash = ICE_FLOW_HASH_IPV6 |
  2366. ICE_FLOW_HASH_TCP_PORT;
  2367. hash_flds &= ~ICE_FLOW_AVF_RSS_TCP_IPV6_MASKS;
  2368. } else if (hash_flds &
  2369. ICE_FLOW_AVF_RSS_UDP_IPV6_MASKS) {
  2370. rss_hash = ICE_FLOW_HASH_IPV6 |
  2371. ICE_FLOW_HASH_UDP_PORT;
  2372. hash_flds &= ~ICE_FLOW_AVF_RSS_UDP_IPV6_MASKS;
  2373. } else if (hash_flds &
  2374. BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_SCTP)) {
  2375. rss_hash = ICE_FLOW_HASH_IPV6 |
  2376. ICE_FLOW_HASH_SCTP_PORT;
  2377. hash_flds &=
  2378. ~BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_SCTP);
  2379. }
  2380. }
  2381. if (rss_hash == ICE_HASH_INVALID)
  2382. return -EIO;
  2383. hcfg.addl_hdrs = ICE_FLOW_SEG_HDR_NONE;
  2384. hcfg.hash_flds = rss_hash;
  2385. hcfg.hdr_type = ICE_RSS_ANY_HEADERS;
  2386. hcfg.symm = false;
  2387. status = ice_add_rss_cfg(hw, vsi, &hcfg);
  2388. if (status)
  2389. break;
  2390. }
  2391. return status;
  2392. }
  2393. static bool rss_cfg_symm_valid(u64 hfld)
  2394. {
  2395. return !((!!(hfld & ICE_FLOW_HASH_FLD_IPV4_SA) ^
  2396. !!(hfld & ICE_FLOW_HASH_FLD_IPV4_DA)) ||
  2397. (!!(hfld & ICE_FLOW_HASH_FLD_IPV6_SA) ^
  2398. !!(hfld & ICE_FLOW_HASH_FLD_IPV6_DA)) ||
  2399. (!!(hfld & ICE_FLOW_HASH_FLD_TCP_SRC_PORT) ^
  2400. !!(hfld & ICE_FLOW_HASH_FLD_TCP_DST_PORT)) ||
  2401. (!!(hfld & ICE_FLOW_HASH_FLD_UDP_SRC_PORT) ^
  2402. !!(hfld & ICE_FLOW_HASH_FLD_UDP_DST_PORT)) ||
  2403. (!!(hfld & ICE_FLOW_HASH_FLD_SCTP_SRC_PORT) ^
  2404. !!(hfld & ICE_FLOW_HASH_FLD_SCTP_DST_PORT)));
  2405. }
  2406. /**
  2407. * ice_set_rss_cfg_symm - set symmtery for all VSI's RSS configurations
  2408. * @hw: pointer to the hardware structure
  2409. * @vsi: VSI to set/unset Symmetric RSS
  2410. * @symm: TRUE to set Symmetric RSS hashing
  2411. */
  2412. int ice_set_rss_cfg_symm(struct ice_hw *hw, struct ice_vsi *vsi, bool symm)
  2413. {
  2414. struct ice_rss_hash_cfg local;
  2415. struct ice_rss_cfg *r, *tmp;
  2416. u16 vsi_handle = vsi->idx;
  2417. int status = 0;
  2418. if (!ice_is_vsi_valid(hw, vsi_handle))
  2419. return -EINVAL;
  2420. mutex_lock(&hw->rss_locks);
  2421. list_for_each_entry_safe(r, tmp, &hw->rss_list_head, l_entry) {
  2422. if (test_bit(vsi_handle, r->vsis) && r->hash.symm != symm) {
  2423. local = r->hash;
  2424. local.symm = symm;
  2425. if (symm && !rss_cfg_symm_valid(r->hash.hash_flds))
  2426. continue;
  2427. status = ice_add_rss_cfg_sync(hw, vsi_handle, &local);
  2428. if (status)
  2429. break;
  2430. }
  2431. }
  2432. mutex_unlock(&hw->rss_locks);
  2433. return status;
  2434. }
  2435. /**
  2436. * ice_replay_rss_cfg - replay RSS configurations associated with VSI
  2437. * @hw: pointer to the hardware structure
  2438. * @vsi_handle: software VSI handle
  2439. */
  2440. int ice_replay_rss_cfg(struct ice_hw *hw, u16 vsi_handle)
  2441. {
  2442. struct ice_rss_cfg *r;
  2443. int status = 0;
  2444. if (!ice_is_vsi_valid(hw, vsi_handle))
  2445. return -EINVAL;
  2446. mutex_lock(&hw->rss_locks);
  2447. list_for_each_entry(r, &hw->rss_list_head, l_entry) {
  2448. if (test_bit(vsi_handle, r->vsis)) {
  2449. status = ice_add_rss_cfg_sync(hw, vsi_handle, &r->hash);
  2450. if (status)
  2451. break;
  2452. }
  2453. }
  2454. mutex_unlock(&hw->rss_locks);
  2455. return status;
  2456. }
  2457. /**
  2458. * ice_get_rss_cfg - returns hashed fields for the given header types
  2459. * @hw: pointer to the hardware structure
  2460. * @vsi_handle: software VSI handle
  2461. * @hdrs: protocol header type
  2462. * @symm: whether the RSS is symmetric (bool, output)
  2463. *
  2464. * This function will return the match fields of the first instance of flow
  2465. * profile having the given header types and containing input VSI
  2466. */
  2467. u64 ice_get_rss_cfg(struct ice_hw *hw, u16 vsi_handle, u32 hdrs, bool *symm)
  2468. {
  2469. u64 rss_hash = ICE_HASH_INVALID;
  2470. struct ice_rss_cfg *r;
  2471. /* verify if the protocol header is non zero and VSI is valid */
  2472. if (hdrs == ICE_FLOW_SEG_HDR_NONE || !ice_is_vsi_valid(hw, vsi_handle))
  2473. return ICE_HASH_INVALID;
  2474. mutex_lock(&hw->rss_locks);
  2475. list_for_each_entry(r, &hw->rss_list_head, l_entry)
  2476. if (test_bit(vsi_handle, r->vsis) &&
  2477. r->hash.addl_hdrs == hdrs) {
  2478. rss_hash = r->hash.hash_flds;
  2479. *symm = r->hash.symm;
  2480. break;
  2481. }
  2482. mutex_unlock(&hw->rss_locks);
  2483. return rss_hash;
  2484. }