megaraid_ioctl.h 8.4 KB

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