be.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /**
  2. * Copyright (C) 2005 - 2012 Emulex
  3. * All rights reserved.
  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@emulex.com
  12. *
  13. * Emulex
  14. * 3333 Susan Street
  15. * Costa Mesa, CA 92626
  16. */
  17. #ifndef BEISCSI_H
  18. #define BEISCSI_H
  19. #include <linux/pci.h>
  20. #include <linux/if_vlan.h>
  21. #include <linux/blk-iopoll.h>
  22. #define FW_VER_LEN 32
  23. #define MCC_Q_LEN 128
  24. #define MCC_CQ_LEN 256
  25. #define MAX_MCC_CMD 16
  26. /* BladeEngine Generation numbers */
  27. #define BE_GEN2 2
  28. #define BE_GEN3 3
  29. #define BE_GEN4 4
  30. struct be_dma_mem {
  31. void *va;
  32. dma_addr_t dma;
  33. u32 size;
  34. };
  35. struct be_queue_info {
  36. struct be_dma_mem dma_mem;
  37. u16 len;
  38. u16 entry_size; /* Size of an element in the queue */
  39. u16 id;
  40. u16 tail, head;
  41. bool created;
  42. atomic_t used; /* Number of valid elements in the queue */
  43. };
  44. static inline u32 MODULO(u16 val, u16 limit)
  45. {
  46. WARN_ON(limit & (limit - 1));
  47. return val & (limit - 1);
  48. }
  49. static inline void index_inc(u16 *index, u16 limit)
  50. {
  51. *index = MODULO((*index + 1), limit);
  52. }
  53. static inline void *queue_head_node(struct be_queue_info *q)
  54. {
  55. return q->dma_mem.va + q->head * q->entry_size;
  56. }
  57. static inline void *queue_get_wrb(struct be_queue_info *q, unsigned int wrb_num)
  58. {
  59. return q->dma_mem.va + wrb_num * q->entry_size;
  60. }
  61. static inline void *queue_tail_node(struct be_queue_info *q)
  62. {
  63. return q->dma_mem.va + q->tail * q->entry_size;
  64. }
  65. static inline void queue_head_inc(struct be_queue_info *q)
  66. {
  67. index_inc(&q->head, q->len);
  68. }
  69. static inline void queue_tail_inc(struct be_queue_info *q)
  70. {
  71. index_inc(&q->tail, q->len);
  72. }
  73. /*ISCSI */
  74. struct be_eq_obj {
  75. bool todo_mcc_cq;
  76. bool todo_cq;
  77. struct be_queue_info q;
  78. struct beiscsi_hba *phba;
  79. struct be_queue_info *cq;
  80. struct work_struct work_cqs; /* Work Item */
  81. struct blk_iopoll iopoll;
  82. };
  83. struct be_mcc_obj {
  84. struct be_queue_info q;
  85. struct be_queue_info cq;
  86. };
  87. struct be_ctrl_info {
  88. u8 __iomem *csr;
  89. u8 __iomem *db; /* Door Bell */
  90. u8 __iomem *pcicfg; /* PCI config space */
  91. struct pci_dev *pdev;
  92. /* Mbox used for cmd request/response */
  93. spinlock_t mbox_lock; /* For serializing mbox cmds to BE card */
  94. struct be_dma_mem mbox_mem;
  95. /* Mbox mem is adjusted to align to 16 bytes. The allocated addr
  96. * is stored for freeing purpose */
  97. struct be_dma_mem mbox_mem_alloced;
  98. /* MCC Rings */
  99. struct be_mcc_obj mcc_obj;
  100. spinlock_t mcc_lock; /* For serializing mcc cmds to BE card */
  101. spinlock_t mcc_cq_lock;
  102. wait_queue_head_t mcc_wait[MAX_MCC_CMD + 1];
  103. unsigned int mcc_tag[MAX_MCC_CMD];
  104. unsigned int mcc_numtag[MAX_MCC_CMD + 1];
  105. unsigned short mcc_alloc_index;
  106. unsigned short mcc_free_index;
  107. unsigned int mcc_tag_available;
  108. };
  109. #include "be_cmds.h"
  110. #define PAGE_SHIFT_4K 12
  111. #define PAGE_SIZE_4K (1 << PAGE_SHIFT_4K)
  112. #define mcc_timeout 120000 /* 5s timeout */
  113. /* Returns number of pages spanned by the data starting at the given addr */
  114. #define PAGES_4K_SPANNED(_address, size) \
  115. ((u32)((((size_t)(_address) & (PAGE_SIZE_4K - 1)) + \
  116. (size) + (PAGE_SIZE_4K - 1)) >> PAGE_SHIFT_4K))
  117. /* Returns bit offset within a DWORD of a bitfield */
  118. #define AMAP_BIT_OFFSET(_struct, field) \
  119. (((size_t)&(((_struct *)0)->field))%32)
  120. /* Returns the bit mask of the field that is NOT shifted into location. */
  121. static inline u32 amap_mask(u32 bitsize)
  122. {
  123. return (bitsize == 32 ? 0xFFFFFFFF : (1 << bitsize) - 1);
  124. }
  125. static inline void amap_set(void *ptr, u32 dw_offset, u32 mask,
  126. u32 offset, u32 value)
  127. {
  128. u32 *dw = (u32 *) ptr + dw_offset;
  129. *dw &= ~(mask << offset);
  130. *dw |= (mask & value) << offset;
  131. }
  132. #define AMAP_SET_BITS(_struct, field, ptr, val) \
  133. amap_set(ptr, \
  134. offsetof(_struct, field)/32, \
  135. amap_mask(sizeof(((_struct *)0)->field)), \
  136. AMAP_BIT_OFFSET(_struct, field), \
  137. val)
  138. static inline u32 amap_get(void *ptr, u32 dw_offset, u32 mask, u32 offset)
  139. {
  140. u32 *dw = ptr;
  141. return mask & (*(dw + dw_offset) >> offset);
  142. }
  143. #define AMAP_GET_BITS(_struct, field, ptr) \
  144. amap_get(ptr, \
  145. offsetof(_struct, field)/32, \
  146. amap_mask(sizeof(((_struct *)0)->field)), \
  147. AMAP_BIT_OFFSET(_struct, field))
  148. #define be_dws_cpu_to_le(wrb, len) swap_dws(wrb, len)
  149. #define be_dws_le_to_cpu(wrb, len) swap_dws(wrb, len)
  150. static inline void swap_dws(void *wrb, int len)
  151. {
  152. #ifdef __BIG_ENDIAN
  153. u32 *dw = wrb;
  154. WARN_ON(len % 4);
  155. do {
  156. *dw = cpu_to_le32(*dw);
  157. dw++;
  158. len -= 4;
  159. } while (len);
  160. #endif /* __BIG_ENDIAN */
  161. }
  162. #endif /* BEISCSI_H */