hns_dsaf_main.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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. #ifndef __HNS_DSAF_MAIN_H
  10. #define __HNS_DSAF_MAIN_H
  11. #include "hnae.h"
  12. #include "hns_dsaf_reg.h"
  13. #include "hns_dsaf_mac.h"
  14. struct hns_mac_cb;
  15. #define DSAF_DRV_NAME "hns_dsaf"
  16. #define DSAF_MOD_VERSION "v1.0"
  17. #define DSAF_DEVICE_NAME "dsaf"
  18. #define HNS_DSAF_DEBUG_NW_REG_OFFSET 0x100000
  19. #define DSAF_BASE_INNER_PORT_NUM 127/* mac tbl qid*/
  20. #define DSAF_MAX_CHIP_NUM 2 /*max 2 chips */
  21. #define DSAF_DEFAUTL_QUEUE_NUM_PER_PPE 22
  22. #define HNS_DSAF_MAX_DESC_CNT 1024
  23. #define HNS_DSAF_MIN_DESC_CNT 16
  24. #define DSAF_INVALID_ENTRY_IDX 0xffff
  25. #define DSAF_CFG_READ_CNT 30
  26. #define DSAF_DUMP_REGS_NUM 504
  27. #define DSAF_STATIC_NUM 28
  28. #define DSAF_V2_STATIC_NUM 44
  29. #define DSAF_PRIO_NR 8
  30. #define DSAF_REG_PER_ZONE 3
  31. #define DSAF_ROCE_CREDIT_CHN 8
  32. #define DSAF_ROCE_CHAN_MODE 3
  33. #define HNS_MAX_WAIT_CNT 10000
  34. enum dsaf_roce_port_mode {
  35. DSAF_ROCE_6PORT_MODE,
  36. DSAF_ROCE_4PORT_MODE,
  37. DSAF_ROCE_2PORT_MODE,
  38. DSAF_ROCE_CHAN_MODE_NUM,
  39. };
  40. enum dsaf_roce_port_num {
  41. DSAF_ROCE_PORT_0,
  42. DSAF_ROCE_PORT_1,
  43. DSAF_ROCE_PORT_2,
  44. DSAF_ROCE_PORT_3,
  45. DSAF_ROCE_PORT_4,
  46. DSAF_ROCE_PORT_5,
  47. };
  48. enum dsaf_roce_qos_sl {
  49. DSAF_ROCE_SL_0,
  50. DSAF_ROCE_SL_1,
  51. DSAF_ROCE_SL_2,
  52. DSAF_ROCE_SL_3,
  53. };
  54. #define DSAF_STATS_READ(p, offset) (*((u64 *)((u8 *)(p) + (offset))))
  55. #define HNS_DSAF_IS_DEBUG(dev) ((dev)->dsaf_mode == DSAF_MODE_DISABLE_SP)
  56. enum hal_dsaf_mode {
  57. HRD_DSAF_NO_DSAF_MODE = 0x0,
  58. HRD_DSAF_MODE = 0x1,
  59. };
  60. enum hal_dsaf_tc_mode {
  61. HRD_DSAF_4TC_MODE = 0X0,
  62. HRD_DSAF_8TC_MODE = 0X1,
  63. };
  64. struct dsaf_vm_def_vlan {
  65. u32 vm_def_vlan_id;
  66. u32 vm_def_vlan_cfi;
  67. u32 vm_def_vlan_pri;
  68. };
  69. struct dsaf_tbl_tcam_data {
  70. u32 tbl_tcam_data_high;
  71. u32 tbl_tcam_data_low;
  72. };
  73. #define DSAF_PORT_MSK_NUM \
  74. ((DSAF_TOTAL_QUEUE_NUM + DSAF_SERVICE_NW_NUM - 1) / 32 + 1)
  75. struct dsaf_tbl_tcam_mcast_cfg {
  76. u8 tbl_mcast_old_en;
  77. u8 tbl_mcast_item_vld;
  78. u32 tbl_mcast_port_msk[DSAF_PORT_MSK_NUM];
  79. };
  80. struct dsaf_tbl_tcam_ucast_cfg {
  81. u32 tbl_ucast_old_en;
  82. u32 tbl_ucast_item_vld;
  83. u32 tbl_ucast_mac_discard;
  84. u32 tbl_ucast_dvc;
  85. u32 tbl_ucast_out_port;
  86. };
  87. struct dsaf_tbl_line_cfg {
  88. u32 tbl_line_mac_discard;
  89. u32 tbl_line_dvc;
  90. u32 tbl_line_out_port;
  91. };
  92. enum dsaf_port_rate_mode {
  93. DSAF_PORT_RATE_1000 = 0,
  94. DSAF_PORT_RATE_2500,
  95. DSAF_PORT_RATE_10000
  96. };
  97. enum dsaf_stp_port_type {
  98. DSAF_STP_PORT_TYPE_DISCARD = 0,
  99. DSAF_STP_PORT_TYPE_BLOCK = 1,
  100. DSAF_STP_PORT_TYPE_LISTEN = 2,
  101. DSAF_STP_PORT_TYPE_LEARN = 3,
  102. DSAF_STP_PORT_TYPE_FORWARD = 4
  103. };
  104. enum dsaf_sw_port_type {
  105. DSAF_SW_PORT_TYPE_NON_VLAN = 0,
  106. DSAF_SW_PORT_TYPE_ACCESS = 1,
  107. DSAF_SW_PORT_TYPE_TRUNK = 2,
  108. };
  109. #define DSAF_SUB_BASE_SIZE (0x10000)
  110. /* dsaf mode define */
  111. enum dsaf_mode {
  112. DSAF_MODE_INVALID = 0, /**< Invalid dsaf mode */
  113. DSAF_MODE_ENABLE_FIX, /**< en DSAF-mode, fixed to queue*/
  114. DSAF_MODE_ENABLE_0VM, /**< en DSAF-mode, support 0 VM */
  115. DSAF_MODE_ENABLE_8VM, /**< en DSAF-mode, support 8 VM */
  116. DSAF_MODE_ENABLE_16VM, /**< en DSAF-mode, support 16 VM */
  117. DSAF_MODE_ENABLE_32VM, /**< en DSAF-mode, support 32 VM */
  118. DSAF_MODE_ENABLE_128VM, /**< en DSAF-mode, support 128 VM */
  119. DSAF_MODE_ENABLE, /**< before is enable DSAF mode*/
  120. DSAF_MODE_DISABLE_SP, /* <non-dsaf, single port mode */
  121. DSAF_MODE_DISABLE_FIX, /**< non-dasf, fixed to queue*/
  122. DSAF_MODE_DISABLE_2PORT_8VM, /**< non-dasf, 2port 8VM */
  123. DSAF_MODE_DISABLE_2PORT_16VM, /**< non-dasf, 2port 16VM */
  124. DSAF_MODE_DISABLE_2PORT_64VM, /**< non-dasf, 2port 64VM */
  125. DSAF_MODE_DISABLE_6PORT_0VM, /**< non-dasf, 6port 0VM */
  126. DSAF_MODE_DISABLE_6PORT_2VM, /**< non-dasf, 6port 2VM */
  127. DSAF_MODE_DISABLE_6PORT_4VM, /**< non-dasf, 6port 4VM */
  128. DSAF_MODE_DISABLE_6PORT_16VM, /**< non-dasf, 6port 16VM */
  129. DSAF_MODE_MAX /**< the last one, use as the num */
  130. };
  131. #define DSAF_DEST_PORT_NUM 256 /* DSAF max port num */
  132. #define DSAF_WORD_BIT_CNT 32 /* the num bit of word */
  133. /*mac entry, mc or uc entry*/
  134. struct dsaf_drv_mac_single_dest_entry {
  135. /* mac addr, match the entry*/
  136. u8 addr[ETH_ALEN];
  137. u16 in_vlan_id; /* value of VlanId */
  138. /* the vld input port num, dsaf-mode fix 0, */
  139. /* non-dasf is the entry whitch port vld*/
  140. u8 in_port_num;
  141. u8 port_num; /*output port num*/
  142. u8 rsv[6];
  143. };
  144. /*only mc entry*/
  145. struct dsaf_drv_mac_multi_dest_entry {
  146. /* mac addr, match the entry*/
  147. u8 addr[ETH_ALEN];
  148. u16 in_vlan_id;
  149. /* this mac addr output port,*/
  150. /* bit0-bit5 means Port0-Port5(1bit is vld)**/
  151. u32 port_mask[DSAF_DEST_PORT_NUM / DSAF_WORD_BIT_CNT];
  152. /* the vld input port num, dsaf-mode fix 0,*/
  153. /* non-dasf is the entry whitch port vld*/
  154. u8 in_port_num;
  155. u8 rsv[7];
  156. };
  157. struct dsaf_hw_stats {
  158. u64 pad_drop;
  159. u64 man_pkts;
  160. u64 rx_pkts;
  161. u64 rx_pkt_id;
  162. u64 rx_pause_frame;
  163. u64 release_buf_num;
  164. u64 sbm_drop;
  165. u64 crc_false;
  166. u64 bp_drop;
  167. u64 rslt_drop;
  168. u64 local_addr_false;
  169. u64 vlan_drop;
  170. u64 stp_drop;
  171. u64 rx_pfc[DSAF_PRIO_NR];
  172. u64 tx_pfc[DSAF_PRIO_NR];
  173. u64 tx_pkts;
  174. };
  175. struct hnae_vf_cb {
  176. u8 port_index;
  177. struct hns_mac_cb *mac_cb;
  178. struct dsaf_device *dsaf_dev;
  179. struct hnae_handle ae_handle; /* must be the last number */
  180. };
  181. struct dsaf_int_xge_src {
  182. u32 xid_xge_ecc_err_int_src;
  183. u32 xid_xge_fsm_timout_int_src;
  184. u32 sbm_xge_lnk_fsm_timout_int_src;
  185. u32 sbm_xge_lnk_ecc_2bit_int_src;
  186. u32 sbm_xge_mib_req_failed_int_src;
  187. u32 sbm_xge_mib_req_fsm_timout_int_src;
  188. u32 sbm_xge_mib_rels_fsm_timout_int_src;
  189. u32 sbm_xge_sram_ecc_2bit_int_src;
  190. u32 sbm_xge_mib_buf_sum_err_int_src;
  191. u32 sbm_xge_mib_req_extra_int_src;
  192. u32 sbm_xge_mib_rels_extra_int_src;
  193. u32 voq_xge_start_to_over_0_int_src;
  194. u32 voq_xge_start_to_over_1_int_src;
  195. u32 voq_xge_ecc_err_int_src;
  196. };
  197. struct dsaf_int_ppe_src {
  198. u32 xid_ppe_fsm_timout_int_src;
  199. u32 sbm_ppe_lnk_fsm_timout_int_src;
  200. u32 sbm_ppe_lnk_ecc_2bit_int_src;
  201. u32 sbm_ppe_mib_req_failed_int_src;
  202. u32 sbm_ppe_mib_req_fsm_timout_int_src;
  203. u32 sbm_ppe_mib_rels_fsm_timout_int_src;
  204. u32 sbm_ppe_sram_ecc_2bit_int_src;
  205. u32 sbm_ppe_mib_buf_sum_err_int_src;
  206. u32 sbm_ppe_mib_req_extra_int_src;
  207. u32 sbm_ppe_mib_rels_extra_int_src;
  208. u32 voq_ppe_start_to_over_0_int_src;
  209. u32 voq_ppe_ecc_err_int_src;
  210. u32 xod_ppe_fifo_rd_empty_int_src;
  211. u32 xod_ppe_fifo_wr_full_int_src;
  212. };
  213. struct dsaf_int_rocee_src {
  214. u32 xid_rocee_fsm_timout_int_src;
  215. u32 sbm_rocee_lnk_fsm_timout_int_src;
  216. u32 sbm_rocee_lnk_ecc_2bit_int_src;
  217. u32 sbm_rocee_mib_req_failed_int_src;
  218. u32 sbm_rocee_mib_req_fsm_timout_int_src;
  219. u32 sbm_rocee_mib_rels_fsm_timout_int_src;
  220. u32 sbm_rocee_sram_ecc_2bit_int_src;
  221. u32 sbm_rocee_mib_buf_sum_err_int_src;
  222. u32 sbm_rocee_mib_req_extra_int_src;
  223. u32 sbm_rocee_mib_rels_extra_int_src;
  224. u32 voq_rocee_start_to_over_0_int_src;
  225. u32 voq_rocee_ecc_err_int_src;
  226. };
  227. struct dsaf_int_tbl_src {
  228. u32 tbl_da0_mis_src;
  229. u32 tbl_da1_mis_src;
  230. u32 tbl_da2_mis_src;
  231. u32 tbl_da3_mis_src;
  232. u32 tbl_da4_mis_src;
  233. u32 tbl_da5_mis_src;
  234. u32 tbl_da6_mis_src;
  235. u32 tbl_da7_mis_src;
  236. u32 tbl_sa_mis_src;
  237. u32 tbl_old_sech_end_src;
  238. u32 lram_ecc_err1_src;
  239. u32 lram_ecc_err2_src;
  240. u32 tram_ecc_err1_src;
  241. u32 tram_ecc_err2_src;
  242. u32 tbl_ucast_bcast_xge0_src;
  243. u32 tbl_ucast_bcast_xge1_src;
  244. u32 tbl_ucast_bcast_xge2_src;
  245. u32 tbl_ucast_bcast_xge3_src;
  246. u32 tbl_ucast_bcast_xge4_src;
  247. u32 tbl_ucast_bcast_xge5_src;
  248. u32 tbl_ucast_bcast_ppe_src;
  249. u32 tbl_ucast_bcast_rocee_src;
  250. };
  251. struct dsaf_int_stat {
  252. struct dsaf_int_xge_src dsaf_int_xge_stat[DSAF_COMM_CHN];
  253. struct dsaf_int_ppe_src dsaf_int_ppe_stat[DSAF_COMM_CHN];
  254. struct dsaf_int_rocee_src dsaf_int_rocee_stat[DSAF_COMM_CHN];
  255. struct dsaf_int_tbl_src dsaf_int_tbl_stat[1];
  256. };
  257. struct dsaf_misc_op {
  258. void (*cpld_set_led)(struct hns_mac_cb *mac_cb, int link_status,
  259. u16 speed, int data);
  260. void (*cpld_reset_led)(struct hns_mac_cb *mac_cb);
  261. int (*cpld_set_led_id)(struct hns_mac_cb *mac_cb,
  262. enum hnae_led_state status);
  263. /* reset series function, it will be reset if the dereset is 0 */
  264. void (*dsaf_reset)(struct dsaf_device *dsaf_dev, bool dereset);
  265. void (*xge_srst)(struct dsaf_device *dsaf_dev, u32 port, bool dereset);
  266. void (*ge_srst)(struct dsaf_device *dsaf_dev, u32 port, bool dereset);
  267. void (*ppe_srst)(struct dsaf_device *dsaf_dev, u32 port, bool dereset);
  268. void (*ppe_comm_srst)(struct dsaf_device *dsaf_dev, bool dereset);
  269. void (*hns_dsaf_srst_chns)(struct dsaf_device *dsaf_dev, u32 msk,
  270. bool dereset);
  271. void (*hns_dsaf_roce_srst)(struct dsaf_device *dsaf_dev, bool dereset);
  272. phy_interface_t (*get_phy_if)(struct hns_mac_cb *mac_cb);
  273. int (*get_sfp_prsnt)(struct hns_mac_cb *mac_cb, int *sfp_prsnt);
  274. int (*cfg_serdes_loopback)(struct hns_mac_cb *mac_cb, bool en);
  275. };
  276. /* Dsaf device struct define ,and mac -> dsaf */
  277. struct dsaf_device {
  278. struct device *dev;
  279. struct hnae_ae_dev ae_dev;
  280. u8 __iomem *sc_base;
  281. u8 __iomem *sds_base;
  282. u8 __iomem *ppe_base;
  283. u8 __iomem *io_base;
  284. struct regmap *sub_ctrl;
  285. phys_addr_t ppe_paddr;
  286. u32 desc_num; /* desc num per queue*/
  287. u32 buf_size; /* ring buffer size */
  288. u32 reset_offset; /* reset field offset in sub sysctrl */
  289. int buf_size_type; /* ring buffer size-type */
  290. enum dsaf_mode dsaf_mode; /* dsaf mode */
  291. enum hal_dsaf_mode dsaf_en;
  292. enum hal_dsaf_tc_mode dsaf_tc_mode;
  293. u32 dsaf_ver;
  294. u16 tcam_max_num; /* max TCAM entry for user except promisc */
  295. struct ppe_common_cb *ppe_common[DSAF_COMM_DEV_NUM];
  296. struct rcb_common_cb *rcb_common[DSAF_COMM_DEV_NUM];
  297. struct hns_mac_cb *mac_cb[DSAF_MAX_PORT_NUM];
  298. struct dsaf_misc_op *misc_op;
  299. struct dsaf_hw_stats hw_stats[DSAF_NODE_NUM];
  300. struct dsaf_int_stat int_stat;
  301. /* make sure tcam table config spinlock */
  302. spinlock_t tcam_lock;
  303. };
  304. static inline void *hns_dsaf_dev_priv(const struct dsaf_device *dsaf_dev)
  305. {
  306. return (void *)((u8 *)dsaf_dev + sizeof(*dsaf_dev));
  307. }
  308. #define DSAF_TBL_TCAM_KEY_PORT_S 0
  309. #define DSAF_TBL_TCAM_KEY_PORT_M (((1ULL << 4) - 1) << 0)
  310. #define DSAF_TBL_TCAM_KEY_VLAN_S 4
  311. #define DSAF_TBL_TCAM_KEY_VLAN_M (((1ULL << 12) - 1) << 4)
  312. struct dsaf_drv_tbl_tcam_key {
  313. union {
  314. struct {
  315. u8 mac_3;
  316. u8 mac_2;
  317. u8 mac_1;
  318. u8 mac_0;
  319. } bits;
  320. u32 val;
  321. } high;
  322. union {
  323. struct {
  324. u16 port_vlan;
  325. u8 mac_5;
  326. u8 mac_4;
  327. } bits;
  328. u32 val;
  329. } low;
  330. };
  331. struct dsaf_drv_soft_mac_tbl {
  332. struct dsaf_drv_tbl_tcam_key tcam_key;
  333. u16 index; /*the entry's index in tcam tab*/
  334. };
  335. struct dsaf_drv_priv {
  336. /* soft tab Mac key, for hardware tab*/
  337. struct dsaf_drv_soft_mac_tbl *soft_mac_tbl;
  338. };
  339. static inline void hns_dsaf_tbl_tcam_addr_cfg(struct dsaf_device *dsaf_dev,
  340. u32 tab_tcam_addr)
  341. {
  342. dsaf_set_dev_field(dsaf_dev, DSAF_TBL_TCAM_ADDR_0_REG,
  343. DSAF_TBL_TCAM_ADDR_M, DSAF_TBL_TCAM_ADDR_S,
  344. tab_tcam_addr);
  345. }
  346. static inline void hns_dsaf_tbl_tcam_load_pul(struct dsaf_device *dsaf_dev)
  347. {
  348. u32 o_tbl_pul;
  349. o_tbl_pul = dsaf_read_dev(dsaf_dev, DSAF_TBL_PUL_0_REG);
  350. dsaf_set_bit(o_tbl_pul, DSAF_TBL_PUL_TCAM_LOAD_S, 1);
  351. dsaf_write_dev(dsaf_dev, DSAF_TBL_PUL_0_REG, o_tbl_pul);
  352. dsaf_set_bit(o_tbl_pul, DSAF_TBL_PUL_TCAM_LOAD_S, 0);
  353. dsaf_write_dev(dsaf_dev, DSAF_TBL_PUL_0_REG, o_tbl_pul);
  354. }
  355. static inline void hns_dsaf_tbl_line_addr_cfg(struct dsaf_device *dsaf_dev,
  356. u32 tab_line_addr)
  357. {
  358. dsaf_set_dev_field(dsaf_dev, DSAF_TBL_LINE_ADDR_0_REG,
  359. DSAF_TBL_LINE_ADDR_M, DSAF_TBL_LINE_ADDR_S,
  360. tab_line_addr);
  361. }
  362. static inline struct hnae_vf_cb *hns_ae_get_vf_cb(
  363. struct hnae_handle *handle)
  364. {
  365. return container_of(handle, struct hnae_vf_cb, ae_handle);
  366. }
  367. int hns_dsaf_set_mac_uc_entry(struct dsaf_device *dsaf_dev,
  368. struct dsaf_drv_mac_single_dest_entry *mac_entry);
  369. int hns_dsaf_add_mac_mc_port(struct dsaf_device *dsaf_dev,
  370. struct dsaf_drv_mac_single_dest_entry *mac_entry);
  371. int hns_dsaf_del_mac_entry(struct dsaf_device *dsaf_dev, u16 vlan_id,
  372. u8 in_port_num, u8 *addr);
  373. int hns_dsaf_del_mac_mc_port(struct dsaf_device *dsaf_dev,
  374. struct dsaf_drv_mac_single_dest_entry *mac_entry);
  375. void hns_dsaf_fix_mac_mode(struct hns_mac_cb *mac_cb);
  376. int hns_dsaf_ae_init(struct dsaf_device *dsaf_dev);
  377. void hns_dsaf_ae_uninit(struct dsaf_device *dsaf_dev);
  378. void hns_dsaf_update_stats(struct dsaf_device *dsaf_dev, u32 inode_num);
  379. int hns_dsaf_get_sset_count(struct dsaf_device *dsaf_dev, int stringset);
  380. void hns_dsaf_get_stats(struct dsaf_device *ddev, u64 *data, int port);
  381. void hns_dsaf_get_strings(int stringset, u8 *data, int port,
  382. struct dsaf_device *dsaf_dev);
  383. void hns_dsaf_get_regs(struct dsaf_device *ddev, u32 port, void *data);
  384. int hns_dsaf_get_regs_count(void);
  385. void hns_dsaf_set_promisc_mode(struct dsaf_device *dsaf_dev, u32 en);
  386. void hns_dsaf_set_promisc_tcam(struct dsaf_device *dsaf_dev,
  387. u32 port, bool enable);
  388. void hns_dsaf_get_rx_mac_pause_en(struct dsaf_device *dsaf_dev, int mac_id,
  389. u32 *en);
  390. int hns_dsaf_set_rx_mac_pause_en(struct dsaf_device *dsaf_dev, int mac_id,
  391. u32 en);
  392. int hns_dsaf_rm_mac_addr(
  393. struct dsaf_device *dsaf_dev,
  394. struct dsaf_drv_mac_single_dest_entry *mac_entry);
  395. int hns_dsaf_clr_mac_mc_port(struct dsaf_device *dsaf_dev,
  396. u8 mac_id, u8 port_num);
  397. int hns_dsaf_wait_pkt_clean(struct dsaf_device *dsaf_dev, int port);
  398. #endif /* __HNS_DSAF_MAIN_H__ */