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