2 * Marvell UMI head file
4 * Copyright 2011 Marvell. <jyli@marvell.com>
6 * This file is licensed under GPLv2.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; version 2 of the
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27 #define MAX_BASE_ADDRESS 6
32 #define VER_BUILD 1500
34 #define MV_DRIVER_NAME "mvumi"
35 #define PCI_VENDOR_ID_MARVELL_2 0x1b4b
36 #define PCI_DEVICE_ID_MARVELL_MV9143 0x9143
38 #define MVUMI_INTERNAL_CMD_WAIT_TIME 45
40 #define IS_DMA64 (sizeof(dma_addr_t) == 8)
42 enum mvumi_qc_result {
43 MV_QUEUE_COMMAND_RESULT_SENT = 0,
44 MV_QUEUE_COMMAND_RESULT_NO_RESOURCE,
48 /*******************************************/
50 /* ARM Mbus Registers Map */
52 /*******************************************/
53 CPU_MAIN_INT_CAUSE_REG = 0x20200,
54 CPU_MAIN_IRQ_MASK_REG = 0x20204,
55 CPU_MAIN_FIQ_MASK_REG = 0x20208,
56 CPU_ENPOINTA_MASK_REG = 0x2020C,
57 CPU_ENPOINTB_MASK_REG = 0x20210,
59 INT_MAP_COMAERR = 1 << 6,
60 INT_MAP_COMAIN = 1 << 7,
61 INT_MAP_COMAOUT = 1 << 8,
62 INT_MAP_COMBERR = 1 << 9,
63 INT_MAP_COMBIN = 1 << 10,
64 INT_MAP_COMBOUT = 1 << 11,
66 INT_MAP_COMAINT = (INT_MAP_COMAOUT | INT_MAP_COMAERR),
67 INT_MAP_COMBINT = (INT_MAP_COMBOUT | INT_MAP_COMBIN | INT_MAP_COMBERR),
69 INT_MAP_DL_PCIEA2CPU = 1 << 0,
70 INT_MAP_DL_CPU2PCIEA = 1 << 1,
72 /***************************************/
74 /* ARM Doorbell Registers Map */
76 /***************************************/
77 CPU_PCIEA_TO_ARM_DRBL_REG = 0x20400,
78 CPU_PCIEA_TO_ARM_MASK_REG = 0x20404,
79 CPU_ARM_TO_PCIEA_DRBL_REG = 0x20408,
80 CPU_ARM_TO_PCIEA_MASK_REG = 0x2040C,
82 DRBL_HANDSHAKE = 1 << 0,
83 DRBL_SOFT_RESET = 1 << 1,
84 DRBL_BUS_CHANGE = 1 << 2,
85 DRBL_EVENT_NOTIFY = 1 << 3,
86 DRBL_MU_RESET = 1 << 4,
87 DRBL_HANDSHAKE_ISR = DRBL_HANDSHAKE,
89 CPU_PCIEA_TO_ARM_MSG0 = 0x20430,
90 CPU_PCIEA_TO_ARM_MSG1 = 0x20434,
91 CPU_ARM_TO_PCIEA_MSG0 = 0x20438,
92 CPU_ARM_TO_PCIEA_MSG1 = 0x2043C,
94 /*******************************************/
96 /* ARM Communication List Registers Map */
98 /*******************************************/
99 CLA_INB_LIST_BASEL = 0x500,
100 CLA_INB_LIST_BASEH = 0x504,
101 CLA_INB_AVAL_COUNT_BASEL = 0x508,
102 CLA_INB_AVAL_COUNT_BASEH = 0x50C,
103 CLA_INB_DESTI_LIST_BASEL = 0x510,
104 CLA_INB_DESTI_LIST_BASEH = 0x514,
105 CLA_INB_WRITE_POINTER = 0x518,
106 CLA_INB_READ_POINTER = 0x51C,
108 CLA_OUTB_LIST_BASEL = 0x530,
109 CLA_OUTB_LIST_BASEH = 0x534,
110 CLA_OUTB_SOURCE_LIST_BASEL = 0x538,
111 CLA_OUTB_SOURCE_LIST_BASEH = 0x53C,
112 CLA_OUTB_COPY_POINTER = 0x544,
113 CLA_OUTB_READ_POINTER = 0x548,
115 CLA_ISR_CAUSE = 0x560,
116 CLA_ISR_MASK = 0x564,
118 INT_MAP_MU = (INT_MAP_DL_CPU2PCIEA | INT_MAP_COMAINT),
120 CL_POINTER_TOGGLE = 1 << 12,
122 CLIC_IN_IRQ = 1 << 0,
123 CLIC_OUT_IRQ = 1 << 1,
124 CLIC_IN_ERR_IRQ = 1 << 8,
125 CLIC_OUT_ERR_IRQ = 1 << 12,
127 CL_SLOT_NUM_MASK = 0xFFF,
130 * Command flag is the flag for the CDB command itself
132 /* 1-non data; 0-data command */
133 CMD_FLAG_NON_DATA = 1 << 0,
134 CMD_FLAG_DMA = 1 << 1,
135 CMD_FLAG_PIO = 1 << 2,
136 /* 1-host read data */
137 CMD_FLAG_DATA_IN = 1 << 3,
138 /* 1-host write data */
139 CMD_FLAG_DATA_OUT = 1 << 4,
141 SCSI_CMD_MARVELL_SPECIFIC = 0xE1,
142 CDB_CORE_SHUTDOWN = 0xB,
145 #define APICDB0_EVENT 0xF4
146 #define APICDB1_EVENT_GETEVENT 0
147 #define MAX_EVENTS_RETURNED 6
149 struct mvumi_driver_event {
157 u8 sense_data_length;
162 struct mvumi_event_req {
164 unsigned char reserved[3];
165 struct mvumi_driver_event events[MAX_EVENTS_RETURNED];
168 struct mvumi_events_wq {
169 struct work_struct work_q;
170 struct mvumi_hba *mhba;
175 #define MVUMI_MAX_SG_ENTRY 32
176 #define SGD_EOT (1L << 27)
186 struct list_head entry;
190 unsigned short type; /* enum Resource_Type */
195 RESOURCE_CACHED_MEMORY = 0,
196 RESOURCE_UNCACHED_MEMORY
199 struct mvumi_sense_data {
205 u8 incorrect_length:1;
209 u8 additional_sense_length;
210 u8 command_specific_information[4];
211 u8 additional_sense_code;
212 u8 additional_sense_code_qualifier;
213 u8 field_replaceable_unit_code;
214 u8 sense_key_specific[3];
217 /* Request initiator must set the status to REQ_STATUS_PENDING. */
218 #define REQ_STATUS_PENDING 0x80
221 struct list_head queue_pointer;
222 struct mvumi_msg_frame *frame;
223 struct scsi_cmnd *scmd;
226 unsigned short request_id;
227 unsigned char cmd_status;
231 * the function type of the in bound frame
233 #define CL_FUN_SCSI_CMD 0x1
235 struct mvumi_msg_frame {
242 u32 data_transfer_length;
245 u8 cdb[MAX_COMMAND_SIZE];
250 * the respond flag for data_payload of the out bound frame
252 #define CL_RSP_FLAG_NODATA 0x0
253 #define CL_RSP_FLAG_SENSEDATA 0x1
255 struct mvumi_rsp_frame {
259 u8 rsp_flag; /* Indicates the type of Data_Payload.*/
264 struct mvumi_ob_data {
265 struct list_head list;
266 unsigned char data[0];
269 struct version_info {
276 #define FW_MAX_DELAY 30
277 #define MVUMI_FW_BUSY (1U << 0)
278 #define MVUMI_FW_ATTACH (1U << 1)
279 #define MVUMI_FW_ALLOC (1U << 2)
282 * State is the state of the MU
284 #define FW_STATE_IDLE 0
285 #define FW_STATE_STARTING 1
286 #define FW_STATE_HANDSHAKING 2
287 #define FW_STATE_STARTED 3
288 #define FW_STATE_ABORT 4
290 #define HANDSHAKE_SIGNATURE 0x5A5A5A5AL
291 #define HANDSHAKE_READYSTATE 0x55AA5AA5L
292 #define HANDSHAKE_DONESTATE 0x55AAA55AL
294 /* HandShake Status definition */
295 #define HS_STATUS_OK 1
296 #define HS_STATUS_ERR 2
297 #define HS_STATUS_INVALID 3
299 /* HandShake State/Cmd definition */
302 #define HS_S_PAGE_ADDR 3
303 #define HS_S_QUERY_PAGE 4
304 #define HS_S_SEND_PAGE 5
307 #define HS_PAGE_VERIFY_SIZE 128
309 #define HS_GET_STATE(a) (a & 0xFFFF)
310 #define HS_GET_STATUS(a) ((a & 0xFFFF0000) >> 16)
311 #define HS_SET_STATE(a, b) (a |= (b & 0xFFFF))
312 #define HS_SET_STATUS(a, b) (a |= ((b & 0xFFFF) << 16))
314 /* handshake frame */
315 struct mvumi_hs_frame {
317 /* host information */
320 struct version_info host_ver; /* bios or driver version */
322 /* controller information */
328 /* communication list configuration */
340 u64 seconds_since1970;
343 struct mvumi_hs_header {
347 u32 frame_content[1];
351 * the page code type of the handshake header
353 #define HS_PAGE_FIRM_CAP 0x1
354 #define HS_PAGE_HOST_INFO 0x2
355 #define HS_PAGE_FIRM_CTL 0x3
356 #define HS_PAGE_CL_INFO 0x4
357 #define HS_PAGE_TOTAL 0x5
359 #define HSP_SIZE(i) sizeof(struct mvumi_hs_page##i)
361 #define HSP_MAX_SIZE ({ \
363 m1 = max(HSP_SIZE(1), HSP_SIZE(3)); \
364 m2 = max(HSP_SIZE(2), HSP_SIZE(4)); \
365 size = max(m1, m2); \
369 /* The format of the page code for Firmware capability */
370 struct mvumi_hs_page1 {
376 u16 max_devices_support;
379 u32 max_transfer_size;
380 struct version_info fw_ver;
381 u8 cl_in_max_entry_size;
382 u8 cl_out_max_entry_size;
383 u8 cl_inout_list_depth;
389 /* The format of the page code for Host information */
390 struct mvumi_hs_page2 {
397 struct version_info host_ver;
402 u64 seconds_since1970;
405 /* The format of the page code for firmware control */
406 struct mvumi_hs_page3 {
412 u32 host_bufferaddr_l;
413 u32 host_bufferaddr_h;
414 u32 host_eventaddr_l;
415 u32 host_eventaddr_h;
418 struct mvumi_hs_page4 {
433 unsigned short *stack;
439 void *base_addr[MAX_BASE_ADDRESS];
441 struct list_head cmd_pool;
442 struct Scsi_Host *shost;
443 wait_queue_head_t int_cmd_wait_q;
444 struct pci_dev *pdev;
445 unsigned int unique_id;
446 atomic_t fw_outstanding;
447 struct mvumi_instance_template *instancet;
450 dma_addr_t ib_list_phys;
453 dma_addr_t ob_list_phys;
456 dma_addr_t ib_shadow_phys;
459 dma_addr_t ob_shadow_phys;
461 void *handshake_page;
462 dma_addr_t handshake_page_phys;
464 unsigned int global_isr;
465 unsigned int isr_status;
467 unsigned short max_sge;
468 unsigned short max_target_id;
469 unsigned char *target_map;
471 unsigned int list_num_io;
472 unsigned int ib_max_size;
473 unsigned int ob_max_size;
474 unsigned int ib_max_size_setting;
475 unsigned int ob_max_size_setting;
476 unsigned int max_transfer_size;
477 unsigned char hba_total_pages;
478 unsigned char fw_flag;
479 unsigned char request_id_enabled;
480 unsigned short hba_capability;
481 unsigned short io_seq;
483 unsigned int ib_cur_slot;
484 unsigned int ob_cur_slot;
485 unsigned int fw_state;
487 struct list_head ob_data_list;
488 struct list_head free_ob_list;
489 struct list_head res_list;
490 struct list_head waiting_req_list;
492 struct mvumi_tag tag_pool;
493 struct mvumi_cmd **tag_cmd;
496 struct mvumi_instance_template {
497 void (*fire_cmd)(struct mvumi_hba *, struct mvumi_cmd *);
498 void (*enable_intr)(void *) ;
499 void (*disable_intr)(void *);
500 int (*clear_intr)(void *);
501 unsigned int (*read_fw_status_reg)(void *);
504 extern struct timezone sys_tz;