hpilo.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 8
  16. /* max number of supported devices */
  17. #define MAX_ILO_DEV 1
  18. /* max number of files */
  19. #define MAX_OPEN (MAX_CCB * MAX_ILO_DEV)
  20. /* spin counter for open/close delay */
  21. #define MAX_WAIT 10000
  22. /*
  23. * Per device, used to track global memory allocations.
  24. */
  25. struct ilo_hwinfo {
  26. /* mmio registers on device */
  27. char __iomem *mmio_vaddr;
  28. /* doorbell registers on device */
  29. char __iomem *db_vaddr;
  30. /* shared memory on device used for channel control blocks */
  31. char __iomem *ram_vaddr;
  32. /* files corresponding to this device */
  33. struct ccb_data *ccb_alloc[MAX_CCB];
  34. struct pci_dev *ilo_dev;
  35. spinlock_t alloc_lock;
  36. spinlock_t fifo_lock;
  37. struct cdev cdev;
  38. };
  39. /* offset from mmio_vaddr */
  40. #define DB_OUT 0xD4
  41. /* DB_OUT reset bit */
  42. #define DB_RESET 26
  43. /*
  44. * Channel control block. Used to manage hardware queues.
  45. * The format must match hw's version. The hw ccb is 128 bytes,
  46. * but the context area shouldn't be touched by the driver.
  47. */
  48. #define ILOSW_CCB_SZ 64
  49. #define ILOHW_CCB_SZ 128
  50. struct ccb {
  51. union {
  52. char *send_fifobar;
  53. u64 padding1;
  54. } ccb_u1;
  55. union {
  56. char *send_desc;
  57. u64 padding2;
  58. } ccb_u2;
  59. u64 send_ctrl;
  60. union {
  61. char *recv_fifobar;
  62. u64 padding3;
  63. } ccb_u3;
  64. union {
  65. char *recv_desc;
  66. u64 padding4;
  67. } ccb_u4;
  68. u64 recv_ctrl;
  69. union {
  70. char __iomem *db_base;
  71. u64 padding5;
  72. } ccb_u5;
  73. u64 channel;
  74. /* unused context area (64 bytes) */
  75. };
  76. /* ccb queue parameters */
  77. #define SENDQ 1
  78. #define RECVQ 2
  79. #define NR_QENTRY 4
  80. #define L2_QENTRY_SZ 12
  81. /* ccb ctrl bitfields */
  82. #define CTRL_BITPOS_L2SZ 0
  83. #define CTRL_BITPOS_FIFOINDEXMASK 4
  84. #define CTRL_BITPOS_DESCLIMIT 18
  85. #define CTRL_BITPOS_A 30
  86. #define CTRL_BITPOS_G 31
  87. /* ccb doorbell macros */
  88. #define L2_DB_SIZE 14
  89. #define ONE_DB_SIZE (1 << L2_DB_SIZE)
  90. /*
  91. * Per fd structure used to track the ccb allocated to that dev file.
  92. */
  93. struct ccb_data {
  94. /* software version of ccb, using virtual addrs */
  95. struct ccb driver_ccb;
  96. /* hardware version of ccb, using physical addrs */
  97. struct ccb ilo_ccb;
  98. /* hardware ccb is written to this shared mapped device memory */
  99. struct ccb __iomem *mapped_ccb;
  100. /* dma'able memory used for send/recv queues */
  101. void *dma_va;
  102. dma_addr_t dma_pa;
  103. size_t dma_size;
  104. /* pointer to hardware device info */
  105. struct ilo_hwinfo *ilo_hw;
  106. /* usage count, to allow for shared ccb's */
  107. int ccb_cnt;
  108. /* open wanted exclusive access to this ccb */
  109. int ccb_excl;
  110. };
  111. /*
  112. * FIFO queue structure, shared with hw.
  113. */
  114. #define ILO_START_ALIGN 4096
  115. #define ILO_CACHE_SZ 128
  116. struct fifo {
  117. u64 nrents; /* user requested number of fifo entries */
  118. u64 imask; /* mask to extract valid fifo index */
  119. u64 merge; /* O/C bits to merge in during enqueue operation */
  120. u64 reset; /* set to non-zero when the target device resets */
  121. u8 pad_0[ILO_CACHE_SZ - (sizeof(u64) * 4)];
  122. u64 head;
  123. u8 pad_1[ILO_CACHE_SZ - (sizeof(u64))];
  124. u64 tail;
  125. u8 pad_2[ILO_CACHE_SZ - (sizeof(u64))];
  126. u64 fifobar[1];
  127. };
  128. /* convert between struct fifo, and the fifobar, which is saved in the ccb */
  129. #define FIFOHANDLESIZE (sizeof(struct fifo) - sizeof(u64))
  130. #define FIFOBARTOHANDLE(_fifo) \
  131. ((struct fifo *)(((char *)(_fifo)) - FIFOHANDLESIZE))
  132. /* the number of qwords to consume from the entry descriptor */
  133. #define ENTRY_BITPOS_QWORDS 0
  134. /* descriptor index number (within a specified queue) */
  135. #define ENTRY_BITPOS_DESCRIPTOR 10
  136. /* state bit, fifo entry consumed by consumer */
  137. #define ENTRY_BITPOS_C 22
  138. /* state bit, fifo entry is occupied */
  139. #define ENTRY_BITPOS_O 23
  140. #define ENTRY_BITS_QWORDS 10
  141. #define ENTRY_BITS_DESCRIPTOR 12
  142. #define ENTRY_BITS_C 1
  143. #define ENTRY_BITS_O 1
  144. #define ENTRY_BITS_TOTAL \
  145. (ENTRY_BITS_C + ENTRY_BITS_O + \
  146. ENTRY_BITS_QWORDS + ENTRY_BITS_DESCRIPTOR)
  147. /* extract various entry fields */
  148. #define ENTRY_MASK ((1 << ENTRY_BITS_TOTAL) - 1)
  149. #define ENTRY_MASK_C (((1 << ENTRY_BITS_C) - 1) << ENTRY_BITPOS_C)
  150. #define ENTRY_MASK_O (((1 << ENTRY_BITS_O) - 1) << ENTRY_BITPOS_O)
  151. #define ENTRY_MASK_QWORDS \
  152. (((1 << ENTRY_BITS_QWORDS) - 1) << ENTRY_BITPOS_QWORDS)
  153. #define ENTRY_MASK_DESCRIPTOR \
  154. (((1 << ENTRY_BITS_DESCRIPTOR) - 1) << ENTRY_BITPOS_DESCRIPTOR)
  155. #define ENTRY_MASK_NOSTATE (ENTRY_MASK >> (ENTRY_BITS_C + ENTRY_BITS_O))
  156. #endif /* __HPILO_H */