/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * * Linux MegaRAID device driver * * Copyright (c) 2003-2004 LSI Logic Corporation. * * FILE : mega_common.h * * Libaray of common routine used by all low-level megaraid drivers */ #ifndef _MEGA_COMMON_H_ #define _MEGA_COMMON_H_ #include <linux/kernel.h> #include <linux/types.h> #include <linux/pci.h> #include <linux/spinlock.h> #include <linux/mutex.h> #include <linux/interrupt.h> #include <linux/delay.h> #include <linux/blkdev.h> #include <linux/list.h> #include <linux/moduleparam.h> #include <linux/dma-mapping.h> #include <scsi/scsi.h> #include <scsi/scsi_cmnd.h> #include <scsi/scsi_device.h> #include <scsi/scsi_host.h> #define LSI_MAX_CHANNELS … #define LSI_MAX_LOGICAL_DRIVES_64LD … #define HBA_SIGNATURE_64_BIT … #define PCI_CONF_AMISIG64 … #define MEGA_SCSI_INQ_EVPD … #define MEGA_INVALID_FIELD_IN_CDB … /** * scb_t - scsi command control block * @ccb : command control block for individual driver * @list : list of control blocks * @gp : general purpose field for LLDs * @sno : all SCBs have a serial number * @scp : associated scsi command * @state : current state of scb * @dma_dir : direction of data transfer * @dma_type : transfer with sg list, buffer, or no data transfer * @dev_channel : actual channel on the device * @dev_target : actual target on the device * @status : completion status * * This is our central data structure to issue commands the each driver. * Driver specific data structures are maintained in the ccb field. * scb provides a field 'gp', which can be used by LLD for its own purposes * * dev_channel and dev_target must be initialized with the actual channel and * target on the controller. */ scb_t; /* * SCB states as it transitions from one state to another */ #define SCB_FREE … #define SCB_ACTIVE … #define SCB_PENDQ … #define SCB_ISSUED … #define SCB_ABORT … #define SCB_RESET … /* * DMA types for scb */ #define MRAID_DMA_NONE … #define MRAID_DMA_WSG … #define MRAID_DMA_WBUF … /** * struct adapter_t - driver's initialization structure * @aram dpc_h : tasklet handle * @pdev : pci configuration pointer for kernel * @host : pointer to host structure of mid-layer * @lock : synchronization lock for mid-layer and driver * @quiescent : driver is quiescent for now. * @outstanding_cmds : number of commands pending in the driver * @kscb_list : pointer to the bulk of SCBs pointers for IO * @kscb_pool : pool of free scbs for IO * @kscb_pool_lock : lock for pool of free scbs * @pend_list : pending commands list * @pend_list_lock : exclusion lock for pending commands list * @completed_list : list of completed commands * @completed_list_lock : exclusion lock for list of completed commands * @sglen : max sg elements supported * @device_ids : to convert kernel device addr to our devices. * @raid_device : raid adapter specific pointer * @max_channel : maximum channel number supported - inclusive * @max_target : max target supported - inclusive * @max_lun : max lun supported - inclusive * @unique_id : unique identifier for each adapter * @irq : IRQ for this adapter * @ito : internal timeout value, (-1) means no timeout * @ibuf : buffer to issue internal commands * @ibuf_dma_h : dma handle for the above buffer * @uscb_list : SCB pointers for user cmds, common mgmt module * @uscb_pool : pool of SCBs for user commands * @uscb_pool_lock : exclusion lock for these SCBs * @max_cmds : max outstanding commands * @fw_version : firmware version * @bios_version : bios version * @max_cdb_sz : biggest CDB size supported. * @ha : is high availability present - clustering * @init_id : initiator ID, the default value should be 7 * @max_sectors : max sectors per request * @cmd_per_lun : max outstanding commands per LUN * @being_detached : set when unloading, no more mgmt calls * * * mraid_setup_device_map() can be called anytime after the device map is * available and MRAID_GET_DEVICE_MAP() can be called whenever the mapping is * required, usually from LLD's queue entry point. The formar API sets up the * MRAID_IS_LOGICAL(adapter_t *, struct scsi_cmnd *) to find out if the * device in question is a logical drive. * * quiescent flag should be set by the driver if it is not accepting more * commands * * NOTE: The fields of this structures are placed to minimize cache misses */ // amount of space required to store the bios and firmware version strings #define VERSION_SIZE … adapter_t; #define SCSI_FREE_LIST_LOCK(adapter) … #define USER_FREE_LIST_LOCK(adapter) … #define PENDING_LIST_LOCK(adapter) … #define COMPLETED_LIST_LOCK(adapter) … // conversion from scsi command #define SCP2HOST(scp) … #define SCP2HOSTDATA(scp) … #define SCP2CHANNEL(scp) … #define SCP2TARGET(scp) … #define SCP2LUN(scp) … // generic macro to convert scsi command and host to controller's soft state #define SCSIHOST2ADAP(host) … #define SCP2ADAPTER(scp) … #define MRAID_IS_LOGICAL(adp, scp) … #define MRAID_IS_LOGICAL_SDEV(adp, sdev) … /** * MRAID_GET_DEVICE_MAP - device ids * @adp : adapter's soft state * @scp : mid-layer scsi command pointer * @p_chan : physical channel on the controller * @target : target id of the device or logical drive number * @islogical : set if the command is for the logical drive * * Macro to retrieve information about device class, logical or physical and * the corresponding physical channel and target or logical drive number */ #define MRAID_GET_DEVICE_MAP(adp, scp, p_chan, target, islogical) … /* * ### Helper routines ### */ #define LSI_DBGLVL … // mraid_debug_level #ifdef DEBUG #if defined (_ASSERT_PANIC) #define ASSERT_ACTION … #else #define ASSERT_ACTION … #endif #define ASSERT … #else #define ASSERT(expression) … #endif /** * struct mraid_pci_blk - structure holds DMA memory block info * @vaddr : virtual address to a memory block * @dma_addr : DMA handle to a memory block * * This structure is filled up for the caller. It is the responsibilty of the * caller to allocate this array big enough to store addresses for all * requested elements */ struct mraid_pci_blk { … }; #endif // _MEGA_COMMON_H_