cxio_hal.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #ifndef __CXIO_HAL_H__
  33. #define __CXIO_HAL_H__
  34. #include <linux/list.h>
  35. #include <linux/mutex.h>
  36. #include "t3_cpl.h"
  37. #include "t3cdev.h"
  38. #include "cxgb3_ctl_defs.h"
  39. #include "cxio_wr.h"
  40. #define T3_CTRL_QP_ID FW_RI_SGEEC_START
  41. #define T3_CTL_QP_TID FW_RI_TID_START
  42. #define T3_CTRL_QP_SIZE_LOG2 8
  43. #define T3_CTRL_CQ_ID 0
  44. /* TBD */
  45. #define T3_MAX_NUM_RI (1<<15)
  46. #define T3_MAX_NUM_QP (1<<15)
  47. #define T3_MAX_NUM_CQ (1<<15)
  48. #define T3_MAX_NUM_PD (1<<15)
  49. #define T3_MAX_PBL_SIZE 256
  50. #define T3_MAX_RQ_SIZE 1024
  51. #define T3_MAX_NUM_STAG (1<<15)
  52. #define T3_STAG_UNSET 0xffffffff
  53. #define T3_MAX_DEV_NAME_LEN 32
  54. struct cxio_hal_ctrl_qp {
  55. u32 wptr;
  56. u32 rptr;
  57. struct mutex lock; /* for the wtpr, can sleep */
  58. wait_queue_head_t waitq;/* wait for RspQ/CQE msg */
  59. union t3_wr *workq; /* the work request queue */
  60. dma_addr_t dma_addr; /* pci bus address of the workq */
  61. DECLARE_PCI_UNMAP_ADDR(mapping)
  62. void __iomem *doorbell;
  63. };
  64. struct cxio_hal_resource {
  65. struct kfifo *tpt_fifo;
  66. spinlock_t tpt_fifo_lock;
  67. struct kfifo *qpid_fifo;
  68. spinlock_t qpid_fifo_lock;
  69. struct kfifo *cqid_fifo;
  70. spinlock_t cqid_fifo_lock;
  71. struct kfifo *pdid_fifo;
  72. spinlock_t pdid_fifo_lock;
  73. };
  74. struct cxio_qpid_list {
  75. struct list_head entry;
  76. u32 qpid;
  77. };
  78. struct cxio_ucontext {
  79. struct list_head qpids;
  80. struct mutex lock;
  81. };
  82. struct cxio_rdev {
  83. char dev_name[T3_MAX_DEV_NAME_LEN];
  84. struct t3cdev *t3cdev_p;
  85. struct rdma_info rnic_info;
  86. struct adap_ports port_info;
  87. struct cxio_hal_resource *rscp;
  88. struct cxio_hal_ctrl_qp ctrl_qp;
  89. void *ulp;
  90. unsigned long qpshift;
  91. u32 qpnr;
  92. u32 qpmask;
  93. struct cxio_ucontext uctx;
  94. struct gen_pool *pbl_pool;
  95. struct gen_pool *rqt_pool;
  96. struct list_head entry;
  97. };
  98. static inline int cxio_num_stags(struct cxio_rdev *rdev_p)
  99. {
  100. return min((int)T3_MAX_NUM_STAG, (int)((rdev_p->rnic_info.tpt_top - rdev_p->rnic_info.tpt_base) >> 5));
  101. }
  102. typedef void (*cxio_hal_ev_callback_func_t) (struct cxio_rdev * rdev_p,
  103. struct sk_buff * skb);
  104. #define RSPQ_CQID(rsp) (be32_to_cpu(rsp->cq_ptrid) & 0xffff)
  105. #define RSPQ_CQPTR(rsp) ((be32_to_cpu(rsp->cq_ptrid) >> 16) & 0xffff)
  106. #define RSPQ_GENBIT(rsp) ((be32_to_cpu(rsp->flags) >> 16) & 1)
  107. #define RSPQ_OVERFLOW(rsp) ((be32_to_cpu(rsp->flags) >> 17) & 1)
  108. #define RSPQ_AN(rsp) ((be32_to_cpu(rsp->flags) >> 18) & 1)
  109. #define RSPQ_SE(rsp) ((be32_to_cpu(rsp->flags) >> 19) & 1)
  110. #define RSPQ_NOTIFY(rsp) ((be32_to_cpu(rsp->flags) >> 20) & 1)
  111. #define RSPQ_CQBRANCH(rsp) ((be32_to_cpu(rsp->flags) >> 21) & 1)
  112. #define RSPQ_CREDIT_THRESH(rsp) ((be32_to_cpu(rsp->flags) >> 22) & 1)
  113. struct respQ_msg_t {
  114. __be32 flags; /* flit 0 */
  115. __be32 cq_ptrid;
  116. __be64 rsvd; /* flit 1 */
  117. struct t3_cqe cqe; /* flits 2-3 */
  118. };
  119. enum t3_cq_opcode {
  120. CQ_ARM_AN = 0x2,
  121. CQ_ARM_SE = 0x6,
  122. CQ_FORCE_AN = 0x3,
  123. CQ_CREDIT_UPDATE = 0x7
  124. };
  125. int cxio_rdev_open(struct cxio_rdev *rdev);
  126. void cxio_rdev_close(struct cxio_rdev *rdev);
  127. int cxio_hal_cq_op(struct cxio_rdev *rdev, struct t3_cq *cq,
  128. enum t3_cq_opcode op, u32 credit);
  129. int cxio_create_cq(struct cxio_rdev *rdev, struct t3_cq *cq);
  130. int cxio_destroy_cq(struct cxio_rdev *rdev, struct t3_cq *cq);
  131. int cxio_resize_cq(struct cxio_rdev *rdev, struct t3_cq *cq);
  132. void cxio_release_ucontext(struct cxio_rdev *rdev, struct cxio_ucontext *uctx);
  133. void cxio_init_ucontext(struct cxio_rdev *rdev, struct cxio_ucontext *uctx);
  134. int cxio_create_qp(struct cxio_rdev *rdev, u32 kernel_domain, struct t3_wq *wq,
  135. struct cxio_ucontext *uctx);
  136. int cxio_destroy_qp(struct cxio_rdev *rdev, struct t3_wq *wq,
  137. struct cxio_ucontext *uctx);
  138. int cxio_peek_cq(struct t3_wq *wr, struct t3_cq *cq, int opcode);
  139. int cxio_register_phys_mem(struct cxio_rdev *rdev, u32 * stag, u32 pdid,
  140. enum tpt_mem_perm perm, u32 zbva, u64 to, u32 len,
  141. u8 page_size, __be64 *pbl, u32 *pbl_size,
  142. u32 *pbl_addr);
  143. int cxio_reregister_phys_mem(struct cxio_rdev *rdev, u32 * stag, u32 pdid,
  144. enum tpt_mem_perm perm, u32 zbva, u64 to, u32 len,
  145. u8 page_size, __be64 *pbl, u32 *pbl_size,
  146. u32 *pbl_addr);
  147. int cxio_dereg_mem(struct cxio_rdev *rdev, u32 stag, u32 pbl_size,
  148. u32 pbl_addr);
  149. int cxio_allocate_window(struct cxio_rdev *rdev, u32 * stag, u32 pdid);
  150. int cxio_deallocate_window(struct cxio_rdev *rdev, u32 stag);
  151. int cxio_rdma_init(struct cxio_rdev *rdev, struct t3_rdma_init_attr *attr);
  152. void cxio_register_ev_cb(cxio_hal_ev_callback_func_t ev_cb);
  153. void cxio_unregister_ev_cb(cxio_hal_ev_callback_func_t ev_cb);
  154. u32 cxio_hal_get_pdid(struct cxio_hal_resource *rscp);
  155. void cxio_hal_put_pdid(struct cxio_hal_resource *rscp, u32 pdid);
  156. int __init cxio_hal_init(void);
  157. void __exit cxio_hal_exit(void);
  158. void cxio_flush_rq(struct t3_wq *wq, struct t3_cq *cq, int count);
  159. void cxio_flush_sq(struct t3_wq *wq, struct t3_cq *cq, int count);
  160. void cxio_count_rcqes(struct t3_cq *cq, struct t3_wq *wq, int *count);
  161. void cxio_count_scqes(struct t3_cq *cq, struct t3_wq *wq, int *count);
  162. void cxio_flush_hw_cq(struct t3_cq *cq);
  163. int cxio_poll_cq(struct t3_wq *wq, struct t3_cq *cq, struct t3_cqe *cqe,
  164. u8 *cqe_flushed, u64 *cookie, u32 *credit);
  165. #define MOD "iw_cxgb3: "
  166. #define PDBG(fmt, args...) pr_debug(MOD fmt, ## args)
  167. #ifdef DEBUG
  168. void cxio_dump_tpt(struct cxio_rdev *rev, u32 stag);
  169. void cxio_dump_pbl(struct cxio_rdev *rev, u32 pbl_addr, uint len, u8 shift);
  170. void cxio_dump_wqe(union t3_wr *wqe);
  171. void cxio_dump_wce(struct t3_cqe *wce);
  172. void cxio_dump_rqt(struct cxio_rdev *rdev, u32 hwtid, int nents);
  173. void cxio_dump_tcb(struct cxio_rdev *rdev, u32 hwtid);
  174. #endif
  175. #endif