^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Linux MegaRAID device driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (c) 2003-2004 LSI Logic Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * FILE : mega_common.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Libaray of common routine used by all low-level megaraid drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #ifndef _MEGA_COMMON_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define _MEGA_COMMON_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/dma-mapping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <scsi/scsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <scsi/scsi_cmnd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <scsi/scsi_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define LSI_MAX_CHANNELS 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define LSI_MAX_LOGICAL_DRIVES_64LD (64+1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define HBA_SIGNATURE_64_BIT 0x299
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define PCI_CONF_AMISIG64 0xa4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define MEGA_SCSI_INQ_EVPD 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define MEGA_INVALID_FIELD_IN_CDB 0x24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * scb_t - scsi command control block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * @ccb : command control block for individual driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * @list : list of control blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * @gp : general purpose field for LLDs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * @sno : all SCBs have a serial number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * @scp : associated scsi command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * @state : current state of scb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * @dma_dir : direction of data transfer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * @dma_type : transfer with sg list, buffer, or no data transfer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * @dev_channel : actual channel on the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * @dev_target : actual target on the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * @status : completion status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * This is our central data structure to issue commands the each driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * Driver specific data structures are maintained in the ccb field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * scb provides a field 'gp', which can be used by LLD for its own purposes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * dev_channel and dev_target must be initialized with the actual channel and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * target on the controller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) typedef struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) caddr_t ccb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) unsigned long gp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) unsigned int sno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct scsi_cmnd *scp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) uint32_t state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) uint32_t dma_direction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) uint32_t dma_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) uint16_t dev_channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) uint16_t dev_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) uint32_t status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) } scb_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * SCB states as it transitions from one state to another
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #define SCB_FREE 0x0000 /* on the free list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #define SCB_ACTIVE 0x0001 /* off the free list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #define SCB_PENDQ 0x0002 /* on the pending queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define SCB_ISSUED 0x0004 /* issued - owner f/w */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #define SCB_ABORT 0x0008 /* Got an abort for this one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #define SCB_RESET 0x0010 /* Got a reset for this one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * DMA types for scb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #define MRAID_DMA_NONE 0x0000 /* no data transfer for this command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #define MRAID_DMA_WSG 0x0001 /* data transfer using a sg list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #define MRAID_DMA_WBUF 0x0002 /* data transfer using a contiguous buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * struct adapter_t - driver's initialization structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * @aram dpc_h : tasklet handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * @pdev : pci configuration pointer for kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * @host : pointer to host structure of mid-layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * @lock : synchronization lock for mid-layer and driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * @quiescent : driver is quiescent for now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * @outstanding_cmds : number of commands pending in the driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * @kscb_list : pointer to the bulk of SCBs pointers for IO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * @kscb_pool : pool of free scbs for IO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * @kscb_pool_lock : lock for pool of free scbs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * @pend_list : pending commands list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * @pend_list_lock : exclusion lock for pending commands list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * @completed_list : list of completed commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * @completed_list_lock : exclusion lock for list of completed commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * @sglen : max sg elements supported
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * @device_ids : to convert kernel device addr to our devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * @raid_device : raid adapter specific pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * @max_channel : maximum channel number supported - inclusive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * @max_target : max target supported - inclusive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * @max_lun : max lun supported - inclusive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * @unique_id : unique identifier for each adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * @irq : IRQ for this adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * @ito : internal timeout value, (-1) means no timeout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * @ibuf : buffer to issue internal commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * @ibuf_dma_h : dma handle for the above buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * @uscb_list : SCB pointers for user cmds, common mgmt module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * @uscb_pool : pool of SCBs for user commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * @uscb_pool_lock : exclusion lock for these SCBs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * @max_cmds : max outstanding commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * @fw_version : firmware version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * @bios_version : bios version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * @max_cdb_sz : biggest CDB size supported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * @ha : is high availability present - clustering
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * @init_id : initiator ID, the default value should be 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * @max_sectors : max sectors per request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * @cmd_per_lun : max outstanding commands per LUN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * @being_detached : set when unloading, no more mgmt calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * mraid_setup_device_map() can be called anytime after the device map is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * available and MRAID_GET_DEVICE_MAP() can be called whenever the mapping is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * required, usually from LLD's queue entry point. The formar API sets up the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * MRAID_IS_LOGICAL(adapter_t *, struct scsi_cmnd *) to find out if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * device in question is a logical drive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * quiescent flag should be set by the driver if it is not accepting more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * NOTE: The fields of this structures are placed to minimize cache misses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) // amount of space required to store the bios and firmware version strings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #define VERSION_SIZE 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) typedef struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct tasklet_struct dpc_h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct pci_dev *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct Scsi_Host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) uint8_t quiescent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) int outstanding_cmds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) scb_t *kscb_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct list_head kscb_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) spinlock_t kscb_pool_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) struct list_head pend_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) spinlock_t pend_list_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct list_head completed_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) spinlock_t completed_list_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) uint16_t sglen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) int device_ids[LSI_MAX_CHANNELS]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) [LSI_MAX_LOGICAL_DRIVES_64LD];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) caddr_t raid_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) uint8_t max_channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) uint16_t max_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) uint8_t max_lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) uint32_t unique_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) uint8_t ito;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) caddr_t ibuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) dma_addr_t ibuf_dma_h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) scb_t *uscb_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct list_head uscb_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) spinlock_t uscb_pool_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) int max_cmds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) uint8_t fw_version[VERSION_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) uint8_t bios_version[VERSION_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) uint8_t max_cdb_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) uint8_t ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) uint16_t init_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) uint16_t max_sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) uint16_t cmd_per_lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) atomic_t being_detached;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) } adapter_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) #define SCSI_FREE_LIST_LOCK(adapter) (&adapter->kscb_pool_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) #define USER_FREE_LIST_LOCK(adapter) (&adapter->uscb_pool_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) #define PENDING_LIST_LOCK(adapter) (&adapter->pend_list_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) #define COMPLETED_LIST_LOCK(adapter) (&adapter->completed_list_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) // conversion from scsi command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) #define SCP2HOST(scp) (scp)->device->host // to host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) #define SCP2HOSTDATA(scp) SCP2HOST(scp)->hostdata // to soft state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) #define SCP2CHANNEL(scp) (scp)->device->channel // to channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) #define SCP2TARGET(scp) (scp)->device->id // to target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) #define SCP2LUN(scp) (u32)(scp)->device->lun // to LUN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) // generic macro to convert scsi command and host to controller's soft state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) #define SCSIHOST2ADAP(host) (((caddr_t *)(host->hostdata))[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) #define SCP2ADAPTER(scp) (adapter_t *)SCSIHOST2ADAP(SCP2HOST(scp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) #define MRAID_IS_LOGICAL(adp, scp) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) (SCP2CHANNEL(scp) == (adp)->max_channel) ? 1 : 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) #define MRAID_IS_LOGICAL_SDEV(adp, sdev) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) (sdev->channel == (adp)->max_channel) ? 1 : 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * MRAID_GET_DEVICE_MAP - device ids
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * @adp : adapter's soft state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * @scp : mid-layer scsi command pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * @p_chan : physical channel on the controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * @target : target id of the device or logical drive number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * @islogical : set if the command is for the logical drive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * Macro to retrieve information about device class, logical or physical and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * the corresponding physical channel and target or logical drive number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) #define MRAID_GET_DEVICE_MAP(adp, scp, p_chan, target, islogical) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /* \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * Is the request coming for the virtual channel \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) */ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) islogical = MRAID_IS_LOGICAL(adp, scp); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /* \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * Get an index into our table of drive ids mapping \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) */ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (islogical) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) p_chan = 0xFF; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) target = \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) (adp)->device_ids[(adp)->max_channel][SCP2TARGET(scp)]; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) else { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) p_chan = ((adp)->device_ids[SCP2CHANNEL(scp)] \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) [SCP2TARGET(scp)] >> 8) & 0xFF; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) target = ((adp)->device_ids[SCP2CHANNEL(scp)] \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) [SCP2TARGET(scp)] & 0xFF); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * ### Helper routines ###
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) #define LSI_DBGLVL mraid_debug_level // each LLD must define a global
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) // mraid_debug_level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) #if defined (_ASSERT_PANIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) #define ASSERT_ACTION panic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) #define ASSERT_ACTION printk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) #define ASSERT(expression) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (!(expression)) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) ASSERT_ACTION("assertion failed:(%s), file: %s, line: %d:%s\n", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) #expression, __FILE__, __LINE__, __func__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) #define ASSERT(expression)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * struct mraid_pci_blk - structure holds DMA memory block info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) * @vaddr : virtual address to a memory block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) * @dma_addr : DMA handle to a memory block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * This structure is filled up for the caller. It is the responsibilty of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) * caller to allocate this array big enough to store addresses for all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * requested elements
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) struct mraid_pci_blk {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) caddr_t vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) dma_addr_t dma_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) #endif // _MEGA_COMMON_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) // vim: set ts=8 sw=8 tw=78: