hns_dsaf_rcb.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  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/cdev.h>
  10. #include <linux/module.h>
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/netdevice.h>
  14. #include <linux/etherdevice.h>
  15. #include <asm/cacheflush.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/of.h>
  18. #include <linux/of_address.h>
  19. #include <linux/of_platform.h>
  20. #include <linux/of_irq.h>
  21. #include <linux/spinlock.h>
  22. #include "hns_dsaf_main.h"
  23. #include "hns_dsaf_ppe.h"
  24. #include "hns_dsaf_rcb.h"
  25. #define RCB_COMMON_REG_OFFSET 0x80000
  26. #define TX_RING 0
  27. #define RX_RING 1
  28. #define RCB_RESET_WAIT_TIMES 30
  29. #define RCB_RESET_TRY_TIMES 10
  30. /* Because default mtu is 1500, rcb buffer size is set to 2048 enough */
  31. #define RCB_DEFAULT_BUFFER_SIZE 2048
  32. /**
  33. *hns_rcb_wait_fbd_clean - clean fbd
  34. *@qs: ring struct pointer array
  35. *@qnum: num of array
  36. *@flag: tx or rx flag
  37. */
  38. void hns_rcb_wait_fbd_clean(struct hnae_queue **qs, int q_num, u32 flag)
  39. {
  40. int i, wait_cnt;
  41. u32 fbd_num;
  42. for (wait_cnt = i = 0; i < q_num; wait_cnt++) {
  43. usleep_range(200, 300);
  44. fbd_num = 0;
  45. if (flag & RCB_INT_FLAG_TX)
  46. fbd_num += dsaf_read_dev(qs[i],
  47. RCB_RING_TX_RING_FBDNUM_REG);
  48. if (flag & RCB_INT_FLAG_RX)
  49. fbd_num += dsaf_read_dev(qs[i],
  50. RCB_RING_RX_RING_FBDNUM_REG);
  51. if (!fbd_num)
  52. i++;
  53. if (wait_cnt >= 10000)
  54. break;
  55. }
  56. if (i < q_num)
  57. dev_err(qs[i]->handle->owner_dev,
  58. "queue(%d) wait fbd(%d) clean fail!!\n", i, fbd_num);
  59. }
  60. int hns_rcb_wait_tx_ring_clean(struct hnae_queue *qs)
  61. {
  62. u32 head, tail;
  63. int wait_cnt;
  64. tail = dsaf_read_dev(&qs->tx_ring, RCB_REG_TAIL);
  65. wait_cnt = 0;
  66. while (wait_cnt++ < HNS_MAX_WAIT_CNT) {
  67. head = dsaf_read_dev(&qs->tx_ring, RCB_REG_HEAD);
  68. if (tail == head)
  69. break;
  70. usleep_range(100, 200);
  71. }
  72. if (wait_cnt >= HNS_MAX_WAIT_CNT) {
  73. dev_err(qs->dev->dev, "rcb wait timeout, head not equal to tail.\n");
  74. return -EBUSY;
  75. }
  76. return 0;
  77. }
  78. /**
  79. *hns_rcb_reset_ring_hw - ring reset
  80. *@q: ring struct pointer
  81. */
  82. void hns_rcb_reset_ring_hw(struct hnae_queue *q)
  83. {
  84. u32 wait_cnt;
  85. u32 try_cnt = 0;
  86. u32 could_ret;
  87. u32 tx_fbd_num;
  88. while (try_cnt++ < RCB_RESET_TRY_TIMES) {
  89. usleep_range(100, 200);
  90. tx_fbd_num = dsaf_read_dev(q, RCB_RING_TX_RING_FBDNUM_REG);
  91. if (tx_fbd_num)
  92. continue;
  93. dsaf_write_dev(q, RCB_RING_PREFETCH_EN_REG, 0);
  94. dsaf_write_dev(q, RCB_RING_T0_BE_RST, 1);
  95. msleep(20);
  96. could_ret = dsaf_read_dev(q, RCB_RING_COULD_BE_RST);
  97. wait_cnt = 0;
  98. while (!could_ret && (wait_cnt < RCB_RESET_WAIT_TIMES)) {
  99. dsaf_write_dev(q, RCB_RING_T0_BE_RST, 0);
  100. dsaf_write_dev(q, RCB_RING_T0_BE_RST, 1);
  101. msleep(20);
  102. could_ret = dsaf_read_dev(q, RCB_RING_COULD_BE_RST);
  103. wait_cnt++;
  104. }
  105. dsaf_write_dev(q, RCB_RING_T0_BE_RST, 0);
  106. if (could_ret)
  107. break;
  108. }
  109. if (try_cnt >= RCB_RESET_TRY_TIMES)
  110. dev_err(q->dev->dev, "port%d reset ring fail\n",
  111. hns_ae_get_vf_cb(q->handle)->port_index);
  112. }
  113. /**
  114. *hns_rcb_int_ctrl_hw - rcb irq enable control
  115. *@q: hnae queue struct pointer
  116. *@flag:ring flag tx or rx
  117. *@mask:mask
  118. */
  119. void hns_rcb_int_ctrl_hw(struct hnae_queue *q, u32 flag, u32 mask)
  120. {
  121. u32 int_mask_en = !!mask;
  122. if (flag & RCB_INT_FLAG_TX) {
  123. dsaf_write_dev(q, RCB_RING_INTMSK_TXWL_REG, int_mask_en);
  124. dsaf_write_dev(q, RCB_RING_INTMSK_TX_OVERTIME_REG,
  125. int_mask_en);
  126. }
  127. if (flag & RCB_INT_FLAG_RX) {
  128. dsaf_write_dev(q, RCB_RING_INTMSK_RXWL_REG, int_mask_en);
  129. dsaf_write_dev(q, RCB_RING_INTMSK_RX_OVERTIME_REG,
  130. int_mask_en);
  131. }
  132. }
  133. void hns_rcb_int_clr_hw(struct hnae_queue *q, u32 flag)
  134. {
  135. if (flag & RCB_INT_FLAG_TX) {
  136. dsaf_write_dev(q, RCB_RING_INTSTS_TX_RING_REG, 1);
  137. dsaf_write_dev(q, RCB_RING_INTSTS_TX_OVERTIME_REG, 1);
  138. }
  139. if (flag & RCB_INT_FLAG_RX) {
  140. dsaf_write_dev(q, RCB_RING_INTSTS_RX_RING_REG, 1);
  141. dsaf_write_dev(q, RCB_RING_INTSTS_RX_OVERTIME_REG, 1);
  142. }
  143. }
  144. void hns_rcbv2_int_ctrl_hw(struct hnae_queue *q, u32 flag, u32 mask)
  145. {
  146. u32 int_mask_en = !!mask;
  147. if (flag & RCB_INT_FLAG_TX)
  148. dsaf_write_dev(q, RCB_RING_INTMSK_TXWL_REG, int_mask_en);
  149. if (flag & RCB_INT_FLAG_RX)
  150. dsaf_write_dev(q, RCB_RING_INTMSK_RXWL_REG, int_mask_en);
  151. }
  152. void hns_rcbv2_int_clr_hw(struct hnae_queue *q, u32 flag)
  153. {
  154. if (flag & RCB_INT_FLAG_TX)
  155. dsaf_write_dev(q, RCBV2_TX_RING_INT_STS_REG, 1);
  156. if (flag & RCB_INT_FLAG_RX)
  157. dsaf_write_dev(q, RCBV2_RX_RING_INT_STS_REG, 1);
  158. }
  159. /**
  160. *hns_rcb_ring_enable_hw - enable ring
  161. *@ring: rcb ring
  162. */
  163. void hns_rcb_ring_enable_hw(struct hnae_queue *q, u32 val)
  164. {
  165. dsaf_write_dev(q, RCB_RING_PREFETCH_EN_REG, !!val);
  166. }
  167. void hns_rcb_start(struct hnae_queue *q, u32 val)
  168. {
  169. hns_rcb_ring_enable_hw(q, val);
  170. }
  171. /**
  172. *hns_rcb_common_init_commit_hw - make rcb common init completed
  173. *@rcb_common: rcb common device
  174. */
  175. void hns_rcb_common_init_commit_hw(struct rcb_common_cb *rcb_common)
  176. {
  177. wmb(); /* Sync point before breakpoint */
  178. dsaf_write_dev(rcb_common, RCB_COM_CFG_SYS_FSH_REG, 1);
  179. wmb(); /* Sync point after breakpoint */
  180. }
  181. /* hns_rcb_set_tx_ring_bs - init rcb ring buf size regester
  182. *@q: hnae_queue
  183. *@buf_size: buffer size set to hw
  184. */
  185. void hns_rcb_set_tx_ring_bs(struct hnae_queue *q, u32 buf_size)
  186. {
  187. u32 bd_size_type = hns_rcb_buf_size2type(buf_size);
  188. dsaf_write_dev(q, RCB_RING_TX_RING_BD_LEN_REG,
  189. bd_size_type);
  190. }
  191. /* hns_rcb_set_rx_ring_bs - init rcb ring buf size regester
  192. *@q: hnae_queue
  193. *@buf_size: buffer size set to hw
  194. */
  195. void hns_rcb_set_rx_ring_bs(struct hnae_queue *q, u32 buf_size)
  196. {
  197. u32 bd_size_type = hns_rcb_buf_size2type(buf_size);
  198. dsaf_write_dev(q, RCB_RING_RX_RING_BD_LEN_REG,
  199. bd_size_type);
  200. }
  201. /**
  202. *hns_rcb_ring_init - init rcb ring
  203. *@ring_pair: ring pair control block
  204. *@ring_type: ring type, RX_RING or TX_RING
  205. */
  206. static void hns_rcb_ring_init(struct ring_pair_cb *ring_pair, int ring_type)
  207. {
  208. struct hnae_queue *q = &ring_pair->q;
  209. struct hnae_ring *ring =
  210. (ring_type == RX_RING) ? &q->rx_ring : &q->tx_ring;
  211. dma_addr_t dma = ring->desc_dma_addr;
  212. if (ring_type == RX_RING) {
  213. dsaf_write_dev(q, RCB_RING_RX_RING_BASEADDR_L_REG,
  214. (u32)dma);
  215. dsaf_write_dev(q, RCB_RING_RX_RING_BASEADDR_H_REG,
  216. (u32)((dma >> 31) >> 1));
  217. hns_rcb_set_rx_ring_bs(q, ring->buf_size);
  218. dsaf_write_dev(q, RCB_RING_RX_RING_BD_NUM_REG,
  219. ring_pair->port_id_in_comm);
  220. dsaf_write_dev(q, RCB_RING_RX_RING_PKTLINE_REG,
  221. ring_pair->port_id_in_comm);
  222. } else {
  223. dsaf_write_dev(q, RCB_RING_TX_RING_BASEADDR_L_REG,
  224. (u32)dma);
  225. dsaf_write_dev(q, RCB_RING_TX_RING_BASEADDR_H_REG,
  226. (u32)((dma >> 31) >> 1));
  227. hns_rcb_set_tx_ring_bs(q, ring->buf_size);
  228. dsaf_write_dev(q, RCB_RING_TX_RING_BD_NUM_REG,
  229. ring_pair->port_id_in_comm);
  230. dsaf_write_dev(q, RCB_RING_TX_RING_PKTLINE_REG,
  231. ring_pair->port_id_in_comm + HNS_RCB_TX_PKTLINE_OFFSET);
  232. }
  233. }
  234. /**
  235. *hns_rcb_init_hw - init rcb hardware
  236. *@ring: rcb ring
  237. */
  238. void hns_rcb_init_hw(struct ring_pair_cb *ring)
  239. {
  240. hns_rcb_ring_init(ring, RX_RING);
  241. hns_rcb_ring_init(ring, TX_RING);
  242. }
  243. /**
  244. *hns_rcb_set_port_desc_cnt - set rcb port description num
  245. *@rcb_common: rcb_common device
  246. *@port_idx:port index
  247. *@desc_cnt:BD num
  248. */
  249. static void hns_rcb_set_port_desc_cnt(struct rcb_common_cb *rcb_common,
  250. u32 port_idx, u32 desc_cnt)
  251. {
  252. dsaf_write_dev(rcb_common, RCB_CFG_BD_NUM_REG + port_idx * 4,
  253. desc_cnt);
  254. }
  255. static void hns_rcb_set_port_timeout(
  256. struct rcb_common_cb *rcb_common, u32 port_idx, u32 timeout)
  257. {
  258. if (AE_IS_VER1(rcb_common->dsaf_dev->dsaf_ver)) {
  259. dsaf_write_dev(rcb_common, RCB_CFG_OVERTIME_REG,
  260. timeout * HNS_RCB_CLK_FREQ_MHZ);
  261. } else if (!HNS_DSAF_IS_DEBUG(rcb_common->dsaf_dev)) {
  262. if (timeout > HNS_RCB_DEF_GAP_TIME_USECS)
  263. dsaf_write_dev(rcb_common,
  264. RCB_PORT_INT_GAPTIME_REG + port_idx * 4,
  265. HNS_RCB_DEF_GAP_TIME_USECS);
  266. else
  267. dsaf_write_dev(rcb_common,
  268. RCB_PORT_INT_GAPTIME_REG + port_idx * 4,
  269. timeout);
  270. dsaf_write_dev(rcb_common,
  271. RCB_PORT_CFG_OVERTIME_REG + port_idx * 4,
  272. timeout);
  273. } else {
  274. dsaf_write_dev(rcb_common,
  275. RCB_PORT_CFG_OVERTIME_REG + port_idx * 4,
  276. timeout);
  277. }
  278. }
  279. static int hns_rcb_common_get_port_num(struct rcb_common_cb *rcb_common)
  280. {
  281. if (!HNS_DSAF_IS_DEBUG(rcb_common->dsaf_dev))
  282. return HNS_RCB_SERVICE_NW_ENGINE_NUM;
  283. else
  284. return HNS_RCB_DEBUG_NW_ENGINE_NUM;
  285. }
  286. /*clr rcb comm exception irq**/
  287. static void hns_rcb_comm_exc_irq_en(
  288. struct rcb_common_cb *rcb_common, int en)
  289. {
  290. u32 clr_vlue = 0xfffffffful;
  291. u32 msk_vlue = en ? 0 : 0xfffffffful;
  292. /* clr int*/
  293. dsaf_write_dev(rcb_common, RCB_COM_INTSTS_ECC_ERR_REG, clr_vlue);
  294. dsaf_write_dev(rcb_common, RCB_COM_SF_CFG_RING_STS, clr_vlue);
  295. dsaf_write_dev(rcb_common, RCB_COM_SF_CFG_BD_RINT_STS, clr_vlue);
  296. dsaf_write_dev(rcb_common, RCB_COM_RINT_TX_PKT_REG, clr_vlue);
  297. dsaf_write_dev(rcb_common, RCB_COM_AXI_ERR_STS, clr_vlue);
  298. /*en msk*/
  299. dsaf_write_dev(rcb_common, RCB_COM_INTMASK_ECC_ERR_REG, msk_vlue);
  300. dsaf_write_dev(rcb_common, RCB_COM_SF_CFG_INTMASK_RING, msk_vlue);
  301. /*for tx bd neednot cacheline, so msk sf_txring_fbd_intmask (bit 1)**/
  302. dsaf_write_dev(rcb_common, RCB_COM_SF_CFG_INTMASK_BD, msk_vlue | 2);
  303. dsaf_write_dev(rcb_common, RCB_COM_INTMSK_TX_PKT_REG, msk_vlue);
  304. dsaf_write_dev(rcb_common, RCB_COM_AXI_WR_ERR_INTMASK, msk_vlue);
  305. }
  306. /**
  307. *hns_rcb_common_init_hw - init rcb common hardware
  308. *@rcb_common: rcb_common device
  309. *retuen 0 - success , negative --fail
  310. */
  311. int hns_rcb_common_init_hw(struct rcb_common_cb *rcb_common)
  312. {
  313. u32 reg_val;
  314. int i;
  315. int port_num = hns_rcb_common_get_port_num(rcb_common);
  316. hns_rcb_comm_exc_irq_en(rcb_common, 0);
  317. reg_val = dsaf_read_dev(rcb_common, RCB_COM_CFG_INIT_FLAG_REG);
  318. if (0x1 != (reg_val & 0x1)) {
  319. dev_err(rcb_common->dsaf_dev->dev,
  320. "RCB_COM_CFG_INIT_FLAG_REG reg = 0x%x\n", reg_val);
  321. return -EBUSY;
  322. }
  323. for (i = 0; i < port_num; i++) {
  324. hns_rcb_set_port_desc_cnt(rcb_common, i, rcb_common->desc_num);
  325. hns_rcb_set_rx_coalesced_frames(
  326. rcb_common, i, HNS_RCB_DEF_RX_COALESCED_FRAMES);
  327. if (!AE_IS_VER1(rcb_common->dsaf_dev->dsaf_ver) &&
  328. !HNS_DSAF_IS_DEBUG(rcb_common->dsaf_dev))
  329. hns_rcb_set_tx_coalesced_frames(
  330. rcb_common, i, HNS_RCB_DEF_TX_COALESCED_FRAMES);
  331. hns_rcb_set_port_timeout(
  332. rcb_common, i, HNS_RCB_DEF_COALESCED_USECS);
  333. }
  334. dsaf_write_dev(rcb_common, RCB_COM_CFG_ENDIAN_REG,
  335. HNS_RCB_COMMON_ENDIAN);
  336. if (AE_IS_VER1(rcb_common->dsaf_dev->dsaf_ver)) {
  337. dsaf_write_dev(rcb_common, RCB_COM_CFG_FNA_REG, 0x0);
  338. dsaf_write_dev(rcb_common, RCB_COM_CFG_FA_REG, 0x1);
  339. } else {
  340. dsaf_set_dev_bit(rcb_common, RCBV2_COM_CFG_USER_REG,
  341. RCB_COM_CFG_FNA_B, false);
  342. dsaf_set_dev_bit(rcb_common, RCBV2_COM_CFG_USER_REG,
  343. RCB_COM_CFG_FA_B, true);
  344. dsaf_set_dev_bit(rcb_common, RCBV2_COM_CFG_TSO_MODE_REG,
  345. RCB_COM_TSO_MODE_B, HNS_TSO_MODE_8BD_32K);
  346. }
  347. return 0;
  348. }
  349. int hns_rcb_buf_size2type(u32 buf_size)
  350. {
  351. int bd_size_type;
  352. switch (buf_size) {
  353. case 512:
  354. bd_size_type = HNS_BD_SIZE_512_TYPE;
  355. break;
  356. case 1024:
  357. bd_size_type = HNS_BD_SIZE_1024_TYPE;
  358. break;
  359. case 2048:
  360. bd_size_type = HNS_BD_SIZE_2048_TYPE;
  361. break;
  362. case 4096:
  363. bd_size_type = HNS_BD_SIZE_4096_TYPE;
  364. break;
  365. default:
  366. bd_size_type = -EINVAL;
  367. }
  368. return bd_size_type;
  369. }
  370. static void hns_rcb_ring_get_cfg(struct hnae_queue *q, int ring_type)
  371. {
  372. struct hnae_ring *ring;
  373. struct rcb_common_cb *rcb_common;
  374. struct ring_pair_cb *ring_pair_cb;
  375. u16 desc_num, mdnum_ppkt;
  376. bool irq_idx, is_ver1;
  377. ring_pair_cb = container_of(q, struct ring_pair_cb, q);
  378. is_ver1 = AE_IS_VER1(ring_pair_cb->rcb_common->dsaf_dev->dsaf_ver);
  379. if (ring_type == RX_RING) {
  380. ring = &q->rx_ring;
  381. ring->io_base = ring_pair_cb->q.io_base;
  382. irq_idx = HNS_RCB_IRQ_IDX_RX;
  383. mdnum_ppkt = HNS_RCB_RING_MAX_BD_PER_PKT;
  384. } else {
  385. ring = &q->tx_ring;
  386. ring->io_base = (u8 __iomem *)ring_pair_cb->q.io_base +
  387. HNS_RCB_TX_REG_OFFSET;
  388. irq_idx = HNS_RCB_IRQ_IDX_TX;
  389. mdnum_ppkt = is_ver1 ? HNS_RCB_RING_MAX_TXBD_PER_PKT :
  390. HNS_RCBV2_RING_MAX_TXBD_PER_PKT;
  391. }
  392. rcb_common = ring_pair_cb->rcb_common;
  393. desc_num = rcb_common->dsaf_dev->desc_num;
  394. ring->desc = NULL;
  395. ring->desc_cb = NULL;
  396. ring->irq = ring_pair_cb->virq[irq_idx];
  397. ring->desc_dma_addr = 0;
  398. ring->buf_size = RCB_DEFAULT_BUFFER_SIZE;
  399. ring->desc_num = desc_num;
  400. ring->max_desc_num_per_pkt = mdnum_ppkt;
  401. ring->max_raw_data_sz_per_desc = HNS_RCB_MAX_PKT_SIZE;
  402. ring->max_pkt_size = HNS_RCB_MAX_PKT_SIZE;
  403. ring->next_to_use = 0;
  404. ring->next_to_clean = 0;
  405. }
  406. static void hns_rcb_ring_pair_get_cfg(struct ring_pair_cb *ring_pair_cb)
  407. {
  408. ring_pair_cb->q.handle = NULL;
  409. hns_rcb_ring_get_cfg(&ring_pair_cb->q, RX_RING);
  410. hns_rcb_ring_get_cfg(&ring_pair_cb->q, TX_RING);
  411. }
  412. static int hns_rcb_get_port_in_comm(
  413. struct rcb_common_cb *rcb_common, int ring_idx)
  414. {
  415. return ring_idx / (rcb_common->max_q_per_vf * rcb_common->max_vfn);
  416. }
  417. #define SERVICE_RING_IRQ_IDX(v1) \
  418. ((v1) ? HNS_SERVICE_RING_IRQ_IDX : HNSV2_SERVICE_RING_IRQ_IDX)
  419. static int hns_rcb_get_base_irq_idx(struct rcb_common_cb *rcb_common)
  420. {
  421. bool is_ver1 = AE_IS_VER1(rcb_common->dsaf_dev->dsaf_ver);
  422. if (!HNS_DSAF_IS_DEBUG(rcb_common->dsaf_dev))
  423. return SERVICE_RING_IRQ_IDX(is_ver1);
  424. else
  425. return HNS_DEBUG_RING_IRQ_IDX;
  426. }
  427. #define RCB_COMM_BASE_TO_RING_BASE(base, ringid)\
  428. ((base) + 0x10000 + HNS_RCB_REG_OFFSET * (ringid))
  429. /**
  430. *hns_rcb_get_cfg - get rcb config
  431. *@rcb_common: rcb common device
  432. */
  433. int hns_rcb_get_cfg(struct rcb_common_cb *rcb_common)
  434. {
  435. struct ring_pair_cb *ring_pair_cb;
  436. u32 i;
  437. u32 ring_num = rcb_common->ring_num;
  438. int base_irq_idx = hns_rcb_get_base_irq_idx(rcb_common);
  439. struct platform_device *pdev =
  440. to_platform_device(rcb_common->dsaf_dev->dev);
  441. bool is_ver1 = AE_IS_VER1(rcb_common->dsaf_dev->dsaf_ver);
  442. for (i = 0; i < ring_num; i++) {
  443. ring_pair_cb = &rcb_common->ring_pair_cb[i];
  444. ring_pair_cb->rcb_common = rcb_common;
  445. ring_pair_cb->dev = rcb_common->dsaf_dev->dev;
  446. ring_pair_cb->index = i;
  447. ring_pair_cb->q.io_base =
  448. RCB_COMM_BASE_TO_RING_BASE(rcb_common->io_base, i);
  449. ring_pair_cb->port_id_in_comm =
  450. hns_rcb_get_port_in_comm(rcb_common, i);
  451. ring_pair_cb->virq[HNS_RCB_IRQ_IDX_TX] =
  452. is_ver1 ? platform_get_irq(pdev, base_irq_idx + i * 2) :
  453. platform_get_irq(pdev, base_irq_idx + i * 3 + 1);
  454. ring_pair_cb->virq[HNS_RCB_IRQ_IDX_RX] =
  455. is_ver1 ? platform_get_irq(pdev, base_irq_idx + i * 2 + 1) :
  456. platform_get_irq(pdev, base_irq_idx + i * 3);
  457. if ((ring_pair_cb->virq[HNS_RCB_IRQ_IDX_TX] == -EPROBE_DEFER) ||
  458. (ring_pair_cb->virq[HNS_RCB_IRQ_IDX_RX] == -EPROBE_DEFER))
  459. return -EPROBE_DEFER;
  460. ring_pair_cb->q.phy_base =
  461. RCB_COMM_BASE_TO_RING_BASE(rcb_common->phy_base, i);
  462. hns_rcb_ring_pair_get_cfg(ring_pair_cb);
  463. }
  464. return 0;
  465. }
  466. /**
  467. *hns_rcb_get_rx_coalesced_frames - get rcb port rx coalesced frames
  468. *@rcb_common: rcb_common device
  469. *@port_idx:port id in comm
  470. *
  471. *Returns: coalesced_frames
  472. */
  473. u32 hns_rcb_get_rx_coalesced_frames(
  474. struct rcb_common_cb *rcb_common, u32 port_idx)
  475. {
  476. return dsaf_read_dev(rcb_common, RCB_CFG_PKTLINE_REG + port_idx * 4);
  477. }
  478. /**
  479. *hns_rcb_get_tx_coalesced_frames - get rcb port tx coalesced frames
  480. *@rcb_common: rcb_common device
  481. *@port_idx:port id in comm
  482. *
  483. *Returns: coalesced_frames
  484. */
  485. u32 hns_rcb_get_tx_coalesced_frames(
  486. struct rcb_common_cb *rcb_common, u32 port_idx)
  487. {
  488. u64 reg;
  489. reg = RCB_CFG_PKTLINE_REG + (port_idx + HNS_RCB_TX_PKTLINE_OFFSET) * 4;
  490. return dsaf_read_dev(rcb_common, reg);
  491. }
  492. /**
  493. *hns_rcb_get_coalesce_usecs - get rcb port coalesced time_out
  494. *@rcb_common: rcb_common device
  495. *@port_idx:port id in comm
  496. *
  497. *Returns: time_out
  498. */
  499. u32 hns_rcb_get_coalesce_usecs(
  500. struct rcb_common_cb *rcb_common, u32 port_idx)
  501. {
  502. if (AE_IS_VER1(rcb_common->dsaf_dev->dsaf_ver))
  503. return dsaf_read_dev(rcb_common, RCB_CFG_OVERTIME_REG) /
  504. HNS_RCB_CLK_FREQ_MHZ;
  505. else
  506. return dsaf_read_dev(rcb_common,
  507. RCB_PORT_CFG_OVERTIME_REG + port_idx * 4);
  508. }
  509. /**
  510. *hns_rcb_set_coalesce_usecs - set rcb port coalesced time_out
  511. *@rcb_common: rcb_common device
  512. *@port_idx:port id in comm
  513. *@timeout:tx/rx time for coalesced time_out
  514. *
  515. * Returns:
  516. * Zero for success, or an error code in case of failure
  517. */
  518. int hns_rcb_set_coalesce_usecs(
  519. struct rcb_common_cb *rcb_common, u32 port_idx, u32 timeout)
  520. {
  521. u32 old_timeout = hns_rcb_get_coalesce_usecs(rcb_common, port_idx);
  522. if (timeout == old_timeout)
  523. return 0;
  524. if (AE_IS_VER1(rcb_common->dsaf_dev->dsaf_ver)) {
  525. if (!HNS_DSAF_IS_DEBUG(rcb_common->dsaf_dev)) {
  526. dev_err(rcb_common->dsaf_dev->dev,
  527. "error: not support coalesce_usecs setting!\n");
  528. return -EINVAL;
  529. }
  530. }
  531. if (timeout > HNS_RCB_MAX_COALESCED_USECS || timeout == 0) {
  532. dev_err(rcb_common->dsaf_dev->dev,
  533. "error: coalesce_usecs setting supports 1~1023us\n");
  534. return -EINVAL;
  535. }
  536. hns_rcb_set_port_timeout(rcb_common, port_idx, timeout);
  537. return 0;
  538. }
  539. /**
  540. *hns_rcb_set_tx_coalesced_frames - set rcb coalesced frames
  541. *@rcb_common: rcb_common device
  542. *@port_idx:port id in comm
  543. *@coalesced_frames:tx/rx BD num for coalesced frames
  544. *
  545. * Returns:
  546. * Zero for success, or an error code in case of failure
  547. */
  548. int hns_rcb_set_tx_coalesced_frames(
  549. struct rcb_common_cb *rcb_common, u32 port_idx, u32 coalesced_frames)
  550. {
  551. u32 old_waterline =
  552. hns_rcb_get_tx_coalesced_frames(rcb_common, port_idx);
  553. u64 reg;
  554. if (coalesced_frames == old_waterline)
  555. return 0;
  556. if (coalesced_frames != 1) {
  557. dev_err(rcb_common->dsaf_dev->dev,
  558. "error: not support tx coalesce_frames setting!\n");
  559. return -EINVAL;
  560. }
  561. reg = RCB_CFG_PKTLINE_REG + (port_idx + HNS_RCB_TX_PKTLINE_OFFSET) * 4;
  562. dsaf_write_dev(rcb_common, reg, coalesced_frames);
  563. return 0;
  564. }
  565. /**
  566. *hns_rcb_set_rx_coalesced_frames - set rcb rx coalesced frames
  567. *@rcb_common: rcb_common device
  568. *@port_idx:port id in comm
  569. *@coalesced_frames:tx/rx BD num for coalesced frames
  570. *
  571. * Returns:
  572. * Zero for success, or an error code in case of failure
  573. */
  574. int hns_rcb_set_rx_coalesced_frames(
  575. struct rcb_common_cb *rcb_common, u32 port_idx, u32 coalesced_frames)
  576. {
  577. u32 old_waterline =
  578. hns_rcb_get_rx_coalesced_frames(rcb_common, port_idx);
  579. if (coalesced_frames == old_waterline)
  580. return 0;
  581. if (coalesced_frames >= rcb_common->desc_num ||
  582. coalesced_frames > HNS_RCB_MAX_COALESCED_FRAMES ||
  583. coalesced_frames < HNS_RCB_MIN_COALESCED_FRAMES) {
  584. dev_err(rcb_common->dsaf_dev->dev,
  585. "error: not support coalesce_frames setting!\n");
  586. return -EINVAL;
  587. }
  588. dsaf_write_dev(rcb_common, RCB_CFG_PKTLINE_REG + port_idx * 4,
  589. coalesced_frames);
  590. return 0;
  591. }
  592. /**
  593. *hns_rcb_get_queue_mode - get max VM number and max ring number per VM
  594. * accordding to dsaf mode
  595. *@dsaf_mode: dsaf mode
  596. *@max_vfn : max vfn number
  597. *@max_q_per_vf:max ring number per vm
  598. */
  599. void hns_rcb_get_queue_mode(enum dsaf_mode dsaf_mode, u16 *max_vfn,
  600. u16 *max_q_per_vf)
  601. {
  602. switch (dsaf_mode) {
  603. case DSAF_MODE_DISABLE_6PORT_0VM:
  604. *max_vfn = 1;
  605. *max_q_per_vf = 16;
  606. break;
  607. case DSAF_MODE_DISABLE_FIX:
  608. case DSAF_MODE_DISABLE_SP:
  609. *max_vfn = 1;
  610. *max_q_per_vf = 1;
  611. break;
  612. case DSAF_MODE_DISABLE_2PORT_64VM:
  613. *max_vfn = 64;
  614. *max_q_per_vf = 1;
  615. break;
  616. case DSAF_MODE_DISABLE_6PORT_16VM:
  617. *max_vfn = 16;
  618. *max_q_per_vf = 1;
  619. break;
  620. default:
  621. *max_vfn = 1;
  622. *max_q_per_vf = 16;
  623. break;
  624. }
  625. }
  626. static int hns_rcb_get_ring_num(struct dsaf_device *dsaf_dev)
  627. {
  628. switch (dsaf_dev->dsaf_mode) {
  629. case DSAF_MODE_ENABLE_FIX:
  630. case DSAF_MODE_DISABLE_SP:
  631. return 1;
  632. case DSAF_MODE_DISABLE_FIX:
  633. return 6;
  634. case DSAF_MODE_ENABLE_0VM:
  635. return 32;
  636. case DSAF_MODE_DISABLE_6PORT_0VM:
  637. case DSAF_MODE_ENABLE_16VM:
  638. case DSAF_MODE_DISABLE_6PORT_2VM:
  639. case DSAF_MODE_DISABLE_6PORT_16VM:
  640. case DSAF_MODE_DISABLE_6PORT_4VM:
  641. case DSAF_MODE_ENABLE_8VM:
  642. return 96;
  643. case DSAF_MODE_DISABLE_2PORT_16VM:
  644. case DSAF_MODE_DISABLE_2PORT_8VM:
  645. case DSAF_MODE_ENABLE_32VM:
  646. case DSAF_MODE_DISABLE_2PORT_64VM:
  647. case DSAF_MODE_ENABLE_128VM:
  648. return 128;
  649. default:
  650. dev_warn(dsaf_dev->dev,
  651. "get ring num fail,use default!dsaf_mode=%d\n",
  652. dsaf_dev->dsaf_mode);
  653. return 128;
  654. }
  655. }
  656. static void __iomem *hns_rcb_common_get_vaddr(struct rcb_common_cb *rcb_common)
  657. {
  658. struct dsaf_device *dsaf_dev = rcb_common->dsaf_dev;
  659. return dsaf_dev->ppe_base + RCB_COMMON_REG_OFFSET;
  660. }
  661. static phys_addr_t hns_rcb_common_get_paddr(struct rcb_common_cb *rcb_common)
  662. {
  663. struct dsaf_device *dsaf_dev = rcb_common->dsaf_dev;
  664. return dsaf_dev->ppe_paddr + RCB_COMMON_REG_OFFSET;
  665. }
  666. int hns_rcb_common_get_cfg(struct dsaf_device *dsaf_dev,
  667. int comm_index)
  668. {
  669. struct rcb_common_cb *rcb_common;
  670. enum dsaf_mode dsaf_mode = dsaf_dev->dsaf_mode;
  671. u16 max_vfn;
  672. u16 max_q_per_vf;
  673. int ring_num = hns_rcb_get_ring_num(dsaf_dev);
  674. rcb_common =
  675. devm_kzalloc(dsaf_dev->dev, sizeof(*rcb_common) +
  676. ring_num * sizeof(struct ring_pair_cb), GFP_KERNEL);
  677. if (!rcb_common) {
  678. dev_err(dsaf_dev->dev, "rcb common devm_kzalloc fail!\n");
  679. return -ENOMEM;
  680. }
  681. rcb_common->comm_index = comm_index;
  682. rcb_common->ring_num = ring_num;
  683. rcb_common->dsaf_dev = dsaf_dev;
  684. rcb_common->desc_num = dsaf_dev->desc_num;
  685. hns_rcb_get_queue_mode(dsaf_mode, &max_vfn, &max_q_per_vf);
  686. rcb_common->max_vfn = max_vfn;
  687. rcb_common->max_q_per_vf = max_q_per_vf;
  688. rcb_common->io_base = hns_rcb_common_get_vaddr(rcb_common);
  689. rcb_common->phy_base = hns_rcb_common_get_paddr(rcb_common);
  690. dsaf_dev->rcb_common[comm_index] = rcb_common;
  691. return 0;
  692. }
  693. void hns_rcb_common_free_cfg(struct dsaf_device *dsaf_dev,
  694. u32 comm_index)
  695. {
  696. dsaf_dev->rcb_common[comm_index] = NULL;
  697. }
  698. void hns_rcb_update_stats(struct hnae_queue *queue)
  699. {
  700. struct ring_pair_cb *ring =
  701. container_of(queue, struct ring_pair_cb, q);
  702. struct dsaf_device *dsaf_dev = ring->rcb_common->dsaf_dev;
  703. struct ppe_common_cb *ppe_common
  704. = dsaf_dev->ppe_common[ring->rcb_common->comm_index];
  705. struct hns_ring_hw_stats *hw_stats = &ring->hw_stats;
  706. hw_stats->rx_pkts += dsaf_read_dev(queue,
  707. RCB_RING_RX_RING_PKTNUM_RECORD_REG);
  708. dsaf_write_dev(queue, RCB_RING_RX_RING_PKTNUM_RECORD_REG, 0x1);
  709. hw_stats->ppe_rx_ok_pkts += dsaf_read_dev(ppe_common,
  710. PPE_COM_HIS_RX_PKT_QID_OK_CNT_REG + 4 * ring->index);
  711. hw_stats->ppe_rx_drop_pkts += dsaf_read_dev(ppe_common,
  712. PPE_COM_HIS_RX_PKT_QID_DROP_CNT_REG + 4 * ring->index);
  713. hw_stats->tx_pkts += dsaf_read_dev(queue,
  714. RCB_RING_TX_RING_PKTNUM_RECORD_REG);
  715. dsaf_write_dev(queue, RCB_RING_TX_RING_PKTNUM_RECORD_REG, 0x1);
  716. hw_stats->ppe_tx_ok_pkts += dsaf_read_dev(ppe_common,
  717. PPE_COM_HIS_TX_PKT_QID_OK_CNT_REG + 4 * ring->index);
  718. hw_stats->ppe_tx_drop_pkts += dsaf_read_dev(ppe_common,
  719. PPE_COM_HIS_TX_PKT_QID_ERR_CNT_REG + 4 * ring->index);
  720. }
  721. /**
  722. *hns_rcb_get_stats - get rcb statistic
  723. *@ring: rcb ring
  724. *@data:statistic value
  725. */
  726. void hns_rcb_get_stats(struct hnae_queue *queue, u64 *data)
  727. {
  728. u64 *regs_buff = data;
  729. struct ring_pair_cb *ring =
  730. container_of(queue, struct ring_pair_cb, q);
  731. struct hns_ring_hw_stats *hw_stats = &ring->hw_stats;
  732. regs_buff[0] = hw_stats->tx_pkts;
  733. regs_buff[1] = hw_stats->ppe_tx_ok_pkts;
  734. regs_buff[2] = hw_stats->ppe_tx_drop_pkts;
  735. regs_buff[3] =
  736. dsaf_read_dev(queue, RCB_RING_TX_RING_FBDNUM_REG);
  737. regs_buff[4] = queue->tx_ring.stats.tx_pkts;
  738. regs_buff[5] = queue->tx_ring.stats.tx_bytes;
  739. regs_buff[6] = queue->tx_ring.stats.tx_err_cnt;
  740. regs_buff[7] = queue->tx_ring.stats.io_err_cnt;
  741. regs_buff[8] = queue->tx_ring.stats.sw_err_cnt;
  742. regs_buff[9] = queue->tx_ring.stats.seg_pkt_cnt;
  743. regs_buff[10] = queue->tx_ring.stats.restart_queue;
  744. regs_buff[11] = queue->tx_ring.stats.tx_busy;
  745. regs_buff[12] = hw_stats->rx_pkts;
  746. regs_buff[13] = hw_stats->ppe_rx_ok_pkts;
  747. regs_buff[14] = hw_stats->ppe_rx_drop_pkts;
  748. regs_buff[15] =
  749. dsaf_read_dev(queue, RCB_RING_RX_RING_FBDNUM_REG);
  750. regs_buff[16] = queue->rx_ring.stats.rx_pkts;
  751. regs_buff[17] = queue->rx_ring.stats.rx_bytes;
  752. regs_buff[18] = queue->rx_ring.stats.rx_err_cnt;
  753. regs_buff[19] = queue->rx_ring.stats.io_err_cnt;
  754. regs_buff[20] = queue->rx_ring.stats.sw_err_cnt;
  755. regs_buff[21] = queue->rx_ring.stats.seg_pkt_cnt;
  756. regs_buff[22] = queue->rx_ring.stats.reuse_pg_cnt;
  757. regs_buff[23] = queue->rx_ring.stats.err_pkt_len;
  758. regs_buff[24] = queue->rx_ring.stats.non_vld_descs;
  759. regs_buff[25] = queue->rx_ring.stats.err_bd_num;
  760. regs_buff[26] = queue->rx_ring.stats.l2_err;
  761. regs_buff[27] = queue->rx_ring.stats.l3l4_csum_err;
  762. }
  763. /**
  764. *hns_rcb_get_ring_sset_count - rcb string set count
  765. *@stringset:ethtool cmd
  766. *return rcb ring string set count
  767. */
  768. int hns_rcb_get_ring_sset_count(int stringset)
  769. {
  770. if (stringset == ETH_SS_STATS)
  771. return HNS_RING_STATIC_REG_NUM;
  772. return 0;
  773. }
  774. /**
  775. *hns_rcb_get_common_regs_count - rcb common regs count
  776. *return regs count
  777. */
  778. int hns_rcb_get_common_regs_count(void)
  779. {
  780. return HNS_RCB_COMMON_DUMP_REG_NUM;
  781. }
  782. /**
  783. *rcb_get_sset_count - rcb ring regs count
  784. *return regs count
  785. */
  786. int hns_rcb_get_ring_regs_count(void)
  787. {
  788. return HNS_RCB_RING_DUMP_REG_NUM;
  789. }
  790. /**
  791. *hns_rcb_get_strings - get rcb string set
  792. *@stringset:string set index
  793. *@data:strings name value
  794. *@index:queue index
  795. */
  796. void hns_rcb_get_strings(int stringset, u8 *data, int index)
  797. {
  798. char *buff = (char *)data;
  799. if (stringset != ETH_SS_STATS)
  800. return;
  801. snprintf(buff, ETH_GSTRING_LEN, "tx_ring%d_rcb_pkt_num", index);
  802. buff = buff + ETH_GSTRING_LEN;
  803. snprintf(buff, ETH_GSTRING_LEN, "tx_ring%d_ppe_tx_pkt_num", index);
  804. buff = buff + ETH_GSTRING_LEN;
  805. snprintf(buff, ETH_GSTRING_LEN, "tx_ring%d_ppe_drop_pkt_num", index);
  806. buff = buff + ETH_GSTRING_LEN;
  807. snprintf(buff, ETH_GSTRING_LEN, "tx_ring%d_fbd_num", index);
  808. buff = buff + ETH_GSTRING_LEN;
  809. snprintf(buff, ETH_GSTRING_LEN, "tx_ring%d_pkt_num", index);
  810. buff = buff + ETH_GSTRING_LEN;
  811. snprintf(buff, ETH_GSTRING_LEN, "tx_ring%d_bytes", index);
  812. buff = buff + ETH_GSTRING_LEN;
  813. snprintf(buff, ETH_GSTRING_LEN, "tx_ring%d_err_cnt", index);
  814. buff = buff + ETH_GSTRING_LEN;
  815. snprintf(buff, ETH_GSTRING_LEN, "tx_ring%d_io_err", index);
  816. buff = buff + ETH_GSTRING_LEN;
  817. snprintf(buff, ETH_GSTRING_LEN, "tx_ring%d_sw_err", index);
  818. buff = buff + ETH_GSTRING_LEN;
  819. snprintf(buff, ETH_GSTRING_LEN, "tx_ring%d_seg_pkt", index);
  820. buff = buff + ETH_GSTRING_LEN;
  821. snprintf(buff, ETH_GSTRING_LEN, "tx_ring%d_restart_queue", index);
  822. buff = buff + ETH_GSTRING_LEN;
  823. snprintf(buff, ETH_GSTRING_LEN, "tx_ring%d_tx_busy", index);
  824. buff = buff + ETH_GSTRING_LEN;
  825. snprintf(buff, ETH_GSTRING_LEN, "rx_ring%d_rcb_pkt_num", index);
  826. buff = buff + ETH_GSTRING_LEN;
  827. snprintf(buff, ETH_GSTRING_LEN, "rx_ring%d_ppe_pkt_num", index);
  828. buff = buff + ETH_GSTRING_LEN;
  829. snprintf(buff, ETH_GSTRING_LEN, "rx_ring%d_ppe_drop_pkt_num", index);
  830. buff = buff + ETH_GSTRING_LEN;
  831. snprintf(buff, ETH_GSTRING_LEN, "rx_ring%d_fbd_num", index);
  832. buff = buff + ETH_GSTRING_LEN;
  833. snprintf(buff, ETH_GSTRING_LEN, "rx_ring%d_pkt_num", index);
  834. buff = buff + ETH_GSTRING_LEN;
  835. snprintf(buff, ETH_GSTRING_LEN, "rx_ring%d_bytes", index);
  836. buff = buff + ETH_GSTRING_LEN;
  837. snprintf(buff, ETH_GSTRING_LEN, "rx_ring%d_err_cnt", index);
  838. buff = buff + ETH_GSTRING_LEN;
  839. snprintf(buff, ETH_GSTRING_LEN, "rx_ring%d_io_err", index);
  840. buff = buff + ETH_GSTRING_LEN;
  841. snprintf(buff, ETH_GSTRING_LEN, "rx_ring%d_sw_err", index);
  842. buff = buff + ETH_GSTRING_LEN;
  843. snprintf(buff, ETH_GSTRING_LEN, "rx_ring%d_seg_pkt", index);
  844. buff = buff + ETH_GSTRING_LEN;
  845. snprintf(buff, ETH_GSTRING_LEN, "rx_ring%d_reuse_pg", index);
  846. buff = buff + ETH_GSTRING_LEN;
  847. snprintf(buff, ETH_GSTRING_LEN, "rx_ring%d_len_err", index);
  848. buff = buff + ETH_GSTRING_LEN;
  849. snprintf(buff, ETH_GSTRING_LEN, "rx_ring%d_non_vld_desc_err", index);
  850. buff = buff + ETH_GSTRING_LEN;
  851. snprintf(buff, ETH_GSTRING_LEN, "rx_ring%d_bd_num_err", index);
  852. buff = buff + ETH_GSTRING_LEN;
  853. snprintf(buff, ETH_GSTRING_LEN, "rx_ring%d_l2_err", index);
  854. buff = buff + ETH_GSTRING_LEN;
  855. snprintf(buff, ETH_GSTRING_LEN, "rx_ring%d_l3l4csum_err", index);
  856. }
  857. void hns_rcb_get_common_regs(struct rcb_common_cb *rcb_com, void *data)
  858. {
  859. u32 *regs = data;
  860. bool is_ver1 = AE_IS_VER1(rcb_com->dsaf_dev->dsaf_ver);
  861. bool is_dbg = HNS_DSAF_IS_DEBUG(rcb_com->dsaf_dev);
  862. u32 reg_tmp;
  863. u32 reg_num_tmp;
  864. u32 i = 0;
  865. /*rcb common registers */
  866. regs[0] = dsaf_read_dev(rcb_com, RCB_COM_CFG_ENDIAN_REG);
  867. regs[1] = dsaf_read_dev(rcb_com, RCB_COM_CFG_SYS_FSH_REG);
  868. regs[2] = dsaf_read_dev(rcb_com, RCB_COM_CFG_INIT_FLAG_REG);
  869. regs[3] = dsaf_read_dev(rcb_com, RCB_COM_CFG_PKT_REG);
  870. regs[4] = dsaf_read_dev(rcb_com, RCB_COM_CFG_RINVLD_REG);
  871. regs[5] = dsaf_read_dev(rcb_com, RCB_COM_CFG_FNA_REG);
  872. regs[6] = dsaf_read_dev(rcb_com, RCB_COM_CFG_FA_REG);
  873. regs[7] = dsaf_read_dev(rcb_com, RCB_COM_CFG_PKT_TC_BP_REG);
  874. regs[8] = dsaf_read_dev(rcb_com, RCB_COM_CFG_PPE_TNL_CLKEN_REG);
  875. regs[9] = dsaf_read_dev(rcb_com, RCB_COM_INTMSK_TX_PKT_REG);
  876. regs[10] = dsaf_read_dev(rcb_com, RCB_COM_RINT_TX_PKT_REG);
  877. regs[11] = dsaf_read_dev(rcb_com, RCB_COM_INTMASK_ECC_ERR_REG);
  878. regs[12] = dsaf_read_dev(rcb_com, RCB_COM_INTSTS_ECC_ERR_REG);
  879. regs[13] = dsaf_read_dev(rcb_com, RCB_COM_EBD_SRAM_ERR_REG);
  880. regs[14] = dsaf_read_dev(rcb_com, RCB_COM_RXRING_ERR_REG);
  881. regs[15] = dsaf_read_dev(rcb_com, RCB_COM_TXRING_ERR_REG);
  882. regs[16] = dsaf_read_dev(rcb_com, RCB_COM_TX_FBD_ERR_REG);
  883. regs[17] = dsaf_read_dev(rcb_com, RCB_SRAM_ECC_CHK_EN_REG);
  884. regs[18] = dsaf_read_dev(rcb_com, RCB_SRAM_ECC_CHK0_REG);
  885. regs[19] = dsaf_read_dev(rcb_com, RCB_SRAM_ECC_CHK1_REG);
  886. regs[20] = dsaf_read_dev(rcb_com, RCB_SRAM_ECC_CHK2_REG);
  887. regs[21] = dsaf_read_dev(rcb_com, RCB_SRAM_ECC_CHK3_REG);
  888. regs[22] = dsaf_read_dev(rcb_com, RCB_SRAM_ECC_CHK4_REG);
  889. regs[23] = dsaf_read_dev(rcb_com, RCB_SRAM_ECC_CHK5_REG);
  890. regs[24] = dsaf_read_dev(rcb_com, RCB_ECC_ERR_ADDR0_REG);
  891. regs[25] = dsaf_read_dev(rcb_com, RCB_ECC_ERR_ADDR3_REG);
  892. regs[26] = dsaf_read_dev(rcb_com, RCB_ECC_ERR_ADDR4_REG);
  893. regs[27] = dsaf_read_dev(rcb_com, RCB_ECC_ERR_ADDR5_REG);
  894. regs[28] = dsaf_read_dev(rcb_com, RCB_COM_SF_CFG_INTMASK_RING);
  895. regs[29] = dsaf_read_dev(rcb_com, RCB_COM_SF_CFG_RING_STS);
  896. regs[30] = dsaf_read_dev(rcb_com, RCB_COM_SF_CFG_RING);
  897. regs[31] = dsaf_read_dev(rcb_com, RCB_COM_SF_CFG_INTMASK_BD);
  898. regs[32] = dsaf_read_dev(rcb_com, RCB_COM_SF_CFG_BD_RINT_STS);
  899. regs[33] = dsaf_read_dev(rcb_com, RCB_COM_RCB_RD_BD_BUSY);
  900. regs[34] = dsaf_read_dev(rcb_com, RCB_COM_RCB_FBD_CRT_EN);
  901. regs[35] = dsaf_read_dev(rcb_com, RCB_COM_AXI_WR_ERR_INTMASK);
  902. regs[36] = dsaf_read_dev(rcb_com, RCB_COM_AXI_ERR_STS);
  903. regs[37] = dsaf_read_dev(rcb_com, RCB_COM_CHK_TX_FBD_NUM_REG);
  904. /* rcb common entry registers */
  905. for (i = 0; i < 16; i++) { /* total 16 model registers */
  906. regs[38 + i]
  907. = dsaf_read_dev(rcb_com, RCB_CFG_BD_NUM_REG + 4 * i);
  908. regs[54 + i]
  909. = dsaf_read_dev(rcb_com, RCB_CFG_PKTLINE_REG + 4 * i);
  910. }
  911. reg_tmp = is_ver1 ? RCB_CFG_OVERTIME_REG : RCB_PORT_CFG_OVERTIME_REG;
  912. reg_num_tmp = (is_ver1 || is_dbg) ? 1 : 6;
  913. for (i = 0; i < reg_num_tmp; i++)
  914. regs[70 + i] = dsaf_read_dev(rcb_com, reg_tmp);
  915. regs[76] = dsaf_read_dev(rcb_com, RCB_CFG_PKTLINE_INT_NUM_REG);
  916. regs[77] = dsaf_read_dev(rcb_com, RCB_CFG_OVERTIME_INT_NUM_REG);
  917. /* mark end of rcb common regs */
  918. for (i = 78; i < 80; i++)
  919. regs[i] = 0xcccccccc;
  920. }
  921. void hns_rcb_get_ring_regs(struct hnae_queue *queue, void *data)
  922. {
  923. u32 *regs = data;
  924. struct ring_pair_cb *ring_pair
  925. = container_of(queue, struct ring_pair_cb, q);
  926. u32 i = 0;
  927. /*rcb ring registers */
  928. regs[0] = dsaf_read_dev(queue, RCB_RING_RX_RING_BASEADDR_L_REG);
  929. regs[1] = dsaf_read_dev(queue, RCB_RING_RX_RING_BASEADDR_H_REG);
  930. regs[2] = dsaf_read_dev(queue, RCB_RING_RX_RING_BD_NUM_REG);
  931. regs[3] = dsaf_read_dev(queue, RCB_RING_RX_RING_BD_LEN_REG);
  932. regs[4] = dsaf_read_dev(queue, RCB_RING_RX_RING_PKTLINE_REG);
  933. regs[5] = dsaf_read_dev(queue, RCB_RING_RX_RING_TAIL_REG);
  934. regs[6] = dsaf_read_dev(queue, RCB_RING_RX_RING_HEAD_REG);
  935. regs[7] = dsaf_read_dev(queue, RCB_RING_RX_RING_FBDNUM_REG);
  936. regs[8] = dsaf_read_dev(queue, RCB_RING_RX_RING_PKTNUM_RECORD_REG);
  937. regs[9] = dsaf_read_dev(queue, RCB_RING_TX_RING_BASEADDR_L_REG);
  938. regs[10] = dsaf_read_dev(queue, RCB_RING_TX_RING_BASEADDR_H_REG);
  939. regs[11] = dsaf_read_dev(queue, RCB_RING_TX_RING_BD_NUM_REG);
  940. regs[12] = dsaf_read_dev(queue, RCB_RING_TX_RING_BD_LEN_REG);
  941. regs[13] = dsaf_read_dev(queue, RCB_RING_TX_RING_PKTLINE_REG);
  942. regs[15] = dsaf_read_dev(queue, RCB_RING_TX_RING_TAIL_REG);
  943. regs[16] = dsaf_read_dev(queue, RCB_RING_TX_RING_HEAD_REG);
  944. regs[17] = dsaf_read_dev(queue, RCB_RING_TX_RING_FBDNUM_REG);
  945. regs[18] = dsaf_read_dev(queue, RCB_RING_TX_RING_OFFSET_REG);
  946. regs[19] = dsaf_read_dev(queue, RCB_RING_TX_RING_PKTNUM_RECORD_REG);
  947. regs[20] = dsaf_read_dev(queue, RCB_RING_PREFETCH_EN_REG);
  948. regs[21] = dsaf_read_dev(queue, RCB_RING_CFG_VF_NUM_REG);
  949. regs[22] = dsaf_read_dev(queue, RCB_RING_ASID_REG);
  950. regs[23] = dsaf_read_dev(queue, RCB_RING_RX_VM_REG);
  951. regs[24] = dsaf_read_dev(queue, RCB_RING_T0_BE_RST);
  952. regs[25] = dsaf_read_dev(queue, RCB_RING_COULD_BE_RST);
  953. regs[26] = dsaf_read_dev(queue, RCB_RING_WRR_WEIGHT_REG);
  954. regs[27] = dsaf_read_dev(queue, RCB_RING_INTMSK_RXWL_REG);
  955. regs[28] = dsaf_read_dev(queue, RCB_RING_INTSTS_RX_RING_REG);
  956. regs[29] = dsaf_read_dev(queue, RCB_RING_INTMSK_TXWL_REG);
  957. regs[30] = dsaf_read_dev(queue, RCB_RING_INTSTS_TX_RING_REG);
  958. regs[31] = dsaf_read_dev(queue, RCB_RING_INTMSK_RX_OVERTIME_REG);
  959. regs[32] = dsaf_read_dev(queue, RCB_RING_INTSTS_RX_OVERTIME_REG);
  960. regs[33] = dsaf_read_dev(queue, RCB_RING_INTMSK_TX_OVERTIME_REG);
  961. regs[34] = dsaf_read_dev(queue, RCB_RING_INTSTS_TX_OVERTIME_REG);
  962. /* mark end of ring regs */
  963. for (i = 35; i < 40; i++)
  964. regs[i] = 0xcccccc00 + ring_pair->index;
  965. }