xref: /linux/drivers/net/ethernet/marvell/octeon_ep/octep_config.h (revision b5a78c7127f2007cfc7ad322b6ce0aa4bf347138)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Marvell Octeon EP (EndPoint) Ethernet Driver
3  *
4  * Copyright (C) 2020 Marvell.
5  *
6  */
7 
8 #ifndef _OCTEP_CONFIG_H_
9 #define _OCTEP_CONFIG_H_
10 
11 /* Tx instruction types by length */
12 #define OCTEP_32BYTE_INSTR  32
13 #define OCTEP_64BYTE_INSTR  64
14 
15 /* Tx Queue: maximum descriptors per ring */
16 #define OCTEP_IQ_MAX_DESCRIPTORS    1024
17 /* Minimum input (Tx) requests to be enqueued to ring doorbell */
18 #define OCTEP_DB_MIN                1
19 /* Packet threshold for Tx queue interrupt */
20 #define OCTEP_IQ_INTR_THRESHOLD     0x0
21 
22 /* Rx Queue: maximum descriptors per ring */
23 #define OCTEP_OQ_MAX_DESCRIPTORS   1024
24 
25 /* Rx buffer size: Use page size buffers.
26  * Build skb from allocated page buffer once the packet is received.
27  * When a gathered packet is received, make head page as skb head and
28  * page buffers in consecutive Rx descriptors as fragments.
29  */
30 #define OCTEP_OQ_BUF_SIZE          (SKB_WITH_OVERHEAD(PAGE_SIZE))
31 #define OCTEP_OQ_PKTS_PER_INTR     128
32 #define OCTEP_OQ_REFILL_THRESHOLD  (OCTEP_OQ_MAX_DESCRIPTORS / 4)
33 
34 #define OCTEP_OQ_INTR_PKT_THRESHOLD   1
35 #define OCTEP_OQ_INTR_TIME_THRESHOLD  10
36 
37 #define OCTEP_MSIX_NAME_SIZE      (IFNAMSIZ + 32)
38 
39 /* Tx Queue wake threshold
40  * wakeup a stopped Tx queue if minimum 2 descriptors are available.
41  * Even a skb with fragments consume only one Tx queue descriptor entry.
42  */
43 #define OCTEP_WAKE_QUEUE_THRESHOLD 2
44 
45 /* Minimum MTU supported by Octeon network interface */
46 #define OCTEP_MIN_MTU        ETH_MIN_MTU
47 /* Maximum MTU supported by Octeon interface*/
48 #define OCTEP_MAX_MTU        (10000 - (ETH_HLEN + ETH_FCS_LEN))
49 /* Default MTU */
50 #define OCTEP_DEFAULT_MTU    1500
51 
52 /* pf heartbeat interval in milliseconds */
53 #define OCTEP_DEFAULT_FW_HB_INTERVAL           1000
54 /* pf heartbeat miss count */
55 #define OCTEP_DEFAULT_FW_HB_MISS_COUNT         20
56 
57 /* Macros to get octeon config params */
58 #define CFG_GET_IQ_CFG(cfg)             ((cfg)->iq)
59 #define CFG_GET_IQ_NUM_DESC(cfg)        ((cfg)->iq.num_descs)
60 #define CFG_GET_IQ_INSTR_TYPE(cfg)      ((cfg)->iq.instr_type)
61 #define CFG_GET_IQ_PKIND(cfg)           ((cfg)->iq.pkind)
62 #define CFG_GET_IQ_INSTR_SIZE(cfg)      (64)
63 #define CFG_GET_IQ_DB_MIN(cfg)          ((cfg)->iq.db_min)
64 #define CFG_GET_IQ_INTR_THRESHOLD(cfg)  ((cfg)->iq.intr_threshold)
65 
66 #define CFG_GET_OQ_NUM_DESC(cfg)          ((cfg)->oq.num_descs)
67 #define CFG_GET_OQ_BUF_SIZE(cfg)          ((cfg)->oq.buf_size)
68 #define CFG_GET_OQ_REFILL_THRESHOLD(cfg)  ((cfg)->oq.refill_threshold)
69 #define CFG_GET_OQ_INTR_PKT(cfg)          ((cfg)->oq.oq_intr_pkt)
70 #define CFG_GET_OQ_INTR_TIME(cfg)         ((cfg)->oq.oq_intr_time)
71 
72 #define CFG_GET_PORTS_MAX_IO_RINGS(cfg)    ((cfg)->pf_ring_cfg.max_io_rings)
73 #define CFG_GET_PORTS_ACTIVE_IO_RINGS(cfg) ((cfg)->pf_ring_cfg.active_io_rings)
74 #define CFG_GET_PORTS_PF_SRN(cfg)          ((cfg)->pf_ring_cfg.srn)
75 
76 #define CFG_GET_DPI_PKIND(cfg)            ((cfg)->core_cfg.dpi_pkind)
77 #define CFG_GET_CORE_TICS_PER_US(cfg)     ((cfg)->core_cfg.core_tics_per_us)
78 #define CFG_GET_COPROC_TICS_PER_US(cfg)   ((cfg)->core_cfg.coproc_tics_per_us)
79 
80 #define CFG_GET_MAX_VFS(cfg)        ((cfg)->sriov_cfg.max_vfs)
81 #define CFG_GET_ACTIVE_VFS(cfg)     ((cfg)->sriov_cfg.active_vfs)
82 #define CFG_GET_MAX_RPVF(cfg)       ((cfg)->sriov_cfg.max_rings_per_vf)
83 #define CFG_GET_ACTIVE_RPVF(cfg)    ((cfg)->sriov_cfg.active_rings_per_vf)
84 #define CFG_GET_VF_SRN(cfg)         ((cfg)->sriov_cfg.vf_srn)
85 
86 #define CFG_GET_IOQ_MSIX(cfg)            ((cfg)->msix_cfg.ioq_msix)
87 #define CFG_GET_NON_IOQ_MSIX(cfg)        ((cfg)->msix_cfg.non_ioq_msix)
88 #define CFG_GET_NON_IOQ_MSIX_NAMES(cfg)  ((cfg)->msix_cfg.non_ioq_msix_names)
89 
90 #define CFG_GET_CTRL_MBOX_MEM_ADDR(cfg)  ((cfg)->ctrl_mbox_cfg.barmem_addr)
91 
92 /* Hardware Tx Queue configuration. */
93 struct octep_iq_config {
94 	/* Size of the Input queue (number of commands) */
95 	u16 num_descs;
96 
97 	/* Command size - 32 or 64 bytes */
98 	u16 instr_type;
99 
100 	/* pkind for packets sent to Octeon */
101 	u16 pkind;
102 
103 	/* Minimum number of commands pending to be posted to Octeon before driver
104 	 * hits the Input queue doorbell.
105 	 */
106 	u16 db_min;
107 
108 	/* Trigger the IQ interrupt when processed cmd count reaches
109 	 * this level.
110 	 */
111 	u32 intr_threshold;
112 };
113 
114 /* Hardware Rx Queue configuration. */
115 struct octep_oq_config {
116 	/* Size of Output queue (number of descriptors) */
117 	u16 num_descs;
118 
119 	/* Size of buffer in this Output queue. */
120 	u16 buf_size;
121 
122 	/* The number of buffers that were consumed during packet processing
123 	 * by the driver on this Output queue before the driver attempts to
124 	 * replenish the descriptor ring with new buffers.
125 	 */
126 	u16 refill_threshold;
127 
128 	/* Interrupt Coalescing (Packet Count). Octeon will interrupt the host
129 	 * only if it sent as many packets as specified by this field.
130 	 * The driver usually does not use packet count interrupt coalescing.
131 	 */
132 	u32 oq_intr_pkt;
133 
134 	/* Interrupt Coalescing (Time Interval). Octeon will interrupt the host
135 	 * if at least one packet was sent in the time interval specified by
136 	 * this field. The driver uses time interval interrupt coalescing by
137 	 * default. The time is specified in microseconds.
138 	 */
139 	u32 oq_intr_time;
140 };
141 
142 /* Tx/Rx configuration */
143 struct octep_pf_ring_config {
144 	/* Max number of IOQs */
145 	u16 max_io_rings;
146 
147 	/* Number of active IOQs */
148 	u16 active_io_rings;
149 
150 	/* Starting IOQ number: this changes based on which PEM is used */
151 	u16 srn;
152 };
153 
154 /* Octeon Hardware SRIOV config */
155 struct octep_sriov_config {
156 	/* Max number of VF devices supported */
157 	u16 max_vfs;
158 
159 	/* Number of VF devices enabled   */
160 	u16 active_vfs;
161 
162 	/* Max number of rings assigned to VF  */
163 	u8 max_rings_per_vf;
164 
165 	/* Number of rings enabled per VF */
166 	u8 active_rings_per_vf;
167 
168 	/* starting ring number of VF's: ring-0 of VF-0 of the PF */
169 	u16 vf_srn;
170 };
171 
172 /* Octeon MSI-x config. */
173 struct octep_msix_config {
174 	/* Number of IOQ interrupts */
175 	u16 ioq_msix;
176 
177 	/* Number of Non IOQ interrupts */
178 	u16 non_ioq_msix;
179 
180 	/* Names of Non IOQ interrupts */
181 	char **non_ioq_msix_names;
182 };
183 
184 struct octep_ctrl_mbox_config {
185 	/* Barmem address for control mbox */
186 	void __iomem *barmem_addr;
187 };
188 
189 /* Info from firmware */
190 struct octep_fw_info {
191 	/* interface pkind */
192 	u16 pkind;
193 	/* heartbeat interval in milliseconds */
194 	u16 hb_interval;
195 	/* heartbeat miss count */
196 	u16 hb_miss_count;
197 };
198 
199 /* Data Structure to hold configuration limits and active config */
200 struct octep_config {
201 	/* Input Queue attributes. */
202 	struct octep_iq_config iq;
203 
204 	/* Output Queue attributes. */
205 	struct octep_oq_config oq;
206 
207 	/* NIC Port Configuration */
208 	struct octep_pf_ring_config pf_ring_cfg;
209 
210 	/* SRIOV configuration of the PF */
211 	struct octep_sriov_config sriov_cfg;
212 
213 	/* MSI-X interrupt config */
214 	struct octep_msix_config msix_cfg;
215 
216 	/* ctrl mbox config */
217 	struct octep_ctrl_mbox_config ctrl_mbox_cfg;
218 
219 	/* fw info */
220 	struct octep_fw_info fw_info;
221 };
222 #endif /* _OCTEP_CONFIG_H_ */
223