Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mega_common.h
Go to the documentation of this file.
1 /*
2  *
3  * Linux MegaRAID device driver
4  *
5  * Copyright (c) 2003-2004 LSI Logic Corporation.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version
10  * 2 of the License, or (at your option) any later version.
11  *
12  * FILE : mega_common.h
13  *
14  * Libaray of common routine used by all low-level megaraid drivers
15  */
16 
17 #ifndef _MEGA_COMMON_H_
18 #define _MEGA_COMMON_H_
19 
20 #include <linux/kernel.h>
21 #include <linux/types.h>
22 #include <linux/pci.h>
23 #include <linux/spinlock.h>
24 #include <linux/mutex.h>
25 #include <linux/interrupt.h>
26 #include <linux/delay.h>
27 #include <linux/blkdev.h>
28 #include <linux/list.h>
29 #include <linux/moduleparam.h>
30 #include <linux/dma-mapping.h>
31 #include <scsi/scsi.h>
32 #include <scsi/scsi_cmnd.h>
33 #include <scsi/scsi_device.h>
34 #include <scsi/scsi_host.h>
35 
36 
37 #define LSI_MAX_CHANNELS 16
38 #define LSI_MAX_LOGICAL_DRIVES_64LD (64+1)
39 
40 #define HBA_SIGNATURE_64_BIT 0x299
41 #define PCI_CONF_AMISIG64 0xa4
42 
43 #define MEGA_SCSI_INQ_EVPD 1
44 #define MEGA_INVALID_FIELD_IN_CDB 0x24
45 
46 
68 typedef struct {
70  struct list_head list;
71  unsigned long gp;
72  unsigned int sno;
73  struct scsi_cmnd *scp;
80 } scb_t;
81 
82 /*
83  * SCB states as it transitions from one state to another
84  */
85 #define SCB_FREE 0x0000 /* on the free list */
86 #define SCB_ACTIVE 0x0001 /* off the free list */
87 #define SCB_PENDQ 0x0002 /* on the pending queue */
88 #define SCB_ISSUED 0x0004 /* issued - owner f/w */
89 #define SCB_ABORT 0x0008 /* Got an abort for this one */
90 #define SCB_RESET 0x0010 /* Got a reset for this one */
91 
92 /*
93  * DMA types for scb
94  */
95 #define MRAID_DMA_NONE 0x0000 /* no data transfer for this command */
96 #define MRAID_DMA_WSG 0x0001 /* data transfer using a sg list */
97 #define MRAID_DMA_WBUF 0x0002 /* data transfer using a contiguous buffer */
98 
99 
152 // amount of space required to store the bios and firmware version strings
153 #define VERSION_SIZE 16
154 
155 typedef struct {
156  struct tasklet_struct dpc_h;
157  struct pci_dev *pdev;
158  struct Scsi_Host *host;
163  struct list_head kscb_pool;
165  struct list_head pend_list;
167  struct list_head completed_list;
170  int device_ids[LSI_MAX_CHANNELS]
176 
178  int irq;
183  struct list_head uscb_pool;
185  int max_cmds;
187  uint8_t bios_version[VERSION_SIZE];
194 } adapter_t;
195 
196 #define SCSI_FREE_LIST_LOCK(adapter) (&adapter->kscb_pool_lock)
197 #define USER_FREE_LIST_LOCK(adapter) (&adapter->uscb_pool_lock)
198 #define PENDING_LIST_LOCK(adapter) (&adapter->pend_list_lock)
199 #define COMPLETED_LIST_LOCK(adapter) (&adapter->completed_list_lock)
200 
201 
202 // conversion from scsi command
203 #define SCP2HOST(scp) (scp)->device->host // to host
204 #define SCP2HOSTDATA(scp) SCP2HOST(scp)->hostdata // to soft state
205 #define SCP2CHANNEL(scp) (scp)->device->channel // to channel
206 #define SCP2TARGET(scp) (scp)->device->id // to target
207 #define SCP2LUN(scp) (scp)->device->lun // to LUN
208 
209 // generic macro to convert scsi command and host to controller's soft state
210 #define SCSIHOST2ADAP(host) (((caddr_t *)(host->hostdata))[0])
211 #define SCP2ADAPTER(scp) (adapter_t *)SCSIHOST2ADAP(SCP2HOST(scp))
212 
213 
214 #define MRAID_IS_LOGICAL(adp, scp) \
215  (SCP2CHANNEL(scp) == (adp)->max_channel) ? 1 : 0
216 
217 #define MRAID_IS_LOGICAL_SDEV(adp, sdev) \
218  (sdev->channel == (adp)->max_channel) ? 1 : 0
219 
231 #define MRAID_GET_DEVICE_MAP(adp, scp, p_chan, target, islogical) \
232  /* \
233  * Is the request coming for the virtual channel \
234  */ \
235  islogical = MRAID_IS_LOGICAL(adp, scp); \
236  \
237  /* \
238  * Get an index into our table of drive ids mapping \
239  */ \
240  if (islogical) { \
241  p_chan = 0xFF; \
242  target = \
243  (adp)->device_ids[(adp)->max_channel][SCP2TARGET(scp)]; \
244  } \
245  else { \
246  p_chan = ((adp)->device_ids[SCP2CHANNEL(scp)] \
247  [SCP2TARGET(scp)] >> 8) & 0xFF; \
248  target = ((adp)->device_ids[SCP2CHANNEL(scp)] \
249  [SCP2TARGET(scp)] & 0xFF); \
250  }
252 /*
253  * ### Helper routines ###
254  */
255 #define LSI_DBGLVL mraid_debug_level // each LLD must define a global
256  // mraid_debug_level
257 
258 #ifdef DEBUG
259 #if defined (_ASSERT_PANIC)
260 #define ASSERT_ACTION panic
261 #else
262 #define ASSERT_ACTION printk
263 #endif
264 
265 #define ASSERT(expression) \
266  if (!(expression)) { \
267  ASSERT_ACTION("assertion failed:(%s), file: %s, line: %d:%s\n", \
268  #expression, __FILE__, __LINE__, __func__); \
269  }
270 #else
271 #define ASSERT(expression)
272 #endif
273 
283 struct mraid_pci_blk {
284  caddr_t vaddr;
286 };
287 
288 #endif // _MEGA_COMMON_H_
289 
290 // vim: set ts=8 sw=8 tw=78: