1*2874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Linux MegaRAID device driver 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * Copyright (c) 2003-2004 LSI Logic Corporation. 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * FILE : megaraid_ioctl.h 91da177e4SLinus Torvalds * 101da177e4SLinus Torvalds * Definitions to interface with user level applications 111da177e4SLinus Torvalds */ 121da177e4SLinus Torvalds 131da177e4SLinus Torvalds #ifndef _MEGARAID_IOCTL_H_ 141da177e4SLinus Torvalds #define _MEGARAID_IOCTL_H_ 151da177e4SLinus Torvalds 161da177e4SLinus Torvalds #include <linux/types.h> 176188e10dSMatthew Wilcox #include <linux/semaphore.h> 18c251a7beSKees Cook #include <linux/timer.h> 191da177e4SLinus Torvalds 201da177e4SLinus Torvalds #include "mbox_defs.h" 211da177e4SLinus Torvalds 22a69b74d3SRandy Dunlap /* 23a69b74d3SRandy Dunlap * console messages debug levels 241da177e4SLinus Torvalds */ 251da177e4SLinus Torvalds #define CL_ANN 0 /* print unconditionally, announcements */ 261da177e4SLinus Torvalds #define CL_DLEVEL1 1 /* debug level 1, informative */ 271da177e4SLinus Torvalds #define CL_DLEVEL2 2 /* debug level 2, verbose */ 281da177e4SLinus Torvalds #define CL_DLEVEL3 3 /* debug level 3, very verbose */ 291da177e4SLinus Torvalds 30a69b74d3SRandy Dunlap /** 31a69b74d3SRandy Dunlap * con_log() - console log routine 32a69b74d3SRandy Dunlap * @level : indicates the severity of the message. 33a69b74d3SRandy Dunlap * @fmt : format string 34a69b74d3SRandy Dunlap * 35a69b74d3SRandy Dunlap * con_log displays the error messages on the console based on the current 36a69b74d3SRandy Dunlap * debug level. Also it attaches the appropriate kernel severity level with 37a69b74d3SRandy Dunlap * the message. 38a69b74d3SRandy Dunlap */ 391da177e4SLinus Torvalds #define con_log(level, fmt) if (LSI_DBGLVL >= level) printk fmt; 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds /* 421da177e4SLinus Torvalds * Definitions & Declarations needed to use common management module 431da177e4SLinus Torvalds */ 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds #define MEGAIOC_MAGIC 'm' 461da177e4SLinus Torvalds #define MEGAIOCCMD _IOWR(MEGAIOC_MAGIC, 0, mimd_t) 471da177e4SLinus Torvalds 481da177e4SLinus Torvalds #define MEGAIOC_QNADAP 'm' /* Query # of adapters */ 491da177e4SLinus Torvalds #define MEGAIOC_QDRVRVER 'e' /* Query driver version */ 501da177e4SLinus Torvalds #define MEGAIOC_QADAPINFO 'g' /* Query adapter information */ 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds #define USCSICMD 0x80 531da177e4SLinus Torvalds #define UIOC_RD 0x00001 541da177e4SLinus Torvalds #define UIOC_WR 0x00002 551da177e4SLinus Torvalds 561da177e4SLinus Torvalds #define MBOX_CMD 0x00000 571da177e4SLinus Torvalds #define GET_DRIVER_VER 0x10000 581da177e4SLinus Torvalds #define GET_N_ADAP 0x20000 591da177e4SLinus Torvalds #define GET_ADAP_INFO 0x30000 601da177e4SLinus Torvalds #define GET_CAP 0x40000 611da177e4SLinus Torvalds #define GET_STATS 0x50000 621da177e4SLinus Torvalds #define GET_IOCTL_VERSION 0x01 631da177e4SLinus Torvalds 641da177e4SLinus Torvalds #define EXT_IOCTL_SIGN_SZ 16 651da177e4SLinus Torvalds #define EXT_IOCTL_SIGN "$$_EXTD_IOCTL_$$" 661da177e4SLinus Torvalds 671da177e4SLinus Torvalds #define MBOX_LEGACY 0x00 /* ioctl has legacy mbox*/ 681da177e4SLinus Torvalds #define MBOX_HPE 0x01 /* ioctl has hpe mbox */ 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds #define APPTYPE_MIMD 0x00 /* old existing apps */ 711da177e4SLinus Torvalds #define APPTYPE_UIOC 0x01 /* new apps using uioc */ 721da177e4SLinus Torvalds 731da177e4SLinus Torvalds #define IOCTL_ISSUE 0x00000001 /* Issue ioctl */ 741da177e4SLinus Torvalds #define IOCTL_ABORT 0x00000002 /* Abort previous ioctl */ 751da177e4SLinus Torvalds 761da177e4SLinus Torvalds #define DRVRTYPE_MBOX 0x00000001 /* regular mbox driver */ 771da177e4SLinus Torvalds #define DRVRTYPE_HPE 0x00000002 /* new hpe driver */ 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds #define MKADAP(adapno) (MEGAIOC_MAGIC << 8 | (adapno) ) 801da177e4SLinus Torvalds #define GETADAP(mkadap) ((mkadap) ^ MEGAIOC_MAGIC << 8) 811da177e4SLinus Torvalds 821da177e4SLinus Torvalds #define MAX_DMA_POOLS 5 /* 4k, 8k, 16k, 32k, 64k*/ 831da177e4SLinus Torvalds 841da177e4SLinus Torvalds 851da177e4SLinus Torvalds /** 861da177e4SLinus Torvalds * struct uioc_t - the common ioctl packet structure 871da177e4SLinus Torvalds * 881da177e4SLinus Torvalds * @signature : Must be "$$_EXTD_IOCTL_$$" 891da177e4SLinus Torvalds * @mb_type : Type of the mail box (MB_LEGACY or MB_HPE) 901da177e4SLinus Torvalds * @app_type : Type of the issuing application (existing or new) 911da177e4SLinus Torvalds * @opcode : Opcode of the command 921da177e4SLinus Torvalds * @adapno : Adapter number 931da177e4SLinus Torvalds * @cmdbuf : Pointer to buffer - can point to mbox or plain data buffer 941da177e4SLinus Torvalds * @xferlen : xferlen for DCMD and non mailbox commands 951da177e4SLinus Torvalds * @data_dir : Direction of the data transfer 961da177e4SLinus Torvalds * @status : Status from the driver 971da177e4SLinus Torvalds * @reserved : reserved bytes for future expansion 981da177e4SLinus Torvalds * 991da177e4SLinus Torvalds * @user_data : user data transfer address is saved in this 1001da177e4SLinus Torvalds * @user_data_len: length of the data buffer sent by user app 1011da177e4SLinus Torvalds * @user_pthru : user passthru address is saves in this (null if DCMD) 1021da177e4SLinus Torvalds * @pthru32 : kernel address passthru (allocated per kioc) 1031da177e4SLinus Torvalds * @pthru32_h : physicall address of @pthru32 1041da177e4SLinus Torvalds * @list : for kioc free pool list maintenance 1051da177e4SLinus Torvalds * @done : call back routine for llds to call when kioc is completed 1061da177e4SLinus Torvalds * @buf_vaddr : dma pool buffer attached to kioc for data transfer 1071da177e4SLinus Torvalds * @buf_paddr : physical address of the dma pool buffer 1081da177e4SLinus Torvalds * @pool_index : index of the dma pool that @buf_vaddr is taken from 1091da177e4SLinus Torvalds * @free_buf : indicates if buffer needs to be freed after kioc completes 1101da177e4SLinus Torvalds * 1111da177e4SLinus Torvalds * Note : All LSI drivers understand only this packet. Any other 1121da177e4SLinus Torvalds * : format sent by applications would be converted to this. 1131da177e4SLinus Torvalds */ 1141da177e4SLinus Torvalds typedef struct uioc { 1151da177e4SLinus Torvalds 1161da177e4SLinus Torvalds /* User Apps: */ 1171da177e4SLinus Torvalds 1181da177e4SLinus Torvalds uint8_t signature[EXT_IOCTL_SIGN_SZ]; 1191da177e4SLinus Torvalds uint16_t mb_type; 1201da177e4SLinus Torvalds uint16_t app_type; 1211da177e4SLinus Torvalds uint32_t opcode; 1221da177e4SLinus Torvalds uint32_t adapno; 1231da177e4SLinus Torvalds uint64_t cmdbuf; 1241da177e4SLinus Torvalds uint32_t xferlen; 1251da177e4SLinus Torvalds uint32_t data_dir; 1261da177e4SLinus Torvalds int32_t status; 1271da177e4SLinus Torvalds uint8_t reserved[128]; 1281da177e4SLinus Torvalds 1291da177e4SLinus Torvalds /* Driver Data: */ 1301da177e4SLinus Torvalds void __user * user_data; 1311da177e4SLinus Torvalds uint32_t user_data_len; 1320b4972d5SJu, Seokmann 1330b4972d5SJu, Seokmann /* 64bit alignment */ 1340b4972d5SJu, Seokmann uint32_t pad_for_64bit_align; 1350b4972d5SJu, Seokmann 1361da177e4SLinus Torvalds mraid_passthru_t __user *user_pthru; 1371da177e4SLinus Torvalds 1381da177e4SLinus Torvalds mraid_passthru_t *pthru32; 1391da177e4SLinus Torvalds dma_addr_t pthru32_h; 1401da177e4SLinus Torvalds 1411da177e4SLinus Torvalds struct list_head list; 1421da177e4SLinus Torvalds void (*done)(struct uioc*); 1431da177e4SLinus Torvalds 1441da177e4SLinus Torvalds caddr_t buf_vaddr; 1451da177e4SLinus Torvalds dma_addr_t buf_paddr; 1461da177e4SLinus Torvalds int8_t pool_index; 1471da177e4SLinus Torvalds uint8_t free_buf; 1481da177e4SLinus Torvalds 1491da177e4SLinus Torvalds uint8_t timedout; 1501da177e4SLinus Torvalds 1511da177e4SLinus Torvalds } __attribute__ ((aligned(1024),packed)) uioc_t; 1521da177e4SLinus Torvalds 153c251a7beSKees Cook /* For on-stack uioc timers. */ 154c251a7beSKees Cook struct uioc_timeout { 155c251a7beSKees Cook struct timer_list timer; 156c251a7beSKees Cook uioc_t *uioc; 157c251a7beSKees Cook }; 1581da177e4SLinus Torvalds 1591da177e4SLinus Torvalds /** 1601da177e4SLinus Torvalds * struct mraid_hba_info - information about the controller 1611da177e4SLinus Torvalds * 162a69b74d3SRandy Dunlap * @pci_vendor_id : PCI vendor id 163a69b74d3SRandy Dunlap * @pci_device_id : PCI device id 164a69b74d3SRandy Dunlap * @subsystem_vendor_id : PCI subsystem vendor id 165a69b74d3SRandy Dunlap * @subsystem_device_id : PCI subsystem device id 166a69b74d3SRandy Dunlap * @baseport : base port of hba memory 167a69b74d3SRandy Dunlap * @pci_bus : PCI bus 168a69b74d3SRandy Dunlap * @pci_dev_fn : PCI device/function values 169a69b74d3SRandy Dunlap * @irq : interrupt vector for the device 1701da177e4SLinus Torvalds * 1711da177e4SLinus Torvalds * Extended information of 256 bytes about the controller. Align on the single 1721da177e4SLinus Torvalds * byte boundary so that 32-bit applications can be run on 64-bit platform 1731da177e4SLinus Torvalds * drivers withoug re-compilation. 1741da177e4SLinus Torvalds * NOTE: reduce the number of reserved bytes whenever new field are added, so 1751da177e4SLinus Torvalds * that total size of the structure remains 256 bytes. 1761da177e4SLinus Torvalds */ 1771da177e4SLinus Torvalds typedef struct mraid_hba_info { 1781da177e4SLinus Torvalds 1791da177e4SLinus Torvalds uint16_t pci_vendor_id; 1801da177e4SLinus Torvalds uint16_t pci_device_id; 1811da177e4SLinus Torvalds uint16_t subsys_vendor_id; 1821da177e4SLinus Torvalds uint16_t subsys_device_id; 1831da177e4SLinus Torvalds 1841da177e4SLinus Torvalds uint64_t baseport; 1851da177e4SLinus Torvalds uint8_t pci_bus; 1861da177e4SLinus Torvalds uint8_t pci_dev_fn; 1871da177e4SLinus Torvalds uint8_t pci_slot; 1881da177e4SLinus Torvalds uint8_t irq; 1891da177e4SLinus Torvalds 1901da177e4SLinus Torvalds uint32_t unique_id; 1911da177e4SLinus Torvalds uint32_t host_no; 1921da177e4SLinus Torvalds 1931da177e4SLinus Torvalds uint8_t num_ldrv; 1941da177e4SLinus Torvalds } __attribute__ ((aligned(256), packed)) mraid_hba_info_t; 1951da177e4SLinus Torvalds 1961da177e4SLinus Torvalds 1971da177e4SLinus Torvalds /** 1981da177e4SLinus Torvalds * mcontroller : adapter info structure for old mimd_t apps 1991da177e4SLinus Torvalds * 2001da177e4SLinus Torvalds * @base : base address 2011da177e4SLinus Torvalds * @irq : irq number 2021da177e4SLinus Torvalds * @numldrv : number of logical drives 2031da177e4SLinus Torvalds * @pcibus : pci bus 2041da177e4SLinus Torvalds * @pcidev : pci device 2051da177e4SLinus Torvalds * @pcifun : pci function 2061da177e4SLinus Torvalds * @pciid : pci id 2071da177e4SLinus Torvalds * @pcivendor : vendor id 2081da177e4SLinus Torvalds * @pcislot : slot number 2091da177e4SLinus Torvalds * @uid : unique id 2101da177e4SLinus Torvalds */ 2111da177e4SLinus Torvalds typedef struct mcontroller { 2121da177e4SLinus Torvalds 2131da177e4SLinus Torvalds uint64_t base; 2141da177e4SLinus Torvalds uint8_t irq; 2151da177e4SLinus Torvalds uint8_t numldrv; 2161da177e4SLinus Torvalds uint8_t pcibus; 2171da177e4SLinus Torvalds uint16_t pcidev; 2181da177e4SLinus Torvalds uint8_t pcifun; 2191da177e4SLinus Torvalds uint16_t pciid; 2201da177e4SLinus Torvalds uint16_t pcivendor; 2211da177e4SLinus Torvalds uint8_t pcislot; 2221da177e4SLinus Torvalds uint32_t uid; 2231da177e4SLinus Torvalds 2241da177e4SLinus Torvalds } __attribute__ ((packed)) mcontroller_t; 2251da177e4SLinus Torvalds 2261da177e4SLinus Torvalds 2271da177e4SLinus Torvalds /** 2281da177e4SLinus Torvalds * mm_dmapool_t : Represents one dma pool with just one buffer 2291da177e4SLinus Torvalds * 2301da177e4SLinus Torvalds * @vaddr : Virtual address 2311da177e4SLinus Torvalds * @paddr : DMA physicall address 2321da177e4SLinus Torvalds * @bufsize : In KB - 4 = 4k, 8 = 8k etc. 2331da177e4SLinus Torvalds * @handle : Handle to the dma pool 2341da177e4SLinus Torvalds * @lock : lock to synchronize access to the pool 2351da177e4SLinus Torvalds * @in_use : If pool already in use, attach new block 2361da177e4SLinus Torvalds */ 2371da177e4SLinus Torvalds typedef struct mm_dmapool { 2381da177e4SLinus Torvalds caddr_t vaddr; 2391da177e4SLinus Torvalds dma_addr_t paddr; 2401da177e4SLinus Torvalds uint32_t buf_size; 2411da177e4SLinus Torvalds struct dma_pool *handle; 2421da177e4SLinus Torvalds spinlock_t lock; 2431da177e4SLinus Torvalds uint8_t in_use; 2441da177e4SLinus Torvalds } mm_dmapool_t; 2451da177e4SLinus Torvalds 2461da177e4SLinus Torvalds 2471da177e4SLinus Torvalds /** 2481da177e4SLinus Torvalds * mraid_mmadp_t: Structure that drivers pass during (un)registration 2491da177e4SLinus Torvalds * 2501da177e4SLinus Torvalds * @unique_id : Any unique id (usually PCI bus+dev+fn) 2511da177e4SLinus Torvalds * @drvr_type : megaraid or hpe (DRVRTYPE_MBOX or DRVRTYPE_HPE) 2521da177e4SLinus Torvalds * @drv_data : Driver specific; not touched by the common module 2531da177e4SLinus Torvalds * @timeout : timeout for issued kiocs 2541da177e4SLinus Torvalds * @max_kioc : Maximum ioctl packets acceptable by the lld 2551da177e4SLinus Torvalds * @pdev : pci dev; used for allocating dma'ble memory 2561da177e4SLinus Torvalds * @issue_uioc : Driver supplied routine to issue uioc_t commands 2571da177e4SLinus Torvalds * : issue_uioc(drvr_data, kioc, ISSUE/ABORT, uioc_done) 2581da177e4SLinus Torvalds * @quiescent : flag to indicate if ioctl can be issued to this adp 2591da177e4SLinus Torvalds * @list : attach with the global list of adapters 2601da177e4SLinus Torvalds * @kioc_list : block of mem for @max_kioc number of kiocs 2611da177e4SLinus Torvalds * @kioc_pool : pool of free kiocs 2621da177e4SLinus Torvalds * @kioc_pool_lock : protection for free pool 2631da177e4SLinus Torvalds * @kioc_semaphore : so as not to exceed @max_kioc parallel ioctls 2641da177e4SLinus Torvalds * @mbox_list : block of mem for @max_kioc number of mboxes 2651da177e4SLinus Torvalds * @pthru_dma_pool : DMA pool to allocate passthru packets 2661da177e4SLinus Torvalds * @dma_pool_list : array of dma pools 2671da177e4SLinus Torvalds */ 2681da177e4SLinus Torvalds 2691da177e4SLinus Torvalds typedef struct mraid_mmadp { 2701da177e4SLinus Torvalds 2711da177e4SLinus Torvalds /* Filled by driver */ 2721da177e4SLinus Torvalds 2731da177e4SLinus Torvalds uint32_t unique_id; 2741da177e4SLinus Torvalds uint32_t drvr_type; 2751da177e4SLinus Torvalds unsigned long drvr_data; 2761da177e4SLinus Torvalds uint16_t timeout; 2771da177e4SLinus Torvalds uint8_t max_kioc; 2781da177e4SLinus Torvalds 2791da177e4SLinus Torvalds struct pci_dev *pdev; 2801da177e4SLinus Torvalds 2811da177e4SLinus Torvalds int(*issue_uioc)(unsigned long, uioc_t *, uint32_t); 2821da177e4SLinus Torvalds 2831da177e4SLinus Torvalds /* Maintained by common module */ 2841da177e4SLinus Torvalds uint32_t quiescent; 2851da177e4SLinus Torvalds 2861da177e4SLinus Torvalds struct list_head list; 2871da177e4SLinus Torvalds uioc_t *kioc_list; 2881da177e4SLinus Torvalds struct list_head kioc_pool; 2891da177e4SLinus Torvalds spinlock_t kioc_pool_lock; 2901da177e4SLinus Torvalds struct semaphore kioc_semaphore; 2911da177e4SLinus Torvalds 2921da177e4SLinus Torvalds mbox64_t *mbox_list; 2931da177e4SLinus Torvalds struct dma_pool *pthru_dma_pool; 2941da177e4SLinus Torvalds mm_dmapool_t dma_pool_list[MAX_DMA_POOLS]; 2951da177e4SLinus Torvalds 2961da177e4SLinus Torvalds } mraid_mmadp_t; 2971da177e4SLinus Torvalds 2981da177e4SLinus Torvalds int mraid_mm_register_adp(mraid_mmadp_t *); 2991da177e4SLinus Torvalds int mraid_mm_unregister_adp(uint32_t); 3001da177e4SLinus Torvalds uint32_t mraid_mm_adapter_app_handle(uint32_t); 3011da177e4SLinus Torvalds 3021da177e4SLinus Torvalds #endif /* _MEGARAID_IOCTL_H_ */ 303