octeon_iq.h 10 KB

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