]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/net/ethernet/cavium/liquidio/octeon_iq.h
liquidio: soft command buffer limits
[mirror_ubuntu-zesty-kernel.git] / drivers / net / ethernet / cavium / liquidio / octeon_iq.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_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 {
6a885b60
RV
78 struct octeon_device *oct_dev;
79
f21fb3ed
RV
80 /** A spinlock to protect access to the input ring. */
81 spinlock_t lock;
82
83 /** Flag that indicates if the queue uses 64 byte commands. */
84 u32 iqcmd_64B:1;
85
26236fa9
RV
86 /** Queue info. */
87 union oct_txpciq txpciq;
f21fb3ed
RV
88
89 u32 rsvd:17;
90
91 /* Controls the periodic flushing of iq */
92 u32 do_auto_flush:1;
93
94 u32 status:8;
95
96 /** Maximum no. of instructions in this queue. */
97 u32 max_count;
98
99 /** Index in input ring where the driver should write the next packet */
100 u32 host_write_index;
101
102 /** Index in input ring where Octeon is expected to read the next
103 * packet.
104 */
105 u32 octeon_read_index;
106
107 /** This index aids in finding the window in the queue where Octeon
108 * has read the commands.
109 */
110 u32 flush_index;
111
112 /** This field keeps track of the instructions pending in this queue. */
113 atomic_t instr_pending;
114
115 u32 reset_instr_cnt;
116
117 /** Pointer to the Virtual Base addr of the input ring. */
118 u8 *base_addr;
119
120 struct octeon_request_list *request_list;
121
122 /** Octeon doorbell register for the ring. */
123 void __iomem *doorbell_reg;
124
125 /** Octeon instruction count register for this ring. */
126 void __iomem *inst_cnt_reg;
127
128 /** Number of instructions pending to be posted to Octeon. */
129 u32 fill_cnt;
130
131 /** The max. number of instructions that can be held pending by the
132 * driver.
133 */
134 u32 fill_threshold;
135
136 /** The last time that the doorbell was rung. */
137 u64 last_db_time;
138
139 /** The doorbell timeout. If the doorbell was not rung for this time and
140 * fill_cnt is non-zero, ring the doorbell again.
141 */
142 u32 db_timeout;
143
144 /** Statistics for this input queue. */
145 struct oct_iq_stats stats;
146
147 /** DMA mapped base address of the input descriptor ring. */
148 u64 base_addr_dma;
149
150 /** Application context */
151 void *app_ctx;
0cece6c5
RV
152
153 /* network stack queue index */
154 int q_index;
155
156 /*os ifidx associated with this queue */
157 int ifidx;
158
f21fb3ed
RV
159};
160
161/*---------------------- INSTRUCTION FORMAT ----------------------------*/
162
163/** 32-byte instruction format.
164 * Format of instruction for a 32-byte mode input queue.
165 */
166struct octeon_instr_32B {
167 /** Pointer where the input data is available. */
168 u64 dptr;
169
170 /** Instruction Header. */
171 u64 ih;
172
173 /** Pointer where the response for a RAW mode packet will be written
174 * by Octeon.
175 */
176 u64 rptr;
177
178 /** Input Request Header. Additional info about the input. */
179 u64 irh;
180
181};
182
183#define OCT_32B_INSTR_SIZE (sizeof(struct octeon_instr_32B))
184
185/** 64-byte instruction format.
186 * Format of instruction for a 64-byte mode input queue.
187 */
6a885b60 188struct octeon_instr2_64B {
f21fb3ed
RV
189 /** Pointer where the input data is available. */
190 u64 dptr;
191
192 /** Instruction Header. */
6a885b60 193 u64 ih2;
f21fb3ed
RV
194
195 /** Input Request Header. */
196 u64 irh;
197
198 /** opcode/subcode specific parameters */
199 u64 ossp[2];
200
201 /** Return Data Parameters */
202 u64 rdp;
203
204 /** Pointer where the response for a RAW mode packet will be written
205 * by Octeon.
206 */
207 u64 rptr;
208
209 u64 reserved;
6a885b60
RV
210};
211
212struct octeon_instr3_64B {
213 /** Pointer where the input data is available. */
214 u64 dptr;
215
216 /** Instruction Header. */
217 u64 ih3;
218
219 /** Instruction Header. */
220 u64 pki_ih3;
221
222 /** Input Request Header. */
223 u64 irh;
224
225 /** opcode/subcode specific parameters */
226 u64 ossp[2];
227
228 /** Return Data Parameters */
229 u64 rdp;
230
231 /** Pointer where the response for a RAW mode packet will be written
232 * by Octeon.
233 */
234 u64 rptr;
f21fb3ed
RV
235
236};
237
6a885b60
RV
238union octeon_instr_64B {
239 struct octeon_instr2_64B cmd2;
240 struct octeon_instr3_64B cmd3;
241};
242
243#define OCT_64B_INSTR_SIZE (sizeof(union octeon_instr_64B))
f21fb3ed
RV
244
245/** The size of each buffer in soft command buffer pool
246 */
63da8404 247#define SOFT_COMMAND_BUFFER_SIZE 1536
f21fb3ed
RV
248
249struct octeon_soft_command {
250 /** Soft command buffer info. */
251 struct list_head node;
252 u64 dma_addr;
253 u32 size;
254
255 /** Command and return status */
6a885b60
RV
256 union octeon_instr_64B cmd;
257
f21fb3ed
RV
258#define COMPLETION_WORD_INIT 0xffffffffffffffffULL
259 u64 *status_word;
260
261 /** Data buffer info */
262 void *virtdptr;
263 u64 dmadptr;
264 u32 datasize;
265
266 /** Return buffer info */
267 void *virtrptr;
268 u64 dmarptr;
269 u32 rdatasize;
270
271 /** Context buffer info */
272 void *ctxptr;
273 u32 ctxsize;
274
275 /** Time out and callback */
276 size_t wait_time;
277 size_t timeout;
278 u32 iq_no;
279 void (*callback)(struct octeon_device *, u32, void *);
280 void *callback_arg;
281};
282
283/** Maximum number of buffers to allocate into soft command buffer pool
284 */
63da8404 285#define MAX_SOFT_COMMAND_BUFFERS 256
f21fb3ed
RV
286
287/** Head of a soft command buffer pool.
288 */
289struct octeon_sc_buffer_pool {
290 /** List structure to add delete pending entries to */
291 struct list_head head;
292
293 /** A lock for this response list */
294 spinlock_t lock;
295
296 atomic_t alloc_buf_count;
297};
298
299int octeon_setup_sc_buffer_pool(struct octeon_device *oct);
300int octeon_free_sc_buffer_pool(struct octeon_device *oct);
301struct octeon_soft_command *
302 octeon_alloc_soft_command(struct octeon_device *oct,
303 u32 datasize, u32 rdatasize,
304 u32 ctxsize);
305void octeon_free_soft_command(struct octeon_device *oct,
306 struct octeon_soft_command *sc);
307
308/**
309 * octeon_init_instr_queue()
310 * @param octeon_dev - pointer to the octeon device structure.
26236fa9 311 * @param txpciq - queue to be initialized (0 <= q_no <= 3).
f21fb3ed
RV
312 *
313 * Called at driver init time for each input queue. iq_conf has the
314 * configuration parameters for the queue.
315 *
316 * @return Success: 0 Failure: 1
317 */
26236fa9
RV
318int octeon_init_instr_queue(struct octeon_device *octeon_dev,
319 union oct_txpciq txpciq,
f21fb3ed
RV
320 u32 num_descs);
321
322/**
323 * octeon_delete_instr_queue()
324 * @param octeon_dev - pointer to the octeon device structure.
325 * @param iq_no - queue to be deleted (0 <= q_no <= 3).
326 *
327 * Called at driver unload time for each input queue. Deletes all
328 * allocated resources for the input queue.
329 *
330 * @return Success: 0 Failure: 1
331 */
332int octeon_delete_instr_queue(struct octeon_device *octeon_dev, u32 iq_no);
333
334int lio_wait_for_instr_fetch(struct octeon_device *oct);
335
336int
337octeon_register_reqtype_free_fn(struct octeon_device *oct, int reqtype,
338 void (*fn)(void *));
339
340int
341lio_process_iq_request_list(struct octeon_device *oct,
342 struct octeon_instr_queue *iq);
343
344int octeon_send_command(struct octeon_device *oct, u32 iq_no,
345 u32 force_db, void *cmd, void *buf,
346 u32 datasize, u32 reqtype);
347
348void octeon_prepare_soft_command(struct octeon_device *oct,
349 struct octeon_soft_command *sc,
350 u8 opcode, u8 subcode,
351 u32 irh_ossp, u64 ossp0,
352 u64 ossp1);
353
354int octeon_send_soft_command(struct octeon_device *oct,
355 struct octeon_soft_command *sc);
356
0cece6c5
RV
357int octeon_setup_iq(struct octeon_device *oct, int ifidx,
358 int q_index, union oct_txpciq iq_no, u32 num_descs,
359 void *app_ctx);
f21fb3ed
RV
360
361#endif /* __OCTEON_IQ_H__ */