xref: /linux/drivers/scsi/megaraid/megaraid_mbox.h (revision 8be98d2f2a0a262f8bf8a0bc1fdf522b3c7aab17)
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_mbox.h
91da177e4SLinus Torvalds  */
101da177e4SLinus Torvalds 
111da177e4SLinus Torvalds #ifndef _MEGARAID_H_
121da177e4SLinus Torvalds #define _MEGARAID_H_
131da177e4SLinus Torvalds 
141da177e4SLinus Torvalds 
151da177e4SLinus Torvalds #include "mega_common.h"
161da177e4SLinus Torvalds #include "mbox_defs.h"
171da177e4SLinus Torvalds #include "megaraid_ioctl.h"
181da177e4SLinus Torvalds 
191da177e4SLinus Torvalds 
20cd96d96fSSumant Patro #define MEGARAID_VERSION	"2.20.5.1"
21cd96d96fSSumant Patro #define MEGARAID_EXT_VERSION	"(Release Date: Thu Nov 16 15:32:35 EST 2006)"
221da177e4SLinus Torvalds 
231da177e4SLinus Torvalds 
241da177e4SLinus Torvalds /*
251da177e4SLinus Torvalds  * Define some PCI values here until they are put in the kernel
261da177e4SLinus Torvalds  */
271da177e4SLinus Torvalds #define PCI_DEVICE_ID_PERC4_DI_DISCOVERY		0x000E
281da177e4SLinus Torvalds #define PCI_SUBSYS_ID_PERC4_DI_DISCOVERY		0x0123
291da177e4SLinus Torvalds 
301da177e4SLinus Torvalds #define PCI_DEVICE_ID_PERC4_SC				0x1960
311da177e4SLinus Torvalds #define PCI_SUBSYS_ID_PERC4_SC				0x0520
321da177e4SLinus Torvalds 
331da177e4SLinus Torvalds #define PCI_DEVICE_ID_PERC4_DC				0x1960
341da177e4SLinus Torvalds #define PCI_SUBSYS_ID_PERC4_DC				0x0518
351da177e4SLinus Torvalds 
36672b2d38SJu, Seokmann  #define PCI_DEVICE_ID_VERDE				0x0407
371da177e4SLinus Torvalds 
381da177e4SLinus Torvalds #define PCI_DEVICE_ID_PERC4_DI_EVERGLADES		0x000F
391da177e4SLinus Torvalds #define PCI_SUBSYS_ID_PERC4_DI_EVERGLADES		0x014A
401da177e4SLinus Torvalds 
411da177e4SLinus Torvalds #define PCI_DEVICE_ID_PERC4E_SI_BIGBEND			0x0013
421da177e4SLinus Torvalds #define PCI_SUBSYS_ID_PERC4E_SI_BIGBEND			0x016c
431da177e4SLinus Torvalds 
441da177e4SLinus Torvalds #define PCI_DEVICE_ID_PERC4E_DI_KOBUK			0x0013
451da177e4SLinus Torvalds #define PCI_SUBSYS_ID_PERC4E_DI_KOBUK			0x016d
461da177e4SLinus Torvalds 
471da177e4SLinus Torvalds #define PCI_DEVICE_ID_PERC4E_DI_CORVETTE		0x0013
481da177e4SLinus Torvalds #define PCI_SUBSYS_ID_PERC4E_DI_CORVETTE		0x016e
491da177e4SLinus Torvalds 
501da177e4SLinus Torvalds #define PCI_DEVICE_ID_PERC4E_DI_EXPEDITION		0x0013
511da177e4SLinus Torvalds #define PCI_SUBSYS_ID_PERC4E_DI_EXPEDITION		0x016f
521da177e4SLinus Torvalds 
531da177e4SLinus Torvalds #define PCI_DEVICE_ID_PERC4E_DI_GUADALUPE		0x0013
541da177e4SLinus Torvalds #define PCI_SUBSYS_ID_PERC4E_DI_GUADALUPE		0x0170
551da177e4SLinus Torvalds 
56672b2d38SJu, Seokmann  #define PCI_DEVICE_ID_DOBSON				0x0408
571da177e4SLinus Torvalds 
581da177e4SLinus Torvalds #define PCI_DEVICE_ID_MEGARAID_SCSI_320_0		0x1960
591da177e4SLinus Torvalds #define PCI_SUBSYS_ID_MEGARAID_SCSI_320_0		0xA520
601da177e4SLinus Torvalds 
611da177e4SLinus Torvalds #define PCI_DEVICE_ID_MEGARAID_SCSI_320_1		0x1960
621da177e4SLinus Torvalds #define PCI_SUBSYS_ID_MEGARAID_SCSI_320_1		0x0520
631da177e4SLinus Torvalds 
641da177e4SLinus Torvalds #define PCI_DEVICE_ID_MEGARAID_SCSI_320_2		0x1960
651da177e4SLinus Torvalds #define PCI_SUBSYS_ID_MEGARAID_SCSI_320_2		0x0518
661da177e4SLinus Torvalds 
671da177e4SLinus Torvalds #define PCI_DEVICE_ID_MEGARAID_I4_133_RAID		0x1960
681da177e4SLinus Torvalds #define PCI_SUBSYS_ID_MEGARAID_I4_133_RAID		0x0522
691da177e4SLinus Torvalds 
701da177e4SLinus Torvalds #define PCI_DEVICE_ID_MEGARAID_SATA_150_4		0x1960
711da177e4SLinus Torvalds #define PCI_SUBSYS_ID_MEGARAID_SATA_150_4		0x4523
721da177e4SLinus Torvalds 
731da177e4SLinus Torvalds #define PCI_DEVICE_ID_MEGARAID_SATA_150_6		0x1960
741da177e4SLinus Torvalds #define PCI_SUBSYS_ID_MEGARAID_SATA_150_6		0x0523
751da177e4SLinus Torvalds 
76672b2d38SJu, Seokmann  #define PCI_DEVICE_ID_LINDSAY				0x0409
771da177e4SLinus Torvalds 
781da177e4SLinus Torvalds #define PCI_DEVICE_ID_INTEL_RAID_SRCS16			0x1960
791da177e4SLinus Torvalds #define PCI_SUBSYS_ID_INTEL_RAID_SRCS16			0x0523
801da177e4SLinus Torvalds 
811da177e4SLinus Torvalds #define PCI_DEVICE_ID_INTEL_RAID_SRCU41L_LAKE_SHETEK	0x1960
821da177e4SLinus Torvalds #define PCI_SUBSYS_ID_INTEL_RAID_SRCU41L_LAKE_SHETEK	0x0520
831da177e4SLinus Torvalds 
841da177e4SLinus Torvalds #define PCI_SUBSYS_ID_PERC3_QC				0x0471
851da177e4SLinus Torvalds #define PCI_SUBSYS_ID_PERC3_DC				0x0493
861da177e4SLinus Torvalds #define PCI_SUBSYS_ID_PERC3_SC				0x0475
8769cd39e9SHannes Reinecke #define PCI_SUBSYS_ID_CERC_ATA100_4CH			0x0511
881da177e4SLinus Torvalds 
891da177e4SLinus Torvalds 
901da177e4SLinus Torvalds #define MBOX_MAX_SCSI_CMDS	128	// number of cmds reserved for kernel
911da177e4SLinus Torvalds #define MBOX_MAX_USER_CMDS	32	// number of cmds for applications
921da177e4SLinus Torvalds #define MBOX_DEF_CMD_PER_LUN	64	// default commands per lun
931da177e4SLinus Torvalds #define MBOX_DEFAULT_SG_SIZE	26	// default sg size supported by all fw
941da177e4SLinus Torvalds #define MBOX_MAX_SG_SIZE	32	// maximum scatter-gather list size
951da177e4SLinus Torvalds #define MBOX_MAX_SECTORS	128	// maximum sectors per IO
961da177e4SLinus Torvalds #define MBOX_TIMEOUT		30	// timeout value for internal cmds
971da177e4SLinus Torvalds #define MBOX_BUSY_WAIT		10	// max usec to wait for busy mailbox
981da177e4SLinus Torvalds #define MBOX_RESET_WAIT		180	// wait these many seconds in reset
991da177e4SLinus Torvalds #define MBOX_RESET_EXT_WAIT	120	// extended wait reset
100c005fb4fSJu, Seokmann #define MBOX_SYNC_WAIT_CNT	0xFFFF	// wait loop index for synchronous mode
101c005fb4fSJu, Seokmann 
102c005fb4fSJu, Seokmann #define MBOX_SYNC_DELAY_200	200	// 200 micro-seconds
1031da177e4SLinus Torvalds 
1041da177e4SLinus Torvalds /*
1051da177e4SLinus Torvalds  * maximum transfer that can happen through the firmware commands issued
1061da177e4SLinus Torvalds  * internnaly from the driver.
1071da177e4SLinus Torvalds  */
1081da177e4SLinus Torvalds #define MBOX_IBUF_SIZE		4096
1091da177e4SLinus Torvalds 
1101da177e4SLinus Torvalds 
1111da177e4SLinus Torvalds /**
1121da177e4SLinus Torvalds  * mbox_ccb_t - command control block specific to mailbox based controllers
1131da177e4SLinus Torvalds  * @raw_mbox		: raw mailbox pointer
1141da177e4SLinus Torvalds  * @mbox		: mailbox
1151da177e4SLinus Torvalds  * @mbox64		: extended mailbox
1166868aa76SColin Ian King  * @mbox_dma_h		: mailbox dma address
1171da177e4SLinus Torvalds  * @sgl64		: 64-bit scatter-gather list
1181da177e4SLinus Torvalds  * @sgl32		: 32-bit scatter-gather list
1191da177e4SLinus Torvalds  * @sgl_dma_h		: dma handle for the scatter-gather list
1201da177e4SLinus Torvalds  * @pthru		: passthru structure
1211da177e4SLinus Torvalds  * @pthru_dma_h		: dma handle for the passthru structure
1221da177e4SLinus Torvalds  * @epthru		: extended passthru structure
1231da177e4SLinus Torvalds  * @epthru_dma_h	: dma handle for extended passthru structure
1241da177e4SLinus Torvalds  * @buf_dma_h		: dma handle for buffers w/o sg list
1251da177e4SLinus Torvalds  *
1261da177e4SLinus Torvalds  * command control block specific to the mailbox based controllers
1271da177e4SLinus Torvalds  */
1281da177e4SLinus Torvalds typedef struct {
1291da177e4SLinus Torvalds 	uint8_t			*raw_mbox;
1301da177e4SLinus Torvalds 	mbox_t			*mbox;
1311da177e4SLinus Torvalds 	mbox64_t		*mbox64;
1321da177e4SLinus Torvalds 	dma_addr_t		mbox_dma_h;
1331da177e4SLinus Torvalds 	mbox_sgl64		*sgl64;
1341da177e4SLinus Torvalds 	mbox_sgl32		*sgl32;
1351da177e4SLinus Torvalds 	dma_addr_t		sgl_dma_h;
1361da177e4SLinus Torvalds 	mraid_passthru_t	*pthru;
1371da177e4SLinus Torvalds 	dma_addr_t		pthru_dma_h;
1381da177e4SLinus Torvalds 	mraid_epassthru_t	*epthru;
1391da177e4SLinus Torvalds 	dma_addr_t		epthru_dma_h;
1401da177e4SLinus Torvalds 	dma_addr_t		buf_dma_h;
1411da177e4SLinus Torvalds } mbox_ccb_t;
1421da177e4SLinus Torvalds 
1431da177e4SLinus Torvalds 
1441da177e4SLinus Torvalds /**
1451da177e4SLinus Torvalds  * mraid_device_t - adapter soft state structure for mailbox controllers
146a69b74d3SRandy Dunlap  * @una_mbox64			: 64-bit mbox - unaligned
147a69b74d3SRandy Dunlap  * @una_mbox64_dma		: mbox dma addr - unaligned
148a69b74d3SRandy Dunlap  * @mbox			: 32-bit mbox - aligned
149a69b74d3SRandy Dunlap  * @mbox64			: 64-bit mbox - aligned
150a69b74d3SRandy Dunlap  * @mbox_dma			: mbox dma addr - aligned
151a69b74d3SRandy Dunlap  * @mailbox_lock		: exclusion lock for the mailbox
152a69b74d3SRandy Dunlap  * @baseport			: base port of hba memory
153a69b74d3SRandy Dunlap  * @baseaddr			: mapped addr of hba memory
154a69b74d3SRandy Dunlap  * @mbox_pool			: pool of mailboxes
155a69b74d3SRandy Dunlap  * @mbox_pool_handle		: handle for the mailbox pool memory
156a69b74d3SRandy Dunlap  * @epthru_pool			: a pool for extended passthru commands
157a69b74d3SRandy Dunlap  * @epthru_pool_handle		: handle to the pool above
158a69b74d3SRandy Dunlap  * @sg_pool			: pool of scatter-gather lists for this driver
159a69b74d3SRandy Dunlap  * @sg_pool_handle		: handle to the pool above
160a69b74d3SRandy Dunlap  * @ccb_list			: list of our command control blocks
161a69b74d3SRandy Dunlap  * @uccb_list			: list of cmd control blocks for mgmt module
162a69b74d3SRandy Dunlap  * @umbox64			: array of mailbox for user commands (cmm)
163a69b74d3SRandy Dunlap  * @pdrv_state			: array for state of each physical drive.
164a69b74d3SRandy Dunlap  * @last_disp			: flag used to show device scanning
165a69b74d3SRandy Dunlap  * @hw_error			: set if FW not responding
166a69b74d3SRandy Dunlap  * @fast_load			: If set, skip physical device scanning
1671da177e4SLinus Torvalds  * @channel_class		: channel class, RAID or SCSI
1680c2cc433SMatthias Kaehlcke  * @sysfs_mtx			: mutex to serialize access to sysfs res.
1691da177e4SLinus Torvalds  * @sysfs_uioc			: management packet to issue FW calls from sysfs
1701da177e4SLinus Torvalds  * @sysfs_mbox64		: mailbox packet to issue FW calls from sysfs
1711da177e4SLinus Torvalds  * @sysfs_buffer		: data buffer for FW commands issued from sysfs
1721da177e4SLinus Torvalds  * @sysfs_buffer_dma		: DMA buffer for FW commands issued from sysfs
1731da177e4SLinus Torvalds  * @sysfs_wait_q		: wait queue for sysfs operations
1741da177e4SLinus Torvalds  * @random_del_supported	: set if the random deletion is supported
1751da177e4SLinus Torvalds  * @curr_ldmap			: current LDID map
1761da177e4SLinus Torvalds  *
1771da177e4SLinus Torvalds  * Initialization structure for mailbox controllers: memory based and IO based
1781da177e4SLinus Torvalds  * All the fields in this structure are LLD specific and may be discovered at
1791da177e4SLinus Torvalds  * init() or start() time.
1801da177e4SLinus Torvalds  *
1811da177e4SLinus Torvalds  * NOTE: The fields of this structures are placed to minimize cache misses
1821da177e4SLinus Torvalds  */
1831da177e4SLinus Torvalds #define MAX_LD_EXTENDED64	64
1841da177e4SLinus Torvalds typedef struct {
1851da177e4SLinus Torvalds 	mbox64_t			*una_mbox64;
1861da177e4SLinus Torvalds 	dma_addr_t			una_mbox64_dma;
1871da177e4SLinus Torvalds 	mbox_t				*mbox;
1881da177e4SLinus Torvalds 	mbox64_t			*mbox64;
1891da177e4SLinus Torvalds 	dma_addr_t			mbox_dma;
1901da177e4SLinus Torvalds 	spinlock_t			mailbox_lock;
1911da177e4SLinus Torvalds 	unsigned long			baseport;
1921da177e4SLinus Torvalds 	void __iomem *			baseaddr;
1931da177e4SLinus Torvalds 	struct mraid_pci_blk		mbox_pool[MBOX_MAX_SCSI_CMDS];
1941da177e4SLinus Torvalds 	struct dma_pool			*mbox_pool_handle;
1951da177e4SLinus Torvalds 	struct mraid_pci_blk		epthru_pool[MBOX_MAX_SCSI_CMDS];
1961da177e4SLinus Torvalds 	struct dma_pool			*epthru_pool_handle;
1971da177e4SLinus Torvalds 	struct mraid_pci_blk		sg_pool[MBOX_MAX_SCSI_CMDS];
1981da177e4SLinus Torvalds 	struct dma_pool			*sg_pool_handle;
1991da177e4SLinus Torvalds 	mbox_ccb_t			ccb_list[MBOX_MAX_SCSI_CMDS];
2001da177e4SLinus Torvalds 	mbox_ccb_t			uccb_list[MBOX_MAX_USER_CMDS];
2011da177e4SLinus Torvalds 	mbox64_t			umbox64[MBOX_MAX_USER_CMDS];
2021da177e4SLinus Torvalds 
2031da177e4SLinus Torvalds 	uint8_t				pdrv_state[MBOX_MAX_PHYSICAL_DRIVES];
2041da177e4SLinus Torvalds 	uint32_t			last_disp;
2051da177e4SLinus Torvalds 	int				hw_error;
2061da177e4SLinus Torvalds 	int				fast_load;
2071da177e4SLinus Torvalds 	uint8_t				channel_class;
2080c2cc433SMatthias Kaehlcke 	struct mutex			sysfs_mtx;
2091da177e4SLinus Torvalds 	uioc_t				*sysfs_uioc;
2101da177e4SLinus Torvalds 	mbox64_t			*sysfs_mbox64;
2111da177e4SLinus Torvalds 	caddr_t				sysfs_buffer;
2121da177e4SLinus Torvalds 	dma_addr_t			sysfs_buffer_dma;
2131da177e4SLinus Torvalds 	wait_queue_head_t		sysfs_wait_q;
2141da177e4SLinus Torvalds 	int				random_del_supported;
2151da177e4SLinus Torvalds 	uint16_t			curr_ldmap[MAX_LD_EXTENDED64];
2161da177e4SLinus Torvalds } mraid_device_t;
2171da177e4SLinus Torvalds 
2181da177e4SLinus Torvalds // route to raid device from adapter
2191da177e4SLinus Torvalds #define ADAP2RAIDDEV(adp)	((mraid_device_t *)((adp)->raid_device))
2201da177e4SLinus Torvalds 
2211da177e4SLinus Torvalds #define MAILBOX_LOCK(rdev)	(&(rdev)->mailbox_lock)
2221da177e4SLinus Torvalds 
2231da177e4SLinus Torvalds // Find out if this channel is a RAID or SCSI
2241da177e4SLinus Torvalds #define IS_RAID_CH(rdev, ch)	(((rdev)->channel_class >> (ch)) & 0x01)
2251da177e4SLinus Torvalds 
2261da177e4SLinus Torvalds 
2271da177e4SLinus Torvalds #define RDINDOOR(rdev)		readl((rdev)->baseaddr + 0x20)
2281da177e4SLinus Torvalds #define RDOUTDOOR(rdev)		readl((rdev)->baseaddr + 0x2C)
2291da177e4SLinus Torvalds #define WRINDOOR(rdev, value)	writel(value, (rdev)->baseaddr + 0x20)
2301da177e4SLinus Torvalds #define WROUTDOOR(rdev, value)	writel(value, (rdev)->baseaddr + 0x2C)
2311da177e4SLinus Torvalds 
2321da177e4SLinus Torvalds #endif // _MEGARAID_H_
233