hpilo.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * linux/drivers/char/hpilo.h
  4. *
  5. * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
  6. * David Altobelli <[email protected]>
  7. */
  8. #ifndef __HPILO_H
  9. #define __HPILO_H
  10. #define ILO_NAME "hpilo"
  11. /* iLO ASIC PCI revision id */
  12. #define PCI_REV_ID_NECHES 7
  13. /* max number of open channel control blocks per device, hw limited to 32 */
  14. #define MAX_CCB 24
  15. /* min number of open channel control blocks per device, hw limited to 32 */
  16. #define MIN_CCB 8
  17. /* max number of supported devices */
  18. #define MAX_ILO_DEV 1
  19. /* max number of files */
  20. #define MAX_OPEN (MAX_CCB * MAX_ILO_DEV)
  21. /* total wait time in usec */
  22. #define MAX_WAIT_TIME 10000
  23. /* per spin wait time in usec */
  24. #define WAIT_TIME 10
  25. /* spin counter for open/close delay */
  26. #define MAX_WAIT (MAX_WAIT_TIME / WAIT_TIME)
  27. /*
  28. * Per device, used to track global memory allocations.
  29. */
  30. struct ilo_hwinfo {
  31. /* mmio registers on device */
  32. char __iomem *mmio_vaddr;
  33. /* doorbell registers on device */
  34. char __iomem *db_vaddr;
  35. /* shared memory on device used for channel control blocks */
  36. char __iomem *ram_vaddr;
  37. /* files corresponding to this device */
  38. struct ccb_data *ccb_alloc[MAX_CCB];
  39. struct pci_dev *ilo_dev;
  40. /*
  41. * open_lock serializes ccb_cnt during open and close
  42. * [ irq disabled ]
  43. * -> alloc_lock used when adding/removing/searching ccb_alloc,
  44. * which represents all ccbs open on the device
  45. * --> fifo_lock controls access to fifo queues shared with hw
  46. *
  47. * Locks must be taken in this order, but open_lock and alloc_lock
  48. * are optional, they do not need to be held in order to take a
  49. * lower level lock.
  50. */
  51. spinlock_t open_lock;
  52. spinlock_t alloc_lock;
  53. spinlock_t fifo_lock;
  54. struct cdev cdev;
  55. };
  56. /* offset from mmio_vaddr for enabling doorbell interrupts */
  57. #define DB_IRQ 0xB2
  58. /* offset from mmio_vaddr for outbound communications */
  59. #define DB_OUT 0xD4
  60. /* DB_OUT reset bit */
  61. #define DB_RESET 26
  62. /*
  63. * Channel control block. Used to manage hardware queues.
  64. * The format must match hw's version. The hw ccb is 128 bytes,
  65. * but the context area shouldn't be touched by the driver.
  66. */
  67. #define ILOSW_CCB_SZ 64
  68. #define ILOHW_CCB_SZ 128
  69. struct ccb {
  70. union {
  71. char *send_fifobar;
  72. u64 send_fifobar_pa;
  73. } ccb_u1;
  74. union {
  75. char *send_desc;
  76. u64 send_desc_pa;
  77. } ccb_u2;
  78. u64 send_ctrl;
  79. union {
  80. char *recv_fifobar;
  81. u64 recv_fifobar_pa;
  82. } ccb_u3;
  83. union {
  84. char *recv_desc;
  85. u64 recv_desc_pa;
  86. } ccb_u4;
  87. u64 recv_ctrl;
  88. union {
  89. char __iomem *db_base;
  90. u64 padding5;
  91. } ccb_u5;
  92. u64 channel;
  93. /* unused context area (64 bytes) */
  94. };
  95. /* ccb queue parameters */
  96. #define SENDQ 1
  97. #define RECVQ 2
  98. #define NR_QENTRY 4
  99. #define L2_QENTRY_SZ 12
  100. /* ccb ctrl bitfields */
  101. #define CTRL_BITPOS_L2SZ 0
  102. #define CTRL_BITPOS_FIFOINDEXMASK 4
  103. #define CTRL_BITPOS_DESCLIMIT 18
  104. #define CTRL_BITPOS_A 30
  105. #define CTRL_BITPOS_G 31
  106. /* ccb doorbell macros */
  107. #define L2_DB_SIZE 14
  108. #define ONE_DB_SIZE (1 << L2_DB_SIZE)
  109. /*
  110. * Per fd structure used to track the ccb allocated to that dev file.
  111. */
  112. struct ccb_data {
  113. /* software version of ccb, using virtual addrs */
  114. struct ccb driver_ccb;
  115. /* hardware version of ccb, using physical addrs */
  116. struct ccb ilo_ccb;
  117. /* hardware ccb is written to this shared mapped device memory */
  118. struct ccb __iomem *mapped_ccb;
  119. /* dma'able memory used for send/recv queues */
  120. void *dma_va;
  121. dma_addr_t dma_pa;
  122. size_t dma_size;
  123. /* pointer to hardware device info */
  124. struct ilo_hwinfo *ilo_hw;
  125. /* queue for this ccb to wait for recv data */
  126. wait_queue_head_t ccb_waitq;
  127. /* usage count, to allow for shared ccb's */
  128. int ccb_cnt;
  129. /* open wanted exclusive access to this ccb */
  130. int ccb_excl;
  131. };
  132. /*
  133. * FIFO queue structure, shared with hw.
  134. */
  135. #define ILO_START_ALIGN 4096
  136. #define ILO_CACHE_SZ 128
  137. struct fifo {
  138. u64 nrents; /* user requested number of fifo entries */
  139. u64 imask; /* mask to extract valid fifo index */
  140. u64 merge; /* O/C bits to merge in during enqueue operation */
  141. u64 reset; /* set to non-zero when the target device resets */
  142. u8 pad_0[ILO_CACHE_SZ - (sizeof(u64) * 4)];
  143. u64 head;
  144. u8 pad_1[ILO_CACHE_SZ - (sizeof(u64))];
  145. u64 tail;
  146. u8 pad_2[ILO_CACHE_SZ - (sizeof(u64))];
  147. u64 fifobar[];
  148. };
  149. /* convert between struct fifo, and the fifobar, which is saved in the ccb */
  150. #define FIFOHANDLESIZE (sizeof(struct fifo))
  151. #define FIFOBARTOHANDLE(_fifo) \
  152. ((struct fifo *)(((char *)(_fifo)) - FIFOHANDLESIZE))
  153. /* the number of qwords to consume from the entry descriptor */
  154. #define ENTRY_BITPOS_QWORDS 0
  155. /* descriptor index number (within a specified queue) */
  156. #define ENTRY_BITPOS_DESCRIPTOR 10
  157. /* state bit, fifo entry consumed by consumer */
  158. #define ENTRY_BITPOS_C 22
  159. /* state bit, fifo entry is occupied */
  160. #define ENTRY_BITPOS_O 23
  161. #define ENTRY_BITS_QWORDS 10
  162. #define ENTRY_BITS_DESCRIPTOR 12
  163. #define ENTRY_BITS_C 1
  164. #define ENTRY_BITS_O 1
  165. #define ENTRY_BITS_TOTAL \
  166. (ENTRY_BITS_C + ENTRY_BITS_O + \
  167. ENTRY_BITS_QWORDS + ENTRY_BITS_DESCRIPTOR)
  168. /* extract various entry fields */
  169. #define ENTRY_MASK ((1 << ENTRY_BITS_TOTAL) - 1)
  170. #define ENTRY_MASK_C (((1 << ENTRY_BITS_C) - 1) << ENTRY_BITPOS_C)
  171. #define ENTRY_MASK_O (((1 << ENTRY_BITS_O) - 1) << ENTRY_BITPOS_O)
  172. #define ENTRY_MASK_QWORDS \
  173. (((1 << ENTRY_BITS_QWORDS) - 1) << ENTRY_BITPOS_QWORDS)
  174. #define ENTRY_MASK_DESCRIPTOR \
  175. (((1 << ENTRY_BITS_DESCRIPTOR) - 1) << ENTRY_BITPOS_DESCRIPTOR)
  176. #define ENTRY_MASK_NOSTATE (ENTRY_MASK >> (ENTRY_BITS_C + ENTRY_BITS_O))
  177. #endif /* __HPILO_H */