1 /* SPDX-License-Identifier: GPL-2.0-or-later */
4 * Linux MegaRAID device driver
6 * Copyright (c) 2003-2004 LSI Logic Corporation.
8 * FILE : megaraid_ioctl.h
10 * Definitions to interface with user level applications
13 #ifndef _MEGARAID_IOCTL_H_
14 #define _MEGARAID_IOCTL_H_
16 #include <linux/types.h>
17 #include <linux/semaphore.h>
18 #include <linux/timer.h>
20 #include "mbox_defs.h"
23 * console messages debug levels
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 */
31 * con_log() - console log routine
32 * @level : indicates the severity of the message.
33 * @fmt : format string
35 * con_log displays the error messages on the console based on the current
36 * debug level. Also it attaches the appropriate kernel severity level with
39 #define con_log(level, fmt) if (LSI_DBGLVL >= level) printk fmt;
42 * Definitions & Declarations needed to use common management module
45 #define MEGAIOC_MAGIC 'm'
46 #define MEGAIOCCMD _IOWR(MEGAIOC_MAGIC, 0, mimd_t)
48 #define MEGAIOC_QNADAP 'm' /* Query # of adapters */
49 #define MEGAIOC_QDRVRVER 'e' /* Query driver version */
50 #define MEGAIOC_QADAPINFO 'g' /* Query adapter information */
53 #define UIOC_RD 0x00001
54 #define UIOC_WR 0x00002
56 #define MBOX_CMD 0x00000
57 #define GET_DRIVER_VER 0x10000
58 #define GET_N_ADAP 0x20000
59 #define GET_ADAP_INFO 0x30000
60 #define GET_CAP 0x40000
61 #define GET_STATS 0x50000
62 #define GET_IOCTL_VERSION 0x01
64 #define EXT_IOCTL_SIGN_SZ 16
65 #define EXT_IOCTL_SIGN "$$_EXTD_IOCTL_$$"
67 #define MBOX_LEGACY 0x00 /* ioctl has legacy mbox*/
68 #define MBOX_HPE 0x01 /* ioctl has hpe mbox */
70 #define APPTYPE_MIMD 0x00 /* old existing apps */
71 #define APPTYPE_UIOC 0x01 /* new apps using uioc */
73 #define IOCTL_ISSUE 0x00000001 /* Issue ioctl */
74 #define IOCTL_ABORT 0x00000002 /* Abort previous ioctl */
76 #define DRVRTYPE_MBOX 0x00000001 /* regular mbox driver */
77 #define DRVRTYPE_HPE 0x00000002 /* new hpe driver */
79 #define MKADAP(adapno) (MEGAIOC_MAGIC << 8 | (adapno) )
80 #define GETADAP(mkadap) ((mkadap) ^ MEGAIOC_MAGIC << 8)
82 #define MAX_DMA_POOLS 5 /* 4k, 8k, 16k, 32k, 64k*/
86 * struct uioc_t - the common ioctl packet structure
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 command
92 * @adapno : Adapter number
93 * @cmdbuf : Pointer to buffer - can point to mbox or plain data buffer
94 * @xferlen : xferlen for DCMD and non mailbox commands
95 * @data_dir : Direction of the data transfer
96 * @status : Status from the driver
97 * @reserved : reserved bytes for future expansion
99 * @user_data : user data transfer address is saved in this
100 * @user_data_len: length of the data buffer sent by user app
101 * @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 @pthru32
104 * @list : for kioc free pool list maintenance
105 * @done : call back routine for llds to call when kioc is completed
106 * @buf_vaddr : dma pool buffer attached to kioc for data transfer
107 * @buf_paddr : physical address of the dma pool buffer
108 * @pool_index : index of the dma pool that @buf_vaddr is taken from
109 * @free_buf : indicates if buffer needs to be freed after kioc completes
111 * Note : All LSI drivers understand only this packet. Any other
112 * : format sent by applications would be converted to this.
114 typedef struct uioc
{
118 uint8_t signature
[EXT_IOCTL_SIGN_SZ
];
127 uint8_t reserved
[128];
130 void __user
* user_data
;
131 uint32_t user_data_len
;
133 /* 64bit alignment */
134 uint32_t pad_for_64bit_align
;
136 mraid_passthru_t __user
*user_pthru
;
138 mraid_passthru_t
*pthru32
;
139 dma_addr_t pthru32_h
;
141 struct list_head list
;
142 void (*done
)(struct uioc
*);
145 dma_addr_t buf_paddr
;
151 } __attribute__ ((aligned(1024),packed
)) uioc_t
;
153 /* For on-stack uioc timers. */
154 struct uioc_timeout
{
155 struct timer_list timer
;
160 * struct mraid_hba_info - information about the controller
162 * @pci_vendor_id : PCI vendor id
163 * @pci_device_id : PCI device id
164 * @subsystem_vendor_id : PCI subsystem vendor id
165 * @subsystem_device_id : PCI subsystem device id
166 * @baseport : base port of hba memory
168 * @pci_dev_fn : PCI device/function values
169 * @irq : interrupt vector for the device
171 * Extended information of 256 bytes about the controller. Align on the single
172 * byte boundary so that 32-bit applications can be run on 64-bit platform
173 * drivers withoug re-compilation.
174 * NOTE: reduce the number of reserved bytes whenever new field are added, so
175 * that total size of the structure remains 256 bytes.
177 typedef struct mraid_hba_info
{
179 uint16_t pci_vendor_id
;
180 uint16_t pci_device_id
;
181 uint16_t subsys_vendor_id
;
182 uint16_t subsys_device_id
;
194 } __attribute__ ((aligned(256), packed
)) mraid_hba_info_t
;
198 * mcontroller : adapter info structure for old mimd_t apps
200 * @base : base address
202 * @numldrv : number of logical drives
204 * @pcidev : pci device
205 * @pcifun : pci function
207 * @pcivendor : vendor id
208 * @pcislot : slot number
211 typedef struct mcontroller
{
224 } __attribute__ ((packed
)) mcontroller_t
;
228 * mm_dmapool_t : Represents one dma pool with just one buffer
230 * @vaddr : Virtual address
231 * @paddr : DMA physicall address
232 * @bufsize : In KB - 4 = 4k, 8 = 8k etc.
233 * @handle : Handle to the dma pool
234 * @lock : lock to synchronize access to the pool
235 * @in_use : If pool already in use, attach new block
237 typedef struct mm_dmapool
{
241 struct dma_pool
*handle
;
248 * mraid_mmadp_t: Structure that drivers pass during (un)registration
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 module
253 * @timeout : timeout for issued kiocs
254 * @max_kioc : Maximum ioctl packets acceptable by the lld
255 * @pdev : pci dev; used for allocating dma'ble memory
256 * @issue_uioc : Driver supplied routine to issue uioc_t commands
257 * : issue_uioc(drvr_data, kioc, ISSUE/ABORT, uioc_done)
258 * @quiescent : flag to indicate if ioctl can be issued to this adp
259 * @list : attach with the global list of adapters
260 * @kioc_list : block of mem for @max_kioc number of kiocs
261 * @kioc_pool : pool of free kiocs
262 * @kioc_pool_lock : protection for free pool
263 * @kioc_semaphore : so as not to exceed @max_kioc parallel ioctls
264 * @mbox_list : block of mem for @max_kioc number of mboxes
265 * @pthru_dma_pool : DMA pool to allocate passthru packets
266 * @dma_pool_list : array of dma pools
269 typedef struct mraid_mmadp
{
271 /* Filled by driver */
275 unsigned long drvr_data
;
279 struct pci_dev
*pdev
;
281 int(*issue_uioc
)(unsigned long, uioc_t
*, uint32_t);
283 /* Maintained by common module */
286 struct list_head list
;
288 struct list_head kioc_pool
;
289 spinlock_t kioc_pool_lock
;
290 struct semaphore kioc_semaphore
;
293 struct dma_pool
*pthru_dma_pool
;
294 mm_dmapool_t dma_pool_list
[MAX_DMA_POOLS
];
298 int mraid_mm_register_adp(mraid_mmadp_t
*);
299 int mraid_mm_unregister_adp(uint32_t);
300 uint32_t mraid_mm_adapter_app_handle(uint32_t);
302 #endif /* _MEGARAID_IOCTL_H_ */