be.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Copyright 2017 Broadcom. All Rights Reserved.
  3. * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License version 2
  7. * as published by the Free Software Foundation. The full GNU General
  8. * Public License is included in this distribution in the file called COPYING.
  9. *
  10. * Contact Information:
  11. * linux-drivers@broadcom.com
  12. *
  13. */
  14. #ifndef BEISCSI_H
  15. #define BEISCSI_H
  16. #include <linux/pci.h>
  17. #include <linux/if_vlan.h>
  18. #include <linux/irq_poll.h>
  19. #define FW_VER_LEN 32
  20. #define MCC_Q_LEN 128
  21. #define MCC_CQ_LEN 256
  22. #define MAX_MCC_CMD 16
  23. /* BladeEngine Generation numbers */
  24. #define BE_GEN2 2
  25. #define BE_GEN3 3
  26. #define BE_GEN4 4
  27. struct be_dma_mem {
  28. void *va;
  29. dma_addr_t dma;
  30. u32 size;
  31. };
  32. struct be_queue_info {
  33. struct be_dma_mem dma_mem;
  34. u16 len;
  35. u16 entry_size; /* Size of an element in the queue */
  36. u16 id;
  37. u16 tail, head;
  38. bool created;
  39. u16 used; /* Number of valid elements in the queue */
  40. };
  41. static inline u32 MODULO(u16 val, u16 limit)
  42. {
  43. WARN_ON(limit & (limit - 1));
  44. return val & (limit - 1);
  45. }
  46. static inline void index_inc(u16 *index, u16 limit)
  47. {
  48. *index = MODULO((*index + 1), limit);
  49. }
  50. static inline void *queue_head_node(struct be_queue_info *q)
  51. {
  52. return q->dma_mem.va + q->head * q->entry_size;
  53. }
  54. static inline void *queue_get_wrb(struct be_queue_info *q, unsigned int wrb_num)
  55. {
  56. return q->dma_mem.va + wrb_num * q->entry_size;
  57. }
  58. static inline void *queue_tail_node(struct be_queue_info *q)
  59. {
  60. return q->dma_mem.va + q->tail * q->entry_size;
  61. }
  62. static inline void queue_head_inc(struct be_queue_info *q)
  63. {
  64. index_inc(&q->head, q->len);
  65. }
  66. static inline void queue_tail_inc(struct be_queue_info *q)
  67. {
  68. index_inc(&q->tail, q->len);
  69. }
  70. /*ISCSI */
  71. struct be_aic_obj { /* Adaptive interrupt coalescing (AIC) info */
  72. u32 min_eqd; /* in usecs */
  73. u32 max_eqd; /* in usecs */
  74. u32 prev_eqd; /* in usecs */
  75. u32 et_eqd; /* configured val when aic is off */
  76. ulong jiffies;
  77. u64 eq_prev; /* Used to calculate eqe */
  78. };
  79. struct be_eq_obj {
  80. u32 cq_count;
  81. struct be_queue_info q;
  82. struct beiscsi_hba *phba;
  83. struct be_queue_info *cq;
  84. struct work_struct mcc_work; /* Work Item */
  85. struct irq_poll iopoll;
  86. };
  87. struct be_mcc_obj {
  88. struct be_queue_info q;
  89. struct be_queue_info cq;
  90. };
  91. struct beiscsi_mcc_tag_state {
  92. unsigned long tag_state;
  93. #define MCC_TAG_STATE_RUNNING 0
  94. #define MCC_TAG_STATE_TIMEOUT 1
  95. #define MCC_TAG_STATE_ASYNC 2
  96. #define MCC_TAG_STATE_IGNORE 3
  97. void (*cbfn)(struct beiscsi_hba *, unsigned int);
  98. struct be_dma_mem tag_mem_state;
  99. };
  100. struct be_ctrl_info {
  101. u8 __iomem *csr;
  102. u8 __iomem *db; /* Door Bell */
  103. u8 __iomem *pcicfg; /* PCI config space */
  104. struct pci_dev *pdev;
  105. /* Mbox used for cmd request/response */
  106. struct mutex mbox_lock; /* For serializing mbox cmds to BE card */
  107. struct be_dma_mem mbox_mem;
  108. /* Mbox mem is adjusted to align to 16 bytes. The allocated addr
  109. * is stored for freeing purpose */
  110. struct be_dma_mem mbox_mem_alloced;
  111. /* MCC Rings */
  112. struct be_mcc_obj mcc_obj;
  113. spinlock_t mcc_lock; /* For serializing mcc cmds to BE card */
  114. wait_queue_head_t mcc_wait[MAX_MCC_CMD + 1];
  115. unsigned int mcc_tag[MAX_MCC_CMD];
  116. unsigned int mcc_tag_status[MAX_MCC_CMD + 1];
  117. unsigned short mcc_alloc_index;
  118. unsigned short mcc_free_index;
  119. unsigned int mcc_tag_available;
  120. struct beiscsi_mcc_tag_state ptag_state[MAX_MCC_CMD + 1];
  121. };
  122. #include "be_cmds.h"
  123. /* WRB index mask for MCC_Q_LEN queue entries */
  124. #define MCC_Q_WRB_IDX_MASK CQE_STATUS_WRB_MASK
  125. #define MCC_Q_WRB_IDX_SHIFT CQE_STATUS_WRB_SHIFT
  126. /* TAG is from 1...MAX_MCC_CMD, MASK includes MAX_MCC_CMD */
  127. #define MCC_Q_CMD_TAG_MASK ((MAX_MCC_CMD << 1) - 1)
  128. #define PAGE_SHIFT_4K 12
  129. #define PAGE_SIZE_4K (1 << PAGE_SHIFT_4K)
  130. #define mcc_timeout 120000 /* 12s timeout */
  131. /* Returns number of pages spanned by the data starting at the given addr */
  132. #define PAGES_4K_SPANNED(_address, size) \
  133. ((u32)((((size_t)(_address) & (PAGE_SIZE_4K - 1)) + \
  134. (size) + (PAGE_SIZE_4K - 1)) >> PAGE_SHIFT_4K))
  135. /* Returns bit offset within a DWORD of a bitfield */
  136. #define AMAP_BIT_OFFSET(_struct, field) \
  137. (((size_t)&(((_struct *)0)->field))%32)
  138. /* Returns the bit mask of the field that is NOT shifted into location. */
  139. static inline u32 amap_mask(u32 bitsize)
  140. {
  141. return (bitsize == 32 ? 0xFFFFFFFF : (1 << bitsize) - 1);
  142. }
  143. static inline void amap_set(void *ptr, u32 dw_offset, u32 mask,
  144. u32 offset, u32 value)
  145. {
  146. u32 *dw = (u32 *) ptr + dw_offset;
  147. *dw &= ~(mask << offset);
  148. *dw |= (mask & value) << offset;
  149. }
  150. #define AMAP_SET_BITS(_struct, field, ptr, val) \
  151. amap_set(ptr, \
  152. offsetof(_struct, field)/32, \
  153. amap_mask(sizeof(((_struct *)0)->field)), \
  154. AMAP_BIT_OFFSET(_struct, field), \
  155. val)
  156. static inline u32 amap_get(void *ptr, u32 dw_offset, u32 mask, u32 offset)
  157. {
  158. u32 *dw = ptr;
  159. return mask & (*(dw + dw_offset) >> offset);
  160. }
  161. #define AMAP_GET_BITS(_struct, field, ptr) \
  162. amap_get(ptr, \
  163. offsetof(_struct, field)/32, \
  164. amap_mask(sizeof(((_struct *)0)->field)), \
  165. AMAP_BIT_OFFSET(_struct, field))
  166. #define be_dws_cpu_to_le(wrb, len) swap_dws(wrb, len)
  167. #define be_dws_le_to_cpu(wrb, len) swap_dws(wrb, len)
  168. static inline void swap_dws(void *wrb, int len)
  169. {
  170. #ifdef __BIG_ENDIAN
  171. u32 *dw = wrb;
  172. WARN_ON(len % 4);
  173. do {
  174. *dw = cpu_to_le32(*dw);
  175. dw++;
  176. len -= 4;
  177. } while (len);
  178. #endif /* __BIG_ENDIAN */
  179. }
  180. #endif /* BEISCSI_H */