blob: bc52cdcf08e68f6d6370c4cbb5fedf00ed51698f [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 UW_ERR (uint)(0xFFFF)
82#define isodd_word(val) ((((uint)val) & (uint)0x0001) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Dave Jones2672ea82006-08-02 17:11:49 -040084#define PCI_VENDOR_ID_ASP 0x10cd
85#define PCI_DEVICE_ID_ASP_1200A 0x1100
86#define PCI_DEVICE_ID_ASP_ABP940 0x1200
87#define PCI_DEVICE_ID_ASP_ABP940U 0x1300
88#define PCI_DEVICE_ID_ASP_ABP940UW 0x2300
89#define PCI_DEVICE_ID_38C0800_REV1 0x2500
90#define PCI_DEVICE_ID_38C1600_REV1 0x2700
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092/*
93 * Enable CC_VERY_LONG_SG_LIST to support up to 64K element SG lists.
94 * The SRB structure will have to be changed and the ASC_SRB2SCSIQ()
95 * macro re-defined to be able to obtain a ASC_SCSI_Q pointer from the
96 * SRB structure.
97 */
98#define CC_VERY_LONG_SG_LIST 0
99#define ASC_SRB2SCSIQ(srb_ptr) (srb_ptr)
100
Matthew Wilcox9d511a42007-10-02 21:55:42 -0400101#define PortAddr unsigned int /* port address size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#define inp(port) inb(port)
103#define outp(port, byte) outb((byte), (port))
104
105#define inpw(port) inw(port)
106#define outpw(port, word) outw((word), (port))
107
108#define ASC_MAX_SG_QUEUE 7
109#define ASC_MAX_SG_LIST 255
110
111#define ASC_CS_TYPE unsigned short
112
113#define ASC_IS_ISA (0x0001)
114#define ASC_IS_ISAPNP (0x0081)
115#define ASC_IS_EISA (0x0002)
116#define ASC_IS_PCI (0x0004)
117#define ASC_IS_PCI_ULTRA (0x0104)
118#define ASC_IS_PCMCIA (0x0008)
119#define ASC_IS_MCA (0x0020)
120#define ASC_IS_VL (0x0040)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121#define ASC_IS_WIDESCSI_16 (0x0100)
122#define ASC_IS_WIDESCSI_32 (0x0200)
123#define ASC_IS_BIG_ENDIAN (0x8000)
Matthew Wilcox95c9f162007-09-09 08:56:39 -0600124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125#define ASC_CHIP_MIN_VER_VL (0x01)
126#define ASC_CHIP_MAX_VER_VL (0x07)
127#define ASC_CHIP_MIN_VER_PCI (0x09)
128#define ASC_CHIP_MAX_VER_PCI (0x0F)
129#define ASC_CHIP_VER_PCI_BIT (0x08)
130#define ASC_CHIP_MIN_VER_ISA (0x11)
131#define ASC_CHIP_MIN_VER_ISA_PNP (0x21)
132#define ASC_CHIP_MAX_VER_ISA (0x27)
133#define ASC_CHIP_VER_ISA_BIT (0x30)
134#define ASC_CHIP_VER_ISAPNP_BIT (0x20)
135#define ASC_CHIP_VER_ASYN_BUG (0x21)
136#define ASC_CHIP_VER_PCI 0x08
137#define ASC_CHIP_VER_PCI_ULTRA_3150 (ASC_CHIP_VER_PCI | 0x02)
138#define ASC_CHIP_VER_PCI_ULTRA_3050 (ASC_CHIP_VER_PCI | 0x03)
139#define ASC_CHIP_MIN_VER_EISA (0x41)
140#define ASC_CHIP_MAX_VER_EISA (0x47)
141#define ASC_CHIP_VER_EISA_BIT (0x40)
142#define ASC_CHIP_LATEST_VER_EISA ((ASC_CHIP_MIN_VER_EISA - 1) + 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143#define ASC_MAX_VL_DMA_COUNT (0x07FFFFFFL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144#define ASC_MAX_PCI_DMA_COUNT (0xFFFFFFFFL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#define ASC_MAX_ISA_DMA_COUNT (0x00FFFFFFL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
147#define ASC_SCSI_ID_BITS 3
148#define ASC_SCSI_TIX_TYPE uchar
149#define ASC_ALL_DEVICE_BIT_SET 0xFF
150#define ASC_SCSI_BIT_ID_TYPE uchar
151#define ASC_MAX_TID 7
152#define ASC_MAX_LUN 7
153#define ASC_SCSI_WIDTH_BIT_SET 0xFF
154#define ASC_MAX_SENSE_LEN 32
155#define ASC_MIN_SENSE_LEN 14
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156#define ASC_SCSI_RESET_HOLD_TIME_US 60
157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158/*
Matthew Wilcoxf05ec592007-09-09 08:56:36 -0600159 * Narrow boards only support 12-byte commands, while wide boards
160 * extend to 16-byte commands.
161 */
162#define ASC_MAX_CDB_LEN 12
163#define ADV_MAX_CDB_LEN 16
164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165#define MS_SDTR_LEN 0x03
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166#define MS_WDTR_LEN 0x02
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168#define ASC_SG_LIST_PER_Q 7
169#define QS_FREE 0x00
170#define QS_READY 0x01
171#define QS_DISC1 0x02
172#define QS_DISC2 0x04
173#define QS_BUSY 0x08
174#define QS_ABORTED 0x40
175#define QS_DONE 0x80
176#define QC_NO_CALLBACK 0x01
177#define QC_SG_SWAP_QUEUE 0x02
178#define QC_SG_HEAD 0x04
179#define QC_DATA_IN 0x08
180#define QC_DATA_OUT 0x10
181#define QC_URGENT 0x20
182#define QC_MSG_OUT 0x40
183#define QC_REQ_SENSE 0x80
184#define QCSG_SG_XFER_LIST 0x02
185#define QCSG_SG_XFER_MORE 0x04
186#define QCSG_SG_XFER_END 0x08
187#define QD_IN_PROGRESS 0x00
188#define QD_NO_ERROR 0x01
189#define QD_ABORTED_BY_HOST 0x02
190#define QD_WITH_ERROR 0x04
191#define QD_INVALID_REQUEST 0x80
192#define QD_INVALID_HOST_NUM 0x81
193#define QD_INVALID_DEVICE 0x82
194#define QD_ERR_INTERNAL 0xFF
195#define QHSTA_NO_ERROR 0x00
196#define QHSTA_M_SEL_TIMEOUT 0x11
197#define QHSTA_M_DATA_OVER_RUN 0x12
198#define QHSTA_M_DATA_UNDER_RUN 0x12
199#define QHSTA_M_UNEXPECTED_BUS_FREE 0x13
200#define QHSTA_M_BAD_BUS_PHASE_SEQ 0x14
201#define QHSTA_D_QDONE_SG_LIST_CORRUPTED 0x21
202#define QHSTA_D_ASC_DVC_ERROR_CODE_SET 0x22
203#define QHSTA_D_HOST_ABORT_FAILED 0x23
204#define QHSTA_D_EXE_SCSI_Q_FAILED 0x24
205#define QHSTA_D_EXE_SCSI_Q_BUSY_TIMEOUT 0x25
206#define QHSTA_D_ASPI_NO_BUF_POOL 0x26
207#define QHSTA_M_WTM_TIMEOUT 0x41
208#define QHSTA_M_BAD_CMPL_STATUS_IN 0x42
209#define QHSTA_M_NO_AUTO_REQ_SENSE 0x43
210#define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
211#define QHSTA_M_TARGET_STATUS_BUSY 0x45
212#define QHSTA_M_BAD_TAG_CODE 0x46
213#define QHSTA_M_BAD_QUEUE_FULL_OR_BUSY 0x47
214#define QHSTA_M_HUNG_REQ_SCSI_BUS_RESET 0x48
215#define QHSTA_D_LRAM_CMP_ERROR 0x81
216#define QHSTA_M_MICRO_CODE_ERROR_HALT 0xA1
217#define ASC_FLAG_SCSIQ_REQ 0x01
218#define ASC_FLAG_BIOS_SCSIQ_REQ 0x02
219#define ASC_FLAG_BIOS_ASYNC_IO 0x04
220#define ASC_FLAG_SRB_LINEAR_ADDR 0x08
221#define ASC_FLAG_WIN16 0x10
222#define ASC_FLAG_WIN32 0x20
223#define ASC_FLAG_ISA_OVER_16MB 0x40
224#define ASC_FLAG_DOS_VM_CALLBACK 0x80
225#define ASC_TAG_FLAG_EXTRA_BYTES 0x10
226#define ASC_TAG_FLAG_DISABLE_DISCONNECT 0x04
227#define ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX 0x08
228#define ASC_TAG_FLAG_DISABLE_CHK_COND_INT_HOST 0x40
229#define ASC_SCSIQ_CPY_BEG 4
230#define ASC_SCSIQ_SGHD_CPY_BEG 2
231#define ASC_SCSIQ_B_FWD 0
232#define ASC_SCSIQ_B_BWD 1
233#define ASC_SCSIQ_B_STATUS 2
234#define ASC_SCSIQ_B_QNO 3
235#define ASC_SCSIQ_B_CNTL 4
236#define ASC_SCSIQ_B_SG_QUEUE_CNT 5
237#define ASC_SCSIQ_D_DATA_ADDR 8
238#define ASC_SCSIQ_D_DATA_CNT 12
239#define ASC_SCSIQ_B_SENSE_LEN 20
240#define ASC_SCSIQ_DONE_INFO_BEG 22
241#define ASC_SCSIQ_D_SRBPTR 22
242#define ASC_SCSIQ_B_TARGET_IX 26
243#define ASC_SCSIQ_B_CDB_LEN 28
244#define ASC_SCSIQ_B_TAG_CODE 29
245#define ASC_SCSIQ_W_VM_ID 30
246#define ASC_SCSIQ_DONE_STATUS 32
247#define ASC_SCSIQ_HOST_STATUS 33
248#define ASC_SCSIQ_SCSI_STATUS 34
249#define ASC_SCSIQ_CDB_BEG 36
250#define ASC_SCSIQ_DW_REMAIN_XFER_ADDR 56
251#define ASC_SCSIQ_DW_REMAIN_XFER_CNT 60
252#define ASC_SCSIQ_B_FIRST_SG_WK_QP 48
253#define ASC_SCSIQ_B_SG_WK_QP 49
254#define ASC_SCSIQ_B_SG_WK_IX 50
255#define ASC_SCSIQ_W_ALT_DC1 52
256#define ASC_SCSIQ_B_LIST_CNT 6
257#define ASC_SCSIQ_B_CUR_LIST_CNT 7
258#define ASC_SGQ_B_SG_CNTL 4
259#define ASC_SGQ_B_SG_HEAD_QP 5
260#define ASC_SGQ_B_SG_LIST_CNT 6
261#define ASC_SGQ_B_SG_CUR_LIST_CNT 7
262#define ASC_SGQ_LIST_BEG 8
263#define ASC_DEF_SCSI1_QNG 4
264#define ASC_MAX_SCSI1_QNG 4
265#define ASC_DEF_SCSI2_QNG 16
266#define ASC_MAX_SCSI2_QNG 32
267#define ASC_TAG_CODE_MASK 0x23
268#define ASC_STOP_REQ_RISC_STOP 0x01
269#define ASC_STOP_ACK_RISC_STOP 0x03
270#define ASC_STOP_CLEAN_UP_BUSY_Q 0x10
271#define ASC_STOP_CLEAN_UP_DISC_Q 0x20
272#define ASC_STOP_HOST_REQ_RISC_HALT 0x40
273#define ASC_TIDLUN_TO_IX(tid, lun) (ASC_SCSI_TIX_TYPE)((tid) + ((lun)<<ASC_SCSI_ID_BITS))
274#define ASC_TID_TO_TARGET_ID(tid) (ASC_SCSI_BIT_ID_TYPE)(0x01 << (tid))
275#define ASC_TIX_TO_TARGET_ID(tix) (0x01 << ((tix) & ASC_MAX_TID))
276#define ASC_TIX_TO_TID(tix) ((tix) & ASC_MAX_TID)
277#define ASC_TID_TO_TIX(tid) ((tid) & ASC_MAX_TID)
278#define ASC_TIX_TO_LUN(tix) (((tix) >> ASC_SCSI_ID_BITS) & ASC_MAX_LUN)
279#define ASC_QNO_TO_QADDR(q_no) ((ASC_QADR_BEG)+((int)(q_no) << 6))
280
281typedef struct asc_scsiq_1 {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400282 uchar status;
283 uchar q_no;
284 uchar cntl;
285 uchar sg_queue_cnt;
286 uchar target_id;
287 uchar target_lun;
Hannes Reinecke95cfab62015-04-24 13:18:27 +0200288 __le32 data_addr;
289 __le32 data_cnt;
290 __le32 sense_addr;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400291 uchar sense_len;
292 uchar extra_bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293} ASC_SCSIQ_1;
294
295typedef struct asc_scsiq_2 {
Hannes Reinecke9c17c622015-04-24 13:18:21 +0200296 u32 srb_tag;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400297 uchar target_ix;
298 uchar flag;
299 uchar cdb_len;
300 uchar tag_code;
301 ushort vm_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302} ASC_SCSIQ_2;
303
304typedef struct asc_scsiq_3 {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400305 uchar done_stat;
306 uchar host_stat;
307 uchar scsi_stat;
308 uchar scsi_msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309} ASC_SCSIQ_3;
310
311typedef struct asc_scsiq_4 {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400312 uchar cdb[ASC_MAX_CDB_LEN];
313 uchar y_first_sg_list_qp;
314 uchar y_working_sg_qp;
315 uchar y_working_sg_ix;
316 uchar y_res;
317 ushort x_req_count;
318 ushort x_reconnect_rtn;
Hannes Reinecke95cfab62015-04-24 13:18:27 +0200319 __le32 x_saved_data_addr;
320 __le32 x_saved_data_cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321} ASC_SCSIQ_4;
322
323typedef struct asc_q_done_info {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400324 ASC_SCSIQ_2 d2;
325 ASC_SCSIQ_3 d3;
326 uchar q_status;
327 uchar q_no;
328 uchar cntl;
329 uchar sense_len;
330 uchar extra_bytes;
331 uchar res;
Hannes Reinecke95cfab62015-04-24 13:18:27 +0200332 u32 remain_bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333} ASC_QDONE_INFO;
334
335typedef struct asc_sg_list {
Hannes Reinecke95cfab62015-04-24 13:18:27 +0200336 __le32 addr;
337 __le32 bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338} ASC_SG_LIST;
339
340typedef struct asc_sg_head {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400341 ushort entry_cnt;
342 ushort queue_cnt;
343 ushort entry_to_copy;
344 ushort res;
Matthew Wilcox05848b62007-10-02 21:55:25 -0400345 ASC_SG_LIST sg_list[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346} ASC_SG_HEAD;
347
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348typedef struct asc_scsi_q {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400349 ASC_SCSIQ_1 q1;
350 ASC_SCSIQ_2 q2;
351 uchar *cdbptr;
352 ASC_SG_HEAD *sg_head;
353 ushort remain_sg_entry_cnt;
354 ushort next_sg_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355} ASC_SCSI_Q;
356
357typedef struct asc_scsi_req_q {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400358 ASC_SCSIQ_1 r1;
359 ASC_SCSIQ_2 r2;
360 uchar *cdbptr;
361 ASC_SG_HEAD *sg_head;
362 uchar *sense_ptr;
363 ASC_SCSIQ_3 r3;
364 uchar cdb[ASC_MAX_CDB_LEN];
365 uchar sense[ASC_MIN_SENSE_LEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366} ASC_SCSI_REQ_Q;
367
368typedef struct asc_scsi_bios_req_q {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400369 ASC_SCSIQ_1 r1;
370 ASC_SCSIQ_2 r2;
371 uchar *cdbptr;
372 ASC_SG_HEAD *sg_head;
373 uchar *sense_ptr;
374 ASC_SCSIQ_3 r3;
375 uchar cdb[ASC_MAX_CDB_LEN];
376 uchar sense[ASC_MIN_SENSE_LEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377} ASC_SCSI_BIOS_REQ_Q;
378
379typedef struct asc_risc_q {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400380 uchar fwd;
381 uchar bwd;
382 ASC_SCSIQ_1 i1;
383 ASC_SCSIQ_2 i2;
384 ASC_SCSIQ_3 i3;
385 ASC_SCSIQ_4 i4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386} ASC_RISC_Q;
387
388typedef struct asc_sg_list_q {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400389 uchar seq_no;
390 uchar q_no;
391 uchar cntl;
392 uchar sg_head_qp;
393 uchar sg_list_cnt;
394 uchar sg_cur_list_cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395} ASC_SG_LIST_Q;
396
397typedef struct asc_risc_sg_list_q {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400398 uchar fwd;
399 uchar bwd;
400 ASC_SG_LIST_Q sg;
401 ASC_SG_LIST sg_list[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402} ASC_RISC_SG_LIST_Q;
403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404#define ASCQ_ERR_Q_STATUS 0x0D
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405#define ASCQ_ERR_CUR_QNG 0x17
406#define ASCQ_ERR_SG_Q_LINKS 0x18
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407#define ASCQ_ERR_ISR_RE_ENTRY 0x1A
408#define ASCQ_ERR_CRITICAL_RE_ENTRY 0x1B
409#define ASCQ_ERR_ISR_ON_CRITICAL 0x1C
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
411/*
412 * Warning code values are set in ASC_DVC_VAR 'warn_code'.
413 */
414#define ASC_WARN_NO_ERROR 0x0000
415#define ASC_WARN_IO_PORT_ROTATE 0x0001
416#define ASC_WARN_EEPROM_CHKSUM 0x0002
417#define ASC_WARN_IRQ_MODIFIED 0x0004
418#define ASC_WARN_AUTO_CONFIG 0x0008
419#define ASC_WARN_CMD_QNG_CONFLICT 0x0010
420#define ASC_WARN_EEPROM_RECOVER 0x0020
421#define ASC_WARN_CFG_MSW_RECOVER 0x0040
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
423/*
Matthew Wilcox720349a2007-10-02 21:55:30 -0400424 * Error code values are set in {ASC/ADV}_DVC_VAR 'err_code'.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 */
Matthew Wilcox720349a2007-10-02 21:55:30 -0400426#define ASC_IERR_NO_CARRIER 0x0001 /* No more carrier memory */
427#define ASC_IERR_MCODE_CHKSUM 0x0002 /* micro code check sum error */
428#define ASC_IERR_SET_PC_ADDR 0x0004
429#define ASC_IERR_START_STOP_CHIP 0x0008 /* start/stop chip failed */
430#define ASC_IERR_ILLEGAL_CONNECTION 0x0010 /* Illegal cable connection */
431#define ASC_IERR_SINGLE_END_DEVICE 0x0020 /* SE device on DIFF bus */
432#define ASC_IERR_REVERSED_CABLE 0x0040 /* Narrow flat cable reversed */
433#define ASC_IERR_SET_SCSI_ID 0x0080 /* set SCSI ID failed */
434#define ASC_IERR_HVD_DEVICE 0x0100 /* HVD device on LVD port */
435#define ASC_IERR_BAD_SIGNATURE 0x0200 /* signature not found */
436#define ASC_IERR_NO_BUS_TYPE 0x0400
437#define ASC_IERR_BIST_PRE_TEST 0x0800 /* BIST pre-test error */
438#define ASC_IERR_BIST_RAM_TEST 0x1000 /* BIST RAM test error */
439#define ASC_IERR_BAD_CHIPTYPE 0x2000 /* Invalid chip_type setting */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441#define ASC_DEF_MAX_TOTAL_QNG (0xF0)
442#define ASC_MIN_TAG_Q_PER_DVC (0x04)
Matthew Wilcox95c9f162007-09-09 08:56:39 -0600443#define ASC_MIN_FREE_Q (0x02)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444#define ASC_MIN_TOTAL_QNG ((ASC_MAX_SG_QUEUE)+(ASC_MIN_FREE_Q))
445#define ASC_MAX_TOTAL_QNG 240
446#define ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG 16
447#define ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG 8
448#define ASC_MAX_PCI_INRAM_TOTAL_QNG 20
449#define ASC_MAX_INRAM_TAG_QNG 16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450#define ASC_IOADR_GAP 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451#define ASC_SYN_MAX_OFFSET 0x0F
452#define ASC_DEF_SDTR_OFFSET 0x0F
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453#define ASC_SDTR_ULTRA_PCI_10MB_INDEX 0x02
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -0400454#define ASYN_SDTR_DATA_FIX_PCI_REV_AB 0x41
455
456/* The narrow chip only supports a limited selection of transfer rates.
457 * These are encoded in the range 0..7 or 0..15 depending whether the chip
458 * is Ultra-capable or not. These tables let us convert from one to the other.
459 */
460static const unsigned char asc_syn_xfer_period[8] = {
461 25, 30, 35, 40, 50, 60, 70, 85
462};
463
464static const unsigned char asc_syn_ultra_xfer_period[16] = {
465 12, 19, 25, 32, 38, 44, 50, 57, 63, 69, 75, 82, 88, 94, 100, 107
466};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
468typedef struct ext_msg {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400469 uchar msg_type;
470 uchar msg_len;
471 uchar msg_req;
472 union {
473 struct {
474 uchar sdtr_xfer_period;
475 uchar sdtr_req_ack_offset;
476 } sdtr;
477 struct {
478 uchar wdtr_width;
479 } wdtr;
480 struct {
481 uchar mdp_b3;
482 uchar mdp_b2;
483 uchar mdp_b1;
484 uchar mdp_b0;
485 } mdp;
486 } u_ext_msg;
487 uchar res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488} EXT_MSG;
489
490#define xfer_period u_ext_msg.sdtr.sdtr_xfer_period
491#define req_ack_offset u_ext_msg.sdtr.sdtr_req_ack_offset
492#define wdtr_width u_ext_msg.wdtr.wdtr_width
493#define mdp_b3 u_ext_msg.mdp_b3
494#define mdp_b2 u_ext_msg.mdp_b2
495#define mdp_b1 u_ext_msg.mdp_b1
496#define mdp_b0 u_ext_msg.mdp_b0
497
498typedef struct asc_dvc_cfg {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400499 ASC_SCSI_BIT_ID_TYPE can_tagged_qng;
500 ASC_SCSI_BIT_ID_TYPE cmd_qng_enabled;
501 ASC_SCSI_BIT_ID_TYPE disc_enable;
502 ASC_SCSI_BIT_ID_TYPE sdtr_enable;
503 uchar chip_scsi_id;
504 uchar isa_dma_speed;
505 uchar isa_dma_channel;
506 uchar chip_version;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400507 ushort mcode_date;
508 ushort mcode_version;
509 uchar max_tag_qng[ASC_MAX_TID + 1];
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400510 uchar sdtr_period_offset[ASC_MAX_TID + 1];
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400511 uchar adapter_info[6];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512} ASC_DVC_CFG;
513
514#define ASC_DEF_DVC_CNTL 0xFFFF
515#define ASC_DEF_CHIP_SCSI_ID 7
516#define ASC_DEF_ISA_DMA_SPEED 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517#define ASC_INIT_STATE_BEG_GET_CFG 0x0001
518#define ASC_INIT_STATE_END_GET_CFG 0x0002
519#define ASC_INIT_STATE_BEG_SET_CFG 0x0004
520#define ASC_INIT_STATE_END_SET_CFG 0x0008
521#define ASC_INIT_STATE_BEG_LOAD_MC 0x0010
522#define ASC_INIT_STATE_END_LOAD_MC 0x0020
523#define ASC_INIT_STATE_BEG_INQUIRY 0x0040
524#define ASC_INIT_STATE_END_INQUIRY 0x0080
525#define ASC_INIT_RESET_SCSI_DONE 0x0100
526#define ASC_INIT_STATE_WITHOUT_EEP 0x8000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527#define ASC_BUG_FIX_IF_NOT_DWB 0x0001
528#define ASC_BUG_FIX_ASYN_USE_SYN 0x0002
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529#define ASC_MIN_TAGGED_CMD 7
530#define ASC_MAX_SCSI_RESET_WAIT 30
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -0400531#define ASC_OVERRUN_BSIZE 64
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400533struct asc_dvc_var; /* Forward Declaration. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535typedef struct asc_dvc_var {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400536 PortAddr iop_base;
537 ushort err_code;
538 ushort dvc_cntl;
539 ushort bug_fix_cntl;
540 ushort bus_type;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400541 ASC_SCSI_BIT_ID_TYPE init_sdtr;
542 ASC_SCSI_BIT_ID_TYPE sdtr_done;
543 ASC_SCSI_BIT_ID_TYPE use_tagged_qng;
544 ASC_SCSI_BIT_ID_TYPE unit_not_ready;
545 ASC_SCSI_BIT_ID_TYPE queue_full_or_busy;
546 ASC_SCSI_BIT_ID_TYPE start_motor;
FUJITA Tomonori7d5d4082008-02-08 09:50:08 +0900547 uchar *overrun_buf;
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -0400548 dma_addr_t overrun_dma;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400549 uchar scsi_reset_wait;
550 uchar chip_no;
Hannes Reineckeae267592015-04-24 13:18:28 +0200551 bool is_in_int;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400552 uchar max_total_qng;
553 uchar cur_total_qng;
554 uchar in_critical_cnt;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400555 uchar last_q_shortage;
556 ushort init_state;
557 uchar cur_dvc_qng[ASC_MAX_TID + 1];
558 uchar max_dvc_qng[ASC_MAX_TID + 1];
559 ASC_SCSI_Q *scsiq_busy_head[ASC_MAX_TID + 1];
560 ASC_SCSI_Q *scsiq_busy_tail[ASC_MAX_TID + 1];
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -0400561 const uchar *sdtr_period_tbl;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400562 ASC_DVC_CFG *cfg;
563 ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer_always;
564 char redo_scam;
565 ushort res2;
566 uchar dos_int13_table[ASC_MAX_TID + 1];
Hannes Reinecke95cfab62015-04-24 13:18:27 +0200567 unsigned int max_dma_count;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400568 ASC_SCSI_BIT_ID_TYPE no_scam;
569 ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer;
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -0400570 uchar min_sdtr_index;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400571 uchar max_sdtr_index;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400572 struct asc_board *drv_ptr;
Hannes Reinecke95cfab62015-04-24 13:18:27 +0200573 unsigned int uc_break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574} ASC_DVC_VAR;
575
576typedef struct asc_dvc_inq_info {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400577 uchar type[ASC_MAX_TID + 1][ASC_MAX_LUN + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578} ASC_DVC_INQ_INFO;
579
580typedef struct asc_cap_info {
Hannes Reinecke95cfab62015-04-24 13:18:27 +0200581 u32 lba;
582 u32 blk_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583} ASC_CAP_INFO;
584
585typedef struct asc_cap_info_array {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400586 ASC_CAP_INFO cap_info[ASC_MAX_TID + 1][ASC_MAX_LUN + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587} ASC_CAP_INFO_ARRAY;
588
589#define ASC_MCNTL_NO_SEL_TIMEOUT (ushort)0x0001
590#define ASC_MCNTL_NULL_TARGET (ushort)0x0002
591#define ASC_CNTL_INITIATOR (ushort)0x0001
592#define ASC_CNTL_BIOS_GT_1GB (ushort)0x0002
593#define ASC_CNTL_BIOS_GT_2_DISK (ushort)0x0004
594#define ASC_CNTL_BIOS_REMOVABLE (ushort)0x0008
595#define ASC_CNTL_NO_SCAM (ushort)0x0010
596#define ASC_CNTL_INT_MULTI_Q (ushort)0x0080
597#define ASC_CNTL_NO_LUN_SUPPORT (ushort)0x0040
598#define ASC_CNTL_NO_VERIFY_COPY (ushort)0x0100
599#define ASC_CNTL_RESET_SCSI (ushort)0x0200
600#define ASC_CNTL_INIT_INQUIRY (ushort)0x0400
601#define ASC_CNTL_INIT_VERBOSE (ushort)0x0800
602#define ASC_CNTL_SCSI_PARITY (ushort)0x1000
603#define ASC_CNTL_BURST_MODE (ushort)0x2000
604#define ASC_CNTL_SDTR_ENABLE_ULTRA (ushort)0x4000
605#define ASC_EEP_DVC_CFG_BEG_VL 2
606#define ASC_EEP_MAX_DVC_ADDR_VL 15
607#define ASC_EEP_DVC_CFG_BEG 32
608#define ASC_EEP_MAX_DVC_ADDR 45
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609#define ASC_EEP_MAX_RETRY 20
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
611/*
612 * These macros keep the chip SCSI id and ISA DMA speed
613 * bitfields in board order. C bitfields aren't portable
614 * between big and little-endian platforms so they are
615 * not used.
616 */
617
618#define ASC_EEP_GET_CHIP_ID(cfg) ((cfg)->id_speed & 0x0f)
619#define ASC_EEP_GET_DMA_SPD(cfg) (((cfg)->id_speed & 0xf0) >> 4)
620#define ASC_EEP_SET_CHIP_ID(cfg, sid) \
621 ((cfg)->id_speed = ((cfg)->id_speed & 0xf0) | ((sid) & ASC_MAX_TID))
622#define ASC_EEP_SET_DMA_SPD(cfg, spd) \
623 ((cfg)->id_speed = ((cfg)->id_speed & 0x0f) | ((spd) & 0x0f) << 4)
624
625typedef struct asceep_config {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400626 ushort cfg_lsw;
627 ushort cfg_msw;
628 uchar init_sdtr;
629 uchar disc_enable;
630 uchar use_cmd_qng;
631 uchar start_motor;
632 uchar max_total_qng;
633 uchar max_tag_qng;
634 uchar bios_scan;
635 uchar power_up_wait;
636 uchar no_scam;
637 uchar id_speed; /* low order 4 bits is chip scsi id */
638 /* high order 4 bits is isa dma speed */
639 uchar dos_int13_table[ASC_MAX_TID + 1];
640 uchar adapter_info[6];
641 ushort cntl;
642 ushort chksum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643} ASCEEP_CONFIG;
644
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645#define ASC_EEP_CMD_READ 0x80
646#define ASC_EEP_CMD_WRITE 0x40
647#define ASC_EEP_CMD_WRITE_ABLE 0x30
648#define ASC_EEP_CMD_WRITE_DISABLE 0x00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649#define ASCV_MSGOUT_BEG 0x0000
650#define ASCV_MSGOUT_SDTR_PERIOD (ASCV_MSGOUT_BEG+3)
651#define ASCV_MSGOUT_SDTR_OFFSET (ASCV_MSGOUT_BEG+4)
652#define ASCV_BREAK_SAVED_CODE (ushort)0x0006
653#define ASCV_MSGIN_BEG (ASCV_MSGOUT_BEG+8)
654#define ASCV_MSGIN_SDTR_PERIOD (ASCV_MSGIN_BEG+3)
655#define ASCV_MSGIN_SDTR_OFFSET (ASCV_MSGIN_BEG+4)
656#define ASCV_SDTR_DATA_BEG (ASCV_MSGIN_BEG+8)
657#define ASCV_SDTR_DONE_BEG (ASCV_SDTR_DATA_BEG+8)
658#define ASCV_MAX_DVC_QNG_BEG (ushort)0x0020
659#define ASCV_BREAK_ADDR (ushort)0x0028
660#define ASCV_BREAK_NOTIFY_COUNT (ushort)0x002A
661#define ASCV_BREAK_CONTROL (ushort)0x002C
662#define ASCV_BREAK_HIT_COUNT (ushort)0x002E
663
664#define ASCV_ASCDVC_ERR_CODE_W (ushort)0x0030
665#define ASCV_MCODE_CHKSUM_W (ushort)0x0032
666#define ASCV_MCODE_SIZE_W (ushort)0x0034
667#define ASCV_STOP_CODE_B (ushort)0x0036
668#define ASCV_DVC_ERR_CODE_B (ushort)0x0037
669#define ASCV_OVERRUN_PADDR_D (ushort)0x0038
670#define ASCV_OVERRUN_BSIZE_D (ushort)0x003C
671#define ASCV_HALTCODE_W (ushort)0x0040
672#define ASCV_CHKSUM_W (ushort)0x0042
673#define ASCV_MC_DATE_W (ushort)0x0044
674#define ASCV_MC_VER_W (ushort)0x0046
675#define ASCV_NEXTRDY_B (ushort)0x0048
676#define ASCV_DONENEXT_B (ushort)0x0049
677#define ASCV_USE_TAGGED_QNG_B (ushort)0x004A
678#define ASCV_SCSIBUSY_B (ushort)0x004B
679#define ASCV_Q_DONE_IN_PROGRESS_B (ushort)0x004C
680#define ASCV_CURCDB_B (ushort)0x004D
681#define ASCV_RCLUN_B (ushort)0x004E
682#define ASCV_BUSY_QHEAD_B (ushort)0x004F
683#define ASCV_DISC1_QHEAD_B (ushort)0x0050
684#define ASCV_DISC_ENABLE_B (ushort)0x0052
685#define ASCV_CAN_TAGGED_QNG_B (ushort)0x0053
686#define ASCV_HOSTSCSI_ID_B (ushort)0x0055
687#define ASCV_MCODE_CNTL_B (ushort)0x0056
688#define ASCV_NULL_TARGET_B (ushort)0x0057
689#define ASCV_FREE_Q_HEAD_W (ushort)0x0058
690#define ASCV_DONE_Q_TAIL_W (ushort)0x005A
691#define ASCV_FREE_Q_HEAD_B (ushort)(ASCV_FREE_Q_HEAD_W+1)
692#define ASCV_DONE_Q_TAIL_B (ushort)(ASCV_DONE_Q_TAIL_W+1)
693#define ASCV_HOST_FLAG_B (ushort)0x005D
694#define ASCV_TOTAL_READY_Q_B (ushort)0x0064
695#define ASCV_VER_SERIAL_B (ushort)0x0065
696#define ASCV_HALTCODE_SAVED_W (ushort)0x0066
697#define ASCV_WTM_FLAG_B (ushort)0x0068
698#define ASCV_RISC_FLAG_B (ushort)0x006A
699#define ASCV_REQ_SG_LIST_QP (ushort)0x006B
700#define ASC_HOST_FLAG_IN_ISR 0x01
701#define ASC_HOST_FLAG_ACK_INT 0x02
702#define ASC_RISC_FLAG_GEN_INT 0x01
703#define ASC_RISC_FLAG_REQ_SG_LIST 0x02
704#define IOP_CTRL (0x0F)
705#define IOP_STATUS (0x0E)
706#define IOP_INT_ACK IOP_STATUS
707#define IOP_REG_IFC (0x0D)
708#define IOP_SYN_OFFSET (0x0B)
709#define IOP_EXTRA_CONTROL (0x0D)
710#define IOP_REG_PC (0x0C)
711#define IOP_RAM_ADDR (0x0A)
712#define IOP_RAM_DATA (0x08)
713#define IOP_EEP_DATA (0x06)
714#define IOP_EEP_CMD (0x07)
715#define IOP_VERSION (0x03)
716#define IOP_CONFIG_HIGH (0x04)
717#define IOP_CONFIG_LOW (0x02)
718#define IOP_SIG_BYTE (0x01)
719#define IOP_SIG_WORD (0x00)
720#define IOP_REG_DC1 (0x0E)
721#define IOP_REG_DC0 (0x0C)
722#define IOP_REG_SB (0x0B)
723#define IOP_REG_DA1 (0x0A)
724#define IOP_REG_DA0 (0x08)
725#define IOP_REG_SC (0x09)
726#define IOP_DMA_SPEED (0x07)
727#define IOP_REG_FLAG (0x07)
728#define IOP_FIFO_H (0x06)
729#define IOP_FIFO_L (0x04)
730#define IOP_REG_ID (0x05)
731#define IOP_REG_QP (0x03)
732#define IOP_REG_IH (0x02)
733#define IOP_REG_IX (0x01)
734#define IOP_REG_AX (0x00)
735#define IFC_REG_LOCK (0x00)
736#define IFC_REG_UNLOCK (0x09)
737#define IFC_WR_EN_FILTER (0x10)
738#define IFC_RD_NO_EEPROM (0x10)
739#define IFC_SLEW_RATE (0x20)
740#define IFC_ACT_NEG (0x40)
741#define IFC_INP_FILTER (0x80)
742#define IFC_INIT_DEFAULT (IFC_ACT_NEG | IFC_REG_UNLOCK)
743#define SC_SEL (uchar)(0x80)
744#define SC_BSY (uchar)(0x40)
745#define SC_ACK (uchar)(0x20)
746#define SC_REQ (uchar)(0x10)
747#define SC_ATN (uchar)(0x08)
748#define SC_IO (uchar)(0x04)
749#define SC_CD (uchar)(0x02)
750#define SC_MSG (uchar)(0x01)
751#define SEC_SCSI_CTL (uchar)(0x80)
752#define SEC_ACTIVE_NEGATE (uchar)(0x40)
753#define SEC_SLEW_RATE (uchar)(0x20)
754#define SEC_ENABLE_FILTER (uchar)(0x10)
755#define ASC_HALT_EXTMSG_IN (ushort)0x8000
756#define ASC_HALT_CHK_CONDITION (ushort)0x8100
757#define ASC_HALT_SS_QUEUE_FULL (ushort)0x8200
758#define ASC_HALT_DISABLE_ASYN_USE_SYN_FIX (ushort)0x8300
759#define ASC_HALT_ENABLE_ASYN_USE_SYN_FIX (ushort)0x8400
760#define ASC_HALT_SDTR_REJECTED (ushort)0x4000
761#define ASC_HALT_HOST_COPY_SG_LIST_TO_RISC ( ushort )0x2000
762#define ASC_MAX_QNO 0xF8
763#define ASC_DATA_SEC_BEG (ushort)0x0080
764#define ASC_DATA_SEC_END (ushort)0x0080
765#define ASC_CODE_SEC_BEG (ushort)0x0080
766#define ASC_CODE_SEC_END (ushort)0x0080
767#define ASC_QADR_BEG (0x4000)
768#define ASC_QADR_USED (ushort)(ASC_MAX_QNO * 64)
769#define ASC_QADR_END (ushort)0x7FFF
770#define ASC_QLAST_ADR (ushort)0x7FC0
771#define ASC_QBLK_SIZE 0x40
772#define ASC_BIOS_DATA_QBEG 0xF8
773#define ASC_MIN_ACTIVE_QNO 0x01
774#define ASC_QLINK_END 0xFF
775#define ASC_EEPROM_WORDS 0x10
776#define ASC_MAX_MGS_LEN 0x10
777#define ASC_BIOS_ADDR_DEF 0xDC00
778#define ASC_BIOS_SIZE 0x3800
779#define ASC_BIOS_RAM_OFF 0x3800
780#define ASC_BIOS_RAM_SIZE 0x800
781#define ASC_BIOS_MIN_ADDR 0xC000
782#define ASC_BIOS_MAX_ADDR 0xEC00
783#define ASC_BIOS_BANK_SIZE 0x0400
784#define ASC_MCODE_START_ADDR 0x0080
785#define ASC_CFG0_HOST_INT_ON 0x0020
786#define ASC_CFG0_BIOS_ON 0x0040
787#define ASC_CFG0_VERA_BURST_ON 0x0080
788#define ASC_CFG0_SCSI_PARITY_ON 0x0800
789#define ASC_CFG1_SCSI_TARGET_ON 0x0080
790#define ASC_CFG1_LRAM_8BITS_ON 0x0800
791#define ASC_CFG_MSW_CLR_MASK 0x3080
792#define CSW_TEST1 (ASC_CS_TYPE)0x8000
793#define CSW_AUTO_CONFIG (ASC_CS_TYPE)0x4000
794#define CSW_RESERVED1 (ASC_CS_TYPE)0x2000
795#define CSW_IRQ_WRITTEN (ASC_CS_TYPE)0x1000
796#define CSW_33MHZ_SELECTED (ASC_CS_TYPE)0x0800
797#define CSW_TEST2 (ASC_CS_TYPE)0x0400
798#define CSW_TEST3 (ASC_CS_TYPE)0x0200
799#define CSW_RESERVED2 (ASC_CS_TYPE)0x0100
800#define CSW_DMA_DONE (ASC_CS_TYPE)0x0080
801#define CSW_FIFO_RDY (ASC_CS_TYPE)0x0040
802#define CSW_EEP_READ_DONE (ASC_CS_TYPE)0x0020
803#define CSW_HALTED (ASC_CS_TYPE)0x0010
804#define CSW_SCSI_RESET_ACTIVE (ASC_CS_TYPE)0x0008
805#define CSW_PARITY_ERR (ASC_CS_TYPE)0x0004
806#define CSW_SCSI_RESET_LATCH (ASC_CS_TYPE)0x0002
807#define CSW_INT_PENDING (ASC_CS_TYPE)0x0001
808#define CIW_CLR_SCSI_RESET_INT (ASC_CS_TYPE)0x1000
809#define CIW_INT_ACK (ASC_CS_TYPE)0x0100
810#define CIW_TEST1 (ASC_CS_TYPE)0x0200
811#define CIW_TEST2 (ASC_CS_TYPE)0x0400
812#define CIW_SEL_33MHZ (ASC_CS_TYPE)0x0800
813#define CIW_IRQ_ACT (ASC_CS_TYPE)0x1000
814#define CC_CHIP_RESET (uchar)0x80
815#define CC_SCSI_RESET (uchar)0x40
816#define CC_HALT (uchar)0x20
817#define CC_SINGLE_STEP (uchar)0x10
818#define CC_DMA_ABLE (uchar)0x08
819#define CC_TEST (uchar)0x04
820#define CC_BANK_ONE (uchar)0x02
821#define CC_DIAG (uchar)0x01
822#define ASC_1000_ID0W 0x04C1
823#define ASC_1000_ID0W_FIX 0x00C1
824#define ASC_1000_ID1B 0x25
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825#define ASC_EISA_REV_IOP_MASK (0x0C83)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826#define ASC_EISA_CFG_IOP_MASK (0x0C86)
827#define ASC_GET_EISA_SLOT(iop) (PortAddr)((iop) & 0xF000)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828#define INS_HALTINT (ushort)0x6281
829#define INS_HALT (ushort)0x6280
830#define INS_SINT (ushort)0x6200
831#define INS_RFLAG_WTM (ushort)0x7380
832#define ASC_MC_SAVE_CODE_WSIZE 0x500
833#define ASC_MC_SAVE_DATA_WSIZE 0x40
834
835typedef struct asc_mc_saved {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400836 ushort data[ASC_MC_SAVE_DATA_WSIZE];
837 ushort code[ASC_MC_SAVE_CODE_WSIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838} ASC_MC_SAVED;
839
840#define AscGetQDoneInProgress(port) AscReadLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B)
841#define AscPutQDoneInProgress(port, val) AscWriteLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B, val)
842#define AscGetVarFreeQHead(port) AscReadLramWord((port), ASCV_FREE_Q_HEAD_W)
843#define AscGetVarDoneQTail(port) AscReadLramWord((port), ASCV_DONE_Q_TAIL_W)
844#define AscPutVarFreeQHead(port, val) AscWriteLramWord((port), ASCV_FREE_Q_HEAD_W, val)
845#define AscPutVarDoneQTail(port, val) AscWriteLramWord((port), ASCV_DONE_Q_TAIL_W, val)
846#define AscGetRiscVarFreeQHead(port) AscReadLramByte((port), ASCV_NEXTRDY_B)
847#define AscGetRiscVarDoneQTail(port) AscReadLramByte((port), ASCV_DONENEXT_B)
848#define AscPutRiscVarFreeQHead(port, val) AscWriteLramByte((port), ASCV_NEXTRDY_B, val)
849#define AscPutRiscVarDoneQTail(port, val) AscWriteLramByte((port), ASCV_DONENEXT_B, val)
Matthew Wilcox51219352007-10-02 21:55:22 -0400850#define AscPutMCodeSDTRDoneAtID(port, id, data) AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id), (data))
851#define AscGetMCodeSDTRDoneAtID(port, id) AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id))
852#define AscPutMCodeInitSDTRAtID(port, id, data) AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id), data)
853#define AscGetMCodeInitSDTRAtID(port, id) AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854#define AscGetChipSignatureByte(port) (uchar)inp((port)+IOP_SIG_BYTE)
855#define AscGetChipSignatureWord(port) (ushort)inpw((port)+IOP_SIG_WORD)
856#define AscGetChipVerNo(port) (uchar)inp((port)+IOP_VERSION)
857#define AscGetChipCfgLsw(port) (ushort)inpw((port)+IOP_CONFIG_LOW)
858#define AscGetChipCfgMsw(port) (ushort)inpw((port)+IOP_CONFIG_HIGH)
859#define AscSetChipCfgLsw(port, data) outpw((port)+IOP_CONFIG_LOW, data)
860#define AscSetChipCfgMsw(port, data) outpw((port)+IOP_CONFIG_HIGH, data)
861#define AscGetChipEEPCmd(port) (uchar)inp((port)+IOP_EEP_CMD)
862#define AscSetChipEEPCmd(port, data) outp((port)+IOP_EEP_CMD, data)
863#define AscGetChipEEPData(port) (ushort)inpw((port)+IOP_EEP_DATA)
864#define AscSetChipEEPData(port, data) outpw((port)+IOP_EEP_DATA, data)
865#define AscGetChipLramAddr(port) (ushort)inpw((PortAddr)((port)+IOP_RAM_ADDR))
866#define AscSetChipLramAddr(port, addr) outpw((PortAddr)((port)+IOP_RAM_ADDR), addr)
867#define AscGetChipLramData(port) (ushort)inpw((port)+IOP_RAM_DATA)
868#define AscSetChipLramData(port, data) outpw((port)+IOP_RAM_DATA, data)
869#define AscGetChipIFC(port) (uchar)inp((port)+IOP_REG_IFC)
870#define AscSetChipIFC(port, data) outp((port)+IOP_REG_IFC, data)
871#define AscGetChipStatus(port) (ASC_CS_TYPE)inpw((port)+IOP_STATUS)
872#define AscSetChipStatus(port, cs_val) outpw((port)+IOP_STATUS, cs_val)
873#define AscGetChipControl(port) (uchar)inp((port)+IOP_CTRL)
874#define AscSetChipControl(port, cc_val) outp((port)+IOP_CTRL, cc_val)
875#define AscGetChipSyn(port) (uchar)inp((port)+IOP_SYN_OFFSET)
876#define AscSetChipSyn(port, data) outp((port)+IOP_SYN_OFFSET, data)
877#define AscSetPCAddr(port, data) outpw((port)+IOP_REG_PC, data)
878#define AscGetPCAddr(port) (ushort)inpw((port)+IOP_REG_PC)
879#define AscIsIntPending(port) (AscGetChipStatus(port) & (CSW_INT_PENDING | CSW_SCSI_RESET_LATCH))
880#define AscGetChipScsiID(port) ((AscGetChipCfgLsw(port) >> 8) & ASC_MAX_TID)
881#define AscGetExtraControl(port) (uchar)inp((port)+IOP_EXTRA_CONTROL)
882#define AscSetExtraControl(port, data) outp((port)+IOP_EXTRA_CONTROL, data)
883#define AscReadChipAX(port) (ushort)inpw((port)+IOP_REG_AX)
884#define AscWriteChipAX(port, data) outpw((port)+IOP_REG_AX, data)
885#define AscReadChipIX(port) (uchar)inp((port)+IOP_REG_IX)
886#define AscWriteChipIX(port, data) outp((port)+IOP_REG_IX, data)
887#define AscReadChipIH(port) (ushort)inpw((port)+IOP_REG_IH)
888#define AscWriteChipIH(port, data) outpw((port)+IOP_REG_IH, data)
889#define AscReadChipQP(port) (uchar)inp((port)+IOP_REG_QP)
890#define AscWriteChipQP(port, data) outp((port)+IOP_REG_QP, data)
891#define AscReadChipFIFO_L(port) (ushort)inpw((port)+IOP_REG_FIFO_L)
892#define AscWriteChipFIFO_L(port, data) outpw((port)+IOP_REG_FIFO_L, data)
893#define AscReadChipFIFO_H(port) (ushort)inpw((port)+IOP_REG_FIFO_H)
894#define AscWriteChipFIFO_H(port, data) outpw((port)+IOP_REG_FIFO_H, data)
895#define AscReadChipDmaSpeed(port) (uchar)inp((port)+IOP_DMA_SPEED)
896#define AscWriteChipDmaSpeed(port, data) outp((port)+IOP_DMA_SPEED, data)
897#define AscReadChipDA0(port) (ushort)inpw((port)+IOP_REG_DA0)
898#define AscWriteChipDA0(port) outpw((port)+IOP_REG_DA0, data)
899#define AscReadChipDA1(port) (ushort)inpw((port)+IOP_REG_DA1)
900#define AscWriteChipDA1(port) outpw((port)+IOP_REG_DA1, data)
901#define AscReadChipDC0(port) (ushort)inpw((port)+IOP_REG_DC0)
902#define AscWriteChipDC0(port) outpw((port)+IOP_REG_DC0, data)
903#define AscReadChipDC1(port) (ushort)inpw((port)+IOP_REG_DC1)
904#define AscWriteChipDC1(port) outpw((port)+IOP_REG_DC1, data)
905#define AscReadChipDvcID(port) (uchar)inp((port)+IOP_REG_ID)
906#define AscWriteChipDvcID(port, data) outp((port)+IOP_REG_ID, data)
907
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 * These macros are used to convert a virtual address to a
910 * 32-bit value. This currently can be used on Linux Alpha
911 * which uses 64-bit virtual address but a 32-bit bus address.
912 * This is likely to break in the future, but doing this now
913 * will give us time to change the HW and FW to handle 64-bit
914 * addresses.
915 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916#define ADV_U32_TO_VADDR bus_to_virt
917
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400918#define AdvPortAddr void __iomem * /* Virtual memory address size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
920/*
921 * Define Adv Library required memory access macros.
922 */
923#define ADV_MEM_READB(addr) readb(addr)
924#define ADV_MEM_READW(addr) readw(addr)
925#define ADV_MEM_WRITEB(addr, byte) writeb(byte, addr)
926#define ADV_MEM_WRITEW(addr, word) writew(word, addr)
927#define ADV_MEM_WRITEDW(addr, dword) writel(dword, addr)
928
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 * Define total number of simultaneous maximum element scatter-gather
931 * request blocks per wide adapter. ASC_DEF_MAX_HOST_QNG (253) is the
932 * maximum number of outstanding commands per wide host adapter. Each
933 * command uses one or more ADV_SG_BLOCK each with 15 scatter-gather
934 * elements. Allow each command to have at least one ADV_SG_BLOCK structure.
935 * This allows about 15 commands to have the maximum 17 ADV_SG_BLOCK
936 * structures or 255 scatter-gather elements.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 */
938#define ADV_TOT_SG_BLOCK ASC_DEF_MAX_HOST_QNG
939
940/*
Matthew Wilcox98d41c22007-10-02 21:55:37 -0400941 * Define maximum number of scatter-gather elements per request.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 */
943#define ADV_MAX_SG_LIST 255
Matthew Wilcox98d41c22007-10-02 21:55:37 -0400944#define NO_OF_SG_PER_BLOCK 15
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946#define ADV_EEP_DVC_CFG_BEGIN (0x00)
947#define ADV_EEP_DVC_CFG_END (0x15)
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400948#define ADV_EEP_DVC_CTL_BEGIN (0x16) /* location of OEM name */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949#define ADV_EEP_MAX_WORD_ADDR (0x1E)
950
951#define ADV_EEP_DELAY_MS 100
952
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400953#define ADV_EEPROM_BIG_ENDIAN 0x8000 /* EEPROM Bit 15 */
954#define ADV_EEPROM_BIOS_ENABLE 0x4000 /* EEPROM Bit 14 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955/*
956 * For the ASC3550 Bit 13 is Termination Polarity control bit.
957 * For later ICs Bit 13 controls whether the CIS (Card Information
958 * Service Section) is loaded from EEPROM.
959 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400960#define ADV_EEPROM_TERM_POL 0x2000 /* EEPROM Bit 13 */
961#define ADV_EEPROM_CIS_LD 0x2000 /* EEPROM Bit 13 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962/*
963 * ASC38C1600 Bit 11
964 *
965 * If EEPROM Bit 11 is 0 for Function 0, then Function 0 will specify
966 * INT A in the PCI Configuration Space Int Pin field. If it is 1, then
967 * Function 0 will specify INT B.
968 *
969 * If EEPROM Bit 11 is 0 for Function 1, then Function 1 will specify
970 * INT B in the PCI Configuration Space Int Pin field. If it is 1, then
971 * Function 1 will specify INT A.
972 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400973#define ADV_EEPROM_INTAB 0x0800 /* EEPROM Bit 11 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400975typedef struct adveep_3550_config {
976 /* Word Offset, Description */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400978 ushort cfg_lsw; /* 00 power up initialization */
979 /* bit 13 set - Term Polarity Control */
980 /* bit 14 set - BIOS Enable */
981 /* bit 15 set - Big Endian Mode */
982 ushort cfg_msw; /* 01 unused */
983 ushort disc_enable; /* 02 disconnect enable */
984 ushort wdtr_able; /* 03 Wide DTR able */
985 ushort sdtr_able; /* 04 Synchronous DTR able */
986 ushort start_motor; /* 05 send start up motor */
987 ushort tagqng_able; /* 06 tag queuing able */
988 ushort bios_scan; /* 07 BIOS device control */
989 ushort scam_tolerant; /* 08 no scam */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400991 uchar adapter_scsi_id; /* 09 Host Adapter ID */
992 uchar bios_boot_delay; /* power up wait */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400994 uchar scsi_reset_delay; /* 10 reset delay */
995 uchar bios_id_lun; /* first boot device scsi id & lun */
996 /* high nibble is lun */
997 /* low nibble is scsi id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400999 uchar termination; /* 11 0 - automatic */
1000 /* 1 - low off / high off */
1001 /* 2 - low off / high on */
1002 /* 3 - low on / high on */
1003 /* There is no low on / high off */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001005 uchar reserved1; /* reserved byte (not used) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001007 ushort bios_ctrl; /* 12 BIOS control bits */
1008 /* bit 0 BIOS don't act as initiator. */
1009 /* bit 1 BIOS > 1 GB support */
1010 /* bit 2 BIOS > 2 Disk Support */
1011 /* bit 3 BIOS don't support removables */
1012 /* bit 4 BIOS support bootable CD */
1013 /* bit 5 BIOS scan enabled */
1014 /* bit 6 BIOS support multiple LUNs */
1015 /* bit 7 BIOS display of message */
1016 /* bit 8 SCAM disabled */
1017 /* bit 9 Reset SCSI bus during init. */
1018 /* bit 10 */
1019 /* bit 11 No verbose initialization. */
1020 /* bit 12 SCSI parity enabled */
1021 /* bit 13 */
1022 /* bit 14 */
1023 /* bit 15 */
1024 ushort ultra_able; /* 13 ULTRA speed able */
1025 ushort reserved2; /* 14 reserved */
1026 uchar max_host_qng; /* 15 maximum host queuing */
1027 uchar max_dvc_qng; /* maximum per device queuing */
1028 ushort dvc_cntl; /* 16 control bit for driver */
1029 ushort bug_fix; /* 17 control bit for bug fix */
1030 ushort serial_number_word1; /* 18 Board serial number word 1 */
1031 ushort serial_number_word2; /* 19 Board serial number word 2 */
1032 ushort serial_number_word3; /* 20 Board serial number word 3 */
1033 ushort check_sum; /* 21 EEP check sum */
1034 uchar oem_name[16]; /* 22 OEM name */
1035 ushort dvc_err_code; /* 30 last device driver error code */
1036 ushort adv_err_code; /* 31 last uc and Adv Lib error code */
1037 ushort adv_err_addr; /* 32 last uc error address */
1038 ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
1039 ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
1040 ushort saved_adv_err_addr; /* 35 saved last uc error address */
1041 ushort num_of_err; /* 36 number of error */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042} ADVEEP_3550_CONFIG;
1043
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001044typedef struct adveep_38C0800_config {
1045 /* Word Offset, Description */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001047 ushort cfg_lsw; /* 00 power up initialization */
1048 /* bit 13 set - Load CIS */
1049 /* bit 14 set - BIOS Enable */
1050 /* bit 15 set - Big Endian Mode */
1051 ushort cfg_msw; /* 01 unused */
1052 ushort disc_enable; /* 02 disconnect enable */
1053 ushort wdtr_able; /* 03 Wide DTR able */
1054 ushort sdtr_speed1; /* 04 SDTR Speed TID 0-3 */
1055 ushort start_motor; /* 05 send start up motor */
1056 ushort tagqng_able; /* 06 tag queuing able */
1057 ushort bios_scan; /* 07 BIOS device control */
1058 ushort scam_tolerant; /* 08 no scam */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001060 uchar adapter_scsi_id; /* 09 Host Adapter ID */
1061 uchar bios_boot_delay; /* power up wait */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001063 uchar scsi_reset_delay; /* 10 reset delay */
1064 uchar bios_id_lun; /* first boot device scsi id & lun */
1065 /* high nibble is lun */
1066 /* low nibble is scsi id */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001068 uchar termination_se; /* 11 0 - automatic */
1069 /* 1 - low off / high off */
1070 /* 2 - low off / high on */
1071 /* 3 - low on / high on */
1072 /* There is no low on / high off */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001074 uchar termination_lvd; /* 11 0 - automatic */
1075 /* 1 - low off / high off */
1076 /* 2 - low off / high on */
1077 /* 3 - low on / high on */
1078 /* There is no low on / high off */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001080 ushort bios_ctrl; /* 12 BIOS control bits */
1081 /* bit 0 BIOS don't act as initiator. */
1082 /* bit 1 BIOS > 1 GB support */
1083 /* bit 2 BIOS > 2 Disk Support */
1084 /* bit 3 BIOS don't support removables */
1085 /* bit 4 BIOS support bootable CD */
1086 /* bit 5 BIOS scan enabled */
1087 /* bit 6 BIOS support multiple LUNs */
1088 /* bit 7 BIOS display of message */
1089 /* bit 8 SCAM disabled */
1090 /* bit 9 Reset SCSI bus during init. */
1091 /* bit 10 */
1092 /* bit 11 No verbose initialization. */
1093 /* bit 12 SCSI parity enabled */
1094 /* bit 13 */
1095 /* bit 14 */
1096 /* bit 15 */
1097 ushort sdtr_speed2; /* 13 SDTR speed TID 4-7 */
1098 ushort sdtr_speed3; /* 14 SDTR speed TID 8-11 */
1099 uchar max_host_qng; /* 15 maximum host queueing */
1100 uchar max_dvc_qng; /* maximum per device queuing */
1101 ushort dvc_cntl; /* 16 control bit for driver */
1102 ushort sdtr_speed4; /* 17 SDTR speed 4 TID 12-15 */
1103 ushort serial_number_word1; /* 18 Board serial number word 1 */
1104 ushort serial_number_word2; /* 19 Board serial number word 2 */
1105 ushort serial_number_word3; /* 20 Board serial number word 3 */
1106 ushort check_sum; /* 21 EEP check sum */
1107 uchar oem_name[16]; /* 22 OEM name */
1108 ushort dvc_err_code; /* 30 last device driver error code */
1109 ushort adv_err_code; /* 31 last uc and Adv Lib error code */
1110 ushort adv_err_addr; /* 32 last uc error address */
1111 ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
1112 ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
1113 ushort saved_adv_err_addr; /* 35 saved last uc error address */
1114 ushort reserved36; /* 36 reserved */
1115 ushort reserved37; /* 37 reserved */
1116 ushort reserved38; /* 38 reserved */
1117 ushort reserved39; /* 39 reserved */
1118 ushort reserved40; /* 40 reserved */
1119 ushort reserved41; /* 41 reserved */
1120 ushort reserved42; /* 42 reserved */
1121 ushort reserved43; /* 43 reserved */
1122 ushort reserved44; /* 44 reserved */
1123 ushort reserved45; /* 45 reserved */
1124 ushort reserved46; /* 46 reserved */
1125 ushort reserved47; /* 47 reserved */
1126 ushort reserved48; /* 48 reserved */
1127 ushort reserved49; /* 49 reserved */
1128 ushort reserved50; /* 50 reserved */
1129 ushort reserved51; /* 51 reserved */
1130 ushort reserved52; /* 52 reserved */
1131 ushort reserved53; /* 53 reserved */
1132 ushort reserved54; /* 54 reserved */
1133 ushort reserved55; /* 55 reserved */
1134 ushort cisptr_lsw; /* 56 CIS PTR LSW */
1135 ushort cisprt_msw; /* 57 CIS PTR MSW */
1136 ushort subsysvid; /* 58 SubSystem Vendor ID */
1137 ushort subsysid; /* 59 SubSystem ID */
1138 ushort reserved60; /* 60 reserved */
1139 ushort reserved61; /* 61 reserved */
1140 ushort reserved62; /* 62 reserved */
1141 ushort reserved63; /* 63 reserved */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142} ADVEEP_38C0800_CONFIG;
1143
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001144typedef struct adveep_38C1600_config {
1145 /* Word Offset, Description */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001147 ushort cfg_lsw; /* 00 power up initialization */
1148 /* bit 11 set - Func. 0 INTB, Func. 1 INTA */
1149 /* clear - Func. 0 INTA, Func. 1 INTB */
1150 /* bit 13 set - Load CIS */
1151 /* bit 14 set - BIOS Enable */
1152 /* bit 15 set - Big Endian Mode */
1153 ushort cfg_msw; /* 01 unused */
1154 ushort disc_enable; /* 02 disconnect enable */
1155 ushort wdtr_able; /* 03 Wide DTR able */
1156 ushort sdtr_speed1; /* 04 SDTR Speed TID 0-3 */
1157 ushort start_motor; /* 05 send start up motor */
1158 ushort tagqng_able; /* 06 tag queuing able */
1159 ushort bios_scan; /* 07 BIOS device control */
1160 ushort scam_tolerant; /* 08 no scam */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001162 uchar adapter_scsi_id; /* 09 Host Adapter ID */
1163 uchar bios_boot_delay; /* power up wait */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001165 uchar scsi_reset_delay; /* 10 reset delay */
1166 uchar bios_id_lun; /* first boot device scsi id & lun */
1167 /* high nibble is lun */
1168 /* low nibble is scsi id */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001170 uchar termination_se; /* 11 0 - automatic */
1171 /* 1 - low off / high off */
1172 /* 2 - low off / high on */
1173 /* 3 - low on / high on */
1174 /* There is no low on / high off */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001176 uchar termination_lvd; /* 11 0 - automatic */
1177 /* 1 - low off / high off */
1178 /* 2 - low off / high on */
1179 /* 3 - low on / high on */
1180 /* There is no low on / high off */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001182 ushort bios_ctrl; /* 12 BIOS control bits */
1183 /* bit 0 BIOS don't act as initiator. */
1184 /* bit 1 BIOS > 1 GB support */
1185 /* bit 2 BIOS > 2 Disk Support */
1186 /* bit 3 BIOS don't support removables */
1187 /* bit 4 BIOS support bootable CD */
1188 /* bit 5 BIOS scan enabled */
1189 /* bit 6 BIOS support multiple LUNs */
1190 /* bit 7 BIOS display of message */
1191 /* bit 8 SCAM disabled */
1192 /* bit 9 Reset SCSI bus during init. */
1193 /* bit 10 Basic Integrity Checking disabled */
1194 /* bit 11 No verbose initialization. */
1195 /* bit 12 SCSI parity enabled */
1196 /* bit 13 AIPP (Asyn. Info. Ph. Prot.) dis. */
1197 /* bit 14 */
1198 /* bit 15 */
1199 ushort sdtr_speed2; /* 13 SDTR speed TID 4-7 */
1200 ushort sdtr_speed3; /* 14 SDTR speed TID 8-11 */
1201 uchar max_host_qng; /* 15 maximum host queueing */
1202 uchar max_dvc_qng; /* maximum per device queuing */
1203 ushort dvc_cntl; /* 16 control bit for driver */
1204 ushort sdtr_speed4; /* 17 SDTR speed 4 TID 12-15 */
1205 ushort serial_number_word1; /* 18 Board serial number word 1 */
1206 ushort serial_number_word2; /* 19 Board serial number word 2 */
1207 ushort serial_number_word3; /* 20 Board serial number word 3 */
1208 ushort check_sum; /* 21 EEP check sum */
1209 uchar oem_name[16]; /* 22 OEM name */
1210 ushort dvc_err_code; /* 30 last device driver error code */
1211 ushort adv_err_code; /* 31 last uc and Adv Lib error code */
1212 ushort adv_err_addr; /* 32 last uc error address */
1213 ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
1214 ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
1215 ushort saved_adv_err_addr; /* 35 saved last uc error address */
1216 ushort reserved36; /* 36 reserved */
1217 ushort reserved37; /* 37 reserved */
1218 ushort reserved38; /* 38 reserved */
1219 ushort reserved39; /* 39 reserved */
1220 ushort reserved40; /* 40 reserved */
1221 ushort reserved41; /* 41 reserved */
1222 ushort reserved42; /* 42 reserved */
1223 ushort reserved43; /* 43 reserved */
1224 ushort reserved44; /* 44 reserved */
1225 ushort reserved45; /* 45 reserved */
1226 ushort reserved46; /* 46 reserved */
1227 ushort reserved47; /* 47 reserved */
1228 ushort reserved48; /* 48 reserved */
1229 ushort reserved49; /* 49 reserved */
1230 ushort reserved50; /* 50 reserved */
1231 ushort reserved51; /* 51 reserved */
1232 ushort reserved52; /* 52 reserved */
1233 ushort reserved53; /* 53 reserved */
1234 ushort reserved54; /* 54 reserved */
1235 ushort reserved55; /* 55 reserved */
1236 ushort cisptr_lsw; /* 56 CIS PTR LSW */
1237 ushort cisprt_msw; /* 57 CIS PTR MSW */
1238 ushort subsysvid; /* 58 SubSystem Vendor ID */
1239 ushort subsysid; /* 59 SubSystem ID */
1240 ushort reserved60; /* 60 reserved */
1241 ushort reserved61; /* 61 reserved */
1242 ushort reserved62; /* 62 reserved */
1243 ushort reserved63; /* 63 reserved */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244} ADVEEP_38C1600_CONFIG;
1245
1246/*
1247 * EEPROM Commands
1248 */
1249#define ASC_EEP_CMD_DONE 0x0200
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
1251/* bios_ctrl */
1252#define BIOS_CTRL_BIOS 0x0001
1253#define BIOS_CTRL_EXTENDED_XLAT 0x0002
1254#define BIOS_CTRL_GT_2_DISK 0x0004
1255#define BIOS_CTRL_BIOS_REMOVABLE 0x0008
1256#define BIOS_CTRL_BOOTABLE_CD 0x0010
1257#define BIOS_CTRL_MULTIPLE_LUN 0x0040
1258#define BIOS_CTRL_DISPLAY_MSG 0x0080
1259#define BIOS_CTRL_NO_SCAM 0x0100
1260#define BIOS_CTRL_RESET_SCSI_BUS 0x0200
1261#define BIOS_CTRL_INIT_VERBOSE 0x0800
1262#define BIOS_CTRL_SCSI_PARITY 0x1000
1263#define BIOS_CTRL_AIPP_DIS 0x2000
1264
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001265#define ADV_3550_MEMSIZE 0x2000 /* 8 KB Internal Memory */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001267#define ADV_38C0800_MEMSIZE 0x4000 /* 16 KB Internal Memory */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268
1269/*
1270 * XXX - Since ASC38C1600 Rev.3 has a local RAM failure issue, there is
1271 * a special 16K Adv Library and Microcode version. After the issue is
1272 * resolved, should restore 32K support.
1273 *
1274 * #define ADV_38C1600_MEMSIZE 0x8000L * 32 KB Internal Memory *
1275 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001276#define ADV_38C1600_MEMSIZE 0x4000 /* 16 KB Internal Memory */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277
1278/*
1279 * Byte I/O register address from base of 'iop_base'.
1280 */
1281#define IOPB_INTR_STATUS_REG 0x00
1282#define IOPB_CHIP_ID_1 0x01
1283#define IOPB_INTR_ENABLES 0x02
1284#define IOPB_CHIP_TYPE_REV 0x03
1285#define IOPB_RES_ADDR_4 0x04
1286#define IOPB_RES_ADDR_5 0x05
1287#define IOPB_RAM_DATA 0x06
1288#define IOPB_RES_ADDR_7 0x07
1289#define IOPB_FLAG_REG 0x08
1290#define IOPB_RES_ADDR_9 0x09
1291#define IOPB_RISC_CSR 0x0A
1292#define IOPB_RES_ADDR_B 0x0B
1293#define IOPB_RES_ADDR_C 0x0C
1294#define IOPB_RES_ADDR_D 0x0D
1295#define IOPB_SOFT_OVER_WR 0x0E
1296#define IOPB_RES_ADDR_F 0x0F
1297#define IOPB_MEM_CFG 0x10
1298#define IOPB_RES_ADDR_11 0x11
1299#define IOPB_GPIO_DATA 0x12
1300#define IOPB_RES_ADDR_13 0x13
1301#define IOPB_FLASH_PAGE 0x14
1302#define IOPB_RES_ADDR_15 0x15
1303#define IOPB_GPIO_CNTL 0x16
1304#define IOPB_RES_ADDR_17 0x17
1305#define IOPB_FLASH_DATA 0x18
1306#define IOPB_RES_ADDR_19 0x19
1307#define IOPB_RES_ADDR_1A 0x1A
1308#define IOPB_RES_ADDR_1B 0x1B
1309#define IOPB_RES_ADDR_1C 0x1C
1310#define IOPB_RES_ADDR_1D 0x1D
1311#define IOPB_RES_ADDR_1E 0x1E
1312#define IOPB_RES_ADDR_1F 0x1F
1313#define IOPB_DMA_CFG0 0x20
1314#define IOPB_DMA_CFG1 0x21
1315#define IOPB_TICKLE 0x22
1316#define IOPB_DMA_REG_WR 0x23
1317#define IOPB_SDMA_STATUS 0x24
1318#define IOPB_SCSI_BYTE_CNT 0x25
1319#define IOPB_HOST_BYTE_CNT 0x26
1320#define IOPB_BYTE_LEFT_TO_XFER 0x27
1321#define IOPB_BYTE_TO_XFER_0 0x28
1322#define IOPB_BYTE_TO_XFER_1 0x29
1323#define IOPB_BYTE_TO_XFER_2 0x2A
1324#define IOPB_BYTE_TO_XFER_3 0x2B
1325#define IOPB_ACC_GRP 0x2C
1326#define IOPB_RES_ADDR_2D 0x2D
1327#define IOPB_DEV_ID 0x2E
1328#define IOPB_RES_ADDR_2F 0x2F
1329#define IOPB_SCSI_DATA 0x30
1330#define IOPB_RES_ADDR_31 0x31
1331#define IOPB_RES_ADDR_32 0x32
1332#define IOPB_SCSI_DATA_HSHK 0x33
1333#define IOPB_SCSI_CTRL 0x34
1334#define IOPB_RES_ADDR_35 0x35
1335#define IOPB_RES_ADDR_36 0x36
1336#define IOPB_RES_ADDR_37 0x37
1337#define IOPB_RAM_BIST 0x38
1338#define IOPB_PLL_TEST 0x39
1339#define IOPB_PCI_INT_CFG 0x3A
1340#define IOPB_RES_ADDR_3B 0x3B
1341#define IOPB_RFIFO_CNT 0x3C
1342#define IOPB_RES_ADDR_3D 0x3D
1343#define IOPB_RES_ADDR_3E 0x3E
1344#define IOPB_RES_ADDR_3F 0x3F
1345
1346/*
1347 * Word I/O register address from base of 'iop_base'.
1348 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001349#define IOPW_CHIP_ID_0 0x00 /* CID0 */
1350#define IOPW_CTRL_REG 0x02 /* CC */
1351#define IOPW_RAM_ADDR 0x04 /* LA */
1352#define IOPW_RAM_DATA 0x06 /* LD */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353#define IOPW_RES_ADDR_08 0x08
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001354#define IOPW_RISC_CSR 0x0A /* CSR */
1355#define IOPW_SCSI_CFG0 0x0C /* CFG0 */
1356#define IOPW_SCSI_CFG1 0x0E /* CFG1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357#define IOPW_RES_ADDR_10 0x10
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001358#define IOPW_SEL_MASK 0x12 /* SM */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359#define IOPW_RES_ADDR_14 0x14
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001360#define IOPW_FLASH_ADDR 0x16 /* FA */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361#define IOPW_RES_ADDR_18 0x18
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001362#define IOPW_EE_CMD 0x1A /* EC */
1363#define IOPW_EE_DATA 0x1C /* ED */
1364#define IOPW_SFIFO_CNT 0x1E /* SFC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365#define IOPW_RES_ADDR_20 0x20
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001366#define IOPW_Q_BASE 0x22 /* QB */
1367#define IOPW_QP 0x24 /* QP */
1368#define IOPW_IX 0x26 /* IX */
1369#define IOPW_SP 0x28 /* SP */
1370#define IOPW_PC 0x2A /* PC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371#define IOPW_RES_ADDR_2C 0x2C
1372#define IOPW_RES_ADDR_2E 0x2E
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001373#define IOPW_SCSI_DATA 0x30 /* SD */
1374#define IOPW_SCSI_DATA_HSHK 0x32 /* SDH */
1375#define IOPW_SCSI_CTRL 0x34 /* SC */
1376#define IOPW_HSHK_CFG 0x36 /* HCFG */
1377#define IOPW_SXFR_STATUS 0x36 /* SXS */
1378#define IOPW_SXFR_CNTL 0x38 /* SXL */
1379#define IOPW_SXFR_CNTH 0x3A /* SXH */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380#define IOPW_RES_ADDR_3C 0x3C
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001381#define IOPW_RFIFO_DATA 0x3E /* RFD */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382
1383/*
1384 * Doubleword I/O register address from base of 'iop_base'.
1385 */
1386#define IOPDW_RES_ADDR_0 0x00
1387#define IOPDW_RAM_DATA 0x04
1388#define IOPDW_RES_ADDR_8 0x08
1389#define IOPDW_RES_ADDR_C 0x0C
1390#define IOPDW_RES_ADDR_10 0x10
1391#define IOPDW_COMMA 0x14
1392#define IOPDW_COMMB 0x18
1393#define IOPDW_RES_ADDR_1C 0x1C
1394#define IOPDW_SDMA_ADDR0 0x20
1395#define IOPDW_SDMA_ADDR1 0x24
1396#define IOPDW_SDMA_COUNT 0x28
1397#define IOPDW_SDMA_ERROR 0x2C
1398#define IOPDW_RDMA_ADDR0 0x30
1399#define IOPDW_RDMA_ADDR1 0x34
1400#define IOPDW_RDMA_COUNT 0x38
1401#define IOPDW_RDMA_ERROR 0x3C
1402
1403#define ADV_CHIP_ID_BYTE 0x25
1404#define ADV_CHIP_ID_WORD 0x04C1
1405
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406#define ADV_INTR_ENABLE_HOST_INTR 0x01
1407#define ADV_INTR_ENABLE_SEL_INTR 0x02
1408#define ADV_INTR_ENABLE_DPR_INTR 0x04
1409#define ADV_INTR_ENABLE_RTA_INTR 0x08
1410#define ADV_INTR_ENABLE_RMA_INTR 0x10
1411#define ADV_INTR_ENABLE_RST_INTR 0x20
1412#define ADV_INTR_ENABLE_DPE_INTR 0x40
1413#define ADV_INTR_ENABLE_GLOBAL_INTR 0x80
1414
1415#define ADV_INTR_STATUS_INTRA 0x01
1416#define ADV_INTR_STATUS_INTRB 0x02
1417#define ADV_INTR_STATUS_INTRC 0x04
1418
1419#define ADV_RISC_CSR_STOP (0x0000)
1420#define ADV_RISC_TEST_COND (0x2000)
1421#define ADV_RISC_CSR_RUN (0x4000)
1422#define ADV_RISC_CSR_SINGLE_STEP (0x8000)
1423
1424#define ADV_CTRL_REG_HOST_INTR 0x0100
1425#define ADV_CTRL_REG_SEL_INTR 0x0200
1426#define ADV_CTRL_REG_DPR_INTR 0x0400
1427#define ADV_CTRL_REG_RTA_INTR 0x0800
1428#define ADV_CTRL_REG_RMA_INTR 0x1000
1429#define ADV_CTRL_REG_RES_BIT14 0x2000
1430#define ADV_CTRL_REG_DPE_INTR 0x4000
1431#define ADV_CTRL_REG_POWER_DONE 0x8000
1432#define ADV_CTRL_REG_ANY_INTR 0xFF00
1433
1434#define ADV_CTRL_REG_CMD_RESET 0x00C6
1435#define ADV_CTRL_REG_CMD_WR_IO_REG 0x00C5
1436#define ADV_CTRL_REG_CMD_RD_IO_REG 0x00C4
1437#define ADV_CTRL_REG_CMD_WR_PCI_CFG_SPACE 0x00C3
1438#define ADV_CTRL_REG_CMD_RD_PCI_CFG_SPACE 0x00C2
1439
1440#define ADV_TICKLE_NOP 0x00
1441#define ADV_TICKLE_A 0x01
1442#define ADV_TICKLE_B 0x02
1443#define ADV_TICKLE_C 0x03
1444
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445#define AdvIsIntPending(port) \
1446 (AdvReadWordRegister(port, IOPW_CTRL_REG) & ADV_CTRL_REG_HOST_INTR)
1447
1448/*
1449 * SCSI_CFG0 Register bit definitions
1450 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001451#define TIMER_MODEAB 0xC000 /* Watchdog, Second, and Select. Timer Ctrl. */
1452#define PARITY_EN 0x2000 /* Enable SCSI Parity Error detection */
1453#define EVEN_PARITY 0x1000 /* Select Even Parity */
1454#define WD_LONG 0x0800 /* Watchdog Interval, 1: 57 min, 0: 13 sec */
1455#define QUEUE_128 0x0400 /* Queue Size, 1: 128 byte, 0: 64 byte */
1456#define PRIM_MODE 0x0100 /* Primitive SCSI mode */
1457#define SCAM_EN 0x0080 /* Enable SCAM selection */
1458#define SEL_TMO_LONG 0x0040 /* Sel/Resel Timeout, 1: 400 ms, 0: 1.6 ms */
1459#define CFRM_ID 0x0020 /* SCAM id sel. confirm., 1: fast, 0: 6.4 ms */
1460#define OUR_ID_EN 0x0010 /* Enable OUR_ID bits */
1461#define OUR_ID 0x000F /* SCSI ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
1463/*
1464 * SCSI_CFG1 Register bit definitions
1465 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001466#define BIG_ENDIAN 0x8000 /* Enable Big Endian Mode MIO:15, EEP:15 */
1467#define TERM_POL 0x2000 /* Terminator Polarity Ctrl. MIO:13, EEP:13 */
1468#define SLEW_RATE 0x1000 /* SCSI output buffer slew rate */
1469#define FILTER_SEL 0x0C00 /* Filter Period Selection */
1470#define FLTR_DISABLE 0x0000 /* Input Filtering Disabled */
1471#define FLTR_11_TO_20NS 0x0800 /* Input Filtering 11ns to 20ns */
1472#define FLTR_21_TO_39NS 0x0C00 /* Input Filtering 21ns to 39ns */
1473#define ACTIVE_DBL 0x0200 /* Disable Active Negation */
1474#define DIFF_MODE 0x0100 /* SCSI differential Mode (Read-Only) */
1475#define DIFF_SENSE 0x0080 /* 1: No SE cables, 0: SE cable (Read-Only) */
1476#define TERM_CTL_SEL 0x0040 /* Enable TERM_CTL_H and TERM_CTL_L */
1477#define TERM_CTL 0x0030 /* External SCSI Termination Bits */
1478#define TERM_CTL_H 0x0020 /* Enable External SCSI Upper Termination */
1479#define TERM_CTL_L 0x0010 /* Enable External SCSI Lower Termination */
1480#define CABLE_DETECT 0x000F /* External SCSI Cable Connection Status */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481
1482/*
1483 * Addendum for ASC-38C0800 Chip
1484 *
1485 * The ASC-38C1600 Chip uses the same definitions except that the
1486 * bus mode override bits [12:10] have been moved to byte register
1487 * offset 0xE (IOPB_SOFT_OVER_WR) bits [12:10]. The [12:10] bits in
1488 * SCSI_CFG1 are read-only and always available. Bit 14 (DIS_TERM_DRV)
1489 * is not needed. The [12:10] bits in IOPB_SOFT_OVER_WR are write-only.
1490 * Also each ASC-38C1600 function or channel uses only cable bits [5:4]
1491 * and [1:0]. Bits [14], [7:6], [3:2] are unused.
1492 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001493#define DIS_TERM_DRV 0x4000 /* 1: Read c_det[3:0], 0: cannot read */
1494#define HVD_LVD_SE 0x1C00 /* Device Detect Bits */
1495#define HVD 0x1000 /* HVD Device Detect */
1496#define LVD 0x0800 /* LVD Device Detect */
1497#define SE 0x0400 /* SE Device Detect */
1498#define TERM_LVD 0x00C0 /* LVD Termination Bits */
1499#define TERM_LVD_HI 0x0080 /* Enable LVD Upper Termination */
1500#define TERM_LVD_LO 0x0040 /* Enable LVD Lower Termination */
1501#define TERM_SE 0x0030 /* SE Termination Bits */
1502#define TERM_SE_HI 0x0020 /* Enable SE Upper Termination */
1503#define TERM_SE_LO 0x0010 /* Enable SE Lower Termination */
1504#define C_DET_LVD 0x000C /* LVD Cable Detect Bits */
1505#define C_DET3 0x0008 /* Cable Detect for LVD External Wide */
1506#define C_DET2 0x0004 /* Cable Detect for LVD Internal Wide */
1507#define C_DET_SE 0x0003 /* SE Cable Detect Bits */
1508#define C_DET1 0x0002 /* Cable Detect for SE Internal Wide */
1509#define C_DET0 0x0001 /* Cable Detect for SE Internal Narrow */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
1511#define CABLE_ILLEGAL_A 0x7
1512 /* x 0 0 0 | on on | Illegal (all 3 connectors are used) */
1513
1514#define CABLE_ILLEGAL_B 0xB
1515 /* 0 x 0 0 | on on | Illegal (all 3 connectors are used) */
1516
1517/*
1518 * MEM_CFG Register bit definitions
1519 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001520#define BIOS_EN 0x40 /* BIOS Enable MIO:14,EEP:14 */
1521#define FAST_EE_CLK 0x20 /* Diagnostic Bit */
1522#define RAM_SZ 0x1C /* Specify size of RAM to RISC */
1523#define RAM_SZ_2KB 0x00 /* 2 KB */
1524#define RAM_SZ_4KB 0x04 /* 4 KB */
1525#define RAM_SZ_8KB 0x08 /* 8 KB */
1526#define RAM_SZ_16KB 0x0C /* 16 KB */
1527#define RAM_SZ_32KB 0x10 /* 32 KB */
1528#define RAM_SZ_64KB 0x14 /* 64 KB */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529
1530/*
1531 * DMA_CFG0 Register bit definitions
1532 *
1533 * This register is only accessible to the host.
1534 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001535#define BC_THRESH_ENB 0x80 /* PCI DMA Start Conditions */
1536#define FIFO_THRESH 0x70 /* PCI DMA FIFO Threshold */
1537#define FIFO_THRESH_16B 0x00 /* 16 bytes */
1538#define FIFO_THRESH_32B 0x20 /* 32 bytes */
1539#define FIFO_THRESH_48B 0x30 /* 48 bytes */
1540#define FIFO_THRESH_64B 0x40 /* 64 bytes */
1541#define FIFO_THRESH_80B 0x50 /* 80 bytes (default) */
1542#define FIFO_THRESH_96B 0x60 /* 96 bytes */
1543#define FIFO_THRESH_112B 0x70 /* 112 bytes */
1544#define START_CTL 0x0C /* DMA start conditions */
1545#define START_CTL_TH 0x00 /* Wait threshold level (default) */
1546#define START_CTL_ID 0x04 /* Wait SDMA/SBUS idle */
1547#define START_CTL_THID 0x08 /* Wait threshold and SDMA/SBUS idle */
1548#define START_CTL_EMFU 0x0C /* Wait SDMA FIFO empty/full */
1549#define READ_CMD 0x03 /* Memory Read Method */
1550#define READ_CMD_MR 0x00 /* Memory Read */
1551#define READ_CMD_MRL 0x02 /* Memory Read Long */
1552#define READ_CMD_MRM 0x03 /* Memory Read Multiple (default) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
1554/*
1555 * ASC-38C0800 RAM BIST Register bit definitions
1556 */
1557#define RAM_TEST_MODE 0x80
1558#define PRE_TEST_MODE 0x40
1559#define NORMAL_MODE 0x00
1560#define RAM_TEST_DONE 0x10
1561#define RAM_TEST_STATUS 0x0F
1562#define RAM_TEST_HOST_ERROR 0x08
1563#define RAM_TEST_INTRAM_ERROR 0x04
1564#define RAM_TEST_RISC_ERROR 0x02
1565#define RAM_TEST_SCSI_ERROR 0x01
1566#define RAM_TEST_SUCCESS 0x00
1567#define PRE_TEST_VALUE 0x05
1568#define NORMAL_VALUE 0x00
1569
1570/*
1571 * ASC38C1600 Definitions
1572 *
1573 * IOPB_PCI_INT_CFG Bit Field Definitions
1574 */
1575
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001576#define INTAB_LD 0x80 /* Value loaded from EEPROM Bit 11. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
1578/*
1579 * Bit 1 can be set to change the interrupt for the Function to operate in
1580 * Totem Pole mode. By default Bit 1 is 0 and the interrupt operates in
1581 * Open Drain mode. Both functions of the ASC38C1600 must be set to the same
1582 * mode, otherwise the operating mode is undefined.
1583 */
1584#define TOTEMPOLE 0x02
1585
1586/*
1587 * Bit 0 can be used to change the Int Pin for the Function. The value is
1588 * 0 by default for both Functions with Function 0 using INT A and Function
1589 * B using INT B. For Function 0 if set, INT B is used. For Function 1 if set,
1590 * INT A is used.
1591 *
1592 * EEPROM Word 0 Bit 11 for each Function may change the initial Int Pin
1593 * value specified in the PCI Configuration Space.
1594 */
1595#define INTAB 0x01
1596
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597/*
1598 * Adv Library Status Definitions
1599 */
1600#define ADV_TRUE 1
1601#define ADV_FALSE 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602#define ADV_SUCCESS 1
1603#define ADV_BUSY 0
1604#define ADV_ERROR (-1)
1605
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606/*
1607 * ADV_DVC_VAR 'warn_code' values
1608 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001609#define ASC_WARN_BUSRESET_ERROR 0x0001 /* SCSI Bus Reset error */
1610#define ASC_WARN_EEPROM_CHKSUM 0x0002 /* EEP check sum error */
1611#define ASC_WARN_EEPROM_TERMINATION 0x0004 /* EEP termination bad field */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001612#define ASC_WARN_ERROR 0xFFFF /* ADV_ERROR return */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001614#define ADV_MAX_TID 15 /* max. target identifier */
1615#define ADV_MAX_LUN 7 /* max. logical unit number */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616
1617/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 * Fixed locations of microcode operating variables.
1619 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001620#define ASC_MC_CODE_BEGIN_ADDR 0x0028 /* microcode start address */
1621#define ASC_MC_CODE_END_ADDR 0x002A /* microcode end address */
1622#define ASC_MC_CODE_CHK_SUM 0x002C /* microcode code checksum */
1623#define ASC_MC_VERSION_DATE 0x0038 /* microcode version */
1624#define ASC_MC_VERSION_NUM 0x003A /* microcode number */
1625#define ASC_MC_BIOSMEM 0x0040 /* BIOS RISC Memory Start */
1626#define ASC_MC_BIOSLEN 0x0050 /* BIOS RISC Memory Length */
1627#define ASC_MC_BIOS_SIGNATURE 0x0058 /* BIOS Signature 0x55AA */
1628#define ASC_MC_BIOS_VERSION 0x005A /* BIOS Version (2 bytes) */
1629#define ASC_MC_SDTR_SPEED1 0x0090 /* SDTR Speed for TID 0-3 */
1630#define ASC_MC_SDTR_SPEED2 0x0092 /* SDTR Speed for TID 4-7 */
1631#define ASC_MC_SDTR_SPEED3 0x0094 /* SDTR Speed for TID 8-11 */
1632#define ASC_MC_SDTR_SPEED4 0x0096 /* SDTR Speed for TID 12-15 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633#define ASC_MC_CHIP_TYPE 0x009A
1634#define ASC_MC_INTRB_CODE 0x009B
1635#define ASC_MC_WDTR_ABLE 0x009C
1636#define ASC_MC_SDTR_ABLE 0x009E
1637#define ASC_MC_TAGQNG_ABLE 0x00A0
1638#define ASC_MC_DISC_ENABLE 0x00A2
1639#define ASC_MC_IDLE_CMD_STATUS 0x00A4
1640#define ASC_MC_IDLE_CMD 0x00A6
1641#define ASC_MC_IDLE_CMD_PARAMETER 0x00A8
1642#define ASC_MC_DEFAULT_SCSI_CFG0 0x00AC
1643#define ASC_MC_DEFAULT_SCSI_CFG1 0x00AE
1644#define ASC_MC_DEFAULT_MEM_CFG 0x00B0
1645#define ASC_MC_DEFAULT_SEL_MASK 0x00B2
1646#define ASC_MC_SDTR_DONE 0x00B6
1647#define ASC_MC_NUMBER_OF_QUEUED_CMD 0x00C0
1648#define ASC_MC_NUMBER_OF_MAX_CMD 0x00D0
1649#define ASC_MC_DEVICE_HSHK_CFG_TABLE 0x0100
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001650#define ASC_MC_CONTROL_FLAG 0x0122 /* Microcode control flag. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651#define ASC_MC_WDTR_DONE 0x0124
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001652#define ASC_MC_CAM_MODE_MASK 0x015E /* CAM mode TID bitmask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653#define ASC_MC_ICQ 0x0160
1654#define ASC_MC_IRQ 0x0164
1655#define ASC_MC_PPR_ABLE 0x017A
1656
1657/*
1658 * BIOS LRAM variable absolute offsets.
1659 */
1660#define BIOS_CODESEG 0x54
1661#define BIOS_CODELEN 0x56
1662#define BIOS_SIGNATURE 0x58
1663#define BIOS_VERSION 0x5A
1664
1665/*
1666 * Microcode Control Flags
1667 *
1668 * Flags set by the Adv Library in RISC variable 'control_flag' (0x122)
1669 * and handled by the microcode.
1670 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001671#define CONTROL_FLAG_IGNORE_PERR 0x0001 /* Ignore DMA Parity Errors */
1672#define CONTROL_FLAG_ENABLE_AIPP 0x0002 /* Enabled AIPP checking. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673
1674/*
1675 * ASC_MC_DEVICE_HSHK_CFG_TABLE microcode table or HSHK_CFG register format
1676 */
1677#define HSHK_CFG_WIDE_XFR 0x8000
1678#define HSHK_CFG_RATE 0x0F00
1679#define HSHK_CFG_OFFSET 0x001F
1680
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001681#define ASC_DEF_MAX_HOST_QNG 0xFD /* Max. number of host commands (253) */
1682#define ASC_DEF_MIN_HOST_QNG 0x10 /* Min. number of host commands (16) */
1683#define ASC_DEF_MAX_DVC_QNG 0x3F /* Max. number commands per device (63) */
1684#define ASC_DEF_MIN_DVC_QNG 0x04 /* Min. number commands per device (4) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001686#define ASC_QC_DATA_CHECK 0x01 /* Require ASC_QC_DATA_OUT set or clear. */
1687#define ASC_QC_DATA_OUT 0x02 /* Data out DMA transfer. */
1688#define ASC_QC_START_MOTOR 0x04 /* Send auto-start motor before request. */
1689#define ASC_QC_NO_OVERRUN 0x08 /* Don't report overrun. */
1690#define ASC_QC_FREEZE_TIDQ 0x10 /* Freeze TID queue after request. XXX TBD */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001692#define ASC_QSC_NO_DISC 0x01 /* Don't allow disconnect for request. */
1693#define ASC_QSC_NO_TAGMSG 0x02 /* Don't allow tag queuing for request. */
1694#define ASC_QSC_NO_SYNC 0x04 /* Don't use Synch. transfer on request. */
1695#define ASC_QSC_NO_WIDE 0x08 /* Don't use Wide transfer on request. */
1696#define ASC_QSC_REDO_DTR 0x10 /* Renegotiate WDTR/SDTR before request. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697/*
1698 * Note: If a Tag Message is to be sent and neither ASC_QSC_HEAD_TAG or
1699 * ASC_QSC_ORDERED_TAG is set, then a Simple Tag Message (0x20) is used.
1700 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001701#define ASC_QSC_HEAD_TAG 0x40 /* Use Head Tag Message (0x21). */
1702#define ASC_QSC_ORDERED_TAG 0x80 /* Use Ordered Tag Message (0x22). */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703
1704/*
1705 * All fields here are accessed by the board microcode and need to be
1706 * little-endian.
1707 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001708typedef struct adv_carr_t {
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001709 __le32 carr_va; /* Carrier Virtual Address */
1710 __le32 carr_pa; /* Carrier Physical Address */
1711 __le32 areq_vpa; /* ASC_SCSI_REQ_Q Virtual or Physical Address */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001712 /*
1713 * next_vpa [31:4] Carrier Virtual or Physical Next Pointer
1714 *
1715 * next_vpa [3:1] Reserved Bits
1716 * next_vpa [0] Done Flag set in Response Queue.
1717 */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001718 __le32 next_vpa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719} ADV_CARR_T;
1720
1721/*
1722 * Mask used to eliminate low 4 bits of carrier 'next_vpa' field.
1723 */
1724#define ASC_NEXT_VPA_MASK 0xFFFFFFF0
1725
1726#define ASC_RQ_DONE 0x00000001
1727#define ASC_RQ_GOOD 0x00000002
1728#define ASC_CQ_STOPPER 0x00000000
1729
1730#define ASC_GET_CARRP(carrp) ((carrp) & ASC_NEXT_VPA_MASK)
1731
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001732/*
1733 * Each carrier is 64 bytes, and we need three additional
1734 * carrier for icq, irq, and the termination carrier.
1735 */
1736#define ADV_CARRIER_COUNT (ASC_DEF_MAX_HOST_QNG + 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737
1738#define ADV_CARRIER_BUFSIZE \
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001739 (ADV_CARRIER_COUNT * sizeof(ADV_CARR_T))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
1741/*
1742 * ASC_SCSI_REQ_Q 'a_flag' definitions
1743 *
1744 * The Adv Library should limit use to the lower nibble (4 bits) of
1745 * a_flag. Drivers are free to use the upper nibble (4 bits) of a_flag.
1746 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001747#define ADV_POLL_REQUEST 0x01 /* poll for request completion */
1748#define ADV_SCSIQ_DONE 0x02 /* request done */
1749#define ADV_DONT_RETRY 0x08 /* don't do retry */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001751#define ADV_CHIP_ASC3550 0x01 /* Ultra-Wide IC */
1752#define ADV_CHIP_ASC38C0800 0x02 /* Ultra2-Wide/LVD IC */
1753#define ADV_CHIP_ASC38C1600 0x03 /* Ultra3-Wide/LVD2 IC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754
1755/*
1756 * Adapter temporary configuration structure
1757 *
1758 * This structure can be discarded after initialization. Don't add
1759 * fields here needed after initialization.
1760 *
1761 * Field naming convention:
1762 *
1763 * *_enable indicates the field enables or disables a feature. The
1764 * value of the field is never reset.
1765 */
1766typedef struct adv_dvc_cfg {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001767 ushort disc_enable; /* enable disconnection */
1768 uchar chip_version; /* chip version */
1769 uchar termination; /* Term. Ctrl. bits 6-5 of SCSI_CFG1 register */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001770 ushort control_flag; /* Microcode Control Flag */
1771 ushort mcode_date; /* Microcode date */
1772 ushort mcode_version; /* Microcode version */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001773 ushort serial1; /* EEPROM serial number word 1 */
1774 ushort serial2; /* EEPROM serial number word 2 */
1775 ushort serial3; /* EEPROM serial number word 3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776} ADV_DVC_CFG;
1777
1778struct adv_dvc_var;
1779struct adv_scsi_req_q;
1780
Hannes Reinecke0ce53822015-04-24 13:18:25 +02001781typedef struct adv_sg_block {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001782 uchar reserved1;
1783 uchar reserved2;
1784 uchar reserved3;
1785 uchar sg_cnt; /* Valid entries in block. */
Hannes Reinecke0ce53822015-04-24 13:18:25 +02001786 __le32 sg_ptr; /* Pointer to next sg block. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001787 struct {
Hannes Reinecke0ce53822015-04-24 13:18:25 +02001788 __le32 sg_addr; /* SG element address. */
1789 __le32 sg_count; /* SG element count. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001790 } sg_list[NO_OF_SG_PER_BLOCK];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791} ADV_SG_BLOCK;
1792
1793/*
1794 * ADV_SCSI_REQ_Q - microcode request structure
1795 *
1796 * All fields in this structure up to byte 60 are used by the microcode.
1797 * The microcode makes assumptions about the size and ordering of fields
1798 * in this structure. Do not change the structure definition here without
1799 * coordinating the change with the microcode.
1800 *
1801 * All fields accessed by microcode must be maintained in little_endian
1802 * order.
1803 */
1804typedef struct adv_scsi_req_q {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001805 uchar cntl; /* Ucode flags and state (ASC_MC_QC_*). */
1806 uchar target_cmd;
1807 uchar target_id; /* Device target identifier. */
1808 uchar target_lun; /* Device target logical unit number. */
Hannes Reinecke95cfab62015-04-24 13:18:27 +02001809 __le32 data_addr; /* Data buffer physical address. */
1810 __le32 data_cnt; /* Data count. Ucode sets to residual. */
Hannes Reinecke811ddc02015-04-24 13:18:22 +02001811 __le32 sense_addr;
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001812 __le32 carr_pa;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001813 uchar mflag;
1814 uchar sense_len;
1815 uchar cdb_len; /* SCSI CDB length. Must <= 16 bytes. */
1816 uchar scsi_cntl;
1817 uchar done_status; /* Completion status. */
1818 uchar scsi_status; /* SCSI status byte. */
1819 uchar host_status; /* Ucode host status. */
1820 uchar sg_working_ix;
1821 uchar cdb[12]; /* SCSI CDB bytes 0-11. */
Hannes Reinecke95cfab62015-04-24 13:18:27 +02001822 __le32 sg_real_addr; /* SG list physical address. */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001823 __le32 scsiq_rptr;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001824 uchar cdb16[4]; /* SCSI CDB bytes 12-15. */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001825 __le32 scsiq_ptr;
1826 __le32 carr_va;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001827 /*
1828 * End of microcode structure - 60 bytes. The rest of the structure
1829 * is used by the Adv Library and ignored by the microcode.
1830 */
Hannes Reinecke9c17c622015-04-24 13:18:21 +02001831 u32 srb_tag;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001832 uchar a_flag;
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001833 uchar pad[3]; /* Pad out to a word boundary. */
1834 ADV_SG_BLOCK *sg_list_ptr; /* SG list virtual address. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835} ADV_SCSI_REQ_Q;
1836
1837/*
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001838 * The following two structures are used to process Wide Board requests.
1839 *
1840 * The ADV_SCSI_REQ_Q structure in adv_req_t is passed to the Adv Library
Hannes Reinecke9c17c622015-04-24 13:18:21 +02001841 * and microcode with the ADV_SCSI_REQ_Q field 'srb_tag' set to the
1842 * SCSI request tag. The adv_req_t structure 'cmndp' field in turn points
1843 * to the Mid-Level SCSI request structure.
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001844 *
1845 * Zero or more ADV_SG_BLOCK are used with each ADV_SCSI_REQ_Q. Each
1846 * ADV_SG_BLOCK structure holds 15 scatter-gather elements. Under Linux
1847 * up to 255 scatter-gather elements may be used per request or
1848 * ADV_SCSI_REQ_Q.
1849 *
1850 * Both structures must be 32 byte aligned.
1851 */
1852typedef struct adv_sgblk {
1853 ADV_SG_BLOCK sg_block; /* Sgblock structure. */
Hannes Reinecke0ce53822015-04-24 13:18:25 +02001854 dma_addr_t sg_addr; /* Physical address */
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001855 struct adv_sgblk *next_sgblkp; /* Next scatter-gather structure. */
1856} adv_sgblk_t;
1857
1858typedef struct adv_req {
1859 ADV_SCSI_REQ_Q scsi_req_q; /* Adv Library request structure. */
Hannes Reinecke4b47e462015-04-24 13:18:24 +02001860 uchar align[24]; /* Request structure padding. */
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001861 struct scsi_cmnd *cmndp; /* Mid-Level SCSI command pointer. */
Hannes Reinecke4b47e462015-04-24 13:18:24 +02001862 dma_addr_t req_addr;
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001863 adv_sgblk_t *sgblkp; /* Adv Library scatter-gather pointer. */
Hannes Reinecke4b47e462015-04-24 13:18:24 +02001864} adv_req_t __aligned(32);
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001865
1866/*
1867 * Adapter operation variable structure.
1868 *
1869 * One structure is required per host adapter.
1870 *
1871 * Field naming convention:
1872 *
1873 * *_able indicates both whether a feature should be enabled or disabled
1874 * and whether a device isi capable of the feature. At initialization
1875 * this field may be set, but later if a device is found to be incapable
1876 * of the feature, the field is cleared.
1877 */
1878typedef struct adv_dvc_var {
1879 AdvPortAddr iop_base; /* I/O port address */
1880 ushort err_code; /* fatal error code */
1881 ushort bios_ctrl; /* BIOS control word, EEPROM word 12 */
1882 ushort wdtr_able; /* try WDTR for a device */
1883 ushort sdtr_able; /* try SDTR for a device */
1884 ushort ultra_able; /* try SDTR Ultra speed for a device */
1885 ushort sdtr_speed1; /* EEPROM SDTR Speed for TID 0-3 */
1886 ushort sdtr_speed2; /* EEPROM SDTR Speed for TID 4-7 */
1887 ushort sdtr_speed3; /* EEPROM SDTR Speed for TID 8-11 */
1888 ushort sdtr_speed4; /* EEPROM SDTR Speed for TID 12-15 */
1889 ushort tagqng_able; /* try tagged queuing with a device */
1890 ushort ppr_able; /* PPR message capable per TID bitmask. */
1891 uchar max_dvc_qng; /* maximum number of tagged commands per device */
1892 ushort start_motor; /* start motor command allowed */
1893 uchar scsi_reset_wait; /* delay in seconds after scsi bus reset */
1894 uchar chip_no; /* should be assigned by caller */
1895 uchar max_host_qng; /* maximum number of Q'ed command allowed */
1896 ushort no_scam; /* scam_tolerant of EEPROM */
1897 struct asc_board *drv_ptr; /* driver pointer to private structure */
1898 uchar chip_scsi_id; /* chip SCSI target ID */
1899 uchar chip_type;
1900 uchar bist_err_code;
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001901 ADV_CARR_T *carrier;
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001902 ADV_CARR_T *carr_freelist; /* Carrier free list. */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001903 dma_addr_t carrier_addr;
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001904 ADV_CARR_T *icq_sp; /* Initiator command queue stopper pointer. */
1905 ADV_CARR_T *irq_sp; /* Initiator response queue stopper pointer. */
1906 ushort carr_pending_cnt; /* Count of pending carriers. */
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001907 /*
1908 * Note: The following fields will not be used after initialization. The
1909 * driver may discard the buffer after initialization is done.
1910 */
1911 ADV_DVC_CFG *cfg; /* temporary configuration structure */
1912} ADV_DVC_VAR;
1913
1914/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 * Microcode idle loop commands
1916 */
1917#define IDLE_CMD_COMPLETED 0
1918#define IDLE_CMD_STOP_CHIP 0x0001
1919#define IDLE_CMD_STOP_CHIP_SEND_INT 0x0002
1920#define IDLE_CMD_SEND_INT 0x0004
1921#define IDLE_CMD_ABORT 0x0008
1922#define IDLE_CMD_DEVICE_RESET 0x0010
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001923#define IDLE_CMD_SCSI_RESET_START 0x0020 /* Assert SCSI Bus Reset */
1924#define IDLE_CMD_SCSI_RESET_END 0x0040 /* Deassert SCSI Bus Reset */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925#define IDLE_CMD_SCSIREQ 0x0080
1926
1927#define IDLE_CMD_STATUS_SUCCESS 0x0001
1928#define IDLE_CMD_STATUS_FAILURE 0x0002
1929
1930/*
1931 * AdvSendIdleCmd() flag definitions.
1932 */
1933#define ADV_NOWAIT 0x01
1934
1935/*
1936 * Wait loop time out values.
1937 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001938#define SCSI_WAIT_100_MSEC 100UL /* 100 milliseconds */
1939#define SCSI_US_PER_MSEC 1000 /* microseconds per millisecond */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001940#define SCSI_MAX_RETRY 10 /* retry count */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001942#define ADV_ASYNC_RDMA_FAILURE 0x01 /* Fatal RDMA failure. */
1943#define ADV_ASYNC_SCSI_BUS_RESET_DET 0x02 /* Detected SCSI Bus Reset. */
1944#define ADV_ASYNC_CARRIER_READY_FAILURE 0x03 /* Carrier Ready failure. */
1945#define ADV_RDMA_IN_CARR_AND_Q_INVALID 0x04 /* RDMAed-in data invalid. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001947#define ADV_HOST_SCSI_BUS_RESET 0x80 /* Host Initiated SCSI Bus Reset. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949/* Read byte from a register. */
1950#define AdvReadByteRegister(iop_base, reg_off) \
1951 (ADV_MEM_READB((iop_base) + (reg_off)))
1952
1953/* Write byte to a register. */
1954#define AdvWriteByteRegister(iop_base, reg_off, byte) \
1955 (ADV_MEM_WRITEB((iop_base) + (reg_off), (byte)))
1956
1957/* Read word (2 bytes) from a register. */
1958#define AdvReadWordRegister(iop_base, reg_off) \
1959 (ADV_MEM_READW((iop_base) + (reg_off)))
1960
1961/* Write word (2 bytes) to a register. */
1962#define AdvWriteWordRegister(iop_base, reg_off, word) \
1963 (ADV_MEM_WRITEW((iop_base) + (reg_off), (word)))
1964
1965/* Write dword (4 bytes) to a register. */
1966#define AdvWriteDWordRegister(iop_base, reg_off, dword) \
1967 (ADV_MEM_WRITEDW((iop_base) + (reg_off), (dword)))
1968
1969/* Read byte from LRAM. */
1970#define AdvReadByteLram(iop_base, addr, byte) \
1971do { \
1972 ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
1973 (byte) = ADV_MEM_READB((iop_base) + IOPB_RAM_DATA); \
1974} while (0)
1975
1976/* Write byte to LRAM. */
1977#define AdvWriteByteLram(iop_base, addr, byte) \
1978 (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
1979 ADV_MEM_WRITEB((iop_base) + IOPB_RAM_DATA, (byte)))
1980
1981/* Read word (2 bytes) from LRAM. */
1982#define AdvReadWordLram(iop_base, addr, word) \
1983do { \
1984 ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
1985 (word) = (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA)); \
1986} while (0)
1987
1988/* Write word (2 bytes) to LRAM. */
1989#define AdvWriteWordLram(iop_base, addr, word) \
1990 (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
1991 ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
1992
1993/* Write little-endian double word (4 bytes) to LRAM */
1994/* Because of unspecified C language ordering don't use auto-increment. */
1995#define AdvWriteDWordLramNoSwap(iop_base, addr, dword) \
1996 ((ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
1997 ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
1998 cpu_to_le16((ushort) ((dword) & 0xFFFF)))), \
1999 (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr) + 2), \
2000 ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
2001 cpu_to_le16((ushort) ((dword >> 16) & 0xFFFF)))))
2002
2003/* Read word (2 bytes) from LRAM assuming that the address is already set. */
2004#define AdvReadWordAutoIncLram(iop_base) \
2005 (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA))
2006
2007/* Write word (2 bytes) to LRAM assuming that the address is already set. */
2008#define AdvWriteWordAutoIncLram(iop_base, word) \
2009 (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
2010
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011/*
2012 * Define macro to check for Condor signature.
2013 *
2014 * Evaluate to ADV_TRUE if a Condor chip is found the specified port
2015 * address 'iop_base'. Otherwise evalue to ADV_FALSE.
2016 */
2017#define AdvFindSignature(iop_base) \
2018 (((AdvReadByteRegister((iop_base), IOPB_CHIP_ID_1) == \
2019 ADV_CHIP_ID_BYTE) && \
2020 (AdvReadWordRegister((iop_base), IOPW_CHIP_ID_0) == \
2021 ADV_CHIP_ID_WORD)) ? ADV_TRUE : ADV_FALSE)
2022
2023/*
2024 * Define macro to Return the version number of the chip at 'iop_base'.
2025 *
2026 * The second parameter 'bus_type' is currently unused.
2027 */
2028#define AdvGetChipVersion(iop_base, bus_type) \
2029 AdvReadByteRegister((iop_base), IOPB_CHIP_TYPE_REV)
2030
2031/*
Hannes Reinecke9c17c622015-04-24 13:18:21 +02002032 * Abort an SRB in the chip's RISC Memory. The 'srb_tag' argument must
2033 * match the ASC_SCSI_REQ_Q 'srb_tag' field.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 *
2035 * If the request has not yet been sent to the device it will simply be
2036 * aborted from RISC memory. If the request is disconnected it will be
2037 * aborted on reselection by sending an Abort Message to the target ID.
2038 *
2039 * Return value:
2040 * ADV_TRUE(1) - Queue was successfully aborted.
2041 * ADV_FALSE(0) - Queue was not found on the active queue list.
2042 */
Hannes Reinecke9c17c622015-04-24 13:18:21 +02002043#define AdvAbortQueue(asc_dvc, srb_tag) \
2044 AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_ABORT, \
2045 (ADV_DCNT) (srb_tag))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046
2047/*
2048 * Send a Bus Device Reset Message to the specified target ID.
2049 *
2050 * All outstanding commands will be purged if sending the
2051 * Bus Device Reset Message is successful.
2052 *
2053 * Return Value:
2054 * ADV_TRUE(1) - All requests on the target are purged.
2055 * ADV_FALSE(0) - Couldn't issue Bus Device Reset Message; Requests
2056 * are not purged.
2057 */
2058#define AdvResetDevice(asc_dvc, target_id) \
Hannes Reinecke9c17c622015-04-24 13:18:21 +02002059 AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_DEVICE_RESET, \
2060 (ADV_DCNT) (target_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061
2062/*
2063 * SCSI Wide Type definition.
2064 */
2065#define ADV_SCSI_BIT_ID_TYPE ushort
2066
2067/*
2068 * AdvInitScsiTarget() 'cntl_flag' options.
2069 */
2070#define ADV_SCAN_LUN 0x01
2071#define ADV_CAPINFO_NOLUN 0x02
2072
2073/*
2074 * Convert target id to target id bit mask.
2075 */
2076#define ADV_TID_TO_TIDMASK(tid) (0x01 << ((tid) & ADV_MAX_TID))
2077
2078/*
2079 * ASC_SCSI_REQ_Q 'done_status' and 'host_status' return values.
2080 */
2081
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002082#define QD_NO_STATUS 0x00 /* Request not completed yet. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083#define QD_NO_ERROR 0x01
2084#define QD_ABORTED_BY_HOST 0x02
2085#define QD_WITH_ERROR 0x04
2086
2087#define QHSTA_NO_ERROR 0x00
2088#define QHSTA_M_SEL_TIMEOUT 0x11
2089#define QHSTA_M_DATA_OVER_RUN 0x12
2090#define QHSTA_M_UNEXPECTED_BUS_FREE 0x13
2091#define QHSTA_M_QUEUE_ABORTED 0x15
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002092#define QHSTA_M_SXFR_SDMA_ERR 0x16 /* SXFR_STATUS SCSI DMA Error */
2093#define QHSTA_M_SXFR_SXFR_PERR 0x17 /* SXFR_STATUS SCSI Bus Parity Error */
2094#define QHSTA_M_RDMA_PERR 0x18 /* RISC PCI DMA parity error */
2095#define QHSTA_M_SXFR_OFF_UFLW 0x19 /* SXFR_STATUS Offset Underflow */
2096#define QHSTA_M_SXFR_OFF_OFLW 0x20 /* SXFR_STATUS Offset Overflow */
2097#define QHSTA_M_SXFR_WD_TMO 0x21 /* SXFR_STATUS Watchdog Timeout */
2098#define QHSTA_M_SXFR_DESELECTED 0x22 /* SXFR_STATUS Deselected */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099/* Note: QHSTA_M_SXFR_XFR_OFLW is identical to QHSTA_M_DATA_OVER_RUN. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002100#define QHSTA_M_SXFR_XFR_OFLW 0x12 /* SXFR_STATUS Transfer Overflow */
2101#define QHSTA_M_SXFR_XFR_PH_ERR 0x24 /* SXFR_STATUS Transfer Phase Error */
2102#define QHSTA_M_SXFR_UNKNOWN_ERROR 0x25 /* SXFR_STATUS Unknown Error */
2103#define QHSTA_M_SCSI_BUS_RESET 0x30 /* Request aborted from SBR */
2104#define QHSTA_M_SCSI_BUS_RESET_UNSOL 0x31 /* Request aborted from unsol. SBR */
2105#define QHSTA_M_BUS_DEVICE_RESET 0x32 /* Request aborted from BDR */
2106#define QHSTA_M_DIRECTION_ERR 0x35 /* Data Phase mismatch */
2107#define QHSTA_M_DIRECTION_ERR_HUNG 0x36 /* Data Phase mismatch and bus hang */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108#define QHSTA_M_WTM_TIMEOUT 0x41
2109#define QHSTA_M_BAD_CMPL_STATUS_IN 0x42
2110#define QHSTA_M_NO_AUTO_REQ_SENSE 0x43
2111#define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002112#define QHSTA_M_INVALID_DEVICE 0x45 /* Bad target ID */
2113#define QHSTA_M_FROZEN_TIDQ 0x46 /* TID Queue frozen. */
2114#define QHSTA_M_SGBACKUP_ERROR 0x47 /* Scatter-Gather backup error */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116/* Return the address that is aligned at the next doubleword >= to 'addr'. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117#define ADV_32BALIGN(addr) (((ulong) (addr) + 0x1F) & ~0x1F)
2118
2119/*
2120 * Total contiguous memory needed for driver SG blocks.
2121 *
2122 * ADV_MAX_SG_LIST must be defined by a driver. It is the maximum
2123 * number of scatter-gather elements the driver supports in a
2124 * single request.
2125 */
2126
2127#define ADV_SG_LIST_MAX_BYTE_SIZE \
2128 (sizeof(ADV_SG_BLOCK) * \
2129 ((ADV_MAX_SG_LIST + (NO_OF_SG_PER_BLOCK - 1))/NO_OF_SG_PER_BLOCK))
2130
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002131/* struct asc_board flags */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002132#define ASC_IS_WIDE_BOARD 0x04 /* AdvanSys Wide Board */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133
2134#define ASC_NARROW_BOARD(boardp) (((boardp)->flags & ASC_IS_WIDE_BOARD) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002136#define NO_ISA_DMA 0xff /* No ISA DMA Channel Used */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002138#define ASC_INFO_SIZE 128 /* advansys_info() line size */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140/* Asc Library return codes */
2141#define ASC_TRUE 1
2142#define ASC_FALSE 0
2143#define ASC_NOERROR 1
2144#define ASC_BUSY 0
2145#define ASC_ERROR (-1)
2146
2147/* struct scsi_cmnd function return codes */
2148#define STATUS_BYTE(byte) (byte)
2149#define MSG_BYTE(byte) ((byte) << 8)
2150#define HOST_BYTE(byte) ((byte) << 16)
2151#define DRIVER_BYTE(byte) ((byte) << 24)
2152
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002153#define ASC_STATS(shost, counter) ASC_STATS_ADD(shost, counter, 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154#ifndef ADVANSYS_STATS
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002155#define ASC_STATS_ADD(shost, counter, count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156#else /* ADVANSYS_STATS */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002157#define ASC_STATS_ADD(shost, counter, count) \
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002158 (((struct asc_board *) shost_priv(shost))->asc_stats.counter += (count))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159#endif /* ADVANSYS_STATS */
2160
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161/* If the result wraps when calculating tenths, return 0. */
2162#define ASC_TENTHS(num, den) \
2163 (((10 * ((num)/(den))) > (((num) * 10)/(den))) ? \
2164 0 : ((((num) * 10)/(den)) - (10 * ((num)/(den)))))
2165
2166/*
2167 * Display a message to the console.
2168 */
2169#define ASC_PRINT(s) \
2170 { \
2171 printk("advansys: "); \
2172 printk(s); \
2173 }
2174
2175#define ASC_PRINT1(s, a1) \
2176 { \
2177 printk("advansys: "); \
2178 printk((s), (a1)); \
2179 }
2180
2181#define ASC_PRINT2(s, a1, a2) \
2182 { \
2183 printk("advansys: "); \
2184 printk((s), (a1), (a2)); \
2185 }
2186
2187#define ASC_PRINT3(s, a1, a2, a3) \
2188 { \
2189 printk("advansys: "); \
2190 printk((s), (a1), (a2), (a3)); \
2191 }
2192
2193#define ASC_PRINT4(s, a1, a2, a3, a4) \
2194 { \
2195 printk("advansys: "); \
2196 printk((s), (a1), (a2), (a3), (a4)); \
2197 }
2198
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199#ifndef ADVANSYS_DEBUG
2200
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002201#define ASC_DBG(lvl, s...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202#define ASC_DBG_PRT_SCSI_HOST(lvl, s)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203#define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp)
2204#define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
2205#define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone)
2206#define ADV_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
2207#define ASC_DBG_PRT_HEX(lvl, name, start, length)
2208#define ASC_DBG_PRT_CDB(lvl, cdb, len)
2209#define ASC_DBG_PRT_SENSE(lvl, sense, len)
2210#define ASC_DBG_PRT_INQUIRY(lvl, inq, len)
2211
2212#else /* ADVANSYS_DEBUG */
2213
2214/*
2215 * Debugging Message Levels:
2216 * 0: Errors Only
2217 * 1: High-Level Tracing
2218 * 2-N: Verbose Tracing
2219 */
2220
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002221#define ASC_DBG(lvl, format, arg...) { \
2222 if (asc_dbglvl >= (lvl)) \
2223 printk(KERN_DEBUG "%s: %s: " format, DRV_NAME, \
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07002224 __func__ , ## arg); \
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002225}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226
2227#define ASC_DBG_PRT_SCSI_HOST(lvl, s) \
2228 { \
2229 if (asc_dbglvl >= (lvl)) { \
2230 asc_prt_scsi_host(s); \
2231 } \
2232 }
2233
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234#define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp) \
2235 { \
2236 if (asc_dbglvl >= (lvl)) { \
2237 asc_prt_asc_scsi_q(scsiqp); \
2238 } \
2239 }
2240
2241#define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone) \
2242 { \
2243 if (asc_dbglvl >= (lvl)) { \
2244 asc_prt_asc_qdone_info(qdone); \
2245 } \
2246 }
2247
2248#define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp) \
2249 { \
2250 if (asc_dbglvl >= (lvl)) { \
2251 asc_prt_adv_scsi_req_q(scsiqp); \
2252 } \
2253 }
2254
2255#define ASC_DBG_PRT_HEX(lvl, name, start, length) \
2256 { \
2257 if (asc_dbglvl >= (lvl)) { \
2258 asc_prt_hex((name), (start), (length)); \
2259 } \
2260 }
2261
2262#define ASC_DBG_PRT_CDB(lvl, cdb, len) \
2263 ASC_DBG_PRT_HEX((lvl), "CDB", (uchar *) (cdb), (len));
2264
2265#define ASC_DBG_PRT_SENSE(lvl, sense, len) \
2266 ASC_DBG_PRT_HEX((lvl), "SENSE", (uchar *) (sense), (len));
2267
2268#define ASC_DBG_PRT_INQUIRY(lvl, inq, len) \
2269 ASC_DBG_PRT_HEX((lvl), "INQUIRY", (uchar *) (inq), (len));
2270#endif /* ADVANSYS_DEBUG */
2271
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272#ifdef ADVANSYS_STATS
2273
2274/* Per board statistics structure */
2275struct asc_stats {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002276 /* Driver Entrypoint Statistics */
Hannes Reinecke95cfab62015-04-24 13:18:27 +02002277 unsigned int queuecommand; /* # calls to advansys_queuecommand() */
2278 unsigned int reset; /* # calls to advansys_eh_bus_reset() */
2279 unsigned int biosparam; /* # calls to advansys_biosparam() */
2280 unsigned int interrupt; /* # advansys_interrupt() calls */
2281 unsigned int callback; /* # calls to asc/adv_isr_callback() */
2282 unsigned int done; /* # calls to request's scsi_done function */
2283 unsigned int build_error; /* # asc/adv_build_req() ASC_ERROR returns. */
2284 unsigned int adv_build_noreq; /* # adv_build_req() adv_req_t alloc. fail. */
2285 unsigned int adv_build_nosg; /* # adv_build_req() adv_sgblk_t alloc. fail. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002286 /* AscExeScsiQueue()/AdvExeScsiQueue() Statistics */
Hannes Reinecke95cfab62015-04-24 13:18:27 +02002287 unsigned int exe_noerror; /* # ASC_NOERROR returns. */
2288 unsigned int exe_busy; /* # ASC_BUSY returns. */
2289 unsigned int exe_error; /* # ASC_ERROR returns. */
2290 unsigned int exe_unknown; /* # unknown returns. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002291 /* Data Transfer Statistics */
Hannes Reinecke95cfab62015-04-24 13:18:27 +02002292 unsigned int xfer_cnt; /* # I/O requests received */
2293 unsigned int xfer_elem; /* # scatter-gather elements */
2294 unsigned int xfer_sect; /* # 512-byte blocks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295};
2296#endif /* ADVANSYS_STATS */
2297
2298/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 * Structure allocated for each board.
2300 *
Matthew Wilcox8dfb5372007-07-30 09:08:34 -06002301 * This structure is allocated by scsi_host_alloc() at the end
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 * of the 'Scsi_Host' structure starting at the 'hostdata'
2303 * field. It is guaranteed to be allocated from DMA-able memory.
2304 */
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002305struct asc_board {
Matthew Wilcox394dbf32007-07-26 11:56:40 -04002306 struct device *dev;
Hannes Reinecke9c17c622015-04-24 13:18:21 +02002307 struct Scsi_Host *shost;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002308 uint flags; /* Board flags */
Matthew Wilcoxd361db42007-10-02 21:55:29 -04002309 unsigned int irq;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002310 union {
2311 ASC_DVC_VAR asc_dvc_var; /* Narrow board */
2312 ADV_DVC_VAR adv_dvc_var; /* Wide board */
2313 } dvc_var;
2314 union {
2315 ASC_DVC_CFG asc_dvc_cfg; /* Narrow board */
2316 ADV_DVC_CFG adv_dvc_cfg; /* Wide board */
2317 } dvc_cfg;
2318 ushort asc_n_io_port; /* Number I/O ports. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002319 ADV_SCSI_BIT_ID_TYPE init_tidmask; /* Target init./valid mask */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002320 ushort reqcnt[ADV_MAX_TID + 1]; /* Starvation request count */
2321 ADV_SCSI_BIT_ID_TYPE queue_full; /* Queue full mask */
2322 ushort queue_full_cnt[ADV_MAX_TID + 1]; /* Queue full count */
2323 union {
2324 ASCEEP_CONFIG asc_eep; /* Narrow EEPROM config. */
2325 ADVEEP_3550_CONFIG adv_3550_eep; /* 3550 EEPROM config. */
2326 ADVEEP_38C0800_CONFIG adv_38C0800_eep; /* 38C0800 EEPROM config. */
2327 ADVEEP_38C1600_CONFIG adv_38C1600_eep; /* 38C1600 EEPROM config. */
2328 } eep_config;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002329 /* /proc/scsi/advansys/[0...] */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330#ifdef ADVANSYS_STATS
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002331 struct asc_stats asc_stats; /* Board statistics */
2332#endif /* ADVANSYS_STATS */
2333 /*
2334 * The following fields are used only for Narrow Boards.
2335 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002336 uchar sdtr_data[ASC_MAX_TID + 1]; /* SDTR information */
2337 /*
2338 * The following fields are used only for Wide Boards.
2339 */
2340 void __iomem *ioremap_addr; /* I/O Memory remap address. */
2341 ushort ioport; /* I/O Port address. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002342 adv_req_t *adv_reqp; /* Request structures. */
Hannes Reinecke4b47e462015-04-24 13:18:24 +02002343 dma_addr_t adv_reqp_addr;
2344 size_t adv_reqp_size;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02002345 struct dma_pool *adv_sgblk_pool; /* Scatter-gather structures. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002346 ushort bios_signature; /* BIOS Signature. */
2347 ushort bios_version; /* BIOS Version. */
2348 ushort bios_codeseg; /* BIOS Code Segment. */
2349 ushort bios_codelen; /* BIOS Code Segment Length. */
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002350};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -04002352#define asc_dvc_to_board(asc_dvc) container_of(asc_dvc, struct asc_board, \
2353 dvc_var.asc_dvc_var)
Matthew Wilcox13ac2d92007-07-30 08:10:23 -06002354#define adv_dvc_to_board(adv_dvc) container_of(adv_dvc, struct asc_board, \
2355 dvc_var.adv_dvc_var)
2356#define adv_dvc_to_pdev(adv_dvc) to_pci_dev(adv_dvc_to_board(adv_dvc)->dev)
2357
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358#ifdef ADVANSYS_DEBUG
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002359static int asc_dbglvl = 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361/*
Matthew Wilcox51219352007-10-02 21:55:22 -04002362 * asc_prt_asc_dvc_var()
2363 */
2364static void asc_prt_asc_dvc_var(ASC_DVC_VAR *h)
2365{
2366 printk("ASC_DVC_VAR at addr 0x%lx\n", (ulong)h);
2367
2368 printk(" iop_base 0x%x, err_code 0x%x, dvc_cntl 0x%x, bug_fix_cntl "
2369 "%d,\n", h->iop_base, h->err_code, h->dvc_cntl, h->bug_fix_cntl);
2370
2371 printk(" bus_type %d, init_sdtr 0x%x,\n", h->bus_type,
2372 (unsigned)h->init_sdtr);
2373
2374 printk(" sdtr_done 0x%x, use_tagged_qng 0x%x, unit_not_ready 0x%x, "
2375 "chip_no 0x%x,\n", (unsigned)h->sdtr_done,
2376 (unsigned)h->use_tagged_qng, (unsigned)h->unit_not_ready,
2377 (unsigned)h->chip_no);
2378
2379 printk(" queue_full_or_busy 0x%x, start_motor 0x%x, scsi_reset_wait "
2380 "%u,\n", (unsigned)h->queue_full_or_busy,
2381 (unsigned)h->start_motor, (unsigned)h->scsi_reset_wait);
2382
2383 printk(" is_in_int %u, max_total_qng %u, cur_total_qng %u, "
2384 "in_critical_cnt %u,\n", (unsigned)h->is_in_int,
2385 (unsigned)h->max_total_qng, (unsigned)h->cur_total_qng,
2386 (unsigned)h->in_critical_cnt);
2387
2388 printk(" last_q_shortage %u, init_state 0x%x, no_scam 0x%x, "
2389 "pci_fix_asyn_xfer 0x%x,\n", (unsigned)h->last_q_shortage,
2390 (unsigned)h->init_state, (unsigned)h->no_scam,
2391 (unsigned)h->pci_fix_asyn_xfer);
2392
Matthew Wilcoxd361db42007-10-02 21:55:29 -04002393 printk(" cfg 0x%lx\n", (ulong)h->cfg);
Matthew Wilcox51219352007-10-02 21:55:22 -04002394}
2395
2396/*
2397 * asc_prt_asc_dvc_cfg()
2398 */
2399static void asc_prt_asc_dvc_cfg(ASC_DVC_CFG *h)
2400{
2401 printk("ASC_DVC_CFG at addr 0x%lx\n", (ulong)h);
2402
2403 printk(" can_tagged_qng 0x%x, cmd_qng_enabled 0x%x,\n",
2404 h->can_tagged_qng, h->cmd_qng_enabled);
2405 printk(" disc_enable 0x%x, sdtr_enable 0x%x,\n",
2406 h->disc_enable, h->sdtr_enable);
2407
Matthew Wilcoxb08fc562007-10-02 21:55:32 -04002408 printk(" chip_scsi_id %d, isa_dma_speed %d, isa_dma_channel %d, "
2409 "chip_version %d,\n", h->chip_scsi_id, h->isa_dma_speed,
2410 h->isa_dma_channel, h->chip_version);
Matthew Wilcox51219352007-10-02 21:55:22 -04002411
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -04002412 printk(" mcode_date 0x%x, mcode_version %d\n",
2413 h->mcode_date, h->mcode_version);
Matthew Wilcox51219352007-10-02 21:55:22 -04002414}
2415
2416/*
Matthew Wilcox51219352007-10-02 21:55:22 -04002417 * asc_prt_adv_dvc_var()
2418 *
2419 * Display an ADV_DVC_VAR structure.
2420 */
2421static void asc_prt_adv_dvc_var(ADV_DVC_VAR *h)
2422{
2423 printk(" ADV_DVC_VAR at addr 0x%lx\n", (ulong)h);
2424
2425 printk(" iop_base 0x%lx, err_code 0x%x, ultra_able 0x%x\n",
2426 (ulong)h->iop_base, h->err_code, (unsigned)h->ultra_able);
2427
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002428 printk(" sdtr_able 0x%x, wdtr_able 0x%x\n",
2429 (unsigned)h->sdtr_able, (unsigned)h->wdtr_able);
Matthew Wilcox51219352007-10-02 21:55:22 -04002430
Matthew Wilcoxd361db42007-10-02 21:55:29 -04002431 printk(" start_motor 0x%x, scsi_reset_wait 0x%x\n",
2432 (unsigned)h->start_motor, (unsigned)h->scsi_reset_wait);
Matthew Wilcox51219352007-10-02 21:55:22 -04002433
Hannes Reinecke98b96a72015-04-24 13:18:23 +02002434 printk(" max_host_qng %u, max_dvc_qng %u, carr_freelist 0x%p\n",
Matthew Wilcox51219352007-10-02 21:55:22 -04002435 (unsigned)h->max_host_qng, (unsigned)h->max_dvc_qng,
Hannes Reinecke98b96a72015-04-24 13:18:23 +02002436 h->carr_freelist);
Matthew Wilcox51219352007-10-02 21:55:22 -04002437
Hannes Reinecke98b96a72015-04-24 13:18:23 +02002438 printk(" icq_sp 0x%p, irq_sp 0x%p\n", h->icq_sp, h->irq_sp);
Matthew Wilcox51219352007-10-02 21:55:22 -04002439
2440 printk(" no_scam 0x%x, tagqng_able 0x%x\n",
2441 (unsigned)h->no_scam, (unsigned)h->tagqng_able);
2442
2443 printk(" chip_scsi_id 0x%x, cfg 0x%lx\n",
2444 (unsigned)h->chip_scsi_id, (ulong)h->cfg);
2445}
2446
2447/*
2448 * asc_prt_adv_dvc_cfg()
2449 *
2450 * Display an ADV_DVC_CFG structure.
2451 */
2452static void asc_prt_adv_dvc_cfg(ADV_DVC_CFG *h)
2453{
2454 printk(" ADV_DVC_CFG at addr 0x%lx\n", (ulong)h);
2455
2456 printk(" disc_enable 0x%x, termination 0x%x\n",
2457 h->disc_enable, h->termination);
2458
2459 printk(" chip_version 0x%x, mcode_date 0x%x\n",
2460 h->chip_version, h->mcode_date);
2461
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002462 printk(" mcode_version 0x%x, control_flag 0x%x\n",
2463 h->mcode_version, h->control_flag);
Matthew Wilcox51219352007-10-02 21:55:22 -04002464}
2465
2466/*
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002467 * asc_prt_scsi_host()
Matthew Wilcox51219352007-10-02 21:55:22 -04002468 */
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002469static void asc_prt_scsi_host(struct Scsi_Host *s)
Matthew Wilcox51219352007-10-02 21:55:22 -04002470{
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002471 struct asc_board *boardp = shost_priv(s);
Matthew Wilcox51219352007-10-02 21:55:22 -04002472
Kay Sievers71610f52008-12-03 22:41:36 +01002473 printk("Scsi_Host at addr 0x%p, device %s\n", s, dev_name(boardp->dev));
Hannes Reinecke50d14a72013-10-23 10:51:17 +02002474 printk(" host_busy %u, host_no %d,\n",
Christoph Hellwig74665012014-01-22 15:29:29 +01002475 atomic_read(&s->host_busy), s->host_no);
Matthew Wilcox51219352007-10-02 21:55:22 -04002476
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002477 printk(" base 0x%lx, io_port 0x%lx, irq %d,\n",
2478 (ulong)s->base, (ulong)s->io_port, boardp->irq);
Matthew Wilcox51219352007-10-02 21:55:22 -04002479
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002480 printk(" dma_channel %d, this_id %d, can_queue %d,\n",
2481 s->dma_channel, s->this_id, s->can_queue);
Matthew Wilcox51219352007-10-02 21:55:22 -04002482
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002483 printk(" cmd_per_lun %d, sg_tablesize %d, unchecked_isa_dma %d\n",
2484 s->cmd_per_lun, s->sg_tablesize, s->unchecked_isa_dma);
Matthew Wilcox51219352007-10-02 21:55:22 -04002485
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002486 if (ASC_NARROW_BOARD(boardp)) {
2487 asc_prt_asc_dvc_var(&boardp->dvc_var.asc_dvc_var);
2488 asc_prt_asc_dvc_cfg(&boardp->dvc_cfg.asc_dvc_cfg);
2489 } else {
2490 asc_prt_adv_dvc_var(&boardp->dvc_var.adv_dvc_var);
2491 asc_prt_adv_dvc_cfg(&boardp->dvc_cfg.adv_dvc_cfg);
Matthew Wilcox51219352007-10-02 21:55:22 -04002492 }
2493}
2494
2495/*
2496 * asc_prt_hex()
2497 *
2498 * Print hexadecimal output in 4 byte groupings 32 bytes
2499 * or 8 double-words per line.
2500 */
2501static void asc_prt_hex(char *f, uchar *s, int l)
2502{
2503 int i;
2504 int j;
2505 int k;
2506 int m;
2507
2508 printk("%s: (%d bytes)\n", f, l);
2509
2510 for (i = 0; i < l; i += 32) {
2511
2512 /* Display a maximum of 8 double-words per line. */
2513 if ((k = (l - i) / 4) >= 8) {
2514 k = 8;
2515 m = 0;
2516 } else {
2517 m = (l - i) % 4;
2518 }
2519
2520 for (j = 0; j < k; j++) {
2521 printk(" %2.2X%2.2X%2.2X%2.2X",
2522 (unsigned)s[i + (j * 4)],
2523 (unsigned)s[i + (j * 4) + 1],
2524 (unsigned)s[i + (j * 4) + 2],
2525 (unsigned)s[i + (j * 4) + 3]);
2526 }
2527
2528 switch (m) {
2529 case 0:
2530 default:
2531 break;
2532 case 1:
2533 printk(" %2.2X", (unsigned)s[i + (j * 4)]);
2534 break;
2535 case 2:
2536 printk(" %2.2X%2.2X",
2537 (unsigned)s[i + (j * 4)],
2538 (unsigned)s[i + (j * 4) + 1]);
2539 break;
2540 case 3:
2541 printk(" %2.2X%2.2X%2.2X",
2542 (unsigned)s[i + (j * 4) + 1],
2543 (unsigned)s[i + (j * 4) + 2],
2544 (unsigned)s[i + (j * 4) + 3]);
2545 break;
2546 }
2547
2548 printk("\n");
2549 }
2550}
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002551
2552/*
2553 * asc_prt_asc_scsi_q()
2554 */
2555static void asc_prt_asc_scsi_q(ASC_SCSI_Q *q)
2556{
2557 ASC_SG_HEAD *sgp;
2558 int i;
2559
2560 printk("ASC_SCSI_Q at addr 0x%lx\n", (ulong)q);
2561
2562 printk
Hannes Reinecke9c17c622015-04-24 13:18:21 +02002563 (" target_ix 0x%x, target_lun %u, srb_tag 0x%x, tag_code 0x%x,\n",
2564 q->q2.target_ix, q->q1.target_lun, q->q2.srb_tag,
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002565 q->q2.tag_code);
2566
2567 printk
2568 (" data_addr 0x%lx, data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
2569 (ulong)le32_to_cpu(q->q1.data_addr),
2570 (ulong)le32_to_cpu(q->q1.data_cnt),
2571 (ulong)le32_to_cpu(q->q1.sense_addr), q->q1.sense_len);
2572
2573 printk(" cdbptr 0x%lx, cdb_len %u, sg_head 0x%lx, sg_queue_cnt %u\n",
2574 (ulong)q->cdbptr, q->q2.cdb_len,
2575 (ulong)q->sg_head, q->q1.sg_queue_cnt);
2576
2577 if (q->sg_head) {
2578 sgp = q->sg_head;
2579 printk("ASC_SG_HEAD at addr 0x%lx\n", (ulong)sgp);
2580 printk(" entry_cnt %u, queue_cnt %u\n", sgp->entry_cnt,
2581 sgp->queue_cnt);
2582 for (i = 0; i < sgp->entry_cnt; i++) {
2583 printk(" [%u]: addr 0x%lx, bytes %lu\n",
2584 i, (ulong)le32_to_cpu(sgp->sg_list[i].addr),
2585 (ulong)le32_to_cpu(sgp->sg_list[i].bytes));
2586 }
2587
2588 }
2589}
2590
2591/*
2592 * asc_prt_asc_qdone_info()
2593 */
2594static void asc_prt_asc_qdone_info(ASC_QDONE_INFO *q)
2595{
2596 printk("ASC_QDONE_INFO at addr 0x%lx\n", (ulong)q);
Hannes Reinecke9c17c622015-04-24 13:18:21 +02002597 printk(" srb_tag 0x%x, target_ix %u, cdb_len %u, tag_code %u,\n",
2598 q->d2.srb_tag, q->d2.target_ix, q->d2.cdb_len,
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002599 q->d2.tag_code);
2600 printk
2601 (" done_stat 0x%x, host_stat 0x%x, scsi_stat 0x%x, scsi_msg 0x%x\n",
2602 q->d3.done_stat, q->d3.host_stat, q->d3.scsi_stat, q->d3.scsi_msg);
2603}
2604
2605/*
2606 * asc_prt_adv_sgblock()
2607 *
2608 * Display an ADV_SG_BLOCK structure.
2609 */
2610static void asc_prt_adv_sgblock(int sgblockno, ADV_SG_BLOCK *b)
2611{
2612 int i;
2613
Hannes Reinecke0ce53822015-04-24 13:18:25 +02002614 printk(" ADV_SG_BLOCK at addr 0x%lx (sgblockno %d)\n",
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002615 (ulong)b, sgblockno);
2616 printk(" sg_cnt %u, sg_ptr 0x%lx\n",
2617 b->sg_cnt, (ulong)le32_to_cpu(b->sg_ptr));
2618 BUG_ON(b->sg_cnt > NO_OF_SG_PER_BLOCK);
2619 if (b->sg_ptr != 0)
2620 BUG_ON(b->sg_cnt != NO_OF_SG_PER_BLOCK);
2621 for (i = 0; i < b->sg_cnt; i++) {
2622 printk(" [%u]: sg_addr 0x%lx, sg_count 0x%lx\n",
2623 i, (ulong)b->sg_list[i].sg_addr,
2624 (ulong)b->sg_list[i].sg_count);
2625 }
2626}
2627
2628/*
2629 * asc_prt_adv_scsi_req_q()
2630 *
2631 * Display an ADV_SCSI_REQ_Q structure.
2632 */
2633static void asc_prt_adv_scsi_req_q(ADV_SCSI_REQ_Q *q)
2634{
2635 int sg_blk_cnt;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02002636 struct adv_sg_block *sg_ptr;
2637 adv_sgblk_t *sgblkp;
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002638
2639 printk("ADV_SCSI_REQ_Q at addr 0x%lx\n", (ulong)q);
2640
Hannes Reinecke9c17c622015-04-24 13:18:21 +02002641 printk(" target_id %u, target_lun %u, srb_tag 0x%x, a_flag 0x%x\n",
2642 q->target_id, q->target_lun, q->srb_tag, q->a_flag);
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002643
Hannes Reinecke98b96a72015-04-24 13:18:23 +02002644 printk(" cntl 0x%x, data_addr 0x%lx\n",
2645 q->cntl, (ulong)le32_to_cpu(q->data_addr));
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002646
2647 printk(" data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
2648 (ulong)le32_to_cpu(q->data_cnt),
2649 (ulong)le32_to_cpu(q->sense_addr), q->sense_len);
2650
2651 printk
2652 (" cdb_len %u, done_status 0x%x, host_status 0x%x, scsi_status 0x%x\n",
2653 q->cdb_len, q->done_status, q->host_status, q->scsi_status);
2654
2655 printk(" sg_working_ix 0x%x, target_cmd %u\n",
2656 q->sg_working_ix, q->target_cmd);
2657
2658 printk(" scsiq_rptr 0x%lx, sg_real_addr 0x%lx, sg_list_ptr 0x%lx\n",
2659 (ulong)le32_to_cpu(q->scsiq_rptr),
2660 (ulong)le32_to_cpu(q->sg_real_addr), (ulong)q->sg_list_ptr);
2661
2662 /* Display the request's ADV_SG_BLOCK structures. */
2663 if (q->sg_list_ptr != NULL) {
Hannes Reinecke0ce53822015-04-24 13:18:25 +02002664 sgblkp = container_of(q->sg_list_ptr, adv_sgblk_t, sg_block);
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002665 sg_blk_cnt = 0;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02002666 while (sgblkp) {
2667 sg_ptr = &sgblkp->sg_block;
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002668 asc_prt_adv_sgblock(sg_blk_cnt, sg_ptr);
2669 if (sg_ptr->sg_ptr == 0) {
2670 break;
2671 }
Hannes Reinecke0ce53822015-04-24 13:18:25 +02002672 sgblkp = sgblkp->next_sgblkp;
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002673 sg_blk_cnt++;
2674 }
2675 }
2676}
Matthew Wilcox51219352007-10-02 21:55:22 -04002677#endif /* ADVANSYS_DEBUG */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678
2679/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 * advansys_info()
2681 *
2682 * Return suitable for printing on the console with the argument
2683 * adapter's configuration information.
2684 *
2685 * Note: The information line should not exceed ASC_INFO_SIZE bytes,
2686 * otherwise the static 'info' array will be overrun.
2687 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002688static const char *advansys_info(struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689{
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002690 static char info[ASC_INFO_SIZE];
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002691 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002692 ASC_DVC_VAR *asc_dvc_varp;
2693 ADV_DVC_VAR *adv_dvc_varp;
2694 char *busname;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002695 char *widename = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002697 if (ASC_NARROW_BOARD(boardp)) {
2698 asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002699 ASC_DBG(1, "begin\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002700 if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
2701 if ((asc_dvc_varp->bus_type & ASC_IS_ISAPNP) ==
2702 ASC_IS_ISAPNP) {
2703 busname = "ISA PnP";
2704 } else {
2705 busname = "ISA";
2706 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002707 sprintf(info,
2708 "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X, DMA 0x%X",
2709 ASC_VERSION, busname,
2710 (ulong)shost->io_port,
Matthew Wilcox4a2d31c2007-07-26 11:55:34 -04002711 (ulong)shost->io_port + ASC_IOADR_GAP - 1,
Matthew Wilcoxd361db42007-10-02 21:55:29 -04002712 boardp->irq, shost->dma_channel);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002713 } else {
2714 if (asc_dvc_varp->bus_type & ASC_IS_VL) {
2715 busname = "VL";
2716 } else if (asc_dvc_varp->bus_type & ASC_IS_EISA) {
2717 busname = "EISA";
2718 } else if (asc_dvc_varp->bus_type & ASC_IS_PCI) {
2719 if ((asc_dvc_varp->bus_type & ASC_IS_PCI_ULTRA)
2720 == ASC_IS_PCI_ULTRA) {
2721 busname = "PCI Ultra";
2722 } else {
2723 busname = "PCI";
2724 }
2725 } else {
2726 busname = "?";
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04002727 shost_printk(KERN_ERR, shost, "unknown bus "
2728 "type %d\n", asc_dvc_varp->bus_type);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002729 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002730 sprintf(info,
2731 "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X",
Matthew Wilcoxecec1942007-07-30 08:08:22 -06002732 ASC_VERSION, busname, (ulong)shost->io_port,
Matthew Wilcox4a2d31c2007-07-26 11:55:34 -04002733 (ulong)shost->io_port + ASC_IOADR_GAP - 1,
Matthew Wilcoxd361db42007-10-02 21:55:29 -04002734 boardp->irq);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002735 }
2736 } else {
2737 /*
2738 * Wide Adapter Information
2739 *
2740 * Memory-mapped I/O is used instead of I/O space to access
2741 * the adapter, but display the I/O Port range. The Memory
2742 * I/O address is displayed through the driver /proc file.
2743 */
2744 adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
2745 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002746 widename = "Ultra-Wide";
2747 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002748 widename = "Ultra2-Wide";
2749 } else {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002750 widename = "Ultra3-Wide";
2751 }
2752 sprintf(info,
2753 "AdvanSys SCSI %s: PCI %s: PCIMEM 0x%lX-0x%lX, IRQ 0x%X",
2754 ASC_VERSION, widename, (ulong)adv_dvc_varp->iop_base,
Matthew Wilcoxd361db42007-10-02 21:55:29 -04002755 (ulong)adv_dvc_varp->iop_base + boardp->asc_n_io_port - 1, boardp->irq);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002756 }
Matthew Wilcoxb009bef2007-09-09 08:56:38 -06002757 BUG_ON(strlen(info) >= ASC_INFO_SIZE);
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002758 ASC_DBG(1, "end\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002759 return info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760}
2761
Matthew Wilcox51219352007-10-02 21:55:22 -04002762#ifdef CONFIG_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763
2764/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765 * asc_prt_board_devices()
2766 *
2767 * Print driver information for devices attached to the board.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 */
Al Virob59fb6f2013-03-31 02:59:55 -04002769static void asc_prt_board_devices(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002771 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002772 int chip_scsi_id;
2773 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774
Al Virob59fb6f2013-03-31 02:59:55 -04002775 seq_printf(m,
2776 "\nDevice Information for AdvanSys SCSI Host %d:\n",
2777 shost->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002779 if (ASC_NARROW_BOARD(boardp)) {
2780 chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
2781 } else {
2782 chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
2783 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784
Rasmus Villemoes2f979422014-12-03 00:10:50 +01002785 seq_puts(m, "Target IDs Detected:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002786 for (i = 0; i <= ADV_MAX_TID; i++) {
Al Virob59fb6f2013-03-31 02:59:55 -04002787 if (boardp->init_tidmask & ADV_TID_TO_TIDMASK(i))
2788 seq_printf(m, " %X,", i);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002789 }
Al Virob59fb6f2013-03-31 02:59:55 -04002790 seq_printf(m, " (%X=Host Adapter)\n", chip_scsi_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791}
2792
2793/*
2794 * Display Wide Board BIOS Information.
2795 */
Al Virob59fb6f2013-03-31 02:59:55 -04002796static void asc_prt_adv_bios(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002798 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002799 ushort major, minor, letter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800
Rasmus Villemoes2f979422014-12-03 00:10:50 +01002801 seq_puts(m, "\nROM BIOS Version: ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002803 /*
2804 * If the BIOS saved a valid signature, then fill in
2805 * the BIOS code segment base address.
2806 */
2807 if (boardp->bios_signature != 0x55AA) {
Rasmus Villemoes3d300792014-12-03 00:10:53 +01002808 seq_puts(m, "Disabled or Pre-3.1\n"
2809 "BIOS either disabled or Pre-3.1. If it is pre-3.1, then a newer version\n"
2810 "can be found at the ConnectCom FTP site: ftp://ftp.connectcom.net/pub\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002811 } else {
2812 major = (boardp->bios_version >> 12) & 0xF;
2813 minor = (boardp->bios_version >> 8) & 0xF;
2814 letter = (boardp->bios_version & 0xFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815
Al Virob59fb6f2013-03-31 02:59:55 -04002816 seq_printf(m, "%d.%d%c\n",
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002817 major, minor,
2818 letter >= 26 ? '?' : letter + 'A');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002819 /*
2820 * Current available ROM BIOS release is 3.1I for UW
2821 * and 3.2I for U2W. This code doesn't differentiate
2822 * UW and U2W boards.
2823 */
2824 if (major < 3 || (major <= 3 && minor < 1) ||
2825 (major <= 3 && minor <= 1 && letter < ('I' - 'A'))) {
Rasmus Villemoes3d300792014-12-03 00:10:53 +01002826 seq_puts(m, "Newer version of ROM BIOS is available at the ConnectCom FTP site:\n"
2827 "ftp://ftp.connectcom.net/pub\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002828 }
2829 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830}
2831
2832/*
2833 * Add serial number to information bar if signature AAh
2834 * is found in at bit 15-9 (7 bits) of word 1.
2835 *
2836 * Serial Number consists fo 12 alpha-numeric digits.
2837 *
2838 * 1 - Product type (A,B,C,D..) Word0: 15-13 (3 bits)
2839 * 2 - MFG Location (A,B,C,D..) Word0: 12-10 (3 bits)
2840 * 3-4 - Product ID (0-99) Word0: 9-0 (10 bits)
2841 * 5 - Product revision (A-J) Word0: " "
2842 *
2843 * Signature Word1: 15-9 (7 bits)
2844 * 6 - Year (0-9) Word1: 8-6 (3 bits) & Word2: 15 (1 bit)
2845 * 7-8 - Week of the year (1-52) Word1: 5-0 (6 bits)
2846 *
2847 * 9-12 - Serial Number (A001-Z999) Word2: 14-0 (15 bits)
2848 *
2849 * Note 1: Only production cards will have a serial number.
2850 *
2851 * Note 2: Signature is most significant 7 bits (0xFE).
2852 *
2853 * Returns ASC_TRUE if serial number found, otherwise returns ASC_FALSE.
2854 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002855static int asc_get_eeprom_string(ushort *serialnum, uchar *cp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856{
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002857 ushort w, num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002859 if ((serialnum[1] & 0xFE00) != ((ushort)0xAA << 8)) {
2860 return ASC_FALSE;
2861 } else {
2862 /*
2863 * First word - 6 digits.
2864 */
2865 w = serialnum[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002867 /* Product type - 1st digit. */
2868 if ((*cp = 'A' + ((w & 0xE000) >> 13)) == 'H') {
2869 /* Product type is P=Prototype */
2870 *cp += 0x8;
2871 }
2872 cp++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002874 /* Manufacturing location - 2nd digit. */
2875 *cp++ = 'A' + ((w & 0x1C00) >> 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002877 /* Product ID - 3rd, 4th digits. */
2878 num = w & 0x3FF;
2879 *cp++ = '0' + (num / 100);
2880 num %= 100;
2881 *cp++ = '0' + (num / 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002883 /* Product revision - 5th digit. */
2884 *cp++ = 'A' + (num % 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002886 /*
2887 * Second word
2888 */
2889 w = serialnum[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002891 /*
2892 * Year - 6th digit.
2893 *
2894 * If bit 15 of third word is set, then the
2895 * last digit of the year is greater than 7.
2896 */
2897 if (serialnum[2] & 0x8000) {
2898 *cp++ = '8' + ((w & 0x1C0) >> 6);
2899 } else {
2900 *cp++ = '0' + ((w & 0x1C0) >> 6);
2901 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002903 /* Week of year - 7th, 8th digits. */
2904 num = w & 0x003F;
2905 *cp++ = '0' + num / 10;
2906 num %= 10;
2907 *cp++ = '0' + num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002909 /*
2910 * Third word
2911 */
2912 w = serialnum[2] & 0x7FFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002914 /* Serial number - 9th digit. */
2915 *cp++ = 'A' + (w / 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002917 /* 10th, 11th, 12th digits. */
2918 num = w % 1000;
2919 *cp++ = '0' + num / 100;
2920 num %= 100;
2921 *cp++ = '0' + num / 10;
2922 num %= 10;
2923 *cp++ = '0' + num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002925 *cp = '\0'; /* Null Terminate the string. */
2926 return ASC_TRUE;
2927 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928}
2929
2930/*
2931 * asc_prt_asc_board_eeprom()
2932 *
2933 * Print board EEPROM configuration.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 */
Al Virob59fb6f2013-03-31 02:59:55 -04002935static void asc_prt_asc_board_eeprom(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002937 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002938 ASC_DVC_VAR *asc_dvc_varp;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002939 ASCEEP_CONFIG *ep;
2940 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941#ifdef CONFIG_ISA
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002942 int isa_dma_speed[] = { 10, 8, 7, 6, 5, 4, 3, 2 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943#endif /* CONFIG_ISA */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002944 uchar serialstr[13];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002946 asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
2947 ep = &boardp->eep_config.asc_eep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948
Al Virob59fb6f2013-03-31 02:59:55 -04002949 seq_printf(m,
2950 "\nEEPROM Settings for AdvanSys SCSI Host %d:\n",
2951 shost->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002953 if (asc_get_eeprom_string((ushort *)&ep->adapter_info[0], serialstr)
Al Virob59fb6f2013-03-31 02:59:55 -04002954 == ASC_TRUE)
2955 seq_printf(m, " Serial Number: %s\n", serialstr);
2956 else if (ep->adapter_info[5] == 0xBB)
Rasmus Villemoes2f979422014-12-03 00:10:50 +01002957 seq_puts(m,
2958 " Default Settings Used for EEPROM-less Adapter.\n");
Al Virob59fb6f2013-03-31 02:59:55 -04002959 else
Rasmus Villemoes2f979422014-12-03 00:10:50 +01002960 seq_puts(m, " Serial Number Signature Not Present.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961
Al Virob59fb6f2013-03-31 02:59:55 -04002962 seq_printf(m,
2963 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
2964 ASC_EEP_GET_CHIP_ID(ep), ep->max_total_qng,
2965 ep->max_tag_qng);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966
Al Virob59fb6f2013-03-31 02:59:55 -04002967 seq_printf(m,
2968 " cntl 0x%x, no_scam 0x%x\n", ep->cntl, ep->no_scam);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969
Rasmus Villemoes2f979422014-12-03 00:10:50 +01002970 seq_puts(m, " Target ID: ");
Al Virob59fb6f2013-03-31 02:59:55 -04002971 for (i = 0; i <= ASC_MAX_TID; i++)
2972 seq_printf(m, " %d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973
Rasmus Villemoes3d300792014-12-03 00:10:53 +01002974 seq_puts(m, "\n Disconnects: ");
Al Virob59fb6f2013-03-31 02:59:55 -04002975 for (i = 0; i <= ASC_MAX_TID; i++)
2976 seq_printf(m, " %c",
2977 (ep->disc_enable & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978
Rasmus Villemoes3d300792014-12-03 00:10:53 +01002979 seq_puts(m, "\n Command Queuing: ");
Al Virob59fb6f2013-03-31 02:59:55 -04002980 for (i = 0; i <= ASC_MAX_TID; i++)
2981 seq_printf(m, " %c",
2982 (ep->use_cmd_qng & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983
Rasmus Villemoes3d300792014-12-03 00:10:53 +01002984 seq_puts(m, "\n Start Motor: ");
Al Virob59fb6f2013-03-31 02:59:55 -04002985 for (i = 0; i <= ASC_MAX_TID; i++)
2986 seq_printf(m, " %c",
2987 (ep->start_motor & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988
Rasmus Villemoes3d300792014-12-03 00:10:53 +01002989 seq_puts(m, "\n Synchronous Transfer:");
Al Virob59fb6f2013-03-31 02:59:55 -04002990 for (i = 0; i <= ASC_MAX_TID; i++)
2991 seq_printf(m, " %c",
2992 (ep->init_sdtr & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01002993 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994
2995#ifdef CONFIG_ISA
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002996 if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
Al Virob59fb6f2013-03-31 02:59:55 -04002997 seq_printf(m,
2998 " Host ISA DMA speed: %d MB/S\n",
2999 isa_dma_speed[ASC_EEP_GET_DMA_SPD(ep)]);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003000 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001#endif /* CONFIG_ISA */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002}
3003
3004/*
3005 * asc_prt_adv_board_eeprom()
3006 *
3007 * Print board EEPROM configuration.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008 */
Al Virob59fb6f2013-03-31 02:59:55 -04003009static void asc_prt_adv_board_eeprom(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04003011 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003012 ADV_DVC_VAR *adv_dvc_varp;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003013 int i;
3014 char *termstr;
3015 uchar serialstr[13];
3016 ADVEEP_3550_CONFIG *ep_3550 = NULL;
3017 ADVEEP_38C0800_CONFIG *ep_38C0800 = NULL;
3018 ADVEEP_38C1600_CONFIG *ep_38C1600 = NULL;
3019 ushort word;
3020 ushort *wordp;
3021 ushort sdtr_speed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003023 adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
3024 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
3025 ep_3550 = &boardp->eep_config.adv_3550_eep;
3026 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
3027 ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
3028 } else {
3029 ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
3030 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031
Al Virob59fb6f2013-03-31 02:59:55 -04003032 seq_printf(m,
3033 "\nEEPROM Settings for AdvanSys SCSI Host %d:\n",
3034 shost->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003036 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
3037 wordp = &ep_3550->serial_number_word1;
3038 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
3039 wordp = &ep_38C0800->serial_number_word1;
3040 } else {
3041 wordp = &ep_38C1600->serial_number_word1;
3042 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043
Al Virob59fb6f2013-03-31 02:59:55 -04003044 if (asc_get_eeprom_string(wordp, serialstr) == ASC_TRUE)
3045 seq_printf(m, " Serial Number: %s\n", serialstr);
3046 else
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003047 seq_puts(m, " Serial Number Signature Not Present.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048
Al Virob59fb6f2013-03-31 02:59:55 -04003049 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
3050 seq_printf(m,
3051 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
3052 ep_3550->adapter_scsi_id,
3053 ep_3550->max_host_qng, ep_3550->max_dvc_qng);
3054 else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
3055 seq_printf(m,
3056 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
3057 ep_38C0800->adapter_scsi_id,
3058 ep_38C0800->max_host_qng,
3059 ep_38C0800->max_dvc_qng);
3060 else
3061 seq_printf(m,
3062 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
3063 ep_38C1600->adapter_scsi_id,
3064 ep_38C1600->max_host_qng,
3065 ep_38C1600->max_dvc_qng);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003066 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
3067 word = ep_3550->termination;
3068 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
3069 word = ep_38C0800->termination_lvd;
3070 } else {
3071 word = ep_38C1600->termination_lvd;
3072 }
3073 switch (word) {
3074 case 1:
3075 termstr = "Low Off/High Off";
3076 break;
3077 case 2:
3078 termstr = "Low Off/High On";
3079 break;
3080 case 3:
3081 termstr = "Low On/High On";
3082 break;
3083 default:
3084 case 0:
3085 termstr = "Automatic";
3086 break;
3087 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088
Al Virob59fb6f2013-03-31 02:59:55 -04003089 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
3090 seq_printf(m,
3091 " termination: %u (%s), bios_ctrl: 0x%x\n",
3092 ep_3550->termination, termstr,
3093 ep_3550->bios_ctrl);
3094 else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
3095 seq_printf(m,
3096 " termination: %u (%s), bios_ctrl: 0x%x\n",
3097 ep_38C0800->termination_lvd, termstr,
3098 ep_38C0800->bios_ctrl);
3099 else
3100 seq_printf(m,
3101 " termination: %u (%s), bios_ctrl: 0x%x\n",
3102 ep_38C1600->termination_lvd, termstr,
3103 ep_38C1600->bios_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003105 seq_puts(m, " Target ID: ");
Al Virob59fb6f2013-03-31 02:59:55 -04003106 for (i = 0; i <= ADV_MAX_TID; i++)
3107 seq_printf(m, " %X", i);
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003108 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003110 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
3111 word = ep_3550->disc_enable;
3112 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
3113 word = ep_38C0800->disc_enable;
3114 } else {
3115 word = ep_38C1600->disc_enable;
3116 }
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003117 seq_puts(m, " Disconnects: ");
Al Virob59fb6f2013-03-31 02:59:55 -04003118 for (i = 0; i <= ADV_MAX_TID; i++)
3119 seq_printf(m, " %c",
3120 (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003121 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003123 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
3124 word = ep_3550->tagqng_able;
3125 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
3126 word = ep_38C0800->tagqng_able;
3127 } else {
3128 word = ep_38C1600->tagqng_able;
3129 }
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003130 seq_puts(m, " Command Queuing: ");
Al Virob59fb6f2013-03-31 02:59:55 -04003131 for (i = 0; i <= ADV_MAX_TID; i++)
3132 seq_printf(m, " %c",
3133 (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003134 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003136 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
3137 word = ep_3550->start_motor;
3138 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
3139 word = ep_38C0800->start_motor;
3140 } else {
3141 word = ep_38C1600->start_motor;
3142 }
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003143 seq_puts(m, " Start Motor: ");
Al Virob59fb6f2013-03-31 02:59:55 -04003144 for (i = 0; i <= ADV_MAX_TID; i++)
3145 seq_printf(m, " %c",
3146 (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003147 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003149 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003150 seq_puts(m, " Synchronous Transfer:");
Al Virob59fb6f2013-03-31 02:59:55 -04003151 for (i = 0; i <= ADV_MAX_TID; i++)
3152 seq_printf(m, " %c",
3153 (ep_3550->sdtr_able & ADV_TID_TO_TIDMASK(i)) ?
3154 'Y' : 'N');
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003155 seq_putc(m, '\n');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003156 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003158 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003159 seq_puts(m, " Ultra Transfer: ");
Al Virob59fb6f2013-03-31 02:59:55 -04003160 for (i = 0; i <= ADV_MAX_TID; i++)
3161 seq_printf(m, " %c",
3162 (ep_3550->ultra_able & ADV_TID_TO_TIDMASK(i))
3163 ? 'Y' : 'N');
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003164 seq_putc(m, '\n');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003165 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003167 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
3168 word = ep_3550->wdtr_able;
3169 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
3170 word = ep_38C0800->wdtr_able;
3171 } else {
3172 word = ep_38C1600->wdtr_able;
3173 }
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003174 seq_puts(m, " Wide Transfer: ");
Al Virob59fb6f2013-03-31 02:59:55 -04003175 for (i = 0; i <= ADV_MAX_TID; i++)
3176 seq_printf(m, " %c",
3177 (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003178 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003180 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800 ||
3181 adv_dvc_varp->chip_type == ADV_CHIP_ASC38C1600) {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003182 seq_puts(m, " Synchronous Transfer Speed (Mhz):\n ");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003183 for (i = 0; i <= ADV_MAX_TID; i++) {
3184 char *speed_str;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003186 if (i == 0) {
3187 sdtr_speed = adv_dvc_varp->sdtr_speed1;
3188 } else if (i == 4) {
3189 sdtr_speed = adv_dvc_varp->sdtr_speed2;
3190 } else if (i == 8) {
3191 sdtr_speed = adv_dvc_varp->sdtr_speed3;
3192 } else if (i == 12) {
3193 sdtr_speed = adv_dvc_varp->sdtr_speed4;
3194 }
3195 switch (sdtr_speed & ADV_MAX_TID) {
3196 case 0:
3197 speed_str = "Off";
3198 break;
3199 case 1:
3200 speed_str = " 5";
3201 break;
3202 case 2:
3203 speed_str = " 10";
3204 break;
3205 case 3:
3206 speed_str = " 20";
3207 break;
3208 case 4:
3209 speed_str = " 40";
3210 break;
3211 case 5:
3212 speed_str = " 80";
3213 break;
3214 default:
3215 speed_str = "Unk";
3216 break;
3217 }
Al Virob59fb6f2013-03-31 02:59:55 -04003218 seq_printf(m, "%X:%s ", i, speed_str);
3219 if (i == 7)
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003220 seq_puts(m, "\n ");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003221 sdtr_speed >>= 4;
3222 }
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003223 seq_putc(m, '\n');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003224 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225}
3226
3227/*
3228 * asc_prt_driver_conf()
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 */
Al Virob59fb6f2013-03-31 02:59:55 -04003230static void asc_prt_driver_conf(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04003232 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003233 int chip_scsi_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234
Al Virob59fb6f2013-03-31 02:59:55 -04003235 seq_printf(m,
3236 "\nLinux Driver Configuration and Information for AdvanSys SCSI Host %d:\n",
3237 shost->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238
Al Virob59fb6f2013-03-31 02:59:55 -04003239 seq_printf(m,
Hannes Reinecke1abf6352014-06-25 15:27:38 +02003240 " host_busy %u, max_id %u, max_lun %llu, max_channel %u\n",
Christoph Hellwig74665012014-01-22 15:29:29 +01003241 atomic_read(&shost->host_busy), shost->max_id,
Al Virob59fb6f2013-03-31 02:59:55 -04003242 shost->max_lun, shost->max_channel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243
Al Virob59fb6f2013-03-31 02:59:55 -04003244 seq_printf(m,
3245 " unique_id %d, can_queue %d, this_id %d, sg_tablesize %u, cmd_per_lun %u\n",
3246 shost->unique_id, shost->can_queue, shost->this_id,
3247 shost->sg_tablesize, shost->cmd_per_lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248
Al Virob59fb6f2013-03-31 02:59:55 -04003249 seq_printf(m,
3250 " unchecked_isa_dma %d, use_clustering %d\n",
3251 shost->unchecked_isa_dma, shost->use_clustering);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252
Al Virob59fb6f2013-03-31 02:59:55 -04003253 seq_printf(m,
Al Viro31491e12013-03-31 03:04:13 -04003254 " flags 0x%x, last_reset 0x%lx, jiffies 0x%lx, asc_n_io_port 0x%x\n",
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02003255 boardp->flags, shost->last_reset, jiffies,
Al Virob59fb6f2013-03-31 02:59:55 -04003256 boardp->asc_n_io_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257
Al Viro31491e12013-03-31 03:04:13 -04003258 seq_printf(m, " io_port 0x%lx\n", shost->io_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003260 if (ASC_NARROW_BOARD(boardp)) {
3261 chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
3262 } else {
3263 chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
3264 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265}
3266
3267/*
3268 * asc_prt_asc_board_info()
3269 *
3270 * Print dynamic board configuration information.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271 */
Al Virob59fb6f2013-03-31 02:59:55 -04003272static void asc_prt_asc_board_info(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04003274 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003275 int chip_scsi_id;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003276 ASC_DVC_VAR *v;
3277 ASC_DVC_CFG *c;
3278 int i;
3279 int renegotiate = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003281 v = &boardp->dvc_var.asc_dvc_var;
3282 c = &boardp->dvc_cfg.asc_dvc_cfg;
3283 chip_scsi_id = c->chip_scsi_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284
Al Virob59fb6f2013-03-31 02:59:55 -04003285 seq_printf(m,
3286 "\nAsc Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
3287 shost->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288
Al Virob59fb6f2013-03-31 02:59:55 -04003289 seq_printf(m, " chip_version %u, mcode_date 0x%x, "
3290 "mcode_version 0x%x, err_code %u\n",
3291 c->chip_version, c->mcode_date, c->mcode_version,
3292 v->err_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003294 /* Current number of commands waiting for the host. */
Al Virob59fb6f2013-03-31 02:59:55 -04003295 seq_printf(m,
3296 " Total Command Pending: %d\n", v->cur_total_qng);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003298 seq_puts(m, " Command Queuing:");
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:%c",
3305 i,
3306 (v->use_tagged_qng & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003307 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003309 /* Current number of commands waiting for a device. */
Rasmus Villemoes3d300792014-12-03 00:10:53 +01003310 seq_puts(m, "\n Command Queue Pending:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003311 for (i = 0; i <= ASC_MAX_TID; i++) {
3312 if ((chip_scsi_id == i) ||
3313 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3314 continue;
3315 }
Al Virob59fb6f2013-03-31 02:59:55 -04003316 seq_printf(m, " %X:%u", i, v->cur_dvc_qng[i]);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003317 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003319 /* Current limit on number of commands that can be sent to a device. */
Rasmus Villemoes3d300792014-12-03 00:10:53 +01003320 seq_puts(m, "\n Command Queue Limit:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003321 for (i = 0; i <= ASC_MAX_TID; i++) {
3322 if ((chip_scsi_id == i) ||
3323 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3324 continue;
3325 }
Al Virob59fb6f2013-03-31 02:59:55 -04003326 seq_printf(m, " %X:%u", i, v->max_dvc_qng[i]);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003327 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003329 /* Indicate whether the device has returned queue full status. */
Rasmus Villemoes3d300792014-12-03 00:10:53 +01003330 seq_puts(m, "\n Command Queue Full:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003331 for (i = 0; i <= ASC_MAX_TID; i++) {
3332 if ((chip_scsi_id == i) ||
3333 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3334 continue;
3335 }
Al Virob59fb6f2013-03-31 02:59:55 -04003336 if (boardp->queue_full & ADV_TID_TO_TIDMASK(i))
3337 seq_printf(m, " %X:Y-%d",
3338 i, boardp->queue_full_cnt[i]);
3339 else
3340 seq_printf(m, " %X:N", i);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003341 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342
Rasmus Villemoes3d300792014-12-03 00:10:53 +01003343 seq_puts(m, "\n Synchronous Transfer:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003344 for (i = 0; i <= ASC_MAX_TID; i++) {
3345 if ((chip_scsi_id == i) ||
3346 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3347 continue;
3348 }
Al Virob59fb6f2013-03-31 02:59:55 -04003349 seq_printf(m, " %X:%c",
3350 i,
3351 (v->sdtr_done & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003352 }
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003353 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003355 for (i = 0; i <= ASC_MAX_TID; i++) {
3356 uchar syn_period_ix;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003358 if ((chip_scsi_id == i) ||
3359 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) ||
3360 ((v->init_sdtr & ADV_TID_TO_TIDMASK(i)) == 0)) {
3361 continue;
3362 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363
Al Virob59fb6f2013-03-31 02:59:55 -04003364 seq_printf(m, " %X:", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003366 if ((boardp->sdtr_data[i] & ASC_SYN_MAX_OFFSET) == 0) {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003367 seq_puts(m, " Asynchronous");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003368 } else {
3369 syn_period_ix =
3370 (boardp->sdtr_data[i] >> 4) & (v->max_sdtr_index -
3371 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372
Al Virob59fb6f2013-03-31 02:59:55 -04003373 seq_printf(m,
3374 " Transfer Period Factor: %d (%d.%d Mhz),",
3375 v->sdtr_period_tbl[syn_period_ix],
3376 250 / v->sdtr_period_tbl[syn_period_ix],
3377 ASC_TENTHS(250,
3378 v->sdtr_period_tbl[syn_period_ix]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379
Al Virob59fb6f2013-03-31 02:59:55 -04003380 seq_printf(m, " REQ/ACK Offset: %d",
3381 boardp->sdtr_data[i] & ASC_SYN_MAX_OFFSET);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003382 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003384 if ((v->sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003385 seq_puts(m, "*\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003386 renegotiate = 1;
3387 } else {
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003388 seq_putc(m, '\n');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003389 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003390 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003392 if (renegotiate) {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003393 seq_puts(m, " * = Re-negotiation pending before next command.\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003394 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395}
3396
3397/*
3398 * asc_prt_adv_board_info()
3399 *
3400 * Print dynamic board configuration information.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003401 */
Al Virob59fb6f2013-03-31 02:59:55 -04003402static void asc_prt_adv_board_info(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04003404 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003405 int i;
3406 ADV_DVC_VAR *v;
3407 ADV_DVC_CFG *c;
3408 AdvPortAddr iop_base;
3409 ushort chip_scsi_id;
3410 ushort lramword;
3411 uchar lrambyte;
3412 ushort tagqng_able;
3413 ushort sdtr_able, wdtr_able;
3414 ushort wdtr_done, sdtr_done;
3415 ushort period = 0;
3416 int renegotiate = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003418 v = &boardp->dvc_var.adv_dvc_var;
3419 c = &boardp->dvc_cfg.adv_dvc_cfg;
3420 iop_base = v->iop_base;
3421 chip_scsi_id = v->chip_scsi_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422
Al Virob59fb6f2013-03-31 02:59:55 -04003423 seq_printf(m,
3424 "\nAdv Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
3425 shost->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426
Al Virob59fb6f2013-03-31 02:59:55 -04003427 seq_printf(m,
3428 " iop_base 0x%lx, cable_detect: %X, err_code %u\n",
Al Viro31491e12013-03-31 03:04:13 -04003429 (unsigned long)v->iop_base,
Al Virob59fb6f2013-03-31 02:59:55 -04003430 AdvReadWordRegister(iop_base,IOPW_SCSI_CFG1) & CABLE_DETECT,
3431 v->err_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432
Al Virob59fb6f2013-03-31 02:59:55 -04003433 seq_printf(m, " chip_version %u, mcode_date 0x%x, "
3434 "mcode_version 0x%x\n", c->chip_version,
3435 c->mcode_date, c->mcode_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003437 AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003438 seq_puts(m, " Queuing Enabled:");
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
Al Virob59fb6f2013-03-31 02:59:55 -04003445 seq_printf(m, " %X:%c",
3446 i,
3447 (tagqng_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003448 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449
Rasmus Villemoes3d300792014-12-03 00:10:53 +01003450 seq_puts(m, "\n Queue Limit:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003451 for (i = 0; i <= ADV_MAX_TID; i++) {
3452 if ((chip_scsi_id == i) ||
3453 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3454 continue;
3455 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003457 AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + i,
3458 lrambyte);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459
Al Virob59fb6f2013-03-31 02:59:55 -04003460 seq_printf(m, " %X:%d", i, lrambyte);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003461 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462
Rasmus Villemoes3d300792014-12-03 00:10:53 +01003463 seq_puts(m, "\n Command Pending:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003464 for (i = 0; i <= ADV_MAX_TID; i++) {
3465 if ((chip_scsi_id == i) ||
3466 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3467 continue;
3468 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003470 AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_QUEUED_CMD + i,
3471 lrambyte);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472
Al Virob59fb6f2013-03-31 02:59:55 -04003473 seq_printf(m, " %X:%d", i, lrambyte);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003474 }
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003475 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003477 AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003478 seq_puts(m, " Wide Enabled:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003479 for (i = 0; i <= ADV_MAX_TID; i++) {
3480 if ((chip_scsi_id == i) ||
3481 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3482 continue;
3483 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484
Al Virob59fb6f2013-03-31 02:59:55 -04003485 seq_printf(m, " %X:%c",
3486 i,
3487 (wdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003488 }
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003489 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003491 AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, wdtr_done);
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003492 seq_puts(m, " Transfer Bit Width:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003493 for (i = 0; i <= ADV_MAX_TID; i++) {
3494 if ((chip_scsi_id == i) ||
3495 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3496 continue;
3497 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003499 AdvReadWordLram(iop_base,
3500 ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i),
3501 lramword);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003502
Al Virob59fb6f2013-03-31 02:59:55 -04003503 seq_printf(m, " %X:%d",
3504 i, (lramword & 0x8000) ? 16 : 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003506 if ((wdtr_able & ADV_TID_TO_TIDMASK(i)) &&
3507 (wdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003508 seq_putc(m, '*');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003509 renegotiate = 1;
3510 }
3511 }
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003512 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003514 AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003515 seq_puts(m, " Synchronous Enabled:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003516 for (i = 0; i <= ADV_MAX_TID; i++) {
3517 if ((chip_scsi_id == i) ||
3518 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3519 continue;
3520 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521
Al Virob59fb6f2013-03-31 02:59:55 -04003522 seq_printf(m, " %X:%c",
3523 i,
3524 (sdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003525 }
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003526 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003528 AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, sdtr_done);
3529 for (i = 0; i <= ADV_MAX_TID; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003531 AdvReadWordLram(iop_base,
3532 ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i),
3533 lramword);
3534 lramword &= ~0x8000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003536 if ((chip_scsi_id == i) ||
3537 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) ||
3538 ((sdtr_able & ADV_TID_TO_TIDMASK(i)) == 0)) {
3539 continue;
3540 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541
Al Virob59fb6f2013-03-31 02:59:55 -04003542 seq_printf(m, " %X:", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003543
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003544 if ((lramword & 0x1F) == 0) { /* Check for REQ/ACK Offset 0. */
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003545 seq_puts(m, " Asynchronous");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003546 } else {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003547 seq_puts(m, " Transfer Period Factor: ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003549 if ((lramword & 0x1F00) == 0x1100) { /* 80 Mhz */
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003550 seq_puts(m, "9 (80.0 Mhz),");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003551 } else if ((lramword & 0x1F00) == 0x1000) { /* 40 Mhz */
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003552 seq_puts(m, "10 (40.0 Mhz),");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003553 } else { /* 20 Mhz or below. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003555 period = (((lramword >> 8) * 25) + 50) / 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003557 if (period == 0) { /* Should never happen. */
Al Viro31491e12013-03-31 03:04:13 -04003558 seq_printf(m, "%d (? Mhz), ", period);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003559 } else {
Al Virob59fb6f2013-03-31 02:59:55 -04003560 seq_printf(m,
3561 "%d (%d.%d Mhz),",
3562 period, 250 / period,
3563 ASC_TENTHS(250, period));
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003564 }
3565 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566
Al Virob59fb6f2013-03-31 02:59:55 -04003567 seq_printf(m, " REQ/ACK Offset: %d",
3568 lramword & 0x1F);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003569 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003570
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003571 if ((sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003572 seq_puts(m, "*\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003573 renegotiate = 1;
3574 } else {
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003575 seq_putc(m, '\n');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003576 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003577 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003579 if (renegotiate) {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003580 seq_puts(m, " * = Re-negotiation pending before next command.\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003581 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003582}
3583
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584#ifdef ADVANSYS_STATS
Linus Torvalds1da177e2005-04-16 15:20:36 -07003585/*
3586 * asc_prt_board_stats()
Linus Torvalds1da177e2005-04-16 15:20:36 -07003587 */
Al Virob59fb6f2013-03-31 02:59:55 -04003588static void asc_prt_board_stats(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003589{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04003590 struct asc_board *boardp = shost_priv(shost);
3591 struct asc_stats *s = &boardp->asc_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592
Al Virob59fb6f2013-03-31 02:59:55 -04003593 seq_printf(m,
3594 "\nLinux Driver Statistics for AdvanSys SCSI Host %d:\n",
3595 shost->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003596
Al Virob59fb6f2013-03-31 02:59:55 -04003597 seq_printf(m,
Al Viro31491e12013-03-31 03:04:13 -04003598 " queuecommand %u, reset %u, biosparam %u, interrupt %u\n",
Al Virob59fb6f2013-03-31 02:59:55 -04003599 s->queuecommand, s->reset, s->biosparam,
3600 s->interrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601
Al Virob59fb6f2013-03-31 02:59:55 -04003602 seq_printf(m,
Al Viro31491e12013-03-31 03:04:13 -04003603 " callback %u, done %u, build_error %u, build_noreq %u, build_nosg %u\n",
Al Virob59fb6f2013-03-31 02:59:55 -04003604 s->callback, s->done, s->build_error,
3605 s->adv_build_noreq, s->adv_build_nosg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606
Al Virob59fb6f2013-03-31 02:59:55 -04003607 seq_printf(m,
Al Viro31491e12013-03-31 03:04:13 -04003608 " exe_noerror %u, exe_busy %u, exe_error %u, exe_unknown %u\n",
Al Virob59fb6f2013-03-31 02:59:55 -04003609 s->exe_noerror, s->exe_busy, s->exe_error,
3610 s->exe_unknown);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003611
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003612 /*
3613 * Display data transfer statistics.
3614 */
Matthew Wilcox52c334e2007-10-02 21:55:39 -04003615 if (s->xfer_cnt > 0) {
Al Viro31491e12013-03-31 03:04:13 -04003616 seq_printf(m, " xfer_cnt %u, xfer_elem %u, ",
Al Virob59fb6f2013-03-31 02:59:55 -04003617 s->xfer_cnt, s->xfer_elem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003618
Al Viro31491e12013-03-31 03:04:13 -04003619 seq_printf(m, "xfer_bytes %u.%01u kb\n",
Al Virob59fb6f2013-03-31 02:59:55 -04003620 s->xfer_sect / 2, ASC_TENTHS(s->xfer_sect, 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003622 /* Scatter gather transfer statistics */
Al Viro31491e12013-03-31 03:04:13 -04003623 seq_printf(m, " avg_num_elem %u.%01u, ",
Al Virob59fb6f2013-03-31 02:59:55 -04003624 s->xfer_elem / s->xfer_cnt,
3625 ASC_TENTHS(s->xfer_elem, s->xfer_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626
Al Viro31491e12013-03-31 03:04:13 -04003627 seq_printf(m, "avg_elem_size %u.%01u kb, ",
Al Virob59fb6f2013-03-31 02:59:55 -04003628 (s->xfer_sect / 2) / s->xfer_elem,
3629 ASC_TENTHS((s->xfer_sect / 2), s->xfer_elem));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630
Al Viro31491e12013-03-31 03:04:13 -04003631 seq_printf(m, "avg_xfer_size %u.%01u kb\n",
Al Virob59fb6f2013-03-31 02:59:55 -04003632 (s->xfer_sect / 2) / s->xfer_cnt,
3633 ASC_TENTHS((s->xfer_sect / 2), s->xfer_cnt));
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003634 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003636#endif /* ADVANSYS_STATS */
3637
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638/*
Al Virob59fb6f2013-03-31 02:59:55 -04003639 * advansys_show_info() - /proc/scsi/advansys/{0,1,2,3,...}
Matthew Wilcox51219352007-10-02 21:55:22 -04003640 *
Al Virob59fb6f2013-03-31 02:59:55 -04003641 * m: seq_file to print into
3642 * shost: Scsi_Host
Matthew Wilcox51219352007-10-02 21:55:22 -04003643 *
3644 * Return the number of bytes read from or written to a
3645 * /proc/scsi/advansys/[0...] file.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646 */
Matthew Wilcox51219352007-10-02 21:55:22 -04003647static int
Al Virob59fb6f2013-03-31 02:59:55 -04003648advansys_show_info(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003649{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04003650 struct asc_board *boardp = shost_priv(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003651
Matthew Wilcoxb352f922007-10-02 21:55:33 -04003652 ASC_DBG(1, "begin\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003653
Matthew Wilcox51219352007-10-02 21:55:22 -04003654 /*
Matthew Wilcox51219352007-10-02 21:55:22 -04003655 * User read of /proc/scsi/advansys/[0...] file.
3656 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657
Matthew Wilcox51219352007-10-02 21:55:22 -04003658 /*
3659 * Get board configuration information.
3660 *
3661 * advansys_info() returns the board string from its own static buffer.
3662 */
Matthew Wilcox51219352007-10-02 21:55:22 -04003663 /* Copy board information. */
Al Virob59fb6f2013-03-31 02:59:55 -04003664 seq_printf(m, "%s\n", (char *)advansys_info(shost));
Matthew Wilcox51219352007-10-02 21:55:22 -04003665 /*
3666 * Display Wide Board BIOS Information.
3667 */
Al Virob59fb6f2013-03-31 02:59:55 -04003668 if (!ASC_NARROW_BOARD(boardp))
3669 asc_prt_adv_bios(m, shost);
Matthew Wilcox51219352007-10-02 21:55:22 -04003670
3671 /*
3672 * Display driver information for each device attached to the board.
3673 */
Al Virob59fb6f2013-03-31 02:59:55 -04003674 asc_prt_board_devices(m, shost);
Matthew Wilcox51219352007-10-02 21:55:22 -04003675
3676 /*
3677 * Display EEPROM configuration for the board.
3678 */
Al Virob59fb6f2013-03-31 02:59:55 -04003679 if (ASC_NARROW_BOARD(boardp))
3680 asc_prt_asc_board_eeprom(m, shost);
3681 else
3682 asc_prt_adv_board_eeprom(m, shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683
Matthew Wilcox51219352007-10-02 21:55:22 -04003684 /*
3685 * Display driver configuration and information for the board.
3686 */
Al Virob59fb6f2013-03-31 02:59:55 -04003687 asc_prt_driver_conf(m, shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688
Matthew Wilcox51219352007-10-02 21:55:22 -04003689#ifdef ADVANSYS_STATS
3690 /*
3691 * Display driver statistics for the board.
3692 */
Al Virob59fb6f2013-03-31 02:59:55 -04003693 asc_prt_board_stats(m, shost);
Matthew Wilcox51219352007-10-02 21:55:22 -04003694#endif /* ADVANSYS_STATS */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695
Matthew Wilcox51219352007-10-02 21:55:22 -04003696 /*
3697 * Display Asc Library dynamic configuration information
3698 * for the board.
3699 */
Al Virob59fb6f2013-03-31 02:59:55 -04003700 if (ASC_NARROW_BOARD(boardp))
3701 asc_prt_asc_board_info(m, shost);
3702 else
3703 asc_prt_adv_board_info(m, shost);
3704 return 0;
Matthew Wilcox51219352007-10-02 21:55:22 -04003705}
3706#endif /* CONFIG_PROC_FS */
3707
3708static void asc_scsi_done(struct scsi_cmnd *scp)
3709{
Matthew Wilcox52c334e2007-10-02 21:55:39 -04003710 scsi_dma_unmap(scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04003711 ASC_STATS(scp->device->host, done);
Matthew Wilcox51219352007-10-02 21:55:22 -04003712 scp->scsi_done(scp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713}
3714
Matthew Wilcox51219352007-10-02 21:55:22 -04003715static void AscSetBank(PortAddr iop_base, uchar bank)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716{
Matthew Wilcox51219352007-10-02 21:55:22 -04003717 uchar val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003718
Matthew Wilcox51219352007-10-02 21:55:22 -04003719 val = AscGetChipControl(iop_base) &
3720 (~
3721 (CC_SINGLE_STEP | CC_TEST | CC_DIAG | CC_SCSI_RESET |
3722 CC_CHIP_RESET));
3723 if (bank == 1) {
3724 val |= CC_BANK_ONE;
3725 } else if (bank == 2) {
3726 val |= CC_DIAG | CC_BANK_ONE;
3727 } else {
3728 val &= ~CC_BANK_ONE;
3729 }
3730 AscSetChipControl(iop_base, val);
Matthew Wilcox51219352007-10-02 21:55:22 -04003731}
3732
3733static void AscSetChipIH(PortAddr iop_base, ushort ins_code)
3734{
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003735 AscSetBank(iop_base, 1);
Matthew Wilcox51219352007-10-02 21:55:22 -04003736 AscWriteChipIH(iop_base, ins_code);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003737 AscSetBank(iop_base, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738}
3739
Matthew Wilcox51219352007-10-02 21:55:22 -04003740static int AscStartChip(PortAddr iop_base)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741{
Matthew Wilcox51219352007-10-02 21:55:22 -04003742 AscSetChipControl(iop_base, 0);
3743 if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) {
3744 return (0);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003745 }
Matthew Wilcox51219352007-10-02 21:55:22 -04003746 return (1);
3747}
3748
Hannes Reineckeae267592015-04-24 13:18:28 +02003749static bool AscStopChip(PortAddr iop_base)
Matthew Wilcox51219352007-10-02 21:55:22 -04003750{
3751 uchar cc_val;
3752
3753 cc_val =
3754 AscGetChipControl(iop_base) &
3755 (~(CC_SINGLE_STEP | CC_TEST | CC_DIAG));
3756 AscSetChipControl(iop_base, (uchar)(cc_val | CC_HALT));
3757 AscSetChipIH(iop_base, INS_HALT);
3758 AscSetChipIH(iop_base, INS_RFLAG_WTM);
3759 if ((AscGetChipStatus(iop_base) & CSW_HALTED) == 0) {
Hannes Reineckeae267592015-04-24 13:18:28 +02003760 return false;
Matthew Wilcox51219352007-10-02 21:55:22 -04003761 }
Hannes Reineckeae267592015-04-24 13:18:28 +02003762 return true;
Matthew Wilcox51219352007-10-02 21:55:22 -04003763}
3764
Hannes Reinecked647c782015-04-24 13:18:26 +02003765static bool AscIsChipHalted(PortAddr iop_base)
Matthew Wilcox51219352007-10-02 21:55:22 -04003766{
3767 if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) {
3768 if ((AscGetChipControl(iop_base) & CC_HALT) != 0) {
Hannes Reinecked647c782015-04-24 13:18:26 +02003769 return true;
Matthew Wilcox51219352007-10-02 21:55:22 -04003770 }
3771 }
Hannes Reinecked647c782015-04-24 13:18:26 +02003772 return false;
Matthew Wilcox51219352007-10-02 21:55:22 -04003773}
3774
Hannes Reinecked647c782015-04-24 13:18:26 +02003775static bool AscResetChipAndScsiBus(ASC_DVC_VAR *asc_dvc)
Matthew Wilcox51219352007-10-02 21:55:22 -04003776{
3777 PortAddr iop_base;
3778 int i = 10;
3779
3780 iop_base = asc_dvc->iop_base;
3781 while ((AscGetChipStatus(iop_base) & CSW_SCSI_RESET_ACTIVE)
3782 && (i-- > 0)) {
3783 mdelay(100);
3784 }
3785 AscStopChip(iop_base);
3786 AscSetChipControl(iop_base, CC_CHIP_RESET | CC_SCSI_RESET | CC_HALT);
3787 udelay(60);
3788 AscSetChipIH(iop_base, INS_RFLAG_WTM);
3789 AscSetChipIH(iop_base, INS_HALT);
3790 AscSetChipControl(iop_base, CC_CHIP_RESET | CC_HALT);
3791 AscSetChipControl(iop_base, CC_HALT);
3792 mdelay(200);
3793 AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
3794 AscSetChipStatus(iop_base, 0);
3795 return (AscIsChipHalted(iop_base));
3796}
3797
3798static int AscFindSignature(PortAddr iop_base)
3799{
3800 ushort sig_word;
3801
Matthew Wilcoxb352f922007-10-02 21:55:33 -04003802 ASC_DBG(1, "AscGetChipSignatureByte(0x%x) 0x%x\n",
Matthew Wilcox51219352007-10-02 21:55:22 -04003803 iop_base, AscGetChipSignatureByte(iop_base));
3804 if (AscGetChipSignatureByte(iop_base) == (uchar)ASC_1000_ID1B) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04003805 ASC_DBG(1, "AscGetChipSignatureWord(0x%x) 0x%x\n",
Matthew Wilcox51219352007-10-02 21:55:22 -04003806 iop_base, AscGetChipSignatureWord(iop_base));
3807 sig_word = AscGetChipSignatureWord(iop_base);
3808 if ((sig_word == (ushort)ASC_1000_ID0W) ||
3809 (sig_word == (ushort)ASC_1000_ID0W_FIX)) {
3810 return (1);
3811 }
3812 }
3813 return (0);
3814}
3815
3816static void AscEnableInterrupt(PortAddr iop_base)
3817{
3818 ushort cfg;
3819
3820 cfg = AscGetChipCfgLsw(iop_base);
3821 AscSetChipCfgLsw(iop_base, cfg | ASC_CFG0_HOST_INT_ON);
Matthew Wilcox51219352007-10-02 21:55:22 -04003822}
3823
3824static void AscDisableInterrupt(PortAddr iop_base)
3825{
3826 ushort cfg;
3827
3828 cfg = AscGetChipCfgLsw(iop_base);
3829 AscSetChipCfgLsw(iop_base, cfg & (~ASC_CFG0_HOST_INT_ON));
Matthew Wilcox51219352007-10-02 21:55:22 -04003830}
3831
3832static uchar AscReadLramByte(PortAddr iop_base, ushort addr)
3833{
3834 unsigned char byte_data;
3835 unsigned short word_data;
3836
3837 if (isodd_word(addr)) {
3838 AscSetChipLramAddr(iop_base, addr - 1);
3839 word_data = AscGetChipLramData(iop_base);
3840 byte_data = (word_data >> 8) & 0xFF;
3841 } else {
3842 AscSetChipLramAddr(iop_base, addr);
3843 word_data = AscGetChipLramData(iop_base);
3844 byte_data = word_data & 0xFF;
3845 }
3846 return byte_data;
3847}
3848
3849static ushort AscReadLramWord(PortAddr iop_base, ushort addr)
3850{
3851 ushort word_data;
3852
3853 AscSetChipLramAddr(iop_base, addr);
3854 word_data = AscGetChipLramData(iop_base);
3855 return (word_data);
3856}
3857
3858#if CC_VERY_LONG_SG_LIST
Hannes Reinecke95cfab62015-04-24 13:18:27 +02003859static u32 AscReadLramDWord(PortAddr iop_base, ushort addr)
Matthew Wilcox51219352007-10-02 21:55:22 -04003860{
3861 ushort val_low, val_high;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02003862 u32 dword_data;
Matthew Wilcox51219352007-10-02 21:55:22 -04003863
3864 AscSetChipLramAddr(iop_base, addr);
3865 val_low = AscGetChipLramData(iop_base);
3866 val_high = AscGetChipLramData(iop_base);
Hannes Reinecke95cfab62015-04-24 13:18:27 +02003867 dword_data = ((u32) val_high << 16) | (u32) val_low;
Matthew Wilcox51219352007-10-02 21:55:22 -04003868 return (dword_data);
3869}
3870#endif /* CC_VERY_LONG_SG_LIST */
3871
3872static void
3873AscMemWordSetLram(PortAddr iop_base, ushort s_addr, ushort set_wval, int words)
3874{
3875 int i;
3876
3877 AscSetChipLramAddr(iop_base, s_addr);
3878 for (i = 0; i < words; i++) {
3879 AscSetChipLramData(iop_base, set_wval);
3880 }
3881}
3882
3883static void AscWriteLramWord(PortAddr iop_base, ushort addr, ushort word_val)
3884{
3885 AscSetChipLramAddr(iop_base, addr);
3886 AscSetChipLramData(iop_base, word_val);
Matthew Wilcox51219352007-10-02 21:55:22 -04003887}
3888
3889static void AscWriteLramByte(PortAddr iop_base, ushort addr, uchar byte_val)
3890{
3891 ushort word_data;
3892
3893 if (isodd_word(addr)) {
3894 addr--;
3895 word_data = AscReadLramWord(iop_base, addr);
3896 word_data &= 0x00FF;
3897 word_data |= (((ushort)byte_val << 8) & 0xFF00);
3898 } else {
3899 word_data = AscReadLramWord(iop_base, addr);
3900 word_data &= 0xFF00;
3901 word_data |= ((ushort)byte_val & 0x00FF);
3902 }
3903 AscWriteLramWord(iop_base, addr, word_data);
Matthew Wilcox51219352007-10-02 21:55:22 -04003904}
3905
3906/*
3907 * Copy 2 bytes to LRAM.
3908 *
3909 * The source data is assumed to be in little-endian order in memory
3910 * and is maintained in little-endian order when written to LRAM.
3911 */
3912static void
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05303913AscMemWordCopyPtrToLram(PortAddr iop_base, ushort s_addr,
3914 const uchar *s_buffer, int words)
Matthew Wilcox51219352007-10-02 21:55:22 -04003915{
3916 int i;
3917
3918 AscSetChipLramAddr(iop_base, s_addr);
3919 for (i = 0; i < 2 * words; i += 2) {
3920 /*
3921 * On a little-endian system the second argument below
3922 * produces a little-endian ushort which is written to
3923 * LRAM in little-endian order. On a big-endian system
3924 * the second argument produces a big-endian ushort which
3925 * is "transparently" byte-swapped by outpw() and written
3926 * in little-endian order to LRAM.
3927 */
3928 outpw(iop_base + IOP_RAM_DATA,
3929 ((ushort)s_buffer[i + 1] << 8) | s_buffer[i]);
3930 }
Matthew Wilcox51219352007-10-02 21:55:22 -04003931}
3932
3933/*
3934 * Copy 4 bytes to LRAM.
3935 *
3936 * The source data is assumed to be in little-endian order in memory
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003937 * and is maintained in little-endian order when written to LRAM.
Matthew Wilcox51219352007-10-02 21:55:22 -04003938 */
3939static void
3940AscMemDWordCopyPtrToLram(PortAddr iop_base,
3941 ushort s_addr, uchar *s_buffer, int dwords)
3942{
3943 int i;
3944
3945 AscSetChipLramAddr(iop_base, s_addr);
3946 for (i = 0; i < 4 * dwords; i += 4) {
3947 outpw(iop_base + IOP_RAM_DATA, ((ushort)s_buffer[i + 1] << 8) | s_buffer[i]); /* LSW */
3948 outpw(iop_base + IOP_RAM_DATA, ((ushort)s_buffer[i + 3] << 8) | s_buffer[i + 2]); /* MSW */
3949 }
Matthew Wilcox51219352007-10-02 21:55:22 -04003950}
3951
3952/*
3953 * Copy 2 bytes from LRAM.
3954 *
3955 * The source data is assumed to be in little-endian order in LRAM
3956 * and is maintained in little-endian order when written to memory.
3957 */
3958static void
3959AscMemWordCopyPtrFromLram(PortAddr iop_base,
3960 ushort s_addr, uchar *d_buffer, int words)
3961{
3962 int i;
3963 ushort word;
3964
3965 AscSetChipLramAddr(iop_base, s_addr);
3966 for (i = 0; i < 2 * words; i += 2) {
3967 word = inpw(iop_base + IOP_RAM_DATA);
3968 d_buffer[i] = word & 0xff;
3969 d_buffer[i + 1] = (word >> 8) & 0xff;
3970 }
Matthew Wilcox51219352007-10-02 21:55:22 -04003971}
3972
Hannes Reinecke95cfab62015-04-24 13:18:27 +02003973static u32 AscMemSumLramWord(PortAddr iop_base, ushort s_addr, int words)
Matthew Wilcox51219352007-10-02 21:55:22 -04003974{
Hannes Reinecke95cfab62015-04-24 13:18:27 +02003975 u32 sum = 0;
Matthew Wilcox51219352007-10-02 21:55:22 -04003976 int i;
3977
Matthew Wilcox51219352007-10-02 21:55:22 -04003978 for (i = 0; i < words; i++, s_addr += 2) {
3979 sum += AscReadLramWord(iop_base, s_addr);
3980 }
3981 return (sum);
3982}
3983
3984static ushort AscInitLram(ASC_DVC_VAR *asc_dvc)
3985{
3986 uchar i;
3987 ushort s_addr;
3988 PortAddr iop_base;
3989 ushort warn_code;
3990
3991 iop_base = asc_dvc->iop_base;
3992 warn_code = 0;
3993 AscMemWordSetLram(iop_base, ASC_QADR_BEG, 0,
3994 (ushort)(((int)(asc_dvc->max_total_qng + 2 + 1) *
3995 64) >> 1));
3996 i = ASC_MIN_ACTIVE_QNO;
3997 s_addr = ASC_QADR_BEG + ASC_QBLK_SIZE;
3998 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
3999 (uchar)(i + 1));
4000 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
4001 (uchar)(asc_dvc->max_total_qng));
4002 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
4003 (uchar)i);
4004 i++;
4005 s_addr += ASC_QBLK_SIZE;
4006 for (; i < asc_dvc->max_total_qng; i++, s_addr += ASC_QBLK_SIZE) {
4007 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
4008 (uchar)(i + 1));
4009 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
4010 (uchar)(i - 1));
4011 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
4012 (uchar)i);
4013 }
4014 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
4015 (uchar)ASC_QLINK_END);
4016 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
4017 (uchar)(asc_dvc->max_total_qng - 1));
4018 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
4019 (uchar)asc_dvc->max_total_qng);
4020 i++;
4021 s_addr += ASC_QBLK_SIZE;
4022 for (; i <= (uchar)(asc_dvc->max_total_qng + 3);
4023 i++, s_addr += ASC_QBLK_SIZE) {
4024 AscWriteLramByte(iop_base,
4025 (ushort)(s_addr + (ushort)ASC_SCSIQ_B_FWD), i);
4026 AscWriteLramByte(iop_base,
4027 (ushort)(s_addr + (ushort)ASC_SCSIQ_B_BWD), i);
4028 AscWriteLramByte(iop_base,
4029 (ushort)(s_addr + (ushort)ASC_SCSIQ_B_QNO), i);
4030 }
4031 return warn_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004032}
4033
Hannes Reinecke95cfab62015-04-24 13:18:27 +02004034static u32
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304035AscLoadMicroCode(PortAddr iop_base, ushort s_addr,
4036 const uchar *mcode_buf, ushort mcode_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037{
Hannes Reinecke95cfab62015-04-24 13:18:27 +02004038 u32 chksum;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004039 ushort mcode_word_size;
4040 ushort mcode_chksum;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004041
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004042 /* Write the microcode buffer starting at LRAM address 0. */
4043 mcode_word_size = (ushort)(mcode_size >> 1);
4044 AscMemWordSetLram(iop_base, s_addr, 0, mcode_word_size);
4045 AscMemWordCopyPtrToLram(iop_base, s_addr, mcode_buf, mcode_word_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004047 chksum = AscMemSumLramWord(iop_base, s_addr, mcode_word_size);
Matthew Wilcoxb352f922007-10-02 21:55:33 -04004048 ASC_DBG(1, "chksum 0x%lx\n", (ulong)chksum);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004049 mcode_chksum = (ushort)AscMemSumLramWord(iop_base,
4050 (ushort)ASC_CODE_SEC_BEG,
4051 (ushort)((mcode_size -
4052 s_addr - (ushort)
4053 ASC_CODE_SEC_BEG) /
4054 2));
Matthew Wilcoxb352f922007-10-02 21:55:33 -04004055 ASC_DBG(1, "mcode_chksum 0x%lx\n", (ulong)mcode_chksum);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004056 AscWriteLramWord(iop_base, ASCV_MCODE_CHKSUM_W, mcode_chksum);
4057 AscWriteLramWord(iop_base, ASCV_MCODE_SIZE_W, mcode_size);
Matthew Wilcoxb352f922007-10-02 21:55:33 -04004058 return chksum;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004059}
4060
Matthew Wilcox51219352007-10-02 21:55:22 -04004061static void AscInitQLinkVar(ASC_DVC_VAR *asc_dvc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062{
Matthew Wilcox51219352007-10-02 21:55:22 -04004063 PortAddr iop_base;
4064 int i;
4065 ushort lram_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066
Matthew Wilcox51219352007-10-02 21:55:22 -04004067 iop_base = asc_dvc->iop_base;
4068 AscPutRiscVarFreeQHead(iop_base, 1);
4069 AscPutRiscVarDoneQTail(iop_base, asc_dvc->max_total_qng);
4070 AscPutVarFreeQHead(iop_base, 1);
4071 AscPutVarDoneQTail(iop_base, asc_dvc->max_total_qng);
4072 AscWriteLramByte(iop_base, ASCV_BUSY_QHEAD_B,
4073 (uchar)((int)asc_dvc->max_total_qng + 1));
4074 AscWriteLramByte(iop_base, ASCV_DISC1_QHEAD_B,
4075 (uchar)((int)asc_dvc->max_total_qng + 2));
4076 AscWriteLramByte(iop_base, (ushort)ASCV_TOTAL_READY_Q_B,
4077 asc_dvc->max_total_qng);
4078 AscWriteLramWord(iop_base, ASCV_ASCDVC_ERR_CODE_W, 0);
4079 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
4080 AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, 0);
4081 AscWriteLramByte(iop_base, ASCV_SCSIBUSY_B, 0);
4082 AscWriteLramByte(iop_base, ASCV_WTM_FLAG_B, 0);
4083 AscPutQDoneInProgress(iop_base, 0);
4084 lram_addr = ASC_QADR_BEG;
4085 for (i = 0; i < 32; i++, lram_addr += 2) {
4086 AscWriteLramWord(iop_base, lram_addr, 0);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004087 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004088}
4089
Matthew Wilcox51219352007-10-02 21:55:22 -04004090static ushort AscInitMicroCodeVar(ASC_DVC_VAR *asc_dvc)
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004091{
Matthew Wilcox51219352007-10-02 21:55:22 -04004092 int i;
4093 ushort warn_code;
4094 PortAddr iop_base;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02004095 __le32 phy_addr;
4096 __le32 phy_size;
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -04004097 struct asc_board *board = asc_dvc_to_board(asc_dvc);
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004098
Matthew Wilcox51219352007-10-02 21:55:22 -04004099 iop_base = asc_dvc->iop_base;
4100 warn_code = 0;
4101 for (i = 0; i <= ASC_MAX_TID; i++) {
4102 AscPutMCodeInitSDTRAtID(iop_base, i,
4103 asc_dvc->cfg->sdtr_period_offset[i]);
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004104 }
4105
Matthew Wilcox51219352007-10-02 21:55:22 -04004106 AscInitQLinkVar(asc_dvc);
4107 AscWriteLramByte(iop_base, ASCV_DISC_ENABLE_B,
4108 asc_dvc->cfg->disc_enable);
4109 AscWriteLramByte(iop_base, ASCV_HOSTSCSI_ID_B,
4110 ASC_TID_TO_TARGET_ID(asc_dvc->cfg->chip_scsi_id));
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004111
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -04004112 /* Ensure overrun buffer is aligned on an 8 byte boundary. */
4113 BUG_ON((unsigned long)asc_dvc->overrun_buf & 7);
4114 asc_dvc->overrun_dma = dma_map_single(board->dev, asc_dvc->overrun_buf,
4115 ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -03004116 if (dma_mapping_error(board->dev, asc_dvc->overrun_dma)) {
4117 warn_code = -ENOMEM;
4118 goto err_dma_map;
4119 }
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -04004120 phy_addr = cpu_to_le32(asc_dvc->overrun_dma);
Matthew Wilcox51219352007-10-02 21:55:22 -04004121 AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_PADDR_D,
4122 (uchar *)&phy_addr, 1);
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -04004123 phy_size = cpu_to_le32(ASC_OVERRUN_BSIZE);
Matthew Wilcox51219352007-10-02 21:55:22 -04004124 AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_BSIZE_D,
4125 (uchar *)&phy_size, 1);
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004126
Matthew Wilcox51219352007-10-02 21:55:22 -04004127 asc_dvc->cfg->mcode_date =
4128 AscReadLramWord(iop_base, (ushort)ASCV_MC_DATE_W);
4129 asc_dvc->cfg->mcode_version =
4130 AscReadLramWord(iop_base, (ushort)ASCV_MC_VER_W);
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004131
Matthew Wilcox51219352007-10-02 21:55:22 -04004132 AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
4133 if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
4134 asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -03004135 warn_code = UW_ERR;
4136 goto err_mcode_start;
Matthew Wilcox51219352007-10-02 21:55:22 -04004137 }
4138 if (AscStartChip(iop_base) != 1) {
4139 asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -03004140 warn_code = UW_ERR;
4141 goto err_mcode_start;
Matthew Wilcox51219352007-10-02 21:55:22 -04004142 }
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004143
Matthew Wilcox51219352007-10-02 21:55:22 -04004144 return warn_code;
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -03004145
4146err_mcode_start:
4147 dma_unmap_single(board->dev, asc_dvc->overrun_dma,
4148 ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
4149err_dma_map:
4150 asc_dvc->overrun_dma = 0;
4151 return warn_code;
Matthew Wilcox51219352007-10-02 21:55:22 -04004152}
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004153
Matthew Wilcox51219352007-10-02 21:55:22 -04004154static ushort AscInitAsc1000Driver(ASC_DVC_VAR *asc_dvc)
4155{
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304156 const struct firmware *fw;
4157 const char fwname[] = "advansys/mcode.bin";
4158 int err;
4159 unsigned long chksum;
Matthew Wilcox51219352007-10-02 21:55:22 -04004160 ushort warn_code;
4161 PortAddr iop_base;
4162
4163 iop_base = asc_dvc->iop_base;
4164 warn_code = 0;
4165 if ((asc_dvc->dvc_cntl & ASC_CNTL_RESET_SCSI) &&
4166 !(asc_dvc->init_state & ASC_INIT_RESET_SCSI_DONE)) {
4167 AscResetChipAndScsiBus(asc_dvc);
4168 mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
4169 }
4170 asc_dvc->init_state |= ASC_INIT_STATE_BEG_LOAD_MC;
4171 if (asc_dvc->err_code != 0)
4172 return UW_ERR;
4173 if (!AscFindSignature(asc_dvc->iop_base)) {
4174 asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
4175 return warn_code;
4176 }
4177 AscDisableInterrupt(iop_base);
4178 warn_code |= AscInitLram(asc_dvc);
4179 if (asc_dvc->err_code != 0)
4180 return UW_ERR;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304181
4182 err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
4183 if (err) {
4184 printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
4185 fwname, err);
Herton Ronaldo Krzesinskicf747442010-03-19 19:37:26 -03004186 asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304187 return err;
4188 }
4189 if (fw->size < 4) {
4190 printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
4191 fw->size, fwname);
4192 release_firmware(fw);
Herton Ronaldo Krzesinskicf747442010-03-19 19:37:26 -03004193 asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304194 return -EINVAL;
4195 }
4196 chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
4197 (fw->data[1] << 8) | fw->data[0];
4198 ASC_DBG(1, "_asc_mcode_chksum 0x%lx\n", (ulong)chksum);
4199 if (AscLoadMicroCode(iop_base, 0, &fw->data[4],
4200 fw->size - 4) != chksum) {
Matthew Wilcox51219352007-10-02 21:55:22 -04004201 asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304202 release_firmware(fw);
Matthew Wilcox51219352007-10-02 21:55:22 -04004203 return warn_code;
4204 }
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304205 release_firmware(fw);
Matthew Wilcox51219352007-10-02 21:55:22 -04004206 warn_code |= AscInitMicroCodeVar(asc_dvc);
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -03004207 if (!asc_dvc->overrun_dma)
4208 return warn_code;
Matthew Wilcox51219352007-10-02 21:55:22 -04004209 asc_dvc->init_state |= ASC_INIT_STATE_END_LOAD_MC;
4210 AscEnableInterrupt(iop_base);
4211 return warn_code;
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004212}
4213
Linus Torvalds1da177e2005-04-16 15:20:36 -07004214/*
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004215 * Load the Microcode
4216 *
4217 * Write the microcode image to RISC memory starting at address 0.
4218 *
4219 * The microcode is stored compressed in the following format:
4220 *
4221 * 254 word (508 byte) table indexed by byte code followed
4222 * by the following byte codes:
4223 *
4224 * 1-Byte Code:
4225 * 00: Emit word 0 in table.
4226 * 01: Emit word 1 in table.
4227 * .
4228 * FD: Emit word 253 in table.
4229 *
4230 * Multi-Byte Code:
4231 * FE WW WW: (3 byte code) Word to emit is the next word WW WW.
4232 * FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
4233 *
4234 * Returns 0 or an error if the checksum doesn't match
4235 */
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304236static int AdvLoadMicrocode(AdvPortAddr iop_base, const unsigned char *buf,
4237 int size, int memsize, int chksum)
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004238{
4239 int i, j, end, len = 0;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02004240 u32 sum;
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004241
4242 AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
4243
4244 for (i = 253 * 2; i < size; i++) {
4245 if (buf[i] == 0xff) {
4246 unsigned short word = (buf[i + 3] << 8) | buf[i + 2];
4247 for (j = 0; j < buf[i + 1]; j++) {
4248 AdvWriteWordAutoIncLram(iop_base, word);
4249 len += 2;
4250 }
4251 i += 3;
4252 } else if (buf[i] == 0xfe) {
4253 unsigned short word = (buf[i + 2] << 8) | buf[i + 1];
4254 AdvWriteWordAutoIncLram(iop_base, word);
4255 i += 2;
4256 len += 2;
4257 } else {
Matthew Wilcox951b62c2007-10-05 15:57:06 -04004258 unsigned int off = buf[i] * 2;
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004259 unsigned short word = (buf[off + 1] << 8) | buf[off];
4260 AdvWriteWordAutoIncLram(iop_base, word);
4261 len += 2;
4262 }
4263 }
4264
4265 end = len;
4266
4267 while (len < memsize) {
4268 AdvWriteWordAutoIncLram(iop_base, 0);
4269 len += 2;
4270 }
4271
4272 /* Verify the microcode checksum. */
4273 sum = 0;
4274 AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
4275
4276 for (len = 0; len < end; len += 2) {
4277 sum += AdvReadWordAutoIncLram(iop_base);
4278 }
4279
4280 if (sum != chksum)
4281 return ASC_IERR_MCODE_CHKSUM;
4282
4283 return 0;
4284}
4285
Hannes Reinecke98b96a72015-04-24 13:18:23 +02004286static void AdvBuildCarrierFreelist(struct adv_dvc_var *adv_dvc)
Matthew Wilcox51219352007-10-02 21:55:22 -04004287{
Hannes Reinecke98b96a72015-04-24 13:18:23 +02004288 off_t carr_offset = 0, next_offset;
4289 dma_addr_t carr_paddr;
4290 int carr_num = ADV_CARRIER_BUFSIZE / sizeof(ADV_CARR_T), i;
Matthew Wilcox51219352007-10-02 21:55:22 -04004291
Hannes Reinecke98b96a72015-04-24 13:18:23 +02004292 for (i = 0; i < carr_num; i++) {
4293 carr_offset = i * sizeof(ADV_CARR_T);
4294 /* Get physical address of the carrier 'carrp'. */
4295 carr_paddr = adv_dvc->carrier_addr + carr_offset;
4296
4297 adv_dvc->carrier[i].carr_pa = cpu_to_le32(carr_paddr);
4298 adv_dvc->carrier[i].carr_va = cpu_to_le32(carr_offset);
4299 adv_dvc->carrier[i].areq_vpa = 0;
4300 next_offset = carr_offset + sizeof(ADV_CARR_T);
4301 if (i == carr_num)
4302 next_offset = ~0;
4303 adv_dvc->carrier[i].next_vpa = cpu_to_le32(next_offset);
4304 }
4305 /*
4306 * We cannot have a carrier with 'carr_va' of '0', as
4307 * a reference to this carrier would be interpreted as
4308 * list termination.
4309 * So start at carrier 1 with the freelist.
4310 */
4311 adv_dvc->carr_freelist = &adv_dvc->carrier[1];
4312}
4313
4314static ADV_CARR_T *adv_get_carrier(struct adv_dvc_var *adv_dvc, u32 offset)
4315{
4316 int index;
4317
4318 BUG_ON(offset > ADV_CARRIER_BUFSIZE);
4319
4320 index = offset / sizeof(ADV_CARR_T);
4321 return &adv_dvc->carrier[index];
4322}
4323
4324static ADV_CARR_T *adv_get_next_carrier(struct adv_dvc_var *adv_dvc)
4325{
4326 ADV_CARR_T *carrp = adv_dvc->carr_freelist;
4327 u32 next_vpa = le32_to_cpu(carrp->next_vpa);
4328
4329 if (next_vpa == 0 || next_vpa == ~0) {
4330 ASC_DBG(1, "invalid vpa offset 0x%x\n", next_vpa);
4331 return NULL;
Matthew Wilcox51219352007-10-02 21:55:22 -04004332 }
4333
Hannes Reinecke98b96a72015-04-24 13:18:23 +02004334 adv_dvc->carr_freelist = adv_get_carrier(adv_dvc, next_vpa);
4335 /*
4336 * insert stopper carrier to terminate list
4337 */
4338 carrp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
Matthew Wilcox51219352007-10-02 21:55:22 -04004339
Hannes Reinecke98b96a72015-04-24 13:18:23 +02004340 return carrp;
Matthew Wilcox51219352007-10-02 21:55:22 -04004341}
4342
4343/*
Hannes Reinecke4b47e462015-04-24 13:18:24 +02004344 * 'offset' is the index in the request pointer array
4345 */
4346static adv_req_t * adv_get_reqp(struct adv_dvc_var *adv_dvc, u32 offset)
4347{
4348 struct asc_board *boardp = adv_dvc->drv_ptr;
4349
4350 BUG_ON(offset > adv_dvc->max_host_qng);
4351 return &boardp->adv_reqp[offset];
4352}
4353
4354/*
Matthew Wilcox51219352007-10-02 21:55:22 -04004355 * Send an idle command to the chip and wait for completion.
4356 *
4357 * Command completion is polled for once per microsecond.
4358 *
4359 * The function can be called from anywhere including an interrupt handler.
4360 * But the function is not re-entrant, so it uses the DvcEnter/LeaveCritical()
4361 * functions to prevent reentrancy.
4362 *
4363 * Return Values:
4364 * ADV_TRUE - command completed successfully
4365 * ADV_FALSE - command failed
4366 * ADV_ERROR - command timed out
4367 */
4368static int
4369AdvSendIdleCmd(ADV_DVC_VAR *asc_dvc,
Hannes Reinecke95cfab62015-04-24 13:18:27 +02004370 ushort idle_cmd, u32 idle_cmd_parameter)
Matthew Wilcox51219352007-10-02 21:55:22 -04004371{
Hannes Reinecke95cfab62015-04-24 13:18:27 +02004372 int result, i, j;
Matthew Wilcox51219352007-10-02 21:55:22 -04004373 AdvPortAddr iop_base;
4374
4375 iop_base = asc_dvc->iop_base;
4376
4377 /*
4378 * Clear the idle command status which is set by the microcode
4379 * to a non-zero value to indicate when the command is completed.
4380 * The non-zero result is one of the IDLE_CMD_STATUS_* values
4381 */
4382 AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS, (ushort)0);
4383
4384 /*
4385 * Write the idle command value after the idle command parameter
4386 * has been written to avoid a race condition. If the order is not
4387 * followed, the microcode may process the idle command before the
4388 * parameters have been written to LRAM.
4389 */
4390 AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IDLE_CMD_PARAMETER,
4391 cpu_to_le32(idle_cmd_parameter));
4392 AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD, idle_cmd);
4393
4394 /*
4395 * Tickle the RISC to tell it to process the idle command.
4396 */
4397 AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_B);
4398 if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
4399 /*
4400 * Clear the tickle value. In the ASC-3550 the RISC flag
4401 * command 'clr_tickle_b' does not work unless the host
4402 * value is cleared.
4403 */
4404 AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_NOP);
4405 }
4406
4407 /* Wait for up to 100 millisecond for the idle command to timeout. */
4408 for (i = 0; i < SCSI_WAIT_100_MSEC; i++) {
4409 /* Poll once each microsecond for command completion. */
4410 for (j = 0; j < SCSI_US_PER_MSEC; j++) {
4411 AdvReadWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS,
4412 result);
4413 if (result != 0)
4414 return result;
4415 udelay(1);
4416 }
4417 }
4418
4419 BUG(); /* The idle command should never timeout. */
4420 return ADV_ERROR;
4421}
4422
4423/*
4424 * Reset SCSI Bus and purge all outstanding requests.
4425 *
4426 * Return Value:
4427 * ADV_TRUE(1) - All requests are purged and SCSI Bus is reset.
4428 * ADV_FALSE(0) - Microcode command failed.
4429 * ADV_ERROR(-1) - Microcode command timed-out. Microcode or IC
4430 * may be hung which requires driver recovery.
4431 */
4432static int AdvResetSB(ADV_DVC_VAR *asc_dvc)
4433{
4434 int status;
4435
4436 /*
4437 * Send the SCSI Bus Reset idle start idle command which asserts
4438 * the SCSI Bus Reset signal.
4439 */
4440 status = AdvSendIdleCmd(asc_dvc, (ushort)IDLE_CMD_SCSI_RESET_START, 0L);
4441 if (status != ADV_TRUE) {
4442 return status;
4443 }
4444
4445 /*
4446 * Delay for the specified SCSI Bus Reset hold time.
4447 *
4448 * The hold time delay is done on the host because the RISC has no
4449 * microsecond accurate timer.
4450 */
4451 udelay(ASC_SCSI_RESET_HOLD_TIME_US);
4452
4453 /*
4454 * Send the SCSI Bus Reset end idle command which de-asserts
4455 * the SCSI Bus Reset signal and purges any pending requests.
4456 */
4457 status = AdvSendIdleCmd(asc_dvc, (ushort)IDLE_CMD_SCSI_RESET_END, 0L);
4458 if (status != ADV_TRUE) {
4459 return status;
4460 }
4461
4462 mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
4463
4464 return status;
4465}
4466
4467/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468 * Initialize the ASC-3550.
4469 *
4470 * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
4471 *
4472 * For a non-fatal error return a warning code. If there are no warnings
4473 * then 0 is returned.
4474 *
4475 * Needed after initialization for error recovery.
4476 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004477static int AdvInitAsc3550Driver(ADV_DVC_VAR *asc_dvc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478{
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304479 const struct firmware *fw;
4480 const char fwname[] = "advansys/3550.bin";
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004481 AdvPortAddr iop_base;
4482 ushort warn_code;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004483 int begin_addr;
4484 int end_addr;
4485 ushort code_sum;
4486 int word;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004487 int i;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304488 int err;
4489 unsigned long chksum;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004490 ushort scsi_cfg1;
4491 uchar tid;
4492 ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
4493 ushort wdtr_able = 0, sdtr_able, tagqng_able;
4494 uchar max_cmd[ADV_MAX_TID + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004495
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004496 /* If there is already an error, don't continue. */
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004497 if (asc_dvc->err_code != 0)
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004498 return ADV_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004499
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004500 /*
4501 * The caller must set 'chip_type' to ADV_CHIP_ASC3550.
4502 */
4503 if (asc_dvc->chip_type != ADV_CHIP_ASC3550) {
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004504 asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004505 return ADV_ERROR;
4506 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004507
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004508 warn_code = 0;
4509 iop_base = asc_dvc->iop_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004510
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004511 /*
4512 * Save the RISC memory BIOS region before writing the microcode.
4513 * The BIOS may already be loaded and using its RISC LRAM region
4514 * so its region must be saved and restored.
4515 *
4516 * Note: This code makes the assumption, which is currently true,
4517 * that a chip reset does not clear RISC LRAM.
4518 */
4519 for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
4520 AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
4521 bios_mem[i]);
4522 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004523
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004524 /*
4525 * Save current per TID negotiated values.
4526 */
4527 if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] == 0x55AA) {
4528 ushort bios_version, major, minor;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004529
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004530 bios_version =
4531 bios_mem[(ASC_MC_BIOS_VERSION - ASC_MC_BIOSMEM) / 2];
4532 major = (bios_version >> 12) & 0xF;
4533 minor = (bios_version >> 8) & 0xF;
4534 if (major < 3 || (major == 3 && minor == 1)) {
4535 /* BIOS 3.1 and earlier location of 'wdtr_able' variable. */
4536 AdvReadWordLram(iop_base, 0x120, wdtr_able);
4537 } else {
4538 AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
4539 }
4540 }
4541 AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
4542 AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
4543 for (tid = 0; tid <= ADV_MAX_TID; tid++) {
4544 AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
4545 max_cmd[tid]);
4546 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004547
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304548 err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
4549 if (err) {
4550 printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
4551 fwname, err);
Herton Ronaldo Krzesinskicf747442010-03-19 19:37:26 -03004552 asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304553 return err;
4554 }
4555 if (fw->size < 4) {
4556 printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
4557 fw->size, fwname);
4558 release_firmware(fw);
Herton Ronaldo Krzesinskicf747442010-03-19 19:37:26 -03004559 asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304560 return -EINVAL;
4561 }
4562 chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
4563 (fw->data[1] << 8) | fw->data[0];
4564 asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
4565 fw->size - 4, ADV_3550_MEMSIZE,
4566 chksum);
4567 release_firmware(fw);
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004568 if (asc_dvc->err_code)
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004569 return ADV_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004570
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004571 /*
4572 * Restore the RISC memory BIOS region.
4573 */
4574 for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
4575 AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
4576 bios_mem[i]);
4577 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004578
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004579 /*
4580 * Calculate and write the microcode code checksum to the microcode
4581 * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
4582 */
4583 AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
4584 AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
4585 code_sum = 0;
4586 AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
4587 for (word = begin_addr; word < end_addr; word += 2) {
4588 code_sum += AdvReadWordAutoIncLram(iop_base);
4589 }
4590 AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004591
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004592 /*
4593 * Read and save microcode version and date.
4594 */
4595 AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
4596 asc_dvc->cfg->mcode_date);
4597 AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
4598 asc_dvc->cfg->mcode_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004599
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004600 /*
4601 * Set the chip type to indicate the ASC3550.
4602 */
4603 AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC3550);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004604
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004605 /*
4606 * If the PCI Configuration Command Register "Parity Error Response
4607 * Control" Bit was clear (0), then set the microcode variable
4608 * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
4609 * to ignore DMA parity errors.
4610 */
4611 if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
4612 AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
4613 word |= CONTROL_FLAG_IGNORE_PERR;
4614 AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
4615 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004617 /*
4618 * For ASC-3550, setting the START_CTL_EMFU [3:2] bits sets a FIFO
4619 * threshold of 128 bytes. This register is only accessible to the host.
4620 */
4621 AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
4622 START_CTL_EMFU | READ_CMD_MRM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004623
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004624 /*
4625 * Microcode operating variables for WDTR, SDTR, and command tag
Matthew Wilcox47d853c2007-07-26 11:41:33 -04004626 * queuing will be set in slave_configure() based on what a
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004627 * device reports it is capable of in Inquiry byte 7.
4628 *
4629 * If SCSI Bus Resets have been disabled, then directly set
4630 * SDTR and WDTR from the EEPROM configuration. This will allow
4631 * the BIOS and warm boot to work without a SCSI bus hang on
4632 * the Inquiry caused by host and target mismatched DTR values.
4633 * Without the SCSI Bus Reset, before an Inquiry a device can't
4634 * be assumed to be in Asynchronous, Narrow mode.
4635 */
4636 if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
4637 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
4638 asc_dvc->wdtr_able);
4639 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
4640 asc_dvc->sdtr_able);
4641 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004642
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004643 /*
4644 * Set microcode operating variables for SDTR_SPEED1, SDTR_SPEED2,
4645 * SDTR_SPEED3, and SDTR_SPEED4 based on the ULTRA EEPROM per TID
4646 * bitmask. These values determine the maximum SDTR speed negotiated
4647 * with a device.
4648 *
4649 * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
4650 * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
4651 * without determining here whether the device supports SDTR.
4652 *
4653 * 4-bit speed SDTR speed name
4654 * =========== ===============
4655 * 0000b (0x0) SDTR disabled
4656 * 0001b (0x1) 5 Mhz
4657 * 0010b (0x2) 10 Mhz
4658 * 0011b (0x3) 20 Mhz (Ultra)
4659 * 0100b (0x4) 40 Mhz (LVD/Ultra2)
4660 * 0101b (0x5) 80 Mhz (LVD2/Ultra3)
4661 * 0110b (0x6) Undefined
4662 * .
4663 * 1111b (0xF) Undefined
4664 */
4665 word = 0;
4666 for (tid = 0; tid <= ADV_MAX_TID; tid++) {
4667 if (ADV_TID_TO_TIDMASK(tid) & asc_dvc->ultra_able) {
4668 /* Set Ultra speed for TID 'tid'. */
4669 word |= (0x3 << (4 * (tid % 4)));
4670 } else {
4671 /* Set Fast speed for TID 'tid'. */
4672 word |= (0x2 << (4 * (tid % 4)));
4673 }
4674 if (tid == 3) { /* Check if done with sdtr_speed1. */
4675 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, word);
4676 word = 0;
4677 } else if (tid == 7) { /* Check if done with sdtr_speed2. */
4678 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, word);
4679 word = 0;
4680 } else if (tid == 11) { /* Check if done with sdtr_speed3. */
4681 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, word);
4682 word = 0;
4683 } else if (tid == 15) { /* Check if done with sdtr_speed4. */
4684 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, word);
4685 /* End of loop. */
4686 }
4687 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004688
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004689 /*
4690 * Set microcode operating variable for the disconnect per TID bitmask.
4691 */
4692 AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
4693 asc_dvc->cfg->disc_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004694
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004695 /*
4696 * Set SCSI_CFG0 Microcode Default Value.
4697 *
4698 * The microcode will set the SCSI_CFG0 register using this value
4699 * after it is started below.
4700 */
4701 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
4702 PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
4703 asc_dvc->chip_scsi_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004704
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004705 /*
4706 * Determine SCSI_CFG1 Microcode Default Value.
4707 *
4708 * The microcode will set the SCSI_CFG1 register using this value
4709 * after it is started below.
4710 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004711
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004712 /* Read current SCSI_CFG1 Register value. */
4713 scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004714
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004715 /*
4716 * If all three connectors are in use, return an error.
4717 */
4718 if ((scsi_cfg1 & CABLE_ILLEGAL_A) == 0 ||
4719 (scsi_cfg1 & CABLE_ILLEGAL_B) == 0) {
4720 asc_dvc->err_code |= ASC_IERR_ILLEGAL_CONNECTION;
4721 return ADV_ERROR;
4722 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004723
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004724 /*
4725 * If the internal narrow cable is reversed all of the SCSI_CTRL
4726 * register signals will be set. Check for and return an error if
4727 * this condition is found.
4728 */
4729 if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
4730 asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
4731 return ADV_ERROR;
4732 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004733
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004734 /*
4735 * If this is a differential board and a single-ended device
4736 * is attached to one of the connectors, return an error.
4737 */
4738 if ((scsi_cfg1 & DIFF_MODE) && (scsi_cfg1 & DIFF_SENSE) == 0) {
4739 asc_dvc->err_code |= ASC_IERR_SINGLE_END_DEVICE;
4740 return ADV_ERROR;
4741 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004742
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004743 /*
4744 * If automatic termination control is enabled, then set the
4745 * termination value based on a table listed in a_condor.h.
4746 *
4747 * If manual termination was specified with an EEPROM setting
4748 * then 'termination' was set-up in AdvInitFrom3550EEPROM() and
4749 * is ready to be 'ored' into SCSI_CFG1.
4750 */
4751 if (asc_dvc->cfg->termination == 0) {
4752 /*
4753 * The software always controls termination by setting TERM_CTL_SEL.
4754 * If TERM_CTL_SEL were set to 0, the hardware would set termination.
4755 */
4756 asc_dvc->cfg->termination |= TERM_CTL_SEL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004757
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004758 switch (scsi_cfg1 & CABLE_DETECT) {
4759 /* TERM_CTL_H: on, TERM_CTL_L: on */
4760 case 0x3:
4761 case 0x7:
4762 case 0xB:
4763 case 0xD:
4764 case 0xE:
4765 case 0xF:
4766 asc_dvc->cfg->termination |= (TERM_CTL_H | TERM_CTL_L);
4767 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004768
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004769 /* TERM_CTL_H: on, TERM_CTL_L: off */
4770 case 0x1:
4771 case 0x5:
4772 case 0x9:
4773 case 0xA:
4774 case 0xC:
4775 asc_dvc->cfg->termination |= TERM_CTL_H;
4776 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004777
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004778 /* TERM_CTL_H: off, TERM_CTL_L: off */
4779 case 0x2:
4780 case 0x6:
4781 break;
4782 }
4783 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004784
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004785 /*
4786 * Clear any set TERM_CTL_H and TERM_CTL_L bits.
4787 */
4788 scsi_cfg1 &= ~TERM_CTL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004789
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004790 /*
4791 * Invert the TERM_CTL_H and TERM_CTL_L bits and then
4792 * set 'scsi_cfg1'. The TERM_POL bit does not need to be
4793 * referenced, because the hardware internally inverts
4794 * the Termination High and Low bits if TERM_POL is set.
4795 */
4796 scsi_cfg1 |= (TERM_CTL_SEL | (~asc_dvc->cfg->termination & TERM_CTL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004797
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004798 /*
4799 * Set SCSI_CFG1 Microcode Default Value
4800 *
4801 * Set filter value and possibly modified termination control
4802 * bits in the Microcode SCSI_CFG1 Register Value.
4803 *
4804 * The microcode will set the SCSI_CFG1 register using this value
4805 * after it is started below.
4806 */
4807 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1,
4808 FLTR_DISABLE | scsi_cfg1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004809
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004810 /*
4811 * Set MEM_CFG Microcode Default Value
4812 *
4813 * The microcode will set the MEM_CFG register using this value
4814 * after it is started below.
4815 *
4816 * MEM_CFG may be accessed as a word or byte, but only bits 0-7
4817 * are defined.
4818 *
4819 * ASC-3550 has 8KB internal memory.
4820 */
4821 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
4822 BIOS_EN | RAM_SZ_8KB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004823
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004824 /*
4825 * Set SEL_MASK Microcode Default Value
4826 *
4827 * The microcode will set the SEL_MASK register using this value
4828 * after it is started below.
4829 */
4830 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
4831 ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004832
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004833 AdvBuildCarrierFreelist(asc_dvc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004834
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004835 /*
4836 * Set-up the Host->RISC Initiator Command Queue (ICQ).
4837 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004838
Hannes Reinecke98b96a72015-04-24 13:18:23 +02004839 asc_dvc->icq_sp = adv_get_next_carrier(asc_dvc);
4840 if (!asc_dvc->icq_sp) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004841 asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
4842 return ADV_ERROR;
4843 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004844
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004845 /*
4846 * Set RISC ICQ physical address start value.
4847 */
4848 AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004849
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004850 /*
4851 * Set-up the RISC->Host Initiator Response Queue (IRQ).
4852 */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02004853 asc_dvc->irq_sp = adv_get_next_carrier(asc_dvc);
4854 if (!asc_dvc->irq_sp) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004855 asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
4856 return ADV_ERROR;
4857 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004858
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004859 /*
4860 * Set RISC IRQ physical address start value.
4861 */
4862 AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
4863 asc_dvc->carr_pending_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004864
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004865 AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
4866 (ADV_INTR_ENABLE_HOST_INTR |
4867 ADV_INTR_ENABLE_GLOBAL_INTR));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004868
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004869 AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
4870 AdvWriteWordRegister(iop_base, IOPW_PC, word);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004871
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004872 /* finally, finally, gentlemen, start your engine */
4873 AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004874
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004875 /*
4876 * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
4877 * Resets should be performed. The RISC has to be running
4878 * to issue a SCSI Bus Reset.
4879 */
4880 if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
4881 /*
4882 * If the BIOS Signature is present in memory, restore the
4883 * BIOS Handshake Configuration Table and do not perform
4884 * a SCSI Bus Reset.
4885 */
4886 if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
4887 0x55AA) {
4888 /*
4889 * Restore per TID negotiated values.
4890 */
4891 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
4892 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
4893 AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
4894 tagqng_able);
4895 for (tid = 0; tid <= ADV_MAX_TID; tid++) {
4896 AdvWriteByteLram(iop_base,
4897 ASC_MC_NUMBER_OF_MAX_CMD + tid,
4898 max_cmd[tid]);
4899 }
4900 } else {
4901 if (AdvResetSB(asc_dvc) != ADV_TRUE) {
4902 warn_code = ASC_WARN_BUSRESET_ERROR;
4903 }
4904 }
4905 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004906
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004907 return warn_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004908}
4909
4910/*
4911 * Initialize the ASC-38C0800.
4912 *
4913 * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
4914 *
4915 * For a non-fatal error return a warning code. If there are no warnings
4916 * then 0 is returned.
4917 *
4918 * Needed after initialization for error recovery.
4919 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004920static int AdvInitAsc38C0800Driver(ADV_DVC_VAR *asc_dvc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004921{
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304922 const struct firmware *fw;
4923 const char fwname[] = "advansys/38C0800.bin";
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004924 AdvPortAddr iop_base;
4925 ushort warn_code;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004926 int begin_addr;
4927 int end_addr;
4928 ushort code_sum;
4929 int word;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004930 int i;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304931 int err;
4932 unsigned long chksum;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004933 ushort scsi_cfg1;
4934 uchar byte;
4935 uchar tid;
4936 ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
4937 ushort wdtr_able, sdtr_able, tagqng_able;
4938 uchar max_cmd[ADV_MAX_TID + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004939
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004940 /* If there is already an error, don't continue. */
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004941 if (asc_dvc->err_code != 0)
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004942 return ADV_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004943
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004944 /*
4945 * The caller must set 'chip_type' to ADV_CHIP_ASC38C0800.
4946 */
4947 if (asc_dvc->chip_type != ADV_CHIP_ASC38C0800) {
4948 asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
4949 return ADV_ERROR;
4950 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004951
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004952 warn_code = 0;
4953 iop_base = asc_dvc->iop_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004955 /*
4956 * Save the RISC memory BIOS region before writing the microcode.
4957 * The BIOS may already be loaded and using its RISC LRAM region
4958 * so its region must be saved and restored.
4959 *
4960 * Note: This code makes the assumption, which is currently true,
4961 * that a chip reset does not clear RISC LRAM.
4962 */
4963 for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
4964 AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
4965 bios_mem[i]);
4966 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004967
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004968 /*
4969 * Save current per TID negotiated values.
4970 */
4971 AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
4972 AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
4973 AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
4974 for (tid = 0; tid <= ADV_MAX_TID; tid++) {
4975 AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
4976 max_cmd[tid]);
4977 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004978
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004979 /*
4980 * RAM BIST (RAM Built-In Self Test)
4981 *
4982 * Address : I/O base + offset 0x38h register (byte).
4983 * Function: Bit 7-6(RW) : RAM mode
4984 * Normal Mode : 0x00
4985 * Pre-test Mode : 0x40
4986 * RAM Test Mode : 0x80
4987 * Bit 5 : unused
4988 * Bit 4(RO) : Done bit
4989 * Bit 3-0(RO) : Status
4990 * Host Error : 0x08
4991 * Int_RAM Error : 0x04
4992 * RISC Error : 0x02
4993 * SCSI Error : 0x01
4994 * No Error : 0x00
4995 *
4996 * Note: RAM BIST code should be put right here, before loading the
4997 * microcode and after saving the RISC memory BIOS region.
4998 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004999
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005000 /*
5001 * LRAM Pre-test
5002 *
5003 * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
5004 * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
5005 * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
5006 * to NORMAL_MODE, return an error too.
5007 */
5008 for (i = 0; i < 2; i++) {
5009 AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
Matthew Wilcoxb009bef2007-09-09 08:56:38 -06005010 mdelay(10); /* Wait for 10ms before reading back. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005011 byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
5012 if ((byte & RAM_TEST_DONE) == 0
5013 || (byte & 0x0F) != PRE_TEST_VALUE) {
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005014 asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005015 return ADV_ERROR;
5016 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005017
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005018 AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
Matthew Wilcoxb009bef2007-09-09 08:56:38 -06005019 mdelay(10); /* Wait for 10ms before reading back. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005020 if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
5021 != NORMAL_VALUE) {
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005022 asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005023 return ADV_ERROR;
5024 }
5025 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005026
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005027 /*
5028 * LRAM Test - It takes about 1.5 ms to run through the test.
5029 *
5030 * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
5031 * If Done bit not set or Status not 0, save register byte, set the
5032 * err_code, and return an error.
5033 */
5034 AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
Matthew Wilcoxb009bef2007-09-09 08:56:38 -06005035 mdelay(10); /* Wait for 10ms before checking status. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005036
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005037 byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
5038 if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
5039 /* Get here if Done bit not set or Status not 0. */
5040 asc_dvc->bist_err_code = byte; /* for BIOS display message */
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005041 asc_dvc->err_code = ASC_IERR_BIST_RAM_TEST;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005042 return ADV_ERROR;
5043 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005044
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005045 /* We need to reset back to normal mode after LRAM test passes. */
5046 AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005047
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05305048 err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
5049 if (err) {
5050 printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
5051 fwname, err);
Herton Ronaldo Krzesinskicf747442010-03-19 19:37:26 -03005052 asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05305053 return err;
5054 }
5055 if (fw->size < 4) {
5056 printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
5057 fw->size, fwname);
5058 release_firmware(fw);
Herton Ronaldo Krzesinskicf747442010-03-19 19:37:26 -03005059 asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05305060 return -EINVAL;
5061 }
5062 chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
5063 (fw->data[1] << 8) | fw->data[0];
5064 asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
5065 fw->size - 4, ADV_38C0800_MEMSIZE,
5066 chksum);
5067 release_firmware(fw);
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005068 if (asc_dvc->err_code)
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005069 return ADV_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005070
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005071 /*
5072 * Restore the RISC memory BIOS region.
5073 */
5074 for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
5075 AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
5076 bios_mem[i]);
5077 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005078
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005079 /*
5080 * Calculate and write the microcode code checksum to the microcode
5081 * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
5082 */
5083 AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
5084 AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
5085 code_sum = 0;
5086 AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
5087 for (word = begin_addr; word < end_addr; word += 2) {
5088 code_sum += AdvReadWordAutoIncLram(iop_base);
5089 }
5090 AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005091
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005092 /*
5093 * Read microcode version and date.
5094 */
5095 AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
5096 asc_dvc->cfg->mcode_date);
5097 AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
5098 asc_dvc->cfg->mcode_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005099
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005100 /*
5101 * Set the chip type to indicate the ASC38C0800.
5102 */
5103 AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C0800);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005104
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005105 /*
5106 * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
5107 * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
5108 * cable detection and then we are able to read C_DET[3:0].
5109 *
5110 * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
5111 * Microcode Default Value' section below.
5112 */
5113 scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
5114 AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1,
5115 scsi_cfg1 | DIS_TERM_DRV);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005116
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005117 /*
5118 * If the PCI Configuration Command Register "Parity Error Response
5119 * Control" Bit was clear (0), then set the microcode variable
5120 * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
5121 * to ignore DMA parity errors.
5122 */
5123 if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
5124 AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
5125 word |= CONTROL_FLAG_IGNORE_PERR;
5126 AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
5127 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005128
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005129 /*
5130 * For ASC-38C0800, set FIFO_THRESH_80B [6:4] bits and START_CTL_TH [3:2]
5131 * bits for the default FIFO threshold.
5132 *
5133 * Note: ASC-38C0800 FIFO threshold has been changed to 256 bytes.
5134 *
5135 * For DMA Errata #4 set the BC_THRESH_ENB bit.
5136 */
5137 AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
5138 BC_THRESH_ENB | FIFO_THRESH_80B | START_CTL_TH |
5139 READ_CMD_MRM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005140
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005141 /*
5142 * Microcode operating variables for WDTR, SDTR, and command tag
Matthew Wilcox47d853c2007-07-26 11:41:33 -04005143 * queuing will be set in slave_configure() based on what a
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005144 * device reports it is capable of in Inquiry byte 7.
5145 *
5146 * If SCSI Bus Resets have been disabled, then directly set
5147 * SDTR and WDTR from the EEPROM configuration. This will allow
5148 * the BIOS and warm boot to work without a SCSI bus hang on
5149 * the Inquiry caused by host and target mismatched DTR values.
5150 * Without the SCSI Bus Reset, before an Inquiry a device can't
5151 * be assumed to be in Asynchronous, Narrow mode.
5152 */
5153 if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
5154 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
5155 asc_dvc->wdtr_able);
5156 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
5157 asc_dvc->sdtr_able);
5158 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005159
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005160 /*
5161 * Set microcode operating variables for DISC and SDTR_SPEED1,
5162 * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
5163 * configuration values.
5164 *
5165 * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
5166 * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
5167 * without determining here whether the device supports SDTR.
5168 */
5169 AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
5170 asc_dvc->cfg->disc_enable);
5171 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
5172 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
5173 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
5174 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005175
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005176 /*
5177 * Set SCSI_CFG0 Microcode Default Value.
5178 *
5179 * The microcode will set the SCSI_CFG0 register using this value
5180 * after it is started below.
5181 */
5182 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
5183 PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
5184 asc_dvc->chip_scsi_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005185
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005186 /*
5187 * Determine SCSI_CFG1 Microcode Default Value.
5188 *
5189 * The microcode will set the SCSI_CFG1 register using this value
5190 * after it is started below.
5191 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005192
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005193 /* Read current SCSI_CFG1 Register value. */
5194 scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005195
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005196 /*
5197 * If the internal narrow cable is reversed all of the SCSI_CTRL
5198 * register signals will be set. Check for and return an error if
5199 * this condition is found.
5200 */
5201 if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
5202 asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
5203 return ADV_ERROR;
5204 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005205
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005206 /*
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005207 * All kind of combinations of devices attached to one of four
5208 * connectors are acceptable except HVD device attached. For example,
5209 * LVD device can be attached to SE connector while SE device attached
5210 * to LVD connector. If LVD device attached to SE connector, it only
5211 * runs up to Ultra speed.
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005212 *
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005213 * If an HVD device is attached to one of LVD connectors, return an
5214 * error. However, there is no way to detect HVD device attached to
5215 * SE connectors.
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005216 */
5217 if (scsi_cfg1 & HVD) {
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005218 asc_dvc->err_code = ASC_IERR_HVD_DEVICE;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005219 return ADV_ERROR;
5220 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005221
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005222 /*
5223 * If either SE or LVD automatic termination control is enabled, then
5224 * set the termination value based on a table listed in a_condor.h.
5225 *
5226 * If manual termination was specified with an EEPROM setting then
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005227 * 'termination' was set-up in AdvInitFrom38C0800EEPROM() and is ready
5228 * to be 'ored' into SCSI_CFG1.
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005229 */
5230 if ((asc_dvc->cfg->termination & TERM_SE) == 0) {
5231 /* SE automatic termination control is enabled. */
5232 switch (scsi_cfg1 & C_DET_SE) {
5233 /* TERM_SE_HI: on, TERM_SE_LO: on */
5234 case 0x1:
5235 case 0x2:
5236 case 0x3:
5237 asc_dvc->cfg->termination |= TERM_SE;
5238 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005239
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005240 /* TERM_SE_HI: on, TERM_SE_LO: off */
5241 case 0x0:
5242 asc_dvc->cfg->termination |= TERM_SE_HI;
5243 break;
5244 }
5245 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005246
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005247 if ((asc_dvc->cfg->termination & TERM_LVD) == 0) {
5248 /* LVD automatic termination control is enabled. */
5249 switch (scsi_cfg1 & C_DET_LVD) {
5250 /* TERM_LVD_HI: on, TERM_LVD_LO: on */
5251 case 0x4:
5252 case 0x8:
5253 case 0xC:
5254 asc_dvc->cfg->termination |= TERM_LVD;
5255 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005256
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005257 /* TERM_LVD_HI: off, TERM_LVD_LO: off */
5258 case 0x0:
5259 break;
5260 }
5261 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005262
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005263 /*
5264 * Clear any set TERM_SE and TERM_LVD bits.
5265 */
5266 scsi_cfg1 &= (~TERM_SE & ~TERM_LVD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005267
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005268 /*
5269 * Invert the TERM_SE and TERM_LVD bits and then set 'scsi_cfg1'.
5270 */
5271 scsi_cfg1 |= (~asc_dvc->cfg->termination & 0xF0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005272
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005273 /*
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005274 * Clear BIG_ENDIAN, DIS_TERM_DRV, Terminator Polarity and HVD/LVD/SE
5275 * bits and set possibly modified termination control bits in the
5276 * Microcode SCSI_CFG1 Register Value.
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005277 */
5278 scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL & ~HVD_LVD_SE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005279
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005280 /*
5281 * Set SCSI_CFG1 Microcode Default Value
5282 *
5283 * Set possibly modified termination control and reset DIS_TERM_DRV
5284 * bits in the Microcode SCSI_CFG1 Register Value.
5285 *
5286 * The microcode will set the SCSI_CFG1 register using this value
5287 * after it is started below.
5288 */
5289 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005290
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005291 /*
5292 * Set MEM_CFG Microcode Default Value
5293 *
5294 * The microcode will set the MEM_CFG register using this value
5295 * after it is started below.
5296 *
5297 * MEM_CFG may be accessed as a word or byte, but only bits 0-7
5298 * are defined.
5299 *
5300 * ASC-38C0800 has 16KB internal memory.
5301 */
5302 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
5303 BIOS_EN | RAM_SZ_16KB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005304
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005305 /*
5306 * Set SEL_MASK Microcode Default Value
5307 *
5308 * The microcode will set the SEL_MASK register using this value
5309 * after it is started below.
5310 */
5311 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
5312 ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005313
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06005314 AdvBuildCarrierFreelist(asc_dvc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005315
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005316 /*
5317 * Set-up the Host->RISC Initiator Command Queue (ICQ).
5318 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005319
Hannes Reinecke98b96a72015-04-24 13:18:23 +02005320 asc_dvc->icq_sp = adv_get_next_carrier(asc_dvc);
5321 if (!asc_dvc->icq_sp) {
5322 ASC_DBG(0, "Failed to get ICQ carrier\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005323 asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
5324 return ADV_ERROR;
5325 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005326
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005327 /*
5328 * Set RISC ICQ physical address start value.
5329 * carr_pa is LE, must be native before write
5330 */
5331 AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005332
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005333 /*
5334 * Set-up the RISC->Host Initiator Response Queue (IRQ).
5335 */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02005336 asc_dvc->irq_sp = adv_get_next_carrier(asc_dvc);
5337 if (!asc_dvc->irq_sp) {
5338 ASC_DBG(0, "Failed to get IRQ carrier\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005339 asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
5340 return ADV_ERROR;
5341 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005342
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005343 /*
5344 * Set RISC IRQ physical address start value.
5345 *
5346 * carr_pa is LE, must be native before write *
5347 */
5348 AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
5349 asc_dvc->carr_pending_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005350
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005351 AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
5352 (ADV_INTR_ENABLE_HOST_INTR |
5353 ADV_INTR_ENABLE_GLOBAL_INTR));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005354
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005355 AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
5356 AdvWriteWordRegister(iop_base, IOPW_PC, word);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005357
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005358 /* finally, finally, gentlemen, start your engine */
5359 AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005360
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005361 /*
5362 * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
5363 * Resets should be performed. The RISC has to be running
5364 * to issue a SCSI Bus Reset.
5365 */
5366 if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
5367 /*
5368 * If the BIOS Signature is present in memory, restore the
5369 * BIOS Handshake Configuration Table and do not perform
5370 * a SCSI Bus Reset.
5371 */
5372 if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
5373 0x55AA) {
5374 /*
5375 * Restore per TID negotiated values.
5376 */
5377 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
5378 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
5379 AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
5380 tagqng_able);
5381 for (tid = 0; tid <= ADV_MAX_TID; tid++) {
5382 AdvWriteByteLram(iop_base,
5383 ASC_MC_NUMBER_OF_MAX_CMD + tid,
5384 max_cmd[tid]);
5385 }
5386 } else {
5387 if (AdvResetSB(asc_dvc) != ADV_TRUE) {
5388 warn_code = ASC_WARN_BUSRESET_ERROR;
5389 }
5390 }
5391 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005392
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005393 return warn_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005394}
5395
5396/*
5397 * Initialize the ASC-38C1600.
5398 *
5399 * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
5400 *
5401 * For a non-fatal error return a warning code. If there are no warnings
5402 * then 0 is returned.
5403 *
5404 * Needed after initialization for error recovery.
5405 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005406static int AdvInitAsc38C1600Driver(ADV_DVC_VAR *asc_dvc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005407{
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05305408 const struct firmware *fw;
5409 const char fwname[] = "advansys/38C1600.bin";
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005410 AdvPortAddr iop_base;
5411 ushort warn_code;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005412 int begin_addr;
5413 int end_addr;
5414 ushort code_sum;
5415 long word;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005416 int i;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05305417 int err;
5418 unsigned long chksum;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005419 ushort scsi_cfg1;
5420 uchar byte;
5421 uchar tid;
5422 ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
5423 ushort wdtr_able, sdtr_able, ppr_able, tagqng_able;
5424 uchar max_cmd[ASC_MAX_TID + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005425
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005426 /* If there is already an error, don't continue. */
5427 if (asc_dvc->err_code != 0) {
5428 return ADV_ERROR;
5429 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005430
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005431 /*
5432 * The caller must set 'chip_type' to ADV_CHIP_ASC38C1600.
5433 */
5434 if (asc_dvc->chip_type != ADV_CHIP_ASC38C1600) {
5435 asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
5436 return ADV_ERROR;
5437 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005438
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005439 warn_code = 0;
5440 iop_base = asc_dvc->iop_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005441
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005442 /*
5443 * Save the RISC memory BIOS region before writing the microcode.
5444 * The BIOS may already be loaded and using its RISC LRAM region
5445 * so its region must be saved and restored.
5446 *
5447 * Note: This code makes the assumption, which is currently true,
5448 * that a chip reset does not clear RISC LRAM.
5449 */
5450 for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
5451 AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
5452 bios_mem[i]);
5453 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005454
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005455 /*
5456 * Save current per TID negotiated values.
5457 */
5458 AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
5459 AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
5460 AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
5461 AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
5462 for (tid = 0; tid <= ASC_MAX_TID; tid++) {
5463 AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
5464 max_cmd[tid]);
5465 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005466
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005467 /*
5468 * RAM BIST (Built-In Self Test)
5469 *
5470 * Address : I/O base + offset 0x38h register (byte).
5471 * Function: Bit 7-6(RW) : RAM mode
5472 * Normal Mode : 0x00
5473 * Pre-test Mode : 0x40
5474 * RAM Test Mode : 0x80
5475 * Bit 5 : unused
5476 * Bit 4(RO) : Done bit
5477 * Bit 3-0(RO) : Status
5478 * Host Error : 0x08
5479 * Int_RAM Error : 0x04
5480 * RISC Error : 0x02
5481 * SCSI Error : 0x01
5482 * No Error : 0x00
5483 *
5484 * Note: RAM BIST code should be put right here, before loading the
5485 * microcode and after saving the RISC memory BIOS region.
5486 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005487
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005488 /*
5489 * LRAM Pre-test
5490 *
5491 * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
5492 * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
5493 * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
5494 * to NORMAL_MODE, return an error too.
5495 */
5496 for (i = 0; i < 2; i++) {
5497 AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
Matthew Wilcoxb009bef2007-09-09 08:56:38 -06005498 mdelay(10); /* Wait for 10ms before reading back. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005499 byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
5500 if ((byte & RAM_TEST_DONE) == 0
5501 || (byte & 0x0F) != PRE_TEST_VALUE) {
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005502 asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005503 return ADV_ERROR;
5504 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005505
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005506 AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
Matthew Wilcoxb009bef2007-09-09 08:56:38 -06005507 mdelay(10); /* Wait for 10ms before reading back. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005508 if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
5509 != NORMAL_VALUE) {
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005510 asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005511 return ADV_ERROR;
5512 }
5513 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005514
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005515 /*
5516 * LRAM Test - It takes about 1.5 ms to run through the test.
5517 *
5518 * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
5519 * If Done bit not set or Status not 0, save register byte, set the
5520 * err_code, and return an error.
5521 */
5522 AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
Matthew Wilcoxb009bef2007-09-09 08:56:38 -06005523 mdelay(10); /* Wait for 10ms before checking status. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005524
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005525 byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
5526 if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
5527 /* Get here if Done bit not set or Status not 0. */
5528 asc_dvc->bist_err_code = byte; /* for BIOS display message */
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005529 asc_dvc->err_code = ASC_IERR_BIST_RAM_TEST;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005530 return ADV_ERROR;
5531 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005532
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005533 /* We need to reset back to normal mode after LRAM test passes. */
5534 AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005535
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05305536 err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
5537 if (err) {
5538 printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
5539 fwname, err);
Herton Ronaldo Krzesinskicf747442010-03-19 19:37:26 -03005540 asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05305541 return err;
5542 }
5543 if (fw->size < 4) {
5544 printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
5545 fw->size, fwname);
5546 release_firmware(fw);
Herton Ronaldo Krzesinskicf747442010-03-19 19:37:26 -03005547 asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05305548 return -EINVAL;
5549 }
5550 chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
5551 (fw->data[1] << 8) | fw->data[0];
5552 asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
5553 fw->size - 4, ADV_38C1600_MEMSIZE,
5554 chksum);
5555 release_firmware(fw);
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005556 if (asc_dvc->err_code)
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005557 return ADV_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005558
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005559 /*
5560 * Restore the RISC memory BIOS region.
5561 */
5562 for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
5563 AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
5564 bios_mem[i]);
5565 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005566
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005567 /*
5568 * Calculate and write the microcode code checksum to the microcode
5569 * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
5570 */
5571 AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
5572 AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
5573 code_sum = 0;
5574 AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
5575 for (word = begin_addr; word < end_addr; word += 2) {
5576 code_sum += AdvReadWordAutoIncLram(iop_base);
5577 }
5578 AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005579
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005580 /*
5581 * Read microcode version and date.
5582 */
5583 AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
5584 asc_dvc->cfg->mcode_date);
5585 AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
5586 asc_dvc->cfg->mcode_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005587
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005588 /*
5589 * Set the chip type to indicate the ASC38C1600.
5590 */
5591 AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C1600);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005592
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005593 /*
5594 * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
5595 * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
5596 * cable detection and then we are able to read C_DET[3:0].
5597 *
5598 * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
5599 * Microcode Default Value' section below.
5600 */
5601 scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
5602 AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1,
5603 scsi_cfg1 | DIS_TERM_DRV);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005604
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005605 /*
5606 * If the PCI Configuration Command Register "Parity Error Response
5607 * Control" Bit was clear (0), then set the microcode variable
5608 * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
5609 * to ignore DMA parity errors.
5610 */
5611 if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
5612 AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
5613 word |= CONTROL_FLAG_IGNORE_PERR;
5614 AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
5615 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005616
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005617 /*
5618 * If the BIOS control flag AIPP (Asynchronous Information
5619 * Phase Protection) disable bit is not set, then set the firmware
5620 * 'control_flag' CONTROL_FLAG_ENABLE_AIPP bit to enable
5621 * AIPP checking and encoding.
5622 */
5623 if ((asc_dvc->bios_ctrl & BIOS_CTRL_AIPP_DIS) == 0) {
5624 AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
5625 word |= CONTROL_FLAG_ENABLE_AIPP;
5626 AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
5627 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005628
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005629 /*
5630 * For ASC-38C1600 use DMA_CFG0 default values: FIFO_THRESH_80B [6:4],
5631 * and START_CTL_TH [3:2].
5632 */
5633 AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
5634 FIFO_THRESH_80B | START_CTL_TH | READ_CMD_MRM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005635
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005636 /*
5637 * Microcode operating variables for WDTR, SDTR, and command tag
Matthew Wilcox47d853c2007-07-26 11:41:33 -04005638 * queuing will be set in slave_configure() based on what a
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005639 * device reports it is capable of in Inquiry byte 7.
5640 *
5641 * If SCSI Bus Resets have been disabled, then directly set
5642 * SDTR and WDTR from the EEPROM configuration. This will allow
5643 * the BIOS and warm boot to work without a SCSI bus hang on
5644 * the Inquiry caused by host and target mismatched DTR values.
5645 * Without the SCSI Bus Reset, before an Inquiry a device can't
5646 * be assumed to be in Asynchronous, Narrow mode.
5647 */
5648 if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
5649 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
5650 asc_dvc->wdtr_able);
5651 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
5652 asc_dvc->sdtr_able);
5653 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005654
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005655 /*
5656 * Set microcode operating variables for DISC and SDTR_SPEED1,
5657 * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
5658 * configuration values.
5659 *
5660 * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
5661 * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
5662 * without determining here whether the device supports SDTR.
5663 */
5664 AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
5665 asc_dvc->cfg->disc_enable);
5666 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
5667 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
5668 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
5669 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005670
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005671 /*
5672 * Set SCSI_CFG0 Microcode Default Value.
5673 *
5674 * The microcode will set the SCSI_CFG0 register using this value
5675 * after it is started below.
5676 */
5677 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
5678 PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
5679 asc_dvc->chip_scsi_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005680
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005681 /*
5682 * Calculate SCSI_CFG1 Microcode Default Value.
5683 *
5684 * The microcode will set the SCSI_CFG1 register using this value
5685 * after it is started below.
5686 *
5687 * Each ASC-38C1600 function has only two cable detect bits.
5688 * The bus mode override bits are in IOPB_SOFT_OVER_WR.
5689 */
5690 scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005691
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005692 /*
5693 * If the cable is reversed all of the SCSI_CTRL register signals
5694 * will be set. Check for and return an error if this condition is
5695 * found.
5696 */
5697 if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
5698 asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
5699 return ADV_ERROR;
5700 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005701
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005702 /*
5703 * Each ASC-38C1600 function has two connectors. Only an HVD device
5704 * can not be connected to either connector. An LVD device or SE device
5705 * may be connected to either connecor. If an SE device is connected,
5706 * then at most Ultra speed (20 Mhz) can be used on both connectors.
5707 *
5708 * If an HVD device is attached, return an error.
5709 */
5710 if (scsi_cfg1 & HVD) {
5711 asc_dvc->err_code |= ASC_IERR_HVD_DEVICE;
5712 return ADV_ERROR;
5713 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005714
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005715 /*
5716 * Each function in the ASC-38C1600 uses only the SE cable detect and
5717 * termination because there are two connectors for each function. Each
5718 * function may use either LVD or SE mode. Corresponding the SE automatic
5719 * termination control EEPROM bits are used for each function. Each
5720 * function has its own EEPROM. If SE automatic control is enabled for
5721 * the function, then set the termination value based on a table listed
5722 * in a_condor.h.
5723 *
5724 * If manual termination is specified in the EEPROM for the function,
5725 * then 'termination' was set-up in AscInitFrom38C1600EEPROM() and is
5726 * ready to be 'ored' into SCSI_CFG1.
5727 */
5728 if ((asc_dvc->cfg->termination & TERM_SE) == 0) {
Matthew Wilcox13ac2d92007-07-30 08:10:23 -06005729 struct pci_dev *pdev = adv_dvc_to_pdev(asc_dvc);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005730 /* SE automatic termination control is enabled. */
5731 switch (scsi_cfg1 & C_DET_SE) {
5732 /* TERM_SE_HI: on, TERM_SE_LO: on */
5733 case 0x1:
5734 case 0x2:
5735 case 0x3:
5736 asc_dvc->cfg->termination |= TERM_SE;
5737 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005738
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005739 case 0x0:
Matthew Wilcox13ac2d92007-07-30 08:10:23 -06005740 if (PCI_FUNC(pdev->devfn) == 0) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005741 /* Function 0 - TERM_SE_HI: off, TERM_SE_LO: off */
5742 } else {
5743 /* Function 1 - TERM_SE_HI: on, TERM_SE_LO: off */
5744 asc_dvc->cfg->termination |= TERM_SE_HI;
5745 }
5746 break;
5747 }
5748 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005749
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005750 /*
5751 * Clear any set TERM_SE bits.
5752 */
5753 scsi_cfg1 &= ~TERM_SE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005754
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005755 /*
5756 * Invert the TERM_SE bits and then set 'scsi_cfg1'.
5757 */
5758 scsi_cfg1 |= (~asc_dvc->cfg->termination & TERM_SE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005759
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005760 /*
5761 * Clear Big Endian and Terminator Polarity bits and set possibly
5762 * modified termination control bits in the Microcode SCSI_CFG1
5763 * Register Value.
5764 *
5765 * Big Endian bit is not used even on big endian machines.
5766 */
5767 scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005768
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005769 /*
5770 * Set SCSI_CFG1 Microcode Default Value
5771 *
5772 * Set possibly modified termination control bits in the Microcode
5773 * SCSI_CFG1 Register Value.
5774 *
5775 * The microcode will set the SCSI_CFG1 register using this value
5776 * after it is started below.
5777 */
5778 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005779
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005780 /*
5781 * Set MEM_CFG Microcode Default Value
5782 *
5783 * The microcode will set the MEM_CFG register using this value
5784 * after it is started below.
5785 *
5786 * MEM_CFG may be accessed as a word or byte, but only bits 0-7
5787 * are defined.
5788 *
5789 * ASC-38C1600 has 32KB internal memory.
5790 *
5791 * XXX - Since ASC38C1600 Rev.3 has a Local RAM failure issue, we come
5792 * out a special 16K Adv Library and Microcode version. After the issue
5793 * resolved, we should turn back to the 32K support. Both a_condor.h and
5794 * mcode.sas files also need to be updated.
5795 *
5796 * AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
5797 * BIOS_EN | RAM_SZ_32KB);
5798 */
5799 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
5800 BIOS_EN | RAM_SZ_16KB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005801
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005802 /*
5803 * Set SEL_MASK Microcode Default Value
5804 *
5805 * The microcode will set the SEL_MASK register using this value
5806 * after it is started below.
5807 */
5808 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
5809 ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005810
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06005811 AdvBuildCarrierFreelist(asc_dvc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005812
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005813 /*
5814 * Set-up the Host->RISC Initiator Command Queue (ICQ).
5815 */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02005816 asc_dvc->icq_sp = adv_get_next_carrier(asc_dvc);
5817 if (!asc_dvc->icq_sp) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005818 asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
5819 return ADV_ERROR;
5820 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005821
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005822 /*
5823 * Set RISC ICQ physical address start value. Initialize the
5824 * COMMA register to the same value otherwise the RISC will
5825 * prematurely detect a command is available.
5826 */
5827 AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
5828 AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
5829 le32_to_cpu(asc_dvc->icq_sp->carr_pa));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005830
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005831 /*
5832 * Set-up the RISC->Host Initiator Response Queue (IRQ).
5833 */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02005834 asc_dvc->irq_sp = adv_get_next_carrier(asc_dvc);
5835 if (!asc_dvc->irq_sp) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005836 asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
5837 return ADV_ERROR;
5838 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005839
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005840 /*
5841 * Set RISC IRQ physical address start value.
5842 */
5843 AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
5844 asc_dvc->carr_pending_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005845
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005846 AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
5847 (ADV_INTR_ENABLE_HOST_INTR |
5848 ADV_INTR_ENABLE_GLOBAL_INTR));
5849 AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
5850 AdvWriteWordRegister(iop_base, IOPW_PC, word);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005851
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005852 /* finally, finally, gentlemen, start your engine */
5853 AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005854
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005855 /*
5856 * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
5857 * Resets should be performed. The RISC has to be running
5858 * to issue a SCSI Bus Reset.
5859 */
5860 if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
5861 /*
5862 * If the BIOS Signature is present in memory, restore the
5863 * per TID microcode operating variables.
5864 */
5865 if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
5866 0x55AA) {
5867 /*
5868 * Restore per TID negotiated values.
5869 */
5870 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
5871 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
5872 AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
5873 AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
5874 tagqng_able);
5875 for (tid = 0; tid <= ASC_MAX_TID; tid++) {
5876 AdvWriteByteLram(iop_base,
5877 ASC_MC_NUMBER_OF_MAX_CMD + tid,
5878 max_cmd[tid]);
5879 }
5880 } else {
5881 if (AdvResetSB(asc_dvc) != ADV_TRUE) {
5882 warn_code = ASC_WARN_BUSRESET_ERROR;
5883 }
5884 }
5885 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005886
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005887 return warn_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005888}
5889
5890/*
Matthew Wilcox51219352007-10-02 21:55:22 -04005891 * Reset chip and SCSI Bus.
5892 *
5893 * Return Value:
5894 * ADV_TRUE(1) - Chip re-initialization and SCSI Bus Reset successful.
5895 * ADV_FALSE(0) - Chip re-initialization and SCSI Bus Reset failure.
5896 */
5897static int AdvResetChipAndSB(ADV_DVC_VAR *asc_dvc)
5898{
5899 int status;
5900 ushort wdtr_able, sdtr_able, tagqng_able;
5901 ushort ppr_able = 0;
5902 uchar tid, max_cmd[ADV_MAX_TID + 1];
5903 AdvPortAddr iop_base;
5904 ushort bios_sig;
5905
5906 iop_base = asc_dvc->iop_base;
5907
5908 /*
5909 * Save current per TID negotiated values.
5910 */
5911 AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
5912 AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
5913 if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
5914 AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
5915 }
5916 AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
5917 for (tid = 0; tid <= ADV_MAX_TID; tid++) {
5918 AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
5919 max_cmd[tid]);
5920 }
5921
5922 /*
5923 * Force the AdvInitAsc3550/38C0800Driver() function to
5924 * perform a SCSI Bus Reset by clearing the BIOS signature word.
5925 * The initialization functions assumes a SCSI Bus Reset is not
5926 * needed if the BIOS signature word is present.
5927 */
5928 AdvReadWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
5929 AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, 0);
5930
5931 /*
5932 * Stop chip and reset it.
5933 */
5934 AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_STOP);
5935 AdvWriteWordRegister(iop_base, IOPW_CTRL_REG, ADV_CTRL_REG_CMD_RESET);
5936 mdelay(100);
5937 AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
5938 ADV_CTRL_REG_CMD_WR_IO_REG);
5939
5940 /*
5941 * Reset Adv Library error code, if any, and try
5942 * re-initializing the chip.
5943 */
5944 asc_dvc->err_code = 0;
5945 if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
5946 status = AdvInitAsc38C1600Driver(asc_dvc);
5947 } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
5948 status = AdvInitAsc38C0800Driver(asc_dvc);
5949 } else {
5950 status = AdvInitAsc3550Driver(asc_dvc);
5951 }
5952
5953 /* Translate initialization return value to status value. */
5954 if (status == 0) {
5955 status = ADV_TRUE;
5956 } else {
5957 status = ADV_FALSE;
5958 }
5959
5960 /*
5961 * Restore the BIOS signature word.
5962 */
5963 AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
5964
5965 /*
5966 * Restore per TID negotiated values.
5967 */
5968 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
5969 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
5970 if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
5971 AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
5972 }
5973 AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
5974 for (tid = 0; tid <= ADV_MAX_TID; tid++) {
5975 AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
5976 max_cmd[tid]);
5977 }
5978
5979 return status;
5980}
5981
5982/*
5983 * adv_async_callback() - Adv Library asynchronous event callback function.
5984 */
5985static void adv_async_callback(ADV_DVC_VAR *adv_dvc_varp, uchar code)
5986{
5987 switch (code) {
5988 case ADV_ASYNC_SCSI_BUS_RESET_DET:
5989 /*
5990 * The firmware detected a SCSI Bus reset.
5991 */
Matthew Wilcoxb352f922007-10-02 21:55:33 -04005992 ASC_DBG(0, "ADV_ASYNC_SCSI_BUS_RESET_DET\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04005993 break;
5994
5995 case ADV_ASYNC_RDMA_FAILURE:
5996 /*
5997 * Handle RDMA failure by resetting the SCSI Bus and
5998 * possibly the chip if it is unresponsive. Log the error
5999 * with a unique code.
6000 */
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006001 ASC_DBG(0, "ADV_ASYNC_RDMA_FAILURE\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04006002 AdvResetChipAndSB(adv_dvc_varp);
6003 break;
6004
6005 case ADV_HOST_SCSI_BUS_RESET:
6006 /*
6007 * Host generated SCSI bus reset occurred.
6008 */
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006009 ASC_DBG(0, "ADV_HOST_SCSI_BUS_RESET\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04006010 break;
6011
6012 default:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006013 ASC_DBG(0, "unknown code 0x%x\n", code);
Matthew Wilcox51219352007-10-02 21:55:22 -04006014 break;
6015 }
6016}
6017
6018/*
6019 * adv_isr_callback() - Second Level Interrupt Handler called by AdvISR().
6020 *
6021 * Callback function for the Wide SCSI Adv Library.
6022 */
6023static void adv_isr_callback(ADV_DVC_VAR *adv_dvc_varp, ADV_SCSI_REQ_Q *scsiqp)
6024{
Hannes Reinecke9c17c622015-04-24 13:18:21 +02006025 struct asc_board *boardp = adv_dvc_varp->drv_ptr;
6026 u32 srb_tag;
Matthew Wilcox51219352007-10-02 21:55:22 -04006027 adv_req_t *reqp;
6028 adv_sgblk_t *sgblkp;
6029 struct scsi_cmnd *scp;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02006030 u32 resid_cnt;
Hannes Reinecke811ddc02015-04-24 13:18:22 +02006031 dma_addr_t sense_addr;
Matthew Wilcox51219352007-10-02 21:55:22 -04006032
Hannes Reinecke9c17c622015-04-24 13:18:21 +02006033 ASC_DBG(1, "adv_dvc_varp 0x%p, scsiqp 0x%p\n",
6034 adv_dvc_varp, scsiqp);
Matthew Wilcox51219352007-10-02 21:55:22 -04006035 ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
6036
6037 /*
6038 * Get the adv_req_t structure for the command that has been
6039 * completed. The adv_req_t structure actually contains the
6040 * completed ADV_SCSI_REQ_Q structure.
6041 */
Hannes Reinecke9c17c622015-04-24 13:18:21 +02006042 srb_tag = le32_to_cpu(scsiqp->srb_tag);
6043 scp = scsi_host_find_tag(boardp->shost, scsiqp->srb_tag);
Matthew Wilcox51219352007-10-02 21:55:22 -04006044
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006045 ASC_DBG(1, "scp 0x%p\n", scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04006046 if (scp == NULL) {
6047 ASC_PRINT
6048 ("adv_isr_callback: scp is NULL; adv_req_t dropped.\n");
6049 return;
6050 }
6051 ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
6052
Hannes Reinecke9c17c622015-04-24 13:18:21 +02006053 reqp = (adv_req_t *)scp->host_scribble;
6054 ASC_DBG(1, "reqp 0x%lx\n", (ulong)reqp);
6055 if (reqp == NULL) {
6056 ASC_PRINT("adv_isr_callback: reqp is NULL\n");
6057 return;
6058 }
6059 /*
6060 * Remove backreferences to avoid duplicate
6061 * command completions.
6062 */
6063 scp->host_scribble = NULL;
6064 reqp->cmndp = NULL;
Matthew Wilcox51219352007-10-02 21:55:22 -04006065
Hannes Reinecke9c17c622015-04-24 13:18:21 +02006066 ASC_STATS(boardp->shost, callback);
6067 ASC_DBG(1, "shost 0x%p\n", boardp->shost);
Matthew Wilcox51219352007-10-02 21:55:22 -04006068
Hannes Reinecke811ddc02015-04-24 13:18:22 +02006069 sense_addr = le32_to_cpu(scsiqp->sense_addr);
6070 dma_unmap_single(boardp->dev, sense_addr,
6071 SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
6072
Matthew Wilcox51219352007-10-02 21:55:22 -04006073 /*
6074 * 'done_status' contains the command's ending status.
6075 */
6076 switch (scsiqp->done_status) {
6077 case QD_NO_ERROR:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006078 ASC_DBG(2, "QD_NO_ERROR\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04006079 scp->result = 0;
6080
6081 /*
6082 * Check for an underrun condition.
6083 *
6084 * If there was no error and an underrun condition, then
6085 * then return the number of underrun bytes.
6086 */
6087 resid_cnt = le32_to_cpu(scsiqp->data_cnt);
Matthew Wilcox52c334e2007-10-02 21:55:39 -04006088 if (scsi_bufflen(scp) != 0 && resid_cnt != 0 &&
6089 resid_cnt <= scsi_bufflen(scp)) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006090 ASC_DBG(1, "underrun condition %lu bytes\n",
Matthew Wilcox51219352007-10-02 21:55:22 -04006091 (ulong)resid_cnt);
Matthew Wilcox52c334e2007-10-02 21:55:39 -04006092 scsi_set_resid(scp, resid_cnt);
Matthew Wilcox51219352007-10-02 21:55:22 -04006093 }
6094 break;
6095
6096 case QD_WITH_ERROR:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006097 ASC_DBG(2, "QD_WITH_ERROR\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04006098 switch (scsiqp->host_status) {
6099 case QHSTA_NO_ERROR:
6100 if (scsiqp->scsi_status == SAM_STAT_CHECK_CONDITION) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006101 ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04006102 ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09006103 SCSI_SENSE_BUFFERSIZE);
Matthew Wilcox51219352007-10-02 21:55:22 -04006104 /*
6105 * Note: The 'status_byte()' macro used by
6106 * target drivers defined in scsi.h shifts the
6107 * status byte returned by host drivers right
6108 * by 1 bit. This is why target drivers also
6109 * use right shifted status byte definitions.
6110 * For instance target drivers use
6111 * CHECK_CONDITION, defined to 0x1, instead of
6112 * the SCSI defined check condition value of
6113 * 0x2. Host drivers are supposed to return
6114 * the status byte as it is defined by SCSI.
6115 */
6116 scp->result = DRIVER_BYTE(DRIVER_SENSE) |
6117 STATUS_BYTE(scsiqp->scsi_status);
6118 } else {
6119 scp->result = STATUS_BYTE(scsiqp->scsi_status);
6120 }
6121 break;
6122
6123 default:
6124 /* Some other QHSTA error occurred. */
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006125 ASC_DBG(1, "host_status 0x%x\n", scsiqp->host_status);
Matthew Wilcox51219352007-10-02 21:55:22 -04006126 scp->result = HOST_BYTE(DID_BAD_TARGET);
6127 break;
6128 }
6129 break;
6130
6131 case QD_ABORTED_BY_HOST:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006132 ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04006133 scp->result =
6134 HOST_BYTE(DID_ABORT) | STATUS_BYTE(scsiqp->scsi_status);
6135 break;
6136
6137 default:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006138 ASC_DBG(1, "done_status 0x%x\n", scsiqp->done_status);
Matthew Wilcox51219352007-10-02 21:55:22 -04006139 scp->result =
6140 HOST_BYTE(DID_ERROR) | STATUS_BYTE(scsiqp->scsi_status);
6141 break;
6142 }
6143
6144 /*
6145 * If the 'init_tidmask' bit isn't already set for the target and the
6146 * current request finished normally, then set the bit for the target
6147 * to indicate that a device is present.
6148 */
6149 if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
6150 scsiqp->done_status == QD_NO_ERROR &&
6151 scsiqp->host_status == QHSTA_NO_ERROR) {
6152 boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
6153 }
6154
6155 asc_scsi_done(scp);
6156
6157 /*
6158 * Free all 'adv_sgblk_t' structures allocated for the request.
6159 */
6160 while ((sgblkp = reqp->sgblkp) != NULL) {
6161 /* Remove 'sgblkp' from the request list. */
6162 reqp->sgblkp = sgblkp->next_sgblkp;
6163
Hannes Reinecke0ce53822015-04-24 13:18:25 +02006164 dma_pool_free(boardp->adv_sgblk_pool, sgblkp,
6165 sgblkp->sg_addr);
Matthew Wilcox51219352007-10-02 21:55:22 -04006166 }
6167
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006168 ASC_DBG(1, "done\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04006169}
6170
6171/*
6172 * Adv Library Interrupt Service Routine
6173 *
6174 * This function is called by a driver's interrupt service routine.
6175 * The function disables and re-enables interrupts.
6176 *
6177 * When a microcode idle command is completed, the ADV_DVC_VAR
6178 * 'idle_cmd_done' field is set to ADV_TRUE.
6179 *
6180 * Note: AdvISR() can be called when interrupts are disabled or even
6181 * when there is no hardware interrupt condition present. It will
6182 * always check for completed idle commands and microcode requests.
6183 * This is an important feature that shouldn't be changed because it
6184 * allows commands to be completed from polling mode loops.
6185 *
6186 * Return:
6187 * ADV_TRUE(1) - interrupt was pending
6188 * ADV_FALSE(0) - no interrupt was pending
6189 */
6190static int AdvISR(ADV_DVC_VAR *asc_dvc)
6191{
6192 AdvPortAddr iop_base;
6193 uchar int_stat;
6194 ushort target_bit;
6195 ADV_CARR_T *free_carrp;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02006196 __le32 irq_next_vpa;
Matthew Wilcox51219352007-10-02 21:55:22 -04006197 ADV_SCSI_REQ_Q *scsiq;
Hannes Reinecke4b47e462015-04-24 13:18:24 +02006198 adv_req_t *reqp;
Matthew Wilcox51219352007-10-02 21:55:22 -04006199
6200 iop_base = asc_dvc->iop_base;
6201
6202 /* Reading the register clears the interrupt. */
6203 int_stat = AdvReadByteRegister(iop_base, IOPB_INTR_STATUS_REG);
6204
6205 if ((int_stat & (ADV_INTR_STATUS_INTRA | ADV_INTR_STATUS_INTRB |
6206 ADV_INTR_STATUS_INTRC)) == 0) {
6207 return ADV_FALSE;
6208 }
6209
6210 /*
6211 * Notify the driver of an asynchronous microcode condition by
6212 * calling the adv_async_callback function. The function
6213 * is passed the microcode ASC_MC_INTRB_CODE byte value.
6214 */
6215 if (int_stat & ADV_INTR_STATUS_INTRB) {
6216 uchar intrb_code;
6217
6218 AdvReadByteLram(iop_base, ASC_MC_INTRB_CODE, intrb_code);
6219
6220 if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
6221 asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
6222 if (intrb_code == ADV_ASYNC_CARRIER_READY_FAILURE &&
6223 asc_dvc->carr_pending_cnt != 0) {
6224 AdvWriteByteRegister(iop_base, IOPB_TICKLE,
6225 ADV_TICKLE_A);
6226 if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
6227 AdvWriteByteRegister(iop_base,
6228 IOPB_TICKLE,
6229 ADV_TICKLE_NOP);
6230 }
6231 }
6232 }
6233
6234 adv_async_callback(asc_dvc, intrb_code);
6235 }
6236
6237 /*
6238 * Check if the IRQ stopper carrier contains a completed request.
6239 */
6240 while (((irq_next_vpa =
6241 le32_to_cpu(asc_dvc->irq_sp->next_vpa)) & ASC_RQ_DONE) != 0) {
6242 /*
6243 * Get a pointer to the newly completed ADV_SCSI_REQ_Q structure.
6244 * The RISC will have set 'areq_vpa' to a virtual address.
6245 *
6246 * The firmware will have copied the ASC_SCSI_REQ_Q.scsiq_ptr
6247 * field to the carrier ADV_CARR_T.areq_vpa field. The conversion
6248 * below complements the conversion of ASC_SCSI_REQ_Q.scsiq_ptr'
6249 * in AdvExeScsiQueue().
6250 */
Hannes Reinecke4b47e462015-04-24 13:18:24 +02006251 u32 pa_offset = le32_to_cpu(asc_dvc->irq_sp->areq_vpa);
6252 ASC_DBG(1, "irq_sp %p areq_vpa %u\n",
6253 asc_dvc->irq_sp, pa_offset);
6254 reqp = adv_get_reqp(asc_dvc, pa_offset);
6255 scsiq = &reqp->scsi_req_q;
Matthew Wilcox51219352007-10-02 21:55:22 -04006256
6257 /*
6258 * Request finished with good status and the queue was not
6259 * DMAed to host memory by the firmware. Set all status fields
6260 * to indicate good status.
6261 */
6262 if ((irq_next_vpa & ASC_RQ_GOOD) != 0) {
6263 scsiq->done_status = QD_NO_ERROR;
6264 scsiq->host_status = scsiq->scsi_status = 0;
6265 scsiq->data_cnt = 0L;
6266 }
6267
6268 /*
6269 * Advance the stopper pointer to the next carrier
6270 * ignoring the lower four bits. Free the previous
6271 * stopper carrier.
6272 */
6273 free_carrp = asc_dvc->irq_sp;
Hannes Reinecke98b96a72015-04-24 13:18:23 +02006274 asc_dvc->irq_sp = adv_get_carrier(asc_dvc,
6275 ASC_GET_CARRP(irq_next_vpa));
Matthew Wilcox51219352007-10-02 21:55:22 -04006276
Hannes Reinecke98b96a72015-04-24 13:18:23 +02006277 free_carrp->next_vpa = asc_dvc->carr_freelist->carr_va;
Matthew Wilcox51219352007-10-02 21:55:22 -04006278 asc_dvc->carr_freelist = free_carrp;
6279 asc_dvc->carr_pending_cnt--;
6280
6281 target_bit = ADV_TID_TO_TIDMASK(scsiq->target_id);
6282
6283 /*
6284 * Clear request microcode control flag.
6285 */
6286 scsiq->cntl = 0;
6287
6288 /*
6289 * Notify the driver of the completed request by passing
6290 * the ADV_SCSI_REQ_Q pointer to its callback function.
6291 */
6292 scsiq->a_flag |= ADV_SCSIQ_DONE;
6293 adv_isr_callback(asc_dvc, scsiq);
6294 /*
6295 * Note: After the driver callback function is called, 'scsiq'
6296 * can no longer be referenced.
6297 *
6298 * Fall through and continue processing other completed
6299 * requests...
6300 */
6301 }
6302 return ADV_TRUE;
6303}
6304
6305static int AscSetLibErrorCode(ASC_DVC_VAR *asc_dvc, ushort err_code)
6306{
6307 if (asc_dvc->err_code == 0) {
6308 asc_dvc->err_code = err_code;
6309 AscWriteLramWord(asc_dvc->iop_base, ASCV_ASCDVC_ERR_CODE_W,
6310 err_code);
6311 }
6312 return err_code;
6313}
6314
6315static void AscAckInterrupt(PortAddr iop_base)
6316{
6317 uchar host_flag;
6318 uchar risc_flag;
6319 ushort loop;
6320
6321 loop = 0;
6322 do {
6323 risc_flag = AscReadLramByte(iop_base, ASCV_RISC_FLAG_B);
6324 if (loop++ > 0x7FFF) {
6325 break;
6326 }
6327 } while ((risc_flag & ASC_RISC_FLAG_GEN_INT) != 0);
6328 host_flag =
6329 AscReadLramByte(iop_base,
6330 ASCV_HOST_FLAG_B) & (~ASC_HOST_FLAG_ACK_INT);
6331 AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
6332 (uchar)(host_flag | ASC_HOST_FLAG_ACK_INT));
6333 AscSetChipStatus(iop_base, CIW_INT_ACK);
6334 loop = 0;
6335 while (AscGetChipStatus(iop_base) & CSW_INT_PENDING) {
6336 AscSetChipStatus(iop_base, CIW_INT_ACK);
6337 if (loop++ > 3) {
6338 break;
6339 }
6340 }
6341 AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
Matthew Wilcox51219352007-10-02 21:55:22 -04006342}
6343
6344static uchar AscGetSynPeriodIndex(ASC_DVC_VAR *asc_dvc, uchar syn_time)
6345{
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04006346 const uchar *period_table;
Matthew Wilcox51219352007-10-02 21:55:22 -04006347 int max_index;
6348 int min_index;
6349 int i;
6350
6351 period_table = asc_dvc->sdtr_period_tbl;
6352 max_index = (int)asc_dvc->max_sdtr_index;
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04006353 min_index = (int)asc_dvc->min_sdtr_index;
Matthew Wilcox51219352007-10-02 21:55:22 -04006354 if ((syn_time <= period_table[max_index])) {
6355 for (i = min_index; i < (max_index - 1); i++) {
6356 if (syn_time <= period_table[i]) {
6357 return (uchar)i;
6358 }
6359 }
6360 return (uchar)max_index;
6361 } else {
6362 return (uchar)(max_index + 1);
6363 }
6364}
6365
6366static uchar
6367AscMsgOutSDTR(ASC_DVC_VAR *asc_dvc, uchar sdtr_period, uchar sdtr_offset)
6368{
6369 EXT_MSG sdtr_buf;
6370 uchar sdtr_period_index;
6371 PortAddr iop_base;
6372
6373 iop_base = asc_dvc->iop_base;
6374 sdtr_buf.msg_type = EXTENDED_MESSAGE;
6375 sdtr_buf.msg_len = MS_SDTR_LEN;
6376 sdtr_buf.msg_req = EXTENDED_SDTR;
6377 sdtr_buf.xfer_period = sdtr_period;
6378 sdtr_offset &= ASC_SYN_MAX_OFFSET;
6379 sdtr_buf.req_ack_offset = sdtr_offset;
6380 sdtr_period_index = AscGetSynPeriodIndex(asc_dvc, sdtr_period);
6381 if (sdtr_period_index <= asc_dvc->max_sdtr_index) {
6382 AscMemWordCopyPtrToLram(iop_base, ASCV_MSGOUT_BEG,
6383 (uchar *)&sdtr_buf,
6384 sizeof(EXT_MSG) >> 1);
6385 return ((sdtr_period_index << 4) | sdtr_offset);
6386 } else {
6387 sdtr_buf.req_ack_offset = 0;
6388 AscMemWordCopyPtrToLram(iop_base, ASCV_MSGOUT_BEG,
6389 (uchar *)&sdtr_buf,
6390 sizeof(EXT_MSG) >> 1);
6391 return 0;
6392 }
6393}
6394
6395static uchar
6396AscCalSDTRData(ASC_DVC_VAR *asc_dvc, uchar sdtr_period, uchar syn_offset)
6397{
6398 uchar byte;
6399 uchar sdtr_period_ix;
6400
6401 sdtr_period_ix = AscGetSynPeriodIndex(asc_dvc, sdtr_period);
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04006402 if (sdtr_period_ix > asc_dvc->max_sdtr_index)
Matthew Wilcox51219352007-10-02 21:55:22 -04006403 return 0xFF;
Matthew Wilcox51219352007-10-02 21:55:22 -04006404 byte = (sdtr_period_ix << 4) | (syn_offset & ASC_SYN_MAX_OFFSET);
6405 return byte;
6406}
6407
Hannes Reinecked647c782015-04-24 13:18:26 +02006408static bool AscSetChipSynRegAtID(PortAddr iop_base, uchar id, uchar sdtr_data)
Matthew Wilcox51219352007-10-02 21:55:22 -04006409{
6410 ASC_SCSI_BIT_ID_TYPE org_id;
6411 int i;
Hannes Reinecked647c782015-04-24 13:18:26 +02006412 bool sta = true;
Matthew Wilcox51219352007-10-02 21:55:22 -04006413
6414 AscSetBank(iop_base, 1);
6415 org_id = AscReadChipDvcID(iop_base);
6416 for (i = 0; i <= ASC_MAX_TID; i++) {
6417 if (org_id == (0x01 << i))
6418 break;
6419 }
6420 org_id = (ASC_SCSI_BIT_ID_TYPE) i;
6421 AscWriteChipDvcID(iop_base, id);
6422 if (AscReadChipDvcID(iop_base) == (0x01 << id)) {
6423 AscSetBank(iop_base, 0);
6424 AscSetChipSyn(iop_base, sdtr_data);
6425 if (AscGetChipSyn(iop_base) != sdtr_data) {
Hannes Reinecked647c782015-04-24 13:18:26 +02006426 sta = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04006427 }
6428 } else {
Hannes Reinecked647c782015-04-24 13:18:26 +02006429 sta = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04006430 }
6431 AscSetBank(iop_base, 1);
6432 AscWriteChipDvcID(iop_base, org_id);
6433 AscSetBank(iop_base, 0);
6434 return (sta);
6435}
6436
6437static void AscSetChipSDTR(PortAddr iop_base, uchar sdtr_data, uchar tid_no)
6438{
6439 AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
6440 AscPutMCodeSDTRDoneAtID(iop_base, tid_no, sdtr_data);
6441}
6442
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006443static void AscIsrChipHalted(ASC_DVC_VAR *asc_dvc)
Matthew Wilcox51219352007-10-02 21:55:22 -04006444{
6445 EXT_MSG ext_msg;
6446 EXT_MSG out_msg;
6447 ushort halt_q_addr;
Hannes Reineckeae267592015-04-24 13:18:28 +02006448 bool sdtr_accept;
Matthew Wilcox51219352007-10-02 21:55:22 -04006449 ushort int_halt_code;
6450 ASC_SCSI_BIT_ID_TYPE scsi_busy;
6451 ASC_SCSI_BIT_ID_TYPE target_id;
6452 PortAddr iop_base;
6453 uchar tag_code;
6454 uchar q_status;
6455 uchar halt_qp;
6456 uchar sdtr_data;
6457 uchar target_ix;
6458 uchar q_cntl, tid_no;
6459 uchar cur_dvc_qng;
6460 uchar asyn_sdtr;
6461 uchar scsi_status;
Matthew Wilcoxd2411492007-10-02 21:55:31 -04006462 struct asc_board *boardp;
Matthew Wilcox51219352007-10-02 21:55:22 -04006463
6464 BUG_ON(!asc_dvc->drv_ptr);
6465 boardp = asc_dvc->drv_ptr;
6466
6467 iop_base = asc_dvc->iop_base;
6468 int_halt_code = AscReadLramWord(iop_base, ASCV_HALTCODE_W);
6469
6470 halt_qp = AscReadLramByte(iop_base, ASCV_CURCDB_B);
6471 halt_q_addr = ASC_QNO_TO_QADDR(halt_qp);
6472 target_ix = AscReadLramByte(iop_base,
6473 (ushort)(halt_q_addr +
6474 (ushort)ASC_SCSIQ_B_TARGET_IX));
6475 q_cntl = AscReadLramByte(iop_base,
6476 (ushort)(halt_q_addr + (ushort)ASC_SCSIQ_B_CNTL));
6477 tid_no = ASC_TIX_TO_TID(target_ix);
6478 target_id = (uchar)ASC_TID_TO_TARGET_ID(tid_no);
6479 if (asc_dvc->pci_fix_asyn_xfer & target_id) {
6480 asyn_sdtr = ASYN_SDTR_DATA_FIX_PCI_REV_AB;
6481 } else {
6482 asyn_sdtr = 0;
6483 }
6484 if (int_halt_code == ASC_HALT_DISABLE_ASYN_USE_SYN_FIX) {
6485 if (asc_dvc->pci_fix_asyn_xfer & target_id) {
6486 AscSetChipSDTR(iop_base, 0, tid_no);
6487 boardp->sdtr_data[tid_no] = 0;
6488 }
6489 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006490 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006491 } else if (int_halt_code == ASC_HALT_ENABLE_ASYN_USE_SYN_FIX) {
6492 if (asc_dvc->pci_fix_asyn_xfer & target_id) {
6493 AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
6494 boardp->sdtr_data[tid_no] = asyn_sdtr;
6495 }
6496 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006497 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006498 } else if (int_halt_code == ASC_HALT_EXTMSG_IN) {
6499 AscMemWordCopyPtrFromLram(iop_base,
6500 ASCV_MSGIN_BEG,
6501 (uchar *)&ext_msg,
6502 sizeof(EXT_MSG) >> 1);
6503
6504 if (ext_msg.msg_type == EXTENDED_MESSAGE &&
6505 ext_msg.msg_req == EXTENDED_SDTR &&
6506 ext_msg.msg_len == MS_SDTR_LEN) {
Hannes Reineckeae267592015-04-24 13:18:28 +02006507 sdtr_accept = true;
Matthew Wilcox51219352007-10-02 21:55:22 -04006508 if ((ext_msg.req_ack_offset > ASC_SYN_MAX_OFFSET)) {
6509
Hannes Reineckeae267592015-04-24 13:18:28 +02006510 sdtr_accept = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04006511 ext_msg.req_ack_offset = ASC_SYN_MAX_OFFSET;
6512 }
6513 if ((ext_msg.xfer_period <
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04006514 asc_dvc->sdtr_period_tbl[asc_dvc->min_sdtr_index])
Matthew Wilcox51219352007-10-02 21:55:22 -04006515 || (ext_msg.xfer_period >
6516 asc_dvc->sdtr_period_tbl[asc_dvc->
6517 max_sdtr_index])) {
Hannes Reineckeae267592015-04-24 13:18:28 +02006518 sdtr_accept = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04006519 ext_msg.xfer_period =
6520 asc_dvc->sdtr_period_tbl[asc_dvc->
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04006521 min_sdtr_index];
Matthew Wilcox51219352007-10-02 21:55:22 -04006522 }
6523 if (sdtr_accept) {
6524 sdtr_data =
6525 AscCalSDTRData(asc_dvc, ext_msg.xfer_period,
6526 ext_msg.req_ack_offset);
6527 if ((sdtr_data == 0xFF)) {
6528
6529 q_cntl |= QC_MSG_OUT;
6530 asc_dvc->init_sdtr &= ~target_id;
6531 asc_dvc->sdtr_done &= ~target_id;
6532 AscSetChipSDTR(iop_base, asyn_sdtr,
6533 tid_no);
6534 boardp->sdtr_data[tid_no] = asyn_sdtr;
6535 }
6536 }
6537 if (ext_msg.req_ack_offset == 0) {
6538
6539 q_cntl &= ~QC_MSG_OUT;
6540 asc_dvc->init_sdtr &= ~target_id;
6541 asc_dvc->sdtr_done &= ~target_id;
6542 AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
6543 } else {
6544 if (sdtr_accept && (q_cntl & QC_MSG_OUT)) {
Matthew Wilcox51219352007-10-02 21:55:22 -04006545 q_cntl &= ~QC_MSG_OUT;
6546 asc_dvc->sdtr_done |= target_id;
6547 asc_dvc->init_sdtr |= target_id;
6548 asc_dvc->pci_fix_asyn_xfer &=
6549 ~target_id;
6550 sdtr_data =
6551 AscCalSDTRData(asc_dvc,
6552 ext_msg.xfer_period,
6553 ext_msg.
6554 req_ack_offset);
6555 AscSetChipSDTR(iop_base, sdtr_data,
6556 tid_no);
6557 boardp->sdtr_data[tid_no] = sdtr_data;
6558 } else {
Matthew Wilcox51219352007-10-02 21:55:22 -04006559 q_cntl |= QC_MSG_OUT;
6560 AscMsgOutSDTR(asc_dvc,
6561 ext_msg.xfer_period,
6562 ext_msg.req_ack_offset);
6563 asc_dvc->pci_fix_asyn_xfer &=
6564 ~target_id;
6565 sdtr_data =
6566 AscCalSDTRData(asc_dvc,
6567 ext_msg.xfer_period,
6568 ext_msg.
6569 req_ack_offset);
6570 AscSetChipSDTR(iop_base, sdtr_data,
6571 tid_no);
6572 boardp->sdtr_data[tid_no] = sdtr_data;
6573 asc_dvc->sdtr_done |= target_id;
6574 asc_dvc->init_sdtr |= target_id;
6575 }
6576 }
6577
6578 AscWriteLramByte(iop_base,
6579 (ushort)(halt_q_addr +
6580 (ushort)ASC_SCSIQ_B_CNTL),
6581 q_cntl);
6582 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006583 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006584 } else if (ext_msg.msg_type == EXTENDED_MESSAGE &&
6585 ext_msg.msg_req == EXTENDED_WDTR &&
6586 ext_msg.msg_len == MS_WDTR_LEN) {
6587
6588 ext_msg.wdtr_width = 0;
6589 AscMemWordCopyPtrToLram(iop_base,
6590 ASCV_MSGOUT_BEG,
6591 (uchar *)&ext_msg,
6592 sizeof(EXT_MSG) >> 1);
6593 q_cntl |= QC_MSG_OUT;
6594 AscWriteLramByte(iop_base,
6595 (ushort)(halt_q_addr +
6596 (ushort)ASC_SCSIQ_B_CNTL),
6597 q_cntl);
6598 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006599 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006600 } else {
6601
6602 ext_msg.msg_type = MESSAGE_REJECT;
6603 AscMemWordCopyPtrToLram(iop_base,
6604 ASCV_MSGOUT_BEG,
6605 (uchar *)&ext_msg,
6606 sizeof(EXT_MSG) >> 1);
6607 q_cntl |= QC_MSG_OUT;
6608 AscWriteLramByte(iop_base,
6609 (ushort)(halt_q_addr +
6610 (ushort)ASC_SCSIQ_B_CNTL),
6611 q_cntl);
6612 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006613 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006614 }
6615 } else if (int_halt_code == ASC_HALT_CHK_CONDITION) {
6616
6617 q_cntl |= QC_REQ_SENSE;
6618
6619 if ((asc_dvc->init_sdtr & target_id) != 0) {
6620
6621 asc_dvc->sdtr_done &= ~target_id;
6622
6623 sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
6624 q_cntl |= QC_MSG_OUT;
6625 AscMsgOutSDTR(asc_dvc,
6626 asc_dvc->
6627 sdtr_period_tbl[(sdtr_data >> 4) &
6628 (uchar)(asc_dvc->
6629 max_sdtr_index -
6630 1)],
6631 (uchar)(sdtr_data & (uchar)
6632 ASC_SYN_MAX_OFFSET));
6633 }
6634
6635 AscWriteLramByte(iop_base,
6636 (ushort)(halt_q_addr +
6637 (ushort)ASC_SCSIQ_B_CNTL), q_cntl);
6638
6639 tag_code = AscReadLramByte(iop_base,
6640 (ushort)(halt_q_addr + (ushort)
6641 ASC_SCSIQ_B_TAG_CODE));
6642 tag_code &= 0xDC;
6643 if ((asc_dvc->pci_fix_asyn_xfer & target_id)
6644 && !(asc_dvc->pci_fix_asyn_xfer_always & target_id)
6645 ) {
6646
6647 tag_code |= (ASC_TAG_FLAG_DISABLE_DISCONNECT
6648 | ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX);
6649
6650 }
6651 AscWriteLramByte(iop_base,
6652 (ushort)(halt_q_addr +
6653 (ushort)ASC_SCSIQ_B_TAG_CODE),
6654 tag_code);
6655
6656 q_status = AscReadLramByte(iop_base,
6657 (ushort)(halt_q_addr + (ushort)
6658 ASC_SCSIQ_B_STATUS));
6659 q_status |= (QS_READY | QS_BUSY);
6660 AscWriteLramByte(iop_base,
6661 (ushort)(halt_q_addr +
6662 (ushort)ASC_SCSIQ_B_STATUS),
6663 q_status);
6664
6665 scsi_busy = AscReadLramByte(iop_base, (ushort)ASCV_SCSIBUSY_B);
6666 scsi_busy &= ~target_id;
6667 AscWriteLramByte(iop_base, (ushort)ASCV_SCSIBUSY_B, scsi_busy);
6668
6669 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006670 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006671 } else if (int_halt_code == ASC_HALT_SDTR_REJECTED) {
6672
6673 AscMemWordCopyPtrFromLram(iop_base,
6674 ASCV_MSGOUT_BEG,
6675 (uchar *)&out_msg,
6676 sizeof(EXT_MSG) >> 1);
6677
6678 if ((out_msg.msg_type == EXTENDED_MESSAGE) &&
6679 (out_msg.msg_len == MS_SDTR_LEN) &&
6680 (out_msg.msg_req == EXTENDED_SDTR)) {
6681
6682 asc_dvc->init_sdtr &= ~target_id;
6683 asc_dvc->sdtr_done &= ~target_id;
6684 AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
6685 boardp->sdtr_data[tid_no] = asyn_sdtr;
6686 }
6687 q_cntl &= ~QC_MSG_OUT;
6688 AscWriteLramByte(iop_base,
6689 (ushort)(halt_q_addr +
6690 (ushort)ASC_SCSIQ_B_CNTL), q_cntl);
6691 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006692 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006693 } else if (int_halt_code == ASC_HALT_SS_QUEUE_FULL) {
6694
6695 scsi_status = AscReadLramByte(iop_base,
6696 (ushort)((ushort)halt_q_addr +
6697 (ushort)
6698 ASC_SCSIQ_SCSI_STATUS));
6699 cur_dvc_qng =
6700 AscReadLramByte(iop_base,
6701 (ushort)((ushort)ASC_QADR_BEG +
6702 (ushort)target_ix));
6703 if ((cur_dvc_qng > 0) && (asc_dvc->cur_dvc_qng[tid_no] > 0)) {
6704
6705 scsi_busy = AscReadLramByte(iop_base,
6706 (ushort)ASCV_SCSIBUSY_B);
6707 scsi_busy |= target_id;
6708 AscWriteLramByte(iop_base,
6709 (ushort)ASCV_SCSIBUSY_B, scsi_busy);
6710 asc_dvc->queue_full_or_busy |= target_id;
6711
6712 if (scsi_status == SAM_STAT_TASK_SET_FULL) {
6713 if (cur_dvc_qng > ASC_MIN_TAGGED_CMD) {
6714 cur_dvc_qng -= 1;
6715 asc_dvc->max_dvc_qng[tid_no] =
6716 cur_dvc_qng;
6717
6718 AscWriteLramByte(iop_base,
6719 (ushort)((ushort)
6720 ASCV_MAX_DVC_QNG_BEG
6721 + (ushort)
6722 tid_no),
6723 cur_dvc_qng);
6724
6725 /*
6726 * Set the device queue depth to the
6727 * number of active requests when the
6728 * QUEUE FULL condition was encountered.
6729 */
6730 boardp->queue_full |= target_id;
6731 boardp->queue_full_cnt[tid_no] =
6732 cur_dvc_qng;
6733 }
6734 }
6735 }
6736 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006737 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006738 }
6739#if CC_VERY_LONG_SG_LIST
6740 else if (int_halt_code == ASC_HALT_HOST_COPY_SG_LIST_TO_RISC) {
6741 uchar q_no;
6742 ushort q_addr;
6743 uchar sg_wk_q_no;
6744 uchar first_sg_wk_q_no;
6745 ASC_SCSI_Q *scsiq; /* Ptr to driver request. */
6746 ASC_SG_HEAD *sg_head; /* Ptr to driver SG request. */
6747 ASC_SG_LIST_Q scsi_sg_q; /* Structure written to queue. */
6748 ushort sg_list_dwords;
6749 ushort sg_entry_cnt;
6750 uchar next_qp;
6751 int i;
6752
6753 q_no = AscReadLramByte(iop_base, (ushort)ASCV_REQ_SG_LIST_QP);
6754 if (q_no == ASC_QLINK_END)
6755 return 0;
6756
6757 q_addr = ASC_QNO_TO_QADDR(q_no);
6758
6759 /*
6760 * Convert the request's SRB pointer to a host ASC_SCSI_REQ
6761 * structure pointer using a macro provided by the driver.
6762 * The ASC_SCSI_REQ pointer provides a pointer to the
6763 * host ASC_SG_HEAD structure.
6764 */
6765 /* Read request's SRB pointer. */
6766 scsiq = (ASC_SCSI_Q *)
6767 ASC_SRB2SCSIQ(ASC_U32_TO_VADDR(AscReadLramDWord(iop_base,
6768 (ushort)
6769 (q_addr +
6770 ASC_SCSIQ_D_SRBPTR))));
6771
6772 /*
6773 * Get request's first and working SG queue.
6774 */
6775 sg_wk_q_no = AscReadLramByte(iop_base,
6776 (ushort)(q_addr +
6777 ASC_SCSIQ_B_SG_WK_QP));
6778
6779 first_sg_wk_q_no = AscReadLramByte(iop_base,
6780 (ushort)(q_addr +
6781 ASC_SCSIQ_B_FIRST_SG_WK_QP));
6782
6783 /*
6784 * Reset request's working SG queue back to the
6785 * first SG queue.
6786 */
6787 AscWriteLramByte(iop_base,
6788 (ushort)(q_addr +
6789 (ushort)ASC_SCSIQ_B_SG_WK_QP),
6790 first_sg_wk_q_no);
6791
6792 sg_head = scsiq->sg_head;
6793
6794 /*
6795 * Set sg_entry_cnt to the number of SG elements
6796 * that will be completed on this interrupt.
6797 *
6798 * Note: The allocated SG queues contain ASC_MAX_SG_LIST - 1
6799 * SG elements. The data_cnt and data_addr fields which
6800 * add 1 to the SG element capacity are not used when
6801 * restarting SG handling after a halt.
6802 */
6803 if (scsiq->remain_sg_entry_cnt > (ASC_MAX_SG_LIST - 1)) {
6804 sg_entry_cnt = ASC_MAX_SG_LIST - 1;
6805
6806 /*
6807 * Keep track of remaining number of SG elements that
6808 * will need to be handled on the next interrupt.
6809 */
6810 scsiq->remain_sg_entry_cnt -= (ASC_MAX_SG_LIST - 1);
6811 } else {
6812 sg_entry_cnt = scsiq->remain_sg_entry_cnt;
6813 scsiq->remain_sg_entry_cnt = 0;
6814 }
6815
6816 /*
6817 * Copy SG elements into the list of allocated SG queues.
6818 *
6819 * Last index completed is saved in scsiq->next_sg_index.
6820 */
6821 next_qp = first_sg_wk_q_no;
6822 q_addr = ASC_QNO_TO_QADDR(next_qp);
6823 scsi_sg_q.sg_head_qp = q_no;
6824 scsi_sg_q.cntl = QCSG_SG_XFER_LIST;
6825 for (i = 0; i < sg_head->queue_cnt; i++) {
6826 scsi_sg_q.seq_no = i + 1;
6827 if (sg_entry_cnt > ASC_SG_LIST_PER_Q) {
6828 sg_list_dwords = (uchar)(ASC_SG_LIST_PER_Q * 2);
6829 sg_entry_cnt -= ASC_SG_LIST_PER_Q;
6830 /*
6831 * After very first SG queue RISC FW uses next
6832 * SG queue first element then checks sg_list_cnt
6833 * against zero and then decrements, so set
6834 * sg_list_cnt 1 less than number of SG elements
6835 * in each SG queue.
6836 */
6837 scsi_sg_q.sg_list_cnt = ASC_SG_LIST_PER_Q - 1;
6838 scsi_sg_q.sg_cur_list_cnt =
6839 ASC_SG_LIST_PER_Q - 1;
6840 } else {
6841 /*
6842 * This is the last SG queue in the list of
6843 * allocated SG queues. If there are more
6844 * SG elements than will fit in the allocated
6845 * queues, then set the QCSG_SG_XFER_MORE flag.
6846 */
6847 if (scsiq->remain_sg_entry_cnt != 0) {
6848 scsi_sg_q.cntl |= QCSG_SG_XFER_MORE;
6849 } else {
6850 scsi_sg_q.cntl |= QCSG_SG_XFER_END;
6851 }
6852 /* equals sg_entry_cnt * 2 */
6853 sg_list_dwords = sg_entry_cnt << 1;
6854 scsi_sg_q.sg_list_cnt = sg_entry_cnt - 1;
6855 scsi_sg_q.sg_cur_list_cnt = sg_entry_cnt - 1;
6856 sg_entry_cnt = 0;
6857 }
6858
6859 scsi_sg_q.q_no = next_qp;
6860 AscMemWordCopyPtrToLram(iop_base,
6861 q_addr + ASC_SCSIQ_SGHD_CPY_BEG,
6862 (uchar *)&scsi_sg_q,
6863 sizeof(ASC_SG_LIST_Q) >> 1);
6864
6865 AscMemDWordCopyPtrToLram(iop_base,
6866 q_addr + ASC_SGQ_LIST_BEG,
6867 (uchar *)&sg_head->
6868 sg_list[scsiq->next_sg_index],
6869 sg_list_dwords);
6870
6871 scsiq->next_sg_index += ASC_SG_LIST_PER_Q;
6872
6873 /*
6874 * If the just completed SG queue contained the
6875 * last SG element, then no more SG queues need
6876 * to be written.
6877 */
6878 if (scsi_sg_q.cntl & QCSG_SG_XFER_END) {
6879 break;
6880 }
6881
6882 next_qp = AscReadLramByte(iop_base,
6883 (ushort)(q_addr +
6884 ASC_SCSIQ_B_FWD));
6885 q_addr = ASC_QNO_TO_QADDR(next_qp);
6886 }
6887
6888 /*
6889 * Clear the halt condition so the RISC will be restarted
6890 * after the return.
6891 */
6892 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006893 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006894 }
6895#endif /* CC_VERY_LONG_SG_LIST */
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006896 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006897}
6898
6899/*
6900 * void
6901 * DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
6902 *
6903 * Calling/Exit State:
6904 * none
6905 *
6906 * Description:
6907 * Input an ASC_QDONE_INFO structure from the chip
6908 */
6909static void
6910DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
6911{
6912 int i;
6913 ushort word;
6914
6915 AscSetChipLramAddr(iop_base, s_addr);
6916 for (i = 0; i < 2 * words; i += 2) {
6917 if (i == 10) {
6918 continue;
6919 }
6920 word = inpw(iop_base + IOP_RAM_DATA);
6921 inbuf[i] = word & 0xff;
6922 inbuf[i + 1] = (word >> 8) & 0xff;
6923 }
6924 ASC_DBG_PRT_HEX(2, "DvcGetQinfo", inbuf, 2 * words);
6925}
6926
6927static uchar
6928_AscCopyLramScsiDoneQ(PortAddr iop_base,
6929 ushort q_addr,
Hannes Reinecke95cfab62015-04-24 13:18:27 +02006930 ASC_QDONE_INFO *scsiq, unsigned int max_dma_count)
Matthew Wilcox51219352007-10-02 21:55:22 -04006931{
6932 ushort _val;
6933 uchar sg_queue_cnt;
6934
6935 DvcGetQinfo(iop_base,
6936 q_addr + ASC_SCSIQ_DONE_INFO_BEG,
6937 (uchar *)scsiq,
6938 (sizeof(ASC_SCSIQ_2) + sizeof(ASC_SCSIQ_3)) / 2);
6939
6940 _val = AscReadLramWord(iop_base,
6941 (ushort)(q_addr + (ushort)ASC_SCSIQ_B_STATUS));
6942 scsiq->q_status = (uchar)_val;
6943 scsiq->q_no = (uchar)(_val >> 8);
6944 _val = AscReadLramWord(iop_base,
6945 (ushort)(q_addr + (ushort)ASC_SCSIQ_B_CNTL));
6946 scsiq->cntl = (uchar)_val;
6947 sg_queue_cnt = (uchar)(_val >> 8);
6948 _val = AscReadLramWord(iop_base,
6949 (ushort)(q_addr +
6950 (ushort)ASC_SCSIQ_B_SENSE_LEN));
6951 scsiq->sense_len = (uchar)_val;
6952 scsiq->extra_bytes = (uchar)(_val >> 8);
6953
6954 /*
6955 * Read high word of remain bytes from alternate location.
6956 */
Hannes Reinecke95cfab62015-04-24 13:18:27 +02006957 scsiq->remain_bytes = (((u32)AscReadLramWord(iop_base,
6958 (ushort)(q_addr +
6959 (ushort)
6960 ASC_SCSIQ_W_ALT_DC1)))
Matthew Wilcox51219352007-10-02 21:55:22 -04006961 << 16);
6962 /*
6963 * Read low word of remain bytes from original location.
6964 */
6965 scsiq->remain_bytes += AscReadLramWord(iop_base,
6966 (ushort)(q_addr + (ushort)
6967 ASC_SCSIQ_DW_REMAIN_XFER_CNT));
6968
6969 scsiq->remain_bytes &= max_dma_count;
6970 return sg_queue_cnt;
6971}
6972
6973/*
6974 * asc_isr_callback() - Second Level Interrupt Handler called by AscISR().
6975 *
6976 * Interrupt callback function for the Narrow SCSI Asc Library.
6977 */
6978static void asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep)
6979{
Hannes Reinecke9c17c622015-04-24 13:18:21 +02006980 struct asc_board *boardp = asc_dvc_varp->drv_ptr;
6981 u32 srb_tag;
Matthew Wilcox51219352007-10-02 21:55:22 -04006982 struct scsi_cmnd *scp;
Matthew Wilcox51219352007-10-02 21:55:22 -04006983
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006984 ASC_DBG(1, "asc_dvc_varp 0x%p, qdonep 0x%p\n", asc_dvc_varp, qdonep);
Matthew Wilcox51219352007-10-02 21:55:22 -04006985 ASC_DBG_PRT_ASC_QDONE_INFO(2, qdonep);
6986
Hannes Reinecke9c17c622015-04-24 13:18:21 +02006987 /*
6988 * Decrease the srb_tag by 1 to find the SCSI command
6989 */
6990 srb_tag = qdonep->d2.srb_tag - 1;
6991 scp = scsi_host_find_tag(boardp->shost, srb_tag);
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04006992 if (!scp)
Matthew Wilcox51219352007-10-02 21:55:22 -04006993 return;
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04006994
Matthew Wilcox51219352007-10-02 21:55:22 -04006995 ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
6996
Hannes Reinecke9c17c622015-04-24 13:18:21 +02006997 ASC_STATS(boardp->shost, callback);
Matthew Wilcox51219352007-10-02 21:55:22 -04006998
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04006999 dma_unmap_single(boardp->dev, scp->SCp.dma_handle,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09007000 SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
Matthew Wilcox51219352007-10-02 21:55:22 -04007001 /*
7002 * 'qdonep' contains the command's ending status.
7003 */
7004 switch (qdonep->d3.done_stat) {
7005 case QD_NO_ERROR:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007006 ASC_DBG(2, "QD_NO_ERROR\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007007 scp->result = 0;
7008
7009 /*
7010 * Check for an underrun condition.
7011 *
7012 * If there was no error and an underrun condition, then
7013 * return the number of underrun bytes.
7014 */
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007015 if (scsi_bufflen(scp) != 0 && qdonep->remain_bytes != 0 &&
7016 qdonep->remain_bytes <= scsi_bufflen(scp)) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007017 ASC_DBG(1, "underrun condition %u bytes\n",
Matthew Wilcox51219352007-10-02 21:55:22 -04007018 (unsigned)qdonep->remain_bytes);
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007019 scsi_set_resid(scp, qdonep->remain_bytes);
Matthew Wilcox51219352007-10-02 21:55:22 -04007020 }
7021 break;
7022
7023 case QD_WITH_ERROR:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007024 ASC_DBG(2, "QD_WITH_ERROR\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007025 switch (qdonep->d3.host_stat) {
7026 case QHSTA_NO_ERROR:
7027 if (qdonep->d3.scsi_stat == SAM_STAT_CHECK_CONDITION) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007028 ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007029 ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09007030 SCSI_SENSE_BUFFERSIZE);
Matthew Wilcox51219352007-10-02 21:55:22 -04007031 /*
7032 * Note: The 'status_byte()' macro used by
7033 * target drivers defined in scsi.h shifts the
7034 * status byte returned by host drivers right
7035 * by 1 bit. This is why target drivers also
7036 * use right shifted status byte definitions.
7037 * For instance target drivers use
7038 * CHECK_CONDITION, defined to 0x1, instead of
7039 * the SCSI defined check condition value of
7040 * 0x2. Host drivers are supposed to return
7041 * the status byte as it is defined by SCSI.
7042 */
7043 scp->result = DRIVER_BYTE(DRIVER_SENSE) |
7044 STATUS_BYTE(qdonep->d3.scsi_stat);
7045 } else {
7046 scp->result = STATUS_BYTE(qdonep->d3.scsi_stat);
7047 }
7048 break;
7049
7050 default:
7051 /* QHSTA error occurred */
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007052 ASC_DBG(1, "host_stat 0x%x\n", qdonep->d3.host_stat);
Matthew Wilcox51219352007-10-02 21:55:22 -04007053 scp->result = HOST_BYTE(DID_BAD_TARGET);
7054 break;
7055 }
7056 break;
7057
7058 case QD_ABORTED_BY_HOST:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007059 ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007060 scp->result =
7061 HOST_BYTE(DID_ABORT) | MSG_BYTE(qdonep->d3.
7062 scsi_msg) |
7063 STATUS_BYTE(qdonep->d3.scsi_stat);
7064 break;
7065
7066 default:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007067 ASC_DBG(1, "done_stat 0x%x\n", qdonep->d3.done_stat);
Matthew Wilcox51219352007-10-02 21:55:22 -04007068 scp->result =
7069 HOST_BYTE(DID_ERROR) | MSG_BYTE(qdonep->d3.
7070 scsi_msg) |
7071 STATUS_BYTE(qdonep->d3.scsi_stat);
7072 break;
7073 }
7074
7075 /*
7076 * If the 'init_tidmask' bit isn't already set for the target and the
7077 * current request finished normally, then set the bit for the target
7078 * to indicate that a device is present.
7079 */
7080 if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
7081 qdonep->d3.done_stat == QD_NO_ERROR &&
7082 qdonep->d3.host_stat == QHSTA_NO_ERROR) {
7083 boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
7084 }
7085
7086 asc_scsi_done(scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04007087}
7088
7089static int AscIsrQDone(ASC_DVC_VAR *asc_dvc)
7090{
7091 uchar next_qp;
7092 uchar n_q_used;
7093 uchar sg_list_qp;
7094 uchar sg_queue_cnt;
7095 uchar q_cnt;
7096 uchar done_q_tail;
7097 uchar tid_no;
7098 ASC_SCSI_BIT_ID_TYPE scsi_busy;
7099 ASC_SCSI_BIT_ID_TYPE target_id;
7100 PortAddr iop_base;
7101 ushort q_addr;
7102 ushort sg_q_addr;
7103 uchar cur_target_qng;
7104 ASC_QDONE_INFO scsiq_buf;
7105 ASC_QDONE_INFO *scsiq;
Hannes Reineckeae267592015-04-24 13:18:28 +02007106 bool false_overrun;
Matthew Wilcox51219352007-10-02 21:55:22 -04007107
7108 iop_base = asc_dvc->iop_base;
7109 n_q_used = 1;
7110 scsiq = (ASC_QDONE_INFO *)&scsiq_buf;
7111 done_q_tail = (uchar)AscGetVarDoneQTail(iop_base);
7112 q_addr = ASC_QNO_TO_QADDR(done_q_tail);
7113 next_qp = AscReadLramByte(iop_base,
7114 (ushort)(q_addr + (ushort)ASC_SCSIQ_B_FWD));
7115 if (next_qp != ASC_QLINK_END) {
7116 AscPutVarDoneQTail(iop_base, next_qp);
7117 q_addr = ASC_QNO_TO_QADDR(next_qp);
7118 sg_queue_cnt = _AscCopyLramScsiDoneQ(iop_base, q_addr, scsiq,
7119 asc_dvc->max_dma_count);
7120 AscWriteLramByte(iop_base,
7121 (ushort)(q_addr +
7122 (ushort)ASC_SCSIQ_B_STATUS),
7123 (uchar)(scsiq->
7124 q_status & (uchar)~(QS_READY |
7125 QS_ABORTED)));
7126 tid_no = ASC_TIX_TO_TID(scsiq->d2.target_ix);
7127 target_id = ASC_TIX_TO_TARGET_ID(scsiq->d2.target_ix);
7128 if ((scsiq->cntl & QC_SG_HEAD) != 0) {
7129 sg_q_addr = q_addr;
7130 sg_list_qp = next_qp;
7131 for (q_cnt = 0; q_cnt < sg_queue_cnt; q_cnt++) {
7132 sg_list_qp = AscReadLramByte(iop_base,
7133 (ushort)(sg_q_addr
7134 + (ushort)
7135 ASC_SCSIQ_B_FWD));
7136 sg_q_addr = ASC_QNO_TO_QADDR(sg_list_qp);
7137 if (sg_list_qp == ASC_QLINK_END) {
7138 AscSetLibErrorCode(asc_dvc,
7139 ASCQ_ERR_SG_Q_LINKS);
7140 scsiq->d3.done_stat = QD_WITH_ERROR;
7141 scsiq->d3.host_stat =
7142 QHSTA_D_QDONE_SG_LIST_CORRUPTED;
7143 goto FATAL_ERR_QDONE;
7144 }
7145 AscWriteLramByte(iop_base,
7146 (ushort)(sg_q_addr + (ushort)
7147 ASC_SCSIQ_B_STATUS),
7148 QS_FREE);
7149 }
7150 n_q_used = sg_queue_cnt + 1;
7151 AscPutVarDoneQTail(iop_base, sg_list_qp);
7152 }
7153 if (asc_dvc->queue_full_or_busy & target_id) {
7154 cur_target_qng = AscReadLramByte(iop_base,
7155 (ushort)((ushort)
7156 ASC_QADR_BEG
7157 + (ushort)
7158 scsiq->d2.
7159 target_ix));
7160 if (cur_target_qng < asc_dvc->max_dvc_qng[tid_no]) {
7161 scsi_busy = AscReadLramByte(iop_base, (ushort)
7162 ASCV_SCSIBUSY_B);
7163 scsi_busy &= ~target_id;
7164 AscWriteLramByte(iop_base,
7165 (ushort)ASCV_SCSIBUSY_B,
7166 scsi_busy);
7167 asc_dvc->queue_full_or_busy &= ~target_id;
7168 }
7169 }
7170 if (asc_dvc->cur_total_qng >= n_q_used) {
7171 asc_dvc->cur_total_qng -= n_q_used;
7172 if (asc_dvc->cur_dvc_qng[tid_no] != 0) {
7173 asc_dvc->cur_dvc_qng[tid_no]--;
7174 }
7175 } else {
7176 AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CUR_QNG);
7177 scsiq->d3.done_stat = QD_WITH_ERROR;
7178 goto FATAL_ERR_QDONE;
7179 }
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007180 if ((scsiq->d2.srb_tag == 0UL) ||
Matthew Wilcox51219352007-10-02 21:55:22 -04007181 ((scsiq->q_status & QS_ABORTED) != 0)) {
7182 return (0x11);
7183 } else if (scsiq->q_status == QS_DONE) {
Hannes Reineckeae267592015-04-24 13:18:28 +02007184 /*
7185 * This is also curious.
7186 * false_overrun will _always_ be set to 'false'
7187 */
7188 false_overrun = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04007189 if (scsiq->extra_bytes != 0) {
Hannes Reinecke95cfab62015-04-24 13:18:27 +02007190 scsiq->remain_bytes += scsiq->extra_bytes;
Matthew Wilcox51219352007-10-02 21:55:22 -04007191 }
7192 if (scsiq->d3.done_stat == QD_WITH_ERROR) {
7193 if (scsiq->d3.host_stat ==
7194 QHSTA_M_DATA_OVER_RUN) {
7195 if ((scsiq->
7196 cntl & (QC_DATA_IN | QC_DATA_OUT))
7197 == 0) {
7198 scsiq->d3.done_stat =
7199 QD_NO_ERROR;
7200 scsiq->d3.host_stat =
7201 QHSTA_NO_ERROR;
7202 } else if (false_overrun) {
7203 scsiq->d3.done_stat =
7204 QD_NO_ERROR;
7205 scsiq->d3.host_stat =
7206 QHSTA_NO_ERROR;
7207 }
7208 } else if (scsiq->d3.host_stat ==
7209 QHSTA_M_HUNG_REQ_SCSI_BUS_RESET) {
7210 AscStopChip(iop_base);
7211 AscSetChipControl(iop_base,
7212 (uchar)(CC_SCSI_RESET
7213 | CC_HALT));
7214 udelay(60);
7215 AscSetChipControl(iop_base, CC_HALT);
7216 AscSetChipStatus(iop_base,
7217 CIW_CLR_SCSI_RESET_INT);
7218 AscSetChipStatus(iop_base, 0);
7219 AscSetChipControl(iop_base, 0);
7220 }
7221 }
7222 if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
7223 asc_isr_callback(asc_dvc, scsiq);
7224 } else {
7225 if ((AscReadLramByte(iop_base,
7226 (ushort)(q_addr + (ushort)
7227 ASC_SCSIQ_CDB_BEG))
7228 == START_STOP)) {
7229 asc_dvc->unit_not_ready &= ~target_id;
7230 if (scsiq->d3.done_stat != QD_NO_ERROR) {
7231 asc_dvc->start_motor &=
7232 ~target_id;
7233 }
7234 }
7235 }
7236 return (1);
7237 } else {
7238 AscSetLibErrorCode(asc_dvc, ASCQ_ERR_Q_STATUS);
7239 FATAL_ERR_QDONE:
7240 if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
7241 asc_isr_callback(asc_dvc, scsiq);
7242 }
7243 return (0x80);
7244 }
7245 }
7246 return (0);
7247}
7248
7249static int AscISR(ASC_DVC_VAR *asc_dvc)
7250{
7251 ASC_CS_TYPE chipstat;
7252 PortAddr iop_base;
7253 ushort saved_ram_addr;
7254 uchar ctrl_reg;
7255 uchar saved_ctrl_reg;
7256 int int_pending;
7257 int status;
7258 uchar host_flag;
7259
7260 iop_base = asc_dvc->iop_base;
Hannes Reineckeae267592015-04-24 13:18:28 +02007261 int_pending = ASC_FALSE;
Matthew Wilcox51219352007-10-02 21:55:22 -04007262
7263 if (AscIsIntPending(iop_base) == 0)
7264 return int_pending;
7265
7266 if ((asc_dvc->init_state & ASC_INIT_STATE_END_LOAD_MC) == 0) {
Hannes Reineckeae267592015-04-24 13:18:28 +02007267 return ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04007268 }
7269 if (asc_dvc->in_critical_cnt != 0) {
7270 AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_ON_CRITICAL);
Hannes Reineckeae267592015-04-24 13:18:28 +02007271 return ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04007272 }
7273 if (asc_dvc->is_in_int) {
7274 AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_RE_ENTRY);
Hannes Reineckeae267592015-04-24 13:18:28 +02007275 return ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04007276 }
Hannes Reineckeae267592015-04-24 13:18:28 +02007277 asc_dvc->is_in_int = true;
Matthew Wilcox51219352007-10-02 21:55:22 -04007278 ctrl_reg = AscGetChipControl(iop_base);
7279 saved_ctrl_reg = ctrl_reg & (~(CC_SCSI_RESET | CC_CHIP_RESET |
7280 CC_SINGLE_STEP | CC_DIAG | CC_TEST));
7281 chipstat = AscGetChipStatus(iop_base);
7282 if (chipstat & CSW_SCSI_RESET_LATCH) {
7283 if (!(asc_dvc->bus_type & (ASC_IS_VL | ASC_IS_EISA))) {
7284 int i = 10;
Hannes Reineckeae267592015-04-24 13:18:28 +02007285 int_pending = ASC_TRUE;
Matthew Wilcox51219352007-10-02 21:55:22 -04007286 asc_dvc->sdtr_done = 0;
7287 saved_ctrl_reg &= (uchar)(~CC_HALT);
7288 while ((AscGetChipStatus(iop_base) &
7289 CSW_SCSI_RESET_ACTIVE) && (i-- > 0)) {
7290 mdelay(100);
7291 }
7292 AscSetChipControl(iop_base, (CC_CHIP_RESET | CC_HALT));
7293 AscSetChipControl(iop_base, CC_HALT);
7294 AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
7295 AscSetChipStatus(iop_base, 0);
7296 chipstat = AscGetChipStatus(iop_base);
7297 }
7298 }
7299 saved_ram_addr = AscGetChipLramAddr(iop_base);
7300 host_flag = AscReadLramByte(iop_base,
7301 ASCV_HOST_FLAG_B) &
7302 (uchar)(~ASC_HOST_FLAG_IN_ISR);
7303 AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
7304 (uchar)(host_flag | (uchar)ASC_HOST_FLAG_IN_ISR));
7305 if ((chipstat & CSW_INT_PENDING) || (int_pending)) {
7306 AscAckInterrupt(iop_base);
Hannes Reineckeae267592015-04-24 13:18:28 +02007307 int_pending = ASC_TRUE;
Matthew Wilcox51219352007-10-02 21:55:22 -04007308 if ((chipstat & CSW_HALTED) && (ctrl_reg & CC_SINGLE_STEP)) {
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02007309 AscIsrChipHalted(asc_dvc);
7310 saved_ctrl_reg &= (uchar)(~CC_HALT);
Matthew Wilcox51219352007-10-02 21:55:22 -04007311 } else {
Matthew Wilcox51219352007-10-02 21:55:22 -04007312 if ((asc_dvc->dvc_cntl & ASC_CNTL_INT_MULTI_Q) != 0) {
7313 while (((status =
7314 AscIsrQDone(asc_dvc)) & 0x01) != 0) {
7315 }
7316 } else {
7317 do {
7318 if ((status =
7319 AscIsrQDone(asc_dvc)) == 1) {
7320 break;
7321 }
7322 } while (status == 0x11);
7323 }
7324 if ((status & 0x80) != 0)
Hannes Reineckeae267592015-04-24 13:18:28 +02007325 int_pending = ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04007326 }
7327 }
7328 AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
7329 AscSetChipLramAddr(iop_base, saved_ram_addr);
7330 AscSetChipControl(iop_base, saved_ctrl_reg);
Hannes Reineckeae267592015-04-24 13:18:28 +02007331 asc_dvc->is_in_int = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04007332 return int_pending;
7333}
7334
7335/*
7336 * advansys_reset()
7337 *
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007338 * Reset the host associated with the command 'scp'.
Matthew Wilcox51219352007-10-02 21:55:22 -04007339 *
7340 * This function runs its own thread. Interrupts must be blocked but
7341 * sleeping is allowed and no locking other than for host structures is
7342 * required. Returns SUCCESS or FAILED.
7343 */
7344static int advansys_reset(struct scsi_cmnd *scp)
7345{
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007346 struct Scsi_Host *shost = scp->device->host;
Matthew Wilcoxd2411492007-10-02 21:55:31 -04007347 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007348 unsigned long flags;
Matthew Wilcox51219352007-10-02 21:55:22 -04007349 int status;
7350 int ret = SUCCESS;
7351
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007352 ASC_DBG(1, "0x%p\n", scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04007353
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007354 ASC_STATS(shost, reset);
Matthew Wilcox51219352007-10-02 21:55:22 -04007355
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007356 scmd_printk(KERN_INFO, scp, "SCSI host reset started...\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007357
7358 if (ASC_NARROW_BOARD(boardp)) {
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007359 ASC_DVC_VAR *asc_dvc = &boardp->dvc_var.asc_dvc_var;
Matthew Wilcox51219352007-10-02 21:55:22 -04007360
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007361 /* Reset the chip and SCSI bus. */
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007362 ASC_DBG(1, "before AscInitAsc1000Driver()\n");
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007363 status = AscInitAsc1000Driver(asc_dvc);
Matthew Wilcox51219352007-10-02 21:55:22 -04007364
Adam Buchbinder6070d812009-12-04 15:47:01 -05007365 /* Refer to ASC_IERR_* definitions for meaning of 'err_code'. */
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -03007366 if (asc_dvc->err_code || !asc_dvc->overrun_dma) {
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007367 scmd_printk(KERN_INFO, scp, "SCSI host reset error: "
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -03007368 "0x%x, status: 0x%x\n", asc_dvc->err_code,
7369 status);
Matthew Wilcox51219352007-10-02 21:55:22 -04007370 ret = FAILED;
7371 } else if (status) {
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007372 scmd_printk(KERN_INFO, scp, "SCSI host reset warning: "
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007373 "0x%x\n", status);
Matthew Wilcox51219352007-10-02 21:55:22 -04007374 } else {
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007375 scmd_printk(KERN_INFO, scp, "SCSI host reset "
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007376 "successful\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007377 }
7378
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007379 ASC_DBG(1, "after AscInitAsc1000Driver()\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007380 } else {
7381 /*
Matthew Wilcox51219352007-10-02 21:55:22 -04007382 * If the suggest reset bus flags are set, then reset the bus.
7383 * Otherwise only reset the device.
7384 */
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007385 ADV_DVC_VAR *adv_dvc = &boardp->dvc_var.adv_dvc_var;
Matthew Wilcox51219352007-10-02 21:55:22 -04007386
7387 /*
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007388 * Reset the chip and SCSI bus.
Matthew Wilcox51219352007-10-02 21:55:22 -04007389 */
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007390 ASC_DBG(1, "before AdvResetChipAndSB()\n");
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007391 switch (AdvResetChipAndSB(adv_dvc)) {
Matthew Wilcox51219352007-10-02 21:55:22 -04007392 case ASC_TRUE:
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007393 scmd_printk(KERN_INFO, scp, "SCSI host reset "
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007394 "successful\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007395 break;
7396 case ASC_FALSE:
7397 default:
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007398 scmd_printk(KERN_INFO, scp, "SCSI host reset error\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007399 ret = FAILED;
7400 break;
7401 }
Matthew Wilcoxf092d222007-10-02 21:55:34 -04007402 spin_lock_irqsave(shost->host_lock, flags);
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007403 AdvISR(adv_dvc);
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007404 spin_unlock_irqrestore(shost->host_lock, flags);
Matthew Wilcox51219352007-10-02 21:55:22 -04007405 }
Matthew Wilcox51219352007-10-02 21:55:22 -04007406
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007407 ASC_DBG(1, "ret %d\n", ret);
Matthew Wilcox51219352007-10-02 21:55:22 -04007408
7409 return ret;
7410}
7411
7412/*
7413 * advansys_biosparam()
7414 *
7415 * Translate disk drive geometry if the "BIOS greater than 1 GB"
7416 * support is enabled for a drive.
7417 *
7418 * ip (information pointer) is an int array with the following definition:
7419 * ip[0]: heads
7420 * ip[1]: sectors
7421 * ip[2]: cylinders
7422 */
7423static int
7424advansys_biosparam(struct scsi_device *sdev, struct block_device *bdev,
7425 sector_t capacity, int ip[])
7426{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04007427 struct asc_board *boardp = shost_priv(sdev->host);
Matthew Wilcox51219352007-10-02 21:55:22 -04007428
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007429 ASC_DBG(1, "begin\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007430 ASC_STATS(sdev->host, biosparam);
Matthew Wilcox51219352007-10-02 21:55:22 -04007431 if (ASC_NARROW_BOARD(boardp)) {
7432 if ((boardp->dvc_var.asc_dvc_var.dvc_cntl &
7433 ASC_CNTL_BIOS_GT_1GB) && capacity > 0x200000) {
7434 ip[0] = 255;
7435 ip[1] = 63;
7436 } else {
7437 ip[0] = 64;
7438 ip[1] = 32;
7439 }
7440 } else {
7441 if ((boardp->dvc_var.adv_dvc_var.bios_ctrl &
7442 BIOS_CTRL_EXTENDED_XLAT) && capacity > 0x200000) {
7443 ip[0] = 255;
7444 ip[1] = 63;
7445 } else {
7446 ip[0] = 64;
7447 ip[1] = 32;
7448 }
7449 }
7450 ip[2] = (unsigned long)capacity / (ip[0] * ip[1]);
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007451 ASC_DBG(1, "end\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007452 return 0;
7453}
7454
7455/*
7456 * First-level interrupt handler.
7457 *
7458 * 'dev_id' is a pointer to the interrupting adapter's Scsi_Host.
7459 */
7460static irqreturn_t advansys_interrupt(int irq, void *dev_id)
7461{
Matthew Wilcox51219352007-10-02 21:55:22 -04007462 struct Scsi_Host *shost = dev_id;
Matthew Wilcoxd2411492007-10-02 21:55:31 -04007463 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox51219352007-10-02 21:55:22 -04007464 irqreturn_t result = IRQ_NONE;
7465
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007466 ASC_DBG(2, "boardp 0x%p\n", boardp);
Matthew Wilcoxf092d222007-10-02 21:55:34 -04007467 spin_lock(shost->host_lock);
Matthew Wilcox51219352007-10-02 21:55:22 -04007468 if (ASC_NARROW_BOARD(boardp)) {
7469 if (AscIsIntPending(shost->io_port)) {
7470 result = IRQ_HANDLED;
7471 ASC_STATS(shost, interrupt);
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007472 ASC_DBG(1, "before AscISR()\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007473 AscISR(&boardp->dvc_var.asc_dvc_var);
7474 }
7475 } else {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007476 ASC_DBG(1, "before AdvISR()\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007477 if (AdvISR(&boardp->dvc_var.adv_dvc_var)) {
7478 result = IRQ_HANDLED;
7479 ASC_STATS(shost, interrupt);
7480 }
7481 }
Matthew Wilcoxf092d222007-10-02 21:55:34 -04007482 spin_unlock(shost->host_lock);
Matthew Wilcox51219352007-10-02 21:55:22 -04007483
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007484 ASC_DBG(1, "end\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007485 return result;
7486}
7487
Hannes Reinecked647c782015-04-24 13:18:26 +02007488static bool AscHostReqRiscHalt(PortAddr iop_base)
Matthew Wilcox51219352007-10-02 21:55:22 -04007489{
7490 int count = 0;
Hannes Reinecked647c782015-04-24 13:18:26 +02007491 bool sta = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04007492 uchar saved_stop_code;
7493
7494 if (AscIsChipHalted(iop_base))
Hannes Reinecked647c782015-04-24 13:18:26 +02007495 return true;
Matthew Wilcox51219352007-10-02 21:55:22 -04007496 saved_stop_code = AscReadLramByte(iop_base, ASCV_STOP_CODE_B);
7497 AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
7498 ASC_STOP_HOST_REQ_RISC_HALT | ASC_STOP_REQ_RISC_STOP);
7499 do {
7500 if (AscIsChipHalted(iop_base)) {
Hannes Reinecked647c782015-04-24 13:18:26 +02007501 sta = true;
Matthew Wilcox51219352007-10-02 21:55:22 -04007502 break;
7503 }
7504 mdelay(100);
7505 } while (count++ < 20);
7506 AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, saved_stop_code);
Hannes Reinecked647c782015-04-24 13:18:26 +02007507 return sta;
Matthew Wilcox51219352007-10-02 21:55:22 -04007508}
7509
Hannes Reinecked647c782015-04-24 13:18:26 +02007510static bool
Matthew Wilcox51219352007-10-02 21:55:22 -04007511AscSetRunChipSynRegAtID(PortAddr iop_base, uchar tid_no, uchar sdtr_data)
7512{
Hannes Reinecked647c782015-04-24 13:18:26 +02007513 bool sta = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04007514
7515 if (AscHostReqRiscHalt(iop_base)) {
7516 sta = AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
7517 AscStartChip(iop_base);
7518 }
7519 return sta;
7520}
7521
7522static void AscAsyncFix(ASC_DVC_VAR *asc_dvc, struct scsi_device *sdev)
7523{
7524 char type = sdev->type;
7525 ASC_SCSI_BIT_ID_TYPE tid_bits = 1 << sdev->id;
7526
7527 if (!(asc_dvc->bug_fix_cntl & ASC_BUG_FIX_ASYN_USE_SYN))
7528 return;
7529 if (asc_dvc->init_sdtr & tid_bits)
7530 return;
7531
7532 if ((type == TYPE_ROM) && (strncmp(sdev->vendor, "HP ", 3) == 0))
7533 asc_dvc->pci_fix_asyn_xfer_always |= tid_bits;
7534
7535 asc_dvc->pci_fix_asyn_xfer |= tid_bits;
7536 if ((type == TYPE_PROCESSOR) || (type == TYPE_SCANNER) ||
7537 (type == TYPE_ROM) || (type == TYPE_TAPE))
7538 asc_dvc->pci_fix_asyn_xfer &= ~tid_bits;
7539
7540 if (asc_dvc->pci_fix_asyn_xfer & tid_bits)
7541 AscSetRunChipSynRegAtID(asc_dvc->iop_base, sdev->id,
7542 ASYN_SDTR_DATA_FIX_PCI_REV_AB);
7543}
7544
7545static void
7546advansys_narrow_slave_configure(struct scsi_device *sdev, ASC_DVC_VAR *asc_dvc)
7547{
7548 ASC_SCSI_BIT_ID_TYPE tid_bit = 1 << sdev->id;
7549 ASC_SCSI_BIT_ID_TYPE orig_use_tagged_qng = asc_dvc->use_tagged_qng;
7550
7551 if (sdev->lun == 0) {
7552 ASC_SCSI_BIT_ID_TYPE orig_init_sdtr = asc_dvc->init_sdtr;
7553 if ((asc_dvc->cfg->sdtr_enable & tid_bit) && sdev->sdtr) {
7554 asc_dvc->init_sdtr |= tid_bit;
7555 } else {
7556 asc_dvc->init_sdtr &= ~tid_bit;
7557 }
7558
7559 if (orig_init_sdtr != asc_dvc->init_sdtr)
7560 AscAsyncFix(asc_dvc, sdev);
7561 }
7562
7563 if (sdev->tagged_supported) {
7564 if (asc_dvc->cfg->cmd_qng_enabled & tid_bit) {
7565 if (sdev->lun == 0) {
7566 asc_dvc->cfg->can_tagged_qng |= tid_bit;
7567 asc_dvc->use_tagged_qng |= tid_bit;
7568 }
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01007569 scsi_change_queue_depth(sdev,
Matthew Wilcox51219352007-10-02 21:55:22 -04007570 asc_dvc->max_dvc_qng[sdev->id]);
7571 }
7572 } else {
7573 if (sdev->lun == 0) {
7574 asc_dvc->cfg->can_tagged_qng &= ~tid_bit;
7575 asc_dvc->use_tagged_qng &= ~tid_bit;
7576 }
Matthew Wilcox51219352007-10-02 21:55:22 -04007577 }
7578
7579 if ((sdev->lun == 0) &&
7580 (orig_use_tagged_qng != asc_dvc->use_tagged_qng)) {
7581 AscWriteLramByte(asc_dvc->iop_base, ASCV_DISC_ENABLE_B,
7582 asc_dvc->cfg->disc_enable);
7583 AscWriteLramByte(asc_dvc->iop_base, ASCV_USE_TAGGED_QNG_B,
7584 asc_dvc->use_tagged_qng);
7585 AscWriteLramByte(asc_dvc->iop_base, ASCV_CAN_TAGGED_QNG_B,
7586 asc_dvc->cfg->can_tagged_qng);
7587
7588 asc_dvc->max_dvc_qng[sdev->id] =
7589 asc_dvc->cfg->max_tag_qng[sdev->id];
7590 AscWriteLramByte(asc_dvc->iop_base,
7591 (ushort)(ASCV_MAX_DVC_QNG_BEG + sdev->id),
7592 asc_dvc->max_dvc_qng[sdev->id]);
7593 }
7594}
7595
7596/*
7597 * Wide Transfers
7598 *
7599 * If the EEPROM enabled WDTR for the device and the device supports wide
7600 * bus (16 bit) transfers, then turn on the device's 'wdtr_able' bit and
7601 * write the new value to the microcode.
7602 */
7603static void
7604advansys_wide_enable_wdtr(AdvPortAddr iop_base, unsigned short tidmask)
7605{
7606 unsigned short cfg_word;
7607 AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
7608 if ((cfg_word & tidmask) != 0)
7609 return;
7610
7611 cfg_word |= tidmask;
7612 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
7613
7614 /*
7615 * Clear the microcode SDTR and WDTR negotiation done indicators for
7616 * the target to cause it to negotiate with the new setting set above.
7617 * WDTR when accepted causes the target to enter asynchronous mode, so
7618 * SDTR must be negotiated.
7619 */
7620 AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
7621 cfg_word &= ~tidmask;
7622 AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
7623 AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
7624 cfg_word &= ~tidmask;
7625 AdvWriteWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
7626}
7627
7628/*
7629 * Synchronous Transfers
7630 *
7631 * If the EEPROM enabled SDTR for the device and the device
7632 * supports synchronous transfers, then turn on the device's
7633 * 'sdtr_able' bit. Write the new value to the microcode.
7634 */
7635static void
7636advansys_wide_enable_sdtr(AdvPortAddr iop_base, unsigned short tidmask)
7637{
7638 unsigned short cfg_word;
7639 AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
7640 if ((cfg_word & tidmask) != 0)
7641 return;
7642
7643 cfg_word |= tidmask;
7644 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
7645
7646 /*
7647 * Clear the microcode "SDTR negotiation" done indicator for the
7648 * target to cause it to negotiate with the new setting set above.
7649 */
7650 AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
7651 cfg_word &= ~tidmask;
7652 AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
7653}
7654
7655/*
7656 * PPR (Parallel Protocol Request) Capable
7657 *
7658 * If the device supports DT mode, then it must be PPR capable.
7659 * The PPR message will be used in place of the SDTR and WDTR
7660 * messages to negotiate synchronous speed and offset, transfer
7661 * width, and protocol options.
7662 */
7663static void advansys_wide_enable_ppr(ADV_DVC_VAR *adv_dvc,
7664 AdvPortAddr iop_base, unsigned short tidmask)
7665{
7666 AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, adv_dvc->ppr_able);
7667 adv_dvc->ppr_able |= tidmask;
7668 AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, adv_dvc->ppr_able);
7669}
7670
7671static void
7672advansys_wide_slave_configure(struct scsi_device *sdev, ADV_DVC_VAR *adv_dvc)
7673{
7674 AdvPortAddr iop_base = adv_dvc->iop_base;
7675 unsigned short tidmask = 1 << sdev->id;
7676
7677 if (sdev->lun == 0) {
7678 /*
7679 * Handle WDTR, SDTR, and Tag Queuing. If the feature
7680 * is enabled in the EEPROM and the device supports the
7681 * feature, then enable it in the microcode.
7682 */
7683
7684 if ((adv_dvc->wdtr_able & tidmask) && sdev->wdtr)
7685 advansys_wide_enable_wdtr(iop_base, tidmask);
7686 if ((adv_dvc->sdtr_able & tidmask) && sdev->sdtr)
7687 advansys_wide_enable_sdtr(iop_base, tidmask);
7688 if (adv_dvc->chip_type == ADV_CHIP_ASC38C1600 && sdev->ppr)
7689 advansys_wide_enable_ppr(adv_dvc, iop_base, tidmask);
7690
7691 /*
7692 * Tag Queuing is disabled for the BIOS which runs in polled
7693 * mode and would see no benefit from Tag Queuing. Also by
7694 * disabling Tag Queuing in the BIOS devices with Tag Queuing
7695 * bugs will at least work with the BIOS.
7696 */
7697 if ((adv_dvc->tagqng_able & tidmask) &&
7698 sdev->tagged_supported) {
7699 unsigned short cfg_word;
7700 AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, cfg_word);
7701 cfg_word |= tidmask;
7702 AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
7703 cfg_word);
7704 AdvWriteByteLram(iop_base,
7705 ASC_MC_NUMBER_OF_MAX_CMD + sdev->id,
7706 adv_dvc->max_dvc_qng);
7707 }
7708 }
7709
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01007710 if ((adv_dvc->tagqng_able & tidmask) && sdev->tagged_supported)
7711 scsi_change_queue_depth(sdev, adv_dvc->max_dvc_qng);
Matthew Wilcox51219352007-10-02 21:55:22 -04007712}
7713
7714/*
7715 * Set the number of commands to queue per device for the
7716 * specified host adapter.
7717 */
7718static int advansys_slave_configure(struct scsi_device *sdev)
7719{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04007720 struct asc_board *boardp = shost_priv(sdev->host);
Matthew Wilcox51219352007-10-02 21:55:22 -04007721
Matthew Wilcox51219352007-10-02 21:55:22 -04007722 if (ASC_NARROW_BOARD(boardp))
7723 advansys_narrow_slave_configure(sdev,
7724 &boardp->dvc_var.asc_dvc_var);
7725 else
7726 advansys_wide_slave_configure(sdev,
7727 &boardp->dvc_var.adv_dvc_var);
7728
7729 return 0;
7730}
7731
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04007732static __le32 advansys_get_sense_buffer_dma(struct scsi_cmnd *scp)
7733{
7734 struct asc_board *board = shost_priv(scp->device->host);
7735 scp->SCp.dma_handle = dma_map_single(board->dev, scp->sense_buffer,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09007736 SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04007737 dma_cache_sync(board->dev, scp->sense_buffer,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09007738 SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04007739 return cpu_to_le32(scp->SCp.dma_handle);
7740}
7741
Matthew Wilcoxd2411492007-10-02 21:55:31 -04007742static int asc_build_req(struct asc_board *boardp, struct scsi_cmnd *scp,
Matthew Wilcox05848b62007-10-02 21:55:25 -04007743 struct asc_scsi_q *asc_scsi_q)
Matthew Wilcox51219352007-10-02 21:55:22 -04007744{
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04007745 struct asc_dvc_var *asc_dvc = &boardp->dvc_var.asc_dvc_var;
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007746 int use_sg;
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007747 u32 srb_tag;
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007748
Matthew Wilcox05848b62007-10-02 21:55:25 -04007749 memset(asc_scsi_q, 0, sizeof(*asc_scsi_q));
Matthew Wilcox51219352007-10-02 21:55:22 -04007750
7751 /*
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007752 * Set the srb_tag to the command tag + 1, as
7753 * srb_tag '0' is used internally by the chip.
Matthew Wilcox51219352007-10-02 21:55:22 -04007754 */
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007755 srb_tag = scp->request->tag + 1;
7756 asc_scsi_q->q2.srb_tag = srb_tag;
Matthew Wilcox51219352007-10-02 21:55:22 -04007757
7758 /*
7759 * Build the ASC_SCSI_Q request.
7760 */
Matthew Wilcox05848b62007-10-02 21:55:25 -04007761 asc_scsi_q->cdbptr = &scp->cmnd[0];
7762 asc_scsi_q->q2.cdb_len = scp->cmd_len;
7763 asc_scsi_q->q1.target_id = ASC_TID_TO_TARGET_ID(scp->device->id);
7764 asc_scsi_q->q1.target_lun = scp->device->lun;
7765 asc_scsi_q->q2.target_ix =
Matthew Wilcox51219352007-10-02 21:55:22 -04007766 ASC_TIDLUN_TO_IX(scp->device->id, scp->device->lun);
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04007767 asc_scsi_q->q1.sense_addr = advansys_get_sense_buffer_dma(scp);
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09007768 asc_scsi_q->q1.sense_len = SCSI_SENSE_BUFFERSIZE;
Matthew Wilcox51219352007-10-02 21:55:22 -04007769
7770 /*
7771 * If there are any outstanding requests for the current target,
7772 * then every 255th request send an ORDERED request. This heuristic
7773 * tries to retain the benefit of request sorting while preventing
7774 * request starvation. 255 is the max number of tags or pending commands
7775 * a device may have outstanding.
7776 *
7777 * The request count is incremented below for every successfully
7778 * started request.
7779 *
7780 */
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04007781 if ((asc_dvc->cur_dvc_qng[scp->device->id] > 0) &&
Matthew Wilcox51219352007-10-02 21:55:22 -04007782 (boardp->reqcnt[scp->device->id] % 255) == 0) {
Christoph Hellwig68d81f42014-11-24 07:07:25 -08007783 asc_scsi_q->q2.tag_code = ORDERED_QUEUE_TAG;
Matthew Wilcox51219352007-10-02 21:55:22 -04007784 } else {
Christoph Hellwig68d81f42014-11-24 07:07:25 -08007785 asc_scsi_q->q2.tag_code = SIMPLE_QUEUE_TAG;
Matthew Wilcox51219352007-10-02 21:55:22 -04007786 }
7787
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007788 /* Build ASC_SCSI_Q */
7789 use_sg = scsi_dma_map(scp);
7790 if (use_sg != 0) {
Matthew Wilcox51219352007-10-02 21:55:22 -04007791 int sgcnt;
Matthew Wilcox51219352007-10-02 21:55:22 -04007792 struct scatterlist *slp;
Matthew Wilcox05848b62007-10-02 21:55:25 -04007793 struct asc_sg_head *asc_sg_head;
Matthew Wilcox51219352007-10-02 21:55:22 -04007794
Matthew Wilcox51219352007-10-02 21:55:22 -04007795 if (use_sg > scp->device->host->sg_tablesize) {
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04007796 scmd_printk(KERN_ERR, scp, "use_sg %d > "
7797 "sg_tablesize %d\n", use_sg,
7798 scp->device->host->sg_tablesize);
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007799 scsi_dma_unmap(scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04007800 scp->result = HOST_BYTE(DID_ERROR);
7801 return ASC_ERROR;
7802 }
7803
Matthew Wilcox05848b62007-10-02 21:55:25 -04007804 asc_sg_head = kzalloc(sizeof(asc_scsi_q->sg_head) +
7805 use_sg * sizeof(struct asc_sg_list), GFP_ATOMIC);
7806 if (!asc_sg_head) {
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007807 scsi_dma_unmap(scp);
Matthew Wilcox05848b62007-10-02 21:55:25 -04007808 scp->result = HOST_BYTE(DID_SOFT_ERROR);
7809 return ASC_ERROR;
7810 }
Matthew Wilcox51219352007-10-02 21:55:22 -04007811
Matthew Wilcox05848b62007-10-02 21:55:25 -04007812 asc_scsi_q->q1.cntl |= QC_SG_HEAD;
7813 asc_scsi_q->sg_head = asc_sg_head;
7814 asc_scsi_q->q1.data_cnt = 0;
7815 asc_scsi_q->q1.data_addr = 0;
Matthew Wilcox51219352007-10-02 21:55:22 -04007816 /* This is a byte value, otherwise it would need to be swapped. */
Matthew Wilcox05848b62007-10-02 21:55:25 -04007817 asc_sg_head->entry_cnt = asc_scsi_q->q1.sg_queue_cnt = use_sg;
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007818 ASC_STATS_ADD(scp->device->host, xfer_elem,
Matthew Wilcox05848b62007-10-02 21:55:25 -04007819 asc_sg_head->entry_cnt);
Matthew Wilcox51219352007-10-02 21:55:22 -04007820
7821 /*
7822 * Convert scatter-gather list into ASC_SG_HEAD list.
7823 */
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007824 scsi_for_each_sg(scp, slp, use_sg, sgcnt) {
Matthew Wilcox05848b62007-10-02 21:55:25 -04007825 asc_sg_head->sg_list[sgcnt].addr =
Matthew Wilcox51219352007-10-02 21:55:22 -04007826 cpu_to_le32(sg_dma_address(slp));
Matthew Wilcox05848b62007-10-02 21:55:25 -04007827 asc_sg_head->sg_list[sgcnt].bytes =
Matthew Wilcox51219352007-10-02 21:55:22 -04007828 cpu_to_le32(sg_dma_len(slp));
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007829 ASC_STATS_ADD(scp->device->host, xfer_sect,
7830 DIV_ROUND_UP(sg_dma_len(slp), 512));
Matthew Wilcox51219352007-10-02 21:55:22 -04007831 }
7832 }
7833
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007834 ASC_STATS(scp->device->host, xfer_cnt);
7835
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007836 ASC_DBG_PRT_ASC_SCSI_Q(2, asc_scsi_q);
Matthew Wilcox51219352007-10-02 21:55:22 -04007837 ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
7838
7839 return ASC_NOERROR;
7840}
7841
7842/*
7843 * Build scatter-gather list for Adv Library (Wide Board).
7844 *
7845 * Additional ADV_SG_BLOCK structures will need to be allocated
7846 * if the total number of scatter-gather elements exceeds
7847 * NO_OF_SG_PER_BLOCK (15). The ADV_SG_BLOCK structures are
7848 * assumed to be physically contiguous.
7849 *
7850 * Return:
7851 * ADV_SUCCESS(1) - SG List successfully created
7852 * ADV_ERROR(-1) - SG List creation failed
7853 */
7854static int
Hannes Reinecke4b47e462015-04-24 13:18:24 +02007855adv_get_sglist(struct asc_board *boardp, adv_req_t *reqp,
7856 ADV_SCSI_REQ_Q *scsiqp, struct scsi_cmnd *scp, int use_sg)
Matthew Wilcox51219352007-10-02 21:55:22 -04007857{
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007858 adv_sgblk_t *sgblkp, *prev_sgblkp;
Matthew Wilcox51219352007-10-02 21:55:22 -04007859 struct scatterlist *slp;
7860 int sg_elem_cnt;
7861 ADV_SG_BLOCK *sg_block, *prev_sg_block;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007862 dma_addr_t sgblk_paddr;
Matthew Wilcox51219352007-10-02 21:55:22 -04007863 int i;
7864
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007865 slp = scsi_sglist(scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04007866 sg_elem_cnt = use_sg;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007867 prev_sgblkp = NULL;
Matthew Wilcox51219352007-10-02 21:55:22 -04007868 prev_sg_block = NULL;
7869 reqp->sgblkp = NULL;
7870
7871 for (;;) {
7872 /*
7873 * Allocate a 'adv_sgblk_t' structure from the board free
7874 * list. One 'adv_sgblk_t' structure holds NO_OF_SG_PER_BLOCK
7875 * (15) scatter-gather elements.
7876 */
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007877 sgblkp = dma_pool_alloc(boardp->adv_sgblk_pool, GFP_ATOMIC,
7878 &sgblk_paddr);
7879 if (!sgblkp) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007880 ASC_DBG(1, "no free adv_sgblk_t\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007881 ASC_STATS(scp->device->host, adv_build_nosg);
7882
7883 /*
7884 * Allocation failed. Free 'adv_sgblk_t' structures
7885 * already allocated for the request.
7886 */
7887 while ((sgblkp = reqp->sgblkp) != NULL) {
7888 /* Remove 'sgblkp' from the request list. */
7889 reqp->sgblkp = sgblkp->next_sgblkp;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007890 sgblkp->next_sgblkp = NULL;
7891 dma_pool_free(boardp->adv_sgblk_pool, sgblkp,
7892 sgblkp->sg_addr);
Matthew Wilcox51219352007-10-02 21:55:22 -04007893 }
7894 return ASC_BUSY;
7895 }
Matthew Wilcox51219352007-10-02 21:55:22 -04007896 /* Complete 'adv_sgblk_t' board allocation. */
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007897 sgblkp->sg_addr = sgblk_paddr;
Matthew Wilcox51219352007-10-02 21:55:22 -04007898 sgblkp->next_sgblkp = NULL;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007899 sg_block = &sgblkp->sg_block;
Matthew Wilcox51219352007-10-02 21:55:22 -04007900
7901 /*
7902 * Check if this is the first 'adv_sgblk_t' for the
7903 * request.
7904 */
7905 if (reqp->sgblkp == NULL) {
7906 /* Request's first scatter-gather block. */
7907 reqp->sgblkp = sgblkp;
7908
7909 /*
7910 * Set ADV_SCSI_REQ_T ADV_SG_BLOCK virtual and physical
7911 * address pointers.
7912 */
7913 scsiqp->sg_list_ptr = sg_block;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007914 scsiqp->sg_real_addr = cpu_to_le32(sgblk_paddr);
Matthew Wilcox51219352007-10-02 21:55:22 -04007915 } else {
7916 /* Request's second or later scatter-gather block. */
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007917 prev_sgblkp->next_sgblkp = sgblkp;
Matthew Wilcox51219352007-10-02 21:55:22 -04007918
7919 /*
7920 * Point the previous ADV_SG_BLOCK structure to
7921 * the newly allocated ADV_SG_BLOCK structure.
7922 */
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007923 prev_sg_block->sg_ptr = cpu_to_le32(sgblk_paddr);
Matthew Wilcox51219352007-10-02 21:55:22 -04007924 }
7925
7926 for (i = 0; i < NO_OF_SG_PER_BLOCK; i++) {
7927 sg_block->sg_list[i].sg_addr =
7928 cpu_to_le32(sg_dma_address(slp));
7929 sg_block->sg_list[i].sg_count =
7930 cpu_to_le32(sg_dma_len(slp));
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007931 ASC_STATS_ADD(scp->device->host, xfer_sect,
7932 DIV_ROUND_UP(sg_dma_len(slp), 512));
Matthew Wilcox51219352007-10-02 21:55:22 -04007933
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007934 if (--sg_elem_cnt == 0) {
7935 /*
7936 * Last ADV_SG_BLOCK and scatter-gather entry.
7937 */
Matthew Wilcox51219352007-10-02 21:55:22 -04007938 sg_block->sg_cnt = i + 1;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007939 sg_block->sg_ptr = 0L; /* Last ADV_SG_BLOCK in list. */
Matthew Wilcox51219352007-10-02 21:55:22 -04007940 return ADV_SUCCESS;
7941 }
7942 slp++;
7943 }
7944 sg_block->sg_cnt = NO_OF_SG_PER_BLOCK;
7945 prev_sg_block = sg_block;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007946 prev_sgblkp = sgblkp;
Matthew Wilcox51219352007-10-02 21:55:22 -04007947 }
7948}
7949
7950/*
7951 * Build a request structure for the Adv Library (Wide Board).
7952 *
7953 * If an adv_req_t can not be allocated to issue the request,
7954 * then return ASC_BUSY. If an error occurs, then return ASC_ERROR.
7955 *
7956 * Multi-byte fields in the ASC_SCSI_REQ_Q that are used by the
7957 * microcode for DMA addresses or math operations are byte swapped
7958 * to little-endian order.
7959 */
7960static int
Matthew Wilcoxd2411492007-10-02 21:55:31 -04007961adv_build_req(struct asc_board *boardp, struct scsi_cmnd *scp,
Hannes Reinecke4b47e462015-04-24 13:18:24 +02007962 adv_req_t **adv_reqpp)
Matthew Wilcox51219352007-10-02 21:55:22 -04007963{
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007964 u32 srb_tag = scp->request->tag;
Matthew Wilcox51219352007-10-02 21:55:22 -04007965 adv_req_t *reqp;
7966 ADV_SCSI_REQ_Q *scsiqp;
Matthew Wilcox51219352007-10-02 21:55:22 -04007967 int ret;
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007968 int use_sg;
Hannes Reinecke811ddc02015-04-24 13:18:22 +02007969 dma_addr_t sense_addr;
Matthew Wilcox51219352007-10-02 21:55:22 -04007970
7971 /*
7972 * Allocate an adv_req_t structure from the board to execute
7973 * the command.
7974 */
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007975 reqp = &boardp->adv_reqp[srb_tag];
7976 if (reqp->cmndp && reqp->cmndp != scp ) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007977 ASC_DBG(1, "no free adv_req_t\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007978 ASC_STATS(scp->device->host, adv_build_noreq);
7979 return ASC_BUSY;
Matthew Wilcox51219352007-10-02 21:55:22 -04007980 }
7981
Hannes Reinecke4b47e462015-04-24 13:18:24 +02007982 reqp->req_addr = boardp->adv_reqp_addr + (srb_tag * sizeof(adv_req_t));
7983
7984 scsiqp = &reqp->scsi_req_q;
Matthew Wilcox51219352007-10-02 21:55:22 -04007985
7986 /*
7987 * Initialize the structure.
7988 */
7989 scsiqp->cntl = scsiqp->scsi_cntl = scsiqp->done_status = 0;
7990
7991 /*
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007992 * Set the srb_tag to the command tag.
Matthew Wilcox51219352007-10-02 21:55:22 -04007993 */
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007994 scsiqp->srb_tag = srb_tag;
Matthew Wilcox51219352007-10-02 21:55:22 -04007995
7996 /*
Hannes Reinecke4b47e462015-04-24 13:18:24 +02007997 * Set 'host_scribble' to point to the adv_req_t structure.
Matthew Wilcox51219352007-10-02 21:55:22 -04007998 */
7999 reqp->cmndp = scp;
Hannes Reinecke9c17c622015-04-24 13:18:21 +02008000 scp->host_scribble = (void *)reqp;
Matthew Wilcox51219352007-10-02 21:55:22 -04008001
8002 /*
8003 * Build the ADV_SCSI_REQ_Q request.
8004 */
8005
8006 /* Set CDB length and copy it to the request structure. */
8007 scsiqp->cdb_len = scp->cmd_len;
8008 /* Copy first 12 CDB bytes to cdb[]. */
Hannes Reinecke811ddc02015-04-24 13:18:22 +02008009 memcpy(scsiqp->cdb, scp->cmnd, scp->cmd_len < 12 ? scp->cmd_len : 12);
Matthew Wilcox51219352007-10-02 21:55:22 -04008010 /* Copy last 4 CDB bytes, if present, to cdb16[]. */
Hannes Reinecke811ddc02015-04-24 13:18:22 +02008011 if (scp->cmd_len > 12) {
8012 int cdb16_len = scp->cmd_len - 12;
8013
8014 memcpy(scsiqp->cdb16, &scp->cmnd[12], cdb16_len);
Matthew Wilcox51219352007-10-02 21:55:22 -04008015 }
8016
8017 scsiqp->target_id = scp->device->id;
8018 scsiqp->target_lun = scp->device->lun;
8019
Hannes Reinecke811ddc02015-04-24 13:18:22 +02008020 sense_addr = dma_map_single(boardp->dev, scp->sense_buffer,
8021 SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
8022 scsiqp->sense_addr = cpu_to_le32(sense_addr);
8023 scsiqp->sense_len = cpu_to_le32(SCSI_SENSE_BUFFERSIZE);
Matthew Wilcox51219352007-10-02 21:55:22 -04008024
Matthew Wilcox52c334e2007-10-02 21:55:39 -04008025 /* Build ADV_SCSI_REQ_Q */
Matthew Wilcox51219352007-10-02 21:55:22 -04008026
Matthew Wilcox52c334e2007-10-02 21:55:39 -04008027 use_sg = scsi_dma_map(scp);
8028 if (use_sg == 0) {
8029 /* Zero-length transfer */
Matthew Wilcox51219352007-10-02 21:55:22 -04008030 reqp->sgblkp = NULL;
Matthew Wilcox52c334e2007-10-02 21:55:39 -04008031 scsiqp->data_cnt = 0;
Matthew Wilcox52c334e2007-10-02 21:55:39 -04008032
8033 scsiqp->data_addr = 0;
Matthew Wilcox51219352007-10-02 21:55:22 -04008034 scsiqp->sg_list_ptr = NULL;
8035 scsiqp->sg_real_addr = 0;
Matthew Wilcox51219352007-10-02 21:55:22 -04008036 } else {
Matthew Wilcox51219352007-10-02 21:55:22 -04008037 if (use_sg > ADV_MAX_SG_LIST) {
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04008038 scmd_printk(KERN_ERR, scp, "use_sg %d > "
8039 "ADV_MAX_SG_LIST %d\n", use_sg,
Matthew Wilcox51219352007-10-02 21:55:22 -04008040 scp->device->host->sg_tablesize);
Matthew Wilcox52c334e2007-10-02 21:55:39 -04008041 scsi_dma_unmap(scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04008042 scp->result = HOST_BYTE(DID_ERROR);
Hannes Reinecke9c17c622015-04-24 13:18:21 +02008043 reqp->cmndp = NULL;
8044 scp->host_scribble = NULL;
Matthew Wilcox51219352007-10-02 21:55:22 -04008045
8046 return ASC_ERROR;
8047 }
8048
Matthew Wilcox52c334e2007-10-02 21:55:39 -04008049 scsiqp->data_cnt = cpu_to_le32(scsi_bufflen(scp));
8050
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008051 ret = adv_get_sglist(boardp, reqp, scsiqp, scp, use_sg);
Matthew Wilcox51219352007-10-02 21:55:22 -04008052 if (ret != ADV_SUCCESS) {
Hannes Reinecke9c17c622015-04-24 13:18:21 +02008053 scsi_dma_unmap(scp);
8054 scp->result = HOST_BYTE(DID_ERROR);
8055 reqp->cmndp = NULL;
8056 scp->host_scribble = NULL;
Matthew Wilcox51219352007-10-02 21:55:22 -04008057
8058 return ret;
8059 }
8060
Matthew Wilcox52c334e2007-10-02 21:55:39 -04008061 ASC_STATS_ADD(scp->device->host, xfer_elem, use_sg);
Matthew Wilcox51219352007-10-02 21:55:22 -04008062 }
8063
Matthew Wilcox52c334e2007-10-02 21:55:39 -04008064 ASC_STATS(scp->device->host, xfer_cnt);
8065
Matthew Wilcox51219352007-10-02 21:55:22 -04008066 ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
8067 ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
8068
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008069 *adv_reqpp = reqp;
Matthew Wilcox51219352007-10-02 21:55:22 -04008070
8071 return ASC_NOERROR;
8072}
8073
8074static int AscSgListToQueue(int sg_list)
8075{
8076 int n_sg_list_qs;
8077
8078 n_sg_list_qs = ((sg_list - 1) / ASC_SG_LIST_PER_Q);
8079 if (((sg_list - 1) % ASC_SG_LIST_PER_Q) != 0)
8080 n_sg_list_qs++;
8081 return n_sg_list_qs + 1;
8082}
8083
8084static uint
8085AscGetNumOfFreeQueue(ASC_DVC_VAR *asc_dvc, uchar target_ix, uchar n_qs)
8086{
8087 uint cur_used_qs;
8088 uint cur_free_qs;
8089 ASC_SCSI_BIT_ID_TYPE target_id;
8090 uchar tid_no;
8091
8092 target_id = ASC_TIX_TO_TARGET_ID(target_ix);
8093 tid_no = ASC_TIX_TO_TID(target_ix);
8094 if ((asc_dvc->unit_not_ready & target_id) ||
8095 (asc_dvc->queue_full_or_busy & target_id)) {
8096 return 0;
8097 }
8098 if (n_qs == 1) {
8099 cur_used_qs = (uint) asc_dvc->cur_total_qng +
8100 (uint) asc_dvc->last_q_shortage + (uint) ASC_MIN_FREE_Q;
8101 } else {
8102 cur_used_qs = (uint) asc_dvc->cur_total_qng +
8103 (uint) ASC_MIN_FREE_Q;
8104 }
8105 if ((uint) (cur_used_qs + n_qs) <= (uint) asc_dvc->max_total_qng) {
8106 cur_free_qs = (uint) asc_dvc->max_total_qng - cur_used_qs;
8107 if (asc_dvc->cur_dvc_qng[tid_no] >=
8108 asc_dvc->max_dvc_qng[tid_no]) {
8109 return 0;
8110 }
8111 return cur_free_qs;
8112 }
8113 if (n_qs > 1) {
8114 if ((n_qs > asc_dvc->last_q_shortage)
8115 && (n_qs <= (asc_dvc->max_total_qng - ASC_MIN_FREE_Q))) {
8116 asc_dvc->last_q_shortage = n_qs;
8117 }
8118 }
8119 return 0;
8120}
8121
8122static uchar AscAllocFreeQueue(PortAddr iop_base, uchar free_q_head)
8123{
8124 ushort q_addr;
8125 uchar next_qp;
8126 uchar q_status;
8127
8128 q_addr = ASC_QNO_TO_QADDR(free_q_head);
8129 q_status = (uchar)AscReadLramByte(iop_base,
8130 (ushort)(q_addr +
8131 ASC_SCSIQ_B_STATUS));
8132 next_qp = AscReadLramByte(iop_base, (ushort)(q_addr + ASC_SCSIQ_B_FWD));
8133 if (((q_status & QS_READY) == 0) && (next_qp != ASC_QLINK_END))
8134 return next_qp;
8135 return ASC_QLINK_END;
8136}
8137
8138static uchar
8139AscAllocMultipleFreeQueue(PortAddr iop_base, uchar free_q_head, uchar n_free_q)
8140{
8141 uchar i;
8142
8143 for (i = 0; i < n_free_q; i++) {
8144 free_q_head = AscAllocFreeQueue(iop_base, free_q_head);
8145 if (free_q_head == ASC_QLINK_END)
8146 break;
8147 }
8148 return free_q_head;
8149}
8150
8151/*
8152 * void
8153 * DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
8154 *
8155 * Calling/Exit State:
8156 * none
8157 *
8158 * Description:
8159 * Output an ASC_SCSI_Q structure to the chip
8160 */
8161static void
8162DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
8163{
8164 int i;
8165
8166 ASC_DBG_PRT_HEX(2, "DvcPutScsiQ", outbuf, 2 * words);
8167 AscSetChipLramAddr(iop_base, s_addr);
8168 for (i = 0; i < 2 * words; i += 2) {
8169 if (i == 4 || i == 20) {
8170 continue;
8171 }
8172 outpw(iop_base + IOP_RAM_DATA,
8173 ((ushort)outbuf[i + 1] << 8) | outbuf[i]);
8174 }
8175}
8176
8177static int AscPutReadyQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar q_no)
8178{
8179 ushort q_addr;
8180 uchar tid_no;
8181 uchar sdtr_data;
8182 uchar syn_period_ix;
8183 uchar syn_offset;
8184 PortAddr iop_base;
8185
8186 iop_base = asc_dvc->iop_base;
8187 if (((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) &&
8188 ((asc_dvc->sdtr_done & scsiq->q1.target_id) == 0)) {
8189 tid_no = ASC_TIX_TO_TID(scsiq->q2.target_ix);
8190 sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
8191 syn_period_ix =
8192 (sdtr_data >> 4) & (asc_dvc->max_sdtr_index - 1);
8193 syn_offset = sdtr_data & ASC_SYN_MAX_OFFSET;
8194 AscMsgOutSDTR(asc_dvc,
8195 asc_dvc->sdtr_period_tbl[syn_period_ix],
8196 syn_offset);
8197 scsiq->q1.cntl |= QC_MSG_OUT;
8198 }
8199 q_addr = ASC_QNO_TO_QADDR(q_no);
8200 if ((scsiq->q1.target_id & asc_dvc->use_tagged_qng) == 0) {
Christoph Hellwig68d81f42014-11-24 07:07:25 -08008201 scsiq->q2.tag_code &= ~SIMPLE_QUEUE_TAG;
Matthew Wilcox51219352007-10-02 21:55:22 -04008202 }
8203 scsiq->q1.status = QS_FREE;
8204 AscMemWordCopyPtrToLram(iop_base,
8205 q_addr + ASC_SCSIQ_CDB_BEG,
8206 (uchar *)scsiq->cdbptr, scsiq->q2.cdb_len >> 1);
8207
8208 DvcPutScsiQ(iop_base,
8209 q_addr + ASC_SCSIQ_CPY_BEG,
8210 (uchar *)&scsiq->q1.cntl,
8211 ((sizeof(ASC_SCSIQ_1) + sizeof(ASC_SCSIQ_2)) / 2) - 1);
8212 AscWriteLramWord(iop_base,
8213 (ushort)(q_addr + (ushort)ASC_SCSIQ_B_STATUS),
8214 (ushort)(((ushort)scsiq->q1.
8215 q_no << 8) | (ushort)QS_READY));
8216 return 1;
8217}
8218
8219static int
8220AscPutReadySgListQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar q_no)
8221{
8222 int sta;
8223 int i;
8224 ASC_SG_HEAD *sg_head;
8225 ASC_SG_LIST_Q scsi_sg_q;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008226 __le32 saved_data_addr;
8227 __le32 saved_data_cnt;
Matthew Wilcox51219352007-10-02 21:55:22 -04008228 PortAddr iop_base;
8229 ushort sg_list_dwords;
8230 ushort sg_index;
8231 ushort sg_entry_cnt;
8232 ushort q_addr;
8233 uchar next_qp;
8234
8235 iop_base = asc_dvc->iop_base;
8236 sg_head = scsiq->sg_head;
8237 saved_data_addr = scsiq->q1.data_addr;
8238 saved_data_cnt = scsiq->q1.data_cnt;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008239 scsiq->q1.data_addr = sg_head->sg_list[0].addr;
8240 scsiq->q1.data_cnt = sg_head->sg_list[0].bytes;
Matthew Wilcox51219352007-10-02 21:55:22 -04008241#if CC_VERY_LONG_SG_LIST
8242 /*
8243 * If sg_head->entry_cnt is greater than ASC_MAX_SG_LIST
8244 * then not all SG elements will fit in the allocated queues.
8245 * The rest of the SG elements will be copied when the RISC
8246 * completes the SG elements that fit and halts.
8247 */
8248 if (sg_head->entry_cnt > ASC_MAX_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. ASC_MAX_SG_LIST is
8253 * already inflated by 1 to account for this. For example it
8254 * may be 50 which is 1 + 7 queues * 7 SG elements.
8255 */
8256 sg_entry_cnt = ASC_MAX_SG_LIST - 1;
8257
8258 /*
8259 * Keep track of remaining number of SG elements that will
8260 * need to be handled from a_isr.c.
8261 */
8262 scsiq->remain_sg_entry_cnt =
8263 sg_head->entry_cnt - ASC_MAX_SG_LIST;
8264 } else {
8265#endif /* CC_VERY_LONG_SG_LIST */
8266 /*
8267 * Set sg_entry_cnt to be the number of SG elements that
8268 * will fit in the allocated SG queues. It is minus 1, because
8269 * the first SG element is handled above.
8270 */
8271 sg_entry_cnt = sg_head->entry_cnt - 1;
8272#if CC_VERY_LONG_SG_LIST
8273 }
8274#endif /* CC_VERY_LONG_SG_LIST */
8275 if (sg_entry_cnt != 0) {
8276 scsiq->q1.cntl |= QC_SG_HEAD;
8277 q_addr = ASC_QNO_TO_QADDR(q_no);
8278 sg_index = 1;
8279 scsiq->q1.sg_queue_cnt = sg_head->queue_cnt;
8280 scsi_sg_q.sg_head_qp = q_no;
8281 scsi_sg_q.cntl = QCSG_SG_XFER_LIST;
8282 for (i = 0; i < sg_head->queue_cnt; i++) {
8283 scsi_sg_q.seq_no = i + 1;
8284 if (sg_entry_cnt > ASC_SG_LIST_PER_Q) {
8285 sg_list_dwords = (uchar)(ASC_SG_LIST_PER_Q * 2);
8286 sg_entry_cnt -= ASC_SG_LIST_PER_Q;
8287 if (i == 0) {
8288 scsi_sg_q.sg_list_cnt =
8289 ASC_SG_LIST_PER_Q;
8290 scsi_sg_q.sg_cur_list_cnt =
8291 ASC_SG_LIST_PER_Q;
8292 } else {
8293 scsi_sg_q.sg_list_cnt =
8294 ASC_SG_LIST_PER_Q - 1;
8295 scsi_sg_q.sg_cur_list_cnt =
8296 ASC_SG_LIST_PER_Q - 1;
8297 }
8298 } else {
8299#if CC_VERY_LONG_SG_LIST
8300 /*
8301 * This is the last SG queue in the list of
8302 * allocated SG queues. If there are more
8303 * SG elements than will fit in the allocated
8304 * queues, then set the QCSG_SG_XFER_MORE flag.
8305 */
8306 if (sg_head->entry_cnt > ASC_MAX_SG_LIST) {
8307 scsi_sg_q.cntl |= QCSG_SG_XFER_MORE;
8308 } else {
8309#endif /* CC_VERY_LONG_SG_LIST */
8310 scsi_sg_q.cntl |= QCSG_SG_XFER_END;
8311#if CC_VERY_LONG_SG_LIST
8312 }
8313#endif /* CC_VERY_LONG_SG_LIST */
8314 sg_list_dwords = sg_entry_cnt << 1;
8315 if (i == 0) {
8316 scsi_sg_q.sg_list_cnt = sg_entry_cnt;
8317 scsi_sg_q.sg_cur_list_cnt =
8318 sg_entry_cnt;
8319 } else {
8320 scsi_sg_q.sg_list_cnt =
8321 sg_entry_cnt - 1;
8322 scsi_sg_q.sg_cur_list_cnt =
8323 sg_entry_cnt - 1;
8324 }
8325 sg_entry_cnt = 0;
8326 }
8327 next_qp = AscReadLramByte(iop_base,
8328 (ushort)(q_addr +
8329 ASC_SCSIQ_B_FWD));
8330 scsi_sg_q.q_no = next_qp;
8331 q_addr = ASC_QNO_TO_QADDR(next_qp);
8332 AscMemWordCopyPtrToLram(iop_base,
8333 q_addr + ASC_SCSIQ_SGHD_CPY_BEG,
8334 (uchar *)&scsi_sg_q,
8335 sizeof(ASC_SG_LIST_Q) >> 1);
8336 AscMemDWordCopyPtrToLram(iop_base,
8337 q_addr + ASC_SGQ_LIST_BEG,
8338 (uchar *)&sg_head->
8339 sg_list[sg_index],
8340 sg_list_dwords);
8341 sg_index += ASC_SG_LIST_PER_Q;
8342 scsiq->next_sg_index = sg_index;
8343 }
8344 } else {
8345 scsiq->q1.cntl &= ~QC_SG_HEAD;
8346 }
8347 sta = AscPutReadyQueue(asc_dvc, scsiq, q_no);
8348 scsiq->q1.data_addr = saved_data_addr;
8349 scsiq->q1.data_cnt = saved_data_cnt;
8350 return (sta);
8351}
8352
8353static int
8354AscSendScsiQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar n_q_required)
8355{
8356 PortAddr iop_base;
8357 uchar free_q_head;
8358 uchar next_qp;
8359 uchar tid_no;
8360 uchar target_ix;
8361 int sta;
8362
8363 iop_base = asc_dvc->iop_base;
8364 target_ix = scsiq->q2.target_ix;
8365 tid_no = ASC_TIX_TO_TID(target_ix);
8366 sta = 0;
8367 free_q_head = (uchar)AscGetVarFreeQHead(iop_base);
8368 if (n_q_required > 1) {
8369 next_qp = AscAllocMultipleFreeQueue(iop_base, free_q_head,
8370 (uchar)n_q_required);
8371 if (next_qp != ASC_QLINK_END) {
8372 asc_dvc->last_q_shortage = 0;
8373 scsiq->sg_head->queue_cnt = n_q_required - 1;
8374 scsiq->q1.q_no = free_q_head;
8375 sta = AscPutReadySgListQueue(asc_dvc, scsiq,
8376 free_q_head);
8377 }
8378 } else if (n_q_required == 1) {
8379 next_qp = AscAllocFreeQueue(iop_base, free_q_head);
8380 if (next_qp != ASC_QLINK_END) {
8381 scsiq->q1.q_no = free_q_head;
8382 sta = AscPutReadyQueue(asc_dvc, scsiq, free_q_head);
8383 }
8384 }
8385 if (sta == 1) {
8386 AscPutVarFreeQHead(iop_base, next_qp);
8387 asc_dvc->cur_total_qng += n_q_required;
8388 asc_dvc->cur_dvc_qng[tid_no]++;
8389 }
8390 return sta;
8391}
8392
8393#define ASC_SYN_OFFSET_ONE_DISABLE_LIST 16
8394static uchar _syn_offset_one_disable_cmd[ASC_SYN_OFFSET_ONE_DISABLE_LIST] = {
8395 INQUIRY,
8396 REQUEST_SENSE,
8397 READ_CAPACITY,
8398 READ_TOC,
8399 MODE_SELECT,
8400 MODE_SENSE,
8401 MODE_SELECT_10,
8402 MODE_SENSE_10,
8403 0xFF,
8404 0xFF,
8405 0xFF,
8406 0xFF,
8407 0xFF,
8408 0xFF,
8409 0xFF,
8410 0xFF
8411};
8412
8413static int AscExeScsiQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq)
8414{
8415 PortAddr iop_base;
8416 int sta;
8417 int n_q_required;
Hannes Reineckeae267592015-04-24 13:18:28 +02008418 bool disable_syn_offset_one_fix;
Matthew Wilcox51219352007-10-02 21:55:22 -04008419 int i;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008420 u32 addr;
Matthew Wilcox51219352007-10-02 21:55:22 -04008421 ushort sg_entry_cnt = 0;
8422 ushort sg_entry_cnt_minus_one = 0;
8423 uchar target_ix;
8424 uchar tid_no;
8425 uchar sdtr_data;
8426 uchar extra_bytes;
8427 uchar scsi_cmd;
8428 uchar disable_cmd;
8429 ASC_SG_HEAD *sg_head;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008430 unsigned long data_cnt;
Matthew Wilcox51219352007-10-02 21:55:22 -04008431
8432 iop_base = asc_dvc->iop_base;
8433 sg_head = scsiq->sg_head;
8434 if (asc_dvc->err_code != 0)
Hannes Reineckef1138a82015-04-24 13:18:29 +02008435 return ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04008436 scsiq->q1.q_no = 0;
8437 if ((scsiq->q2.tag_code & ASC_TAG_FLAG_EXTRA_BYTES) == 0) {
8438 scsiq->q1.extra_bytes = 0;
8439 }
8440 sta = 0;
8441 target_ix = scsiq->q2.target_ix;
8442 tid_no = ASC_TIX_TO_TID(target_ix);
8443 n_q_required = 1;
8444 if (scsiq->cdbptr[0] == REQUEST_SENSE) {
8445 if ((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) {
8446 asc_dvc->sdtr_done &= ~scsiq->q1.target_id;
8447 sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
8448 AscMsgOutSDTR(asc_dvc,
8449 asc_dvc->
8450 sdtr_period_tbl[(sdtr_data >> 4) &
8451 (uchar)(asc_dvc->
8452 max_sdtr_index -
8453 1)],
8454 (uchar)(sdtr_data & (uchar)
8455 ASC_SYN_MAX_OFFSET));
8456 scsiq->q1.cntl |= (QC_MSG_OUT | QC_URGENT);
8457 }
8458 }
8459 if (asc_dvc->in_critical_cnt != 0) {
8460 AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CRITICAL_RE_ENTRY);
Hannes Reineckef1138a82015-04-24 13:18:29 +02008461 return ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04008462 }
8463 asc_dvc->in_critical_cnt++;
8464 if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
8465 if ((sg_entry_cnt = sg_head->entry_cnt) == 0) {
8466 asc_dvc->in_critical_cnt--;
Hannes Reineckef1138a82015-04-24 13:18:29 +02008467 return ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04008468 }
8469#if !CC_VERY_LONG_SG_LIST
8470 if (sg_entry_cnt > ASC_MAX_SG_LIST) {
8471 asc_dvc->in_critical_cnt--;
Hannes Reineckef1138a82015-04-24 13:18:29 +02008472 return ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04008473 }
8474#endif /* !CC_VERY_LONG_SG_LIST */
8475 if (sg_entry_cnt == 1) {
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008476 scsiq->q1.data_addr = sg_head->sg_list[0].addr;
8477 scsiq->q1.data_cnt = sg_head->sg_list[0].bytes;
Matthew Wilcox51219352007-10-02 21:55:22 -04008478 scsiq->q1.cntl &= ~(QC_SG_HEAD | QC_SG_SWAP_QUEUE);
8479 }
8480 sg_entry_cnt_minus_one = sg_entry_cnt - 1;
8481 }
8482 scsi_cmd = scsiq->cdbptr[0];
Hannes Reineckeae267592015-04-24 13:18:28 +02008483 disable_syn_offset_one_fix = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04008484 if ((asc_dvc->pci_fix_asyn_xfer & scsiq->q1.target_id) &&
8485 !(asc_dvc->pci_fix_asyn_xfer_always & scsiq->q1.target_id)) {
8486 if (scsiq->q1.cntl & QC_SG_HEAD) {
8487 data_cnt = 0;
8488 for (i = 0; i < sg_entry_cnt; i++) {
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008489 data_cnt += le32_to_cpu(sg_head->sg_list[i].
8490 bytes);
Matthew Wilcox51219352007-10-02 21:55:22 -04008491 }
8492 } else {
8493 data_cnt = le32_to_cpu(scsiq->q1.data_cnt);
8494 }
8495 if (data_cnt != 0UL) {
8496 if (data_cnt < 512UL) {
Hannes Reineckeae267592015-04-24 13:18:28 +02008497 disable_syn_offset_one_fix = true;
Matthew Wilcox51219352007-10-02 21:55:22 -04008498 } else {
8499 for (i = 0; i < ASC_SYN_OFFSET_ONE_DISABLE_LIST;
8500 i++) {
8501 disable_cmd =
8502 _syn_offset_one_disable_cmd[i];
8503 if (disable_cmd == 0xFF) {
8504 break;
8505 }
8506 if (scsi_cmd == disable_cmd) {
8507 disable_syn_offset_one_fix =
Hannes Reineckeae267592015-04-24 13:18:28 +02008508 true;
Matthew Wilcox51219352007-10-02 21:55:22 -04008509 break;
8510 }
8511 }
8512 }
8513 }
8514 }
8515 if (disable_syn_offset_one_fix) {
Christoph Hellwig68d81f42014-11-24 07:07:25 -08008516 scsiq->q2.tag_code &= ~SIMPLE_QUEUE_TAG;
Matthew Wilcox51219352007-10-02 21:55:22 -04008517 scsiq->q2.tag_code |= (ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX |
8518 ASC_TAG_FLAG_DISABLE_DISCONNECT);
8519 } else {
8520 scsiq->q2.tag_code &= 0x27;
8521 }
8522 if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
8523 if (asc_dvc->bug_fix_cntl) {
8524 if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
8525 if ((scsi_cmd == READ_6) ||
8526 (scsi_cmd == READ_10)) {
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008527 addr = le32_to_cpu(sg_head->
Matthew Wilcox51219352007-10-02 21:55:22 -04008528 sg_list
8529 [sg_entry_cnt_minus_one].
8530 addr) +
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008531 le32_to_cpu(sg_head->
Matthew Wilcox51219352007-10-02 21:55:22 -04008532 sg_list
8533 [sg_entry_cnt_minus_one].
8534 bytes);
8535 extra_bytes =
8536 (uchar)((ushort)addr & 0x0003);
8537 if ((extra_bytes != 0)
8538 &&
8539 ((scsiq->q2.
8540 tag_code &
8541 ASC_TAG_FLAG_EXTRA_BYTES)
8542 == 0)) {
8543 scsiq->q2.tag_code |=
8544 ASC_TAG_FLAG_EXTRA_BYTES;
8545 scsiq->q1.extra_bytes =
8546 extra_bytes;
8547 data_cnt =
8548 le32_to_cpu(sg_head->
8549 sg_list
8550 [sg_entry_cnt_minus_one].
8551 bytes);
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008552 data_cnt -= extra_bytes;
Matthew Wilcox51219352007-10-02 21:55:22 -04008553 sg_head->
8554 sg_list
8555 [sg_entry_cnt_minus_one].
8556 bytes =
8557 cpu_to_le32(data_cnt);
8558 }
8559 }
8560 }
8561 }
8562 sg_head->entry_to_copy = sg_head->entry_cnt;
8563#if CC_VERY_LONG_SG_LIST
8564 /*
8565 * Set the sg_entry_cnt to the maximum possible. The rest of
8566 * the SG elements will be copied when the RISC completes the
8567 * SG elements that fit and halts.
8568 */
8569 if (sg_entry_cnt > ASC_MAX_SG_LIST) {
8570 sg_entry_cnt = ASC_MAX_SG_LIST;
8571 }
8572#endif /* CC_VERY_LONG_SG_LIST */
8573 n_q_required = AscSgListToQueue(sg_entry_cnt);
8574 if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, n_q_required) >=
8575 (uint) n_q_required)
8576 || ((scsiq->q1.cntl & QC_URGENT) != 0)) {
8577 if ((sta =
8578 AscSendScsiQueue(asc_dvc, scsiq,
8579 n_q_required)) == 1) {
8580 asc_dvc->in_critical_cnt--;
8581 return (sta);
8582 }
8583 }
8584 } else {
8585 if (asc_dvc->bug_fix_cntl) {
8586 if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
8587 if ((scsi_cmd == READ_6) ||
8588 (scsi_cmd == READ_10)) {
8589 addr =
8590 le32_to_cpu(scsiq->q1.data_addr) +
8591 le32_to_cpu(scsiq->q1.data_cnt);
8592 extra_bytes =
8593 (uchar)((ushort)addr & 0x0003);
8594 if ((extra_bytes != 0)
8595 &&
8596 ((scsiq->q2.
8597 tag_code &
8598 ASC_TAG_FLAG_EXTRA_BYTES)
8599 == 0)) {
8600 data_cnt =
8601 le32_to_cpu(scsiq->q1.
8602 data_cnt);
8603 if (((ushort)data_cnt & 0x01FF)
8604 == 0) {
8605 scsiq->q2.tag_code |=
8606 ASC_TAG_FLAG_EXTRA_BYTES;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008607 data_cnt -= extra_bytes;
Matthew Wilcox51219352007-10-02 21:55:22 -04008608 scsiq->q1.data_cnt =
8609 cpu_to_le32
8610 (data_cnt);
8611 scsiq->q1.extra_bytes =
8612 extra_bytes;
8613 }
8614 }
8615 }
8616 }
8617 }
8618 n_q_required = 1;
8619 if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, 1) >= 1) ||
8620 ((scsiq->q1.cntl & QC_URGENT) != 0)) {
8621 if ((sta = AscSendScsiQueue(asc_dvc, scsiq,
8622 n_q_required)) == 1) {
8623 asc_dvc->in_critical_cnt--;
8624 return (sta);
8625 }
8626 }
8627 }
8628 asc_dvc->in_critical_cnt--;
8629 return (sta);
8630}
8631
8632/*
8633 * AdvExeScsiQueue() - Send a request to the RISC microcode program.
8634 *
8635 * Allocate a carrier structure, point the carrier to the ADV_SCSI_REQ_Q,
8636 * add the carrier to the ICQ (Initiator Command Queue), and tickle the
8637 * RISC to notify it a new command is ready to be executed.
8638 *
8639 * If 'done_status' is not set to QD_DO_RETRY, then 'error_retry' will be
8640 * set to SCSI_MAX_RETRY.
8641 *
8642 * Multi-byte fields in the ASC_SCSI_REQ_Q that are used by the microcode
8643 * for DMA addresses or math operations are byte swapped to little-endian
8644 * order.
8645 *
8646 * Return:
8647 * ADV_SUCCESS(1) - The request was successfully queued.
8648 * ADV_BUSY(0) - Resource unavailable; Retry again after pending
8649 * request completes.
8650 * ADV_ERROR(-1) - Invalid ADV_SCSI_REQ_Q request structure
8651 * host IC error.
8652 */
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008653static int AdvExeScsiQueue(ADV_DVC_VAR *asc_dvc, adv_req_t *reqp)
Matthew Wilcox51219352007-10-02 21:55:22 -04008654{
8655 AdvPortAddr iop_base;
Matthew Wilcox51219352007-10-02 21:55:22 -04008656 ADV_CARR_T *new_carrp;
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008657 ADV_SCSI_REQ_Q *scsiq = &reqp->scsi_req_q;
Matthew Wilcox51219352007-10-02 21:55:22 -04008658
8659 /*
8660 * The ADV_SCSI_REQ_Q 'target_id' field should never exceed ADV_MAX_TID.
8661 */
8662 if (scsiq->target_id > ADV_MAX_TID) {
8663 scsiq->host_status = QHSTA_M_INVALID_DEVICE;
8664 scsiq->done_status = QD_WITH_ERROR;
8665 return ADV_ERROR;
8666 }
8667
8668 iop_base = asc_dvc->iop_base;
8669
8670 /*
8671 * Allocate a carrier ensuring at least one carrier always
8672 * remains on the freelist and initialize fields.
8673 */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02008674 new_carrp = adv_get_next_carrier(asc_dvc);
8675 if (!new_carrp) {
8676 ASC_DBG(1, "No free carriers\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04008677 return ADV_BUSY;
8678 }
Matthew Wilcox51219352007-10-02 21:55:22 -04008679
Hannes Reinecke98b96a72015-04-24 13:18:23 +02008680 asc_dvc->carr_pending_cnt++;
Matthew Wilcox51219352007-10-02 21:55:22 -04008681
8682 /*
8683 * Clear the ADV_SCSI_REQ_Q done flag.
8684 */
8685 scsiq->a_flag &= ~ADV_SCSIQ_DONE;
8686
Matthew Wilcox51219352007-10-02 21:55:22 -04008687 /* Save virtual and physical address of ADV_SCSI_REQ_Q and carrier. */
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008688 scsiq->scsiq_ptr = cpu_to_le32(scsiq->srb_tag);
8689 scsiq->scsiq_rptr = cpu_to_le32(reqp->req_addr);
Matthew Wilcox51219352007-10-02 21:55:22 -04008690
Hannes Reinecke98b96a72015-04-24 13:18:23 +02008691 scsiq->carr_va = asc_dvc->icq_sp->carr_va;
Matthew Wilcox51219352007-10-02 21:55:22 -04008692 scsiq->carr_pa = asc_dvc->icq_sp->carr_pa;
8693
8694 /*
8695 * Use the current stopper to send the ADV_SCSI_REQ_Q command to
8696 * the microcode. The newly allocated stopper will become the new
8697 * stopper.
8698 */
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008699 asc_dvc->icq_sp->areq_vpa = scsiq->scsiq_rptr;
Matthew Wilcox51219352007-10-02 21:55:22 -04008700
8701 /*
8702 * Set the 'next_vpa' pointer for the old stopper to be the
8703 * physical address of the new stopper. The RISC can only
8704 * follow physical addresses.
8705 */
8706 asc_dvc->icq_sp->next_vpa = new_carrp->carr_pa;
8707
8708 /*
8709 * Set the host adapter stopper pointer to point to the new carrier.
8710 */
8711 asc_dvc->icq_sp = new_carrp;
8712
8713 if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
8714 asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
8715 /*
8716 * Tickle the RISC to tell it to read its Command Queue Head pointer.
8717 */
8718 AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_A);
8719 if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
8720 /*
8721 * Clear the tickle value. In the ASC-3550 the RISC flag
8722 * command 'clr_tickle_a' does not work unless the host
8723 * value is cleared.
8724 */
8725 AdvWriteByteRegister(iop_base, IOPB_TICKLE,
8726 ADV_TICKLE_NOP);
8727 }
8728 } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
8729 /*
8730 * Notify the RISC a carrier is ready by writing the physical
8731 * address of the new carrier stopper to the COMMA register.
8732 */
8733 AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
8734 le32_to_cpu(new_carrp->carr_pa));
8735 }
8736
8737 return ADV_SUCCESS;
8738}
8739
8740/*
8741 * Execute a single 'Scsi_Cmnd'.
Matthew Wilcox51219352007-10-02 21:55:22 -04008742 */
8743static int asc_execute_scsi_cmnd(struct scsi_cmnd *scp)
8744{
Matthew Wilcox41d24932007-10-02 21:55:24 -04008745 int ret, err_code;
Matthew Wilcoxd2411492007-10-02 21:55:31 -04008746 struct asc_board *boardp = shost_priv(scp->device->host);
Matthew Wilcox51219352007-10-02 21:55:22 -04008747
Matthew Wilcoxb352f922007-10-02 21:55:33 -04008748 ASC_DBG(1, "scp 0x%p\n", scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04008749
8750 if (ASC_NARROW_BOARD(boardp)) {
Matthew Wilcox41d24932007-10-02 21:55:24 -04008751 ASC_DVC_VAR *asc_dvc = &boardp->dvc_var.asc_dvc_var;
Matthew Wilcox05848b62007-10-02 21:55:25 -04008752 struct asc_scsi_q asc_scsi_q;
Matthew Wilcox51219352007-10-02 21:55:22 -04008753
Matthew Wilcox41d24932007-10-02 21:55:24 -04008754 /* asc_build_req() can not return ASC_BUSY. */
Matthew Wilcox05848b62007-10-02 21:55:25 -04008755 ret = asc_build_req(boardp, scp, &asc_scsi_q);
8756 if (ret == ASC_ERROR) {
Matthew Wilcox51219352007-10-02 21:55:22 -04008757 ASC_STATS(scp->device->host, build_error);
8758 return ASC_ERROR;
8759 }
8760
Matthew Wilcox41d24932007-10-02 21:55:24 -04008761 ret = AscExeScsiQueue(asc_dvc, &asc_scsi_q);
Matthew Wilcox05848b62007-10-02 21:55:25 -04008762 kfree(asc_scsi_q.sg_head);
Matthew Wilcox41d24932007-10-02 21:55:24 -04008763 err_code = asc_dvc->err_code;
Matthew Wilcox51219352007-10-02 21:55:22 -04008764 } else {
Matthew Wilcox41d24932007-10-02 21:55:24 -04008765 ADV_DVC_VAR *adv_dvc = &boardp->dvc_var.adv_dvc_var;
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008766 adv_req_t *adv_reqp;
Matthew Wilcox51219352007-10-02 21:55:22 -04008767
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008768 switch (adv_build_req(boardp, scp, &adv_reqp)) {
Matthew Wilcox51219352007-10-02 21:55:22 -04008769 case ASC_NOERROR:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04008770 ASC_DBG(3, "adv_build_req ASC_NOERROR\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04008771 break;
8772 case ASC_BUSY:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04008773 ASC_DBG(1, "adv_build_req ASC_BUSY\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04008774 /*
8775 * The asc_stats fields 'adv_build_noreq' and
8776 * 'adv_build_nosg' count wide board busy conditions.
8777 * They are updated in adv_build_req and
8778 * adv_get_sglist, respectively.
8779 */
8780 return ASC_BUSY;
8781 case ASC_ERROR:
8782 default:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04008783 ASC_DBG(1, "adv_build_req ASC_ERROR\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04008784 ASC_STATS(scp->device->host, build_error);
8785 return ASC_ERROR;
8786 }
8787
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008788 ret = AdvExeScsiQueue(adv_dvc, adv_reqp);
Matthew Wilcox41d24932007-10-02 21:55:24 -04008789 err_code = adv_dvc->err_code;
8790 }
8791
8792 switch (ret) {
8793 case ASC_NOERROR:
8794 ASC_STATS(scp->device->host, exe_noerror);
8795 /*
8796 * Increment monotonically increasing per device
8797 * successful request counter. Wrapping doesn't matter.
8798 */
8799 boardp->reqcnt[scp->device->id]++;
Matthew Wilcoxb352f922007-10-02 21:55:33 -04008800 ASC_DBG(1, "ExeScsiQueue() ASC_NOERROR\n");
Matthew Wilcox41d24932007-10-02 21:55:24 -04008801 break;
8802 case ASC_BUSY:
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008803 ASC_DBG(1, "ExeScsiQueue() ASC_BUSY\n");
Matthew Wilcox41d24932007-10-02 21:55:24 -04008804 ASC_STATS(scp->device->host, exe_busy);
8805 break;
8806 case ASC_ERROR:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04008807 scmd_printk(KERN_ERR, scp, "ExeScsiQueue() ASC_ERROR, "
8808 "err_code 0x%x\n", err_code);
Matthew Wilcox41d24932007-10-02 21:55:24 -04008809 ASC_STATS(scp->device->host, exe_error);
8810 scp->result = HOST_BYTE(DID_ERROR);
8811 break;
8812 default:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04008813 scmd_printk(KERN_ERR, scp, "ExeScsiQueue() unknown, "
8814 "err_code 0x%x\n", err_code);
Matthew Wilcox41d24932007-10-02 21:55:24 -04008815 ASC_STATS(scp->device->host, exe_unknown);
8816 scp->result = HOST_BYTE(DID_ERROR);
8817 break;
Matthew Wilcox51219352007-10-02 21:55:22 -04008818 }
8819
Matthew Wilcoxb352f922007-10-02 21:55:33 -04008820 ASC_DBG(1, "end\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04008821 return ret;
8822}
8823
8824/*
8825 * advansys_queuecommand() - interrupt-driven I/O entrypoint.
8826 *
8827 * This function always returns 0. Command return status is saved
8828 * in the 'scp' result field.
8829 */
8830static int
Jeff Garzikf2812332010-11-16 02:10:29 -05008831advansys_queuecommand_lck(struct scsi_cmnd *scp, void (*done)(struct scsi_cmnd *))
Matthew Wilcox51219352007-10-02 21:55:22 -04008832{
8833 struct Scsi_Host *shost = scp->device->host;
Matthew Wilcox51219352007-10-02 21:55:22 -04008834 int asc_res, result = 0;
8835
8836 ASC_STATS(shost, queuecommand);
8837 scp->scsi_done = done;
8838
Matthew Wilcox51219352007-10-02 21:55:22 -04008839 asc_res = asc_execute_scsi_cmnd(scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04008840
8841 switch (asc_res) {
8842 case ASC_NOERROR:
8843 break;
8844 case ASC_BUSY:
8845 result = SCSI_MLQUEUE_HOST_BUSY;
8846 break;
8847 case ASC_ERROR:
8848 default:
8849 asc_scsi_done(scp);
8850 break;
8851 }
8852
8853 return result;
8854}
8855
Jeff Garzikf2812332010-11-16 02:10:29 -05008856static DEF_SCSI_QCMD(advansys_queuecommand)
8857
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008858static ushort AscGetEisaChipCfg(PortAddr iop_base)
Matthew Wilcox51219352007-10-02 21:55:22 -04008859{
8860 PortAddr eisa_cfg_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
8861 (PortAddr) (ASC_EISA_CFG_IOP_MASK);
8862 return inpw(eisa_cfg_iop);
8863}
8864
8865/*
8866 * Return the BIOS address of the adapter at the specified
8867 * I/O port and with the specified bus type.
8868 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008869static unsigned short AscGetChipBiosAddress(PortAddr iop_base,
8870 unsigned short bus_type)
Matthew Wilcox51219352007-10-02 21:55:22 -04008871{
8872 unsigned short cfg_lsw;
8873 unsigned short bios_addr;
8874
8875 /*
8876 * The PCI BIOS is re-located by the motherboard BIOS. Because
8877 * of this the driver can not determine where a PCI BIOS is
8878 * loaded and executes.
8879 */
8880 if (bus_type & ASC_IS_PCI)
8881 return 0;
8882
8883 if ((bus_type & ASC_IS_EISA) != 0) {
8884 cfg_lsw = AscGetEisaChipCfg(iop_base);
8885 cfg_lsw &= 0x000F;
8886 bios_addr = ASC_BIOS_MIN_ADDR + cfg_lsw * ASC_BIOS_BANK_SIZE;
8887 return bios_addr;
8888 }
8889
8890 cfg_lsw = AscGetChipCfgLsw(iop_base);
8891
8892 /*
8893 * ISA PnP uses the top bit as the 32K BIOS flag
8894 */
8895 if (bus_type == ASC_IS_ISAPNP)
8896 cfg_lsw &= 0x7FFF;
8897 bios_addr = ASC_BIOS_MIN_ADDR + (cfg_lsw >> 12) * ASC_BIOS_BANK_SIZE;
8898 return bios_addr;
8899}
8900
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008901static uchar AscSetChipScsiID(PortAddr iop_base, uchar new_host_id)
Matthew Wilcox51219352007-10-02 21:55:22 -04008902{
8903 ushort cfg_lsw;
8904
8905 if (AscGetChipScsiID(iop_base) == new_host_id) {
8906 return (new_host_id);
8907 }
8908 cfg_lsw = AscGetChipCfgLsw(iop_base);
8909 cfg_lsw &= 0xF8FF;
8910 cfg_lsw |= (ushort)((new_host_id & ASC_MAX_TID) << 8);
8911 AscSetChipCfgLsw(iop_base, cfg_lsw);
8912 return (AscGetChipScsiID(iop_base));
8913}
8914
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008915static unsigned char AscGetChipScsiCtrl(PortAddr iop_base)
Matthew Wilcox51219352007-10-02 21:55:22 -04008916{
8917 unsigned char sc;
8918
8919 AscSetBank(iop_base, 1);
8920 sc = inp(iop_base + IOP_REG_SC);
8921 AscSetBank(iop_base, 0);
8922 return sc;
8923}
8924
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008925static unsigned char AscGetChipVersion(PortAddr iop_base,
8926 unsigned short bus_type)
Matthew Wilcox51219352007-10-02 21:55:22 -04008927{
8928 if (bus_type & ASC_IS_EISA) {
8929 PortAddr eisa_iop;
8930 unsigned char revision;
8931 eisa_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
8932 (PortAddr) ASC_EISA_REV_IOP_MASK;
8933 revision = inp(eisa_iop);
8934 return ASC_CHIP_MIN_VER_EISA - 1 + revision;
8935 }
8936 return AscGetChipVerNo(iop_base);
8937}
8938
Matthew Wilcox51219352007-10-02 21:55:22 -04008939#ifdef CONFIG_ISA
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008940static void AscEnableIsaDma(uchar dma_channel)
Matthew Wilcox51219352007-10-02 21:55:22 -04008941{
8942 if (dma_channel < 4) {
8943 outp(0x000B, (ushort)(0xC0 | dma_channel));
8944 outp(0x000A, dma_channel);
8945 } else if (dma_channel < 8) {
8946 outp(0x00D6, (ushort)(0xC0 | (dma_channel - 4)));
8947 outp(0x00D4, (ushort)(dma_channel - 4));
8948 }
Matthew Wilcox51219352007-10-02 21:55:22 -04008949}
8950#endif /* CONFIG_ISA */
8951
8952static int AscStopQueueExe(PortAddr iop_base)
8953{
8954 int count = 0;
8955
8956 if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) == 0) {
8957 AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
8958 ASC_STOP_REQ_RISC_STOP);
8959 do {
8960 if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) &
8961 ASC_STOP_ACK_RISC_STOP) {
8962 return (1);
8963 }
8964 mdelay(100);
8965 } while (count++ < 20);
8966 }
8967 return (0);
8968}
8969
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008970static unsigned int AscGetMaxDmaCount(ushort bus_type)
Matthew Wilcox51219352007-10-02 21:55:22 -04008971{
8972 if (bus_type & ASC_IS_ISA)
8973 return ASC_MAX_ISA_DMA_COUNT;
8974 else if (bus_type & (ASC_IS_EISA | ASC_IS_VL))
8975 return ASC_MAX_VL_DMA_COUNT;
8976 return ASC_MAX_PCI_DMA_COUNT;
8977}
8978
8979#ifdef CONFIG_ISA
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008980static ushort AscGetIsaDmaChannel(PortAddr iop_base)
Matthew Wilcox51219352007-10-02 21:55:22 -04008981{
8982 ushort channel;
8983
8984 channel = AscGetChipCfgLsw(iop_base) & 0x0003;
8985 if (channel == 0x03)
8986 return (0);
8987 else if (channel == 0x00)
8988 return (7);
8989 return (channel + 4);
8990}
8991
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008992static ushort AscSetIsaDmaChannel(PortAddr iop_base, ushort dma_channel)
Matthew Wilcox51219352007-10-02 21:55:22 -04008993{
8994 ushort cfg_lsw;
8995 uchar value;
8996
8997 if ((dma_channel >= 5) && (dma_channel <= 7)) {
8998 if (dma_channel == 7)
8999 value = 0x00;
9000 else
9001 value = dma_channel - 4;
9002 cfg_lsw = AscGetChipCfgLsw(iop_base) & 0xFFFC;
9003 cfg_lsw |= value;
9004 AscSetChipCfgLsw(iop_base, cfg_lsw);
9005 return (AscGetIsaDmaChannel(iop_base));
9006 }
9007 return 0;
9008}
9009
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009010static uchar AscGetIsaDmaSpeed(PortAddr iop_base)
Matthew Wilcox51219352007-10-02 21:55:22 -04009011{
9012 uchar speed_value;
9013
9014 AscSetBank(iop_base, 1);
9015 speed_value = AscReadChipDmaSpeed(iop_base);
9016 speed_value &= 0x07;
9017 AscSetBank(iop_base, 0);
9018 return speed_value;
9019}
9020
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009021static uchar AscSetIsaDmaSpeed(PortAddr iop_base, uchar speed_value)
Matthew Wilcox51219352007-10-02 21:55:22 -04009022{
9023 speed_value &= 0x07;
9024 AscSetBank(iop_base, 1);
9025 AscWriteChipDmaSpeed(iop_base, speed_value);
9026 AscSetBank(iop_base, 0);
9027 return AscGetIsaDmaSpeed(iop_base);
9028}
9029#endif /* CONFIG_ISA */
9030
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009031static ushort AscInitAscDvcVar(ASC_DVC_VAR *asc_dvc)
Matthew Wilcox51219352007-10-02 21:55:22 -04009032{
9033 int i;
9034 PortAddr iop_base;
9035 ushort warn_code;
9036 uchar chip_version;
9037
9038 iop_base = asc_dvc->iop_base;
9039 warn_code = 0;
9040 asc_dvc->err_code = 0;
9041 if ((asc_dvc->bus_type &
9042 (ASC_IS_ISA | ASC_IS_PCI | ASC_IS_EISA | ASC_IS_VL)) == 0) {
9043 asc_dvc->err_code |= ASC_IERR_NO_BUS_TYPE;
9044 }
9045 AscSetChipControl(iop_base, CC_HALT);
9046 AscSetChipStatus(iop_base, 0);
9047 asc_dvc->bug_fix_cntl = 0;
9048 asc_dvc->pci_fix_asyn_xfer = 0;
9049 asc_dvc->pci_fix_asyn_xfer_always = 0;
Uwe Kleine-König421f91d2010-06-11 12:17:00 +02009050 /* asc_dvc->init_state initialized in AscInitGetConfig(). */
Matthew Wilcox51219352007-10-02 21:55:22 -04009051 asc_dvc->sdtr_done = 0;
9052 asc_dvc->cur_total_qng = 0;
Hannes Reineckeae267592015-04-24 13:18:28 +02009053 asc_dvc->is_in_int = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04009054 asc_dvc->in_critical_cnt = 0;
9055 asc_dvc->last_q_shortage = 0;
9056 asc_dvc->use_tagged_qng = 0;
9057 asc_dvc->no_scam = 0;
9058 asc_dvc->unit_not_ready = 0;
9059 asc_dvc->queue_full_or_busy = 0;
9060 asc_dvc->redo_scam = 0;
9061 asc_dvc->res2 = 0;
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04009062 asc_dvc->min_sdtr_index = 0;
Matthew Wilcox51219352007-10-02 21:55:22 -04009063 asc_dvc->cfg->can_tagged_qng = 0;
9064 asc_dvc->cfg->cmd_qng_enabled = 0;
9065 asc_dvc->dvc_cntl = ASC_DEF_DVC_CNTL;
9066 asc_dvc->init_sdtr = 0;
9067 asc_dvc->max_total_qng = ASC_DEF_MAX_TOTAL_QNG;
9068 asc_dvc->scsi_reset_wait = 3;
9069 asc_dvc->start_motor = ASC_SCSI_WIDTH_BIT_SET;
9070 asc_dvc->max_dma_count = AscGetMaxDmaCount(asc_dvc->bus_type);
9071 asc_dvc->cfg->sdtr_enable = ASC_SCSI_WIDTH_BIT_SET;
9072 asc_dvc->cfg->disc_enable = ASC_SCSI_WIDTH_BIT_SET;
9073 asc_dvc->cfg->chip_scsi_id = ASC_DEF_CHIP_SCSI_ID;
Matthew Wilcox51219352007-10-02 21:55:22 -04009074 chip_version = AscGetChipVersion(iop_base, asc_dvc->bus_type);
9075 asc_dvc->cfg->chip_version = chip_version;
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04009076 asc_dvc->sdtr_period_tbl = asc_syn_xfer_period;
Matthew Wilcox51219352007-10-02 21:55:22 -04009077 asc_dvc->max_sdtr_index = 7;
9078 if ((asc_dvc->bus_type & ASC_IS_PCI) &&
9079 (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3150)) {
9080 asc_dvc->bus_type = ASC_IS_PCI_ULTRA;
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04009081 asc_dvc->sdtr_period_tbl = asc_syn_ultra_xfer_period;
Matthew Wilcox51219352007-10-02 21:55:22 -04009082 asc_dvc->max_sdtr_index = 15;
9083 if (chip_version == ASC_CHIP_VER_PCI_ULTRA_3150) {
9084 AscSetExtraControl(iop_base,
9085 (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
9086 } else if (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3050) {
9087 AscSetExtraControl(iop_base,
9088 (SEC_ACTIVE_NEGATE |
9089 SEC_ENABLE_FILTER));
9090 }
9091 }
9092 if (asc_dvc->bus_type == ASC_IS_PCI) {
9093 AscSetExtraControl(iop_base,
9094 (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
9095 }
9096
9097 asc_dvc->cfg->isa_dma_speed = ASC_DEF_ISA_DMA_SPEED;
9098#ifdef CONFIG_ISA
9099 if ((asc_dvc->bus_type & ASC_IS_ISA) != 0) {
9100 if (chip_version >= ASC_CHIP_MIN_VER_ISA_PNP) {
9101 AscSetChipIFC(iop_base, IFC_INIT_DEFAULT);
9102 asc_dvc->bus_type = ASC_IS_ISAPNP;
9103 }
9104 asc_dvc->cfg->isa_dma_channel =
9105 (uchar)AscGetIsaDmaChannel(iop_base);
9106 }
9107#endif /* CONFIG_ISA */
9108 for (i = 0; i <= ASC_MAX_TID; i++) {
9109 asc_dvc->cur_dvc_qng[i] = 0;
9110 asc_dvc->max_dvc_qng[i] = ASC_MAX_SCSI1_QNG;
9111 asc_dvc->scsiq_busy_head[i] = (ASC_SCSI_Q *)0L;
9112 asc_dvc->scsiq_busy_tail[i] = (ASC_SCSI_Q *)0L;
9113 asc_dvc->cfg->max_tag_qng[i] = ASC_MAX_INRAM_TAG_QNG;
9114 }
9115 return warn_code;
9116}
9117
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009118static int AscWriteEEPCmdReg(PortAddr iop_base, uchar cmd_reg)
Matthew Wilcox51219352007-10-02 21:55:22 -04009119{
9120 int retry;
9121
9122 for (retry = 0; retry < ASC_EEP_MAX_RETRY; retry++) {
9123 unsigned char read_back;
9124 AscSetChipEEPCmd(iop_base, cmd_reg);
9125 mdelay(1);
9126 read_back = AscGetChipEEPCmd(iop_base);
9127 if (read_back == cmd_reg)
9128 return 1;
9129 }
9130 return 0;
9131}
9132
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009133static void AscWaitEEPRead(void)
Matthew Wilcox51219352007-10-02 21:55:22 -04009134{
9135 mdelay(1);
9136}
9137
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009138static ushort AscReadEEPWord(PortAddr iop_base, uchar addr)
Matthew Wilcox51219352007-10-02 21:55:22 -04009139{
9140 ushort read_wval;
9141 uchar cmd_reg;
9142
9143 AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
9144 AscWaitEEPRead();
9145 cmd_reg = addr | ASC_EEP_CMD_READ;
9146 AscWriteEEPCmdReg(iop_base, cmd_reg);
9147 AscWaitEEPRead();
9148 read_wval = AscGetChipEEPData(iop_base);
9149 AscWaitEEPRead();
9150 return read_wval;
9151}
9152
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009153static ushort AscGetEEPConfig(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf,
9154 ushort bus_type)
Matthew Wilcox51219352007-10-02 21:55:22 -04009155{
9156 ushort wval;
9157 ushort sum;
9158 ushort *wbuf;
9159 int cfg_beg;
9160 int cfg_end;
9161 int uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
9162 int s_addr;
9163
9164 wbuf = (ushort *)cfg_buf;
9165 sum = 0;
9166 /* Read two config words; Byte-swapping done by AscReadEEPWord(). */
9167 for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
9168 *wbuf = AscReadEEPWord(iop_base, (uchar)s_addr);
9169 sum += *wbuf;
9170 }
9171 if (bus_type & ASC_IS_VL) {
9172 cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
9173 cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
9174 } else {
9175 cfg_beg = ASC_EEP_DVC_CFG_BEG;
9176 cfg_end = ASC_EEP_MAX_DVC_ADDR;
9177 }
9178 for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
9179 wval = AscReadEEPWord(iop_base, (uchar)s_addr);
9180 if (s_addr <= uchar_end_in_config) {
9181 /*
9182 * Swap all char fields - must unswap bytes already swapped
9183 * by AscReadEEPWord().
9184 */
9185 *wbuf = le16_to_cpu(wval);
9186 } else {
9187 /* Don't swap word field at the end - cntl field. */
9188 *wbuf = wval;
9189 }
9190 sum += wval; /* Checksum treats all EEPROM data as words. */
9191 }
9192 /*
9193 * Read the checksum word which will be compared against 'sum'
9194 * by the caller. Word field already swapped.
9195 */
9196 *wbuf = AscReadEEPWord(iop_base, (uchar)s_addr);
9197 return sum;
9198}
9199
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009200static int AscTestExternalLram(ASC_DVC_VAR *asc_dvc)
Matthew Wilcox51219352007-10-02 21:55:22 -04009201{
9202 PortAddr iop_base;
9203 ushort q_addr;
9204 ushort saved_word;
9205 int sta;
9206
9207 iop_base = asc_dvc->iop_base;
9208 sta = 0;
9209 q_addr = ASC_QNO_TO_QADDR(241);
9210 saved_word = AscReadLramWord(iop_base, q_addr);
9211 AscSetChipLramAddr(iop_base, q_addr);
9212 AscSetChipLramData(iop_base, 0x55AA);
9213 mdelay(10);
9214 AscSetChipLramAddr(iop_base, q_addr);
9215 if (AscGetChipLramData(iop_base) == 0x55AA) {
9216 sta = 1;
9217 AscWriteLramWord(iop_base, q_addr, saved_word);
9218 }
9219 return (sta);
9220}
9221
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009222static void AscWaitEEPWrite(void)
Matthew Wilcox51219352007-10-02 21:55:22 -04009223{
9224 mdelay(20);
Matthew Wilcox51219352007-10-02 21:55:22 -04009225}
9226
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009227static int AscWriteEEPDataReg(PortAddr iop_base, ushort data_reg)
Matthew Wilcox51219352007-10-02 21:55:22 -04009228{
9229 ushort read_back;
9230 int retry;
9231
9232 retry = 0;
Hannes Reineckeae267592015-04-24 13:18:28 +02009233 while (true) {
Matthew Wilcox51219352007-10-02 21:55:22 -04009234 AscSetChipEEPData(iop_base, data_reg);
9235 mdelay(1);
9236 read_back = AscGetChipEEPData(iop_base);
9237 if (read_back == data_reg) {
9238 return (1);
9239 }
9240 if (retry++ > ASC_EEP_MAX_RETRY) {
9241 return (0);
9242 }
9243 }
9244}
9245
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009246static ushort AscWriteEEPWord(PortAddr iop_base, uchar addr, ushort word_val)
Matthew Wilcox51219352007-10-02 21:55:22 -04009247{
9248 ushort read_wval;
9249
9250 read_wval = AscReadEEPWord(iop_base, addr);
9251 if (read_wval != word_val) {
9252 AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_ABLE);
9253 AscWaitEEPRead();
9254 AscWriteEEPDataReg(iop_base, word_val);
9255 AscWaitEEPRead();
9256 AscWriteEEPCmdReg(iop_base,
9257 (uchar)((uchar)ASC_EEP_CMD_WRITE | addr));
9258 AscWaitEEPWrite();
9259 AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
9260 AscWaitEEPRead();
9261 return (AscReadEEPWord(iop_base, addr));
9262 }
9263 return (read_wval);
9264}
9265
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009266static int AscSetEEPConfigOnce(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf,
9267 ushort bus_type)
Matthew Wilcox51219352007-10-02 21:55:22 -04009268{
9269 int n_error;
9270 ushort *wbuf;
9271 ushort word;
9272 ushort sum;
9273 int s_addr;
9274 int cfg_beg;
9275 int cfg_end;
9276 int uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
9277
9278 wbuf = (ushort *)cfg_buf;
9279 n_error = 0;
9280 sum = 0;
9281 /* Write two config words; AscWriteEEPWord() will swap bytes. */
9282 for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
9283 sum += *wbuf;
9284 if (*wbuf != AscWriteEEPWord(iop_base, (uchar)s_addr, *wbuf)) {
9285 n_error++;
9286 }
9287 }
9288 if (bus_type & ASC_IS_VL) {
9289 cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
9290 cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
9291 } else {
9292 cfg_beg = ASC_EEP_DVC_CFG_BEG;
9293 cfg_end = ASC_EEP_MAX_DVC_ADDR;
9294 }
9295 for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
9296 if (s_addr <= uchar_end_in_config) {
9297 /*
9298 * This is a char field. Swap char fields before they are
9299 * swapped again by AscWriteEEPWord().
9300 */
9301 word = cpu_to_le16(*wbuf);
9302 if (word !=
9303 AscWriteEEPWord(iop_base, (uchar)s_addr, word)) {
9304 n_error++;
9305 }
9306 } else {
9307 /* Don't swap word field at the end - cntl field. */
9308 if (*wbuf !=
9309 AscWriteEEPWord(iop_base, (uchar)s_addr, *wbuf)) {
9310 n_error++;
9311 }
9312 }
9313 sum += *wbuf; /* Checksum calculated from word values. */
9314 }
9315 /* Write checksum word. It will be swapped by AscWriteEEPWord(). */
9316 *wbuf = sum;
9317 if (sum != AscWriteEEPWord(iop_base, (uchar)s_addr, sum)) {
9318 n_error++;
9319 }
9320
9321 /* Read EEPROM back again. */
9322 wbuf = (ushort *)cfg_buf;
9323 /*
9324 * Read two config words; Byte-swapping done by AscReadEEPWord().
9325 */
9326 for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
9327 if (*wbuf != AscReadEEPWord(iop_base, (uchar)s_addr)) {
9328 n_error++;
9329 }
9330 }
9331 if (bus_type & ASC_IS_VL) {
9332 cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
9333 cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
9334 } else {
9335 cfg_beg = ASC_EEP_DVC_CFG_BEG;
9336 cfg_end = ASC_EEP_MAX_DVC_ADDR;
9337 }
9338 for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
9339 if (s_addr <= uchar_end_in_config) {
9340 /*
9341 * Swap all char fields. Must unswap bytes already swapped
9342 * by AscReadEEPWord().
9343 */
9344 word =
9345 le16_to_cpu(AscReadEEPWord
9346 (iop_base, (uchar)s_addr));
9347 } else {
9348 /* Don't swap word field at the end - cntl field. */
9349 word = AscReadEEPWord(iop_base, (uchar)s_addr);
9350 }
9351 if (*wbuf != word) {
9352 n_error++;
9353 }
9354 }
9355 /* Read checksum; Byte swapping not needed. */
9356 if (AscReadEEPWord(iop_base, (uchar)s_addr) != sum) {
9357 n_error++;
9358 }
9359 return n_error;
9360}
9361
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009362static int AscSetEEPConfig(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf,
9363 ushort bus_type)
Matthew Wilcox51219352007-10-02 21:55:22 -04009364{
9365 int retry;
9366 int n_error;
9367
9368 retry = 0;
Hannes Reineckeae267592015-04-24 13:18:28 +02009369 while (true) {
Matthew Wilcox51219352007-10-02 21:55:22 -04009370 if ((n_error = AscSetEEPConfigOnce(iop_base, cfg_buf,
9371 bus_type)) == 0) {
9372 break;
9373 }
9374 if (++retry > ASC_EEP_MAX_RETRY) {
9375 break;
9376 }
9377 }
9378 return n_error;
9379}
9380
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009381static ushort AscInitFromEEP(ASC_DVC_VAR *asc_dvc)
Matthew Wilcox51219352007-10-02 21:55:22 -04009382{
9383 ASCEEP_CONFIG eep_config_buf;
9384 ASCEEP_CONFIG *eep_config;
9385 PortAddr iop_base;
9386 ushort chksum;
9387 ushort warn_code;
9388 ushort cfg_msw, cfg_lsw;
9389 int i;
9390 int write_eep = 0;
9391
9392 iop_base = asc_dvc->iop_base;
9393 warn_code = 0;
9394 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0x00FE);
9395 AscStopQueueExe(iop_base);
Hannes Reineckeae267592015-04-24 13:18:28 +02009396 if ((AscStopChip(iop_base)) ||
Matthew Wilcox51219352007-10-02 21:55:22 -04009397 (AscGetChipScsiCtrl(iop_base) != 0)) {
9398 asc_dvc->init_state |= ASC_INIT_RESET_SCSI_DONE;
9399 AscResetChipAndScsiBus(asc_dvc);
9400 mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
9401 }
Hannes Reinecked647c782015-04-24 13:18:26 +02009402 if (!AscIsChipHalted(iop_base)) {
Matthew Wilcox51219352007-10-02 21:55:22 -04009403 asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
9404 return (warn_code);
9405 }
9406 AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
9407 if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
9408 asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
9409 return (warn_code);
9410 }
9411 eep_config = (ASCEEP_CONFIG *)&eep_config_buf;
9412 cfg_msw = AscGetChipCfgMsw(iop_base);
9413 cfg_lsw = AscGetChipCfgLsw(iop_base);
9414 if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
9415 cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
9416 warn_code |= ASC_WARN_CFG_MSW_RECOVER;
9417 AscSetChipCfgMsw(iop_base, cfg_msw);
9418 }
9419 chksum = AscGetEEPConfig(iop_base, eep_config, asc_dvc->bus_type);
Matthew Wilcoxb352f922007-10-02 21:55:33 -04009420 ASC_DBG(1, "chksum 0x%x\n", chksum);
Matthew Wilcox51219352007-10-02 21:55:22 -04009421 if (chksum == 0) {
9422 chksum = 0xaa55;
9423 }
9424 if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
9425 warn_code |= ASC_WARN_AUTO_CONFIG;
9426 if (asc_dvc->cfg->chip_version == 3) {
9427 if (eep_config->cfg_lsw != cfg_lsw) {
9428 warn_code |= ASC_WARN_EEPROM_RECOVER;
9429 eep_config->cfg_lsw =
9430 AscGetChipCfgLsw(iop_base);
9431 }
9432 if (eep_config->cfg_msw != cfg_msw) {
9433 warn_code |= ASC_WARN_EEPROM_RECOVER;
9434 eep_config->cfg_msw =
9435 AscGetChipCfgMsw(iop_base);
9436 }
9437 }
9438 }
9439 eep_config->cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
9440 eep_config->cfg_lsw |= ASC_CFG0_HOST_INT_ON;
Matthew Wilcoxb352f922007-10-02 21:55:33 -04009441 ASC_DBG(1, "eep_config->chksum 0x%x\n", eep_config->chksum);
Matthew Wilcox51219352007-10-02 21:55:22 -04009442 if (chksum != eep_config->chksum) {
9443 if (AscGetChipVersion(iop_base, asc_dvc->bus_type) ==
9444 ASC_CHIP_VER_PCI_ULTRA_3050) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04009445 ASC_DBG(1, "chksum error ignored; EEPROM-less board\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009446 eep_config->init_sdtr = 0xFF;
9447 eep_config->disc_enable = 0xFF;
9448 eep_config->start_motor = 0xFF;
9449 eep_config->use_cmd_qng = 0;
9450 eep_config->max_total_qng = 0xF0;
9451 eep_config->max_tag_qng = 0x20;
9452 eep_config->cntl = 0xBFFF;
9453 ASC_EEP_SET_CHIP_ID(eep_config, 7);
9454 eep_config->no_scam = 0;
9455 eep_config->adapter_info[0] = 0;
9456 eep_config->adapter_info[1] = 0;
9457 eep_config->adapter_info[2] = 0;
9458 eep_config->adapter_info[3] = 0;
9459 eep_config->adapter_info[4] = 0;
9460 /* Indicate EEPROM-less board. */
9461 eep_config->adapter_info[5] = 0xBB;
9462 } else {
9463 ASC_PRINT
9464 ("AscInitFromEEP: EEPROM checksum error; Will try to re-write EEPROM.\n");
9465 write_eep = 1;
9466 warn_code |= ASC_WARN_EEPROM_CHKSUM;
9467 }
9468 }
9469 asc_dvc->cfg->sdtr_enable = eep_config->init_sdtr;
9470 asc_dvc->cfg->disc_enable = eep_config->disc_enable;
9471 asc_dvc->cfg->cmd_qng_enabled = eep_config->use_cmd_qng;
9472 asc_dvc->cfg->isa_dma_speed = ASC_EEP_GET_DMA_SPD(eep_config);
9473 asc_dvc->start_motor = eep_config->start_motor;
9474 asc_dvc->dvc_cntl = eep_config->cntl;
9475 asc_dvc->no_scam = eep_config->no_scam;
9476 asc_dvc->cfg->adapter_info[0] = eep_config->adapter_info[0];
9477 asc_dvc->cfg->adapter_info[1] = eep_config->adapter_info[1];
9478 asc_dvc->cfg->adapter_info[2] = eep_config->adapter_info[2];
9479 asc_dvc->cfg->adapter_info[3] = eep_config->adapter_info[3];
9480 asc_dvc->cfg->adapter_info[4] = eep_config->adapter_info[4];
9481 asc_dvc->cfg->adapter_info[5] = eep_config->adapter_info[5];
9482 if (!AscTestExternalLram(asc_dvc)) {
9483 if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) ==
9484 ASC_IS_PCI_ULTRA)) {
9485 eep_config->max_total_qng =
9486 ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG;
9487 eep_config->max_tag_qng =
9488 ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG;
9489 } else {
9490 eep_config->cfg_msw |= 0x0800;
9491 cfg_msw |= 0x0800;
9492 AscSetChipCfgMsw(iop_base, cfg_msw);
9493 eep_config->max_total_qng = ASC_MAX_PCI_INRAM_TOTAL_QNG;
9494 eep_config->max_tag_qng = ASC_MAX_INRAM_TAG_QNG;
9495 }
9496 } else {
9497 }
9498 if (eep_config->max_total_qng < ASC_MIN_TOTAL_QNG) {
9499 eep_config->max_total_qng = ASC_MIN_TOTAL_QNG;
9500 }
9501 if (eep_config->max_total_qng > ASC_MAX_TOTAL_QNG) {
9502 eep_config->max_total_qng = ASC_MAX_TOTAL_QNG;
9503 }
9504 if (eep_config->max_tag_qng > eep_config->max_total_qng) {
9505 eep_config->max_tag_qng = eep_config->max_total_qng;
9506 }
9507 if (eep_config->max_tag_qng < ASC_MIN_TAG_Q_PER_DVC) {
9508 eep_config->max_tag_qng = ASC_MIN_TAG_Q_PER_DVC;
9509 }
9510 asc_dvc->max_total_qng = eep_config->max_total_qng;
9511 if ((eep_config->use_cmd_qng & eep_config->disc_enable) !=
9512 eep_config->use_cmd_qng) {
9513 eep_config->disc_enable = eep_config->use_cmd_qng;
9514 warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
9515 }
Matthew Wilcox51219352007-10-02 21:55:22 -04009516 ASC_EEP_SET_CHIP_ID(eep_config,
9517 ASC_EEP_GET_CHIP_ID(eep_config) & ASC_MAX_TID);
9518 asc_dvc->cfg->chip_scsi_id = ASC_EEP_GET_CHIP_ID(eep_config);
9519 if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) &&
9520 !(asc_dvc->dvc_cntl & ASC_CNTL_SDTR_ENABLE_ULTRA)) {
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04009521 asc_dvc->min_sdtr_index = ASC_SDTR_ULTRA_PCI_10MB_INDEX;
Matthew Wilcox51219352007-10-02 21:55:22 -04009522 }
9523
9524 for (i = 0; i <= ASC_MAX_TID; i++) {
9525 asc_dvc->dos_int13_table[i] = eep_config->dos_int13_table[i];
9526 asc_dvc->cfg->max_tag_qng[i] = eep_config->max_tag_qng;
9527 asc_dvc->cfg->sdtr_period_offset[i] =
9528 (uchar)(ASC_DEF_SDTR_OFFSET |
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04009529 (asc_dvc->min_sdtr_index << 4));
Matthew Wilcox51219352007-10-02 21:55:22 -04009530 }
9531 eep_config->cfg_msw = AscGetChipCfgMsw(iop_base);
9532 if (write_eep) {
9533 if ((i = AscSetEEPConfig(iop_base, eep_config,
9534 asc_dvc->bus_type)) != 0) {
9535 ASC_PRINT1
9536 ("AscInitFromEEP: Failed to re-write EEPROM with %d errors.\n",
9537 i);
9538 } else {
9539 ASC_PRINT
9540 ("AscInitFromEEP: Successfully re-wrote EEPROM.\n");
9541 }
9542 }
9543 return (warn_code);
9544}
9545
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009546static int AscInitGetConfig(struct Scsi_Host *shost)
Matthew Wilcox51219352007-10-02 21:55:22 -04009547{
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009548 struct asc_board *board = shost_priv(shost);
9549 ASC_DVC_VAR *asc_dvc = &board->dvc_var.asc_dvc_var;
Matthew Wilcox51219352007-10-02 21:55:22 -04009550 unsigned short warn_code = 0;
9551
9552 asc_dvc->init_state = ASC_INIT_STATE_BEG_GET_CFG;
9553 if (asc_dvc->err_code != 0)
9554 return asc_dvc->err_code;
9555
9556 if (AscFindSignature(asc_dvc->iop_base)) {
9557 warn_code |= AscInitAscDvcVar(asc_dvc);
9558 warn_code |= AscInitFromEEP(asc_dvc);
9559 asc_dvc->init_state |= ASC_INIT_STATE_END_GET_CFG;
9560 if (asc_dvc->scsi_reset_wait > ASC_MAX_SCSI_RESET_WAIT)
9561 asc_dvc->scsi_reset_wait = ASC_MAX_SCSI_RESET_WAIT;
9562 } else {
9563 asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
9564 }
9565
9566 switch (warn_code) {
9567 case 0: /* No error */
9568 break;
9569 case ASC_WARN_IO_PORT_ROTATE:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009570 shost_printk(KERN_WARNING, shost, "I/O port address "
9571 "modified\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009572 break;
9573 case ASC_WARN_AUTO_CONFIG:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009574 shost_printk(KERN_WARNING, shost, "I/O port increment switch "
9575 "enabled\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009576 break;
9577 case ASC_WARN_EEPROM_CHKSUM:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009578 shost_printk(KERN_WARNING, shost, "EEPROM checksum error\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009579 break;
9580 case ASC_WARN_IRQ_MODIFIED:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009581 shost_printk(KERN_WARNING, shost, "IRQ modified\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009582 break;
9583 case ASC_WARN_CMD_QNG_CONFLICT:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009584 shost_printk(KERN_WARNING, shost, "tag queuing enabled w/o "
9585 "disconnects\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009586 break;
9587 default:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009588 shost_printk(KERN_WARNING, shost, "unknown warning: 0x%x\n",
9589 warn_code);
Matthew Wilcox51219352007-10-02 21:55:22 -04009590 break;
9591 }
9592
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009593 if (asc_dvc->err_code != 0)
9594 shost_printk(KERN_ERR, shost, "error 0x%x at init_state "
9595 "0x%x\n", asc_dvc->err_code, asc_dvc->init_state);
Matthew Wilcox51219352007-10-02 21:55:22 -04009596
9597 return asc_dvc->err_code;
9598}
9599
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009600static int AscInitSetConfig(struct pci_dev *pdev, struct Scsi_Host *shost)
Matthew Wilcox51219352007-10-02 21:55:22 -04009601{
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009602 struct asc_board *board = shost_priv(shost);
9603 ASC_DVC_VAR *asc_dvc = &board->dvc_var.asc_dvc_var;
Matthew Wilcox51219352007-10-02 21:55:22 -04009604 PortAddr iop_base = asc_dvc->iop_base;
9605 unsigned short cfg_msw;
9606 unsigned short warn_code = 0;
9607
9608 asc_dvc->init_state |= ASC_INIT_STATE_BEG_SET_CFG;
9609 if (asc_dvc->err_code != 0)
9610 return asc_dvc->err_code;
9611 if (!AscFindSignature(asc_dvc->iop_base)) {
9612 asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
9613 return asc_dvc->err_code;
9614 }
9615
9616 cfg_msw = AscGetChipCfgMsw(iop_base);
9617 if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
9618 cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
9619 warn_code |= ASC_WARN_CFG_MSW_RECOVER;
9620 AscSetChipCfgMsw(iop_base, cfg_msw);
9621 }
9622 if ((asc_dvc->cfg->cmd_qng_enabled & asc_dvc->cfg->disc_enable) !=
9623 asc_dvc->cfg->cmd_qng_enabled) {
9624 asc_dvc->cfg->disc_enable = asc_dvc->cfg->cmd_qng_enabled;
9625 warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
9626 }
9627 if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
9628 warn_code |= ASC_WARN_AUTO_CONFIG;
9629 }
Matthew Wilcox51219352007-10-02 21:55:22 -04009630#ifdef CONFIG_PCI
9631 if (asc_dvc->bus_type & ASC_IS_PCI) {
9632 cfg_msw &= 0xFFC0;
9633 AscSetChipCfgMsw(iop_base, cfg_msw);
9634 if ((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) {
9635 } else {
9636 if ((pdev->device == PCI_DEVICE_ID_ASP_1200A) ||
9637 (pdev->device == PCI_DEVICE_ID_ASP_ABP940)) {
9638 asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_IF_NOT_DWB;
9639 asc_dvc->bug_fix_cntl |=
9640 ASC_BUG_FIX_ASYN_USE_SYN;
9641 }
9642 }
9643 } else
9644#endif /* CONFIG_PCI */
9645 if (asc_dvc->bus_type == ASC_IS_ISAPNP) {
9646 if (AscGetChipVersion(iop_base, asc_dvc->bus_type)
9647 == ASC_CHIP_VER_ASYN_BUG) {
9648 asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_ASYN_USE_SYN;
9649 }
9650 }
9651 if (AscSetChipScsiID(iop_base, asc_dvc->cfg->chip_scsi_id) !=
9652 asc_dvc->cfg->chip_scsi_id) {
9653 asc_dvc->err_code |= ASC_IERR_SET_SCSI_ID;
9654 }
9655#ifdef CONFIG_ISA
9656 if (asc_dvc->bus_type & ASC_IS_ISA) {
9657 AscSetIsaDmaChannel(iop_base, asc_dvc->cfg->isa_dma_channel);
9658 AscSetIsaDmaSpeed(iop_base, asc_dvc->cfg->isa_dma_speed);
9659 }
9660#endif /* CONFIG_ISA */
9661
9662 asc_dvc->init_state |= ASC_INIT_STATE_END_SET_CFG;
9663
9664 switch (warn_code) {
9665 case 0: /* No error. */
9666 break;
9667 case ASC_WARN_IO_PORT_ROTATE:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009668 shost_printk(KERN_WARNING, shost, "I/O port address "
9669 "modified\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009670 break;
9671 case ASC_WARN_AUTO_CONFIG:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009672 shost_printk(KERN_WARNING, shost, "I/O port increment switch "
9673 "enabled\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009674 break;
9675 case ASC_WARN_EEPROM_CHKSUM:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009676 shost_printk(KERN_WARNING, shost, "EEPROM checksum error\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009677 break;
9678 case ASC_WARN_IRQ_MODIFIED:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009679 shost_printk(KERN_WARNING, shost, "IRQ modified\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009680 break;
9681 case ASC_WARN_CMD_QNG_CONFLICT:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009682 shost_printk(KERN_WARNING, shost, "tag queuing w/o "
9683 "disconnects\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009684 break;
9685 default:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009686 shost_printk(KERN_WARNING, shost, "unknown warning: 0x%x\n",
9687 warn_code);
Matthew Wilcox51219352007-10-02 21:55:22 -04009688 break;
9689 }
9690
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009691 if (asc_dvc->err_code != 0)
9692 shost_printk(KERN_ERR, shost, "error 0x%x at init_state "
9693 "0x%x\n", asc_dvc->err_code, asc_dvc->init_state);
Matthew Wilcox51219352007-10-02 21:55:22 -04009694
9695 return asc_dvc->err_code;
9696}
9697
9698/*
9699 * EEPROM Configuration.
9700 *
9701 * All drivers should use this structure to set the default EEPROM
9702 * configuration. The BIOS now uses this structure when it is built.
9703 * Additional structure information can be found in a_condor.h where
9704 * the structure is defined.
9705 *
9706 * The *_Field_IsChar structs are needed to correct for endianness.
9707 * These values are read from the board 16 bits at a time directly
9708 * into the structs. Because some fields are char, the values will be
9709 * in the wrong order. The *_Field_IsChar tells when to flip the
9710 * bytes. Data read and written to PCI memory is automatically swapped
9711 * on big-endian platforms so char fields read as words are actually being
9712 * unswapped on big-endian platforms.
9713 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009714static ADVEEP_3550_CONFIG Default_3550_EEPROM_Config = {
Matthew Wilcox51219352007-10-02 21:55:22 -04009715 ADV_EEPROM_BIOS_ENABLE, /* cfg_lsw */
9716 0x0000, /* cfg_msw */
9717 0xFFFF, /* disc_enable */
9718 0xFFFF, /* wdtr_able */
9719 0xFFFF, /* sdtr_able */
9720 0xFFFF, /* start_motor */
9721 0xFFFF, /* tagqng_able */
9722 0xFFFF, /* bios_scan */
9723 0, /* scam_tolerant */
9724 7, /* adapter_scsi_id */
9725 0, /* bios_boot_delay */
9726 3, /* scsi_reset_delay */
9727 0, /* bios_id_lun */
9728 0, /* termination */
9729 0, /* reserved1 */
9730 0xFFE7, /* bios_ctrl */
9731 0xFFFF, /* ultra_able */
9732 0, /* reserved2 */
9733 ASC_DEF_MAX_HOST_QNG, /* max_host_qng */
9734 ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
9735 0, /* dvc_cntl */
9736 0, /* bug_fix */
9737 0, /* serial_number_word1 */
9738 0, /* serial_number_word2 */
9739 0, /* serial_number_word3 */
9740 0, /* check_sum */
9741 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
9742 , /* oem_name[16] */
9743 0, /* dvc_err_code */
9744 0, /* adv_err_code */
9745 0, /* adv_err_addr */
9746 0, /* saved_dvc_err_code */
9747 0, /* saved_adv_err_code */
9748 0, /* saved_adv_err_addr */
9749 0 /* num_of_err */
9750};
9751
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009752static ADVEEP_3550_CONFIG ADVEEP_3550_Config_Field_IsChar = {
Matthew Wilcox51219352007-10-02 21:55:22 -04009753 0, /* cfg_lsw */
9754 0, /* cfg_msw */
9755 0, /* -disc_enable */
9756 0, /* wdtr_able */
9757 0, /* sdtr_able */
9758 0, /* start_motor */
9759 0, /* tagqng_able */
9760 0, /* bios_scan */
9761 0, /* scam_tolerant */
9762 1, /* adapter_scsi_id */
9763 1, /* bios_boot_delay */
9764 1, /* scsi_reset_delay */
9765 1, /* bios_id_lun */
9766 1, /* termination */
9767 1, /* reserved1 */
9768 0, /* bios_ctrl */
9769 0, /* ultra_able */
9770 0, /* reserved2 */
9771 1, /* max_host_qng */
9772 1, /* max_dvc_qng */
9773 0, /* dvc_cntl */
9774 0, /* bug_fix */
9775 0, /* serial_number_word1 */
9776 0, /* serial_number_word2 */
9777 0, /* serial_number_word3 */
9778 0, /* check_sum */
9779 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
9780 , /* oem_name[16] */
9781 0, /* dvc_err_code */
9782 0, /* adv_err_code */
9783 0, /* adv_err_addr */
9784 0, /* saved_dvc_err_code */
9785 0, /* saved_adv_err_code */
9786 0, /* saved_adv_err_addr */
9787 0 /* num_of_err */
9788};
9789
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009790static ADVEEP_38C0800_CONFIG Default_38C0800_EEPROM_Config = {
Matthew Wilcox51219352007-10-02 21:55:22 -04009791 ADV_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */
9792 0x0000, /* 01 cfg_msw */
9793 0xFFFF, /* 02 disc_enable */
9794 0xFFFF, /* 03 wdtr_able */
9795 0x4444, /* 04 sdtr_speed1 */
9796 0xFFFF, /* 05 start_motor */
9797 0xFFFF, /* 06 tagqng_able */
9798 0xFFFF, /* 07 bios_scan */
9799 0, /* 08 scam_tolerant */
9800 7, /* 09 adapter_scsi_id */
9801 0, /* bios_boot_delay */
9802 3, /* 10 scsi_reset_delay */
9803 0, /* bios_id_lun */
9804 0, /* 11 termination_se */
9805 0, /* termination_lvd */
9806 0xFFE7, /* 12 bios_ctrl */
9807 0x4444, /* 13 sdtr_speed2 */
9808 0x4444, /* 14 sdtr_speed3 */
9809 ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
9810 ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
9811 0, /* 16 dvc_cntl */
9812 0x4444, /* 17 sdtr_speed4 */
9813 0, /* 18 serial_number_word1 */
9814 0, /* 19 serial_number_word2 */
9815 0, /* 20 serial_number_word3 */
9816 0, /* 21 check_sum */
9817 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
9818 , /* 22-29 oem_name[16] */
9819 0, /* 30 dvc_err_code */
9820 0, /* 31 adv_err_code */
9821 0, /* 32 adv_err_addr */
9822 0, /* 33 saved_dvc_err_code */
9823 0, /* 34 saved_adv_err_code */
9824 0, /* 35 saved_adv_err_addr */
9825 0, /* 36 reserved */
9826 0, /* 37 reserved */
9827 0, /* 38 reserved */
9828 0, /* 39 reserved */
9829 0, /* 40 reserved */
9830 0, /* 41 reserved */
9831 0, /* 42 reserved */
9832 0, /* 43 reserved */
9833 0, /* 44 reserved */
9834 0, /* 45 reserved */
9835 0, /* 46 reserved */
9836 0, /* 47 reserved */
9837 0, /* 48 reserved */
9838 0, /* 49 reserved */
9839 0, /* 50 reserved */
9840 0, /* 51 reserved */
9841 0, /* 52 reserved */
9842 0, /* 53 reserved */
9843 0, /* 54 reserved */
9844 0, /* 55 reserved */
9845 0, /* 56 cisptr_lsw */
9846 0, /* 57 cisprt_msw */
9847 PCI_VENDOR_ID_ASP, /* 58 subsysvid */
9848 PCI_DEVICE_ID_38C0800_REV1, /* 59 subsysid */
9849 0, /* 60 reserved */
9850 0, /* 61 reserved */
9851 0, /* 62 reserved */
9852 0 /* 63 reserved */
9853};
9854
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009855static ADVEEP_38C0800_CONFIG ADVEEP_38C0800_Config_Field_IsChar = {
Matthew Wilcox51219352007-10-02 21:55:22 -04009856 0, /* 00 cfg_lsw */
9857 0, /* 01 cfg_msw */
9858 0, /* 02 disc_enable */
9859 0, /* 03 wdtr_able */
9860 0, /* 04 sdtr_speed1 */
9861 0, /* 05 start_motor */
9862 0, /* 06 tagqng_able */
9863 0, /* 07 bios_scan */
9864 0, /* 08 scam_tolerant */
9865 1, /* 09 adapter_scsi_id */
9866 1, /* bios_boot_delay */
9867 1, /* 10 scsi_reset_delay */
9868 1, /* bios_id_lun */
9869 1, /* 11 termination_se */
9870 1, /* termination_lvd */
9871 0, /* 12 bios_ctrl */
9872 0, /* 13 sdtr_speed2 */
9873 0, /* 14 sdtr_speed3 */
9874 1, /* 15 max_host_qng */
9875 1, /* max_dvc_qng */
9876 0, /* 16 dvc_cntl */
9877 0, /* 17 sdtr_speed4 */
9878 0, /* 18 serial_number_word1 */
9879 0, /* 19 serial_number_word2 */
9880 0, /* 20 serial_number_word3 */
9881 0, /* 21 check_sum */
9882 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
9883 , /* 22-29 oem_name[16] */
9884 0, /* 30 dvc_err_code */
9885 0, /* 31 adv_err_code */
9886 0, /* 32 adv_err_addr */
9887 0, /* 33 saved_dvc_err_code */
9888 0, /* 34 saved_adv_err_code */
9889 0, /* 35 saved_adv_err_addr */
9890 0, /* 36 reserved */
9891 0, /* 37 reserved */
9892 0, /* 38 reserved */
9893 0, /* 39 reserved */
9894 0, /* 40 reserved */
9895 0, /* 41 reserved */
9896 0, /* 42 reserved */
9897 0, /* 43 reserved */
9898 0, /* 44 reserved */
9899 0, /* 45 reserved */
9900 0, /* 46 reserved */
9901 0, /* 47 reserved */
9902 0, /* 48 reserved */
9903 0, /* 49 reserved */
9904 0, /* 50 reserved */
9905 0, /* 51 reserved */
9906 0, /* 52 reserved */
9907 0, /* 53 reserved */
9908 0, /* 54 reserved */
9909 0, /* 55 reserved */
9910 0, /* 56 cisptr_lsw */
9911 0, /* 57 cisprt_msw */
9912 0, /* 58 subsysvid */
9913 0, /* 59 subsysid */
9914 0, /* 60 reserved */
9915 0, /* 61 reserved */
9916 0, /* 62 reserved */
9917 0 /* 63 reserved */
9918};
9919
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009920static ADVEEP_38C1600_CONFIG Default_38C1600_EEPROM_Config = {
Matthew Wilcox51219352007-10-02 21:55:22 -04009921 ADV_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */
9922 0x0000, /* 01 cfg_msw */
9923 0xFFFF, /* 02 disc_enable */
9924 0xFFFF, /* 03 wdtr_able */
9925 0x5555, /* 04 sdtr_speed1 */
9926 0xFFFF, /* 05 start_motor */
9927 0xFFFF, /* 06 tagqng_able */
9928 0xFFFF, /* 07 bios_scan */
9929 0, /* 08 scam_tolerant */
9930 7, /* 09 adapter_scsi_id */
9931 0, /* bios_boot_delay */
9932 3, /* 10 scsi_reset_delay */
9933 0, /* bios_id_lun */
9934 0, /* 11 termination_se */
9935 0, /* termination_lvd */
9936 0xFFE7, /* 12 bios_ctrl */
9937 0x5555, /* 13 sdtr_speed2 */
9938 0x5555, /* 14 sdtr_speed3 */
9939 ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
9940 ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
9941 0, /* 16 dvc_cntl */
9942 0x5555, /* 17 sdtr_speed4 */
9943 0, /* 18 serial_number_word1 */
9944 0, /* 19 serial_number_word2 */
9945 0, /* 20 serial_number_word3 */
9946 0, /* 21 check_sum */
9947 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
9948 , /* 22-29 oem_name[16] */
9949 0, /* 30 dvc_err_code */
9950 0, /* 31 adv_err_code */
9951 0, /* 32 adv_err_addr */
9952 0, /* 33 saved_dvc_err_code */
9953 0, /* 34 saved_adv_err_code */
9954 0, /* 35 saved_adv_err_addr */
9955 0, /* 36 reserved */
9956 0, /* 37 reserved */
9957 0, /* 38 reserved */
9958 0, /* 39 reserved */
9959 0, /* 40 reserved */
9960 0, /* 41 reserved */
9961 0, /* 42 reserved */
9962 0, /* 43 reserved */
9963 0, /* 44 reserved */
9964 0, /* 45 reserved */
9965 0, /* 46 reserved */
9966 0, /* 47 reserved */
9967 0, /* 48 reserved */
9968 0, /* 49 reserved */
9969 0, /* 50 reserved */
9970 0, /* 51 reserved */
9971 0, /* 52 reserved */
9972 0, /* 53 reserved */
9973 0, /* 54 reserved */
9974 0, /* 55 reserved */
9975 0, /* 56 cisptr_lsw */
9976 0, /* 57 cisprt_msw */
9977 PCI_VENDOR_ID_ASP, /* 58 subsysvid */
9978 PCI_DEVICE_ID_38C1600_REV1, /* 59 subsysid */
9979 0, /* 60 reserved */
9980 0, /* 61 reserved */
9981 0, /* 62 reserved */
9982 0 /* 63 reserved */
9983};
9984
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009985static ADVEEP_38C1600_CONFIG ADVEEP_38C1600_Config_Field_IsChar = {
Matthew Wilcox51219352007-10-02 21:55:22 -04009986 0, /* 00 cfg_lsw */
9987 0, /* 01 cfg_msw */
9988 0, /* 02 disc_enable */
9989 0, /* 03 wdtr_able */
9990 0, /* 04 sdtr_speed1 */
9991 0, /* 05 start_motor */
9992 0, /* 06 tagqng_able */
9993 0, /* 07 bios_scan */
9994 0, /* 08 scam_tolerant */
9995 1, /* 09 adapter_scsi_id */
9996 1, /* bios_boot_delay */
9997 1, /* 10 scsi_reset_delay */
9998 1, /* bios_id_lun */
9999 1, /* 11 termination_se */
10000 1, /* termination_lvd */
10001 0, /* 12 bios_ctrl */
10002 0, /* 13 sdtr_speed2 */
10003 0, /* 14 sdtr_speed3 */
10004 1, /* 15 max_host_qng */
10005 1, /* max_dvc_qng */
10006 0, /* 16 dvc_cntl */
10007 0, /* 17 sdtr_speed4 */
10008 0, /* 18 serial_number_word1 */
10009 0, /* 19 serial_number_word2 */
10010 0, /* 20 serial_number_word3 */
10011 0, /* 21 check_sum */
10012 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
10013 , /* 22-29 oem_name[16] */
10014 0, /* 30 dvc_err_code */
10015 0, /* 31 adv_err_code */
10016 0, /* 32 adv_err_addr */
10017 0, /* 33 saved_dvc_err_code */
10018 0, /* 34 saved_adv_err_code */
10019 0, /* 35 saved_adv_err_addr */
10020 0, /* 36 reserved */
10021 0, /* 37 reserved */
10022 0, /* 38 reserved */
10023 0, /* 39 reserved */
10024 0, /* 40 reserved */
10025 0, /* 41 reserved */
10026 0, /* 42 reserved */
10027 0, /* 43 reserved */
10028 0, /* 44 reserved */
10029 0, /* 45 reserved */
10030 0, /* 46 reserved */
10031 0, /* 47 reserved */
10032 0, /* 48 reserved */
10033 0, /* 49 reserved */
10034 0, /* 50 reserved */
10035 0, /* 51 reserved */
10036 0, /* 52 reserved */
10037 0, /* 53 reserved */
10038 0, /* 54 reserved */
10039 0, /* 55 reserved */
10040 0, /* 56 cisptr_lsw */
10041 0, /* 57 cisprt_msw */
10042 0, /* 58 subsysvid */
10043 0, /* 59 subsysid */
10044 0, /* 60 reserved */
10045 0, /* 61 reserved */
10046 0, /* 62 reserved */
10047 0 /* 63 reserved */
10048};
10049
10050#ifdef CONFIG_PCI
10051/*
10052 * Wait for EEPROM command to complete
10053 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010054static void AdvWaitEEPCmd(AdvPortAddr iop_base)
Matthew Wilcox51219352007-10-02 21:55:22 -040010055{
10056 int eep_delay_ms;
10057
10058 for (eep_delay_ms = 0; eep_delay_ms < ADV_EEP_DELAY_MS; eep_delay_ms++) {
10059 if (AdvReadWordRegister(iop_base, IOPW_EE_CMD) &
10060 ASC_EEP_CMD_DONE) {
10061 break;
10062 }
10063 mdelay(1);
10064 }
10065 if ((AdvReadWordRegister(iop_base, IOPW_EE_CMD) & ASC_EEP_CMD_DONE) ==
10066 0)
10067 BUG();
10068}
10069
10070/*
10071 * Read the EEPROM from specified location
10072 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010073static ushort AdvReadEEPWord(AdvPortAddr iop_base, int eep_word_addr)
Matthew Wilcox51219352007-10-02 21:55:22 -040010074{
10075 AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
10076 ASC_EEP_CMD_READ | eep_word_addr);
10077 AdvWaitEEPCmd(iop_base);
10078 return AdvReadWordRegister(iop_base, IOPW_EE_DATA);
10079}
10080
10081/*
10082 * Write the EEPROM from 'cfg_buf'.
10083 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010084static void AdvSet3550EEPConfig(AdvPortAddr iop_base,
10085 ADVEEP_3550_CONFIG *cfg_buf)
Matthew Wilcox51219352007-10-02 21:55:22 -040010086{
10087 ushort *wbuf;
10088 ushort addr, chksum;
10089 ushort *charfields;
10090
10091 wbuf = (ushort *)cfg_buf;
10092 charfields = (ushort *)&ADVEEP_3550_Config_Field_IsChar;
10093 chksum = 0;
10094
10095 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
10096 AdvWaitEEPCmd(iop_base);
10097
10098 /*
10099 * Write EEPROM from word 0 to word 20.
10100 */
10101 for (addr = ADV_EEP_DVC_CFG_BEGIN;
10102 addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
10103 ushort word;
10104
10105 if (*charfields++) {
10106 word = cpu_to_le16(*wbuf);
10107 } else {
10108 word = *wbuf;
10109 }
10110 chksum += *wbuf; /* Checksum is calculated from word values. */
10111 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
10112 AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
10113 ASC_EEP_CMD_WRITE | addr);
10114 AdvWaitEEPCmd(iop_base);
10115 mdelay(ADV_EEP_DELAY_MS);
10116 }
10117
10118 /*
10119 * Write EEPROM checksum at word 21.
10120 */
10121 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
10122 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
10123 AdvWaitEEPCmd(iop_base);
10124 wbuf++;
10125 charfields++;
10126
10127 /*
10128 * Write EEPROM OEM name at words 22 to 29.
10129 */
10130 for (addr = ADV_EEP_DVC_CTL_BEGIN;
10131 addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
10132 ushort word;
10133
10134 if (*charfields++) {
10135 word = cpu_to_le16(*wbuf);
10136 } else {
10137 word = *wbuf;
10138 }
10139 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
10140 AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
10141 ASC_EEP_CMD_WRITE | addr);
10142 AdvWaitEEPCmd(iop_base);
10143 }
10144 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
10145 AdvWaitEEPCmd(iop_base);
10146}
10147
10148/*
10149 * Write the EEPROM from 'cfg_buf'.
10150 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010151static void AdvSet38C0800EEPConfig(AdvPortAddr iop_base,
10152 ADVEEP_38C0800_CONFIG *cfg_buf)
Matthew Wilcox51219352007-10-02 21:55:22 -040010153{
10154 ushort *wbuf;
10155 ushort *charfields;
10156 ushort addr, chksum;
10157
10158 wbuf = (ushort *)cfg_buf;
10159 charfields = (ushort *)&ADVEEP_38C0800_Config_Field_IsChar;
10160 chksum = 0;
10161
10162 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
10163 AdvWaitEEPCmd(iop_base);
10164
10165 /*
10166 * Write EEPROM from word 0 to word 20.
10167 */
10168 for (addr = ADV_EEP_DVC_CFG_BEGIN;
10169 addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
10170 ushort word;
10171
10172 if (*charfields++) {
10173 word = cpu_to_le16(*wbuf);
10174 } else {
10175 word = *wbuf;
10176 }
10177 chksum += *wbuf; /* Checksum is calculated from word values. */
10178 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
10179 AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
10180 ASC_EEP_CMD_WRITE | addr);
10181 AdvWaitEEPCmd(iop_base);
10182 mdelay(ADV_EEP_DELAY_MS);
10183 }
10184
10185 /*
10186 * Write EEPROM checksum at word 21.
10187 */
10188 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
10189 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
10190 AdvWaitEEPCmd(iop_base);
10191 wbuf++;
10192 charfields++;
10193
10194 /*
10195 * Write EEPROM OEM name at words 22 to 29.
10196 */
10197 for (addr = ADV_EEP_DVC_CTL_BEGIN;
10198 addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
10199 ushort word;
10200
10201 if (*charfields++) {
10202 word = cpu_to_le16(*wbuf);
10203 } else {
10204 word = *wbuf;
10205 }
10206 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
10207 AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
10208 ASC_EEP_CMD_WRITE | addr);
10209 AdvWaitEEPCmd(iop_base);
10210 }
10211 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
10212 AdvWaitEEPCmd(iop_base);
10213}
10214
10215/*
10216 * Write the EEPROM from 'cfg_buf'.
10217 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010218static void AdvSet38C1600EEPConfig(AdvPortAddr iop_base,
10219 ADVEEP_38C1600_CONFIG *cfg_buf)
Matthew Wilcox51219352007-10-02 21:55:22 -040010220{
10221 ushort *wbuf;
10222 ushort *charfields;
10223 ushort addr, chksum;
10224
10225 wbuf = (ushort *)cfg_buf;
10226 charfields = (ushort *)&ADVEEP_38C1600_Config_Field_IsChar;
10227 chksum = 0;
10228
10229 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
10230 AdvWaitEEPCmd(iop_base);
10231
10232 /*
10233 * Write EEPROM from word 0 to word 20.
10234 */
10235 for (addr = ADV_EEP_DVC_CFG_BEGIN;
10236 addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
10237 ushort word;
10238
10239 if (*charfields++) {
10240 word = cpu_to_le16(*wbuf);
10241 } else {
10242 word = *wbuf;
10243 }
10244 chksum += *wbuf; /* Checksum is calculated from word values. */
10245 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
10246 AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
10247 ASC_EEP_CMD_WRITE | addr);
10248 AdvWaitEEPCmd(iop_base);
10249 mdelay(ADV_EEP_DELAY_MS);
10250 }
10251
10252 /*
10253 * Write EEPROM checksum at word 21.
10254 */
10255 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
10256 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
10257 AdvWaitEEPCmd(iop_base);
10258 wbuf++;
10259 charfields++;
10260
10261 /*
10262 * Write EEPROM OEM name at words 22 to 29.
10263 */
10264 for (addr = ADV_EEP_DVC_CTL_BEGIN;
10265 addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
10266 ushort word;
10267
10268 if (*charfields++) {
10269 word = cpu_to_le16(*wbuf);
10270 } else {
10271 word = *wbuf;
10272 }
10273 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
10274 AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
10275 ASC_EEP_CMD_WRITE | addr);
10276 AdvWaitEEPCmd(iop_base);
10277 }
10278 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
10279 AdvWaitEEPCmd(iop_base);
10280}
10281
10282/*
10283 * Read EEPROM configuration into the specified buffer.
10284 *
10285 * Return a checksum based on the EEPROM configuration read.
10286 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010287static ushort AdvGet3550EEPConfig(AdvPortAddr iop_base,
10288 ADVEEP_3550_CONFIG *cfg_buf)
Matthew Wilcox51219352007-10-02 21:55:22 -040010289{
10290 ushort wval, chksum;
10291 ushort *wbuf;
10292 int eep_addr;
10293 ushort *charfields;
10294
10295 charfields = (ushort *)&ADVEEP_3550_Config_Field_IsChar;
10296 wbuf = (ushort *)cfg_buf;
10297 chksum = 0;
10298
10299 for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
10300 eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
10301 wval = AdvReadEEPWord(iop_base, eep_addr);
10302 chksum += wval; /* Checksum is calculated from word values. */
10303 if (*charfields++) {
10304 *wbuf = le16_to_cpu(wval);
10305 } else {
10306 *wbuf = wval;
10307 }
10308 }
10309 /* Read checksum word. */
10310 *wbuf = AdvReadEEPWord(iop_base, eep_addr);
10311 wbuf++;
10312 charfields++;
10313
10314 /* Read rest of EEPROM not covered by the checksum. */
10315 for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
10316 eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
10317 *wbuf = AdvReadEEPWord(iop_base, eep_addr);
10318 if (*charfields++) {
10319 *wbuf = le16_to_cpu(*wbuf);
10320 }
10321 }
10322 return chksum;
10323}
10324
10325/*
10326 * Read EEPROM configuration into the specified buffer.
10327 *
10328 * Return a checksum based on the EEPROM configuration read.
10329 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010330static ushort AdvGet38C0800EEPConfig(AdvPortAddr iop_base,
10331 ADVEEP_38C0800_CONFIG *cfg_buf)
Matthew Wilcox51219352007-10-02 21:55:22 -040010332{
10333 ushort wval, chksum;
10334 ushort *wbuf;
10335 int eep_addr;
10336 ushort *charfields;
10337
10338 charfields = (ushort *)&ADVEEP_38C0800_Config_Field_IsChar;
10339 wbuf = (ushort *)cfg_buf;
10340 chksum = 0;
10341
10342 for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
10343 eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
10344 wval = AdvReadEEPWord(iop_base, eep_addr);
10345 chksum += wval; /* Checksum is calculated from word values. */
10346 if (*charfields++) {
10347 *wbuf = le16_to_cpu(wval);
10348 } else {
10349 *wbuf = wval;
10350 }
10351 }
10352 /* Read checksum word. */
10353 *wbuf = AdvReadEEPWord(iop_base, eep_addr);
10354 wbuf++;
10355 charfields++;
10356
10357 /* Read rest of EEPROM not covered by the checksum. */
10358 for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
10359 eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
10360 *wbuf = AdvReadEEPWord(iop_base, eep_addr);
10361 if (*charfields++) {
10362 *wbuf = le16_to_cpu(*wbuf);
10363 }
10364 }
10365 return chksum;
10366}
10367
10368/*
10369 * Read EEPROM configuration into the specified buffer.
10370 *
10371 * Return a checksum based on the EEPROM configuration read.
10372 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010373static ushort AdvGet38C1600EEPConfig(AdvPortAddr iop_base,
10374 ADVEEP_38C1600_CONFIG *cfg_buf)
Matthew Wilcox51219352007-10-02 21:55:22 -040010375{
10376 ushort wval, chksum;
10377 ushort *wbuf;
10378 int eep_addr;
10379 ushort *charfields;
10380
10381 charfields = (ushort *)&ADVEEP_38C1600_Config_Field_IsChar;
10382 wbuf = (ushort *)cfg_buf;
10383 chksum = 0;
10384
10385 for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
10386 eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
10387 wval = AdvReadEEPWord(iop_base, eep_addr);
10388 chksum += wval; /* Checksum is calculated from word values. */
10389 if (*charfields++) {
10390 *wbuf = le16_to_cpu(wval);
10391 } else {
10392 *wbuf = wval;
10393 }
10394 }
10395 /* Read checksum word. */
10396 *wbuf = AdvReadEEPWord(iop_base, eep_addr);
10397 wbuf++;
10398 charfields++;
10399
10400 /* Read rest of EEPROM not covered by the checksum. */
10401 for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
10402 eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
10403 *wbuf = AdvReadEEPWord(iop_base, eep_addr);
10404 if (*charfields++) {
10405 *wbuf = le16_to_cpu(*wbuf);
10406 }
10407 }
10408 return chksum;
10409}
10410
10411/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070010412 * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
10413 * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
10414 * all of this is done.
10415 *
10416 * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
10417 *
10418 * For a non-fatal error return a warning code. If there are no warnings
10419 * then 0 is returned.
10420 *
10421 * Note: Chip is stopped on entry.
10422 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010423static int AdvInitFrom3550EEP(ADV_DVC_VAR *asc_dvc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070010424{
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010425 AdvPortAddr iop_base;
10426 ushort warn_code;
10427 ADVEEP_3550_CONFIG eep_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010428
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010429 iop_base = asc_dvc->iop_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010430
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010431 warn_code = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010432
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010433 /*
10434 * Read the board's EEPROM configuration.
10435 *
10436 * Set default values if a bad checksum is found.
10437 */
10438 if (AdvGet3550EEPConfig(iop_base, &eep_config) != eep_config.check_sum) {
10439 warn_code |= ASC_WARN_EEPROM_CHKSUM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010440
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010441 /*
10442 * Set EEPROM default values.
10443 */
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010444 memcpy(&eep_config, &Default_3550_EEPROM_Config,
10445 sizeof(ADVEEP_3550_CONFIG));
Linus Torvalds1da177e2005-04-16 15:20:36 -070010446
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010447 /*
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010448 * Assume the 6 byte board serial number that was read from
10449 * EEPROM is correct even if the EEPROM checksum failed.
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010450 */
10451 eep_config.serial_number_word3 =
10452 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010453
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010454 eep_config.serial_number_word2 =
10455 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010456
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010457 eep_config.serial_number_word1 =
10458 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010459
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010460 AdvSet3550EEPConfig(iop_base, &eep_config);
10461 }
10462 /*
10463 * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
10464 * EEPROM configuration that was read.
10465 *
10466 * This is the mapping of EEPROM fields to Adv Library fields.
10467 */
10468 asc_dvc->wdtr_able = eep_config.wdtr_able;
10469 asc_dvc->sdtr_able = eep_config.sdtr_able;
10470 asc_dvc->ultra_able = eep_config.ultra_able;
10471 asc_dvc->tagqng_able = eep_config.tagqng_able;
10472 asc_dvc->cfg->disc_enable = eep_config.disc_enable;
10473 asc_dvc->max_host_qng = eep_config.max_host_qng;
10474 asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
10475 asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
10476 asc_dvc->start_motor = eep_config.start_motor;
10477 asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
10478 asc_dvc->bios_ctrl = eep_config.bios_ctrl;
10479 asc_dvc->no_scam = eep_config.scam_tolerant;
10480 asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
10481 asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
10482 asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010483
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010484 /*
10485 * Set the host maximum queuing (max. 253, min. 16) and the per device
10486 * maximum queuing (max. 63, min. 4).
10487 */
10488 if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
10489 eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
10490 } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
10491 /* If the value is zero, assume it is uninitialized. */
10492 if (eep_config.max_host_qng == 0) {
10493 eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
10494 } else {
10495 eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
10496 }
10497 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010498
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010499 if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
10500 eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
10501 } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
10502 /* If the value is zero, assume it is uninitialized. */
10503 if (eep_config.max_dvc_qng == 0) {
10504 eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
10505 } else {
10506 eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
10507 }
10508 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010509
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010510 /*
10511 * If 'max_dvc_qng' is greater than 'max_host_qng', then
10512 * set 'max_dvc_qng' to 'max_host_qng'.
10513 */
10514 if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
10515 eep_config.max_dvc_qng = eep_config.max_host_qng;
10516 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010517
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010518 /*
10519 * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
10520 * values based on possibly adjusted EEPROM values.
10521 */
10522 asc_dvc->max_host_qng = eep_config.max_host_qng;
10523 asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010524
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010525 /*
10526 * If the EEPROM 'termination' field is set to automatic (0), then set
10527 * the ADV_DVC_CFG 'termination' field to automatic also.
10528 *
10529 * If the termination is specified with a non-zero 'termination'
10530 * value check that a legal value is set and set the ADV_DVC_CFG
10531 * 'termination' field appropriately.
10532 */
10533 if (eep_config.termination == 0) {
10534 asc_dvc->cfg->termination = 0; /* auto termination */
10535 } else {
10536 /* Enable manual control with low off / high off. */
10537 if (eep_config.termination == 1) {
10538 asc_dvc->cfg->termination = TERM_CTL_SEL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010539
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010540 /* Enable manual control with low off / high on. */
10541 } else if (eep_config.termination == 2) {
10542 asc_dvc->cfg->termination = TERM_CTL_SEL | TERM_CTL_H;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010543
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010544 /* Enable manual control with low on / high on. */
10545 } else if (eep_config.termination == 3) {
10546 asc_dvc->cfg->termination =
10547 TERM_CTL_SEL | TERM_CTL_H | TERM_CTL_L;
10548 } else {
10549 /*
10550 * The EEPROM 'termination' field contains a bad value. Use
10551 * automatic termination instead.
10552 */
10553 asc_dvc->cfg->termination = 0;
10554 warn_code |= ASC_WARN_EEPROM_TERMINATION;
10555 }
10556 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010557
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010558 return warn_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010559}
10560
10561/*
10562 * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
10563 * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
10564 * all of this is done.
10565 *
10566 * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
10567 *
10568 * For a non-fatal error return a warning code. If there are no warnings
10569 * then 0 is returned.
10570 *
10571 * Note: Chip is stopped on entry.
10572 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010573static int AdvInitFrom38C0800EEP(ADV_DVC_VAR *asc_dvc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070010574{
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010575 AdvPortAddr iop_base;
10576 ushort warn_code;
10577 ADVEEP_38C0800_CONFIG eep_config;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010578 uchar tid, termination;
10579 ushort sdtr_speed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010580
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010581 iop_base = asc_dvc->iop_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010582
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010583 warn_code = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010584
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010585 /*
10586 * Read the board's EEPROM configuration.
10587 *
10588 * Set default values if a bad checksum is found.
10589 */
10590 if (AdvGet38C0800EEPConfig(iop_base, &eep_config) !=
10591 eep_config.check_sum) {
10592 warn_code |= ASC_WARN_EEPROM_CHKSUM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010593
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010594 /*
10595 * Set EEPROM default values.
10596 */
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010597 memcpy(&eep_config, &Default_38C0800_EEPROM_Config,
10598 sizeof(ADVEEP_38C0800_CONFIG));
Linus Torvalds1da177e2005-04-16 15:20:36 -070010599
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010600 /*
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010601 * Assume the 6 byte board serial number that was read from
10602 * EEPROM is correct even if the EEPROM checksum failed.
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010603 */
10604 eep_config.serial_number_word3 =
10605 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010606
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010607 eep_config.serial_number_word2 =
10608 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010609
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010610 eep_config.serial_number_word1 =
10611 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010612
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010613 AdvSet38C0800EEPConfig(iop_base, &eep_config);
10614 }
10615 /*
10616 * Set ADV_DVC_VAR and ADV_DVC_CFG variables from the
10617 * EEPROM configuration that was read.
10618 *
10619 * This is the mapping of EEPROM fields to Adv Library fields.
10620 */
10621 asc_dvc->wdtr_able = eep_config.wdtr_able;
10622 asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
10623 asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
10624 asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
10625 asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
10626 asc_dvc->tagqng_able = eep_config.tagqng_able;
10627 asc_dvc->cfg->disc_enable = eep_config.disc_enable;
10628 asc_dvc->max_host_qng = eep_config.max_host_qng;
10629 asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
10630 asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
10631 asc_dvc->start_motor = eep_config.start_motor;
10632 asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
10633 asc_dvc->bios_ctrl = eep_config.bios_ctrl;
10634 asc_dvc->no_scam = eep_config.scam_tolerant;
10635 asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
10636 asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
10637 asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010638
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010639 /*
10640 * For every Target ID if any of its 'sdtr_speed[1234]' bits
10641 * are set, then set an 'sdtr_able' bit for it.
10642 */
10643 asc_dvc->sdtr_able = 0;
10644 for (tid = 0; tid <= ADV_MAX_TID; tid++) {
10645 if (tid == 0) {
10646 sdtr_speed = asc_dvc->sdtr_speed1;
10647 } else if (tid == 4) {
10648 sdtr_speed = asc_dvc->sdtr_speed2;
10649 } else if (tid == 8) {
10650 sdtr_speed = asc_dvc->sdtr_speed3;
10651 } else if (tid == 12) {
10652 sdtr_speed = asc_dvc->sdtr_speed4;
10653 }
10654 if (sdtr_speed & ADV_MAX_TID) {
10655 asc_dvc->sdtr_able |= (1 << tid);
10656 }
10657 sdtr_speed >>= 4;
10658 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010659
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010660 /*
10661 * Set the host maximum queuing (max. 253, min. 16) and the per device
10662 * maximum queuing (max. 63, min. 4).
10663 */
10664 if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
10665 eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
10666 } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
10667 /* If the value is zero, assume it is uninitialized. */
10668 if (eep_config.max_host_qng == 0) {
10669 eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
10670 } else {
10671 eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
10672 }
10673 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010674
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010675 if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
10676 eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
10677 } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
10678 /* If the value is zero, assume it is uninitialized. */
10679 if (eep_config.max_dvc_qng == 0) {
10680 eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
10681 } else {
10682 eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
10683 }
10684 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010685
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010686 /*
10687 * If 'max_dvc_qng' is greater than 'max_host_qng', then
10688 * set 'max_dvc_qng' to 'max_host_qng'.
10689 */
10690 if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
10691 eep_config.max_dvc_qng = eep_config.max_host_qng;
10692 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010693
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010694 /*
10695 * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
10696 * values based on possibly adjusted EEPROM values.
10697 */
10698 asc_dvc->max_host_qng = eep_config.max_host_qng;
10699 asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010700
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010701 /*
10702 * If the EEPROM 'termination' field is set to automatic (0), then set
10703 * the ADV_DVC_CFG 'termination' field to automatic also.
10704 *
10705 * If the termination is specified with a non-zero 'termination'
10706 * value check that a legal value is set and set the ADV_DVC_CFG
10707 * 'termination' field appropriately.
10708 */
10709 if (eep_config.termination_se == 0) {
10710 termination = 0; /* auto termination for SE */
10711 } else {
10712 /* Enable manual control with low off / high off. */
10713 if (eep_config.termination_se == 1) {
10714 termination = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010715
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010716 /* Enable manual control with low off / high on. */
10717 } else if (eep_config.termination_se == 2) {
10718 termination = TERM_SE_HI;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010719
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010720 /* Enable manual control with low on / high on. */
10721 } else if (eep_config.termination_se == 3) {
10722 termination = TERM_SE;
10723 } else {
10724 /*
10725 * The EEPROM 'termination_se' field contains a bad value.
10726 * Use automatic termination instead.
10727 */
10728 termination = 0;
10729 warn_code |= ASC_WARN_EEPROM_TERMINATION;
10730 }
10731 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010732
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010733 if (eep_config.termination_lvd == 0) {
10734 asc_dvc->cfg->termination = termination; /* auto termination for LVD */
10735 } else {
10736 /* Enable manual control with low off / high off. */
10737 if (eep_config.termination_lvd == 1) {
10738 asc_dvc->cfg->termination = termination;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010739
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010740 /* Enable manual control with low off / high on. */
10741 } else if (eep_config.termination_lvd == 2) {
10742 asc_dvc->cfg->termination = termination | TERM_LVD_HI;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010743
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010744 /* Enable manual control with low on / high on. */
10745 } else if (eep_config.termination_lvd == 3) {
10746 asc_dvc->cfg->termination = termination | TERM_LVD;
10747 } else {
10748 /*
10749 * The EEPROM 'termination_lvd' field contains a bad value.
10750 * Use automatic termination instead.
10751 */
10752 asc_dvc->cfg->termination = termination;
10753 warn_code |= ASC_WARN_EEPROM_TERMINATION;
10754 }
10755 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010756
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010757 return warn_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010758}
10759
10760/*
10761 * Read the board's EEPROM configuration. Set fields in ASC_DVC_VAR and
10762 * ASC_DVC_CFG based on the EEPROM settings. The chip is stopped while
10763 * all of this is done.
10764 *
10765 * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
10766 *
10767 * For a non-fatal error return a warning code. If there are no warnings
10768 * then 0 is returned.
10769 *
10770 * Note: Chip is stopped on entry.
10771 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010772static int AdvInitFrom38C1600EEP(ADV_DVC_VAR *asc_dvc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070010773{
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010774 AdvPortAddr iop_base;
10775 ushort warn_code;
10776 ADVEEP_38C1600_CONFIG eep_config;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010777 uchar tid, termination;
10778 ushort sdtr_speed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010779
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010780 iop_base = asc_dvc->iop_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010781
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010782 warn_code = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010783
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010784 /*
10785 * Read the board's EEPROM configuration.
10786 *
10787 * Set default values if a bad checksum is found.
10788 */
10789 if (AdvGet38C1600EEPConfig(iop_base, &eep_config) !=
10790 eep_config.check_sum) {
Matthew Wilcox13ac2d92007-07-30 08:10:23 -060010791 struct pci_dev *pdev = adv_dvc_to_pdev(asc_dvc);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010792 warn_code |= ASC_WARN_EEPROM_CHKSUM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010793
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010794 /*
10795 * Set EEPROM default values.
10796 */
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010797 memcpy(&eep_config, &Default_38C1600_EEPROM_Config,
10798 sizeof(ADVEEP_38C1600_CONFIG));
Linus Torvalds1da177e2005-04-16 15:20:36 -070010799
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010800 if (PCI_FUNC(pdev->devfn) != 0) {
10801 u8 ints;
10802 /*
10803 * Disable Bit 14 (BIOS_ENABLE) to fix SPARC Ultra 60
10804 * and old Mac system booting problem. The Expansion
10805 * ROM must be disabled in Function 1 for these systems
10806 */
10807 eep_config.cfg_lsw &= ~ADV_EEPROM_BIOS_ENABLE;
10808 /*
10809 * Clear the INTAB (bit 11) if the GPIO 0 input
10810 * indicates the Function 1 interrupt line is wired
10811 * to INTB.
10812 *
10813 * Set/Clear Bit 11 (INTAB) from the GPIO bit 0 input:
10814 * 1 - Function 1 interrupt line wired to INT A.
10815 * 0 - Function 1 interrupt line wired to INT B.
10816 *
10817 * Note: Function 0 is always wired to INTA.
10818 * Put all 5 GPIO bits in input mode and then read
10819 * their input values.
10820 */
10821 AdvWriteByteRegister(iop_base, IOPB_GPIO_CNTL, 0);
10822 ints = AdvReadByteRegister(iop_base, IOPB_GPIO_DATA);
10823 if ((ints & 0x01) == 0)
10824 eep_config.cfg_lsw &= ~ADV_EEPROM_INTAB;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010825 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010826
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010827 /*
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010828 * Assume the 6 byte board serial number that was read from
10829 * EEPROM is correct even if the EEPROM checksum failed.
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010830 */
10831 eep_config.serial_number_word3 =
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010832 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010833 eep_config.serial_number_word2 =
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010834 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010835 eep_config.serial_number_word1 =
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010836 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010837
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010838 AdvSet38C1600EEPConfig(iop_base, &eep_config);
10839 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010840
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010841 /*
10842 * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
10843 * EEPROM configuration that was read.
10844 *
10845 * This is the mapping of EEPROM fields to Adv Library fields.
10846 */
10847 asc_dvc->wdtr_able = eep_config.wdtr_able;
10848 asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
10849 asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
10850 asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
10851 asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
10852 asc_dvc->ppr_able = 0;
10853 asc_dvc->tagqng_able = eep_config.tagqng_able;
10854 asc_dvc->cfg->disc_enable = eep_config.disc_enable;
10855 asc_dvc->max_host_qng = eep_config.max_host_qng;
10856 asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
10857 asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ASC_MAX_TID);
10858 asc_dvc->start_motor = eep_config.start_motor;
10859 asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
10860 asc_dvc->bios_ctrl = eep_config.bios_ctrl;
10861 asc_dvc->no_scam = eep_config.scam_tolerant;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010862
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010863 /*
10864 * For every Target ID if any of its 'sdtr_speed[1234]' bits
10865 * are set, then set an 'sdtr_able' bit for it.
10866 */
10867 asc_dvc->sdtr_able = 0;
10868 for (tid = 0; tid <= ASC_MAX_TID; tid++) {
10869 if (tid == 0) {
10870 sdtr_speed = asc_dvc->sdtr_speed1;
10871 } else if (tid == 4) {
10872 sdtr_speed = asc_dvc->sdtr_speed2;
10873 } else if (tid == 8) {
10874 sdtr_speed = asc_dvc->sdtr_speed3;
10875 } else if (tid == 12) {
10876 sdtr_speed = asc_dvc->sdtr_speed4;
10877 }
10878 if (sdtr_speed & ASC_MAX_TID) {
10879 asc_dvc->sdtr_able |= (1 << tid);
10880 }
10881 sdtr_speed >>= 4;
10882 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010883
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010884 /*
10885 * Set the host maximum queuing (max. 253, min. 16) and the per device
10886 * maximum queuing (max. 63, min. 4).
10887 */
10888 if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
10889 eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
10890 } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
10891 /* If the value is zero, assume it is uninitialized. */
10892 if (eep_config.max_host_qng == 0) {
10893 eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
10894 } else {
10895 eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
10896 }
10897 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010898
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010899 if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
10900 eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
10901 } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
10902 /* If the value is zero, assume it is uninitialized. */
10903 if (eep_config.max_dvc_qng == 0) {
10904 eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
10905 } else {
10906 eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
10907 }
10908 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010909
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010910 /*
10911 * If 'max_dvc_qng' is greater than 'max_host_qng', then
10912 * set 'max_dvc_qng' to 'max_host_qng'.
10913 */
10914 if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
10915 eep_config.max_dvc_qng = eep_config.max_host_qng;
10916 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010917
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010918 /*
10919 * Set ASC_DVC_VAR 'max_host_qng' and ASC_DVC_VAR 'max_dvc_qng'
10920 * values based on possibly adjusted EEPROM values.
10921 */
10922 asc_dvc->max_host_qng = eep_config.max_host_qng;
10923 asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010924
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010925 /*
10926 * If the EEPROM 'termination' field is set to automatic (0), then set
10927 * the ASC_DVC_CFG 'termination' field to automatic also.
10928 *
10929 * If the termination is specified with a non-zero 'termination'
10930 * value check that a legal value is set and set the ASC_DVC_CFG
10931 * 'termination' field appropriately.
10932 */
10933 if (eep_config.termination_se == 0) {
10934 termination = 0; /* auto termination for SE */
10935 } else {
10936 /* Enable manual control with low off / high off. */
10937 if (eep_config.termination_se == 1) {
10938 termination = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010939
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010940 /* Enable manual control with low off / high on. */
10941 } else if (eep_config.termination_se == 2) {
10942 termination = TERM_SE_HI;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010943
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010944 /* Enable manual control with low on / high on. */
10945 } else if (eep_config.termination_se == 3) {
10946 termination = TERM_SE;
10947 } else {
10948 /*
10949 * The EEPROM 'termination_se' field contains a bad value.
10950 * Use automatic termination instead.
10951 */
10952 termination = 0;
10953 warn_code |= ASC_WARN_EEPROM_TERMINATION;
10954 }
10955 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010956
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010957 if (eep_config.termination_lvd == 0) {
10958 asc_dvc->cfg->termination = termination; /* auto termination for LVD */
10959 } else {
10960 /* Enable manual control with low off / high off. */
10961 if (eep_config.termination_lvd == 1) {
10962 asc_dvc->cfg->termination = termination;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010963
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010964 /* Enable manual control with low off / high on. */
10965 } else if (eep_config.termination_lvd == 2) {
10966 asc_dvc->cfg->termination = termination | TERM_LVD_HI;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010967
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010968 /* Enable manual control with low on / high on. */
10969 } else if (eep_config.termination_lvd == 3) {
10970 asc_dvc->cfg->termination = termination | TERM_LVD;
10971 } else {
10972 /*
10973 * The EEPROM 'termination_lvd' field contains a bad value.
10974 * Use automatic termination instead.
10975 */
10976 asc_dvc->cfg->termination = termination;
10977 warn_code |= ASC_WARN_EEPROM_TERMINATION;
10978 }
10979 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010980
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010981 return warn_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010982}
10983
10984/*
Matthew Wilcox51219352007-10-02 21:55:22 -040010985 * Initialize the ADV_DVC_VAR structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010986 *
Matthew Wilcox51219352007-10-02 21:55:22 -040010987 * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010988 *
Matthew Wilcox51219352007-10-02 21:55:22 -040010989 * For a non-fatal error return a warning code. If there are no warnings
10990 * then 0 is returned.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010991 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010992static int AdvInitGetConfig(struct pci_dev *pdev, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -070010993{
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040010994 struct asc_board *board = shost_priv(shost);
10995 ADV_DVC_VAR *asc_dvc = &board->dvc_var.adv_dvc_var;
Matthew Wilcox51219352007-10-02 21:55:22 -040010996 unsigned short warn_code = 0;
10997 AdvPortAddr iop_base = asc_dvc->iop_base;
10998 u16 cmd;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010999 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070011000
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011001 asc_dvc->err_code = 0;
Matthew Wilcox51219352007-10-02 21:55:22 -040011002
11003 /*
11004 * Save the state of the PCI Configuration Command Register
11005 * "Parity Error Response Control" Bit. If the bit is clear (0),
11006 * in AdvInitAsc3550/38C0800Driver() tell the microcode to ignore
11007 * DMA parity errors.
11008 */
11009 asc_dvc->cfg->control_flag = 0;
11010 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
11011 if ((cmd & PCI_COMMAND_PARITY) == 0)
11012 asc_dvc->cfg->control_flag |= CONTROL_FLAG_IGNORE_PERR;
11013
Matthew Wilcox51219352007-10-02 21:55:22 -040011014 asc_dvc->cfg->chip_version =
11015 AdvGetChipVersion(iop_base, asc_dvc->bus_type);
11016
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011017 ASC_DBG(1, "iopb_chip_id_1: 0x%x 0x%x\n",
Matthew Wilcox51219352007-10-02 21:55:22 -040011018 (ushort)AdvReadByteRegister(iop_base, IOPB_CHIP_ID_1),
11019 (ushort)ADV_CHIP_ID_BYTE);
11020
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011021 ASC_DBG(1, "iopw_chip_id_0: 0x%x 0x%x\n",
Matthew Wilcox51219352007-10-02 21:55:22 -040011022 (ushort)AdvReadWordRegister(iop_base, IOPW_CHIP_ID_0),
11023 (ushort)ADV_CHIP_ID_WORD);
11024
11025 /*
11026 * Reset the chip to start and allow register writes.
11027 */
11028 if (AdvFindSignature(iop_base) == 0) {
11029 asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
11030 return ADV_ERROR;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011031 } else {
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011032 /*
Matthew Wilcox51219352007-10-02 21:55:22 -040011033 * The caller must set 'chip_type' to a valid setting.
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011034 */
Matthew Wilcox51219352007-10-02 21:55:22 -040011035 if (asc_dvc->chip_type != ADV_CHIP_ASC3550 &&
11036 asc_dvc->chip_type != ADV_CHIP_ASC38C0800 &&
11037 asc_dvc->chip_type != ADV_CHIP_ASC38C1600) {
11038 asc_dvc->err_code |= ASC_IERR_BAD_CHIPTYPE;
11039 return ADV_ERROR;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011040 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070011041
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011042 /*
Matthew Wilcox51219352007-10-02 21:55:22 -040011043 * Reset Chip.
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011044 */
Matthew Wilcox51219352007-10-02 21:55:22 -040011045 AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
11046 ADV_CTRL_REG_CMD_RESET);
11047 mdelay(100);
11048 AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
11049 ADV_CTRL_REG_CMD_WR_IO_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -070011050
Matthew Wilcox51219352007-10-02 21:55:22 -040011051 if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
11052 status = AdvInitFrom38C1600EEP(asc_dvc);
11053 } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
11054 status = AdvInitFrom38C0800EEP(asc_dvc);
11055 } else {
11056 status = AdvInitFrom3550EEP(asc_dvc);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011057 }
Matthew Wilcox51219352007-10-02 21:55:22 -040011058 warn_code |= status;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011059 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070011060
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011061 if (warn_code != 0)
11062 shost_printk(KERN_WARNING, shost, "warning: 0x%x\n", warn_code);
Matthew Wilcox51219352007-10-02 21:55:22 -040011063
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011064 if (asc_dvc->err_code)
11065 shost_printk(KERN_ERR, shost, "error code 0x%x\n",
11066 asc_dvc->err_code);
Matthew Wilcox51219352007-10-02 21:55:22 -040011067
11068 return asc_dvc->err_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -070011069}
Matthew Wilcox51219352007-10-02 21:55:22 -040011070#endif
11071
11072static struct scsi_host_template advansys_template = {
11073 .proc_name = DRV_NAME,
11074#ifdef CONFIG_PROC_FS
Al Virob59fb6f2013-03-31 02:59:55 -040011075 .show_info = advansys_show_info,
Matthew Wilcox51219352007-10-02 21:55:22 -040011076#endif
11077 .name = DRV_NAME,
11078 .info = advansys_info,
11079 .queuecommand = advansys_queuecommand,
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +020011080 .eh_host_reset_handler = advansys_reset,
Matthew Wilcox51219352007-10-02 21:55:22 -040011081 .bios_param = advansys_biosparam,
11082 .slave_configure = advansys_slave_configure,
11083 /*
11084 * Because the driver may control an ISA adapter 'unchecked_isa_dma'
11085 * must be set. The flag will be cleared in advansys_board_found
11086 * for non-ISA adapters.
11087 */
Hannes Reineckeae267592015-04-24 13:18:28 +020011088 .unchecked_isa_dma = true,
Matthew Wilcox51219352007-10-02 21:55:22 -040011089 /*
11090 * All adapters controlled by this driver are capable of large
11091 * scatter-gather lists. According to the mid-level SCSI documentation
11092 * this obviates any performance gain provided by setting
11093 * 'use_clustering'. But empirically while CPU utilization is increased
11094 * by enabling clustering, I/O throughput increases as well.
11095 */
11096 .use_clustering = ENABLE_CLUSTERING,
Hannes Reinecke9c17c622015-04-24 13:18:21 +020011097 .use_blk_tags = 1,
Matthew Wilcox51219352007-10-02 21:55:22 -040011098};
Linus Torvalds1da177e2005-04-16 15:20:36 -070011099
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011100static int advansys_wide_init_chip(struct Scsi_Host *shost)
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011101{
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011102 struct asc_board *board = shost_priv(shost);
11103 struct adv_dvc_var *adv_dvc = &board->dvc_var.adv_dvc_var;
Hannes Reinecke0ce53822015-04-24 13:18:25 +020011104 size_t sgblk_pool_size;
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011105 int warn_code, err_code;
11106
11107 /*
11108 * Allocate buffer carrier structures. The total size
Hannes Reinecke98b96a72015-04-24 13:18:23 +020011109 * is about 8 KB, so allocate all at once.
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011110 */
Hannes Reinecke98b96a72015-04-24 13:18:23 +020011111 adv_dvc->carrier = dma_alloc_coherent(board->dev,
11112 ADV_CARRIER_BUFSIZE, &adv_dvc->carrier_addr, GFP_KERNEL);
11113 ASC_DBG(1, "carrier 0x%p\n", adv_dvc->carrier);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011114
Hannes Reinecke98b96a72015-04-24 13:18:23 +020011115 if (!adv_dvc->carrier)
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011116 goto kmalloc_failed;
11117
11118 /*
11119 * Allocate up to 'max_host_qng' request structures for the Wide
11120 * board. The total size is about 16 KB, so allocate all at once.
11121 * If the allocation fails decrement and try again.
11122 */
Hannes Reinecke4b47e462015-04-24 13:18:24 +020011123 board->adv_reqp_size = adv_dvc->max_host_qng * sizeof(adv_req_t);
11124 if (board->adv_reqp_size & 0x1f) {
11125 ASC_DBG(1, "unaligned reqp %lu bytes\n", sizeof(adv_req_t));
11126 board->adv_reqp_size = ADV_32BALIGN(board->adv_reqp_size);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011127 }
Hannes Reinecke4b47e462015-04-24 13:18:24 +020011128 board->adv_reqp = dma_alloc_coherent(board->dev, board->adv_reqp_size,
11129 &board->adv_reqp_addr, GFP_KERNEL);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011130
Hannes Reinecke4b47e462015-04-24 13:18:24 +020011131 if (!board->adv_reqp)
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011132 goto kmalloc_failed;
11133
Hannes Reinecke4b47e462015-04-24 13:18:24 +020011134 ASC_DBG(1, "reqp 0x%p, req_cnt %d, bytes %lu\n", board->adv_reqp,
11135 adv_dvc->max_host_qng, board->adv_reqp_size);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011136
11137 /*
11138 * Allocate up to ADV_TOT_SG_BLOCK request structures for
11139 * the Wide board. Each structure is about 136 bytes.
11140 */
Hannes Reinecke0ce53822015-04-24 13:18:25 +020011141 sgblk_pool_size = sizeof(adv_sgblk_t) * ADV_TOT_SG_BLOCK;
11142 board->adv_sgblk_pool = dma_pool_create("adv_sgblk", board->dev,
11143 sgblk_pool_size, 32, 0);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011144
Hannes Reinecke0ce53822015-04-24 13:18:25 +020011145 ASC_DBG(1, "sg_cnt %d * %lu = %lu bytes\n", ADV_TOT_SG_BLOCK,
11146 sizeof(adv_sgblk_t), sgblk_pool_size);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011147
Hannes Reinecke0ce53822015-04-24 13:18:25 +020011148 if (!board->adv_sgblk_pool)
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011149 goto kmalloc_failed;
11150
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011151 if (adv_dvc->chip_type == ADV_CHIP_ASC3550) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011152 ASC_DBG(2, "AdvInitAsc3550Driver()\n");
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011153 warn_code = AdvInitAsc3550Driver(adv_dvc);
11154 } else if (adv_dvc->chip_type == ADV_CHIP_ASC38C0800) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011155 ASC_DBG(2, "AdvInitAsc38C0800Driver()\n");
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011156 warn_code = AdvInitAsc38C0800Driver(adv_dvc);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011157 } else {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011158 ASC_DBG(2, "AdvInitAsc38C1600Driver()\n");
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011159 warn_code = AdvInitAsc38C1600Driver(adv_dvc);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011160 }
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011161 err_code = adv_dvc->err_code;
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011162
11163 if (warn_code || err_code) {
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011164 shost_printk(KERN_WARNING, shost, "error: warn 0x%x, error "
11165 "0x%x\n", warn_code, err_code);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011166 }
11167
11168 goto exit;
11169
11170 kmalloc_failed:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011171 shost_printk(KERN_ERR, shost, "error: kmalloc() failed\n");
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011172 err_code = ADV_ERROR;
11173 exit:
11174 return err_code;
11175}
11176
Matthew Wilcox98d41c22007-10-02 21:55:37 -040011177static void advansys_wide_free_mem(struct asc_board *board)
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011178{
Matthew Wilcox98d41c22007-10-02 21:55:37 -040011179 struct adv_dvc_var *adv_dvc = &board->dvc_var.adv_dvc_var;
Hannes Reinecke98b96a72015-04-24 13:18:23 +020011180
11181 if (adv_dvc->carrier) {
11182 dma_free_coherent(board->dev, ADV_CARRIER_BUFSIZE,
11183 adv_dvc->carrier, adv_dvc->carrier_addr);
11184 adv_dvc->carrier = NULL;
11185 }
Hannes Reinecke4b47e462015-04-24 13:18:24 +020011186 if (board->adv_reqp) {
11187 dma_free_coherent(board->dev, board->adv_reqp_size,
11188 board->adv_reqp, board->adv_reqp_addr);
11189 board->adv_reqp = NULL;
11190 }
Hannes Reinecke0ce53822015-04-24 13:18:25 +020011191 if (board->adv_sgblk_pool) {
11192 dma_pool_destroy(board->adv_sgblk_pool);
11193 board->adv_sgblk_pool = NULL;
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011194 }
11195}
11196
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011197static int advansys_board_found(struct Scsi_Host *shost, unsigned int iop,
11198 int bus_type)
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011199{
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011200 struct pci_dev *pdev;
Matthew Wilcoxd2411492007-10-02 21:55:31 -040011201 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011202 ASC_DVC_VAR *asc_dvc_varp = NULL;
11203 ADV_DVC_VAR *adv_dvc_varp = NULL;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011204 int share_irq, warn_code, ret;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011205
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011206 pdev = (bus_type == ASC_IS_PCI) ? to_pci_dev(boardp->dev) : NULL;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011207
11208 if (ASC_NARROW_BOARD(boardp)) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011209 ASC_DBG(1, "narrow board\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011210 asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
11211 asc_dvc_varp->bus_type = bus_type;
11212 asc_dvc_varp->drv_ptr = boardp;
11213 asc_dvc_varp->cfg = &boardp->dvc_cfg.asc_dvc_cfg;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011214 asc_dvc_varp->iop_base = iop;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011215 } else {
Matthew Wilcox57ba5fe2007-07-26 11:55:07 -040011216#ifdef CONFIG_PCI
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011217 adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
11218 adv_dvc_varp->drv_ptr = boardp;
11219 adv_dvc_varp->cfg = &boardp->dvc_cfg.adv_dvc_cfg;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011220 if (pdev->device == PCI_DEVICE_ID_ASP_ABP940UW) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011221 ASC_DBG(1, "wide board ASC-3550\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011222 adv_dvc_varp->chip_type = ADV_CHIP_ASC3550;
11223 } else if (pdev->device == PCI_DEVICE_ID_38C0800_REV1) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011224 ASC_DBG(1, "wide board ASC-38C0800\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011225 adv_dvc_varp->chip_type = ADV_CHIP_ASC38C0800;
11226 } else {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011227 ASC_DBG(1, "wide board ASC-38C1600\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011228 adv_dvc_varp->chip_type = ADV_CHIP_ASC38C1600;
11229 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011230
Matthew Wilcox57ba5fe2007-07-26 11:55:07 -040011231 boardp->asc_n_io_port = pci_resource_len(pdev, 1);
Arjan van de Ven25729a72008-09-28 16:18:02 -070011232 boardp->ioremap_addr = pci_ioremap_bar(pdev, 1);
Matthew Wilcox57ba5fe2007-07-26 11:55:07 -040011233 if (!boardp->ioremap_addr) {
Matthew Wilcox9d511a42007-10-02 21:55:42 -040011234 shost_printk(KERN_ERR, shost, "ioremap(%lx, %d) "
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011235 "returned NULL\n",
Matthew Wilcox9d511a42007-10-02 21:55:42 -040011236 (long)pci_resource_start(pdev, 1),
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011237 boardp->asc_n_io_port);
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011238 ret = -ENODEV;
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011239 goto err_shost;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011240 }
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011241 adv_dvc_varp->iop_base = (AdvPortAddr)boardp->ioremap_addr;
11242 ASC_DBG(1, "iop_base: 0x%p\n", adv_dvc_varp->iop_base);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011243
11244 /*
11245 * Even though it isn't used to access wide boards, other
11246 * than for the debug line below, save I/O Port address so
11247 * that it can be reported.
11248 */
11249 boardp->ioport = iop;
11250
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011251 ASC_DBG(1, "iopb_chip_id_1 0x%x, iopw_chip_id_0 0x%x\n",
11252 (ushort)inp(iop + 1), (ushort)inpw(iop));
Matthew Wilcox57ba5fe2007-07-26 11:55:07 -040011253#endif /* CONFIG_PCI */
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011254 }
11255
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011256 if (ASC_NARROW_BOARD(boardp)) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011257 /*
11258 * Set the board bus type and PCI IRQ before
11259 * calling AscInitGetConfig().
11260 */
11261 switch (asc_dvc_varp->bus_type) {
11262#ifdef CONFIG_ISA
11263 case ASC_IS_ISA:
Hannes Reineckeae267592015-04-24 13:18:28 +020011264 shost->unchecked_isa_dma = true;
Matthew Wilcox074c8fe2007-07-28 23:11:05 -060011265 share_irq = 0;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011266 break;
11267 case ASC_IS_VL:
Hannes Reineckeae267592015-04-24 13:18:28 +020011268 shost->unchecked_isa_dma = false;
Matthew Wilcox074c8fe2007-07-28 23:11:05 -060011269 share_irq = 0;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011270 break;
11271 case ASC_IS_EISA:
Hannes Reineckeae267592015-04-24 13:18:28 +020011272 shost->unchecked_isa_dma = false;
Matthew Wilcox074c8fe2007-07-28 23:11:05 -060011273 share_irq = IRQF_SHARED;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011274 break;
11275#endif /* CONFIG_ISA */
11276#ifdef CONFIG_PCI
11277 case ASC_IS_PCI:
Hannes Reineckeae267592015-04-24 13:18:28 +020011278 shost->unchecked_isa_dma = false;
Matthew Wilcox074c8fe2007-07-28 23:11:05 -060011279 share_irq = IRQF_SHARED;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011280 break;
11281#endif /* CONFIG_PCI */
11282 default:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011283 shost_printk(KERN_ERR, shost, "unknown adapter type: "
11284 "%d\n", asc_dvc_varp->bus_type);
Hannes Reineckeae267592015-04-24 13:18:28 +020011285 shost->unchecked_isa_dma = false;
Matthew Wilcox074c8fe2007-07-28 23:11:05 -060011286 share_irq = 0;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011287 break;
11288 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011289
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011290 /*
11291 * NOTE: AscInitGetConfig() may change the board's
11292 * bus_type value. The bus_type value should no
11293 * longer be used. If the bus_type field must be
11294 * referenced only use the bit-wise AND operator "&".
11295 */
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011296 ASC_DBG(2, "AscInitGetConfig()\n");
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011297 ret = AscInitGetConfig(shost) ? -ENODEV : 0;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011298 } else {
Matthew Wilcoxc2dce2f2007-09-09 08:56:30 -060011299#ifdef CONFIG_PCI
11300 /*
11301 * For Wide boards set PCI information before calling
11302 * AdvInitGetConfig().
11303 */
Hannes Reineckeae267592015-04-24 13:18:28 +020011304 shost->unchecked_isa_dma = false;
Matthew Wilcoxc2dce2f2007-09-09 08:56:30 -060011305 share_irq = IRQF_SHARED;
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011306 ASC_DBG(2, "AdvInitGetConfig()\n");
Matthew Wilcox394dbf32007-07-26 11:56:40 -040011307
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011308 ret = AdvInitGetConfig(pdev, shost) ? -ENODEV : 0;
Matthew Wilcoxc2dce2f2007-09-09 08:56:30 -060011309#endif /* CONFIG_PCI */
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011310 }
11311
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011312 if (ret)
Al Virob59fb6f2013-03-31 02:59:55 -040011313 goto err_unmap;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011314
11315 /*
11316 * Save the EEPROM configuration so that it can be displayed
11317 * from /proc/scsi/advansys/[0...].
11318 */
11319 if (ASC_NARROW_BOARD(boardp)) {
11320
11321 ASCEEP_CONFIG *ep;
11322
11323 /*
11324 * Set the adapter's target id bit in the 'init_tidmask' field.
11325 */
11326 boardp->init_tidmask |=
11327 ADV_TID_TO_TIDMASK(asc_dvc_varp->cfg->chip_scsi_id);
11328
11329 /*
11330 * Save EEPROM settings for the board.
11331 */
11332 ep = &boardp->eep_config.asc_eep;
11333
11334 ep->init_sdtr = asc_dvc_varp->cfg->sdtr_enable;
11335 ep->disc_enable = asc_dvc_varp->cfg->disc_enable;
11336 ep->use_cmd_qng = asc_dvc_varp->cfg->cmd_qng_enabled;
11337 ASC_EEP_SET_DMA_SPD(ep, asc_dvc_varp->cfg->isa_dma_speed);
11338 ep->start_motor = asc_dvc_varp->start_motor;
11339 ep->cntl = asc_dvc_varp->dvc_cntl;
11340 ep->no_scam = asc_dvc_varp->no_scam;
11341 ep->max_total_qng = asc_dvc_varp->max_total_qng;
11342 ASC_EEP_SET_CHIP_ID(ep, asc_dvc_varp->cfg->chip_scsi_id);
11343 /* 'max_tag_qng' is set to the same value for every device. */
11344 ep->max_tag_qng = asc_dvc_varp->cfg->max_tag_qng[0];
11345 ep->adapter_info[0] = asc_dvc_varp->cfg->adapter_info[0];
11346 ep->adapter_info[1] = asc_dvc_varp->cfg->adapter_info[1];
11347 ep->adapter_info[2] = asc_dvc_varp->cfg->adapter_info[2];
11348 ep->adapter_info[3] = asc_dvc_varp->cfg->adapter_info[3];
11349 ep->adapter_info[4] = asc_dvc_varp->cfg->adapter_info[4];
11350 ep->adapter_info[5] = asc_dvc_varp->cfg->adapter_info[5];
11351
11352 /*
11353 * Modify board configuration.
11354 */
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011355 ASC_DBG(2, "AscInitSetConfig()\n");
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011356 ret = AscInitSetConfig(pdev, shost) ? -ENODEV : 0;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011357 if (ret)
Al Virob59fb6f2013-03-31 02:59:55 -040011358 goto err_unmap;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011359 } else {
11360 ADVEEP_3550_CONFIG *ep_3550;
11361 ADVEEP_38C0800_CONFIG *ep_38C0800;
11362 ADVEEP_38C1600_CONFIG *ep_38C1600;
11363
11364 /*
11365 * Save Wide EEP Configuration Information.
11366 */
11367 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
11368 ep_3550 = &boardp->eep_config.adv_3550_eep;
11369
11370 ep_3550->adapter_scsi_id = adv_dvc_varp->chip_scsi_id;
11371 ep_3550->max_host_qng = adv_dvc_varp->max_host_qng;
11372 ep_3550->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
11373 ep_3550->termination = adv_dvc_varp->cfg->termination;
11374 ep_3550->disc_enable = adv_dvc_varp->cfg->disc_enable;
11375 ep_3550->bios_ctrl = adv_dvc_varp->bios_ctrl;
11376 ep_3550->wdtr_able = adv_dvc_varp->wdtr_able;
11377 ep_3550->sdtr_able = adv_dvc_varp->sdtr_able;
11378 ep_3550->ultra_able = adv_dvc_varp->ultra_able;
11379 ep_3550->tagqng_able = adv_dvc_varp->tagqng_able;
11380 ep_3550->start_motor = adv_dvc_varp->start_motor;
11381 ep_3550->scsi_reset_delay =
11382 adv_dvc_varp->scsi_reset_wait;
11383 ep_3550->serial_number_word1 =
11384 adv_dvc_varp->cfg->serial1;
11385 ep_3550->serial_number_word2 =
11386 adv_dvc_varp->cfg->serial2;
11387 ep_3550->serial_number_word3 =
11388 adv_dvc_varp->cfg->serial3;
11389 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
11390 ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
11391
11392 ep_38C0800->adapter_scsi_id =
11393 adv_dvc_varp->chip_scsi_id;
11394 ep_38C0800->max_host_qng = adv_dvc_varp->max_host_qng;
11395 ep_38C0800->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
11396 ep_38C0800->termination_lvd =
11397 adv_dvc_varp->cfg->termination;
11398 ep_38C0800->disc_enable =
11399 adv_dvc_varp->cfg->disc_enable;
11400 ep_38C0800->bios_ctrl = adv_dvc_varp->bios_ctrl;
11401 ep_38C0800->wdtr_able = adv_dvc_varp->wdtr_able;
11402 ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
11403 ep_38C0800->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
11404 ep_38C0800->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
11405 ep_38C0800->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
11406 ep_38C0800->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
11407 ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
11408 ep_38C0800->start_motor = adv_dvc_varp->start_motor;
11409 ep_38C0800->scsi_reset_delay =
11410 adv_dvc_varp->scsi_reset_wait;
11411 ep_38C0800->serial_number_word1 =
11412 adv_dvc_varp->cfg->serial1;
11413 ep_38C0800->serial_number_word2 =
11414 adv_dvc_varp->cfg->serial2;
11415 ep_38C0800->serial_number_word3 =
11416 adv_dvc_varp->cfg->serial3;
11417 } else {
11418 ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
11419
11420 ep_38C1600->adapter_scsi_id =
11421 adv_dvc_varp->chip_scsi_id;
11422 ep_38C1600->max_host_qng = adv_dvc_varp->max_host_qng;
11423 ep_38C1600->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
11424 ep_38C1600->termination_lvd =
11425 adv_dvc_varp->cfg->termination;
11426 ep_38C1600->disc_enable =
11427 adv_dvc_varp->cfg->disc_enable;
11428 ep_38C1600->bios_ctrl = adv_dvc_varp->bios_ctrl;
11429 ep_38C1600->wdtr_able = adv_dvc_varp->wdtr_able;
11430 ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
11431 ep_38C1600->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
11432 ep_38C1600->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
11433 ep_38C1600->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
11434 ep_38C1600->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
11435 ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
11436 ep_38C1600->start_motor = adv_dvc_varp->start_motor;
11437 ep_38C1600->scsi_reset_delay =
11438 adv_dvc_varp->scsi_reset_wait;
11439 ep_38C1600->serial_number_word1 =
11440 adv_dvc_varp->cfg->serial1;
11441 ep_38C1600->serial_number_word2 =
11442 adv_dvc_varp->cfg->serial2;
11443 ep_38C1600->serial_number_word3 =
11444 adv_dvc_varp->cfg->serial3;
11445 }
11446
11447 /*
11448 * Set the adapter's target id bit in the 'init_tidmask' field.
11449 */
11450 boardp->init_tidmask |=
11451 ADV_TID_TO_TIDMASK(adv_dvc_varp->chip_scsi_id);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011452 }
11453
11454 /*
11455 * Channels are numbered beginning with 0. For AdvanSys one host
11456 * structure supports one channel. Multi-channel boards have a
11457 * separate host structure for each channel.
11458 */
11459 shost->max_channel = 0;
11460 if (ASC_NARROW_BOARD(boardp)) {
11461 shost->max_id = ASC_MAX_TID + 1;
11462 shost->max_lun = ASC_MAX_LUN + 1;
Matthew Wilcoxf05ec592007-09-09 08:56:36 -060011463 shost->max_cmd_len = ASC_MAX_CDB_LEN;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011464
11465 shost->io_port = asc_dvc_varp->iop_base;
11466 boardp->asc_n_io_port = ASC_IOADR_GAP;
11467 shost->this_id = asc_dvc_varp->cfg->chip_scsi_id;
11468
11469 /* Set maximum number of queues the adapter can handle. */
11470 shost->can_queue = asc_dvc_varp->max_total_qng;
11471 } else {
11472 shost->max_id = ADV_MAX_TID + 1;
11473 shost->max_lun = ADV_MAX_LUN + 1;
Matthew Wilcoxf05ec592007-09-09 08:56:36 -060011474 shost->max_cmd_len = ADV_MAX_CDB_LEN;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011475
11476 /*
11477 * Save the I/O Port address and length even though
11478 * I/O ports are not used to access Wide boards.
11479 * Instead the Wide boards are accessed with
11480 * PCI Memory Mapped I/O.
11481 */
11482 shost->io_port = iop;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011483
11484 shost->this_id = adv_dvc_varp->chip_scsi_id;
11485
11486 /* Set maximum number of queues the adapter can handle. */
11487 shost->can_queue = adv_dvc_varp->max_host_qng;
11488 }
Hannes Reinecke9c17c622015-04-24 13:18:21 +020011489 ret = scsi_init_shared_tag_map(shost, shost->can_queue);
11490 if (ret) {
11491 shost_printk(KERN_ERR, shost, "init tag map failed\n");
11492 goto err_free_dma;
11493 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011494
11495 /*
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011496 * Following v1.3.89, 'cmd_per_lun' is no longer needed
11497 * and should be set to zero.
11498 *
11499 * But because of a bug introduced in v1.3.89 if the driver is
11500 * compiled as a module and 'cmd_per_lun' is zero, the Mid-Level
11501 * SCSI function 'allocate_device' will panic. To allow the driver
11502 * to work as a module in these kernels set 'cmd_per_lun' to 1.
11503 *
11504 * Note: This is wrong. cmd_per_lun should be set to the depth
11505 * you want on untagged devices always.
11506 #ifdef MODULE
11507 */
11508 shost->cmd_per_lun = 1;
11509/* #else
11510 shost->cmd_per_lun = 0;
11511#endif */
11512
11513 /*
11514 * Set the maximum number of scatter-gather elements the
11515 * adapter can handle.
11516 */
11517 if (ASC_NARROW_BOARD(boardp)) {
11518 /*
11519 * Allow two commands with 'sg_tablesize' scatter-gather
11520 * elements to be executed simultaneously. This value is
11521 * the theoretical hardware limit. It may be decreased
11522 * below.
11523 */
11524 shost->sg_tablesize =
11525 (((asc_dvc_varp->max_total_qng - 2) / 2) *
11526 ASC_SG_LIST_PER_Q) + 1;
11527 } else {
11528 shost->sg_tablesize = ADV_MAX_SG_LIST;
11529 }
11530
11531 /*
11532 * The value of 'sg_tablesize' can not exceed the SCSI
11533 * mid-level driver definition of SG_ALL. SG_ALL also
11534 * must not be exceeded, because it is used to define the
11535 * size of the scatter-gather table in 'struct asc_sg_head'.
11536 */
11537 if (shost->sg_tablesize > SG_ALL) {
11538 shost->sg_tablesize = SG_ALL;
11539 }
11540
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011541 ASC_DBG(1, "sg_tablesize: %d\n", shost->sg_tablesize);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011542
11543 /* BIOS start address. */
11544 if (ASC_NARROW_BOARD(boardp)) {
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011545 shost->base = AscGetChipBiosAddress(asc_dvc_varp->iop_base,
11546 asc_dvc_varp->bus_type);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011547 } else {
11548 /*
11549 * Fill-in BIOS board variables. The Wide BIOS saves
11550 * information in LRAM that is used by the driver.
11551 */
11552 AdvReadWordLram(adv_dvc_varp->iop_base,
11553 BIOS_SIGNATURE, boardp->bios_signature);
11554 AdvReadWordLram(adv_dvc_varp->iop_base,
11555 BIOS_VERSION, boardp->bios_version);
11556 AdvReadWordLram(adv_dvc_varp->iop_base,
11557 BIOS_CODESEG, boardp->bios_codeseg);
11558 AdvReadWordLram(adv_dvc_varp->iop_base,
11559 BIOS_CODELEN, boardp->bios_codelen);
11560
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011561 ASC_DBG(1, "bios_signature 0x%x, bios_version 0x%x\n",
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011562 boardp->bios_signature, boardp->bios_version);
11563
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011564 ASC_DBG(1, "bios_codeseg 0x%x, bios_codelen 0x%x\n",
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011565 boardp->bios_codeseg, boardp->bios_codelen);
11566
11567 /*
11568 * If the BIOS saved a valid signature, then fill in
11569 * the BIOS code segment base address.
11570 */
11571 if (boardp->bios_signature == 0x55AA) {
11572 /*
11573 * Convert x86 realmode code segment to a linear
11574 * address by shifting left 4.
11575 */
11576 shost->base = ((ulong)boardp->bios_codeseg << 4);
11577 } else {
11578 shost->base = 0;
11579 }
11580 }
11581
11582 /*
11583 * Register Board Resources - I/O Port, DMA, IRQ
11584 */
11585
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011586 /* Register DMA Channel for Narrow boards. */
11587 shost->dma_channel = NO_ISA_DMA; /* Default to no ISA DMA. */
11588#ifdef CONFIG_ISA
11589 if (ASC_NARROW_BOARD(boardp)) {
11590 /* Register DMA channel for ISA bus. */
11591 if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
11592 shost->dma_channel = asc_dvc_varp->cfg->isa_dma_channel;
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060011593 ret = request_dma(shost->dma_channel, DRV_NAME);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011594 if (ret) {
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011595 shost_printk(KERN_ERR, shost, "request_dma() "
11596 "%d failed %d\n",
11597 shost->dma_channel, ret);
Al Virob59fb6f2013-03-31 02:59:55 -040011598 goto err_unmap;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011599 }
11600 AscEnableIsaDma(shost->dma_channel);
11601 }
11602 }
11603#endif /* CONFIG_ISA */
11604
11605 /* Register IRQ Number. */
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011606 ASC_DBG(2, "request_irq(%d, %p)\n", boardp->irq, shost);
Matthew Wilcox074c8fe2007-07-28 23:11:05 -060011607
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011608 ret = request_irq(boardp->irq, advansys_interrupt, share_irq,
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060011609 DRV_NAME, shost);
Matthew Wilcox074c8fe2007-07-28 23:11:05 -060011610
11611 if (ret) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011612 if (ret == -EBUSY) {
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011613 shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
11614 "already in use\n", boardp->irq);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011615 } else if (ret == -EINVAL) {
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011616 shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
11617 "not valid\n", boardp->irq);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011618 } else {
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011619 shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
11620 "failed with %d\n", boardp->irq, ret);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011621 }
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011622 goto err_free_dma;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011623 }
11624
11625 /*
11626 * Initialize board RISC chip and enable interrupts.
11627 */
11628 if (ASC_NARROW_BOARD(boardp)) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011629 ASC_DBG(2, "AscInitAsc1000Driver()\n");
FUJITA Tomonori7d5d4082008-02-08 09:50:08 +090011630
11631 asc_dvc_varp->overrun_buf = kzalloc(ASC_OVERRUN_BSIZE, GFP_KERNEL);
11632 if (!asc_dvc_varp->overrun_buf) {
11633 ret = -ENOMEM;
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -030011634 goto err_free_irq;
FUJITA Tomonori7d5d4082008-02-08 09:50:08 +090011635 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011636 warn_code = AscInitAsc1000Driver(asc_dvc_varp);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011637
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011638 if (warn_code || asc_dvc_varp->err_code) {
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011639 shost_printk(KERN_ERR, shost, "error: init_state 0x%x, "
11640 "warn 0x%x, error 0x%x\n",
11641 asc_dvc_varp->init_state, warn_code,
11642 asc_dvc_varp->err_code);
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -030011643 if (!asc_dvc_varp->overrun_dma) {
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011644 ret = -ENODEV;
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -030011645 goto err_free_mem;
FUJITA Tomonori7d5d4082008-02-08 09:50:08 +090011646 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011647 }
11648 } else {
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -030011649 if (advansys_wide_init_chip(shost)) {
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011650 ret = -ENODEV;
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -030011651 goto err_free_mem;
11652 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011653 }
11654
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011655 ASC_DBG_PRT_SCSI_HOST(2, shost);
11656
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011657 ret = scsi_add_host(shost, boardp->dev);
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060011658 if (ret)
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -030011659 goto err_free_mem;
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060011660
11661 scsi_scan_host(shost);
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011662 return 0;
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011663
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -030011664 err_free_mem:
11665 if (ASC_NARROW_BOARD(boardp)) {
11666 if (asc_dvc_varp->overrun_dma)
11667 dma_unmap_single(boardp->dev, asc_dvc_varp->overrun_dma,
11668 ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
11669 kfree(asc_dvc_varp->overrun_buf);
11670 } else
11671 advansys_wide_free_mem(boardp);
11672 err_free_irq:
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011673 free_irq(boardp->irq, shost);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011674 err_free_dma:
Al Viro30037812008-11-22 17:34:54 +000011675#ifdef CONFIG_ISA
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011676 if (shost->dma_channel != NO_ISA_DMA)
11677 free_dma(shost->dma_channel);
Al Viro30037812008-11-22 17:34:54 +000011678#endif
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011679 err_unmap:
11680 if (boardp->ioremap_addr)
11681 iounmap(boardp->ioremap_addr);
11682 err_shost:
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011683 return ret;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011684}
11685
11686/*
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011687 * advansys_release()
11688 *
11689 * Release resources allocated for a single AdvanSys adapter.
11690 */
11691static int advansys_release(struct Scsi_Host *shost)
11692{
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -040011693 struct asc_board *board = shost_priv(shost);
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011694 ASC_DBG(1, "begin\n");
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060011695 scsi_remove_host(shost);
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -040011696 free_irq(board->irq, shost);
Al Viro30037812008-11-22 17:34:54 +000011697#ifdef CONFIG_ISA
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011698 if (shost->dma_channel != NO_ISA_DMA) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011699 ASC_DBG(1, "free_dma()\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011700 free_dma(shost->dma_channel);
11701 }
Al Viro30037812008-11-22 17:34:54 +000011702#endif
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -040011703 if (ASC_NARROW_BOARD(board)) {
11704 dma_unmap_single(board->dev,
11705 board->dvc_var.asc_dvc_var.overrun_dma,
11706 ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
FUJITA Tomonori7d5d4082008-02-08 09:50:08 +090011707 kfree(board->dvc_var.asc_dvc_var.overrun_buf);
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -040011708 } else {
11709 iounmap(board->ioremap_addr);
11710 advansys_wide_free_mem(board);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011711 }
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060011712 scsi_host_put(shost);
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011713 ASC_DBG(1, "end\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011714 return 0;
11715}
11716
Matthew Wilcox95c9f162007-09-09 08:56:39 -060011717#define ASC_IOADR_TABLE_MAX_IX 11
11718
Randy Dunlap747d0162008-01-14 00:55:18 -080011719static PortAddr _asc_def_iop_base[ASC_IOADR_TABLE_MAX_IX] = {
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011720 0x100, 0x0110, 0x120, 0x0130, 0x140, 0x0150, 0x0190,
11721 0x0210, 0x0230, 0x0250, 0x0330
11722};
11723
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011724/*
11725 * The ISA IRQ number is found in bits 2 and 3 of the CfgLsw. It decodes as:
11726 * 00: 10
11727 * 01: 11
11728 * 10: 12
11729 * 11: 15
11730 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011731static unsigned int advansys_isa_irq_no(PortAddr iop_base)
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011732{
11733 unsigned short cfg_lsw = AscGetChipCfgLsw(iop_base);
11734 unsigned int chip_irq = ((cfg_lsw >> 2) & 0x03) + 10;
11735 if (chip_irq == 13)
11736 chip_irq = 15;
11737 return chip_irq;
11738}
11739
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011740static int advansys_isa_probe(struct device *dev, unsigned int id)
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011741{
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011742 int err = -ENODEV;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011743 PortAddr iop_base = _asc_def_iop_base[id];
11744 struct Scsi_Host *shost;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011745 struct asc_board *board;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011746
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060011747 if (!request_region(iop_base, ASC_IOADR_GAP, DRV_NAME)) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011748 ASC_DBG(1, "I/O port 0x%x busy\n", iop_base);
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011749 return -ENODEV;
11750 }
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011751 ASC_DBG(1, "probing I/O port 0x%x\n", iop_base);
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011752 if (!AscFindSignature(iop_base))
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011753 goto release_region;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011754 if (!(AscGetChipVersion(iop_base, ASC_IS_ISA) & ASC_CHIP_VER_ISA_BIT))
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011755 goto release_region;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011756
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011757 err = -ENOMEM;
11758 shost = scsi_host_alloc(&advansys_template, sizeof(*board));
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011759 if (!shost)
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011760 goto release_region;
11761
Matthew Wilcoxd2411492007-10-02 21:55:31 -040011762 board = shost_priv(shost);
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011763 board->irq = advansys_isa_irq_no(iop_base);
11764 board->dev = dev;
Hannes Reinecke9c17c622015-04-24 13:18:21 +020011765 board->shost = shost;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011766
11767 err = advansys_board_found(shost, iop_base, ASC_IS_ISA);
11768 if (err)
11769 goto free_host;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011770
11771 dev_set_drvdata(dev, shost);
11772 return 0;
11773
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011774 free_host:
11775 scsi_host_put(shost);
11776 release_region:
Matthew Wilcox71f36112007-07-30 08:04:53 -060011777 release_region(iop_base, ASC_IOADR_GAP);
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011778 return err;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011779}
11780
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011781static int advansys_isa_remove(struct device *dev, unsigned int id)
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011782{
Matthew Wilcox71f36112007-07-30 08:04:53 -060011783 int ioport = _asc_def_iop_base[id];
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011784 advansys_release(dev_get_drvdata(dev));
Matthew Wilcox71f36112007-07-30 08:04:53 -060011785 release_region(ioport, ASC_IOADR_GAP);
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011786 return 0;
11787}
11788
11789static struct isa_driver advansys_isa_driver = {
11790 .probe = advansys_isa_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011791 .remove = advansys_isa_remove,
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011792 .driver = {
11793 .owner = THIS_MODULE,
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060011794 .name = DRV_NAME,
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011795 },
11796};
11797
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011798/*
11799 * The VLB IRQ number is found in bits 2 to 4 of the CfgLsw. It decodes as:
11800 * 000: invalid
11801 * 001: 10
11802 * 010: 11
11803 * 011: 12
11804 * 100: invalid
11805 * 101: 14
11806 * 110: 15
11807 * 111: invalid
11808 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011809static unsigned int advansys_vlb_irq_no(PortAddr iop_base)
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011810{
11811 unsigned short cfg_lsw = AscGetChipCfgLsw(iop_base);
11812 unsigned int chip_irq = ((cfg_lsw >> 2) & 0x07) + 9;
11813 if ((chip_irq < 10) || (chip_irq == 13) || (chip_irq > 15))
11814 return 0;
11815 return chip_irq;
11816}
11817
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011818static int advansys_vlb_probe(struct device *dev, unsigned int id)
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011819{
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011820 int err = -ENODEV;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011821 PortAddr iop_base = _asc_def_iop_base[id];
11822 struct Scsi_Host *shost;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011823 struct asc_board *board;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011824
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060011825 if (!request_region(iop_base, ASC_IOADR_GAP, DRV_NAME)) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011826 ASC_DBG(1, "I/O port 0x%x busy\n", iop_base);
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011827 return -ENODEV;
11828 }
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011829 ASC_DBG(1, "probing I/O port 0x%x\n", iop_base);
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011830 if (!AscFindSignature(iop_base))
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011831 goto release_region;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011832 /*
11833 * I don't think this condition can actually happen, but the old
11834 * driver did it, and the chances of finding a VLB setup in 2007
11835 * to do testing with is slight to none.
11836 */
11837 if (AscGetChipVersion(iop_base, ASC_IS_VL) > ASC_CHIP_MAX_VER_VL)
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011838 goto release_region;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011839
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011840 err = -ENOMEM;
11841 shost = scsi_host_alloc(&advansys_template, sizeof(*board));
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011842 if (!shost)
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011843 goto release_region;
11844
Matthew Wilcoxd2411492007-10-02 21:55:31 -040011845 board = shost_priv(shost);
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011846 board->irq = advansys_vlb_irq_no(iop_base);
11847 board->dev = dev;
Hannes Reinecke9c17c622015-04-24 13:18:21 +020011848 board->shost = shost;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011849
11850 err = advansys_board_found(shost, iop_base, ASC_IS_VL);
11851 if (err)
11852 goto free_host;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011853
11854 dev_set_drvdata(dev, shost);
11855 return 0;
11856
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011857 free_host:
11858 scsi_host_put(shost);
11859 release_region:
Matthew Wilcox71f36112007-07-30 08:04:53 -060011860 release_region(iop_base, ASC_IOADR_GAP);
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011861 return -ENODEV;
11862}
11863
11864static struct isa_driver advansys_vlb_driver = {
11865 .probe = advansys_vlb_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011866 .remove = advansys_isa_remove,
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011867 .driver = {
11868 .owner = THIS_MODULE,
Matthew Wilcoxb8e5152b2007-09-09 08:56:26 -060011869 .name = "advansys_vlb",
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011870 },
11871};
11872
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011873static struct eisa_device_id advansys_eisa_table[] = {
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011874 { "ABP7401" },
11875 { "ABP7501" },
11876 { "" }
11877};
11878
11879MODULE_DEVICE_TABLE(eisa, advansys_eisa_table);
11880
11881/*
11882 * EISA is a little more tricky than PCI; each EISA device may have two
11883 * channels, and this driver is written to make each channel its own Scsi_Host
11884 */
11885struct eisa_scsi_data {
11886 struct Scsi_Host *host[2];
11887};
11888
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011889/*
11890 * The EISA IRQ number is found in bits 8 to 10 of the CfgLsw. It decodes as:
11891 * 000: 10
11892 * 001: 11
11893 * 010: 12
11894 * 011: invalid
11895 * 100: 14
11896 * 101: 15
11897 * 110: invalid
11898 * 111: invalid
11899 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011900static unsigned int advansys_eisa_irq_no(struct eisa_device *edev)
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011901{
11902 unsigned short cfg_lsw = inw(edev->base_addr + 0xc86);
11903 unsigned int chip_irq = ((cfg_lsw >> 8) & 0x07) + 10;
11904 if ((chip_irq == 13) || (chip_irq > 15))
11905 return 0;
11906 return chip_irq;
11907}
11908
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011909static int advansys_eisa_probe(struct device *dev)
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011910{
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011911 int i, ioport, irq = 0;
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011912 int err;
11913 struct eisa_device *edev = to_eisa_device(dev);
11914 struct eisa_scsi_data *data;
11915
11916 err = -ENOMEM;
11917 data = kzalloc(sizeof(*data), GFP_KERNEL);
11918 if (!data)
11919 goto fail;
11920 ioport = edev->base_addr + 0xc30;
11921
11922 err = -ENODEV;
11923 for (i = 0; i < 2; i++, ioport += 0x20) {
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011924 struct asc_board *board;
11925 struct Scsi_Host *shost;
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060011926 if (!request_region(ioport, ASC_IOADR_GAP, DRV_NAME)) {
Matthew Wilcox71f36112007-07-30 08:04:53 -060011927 printk(KERN_WARNING "Region %x-%x busy\n", ioport,
11928 ioport + ASC_IOADR_GAP - 1);
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011929 continue;
Matthew Wilcox71f36112007-07-30 08:04:53 -060011930 }
11931 if (!AscFindSignature(ioport)) {
11932 release_region(ioport, ASC_IOADR_GAP);
11933 continue;
11934 }
11935
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011936 /*
11937 * I don't know why we need to do this for EISA chips, but
11938 * not for any others. It looks to be equivalent to
11939 * AscGetChipCfgMsw, but I may have overlooked something,
11940 * so I'm not converting it until I get an EISA board to
11941 * test with.
11942 */
11943 inw(ioport + 4);
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011944
11945 if (!irq)
11946 irq = advansys_eisa_irq_no(edev);
11947
11948 err = -ENOMEM;
11949 shost = scsi_host_alloc(&advansys_template, sizeof(*board));
11950 if (!shost)
11951 goto release_region;
11952
Matthew Wilcoxd2411492007-10-02 21:55:31 -040011953 board = shost_priv(shost);
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011954 board->irq = irq;
11955 board->dev = dev;
Hannes Reinecke9c17c622015-04-24 13:18:21 +020011956 board->shost = shost;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011957
11958 err = advansys_board_found(shost, ioport, ASC_IS_EISA);
11959 if (!err) {
11960 data->host[i] = shost;
11961 continue;
Matthew Wilcox71f36112007-07-30 08:04:53 -060011962 }
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011963
11964 scsi_host_put(shost);
11965 release_region:
11966 release_region(ioport, ASC_IOADR_GAP);
11967 break;
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011968 }
11969
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011970 if (err)
11971 goto free_data;
11972 dev_set_drvdata(dev, data);
11973 return 0;
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011974
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011975 free_data:
11976 kfree(data->host[0]);
11977 kfree(data->host[1]);
11978 kfree(data);
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011979 fail:
11980 return err;
11981}
11982
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011983static int advansys_eisa_remove(struct device *dev)
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011984{
11985 int i;
11986 struct eisa_scsi_data *data = dev_get_drvdata(dev);
11987
11988 for (i = 0; i < 2; i++) {
Matthew Wilcox71f36112007-07-30 08:04:53 -060011989 int ioport;
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011990 struct Scsi_Host *shost = data->host[i];
11991 if (!shost)
11992 continue;
Matthew Wilcox71f36112007-07-30 08:04:53 -060011993 ioport = shost->io_port;
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011994 advansys_release(shost);
Matthew Wilcox71f36112007-07-30 08:04:53 -060011995 release_region(ioport, ASC_IOADR_GAP);
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011996 }
11997
11998 kfree(data);
11999 return 0;
12000}
12001
12002static struct eisa_driver advansys_eisa_driver = {
12003 .id_table = advansys_eisa_table,
12004 .driver = {
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060012005 .name = DRV_NAME,
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060012006 .probe = advansys_eisa_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012007 .remove = advansys_eisa_remove,
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060012008 }
12009};
12010
Dave Jones2672ea82006-08-02 17:11:49 -040012011/* PCI Devices supported by this driver */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012012static struct pci_device_id advansys_pci_tbl[] = {
Matthew Wilcox27c868c2007-07-26 10:56:23 -040012013 {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_1200A,
12014 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
12015 {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940,
12016 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
12017 {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940U,
12018 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
12019 {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940UW,
12020 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
12021 {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_38C0800_REV1,
12022 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
12023 {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_38C1600_REV1,
12024 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
12025 {}
Dave Jones2672ea82006-08-02 17:11:49 -040012026};
Matthew Wilcox27c868c2007-07-26 10:56:23 -040012027
Dave Jones2672ea82006-08-02 17:11:49 -040012028MODULE_DEVICE_TABLE(pci, advansys_pci_tbl);
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012029
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012030static void advansys_set_latency(struct pci_dev *pdev)
Matthew Wilcox9649af32007-07-26 21:51:47 -060012031{
12032 if ((pdev->device == PCI_DEVICE_ID_ASP_1200A) ||
12033 (pdev->device == PCI_DEVICE_ID_ASP_ABP940)) {
12034 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0);
12035 } else {
12036 u8 latency;
12037 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency);
12038 if (latency < 0x20)
12039 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x20);
12040 }
12041}
12042
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012043static int advansys_pci_probe(struct pci_dev *pdev,
12044 const struct pci_device_id *ent)
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012045{
12046 int err, ioport;
12047 struct Scsi_Host *shost;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040012048 struct asc_board *board;
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012049
12050 err = pci_enable_device(pdev);
12051 if (err)
12052 goto fail;
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060012053 err = pci_request_regions(pdev, DRV_NAME);
Matthew Wilcox71f36112007-07-30 08:04:53 -060012054 if (err)
12055 goto disable_device;
Matthew Wilcox9649af32007-07-26 21:51:47 -060012056 pci_set_master(pdev);
12057 advansys_set_latency(pdev);
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012058
Matthew Wilcoxd361db42007-10-02 21:55:29 -040012059 err = -ENODEV;
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012060 if (pci_resource_len(pdev, 0) == 0)
Matthew Wilcoxd361db42007-10-02 21:55:29 -040012061 goto release_region;
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012062
12063 ioport = pci_resource_start(pdev, 0);
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012064
Matthew Wilcoxd361db42007-10-02 21:55:29 -040012065 err = -ENOMEM;
12066 shost = scsi_host_alloc(&advansys_template, sizeof(*board));
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012067 if (!shost)
Matthew Wilcoxd361db42007-10-02 21:55:29 -040012068 goto release_region;
12069
Matthew Wilcoxd2411492007-10-02 21:55:31 -040012070 board = shost_priv(shost);
Matthew Wilcoxd361db42007-10-02 21:55:29 -040012071 board->irq = pdev->irq;
12072 board->dev = &pdev->dev;
Hannes Reinecke9c17c622015-04-24 13:18:21 +020012073 board->shost = shost;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040012074
12075 if (pdev->device == PCI_DEVICE_ID_ASP_ABP940UW ||
12076 pdev->device == PCI_DEVICE_ID_38C0800_REV1 ||
12077 pdev->device == PCI_DEVICE_ID_38C1600_REV1) {
12078 board->flags |= ASC_IS_WIDE_BOARD;
12079 }
12080
12081 err = advansys_board_found(shost, ioport, ASC_IS_PCI);
12082 if (err)
12083 goto free_host;
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012084
12085 pci_set_drvdata(pdev, shost);
12086 return 0;
12087
Matthew Wilcoxd361db42007-10-02 21:55:29 -040012088 free_host:
12089 scsi_host_put(shost);
12090 release_region:
Matthew Wilcox71f36112007-07-30 08:04:53 -060012091 pci_release_regions(pdev);
12092 disable_device:
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012093 pci_disable_device(pdev);
12094 fail:
12095 return err;
12096}
12097
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012098static void advansys_pci_remove(struct pci_dev *pdev)
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012099{
12100 advansys_release(pci_get_drvdata(pdev));
Matthew Wilcox71f36112007-07-30 08:04:53 -060012101 pci_release_regions(pdev);
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012102 pci_disable_device(pdev);
12103}
12104
12105static struct pci_driver advansys_pci_driver = {
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060012106 .name = DRV_NAME,
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012107 .id_table = advansys_pci_tbl,
12108 .probe = advansys_pci_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012109 .remove = advansys_pci_remove,
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012110};
Matthew Wilcox8c6af9e2007-07-26 11:03:19 -040012111
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060012112static int __init advansys_init(void)
12113{
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060012114 int error;
12115
12116 error = isa_register_driver(&advansys_isa_driver,
12117 ASC_IOADR_TABLE_MAX_IX);
12118 if (error)
12119 goto fail;
12120
12121 error = isa_register_driver(&advansys_vlb_driver,
12122 ASC_IOADR_TABLE_MAX_IX);
12123 if (error)
12124 goto unregister_isa;
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060012125
12126 error = eisa_driver_register(&advansys_eisa_driver);
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012127 if (error)
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060012128 goto unregister_vlb;
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060012129
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060012130 error = pci_register_driver(&advansys_pci_driver);
12131 if (error)
12132 goto unregister_eisa;
12133
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060012134 return 0;
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012135
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060012136 unregister_eisa:
12137 eisa_driver_unregister(&advansys_eisa_driver);
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060012138 unregister_vlb:
12139 isa_unregister_driver(&advansys_vlb_driver);
12140 unregister_isa:
12141 isa_unregister_driver(&advansys_isa_driver);
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012142 fail:
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012143 return error;
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060012144}
12145
12146static void __exit advansys_exit(void)
12147{
Matthew Wilcox78e77d82007-07-29 21:46:15 -060012148 pci_unregister_driver(&advansys_pci_driver);
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060012149 eisa_driver_unregister(&advansys_eisa_driver);
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060012150 isa_unregister_driver(&advansys_vlb_driver);
12151 isa_unregister_driver(&advansys_isa_driver);
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060012152}
12153
12154module_init(advansys_init);
12155module_exit(advansys_exit);
12156
Matthew Wilcox8c6af9e2007-07-26 11:03:19 -040012157MODULE_LICENSE("GPL");
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +053012158MODULE_FIRMWARE("advansys/mcode.bin");
12159MODULE_FIRMWARE("advansys/3550.bin");
12160MODULE_FIRMWARE("advansys/38C0800.bin");
12161MODULE_FIRMWARE("advansys/38C1600.bin");