1 /**********************************************************************
4 * Contact: support@cavium.com
5 * Please include "LiquidIO" in the subject.
7 * Copyright (c) 2003-2016 Cavium, Inc.
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.
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 details.
17 ***********************************************************************/
19 * \brief Host Driver: Implementation of Octeon input queues. "Input" is
20 * with respect to the Octeon device on the NIC. From this driver's
21 * point of view they are egress queues.
24 #ifndef __OCTEON_IQ_H__
25 #define __OCTEON_IQ_H__
27 #define IQ_STATUS_RUNNING 1
30 #define IQ_SEND_STOP 1
31 #define IQ_SEND_FAILED -1
33 /*------------------------- INSTRUCTION QUEUE --------------------------*/
37 #define REQTYPE_NONE 0
38 #define REQTYPE_NORESP_NET 1
39 #define REQTYPE_NORESP_NET_SG 2
40 #define REQTYPE_RESP_NET 3
41 #define REQTYPE_RESP_NET_SG 4
42 #define REQTYPE_SOFT_COMMAND 5
43 #define REQTYPE_LAST 5
45 struct octeon_request_list
{
52 /** Input Queue statistics. Each input queue has four stats fields. */
54 u64 instr_posted
; /**< Instructions posted to this queue. */
55 u64 instr_processed
; /**< Instructions processed in this queue. */
56 u64 instr_dropped
; /**< Instructions that could not be processed */
57 u64 bytes_sent
; /**< Bytes sent through this queue. */
58 u64 sgentry_sent
;/**< Gather entries sent through this queue. */
59 u64 tx_done
;/**< Num of packets sent to network. */
60 u64 tx_iq_busy
;/**< Numof times this iq was found to be full. */
61 u64 tx_dropped
;/**< Numof pkts dropped dueto xmitpath errors. */
62 u64 tx_tot_bytes
;/**< Total count of bytes sento to network. */
63 u64 tx_gso
; /* count of tso */
64 u64 tx_vxlan
; /* tunnel */
65 u64 tx_dmamap_fail
; /* Number of times dma mapping failed */
66 u64 tx_restart
; /* Number of times this queue restarted */
69 #define OCT_IQ_STATS_SIZE (sizeof(struct oct_iq_stats))
71 /** The instruction (input) queue.
72 * The input queue is used to post raw (instruction) mode data or packet
73 * data to Octeon device from the host. Each input queue (upto 4) for
74 * a Octeon device has one such structure to represent it.
76 struct octeon_instr_queue
{
77 struct octeon_device
*oct_dev
;
79 /** A spinlock to protect access to the input ring. */
82 /** A spinlock to protect while posting on the ring. */
85 /** This flag indicates if the queue can be used for soft commands.
86 * If this flag is set, post_lock must be acquired before posting
87 * a command to the queue.
88 * If this flag is clear, post_lock is invalid for the queue.
89 * All control commands (soft commands) will go through only Queue 0
90 * (control and data queue). So only queue-0 needs post_lock,
91 * other queues are only data queues and does not need post_lock
99 /** A spinlock to protect access to the input ring.*/
100 spinlock_t iq_flush_running_lock
;
102 /** Flag that indicates if the queue uses 64 byte commands. */
106 union oct_txpciq txpciq
;
110 /* Controls whether extra flushing of IQ is done on Tx */
115 /** Maximum no. of instructions in this queue. */
118 /** Index in input ring where the driver should write the next packet */
119 u32 host_write_index
;
121 /** Index in input ring where Octeon is expected to read the next
124 u32 octeon_read_index
;
126 /** This index aids in finding the window in the queue where Octeon
127 * has read the commands.
131 /** This field keeps track of the instructions pending in this queue. */
132 atomic_t instr_pending
;
136 /** Pointer to the Virtual Base addr of the input ring. */
139 struct octeon_request_list
*request_list
;
141 /** Octeon doorbell register for the ring. */
142 void __iomem
*doorbell_reg
;
144 /** Octeon instruction count register for this ring. */
145 void __iomem
*inst_cnt_reg
;
147 /** Number of instructions pending to be posted to Octeon. */
150 /** The max. number of instructions that can be held pending by the
155 /** The last time that the doorbell was rung. */
158 /** The doorbell timeout. If the doorbell was not rung for this time and
159 * fill_cnt is non-zero, ring the doorbell again.
163 /** Statistics for this input queue. */
164 struct oct_iq_stats stats
;
166 /** DMA mapped base address of the input descriptor ring. */
167 dma_addr_t base_addr_dma
;
169 /** Application context */
172 /* network stack queue index */
175 /*os ifidx associated with this queue */
180 /*---------------------- INSTRUCTION FORMAT ----------------------------*/
182 /** 32-byte instruction format.
183 * Format of instruction for a 32-byte mode input queue.
185 struct octeon_instr_32B
{
186 /** Pointer where the input data is available. */
189 /** Instruction Header. */
192 /** Pointer where the response for a RAW mode packet will be written
197 /** Input Request Header. Additional info about the input. */
202 #define OCT_32B_INSTR_SIZE (sizeof(struct octeon_instr_32B))
204 /** 64-byte instruction format.
205 * Format of instruction for a 64-byte mode input queue.
207 struct octeon_instr2_64B
{
208 /** Pointer where the input data is available. */
211 /** Instruction Header. */
214 /** Input Request Header. */
217 /** opcode/subcode specific parameters */
220 /** Return Data Parameters */
223 /** Pointer where the response for a RAW mode packet will be written
231 struct octeon_instr3_64B
{
232 /** Pointer where the input data is available. */
235 /** Instruction Header. */
238 /** Instruction Header. */
241 /** Input Request Header. */
244 /** opcode/subcode specific parameters */
247 /** Return Data Parameters */
250 /** Pointer where the response for a RAW mode packet will be written
257 union octeon_instr_64B
{
258 struct octeon_instr2_64B cmd2
;
259 struct octeon_instr3_64B cmd3
;
262 #define OCT_64B_INSTR_SIZE (sizeof(union octeon_instr_64B))
264 /** The size of each buffer in soft command buffer pool
266 #define SOFT_COMMAND_BUFFER_SIZE 2048
268 struct octeon_soft_command
{
269 /** Soft command buffer info. */
270 struct list_head node
;
274 /** Command and return status */
275 union octeon_instr_64B cmd
;
277 #define COMPLETION_WORD_INIT 0xffffffffffffffffULL
280 /** Data buffer info */
285 /** Return buffer info */
290 /** Context buffer info */
294 /** Time out and callback */
297 void (*callback
)(struct octeon_device
*, u32
, void *);
302 struct completion complete
;
305 /* max timeout (in milli sec) for soft request */
306 #define LIO_SC_MAX_TMO_MS 60000
308 /** Maximum number of buffers to allocate into soft command buffer pool
310 #define MAX_SOFT_COMMAND_BUFFERS 256
312 /** Head of a soft command buffer pool.
314 struct octeon_sc_buffer_pool
{
315 /** List structure to add delete pending entries to */
316 struct list_head head
;
318 /** A lock for this response list */
321 atomic_t alloc_buf_count
;
324 #define INCR_INSTRQUEUE_PKT_COUNT(octeon_dev_ptr, iq_no, field, count) \
325 (((octeon_dev_ptr)->instr_queue[iq_no]->stats.field) += count)
327 int octeon_setup_sc_buffer_pool(struct octeon_device
*oct
);
328 int octeon_free_sc_done_list(struct octeon_device
*oct
);
329 int octeon_free_sc_zombie_list(struct octeon_device
*oct
);
330 int octeon_free_sc_buffer_pool(struct octeon_device
*oct
);
331 struct octeon_soft_command
*
332 octeon_alloc_soft_command(struct octeon_device
*oct
,
333 u32 datasize
, u32 rdatasize
,
335 void octeon_free_soft_command(struct octeon_device
*oct
,
336 struct octeon_soft_command
*sc
);
339 * octeon_init_instr_queue()
340 * @param octeon_dev - pointer to the octeon device structure.
341 * @param txpciq - queue to be initialized (0 <= q_no <= 3).
343 * Called at driver init time for each input queue. iq_conf has the
344 * configuration parameters for the queue.
346 * @return Success: 0 Failure: 1
348 int octeon_init_instr_queue(struct octeon_device
*octeon_dev
,
349 union oct_txpciq txpciq
,
353 * octeon_delete_instr_queue()
354 * @param octeon_dev - pointer to the octeon device structure.
355 * @param iq_no - queue to be deleted (0 <= q_no <= 3).
357 * Called at driver unload time for each input queue. Deletes all
358 * allocated resources for the input queue.
360 * @return Success: 0 Failure: 1
362 int octeon_delete_instr_queue(struct octeon_device
*octeon_dev
, u32 iq_no
);
364 int lio_wait_for_instr_fetch(struct octeon_device
*oct
);
367 octeon_ring_doorbell_locked(struct octeon_device
*oct
, u32 iq_no
);
370 octeon_register_reqtype_free_fn(struct octeon_device
*oct
, int reqtype
,
374 lio_process_iq_request_list(struct octeon_device
*oct
,
375 struct octeon_instr_queue
*iq
, u32 napi_budget
);
377 int octeon_send_command(struct octeon_device
*oct
, u32 iq_no
,
378 u32 force_db
, void *cmd
, void *buf
,
379 u32 datasize
, u32 reqtype
);
381 void octeon_dump_soft_command(struct octeon_device
*oct
,
382 struct octeon_soft_command
*sc
);
384 void octeon_prepare_soft_command(struct octeon_device
*oct
,
385 struct octeon_soft_command
*sc
,
386 u8 opcode
, u8 subcode
,
387 u32 irh_ossp
, u64 ossp0
,
390 int octeon_send_soft_command(struct octeon_device
*oct
,
391 struct octeon_soft_command
*sc
);
393 int octeon_setup_iq(struct octeon_device
*oct
, int ifidx
,
394 int q_index
, union oct_txpciq iq_no
, u32 num_descs
,
397 octeon_flush_iq(struct octeon_device
*oct
, struct octeon_instr_queue
*iq
,
399 #endif /* __OCTEON_IQ_H__ */