megaraid_ioctl.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. *
  4. * Linux MegaRAID device driver
  5. *
  6. * Copyright (c) 2003-2004 LSI Logic Corporation.
  7. *
  8. * FILE : megaraid_ioctl.h
  9. *
  10. * Definitions to interface with user level applications
  11. */
  12. #ifndef _MEGARAID_IOCTL_H_
  13. #define _MEGARAID_IOCTL_H_
  14. #include <linux/types.h>
  15. #include <linux/semaphore.h>
  16. #include <linux/timer.h>
  17. #include "mbox_defs.h"
  18. /*
  19. * console messages debug levels
  20. */
  21. #define CL_ANN 0 /* print unconditionally, announcements */
  22. #define CL_DLEVEL1 1 /* debug level 1, informative */
  23. #define CL_DLEVEL2 2 /* debug level 2, verbose */
  24. #define CL_DLEVEL3 3 /* debug level 3, very verbose */
  25. /**
  26. * con_log() - console log routine
  27. * @level : indicates the severity of the message.
  28. * @fmt : format string
  29. *
  30. * con_log displays the error messages on the console based on the current
  31. * debug level. Also it attaches the appropriate kernel severity level with
  32. * the message.
  33. */
  34. #define con_log(level, fmt) if (LSI_DBGLVL >= level) printk fmt;
  35. /*
  36. * Definitions & Declarations needed to use common management module
  37. */
  38. #define MEGAIOC_MAGIC 'm'
  39. #define MEGAIOCCMD _IOWR(MEGAIOC_MAGIC, 0, mimd_t)
  40. #define MEGAIOC_QNADAP 'm' /* Query # of adapters */
  41. #define MEGAIOC_QDRVRVER 'e' /* Query driver version */
  42. #define MEGAIOC_QADAPINFO 'g' /* Query adapter information */
  43. #define USCSICMD 0x80
  44. #define UIOC_RD 0x00001
  45. #define UIOC_WR 0x00002
  46. #define MBOX_CMD 0x00000
  47. #define GET_DRIVER_VER 0x10000
  48. #define GET_N_ADAP 0x20000
  49. #define GET_ADAP_INFO 0x30000
  50. #define GET_CAP 0x40000
  51. #define GET_STATS 0x50000
  52. #define GET_IOCTL_VERSION 0x01
  53. #define EXT_IOCTL_SIGN_SZ 16
  54. #define EXT_IOCTL_SIGN "$$_EXTD_IOCTL_$$"
  55. #define MBOX_LEGACY 0x00 /* ioctl has legacy mbox*/
  56. #define MBOX_HPE 0x01 /* ioctl has hpe mbox */
  57. #define APPTYPE_MIMD 0x00 /* old existing apps */
  58. #define APPTYPE_UIOC 0x01 /* new apps using uioc */
  59. #define IOCTL_ISSUE 0x00000001 /* Issue ioctl */
  60. #define IOCTL_ABORT 0x00000002 /* Abort previous ioctl */
  61. #define DRVRTYPE_MBOX 0x00000001 /* regular mbox driver */
  62. #define DRVRTYPE_HPE 0x00000002 /* new hpe driver */
  63. #define MKADAP(adapno) (MEGAIOC_MAGIC << 8 | (adapno) )
  64. #define GETADAP(mkadap) ((mkadap) ^ MEGAIOC_MAGIC << 8)
  65. #define MAX_DMA_POOLS 5 /* 4k, 8k, 16k, 32k, 64k*/
  66. /**
  67. * struct uioc_t - the common ioctl packet structure
  68. *
  69. * @signature : Must be "$$_EXTD_IOCTL_$$"
  70. * @mb_type : Type of the mail box (MB_LEGACY or MB_HPE)
  71. * @app_type : Type of the issuing application (existing or new)
  72. * @opcode : Opcode of the command
  73. * @adapno : Adapter number
  74. * @cmdbuf : Pointer to buffer - can point to mbox or plain data buffer
  75. * @xferlen : xferlen for DCMD and non mailbox commands
  76. * @data_dir : Direction of the data transfer
  77. * @status : Status from the driver
  78. * @reserved : reserved bytes for future expansion
  79. *
  80. * @user_data : user data transfer address is saved in this
  81. * @user_data_len: length of the data buffer sent by user app
  82. * @user_pthru : user passthru address is saves in this (null if DCMD)
  83. * @pthru32 : kernel address passthru (allocated per kioc)
  84. * @pthru32_h : physicall address of @pthru32
  85. * @list : for kioc free pool list maintenance
  86. * @done : call back routine for llds to call when kioc is completed
  87. * @buf_vaddr : dma pool buffer attached to kioc for data transfer
  88. * @buf_paddr : physical address of the dma pool buffer
  89. * @pool_index : index of the dma pool that @buf_vaddr is taken from
  90. * @free_buf : indicates if buffer needs to be freed after kioc completes
  91. *
  92. * Note : All LSI drivers understand only this packet. Any other
  93. * : format sent by applications would be converted to this.
  94. */
  95. typedef struct uioc {
  96. /* User Apps: */
  97. uint8_t signature[EXT_IOCTL_SIGN_SZ];
  98. uint16_t mb_type;
  99. uint16_t app_type;
  100. uint32_t opcode;
  101. uint32_t adapno;
  102. uint64_t cmdbuf;
  103. uint32_t xferlen;
  104. uint32_t data_dir;
  105. int32_t status;
  106. uint8_t reserved[128];
  107. /* Driver Data: */
  108. void __user * user_data;
  109. uint32_t user_data_len;
  110. /* 64bit alignment */
  111. uint32_t pad_for_64bit_align;
  112. mraid_passthru_t __user *user_pthru;
  113. mraid_passthru_t *pthru32;
  114. dma_addr_t pthru32_h;
  115. struct list_head list;
  116. void (*done)(struct uioc*);
  117. caddr_t buf_vaddr;
  118. dma_addr_t buf_paddr;
  119. int8_t pool_index;
  120. uint8_t free_buf;
  121. uint8_t timedout;
  122. } __attribute__ ((aligned(1024),packed)) uioc_t;
  123. /* For on-stack uioc timers. */
  124. struct uioc_timeout {
  125. struct timer_list timer;
  126. uioc_t *uioc;
  127. };
  128. /**
  129. * struct mraid_hba_info - information about the controller
  130. *
  131. * @pci_vendor_id : PCI vendor id
  132. * @pci_device_id : PCI device id
  133. * @subsystem_vendor_id : PCI subsystem vendor id
  134. * @subsystem_device_id : PCI subsystem device id
  135. * @baseport : base port of hba memory
  136. * @pci_bus : PCI bus
  137. * @pci_dev_fn : PCI device/function values
  138. * @irq : interrupt vector for the device
  139. *
  140. * Extended information of 256 bytes about the controller. Align on the single
  141. * byte boundary so that 32-bit applications can be run on 64-bit platform
  142. * drivers withoug re-compilation.
  143. * NOTE: reduce the number of reserved bytes whenever new field are added, so
  144. * that total size of the structure remains 256 bytes.
  145. */
  146. typedef struct mraid_hba_info {
  147. uint16_t pci_vendor_id;
  148. uint16_t pci_device_id;
  149. uint16_t subsys_vendor_id;
  150. uint16_t subsys_device_id;
  151. uint64_t baseport;
  152. uint8_t pci_bus;
  153. uint8_t pci_dev_fn;
  154. uint8_t pci_slot;
  155. uint8_t irq;
  156. uint32_t unique_id;
  157. uint32_t host_no;
  158. uint8_t num_ldrv;
  159. } __attribute__ ((aligned(256), packed)) mraid_hba_info_t;
  160. /**
  161. * mcontroller : adapter info structure for old mimd_t apps
  162. *
  163. * @base : base address
  164. * @irq : irq number
  165. * @numldrv : number of logical drives
  166. * @pcibus : pci bus
  167. * @pcidev : pci device
  168. * @pcifun : pci function
  169. * @pciid : pci id
  170. * @pcivendor : vendor id
  171. * @pcislot : slot number
  172. * @uid : unique id
  173. */
  174. typedef struct mcontroller {
  175. uint64_t base;
  176. uint8_t irq;
  177. uint8_t numldrv;
  178. uint8_t pcibus;
  179. uint16_t pcidev;
  180. uint8_t pcifun;
  181. uint16_t pciid;
  182. uint16_t pcivendor;
  183. uint8_t pcislot;
  184. uint32_t uid;
  185. } __attribute__ ((packed)) mcontroller_t;
  186. /**
  187. * mm_dmapool_t : Represents one dma pool with just one buffer
  188. *
  189. * @vaddr : Virtual address
  190. * @paddr : DMA physicall address
  191. * @bufsize : In KB - 4 = 4k, 8 = 8k etc.
  192. * @handle : Handle to the dma pool
  193. * @lock : lock to synchronize access to the pool
  194. * @in_use : If pool already in use, attach new block
  195. */
  196. typedef struct mm_dmapool {
  197. caddr_t vaddr;
  198. dma_addr_t paddr;
  199. uint32_t buf_size;
  200. struct dma_pool *handle;
  201. spinlock_t lock;
  202. uint8_t in_use;
  203. } mm_dmapool_t;
  204. /**
  205. * mraid_mmadp_t: Structure that drivers pass during (un)registration
  206. *
  207. * @unique_id : Any unique id (usually PCI bus+dev+fn)
  208. * @drvr_type : megaraid or hpe (DRVRTYPE_MBOX or DRVRTYPE_HPE)
  209. * @drv_data : Driver specific; not touched by the common module
  210. * @timeout : timeout for issued kiocs
  211. * @max_kioc : Maximum ioctl packets acceptable by the lld
  212. * @pdev : pci dev; used for allocating dma'ble memory
  213. * @issue_uioc : Driver supplied routine to issue uioc_t commands
  214. * : issue_uioc(drvr_data, kioc, ISSUE/ABORT, uioc_done)
  215. * @quiescent : flag to indicate if ioctl can be issued to this adp
  216. * @list : attach with the global list of adapters
  217. * @kioc_list : block of mem for @max_kioc number of kiocs
  218. * @kioc_pool : pool of free kiocs
  219. * @kioc_pool_lock : protection for free pool
  220. * @kioc_semaphore : so as not to exceed @max_kioc parallel ioctls
  221. * @mbox_list : block of mem for @max_kioc number of mboxes
  222. * @pthru_dma_pool : DMA pool to allocate passthru packets
  223. * @dma_pool_list : array of dma pools
  224. */
  225. typedef struct mraid_mmadp {
  226. /* Filled by driver */
  227. uint32_t unique_id;
  228. uint32_t drvr_type;
  229. unsigned long drvr_data;
  230. uint16_t timeout;
  231. uint8_t max_kioc;
  232. struct pci_dev *pdev;
  233. int(*issue_uioc)(unsigned long, uioc_t *, uint32_t);
  234. /* Maintained by common module */
  235. uint32_t quiescent;
  236. struct list_head list;
  237. uioc_t *kioc_list;
  238. struct list_head kioc_pool;
  239. spinlock_t kioc_pool_lock;
  240. struct semaphore kioc_semaphore;
  241. mbox64_t *mbox_list;
  242. struct dma_pool *pthru_dma_pool;
  243. mm_dmapool_t dma_pool_list[MAX_DMA_POOLS];
  244. } mraid_mmadp_t;
  245. int mraid_mm_register_adp(mraid_mmadp_t *);
  246. int mraid_mm_unregister_adp(uint32_t);
  247. uint32_t mraid_mm_adapter_app_handle(uint32_t);
  248. #endif /* _MEGARAID_IOCTL_H_ */