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 
10 #ifndef _HNS_DSAF_RCB_H
11 #define _HNS_DSAF_RCB_H
12 
13 #include <linux/netdevice.h>
14 #include <linux/platform_device.h>
15 
16 #include "hnae.h"
17 #include "hns_dsaf_main.h"
18 
19 struct rcb_common_cb;
20 
21 #define HNS_RCB_IRQ_NUM_PER_QUEUE		2
22 #define HNS_RCB_IRQ_IDX_TX			0
23 #define HNS_RCB_IRQ_IDX_RX			1
24 #define HNS_RCB_TX_REG_OFFSET			0x40
25 
26 #define HNS_RCB_SERVICE_NW_ENGINE_NUM		DSAF_COMM_CHN
27 #define HNS_RCB_DEBUG_NW_ENGINE_NUM		1
28 #define HNS_RCB_RING_MAX_BD_PER_PKT		3
29 #define HNS_RCB_MAX_PKT_SIZE MAC_MAX_MTU
30 
31 #define HNS_RCB_RING_MAX_PENDING_BD		1024
32 #define HNS_RCB_RING_MIN_PENDING_BD		16
33 
34 #define HNS_RCB_REG_OFFSET			0x10000
35 
36 #define HNS_RCB_MAX_COALESCED_FRAMES		1023
37 #define HNS_RCB_MIN_COALESCED_FRAMES		1
38 #define HNS_RCB_DEF_COALESCED_FRAMES		50
39 #define HNS_RCB_MAX_TIME_OUT			0x500
40 
41 #define HNS_RCB_COMMON_ENDIAN			1
42 
43 #define HNS_BD_SIZE_512_TYPE			0
44 #define HNS_BD_SIZE_1024_TYPE			1
45 #define HNS_BD_SIZE_2048_TYPE			2
46 #define HNS_BD_SIZE_4096_TYPE			3
47 
48 #define HNS_RCB_COMMON_DUMP_REG_NUM 80
49 #define HNS_RCB_RING_DUMP_REG_NUM 40
50 #define HNS_RING_STATIC_REG_NUM 28
51 
52 #define HNS_DUMP_REG_NUM			500
53 #define HNS_STATIC_REG_NUM			12
54 
55 enum rcb_int_flag {
56 	RCB_INT_FLAG_TX = 0x1,
57 	RCB_INT_FLAG_RX = (0x1 << 1),
58 	RCB_INT_FLAG_MAX = (0x1 << 2),	/*must be the last element */
59 };
60 
61 struct hns_ring_hw_stats {
62 	u64 tx_pkts;
63 	u64 ppe_tx_ok_pkts;
64 	u64 ppe_tx_drop_pkts;
65 	u64 rx_pkts;
66 	u64 ppe_rx_ok_pkts;
67 	u64 ppe_rx_drop_pkts;
68 };
69 
70 struct ring_pair_cb {
71 	struct rcb_common_cb *rcb_common;	/*  ring belongs to */
72 	struct device *dev;	/*device for DMA mapping */
73 	struct hnae_queue q;
74 
75 	u16 index;	/* global index in a rcb common device */
76 	u16 buf_size;
77 
78 	int virq[HNS_RCB_IRQ_NUM_PER_QUEUE];
79 
80 	u8 port_id_in_dsa;
81 	u8 used_by_vf;
82 
83 	struct hns_ring_hw_stats hw_stats;
84 };
85 
86 struct rcb_common_cb {
87 	u8 __iomem *io_base;
88 	phys_addr_t phy_base;
89 	struct dsaf_device *dsaf_dev;
90 	u16 max_vfn;
91 	u16 max_q_per_vf;
92 
93 	u8 comm_index;
94 	u32 ring_num;
95 	u32 coalesced_frames; /* frames  threshold of  rx interrupt   */
96 	u32 timeout; /* time threshold of  rx interrupt  */
97 	u32 desc_num; /*  desc num per queue*/
98 
99 	struct ring_pair_cb ring_pair_cb[0];
100 };
101 
102 int hns_rcb_buf_size2type(u32 buf_size);
103 
104 int hns_rcb_common_get_cfg(struct dsaf_device *dsaf_dev, int comm_index);
105 void hns_rcb_common_free_cfg(struct dsaf_device *dsaf_dev, u32 comm_index);
106 int hns_rcb_common_init_hw(struct rcb_common_cb *rcb_common);
107 void hns_rcb_start(struct hnae_queue *q, u32 val);
108 void hns_rcb_get_cfg(struct rcb_common_cb *rcb_common);
109 void hns_rcb_common_init_commit_hw(struct rcb_common_cb *rcb_common);
110 void hns_rcb_get_queue_mode(enum dsaf_mode dsaf_mode, int comm_index,
111 			    u16 *max_vfn, u16 *max_q_per_vf);
112 
113 void hns_rcb_ring_enable_hw(struct hnae_queue *q, u32 val);
114 void hns_rcb_int_clr_hw(struct hnae_queue *q, u32 flag);
115 void hns_rcb_int_ctrl_hw(struct hnae_queue *q, u32 flag, u32 enable);
116 void hns_rcb_init_hw(struct ring_pair_cb *ring);
117 void hns_rcb_reset_ring_hw(struct hnae_queue *q);
118 void hns_rcb_wait_fbd_clean(struct hnae_queue **qs, int q_num, u32 flag);
119 
120 u32 hns_rcb_get_coalesced_frames(struct dsaf_device *dsaf_dev, int comm_index);
121 u32 hns_rcb_get_coalesce_usecs(struct dsaf_device *dsaf_dev, int comm_index);
122 void hns_rcb_set_coalesce_usecs(struct dsaf_device *dsaf_dev,
123 				int comm_index, u32 timeout);
124 int hns_rcb_set_coalesced_frames(struct dsaf_device *dsaf_dev,
125 				 int comm_index, u32 coalesce_frames);
126 void hns_rcb_update_stats(struct hnae_queue *queue);
127 
128 void hns_rcb_get_stats(struct hnae_queue *queue, u64 *data);
129 
130 void hns_rcb_get_common_regs(struct rcb_common_cb *rcb_common, void *data);
131 
132 int hns_rcb_get_ring_sset_count(int stringset);
133 int hns_rcb_get_common_regs_count(void);
134 int hns_rcb_get_ring_regs_count(void);
135 
136 void hns_rcb_get_ring_regs(struct hnae_queue *queue, void *data);
137 
138 void hns_rcb_get_strings(int stringset, u8 *data, int index);
139 #endif /* _HNS_DSAF_RCB_H */
140