blob: 88604244ae27c8e2b69e78fd1b8dfc90314fdb2a [file] [log] [blame]
Matthew Wilcox01fbfe02007-09-09 08:56:40 -06001#define DRV_NAME "advansys"
Matthew Wilcox8c6af9e2007-07-26 11:03:19 -04002#define ASC_VERSION "3.4" /* AdvanSys Driver Version */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003
4/*
5 * advansys.c - Linux Host Driver for AdvanSys SCSI Adapters
6 *
7 * Copyright (c) 1995-2000 Advanced System Products, Inc.
8 * Copyright (c) 2000-2001 ConnectCom Solutions, Inc.
Matthew Wilcox8c6af9e2007-07-26 11:03:19 -04009 * Copyright (c) 2007 Matthew Wilcox <matthew@wil.cx>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * All Rights Reserved.
11 *
Matthew Wilcox8c6af9e2007-07-26 11:03:19 -040012 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 */
17
18/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 * As of March 8, 2000 Advanced System Products, Inc. (AdvanSys)
20 * changed its name to ConnectCom Solutions, Inc.
Matthew Wilcox8c6af9e2007-07-26 11:03:19 -040021 * On June 18, 2001 Initio Corp. acquired ConnectCom's SCSI assets
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 */
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/string.h>
26#include <linux/kernel.h>
27#include <linux/types.h>
28#include <linux/ioport.h>
29#include <linux/interrupt.h>
30#include <linux/delay.h>
31#include <linux/slab.h>
32#include <linux/mm.h>
33#include <linux/proc_fs.h>
34#include <linux/init.h>
35#include <linux/blkdev.h>
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060036#include <linux/isa.h>
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060037#include <linux/eisa.h>
Matthew Wilcox8c6af9e2007-07-26 11:03:19 -040038#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/spinlock.h>
40#include <linux/dma-mapping.h>
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +053041#include <linux/firmware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <asm/dma.h>
45
Matthew Wilcox8c6af9e2007-07-26 11:03:19 -040046#include <scsi/scsi_cmnd.h>
47#include <scsi/scsi_device.h>
48#include <scsi/scsi_tcq.h>
49#include <scsi/scsi.h>
50#include <scsi/scsi_host.h>
51
Matthew Wilcox4bd6d7f2007-07-30 08:41:03 -060052/* FIXME:
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 *
Matthew Wilcox4bd6d7f2007-07-30 08:41:03 -060054 * 1. Although all of the necessary command mapping places have the
55 * appropriate dma_map.. APIs, the driver still processes its internal
56 * queue using bus_to_virt() and virt_to_bus() which are illegal under
57 * the API. The entire queue processing structure will need to be
58 * altered to fix this.
59 * 2. Need to add memory mapping workaround. Test the memory mapping.
60 * If it doesn't work revert to I/O port access. Can a test be done
61 * safely?
62 * 3. Handle an interrupt not working. Keep an interrupt counter in
63 * the interrupt handler. In the timeout function if the interrupt
64 * has not occurred then print a message and run in polled mode.
65 * 4. Need to add support for target mode commands, cf. CAM XPT.
66 * 5. check DMA mapping functions for failure
Matthew Wilcox349d2c42007-09-09 08:56:34 -060067 * 6. Use scsi_transport_spi
68 * 7. advansys_info is not safe against multiple simultaneous callers
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040069 * 8. Add module_param to override ISA/VLB ioport array
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 */
71#warning this driver is still not properly converted to the DMA API
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073/* Enable driver /proc statistics. */
74#define ADVANSYS_STATS
75
76/* Enable driver tracing. */
Matthew Wilcoxb352f922007-10-02 21:55:33 -040077#undef ADVANSYS_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Linus Torvalds1da177e2005-04-16 15:20:36 -070079typedef unsigned char uchar;
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081#define isodd_word(val) ((((uint)val) & (uint)0x0001) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Dave Jones2672ea82006-08-02 17:11:49 -040083#define PCI_VENDOR_ID_ASP 0x10cd
84#define PCI_DEVICE_ID_ASP_1200A 0x1100
85#define PCI_DEVICE_ID_ASP_ABP940 0x1200
86#define PCI_DEVICE_ID_ASP_ABP940U 0x1300
87#define PCI_DEVICE_ID_ASP_ABP940UW 0x2300
88#define PCI_DEVICE_ID_38C0800_REV1 0x2500
89#define PCI_DEVICE_ID_38C1600_REV1 0x2700
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091/*
92 * Enable CC_VERY_LONG_SG_LIST to support up to 64K element SG lists.
93 * The SRB structure will have to be changed and the ASC_SRB2SCSIQ()
94 * macro re-defined to be able to obtain a ASC_SCSI_Q pointer from the
95 * SRB structure.
96 */
97#define CC_VERY_LONG_SG_LIST 0
98#define ASC_SRB2SCSIQ(srb_ptr) (srb_ptr)
99
Matthew Wilcox9d511a42007-10-02 21:55:42 -0400100#define PortAddr unsigned int /* port address size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#define inp(port) inb(port)
102#define outp(port, byte) outb((byte), (port))
103
104#define inpw(port) inw(port)
105#define outpw(port, word) outw((word), (port))
106
107#define ASC_MAX_SG_QUEUE 7
108#define ASC_MAX_SG_LIST 255
109
110#define ASC_CS_TYPE unsigned short
111
112#define ASC_IS_ISA (0x0001)
113#define ASC_IS_ISAPNP (0x0081)
114#define ASC_IS_EISA (0x0002)
115#define ASC_IS_PCI (0x0004)
116#define ASC_IS_PCI_ULTRA (0x0104)
117#define ASC_IS_PCMCIA (0x0008)
118#define ASC_IS_MCA (0x0020)
119#define ASC_IS_VL (0x0040)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120#define ASC_IS_WIDESCSI_16 (0x0100)
121#define ASC_IS_WIDESCSI_32 (0x0200)
122#define ASC_IS_BIG_ENDIAN (0x8000)
Matthew Wilcox95c9f162007-09-09 08:56:39 -0600123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124#define ASC_CHIP_MIN_VER_VL (0x01)
125#define ASC_CHIP_MAX_VER_VL (0x07)
126#define ASC_CHIP_MIN_VER_PCI (0x09)
127#define ASC_CHIP_MAX_VER_PCI (0x0F)
128#define ASC_CHIP_VER_PCI_BIT (0x08)
129#define ASC_CHIP_MIN_VER_ISA (0x11)
130#define ASC_CHIP_MIN_VER_ISA_PNP (0x21)
131#define ASC_CHIP_MAX_VER_ISA (0x27)
132#define ASC_CHIP_VER_ISA_BIT (0x30)
133#define ASC_CHIP_VER_ISAPNP_BIT (0x20)
134#define ASC_CHIP_VER_ASYN_BUG (0x21)
135#define ASC_CHIP_VER_PCI 0x08
136#define ASC_CHIP_VER_PCI_ULTRA_3150 (ASC_CHIP_VER_PCI | 0x02)
137#define ASC_CHIP_VER_PCI_ULTRA_3050 (ASC_CHIP_VER_PCI | 0x03)
138#define ASC_CHIP_MIN_VER_EISA (0x41)
139#define ASC_CHIP_MAX_VER_EISA (0x47)
140#define ASC_CHIP_VER_EISA_BIT (0x40)
141#define ASC_CHIP_LATEST_VER_EISA ((ASC_CHIP_MIN_VER_EISA - 1) + 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#define ASC_MAX_VL_DMA_COUNT (0x07FFFFFFL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143#define ASC_MAX_PCI_DMA_COUNT (0xFFFFFFFFL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144#define ASC_MAX_ISA_DMA_COUNT (0x00FFFFFFL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146#define ASC_SCSI_ID_BITS 3
147#define ASC_SCSI_TIX_TYPE uchar
148#define ASC_ALL_DEVICE_BIT_SET 0xFF
149#define ASC_SCSI_BIT_ID_TYPE uchar
150#define ASC_MAX_TID 7
151#define ASC_MAX_LUN 7
152#define ASC_SCSI_WIDTH_BIT_SET 0xFF
153#define ASC_MAX_SENSE_LEN 32
154#define ASC_MIN_SENSE_LEN 14
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155#define ASC_SCSI_RESET_HOLD_TIME_US 60
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157/*
Matthew Wilcoxf05ec592007-09-09 08:56:36 -0600158 * Narrow boards only support 12-byte commands, while wide boards
159 * extend to 16-byte commands.
160 */
161#define ASC_MAX_CDB_LEN 12
162#define ADV_MAX_CDB_LEN 16
163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164#define MS_SDTR_LEN 0x03
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165#define MS_WDTR_LEN 0x02
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167#define ASC_SG_LIST_PER_Q 7
168#define QS_FREE 0x00
169#define QS_READY 0x01
170#define QS_DISC1 0x02
171#define QS_DISC2 0x04
172#define QS_BUSY 0x08
173#define QS_ABORTED 0x40
174#define QS_DONE 0x80
175#define QC_NO_CALLBACK 0x01
176#define QC_SG_SWAP_QUEUE 0x02
177#define QC_SG_HEAD 0x04
178#define QC_DATA_IN 0x08
179#define QC_DATA_OUT 0x10
180#define QC_URGENT 0x20
181#define QC_MSG_OUT 0x40
182#define QC_REQ_SENSE 0x80
183#define QCSG_SG_XFER_LIST 0x02
184#define QCSG_SG_XFER_MORE 0x04
185#define QCSG_SG_XFER_END 0x08
186#define QD_IN_PROGRESS 0x00
187#define QD_NO_ERROR 0x01
188#define QD_ABORTED_BY_HOST 0x02
189#define QD_WITH_ERROR 0x04
190#define QD_INVALID_REQUEST 0x80
191#define QD_INVALID_HOST_NUM 0x81
192#define QD_INVALID_DEVICE 0x82
193#define QD_ERR_INTERNAL 0xFF
194#define QHSTA_NO_ERROR 0x00
195#define QHSTA_M_SEL_TIMEOUT 0x11
196#define QHSTA_M_DATA_OVER_RUN 0x12
197#define QHSTA_M_DATA_UNDER_RUN 0x12
198#define QHSTA_M_UNEXPECTED_BUS_FREE 0x13
199#define QHSTA_M_BAD_BUS_PHASE_SEQ 0x14
200#define QHSTA_D_QDONE_SG_LIST_CORRUPTED 0x21
201#define QHSTA_D_ASC_DVC_ERROR_CODE_SET 0x22
202#define QHSTA_D_HOST_ABORT_FAILED 0x23
203#define QHSTA_D_EXE_SCSI_Q_FAILED 0x24
204#define QHSTA_D_EXE_SCSI_Q_BUSY_TIMEOUT 0x25
205#define QHSTA_D_ASPI_NO_BUF_POOL 0x26
206#define QHSTA_M_WTM_TIMEOUT 0x41
207#define QHSTA_M_BAD_CMPL_STATUS_IN 0x42
208#define QHSTA_M_NO_AUTO_REQ_SENSE 0x43
209#define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
210#define QHSTA_M_TARGET_STATUS_BUSY 0x45
211#define QHSTA_M_BAD_TAG_CODE 0x46
212#define QHSTA_M_BAD_QUEUE_FULL_OR_BUSY 0x47
213#define QHSTA_M_HUNG_REQ_SCSI_BUS_RESET 0x48
214#define QHSTA_D_LRAM_CMP_ERROR 0x81
215#define QHSTA_M_MICRO_CODE_ERROR_HALT 0xA1
216#define ASC_FLAG_SCSIQ_REQ 0x01
217#define ASC_FLAG_BIOS_SCSIQ_REQ 0x02
218#define ASC_FLAG_BIOS_ASYNC_IO 0x04
219#define ASC_FLAG_SRB_LINEAR_ADDR 0x08
220#define ASC_FLAG_WIN16 0x10
221#define ASC_FLAG_WIN32 0x20
222#define ASC_FLAG_ISA_OVER_16MB 0x40
223#define ASC_FLAG_DOS_VM_CALLBACK 0x80
224#define ASC_TAG_FLAG_EXTRA_BYTES 0x10
225#define ASC_TAG_FLAG_DISABLE_DISCONNECT 0x04
226#define ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX 0x08
227#define ASC_TAG_FLAG_DISABLE_CHK_COND_INT_HOST 0x40
228#define ASC_SCSIQ_CPY_BEG 4
229#define ASC_SCSIQ_SGHD_CPY_BEG 2
230#define ASC_SCSIQ_B_FWD 0
231#define ASC_SCSIQ_B_BWD 1
232#define ASC_SCSIQ_B_STATUS 2
233#define ASC_SCSIQ_B_QNO 3
234#define ASC_SCSIQ_B_CNTL 4
235#define ASC_SCSIQ_B_SG_QUEUE_CNT 5
236#define ASC_SCSIQ_D_DATA_ADDR 8
237#define ASC_SCSIQ_D_DATA_CNT 12
238#define ASC_SCSIQ_B_SENSE_LEN 20
239#define ASC_SCSIQ_DONE_INFO_BEG 22
240#define ASC_SCSIQ_D_SRBPTR 22
241#define ASC_SCSIQ_B_TARGET_IX 26
242#define ASC_SCSIQ_B_CDB_LEN 28
243#define ASC_SCSIQ_B_TAG_CODE 29
244#define ASC_SCSIQ_W_VM_ID 30
245#define ASC_SCSIQ_DONE_STATUS 32
246#define ASC_SCSIQ_HOST_STATUS 33
247#define ASC_SCSIQ_SCSI_STATUS 34
248#define ASC_SCSIQ_CDB_BEG 36
249#define ASC_SCSIQ_DW_REMAIN_XFER_ADDR 56
250#define ASC_SCSIQ_DW_REMAIN_XFER_CNT 60
251#define ASC_SCSIQ_B_FIRST_SG_WK_QP 48
252#define ASC_SCSIQ_B_SG_WK_QP 49
253#define ASC_SCSIQ_B_SG_WK_IX 50
254#define ASC_SCSIQ_W_ALT_DC1 52
255#define ASC_SCSIQ_B_LIST_CNT 6
256#define ASC_SCSIQ_B_CUR_LIST_CNT 7
257#define ASC_SGQ_B_SG_CNTL 4
258#define ASC_SGQ_B_SG_HEAD_QP 5
259#define ASC_SGQ_B_SG_LIST_CNT 6
260#define ASC_SGQ_B_SG_CUR_LIST_CNT 7
261#define ASC_SGQ_LIST_BEG 8
262#define ASC_DEF_SCSI1_QNG 4
263#define ASC_MAX_SCSI1_QNG 4
264#define ASC_DEF_SCSI2_QNG 16
265#define ASC_MAX_SCSI2_QNG 32
266#define ASC_TAG_CODE_MASK 0x23
267#define ASC_STOP_REQ_RISC_STOP 0x01
268#define ASC_STOP_ACK_RISC_STOP 0x03
269#define ASC_STOP_CLEAN_UP_BUSY_Q 0x10
270#define ASC_STOP_CLEAN_UP_DISC_Q 0x20
271#define ASC_STOP_HOST_REQ_RISC_HALT 0x40
272#define ASC_TIDLUN_TO_IX(tid, lun) (ASC_SCSI_TIX_TYPE)((tid) + ((lun)<<ASC_SCSI_ID_BITS))
273#define ASC_TID_TO_TARGET_ID(tid) (ASC_SCSI_BIT_ID_TYPE)(0x01 << (tid))
274#define ASC_TIX_TO_TARGET_ID(tix) (0x01 << ((tix) & ASC_MAX_TID))
275#define ASC_TIX_TO_TID(tix) ((tix) & ASC_MAX_TID)
276#define ASC_TID_TO_TIX(tid) ((tid) & ASC_MAX_TID)
277#define ASC_TIX_TO_LUN(tix) (((tix) >> ASC_SCSI_ID_BITS) & ASC_MAX_LUN)
278#define ASC_QNO_TO_QADDR(q_no) ((ASC_QADR_BEG)+((int)(q_no) << 6))
279
280typedef struct asc_scsiq_1 {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400281 uchar status;
282 uchar q_no;
283 uchar cntl;
284 uchar sg_queue_cnt;
285 uchar target_id;
286 uchar target_lun;
Hannes Reinecke95cfab62015-04-24 13:18:27 +0200287 __le32 data_addr;
288 __le32 data_cnt;
289 __le32 sense_addr;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400290 uchar sense_len;
291 uchar extra_bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292} ASC_SCSIQ_1;
293
294typedef struct asc_scsiq_2 {
Hannes Reinecke9c17c622015-04-24 13:18:21 +0200295 u32 srb_tag;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400296 uchar target_ix;
297 uchar flag;
298 uchar cdb_len;
299 uchar tag_code;
300 ushort vm_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301} ASC_SCSIQ_2;
302
303typedef struct asc_scsiq_3 {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400304 uchar done_stat;
305 uchar host_stat;
306 uchar scsi_stat;
307 uchar scsi_msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308} ASC_SCSIQ_3;
309
310typedef struct asc_scsiq_4 {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400311 uchar cdb[ASC_MAX_CDB_LEN];
312 uchar y_first_sg_list_qp;
313 uchar y_working_sg_qp;
314 uchar y_working_sg_ix;
315 uchar y_res;
316 ushort x_req_count;
317 ushort x_reconnect_rtn;
Hannes Reinecke95cfab62015-04-24 13:18:27 +0200318 __le32 x_saved_data_addr;
319 __le32 x_saved_data_cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320} ASC_SCSIQ_4;
321
322typedef struct asc_q_done_info {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400323 ASC_SCSIQ_2 d2;
324 ASC_SCSIQ_3 d3;
325 uchar q_status;
326 uchar q_no;
327 uchar cntl;
328 uchar sense_len;
329 uchar extra_bytes;
330 uchar res;
Hannes Reinecke95cfab62015-04-24 13:18:27 +0200331 u32 remain_bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332} ASC_QDONE_INFO;
333
334typedef struct asc_sg_list {
Hannes Reinecke95cfab62015-04-24 13:18:27 +0200335 __le32 addr;
336 __le32 bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337} ASC_SG_LIST;
338
339typedef struct asc_sg_head {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400340 ushort entry_cnt;
341 ushort queue_cnt;
342 ushort entry_to_copy;
343 ushort res;
Matthew Wilcox05848b62007-10-02 21:55:25 -0400344 ASC_SG_LIST sg_list[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345} ASC_SG_HEAD;
346
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347typedef struct asc_scsi_q {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400348 ASC_SCSIQ_1 q1;
349 ASC_SCSIQ_2 q2;
350 uchar *cdbptr;
351 ASC_SG_HEAD *sg_head;
352 ushort remain_sg_entry_cnt;
353 ushort next_sg_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354} ASC_SCSI_Q;
355
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356typedef struct asc_scsi_bios_req_q {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400357 ASC_SCSIQ_1 r1;
358 ASC_SCSIQ_2 r2;
359 uchar *cdbptr;
360 ASC_SG_HEAD *sg_head;
361 uchar *sense_ptr;
362 ASC_SCSIQ_3 r3;
363 uchar cdb[ASC_MAX_CDB_LEN];
364 uchar sense[ASC_MIN_SENSE_LEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365} ASC_SCSI_BIOS_REQ_Q;
366
367typedef struct asc_risc_q {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400368 uchar fwd;
369 uchar bwd;
370 ASC_SCSIQ_1 i1;
371 ASC_SCSIQ_2 i2;
372 ASC_SCSIQ_3 i3;
373 ASC_SCSIQ_4 i4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374} ASC_RISC_Q;
375
376typedef struct asc_sg_list_q {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400377 uchar seq_no;
378 uchar q_no;
379 uchar cntl;
380 uchar sg_head_qp;
381 uchar sg_list_cnt;
382 uchar sg_cur_list_cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383} ASC_SG_LIST_Q;
384
385typedef struct asc_risc_sg_list_q {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400386 uchar fwd;
387 uchar bwd;
388 ASC_SG_LIST_Q sg;
389 ASC_SG_LIST sg_list[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390} ASC_RISC_SG_LIST_Q;
391
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392#define ASCQ_ERR_Q_STATUS 0x0D
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393#define ASCQ_ERR_CUR_QNG 0x17
394#define ASCQ_ERR_SG_Q_LINKS 0x18
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395#define ASCQ_ERR_ISR_RE_ENTRY 0x1A
396#define ASCQ_ERR_CRITICAL_RE_ENTRY 0x1B
397#define ASCQ_ERR_ISR_ON_CRITICAL 0x1C
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
399/*
400 * Warning code values are set in ASC_DVC_VAR 'warn_code'.
401 */
402#define ASC_WARN_NO_ERROR 0x0000
403#define ASC_WARN_IO_PORT_ROTATE 0x0001
404#define ASC_WARN_EEPROM_CHKSUM 0x0002
405#define ASC_WARN_IRQ_MODIFIED 0x0004
406#define ASC_WARN_AUTO_CONFIG 0x0008
407#define ASC_WARN_CMD_QNG_CONFLICT 0x0010
408#define ASC_WARN_EEPROM_RECOVER 0x0020
409#define ASC_WARN_CFG_MSW_RECOVER 0x0040
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
411/*
Matthew Wilcox720349a2007-10-02 21:55:30 -0400412 * Error code values are set in {ASC/ADV}_DVC_VAR 'err_code'.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 */
Matthew Wilcox720349a2007-10-02 21:55:30 -0400414#define ASC_IERR_NO_CARRIER 0x0001 /* No more carrier memory */
415#define ASC_IERR_MCODE_CHKSUM 0x0002 /* micro code check sum error */
416#define ASC_IERR_SET_PC_ADDR 0x0004
417#define ASC_IERR_START_STOP_CHIP 0x0008 /* start/stop chip failed */
418#define ASC_IERR_ILLEGAL_CONNECTION 0x0010 /* Illegal cable connection */
419#define ASC_IERR_SINGLE_END_DEVICE 0x0020 /* SE device on DIFF bus */
420#define ASC_IERR_REVERSED_CABLE 0x0040 /* Narrow flat cable reversed */
421#define ASC_IERR_SET_SCSI_ID 0x0080 /* set SCSI ID failed */
422#define ASC_IERR_HVD_DEVICE 0x0100 /* HVD device on LVD port */
423#define ASC_IERR_BAD_SIGNATURE 0x0200 /* signature not found */
424#define ASC_IERR_NO_BUS_TYPE 0x0400
425#define ASC_IERR_BIST_PRE_TEST 0x0800 /* BIST pre-test error */
426#define ASC_IERR_BIST_RAM_TEST 0x1000 /* BIST RAM test error */
427#define ASC_IERR_BAD_CHIPTYPE 0x2000 /* Invalid chip_type setting */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429#define ASC_DEF_MAX_TOTAL_QNG (0xF0)
430#define ASC_MIN_TAG_Q_PER_DVC (0x04)
Matthew Wilcox95c9f162007-09-09 08:56:39 -0600431#define ASC_MIN_FREE_Q (0x02)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432#define ASC_MIN_TOTAL_QNG ((ASC_MAX_SG_QUEUE)+(ASC_MIN_FREE_Q))
433#define ASC_MAX_TOTAL_QNG 240
434#define ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG 16
435#define ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG 8
436#define ASC_MAX_PCI_INRAM_TOTAL_QNG 20
437#define ASC_MAX_INRAM_TAG_QNG 16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438#define ASC_IOADR_GAP 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439#define ASC_SYN_MAX_OFFSET 0x0F
440#define ASC_DEF_SDTR_OFFSET 0x0F
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441#define ASC_SDTR_ULTRA_PCI_10MB_INDEX 0x02
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -0400442#define ASYN_SDTR_DATA_FIX_PCI_REV_AB 0x41
443
444/* The narrow chip only supports a limited selection of transfer rates.
445 * These are encoded in the range 0..7 or 0..15 depending whether the chip
446 * is Ultra-capable or not. These tables let us convert from one to the other.
447 */
448static const unsigned char asc_syn_xfer_period[8] = {
449 25, 30, 35, 40, 50, 60, 70, 85
450};
451
452static const unsigned char asc_syn_ultra_xfer_period[16] = {
453 12, 19, 25, 32, 38, 44, 50, 57, 63, 69, 75, 82, 88, 94, 100, 107
454};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
456typedef struct ext_msg {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400457 uchar msg_type;
458 uchar msg_len;
459 uchar msg_req;
460 union {
461 struct {
462 uchar sdtr_xfer_period;
463 uchar sdtr_req_ack_offset;
464 } sdtr;
465 struct {
466 uchar wdtr_width;
467 } wdtr;
468 struct {
469 uchar mdp_b3;
470 uchar mdp_b2;
471 uchar mdp_b1;
472 uchar mdp_b0;
473 } mdp;
474 } u_ext_msg;
475 uchar res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476} EXT_MSG;
477
478#define xfer_period u_ext_msg.sdtr.sdtr_xfer_period
479#define req_ack_offset u_ext_msg.sdtr.sdtr_req_ack_offset
480#define wdtr_width u_ext_msg.wdtr.wdtr_width
481#define mdp_b3 u_ext_msg.mdp_b3
482#define mdp_b2 u_ext_msg.mdp_b2
483#define mdp_b1 u_ext_msg.mdp_b1
484#define mdp_b0 u_ext_msg.mdp_b0
485
486typedef struct asc_dvc_cfg {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400487 ASC_SCSI_BIT_ID_TYPE can_tagged_qng;
488 ASC_SCSI_BIT_ID_TYPE cmd_qng_enabled;
489 ASC_SCSI_BIT_ID_TYPE disc_enable;
490 ASC_SCSI_BIT_ID_TYPE sdtr_enable;
491 uchar chip_scsi_id;
492 uchar isa_dma_speed;
493 uchar isa_dma_channel;
494 uchar chip_version;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400495 ushort mcode_date;
496 ushort mcode_version;
497 uchar max_tag_qng[ASC_MAX_TID + 1];
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400498 uchar sdtr_period_offset[ASC_MAX_TID + 1];
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400499 uchar adapter_info[6];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500} ASC_DVC_CFG;
501
502#define ASC_DEF_DVC_CNTL 0xFFFF
503#define ASC_DEF_CHIP_SCSI_ID 7
504#define ASC_DEF_ISA_DMA_SPEED 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505#define ASC_INIT_STATE_BEG_GET_CFG 0x0001
506#define ASC_INIT_STATE_END_GET_CFG 0x0002
507#define ASC_INIT_STATE_BEG_SET_CFG 0x0004
508#define ASC_INIT_STATE_END_SET_CFG 0x0008
509#define ASC_INIT_STATE_BEG_LOAD_MC 0x0010
510#define ASC_INIT_STATE_END_LOAD_MC 0x0020
511#define ASC_INIT_STATE_BEG_INQUIRY 0x0040
512#define ASC_INIT_STATE_END_INQUIRY 0x0080
513#define ASC_INIT_RESET_SCSI_DONE 0x0100
514#define ASC_INIT_STATE_WITHOUT_EEP 0x8000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515#define ASC_BUG_FIX_IF_NOT_DWB 0x0001
516#define ASC_BUG_FIX_ASYN_USE_SYN 0x0002
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517#define ASC_MIN_TAGGED_CMD 7
518#define ASC_MAX_SCSI_RESET_WAIT 30
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -0400519#define ASC_OVERRUN_BSIZE 64
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400521struct asc_dvc_var; /* Forward Declaration. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523typedef struct asc_dvc_var {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400524 PortAddr iop_base;
525 ushort err_code;
526 ushort dvc_cntl;
527 ushort bug_fix_cntl;
528 ushort bus_type;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400529 ASC_SCSI_BIT_ID_TYPE init_sdtr;
530 ASC_SCSI_BIT_ID_TYPE sdtr_done;
531 ASC_SCSI_BIT_ID_TYPE use_tagged_qng;
532 ASC_SCSI_BIT_ID_TYPE unit_not_ready;
533 ASC_SCSI_BIT_ID_TYPE queue_full_or_busy;
534 ASC_SCSI_BIT_ID_TYPE start_motor;
FUJITA Tomonori7d5d4082008-02-08 09:50:08 +0900535 uchar *overrun_buf;
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -0400536 dma_addr_t overrun_dma;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400537 uchar scsi_reset_wait;
538 uchar chip_no;
Hannes Reineckeae267592015-04-24 13:18:28 +0200539 bool is_in_int;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400540 uchar max_total_qng;
541 uchar cur_total_qng;
542 uchar in_critical_cnt;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400543 uchar last_q_shortage;
544 ushort init_state;
545 uchar cur_dvc_qng[ASC_MAX_TID + 1];
546 uchar max_dvc_qng[ASC_MAX_TID + 1];
547 ASC_SCSI_Q *scsiq_busy_head[ASC_MAX_TID + 1];
548 ASC_SCSI_Q *scsiq_busy_tail[ASC_MAX_TID + 1];
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -0400549 const uchar *sdtr_period_tbl;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400550 ASC_DVC_CFG *cfg;
551 ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer_always;
552 char redo_scam;
553 ushort res2;
554 uchar dos_int13_table[ASC_MAX_TID + 1];
Hannes Reinecke95cfab62015-04-24 13:18:27 +0200555 unsigned int max_dma_count;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400556 ASC_SCSI_BIT_ID_TYPE no_scam;
557 ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer;
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -0400558 uchar min_sdtr_index;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400559 uchar max_sdtr_index;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400560 struct asc_board *drv_ptr;
Hannes Reinecke95cfab62015-04-24 13:18:27 +0200561 unsigned int uc_break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562} ASC_DVC_VAR;
563
564typedef struct asc_dvc_inq_info {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400565 uchar type[ASC_MAX_TID + 1][ASC_MAX_LUN + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566} ASC_DVC_INQ_INFO;
567
568typedef struct asc_cap_info {
Hannes Reinecke95cfab62015-04-24 13:18:27 +0200569 u32 lba;
570 u32 blk_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571} ASC_CAP_INFO;
572
573typedef struct asc_cap_info_array {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400574 ASC_CAP_INFO cap_info[ASC_MAX_TID + 1][ASC_MAX_LUN + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575} ASC_CAP_INFO_ARRAY;
576
577#define ASC_MCNTL_NO_SEL_TIMEOUT (ushort)0x0001
578#define ASC_MCNTL_NULL_TARGET (ushort)0x0002
579#define ASC_CNTL_INITIATOR (ushort)0x0001
580#define ASC_CNTL_BIOS_GT_1GB (ushort)0x0002
581#define ASC_CNTL_BIOS_GT_2_DISK (ushort)0x0004
582#define ASC_CNTL_BIOS_REMOVABLE (ushort)0x0008
583#define ASC_CNTL_NO_SCAM (ushort)0x0010
584#define ASC_CNTL_INT_MULTI_Q (ushort)0x0080
585#define ASC_CNTL_NO_LUN_SUPPORT (ushort)0x0040
586#define ASC_CNTL_NO_VERIFY_COPY (ushort)0x0100
587#define ASC_CNTL_RESET_SCSI (ushort)0x0200
588#define ASC_CNTL_INIT_INQUIRY (ushort)0x0400
589#define ASC_CNTL_INIT_VERBOSE (ushort)0x0800
590#define ASC_CNTL_SCSI_PARITY (ushort)0x1000
591#define ASC_CNTL_BURST_MODE (ushort)0x2000
592#define ASC_CNTL_SDTR_ENABLE_ULTRA (ushort)0x4000
593#define ASC_EEP_DVC_CFG_BEG_VL 2
594#define ASC_EEP_MAX_DVC_ADDR_VL 15
595#define ASC_EEP_DVC_CFG_BEG 32
596#define ASC_EEP_MAX_DVC_ADDR 45
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597#define ASC_EEP_MAX_RETRY 20
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
599/*
600 * These macros keep the chip SCSI id and ISA DMA speed
601 * bitfields in board order. C bitfields aren't portable
602 * between big and little-endian platforms so they are
603 * not used.
604 */
605
606#define ASC_EEP_GET_CHIP_ID(cfg) ((cfg)->id_speed & 0x0f)
607#define ASC_EEP_GET_DMA_SPD(cfg) (((cfg)->id_speed & 0xf0) >> 4)
608#define ASC_EEP_SET_CHIP_ID(cfg, sid) \
609 ((cfg)->id_speed = ((cfg)->id_speed & 0xf0) | ((sid) & ASC_MAX_TID))
610#define ASC_EEP_SET_DMA_SPD(cfg, spd) \
611 ((cfg)->id_speed = ((cfg)->id_speed & 0x0f) | ((spd) & 0x0f) << 4)
612
613typedef struct asceep_config {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400614 ushort cfg_lsw;
615 ushort cfg_msw;
616 uchar init_sdtr;
617 uchar disc_enable;
618 uchar use_cmd_qng;
619 uchar start_motor;
620 uchar max_total_qng;
621 uchar max_tag_qng;
622 uchar bios_scan;
623 uchar power_up_wait;
624 uchar no_scam;
625 uchar id_speed; /* low order 4 bits is chip scsi id */
626 /* high order 4 bits is isa dma speed */
627 uchar dos_int13_table[ASC_MAX_TID + 1];
628 uchar adapter_info[6];
629 ushort cntl;
630 ushort chksum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631} ASCEEP_CONFIG;
632
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633#define ASC_EEP_CMD_READ 0x80
634#define ASC_EEP_CMD_WRITE 0x40
635#define ASC_EEP_CMD_WRITE_ABLE 0x30
636#define ASC_EEP_CMD_WRITE_DISABLE 0x00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637#define ASCV_MSGOUT_BEG 0x0000
638#define ASCV_MSGOUT_SDTR_PERIOD (ASCV_MSGOUT_BEG+3)
639#define ASCV_MSGOUT_SDTR_OFFSET (ASCV_MSGOUT_BEG+4)
640#define ASCV_BREAK_SAVED_CODE (ushort)0x0006
641#define ASCV_MSGIN_BEG (ASCV_MSGOUT_BEG+8)
642#define ASCV_MSGIN_SDTR_PERIOD (ASCV_MSGIN_BEG+3)
643#define ASCV_MSGIN_SDTR_OFFSET (ASCV_MSGIN_BEG+4)
644#define ASCV_SDTR_DATA_BEG (ASCV_MSGIN_BEG+8)
645#define ASCV_SDTR_DONE_BEG (ASCV_SDTR_DATA_BEG+8)
646#define ASCV_MAX_DVC_QNG_BEG (ushort)0x0020
647#define ASCV_BREAK_ADDR (ushort)0x0028
648#define ASCV_BREAK_NOTIFY_COUNT (ushort)0x002A
649#define ASCV_BREAK_CONTROL (ushort)0x002C
650#define ASCV_BREAK_HIT_COUNT (ushort)0x002E
651
652#define ASCV_ASCDVC_ERR_CODE_W (ushort)0x0030
653#define ASCV_MCODE_CHKSUM_W (ushort)0x0032
654#define ASCV_MCODE_SIZE_W (ushort)0x0034
655#define ASCV_STOP_CODE_B (ushort)0x0036
656#define ASCV_DVC_ERR_CODE_B (ushort)0x0037
657#define ASCV_OVERRUN_PADDR_D (ushort)0x0038
658#define ASCV_OVERRUN_BSIZE_D (ushort)0x003C
659#define ASCV_HALTCODE_W (ushort)0x0040
660#define ASCV_CHKSUM_W (ushort)0x0042
661#define ASCV_MC_DATE_W (ushort)0x0044
662#define ASCV_MC_VER_W (ushort)0x0046
663#define ASCV_NEXTRDY_B (ushort)0x0048
664#define ASCV_DONENEXT_B (ushort)0x0049
665#define ASCV_USE_TAGGED_QNG_B (ushort)0x004A
666#define ASCV_SCSIBUSY_B (ushort)0x004B
667#define ASCV_Q_DONE_IN_PROGRESS_B (ushort)0x004C
668#define ASCV_CURCDB_B (ushort)0x004D
669#define ASCV_RCLUN_B (ushort)0x004E
670#define ASCV_BUSY_QHEAD_B (ushort)0x004F
671#define ASCV_DISC1_QHEAD_B (ushort)0x0050
672#define ASCV_DISC_ENABLE_B (ushort)0x0052
673#define ASCV_CAN_TAGGED_QNG_B (ushort)0x0053
674#define ASCV_HOSTSCSI_ID_B (ushort)0x0055
675#define ASCV_MCODE_CNTL_B (ushort)0x0056
676#define ASCV_NULL_TARGET_B (ushort)0x0057
677#define ASCV_FREE_Q_HEAD_W (ushort)0x0058
678#define ASCV_DONE_Q_TAIL_W (ushort)0x005A
679#define ASCV_FREE_Q_HEAD_B (ushort)(ASCV_FREE_Q_HEAD_W+1)
680#define ASCV_DONE_Q_TAIL_B (ushort)(ASCV_DONE_Q_TAIL_W+1)
681#define ASCV_HOST_FLAG_B (ushort)0x005D
682#define ASCV_TOTAL_READY_Q_B (ushort)0x0064
683#define ASCV_VER_SERIAL_B (ushort)0x0065
684#define ASCV_HALTCODE_SAVED_W (ushort)0x0066
685#define ASCV_WTM_FLAG_B (ushort)0x0068
686#define ASCV_RISC_FLAG_B (ushort)0x006A
687#define ASCV_REQ_SG_LIST_QP (ushort)0x006B
688#define ASC_HOST_FLAG_IN_ISR 0x01
689#define ASC_HOST_FLAG_ACK_INT 0x02
690#define ASC_RISC_FLAG_GEN_INT 0x01
691#define ASC_RISC_FLAG_REQ_SG_LIST 0x02
692#define IOP_CTRL (0x0F)
693#define IOP_STATUS (0x0E)
694#define IOP_INT_ACK IOP_STATUS
695#define IOP_REG_IFC (0x0D)
696#define IOP_SYN_OFFSET (0x0B)
697#define IOP_EXTRA_CONTROL (0x0D)
698#define IOP_REG_PC (0x0C)
699#define IOP_RAM_ADDR (0x0A)
700#define IOP_RAM_DATA (0x08)
701#define IOP_EEP_DATA (0x06)
702#define IOP_EEP_CMD (0x07)
703#define IOP_VERSION (0x03)
704#define IOP_CONFIG_HIGH (0x04)
705#define IOP_CONFIG_LOW (0x02)
706#define IOP_SIG_BYTE (0x01)
707#define IOP_SIG_WORD (0x00)
708#define IOP_REG_DC1 (0x0E)
709#define IOP_REG_DC0 (0x0C)
710#define IOP_REG_SB (0x0B)
711#define IOP_REG_DA1 (0x0A)
712#define IOP_REG_DA0 (0x08)
713#define IOP_REG_SC (0x09)
714#define IOP_DMA_SPEED (0x07)
715#define IOP_REG_FLAG (0x07)
716#define IOP_FIFO_H (0x06)
717#define IOP_FIFO_L (0x04)
718#define IOP_REG_ID (0x05)
719#define IOP_REG_QP (0x03)
720#define IOP_REG_IH (0x02)
721#define IOP_REG_IX (0x01)
722#define IOP_REG_AX (0x00)
723#define IFC_REG_LOCK (0x00)
724#define IFC_REG_UNLOCK (0x09)
725#define IFC_WR_EN_FILTER (0x10)
726#define IFC_RD_NO_EEPROM (0x10)
727#define IFC_SLEW_RATE (0x20)
728#define IFC_ACT_NEG (0x40)
729#define IFC_INP_FILTER (0x80)
730#define IFC_INIT_DEFAULT (IFC_ACT_NEG | IFC_REG_UNLOCK)
731#define SC_SEL (uchar)(0x80)
732#define SC_BSY (uchar)(0x40)
733#define SC_ACK (uchar)(0x20)
734#define SC_REQ (uchar)(0x10)
735#define SC_ATN (uchar)(0x08)
736#define SC_IO (uchar)(0x04)
737#define SC_CD (uchar)(0x02)
738#define SC_MSG (uchar)(0x01)
739#define SEC_SCSI_CTL (uchar)(0x80)
740#define SEC_ACTIVE_NEGATE (uchar)(0x40)
741#define SEC_SLEW_RATE (uchar)(0x20)
742#define SEC_ENABLE_FILTER (uchar)(0x10)
743#define ASC_HALT_EXTMSG_IN (ushort)0x8000
744#define ASC_HALT_CHK_CONDITION (ushort)0x8100
745#define ASC_HALT_SS_QUEUE_FULL (ushort)0x8200
746#define ASC_HALT_DISABLE_ASYN_USE_SYN_FIX (ushort)0x8300
747#define ASC_HALT_ENABLE_ASYN_USE_SYN_FIX (ushort)0x8400
748#define ASC_HALT_SDTR_REJECTED (ushort)0x4000
749#define ASC_HALT_HOST_COPY_SG_LIST_TO_RISC ( ushort )0x2000
750#define ASC_MAX_QNO 0xF8
751#define ASC_DATA_SEC_BEG (ushort)0x0080
752#define ASC_DATA_SEC_END (ushort)0x0080
753#define ASC_CODE_SEC_BEG (ushort)0x0080
754#define ASC_CODE_SEC_END (ushort)0x0080
755#define ASC_QADR_BEG (0x4000)
756#define ASC_QADR_USED (ushort)(ASC_MAX_QNO * 64)
757#define ASC_QADR_END (ushort)0x7FFF
758#define ASC_QLAST_ADR (ushort)0x7FC0
759#define ASC_QBLK_SIZE 0x40
760#define ASC_BIOS_DATA_QBEG 0xF8
761#define ASC_MIN_ACTIVE_QNO 0x01
762#define ASC_QLINK_END 0xFF
763#define ASC_EEPROM_WORDS 0x10
764#define ASC_MAX_MGS_LEN 0x10
765#define ASC_BIOS_ADDR_DEF 0xDC00
766#define ASC_BIOS_SIZE 0x3800
767#define ASC_BIOS_RAM_OFF 0x3800
768#define ASC_BIOS_RAM_SIZE 0x800
769#define ASC_BIOS_MIN_ADDR 0xC000
770#define ASC_BIOS_MAX_ADDR 0xEC00
771#define ASC_BIOS_BANK_SIZE 0x0400
772#define ASC_MCODE_START_ADDR 0x0080
773#define ASC_CFG0_HOST_INT_ON 0x0020
774#define ASC_CFG0_BIOS_ON 0x0040
775#define ASC_CFG0_VERA_BURST_ON 0x0080
776#define ASC_CFG0_SCSI_PARITY_ON 0x0800
777#define ASC_CFG1_SCSI_TARGET_ON 0x0080
778#define ASC_CFG1_LRAM_8BITS_ON 0x0800
779#define ASC_CFG_MSW_CLR_MASK 0x3080
780#define CSW_TEST1 (ASC_CS_TYPE)0x8000
781#define CSW_AUTO_CONFIG (ASC_CS_TYPE)0x4000
782#define CSW_RESERVED1 (ASC_CS_TYPE)0x2000
783#define CSW_IRQ_WRITTEN (ASC_CS_TYPE)0x1000
784#define CSW_33MHZ_SELECTED (ASC_CS_TYPE)0x0800
785#define CSW_TEST2 (ASC_CS_TYPE)0x0400
786#define CSW_TEST3 (ASC_CS_TYPE)0x0200
787#define CSW_RESERVED2 (ASC_CS_TYPE)0x0100
788#define CSW_DMA_DONE (ASC_CS_TYPE)0x0080
789#define CSW_FIFO_RDY (ASC_CS_TYPE)0x0040
790#define CSW_EEP_READ_DONE (ASC_CS_TYPE)0x0020
791#define CSW_HALTED (ASC_CS_TYPE)0x0010
792#define CSW_SCSI_RESET_ACTIVE (ASC_CS_TYPE)0x0008
793#define CSW_PARITY_ERR (ASC_CS_TYPE)0x0004
794#define CSW_SCSI_RESET_LATCH (ASC_CS_TYPE)0x0002
795#define CSW_INT_PENDING (ASC_CS_TYPE)0x0001
796#define CIW_CLR_SCSI_RESET_INT (ASC_CS_TYPE)0x1000
797#define CIW_INT_ACK (ASC_CS_TYPE)0x0100
798#define CIW_TEST1 (ASC_CS_TYPE)0x0200
799#define CIW_TEST2 (ASC_CS_TYPE)0x0400
800#define CIW_SEL_33MHZ (ASC_CS_TYPE)0x0800
801#define CIW_IRQ_ACT (ASC_CS_TYPE)0x1000
802#define CC_CHIP_RESET (uchar)0x80
803#define CC_SCSI_RESET (uchar)0x40
804#define CC_HALT (uchar)0x20
805#define CC_SINGLE_STEP (uchar)0x10
806#define CC_DMA_ABLE (uchar)0x08
807#define CC_TEST (uchar)0x04
808#define CC_BANK_ONE (uchar)0x02
809#define CC_DIAG (uchar)0x01
810#define ASC_1000_ID0W 0x04C1
811#define ASC_1000_ID0W_FIX 0x00C1
812#define ASC_1000_ID1B 0x25
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813#define ASC_EISA_REV_IOP_MASK (0x0C83)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814#define ASC_EISA_CFG_IOP_MASK (0x0C86)
815#define ASC_GET_EISA_SLOT(iop) (PortAddr)((iop) & 0xF000)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816#define INS_HALTINT (ushort)0x6281
817#define INS_HALT (ushort)0x6280
818#define INS_SINT (ushort)0x6200
819#define INS_RFLAG_WTM (ushort)0x7380
820#define ASC_MC_SAVE_CODE_WSIZE 0x500
821#define ASC_MC_SAVE_DATA_WSIZE 0x40
822
823typedef struct asc_mc_saved {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400824 ushort data[ASC_MC_SAVE_DATA_WSIZE];
825 ushort code[ASC_MC_SAVE_CODE_WSIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826} ASC_MC_SAVED;
827
828#define AscGetQDoneInProgress(port) AscReadLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B)
829#define AscPutQDoneInProgress(port, val) AscWriteLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B, val)
830#define AscGetVarFreeQHead(port) AscReadLramWord((port), ASCV_FREE_Q_HEAD_W)
831#define AscGetVarDoneQTail(port) AscReadLramWord((port), ASCV_DONE_Q_TAIL_W)
832#define AscPutVarFreeQHead(port, val) AscWriteLramWord((port), ASCV_FREE_Q_HEAD_W, val)
833#define AscPutVarDoneQTail(port, val) AscWriteLramWord((port), ASCV_DONE_Q_TAIL_W, val)
834#define AscGetRiscVarFreeQHead(port) AscReadLramByte((port), ASCV_NEXTRDY_B)
835#define AscGetRiscVarDoneQTail(port) AscReadLramByte((port), ASCV_DONENEXT_B)
836#define AscPutRiscVarFreeQHead(port, val) AscWriteLramByte((port), ASCV_NEXTRDY_B, val)
837#define AscPutRiscVarDoneQTail(port, val) AscWriteLramByte((port), ASCV_DONENEXT_B, val)
Matthew Wilcox51219352007-10-02 21:55:22 -0400838#define AscPutMCodeSDTRDoneAtID(port, id, data) AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id), (data))
839#define AscGetMCodeSDTRDoneAtID(port, id) AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id))
840#define AscPutMCodeInitSDTRAtID(port, id, data) AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id), data)
841#define AscGetMCodeInitSDTRAtID(port, id) AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842#define AscGetChipSignatureByte(port) (uchar)inp((port)+IOP_SIG_BYTE)
843#define AscGetChipSignatureWord(port) (ushort)inpw((port)+IOP_SIG_WORD)
844#define AscGetChipVerNo(port) (uchar)inp((port)+IOP_VERSION)
845#define AscGetChipCfgLsw(port) (ushort)inpw((port)+IOP_CONFIG_LOW)
846#define AscGetChipCfgMsw(port) (ushort)inpw((port)+IOP_CONFIG_HIGH)
847#define AscSetChipCfgLsw(port, data) outpw((port)+IOP_CONFIG_LOW, data)
848#define AscSetChipCfgMsw(port, data) outpw((port)+IOP_CONFIG_HIGH, data)
849#define AscGetChipEEPCmd(port) (uchar)inp((port)+IOP_EEP_CMD)
850#define AscSetChipEEPCmd(port, data) outp((port)+IOP_EEP_CMD, data)
851#define AscGetChipEEPData(port) (ushort)inpw((port)+IOP_EEP_DATA)
852#define AscSetChipEEPData(port, data) outpw((port)+IOP_EEP_DATA, data)
853#define AscGetChipLramAddr(port) (ushort)inpw((PortAddr)((port)+IOP_RAM_ADDR))
854#define AscSetChipLramAddr(port, addr) outpw((PortAddr)((port)+IOP_RAM_ADDR), addr)
855#define AscGetChipLramData(port) (ushort)inpw((port)+IOP_RAM_DATA)
856#define AscSetChipLramData(port, data) outpw((port)+IOP_RAM_DATA, data)
857#define AscGetChipIFC(port) (uchar)inp((port)+IOP_REG_IFC)
858#define AscSetChipIFC(port, data) outp((port)+IOP_REG_IFC, data)
859#define AscGetChipStatus(port) (ASC_CS_TYPE)inpw((port)+IOP_STATUS)
860#define AscSetChipStatus(port, cs_val) outpw((port)+IOP_STATUS, cs_val)
861#define AscGetChipControl(port) (uchar)inp((port)+IOP_CTRL)
862#define AscSetChipControl(port, cc_val) outp((port)+IOP_CTRL, cc_val)
863#define AscGetChipSyn(port) (uchar)inp((port)+IOP_SYN_OFFSET)
864#define AscSetChipSyn(port, data) outp((port)+IOP_SYN_OFFSET, data)
865#define AscSetPCAddr(port, data) outpw((port)+IOP_REG_PC, data)
866#define AscGetPCAddr(port) (ushort)inpw((port)+IOP_REG_PC)
867#define AscIsIntPending(port) (AscGetChipStatus(port) & (CSW_INT_PENDING | CSW_SCSI_RESET_LATCH))
868#define AscGetChipScsiID(port) ((AscGetChipCfgLsw(port) >> 8) & ASC_MAX_TID)
869#define AscGetExtraControl(port) (uchar)inp((port)+IOP_EXTRA_CONTROL)
870#define AscSetExtraControl(port, data) outp((port)+IOP_EXTRA_CONTROL, data)
871#define AscReadChipAX(port) (ushort)inpw((port)+IOP_REG_AX)
872#define AscWriteChipAX(port, data) outpw((port)+IOP_REG_AX, data)
873#define AscReadChipIX(port) (uchar)inp((port)+IOP_REG_IX)
874#define AscWriteChipIX(port, data) outp((port)+IOP_REG_IX, data)
875#define AscReadChipIH(port) (ushort)inpw((port)+IOP_REG_IH)
876#define AscWriteChipIH(port, data) outpw((port)+IOP_REG_IH, data)
877#define AscReadChipQP(port) (uchar)inp((port)+IOP_REG_QP)
878#define AscWriteChipQP(port, data) outp((port)+IOP_REG_QP, data)
879#define AscReadChipFIFO_L(port) (ushort)inpw((port)+IOP_REG_FIFO_L)
880#define AscWriteChipFIFO_L(port, data) outpw((port)+IOP_REG_FIFO_L, data)
881#define AscReadChipFIFO_H(port) (ushort)inpw((port)+IOP_REG_FIFO_H)
882#define AscWriteChipFIFO_H(port, data) outpw((port)+IOP_REG_FIFO_H, data)
883#define AscReadChipDmaSpeed(port) (uchar)inp((port)+IOP_DMA_SPEED)
884#define AscWriteChipDmaSpeed(port, data) outp((port)+IOP_DMA_SPEED, data)
885#define AscReadChipDA0(port) (ushort)inpw((port)+IOP_REG_DA0)
886#define AscWriteChipDA0(port) outpw((port)+IOP_REG_DA0, data)
887#define AscReadChipDA1(port) (ushort)inpw((port)+IOP_REG_DA1)
888#define AscWriteChipDA1(port) outpw((port)+IOP_REG_DA1, data)
889#define AscReadChipDC0(port) (ushort)inpw((port)+IOP_REG_DC0)
890#define AscWriteChipDC0(port) outpw((port)+IOP_REG_DC0, data)
891#define AscReadChipDC1(port) (ushort)inpw((port)+IOP_REG_DC1)
892#define AscWriteChipDC1(port) outpw((port)+IOP_REG_DC1, data)
893#define AscReadChipDvcID(port) (uchar)inp((port)+IOP_REG_ID)
894#define AscWriteChipDvcID(port, data) outp((port)+IOP_REG_ID, data)
895
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 * These macros are used to convert a virtual address to a
898 * 32-bit value. This currently can be used on Linux Alpha
899 * which uses 64-bit virtual address but a 32-bit bus address.
900 * This is likely to break in the future, but doing this now
901 * will give us time to change the HW and FW to handle 64-bit
902 * addresses.
903 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904#define ADV_U32_TO_VADDR bus_to_virt
905
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400906#define AdvPortAddr void __iomem * /* Virtual memory address size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
908/*
909 * Define Adv Library required memory access macros.
910 */
911#define ADV_MEM_READB(addr) readb(addr)
912#define ADV_MEM_READW(addr) readw(addr)
913#define ADV_MEM_WRITEB(addr, byte) writeb(byte, addr)
914#define ADV_MEM_WRITEW(addr, word) writew(word, addr)
915#define ADV_MEM_WRITEDW(addr, dword) writel(dword, addr)
916
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 * Define total number of simultaneous maximum element scatter-gather
919 * request blocks per wide adapter. ASC_DEF_MAX_HOST_QNG (253) is the
920 * maximum number of outstanding commands per wide host adapter. Each
921 * command uses one or more ADV_SG_BLOCK each with 15 scatter-gather
922 * elements. Allow each command to have at least one ADV_SG_BLOCK structure.
923 * This allows about 15 commands to have the maximum 17 ADV_SG_BLOCK
924 * structures or 255 scatter-gather elements.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 */
926#define ADV_TOT_SG_BLOCK ASC_DEF_MAX_HOST_QNG
927
928/*
Matthew Wilcox98d41c22007-10-02 21:55:37 -0400929 * Define maximum number of scatter-gather elements per request.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 */
931#define ADV_MAX_SG_LIST 255
Matthew Wilcox98d41c22007-10-02 21:55:37 -0400932#define NO_OF_SG_PER_BLOCK 15
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934#define ADV_EEP_DVC_CFG_BEGIN (0x00)
935#define ADV_EEP_DVC_CFG_END (0x15)
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400936#define ADV_EEP_DVC_CTL_BEGIN (0x16) /* location of OEM name */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937#define ADV_EEP_MAX_WORD_ADDR (0x1E)
938
939#define ADV_EEP_DELAY_MS 100
940
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400941#define ADV_EEPROM_BIG_ENDIAN 0x8000 /* EEPROM Bit 15 */
942#define ADV_EEPROM_BIOS_ENABLE 0x4000 /* EEPROM Bit 14 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943/*
944 * For the ASC3550 Bit 13 is Termination Polarity control bit.
945 * For later ICs Bit 13 controls whether the CIS (Card Information
946 * Service Section) is loaded from EEPROM.
947 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400948#define ADV_EEPROM_TERM_POL 0x2000 /* EEPROM Bit 13 */
949#define ADV_EEPROM_CIS_LD 0x2000 /* EEPROM Bit 13 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950/*
951 * ASC38C1600 Bit 11
952 *
953 * If EEPROM Bit 11 is 0 for Function 0, then Function 0 will specify
954 * INT A in the PCI Configuration Space Int Pin field. If it is 1, then
955 * Function 0 will specify INT B.
956 *
957 * If EEPROM Bit 11 is 0 for Function 1, then Function 1 will specify
958 * INT B in the PCI Configuration Space Int Pin field. If it is 1, then
959 * Function 1 will specify INT A.
960 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400961#define ADV_EEPROM_INTAB 0x0800 /* EEPROM Bit 11 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400963typedef struct adveep_3550_config {
964 /* Word Offset, Description */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400966 ushort cfg_lsw; /* 00 power up initialization */
967 /* bit 13 set - Term Polarity Control */
968 /* bit 14 set - BIOS Enable */
969 /* bit 15 set - Big Endian Mode */
970 ushort cfg_msw; /* 01 unused */
971 ushort disc_enable; /* 02 disconnect enable */
972 ushort wdtr_able; /* 03 Wide DTR able */
973 ushort sdtr_able; /* 04 Synchronous DTR able */
974 ushort start_motor; /* 05 send start up motor */
975 ushort tagqng_able; /* 06 tag queuing able */
976 ushort bios_scan; /* 07 BIOS device control */
977 ushort scam_tolerant; /* 08 no scam */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400979 uchar adapter_scsi_id; /* 09 Host Adapter ID */
980 uchar bios_boot_delay; /* power up wait */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400982 uchar scsi_reset_delay; /* 10 reset delay */
983 uchar bios_id_lun; /* first boot device scsi id & lun */
984 /* high nibble is lun */
985 /* low nibble is scsi id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400987 uchar termination; /* 11 0 - automatic */
988 /* 1 - low off / high off */
989 /* 2 - low off / high on */
990 /* 3 - low on / high on */
991 /* There is no low on / high off */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400993 uchar reserved1; /* reserved byte (not used) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400995 ushort bios_ctrl; /* 12 BIOS control bits */
996 /* bit 0 BIOS don't act as initiator. */
997 /* bit 1 BIOS > 1 GB support */
998 /* bit 2 BIOS > 2 Disk Support */
999 /* bit 3 BIOS don't support removables */
1000 /* bit 4 BIOS support bootable CD */
1001 /* bit 5 BIOS scan enabled */
1002 /* bit 6 BIOS support multiple LUNs */
1003 /* bit 7 BIOS display of message */
1004 /* bit 8 SCAM disabled */
1005 /* bit 9 Reset SCSI bus during init. */
1006 /* bit 10 */
1007 /* bit 11 No verbose initialization. */
1008 /* bit 12 SCSI parity enabled */
1009 /* bit 13 */
1010 /* bit 14 */
1011 /* bit 15 */
1012 ushort ultra_able; /* 13 ULTRA speed able */
1013 ushort reserved2; /* 14 reserved */
1014 uchar max_host_qng; /* 15 maximum host queuing */
1015 uchar max_dvc_qng; /* maximum per device queuing */
1016 ushort dvc_cntl; /* 16 control bit for driver */
1017 ushort bug_fix; /* 17 control bit for bug fix */
1018 ushort serial_number_word1; /* 18 Board serial number word 1 */
1019 ushort serial_number_word2; /* 19 Board serial number word 2 */
1020 ushort serial_number_word3; /* 20 Board serial number word 3 */
1021 ushort check_sum; /* 21 EEP check sum */
1022 uchar oem_name[16]; /* 22 OEM name */
1023 ushort dvc_err_code; /* 30 last device driver error code */
1024 ushort adv_err_code; /* 31 last uc and Adv Lib error code */
1025 ushort adv_err_addr; /* 32 last uc error address */
1026 ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
1027 ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
1028 ushort saved_adv_err_addr; /* 35 saved last uc error address */
1029 ushort num_of_err; /* 36 number of error */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030} ADVEEP_3550_CONFIG;
1031
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001032typedef struct adveep_38C0800_config {
1033 /* Word Offset, Description */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001035 ushort cfg_lsw; /* 00 power up initialization */
1036 /* bit 13 set - Load CIS */
1037 /* bit 14 set - BIOS Enable */
1038 /* bit 15 set - Big Endian Mode */
1039 ushort cfg_msw; /* 01 unused */
1040 ushort disc_enable; /* 02 disconnect enable */
1041 ushort wdtr_able; /* 03 Wide DTR able */
1042 ushort sdtr_speed1; /* 04 SDTR Speed TID 0-3 */
1043 ushort start_motor; /* 05 send start up motor */
1044 ushort tagqng_able; /* 06 tag queuing able */
1045 ushort bios_scan; /* 07 BIOS device control */
1046 ushort scam_tolerant; /* 08 no scam */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001048 uchar adapter_scsi_id; /* 09 Host Adapter ID */
1049 uchar bios_boot_delay; /* power up wait */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001051 uchar scsi_reset_delay; /* 10 reset delay */
1052 uchar bios_id_lun; /* first boot device scsi id & lun */
1053 /* high nibble is lun */
1054 /* low nibble is scsi id */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001056 uchar termination_se; /* 11 0 - automatic */
1057 /* 1 - low off / high off */
1058 /* 2 - low off / high on */
1059 /* 3 - low on / high on */
1060 /* There is no low on / high off */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001062 uchar termination_lvd; /* 11 0 - automatic */
1063 /* 1 - low off / high off */
1064 /* 2 - low off / high on */
1065 /* 3 - low on / high on */
1066 /* There is no low on / high off */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001068 ushort bios_ctrl; /* 12 BIOS control bits */
1069 /* bit 0 BIOS don't act as initiator. */
1070 /* bit 1 BIOS > 1 GB support */
1071 /* bit 2 BIOS > 2 Disk Support */
1072 /* bit 3 BIOS don't support removables */
1073 /* bit 4 BIOS support bootable CD */
1074 /* bit 5 BIOS scan enabled */
1075 /* bit 6 BIOS support multiple LUNs */
1076 /* bit 7 BIOS display of message */
1077 /* bit 8 SCAM disabled */
1078 /* bit 9 Reset SCSI bus during init. */
1079 /* bit 10 */
1080 /* bit 11 No verbose initialization. */
1081 /* bit 12 SCSI parity enabled */
1082 /* bit 13 */
1083 /* bit 14 */
1084 /* bit 15 */
1085 ushort sdtr_speed2; /* 13 SDTR speed TID 4-7 */
1086 ushort sdtr_speed3; /* 14 SDTR speed TID 8-11 */
1087 uchar max_host_qng; /* 15 maximum host queueing */
1088 uchar max_dvc_qng; /* maximum per device queuing */
1089 ushort dvc_cntl; /* 16 control bit for driver */
1090 ushort sdtr_speed4; /* 17 SDTR speed 4 TID 12-15 */
1091 ushort serial_number_word1; /* 18 Board serial number word 1 */
1092 ushort serial_number_word2; /* 19 Board serial number word 2 */
1093 ushort serial_number_word3; /* 20 Board serial number word 3 */
1094 ushort check_sum; /* 21 EEP check sum */
1095 uchar oem_name[16]; /* 22 OEM name */
1096 ushort dvc_err_code; /* 30 last device driver error code */
1097 ushort adv_err_code; /* 31 last uc and Adv Lib error code */
1098 ushort adv_err_addr; /* 32 last uc error address */
1099 ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
1100 ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
1101 ushort saved_adv_err_addr; /* 35 saved last uc error address */
1102 ushort reserved36; /* 36 reserved */
1103 ushort reserved37; /* 37 reserved */
1104 ushort reserved38; /* 38 reserved */
1105 ushort reserved39; /* 39 reserved */
1106 ushort reserved40; /* 40 reserved */
1107 ushort reserved41; /* 41 reserved */
1108 ushort reserved42; /* 42 reserved */
1109 ushort reserved43; /* 43 reserved */
1110 ushort reserved44; /* 44 reserved */
1111 ushort reserved45; /* 45 reserved */
1112 ushort reserved46; /* 46 reserved */
1113 ushort reserved47; /* 47 reserved */
1114 ushort reserved48; /* 48 reserved */
1115 ushort reserved49; /* 49 reserved */
1116 ushort reserved50; /* 50 reserved */
1117 ushort reserved51; /* 51 reserved */
1118 ushort reserved52; /* 52 reserved */
1119 ushort reserved53; /* 53 reserved */
1120 ushort reserved54; /* 54 reserved */
1121 ushort reserved55; /* 55 reserved */
1122 ushort cisptr_lsw; /* 56 CIS PTR LSW */
1123 ushort cisprt_msw; /* 57 CIS PTR MSW */
1124 ushort subsysvid; /* 58 SubSystem Vendor ID */
1125 ushort subsysid; /* 59 SubSystem ID */
1126 ushort reserved60; /* 60 reserved */
1127 ushort reserved61; /* 61 reserved */
1128 ushort reserved62; /* 62 reserved */
1129 ushort reserved63; /* 63 reserved */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130} ADVEEP_38C0800_CONFIG;
1131
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001132typedef struct adveep_38C1600_config {
1133 /* Word Offset, Description */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001135 ushort cfg_lsw; /* 00 power up initialization */
1136 /* bit 11 set - Func. 0 INTB, Func. 1 INTA */
1137 /* clear - Func. 0 INTA, Func. 1 INTB */
1138 /* bit 13 set - Load CIS */
1139 /* bit 14 set - BIOS Enable */
1140 /* bit 15 set - Big Endian Mode */
1141 ushort cfg_msw; /* 01 unused */
1142 ushort disc_enable; /* 02 disconnect enable */
1143 ushort wdtr_able; /* 03 Wide DTR able */
1144 ushort sdtr_speed1; /* 04 SDTR Speed TID 0-3 */
1145 ushort start_motor; /* 05 send start up motor */
1146 ushort tagqng_able; /* 06 tag queuing able */
1147 ushort bios_scan; /* 07 BIOS device control */
1148 ushort scam_tolerant; /* 08 no scam */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001150 uchar adapter_scsi_id; /* 09 Host Adapter ID */
1151 uchar bios_boot_delay; /* power up wait */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001153 uchar scsi_reset_delay; /* 10 reset delay */
1154 uchar bios_id_lun; /* first boot device scsi id & lun */
1155 /* high nibble is lun */
1156 /* low nibble is scsi id */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001158 uchar termination_se; /* 11 0 - automatic */
1159 /* 1 - low off / high off */
1160 /* 2 - low off / high on */
1161 /* 3 - low on / high on */
1162 /* There is no low on / high off */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001164 uchar termination_lvd; /* 11 0 - automatic */
1165 /* 1 - low off / high off */
1166 /* 2 - low off / high on */
1167 /* 3 - low on / high on */
1168 /* There is no low on / high off */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001170 ushort bios_ctrl; /* 12 BIOS control bits */
1171 /* bit 0 BIOS don't act as initiator. */
1172 /* bit 1 BIOS > 1 GB support */
1173 /* bit 2 BIOS > 2 Disk Support */
1174 /* bit 3 BIOS don't support removables */
1175 /* bit 4 BIOS support bootable CD */
1176 /* bit 5 BIOS scan enabled */
1177 /* bit 6 BIOS support multiple LUNs */
1178 /* bit 7 BIOS display of message */
1179 /* bit 8 SCAM disabled */
1180 /* bit 9 Reset SCSI bus during init. */
1181 /* bit 10 Basic Integrity Checking disabled */
1182 /* bit 11 No verbose initialization. */
1183 /* bit 12 SCSI parity enabled */
1184 /* bit 13 AIPP (Asyn. Info. Ph. Prot.) dis. */
1185 /* bit 14 */
1186 /* bit 15 */
1187 ushort sdtr_speed2; /* 13 SDTR speed TID 4-7 */
1188 ushort sdtr_speed3; /* 14 SDTR speed TID 8-11 */
1189 uchar max_host_qng; /* 15 maximum host queueing */
1190 uchar max_dvc_qng; /* maximum per device queuing */
1191 ushort dvc_cntl; /* 16 control bit for driver */
1192 ushort sdtr_speed4; /* 17 SDTR speed 4 TID 12-15 */
1193 ushort serial_number_word1; /* 18 Board serial number word 1 */
1194 ushort serial_number_word2; /* 19 Board serial number word 2 */
1195 ushort serial_number_word3; /* 20 Board serial number word 3 */
1196 ushort check_sum; /* 21 EEP check sum */
1197 uchar oem_name[16]; /* 22 OEM name */
1198 ushort dvc_err_code; /* 30 last device driver error code */
1199 ushort adv_err_code; /* 31 last uc and Adv Lib error code */
1200 ushort adv_err_addr; /* 32 last uc error address */
1201 ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
1202 ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
1203 ushort saved_adv_err_addr; /* 35 saved last uc error address */
1204 ushort reserved36; /* 36 reserved */
1205 ushort reserved37; /* 37 reserved */
1206 ushort reserved38; /* 38 reserved */
1207 ushort reserved39; /* 39 reserved */
1208 ushort reserved40; /* 40 reserved */
1209 ushort reserved41; /* 41 reserved */
1210 ushort reserved42; /* 42 reserved */
1211 ushort reserved43; /* 43 reserved */
1212 ushort reserved44; /* 44 reserved */
1213 ushort reserved45; /* 45 reserved */
1214 ushort reserved46; /* 46 reserved */
1215 ushort reserved47; /* 47 reserved */
1216 ushort reserved48; /* 48 reserved */
1217 ushort reserved49; /* 49 reserved */
1218 ushort reserved50; /* 50 reserved */
1219 ushort reserved51; /* 51 reserved */
1220 ushort reserved52; /* 52 reserved */
1221 ushort reserved53; /* 53 reserved */
1222 ushort reserved54; /* 54 reserved */
1223 ushort reserved55; /* 55 reserved */
1224 ushort cisptr_lsw; /* 56 CIS PTR LSW */
1225 ushort cisprt_msw; /* 57 CIS PTR MSW */
1226 ushort subsysvid; /* 58 SubSystem Vendor ID */
1227 ushort subsysid; /* 59 SubSystem ID */
1228 ushort reserved60; /* 60 reserved */
1229 ushort reserved61; /* 61 reserved */
1230 ushort reserved62; /* 62 reserved */
1231 ushort reserved63; /* 63 reserved */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232} ADVEEP_38C1600_CONFIG;
1233
1234/*
1235 * EEPROM Commands
1236 */
1237#define ASC_EEP_CMD_DONE 0x0200
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238
1239/* bios_ctrl */
1240#define BIOS_CTRL_BIOS 0x0001
1241#define BIOS_CTRL_EXTENDED_XLAT 0x0002
1242#define BIOS_CTRL_GT_2_DISK 0x0004
1243#define BIOS_CTRL_BIOS_REMOVABLE 0x0008
1244#define BIOS_CTRL_BOOTABLE_CD 0x0010
1245#define BIOS_CTRL_MULTIPLE_LUN 0x0040
1246#define BIOS_CTRL_DISPLAY_MSG 0x0080
1247#define BIOS_CTRL_NO_SCAM 0x0100
1248#define BIOS_CTRL_RESET_SCSI_BUS 0x0200
1249#define BIOS_CTRL_INIT_VERBOSE 0x0800
1250#define BIOS_CTRL_SCSI_PARITY 0x1000
1251#define BIOS_CTRL_AIPP_DIS 0x2000
1252
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001253#define ADV_3550_MEMSIZE 0x2000 /* 8 KB Internal Memory */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001255#define ADV_38C0800_MEMSIZE 0x4000 /* 16 KB Internal Memory */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256
1257/*
1258 * XXX - Since ASC38C1600 Rev.3 has a local RAM failure issue, there is
1259 * a special 16K Adv Library and Microcode version. After the issue is
1260 * resolved, should restore 32K support.
1261 *
1262 * #define ADV_38C1600_MEMSIZE 0x8000L * 32 KB Internal Memory *
1263 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001264#define ADV_38C1600_MEMSIZE 0x4000 /* 16 KB Internal Memory */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265
1266/*
1267 * Byte I/O register address from base of 'iop_base'.
1268 */
1269#define IOPB_INTR_STATUS_REG 0x00
1270#define IOPB_CHIP_ID_1 0x01
1271#define IOPB_INTR_ENABLES 0x02
1272#define IOPB_CHIP_TYPE_REV 0x03
1273#define IOPB_RES_ADDR_4 0x04
1274#define IOPB_RES_ADDR_5 0x05
1275#define IOPB_RAM_DATA 0x06
1276#define IOPB_RES_ADDR_7 0x07
1277#define IOPB_FLAG_REG 0x08
1278#define IOPB_RES_ADDR_9 0x09
1279#define IOPB_RISC_CSR 0x0A
1280#define IOPB_RES_ADDR_B 0x0B
1281#define IOPB_RES_ADDR_C 0x0C
1282#define IOPB_RES_ADDR_D 0x0D
1283#define IOPB_SOFT_OVER_WR 0x0E
1284#define IOPB_RES_ADDR_F 0x0F
1285#define IOPB_MEM_CFG 0x10
1286#define IOPB_RES_ADDR_11 0x11
1287#define IOPB_GPIO_DATA 0x12
1288#define IOPB_RES_ADDR_13 0x13
1289#define IOPB_FLASH_PAGE 0x14
1290#define IOPB_RES_ADDR_15 0x15
1291#define IOPB_GPIO_CNTL 0x16
1292#define IOPB_RES_ADDR_17 0x17
1293#define IOPB_FLASH_DATA 0x18
1294#define IOPB_RES_ADDR_19 0x19
1295#define IOPB_RES_ADDR_1A 0x1A
1296#define IOPB_RES_ADDR_1B 0x1B
1297#define IOPB_RES_ADDR_1C 0x1C
1298#define IOPB_RES_ADDR_1D 0x1D
1299#define IOPB_RES_ADDR_1E 0x1E
1300#define IOPB_RES_ADDR_1F 0x1F
1301#define IOPB_DMA_CFG0 0x20
1302#define IOPB_DMA_CFG1 0x21
1303#define IOPB_TICKLE 0x22
1304#define IOPB_DMA_REG_WR 0x23
1305#define IOPB_SDMA_STATUS 0x24
1306#define IOPB_SCSI_BYTE_CNT 0x25
1307#define IOPB_HOST_BYTE_CNT 0x26
1308#define IOPB_BYTE_LEFT_TO_XFER 0x27
1309#define IOPB_BYTE_TO_XFER_0 0x28
1310#define IOPB_BYTE_TO_XFER_1 0x29
1311#define IOPB_BYTE_TO_XFER_2 0x2A
1312#define IOPB_BYTE_TO_XFER_3 0x2B
1313#define IOPB_ACC_GRP 0x2C
1314#define IOPB_RES_ADDR_2D 0x2D
1315#define IOPB_DEV_ID 0x2E
1316#define IOPB_RES_ADDR_2F 0x2F
1317#define IOPB_SCSI_DATA 0x30
1318#define IOPB_RES_ADDR_31 0x31
1319#define IOPB_RES_ADDR_32 0x32
1320#define IOPB_SCSI_DATA_HSHK 0x33
1321#define IOPB_SCSI_CTRL 0x34
1322#define IOPB_RES_ADDR_35 0x35
1323#define IOPB_RES_ADDR_36 0x36
1324#define IOPB_RES_ADDR_37 0x37
1325#define IOPB_RAM_BIST 0x38
1326#define IOPB_PLL_TEST 0x39
1327#define IOPB_PCI_INT_CFG 0x3A
1328#define IOPB_RES_ADDR_3B 0x3B
1329#define IOPB_RFIFO_CNT 0x3C
1330#define IOPB_RES_ADDR_3D 0x3D
1331#define IOPB_RES_ADDR_3E 0x3E
1332#define IOPB_RES_ADDR_3F 0x3F
1333
1334/*
1335 * Word I/O register address from base of 'iop_base'.
1336 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001337#define IOPW_CHIP_ID_0 0x00 /* CID0 */
1338#define IOPW_CTRL_REG 0x02 /* CC */
1339#define IOPW_RAM_ADDR 0x04 /* LA */
1340#define IOPW_RAM_DATA 0x06 /* LD */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341#define IOPW_RES_ADDR_08 0x08
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001342#define IOPW_RISC_CSR 0x0A /* CSR */
1343#define IOPW_SCSI_CFG0 0x0C /* CFG0 */
1344#define IOPW_SCSI_CFG1 0x0E /* CFG1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345#define IOPW_RES_ADDR_10 0x10
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001346#define IOPW_SEL_MASK 0x12 /* SM */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347#define IOPW_RES_ADDR_14 0x14
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001348#define IOPW_FLASH_ADDR 0x16 /* FA */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349#define IOPW_RES_ADDR_18 0x18
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001350#define IOPW_EE_CMD 0x1A /* EC */
1351#define IOPW_EE_DATA 0x1C /* ED */
1352#define IOPW_SFIFO_CNT 0x1E /* SFC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353#define IOPW_RES_ADDR_20 0x20
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001354#define IOPW_Q_BASE 0x22 /* QB */
1355#define IOPW_QP 0x24 /* QP */
1356#define IOPW_IX 0x26 /* IX */
1357#define IOPW_SP 0x28 /* SP */
1358#define IOPW_PC 0x2A /* PC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359#define IOPW_RES_ADDR_2C 0x2C
1360#define IOPW_RES_ADDR_2E 0x2E
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001361#define IOPW_SCSI_DATA 0x30 /* SD */
1362#define IOPW_SCSI_DATA_HSHK 0x32 /* SDH */
1363#define IOPW_SCSI_CTRL 0x34 /* SC */
1364#define IOPW_HSHK_CFG 0x36 /* HCFG */
1365#define IOPW_SXFR_STATUS 0x36 /* SXS */
1366#define IOPW_SXFR_CNTL 0x38 /* SXL */
1367#define IOPW_SXFR_CNTH 0x3A /* SXH */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368#define IOPW_RES_ADDR_3C 0x3C
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001369#define IOPW_RFIFO_DATA 0x3E /* RFD */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370
1371/*
1372 * Doubleword I/O register address from base of 'iop_base'.
1373 */
1374#define IOPDW_RES_ADDR_0 0x00
1375#define IOPDW_RAM_DATA 0x04
1376#define IOPDW_RES_ADDR_8 0x08
1377#define IOPDW_RES_ADDR_C 0x0C
1378#define IOPDW_RES_ADDR_10 0x10
1379#define IOPDW_COMMA 0x14
1380#define IOPDW_COMMB 0x18
1381#define IOPDW_RES_ADDR_1C 0x1C
1382#define IOPDW_SDMA_ADDR0 0x20
1383#define IOPDW_SDMA_ADDR1 0x24
1384#define IOPDW_SDMA_COUNT 0x28
1385#define IOPDW_SDMA_ERROR 0x2C
1386#define IOPDW_RDMA_ADDR0 0x30
1387#define IOPDW_RDMA_ADDR1 0x34
1388#define IOPDW_RDMA_COUNT 0x38
1389#define IOPDW_RDMA_ERROR 0x3C
1390
1391#define ADV_CHIP_ID_BYTE 0x25
1392#define ADV_CHIP_ID_WORD 0x04C1
1393
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394#define ADV_INTR_ENABLE_HOST_INTR 0x01
1395#define ADV_INTR_ENABLE_SEL_INTR 0x02
1396#define ADV_INTR_ENABLE_DPR_INTR 0x04
1397#define ADV_INTR_ENABLE_RTA_INTR 0x08
1398#define ADV_INTR_ENABLE_RMA_INTR 0x10
1399#define ADV_INTR_ENABLE_RST_INTR 0x20
1400#define ADV_INTR_ENABLE_DPE_INTR 0x40
1401#define ADV_INTR_ENABLE_GLOBAL_INTR 0x80
1402
1403#define ADV_INTR_STATUS_INTRA 0x01
1404#define ADV_INTR_STATUS_INTRB 0x02
1405#define ADV_INTR_STATUS_INTRC 0x04
1406
1407#define ADV_RISC_CSR_STOP (0x0000)
1408#define ADV_RISC_TEST_COND (0x2000)
1409#define ADV_RISC_CSR_RUN (0x4000)
1410#define ADV_RISC_CSR_SINGLE_STEP (0x8000)
1411
1412#define ADV_CTRL_REG_HOST_INTR 0x0100
1413#define ADV_CTRL_REG_SEL_INTR 0x0200
1414#define ADV_CTRL_REG_DPR_INTR 0x0400
1415#define ADV_CTRL_REG_RTA_INTR 0x0800
1416#define ADV_CTRL_REG_RMA_INTR 0x1000
1417#define ADV_CTRL_REG_RES_BIT14 0x2000
1418#define ADV_CTRL_REG_DPE_INTR 0x4000
1419#define ADV_CTRL_REG_POWER_DONE 0x8000
1420#define ADV_CTRL_REG_ANY_INTR 0xFF00
1421
1422#define ADV_CTRL_REG_CMD_RESET 0x00C6
1423#define ADV_CTRL_REG_CMD_WR_IO_REG 0x00C5
1424#define ADV_CTRL_REG_CMD_RD_IO_REG 0x00C4
1425#define ADV_CTRL_REG_CMD_WR_PCI_CFG_SPACE 0x00C3
1426#define ADV_CTRL_REG_CMD_RD_PCI_CFG_SPACE 0x00C2
1427
1428#define ADV_TICKLE_NOP 0x00
1429#define ADV_TICKLE_A 0x01
1430#define ADV_TICKLE_B 0x02
1431#define ADV_TICKLE_C 0x03
1432
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433#define AdvIsIntPending(port) \
1434 (AdvReadWordRegister(port, IOPW_CTRL_REG) & ADV_CTRL_REG_HOST_INTR)
1435
1436/*
1437 * SCSI_CFG0 Register bit definitions
1438 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001439#define TIMER_MODEAB 0xC000 /* Watchdog, Second, and Select. Timer Ctrl. */
1440#define PARITY_EN 0x2000 /* Enable SCSI Parity Error detection */
1441#define EVEN_PARITY 0x1000 /* Select Even Parity */
1442#define WD_LONG 0x0800 /* Watchdog Interval, 1: 57 min, 0: 13 sec */
1443#define QUEUE_128 0x0400 /* Queue Size, 1: 128 byte, 0: 64 byte */
1444#define PRIM_MODE 0x0100 /* Primitive SCSI mode */
1445#define SCAM_EN 0x0080 /* Enable SCAM selection */
1446#define SEL_TMO_LONG 0x0040 /* Sel/Resel Timeout, 1: 400 ms, 0: 1.6 ms */
1447#define CFRM_ID 0x0020 /* SCAM id sel. confirm., 1: fast, 0: 6.4 ms */
1448#define OUR_ID_EN 0x0010 /* Enable OUR_ID bits */
1449#define OUR_ID 0x000F /* SCSI ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
1451/*
1452 * SCSI_CFG1 Register bit definitions
1453 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001454#define BIG_ENDIAN 0x8000 /* Enable Big Endian Mode MIO:15, EEP:15 */
1455#define TERM_POL 0x2000 /* Terminator Polarity Ctrl. MIO:13, EEP:13 */
1456#define SLEW_RATE 0x1000 /* SCSI output buffer slew rate */
1457#define FILTER_SEL 0x0C00 /* Filter Period Selection */
1458#define FLTR_DISABLE 0x0000 /* Input Filtering Disabled */
1459#define FLTR_11_TO_20NS 0x0800 /* Input Filtering 11ns to 20ns */
1460#define FLTR_21_TO_39NS 0x0C00 /* Input Filtering 21ns to 39ns */
1461#define ACTIVE_DBL 0x0200 /* Disable Active Negation */
1462#define DIFF_MODE 0x0100 /* SCSI differential Mode (Read-Only) */
1463#define DIFF_SENSE 0x0080 /* 1: No SE cables, 0: SE cable (Read-Only) */
1464#define TERM_CTL_SEL 0x0040 /* Enable TERM_CTL_H and TERM_CTL_L */
1465#define TERM_CTL 0x0030 /* External SCSI Termination Bits */
1466#define TERM_CTL_H 0x0020 /* Enable External SCSI Upper Termination */
1467#define TERM_CTL_L 0x0010 /* Enable External SCSI Lower Termination */
1468#define CABLE_DETECT 0x000F /* External SCSI Cable Connection Status */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
1470/*
1471 * Addendum for ASC-38C0800 Chip
1472 *
1473 * The ASC-38C1600 Chip uses the same definitions except that the
1474 * bus mode override bits [12:10] have been moved to byte register
1475 * offset 0xE (IOPB_SOFT_OVER_WR) bits [12:10]. The [12:10] bits in
1476 * SCSI_CFG1 are read-only and always available. Bit 14 (DIS_TERM_DRV)
1477 * is not needed. The [12:10] bits in IOPB_SOFT_OVER_WR are write-only.
1478 * Also each ASC-38C1600 function or channel uses only cable bits [5:4]
1479 * and [1:0]. Bits [14], [7:6], [3:2] are unused.
1480 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001481#define DIS_TERM_DRV 0x4000 /* 1: Read c_det[3:0], 0: cannot read */
1482#define HVD_LVD_SE 0x1C00 /* Device Detect Bits */
1483#define HVD 0x1000 /* HVD Device Detect */
1484#define LVD 0x0800 /* LVD Device Detect */
1485#define SE 0x0400 /* SE Device Detect */
1486#define TERM_LVD 0x00C0 /* LVD Termination Bits */
1487#define TERM_LVD_HI 0x0080 /* Enable LVD Upper Termination */
1488#define TERM_LVD_LO 0x0040 /* Enable LVD Lower Termination */
1489#define TERM_SE 0x0030 /* SE Termination Bits */
1490#define TERM_SE_HI 0x0020 /* Enable SE Upper Termination */
1491#define TERM_SE_LO 0x0010 /* Enable SE Lower Termination */
1492#define C_DET_LVD 0x000C /* LVD Cable Detect Bits */
1493#define C_DET3 0x0008 /* Cable Detect for LVD External Wide */
1494#define C_DET2 0x0004 /* Cable Detect for LVD Internal Wide */
1495#define C_DET_SE 0x0003 /* SE Cable Detect Bits */
1496#define C_DET1 0x0002 /* Cable Detect for SE Internal Wide */
1497#define C_DET0 0x0001 /* Cable Detect for SE Internal Narrow */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498
1499#define CABLE_ILLEGAL_A 0x7
1500 /* x 0 0 0 | on on | Illegal (all 3 connectors are used) */
1501
1502#define CABLE_ILLEGAL_B 0xB
1503 /* 0 x 0 0 | on on | Illegal (all 3 connectors are used) */
1504
1505/*
1506 * MEM_CFG Register bit definitions
1507 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001508#define BIOS_EN 0x40 /* BIOS Enable MIO:14,EEP:14 */
1509#define FAST_EE_CLK 0x20 /* Diagnostic Bit */
1510#define RAM_SZ 0x1C /* Specify size of RAM to RISC */
1511#define RAM_SZ_2KB 0x00 /* 2 KB */
1512#define RAM_SZ_4KB 0x04 /* 4 KB */
1513#define RAM_SZ_8KB 0x08 /* 8 KB */
1514#define RAM_SZ_16KB 0x0C /* 16 KB */
1515#define RAM_SZ_32KB 0x10 /* 32 KB */
1516#define RAM_SZ_64KB 0x14 /* 64 KB */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517
1518/*
1519 * DMA_CFG0 Register bit definitions
1520 *
1521 * This register is only accessible to the host.
1522 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001523#define BC_THRESH_ENB 0x80 /* PCI DMA Start Conditions */
1524#define FIFO_THRESH 0x70 /* PCI DMA FIFO Threshold */
1525#define FIFO_THRESH_16B 0x00 /* 16 bytes */
1526#define FIFO_THRESH_32B 0x20 /* 32 bytes */
1527#define FIFO_THRESH_48B 0x30 /* 48 bytes */
1528#define FIFO_THRESH_64B 0x40 /* 64 bytes */
1529#define FIFO_THRESH_80B 0x50 /* 80 bytes (default) */
1530#define FIFO_THRESH_96B 0x60 /* 96 bytes */
1531#define FIFO_THRESH_112B 0x70 /* 112 bytes */
1532#define START_CTL 0x0C /* DMA start conditions */
1533#define START_CTL_TH 0x00 /* Wait threshold level (default) */
1534#define START_CTL_ID 0x04 /* Wait SDMA/SBUS idle */
1535#define START_CTL_THID 0x08 /* Wait threshold and SDMA/SBUS idle */
1536#define START_CTL_EMFU 0x0C /* Wait SDMA FIFO empty/full */
1537#define READ_CMD 0x03 /* Memory Read Method */
1538#define READ_CMD_MR 0x00 /* Memory Read */
1539#define READ_CMD_MRL 0x02 /* Memory Read Long */
1540#define READ_CMD_MRM 0x03 /* Memory Read Multiple (default) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541
1542/*
1543 * ASC-38C0800 RAM BIST Register bit definitions
1544 */
1545#define RAM_TEST_MODE 0x80
1546#define PRE_TEST_MODE 0x40
1547#define NORMAL_MODE 0x00
1548#define RAM_TEST_DONE 0x10
1549#define RAM_TEST_STATUS 0x0F
1550#define RAM_TEST_HOST_ERROR 0x08
1551#define RAM_TEST_INTRAM_ERROR 0x04
1552#define RAM_TEST_RISC_ERROR 0x02
1553#define RAM_TEST_SCSI_ERROR 0x01
1554#define RAM_TEST_SUCCESS 0x00
1555#define PRE_TEST_VALUE 0x05
1556#define NORMAL_VALUE 0x00
1557
1558/*
1559 * ASC38C1600 Definitions
1560 *
1561 * IOPB_PCI_INT_CFG Bit Field Definitions
1562 */
1563
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001564#define INTAB_LD 0x80 /* Value loaded from EEPROM Bit 11. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
1566/*
1567 * Bit 1 can be set to change the interrupt for the Function to operate in
1568 * Totem Pole mode. By default Bit 1 is 0 and the interrupt operates in
1569 * Open Drain mode. Both functions of the ASC38C1600 must be set to the same
1570 * mode, otherwise the operating mode is undefined.
1571 */
1572#define TOTEMPOLE 0x02
1573
1574/*
1575 * Bit 0 can be used to change the Int Pin for the Function. The value is
1576 * 0 by default for both Functions with Function 0 using INT A and Function
1577 * B using INT B. For Function 0 if set, INT B is used. For Function 1 if set,
1578 * INT A is used.
1579 *
1580 * EEPROM Word 0 Bit 11 for each Function may change the initial Int Pin
1581 * value specified in the PCI Configuration Space.
1582 */
1583#define INTAB 0x01
1584
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585/*
1586 * Adv Library Status Definitions
1587 */
1588#define ADV_TRUE 1
1589#define ADV_FALSE 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590#define ADV_SUCCESS 1
1591#define ADV_BUSY 0
1592#define ADV_ERROR (-1)
1593
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594/*
1595 * ADV_DVC_VAR 'warn_code' values
1596 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001597#define ASC_WARN_BUSRESET_ERROR 0x0001 /* SCSI Bus Reset error */
1598#define ASC_WARN_EEPROM_CHKSUM 0x0002 /* EEP check sum error */
1599#define ASC_WARN_EEPROM_TERMINATION 0x0004 /* EEP termination bad field */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001600#define ASC_WARN_ERROR 0xFFFF /* ADV_ERROR return */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001602#define ADV_MAX_TID 15 /* max. target identifier */
1603#define ADV_MAX_LUN 7 /* max. logical unit number */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604
1605/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 * Fixed locations of microcode operating variables.
1607 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001608#define ASC_MC_CODE_BEGIN_ADDR 0x0028 /* microcode start address */
1609#define ASC_MC_CODE_END_ADDR 0x002A /* microcode end address */
1610#define ASC_MC_CODE_CHK_SUM 0x002C /* microcode code checksum */
1611#define ASC_MC_VERSION_DATE 0x0038 /* microcode version */
1612#define ASC_MC_VERSION_NUM 0x003A /* microcode number */
1613#define ASC_MC_BIOSMEM 0x0040 /* BIOS RISC Memory Start */
1614#define ASC_MC_BIOSLEN 0x0050 /* BIOS RISC Memory Length */
1615#define ASC_MC_BIOS_SIGNATURE 0x0058 /* BIOS Signature 0x55AA */
1616#define ASC_MC_BIOS_VERSION 0x005A /* BIOS Version (2 bytes) */
1617#define ASC_MC_SDTR_SPEED1 0x0090 /* SDTR Speed for TID 0-3 */
1618#define ASC_MC_SDTR_SPEED2 0x0092 /* SDTR Speed for TID 4-7 */
1619#define ASC_MC_SDTR_SPEED3 0x0094 /* SDTR Speed for TID 8-11 */
1620#define ASC_MC_SDTR_SPEED4 0x0096 /* SDTR Speed for TID 12-15 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621#define ASC_MC_CHIP_TYPE 0x009A
1622#define ASC_MC_INTRB_CODE 0x009B
1623#define ASC_MC_WDTR_ABLE 0x009C
1624#define ASC_MC_SDTR_ABLE 0x009E
1625#define ASC_MC_TAGQNG_ABLE 0x00A0
1626#define ASC_MC_DISC_ENABLE 0x00A2
1627#define ASC_MC_IDLE_CMD_STATUS 0x00A4
1628#define ASC_MC_IDLE_CMD 0x00A6
1629#define ASC_MC_IDLE_CMD_PARAMETER 0x00A8
1630#define ASC_MC_DEFAULT_SCSI_CFG0 0x00AC
1631#define ASC_MC_DEFAULT_SCSI_CFG1 0x00AE
1632#define ASC_MC_DEFAULT_MEM_CFG 0x00B0
1633#define ASC_MC_DEFAULT_SEL_MASK 0x00B2
1634#define ASC_MC_SDTR_DONE 0x00B6
1635#define ASC_MC_NUMBER_OF_QUEUED_CMD 0x00C0
1636#define ASC_MC_NUMBER_OF_MAX_CMD 0x00D0
1637#define ASC_MC_DEVICE_HSHK_CFG_TABLE 0x0100
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001638#define ASC_MC_CONTROL_FLAG 0x0122 /* Microcode control flag. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639#define ASC_MC_WDTR_DONE 0x0124
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001640#define ASC_MC_CAM_MODE_MASK 0x015E /* CAM mode TID bitmask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641#define ASC_MC_ICQ 0x0160
1642#define ASC_MC_IRQ 0x0164
1643#define ASC_MC_PPR_ABLE 0x017A
1644
1645/*
1646 * BIOS LRAM variable absolute offsets.
1647 */
1648#define BIOS_CODESEG 0x54
1649#define BIOS_CODELEN 0x56
1650#define BIOS_SIGNATURE 0x58
1651#define BIOS_VERSION 0x5A
1652
1653/*
1654 * Microcode Control Flags
1655 *
1656 * Flags set by the Adv Library in RISC variable 'control_flag' (0x122)
1657 * and handled by the microcode.
1658 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001659#define CONTROL_FLAG_IGNORE_PERR 0x0001 /* Ignore DMA Parity Errors */
1660#define CONTROL_FLAG_ENABLE_AIPP 0x0002 /* Enabled AIPP checking. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661
1662/*
1663 * ASC_MC_DEVICE_HSHK_CFG_TABLE microcode table or HSHK_CFG register format
1664 */
1665#define HSHK_CFG_WIDE_XFR 0x8000
1666#define HSHK_CFG_RATE 0x0F00
1667#define HSHK_CFG_OFFSET 0x001F
1668
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001669#define ASC_DEF_MAX_HOST_QNG 0xFD /* Max. number of host commands (253) */
1670#define ASC_DEF_MIN_HOST_QNG 0x10 /* Min. number of host commands (16) */
1671#define ASC_DEF_MAX_DVC_QNG 0x3F /* Max. number commands per device (63) */
1672#define ASC_DEF_MIN_DVC_QNG 0x04 /* Min. number commands per device (4) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001674#define ASC_QC_DATA_CHECK 0x01 /* Require ASC_QC_DATA_OUT set or clear. */
1675#define ASC_QC_DATA_OUT 0x02 /* Data out DMA transfer. */
1676#define ASC_QC_START_MOTOR 0x04 /* Send auto-start motor before request. */
1677#define ASC_QC_NO_OVERRUN 0x08 /* Don't report overrun. */
1678#define ASC_QC_FREEZE_TIDQ 0x10 /* Freeze TID queue after request. XXX TBD */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001680#define ASC_QSC_NO_DISC 0x01 /* Don't allow disconnect for request. */
1681#define ASC_QSC_NO_TAGMSG 0x02 /* Don't allow tag queuing for request. */
1682#define ASC_QSC_NO_SYNC 0x04 /* Don't use Synch. transfer on request. */
1683#define ASC_QSC_NO_WIDE 0x08 /* Don't use Wide transfer on request. */
1684#define ASC_QSC_REDO_DTR 0x10 /* Renegotiate WDTR/SDTR before request. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685/*
1686 * Note: If a Tag Message is to be sent and neither ASC_QSC_HEAD_TAG or
1687 * ASC_QSC_ORDERED_TAG is set, then a Simple Tag Message (0x20) is used.
1688 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001689#define ASC_QSC_HEAD_TAG 0x40 /* Use Head Tag Message (0x21). */
1690#define ASC_QSC_ORDERED_TAG 0x80 /* Use Ordered Tag Message (0x22). */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691
1692/*
1693 * All fields here are accessed by the board microcode and need to be
1694 * little-endian.
1695 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001696typedef struct adv_carr_t {
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001697 __le32 carr_va; /* Carrier Virtual Address */
1698 __le32 carr_pa; /* Carrier Physical Address */
Hannes Reinecke9fef6ba2015-04-24 13:18:33 +02001699 __le32 areq_vpa; /* ADV_SCSI_REQ_Q Virtual or Physical Address */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001700 /*
1701 * next_vpa [31:4] Carrier Virtual or Physical Next Pointer
1702 *
1703 * next_vpa [3:1] Reserved Bits
1704 * next_vpa [0] Done Flag set in Response Queue.
1705 */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001706 __le32 next_vpa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707} ADV_CARR_T;
1708
1709/*
1710 * Mask used to eliminate low 4 bits of carrier 'next_vpa' field.
1711 */
1712#define ASC_NEXT_VPA_MASK 0xFFFFFFF0
1713
1714#define ASC_RQ_DONE 0x00000001
1715#define ASC_RQ_GOOD 0x00000002
1716#define ASC_CQ_STOPPER 0x00000000
1717
1718#define ASC_GET_CARRP(carrp) ((carrp) & ASC_NEXT_VPA_MASK)
1719
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001720/*
1721 * Each carrier is 64 bytes, and we need three additional
1722 * carrier for icq, irq, and the termination carrier.
1723 */
1724#define ADV_CARRIER_COUNT (ASC_DEF_MAX_HOST_QNG + 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725
1726#define ADV_CARRIER_BUFSIZE \
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001727 (ADV_CARRIER_COUNT * sizeof(ADV_CARR_T))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728
1729/*
Hannes Reinecke9fef6ba2015-04-24 13:18:33 +02001730 * ADV_SCSI_REQ_Q 'a_flag' definitions
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 *
1732 * The Adv Library should limit use to the lower nibble (4 bits) of
1733 * a_flag. Drivers are free to use the upper nibble (4 bits) of a_flag.
1734 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001735#define ADV_POLL_REQUEST 0x01 /* poll for request completion */
1736#define ADV_SCSIQ_DONE 0x02 /* request done */
1737#define ADV_DONT_RETRY 0x08 /* don't do retry */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001739#define ADV_CHIP_ASC3550 0x01 /* Ultra-Wide IC */
1740#define ADV_CHIP_ASC38C0800 0x02 /* Ultra2-Wide/LVD IC */
1741#define ADV_CHIP_ASC38C1600 0x03 /* Ultra3-Wide/LVD2 IC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742
1743/*
1744 * Adapter temporary configuration structure
1745 *
1746 * This structure can be discarded after initialization. Don't add
1747 * fields here needed after initialization.
1748 *
1749 * Field naming convention:
1750 *
1751 * *_enable indicates the field enables or disables a feature. The
1752 * value of the field is never reset.
1753 */
1754typedef struct adv_dvc_cfg {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001755 ushort disc_enable; /* enable disconnection */
1756 uchar chip_version; /* chip version */
1757 uchar termination; /* Term. Ctrl. bits 6-5 of SCSI_CFG1 register */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001758 ushort control_flag; /* Microcode Control Flag */
1759 ushort mcode_date; /* Microcode date */
1760 ushort mcode_version; /* Microcode version */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001761 ushort serial1; /* EEPROM serial number word 1 */
1762 ushort serial2; /* EEPROM serial number word 2 */
1763 ushort serial3; /* EEPROM serial number word 3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764} ADV_DVC_CFG;
1765
1766struct adv_dvc_var;
1767struct adv_scsi_req_q;
1768
Hannes Reinecke0ce53822015-04-24 13:18:25 +02001769typedef struct adv_sg_block {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001770 uchar reserved1;
1771 uchar reserved2;
1772 uchar reserved3;
1773 uchar sg_cnt; /* Valid entries in block. */
Hannes Reinecke0ce53822015-04-24 13:18:25 +02001774 __le32 sg_ptr; /* Pointer to next sg block. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001775 struct {
Hannes Reinecke0ce53822015-04-24 13:18:25 +02001776 __le32 sg_addr; /* SG element address. */
1777 __le32 sg_count; /* SG element count. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001778 } sg_list[NO_OF_SG_PER_BLOCK];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779} ADV_SG_BLOCK;
1780
1781/*
1782 * ADV_SCSI_REQ_Q - microcode request structure
1783 *
1784 * All fields in this structure up to byte 60 are used by the microcode.
1785 * The microcode makes assumptions about the size and ordering of fields
1786 * in this structure. Do not change the structure definition here without
1787 * coordinating the change with the microcode.
1788 *
1789 * All fields accessed by microcode must be maintained in little_endian
1790 * order.
1791 */
1792typedef struct adv_scsi_req_q {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001793 uchar cntl; /* Ucode flags and state (ASC_MC_QC_*). */
1794 uchar target_cmd;
1795 uchar target_id; /* Device target identifier. */
1796 uchar target_lun; /* Device target logical unit number. */
Hannes Reinecke95cfab62015-04-24 13:18:27 +02001797 __le32 data_addr; /* Data buffer physical address. */
1798 __le32 data_cnt; /* Data count. Ucode sets to residual. */
Hannes Reinecke811ddc02015-04-24 13:18:22 +02001799 __le32 sense_addr;
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001800 __le32 carr_pa;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001801 uchar mflag;
1802 uchar sense_len;
1803 uchar cdb_len; /* SCSI CDB length. Must <= 16 bytes. */
1804 uchar scsi_cntl;
1805 uchar done_status; /* Completion status. */
1806 uchar scsi_status; /* SCSI status byte. */
1807 uchar host_status; /* Ucode host status. */
1808 uchar sg_working_ix;
1809 uchar cdb[12]; /* SCSI CDB bytes 0-11. */
Hannes Reinecke95cfab62015-04-24 13:18:27 +02001810 __le32 sg_real_addr; /* SG list physical address. */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001811 __le32 scsiq_rptr;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001812 uchar cdb16[4]; /* SCSI CDB bytes 12-15. */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001813 __le32 scsiq_ptr;
1814 __le32 carr_va;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001815 /*
1816 * End of microcode structure - 60 bytes. The rest of the structure
1817 * is used by the Adv Library and ignored by the microcode.
1818 */
Hannes Reinecke9c17c622015-04-24 13:18:21 +02001819 u32 srb_tag;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001820 uchar a_flag;
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001821 uchar pad[3]; /* Pad out to a word boundary. */
1822 ADV_SG_BLOCK *sg_list_ptr; /* SG list virtual address. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823} ADV_SCSI_REQ_Q;
1824
1825/*
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001826 * The following two structures are used to process Wide Board requests.
1827 *
1828 * The ADV_SCSI_REQ_Q structure in adv_req_t is passed to the Adv Library
Hannes Reinecke9c17c622015-04-24 13:18:21 +02001829 * and microcode with the ADV_SCSI_REQ_Q field 'srb_tag' set to the
1830 * SCSI request tag. The adv_req_t structure 'cmndp' field in turn points
1831 * to the Mid-Level SCSI request structure.
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001832 *
1833 * Zero or more ADV_SG_BLOCK are used with each ADV_SCSI_REQ_Q. Each
1834 * ADV_SG_BLOCK structure holds 15 scatter-gather elements. Under Linux
1835 * up to 255 scatter-gather elements may be used per request or
1836 * ADV_SCSI_REQ_Q.
1837 *
1838 * Both structures must be 32 byte aligned.
1839 */
1840typedef struct adv_sgblk {
1841 ADV_SG_BLOCK sg_block; /* Sgblock structure. */
Hannes Reinecke0ce53822015-04-24 13:18:25 +02001842 dma_addr_t sg_addr; /* Physical address */
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001843 struct adv_sgblk *next_sgblkp; /* Next scatter-gather structure. */
1844} adv_sgblk_t;
1845
1846typedef struct adv_req {
1847 ADV_SCSI_REQ_Q scsi_req_q; /* Adv Library request structure. */
Hannes Reinecke4b47e462015-04-24 13:18:24 +02001848 uchar align[24]; /* Request structure padding. */
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001849 struct scsi_cmnd *cmndp; /* Mid-Level SCSI command pointer. */
Hannes Reinecke4b47e462015-04-24 13:18:24 +02001850 dma_addr_t req_addr;
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001851 adv_sgblk_t *sgblkp; /* Adv Library scatter-gather pointer. */
Hannes Reinecke4b47e462015-04-24 13:18:24 +02001852} adv_req_t __aligned(32);
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001853
1854/*
1855 * Adapter operation variable structure.
1856 *
1857 * One structure is required per host adapter.
1858 *
1859 * Field naming convention:
1860 *
1861 * *_able indicates both whether a feature should be enabled or disabled
1862 * and whether a device isi capable of the feature. At initialization
1863 * this field may be set, but later if a device is found to be incapable
1864 * of the feature, the field is cleared.
1865 */
1866typedef struct adv_dvc_var {
1867 AdvPortAddr iop_base; /* I/O port address */
1868 ushort err_code; /* fatal error code */
1869 ushort bios_ctrl; /* BIOS control word, EEPROM word 12 */
1870 ushort wdtr_able; /* try WDTR for a device */
1871 ushort sdtr_able; /* try SDTR for a device */
1872 ushort ultra_able; /* try SDTR Ultra speed for a device */
1873 ushort sdtr_speed1; /* EEPROM SDTR Speed for TID 0-3 */
1874 ushort sdtr_speed2; /* EEPROM SDTR Speed for TID 4-7 */
1875 ushort sdtr_speed3; /* EEPROM SDTR Speed for TID 8-11 */
1876 ushort sdtr_speed4; /* EEPROM SDTR Speed for TID 12-15 */
1877 ushort tagqng_able; /* try tagged queuing with a device */
1878 ushort ppr_able; /* PPR message capable per TID bitmask. */
1879 uchar max_dvc_qng; /* maximum number of tagged commands per device */
1880 ushort start_motor; /* start motor command allowed */
1881 uchar scsi_reset_wait; /* delay in seconds after scsi bus reset */
1882 uchar chip_no; /* should be assigned by caller */
1883 uchar max_host_qng; /* maximum number of Q'ed command allowed */
1884 ushort no_scam; /* scam_tolerant of EEPROM */
1885 struct asc_board *drv_ptr; /* driver pointer to private structure */
1886 uchar chip_scsi_id; /* chip SCSI target ID */
1887 uchar chip_type;
1888 uchar bist_err_code;
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001889 ADV_CARR_T *carrier;
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001890 ADV_CARR_T *carr_freelist; /* Carrier free list. */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001891 dma_addr_t carrier_addr;
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001892 ADV_CARR_T *icq_sp; /* Initiator command queue stopper pointer. */
1893 ADV_CARR_T *irq_sp; /* Initiator response queue stopper pointer. */
1894 ushort carr_pending_cnt; /* Count of pending carriers. */
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001895 /*
1896 * Note: The following fields will not be used after initialization. The
1897 * driver may discard the buffer after initialization is done.
1898 */
1899 ADV_DVC_CFG *cfg; /* temporary configuration structure */
1900} ADV_DVC_VAR;
1901
1902/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 * Microcode idle loop commands
1904 */
1905#define IDLE_CMD_COMPLETED 0
1906#define IDLE_CMD_STOP_CHIP 0x0001
1907#define IDLE_CMD_STOP_CHIP_SEND_INT 0x0002
1908#define IDLE_CMD_SEND_INT 0x0004
1909#define IDLE_CMD_ABORT 0x0008
1910#define IDLE_CMD_DEVICE_RESET 0x0010
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001911#define IDLE_CMD_SCSI_RESET_START 0x0020 /* Assert SCSI Bus Reset */
1912#define IDLE_CMD_SCSI_RESET_END 0x0040 /* Deassert SCSI Bus Reset */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913#define IDLE_CMD_SCSIREQ 0x0080
1914
1915#define IDLE_CMD_STATUS_SUCCESS 0x0001
1916#define IDLE_CMD_STATUS_FAILURE 0x0002
1917
1918/*
1919 * AdvSendIdleCmd() flag definitions.
1920 */
1921#define ADV_NOWAIT 0x01
1922
1923/*
1924 * Wait loop time out values.
1925 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001926#define SCSI_WAIT_100_MSEC 100UL /* 100 milliseconds */
1927#define SCSI_US_PER_MSEC 1000 /* microseconds per millisecond */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001928#define SCSI_MAX_RETRY 10 /* retry count */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001930#define ADV_ASYNC_RDMA_FAILURE 0x01 /* Fatal RDMA failure. */
1931#define ADV_ASYNC_SCSI_BUS_RESET_DET 0x02 /* Detected SCSI Bus Reset. */
1932#define ADV_ASYNC_CARRIER_READY_FAILURE 0x03 /* Carrier Ready failure. */
1933#define ADV_RDMA_IN_CARR_AND_Q_INVALID 0x04 /* RDMAed-in data invalid. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001935#define ADV_HOST_SCSI_BUS_RESET 0x80 /* Host Initiated SCSI Bus Reset. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937/* Read byte from a register. */
1938#define AdvReadByteRegister(iop_base, reg_off) \
1939 (ADV_MEM_READB((iop_base) + (reg_off)))
1940
1941/* Write byte to a register. */
1942#define AdvWriteByteRegister(iop_base, reg_off, byte) \
1943 (ADV_MEM_WRITEB((iop_base) + (reg_off), (byte)))
1944
1945/* Read word (2 bytes) from a register. */
1946#define AdvReadWordRegister(iop_base, reg_off) \
1947 (ADV_MEM_READW((iop_base) + (reg_off)))
1948
1949/* Write word (2 bytes) to a register. */
1950#define AdvWriteWordRegister(iop_base, reg_off, word) \
1951 (ADV_MEM_WRITEW((iop_base) + (reg_off), (word)))
1952
1953/* Write dword (4 bytes) to a register. */
1954#define AdvWriteDWordRegister(iop_base, reg_off, dword) \
1955 (ADV_MEM_WRITEDW((iop_base) + (reg_off), (dword)))
1956
1957/* Read byte from LRAM. */
1958#define AdvReadByteLram(iop_base, addr, byte) \
1959do { \
1960 ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
1961 (byte) = ADV_MEM_READB((iop_base) + IOPB_RAM_DATA); \
1962} while (0)
1963
1964/* Write byte to LRAM. */
1965#define AdvWriteByteLram(iop_base, addr, byte) \
1966 (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
1967 ADV_MEM_WRITEB((iop_base) + IOPB_RAM_DATA, (byte)))
1968
1969/* Read word (2 bytes) from LRAM. */
1970#define AdvReadWordLram(iop_base, addr, word) \
1971do { \
1972 ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
1973 (word) = (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA)); \
1974} while (0)
1975
1976/* Write word (2 bytes) to LRAM. */
1977#define AdvWriteWordLram(iop_base, addr, word) \
1978 (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
1979 ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
1980
1981/* Write little-endian double word (4 bytes) to LRAM */
1982/* Because of unspecified C language ordering don't use auto-increment. */
1983#define AdvWriteDWordLramNoSwap(iop_base, addr, dword) \
1984 ((ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
1985 ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
1986 cpu_to_le16((ushort) ((dword) & 0xFFFF)))), \
1987 (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr) + 2), \
1988 ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
1989 cpu_to_le16((ushort) ((dword >> 16) & 0xFFFF)))))
1990
1991/* Read word (2 bytes) from LRAM assuming that the address is already set. */
1992#define AdvReadWordAutoIncLram(iop_base) \
1993 (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA))
1994
1995/* Write word (2 bytes) to LRAM assuming that the address is already set. */
1996#define AdvWriteWordAutoIncLram(iop_base, word) \
1997 (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
1998
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999/*
2000 * Define macro to check for Condor signature.
2001 *
2002 * Evaluate to ADV_TRUE if a Condor chip is found the specified port
2003 * address 'iop_base'. Otherwise evalue to ADV_FALSE.
2004 */
2005#define AdvFindSignature(iop_base) \
2006 (((AdvReadByteRegister((iop_base), IOPB_CHIP_ID_1) == \
2007 ADV_CHIP_ID_BYTE) && \
2008 (AdvReadWordRegister((iop_base), IOPW_CHIP_ID_0) == \
2009 ADV_CHIP_ID_WORD)) ? ADV_TRUE : ADV_FALSE)
2010
2011/*
2012 * Define macro to Return the version number of the chip at 'iop_base'.
2013 *
2014 * The second parameter 'bus_type' is currently unused.
2015 */
2016#define AdvGetChipVersion(iop_base, bus_type) \
2017 AdvReadByteRegister((iop_base), IOPB_CHIP_TYPE_REV)
2018
2019/*
Hannes Reinecke9c17c622015-04-24 13:18:21 +02002020 * Abort an SRB in the chip's RISC Memory. The 'srb_tag' argument must
Hannes Reinecke9fef6ba2015-04-24 13:18:33 +02002021 * match the ADV_SCSI_REQ_Q 'srb_tag' field.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 *
2023 * If the request has not yet been sent to the device it will simply be
2024 * aborted from RISC memory. If the request is disconnected it will be
2025 * aborted on reselection by sending an Abort Message to the target ID.
2026 *
2027 * Return value:
2028 * ADV_TRUE(1) - Queue was successfully aborted.
2029 * ADV_FALSE(0) - Queue was not found on the active queue list.
2030 */
Hannes Reinecke9c17c622015-04-24 13:18:21 +02002031#define AdvAbortQueue(asc_dvc, srb_tag) \
2032 AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_ABORT, \
2033 (ADV_DCNT) (srb_tag))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034
2035/*
2036 * Send a Bus Device Reset Message to the specified target ID.
2037 *
2038 * All outstanding commands will be purged if sending the
2039 * Bus Device Reset Message is successful.
2040 *
2041 * Return Value:
2042 * ADV_TRUE(1) - All requests on the target are purged.
2043 * ADV_FALSE(0) - Couldn't issue Bus Device Reset Message; Requests
2044 * are not purged.
2045 */
2046#define AdvResetDevice(asc_dvc, target_id) \
Hannes Reinecke9c17c622015-04-24 13:18:21 +02002047 AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_DEVICE_RESET, \
2048 (ADV_DCNT) (target_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049
2050/*
2051 * SCSI Wide Type definition.
2052 */
2053#define ADV_SCSI_BIT_ID_TYPE ushort
2054
2055/*
2056 * AdvInitScsiTarget() 'cntl_flag' options.
2057 */
2058#define ADV_SCAN_LUN 0x01
2059#define ADV_CAPINFO_NOLUN 0x02
2060
2061/*
2062 * Convert target id to target id bit mask.
2063 */
2064#define ADV_TID_TO_TIDMASK(tid) (0x01 << ((tid) & ADV_MAX_TID))
2065
2066/*
Hannes Reinecke9fef6ba2015-04-24 13:18:33 +02002067 * ADV_SCSI_REQ_Q 'done_status' and 'host_status' return values.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 */
2069
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002070#define QD_NO_STATUS 0x00 /* Request not completed yet. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071#define QD_NO_ERROR 0x01
2072#define QD_ABORTED_BY_HOST 0x02
2073#define QD_WITH_ERROR 0x04
2074
2075#define QHSTA_NO_ERROR 0x00
2076#define QHSTA_M_SEL_TIMEOUT 0x11
2077#define QHSTA_M_DATA_OVER_RUN 0x12
2078#define QHSTA_M_UNEXPECTED_BUS_FREE 0x13
2079#define QHSTA_M_QUEUE_ABORTED 0x15
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002080#define QHSTA_M_SXFR_SDMA_ERR 0x16 /* SXFR_STATUS SCSI DMA Error */
2081#define QHSTA_M_SXFR_SXFR_PERR 0x17 /* SXFR_STATUS SCSI Bus Parity Error */
2082#define QHSTA_M_RDMA_PERR 0x18 /* RISC PCI DMA parity error */
2083#define QHSTA_M_SXFR_OFF_UFLW 0x19 /* SXFR_STATUS Offset Underflow */
2084#define QHSTA_M_SXFR_OFF_OFLW 0x20 /* SXFR_STATUS Offset Overflow */
2085#define QHSTA_M_SXFR_WD_TMO 0x21 /* SXFR_STATUS Watchdog Timeout */
2086#define QHSTA_M_SXFR_DESELECTED 0x22 /* SXFR_STATUS Deselected */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087/* Note: QHSTA_M_SXFR_XFR_OFLW is identical to QHSTA_M_DATA_OVER_RUN. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002088#define QHSTA_M_SXFR_XFR_OFLW 0x12 /* SXFR_STATUS Transfer Overflow */
2089#define QHSTA_M_SXFR_XFR_PH_ERR 0x24 /* SXFR_STATUS Transfer Phase Error */
2090#define QHSTA_M_SXFR_UNKNOWN_ERROR 0x25 /* SXFR_STATUS Unknown Error */
2091#define QHSTA_M_SCSI_BUS_RESET 0x30 /* Request aborted from SBR */
2092#define QHSTA_M_SCSI_BUS_RESET_UNSOL 0x31 /* Request aborted from unsol. SBR */
2093#define QHSTA_M_BUS_DEVICE_RESET 0x32 /* Request aborted from BDR */
2094#define QHSTA_M_DIRECTION_ERR 0x35 /* Data Phase mismatch */
2095#define QHSTA_M_DIRECTION_ERR_HUNG 0x36 /* Data Phase mismatch and bus hang */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096#define QHSTA_M_WTM_TIMEOUT 0x41
2097#define QHSTA_M_BAD_CMPL_STATUS_IN 0x42
2098#define QHSTA_M_NO_AUTO_REQ_SENSE 0x43
2099#define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002100#define QHSTA_M_INVALID_DEVICE 0x45 /* Bad target ID */
2101#define QHSTA_M_FROZEN_TIDQ 0x46 /* TID Queue frozen. */
2102#define QHSTA_M_SGBACKUP_ERROR 0x47 /* Scatter-Gather backup error */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104/* Return the address that is aligned at the next doubleword >= to 'addr'. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105#define ADV_32BALIGN(addr) (((ulong) (addr) + 0x1F) & ~0x1F)
2106
2107/*
2108 * Total contiguous memory needed for driver SG blocks.
2109 *
2110 * ADV_MAX_SG_LIST must be defined by a driver. It is the maximum
2111 * number of scatter-gather elements the driver supports in a
2112 * single request.
2113 */
2114
2115#define ADV_SG_LIST_MAX_BYTE_SIZE \
2116 (sizeof(ADV_SG_BLOCK) * \
2117 ((ADV_MAX_SG_LIST + (NO_OF_SG_PER_BLOCK - 1))/NO_OF_SG_PER_BLOCK))
2118
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002119/* struct asc_board flags */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002120#define ASC_IS_WIDE_BOARD 0x04 /* AdvanSys Wide Board */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121
2122#define ASC_NARROW_BOARD(boardp) (((boardp)->flags & ASC_IS_WIDE_BOARD) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002124#define NO_ISA_DMA 0xff /* No ISA DMA Channel Used */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002126#define ASC_INFO_SIZE 128 /* advansys_info() line size */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128/* Asc Library return codes */
2129#define ASC_TRUE 1
2130#define ASC_FALSE 0
2131#define ASC_NOERROR 1
2132#define ASC_BUSY 0
2133#define ASC_ERROR (-1)
2134
2135/* struct scsi_cmnd function return codes */
2136#define STATUS_BYTE(byte) (byte)
2137#define MSG_BYTE(byte) ((byte) << 8)
2138#define HOST_BYTE(byte) ((byte) << 16)
2139#define DRIVER_BYTE(byte) ((byte) << 24)
2140
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002141#define ASC_STATS(shost, counter) ASC_STATS_ADD(shost, counter, 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142#ifndef ADVANSYS_STATS
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002143#define ASC_STATS_ADD(shost, counter, count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144#else /* ADVANSYS_STATS */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002145#define ASC_STATS_ADD(shost, counter, count) \
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002146 (((struct asc_board *) shost_priv(shost))->asc_stats.counter += (count))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147#endif /* ADVANSYS_STATS */
2148
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149/* If the result wraps when calculating tenths, return 0. */
2150#define ASC_TENTHS(num, den) \
2151 (((10 * ((num)/(den))) > (((num) * 10)/(den))) ? \
2152 0 : ((((num) * 10)/(den)) - (10 * ((num)/(den)))))
2153
2154/*
2155 * Display a message to the console.
2156 */
2157#define ASC_PRINT(s) \
2158 { \
2159 printk("advansys: "); \
2160 printk(s); \
2161 }
2162
2163#define ASC_PRINT1(s, a1) \
2164 { \
2165 printk("advansys: "); \
2166 printk((s), (a1)); \
2167 }
2168
2169#define ASC_PRINT2(s, a1, a2) \
2170 { \
2171 printk("advansys: "); \
2172 printk((s), (a1), (a2)); \
2173 }
2174
2175#define ASC_PRINT3(s, a1, a2, a3) \
2176 { \
2177 printk("advansys: "); \
2178 printk((s), (a1), (a2), (a3)); \
2179 }
2180
2181#define ASC_PRINT4(s, a1, a2, a3, a4) \
2182 { \
2183 printk("advansys: "); \
2184 printk((s), (a1), (a2), (a3), (a4)); \
2185 }
2186
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187#ifndef ADVANSYS_DEBUG
2188
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002189#define ASC_DBG(lvl, s...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190#define ASC_DBG_PRT_SCSI_HOST(lvl, s)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191#define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp)
2192#define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
2193#define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone)
2194#define ADV_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
2195#define ASC_DBG_PRT_HEX(lvl, name, start, length)
2196#define ASC_DBG_PRT_CDB(lvl, cdb, len)
2197#define ASC_DBG_PRT_SENSE(lvl, sense, len)
2198#define ASC_DBG_PRT_INQUIRY(lvl, inq, len)
2199
2200#else /* ADVANSYS_DEBUG */
2201
2202/*
2203 * Debugging Message Levels:
2204 * 0: Errors Only
2205 * 1: High-Level Tracing
2206 * 2-N: Verbose Tracing
2207 */
2208
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002209#define ASC_DBG(lvl, format, arg...) { \
2210 if (asc_dbglvl >= (lvl)) \
2211 printk(KERN_DEBUG "%s: %s: " format, DRV_NAME, \
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07002212 __func__ , ## arg); \
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002213}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214
2215#define ASC_DBG_PRT_SCSI_HOST(lvl, s) \
2216 { \
2217 if (asc_dbglvl >= (lvl)) { \
2218 asc_prt_scsi_host(s); \
2219 } \
2220 }
2221
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222#define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp) \
2223 { \
2224 if (asc_dbglvl >= (lvl)) { \
2225 asc_prt_asc_scsi_q(scsiqp); \
2226 } \
2227 }
2228
2229#define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone) \
2230 { \
2231 if (asc_dbglvl >= (lvl)) { \
2232 asc_prt_asc_qdone_info(qdone); \
2233 } \
2234 }
2235
2236#define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp) \
2237 { \
2238 if (asc_dbglvl >= (lvl)) { \
2239 asc_prt_adv_scsi_req_q(scsiqp); \
2240 } \
2241 }
2242
2243#define ASC_DBG_PRT_HEX(lvl, name, start, length) \
2244 { \
2245 if (asc_dbglvl >= (lvl)) { \
2246 asc_prt_hex((name), (start), (length)); \
2247 } \
2248 }
2249
2250#define ASC_DBG_PRT_CDB(lvl, cdb, len) \
2251 ASC_DBG_PRT_HEX((lvl), "CDB", (uchar *) (cdb), (len));
2252
2253#define ASC_DBG_PRT_SENSE(lvl, sense, len) \
2254 ASC_DBG_PRT_HEX((lvl), "SENSE", (uchar *) (sense), (len));
2255
2256#define ASC_DBG_PRT_INQUIRY(lvl, inq, len) \
2257 ASC_DBG_PRT_HEX((lvl), "INQUIRY", (uchar *) (inq), (len));
2258#endif /* ADVANSYS_DEBUG */
2259
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260#ifdef ADVANSYS_STATS
2261
2262/* Per board statistics structure */
2263struct asc_stats {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002264 /* Driver Entrypoint Statistics */
Hannes Reinecke95cfab62015-04-24 13:18:27 +02002265 unsigned int queuecommand; /* # calls to advansys_queuecommand() */
2266 unsigned int reset; /* # calls to advansys_eh_bus_reset() */
2267 unsigned int biosparam; /* # calls to advansys_biosparam() */
2268 unsigned int interrupt; /* # advansys_interrupt() calls */
2269 unsigned int callback; /* # calls to asc/adv_isr_callback() */
2270 unsigned int done; /* # calls to request's scsi_done function */
2271 unsigned int build_error; /* # asc/adv_build_req() ASC_ERROR returns. */
2272 unsigned int adv_build_noreq; /* # adv_build_req() adv_req_t alloc. fail. */
2273 unsigned int adv_build_nosg; /* # adv_build_req() adv_sgblk_t alloc. fail. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002274 /* AscExeScsiQueue()/AdvExeScsiQueue() Statistics */
Hannes Reinecke95cfab62015-04-24 13:18:27 +02002275 unsigned int exe_noerror; /* # ASC_NOERROR returns. */
2276 unsigned int exe_busy; /* # ASC_BUSY returns. */
2277 unsigned int exe_error; /* # ASC_ERROR returns. */
2278 unsigned int exe_unknown; /* # unknown returns. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002279 /* Data Transfer Statistics */
Hannes Reinecke95cfab62015-04-24 13:18:27 +02002280 unsigned int xfer_cnt; /* # I/O requests received */
2281 unsigned int xfer_elem; /* # scatter-gather elements */
2282 unsigned int xfer_sect; /* # 512-byte blocks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283};
2284#endif /* ADVANSYS_STATS */
2285
2286/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 * Structure allocated for each board.
2288 *
Matthew Wilcox8dfb5372007-07-30 09:08:34 -06002289 * This structure is allocated by scsi_host_alloc() at the end
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 * of the 'Scsi_Host' structure starting at the 'hostdata'
2291 * field. It is guaranteed to be allocated from DMA-able memory.
2292 */
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002293struct asc_board {
Matthew Wilcox394dbf32007-07-26 11:56:40 -04002294 struct device *dev;
Hannes Reinecke9c17c622015-04-24 13:18:21 +02002295 struct Scsi_Host *shost;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002296 uint flags; /* Board flags */
Matthew Wilcoxd361db42007-10-02 21:55:29 -04002297 unsigned int irq;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002298 union {
2299 ASC_DVC_VAR asc_dvc_var; /* Narrow board */
2300 ADV_DVC_VAR adv_dvc_var; /* Wide board */
2301 } dvc_var;
2302 union {
2303 ASC_DVC_CFG asc_dvc_cfg; /* Narrow board */
2304 ADV_DVC_CFG adv_dvc_cfg; /* Wide board */
2305 } dvc_cfg;
2306 ushort asc_n_io_port; /* Number I/O ports. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002307 ADV_SCSI_BIT_ID_TYPE init_tidmask; /* Target init./valid mask */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002308 ushort reqcnt[ADV_MAX_TID + 1]; /* Starvation request count */
2309 ADV_SCSI_BIT_ID_TYPE queue_full; /* Queue full mask */
2310 ushort queue_full_cnt[ADV_MAX_TID + 1]; /* Queue full count */
2311 union {
2312 ASCEEP_CONFIG asc_eep; /* Narrow EEPROM config. */
2313 ADVEEP_3550_CONFIG adv_3550_eep; /* 3550 EEPROM config. */
2314 ADVEEP_38C0800_CONFIG adv_38C0800_eep; /* 38C0800 EEPROM config. */
2315 ADVEEP_38C1600_CONFIG adv_38C1600_eep; /* 38C1600 EEPROM config. */
2316 } eep_config;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002317 /* /proc/scsi/advansys/[0...] */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318#ifdef ADVANSYS_STATS
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002319 struct asc_stats asc_stats; /* Board statistics */
2320#endif /* ADVANSYS_STATS */
2321 /*
2322 * The following fields are used only for Narrow Boards.
2323 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002324 uchar sdtr_data[ASC_MAX_TID + 1]; /* SDTR information */
2325 /*
2326 * The following fields are used only for Wide Boards.
2327 */
2328 void __iomem *ioremap_addr; /* I/O Memory remap address. */
2329 ushort ioport; /* I/O Port address. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002330 adv_req_t *adv_reqp; /* Request structures. */
Hannes Reinecke4b47e462015-04-24 13:18:24 +02002331 dma_addr_t adv_reqp_addr;
2332 size_t adv_reqp_size;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02002333 struct dma_pool *adv_sgblk_pool; /* Scatter-gather structures. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002334 ushort bios_signature; /* BIOS Signature. */
2335 ushort bios_version; /* BIOS Version. */
2336 ushort bios_codeseg; /* BIOS Code Segment. */
2337 ushort bios_codelen; /* BIOS Code Segment Length. */
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002338};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -04002340#define asc_dvc_to_board(asc_dvc) container_of(asc_dvc, struct asc_board, \
2341 dvc_var.asc_dvc_var)
Matthew Wilcox13ac2d92007-07-30 08:10:23 -06002342#define adv_dvc_to_board(adv_dvc) container_of(adv_dvc, struct asc_board, \
2343 dvc_var.adv_dvc_var)
2344#define adv_dvc_to_pdev(adv_dvc) to_pci_dev(adv_dvc_to_board(adv_dvc)->dev)
2345
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346#ifdef ADVANSYS_DEBUG
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002347static int asc_dbglvl = 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349/*
Matthew Wilcox51219352007-10-02 21:55:22 -04002350 * asc_prt_asc_dvc_var()
2351 */
2352static void asc_prt_asc_dvc_var(ASC_DVC_VAR *h)
2353{
2354 printk("ASC_DVC_VAR at addr 0x%lx\n", (ulong)h);
2355
2356 printk(" iop_base 0x%x, err_code 0x%x, dvc_cntl 0x%x, bug_fix_cntl "
2357 "%d,\n", h->iop_base, h->err_code, h->dvc_cntl, h->bug_fix_cntl);
2358
2359 printk(" bus_type %d, init_sdtr 0x%x,\n", h->bus_type,
2360 (unsigned)h->init_sdtr);
2361
2362 printk(" sdtr_done 0x%x, use_tagged_qng 0x%x, unit_not_ready 0x%x, "
2363 "chip_no 0x%x,\n", (unsigned)h->sdtr_done,
2364 (unsigned)h->use_tagged_qng, (unsigned)h->unit_not_ready,
2365 (unsigned)h->chip_no);
2366
2367 printk(" queue_full_or_busy 0x%x, start_motor 0x%x, scsi_reset_wait "
2368 "%u,\n", (unsigned)h->queue_full_or_busy,
2369 (unsigned)h->start_motor, (unsigned)h->scsi_reset_wait);
2370
2371 printk(" is_in_int %u, max_total_qng %u, cur_total_qng %u, "
2372 "in_critical_cnt %u,\n", (unsigned)h->is_in_int,
2373 (unsigned)h->max_total_qng, (unsigned)h->cur_total_qng,
2374 (unsigned)h->in_critical_cnt);
2375
2376 printk(" last_q_shortage %u, init_state 0x%x, no_scam 0x%x, "
2377 "pci_fix_asyn_xfer 0x%x,\n", (unsigned)h->last_q_shortage,
2378 (unsigned)h->init_state, (unsigned)h->no_scam,
2379 (unsigned)h->pci_fix_asyn_xfer);
2380
Matthew Wilcoxd361db42007-10-02 21:55:29 -04002381 printk(" cfg 0x%lx\n", (ulong)h->cfg);
Matthew Wilcox51219352007-10-02 21:55:22 -04002382}
2383
2384/*
2385 * asc_prt_asc_dvc_cfg()
2386 */
2387static void asc_prt_asc_dvc_cfg(ASC_DVC_CFG *h)
2388{
2389 printk("ASC_DVC_CFG at addr 0x%lx\n", (ulong)h);
2390
2391 printk(" can_tagged_qng 0x%x, cmd_qng_enabled 0x%x,\n",
2392 h->can_tagged_qng, h->cmd_qng_enabled);
2393 printk(" disc_enable 0x%x, sdtr_enable 0x%x,\n",
2394 h->disc_enable, h->sdtr_enable);
2395
Matthew Wilcoxb08fc562007-10-02 21:55:32 -04002396 printk(" chip_scsi_id %d, isa_dma_speed %d, isa_dma_channel %d, "
2397 "chip_version %d,\n", h->chip_scsi_id, h->isa_dma_speed,
2398 h->isa_dma_channel, h->chip_version);
Matthew Wilcox51219352007-10-02 21:55:22 -04002399
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -04002400 printk(" mcode_date 0x%x, mcode_version %d\n",
2401 h->mcode_date, h->mcode_version);
Matthew Wilcox51219352007-10-02 21:55:22 -04002402}
2403
2404/*
Matthew Wilcox51219352007-10-02 21:55:22 -04002405 * asc_prt_adv_dvc_var()
2406 *
2407 * Display an ADV_DVC_VAR structure.
2408 */
2409static void asc_prt_adv_dvc_var(ADV_DVC_VAR *h)
2410{
2411 printk(" ADV_DVC_VAR at addr 0x%lx\n", (ulong)h);
2412
2413 printk(" iop_base 0x%lx, err_code 0x%x, ultra_able 0x%x\n",
2414 (ulong)h->iop_base, h->err_code, (unsigned)h->ultra_able);
2415
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002416 printk(" sdtr_able 0x%x, wdtr_able 0x%x\n",
2417 (unsigned)h->sdtr_able, (unsigned)h->wdtr_able);
Matthew Wilcox51219352007-10-02 21:55:22 -04002418
Matthew Wilcoxd361db42007-10-02 21:55:29 -04002419 printk(" start_motor 0x%x, scsi_reset_wait 0x%x\n",
2420 (unsigned)h->start_motor, (unsigned)h->scsi_reset_wait);
Matthew Wilcox51219352007-10-02 21:55:22 -04002421
Hannes Reinecke98b96a72015-04-24 13:18:23 +02002422 printk(" max_host_qng %u, max_dvc_qng %u, carr_freelist 0x%p\n",
Matthew Wilcox51219352007-10-02 21:55:22 -04002423 (unsigned)h->max_host_qng, (unsigned)h->max_dvc_qng,
Hannes Reinecke98b96a72015-04-24 13:18:23 +02002424 h->carr_freelist);
Matthew Wilcox51219352007-10-02 21:55:22 -04002425
Hannes Reinecke98b96a72015-04-24 13:18:23 +02002426 printk(" icq_sp 0x%p, irq_sp 0x%p\n", h->icq_sp, h->irq_sp);
Matthew Wilcox51219352007-10-02 21:55:22 -04002427
2428 printk(" no_scam 0x%x, tagqng_able 0x%x\n",
2429 (unsigned)h->no_scam, (unsigned)h->tagqng_able);
2430
2431 printk(" chip_scsi_id 0x%x, cfg 0x%lx\n",
2432 (unsigned)h->chip_scsi_id, (ulong)h->cfg);
2433}
2434
2435/*
2436 * asc_prt_adv_dvc_cfg()
2437 *
2438 * Display an ADV_DVC_CFG structure.
2439 */
2440static void asc_prt_adv_dvc_cfg(ADV_DVC_CFG *h)
2441{
2442 printk(" ADV_DVC_CFG at addr 0x%lx\n", (ulong)h);
2443
2444 printk(" disc_enable 0x%x, termination 0x%x\n",
2445 h->disc_enable, h->termination);
2446
2447 printk(" chip_version 0x%x, mcode_date 0x%x\n",
2448 h->chip_version, h->mcode_date);
2449
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002450 printk(" mcode_version 0x%x, control_flag 0x%x\n",
2451 h->mcode_version, h->control_flag);
Matthew Wilcox51219352007-10-02 21:55:22 -04002452}
2453
2454/*
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002455 * asc_prt_scsi_host()
Matthew Wilcox51219352007-10-02 21:55:22 -04002456 */
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002457static void asc_prt_scsi_host(struct Scsi_Host *s)
Matthew Wilcox51219352007-10-02 21:55:22 -04002458{
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002459 struct asc_board *boardp = shost_priv(s);
Matthew Wilcox51219352007-10-02 21:55:22 -04002460
Kay Sievers71610f52008-12-03 22:41:36 +01002461 printk("Scsi_Host at addr 0x%p, device %s\n", s, dev_name(boardp->dev));
Hannes Reinecke50d14a72013-10-23 10:51:17 +02002462 printk(" host_busy %u, host_no %d,\n",
Christoph Hellwig74665012014-01-22 15:29:29 +01002463 atomic_read(&s->host_busy), s->host_no);
Matthew Wilcox51219352007-10-02 21:55:22 -04002464
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002465 printk(" base 0x%lx, io_port 0x%lx, irq %d,\n",
2466 (ulong)s->base, (ulong)s->io_port, boardp->irq);
Matthew Wilcox51219352007-10-02 21:55:22 -04002467
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002468 printk(" dma_channel %d, this_id %d, can_queue %d,\n",
2469 s->dma_channel, s->this_id, s->can_queue);
Matthew Wilcox51219352007-10-02 21:55:22 -04002470
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002471 printk(" cmd_per_lun %d, sg_tablesize %d, unchecked_isa_dma %d\n",
2472 s->cmd_per_lun, s->sg_tablesize, s->unchecked_isa_dma);
Matthew Wilcox51219352007-10-02 21:55:22 -04002473
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002474 if (ASC_NARROW_BOARD(boardp)) {
2475 asc_prt_asc_dvc_var(&boardp->dvc_var.asc_dvc_var);
2476 asc_prt_asc_dvc_cfg(&boardp->dvc_cfg.asc_dvc_cfg);
2477 } else {
2478 asc_prt_adv_dvc_var(&boardp->dvc_var.adv_dvc_var);
2479 asc_prt_adv_dvc_cfg(&boardp->dvc_cfg.adv_dvc_cfg);
Matthew Wilcox51219352007-10-02 21:55:22 -04002480 }
2481}
2482
2483/*
2484 * asc_prt_hex()
2485 *
2486 * Print hexadecimal output in 4 byte groupings 32 bytes
2487 * or 8 double-words per line.
2488 */
2489static void asc_prt_hex(char *f, uchar *s, int l)
2490{
2491 int i;
2492 int j;
2493 int k;
2494 int m;
2495
2496 printk("%s: (%d bytes)\n", f, l);
2497
2498 for (i = 0; i < l; i += 32) {
2499
2500 /* Display a maximum of 8 double-words per line. */
2501 if ((k = (l - i) / 4) >= 8) {
2502 k = 8;
2503 m = 0;
2504 } else {
2505 m = (l - i) % 4;
2506 }
2507
2508 for (j = 0; j < k; j++) {
2509 printk(" %2.2X%2.2X%2.2X%2.2X",
2510 (unsigned)s[i + (j * 4)],
2511 (unsigned)s[i + (j * 4) + 1],
2512 (unsigned)s[i + (j * 4) + 2],
2513 (unsigned)s[i + (j * 4) + 3]);
2514 }
2515
2516 switch (m) {
2517 case 0:
2518 default:
2519 break;
2520 case 1:
2521 printk(" %2.2X", (unsigned)s[i + (j * 4)]);
2522 break;
2523 case 2:
2524 printk(" %2.2X%2.2X",
2525 (unsigned)s[i + (j * 4)],
2526 (unsigned)s[i + (j * 4) + 1]);
2527 break;
2528 case 3:
2529 printk(" %2.2X%2.2X%2.2X",
2530 (unsigned)s[i + (j * 4) + 1],
2531 (unsigned)s[i + (j * 4) + 2],
2532 (unsigned)s[i + (j * 4) + 3]);
2533 break;
2534 }
2535
2536 printk("\n");
2537 }
2538}
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002539
2540/*
2541 * asc_prt_asc_scsi_q()
2542 */
2543static void asc_prt_asc_scsi_q(ASC_SCSI_Q *q)
2544{
2545 ASC_SG_HEAD *sgp;
2546 int i;
2547
2548 printk("ASC_SCSI_Q at addr 0x%lx\n", (ulong)q);
2549
2550 printk
Hannes Reinecke9c17c622015-04-24 13:18:21 +02002551 (" target_ix 0x%x, target_lun %u, srb_tag 0x%x, tag_code 0x%x,\n",
2552 q->q2.target_ix, q->q1.target_lun, q->q2.srb_tag,
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002553 q->q2.tag_code);
2554
2555 printk
2556 (" data_addr 0x%lx, data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
2557 (ulong)le32_to_cpu(q->q1.data_addr),
2558 (ulong)le32_to_cpu(q->q1.data_cnt),
2559 (ulong)le32_to_cpu(q->q1.sense_addr), q->q1.sense_len);
2560
2561 printk(" cdbptr 0x%lx, cdb_len %u, sg_head 0x%lx, sg_queue_cnt %u\n",
2562 (ulong)q->cdbptr, q->q2.cdb_len,
2563 (ulong)q->sg_head, q->q1.sg_queue_cnt);
2564
2565 if (q->sg_head) {
2566 sgp = q->sg_head;
2567 printk("ASC_SG_HEAD at addr 0x%lx\n", (ulong)sgp);
2568 printk(" entry_cnt %u, queue_cnt %u\n", sgp->entry_cnt,
2569 sgp->queue_cnt);
2570 for (i = 0; i < sgp->entry_cnt; i++) {
2571 printk(" [%u]: addr 0x%lx, bytes %lu\n",
2572 i, (ulong)le32_to_cpu(sgp->sg_list[i].addr),
2573 (ulong)le32_to_cpu(sgp->sg_list[i].bytes));
2574 }
2575
2576 }
2577}
2578
2579/*
2580 * asc_prt_asc_qdone_info()
2581 */
2582static void asc_prt_asc_qdone_info(ASC_QDONE_INFO *q)
2583{
2584 printk("ASC_QDONE_INFO at addr 0x%lx\n", (ulong)q);
Hannes Reinecke9c17c622015-04-24 13:18:21 +02002585 printk(" srb_tag 0x%x, target_ix %u, cdb_len %u, tag_code %u,\n",
2586 q->d2.srb_tag, q->d2.target_ix, q->d2.cdb_len,
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002587 q->d2.tag_code);
2588 printk
2589 (" done_stat 0x%x, host_stat 0x%x, scsi_stat 0x%x, scsi_msg 0x%x\n",
2590 q->d3.done_stat, q->d3.host_stat, q->d3.scsi_stat, q->d3.scsi_msg);
2591}
2592
2593/*
2594 * asc_prt_adv_sgblock()
2595 *
2596 * Display an ADV_SG_BLOCK structure.
2597 */
2598static void asc_prt_adv_sgblock(int sgblockno, ADV_SG_BLOCK *b)
2599{
2600 int i;
2601
Hannes Reinecke0ce53822015-04-24 13:18:25 +02002602 printk(" ADV_SG_BLOCK at addr 0x%lx (sgblockno %d)\n",
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002603 (ulong)b, sgblockno);
2604 printk(" sg_cnt %u, sg_ptr 0x%lx\n",
2605 b->sg_cnt, (ulong)le32_to_cpu(b->sg_ptr));
2606 BUG_ON(b->sg_cnt > NO_OF_SG_PER_BLOCK);
2607 if (b->sg_ptr != 0)
2608 BUG_ON(b->sg_cnt != NO_OF_SG_PER_BLOCK);
2609 for (i = 0; i < b->sg_cnt; i++) {
2610 printk(" [%u]: sg_addr 0x%lx, sg_count 0x%lx\n",
2611 i, (ulong)b->sg_list[i].sg_addr,
2612 (ulong)b->sg_list[i].sg_count);
2613 }
2614}
2615
2616/*
2617 * asc_prt_adv_scsi_req_q()
2618 *
2619 * Display an ADV_SCSI_REQ_Q structure.
2620 */
2621static void asc_prt_adv_scsi_req_q(ADV_SCSI_REQ_Q *q)
2622{
2623 int sg_blk_cnt;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02002624 struct adv_sg_block *sg_ptr;
2625 adv_sgblk_t *sgblkp;
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002626
2627 printk("ADV_SCSI_REQ_Q at addr 0x%lx\n", (ulong)q);
2628
Hannes Reinecke9c17c622015-04-24 13:18:21 +02002629 printk(" target_id %u, target_lun %u, srb_tag 0x%x, a_flag 0x%x\n",
2630 q->target_id, q->target_lun, q->srb_tag, q->a_flag);
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002631
Hannes Reinecke98b96a72015-04-24 13:18:23 +02002632 printk(" cntl 0x%x, data_addr 0x%lx\n",
2633 q->cntl, (ulong)le32_to_cpu(q->data_addr));
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002634
2635 printk(" data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
2636 (ulong)le32_to_cpu(q->data_cnt),
2637 (ulong)le32_to_cpu(q->sense_addr), q->sense_len);
2638
2639 printk
2640 (" cdb_len %u, done_status 0x%x, host_status 0x%x, scsi_status 0x%x\n",
2641 q->cdb_len, q->done_status, q->host_status, q->scsi_status);
2642
2643 printk(" sg_working_ix 0x%x, target_cmd %u\n",
2644 q->sg_working_ix, q->target_cmd);
2645
2646 printk(" scsiq_rptr 0x%lx, sg_real_addr 0x%lx, sg_list_ptr 0x%lx\n",
2647 (ulong)le32_to_cpu(q->scsiq_rptr),
2648 (ulong)le32_to_cpu(q->sg_real_addr), (ulong)q->sg_list_ptr);
2649
2650 /* Display the request's ADV_SG_BLOCK structures. */
2651 if (q->sg_list_ptr != NULL) {
Hannes Reinecke0ce53822015-04-24 13:18:25 +02002652 sgblkp = container_of(q->sg_list_ptr, adv_sgblk_t, sg_block);
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002653 sg_blk_cnt = 0;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02002654 while (sgblkp) {
2655 sg_ptr = &sgblkp->sg_block;
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002656 asc_prt_adv_sgblock(sg_blk_cnt, sg_ptr);
2657 if (sg_ptr->sg_ptr == 0) {
2658 break;
2659 }
Hannes Reinecke0ce53822015-04-24 13:18:25 +02002660 sgblkp = sgblkp->next_sgblkp;
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002661 sg_blk_cnt++;
2662 }
2663 }
2664}
Matthew Wilcox51219352007-10-02 21:55:22 -04002665#endif /* ADVANSYS_DEBUG */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666
2667/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 * advansys_info()
2669 *
2670 * Return suitable for printing on the console with the argument
2671 * adapter's configuration information.
2672 *
2673 * Note: The information line should not exceed ASC_INFO_SIZE bytes,
2674 * otherwise the static 'info' array will be overrun.
2675 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002676static const char *advansys_info(struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677{
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002678 static char info[ASC_INFO_SIZE];
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002679 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002680 ASC_DVC_VAR *asc_dvc_varp;
2681 ADV_DVC_VAR *adv_dvc_varp;
2682 char *busname;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002683 char *widename = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002685 if (ASC_NARROW_BOARD(boardp)) {
2686 asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002687 ASC_DBG(1, "begin\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002688 if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
2689 if ((asc_dvc_varp->bus_type & ASC_IS_ISAPNP) ==
2690 ASC_IS_ISAPNP) {
2691 busname = "ISA PnP";
2692 } else {
2693 busname = "ISA";
2694 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002695 sprintf(info,
2696 "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X, DMA 0x%X",
2697 ASC_VERSION, busname,
2698 (ulong)shost->io_port,
Matthew Wilcox4a2d31c2007-07-26 11:55:34 -04002699 (ulong)shost->io_port + ASC_IOADR_GAP - 1,
Matthew Wilcoxd361db42007-10-02 21:55:29 -04002700 boardp->irq, shost->dma_channel);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002701 } else {
2702 if (asc_dvc_varp->bus_type & ASC_IS_VL) {
2703 busname = "VL";
2704 } else if (asc_dvc_varp->bus_type & ASC_IS_EISA) {
2705 busname = "EISA";
2706 } else if (asc_dvc_varp->bus_type & ASC_IS_PCI) {
2707 if ((asc_dvc_varp->bus_type & ASC_IS_PCI_ULTRA)
2708 == ASC_IS_PCI_ULTRA) {
2709 busname = "PCI Ultra";
2710 } else {
2711 busname = "PCI";
2712 }
2713 } else {
2714 busname = "?";
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04002715 shost_printk(KERN_ERR, shost, "unknown bus "
2716 "type %d\n", asc_dvc_varp->bus_type);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002717 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002718 sprintf(info,
2719 "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X",
Matthew Wilcoxecec1942007-07-30 08:08:22 -06002720 ASC_VERSION, busname, (ulong)shost->io_port,
Matthew Wilcox4a2d31c2007-07-26 11:55:34 -04002721 (ulong)shost->io_port + ASC_IOADR_GAP - 1,
Matthew Wilcoxd361db42007-10-02 21:55:29 -04002722 boardp->irq);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002723 }
2724 } else {
2725 /*
2726 * Wide Adapter Information
2727 *
2728 * Memory-mapped I/O is used instead of I/O space to access
2729 * the adapter, but display the I/O Port range. The Memory
2730 * I/O address is displayed through the driver /proc file.
2731 */
2732 adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
2733 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002734 widename = "Ultra-Wide";
2735 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002736 widename = "Ultra2-Wide";
2737 } else {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002738 widename = "Ultra3-Wide";
2739 }
2740 sprintf(info,
2741 "AdvanSys SCSI %s: PCI %s: PCIMEM 0x%lX-0x%lX, IRQ 0x%X",
2742 ASC_VERSION, widename, (ulong)adv_dvc_varp->iop_base,
Matthew Wilcoxd361db42007-10-02 21:55:29 -04002743 (ulong)adv_dvc_varp->iop_base + boardp->asc_n_io_port - 1, boardp->irq);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002744 }
Matthew Wilcoxb009bef2007-09-09 08:56:38 -06002745 BUG_ON(strlen(info) >= ASC_INFO_SIZE);
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002746 ASC_DBG(1, "end\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002747 return info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748}
2749
Matthew Wilcox51219352007-10-02 21:55:22 -04002750#ifdef CONFIG_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751
2752/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 * asc_prt_board_devices()
2754 *
2755 * Print driver information for devices attached to the board.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 */
Al Virob59fb6f2013-03-31 02:59:55 -04002757static void asc_prt_board_devices(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002759 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002760 int chip_scsi_id;
2761 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762
Al Virob59fb6f2013-03-31 02:59:55 -04002763 seq_printf(m,
2764 "\nDevice Information for AdvanSys SCSI Host %d:\n",
2765 shost->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002767 if (ASC_NARROW_BOARD(boardp)) {
2768 chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
2769 } else {
2770 chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
2771 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772
Rasmus Villemoes2f979422014-12-03 00:10:50 +01002773 seq_puts(m, "Target IDs Detected:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002774 for (i = 0; i <= ADV_MAX_TID; i++) {
Al Virob59fb6f2013-03-31 02:59:55 -04002775 if (boardp->init_tidmask & ADV_TID_TO_TIDMASK(i))
2776 seq_printf(m, " %X,", i);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002777 }
Al Virob59fb6f2013-03-31 02:59:55 -04002778 seq_printf(m, " (%X=Host Adapter)\n", chip_scsi_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779}
2780
2781/*
2782 * Display Wide Board BIOS Information.
2783 */
Al Virob59fb6f2013-03-31 02:59:55 -04002784static void asc_prt_adv_bios(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002786 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002787 ushort major, minor, letter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788
Rasmus Villemoes2f979422014-12-03 00:10:50 +01002789 seq_puts(m, "\nROM BIOS Version: ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002791 /*
2792 * If the BIOS saved a valid signature, then fill in
2793 * the BIOS code segment base address.
2794 */
2795 if (boardp->bios_signature != 0x55AA) {
Rasmus Villemoes3d300792014-12-03 00:10:53 +01002796 seq_puts(m, "Disabled or Pre-3.1\n"
2797 "BIOS either disabled or Pre-3.1. If it is pre-3.1, then a newer version\n"
2798 "can be found at the ConnectCom FTP site: ftp://ftp.connectcom.net/pub\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002799 } else {
2800 major = (boardp->bios_version >> 12) & 0xF;
2801 minor = (boardp->bios_version >> 8) & 0xF;
2802 letter = (boardp->bios_version & 0xFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803
Al Virob59fb6f2013-03-31 02:59:55 -04002804 seq_printf(m, "%d.%d%c\n",
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002805 major, minor,
2806 letter >= 26 ? '?' : letter + 'A');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002807 /*
2808 * Current available ROM BIOS release is 3.1I for UW
2809 * and 3.2I for U2W. This code doesn't differentiate
2810 * UW and U2W boards.
2811 */
2812 if (major < 3 || (major <= 3 && minor < 1) ||
2813 (major <= 3 && minor <= 1 && letter < ('I' - 'A'))) {
Rasmus Villemoes3d300792014-12-03 00:10:53 +01002814 seq_puts(m, "Newer version of ROM BIOS is available at the ConnectCom FTP site:\n"
2815 "ftp://ftp.connectcom.net/pub\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002816 }
2817 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818}
2819
2820/*
2821 * Add serial number to information bar if signature AAh
2822 * is found in at bit 15-9 (7 bits) of word 1.
2823 *
2824 * Serial Number consists fo 12 alpha-numeric digits.
2825 *
2826 * 1 - Product type (A,B,C,D..) Word0: 15-13 (3 bits)
2827 * 2 - MFG Location (A,B,C,D..) Word0: 12-10 (3 bits)
2828 * 3-4 - Product ID (0-99) Word0: 9-0 (10 bits)
2829 * 5 - Product revision (A-J) Word0: " "
2830 *
2831 * Signature Word1: 15-9 (7 bits)
2832 * 6 - Year (0-9) Word1: 8-6 (3 bits) & Word2: 15 (1 bit)
2833 * 7-8 - Week of the year (1-52) Word1: 5-0 (6 bits)
2834 *
2835 * 9-12 - Serial Number (A001-Z999) Word2: 14-0 (15 bits)
2836 *
2837 * Note 1: Only production cards will have a serial number.
2838 *
2839 * Note 2: Signature is most significant 7 bits (0xFE).
2840 *
2841 * Returns ASC_TRUE if serial number found, otherwise returns ASC_FALSE.
2842 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002843static int asc_get_eeprom_string(ushort *serialnum, uchar *cp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844{
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002845 ushort w, num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002847 if ((serialnum[1] & 0xFE00) != ((ushort)0xAA << 8)) {
2848 return ASC_FALSE;
2849 } else {
2850 /*
2851 * First word - 6 digits.
2852 */
2853 w = serialnum[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002855 /* Product type - 1st digit. */
2856 if ((*cp = 'A' + ((w & 0xE000) >> 13)) == 'H') {
2857 /* Product type is P=Prototype */
2858 *cp += 0x8;
2859 }
2860 cp++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002862 /* Manufacturing location - 2nd digit. */
2863 *cp++ = 'A' + ((w & 0x1C00) >> 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002865 /* Product ID - 3rd, 4th digits. */
2866 num = w & 0x3FF;
2867 *cp++ = '0' + (num / 100);
2868 num %= 100;
2869 *cp++ = '0' + (num / 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002871 /* Product revision - 5th digit. */
2872 *cp++ = 'A' + (num % 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002874 /*
2875 * Second word
2876 */
2877 w = serialnum[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002879 /*
2880 * Year - 6th digit.
2881 *
2882 * If bit 15 of third word is set, then the
2883 * last digit of the year is greater than 7.
2884 */
2885 if (serialnum[2] & 0x8000) {
2886 *cp++ = '8' + ((w & 0x1C0) >> 6);
2887 } else {
2888 *cp++ = '0' + ((w & 0x1C0) >> 6);
2889 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002891 /* Week of year - 7th, 8th digits. */
2892 num = w & 0x003F;
2893 *cp++ = '0' + num / 10;
2894 num %= 10;
2895 *cp++ = '0' + num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002897 /*
2898 * Third word
2899 */
2900 w = serialnum[2] & 0x7FFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002902 /* Serial number - 9th digit. */
2903 *cp++ = 'A' + (w / 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002905 /* 10th, 11th, 12th digits. */
2906 num = w % 1000;
2907 *cp++ = '0' + num / 100;
2908 num %= 100;
2909 *cp++ = '0' + num / 10;
2910 num %= 10;
2911 *cp++ = '0' + num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002913 *cp = '\0'; /* Null Terminate the string. */
2914 return ASC_TRUE;
2915 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916}
2917
2918/*
2919 * asc_prt_asc_board_eeprom()
2920 *
2921 * Print board EEPROM configuration.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 */
Al Virob59fb6f2013-03-31 02:59:55 -04002923static void asc_prt_asc_board_eeprom(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002925 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002926 ASC_DVC_VAR *asc_dvc_varp;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002927 ASCEEP_CONFIG *ep;
2928 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929#ifdef CONFIG_ISA
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002930 int isa_dma_speed[] = { 10, 8, 7, 6, 5, 4, 3, 2 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931#endif /* CONFIG_ISA */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002932 uchar serialstr[13];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002934 asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
2935 ep = &boardp->eep_config.asc_eep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936
Al Virob59fb6f2013-03-31 02:59:55 -04002937 seq_printf(m,
2938 "\nEEPROM Settings for AdvanSys SCSI Host %d:\n",
2939 shost->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002941 if (asc_get_eeprom_string((ushort *)&ep->adapter_info[0], serialstr)
Al Virob59fb6f2013-03-31 02:59:55 -04002942 == ASC_TRUE)
2943 seq_printf(m, " Serial Number: %s\n", serialstr);
2944 else if (ep->adapter_info[5] == 0xBB)
Rasmus Villemoes2f979422014-12-03 00:10:50 +01002945 seq_puts(m,
2946 " Default Settings Used for EEPROM-less Adapter.\n");
Al Virob59fb6f2013-03-31 02:59:55 -04002947 else
Rasmus Villemoes2f979422014-12-03 00:10:50 +01002948 seq_puts(m, " Serial Number Signature Not Present.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949
Al Virob59fb6f2013-03-31 02:59:55 -04002950 seq_printf(m,
2951 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
2952 ASC_EEP_GET_CHIP_ID(ep), ep->max_total_qng,
2953 ep->max_tag_qng);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954
Al Virob59fb6f2013-03-31 02:59:55 -04002955 seq_printf(m,
2956 " cntl 0x%x, no_scam 0x%x\n", ep->cntl, ep->no_scam);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957
Rasmus Villemoes2f979422014-12-03 00:10:50 +01002958 seq_puts(m, " Target ID: ");
Al Virob59fb6f2013-03-31 02:59:55 -04002959 for (i = 0; i <= ASC_MAX_TID; i++)
2960 seq_printf(m, " %d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961
Rasmus Villemoes3d300792014-12-03 00:10:53 +01002962 seq_puts(m, "\n Disconnects: ");
Al Virob59fb6f2013-03-31 02:59:55 -04002963 for (i = 0; i <= ASC_MAX_TID; i++)
2964 seq_printf(m, " %c",
2965 (ep->disc_enable & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966
Rasmus Villemoes3d300792014-12-03 00:10:53 +01002967 seq_puts(m, "\n Command Queuing: ");
Al Virob59fb6f2013-03-31 02:59:55 -04002968 for (i = 0; i <= ASC_MAX_TID; i++)
2969 seq_printf(m, " %c",
2970 (ep->use_cmd_qng & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971
Rasmus Villemoes3d300792014-12-03 00:10:53 +01002972 seq_puts(m, "\n Start Motor: ");
Al Virob59fb6f2013-03-31 02:59:55 -04002973 for (i = 0; i <= ASC_MAX_TID; i++)
2974 seq_printf(m, " %c",
2975 (ep->start_motor & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976
Rasmus Villemoes3d300792014-12-03 00:10:53 +01002977 seq_puts(m, "\n Synchronous Transfer:");
Al Virob59fb6f2013-03-31 02:59:55 -04002978 for (i = 0; i <= ASC_MAX_TID; i++)
2979 seq_printf(m, " %c",
2980 (ep->init_sdtr & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01002981 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982
2983#ifdef CONFIG_ISA
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002984 if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
Al Virob59fb6f2013-03-31 02:59:55 -04002985 seq_printf(m,
2986 " Host ISA DMA speed: %d MB/S\n",
2987 isa_dma_speed[ASC_EEP_GET_DMA_SPD(ep)]);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002988 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989#endif /* CONFIG_ISA */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990}
2991
2992/*
2993 * asc_prt_adv_board_eeprom()
2994 *
2995 * Print board EEPROM configuration.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 */
Al Virob59fb6f2013-03-31 02:59:55 -04002997static void asc_prt_adv_board_eeprom(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002999 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003000 ADV_DVC_VAR *adv_dvc_varp;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003001 int i;
3002 char *termstr;
3003 uchar serialstr[13];
3004 ADVEEP_3550_CONFIG *ep_3550 = NULL;
3005 ADVEEP_38C0800_CONFIG *ep_38C0800 = NULL;
3006 ADVEEP_38C1600_CONFIG *ep_38C1600 = NULL;
3007 ushort word;
3008 ushort *wordp;
3009 ushort sdtr_speed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003011 adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
3012 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
3013 ep_3550 = &boardp->eep_config.adv_3550_eep;
3014 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
3015 ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
3016 } else {
3017 ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
3018 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019
Al Virob59fb6f2013-03-31 02:59:55 -04003020 seq_printf(m,
3021 "\nEEPROM Settings for AdvanSys SCSI Host %d:\n",
3022 shost->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003024 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
3025 wordp = &ep_3550->serial_number_word1;
3026 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
3027 wordp = &ep_38C0800->serial_number_word1;
3028 } else {
3029 wordp = &ep_38C1600->serial_number_word1;
3030 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031
Al Virob59fb6f2013-03-31 02:59:55 -04003032 if (asc_get_eeprom_string(wordp, serialstr) == ASC_TRUE)
3033 seq_printf(m, " Serial Number: %s\n", serialstr);
3034 else
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003035 seq_puts(m, " Serial Number Signature Not Present.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036
Al Virob59fb6f2013-03-31 02:59:55 -04003037 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
3038 seq_printf(m,
3039 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
3040 ep_3550->adapter_scsi_id,
3041 ep_3550->max_host_qng, ep_3550->max_dvc_qng);
3042 else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
3043 seq_printf(m,
3044 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
3045 ep_38C0800->adapter_scsi_id,
3046 ep_38C0800->max_host_qng,
3047 ep_38C0800->max_dvc_qng);
3048 else
3049 seq_printf(m,
3050 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
3051 ep_38C1600->adapter_scsi_id,
3052 ep_38C1600->max_host_qng,
3053 ep_38C1600->max_dvc_qng);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003054 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
3055 word = ep_3550->termination;
3056 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
3057 word = ep_38C0800->termination_lvd;
3058 } else {
3059 word = ep_38C1600->termination_lvd;
3060 }
3061 switch (word) {
3062 case 1:
3063 termstr = "Low Off/High Off";
3064 break;
3065 case 2:
3066 termstr = "Low Off/High On";
3067 break;
3068 case 3:
3069 termstr = "Low On/High On";
3070 break;
3071 default:
3072 case 0:
3073 termstr = "Automatic";
3074 break;
3075 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076
Al Virob59fb6f2013-03-31 02:59:55 -04003077 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
3078 seq_printf(m,
3079 " termination: %u (%s), bios_ctrl: 0x%x\n",
3080 ep_3550->termination, termstr,
3081 ep_3550->bios_ctrl);
3082 else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
3083 seq_printf(m,
3084 " termination: %u (%s), bios_ctrl: 0x%x\n",
3085 ep_38C0800->termination_lvd, termstr,
3086 ep_38C0800->bios_ctrl);
3087 else
3088 seq_printf(m,
3089 " termination: %u (%s), bios_ctrl: 0x%x\n",
3090 ep_38C1600->termination_lvd, termstr,
3091 ep_38C1600->bios_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003093 seq_puts(m, " Target ID: ");
Al Virob59fb6f2013-03-31 02:59:55 -04003094 for (i = 0; i <= ADV_MAX_TID; i++)
3095 seq_printf(m, " %X", i);
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003096 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003098 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
3099 word = ep_3550->disc_enable;
3100 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
3101 word = ep_38C0800->disc_enable;
3102 } else {
3103 word = ep_38C1600->disc_enable;
3104 }
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003105 seq_puts(m, " Disconnects: ");
Al Virob59fb6f2013-03-31 02:59:55 -04003106 for (i = 0; i <= ADV_MAX_TID; i++)
3107 seq_printf(m, " %c",
3108 (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003109 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003111 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
3112 word = ep_3550->tagqng_able;
3113 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
3114 word = ep_38C0800->tagqng_able;
3115 } else {
3116 word = ep_38C1600->tagqng_able;
3117 }
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003118 seq_puts(m, " Command Queuing: ");
Al Virob59fb6f2013-03-31 02:59:55 -04003119 for (i = 0; i <= ADV_MAX_TID; i++)
3120 seq_printf(m, " %c",
3121 (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003122 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003124 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
3125 word = ep_3550->start_motor;
3126 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
3127 word = ep_38C0800->start_motor;
3128 } else {
3129 word = ep_38C1600->start_motor;
3130 }
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003131 seq_puts(m, " Start Motor: ");
Al Virob59fb6f2013-03-31 02:59:55 -04003132 for (i = 0; i <= ADV_MAX_TID; i++)
3133 seq_printf(m, " %c",
3134 (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003135 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003137 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003138 seq_puts(m, " Synchronous Transfer:");
Al Virob59fb6f2013-03-31 02:59:55 -04003139 for (i = 0; i <= ADV_MAX_TID; i++)
3140 seq_printf(m, " %c",
3141 (ep_3550->sdtr_able & ADV_TID_TO_TIDMASK(i)) ?
3142 'Y' : 'N');
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003143 seq_putc(m, '\n');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003144 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003146 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003147 seq_puts(m, " Ultra Transfer: ");
Al Virob59fb6f2013-03-31 02:59:55 -04003148 for (i = 0; i <= ADV_MAX_TID; i++)
3149 seq_printf(m, " %c",
3150 (ep_3550->ultra_able & ADV_TID_TO_TIDMASK(i))
3151 ? 'Y' : 'N');
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003152 seq_putc(m, '\n');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003153 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003155 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
3156 word = ep_3550->wdtr_able;
3157 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
3158 word = ep_38C0800->wdtr_able;
3159 } else {
3160 word = ep_38C1600->wdtr_able;
3161 }
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003162 seq_puts(m, " Wide Transfer: ");
Al Virob59fb6f2013-03-31 02:59:55 -04003163 for (i = 0; i <= ADV_MAX_TID; i++)
3164 seq_printf(m, " %c",
3165 (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003166 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003168 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800 ||
3169 adv_dvc_varp->chip_type == ADV_CHIP_ASC38C1600) {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003170 seq_puts(m, " Synchronous Transfer Speed (Mhz):\n ");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003171 for (i = 0; i <= ADV_MAX_TID; i++) {
3172 char *speed_str;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003174 if (i == 0) {
3175 sdtr_speed = adv_dvc_varp->sdtr_speed1;
3176 } else if (i == 4) {
3177 sdtr_speed = adv_dvc_varp->sdtr_speed2;
3178 } else if (i == 8) {
3179 sdtr_speed = adv_dvc_varp->sdtr_speed3;
3180 } else if (i == 12) {
3181 sdtr_speed = adv_dvc_varp->sdtr_speed4;
3182 }
3183 switch (sdtr_speed & ADV_MAX_TID) {
3184 case 0:
3185 speed_str = "Off";
3186 break;
3187 case 1:
3188 speed_str = " 5";
3189 break;
3190 case 2:
3191 speed_str = " 10";
3192 break;
3193 case 3:
3194 speed_str = " 20";
3195 break;
3196 case 4:
3197 speed_str = " 40";
3198 break;
3199 case 5:
3200 speed_str = " 80";
3201 break;
3202 default:
3203 speed_str = "Unk";
3204 break;
3205 }
Al Virob59fb6f2013-03-31 02:59:55 -04003206 seq_printf(m, "%X:%s ", i, speed_str);
3207 if (i == 7)
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003208 seq_puts(m, "\n ");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003209 sdtr_speed >>= 4;
3210 }
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003211 seq_putc(m, '\n');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003212 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213}
3214
3215/*
3216 * asc_prt_driver_conf()
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 */
Al Virob59fb6f2013-03-31 02:59:55 -04003218static void asc_prt_driver_conf(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04003220 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003221 int chip_scsi_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222
Al Virob59fb6f2013-03-31 02:59:55 -04003223 seq_printf(m,
3224 "\nLinux Driver Configuration and Information for AdvanSys SCSI Host %d:\n",
3225 shost->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226
Al Virob59fb6f2013-03-31 02:59:55 -04003227 seq_printf(m,
Hannes Reinecke1abf6352014-06-25 15:27:38 +02003228 " host_busy %u, max_id %u, max_lun %llu, max_channel %u\n",
Christoph Hellwig74665012014-01-22 15:29:29 +01003229 atomic_read(&shost->host_busy), shost->max_id,
Al Virob59fb6f2013-03-31 02:59:55 -04003230 shost->max_lun, shost->max_channel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231
Al Virob59fb6f2013-03-31 02:59:55 -04003232 seq_printf(m,
3233 " unique_id %d, can_queue %d, this_id %d, sg_tablesize %u, cmd_per_lun %u\n",
3234 shost->unique_id, shost->can_queue, shost->this_id,
3235 shost->sg_tablesize, shost->cmd_per_lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236
Al Virob59fb6f2013-03-31 02:59:55 -04003237 seq_printf(m,
3238 " unchecked_isa_dma %d, use_clustering %d\n",
3239 shost->unchecked_isa_dma, shost->use_clustering);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240
Al Virob59fb6f2013-03-31 02:59:55 -04003241 seq_printf(m,
Al Viro31491e12013-03-31 03:04:13 -04003242 " flags 0x%x, last_reset 0x%lx, jiffies 0x%lx, asc_n_io_port 0x%x\n",
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02003243 boardp->flags, shost->last_reset, jiffies,
Al Virob59fb6f2013-03-31 02:59:55 -04003244 boardp->asc_n_io_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245
Al Viro31491e12013-03-31 03:04:13 -04003246 seq_printf(m, " io_port 0x%lx\n", shost->io_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003248 if (ASC_NARROW_BOARD(boardp)) {
3249 chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
3250 } else {
3251 chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
3252 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253}
3254
3255/*
3256 * asc_prt_asc_board_info()
3257 *
3258 * Print dynamic board configuration information.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 */
Al Virob59fb6f2013-03-31 02:59:55 -04003260static void asc_prt_asc_board_info(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04003262 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003263 int chip_scsi_id;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003264 ASC_DVC_VAR *v;
3265 ASC_DVC_CFG *c;
3266 int i;
3267 int renegotiate = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003269 v = &boardp->dvc_var.asc_dvc_var;
3270 c = &boardp->dvc_cfg.asc_dvc_cfg;
3271 chip_scsi_id = c->chip_scsi_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272
Al Virob59fb6f2013-03-31 02:59:55 -04003273 seq_printf(m,
3274 "\nAsc Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
3275 shost->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276
Al Virob59fb6f2013-03-31 02:59:55 -04003277 seq_printf(m, " chip_version %u, mcode_date 0x%x, "
3278 "mcode_version 0x%x, err_code %u\n",
3279 c->chip_version, c->mcode_date, c->mcode_version,
3280 v->err_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003282 /* Current number of commands waiting for the host. */
Al Virob59fb6f2013-03-31 02:59:55 -04003283 seq_printf(m,
3284 " Total Command Pending: %d\n", v->cur_total_qng);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003286 seq_puts(m, " Command Queuing:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003287 for (i = 0; i <= ASC_MAX_TID; i++) {
3288 if ((chip_scsi_id == i) ||
3289 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3290 continue;
3291 }
Al Virob59fb6f2013-03-31 02:59:55 -04003292 seq_printf(m, " %X:%c",
3293 i,
3294 (v->use_tagged_qng & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003295 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003297 /* Current number of commands waiting for a device. */
Rasmus Villemoes3d300792014-12-03 00:10:53 +01003298 seq_puts(m, "\n Command Queue Pending:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003299 for (i = 0; i <= ASC_MAX_TID; i++) {
3300 if ((chip_scsi_id == i) ||
3301 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3302 continue;
3303 }
Al Virob59fb6f2013-03-31 02:59:55 -04003304 seq_printf(m, " %X:%u", i, v->cur_dvc_qng[i]);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003305 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003307 /* Current limit on number of commands that can be sent to a device. */
Rasmus Villemoes3d300792014-12-03 00:10:53 +01003308 seq_puts(m, "\n Command Queue Limit:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003309 for (i = 0; i <= ASC_MAX_TID; i++) {
3310 if ((chip_scsi_id == i) ||
3311 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3312 continue;
3313 }
Al Virob59fb6f2013-03-31 02:59:55 -04003314 seq_printf(m, " %X:%u", i, v->max_dvc_qng[i]);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003315 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003317 /* Indicate whether the device has returned queue full status. */
Rasmus Villemoes3d300792014-12-03 00:10:53 +01003318 seq_puts(m, "\n Command Queue Full:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003319 for (i = 0; i <= ASC_MAX_TID; i++) {
3320 if ((chip_scsi_id == i) ||
3321 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3322 continue;
3323 }
Al Virob59fb6f2013-03-31 02:59:55 -04003324 if (boardp->queue_full & ADV_TID_TO_TIDMASK(i))
3325 seq_printf(m, " %X:Y-%d",
3326 i, boardp->queue_full_cnt[i]);
3327 else
3328 seq_printf(m, " %X:N", i);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003329 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330
Rasmus Villemoes3d300792014-12-03 00:10:53 +01003331 seq_puts(m, "\n Synchronous Transfer:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003332 for (i = 0; i <= ASC_MAX_TID; i++) {
3333 if ((chip_scsi_id == i) ||
3334 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3335 continue;
3336 }
Al Virob59fb6f2013-03-31 02:59:55 -04003337 seq_printf(m, " %X:%c",
3338 i,
3339 (v->sdtr_done & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003340 }
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003341 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003343 for (i = 0; i <= ASC_MAX_TID; i++) {
3344 uchar syn_period_ix;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003346 if ((chip_scsi_id == i) ||
3347 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) ||
3348 ((v->init_sdtr & ADV_TID_TO_TIDMASK(i)) == 0)) {
3349 continue;
3350 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351
Al Virob59fb6f2013-03-31 02:59:55 -04003352 seq_printf(m, " %X:", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003354 if ((boardp->sdtr_data[i] & ASC_SYN_MAX_OFFSET) == 0) {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003355 seq_puts(m, " Asynchronous");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003356 } else {
3357 syn_period_ix =
3358 (boardp->sdtr_data[i] >> 4) & (v->max_sdtr_index -
3359 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360
Al Virob59fb6f2013-03-31 02:59:55 -04003361 seq_printf(m,
3362 " Transfer Period Factor: %d (%d.%d Mhz),",
3363 v->sdtr_period_tbl[syn_period_ix],
3364 250 / v->sdtr_period_tbl[syn_period_ix],
3365 ASC_TENTHS(250,
3366 v->sdtr_period_tbl[syn_period_ix]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367
Al Virob59fb6f2013-03-31 02:59:55 -04003368 seq_printf(m, " REQ/ACK Offset: %d",
3369 boardp->sdtr_data[i] & ASC_SYN_MAX_OFFSET);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003370 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003372 if ((v->sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003373 seq_puts(m, "*\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003374 renegotiate = 1;
3375 } else {
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003376 seq_putc(m, '\n');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003377 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003378 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003380 if (renegotiate) {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003381 seq_puts(m, " * = Re-negotiation pending before next command.\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003382 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383}
3384
3385/*
3386 * asc_prt_adv_board_info()
3387 *
3388 * Print dynamic board configuration information.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 */
Al Virob59fb6f2013-03-31 02:59:55 -04003390static void asc_prt_adv_board_info(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04003392 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003393 int i;
3394 ADV_DVC_VAR *v;
3395 ADV_DVC_CFG *c;
3396 AdvPortAddr iop_base;
3397 ushort chip_scsi_id;
3398 ushort lramword;
3399 uchar lrambyte;
3400 ushort tagqng_able;
3401 ushort sdtr_able, wdtr_able;
3402 ushort wdtr_done, sdtr_done;
3403 ushort period = 0;
3404 int renegotiate = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003406 v = &boardp->dvc_var.adv_dvc_var;
3407 c = &boardp->dvc_cfg.adv_dvc_cfg;
3408 iop_base = v->iop_base;
3409 chip_scsi_id = v->chip_scsi_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410
Al Virob59fb6f2013-03-31 02:59:55 -04003411 seq_printf(m,
3412 "\nAdv Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
3413 shost->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414
Al Virob59fb6f2013-03-31 02:59:55 -04003415 seq_printf(m,
3416 " iop_base 0x%lx, cable_detect: %X, err_code %u\n",
Al Viro31491e12013-03-31 03:04:13 -04003417 (unsigned long)v->iop_base,
Al Virob59fb6f2013-03-31 02:59:55 -04003418 AdvReadWordRegister(iop_base,IOPW_SCSI_CFG1) & CABLE_DETECT,
3419 v->err_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420
Al Virob59fb6f2013-03-31 02:59:55 -04003421 seq_printf(m, " chip_version %u, mcode_date 0x%x, "
3422 "mcode_version 0x%x\n", c->chip_version,
3423 c->mcode_date, c->mcode_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003425 AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003426 seq_puts(m, " Queuing Enabled:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003427 for (i = 0; i <= ADV_MAX_TID; i++) {
3428 if ((chip_scsi_id == i) ||
3429 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3430 continue;
3431 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432
Al Virob59fb6f2013-03-31 02:59:55 -04003433 seq_printf(m, " %X:%c",
3434 i,
3435 (tagqng_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003436 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437
Rasmus Villemoes3d300792014-12-03 00:10:53 +01003438 seq_puts(m, "\n Queue Limit:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003439 for (i = 0; i <= ADV_MAX_TID; i++) {
3440 if ((chip_scsi_id == i) ||
3441 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3442 continue;
3443 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003445 AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + i,
3446 lrambyte);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447
Al Virob59fb6f2013-03-31 02:59:55 -04003448 seq_printf(m, " %X:%d", i, lrambyte);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003449 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450
Rasmus Villemoes3d300792014-12-03 00:10:53 +01003451 seq_puts(m, "\n Command Pending:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003452 for (i = 0; i <= ADV_MAX_TID; i++) {
3453 if ((chip_scsi_id == i) ||
3454 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3455 continue;
3456 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003458 AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_QUEUED_CMD + i,
3459 lrambyte);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460
Al Virob59fb6f2013-03-31 02:59:55 -04003461 seq_printf(m, " %X:%d", i, lrambyte);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003462 }
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003463 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003465 AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003466 seq_puts(m, " Wide Enabled:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003467 for (i = 0; i <= ADV_MAX_TID; i++) {
3468 if ((chip_scsi_id == i) ||
3469 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3470 continue;
3471 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472
Al Virob59fb6f2013-03-31 02:59:55 -04003473 seq_printf(m, " %X:%c",
3474 i,
3475 (wdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003476 }
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003477 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003478
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003479 AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, wdtr_done);
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003480 seq_puts(m, " Transfer Bit Width:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003481 for (i = 0; i <= ADV_MAX_TID; i++) {
3482 if ((chip_scsi_id == i) ||
3483 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3484 continue;
3485 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003487 AdvReadWordLram(iop_base,
3488 ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i),
3489 lramword);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490
Al Virob59fb6f2013-03-31 02:59:55 -04003491 seq_printf(m, " %X:%d",
3492 i, (lramword & 0x8000) ? 16 : 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003494 if ((wdtr_able & ADV_TID_TO_TIDMASK(i)) &&
3495 (wdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003496 seq_putc(m, '*');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003497 renegotiate = 1;
3498 }
3499 }
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003500 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003502 AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003503 seq_puts(m, " Synchronous Enabled:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003504 for (i = 0; i <= ADV_MAX_TID; i++) {
3505 if ((chip_scsi_id == i) ||
3506 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3507 continue;
3508 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003509
Al Virob59fb6f2013-03-31 02:59:55 -04003510 seq_printf(m, " %X:%c",
3511 i,
3512 (sdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003513 }
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003514 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003516 AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, sdtr_done);
3517 for (i = 0; i <= ADV_MAX_TID; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003519 AdvReadWordLram(iop_base,
3520 ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i),
3521 lramword);
3522 lramword &= ~0x8000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003524 if ((chip_scsi_id == i) ||
3525 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) ||
3526 ((sdtr_able & ADV_TID_TO_TIDMASK(i)) == 0)) {
3527 continue;
3528 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529
Al Virob59fb6f2013-03-31 02:59:55 -04003530 seq_printf(m, " %X:", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003532 if ((lramword & 0x1F) == 0) { /* Check for REQ/ACK Offset 0. */
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003533 seq_puts(m, " Asynchronous");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003534 } else {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003535 seq_puts(m, " Transfer Period Factor: ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003537 if ((lramword & 0x1F00) == 0x1100) { /* 80 Mhz */
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003538 seq_puts(m, "9 (80.0 Mhz),");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003539 } else if ((lramword & 0x1F00) == 0x1000) { /* 40 Mhz */
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003540 seq_puts(m, "10 (40.0 Mhz),");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003541 } else { /* 20 Mhz or below. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003543 period = (((lramword >> 8) * 25) + 50) / 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003545 if (period == 0) { /* Should never happen. */
Al Viro31491e12013-03-31 03:04:13 -04003546 seq_printf(m, "%d (? Mhz), ", period);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003547 } else {
Al Virob59fb6f2013-03-31 02:59:55 -04003548 seq_printf(m,
3549 "%d (%d.%d Mhz),",
3550 period, 250 / period,
3551 ASC_TENTHS(250, period));
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003552 }
3553 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554
Al Virob59fb6f2013-03-31 02:59:55 -04003555 seq_printf(m, " REQ/ACK Offset: %d",
3556 lramword & 0x1F);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003557 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003558
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003559 if ((sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003560 seq_puts(m, "*\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003561 renegotiate = 1;
3562 } else {
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003563 seq_putc(m, '\n');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003564 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003565 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003567 if (renegotiate) {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003568 seq_puts(m, " * = Re-negotiation pending before next command.\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003569 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003570}
3571
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572#ifdef ADVANSYS_STATS
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573/*
3574 * asc_prt_board_stats()
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575 */
Al Virob59fb6f2013-03-31 02:59:55 -04003576static void asc_prt_board_stats(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003577{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04003578 struct asc_board *boardp = shost_priv(shost);
3579 struct asc_stats *s = &boardp->asc_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003580
Al Virob59fb6f2013-03-31 02:59:55 -04003581 seq_printf(m,
3582 "\nLinux Driver Statistics for AdvanSys SCSI Host %d:\n",
3583 shost->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584
Al Virob59fb6f2013-03-31 02:59:55 -04003585 seq_printf(m,
Al Viro31491e12013-03-31 03:04:13 -04003586 " queuecommand %u, reset %u, biosparam %u, interrupt %u\n",
Al Virob59fb6f2013-03-31 02:59:55 -04003587 s->queuecommand, s->reset, s->biosparam,
3588 s->interrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003589
Al Virob59fb6f2013-03-31 02:59:55 -04003590 seq_printf(m,
Al Viro31491e12013-03-31 03:04:13 -04003591 " callback %u, done %u, build_error %u, build_noreq %u, build_nosg %u\n",
Al Virob59fb6f2013-03-31 02:59:55 -04003592 s->callback, s->done, s->build_error,
3593 s->adv_build_noreq, s->adv_build_nosg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003594
Al Virob59fb6f2013-03-31 02:59:55 -04003595 seq_printf(m,
Al Viro31491e12013-03-31 03:04:13 -04003596 " exe_noerror %u, exe_busy %u, exe_error %u, exe_unknown %u\n",
Al Virob59fb6f2013-03-31 02:59:55 -04003597 s->exe_noerror, s->exe_busy, s->exe_error,
3598 s->exe_unknown);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003599
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003600 /*
3601 * Display data transfer statistics.
3602 */
Matthew Wilcox52c334e2007-10-02 21:55:39 -04003603 if (s->xfer_cnt > 0) {
Al Viro31491e12013-03-31 03:04:13 -04003604 seq_printf(m, " xfer_cnt %u, xfer_elem %u, ",
Al Virob59fb6f2013-03-31 02:59:55 -04003605 s->xfer_cnt, s->xfer_elem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606
Al Viro31491e12013-03-31 03:04:13 -04003607 seq_printf(m, "xfer_bytes %u.%01u kb\n",
Al Virob59fb6f2013-03-31 02:59:55 -04003608 s->xfer_sect / 2, ASC_TENTHS(s->xfer_sect, 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003609
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003610 /* Scatter gather transfer statistics */
Al Viro31491e12013-03-31 03:04:13 -04003611 seq_printf(m, " avg_num_elem %u.%01u, ",
Al Virob59fb6f2013-03-31 02:59:55 -04003612 s->xfer_elem / s->xfer_cnt,
3613 ASC_TENTHS(s->xfer_elem, s->xfer_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614
Al Viro31491e12013-03-31 03:04:13 -04003615 seq_printf(m, "avg_elem_size %u.%01u kb, ",
Al Virob59fb6f2013-03-31 02:59:55 -04003616 (s->xfer_sect / 2) / s->xfer_elem,
3617 ASC_TENTHS((s->xfer_sect / 2), s->xfer_elem));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003618
Al Viro31491e12013-03-31 03:04:13 -04003619 seq_printf(m, "avg_xfer_size %u.%01u kb\n",
Al Virob59fb6f2013-03-31 02:59:55 -04003620 (s->xfer_sect / 2) / s->xfer_cnt,
3621 ASC_TENTHS((s->xfer_sect / 2), s->xfer_cnt));
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003622 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003623}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624#endif /* ADVANSYS_STATS */
3625
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626/*
Al Virob59fb6f2013-03-31 02:59:55 -04003627 * advansys_show_info() - /proc/scsi/advansys/{0,1,2,3,...}
Matthew Wilcox51219352007-10-02 21:55:22 -04003628 *
Al Virob59fb6f2013-03-31 02:59:55 -04003629 * m: seq_file to print into
3630 * shost: Scsi_Host
Matthew Wilcox51219352007-10-02 21:55:22 -04003631 *
3632 * Return the number of bytes read from or written to a
3633 * /proc/scsi/advansys/[0...] file.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634 */
Matthew Wilcox51219352007-10-02 21:55:22 -04003635static int
Al Virob59fb6f2013-03-31 02:59:55 -04003636advansys_show_info(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04003638 struct asc_board *boardp = shost_priv(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003639
Matthew Wilcoxb352f922007-10-02 21:55:33 -04003640 ASC_DBG(1, "begin\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641
Matthew Wilcox51219352007-10-02 21:55:22 -04003642 /*
Matthew Wilcox51219352007-10-02 21:55:22 -04003643 * User read of /proc/scsi/advansys/[0...] file.
3644 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645
Matthew Wilcox51219352007-10-02 21:55:22 -04003646 /*
3647 * Get board configuration information.
3648 *
3649 * advansys_info() returns the board string from its own static buffer.
3650 */
Matthew Wilcox51219352007-10-02 21:55:22 -04003651 /* Copy board information. */
Al Virob59fb6f2013-03-31 02:59:55 -04003652 seq_printf(m, "%s\n", (char *)advansys_info(shost));
Matthew Wilcox51219352007-10-02 21:55:22 -04003653 /*
3654 * Display Wide Board BIOS Information.
3655 */
Al Virob59fb6f2013-03-31 02:59:55 -04003656 if (!ASC_NARROW_BOARD(boardp))
3657 asc_prt_adv_bios(m, shost);
Matthew Wilcox51219352007-10-02 21:55:22 -04003658
3659 /*
3660 * Display driver information for each device attached to the board.
3661 */
Al Virob59fb6f2013-03-31 02:59:55 -04003662 asc_prt_board_devices(m, shost);
Matthew Wilcox51219352007-10-02 21:55:22 -04003663
3664 /*
3665 * Display EEPROM configuration for the board.
3666 */
Al Virob59fb6f2013-03-31 02:59:55 -04003667 if (ASC_NARROW_BOARD(boardp))
3668 asc_prt_asc_board_eeprom(m, shost);
3669 else
3670 asc_prt_adv_board_eeprom(m, shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671
Matthew Wilcox51219352007-10-02 21:55:22 -04003672 /*
3673 * Display driver configuration and information for the board.
3674 */
Al Virob59fb6f2013-03-31 02:59:55 -04003675 asc_prt_driver_conf(m, shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676
Matthew Wilcox51219352007-10-02 21:55:22 -04003677#ifdef ADVANSYS_STATS
3678 /*
3679 * Display driver statistics for the board.
3680 */
Al Virob59fb6f2013-03-31 02:59:55 -04003681 asc_prt_board_stats(m, shost);
Matthew Wilcox51219352007-10-02 21:55:22 -04003682#endif /* ADVANSYS_STATS */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683
Matthew Wilcox51219352007-10-02 21:55:22 -04003684 /*
3685 * Display Asc Library dynamic configuration information
3686 * for the board.
3687 */
Al Virob59fb6f2013-03-31 02:59:55 -04003688 if (ASC_NARROW_BOARD(boardp))
3689 asc_prt_asc_board_info(m, shost);
3690 else
3691 asc_prt_adv_board_info(m, shost);
3692 return 0;
Matthew Wilcox51219352007-10-02 21:55:22 -04003693}
3694#endif /* CONFIG_PROC_FS */
3695
3696static void asc_scsi_done(struct scsi_cmnd *scp)
3697{
Matthew Wilcox52c334e2007-10-02 21:55:39 -04003698 scsi_dma_unmap(scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04003699 ASC_STATS(scp->device->host, done);
Matthew Wilcox51219352007-10-02 21:55:22 -04003700 scp->scsi_done(scp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701}
3702
Matthew Wilcox51219352007-10-02 21:55:22 -04003703static void AscSetBank(PortAddr iop_base, uchar bank)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704{
Matthew Wilcox51219352007-10-02 21:55:22 -04003705 uchar val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003706
Matthew Wilcox51219352007-10-02 21:55:22 -04003707 val = AscGetChipControl(iop_base) &
3708 (~
3709 (CC_SINGLE_STEP | CC_TEST | CC_DIAG | CC_SCSI_RESET |
3710 CC_CHIP_RESET));
3711 if (bank == 1) {
3712 val |= CC_BANK_ONE;
3713 } else if (bank == 2) {
3714 val |= CC_DIAG | CC_BANK_ONE;
3715 } else {
3716 val &= ~CC_BANK_ONE;
3717 }
3718 AscSetChipControl(iop_base, val);
Matthew Wilcox51219352007-10-02 21:55:22 -04003719}
3720
3721static void AscSetChipIH(PortAddr iop_base, ushort ins_code)
3722{
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003723 AscSetBank(iop_base, 1);
Matthew Wilcox51219352007-10-02 21:55:22 -04003724 AscWriteChipIH(iop_base, ins_code);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003725 AscSetBank(iop_base, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726}
3727
Matthew Wilcox51219352007-10-02 21:55:22 -04003728static int AscStartChip(PortAddr iop_base)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729{
Matthew Wilcox51219352007-10-02 21:55:22 -04003730 AscSetChipControl(iop_base, 0);
3731 if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) {
3732 return (0);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003733 }
Matthew Wilcox51219352007-10-02 21:55:22 -04003734 return (1);
3735}
3736
Hannes Reineckeae267592015-04-24 13:18:28 +02003737static bool AscStopChip(PortAddr iop_base)
Matthew Wilcox51219352007-10-02 21:55:22 -04003738{
3739 uchar cc_val;
3740
3741 cc_val =
3742 AscGetChipControl(iop_base) &
3743 (~(CC_SINGLE_STEP | CC_TEST | CC_DIAG));
3744 AscSetChipControl(iop_base, (uchar)(cc_val | CC_HALT));
3745 AscSetChipIH(iop_base, INS_HALT);
3746 AscSetChipIH(iop_base, INS_RFLAG_WTM);
3747 if ((AscGetChipStatus(iop_base) & CSW_HALTED) == 0) {
Hannes Reineckeae267592015-04-24 13:18:28 +02003748 return false;
Matthew Wilcox51219352007-10-02 21:55:22 -04003749 }
Hannes Reineckeae267592015-04-24 13:18:28 +02003750 return true;
Matthew Wilcox51219352007-10-02 21:55:22 -04003751}
3752
Hannes Reinecked647c782015-04-24 13:18:26 +02003753static bool AscIsChipHalted(PortAddr iop_base)
Matthew Wilcox51219352007-10-02 21:55:22 -04003754{
3755 if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) {
3756 if ((AscGetChipControl(iop_base) & CC_HALT) != 0) {
Hannes Reinecked647c782015-04-24 13:18:26 +02003757 return true;
Matthew Wilcox51219352007-10-02 21:55:22 -04003758 }
3759 }
Hannes Reinecked647c782015-04-24 13:18:26 +02003760 return false;
Matthew Wilcox51219352007-10-02 21:55:22 -04003761}
3762
Hannes Reinecked647c782015-04-24 13:18:26 +02003763static bool AscResetChipAndScsiBus(ASC_DVC_VAR *asc_dvc)
Matthew Wilcox51219352007-10-02 21:55:22 -04003764{
3765 PortAddr iop_base;
3766 int i = 10;
3767
3768 iop_base = asc_dvc->iop_base;
3769 while ((AscGetChipStatus(iop_base) & CSW_SCSI_RESET_ACTIVE)
3770 && (i-- > 0)) {
3771 mdelay(100);
3772 }
3773 AscStopChip(iop_base);
3774 AscSetChipControl(iop_base, CC_CHIP_RESET | CC_SCSI_RESET | CC_HALT);
3775 udelay(60);
3776 AscSetChipIH(iop_base, INS_RFLAG_WTM);
3777 AscSetChipIH(iop_base, INS_HALT);
3778 AscSetChipControl(iop_base, CC_CHIP_RESET | CC_HALT);
3779 AscSetChipControl(iop_base, CC_HALT);
3780 mdelay(200);
3781 AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
3782 AscSetChipStatus(iop_base, 0);
3783 return (AscIsChipHalted(iop_base));
3784}
3785
3786static int AscFindSignature(PortAddr iop_base)
3787{
3788 ushort sig_word;
3789
Matthew Wilcoxb352f922007-10-02 21:55:33 -04003790 ASC_DBG(1, "AscGetChipSignatureByte(0x%x) 0x%x\n",
Matthew Wilcox51219352007-10-02 21:55:22 -04003791 iop_base, AscGetChipSignatureByte(iop_base));
3792 if (AscGetChipSignatureByte(iop_base) == (uchar)ASC_1000_ID1B) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04003793 ASC_DBG(1, "AscGetChipSignatureWord(0x%x) 0x%x\n",
Matthew Wilcox51219352007-10-02 21:55:22 -04003794 iop_base, AscGetChipSignatureWord(iop_base));
3795 sig_word = AscGetChipSignatureWord(iop_base);
3796 if ((sig_word == (ushort)ASC_1000_ID0W) ||
3797 (sig_word == (ushort)ASC_1000_ID0W_FIX)) {
3798 return (1);
3799 }
3800 }
3801 return (0);
3802}
3803
3804static void AscEnableInterrupt(PortAddr iop_base)
3805{
3806 ushort cfg;
3807
3808 cfg = AscGetChipCfgLsw(iop_base);
3809 AscSetChipCfgLsw(iop_base, cfg | ASC_CFG0_HOST_INT_ON);
Matthew Wilcox51219352007-10-02 21:55:22 -04003810}
3811
3812static void AscDisableInterrupt(PortAddr iop_base)
3813{
3814 ushort cfg;
3815
3816 cfg = AscGetChipCfgLsw(iop_base);
3817 AscSetChipCfgLsw(iop_base, cfg & (~ASC_CFG0_HOST_INT_ON));
Matthew Wilcox51219352007-10-02 21:55:22 -04003818}
3819
3820static uchar AscReadLramByte(PortAddr iop_base, ushort addr)
3821{
3822 unsigned char byte_data;
3823 unsigned short word_data;
3824
3825 if (isodd_word(addr)) {
3826 AscSetChipLramAddr(iop_base, addr - 1);
3827 word_data = AscGetChipLramData(iop_base);
3828 byte_data = (word_data >> 8) & 0xFF;
3829 } else {
3830 AscSetChipLramAddr(iop_base, addr);
3831 word_data = AscGetChipLramData(iop_base);
3832 byte_data = word_data & 0xFF;
3833 }
3834 return byte_data;
3835}
3836
3837static ushort AscReadLramWord(PortAddr iop_base, ushort addr)
3838{
3839 ushort word_data;
3840
3841 AscSetChipLramAddr(iop_base, addr);
3842 word_data = AscGetChipLramData(iop_base);
3843 return (word_data);
3844}
3845
3846#if CC_VERY_LONG_SG_LIST
Hannes Reinecke95cfab62015-04-24 13:18:27 +02003847static u32 AscReadLramDWord(PortAddr iop_base, ushort addr)
Matthew Wilcox51219352007-10-02 21:55:22 -04003848{
3849 ushort val_low, val_high;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02003850 u32 dword_data;
Matthew Wilcox51219352007-10-02 21:55:22 -04003851
3852 AscSetChipLramAddr(iop_base, addr);
3853 val_low = AscGetChipLramData(iop_base);
3854 val_high = AscGetChipLramData(iop_base);
Hannes Reinecke95cfab62015-04-24 13:18:27 +02003855 dword_data = ((u32) val_high << 16) | (u32) val_low;
Matthew Wilcox51219352007-10-02 21:55:22 -04003856 return (dword_data);
3857}
3858#endif /* CC_VERY_LONG_SG_LIST */
3859
3860static void
3861AscMemWordSetLram(PortAddr iop_base, ushort s_addr, ushort set_wval, int words)
3862{
3863 int i;
3864
3865 AscSetChipLramAddr(iop_base, s_addr);
3866 for (i = 0; i < words; i++) {
3867 AscSetChipLramData(iop_base, set_wval);
3868 }
3869}
3870
3871static void AscWriteLramWord(PortAddr iop_base, ushort addr, ushort word_val)
3872{
3873 AscSetChipLramAddr(iop_base, addr);
3874 AscSetChipLramData(iop_base, word_val);
Matthew Wilcox51219352007-10-02 21:55:22 -04003875}
3876
3877static void AscWriteLramByte(PortAddr iop_base, ushort addr, uchar byte_val)
3878{
3879 ushort word_data;
3880
3881 if (isodd_word(addr)) {
3882 addr--;
3883 word_data = AscReadLramWord(iop_base, addr);
3884 word_data &= 0x00FF;
3885 word_data |= (((ushort)byte_val << 8) & 0xFF00);
3886 } else {
3887 word_data = AscReadLramWord(iop_base, addr);
3888 word_data &= 0xFF00;
3889 word_data |= ((ushort)byte_val & 0x00FF);
3890 }
3891 AscWriteLramWord(iop_base, addr, word_data);
Matthew Wilcox51219352007-10-02 21:55:22 -04003892}
3893
3894/*
3895 * Copy 2 bytes to LRAM.
3896 *
3897 * The source data is assumed to be in little-endian order in memory
3898 * and is maintained in little-endian order when written to LRAM.
3899 */
3900static void
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05303901AscMemWordCopyPtrToLram(PortAddr iop_base, ushort s_addr,
3902 const uchar *s_buffer, int words)
Matthew Wilcox51219352007-10-02 21:55:22 -04003903{
3904 int i;
3905
3906 AscSetChipLramAddr(iop_base, s_addr);
3907 for (i = 0; i < 2 * words; i += 2) {
3908 /*
3909 * On a little-endian system the second argument below
3910 * produces a little-endian ushort which is written to
3911 * LRAM in little-endian order. On a big-endian system
3912 * the second argument produces a big-endian ushort which
3913 * is "transparently" byte-swapped by outpw() and written
3914 * in little-endian order to LRAM.
3915 */
3916 outpw(iop_base + IOP_RAM_DATA,
3917 ((ushort)s_buffer[i + 1] << 8) | s_buffer[i]);
3918 }
Matthew Wilcox51219352007-10-02 21:55:22 -04003919}
3920
3921/*
3922 * Copy 4 bytes to LRAM.
3923 *
3924 * The source data is assumed to be in little-endian order in memory
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003925 * and is maintained in little-endian order when written to LRAM.
Matthew Wilcox51219352007-10-02 21:55:22 -04003926 */
3927static void
3928AscMemDWordCopyPtrToLram(PortAddr iop_base,
3929 ushort s_addr, uchar *s_buffer, int dwords)
3930{
3931 int i;
3932
3933 AscSetChipLramAddr(iop_base, s_addr);
3934 for (i = 0; i < 4 * dwords; i += 4) {
3935 outpw(iop_base + IOP_RAM_DATA, ((ushort)s_buffer[i + 1] << 8) | s_buffer[i]); /* LSW */
3936 outpw(iop_base + IOP_RAM_DATA, ((ushort)s_buffer[i + 3] << 8) | s_buffer[i + 2]); /* MSW */
3937 }
Matthew Wilcox51219352007-10-02 21:55:22 -04003938}
3939
3940/*
3941 * Copy 2 bytes from LRAM.
3942 *
3943 * The source data is assumed to be in little-endian order in LRAM
3944 * and is maintained in little-endian order when written to memory.
3945 */
3946static void
3947AscMemWordCopyPtrFromLram(PortAddr iop_base,
3948 ushort s_addr, uchar *d_buffer, int words)
3949{
3950 int i;
3951 ushort word;
3952
3953 AscSetChipLramAddr(iop_base, s_addr);
3954 for (i = 0; i < 2 * words; i += 2) {
3955 word = inpw(iop_base + IOP_RAM_DATA);
3956 d_buffer[i] = word & 0xff;
3957 d_buffer[i + 1] = (word >> 8) & 0xff;
3958 }
Matthew Wilcox51219352007-10-02 21:55:22 -04003959}
3960
Hannes Reinecke95cfab62015-04-24 13:18:27 +02003961static u32 AscMemSumLramWord(PortAddr iop_base, ushort s_addr, int words)
Matthew Wilcox51219352007-10-02 21:55:22 -04003962{
Hannes Reinecke95cfab62015-04-24 13:18:27 +02003963 u32 sum = 0;
Matthew Wilcox51219352007-10-02 21:55:22 -04003964 int i;
3965
Matthew Wilcox51219352007-10-02 21:55:22 -04003966 for (i = 0; i < words; i++, s_addr += 2) {
3967 sum += AscReadLramWord(iop_base, s_addr);
3968 }
3969 return (sum);
3970}
3971
Hannes Reineckef33134e2015-04-24 13:18:31 +02003972static void AscInitLram(ASC_DVC_VAR *asc_dvc)
Matthew Wilcox51219352007-10-02 21:55:22 -04003973{
3974 uchar i;
3975 ushort s_addr;
3976 PortAddr iop_base;
Matthew Wilcox51219352007-10-02 21:55:22 -04003977
3978 iop_base = asc_dvc->iop_base;
Matthew Wilcox51219352007-10-02 21:55:22 -04003979 AscMemWordSetLram(iop_base, ASC_QADR_BEG, 0,
3980 (ushort)(((int)(asc_dvc->max_total_qng + 2 + 1) *
3981 64) >> 1));
3982 i = ASC_MIN_ACTIVE_QNO;
3983 s_addr = ASC_QADR_BEG + ASC_QBLK_SIZE;
3984 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
3985 (uchar)(i + 1));
3986 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
3987 (uchar)(asc_dvc->max_total_qng));
3988 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
3989 (uchar)i);
3990 i++;
3991 s_addr += ASC_QBLK_SIZE;
3992 for (; i < asc_dvc->max_total_qng; i++, s_addr += ASC_QBLK_SIZE) {
3993 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
3994 (uchar)(i + 1));
3995 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
3996 (uchar)(i - 1));
3997 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
3998 (uchar)i);
3999 }
4000 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
4001 (uchar)ASC_QLINK_END);
4002 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
4003 (uchar)(asc_dvc->max_total_qng - 1));
4004 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
4005 (uchar)asc_dvc->max_total_qng);
4006 i++;
4007 s_addr += ASC_QBLK_SIZE;
4008 for (; i <= (uchar)(asc_dvc->max_total_qng + 3);
4009 i++, s_addr += ASC_QBLK_SIZE) {
4010 AscWriteLramByte(iop_base,
4011 (ushort)(s_addr + (ushort)ASC_SCSIQ_B_FWD), i);
4012 AscWriteLramByte(iop_base,
4013 (ushort)(s_addr + (ushort)ASC_SCSIQ_B_BWD), i);
4014 AscWriteLramByte(iop_base,
4015 (ushort)(s_addr + (ushort)ASC_SCSIQ_B_QNO), i);
4016 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017}
4018
Hannes Reinecke95cfab62015-04-24 13:18:27 +02004019static u32
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304020AscLoadMicroCode(PortAddr iop_base, ushort s_addr,
4021 const uchar *mcode_buf, ushort mcode_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022{
Hannes Reinecke95cfab62015-04-24 13:18:27 +02004023 u32 chksum;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004024 ushort mcode_word_size;
4025 ushort mcode_chksum;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004026
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004027 /* Write the microcode buffer starting at LRAM address 0. */
4028 mcode_word_size = (ushort)(mcode_size >> 1);
4029 AscMemWordSetLram(iop_base, s_addr, 0, mcode_word_size);
4030 AscMemWordCopyPtrToLram(iop_base, s_addr, mcode_buf, mcode_word_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004031
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004032 chksum = AscMemSumLramWord(iop_base, s_addr, mcode_word_size);
Matthew Wilcoxb352f922007-10-02 21:55:33 -04004033 ASC_DBG(1, "chksum 0x%lx\n", (ulong)chksum);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004034 mcode_chksum = (ushort)AscMemSumLramWord(iop_base,
4035 (ushort)ASC_CODE_SEC_BEG,
4036 (ushort)((mcode_size -
4037 s_addr - (ushort)
4038 ASC_CODE_SEC_BEG) /
4039 2));
Matthew Wilcoxb352f922007-10-02 21:55:33 -04004040 ASC_DBG(1, "mcode_chksum 0x%lx\n", (ulong)mcode_chksum);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004041 AscWriteLramWord(iop_base, ASCV_MCODE_CHKSUM_W, mcode_chksum);
4042 AscWriteLramWord(iop_base, ASCV_MCODE_SIZE_W, mcode_size);
Matthew Wilcoxb352f922007-10-02 21:55:33 -04004043 return chksum;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004044}
4045
Matthew Wilcox51219352007-10-02 21:55:22 -04004046static void AscInitQLinkVar(ASC_DVC_VAR *asc_dvc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047{
Matthew Wilcox51219352007-10-02 21:55:22 -04004048 PortAddr iop_base;
4049 int i;
4050 ushort lram_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004051
Matthew Wilcox51219352007-10-02 21:55:22 -04004052 iop_base = asc_dvc->iop_base;
4053 AscPutRiscVarFreeQHead(iop_base, 1);
4054 AscPutRiscVarDoneQTail(iop_base, asc_dvc->max_total_qng);
4055 AscPutVarFreeQHead(iop_base, 1);
4056 AscPutVarDoneQTail(iop_base, asc_dvc->max_total_qng);
4057 AscWriteLramByte(iop_base, ASCV_BUSY_QHEAD_B,
4058 (uchar)((int)asc_dvc->max_total_qng + 1));
4059 AscWriteLramByte(iop_base, ASCV_DISC1_QHEAD_B,
4060 (uchar)((int)asc_dvc->max_total_qng + 2));
4061 AscWriteLramByte(iop_base, (ushort)ASCV_TOTAL_READY_Q_B,
4062 asc_dvc->max_total_qng);
4063 AscWriteLramWord(iop_base, ASCV_ASCDVC_ERR_CODE_W, 0);
4064 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
4065 AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, 0);
4066 AscWriteLramByte(iop_base, ASCV_SCSIBUSY_B, 0);
4067 AscWriteLramByte(iop_base, ASCV_WTM_FLAG_B, 0);
4068 AscPutQDoneInProgress(iop_base, 0);
4069 lram_addr = ASC_QADR_BEG;
4070 for (i = 0; i < 32; i++, lram_addr += 2) {
4071 AscWriteLramWord(iop_base, lram_addr, 0);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004072 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073}
4074
Hannes Reineckef33134e2015-04-24 13:18:31 +02004075static int AscInitMicroCodeVar(ASC_DVC_VAR *asc_dvc)
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004076{
Matthew Wilcox51219352007-10-02 21:55:22 -04004077 int i;
Hannes Reineckef33134e2015-04-24 13:18:31 +02004078 int warn_code;
Matthew Wilcox51219352007-10-02 21:55:22 -04004079 PortAddr iop_base;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02004080 __le32 phy_addr;
4081 __le32 phy_size;
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -04004082 struct asc_board *board = asc_dvc_to_board(asc_dvc);
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004083
Matthew Wilcox51219352007-10-02 21:55:22 -04004084 iop_base = asc_dvc->iop_base;
4085 warn_code = 0;
4086 for (i = 0; i <= ASC_MAX_TID; i++) {
4087 AscPutMCodeInitSDTRAtID(iop_base, i,
4088 asc_dvc->cfg->sdtr_period_offset[i]);
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004089 }
4090
Matthew Wilcox51219352007-10-02 21:55:22 -04004091 AscInitQLinkVar(asc_dvc);
4092 AscWriteLramByte(iop_base, ASCV_DISC_ENABLE_B,
4093 asc_dvc->cfg->disc_enable);
4094 AscWriteLramByte(iop_base, ASCV_HOSTSCSI_ID_B,
4095 ASC_TID_TO_TARGET_ID(asc_dvc->cfg->chip_scsi_id));
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004096
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -04004097 /* Ensure overrun buffer is aligned on an 8 byte boundary. */
4098 BUG_ON((unsigned long)asc_dvc->overrun_buf & 7);
4099 asc_dvc->overrun_dma = dma_map_single(board->dev, asc_dvc->overrun_buf,
4100 ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -03004101 if (dma_mapping_error(board->dev, asc_dvc->overrun_dma)) {
4102 warn_code = -ENOMEM;
4103 goto err_dma_map;
4104 }
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -04004105 phy_addr = cpu_to_le32(asc_dvc->overrun_dma);
Matthew Wilcox51219352007-10-02 21:55:22 -04004106 AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_PADDR_D,
4107 (uchar *)&phy_addr, 1);
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -04004108 phy_size = cpu_to_le32(ASC_OVERRUN_BSIZE);
Matthew Wilcox51219352007-10-02 21:55:22 -04004109 AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_BSIZE_D,
4110 (uchar *)&phy_size, 1);
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004111
Matthew Wilcox51219352007-10-02 21:55:22 -04004112 asc_dvc->cfg->mcode_date =
4113 AscReadLramWord(iop_base, (ushort)ASCV_MC_DATE_W);
4114 asc_dvc->cfg->mcode_version =
4115 AscReadLramWord(iop_base, (ushort)ASCV_MC_VER_W);
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004116
Matthew Wilcox51219352007-10-02 21:55:22 -04004117 AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
4118 if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
4119 asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
Hannes Reineckef33134e2015-04-24 13:18:31 +02004120 warn_code = -EINVAL;
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -03004121 goto err_mcode_start;
Matthew Wilcox51219352007-10-02 21:55:22 -04004122 }
4123 if (AscStartChip(iop_base) != 1) {
4124 asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
Hannes Reineckef33134e2015-04-24 13:18:31 +02004125 warn_code = -EIO;
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -03004126 goto err_mcode_start;
Matthew Wilcox51219352007-10-02 21:55:22 -04004127 }
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004128
Matthew Wilcox51219352007-10-02 21:55:22 -04004129 return warn_code;
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -03004130
4131err_mcode_start:
4132 dma_unmap_single(board->dev, asc_dvc->overrun_dma,
4133 ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
4134err_dma_map:
4135 asc_dvc->overrun_dma = 0;
4136 return warn_code;
Matthew Wilcox51219352007-10-02 21:55:22 -04004137}
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004138
Hannes Reineckef33134e2015-04-24 13:18:31 +02004139static int AscInitAsc1000Driver(ASC_DVC_VAR *asc_dvc)
Matthew Wilcox51219352007-10-02 21:55:22 -04004140{
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304141 const struct firmware *fw;
4142 const char fwname[] = "advansys/mcode.bin";
4143 int err;
4144 unsigned long chksum;
Hannes Reineckef33134e2015-04-24 13:18:31 +02004145 int warn_code;
Matthew Wilcox51219352007-10-02 21:55:22 -04004146 PortAddr iop_base;
4147
4148 iop_base = asc_dvc->iop_base;
4149 warn_code = 0;
4150 if ((asc_dvc->dvc_cntl & ASC_CNTL_RESET_SCSI) &&
4151 !(asc_dvc->init_state & ASC_INIT_RESET_SCSI_DONE)) {
4152 AscResetChipAndScsiBus(asc_dvc);
4153 mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
4154 }
4155 asc_dvc->init_state |= ASC_INIT_STATE_BEG_LOAD_MC;
4156 if (asc_dvc->err_code != 0)
Hannes Reineckef33134e2015-04-24 13:18:31 +02004157 return ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04004158 if (!AscFindSignature(asc_dvc->iop_base)) {
4159 asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
4160 return warn_code;
4161 }
4162 AscDisableInterrupt(iop_base);
Hannes Reineckef33134e2015-04-24 13:18:31 +02004163 AscInitLram(asc_dvc);
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304164
4165 err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
4166 if (err) {
4167 printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
4168 fwname, err);
Herton Ronaldo Krzesinskicf747442010-03-19 19:37:26 -03004169 asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304170 return err;
4171 }
4172 if (fw->size < 4) {
4173 printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
4174 fw->size, fwname);
4175 release_firmware(fw);
Herton Ronaldo Krzesinskicf747442010-03-19 19:37:26 -03004176 asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304177 return -EINVAL;
4178 }
4179 chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
4180 (fw->data[1] << 8) | fw->data[0];
4181 ASC_DBG(1, "_asc_mcode_chksum 0x%lx\n", (ulong)chksum);
4182 if (AscLoadMicroCode(iop_base, 0, &fw->data[4],
4183 fw->size - 4) != chksum) {
Matthew Wilcox51219352007-10-02 21:55:22 -04004184 asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304185 release_firmware(fw);
Matthew Wilcox51219352007-10-02 21:55:22 -04004186 return warn_code;
4187 }
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304188 release_firmware(fw);
Matthew Wilcox51219352007-10-02 21:55:22 -04004189 warn_code |= AscInitMicroCodeVar(asc_dvc);
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -03004190 if (!asc_dvc->overrun_dma)
4191 return warn_code;
Matthew Wilcox51219352007-10-02 21:55:22 -04004192 asc_dvc->init_state |= ASC_INIT_STATE_END_LOAD_MC;
4193 AscEnableInterrupt(iop_base);
4194 return warn_code;
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004195}
4196
Linus Torvalds1da177e2005-04-16 15:20:36 -07004197/*
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004198 * Load the Microcode
4199 *
4200 * Write the microcode image to RISC memory starting at address 0.
4201 *
4202 * The microcode is stored compressed in the following format:
4203 *
4204 * 254 word (508 byte) table indexed by byte code followed
4205 * by the following byte codes:
4206 *
4207 * 1-Byte Code:
4208 * 00: Emit word 0 in table.
4209 * 01: Emit word 1 in table.
4210 * .
4211 * FD: Emit word 253 in table.
4212 *
4213 * Multi-Byte Code:
4214 * FE WW WW: (3 byte code) Word to emit is the next word WW WW.
4215 * FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
4216 *
4217 * Returns 0 or an error if the checksum doesn't match
4218 */
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304219static int AdvLoadMicrocode(AdvPortAddr iop_base, const unsigned char *buf,
4220 int size, int memsize, int chksum)
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004221{
4222 int i, j, end, len = 0;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02004223 u32 sum;
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004224
4225 AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
4226
4227 for (i = 253 * 2; i < size; i++) {
4228 if (buf[i] == 0xff) {
4229 unsigned short word = (buf[i + 3] << 8) | buf[i + 2];
4230 for (j = 0; j < buf[i + 1]; j++) {
4231 AdvWriteWordAutoIncLram(iop_base, word);
4232 len += 2;
4233 }
4234 i += 3;
4235 } else if (buf[i] == 0xfe) {
4236 unsigned short word = (buf[i + 2] << 8) | buf[i + 1];
4237 AdvWriteWordAutoIncLram(iop_base, word);
4238 i += 2;
4239 len += 2;
4240 } else {
Matthew Wilcox951b62c2007-10-05 15:57:06 -04004241 unsigned int off = buf[i] * 2;
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004242 unsigned short word = (buf[off + 1] << 8) | buf[off];
4243 AdvWriteWordAutoIncLram(iop_base, word);
4244 len += 2;
4245 }
4246 }
4247
4248 end = len;
4249
4250 while (len < memsize) {
4251 AdvWriteWordAutoIncLram(iop_base, 0);
4252 len += 2;
4253 }
4254
4255 /* Verify the microcode checksum. */
4256 sum = 0;
4257 AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
4258
4259 for (len = 0; len < end; len += 2) {
4260 sum += AdvReadWordAutoIncLram(iop_base);
4261 }
4262
4263 if (sum != chksum)
4264 return ASC_IERR_MCODE_CHKSUM;
4265
4266 return 0;
4267}
4268
Hannes Reinecke98b96a72015-04-24 13:18:23 +02004269static void AdvBuildCarrierFreelist(struct adv_dvc_var *adv_dvc)
Matthew Wilcox51219352007-10-02 21:55:22 -04004270{
Hannes Reinecke98b96a72015-04-24 13:18:23 +02004271 off_t carr_offset = 0, next_offset;
4272 dma_addr_t carr_paddr;
4273 int carr_num = ADV_CARRIER_BUFSIZE / sizeof(ADV_CARR_T), i;
Matthew Wilcox51219352007-10-02 21:55:22 -04004274
Hannes Reinecke98b96a72015-04-24 13:18:23 +02004275 for (i = 0; i < carr_num; i++) {
4276 carr_offset = i * sizeof(ADV_CARR_T);
4277 /* Get physical address of the carrier 'carrp'. */
4278 carr_paddr = adv_dvc->carrier_addr + carr_offset;
4279
4280 adv_dvc->carrier[i].carr_pa = cpu_to_le32(carr_paddr);
4281 adv_dvc->carrier[i].carr_va = cpu_to_le32(carr_offset);
4282 adv_dvc->carrier[i].areq_vpa = 0;
4283 next_offset = carr_offset + sizeof(ADV_CARR_T);
4284 if (i == carr_num)
4285 next_offset = ~0;
4286 adv_dvc->carrier[i].next_vpa = cpu_to_le32(next_offset);
4287 }
4288 /*
4289 * We cannot have a carrier with 'carr_va' of '0', as
4290 * a reference to this carrier would be interpreted as
4291 * list termination.
4292 * So start at carrier 1 with the freelist.
4293 */
4294 adv_dvc->carr_freelist = &adv_dvc->carrier[1];
4295}
4296
4297static ADV_CARR_T *adv_get_carrier(struct adv_dvc_var *adv_dvc, u32 offset)
4298{
4299 int index;
4300
4301 BUG_ON(offset > ADV_CARRIER_BUFSIZE);
4302
4303 index = offset / sizeof(ADV_CARR_T);
4304 return &adv_dvc->carrier[index];
4305}
4306
4307static ADV_CARR_T *adv_get_next_carrier(struct adv_dvc_var *adv_dvc)
4308{
4309 ADV_CARR_T *carrp = adv_dvc->carr_freelist;
4310 u32 next_vpa = le32_to_cpu(carrp->next_vpa);
4311
4312 if (next_vpa == 0 || next_vpa == ~0) {
4313 ASC_DBG(1, "invalid vpa offset 0x%x\n", next_vpa);
4314 return NULL;
Matthew Wilcox51219352007-10-02 21:55:22 -04004315 }
4316
Hannes Reinecke98b96a72015-04-24 13:18:23 +02004317 adv_dvc->carr_freelist = adv_get_carrier(adv_dvc, next_vpa);
4318 /*
4319 * insert stopper carrier to terminate list
4320 */
4321 carrp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
Matthew Wilcox51219352007-10-02 21:55:22 -04004322
Hannes Reinecke98b96a72015-04-24 13:18:23 +02004323 return carrp;
Matthew Wilcox51219352007-10-02 21:55:22 -04004324}
4325
4326/*
Hannes Reinecke4b47e462015-04-24 13:18:24 +02004327 * 'offset' is the index in the request pointer array
4328 */
4329static adv_req_t * adv_get_reqp(struct adv_dvc_var *adv_dvc, u32 offset)
4330{
4331 struct asc_board *boardp = adv_dvc->drv_ptr;
4332
4333 BUG_ON(offset > adv_dvc->max_host_qng);
4334 return &boardp->adv_reqp[offset];
4335}
4336
4337/*
Matthew Wilcox51219352007-10-02 21:55:22 -04004338 * Send an idle command to the chip and wait for completion.
4339 *
4340 * Command completion is polled for once per microsecond.
4341 *
4342 * The function can be called from anywhere including an interrupt handler.
4343 * But the function is not re-entrant, so it uses the DvcEnter/LeaveCritical()
4344 * functions to prevent reentrancy.
4345 *
4346 * Return Values:
4347 * ADV_TRUE - command completed successfully
4348 * ADV_FALSE - command failed
4349 * ADV_ERROR - command timed out
4350 */
4351static int
4352AdvSendIdleCmd(ADV_DVC_VAR *asc_dvc,
Hannes Reinecke95cfab62015-04-24 13:18:27 +02004353 ushort idle_cmd, u32 idle_cmd_parameter)
Matthew Wilcox51219352007-10-02 21:55:22 -04004354{
Hannes Reinecke95cfab62015-04-24 13:18:27 +02004355 int result, i, j;
Matthew Wilcox51219352007-10-02 21:55:22 -04004356 AdvPortAddr iop_base;
4357
4358 iop_base = asc_dvc->iop_base;
4359
4360 /*
4361 * Clear the idle command status which is set by the microcode
4362 * to a non-zero value to indicate when the command is completed.
4363 * The non-zero result is one of the IDLE_CMD_STATUS_* values
4364 */
4365 AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS, (ushort)0);
4366
4367 /*
4368 * Write the idle command value after the idle command parameter
4369 * has been written to avoid a race condition. If the order is not
4370 * followed, the microcode may process the idle command before the
4371 * parameters have been written to LRAM.
4372 */
4373 AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IDLE_CMD_PARAMETER,
4374 cpu_to_le32(idle_cmd_parameter));
4375 AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD, idle_cmd);
4376
4377 /*
4378 * Tickle the RISC to tell it to process the idle command.
4379 */
4380 AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_B);
4381 if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
4382 /*
4383 * Clear the tickle value. In the ASC-3550 the RISC flag
4384 * command 'clr_tickle_b' does not work unless the host
4385 * value is cleared.
4386 */
4387 AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_NOP);
4388 }
4389
4390 /* Wait for up to 100 millisecond for the idle command to timeout. */
4391 for (i = 0; i < SCSI_WAIT_100_MSEC; i++) {
4392 /* Poll once each microsecond for command completion. */
4393 for (j = 0; j < SCSI_US_PER_MSEC; j++) {
4394 AdvReadWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS,
4395 result);
4396 if (result != 0)
4397 return result;
4398 udelay(1);
4399 }
4400 }
4401
4402 BUG(); /* The idle command should never timeout. */
4403 return ADV_ERROR;
4404}
4405
4406/*
4407 * Reset SCSI Bus and purge all outstanding requests.
4408 *
4409 * Return Value:
4410 * ADV_TRUE(1) - All requests are purged and SCSI Bus is reset.
4411 * ADV_FALSE(0) - Microcode command failed.
4412 * ADV_ERROR(-1) - Microcode command timed-out. Microcode or IC
4413 * may be hung which requires driver recovery.
4414 */
4415static int AdvResetSB(ADV_DVC_VAR *asc_dvc)
4416{
4417 int status;
4418
4419 /*
4420 * Send the SCSI Bus Reset idle start idle command which asserts
4421 * the SCSI Bus Reset signal.
4422 */
4423 status = AdvSendIdleCmd(asc_dvc, (ushort)IDLE_CMD_SCSI_RESET_START, 0L);
4424 if (status != ADV_TRUE) {
4425 return status;
4426 }
4427
4428 /*
4429 * Delay for the specified SCSI Bus Reset hold time.
4430 *
4431 * The hold time delay is done on the host because the RISC has no
4432 * microsecond accurate timer.
4433 */
4434 udelay(ASC_SCSI_RESET_HOLD_TIME_US);
4435
4436 /*
4437 * Send the SCSI Bus Reset end idle command which de-asserts
4438 * the SCSI Bus Reset signal and purges any pending requests.
4439 */
4440 status = AdvSendIdleCmd(asc_dvc, (ushort)IDLE_CMD_SCSI_RESET_END, 0L);
4441 if (status != ADV_TRUE) {
4442 return status;
4443 }
4444
4445 mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
4446
4447 return status;
4448}
4449
4450/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004451 * Initialize the ASC-3550.
4452 *
4453 * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
4454 *
4455 * For a non-fatal error return a warning code. If there are no warnings
4456 * then 0 is returned.
4457 *
4458 * Needed after initialization for error recovery.
4459 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004460static int AdvInitAsc3550Driver(ADV_DVC_VAR *asc_dvc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004461{
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304462 const struct firmware *fw;
4463 const char fwname[] = "advansys/3550.bin";
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004464 AdvPortAddr iop_base;
4465 ushort warn_code;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004466 int begin_addr;
4467 int end_addr;
4468 ushort code_sum;
4469 int word;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004470 int i;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304471 int err;
4472 unsigned long chksum;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004473 ushort scsi_cfg1;
4474 uchar tid;
4475 ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
4476 ushort wdtr_able = 0, sdtr_able, tagqng_able;
4477 uchar max_cmd[ADV_MAX_TID + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004479 /* If there is already an error, don't continue. */
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004480 if (asc_dvc->err_code != 0)
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004481 return ADV_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004482
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004483 /*
4484 * The caller must set 'chip_type' to ADV_CHIP_ASC3550.
4485 */
4486 if (asc_dvc->chip_type != ADV_CHIP_ASC3550) {
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004487 asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004488 return ADV_ERROR;
4489 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004490
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004491 warn_code = 0;
4492 iop_base = asc_dvc->iop_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004493
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004494 /*
4495 * Save the RISC memory BIOS region before writing the microcode.
4496 * The BIOS may already be loaded and using its RISC LRAM region
4497 * so its region must be saved and restored.
4498 *
4499 * Note: This code makes the assumption, which is currently true,
4500 * that a chip reset does not clear RISC LRAM.
4501 */
4502 for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
4503 AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
4504 bios_mem[i]);
4505 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004506
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004507 /*
4508 * Save current per TID negotiated values.
4509 */
4510 if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] == 0x55AA) {
4511 ushort bios_version, major, minor;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004512
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004513 bios_version =
4514 bios_mem[(ASC_MC_BIOS_VERSION - ASC_MC_BIOSMEM) / 2];
4515 major = (bios_version >> 12) & 0xF;
4516 minor = (bios_version >> 8) & 0xF;
4517 if (major < 3 || (major == 3 && minor == 1)) {
4518 /* BIOS 3.1 and earlier location of 'wdtr_able' variable. */
4519 AdvReadWordLram(iop_base, 0x120, wdtr_able);
4520 } else {
4521 AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
4522 }
4523 }
4524 AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
4525 AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
4526 for (tid = 0; tid <= ADV_MAX_TID; tid++) {
4527 AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
4528 max_cmd[tid]);
4529 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004530
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304531 err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
4532 if (err) {
4533 printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
4534 fwname, err);
Herton Ronaldo Krzesinskicf747442010-03-19 19:37:26 -03004535 asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304536 return err;
4537 }
4538 if (fw->size < 4) {
4539 printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
4540 fw->size, fwname);
4541 release_firmware(fw);
Herton Ronaldo Krzesinskicf747442010-03-19 19:37:26 -03004542 asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304543 return -EINVAL;
4544 }
4545 chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
4546 (fw->data[1] << 8) | fw->data[0];
4547 asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
4548 fw->size - 4, ADV_3550_MEMSIZE,
4549 chksum);
4550 release_firmware(fw);
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004551 if (asc_dvc->err_code)
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004552 return ADV_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004553
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004554 /*
4555 * Restore the RISC memory BIOS region.
4556 */
4557 for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
4558 AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
4559 bios_mem[i]);
4560 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004561
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004562 /*
4563 * Calculate and write the microcode code checksum to the microcode
4564 * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
4565 */
4566 AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
4567 AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
4568 code_sum = 0;
4569 AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
4570 for (word = begin_addr; word < end_addr; word += 2) {
4571 code_sum += AdvReadWordAutoIncLram(iop_base);
4572 }
4573 AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004574
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004575 /*
4576 * Read and save microcode version and date.
4577 */
4578 AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
4579 asc_dvc->cfg->mcode_date);
4580 AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
4581 asc_dvc->cfg->mcode_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004582
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004583 /*
4584 * Set the chip type to indicate the ASC3550.
4585 */
4586 AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC3550);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004587
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004588 /*
4589 * If the PCI Configuration Command Register "Parity Error Response
4590 * Control" Bit was clear (0), then set the microcode variable
4591 * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
4592 * to ignore DMA parity errors.
4593 */
4594 if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
4595 AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
4596 word |= CONTROL_FLAG_IGNORE_PERR;
4597 AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
4598 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004599
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004600 /*
4601 * For ASC-3550, setting the START_CTL_EMFU [3:2] bits sets a FIFO
4602 * threshold of 128 bytes. This register is only accessible to the host.
4603 */
4604 AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
4605 START_CTL_EMFU | READ_CMD_MRM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004606
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004607 /*
4608 * Microcode operating variables for WDTR, SDTR, and command tag
Matthew Wilcox47d853c2007-07-26 11:41:33 -04004609 * queuing will be set in slave_configure() based on what a
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004610 * device reports it is capable of in Inquiry byte 7.
4611 *
4612 * If SCSI Bus Resets have been disabled, then directly set
4613 * SDTR and WDTR from the EEPROM configuration. This will allow
4614 * the BIOS and warm boot to work without a SCSI bus hang on
4615 * the Inquiry caused by host and target mismatched DTR values.
4616 * Without the SCSI Bus Reset, before an Inquiry a device can't
4617 * be assumed to be in Asynchronous, Narrow mode.
4618 */
4619 if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
4620 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
4621 asc_dvc->wdtr_able);
4622 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
4623 asc_dvc->sdtr_able);
4624 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004625
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004626 /*
4627 * Set microcode operating variables for SDTR_SPEED1, SDTR_SPEED2,
4628 * SDTR_SPEED3, and SDTR_SPEED4 based on the ULTRA EEPROM per TID
4629 * bitmask. These values determine the maximum SDTR speed negotiated
4630 * with a device.
4631 *
4632 * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
4633 * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
4634 * without determining here whether the device supports SDTR.
4635 *
4636 * 4-bit speed SDTR speed name
4637 * =========== ===============
4638 * 0000b (0x0) SDTR disabled
4639 * 0001b (0x1) 5 Mhz
4640 * 0010b (0x2) 10 Mhz
4641 * 0011b (0x3) 20 Mhz (Ultra)
4642 * 0100b (0x4) 40 Mhz (LVD/Ultra2)
4643 * 0101b (0x5) 80 Mhz (LVD2/Ultra3)
4644 * 0110b (0x6) Undefined
4645 * .
4646 * 1111b (0xF) Undefined
4647 */
4648 word = 0;
4649 for (tid = 0; tid <= ADV_MAX_TID; tid++) {
4650 if (ADV_TID_TO_TIDMASK(tid) & asc_dvc->ultra_able) {
4651 /* Set Ultra speed for TID 'tid'. */
4652 word |= (0x3 << (4 * (tid % 4)));
4653 } else {
4654 /* Set Fast speed for TID 'tid'. */
4655 word |= (0x2 << (4 * (tid % 4)));
4656 }
4657 if (tid == 3) { /* Check if done with sdtr_speed1. */
4658 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, word);
4659 word = 0;
4660 } else if (tid == 7) { /* Check if done with sdtr_speed2. */
4661 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, word);
4662 word = 0;
4663 } else if (tid == 11) { /* Check if done with sdtr_speed3. */
4664 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, word);
4665 word = 0;
4666 } else if (tid == 15) { /* Check if done with sdtr_speed4. */
4667 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, word);
4668 /* End of loop. */
4669 }
4670 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004671
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004672 /*
4673 * Set microcode operating variable for the disconnect per TID bitmask.
4674 */
4675 AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
4676 asc_dvc->cfg->disc_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004677
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004678 /*
4679 * Set SCSI_CFG0 Microcode Default Value.
4680 *
4681 * The microcode will set the SCSI_CFG0 register using this value
4682 * after it is started below.
4683 */
4684 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
4685 PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
4686 asc_dvc->chip_scsi_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004687
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004688 /*
4689 * Determine SCSI_CFG1 Microcode Default Value.
4690 *
4691 * The microcode will set the SCSI_CFG1 register using this value
4692 * after it is started below.
4693 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004694
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004695 /* Read current SCSI_CFG1 Register value. */
4696 scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004697
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004698 /*
4699 * If all three connectors are in use, return an error.
4700 */
4701 if ((scsi_cfg1 & CABLE_ILLEGAL_A) == 0 ||
4702 (scsi_cfg1 & CABLE_ILLEGAL_B) == 0) {
4703 asc_dvc->err_code |= ASC_IERR_ILLEGAL_CONNECTION;
4704 return ADV_ERROR;
4705 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004706
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004707 /*
4708 * If the internal narrow cable is reversed all of the SCSI_CTRL
4709 * register signals will be set. Check for and return an error if
4710 * this condition is found.
4711 */
4712 if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
4713 asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
4714 return ADV_ERROR;
4715 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004716
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004717 /*
4718 * If this is a differential board and a single-ended device
4719 * is attached to one of the connectors, return an error.
4720 */
4721 if ((scsi_cfg1 & DIFF_MODE) && (scsi_cfg1 & DIFF_SENSE) == 0) {
4722 asc_dvc->err_code |= ASC_IERR_SINGLE_END_DEVICE;
4723 return ADV_ERROR;
4724 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004725
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004726 /*
4727 * If automatic termination control is enabled, then set the
4728 * termination value based on a table listed in a_condor.h.
4729 *
4730 * If manual termination was specified with an EEPROM setting
4731 * then 'termination' was set-up in AdvInitFrom3550EEPROM() and
4732 * is ready to be 'ored' into SCSI_CFG1.
4733 */
4734 if (asc_dvc->cfg->termination == 0) {
4735 /*
4736 * The software always controls termination by setting TERM_CTL_SEL.
4737 * If TERM_CTL_SEL were set to 0, the hardware would set termination.
4738 */
4739 asc_dvc->cfg->termination |= TERM_CTL_SEL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004740
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004741 switch (scsi_cfg1 & CABLE_DETECT) {
4742 /* TERM_CTL_H: on, TERM_CTL_L: on */
4743 case 0x3:
4744 case 0x7:
4745 case 0xB:
4746 case 0xD:
4747 case 0xE:
4748 case 0xF:
4749 asc_dvc->cfg->termination |= (TERM_CTL_H | TERM_CTL_L);
4750 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004751
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004752 /* TERM_CTL_H: on, TERM_CTL_L: off */
4753 case 0x1:
4754 case 0x5:
4755 case 0x9:
4756 case 0xA:
4757 case 0xC:
4758 asc_dvc->cfg->termination |= TERM_CTL_H;
4759 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004760
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004761 /* TERM_CTL_H: off, TERM_CTL_L: off */
4762 case 0x2:
4763 case 0x6:
4764 break;
4765 }
4766 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004768 /*
4769 * Clear any set TERM_CTL_H and TERM_CTL_L bits.
4770 */
4771 scsi_cfg1 &= ~TERM_CTL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004772
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004773 /*
4774 * Invert the TERM_CTL_H and TERM_CTL_L bits and then
4775 * set 'scsi_cfg1'. The TERM_POL bit does not need to be
4776 * referenced, because the hardware internally inverts
4777 * the Termination High and Low bits if TERM_POL is set.
4778 */
4779 scsi_cfg1 |= (TERM_CTL_SEL | (~asc_dvc->cfg->termination & TERM_CTL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004780
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004781 /*
4782 * Set SCSI_CFG1 Microcode Default Value
4783 *
4784 * Set filter value and possibly modified termination control
4785 * bits in the Microcode SCSI_CFG1 Register Value.
4786 *
4787 * The microcode will set the SCSI_CFG1 register using this value
4788 * after it is started below.
4789 */
4790 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1,
4791 FLTR_DISABLE | scsi_cfg1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004792
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004793 /*
4794 * Set MEM_CFG Microcode Default Value
4795 *
4796 * The microcode will set the MEM_CFG register using this value
4797 * after it is started below.
4798 *
4799 * MEM_CFG may be accessed as a word or byte, but only bits 0-7
4800 * are defined.
4801 *
4802 * ASC-3550 has 8KB internal memory.
4803 */
4804 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
4805 BIOS_EN | RAM_SZ_8KB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004806
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004807 /*
4808 * Set SEL_MASK Microcode Default Value
4809 *
4810 * The microcode will set the SEL_MASK register using this value
4811 * after it is started below.
4812 */
4813 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
4814 ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004815
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004816 AdvBuildCarrierFreelist(asc_dvc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004817
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004818 /*
4819 * Set-up the Host->RISC Initiator Command Queue (ICQ).
4820 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004821
Hannes Reinecke98b96a72015-04-24 13:18:23 +02004822 asc_dvc->icq_sp = adv_get_next_carrier(asc_dvc);
4823 if (!asc_dvc->icq_sp) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004824 asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
4825 return ADV_ERROR;
4826 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004827
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004828 /*
4829 * Set RISC ICQ physical address start value.
4830 */
4831 AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004832
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004833 /*
4834 * Set-up the RISC->Host Initiator Response Queue (IRQ).
4835 */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02004836 asc_dvc->irq_sp = adv_get_next_carrier(asc_dvc);
4837 if (!asc_dvc->irq_sp) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004838 asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
4839 return ADV_ERROR;
4840 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004842 /*
4843 * Set RISC IRQ physical address start value.
4844 */
4845 AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
4846 asc_dvc->carr_pending_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004847
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004848 AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
4849 (ADV_INTR_ENABLE_HOST_INTR |
4850 ADV_INTR_ENABLE_GLOBAL_INTR));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004851
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004852 AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
4853 AdvWriteWordRegister(iop_base, IOPW_PC, word);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004854
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004855 /* finally, finally, gentlemen, start your engine */
4856 AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004858 /*
4859 * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
4860 * Resets should be performed. The RISC has to be running
4861 * to issue a SCSI Bus Reset.
4862 */
4863 if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
4864 /*
4865 * If the BIOS Signature is present in memory, restore the
4866 * BIOS Handshake Configuration Table and do not perform
4867 * a SCSI Bus Reset.
4868 */
4869 if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
4870 0x55AA) {
4871 /*
4872 * Restore per TID negotiated values.
4873 */
4874 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
4875 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
4876 AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
4877 tagqng_able);
4878 for (tid = 0; tid <= ADV_MAX_TID; tid++) {
4879 AdvWriteByteLram(iop_base,
4880 ASC_MC_NUMBER_OF_MAX_CMD + tid,
4881 max_cmd[tid]);
4882 }
4883 } else {
4884 if (AdvResetSB(asc_dvc) != ADV_TRUE) {
4885 warn_code = ASC_WARN_BUSRESET_ERROR;
4886 }
4887 }
4888 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004889
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004890 return warn_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004891}
4892
4893/*
4894 * Initialize the ASC-38C0800.
4895 *
4896 * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
4897 *
4898 * For a non-fatal error return a warning code. If there are no warnings
4899 * then 0 is returned.
4900 *
4901 * Needed after initialization for error recovery.
4902 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004903static int AdvInitAsc38C0800Driver(ADV_DVC_VAR *asc_dvc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004904{
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304905 const struct firmware *fw;
4906 const char fwname[] = "advansys/38C0800.bin";
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004907 AdvPortAddr iop_base;
4908 ushort warn_code;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004909 int begin_addr;
4910 int end_addr;
4911 ushort code_sum;
4912 int word;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004913 int i;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304914 int err;
4915 unsigned long chksum;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004916 ushort scsi_cfg1;
4917 uchar byte;
4918 uchar tid;
4919 ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
4920 ushort wdtr_able, sdtr_able, tagqng_able;
4921 uchar max_cmd[ADV_MAX_TID + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004922
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004923 /* If there is already an error, don't continue. */
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004924 if (asc_dvc->err_code != 0)
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004925 return ADV_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004926
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004927 /*
4928 * The caller must set 'chip_type' to ADV_CHIP_ASC38C0800.
4929 */
4930 if (asc_dvc->chip_type != ADV_CHIP_ASC38C0800) {
4931 asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
4932 return ADV_ERROR;
4933 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004934
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004935 warn_code = 0;
4936 iop_base = asc_dvc->iop_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004937
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004938 /*
4939 * Save the RISC memory BIOS region before writing the microcode.
4940 * The BIOS may already be loaded and using its RISC LRAM region
4941 * so its region must be saved and restored.
4942 *
4943 * Note: This code makes the assumption, which is currently true,
4944 * that a chip reset does not clear RISC LRAM.
4945 */
4946 for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
4947 AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
4948 bios_mem[i]);
4949 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004950
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004951 /*
4952 * Save current per TID negotiated values.
4953 */
4954 AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
4955 AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
4956 AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
4957 for (tid = 0; tid <= ADV_MAX_TID; tid++) {
4958 AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
4959 max_cmd[tid]);
4960 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004961
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004962 /*
4963 * RAM BIST (RAM Built-In Self Test)
4964 *
4965 * Address : I/O base + offset 0x38h register (byte).
4966 * Function: Bit 7-6(RW) : RAM mode
4967 * Normal Mode : 0x00
4968 * Pre-test Mode : 0x40
4969 * RAM Test Mode : 0x80
4970 * Bit 5 : unused
4971 * Bit 4(RO) : Done bit
4972 * Bit 3-0(RO) : Status
4973 * Host Error : 0x08
4974 * Int_RAM Error : 0x04
4975 * RISC Error : 0x02
4976 * SCSI Error : 0x01
4977 * No Error : 0x00
4978 *
4979 * Note: RAM BIST code should be put right here, before loading the
4980 * microcode and after saving the RISC memory BIOS region.
4981 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004982
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004983 /*
4984 * LRAM Pre-test
4985 *
4986 * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
4987 * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
4988 * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
4989 * to NORMAL_MODE, return an error too.
4990 */
4991 for (i = 0; i < 2; i++) {
4992 AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
Matthew Wilcoxb009bef2007-09-09 08:56:38 -06004993 mdelay(10); /* Wait for 10ms before reading back. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004994 byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
4995 if ((byte & RAM_TEST_DONE) == 0
4996 || (byte & 0x0F) != PRE_TEST_VALUE) {
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004997 asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004998 return ADV_ERROR;
4999 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005000
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005001 AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
Matthew Wilcoxb009bef2007-09-09 08:56:38 -06005002 mdelay(10); /* Wait for 10ms before reading back. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005003 if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
5004 != NORMAL_VALUE) {
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005005 asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005006 return ADV_ERROR;
5007 }
5008 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005009
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005010 /*
5011 * LRAM Test - It takes about 1.5 ms to run through the test.
5012 *
5013 * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
5014 * If Done bit not set or Status not 0, save register byte, set the
5015 * err_code, and return an error.
5016 */
5017 AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
Matthew Wilcoxb009bef2007-09-09 08:56:38 -06005018 mdelay(10); /* Wait for 10ms before checking status. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005019
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005020 byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
5021 if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
5022 /* Get here if Done bit not set or Status not 0. */
5023 asc_dvc->bist_err_code = byte; /* for BIOS display message */
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005024 asc_dvc->err_code = ASC_IERR_BIST_RAM_TEST;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005025 return ADV_ERROR;
5026 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005027
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005028 /* We need to reset back to normal mode after LRAM test passes. */
5029 AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005030
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05305031 err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
5032 if (err) {
5033 printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
5034 fwname, err);
Herton Ronaldo Krzesinskicf747442010-03-19 19:37:26 -03005035 asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05305036 return err;
5037 }
5038 if (fw->size < 4) {
5039 printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
5040 fw->size, fwname);
5041 release_firmware(fw);
Herton Ronaldo Krzesinskicf747442010-03-19 19:37:26 -03005042 asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05305043 return -EINVAL;
5044 }
5045 chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
5046 (fw->data[1] << 8) | fw->data[0];
5047 asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
5048 fw->size - 4, ADV_38C0800_MEMSIZE,
5049 chksum);
5050 release_firmware(fw);
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005051 if (asc_dvc->err_code)
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005052 return ADV_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005053
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005054 /*
5055 * Restore the RISC memory BIOS region.
5056 */
5057 for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
5058 AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
5059 bios_mem[i]);
5060 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005061
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005062 /*
5063 * Calculate and write the microcode code checksum to the microcode
5064 * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
5065 */
5066 AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
5067 AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
5068 code_sum = 0;
5069 AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
5070 for (word = begin_addr; word < end_addr; word += 2) {
5071 code_sum += AdvReadWordAutoIncLram(iop_base);
5072 }
5073 AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005074
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005075 /*
5076 * Read microcode version and date.
5077 */
5078 AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
5079 asc_dvc->cfg->mcode_date);
5080 AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
5081 asc_dvc->cfg->mcode_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005082
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005083 /*
5084 * Set the chip type to indicate the ASC38C0800.
5085 */
5086 AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C0800);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005087
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005088 /*
5089 * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
5090 * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
5091 * cable detection and then we are able to read C_DET[3:0].
5092 *
5093 * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
5094 * Microcode Default Value' section below.
5095 */
5096 scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
5097 AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1,
5098 scsi_cfg1 | DIS_TERM_DRV);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005099
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005100 /*
5101 * If the PCI Configuration Command Register "Parity Error Response
5102 * Control" Bit was clear (0), then set the microcode variable
5103 * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
5104 * to ignore DMA parity errors.
5105 */
5106 if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
5107 AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
5108 word |= CONTROL_FLAG_IGNORE_PERR;
5109 AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
5110 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005111
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005112 /*
5113 * For ASC-38C0800, set FIFO_THRESH_80B [6:4] bits and START_CTL_TH [3:2]
5114 * bits for the default FIFO threshold.
5115 *
5116 * Note: ASC-38C0800 FIFO threshold has been changed to 256 bytes.
5117 *
5118 * For DMA Errata #4 set the BC_THRESH_ENB bit.
5119 */
5120 AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
5121 BC_THRESH_ENB | FIFO_THRESH_80B | START_CTL_TH |
5122 READ_CMD_MRM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005123
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005124 /*
5125 * Microcode operating variables for WDTR, SDTR, and command tag
Matthew Wilcox47d853c2007-07-26 11:41:33 -04005126 * queuing will be set in slave_configure() based on what a
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005127 * device reports it is capable of in Inquiry byte 7.
5128 *
5129 * If SCSI Bus Resets have been disabled, then directly set
5130 * SDTR and WDTR from the EEPROM configuration. This will allow
5131 * the BIOS and warm boot to work without a SCSI bus hang on
5132 * the Inquiry caused by host and target mismatched DTR values.
5133 * Without the SCSI Bus Reset, before an Inquiry a device can't
5134 * be assumed to be in Asynchronous, Narrow mode.
5135 */
5136 if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
5137 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
5138 asc_dvc->wdtr_able);
5139 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
5140 asc_dvc->sdtr_able);
5141 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005142
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005143 /*
5144 * Set microcode operating variables for DISC and SDTR_SPEED1,
5145 * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
5146 * configuration values.
5147 *
5148 * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
5149 * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
5150 * without determining here whether the device supports SDTR.
5151 */
5152 AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
5153 asc_dvc->cfg->disc_enable);
5154 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
5155 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
5156 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
5157 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005158
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005159 /*
5160 * Set SCSI_CFG0 Microcode Default Value.
5161 *
5162 * The microcode will set the SCSI_CFG0 register using this value
5163 * after it is started below.
5164 */
5165 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
5166 PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
5167 asc_dvc->chip_scsi_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005168
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005169 /*
5170 * Determine SCSI_CFG1 Microcode Default Value.
5171 *
5172 * The microcode will set the SCSI_CFG1 register using this value
5173 * after it is started below.
5174 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005175
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005176 /* Read current SCSI_CFG1 Register value. */
5177 scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005178
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005179 /*
5180 * If the internal narrow cable is reversed all of the SCSI_CTRL
5181 * register signals will be set. Check for and return an error if
5182 * this condition is found.
5183 */
5184 if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
5185 asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
5186 return ADV_ERROR;
5187 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005188
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005189 /*
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005190 * All kind of combinations of devices attached to one of four
5191 * connectors are acceptable except HVD device attached. For example,
5192 * LVD device can be attached to SE connector while SE device attached
5193 * to LVD connector. If LVD device attached to SE connector, it only
5194 * runs up to Ultra speed.
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005195 *
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005196 * If an HVD device is attached to one of LVD connectors, return an
5197 * error. However, there is no way to detect HVD device attached to
5198 * SE connectors.
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005199 */
5200 if (scsi_cfg1 & HVD) {
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005201 asc_dvc->err_code = ASC_IERR_HVD_DEVICE;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005202 return ADV_ERROR;
5203 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005204
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005205 /*
5206 * If either SE or LVD automatic termination control is enabled, then
5207 * set the termination value based on a table listed in a_condor.h.
5208 *
5209 * If manual termination was specified with an EEPROM setting then
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005210 * 'termination' was set-up in AdvInitFrom38C0800EEPROM() and is ready
5211 * to be 'ored' into SCSI_CFG1.
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005212 */
5213 if ((asc_dvc->cfg->termination & TERM_SE) == 0) {
5214 /* SE automatic termination control is enabled. */
5215 switch (scsi_cfg1 & C_DET_SE) {
5216 /* TERM_SE_HI: on, TERM_SE_LO: on */
5217 case 0x1:
5218 case 0x2:
5219 case 0x3:
5220 asc_dvc->cfg->termination |= TERM_SE;
5221 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005222
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005223 /* TERM_SE_HI: on, TERM_SE_LO: off */
5224 case 0x0:
5225 asc_dvc->cfg->termination |= TERM_SE_HI;
5226 break;
5227 }
5228 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005229
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005230 if ((asc_dvc->cfg->termination & TERM_LVD) == 0) {
5231 /* LVD automatic termination control is enabled. */
5232 switch (scsi_cfg1 & C_DET_LVD) {
5233 /* TERM_LVD_HI: on, TERM_LVD_LO: on */
5234 case 0x4:
5235 case 0x8:
5236 case 0xC:
5237 asc_dvc->cfg->termination |= TERM_LVD;
5238 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005239
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005240 /* TERM_LVD_HI: off, TERM_LVD_LO: off */
5241 case 0x0:
5242 break;
5243 }
5244 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005245
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005246 /*
5247 * Clear any set TERM_SE and TERM_LVD bits.
5248 */
5249 scsi_cfg1 &= (~TERM_SE & ~TERM_LVD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005250
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005251 /*
5252 * Invert the TERM_SE and TERM_LVD bits and then set 'scsi_cfg1'.
5253 */
5254 scsi_cfg1 |= (~asc_dvc->cfg->termination & 0xF0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005255
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005256 /*
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005257 * Clear BIG_ENDIAN, DIS_TERM_DRV, Terminator Polarity and HVD/LVD/SE
5258 * bits and set possibly modified termination control bits in the
5259 * Microcode SCSI_CFG1 Register Value.
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005260 */
5261 scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL & ~HVD_LVD_SE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005262
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005263 /*
5264 * Set SCSI_CFG1 Microcode Default Value
5265 *
5266 * Set possibly modified termination control and reset DIS_TERM_DRV
5267 * bits in the Microcode SCSI_CFG1 Register Value.
5268 *
5269 * The microcode will set the SCSI_CFG1 register using this value
5270 * after it is started below.
5271 */
5272 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005273
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005274 /*
5275 * Set MEM_CFG Microcode Default Value
5276 *
5277 * The microcode will set the MEM_CFG register using this value
5278 * after it is started below.
5279 *
5280 * MEM_CFG may be accessed as a word or byte, but only bits 0-7
5281 * are defined.
5282 *
5283 * ASC-38C0800 has 16KB internal memory.
5284 */
5285 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
5286 BIOS_EN | RAM_SZ_16KB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005287
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005288 /*
5289 * Set SEL_MASK Microcode Default Value
5290 *
5291 * The microcode will set the SEL_MASK register using this value
5292 * after it is started below.
5293 */
5294 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
5295 ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005296
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06005297 AdvBuildCarrierFreelist(asc_dvc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005298
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005299 /*
5300 * Set-up the Host->RISC Initiator Command Queue (ICQ).
5301 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005302
Hannes Reinecke98b96a72015-04-24 13:18:23 +02005303 asc_dvc->icq_sp = adv_get_next_carrier(asc_dvc);
5304 if (!asc_dvc->icq_sp) {
5305 ASC_DBG(0, "Failed to get ICQ carrier\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005306 asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
5307 return ADV_ERROR;
5308 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005309
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005310 /*
5311 * Set RISC ICQ physical address start value.
5312 * carr_pa is LE, must be native before write
5313 */
5314 AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005315
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005316 /*
5317 * Set-up the RISC->Host Initiator Response Queue (IRQ).
5318 */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02005319 asc_dvc->irq_sp = adv_get_next_carrier(asc_dvc);
5320 if (!asc_dvc->irq_sp) {
5321 ASC_DBG(0, "Failed to get IRQ carrier\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005322 asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
5323 return ADV_ERROR;
5324 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005325
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005326 /*
5327 * Set RISC IRQ physical address start value.
5328 *
5329 * carr_pa is LE, must be native before write *
5330 */
5331 AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
5332 asc_dvc->carr_pending_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005333
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005334 AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
5335 (ADV_INTR_ENABLE_HOST_INTR |
5336 ADV_INTR_ENABLE_GLOBAL_INTR));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005337
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005338 AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
5339 AdvWriteWordRegister(iop_base, IOPW_PC, word);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005340
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005341 /* finally, finally, gentlemen, start your engine */
5342 AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005343
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005344 /*
5345 * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
5346 * Resets should be performed. The RISC has to be running
5347 * to issue a SCSI Bus Reset.
5348 */
5349 if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
5350 /*
5351 * If the BIOS Signature is present in memory, restore the
5352 * BIOS Handshake Configuration Table and do not perform
5353 * a SCSI Bus Reset.
5354 */
5355 if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
5356 0x55AA) {
5357 /*
5358 * Restore per TID negotiated values.
5359 */
5360 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
5361 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
5362 AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
5363 tagqng_able);
5364 for (tid = 0; tid <= ADV_MAX_TID; tid++) {
5365 AdvWriteByteLram(iop_base,
5366 ASC_MC_NUMBER_OF_MAX_CMD + tid,
5367 max_cmd[tid]);
5368 }
5369 } else {
5370 if (AdvResetSB(asc_dvc) != ADV_TRUE) {
5371 warn_code = ASC_WARN_BUSRESET_ERROR;
5372 }
5373 }
5374 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005375
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005376 return warn_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005377}
5378
5379/*
5380 * Initialize the ASC-38C1600.
5381 *
5382 * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
5383 *
5384 * For a non-fatal error return a warning code. If there are no warnings
5385 * then 0 is returned.
5386 *
5387 * Needed after initialization for error recovery.
5388 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005389static int AdvInitAsc38C1600Driver(ADV_DVC_VAR *asc_dvc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005390{
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05305391 const struct firmware *fw;
5392 const char fwname[] = "advansys/38C1600.bin";
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005393 AdvPortAddr iop_base;
5394 ushort warn_code;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005395 int begin_addr;
5396 int end_addr;
5397 ushort code_sum;
5398 long word;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005399 int i;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05305400 int err;
5401 unsigned long chksum;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005402 ushort scsi_cfg1;
5403 uchar byte;
5404 uchar tid;
5405 ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
5406 ushort wdtr_able, sdtr_able, ppr_able, tagqng_able;
5407 uchar max_cmd[ASC_MAX_TID + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005408
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005409 /* If there is already an error, don't continue. */
5410 if (asc_dvc->err_code != 0) {
5411 return ADV_ERROR;
5412 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005413
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005414 /*
5415 * The caller must set 'chip_type' to ADV_CHIP_ASC38C1600.
5416 */
5417 if (asc_dvc->chip_type != ADV_CHIP_ASC38C1600) {
5418 asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
5419 return ADV_ERROR;
5420 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005421
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005422 warn_code = 0;
5423 iop_base = asc_dvc->iop_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005424
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005425 /*
5426 * Save the RISC memory BIOS region before writing the microcode.
5427 * The BIOS may already be loaded and using its RISC LRAM region
5428 * so its region must be saved and restored.
5429 *
5430 * Note: This code makes the assumption, which is currently true,
5431 * that a chip reset does not clear RISC LRAM.
5432 */
5433 for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
5434 AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
5435 bios_mem[i]);
5436 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005437
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005438 /*
5439 * Save current per TID negotiated values.
5440 */
5441 AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
5442 AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
5443 AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
5444 AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
5445 for (tid = 0; tid <= ASC_MAX_TID; tid++) {
5446 AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
5447 max_cmd[tid]);
5448 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005449
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005450 /*
5451 * RAM BIST (Built-In Self Test)
5452 *
5453 * Address : I/O base + offset 0x38h register (byte).
5454 * Function: Bit 7-6(RW) : RAM mode
5455 * Normal Mode : 0x00
5456 * Pre-test Mode : 0x40
5457 * RAM Test Mode : 0x80
5458 * Bit 5 : unused
5459 * Bit 4(RO) : Done bit
5460 * Bit 3-0(RO) : Status
5461 * Host Error : 0x08
5462 * Int_RAM Error : 0x04
5463 * RISC Error : 0x02
5464 * SCSI Error : 0x01
5465 * No Error : 0x00
5466 *
5467 * Note: RAM BIST code should be put right here, before loading the
5468 * microcode and after saving the RISC memory BIOS region.
5469 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005470
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005471 /*
5472 * LRAM Pre-test
5473 *
5474 * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
5475 * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
5476 * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
5477 * to NORMAL_MODE, return an error too.
5478 */
5479 for (i = 0; i < 2; i++) {
5480 AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
Matthew Wilcoxb009bef2007-09-09 08:56:38 -06005481 mdelay(10); /* Wait for 10ms before reading back. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005482 byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
5483 if ((byte & RAM_TEST_DONE) == 0
5484 || (byte & 0x0F) != PRE_TEST_VALUE) {
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005485 asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005486 return ADV_ERROR;
5487 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005488
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005489 AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
Matthew Wilcoxb009bef2007-09-09 08:56:38 -06005490 mdelay(10); /* Wait for 10ms before reading back. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005491 if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
5492 != NORMAL_VALUE) {
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005493 asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005494 return ADV_ERROR;
5495 }
5496 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005497
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005498 /*
5499 * LRAM Test - It takes about 1.5 ms to run through the test.
5500 *
5501 * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
5502 * If Done bit not set or Status not 0, save register byte, set the
5503 * err_code, and return an error.
5504 */
5505 AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
Matthew Wilcoxb009bef2007-09-09 08:56:38 -06005506 mdelay(10); /* Wait for 10ms before checking status. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005507
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005508 byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
5509 if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
5510 /* Get here if Done bit not set or Status not 0. */
5511 asc_dvc->bist_err_code = byte; /* for BIOS display message */
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005512 asc_dvc->err_code = ASC_IERR_BIST_RAM_TEST;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005513 return ADV_ERROR;
5514 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005515
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005516 /* We need to reset back to normal mode after LRAM test passes. */
5517 AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005518
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05305519 err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
5520 if (err) {
5521 printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
5522 fwname, err);
Herton Ronaldo Krzesinskicf747442010-03-19 19:37:26 -03005523 asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05305524 return err;
5525 }
5526 if (fw->size < 4) {
5527 printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
5528 fw->size, fwname);
5529 release_firmware(fw);
Herton Ronaldo Krzesinskicf747442010-03-19 19:37:26 -03005530 asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05305531 return -EINVAL;
5532 }
5533 chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
5534 (fw->data[1] << 8) | fw->data[0];
5535 asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
5536 fw->size - 4, ADV_38C1600_MEMSIZE,
5537 chksum);
5538 release_firmware(fw);
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005539 if (asc_dvc->err_code)
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005540 return ADV_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005541
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005542 /*
5543 * Restore the RISC memory BIOS region.
5544 */
5545 for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
5546 AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
5547 bios_mem[i]);
5548 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005549
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005550 /*
5551 * Calculate and write the microcode code checksum to the microcode
5552 * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
5553 */
5554 AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
5555 AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
5556 code_sum = 0;
5557 AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
5558 for (word = begin_addr; word < end_addr; word += 2) {
5559 code_sum += AdvReadWordAutoIncLram(iop_base);
5560 }
5561 AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005562
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005563 /*
5564 * Read microcode version and date.
5565 */
5566 AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
5567 asc_dvc->cfg->mcode_date);
5568 AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
5569 asc_dvc->cfg->mcode_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005570
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005571 /*
5572 * Set the chip type to indicate the ASC38C1600.
5573 */
5574 AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C1600);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005575
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005576 /*
5577 * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
5578 * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
5579 * cable detection and then we are able to read C_DET[3:0].
5580 *
5581 * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
5582 * Microcode Default Value' section below.
5583 */
5584 scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
5585 AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1,
5586 scsi_cfg1 | DIS_TERM_DRV);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005587
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005588 /*
5589 * If the PCI Configuration Command Register "Parity Error Response
5590 * Control" Bit was clear (0), then set the microcode variable
5591 * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
5592 * to ignore DMA parity errors.
5593 */
5594 if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
5595 AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
5596 word |= CONTROL_FLAG_IGNORE_PERR;
5597 AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
5598 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005599
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005600 /*
5601 * If the BIOS control flag AIPP (Asynchronous Information
5602 * Phase Protection) disable bit is not set, then set the firmware
5603 * 'control_flag' CONTROL_FLAG_ENABLE_AIPP bit to enable
5604 * AIPP checking and encoding.
5605 */
5606 if ((asc_dvc->bios_ctrl & BIOS_CTRL_AIPP_DIS) == 0) {
5607 AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
5608 word |= CONTROL_FLAG_ENABLE_AIPP;
5609 AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
5610 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005611
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005612 /*
5613 * For ASC-38C1600 use DMA_CFG0 default values: FIFO_THRESH_80B [6:4],
5614 * and START_CTL_TH [3:2].
5615 */
5616 AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
5617 FIFO_THRESH_80B | START_CTL_TH | READ_CMD_MRM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005618
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005619 /*
5620 * Microcode operating variables for WDTR, SDTR, and command tag
Matthew Wilcox47d853c2007-07-26 11:41:33 -04005621 * queuing will be set in slave_configure() based on what a
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005622 * device reports it is capable of in Inquiry byte 7.
5623 *
5624 * If SCSI Bus Resets have been disabled, then directly set
5625 * SDTR and WDTR from the EEPROM configuration. This will allow
5626 * the BIOS and warm boot to work without a SCSI bus hang on
5627 * the Inquiry caused by host and target mismatched DTR values.
5628 * Without the SCSI Bus Reset, before an Inquiry a device can't
5629 * be assumed to be in Asynchronous, Narrow mode.
5630 */
5631 if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
5632 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
5633 asc_dvc->wdtr_able);
5634 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
5635 asc_dvc->sdtr_able);
5636 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005637
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005638 /*
5639 * Set microcode operating variables for DISC and SDTR_SPEED1,
5640 * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
5641 * configuration values.
5642 *
5643 * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
5644 * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
5645 * without determining here whether the device supports SDTR.
5646 */
5647 AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
5648 asc_dvc->cfg->disc_enable);
5649 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
5650 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
5651 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
5652 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005653
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005654 /*
5655 * Set SCSI_CFG0 Microcode Default Value.
5656 *
5657 * The microcode will set the SCSI_CFG0 register using this value
5658 * after it is started below.
5659 */
5660 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
5661 PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
5662 asc_dvc->chip_scsi_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005663
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005664 /*
5665 * Calculate SCSI_CFG1 Microcode Default Value.
5666 *
5667 * The microcode will set the SCSI_CFG1 register using this value
5668 * after it is started below.
5669 *
5670 * Each ASC-38C1600 function has only two cable detect bits.
5671 * The bus mode override bits are in IOPB_SOFT_OVER_WR.
5672 */
5673 scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005674
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005675 /*
5676 * If the cable is reversed all of the SCSI_CTRL register signals
5677 * will be set. Check for and return an error if this condition is
5678 * found.
5679 */
5680 if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
5681 asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
5682 return ADV_ERROR;
5683 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005684
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005685 /*
5686 * Each ASC-38C1600 function has two connectors. Only an HVD device
5687 * can not be connected to either connector. An LVD device or SE device
5688 * may be connected to either connecor. If an SE device is connected,
5689 * then at most Ultra speed (20 Mhz) can be used on both connectors.
5690 *
5691 * If an HVD device is attached, return an error.
5692 */
5693 if (scsi_cfg1 & HVD) {
5694 asc_dvc->err_code |= ASC_IERR_HVD_DEVICE;
5695 return ADV_ERROR;
5696 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005697
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005698 /*
5699 * Each function in the ASC-38C1600 uses only the SE cable detect and
5700 * termination because there are two connectors for each function. Each
5701 * function may use either LVD or SE mode. Corresponding the SE automatic
5702 * termination control EEPROM bits are used for each function. Each
5703 * function has its own EEPROM. If SE automatic control is enabled for
5704 * the function, then set the termination value based on a table listed
5705 * in a_condor.h.
5706 *
5707 * If manual termination is specified in the EEPROM for the function,
5708 * then 'termination' was set-up in AscInitFrom38C1600EEPROM() and is
5709 * ready to be 'ored' into SCSI_CFG1.
5710 */
5711 if ((asc_dvc->cfg->termination & TERM_SE) == 0) {
Matthew Wilcox13ac2d92007-07-30 08:10:23 -06005712 struct pci_dev *pdev = adv_dvc_to_pdev(asc_dvc);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005713 /* SE automatic termination control is enabled. */
5714 switch (scsi_cfg1 & C_DET_SE) {
5715 /* TERM_SE_HI: on, TERM_SE_LO: on */
5716 case 0x1:
5717 case 0x2:
5718 case 0x3:
5719 asc_dvc->cfg->termination |= TERM_SE;
5720 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005721
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005722 case 0x0:
Matthew Wilcox13ac2d92007-07-30 08:10:23 -06005723 if (PCI_FUNC(pdev->devfn) == 0) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005724 /* Function 0 - TERM_SE_HI: off, TERM_SE_LO: off */
5725 } else {
5726 /* Function 1 - TERM_SE_HI: on, TERM_SE_LO: off */
5727 asc_dvc->cfg->termination |= TERM_SE_HI;
5728 }
5729 break;
5730 }
5731 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005732
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005733 /*
5734 * Clear any set TERM_SE bits.
5735 */
5736 scsi_cfg1 &= ~TERM_SE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005737
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005738 /*
5739 * Invert the TERM_SE bits and then set 'scsi_cfg1'.
5740 */
5741 scsi_cfg1 |= (~asc_dvc->cfg->termination & TERM_SE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005742
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005743 /*
5744 * Clear Big Endian and Terminator Polarity bits and set possibly
5745 * modified termination control bits in the Microcode SCSI_CFG1
5746 * Register Value.
5747 *
5748 * Big Endian bit is not used even on big endian machines.
5749 */
5750 scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005751
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005752 /*
5753 * Set SCSI_CFG1 Microcode Default Value
5754 *
5755 * Set possibly modified termination control bits in the Microcode
5756 * SCSI_CFG1 Register Value.
5757 *
5758 * The microcode will set the SCSI_CFG1 register using this value
5759 * after it is started below.
5760 */
5761 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005762
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005763 /*
5764 * Set MEM_CFG Microcode Default Value
5765 *
5766 * The microcode will set the MEM_CFG register using this value
5767 * after it is started below.
5768 *
5769 * MEM_CFG may be accessed as a word or byte, but only bits 0-7
5770 * are defined.
5771 *
5772 * ASC-38C1600 has 32KB internal memory.
5773 *
5774 * XXX - Since ASC38C1600 Rev.3 has a Local RAM failure issue, we come
5775 * out a special 16K Adv Library and Microcode version. After the issue
5776 * resolved, we should turn back to the 32K support. Both a_condor.h and
5777 * mcode.sas files also need to be updated.
5778 *
5779 * AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
5780 * BIOS_EN | RAM_SZ_32KB);
5781 */
5782 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
5783 BIOS_EN | RAM_SZ_16KB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005784
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005785 /*
5786 * Set SEL_MASK Microcode Default Value
5787 *
5788 * The microcode will set the SEL_MASK register using this value
5789 * after it is started below.
5790 */
5791 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
5792 ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005793
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06005794 AdvBuildCarrierFreelist(asc_dvc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005795
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005796 /*
5797 * Set-up the Host->RISC Initiator Command Queue (ICQ).
5798 */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02005799 asc_dvc->icq_sp = adv_get_next_carrier(asc_dvc);
5800 if (!asc_dvc->icq_sp) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005801 asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
5802 return ADV_ERROR;
5803 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005804
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005805 /*
5806 * Set RISC ICQ physical address start value. Initialize the
5807 * COMMA register to the same value otherwise the RISC will
5808 * prematurely detect a command is available.
5809 */
5810 AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
5811 AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
5812 le32_to_cpu(asc_dvc->icq_sp->carr_pa));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005813
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005814 /*
5815 * Set-up the RISC->Host Initiator Response Queue (IRQ).
5816 */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02005817 asc_dvc->irq_sp = adv_get_next_carrier(asc_dvc);
5818 if (!asc_dvc->irq_sp) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005819 asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
5820 return ADV_ERROR;
5821 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005822
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005823 /*
5824 * Set RISC IRQ physical address start value.
5825 */
5826 AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
5827 asc_dvc->carr_pending_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005828
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005829 AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
5830 (ADV_INTR_ENABLE_HOST_INTR |
5831 ADV_INTR_ENABLE_GLOBAL_INTR));
5832 AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
5833 AdvWriteWordRegister(iop_base, IOPW_PC, word);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005834
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005835 /* finally, finally, gentlemen, start your engine */
5836 AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005837
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005838 /*
5839 * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
5840 * Resets should be performed. The RISC has to be running
5841 * to issue a SCSI Bus Reset.
5842 */
5843 if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
5844 /*
5845 * If the BIOS Signature is present in memory, restore the
5846 * per TID microcode operating variables.
5847 */
5848 if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
5849 0x55AA) {
5850 /*
5851 * Restore per TID negotiated values.
5852 */
5853 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
5854 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
5855 AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
5856 AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
5857 tagqng_able);
5858 for (tid = 0; tid <= ASC_MAX_TID; tid++) {
5859 AdvWriteByteLram(iop_base,
5860 ASC_MC_NUMBER_OF_MAX_CMD + tid,
5861 max_cmd[tid]);
5862 }
5863 } else {
5864 if (AdvResetSB(asc_dvc) != ADV_TRUE) {
5865 warn_code = ASC_WARN_BUSRESET_ERROR;
5866 }
5867 }
5868 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005869
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005870 return warn_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005871}
5872
5873/*
Matthew Wilcox51219352007-10-02 21:55:22 -04005874 * Reset chip and SCSI Bus.
5875 *
5876 * Return Value:
5877 * ADV_TRUE(1) - Chip re-initialization and SCSI Bus Reset successful.
5878 * ADV_FALSE(0) - Chip re-initialization and SCSI Bus Reset failure.
5879 */
5880static int AdvResetChipAndSB(ADV_DVC_VAR *asc_dvc)
5881{
5882 int status;
5883 ushort wdtr_able, sdtr_able, tagqng_able;
5884 ushort ppr_able = 0;
5885 uchar tid, max_cmd[ADV_MAX_TID + 1];
5886 AdvPortAddr iop_base;
5887 ushort bios_sig;
5888
5889 iop_base = asc_dvc->iop_base;
5890
5891 /*
5892 * Save current per TID negotiated values.
5893 */
5894 AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
5895 AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
5896 if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
5897 AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
5898 }
5899 AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
5900 for (tid = 0; tid <= ADV_MAX_TID; tid++) {
5901 AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
5902 max_cmd[tid]);
5903 }
5904
5905 /*
5906 * Force the AdvInitAsc3550/38C0800Driver() function to
5907 * perform a SCSI Bus Reset by clearing the BIOS signature word.
5908 * The initialization functions assumes a SCSI Bus Reset is not
5909 * needed if the BIOS signature word is present.
5910 */
5911 AdvReadWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
5912 AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, 0);
5913
5914 /*
5915 * Stop chip and reset it.
5916 */
5917 AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_STOP);
5918 AdvWriteWordRegister(iop_base, IOPW_CTRL_REG, ADV_CTRL_REG_CMD_RESET);
5919 mdelay(100);
5920 AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
5921 ADV_CTRL_REG_CMD_WR_IO_REG);
5922
5923 /*
5924 * Reset Adv Library error code, if any, and try
5925 * re-initializing the chip.
5926 */
5927 asc_dvc->err_code = 0;
5928 if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
5929 status = AdvInitAsc38C1600Driver(asc_dvc);
5930 } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
5931 status = AdvInitAsc38C0800Driver(asc_dvc);
5932 } else {
5933 status = AdvInitAsc3550Driver(asc_dvc);
5934 }
5935
5936 /* Translate initialization return value to status value. */
5937 if (status == 0) {
5938 status = ADV_TRUE;
5939 } else {
5940 status = ADV_FALSE;
5941 }
5942
5943 /*
5944 * Restore the BIOS signature word.
5945 */
5946 AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
5947
5948 /*
5949 * Restore per TID negotiated values.
5950 */
5951 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
5952 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
5953 if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
5954 AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
5955 }
5956 AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
5957 for (tid = 0; tid <= ADV_MAX_TID; tid++) {
5958 AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
5959 max_cmd[tid]);
5960 }
5961
5962 return status;
5963}
5964
5965/*
5966 * adv_async_callback() - Adv Library asynchronous event callback function.
5967 */
5968static void adv_async_callback(ADV_DVC_VAR *adv_dvc_varp, uchar code)
5969{
5970 switch (code) {
5971 case ADV_ASYNC_SCSI_BUS_RESET_DET:
5972 /*
5973 * The firmware detected a SCSI Bus reset.
5974 */
Matthew Wilcoxb352f922007-10-02 21:55:33 -04005975 ASC_DBG(0, "ADV_ASYNC_SCSI_BUS_RESET_DET\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04005976 break;
5977
5978 case ADV_ASYNC_RDMA_FAILURE:
5979 /*
5980 * Handle RDMA failure by resetting the SCSI Bus and
5981 * possibly the chip if it is unresponsive. Log the error
5982 * with a unique code.
5983 */
Matthew Wilcoxb352f922007-10-02 21:55:33 -04005984 ASC_DBG(0, "ADV_ASYNC_RDMA_FAILURE\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04005985 AdvResetChipAndSB(adv_dvc_varp);
5986 break;
5987
5988 case ADV_HOST_SCSI_BUS_RESET:
5989 /*
5990 * Host generated SCSI bus reset occurred.
5991 */
Matthew Wilcoxb352f922007-10-02 21:55:33 -04005992 ASC_DBG(0, "ADV_HOST_SCSI_BUS_RESET\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04005993 break;
5994
5995 default:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04005996 ASC_DBG(0, "unknown code 0x%x\n", code);
Matthew Wilcox51219352007-10-02 21:55:22 -04005997 break;
5998 }
5999}
6000
6001/*
6002 * adv_isr_callback() - Second Level Interrupt Handler called by AdvISR().
6003 *
6004 * Callback function for the Wide SCSI Adv Library.
6005 */
6006static void adv_isr_callback(ADV_DVC_VAR *adv_dvc_varp, ADV_SCSI_REQ_Q *scsiqp)
6007{
Hannes Reinecke9c17c622015-04-24 13:18:21 +02006008 struct asc_board *boardp = adv_dvc_varp->drv_ptr;
6009 u32 srb_tag;
Matthew Wilcox51219352007-10-02 21:55:22 -04006010 adv_req_t *reqp;
6011 adv_sgblk_t *sgblkp;
6012 struct scsi_cmnd *scp;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02006013 u32 resid_cnt;
Hannes Reinecke811ddc02015-04-24 13:18:22 +02006014 dma_addr_t sense_addr;
Matthew Wilcox51219352007-10-02 21:55:22 -04006015
Hannes Reinecke9c17c622015-04-24 13:18:21 +02006016 ASC_DBG(1, "adv_dvc_varp 0x%p, scsiqp 0x%p\n",
6017 adv_dvc_varp, scsiqp);
Matthew Wilcox51219352007-10-02 21:55:22 -04006018 ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
6019
6020 /*
6021 * Get the adv_req_t structure for the command that has been
6022 * completed. The adv_req_t structure actually contains the
6023 * completed ADV_SCSI_REQ_Q structure.
6024 */
Hannes Reinecke9c17c622015-04-24 13:18:21 +02006025 srb_tag = le32_to_cpu(scsiqp->srb_tag);
6026 scp = scsi_host_find_tag(boardp->shost, scsiqp->srb_tag);
Matthew Wilcox51219352007-10-02 21:55:22 -04006027
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006028 ASC_DBG(1, "scp 0x%p\n", scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04006029 if (scp == NULL) {
6030 ASC_PRINT
6031 ("adv_isr_callback: scp is NULL; adv_req_t dropped.\n");
6032 return;
6033 }
6034 ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
6035
Hannes Reinecke9c17c622015-04-24 13:18:21 +02006036 reqp = (adv_req_t *)scp->host_scribble;
6037 ASC_DBG(1, "reqp 0x%lx\n", (ulong)reqp);
6038 if (reqp == NULL) {
6039 ASC_PRINT("adv_isr_callback: reqp is NULL\n");
6040 return;
6041 }
6042 /*
6043 * Remove backreferences to avoid duplicate
6044 * command completions.
6045 */
6046 scp->host_scribble = NULL;
6047 reqp->cmndp = NULL;
Matthew Wilcox51219352007-10-02 21:55:22 -04006048
Hannes Reinecke9c17c622015-04-24 13:18:21 +02006049 ASC_STATS(boardp->shost, callback);
6050 ASC_DBG(1, "shost 0x%p\n", boardp->shost);
Matthew Wilcox51219352007-10-02 21:55:22 -04006051
Hannes Reinecke811ddc02015-04-24 13:18:22 +02006052 sense_addr = le32_to_cpu(scsiqp->sense_addr);
6053 dma_unmap_single(boardp->dev, sense_addr,
6054 SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
6055
Matthew Wilcox51219352007-10-02 21:55:22 -04006056 /*
6057 * 'done_status' contains the command's ending status.
6058 */
6059 switch (scsiqp->done_status) {
6060 case QD_NO_ERROR:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006061 ASC_DBG(2, "QD_NO_ERROR\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04006062 scp->result = 0;
6063
6064 /*
6065 * Check for an underrun condition.
6066 *
6067 * If there was no error and an underrun condition, then
6068 * then return the number of underrun bytes.
6069 */
6070 resid_cnt = le32_to_cpu(scsiqp->data_cnt);
Matthew Wilcox52c334e2007-10-02 21:55:39 -04006071 if (scsi_bufflen(scp) != 0 && resid_cnt != 0 &&
6072 resid_cnt <= scsi_bufflen(scp)) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006073 ASC_DBG(1, "underrun condition %lu bytes\n",
Matthew Wilcox51219352007-10-02 21:55:22 -04006074 (ulong)resid_cnt);
Matthew Wilcox52c334e2007-10-02 21:55:39 -04006075 scsi_set_resid(scp, resid_cnt);
Matthew Wilcox51219352007-10-02 21:55:22 -04006076 }
6077 break;
6078
6079 case QD_WITH_ERROR:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006080 ASC_DBG(2, "QD_WITH_ERROR\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04006081 switch (scsiqp->host_status) {
6082 case QHSTA_NO_ERROR:
6083 if (scsiqp->scsi_status == SAM_STAT_CHECK_CONDITION) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006084 ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04006085 ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09006086 SCSI_SENSE_BUFFERSIZE);
Matthew Wilcox51219352007-10-02 21:55:22 -04006087 /*
6088 * Note: The 'status_byte()' macro used by
6089 * target drivers defined in scsi.h shifts the
6090 * status byte returned by host drivers right
6091 * by 1 bit. This is why target drivers also
6092 * use right shifted status byte definitions.
6093 * For instance target drivers use
6094 * CHECK_CONDITION, defined to 0x1, instead of
6095 * the SCSI defined check condition value of
6096 * 0x2. Host drivers are supposed to return
6097 * the status byte as it is defined by SCSI.
6098 */
6099 scp->result = DRIVER_BYTE(DRIVER_SENSE) |
6100 STATUS_BYTE(scsiqp->scsi_status);
6101 } else {
6102 scp->result = STATUS_BYTE(scsiqp->scsi_status);
6103 }
6104 break;
6105
6106 default:
6107 /* Some other QHSTA error occurred. */
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006108 ASC_DBG(1, "host_status 0x%x\n", scsiqp->host_status);
Matthew Wilcox51219352007-10-02 21:55:22 -04006109 scp->result = HOST_BYTE(DID_BAD_TARGET);
6110 break;
6111 }
6112 break;
6113
6114 case QD_ABORTED_BY_HOST:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006115 ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04006116 scp->result =
6117 HOST_BYTE(DID_ABORT) | STATUS_BYTE(scsiqp->scsi_status);
6118 break;
6119
6120 default:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006121 ASC_DBG(1, "done_status 0x%x\n", scsiqp->done_status);
Matthew Wilcox51219352007-10-02 21:55:22 -04006122 scp->result =
6123 HOST_BYTE(DID_ERROR) | STATUS_BYTE(scsiqp->scsi_status);
6124 break;
6125 }
6126
6127 /*
6128 * If the 'init_tidmask' bit isn't already set for the target and the
6129 * current request finished normally, then set the bit for the target
6130 * to indicate that a device is present.
6131 */
6132 if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
6133 scsiqp->done_status == QD_NO_ERROR &&
6134 scsiqp->host_status == QHSTA_NO_ERROR) {
6135 boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
6136 }
6137
6138 asc_scsi_done(scp);
6139
6140 /*
6141 * Free all 'adv_sgblk_t' structures allocated for the request.
6142 */
6143 while ((sgblkp = reqp->sgblkp) != NULL) {
6144 /* Remove 'sgblkp' from the request list. */
6145 reqp->sgblkp = sgblkp->next_sgblkp;
6146
Hannes Reinecke0ce53822015-04-24 13:18:25 +02006147 dma_pool_free(boardp->adv_sgblk_pool, sgblkp,
6148 sgblkp->sg_addr);
Matthew Wilcox51219352007-10-02 21:55:22 -04006149 }
6150
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006151 ASC_DBG(1, "done\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04006152}
6153
6154/*
6155 * Adv Library Interrupt Service Routine
6156 *
6157 * This function is called by a driver's interrupt service routine.
6158 * The function disables and re-enables interrupts.
6159 *
6160 * When a microcode idle command is completed, the ADV_DVC_VAR
6161 * 'idle_cmd_done' field is set to ADV_TRUE.
6162 *
6163 * Note: AdvISR() can be called when interrupts are disabled or even
6164 * when there is no hardware interrupt condition present. It will
6165 * always check for completed idle commands and microcode requests.
6166 * This is an important feature that shouldn't be changed because it
6167 * allows commands to be completed from polling mode loops.
6168 *
6169 * Return:
6170 * ADV_TRUE(1) - interrupt was pending
6171 * ADV_FALSE(0) - no interrupt was pending
6172 */
6173static int AdvISR(ADV_DVC_VAR *asc_dvc)
6174{
6175 AdvPortAddr iop_base;
6176 uchar int_stat;
6177 ushort target_bit;
6178 ADV_CARR_T *free_carrp;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02006179 __le32 irq_next_vpa;
Matthew Wilcox51219352007-10-02 21:55:22 -04006180 ADV_SCSI_REQ_Q *scsiq;
Hannes Reinecke4b47e462015-04-24 13:18:24 +02006181 adv_req_t *reqp;
Matthew Wilcox51219352007-10-02 21:55:22 -04006182
6183 iop_base = asc_dvc->iop_base;
6184
6185 /* Reading the register clears the interrupt. */
6186 int_stat = AdvReadByteRegister(iop_base, IOPB_INTR_STATUS_REG);
6187
6188 if ((int_stat & (ADV_INTR_STATUS_INTRA | ADV_INTR_STATUS_INTRB |
6189 ADV_INTR_STATUS_INTRC)) == 0) {
6190 return ADV_FALSE;
6191 }
6192
6193 /*
6194 * Notify the driver of an asynchronous microcode condition by
6195 * calling the adv_async_callback function. The function
6196 * is passed the microcode ASC_MC_INTRB_CODE byte value.
6197 */
6198 if (int_stat & ADV_INTR_STATUS_INTRB) {
6199 uchar intrb_code;
6200
6201 AdvReadByteLram(iop_base, ASC_MC_INTRB_CODE, intrb_code);
6202
6203 if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
6204 asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
6205 if (intrb_code == ADV_ASYNC_CARRIER_READY_FAILURE &&
6206 asc_dvc->carr_pending_cnt != 0) {
6207 AdvWriteByteRegister(iop_base, IOPB_TICKLE,
6208 ADV_TICKLE_A);
6209 if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
6210 AdvWriteByteRegister(iop_base,
6211 IOPB_TICKLE,
6212 ADV_TICKLE_NOP);
6213 }
6214 }
6215 }
6216
6217 adv_async_callback(asc_dvc, intrb_code);
6218 }
6219
6220 /*
6221 * Check if the IRQ stopper carrier contains a completed request.
6222 */
6223 while (((irq_next_vpa =
6224 le32_to_cpu(asc_dvc->irq_sp->next_vpa)) & ASC_RQ_DONE) != 0) {
6225 /*
6226 * Get a pointer to the newly completed ADV_SCSI_REQ_Q structure.
6227 * The RISC will have set 'areq_vpa' to a virtual address.
6228 *
Hannes Reinecke9fef6ba2015-04-24 13:18:33 +02006229 * The firmware will have copied the ADV_SCSI_REQ_Q.scsiq_ptr
Matthew Wilcox51219352007-10-02 21:55:22 -04006230 * field to the carrier ADV_CARR_T.areq_vpa field. The conversion
Hannes Reinecke9fef6ba2015-04-24 13:18:33 +02006231 * below complements the conversion of ADV_SCSI_REQ_Q.scsiq_ptr'
Matthew Wilcox51219352007-10-02 21:55:22 -04006232 * in AdvExeScsiQueue().
6233 */
Hannes Reinecke4b47e462015-04-24 13:18:24 +02006234 u32 pa_offset = le32_to_cpu(asc_dvc->irq_sp->areq_vpa);
6235 ASC_DBG(1, "irq_sp %p areq_vpa %u\n",
6236 asc_dvc->irq_sp, pa_offset);
6237 reqp = adv_get_reqp(asc_dvc, pa_offset);
6238 scsiq = &reqp->scsi_req_q;
Matthew Wilcox51219352007-10-02 21:55:22 -04006239
6240 /*
6241 * Request finished with good status and the queue was not
6242 * DMAed to host memory by the firmware. Set all status fields
6243 * to indicate good status.
6244 */
6245 if ((irq_next_vpa & ASC_RQ_GOOD) != 0) {
6246 scsiq->done_status = QD_NO_ERROR;
6247 scsiq->host_status = scsiq->scsi_status = 0;
6248 scsiq->data_cnt = 0L;
6249 }
6250
6251 /*
6252 * Advance the stopper pointer to the next carrier
6253 * ignoring the lower four bits. Free the previous
6254 * stopper carrier.
6255 */
6256 free_carrp = asc_dvc->irq_sp;
Hannes Reinecke98b96a72015-04-24 13:18:23 +02006257 asc_dvc->irq_sp = adv_get_carrier(asc_dvc,
6258 ASC_GET_CARRP(irq_next_vpa));
Matthew Wilcox51219352007-10-02 21:55:22 -04006259
Hannes Reinecke98b96a72015-04-24 13:18:23 +02006260 free_carrp->next_vpa = asc_dvc->carr_freelist->carr_va;
Matthew Wilcox51219352007-10-02 21:55:22 -04006261 asc_dvc->carr_freelist = free_carrp;
6262 asc_dvc->carr_pending_cnt--;
6263
6264 target_bit = ADV_TID_TO_TIDMASK(scsiq->target_id);
6265
6266 /*
6267 * Clear request microcode control flag.
6268 */
6269 scsiq->cntl = 0;
6270
6271 /*
6272 * Notify the driver of the completed request by passing
6273 * the ADV_SCSI_REQ_Q pointer to its callback function.
6274 */
6275 scsiq->a_flag |= ADV_SCSIQ_DONE;
6276 adv_isr_callback(asc_dvc, scsiq);
6277 /*
6278 * Note: After the driver callback function is called, 'scsiq'
6279 * can no longer be referenced.
6280 *
6281 * Fall through and continue processing other completed
6282 * requests...
6283 */
6284 }
6285 return ADV_TRUE;
6286}
6287
6288static int AscSetLibErrorCode(ASC_DVC_VAR *asc_dvc, ushort err_code)
6289{
6290 if (asc_dvc->err_code == 0) {
6291 asc_dvc->err_code = err_code;
6292 AscWriteLramWord(asc_dvc->iop_base, ASCV_ASCDVC_ERR_CODE_W,
6293 err_code);
6294 }
6295 return err_code;
6296}
6297
6298static void AscAckInterrupt(PortAddr iop_base)
6299{
6300 uchar host_flag;
6301 uchar risc_flag;
6302 ushort loop;
6303
6304 loop = 0;
6305 do {
6306 risc_flag = AscReadLramByte(iop_base, ASCV_RISC_FLAG_B);
6307 if (loop++ > 0x7FFF) {
6308 break;
6309 }
6310 } while ((risc_flag & ASC_RISC_FLAG_GEN_INT) != 0);
6311 host_flag =
6312 AscReadLramByte(iop_base,
6313 ASCV_HOST_FLAG_B) & (~ASC_HOST_FLAG_ACK_INT);
6314 AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
6315 (uchar)(host_flag | ASC_HOST_FLAG_ACK_INT));
6316 AscSetChipStatus(iop_base, CIW_INT_ACK);
6317 loop = 0;
6318 while (AscGetChipStatus(iop_base) & CSW_INT_PENDING) {
6319 AscSetChipStatus(iop_base, CIW_INT_ACK);
6320 if (loop++ > 3) {
6321 break;
6322 }
6323 }
6324 AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
Matthew Wilcox51219352007-10-02 21:55:22 -04006325}
6326
6327static uchar AscGetSynPeriodIndex(ASC_DVC_VAR *asc_dvc, uchar syn_time)
6328{
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04006329 const uchar *period_table;
Matthew Wilcox51219352007-10-02 21:55:22 -04006330 int max_index;
6331 int min_index;
6332 int i;
6333
6334 period_table = asc_dvc->sdtr_period_tbl;
6335 max_index = (int)asc_dvc->max_sdtr_index;
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04006336 min_index = (int)asc_dvc->min_sdtr_index;
Matthew Wilcox51219352007-10-02 21:55:22 -04006337 if ((syn_time <= period_table[max_index])) {
6338 for (i = min_index; i < (max_index - 1); i++) {
6339 if (syn_time <= period_table[i]) {
6340 return (uchar)i;
6341 }
6342 }
6343 return (uchar)max_index;
6344 } else {
6345 return (uchar)(max_index + 1);
6346 }
6347}
6348
6349static uchar
6350AscMsgOutSDTR(ASC_DVC_VAR *asc_dvc, uchar sdtr_period, uchar sdtr_offset)
6351{
6352 EXT_MSG sdtr_buf;
6353 uchar sdtr_period_index;
6354 PortAddr iop_base;
6355
6356 iop_base = asc_dvc->iop_base;
6357 sdtr_buf.msg_type = EXTENDED_MESSAGE;
6358 sdtr_buf.msg_len = MS_SDTR_LEN;
6359 sdtr_buf.msg_req = EXTENDED_SDTR;
6360 sdtr_buf.xfer_period = sdtr_period;
6361 sdtr_offset &= ASC_SYN_MAX_OFFSET;
6362 sdtr_buf.req_ack_offset = sdtr_offset;
6363 sdtr_period_index = AscGetSynPeriodIndex(asc_dvc, sdtr_period);
6364 if (sdtr_period_index <= asc_dvc->max_sdtr_index) {
6365 AscMemWordCopyPtrToLram(iop_base, ASCV_MSGOUT_BEG,
6366 (uchar *)&sdtr_buf,
6367 sizeof(EXT_MSG) >> 1);
6368 return ((sdtr_period_index << 4) | sdtr_offset);
6369 } else {
6370 sdtr_buf.req_ack_offset = 0;
6371 AscMemWordCopyPtrToLram(iop_base, ASCV_MSGOUT_BEG,
6372 (uchar *)&sdtr_buf,
6373 sizeof(EXT_MSG) >> 1);
6374 return 0;
6375 }
6376}
6377
6378static uchar
6379AscCalSDTRData(ASC_DVC_VAR *asc_dvc, uchar sdtr_period, uchar syn_offset)
6380{
6381 uchar byte;
6382 uchar sdtr_period_ix;
6383
6384 sdtr_period_ix = AscGetSynPeriodIndex(asc_dvc, sdtr_period);
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04006385 if (sdtr_period_ix > asc_dvc->max_sdtr_index)
Matthew Wilcox51219352007-10-02 21:55:22 -04006386 return 0xFF;
Matthew Wilcox51219352007-10-02 21:55:22 -04006387 byte = (sdtr_period_ix << 4) | (syn_offset & ASC_SYN_MAX_OFFSET);
6388 return byte;
6389}
6390
Hannes Reinecked647c782015-04-24 13:18:26 +02006391static bool AscSetChipSynRegAtID(PortAddr iop_base, uchar id, uchar sdtr_data)
Matthew Wilcox51219352007-10-02 21:55:22 -04006392{
6393 ASC_SCSI_BIT_ID_TYPE org_id;
6394 int i;
Hannes Reinecked647c782015-04-24 13:18:26 +02006395 bool sta = true;
Matthew Wilcox51219352007-10-02 21:55:22 -04006396
6397 AscSetBank(iop_base, 1);
6398 org_id = AscReadChipDvcID(iop_base);
6399 for (i = 0; i <= ASC_MAX_TID; i++) {
6400 if (org_id == (0x01 << i))
6401 break;
6402 }
6403 org_id = (ASC_SCSI_BIT_ID_TYPE) i;
6404 AscWriteChipDvcID(iop_base, id);
6405 if (AscReadChipDvcID(iop_base) == (0x01 << id)) {
6406 AscSetBank(iop_base, 0);
6407 AscSetChipSyn(iop_base, sdtr_data);
6408 if (AscGetChipSyn(iop_base) != sdtr_data) {
Hannes Reinecked647c782015-04-24 13:18:26 +02006409 sta = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04006410 }
6411 } else {
Hannes Reinecked647c782015-04-24 13:18:26 +02006412 sta = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04006413 }
6414 AscSetBank(iop_base, 1);
6415 AscWriteChipDvcID(iop_base, org_id);
6416 AscSetBank(iop_base, 0);
6417 return (sta);
6418}
6419
6420static void AscSetChipSDTR(PortAddr iop_base, uchar sdtr_data, uchar tid_no)
6421{
6422 AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
6423 AscPutMCodeSDTRDoneAtID(iop_base, tid_no, sdtr_data);
6424}
6425
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006426static void AscIsrChipHalted(ASC_DVC_VAR *asc_dvc)
Matthew Wilcox51219352007-10-02 21:55:22 -04006427{
6428 EXT_MSG ext_msg;
6429 EXT_MSG out_msg;
6430 ushort halt_q_addr;
Hannes Reineckeae267592015-04-24 13:18:28 +02006431 bool sdtr_accept;
Matthew Wilcox51219352007-10-02 21:55:22 -04006432 ushort int_halt_code;
6433 ASC_SCSI_BIT_ID_TYPE scsi_busy;
6434 ASC_SCSI_BIT_ID_TYPE target_id;
6435 PortAddr iop_base;
6436 uchar tag_code;
6437 uchar q_status;
6438 uchar halt_qp;
6439 uchar sdtr_data;
6440 uchar target_ix;
6441 uchar q_cntl, tid_no;
6442 uchar cur_dvc_qng;
6443 uchar asyn_sdtr;
6444 uchar scsi_status;
Matthew Wilcoxd2411492007-10-02 21:55:31 -04006445 struct asc_board *boardp;
Matthew Wilcox51219352007-10-02 21:55:22 -04006446
6447 BUG_ON(!asc_dvc->drv_ptr);
6448 boardp = asc_dvc->drv_ptr;
6449
6450 iop_base = asc_dvc->iop_base;
6451 int_halt_code = AscReadLramWord(iop_base, ASCV_HALTCODE_W);
6452
6453 halt_qp = AscReadLramByte(iop_base, ASCV_CURCDB_B);
6454 halt_q_addr = ASC_QNO_TO_QADDR(halt_qp);
6455 target_ix = AscReadLramByte(iop_base,
6456 (ushort)(halt_q_addr +
6457 (ushort)ASC_SCSIQ_B_TARGET_IX));
6458 q_cntl = AscReadLramByte(iop_base,
6459 (ushort)(halt_q_addr + (ushort)ASC_SCSIQ_B_CNTL));
6460 tid_no = ASC_TIX_TO_TID(target_ix);
6461 target_id = (uchar)ASC_TID_TO_TARGET_ID(tid_no);
6462 if (asc_dvc->pci_fix_asyn_xfer & target_id) {
6463 asyn_sdtr = ASYN_SDTR_DATA_FIX_PCI_REV_AB;
6464 } else {
6465 asyn_sdtr = 0;
6466 }
6467 if (int_halt_code == ASC_HALT_DISABLE_ASYN_USE_SYN_FIX) {
6468 if (asc_dvc->pci_fix_asyn_xfer & target_id) {
6469 AscSetChipSDTR(iop_base, 0, tid_no);
6470 boardp->sdtr_data[tid_no] = 0;
6471 }
6472 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006473 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006474 } else if (int_halt_code == ASC_HALT_ENABLE_ASYN_USE_SYN_FIX) {
6475 if (asc_dvc->pci_fix_asyn_xfer & target_id) {
6476 AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
6477 boardp->sdtr_data[tid_no] = asyn_sdtr;
6478 }
6479 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006480 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006481 } else if (int_halt_code == ASC_HALT_EXTMSG_IN) {
6482 AscMemWordCopyPtrFromLram(iop_base,
6483 ASCV_MSGIN_BEG,
6484 (uchar *)&ext_msg,
6485 sizeof(EXT_MSG) >> 1);
6486
6487 if (ext_msg.msg_type == EXTENDED_MESSAGE &&
6488 ext_msg.msg_req == EXTENDED_SDTR &&
6489 ext_msg.msg_len == MS_SDTR_LEN) {
Hannes Reineckeae267592015-04-24 13:18:28 +02006490 sdtr_accept = true;
Matthew Wilcox51219352007-10-02 21:55:22 -04006491 if ((ext_msg.req_ack_offset > ASC_SYN_MAX_OFFSET)) {
6492
Hannes Reineckeae267592015-04-24 13:18:28 +02006493 sdtr_accept = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04006494 ext_msg.req_ack_offset = ASC_SYN_MAX_OFFSET;
6495 }
6496 if ((ext_msg.xfer_period <
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04006497 asc_dvc->sdtr_period_tbl[asc_dvc->min_sdtr_index])
Matthew Wilcox51219352007-10-02 21:55:22 -04006498 || (ext_msg.xfer_period >
6499 asc_dvc->sdtr_period_tbl[asc_dvc->
6500 max_sdtr_index])) {
Hannes Reineckeae267592015-04-24 13:18:28 +02006501 sdtr_accept = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04006502 ext_msg.xfer_period =
6503 asc_dvc->sdtr_period_tbl[asc_dvc->
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04006504 min_sdtr_index];
Matthew Wilcox51219352007-10-02 21:55:22 -04006505 }
6506 if (sdtr_accept) {
6507 sdtr_data =
6508 AscCalSDTRData(asc_dvc, ext_msg.xfer_period,
6509 ext_msg.req_ack_offset);
6510 if ((sdtr_data == 0xFF)) {
6511
6512 q_cntl |= QC_MSG_OUT;
6513 asc_dvc->init_sdtr &= ~target_id;
6514 asc_dvc->sdtr_done &= ~target_id;
6515 AscSetChipSDTR(iop_base, asyn_sdtr,
6516 tid_no);
6517 boardp->sdtr_data[tid_no] = asyn_sdtr;
6518 }
6519 }
6520 if (ext_msg.req_ack_offset == 0) {
6521
6522 q_cntl &= ~QC_MSG_OUT;
6523 asc_dvc->init_sdtr &= ~target_id;
6524 asc_dvc->sdtr_done &= ~target_id;
6525 AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
6526 } else {
6527 if (sdtr_accept && (q_cntl & QC_MSG_OUT)) {
Matthew Wilcox51219352007-10-02 21:55:22 -04006528 q_cntl &= ~QC_MSG_OUT;
6529 asc_dvc->sdtr_done |= target_id;
6530 asc_dvc->init_sdtr |= target_id;
6531 asc_dvc->pci_fix_asyn_xfer &=
6532 ~target_id;
6533 sdtr_data =
6534 AscCalSDTRData(asc_dvc,
6535 ext_msg.xfer_period,
6536 ext_msg.
6537 req_ack_offset);
6538 AscSetChipSDTR(iop_base, sdtr_data,
6539 tid_no);
6540 boardp->sdtr_data[tid_no] = sdtr_data;
6541 } else {
Matthew Wilcox51219352007-10-02 21:55:22 -04006542 q_cntl |= QC_MSG_OUT;
6543 AscMsgOutSDTR(asc_dvc,
6544 ext_msg.xfer_period,
6545 ext_msg.req_ack_offset);
6546 asc_dvc->pci_fix_asyn_xfer &=
6547 ~target_id;
6548 sdtr_data =
6549 AscCalSDTRData(asc_dvc,
6550 ext_msg.xfer_period,
6551 ext_msg.
6552 req_ack_offset);
6553 AscSetChipSDTR(iop_base, sdtr_data,
6554 tid_no);
6555 boardp->sdtr_data[tid_no] = sdtr_data;
6556 asc_dvc->sdtr_done |= target_id;
6557 asc_dvc->init_sdtr |= target_id;
6558 }
6559 }
6560
6561 AscWriteLramByte(iop_base,
6562 (ushort)(halt_q_addr +
6563 (ushort)ASC_SCSIQ_B_CNTL),
6564 q_cntl);
6565 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006566 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006567 } else if (ext_msg.msg_type == EXTENDED_MESSAGE &&
6568 ext_msg.msg_req == EXTENDED_WDTR &&
6569 ext_msg.msg_len == MS_WDTR_LEN) {
6570
6571 ext_msg.wdtr_width = 0;
6572 AscMemWordCopyPtrToLram(iop_base,
6573 ASCV_MSGOUT_BEG,
6574 (uchar *)&ext_msg,
6575 sizeof(EXT_MSG) >> 1);
6576 q_cntl |= QC_MSG_OUT;
6577 AscWriteLramByte(iop_base,
6578 (ushort)(halt_q_addr +
6579 (ushort)ASC_SCSIQ_B_CNTL),
6580 q_cntl);
6581 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006582 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006583 } else {
6584
6585 ext_msg.msg_type = MESSAGE_REJECT;
6586 AscMemWordCopyPtrToLram(iop_base,
6587 ASCV_MSGOUT_BEG,
6588 (uchar *)&ext_msg,
6589 sizeof(EXT_MSG) >> 1);
6590 q_cntl |= QC_MSG_OUT;
6591 AscWriteLramByte(iop_base,
6592 (ushort)(halt_q_addr +
6593 (ushort)ASC_SCSIQ_B_CNTL),
6594 q_cntl);
6595 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006596 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006597 }
6598 } else if (int_halt_code == ASC_HALT_CHK_CONDITION) {
6599
6600 q_cntl |= QC_REQ_SENSE;
6601
6602 if ((asc_dvc->init_sdtr & target_id) != 0) {
6603
6604 asc_dvc->sdtr_done &= ~target_id;
6605
6606 sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
6607 q_cntl |= QC_MSG_OUT;
6608 AscMsgOutSDTR(asc_dvc,
6609 asc_dvc->
6610 sdtr_period_tbl[(sdtr_data >> 4) &
6611 (uchar)(asc_dvc->
6612 max_sdtr_index -
6613 1)],
6614 (uchar)(sdtr_data & (uchar)
6615 ASC_SYN_MAX_OFFSET));
6616 }
6617
6618 AscWriteLramByte(iop_base,
6619 (ushort)(halt_q_addr +
6620 (ushort)ASC_SCSIQ_B_CNTL), q_cntl);
6621
6622 tag_code = AscReadLramByte(iop_base,
6623 (ushort)(halt_q_addr + (ushort)
6624 ASC_SCSIQ_B_TAG_CODE));
6625 tag_code &= 0xDC;
6626 if ((asc_dvc->pci_fix_asyn_xfer & target_id)
6627 && !(asc_dvc->pci_fix_asyn_xfer_always & target_id)
6628 ) {
6629
6630 tag_code |= (ASC_TAG_FLAG_DISABLE_DISCONNECT
6631 | ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX);
6632
6633 }
6634 AscWriteLramByte(iop_base,
6635 (ushort)(halt_q_addr +
6636 (ushort)ASC_SCSIQ_B_TAG_CODE),
6637 tag_code);
6638
6639 q_status = AscReadLramByte(iop_base,
6640 (ushort)(halt_q_addr + (ushort)
6641 ASC_SCSIQ_B_STATUS));
6642 q_status |= (QS_READY | QS_BUSY);
6643 AscWriteLramByte(iop_base,
6644 (ushort)(halt_q_addr +
6645 (ushort)ASC_SCSIQ_B_STATUS),
6646 q_status);
6647
6648 scsi_busy = AscReadLramByte(iop_base, (ushort)ASCV_SCSIBUSY_B);
6649 scsi_busy &= ~target_id;
6650 AscWriteLramByte(iop_base, (ushort)ASCV_SCSIBUSY_B, scsi_busy);
6651
6652 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006653 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006654 } else if (int_halt_code == ASC_HALT_SDTR_REJECTED) {
6655
6656 AscMemWordCopyPtrFromLram(iop_base,
6657 ASCV_MSGOUT_BEG,
6658 (uchar *)&out_msg,
6659 sizeof(EXT_MSG) >> 1);
6660
6661 if ((out_msg.msg_type == EXTENDED_MESSAGE) &&
6662 (out_msg.msg_len == MS_SDTR_LEN) &&
6663 (out_msg.msg_req == EXTENDED_SDTR)) {
6664
6665 asc_dvc->init_sdtr &= ~target_id;
6666 asc_dvc->sdtr_done &= ~target_id;
6667 AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
6668 boardp->sdtr_data[tid_no] = asyn_sdtr;
6669 }
6670 q_cntl &= ~QC_MSG_OUT;
6671 AscWriteLramByte(iop_base,
6672 (ushort)(halt_q_addr +
6673 (ushort)ASC_SCSIQ_B_CNTL), q_cntl);
6674 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006675 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006676 } else if (int_halt_code == ASC_HALT_SS_QUEUE_FULL) {
6677
6678 scsi_status = AscReadLramByte(iop_base,
6679 (ushort)((ushort)halt_q_addr +
6680 (ushort)
6681 ASC_SCSIQ_SCSI_STATUS));
6682 cur_dvc_qng =
6683 AscReadLramByte(iop_base,
6684 (ushort)((ushort)ASC_QADR_BEG +
6685 (ushort)target_ix));
6686 if ((cur_dvc_qng > 0) && (asc_dvc->cur_dvc_qng[tid_no] > 0)) {
6687
6688 scsi_busy = AscReadLramByte(iop_base,
6689 (ushort)ASCV_SCSIBUSY_B);
6690 scsi_busy |= target_id;
6691 AscWriteLramByte(iop_base,
6692 (ushort)ASCV_SCSIBUSY_B, scsi_busy);
6693 asc_dvc->queue_full_or_busy |= target_id;
6694
6695 if (scsi_status == SAM_STAT_TASK_SET_FULL) {
6696 if (cur_dvc_qng > ASC_MIN_TAGGED_CMD) {
6697 cur_dvc_qng -= 1;
6698 asc_dvc->max_dvc_qng[tid_no] =
6699 cur_dvc_qng;
6700
6701 AscWriteLramByte(iop_base,
6702 (ushort)((ushort)
6703 ASCV_MAX_DVC_QNG_BEG
6704 + (ushort)
6705 tid_no),
6706 cur_dvc_qng);
6707
6708 /*
6709 * Set the device queue depth to the
6710 * number of active requests when the
6711 * QUEUE FULL condition was encountered.
6712 */
6713 boardp->queue_full |= target_id;
6714 boardp->queue_full_cnt[tid_no] =
6715 cur_dvc_qng;
6716 }
6717 }
6718 }
6719 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006720 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006721 }
6722#if CC_VERY_LONG_SG_LIST
6723 else if (int_halt_code == ASC_HALT_HOST_COPY_SG_LIST_TO_RISC) {
6724 uchar q_no;
6725 ushort q_addr;
6726 uchar sg_wk_q_no;
6727 uchar first_sg_wk_q_no;
6728 ASC_SCSI_Q *scsiq; /* Ptr to driver request. */
6729 ASC_SG_HEAD *sg_head; /* Ptr to driver SG request. */
6730 ASC_SG_LIST_Q scsi_sg_q; /* Structure written to queue. */
6731 ushort sg_list_dwords;
6732 ushort sg_entry_cnt;
6733 uchar next_qp;
6734 int i;
6735
6736 q_no = AscReadLramByte(iop_base, (ushort)ASCV_REQ_SG_LIST_QP);
6737 if (q_no == ASC_QLINK_END)
6738 return 0;
6739
6740 q_addr = ASC_QNO_TO_QADDR(q_no);
6741
6742 /*
Hannes Reinecke9fef6ba2015-04-24 13:18:33 +02006743 * Convert the request's SRB pointer to a host ASC_SCSI_Q
Matthew Wilcox51219352007-10-02 21:55:22 -04006744 * structure pointer using a macro provided by the driver.
Hannes Reinecke9fef6ba2015-04-24 13:18:33 +02006745 * The ASC_SCSI_Q pointer provides a pointer to the
Matthew Wilcox51219352007-10-02 21:55:22 -04006746 * host ASC_SG_HEAD structure.
6747 */
6748 /* Read request's SRB pointer. */
6749 scsiq = (ASC_SCSI_Q *)
6750 ASC_SRB2SCSIQ(ASC_U32_TO_VADDR(AscReadLramDWord(iop_base,
6751 (ushort)
6752 (q_addr +
6753 ASC_SCSIQ_D_SRBPTR))));
6754
6755 /*
6756 * Get request's first and working SG queue.
6757 */
6758 sg_wk_q_no = AscReadLramByte(iop_base,
6759 (ushort)(q_addr +
6760 ASC_SCSIQ_B_SG_WK_QP));
6761
6762 first_sg_wk_q_no = AscReadLramByte(iop_base,
6763 (ushort)(q_addr +
6764 ASC_SCSIQ_B_FIRST_SG_WK_QP));
6765
6766 /*
6767 * Reset request's working SG queue back to the
6768 * first SG queue.
6769 */
6770 AscWriteLramByte(iop_base,
6771 (ushort)(q_addr +
6772 (ushort)ASC_SCSIQ_B_SG_WK_QP),
6773 first_sg_wk_q_no);
6774
6775 sg_head = scsiq->sg_head;
6776
6777 /*
6778 * Set sg_entry_cnt to the number of SG elements
6779 * that will be completed on this interrupt.
6780 *
6781 * Note: The allocated SG queues contain ASC_MAX_SG_LIST - 1
6782 * SG elements. The data_cnt and data_addr fields which
6783 * add 1 to the SG element capacity are not used when
6784 * restarting SG handling after a halt.
6785 */
6786 if (scsiq->remain_sg_entry_cnt > (ASC_MAX_SG_LIST - 1)) {
6787 sg_entry_cnt = ASC_MAX_SG_LIST - 1;
6788
6789 /*
6790 * Keep track of remaining number of SG elements that
6791 * will need to be handled on the next interrupt.
6792 */
6793 scsiq->remain_sg_entry_cnt -= (ASC_MAX_SG_LIST - 1);
6794 } else {
6795 sg_entry_cnt = scsiq->remain_sg_entry_cnt;
6796 scsiq->remain_sg_entry_cnt = 0;
6797 }
6798
6799 /*
6800 * Copy SG elements into the list of allocated SG queues.
6801 *
6802 * Last index completed is saved in scsiq->next_sg_index.
6803 */
6804 next_qp = first_sg_wk_q_no;
6805 q_addr = ASC_QNO_TO_QADDR(next_qp);
6806 scsi_sg_q.sg_head_qp = q_no;
6807 scsi_sg_q.cntl = QCSG_SG_XFER_LIST;
6808 for (i = 0; i < sg_head->queue_cnt; i++) {
6809 scsi_sg_q.seq_no = i + 1;
6810 if (sg_entry_cnt > ASC_SG_LIST_PER_Q) {
6811 sg_list_dwords = (uchar)(ASC_SG_LIST_PER_Q * 2);
6812 sg_entry_cnt -= ASC_SG_LIST_PER_Q;
6813 /*
6814 * After very first SG queue RISC FW uses next
6815 * SG queue first element then checks sg_list_cnt
6816 * against zero and then decrements, so set
6817 * sg_list_cnt 1 less than number of SG elements
6818 * in each SG queue.
6819 */
6820 scsi_sg_q.sg_list_cnt = ASC_SG_LIST_PER_Q - 1;
6821 scsi_sg_q.sg_cur_list_cnt =
6822 ASC_SG_LIST_PER_Q - 1;
6823 } else {
6824 /*
6825 * This is the last SG queue in the list of
6826 * allocated SG queues. If there are more
6827 * SG elements than will fit in the allocated
6828 * queues, then set the QCSG_SG_XFER_MORE flag.
6829 */
6830 if (scsiq->remain_sg_entry_cnt != 0) {
6831 scsi_sg_q.cntl |= QCSG_SG_XFER_MORE;
6832 } else {
6833 scsi_sg_q.cntl |= QCSG_SG_XFER_END;
6834 }
6835 /* equals sg_entry_cnt * 2 */
6836 sg_list_dwords = sg_entry_cnt << 1;
6837 scsi_sg_q.sg_list_cnt = sg_entry_cnt - 1;
6838 scsi_sg_q.sg_cur_list_cnt = sg_entry_cnt - 1;
6839 sg_entry_cnt = 0;
6840 }
6841
6842 scsi_sg_q.q_no = next_qp;
6843 AscMemWordCopyPtrToLram(iop_base,
6844 q_addr + ASC_SCSIQ_SGHD_CPY_BEG,
6845 (uchar *)&scsi_sg_q,
6846 sizeof(ASC_SG_LIST_Q) >> 1);
6847
6848 AscMemDWordCopyPtrToLram(iop_base,
6849 q_addr + ASC_SGQ_LIST_BEG,
6850 (uchar *)&sg_head->
6851 sg_list[scsiq->next_sg_index],
6852 sg_list_dwords);
6853
6854 scsiq->next_sg_index += ASC_SG_LIST_PER_Q;
6855
6856 /*
6857 * If the just completed SG queue contained the
6858 * last SG element, then no more SG queues need
6859 * to be written.
6860 */
6861 if (scsi_sg_q.cntl & QCSG_SG_XFER_END) {
6862 break;
6863 }
6864
6865 next_qp = AscReadLramByte(iop_base,
6866 (ushort)(q_addr +
6867 ASC_SCSIQ_B_FWD));
6868 q_addr = ASC_QNO_TO_QADDR(next_qp);
6869 }
6870
6871 /*
6872 * Clear the halt condition so the RISC will be restarted
6873 * after the return.
6874 */
6875 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006876 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006877 }
6878#endif /* CC_VERY_LONG_SG_LIST */
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006879 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006880}
6881
6882/*
6883 * void
6884 * DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
6885 *
6886 * Calling/Exit State:
6887 * none
6888 *
6889 * Description:
6890 * Input an ASC_QDONE_INFO structure from the chip
6891 */
6892static void
6893DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
6894{
6895 int i;
6896 ushort word;
6897
6898 AscSetChipLramAddr(iop_base, s_addr);
6899 for (i = 0; i < 2 * words; i += 2) {
6900 if (i == 10) {
6901 continue;
6902 }
6903 word = inpw(iop_base + IOP_RAM_DATA);
6904 inbuf[i] = word & 0xff;
6905 inbuf[i + 1] = (word >> 8) & 0xff;
6906 }
6907 ASC_DBG_PRT_HEX(2, "DvcGetQinfo", inbuf, 2 * words);
6908}
6909
6910static uchar
6911_AscCopyLramScsiDoneQ(PortAddr iop_base,
6912 ushort q_addr,
Hannes Reinecke95cfab62015-04-24 13:18:27 +02006913 ASC_QDONE_INFO *scsiq, unsigned int max_dma_count)
Matthew Wilcox51219352007-10-02 21:55:22 -04006914{
6915 ushort _val;
6916 uchar sg_queue_cnt;
6917
6918 DvcGetQinfo(iop_base,
6919 q_addr + ASC_SCSIQ_DONE_INFO_BEG,
6920 (uchar *)scsiq,
6921 (sizeof(ASC_SCSIQ_2) + sizeof(ASC_SCSIQ_3)) / 2);
6922
6923 _val = AscReadLramWord(iop_base,
6924 (ushort)(q_addr + (ushort)ASC_SCSIQ_B_STATUS));
6925 scsiq->q_status = (uchar)_val;
6926 scsiq->q_no = (uchar)(_val >> 8);
6927 _val = AscReadLramWord(iop_base,
6928 (ushort)(q_addr + (ushort)ASC_SCSIQ_B_CNTL));
6929 scsiq->cntl = (uchar)_val;
6930 sg_queue_cnt = (uchar)(_val >> 8);
6931 _val = AscReadLramWord(iop_base,
6932 (ushort)(q_addr +
6933 (ushort)ASC_SCSIQ_B_SENSE_LEN));
6934 scsiq->sense_len = (uchar)_val;
6935 scsiq->extra_bytes = (uchar)(_val >> 8);
6936
6937 /*
6938 * Read high word of remain bytes from alternate location.
6939 */
Hannes Reinecke95cfab62015-04-24 13:18:27 +02006940 scsiq->remain_bytes = (((u32)AscReadLramWord(iop_base,
6941 (ushort)(q_addr +
6942 (ushort)
6943 ASC_SCSIQ_W_ALT_DC1)))
Matthew Wilcox51219352007-10-02 21:55:22 -04006944 << 16);
6945 /*
6946 * Read low word of remain bytes from original location.
6947 */
6948 scsiq->remain_bytes += AscReadLramWord(iop_base,
6949 (ushort)(q_addr + (ushort)
6950 ASC_SCSIQ_DW_REMAIN_XFER_CNT));
6951
6952 scsiq->remain_bytes &= max_dma_count;
6953 return sg_queue_cnt;
6954}
6955
6956/*
6957 * asc_isr_callback() - Second Level Interrupt Handler called by AscISR().
6958 *
6959 * Interrupt callback function for the Narrow SCSI Asc Library.
6960 */
6961static void asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep)
6962{
Hannes Reinecke9c17c622015-04-24 13:18:21 +02006963 struct asc_board *boardp = asc_dvc_varp->drv_ptr;
6964 u32 srb_tag;
Matthew Wilcox51219352007-10-02 21:55:22 -04006965 struct scsi_cmnd *scp;
Matthew Wilcox51219352007-10-02 21:55:22 -04006966
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006967 ASC_DBG(1, "asc_dvc_varp 0x%p, qdonep 0x%p\n", asc_dvc_varp, qdonep);
Matthew Wilcox51219352007-10-02 21:55:22 -04006968 ASC_DBG_PRT_ASC_QDONE_INFO(2, qdonep);
6969
Hannes Reinecke9c17c622015-04-24 13:18:21 +02006970 /*
6971 * Decrease the srb_tag by 1 to find the SCSI command
6972 */
6973 srb_tag = qdonep->d2.srb_tag - 1;
6974 scp = scsi_host_find_tag(boardp->shost, srb_tag);
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04006975 if (!scp)
Matthew Wilcox51219352007-10-02 21:55:22 -04006976 return;
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04006977
Matthew Wilcox51219352007-10-02 21:55:22 -04006978 ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
6979
Hannes Reinecke9c17c622015-04-24 13:18:21 +02006980 ASC_STATS(boardp->shost, callback);
Matthew Wilcox51219352007-10-02 21:55:22 -04006981
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04006982 dma_unmap_single(boardp->dev, scp->SCp.dma_handle,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09006983 SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
Matthew Wilcox51219352007-10-02 21:55:22 -04006984 /*
6985 * 'qdonep' contains the command's ending status.
6986 */
6987 switch (qdonep->d3.done_stat) {
6988 case QD_NO_ERROR:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006989 ASC_DBG(2, "QD_NO_ERROR\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04006990 scp->result = 0;
6991
6992 /*
6993 * Check for an underrun condition.
6994 *
6995 * If there was no error and an underrun condition, then
6996 * return the number of underrun bytes.
6997 */
Matthew Wilcox52c334e2007-10-02 21:55:39 -04006998 if (scsi_bufflen(scp) != 0 && qdonep->remain_bytes != 0 &&
6999 qdonep->remain_bytes <= scsi_bufflen(scp)) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007000 ASC_DBG(1, "underrun condition %u bytes\n",
Matthew Wilcox51219352007-10-02 21:55:22 -04007001 (unsigned)qdonep->remain_bytes);
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007002 scsi_set_resid(scp, qdonep->remain_bytes);
Matthew Wilcox51219352007-10-02 21:55:22 -04007003 }
7004 break;
7005
7006 case QD_WITH_ERROR:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007007 ASC_DBG(2, "QD_WITH_ERROR\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007008 switch (qdonep->d3.host_stat) {
7009 case QHSTA_NO_ERROR:
7010 if (qdonep->d3.scsi_stat == SAM_STAT_CHECK_CONDITION) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007011 ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007012 ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09007013 SCSI_SENSE_BUFFERSIZE);
Matthew Wilcox51219352007-10-02 21:55:22 -04007014 /*
7015 * Note: The 'status_byte()' macro used by
7016 * target drivers defined in scsi.h shifts the
7017 * status byte returned by host drivers right
7018 * by 1 bit. This is why target drivers also
7019 * use right shifted status byte definitions.
7020 * For instance target drivers use
7021 * CHECK_CONDITION, defined to 0x1, instead of
7022 * the SCSI defined check condition value of
7023 * 0x2. Host drivers are supposed to return
7024 * the status byte as it is defined by SCSI.
7025 */
7026 scp->result = DRIVER_BYTE(DRIVER_SENSE) |
7027 STATUS_BYTE(qdonep->d3.scsi_stat);
7028 } else {
7029 scp->result = STATUS_BYTE(qdonep->d3.scsi_stat);
7030 }
7031 break;
7032
7033 default:
7034 /* QHSTA error occurred */
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007035 ASC_DBG(1, "host_stat 0x%x\n", qdonep->d3.host_stat);
Matthew Wilcox51219352007-10-02 21:55:22 -04007036 scp->result = HOST_BYTE(DID_BAD_TARGET);
7037 break;
7038 }
7039 break;
7040
7041 case QD_ABORTED_BY_HOST:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007042 ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007043 scp->result =
7044 HOST_BYTE(DID_ABORT) | MSG_BYTE(qdonep->d3.
7045 scsi_msg) |
7046 STATUS_BYTE(qdonep->d3.scsi_stat);
7047 break;
7048
7049 default:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007050 ASC_DBG(1, "done_stat 0x%x\n", qdonep->d3.done_stat);
Matthew Wilcox51219352007-10-02 21:55:22 -04007051 scp->result =
7052 HOST_BYTE(DID_ERROR) | MSG_BYTE(qdonep->d3.
7053 scsi_msg) |
7054 STATUS_BYTE(qdonep->d3.scsi_stat);
7055 break;
7056 }
7057
7058 /*
7059 * If the 'init_tidmask' bit isn't already set for the target and the
7060 * current request finished normally, then set the bit for the target
7061 * to indicate that a device is present.
7062 */
7063 if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
7064 qdonep->d3.done_stat == QD_NO_ERROR &&
7065 qdonep->d3.host_stat == QHSTA_NO_ERROR) {
7066 boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
7067 }
7068
7069 asc_scsi_done(scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04007070}
7071
7072static int AscIsrQDone(ASC_DVC_VAR *asc_dvc)
7073{
7074 uchar next_qp;
7075 uchar n_q_used;
7076 uchar sg_list_qp;
7077 uchar sg_queue_cnt;
7078 uchar q_cnt;
7079 uchar done_q_tail;
7080 uchar tid_no;
7081 ASC_SCSI_BIT_ID_TYPE scsi_busy;
7082 ASC_SCSI_BIT_ID_TYPE target_id;
7083 PortAddr iop_base;
7084 ushort q_addr;
7085 ushort sg_q_addr;
7086 uchar cur_target_qng;
7087 ASC_QDONE_INFO scsiq_buf;
7088 ASC_QDONE_INFO *scsiq;
Hannes Reineckeae267592015-04-24 13:18:28 +02007089 bool false_overrun;
Matthew Wilcox51219352007-10-02 21:55:22 -04007090
7091 iop_base = asc_dvc->iop_base;
7092 n_q_used = 1;
7093 scsiq = (ASC_QDONE_INFO *)&scsiq_buf;
7094 done_q_tail = (uchar)AscGetVarDoneQTail(iop_base);
7095 q_addr = ASC_QNO_TO_QADDR(done_q_tail);
7096 next_qp = AscReadLramByte(iop_base,
7097 (ushort)(q_addr + (ushort)ASC_SCSIQ_B_FWD));
7098 if (next_qp != ASC_QLINK_END) {
7099 AscPutVarDoneQTail(iop_base, next_qp);
7100 q_addr = ASC_QNO_TO_QADDR(next_qp);
7101 sg_queue_cnt = _AscCopyLramScsiDoneQ(iop_base, q_addr, scsiq,
7102 asc_dvc->max_dma_count);
7103 AscWriteLramByte(iop_base,
7104 (ushort)(q_addr +
7105 (ushort)ASC_SCSIQ_B_STATUS),
7106 (uchar)(scsiq->
7107 q_status & (uchar)~(QS_READY |
7108 QS_ABORTED)));
7109 tid_no = ASC_TIX_TO_TID(scsiq->d2.target_ix);
7110 target_id = ASC_TIX_TO_TARGET_ID(scsiq->d2.target_ix);
7111 if ((scsiq->cntl & QC_SG_HEAD) != 0) {
7112 sg_q_addr = q_addr;
7113 sg_list_qp = next_qp;
7114 for (q_cnt = 0; q_cnt < sg_queue_cnt; q_cnt++) {
7115 sg_list_qp = AscReadLramByte(iop_base,
7116 (ushort)(sg_q_addr
7117 + (ushort)
7118 ASC_SCSIQ_B_FWD));
7119 sg_q_addr = ASC_QNO_TO_QADDR(sg_list_qp);
7120 if (sg_list_qp == ASC_QLINK_END) {
7121 AscSetLibErrorCode(asc_dvc,
7122 ASCQ_ERR_SG_Q_LINKS);
7123 scsiq->d3.done_stat = QD_WITH_ERROR;
7124 scsiq->d3.host_stat =
7125 QHSTA_D_QDONE_SG_LIST_CORRUPTED;
7126 goto FATAL_ERR_QDONE;
7127 }
7128 AscWriteLramByte(iop_base,
7129 (ushort)(sg_q_addr + (ushort)
7130 ASC_SCSIQ_B_STATUS),
7131 QS_FREE);
7132 }
7133 n_q_used = sg_queue_cnt + 1;
7134 AscPutVarDoneQTail(iop_base, sg_list_qp);
7135 }
7136 if (asc_dvc->queue_full_or_busy & target_id) {
7137 cur_target_qng = AscReadLramByte(iop_base,
7138 (ushort)((ushort)
7139 ASC_QADR_BEG
7140 + (ushort)
7141 scsiq->d2.
7142 target_ix));
7143 if (cur_target_qng < asc_dvc->max_dvc_qng[tid_no]) {
7144 scsi_busy = AscReadLramByte(iop_base, (ushort)
7145 ASCV_SCSIBUSY_B);
7146 scsi_busy &= ~target_id;
7147 AscWriteLramByte(iop_base,
7148 (ushort)ASCV_SCSIBUSY_B,
7149 scsi_busy);
7150 asc_dvc->queue_full_or_busy &= ~target_id;
7151 }
7152 }
7153 if (asc_dvc->cur_total_qng >= n_q_used) {
7154 asc_dvc->cur_total_qng -= n_q_used;
7155 if (asc_dvc->cur_dvc_qng[tid_no] != 0) {
7156 asc_dvc->cur_dvc_qng[tid_no]--;
7157 }
7158 } else {
7159 AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CUR_QNG);
7160 scsiq->d3.done_stat = QD_WITH_ERROR;
7161 goto FATAL_ERR_QDONE;
7162 }
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007163 if ((scsiq->d2.srb_tag == 0UL) ||
Matthew Wilcox51219352007-10-02 21:55:22 -04007164 ((scsiq->q_status & QS_ABORTED) != 0)) {
7165 return (0x11);
7166 } else if (scsiq->q_status == QS_DONE) {
Hannes Reineckeae267592015-04-24 13:18:28 +02007167 /*
7168 * This is also curious.
7169 * false_overrun will _always_ be set to 'false'
7170 */
7171 false_overrun = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04007172 if (scsiq->extra_bytes != 0) {
Hannes Reinecke95cfab62015-04-24 13:18:27 +02007173 scsiq->remain_bytes += scsiq->extra_bytes;
Matthew Wilcox51219352007-10-02 21:55:22 -04007174 }
7175 if (scsiq->d3.done_stat == QD_WITH_ERROR) {
7176 if (scsiq->d3.host_stat ==
7177 QHSTA_M_DATA_OVER_RUN) {
7178 if ((scsiq->
7179 cntl & (QC_DATA_IN | QC_DATA_OUT))
7180 == 0) {
7181 scsiq->d3.done_stat =
7182 QD_NO_ERROR;
7183 scsiq->d3.host_stat =
7184 QHSTA_NO_ERROR;
7185 } else if (false_overrun) {
7186 scsiq->d3.done_stat =
7187 QD_NO_ERROR;
7188 scsiq->d3.host_stat =
7189 QHSTA_NO_ERROR;
7190 }
7191 } else if (scsiq->d3.host_stat ==
7192 QHSTA_M_HUNG_REQ_SCSI_BUS_RESET) {
7193 AscStopChip(iop_base);
7194 AscSetChipControl(iop_base,
7195 (uchar)(CC_SCSI_RESET
7196 | CC_HALT));
7197 udelay(60);
7198 AscSetChipControl(iop_base, CC_HALT);
7199 AscSetChipStatus(iop_base,
7200 CIW_CLR_SCSI_RESET_INT);
7201 AscSetChipStatus(iop_base, 0);
7202 AscSetChipControl(iop_base, 0);
7203 }
7204 }
7205 if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
7206 asc_isr_callback(asc_dvc, scsiq);
7207 } else {
7208 if ((AscReadLramByte(iop_base,
7209 (ushort)(q_addr + (ushort)
7210 ASC_SCSIQ_CDB_BEG))
7211 == START_STOP)) {
7212 asc_dvc->unit_not_ready &= ~target_id;
7213 if (scsiq->d3.done_stat != QD_NO_ERROR) {
7214 asc_dvc->start_motor &=
7215 ~target_id;
7216 }
7217 }
7218 }
7219 return (1);
7220 } else {
7221 AscSetLibErrorCode(asc_dvc, ASCQ_ERR_Q_STATUS);
7222 FATAL_ERR_QDONE:
7223 if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
7224 asc_isr_callback(asc_dvc, scsiq);
7225 }
7226 return (0x80);
7227 }
7228 }
7229 return (0);
7230}
7231
7232static int AscISR(ASC_DVC_VAR *asc_dvc)
7233{
7234 ASC_CS_TYPE chipstat;
7235 PortAddr iop_base;
7236 ushort saved_ram_addr;
7237 uchar ctrl_reg;
7238 uchar saved_ctrl_reg;
7239 int int_pending;
7240 int status;
7241 uchar host_flag;
7242
7243 iop_base = asc_dvc->iop_base;
Hannes Reineckeae267592015-04-24 13:18:28 +02007244 int_pending = ASC_FALSE;
Matthew Wilcox51219352007-10-02 21:55:22 -04007245
7246 if (AscIsIntPending(iop_base) == 0)
7247 return int_pending;
7248
7249 if ((asc_dvc->init_state & ASC_INIT_STATE_END_LOAD_MC) == 0) {
Hannes Reineckeae267592015-04-24 13:18:28 +02007250 return ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04007251 }
7252 if (asc_dvc->in_critical_cnt != 0) {
7253 AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_ON_CRITICAL);
Hannes Reineckeae267592015-04-24 13:18:28 +02007254 return ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04007255 }
7256 if (asc_dvc->is_in_int) {
7257 AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_RE_ENTRY);
Hannes Reineckeae267592015-04-24 13:18:28 +02007258 return ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04007259 }
Hannes Reineckeae267592015-04-24 13:18:28 +02007260 asc_dvc->is_in_int = true;
Matthew Wilcox51219352007-10-02 21:55:22 -04007261 ctrl_reg = AscGetChipControl(iop_base);
7262 saved_ctrl_reg = ctrl_reg & (~(CC_SCSI_RESET | CC_CHIP_RESET |
7263 CC_SINGLE_STEP | CC_DIAG | CC_TEST));
7264 chipstat = AscGetChipStatus(iop_base);
7265 if (chipstat & CSW_SCSI_RESET_LATCH) {
7266 if (!(asc_dvc->bus_type & (ASC_IS_VL | ASC_IS_EISA))) {
7267 int i = 10;
Hannes Reineckeae267592015-04-24 13:18:28 +02007268 int_pending = ASC_TRUE;
Matthew Wilcox51219352007-10-02 21:55:22 -04007269 asc_dvc->sdtr_done = 0;
7270 saved_ctrl_reg &= (uchar)(~CC_HALT);
7271 while ((AscGetChipStatus(iop_base) &
7272 CSW_SCSI_RESET_ACTIVE) && (i-- > 0)) {
7273 mdelay(100);
7274 }
7275 AscSetChipControl(iop_base, (CC_CHIP_RESET | CC_HALT));
7276 AscSetChipControl(iop_base, CC_HALT);
7277 AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
7278 AscSetChipStatus(iop_base, 0);
7279 chipstat = AscGetChipStatus(iop_base);
7280 }
7281 }
7282 saved_ram_addr = AscGetChipLramAddr(iop_base);
7283 host_flag = AscReadLramByte(iop_base,
7284 ASCV_HOST_FLAG_B) &
7285 (uchar)(~ASC_HOST_FLAG_IN_ISR);
7286 AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
7287 (uchar)(host_flag | (uchar)ASC_HOST_FLAG_IN_ISR));
7288 if ((chipstat & CSW_INT_PENDING) || (int_pending)) {
7289 AscAckInterrupt(iop_base);
Hannes Reineckeae267592015-04-24 13:18:28 +02007290 int_pending = ASC_TRUE;
Matthew Wilcox51219352007-10-02 21:55:22 -04007291 if ((chipstat & CSW_HALTED) && (ctrl_reg & CC_SINGLE_STEP)) {
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02007292 AscIsrChipHalted(asc_dvc);
7293 saved_ctrl_reg &= (uchar)(~CC_HALT);
Matthew Wilcox51219352007-10-02 21:55:22 -04007294 } else {
Matthew Wilcox51219352007-10-02 21:55:22 -04007295 if ((asc_dvc->dvc_cntl & ASC_CNTL_INT_MULTI_Q) != 0) {
7296 while (((status =
7297 AscIsrQDone(asc_dvc)) & 0x01) != 0) {
7298 }
7299 } else {
7300 do {
7301 if ((status =
7302 AscIsrQDone(asc_dvc)) == 1) {
7303 break;
7304 }
7305 } while (status == 0x11);
7306 }
7307 if ((status & 0x80) != 0)
Hannes Reineckeae267592015-04-24 13:18:28 +02007308 int_pending = ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04007309 }
7310 }
7311 AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
7312 AscSetChipLramAddr(iop_base, saved_ram_addr);
7313 AscSetChipControl(iop_base, saved_ctrl_reg);
Hannes Reineckeae267592015-04-24 13:18:28 +02007314 asc_dvc->is_in_int = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04007315 return int_pending;
7316}
7317
7318/*
7319 * advansys_reset()
7320 *
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007321 * Reset the host associated with the command 'scp'.
Matthew Wilcox51219352007-10-02 21:55:22 -04007322 *
7323 * This function runs its own thread. Interrupts must be blocked but
7324 * sleeping is allowed and no locking other than for host structures is
7325 * required. Returns SUCCESS or FAILED.
7326 */
7327static int advansys_reset(struct scsi_cmnd *scp)
7328{
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007329 struct Scsi_Host *shost = scp->device->host;
Matthew Wilcoxd2411492007-10-02 21:55:31 -04007330 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007331 unsigned long flags;
Matthew Wilcox51219352007-10-02 21:55:22 -04007332 int status;
7333 int ret = SUCCESS;
7334
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007335 ASC_DBG(1, "0x%p\n", scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04007336
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007337 ASC_STATS(shost, reset);
Matthew Wilcox51219352007-10-02 21:55:22 -04007338
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007339 scmd_printk(KERN_INFO, scp, "SCSI host reset started...\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007340
7341 if (ASC_NARROW_BOARD(boardp)) {
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007342 ASC_DVC_VAR *asc_dvc = &boardp->dvc_var.asc_dvc_var;
Matthew Wilcox51219352007-10-02 21:55:22 -04007343
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007344 /* Reset the chip and SCSI bus. */
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007345 ASC_DBG(1, "before AscInitAsc1000Driver()\n");
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007346 status = AscInitAsc1000Driver(asc_dvc);
Matthew Wilcox51219352007-10-02 21:55:22 -04007347
Adam Buchbinder6070d812009-12-04 15:47:01 -05007348 /* Refer to ASC_IERR_* definitions for meaning of 'err_code'. */
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -03007349 if (asc_dvc->err_code || !asc_dvc->overrun_dma) {
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007350 scmd_printk(KERN_INFO, scp, "SCSI host reset error: "
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -03007351 "0x%x, status: 0x%x\n", asc_dvc->err_code,
7352 status);
Matthew Wilcox51219352007-10-02 21:55:22 -04007353 ret = FAILED;
7354 } else if (status) {
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007355 scmd_printk(KERN_INFO, scp, "SCSI host reset warning: "
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007356 "0x%x\n", status);
Matthew Wilcox51219352007-10-02 21:55:22 -04007357 } else {
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007358 scmd_printk(KERN_INFO, scp, "SCSI host reset "
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007359 "successful\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007360 }
7361
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007362 ASC_DBG(1, "after AscInitAsc1000Driver()\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007363 } else {
7364 /*
Matthew Wilcox51219352007-10-02 21:55:22 -04007365 * If the suggest reset bus flags are set, then reset the bus.
7366 * Otherwise only reset the device.
7367 */
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007368 ADV_DVC_VAR *adv_dvc = &boardp->dvc_var.adv_dvc_var;
Matthew Wilcox51219352007-10-02 21:55:22 -04007369
7370 /*
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007371 * Reset the chip and SCSI bus.
Matthew Wilcox51219352007-10-02 21:55:22 -04007372 */
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007373 ASC_DBG(1, "before AdvResetChipAndSB()\n");
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007374 switch (AdvResetChipAndSB(adv_dvc)) {
Matthew Wilcox51219352007-10-02 21:55:22 -04007375 case ASC_TRUE:
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007376 scmd_printk(KERN_INFO, scp, "SCSI host reset "
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007377 "successful\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007378 break;
7379 case ASC_FALSE:
7380 default:
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007381 scmd_printk(KERN_INFO, scp, "SCSI host reset error\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007382 ret = FAILED;
7383 break;
7384 }
Matthew Wilcoxf092d222007-10-02 21:55:34 -04007385 spin_lock_irqsave(shost->host_lock, flags);
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007386 AdvISR(adv_dvc);
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007387 spin_unlock_irqrestore(shost->host_lock, flags);
Matthew Wilcox51219352007-10-02 21:55:22 -04007388 }
Matthew Wilcox51219352007-10-02 21:55:22 -04007389
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007390 ASC_DBG(1, "ret %d\n", ret);
Matthew Wilcox51219352007-10-02 21:55:22 -04007391
7392 return ret;
7393}
7394
7395/*
7396 * advansys_biosparam()
7397 *
7398 * Translate disk drive geometry if the "BIOS greater than 1 GB"
7399 * support is enabled for a drive.
7400 *
7401 * ip (information pointer) is an int array with the following definition:
7402 * ip[0]: heads
7403 * ip[1]: sectors
7404 * ip[2]: cylinders
7405 */
7406static int
7407advansys_biosparam(struct scsi_device *sdev, struct block_device *bdev,
7408 sector_t capacity, int ip[])
7409{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04007410 struct asc_board *boardp = shost_priv(sdev->host);
Matthew Wilcox51219352007-10-02 21:55:22 -04007411
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007412 ASC_DBG(1, "begin\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007413 ASC_STATS(sdev->host, biosparam);
Matthew Wilcox51219352007-10-02 21:55:22 -04007414 if (ASC_NARROW_BOARD(boardp)) {
7415 if ((boardp->dvc_var.asc_dvc_var.dvc_cntl &
7416 ASC_CNTL_BIOS_GT_1GB) && capacity > 0x200000) {
7417 ip[0] = 255;
7418 ip[1] = 63;
7419 } else {
7420 ip[0] = 64;
7421 ip[1] = 32;
7422 }
7423 } else {
7424 if ((boardp->dvc_var.adv_dvc_var.bios_ctrl &
7425 BIOS_CTRL_EXTENDED_XLAT) && capacity > 0x200000) {
7426 ip[0] = 255;
7427 ip[1] = 63;
7428 } else {
7429 ip[0] = 64;
7430 ip[1] = 32;
7431 }
7432 }
7433 ip[2] = (unsigned long)capacity / (ip[0] * ip[1]);
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007434 ASC_DBG(1, "end\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007435 return 0;
7436}
7437
7438/*
7439 * First-level interrupt handler.
7440 *
7441 * 'dev_id' is a pointer to the interrupting adapter's Scsi_Host.
7442 */
7443static irqreturn_t advansys_interrupt(int irq, void *dev_id)
7444{
Matthew Wilcox51219352007-10-02 21:55:22 -04007445 struct Scsi_Host *shost = dev_id;
Matthew Wilcoxd2411492007-10-02 21:55:31 -04007446 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox51219352007-10-02 21:55:22 -04007447 irqreturn_t result = IRQ_NONE;
7448
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007449 ASC_DBG(2, "boardp 0x%p\n", boardp);
Matthew Wilcoxf092d222007-10-02 21:55:34 -04007450 spin_lock(shost->host_lock);
Matthew Wilcox51219352007-10-02 21:55:22 -04007451 if (ASC_NARROW_BOARD(boardp)) {
7452 if (AscIsIntPending(shost->io_port)) {
7453 result = IRQ_HANDLED;
7454 ASC_STATS(shost, interrupt);
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007455 ASC_DBG(1, "before AscISR()\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007456 AscISR(&boardp->dvc_var.asc_dvc_var);
7457 }
7458 } else {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007459 ASC_DBG(1, "before AdvISR()\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007460 if (AdvISR(&boardp->dvc_var.adv_dvc_var)) {
7461 result = IRQ_HANDLED;
7462 ASC_STATS(shost, interrupt);
7463 }
7464 }
Matthew Wilcoxf092d222007-10-02 21:55:34 -04007465 spin_unlock(shost->host_lock);
Matthew Wilcox51219352007-10-02 21:55:22 -04007466
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007467 ASC_DBG(1, "end\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007468 return result;
7469}
7470
Hannes Reinecked647c782015-04-24 13:18:26 +02007471static bool AscHostReqRiscHalt(PortAddr iop_base)
Matthew Wilcox51219352007-10-02 21:55:22 -04007472{
7473 int count = 0;
Hannes Reinecked647c782015-04-24 13:18:26 +02007474 bool sta = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04007475 uchar saved_stop_code;
7476
7477 if (AscIsChipHalted(iop_base))
Hannes Reinecked647c782015-04-24 13:18:26 +02007478 return true;
Matthew Wilcox51219352007-10-02 21:55:22 -04007479 saved_stop_code = AscReadLramByte(iop_base, ASCV_STOP_CODE_B);
7480 AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
7481 ASC_STOP_HOST_REQ_RISC_HALT | ASC_STOP_REQ_RISC_STOP);
7482 do {
7483 if (AscIsChipHalted(iop_base)) {
Hannes Reinecked647c782015-04-24 13:18:26 +02007484 sta = true;
Matthew Wilcox51219352007-10-02 21:55:22 -04007485 break;
7486 }
7487 mdelay(100);
7488 } while (count++ < 20);
7489 AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, saved_stop_code);
Hannes Reinecked647c782015-04-24 13:18:26 +02007490 return sta;
Matthew Wilcox51219352007-10-02 21:55:22 -04007491}
7492
Hannes Reinecked647c782015-04-24 13:18:26 +02007493static bool
Matthew Wilcox51219352007-10-02 21:55:22 -04007494AscSetRunChipSynRegAtID(PortAddr iop_base, uchar tid_no, uchar sdtr_data)
7495{
Hannes Reinecked647c782015-04-24 13:18:26 +02007496 bool sta = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04007497
7498 if (AscHostReqRiscHalt(iop_base)) {
7499 sta = AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
7500 AscStartChip(iop_base);
7501 }
7502 return sta;
7503}
7504
7505static void AscAsyncFix(ASC_DVC_VAR *asc_dvc, struct scsi_device *sdev)
7506{
7507 char type = sdev->type;
7508 ASC_SCSI_BIT_ID_TYPE tid_bits = 1 << sdev->id;
7509
7510 if (!(asc_dvc->bug_fix_cntl & ASC_BUG_FIX_ASYN_USE_SYN))
7511 return;
7512 if (asc_dvc->init_sdtr & tid_bits)
7513 return;
7514
7515 if ((type == TYPE_ROM) && (strncmp(sdev->vendor, "HP ", 3) == 0))
7516 asc_dvc->pci_fix_asyn_xfer_always |= tid_bits;
7517
7518 asc_dvc->pci_fix_asyn_xfer |= tid_bits;
7519 if ((type == TYPE_PROCESSOR) || (type == TYPE_SCANNER) ||
7520 (type == TYPE_ROM) || (type == TYPE_TAPE))
7521 asc_dvc->pci_fix_asyn_xfer &= ~tid_bits;
7522
7523 if (asc_dvc->pci_fix_asyn_xfer & tid_bits)
7524 AscSetRunChipSynRegAtID(asc_dvc->iop_base, sdev->id,
7525 ASYN_SDTR_DATA_FIX_PCI_REV_AB);
7526}
7527
7528static void
7529advansys_narrow_slave_configure(struct scsi_device *sdev, ASC_DVC_VAR *asc_dvc)
7530{
7531 ASC_SCSI_BIT_ID_TYPE tid_bit = 1 << sdev->id;
7532 ASC_SCSI_BIT_ID_TYPE orig_use_tagged_qng = asc_dvc->use_tagged_qng;
7533
7534 if (sdev->lun == 0) {
7535 ASC_SCSI_BIT_ID_TYPE orig_init_sdtr = asc_dvc->init_sdtr;
7536 if ((asc_dvc->cfg->sdtr_enable & tid_bit) && sdev->sdtr) {
7537 asc_dvc->init_sdtr |= tid_bit;
7538 } else {
7539 asc_dvc->init_sdtr &= ~tid_bit;
7540 }
7541
7542 if (orig_init_sdtr != asc_dvc->init_sdtr)
7543 AscAsyncFix(asc_dvc, sdev);
7544 }
7545
7546 if (sdev->tagged_supported) {
7547 if (asc_dvc->cfg->cmd_qng_enabled & tid_bit) {
7548 if (sdev->lun == 0) {
7549 asc_dvc->cfg->can_tagged_qng |= tid_bit;
7550 asc_dvc->use_tagged_qng |= tid_bit;
7551 }
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01007552 scsi_change_queue_depth(sdev,
Matthew Wilcox51219352007-10-02 21:55:22 -04007553 asc_dvc->max_dvc_qng[sdev->id]);
7554 }
7555 } else {
7556 if (sdev->lun == 0) {
7557 asc_dvc->cfg->can_tagged_qng &= ~tid_bit;
7558 asc_dvc->use_tagged_qng &= ~tid_bit;
7559 }
Matthew Wilcox51219352007-10-02 21:55:22 -04007560 }
7561
7562 if ((sdev->lun == 0) &&
7563 (orig_use_tagged_qng != asc_dvc->use_tagged_qng)) {
7564 AscWriteLramByte(asc_dvc->iop_base, ASCV_DISC_ENABLE_B,
7565 asc_dvc->cfg->disc_enable);
7566 AscWriteLramByte(asc_dvc->iop_base, ASCV_USE_TAGGED_QNG_B,
7567 asc_dvc->use_tagged_qng);
7568 AscWriteLramByte(asc_dvc->iop_base, ASCV_CAN_TAGGED_QNG_B,
7569 asc_dvc->cfg->can_tagged_qng);
7570
7571 asc_dvc->max_dvc_qng[sdev->id] =
7572 asc_dvc->cfg->max_tag_qng[sdev->id];
7573 AscWriteLramByte(asc_dvc->iop_base,
7574 (ushort)(ASCV_MAX_DVC_QNG_BEG + sdev->id),
7575 asc_dvc->max_dvc_qng[sdev->id]);
7576 }
7577}
7578
7579/*
7580 * Wide Transfers
7581 *
7582 * If the EEPROM enabled WDTR for the device and the device supports wide
7583 * bus (16 bit) transfers, then turn on the device's 'wdtr_able' bit and
7584 * write the new value to the microcode.
7585 */
7586static void
7587advansys_wide_enable_wdtr(AdvPortAddr iop_base, unsigned short tidmask)
7588{
7589 unsigned short cfg_word;
7590 AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
7591 if ((cfg_word & tidmask) != 0)
7592 return;
7593
7594 cfg_word |= tidmask;
7595 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
7596
7597 /*
7598 * Clear the microcode SDTR and WDTR negotiation done indicators for
7599 * the target to cause it to negotiate with the new setting set above.
7600 * WDTR when accepted causes the target to enter asynchronous mode, so
7601 * SDTR must be negotiated.
7602 */
7603 AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
7604 cfg_word &= ~tidmask;
7605 AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
7606 AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
7607 cfg_word &= ~tidmask;
7608 AdvWriteWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
7609}
7610
7611/*
7612 * Synchronous Transfers
7613 *
7614 * If the EEPROM enabled SDTR for the device and the device
7615 * supports synchronous transfers, then turn on the device's
7616 * 'sdtr_able' bit. Write the new value to the microcode.
7617 */
7618static void
7619advansys_wide_enable_sdtr(AdvPortAddr iop_base, unsigned short tidmask)
7620{
7621 unsigned short cfg_word;
7622 AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
7623 if ((cfg_word & tidmask) != 0)
7624 return;
7625
7626 cfg_word |= tidmask;
7627 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
7628
7629 /*
7630 * Clear the microcode "SDTR negotiation" done indicator for the
7631 * target to cause it to negotiate with the new setting set above.
7632 */
7633 AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
7634 cfg_word &= ~tidmask;
7635 AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
7636}
7637
7638/*
7639 * PPR (Parallel Protocol Request) Capable
7640 *
7641 * If the device supports DT mode, then it must be PPR capable.
7642 * The PPR message will be used in place of the SDTR and WDTR
7643 * messages to negotiate synchronous speed and offset, transfer
7644 * width, and protocol options.
7645 */
7646static void advansys_wide_enable_ppr(ADV_DVC_VAR *adv_dvc,
7647 AdvPortAddr iop_base, unsigned short tidmask)
7648{
7649 AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, adv_dvc->ppr_able);
7650 adv_dvc->ppr_able |= tidmask;
7651 AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, adv_dvc->ppr_able);
7652}
7653
7654static void
7655advansys_wide_slave_configure(struct scsi_device *sdev, ADV_DVC_VAR *adv_dvc)
7656{
7657 AdvPortAddr iop_base = adv_dvc->iop_base;
7658 unsigned short tidmask = 1 << sdev->id;
7659
7660 if (sdev->lun == 0) {
7661 /*
7662 * Handle WDTR, SDTR, and Tag Queuing. If the feature
7663 * is enabled in the EEPROM and the device supports the
7664 * feature, then enable it in the microcode.
7665 */
7666
7667 if ((adv_dvc->wdtr_able & tidmask) && sdev->wdtr)
7668 advansys_wide_enable_wdtr(iop_base, tidmask);
7669 if ((adv_dvc->sdtr_able & tidmask) && sdev->sdtr)
7670 advansys_wide_enable_sdtr(iop_base, tidmask);
7671 if (adv_dvc->chip_type == ADV_CHIP_ASC38C1600 && sdev->ppr)
7672 advansys_wide_enable_ppr(adv_dvc, iop_base, tidmask);
7673
7674 /*
7675 * Tag Queuing is disabled for the BIOS which runs in polled
7676 * mode and would see no benefit from Tag Queuing. Also by
7677 * disabling Tag Queuing in the BIOS devices with Tag Queuing
7678 * bugs will at least work with the BIOS.
7679 */
7680 if ((adv_dvc->tagqng_able & tidmask) &&
7681 sdev->tagged_supported) {
7682 unsigned short cfg_word;
7683 AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, cfg_word);
7684 cfg_word |= tidmask;
7685 AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
7686 cfg_word);
7687 AdvWriteByteLram(iop_base,
7688 ASC_MC_NUMBER_OF_MAX_CMD + sdev->id,
7689 adv_dvc->max_dvc_qng);
7690 }
7691 }
7692
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01007693 if ((adv_dvc->tagqng_able & tidmask) && sdev->tagged_supported)
7694 scsi_change_queue_depth(sdev, adv_dvc->max_dvc_qng);
Matthew Wilcox51219352007-10-02 21:55:22 -04007695}
7696
7697/*
7698 * Set the number of commands to queue per device for the
7699 * specified host adapter.
7700 */
7701static int advansys_slave_configure(struct scsi_device *sdev)
7702{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04007703 struct asc_board *boardp = shost_priv(sdev->host);
Matthew Wilcox51219352007-10-02 21:55:22 -04007704
Matthew Wilcox51219352007-10-02 21:55:22 -04007705 if (ASC_NARROW_BOARD(boardp))
7706 advansys_narrow_slave_configure(sdev,
7707 &boardp->dvc_var.asc_dvc_var);
7708 else
7709 advansys_wide_slave_configure(sdev,
7710 &boardp->dvc_var.adv_dvc_var);
7711
7712 return 0;
7713}
7714
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04007715static __le32 advansys_get_sense_buffer_dma(struct scsi_cmnd *scp)
7716{
7717 struct asc_board *board = shost_priv(scp->device->host);
7718 scp->SCp.dma_handle = dma_map_single(board->dev, scp->sense_buffer,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09007719 SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04007720 dma_cache_sync(board->dev, scp->sense_buffer,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09007721 SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04007722 return cpu_to_le32(scp->SCp.dma_handle);
7723}
7724
Matthew Wilcoxd2411492007-10-02 21:55:31 -04007725static int asc_build_req(struct asc_board *boardp, struct scsi_cmnd *scp,
Matthew Wilcox05848b62007-10-02 21:55:25 -04007726 struct asc_scsi_q *asc_scsi_q)
Matthew Wilcox51219352007-10-02 21:55:22 -04007727{
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04007728 struct asc_dvc_var *asc_dvc = &boardp->dvc_var.asc_dvc_var;
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007729 int use_sg;
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007730 u32 srb_tag;
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007731
Matthew Wilcox05848b62007-10-02 21:55:25 -04007732 memset(asc_scsi_q, 0, sizeof(*asc_scsi_q));
Matthew Wilcox51219352007-10-02 21:55:22 -04007733
7734 /*
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007735 * Set the srb_tag to the command tag + 1, as
7736 * srb_tag '0' is used internally by the chip.
Matthew Wilcox51219352007-10-02 21:55:22 -04007737 */
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007738 srb_tag = scp->request->tag + 1;
7739 asc_scsi_q->q2.srb_tag = srb_tag;
Matthew Wilcox51219352007-10-02 21:55:22 -04007740
7741 /*
7742 * Build the ASC_SCSI_Q request.
7743 */
Matthew Wilcox05848b62007-10-02 21:55:25 -04007744 asc_scsi_q->cdbptr = &scp->cmnd[0];
7745 asc_scsi_q->q2.cdb_len = scp->cmd_len;
7746 asc_scsi_q->q1.target_id = ASC_TID_TO_TARGET_ID(scp->device->id);
7747 asc_scsi_q->q1.target_lun = scp->device->lun;
7748 asc_scsi_q->q2.target_ix =
Matthew Wilcox51219352007-10-02 21:55:22 -04007749 ASC_TIDLUN_TO_IX(scp->device->id, scp->device->lun);
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04007750 asc_scsi_q->q1.sense_addr = advansys_get_sense_buffer_dma(scp);
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09007751 asc_scsi_q->q1.sense_len = SCSI_SENSE_BUFFERSIZE;
Matthew Wilcox51219352007-10-02 21:55:22 -04007752
7753 /*
7754 * If there are any outstanding requests for the current target,
7755 * then every 255th request send an ORDERED request. This heuristic
7756 * tries to retain the benefit of request sorting while preventing
7757 * request starvation. 255 is the max number of tags or pending commands
7758 * a device may have outstanding.
7759 *
7760 * The request count is incremented below for every successfully
7761 * started request.
7762 *
7763 */
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04007764 if ((asc_dvc->cur_dvc_qng[scp->device->id] > 0) &&
Matthew Wilcox51219352007-10-02 21:55:22 -04007765 (boardp->reqcnt[scp->device->id] % 255) == 0) {
Christoph Hellwig68d81f42014-11-24 07:07:25 -08007766 asc_scsi_q->q2.tag_code = ORDERED_QUEUE_TAG;
Matthew Wilcox51219352007-10-02 21:55:22 -04007767 } else {
Christoph Hellwig68d81f42014-11-24 07:07:25 -08007768 asc_scsi_q->q2.tag_code = SIMPLE_QUEUE_TAG;
Matthew Wilcox51219352007-10-02 21:55:22 -04007769 }
7770
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007771 /* Build ASC_SCSI_Q */
7772 use_sg = scsi_dma_map(scp);
7773 if (use_sg != 0) {
Matthew Wilcox51219352007-10-02 21:55:22 -04007774 int sgcnt;
Matthew Wilcox51219352007-10-02 21:55:22 -04007775 struct scatterlist *slp;
Matthew Wilcox05848b62007-10-02 21:55:25 -04007776 struct asc_sg_head *asc_sg_head;
Matthew Wilcox51219352007-10-02 21:55:22 -04007777
Matthew Wilcox51219352007-10-02 21:55:22 -04007778 if (use_sg > scp->device->host->sg_tablesize) {
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04007779 scmd_printk(KERN_ERR, scp, "use_sg %d > "
7780 "sg_tablesize %d\n", use_sg,
7781 scp->device->host->sg_tablesize);
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007782 scsi_dma_unmap(scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04007783 scp->result = HOST_BYTE(DID_ERROR);
7784 return ASC_ERROR;
7785 }
7786
Matthew Wilcox05848b62007-10-02 21:55:25 -04007787 asc_sg_head = kzalloc(sizeof(asc_scsi_q->sg_head) +
7788 use_sg * sizeof(struct asc_sg_list), GFP_ATOMIC);
7789 if (!asc_sg_head) {
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007790 scsi_dma_unmap(scp);
Matthew Wilcox05848b62007-10-02 21:55:25 -04007791 scp->result = HOST_BYTE(DID_SOFT_ERROR);
7792 return ASC_ERROR;
7793 }
Matthew Wilcox51219352007-10-02 21:55:22 -04007794
Matthew Wilcox05848b62007-10-02 21:55:25 -04007795 asc_scsi_q->q1.cntl |= QC_SG_HEAD;
7796 asc_scsi_q->sg_head = asc_sg_head;
7797 asc_scsi_q->q1.data_cnt = 0;
7798 asc_scsi_q->q1.data_addr = 0;
Matthew Wilcox51219352007-10-02 21:55:22 -04007799 /* This is a byte value, otherwise it would need to be swapped. */
Matthew Wilcox05848b62007-10-02 21:55:25 -04007800 asc_sg_head->entry_cnt = asc_scsi_q->q1.sg_queue_cnt = use_sg;
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007801 ASC_STATS_ADD(scp->device->host, xfer_elem,
Matthew Wilcox05848b62007-10-02 21:55:25 -04007802 asc_sg_head->entry_cnt);
Matthew Wilcox51219352007-10-02 21:55:22 -04007803
7804 /*
7805 * Convert scatter-gather list into ASC_SG_HEAD list.
7806 */
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007807 scsi_for_each_sg(scp, slp, use_sg, sgcnt) {
Matthew Wilcox05848b62007-10-02 21:55:25 -04007808 asc_sg_head->sg_list[sgcnt].addr =
Matthew Wilcox51219352007-10-02 21:55:22 -04007809 cpu_to_le32(sg_dma_address(slp));
Matthew Wilcox05848b62007-10-02 21:55:25 -04007810 asc_sg_head->sg_list[sgcnt].bytes =
Matthew Wilcox51219352007-10-02 21:55:22 -04007811 cpu_to_le32(sg_dma_len(slp));
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007812 ASC_STATS_ADD(scp->device->host, xfer_sect,
7813 DIV_ROUND_UP(sg_dma_len(slp), 512));
Matthew Wilcox51219352007-10-02 21:55:22 -04007814 }
7815 }
7816
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007817 ASC_STATS(scp->device->host, xfer_cnt);
7818
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007819 ASC_DBG_PRT_ASC_SCSI_Q(2, asc_scsi_q);
Matthew Wilcox51219352007-10-02 21:55:22 -04007820 ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
7821
7822 return ASC_NOERROR;
7823}
7824
7825/*
7826 * Build scatter-gather list for Adv Library (Wide Board).
7827 *
7828 * Additional ADV_SG_BLOCK structures will need to be allocated
7829 * if the total number of scatter-gather elements exceeds
7830 * NO_OF_SG_PER_BLOCK (15). The ADV_SG_BLOCK structures are
7831 * assumed to be physically contiguous.
7832 *
7833 * Return:
7834 * ADV_SUCCESS(1) - SG List successfully created
7835 * ADV_ERROR(-1) - SG List creation failed
7836 */
7837static int
Hannes Reinecke4b47e462015-04-24 13:18:24 +02007838adv_get_sglist(struct asc_board *boardp, adv_req_t *reqp,
7839 ADV_SCSI_REQ_Q *scsiqp, struct scsi_cmnd *scp, int use_sg)
Matthew Wilcox51219352007-10-02 21:55:22 -04007840{
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007841 adv_sgblk_t *sgblkp, *prev_sgblkp;
Matthew Wilcox51219352007-10-02 21:55:22 -04007842 struct scatterlist *slp;
7843 int sg_elem_cnt;
7844 ADV_SG_BLOCK *sg_block, *prev_sg_block;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007845 dma_addr_t sgblk_paddr;
Matthew Wilcox51219352007-10-02 21:55:22 -04007846 int i;
7847
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007848 slp = scsi_sglist(scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04007849 sg_elem_cnt = use_sg;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007850 prev_sgblkp = NULL;
Matthew Wilcox51219352007-10-02 21:55:22 -04007851 prev_sg_block = NULL;
7852 reqp->sgblkp = NULL;
7853
7854 for (;;) {
7855 /*
7856 * Allocate a 'adv_sgblk_t' structure from the board free
7857 * list. One 'adv_sgblk_t' structure holds NO_OF_SG_PER_BLOCK
7858 * (15) scatter-gather elements.
7859 */
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007860 sgblkp = dma_pool_alloc(boardp->adv_sgblk_pool, GFP_ATOMIC,
7861 &sgblk_paddr);
7862 if (!sgblkp) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007863 ASC_DBG(1, "no free adv_sgblk_t\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007864 ASC_STATS(scp->device->host, adv_build_nosg);
7865
7866 /*
7867 * Allocation failed. Free 'adv_sgblk_t' structures
7868 * already allocated for the request.
7869 */
7870 while ((sgblkp = reqp->sgblkp) != NULL) {
7871 /* Remove 'sgblkp' from the request list. */
7872 reqp->sgblkp = sgblkp->next_sgblkp;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007873 sgblkp->next_sgblkp = NULL;
7874 dma_pool_free(boardp->adv_sgblk_pool, sgblkp,
7875 sgblkp->sg_addr);
Matthew Wilcox51219352007-10-02 21:55:22 -04007876 }
7877 return ASC_BUSY;
7878 }
Matthew Wilcox51219352007-10-02 21:55:22 -04007879 /* Complete 'adv_sgblk_t' board allocation. */
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007880 sgblkp->sg_addr = sgblk_paddr;
Matthew Wilcox51219352007-10-02 21:55:22 -04007881 sgblkp->next_sgblkp = NULL;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007882 sg_block = &sgblkp->sg_block;
Matthew Wilcox51219352007-10-02 21:55:22 -04007883
7884 /*
7885 * Check if this is the first 'adv_sgblk_t' for the
7886 * request.
7887 */
7888 if (reqp->sgblkp == NULL) {
7889 /* Request's first scatter-gather block. */
7890 reqp->sgblkp = sgblkp;
7891
7892 /*
7893 * Set ADV_SCSI_REQ_T ADV_SG_BLOCK virtual and physical
7894 * address pointers.
7895 */
7896 scsiqp->sg_list_ptr = sg_block;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007897 scsiqp->sg_real_addr = cpu_to_le32(sgblk_paddr);
Matthew Wilcox51219352007-10-02 21:55:22 -04007898 } else {
7899 /* Request's second or later scatter-gather block. */
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007900 prev_sgblkp->next_sgblkp = sgblkp;
Matthew Wilcox51219352007-10-02 21:55:22 -04007901
7902 /*
7903 * Point the previous ADV_SG_BLOCK structure to
7904 * the newly allocated ADV_SG_BLOCK structure.
7905 */
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007906 prev_sg_block->sg_ptr = cpu_to_le32(sgblk_paddr);
Matthew Wilcox51219352007-10-02 21:55:22 -04007907 }
7908
7909 for (i = 0; i < NO_OF_SG_PER_BLOCK; i++) {
7910 sg_block->sg_list[i].sg_addr =
7911 cpu_to_le32(sg_dma_address(slp));
7912 sg_block->sg_list[i].sg_count =
7913 cpu_to_le32(sg_dma_len(slp));
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007914 ASC_STATS_ADD(scp->device->host, xfer_sect,
7915 DIV_ROUND_UP(sg_dma_len(slp), 512));
Matthew Wilcox51219352007-10-02 21:55:22 -04007916
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007917 if (--sg_elem_cnt == 0) {
7918 /*
7919 * Last ADV_SG_BLOCK and scatter-gather entry.
7920 */
Matthew Wilcox51219352007-10-02 21:55:22 -04007921 sg_block->sg_cnt = i + 1;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007922 sg_block->sg_ptr = 0L; /* Last ADV_SG_BLOCK in list. */
Matthew Wilcox51219352007-10-02 21:55:22 -04007923 return ADV_SUCCESS;
7924 }
7925 slp++;
7926 }
7927 sg_block->sg_cnt = NO_OF_SG_PER_BLOCK;
7928 prev_sg_block = sg_block;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007929 prev_sgblkp = sgblkp;
Matthew Wilcox51219352007-10-02 21:55:22 -04007930 }
7931}
7932
7933/*
7934 * Build a request structure for the Adv Library (Wide Board).
7935 *
7936 * If an adv_req_t can not be allocated to issue the request,
7937 * then return ASC_BUSY. If an error occurs, then return ASC_ERROR.
7938 *
Hannes Reinecke9fef6ba2015-04-24 13:18:33 +02007939 * Multi-byte fields in the ADV_SCSI_REQ_Q that are used by the
Matthew Wilcox51219352007-10-02 21:55:22 -04007940 * microcode for DMA addresses or math operations are byte swapped
7941 * to little-endian order.
7942 */
7943static int
Matthew Wilcoxd2411492007-10-02 21:55:31 -04007944adv_build_req(struct asc_board *boardp, struct scsi_cmnd *scp,
Hannes Reinecke4b47e462015-04-24 13:18:24 +02007945 adv_req_t **adv_reqpp)
Matthew Wilcox51219352007-10-02 21:55:22 -04007946{
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007947 u32 srb_tag = scp->request->tag;
Matthew Wilcox51219352007-10-02 21:55:22 -04007948 adv_req_t *reqp;
7949 ADV_SCSI_REQ_Q *scsiqp;
Matthew Wilcox51219352007-10-02 21:55:22 -04007950 int ret;
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007951 int use_sg;
Hannes Reinecke811ddc02015-04-24 13:18:22 +02007952 dma_addr_t sense_addr;
Matthew Wilcox51219352007-10-02 21:55:22 -04007953
7954 /*
7955 * Allocate an adv_req_t structure from the board to execute
7956 * the command.
7957 */
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007958 reqp = &boardp->adv_reqp[srb_tag];
7959 if (reqp->cmndp && reqp->cmndp != scp ) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007960 ASC_DBG(1, "no free adv_req_t\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007961 ASC_STATS(scp->device->host, adv_build_noreq);
7962 return ASC_BUSY;
Matthew Wilcox51219352007-10-02 21:55:22 -04007963 }
7964
Hannes Reinecke4b47e462015-04-24 13:18:24 +02007965 reqp->req_addr = boardp->adv_reqp_addr + (srb_tag * sizeof(adv_req_t));
7966
7967 scsiqp = &reqp->scsi_req_q;
Matthew Wilcox51219352007-10-02 21:55:22 -04007968
7969 /*
7970 * Initialize the structure.
7971 */
7972 scsiqp->cntl = scsiqp->scsi_cntl = scsiqp->done_status = 0;
7973
7974 /*
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007975 * Set the srb_tag to the command tag.
Matthew Wilcox51219352007-10-02 21:55:22 -04007976 */
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007977 scsiqp->srb_tag = srb_tag;
Matthew Wilcox51219352007-10-02 21:55:22 -04007978
7979 /*
Hannes Reinecke4b47e462015-04-24 13:18:24 +02007980 * Set 'host_scribble' to point to the adv_req_t structure.
Matthew Wilcox51219352007-10-02 21:55:22 -04007981 */
7982 reqp->cmndp = scp;
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007983 scp->host_scribble = (void *)reqp;
Matthew Wilcox51219352007-10-02 21:55:22 -04007984
7985 /*
7986 * Build the ADV_SCSI_REQ_Q request.
7987 */
7988
7989 /* Set CDB length and copy it to the request structure. */
7990 scsiqp->cdb_len = scp->cmd_len;
7991 /* Copy first 12 CDB bytes to cdb[]. */
Hannes Reinecke811ddc02015-04-24 13:18:22 +02007992 memcpy(scsiqp->cdb, scp->cmnd, scp->cmd_len < 12 ? scp->cmd_len : 12);
Matthew Wilcox51219352007-10-02 21:55:22 -04007993 /* Copy last 4 CDB bytes, if present, to cdb16[]. */
Hannes Reinecke811ddc02015-04-24 13:18:22 +02007994 if (scp->cmd_len > 12) {
7995 int cdb16_len = scp->cmd_len - 12;
7996
7997 memcpy(scsiqp->cdb16, &scp->cmnd[12], cdb16_len);
Matthew Wilcox51219352007-10-02 21:55:22 -04007998 }
7999
8000 scsiqp->target_id = scp->device->id;
8001 scsiqp->target_lun = scp->device->lun;
8002
Hannes Reinecke811ddc02015-04-24 13:18:22 +02008003 sense_addr = dma_map_single(boardp->dev, scp->sense_buffer,
8004 SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
8005 scsiqp->sense_addr = cpu_to_le32(sense_addr);
8006 scsiqp->sense_len = cpu_to_le32(SCSI_SENSE_BUFFERSIZE);
Matthew Wilcox51219352007-10-02 21:55:22 -04008007
Matthew Wilcox52c334e2007-10-02 21:55:39 -04008008 /* Build ADV_SCSI_REQ_Q */
Matthew Wilcox51219352007-10-02 21:55:22 -04008009
Matthew Wilcox52c334e2007-10-02 21:55:39 -04008010 use_sg = scsi_dma_map(scp);
8011 if (use_sg == 0) {
8012 /* Zero-length transfer */
Matthew Wilcox51219352007-10-02 21:55:22 -04008013 reqp->sgblkp = NULL;
Matthew Wilcox52c334e2007-10-02 21:55:39 -04008014 scsiqp->data_cnt = 0;
Matthew Wilcox52c334e2007-10-02 21:55:39 -04008015
8016 scsiqp->data_addr = 0;
Matthew Wilcox51219352007-10-02 21:55:22 -04008017 scsiqp->sg_list_ptr = NULL;
8018 scsiqp->sg_real_addr = 0;
Matthew Wilcox51219352007-10-02 21:55:22 -04008019 } else {
Matthew Wilcox51219352007-10-02 21:55:22 -04008020 if (use_sg > ADV_MAX_SG_LIST) {
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04008021 scmd_printk(KERN_ERR, scp, "use_sg %d > "
8022 "ADV_MAX_SG_LIST %d\n", use_sg,
Matthew Wilcox51219352007-10-02 21:55:22 -04008023 scp->device->host->sg_tablesize);
Matthew Wilcox52c334e2007-10-02 21:55:39 -04008024 scsi_dma_unmap(scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04008025 scp->result = HOST_BYTE(DID_ERROR);
Hannes Reinecke9c17c622015-04-24 13:18:21 +02008026 reqp->cmndp = NULL;
8027 scp->host_scribble = NULL;
Matthew Wilcox51219352007-10-02 21:55:22 -04008028
8029 return ASC_ERROR;
8030 }
8031
Matthew Wilcox52c334e2007-10-02 21:55:39 -04008032 scsiqp->data_cnt = cpu_to_le32(scsi_bufflen(scp));
8033
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008034 ret = adv_get_sglist(boardp, reqp, scsiqp, scp, use_sg);
Matthew Wilcox51219352007-10-02 21:55:22 -04008035 if (ret != ADV_SUCCESS) {
Hannes Reinecke9c17c622015-04-24 13:18:21 +02008036 scsi_dma_unmap(scp);
8037 scp->result = HOST_BYTE(DID_ERROR);
8038 reqp->cmndp = NULL;
8039 scp->host_scribble = NULL;
Matthew Wilcox51219352007-10-02 21:55:22 -04008040
8041 return ret;
8042 }
8043
Matthew Wilcox52c334e2007-10-02 21:55:39 -04008044 ASC_STATS_ADD(scp->device->host, xfer_elem, use_sg);
Matthew Wilcox51219352007-10-02 21:55:22 -04008045 }
8046
Matthew Wilcox52c334e2007-10-02 21:55:39 -04008047 ASC_STATS(scp->device->host, xfer_cnt);
8048
Matthew Wilcox51219352007-10-02 21:55:22 -04008049 ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
8050 ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
8051
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008052 *adv_reqpp = reqp;
Matthew Wilcox51219352007-10-02 21:55:22 -04008053
8054 return ASC_NOERROR;
8055}
8056
8057static int AscSgListToQueue(int sg_list)
8058{
8059 int n_sg_list_qs;
8060
8061 n_sg_list_qs = ((sg_list - 1) / ASC_SG_LIST_PER_Q);
8062 if (((sg_list - 1) % ASC_SG_LIST_PER_Q) != 0)
8063 n_sg_list_qs++;
8064 return n_sg_list_qs + 1;
8065}
8066
8067static uint
8068AscGetNumOfFreeQueue(ASC_DVC_VAR *asc_dvc, uchar target_ix, uchar n_qs)
8069{
8070 uint cur_used_qs;
8071 uint cur_free_qs;
8072 ASC_SCSI_BIT_ID_TYPE target_id;
8073 uchar tid_no;
8074
8075 target_id = ASC_TIX_TO_TARGET_ID(target_ix);
8076 tid_no = ASC_TIX_TO_TID(target_ix);
8077 if ((asc_dvc->unit_not_ready & target_id) ||
8078 (asc_dvc->queue_full_or_busy & target_id)) {
8079 return 0;
8080 }
8081 if (n_qs == 1) {
8082 cur_used_qs = (uint) asc_dvc->cur_total_qng +
8083 (uint) asc_dvc->last_q_shortage + (uint) ASC_MIN_FREE_Q;
8084 } else {
8085 cur_used_qs = (uint) asc_dvc->cur_total_qng +
8086 (uint) ASC_MIN_FREE_Q;
8087 }
8088 if ((uint) (cur_used_qs + n_qs) <= (uint) asc_dvc->max_total_qng) {
8089 cur_free_qs = (uint) asc_dvc->max_total_qng - cur_used_qs;
8090 if (asc_dvc->cur_dvc_qng[tid_no] >=
8091 asc_dvc->max_dvc_qng[tid_no]) {
8092 return 0;
8093 }
8094 return cur_free_qs;
8095 }
8096 if (n_qs > 1) {
8097 if ((n_qs > asc_dvc->last_q_shortage)
8098 && (n_qs <= (asc_dvc->max_total_qng - ASC_MIN_FREE_Q))) {
8099 asc_dvc->last_q_shortage = n_qs;
8100 }
8101 }
8102 return 0;
8103}
8104
8105static uchar AscAllocFreeQueue(PortAddr iop_base, uchar free_q_head)
8106{
8107 ushort q_addr;
8108 uchar next_qp;
8109 uchar q_status;
8110
8111 q_addr = ASC_QNO_TO_QADDR(free_q_head);
8112 q_status = (uchar)AscReadLramByte(iop_base,
8113 (ushort)(q_addr +
8114 ASC_SCSIQ_B_STATUS));
8115 next_qp = AscReadLramByte(iop_base, (ushort)(q_addr + ASC_SCSIQ_B_FWD));
8116 if (((q_status & QS_READY) == 0) && (next_qp != ASC_QLINK_END))
8117 return next_qp;
8118 return ASC_QLINK_END;
8119}
8120
8121static uchar
8122AscAllocMultipleFreeQueue(PortAddr iop_base, uchar free_q_head, uchar n_free_q)
8123{
8124 uchar i;
8125
8126 for (i = 0; i < n_free_q; i++) {
8127 free_q_head = AscAllocFreeQueue(iop_base, free_q_head);
8128 if (free_q_head == ASC_QLINK_END)
8129 break;
8130 }
8131 return free_q_head;
8132}
8133
8134/*
8135 * void
8136 * DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
8137 *
8138 * Calling/Exit State:
8139 * none
8140 *
8141 * Description:
8142 * Output an ASC_SCSI_Q structure to the chip
8143 */
8144static void
8145DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
8146{
8147 int i;
8148
8149 ASC_DBG_PRT_HEX(2, "DvcPutScsiQ", outbuf, 2 * words);
8150 AscSetChipLramAddr(iop_base, s_addr);
8151 for (i = 0; i < 2 * words; i += 2) {
8152 if (i == 4 || i == 20) {
8153 continue;
8154 }
8155 outpw(iop_base + IOP_RAM_DATA,
8156 ((ushort)outbuf[i + 1] << 8) | outbuf[i]);
8157 }
8158}
8159
8160static int AscPutReadyQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar q_no)
8161{
8162 ushort q_addr;
8163 uchar tid_no;
8164 uchar sdtr_data;
8165 uchar syn_period_ix;
8166 uchar syn_offset;
8167 PortAddr iop_base;
8168
8169 iop_base = asc_dvc->iop_base;
8170 if (((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) &&
8171 ((asc_dvc->sdtr_done & scsiq->q1.target_id) == 0)) {
8172 tid_no = ASC_TIX_TO_TID(scsiq->q2.target_ix);
8173 sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
8174 syn_period_ix =
8175 (sdtr_data >> 4) & (asc_dvc->max_sdtr_index - 1);
8176 syn_offset = sdtr_data & ASC_SYN_MAX_OFFSET;
8177 AscMsgOutSDTR(asc_dvc,
8178 asc_dvc->sdtr_period_tbl[syn_period_ix],
8179 syn_offset);
8180 scsiq->q1.cntl |= QC_MSG_OUT;
8181 }
8182 q_addr = ASC_QNO_TO_QADDR(q_no);
8183 if ((scsiq->q1.target_id & asc_dvc->use_tagged_qng) == 0) {
Christoph Hellwig68d81f42014-11-24 07:07:25 -08008184 scsiq->q2.tag_code &= ~SIMPLE_QUEUE_TAG;
Matthew Wilcox51219352007-10-02 21:55:22 -04008185 }
8186 scsiq->q1.status = QS_FREE;
8187 AscMemWordCopyPtrToLram(iop_base,
8188 q_addr + ASC_SCSIQ_CDB_BEG,
8189 (uchar *)scsiq->cdbptr, scsiq->q2.cdb_len >> 1);
8190
8191 DvcPutScsiQ(iop_base,
8192 q_addr + ASC_SCSIQ_CPY_BEG,
8193 (uchar *)&scsiq->q1.cntl,
8194 ((sizeof(ASC_SCSIQ_1) + sizeof(ASC_SCSIQ_2)) / 2) - 1);
8195 AscWriteLramWord(iop_base,
8196 (ushort)(q_addr + (ushort)ASC_SCSIQ_B_STATUS),
8197 (ushort)(((ushort)scsiq->q1.
8198 q_no << 8) | (ushort)QS_READY));
8199 return 1;
8200}
8201
8202static int
8203AscPutReadySgListQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar q_no)
8204{
8205 int sta;
8206 int i;
8207 ASC_SG_HEAD *sg_head;
8208 ASC_SG_LIST_Q scsi_sg_q;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008209 __le32 saved_data_addr;
8210 __le32 saved_data_cnt;
Matthew Wilcox51219352007-10-02 21:55:22 -04008211 PortAddr iop_base;
8212 ushort sg_list_dwords;
8213 ushort sg_index;
8214 ushort sg_entry_cnt;
8215 ushort q_addr;
8216 uchar next_qp;
8217
8218 iop_base = asc_dvc->iop_base;
8219 sg_head = scsiq->sg_head;
8220 saved_data_addr = scsiq->q1.data_addr;
8221 saved_data_cnt = scsiq->q1.data_cnt;
Hannes Reinecke37f64602015-04-24 13:18:32 +02008222 scsiq->q1.data_addr = cpu_to_le32(sg_head->sg_list[0].addr);
8223 scsiq->q1.data_cnt = cpu_to_le32(sg_head->sg_list[0].bytes);
Matthew Wilcox51219352007-10-02 21:55:22 -04008224#if CC_VERY_LONG_SG_LIST
8225 /*
8226 * If sg_head->entry_cnt is greater than ASC_MAX_SG_LIST
8227 * then not all SG elements will fit in the allocated queues.
8228 * The rest of the SG elements will be copied when the RISC
8229 * completes the SG elements that fit and halts.
8230 */
8231 if (sg_head->entry_cnt > ASC_MAX_SG_LIST) {
8232 /*
8233 * Set sg_entry_cnt to be the number of SG elements that
8234 * will fit in the allocated SG queues. It is minus 1, because
8235 * the first SG element is handled above. ASC_MAX_SG_LIST is
8236 * already inflated by 1 to account for this. For example it
8237 * may be 50 which is 1 + 7 queues * 7 SG elements.
8238 */
8239 sg_entry_cnt = ASC_MAX_SG_LIST - 1;
8240
8241 /*
8242 * Keep track of remaining number of SG elements that will
8243 * need to be handled from a_isr.c.
8244 */
8245 scsiq->remain_sg_entry_cnt =
8246 sg_head->entry_cnt - ASC_MAX_SG_LIST;
8247 } else {
8248#endif /* CC_VERY_LONG_SG_LIST */
8249 /*
8250 * Set sg_entry_cnt to be the number of SG elements that
8251 * will fit in the allocated SG queues. It is minus 1, because
8252 * the first SG element is handled above.
8253 */
8254 sg_entry_cnt = sg_head->entry_cnt - 1;
8255#if CC_VERY_LONG_SG_LIST
8256 }
8257#endif /* CC_VERY_LONG_SG_LIST */
8258 if (sg_entry_cnt != 0) {
8259 scsiq->q1.cntl |= QC_SG_HEAD;
8260 q_addr = ASC_QNO_TO_QADDR(q_no);
8261 sg_index = 1;
8262 scsiq->q1.sg_queue_cnt = sg_head->queue_cnt;
8263 scsi_sg_q.sg_head_qp = q_no;
8264 scsi_sg_q.cntl = QCSG_SG_XFER_LIST;
8265 for (i = 0; i < sg_head->queue_cnt; i++) {
8266 scsi_sg_q.seq_no = i + 1;
8267 if (sg_entry_cnt > ASC_SG_LIST_PER_Q) {
8268 sg_list_dwords = (uchar)(ASC_SG_LIST_PER_Q * 2);
8269 sg_entry_cnt -= ASC_SG_LIST_PER_Q;
8270 if (i == 0) {
8271 scsi_sg_q.sg_list_cnt =
8272 ASC_SG_LIST_PER_Q;
8273 scsi_sg_q.sg_cur_list_cnt =
8274 ASC_SG_LIST_PER_Q;
8275 } else {
8276 scsi_sg_q.sg_list_cnt =
8277 ASC_SG_LIST_PER_Q - 1;
8278 scsi_sg_q.sg_cur_list_cnt =
8279 ASC_SG_LIST_PER_Q - 1;
8280 }
8281 } else {
8282#if CC_VERY_LONG_SG_LIST
8283 /*
8284 * This is the last SG queue in the list of
8285 * allocated SG queues. If there are more
8286 * SG elements than will fit in the allocated
8287 * queues, then set the QCSG_SG_XFER_MORE flag.
8288 */
8289 if (sg_head->entry_cnt > ASC_MAX_SG_LIST) {
8290 scsi_sg_q.cntl |= QCSG_SG_XFER_MORE;
8291 } else {
8292#endif /* CC_VERY_LONG_SG_LIST */
8293 scsi_sg_q.cntl |= QCSG_SG_XFER_END;
8294#if CC_VERY_LONG_SG_LIST
8295 }
8296#endif /* CC_VERY_LONG_SG_LIST */
8297 sg_list_dwords = sg_entry_cnt << 1;
8298 if (i == 0) {
8299 scsi_sg_q.sg_list_cnt = sg_entry_cnt;
8300 scsi_sg_q.sg_cur_list_cnt =
8301 sg_entry_cnt;
8302 } else {
8303 scsi_sg_q.sg_list_cnt =
8304 sg_entry_cnt - 1;
8305 scsi_sg_q.sg_cur_list_cnt =
8306 sg_entry_cnt - 1;
8307 }
8308 sg_entry_cnt = 0;
8309 }
8310 next_qp = AscReadLramByte(iop_base,
8311 (ushort)(q_addr +
8312 ASC_SCSIQ_B_FWD));
8313 scsi_sg_q.q_no = next_qp;
8314 q_addr = ASC_QNO_TO_QADDR(next_qp);
8315 AscMemWordCopyPtrToLram(iop_base,
8316 q_addr + ASC_SCSIQ_SGHD_CPY_BEG,
8317 (uchar *)&scsi_sg_q,
8318 sizeof(ASC_SG_LIST_Q) >> 1);
8319 AscMemDWordCopyPtrToLram(iop_base,
8320 q_addr + ASC_SGQ_LIST_BEG,
8321 (uchar *)&sg_head->
8322 sg_list[sg_index],
8323 sg_list_dwords);
8324 sg_index += ASC_SG_LIST_PER_Q;
8325 scsiq->next_sg_index = sg_index;
8326 }
8327 } else {
8328 scsiq->q1.cntl &= ~QC_SG_HEAD;
8329 }
8330 sta = AscPutReadyQueue(asc_dvc, scsiq, q_no);
8331 scsiq->q1.data_addr = saved_data_addr;
8332 scsiq->q1.data_cnt = saved_data_cnt;
8333 return (sta);
8334}
8335
8336static int
8337AscSendScsiQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar n_q_required)
8338{
8339 PortAddr iop_base;
8340 uchar free_q_head;
8341 uchar next_qp;
8342 uchar tid_no;
8343 uchar target_ix;
8344 int sta;
8345
8346 iop_base = asc_dvc->iop_base;
8347 target_ix = scsiq->q2.target_ix;
8348 tid_no = ASC_TIX_TO_TID(target_ix);
8349 sta = 0;
8350 free_q_head = (uchar)AscGetVarFreeQHead(iop_base);
8351 if (n_q_required > 1) {
8352 next_qp = AscAllocMultipleFreeQueue(iop_base, free_q_head,
8353 (uchar)n_q_required);
8354 if (next_qp != ASC_QLINK_END) {
8355 asc_dvc->last_q_shortage = 0;
8356 scsiq->sg_head->queue_cnt = n_q_required - 1;
8357 scsiq->q1.q_no = free_q_head;
8358 sta = AscPutReadySgListQueue(asc_dvc, scsiq,
8359 free_q_head);
8360 }
8361 } else if (n_q_required == 1) {
8362 next_qp = AscAllocFreeQueue(iop_base, free_q_head);
8363 if (next_qp != ASC_QLINK_END) {
8364 scsiq->q1.q_no = free_q_head;
8365 sta = AscPutReadyQueue(asc_dvc, scsiq, free_q_head);
8366 }
8367 }
8368 if (sta == 1) {
8369 AscPutVarFreeQHead(iop_base, next_qp);
8370 asc_dvc->cur_total_qng += n_q_required;
8371 asc_dvc->cur_dvc_qng[tid_no]++;
8372 }
8373 return sta;
8374}
8375
8376#define ASC_SYN_OFFSET_ONE_DISABLE_LIST 16
8377static uchar _syn_offset_one_disable_cmd[ASC_SYN_OFFSET_ONE_DISABLE_LIST] = {
8378 INQUIRY,
8379 REQUEST_SENSE,
8380 READ_CAPACITY,
8381 READ_TOC,
8382 MODE_SELECT,
8383 MODE_SENSE,
8384 MODE_SELECT_10,
8385 MODE_SENSE_10,
8386 0xFF,
8387 0xFF,
8388 0xFF,
8389 0xFF,
8390 0xFF,
8391 0xFF,
8392 0xFF,
8393 0xFF
8394};
8395
8396static int AscExeScsiQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq)
8397{
8398 PortAddr iop_base;
8399 int sta;
8400 int n_q_required;
Hannes Reineckeae267592015-04-24 13:18:28 +02008401 bool disable_syn_offset_one_fix;
Matthew Wilcox51219352007-10-02 21:55:22 -04008402 int i;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008403 u32 addr;
Matthew Wilcox51219352007-10-02 21:55:22 -04008404 ushort sg_entry_cnt = 0;
8405 ushort sg_entry_cnt_minus_one = 0;
8406 uchar target_ix;
8407 uchar tid_no;
8408 uchar sdtr_data;
8409 uchar extra_bytes;
8410 uchar scsi_cmd;
8411 uchar disable_cmd;
8412 ASC_SG_HEAD *sg_head;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008413 unsigned long data_cnt;
Matthew Wilcox51219352007-10-02 21:55:22 -04008414
8415 iop_base = asc_dvc->iop_base;
8416 sg_head = scsiq->sg_head;
8417 if (asc_dvc->err_code != 0)
Hannes Reineckef1138a82015-04-24 13:18:29 +02008418 return ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04008419 scsiq->q1.q_no = 0;
8420 if ((scsiq->q2.tag_code & ASC_TAG_FLAG_EXTRA_BYTES) == 0) {
8421 scsiq->q1.extra_bytes = 0;
8422 }
8423 sta = 0;
8424 target_ix = scsiq->q2.target_ix;
8425 tid_no = ASC_TIX_TO_TID(target_ix);
8426 n_q_required = 1;
8427 if (scsiq->cdbptr[0] == REQUEST_SENSE) {
8428 if ((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) {
8429 asc_dvc->sdtr_done &= ~scsiq->q1.target_id;
8430 sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
8431 AscMsgOutSDTR(asc_dvc,
8432 asc_dvc->
8433 sdtr_period_tbl[(sdtr_data >> 4) &
8434 (uchar)(asc_dvc->
8435 max_sdtr_index -
8436 1)],
8437 (uchar)(sdtr_data & (uchar)
8438 ASC_SYN_MAX_OFFSET));
8439 scsiq->q1.cntl |= (QC_MSG_OUT | QC_URGENT);
8440 }
8441 }
8442 if (asc_dvc->in_critical_cnt != 0) {
8443 AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CRITICAL_RE_ENTRY);
Hannes Reineckef1138a82015-04-24 13:18:29 +02008444 return ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04008445 }
8446 asc_dvc->in_critical_cnt++;
8447 if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
8448 if ((sg_entry_cnt = sg_head->entry_cnt) == 0) {
8449 asc_dvc->in_critical_cnt--;
Hannes Reineckef1138a82015-04-24 13:18:29 +02008450 return ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04008451 }
8452#if !CC_VERY_LONG_SG_LIST
8453 if (sg_entry_cnt > ASC_MAX_SG_LIST) {
8454 asc_dvc->in_critical_cnt--;
Hannes Reineckef1138a82015-04-24 13:18:29 +02008455 return ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04008456 }
8457#endif /* !CC_VERY_LONG_SG_LIST */
8458 if (sg_entry_cnt == 1) {
Hannes Reinecke37f64602015-04-24 13:18:32 +02008459 scsiq->q1.data_addr = cpu_to_le32(sg_head->sg_list[0].addr);
8460 scsiq->q1.data_cnt = cpu_to_le32(sg_head->sg_list[0].bytes);
Matthew Wilcox51219352007-10-02 21:55:22 -04008461 scsiq->q1.cntl &= ~(QC_SG_HEAD | QC_SG_SWAP_QUEUE);
8462 }
8463 sg_entry_cnt_minus_one = sg_entry_cnt - 1;
8464 }
8465 scsi_cmd = scsiq->cdbptr[0];
Hannes Reineckeae267592015-04-24 13:18:28 +02008466 disable_syn_offset_one_fix = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04008467 if ((asc_dvc->pci_fix_asyn_xfer & scsiq->q1.target_id) &&
8468 !(asc_dvc->pci_fix_asyn_xfer_always & scsiq->q1.target_id)) {
8469 if (scsiq->q1.cntl & QC_SG_HEAD) {
8470 data_cnt = 0;
8471 for (i = 0; i < sg_entry_cnt; i++) {
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008472 data_cnt += le32_to_cpu(sg_head->sg_list[i].
8473 bytes);
Matthew Wilcox51219352007-10-02 21:55:22 -04008474 }
8475 } else {
8476 data_cnt = le32_to_cpu(scsiq->q1.data_cnt);
8477 }
8478 if (data_cnt != 0UL) {
8479 if (data_cnt < 512UL) {
Hannes Reineckeae267592015-04-24 13:18:28 +02008480 disable_syn_offset_one_fix = true;
Matthew Wilcox51219352007-10-02 21:55:22 -04008481 } else {
8482 for (i = 0; i < ASC_SYN_OFFSET_ONE_DISABLE_LIST;
8483 i++) {
8484 disable_cmd =
8485 _syn_offset_one_disable_cmd[i];
8486 if (disable_cmd == 0xFF) {
8487 break;
8488 }
8489 if (scsi_cmd == disable_cmd) {
8490 disable_syn_offset_one_fix =
Hannes Reineckeae267592015-04-24 13:18:28 +02008491 true;
Matthew Wilcox51219352007-10-02 21:55:22 -04008492 break;
8493 }
8494 }
8495 }
8496 }
8497 }
8498 if (disable_syn_offset_one_fix) {
Christoph Hellwig68d81f42014-11-24 07:07:25 -08008499 scsiq->q2.tag_code &= ~SIMPLE_QUEUE_TAG;
Matthew Wilcox51219352007-10-02 21:55:22 -04008500 scsiq->q2.tag_code |= (ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX |
8501 ASC_TAG_FLAG_DISABLE_DISCONNECT);
8502 } else {
8503 scsiq->q2.tag_code &= 0x27;
8504 }
8505 if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
8506 if (asc_dvc->bug_fix_cntl) {
8507 if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
8508 if ((scsi_cmd == READ_6) ||
8509 (scsi_cmd == READ_10)) {
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008510 addr = le32_to_cpu(sg_head->
Matthew Wilcox51219352007-10-02 21:55:22 -04008511 sg_list
8512 [sg_entry_cnt_minus_one].
8513 addr) +
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008514 le32_to_cpu(sg_head->
Matthew Wilcox51219352007-10-02 21:55:22 -04008515 sg_list
8516 [sg_entry_cnt_minus_one].
8517 bytes);
8518 extra_bytes =
8519 (uchar)((ushort)addr & 0x0003);
8520 if ((extra_bytes != 0)
8521 &&
8522 ((scsiq->q2.
8523 tag_code &
8524 ASC_TAG_FLAG_EXTRA_BYTES)
8525 == 0)) {
8526 scsiq->q2.tag_code |=
8527 ASC_TAG_FLAG_EXTRA_BYTES;
8528 scsiq->q1.extra_bytes =
8529 extra_bytes;
8530 data_cnt =
8531 le32_to_cpu(sg_head->
8532 sg_list
8533 [sg_entry_cnt_minus_one].
8534 bytes);
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008535 data_cnt -= extra_bytes;
Matthew Wilcox51219352007-10-02 21:55:22 -04008536 sg_head->
8537 sg_list
8538 [sg_entry_cnt_minus_one].
8539 bytes =
8540 cpu_to_le32(data_cnt);
8541 }
8542 }
8543 }
8544 }
8545 sg_head->entry_to_copy = sg_head->entry_cnt;
8546#if CC_VERY_LONG_SG_LIST
8547 /*
8548 * Set the sg_entry_cnt to the maximum possible. The rest of
8549 * the SG elements will be copied when the RISC completes the
8550 * SG elements that fit and halts.
8551 */
8552 if (sg_entry_cnt > ASC_MAX_SG_LIST) {
8553 sg_entry_cnt = ASC_MAX_SG_LIST;
8554 }
8555#endif /* CC_VERY_LONG_SG_LIST */
8556 n_q_required = AscSgListToQueue(sg_entry_cnt);
8557 if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, n_q_required) >=
8558 (uint) n_q_required)
8559 || ((scsiq->q1.cntl & QC_URGENT) != 0)) {
8560 if ((sta =
8561 AscSendScsiQueue(asc_dvc, scsiq,
8562 n_q_required)) == 1) {
8563 asc_dvc->in_critical_cnt--;
8564 return (sta);
8565 }
8566 }
8567 } else {
8568 if (asc_dvc->bug_fix_cntl) {
8569 if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
8570 if ((scsi_cmd == READ_6) ||
8571 (scsi_cmd == READ_10)) {
8572 addr =
8573 le32_to_cpu(scsiq->q1.data_addr) +
8574 le32_to_cpu(scsiq->q1.data_cnt);
8575 extra_bytes =
8576 (uchar)((ushort)addr & 0x0003);
8577 if ((extra_bytes != 0)
8578 &&
8579 ((scsiq->q2.
8580 tag_code &
8581 ASC_TAG_FLAG_EXTRA_BYTES)
8582 == 0)) {
8583 data_cnt =
8584 le32_to_cpu(scsiq->q1.
8585 data_cnt);
8586 if (((ushort)data_cnt & 0x01FF)
8587 == 0) {
8588 scsiq->q2.tag_code |=
8589 ASC_TAG_FLAG_EXTRA_BYTES;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008590 data_cnt -= extra_bytes;
Matthew Wilcox51219352007-10-02 21:55:22 -04008591 scsiq->q1.data_cnt =
8592 cpu_to_le32
8593 (data_cnt);
8594 scsiq->q1.extra_bytes =
8595 extra_bytes;
8596 }
8597 }
8598 }
8599 }
8600 }
8601 n_q_required = 1;
8602 if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, 1) >= 1) ||
8603 ((scsiq->q1.cntl & QC_URGENT) != 0)) {
8604 if ((sta = AscSendScsiQueue(asc_dvc, scsiq,
8605 n_q_required)) == 1) {
8606 asc_dvc->in_critical_cnt--;
8607 return (sta);
8608 }
8609 }
8610 }
8611 asc_dvc->in_critical_cnt--;
8612 return (sta);
8613}
8614
8615/*
8616 * AdvExeScsiQueue() - Send a request to the RISC microcode program.
8617 *
8618 * Allocate a carrier structure, point the carrier to the ADV_SCSI_REQ_Q,
8619 * add the carrier to the ICQ (Initiator Command Queue), and tickle the
8620 * RISC to notify it a new command is ready to be executed.
8621 *
8622 * If 'done_status' is not set to QD_DO_RETRY, then 'error_retry' will be
8623 * set to SCSI_MAX_RETRY.
8624 *
Hannes Reinecke9fef6ba2015-04-24 13:18:33 +02008625 * Multi-byte fields in the ADV_SCSI_REQ_Q that are used by the microcode
Matthew Wilcox51219352007-10-02 21:55:22 -04008626 * for DMA addresses or math operations are byte swapped to little-endian
8627 * order.
8628 *
8629 * Return:
8630 * ADV_SUCCESS(1) - The request was successfully queued.
8631 * ADV_BUSY(0) - Resource unavailable; Retry again after pending
8632 * request completes.
8633 * ADV_ERROR(-1) - Invalid ADV_SCSI_REQ_Q request structure
8634 * host IC error.
8635 */
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008636static int AdvExeScsiQueue(ADV_DVC_VAR *asc_dvc, adv_req_t *reqp)
Matthew Wilcox51219352007-10-02 21:55:22 -04008637{
8638 AdvPortAddr iop_base;
Matthew Wilcox51219352007-10-02 21:55:22 -04008639 ADV_CARR_T *new_carrp;
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008640 ADV_SCSI_REQ_Q *scsiq = &reqp->scsi_req_q;
Matthew Wilcox51219352007-10-02 21:55:22 -04008641
8642 /*
8643 * The ADV_SCSI_REQ_Q 'target_id' field should never exceed ADV_MAX_TID.
8644 */
8645 if (scsiq->target_id > ADV_MAX_TID) {
8646 scsiq->host_status = QHSTA_M_INVALID_DEVICE;
8647 scsiq->done_status = QD_WITH_ERROR;
8648 return ADV_ERROR;
8649 }
8650
8651 iop_base = asc_dvc->iop_base;
8652
8653 /*
8654 * Allocate a carrier ensuring at least one carrier always
8655 * remains on the freelist and initialize fields.
8656 */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02008657 new_carrp = adv_get_next_carrier(asc_dvc);
8658 if (!new_carrp) {
8659 ASC_DBG(1, "No free carriers\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04008660 return ADV_BUSY;
8661 }
Matthew Wilcox51219352007-10-02 21:55:22 -04008662
Hannes Reinecke98b96a72015-04-24 13:18:23 +02008663 asc_dvc->carr_pending_cnt++;
Matthew Wilcox51219352007-10-02 21:55:22 -04008664
8665 /*
8666 * Clear the ADV_SCSI_REQ_Q done flag.
8667 */
8668 scsiq->a_flag &= ~ADV_SCSIQ_DONE;
8669
Matthew Wilcox51219352007-10-02 21:55:22 -04008670 /* Save virtual and physical address of ADV_SCSI_REQ_Q and carrier. */
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008671 scsiq->scsiq_ptr = cpu_to_le32(scsiq->srb_tag);
8672 scsiq->scsiq_rptr = cpu_to_le32(reqp->req_addr);
Matthew Wilcox51219352007-10-02 21:55:22 -04008673
Hannes Reinecke98b96a72015-04-24 13:18:23 +02008674 scsiq->carr_va = asc_dvc->icq_sp->carr_va;
Matthew Wilcox51219352007-10-02 21:55:22 -04008675 scsiq->carr_pa = asc_dvc->icq_sp->carr_pa;
8676
8677 /*
8678 * Use the current stopper to send the ADV_SCSI_REQ_Q command to
8679 * the microcode. The newly allocated stopper will become the new
8680 * stopper.
8681 */
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008682 asc_dvc->icq_sp->areq_vpa = scsiq->scsiq_rptr;
Matthew Wilcox51219352007-10-02 21:55:22 -04008683
8684 /*
8685 * Set the 'next_vpa' pointer for the old stopper to be the
8686 * physical address of the new stopper. The RISC can only
8687 * follow physical addresses.
8688 */
8689 asc_dvc->icq_sp->next_vpa = new_carrp->carr_pa;
8690
8691 /*
8692 * Set the host adapter stopper pointer to point to the new carrier.
8693 */
8694 asc_dvc->icq_sp = new_carrp;
8695
8696 if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
8697 asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
8698 /*
8699 * Tickle the RISC to tell it to read its Command Queue Head pointer.
8700 */
8701 AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_A);
8702 if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
8703 /*
8704 * Clear the tickle value. In the ASC-3550 the RISC flag
8705 * command 'clr_tickle_a' does not work unless the host
8706 * value is cleared.
8707 */
8708 AdvWriteByteRegister(iop_base, IOPB_TICKLE,
8709 ADV_TICKLE_NOP);
8710 }
8711 } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
8712 /*
8713 * Notify the RISC a carrier is ready by writing the physical
8714 * address of the new carrier stopper to the COMMA register.
8715 */
8716 AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
8717 le32_to_cpu(new_carrp->carr_pa));
8718 }
8719
8720 return ADV_SUCCESS;
8721}
8722
8723/*
8724 * Execute a single 'Scsi_Cmnd'.
Matthew Wilcox51219352007-10-02 21:55:22 -04008725 */
8726static int asc_execute_scsi_cmnd(struct scsi_cmnd *scp)
8727{
Matthew Wilcox41d24932007-10-02 21:55:24 -04008728 int ret, err_code;
Matthew Wilcoxd2411492007-10-02 21:55:31 -04008729 struct asc_board *boardp = shost_priv(scp->device->host);
Matthew Wilcox51219352007-10-02 21:55:22 -04008730
Matthew Wilcoxb352f922007-10-02 21:55:33 -04008731 ASC_DBG(1, "scp 0x%p\n", scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04008732
8733 if (ASC_NARROW_BOARD(boardp)) {
Matthew Wilcox41d24932007-10-02 21:55:24 -04008734 ASC_DVC_VAR *asc_dvc = &boardp->dvc_var.asc_dvc_var;
Matthew Wilcox05848b62007-10-02 21:55:25 -04008735 struct asc_scsi_q asc_scsi_q;
Matthew Wilcox51219352007-10-02 21:55:22 -04008736
Matthew Wilcox41d24932007-10-02 21:55:24 -04008737 /* asc_build_req() can not return ASC_BUSY. */
Matthew Wilcox05848b62007-10-02 21:55:25 -04008738 ret = asc_build_req(boardp, scp, &asc_scsi_q);
8739 if (ret == ASC_ERROR) {
Matthew Wilcox51219352007-10-02 21:55:22 -04008740 ASC_STATS(scp->device->host, build_error);
8741 return ASC_ERROR;
8742 }
8743
Matthew Wilcox41d24932007-10-02 21:55:24 -04008744 ret = AscExeScsiQueue(asc_dvc, &asc_scsi_q);
Matthew Wilcox05848b62007-10-02 21:55:25 -04008745 kfree(asc_scsi_q.sg_head);
Matthew Wilcox41d24932007-10-02 21:55:24 -04008746 err_code = asc_dvc->err_code;
Matthew Wilcox51219352007-10-02 21:55:22 -04008747 } else {
Matthew Wilcox41d24932007-10-02 21:55:24 -04008748 ADV_DVC_VAR *adv_dvc = &boardp->dvc_var.adv_dvc_var;
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008749 adv_req_t *adv_reqp;
Matthew Wilcox51219352007-10-02 21:55:22 -04008750
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008751 switch (adv_build_req(boardp, scp, &adv_reqp)) {
Matthew Wilcox51219352007-10-02 21:55:22 -04008752 case ASC_NOERROR:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04008753 ASC_DBG(3, "adv_build_req ASC_NOERROR\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04008754 break;
8755 case ASC_BUSY:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04008756 ASC_DBG(1, "adv_build_req ASC_BUSY\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04008757 /*
8758 * The asc_stats fields 'adv_build_noreq' and
8759 * 'adv_build_nosg' count wide board busy conditions.
8760 * They are updated in adv_build_req and
8761 * adv_get_sglist, respectively.
8762 */
8763 return ASC_BUSY;
8764 case ASC_ERROR:
8765 default:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04008766 ASC_DBG(1, "adv_build_req ASC_ERROR\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04008767 ASC_STATS(scp->device->host, build_error);
8768 return ASC_ERROR;
8769 }
8770
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008771 ret = AdvExeScsiQueue(adv_dvc, adv_reqp);
Matthew Wilcox41d24932007-10-02 21:55:24 -04008772 err_code = adv_dvc->err_code;
8773 }
8774
8775 switch (ret) {
8776 case ASC_NOERROR:
8777 ASC_STATS(scp->device->host, exe_noerror);
8778 /*
8779 * Increment monotonically increasing per device
8780 * successful request counter. Wrapping doesn't matter.
8781 */
8782 boardp->reqcnt[scp->device->id]++;
Matthew Wilcoxb352f922007-10-02 21:55:33 -04008783 ASC_DBG(1, "ExeScsiQueue() ASC_NOERROR\n");
Matthew Wilcox41d24932007-10-02 21:55:24 -04008784 break;
8785 case ASC_BUSY:
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008786 ASC_DBG(1, "ExeScsiQueue() ASC_BUSY\n");
Matthew Wilcox41d24932007-10-02 21:55:24 -04008787 ASC_STATS(scp->device->host, exe_busy);
8788 break;
8789 case ASC_ERROR:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04008790 scmd_printk(KERN_ERR, scp, "ExeScsiQueue() ASC_ERROR, "
8791 "err_code 0x%x\n", err_code);
Matthew Wilcox41d24932007-10-02 21:55:24 -04008792 ASC_STATS(scp->device->host, exe_error);
8793 scp->result = HOST_BYTE(DID_ERROR);
8794 break;
8795 default:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04008796 scmd_printk(KERN_ERR, scp, "ExeScsiQueue() unknown, "
8797 "err_code 0x%x\n", err_code);
Matthew Wilcox41d24932007-10-02 21:55:24 -04008798 ASC_STATS(scp->device->host, exe_unknown);
8799 scp->result = HOST_BYTE(DID_ERROR);
8800 break;
Matthew Wilcox51219352007-10-02 21:55:22 -04008801 }
8802
Matthew Wilcoxb352f922007-10-02 21:55:33 -04008803 ASC_DBG(1, "end\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04008804 return ret;
8805}
8806
8807/*
8808 * advansys_queuecommand() - interrupt-driven I/O entrypoint.
8809 *
8810 * This function always returns 0. Command return status is saved
8811 * in the 'scp' result field.
8812 */
8813static int
Jeff Garzikf2812332010-11-16 02:10:29 -05008814advansys_queuecommand_lck(struct scsi_cmnd *scp, void (*done)(struct scsi_cmnd *))
Matthew Wilcox51219352007-10-02 21:55:22 -04008815{
8816 struct Scsi_Host *shost = scp->device->host;
Matthew Wilcox51219352007-10-02 21:55:22 -04008817 int asc_res, result = 0;
8818
8819 ASC_STATS(shost, queuecommand);
8820 scp->scsi_done = done;
8821
Matthew Wilcox51219352007-10-02 21:55:22 -04008822 asc_res = asc_execute_scsi_cmnd(scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04008823
8824 switch (asc_res) {
8825 case ASC_NOERROR:
8826 break;
8827 case ASC_BUSY:
8828 result = SCSI_MLQUEUE_HOST_BUSY;
8829 break;
8830 case ASC_ERROR:
8831 default:
8832 asc_scsi_done(scp);
8833 break;
8834 }
8835
8836 return result;
8837}
8838
Jeff Garzikf2812332010-11-16 02:10:29 -05008839static DEF_SCSI_QCMD(advansys_queuecommand)
8840
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008841static ushort AscGetEisaChipCfg(PortAddr iop_base)
Matthew Wilcox51219352007-10-02 21:55:22 -04008842{
8843 PortAddr eisa_cfg_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
8844 (PortAddr) (ASC_EISA_CFG_IOP_MASK);
8845 return inpw(eisa_cfg_iop);
8846}
8847
8848/*
8849 * Return the BIOS address of the adapter at the specified
8850 * I/O port and with the specified bus type.
8851 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008852static unsigned short AscGetChipBiosAddress(PortAddr iop_base,
8853 unsigned short bus_type)
Matthew Wilcox51219352007-10-02 21:55:22 -04008854{
8855 unsigned short cfg_lsw;
8856 unsigned short bios_addr;
8857
8858 /*
8859 * The PCI BIOS is re-located by the motherboard BIOS. Because
8860 * of this the driver can not determine where a PCI BIOS is
8861 * loaded and executes.
8862 */
8863 if (bus_type & ASC_IS_PCI)
8864 return 0;
8865
8866 if ((bus_type & ASC_IS_EISA) != 0) {
8867 cfg_lsw = AscGetEisaChipCfg(iop_base);
8868 cfg_lsw &= 0x000F;
8869 bios_addr = ASC_BIOS_MIN_ADDR + cfg_lsw * ASC_BIOS_BANK_SIZE;
8870 return bios_addr;
8871 }
8872
8873 cfg_lsw = AscGetChipCfgLsw(iop_base);
8874
8875 /*
8876 * ISA PnP uses the top bit as the 32K BIOS flag
8877 */
8878 if (bus_type == ASC_IS_ISAPNP)
8879 cfg_lsw &= 0x7FFF;
8880 bios_addr = ASC_BIOS_MIN_ADDR + (cfg_lsw >> 12) * ASC_BIOS_BANK_SIZE;
8881 return bios_addr;
8882}
8883
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008884static uchar AscSetChipScsiID(PortAddr iop_base, uchar new_host_id)
Matthew Wilcox51219352007-10-02 21:55:22 -04008885{
8886 ushort cfg_lsw;
8887
8888 if (AscGetChipScsiID(iop_base) == new_host_id) {
8889 return (new_host_id);
8890 }
8891 cfg_lsw = AscGetChipCfgLsw(iop_base);
8892 cfg_lsw &= 0xF8FF;
8893 cfg_lsw |= (ushort)((new_host_id & ASC_MAX_TID) << 8);
8894 AscSetChipCfgLsw(iop_base, cfg_lsw);
8895 return (AscGetChipScsiID(iop_base));
8896}
8897
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008898static unsigned char AscGetChipScsiCtrl(PortAddr iop_base)
Matthew Wilcox51219352007-10-02 21:55:22 -04008899{
8900 unsigned char sc;
8901
8902 AscSetBank(iop_base, 1);
8903 sc = inp(iop_base + IOP_REG_SC);
8904 AscSetBank(iop_base, 0);
8905 return sc;
8906}
8907
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008908static unsigned char AscGetChipVersion(PortAddr iop_base,
8909 unsigned short bus_type)
Matthew Wilcox51219352007-10-02 21:55:22 -04008910{
8911 if (bus_type & ASC_IS_EISA) {
8912 PortAddr eisa_iop;
8913 unsigned char revision;
8914 eisa_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
8915 (PortAddr) ASC_EISA_REV_IOP_MASK;
8916 revision = inp(eisa_iop);
8917 return ASC_CHIP_MIN_VER_EISA - 1 + revision;
8918 }
8919 return AscGetChipVerNo(iop_base);
8920}
8921
Matthew Wilcox51219352007-10-02 21:55:22 -04008922#ifdef CONFIG_ISA
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008923static void AscEnableIsaDma(uchar dma_channel)
Matthew Wilcox51219352007-10-02 21:55:22 -04008924{
8925 if (dma_channel < 4) {
8926 outp(0x000B, (ushort)(0xC0 | dma_channel));
8927 outp(0x000A, dma_channel);
8928 } else if (dma_channel < 8) {
8929 outp(0x00D6, (ushort)(0xC0 | (dma_channel - 4)));
8930 outp(0x00D4, (ushort)(dma_channel - 4));
8931 }
Matthew Wilcox51219352007-10-02 21:55:22 -04008932}
8933#endif /* CONFIG_ISA */
8934
8935static int AscStopQueueExe(PortAddr iop_base)
8936{
8937 int count = 0;
8938
8939 if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) == 0) {
8940 AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
8941 ASC_STOP_REQ_RISC_STOP);
8942 do {
8943 if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) &
8944 ASC_STOP_ACK_RISC_STOP) {
8945 return (1);
8946 }
8947 mdelay(100);
8948 } while (count++ < 20);
8949 }
8950 return (0);
8951}
8952
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008953static unsigned int AscGetMaxDmaCount(ushort bus_type)
Matthew Wilcox51219352007-10-02 21:55:22 -04008954{
8955 if (bus_type & ASC_IS_ISA)
8956 return ASC_MAX_ISA_DMA_COUNT;
8957 else if (bus_type & (ASC_IS_EISA | ASC_IS_VL))
8958 return ASC_MAX_VL_DMA_COUNT;
8959 return ASC_MAX_PCI_DMA_COUNT;
8960}
8961
8962#ifdef CONFIG_ISA
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008963static ushort AscGetIsaDmaChannel(PortAddr iop_base)
Matthew Wilcox51219352007-10-02 21:55:22 -04008964{
8965 ushort channel;
8966
8967 channel = AscGetChipCfgLsw(iop_base) & 0x0003;
8968 if (channel == 0x03)
8969 return (0);
8970 else if (channel == 0x00)
8971 return (7);
8972 return (channel + 4);
8973}
8974
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008975static ushort AscSetIsaDmaChannel(PortAddr iop_base, ushort dma_channel)
Matthew Wilcox51219352007-10-02 21:55:22 -04008976{
8977 ushort cfg_lsw;
8978 uchar value;
8979
8980 if ((dma_channel >= 5) && (dma_channel <= 7)) {
8981 if (dma_channel == 7)
8982 value = 0x00;
8983 else
8984 value = dma_channel - 4;
8985 cfg_lsw = AscGetChipCfgLsw(iop_base) & 0xFFFC;
8986 cfg_lsw |= value;
8987 AscSetChipCfgLsw(iop_base, cfg_lsw);
8988 return (AscGetIsaDmaChannel(iop_base));
8989 }
8990 return 0;
8991}
8992
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008993static uchar AscGetIsaDmaSpeed(PortAddr iop_base)
Matthew Wilcox51219352007-10-02 21:55:22 -04008994{
8995 uchar speed_value;
8996
8997 AscSetBank(iop_base, 1);
8998 speed_value = AscReadChipDmaSpeed(iop_base);
8999 speed_value &= 0x07;
9000 AscSetBank(iop_base, 0);
9001 return speed_value;
9002}
9003
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009004static uchar AscSetIsaDmaSpeed(PortAddr iop_base, uchar speed_value)
Matthew Wilcox51219352007-10-02 21:55:22 -04009005{
9006 speed_value &= 0x07;
9007 AscSetBank(iop_base, 1);
9008 AscWriteChipDmaSpeed(iop_base, speed_value);
9009 AscSetBank(iop_base, 0);
9010 return AscGetIsaDmaSpeed(iop_base);
9011}
9012#endif /* CONFIG_ISA */
9013
Hannes Reineckef33134e2015-04-24 13:18:31 +02009014static void AscInitAscDvcVar(ASC_DVC_VAR *asc_dvc)
Matthew Wilcox51219352007-10-02 21:55:22 -04009015{
9016 int i;
9017 PortAddr iop_base;
Matthew Wilcox51219352007-10-02 21:55:22 -04009018 uchar chip_version;
9019
9020 iop_base = asc_dvc->iop_base;
Matthew Wilcox51219352007-10-02 21:55:22 -04009021 asc_dvc->err_code = 0;
9022 if ((asc_dvc->bus_type &
9023 (ASC_IS_ISA | ASC_IS_PCI | ASC_IS_EISA | ASC_IS_VL)) == 0) {
9024 asc_dvc->err_code |= ASC_IERR_NO_BUS_TYPE;
9025 }
9026 AscSetChipControl(iop_base, CC_HALT);
9027 AscSetChipStatus(iop_base, 0);
9028 asc_dvc->bug_fix_cntl = 0;
9029 asc_dvc->pci_fix_asyn_xfer = 0;
9030 asc_dvc->pci_fix_asyn_xfer_always = 0;
Uwe Kleine-König421f91d2010-06-11 12:17:00 +02009031 /* asc_dvc->init_state initialized in AscInitGetConfig(). */
Matthew Wilcox51219352007-10-02 21:55:22 -04009032 asc_dvc->sdtr_done = 0;
9033 asc_dvc->cur_total_qng = 0;
Hannes Reineckeae267592015-04-24 13:18:28 +02009034 asc_dvc->is_in_int = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04009035 asc_dvc->in_critical_cnt = 0;
9036 asc_dvc->last_q_shortage = 0;
9037 asc_dvc->use_tagged_qng = 0;
9038 asc_dvc->no_scam = 0;
9039 asc_dvc->unit_not_ready = 0;
9040 asc_dvc->queue_full_or_busy = 0;
9041 asc_dvc->redo_scam = 0;
9042 asc_dvc->res2 = 0;
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04009043 asc_dvc->min_sdtr_index = 0;
Matthew Wilcox51219352007-10-02 21:55:22 -04009044 asc_dvc->cfg->can_tagged_qng = 0;
9045 asc_dvc->cfg->cmd_qng_enabled = 0;
9046 asc_dvc->dvc_cntl = ASC_DEF_DVC_CNTL;
9047 asc_dvc->init_sdtr = 0;
9048 asc_dvc->max_total_qng = ASC_DEF_MAX_TOTAL_QNG;
9049 asc_dvc->scsi_reset_wait = 3;
9050 asc_dvc->start_motor = ASC_SCSI_WIDTH_BIT_SET;
9051 asc_dvc->max_dma_count = AscGetMaxDmaCount(asc_dvc->bus_type);
9052 asc_dvc->cfg->sdtr_enable = ASC_SCSI_WIDTH_BIT_SET;
9053 asc_dvc->cfg->disc_enable = ASC_SCSI_WIDTH_BIT_SET;
9054 asc_dvc->cfg->chip_scsi_id = ASC_DEF_CHIP_SCSI_ID;
Matthew Wilcox51219352007-10-02 21:55:22 -04009055 chip_version = AscGetChipVersion(iop_base, asc_dvc->bus_type);
9056 asc_dvc->cfg->chip_version = chip_version;
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04009057 asc_dvc->sdtr_period_tbl = asc_syn_xfer_period;
Matthew Wilcox51219352007-10-02 21:55:22 -04009058 asc_dvc->max_sdtr_index = 7;
9059 if ((asc_dvc->bus_type & ASC_IS_PCI) &&
9060 (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3150)) {
9061 asc_dvc->bus_type = ASC_IS_PCI_ULTRA;
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04009062 asc_dvc->sdtr_period_tbl = asc_syn_ultra_xfer_period;
Matthew Wilcox51219352007-10-02 21:55:22 -04009063 asc_dvc->max_sdtr_index = 15;
9064 if (chip_version == ASC_CHIP_VER_PCI_ULTRA_3150) {
9065 AscSetExtraControl(iop_base,
9066 (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
9067 } else if (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3050) {
9068 AscSetExtraControl(iop_base,
9069 (SEC_ACTIVE_NEGATE |
9070 SEC_ENABLE_FILTER));
9071 }
9072 }
9073 if (asc_dvc->bus_type == ASC_IS_PCI) {
9074 AscSetExtraControl(iop_base,
9075 (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
9076 }
9077
9078 asc_dvc->cfg->isa_dma_speed = ASC_DEF_ISA_DMA_SPEED;
9079#ifdef CONFIG_ISA
9080 if ((asc_dvc->bus_type & ASC_IS_ISA) != 0) {
9081 if (chip_version >= ASC_CHIP_MIN_VER_ISA_PNP) {
9082 AscSetChipIFC(iop_base, IFC_INIT_DEFAULT);
9083 asc_dvc->bus_type = ASC_IS_ISAPNP;
9084 }
9085 asc_dvc->cfg->isa_dma_channel =
9086 (uchar)AscGetIsaDmaChannel(iop_base);
9087 }
9088#endif /* CONFIG_ISA */
9089 for (i = 0; i <= ASC_MAX_TID; i++) {
9090 asc_dvc->cur_dvc_qng[i] = 0;
9091 asc_dvc->max_dvc_qng[i] = ASC_MAX_SCSI1_QNG;
9092 asc_dvc->scsiq_busy_head[i] = (ASC_SCSI_Q *)0L;
9093 asc_dvc->scsiq_busy_tail[i] = (ASC_SCSI_Q *)0L;
9094 asc_dvc->cfg->max_tag_qng[i] = ASC_MAX_INRAM_TAG_QNG;
9095 }
Matthew Wilcox51219352007-10-02 21:55:22 -04009096}
9097
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009098static int AscWriteEEPCmdReg(PortAddr iop_base, uchar cmd_reg)
Matthew Wilcox51219352007-10-02 21:55:22 -04009099{
9100 int retry;
9101
9102 for (retry = 0; retry < ASC_EEP_MAX_RETRY; retry++) {
9103 unsigned char read_back;
9104 AscSetChipEEPCmd(iop_base, cmd_reg);
9105 mdelay(1);
9106 read_back = AscGetChipEEPCmd(iop_base);
9107 if (read_back == cmd_reg)
9108 return 1;
9109 }
9110 return 0;
9111}
9112
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009113static void AscWaitEEPRead(void)
Matthew Wilcox51219352007-10-02 21:55:22 -04009114{
9115 mdelay(1);
9116}
9117
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009118static ushort AscReadEEPWord(PortAddr iop_base, uchar addr)
Matthew Wilcox51219352007-10-02 21:55:22 -04009119{
9120 ushort read_wval;
9121 uchar cmd_reg;
9122
9123 AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
9124 AscWaitEEPRead();
9125 cmd_reg = addr | ASC_EEP_CMD_READ;
9126 AscWriteEEPCmdReg(iop_base, cmd_reg);
9127 AscWaitEEPRead();
9128 read_wval = AscGetChipEEPData(iop_base);
9129 AscWaitEEPRead();
9130 return read_wval;
9131}
9132
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009133static ushort AscGetEEPConfig(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf,
9134 ushort bus_type)
Matthew Wilcox51219352007-10-02 21:55:22 -04009135{
9136 ushort wval;
9137 ushort sum;
9138 ushort *wbuf;
9139 int cfg_beg;
9140 int cfg_end;
9141 int uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
9142 int s_addr;
9143
9144 wbuf = (ushort *)cfg_buf;
9145 sum = 0;
9146 /* Read two config words; Byte-swapping done by AscReadEEPWord(). */
9147 for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
9148 *wbuf = AscReadEEPWord(iop_base, (uchar)s_addr);
9149 sum += *wbuf;
9150 }
9151 if (bus_type & ASC_IS_VL) {
9152 cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
9153 cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
9154 } else {
9155 cfg_beg = ASC_EEP_DVC_CFG_BEG;
9156 cfg_end = ASC_EEP_MAX_DVC_ADDR;
9157 }
9158 for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
9159 wval = AscReadEEPWord(iop_base, (uchar)s_addr);
9160 if (s_addr <= uchar_end_in_config) {
9161 /*
9162 * Swap all char fields - must unswap bytes already swapped
9163 * by AscReadEEPWord().
9164 */
9165 *wbuf = le16_to_cpu(wval);
9166 } else {
9167 /* Don't swap word field at the end - cntl field. */
9168 *wbuf = wval;
9169 }
9170 sum += wval; /* Checksum treats all EEPROM data as words. */
9171 }
9172 /*
9173 * Read the checksum word which will be compared against 'sum'
9174 * by the caller. Word field already swapped.
9175 */
9176 *wbuf = AscReadEEPWord(iop_base, (uchar)s_addr);
9177 return sum;
9178}
9179
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009180static int AscTestExternalLram(ASC_DVC_VAR *asc_dvc)
Matthew Wilcox51219352007-10-02 21:55:22 -04009181{
9182 PortAddr iop_base;
9183 ushort q_addr;
9184 ushort saved_word;
9185 int sta;
9186
9187 iop_base = asc_dvc->iop_base;
9188 sta = 0;
9189 q_addr = ASC_QNO_TO_QADDR(241);
9190 saved_word = AscReadLramWord(iop_base, q_addr);
9191 AscSetChipLramAddr(iop_base, q_addr);
9192 AscSetChipLramData(iop_base, 0x55AA);
9193 mdelay(10);
9194 AscSetChipLramAddr(iop_base, q_addr);
9195 if (AscGetChipLramData(iop_base) == 0x55AA) {
9196 sta = 1;
9197 AscWriteLramWord(iop_base, q_addr, saved_word);
9198 }
9199 return (sta);
9200}
9201
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009202static void AscWaitEEPWrite(void)
Matthew Wilcox51219352007-10-02 21:55:22 -04009203{
9204 mdelay(20);
Matthew Wilcox51219352007-10-02 21:55:22 -04009205}
9206
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009207static int AscWriteEEPDataReg(PortAddr iop_base, ushort data_reg)
Matthew Wilcox51219352007-10-02 21:55:22 -04009208{
9209 ushort read_back;
9210 int retry;
9211
9212 retry = 0;
Hannes Reineckeae267592015-04-24 13:18:28 +02009213 while (true) {
Matthew Wilcox51219352007-10-02 21:55:22 -04009214 AscSetChipEEPData(iop_base, data_reg);
9215 mdelay(1);
9216 read_back = AscGetChipEEPData(iop_base);
9217 if (read_back == data_reg) {
9218 return (1);
9219 }
9220 if (retry++ > ASC_EEP_MAX_RETRY) {
9221 return (0);
9222 }
9223 }
9224}
9225
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009226static ushort AscWriteEEPWord(PortAddr iop_base, uchar addr, ushort word_val)
Matthew Wilcox51219352007-10-02 21:55:22 -04009227{
9228 ushort read_wval;
9229
9230 read_wval = AscReadEEPWord(iop_base, addr);
9231 if (read_wval != word_val) {
9232 AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_ABLE);
9233 AscWaitEEPRead();
9234 AscWriteEEPDataReg(iop_base, word_val);
9235 AscWaitEEPRead();
9236 AscWriteEEPCmdReg(iop_base,
9237 (uchar)((uchar)ASC_EEP_CMD_WRITE | addr));
9238 AscWaitEEPWrite();
9239 AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
9240 AscWaitEEPRead();
9241 return (AscReadEEPWord(iop_base, addr));
9242 }
9243 return (read_wval);
9244}
9245
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009246static int AscSetEEPConfigOnce(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf,
9247 ushort bus_type)
Matthew Wilcox51219352007-10-02 21:55:22 -04009248{
9249 int n_error;
9250 ushort *wbuf;
9251 ushort word;
9252 ushort sum;
9253 int s_addr;
9254 int cfg_beg;
9255 int cfg_end;
9256 int uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
9257
9258 wbuf = (ushort *)cfg_buf;
9259 n_error = 0;
9260 sum = 0;
9261 /* Write two config words; AscWriteEEPWord() will swap bytes. */
9262 for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
9263 sum += *wbuf;
9264 if (*wbuf != AscWriteEEPWord(iop_base, (uchar)s_addr, *wbuf)) {
9265 n_error++;
9266 }
9267 }
9268 if (bus_type & ASC_IS_VL) {
9269 cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
9270 cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
9271 } else {
9272 cfg_beg = ASC_EEP_DVC_CFG_BEG;
9273 cfg_end = ASC_EEP_MAX_DVC_ADDR;
9274 }
9275 for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
9276 if (s_addr <= uchar_end_in_config) {
9277 /*
9278 * This is a char field. Swap char fields before they are
9279 * swapped again by AscWriteEEPWord().
9280 */
9281 word = cpu_to_le16(*wbuf);
9282 if (word !=
9283 AscWriteEEPWord(iop_base, (uchar)s_addr, word)) {
9284 n_error++;
9285 }
9286 } else {
9287 /* Don't swap word field at the end - cntl field. */
9288 if (*wbuf !=
9289 AscWriteEEPWord(iop_base, (uchar)s_addr, *wbuf)) {
9290 n_error++;
9291 }
9292 }
9293 sum += *wbuf; /* Checksum calculated from word values. */
9294 }
9295 /* Write checksum word. It will be swapped by AscWriteEEPWord(). */
9296 *wbuf = sum;
9297 if (sum != AscWriteEEPWord(iop_base, (uchar)s_addr, sum)) {
9298 n_error++;
9299 }
9300
9301 /* Read EEPROM back again. */
9302 wbuf = (ushort *)cfg_buf;
9303 /*
9304 * Read two config words; Byte-swapping done by AscReadEEPWord().
9305 */
9306 for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
9307 if (*wbuf != AscReadEEPWord(iop_base, (uchar)s_addr)) {
9308 n_error++;
9309 }
9310 }
9311 if (bus_type & ASC_IS_VL) {
9312 cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
9313 cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
9314 } else {
9315 cfg_beg = ASC_EEP_DVC_CFG_BEG;
9316 cfg_end = ASC_EEP_MAX_DVC_ADDR;
9317 }
9318 for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
9319 if (s_addr <= uchar_end_in_config) {
9320 /*
9321 * Swap all char fields. Must unswap bytes already swapped
9322 * by AscReadEEPWord().
9323 */
9324 word =
9325 le16_to_cpu(AscReadEEPWord
9326 (iop_base, (uchar)s_addr));
9327 } else {
9328 /* Don't swap word field at the end - cntl field. */
9329 word = AscReadEEPWord(iop_base, (uchar)s_addr);
9330 }
9331 if (*wbuf != word) {
9332 n_error++;
9333 }
9334 }
9335 /* Read checksum; Byte swapping not needed. */
9336 if (AscReadEEPWord(iop_base, (uchar)s_addr) != sum) {
9337 n_error++;
9338 }
9339 return n_error;
9340}
9341
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009342static int AscSetEEPConfig(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf,
9343 ushort bus_type)
Matthew Wilcox51219352007-10-02 21:55:22 -04009344{
9345 int retry;
9346 int n_error;
9347
9348 retry = 0;
Hannes Reineckeae267592015-04-24 13:18:28 +02009349 while (true) {
Matthew Wilcox51219352007-10-02 21:55:22 -04009350 if ((n_error = AscSetEEPConfigOnce(iop_base, cfg_buf,
9351 bus_type)) == 0) {
9352 break;
9353 }
9354 if (++retry > ASC_EEP_MAX_RETRY) {
9355 break;
9356 }
9357 }
9358 return n_error;
9359}
9360
Hannes Reineckef33134e2015-04-24 13:18:31 +02009361static int AscInitFromEEP(ASC_DVC_VAR *asc_dvc)
Matthew Wilcox51219352007-10-02 21:55:22 -04009362{
9363 ASCEEP_CONFIG eep_config_buf;
9364 ASCEEP_CONFIG *eep_config;
9365 PortAddr iop_base;
9366 ushort chksum;
9367 ushort warn_code;
9368 ushort cfg_msw, cfg_lsw;
9369 int i;
9370 int write_eep = 0;
9371
9372 iop_base = asc_dvc->iop_base;
9373 warn_code = 0;
9374 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0x00FE);
9375 AscStopQueueExe(iop_base);
Hannes Reineckeae267592015-04-24 13:18:28 +02009376 if ((AscStopChip(iop_base)) ||
Matthew Wilcox51219352007-10-02 21:55:22 -04009377 (AscGetChipScsiCtrl(iop_base) != 0)) {
9378 asc_dvc->init_state |= ASC_INIT_RESET_SCSI_DONE;
9379 AscResetChipAndScsiBus(asc_dvc);
9380 mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
9381 }
Hannes Reinecked647c782015-04-24 13:18:26 +02009382 if (!AscIsChipHalted(iop_base)) {
Matthew Wilcox51219352007-10-02 21:55:22 -04009383 asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
9384 return (warn_code);
9385 }
9386 AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
9387 if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
9388 asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
9389 return (warn_code);
9390 }
9391 eep_config = (ASCEEP_CONFIG *)&eep_config_buf;
9392 cfg_msw = AscGetChipCfgMsw(iop_base);
9393 cfg_lsw = AscGetChipCfgLsw(iop_base);
9394 if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
9395 cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
9396 warn_code |= ASC_WARN_CFG_MSW_RECOVER;
9397 AscSetChipCfgMsw(iop_base, cfg_msw);
9398 }
9399 chksum = AscGetEEPConfig(iop_base, eep_config, asc_dvc->bus_type);
Matthew Wilcoxb352f922007-10-02 21:55:33 -04009400 ASC_DBG(1, "chksum 0x%x\n", chksum);
Matthew Wilcox51219352007-10-02 21:55:22 -04009401 if (chksum == 0) {
9402 chksum = 0xaa55;
9403 }
9404 if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
9405 warn_code |= ASC_WARN_AUTO_CONFIG;
9406 if (asc_dvc->cfg->chip_version == 3) {
9407 if (eep_config->cfg_lsw != cfg_lsw) {
9408 warn_code |= ASC_WARN_EEPROM_RECOVER;
9409 eep_config->cfg_lsw =
9410 AscGetChipCfgLsw(iop_base);
9411 }
9412 if (eep_config->cfg_msw != cfg_msw) {
9413 warn_code |= ASC_WARN_EEPROM_RECOVER;
9414 eep_config->cfg_msw =
9415 AscGetChipCfgMsw(iop_base);
9416 }
9417 }
9418 }
9419 eep_config->cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
9420 eep_config->cfg_lsw |= ASC_CFG0_HOST_INT_ON;
Matthew Wilcoxb352f922007-10-02 21:55:33 -04009421 ASC_DBG(1, "eep_config->chksum 0x%x\n", eep_config->chksum);
Matthew Wilcox51219352007-10-02 21:55:22 -04009422 if (chksum != eep_config->chksum) {
9423 if (AscGetChipVersion(iop_base, asc_dvc->bus_type) ==
9424 ASC_CHIP_VER_PCI_ULTRA_3050) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04009425 ASC_DBG(1, "chksum error ignored; EEPROM-less board\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009426 eep_config->init_sdtr = 0xFF;
9427 eep_config->disc_enable = 0xFF;
9428 eep_config->start_motor = 0xFF;
9429 eep_config->use_cmd_qng = 0;
9430 eep_config->max_total_qng = 0xF0;
9431 eep_config->max_tag_qng = 0x20;
9432 eep_config->cntl = 0xBFFF;
9433 ASC_EEP_SET_CHIP_ID(eep_config, 7);
9434 eep_config->no_scam = 0;
9435 eep_config->adapter_info[0] = 0;
9436 eep_config->adapter_info[1] = 0;
9437 eep_config->adapter_info[2] = 0;
9438 eep_config->adapter_info[3] = 0;
9439 eep_config->adapter_info[4] = 0;
9440 /* Indicate EEPROM-less board. */
9441 eep_config->adapter_info[5] = 0xBB;
9442 } else {
9443 ASC_PRINT
9444 ("AscInitFromEEP: EEPROM checksum error; Will try to re-write EEPROM.\n");
9445 write_eep = 1;
9446 warn_code |= ASC_WARN_EEPROM_CHKSUM;
9447 }
9448 }
9449 asc_dvc->cfg->sdtr_enable = eep_config->init_sdtr;
9450 asc_dvc->cfg->disc_enable = eep_config->disc_enable;
9451 asc_dvc->cfg->cmd_qng_enabled = eep_config->use_cmd_qng;
9452 asc_dvc->cfg->isa_dma_speed = ASC_EEP_GET_DMA_SPD(eep_config);
9453 asc_dvc->start_motor = eep_config->start_motor;
9454 asc_dvc->dvc_cntl = eep_config->cntl;
9455 asc_dvc->no_scam = eep_config->no_scam;
9456 asc_dvc->cfg->adapter_info[0] = eep_config->adapter_info[0];
9457 asc_dvc->cfg->adapter_info[1] = eep_config->adapter_info[1];
9458 asc_dvc->cfg->adapter_info[2] = eep_config->adapter_info[2];
9459 asc_dvc->cfg->adapter_info[3] = eep_config->adapter_info[3];
9460 asc_dvc->cfg->adapter_info[4] = eep_config->adapter_info[4];
9461 asc_dvc->cfg->adapter_info[5] = eep_config->adapter_info[5];
9462 if (!AscTestExternalLram(asc_dvc)) {
9463 if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) ==
9464 ASC_IS_PCI_ULTRA)) {
9465 eep_config->max_total_qng =
9466 ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG;
9467 eep_config->max_tag_qng =
9468 ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG;
9469 } else {
9470 eep_config->cfg_msw |= 0x0800;
9471 cfg_msw |= 0x0800;
9472 AscSetChipCfgMsw(iop_base, cfg_msw);
9473 eep_config->max_total_qng = ASC_MAX_PCI_INRAM_TOTAL_QNG;
9474 eep_config->max_tag_qng = ASC_MAX_INRAM_TAG_QNG;
9475 }
9476 } else {
9477 }
9478 if (eep_config->max_total_qng < ASC_MIN_TOTAL_QNG) {
9479 eep_config->max_total_qng = ASC_MIN_TOTAL_QNG;
9480 }
9481 if (eep_config->max_total_qng > ASC_MAX_TOTAL_QNG) {
9482 eep_config->max_total_qng = ASC_MAX_TOTAL_QNG;
9483 }
9484 if (eep_config->max_tag_qng > eep_config->max_total_qng) {
9485 eep_config->max_tag_qng = eep_config->max_total_qng;
9486 }
9487 if (eep_config->max_tag_qng < ASC_MIN_TAG_Q_PER_DVC) {
9488 eep_config->max_tag_qng = ASC_MIN_TAG_Q_PER_DVC;
9489 }
9490 asc_dvc->max_total_qng = eep_config->max_total_qng;
9491 if ((eep_config->use_cmd_qng & eep_config->disc_enable) !=
9492 eep_config->use_cmd_qng) {
9493 eep_config->disc_enable = eep_config->use_cmd_qng;
9494 warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
9495 }
Matthew Wilcox51219352007-10-02 21:55:22 -04009496 ASC_EEP_SET_CHIP_ID(eep_config,
9497 ASC_EEP_GET_CHIP_ID(eep_config) & ASC_MAX_TID);
9498 asc_dvc->cfg->chip_scsi_id = ASC_EEP_GET_CHIP_ID(eep_config);
9499 if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) &&
9500 !(asc_dvc->dvc_cntl & ASC_CNTL_SDTR_ENABLE_ULTRA)) {
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04009501 asc_dvc->min_sdtr_index = ASC_SDTR_ULTRA_PCI_10MB_INDEX;
Matthew Wilcox51219352007-10-02 21:55:22 -04009502 }
9503
9504 for (i = 0; i <= ASC_MAX_TID; i++) {
9505 asc_dvc->dos_int13_table[i] = eep_config->dos_int13_table[i];
9506 asc_dvc->cfg->max_tag_qng[i] = eep_config->max_tag_qng;
9507 asc_dvc->cfg->sdtr_period_offset[i] =
9508 (uchar)(ASC_DEF_SDTR_OFFSET |
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04009509 (asc_dvc->min_sdtr_index << 4));
Matthew Wilcox51219352007-10-02 21:55:22 -04009510 }
9511 eep_config->cfg_msw = AscGetChipCfgMsw(iop_base);
9512 if (write_eep) {
9513 if ((i = AscSetEEPConfig(iop_base, eep_config,
9514 asc_dvc->bus_type)) != 0) {
9515 ASC_PRINT1
9516 ("AscInitFromEEP: Failed to re-write EEPROM with %d errors.\n",
9517 i);
9518 } else {
9519 ASC_PRINT
9520 ("AscInitFromEEP: Successfully re-wrote EEPROM.\n");
9521 }
9522 }
9523 return (warn_code);
9524}
9525
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009526static int AscInitGetConfig(struct Scsi_Host *shost)
Matthew Wilcox51219352007-10-02 21:55:22 -04009527{
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009528 struct asc_board *board = shost_priv(shost);
9529 ASC_DVC_VAR *asc_dvc = &board->dvc_var.asc_dvc_var;
Matthew Wilcox51219352007-10-02 21:55:22 -04009530 unsigned short warn_code = 0;
9531
9532 asc_dvc->init_state = ASC_INIT_STATE_BEG_GET_CFG;
9533 if (asc_dvc->err_code != 0)
9534 return asc_dvc->err_code;
9535
9536 if (AscFindSignature(asc_dvc->iop_base)) {
Hannes Reineckef33134e2015-04-24 13:18:31 +02009537 AscInitAscDvcVar(asc_dvc);
9538 warn_code = AscInitFromEEP(asc_dvc);
Matthew Wilcox51219352007-10-02 21:55:22 -04009539 asc_dvc->init_state |= ASC_INIT_STATE_END_GET_CFG;
9540 if (asc_dvc->scsi_reset_wait > ASC_MAX_SCSI_RESET_WAIT)
9541 asc_dvc->scsi_reset_wait = ASC_MAX_SCSI_RESET_WAIT;
9542 } else {
9543 asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
9544 }
9545
9546 switch (warn_code) {
9547 case 0: /* No error */
9548 break;
9549 case ASC_WARN_IO_PORT_ROTATE:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009550 shost_printk(KERN_WARNING, shost, "I/O port address "
9551 "modified\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009552 break;
9553 case ASC_WARN_AUTO_CONFIG:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009554 shost_printk(KERN_WARNING, shost, "I/O port increment switch "
9555 "enabled\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009556 break;
9557 case ASC_WARN_EEPROM_CHKSUM:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009558 shost_printk(KERN_WARNING, shost, "EEPROM checksum error\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009559 break;
9560 case ASC_WARN_IRQ_MODIFIED:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009561 shost_printk(KERN_WARNING, shost, "IRQ modified\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009562 break;
9563 case ASC_WARN_CMD_QNG_CONFLICT:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009564 shost_printk(KERN_WARNING, shost, "tag queuing enabled w/o "
9565 "disconnects\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009566 break;
9567 default:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009568 shost_printk(KERN_WARNING, shost, "unknown warning: 0x%x\n",
9569 warn_code);
Matthew Wilcox51219352007-10-02 21:55:22 -04009570 break;
9571 }
9572
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009573 if (asc_dvc->err_code != 0)
9574 shost_printk(KERN_ERR, shost, "error 0x%x at init_state "
9575 "0x%x\n", asc_dvc->err_code, asc_dvc->init_state);
Matthew Wilcox51219352007-10-02 21:55:22 -04009576
9577 return asc_dvc->err_code;
9578}
9579
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009580static int AscInitSetConfig(struct pci_dev *pdev, struct Scsi_Host *shost)
Matthew Wilcox51219352007-10-02 21:55:22 -04009581{
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009582 struct asc_board *board = shost_priv(shost);
9583 ASC_DVC_VAR *asc_dvc = &board->dvc_var.asc_dvc_var;
Matthew Wilcox51219352007-10-02 21:55:22 -04009584 PortAddr iop_base = asc_dvc->iop_base;
9585 unsigned short cfg_msw;
9586 unsigned short warn_code = 0;
9587
9588 asc_dvc->init_state |= ASC_INIT_STATE_BEG_SET_CFG;
9589 if (asc_dvc->err_code != 0)
9590 return asc_dvc->err_code;
9591 if (!AscFindSignature(asc_dvc->iop_base)) {
9592 asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
9593 return asc_dvc->err_code;
9594 }
9595
9596 cfg_msw = AscGetChipCfgMsw(iop_base);
9597 if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
9598 cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
9599 warn_code |= ASC_WARN_CFG_MSW_RECOVER;
9600 AscSetChipCfgMsw(iop_base, cfg_msw);
9601 }
9602 if ((asc_dvc->cfg->cmd_qng_enabled & asc_dvc->cfg->disc_enable) !=
9603 asc_dvc->cfg->cmd_qng_enabled) {
9604 asc_dvc->cfg->disc_enable = asc_dvc->cfg->cmd_qng_enabled;
9605 warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
9606 }
9607 if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
9608 warn_code |= ASC_WARN_AUTO_CONFIG;
9609 }
Matthew Wilcox51219352007-10-02 21:55:22 -04009610#ifdef CONFIG_PCI
9611 if (asc_dvc->bus_type & ASC_IS_PCI) {
9612 cfg_msw &= 0xFFC0;
9613 AscSetChipCfgMsw(iop_base, cfg_msw);
9614 if ((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) {
9615 } else {
9616 if ((pdev->device == PCI_DEVICE_ID_ASP_1200A) ||
9617 (pdev->device == PCI_DEVICE_ID_ASP_ABP940)) {
9618 asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_IF_NOT_DWB;
9619 asc_dvc->bug_fix_cntl |=
9620 ASC_BUG_FIX_ASYN_USE_SYN;
9621 }
9622 }
9623 } else
9624#endif /* CONFIG_PCI */
9625 if (asc_dvc->bus_type == ASC_IS_ISAPNP) {
9626 if (AscGetChipVersion(iop_base, asc_dvc->bus_type)
9627 == ASC_CHIP_VER_ASYN_BUG) {
9628 asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_ASYN_USE_SYN;
9629 }
9630 }
9631 if (AscSetChipScsiID(iop_base, asc_dvc->cfg->chip_scsi_id) !=
9632 asc_dvc->cfg->chip_scsi_id) {
9633 asc_dvc->err_code |= ASC_IERR_SET_SCSI_ID;
9634 }
9635#ifdef CONFIG_ISA
9636 if (asc_dvc->bus_type & ASC_IS_ISA) {
9637 AscSetIsaDmaChannel(iop_base, asc_dvc->cfg->isa_dma_channel);
9638 AscSetIsaDmaSpeed(iop_base, asc_dvc->cfg->isa_dma_speed);
9639 }
9640#endif /* CONFIG_ISA */
9641
9642 asc_dvc->init_state |= ASC_INIT_STATE_END_SET_CFG;
9643
9644 switch (warn_code) {
9645 case 0: /* No error. */
9646 break;
9647 case ASC_WARN_IO_PORT_ROTATE:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009648 shost_printk(KERN_WARNING, shost, "I/O port address "
9649 "modified\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009650 break;
9651 case ASC_WARN_AUTO_CONFIG:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009652 shost_printk(KERN_WARNING, shost, "I/O port increment switch "
9653 "enabled\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009654 break;
9655 case ASC_WARN_EEPROM_CHKSUM:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009656 shost_printk(KERN_WARNING, shost, "EEPROM checksum error\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009657 break;
9658 case ASC_WARN_IRQ_MODIFIED:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009659 shost_printk(KERN_WARNING, shost, "IRQ modified\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009660 break;
9661 case ASC_WARN_CMD_QNG_CONFLICT:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009662 shost_printk(KERN_WARNING, shost, "tag queuing w/o "
9663 "disconnects\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009664 break;
9665 default:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009666 shost_printk(KERN_WARNING, shost, "unknown warning: 0x%x\n",
9667 warn_code);
Matthew Wilcox51219352007-10-02 21:55:22 -04009668 break;
9669 }
9670
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009671 if (asc_dvc->err_code != 0)
9672 shost_printk(KERN_ERR, shost, "error 0x%x at init_state "
9673 "0x%x\n", asc_dvc->err_code, asc_dvc->init_state);
Matthew Wilcox51219352007-10-02 21:55:22 -04009674
9675 return asc_dvc->err_code;
9676}
9677
9678/*
9679 * EEPROM Configuration.
9680 *
9681 * All drivers should use this structure to set the default EEPROM
9682 * configuration. The BIOS now uses this structure when it is built.
9683 * Additional structure information can be found in a_condor.h where
9684 * the structure is defined.
9685 *
9686 * The *_Field_IsChar structs are needed to correct for endianness.
9687 * These values are read from the board 16 bits at a time directly
9688 * into the structs. Because some fields are char, the values will be
9689 * in the wrong order. The *_Field_IsChar tells when to flip the
9690 * bytes. Data read and written to PCI memory is automatically swapped
9691 * on big-endian platforms so char fields read as words are actually being
9692 * unswapped on big-endian platforms.
9693 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009694static ADVEEP_3550_CONFIG Default_3550_EEPROM_Config = {
Matthew Wilcox51219352007-10-02 21:55:22 -04009695 ADV_EEPROM_BIOS_ENABLE, /* cfg_lsw */
9696 0x0000, /* cfg_msw */
9697 0xFFFF, /* disc_enable */
9698 0xFFFF, /* wdtr_able */
9699 0xFFFF, /* sdtr_able */
9700 0xFFFF, /* start_motor */
9701 0xFFFF, /* tagqng_able */
9702 0xFFFF, /* bios_scan */
9703 0, /* scam_tolerant */
9704 7, /* adapter_scsi_id */
9705 0, /* bios_boot_delay */
9706 3, /* scsi_reset_delay */
9707 0, /* bios_id_lun */
9708 0, /* termination */
9709 0, /* reserved1 */
9710 0xFFE7, /* bios_ctrl */
9711 0xFFFF, /* ultra_able */
9712 0, /* reserved2 */
9713 ASC_DEF_MAX_HOST_QNG, /* max_host_qng */
9714 ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
9715 0, /* dvc_cntl */
9716 0, /* bug_fix */
9717 0, /* serial_number_word1 */
9718 0, /* serial_number_word2 */
9719 0, /* serial_number_word3 */
9720 0, /* check_sum */
9721 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
9722 , /* oem_name[16] */
9723 0, /* dvc_err_code */
9724 0, /* adv_err_code */
9725 0, /* adv_err_addr */
9726 0, /* saved_dvc_err_code */
9727 0, /* saved_adv_err_code */
9728 0, /* saved_adv_err_addr */
9729 0 /* num_of_err */
9730};
9731
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009732static ADVEEP_3550_CONFIG ADVEEP_3550_Config_Field_IsChar = {
Matthew Wilcox51219352007-10-02 21:55:22 -04009733 0, /* cfg_lsw */
9734 0, /* cfg_msw */
9735 0, /* -disc_enable */
9736 0, /* wdtr_able */
9737 0, /* sdtr_able */
9738 0, /* start_motor */
9739 0, /* tagqng_able */
9740 0, /* bios_scan */
9741 0, /* scam_tolerant */
9742 1, /* adapter_scsi_id */
9743 1, /* bios_boot_delay */
9744 1, /* scsi_reset_delay */
9745 1, /* bios_id_lun */
9746 1, /* termination */
9747 1, /* reserved1 */
9748 0, /* bios_ctrl */
9749 0, /* ultra_able */
9750 0, /* reserved2 */
9751 1, /* max_host_qng */
9752 1, /* max_dvc_qng */
9753 0, /* dvc_cntl */
9754 0, /* bug_fix */
9755 0, /* serial_number_word1 */
9756 0, /* serial_number_word2 */
9757 0, /* serial_number_word3 */
9758 0, /* check_sum */
9759 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
9760 , /* oem_name[16] */
9761 0, /* dvc_err_code */
9762 0, /* adv_err_code */
9763 0, /* adv_err_addr */
9764 0, /* saved_dvc_err_code */
9765 0, /* saved_adv_err_code */
9766 0, /* saved_adv_err_addr */
9767 0 /* num_of_err */
9768};
9769
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009770static ADVEEP_38C0800_CONFIG Default_38C0800_EEPROM_Config = {
Matthew Wilcox51219352007-10-02 21:55:22 -04009771 ADV_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */
9772 0x0000, /* 01 cfg_msw */
9773 0xFFFF, /* 02 disc_enable */
9774 0xFFFF, /* 03 wdtr_able */
9775 0x4444, /* 04 sdtr_speed1 */
9776 0xFFFF, /* 05 start_motor */
9777 0xFFFF, /* 06 tagqng_able */
9778 0xFFFF, /* 07 bios_scan */
9779 0, /* 08 scam_tolerant */
9780 7, /* 09 adapter_scsi_id */
9781 0, /* bios_boot_delay */
9782 3, /* 10 scsi_reset_delay */
9783 0, /* bios_id_lun */
9784 0, /* 11 termination_se */
9785 0, /* termination_lvd */
9786 0xFFE7, /* 12 bios_ctrl */
9787 0x4444, /* 13 sdtr_speed2 */
9788 0x4444, /* 14 sdtr_speed3 */
9789 ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
9790 ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
9791 0, /* 16 dvc_cntl */
9792 0x4444, /* 17 sdtr_speed4 */
9793 0, /* 18 serial_number_word1 */
9794 0, /* 19 serial_number_word2 */
9795 0, /* 20 serial_number_word3 */
9796 0, /* 21 check_sum */
9797 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
9798 , /* 22-29 oem_name[16] */
9799 0, /* 30 dvc_err_code */
9800 0, /* 31 adv_err_code */
9801 0, /* 32 adv_err_addr */
9802 0, /* 33 saved_dvc_err_code */
9803 0, /* 34 saved_adv_err_code */
9804 0, /* 35 saved_adv_err_addr */
9805 0, /* 36 reserved */
9806 0, /* 37 reserved */
9807 0, /* 38 reserved */
9808 0, /* 39 reserved */
9809 0, /* 40 reserved */
9810 0, /* 41 reserved */
9811 0, /* 42 reserved */
9812 0, /* 43 reserved */
9813 0, /* 44 reserved */
9814 0, /* 45 reserved */
9815 0, /* 46 reserved */
9816 0, /* 47 reserved */
9817 0, /* 48 reserved */
9818 0, /* 49 reserved */
9819 0, /* 50 reserved */
9820 0, /* 51 reserved */
9821 0, /* 52 reserved */
9822 0, /* 53 reserved */
9823 0, /* 54 reserved */
9824 0, /* 55 reserved */
9825 0, /* 56 cisptr_lsw */
9826 0, /* 57 cisprt_msw */
9827 PCI_VENDOR_ID_ASP, /* 58 subsysvid */
9828 PCI_DEVICE_ID_38C0800_REV1, /* 59 subsysid */
9829 0, /* 60 reserved */
9830 0, /* 61 reserved */
9831 0, /* 62 reserved */
9832 0 /* 63 reserved */
9833};
9834
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009835static ADVEEP_38C0800_CONFIG ADVEEP_38C0800_Config_Field_IsChar = {
Matthew Wilcox51219352007-10-02 21:55:22 -04009836 0, /* 00 cfg_lsw */
9837 0, /* 01 cfg_msw */
9838 0, /* 02 disc_enable */
9839 0, /* 03 wdtr_able */
9840 0, /* 04 sdtr_speed1 */
9841 0, /* 05 start_motor */
9842 0, /* 06 tagqng_able */
9843 0, /* 07 bios_scan */
9844 0, /* 08 scam_tolerant */
9845 1, /* 09 adapter_scsi_id */
9846 1, /* bios_boot_delay */
9847 1, /* 10 scsi_reset_delay */
9848 1, /* bios_id_lun */
9849 1, /* 11 termination_se */
9850 1, /* termination_lvd */
9851 0, /* 12 bios_ctrl */
9852 0, /* 13 sdtr_speed2 */
9853 0, /* 14 sdtr_speed3 */
9854 1, /* 15 max_host_qng */
9855 1, /* max_dvc_qng */
9856 0, /* 16 dvc_cntl */
9857 0, /* 17 sdtr_speed4 */
9858 0, /* 18 serial_number_word1 */
9859 0, /* 19 serial_number_word2 */
9860 0, /* 20 serial_number_word3 */
9861 0, /* 21 check_sum */
9862 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
9863 , /* 22-29 oem_name[16] */
9864 0, /* 30 dvc_err_code */
9865 0, /* 31 adv_err_code */
9866 0, /* 32 adv_err_addr */
9867 0, /* 33 saved_dvc_err_code */
9868 0, /* 34 saved_adv_err_code */
9869 0, /* 35 saved_adv_err_addr */
9870 0, /* 36 reserved */
9871 0, /* 37 reserved */
9872 0, /* 38 reserved */
9873 0, /* 39 reserved */
9874 0, /* 40 reserved */
9875 0, /* 41 reserved */
9876 0, /* 42 reserved */
9877 0, /* 43 reserved */
9878 0, /* 44 reserved */
9879 0, /* 45 reserved */
9880 0, /* 46 reserved */
9881 0, /* 47 reserved */
9882 0, /* 48 reserved */
9883 0, /* 49 reserved */
9884 0, /* 50 reserved */
9885 0, /* 51 reserved */
9886 0, /* 52 reserved */
9887 0, /* 53 reserved */
9888 0, /* 54 reserved */
9889 0, /* 55 reserved */
9890 0, /* 56 cisptr_lsw */
9891 0, /* 57 cisprt_msw */
9892 0, /* 58 subsysvid */
9893 0, /* 59 subsysid */
9894 0, /* 60 reserved */
9895 0, /* 61 reserved */
9896 0, /* 62 reserved */
9897 0 /* 63 reserved */
9898};
9899
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009900static ADVEEP_38C1600_CONFIG Default_38C1600_EEPROM_Config = {
Matthew Wilcox51219352007-10-02 21:55:22 -04009901 ADV_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */
9902 0x0000, /* 01 cfg_msw */
9903 0xFFFF, /* 02 disc_enable */
9904 0xFFFF, /* 03 wdtr_able */
9905 0x5555, /* 04 sdtr_speed1 */
9906 0xFFFF, /* 05 start_motor */
9907 0xFFFF, /* 06 tagqng_able */
9908 0xFFFF, /* 07 bios_scan */
9909 0, /* 08 scam_tolerant */
9910 7, /* 09 adapter_scsi_id */
9911 0, /* bios_boot_delay */
9912 3, /* 10 scsi_reset_delay */
9913 0, /* bios_id_lun */
9914 0, /* 11 termination_se */
9915 0, /* termination_lvd */
9916 0xFFE7, /* 12 bios_ctrl */
9917 0x5555, /* 13 sdtr_speed2 */
9918 0x5555, /* 14 sdtr_speed3 */
9919 ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
9920 ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
9921 0, /* 16 dvc_cntl */
9922 0x5555, /* 17 sdtr_speed4 */
9923 0, /* 18 serial_number_word1 */
9924 0, /* 19 serial_number_word2 */
9925 0, /* 20 serial_number_word3 */
9926 0, /* 21 check_sum */
9927 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
9928 , /* 22-29 oem_name[16] */
9929 0, /* 30 dvc_err_code */
9930 0, /* 31 adv_err_code */
9931 0, /* 32 adv_err_addr */
9932 0, /* 33 saved_dvc_err_code */
9933 0, /* 34 saved_adv_err_code */
9934 0, /* 35 saved_adv_err_addr */
9935 0, /* 36 reserved */
9936 0, /* 37 reserved */
9937 0, /* 38 reserved */
9938 0, /* 39 reserved */
9939 0, /* 40 reserved */
9940 0, /* 41 reserved */
9941 0, /* 42 reserved */
9942 0, /* 43 reserved */
9943 0, /* 44 reserved */
9944 0, /* 45 reserved */
9945 0, /* 46 reserved */
9946 0, /* 47 reserved */
9947 0, /* 48 reserved */
9948 0, /* 49 reserved */
9949 0, /* 50 reserved */
9950 0, /* 51 reserved */
9951 0, /* 52 reserved */
9952 0, /* 53 reserved */
9953 0, /* 54 reserved */
9954 0, /* 55 reserved */
9955 0, /* 56 cisptr_lsw */
9956 0, /* 57 cisprt_msw */
9957 PCI_VENDOR_ID_ASP, /* 58 subsysvid */
9958 PCI_DEVICE_ID_38C1600_REV1, /* 59 subsysid */
9959 0, /* 60 reserved */
9960 0, /* 61 reserved */
9961 0, /* 62 reserved */
9962 0 /* 63 reserved */
9963};
9964
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009965static ADVEEP_38C1600_CONFIG ADVEEP_38C1600_Config_Field_IsChar = {
Matthew Wilcox51219352007-10-02 21:55:22 -04009966 0, /* 00 cfg_lsw */
9967 0, /* 01 cfg_msw */
9968 0, /* 02 disc_enable */
9969 0, /* 03 wdtr_able */
9970 0, /* 04 sdtr_speed1 */
9971 0, /* 05 start_motor */
9972 0, /* 06 tagqng_able */
9973 0, /* 07 bios_scan */
9974 0, /* 08 scam_tolerant */
9975 1, /* 09 adapter_scsi_id */
9976 1, /* bios_boot_delay */
9977 1, /* 10 scsi_reset_delay */
9978 1, /* bios_id_lun */
9979 1, /* 11 termination_se */
9980 1, /* termination_lvd */
9981 0, /* 12 bios_ctrl */
9982 0, /* 13 sdtr_speed2 */
9983 0, /* 14 sdtr_speed3 */
9984 1, /* 15 max_host_qng */
9985 1, /* max_dvc_qng */
9986 0, /* 16 dvc_cntl */
9987 0, /* 17 sdtr_speed4 */
9988 0, /* 18 serial_number_word1 */
9989 0, /* 19 serial_number_word2 */
9990 0, /* 20 serial_number_word3 */
9991 0, /* 21 check_sum */
9992 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
9993 , /* 22-29 oem_name[16] */
9994 0, /* 30 dvc_err_code */
9995 0, /* 31 adv_err_code */
9996 0, /* 32 adv_err_addr */
9997 0, /* 33 saved_dvc_err_code */
9998 0, /* 34 saved_adv_err_code */
9999 0, /* 35 saved_adv_err_addr */
10000 0, /* 36 reserved */
10001 0, /* 37 reserved */
10002 0, /* 38 reserved */
10003 0, /* 39 reserved */
10004 0, /* 40 reserved */
10005 0, /* 41 reserved */
10006 0, /* 42 reserved */
10007 0, /* 43 reserved */
10008 0, /* 44 reserved */
10009 0, /* 45 reserved */
10010 0, /* 46 reserved */
10011 0, /* 47 reserved */
10012 0, /* 48 reserved */
10013 0, /* 49 reserved */
10014 0, /* 50 reserved */
10015 0, /* 51 reserved */
10016 0, /* 52 reserved */
10017 0, /* 53 reserved */
10018 0, /* 54 reserved */
10019 0, /* 55 reserved */
10020 0, /* 56 cisptr_lsw */
10021 0, /* 57 cisprt_msw */
10022 0, /* 58 subsysvid */
10023 0, /* 59 subsysid */
10024 0, /* 60 reserved */
10025 0, /* 61 reserved */
10026 0, /* 62 reserved */
10027 0 /* 63 reserved */
10028};
10029
10030#ifdef CONFIG_PCI
10031/*
10032 * Wait for EEPROM command to complete
10033 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010034static void AdvWaitEEPCmd(AdvPortAddr iop_base)
Matthew Wilcox51219352007-10-02 21:55:22 -040010035{
10036 int eep_delay_ms;
10037
10038 for (eep_delay_ms = 0; eep_delay_ms < ADV_EEP_DELAY_MS; eep_delay_ms++) {
10039 if (AdvReadWordRegister(iop_base, IOPW_EE_CMD) &
10040 ASC_EEP_CMD_DONE) {
10041 break;
10042 }
10043 mdelay(1);
10044 }
10045 if ((AdvReadWordRegister(iop_base, IOPW_EE_CMD) & ASC_EEP_CMD_DONE) ==
10046 0)
10047 BUG();
10048}
10049
10050/*
10051 * Read the EEPROM from specified location
10052 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010053static ushort AdvReadEEPWord(AdvPortAddr iop_base, int eep_word_addr)
Matthew Wilcox51219352007-10-02 21:55:22 -040010054{
10055 AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
10056 ASC_EEP_CMD_READ | eep_word_addr);
10057 AdvWaitEEPCmd(iop_base);
10058 return AdvReadWordRegister(iop_base, IOPW_EE_DATA);
10059}
10060
10061/*
10062 * Write the EEPROM from 'cfg_buf'.
10063 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010064static void AdvSet3550EEPConfig(AdvPortAddr iop_base,
10065 ADVEEP_3550_CONFIG *cfg_buf)
Matthew Wilcox51219352007-10-02 21:55:22 -040010066{
10067 ushort *wbuf;
10068 ushort addr, chksum;
10069 ushort *charfields;
10070
10071 wbuf = (ushort *)cfg_buf;
10072 charfields = (ushort *)&ADVEEP_3550_Config_Field_IsChar;
10073 chksum = 0;
10074
10075 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
10076 AdvWaitEEPCmd(iop_base);
10077
10078 /*
10079 * Write EEPROM from word 0 to word 20.
10080 */
10081 for (addr = ADV_EEP_DVC_CFG_BEGIN;
10082 addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
10083 ushort word;
10084
10085 if (*charfields++) {
10086 word = cpu_to_le16(*wbuf);
10087 } else {
10088 word = *wbuf;
10089 }
10090 chksum += *wbuf; /* Checksum is calculated from word values. */
10091 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
10092 AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
10093 ASC_EEP_CMD_WRITE | addr);
10094 AdvWaitEEPCmd(iop_base);
10095 mdelay(ADV_EEP_DELAY_MS);
10096 }
10097
10098 /*
10099 * Write EEPROM checksum at word 21.
10100 */
10101 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
10102 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
10103 AdvWaitEEPCmd(iop_base);
10104 wbuf++;
10105 charfields++;
10106
10107 /*
10108 * Write EEPROM OEM name at words 22 to 29.
10109 */
10110 for (addr = ADV_EEP_DVC_CTL_BEGIN;
10111 addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
10112 ushort word;
10113
10114 if (*charfields++) {
10115 word = cpu_to_le16(*wbuf);
10116 } else {
10117 word = *wbuf;
10118 }
10119 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
10120 AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
10121 ASC_EEP_CMD_WRITE | addr);
10122 AdvWaitEEPCmd(iop_base);
10123 }
10124 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
10125 AdvWaitEEPCmd(iop_base);
10126}
10127
10128/*
10129 * Write the EEPROM from 'cfg_buf'.
10130 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010131static void AdvSet38C0800EEPConfig(AdvPortAddr iop_base,
10132 ADVEEP_38C0800_CONFIG *cfg_buf)
Matthew Wilcox51219352007-10-02 21:55:22 -040010133{
10134 ushort *wbuf;
10135 ushort *charfields;
10136 ushort addr, chksum;
10137
10138 wbuf = (ushort *)cfg_buf;
10139 charfields = (ushort *)&ADVEEP_38C0800_Config_Field_IsChar;
10140 chksum = 0;
10141
10142 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
10143 AdvWaitEEPCmd(iop_base);
10144
10145 /*
10146 * Write EEPROM from word 0 to word 20.
10147 */
10148 for (addr = ADV_EEP_DVC_CFG_BEGIN;
10149 addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
10150 ushort word;
10151
10152 if (*charfields++) {
10153 word = cpu_to_le16(*wbuf);
10154 } else {
10155 word = *wbuf;
10156 }
10157 chksum += *wbuf; /* Checksum is calculated from word values. */
10158 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
10159 AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
10160 ASC_EEP_CMD_WRITE | addr);
10161 AdvWaitEEPCmd(iop_base);
10162 mdelay(ADV_EEP_DELAY_MS);
10163 }
10164
10165 /*
10166 * Write EEPROM checksum at word 21.
10167 */
10168 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
10169 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
10170 AdvWaitEEPCmd(iop_base);
10171 wbuf++;
10172 charfields++;
10173
10174 /*
10175 * Write EEPROM OEM name at words 22 to 29.
10176 */
10177 for (addr = ADV_EEP_DVC_CTL_BEGIN;
10178 addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
10179 ushort word;
10180
10181 if (*charfields++) {
10182 word = cpu_to_le16(*wbuf);
10183 } else {
10184 word = *wbuf;
10185 }
10186 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
10187 AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
10188 ASC_EEP_CMD_WRITE | addr);
10189 AdvWaitEEPCmd(iop_base);
10190 }
10191 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
10192 AdvWaitEEPCmd(iop_base);
10193}
10194
10195/*
10196 * Write the EEPROM from 'cfg_buf'.
10197 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010198static void AdvSet38C1600EEPConfig(AdvPortAddr iop_base,
10199 ADVEEP_38C1600_CONFIG *cfg_buf)
Matthew Wilcox51219352007-10-02 21:55:22 -040010200{
10201 ushort *wbuf;
10202 ushort *charfields;
10203 ushort addr, chksum;
10204
10205 wbuf = (ushort *)cfg_buf;
10206 charfields = (ushort *)&ADVEEP_38C1600_Config_Field_IsChar;
10207 chksum = 0;
10208
10209 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
10210 AdvWaitEEPCmd(iop_base);
10211
10212 /*
10213 * Write EEPROM from word 0 to word 20.
10214 */
10215 for (addr = ADV_EEP_DVC_CFG_BEGIN;
10216 addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
10217 ushort word;
10218
10219 if (*charfields++) {
10220 word = cpu_to_le16(*wbuf);
10221 } else {
10222 word = *wbuf;
10223 }
10224 chksum += *wbuf; /* Checksum is calculated from word values. */
10225 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
10226 AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
10227 ASC_EEP_CMD_WRITE | addr);
10228 AdvWaitEEPCmd(iop_base);
10229 mdelay(ADV_EEP_DELAY_MS);
10230 }
10231
10232 /*
10233 * Write EEPROM checksum at word 21.
10234 */
10235 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
10236 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
10237 AdvWaitEEPCmd(iop_base);
10238 wbuf++;
10239 charfields++;
10240
10241 /*
10242 * Write EEPROM OEM name at words 22 to 29.
10243 */
10244 for (addr = ADV_EEP_DVC_CTL_BEGIN;
10245 addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
10246 ushort word;
10247
10248 if (*charfields++) {
10249 word = cpu_to_le16(*wbuf);
10250 } else {
10251 word = *wbuf;
10252 }
10253 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
10254 AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
10255 ASC_EEP_CMD_WRITE | addr);
10256 AdvWaitEEPCmd(iop_base);
10257 }
10258 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
10259 AdvWaitEEPCmd(iop_base);
10260}
10261
10262/*
10263 * Read EEPROM configuration into the specified buffer.
10264 *
10265 * Return a checksum based on the EEPROM configuration read.
10266 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010267static ushort AdvGet3550EEPConfig(AdvPortAddr iop_base,
10268 ADVEEP_3550_CONFIG *cfg_buf)
Matthew Wilcox51219352007-10-02 21:55:22 -040010269{
10270 ushort wval, chksum;
10271 ushort *wbuf;
10272 int eep_addr;
10273 ushort *charfields;
10274
10275 charfields = (ushort *)&ADVEEP_3550_Config_Field_IsChar;
10276 wbuf = (ushort *)cfg_buf;
10277 chksum = 0;
10278
10279 for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
10280 eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
10281 wval = AdvReadEEPWord(iop_base, eep_addr);
10282 chksum += wval; /* Checksum is calculated from word values. */
10283 if (*charfields++) {
10284 *wbuf = le16_to_cpu(wval);
10285 } else {
10286 *wbuf = wval;
10287 }
10288 }
10289 /* Read checksum word. */
10290 *wbuf = AdvReadEEPWord(iop_base, eep_addr);
10291 wbuf++;
10292 charfields++;
10293
10294 /* Read rest of EEPROM not covered by the checksum. */
10295 for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
10296 eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
10297 *wbuf = AdvReadEEPWord(iop_base, eep_addr);
10298 if (*charfields++) {
10299 *wbuf = le16_to_cpu(*wbuf);
10300 }
10301 }
10302 return chksum;
10303}
10304
10305/*
10306 * Read EEPROM configuration into the specified buffer.
10307 *
10308 * Return a checksum based on the EEPROM configuration read.
10309 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010310static ushort AdvGet38C0800EEPConfig(AdvPortAddr iop_base,
10311 ADVEEP_38C0800_CONFIG *cfg_buf)
Matthew Wilcox51219352007-10-02 21:55:22 -040010312{
10313 ushort wval, chksum;
10314 ushort *wbuf;
10315 int eep_addr;
10316 ushort *charfields;
10317
10318 charfields = (ushort *)&ADVEEP_38C0800_Config_Field_IsChar;
10319 wbuf = (ushort *)cfg_buf;
10320 chksum = 0;
10321
10322 for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
10323 eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
10324 wval = AdvReadEEPWord(iop_base, eep_addr);
10325 chksum += wval; /* Checksum is calculated from word values. */
10326 if (*charfields++) {
10327 *wbuf = le16_to_cpu(wval);
10328 } else {
10329 *wbuf = wval;
10330 }
10331 }
10332 /* Read checksum word. */
10333 *wbuf = AdvReadEEPWord(iop_base, eep_addr);
10334 wbuf++;
10335 charfields++;
10336
10337 /* Read rest of EEPROM not covered by the checksum. */
10338 for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
10339 eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
10340 *wbuf = AdvReadEEPWord(iop_base, eep_addr);
10341 if (*charfields++) {
10342 *wbuf = le16_to_cpu(*wbuf);
10343 }
10344 }
10345 return chksum;
10346}
10347
10348/*
10349 * Read EEPROM configuration into the specified buffer.
10350 *
10351 * Return a checksum based on the EEPROM configuration read.
10352 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010353static ushort AdvGet38C1600EEPConfig(AdvPortAddr iop_base,
10354 ADVEEP_38C1600_CONFIG *cfg_buf)
Matthew Wilcox51219352007-10-02 21:55:22 -040010355{
10356 ushort wval, chksum;
10357 ushort *wbuf;
10358 int eep_addr;
10359 ushort *charfields;
10360
10361 charfields = (ushort *)&ADVEEP_38C1600_Config_Field_IsChar;
10362 wbuf = (ushort *)cfg_buf;
10363 chksum = 0;
10364
10365 for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
10366 eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
10367 wval = AdvReadEEPWord(iop_base, eep_addr);
10368 chksum += wval; /* Checksum is calculated from word values. */
10369 if (*charfields++) {
10370 *wbuf = le16_to_cpu(wval);
10371 } else {
10372 *wbuf = wval;
10373 }
10374 }
10375 /* Read checksum word. */
10376 *wbuf = AdvReadEEPWord(iop_base, eep_addr);
10377 wbuf++;
10378 charfields++;
10379
10380 /* Read rest of EEPROM not covered by the checksum. */
10381 for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
10382 eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
10383 *wbuf = AdvReadEEPWord(iop_base, eep_addr);
10384 if (*charfields++) {
10385 *wbuf = le16_to_cpu(*wbuf);
10386 }
10387 }
10388 return chksum;
10389}
10390
10391/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070010392 * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
10393 * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
10394 * all of this is done.
10395 *
10396 * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
10397 *
10398 * For a non-fatal error return a warning code. If there are no warnings
10399 * then 0 is returned.
10400 *
10401 * Note: Chip is stopped on entry.
10402 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010403static int AdvInitFrom3550EEP(ADV_DVC_VAR *asc_dvc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070010404{
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010405 AdvPortAddr iop_base;
10406 ushort warn_code;
10407 ADVEEP_3550_CONFIG eep_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010408
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010409 iop_base = asc_dvc->iop_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010410
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010411 warn_code = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010412
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010413 /*
10414 * Read the board's EEPROM configuration.
10415 *
10416 * Set default values if a bad checksum is found.
10417 */
10418 if (AdvGet3550EEPConfig(iop_base, &eep_config) != eep_config.check_sum) {
10419 warn_code |= ASC_WARN_EEPROM_CHKSUM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010420
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010421 /*
10422 * Set EEPROM default values.
10423 */
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010424 memcpy(&eep_config, &Default_3550_EEPROM_Config,
10425 sizeof(ADVEEP_3550_CONFIG));
Linus Torvalds1da177e2005-04-16 15:20:36 -070010426
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010427 /*
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010428 * Assume the 6 byte board serial number that was read from
10429 * EEPROM is correct even if the EEPROM checksum failed.
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010430 */
10431 eep_config.serial_number_word3 =
10432 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010433
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010434 eep_config.serial_number_word2 =
10435 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010436
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010437 eep_config.serial_number_word1 =
10438 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010439
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010440 AdvSet3550EEPConfig(iop_base, &eep_config);
10441 }
10442 /*
10443 * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
10444 * EEPROM configuration that was read.
10445 *
10446 * This is the mapping of EEPROM fields to Adv Library fields.
10447 */
10448 asc_dvc->wdtr_able = eep_config.wdtr_able;
10449 asc_dvc->sdtr_able = eep_config.sdtr_able;
10450 asc_dvc->ultra_able = eep_config.ultra_able;
10451 asc_dvc->tagqng_able = eep_config.tagqng_able;
10452 asc_dvc->cfg->disc_enable = eep_config.disc_enable;
10453 asc_dvc->max_host_qng = eep_config.max_host_qng;
10454 asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
10455 asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
10456 asc_dvc->start_motor = eep_config.start_motor;
10457 asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
10458 asc_dvc->bios_ctrl = eep_config.bios_ctrl;
10459 asc_dvc->no_scam = eep_config.scam_tolerant;
10460 asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
10461 asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
10462 asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010463
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010464 /*
10465 * Set the host maximum queuing (max. 253, min. 16) and the per device
10466 * maximum queuing (max. 63, min. 4).
10467 */
10468 if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
10469 eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
10470 } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
10471 /* If the value is zero, assume it is uninitialized. */
10472 if (eep_config.max_host_qng == 0) {
10473 eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
10474 } else {
10475 eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
10476 }
10477 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010478
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010479 if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
10480 eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
10481 } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
10482 /* If the value is zero, assume it is uninitialized. */
10483 if (eep_config.max_dvc_qng == 0) {
10484 eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
10485 } else {
10486 eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
10487 }
10488 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010489
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010490 /*
10491 * If 'max_dvc_qng' is greater than 'max_host_qng', then
10492 * set 'max_dvc_qng' to 'max_host_qng'.
10493 */
10494 if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
10495 eep_config.max_dvc_qng = eep_config.max_host_qng;
10496 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010497
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010498 /*
10499 * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
10500 * values based on possibly adjusted EEPROM values.
10501 */
10502 asc_dvc->max_host_qng = eep_config.max_host_qng;
10503 asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010504
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010505 /*
10506 * If the EEPROM 'termination' field is set to automatic (0), then set
10507 * the ADV_DVC_CFG 'termination' field to automatic also.
10508 *
10509 * If the termination is specified with a non-zero 'termination'
10510 * value check that a legal value is set and set the ADV_DVC_CFG
10511 * 'termination' field appropriately.
10512 */
10513 if (eep_config.termination == 0) {
10514 asc_dvc->cfg->termination = 0; /* auto termination */
10515 } else {
10516 /* Enable manual control with low off / high off. */
10517 if (eep_config.termination == 1) {
10518 asc_dvc->cfg->termination = TERM_CTL_SEL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010519
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010520 /* Enable manual control with low off / high on. */
10521 } else if (eep_config.termination == 2) {
10522 asc_dvc->cfg->termination = TERM_CTL_SEL | TERM_CTL_H;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010523
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010524 /* Enable manual control with low on / high on. */
10525 } else if (eep_config.termination == 3) {
10526 asc_dvc->cfg->termination =
10527 TERM_CTL_SEL | TERM_CTL_H | TERM_CTL_L;
10528 } else {
10529 /*
10530 * The EEPROM 'termination' field contains a bad value. Use
10531 * automatic termination instead.
10532 */
10533 asc_dvc->cfg->termination = 0;
10534 warn_code |= ASC_WARN_EEPROM_TERMINATION;
10535 }
10536 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010537
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010538 return warn_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010539}
10540
10541/*
10542 * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
10543 * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
10544 * all of this is done.
10545 *
10546 * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
10547 *
10548 * For a non-fatal error return a warning code. If there are no warnings
10549 * then 0 is returned.
10550 *
10551 * Note: Chip is stopped on entry.
10552 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010553static int AdvInitFrom38C0800EEP(ADV_DVC_VAR *asc_dvc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070010554{
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010555 AdvPortAddr iop_base;
10556 ushort warn_code;
10557 ADVEEP_38C0800_CONFIG eep_config;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010558 uchar tid, termination;
10559 ushort sdtr_speed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010560
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010561 iop_base = asc_dvc->iop_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010562
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010563 warn_code = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010564
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010565 /*
10566 * Read the board's EEPROM configuration.
10567 *
10568 * Set default values if a bad checksum is found.
10569 */
10570 if (AdvGet38C0800EEPConfig(iop_base, &eep_config) !=
10571 eep_config.check_sum) {
10572 warn_code |= ASC_WARN_EEPROM_CHKSUM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010573
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010574 /*
10575 * Set EEPROM default values.
10576 */
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010577 memcpy(&eep_config, &Default_38C0800_EEPROM_Config,
10578 sizeof(ADVEEP_38C0800_CONFIG));
Linus Torvalds1da177e2005-04-16 15:20:36 -070010579
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010580 /*
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010581 * Assume the 6 byte board serial number that was read from
10582 * EEPROM is correct even if the EEPROM checksum failed.
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010583 */
10584 eep_config.serial_number_word3 =
10585 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010586
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010587 eep_config.serial_number_word2 =
10588 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010589
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010590 eep_config.serial_number_word1 =
10591 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010592
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010593 AdvSet38C0800EEPConfig(iop_base, &eep_config);
10594 }
10595 /*
10596 * Set ADV_DVC_VAR and ADV_DVC_CFG variables from the
10597 * EEPROM configuration that was read.
10598 *
10599 * This is the mapping of EEPROM fields to Adv Library fields.
10600 */
10601 asc_dvc->wdtr_able = eep_config.wdtr_able;
10602 asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
10603 asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
10604 asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
10605 asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
10606 asc_dvc->tagqng_able = eep_config.tagqng_able;
10607 asc_dvc->cfg->disc_enable = eep_config.disc_enable;
10608 asc_dvc->max_host_qng = eep_config.max_host_qng;
10609 asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
10610 asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
10611 asc_dvc->start_motor = eep_config.start_motor;
10612 asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
10613 asc_dvc->bios_ctrl = eep_config.bios_ctrl;
10614 asc_dvc->no_scam = eep_config.scam_tolerant;
10615 asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
10616 asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
10617 asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010618
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010619 /*
10620 * For every Target ID if any of its 'sdtr_speed[1234]' bits
10621 * are set, then set an 'sdtr_able' bit for it.
10622 */
10623 asc_dvc->sdtr_able = 0;
10624 for (tid = 0; tid <= ADV_MAX_TID; tid++) {
10625 if (tid == 0) {
10626 sdtr_speed = asc_dvc->sdtr_speed1;
10627 } else if (tid == 4) {
10628 sdtr_speed = asc_dvc->sdtr_speed2;
10629 } else if (tid == 8) {
10630 sdtr_speed = asc_dvc->sdtr_speed3;
10631 } else if (tid == 12) {
10632 sdtr_speed = asc_dvc->sdtr_speed4;
10633 }
10634 if (sdtr_speed & ADV_MAX_TID) {
10635 asc_dvc->sdtr_able |= (1 << tid);
10636 }
10637 sdtr_speed >>= 4;
10638 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010639
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010640 /*
10641 * Set the host maximum queuing (max. 253, min. 16) and the per device
10642 * maximum queuing (max. 63, min. 4).
10643 */
10644 if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
10645 eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
10646 } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
10647 /* If the value is zero, assume it is uninitialized. */
10648 if (eep_config.max_host_qng == 0) {
10649 eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
10650 } else {
10651 eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
10652 }
10653 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010654
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010655 if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
10656 eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
10657 } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
10658 /* If the value is zero, assume it is uninitialized. */
10659 if (eep_config.max_dvc_qng == 0) {
10660 eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
10661 } else {
10662 eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
10663 }
10664 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010665
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010666 /*
10667 * If 'max_dvc_qng' is greater than 'max_host_qng', then
10668 * set 'max_dvc_qng' to 'max_host_qng'.
10669 */
10670 if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
10671 eep_config.max_dvc_qng = eep_config.max_host_qng;
10672 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010673
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010674 /*
10675 * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
10676 * values based on possibly adjusted EEPROM values.
10677 */
10678 asc_dvc->max_host_qng = eep_config.max_host_qng;
10679 asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010680
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010681 /*
10682 * If the EEPROM 'termination' field is set to automatic (0), then set
10683 * the ADV_DVC_CFG 'termination' field to automatic also.
10684 *
10685 * If the termination is specified with a non-zero 'termination'
10686 * value check that a legal value is set and set the ADV_DVC_CFG
10687 * 'termination' field appropriately.
10688 */
10689 if (eep_config.termination_se == 0) {
10690 termination = 0; /* auto termination for SE */
10691 } else {
10692 /* Enable manual control with low off / high off. */
10693 if (eep_config.termination_se == 1) {
10694 termination = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010695
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010696 /* Enable manual control with low off / high on. */
10697 } else if (eep_config.termination_se == 2) {
10698 termination = TERM_SE_HI;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010699
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010700 /* Enable manual control with low on / high on. */
10701 } else if (eep_config.termination_se == 3) {
10702 termination = TERM_SE;
10703 } else {
10704 /*
10705 * The EEPROM 'termination_se' field contains a bad value.
10706 * Use automatic termination instead.
10707 */
10708 termination = 0;
10709 warn_code |= ASC_WARN_EEPROM_TERMINATION;
10710 }
10711 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010712
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010713 if (eep_config.termination_lvd == 0) {
10714 asc_dvc->cfg->termination = termination; /* auto termination for LVD */
10715 } else {
10716 /* Enable manual control with low off / high off. */
10717 if (eep_config.termination_lvd == 1) {
10718 asc_dvc->cfg->termination = termination;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010719
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010720 /* Enable manual control with low off / high on. */
10721 } else if (eep_config.termination_lvd == 2) {
10722 asc_dvc->cfg->termination = termination | TERM_LVD_HI;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010723
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010724 /* Enable manual control with low on / high on. */
10725 } else if (eep_config.termination_lvd == 3) {
10726 asc_dvc->cfg->termination = termination | TERM_LVD;
10727 } else {
10728 /*
10729 * The EEPROM 'termination_lvd' field contains a bad value.
10730 * Use automatic termination instead.
10731 */
10732 asc_dvc->cfg->termination = termination;
10733 warn_code |= ASC_WARN_EEPROM_TERMINATION;
10734 }
10735 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010736
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010737 return warn_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010738}
10739
10740/*
10741 * Read the board's EEPROM configuration. Set fields in ASC_DVC_VAR and
10742 * ASC_DVC_CFG based on the EEPROM settings. The chip is stopped while
10743 * all of this is done.
10744 *
10745 * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
10746 *
10747 * For a non-fatal error return a warning code. If there are no warnings
10748 * then 0 is returned.
10749 *
10750 * Note: Chip is stopped on entry.
10751 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010752static int AdvInitFrom38C1600EEP(ADV_DVC_VAR *asc_dvc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070010753{
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010754 AdvPortAddr iop_base;
10755 ushort warn_code;
10756 ADVEEP_38C1600_CONFIG eep_config;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010757 uchar tid, termination;
10758 ushort sdtr_speed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010759
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010760 iop_base = asc_dvc->iop_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010761
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010762 warn_code = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010763
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010764 /*
10765 * Read the board's EEPROM configuration.
10766 *
10767 * Set default values if a bad checksum is found.
10768 */
10769 if (AdvGet38C1600EEPConfig(iop_base, &eep_config) !=
10770 eep_config.check_sum) {
Matthew Wilcox13ac2d92007-07-30 08:10:23 -060010771 struct pci_dev *pdev = adv_dvc_to_pdev(asc_dvc);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010772 warn_code |= ASC_WARN_EEPROM_CHKSUM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010773
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010774 /*
10775 * Set EEPROM default values.
10776 */
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010777 memcpy(&eep_config, &Default_38C1600_EEPROM_Config,
10778 sizeof(ADVEEP_38C1600_CONFIG));
Linus Torvalds1da177e2005-04-16 15:20:36 -070010779
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010780 if (PCI_FUNC(pdev->devfn) != 0) {
10781 u8 ints;
10782 /*
10783 * Disable Bit 14 (BIOS_ENABLE) to fix SPARC Ultra 60
10784 * and old Mac system booting problem. The Expansion
10785 * ROM must be disabled in Function 1 for these systems
10786 */
10787 eep_config.cfg_lsw &= ~ADV_EEPROM_BIOS_ENABLE;
10788 /*
10789 * Clear the INTAB (bit 11) if the GPIO 0 input
10790 * indicates the Function 1 interrupt line is wired
10791 * to INTB.
10792 *
10793 * Set/Clear Bit 11 (INTAB) from the GPIO bit 0 input:
10794 * 1 - Function 1 interrupt line wired to INT A.
10795 * 0 - Function 1 interrupt line wired to INT B.
10796 *
10797 * Note: Function 0 is always wired to INTA.
10798 * Put all 5 GPIO bits in input mode and then read
10799 * their input values.
10800 */
10801 AdvWriteByteRegister(iop_base, IOPB_GPIO_CNTL, 0);
10802 ints = AdvReadByteRegister(iop_base, IOPB_GPIO_DATA);
10803 if ((ints & 0x01) == 0)
10804 eep_config.cfg_lsw &= ~ADV_EEPROM_INTAB;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010805 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010806
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010807 /*
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010808 * Assume the 6 byte board serial number that was read from
10809 * EEPROM is correct even if the EEPROM checksum failed.
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010810 */
10811 eep_config.serial_number_word3 =
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010812 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010813 eep_config.serial_number_word2 =
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010814 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010815 eep_config.serial_number_word1 =
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010816 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010817
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010818 AdvSet38C1600EEPConfig(iop_base, &eep_config);
10819 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010820
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010821 /*
10822 * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
10823 * EEPROM configuration that was read.
10824 *
10825 * This is the mapping of EEPROM fields to Adv Library fields.
10826 */
10827 asc_dvc->wdtr_able = eep_config.wdtr_able;
10828 asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
10829 asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
10830 asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
10831 asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
10832 asc_dvc->ppr_able = 0;
10833 asc_dvc->tagqng_able = eep_config.tagqng_able;
10834 asc_dvc->cfg->disc_enable = eep_config.disc_enable;
10835 asc_dvc->max_host_qng = eep_config.max_host_qng;
10836 asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
10837 asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ASC_MAX_TID);
10838 asc_dvc->start_motor = eep_config.start_motor;
10839 asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
10840 asc_dvc->bios_ctrl = eep_config.bios_ctrl;
10841 asc_dvc->no_scam = eep_config.scam_tolerant;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010842
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010843 /*
10844 * For every Target ID if any of its 'sdtr_speed[1234]' bits
10845 * are set, then set an 'sdtr_able' bit for it.
10846 */
10847 asc_dvc->sdtr_able = 0;
10848 for (tid = 0; tid <= ASC_MAX_TID; tid++) {
10849 if (tid == 0) {
10850 sdtr_speed = asc_dvc->sdtr_speed1;
10851 } else if (tid == 4) {
10852 sdtr_speed = asc_dvc->sdtr_speed2;
10853 } else if (tid == 8) {
10854 sdtr_speed = asc_dvc->sdtr_speed3;
10855 } else if (tid == 12) {
10856 sdtr_speed = asc_dvc->sdtr_speed4;
10857 }
10858 if (sdtr_speed & ASC_MAX_TID) {
10859 asc_dvc->sdtr_able |= (1 << tid);
10860 }
10861 sdtr_speed >>= 4;
10862 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010863
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010864 /*
10865 * Set the host maximum queuing (max. 253, min. 16) and the per device
10866 * maximum queuing (max. 63, min. 4).
10867 */
10868 if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
10869 eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
10870 } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
10871 /* If the value is zero, assume it is uninitialized. */
10872 if (eep_config.max_host_qng == 0) {
10873 eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
10874 } else {
10875 eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
10876 }
10877 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010878
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010879 if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
10880 eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
10881 } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
10882 /* If the value is zero, assume it is uninitialized. */
10883 if (eep_config.max_dvc_qng == 0) {
10884 eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
10885 } else {
10886 eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
10887 }
10888 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010889
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010890 /*
10891 * If 'max_dvc_qng' is greater than 'max_host_qng', then
10892 * set 'max_dvc_qng' to 'max_host_qng'.
10893 */
10894 if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
10895 eep_config.max_dvc_qng = eep_config.max_host_qng;
10896 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010897
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010898 /*
10899 * Set ASC_DVC_VAR 'max_host_qng' and ASC_DVC_VAR 'max_dvc_qng'
10900 * values based on possibly adjusted EEPROM values.
10901 */
10902 asc_dvc->max_host_qng = eep_config.max_host_qng;
10903 asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010904
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010905 /*
10906 * If the EEPROM 'termination' field is set to automatic (0), then set
10907 * the ASC_DVC_CFG 'termination' field to automatic also.
10908 *
10909 * If the termination is specified with a non-zero 'termination'
10910 * value check that a legal value is set and set the ASC_DVC_CFG
10911 * 'termination' field appropriately.
10912 */
10913 if (eep_config.termination_se == 0) {
10914 termination = 0; /* auto termination for SE */
10915 } else {
10916 /* Enable manual control with low off / high off. */
10917 if (eep_config.termination_se == 1) {
10918 termination = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010919
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010920 /* Enable manual control with low off / high on. */
10921 } else if (eep_config.termination_se == 2) {
10922 termination = TERM_SE_HI;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010923
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010924 /* Enable manual control with low on / high on. */
10925 } else if (eep_config.termination_se == 3) {
10926 termination = TERM_SE;
10927 } else {
10928 /*
10929 * The EEPROM 'termination_se' field contains a bad value.
10930 * Use automatic termination instead.
10931 */
10932 termination = 0;
10933 warn_code |= ASC_WARN_EEPROM_TERMINATION;
10934 }
10935 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010936
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010937 if (eep_config.termination_lvd == 0) {
10938 asc_dvc->cfg->termination = termination; /* auto termination for LVD */
10939 } else {
10940 /* Enable manual control with low off / high off. */
10941 if (eep_config.termination_lvd == 1) {
10942 asc_dvc->cfg->termination = termination;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010943
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010944 /* Enable manual control with low off / high on. */
10945 } else if (eep_config.termination_lvd == 2) {
10946 asc_dvc->cfg->termination = termination | TERM_LVD_HI;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010947
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010948 /* Enable manual control with low on / high on. */
10949 } else if (eep_config.termination_lvd == 3) {
10950 asc_dvc->cfg->termination = termination | TERM_LVD;
10951 } else {
10952 /*
10953 * The EEPROM 'termination_lvd' field contains a bad value.
10954 * Use automatic termination instead.
10955 */
10956 asc_dvc->cfg->termination = termination;
10957 warn_code |= ASC_WARN_EEPROM_TERMINATION;
10958 }
10959 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010960
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010961 return warn_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010962}
10963
10964/*
Matthew Wilcox51219352007-10-02 21:55:22 -040010965 * Initialize the ADV_DVC_VAR structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010966 *
Matthew Wilcox51219352007-10-02 21:55:22 -040010967 * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010968 *
Matthew Wilcox51219352007-10-02 21:55:22 -040010969 * For a non-fatal error return a warning code. If there are no warnings
10970 * then 0 is returned.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010971 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010972static int AdvInitGetConfig(struct pci_dev *pdev, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -070010973{
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040010974 struct asc_board *board = shost_priv(shost);
10975 ADV_DVC_VAR *asc_dvc = &board->dvc_var.adv_dvc_var;
Matthew Wilcox51219352007-10-02 21:55:22 -040010976 unsigned short warn_code = 0;
10977 AdvPortAddr iop_base = asc_dvc->iop_base;
10978 u16 cmd;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010979 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010980
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010981 asc_dvc->err_code = 0;
Matthew Wilcox51219352007-10-02 21:55:22 -040010982
10983 /*
10984 * Save the state of the PCI Configuration Command Register
10985 * "Parity Error Response Control" Bit. If the bit is clear (0),
10986 * in AdvInitAsc3550/38C0800Driver() tell the microcode to ignore
10987 * DMA parity errors.
10988 */
10989 asc_dvc->cfg->control_flag = 0;
10990 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
10991 if ((cmd & PCI_COMMAND_PARITY) == 0)
10992 asc_dvc->cfg->control_flag |= CONTROL_FLAG_IGNORE_PERR;
10993
Matthew Wilcox51219352007-10-02 21:55:22 -040010994 asc_dvc->cfg->chip_version =
10995 AdvGetChipVersion(iop_base, asc_dvc->bus_type);
10996
Matthew Wilcoxb352f922007-10-02 21:55:33 -040010997 ASC_DBG(1, "iopb_chip_id_1: 0x%x 0x%x\n",
Matthew Wilcox51219352007-10-02 21:55:22 -040010998 (ushort)AdvReadByteRegister(iop_base, IOPB_CHIP_ID_1),
10999 (ushort)ADV_CHIP_ID_BYTE);
11000
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011001 ASC_DBG(1, "iopw_chip_id_0: 0x%x 0x%x\n",
Matthew Wilcox51219352007-10-02 21:55:22 -040011002 (ushort)AdvReadWordRegister(iop_base, IOPW_CHIP_ID_0),
11003 (ushort)ADV_CHIP_ID_WORD);
11004
11005 /*
11006 * Reset the chip to start and allow register writes.
11007 */
11008 if (AdvFindSignature(iop_base) == 0) {
11009 asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
11010 return ADV_ERROR;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011011 } else {
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011012 /*
Matthew Wilcox51219352007-10-02 21:55:22 -040011013 * The caller must set 'chip_type' to a valid setting.
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011014 */
Matthew Wilcox51219352007-10-02 21:55:22 -040011015 if (asc_dvc->chip_type != ADV_CHIP_ASC3550 &&
11016 asc_dvc->chip_type != ADV_CHIP_ASC38C0800 &&
11017 asc_dvc->chip_type != ADV_CHIP_ASC38C1600) {
11018 asc_dvc->err_code |= ASC_IERR_BAD_CHIPTYPE;
11019 return ADV_ERROR;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011020 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070011021
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011022 /*
Matthew Wilcox51219352007-10-02 21:55:22 -040011023 * Reset Chip.
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011024 */
Matthew Wilcox51219352007-10-02 21:55:22 -040011025 AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
11026 ADV_CTRL_REG_CMD_RESET);
11027 mdelay(100);
11028 AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
11029 ADV_CTRL_REG_CMD_WR_IO_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -070011030
Matthew Wilcox51219352007-10-02 21:55:22 -040011031 if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
11032 status = AdvInitFrom38C1600EEP(asc_dvc);
11033 } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
11034 status = AdvInitFrom38C0800EEP(asc_dvc);
11035 } else {
11036 status = AdvInitFrom3550EEP(asc_dvc);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011037 }
Matthew Wilcox51219352007-10-02 21:55:22 -040011038 warn_code |= status;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011039 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070011040
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011041 if (warn_code != 0)
11042 shost_printk(KERN_WARNING, shost, "warning: 0x%x\n", warn_code);
Matthew Wilcox51219352007-10-02 21:55:22 -040011043
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011044 if (asc_dvc->err_code)
11045 shost_printk(KERN_ERR, shost, "error code 0x%x\n",
11046 asc_dvc->err_code);
Matthew Wilcox51219352007-10-02 21:55:22 -040011047
11048 return asc_dvc->err_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -070011049}
Matthew Wilcox51219352007-10-02 21:55:22 -040011050#endif
11051
11052static struct scsi_host_template advansys_template = {
11053 .proc_name = DRV_NAME,
11054#ifdef CONFIG_PROC_FS
Al Virob59fb6f2013-03-31 02:59:55 -040011055 .show_info = advansys_show_info,
Matthew Wilcox51219352007-10-02 21:55:22 -040011056#endif
11057 .name = DRV_NAME,
11058 .info = advansys_info,
11059 .queuecommand = advansys_queuecommand,
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +020011060 .eh_host_reset_handler = advansys_reset,
Matthew Wilcox51219352007-10-02 21:55:22 -040011061 .bios_param = advansys_biosparam,
11062 .slave_configure = advansys_slave_configure,
11063 /*
11064 * Because the driver may control an ISA adapter 'unchecked_isa_dma'
11065 * must be set. The flag will be cleared in advansys_board_found
11066 * for non-ISA adapters.
11067 */
Hannes Reineckeae267592015-04-24 13:18:28 +020011068 .unchecked_isa_dma = true,
Matthew Wilcox51219352007-10-02 21:55:22 -040011069 /*
11070 * All adapters controlled by this driver are capable of large
11071 * scatter-gather lists. According to the mid-level SCSI documentation
11072 * this obviates any performance gain provided by setting
11073 * 'use_clustering'. But empirically while CPU utilization is increased
11074 * by enabling clustering, I/O throughput increases as well.
11075 */
11076 .use_clustering = ENABLE_CLUSTERING,
Hannes Reinecke9c17c622015-04-24 13:18:21 +020011077 .use_blk_tags = 1,
Matthew Wilcox51219352007-10-02 21:55:22 -040011078};
Linus Torvalds1da177e2005-04-16 15:20:36 -070011079
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011080static int advansys_wide_init_chip(struct Scsi_Host *shost)
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011081{
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011082 struct asc_board *board = shost_priv(shost);
11083 struct adv_dvc_var *adv_dvc = &board->dvc_var.adv_dvc_var;
Hannes Reinecke0ce53822015-04-24 13:18:25 +020011084 size_t sgblk_pool_size;
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011085 int warn_code, err_code;
11086
11087 /*
11088 * Allocate buffer carrier structures. The total size
Hannes Reinecke98b96a72015-04-24 13:18:23 +020011089 * is about 8 KB, so allocate all at once.
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011090 */
Hannes Reinecke98b96a72015-04-24 13:18:23 +020011091 adv_dvc->carrier = dma_alloc_coherent(board->dev,
11092 ADV_CARRIER_BUFSIZE, &adv_dvc->carrier_addr, GFP_KERNEL);
11093 ASC_DBG(1, "carrier 0x%p\n", adv_dvc->carrier);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011094
Hannes Reinecke98b96a72015-04-24 13:18:23 +020011095 if (!adv_dvc->carrier)
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011096 goto kmalloc_failed;
11097
11098 /*
11099 * Allocate up to 'max_host_qng' request structures for the Wide
11100 * board. The total size is about 16 KB, so allocate all at once.
11101 * If the allocation fails decrement and try again.
11102 */
Hannes Reinecke4b47e462015-04-24 13:18:24 +020011103 board->adv_reqp_size = adv_dvc->max_host_qng * sizeof(adv_req_t);
11104 if (board->adv_reqp_size & 0x1f) {
11105 ASC_DBG(1, "unaligned reqp %lu bytes\n", sizeof(adv_req_t));
11106 board->adv_reqp_size = ADV_32BALIGN(board->adv_reqp_size);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011107 }
Hannes Reinecke4b47e462015-04-24 13:18:24 +020011108 board->adv_reqp = dma_alloc_coherent(board->dev, board->adv_reqp_size,
11109 &board->adv_reqp_addr, GFP_KERNEL);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011110
Hannes Reinecke4b47e462015-04-24 13:18:24 +020011111 if (!board->adv_reqp)
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011112 goto kmalloc_failed;
11113
Hannes Reinecke4b47e462015-04-24 13:18:24 +020011114 ASC_DBG(1, "reqp 0x%p, req_cnt %d, bytes %lu\n", board->adv_reqp,
11115 adv_dvc->max_host_qng, board->adv_reqp_size);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011116
11117 /*
11118 * Allocate up to ADV_TOT_SG_BLOCK request structures for
11119 * the Wide board. Each structure is about 136 bytes.
11120 */
Hannes Reinecke0ce53822015-04-24 13:18:25 +020011121 sgblk_pool_size = sizeof(adv_sgblk_t) * ADV_TOT_SG_BLOCK;
11122 board->adv_sgblk_pool = dma_pool_create("adv_sgblk", board->dev,
11123 sgblk_pool_size, 32, 0);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011124
Hannes Reinecke0ce53822015-04-24 13:18:25 +020011125 ASC_DBG(1, "sg_cnt %d * %lu = %lu bytes\n", ADV_TOT_SG_BLOCK,
11126 sizeof(adv_sgblk_t), sgblk_pool_size);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011127
Hannes Reinecke0ce53822015-04-24 13:18:25 +020011128 if (!board->adv_sgblk_pool)
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011129 goto kmalloc_failed;
11130
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011131 if (adv_dvc->chip_type == ADV_CHIP_ASC3550) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011132 ASC_DBG(2, "AdvInitAsc3550Driver()\n");
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011133 warn_code = AdvInitAsc3550Driver(adv_dvc);
11134 } else if (adv_dvc->chip_type == ADV_CHIP_ASC38C0800) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011135 ASC_DBG(2, "AdvInitAsc38C0800Driver()\n");
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011136 warn_code = AdvInitAsc38C0800Driver(adv_dvc);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011137 } else {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011138 ASC_DBG(2, "AdvInitAsc38C1600Driver()\n");
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011139 warn_code = AdvInitAsc38C1600Driver(adv_dvc);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011140 }
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011141 err_code = adv_dvc->err_code;
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011142
11143 if (warn_code || err_code) {
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011144 shost_printk(KERN_WARNING, shost, "error: warn 0x%x, error "
11145 "0x%x\n", warn_code, err_code);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011146 }
11147
11148 goto exit;
11149
11150 kmalloc_failed:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011151 shost_printk(KERN_ERR, shost, "error: kmalloc() failed\n");
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011152 err_code = ADV_ERROR;
11153 exit:
11154 return err_code;
11155}
11156
Matthew Wilcox98d41c22007-10-02 21:55:37 -040011157static void advansys_wide_free_mem(struct asc_board *board)
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011158{
Matthew Wilcox98d41c22007-10-02 21:55:37 -040011159 struct adv_dvc_var *adv_dvc = &board->dvc_var.adv_dvc_var;
Hannes Reinecke98b96a72015-04-24 13:18:23 +020011160
11161 if (adv_dvc->carrier) {
11162 dma_free_coherent(board->dev, ADV_CARRIER_BUFSIZE,
11163 adv_dvc->carrier, adv_dvc->carrier_addr);
11164 adv_dvc->carrier = NULL;
11165 }
Hannes Reinecke4b47e462015-04-24 13:18:24 +020011166 if (board->adv_reqp) {
11167 dma_free_coherent(board->dev, board->adv_reqp_size,
11168 board->adv_reqp, board->adv_reqp_addr);
11169 board->adv_reqp = NULL;
11170 }
Hannes Reinecke0ce53822015-04-24 13:18:25 +020011171 if (board->adv_sgblk_pool) {
11172 dma_pool_destroy(board->adv_sgblk_pool);
11173 board->adv_sgblk_pool = NULL;
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011174 }
11175}
11176
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011177static int advansys_board_found(struct Scsi_Host *shost, unsigned int iop,
11178 int bus_type)
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011179{
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011180 struct pci_dev *pdev;
Matthew Wilcoxd2411492007-10-02 21:55:31 -040011181 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011182 ASC_DVC_VAR *asc_dvc_varp = NULL;
11183 ADV_DVC_VAR *adv_dvc_varp = NULL;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011184 int share_irq, warn_code, ret;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011185
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011186 pdev = (bus_type == ASC_IS_PCI) ? to_pci_dev(boardp->dev) : NULL;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011187
11188 if (ASC_NARROW_BOARD(boardp)) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011189 ASC_DBG(1, "narrow board\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011190 asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
11191 asc_dvc_varp->bus_type = bus_type;
11192 asc_dvc_varp->drv_ptr = boardp;
11193 asc_dvc_varp->cfg = &boardp->dvc_cfg.asc_dvc_cfg;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011194 asc_dvc_varp->iop_base = iop;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011195 } else {
Matthew Wilcox57ba5fe2007-07-26 11:55:07 -040011196#ifdef CONFIG_PCI
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011197 adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
11198 adv_dvc_varp->drv_ptr = boardp;
11199 adv_dvc_varp->cfg = &boardp->dvc_cfg.adv_dvc_cfg;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011200 if (pdev->device == PCI_DEVICE_ID_ASP_ABP940UW) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011201 ASC_DBG(1, "wide board ASC-3550\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011202 adv_dvc_varp->chip_type = ADV_CHIP_ASC3550;
11203 } else if (pdev->device == PCI_DEVICE_ID_38C0800_REV1) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011204 ASC_DBG(1, "wide board ASC-38C0800\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011205 adv_dvc_varp->chip_type = ADV_CHIP_ASC38C0800;
11206 } else {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011207 ASC_DBG(1, "wide board ASC-38C1600\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011208 adv_dvc_varp->chip_type = ADV_CHIP_ASC38C1600;
11209 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011210
Matthew Wilcox57ba5fe2007-07-26 11:55:07 -040011211 boardp->asc_n_io_port = pci_resource_len(pdev, 1);
Arjan van de Ven25729a72008-09-28 16:18:02 -070011212 boardp->ioremap_addr = pci_ioremap_bar(pdev, 1);
Matthew Wilcox57ba5fe2007-07-26 11:55:07 -040011213 if (!boardp->ioremap_addr) {
Matthew Wilcox9d511a42007-10-02 21:55:42 -040011214 shost_printk(KERN_ERR, shost, "ioremap(%lx, %d) "
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011215 "returned NULL\n",
Matthew Wilcox9d511a42007-10-02 21:55:42 -040011216 (long)pci_resource_start(pdev, 1),
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011217 boardp->asc_n_io_port);
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011218 ret = -ENODEV;
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011219 goto err_shost;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011220 }
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011221 adv_dvc_varp->iop_base = (AdvPortAddr)boardp->ioremap_addr;
11222 ASC_DBG(1, "iop_base: 0x%p\n", adv_dvc_varp->iop_base);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011223
11224 /*
11225 * Even though it isn't used to access wide boards, other
11226 * than for the debug line below, save I/O Port address so
11227 * that it can be reported.
11228 */
11229 boardp->ioport = iop;
11230
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011231 ASC_DBG(1, "iopb_chip_id_1 0x%x, iopw_chip_id_0 0x%x\n",
11232 (ushort)inp(iop + 1), (ushort)inpw(iop));
Matthew Wilcox57ba5fe2007-07-26 11:55:07 -040011233#endif /* CONFIG_PCI */
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011234 }
11235
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011236 if (ASC_NARROW_BOARD(boardp)) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011237 /*
11238 * Set the board bus type and PCI IRQ before
11239 * calling AscInitGetConfig().
11240 */
11241 switch (asc_dvc_varp->bus_type) {
11242#ifdef CONFIG_ISA
11243 case ASC_IS_ISA:
Hannes Reineckeae267592015-04-24 13:18:28 +020011244 shost->unchecked_isa_dma = true;
Matthew Wilcox074c8fe2007-07-28 23:11:05 -060011245 share_irq = 0;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011246 break;
11247 case ASC_IS_VL:
Hannes Reineckeae267592015-04-24 13:18:28 +020011248 shost->unchecked_isa_dma = false;
Matthew Wilcox074c8fe2007-07-28 23:11:05 -060011249 share_irq = 0;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011250 break;
11251 case ASC_IS_EISA:
Hannes Reineckeae267592015-04-24 13:18:28 +020011252 shost->unchecked_isa_dma = false;
Matthew Wilcox074c8fe2007-07-28 23:11:05 -060011253 share_irq = IRQF_SHARED;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011254 break;
11255#endif /* CONFIG_ISA */
11256#ifdef CONFIG_PCI
11257 case ASC_IS_PCI:
Hannes Reineckeae267592015-04-24 13:18:28 +020011258 shost->unchecked_isa_dma = false;
Matthew Wilcox074c8fe2007-07-28 23:11:05 -060011259 share_irq = IRQF_SHARED;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011260 break;
11261#endif /* CONFIG_PCI */
11262 default:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011263 shost_printk(KERN_ERR, shost, "unknown adapter type: "
11264 "%d\n", asc_dvc_varp->bus_type);
Hannes Reineckeae267592015-04-24 13:18:28 +020011265 shost->unchecked_isa_dma = false;
Matthew Wilcox074c8fe2007-07-28 23:11:05 -060011266 share_irq = 0;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011267 break;
11268 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011269
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011270 /*
11271 * NOTE: AscInitGetConfig() may change the board's
11272 * bus_type value. The bus_type value should no
11273 * longer be used. If the bus_type field must be
11274 * referenced only use the bit-wise AND operator "&".
11275 */
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011276 ASC_DBG(2, "AscInitGetConfig()\n");
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011277 ret = AscInitGetConfig(shost) ? -ENODEV : 0;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011278 } else {
Matthew Wilcoxc2dce2f2007-09-09 08:56:30 -060011279#ifdef CONFIG_PCI
11280 /*
11281 * For Wide boards set PCI information before calling
11282 * AdvInitGetConfig().
11283 */
Hannes Reineckeae267592015-04-24 13:18:28 +020011284 shost->unchecked_isa_dma = false;
Matthew Wilcoxc2dce2f2007-09-09 08:56:30 -060011285 share_irq = IRQF_SHARED;
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011286 ASC_DBG(2, "AdvInitGetConfig()\n");
Matthew Wilcox394dbf32007-07-26 11:56:40 -040011287
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011288 ret = AdvInitGetConfig(pdev, shost) ? -ENODEV : 0;
Matthew Wilcoxc2dce2f2007-09-09 08:56:30 -060011289#endif /* CONFIG_PCI */
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011290 }
11291
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011292 if (ret)
Al Virob59fb6f2013-03-31 02:59:55 -040011293 goto err_unmap;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011294
11295 /*
11296 * Save the EEPROM configuration so that it can be displayed
11297 * from /proc/scsi/advansys/[0...].
11298 */
11299 if (ASC_NARROW_BOARD(boardp)) {
11300
11301 ASCEEP_CONFIG *ep;
11302
11303 /*
11304 * Set the adapter's target id bit in the 'init_tidmask' field.
11305 */
11306 boardp->init_tidmask |=
11307 ADV_TID_TO_TIDMASK(asc_dvc_varp->cfg->chip_scsi_id);
11308
11309 /*
11310 * Save EEPROM settings for the board.
11311 */
11312 ep = &boardp->eep_config.asc_eep;
11313
11314 ep->init_sdtr = asc_dvc_varp->cfg->sdtr_enable;
11315 ep->disc_enable = asc_dvc_varp->cfg->disc_enable;
11316 ep->use_cmd_qng = asc_dvc_varp->cfg->cmd_qng_enabled;
11317 ASC_EEP_SET_DMA_SPD(ep, asc_dvc_varp->cfg->isa_dma_speed);
11318 ep->start_motor = asc_dvc_varp->start_motor;
11319 ep->cntl = asc_dvc_varp->dvc_cntl;
11320 ep->no_scam = asc_dvc_varp->no_scam;
11321 ep->max_total_qng = asc_dvc_varp->max_total_qng;
11322 ASC_EEP_SET_CHIP_ID(ep, asc_dvc_varp->cfg->chip_scsi_id);
11323 /* 'max_tag_qng' is set to the same value for every device. */
11324 ep->max_tag_qng = asc_dvc_varp->cfg->max_tag_qng[0];
11325 ep->adapter_info[0] = asc_dvc_varp->cfg->adapter_info[0];
11326 ep->adapter_info[1] = asc_dvc_varp->cfg->adapter_info[1];
11327 ep->adapter_info[2] = asc_dvc_varp->cfg->adapter_info[2];
11328 ep->adapter_info[3] = asc_dvc_varp->cfg->adapter_info[3];
11329 ep->adapter_info[4] = asc_dvc_varp->cfg->adapter_info[4];
11330 ep->adapter_info[5] = asc_dvc_varp->cfg->adapter_info[5];
11331
11332 /*
11333 * Modify board configuration.
11334 */
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011335 ASC_DBG(2, "AscInitSetConfig()\n");
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011336 ret = AscInitSetConfig(pdev, shost) ? -ENODEV : 0;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011337 if (ret)
Al Virob59fb6f2013-03-31 02:59:55 -040011338 goto err_unmap;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011339 } else {
11340 ADVEEP_3550_CONFIG *ep_3550;
11341 ADVEEP_38C0800_CONFIG *ep_38C0800;
11342 ADVEEP_38C1600_CONFIG *ep_38C1600;
11343
11344 /*
11345 * Save Wide EEP Configuration Information.
11346 */
11347 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
11348 ep_3550 = &boardp->eep_config.adv_3550_eep;
11349
11350 ep_3550->adapter_scsi_id = adv_dvc_varp->chip_scsi_id;
11351 ep_3550->max_host_qng = adv_dvc_varp->max_host_qng;
11352 ep_3550->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
11353 ep_3550->termination = adv_dvc_varp->cfg->termination;
11354 ep_3550->disc_enable = adv_dvc_varp->cfg->disc_enable;
11355 ep_3550->bios_ctrl = adv_dvc_varp->bios_ctrl;
11356 ep_3550->wdtr_able = adv_dvc_varp->wdtr_able;
11357 ep_3550->sdtr_able = adv_dvc_varp->sdtr_able;
11358 ep_3550->ultra_able = adv_dvc_varp->ultra_able;
11359 ep_3550->tagqng_able = adv_dvc_varp->tagqng_able;
11360 ep_3550->start_motor = adv_dvc_varp->start_motor;
11361 ep_3550->scsi_reset_delay =
11362 adv_dvc_varp->scsi_reset_wait;
11363 ep_3550->serial_number_word1 =
11364 adv_dvc_varp->cfg->serial1;
11365 ep_3550->serial_number_word2 =
11366 adv_dvc_varp->cfg->serial2;
11367 ep_3550->serial_number_word3 =
11368 adv_dvc_varp->cfg->serial3;
11369 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
11370 ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
11371
11372 ep_38C0800->adapter_scsi_id =
11373 adv_dvc_varp->chip_scsi_id;
11374 ep_38C0800->max_host_qng = adv_dvc_varp->max_host_qng;
11375 ep_38C0800->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
11376 ep_38C0800->termination_lvd =
11377 adv_dvc_varp->cfg->termination;
11378 ep_38C0800->disc_enable =
11379 adv_dvc_varp->cfg->disc_enable;
11380 ep_38C0800->bios_ctrl = adv_dvc_varp->bios_ctrl;
11381 ep_38C0800->wdtr_able = adv_dvc_varp->wdtr_able;
11382 ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
11383 ep_38C0800->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
11384 ep_38C0800->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
11385 ep_38C0800->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
11386 ep_38C0800->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
11387 ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
11388 ep_38C0800->start_motor = adv_dvc_varp->start_motor;
11389 ep_38C0800->scsi_reset_delay =
11390 adv_dvc_varp->scsi_reset_wait;
11391 ep_38C0800->serial_number_word1 =
11392 adv_dvc_varp->cfg->serial1;
11393 ep_38C0800->serial_number_word2 =
11394 adv_dvc_varp->cfg->serial2;
11395 ep_38C0800->serial_number_word3 =
11396 adv_dvc_varp->cfg->serial3;
11397 } else {
11398 ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
11399
11400 ep_38C1600->adapter_scsi_id =
11401 adv_dvc_varp->chip_scsi_id;
11402 ep_38C1600->max_host_qng = adv_dvc_varp->max_host_qng;
11403 ep_38C1600->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
11404 ep_38C1600->termination_lvd =
11405 adv_dvc_varp->cfg->termination;
11406 ep_38C1600->disc_enable =
11407 adv_dvc_varp->cfg->disc_enable;
11408 ep_38C1600->bios_ctrl = adv_dvc_varp->bios_ctrl;
11409 ep_38C1600->wdtr_able = adv_dvc_varp->wdtr_able;
11410 ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
11411 ep_38C1600->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
11412 ep_38C1600->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
11413 ep_38C1600->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
11414 ep_38C1600->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
11415 ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
11416 ep_38C1600->start_motor = adv_dvc_varp->start_motor;
11417 ep_38C1600->scsi_reset_delay =
11418 adv_dvc_varp->scsi_reset_wait;
11419 ep_38C1600->serial_number_word1 =
11420 adv_dvc_varp->cfg->serial1;
11421 ep_38C1600->serial_number_word2 =
11422 adv_dvc_varp->cfg->serial2;
11423 ep_38C1600->serial_number_word3 =
11424 adv_dvc_varp->cfg->serial3;
11425 }
11426
11427 /*
11428 * Set the adapter's target id bit in the 'init_tidmask' field.
11429 */
11430 boardp->init_tidmask |=
11431 ADV_TID_TO_TIDMASK(adv_dvc_varp->chip_scsi_id);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011432 }
11433
11434 /*
11435 * Channels are numbered beginning with 0. For AdvanSys one host
11436 * structure supports one channel. Multi-channel boards have a
11437 * separate host structure for each channel.
11438 */
11439 shost->max_channel = 0;
11440 if (ASC_NARROW_BOARD(boardp)) {
11441 shost->max_id = ASC_MAX_TID + 1;
11442 shost->max_lun = ASC_MAX_LUN + 1;
Matthew Wilcoxf05ec592007-09-09 08:56:36 -060011443 shost->max_cmd_len = ASC_MAX_CDB_LEN;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011444
11445 shost->io_port = asc_dvc_varp->iop_base;
11446 boardp->asc_n_io_port = ASC_IOADR_GAP;
11447 shost->this_id = asc_dvc_varp->cfg->chip_scsi_id;
11448
11449 /* Set maximum number of queues the adapter can handle. */
11450 shost->can_queue = asc_dvc_varp->max_total_qng;
11451 } else {
11452 shost->max_id = ADV_MAX_TID + 1;
11453 shost->max_lun = ADV_MAX_LUN + 1;
Matthew Wilcoxf05ec592007-09-09 08:56:36 -060011454 shost->max_cmd_len = ADV_MAX_CDB_LEN;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011455
11456 /*
11457 * Save the I/O Port address and length even though
11458 * I/O ports are not used to access Wide boards.
11459 * Instead the Wide boards are accessed with
11460 * PCI Memory Mapped I/O.
11461 */
11462 shost->io_port = iop;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011463
11464 shost->this_id = adv_dvc_varp->chip_scsi_id;
11465
11466 /* Set maximum number of queues the adapter can handle. */
11467 shost->can_queue = adv_dvc_varp->max_host_qng;
11468 }
Hannes Reinecke9c17c622015-04-24 13:18:21 +020011469 ret = scsi_init_shared_tag_map(shost, shost->can_queue);
11470 if (ret) {
11471 shost_printk(KERN_ERR, shost, "init tag map failed\n");
11472 goto err_free_dma;
11473 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011474
11475 /*
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011476 * Following v1.3.89, 'cmd_per_lun' is no longer needed
11477 * and should be set to zero.
11478 *
11479 * But because of a bug introduced in v1.3.89 if the driver is
11480 * compiled as a module and 'cmd_per_lun' is zero, the Mid-Level
11481 * SCSI function 'allocate_device' will panic. To allow the driver
11482 * to work as a module in these kernels set 'cmd_per_lun' to 1.
11483 *
11484 * Note: This is wrong. cmd_per_lun should be set to the depth
11485 * you want on untagged devices always.
11486 #ifdef MODULE
11487 */
11488 shost->cmd_per_lun = 1;
11489/* #else
11490 shost->cmd_per_lun = 0;
11491#endif */
11492
11493 /*
11494 * Set the maximum number of scatter-gather elements the
11495 * adapter can handle.
11496 */
11497 if (ASC_NARROW_BOARD(boardp)) {
11498 /*
11499 * Allow two commands with 'sg_tablesize' scatter-gather
11500 * elements to be executed simultaneously. This value is
11501 * the theoretical hardware limit. It may be decreased
11502 * below.
11503 */
11504 shost->sg_tablesize =
11505 (((asc_dvc_varp->max_total_qng - 2) / 2) *
11506 ASC_SG_LIST_PER_Q) + 1;
11507 } else {
11508 shost->sg_tablesize = ADV_MAX_SG_LIST;
11509 }
11510
11511 /*
11512 * The value of 'sg_tablesize' can not exceed the SCSI
11513 * mid-level driver definition of SG_ALL. SG_ALL also
11514 * must not be exceeded, because it is used to define the
11515 * size of the scatter-gather table in 'struct asc_sg_head'.
11516 */
11517 if (shost->sg_tablesize > SG_ALL) {
11518 shost->sg_tablesize = SG_ALL;
11519 }
11520
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011521 ASC_DBG(1, "sg_tablesize: %d\n", shost->sg_tablesize);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011522
11523 /* BIOS start address. */
11524 if (ASC_NARROW_BOARD(boardp)) {
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011525 shost->base = AscGetChipBiosAddress(asc_dvc_varp->iop_base,
11526 asc_dvc_varp->bus_type);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011527 } else {
11528 /*
11529 * Fill-in BIOS board variables. The Wide BIOS saves
11530 * information in LRAM that is used by the driver.
11531 */
11532 AdvReadWordLram(adv_dvc_varp->iop_base,
11533 BIOS_SIGNATURE, boardp->bios_signature);
11534 AdvReadWordLram(adv_dvc_varp->iop_base,
11535 BIOS_VERSION, boardp->bios_version);
11536 AdvReadWordLram(adv_dvc_varp->iop_base,
11537 BIOS_CODESEG, boardp->bios_codeseg);
11538 AdvReadWordLram(adv_dvc_varp->iop_base,
11539 BIOS_CODELEN, boardp->bios_codelen);
11540
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011541 ASC_DBG(1, "bios_signature 0x%x, bios_version 0x%x\n",
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011542 boardp->bios_signature, boardp->bios_version);
11543
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011544 ASC_DBG(1, "bios_codeseg 0x%x, bios_codelen 0x%x\n",
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011545 boardp->bios_codeseg, boardp->bios_codelen);
11546
11547 /*
11548 * If the BIOS saved a valid signature, then fill in
11549 * the BIOS code segment base address.
11550 */
11551 if (boardp->bios_signature == 0x55AA) {
11552 /*
11553 * Convert x86 realmode code segment to a linear
11554 * address by shifting left 4.
11555 */
11556 shost->base = ((ulong)boardp->bios_codeseg << 4);
11557 } else {
11558 shost->base = 0;
11559 }
11560 }
11561
11562 /*
11563 * Register Board Resources - I/O Port, DMA, IRQ
11564 */
11565
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011566 /* Register DMA Channel for Narrow boards. */
11567 shost->dma_channel = NO_ISA_DMA; /* Default to no ISA DMA. */
11568#ifdef CONFIG_ISA
11569 if (ASC_NARROW_BOARD(boardp)) {
11570 /* Register DMA channel for ISA bus. */
11571 if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
11572 shost->dma_channel = asc_dvc_varp->cfg->isa_dma_channel;
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060011573 ret = request_dma(shost->dma_channel, DRV_NAME);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011574 if (ret) {
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011575 shost_printk(KERN_ERR, shost, "request_dma() "
11576 "%d failed %d\n",
11577 shost->dma_channel, ret);
Al Virob59fb6f2013-03-31 02:59:55 -040011578 goto err_unmap;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011579 }
11580 AscEnableIsaDma(shost->dma_channel);
11581 }
11582 }
11583#endif /* CONFIG_ISA */
11584
11585 /* Register IRQ Number. */
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011586 ASC_DBG(2, "request_irq(%d, %p)\n", boardp->irq, shost);
Matthew Wilcox074c8fe2007-07-28 23:11:05 -060011587
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011588 ret = request_irq(boardp->irq, advansys_interrupt, share_irq,
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060011589 DRV_NAME, shost);
Matthew Wilcox074c8fe2007-07-28 23:11:05 -060011590
11591 if (ret) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011592 if (ret == -EBUSY) {
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011593 shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
11594 "already in use\n", boardp->irq);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011595 } else if (ret == -EINVAL) {
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011596 shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
11597 "not valid\n", boardp->irq);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011598 } else {
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011599 shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
11600 "failed with %d\n", boardp->irq, ret);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011601 }
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011602 goto err_free_dma;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011603 }
11604
11605 /*
11606 * Initialize board RISC chip and enable interrupts.
11607 */
11608 if (ASC_NARROW_BOARD(boardp)) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011609 ASC_DBG(2, "AscInitAsc1000Driver()\n");
FUJITA Tomonori7d5d4082008-02-08 09:50:08 +090011610
11611 asc_dvc_varp->overrun_buf = kzalloc(ASC_OVERRUN_BSIZE, GFP_KERNEL);
11612 if (!asc_dvc_varp->overrun_buf) {
11613 ret = -ENOMEM;
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -030011614 goto err_free_irq;
FUJITA Tomonori7d5d4082008-02-08 09:50:08 +090011615 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011616 warn_code = AscInitAsc1000Driver(asc_dvc_varp);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011617
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011618 if (warn_code || asc_dvc_varp->err_code) {
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011619 shost_printk(KERN_ERR, shost, "error: init_state 0x%x, "
11620 "warn 0x%x, error 0x%x\n",
11621 asc_dvc_varp->init_state, warn_code,
11622 asc_dvc_varp->err_code);
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -030011623 if (!asc_dvc_varp->overrun_dma) {
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011624 ret = -ENODEV;
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -030011625 goto err_free_mem;
FUJITA Tomonori7d5d4082008-02-08 09:50:08 +090011626 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011627 }
11628 } else {
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -030011629 if (advansys_wide_init_chip(shost)) {
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011630 ret = -ENODEV;
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -030011631 goto err_free_mem;
11632 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011633 }
11634
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011635 ASC_DBG_PRT_SCSI_HOST(2, shost);
11636
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011637 ret = scsi_add_host(shost, boardp->dev);
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060011638 if (ret)
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -030011639 goto err_free_mem;
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060011640
11641 scsi_scan_host(shost);
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011642 return 0;
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011643
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -030011644 err_free_mem:
11645 if (ASC_NARROW_BOARD(boardp)) {
11646 if (asc_dvc_varp->overrun_dma)
11647 dma_unmap_single(boardp->dev, asc_dvc_varp->overrun_dma,
11648 ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
11649 kfree(asc_dvc_varp->overrun_buf);
11650 } else
11651 advansys_wide_free_mem(boardp);
11652 err_free_irq:
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011653 free_irq(boardp->irq, shost);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011654 err_free_dma:
Al Viro30037812008-11-22 17:34:54 +000011655#ifdef CONFIG_ISA
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011656 if (shost->dma_channel != NO_ISA_DMA)
11657 free_dma(shost->dma_channel);
Al Viro30037812008-11-22 17:34:54 +000011658#endif
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011659 err_unmap:
11660 if (boardp->ioremap_addr)
11661 iounmap(boardp->ioremap_addr);
11662 err_shost:
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011663 return ret;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011664}
11665
11666/*
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011667 * advansys_release()
11668 *
11669 * Release resources allocated for a single AdvanSys adapter.
11670 */
11671static int advansys_release(struct Scsi_Host *shost)
11672{
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -040011673 struct asc_board *board = shost_priv(shost);
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011674 ASC_DBG(1, "begin\n");
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060011675 scsi_remove_host(shost);
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -040011676 free_irq(board->irq, shost);
Al Viro30037812008-11-22 17:34:54 +000011677#ifdef CONFIG_ISA
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011678 if (shost->dma_channel != NO_ISA_DMA) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011679 ASC_DBG(1, "free_dma()\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011680 free_dma(shost->dma_channel);
11681 }
Al Viro30037812008-11-22 17:34:54 +000011682#endif
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -040011683 if (ASC_NARROW_BOARD(board)) {
11684 dma_unmap_single(board->dev,
11685 board->dvc_var.asc_dvc_var.overrun_dma,
11686 ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
FUJITA Tomonori7d5d4082008-02-08 09:50:08 +090011687 kfree(board->dvc_var.asc_dvc_var.overrun_buf);
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -040011688 } else {
11689 iounmap(board->ioremap_addr);
11690 advansys_wide_free_mem(board);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011691 }
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060011692 scsi_host_put(shost);
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011693 ASC_DBG(1, "end\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011694 return 0;
11695}
11696
Matthew Wilcox95c9f162007-09-09 08:56:39 -060011697#define ASC_IOADR_TABLE_MAX_IX 11
11698
Randy Dunlap747d0162008-01-14 00:55:18 -080011699static PortAddr _asc_def_iop_base[ASC_IOADR_TABLE_MAX_IX] = {
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011700 0x100, 0x0110, 0x120, 0x0130, 0x140, 0x0150, 0x0190,
11701 0x0210, 0x0230, 0x0250, 0x0330
11702};
11703
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011704/*
11705 * The ISA IRQ number is found in bits 2 and 3 of the CfgLsw. It decodes as:
11706 * 00: 10
11707 * 01: 11
11708 * 10: 12
11709 * 11: 15
11710 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011711static unsigned int advansys_isa_irq_no(PortAddr iop_base)
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011712{
11713 unsigned short cfg_lsw = AscGetChipCfgLsw(iop_base);
11714 unsigned int chip_irq = ((cfg_lsw >> 2) & 0x03) + 10;
11715 if (chip_irq == 13)
11716 chip_irq = 15;
11717 return chip_irq;
11718}
11719
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011720static int advansys_isa_probe(struct device *dev, unsigned int id)
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011721{
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011722 int err = -ENODEV;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011723 PortAddr iop_base = _asc_def_iop_base[id];
11724 struct Scsi_Host *shost;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011725 struct asc_board *board;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011726
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060011727 if (!request_region(iop_base, ASC_IOADR_GAP, DRV_NAME)) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011728 ASC_DBG(1, "I/O port 0x%x busy\n", iop_base);
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011729 return -ENODEV;
11730 }
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011731 ASC_DBG(1, "probing I/O port 0x%x\n", iop_base);
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011732 if (!AscFindSignature(iop_base))
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011733 goto release_region;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011734 if (!(AscGetChipVersion(iop_base, ASC_IS_ISA) & ASC_CHIP_VER_ISA_BIT))
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011735 goto release_region;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011736
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011737 err = -ENOMEM;
11738 shost = scsi_host_alloc(&advansys_template, sizeof(*board));
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011739 if (!shost)
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011740 goto release_region;
11741
Matthew Wilcoxd2411492007-10-02 21:55:31 -040011742 board = shost_priv(shost);
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011743 board->irq = advansys_isa_irq_no(iop_base);
11744 board->dev = dev;
Hannes Reinecke9c17c622015-04-24 13:18:21 +020011745 board->shost = shost;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011746
11747 err = advansys_board_found(shost, iop_base, ASC_IS_ISA);
11748 if (err)
11749 goto free_host;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011750
11751 dev_set_drvdata(dev, shost);
11752 return 0;
11753
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011754 free_host:
11755 scsi_host_put(shost);
11756 release_region:
Matthew Wilcox71f361152007-07-30 08:04:53 -060011757 release_region(iop_base, ASC_IOADR_GAP);
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011758 return err;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011759}
11760
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011761static int advansys_isa_remove(struct device *dev, unsigned int id)
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011762{
Matthew Wilcox71f361152007-07-30 08:04:53 -060011763 int ioport = _asc_def_iop_base[id];
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011764 advansys_release(dev_get_drvdata(dev));
Matthew Wilcox71f361152007-07-30 08:04:53 -060011765 release_region(ioport, ASC_IOADR_GAP);
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011766 return 0;
11767}
11768
11769static struct isa_driver advansys_isa_driver = {
11770 .probe = advansys_isa_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011771 .remove = advansys_isa_remove,
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011772 .driver = {
11773 .owner = THIS_MODULE,
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060011774 .name = DRV_NAME,
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011775 },
11776};
11777
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011778/*
11779 * The VLB IRQ number is found in bits 2 to 4 of the CfgLsw. It decodes as:
11780 * 000: invalid
11781 * 001: 10
11782 * 010: 11
11783 * 011: 12
11784 * 100: invalid
11785 * 101: 14
11786 * 110: 15
11787 * 111: invalid
11788 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011789static unsigned int advansys_vlb_irq_no(PortAddr iop_base)
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011790{
11791 unsigned short cfg_lsw = AscGetChipCfgLsw(iop_base);
11792 unsigned int chip_irq = ((cfg_lsw >> 2) & 0x07) + 9;
11793 if ((chip_irq < 10) || (chip_irq == 13) || (chip_irq > 15))
11794 return 0;
11795 return chip_irq;
11796}
11797
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011798static int advansys_vlb_probe(struct device *dev, unsigned int id)
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011799{
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011800 int err = -ENODEV;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011801 PortAddr iop_base = _asc_def_iop_base[id];
11802 struct Scsi_Host *shost;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011803 struct asc_board *board;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011804
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060011805 if (!request_region(iop_base, ASC_IOADR_GAP, DRV_NAME)) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011806 ASC_DBG(1, "I/O port 0x%x busy\n", iop_base);
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011807 return -ENODEV;
11808 }
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011809 ASC_DBG(1, "probing I/O port 0x%x\n", iop_base);
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011810 if (!AscFindSignature(iop_base))
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011811 goto release_region;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011812 /*
11813 * I don't think this condition can actually happen, but the old
11814 * driver did it, and the chances of finding a VLB setup in 2007
11815 * to do testing with is slight to none.
11816 */
11817 if (AscGetChipVersion(iop_base, ASC_IS_VL) > ASC_CHIP_MAX_VER_VL)
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011818 goto release_region;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011819
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011820 err = -ENOMEM;
11821 shost = scsi_host_alloc(&advansys_template, sizeof(*board));
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011822 if (!shost)
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011823 goto release_region;
11824
Matthew Wilcoxd2411492007-10-02 21:55:31 -040011825 board = shost_priv(shost);
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011826 board->irq = advansys_vlb_irq_no(iop_base);
11827 board->dev = dev;
Hannes Reinecke9c17c622015-04-24 13:18:21 +020011828 board->shost = shost;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011829
11830 err = advansys_board_found(shost, iop_base, ASC_IS_VL);
11831 if (err)
11832 goto free_host;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011833
11834 dev_set_drvdata(dev, shost);
11835 return 0;
11836
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011837 free_host:
11838 scsi_host_put(shost);
11839 release_region:
Matthew Wilcox71f361152007-07-30 08:04:53 -060011840 release_region(iop_base, ASC_IOADR_GAP);
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011841 return -ENODEV;
11842}
11843
11844static struct isa_driver advansys_vlb_driver = {
11845 .probe = advansys_vlb_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011846 .remove = advansys_isa_remove,
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011847 .driver = {
11848 .owner = THIS_MODULE,
Matthew Wilcoxb8e5152b2007-09-09 08:56:26 -060011849 .name = "advansys_vlb",
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011850 },
11851};
11852
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011853static struct eisa_device_id advansys_eisa_table[] = {
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011854 { "ABP7401" },
11855 { "ABP7501" },
11856 { "" }
11857};
11858
11859MODULE_DEVICE_TABLE(eisa, advansys_eisa_table);
11860
11861/*
11862 * EISA is a little more tricky than PCI; each EISA device may have two
11863 * channels, and this driver is written to make each channel its own Scsi_Host
11864 */
11865struct eisa_scsi_data {
11866 struct Scsi_Host *host[2];
11867};
11868
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011869/*
11870 * The EISA IRQ number is found in bits 8 to 10 of the CfgLsw. It decodes as:
11871 * 000: 10
11872 * 001: 11
11873 * 010: 12
11874 * 011: invalid
11875 * 100: 14
11876 * 101: 15
11877 * 110: invalid
11878 * 111: invalid
11879 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011880static unsigned int advansys_eisa_irq_no(struct eisa_device *edev)
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011881{
11882 unsigned short cfg_lsw = inw(edev->base_addr + 0xc86);
11883 unsigned int chip_irq = ((cfg_lsw >> 8) & 0x07) + 10;
11884 if ((chip_irq == 13) || (chip_irq > 15))
11885 return 0;
11886 return chip_irq;
11887}
11888
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011889static int advansys_eisa_probe(struct device *dev)
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011890{
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011891 int i, ioport, irq = 0;
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011892 int err;
11893 struct eisa_device *edev = to_eisa_device(dev);
11894 struct eisa_scsi_data *data;
11895
11896 err = -ENOMEM;
11897 data = kzalloc(sizeof(*data), GFP_KERNEL);
11898 if (!data)
11899 goto fail;
11900 ioport = edev->base_addr + 0xc30;
11901
11902 err = -ENODEV;
11903 for (i = 0; i < 2; i++, ioport += 0x20) {
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011904 struct asc_board *board;
11905 struct Scsi_Host *shost;
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060011906 if (!request_region(ioport, ASC_IOADR_GAP, DRV_NAME)) {
Matthew Wilcox71f361152007-07-30 08:04:53 -060011907 printk(KERN_WARNING "Region %x-%x busy\n", ioport,
11908 ioport + ASC_IOADR_GAP - 1);
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011909 continue;
Matthew Wilcox71f361152007-07-30 08:04:53 -060011910 }
11911 if (!AscFindSignature(ioport)) {
11912 release_region(ioport, ASC_IOADR_GAP);
11913 continue;
11914 }
11915
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011916 /*
11917 * I don't know why we need to do this for EISA chips, but
11918 * not for any others. It looks to be equivalent to
11919 * AscGetChipCfgMsw, but I may have overlooked something,
11920 * so I'm not converting it until I get an EISA board to
11921 * test with.
11922 */
11923 inw(ioport + 4);
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011924
11925 if (!irq)
11926 irq = advansys_eisa_irq_no(edev);
11927
11928 err = -ENOMEM;
11929 shost = scsi_host_alloc(&advansys_template, sizeof(*board));
11930 if (!shost)
11931 goto release_region;
11932
Matthew Wilcoxd2411492007-10-02 21:55:31 -040011933 board = shost_priv(shost);
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011934 board->irq = irq;
11935 board->dev = dev;
Hannes Reinecke9c17c622015-04-24 13:18:21 +020011936 board->shost = shost;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011937
11938 err = advansys_board_found(shost, ioport, ASC_IS_EISA);
11939 if (!err) {
11940 data->host[i] = shost;
11941 continue;
Matthew Wilcox71f361152007-07-30 08:04:53 -060011942 }
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011943
11944 scsi_host_put(shost);
11945 release_region:
11946 release_region(ioport, ASC_IOADR_GAP);
11947 break;
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011948 }
11949
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011950 if (err)
11951 goto free_data;
11952 dev_set_drvdata(dev, data);
11953 return 0;
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011954
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011955 free_data:
11956 kfree(data->host[0]);
11957 kfree(data->host[1]);
11958 kfree(data);
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011959 fail:
11960 return err;
11961}
11962
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011963static int advansys_eisa_remove(struct device *dev)
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011964{
11965 int i;
11966 struct eisa_scsi_data *data = dev_get_drvdata(dev);
11967
11968 for (i = 0; i < 2; i++) {
Matthew Wilcox71f361152007-07-30 08:04:53 -060011969 int ioport;
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011970 struct Scsi_Host *shost = data->host[i];
11971 if (!shost)
11972 continue;
Matthew Wilcox71f361152007-07-30 08:04:53 -060011973 ioport = shost->io_port;
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011974 advansys_release(shost);
Matthew Wilcox71f361152007-07-30 08:04:53 -060011975 release_region(ioport, ASC_IOADR_GAP);
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011976 }
11977
11978 kfree(data);
11979 return 0;
11980}
11981
11982static struct eisa_driver advansys_eisa_driver = {
11983 .id_table = advansys_eisa_table,
11984 .driver = {
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060011985 .name = DRV_NAME,
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011986 .probe = advansys_eisa_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011987 .remove = advansys_eisa_remove,
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011988 }
11989};
11990
Dave Jones2672ea82006-08-02 17:11:49 -040011991/* PCI Devices supported by this driver */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011992static struct pci_device_id advansys_pci_tbl[] = {
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011993 {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_1200A,
11994 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
11995 {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940,
11996 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
11997 {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940U,
11998 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
11999 {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940UW,
12000 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
12001 {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_38C0800_REV1,
12002 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
12003 {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_38C1600_REV1,
12004 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
12005 {}
Dave Jones2672ea82006-08-02 17:11:49 -040012006};
Matthew Wilcox27c868c2007-07-26 10:56:23 -040012007
Dave Jones2672ea82006-08-02 17:11:49 -040012008MODULE_DEVICE_TABLE(pci, advansys_pci_tbl);
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012009
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012010static void advansys_set_latency(struct pci_dev *pdev)
Matthew Wilcox9649af32007-07-26 21:51:47 -060012011{
12012 if ((pdev->device == PCI_DEVICE_ID_ASP_1200A) ||
12013 (pdev->device == PCI_DEVICE_ID_ASP_ABP940)) {
12014 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0);
12015 } else {
12016 u8 latency;
12017 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency);
12018 if (latency < 0x20)
12019 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x20);
12020 }
12021}
12022
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012023static int advansys_pci_probe(struct pci_dev *pdev,
12024 const struct pci_device_id *ent)
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012025{
12026 int err, ioport;
12027 struct Scsi_Host *shost;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040012028 struct asc_board *board;
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012029
12030 err = pci_enable_device(pdev);
12031 if (err)
12032 goto fail;
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060012033 err = pci_request_regions(pdev, DRV_NAME);
Matthew Wilcox71f361152007-07-30 08:04:53 -060012034 if (err)
12035 goto disable_device;
Matthew Wilcox9649af32007-07-26 21:51:47 -060012036 pci_set_master(pdev);
12037 advansys_set_latency(pdev);
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012038
Matthew Wilcoxd361db42007-10-02 21:55:29 -040012039 err = -ENODEV;
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012040 if (pci_resource_len(pdev, 0) == 0)
Matthew Wilcoxd361db42007-10-02 21:55:29 -040012041 goto release_region;
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012042
12043 ioport = pci_resource_start(pdev, 0);
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012044
Matthew Wilcoxd361db42007-10-02 21:55:29 -040012045 err = -ENOMEM;
12046 shost = scsi_host_alloc(&advansys_template, sizeof(*board));
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012047 if (!shost)
Matthew Wilcoxd361db42007-10-02 21:55:29 -040012048 goto release_region;
12049
Matthew Wilcoxd2411492007-10-02 21:55:31 -040012050 board = shost_priv(shost);
Matthew Wilcoxd361db42007-10-02 21:55:29 -040012051 board->irq = pdev->irq;
12052 board->dev = &pdev->dev;
Hannes Reinecke9c17c622015-04-24 13:18:21 +020012053 board->shost = shost;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040012054
12055 if (pdev->device == PCI_DEVICE_ID_ASP_ABP940UW ||
12056 pdev->device == PCI_DEVICE_ID_38C0800_REV1 ||
12057 pdev->device == PCI_DEVICE_ID_38C1600_REV1) {
12058 board->flags |= ASC_IS_WIDE_BOARD;
12059 }
12060
12061 err = advansys_board_found(shost, ioport, ASC_IS_PCI);
12062 if (err)
12063 goto free_host;
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012064
12065 pci_set_drvdata(pdev, shost);
12066 return 0;
12067
Matthew Wilcoxd361db42007-10-02 21:55:29 -040012068 free_host:
12069 scsi_host_put(shost);
12070 release_region:
Matthew Wilcox71f361152007-07-30 08:04:53 -060012071 pci_release_regions(pdev);
12072 disable_device:
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012073 pci_disable_device(pdev);
12074 fail:
12075 return err;
12076}
12077
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012078static void advansys_pci_remove(struct pci_dev *pdev)
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012079{
12080 advansys_release(pci_get_drvdata(pdev));
Matthew Wilcox71f361152007-07-30 08:04:53 -060012081 pci_release_regions(pdev);
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012082 pci_disable_device(pdev);
12083}
12084
12085static struct pci_driver advansys_pci_driver = {
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060012086 .name = DRV_NAME,
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012087 .id_table = advansys_pci_tbl,
12088 .probe = advansys_pci_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012089 .remove = advansys_pci_remove,
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012090};
Matthew Wilcox8c6af9e2007-07-26 11:03:19 -040012091
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060012092static int __init advansys_init(void)
12093{
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060012094 int error;
12095
12096 error = isa_register_driver(&advansys_isa_driver,
12097 ASC_IOADR_TABLE_MAX_IX);
12098 if (error)
12099 goto fail;
12100
12101 error = isa_register_driver(&advansys_vlb_driver,
12102 ASC_IOADR_TABLE_MAX_IX);
12103 if (error)
12104 goto unregister_isa;
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060012105
12106 error = eisa_driver_register(&advansys_eisa_driver);
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012107 if (error)
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060012108 goto unregister_vlb;
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060012109
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060012110 error = pci_register_driver(&advansys_pci_driver);
12111 if (error)
12112 goto unregister_eisa;
12113
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060012114 return 0;
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012115
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060012116 unregister_eisa:
12117 eisa_driver_unregister(&advansys_eisa_driver);
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060012118 unregister_vlb:
12119 isa_unregister_driver(&advansys_vlb_driver);
12120 unregister_isa:
12121 isa_unregister_driver(&advansys_isa_driver);
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012122 fail:
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012123 return error;
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060012124}
12125
12126static void __exit advansys_exit(void)
12127{
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012128 pci_unregister_driver(&advansys_pci_driver);
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060012129 eisa_driver_unregister(&advansys_eisa_driver);
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060012130 isa_unregister_driver(&advansys_vlb_driver);
12131 isa_unregister_driver(&advansys_isa_driver);
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060012132}
12133
12134module_init(advansys_init);
12135module_exit(advansys_exit);
12136
Matthew Wilcox8c6af9e2007-07-26 11:03:19 -040012137MODULE_LICENSE("GPL");
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +053012138MODULE_FIRMWARE("advansys/mcode.bin");
12139MODULE_FIRMWARE("advansys/3550.bin");
12140MODULE_FIRMWARE("advansys/38C0800.bin");
12141MODULE_FIRMWARE("advansys/38C1600.bin");