octeon_iq.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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;
  57. u64 tx_restart;
  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. u32 pkt_in_done;
  72. /** A spinlock to protect access to the input ring.*/
  73. spinlock_t iq_flush_running_lock;
  74. /** Flag that indicates if the queue uses 64 byte commands. */
  75. u32 iqcmd_64B:1;
  76. /** Queue info. */
  77. union oct_txpciq txpciq;
  78. u32 rsvd:17;
  79. /* Controls whether extra flushing of IQ is done on Tx */
  80. u32 do_auto_flush:1;
  81. u32 status:8;
  82. /** Maximum no. of instructions in this queue. */
  83. u32 max_count;
  84. /** Index in input ring where the driver should write the next packet */
  85. u32 host_write_index;
  86. /** Index in input ring where Octeon is expected to read the next
  87. * packet.
  88. */
  89. u32 octeon_read_index;
  90. /** This index aids in finding the window in the queue where Octeon
  91. * has read the commands.
  92. */
  93. u32 flush_index;
  94. /** This field keeps track of the instructions pending in this queue. */
  95. atomic_t instr_pending;
  96. u32 reset_instr_cnt;
  97. /** Pointer to the Virtual Base addr of the input ring. */
  98. u8 *base_addr;
  99. struct octeon_request_list *request_list;
  100. /** Octeon doorbell register for the ring. */
  101. void __iomem *doorbell_reg;
  102. /** Octeon instruction count register for this ring. */
  103. void __iomem *inst_cnt_reg;
  104. /** Number of instructions pending to be posted to Octeon. */
  105. u32 fill_cnt;
  106. /** The max. number of instructions that can be held pending by the
  107. * driver.
  108. */
  109. u32 fill_threshold;
  110. /** The last time that the doorbell was rung. */
  111. u64 last_db_time;
  112. /** The doorbell timeout. If the doorbell was not rung for this time and
  113. * fill_cnt is non-zero, ring the doorbell again.
  114. */
  115. u32 db_timeout;
  116. /** Statistics for this input queue. */
  117. struct oct_iq_stats stats;
  118. /** DMA mapped base address of the input descriptor ring. */
  119. u64 base_addr_dma;
  120. /** Application context */
  121. void *app_ctx;
  122. /* network stack queue index */
  123. int q_index;
  124. /*os ifidx associated with this queue */
  125. int ifidx;
  126. };
  127. /*---------------------- INSTRUCTION FORMAT ----------------------------*/
  128. /** 32-byte instruction format.
  129. * Format of instruction for a 32-byte mode input queue.
  130. */
  131. struct octeon_instr_32B {
  132. /** Pointer where the input data is available. */
  133. u64 dptr;
  134. /** Instruction Header. */
  135. u64 ih;
  136. /** Pointer where the response for a RAW mode packet will be written
  137. * by Octeon.
  138. */
  139. u64 rptr;
  140. /** Input Request Header. Additional info about the input. */
  141. u64 irh;
  142. };
  143. #define OCT_32B_INSTR_SIZE (sizeof(struct octeon_instr_32B))
  144. /** 64-byte instruction format.
  145. * Format of instruction for a 64-byte mode input queue.
  146. */
  147. struct octeon_instr2_64B {
  148. /** Pointer where the input data is available. */
  149. u64 dptr;
  150. /** Instruction Header. */
  151. u64 ih2;
  152. /** Input Request Header. */
  153. u64 irh;
  154. /** opcode/subcode specific parameters */
  155. u64 ossp[2];
  156. /** Return Data Parameters */
  157. u64 rdp;
  158. /** Pointer where the response for a RAW mode packet will be written
  159. * by Octeon.
  160. */
  161. u64 rptr;
  162. u64 reserved;
  163. };
  164. struct octeon_instr3_64B {
  165. /** Pointer where the input data is available. */
  166. u64 dptr;
  167. /** Instruction Header. */
  168. u64 ih3;
  169. /** Instruction Header. */
  170. u64 pki_ih3;
  171. /** Input Request Header. */
  172. u64 irh;
  173. /** opcode/subcode specific parameters */
  174. u64 ossp[2];
  175. /** Return Data Parameters */
  176. u64 rdp;
  177. /** Pointer where the response for a RAW mode packet will be written
  178. * by Octeon.
  179. */
  180. u64 rptr;
  181. };
  182. union octeon_instr_64B {
  183. struct octeon_instr2_64B cmd2;
  184. struct octeon_instr3_64B cmd3;
  185. };
  186. #define OCT_64B_INSTR_SIZE (sizeof(union octeon_instr_64B))
  187. /** The size of each buffer in soft command buffer pool
  188. */
  189. #define SOFT_COMMAND_BUFFER_SIZE 1536
  190. struct octeon_soft_command {
  191. /** Soft command buffer info. */
  192. struct list_head node;
  193. u64 dma_addr;
  194. u32 size;
  195. /** Command and return status */
  196. union octeon_instr_64B cmd;
  197. #define COMPLETION_WORD_INIT 0xffffffffffffffffULL
  198. u64 *status_word;
  199. /** Data buffer info */
  200. void *virtdptr;
  201. u64 dmadptr;
  202. u32 datasize;
  203. /** Return buffer info */
  204. void *virtrptr;
  205. u64 dmarptr;
  206. u32 rdatasize;
  207. /** Context buffer info */
  208. void *ctxptr;
  209. u32 ctxsize;
  210. /** Time out and callback */
  211. size_t wait_time;
  212. size_t timeout;
  213. u32 iq_no;
  214. void (*callback)(struct octeon_device *, u32, void *);
  215. void *callback_arg;
  216. };
  217. /** Maximum number of buffers to allocate into soft command buffer pool
  218. */
  219. #define MAX_SOFT_COMMAND_BUFFERS 256
  220. /** Head of a soft command buffer pool.
  221. */
  222. struct octeon_sc_buffer_pool {
  223. /** List structure to add delete pending entries to */
  224. struct list_head head;
  225. /** A lock for this response list */
  226. spinlock_t lock;
  227. atomic_t alloc_buf_count;
  228. };
  229. #define INCR_INSTRQUEUE_PKT_COUNT(octeon_dev_ptr, iq_no, field, count) \
  230. (((octeon_dev_ptr)->instr_queue[iq_no]->stats.field) += count)
  231. int octeon_setup_sc_buffer_pool(struct octeon_device *oct);
  232. int octeon_free_sc_buffer_pool(struct octeon_device *oct);
  233. struct octeon_soft_command *
  234. octeon_alloc_soft_command(struct octeon_device *oct,
  235. u32 datasize, u32 rdatasize,
  236. u32 ctxsize);
  237. void octeon_free_soft_command(struct octeon_device *oct,
  238. struct octeon_soft_command *sc);
  239. /**
  240. * octeon_init_instr_queue()
  241. * @param octeon_dev - pointer to the octeon device structure.
  242. * @param txpciq - queue to be initialized (0 <= q_no <= 3).
  243. *
  244. * Called at driver init time for each input queue. iq_conf has the
  245. * configuration parameters for the queue.
  246. *
  247. * @return Success: 0 Failure: 1
  248. */
  249. int octeon_init_instr_queue(struct octeon_device *octeon_dev,
  250. union oct_txpciq txpciq,
  251. u32 num_descs);
  252. /**
  253. * octeon_delete_instr_queue()
  254. * @param octeon_dev - pointer to the octeon device structure.
  255. * @param iq_no - queue to be deleted (0 <= q_no <= 3).
  256. *
  257. * Called at driver unload time for each input queue. Deletes all
  258. * allocated resources for the input queue.
  259. *
  260. * @return Success: 0 Failure: 1
  261. */
  262. int octeon_delete_instr_queue(struct octeon_device *octeon_dev, u32 iq_no);
  263. int lio_wait_for_instr_fetch(struct octeon_device *oct);
  264. int
  265. octeon_register_reqtype_free_fn(struct octeon_device *oct, int reqtype,
  266. void (*fn)(void *));
  267. int
  268. lio_process_iq_request_list(struct octeon_device *oct,
  269. struct octeon_instr_queue *iq, u32 napi_budget);
  270. int octeon_send_command(struct octeon_device *oct, u32 iq_no,
  271. u32 force_db, void *cmd, void *buf,
  272. u32 datasize, u32 reqtype);
  273. void octeon_prepare_soft_command(struct octeon_device *oct,
  274. struct octeon_soft_command *sc,
  275. u8 opcode, u8 subcode,
  276. u32 irh_ossp, u64 ossp0,
  277. u64 ossp1);
  278. int octeon_send_soft_command(struct octeon_device *oct,
  279. struct octeon_soft_command *sc);
  280. int octeon_setup_iq(struct octeon_device *oct, int ifidx,
  281. int q_index, union oct_txpciq iq_no, u32 num_descs,
  282. void *app_ctx);
  283. int
  284. octeon_flush_iq(struct octeon_device *oct, struct octeon_instr_queue *iq,
  285. u32 pending_thresh, u32 napi_budget);
  286. #endif /* __OCTEON_IQ_H__ */