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