blob: 14c5d70486d3c5bcb992f457da3046e8a1397b76 [file] [log] [blame]
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001/**********************************************************************
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_iq.h
24 * \brief Host Driver: Implementation of Octeon input queues. "Input" is
25 * with respect to the Octeon device on the NIC. From this driver's
26 * point of view they are egress queues.
27 */
28
29#ifndef __OCTEON_IQ_H__
30#define __OCTEON_IQ_H__
31
32#define IQ_STATUS_RUNNING 1
33
34#define IQ_SEND_OK 0
35#define IQ_SEND_STOP 1
36#define IQ_SEND_FAILED -1
37
38/*------------------------- INSTRUCTION QUEUE --------------------------*/
39
40/* \cond */
41
42#define REQTYPE_NONE 0
43#define REQTYPE_NORESP_NET 1
44#define REQTYPE_NORESP_NET_SG 2
45#define REQTYPE_RESP_NET 3
46#define REQTYPE_RESP_NET_SG 4
47#define REQTYPE_SOFT_COMMAND 5
48#define REQTYPE_LAST 5
49
50struct octeon_request_list {
51 u32 reqtype;
52 void *buf;
53};
54
55/* \endcond */
56
57/** Input Queue statistics. Each input queue has four stats fields. */
58struct oct_iq_stats {
59 u64 instr_posted; /**< Instructions posted to this queue. */
60 u64 instr_processed; /**< Instructions processed in this queue. */
61 u64 instr_dropped; /**< Instructions that could not be processed */
62 u64 bytes_sent; /**< Bytes sent through this queue. */
63 u64 sgentry_sent;/**< Gather entries sent through this queue. */
64 u64 tx_done;/**< Num of packets sent to network. */
65 u64 tx_iq_busy;/**< Numof times this iq was found to be full. */
66 u64 tx_dropped;/**< Numof pkts dropped dueto xmitpath errors. */
67 u64 tx_tot_bytes;/**< Total count of bytes sento to network. */
68};
69
70#define OCT_IQ_STATS_SIZE (sizeof(struct oct_iq_stats))
71
72/** The instruction (input) queue.
73 * The input queue is used to post raw (instruction) mode data or packet
74 * data to Octeon device from the host. Each input queue (upto 4) for
75 * a Octeon device has one such structure to represent it.
76*/
77struct octeon_instr_queue {
78 /** A spinlock to protect access to the input ring. */
79 spinlock_t lock;
80
81 /** Flag that indicates if the queue uses 64 byte commands. */
82 u32 iqcmd_64B:1;
83
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -070084 /** Queue info. */
85 union oct_txpciq txpciq;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070086
87 u32 rsvd:17;
88
89 /* Controls the periodic flushing of iq */
90 u32 do_auto_flush:1;
91
92 u32 status:8;
93
94 /** Maximum no. of instructions in this queue. */
95 u32 max_count;
96
97 /** Index in input ring where the driver should write the next packet */
98 u32 host_write_index;
99
100 /** Index in input ring where Octeon is expected to read the next
101 * packet.
102 */
103 u32 octeon_read_index;
104
105 /** This index aids in finding the window in the queue where Octeon
106 * has read the commands.
107 */
108 u32 flush_index;
109
110 /** This field keeps track of the instructions pending in this queue. */
111 atomic_t instr_pending;
112
113 u32 reset_instr_cnt;
114
115 /** Pointer to the Virtual Base addr of the input ring. */
116 u8 *base_addr;
117
118 struct octeon_request_list *request_list;
119
120 /** Octeon doorbell register for the ring. */
121 void __iomem *doorbell_reg;
122
123 /** Octeon instruction count register for this ring. */
124 void __iomem *inst_cnt_reg;
125
126 /** Number of instructions pending to be posted to Octeon. */
127 u32 fill_cnt;
128
129 /** The max. number of instructions that can be held pending by the
130 * driver.
131 */
132 u32 fill_threshold;
133
134 /** The last time that the doorbell was rung. */
135 u64 last_db_time;
136
137 /** The doorbell timeout. If the doorbell was not rung for this time and
138 * fill_cnt is non-zero, ring the doorbell again.
139 */
140 u32 db_timeout;
141
142 /** Statistics for this input queue. */
143 struct oct_iq_stats stats;
144
145 /** DMA mapped base address of the input descriptor ring. */
146 u64 base_addr_dma;
147
148 /** Application context */
149 void *app_ctx;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700150
151 /* network stack queue index */
152 int q_index;
153
154 /*os ifidx associated with this queue */
155 int ifidx;
156
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700157};
158
159/*---------------------- INSTRUCTION FORMAT ----------------------------*/
160
161/** 32-byte instruction format.
162 * Format of instruction for a 32-byte mode input queue.
163 */
164struct octeon_instr_32B {
165 /** Pointer where the input data is available. */
166 u64 dptr;
167
168 /** Instruction Header. */
169 u64 ih;
170
171 /** Pointer where the response for a RAW mode packet will be written
172 * by Octeon.
173 */
174 u64 rptr;
175
176 /** Input Request Header. Additional info about the input. */
177 u64 irh;
178
179};
180
181#define OCT_32B_INSTR_SIZE (sizeof(struct octeon_instr_32B))
182
183/** 64-byte instruction format.
184 * Format of instruction for a 64-byte mode input queue.
185 */
186struct octeon_instr_64B {
187 /** Pointer where the input data is available. */
188 u64 dptr;
189
190 /** Instruction Header. */
191 u64 ih;
192
193 /** Input Request Header. */
194 u64 irh;
195
196 /** opcode/subcode specific parameters */
197 u64 ossp[2];
198
199 /** Return Data Parameters */
200 u64 rdp;
201
202 /** Pointer where the response for a RAW mode packet will be written
203 * by Octeon.
204 */
205 u64 rptr;
206
207 u64 reserved;
208
209};
210
211#define OCT_64B_INSTR_SIZE (sizeof(struct octeon_instr_64B))
212
213/** The size of each buffer in soft command buffer pool
214 */
215#define SOFT_COMMAND_BUFFER_SIZE 1024
216
217struct octeon_soft_command {
218 /** Soft command buffer info. */
219 struct list_head node;
220 u64 dma_addr;
221 u32 size;
222
223 /** Command and return status */
224 struct octeon_instr_64B cmd;
225#define COMPLETION_WORD_INIT 0xffffffffffffffffULL
226 u64 *status_word;
227
228 /** Data buffer info */
229 void *virtdptr;
230 u64 dmadptr;
231 u32 datasize;
232
233 /** Return buffer info */
234 void *virtrptr;
235 u64 dmarptr;
236 u32 rdatasize;
237
238 /** Context buffer info */
239 void *ctxptr;
240 u32 ctxsize;
241
242 /** Time out and callback */
243 size_t wait_time;
244 size_t timeout;
245 u32 iq_no;
246 void (*callback)(struct octeon_device *, u32, void *);
247 void *callback_arg;
248};
249
250/** Maximum number of buffers to allocate into soft command buffer pool
251 */
252#define MAX_SOFT_COMMAND_BUFFERS 16
253
254/** Head of a soft command buffer pool.
255 */
256struct octeon_sc_buffer_pool {
257 /** List structure to add delete pending entries to */
258 struct list_head head;
259
260 /** A lock for this response list */
261 spinlock_t lock;
262
263 atomic_t alloc_buf_count;
264};
265
266int octeon_setup_sc_buffer_pool(struct octeon_device *oct);
267int octeon_free_sc_buffer_pool(struct octeon_device *oct);
268struct octeon_soft_command *
269 octeon_alloc_soft_command(struct octeon_device *oct,
270 u32 datasize, u32 rdatasize,
271 u32 ctxsize);
272void octeon_free_soft_command(struct octeon_device *oct,
273 struct octeon_soft_command *sc);
274
275/**
276 * octeon_init_instr_queue()
277 * @param octeon_dev - pointer to the octeon device structure.
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700278 * @param txpciq - queue to be initialized (0 <= q_no <= 3).
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700279 *
280 * Called at driver init time for each input queue. iq_conf has the
281 * configuration parameters for the queue.
282 *
283 * @return Success: 0 Failure: 1
284 */
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700285int octeon_init_instr_queue(struct octeon_device *octeon_dev,
286 union oct_txpciq txpciq,
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700287 u32 num_descs);
288
289/**
290 * octeon_delete_instr_queue()
291 * @param octeon_dev - pointer to the octeon device structure.
292 * @param iq_no - queue to be deleted (0 <= q_no <= 3).
293 *
294 * Called at driver unload time for each input queue. Deletes all
295 * allocated resources for the input queue.
296 *
297 * @return Success: 0 Failure: 1
298 */
299int octeon_delete_instr_queue(struct octeon_device *octeon_dev, u32 iq_no);
300
301int lio_wait_for_instr_fetch(struct octeon_device *oct);
302
303int
304octeon_register_reqtype_free_fn(struct octeon_device *oct, int reqtype,
305 void (*fn)(void *));
306
307int
308lio_process_iq_request_list(struct octeon_device *oct,
309 struct octeon_instr_queue *iq);
310
311int octeon_send_command(struct octeon_device *oct, u32 iq_no,
312 u32 force_db, void *cmd, void *buf,
313 u32 datasize, u32 reqtype);
314
315void octeon_prepare_soft_command(struct octeon_device *oct,
316 struct octeon_soft_command *sc,
317 u8 opcode, u8 subcode,
318 u32 irh_ossp, u64 ossp0,
319 u64 ossp1);
320
321int octeon_send_soft_command(struct octeon_device *oct,
322 struct octeon_soft_command *sc);
323
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700324int octeon_setup_iq(struct octeon_device *oct, int ifidx,
325 int q_index, union oct_txpciq iq_no, u32 num_descs,
326 void *app_ctx);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700327
328#endif /* __OCTEON_IQ_H__ */