Linux Audio

Check our new training course

Loading...
  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
 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 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/**
 31 * con_log() - console log routine
 32 * @level		: indicates the severity of the message.
 33 * @fmt			: format string
 34 *
 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
 37 * 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 module
 43 */
 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		0x80
 53#define UIOC_RD			0x00001
 54#define UIOC_WR			0x00002
 55
 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
 63
 64#define EXT_IOCTL_SIGN_SZ	16
 65#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 structure
 87 *
 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
 98 *
 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
110 *
111 * Note		: All LSI drivers understand only this packet. Any other
112 *		: 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 controller
161 *
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
167 * @pci_bus			: PCI bus
168 * @pci_dev_fn			: PCI device/function values
169 * @irq				: interrupt vector for the device
170 *
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.
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 apps
199 *
200 * @base	: base address
201 * @irq		: irq number
202 * @numldrv	: number of logical drives
203 * @pcibus	: pci bus
204 * @pcidev	: pci device
205 * @pcifun	: pci function
206 * @pciid	: pci id
207 * @pcivendor	: vendor id
208 * @pcislot	: slot number
209 * @uid		: unique id
210 */
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 buffer
229 *
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
236 */
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)registration
249 *
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
267 */
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_ */