blob: c0861c05cd4913022c9f2bc4e47061f313a894df [file] [log] [blame]
Erich Chen1c57e862006-07-12 08:59:32 -07001/*
2*******************************************************************************
3** O.S : Linux
4** FILE NAME : arcmsr.h
5** BY : Erich Chen
6** Description: SCSI RAID Device Driver for
7** ARECA RAID Host adapter
8*******************************************************************************
9** Copyright (C) 2002 - 2005, Areca Technology Corporation All rights reserved.
10**
11** Web site: www.areca.com.tw
Nick Cheng1a4f5502007-09-13 17:26:40 +080012** E-mail: support@areca.com.tw
Erich Chen1c57e862006-07-12 08:59:32 -070013**
14** This program is free software; you can redistribute it and/or modify
15** it under the terms of the GNU General Public License version 2 as
16** published by the Free Software Foundation.
17** This program is distributed in the hope that it will be useful,
18** but WITHOUT ANY WARRANTY; without even the implied warranty of
19** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20** GNU General Public License for more details.
21*******************************************************************************
22** Redistribution and use in source and binary forms, with or without
23** modification, are permitted provided that the following conditions
24** are met:
25** 1. Redistributions of source code must retain the above copyright
26** notice, this list of conditions and the following disclaimer.
27** 2. Redistributions in binary form must reproduce the above copyright
28** notice, this list of conditions and the following disclaimer in the
29** documentation and/or other materials provided with the distribution.
30** 3. The name of the author may not be used to endorse or promote products
31** derived from this software without specific prior written permission.
32**
33** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
34** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
35** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
36** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
37** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT
38** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
39** DATA, OR PROFITS; OR BUSINESS INTERRUPTION)HOWEVER CAUSED AND ON ANY
40** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
41**(INCLUDING NEGLIGENCE OR OTHERWISE)ARISING IN ANY WAY OUT OF THE USE OF
42** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43*******************************************************************************
44*/
45#include <linux/interrupt.h>
46
Tony Jonesee959b02008-02-22 00:13:36 +010047struct device_attribute;
Nick Cheng1a4f5502007-09-13 17:26:40 +080048/*The limit of outstanding scsi command that firmware can handle*/
49#define ARCMSR_MAX_OUTSTANDING_CMD 256
50#define ARCMSR_MAX_FREECCB_NUM 320
Nick Chengae52e7f2010-06-18 15:39:12 +080051#define ARCMSR_DRIVER_VERSION "Driver Version 1.20.00.15 2009/12/09"
Erich Chen1c57e862006-07-12 08:59:32 -070052#define ARCMSR_SCSI_INITIATOR_ID 255
53#define ARCMSR_MAX_XFER_SECTORS 512
Nick Cheng1a4f5502007-09-13 17:26:40 +080054#define ARCMSR_MAX_XFER_SECTORS_B 4096
Nick Chengae52e7f2010-06-18 15:39:12 +080055#define ARCMSR_MAX_XFER_SECTORS_C 304
Nick Cheng1a4f5502007-09-13 17:26:40 +080056#define ARCMSR_MAX_TARGETID 17
57#define ARCMSR_MAX_TARGETLUN 8
58#define ARCMSR_MAX_CMD_PERLUN ARCMSR_MAX_OUTSTANDING_CMD
59#define ARCMSR_MAX_QBUFFER 4096
Nick Chengae52e7f2010-06-18 15:39:12 +080060#define ARCMSR_DEFAULT_SG_ENTRIES 38
Nick Cheng1a4f5502007-09-13 17:26:40 +080061#define ARCMSR_MAX_HBB_POSTQUEUE 264
Nick Chengae52e7f2010-06-18 15:39:12 +080062#define ARCMSR_MAX_XFER_LEN 0x26000 /* 152K */
63#define ARCMSR_CDB_SG_PAGE_LENGTH 256
64#ifndef PCI_DEVICE_ID_ARECA_1880
65#define PCI_DEVICE_ID_ARECA_1880 0x1880
66 #endif
Nick Cheng1a4f5502007-09-13 17:26:40 +080067/*
68**********************************************************************************
69**
70**********************************************************************************
71*/
72#define ARC_SUCCESS 0
73#define ARC_FAILURE 1
Erich Chen1c57e862006-07-12 08:59:32 -070074/*
75*******************************************************************************
76** split 64bits dma addressing
77*******************************************************************************
78*/
79#define dma_addr_hi32(addr) (uint32_t) ((addr>>16)>>16)
80#define dma_addr_lo32(addr) (uint32_t) (addr & 0xffffffff)
81/*
82*******************************************************************************
83** MESSAGE CONTROL CODE
84*******************************************************************************
85*/
86struct CMD_MESSAGE
87{
88 uint32_t HeaderLength;
89 uint8_t Signature[8];
90 uint32_t Timeout;
91 uint32_t ControlCode;
92 uint32_t ReturnCode;
93 uint32_t Length;
94};
95/*
96*******************************************************************************
97** IOP Message Transfer Data for user space
98*******************************************************************************
99*/
100struct CMD_MESSAGE_FIELD
101{
102 struct CMD_MESSAGE cmdmessage;
103 uint8_t messagedatabuffer[1032];
104};
105/* IOP message transfer */
Nick Cheng1a4f5502007-09-13 17:26:40 +0800106#define ARCMSR_MESSAGE_FAIL 0x0001
Erich Chen1c57e862006-07-12 08:59:32 -0700107/* DeviceType */
108#define ARECA_SATA_RAID 0x90000000
109/* FunctionCode */
110#define FUNCTION_READ_RQBUFFER 0x0801
111#define FUNCTION_WRITE_WQBUFFER 0x0802
112#define FUNCTION_CLEAR_RQBUFFER 0x0803
113#define FUNCTION_CLEAR_WQBUFFER 0x0804
114#define FUNCTION_CLEAR_ALLQBUFFER 0x0805
115#define FUNCTION_RETURN_CODE_3F 0x0806
116#define FUNCTION_SAY_HELLO 0x0807
117#define FUNCTION_SAY_GOODBYE 0x0808
118#define FUNCTION_FLUSH_ADAPTER_CACHE 0x0809
Nick Cheng36b83de2010-05-17 11:22:42 +0800119#define FUNCTION_GET_FIRMWARE_STATUS 0x080A
120#define FUNCTION_HARDWARE_RESET 0x080B
Erich Chen1c57e862006-07-12 08:59:32 -0700121/* ARECA IO CONTROL CODE*/
122#define ARCMSR_MESSAGE_READ_RQBUFFER \
123 ARECA_SATA_RAID | FUNCTION_READ_RQBUFFER
124#define ARCMSR_MESSAGE_WRITE_WQBUFFER \
125 ARECA_SATA_RAID | FUNCTION_WRITE_WQBUFFER
126#define ARCMSR_MESSAGE_CLEAR_RQBUFFER \
127 ARECA_SATA_RAID | FUNCTION_CLEAR_RQBUFFER
128#define ARCMSR_MESSAGE_CLEAR_WQBUFFER \
129 ARECA_SATA_RAID | FUNCTION_CLEAR_WQBUFFER
130#define ARCMSR_MESSAGE_CLEAR_ALLQBUFFER \
131 ARECA_SATA_RAID | FUNCTION_CLEAR_ALLQBUFFER
132#define ARCMSR_MESSAGE_RETURN_CODE_3F \
133 ARECA_SATA_RAID | FUNCTION_RETURN_CODE_3F
134#define ARCMSR_MESSAGE_SAY_HELLO \
135 ARECA_SATA_RAID | FUNCTION_SAY_HELLO
136#define ARCMSR_MESSAGE_SAY_GOODBYE \
137 ARECA_SATA_RAID | FUNCTION_SAY_GOODBYE
138#define ARCMSR_MESSAGE_FLUSH_ADAPTER_CACHE \
139 ARECA_SATA_RAID | FUNCTION_FLUSH_ADAPTER_CACHE
140/* ARECA IOCTL ReturnCode */
141#define ARCMSR_MESSAGE_RETURNCODE_OK 0x00000001
142#define ARCMSR_MESSAGE_RETURNCODE_ERROR 0x00000006
143#define ARCMSR_MESSAGE_RETURNCODE_3F 0x0000003F
Nick Cheng36b83de2010-05-17 11:22:42 +0800144#define ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON 0x00000088
Erich Chen1c57e862006-07-12 08:59:32 -0700145/*
146*************************************************************
147** structure for holding DMA address data
148*************************************************************
149*/
Nick Chengae52e7f2010-06-18 15:39:12 +0800150#define IS_DMA64 (sizeof(dma_addr_t) == 8)
Erich Chen1c57e862006-07-12 08:59:32 -0700151#define IS_SG64_ADDR 0x01000000 /* bit24 */
152struct SG32ENTRY
153{
Al Viro80da1ad2007-10-29 05:08:28 +0000154 __le32 length;
155 __le32 address;
Nick Chengae52e7f2010-06-18 15:39:12 +0800156} __attribute__ ((packed));
Erich Chen1c57e862006-07-12 08:59:32 -0700157struct SG64ENTRY
158{
Al Viro80da1ad2007-10-29 05:08:28 +0000159 __le32 length;
160 __le32 address;
161 __le32 addresshigh;
Nick Chengae52e7f2010-06-18 15:39:12 +0800162} __attribute__ ((packed));
Erich Chen1c57e862006-07-12 08:59:32 -0700163/*
164********************************************************************
165** Q Buffer of IOP Message Transfer
166********************************************************************
167*/
168struct QBUFFER
169{
170 uint32_t data_len;
171 uint8_t data[124];
172};
173/*
174*******************************************************************************
Nick Cheng1a4f5502007-09-13 17:26:40 +0800175** FIRMWARE INFO for Intel IOP R 80331 processor (Type A)
Erich Chen1c57e862006-07-12 08:59:32 -0700176*******************************************************************************
177*/
178struct FIRMWARE_INFO
179{
Nick Cheng1a4f5502007-09-13 17:26:40 +0800180 uint32_t signature; /*0, 00-03*/
181 uint32_t request_len; /*1, 04-07*/
182 uint32_t numbers_queue; /*2, 08-11*/
Erich Chen1c57e862006-07-12 08:59:32 -0700183 uint32_t sdram_size; /*3, 12-15*/
Nick Cheng1a4f5502007-09-13 17:26:40 +0800184 uint32_t ide_channels; /*4, 16-19*/
185 char vendor[40]; /*5, 20-59*/
186 char model[8]; /*15, 60-67*/
187 char firmware_ver[16]; /*17, 68-83*/
188 char device_map[16]; /*21, 84-99*/
Nick Chengae52e7f2010-06-18 15:39:12 +0800189 uint32_t cfgVersion; /*25,100-103 Added for checking of new firmware capability*/
190 uint8_t cfgSerial[16]; /*26,104-119*/
191 uint32_t cfgPicStatus; /*30,120-123*/
Erich Chen1c57e862006-07-12 08:59:32 -0700192};
193/* signature of set and get firmware config */
Nick Cheng1a4f5502007-09-13 17:26:40 +0800194#define ARCMSR_SIGNATURE_GET_CONFIG 0x87974060
195#define ARCMSR_SIGNATURE_SET_CONFIG 0x87974063
Erich Chen1c57e862006-07-12 08:59:32 -0700196/* message code of inbound message register */
Nick Cheng1a4f5502007-09-13 17:26:40 +0800197#define ARCMSR_INBOUND_MESG0_NOP 0x00000000
198#define ARCMSR_INBOUND_MESG0_GET_CONFIG 0x00000001
Erich Chen1c57e862006-07-12 08:59:32 -0700199#define ARCMSR_INBOUND_MESG0_SET_CONFIG 0x00000002
200#define ARCMSR_INBOUND_MESG0_ABORT_CMD 0x00000003
201#define ARCMSR_INBOUND_MESG0_STOP_BGRB 0x00000004
202#define ARCMSR_INBOUND_MESG0_FLUSH_CACHE 0x00000005
203#define ARCMSR_INBOUND_MESG0_START_BGRB 0x00000006
204#define ARCMSR_INBOUND_MESG0_CHK331PENDING 0x00000007
205#define ARCMSR_INBOUND_MESG0_SYNC_TIMER 0x00000008
206/* doorbell interrupt generator */
207#define ARCMSR_INBOUND_DRIVER_DATA_WRITE_OK 0x00000001
208#define ARCMSR_INBOUND_DRIVER_DATA_READ_OK 0x00000002
209#define ARCMSR_OUTBOUND_IOP331_DATA_WRITE_OK 0x00000001
210#define ARCMSR_OUTBOUND_IOP331_DATA_READ_OK 0x00000002
211/* ccb areca cdb flag */
212#define ARCMSR_CCBPOST_FLAG_SGL_BSIZE 0x80000000
213#define ARCMSR_CCBPOST_FLAG_IAM_BIOS 0x40000000
214#define ARCMSR_CCBREPLY_FLAG_IAM_BIOS 0x40000000
215#define ARCMSR_CCBREPLY_FLAG_ERROR 0x10000000
216/* outbound firmware ok */
217#define ARCMSR_OUTBOUND_MESG1_FIRMWARE_OK 0x80000000
Nick Chengae52e7f2010-06-18 15:39:12 +0800218/* ARC-1680 Bus Reset*/
219#define ARCMSR_ARC1680_BUS_RESET 0x00000003
Nick Cheng1a4f5502007-09-13 17:26:40 +0800220
221/*
222************************************************************************
223** SPEC. for Areca Type B adapter
224************************************************************************
225*/
226/* ARECA HBB COMMAND for its FIRMWARE */
227/* window of "instruction flags" from driver to iop */
228#define ARCMSR_DRV2IOP_DOORBELL 0x00020400
229#define ARCMSR_DRV2IOP_DOORBELL_MASK 0x00020404
230/* window of "instruction flags" from iop to driver */
231#define ARCMSR_IOP2DRV_DOORBELL 0x00020408
232#define ARCMSR_IOP2DRV_DOORBELL_MASK 0x0002040C
233/* ARECA FLAG LANGUAGE */
234/* ioctl transfer */
235#define ARCMSR_IOP2DRV_DATA_WRITE_OK 0x00000001
236/* ioctl transfer */
237#define ARCMSR_IOP2DRV_DATA_READ_OK 0x00000002
238#define ARCMSR_IOP2DRV_CDB_DONE 0x00000004
239#define ARCMSR_IOP2DRV_MESSAGE_CMD_DONE 0x00000008
240
241#define ARCMSR_DOORBELL_HANDLE_INT 0x0000000F
242#define ARCMSR_DOORBELL_INT_CLEAR_PATTERN 0xFF00FFF0
243#define ARCMSR_MESSAGE_INT_CLEAR_PATTERN 0xFF00FFF7
244/* (ARCMSR_INBOUND_MESG0_GET_CONFIG<<16)|ARCMSR_DRV2IOP_MESSAGE_CMD_POSTED) */
245#define ARCMSR_MESSAGE_GET_CONFIG 0x00010008
246/* (ARCMSR_INBOUND_MESG0_SET_CONFIG<<16)|ARCMSR_DRV2IOP_MESSAGE_CMD_POSTED) */
247#define ARCMSR_MESSAGE_SET_CONFIG 0x00020008
248/* (ARCMSR_INBOUND_MESG0_ABORT_CMD<<16)|ARCMSR_DRV2IOP_MESSAGE_CMD_POSTED) */
249#define ARCMSR_MESSAGE_ABORT_CMD 0x00030008
250/* (ARCMSR_INBOUND_MESG0_STOP_BGRB<<16)|ARCMSR_DRV2IOP_MESSAGE_CMD_POSTED) */
251#define ARCMSR_MESSAGE_STOP_BGRB 0x00040008
252/* (ARCMSR_INBOUND_MESG0_FLUSH_CACHE<<16)|ARCMSR_DRV2IOP_MESSAGE_CMD_POSTED) */
253#define ARCMSR_MESSAGE_FLUSH_CACHE 0x00050008
254/* (ARCMSR_INBOUND_MESG0_START_BGRB<<16)|ARCMSR_DRV2IOP_MESSAGE_CMD_POSTED) */
255#define ARCMSR_MESSAGE_START_BGRB 0x00060008
256#define ARCMSR_MESSAGE_START_DRIVER_MODE 0x000E0008
257#define ARCMSR_MESSAGE_SET_POST_WINDOW 0x000F0008
Nick Cheng76d78302008-02-04 23:53:24 -0800258#define ARCMSR_MESSAGE_ACTIVE_EOI_MODE 0x00100008
Nick Cheng1a4f5502007-09-13 17:26:40 +0800259/* ARCMSR_OUTBOUND_MESG1_FIRMWARE_OK */
260#define ARCMSR_MESSAGE_FIRMWARE_OK 0x80000000
261/* ioctl transfer */
262#define ARCMSR_DRV2IOP_DATA_WRITE_OK 0x00000001
263/* ioctl transfer */
264#define ARCMSR_DRV2IOP_DATA_READ_OK 0x00000002
265#define ARCMSR_DRV2IOP_CDB_POSTED 0x00000004
266#define ARCMSR_DRV2IOP_MESSAGE_CMD_POSTED 0x00000008
Nick Cheng76d78302008-02-04 23:53:24 -0800267#define ARCMSR_DRV2IOP_END_OF_INTERRUPT 0x00000010
Nick Cheng1a4f5502007-09-13 17:26:40 +0800268
269/* data tunnel buffer between user space program and its firmware */
270/* user space data to iop 128bytes */
Nick Chengae52e7f2010-06-18 15:39:12 +0800271#define ARCMSR_MESSAGE_WBUFFER 0x0000fe00
Nick Cheng1a4f5502007-09-13 17:26:40 +0800272/* iop data to user space 128bytes */
Nick Chengae52e7f2010-06-18 15:39:12 +0800273#define ARCMSR_MESSAGE_RBUFFER 0x0000ff00
Nick Cheng1a4f5502007-09-13 17:26:40 +0800274/* iop message_rwbuffer for message command */
Nick Chengae52e7f2010-06-18 15:39:12 +0800275#define ARCMSR_MESSAGE_RWBUFFER 0x0000fa00
Erich Chen1c57e862006-07-12 08:59:32 -0700276/*
277*******************************************************************************
278** ARECA SCSI COMMAND DESCRIPTOR BLOCK size 0x1F8 (504)
279*******************************************************************************
280*/
281struct ARCMSR_CDB
282{
283 uint8_t Bus;
284 uint8_t TargetID;
285 uint8_t LUN;
286 uint8_t Function;
Erich Chen1c57e862006-07-12 08:59:32 -0700287 uint8_t CdbLength;
288 uint8_t sgcount;
289 uint8_t Flags;
290#define ARCMSR_CDB_FLAG_SGL_BSIZE 0x01
291#define ARCMSR_CDB_FLAG_BIOS 0x02
292#define ARCMSR_CDB_FLAG_WRITE 0x04
293#define ARCMSR_CDB_FLAG_SIMPLEQ 0x00
294#define ARCMSR_CDB_FLAG_HEADQ 0x08
295#define ARCMSR_CDB_FLAG_ORDEREDQ 0x10
Erich Chen1c57e862006-07-12 08:59:32 -0700296
Nick Chengae52e7f2010-06-18 15:39:12 +0800297 uint8_t msgPages;
Erich Chen1c57e862006-07-12 08:59:32 -0700298 uint32_t Context;
299 uint32_t DataLength;
Erich Chen1c57e862006-07-12 08:59:32 -0700300 uint8_t Cdb[16];
Erich Chen1c57e862006-07-12 08:59:32 -0700301 uint8_t DeviceStatus;
Nick Cheng1a4f5502007-09-13 17:26:40 +0800302#define ARCMSR_DEV_CHECK_CONDITION 0x02
303#define ARCMSR_DEV_SELECT_TIMEOUT 0xF0
304#define ARCMSR_DEV_ABORTED 0xF1
305#define ARCMSR_DEV_INIT_FAIL 0xF2
Erich Chen1c57e862006-07-12 08:59:32 -0700306
Nick Cheng1a4f5502007-09-13 17:26:40 +0800307 uint8_t SenseData[15];
Erich Chen1c57e862006-07-12 08:59:32 -0700308 union
309 {
Nick Chengae52e7f2010-06-18 15:39:12 +0800310 struct SG32ENTRY sg32entry[1];
311 struct SG64ENTRY sg64entry[1];
Erich Chen1c57e862006-07-12 08:59:32 -0700312 } u;
Nick Chengae52e7f2010-06-18 15:39:12 +0800313} __attribute__ ((packed));
Erich Chen1c57e862006-07-12 08:59:32 -0700314/*
315*******************************************************************************
Nick Cheng1a4f5502007-09-13 17:26:40 +0800316** Messaging Unit (MU) of the Intel R 80331 I/O processor(Type A) and Type B processor
Erich Chen1c57e862006-07-12 08:59:32 -0700317*******************************************************************************
318*/
Nick Cheng1a4f5502007-09-13 17:26:40 +0800319struct MessageUnit_A
Erich Chen1c57e862006-07-12 08:59:32 -0700320{
321 uint32_t resrved0[4]; /*0000 000F*/
322 uint32_t inbound_msgaddr0; /*0010 0013*/
323 uint32_t inbound_msgaddr1; /*0014 0017*/
324 uint32_t outbound_msgaddr0; /*0018 001B*/
325 uint32_t outbound_msgaddr1; /*001C 001F*/
326 uint32_t inbound_doorbell; /*0020 0023*/
327 uint32_t inbound_intstatus; /*0024 0027*/
328 uint32_t inbound_intmask; /*0028 002B*/
329 uint32_t outbound_doorbell; /*002C 002F*/
330 uint32_t outbound_intstatus; /*0030 0033*/
331 uint32_t outbound_intmask; /*0034 0037*/
332 uint32_t reserved1[2]; /*0038 003F*/
333 uint32_t inbound_queueport; /*0040 0043*/
334 uint32_t outbound_queueport; /*0044 0047*/
335 uint32_t reserved2[2]; /*0048 004F*/
336 uint32_t reserved3[492]; /*0050 07FF 492*/
337 uint32_t reserved4[128]; /*0800 09FF 128*/
338 uint32_t message_rwbuffer[256]; /*0a00 0DFF 256*/
339 uint32_t message_wbuffer[32]; /*0E00 0E7F 32*/
340 uint32_t reserved5[32]; /*0E80 0EFF 32*/
341 uint32_t message_rbuffer[32]; /*0F00 0F7F 32*/
342 uint32_t reserved6[32]; /*0F80 0FFF 32*/
343};
Nick Cheng1a4f5502007-09-13 17:26:40 +0800344
345struct MessageUnit_B
346{
347 uint32_t post_qbuffer[ARCMSR_MAX_HBB_POSTQUEUE];
348 uint32_t done_qbuffer[ARCMSR_MAX_HBB_POSTQUEUE];
349 uint32_t postq_index;
350 uint32_t doneq_index;
Nick Chengae52e7f2010-06-18 15:39:12 +0800351 uint32_t __iomem *drv2iop_doorbell;
352 uint32_t __iomem *drv2iop_doorbell_mask;
353 uint32_t __iomem *iop2drv_doorbell;
354 uint32_t __iomem *iop2drv_doorbell_mask;
355 uint32_t __iomem *message_rwbuffer;
356 uint32_t __iomem *message_wbuffer;
357 uint32_t __iomem *message_rbuffer;
Nick Cheng1a4f5502007-09-13 17:26:40 +0800358};
359
Erich Chen1c57e862006-07-12 08:59:32 -0700360/*
361*******************************************************************************
362** Adapter Control Block
363*******************************************************************************
364*/
365struct AdapterControlBlock
366{
Nick Cheng1a4f5502007-09-13 17:26:40 +0800367 uint32_t adapter_type; /* adapter A,B..... */
368 #define ACB_ADAPTER_TYPE_A 0x00000001 /* hba I IOP */
369 #define ACB_ADAPTER_TYPE_B 0x00000002 /* hbb M IOP */
370 #define ACB_ADAPTER_TYPE_C 0x00000004 /* hbc P IOP */
371 #define ACB_ADAPTER_TYPE_D 0x00000008 /* hbd A IOP */
Erich Chen1c57e862006-07-12 08:59:32 -0700372 struct pci_dev * pdev;
373 struct Scsi_Host * host;
374 unsigned long vir2phy_offset;
375 /* Offset is used in making arc cdb physical to virtual calculations */
376 uint32_t outbound_int_enable;
Nick Chengae52e7f2010-06-18 15:39:12 +0800377 spinlock_t eh_lock;
378 spinlock_t ccblist_lock;
Al Viro80da1ad2007-10-29 05:08:28 +0000379 union {
Al Viro80da1ad2007-10-29 05:08:28 +0000380 struct MessageUnit_A __iomem * pmuA;
381 struct MessageUnit_B * pmuB;
382 };
Erich Chen1c57e862006-07-12 08:59:32 -0700383 /* message unit ATU inbound base address0 */
Nick Chengae52e7f2010-06-18 15:39:12 +0800384 void __iomem *mem_base0;
385 void __iomem *mem_base1;
Erich Chen1c57e862006-07-12 08:59:32 -0700386 uint32_t acb_flags;
Nick Chengae52e7f2010-06-18 15:39:12 +0800387 u16 dev_id;
Nick Cheng36b83de2010-05-17 11:22:42 +0800388 uint8_t adapter_index;
Nick Cheng1a4f5502007-09-13 17:26:40 +0800389 #define ACB_F_SCSISTOPADAPTER 0x0001
390 #define ACB_F_MSG_STOP_BGRB 0x0002
Erich Chen1c57e862006-07-12 08:59:32 -0700391 /* stop RAID background rebuild */
Nick Cheng1a4f5502007-09-13 17:26:40 +0800392 #define ACB_F_MSG_START_BGRB 0x0004
Erich Chen1c57e862006-07-12 08:59:32 -0700393 /* stop RAID background rebuild */
Nick Cheng1a4f5502007-09-13 17:26:40 +0800394 #define ACB_F_IOPDATA_OVERFLOW 0x0008
Erich Chen1c57e862006-07-12 08:59:32 -0700395 /* iop message data rqbuffer overflow */
Nick Cheng1a4f5502007-09-13 17:26:40 +0800396 #define ACB_F_MESSAGE_WQBUFFER_CLEARED 0x0010
Erich Chen1c57e862006-07-12 08:59:32 -0700397 /* message clear wqbuffer */
Nick Cheng1a4f5502007-09-13 17:26:40 +0800398 #define ACB_F_MESSAGE_RQBUFFER_CLEARED 0x0020
Erich Chen1c57e862006-07-12 08:59:32 -0700399 /* message clear rqbuffer */
Nick Cheng1a4f5502007-09-13 17:26:40 +0800400 #define ACB_F_MESSAGE_WQBUFFER_READED 0x0040
401 #define ACB_F_BUS_RESET 0x0080
402 #define ACB_F_IOP_INITED 0x0100
Erich Chen1c57e862006-07-12 08:59:32 -0700403 /* iop init */
Nick Chengae52e7f2010-06-18 15:39:12 +0800404 #define ACB_F_ABORT 0x0200
Nick Cheng36b83de2010-05-17 11:22:42 +0800405 #define ACB_F_FIRMWARE_TRAP 0x0400
Erich Chen1c57e862006-07-12 08:59:32 -0700406 struct CommandControlBlock * pccb_pool[ARCMSR_MAX_FREECCB_NUM];
407 /* used for memory free */
408 struct list_head ccb_free_list;
409 /* head of free ccb list */
Nick Cheng1a4f5502007-09-13 17:26:40 +0800410
Erich Chen1c57e862006-07-12 08:59:32 -0700411 atomic_t ccboutstandingcount;
Nick Cheng1a4f5502007-09-13 17:26:40 +0800412 /*The present outstanding command number that in the IOP that
413 waiting for being handled by FW*/
Erich Chen1c57e862006-07-12 08:59:32 -0700414
415 void * dma_coherent;
416 /* dma_coherent used for memory free */
417 dma_addr_t dma_coherent_handle;
418 /* dma_coherent_handle used for memory free */
Nick Chengae52e7f2010-06-18 15:39:12 +0800419 dma_addr_t dma_coherent_handle_hbb_mu;
420 unsigned int uncache_size;
Erich Chen1c57e862006-07-12 08:59:32 -0700421 uint8_t rqbuffer[ARCMSR_MAX_QBUFFER];
422 /* data collection buffer for read from 80331 */
423 int32_t rqbuf_firstindex;
424 /* first of read buffer */
425 int32_t rqbuf_lastindex;
426 /* last of read buffer */
427 uint8_t wqbuffer[ARCMSR_MAX_QBUFFER];
428 /* data collection buffer for write to 80331 */
429 int32_t wqbuf_firstindex;
430 /* first of write buffer */
431 int32_t wqbuf_lastindex;
432 /* last of write buffer */
433 uint8_t devstate[ARCMSR_MAX_TARGETID][ARCMSR_MAX_TARGETLUN];
434 /* id0 ..... id15, lun0...lun7 */
435#define ARECA_RAID_GONE 0x55
436#define ARECA_RAID_GOOD 0xaa
437 uint32_t num_resets;
438 uint32_t num_aborts;
Nick Cheng36b83de2010-05-17 11:22:42 +0800439 uint32_t signature;
Erich Chen1c57e862006-07-12 08:59:32 -0700440 uint32_t firm_request_len;
441 uint32_t firm_numbers_queue;
442 uint32_t firm_sdram_size;
443 uint32_t firm_hd_channels;
Nick Chengae52e7f2010-06-18 15:39:12 +0800444 uint32_t firm_cfg_version;
Erich Chen1c57e862006-07-12 08:59:32 -0700445 char firm_model[12];
446 char firm_version[20];
Nick Cheng36b83de2010-05-17 11:22:42 +0800447 char device_map[20]; /*21,84-99*/
448 struct work_struct arcmsr_do_message_isr_bh;
449 struct timer_list eternal_timer;
Nick Chengae52e7f2010-06-18 15:39:12 +0800450 unsigned short fw_flag;
451 #define FW_NORMAL 0x0000
452 #define FW_BOG 0x0001
453 #define FW_DEADLOCK 0x0010
Nick Cheng36b83de2010-05-17 11:22:42 +0800454 atomic_t rq_map_token;
Nick Chengae52e7f2010-06-18 15:39:12 +0800455 atomic_t ante_token_value;
Erich Chen1c57e862006-07-12 08:59:32 -0700456};/* HW_DEVICE_EXTENSION */
457/*
458*******************************************************************************
459** Command Control Block
460** this CCB length must be 32 bytes boundary
461*******************************************************************************
462*/
463struct CommandControlBlock
464{
Nick Chengae52e7f2010-06-18 15:39:12 +0800465 /*x32:sizeof struct_CCB=(32+60)byte, x64:sizeof struct_CCB=(64+60)byte*/
466 struct list_head list; /*x32: 8byte, x64: 16byte*/
467 struct scsi_cmnd *pcmd; /*8 bytes pointer of linux scsi command */
468 struct AdapterControlBlock *acb; /*x32: 4byte, x64: 8byte*/
469 uint32_t shifted_cdb_phyaddr; /*x32: 4byte, x64: 4byte*/
470 uint16_t ccb_flags; /*x32: 2byte, x64: 2byte*/
Erich Chen1c57e862006-07-12 08:59:32 -0700471 #define CCB_FLAG_READ 0x0000
472 #define CCB_FLAG_WRITE 0x0001
473 #define CCB_FLAG_ERROR 0x0002
474 #define CCB_FLAG_FLUSHCACHE 0x0004
475 #define CCB_FLAG_MASTER_ABORTED 0x0008
Nick Chengae52e7f2010-06-18 15:39:12 +0800476 uint16_t startdone; /*x32:2byte,x32:2byte*/
Erich Chen1c57e862006-07-12 08:59:32 -0700477 #define ARCMSR_CCB_DONE 0x0000
478 #define ARCMSR_CCB_START 0x55AA
479 #define ARCMSR_CCB_ABORTED 0xAA55
480 #define ARCMSR_CCB_ILLEGAL 0xFFFF
Nick Chengae52e7f2010-06-18 15:39:12 +0800481 #if BITS_PER_LONG == 64
482 /* ======================512+64 bytes======================== */
483 uint32_t reserved[6]; /*24 byte*/
Erich Chen1c57e862006-07-12 08:59:32 -0700484#else
485 /* ======================512+32 bytes======================== */
Nick Chengae52e7f2010-06-18 15:39:12 +0800486 uint32_t reserved[2]; /*8 byte*/
Erich Chen1c57e862006-07-12 08:59:32 -0700487#endif
Nick Chengae52e7f2010-06-18 15:39:12 +0800488 /* ======================================================= */
489 struct ARCMSR_CDB arcmsr_cdb;
Erich Chen1c57e862006-07-12 08:59:32 -0700490};
491/*
492*******************************************************************************
493** ARECA SCSI sense data
494*******************************************************************************
495*/
496struct SENSE_DATA
497{
498 uint8_t ErrorCode:7;
499#define SCSI_SENSE_CURRENT_ERRORS 0x70
500#define SCSI_SENSE_DEFERRED_ERRORS 0x71
501 uint8_t Valid:1;
502 uint8_t SegmentNumber;
503 uint8_t SenseKey:4;
504 uint8_t Reserved:1;
505 uint8_t IncorrectLength:1;
506 uint8_t EndOfMedia:1;
507 uint8_t FileMark:1;
508 uint8_t Information[4];
509 uint8_t AdditionalSenseLength;
510 uint8_t CommandSpecificInformation[4];
511 uint8_t AdditionalSenseCode;
512 uint8_t AdditionalSenseCodeQualifier;
513 uint8_t FieldReplaceableUnitCode;
514 uint8_t SenseKeySpecific[3];
515};
516/*
517*******************************************************************************
518** Outbound Interrupt Status Register - OISR
519*******************************************************************************
520*/
521#define ARCMSR_MU_OUTBOUND_INTERRUPT_STATUS_REG 0x30
522#define ARCMSR_MU_OUTBOUND_PCI_INT 0x10
523#define ARCMSR_MU_OUTBOUND_POSTQUEUE_INT 0x08
524#define ARCMSR_MU_OUTBOUND_DOORBELL_INT 0x04
525#define ARCMSR_MU_OUTBOUND_MESSAGE1_INT 0x02
526#define ARCMSR_MU_OUTBOUND_MESSAGE0_INT 0x01
527#define ARCMSR_MU_OUTBOUND_HANDLE_INT \
528 (ARCMSR_MU_OUTBOUND_MESSAGE0_INT \
529 |ARCMSR_MU_OUTBOUND_MESSAGE1_INT \
530 |ARCMSR_MU_OUTBOUND_DOORBELL_INT \
531 |ARCMSR_MU_OUTBOUND_POSTQUEUE_INT \
532 |ARCMSR_MU_OUTBOUND_PCI_INT)
533/*
534*******************************************************************************
535** Outbound Interrupt Mask Register - OIMR
536*******************************************************************************
537*/
538#define ARCMSR_MU_OUTBOUND_INTERRUPT_MASK_REG 0x34
539#define ARCMSR_MU_OUTBOUND_PCI_INTMASKENABLE 0x10
540#define ARCMSR_MU_OUTBOUND_POSTQUEUE_INTMASKENABLE 0x08
541#define ARCMSR_MU_OUTBOUND_DOORBELL_INTMASKENABLE 0x04
542#define ARCMSR_MU_OUTBOUND_MESSAGE1_INTMASKENABLE 0x02
543#define ARCMSR_MU_OUTBOUND_MESSAGE0_INTMASKENABLE 0x01
544#define ARCMSR_MU_OUTBOUND_ALL_INTMASKENABLE 0x1F
545
Nick Cheng1a4f5502007-09-13 17:26:40 +0800546extern void arcmsr_post_ioctldata2iop(struct AdapterControlBlock *);
547extern void arcmsr_iop_message_read(struct AdapterControlBlock *);
Al Viro80da1ad2007-10-29 05:08:28 +0000548extern struct QBUFFER __iomem *arcmsr_get_iop_rqbuffer(struct AdapterControlBlock *);
Tony Jonesee959b02008-02-22 00:13:36 +0100549extern struct device_attribute *arcmsr_host_attrs[];
Nick Cheng1a4f5502007-09-13 17:26:40 +0800550extern int arcmsr_alloc_sysfs_attr(struct AdapterControlBlock *);
Erich Chen1c57e862006-07-12 08:59:32 -0700551void arcmsr_free_sysfs_attr(struct AdapterControlBlock *acb);