303 lines · c
1/* SPDX-License-Identifier: GPL-2.0-or-later */2/*3 *4 * Linux MegaRAID device driver5 *6 * Copyright (c) 2003-2004 LSI Logic Corporation.7 *8 * FILE : megaraid_ioctl.h9 *10 * Definitions to interface with user level applications11 */12 13#ifndef _MEGARAID_IOCTL_H_14#define _MEGARAID_IOCTL_H_15 16#include <linux/types.h>17#include <linux/semaphore.h>18#include <linux/timer.h>19 20#include "mbox_defs.h"21 22/*23 * console messages debug levels24 */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/**31 * con_log() - console log routine32 * @level : indicates the severity of the message.33 * @fmt : format string34 *35 * con_log displays the error messages on the console based on the current36 * debug level. Also it attaches the appropriate kernel severity level with37 * the message.38 */39#define con_log(level, fmt) if (LSI_DBGLVL >= level) printk fmt;40 41/*42 * Definitions & Declarations needed to use common management module43 */44 45#define MEGAIOC_MAGIC 'm'46#define MEGAIOCCMD _IOWR(MEGAIOC_MAGIC, 0, mimd_t)47 48#define MEGAIOC_QNADAP 'm' /* Query # of adapters */49#define MEGAIOC_QDRVRVER 'e' /* Query driver version */50#define MEGAIOC_QADAPINFO 'g' /* Query adapter information */51 52#define USCSICMD 0x8053#define UIOC_RD 0x0000154#define UIOC_WR 0x0000255 56#define MBOX_CMD 0x0000057#define GET_DRIVER_VER 0x1000058#define GET_N_ADAP 0x2000059#define GET_ADAP_INFO 0x3000060#define GET_CAP 0x4000061#define GET_STATS 0x5000062#define GET_IOCTL_VERSION 0x0163 64#define EXT_IOCTL_SIGN_SZ 1665#define EXT_IOCTL_SIGN "$$_EXTD_IOCTL_$$"66 67#define MBOX_LEGACY 0x00 /* ioctl has legacy mbox*/68#define MBOX_HPE 0x01 /* ioctl has hpe mbox */69 70#define APPTYPE_MIMD 0x00 /* old existing apps */71#define APPTYPE_UIOC 0x01 /* new apps using uioc */72 73#define IOCTL_ISSUE 0x00000001 /* Issue ioctl */74#define IOCTL_ABORT 0x00000002 /* Abort previous ioctl */75 76#define DRVRTYPE_MBOX 0x00000001 /* regular mbox driver */77#define DRVRTYPE_HPE 0x00000002 /* new hpe driver */78 79#define MKADAP(adapno) (MEGAIOC_MAGIC << 8 | (adapno) )80#define GETADAP(mkadap) ((mkadap) ^ MEGAIOC_MAGIC << 8)81 82#define MAX_DMA_POOLS 5 /* 4k, 8k, 16k, 32k, 64k*/83 84 85/**86 * struct uioc_t - the common ioctl packet structure87 *88 * @signature : Must be "$$_EXTD_IOCTL_$$"89 * @mb_type : Type of the mail box (MB_LEGACY or MB_HPE)90 * @app_type : Type of the issuing application (existing or new)91 * @opcode : Opcode of the command92 * @adapno : Adapter number93 * @cmdbuf : Pointer to buffer - can point to mbox or plain data buffer94 * @xferlen : xferlen for DCMD and non mailbox commands95 * @data_dir : Direction of the data transfer96 * @status : Status from the driver97 * @reserved : reserved bytes for future expansion98 *99 * @user_data : user data transfer address is saved in this100 * @user_data_len: length of the data buffer sent by user app101 * @user_pthru : user passthru address is saves in this (null if DCMD)102 * @pthru32 : kernel address passthru (allocated per kioc)103 * @pthru32_h : physicall address of @pthru32104 * @list : for kioc free pool list maintenance105 * @done : call back routine for llds to call when kioc is completed106 * @buf_vaddr : dma pool buffer attached to kioc for data transfer107 * @buf_paddr : physical address of the dma pool buffer108 * @pool_index : index of the dma pool that @buf_vaddr is taken from109 * @free_buf : indicates if buffer needs to be freed after kioc completes110 *111 * Note : All LSI drivers understand only this packet. Any other112 * : format sent by applications would be converted to this.113 */114typedef struct uioc {115 116/* User Apps: */117 118 uint8_t signature[EXT_IOCTL_SIGN_SZ];119 uint16_t mb_type;120 uint16_t app_type;121 uint32_t opcode;122 uint32_t adapno;123 uint64_t cmdbuf;124 uint32_t xferlen;125 uint32_t data_dir;126 int32_t status;127 uint8_t reserved[128];128 129/* Driver Data: */130 void __user * user_data;131 uint32_t user_data_len;132 133 /* 64bit alignment */134 uint32_t pad_for_64bit_align;135 136 mraid_passthru_t __user *user_pthru;137 138 mraid_passthru_t *pthru32;139 dma_addr_t pthru32_h;140 141 struct list_head list;142 void (*done)(struct uioc*);143 144 caddr_t buf_vaddr;145 dma_addr_t buf_paddr;146 int8_t pool_index;147 uint8_t free_buf;148 149 uint8_t timedout;150 151} __attribute__ ((aligned(1024),packed)) uioc_t;152 153/* For on-stack uioc timers. */154struct uioc_timeout {155 struct timer_list timer;156 uioc_t *uioc;157};158 159/**160 * struct mraid_hba_info - information about the controller161 *162 * @pci_vendor_id : PCI vendor id163 * @pci_device_id : PCI device id164 * @subsystem_vendor_id : PCI subsystem vendor id165 * @subsystem_device_id : PCI subsystem device id166 * @baseport : base port of hba memory167 * @pci_bus : PCI bus168 * @pci_dev_fn : PCI device/function values169 * @irq : interrupt vector for the device170 *171 * Extended information of 256 bytes about the controller. Align on the single172 * byte boundary so that 32-bit applications can be run on 64-bit platform173 * drivers withoug re-compilation.174 * NOTE: reduce the number of reserved bytes whenever new field are added, so175 * that total size of the structure remains 256 bytes.176 */177typedef struct mraid_hba_info {178 179 uint16_t pci_vendor_id;180 uint16_t pci_device_id;181 uint16_t subsys_vendor_id;182 uint16_t subsys_device_id;183 184 uint64_t baseport;185 uint8_t pci_bus;186 uint8_t pci_dev_fn;187 uint8_t pci_slot;188 uint8_t irq;189 190 uint32_t unique_id;191 uint32_t host_no;192 193 uint8_t num_ldrv;194} __attribute__ ((aligned(256), packed)) mraid_hba_info_t;195 196 197/**198 * mcontroller : adapter info structure for old mimd_t apps199 *200 * @base : base address201 * @irq : irq number202 * @numldrv : number of logical drives203 * @pcibus : pci bus204 * @pcidev : pci device205 * @pcifun : pci function206 * @pciid : pci id207 * @pcivendor : vendor id208 * @pcislot : slot number209 * @uid : unique id210 */211typedef struct mcontroller {212 213 uint64_t base;214 uint8_t irq;215 uint8_t numldrv;216 uint8_t pcibus;217 uint16_t pcidev;218 uint8_t pcifun;219 uint16_t pciid;220 uint16_t pcivendor;221 uint8_t pcislot;222 uint32_t uid;223 224} __attribute__ ((packed)) mcontroller_t;225 226 227/**228 * mm_dmapool_t : Represents one dma pool with just one buffer229 *230 * @vaddr : Virtual address231 * @paddr : DMA physicall address232 * @bufsize : In KB - 4 = 4k, 8 = 8k etc.233 * @handle : Handle to the dma pool234 * @lock : lock to synchronize access to the pool235 * @in_use : If pool already in use, attach new block236 */237typedef struct mm_dmapool {238 caddr_t vaddr;239 dma_addr_t paddr;240 uint32_t buf_size;241 struct dma_pool *handle;242 spinlock_t lock;243 uint8_t in_use;244} mm_dmapool_t;245 246 247/**248 * mraid_mmadp_t: Structure that drivers pass during (un)registration249 *250 * @unique_id : Any unique id (usually PCI bus+dev+fn)251 * @drvr_type : megaraid or hpe (DRVRTYPE_MBOX or DRVRTYPE_HPE)252 * @drv_data : Driver specific; not touched by the common module253 * @timeout : timeout for issued kiocs254 * @max_kioc : Maximum ioctl packets acceptable by the lld255 * @pdev : pci dev; used for allocating dma'ble memory256 * @issue_uioc : Driver supplied routine to issue uioc_t commands257 * : issue_uioc(drvr_data, kioc, ISSUE/ABORT, uioc_done)258 * @quiescent : flag to indicate if ioctl can be issued to this adp259 * @list : attach with the global list of adapters260 * @kioc_list : block of mem for @max_kioc number of kiocs261 * @kioc_pool : pool of free kiocs262 * @kioc_pool_lock : protection for free pool263 * @kioc_semaphore : so as not to exceed @max_kioc parallel ioctls264 * @mbox_list : block of mem for @max_kioc number of mboxes265 * @pthru_dma_pool : DMA pool to allocate passthru packets266 * @dma_pool_list : array of dma pools267 */268 269typedef struct mraid_mmadp {270 271/* Filled by driver */272 273 uint32_t unique_id;274 uint32_t drvr_type;275 unsigned long drvr_data;276 uint16_t timeout;277 uint8_t max_kioc;278 279 struct pci_dev *pdev;280 281 int(*issue_uioc)(unsigned long, uioc_t *, uint32_t);282 283/* Maintained by common module */284 uint32_t quiescent;285 286 struct list_head list;287 uioc_t *kioc_list;288 struct list_head kioc_pool;289 spinlock_t kioc_pool_lock;290 struct semaphore kioc_semaphore;291 292 mbox64_t *mbox_list;293 struct dma_pool *pthru_dma_pool;294 mm_dmapool_t dma_pool_list[MAX_DMA_POOLS];295 296} mraid_mmadp_t;297 298int mraid_mm_register_adp(mraid_mmadp_t *);299int mraid_mm_unregister_adp(uint32_t);300uint32_t mraid_mm_adapter_app_handle(uint32_t);301 302#endif /* _MEGARAID_IOCTL_H_ */303