hns_dsaf_ppe.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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/module.h>
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/netdevice.h>
  13. #include <linux/etherdevice.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/of.h>
  16. #include <linux/of_address.h>
  17. #include <linux/of_platform.h>
  18. #include "hns_dsaf_ppe.h"
  19. void hns_ppe_set_tso_enable(struct hns_ppe_cb *ppe_cb, u32 value)
  20. {
  21. dsaf_set_dev_bit(ppe_cb, PPEV2_CFG_TSO_EN_REG, 0, !!value);
  22. }
  23. void hns_ppe_set_rss_key(struct hns_ppe_cb *ppe_cb,
  24. const u32 rss_key[HNS_PPEV2_RSS_KEY_NUM])
  25. {
  26. u32 key_item;
  27. for (key_item = 0; key_item < HNS_PPEV2_RSS_KEY_NUM; key_item++)
  28. dsaf_write_dev(ppe_cb, PPEV2_RSS_KEY_REG + key_item * 0x4,
  29. rss_key[key_item]);
  30. }
  31. void hns_ppe_set_indir_table(struct hns_ppe_cb *ppe_cb,
  32. const u32 rss_tab[HNS_PPEV2_RSS_IND_TBL_SIZE])
  33. {
  34. int i;
  35. int reg_value;
  36. for (i = 0; i < (HNS_PPEV2_RSS_IND_TBL_SIZE / 4); i++) {
  37. reg_value = dsaf_read_dev(ppe_cb,
  38. PPEV2_INDRECTION_TBL_REG + i * 0x4);
  39. dsaf_set_field(reg_value, PPEV2_CFG_RSS_TBL_4N0_M,
  40. PPEV2_CFG_RSS_TBL_4N0_S,
  41. rss_tab[i * 4 + 0] & 0x1F);
  42. dsaf_set_field(reg_value, PPEV2_CFG_RSS_TBL_4N1_M,
  43. PPEV2_CFG_RSS_TBL_4N1_S,
  44. rss_tab[i * 4 + 1] & 0x1F);
  45. dsaf_set_field(reg_value, PPEV2_CFG_RSS_TBL_4N2_M,
  46. PPEV2_CFG_RSS_TBL_4N2_S,
  47. rss_tab[i * 4 + 2] & 0x1F);
  48. dsaf_set_field(reg_value, PPEV2_CFG_RSS_TBL_4N3_M,
  49. PPEV2_CFG_RSS_TBL_4N3_S,
  50. rss_tab[i * 4 + 3] & 0x1F);
  51. dsaf_write_dev(
  52. ppe_cb, PPEV2_INDRECTION_TBL_REG + i * 0x4, reg_value);
  53. }
  54. }
  55. static void __iomem *
  56. hns_ppe_common_get_ioaddr(struct ppe_common_cb *ppe_common)
  57. {
  58. return ppe_common->dsaf_dev->ppe_base + PPE_COMMON_REG_OFFSET;
  59. }
  60. /**
  61. * hns_ppe_common_get_cfg - get ppe common config
  62. * @dsaf_dev: dasf device
  63. * comm_index: common index
  64. * retuen 0 - success , negative --fail
  65. */
  66. static int hns_ppe_common_get_cfg(struct dsaf_device *dsaf_dev, int comm_index)
  67. {
  68. struct ppe_common_cb *ppe_common;
  69. int ppe_num;
  70. if (!HNS_DSAF_IS_DEBUG(dsaf_dev))
  71. ppe_num = HNS_PPE_SERVICE_NW_ENGINE_NUM;
  72. else
  73. ppe_num = HNS_PPE_DEBUG_NW_ENGINE_NUM;
  74. ppe_common = devm_kzalloc(dsaf_dev->dev, sizeof(*ppe_common) +
  75. ppe_num * sizeof(struct hns_ppe_cb), GFP_KERNEL);
  76. if (!ppe_common)
  77. return -ENOMEM;
  78. ppe_common->ppe_num = ppe_num;
  79. ppe_common->dsaf_dev = dsaf_dev;
  80. ppe_common->comm_index = comm_index;
  81. if (!HNS_DSAF_IS_DEBUG(dsaf_dev))
  82. ppe_common->ppe_mode = PPE_COMMON_MODE_SERVICE;
  83. else
  84. ppe_common->ppe_mode = PPE_COMMON_MODE_DEBUG;
  85. ppe_common->dev = dsaf_dev->dev;
  86. ppe_common->io_base = hns_ppe_common_get_ioaddr(ppe_common);
  87. dsaf_dev->ppe_common[comm_index] = ppe_common;
  88. return 0;
  89. }
  90. static void
  91. hns_ppe_common_free_cfg(struct dsaf_device *dsaf_dev, u32 comm_index)
  92. {
  93. dsaf_dev->ppe_common[comm_index] = NULL;
  94. }
  95. static void __iomem *hns_ppe_get_iobase(struct ppe_common_cb *ppe_common,
  96. int ppe_idx)
  97. {
  98. return ppe_common->dsaf_dev->ppe_base + ppe_idx * PPE_REG_OFFSET;
  99. }
  100. static void hns_ppe_get_cfg(struct ppe_common_cb *ppe_common)
  101. {
  102. u32 i;
  103. struct hns_ppe_cb *ppe_cb;
  104. u32 ppe_num = ppe_common->ppe_num;
  105. for (i = 0; i < ppe_num; i++) {
  106. ppe_cb = &ppe_common->ppe_cb[i];
  107. ppe_cb->dev = ppe_common->dev;
  108. ppe_cb->next = NULL;
  109. ppe_cb->ppe_common_cb = ppe_common;
  110. ppe_cb->index = i;
  111. ppe_cb->io_base = hns_ppe_get_iobase(ppe_common, i);
  112. ppe_cb->virq = 0;
  113. }
  114. }
  115. static void hns_ppe_cnt_clr_ce(struct hns_ppe_cb *ppe_cb)
  116. {
  117. dsaf_set_dev_bit(ppe_cb, PPE_TNL_0_5_CNT_CLR_CE_REG,
  118. PPE_CNT_CLR_CE_B, 1);
  119. }
  120. static void hns_ppe_set_vlan_strip(struct hns_ppe_cb *ppe_cb, int en)
  121. {
  122. dsaf_write_dev(ppe_cb, PPEV2_VLAN_STRIP_EN_REG, en);
  123. }
  124. /**
  125. * hns_ppe_checksum_hw - set ppe checksum caculate
  126. * @ppe_device: ppe device
  127. * @value: value
  128. */
  129. static void hns_ppe_checksum_hw(struct hns_ppe_cb *ppe_cb, u32 value)
  130. {
  131. dsaf_set_dev_field(ppe_cb, PPE_CFG_PRO_CHECK_EN_REG,
  132. 0xfffffff, 0, value);
  133. }
  134. static void hns_ppe_set_qid_mode(struct ppe_common_cb *ppe_common,
  135. enum ppe_qid_mode qid_mdoe)
  136. {
  137. dsaf_set_dev_field(ppe_common, PPE_COM_CFG_QID_MODE_REG,
  138. PPE_CFG_QID_MODE_CF_QID_MODE_M,
  139. PPE_CFG_QID_MODE_CF_QID_MODE_S, qid_mdoe);
  140. }
  141. /**
  142. * hns_ppe_set_qid - set ppe qid
  143. * @ppe_common: ppe common device
  144. * @qid: queue id
  145. */
  146. static void hns_ppe_set_qid(struct ppe_common_cb *ppe_common, u32 qid)
  147. {
  148. u32 qid_mod = dsaf_read_dev(ppe_common, PPE_COM_CFG_QID_MODE_REG);
  149. if (!dsaf_get_field(qid_mod, PPE_CFG_QID_MODE_DEF_QID_M,
  150. PPE_CFG_QID_MODE_DEF_QID_S)) {
  151. dsaf_set_field(qid_mod, PPE_CFG_QID_MODE_DEF_QID_M,
  152. PPE_CFG_QID_MODE_DEF_QID_S, qid);
  153. dsaf_write_dev(ppe_common, PPE_COM_CFG_QID_MODE_REG, qid_mod);
  154. }
  155. }
  156. /**
  157. * hns_ppe_set_port_mode - set port mode
  158. * @ppe_device: ppe device
  159. * @mode: port mode
  160. */
  161. static void hns_ppe_set_port_mode(struct hns_ppe_cb *ppe_cb,
  162. enum ppe_port_mode mode)
  163. {
  164. dsaf_write_dev(ppe_cb, PPE_CFG_XGE_MODE_REG, mode);
  165. }
  166. /**
  167. * hns_ppe_common_init_hw - init ppe common device
  168. * @ppe_common: ppe common device
  169. *
  170. * Return 0 on success, negative on failure
  171. */
  172. static int hns_ppe_common_init_hw(struct ppe_common_cb *ppe_common)
  173. {
  174. enum ppe_qid_mode qid_mode;
  175. struct dsaf_device *dsaf_dev = ppe_common->dsaf_dev;
  176. enum dsaf_mode dsaf_mode = dsaf_dev->dsaf_mode;
  177. dsaf_dev->misc_op->ppe_comm_srst(dsaf_dev, 0);
  178. msleep(100);
  179. dsaf_dev->misc_op->ppe_comm_srst(dsaf_dev, 1);
  180. msleep(100);
  181. if (ppe_common->ppe_mode == PPE_COMMON_MODE_SERVICE) {
  182. switch (dsaf_mode) {
  183. case DSAF_MODE_ENABLE_FIX:
  184. case DSAF_MODE_DISABLE_FIX:
  185. qid_mode = PPE_QID_MODE0;
  186. hns_ppe_set_qid(ppe_common, 0);
  187. break;
  188. case DSAF_MODE_ENABLE_0VM:
  189. case DSAF_MODE_DISABLE_2PORT_64VM:
  190. qid_mode = PPE_QID_MODE3;
  191. break;
  192. case DSAF_MODE_ENABLE_8VM:
  193. case DSAF_MODE_DISABLE_2PORT_16VM:
  194. qid_mode = PPE_QID_MODE4;
  195. break;
  196. case DSAF_MODE_ENABLE_16VM:
  197. case DSAF_MODE_DISABLE_6PORT_0VM:
  198. qid_mode = PPE_QID_MODE5;
  199. break;
  200. case DSAF_MODE_ENABLE_32VM:
  201. case DSAF_MODE_DISABLE_6PORT_16VM:
  202. qid_mode = PPE_QID_MODE2;
  203. break;
  204. case DSAF_MODE_ENABLE_128VM:
  205. case DSAF_MODE_DISABLE_6PORT_4VM:
  206. qid_mode = PPE_QID_MODE1;
  207. break;
  208. case DSAF_MODE_DISABLE_2PORT_8VM:
  209. qid_mode = PPE_QID_MODE7;
  210. break;
  211. case DSAF_MODE_DISABLE_6PORT_2VM:
  212. qid_mode = PPE_QID_MODE6;
  213. break;
  214. default:
  215. dev_err(ppe_common->dev,
  216. "get ppe queue mode failed! dsaf_mode=%d\n",
  217. dsaf_mode);
  218. return -EINVAL;
  219. }
  220. hns_ppe_set_qid_mode(ppe_common, qid_mode);
  221. }
  222. dsaf_set_dev_bit(ppe_common, PPE_COM_COMMON_CNT_CLR_CE_REG,
  223. PPE_COMMON_CNT_CLR_CE_B, 1);
  224. return 0;
  225. }
  226. /*clr ppe exception irq*/
  227. static void hns_ppe_exc_irq_en(struct hns_ppe_cb *ppe_cb, int en)
  228. {
  229. u32 clr_vlue = 0xfffffffful;
  230. u32 msk_vlue = en ? 0xfffffffful : 0; /*1 is en, 0 is dis*/
  231. u32 vld_msk = 0;
  232. /*only care bit 0,1,7*/
  233. dsaf_set_bit(vld_msk, 0, 1);
  234. dsaf_set_bit(vld_msk, 1, 1);
  235. dsaf_set_bit(vld_msk, 7, 1);
  236. /*clr sts**/
  237. dsaf_write_dev(ppe_cb, PPE_RINT_REG, clr_vlue);
  238. /*for some reserved bits, so set 0**/
  239. dsaf_write_dev(ppe_cb, PPE_INTEN_REG, msk_vlue & vld_msk);
  240. }
  241. int hns_ppe_wait_tx_fifo_clean(struct hns_ppe_cb *ppe_cb)
  242. {
  243. int wait_cnt;
  244. u32 val;
  245. wait_cnt = 0;
  246. while (wait_cnt++ < HNS_MAX_WAIT_CNT) {
  247. val = dsaf_read_dev(ppe_cb, PPE_CURR_TX_FIFO0_REG) & 0x3ffU;
  248. if (!val)
  249. break;
  250. usleep_range(100, 200);
  251. }
  252. if (wait_cnt >= HNS_MAX_WAIT_CNT) {
  253. dev_err(ppe_cb->dev, "hns ppe tx fifo clean wait timeout, still has %u pkt.\n",
  254. val);
  255. return -EBUSY;
  256. }
  257. return 0;
  258. }
  259. /**
  260. * ppe_init_hw - init ppe
  261. * @ppe_cb: ppe device
  262. */
  263. static void hns_ppe_init_hw(struct hns_ppe_cb *ppe_cb)
  264. {
  265. struct ppe_common_cb *ppe_common_cb = ppe_cb->ppe_common_cb;
  266. u32 port = ppe_cb->index;
  267. struct dsaf_device *dsaf_dev = ppe_common_cb->dsaf_dev;
  268. int i;
  269. /* get default RSS key */
  270. netdev_rss_key_fill(ppe_cb->rss_key, HNS_PPEV2_RSS_KEY_SIZE);
  271. dsaf_dev->misc_op->ppe_srst(dsaf_dev, port, 0);
  272. mdelay(10);
  273. dsaf_dev->misc_op->ppe_srst(dsaf_dev, port, 1);
  274. /* clr and msk except irq*/
  275. hns_ppe_exc_irq_en(ppe_cb, 0);
  276. if (ppe_common_cb->ppe_mode == PPE_COMMON_MODE_DEBUG) {
  277. hns_ppe_set_port_mode(ppe_cb, PPE_MODE_GE);
  278. dsaf_write_dev(ppe_cb, PPE_CFG_PAUSE_IDLE_CNT_REG, 0);
  279. } else {
  280. hns_ppe_set_port_mode(ppe_cb, PPE_MODE_XGE);
  281. }
  282. hns_ppe_checksum_hw(ppe_cb, 0xffffffff);
  283. hns_ppe_cnt_clr_ce(ppe_cb);
  284. if (!AE_IS_VER1(dsaf_dev->dsaf_ver)) {
  285. hns_ppe_set_vlan_strip(ppe_cb, 0);
  286. dsaf_write_dev(ppe_cb, PPE_CFG_MAX_FRAME_LEN_REG,
  287. HNS_PPEV2_MAX_FRAME_LEN);
  288. /* set default RSS key in h/w */
  289. hns_ppe_set_rss_key(ppe_cb, ppe_cb->rss_key);
  290. /* Set default indrection table in h/w */
  291. for (i = 0; i < HNS_PPEV2_RSS_IND_TBL_SIZE; i++)
  292. ppe_cb->rss_indir_table[i] = i;
  293. hns_ppe_set_indir_table(ppe_cb, ppe_cb->rss_indir_table);
  294. }
  295. }
  296. /**
  297. * ppe_uninit_hw - uninit ppe
  298. * @ppe_device: ppe device
  299. */
  300. static void hns_ppe_uninit_hw(struct hns_ppe_cb *ppe_cb)
  301. {
  302. u32 port;
  303. if (ppe_cb->ppe_common_cb) {
  304. struct dsaf_device *dsaf_dev = ppe_cb->ppe_common_cb->dsaf_dev;
  305. port = ppe_cb->index;
  306. dsaf_dev->misc_op->ppe_srst(dsaf_dev, port, 0);
  307. }
  308. }
  309. static void hns_ppe_uninit_ex(struct ppe_common_cb *ppe_common)
  310. {
  311. u32 i;
  312. for (i = 0; i < ppe_common->ppe_num; i++) {
  313. if (ppe_common->dsaf_dev->mac_cb[i])
  314. hns_ppe_uninit_hw(&ppe_common->ppe_cb[i]);
  315. memset(&ppe_common->ppe_cb[i], 0, sizeof(struct hns_ppe_cb));
  316. }
  317. }
  318. void hns_ppe_uninit(struct dsaf_device *dsaf_dev)
  319. {
  320. u32 i;
  321. for (i = 0; i < HNS_PPE_COM_NUM; i++) {
  322. if (dsaf_dev->ppe_common[i])
  323. hns_ppe_uninit_ex(dsaf_dev->ppe_common[i]);
  324. hns_rcb_common_free_cfg(dsaf_dev, i);
  325. hns_ppe_common_free_cfg(dsaf_dev, i);
  326. }
  327. }
  328. /**
  329. * hns_ppe_reset - reinit ppe/rcb hw
  330. * @dsaf_dev: dasf device
  331. * retuen void
  332. */
  333. void hns_ppe_reset_common(struct dsaf_device *dsaf_dev, u8 ppe_common_index)
  334. {
  335. u32 i;
  336. int ret;
  337. struct ppe_common_cb *ppe_common;
  338. ppe_common = dsaf_dev->ppe_common[ppe_common_index];
  339. ret = hns_ppe_common_init_hw(ppe_common);
  340. if (ret)
  341. return;
  342. for (i = 0; i < ppe_common->ppe_num; i++) {
  343. /* We only need to initiate ppe when the port exists */
  344. if (dsaf_dev->mac_cb[i])
  345. hns_ppe_init_hw(&ppe_common->ppe_cb[i]);
  346. }
  347. ret = hns_rcb_common_init_hw(dsaf_dev->rcb_common[ppe_common_index]);
  348. if (ret)
  349. return;
  350. hns_rcb_common_init_commit_hw(dsaf_dev->rcb_common[ppe_common_index]);
  351. }
  352. void hns_ppe_update_stats(struct hns_ppe_cb *ppe_cb)
  353. {
  354. struct hns_ppe_hw_stats *hw_stats = &ppe_cb->hw_stats;
  355. hw_stats->rx_pkts_from_sw
  356. += dsaf_read_dev(ppe_cb, PPE_HIS_RX_SW_PKT_CNT_REG);
  357. hw_stats->rx_pkts
  358. += dsaf_read_dev(ppe_cb, PPE_HIS_RX_WR_BD_OK_PKT_CNT_REG);
  359. hw_stats->rx_drop_no_bd
  360. += dsaf_read_dev(ppe_cb, PPE_HIS_RX_PKT_NO_BUF_CNT_REG);
  361. hw_stats->rx_alloc_buf_fail
  362. += dsaf_read_dev(ppe_cb, PPE_HIS_RX_APP_BUF_FAIL_CNT_REG);
  363. hw_stats->rx_alloc_buf_wait
  364. += dsaf_read_dev(ppe_cb, PPE_HIS_RX_APP_BUF_WAIT_CNT_REG);
  365. hw_stats->rx_drop_no_buf
  366. += dsaf_read_dev(ppe_cb, PPE_HIS_RX_PKT_DROP_FUL_CNT_REG);
  367. hw_stats->rx_err_fifo_full
  368. += dsaf_read_dev(ppe_cb, PPE_HIS_RX_PKT_DROP_PRT_CNT_REG);
  369. hw_stats->tx_bd_form_rcb
  370. += dsaf_read_dev(ppe_cb, PPE_HIS_TX_BD_CNT_REG);
  371. hw_stats->tx_pkts_from_rcb
  372. += dsaf_read_dev(ppe_cb, PPE_HIS_TX_PKT_CNT_REG);
  373. hw_stats->tx_pkts
  374. += dsaf_read_dev(ppe_cb, PPE_HIS_TX_PKT_OK_CNT_REG);
  375. hw_stats->tx_err_fifo_empty
  376. += dsaf_read_dev(ppe_cb, PPE_HIS_TX_PKT_EPT_CNT_REG);
  377. hw_stats->tx_err_checksum
  378. += dsaf_read_dev(ppe_cb, PPE_HIS_TX_PKT_CS_FAIL_CNT_REG);
  379. }
  380. int hns_ppe_get_sset_count(int stringset)
  381. {
  382. if (stringset == ETH_SS_STATS)
  383. return ETH_PPE_STATIC_NUM;
  384. return 0;
  385. }
  386. int hns_ppe_get_regs_count(void)
  387. {
  388. return ETH_PPE_DUMP_NUM;
  389. }
  390. /**
  391. * ppe_get_strings - get ppe srting
  392. * @ppe_device: ppe device
  393. * @stringset: string set type
  394. * @data: output string
  395. */
  396. void hns_ppe_get_strings(struct hns_ppe_cb *ppe_cb, int stringset, u8 *data)
  397. {
  398. char *buff = (char *)data;
  399. int index = ppe_cb->index;
  400. snprintf(buff, ETH_GSTRING_LEN, "ppe%d_rx_sw_pkt", index);
  401. buff = buff + ETH_GSTRING_LEN;
  402. snprintf(buff, ETH_GSTRING_LEN, "ppe%d_rx_pkt_ok", index);
  403. buff = buff + ETH_GSTRING_LEN;
  404. snprintf(buff, ETH_GSTRING_LEN, "ppe%d_rx_drop_pkt_no_bd", index);
  405. buff = buff + ETH_GSTRING_LEN;
  406. snprintf(buff, ETH_GSTRING_LEN, "ppe%d_rx_alloc_buf_fail", index);
  407. buff = buff + ETH_GSTRING_LEN;
  408. snprintf(buff, ETH_GSTRING_LEN, "ppe%d_rx_alloc_buf_wait", index);
  409. buff = buff + ETH_GSTRING_LEN;
  410. snprintf(buff, ETH_GSTRING_LEN, "ppe%d_rx_pkt_drop_no_buf", index);
  411. buff = buff + ETH_GSTRING_LEN;
  412. snprintf(buff, ETH_GSTRING_LEN, "ppe%d_rx_pkt_err_fifo_full", index);
  413. buff = buff + ETH_GSTRING_LEN;
  414. snprintf(buff, ETH_GSTRING_LEN, "ppe%d_tx_bd", index);
  415. buff = buff + ETH_GSTRING_LEN;
  416. snprintf(buff, ETH_GSTRING_LEN, "ppe%d_tx_pkt", index);
  417. buff = buff + ETH_GSTRING_LEN;
  418. snprintf(buff, ETH_GSTRING_LEN, "ppe%d_tx_pkt_ok", index);
  419. buff = buff + ETH_GSTRING_LEN;
  420. snprintf(buff, ETH_GSTRING_LEN, "ppe%d_tx_pkt_err_fifo_empty", index);
  421. buff = buff + ETH_GSTRING_LEN;
  422. snprintf(buff, ETH_GSTRING_LEN, "ppe%d_tx_pkt_err_csum_fail", index);
  423. }
  424. void hns_ppe_get_stats(struct hns_ppe_cb *ppe_cb, u64 *data)
  425. {
  426. u64 *regs_buff = data;
  427. struct hns_ppe_hw_stats *hw_stats = &ppe_cb->hw_stats;
  428. regs_buff[0] = hw_stats->rx_pkts_from_sw;
  429. regs_buff[1] = hw_stats->rx_pkts;
  430. regs_buff[2] = hw_stats->rx_drop_no_bd;
  431. regs_buff[3] = hw_stats->rx_alloc_buf_fail;
  432. regs_buff[4] = hw_stats->rx_alloc_buf_wait;
  433. regs_buff[5] = hw_stats->rx_drop_no_buf;
  434. regs_buff[6] = hw_stats->rx_err_fifo_full;
  435. regs_buff[7] = hw_stats->tx_bd_form_rcb;
  436. regs_buff[8] = hw_stats->tx_pkts_from_rcb;
  437. regs_buff[9] = hw_stats->tx_pkts;
  438. regs_buff[10] = hw_stats->tx_err_fifo_empty;
  439. regs_buff[11] = hw_stats->tx_err_checksum;
  440. }
  441. /**
  442. * hns_ppe_init - init ppe device
  443. * @dsaf_dev: dasf device
  444. * retuen 0 - success , negative --fail
  445. */
  446. int hns_ppe_init(struct dsaf_device *dsaf_dev)
  447. {
  448. int ret;
  449. int i;
  450. for (i = 0; i < HNS_PPE_COM_NUM; i++) {
  451. ret = hns_ppe_common_get_cfg(dsaf_dev, i);
  452. if (ret)
  453. goto get_cfg_fail;
  454. ret = hns_rcb_common_get_cfg(dsaf_dev, i);
  455. if (ret)
  456. goto get_cfg_fail;
  457. hns_ppe_get_cfg(dsaf_dev->ppe_common[i]);
  458. ret = hns_rcb_get_cfg(dsaf_dev->rcb_common[i]);
  459. if (ret)
  460. goto get_cfg_fail;
  461. }
  462. for (i = 0; i < HNS_PPE_COM_NUM; i++)
  463. hns_ppe_reset_common(dsaf_dev, i);
  464. return 0;
  465. get_cfg_fail:
  466. for (i = 0; i < HNS_PPE_COM_NUM; i++) {
  467. hns_rcb_common_free_cfg(dsaf_dev, i);
  468. hns_ppe_common_free_cfg(dsaf_dev, i);
  469. }
  470. return ret;
  471. }
  472. void hns_ppe_get_regs(struct hns_ppe_cb *ppe_cb, void *data)
  473. {
  474. struct ppe_common_cb *ppe_common = ppe_cb->ppe_common_cb;
  475. u32 *regs = data;
  476. u32 i;
  477. u32 offset;
  478. /* ppe common registers */
  479. regs[0] = dsaf_read_dev(ppe_common, PPE_COM_CFG_QID_MODE_REG);
  480. regs[1] = dsaf_read_dev(ppe_common, PPE_COM_INTEN_REG);
  481. regs[2] = dsaf_read_dev(ppe_common, PPE_COM_RINT_REG);
  482. regs[3] = dsaf_read_dev(ppe_common, PPE_COM_INTSTS_REG);
  483. regs[4] = dsaf_read_dev(ppe_common, PPE_COM_COMMON_CNT_CLR_CE_REG);
  484. for (i = 0; i < DSAF_TOTAL_QUEUE_NUM; i++) {
  485. offset = PPE_COM_HIS_RX_PKT_QID_DROP_CNT_REG + 0x4 * i;
  486. regs[5 + i] = dsaf_read_dev(ppe_common, offset);
  487. offset = PPE_COM_HIS_RX_PKT_QID_OK_CNT_REG + 0x4 * i;
  488. regs[5 + i + DSAF_TOTAL_QUEUE_NUM]
  489. = dsaf_read_dev(ppe_common, offset);
  490. offset = PPE_COM_HIS_TX_PKT_QID_ERR_CNT_REG + 0x4 * i;
  491. regs[5 + i + DSAF_TOTAL_QUEUE_NUM * 2]
  492. = dsaf_read_dev(ppe_common, offset);
  493. offset = PPE_COM_HIS_TX_PKT_QID_OK_CNT_REG + 0x4 * i;
  494. regs[5 + i + DSAF_TOTAL_QUEUE_NUM * 3]
  495. = dsaf_read_dev(ppe_common, offset);
  496. }
  497. /* mark end of ppe regs */
  498. for (i = 521; i < 524; i++)
  499. regs[i] = 0xeeeeeeee;
  500. /* ppe channel registers */
  501. regs[525] = dsaf_read_dev(ppe_cb, PPE_CFG_TX_FIFO_THRSLD_REG);
  502. regs[526] = dsaf_read_dev(ppe_cb, PPE_CFG_RX_FIFO_THRSLD_REG);
  503. regs[527] = dsaf_read_dev(ppe_cb, PPE_CFG_RX_FIFO_PAUSE_THRSLD_REG);
  504. regs[528] = dsaf_read_dev(ppe_cb, PPE_CFG_RX_FIFO_SW_BP_THRSLD_REG);
  505. regs[529] = dsaf_read_dev(ppe_cb, PPE_CFG_PAUSE_IDLE_CNT_REG);
  506. regs[530] = dsaf_read_dev(ppe_cb, PPE_CFG_BUS_CTRL_REG);
  507. regs[531] = dsaf_read_dev(ppe_cb, PPE_CFG_TNL_TO_BE_RST_REG);
  508. regs[532] = dsaf_read_dev(ppe_cb, PPE_CURR_TNL_CAN_RST_REG);
  509. regs[533] = dsaf_read_dev(ppe_cb, PPE_CFG_XGE_MODE_REG);
  510. regs[534] = dsaf_read_dev(ppe_cb, PPE_CFG_MAX_FRAME_LEN_REG);
  511. regs[535] = dsaf_read_dev(ppe_cb, PPE_CFG_RX_PKT_MODE_REG);
  512. regs[536] = dsaf_read_dev(ppe_cb, PPE_CFG_RX_VLAN_TAG_REG);
  513. regs[537] = dsaf_read_dev(ppe_cb, PPE_CFG_TAG_GEN_REG);
  514. regs[538] = dsaf_read_dev(ppe_cb, PPE_CFG_PARSE_TAG_REG);
  515. regs[539] = dsaf_read_dev(ppe_cb, PPE_CFG_PRO_CHECK_EN_REG);
  516. regs[540] = dsaf_read_dev(ppe_cb, PPE_INTEN_REG);
  517. regs[541] = dsaf_read_dev(ppe_cb, PPE_RINT_REG);
  518. regs[542] = dsaf_read_dev(ppe_cb, PPE_INTSTS_REG);
  519. regs[543] = dsaf_read_dev(ppe_cb, PPE_CFG_RX_PKT_INT_REG);
  520. regs[544] = dsaf_read_dev(ppe_cb, PPE_CFG_HEAT_DECT_TIME0_REG);
  521. regs[545] = dsaf_read_dev(ppe_cb, PPE_CFG_HEAT_DECT_TIME1_REG);
  522. /* ppe static */
  523. regs[546] = dsaf_read_dev(ppe_cb, PPE_HIS_RX_SW_PKT_CNT_REG);
  524. regs[547] = dsaf_read_dev(ppe_cb, PPE_HIS_RX_WR_BD_OK_PKT_CNT_REG);
  525. regs[548] = dsaf_read_dev(ppe_cb, PPE_HIS_RX_PKT_NO_BUF_CNT_REG);
  526. regs[549] = dsaf_read_dev(ppe_cb, PPE_HIS_TX_BD_CNT_REG);
  527. regs[550] = dsaf_read_dev(ppe_cb, PPE_HIS_TX_PKT_CNT_REG);
  528. regs[551] = dsaf_read_dev(ppe_cb, PPE_HIS_TX_PKT_OK_CNT_REG);
  529. regs[552] = dsaf_read_dev(ppe_cb, PPE_HIS_TX_PKT_EPT_CNT_REG);
  530. regs[553] = dsaf_read_dev(ppe_cb, PPE_HIS_TX_PKT_CS_FAIL_CNT_REG);
  531. regs[554] = dsaf_read_dev(ppe_cb, PPE_HIS_RX_APP_BUF_FAIL_CNT_REG);
  532. regs[555] = dsaf_read_dev(ppe_cb, PPE_HIS_RX_APP_BUF_WAIT_CNT_REG);
  533. regs[556] = dsaf_read_dev(ppe_cb, PPE_HIS_RX_PKT_DROP_FUL_CNT_REG);
  534. regs[557] = dsaf_read_dev(ppe_cb, PPE_HIS_RX_PKT_DROP_PRT_CNT_REG);
  535. regs[558] = dsaf_read_dev(ppe_cb, PPE_TNL_0_5_CNT_CLR_CE_REG);
  536. regs[559] = dsaf_read_dev(ppe_cb, PPE_CFG_AXI_DBG_REG);
  537. regs[560] = dsaf_read_dev(ppe_cb, PPE_HIS_PRO_ERR_REG);
  538. regs[561] = dsaf_read_dev(ppe_cb, PPE_HIS_TNL_FIFO_ERR_REG);
  539. regs[562] = dsaf_read_dev(ppe_cb, PPE_CURR_CFF_DATA_NUM_REG);
  540. regs[563] = dsaf_read_dev(ppe_cb, PPE_CURR_RX_ST_REG);
  541. regs[564] = dsaf_read_dev(ppe_cb, PPE_CURR_TX_ST_REG);
  542. regs[565] = dsaf_read_dev(ppe_cb, PPE_CURR_RX_FIFO0_REG);
  543. regs[566] = dsaf_read_dev(ppe_cb, PPE_CURR_RX_FIFO1_REG);
  544. regs[567] = dsaf_read_dev(ppe_cb, PPE_CURR_TX_FIFO0_REG);
  545. regs[568] = dsaf_read_dev(ppe_cb, PPE_CURR_TX_FIFO1_REG);
  546. regs[569] = dsaf_read_dev(ppe_cb, PPE_ECO0_REG);
  547. regs[570] = dsaf_read_dev(ppe_cb, PPE_ECO1_REG);
  548. regs[571] = dsaf_read_dev(ppe_cb, PPE_ECO2_REG);
  549. /* mark end of ppe regs */
  550. for (i = 572; i < 576; i++)
  551. regs[i] = 0xeeeeeeee;
  552. }