hpilo.h 5.7 KB

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