liquidio: New driver FW command structure
[deliverable/linux.git] / drivers / net / ethernet / cavium / liquidio / octeon_droq.h
CommitLineData
f21fb3ed
RV
1/**********************************************************************
2 * Author: Cavium, Inc.
3 *
4 * Contact: support@cavium.com
5 * Please include "LiquidIO" in the subject.
6 *
7 * Copyright (c) 2003-2015 Cavium, Inc.
8 *
9 * This file is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License, Version 2, as
11 * published by the Free Software Foundation.
12 *
13 * This file is distributed in the hope that it will be useful, but
14 * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16 * NONINFRINGEMENT. See the GNU General Public License for more
17 * details.
18 *
19 * This file may also be available under a different license from Cavium.
20 * Contact Cavium, Inc. for more information
21 **********************************************************************/
22
23/*! \file octeon_droq.h
24 * \brief Implementation of Octeon Output queues. "Output" is with
25 * respect to the Octeon device on the NIC. From this driver's point of
26 * view they are ingress queues.
27 */
28
29#ifndef __OCTEON_DROQ_H__
30#define __OCTEON_DROQ_H__
31
32/* Default number of packets that will be processed in one iteration. */
33#define MAX_PACKET_BUDGET 0xFFFFFFFF
34
35/** Octeon descriptor format.
36 * The descriptor ring is made of descriptors which have 2 64-bit values:
37 * -# Physical (bus) address of the data buffer.
38 * -# Physical (bus) address of a octeon_droq_info structure.
39 * The Octeon device DMA's incoming packets and its information at the address
40 * given by these descriptor fields.
41 */
42struct octeon_droq_desc {
43 /** The buffer pointer */
44 u64 buffer_ptr;
45
46 /** The Info pointer */
47 u64 info_ptr;
48};
49
50#define OCT_DROQ_DESC_SIZE (sizeof(struct octeon_droq_desc))
51
52/** Information about packet DMA'ed by Octeon.
53 * The format of the information available at Info Pointer after Octeon
54 * has posted a packet. Not all descriptors have valid information. Only
55 * the Info field of the first descriptor for a packet has information
56 * about the packet.
57 */
58struct octeon_droq_info {
59 /** The Output Receive Header. */
60 union octeon_rh rh;
61
62 /** The Length of the packet. */
63 u64 length;
64};
65
66#define OCT_DROQ_INFO_SIZE (sizeof(struct octeon_droq_info))
67
cabeb13b
RV
68struct octeon_skb_page_info {
69 /* DMA address for the page */
70 dma_addr_t dma;
71
72 /* Page for the rx dma **/
73 struct page *page;
74
75 /** which offset into page */
76 unsigned int page_offset;
77};
78
f21fb3ed
RV
79/** Pointer to data buffer.
80 * Driver keeps a pointer to the data buffer that it made available to
81 * the Octeon device. Since the descriptor ring keeps physical (bus)
82 * addresses, this field is required for the driver to keep track of
83 * the virtual address pointers.
84*/
85struct octeon_recv_buffer {
86 /** Packet buffer, including metadata. */
87 void *buffer;
88
89 /** Data in the packet buffer. */
90 u8 *data;
cabeb13b
RV
91
92 /** pg_info **/
93 struct octeon_skb_page_info pg_info;
f21fb3ed
RV
94};
95
96#define OCT_DROQ_RECVBUF_SIZE (sizeof(struct octeon_recv_buffer))
97
98/** Output Queue statistics. Each output queue has four stats fields. */
99struct oct_droq_stats {
100 /** Number of packets received in this queue. */
101 u64 pkts_received;
102
103 /** Bytes received by this queue. */
104 u64 bytes_received;
105
106 /** Packets dropped due to no dispatch function. */
107 u64 dropped_nodispatch;
108
109 /** Packets dropped due to no memory available. */
110 u64 dropped_nomem;
111
112 /** Packets dropped due to large number of pkts to process. */
113 u64 dropped_toomany;
114
115 /** Number of packets sent to stack from this queue. */
116 u64 rx_pkts_received;
117
118 /** Number of Bytes sent to stack from this queue. */
119 u64 rx_bytes_received;
120
121 /** Num of Packets dropped due to receive path failures. */
122 u64 rx_dropped;
cabeb13b
RV
123
124 /** Num of failures of recv_buffer_alloc() */
125 u64 rx_alloc_failure;
126
f21fb3ed
RV
127};
128
129#define POLL_EVENT_INTR_ARRIVED 1
130#define POLL_EVENT_PROCESS_PKTS 2
131#define POLL_EVENT_PENDING_PKTS 3
132#define POLL_EVENT_ENABLE_INTR 4
133
134/* The maximum number of buffers that can be dispatched from the
135 * output/dma queue. Set to 64 assuming 1K buffers in DROQ and the fact that
136 * max packet size from DROQ is 64K.
137 */
138#define MAX_RECV_BUFS 64
139
140/** Receive Packet format used when dispatching output queue packets
141 * with non-raw opcodes.
142 * The received packet will be sent to the upper layers using this
143 * structure which is passed as a parameter to the dispatch function
144 */
145struct octeon_recv_pkt {
146 /** Number of buffers in this received packet */
147 u16 buffer_count;
148
149 /** Id of the device that is sending the packet up */
150 u16 octeon_id;
151
152 /** Length of data in the packet buffer */
153 u32 length;
154
155 /** The receive header */
156 union octeon_rh rh;
157
158 /** Pointer to the OS-specific packet buffer */
159 void *buffer_ptr[MAX_RECV_BUFS];
160
161 /** Size of the buffers pointed to by ptr's in buffer_ptr */
162 u32 buffer_size[MAX_RECV_BUFS];
163};
164
165#define OCT_RECV_PKT_SIZE (sizeof(struct octeon_recv_pkt))
166
167/** The first parameter of a dispatch function.
168 * For a raw mode opcode, the driver dispatches with the device
169 * pointer in this structure.
170 * For non-raw mode opcode, the driver dispatches the recv_pkt
171 * created to contain the buffers with data received from Octeon.
172 * ---------------------
173 * | *recv_pkt ----|---
174 * |-------------------| |
175 * | 0 or more bytes | |
176 * | reserved by driver| |
177 * |-------------------|<-/
178 * | octeon_recv_pkt |
179 * | |
180 * |___________________|
181 */
182struct octeon_recv_info {
183 void *rsvd;
184 struct octeon_recv_pkt *recv_pkt;
185};
186
187#define OCT_RECV_INFO_SIZE (sizeof(struct octeon_recv_info))
188
189/** Allocate a recv_info structure. The recv_pkt pointer in the recv_info
190 * structure is filled in before this call returns.
191 * @param extra_bytes - extra bytes to be allocated at the end of the recv info
192 * structure.
193 * @return - pointer to a newly allocated recv_info structure.
194 */
195static inline struct octeon_recv_info *octeon_alloc_recv_info(int extra_bytes)
196{
197 struct octeon_recv_info *recv_info;
198 u8 *buf;
199
200 buf = kmalloc(OCT_RECV_PKT_SIZE + OCT_RECV_INFO_SIZE +
201 extra_bytes, GFP_ATOMIC);
202 if (!buf)
203 return NULL;
204
205 recv_info = (struct octeon_recv_info *)buf;
206 recv_info->recv_pkt =
207 (struct octeon_recv_pkt *)(buf + OCT_RECV_INFO_SIZE);
208 recv_info->rsvd = NULL;
209 if (extra_bytes)
210 recv_info->rsvd = buf + OCT_RECV_INFO_SIZE + OCT_RECV_PKT_SIZE;
211
212 return recv_info;
213}
214
215/** Free a recv_info structure.
216 * @param recv_info - Pointer to receive_info to be freed
217 */
218static inline void octeon_free_recv_info(struct octeon_recv_info *recv_info)
219{
220 kfree(recv_info);
221}
222
223typedef int (*octeon_dispatch_fn_t)(struct octeon_recv_info *, void *);
224
225/** Used by NIC module to register packet handler and to get device
226 * information for each octeon device.
227 */
228struct octeon_droq_ops {
229 /** This registered function will be called by the driver with
230 * the octeon id, pointer to buffer from droq and length of
231 * data in the buffer. The receive header gives the port
232 * number to the caller. Function pointer is set by caller.
233 */
234 void (*fptr)(u32, void *, u32, union octeon_rh *, void *);
235
236 /* This function will be called by the driver for all NAPI related
237 * events. The first param is the octeon id. The second param is the
238 * output queue number. The third is the NAPI event that occurred.
239 */
240 void (*napi_fn)(void *);
241
242 u32 poll_mode;
243
244 /** Flag indicating if the DROQ handler should drop packets that
245 * it cannot handle in one iteration. Set by caller.
246 */
247 u32 drop_on_max;
248};
249
250/** The Descriptor Ring Output Queue structure.
251 * This structure has all the information required to implement a
252 * Octeon DROQ.
253 */
254struct octeon_droq {
255 /** A spinlock to protect access to this ring. */
256 spinlock_t lock;
257
258 u32 q_no;
259
260 struct octeon_droq_ops ops;
261
262 struct octeon_device *oct_dev;
263
264 /** The 8B aligned descriptor ring starts at this address. */
265 struct octeon_droq_desc *desc_ring;
266
267 /** Index in the ring where the driver should read the next packet */
268 u32 read_idx;
269
270 /** Index in the ring where Octeon will write the next packet */
271 u32 write_idx;
272
273 /** Index in the ring where the driver will refill the descriptor's
274 * buffer
275 */
276 u32 refill_idx;
277
278 /** Packets pending to be processed */
279 atomic_t pkts_pending;
280
281 /** Number of descriptors in this ring. */
282 u32 max_count;
283
284 /** The number of descriptors pending refill. */
285 u32 refill_count;
286
287 u32 pkts_per_intr;
288 u32 refill_threshold;
289
290 /** The max number of descriptors in DROQ without a buffer.
291 * This field is used to keep track of empty space threshold. If the
292 * refill_count reaches this value, the DROQ cannot accept a max-sized
293 * (64K) packet.
294 */
295 u32 max_empty_descs;
296
297 /** The 8B aligned info ptrs begin from this address. */
298 struct octeon_droq_info *info_list;
299
300 /** The receive buffer list. This list has the virtual addresses of the
301 * buffers.
302 */
303 struct octeon_recv_buffer *recv_buf_list;
304
305 /** The size of each buffer pointed by the buffer pointer. */
306 u32 buffer_size;
307
308 /** Pointer to the mapped packet credit register.
309 * Host writes number of info/buffer ptrs available to this register
310 */
311 void __iomem *pkts_credit_reg;
312
313 /** Pointer to the mapped packet sent register.
314 * Octeon writes the number of packets DMA'ed to host memory
315 * in this register.
316 */
317 void __iomem *pkts_sent_reg;
318
319 struct list_head dispatch_list;
320
321 /** Statistics for this DROQ. */
322 struct oct_droq_stats stats;
323
324 /** DMA mapped address of the DROQ descriptor ring. */
325 size_t desc_ring_dma;
326
327 /** Info ptr list are allocated at this virtual address. */
328 size_t info_base_addr;
329
330 /** DMA mapped address of the info list */
331 size_t info_list_dma;
332
333 /** Allocated size of info list. */
334 u32 info_alloc_size;
335
336 /** application context */
337 void *app_ctx;
338
339 struct napi_struct napi;
340
341 u32 cpu_id;
342
343 struct call_single_data csd;
344};
345
346#define OCT_DROQ_SIZE (sizeof(struct octeon_droq))
347
348/**
349 * Allocates space for the descriptor ring for the droq and sets the
350 * base addr, num desc etc in Octeon registers.
351 *
352 * @param oct_dev - pointer to the octeon device structure
353 * @param q_no - droq no. ranges from 0 - 3.
354 * @param app_ctx - pointer to application context
355 * @return Success: 0 Failure: 1
356*/
357int octeon_init_droq(struct octeon_device *oct_dev,
358 u32 q_no,
359 u32 num_descs,
360 u32 desc_size,
361 void *app_ctx);
362
363/**
364 * Frees the space for descriptor ring for the droq.
365 *
366 * @param oct_dev - pointer to the octeon device structure
367 * @param q_no - droq no. ranges from 0 - 3.
368 * @return: Success: 0 Failure: 1
369*/
370int octeon_delete_droq(struct octeon_device *oct_dev, u32 q_no);
371
372/** Register a change in droq operations. The ops field has a pointer to a
373 * function which will called by the DROQ handler for all packets arriving
374 * on output queues given by q_no irrespective of the type of packet.
375 * The ops field also has a flag which if set tells the DROQ handler to
376 * drop packets if it receives more than what it can process in one
377 * invocation of the handler.
378 * @param oct - octeon device
379 * @param q_no - octeon output queue number (0 <= q_no <= MAX_OCTEON_DROQ-1
380 * @param ops - the droq_ops settings for this queue
381 * @return - 0 on success, -ENODEV or -EINVAL on error.
382 */
383int
384octeon_register_droq_ops(struct octeon_device *oct,
385 u32 q_no,
386 struct octeon_droq_ops *ops);
387
388/** Resets the function pointer and flag settings made by
389 * octeon_register_droq_ops(). After this routine is called, the DROQ handler
390 * will lookup dispatch function for each arriving packet on the output queue
391 * given by q_no.
392 * @param oct - octeon device
393 * @param q_no - octeon output queue number (0 <= q_no <= MAX_OCTEON_DROQ-1
394 * @return - 0 on success, -ENODEV or -EINVAL on error.
395 */
396int octeon_unregister_droq_ops(struct octeon_device *oct, u32 q_no);
397
398/** Register a dispatch function for a opcode/subcode. The driver will call
399 * this dispatch function when it receives a packet with the given
400 * opcode/subcode in its output queues along with the user specified
401 * argument.
402 * @param oct - the octeon device to register with.
403 * @param opcode - the opcode for which the dispatch will be registered.
404 * @param subcode - the subcode for which the dispatch will be registered
405 * @param fn - the dispatch function.
406 * @param fn_arg - user specified that will be passed along with the
407 * dispatch function by the driver.
408 * @return Success: 0; Failure: 1
409 */
410int octeon_register_dispatch_fn(struct octeon_device *oct,
411 u16 opcode,
412 u16 subcode,
413 octeon_dispatch_fn_t fn, void *fn_arg);
414
415/** Remove registration for an opcode/subcode. This will delete the mapping for
416 * an opcode/subcode. The dispatch function will be unregistered and will no
417 * longer be called if a packet with the opcode/subcode arrives in the driver
418 * output queues.
419 * @param oct - the octeon device to unregister from.
420 * @param opcode - the opcode to be unregistered.
421 * @param subcode - the subcode to be unregistered.
422 *
423 * @return Success: 0; Failure: 1
424 */
425int octeon_unregister_dispatch_fn(struct octeon_device *oct,
426 u16 opcode,
427 u16 subcode);
428
429void octeon_droq_print_stats(void);
430
431u32 octeon_droq_check_hw_for_pkts(struct octeon_device *oct,
432 struct octeon_droq *droq);
433
434int octeon_create_droq(struct octeon_device *oct, u32 q_no,
435 u32 num_descs, u32 desc_size, void *app_ctx);
436
437int octeon_droq_process_packets(struct octeon_device *oct,
438 struct octeon_droq *droq,
439 u32 budget);
440
441int octeon_process_droq_poll_cmd(struct octeon_device *oct, u32 q_no,
442 int cmd, u32 arg);
443
444#endif /*__OCTEON_DROQ_H__ */
This page took 0.143508 seconds and 5 git commands to generate.