hns_dsaf_main.c 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163
  1. /*
  2. * Copyright (c) 2014-2015 Hisilicon Limited.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. */
  9. #include <linux/acpi.h>
  10. #include <linux/device.h>
  11. #include <linux/init.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/netdevice.h>
  16. #include <linux/mfd/syscon.h>
  17. #include <linux/of.h>
  18. #include <linux/of_address.h>
  19. #include <linux/of_irq.h>
  20. #include <linux/of_platform.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/vmalloc.h>
  23. #include "hns_dsaf_mac.h"
  24. #include "hns_dsaf_main.h"
  25. #include "hns_dsaf_ppe.h"
  26. #include "hns_dsaf_rcb.h"
  27. #include "hns_dsaf_misc.h"
  28. const static char *g_dsaf_mode_match[DSAF_MODE_MAX] = {
  29. [DSAF_MODE_DISABLE_2PORT_64VM] = "2port-64vf",
  30. [DSAF_MODE_DISABLE_6PORT_0VM] = "6port-16rss",
  31. [DSAF_MODE_DISABLE_6PORT_16VM] = "6port-16vf",
  32. [DSAF_MODE_DISABLE_SP] = "single-port",
  33. };
  34. static const struct acpi_device_id hns_dsaf_acpi_match[] = {
  35. { "HISI00B1", 0 },
  36. { "HISI00B2", 0 },
  37. { },
  38. };
  39. MODULE_DEVICE_TABLE(acpi, hns_dsaf_acpi_match);
  40. static int hns_dsaf_get_cfg(struct dsaf_device *dsaf_dev)
  41. {
  42. int ret, i;
  43. u32 desc_num;
  44. u32 buf_size;
  45. u32 reset_offset = 0;
  46. u32 res_idx = 0;
  47. const char *mode_str;
  48. struct regmap *syscon;
  49. struct resource *res;
  50. struct device_node *np = dsaf_dev->dev->of_node, *np_temp;
  51. struct platform_device *pdev = to_platform_device(dsaf_dev->dev);
  52. if (dev_of_node(dsaf_dev->dev)) {
  53. if (of_device_is_compatible(np, "hisilicon,hns-dsaf-v1"))
  54. dsaf_dev->dsaf_ver = AE_VERSION_1;
  55. else
  56. dsaf_dev->dsaf_ver = AE_VERSION_2;
  57. } else if (is_acpi_node(dsaf_dev->dev->fwnode)) {
  58. if (acpi_dev_found(hns_dsaf_acpi_match[0].id))
  59. dsaf_dev->dsaf_ver = AE_VERSION_1;
  60. else if (acpi_dev_found(hns_dsaf_acpi_match[1].id))
  61. dsaf_dev->dsaf_ver = AE_VERSION_2;
  62. else
  63. return -ENXIO;
  64. } else {
  65. dev_err(dsaf_dev->dev, "cannot get cfg data from of or acpi\n");
  66. return -ENXIO;
  67. }
  68. ret = device_property_read_string(dsaf_dev->dev, "mode", &mode_str);
  69. if (ret) {
  70. dev_err(dsaf_dev->dev, "get dsaf mode fail, ret=%d!\n", ret);
  71. return ret;
  72. }
  73. for (i = 0; i < DSAF_MODE_MAX; i++) {
  74. if (g_dsaf_mode_match[i] &&
  75. !strcmp(mode_str, g_dsaf_mode_match[i]))
  76. break;
  77. }
  78. if (i >= DSAF_MODE_MAX ||
  79. i == DSAF_MODE_INVALID || i == DSAF_MODE_ENABLE) {
  80. dev_err(dsaf_dev->dev,
  81. "%s prs mode str fail!\n", dsaf_dev->ae_dev.name);
  82. return -EINVAL;
  83. }
  84. dsaf_dev->dsaf_mode = (enum dsaf_mode)i;
  85. if (dsaf_dev->dsaf_mode > DSAF_MODE_ENABLE)
  86. dsaf_dev->dsaf_en = HRD_DSAF_NO_DSAF_MODE;
  87. else
  88. dsaf_dev->dsaf_en = HRD_DSAF_MODE;
  89. if ((i == DSAF_MODE_ENABLE_16VM) ||
  90. (i == DSAF_MODE_DISABLE_2PORT_8VM) ||
  91. (i == DSAF_MODE_DISABLE_6PORT_2VM))
  92. dsaf_dev->dsaf_tc_mode = HRD_DSAF_8TC_MODE;
  93. else
  94. dsaf_dev->dsaf_tc_mode = HRD_DSAF_4TC_MODE;
  95. if (dev_of_node(dsaf_dev->dev)) {
  96. np_temp = of_parse_phandle(np, "subctrl-syscon", 0);
  97. syscon = syscon_node_to_regmap(np_temp);
  98. of_node_put(np_temp);
  99. if (IS_ERR_OR_NULL(syscon)) {
  100. res = platform_get_resource(pdev, IORESOURCE_MEM,
  101. res_idx++);
  102. if (!res) {
  103. dev_err(dsaf_dev->dev, "subctrl info is needed!\n");
  104. return -ENOMEM;
  105. }
  106. dsaf_dev->sc_base = devm_ioremap_resource(&pdev->dev,
  107. res);
  108. if (IS_ERR(dsaf_dev->sc_base))
  109. return PTR_ERR(dsaf_dev->sc_base);
  110. res = platform_get_resource(pdev, IORESOURCE_MEM,
  111. res_idx++);
  112. if (!res) {
  113. dev_err(dsaf_dev->dev, "serdes-ctrl info is needed!\n");
  114. return -ENOMEM;
  115. }
  116. dsaf_dev->sds_base = devm_ioremap_resource(&pdev->dev,
  117. res);
  118. if (IS_ERR(dsaf_dev->sds_base))
  119. return PTR_ERR(dsaf_dev->sds_base);
  120. } else {
  121. dsaf_dev->sub_ctrl = syscon;
  122. }
  123. }
  124. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ppe-base");
  125. if (!res) {
  126. res = platform_get_resource(pdev, IORESOURCE_MEM, res_idx++);
  127. if (!res) {
  128. dev_err(dsaf_dev->dev, "ppe-base info is needed!\n");
  129. return -ENOMEM;
  130. }
  131. }
  132. dsaf_dev->ppe_base = devm_ioremap_resource(&pdev->dev, res);
  133. if (IS_ERR(dsaf_dev->ppe_base))
  134. return PTR_ERR(dsaf_dev->ppe_base);
  135. dsaf_dev->ppe_paddr = res->start;
  136. if (!HNS_DSAF_IS_DEBUG(dsaf_dev)) {
  137. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  138. "dsaf-base");
  139. if (!res) {
  140. res = platform_get_resource(pdev, IORESOURCE_MEM,
  141. res_idx);
  142. if (!res) {
  143. dev_err(dsaf_dev->dev,
  144. "dsaf-base info is needed!\n");
  145. return -ENOMEM;
  146. }
  147. }
  148. dsaf_dev->io_base = devm_ioremap_resource(&pdev->dev, res);
  149. if (IS_ERR(dsaf_dev->io_base))
  150. return PTR_ERR(dsaf_dev->io_base);
  151. }
  152. ret = device_property_read_u32(dsaf_dev->dev, "desc-num", &desc_num);
  153. if (ret < 0 || desc_num < HNS_DSAF_MIN_DESC_CNT ||
  154. desc_num > HNS_DSAF_MAX_DESC_CNT) {
  155. dev_err(dsaf_dev->dev, "get desc-num(%d) fail, ret=%d!\n",
  156. desc_num, ret);
  157. return -EINVAL;
  158. }
  159. dsaf_dev->desc_num = desc_num;
  160. ret = device_property_read_u32(dsaf_dev->dev, "reset-field-offset",
  161. &reset_offset);
  162. if (ret < 0) {
  163. dev_dbg(dsaf_dev->dev,
  164. "get reset-field-offset fail, ret=%d!\r\n", ret);
  165. }
  166. dsaf_dev->reset_offset = reset_offset;
  167. ret = device_property_read_u32(dsaf_dev->dev, "buf-size", &buf_size);
  168. if (ret < 0) {
  169. dev_err(dsaf_dev->dev,
  170. "get buf-size fail, ret=%d!\r\n", ret);
  171. return ret;
  172. }
  173. dsaf_dev->buf_size = buf_size;
  174. dsaf_dev->buf_size_type = hns_rcb_buf_size2type(buf_size);
  175. if (dsaf_dev->buf_size_type < 0) {
  176. dev_err(dsaf_dev->dev,
  177. "buf_size(%d) is wrong!\n", buf_size);
  178. return -EINVAL;
  179. }
  180. dsaf_dev->misc_op = hns_misc_op_get(dsaf_dev);
  181. if (!dsaf_dev->misc_op)
  182. return -ENOMEM;
  183. if (!dma_set_mask_and_coherent(dsaf_dev->dev, DMA_BIT_MASK(64ULL)))
  184. dev_dbg(dsaf_dev->dev, "set mask to 64bit\n");
  185. else
  186. dev_err(dsaf_dev->dev, "set mask to 64bit fail!\n");
  187. return 0;
  188. }
  189. /**
  190. * hns_dsaf_sbm_link_sram_init_en - config dsaf_sbm_init_en
  191. * @dsaf_id: dsa fabric id
  192. */
  193. static void hns_dsaf_sbm_link_sram_init_en(struct dsaf_device *dsaf_dev)
  194. {
  195. dsaf_set_dev_bit(dsaf_dev, DSAF_CFG_0_REG, DSAF_CFG_SBM_INIT_S, 1);
  196. }
  197. /**
  198. * hns_dsaf_reg_cnt_clr_ce - config hns_dsaf_reg_cnt_clr_ce
  199. * @dsaf_id: dsa fabric id
  200. * @hns_dsaf_reg_cnt_clr_ce: config value
  201. */
  202. static void
  203. hns_dsaf_reg_cnt_clr_ce(struct dsaf_device *dsaf_dev, u32 reg_cnt_clr_ce)
  204. {
  205. dsaf_set_dev_bit(dsaf_dev, DSAF_DSA_REG_CNT_CLR_CE_REG,
  206. DSAF_CNT_CLR_CE_S, reg_cnt_clr_ce);
  207. }
  208. /**
  209. * hns_ppe_qid_cfg - config ppe qid
  210. * @dsaf_id: dsa fabric id
  211. * @pppe_qid_cfg: value array
  212. */
  213. static void
  214. hns_dsaf_ppe_qid_cfg(struct dsaf_device *dsaf_dev, u32 qid_cfg)
  215. {
  216. u32 i;
  217. for (i = 0; i < DSAF_COMM_CHN; i++) {
  218. dsaf_set_dev_field(dsaf_dev,
  219. DSAF_PPE_QID_CFG_0_REG + 0x0004 * i,
  220. DSAF_PPE_QID_CFG_M, DSAF_PPE_QID_CFG_S,
  221. qid_cfg);
  222. }
  223. }
  224. static void hns_dsaf_mix_def_qid_cfg(struct dsaf_device *dsaf_dev)
  225. {
  226. u16 max_q_per_vf, max_vfn;
  227. u32 q_id, q_num_per_port;
  228. u32 i;
  229. hns_rcb_get_queue_mode(dsaf_dev->dsaf_mode, &max_vfn, &max_q_per_vf);
  230. q_num_per_port = max_vfn * max_q_per_vf;
  231. for (i = 0, q_id = 0; i < DSAF_SERVICE_NW_NUM; i++) {
  232. dsaf_set_dev_field(dsaf_dev,
  233. DSAF_MIX_DEF_QID_0_REG + 0x0004 * i,
  234. 0xff, 0, q_id);
  235. q_id += q_num_per_port;
  236. }
  237. }
  238. static void hns_dsaf_inner_qid_cfg(struct dsaf_device *dsaf_dev)
  239. {
  240. u16 max_q_per_vf, max_vfn;
  241. u32 q_id, q_num_per_port;
  242. u32 mac_id;
  243. if (AE_IS_VER1(dsaf_dev->dsaf_ver))
  244. return;
  245. hns_rcb_get_queue_mode(dsaf_dev->dsaf_mode, &max_vfn, &max_q_per_vf);
  246. q_num_per_port = max_vfn * max_q_per_vf;
  247. for (mac_id = 0, q_id = 0; mac_id < DSAF_SERVICE_NW_NUM; mac_id++) {
  248. dsaf_set_dev_field(dsaf_dev,
  249. DSAFV2_SERDES_LBK_0_REG + 4 * mac_id,
  250. DSAFV2_SERDES_LBK_QID_M,
  251. DSAFV2_SERDES_LBK_QID_S,
  252. q_id);
  253. q_id += q_num_per_port;
  254. }
  255. }
  256. /**
  257. * hns_dsaf_sw_port_type_cfg - cfg sw type
  258. * @dsaf_id: dsa fabric id
  259. * @psw_port_type: array
  260. */
  261. static void hns_dsaf_sw_port_type_cfg(struct dsaf_device *dsaf_dev,
  262. enum dsaf_sw_port_type port_type)
  263. {
  264. u32 i;
  265. for (i = 0; i < DSAF_SW_PORT_NUM; i++) {
  266. dsaf_set_dev_field(dsaf_dev,
  267. DSAF_SW_PORT_TYPE_0_REG + 0x0004 * i,
  268. DSAF_SW_PORT_TYPE_M, DSAF_SW_PORT_TYPE_S,
  269. port_type);
  270. }
  271. }
  272. /**
  273. * hns_dsaf_stp_port_type_cfg - cfg stp type
  274. * @dsaf_id: dsa fabric id
  275. * @pstp_port_type: array
  276. */
  277. static void hns_dsaf_stp_port_type_cfg(struct dsaf_device *dsaf_dev,
  278. enum dsaf_stp_port_type port_type)
  279. {
  280. u32 i;
  281. for (i = 0; i < DSAF_COMM_CHN; i++) {
  282. dsaf_set_dev_field(dsaf_dev,
  283. DSAF_STP_PORT_TYPE_0_REG + 0x0004 * i,
  284. DSAF_STP_PORT_TYPE_M, DSAF_STP_PORT_TYPE_S,
  285. port_type);
  286. }
  287. }
  288. #define HNS_DSAF_SBM_NUM(dev) \
  289. (AE_IS_VER1((dev)->dsaf_ver) ? DSAF_SBM_NUM : DSAFV2_SBM_NUM)
  290. /**
  291. * hns_dsaf_sbm_cfg - config sbm
  292. * @dsaf_id: dsa fabric id
  293. */
  294. static void hns_dsaf_sbm_cfg(struct dsaf_device *dsaf_dev)
  295. {
  296. u32 o_sbm_cfg;
  297. u32 i;
  298. for (i = 0; i < HNS_DSAF_SBM_NUM(dsaf_dev); i++) {
  299. o_sbm_cfg = dsaf_read_dev(dsaf_dev,
  300. DSAF_SBM_CFG_REG_0_REG + 0x80 * i);
  301. dsaf_set_bit(o_sbm_cfg, DSAF_SBM_CFG_EN_S, 1);
  302. dsaf_set_bit(o_sbm_cfg, DSAF_SBM_CFG_SHCUT_EN_S, 0);
  303. dsaf_write_dev(dsaf_dev,
  304. DSAF_SBM_CFG_REG_0_REG + 0x80 * i, o_sbm_cfg);
  305. }
  306. }
  307. /**
  308. * hns_dsaf_sbm_cfg_mib_en - config sbm
  309. * @dsaf_id: dsa fabric id
  310. */
  311. static int hns_dsaf_sbm_cfg_mib_en(struct dsaf_device *dsaf_dev)
  312. {
  313. u32 sbm_cfg_mib_en;
  314. u32 i;
  315. u32 reg;
  316. u32 read_cnt;
  317. /* validate configure by setting SBM_CFG_MIB_EN bit from 0 to 1. */
  318. for (i = 0; i < HNS_DSAF_SBM_NUM(dsaf_dev); i++) {
  319. reg = DSAF_SBM_CFG_REG_0_REG + 0x80 * i;
  320. dsaf_set_dev_bit(dsaf_dev, reg, DSAF_SBM_CFG_MIB_EN_S, 0);
  321. }
  322. for (i = 0; i < HNS_DSAF_SBM_NUM(dsaf_dev); i++) {
  323. reg = DSAF_SBM_CFG_REG_0_REG + 0x80 * i;
  324. dsaf_set_dev_bit(dsaf_dev, reg, DSAF_SBM_CFG_MIB_EN_S, 1);
  325. }
  326. /* waitint for all sbm enable finished */
  327. for (i = 0; i < HNS_DSAF_SBM_NUM(dsaf_dev); i++) {
  328. read_cnt = 0;
  329. reg = DSAF_SBM_CFG_REG_0_REG + 0x80 * i;
  330. do {
  331. udelay(1);
  332. sbm_cfg_mib_en = dsaf_get_dev_bit(
  333. dsaf_dev, reg, DSAF_SBM_CFG_MIB_EN_S);
  334. read_cnt++;
  335. } while (sbm_cfg_mib_en == 0 &&
  336. read_cnt < DSAF_CFG_READ_CNT);
  337. if (sbm_cfg_mib_en == 0) {
  338. dev_err(dsaf_dev->dev,
  339. "sbm_cfg_mib_en fail,%s,sbm_num=%d\n",
  340. dsaf_dev->ae_dev.name, i);
  341. return -ENODEV;
  342. }
  343. }
  344. return 0;
  345. }
  346. /**
  347. * hns_dsaf_sbm_bp_wl_cfg - config sbm
  348. * @dsaf_id: dsa fabric id
  349. */
  350. static void hns_dsaf_sbm_bp_wl_cfg(struct dsaf_device *dsaf_dev)
  351. {
  352. u32 o_sbm_bp_cfg;
  353. u32 reg;
  354. u32 i;
  355. /* XGE */
  356. for (i = 0; i < DSAF_XGE_NUM; i++) {
  357. reg = DSAF_SBM_BP_CFG_0_XGE_REG_0_REG + 0x80 * i;
  358. o_sbm_bp_cfg = dsaf_read_dev(dsaf_dev, reg);
  359. dsaf_set_field(o_sbm_bp_cfg, DSAF_SBM_CFG0_COM_MAX_BUF_NUM_M,
  360. DSAF_SBM_CFG0_COM_MAX_BUF_NUM_S, 512);
  361. dsaf_set_field(o_sbm_bp_cfg, DSAF_SBM_CFG0_VC0_MAX_BUF_NUM_M,
  362. DSAF_SBM_CFG0_VC0_MAX_BUF_NUM_S, 0);
  363. dsaf_set_field(o_sbm_bp_cfg, DSAF_SBM_CFG0_VC1_MAX_BUF_NUM_M,
  364. DSAF_SBM_CFG0_VC1_MAX_BUF_NUM_S, 0);
  365. dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg);
  366. reg = DSAF_SBM_BP_CFG_1_REG_0_REG + 0x80 * i;
  367. o_sbm_bp_cfg = dsaf_read_dev(dsaf_dev, reg);
  368. dsaf_set_field(o_sbm_bp_cfg, DSAF_SBM_CFG1_TC4_MAX_BUF_NUM_M,
  369. DSAF_SBM_CFG1_TC4_MAX_BUF_NUM_S, 0);
  370. dsaf_set_field(o_sbm_bp_cfg, DSAF_SBM_CFG1_TC0_MAX_BUF_NUM_M,
  371. DSAF_SBM_CFG1_TC0_MAX_BUF_NUM_S, 0);
  372. dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg);
  373. reg = DSAF_SBM_BP_CFG_2_XGE_REG_0_REG + 0x80 * i;
  374. o_sbm_bp_cfg = dsaf_read_dev(dsaf_dev, reg);
  375. dsaf_set_field(o_sbm_bp_cfg, DSAF_SBM_CFG2_SET_BUF_NUM_M,
  376. DSAF_SBM_CFG2_SET_BUF_NUM_S, 104);
  377. dsaf_set_field(o_sbm_bp_cfg, DSAF_SBM_CFG2_RESET_BUF_NUM_M,
  378. DSAF_SBM_CFG2_RESET_BUF_NUM_S, 128);
  379. dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg);
  380. reg = DSAF_SBM_BP_CFG_3_REG_0_REG + 0x80 * i;
  381. o_sbm_bp_cfg = dsaf_read_dev(dsaf_dev, reg);
  382. dsaf_set_field(o_sbm_bp_cfg,
  383. DSAF_SBM_CFG3_SET_BUF_NUM_NO_PFC_M,
  384. DSAF_SBM_CFG3_SET_BUF_NUM_NO_PFC_S, 110);
  385. dsaf_set_field(o_sbm_bp_cfg,
  386. DSAF_SBM_CFG3_RESET_BUF_NUM_NO_PFC_M,
  387. DSAF_SBM_CFG3_RESET_BUF_NUM_NO_PFC_S, 160);
  388. dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg);
  389. /* for no enable pfc mode */
  390. reg = DSAF_SBM_BP_CFG_4_REG_0_REG + 0x80 * i;
  391. o_sbm_bp_cfg = dsaf_read_dev(dsaf_dev, reg);
  392. dsaf_set_field(o_sbm_bp_cfg,
  393. DSAF_SBM_CFG3_SET_BUF_NUM_NO_PFC_M,
  394. DSAF_SBM_CFG3_SET_BUF_NUM_NO_PFC_S, 128);
  395. dsaf_set_field(o_sbm_bp_cfg,
  396. DSAF_SBM_CFG3_RESET_BUF_NUM_NO_PFC_M,
  397. DSAF_SBM_CFG3_RESET_BUF_NUM_NO_PFC_S, 192);
  398. dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg);
  399. }
  400. /* PPE */
  401. for (i = 0; i < DSAF_COMM_CHN; i++) {
  402. reg = DSAF_SBM_BP_CFG_2_PPE_REG_0_REG + 0x80 * i;
  403. o_sbm_bp_cfg = dsaf_read_dev(dsaf_dev, reg);
  404. dsaf_set_field(o_sbm_bp_cfg, DSAF_SBM_CFG2_SET_BUF_NUM_M,
  405. DSAF_SBM_CFG2_SET_BUF_NUM_S, 10);
  406. dsaf_set_field(o_sbm_bp_cfg, DSAF_SBM_CFG2_RESET_BUF_NUM_M,
  407. DSAF_SBM_CFG2_RESET_BUF_NUM_S, 12);
  408. dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg);
  409. }
  410. /* RoCEE */
  411. for (i = 0; i < DSAF_COMM_CHN; i++) {
  412. reg = DSAF_SBM_BP_CFG_2_ROCEE_REG_0_REG + 0x80 * i;
  413. o_sbm_bp_cfg = dsaf_read_dev(dsaf_dev, reg);
  414. dsaf_set_field(o_sbm_bp_cfg, DSAF_SBM_CFG2_SET_BUF_NUM_M,
  415. DSAF_SBM_CFG2_SET_BUF_NUM_S, 2);
  416. dsaf_set_field(o_sbm_bp_cfg, DSAF_SBM_CFG2_RESET_BUF_NUM_M,
  417. DSAF_SBM_CFG2_RESET_BUF_NUM_S, 4);
  418. dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg);
  419. }
  420. }
  421. static void hns_dsafv2_sbm_bp_wl_cfg(struct dsaf_device *dsaf_dev)
  422. {
  423. u32 o_sbm_bp_cfg;
  424. u32 reg;
  425. u32 i;
  426. /* XGE */
  427. for (i = 0; i < DSAFV2_SBM_XGE_CHN; i++) {
  428. reg = DSAF_SBM_BP_CFG_0_XGE_REG_0_REG + 0x80 * i;
  429. o_sbm_bp_cfg = dsaf_read_dev(dsaf_dev, reg);
  430. dsaf_set_field(o_sbm_bp_cfg, DSAFV2_SBM_CFG0_COM_MAX_BUF_NUM_M,
  431. DSAFV2_SBM_CFG0_COM_MAX_BUF_NUM_S, 256);
  432. dsaf_set_field(o_sbm_bp_cfg, DSAFV2_SBM_CFG0_VC0_MAX_BUF_NUM_M,
  433. DSAFV2_SBM_CFG0_VC0_MAX_BUF_NUM_S, 0);
  434. dsaf_set_field(o_sbm_bp_cfg, DSAFV2_SBM_CFG0_VC1_MAX_BUF_NUM_M,
  435. DSAFV2_SBM_CFG0_VC1_MAX_BUF_NUM_S, 0);
  436. dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg);
  437. reg = DSAF_SBM_BP_CFG_1_REG_0_REG + 0x80 * i;
  438. o_sbm_bp_cfg = dsaf_read_dev(dsaf_dev, reg);
  439. dsaf_set_field(o_sbm_bp_cfg, DSAFV2_SBM_CFG1_TC4_MAX_BUF_NUM_M,
  440. DSAFV2_SBM_CFG1_TC4_MAX_BUF_NUM_S, 0);
  441. dsaf_set_field(o_sbm_bp_cfg, DSAFV2_SBM_CFG1_TC0_MAX_BUF_NUM_M,
  442. DSAFV2_SBM_CFG1_TC0_MAX_BUF_NUM_S, 0);
  443. dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg);
  444. reg = DSAF_SBM_BP_CFG_2_XGE_REG_0_REG + 0x80 * i;
  445. o_sbm_bp_cfg = dsaf_read_dev(dsaf_dev, reg);
  446. dsaf_set_field(o_sbm_bp_cfg, DSAFV2_SBM_CFG2_SET_BUF_NUM_M,
  447. DSAFV2_SBM_CFG2_SET_BUF_NUM_S, 104);
  448. dsaf_set_field(o_sbm_bp_cfg, DSAFV2_SBM_CFG2_RESET_BUF_NUM_M,
  449. DSAFV2_SBM_CFG2_RESET_BUF_NUM_S, 128);
  450. dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg);
  451. reg = DSAF_SBM_BP_CFG_3_REG_0_REG + 0x80 * i;
  452. o_sbm_bp_cfg = dsaf_read_dev(dsaf_dev, reg);
  453. dsaf_set_field(o_sbm_bp_cfg,
  454. DSAFV2_SBM_CFG3_SET_BUF_NUM_NO_PFC_M,
  455. DSAFV2_SBM_CFG3_SET_BUF_NUM_NO_PFC_S, 55);
  456. dsaf_set_field(o_sbm_bp_cfg,
  457. DSAFV2_SBM_CFG3_RESET_BUF_NUM_NO_PFC_M,
  458. DSAFV2_SBM_CFG3_RESET_BUF_NUM_NO_PFC_S, 110);
  459. dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg);
  460. /* for no enable pfc mode */
  461. reg = DSAF_SBM_BP_CFG_4_REG_0_REG + 0x80 * i;
  462. o_sbm_bp_cfg = dsaf_read_dev(dsaf_dev, reg);
  463. dsaf_set_field(o_sbm_bp_cfg,
  464. DSAFV2_SBM_CFG4_SET_BUF_NUM_NO_PFC_M,
  465. DSAFV2_SBM_CFG4_SET_BUF_NUM_NO_PFC_S, 128);
  466. dsaf_set_field(o_sbm_bp_cfg,
  467. DSAFV2_SBM_CFG4_RESET_BUF_NUM_NO_PFC_M,
  468. DSAFV2_SBM_CFG4_RESET_BUF_NUM_NO_PFC_S, 192);
  469. dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg);
  470. }
  471. /* PPE */
  472. for (i = 0; i < DSAFV2_SBM_PPE_CHN; i++) {
  473. reg = DSAF_SBM_BP_CFG_2_PPE_REG_0_REG + 0x80 * i;
  474. o_sbm_bp_cfg = dsaf_read_dev(dsaf_dev, reg);
  475. dsaf_set_field(o_sbm_bp_cfg,
  476. DSAFV2_SBM_CFG2_PPE_SET_BUF_NUM_M,
  477. DSAFV2_SBM_CFG2_PPE_SET_BUF_NUM_S, 2);
  478. dsaf_set_field(o_sbm_bp_cfg,
  479. DSAFV2_SBM_CFG2_PPE_RESET_BUF_NUM_M,
  480. DSAFV2_SBM_CFG2_PPE_RESET_BUF_NUM_S, 3);
  481. dsaf_set_field(o_sbm_bp_cfg,
  482. DSAFV2_SBM_CFG2_PPE_CFG_USEFUL_NUM_M,
  483. DSAFV2_SBM_CFG2_PPE_CFG_USEFUL_NUM_S, 52);
  484. dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg);
  485. }
  486. /* RoCEE */
  487. for (i = 0; i < DASFV2_ROCEE_CRD_NUM; i++) {
  488. reg = DSAFV2_SBM_BP_CFG_2_ROCEE_REG_0_REG + 0x80 * i;
  489. o_sbm_bp_cfg = dsaf_read_dev(dsaf_dev, reg);
  490. dsaf_set_field(o_sbm_bp_cfg,
  491. DSAFV2_SBM_CFG2_ROCEE_SET_BUF_NUM_M,
  492. DSAFV2_SBM_CFG2_ROCEE_SET_BUF_NUM_S, 2);
  493. dsaf_set_field(o_sbm_bp_cfg,
  494. DSAFV2_SBM_CFG2_ROCEE_RESET_BUF_NUM_M,
  495. DSAFV2_SBM_CFG2_ROCEE_RESET_BUF_NUM_S, 4);
  496. dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg);
  497. }
  498. }
  499. /**
  500. * hns_dsaf_voq_bp_all_thrd_cfg - voq
  501. * @dsaf_id: dsa fabric id
  502. */
  503. static void hns_dsaf_voq_bp_all_thrd_cfg(struct dsaf_device *dsaf_dev)
  504. {
  505. u32 voq_bp_all_thrd;
  506. u32 i;
  507. for (i = 0; i < DSAF_VOQ_NUM; i++) {
  508. voq_bp_all_thrd = dsaf_read_dev(
  509. dsaf_dev, DSAF_VOQ_BP_ALL_THRD_0_REG + 0x40 * i);
  510. if (i < DSAF_XGE_NUM) {
  511. dsaf_set_field(voq_bp_all_thrd,
  512. DSAF_VOQ_BP_ALL_DOWNTHRD_M,
  513. DSAF_VOQ_BP_ALL_DOWNTHRD_S, 930);
  514. dsaf_set_field(voq_bp_all_thrd,
  515. DSAF_VOQ_BP_ALL_UPTHRD_M,
  516. DSAF_VOQ_BP_ALL_UPTHRD_S, 950);
  517. } else {
  518. dsaf_set_field(voq_bp_all_thrd,
  519. DSAF_VOQ_BP_ALL_DOWNTHRD_M,
  520. DSAF_VOQ_BP_ALL_DOWNTHRD_S, 220);
  521. dsaf_set_field(voq_bp_all_thrd,
  522. DSAF_VOQ_BP_ALL_UPTHRD_M,
  523. DSAF_VOQ_BP_ALL_UPTHRD_S, 230);
  524. }
  525. dsaf_write_dev(
  526. dsaf_dev, DSAF_VOQ_BP_ALL_THRD_0_REG + 0x40 * i,
  527. voq_bp_all_thrd);
  528. }
  529. }
  530. static void hns_dsaf_tbl_tcam_match_cfg(
  531. struct dsaf_device *dsaf_dev,
  532. struct dsaf_tbl_tcam_data *ptbl_tcam_data)
  533. {
  534. dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_MATCH_CFG_L_REG,
  535. ptbl_tcam_data->tbl_tcam_data_low);
  536. dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_MATCH_CFG_H_REG,
  537. ptbl_tcam_data->tbl_tcam_data_high);
  538. }
  539. /**
  540. * hns_dsaf_tbl_tcam_data_cfg - tbl
  541. * @dsaf_id: dsa fabric id
  542. * @ptbl_tcam_data: addr
  543. */
  544. static void hns_dsaf_tbl_tcam_data_cfg(
  545. struct dsaf_device *dsaf_dev,
  546. struct dsaf_tbl_tcam_data *ptbl_tcam_data)
  547. {
  548. dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_LOW_0_REG,
  549. ptbl_tcam_data->tbl_tcam_data_low);
  550. dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_HIGH_0_REG,
  551. ptbl_tcam_data->tbl_tcam_data_high);
  552. }
  553. /**
  554. * dsaf_tbl_tcam_mcast_cfg - tbl
  555. * @dsaf_id: dsa fabric id
  556. * @ptbl_tcam_mcast: addr
  557. */
  558. static void hns_dsaf_tbl_tcam_mcast_cfg(
  559. struct dsaf_device *dsaf_dev,
  560. struct dsaf_tbl_tcam_mcast_cfg *mcast)
  561. {
  562. u32 mcast_cfg4;
  563. mcast_cfg4 = dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_MCAST_CFG_4_0_REG);
  564. dsaf_set_bit(mcast_cfg4, DSAF_TBL_MCAST_CFG4_ITEM_VLD_S,
  565. mcast->tbl_mcast_item_vld);
  566. dsaf_set_bit(mcast_cfg4, DSAF_TBL_MCAST_CFG4_OLD_EN_S,
  567. mcast->tbl_mcast_old_en);
  568. dsaf_set_field(mcast_cfg4, DSAF_TBL_MCAST_CFG4_VM128_112_M,
  569. DSAF_TBL_MCAST_CFG4_VM128_112_S,
  570. mcast->tbl_mcast_port_msk[4]);
  571. dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_MCAST_CFG_4_0_REG, mcast_cfg4);
  572. dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_MCAST_CFG_3_0_REG,
  573. mcast->tbl_mcast_port_msk[3]);
  574. dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_MCAST_CFG_2_0_REG,
  575. mcast->tbl_mcast_port_msk[2]);
  576. dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_MCAST_CFG_1_0_REG,
  577. mcast->tbl_mcast_port_msk[1]);
  578. dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_MCAST_CFG_0_0_REG,
  579. mcast->tbl_mcast_port_msk[0]);
  580. }
  581. /**
  582. * hns_dsaf_tbl_tcam_ucast_cfg - tbl
  583. * @dsaf_id: dsa fabric id
  584. * @ptbl_tcam_ucast: addr
  585. */
  586. static void hns_dsaf_tbl_tcam_ucast_cfg(
  587. struct dsaf_device *dsaf_dev,
  588. struct dsaf_tbl_tcam_ucast_cfg *tbl_tcam_ucast)
  589. {
  590. u32 ucast_cfg1;
  591. ucast_cfg1 = dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_UCAST_CFG_0_REG);
  592. dsaf_set_bit(ucast_cfg1, DSAF_TBL_UCAST_CFG1_MAC_DISCARD_S,
  593. tbl_tcam_ucast->tbl_ucast_mac_discard);
  594. dsaf_set_bit(ucast_cfg1, DSAF_TBL_UCAST_CFG1_ITEM_VLD_S,
  595. tbl_tcam_ucast->tbl_ucast_item_vld);
  596. dsaf_set_bit(ucast_cfg1, DSAF_TBL_UCAST_CFG1_OLD_EN_S,
  597. tbl_tcam_ucast->tbl_ucast_old_en);
  598. dsaf_set_bit(ucast_cfg1, DSAF_TBL_UCAST_CFG1_DVC_S,
  599. tbl_tcam_ucast->tbl_ucast_dvc);
  600. dsaf_set_field(ucast_cfg1, DSAF_TBL_UCAST_CFG1_OUT_PORT_M,
  601. DSAF_TBL_UCAST_CFG1_OUT_PORT_S,
  602. tbl_tcam_ucast->tbl_ucast_out_port);
  603. dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_UCAST_CFG_0_REG, ucast_cfg1);
  604. }
  605. /**
  606. * hns_dsaf_tbl_line_cfg - tbl
  607. * @dsaf_id: dsa fabric id
  608. * @ptbl_lin: addr
  609. */
  610. static void hns_dsaf_tbl_line_cfg(struct dsaf_device *dsaf_dev,
  611. struct dsaf_tbl_line_cfg *tbl_lin)
  612. {
  613. u32 tbl_line;
  614. tbl_line = dsaf_read_dev(dsaf_dev, DSAF_TBL_LIN_CFG_0_REG);
  615. dsaf_set_bit(tbl_line, DSAF_TBL_LINE_CFG_MAC_DISCARD_S,
  616. tbl_lin->tbl_line_mac_discard);
  617. dsaf_set_bit(tbl_line, DSAF_TBL_LINE_CFG_DVC_S,
  618. tbl_lin->tbl_line_dvc);
  619. dsaf_set_field(tbl_line, DSAF_TBL_LINE_CFG_OUT_PORT_M,
  620. DSAF_TBL_LINE_CFG_OUT_PORT_S,
  621. tbl_lin->tbl_line_out_port);
  622. dsaf_write_dev(dsaf_dev, DSAF_TBL_LIN_CFG_0_REG, tbl_line);
  623. }
  624. /**
  625. * hns_dsaf_tbl_tcam_mcast_pul - tbl
  626. * @dsaf_id: dsa fabric id
  627. */
  628. static void hns_dsaf_tbl_tcam_mcast_pul(struct dsaf_device *dsaf_dev)
  629. {
  630. u32 o_tbl_pul;
  631. o_tbl_pul = dsaf_read_dev(dsaf_dev, DSAF_TBL_PUL_0_REG);
  632. dsaf_set_bit(o_tbl_pul, DSAF_TBL_PUL_MCAST_VLD_S, 1);
  633. dsaf_write_dev(dsaf_dev, DSAF_TBL_PUL_0_REG, o_tbl_pul);
  634. dsaf_set_bit(o_tbl_pul, DSAF_TBL_PUL_MCAST_VLD_S, 0);
  635. dsaf_write_dev(dsaf_dev, DSAF_TBL_PUL_0_REG, o_tbl_pul);
  636. }
  637. /**
  638. * hns_dsaf_tbl_line_pul - tbl
  639. * @dsaf_id: dsa fabric id
  640. */
  641. static void hns_dsaf_tbl_line_pul(struct dsaf_device *dsaf_dev)
  642. {
  643. u32 tbl_pul;
  644. tbl_pul = dsaf_read_dev(dsaf_dev, DSAF_TBL_PUL_0_REG);
  645. dsaf_set_bit(tbl_pul, DSAF_TBL_PUL_LINE_VLD_S, 1);
  646. dsaf_write_dev(dsaf_dev, DSAF_TBL_PUL_0_REG, tbl_pul);
  647. dsaf_set_bit(tbl_pul, DSAF_TBL_PUL_LINE_VLD_S, 0);
  648. dsaf_write_dev(dsaf_dev, DSAF_TBL_PUL_0_REG, tbl_pul);
  649. }
  650. /**
  651. * hns_dsaf_tbl_tcam_data_mcast_pul - tbl
  652. * @dsaf_id: dsa fabric id
  653. */
  654. static void hns_dsaf_tbl_tcam_data_mcast_pul(
  655. struct dsaf_device *dsaf_dev)
  656. {
  657. u32 o_tbl_pul;
  658. o_tbl_pul = dsaf_read_dev(dsaf_dev, DSAF_TBL_PUL_0_REG);
  659. dsaf_set_bit(o_tbl_pul, DSAF_TBL_PUL_TCAM_DATA_VLD_S, 1);
  660. dsaf_set_bit(o_tbl_pul, DSAF_TBL_PUL_MCAST_VLD_S, 1);
  661. dsaf_write_dev(dsaf_dev, DSAF_TBL_PUL_0_REG, o_tbl_pul);
  662. dsaf_set_bit(o_tbl_pul, DSAF_TBL_PUL_TCAM_DATA_VLD_S, 0);
  663. dsaf_set_bit(o_tbl_pul, DSAF_TBL_PUL_MCAST_VLD_S, 0);
  664. dsaf_write_dev(dsaf_dev, DSAF_TBL_PUL_0_REG, o_tbl_pul);
  665. }
  666. /**
  667. * hns_dsaf_tbl_tcam_data_ucast_pul - tbl
  668. * @dsaf_id: dsa fabric id
  669. */
  670. static void hns_dsaf_tbl_tcam_data_ucast_pul(
  671. struct dsaf_device *dsaf_dev)
  672. {
  673. u32 o_tbl_pul;
  674. o_tbl_pul = dsaf_read_dev(dsaf_dev, DSAF_TBL_PUL_0_REG);
  675. dsaf_set_bit(o_tbl_pul, DSAF_TBL_PUL_TCAM_DATA_VLD_S, 1);
  676. dsaf_set_bit(o_tbl_pul, DSAF_TBL_PUL_UCAST_VLD_S, 1);
  677. dsaf_write_dev(dsaf_dev, DSAF_TBL_PUL_0_REG, o_tbl_pul);
  678. dsaf_set_bit(o_tbl_pul, DSAF_TBL_PUL_TCAM_DATA_VLD_S, 0);
  679. dsaf_set_bit(o_tbl_pul, DSAF_TBL_PUL_UCAST_VLD_S, 0);
  680. dsaf_write_dev(dsaf_dev, DSAF_TBL_PUL_0_REG, o_tbl_pul);
  681. }
  682. void hns_dsaf_set_promisc_mode(struct dsaf_device *dsaf_dev, u32 en)
  683. {
  684. if (AE_IS_VER1(dsaf_dev->dsaf_ver) && !HNS_DSAF_IS_DEBUG(dsaf_dev))
  685. dsaf_set_dev_bit(dsaf_dev, DSAF_CFG_0_REG,
  686. DSAF_CFG_MIX_MODE_S, !!en);
  687. }
  688. /**
  689. * hns_dsaf_tbl_stat_en - tbl
  690. * @dsaf_id: dsa fabric id
  691. * @ptbl_stat_en: addr
  692. */
  693. static void hns_dsaf_tbl_stat_en(struct dsaf_device *dsaf_dev)
  694. {
  695. u32 o_tbl_ctrl;
  696. o_tbl_ctrl = dsaf_read_dev(dsaf_dev, DSAF_TBL_DFX_CTRL_0_REG);
  697. dsaf_set_bit(o_tbl_ctrl, DSAF_TBL_DFX_LINE_LKUP_NUM_EN_S, 1);
  698. dsaf_set_bit(o_tbl_ctrl, DSAF_TBL_DFX_UC_LKUP_NUM_EN_S, 1);
  699. dsaf_set_bit(o_tbl_ctrl, DSAF_TBL_DFX_MC_LKUP_NUM_EN_S, 1);
  700. dsaf_set_bit(o_tbl_ctrl, DSAF_TBL_DFX_BC_LKUP_NUM_EN_S, 1);
  701. dsaf_write_dev(dsaf_dev, DSAF_TBL_DFX_CTRL_0_REG, o_tbl_ctrl);
  702. }
  703. /**
  704. * hns_dsaf_rocee_bp_en - rocee back press enable
  705. * @dsaf_id: dsa fabric id
  706. */
  707. static void hns_dsaf_rocee_bp_en(struct dsaf_device *dsaf_dev)
  708. {
  709. if (AE_IS_VER1(dsaf_dev->dsaf_ver))
  710. dsaf_set_dev_bit(dsaf_dev, DSAF_XGE_CTRL_SIG_CFG_0_REG,
  711. DSAF_FC_XGE_TX_PAUSE_S, 1);
  712. }
  713. /* set msk for dsaf exception irq*/
  714. static void hns_dsaf_int_xge_msk_set(struct dsaf_device *dsaf_dev,
  715. u32 chnn_num, u32 mask_set)
  716. {
  717. dsaf_write_dev(dsaf_dev,
  718. DSAF_XGE_INT_MSK_0_REG + 0x4 * chnn_num, mask_set);
  719. }
  720. static void hns_dsaf_int_ppe_msk_set(struct dsaf_device *dsaf_dev,
  721. u32 chnn_num, u32 msk_set)
  722. {
  723. dsaf_write_dev(dsaf_dev,
  724. DSAF_PPE_INT_MSK_0_REG + 0x4 * chnn_num, msk_set);
  725. }
  726. static void hns_dsaf_int_rocee_msk_set(struct dsaf_device *dsaf_dev,
  727. u32 chnn, u32 msk_set)
  728. {
  729. dsaf_write_dev(dsaf_dev,
  730. DSAF_ROCEE_INT_MSK_0_REG + 0x4 * chnn, msk_set);
  731. }
  732. static void
  733. hns_dsaf_int_tbl_msk_set(struct dsaf_device *dsaf_dev, u32 msk_set)
  734. {
  735. dsaf_write_dev(dsaf_dev, DSAF_TBL_INT_MSK_0_REG, msk_set);
  736. }
  737. /* clr dsaf exception irq*/
  738. static void hns_dsaf_int_xge_src_clr(struct dsaf_device *dsaf_dev,
  739. u32 chnn_num, u32 int_src)
  740. {
  741. dsaf_write_dev(dsaf_dev,
  742. DSAF_XGE_INT_SRC_0_REG + 0x4 * chnn_num, int_src);
  743. }
  744. static void hns_dsaf_int_ppe_src_clr(struct dsaf_device *dsaf_dev,
  745. u32 chnn, u32 int_src)
  746. {
  747. dsaf_write_dev(dsaf_dev,
  748. DSAF_PPE_INT_SRC_0_REG + 0x4 * chnn, int_src);
  749. }
  750. static void hns_dsaf_int_rocee_src_clr(struct dsaf_device *dsaf_dev,
  751. u32 chnn, u32 int_src)
  752. {
  753. dsaf_write_dev(dsaf_dev,
  754. DSAF_ROCEE_INT_SRC_0_REG + 0x4 * chnn, int_src);
  755. }
  756. static void hns_dsaf_int_tbl_src_clr(struct dsaf_device *dsaf_dev,
  757. u32 int_src)
  758. {
  759. dsaf_write_dev(dsaf_dev, DSAF_TBL_INT_SRC_0_REG, int_src);
  760. }
  761. /**
  762. * hns_dsaf_single_line_tbl_cfg - INT
  763. * @dsaf_id: dsa fabric id
  764. * @address:
  765. * @ptbl_line:
  766. */
  767. static void hns_dsaf_single_line_tbl_cfg(
  768. struct dsaf_device *dsaf_dev,
  769. u32 address, struct dsaf_tbl_line_cfg *ptbl_line)
  770. {
  771. spin_lock_bh(&dsaf_dev->tcam_lock);
  772. /*Write Addr*/
  773. hns_dsaf_tbl_line_addr_cfg(dsaf_dev, address);
  774. /*Write Line*/
  775. hns_dsaf_tbl_line_cfg(dsaf_dev, ptbl_line);
  776. /*Write Plus*/
  777. hns_dsaf_tbl_line_pul(dsaf_dev);
  778. spin_unlock_bh(&dsaf_dev->tcam_lock);
  779. }
  780. /**
  781. * hns_dsaf_tcam_uc_cfg - INT
  782. * @dsaf_id: dsa fabric id
  783. * @address,
  784. * @ptbl_tcam_data,
  785. */
  786. static void hns_dsaf_tcam_uc_cfg(
  787. struct dsaf_device *dsaf_dev, u32 address,
  788. struct dsaf_tbl_tcam_data *ptbl_tcam_data,
  789. struct dsaf_tbl_tcam_ucast_cfg *ptbl_tcam_ucast)
  790. {
  791. spin_lock_bh(&dsaf_dev->tcam_lock);
  792. /*Write Addr*/
  793. hns_dsaf_tbl_tcam_addr_cfg(dsaf_dev, address);
  794. /*Write Tcam Data*/
  795. hns_dsaf_tbl_tcam_data_cfg(dsaf_dev, ptbl_tcam_data);
  796. /*Write Tcam Ucast*/
  797. hns_dsaf_tbl_tcam_ucast_cfg(dsaf_dev, ptbl_tcam_ucast);
  798. /*Write Plus*/
  799. hns_dsaf_tbl_tcam_data_ucast_pul(dsaf_dev);
  800. spin_unlock_bh(&dsaf_dev->tcam_lock);
  801. }
  802. /**
  803. * hns_dsaf_tcam_mc_cfg - cfg the tcam for mc
  804. * @dsaf_dev: dsa fabric device struct pointer
  805. * @address: tcam index
  806. * @ptbl_tcam_data: tcam data struct pointer
  807. * @ptbl_tcam_mcast: tcam mask struct pointer, it must be null for HNSv1
  808. */
  809. static void hns_dsaf_tcam_mc_cfg(
  810. struct dsaf_device *dsaf_dev, u32 address,
  811. struct dsaf_tbl_tcam_data *ptbl_tcam_data,
  812. struct dsaf_tbl_tcam_data *ptbl_tcam_mask,
  813. struct dsaf_tbl_tcam_mcast_cfg *ptbl_tcam_mcast)
  814. {
  815. spin_lock_bh(&dsaf_dev->tcam_lock);
  816. /*Write Addr*/
  817. hns_dsaf_tbl_tcam_addr_cfg(dsaf_dev, address);
  818. /*Write Tcam Data*/
  819. hns_dsaf_tbl_tcam_data_cfg(dsaf_dev, ptbl_tcam_data);
  820. /*Write Tcam Mcast*/
  821. hns_dsaf_tbl_tcam_mcast_cfg(dsaf_dev, ptbl_tcam_mcast);
  822. /* Write Match Data */
  823. if (ptbl_tcam_mask)
  824. hns_dsaf_tbl_tcam_match_cfg(dsaf_dev, ptbl_tcam_mask);
  825. /* Write Puls */
  826. hns_dsaf_tbl_tcam_data_mcast_pul(dsaf_dev);
  827. spin_unlock_bh(&dsaf_dev->tcam_lock);
  828. }
  829. /**
  830. * hns_dsaf_tcam_uc_cfg_vague - INT
  831. * @dsaf_dev: dsa fabric device struct pointer
  832. * @address,
  833. * @ptbl_tcam_data,
  834. */
  835. static void hns_dsaf_tcam_uc_cfg_vague(struct dsaf_device *dsaf_dev,
  836. u32 address,
  837. struct dsaf_tbl_tcam_data *tcam_data,
  838. struct dsaf_tbl_tcam_data *tcam_mask,
  839. struct dsaf_tbl_tcam_ucast_cfg *tcam_uc)
  840. {
  841. spin_lock_bh(&dsaf_dev->tcam_lock);
  842. hns_dsaf_tbl_tcam_addr_cfg(dsaf_dev, address);
  843. hns_dsaf_tbl_tcam_data_cfg(dsaf_dev, tcam_data);
  844. hns_dsaf_tbl_tcam_ucast_cfg(dsaf_dev, tcam_uc);
  845. hns_dsaf_tbl_tcam_match_cfg(dsaf_dev, tcam_mask);
  846. hns_dsaf_tbl_tcam_data_ucast_pul(dsaf_dev);
  847. /*Restore Match Data*/
  848. tcam_mask->tbl_tcam_data_high = 0xffffffff;
  849. tcam_mask->tbl_tcam_data_low = 0xffffffff;
  850. hns_dsaf_tbl_tcam_match_cfg(dsaf_dev, tcam_mask);
  851. spin_unlock_bh(&dsaf_dev->tcam_lock);
  852. }
  853. /**
  854. * hns_dsaf_tcam_mc_cfg_vague - INT
  855. * @dsaf_dev: dsa fabric device struct pointer
  856. * @address,
  857. * @ptbl_tcam_data,
  858. * @ptbl_tcam_mask
  859. * @ptbl_tcam_mcast
  860. */
  861. static void hns_dsaf_tcam_mc_cfg_vague(struct dsaf_device *dsaf_dev,
  862. u32 address,
  863. struct dsaf_tbl_tcam_data *tcam_data,
  864. struct dsaf_tbl_tcam_data *tcam_mask,
  865. struct dsaf_tbl_tcam_mcast_cfg *tcam_mc)
  866. {
  867. spin_lock_bh(&dsaf_dev->tcam_lock);
  868. hns_dsaf_tbl_tcam_addr_cfg(dsaf_dev, address);
  869. hns_dsaf_tbl_tcam_data_cfg(dsaf_dev, tcam_data);
  870. hns_dsaf_tbl_tcam_mcast_cfg(dsaf_dev, tcam_mc);
  871. hns_dsaf_tbl_tcam_match_cfg(dsaf_dev, tcam_mask);
  872. hns_dsaf_tbl_tcam_data_mcast_pul(dsaf_dev);
  873. /*Restore Match Data*/
  874. tcam_mask->tbl_tcam_data_high = 0xffffffff;
  875. tcam_mask->tbl_tcam_data_low = 0xffffffff;
  876. hns_dsaf_tbl_tcam_match_cfg(dsaf_dev, tcam_mask);
  877. spin_unlock_bh(&dsaf_dev->tcam_lock);
  878. }
  879. /**
  880. * hns_dsaf_tcam_mc_invld - INT
  881. * @dsaf_id: dsa fabric id
  882. * @address
  883. */
  884. static void hns_dsaf_tcam_mc_invld(struct dsaf_device *dsaf_dev, u32 address)
  885. {
  886. spin_lock_bh(&dsaf_dev->tcam_lock);
  887. /*Write Addr*/
  888. hns_dsaf_tbl_tcam_addr_cfg(dsaf_dev, address);
  889. /*write tcam mcast*/
  890. dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_MCAST_CFG_0_0_REG, 0);
  891. dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_MCAST_CFG_1_0_REG, 0);
  892. dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_MCAST_CFG_2_0_REG, 0);
  893. dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_MCAST_CFG_3_0_REG, 0);
  894. dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_MCAST_CFG_4_0_REG, 0);
  895. /*Write Plus*/
  896. hns_dsaf_tbl_tcam_mcast_pul(dsaf_dev);
  897. spin_unlock_bh(&dsaf_dev->tcam_lock);
  898. }
  899. static void
  900. hns_dsaf_tcam_addr_get(struct dsaf_drv_tbl_tcam_key *mac_key, u8 *addr)
  901. {
  902. addr[0] = mac_key->high.bits.mac_0;
  903. addr[1] = mac_key->high.bits.mac_1;
  904. addr[2] = mac_key->high.bits.mac_2;
  905. addr[3] = mac_key->high.bits.mac_3;
  906. addr[4] = mac_key->low.bits.mac_4;
  907. addr[5] = mac_key->low.bits.mac_5;
  908. }
  909. /**
  910. * hns_dsaf_tcam_uc_get - INT
  911. * @dsaf_id: dsa fabric id
  912. * @address
  913. * @ptbl_tcam_data
  914. * @ptbl_tcam_ucast
  915. */
  916. static void hns_dsaf_tcam_uc_get(
  917. struct dsaf_device *dsaf_dev, u32 address,
  918. struct dsaf_tbl_tcam_data *ptbl_tcam_data,
  919. struct dsaf_tbl_tcam_ucast_cfg *ptbl_tcam_ucast)
  920. {
  921. u32 tcam_read_data0;
  922. u32 tcam_read_data4;
  923. spin_lock_bh(&dsaf_dev->tcam_lock);
  924. /*Write Addr*/
  925. hns_dsaf_tbl_tcam_addr_cfg(dsaf_dev, address);
  926. /*read tcam item puls*/
  927. hns_dsaf_tbl_tcam_load_pul(dsaf_dev);
  928. /*read tcam data*/
  929. ptbl_tcam_data->tbl_tcam_data_high
  930. = dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_RDATA_HIGH_0_REG);
  931. ptbl_tcam_data->tbl_tcam_data_low
  932. = dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_RDATA_LOW_0_REG);
  933. /*read tcam mcast*/
  934. tcam_read_data0 = dsaf_read_dev(dsaf_dev,
  935. DSAF_TBL_TCAM_RAM_RDATA0_0_REG);
  936. tcam_read_data4 = dsaf_read_dev(dsaf_dev,
  937. DSAF_TBL_TCAM_RAM_RDATA4_0_REG);
  938. ptbl_tcam_ucast->tbl_ucast_item_vld
  939. = dsaf_get_bit(tcam_read_data4,
  940. DSAF_TBL_MCAST_CFG4_ITEM_VLD_S);
  941. ptbl_tcam_ucast->tbl_ucast_old_en
  942. = dsaf_get_bit(tcam_read_data4, DSAF_TBL_MCAST_CFG4_OLD_EN_S);
  943. ptbl_tcam_ucast->tbl_ucast_mac_discard
  944. = dsaf_get_bit(tcam_read_data0,
  945. DSAF_TBL_UCAST_CFG1_MAC_DISCARD_S);
  946. ptbl_tcam_ucast->tbl_ucast_out_port
  947. = dsaf_get_field(tcam_read_data0,
  948. DSAF_TBL_UCAST_CFG1_OUT_PORT_M,
  949. DSAF_TBL_UCAST_CFG1_OUT_PORT_S);
  950. ptbl_tcam_ucast->tbl_ucast_dvc
  951. = dsaf_get_bit(tcam_read_data0, DSAF_TBL_UCAST_CFG1_DVC_S);
  952. spin_unlock_bh(&dsaf_dev->tcam_lock);
  953. }
  954. /**
  955. * hns_dsaf_tcam_mc_get - INT
  956. * @dsaf_id: dsa fabric id
  957. * @address
  958. * @ptbl_tcam_data
  959. * @ptbl_tcam_ucast
  960. */
  961. static void hns_dsaf_tcam_mc_get(
  962. struct dsaf_device *dsaf_dev, u32 address,
  963. struct dsaf_tbl_tcam_data *ptbl_tcam_data,
  964. struct dsaf_tbl_tcam_mcast_cfg *ptbl_tcam_mcast)
  965. {
  966. u32 data_tmp;
  967. spin_lock_bh(&dsaf_dev->tcam_lock);
  968. /*Write Addr*/
  969. hns_dsaf_tbl_tcam_addr_cfg(dsaf_dev, address);
  970. /*read tcam item puls*/
  971. hns_dsaf_tbl_tcam_load_pul(dsaf_dev);
  972. /*read tcam data*/
  973. ptbl_tcam_data->tbl_tcam_data_high =
  974. dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_RDATA_HIGH_0_REG);
  975. ptbl_tcam_data->tbl_tcam_data_low =
  976. dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_RDATA_LOW_0_REG);
  977. /*read tcam mcast*/
  978. ptbl_tcam_mcast->tbl_mcast_port_msk[0] =
  979. dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_RAM_RDATA0_0_REG);
  980. ptbl_tcam_mcast->tbl_mcast_port_msk[1] =
  981. dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_RAM_RDATA1_0_REG);
  982. ptbl_tcam_mcast->tbl_mcast_port_msk[2] =
  983. dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_RAM_RDATA2_0_REG);
  984. ptbl_tcam_mcast->tbl_mcast_port_msk[3] =
  985. dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_RAM_RDATA3_0_REG);
  986. data_tmp = dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_RAM_RDATA4_0_REG);
  987. ptbl_tcam_mcast->tbl_mcast_item_vld =
  988. dsaf_get_bit(data_tmp, DSAF_TBL_MCAST_CFG4_ITEM_VLD_S);
  989. ptbl_tcam_mcast->tbl_mcast_old_en =
  990. dsaf_get_bit(data_tmp, DSAF_TBL_MCAST_CFG4_OLD_EN_S);
  991. ptbl_tcam_mcast->tbl_mcast_port_msk[4] =
  992. dsaf_get_field(data_tmp, DSAF_TBL_MCAST_CFG4_VM128_112_M,
  993. DSAF_TBL_MCAST_CFG4_VM128_112_S);
  994. spin_unlock_bh(&dsaf_dev->tcam_lock);
  995. }
  996. /**
  997. * hns_dsaf_tbl_line_init - INT
  998. * @dsaf_id: dsa fabric id
  999. */
  1000. static void hns_dsaf_tbl_line_init(struct dsaf_device *dsaf_dev)
  1001. {
  1002. u32 i;
  1003. /* defaultly set all lineal mac table entry resulting discard */
  1004. struct dsaf_tbl_line_cfg tbl_line[] = {{1, 0, 0} };
  1005. for (i = 0; i < DSAF_LINE_SUM; i++)
  1006. hns_dsaf_single_line_tbl_cfg(dsaf_dev, i, tbl_line);
  1007. }
  1008. /**
  1009. * hns_dsaf_tbl_tcam_init - INT
  1010. * @dsaf_id: dsa fabric id
  1011. */
  1012. static void hns_dsaf_tbl_tcam_init(struct dsaf_device *dsaf_dev)
  1013. {
  1014. u32 i;
  1015. struct dsaf_tbl_tcam_data tcam_data[] = {{0, 0} };
  1016. struct dsaf_tbl_tcam_ucast_cfg tcam_ucast[] = {{0, 0, 0, 0, 0} };
  1017. /*tcam tbl*/
  1018. for (i = 0; i < DSAF_TCAM_SUM; i++)
  1019. hns_dsaf_tcam_uc_cfg(dsaf_dev, i, tcam_data, tcam_ucast);
  1020. }
  1021. /**
  1022. * hns_dsaf_pfc_en_cfg - dsaf pfc pause cfg
  1023. * @mac_cb: mac contrl block
  1024. */
  1025. static void hns_dsaf_pfc_en_cfg(struct dsaf_device *dsaf_dev,
  1026. int mac_id, int tc_en)
  1027. {
  1028. dsaf_write_dev(dsaf_dev, DSAF_PFC_EN_0_REG + mac_id * 4, tc_en);
  1029. }
  1030. static void hns_dsaf_set_pfc_pause(struct dsaf_device *dsaf_dev,
  1031. int mac_id, int tx_en, int rx_en)
  1032. {
  1033. if (AE_IS_VER1(dsaf_dev->dsaf_ver)) {
  1034. if (!tx_en || !rx_en)
  1035. dev_err(dsaf_dev->dev, "dsaf v1 can not close pfc!\n");
  1036. return;
  1037. }
  1038. dsaf_set_dev_bit(dsaf_dev, DSAF_PAUSE_CFG_REG + mac_id * 4,
  1039. DSAF_PFC_PAUSE_RX_EN_B, !!rx_en);
  1040. dsaf_set_dev_bit(dsaf_dev, DSAF_PAUSE_CFG_REG + mac_id * 4,
  1041. DSAF_PFC_PAUSE_TX_EN_B, !!tx_en);
  1042. }
  1043. int hns_dsaf_set_rx_mac_pause_en(struct dsaf_device *dsaf_dev, int mac_id,
  1044. u32 en)
  1045. {
  1046. if (AE_IS_VER1(dsaf_dev->dsaf_ver)) {
  1047. if (!en) {
  1048. dev_err(dsaf_dev->dev, "dsafv1 can't close rx_pause!\n");
  1049. return -EINVAL;
  1050. }
  1051. }
  1052. dsaf_set_dev_bit(dsaf_dev, DSAF_PAUSE_CFG_REG + mac_id * 4,
  1053. DSAF_MAC_PAUSE_RX_EN_B, !!en);
  1054. return 0;
  1055. }
  1056. void hns_dsaf_get_rx_mac_pause_en(struct dsaf_device *dsaf_dev, int mac_id,
  1057. u32 *en)
  1058. {
  1059. if (AE_IS_VER1(dsaf_dev->dsaf_ver))
  1060. *en = 1;
  1061. else
  1062. *en = dsaf_get_dev_bit(dsaf_dev,
  1063. DSAF_PAUSE_CFG_REG + mac_id * 4,
  1064. DSAF_MAC_PAUSE_RX_EN_B);
  1065. }
  1066. /**
  1067. * hns_dsaf_tbl_tcam_init - INT
  1068. * @dsaf_id: dsa fabric id
  1069. * @dsaf_mode
  1070. */
  1071. static void hns_dsaf_comm_init(struct dsaf_device *dsaf_dev)
  1072. {
  1073. u32 i;
  1074. u32 o_dsaf_cfg;
  1075. bool is_ver1 = AE_IS_VER1(dsaf_dev->dsaf_ver);
  1076. o_dsaf_cfg = dsaf_read_dev(dsaf_dev, DSAF_CFG_0_REG);
  1077. dsaf_set_bit(o_dsaf_cfg, DSAF_CFG_EN_S, dsaf_dev->dsaf_en);
  1078. dsaf_set_bit(o_dsaf_cfg, DSAF_CFG_TC_MODE_S, dsaf_dev->dsaf_tc_mode);
  1079. dsaf_set_bit(o_dsaf_cfg, DSAF_CFG_CRC_EN_S, 0);
  1080. dsaf_set_bit(o_dsaf_cfg, DSAF_CFG_MIX_MODE_S, 0);
  1081. dsaf_set_bit(o_dsaf_cfg, DSAF_CFG_LOCA_ADDR_EN_S, 0);
  1082. dsaf_write_dev(dsaf_dev, DSAF_CFG_0_REG, o_dsaf_cfg);
  1083. hns_dsaf_reg_cnt_clr_ce(dsaf_dev, 1);
  1084. hns_dsaf_stp_port_type_cfg(dsaf_dev, DSAF_STP_PORT_TYPE_FORWARD);
  1085. /* set 22 queue per tx ppe engine, only used in switch mode */
  1086. hns_dsaf_ppe_qid_cfg(dsaf_dev, DSAF_DEFAUTL_QUEUE_NUM_PER_PPE);
  1087. /* set promisc def queue id */
  1088. hns_dsaf_mix_def_qid_cfg(dsaf_dev);
  1089. /* set inner loopback queue id */
  1090. hns_dsaf_inner_qid_cfg(dsaf_dev);
  1091. /* in non switch mode, set all port to access mode */
  1092. hns_dsaf_sw_port_type_cfg(dsaf_dev, DSAF_SW_PORT_TYPE_NON_VLAN);
  1093. /*set dsaf pfc to 0 for parseing rx pause*/
  1094. for (i = 0; i < DSAF_COMM_CHN; i++) {
  1095. hns_dsaf_pfc_en_cfg(dsaf_dev, i, 0);
  1096. hns_dsaf_set_pfc_pause(dsaf_dev, i, is_ver1, is_ver1);
  1097. }
  1098. /*msk and clr exception irqs */
  1099. for (i = 0; i < DSAF_COMM_CHN; i++) {
  1100. hns_dsaf_int_xge_src_clr(dsaf_dev, i, 0xfffffffful);
  1101. hns_dsaf_int_ppe_src_clr(dsaf_dev, i, 0xfffffffful);
  1102. hns_dsaf_int_rocee_src_clr(dsaf_dev, i, 0xfffffffful);
  1103. hns_dsaf_int_xge_msk_set(dsaf_dev, i, 0xfffffffful);
  1104. hns_dsaf_int_ppe_msk_set(dsaf_dev, i, 0xfffffffful);
  1105. hns_dsaf_int_rocee_msk_set(dsaf_dev, i, 0xfffffffful);
  1106. }
  1107. hns_dsaf_int_tbl_src_clr(dsaf_dev, 0xfffffffful);
  1108. hns_dsaf_int_tbl_msk_set(dsaf_dev, 0xfffffffful);
  1109. }
  1110. /**
  1111. * hns_dsaf_inode_init - INT
  1112. * @dsaf_id: dsa fabric id
  1113. */
  1114. static void hns_dsaf_inode_init(struct dsaf_device *dsaf_dev)
  1115. {
  1116. u32 reg;
  1117. u32 tc_cfg;
  1118. u32 i;
  1119. if (dsaf_dev->dsaf_tc_mode == HRD_DSAF_4TC_MODE)
  1120. tc_cfg = HNS_DSAF_I4TC_CFG;
  1121. else
  1122. tc_cfg = HNS_DSAF_I8TC_CFG;
  1123. if (AE_IS_VER1(dsaf_dev->dsaf_ver)) {
  1124. for (i = 0; i < DSAF_INODE_NUM; i++) {
  1125. reg = DSAF_INODE_IN_PORT_NUM_0_REG + 0x80 * i;
  1126. dsaf_set_dev_field(dsaf_dev, reg,
  1127. DSAF_INODE_IN_PORT_NUM_M,
  1128. DSAF_INODE_IN_PORT_NUM_S,
  1129. i % DSAF_XGE_NUM);
  1130. }
  1131. } else {
  1132. for (i = 0; i < DSAF_PORT_TYPE_NUM; i++) {
  1133. reg = DSAF_INODE_IN_PORT_NUM_0_REG + 0x80 * i;
  1134. dsaf_set_dev_field(dsaf_dev, reg,
  1135. DSAF_INODE_IN_PORT_NUM_M,
  1136. DSAF_INODE_IN_PORT_NUM_S, 0);
  1137. dsaf_set_dev_field(dsaf_dev, reg,
  1138. DSAFV2_INODE_IN_PORT1_NUM_M,
  1139. DSAFV2_INODE_IN_PORT1_NUM_S, 1);
  1140. dsaf_set_dev_field(dsaf_dev, reg,
  1141. DSAFV2_INODE_IN_PORT2_NUM_M,
  1142. DSAFV2_INODE_IN_PORT2_NUM_S, 2);
  1143. dsaf_set_dev_field(dsaf_dev, reg,
  1144. DSAFV2_INODE_IN_PORT3_NUM_M,
  1145. DSAFV2_INODE_IN_PORT3_NUM_S, 3);
  1146. dsaf_set_dev_field(dsaf_dev, reg,
  1147. DSAFV2_INODE_IN_PORT4_NUM_M,
  1148. DSAFV2_INODE_IN_PORT4_NUM_S, 4);
  1149. dsaf_set_dev_field(dsaf_dev, reg,
  1150. DSAFV2_INODE_IN_PORT5_NUM_M,
  1151. DSAFV2_INODE_IN_PORT5_NUM_S, 5);
  1152. }
  1153. }
  1154. for (i = 0; i < DSAF_INODE_NUM; i++) {
  1155. reg = DSAF_INODE_PRI_TC_CFG_0_REG + 0x80 * i;
  1156. dsaf_write_dev(dsaf_dev, reg, tc_cfg);
  1157. }
  1158. }
  1159. /**
  1160. * hns_dsaf_sbm_init - INT
  1161. * @dsaf_id: dsa fabric id
  1162. */
  1163. static int hns_dsaf_sbm_init(struct dsaf_device *dsaf_dev)
  1164. {
  1165. u32 flag;
  1166. u32 finish_msk;
  1167. u32 cnt = 0;
  1168. int ret;
  1169. if (AE_IS_VER1(dsaf_dev->dsaf_ver)) {
  1170. hns_dsaf_sbm_bp_wl_cfg(dsaf_dev);
  1171. finish_msk = DSAF_SRAM_INIT_OVER_M;
  1172. } else {
  1173. hns_dsafv2_sbm_bp_wl_cfg(dsaf_dev);
  1174. finish_msk = DSAFV2_SRAM_INIT_OVER_M;
  1175. }
  1176. /* enable sbm chanel, disable sbm chanel shcut function*/
  1177. hns_dsaf_sbm_cfg(dsaf_dev);
  1178. /* enable sbm mib */
  1179. ret = hns_dsaf_sbm_cfg_mib_en(dsaf_dev);
  1180. if (ret) {
  1181. dev_err(dsaf_dev->dev,
  1182. "hns_dsaf_sbm_cfg_mib_en fail,%s, ret=%d\n",
  1183. dsaf_dev->ae_dev.name, ret);
  1184. return ret;
  1185. }
  1186. /* enable sbm initial link sram */
  1187. hns_dsaf_sbm_link_sram_init_en(dsaf_dev);
  1188. do {
  1189. usleep_range(200, 210);/*udelay(200);*/
  1190. flag = dsaf_get_dev_field(dsaf_dev, DSAF_SRAM_INIT_OVER_0_REG,
  1191. finish_msk, DSAF_SRAM_INIT_OVER_S);
  1192. cnt++;
  1193. } while (flag != (finish_msk >> DSAF_SRAM_INIT_OVER_S) &&
  1194. cnt < DSAF_CFG_READ_CNT);
  1195. if (flag != (finish_msk >> DSAF_SRAM_INIT_OVER_S)) {
  1196. dev_err(dsaf_dev->dev,
  1197. "hns_dsaf_sbm_init fail %s, flag=%d, cnt=%d\n",
  1198. dsaf_dev->ae_dev.name, flag, cnt);
  1199. return -ENODEV;
  1200. }
  1201. hns_dsaf_rocee_bp_en(dsaf_dev);
  1202. return 0;
  1203. }
  1204. /**
  1205. * hns_dsaf_tbl_init - INT
  1206. * @dsaf_id: dsa fabric id
  1207. */
  1208. static void hns_dsaf_tbl_init(struct dsaf_device *dsaf_dev)
  1209. {
  1210. hns_dsaf_tbl_stat_en(dsaf_dev);
  1211. hns_dsaf_tbl_tcam_init(dsaf_dev);
  1212. hns_dsaf_tbl_line_init(dsaf_dev);
  1213. }
  1214. /**
  1215. * hns_dsaf_voq_init - INT
  1216. * @dsaf_id: dsa fabric id
  1217. */
  1218. static void hns_dsaf_voq_init(struct dsaf_device *dsaf_dev)
  1219. {
  1220. hns_dsaf_voq_bp_all_thrd_cfg(dsaf_dev);
  1221. }
  1222. /**
  1223. * hns_dsaf_init_hw - init dsa fabric hardware
  1224. * @dsaf_dev: dsa fabric device struct pointer
  1225. */
  1226. static int hns_dsaf_init_hw(struct dsaf_device *dsaf_dev)
  1227. {
  1228. int ret;
  1229. dev_dbg(dsaf_dev->dev,
  1230. "hns_dsaf_init_hw begin %s !\n", dsaf_dev->ae_dev.name);
  1231. dsaf_dev->misc_op->dsaf_reset(dsaf_dev, 0);
  1232. mdelay(10);
  1233. dsaf_dev->misc_op->dsaf_reset(dsaf_dev, 1);
  1234. hns_dsaf_comm_init(dsaf_dev);
  1235. /*init XBAR_INODE*/
  1236. hns_dsaf_inode_init(dsaf_dev);
  1237. /*init SBM*/
  1238. ret = hns_dsaf_sbm_init(dsaf_dev);
  1239. if (ret)
  1240. return ret;
  1241. /*init TBL*/
  1242. hns_dsaf_tbl_init(dsaf_dev);
  1243. /*init VOQ*/
  1244. hns_dsaf_voq_init(dsaf_dev);
  1245. return 0;
  1246. }
  1247. /**
  1248. * hns_dsaf_remove_hw - uninit dsa fabric hardware
  1249. * @dsaf_dev: dsa fabric device struct pointer
  1250. */
  1251. static void hns_dsaf_remove_hw(struct dsaf_device *dsaf_dev)
  1252. {
  1253. /*reset*/
  1254. dsaf_dev->misc_op->dsaf_reset(dsaf_dev, 0);
  1255. }
  1256. /**
  1257. * hns_dsaf_init - init dsa fabric
  1258. * @dsaf_dev: dsa fabric device struct pointer
  1259. * retuen 0 - success , negative --fail
  1260. */
  1261. static int hns_dsaf_init(struct dsaf_device *dsaf_dev)
  1262. {
  1263. struct dsaf_drv_priv *priv =
  1264. (struct dsaf_drv_priv *)hns_dsaf_dev_priv(dsaf_dev);
  1265. u32 i;
  1266. int ret;
  1267. if (HNS_DSAF_IS_DEBUG(dsaf_dev))
  1268. return 0;
  1269. if (AE_IS_VER1(dsaf_dev->dsaf_ver))
  1270. dsaf_dev->tcam_max_num = DSAF_TCAM_SUM;
  1271. else
  1272. dsaf_dev->tcam_max_num =
  1273. DSAF_TCAM_SUM - DSAFV2_MAC_FUZZY_TCAM_NUM;
  1274. spin_lock_init(&dsaf_dev->tcam_lock);
  1275. ret = hns_dsaf_init_hw(dsaf_dev);
  1276. if (ret)
  1277. return ret;
  1278. /* malloc mem for tcam mac key(vlan+mac) */
  1279. priv->soft_mac_tbl = vzalloc(array_size(DSAF_TCAM_SUM,
  1280. sizeof(*priv->soft_mac_tbl)));
  1281. if (!priv->soft_mac_tbl) {
  1282. ret = -ENOMEM;
  1283. goto remove_hw;
  1284. }
  1285. /*all entry invall */
  1286. for (i = 0; i < DSAF_TCAM_SUM; i++)
  1287. (priv->soft_mac_tbl + i)->index = DSAF_INVALID_ENTRY_IDX;
  1288. return 0;
  1289. remove_hw:
  1290. hns_dsaf_remove_hw(dsaf_dev);
  1291. return ret;
  1292. }
  1293. /**
  1294. * hns_dsaf_free - free dsa fabric
  1295. * @dsaf_dev: dsa fabric device struct pointer
  1296. */
  1297. static void hns_dsaf_free(struct dsaf_device *dsaf_dev)
  1298. {
  1299. struct dsaf_drv_priv *priv =
  1300. (struct dsaf_drv_priv *)hns_dsaf_dev_priv(dsaf_dev);
  1301. hns_dsaf_remove_hw(dsaf_dev);
  1302. /* free all mac mem */
  1303. vfree(priv->soft_mac_tbl);
  1304. priv->soft_mac_tbl = NULL;
  1305. }
  1306. /**
  1307. * hns_dsaf_find_soft_mac_entry - find dsa fabric soft entry
  1308. * @dsaf_dev: dsa fabric device struct pointer
  1309. * @mac_key: mac entry struct pointer
  1310. */
  1311. static u16 hns_dsaf_find_soft_mac_entry(
  1312. struct dsaf_device *dsaf_dev,
  1313. struct dsaf_drv_tbl_tcam_key *mac_key)
  1314. {
  1315. struct dsaf_drv_priv *priv =
  1316. (struct dsaf_drv_priv *)hns_dsaf_dev_priv(dsaf_dev);
  1317. struct dsaf_drv_soft_mac_tbl *soft_mac_entry;
  1318. u32 i;
  1319. soft_mac_entry = priv->soft_mac_tbl;
  1320. for (i = 0; i < dsaf_dev->tcam_max_num; i++) {
  1321. /* invall tab entry */
  1322. if ((soft_mac_entry->index != DSAF_INVALID_ENTRY_IDX) &&
  1323. (soft_mac_entry->tcam_key.high.val == mac_key->high.val) &&
  1324. (soft_mac_entry->tcam_key.low.val == mac_key->low.val))
  1325. /* return find result --soft index */
  1326. return soft_mac_entry->index;
  1327. soft_mac_entry++;
  1328. }
  1329. return DSAF_INVALID_ENTRY_IDX;
  1330. }
  1331. /**
  1332. * hns_dsaf_find_empty_mac_entry - search dsa fabric soft empty-entry
  1333. * @dsaf_dev: dsa fabric device struct pointer
  1334. */
  1335. static u16 hns_dsaf_find_empty_mac_entry(struct dsaf_device *dsaf_dev)
  1336. {
  1337. struct dsaf_drv_priv *priv =
  1338. (struct dsaf_drv_priv *)hns_dsaf_dev_priv(dsaf_dev);
  1339. struct dsaf_drv_soft_mac_tbl *soft_mac_entry;
  1340. u32 i;
  1341. soft_mac_entry = priv->soft_mac_tbl;
  1342. for (i = 0; i < dsaf_dev->tcam_max_num; i++) {
  1343. /* inv all entry */
  1344. if (soft_mac_entry->index == DSAF_INVALID_ENTRY_IDX)
  1345. /* return find result --soft index */
  1346. return i;
  1347. soft_mac_entry++;
  1348. }
  1349. return DSAF_INVALID_ENTRY_IDX;
  1350. }
  1351. /**
  1352. * hns_dsaf_find_empty_mac_entry_reverse
  1353. * search dsa fabric soft empty-entry from the end
  1354. * @dsaf_dev: dsa fabric device struct pointer
  1355. */
  1356. static u16 hns_dsaf_find_empty_mac_entry_reverse(struct dsaf_device *dsaf_dev)
  1357. {
  1358. struct dsaf_drv_priv *priv = hns_dsaf_dev_priv(dsaf_dev);
  1359. struct dsaf_drv_soft_mac_tbl *soft_mac_entry;
  1360. int i;
  1361. soft_mac_entry = priv->soft_mac_tbl + (DSAF_TCAM_SUM - 1);
  1362. for (i = (DSAF_TCAM_SUM - 1); i > 0; i--) {
  1363. /* search all entry from end to start.*/
  1364. if (soft_mac_entry->index == DSAF_INVALID_ENTRY_IDX)
  1365. return i;
  1366. soft_mac_entry--;
  1367. }
  1368. return DSAF_INVALID_ENTRY_IDX;
  1369. }
  1370. /**
  1371. * hns_dsaf_set_mac_key - set mac key
  1372. * @dsaf_dev: dsa fabric device struct pointer
  1373. * @mac_key: tcam key pointer
  1374. * @vlan_id: vlan id
  1375. * @in_port_num: input port num
  1376. * @addr: mac addr
  1377. */
  1378. static void hns_dsaf_set_mac_key(
  1379. struct dsaf_device *dsaf_dev,
  1380. struct dsaf_drv_tbl_tcam_key *mac_key, u16 vlan_id, u8 in_port_num,
  1381. u8 *addr)
  1382. {
  1383. u8 port;
  1384. if (dsaf_dev->dsaf_mode <= DSAF_MODE_ENABLE)
  1385. /*DSAF mode : in port id fixed 0*/
  1386. port = 0;
  1387. else
  1388. /*non-dsaf mode*/
  1389. port = in_port_num;
  1390. mac_key->high.bits.mac_0 = addr[0];
  1391. mac_key->high.bits.mac_1 = addr[1];
  1392. mac_key->high.bits.mac_2 = addr[2];
  1393. mac_key->high.bits.mac_3 = addr[3];
  1394. mac_key->low.bits.mac_4 = addr[4];
  1395. mac_key->low.bits.mac_5 = addr[5];
  1396. mac_key->low.bits.port_vlan = 0;
  1397. dsaf_set_field(mac_key->low.bits.port_vlan, DSAF_TBL_TCAM_KEY_VLAN_M,
  1398. DSAF_TBL_TCAM_KEY_VLAN_S, vlan_id);
  1399. dsaf_set_field(mac_key->low.bits.port_vlan, DSAF_TBL_TCAM_KEY_PORT_M,
  1400. DSAF_TBL_TCAM_KEY_PORT_S, port);
  1401. mac_key->low.bits.port_vlan = le16_to_cpu(mac_key->low.bits.port_vlan);
  1402. }
  1403. /**
  1404. * hns_dsaf_set_mac_uc_entry - set mac uc-entry
  1405. * @dsaf_dev: dsa fabric device struct pointer
  1406. * @mac_entry: uc-mac entry
  1407. */
  1408. int hns_dsaf_set_mac_uc_entry(
  1409. struct dsaf_device *dsaf_dev,
  1410. struct dsaf_drv_mac_single_dest_entry *mac_entry)
  1411. {
  1412. u16 entry_index = DSAF_INVALID_ENTRY_IDX;
  1413. struct dsaf_drv_tbl_tcam_key mac_key;
  1414. struct dsaf_tbl_tcam_ucast_cfg mac_data;
  1415. struct dsaf_drv_priv *priv =
  1416. (struct dsaf_drv_priv *)hns_dsaf_dev_priv(dsaf_dev);
  1417. struct dsaf_drv_soft_mac_tbl *soft_mac_entry = priv->soft_mac_tbl;
  1418. struct dsaf_tbl_tcam_data tcam_data;
  1419. /* mac addr check */
  1420. if (MAC_IS_ALL_ZEROS(mac_entry->addr) ||
  1421. MAC_IS_BROADCAST(mac_entry->addr) ||
  1422. MAC_IS_MULTICAST(mac_entry->addr)) {
  1423. dev_err(dsaf_dev->dev, "set_uc %s Mac %pM err!\n",
  1424. dsaf_dev->ae_dev.name, mac_entry->addr);
  1425. return -EINVAL;
  1426. }
  1427. /* config key */
  1428. hns_dsaf_set_mac_key(dsaf_dev, &mac_key, mac_entry->in_vlan_id,
  1429. mac_entry->in_port_num, mac_entry->addr);
  1430. /* entry ie exist? */
  1431. entry_index = hns_dsaf_find_soft_mac_entry(dsaf_dev, &mac_key);
  1432. if (entry_index == DSAF_INVALID_ENTRY_IDX) {
  1433. /*if has not inv entry,find a empty entry */
  1434. entry_index = hns_dsaf_find_empty_mac_entry(dsaf_dev);
  1435. if (entry_index == DSAF_INVALID_ENTRY_IDX) {
  1436. /* has not empty,return error */
  1437. dev_err(dsaf_dev->dev,
  1438. "set_uc_entry failed, %s Mac key(%#x:%#x)\n",
  1439. dsaf_dev->ae_dev.name,
  1440. mac_key.high.val, mac_key.low.val);
  1441. return -EINVAL;
  1442. }
  1443. }
  1444. dev_dbg(dsaf_dev->dev,
  1445. "set_uc_entry, %s Mac key(%#x:%#x) entry_index%d\n",
  1446. dsaf_dev->ae_dev.name, mac_key.high.val,
  1447. mac_key.low.val, entry_index);
  1448. /* config hardware entry */
  1449. mac_data.tbl_ucast_item_vld = 1;
  1450. mac_data.tbl_ucast_mac_discard = 0;
  1451. mac_data.tbl_ucast_old_en = 0;
  1452. /* default config dvc to 0 */
  1453. mac_data.tbl_ucast_dvc = 0;
  1454. mac_data.tbl_ucast_out_port = mac_entry->port_num;
  1455. tcam_data.tbl_tcam_data_high = cpu_to_le32(mac_key.high.val);
  1456. tcam_data.tbl_tcam_data_low = cpu_to_le32(mac_key.low.val);
  1457. hns_dsaf_tcam_uc_cfg(dsaf_dev, entry_index, &tcam_data, &mac_data);
  1458. /* config software entry */
  1459. soft_mac_entry += entry_index;
  1460. soft_mac_entry->index = entry_index;
  1461. soft_mac_entry->tcam_key.high.val = mac_key.high.val;
  1462. soft_mac_entry->tcam_key.low.val = mac_key.low.val;
  1463. return 0;
  1464. }
  1465. int hns_dsaf_rm_mac_addr(
  1466. struct dsaf_device *dsaf_dev,
  1467. struct dsaf_drv_mac_single_dest_entry *mac_entry)
  1468. {
  1469. u16 entry_index = DSAF_INVALID_ENTRY_IDX;
  1470. struct dsaf_tbl_tcam_ucast_cfg mac_data;
  1471. struct dsaf_drv_tbl_tcam_key mac_key;
  1472. /* mac addr check */
  1473. if (!is_valid_ether_addr(mac_entry->addr)) {
  1474. dev_err(dsaf_dev->dev, "rm_uc_addr %s Mac %pM err!\n",
  1475. dsaf_dev->ae_dev.name, mac_entry->addr);
  1476. return -EINVAL;
  1477. }
  1478. /* config key */
  1479. hns_dsaf_set_mac_key(dsaf_dev, &mac_key, mac_entry->in_vlan_id,
  1480. mac_entry->in_port_num, mac_entry->addr);
  1481. entry_index = hns_dsaf_find_soft_mac_entry(dsaf_dev, &mac_key);
  1482. if (entry_index == DSAF_INVALID_ENTRY_IDX) {
  1483. /* can not find the tcam entry, return 0 */
  1484. dev_info(dsaf_dev->dev,
  1485. "rm_uc_addr no tcam, %s Mac key(%#x:%#x)\n",
  1486. dsaf_dev->ae_dev.name,
  1487. mac_key.high.val, mac_key.low.val);
  1488. return 0;
  1489. }
  1490. dev_dbg(dsaf_dev->dev,
  1491. "rm_uc_addr, %s Mac key(%#x:%#x) entry_index%d\n",
  1492. dsaf_dev->ae_dev.name, mac_key.high.val,
  1493. mac_key.low.val, entry_index);
  1494. hns_dsaf_tcam_uc_get(
  1495. dsaf_dev, entry_index,
  1496. (struct dsaf_tbl_tcam_data *)&mac_key,
  1497. &mac_data);
  1498. /* unicast entry not used locally should not clear */
  1499. if (mac_entry->port_num != mac_data.tbl_ucast_out_port)
  1500. return -EFAULT;
  1501. return hns_dsaf_del_mac_entry(dsaf_dev,
  1502. mac_entry->in_vlan_id,
  1503. mac_entry->in_port_num,
  1504. mac_entry->addr);
  1505. }
  1506. static void hns_dsaf_setup_mc_mask(struct dsaf_device *dsaf_dev,
  1507. u8 port_num, u8 *mask, u8 *addr)
  1508. {
  1509. if (MAC_IS_BROADCAST(addr))
  1510. memset(mask, 0xff, ETH_ALEN);
  1511. else
  1512. memcpy(mask, dsaf_dev->mac_cb[port_num]->mc_mask, ETH_ALEN);
  1513. }
  1514. static void hns_dsaf_mc_mask_bit_clear(char *dst, const char *src)
  1515. {
  1516. u16 *a = (u16 *)dst;
  1517. const u16 *b = (const u16 *)src;
  1518. a[0] &= b[0];
  1519. a[1] &= b[1];
  1520. a[2] &= b[2];
  1521. }
  1522. /**
  1523. * hns_dsaf_add_mac_mc_port - add mac mc-port
  1524. * @dsaf_dev: dsa fabric device struct pointer
  1525. * @mac_entry: mc-mac entry
  1526. */
  1527. int hns_dsaf_add_mac_mc_port(struct dsaf_device *dsaf_dev,
  1528. struct dsaf_drv_mac_single_dest_entry *mac_entry)
  1529. {
  1530. u16 entry_index = DSAF_INVALID_ENTRY_IDX;
  1531. struct dsaf_drv_tbl_tcam_key mac_key;
  1532. struct dsaf_drv_tbl_tcam_key mask_key;
  1533. struct dsaf_tbl_tcam_data *pmask_key = NULL;
  1534. struct dsaf_tbl_tcam_mcast_cfg mac_data;
  1535. struct dsaf_drv_priv *priv = hns_dsaf_dev_priv(dsaf_dev);
  1536. struct dsaf_drv_soft_mac_tbl *soft_mac_entry = priv->soft_mac_tbl;
  1537. struct dsaf_tbl_tcam_data tcam_data;
  1538. u8 mc_addr[ETH_ALEN];
  1539. int mskid;
  1540. /*chechk mac addr */
  1541. if (MAC_IS_ALL_ZEROS(mac_entry->addr)) {
  1542. dev_err(dsaf_dev->dev, "set_entry failed,addr %pM!\n",
  1543. mac_entry->addr);
  1544. return -EINVAL;
  1545. }
  1546. ether_addr_copy(mc_addr, mac_entry->addr);
  1547. if (!AE_IS_VER1(dsaf_dev->dsaf_ver)) {
  1548. u8 mc_mask[ETH_ALEN];
  1549. /* prepare for key data setting */
  1550. hns_dsaf_setup_mc_mask(dsaf_dev, mac_entry->in_port_num,
  1551. mc_mask, mac_entry->addr);
  1552. hns_dsaf_mc_mask_bit_clear(mc_addr, mc_mask);
  1553. /* config key mask */
  1554. hns_dsaf_set_mac_key(dsaf_dev, &mask_key,
  1555. 0x0,
  1556. 0xff,
  1557. mc_mask);
  1558. mask_key.high.val = le32_to_cpu(mask_key.high.val);
  1559. mask_key.low.val = le32_to_cpu(mask_key.low.val);
  1560. pmask_key = (struct dsaf_tbl_tcam_data *)(&mask_key);
  1561. }
  1562. /*config key */
  1563. hns_dsaf_set_mac_key(
  1564. dsaf_dev, &mac_key, mac_entry->in_vlan_id,
  1565. mac_entry->in_port_num, mc_addr);
  1566. memset(&mac_data, 0, sizeof(struct dsaf_tbl_tcam_mcast_cfg));
  1567. /* check if the tcam is exist */
  1568. entry_index = hns_dsaf_find_soft_mac_entry(dsaf_dev, &mac_key);
  1569. if (entry_index == DSAF_INVALID_ENTRY_IDX) {
  1570. /*if hasnot , find a empty*/
  1571. entry_index = hns_dsaf_find_empty_mac_entry(dsaf_dev);
  1572. if (entry_index == DSAF_INVALID_ENTRY_IDX) {
  1573. /*if hasnot empty, error*/
  1574. dev_err(dsaf_dev->dev,
  1575. "set_uc_entry failed, %s Mac key(%#x:%#x)\n",
  1576. dsaf_dev->ae_dev.name, mac_key.high.val,
  1577. mac_key.low.val);
  1578. return -EINVAL;
  1579. }
  1580. } else {
  1581. /* if exist, add in */
  1582. hns_dsaf_tcam_mc_get(dsaf_dev, entry_index, &tcam_data,
  1583. &mac_data);
  1584. }
  1585. /* config hardware entry */
  1586. if (mac_entry->port_num < DSAF_SERVICE_NW_NUM) {
  1587. mskid = mac_entry->port_num;
  1588. } else if (mac_entry->port_num >= DSAF_BASE_INNER_PORT_NUM) {
  1589. mskid = mac_entry->port_num -
  1590. DSAF_BASE_INNER_PORT_NUM + DSAF_SERVICE_NW_NUM;
  1591. } else {
  1592. dev_err(dsaf_dev->dev,
  1593. "%s,pnum(%d)error,key(%#x:%#x)\n",
  1594. dsaf_dev->ae_dev.name, mac_entry->port_num,
  1595. mac_key.high.val, mac_key.low.val);
  1596. return -EINVAL;
  1597. }
  1598. dsaf_set_bit(mac_data.tbl_mcast_port_msk[mskid / 32], mskid % 32, 1);
  1599. mac_data.tbl_mcast_old_en = 0;
  1600. mac_data.tbl_mcast_item_vld = 1;
  1601. dev_dbg(dsaf_dev->dev,
  1602. "set_uc_entry, %s Mac key(%#x:%#x) entry_index%d\n",
  1603. dsaf_dev->ae_dev.name, mac_key.high.val,
  1604. mac_key.low.val, entry_index);
  1605. tcam_data.tbl_tcam_data_high = cpu_to_le32(mac_key.high.val);
  1606. tcam_data.tbl_tcam_data_low = cpu_to_le32(mac_key.low.val);
  1607. /* config mc entry with mask */
  1608. hns_dsaf_tcam_mc_cfg(dsaf_dev, entry_index, &tcam_data,
  1609. pmask_key, &mac_data);
  1610. /*config software entry */
  1611. soft_mac_entry += entry_index;
  1612. soft_mac_entry->index = entry_index;
  1613. soft_mac_entry->tcam_key.high.val = mac_key.high.val;
  1614. soft_mac_entry->tcam_key.low.val = mac_key.low.val;
  1615. return 0;
  1616. }
  1617. /**
  1618. * hns_dsaf_del_mac_entry - del mac mc-port
  1619. * @dsaf_dev: dsa fabric device struct pointer
  1620. * @vlan_id: vlian id
  1621. * @in_port_num: input port num
  1622. * @addr : mac addr
  1623. */
  1624. int hns_dsaf_del_mac_entry(struct dsaf_device *dsaf_dev, u16 vlan_id,
  1625. u8 in_port_num, u8 *addr)
  1626. {
  1627. u16 entry_index = DSAF_INVALID_ENTRY_IDX;
  1628. struct dsaf_drv_tbl_tcam_key mac_key;
  1629. struct dsaf_drv_priv *priv =
  1630. (struct dsaf_drv_priv *)hns_dsaf_dev_priv(dsaf_dev);
  1631. struct dsaf_drv_soft_mac_tbl *soft_mac_entry = priv->soft_mac_tbl;
  1632. /*check mac addr */
  1633. if (MAC_IS_ALL_ZEROS(addr) || MAC_IS_BROADCAST(addr)) {
  1634. dev_err(dsaf_dev->dev, "del_entry failed,addr %pM!\n",
  1635. addr);
  1636. return -EINVAL;
  1637. }
  1638. /*config key */
  1639. hns_dsaf_set_mac_key(dsaf_dev, &mac_key, vlan_id, in_port_num, addr);
  1640. /*exist ?*/
  1641. entry_index = hns_dsaf_find_soft_mac_entry(dsaf_dev, &mac_key);
  1642. if (entry_index == DSAF_INVALID_ENTRY_IDX) {
  1643. /*not exist, error */
  1644. dev_err(dsaf_dev->dev,
  1645. "del_mac_entry failed, %s Mac key(%#x:%#x)\n",
  1646. dsaf_dev->ae_dev.name,
  1647. mac_key.high.val, mac_key.low.val);
  1648. return -EINVAL;
  1649. }
  1650. dev_dbg(dsaf_dev->dev,
  1651. "del_mac_entry, %s Mac key(%#x:%#x) entry_index%d\n",
  1652. dsaf_dev->ae_dev.name, mac_key.high.val,
  1653. mac_key.low.val, entry_index);
  1654. /*do del opt*/
  1655. hns_dsaf_tcam_mc_invld(dsaf_dev, entry_index);
  1656. /*del soft emtry */
  1657. soft_mac_entry += entry_index;
  1658. soft_mac_entry->index = DSAF_INVALID_ENTRY_IDX;
  1659. return 0;
  1660. }
  1661. /**
  1662. * hns_dsaf_del_mac_mc_port - del mac mc- port
  1663. * @dsaf_dev: dsa fabric device struct pointer
  1664. * @mac_entry: mac entry
  1665. */
  1666. int hns_dsaf_del_mac_mc_port(struct dsaf_device *dsaf_dev,
  1667. struct dsaf_drv_mac_single_dest_entry *mac_entry)
  1668. {
  1669. u16 entry_index = DSAF_INVALID_ENTRY_IDX;
  1670. struct dsaf_drv_tbl_tcam_key mac_key;
  1671. struct dsaf_drv_priv *priv = hns_dsaf_dev_priv(dsaf_dev);
  1672. struct dsaf_drv_soft_mac_tbl *soft_mac_entry = priv->soft_mac_tbl;
  1673. u16 vlan_id;
  1674. u8 in_port_num;
  1675. struct dsaf_tbl_tcam_mcast_cfg mac_data;
  1676. struct dsaf_tbl_tcam_data tcam_data;
  1677. int mskid;
  1678. const u8 empty_msk[sizeof(mac_data.tbl_mcast_port_msk)] = {0};
  1679. struct dsaf_drv_tbl_tcam_key mask_key;
  1680. struct dsaf_tbl_tcam_data *pmask_key = NULL;
  1681. u8 mc_addr[ETH_ALEN];
  1682. if (!(void *)mac_entry) {
  1683. dev_err(dsaf_dev->dev,
  1684. "hns_dsaf_del_mac_mc_port mac_entry is NULL\n");
  1685. return -EINVAL;
  1686. }
  1687. /*check mac addr */
  1688. if (MAC_IS_ALL_ZEROS(mac_entry->addr)) {
  1689. dev_err(dsaf_dev->dev, "del_port failed, addr %pM!\n",
  1690. mac_entry->addr);
  1691. return -EINVAL;
  1692. }
  1693. /* always mask vlan_id field */
  1694. ether_addr_copy(mc_addr, mac_entry->addr);
  1695. if (!AE_IS_VER1(dsaf_dev->dsaf_ver)) {
  1696. u8 mc_mask[ETH_ALEN];
  1697. /* prepare for key data setting */
  1698. hns_dsaf_setup_mc_mask(dsaf_dev, mac_entry->in_port_num,
  1699. mc_mask, mac_entry->addr);
  1700. hns_dsaf_mc_mask_bit_clear(mc_addr, mc_mask);
  1701. /* config key mask */
  1702. hns_dsaf_set_mac_key(dsaf_dev, &mask_key, 0x00, 0xff, mc_mask);
  1703. mask_key.high.val = le32_to_cpu(mask_key.high.val);
  1704. mask_key.low.val = le32_to_cpu(mask_key.low.val);
  1705. pmask_key = (struct dsaf_tbl_tcam_data *)(&mask_key);
  1706. }
  1707. /* get key info */
  1708. vlan_id = mac_entry->in_vlan_id;
  1709. in_port_num = mac_entry->in_port_num;
  1710. /* config key */
  1711. hns_dsaf_set_mac_key(dsaf_dev, &mac_key, vlan_id, in_port_num, mc_addr);
  1712. /* check if the tcam entry is exist */
  1713. entry_index = hns_dsaf_find_soft_mac_entry(dsaf_dev, &mac_key);
  1714. if (entry_index == DSAF_INVALID_ENTRY_IDX) {
  1715. /*find none */
  1716. dev_err(dsaf_dev->dev,
  1717. "find_soft_mac_entry failed, %s Mac key(%#x:%#x)\n",
  1718. dsaf_dev->ae_dev.name,
  1719. mac_key.high.val, mac_key.low.val);
  1720. return -EINVAL;
  1721. }
  1722. dev_dbg(dsaf_dev->dev,
  1723. "del_mac_mc_port, %s key(%#x:%#x) index%d\n",
  1724. dsaf_dev->ae_dev.name, mac_key.high.val,
  1725. mac_key.low.val, entry_index);
  1726. /* read entry */
  1727. hns_dsaf_tcam_mc_get(dsaf_dev, entry_index, &tcam_data, &mac_data);
  1728. /*del the port*/
  1729. if (mac_entry->port_num < DSAF_SERVICE_NW_NUM) {
  1730. mskid = mac_entry->port_num;
  1731. } else if (mac_entry->port_num >= DSAF_BASE_INNER_PORT_NUM) {
  1732. mskid = mac_entry->port_num -
  1733. DSAF_BASE_INNER_PORT_NUM + DSAF_SERVICE_NW_NUM;
  1734. } else {
  1735. dev_err(dsaf_dev->dev,
  1736. "%s,pnum(%d)error,key(%#x:%#x)\n",
  1737. dsaf_dev->ae_dev.name, mac_entry->port_num,
  1738. mac_key.high.val, mac_key.low.val);
  1739. return -EINVAL;
  1740. }
  1741. dsaf_set_bit(mac_data.tbl_mcast_port_msk[mskid / 32], mskid % 32, 0);
  1742. /*check non port, do del entry */
  1743. if (!memcmp(mac_data.tbl_mcast_port_msk, empty_msk,
  1744. sizeof(mac_data.tbl_mcast_port_msk))) {
  1745. hns_dsaf_tcam_mc_invld(dsaf_dev, entry_index);
  1746. /* del soft entry */
  1747. soft_mac_entry += entry_index;
  1748. soft_mac_entry->index = DSAF_INVALID_ENTRY_IDX;
  1749. } else { /* not zero, just del port, update */
  1750. tcam_data.tbl_tcam_data_high = cpu_to_le32(mac_key.high.val);
  1751. tcam_data.tbl_tcam_data_low = cpu_to_le32(mac_key.low.val);
  1752. hns_dsaf_tcam_mc_cfg(dsaf_dev, entry_index,
  1753. &tcam_data,
  1754. pmask_key, &mac_data);
  1755. }
  1756. return 0;
  1757. }
  1758. int hns_dsaf_clr_mac_mc_port(struct dsaf_device *dsaf_dev, u8 mac_id,
  1759. u8 port_num)
  1760. {
  1761. struct dsaf_drv_priv *priv = hns_dsaf_dev_priv(dsaf_dev);
  1762. struct dsaf_drv_soft_mac_tbl *soft_mac_entry;
  1763. struct dsaf_tbl_tcam_mcast_cfg mac_data;
  1764. int ret = 0, i;
  1765. if (HNS_DSAF_IS_DEBUG(dsaf_dev))
  1766. return 0;
  1767. for (i = 0; i < DSAF_TCAM_SUM - DSAFV2_MAC_FUZZY_TCAM_NUM; i++) {
  1768. u8 addr[ETH_ALEN];
  1769. u8 port;
  1770. soft_mac_entry = priv->soft_mac_tbl + i;
  1771. hns_dsaf_tcam_addr_get(&soft_mac_entry->tcam_key, addr);
  1772. port = dsaf_get_field(
  1773. soft_mac_entry->tcam_key.low.bits.port_vlan,
  1774. DSAF_TBL_TCAM_KEY_PORT_M,
  1775. DSAF_TBL_TCAM_KEY_PORT_S);
  1776. /* check valid tcam mc entry */
  1777. if (soft_mac_entry->index != DSAF_INVALID_ENTRY_IDX &&
  1778. port == mac_id &&
  1779. is_multicast_ether_addr(addr) &&
  1780. !is_broadcast_ether_addr(addr)) {
  1781. const u32 empty_msk[DSAF_PORT_MSK_NUM] = {0};
  1782. struct dsaf_drv_mac_single_dest_entry mac_entry;
  1783. /* disable receiving of this multicast address for
  1784. * the VF.
  1785. */
  1786. ether_addr_copy(mac_entry.addr, addr);
  1787. mac_entry.in_vlan_id = dsaf_get_field(
  1788. soft_mac_entry->tcam_key.low.bits.port_vlan,
  1789. DSAF_TBL_TCAM_KEY_VLAN_M,
  1790. DSAF_TBL_TCAM_KEY_VLAN_S);
  1791. mac_entry.in_port_num = mac_id;
  1792. mac_entry.port_num = port_num;
  1793. if (hns_dsaf_del_mac_mc_port(dsaf_dev, &mac_entry)) {
  1794. ret = -EINVAL;
  1795. continue;
  1796. }
  1797. /* disable receiving of this multicast address for
  1798. * the mac port if all VF are disable
  1799. */
  1800. hns_dsaf_tcam_mc_get(dsaf_dev, i,
  1801. (struct dsaf_tbl_tcam_data *)
  1802. (&soft_mac_entry->tcam_key),
  1803. &mac_data);
  1804. dsaf_set_bit(mac_data.tbl_mcast_port_msk[mac_id / 32],
  1805. mac_id % 32, 0);
  1806. if (!memcmp(mac_data.tbl_mcast_port_msk, empty_msk,
  1807. sizeof(u32) * DSAF_PORT_MSK_NUM)) {
  1808. mac_entry.port_num = mac_id;
  1809. if (hns_dsaf_del_mac_mc_port(dsaf_dev,
  1810. &mac_entry)) {
  1811. ret = -EINVAL;
  1812. continue;
  1813. }
  1814. }
  1815. }
  1816. }
  1817. return ret;
  1818. }
  1819. static struct dsaf_device *hns_dsaf_alloc_dev(struct device *dev,
  1820. size_t sizeof_priv)
  1821. {
  1822. struct dsaf_device *dsaf_dev;
  1823. dsaf_dev = devm_kzalloc(dev,
  1824. sizeof(*dsaf_dev) + sizeof_priv, GFP_KERNEL);
  1825. if (unlikely(!dsaf_dev)) {
  1826. dsaf_dev = ERR_PTR(-ENOMEM);
  1827. } else {
  1828. dsaf_dev->dev = dev;
  1829. dev_set_drvdata(dev, dsaf_dev);
  1830. }
  1831. return dsaf_dev;
  1832. }
  1833. /**
  1834. * hns_dsaf_free_dev - free dev mem
  1835. * @dev: struct device pointer
  1836. */
  1837. static void hns_dsaf_free_dev(struct dsaf_device *dsaf_dev)
  1838. {
  1839. (void)dev_set_drvdata(dsaf_dev->dev, NULL);
  1840. }
  1841. /**
  1842. * dsaf_pfc_unit_cnt - set pfc unit count
  1843. * @dsaf_id: dsa fabric id
  1844. * @pport_rate: value array
  1845. * @pdsaf_pfc_unit_cnt: value array
  1846. */
  1847. static void hns_dsaf_pfc_unit_cnt(struct dsaf_device *dsaf_dev, int mac_id,
  1848. enum dsaf_port_rate_mode rate)
  1849. {
  1850. u32 unit_cnt;
  1851. switch (rate) {
  1852. case DSAF_PORT_RATE_10000:
  1853. unit_cnt = HNS_DSAF_PFC_UNIT_CNT_FOR_XGE;
  1854. break;
  1855. case DSAF_PORT_RATE_1000:
  1856. unit_cnt = HNS_DSAF_PFC_UNIT_CNT_FOR_GE_1000;
  1857. break;
  1858. case DSAF_PORT_RATE_2500:
  1859. unit_cnt = HNS_DSAF_PFC_UNIT_CNT_FOR_GE_1000;
  1860. break;
  1861. default:
  1862. unit_cnt = HNS_DSAF_PFC_UNIT_CNT_FOR_XGE;
  1863. }
  1864. dsaf_set_dev_field(dsaf_dev,
  1865. (DSAF_PFC_UNIT_CNT_0_REG + 0x4 * (u64)mac_id),
  1866. DSAF_PFC_UNINT_CNT_M, DSAF_PFC_UNINT_CNT_S,
  1867. unit_cnt);
  1868. }
  1869. /**
  1870. * dsaf_port_work_rate_cfg - fifo
  1871. * @dsaf_id: dsa fabric id
  1872. * @xge_ge_work_mode
  1873. */
  1874. static void
  1875. hns_dsaf_port_work_rate_cfg(struct dsaf_device *dsaf_dev, int mac_id,
  1876. enum dsaf_port_rate_mode rate_mode)
  1877. {
  1878. u32 port_work_mode;
  1879. port_work_mode = dsaf_read_dev(
  1880. dsaf_dev, DSAF_XGE_GE_WORK_MODE_0_REG + 0x4 * (u64)mac_id);
  1881. if (rate_mode == DSAF_PORT_RATE_10000)
  1882. dsaf_set_bit(port_work_mode, DSAF_XGE_GE_WORK_MODE_S, 1);
  1883. else
  1884. dsaf_set_bit(port_work_mode, DSAF_XGE_GE_WORK_MODE_S, 0);
  1885. dsaf_write_dev(dsaf_dev,
  1886. DSAF_XGE_GE_WORK_MODE_0_REG + 0x4 * (u64)mac_id,
  1887. port_work_mode);
  1888. hns_dsaf_pfc_unit_cnt(dsaf_dev, mac_id, rate_mode);
  1889. }
  1890. /**
  1891. * hns_dsaf_fix_mac_mode - dsaf modify mac mode
  1892. * @mac_cb: mac contrl block
  1893. */
  1894. void hns_dsaf_fix_mac_mode(struct hns_mac_cb *mac_cb)
  1895. {
  1896. enum dsaf_port_rate_mode mode;
  1897. struct dsaf_device *dsaf_dev = mac_cb->dsaf_dev;
  1898. int mac_id = mac_cb->mac_id;
  1899. if (mac_cb->mac_type != HNAE_PORT_SERVICE)
  1900. return;
  1901. if (mac_cb->phy_if == PHY_INTERFACE_MODE_XGMII)
  1902. mode = DSAF_PORT_RATE_10000;
  1903. else
  1904. mode = DSAF_PORT_RATE_1000;
  1905. hns_dsaf_port_work_rate_cfg(dsaf_dev, mac_id, mode);
  1906. }
  1907. static u32 hns_dsaf_get_inode_prio_reg(int index)
  1908. {
  1909. int base_index, offset;
  1910. u32 base_addr = DSAF_INODE_IN_PRIO_PAUSE_BASE_REG;
  1911. base_index = (index + 1) / DSAF_REG_PER_ZONE;
  1912. offset = (index + 1) % DSAF_REG_PER_ZONE;
  1913. return base_addr + DSAF_INODE_IN_PRIO_PAUSE_BASE_OFFSET * base_index +
  1914. DSAF_INODE_IN_PRIO_PAUSE_OFFSET * offset;
  1915. }
  1916. void hns_dsaf_update_stats(struct dsaf_device *dsaf_dev, u32 node_num)
  1917. {
  1918. struct dsaf_hw_stats *hw_stats
  1919. = &dsaf_dev->hw_stats[node_num];
  1920. bool is_ver1 = AE_IS_VER1(dsaf_dev->dsaf_ver);
  1921. int i;
  1922. u32 reg_tmp;
  1923. hw_stats->pad_drop += dsaf_read_dev(dsaf_dev,
  1924. DSAF_INODE_PAD_DISCARD_NUM_0_REG + 0x80 * (u64)node_num);
  1925. hw_stats->man_pkts += dsaf_read_dev(dsaf_dev,
  1926. DSAF_INODE_FINAL_IN_MAN_NUM_0_REG + 0x80 * (u64)node_num);
  1927. hw_stats->rx_pkts += dsaf_read_dev(dsaf_dev,
  1928. DSAF_INODE_FINAL_IN_PKT_NUM_0_REG + 0x80 * (u64)node_num);
  1929. hw_stats->rx_pkt_id += dsaf_read_dev(dsaf_dev,
  1930. DSAF_INODE_SBM_PID_NUM_0_REG + 0x80 * (u64)node_num);
  1931. reg_tmp = is_ver1 ? DSAF_INODE_FINAL_IN_PAUSE_NUM_0_REG :
  1932. DSAFV2_INODE_FINAL_IN_PAUSE_NUM_0_REG;
  1933. hw_stats->rx_pause_frame +=
  1934. dsaf_read_dev(dsaf_dev, reg_tmp + 0x80 * (u64)node_num);
  1935. hw_stats->release_buf_num += dsaf_read_dev(dsaf_dev,
  1936. DSAF_INODE_SBM_RELS_NUM_0_REG + 0x80 * (u64)node_num);
  1937. hw_stats->sbm_drop += dsaf_read_dev(dsaf_dev,
  1938. DSAF_INODE_SBM_DROP_NUM_0_REG + 0x80 * (u64)node_num);
  1939. hw_stats->crc_false += dsaf_read_dev(dsaf_dev,
  1940. DSAF_INODE_CRC_FALSE_NUM_0_REG + 0x80 * (u64)node_num);
  1941. hw_stats->bp_drop += dsaf_read_dev(dsaf_dev,
  1942. DSAF_INODE_BP_DISCARD_NUM_0_REG + 0x80 * (u64)node_num);
  1943. hw_stats->rslt_drop += dsaf_read_dev(dsaf_dev,
  1944. DSAF_INODE_RSLT_DISCARD_NUM_0_REG + 0x80 * (u64)node_num);
  1945. hw_stats->local_addr_false += dsaf_read_dev(dsaf_dev,
  1946. DSAF_INODE_LOCAL_ADDR_FALSE_NUM_0_REG + 0x80 * (u64)node_num);
  1947. hw_stats->vlan_drop += dsaf_read_dev(dsaf_dev,
  1948. DSAF_INODE_SW_VLAN_TAG_DISC_0_REG + 4 * (u64)node_num);
  1949. hw_stats->stp_drop += dsaf_read_dev(dsaf_dev,
  1950. DSAF_INODE_IN_DATA_STP_DISC_0_REG + 4 * (u64)node_num);
  1951. /* pfc pause frame statistics stored in dsaf inode*/
  1952. if ((node_num < DSAF_SERVICE_NW_NUM) && !is_ver1) {
  1953. for (i = 0; i < DSAF_PRIO_NR; i++) {
  1954. reg_tmp = hns_dsaf_get_inode_prio_reg(i);
  1955. hw_stats->rx_pfc[i] += dsaf_read_dev(dsaf_dev,
  1956. reg_tmp + 0x4 * (u64)node_num);
  1957. hw_stats->tx_pfc[i] += dsaf_read_dev(dsaf_dev,
  1958. DSAF_XOD_XGE_PFC_PRIO_CNT_BASE_REG +
  1959. DSAF_XOD_XGE_PFC_PRIO_CNT_OFFSET * i +
  1960. 0xF0 * (u64)node_num);
  1961. }
  1962. }
  1963. hw_stats->tx_pkts += dsaf_read_dev(dsaf_dev,
  1964. DSAF_XOD_RCVPKT_CNT_0_REG + 0x90 * (u64)node_num);
  1965. }
  1966. /**
  1967. *hns_dsaf_get_regs - dump dsaf regs
  1968. *@dsaf_dev: dsaf device
  1969. *@data:data for value of regs
  1970. */
  1971. void hns_dsaf_get_regs(struct dsaf_device *ddev, u32 port, void *data)
  1972. {
  1973. u32 i = 0;
  1974. u32 j;
  1975. u32 *p = data;
  1976. u32 reg_tmp;
  1977. bool is_ver1 = AE_IS_VER1(ddev->dsaf_ver);
  1978. /* dsaf common registers */
  1979. p[0] = dsaf_read_dev(ddev, DSAF_SRAM_INIT_OVER_0_REG);
  1980. p[1] = dsaf_read_dev(ddev, DSAF_CFG_0_REG);
  1981. p[2] = dsaf_read_dev(ddev, DSAF_ECC_ERR_INVERT_0_REG);
  1982. p[3] = dsaf_read_dev(ddev, DSAF_ABNORMAL_TIMEOUT_0_REG);
  1983. p[4] = dsaf_read_dev(ddev, DSAF_FSM_TIMEOUT_0_REG);
  1984. p[5] = dsaf_read_dev(ddev, DSAF_DSA_REG_CNT_CLR_CE_REG);
  1985. p[6] = dsaf_read_dev(ddev, DSAF_DSA_SBM_INF_FIFO_THRD_REG);
  1986. p[7] = dsaf_read_dev(ddev, DSAF_DSA_SRAM_1BIT_ECC_SEL_REG);
  1987. p[8] = dsaf_read_dev(ddev, DSAF_DSA_SRAM_1BIT_ECC_CNT_REG);
  1988. p[9] = dsaf_read_dev(ddev, DSAF_PFC_EN_0_REG + port * 4);
  1989. p[10] = dsaf_read_dev(ddev, DSAF_PFC_UNIT_CNT_0_REG + port * 4);
  1990. p[11] = dsaf_read_dev(ddev, DSAF_XGE_INT_MSK_0_REG + port * 4);
  1991. p[12] = dsaf_read_dev(ddev, DSAF_XGE_INT_SRC_0_REG + port * 4);
  1992. p[13] = dsaf_read_dev(ddev, DSAF_XGE_INT_STS_0_REG + port * 4);
  1993. p[14] = dsaf_read_dev(ddev, DSAF_XGE_INT_MSK_0_REG + port * 4);
  1994. p[15] = dsaf_read_dev(ddev, DSAF_PPE_INT_MSK_0_REG + port * 4);
  1995. p[16] = dsaf_read_dev(ddev, DSAF_ROCEE_INT_MSK_0_REG + port * 4);
  1996. p[17] = dsaf_read_dev(ddev, DSAF_XGE_INT_SRC_0_REG + port * 4);
  1997. p[18] = dsaf_read_dev(ddev, DSAF_PPE_INT_SRC_0_REG + port * 4);
  1998. p[19] = dsaf_read_dev(ddev, DSAF_ROCEE_INT_SRC_0_REG + port * 4);
  1999. p[20] = dsaf_read_dev(ddev, DSAF_XGE_INT_STS_0_REG + port * 4);
  2000. p[21] = dsaf_read_dev(ddev, DSAF_PPE_INT_STS_0_REG + port * 4);
  2001. p[22] = dsaf_read_dev(ddev, DSAF_ROCEE_INT_STS_0_REG + port * 4);
  2002. p[23] = dsaf_read_dev(ddev, DSAF_PPE_QID_CFG_0_REG + port * 4);
  2003. for (i = 0; i < DSAF_SW_PORT_NUM; i++)
  2004. p[24 + i] = dsaf_read_dev(ddev,
  2005. DSAF_SW_PORT_TYPE_0_REG + i * 4);
  2006. p[32] = dsaf_read_dev(ddev, DSAF_MIX_DEF_QID_0_REG + port * 4);
  2007. for (i = 0; i < DSAF_SW_PORT_NUM; i++)
  2008. p[33 + i] = dsaf_read_dev(ddev,
  2009. DSAF_PORT_DEF_VLAN_0_REG + i * 4);
  2010. for (i = 0; i < DSAF_TOTAL_QUEUE_NUM; i++)
  2011. p[41 + i] = dsaf_read_dev(ddev,
  2012. DSAF_VM_DEF_VLAN_0_REG + i * 4);
  2013. /* dsaf inode registers */
  2014. p[170] = dsaf_read_dev(ddev, DSAF_INODE_CUT_THROUGH_CFG_0_REG);
  2015. p[171] = dsaf_read_dev(ddev,
  2016. DSAF_INODE_ECC_ERR_ADDR_0_REG + port * 0x80);
  2017. for (i = 0; i < DSAF_INODE_NUM / DSAF_COMM_CHN; i++) {
  2018. j = i * DSAF_COMM_CHN + port;
  2019. p[172 + i] = dsaf_read_dev(ddev,
  2020. DSAF_INODE_IN_PORT_NUM_0_REG + j * 0x80);
  2021. p[175 + i] = dsaf_read_dev(ddev,
  2022. DSAF_INODE_PRI_TC_CFG_0_REG + j * 0x80);
  2023. p[178 + i] = dsaf_read_dev(ddev,
  2024. DSAF_INODE_BP_STATUS_0_REG + j * 0x80);
  2025. p[181 + i] = dsaf_read_dev(ddev,
  2026. DSAF_INODE_PAD_DISCARD_NUM_0_REG + j * 0x80);
  2027. p[184 + i] = dsaf_read_dev(ddev,
  2028. DSAF_INODE_FINAL_IN_MAN_NUM_0_REG + j * 0x80);
  2029. p[187 + i] = dsaf_read_dev(ddev,
  2030. DSAF_INODE_FINAL_IN_PKT_NUM_0_REG + j * 0x80);
  2031. p[190 + i] = dsaf_read_dev(ddev,
  2032. DSAF_INODE_SBM_PID_NUM_0_REG + j * 0x80);
  2033. reg_tmp = is_ver1 ? DSAF_INODE_FINAL_IN_PAUSE_NUM_0_REG :
  2034. DSAFV2_INODE_FINAL_IN_PAUSE_NUM_0_REG;
  2035. p[193 + i] = dsaf_read_dev(ddev, reg_tmp + j * 0x80);
  2036. p[196 + i] = dsaf_read_dev(ddev,
  2037. DSAF_INODE_SBM_RELS_NUM_0_REG + j * 0x80);
  2038. p[199 + i] = dsaf_read_dev(ddev,
  2039. DSAF_INODE_SBM_DROP_NUM_0_REG + j * 0x80);
  2040. p[202 + i] = dsaf_read_dev(ddev,
  2041. DSAF_INODE_CRC_FALSE_NUM_0_REG + j * 0x80);
  2042. p[205 + i] = dsaf_read_dev(ddev,
  2043. DSAF_INODE_BP_DISCARD_NUM_0_REG + j * 0x80);
  2044. p[208 + i] = dsaf_read_dev(ddev,
  2045. DSAF_INODE_RSLT_DISCARD_NUM_0_REG + j * 0x80);
  2046. p[211 + i] = dsaf_read_dev(ddev,
  2047. DSAF_INODE_LOCAL_ADDR_FALSE_NUM_0_REG + j * 0x80);
  2048. p[214 + i] = dsaf_read_dev(ddev,
  2049. DSAF_INODE_VOQ_OVER_NUM_0_REG + j * 0x80);
  2050. p[217 + i] = dsaf_read_dev(ddev,
  2051. DSAF_INODE_BD_SAVE_STATUS_0_REG + j * 4);
  2052. p[220 + i] = dsaf_read_dev(ddev,
  2053. DSAF_INODE_BD_ORDER_STATUS_0_REG + j * 4);
  2054. p[223 + i] = dsaf_read_dev(ddev,
  2055. DSAF_INODE_SW_VLAN_TAG_DISC_0_REG + j * 4);
  2056. p[226 + i] = dsaf_read_dev(ddev,
  2057. DSAF_INODE_IN_DATA_STP_DISC_0_REG + j * 4);
  2058. }
  2059. p[229] = dsaf_read_dev(ddev, DSAF_INODE_GE_FC_EN_0_REG + port * 4);
  2060. for (i = 0; i < DSAF_INODE_NUM / DSAF_COMM_CHN; i++) {
  2061. j = i * DSAF_COMM_CHN + port;
  2062. p[230 + i] = dsaf_read_dev(ddev,
  2063. DSAF_INODE_VC0_IN_PKT_NUM_0_REG + j * 4);
  2064. }
  2065. p[233] = dsaf_read_dev(ddev,
  2066. DSAF_INODE_VC1_IN_PKT_NUM_0_REG + port * 0x80);
  2067. /* dsaf inode registers */
  2068. for (i = 0; i < HNS_DSAF_SBM_NUM(ddev) / DSAF_COMM_CHN; i++) {
  2069. j = i * DSAF_COMM_CHN + port;
  2070. p[234 + i] = dsaf_read_dev(ddev,
  2071. DSAF_SBM_CFG_REG_0_REG + j * 0x80);
  2072. p[237 + i] = dsaf_read_dev(ddev,
  2073. DSAF_SBM_BP_CFG_0_XGE_REG_0_REG + j * 0x80);
  2074. p[240 + i] = dsaf_read_dev(ddev,
  2075. DSAF_SBM_BP_CFG_1_REG_0_REG + j * 0x80);
  2076. p[243 + i] = dsaf_read_dev(ddev,
  2077. DSAF_SBM_BP_CFG_2_XGE_REG_0_REG + j * 0x80);
  2078. p[246 + i] = dsaf_read_dev(ddev,
  2079. DSAF_SBM_FREE_CNT_0_0_REG + j * 0x80);
  2080. p[249 + i] = dsaf_read_dev(ddev,
  2081. DSAF_SBM_FREE_CNT_1_0_REG + j * 0x80);
  2082. p[252 + i] = dsaf_read_dev(ddev,
  2083. DSAF_SBM_BP_CNT_0_0_REG + j * 0x80);
  2084. p[255 + i] = dsaf_read_dev(ddev,
  2085. DSAF_SBM_BP_CNT_1_0_REG + j * 0x80);
  2086. p[258 + i] = dsaf_read_dev(ddev,
  2087. DSAF_SBM_BP_CNT_2_0_REG + j * 0x80);
  2088. p[261 + i] = dsaf_read_dev(ddev,
  2089. DSAF_SBM_BP_CNT_3_0_REG + j * 0x80);
  2090. p[264 + i] = dsaf_read_dev(ddev,
  2091. DSAF_SBM_INER_ST_0_REG + j * 0x80);
  2092. p[267 + i] = dsaf_read_dev(ddev,
  2093. DSAF_SBM_MIB_REQ_FAILED_TC_0_REG + j * 0x80);
  2094. p[270 + i] = dsaf_read_dev(ddev,
  2095. DSAF_SBM_LNK_INPORT_CNT_0_REG + j * 0x80);
  2096. p[273 + i] = dsaf_read_dev(ddev,
  2097. DSAF_SBM_LNK_DROP_CNT_0_REG + j * 0x80);
  2098. p[276 + i] = dsaf_read_dev(ddev,
  2099. DSAF_SBM_INF_OUTPORT_CNT_0_REG + j * 0x80);
  2100. p[279 + i] = dsaf_read_dev(ddev,
  2101. DSAF_SBM_LNK_INPORT_TC0_CNT_0_REG + j * 0x80);
  2102. p[282 + i] = dsaf_read_dev(ddev,
  2103. DSAF_SBM_LNK_INPORT_TC1_CNT_0_REG + j * 0x80);
  2104. p[285 + i] = dsaf_read_dev(ddev,
  2105. DSAF_SBM_LNK_INPORT_TC2_CNT_0_REG + j * 0x80);
  2106. p[288 + i] = dsaf_read_dev(ddev,
  2107. DSAF_SBM_LNK_INPORT_TC3_CNT_0_REG + j * 0x80);
  2108. p[291 + i] = dsaf_read_dev(ddev,
  2109. DSAF_SBM_LNK_INPORT_TC4_CNT_0_REG + j * 0x80);
  2110. p[294 + i] = dsaf_read_dev(ddev,
  2111. DSAF_SBM_LNK_INPORT_TC5_CNT_0_REG + j * 0x80);
  2112. p[297 + i] = dsaf_read_dev(ddev,
  2113. DSAF_SBM_LNK_INPORT_TC6_CNT_0_REG + j * 0x80);
  2114. p[300 + i] = dsaf_read_dev(ddev,
  2115. DSAF_SBM_LNK_INPORT_TC7_CNT_0_REG + j * 0x80);
  2116. p[303 + i] = dsaf_read_dev(ddev,
  2117. DSAF_SBM_LNK_REQ_CNT_0_REG + j * 0x80);
  2118. p[306 + i] = dsaf_read_dev(ddev,
  2119. DSAF_SBM_LNK_RELS_CNT_0_REG + j * 0x80);
  2120. p[309 + i] = dsaf_read_dev(ddev,
  2121. DSAF_SBM_BP_CFG_3_REG_0_REG + j * 0x80);
  2122. p[312 + i] = dsaf_read_dev(ddev,
  2123. DSAF_SBM_BP_CFG_4_REG_0_REG + j * 0x80);
  2124. }
  2125. /* dsaf onode registers */
  2126. for (i = 0; i < DSAF_XOD_NUM; i++) {
  2127. p[315 + i] = dsaf_read_dev(ddev,
  2128. DSAF_XOD_ETS_TSA_TC0_TC3_CFG_0_REG + i * 0x90);
  2129. p[323 + i] = dsaf_read_dev(ddev,
  2130. DSAF_XOD_ETS_TSA_TC4_TC7_CFG_0_REG + i * 0x90);
  2131. p[331 + i] = dsaf_read_dev(ddev,
  2132. DSAF_XOD_ETS_BW_TC0_TC3_CFG_0_REG + i * 0x90);
  2133. p[339 + i] = dsaf_read_dev(ddev,
  2134. DSAF_XOD_ETS_BW_TC4_TC7_CFG_0_REG + i * 0x90);
  2135. p[347 + i] = dsaf_read_dev(ddev,
  2136. DSAF_XOD_ETS_BW_OFFSET_CFG_0_REG + i * 0x90);
  2137. p[355 + i] = dsaf_read_dev(ddev,
  2138. DSAF_XOD_ETS_TOKEN_CFG_0_REG + i * 0x90);
  2139. }
  2140. p[363] = dsaf_read_dev(ddev, DSAF_XOD_PFS_CFG_0_0_REG + port * 0x90);
  2141. p[364] = dsaf_read_dev(ddev, DSAF_XOD_PFS_CFG_1_0_REG + port * 0x90);
  2142. p[365] = dsaf_read_dev(ddev, DSAF_XOD_PFS_CFG_2_0_REG + port * 0x90);
  2143. for (i = 0; i < DSAF_XOD_BIG_NUM / DSAF_COMM_CHN; i++) {
  2144. j = i * DSAF_COMM_CHN + port;
  2145. p[366 + i] = dsaf_read_dev(ddev,
  2146. DSAF_XOD_GNT_L_0_REG + j * 0x90);
  2147. p[369 + i] = dsaf_read_dev(ddev,
  2148. DSAF_XOD_GNT_H_0_REG + j * 0x90);
  2149. p[372 + i] = dsaf_read_dev(ddev,
  2150. DSAF_XOD_CONNECT_STATE_0_REG + j * 0x90);
  2151. p[375 + i] = dsaf_read_dev(ddev,
  2152. DSAF_XOD_RCVPKT_CNT_0_REG + j * 0x90);
  2153. p[378 + i] = dsaf_read_dev(ddev,
  2154. DSAF_XOD_RCVTC0_CNT_0_REG + j * 0x90);
  2155. p[381 + i] = dsaf_read_dev(ddev,
  2156. DSAF_XOD_RCVTC1_CNT_0_REG + j * 0x90);
  2157. p[384 + i] = dsaf_read_dev(ddev,
  2158. DSAF_XOD_RCVTC2_CNT_0_REG + j * 0x90);
  2159. p[387 + i] = dsaf_read_dev(ddev,
  2160. DSAF_XOD_RCVTC3_CNT_0_REG + j * 0x90);
  2161. p[390 + i] = dsaf_read_dev(ddev,
  2162. DSAF_XOD_RCVVC0_CNT_0_REG + j * 0x90);
  2163. p[393 + i] = dsaf_read_dev(ddev,
  2164. DSAF_XOD_RCVVC1_CNT_0_REG + j * 0x90);
  2165. }
  2166. p[396] = dsaf_read_dev(ddev,
  2167. DSAF_XOD_XGE_RCVIN0_CNT_0_REG + port * 0x90);
  2168. p[397] = dsaf_read_dev(ddev,
  2169. DSAF_XOD_XGE_RCVIN1_CNT_0_REG + port * 0x90);
  2170. p[398] = dsaf_read_dev(ddev,
  2171. DSAF_XOD_XGE_RCVIN2_CNT_0_REG + port * 0x90);
  2172. p[399] = dsaf_read_dev(ddev,
  2173. DSAF_XOD_XGE_RCVIN3_CNT_0_REG + port * 0x90);
  2174. p[400] = dsaf_read_dev(ddev,
  2175. DSAF_XOD_XGE_RCVIN4_CNT_0_REG + port * 0x90);
  2176. p[401] = dsaf_read_dev(ddev,
  2177. DSAF_XOD_XGE_RCVIN5_CNT_0_REG + port * 0x90);
  2178. p[402] = dsaf_read_dev(ddev,
  2179. DSAF_XOD_XGE_RCVIN6_CNT_0_REG + port * 0x90);
  2180. p[403] = dsaf_read_dev(ddev,
  2181. DSAF_XOD_XGE_RCVIN7_CNT_0_REG + port * 0x90);
  2182. p[404] = dsaf_read_dev(ddev,
  2183. DSAF_XOD_PPE_RCVIN0_CNT_0_REG + port * 0x90);
  2184. p[405] = dsaf_read_dev(ddev,
  2185. DSAF_XOD_PPE_RCVIN1_CNT_0_REG + port * 0x90);
  2186. p[406] = dsaf_read_dev(ddev,
  2187. DSAF_XOD_ROCEE_RCVIN0_CNT_0_REG + port * 0x90);
  2188. p[407] = dsaf_read_dev(ddev,
  2189. DSAF_XOD_ROCEE_RCVIN1_CNT_0_REG + port * 0x90);
  2190. p[408] = dsaf_read_dev(ddev,
  2191. DSAF_XOD_FIFO_STATUS_0_REG + port * 0x90);
  2192. /* dsaf voq registers */
  2193. for (i = 0; i < DSAF_VOQ_NUM / DSAF_COMM_CHN; i++) {
  2194. j = (i * DSAF_COMM_CHN + port) * 0x90;
  2195. p[409 + i] = dsaf_read_dev(ddev,
  2196. DSAF_VOQ_ECC_INVERT_EN_0_REG + j);
  2197. p[412 + i] = dsaf_read_dev(ddev,
  2198. DSAF_VOQ_SRAM_PKT_NUM_0_REG + j);
  2199. p[415 + i] = dsaf_read_dev(ddev, DSAF_VOQ_IN_PKT_NUM_0_REG + j);
  2200. p[418 + i] = dsaf_read_dev(ddev,
  2201. DSAF_VOQ_OUT_PKT_NUM_0_REG + j);
  2202. p[421 + i] = dsaf_read_dev(ddev,
  2203. DSAF_VOQ_ECC_ERR_ADDR_0_REG + j);
  2204. p[424 + i] = dsaf_read_dev(ddev, DSAF_VOQ_BP_STATUS_0_REG + j);
  2205. p[427 + i] = dsaf_read_dev(ddev, DSAF_VOQ_SPUP_IDLE_0_REG + j);
  2206. p[430 + i] = dsaf_read_dev(ddev,
  2207. DSAF_VOQ_XGE_XOD_REQ_0_0_REG + j);
  2208. p[433 + i] = dsaf_read_dev(ddev,
  2209. DSAF_VOQ_XGE_XOD_REQ_1_0_REG + j);
  2210. p[436 + i] = dsaf_read_dev(ddev,
  2211. DSAF_VOQ_PPE_XOD_REQ_0_REG + j);
  2212. p[439 + i] = dsaf_read_dev(ddev,
  2213. DSAF_VOQ_ROCEE_XOD_REQ_0_REG + j);
  2214. p[442 + i] = dsaf_read_dev(ddev,
  2215. DSAF_VOQ_BP_ALL_THRD_0_REG + j);
  2216. }
  2217. /* dsaf tbl registers */
  2218. p[445] = dsaf_read_dev(ddev, DSAF_TBL_CTRL_0_REG);
  2219. p[446] = dsaf_read_dev(ddev, DSAF_TBL_INT_MSK_0_REG);
  2220. p[447] = dsaf_read_dev(ddev, DSAF_TBL_INT_SRC_0_REG);
  2221. p[448] = dsaf_read_dev(ddev, DSAF_TBL_INT_STS_0_REG);
  2222. p[449] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_ADDR_0_REG);
  2223. p[450] = dsaf_read_dev(ddev, DSAF_TBL_LINE_ADDR_0_REG);
  2224. p[451] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_HIGH_0_REG);
  2225. p[452] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_LOW_0_REG);
  2226. p[453] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_MCAST_CFG_4_0_REG);
  2227. p[454] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_MCAST_CFG_3_0_REG);
  2228. p[455] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_MCAST_CFG_2_0_REG);
  2229. p[456] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_MCAST_CFG_1_0_REG);
  2230. p[457] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_MCAST_CFG_0_0_REG);
  2231. p[458] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_UCAST_CFG_0_REG);
  2232. p[459] = dsaf_read_dev(ddev, DSAF_TBL_LIN_CFG_0_REG);
  2233. p[460] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_RDATA_HIGH_0_REG);
  2234. p[461] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_RDATA_LOW_0_REG);
  2235. p[462] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_RAM_RDATA4_0_REG);
  2236. p[463] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_RAM_RDATA3_0_REG);
  2237. p[464] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_RAM_RDATA2_0_REG);
  2238. p[465] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_RAM_RDATA1_0_REG);
  2239. p[466] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_RAM_RDATA0_0_REG);
  2240. p[467] = dsaf_read_dev(ddev, DSAF_TBL_LIN_RDATA_0_REG);
  2241. for (i = 0; i < DSAF_SW_PORT_NUM; i++) {
  2242. j = i * 0x8;
  2243. p[468 + 2 * i] = dsaf_read_dev(ddev,
  2244. DSAF_TBL_DA0_MIS_INFO1_0_REG + j);
  2245. p[469 + 2 * i] = dsaf_read_dev(ddev,
  2246. DSAF_TBL_DA0_MIS_INFO0_0_REG + j);
  2247. }
  2248. p[484] = dsaf_read_dev(ddev, DSAF_TBL_SA_MIS_INFO2_0_REG);
  2249. p[485] = dsaf_read_dev(ddev, DSAF_TBL_SA_MIS_INFO1_0_REG);
  2250. p[486] = dsaf_read_dev(ddev, DSAF_TBL_SA_MIS_INFO0_0_REG);
  2251. p[487] = dsaf_read_dev(ddev, DSAF_TBL_PUL_0_REG);
  2252. p[488] = dsaf_read_dev(ddev, DSAF_TBL_OLD_RSLT_0_REG);
  2253. p[489] = dsaf_read_dev(ddev, DSAF_TBL_OLD_SCAN_VAL_0_REG);
  2254. p[490] = dsaf_read_dev(ddev, DSAF_TBL_DFX_CTRL_0_REG);
  2255. p[491] = dsaf_read_dev(ddev, DSAF_TBL_DFX_STAT_0_REG);
  2256. p[492] = dsaf_read_dev(ddev, DSAF_TBL_DFX_STAT_2_0_REG);
  2257. p[493] = dsaf_read_dev(ddev, DSAF_TBL_LKUP_NUM_I_0_REG);
  2258. p[494] = dsaf_read_dev(ddev, DSAF_TBL_LKUP_NUM_O_0_REG);
  2259. p[495] = dsaf_read_dev(ddev, DSAF_TBL_UCAST_BCAST_MIS_INFO_0_0_REG);
  2260. /* dsaf other registers */
  2261. p[496] = dsaf_read_dev(ddev, DSAF_INODE_FIFO_WL_0_REG + port * 0x4);
  2262. p[497] = dsaf_read_dev(ddev, DSAF_ONODE_FIFO_WL_0_REG + port * 0x4);
  2263. p[498] = dsaf_read_dev(ddev, DSAF_XGE_GE_WORK_MODE_0_REG + port * 0x4);
  2264. p[499] = dsaf_read_dev(ddev,
  2265. DSAF_XGE_APP_RX_LINK_UP_0_REG + port * 0x4);
  2266. p[500] = dsaf_read_dev(ddev, DSAF_NETPORT_CTRL_SIG_0_REG + port * 0x4);
  2267. p[501] = dsaf_read_dev(ddev, DSAF_XGE_CTRL_SIG_CFG_0_REG + port * 0x4);
  2268. if (!is_ver1)
  2269. p[502] = dsaf_read_dev(ddev, DSAF_PAUSE_CFG_REG + port * 0x4);
  2270. /* mark end of dsaf regs */
  2271. for (i = 503; i < 504; i++)
  2272. p[i] = 0xdddddddd;
  2273. }
  2274. static char *hns_dsaf_get_node_stats_strings(char *data, int node,
  2275. struct dsaf_device *dsaf_dev)
  2276. {
  2277. char *buff = data;
  2278. int i;
  2279. bool is_ver1 = AE_IS_VER1(dsaf_dev->dsaf_ver);
  2280. snprintf(buff, ETH_GSTRING_LEN, "innod%d_pad_drop_pkts", node);
  2281. buff += ETH_GSTRING_LEN;
  2282. snprintf(buff, ETH_GSTRING_LEN, "innod%d_manage_pkts", node);
  2283. buff += ETH_GSTRING_LEN;
  2284. snprintf(buff, ETH_GSTRING_LEN, "innod%d_rx_pkts", node);
  2285. buff += ETH_GSTRING_LEN;
  2286. snprintf(buff, ETH_GSTRING_LEN, "innod%d_rx_pkt_id", node);
  2287. buff += ETH_GSTRING_LEN;
  2288. snprintf(buff, ETH_GSTRING_LEN, "innod%d_rx_pause_frame", node);
  2289. buff += ETH_GSTRING_LEN;
  2290. snprintf(buff, ETH_GSTRING_LEN, "innod%d_release_buf_num", node);
  2291. buff += ETH_GSTRING_LEN;
  2292. snprintf(buff, ETH_GSTRING_LEN, "innod%d_sbm_drop_pkts", node);
  2293. buff += ETH_GSTRING_LEN;
  2294. snprintf(buff, ETH_GSTRING_LEN, "innod%d_crc_false_pkts", node);
  2295. buff += ETH_GSTRING_LEN;
  2296. snprintf(buff, ETH_GSTRING_LEN, "innod%d_bp_drop_pkts", node);
  2297. buff += ETH_GSTRING_LEN;
  2298. snprintf(buff, ETH_GSTRING_LEN, "innod%d_lookup_rslt_drop_pkts", node);
  2299. buff += ETH_GSTRING_LEN;
  2300. snprintf(buff, ETH_GSTRING_LEN, "innod%d_local_rslt_fail_pkts", node);
  2301. buff += ETH_GSTRING_LEN;
  2302. snprintf(buff, ETH_GSTRING_LEN, "innod%d_vlan_drop_pkts", node);
  2303. buff += ETH_GSTRING_LEN;
  2304. snprintf(buff, ETH_GSTRING_LEN, "innod%d_stp_drop_pkts", node);
  2305. buff += ETH_GSTRING_LEN;
  2306. if (node < DSAF_SERVICE_NW_NUM && !is_ver1) {
  2307. for (i = 0; i < DSAF_PRIO_NR; i++) {
  2308. snprintf(buff + 0 * ETH_GSTRING_LEN * DSAF_PRIO_NR,
  2309. ETH_GSTRING_LEN, "inod%d_pfc_prio%d_pkts",
  2310. node, i);
  2311. snprintf(buff + 1 * ETH_GSTRING_LEN * DSAF_PRIO_NR,
  2312. ETH_GSTRING_LEN, "onod%d_pfc_prio%d_pkts",
  2313. node, i);
  2314. buff += ETH_GSTRING_LEN;
  2315. }
  2316. buff += 1 * DSAF_PRIO_NR * ETH_GSTRING_LEN;
  2317. }
  2318. snprintf(buff, ETH_GSTRING_LEN, "onnod%d_tx_pkts", node);
  2319. buff += ETH_GSTRING_LEN;
  2320. return buff;
  2321. }
  2322. static u64 *hns_dsaf_get_node_stats(struct dsaf_device *ddev, u64 *data,
  2323. int node_num)
  2324. {
  2325. u64 *p = data;
  2326. int i;
  2327. struct dsaf_hw_stats *hw_stats = &ddev->hw_stats[node_num];
  2328. bool is_ver1 = AE_IS_VER1(ddev->dsaf_ver);
  2329. p[0] = hw_stats->pad_drop;
  2330. p[1] = hw_stats->man_pkts;
  2331. p[2] = hw_stats->rx_pkts;
  2332. p[3] = hw_stats->rx_pkt_id;
  2333. p[4] = hw_stats->rx_pause_frame;
  2334. p[5] = hw_stats->release_buf_num;
  2335. p[6] = hw_stats->sbm_drop;
  2336. p[7] = hw_stats->crc_false;
  2337. p[8] = hw_stats->bp_drop;
  2338. p[9] = hw_stats->rslt_drop;
  2339. p[10] = hw_stats->local_addr_false;
  2340. p[11] = hw_stats->vlan_drop;
  2341. p[12] = hw_stats->stp_drop;
  2342. if (node_num < DSAF_SERVICE_NW_NUM && !is_ver1) {
  2343. for (i = 0; i < DSAF_PRIO_NR; i++) {
  2344. p[13 + i + 0 * DSAF_PRIO_NR] = hw_stats->rx_pfc[i];
  2345. p[13 + i + 1 * DSAF_PRIO_NR] = hw_stats->tx_pfc[i];
  2346. }
  2347. p[29] = hw_stats->tx_pkts;
  2348. return &p[30];
  2349. }
  2350. p[13] = hw_stats->tx_pkts;
  2351. return &p[14];
  2352. }
  2353. /**
  2354. *hns_dsaf_get_stats - get dsaf statistic
  2355. *@ddev: dsaf device
  2356. *@data:statistic value
  2357. *@port: port num
  2358. */
  2359. void hns_dsaf_get_stats(struct dsaf_device *ddev, u64 *data, int port)
  2360. {
  2361. u64 *p = data;
  2362. int node_num = port;
  2363. /* for ge/xge node info */
  2364. p = hns_dsaf_get_node_stats(ddev, p, node_num);
  2365. /* for ppe node info */
  2366. node_num = port + DSAF_PPE_INODE_BASE;
  2367. (void)hns_dsaf_get_node_stats(ddev, p, node_num);
  2368. }
  2369. /**
  2370. *hns_dsaf_get_sset_count - get dsaf string set count
  2371. *@stringset: type of values in data
  2372. *return dsaf string name count
  2373. */
  2374. int hns_dsaf_get_sset_count(struct dsaf_device *dsaf_dev, int stringset)
  2375. {
  2376. bool is_ver1 = AE_IS_VER1(dsaf_dev->dsaf_ver);
  2377. if (stringset == ETH_SS_STATS) {
  2378. if (is_ver1)
  2379. return DSAF_STATIC_NUM;
  2380. else
  2381. return DSAF_V2_STATIC_NUM;
  2382. }
  2383. return 0;
  2384. }
  2385. /**
  2386. *hns_dsaf_get_strings - get dsaf string set
  2387. *@stringset:srting set index
  2388. *@data:strings name value
  2389. *@port:port index
  2390. */
  2391. void hns_dsaf_get_strings(int stringset, u8 *data, int port,
  2392. struct dsaf_device *dsaf_dev)
  2393. {
  2394. char *buff = (char *)data;
  2395. int node = port;
  2396. if (stringset != ETH_SS_STATS)
  2397. return;
  2398. /* for ge/xge node info */
  2399. buff = hns_dsaf_get_node_stats_strings(buff, node, dsaf_dev);
  2400. /* for ppe node info */
  2401. node = port + DSAF_PPE_INODE_BASE;
  2402. (void)hns_dsaf_get_node_stats_strings(buff, node, dsaf_dev);
  2403. }
  2404. /**
  2405. *hns_dsaf_get_sset_count - get dsaf regs count
  2406. *return dsaf regs count
  2407. */
  2408. int hns_dsaf_get_regs_count(void)
  2409. {
  2410. return DSAF_DUMP_REGS_NUM;
  2411. }
  2412. static int hns_dsaf_get_port_id(u8 port)
  2413. {
  2414. if (port < DSAF_SERVICE_NW_NUM)
  2415. return port;
  2416. if (port >= DSAF_BASE_INNER_PORT_NUM)
  2417. return port - DSAF_BASE_INNER_PORT_NUM + DSAF_SERVICE_NW_NUM;
  2418. return -EINVAL;
  2419. }
  2420. static void set_promisc_tcam_enable(struct dsaf_device *dsaf_dev, u32 port)
  2421. {
  2422. struct dsaf_tbl_tcam_ucast_cfg tbl_tcam_ucast = {0, 1, 0, 0, 0x80};
  2423. struct dsaf_tbl_tcam_data tbl_tcam_data_mc = {0x01000000, port};
  2424. struct dsaf_tbl_tcam_data tbl_tcam_mask_uc = {0x01000000, 0xf};
  2425. struct dsaf_tbl_tcam_mcast_cfg tbl_tcam_mcast = {0, 0, {0} };
  2426. struct dsaf_drv_priv *priv = hns_dsaf_dev_priv(dsaf_dev);
  2427. struct dsaf_tbl_tcam_data tbl_tcam_data_uc = {0, port};
  2428. struct dsaf_drv_mac_single_dest_entry mask_entry;
  2429. struct dsaf_drv_tbl_tcam_key temp_key, mask_key;
  2430. struct dsaf_drv_soft_mac_tbl *soft_mac_entry;
  2431. u16 entry_index = DSAF_INVALID_ENTRY_IDX;
  2432. struct dsaf_drv_tbl_tcam_key mac_key;
  2433. struct hns_mac_cb *mac_cb;
  2434. u8 addr[ETH_ALEN] = {0};
  2435. u8 port_num;
  2436. int mskid;
  2437. /* promisc use vague table match with vlanid = 0 & macaddr = 0 */
  2438. hns_dsaf_set_mac_key(dsaf_dev, &mac_key, 0x00, port, addr);
  2439. entry_index = hns_dsaf_find_soft_mac_entry(dsaf_dev, &mac_key);
  2440. if (entry_index != DSAF_INVALID_ENTRY_IDX)
  2441. return;
  2442. /* put promisc tcam entry in the end. */
  2443. /* 1. set promisc unicast vague tcam entry. */
  2444. entry_index = hns_dsaf_find_empty_mac_entry_reverse(dsaf_dev);
  2445. if (entry_index == DSAF_INVALID_ENTRY_IDX) {
  2446. dev_err(dsaf_dev->dev,
  2447. "enable uc promisc failed (port:%#x)\n",
  2448. port);
  2449. return;
  2450. }
  2451. mac_cb = dsaf_dev->mac_cb[port];
  2452. (void)hns_mac_get_inner_port_num(mac_cb, 0, &port_num);
  2453. tbl_tcam_ucast.tbl_ucast_out_port = port_num;
  2454. /* config uc vague table */
  2455. hns_dsaf_tcam_uc_cfg_vague(dsaf_dev, entry_index, &tbl_tcam_data_uc,
  2456. &tbl_tcam_mask_uc, &tbl_tcam_ucast);
  2457. /* update software entry */
  2458. soft_mac_entry = priv->soft_mac_tbl;
  2459. soft_mac_entry += entry_index;
  2460. soft_mac_entry->index = entry_index;
  2461. soft_mac_entry->tcam_key.high.val = mac_key.high.val;
  2462. soft_mac_entry->tcam_key.low.val = mac_key.low.val;
  2463. /* step back to the START for mc. */
  2464. soft_mac_entry = priv->soft_mac_tbl;
  2465. /* 2. set promisc multicast vague tcam entry. */
  2466. entry_index = hns_dsaf_find_empty_mac_entry_reverse(dsaf_dev);
  2467. if (entry_index == DSAF_INVALID_ENTRY_IDX) {
  2468. dev_err(dsaf_dev->dev,
  2469. "enable mc promisc failed (port:%#x)\n",
  2470. port);
  2471. return;
  2472. }
  2473. memset(&mask_entry, 0x0, sizeof(mask_entry));
  2474. memset(&mask_key, 0x0, sizeof(mask_key));
  2475. memset(&temp_key, 0x0, sizeof(temp_key));
  2476. mask_entry.addr[0] = 0x01;
  2477. hns_dsaf_set_mac_key(dsaf_dev, &mask_key, mask_entry.in_vlan_id,
  2478. 0xf, mask_entry.addr);
  2479. tbl_tcam_mcast.tbl_mcast_item_vld = 1;
  2480. tbl_tcam_mcast.tbl_mcast_old_en = 0;
  2481. /* set MAC port to handle multicast */
  2482. mskid = hns_dsaf_get_port_id(port);
  2483. if (mskid == -EINVAL) {
  2484. dev_err(dsaf_dev->dev, "%s,pnum(%d)error,key(%#x:%#x)\n",
  2485. dsaf_dev->ae_dev.name, port,
  2486. mask_key.high.val, mask_key.low.val);
  2487. return;
  2488. }
  2489. dsaf_set_bit(tbl_tcam_mcast.tbl_mcast_port_msk[mskid / 32],
  2490. mskid % 32, 1);
  2491. /* set pool bit map to handle multicast */
  2492. mskid = hns_dsaf_get_port_id(port_num);
  2493. if (mskid == -EINVAL) {
  2494. dev_err(dsaf_dev->dev,
  2495. "%s, pool bit map pnum(%d)error,key(%#x:%#x)\n",
  2496. dsaf_dev->ae_dev.name, port_num,
  2497. mask_key.high.val, mask_key.low.val);
  2498. return;
  2499. }
  2500. dsaf_set_bit(tbl_tcam_mcast.tbl_mcast_port_msk[mskid / 32],
  2501. mskid % 32, 1);
  2502. memcpy(&temp_key, &mask_key, sizeof(mask_key));
  2503. hns_dsaf_tcam_mc_cfg_vague(dsaf_dev, entry_index, &tbl_tcam_data_mc,
  2504. (struct dsaf_tbl_tcam_data *)(&mask_key),
  2505. &tbl_tcam_mcast);
  2506. /* update software entry */
  2507. soft_mac_entry += entry_index;
  2508. soft_mac_entry->index = entry_index;
  2509. soft_mac_entry->tcam_key.high.val = temp_key.high.val;
  2510. soft_mac_entry->tcam_key.low.val = temp_key.low.val;
  2511. }
  2512. static void set_promisc_tcam_disable(struct dsaf_device *dsaf_dev, u32 port)
  2513. {
  2514. struct dsaf_tbl_tcam_data tbl_tcam_data_mc = {0x01000000, port};
  2515. struct dsaf_tbl_tcam_ucast_cfg tbl_tcam_ucast = {0, 0, 0, 0, 0};
  2516. struct dsaf_tbl_tcam_mcast_cfg tbl_tcam_mcast = {0, 0, {0} };
  2517. struct dsaf_drv_priv *priv = hns_dsaf_dev_priv(dsaf_dev);
  2518. struct dsaf_tbl_tcam_data tbl_tcam_data_uc = {0, 0};
  2519. struct dsaf_tbl_tcam_data tbl_tcam_mask = {0, 0};
  2520. struct dsaf_drv_soft_mac_tbl *soft_mac_entry;
  2521. u16 entry_index = DSAF_INVALID_ENTRY_IDX;
  2522. struct dsaf_drv_tbl_tcam_key mac_key;
  2523. u8 addr[ETH_ALEN] = {0};
  2524. /* 1. delete uc vague tcam entry. */
  2525. /* promisc use vague table match with vlanid = 0 & macaddr = 0 */
  2526. hns_dsaf_set_mac_key(dsaf_dev, &mac_key, 0x00, port, addr);
  2527. entry_index = hns_dsaf_find_soft_mac_entry(dsaf_dev, &mac_key);
  2528. if (entry_index == DSAF_INVALID_ENTRY_IDX)
  2529. return;
  2530. /* config uc vague table */
  2531. hns_dsaf_tcam_uc_cfg_vague(dsaf_dev, entry_index, &tbl_tcam_data_uc,
  2532. &tbl_tcam_mask, &tbl_tcam_ucast);
  2533. /* update soft management table. */
  2534. soft_mac_entry = priv->soft_mac_tbl;
  2535. soft_mac_entry += entry_index;
  2536. soft_mac_entry->index = DSAF_INVALID_ENTRY_IDX;
  2537. /* step back to the START for mc. */
  2538. soft_mac_entry = priv->soft_mac_tbl;
  2539. /* 2. delete mc vague tcam entry. */
  2540. addr[0] = 0x01;
  2541. memset(&mac_key, 0x0, sizeof(mac_key));
  2542. hns_dsaf_set_mac_key(dsaf_dev, &mac_key, 0x00, port, addr);
  2543. entry_index = hns_dsaf_find_soft_mac_entry(dsaf_dev, &mac_key);
  2544. if (entry_index == DSAF_INVALID_ENTRY_IDX)
  2545. return;
  2546. /* config mc vague table */
  2547. hns_dsaf_tcam_mc_cfg_vague(dsaf_dev, entry_index, &tbl_tcam_data_mc,
  2548. &tbl_tcam_mask, &tbl_tcam_mcast);
  2549. /* update soft management table. */
  2550. soft_mac_entry += entry_index;
  2551. soft_mac_entry->index = DSAF_INVALID_ENTRY_IDX;
  2552. }
  2553. /* Reserve the last TCAM entry for promisc support */
  2554. void hns_dsaf_set_promisc_tcam(struct dsaf_device *dsaf_dev,
  2555. u32 port, bool enable)
  2556. {
  2557. if (enable)
  2558. set_promisc_tcam_enable(dsaf_dev, port);
  2559. else
  2560. set_promisc_tcam_disable(dsaf_dev, port);
  2561. }
  2562. int hns_dsaf_wait_pkt_clean(struct dsaf_device *dsaf_dev, int port)
  2563. {
  2564. u32 val, val_tmp;
  2565. int wait_cnt;
  2566. if (port >= DSAF_SERVICE_NW_NUM)
  2567. return 0;
  2568. wait_cnt = 0;
  2569. while (wait_cnt++ < HNS_MAX_WAIT_CNT) {
  2570. val = dsaf_read_dev(dsaf_dev, DSAF_VOQ_IN_PKT_NUM_0_REG +
  2571. (port + DSAF_XGE_NUM) * 0x40);
  2572. val_tmp = dsaf_read_dev(dsaf_dev, DSAF_VOQ_OUT_PKT_NUM_0_REG +
  2573. (port + DSAF_XGE_NUM) * 0x40);
  2574. if (val == val_tmp)
  2575. break;
  2576. usleep_range(100, 200);
  2577. }
  2578. if (wait_cnt >= HNS_MAX_WAIT_CNT) {
  2579. dev_err(dsaf_dev->dev, "hns dsaf clean wait timeout(%u - %u).\n",
  2580. val, val_tmp);
  2581. return -EBUSY;
  2582. }
  2583. return 0;
  2584. }
  2585. /**
  2586. * dsaf_probe - probo dsaf dev
  2587. * @pdev: dasf platform device
  2588. * retuen 0 - success , negative --fail
  2589. */
  2590. static int hns_dsaf_probe(struct platform_device *pdev)
  2591. {
  2592. struct dsaf_device *dsaf_dev;
  2593. int ret;
  2594. dsaf_dev = hns_dsaf_alloc_dev(&pdev->dev, sizeof(struct dsaf_drv_priv));
  2595. if (IS_ERR(dsaf_dev)) {
  2596. ret = PTR_ERR(dsaf_dev);
  2597. dev_err(&pdev->dev,
  2598. "dsaf_probe dsaf_alloc_dev failed, ret = %#x!\n", ret);
  2599. return ret;
  2600. }
  2601. ret = hns_dsaf_get_cfg(dsaf_dev);
  2602. if (ret)
  2603. goto free_dev;
  2604. ret = hns_dsaf_init(dsaf_dev);
  2605. if (ret)
  2606. goto free_dev;
  2607. ret = hns_mac_init(dsaf_dev);
  2608. if (ret)
  2609. goto uninit_dsaf;
  2610. ret = hns_ppe_init(dsaf_dev);
  2611. if (ret)
  2612. goto uninit_mac;
  2613. ret = hns_dsaf_ae_init(dsaf_dev);
  2614. if (ret)
  2615. goto uninit_ppe;
  2616. return 0;
  2617. uninit_ppe:
  2618. hns_ppe_uninit(dsaf_dev);
  2619. uninit_mac:
  2620. hns_mac_uninit(dsaf_dev);
  2621. uninit_dsaf:
  2622. hns_dsaf_free(dsaf_dev);
  2623. free_dev:
  2624. hns_dsaf_free_dev(dsaf_dev);
  2625. return ret;
  2626. }
  2627. /**
  2628. * dsaf_remove - remove dsaf dev
  2629. * @pdev: dasf platform device
  2630. */
  2631. static int hns_dsaf_remove(struct platform_device *pdev)
  2632. {
  2633. struct dsaf_device *dsaf_dev = dev_get_drvdata(&pdev->dev);
  2634. hns_dsaf_ae_uninit(dsaf_dev);
  2635. hns_ppe_uninit(dsaf_dev);
  2636. hns_mac_uninit(dsaf_dev);
  2637. hns_dsaf_free(dsaf_dev);
  2638. hns_dsaf_free_dev(dsaf_dev);
  2639. return 0;
  2640. }
  2641. static const struct of_device_id g_dsaf_match[] = {
  2642. {.compatible = "hisilicon,hns-dsaf-v1"},
  2643. {.compatible = "hisilicon,hns-dsaf-v2"},
  2644. {}
  2645. };
  2646. MODULE_DEVICE_TABLE(of, g_dsaf_match);
  2647. static struct platform_driver g_dsaf_driver = {
  2648. .probe = hns_dsaf_probe,
  2649. .remove = hns_dsaf_remove,
  2650. .driver = {
  2651. .name = DSAF_DRV_NAME,
  2652. .of_match_table = g_dsaf_match,
  2653. .acpi_match_table = hns_dsaf_acpi_match,
  2654. },
  2655. };
  2656. module_platform_driver(g_dsaf_driver);
  2657. /**
  2658. * hns_dsaf_roce_reset - reset dsaf and roce
  2659. * @dsaf_fwnode: Pointer to framework node for the dasf
  2660. * @enable: false - request reset , true - drop reset
  2661. * retuen 0 - success , negative -fail
  2662. */
  2663. int hns_dsaf_roce_reset(struct fwnode_handle *dsaf_fwnode, bool dereset)
  2664. {
  2665. struct dsaf_device *dsaf_dev;
  2666. struct platform_device *pdev;
  2667. u32 mp;
  2668. u32 sl;
  2669. u32 credit;
  2670. int i;
  2671. const u32 port_map[DSAF_ROCE_CREDIT_CHN][DSAF_ROCE_CHAN_MODE_NUM] = {
  2672. {DSAF_ROCE_PORT_0, DSAF_ROCE_PORT_0, DSAF_ROCE_PORT_0},
  2673. {DSAF_ROCE_PORT_1, DSAF_ROCE_PORT_0, DSAF_ROCE_PORT_0},
  2674. {DSAF_ROCE_PORT_2, DSAF_ROCE_PORT_1, DSAF_ROCE_PORT_0},
  2675. {DSAF_ROCE_PORT_3, DSAF_ROCE_PORT_1, DSAF_ROCE_PORT_0},
  2676. {DSAF_ROCE_PORT_4, DSAF_ROCE_PORT_2, DSAF_ROCE_PORT_1},
  2677. {DSAF_ROCE_PORT_4, DSAF_ROCE_PORT_2, DSAF_ROCE_PORT_1},
  2678. {DSAF_ROCE_PORT_5, DSAF_ROCE_PORT_3, DSAF_ROCE_PORT_1},
  2679. {DSAF_ROCE_PORT_5, DSAF_ROCE_PORT_3, DSAF_ROCE_PORT_1},
  2680. };
  2681. const u32 sl_map[DSAF_ROCE_CREDIT_CHN][DSAF_ROCE_CHAN_MODE_NUM] = {
  2682. {DSAF_ROCE_SL_0, DSAF_ROCE_SL_0, DSAF_ROCE_SL_0},
  2683. {DSAF_ROCE_SL_0, DSAF_ROCE_SL_1, DSAF_ROCE_SL_1},
  2684. {DSAF_ROCE_SL_0, DSAF_ROCE_SL_0, DSAF_ROCE_SL_2},
  2685. {DSAF_ROCE_SL_0, DSAF_ROCE_SL_1, DSAF_ROCE_SL_3},
  2686. {DSAF_ROCE_SL_0, DSAF_ROCE_SL_0, DSAF_ROCE_SL_0},
  2687. {DSAF_ROCE_SL_1, DSAF_ROCE_SL_1, DSAF_ROCE_SL_1},
  2688. {DSAF_ROCE_SL_0, DSAF_ROCE_SL_0, DSAF_ROCE_SL_2},
  2689. {DSAF_ROCE_SL_1, DSAF_ROCE_SL_1, DSAF_ROCE_SL_3},
  2690. };
  2691. /* find the platform device corresponding to fwnode */
  2692. if (is_of_node(dsaf_fwnode)) {
  2693. pdev = of_find_device_by_node(to_of_node(dsaf_fwnode));
  2694. } else if (is_acpi_device_node(dsaf_fwnode)) {
  2695. pdev = hns_dsaf_find_platform_device(dsaf_fwnode);
  2696. } else {
  2697. pr_err("fwnode is neither OF or ACPI type\n");
  2698. return -EINVAL;
  2699. }
  2700. /* check if we were a success in fetching pdev */
  2701. if (!pdev) {
  2702. pr_err("couldn't find platform device for node\n");
  2703. return -ENODEV;
  2704. }
  2705. /* retrieve the dsaf_device from the driver data */
  2706. dsaf_dev = dev_get_drvdata(&pdev->dev);
  2707. if (!dsaf_dev) {
  2708. dev_err(&pdev->dev, "dsaf_dev is NULL\n");
  2709. put_device(&pdev->dev);
  2710. return -ENODEV;
  2711. }
  2712. /* now, make sure we are running on compatible SoC */
  2713. if (AE_IS_VER1(dsaf_dev->dsaf_ver)) {
  2714. dev_err(dsaf_dev->dev, "%s v1 chip doesn't support RoCE!\n",
  2715. dsaf_dev->ae_dev.name);
  2716. put_device(&pdev->dev);
  2717. return -ENODEV;
  2718. }
  2719. /* do reset or de-reset according to the flag */
  2720. if (!dereset) {
  2721. /* reset rocee-channels in dsaf and rocee */
  2722. dsaf_dev->misc_op->hns_dsaf_srst_chns(dsaf_dev, DSAF_CHNS_MASK,
  2723. false);
  2724. dsaf_dev->misc_op->hns_dsaf_roce_srst(dsaf_dev, false);
  2725. } else {
  2726. /* configure dsaf tx roce correspond to port map and sl map */
  2727. mp = dsaf_read_dev(dsaf_dev, DSAF_ROCE_PORT_MAP_REG);
  2728. for (i = 0; i < DSAF_ROCE_CREDIT_CHN; i++)
  2729. dsaf_set_field(mp, 7 << i * 3, i * 3,
  2730. port_map[i][DSAF_ROCE_6PORT_MODE]);
  2731. dsaf_set_field(mp, 3 << i * 3, i * 3, 0);
  2732. dsaf_write_dev(dsaf_dev, DSAF_ROCE_PORT_MAP_REG, mp);
  2733. sl = dsaf_read_dev(dsaf_dev, DSAF_ROCE_SL_MAP_REG);
  2734. for (i = 0; i < DSAF_ROCE_CREDIT_CHN; i++)
  2735. dsaf_set_field(sl, 3 << i * 2, i * 2,
  2736. sl_map[i][DSAF_ROCE_6PORT_MODE]);
  2737. dsaf_write_dev(dsaf_dev, DSAF_ROCE_SL_MAP_REG, sl);
  2738. /* de-reset rocee-channels in dsaf and rocee */
  2739. dsaf_dev->misc_op->hns_dsaf_srst_chns(dsaf_dev, DSAF_CHNS_MASK,
  2740. true);
  2741. msleep(SRST_TIME_INTERVAL);
  2742. dsaf_dev->misc_op->hns_dsaf_roce_srst(dsaf_dev, true);
  2743. /* enable dsaf channel rocee credit */
  2744. credit = dsaf_read_dev(dsaf_dev, DSAF_SBM_ROCEE_CFG_REG_REG);
  2745. dsaf_set_bit(credit, DSAF_SBM_ROCEE_CFG_CRD_EN_B, 0);
  2746. dsaf_write_dev(dsaf_dev, DSAF_SBM_ROCEE_CFG_REG_REG, credit);
  2747. dsaf_set_bit(credit, DSAF_SBM_ROCEE_CFG_CRD_EN_B, 1);
  2748. dsaf_write_dev(dsaf_dev, DSAF_SBM_ROCEE_CFG_REG_REG, credit);
  2749. }
  2750. put_device(&pdev->dev);
  2751. return 0;
  2752. }
  2753. EXPORT_SYMBOL(hns_dsaf_roce_reset);
  2754. MODULE_LICENSE("GPL");
  2755. MODULE_AUTHOR("Huawei Tech. Co., Ltd.");
  2756. MODULE_DESCRIPTION("HNS DSAF driver");
  2757. MODULE_VERSION(DSAF_MOD_VERSION);