1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Marvell Octeon EP (EndPoint) Ethernet Driver
4 * Copyright (C) 2020 Marvell.
12 #define IQ_SEND_STOP 1
13 #define IQ_SEND_FAILED -1
15 #define TX_BUFTYPE_NONE 0
16 #define TX_BUFTYPE_NET 1
17 #define TX_BUFTYPE_NET_SG 2
18 #define NUM_TX_BUFTYPES 3
20 /* Hardware format for Scatter/Gather list */
21 struct octep_tx_sglist_desc {
23 dma_addr_t dma_ptr[4];
26 /* Each Scatter/Gather entry sent to hardwar hold four pointers.
27 * So, number of entries required is (MAX_SKB_FRAGS + 1)/4, where '+1'
28 * is for main skb which also goes as a gather buffer to Octeon hardware.
29 * To allocate sufficient SGLIST entries for a packet with max fragments,
30 * align by adding 3 before calcuating max SGLIST entries per packet.
32 #define OCTEP_SGLIST_ENTRIES_PER_PKT ((MAX_SKB_FRAGS + 1 + 3) / 4)
33 #define OCTEP_SGLIST_SIZE_PER_PKT \
34 (OCTEP_SGLIST_ENTRIES_PER_PKT * sizeof(struct octep_tx_sglist_desc))
36 struct octep_tx_buffer {
39 struct octep_tx_sglist_desc *sglist;
40 dma_addr_t sglist_dma;
44 #define OCTEP_IQ_TXBUFF_INFO_SIZE (sizeof(struct octep_tx_buffer))
46 /* Hardware interface Tx statistics */
47 struct octep_iface_tx_stats {
48 /* Packets dropped due to excessive collisions */
51 /* Packets dropped due to excessive deferral */
54 /* Packets sent that experienced multiple collisions before successful
59 /* Packets sent that experienced a single collision before successful
64 /* Total octets sent on the interface */
67 /* Total frames sent on the interface */
70 /* Packets sent with an octet count < 64 */
73 /* Packets sent with an octet count == 64 */
76 /* Packets sent with an octet count of 65–127 */
79 /* Packets sent with an octet count of 128–255 */
82 /* Packets sent with an octet count of 256–511 */
85 /* Packets sent with an octet count of 512–1023 */
88 /* Packets sent with an octet count of 1024-1518 */
91 /* Packets sent with an octet count of > 1518 */
94 /* Packets sent to a broadcast DMAC */
97 /* Packets sent to the multicast DMAC */
100 /* Packets sent that experienced a transmit underflow and were
105 /* Control/PAUSE packets sent */
109 /* Input Queue statistics. Each input queue has four stats fields. */
110 struct octep_iq_stats {
111 /* Instructions posted to this queue. */
114 /* Instructions copied by hardware for processing. */
117 /* Instructions that could not be processed. */
120 /* Bytes sent through this queue. */
123 /* Gather entries sent through this queue. */
126 /* Number of transmit failures due to TX_BUSY */
129 /* Number of times the queue is restarted */
133 /* The instruction (input) queue.
134 * The input queue is used to post raw (instruction) mode data or packet
135 * data to Octeon device from the host. Each input queue (up to 4) for
136 * a Octeon device has one such structure to represent it.
141 struct octep_device *octep_dev;
142 struct net_device *netdev;
144 struct netdev_queue *netdev_q;
146 /* Index in input ring where driver should write the next packet */
147 u16 host_write_index;
149 /* Index in input ring where Octeon is expected to read next packet */
150 u16 octep_read_index;
152 /* This index aids in finding the window in the queue where Octeon
153 * has read the commands.
157 /* Statistics for this input queue. */
158 struct octep_iq_stats stats;
160 /* This field keeps track of the instructions pending in this queue. */
161 atomic_t instr_pending;
163 /* Pointer to the Virtual Base addr of the input ring. */
164 struct octep_tx_desc_hw *desc_ring;
166 /* DMA mapped base address of the input descriptor ring. */
167 dma_addr_t desc_ring_dma;
169 /* Info of Tx buffers pending completion. */
170 struct octep_tx_buffer *buff_info;
172 /* Base pointer to Scatter/Gather lists for all ring descriptors. */
173 struct octep_tx_sglist_desc *sglist;
175 /* DMA mapped addr of Scatter Gather Lists */
176 dma_addr_t sglist_dma;
178 /* Octeon doorbell register for the ring. */
179 u8 __iomem *doorbell_reg;
181 /* Octeon instruction count register for this ring. */
182 u8 __iomem *inst_cnt_reg;
184 /* interrupt level register for this ring */
185 u8 __iomem *intr_lvl_reg;
187 /* Maximum no. of instructions in this queue. */
196 /* Number of instructions pending to be posted to Octeon. */
199 /* The max. number of instructions that can be held pending by the
200 * driver before ringing doorbell.
205 /* Hardware Tx Instruction Header */
206 struct octep_instr_hdr {
216 /* Front Data size */
219 /* No. of entries in gather list */
222 /* Gather indicator 1=gather*/
229 /* Hardware Tx completion response header */
230 struct octep_instr_resp_hdr {
234 /* PCIe port to use for response */
237 /* Scatter indicator 1=scatter */
240 /* Size of Expected result OR no. of entries in scatter list */
243 /* Desired destination port for result */
246 /* Opcode Specific parameters */
249 /* Opcode for the return packet */
253 /* 64-byte Tx instruction format.
254 * Format of instruction for a 64-byte mode input queue.
256 * only first 16-bytes (dptr and ih) are mandatory; rest are optional
257 * and filled by the driver based on firmware/hardware capabilities.
258 * These optional headers together called Front Data and its size is
259 * described by ih->fsz.
261 struct octep_tx_desc_hw {
262 /* Pointer where the input data is available. */
265 /* Instruction Header. */
267 struct octep_instr_hdr ih;
271 /* Pointer where the response for a RAW mode packet will be written
276 /* Input Instruction Response Header. */
277 struct octep_instr_resp_hdr irh;
279 /* Additional headers available in a 64-byte instruction. */
283 #define OCTEP_IQ_DESC_SIZE (sizeof(struct octep_tx_desc_hw))
284 #endif /* _OCTEP_TX_H_ */