ice_parser.c 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright (C) 2024 Intel Corporation */
  3. #include "ice_common.h"
  4. struct ice_pkg_sect_hdr {
  5. __le16 count;
  6. __le16 offset;
  7. };
  8. /**
  9. * ice_parser_sect_item_get - parse an item from a section
  10. * @sect_type: section type
  11. * @section: section object
  12. * @index: index of the item to get
  13. * @offset: dummy as prototype of ice_pkg_enum_entry's last parameter
  14. *
  15. * Return: a pointer to the item or NULL.
  16. */
  17. static void *ice_parser_sect_item_get(u32 sect_type, void *section,
  18. u32 index, u32 __maybe_unused *offset)
  19. {
  20. size_t data_off = ICE_SEC_DATA_OFFSET;
  21. struct ice_pkg_sect_hdr *hdr;
  22. size_t size;
  23. if (!section)
  24. return NULL;
  25. switch (sect_type) {
  26. case ICE_SID_RXPARSER_IMEM:
  27. size = ICE_SID_RXPARSER_IMEM_ENTRY_SIZE;
  28. break;
  29. case ICE_SID_RXPARSER_METADATA_INIT:
  30. size = ICE_SID_RXPARSER_METADATA_INIT_ENTRY_SIZE;
  31. break;
  32. case ICE_SID_RXPARSER_CAM:
  33. size = ICE_SID_RXPARSER_CAM_ENTRY_SIZE;
  34. break;
  35. case ICE_SID_RXPARSER_PG_SPILL:
  36. size = ICE_SID_RXPARSER_PG_SPILL_ENTRY_SIZE;
  37. break;
  38. case ICE_SID_RXPARSER_NOMATCH_CAM:
  39. size = ICE_SID_RXPARSER_NOMATCH_CAM_ENTRY_SIZE;
  40. break;
  41. case ICE_SID_RXPARSER_NOMATCH_SPILL:
  42. size = ICE_SID_RXPARSER_NOMATCH_SPILL_ENTRY_SIZE;
  43. break;
  44. case ICE_SID_RXPARSER_BOOST_TCAM:
  45. size = ICE_SID_RXPARSER_BOOST_TCAM_ENTRY_SIZE;
  46. break;
  47. case ICE_SID_LBL_RXPARSER_TMEM:
  48. data_off = ICE_SEC_LBL_DATA_OFFSET;
  49. size = ICE_SID_LBL_ENTRY_SIZE;
  50. break;
  51. case ICE_SID_RXPARSER_MARKER_PTYPE:
  52. size = ICE_SID_RXPARSER_MARKER_TYPE_ENTRY_SIZE;
  53. break;
  54. case ICE_SID_RXPARSER_MARKER_GRP:
  55. size = ICE_SID_RXPARSER_MARKER_GRP_ENTRY_SIZE;
  56. break;
  57. case ICE_SID_RXPARSER_PROTO_GRP:
  58. size = ICE_SID_RXPARSER_PROTO_GRP_ENTRY_SIZE;
  59. break;
  60. case ICE_SID_RXPARSER_FLAG_REDIR:
  61. size = ICE_SID_RXPARSER_FLAG_REDIR_ENTRY_SIZE;
  62. break;
  63. default:
  64. return NULL;
  65. }
  66. hdr = section;
  67. if (index >= le16_to_cpu(hdr->count))
  68. return NULL;
  69. return section + data_off + index * size;
  70. }
  71. /**
  72. * ice_parser_create_table - create an item table from a section
  73. * @hw: pointer to the hardware structure
  74. * @sect_type: section type
  75. * @item_size: item size in bytes
  76. * @length: number of items in the table to create
  77. * @parse_item: the function to parse the item
  78. * @no_offset: ignore header offset, calculate index from 0
  79. *
  80. * Return: a pointer to the allocated table or ERR_PTR.
  81. */
  82. static void *
  83. ice_parser_create_table(struct ice_hw *hw, u32 sect_type,
  84. u32 item_size, u32 length,
  85. void (*parse_item)(struct ice_hw *hw, u16 idx,
  86. void *item, void *data,
  87. int size), bool no_offset)
  88. {
  89. struct ice_pkg_enum state = {};
  90. struct ice_seg *seg = hw->seg;
  91. void *table, *data, *item;
  92. u16 idx = 0;
  93. if (!seg)
  94. return ERR_PTR(-EINVAL);
  95. table = kzalloc(item_size * length, GFP_KERNEL);
  96. if (!table)
  97. return ERR_PTR(-ENOMEM);
  98. do {
  99. data = ice_pkg_enum_entry(seg, &state, sect_type, NULL,
  100. ice_parser_sect_item_get);
  101. seg = NULL;
  102. if (data) {
  103. struct ice_pkg_sect_hdr *hdr = state.sect;
  104. if (!no_offset)
  105. idx = le16_to_cpu(hdr->offset) +
  106. state.entry_idx;
  107. item = (void *)((uintptr_t)table + idx * item_size);
  108. parse_item(hw, idx, item, data, item_size);
  109. if (no_offset)
  110. idx++;
  111. }
  112. } while (data);
  113. return table;
  114. }
  115. /*** ICE_SID_RXPARSER_IMEM section ***/
  116. static void ice_imem_bst_bm_dump(struct ice_hw *hw, struct ice_bst_main *bm)
  117. {
  118. struct device *dev = ice_hw_to_dev(hw);
  119. dev_info(dev, "boost main:\n");
  120. dev_info(dev, "\talu0 = %d\n", bm->alu0);
  121. dev_info(dev, "\talu1 = %d\n", bm->alu1);
  122. dev_info(dev, "\talu2 = %d\n", bm->alu2);
  123. dev_info(dev, "\tpg = %d\n", bm->pg);
  124. }
  125. static void ice_imem_bst_kb_dump(struct ice_hw *hw,
  126. struct ice_bst_keybuilder *kb)
  127. {
  128. struct device *dev = ice_hw_to_dev(hw);
  129. dev_info(dev, "boost key builder:\n");
  130. dev_info(dev, "\tpriority = %d\n", kb->prio);
  131. dev_info(dev, "\ttsr_ctrl = %d\n", kb->tsr_ctrl);
  132. }
  133. static void ice_imem_np_kb_dump(struct ice_hw *hw,
  134. struct ice_np_keybuilder *kb)
  135. {
  136. struct device *dev = ice_hw_to_dev(hw);
  137. dev_info(dev, "next proto key builder:\n");
  138. dev_info(dev, "\topc = %d\n", kb->opc);
  139. dev_info(dev, "\tstart_or_reg0 = %d\n", kb->start_reg0);
  140. dev_info(dev, "\tlen_or_reg1 = %d\n", kb->len_reg1);
  141. }
  142. static void ice_imem_pg_kb_dump(struct ice_hw *hw,
  143. struct ice_pg_keybuilder *kb)
  144. {
  145. struct device *dev = ice_hw_to_dev(hw);
  146. dev_info(dev, "parse graph key builder:\n");
  147. dev_info(dev, "\tflag0_ena = %d\n", kb->flag0_ena);
  148. dev_info(dev, "\tflag1_ena = %d\n", kb->flag1_ena);
  149. dev_info(dev, "\tflag2_ena = %d\n", kb->flag2_ena);
  150. dev_info(dev, "\tflag3_ena = %d\n", kb->flag3_ena);
  151. dev_info(dev, "\tflag0_idx = %d\n", kb->flag0_idx);
  152. dev_info(dev, "\tflag1_idx = %d\n", kb->flag1_idx);
  153. dev_info(dev, "\tflag2_idx = %d\n", kb->flag2_idx);
  154. dev_info(dev, "\tflag3_idx = %d\n", kb->flag3_idx);
  155. dev_info(dev, "\talu_reg_idx = %d\n", kb->alu_reg_idx);
  156. }
  157. static void ice_imem_alu_dump(struct ice_hw *hw,
  158. struct ice_alu *alu, int index)
  159. {
  160. struct device *dev = ice_hw_to_dev(hw);
  161. dev_info(dev, "alu%d:\n", index);
  162. dev_info(dev, "\topc = %d\n", alu->opc);
  163. dev_info(dev, "\tsrc_start = %d\n", alu->src_start);
  164. dev_info(dev, "\tsrc_len = %d\n", alu->src_len);
  165. dev_info(dev, "\tshift_xlate_sel = %d\n", alu->shift_xlate_sel);
  166. dev_info(dev, "\tshift_xlate_key = %d\n", alu->shift_xlate_key);
  167. dev_info(dev, "\tsrc_reg_id = %d\n", alu->src_reg_id);
  168. dev_info(dev, "\tdst_reg_id = %d\n", alu->dst_reg_id);
  169. dev_info(dev, "\tinc0 = %d\n", alu->inc0);
  170. dev_info(dev, "\tinc1 = %d\n", alu->inc1);
  171. dev_info(dev, "\tproto_offset_opc = %d\n", alu->proto_offset_opc);
  172. dev_info(dev, "\tproto_offset = %d\n", alu->proto_offset);
  173. dev_info(dev, "\tbranch_addr = %d\n", alu->branch_addr);
  174. dev_info(dev, "\timm = %d\n", alu->imm);
  175. dev_info(dev, "\tdst_start = %d\n", alu->dst_start);
  176. dev_info(dev, "\tdst_len = %d\n", alu->dst_len);
  177. dev_info(dev, "\tflags_extr_imm = %d\n", alu->flags_extr_imm);
  178. dev_info(dev, "\tflags_start_imm= %d\n", alu->flags_start_imm);
  179. }
  180. /**
  181. * ice_imem_dump - dump an imem item info
  182. * @hw: pointer to the hardware structure
  183. * @item: imem item to dump
  184. */
  185. static void ice_imem_dump(struct ice_hw *hw, struct ice_imem_item *item)
  186. {
  187. struct device *dev = ice_hw_to_dev(hw);
  188. dev_info(dev, "index = %d\n", item->idx);
  189. ice_imem_bst_bm_dump(hw, &item->b_m);
  190. ice_imem_bst_kb_dump(hw, &item->b_kb);
  191. dev_info(dev, "pg priority = %d\n", item->pg_prio);
  192. ice_imem_np_kb_dump(hw, &item->np_kb);
  193. ice_imem_pg_kb_dump(hw, &item->pg_kb);
  194. ice_imem_alu_dump(hw, &item->alu0, 0);
  195. ice_imem_alu_dump(hw, &item->alu1, 1);
  196. ice_imem_alu_dump(hw, &item->alu2, 2);
  197. }
  198. #define ICE_IM_BM_ALU0 BIT(0)
  199. #define ICE_IM_BM_ALU1 BIT(1)
  200. #define ICE_IM_BM_ALU2 BIT(2)
  201. #define ICE_IM_BM_PG BIT(3)
  202. /**
  203. * ice_imem_bm_init - parse 4 bits of Boost Main
  204. * @bm: pointer to the Boost Main structure
  205. * @data: Boost Main data to be parsed
  206. */
  207. static void ice_imem_bm_init(struct ice_bst_main *bm, u8 data)
  208. {
  209. bm->alu0 = FIELD_GET(ICE_IM_BM_ALU0, data);
  210. bm->alu1 = FIELD_GET(ICE_IM_BM_ALU1, data);
  211. bm->alu2 = FIELD_GET(ICE_IM_BM_ALU2, data);
  212. bm->pg = FIELD_GET(ICE_IM_BM_PG, data);
  213. }
  214. #define ICE_IM_BKB_PRIO GENMASK(7, 0)
  215. #define ICE_IM_BKB_TSR_CTRL BIT(8)
  216. /**
  217. * ice_imem_bkb_init - parse 10 bits of Boost Main Build
  218. * @bkb: pointer to the Boost Main Build structure
  219. * @data: Boost Main Build data to be parsed
  220. */
  221. static void ice_imem_bkb_init(struct ice_bst_keybuilder *bkb, u16 data)
  222. {
  223. bkb->prio = FIELD_GET(ICE_IM_BKB_PRIO, data);
  224. bkb->tsr_ctrl = FIELD_GET(ICE_IM_BKB_TSR_CTRL, data);
  225. }
  226. #define ICE_IM_NPKB_OPC GENMASK(1, 0)
  227. #define ICE_IM_NPKB_S_R0 GENMASK(9, 2)
  228. #define ICE_IM_NPKB_L_R1 GENMASK(17, 10)
  229. /**
  230. * ice_imem_npkb_init - parse 18 bits of Next Protocol Key Build
  231. * @kb: pointer to the Next Protocol Key Build structure
  232. * @data: Next Protocol Key Build data to be parsed
  233. */
  234. static void ice_imem_npkb_init(struct ice_np_keybuilder *kb, u32 data)
  235. {
  236. kb->opc = FIELD_GET(ICE_IM_NPKB_OPC, data);
  237. kb->start_reg0 = FIELD_GET(ICE_IM_NPKB_S_R0, data);
  238. kb->len_reg1 = FIELD_GET(ICE_IM_NPKB_L_R1, data);
  239. }
  240. #define ICE_IM_PGKB_F0_ENA BIT_ULL(0)
  241. #define ICE_IM_PGKB_F0_IDX GENMASK_ULL(6, 1)
  242. #define ICE_IM_PGKB_F1_ENA BIT_ULL(7)
  243. #define ICE_IM_PGKB_F1_IDX GENMASK_ULL(13, 8)
  244. #define ICE_IM_PGKB_F2_ENA BIT_ULL(14)
  245. #define ICE_IM_PGKB_F2_IDX GENMASK_ULL(20, 15)
  246. #define ICE_IM_PGKB_F3_ENA BIT_ULL(21)
  247. #define ICE_IM_PGKB_F3_IDX GENMASK_ULL(27, 22)
  248. #define ICE_IM_PGKB_AR_IDX GENMASK_ULL(34, 28)
  249. /**
  250. * ice_imem_pgkb_init - parse 35 bits of Parse Graph Key Build
  251. * @kb: pointer to the Parse Graph Key Build structure
  252. * @data: Parse Graph Key Build data to be parsed
  253. */
  254. static void ice_imem_pgkb_init(struct ice_pg_keybuilder *kb, u64 data)
  255. {
  256. kb->flag0_ena = FIELD_GET(ICE_IM_PGKB_F0_ENA, data);
  257. kb->flag0_idx = FIELD_GET(ICE_IM_PGKB_F0_IDX, data);
  258. kb->flag1_ena = FIELD_GET(ICE_IM_PGKB_F1_ENA, data);
  259. kb->flag1_idx = FIELD_GET(ICE_IM_PGKB_F1_IDX, data);
  260. kb->flag2_ena = FIELD_GET(ICE_IM_PGKB_F2_ENA, data);
  261. kb->flag2_idx = FIELD_GET(ICE_IM_PGKB_F2_IDX, data);
  262. kb->flag3_ena = FIELD_GET(ICE_IM_PGKB_F3_ENA, data);
  263. kb->flag3_idx = FIELD_GET(ICE_IM_PGKB_F3_IDX, data);
  264. kb->alu_reg_idx = FIELD_GET(ICE_IM_PGKB_AR_IDX, data);
  265. }
  266. #define ICE_IM_ALU_OPC GENMASK_ULL(5, 0)
  267. #define ICE_IM_ALU_SS GENMASK_ULL(13, 6)
  268. #define ICE_IM_ALU_SL GENMASK_ULL(18, 14)
  269. #define ICE_IM_ALU_SXS BIT_ULL(19)
  270. #define ICE_IM_ALU_SXK GENMASK_ULL(23, 20)
  271. #define ICE_IM_ALU_SRID GENMASK_ULL(30, 24)
  272. #define ICE_IM_ALU_DRID GENMASK_ULL(37, 31)
  273. #define ICE_IM_ALU_INC0 BIT_ULL(38)
  274. #define ICE_IM_ALU_INC1 BIT_ULL(39)
  275. #define ICE_IM_ALU_POO GENMASK_ULL(41, 40)
  276. #define ICE_IM_ALU_PO GENMASK_ULL(49, 42)
  277. #define ICE_IM_ALU_BA_S 50 /* offset for the 2nd 64-bits field */
  278. #define ICE_IM_ALU_BA GENMASK_ULL(57 - ICE_IM_ALU_BA_S, \
  279. 50 - ICE_IM_ALU_BA_S)
  280. #define ICE_IM_ALU_IMM GENMASK_ULL(73 - ICE_IM_ALU_BA_S, \
  281. 58 - ICE_IM_ALU_BA_S)
  282. #define ICE_IM_ALU_DFE BIT_ULL(74 - ICE_IM_ALU_BA_S)
  283. #define ICE_IM_ALU_DS GENMASK_ULL(80 - ICE_IM_ALU_BA_S, \
  284. 75 - ICE_IM_ALU_BA_S)
  285. #define ICE_IM_ALU_DL GENMASK_ULL(86 - ICE_IM_ALU_BA_S, \
  286. 81 - ICE_IM_ALU_BA_S)
  287. #define ICE_IM_ALU_FEI BIT_ULL(87 - ICE_IM_ALU_BA_S)
  288. #define ICE_IM_ALU_FSI GENMASK_ULL(95 - ICE_IM_ALU_BA_S, \
  289. 88 - ICE_IM_ALU_BA_S)
  290. /**
  291. * ice_imem_alu_init - parse 96 bits of ALU entry
  292. * @alu: pointer to the ALU entry structure
  293. * @data: ALU entry data to be parsed
  294. * @off: offset of the ALU entry data
  295. */
  296. static void ice_imem_alu_init(struct ice_alu *alu, u8 *data, u8 off)
  297. {
  298. u64 d64;
  299. u8 idd;
  300. d64 = *((u64 *)data) >> off;
  301. alu->opc = FIELD_GET(ICE_IM_ALU_OPC, d64);
  302. alu->src_start = FIELD_GET(ICE_IM_ALU_SS, d64);
  303. alu->src_len = FIELD_GET(ICE_IM_ALU_SL, d64);
  304. alu->shift_xlate_sel = FIELD_GET(ICE_IM_ALU_SXS, d64);
  305. alu->shift_xlate_key = FIELD_GET(ICE_IM_ALU_SXK, d64);
  306. alu->src_reg_id = FIELD_GET(ICE_IM_ALU_SRID, d64);
  307. alu->dst_reg_id = FIELD_GET(ICE_IM_ALU_DRID, d64);
  308. alu->inc0 = FIELD_GET(ICE_IM_ALU_INC0, d64);
  309. alu->inc1 = FIELD_GET(ICE_IM_ALU_INC1, d64);
  310. alu->proto_offset_opc = FIELD_GET(ICE_IM_ALU_POO, d64);
  311. alu->proto_offset = FIELD_GET(ICE_IM_ALU_PO, d64);
  312. idd = (ICE_IM_ALU_BA_S + off) / BITS_PER_BYTE;
  313. off = (ICE_IM_ALU_BA_S + off) % BITS_PER_BYTE;
  314. d64 = *((u64 *)(&data[idd])) >> off;
  315. alu->branch_addr = FIELD_GET(ICE_IM_ALU_BA, d64);
  316. alu->imm = FIELD_GET(ICE_IM_ALU_IMM, d64);
  317. alu->dedicate_flags_ena = FIELD_GET(ICE_IM_ALU_DFE, d64);
  318. alu->dst_start = FIELD_GET(ICE_IM_ALU_DS, d64);
  319. alu->dst_len = FIELD_GET(ICE_IM_ALU_DL, d64);
  320. alu->flags_extr_imm = FIELD_GET(ICE_IM_ALU_FEI, d64);
  321. alu->flags_start_imm = FIELD_GET(ICE_IM_ALU_FSI, d64);
  322. }
  323. #define ICE_IMEM_BM_S 0
  324. #define ICE_IMEM_BKB_S 4
  325. #define ICE_IMEM_BKB_IDD (ICE_IMEM_BKB_S / BITS_PER_BYTE)
  326. #define ICE_IMEM_BKB_OFF (ICE_IMEM_BKB_S % BITS_PER_BYTE)
  327. #define ICE_IMEM_PGP GENMASK(15, 14)
  328. #define ICE_IMEM_NPKB_S 16
  329. #define ICE_IMEM_NPKB_IDD (ICE_IMEM_NPKB_S / BITS_PER_BYTE)
  330. #define ICE_IMEM_NPKB_OFF (ICE_IMEM_NPKB_S % BITS_PER_BYTE)
  331. #define ICE_IMEM_PGKB_S 34
  332. #define ICE_IMEM_PGKB_IDD (ICE_IMEM_PGKB_S / BITS_PER_BYTE)
  333. #define ICE_IMEM_PGKB_OFF (ICE_IMEM_PGKB_S % BITS_PER_BYTE)
  334. #define ICE_IMEM_ALU0_S 69
  335. #define ICE_IMEM_ALU0_IDD (ICE_IMEM_ALU0_S / BITS_PER_BYTE)
  336. #define ICE_IMEM_ALU0_OFF (ICE_IMEM_ALU0_S % BITS_PER_BYTE)
  337. #define ICE_IMEM_ALU1_S 165
  338. #define ICE_IMEM_ALU1_IDD (ICE_IMEM_ALU1_S / BITS_PER_BYTE)
  339. #define ICE_IMEM_ALU1_OFF (ICE_IMEM_ALU1_S % BITS_PER_BYTE)
  340. #define ICE_IMEM_ALU2_S 357
  341. #define ICE_IMEM_ALU2_IDD (ICE_IMEM_ALU2_S / BITS_PER_BYTE)
  342. #define ICE_IMEM_ALU2_OFF (ICE_IMEM_ALU2_S % BITS_PER_BYTE)
  343. /**
  344. * ice_imem_parse_item - parse 384 bits of IMEM entry
  345. * @hw: pointer to the hardware structure
  346. * @idx: index of IMEM entry
  347. * @item: item of IMEM entry
  348. * @data: IMEM entry data to be parsed
  349. * @size: size of IMEM entry
  350. */
  351. static void ice_imem_parse_item(struct ice_hw *hw, u16 idx, void *item,
  352. void *data, int __maybe_unused size)
  353. {
  354. struct ice_imem_item *ii = item;
  355. u8 *buf = data;
  356. ii->idx = idx;
  357. ice_imem_bm_init(&ii->b_m, *(u8 *)buf);
  358. ice_imem_bkb_init(&ii->b_kb,
  359. *((u16 *)(&buf[ICE_IMEM_BKB_IDD])) >>
  360. ICE_IMEM_BKB_OFF);
  361. ii->pg_prio = FIELD_GET(ICE_IMEM_PGP, *(u16 *)buf);
  362. ice_imem_npkb_init(&ii->np_kb,
  363. *((u32 *)(&buf[ICE_IMEM_NPKB_IDD])) >>
  364. ICE_IMEM_NPKB_OFF);
  365. ice_imem_pgkb_init(&ii->pg_kb,
  366. *((u64 *)(&buf[ICE_IMEM_PGKB_IDD])) >>
  367. ICE_IMEM_PGKB_OFF);
  368. ice_imem_alu_init(&ii->alu0,
  369. &buf[ICE_IMEM_ALU0_IDD],
  370. ICE_IMEM_ALU0_OFF);
  371. ice_imem_alu_init(&ii->alu1,
  372. &buf[ICE_IMEM_ALU1_IDD],
  373. ICE_IMEM_ALU1_OFF);
  374. ice_imem_alu_init(&ii->alu2,
  375. &buf[ICE_IMEM_ALU2_IDD],
  376. ICE_IMEM_ALU2_OFF);
  377. if (hw->debug_mask & ICE_DBG_PARSER)
  378. ice_imem_dump(hw, ii);
  379. }
  380. /**
  381. * ice_imem_table_get - create an imem table
  382. * @hw: pointer to the hardware structure
  383. *
  384. * Return: a pointer to the allocated IMEM table.
  385. */
  386. static struct ice_imem_item *ice_imem_table_get(struct ice_hw *hw)
  387. {
  388. return ice_parser_create_table(hw, ICE_SID_RXPARSER_IMEM,
  389. sizeof(struct ice_imem_item),
  390. ICE_IMEM_TABLE_SIZE,
  391. ice_imem_parse_item, false);
  392. }
  393. /*** ICE_SID_RXPARSER_METADATA_INIT section ***/
  394. /**
  395. * ice_metainit_dump - dump an metainit item info
  396. * @hw: pointer to the hardware structure
  397. * @item: metainit item to dump
  398. */
  399. static void ice_metainit_dump(struct ice_hw *hw, struct ice_metainit_item *item)
  400. {
  401. struct device *dev = ice_hw_to_dev(hw);
  402. dev_info(dev, "index = %d\n", item->idx);
  403. dev_info(dev, "tsr = %d\n", item->tsr);
  404. dev_info(dev, "ho = %d\n", item->ho);
  405. dev_info(dev, "pc = %d\n", item->pc);
  406. dev_info(dev, "pg_rn = %d\n", item->pg_rn);
  407. dev_info(dev, "cd = %d\n", item->cd);
  408. dev_info(dev, "gpr_a_ctrl = %d\n", item->gpr_a_ctrl);
  409. dev_info(dev, "gpr_a_data_mdid = %d\n", item->gpr_a_data_mdid);
  410. dev_info(dev, "gpr_a_data_start = %d\n", item->gpr_a_data_start);
  411. dev_info(dev, "gpr_a_data_len = %d\n", item->gpr_a_data_len);
  412. dev_info(dev, "gpr_a_id = %d\n", item->gpr_a_id);
  413. dev_info(dev, "gpr_b_ctrl = %d\n", item->gpr_b_ctrl);
  414. dev_info(dev, "gpr_b_data_mdid = %d\n", item->gpr_b_data_mdid);
  415. dev_info(dev, "gpr_b_data_start = %d\n", item->gpr_b_data_start);
  416. dev_info(dev, "gpr_b_data_len = %d\n", item->gpr_b_data_len);
  417. dev_info(dev, "gpr_b_id = %d\n", item->gpr_b_id);
  418. dev_info(dev, "gpr_c_ctrl = %d\n", item->gpr_c_ctrl);
  419. dev_info(dev, "gpr_c_data_mdid = %d\n", item->gpr_c_data_mdid);
  420. dev_info(dev, "gpr_c_data_start = %d\n", item->gpr_c_data_start);
  421. dev_info(dev, "gpr_c_data_len = %d\n", item->gpr_c_data_len);
  422. dev_info(dev, "gpr_c_id = %d\n", item->gpr_c_id);
  423. dev_info(dev, "gpr_d_ctrl = %d\n", item->gpr_d_ctrl);
  424. dev_info(dev, "gpr_d_data_mdid = %d\n", item->gpr_d_data_mdid);
  425. dev_info(dev, "gpr_d_data_start = %d\n", item->gpr_d_data_start);
  426. dev_info(dev, "gpr_d_data_len = %d\n", item->gpr_d_data_len);
  427. dev_info(dev, "gpr_d_id = %d\n", item->gpr_d_id);
  428. dev_info(dev, "flags = 0x%llx\n", (unsigned long long)(item->flags));
  429. }
  430. #define ICE_MI_TSR GENMASK_ULL(7, 0)
  431. #define ICE_MI_HO GENMASK_ULL(16, 8)
  432. #define ICE_MI_PC GENMASK_ULL(24, 17)
  433. #define ICE_MI_PGRN GENMASK_ULL(35, 25)
  434. #define ICE_MI_CD GENMASK_ULL(38, 36)
  435. #define ICE_MI_GAC BIT_ULL(39)
  436. #define ICE_MI_GADM GENMASK_ULL(44, 40)
  437. #define ICE_MI_GADS GENMASK_ULL(48, 45)
  438. #define ICE_MI_GADL GENMASK_ULL(53, 49)
  439. #define ICE_MI_GAI GENMASK_ULL(59, 56)
  440. #define ICE_MI_GBC BIT_ULL(60)
  441. #define ICE_MI_GBDM_S 61 /* offset for the 2nd 64-bits field */
  442. #define ICE_MI_GBDM_IDD (ICE_MI_GBDM_S / BITS_PER_BYTE)
  443. #define ICE_MI_GBDM_OFF (ICE_MI_GBDM_S % BITS_PER_BYTE)
  444. #define ICE_MI_GBDM_GENMASK_ULL(high, low) \
  445. GENMASK_ULL((high) - ICE_MI_GBDM_S, (low) - ICE_MI_GBDM_S)
  446. #define ICE_MI_GBDM ICE_MI_GBDM_GENMASK_ULL(65, 61)
  447. #define ICE_MI_GBDS ICE_MI_GBDM_GENMASK_ULL(69, 66)
  448. #define ICE_MI_GBDL ICE_MI_GBDM_GENMASK_ULL(74, 70)
  449. #define ICE_MI_GBI ICE_MI_GBDM_GENMASK_ULL(80, 77)
  450. #define ICE_MI_GCC BIT_ULL(81 - ICE_MI_GBDM_S)
  451. #define ICE_MI_GCDM ICE_MI_GBDM_GENMASK_ULL(86, 82)
  452. #define ICE_MI_GCDS ICE_MI_GBDM_GENMASK_ULL(90, 87)
  453. #define ICE_MI_GCDL ICE_MI_GBDM_GENMASK_ULL(95, 91)
  454. #define ICE_MI_GCI ICE_MI_GBDM_GENMASK_ULL(101, 98)
  455. #define ICE_MI_GDC BIT_ULL(102 - ICE_MI_GBDM_S)
  456. #define ICE_MI_GDDM ICE_MI_GBDM_GENMASK_ULL(107, 103)
  457. #define ICE_MI_GDDS ICE_MI_GBDM_GENMASK_ULL(111, 108)
  458. #define ICE_MI_GDDL ICE_MI_GBDM_GENMASK_ULL(116, 112)
  459. #define ICE_MI_GDI ICE_MI_GBDM_GENMASK_ULL(122, 119)
  460. #define ICE_MI_FLAG_S 123 /* offset for the 3rd 64-bits field */
  461. #define ICE_MI_FLAG_IDD (ICE_MI_FLAG_S / BITS_PER_BYTE)
  462. #define ICE_MI_FLAG_OFF (ICE_MI_FLAG_S % BITS_PER_BYTE)
  463. #define ICE_MI_FLAG GENMASK_ULL(186 - ICE_MI_FLAG_S, \
  464. 123 - ICE_MI_FLAG_S)
  465. /**
  466. * ice_metainit_parse_item - parse 192 bits of Metadata Init entry
  467. * @hw: pointer to the hardware structure
  468. * @idx: index of Metadata Init entry
  469. * @item: item of Metadata Init entry
  470. * @data: Metadata Init entry data to be parsed
  471. * @size: size of Metadata Init entry
  472. */
  473. static void ice_metainit_parse_item(struct ice_hw *hw, u16 idx, void *item,
  474. void *data, int __maybe_unused size)
  475. {
  476. struct ice_metainit_item *mi = item;
  477. u8 *buf = data;
  478. u64 d64;
  479. mi->idx = idx;
  480. d64 = *(u64 *)buf;
  481. mi->tsr = FIELD_GET(ICE_MI_TSR, d64);
  482. mi->ho = FIELD_GET(ICE_MI_HO, d64);
  483. mi->pc = FIELD_GET(ICE_MI_PC, d64);
  484. mi->pg_rn = FIELD_GET(ICE_MI_PGRN, d64);
  485. mi->cd = FIELD_GET(ICE_MI_CD, d64);
  486. mi->gpr_a_ctrl = FIELD_GET(ICE_MI_GAC, d64);
  487. mi->gpr_a_data_mdid = FIELD_GET(ICE_MI_GADM, d64);
  488. mi->gpr_a_data_start = FIELD_GET(ICE_MI_GADS, d64);
  489. mi->gpr_a_data_len = FIELD_GET(ICE_MI_GADL, d64);
  490. mi->gpr_a_id = FIELD_GET(ICE_MI_GAI, d64);
  491. mi->gpr_b_ctrl = FIELD_GET(ICE_MI_GBC, d64);
  492. d64 = *((u64 *)&buf[ICE_MI_GBDM_IDD]) >> ICE_MI_GBDM_OFF;
  493. mi->gpr_b_data_mdid = FIELD_GET(ICE_MI_GBDM, d64);
  494. mi->gpr_b_data_start = FIELD_GET(ICE_MI_GBDS, d64);
  495. mi->gpr_b_data_len = FIELD_GET(ICE_MI_GBDL, d64);
  496. mi->gpr_b_id = FIELD_GET(ICE_MI_GBI, d64);
  497. mi->gpr_c_ctrl = FIELD_GET(ICE_MI_GCC, d64);
  498. mi->gpr_c_data_mdid = FIELD_GET(ICE_MI_GCDM, d64);
  499. mi->gpr_c_data_start = FIELD_GET(ICE_MI_GCDS, d64);
  500. mi->gpr_c_data_len = FIELD_GET(ICE_MI_GCDL, d64);
  501. mi->gpr_c_id = FIELD_GET(ICE_MI_GCI, d64);
  502. mi->gpr_d_ctrl = FIELD_GET(ICE_MI_GDC, d64);
  503. mi->gpr_d_data_mdid = FIELD_GET(ICE_MI_GDDM, d64);
  504. mi->gpr_d_data_start = FIELD_GET(ICE_MI_GDDS, d64);
  505. mi->gpr_d_data_len = FIELD_GET(ICE_MI_GDDL, d64);
  506. mi->gpr_d_id = FIELD_GET(ICE_MI_GDI, d64);
  507. d64 = *((u64 *)&buf[ICE_MI_FLAG_IDD]) >> ICE_MI_FLAG_OFF;
  508. mi->flags = FIELD_GET(ICE_MI_FLAG, d64);
  509. if (hw->debug_mask & ICE_DBG_PARSER)
  510. ice_metainit_dump(hw, mi);
  511. }
  512. /**
  513. * ice_metainit_table_get - create a metainit table
  514. * @hw: pointer to the hardware structure
  515. *
  516. * Return: a pointer to the allocated Metadata initialization table.
  517. */
  518. static struct ice_metainit_item *ice_metainit_table_get(struct ice_hw *hw)
  519. {
  520. return ice_parser_create_table(hw, ICE_SID_RXPARSER_METADATA_INIT,
  521. sizeof(struct ice_metainit_item),
  522. ICE_METAINIT_TABLE_SIZE,
  523. ice_metainit_parse_item, false);
  524. }
  525. /**
  526. * ice_bst_tcam_search - find a TCAM item with specific type
  527. * @tcam_table: the TCAM table
  528. * @lbl_table: the lbl table to search
  529. * @type: the type we need to match against
  530. * @start: start searching from this index
  531. *
  532. * Return: a pointer to the matching BOOST TCAM item or NULL.
  533. */
  534. struct ice_bst_tcam_item *
  535. ice_bst_tcam_search(struct ice_bst_tcam_item *tcam_table,
  536. struct ice_lbl_item *lbl_table,
  537. enum ice_lbl_type type, u16 *start)
  538. {
  539. u16 i = *start;
  540. for (; i < ICE_BST_TCAM_TABLE_SIZE; i++) {
  541. if (lbl_table[i].type == type) {
  542. *start = i;
  543. return &tcam_table[lbl_table[i].idx];
  544. }
  545. }
  546. return NULL;
  547. }
  548. /*** ICE_SID_RXPARSER_CAM, ICE_SID_RXPARSER_PG_SPILL,
  549. * ICE_SID_RXPARSER_NOMATCH_CAM and ICE_SID_RXPARSER_NOMATCH_CAM
  550. * sections ***/
  551. static void ice_pg_cam_key_dump(struct ice_hw *hw, struct ice_pg_cam_key *key)
  552. {
  553. struct device *dev = ice_hw_to_dev(hw);
  554. dev_info(dev, "key:\n");
  555. dev_info(dev, "\tvalid = %d\n", key->valid);
  556. dev_info(dev, "\tnode_id = %d\n", key->node_id);
  557. dev_info(dev, "\tflag0 = %d\n", key->flag0);
  558. dev_info(dev, "\tflag1 = %d\n", key->flag1);
  559. dev_info(dev, "\tflag2 = %d\n", key->flag2);
  560. dev_info(dev, "\tflag3 = %d\n", key->flag3);
  561. dev_info(dev, "\tboost_idx = %d\n", key->boost_idx);
  562. dev_info(dev, "\talu_reg = 0x%04x\n", key->alu_reg);
  563. dev_info(dev, "\tnext_proto = 0x%08x\n", key->next_proto);
  564. }
  565. static void ice_pg_nm_cam_key_dump(struct ice_hw *hw,
  566. struct ice_pg_nm_cam_key *key)
  567. {
  568. struct device *dev = ice_hw_to_dev(hw);
  569. dev_info(dev, "key:\n");
  570. dev_info(dev, "\tvalid = %d\n", key->valid);
  571. dev_info(dev, "\tnode_id = %d\n", key->node_id);
  572. dev_info(dev, "\tflag0 = %d\n", key->flag0);
  573. dev_info(dev, "\tflag1 = %d\n", key->flag1);
  574. dev_info(dev, "\tflag2 = %d\n", key->flag2);
  575. dev_info(dev, "\tflag3 = %d\n", key->flag3);
  576. dev_info(dev, "\tboost_idx = %d\n", key->boost_idx);
  577. dev_info(dev, "\talu_reg = 0x%04x\n", key->alu_reg);
  578. }
  579. static void ice_pg_cam_action_dump(struct ice_hw *hw,
  580. struct ice_pg_cam_action *action)
  581. {
  582. struct device *dev = ice_hw_to_dev(hw);
  583. dev_info(dev, "action:\n");
  584. dev_info(dev, "\tnext_node = %d\n", action->next_node);
  585. dev_info(dev, "\tnext_pc = %d\n", action->next_pc);
  586. dev_info(dev, "\tis_pg = %d\n", action->is_pg);
  587. dev_info(dev, "\tproto_id = %d\n", action->proto_id);
  588. dev_info(dev, "\tis_mg = %d\n", action->is_mg);
  589. dev_info(dev, "\tmarker_id = %d\n", action->marker_id);
  590. dev_info(dev, "\tis_last_round = %d\n", action->is_last_round);
  591. dev_info(dev, "\tho_polarity = %d\n", action->ho_polarity);
  592. dev_info(dev, "\tho_inc = %d\n", action->ho_inc);
  593. }
  594. /**
  595. * ice_pg_cam_dump - dump an parse graph cam info
  596. * @hw: pointer to the hardware structure
  597. * @item: parse graph cam to dump
  598. */
  599. static void ice_pg_cam_dump(struct ice_hw *hw, struct ice_pg_cam_item *item)
  600. {
  601. dev_info(ice_hw_to_dev(hw), "index = %d\n", item->idx);
  602. ice_pg_cam_key_dump(hw, &item->key);
  603. ice_pg_cam_action_dump(hw, &item->action);
  604. }
  605. /**
  606. * ice_pg_nm_cam_dump - dump an parse graph no match cam info
  607. * @hw: pointer to the hardware structure
  608. * @item: parse graph no match cam to dump
  609. */
  610. static void ice_pg_nm_cam_dump(struct ice_hw *hw,
  611. struct ice_pg_nm_cam_item *item)
  612. {
  613. dev_info(ice_hw_to_dev(hw), "index = %d\n", item->idx);
  614. ice_pg_nm_cam_key_dump(hw, &item->key);
  615. ice_pg_cam_action_dump(hw, &item->action);
  616. }
  617. #define ICE_PGCA_NN GENMASK_ULL(10, 0)
  618. #define ICE_PGCA_NPC GENMASK_ULL(18, 11)
  619. #define ICE_PGCA_IPG BIT_ULL(19)
  620. #define ICE_PGCA_PID GENMASK_ULL(30, 23)
  621. #define ICE_PGCA_IMG BIT_ULL(31)
  622. #define ICE_PGCA_MID GENMASK_ULL(39, 32)
  623. #define ICE_PGCA_ILR BIT_ULL(40)
  624. #define ICE_PGCA_HOP BIT_ULL(41)
  625. #define ICE_PGCA_HOI GENMASK_ULL(50, 42)
  626. /**
  627. * ice_pg_cam_action_init - parse 55 bits of Parse Graph CAM Action
  628. * @action: pointer to the Parse Graph CAM Action structure
  629. * @data: Parse Graph CAM Action data to be parsed
  630. */
  631. static void ice_pg_cam_action_init(struct ice_pg_cam_action *action, u64 data)
  632. {
  633. action->next_node = FIELD_GET(ICE_PGCA_NN, data);
  634. action->next_pc = FIELD_GET(ICE_PGCA_NPC, data);
  635. action->is_pg = FIELD_GET(ICE_PGCA_IPG, data);
  636. action->proto_id = FIELD_GET(ICE_PGCA_PID, data);
  637. action->is_mg = FIELD_GET(ICE_PGCA_IMG, data);
  638. action->marker_id = FIELD_GET(ICE_PGCA_MID, data);
  639. action->is_last_round = FIELD_GET(ICE_PGCA_ILR, data);
  640. action->ho_polarity = FIELD_GET(ICE_PGCA_HOP, data);
  641. action->ho_inc = FIELD_GET(ICE_PGCA_HOI, data);
  642. }
  643. #define ICE_PGNCK_VLD BIT_ULL(0)
  644. #define ICE_PGNCK_NID GENMASK_ULL(11, 1)
  645. #define ICE_PGNCK_F0 BIT_ULL(12)
  646. #define ICE_PGNCK_F1 BIT_ULL(13)
  647. #define ICE_PGNCK_F2 BIT_ULL(14)
  648. #define ICE_PGNCK_F3 BIT_ULL(15)
  649. #define ICE_PGNCK_BH BIT_ULL(16)
  650. #define ICE_PGNCK_BI GENMASK_ULL(24, 17)
  651. #define ICE_PGNCK_AR GENMASK_ULL(40, 25)
  652. /**
  653. * ice_pg_nm_cam_key_init - parse 41 bits of Parse Graph NoMatch CAM Key
  654. * @key: pointer to the Parse Graph NoMatch CAM Key structure
  655. * @data: Parse Graph NoMatch CAM Key data to be parsed
  656. */
  657. static void ice_pg_nm_cam_key_init(struct ice_pg_nm_cam_key *key, u64 data)
  658. {
  659. key->valid = FIELD_GET(ICE_PGNCK_VLD, data);
  660. key->node_id = FIELD_GET(ICE_PGNCK_NID, data);
  661. key->flag0 = FIELD_GET(ICE_PGNCK_F0, data);
  662. key->flag1 = FIELD_GET(ICE_PGNCK_F1, data);
  663. key->flag2 = FIELD_GET(ICE_PGNCK_F2, data);
  664. key->flag3 = FIELD_GET(ICE_PGNCK_F3, data);
  665. if (FIELD_GET(ICE_PGNCK_BH, data))
  666. key->boost_idx = FIELD_GET(ICE_PGNCK_BI, data);
  667. else
  668. key->boost_idx = 0;
  669. key->alu_reg = FIELD_GET(ICE_PGNCK_AR, data);
  670. }
  671. #define ICE_PGCK_VLD BIT_ULL(0)
  672. #define ICE_PGCK_NID GENMASK_ULL(11, 1)
  673. #define ICE_PGCK_F0 BIT_ULL(12)
  674. #define ICE_PGCK_F1 BIT_ULL(13)
  675. #define ICE_PGCK_F2 BIT_ULL(14)
  676. #define ICE_PGCK_F3 BIT_ULL(15)
  677. #define ICE_PGCK_BH BIT_ULL(16)
  678. #define ICE_PGCK_BI GENMASK_ULL(24, 17)
  679. #define ICE_PGCK_AR GENMASK_ULL(40, 25)
  680. #define ICE_PGCK_NPK_S 41 /* offset for the 2nd 64-bits field */
  681. #define ICE_PGCK_NPK_IDD (ICE_PGCK_NPK_S / BITS_PER_BYTE)
  682. #define ICE_PGCK_NPK_OFF (ICE_PGCK_NPK_S % BITS_PER_BYTE)
  683. #define ICE_PGCK_NPK GENMASK_ULL(72 - ICE_PGCK_NPK_S, \
  684. 41 - ICE_PGCK_NPK_S)
  685. /**
  686. * ice_pg_cam_key_init - parse 73 bits of Parse Graph CAM Key
  687. * @key: pointer to the Parse Graph CAM Key structure
  688. * @data: Parse Graph CAM Key data to be parsed
  689. */
  690. static void ice_pg_cam_key_init(struct ice_pg_cam_key *key, u8 *data)
  691. {
  692. u64 d64 = *(u64 *)data;
  693. key->valid = FIELD_GET(ICE_PGCK_VLD, d64);
  694. key->node_id = FIELD_GET(ICE_PGCK_NID, d64);
  695. key->flag0 = FIELD_GET(ICE_PGCK_F0, d64);
  696. key->flag1 = FIELD_GET(ICE_PGCK_F1, d64);
  697. key->flag2 = FIELD_GET(ICE_PGCK_F2, d64);
  698. key->flag3 = FIELD_GET(ICE_PGCK_F3, d64);
  699. if (FIELD_GET(ICE_PGCK_BH, d64))
  700. key->boost_idx = FIELD_GET(ICE_PGCK_BI, d64);
  701. else
  702. key->boost_idx = 0;
  703. key->alu_reg = FIELD_GET(ICE_PGCK_AR, d64);
  704. d64 = *((u64 *)&data[ICE_PGCK_NPK_IDD]) >> ICE_PGCK_NPK_OFF;
  705. key->next_proto = FIELD_GET(ICE_PGCK_NPK, d64);
  706. }
  707. #define ICE_PG_CAM_ACT_S 73
  708. #define ICE_PG_CAM_ACT_IDD (ICE_PG_CAM_ACT_S / BITS_PER_BYTE)
  709. #define ICE_PG_CAM_ACT_OFF (ICE_PG_CAM_ACT_S % BITS_PER_BYTE)
  710. /**
  711. * ice_pg_cam_parse_item - parse 128 bits of Parse Graph CAM Entry
  712. * @hw: pointer to the hardware structure
  713. * @idx: index of Parse Graph CAM Entry
  714. * @item: item of Parse Graph CAM Entry
  715. * @data: Parse Graph CAM Entry data to be parsed
  716. * @size: size of Parse Graph CAM Entry
  717. */
  718. static void ice_pg_cam_parse_item(struct ice_hw *hw, u16 idx, void *item,
  719. void *data, int __maybe_unused size)
  720. {
  721. struct ice_pg_cam_item *ci = item;
  722. u8 *buf = data;
  723. u64 d64;
  724. ci->idx = idx;
  725. ice_pg_cam_key_init(&ci->key, buf);
  726. d64 = *((u64 *)&buf[ICE_PG_CAM_ACT_IDD]) >> ICE_PG_CAM_ACT_OFF;
  727. ice_pg_cam_action_init(&ci->action, d64);
  728. if (hw->debug_mask & ICE_DBG_PARSER)
  729. ice_pg_cam_dump(hw, ci);
  730. }
  731. #define ICE_PG_SP_CAM_KEY_S 56
  732. #define ICE_PG_SP_CAM_KEY_IDD (ICE_PG_SP_CAM_KEY_S / BITS_PER_BYTE)
  733. /**
  734. * ice_pg_sp_cam_parse_item - parse 136 bits of Parse Graph Spill CAM Entry
  735. * @hw: pointer to the hardware structure
  736. * @idx: index of Parse Graph Spill CAM Entry
  737. * @item: item of Parse Graph Spill CAM Entry
  738. * @data: Parse Graph Spill CAM Entry data to be parsed
  739. * @size: size of Parse Graph Spill CAM Entry
  740. */
  741. static void ice_pg_sp_cam_parse_item(struct ice_hw *hw, u16 idx, void *item,
  742. void *data, int __maybe_unused size)
  743. {
  744. struct ice_pg_cam_item *ci = item;
  745. u8 *buf = data;
  746. u64 d64;
  747. ci->idx = idx;
  748. d64 = *(u64 *)buf;
  749. ice_pg_cam_action_init(&ci->action, d64);
  750. ice_pg_cam_key_init(&ci->key, &buf[ICE_PG_SP_CAM_KEY_IDD]);
  751. if (hw->debug_mask & ICE_DBG_PARSER)
  752. ice_pg_cam_dump(hw, ci);
  753. }
  754. #define ICE_PG_NM_CAM_ACT_S 41
  755. #define ICE_PG_NM_CAM_ACT_IDD (ICE_PG_NM_CAM_ACT_S / BITS_PER_BYTE)
  756. #define ICE_PG_NM_CAM_ACT_OFF (ICE_PG_NM_CAM_ACT_S % BITS_PER_BYTE)
  757. /**
  758. * ice_pg_nm_cam_parse_item - parse 96 bits of Parse Graph NoMatch CAM Entry
  759. * @hw: pointer to the hardware structure
  760. * @idx: index of Parse Graph NoMatch CAM Entry
  761. * @item: item of Parse Graph NoMatch CAM Entry
  762. * @data: Parse Graph NoMatch CAM Entry data to be parsed
  763. * @size: size of Parse Graph NoMatch CAM Entry
  764. */
  765. static void ice_pg_nm_cam_parse_item(struct ice_hw *hw, u16 idx, void *item,
  766. void *data, int __maybe_unused size)
  767. {
  768. struct ice_pg_nm_cam_item *ci = item;
  769. u8 *buf = data;
  770. u64 d64;
  771. ci->idx = idx;
  772. d64 = *(u64 *)buf;
  773. ice_pg_nm_cam_key_init(&ci->key, d64);
  774. d64 = *((u64 *)&buf[ICE_PG_NM_CAM_ACT_IDD]) >> ICE_PG_NM_CAM_ACT_OFF;
  775. ice_pg_cam_action_init(&ci->action, d64);
  776. if (hw->debug_mask & ICE_DBG_PARSER)
  777. ice_pg_nm_cam_dump(hw, ci);
  778. }
  779. #define ICE_PG_NM_SP_CAM_ACT_S 56
  780. #define ICE_PG_NM_SP_CAM_ACT_IDD (ICE_PG_NM_SP_CAM_ACT_S / BITS_PER_BYTE)
  781. #define ICE_PG_NM_SP_CAM_ACT_OFF (ICE_PG_NM_SP_CAM_ACT_S % BITS_PER_BYTE)
  782. /**
  783. * ice_pg_nm_sp_cam_parse_item - parse 104 bits of Parse Graph NoMatch Spill
  784. * CAM Entry
  785. * @hw: pointer to the hardware structure
  786. * @idx: index of Parse Graph NoMatch Spill CAM Entry
  787. * @item: item of Parse Graph NoMatch Spill CAM Entry
  788. * @data: Parse Graph NoMatch Spill CAM Entry data to be parsed
  789. * @size: size of Parse Graph NoMatch Spill CAM Entry
  790. */
  791. static void ice_pg_nm_sp_cam_parse_item(struct ice_hw *hw, u16 idx,
  792. void *item, void *data,
  793. int __maybe_unused size)
  794. {
  795. struct ice_pg_nm_cam_item *ci = item;
  796. u8 *buf = data;
  797. u64 d64;
  798. ci->idx = idx;
  799. d64 = *(u64 *)buf;
  800. ice_pg_cam_action_init(&ci->action, d64);
  801. d64 = *((u64 *)&buf[ICE_PG_NM_SP_CAM_ACT_IDD]) >>
  802. ICE_PG_NM_SP_CAM_ACT_OFF;
  803. ice_pg_nm_cam_key_init(&ci->key, d64);
  804. if (hw->debug_mask & ICE_DBG_PARSER)
  805. ice_pg_nm_cam_dump(hw, ci);
  806. }
  807. /**
  808. * ice_pg_cam_table_get - create a parse graph cam table
  809. * @hw: pointer to the hardware structure
  810. *
  811. * Return: a pointer to the allocated Parse Graph CAM table.
  812. */
  813. static struct ice_pg_cam_item *ice_pg_cam_table_get(struct ice_hw *hw)
  814. {
  815. return ice_parser_create_table(hw, ICE_SID_RXPARSER_CAM,
  816. sizeof(struct ice_pg_cam_item),
  817. ICE_PG_CAM_TABLE_SIZE,
  818. ice_pg_cam_parse_item, false);
  819. }
  820. /**
  821. * ice_pg_sp_cam_table_get - create a parse graph spill cam table
  822. * @hw: pointer to the hardware structure
  823. *
  824. * Return: a pointer to the allocated Parse Graph Spill CAM table.
  825. */
  826. static struct ice_pg_cam_item *ice_pg_sp_cam_table_get(struct ice_hw *hw)
  827. {
  828. return ice_parser_create_table(hw, ICE_SID_RXPARSER_PG_SPILL,
  829. sizeof(struct ice_pg_cam_item),
  830. ICE_PG_SP_CAM_TABLE_SIZE,
  831. ice_pg_sp_cam_parse_item, false);
  832. }
  833. /**
  834. * ice_pg_nm_cam_table_get - create a parse graph no match cam table
  835. * @hw: pointer to the hardware structure
  836. *
  837. * Return: a pointer to the allocated Parse Graph No Match CAM table.
  838. */
  839. static struct ice_pg_nm_cam_item *ice_pg_nm_cam_table_get(struct ice_hw *hw)
  840. {
  841. return ice_parser_create_table(hw, ICE_SID_RXPARSER_NOMATCH_CAM,
  842. sizeof(struct ice_pg_nm_cam_item),
  843. ICE_PG_NM_CAM_TABLE_SIZE,
  844. ice_pg_nm_cam_parse_item, false);
  845. }
  846. /**
  847. * ice_pg_nm_sp_cam_table_get - create a parse graph no match spill cam table
  848. * @hw: pointer to the hardware structure
  849. *
  850. * Return: a pointer to the allocated Parse Graph No Match Spill CAM table.
  851. */
  852. static struct ice_pg_nm_cam_item *ice_pg_nm_sp_cam_table_get(struct ice_hw *hw)
  853. {
  854. return ice_parser_create_table(hw, ICE_SID_RXPARSER_NOMATCH_SPILL,
  855. sizeof(struct ice_pg_nm_cam_item),
  856. ICE_PG_NM_SP_CAM_TABLE_SIZE,
  857. ice_pg_nm_sp_cam_parse_item, false);
  858. }
  859. static bool __ice_pg_cam_match(struct ice_pg_cam_item *item,
  860. struct ice_pg_cam_key *key)
  861. {
  862. return (item->key.valid &&
  863. !memcmp(&item->key.val, &key->val, sizeof(key->val)));
  864. }
  865. static bool __ice_pg_nm_cam_match(struct ice_pg_nm_cam_item *item,
  866. struct ice_pg_cam_key *key)
  867. {
  868. return (item->key.valid &&
  869. !memcmp(&item->key.val, &key->val, sizeof(item->key.val)));
  870. }
  871. /**
  872. * ice_pg_cam_match - search parse graph cam table by key
  873. * @table: parse graph cam table to search
  874. * @size: cam table size
  875. * @key: search key
  876. *
  877. * Return: a pointer to the matching PG CAM item or NULL.
  878. */
  879. struct ice_pg_cam_item *ice_pg_cam_match(struct ice_pg_cam_item *table,
  880. int size, struct ice_pg_cam_key *key)
  881. {
  882. int i;
  883. for (i = 0; i < size; i++) {
  884. struct ice_pg_cam_item *item = &table[i];
  885. if (__ice_pg_cam_match(item, key))
  886. return item;
  887. }
  888. return NULL;
  889. }
  890. /**
  891. * ice_pg_nm_cam_match - search parse graph no match cam table by key
  892. * @table: parse graph no match cam table to search
  893. * @size: cam table size
  894. * @key: search key
  895. *
  896. * Return: a pointer to the matching PG No Match CAM item or NULL.
  897. */
  898. struct ice_pg_nm_cam_item *
  899. ice_pg_nm_cam_match(struct ice_pg_nm_cam_item *table, int size,
  900. struct ice_pg_cam_key *key)
  901. {
  902. int i;
  903. for (i = 0; i < size; i++) {
  904. struct ice_pg_nm_cam_item *item = &table[i];
  905. if (__ice_pg_nm_cam_match(item, key))
  906. return item;
  907. }
  908. return NULL;
  909. }
  910. /*** Ternary match ***/
  911. /* Perform a ternary match on a 1-byte pattern (@pat) given @key and @key_inv
  912. * Rules (per bit):
  913. * Key == 0 and Key_inv == 0 : Never match (Don't care)
  914. * Key == 0 and Key_inv == 1 : Match on bit == 1
  915. * Key == 1 and Key_inv == 0 : Match on bit == 0
  916. * Key == 1 and Key_inv == 1 : Always match (Don't care)
  917. *
  918. * Return: true if all bits match, false otherwise.
  919. */
  920. static bool ice_ternary_match_byte(u8 key, u8 key_inv, u8 pat)
  921. {
  922. u8 bit_key, bit_key_inv, bit_pat;
  923. int i;
  924. for (i = 0; i < BITS_PER_BYTE; i++) {
  925. bit_key = key & BIT(i);
  926. bit_key_inv = key_inv & BIT(i);
  927. bit_pat = pat & BIT(i);
  928. if (bit_key != 0 && bit_key_inv != 0)
  929. continue;
  930. if ((bit_key == 0 && bit_key_inv == 0) || bit_key == bit_pat)
  931. return false;
  932. }
  933. return true;
  934. }
  935. static bool ice_ternary_match(const u8 *key, const u8 *key_inv,
  936. const u8 *pat, int len)
  937. {
  938. int i;
  939. for (i = 0; i < len; i++)
  940. if (!ice_ternary_match_byte(key[i], key_inv[i], pat[i]))
  941. return false;
  942. return true;
  943. }
  944. /*** ICE_SID_RXPARSER_BOOST_TCAM and ICE_SID_LBL_RXPARSER_TMEM sections ***/
  945. static void ice_bst_np_kb_dump(struct ice_hw *hw, struct ice_np_keybuilder *kb)
  946. {
  947. struct device *dev = ice_hw_to_dev(hw);
  948. dev_info(dev, "next proto key builder:\n");
  949. dev_info(dev, "\topc = %d\n", kb->opc);
  950. dev_info(dev, "\tstart_reg0 = %d\n", kb->start_reg0);
  951. dev_info(dev, "\tlen_reg1 = %d\n", kb->len_reg1);
  952. }
  953. static void ice_bst_pg_kb_dump(struct ice_hw *hw, struct ice_pg_keybuilder *kb)
  954. {
  955. struct device *dev = ice_hw_to_dev(hw);
  956. dev_info(dev, "parse graph key builder:\n");
  957. dev_info(dev, "\tflag0_ena = %d\n", kb->flag0_ena);
  958. dev_info(dev, "\tflag1_ena = %d\n", kb->flag1_ena);
  959. dev_info(dev, "\tflag2_ena = %d\n", kb->flag2_ena);
  960. dev_info(dev, "\tflag3_ena = %d\n", kb->flag3_ena);
  961. dev_info(dev, "\tflag0_idx = %d\n", kb->flag0_idx);
  962. dev_info(dev, "\tflag1_idx = %d\n", kb->flag1_idx);
  963. dev_info(dev, "\tflag2_idx = %d\n", kb->flag2_idx);
  964. dev_info(dev, "\tflag3_idx = %d\n", kb->flag3_idx);
  965. dev_info(dev, "\talu_reg_idx = %d\n", kb->alu_reg_idx);
  966. }
  967. static void ice_bst_alu_dump(struct ice_hw *hw, struct ice_alu *alu, int idx)
  968. {
  969. struct device *dev = ice_hw_to_dev(hw);
  970. dev_info(dev, "alu%d:\n", idx);
  971. dev_info(dev, "\topc = %d\n", alu->opc);
  972. dev_info(dev, "\tsrc_start = %d\n", alu->src_start);
  973. dev_info(dev, "\tsrc_len = %d\n", alu->src_len);
  974. dev_info(dev, "\tshift_xlate_sel = %d\n", alu->shift_xlate_sel);
  975. dev_info(dev, "\tshift_xlate_key = %d\n", alu->shift_xlate_key);
  976. dev_info(dev, "\tsrc_reg_id = %d\n", alu->src_reg_id);
  977. dev_info(dev, "\tdst_reg_id = %d\n", alu->dst_reg_id);
  978. dev_info(dev, "\tinc0 = %d\n", alu->inc0);
  979. dev_info(dev, "\tinc1 = %d\n", alu->inc1);
  980. dev_info(dev, "\tproto_offset_opc = %d\n", alu->proto_offset_opc);
  981. dev_info(dev, "\tproto_offset = %d\n", alu->proto_offset);
  982. dev_info(dev, "\tbranch_addr = %d\n", alu->branch_addr);
  983. dev_info(dev, "\timm = %d\n", alu->imm);
  984. dev_info(dev, "\tdst_start = %d\n", alu->dst_start);
  985. dev_info(dev, "\tdst_len = %d\n", alu->dst_len);
  986. dev_info(dev, "\tflags_extr_imm = %d\n", alu->flags_extr_imm);
  987. dev_info(dev, "\tflags_start_imm= %d\n", alu->flags_start_imm);
  988. }
  989. /**
  990. * ice_bst_tcam_dump - dump a boost tcam info
  991. * @hw: pointer to the hardware structure
  992. * @item: boost tcam to dump
  993. */
  994. static void ice_bst_tcam_dump(struct ice_hw *hw, struct ice_bst_tcam_item *item)
  995. {
  996. struct device *dev = ice_hw_to_dev(hw);
  997. int i;
  998. dev_info(dev, "addr = %d\n", item->addr);
  999. dev_info(dev, "key : ");
  1000. for (i = 0; i < ICE_BST_TCAM_KEY_SIZE; i++)
  1001. dev_info(dev, "%02x ", item->key[i]);
  1002. dev_info(dev, "\n");
  1003. dev_info(dev, "key_inv: ");
  1004. for (i = 0; i < ICE_BST_TCAM_KEY_SIZE; i++)
  1005. dev_info(dev, "%02x ", item->key_inv[i]);
  1006. dev_info(dev, "\n");
  1007. dev_info(dev, "hit_idx_grp = %d\n", item->hit_idx_grp);
  1008. dev_info(dev, "pg_prio = %d\n", item->pg_prio);
  1009. ice_bst_np_kb_dump(hw, &item->np_kb);
  1010. ice_bst_pg_kb_dump(hw, &item->pg_kb);
  1011. ice_bst_alu_dump(hw, &item->alu0, ICE_ALU0_IDX);
  1012. ice_bst_alu_dump(hw, &item->alu1, ICE_ALU1_IDX);
  1013. ice_bst_alu_dump(hw, &item->alu2, ICE_ALU2_IDX);
  1014. }
  1015. static void ice_lbl_dump(struct ice_hw *hw, struct ice_lbl_item *item)
  1016. {
  1017. struct device *dev = ice_hw_to_dev(hw);
  1018. dev_info(dev, "index = %u\n", item->idx);
  1019. dev_info(dev, "type = %u\n", item->type);
  1020. dev_info(dev, "label = %s\n", item->label);
  1021. }
  1022. #define ICE_BST_ALU_OPC GENMASK_ULL(5, 0)
  1023. #define ICE_BST_ALU_SS GENMASK_ULL(13, 6)
  1024. #define ICE_BST_ALU_SL GENMASK_ULL(18, 14)
  1025. #define ICE_BST_ALU_SXS BIT_ULL(19)
  1026. #define ICE_BST_ALU_SXK GENMASK_ULL(23, 20)
  1027. #define ICE_BST_ALU_SRID GENMASK_ULL(30, 24)
  1028. #define ICE_BST_ALU_DRID GENMASK_ULL(37, 31)
  1029. #define ICE_BST_ALU_INC0 BIT_ULL(38)
  1030. #define ICE_BST_ALU_INC1 BIT_ULL(39)
  1031. #define ICE_BST_ALU_POO GENMASK_ULL(41, 40)
  1032. #define ICE_BST_ALU_PO GENMASK_ULL(49, 42)
  1033. #define ICE_BST_ALU_BA_S 50 /* offset for the 2nd 64-bits field */
  1034. #define ICE_BST_ALU_BA GENMASK_ULL(57 - ICE_BST_ALU_BA_S, \
  1035. 50 - ICE_BST_ALU_BA_S)
  1036. #define ICE_BST_ALU_IMM GENMASK_ULL(73 - ICE_BST_ALU_BA_S, \
  1037. 58 - ICE_BST_ALU_BA_S)
  1038. #define ICE_BST_ALU_DFE BIT_ULL(74 - ICE_BST_ALU_BA_S)
  1039. #define ICE_BST_ALU_DS GENMASK_ULL(80 - ICE_BST_ALU_BA_S, \
  1040. 75 - ICE_BST_ALU_BA_S)
  1041. #define ICE_BST_ALU_DL GENMASK_ULL(86 - ICE_BST_ALU_BA_S, \
  1042. 81 - ICE_BST_ALU_BA_S)
  1043. #define ICE_BST_ALU_FEI BIT_ULL(87 - ICE_BST_ALU_BA_S)
  1044. #define ICE_BST_ALU_FSI GENMASK_ULL(95 - ICE_BST_ALU_BA_S, \
  1045. 88 - ICE_BST_ALU_BA_S)
  1046. /**
  1047. * ice_bst_alu_init - parse 96 bits of ALU entry
  1048. * @alu: pointer to the ALU entry structure
  1049. * @data: ALU entry data to be parsed
  1050. * @off: offset of the ALU entry data
  1051. */
  1052. static void ice_bst_alu_init(struct ice_alu *alu, u8 *data, u8 off)
  1053. {
  1054. u64 d64;
  1055. u8 idd;
  1056. d64 = *((u64 *)data) >> off;
  1057. alu->opc = FIELD_GET(ICE_BST_ALU_OPC, d64);
  1058. alu->src_start = FIELD_GET(ICE_BST_ALU_SS, d64);
  1059. alu->src_len = FIELD_GET(ICE_BST_ALU_SL, d64);
  1060. alu->shift_xlate_sel = FIELD_GET(ICE_BST_ALU_SXS, d64);
  1061. alu->shift_xlate_key = FIELD_GET(ICE_BST_ALU_SXK, d64);
  1062. alu->src_reg_id = FIELD_GET(ICE_BST_ALU_SRID, d64);
  1063. alu->dst_reg_id = FIELD_GET(ICE_BST_ALU_DRID, d64);
  1064. alu->inc0 = FIELD_GET(ICE_BST_ALU_INC0, d64);
  1065. alu->inc1 = FIELD_GET(ICE_BST_ALU_INC1, d64);
  1066. alu->proto_offset_opc = FIELD_GET(ICE_BST_ALU_POO, d64);
  1067. alu->proto_offset = FIELD_GET(ICE_BST_ALU_PO, d64);
  1068. idd = (ICE_BST_ALU_BA_S + off) / BITS_PER_BYTE;
  1069. off = (ICE_BST_ALU_BA_S + off) % BITS_PER_BYTE;
  1070. d64 = *((u64 *)(&data[idd])) >> off;
  1071. alu->branch_addr = FIELD_GET(ICE_BST_ALU_BA, d64);
  1072. alu->imm = FIELD_GET(ICE_BST_ALU_IMM, d64);
  1073. alu->dedicate_flags_ena = FIELD_GET(ICE_BST_ALU_DFE, d64);
  1074. alu->dst_start = FIELD_GET(ICE_BST_ALU_DS, d64);
  1075. alu->dst_len = FIELD_GET(ICE_BST_ALU_DL, d64);
  1076. alu->flags_extr_imm = FIELD_GET(ICE_BST_ALU_FEI, d64);
  1077. alu->flags_start_imm = FIELD_GET(ICE_BST_ALU_FSI, d64);
  1078. }
  1079. #define ICE_BST_PGKB_F0_ENA BIT_ULL(0)
  1080. #define ICE_BST_PGKB_F0_IDX GENMASK_ULL(6, 1)
  1081. #define ICE_BST_PGKB_F1_ENA BIT_ULL(7)
  1082. #define ICE_BST_PGKB_F1_IDX GENMASK_ULL(13, 8)
  1083. #define ICE_BST_PGKB_F2_ENA BIT_ULL(14)
  1084. #define ICE_BST_PGKB_F2_IDX GENMASK_ULL(20, 15)
  1085. #define ICE_BST_PGKB_F3_ENA BIT_ULL(21)
  1086. #define ICE_BST_PGKB_F3_IDX GENMASK_ULL(27, 22)
  1087. #define ICE_BST_PGKB_AR_IDX GENMASK_ULL(34, 28)
  1088. /**
  1089. * ice_bst_pgkb_init - parse 35 bits of Parse Graph Key Build
  1090. * @kb: pointer to the Parse Graph Key Build structure
  1091. * @data: Parse Graph Key Build data to be parsed
  1092. */
  1093. static void ice_bst_pgkb_init(struct ice_pg_keybuilder *kb, u64 data)
  1094. {
  1095. kb->flag0_ena = FIELD_GET(ICE_BST_PGKB_F0_ENA, data);
  1096. kb->flag0_idx = FIELD_GET(ICE_BST_PGKB_F0_IDX, data);
  1097. kb->flag1_ena = FIELD_GET(ICE_BST_PGKB_F1_ENA, data);
  1098. kb->flag1_idx = FIELD_GET(ICE_BST_PGKB_F1_IDX, data);
  1099. kb->flag2_ena = FIELD_GET(ICE_BST_PGKB_F2_ENA, data);
  1100. kb->flag2_idx = FIELD_GET(ICE_BST_PGKB_F2_IDX, data);
  1101. kb->flag3_ena = FIELD_GET(ICE_BST_PGKB_F3_ENA, data);
  1102. kb->flag3_idx = FIELD_GET(ICE_BST_PGKB_F3_IDX, data);
  1103. kb->alu_reg_idx = FIELD_GET(ICE_BST_PGKB_AR_IDX, data);
  1104. }
  1105. #define ICE_BST_NPKB_OPC GENMASK(1, 0)
  1106. #define ICE_BST_NPKB_S_R0 GENMASK(9, 2)
  1107. #define ICE_BST_NPKB_L_R1 GENMASK(17, 10)
  1108. /**
  1109. * ice_bst_npkb_init - parse 18 bits of Next Protocol Key Build
  1110. * @kb: pointer to the Next Protocol Key Build structure
  1111. * @data: Next Protocol Key Build data to be parsed
  1112. */
  1113. static void ice_bst_npkb_init(struct ice_np_keybuilder *kb, u32 data)
  1114. {
  1115. kb->opc = FIELD_GET(ICE_BST_NPKB_OPC, data);
  1116. kb->start_reg0 = FIELD_GET(ICE_BST_NPKB_S_R0, data);
  1117. kb->len_reg1 = FIELD_GET(ICE_BST_NPKB_L_R1, data);
  1118. }
  1119. #define ICE_BT_KEY_S 32
  1120. #define ICE_BT_KEY_IDD (ICE_BT_KEY_S / BITS_PER_BYTE)
  1121. #define ICE_BT_KIV_S 192
  1122. #define ICE_BT_KIV_IDD (ICE_BT_KIV_S / BITS_PER_BYTE)
  1123. #define ICE_BT_HIG_S 352
  1124. #define ICE_BT_HIG_IDD (ICE_BT_HIG_S / BITS_PER_BYTE)
  1125. #define ICE_BT_PGP_S 360
  1126. #define ICE_BT_PGP_IDD (ICE_BT_PGP_S / BITS_PER_BYTE)
  1127. #define ICE_BT_PGP_M GENMASK(361 - ICE_BT_PGP_S, 360 - ICE_BT_PGP_S)
  1128. #define ICE_BT_NPKB_S 362
  1129. #define ICE_BT_NPKB_IDD (ICE_BT_NPKB_S / BITS_PER_BYTE)
  1130. #define ICE_BT_NPKB_OFF (ICE_BT_NPKB_S % BITS_PER_BYTE)
  1131. #define ICE_BT_PGKB_S 380
  1132. #define ICE_BT_PGKB_IDD (ICE_BT_PGKB_S / BITS_PER_BYTE)
  1133. #define ICE_BT_PGKB_OFF (ICE_BT_PGKB_S % BITS_PER_BYTE)
  1134. #define ICE_BT_ALU0_S 415
  1135. #define ICE_BT_ALU0_IDD (ICE_BT_ALU0_S / BITS_PER_BYTE)
  1136. #define ICE_BT_ALU0_OFF (ICE_BT_ALU0_S % BITS_PER_BYTE)
  1137. #define ICE_BT_ALU1_S 511
  1138. #define ICE_BT_ALU1_IDD (ICE_BT_ALU1_S / BITS_PER_BYTE)
  1139. #define ICE_BT_ALU1_OFF (ICE_BT_ALU1_S % BITS_PER_BYTE)
  1140. #define ICE_BT_ALU2_S 607
  1141. #define ICE_BT_ALU2_IDD (ICE_BT_ALU2_S / BITS_PER_BYTE)
  1142. #define ICE_BT_ALU2_OFF (ICE_BT_ALU2_S % BITS_PER_BYTE)
  1143. /**
  1144. * ice_bst_parse_item - parse 704 bits of Boost TCAM entry
  1145. * @hw: pointer to the hardware structure
  1146. * @idx: index of Boost TCAM entry
  1147. * @item: item of Boost TCAM entry
  1148. * @data: Boost TCAM entry data to be parsed
  1149. * @size: size of Boost TCAM entry
  1150. */
  1151. static void ice_bst_parse_item(struct ice_hw *hw, u16 idx, void *item,
  1152. void *data, int __maybe_unused size)
  1153. {
  1154. struct ice_bst_tcam_item *ti = item;
  1155. u8 *buf = (u8 *)data;
  1156. int i;
  1157. ti->addr = *(u16 *)buf;
  1158. for (i = 0; i < ICE_BST_TCAM_KEY_SIZE; i++) {
  1159. ti->key[i] = buf[ICE_BT_KEY_IDD + i];
  1160. ti->key_inv[i] = buf[ICE_BT_KIV_IDD + i];
  1161. }
  1162. ti->hit_idx_grp = buf[ICE_BT_HIG_IDD];
  1163. ti->pg_prio = buf[ICE_BT_PGP_IDD] & ICE_BT_PGP_M;
  1164. ice_bst_npkb_init(&ti->np_kb,
  1165. *((u32 *)(&buf[ICE_BT_NPKB_IDD])) >>
  1166. ICE_BT_NPKB_OFF);
  1167. ice_bst_pgkb_init(&ti->pg_kb,
  1168. *((u64 *)(&buf[ICE_BT_PGKB_IDD])) >>
  1169. ICE_BT_PGKB_OFF);
  1170. ice_bst_alu_init(&ti->alu0, &buf[ICE_BT_ALU0_IDD], ICE_BT_ALU0_OFF);
  1171. ice_bst_alu_init(&ti->alu1, &buf[ICE_BT_ALU1_IDD], ICE_BT_ALU1_OFF);
  1172. ice_bst_alu_init(&ti->alu2, &buf[ICE_BT_ALU2_IDD], ICE_BT_ALU2_OFF);
  1173. if (hw->debug_mask & ICE_DBG_PARSER)
  1174. ice_bst_tcam_dump(hw, ti);
  1175. }
  1176. /**
  1177. * ice_bst_tcam_table_get - create a boost tcam table
  1178. * @hw: pointer to the hardware structure
  1179. *
  1180. * Return: a pointer to the allocated Boost TCAM table.
  1181. */
  1182. static struct ice_bst_tcam_item *ice_bst_tcam_table_get(struct ice_hw *hw)
  1183. {
  1184. return ice_parser_create_table(hw, ICE_SID_RXPARSER_BOOST_TCAM,
  1185. sizeof(struct ice_bst_tcam_item),
  1186. ICE_BST_TCAM_TABLE_SIZE,
  1187. ice_bst_parse_item, true);
  1188. }
  1189. static void ice_parse_lbl_item(struct ice_hw *hw, u16 idx, void *item,
  1190. void *data, int __maybe_unused size)
  1191. {
  1192. struct ice_lbl_item *lbl_item = item;
  1193. struct ice_lbl_item *lbl_data = data;
  1194. lbl_item->idx = lbl_data->idx;
  1195. memcpy(lbl_item->label, lbl_data->label, sizeof(lbl_item->label));
  1196. if (strstarts(lbl_item->label, ICE_LBL_BST_DVM))
  1197. lbl_item->type = ICE_LBL_BST_TYPE_DVM;
  1198. else if (strstarts(lbl_item->label, ICE_LBL_BST_SVM))
  1199. lbl_item->type = ICE_LBL_BST_TYPE_SVM;
  1200. else if (strstarts(lbl_item->label, ICE_LBL_TNL_VXLAN))
  1201. lbl_item->type = ICE_LBL_BST_TYPE_VXLAN;
  1202. else if (strstarts(lbl_item->label, ICE_LBL_TNL_GENEVE))
  1203. lbl_item->type = ICE_LBL_BST_TYPE_GENEVE;
  1204. else if (strstarts(lbl_item->label, ICE_LBL_TNL_UDP_ECPRI))
  1205. lbl_item->type = ICE_LBL_BST_TYPE_UDP_ECPRI;
  1206. if (hw->debug_mask & ICE_DBG_PARSER)
  1207. ice_lbl_dump(hw, lbl_item);
  1208. }
  1209. /**
  1210. * ice_bst_lbl_table_get - create a boost label table
  1211. * @hw: pointer to the hardware structure
  1212. *
  1213. * Return: a pointer to the allocated Boost label table.
  1214. */
  1215. static struct ice_lbl_item *ice_bst_lbl_table_get(struct ice_hw *hw)
  1216. {
  1217. return ice_parser_create_table(hw, ICE_SID_LBL_RXPARSER_TMEM,
  1218. sizeof(struct ice_lbl_item),
  1219. ICE_BST_TCAM_TABLE_SIZE,
  1220. ice_parse_lbl_item, true);
  1221. }
  1222. /**
  1223. * ice_bst_tcam_match - match a pattern on the boost tcam table
  1224. * @tcam_table: boost tcam table to search
  1225. * @pat: pattern to match
  1226. *
  1227. * Return: a pointer to the matching Boost TCAM item or NULL.
  1228. */
  1229. struct ice_bst_tcam_item *
  1230. ice_bst_tcam_match(struct ice_bst_tcam_item *tcam_table, u8 *pat)
  1231. {
  1232. int i;
  1233. for (i = 0; i < ICE_BST_TCAM_TABLE_SIZE; i++) {
  1234. struct ice_bst_tcam_item *item = &tcam_table[i];
  1235. if (item->hit_idx_grp == 0)
  1236. continue;
  1237. if (ice_ternary_match(item->key, item->key_inv, pat,
  1238. ICE_BST_TCAM_KEY_SIZE))
  1239. return item;
  1240. }
  1241. return NULL;
  1242. }
  1243. /*** ICE_SID_RXPARSER_MARKER_PTYPE section ***/
  1244. /**
  1245. * ice_ptype_mk_tcam_dump - dump an ptype marker tcam info
  1246. * @hw: pointer to the hardware structure
  1247. * @item: ptype marker tcam to dump
  1248. */
  1249. static void ice_ptype_mk_tcam_dump(struct ice_hw *hw,
  1250. struct ice_ptype_mk_tcam_item *item)
  1251. {
  1252. struct device *dev = ice_hw_to_dev(hw);
  1253. int i;
  1254. dev_info(dev, "address = %d\n", item->address);
  1255. dev_info(dev, "ptype = %d\n", item->ptype);
  1256. dev_info(dev, "key :");
  1257. for (i = 0; i < ICE_PTYPE_MK_TCAM_KEY_SIZE; i++)
  1258. dev_info(dev, "%02x ", item->key[i]);
  1259. dev_info(dev, "\n");
  1260. dev_info(dev, "key_inv:");
  1261. for (i = 0; i < ICE_PTYPE_MK_TCAM_KEY_SIZE; i++)
  1262. dev_info(dev, "%02x ", item->key_inv[i]);
  1263. dev_info(dev, "\n");
  1264. }
  1265. static void ice_parse_ptype_mk_tcam_item(struct ice_hw *hw, u16 idx,
  1266. void *item, void *data, int size)
  1267. {
  1268. memcpy(item, data, size);
  1269. if (hw->debug_mask & ICE_DBG_PARSER)
  1270. ice_ptype_mk_tcam_dump(hw,
  1271. (struct ice_ptype_mk_tcam_item *)item);
  1272. }
  1273. /**
  1274. * ice_ptype_mk_tcam_table_get - create a ptype marker tcam table
  1275. * @hw: pointer to the hardware structure
  1276. *
  1277. * Return: a pointer to the allocated Marker PType TCAM table.
  1278. */
  1279. static
  1280. struct ice_ptype_mk_tcam_item *ice_ptype_mk_tcam_table_get(struct ice_hw *hw)
  1281. {
  1282. return ice_parser_create_table(hw, ICE_SID_RXPARSER_MARKER_PTYPE,
  1283. sizeof(struct ice_ptype_mk_tcam_item),
  1284. ICE_PTYPE_MK_TCAM_TABLE_SIZE,
  1285. ice_parse_ptype_mk_tcam_item, true);
  1286. }
  1287. /**
  1288. * ice_ptype_mk_tcam_match - match a pattern on a ptype marker tcam table
  1289. * @table: ptype marker tcam table to search
  1290. * @pat: pattern to match
  1291. * @len: length of the pattern
  1292. *
  1293. * Return: a pointer to the matching Marker PType item or NULL.
  1294. */
  1295. struct ice_ptype_mk_tcam_item *
  1296. ice_ptype_mk_tcam_match(struct ice_ptype_mk_tcam_item *table,
  1297. u8 *pat, int len)
  1298. {
  1299. int i;
  1300. for (i = 0; i < ICE_PTYPE_MK_TCAM_TABLE_SIZE; i++) {
  1301. struct ice_ptype_mk_tcam_item *item = &table[i];
  1302. if (ice_ternary_match(item->key, item->key_inv, pat, len))
  1303. return item;
  1304. }
  1305. return NULL;
  1306. }
  1307. /*** ICE_SID_RXPARSER_MARKER_GRP section ***/
  1308. /**
  1309. * ice_mk_grp_dump - dump an marker group item info
  1310. * @hw: pointer to the hardware structure
  1311. * @item: marker group item to dump
  1312. */
  1313. static void ice_mk_grp_dump(struct ice_hw *hw, struct ice_mk_grp_item *item)
  1314. {
  1315. struct device *dev = ice_hw_to_dev(hw);
  1316. int i;
  1317. dev_info(dev, "index = %d\n", item->idx);
  1318. dev_info(dev, "markers: ");
  1319. for (i = 0; i < ICE_MK_COUNT_PER_GRP; i++)
  1320. dev_info(dev, "%d ", item->markers[i]);
  1321. dev_info(dev, "\n");
  1322. }
  1323. static void ice_mk_grp_parse_item(struct ice_hw *hw, u16 idx, void *item,
  1324. void *data, int __maybe_unused size)
  1325. {
  1326. struct ice_mk_grp_item *grp = item;
  1327. u8 *buf = data;
  1328. int i;
  1329. grp->idx = idx;
  1330. for (i = 0; i < ICE_MK_COUNT_PER_GRP; i++)
  1331. grp->markers[i] = buf[i];
  1332. if (hw->debug_mask & ICE_DBG_PARSER)
  1333. ice_mk_grp_dump(hw, grp);
  1334. }
  1335. /**
  1336. * ice_mk_grp_table_get - create a marker group table
  1337. * @hw: pointer to the hardware structure
  1338. *
  1339. * Return: a pointer to the allocated Marker Group ID table.
  1340. */
  1341. static struct ice_mk_grp_item *ice_mk_grp_table_get(struct ice_hw *hw)
  1342. {
  1343. return ice_parser_create_table(hw, ICE_SID_RXPARSER_MARKER_GRP,
  1344. sizeof(struct ice_mk_grp_item),
  1345. ICE_MK_GRP_TABLE_SIZE,
  1346. ice_mk_grp_parse_item, false);
  1347. }
  1348. /*** ICE_SID_RXPARSER_PROTO_GRP section ***/
  1349. static void ice_proto_off_dump(struct ice_hw *hw,
  1350. struct ice_proto_off *po, int idx)
  1351. {
  1352. struct device *dev = ice_hw_to_dev(hw);
  1353. dev_info(dev, "proto %d\n", idx);
  1354. dev_info(dev, "\tpolarity = %d\n", po->polarity);
  1355. dev_info(dev, "\tproto_id = %d\n", po->proto_id);
  1356. dev_info(dev, "\toffset = %d\n", po->offset);
  1357. }
  1358. /**
  1359. * ice_proto_grp_dump - dump a proto group item info
  1360. * @hw: pointer to the hardware structure
  1361. * @item: proto group item to dump
  1362. */
  1363. static void ice_proto_grp_dump(struct ice_hw *hw,
  1364. struct ice_proto_grp_item *item)
  1365. {
  1366. int i;
  1367. dev_info(ice_hw_to_dev(hw), "index = %d\n", item->idx);
  1368. for (i = 0; i < ICE_PROTO_COUNT_PER_GRP; i++)
  1369. ice_proto_off_dump(hw, &item->po[i], i);
  1370. }
  1371. #define ICE_PO_POL BIT(0)
  1372. #define ICE_PO_PID GENMASK(8, 1)
  1373. #define ICE_PO_OFF GENMASK(21, 12)
  1374. /**
  1375. * ice_proto_off_parse - parse 22 bits of Protocol entry
  1376. * @po: pointer to the Protocol entry structure
  1377. * @data: Protocol entry data to be parsed
  1378. */
  1379. static void ice_proto_off_parse(struct ice_proto_off *po, u32 data)
  1380. {
  1381. po->polarity = FIELD_GET(ICE_PO_POL, data);
  1382. po->proto_id = FIELD_GET(ICE_PO_PID, data);
  1383. po->offset = FIELD_GET(ICE_PO_OFF, data);
  1384. }
  1385. /**
  1386. * ice_proto_grp_parse_item - parse 192 bits of Protocol Group Table entry
  1387. * @hw: pointer to the hardware structure
  1388. * @idx: index of Protocol Group Table entry
  1389. * @item: item of Protocol Group Table entry
  1390. * @data: Protocol Group Table entry data to be parsed
  1391. * @size: size of Protocol Group Table entry
  1392. */
  1393. static void ice_proto_grp_parse_item(struct ice_hw *hw, u16 idx, void *item,
  1394. void *data, int __maybe_unused size)
  1395. {
  1396. struct ice_proto_grp_item *grp = item;
  1397. u8 *buf = (u8 *)data;
  1398. u8 idd, off;
  1399. u32 d32;
  1400. int i;
  1401. grp->idx = idx;
  1402. for (i = 0; i < ICE_PROTO_COUNT_PER_GRP; i++) {
  1403. idd = (ICE_PROTO_GRP_ITEM_SIZE * i) / BITS_PER_BYTE;
  1404. off = (ICE_PROTO_GRP_ITEM_SIZE * i) % BITS_PER_BYTE;
  1405. d32 = *((u32 *)&buf[idd]) >> off;
  1406. ice_proto_off_parse(&grp->po[i], d32);
  1407. }
  1408. if (hw->debug_mask & ICE_DBG_PARSER)
  1409. ice_proto_grp_dump(hw, grp);
  1410. }
  1411. /**
  1412. * ice_proto_grp_table_get - create a proto group table
  1413. * @hw: pointer to the hardware structure
  1414. *
  1415. * Return: a pointer to the allocated Protocol Group table.
  1416. */
  1417. static struct ice_proto_grp_item *ice_proto_grp_table_get(struct ice_hw *hw)
  1418. {
  1419. return ice_parser_create_table(hw, ICE_SID_RXPARSER_PROTO_GRP,
  1420. sizeof(struct ice_proto_grp_item),
  1421. ICE_PROTO_GRP_TABLE_SIZE,
  1422. ice_proto_grp_parse_item, false);
  1423. }
  1424. /*** ICE_SID_RXPARSER_FLAG_REDIR section ***/
  1425. /**
  1426. * ice_flg_rd_dump - dump a flag redirect item info
  1427. * @hw: pointer to the hardware structure
  1428. * @item: flag redirect item to dump
  1429. */
  1430. static void ice_flg_rd_dump(struct ice_hw *hw, struct ice_flg_rd_item *item)
  1431. {
  1432. struct device *dev = ice_hw_to_dev(hw);
  1433. dev_info(dev, "index = %d\n", item->idx);
  1434. dev_info(dev, "expose = %d\n", item->expose);
  1435. dev_info(dev, "intr_flg_id = %d\n", item->intr_flg_id);
  1436. }
  1437. #define ICE_FRT_EXPO BIT(0)
  1438. #define ICE_FRT_IFID GENMASK(6, 1)
  1439. /**
  1440. * ice_flg_rd_parse_item - parse 8 bits of Flag Redirect Table entry
  1441. * @hw: pointer to the hardware structure
  1442. * @idx: index of Flag Redirect Table entry
  1443. * @item: item of Flag Redirect Table entry
  1444. * @data: Flag Redirect Table entry data to be parsed
  1445. * @size: size of Flag Redirect Table entry
  1446. */
  1447. static void ice_flg_rd_parse_item(struct ice_hw *hw, u16 idx, void *item,
  1448. void *data, int __maybe_unused size)
  1449. {
  1450. struct ice_flg_rd_item *rdi = item;
  1451. u8 d8 = *(u8 *)data;
  1452. rdi->idx = idx;
  1453. rdi->expose = FIELD_GET(ICE_FRT_EXPO, d8);
  1454. rdi->intr_flg_id = FIELD_GET(ICE_FRT_IFID, d8);
  1455. if (hw->debug_mask & ICE_DBG_PARSER)
  1456. ice_flg_rd_dump(hw, rdi);
  1457. }
  1458. /**
  1459. * ice_flg_rd_table_get - create a flag redirect table
  1460. * @hw: pointer to the hardware structure
  1461. *
  1462. * Return: a pointer to the allocated Flags Redirection table.
  1463. */
  1464. static struct ice_flg_rd_item *ice_flg_rd_table_get(struct ice_hw *hw)
  1465. {
  1466. return ice_parser_create_table(hw, ICE_SID_RXPARSER_FLAG_REDIR,
  1467. sizeof(struct ice_flg_rd_item),
  1468. ICE_FLG_RD_TABLE_SIZE,
  1469. ice_flg_rd_parse_item, false);
  1470. }
  1471. /**
  1472. * ice_flg_redirect - redirect a parser flag to packet flag
  1473. * @table: flag redirect table
  1474. * @psr_flg: parser flag to redirect
  1475. *
  1476. * Return: flag or 0 if @psr_flag = 0.
  1477. */
  1478. u64 ice_flg_redirect(struct ice_flg_rd_item *table, u64 psr_flg)
  1479. {
  1480. u64 flg = 0;
  1481. int i;
  1482. for (i = 0; i < ICE_FLG_RDT_SIZE; i++) {
  1483. struct ice_flg_rd_item *item = &table[i];
  1484. if (!item->expose)
  1485. continue;
  1486. if (psr_flg & BIT(item->intr_flg_id))
  1487. flg |= BIT(i);
  1488. }
  1489. return flg;
  1490. }
  1491. /*** ICE_SID_XLT_KEY_BUILDER_SW, ICE_SID_XLT_KEY_BUILDER_ACL,
  1492. * ICE_SID_XLT_KEY_BUILDER_FD and ICE_SID_XLT_KEY_BUILDER_RSS
  1493. * sections ***/
  1494. static void ice_xlt_kb_entry_dump(struct ice_hw *hw,
  1495. struct ice_xlt_kb_entry *entry, int idx)
  1496. {
  1497. struct device *dev = ice_hw_to_dev(hw);
  1498. int i;
  1499. dev_info(dev, "key builder entry %d\n", idx);
  1500. dev_info(dev, "\txlt1_ad_sel = %d\n", entry->xlt1_ad_sel);
  1501. dev_info(dev, "\txlt2_ad_sel = %d\n", entry->xlt2_ad_sel);
  1502. for (i = 0; i < ICE_XLT_KB_FLAG0_14_CNT; i++)
  1503. dev_info(dev, "\tflg%d_sel = %d\n", i, entry->flg0_14_sel[i]);
  1504. dev_info(dev, "\txlt1_md_sel = %d\n", entry->xlt1_md_sel);
  1505. dev_info(dev, "\txlt2_md_sel = %d\n", entry->xlt2_md_sel);
  1506. }
  1507. /**
  1508. * ice_xlt_kb_dump - dump a xlt key build info
  1509. * @hw: pointer to the hardware structure
  1510. * @kb: key build to dump
  1511. */
  1512. static void ice_xlt_kb_dump(struct ice_hw *hw, struct ice_xlt_kb *kb)
  1513. {
  1514. struct device *dev = ice_hw_to_dev(hw);
  1515. int i;
  1516. dev_info(dev, "xlt1_pm = %d\n", kb->xlt1_pm);
  1517. dev_info(dev, "xlt2_pm = %d\n", kb->xlt2_pm);
  1518. dev_info(dev, "prof_id_pm = %d\n", kb->prof_id_pm);
  1519. dev_info(dev, "flag15 lo = 0x%08x\n", (u32)kb->flag15);
  1520. dev_info(dev, "flag15 hi = 0x%08x\n",
  1521. (u32)(kb->flag15 >> (sizeof(u32) * BITS_PER_BYTE)));
  1522. for (i = 0; i < ICE_XLT_KB_TBL_CNT; i++)
  1523. ice_xlt_kb_entry_dump(hw, &kb->entries[i], i);
  1524. }
  1525. #define ICE_XLT_KB_X1AS_S 32 /* offset for the 1st 64-bits field */
  1526. #define ICE_XLT_KB_X1AS_IDD (ICE_XLT_KB_X1AS_S / BITS_PER_BYTE)
  1527. #define ICE_XLT_KB_X1AS_OFF (ICE_XLT_KB_X1AS_S % BITS_PER_BYTE)
  1528. #define ICE_XLT_KB_X1AS GENMASK_ULL(34 - ICE_XLT_KB_X1AS_S, \
  1529. 32 - ICE_XLT_KB_X1AS_S)
  1530. #define ICE_XLT_KB_X2AS GENMASK_ULL(37 - ICE_XLT_KB_X1AS_S, \
  1531. 35 - ICE_XLT_KB_X1AS_S)
  1532. #define ICE_XLT_KB_FL00 GENMASK_ULL(46 - ICE_XLT_KB_X1AS_S, \
  1533. 38 - ICE_XLT_KB_X1AS_S)
  1534. #define ICE_XLT_KB_FL01 GENMASK_ULL(55 - ICE_XLT_KB_X1AS_S, \
  1535. 47 - ICE_XLT_KB_X1AS_S)
  1536. #define ICE_XLT_KB_FL02 GENMASK_ULL(64 - ICE_XLT_KB_X1AS_S, \
  1537. 56 - ICE_XLT_KB_X1AS_S)
  1538. #define ICE_XLT_KB_FL03 GENMASK_ULL(73 - ICE_XLT_KB_X1AS_S, \
  1539. 65 - ICE_XLT_KB_X1AS_S)
  1540. #define ICE_XLT_KB_FL04 GENMASK_ULL(82 - ICE_XLT_KB_X1AS_S, \
  1541. 74 - ICE_XLT_KB_X1AS_S)
  1542. #define ICE_XLT_KB_FL05 GENMASK_ULL(91 - ICE_XLT_KB_X1AS_S, \
  1543. 83 - ICE_XLT_KB_X1AS_S)
  1544. #define ICE_XLT_KB_FL06_S 92 /* offset for the 2nd 64-bits field */
  1545. #define ICE_XLT_KB_FL06_IDD (ICE_XLT_KB_FL06_S / BITS_PER_BYTE)
  1546. #define ICE_XLT_KB_FL06_OFF (ICE_XLT_KB_FL06_S % BITS_PER_BYTE)
  1547. #define ICE_XLT_KB_FL06 GENMASK_ULL(100 - ICE_XLT_KB_FL06_S, \
  1548. 92 - ICE_XLT_KB_FL06_S)
  1549. #define ICE_XLT_KB_FL07 GENMASK_ULL(109 - ICE_XLT_KB_FL06_S, \
  1550. 101 - ICE_XLT_KB_FL06_S)
  1551. #define ICE_XLT_KB_FL08 GENMASK_ULL(118 - ICE_XLT_KB_FL06_S, \
  1552. 110 - ICE_XLT_KB_FL06_S)
  1553. #define ICE_XLT_KB_FL09 GENMASK_ULL(127 - ICE_XLT_KB_FL06_S, \
  1554. 119 - ICE_XLT_KB_FL06_S)
  1555. #define ICE_XLT_KB_FL10 GENMASK_ULL(136 - ICE_XLT_KB_FL06_S, \
  1556. 128 - ICE_XLT_KB_FL06_S)
  1557. #define ICE_XLT_KB_FL11 GENMASK_ULL(145 - ICE_XLT_KB_FL06_S, \
  1558. 137 - ICE_XLT_KB_FL06_S)
  1559. #define ICE_XLT_KB_FL12_S 146 /* offset for the 3rd 64-bits field */
  1560. #define ICE_XLT_KB_FL12_IDD (ICE_XLT_KB_FL12_S / BITS_PER_BYTE)
  1561. #define ICE_XLT_KB_FL12_OFF (ICE_XLT_KB_FL12_S % BITS_PER_BYTE)
  1562. #define ICE_XLT_KB_FL12 GENMASK_ULL(154 - ICE_XLT_KB_FL12_S, \
  1563. 146 - ICE_XLT_KB_FL12_S)
  1564. #define ICE_XLT_KB_FL13 GENMASK_ULL(163 - ICE_XLT_KB_FL12_S, \
  1565. 155 - ICE_XLT_KB_FL12_S)
  1566. #define ICE_XLT_KB_FL14 GENMASK_ULL(181 - ICE_XLT_KB_FL12_S, \
  1567. 164 - ICE_XLT_KB_FL12_S)
  1568. #define ICE_XLT_KB_X1MS GENMASK_ULL(186 - ICE_XLT_KB_FL12_S, \
  1569. 182 - ICE_XLT_KB_FL12_S)
  1570. #define ICE_XLT_KB_X2MS GENMASK_ULL(191 - ICE_XLT_KB_FL12_S, \
  1571. 187 - ICE_XLT_KB_FL12_S)
  1572. /**
  1573. * ice_kb_entry_init - parse 192 bits of XLT Key Builder entry
  1574. * @entry: pointer to the XLT Key Builder entry structure
  1575. * @data: XLT Key Builder entry data to be parsed
  1576. */
  1577. static void ice_kb_entry_init(struct ice_xlt_kb_entry *entry, u8 *data)
  1578. {
  1579. u8 i = 0;
  1580. u64 d64;
  1581. d64 = *((u64 *)&data[ICE_XLT_KB_X1AS_IDD]) >> ICE_XLT_KB_X1AS_OFF;
  1582. entry->xlt1_ad_sel = FIELD_GET(ICE_XLT_KB_X1AS, d64);
  1583. entry->xlt2_ad_sel = FIELD_GET(ICE_XLT_KB_X2AS, d64);
  1584. entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL00, d64);
  1585. entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL01, d64);
  1586. entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL02, d64);
  1587. entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL03, d64);
  1588. entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL04, d64);
  1589. entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL05, d64);
  1590. d64 = *((u64 *)&data[ICE_XLT_KB_FL06_IDD]) >> ICE_XLT_KB_FL06_OFF;
  1591. entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL06, d64);
  1592. entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL07, d64);
  1593. entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL08, d64);
  1594. entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL09, d64);
  1595. entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL10, d64);
  1596. entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL11, d64);
  1597. d64 = *((u64 *)&data[ICE_XLT_KB_FL12_IDD]) >> ICE_XLT_KB_FL12_OFF;
  1598. entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL12, d64);
  1599. entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL13, d64);
  1600. entry->flg0_14_sel[i] = FIELD_GET(ICE_XLT_KB_FL14, d64);
  1601. entry->xlt1_md_sel = FIELD_GET(ICE_XLT_KB_X1MS, d64);
  1602. entry->xlt2_md_sel = FIELD_GET(ICE_XLT_KB_X2MS, d64);
  1603. }
  1604. #define ICE_XLT_KB_X1PM_OFF 0
  1605. #define ICE_XLT_KB_X2PM_OFF 1
  1606. #define ICE_XLT_KB_PIPM_OFF 2
  1607. #define ICE_XLT_KB_FL15_OFF 4
  1608. #define ICE_XLT_KB_TBL_OFF 12
  1609. /**
  1610. * ice_parse_kb_data - parse 204 bits of XLT Key Build Table
  1611. * @hw: pointer to the hardware structure
  1612. * @kb: pointer to the XLT Key Build Table structure
  1613. * @data: XLT Key Build Table data to be parsed
  1614. */
  1615. static void ice_parse_kb_data(struct ice_hw *hw, struct ice_xlt_kb *kb,
  1616. void *data)
  1617. {
  1618. u8 *buf = data;
  1619. int i;
  1620. kb->xlt1_pm = buf[ICE_XLT_KB_X1PM_OFF];
  1621. kb->xlt2_pm = buf[ICE_XLT_KB_X2PM_OFF];
  1622. kb->prof_id_pm = buf[ICE_XLT_KB_PIPM_OFF];
  1623. kb->flag15 = *(u64 *)&buf[ICE_XLT_KB_FL15_OFF];
  1624. for (i = 0; i < ICE_XLT_KB_TBL_CNT; i++)
  1625. ice_kb_entry_init(&kb->entries[i],
  1626. &buf[ICE_XLT_KB_TBL_OFF +
  1627. i * ICE_XLT_KB_TBL_ENTRY_SIZE]);
  1628. if (hw->debug_mask & ICE_DBG_PARSER)
  1629. ice_xlt_kb_dump(hw, kb);
  1630. }
  1631. static struct ice_xlt_kb *ice_xlt_kb_get(struct ice_hw *hw, u32 sect_type)
  1632. {
  1633. struct ice_pkg_enum state = {};
  1634. struct ice_seg *seg = hw->seg;
  1635. struct ice_xlt_kb *kb;
  1636. void *data;
  1637. if (!seg)
  1638. return ERR_PTR(-EINVAL);
  1639. kb = kzalloc(sizeof(*kb), GFP_KERNEL);
  1640. if (!kb)
  1641. return ERR_PTR(-ENOMEM);
  1642. data = ice_pkg_enum_section(seg, &state, sect_type);
  1643. if (!data) {
  1644. ice_debug(hw, ICE_DBG_PARSER, "failed to find section type %d.\n",
  1645. sect_type);
  1646. kfree(kb);
  1647. return ERR_PTR(-EINVAL);
  1648. }
  1649. ice_parse_kb_data(hw, kb, data);
  1650. return kb;
  1651. }
  1652. /**
  1653. * ice_xlt_kb_get_sw - create switch xlt key build
  1654. * @hw: pointer to the hardware structure
  1655. *
  1656. * Return: a pointer to the allocated Key Builder table for Switch.
  1657. */
  1658. static struct ice_xlt_kb *ice_xlt_kb_get_sw(struct ice_hw *hw)
  1659. {
  1660. return ice_xlt_kb_get(hw, ICE_SID_XLT_KEY_BUILDER_SW);
  1661. }
  1662. /**
  1663. * ice_xlt_kb_get_acl - create acl xlt key build
  1664. * @hw: pointer to the hardware structure
  1665. *
  1666. * Return: a pointer to the allocated Key Builder table for ACL.
  1667. */
  1668. static struct ice_xlt_kb *ice_xlt_kb_get_acl(struct ice_hw *hw)
  1669. {
  1670. return ice_xlt_kb_get(hw, ICE_SID_XLT_KEY_BUILDER_ACL);
  1671. }
  1672. /**
  1673. * ice_xlt_kb_get_fd - create fdir xlt key build
  1674. * @hw: pointer to the hardware structure
  1675. *
  1676. * Return: a pointer to the allocated Key Builder table for Flow Director.
  1677. */
  1678. static struct ice_xlt_kb *ice_xlt_kb_get_fd(struct ice_hw *hw)
  1679. {
  1680. return ice_xlt_kb_get(hw, ICE_SID_XLT_KEY_BUILDER_FD);
  1681. }
  1682. /**
  1683. * ice_xlt_kb_get_rss - create rss xlt key build
  1684. * @hw: pointer to the hardware structure
  1685. *
  1686. * Return: a pointer to the allocated Key Builder table for RSS.
  1687. */
  1688. static struct ice_xlt_kb *ice_xlt_kb_get_rss(struct ice_hw *hw)
  1689. {
  1690. return ice_xlt_kb_get(hw, ICE_SID_XLT_KEY_BUILDER_RSS);
  1691. }
  1692. #define ICE_XLT_KB_MASK GENMASK_ULL(5, 0)
  1693. /**
  1694. * ice_xlt_kb_flag_get - aggregate 64 bits packet flag into 16 bits xlt flag
  1695. * @kb: xlt key build
  1696. * @pkt_flag: 64 bits packet flag
  1697. *
  1698. * Return: XLT flag or 0 if @pkt_flag = 0.
  1699. */
  1700. u16 ice_xlt_kb_flag_get(struct ice_xlt_kb *kb, u64 pkt_flag)
  1701. {
  1702. struct ice_xlt_kb_entry *entry = &kb->entries[0];
  1703. u16 flag = 0;
  1704. int i;
  1705. /* check flag 15 */
  1706. if (kb->flag15 & pkt_flag)
  1707. flag = BIT(ICE_XLT_KB_FLAG0_14_CNT);
  1708. /* check flag 0 - 14 */
  1709. for (i = 0; i < ICE_XLT_KB_FLAG0_14_CNT; i++) {
  1710. /* only check first entry */
  1711. u16 idx = entry->flg0_14_sel[i] & ICE_XLT_KB_MASK;
  1712. if (pkt_flag & BIT(idx))
  1713. flag |= (u16)BIT(i);
  1714. }
  1715. return flag;
  1716. }
  1717. /*** Parser API ***/
  1718. /**
  1719. * ice_parser_create - create a parser instance
  1720. * @hw: pointer to the hardware structure
  1721. *
  1722. * Return: a pointer to the allocated parser instance or ERR_PTR
  1723. * in case of error.
  1724. */
  1725. struct ice_parser *ice_parser_create(struct ice_hw *hw)
  1726. {
  1727. struct ice_parser *p;
  1728. void *err;
  1729. p = kzalloc(sizeof(*p), GFP_KERNEL);
  1730. if (!p)
  1731. return ERR_PTR(-ENOMEM);
  1732. p->hw = hw;
  1733. p->rt.psr = p;
  1734. p->imem_table = ice_imem_table_get(hw);
  1735. if (IS_ERR(p->imem_table)) {
  1736. err = p->imem_table;
  1737. goto err;
  1738. }
  1739. p->mi_table = ice_metainit_table_get(hw);
  1740. if (IS_ERR(p->mi_table)) {
  1741. err = p->mi_table;
  1742. goto err;
  1743. }
  1744. p->pg_cam_table = ice_pg_cam_table_get(hw);
  1745. if (IS_ERR(p->pg_cam_table)) {
  1746. err = p->pg_cam_table;
  1747. goto err;
  1748. }
  1749. p->pg_sp_cam_table = ice_pg_sp_cam_table_get(hw);
  1750. if (IS_ERR(p->pg_sp_cam_table)) {
  1751. err = p->pg_sp_cam_table;
  1752. goto err;
  1753. }
  1754. p->pg_nm_cam_table = ice_pg_nm_cam_table_get(hw);
  1755. if (IS_ERR(p->pg_nm_cam_table)) {
  1756. err = p->pg_nm_cam_table;
  1757. goto err;
  1758. }
  1759. p->pg_nm_sp_cam_table = ice_pg_nm_sp_cam_table_get(hw);
  1760. if (IS_ERR(p->pg_nm_sp_cam_table)) {
  1761. err = p->pg_nm_sp_cam_table;
  1762. goto err;
  1763. }
  1764. p->bst_tcam_table = ice_bst_tcam_table_get(hw);
  1765. if (IS_ERR(p->bst_tcam_table)) {
  1766. err = p->bst_tcam_table;
  1767. goto err;
  1768. }
  1769. p->bst_lbl_table = ice_bst_lbl_table_get(hw);
  1770. if (IS_ERR(p->bst_lbl_table)) {
  1771. err = p->bst_lbl_table;
  1772. goto err;
  1773. }
  1774. p->ptype_mk_tcam_table = ice_ptype_mk_tcam_table_get(hw);
  1775. if (IS_ERR(p->ptype_mk_tcam_table)) {
  1776. err = p->ptype_mk_tcam_table;
  1777. goto err;
  1778. }
  1779. p->mk_grp_table = ice_mk_grp_table_get(hw);
  1780. if (IS_ERR(p->mk_grp_table)) {
  1781. err = p->mk_grp_table;
  1782. goto err;
  1783. }
  1784. p->proto_grp_table = ice_proto_grp_table_get(hw);
  1785. if (IS_ERR(p->proto_grp_table)) {
  1786. err = p->proto_grp_table;
  1787. goto err;
  1788. }
  1789. p->flg_rd_table = ice_flg_rd_table_get(hw);
  1790. if (IS_ERR(p->flg_rd_table)) {
  1791. err = p->flg_rd_table;
  1792. goto err;
  1793. }
  1794. p->xlt_kb_sw = ice_xlt_kb_get_sw(hw);
  1795. if (IS_ERR(p->xlt_kb_sw)) {
  1796. err = p->xlt_kb_sw;
  1797. goto err;
  1798. }
  1799. p->xlt_kb_acl = ice_xlt_kb_get_acl(hw);
  1800. if (IS_ERR(p->xlt_kb_acl)) {
  1801. err = p->xlt_kb_acl;
  1802. goto err;
  1803. }
  1804. p->xlt_kb_fd = ice_xlt_kb_get_fd(hw);
  1805. if (IS_ERR(p->xlt_kb_fd)) {
  1806. err = p->xlt_kb_fd;
  1807. goto err;
  1808. }
  1809. p->xlt_kb_rss = ice_xlt_kb_get_rss(hw);
  1810. if (IS_ERR(p->xlt_kb_rss)) {
  1811. err = p->xlt_kb_rss;
  1812. goto err;
  1813. }
  1814. return p;
  1815. err:
  1816. ice_parser_destroy(p);
  1817. return err;
  1818. }
  1819. /**
  1820. * ice_parser_destroy - destroy a parser instance
  1821. * @psr: pointer to a parser instance
  1822. */
  1823. void ice_parser_destroy(struct ice_parser *psr)
  1824. {
  1825. kfree(psr->imem_table);
  1826. kfree(psr->mi_table);
  1827. kfree(psr->pg_cam_table);
  1828. kfree(psr->pg_sp_cam_table);
  1829. kfree(psr->pg_nm_cam_table);
  1830. kfree(psr->pg_nm_sp_cam_table);
  1831. kfree(psr->bst_tcam_table);
  1832. kfree(psr->bst_lbl_table);
  1833. kfree(psr->ptype_mk_tcam_table);
  1834. kfree(psr->mk_grp_table);
  1835. kfree(psr->proto_grp_table);
  1836. kfree(psr->flg_rd_table);
  1837. kfree(psr->xlt_kb_sw);
  1838. kfree(psr->xlt_kb_acl);
  1839. kfree(psr->xlt_kb_fd);
  1840. kfree(psr->xlt_kb_rss);
  1841. kfree(psr);
  1842. }
  1843. /**
  1844. * ice_parser_run - parse on a packet in binary and return the result
  1845. * @psr: pointer to a parser instance
  1846. * @pkt_buf: packet data
  1847. * @pkt_len: packet length
  1848. * @rslt: input/output parameter to save parser result.
  1849. *
  1850. * Return: 0 on success or errno.
  1851. */
  1852. int ice_parser_run(struct ice_parser *psr, const u8 *pkt_buf,
  1853. int pkt_len, struct ice_parser_result *rslt)
  1854. {
  1855. ice_parser_rt_reset(&psr->rt);
  1856. ice_parser_rt_pktbuf_set(&psr->rt, pkt_buf, pkt_len);
  1857. return ice_parser_rt_execute(&psr->rt, rslt);
  1858. }
  1859. /**
  1860. * ice_parser_result_dump - dump a parser result info
  1861. * @hw: pointer to the hardware structure
  1862. * @rslt: parser result info to dump
  1863. */
  1864. void ice_parser_result_dump(struct ice_hw *hw, struct ice_parser_result *rslt)
  1865. {
  1866. struct device *dev = ice_hw_to_dev(hw);
  1867. int i;
  1868. dev_info(dev, "ptype = %d\n", rslt->ptype);
  1869. for (i = 0; i < rslt->po_num; i++)
  1870. dev_info(dev, "proto = %d, offset = %d\n",
  1871. rslt->po[i].proto_id, rslt->po[i].offset);
  1872. dev_info(dev, "flags_psr = 0x%016llx\n", rslt->flags_psr);
  1873. dev_info(dev, "flags_pkt = 0x%016llx\n", rslt->flags_pkt);
  1874. dev_info(dev, "flags_sw = 0x%04x\n", rslt->flags_sw);
  1875. dev_info(dev, "flags_fd = 0x%04x\n", rslt->flags_fd);
  1876. dev_info(dev, "flags_rss = 0x%04x\n", rslt->flags_rss);
  1877. }
  1878. #define ICE_BT_VLD_KEY 0xFF
  1879. #define ICE_BT_INV_KEY 0xFE
  1880. static void ice_bst_dvm_set(struct ice_parser *psr, enum ice_lbl_type type,
  1881. bool on)
  1882. {
  1883. u16 i = 0;
  1884. while (true) {
  1885. struct ice_bst_tcam_item *item;
  1886. u8 key;
  1887. item = ice_bst_tcam_search(psr->bst_tcam_table,
  1888. psr->bst_lbl_table,
  1889. type, &i);
  1890. if (!item)
  1891. break;
  1892. key = on ? ICE_BT_VLD_KEY : ICE_BT_INV_KEY;
  1893. item->key[ICE_BT_VM_OFF] = key;
  1894. item->key_inv[ICE_BT_VM_OFF] = key;
  1895. i++;
  1896. }
  1897. }
  1898. /**
  1899. * ice_parser_dvm_set - configure double vlan mode for parser
  1900. * @psr: pointer to a parser instance
  1901. * @on: true to turn on; false to turn off
  1902. */
  1903. void ice_parser_dvm_set(struct ice_parser *psr, bool on)
  1904. {
  1905. ice_bst_dvm_set(psr, ICE_LBL_BST_TYPE_DVM, on);
  1906. ice_bst_dvm_set(psr, ICE_LBL_BST_TYPE_SVM, !on);
  1907. }
  1908. static int ice_tunnel_port_set(struct ice_parser *psr, enum ice_lbl_type type,
  1909. u16 udp_port, bool on)
  1910. {
  1911. u8 *buf = (u8 *)&udp_port;
  1912. u16 i = 0;
  1913. while (true) {
  1914. struct ice_bst_tcam_item *item;
  1915. item = ice_bst_tcam_search(psr->bst_tcam_table,
  1916. psr->bst_lbl_table,
  1917. type, &i);
  1918. if (!item)
  1919. break;
  1920. /* found empty slot to add */
  1921. if (on && item->key[ICE_BT_TUN_PORT_OFF_H] == ICE_BT_INV_KEY &&
  1922. item->key_inv[ICE_BT_TUN_PORT_OFF_H] == ICE_BT_INV_KEY) {
  1923. item->key_inv[ICE_BT_TUN_PORT_OFF_L] =
  1924. buf[ICE_UDP_PORT_OFF_L];
  1925. item->key_inv[ICE_BT_TUN_PORT_OFF_H] =
  1926. buf[ICE_UDP_PORT_OFF_H];
  1927. item->key[ICE_BT_TUN_PORT_OFF_L] =
  1928. ICE_BT_VLD_KEY - buf[ICE_UDP_PORT_OFF_L];
  1929. item->key[ICE_BT_TUN_PORT_OFF_H] =
  1930. ICE_BT_VLD_KEY - buf[ICE_UDP_PORT_OFF_H];
  1931. return 0;
  1932. /* found a matched slot to delete */
  1933. } else if (!on &&
  1934. (item->key_inv[ICE_BT_TUN_PORT_OFF_L] ==
  1935. buf[ICE_UDP_PORT_OFF_L] ||
  1936. item->key_inv[ICE_BT_TUN_PORT_OFF_H] ==
  1937. buf[ICE_UDP_PORT_OFF_H])) {
  1938. item->key_inv[ICE_BT_TUN_PORT_OFF_L] = ICE_BT_VLD_KEY;
  1939. item->key_inv[ICE_BT_TUN_PORT_OFF_H] = ICE_BT_INV_KEY;
  1940. item->key[ICE_BT_TUN_PORT_OFF_L] = ICE_BT_VLD_KEY;
  1941. item->key[ICE_BT_TUN_PORT_OFF_H] = ICE_BT_INV_KEY;
  1942. return 0;
  1943. }
  1944. i++;
  1945. }
  1946. return -EINVAL;
  1947. }
  1948. /**
  1949. * ice_parser_vxlan_tunnel_set - configure vxlan tunnel for parser
  1950. * @psr: pointer to a parser instance
  1951. * @udp_port: vxlan tunnel port in UDP header
  1952. * @on: true to turn on; false to turn off
  1953. *
  1954. * Return: 0 on success or errno on failure.
  1955. */
  1956. int ice_parser_vxlan_tunnel_set(struct ice_parser *psr,
  1957. u16 udp_port, bool on)
  1958. {
  1959. return ice_tunnel_port_set(psr, ICE_LBL_BST_TYPE_VXLAN, udp_port, on);
  1960. }
  1961. /**
  1962. * ice_parser_geneve_tunnel_set - configure geneve tunnel for parser
  1963. * @psr: pointer to a parser instance
  1964. * @udp_port: geneve tunnel port in UDP header
  1965. * @on: true to turn on; false to turn off
  1966. *
  1967. * Return: 0 on success or errno on failure.
  1968. */
  1969. int ice_parser_geneve_tunnel_set(struct ice_parser *psr,
  1970. u16 udp_port, bool on)
  1971. {
  1972. return ice_tunnel_port_set(psr, ICE_LBL_BST_TYPE_GENEVE, udp_port, on);
  1973. }
  1974. /**
  1975. * ice_parser_ecpri_tunnel_set - configure ecpri tunnel for parser
  1976. * @psr: pointer to a parser instance
  1977. * @udp_port: ecpri tunnel port in UDP header
  1978. * @on: true to turn on; false to turn off
  1979. *
  1980. * Return: 0 on success or errno on failure.
  1981. */
  1982. int ice_parser_ecpri_tunnel_set(struct ice_parser *psr,
  1983. u16 udp_port, bool on)
  1984. {
  1985. return ice_tunnel_port_set(psr, ICE_LBL_BST_TYPE_UDP_ECPRI,
  1986. udp_port, on);
  1987. }
  1988. /**
  1989. * ice_nearest_proto_id - find nearest protocol ID
  1990. * @rslt: pointer to a parser result instance
  1991. * @offset: a min value for the protocol offset
  1992. * @proto_id: the protocol ID (output)
  1993. * @proto_off: the protocol offset (output)
  1994. *
  1995. * From the protocols in @rslt, find the nearest protocol that has offset
  1996. * larger than @offset.
  1997. *
  1998. * Return: if true, the protocol's ID and offset
  1999. */
  2000. static bool ice_nearest_proto_id(struct ice_parser_result *rslt, u16 offset,
  2001. u8 *proto_id, u16 *proto_off)
  2002. {
  2003. u16 dist = U16_MAX;
  2004. u8 proto = 0;
  2005. int i;
  2006. for (i = 0; i < rslt->po_num; i++) {
  2007. if (offset < rslt->po[i].offset)
  2008. continue;
  2009. if (offset - rslt->po[i].offset < dist) {
  2010. proto = rslt->po[i].proto_id;
  2011. dist = offset - rslt->po[i].offset;
  2012. }
  2013. }
  2014. if (dist % 2)
  2015. return false;
  2016. *proto_id = proto;
  2017. *proto_off = dist;
  2018. return true;
  2019. }
  2020. /* default flag mask to cover GTP_EH_PDU, GTP_EH_PDU_LINK and TUN2
  2021. * In future, the flag masks should learn from DDP
  2022. */
  2023. #define ICE_KEYBUILD_FLAG_MASK_DEFAULT_SW 0x4002
  2024. #define ICE_KEYBUILD_FLAG_MASK_DEFAULT_ACL 0x0000
  2025. #define ICE_KEYBUILD_FLAG_MASK_DEFAULT_FD 0x6080
  2026. #define ICE_KEYBUILD_FLAG_MASK_DEFAULT_RSS 0x6010
  2027. /**
  2028. * ice_parser_profile_init - initialize a FXP profile based on parser result
  2029. * @rslt: a instance of a parser result
  2030. * @pkt_buf: packet data buffer
  2031. * @msk_buf: packet mask buffer
  2032. * @buf_len: packet length
  2033. * @blk: FXP pipeline stage
  2034. * @prof: input/output parameter to save the profile
  2035. *
  2036. * Return: 0 on success or errno on failure.
  2037. */
  2038. int ice_parser_profile_init(struct ice_parser_result *rslt,
  2039. const u8 *pkt_buf, const u8 *msk_buf,
  2040. int buf_len, enum ice_block blk,
  2041. struct ice_parser_profile *prof)
  2042. {
  2043. u8 proto_id = U8_MAX;
  2044. u16 proto_off = 0;
  2045. u16 off;
  2046. memset(prof, 0, sizeof(*prof));
  2047. set_bit(rslt->ptype, prof->ptypes);
  2048. if (blk == ICE_BLK_SW) {
  2049. prof->flags = rslt->flags_sw;
  2050. prof->flags_msk = ICE_KEYBUILD_FLAG_MASK_DEFAULT_SW;
  2051. } else if (blk == ICE_BLK_ACL) {
  2052. prof->flags = rslt->flags_acl;
  2053. prof->flags_msk = ICE_KEYBUILD_FLAG_MASK_DEFAULT_ACL;
  2054. } else if (blk == ICE_BLK_FD) {
  2055. prof->flags = rslt->flags_fd;
  2056. prof->flags_msk = ICE_KEYBUILD_FLAG_MASK_DEFAULT_FD;
  2057. } else if (blk == ICE_BLK_RSS) {
  2058. prof->flags = rslt->flags_rss;
  2059. prof->flags_msk = ICE_KEYBUILD_FLAG_MASK_DEFAULT_RSS;
  2060. } else {
  2061. return -EINVAL;
  2062. }
  2063. for (off = 0; off < buf_len - 1; off++) {
  2064. if (msk_buf[off] == 0 && msk_buf[off + 1] == 0)
  2065. continue;
  2066. if (!ice_nearest_proto_id(rslt, off, &proto_id, &proto_off))
  2067. continue;
  2068. if (prof->fv_num >= ICE_PARSER_FV_MAX)
  2069. return -EINVAL;
  2070. prof->fv[prof->fv_num].proto_id = proto_id;
  2071. prof->fv[prof->fv_num].offset = proto_off;
  2072. prof->fv[prof->fv_num].spec = *(const u16 *)&pkt_buf[off];
  2073. prof->fv[prof->fv_num].msk = *(const u16 *)&msk_buf[off];
  2074. prof->fv_num++;
  2075. }
  2076. return 0;
  2077. }
  2078. /**
  2079. * ice_parser_profile_dump - dump an FXP profile info
  2080. * @hw: pointer to the hardware structure
  2081. * @prof: profile info to dump
  2082. */
  2083. void ice_parser_profile_dump(struct ice_hw *hw,
  2084. struct ice_parser_profile *prof)
  2085. {
  2086. struct device *dev = ice_hw_to_dev(hw);
  2087. u16 i;
  2088. dev_info(dev, "ptypes:\n");
  2089. for (i = 0; i < ICE_FLOW_PTYPE_MAX; i++)
  2090. if (test_bit(i, prof->ptypes))
  2091. dev_info(dev, "\t%u\n", i);
  2092. for (i = 0; i < prof->fv_num; i++)
  2093. dev_info(dev, "proto = %u, offset = %2u, spec = 0x%04x, mask = 0x%04x\n",
  2094. prof->fv[i].proto_id, prof->fv[i].offset,
  2095. prof->fv[i].spec, prof->fv[i].msk);
  2096. dev_info(dev, "flags = 0x%04x\n", prof->flags);
  2097. dev_info(dev, "flags_msk = 0x%04x\n", prof->flags_msk);
  2098. }