blob: 05c5eb0f8905b94ee9c1f26e3cfdfc7cc478d880 [file] [log] [blame]
Matthew Wilcox01fbfe02007-09-09 08:56:40 -06001#define DRV_NAME "advansys"
Matthew Wilcox8c6af9e2007-07-26 11:03:19 -04002#define ASC_VERSION "3.4" /* AdvanSys Driver Version */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003
4/*
5 * advansys.c - Linux Host Driver for AdvanSys SCSI Adapters
6 *
7 * Copyright (c) 1995-2000 Advanced System Products, Inc.
8 * Copyright (c) 2000-2001 ConnectCom Solutions, Inc.
Matthew Wilcox8c6af9e2007-07-26 11:03:19 -04009 * Copyright (c) 2007 Matthew Wilcox <matthew@wil.cx>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * All Rights Reserved.
11 *
Matthew Wilcox8c6af9e2007-07-26 11:03:19 -040012 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 */
17
18/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 * As of March 8, 2000 Advanced System Products, Inc. (AdvanSys)
20 * changed its name to ConnectCom Solutions, Inc.
Matthew Wilcox8c6af9e2007-07-26 11:03:19 -040021 * On June 18, 2001 Initio Corp. acquired ConnectCom's SCSI assets
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 */
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/string.h>
26#include <linux/kernel.h>
27#include <linux/types.h>
28#include <linux/ioport.h>
29#include <linux/interrupt.h>
30#include <linux/delay.h>
31#include <linux/slab.h>
32#include <linux/mm.h>
33#include <linux/proc_fs.h>
34#include <linux/init.h>
35#include <linux/blkdev.h>
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060036#include <linux/isa.h>
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060037#include <linux/eisa.h>
Matthew Wilcox8c6af9e2007-07-26 11:03:19 -040038#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/spinlock.h>
40#include <linux/dma-mapping.h>
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +053041#include <linux/firmware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <asm/dma.h>
45
Matthew Wilcox8c6af9e2007-07-26 11:03:19 -040046#include <scsi/scsi_cmnd.h>
47#include <scsi/scsi_device.h>
48#include <scsi/scsi_tcq.h>
49#include <scsi/scsi.h>
50#include <scsi/scsi_host.h>
51
Matthew Wilcox4bd6d7f2007-07-30 08:41:03 -060052/* FIXME:
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 *
Matthew Wilcox4bd6d7f2007-07-30 08:41:03 -060054 * 1. Although all of the necessary command mapping places have the
55 * appropriate dma_map.. APIs, the driver still processes its internal
56 * queue using bus_to_virt() and virt_to_bus() which are illegal under
57 * the API. The entire queue processing structure will need to be
58 * altered to fix this.
59 * 2. Need to add memory mapping workaround. Test the memory mapping.
60 * If it doesn't work revert to I/O port access. Can a test be done
61 * safely?
62 * 3. Handle an interrupt not working. Keep an interrupt counter in
63 * the interrupt handler. In the timeout function if the interrupt
64 * has not occurred then print a message and run in polled mode.
65 * 4. Need to add support for target mode commands, cf. CAM XPT.
66 * 5. check DMA mapping functions for failure
Matthew Wilcox349d2c42007-09-09 08:56:34 -060067 * 6. Use scsi_transport_spi
68 * 7. advansys_info is not safe against multiple simultaneous callers
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040069 * 8. Add module_param to override ISA/VLB ioport array
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 */
71#warning this driver is still not properly converted to the DMA API
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073/* Enable driver /proc statistics. */
74#define ADVANSYS_STATS
75
76/* Enable driver tracing. */
Matthew Wilcoxb352f922007-10-02 21:55:33 -040077#undef ADVANSYS_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Linus Torvalds1da177e2005-04-16 15:20:36 -070079typedef unsigned char uchar;
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081#define isodd_word(val) ((((uint)val) & (uint)0x0001) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Dave Jones2672ea82006-08-02 17:11:49 -040083#define PCI_VENDOR_ID_ASP 0x10cd
84#define PCI_DEVICE_ID_ASP_1200A 0x1100
85#define PCI_DEVICE_ID_ASP_ABP940 0x1200
86#define PCI_DEVICE_ID_ASP_ABP940U 0x1300
87#define PCI_DEVICE_ID_ASP_ABP940UW 0x2300
88#define PCI_DEVICE_ID_38C0800_REV1 0x2500
89#define PCI_DEVICE_ID_38C1600_REV1 0x2700
90
Matthew Wilcox9d511a42007-10-02 21:55:42 -040091#define PortAddr unsigned int /* port address size */
Linus Torvalds1da177e2005-04-16 15:20:36 -070092#define inp(port) inb(port)
93#define outp(port, byte) outb((byte), (port))
94
95#define inpw(port) inw(port)
96#define outpw(port, word) outw((word), (port))
97
98#define ASC_MAX_SG_QUEUE 7
99#define ASC_MAX_SG_LIST 255
100
101#define ASC_CS_TYPE unsigned short
102
103#define ASC_IS_ISA (0x0001)
104#define ASC_IS_ISAPNP (0x0081)
105#define ASC_IS_EISA (0x0002)
106#define ASC_IS_PCI (0x0004)
107#define ASC_IS_PCI_ULTRA (0x0104)
108#define ASC_IS_PCMCIA (0x0008)
109#define ASC_IS_MCA (0x0020)
110#define ASC_IS_VL (0x0040)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#define ASC_IS_WIDESCSI_16 (0x0100)
112#define ASC_IS_WIDESCSI_32 (0x0200)
113#define ASC_IS_BIG_ENDIAN (0x8000)
Matthew Wilcox95c9f162007-09-09 08:56:39 -0600114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115#define ASC_CHIP_MIN_VER_VL (0x01)
116#define ASC_CHIP_MAX_VER_VL (0x07)
117#define ASC_CHIP_MIN_VER_PCI (0x09)
118#define ASC_CHIP_MAX_VER_PCI (0x0F)
119#define ASC_CHIP_VER_PCI_BIT (0x08)
120#define ASC_CHIP_MIN_VER_ISA (0x11)
121#define ASC_CHIP_MIN_VER_ISA_PNP (0x21)
122#define ASC_CHIP_MAX_VER_ISA (0x27)
123#define ASC_CHIP_VER_ISA_BIT (0x30)
124#define ASC_CHIP_VER_ISAPNP_BIT (0x20)
125#define ASC_CHIP_VER_ASYN_BUG (0x21)
126#define ASC_CHIP_VER_PCI 0x08
127#define ASC_CHIP_VER_PCI_ULTRA_3150 (ASC_CHIP_VER_PCI | 0x02)
128#define ASC_CHIP_VER_PCI_ULTRA_3050 (ASC_CHIP_VER_PCI | 0x03)
129#define ASC_CHIP_MIN_VER_EISA (0x41)
130#define ASC_CHIP_MAX_VER_EISA (0x47)
131#define ASC_CHIP_VER_EISA_BIT (0x40)
132#define ASC_CHIP_LATEST_VER_EISA ((ASC_CHIP_MIN_VER_EISA - 1) + 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#define ASC_MAX_VL_DMA_COUNT (0x07FFFFFFL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#define ASC_MAX_PCI_DMA_COUNT (0xFFFFFFFFL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135#define ASC_MAX_ISA_DMA_COUNT (0x00FFFFFFL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137#define ASC_SCSI_ID_BITS 3
138#define ASC_SCSI_TIX_TYPE uchar
139#define ASC_ALL_DEVICE_BIT_SET 0xFF
140#define ASC_SCSI_BIT_ID_TYPE uchar
141#define ASC_MAX_TID 7
142#define ASC_MAX_LUN 7
143#define ASC_SCSI_WIDTH_BIT_SET 0xFF
144#define ASC_MAX_SENSE_LEN 32
145#define ASC_MIN_SENSE_LEN 14
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146#define ASC_SCSI_RESET_HOLD_TIME_US 60
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148/*
Matthew Wilcoxf05ec592007-09-09 08:56:36 -0600149 * Narrow boards only support 12-byte commands, while wide boards
150 * extend to 16-byte commands.
151 */
152#define ASC_MAX_CDB_LEN 12
153#define ADV_MAX_CDB_LEN 16
154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155#define MS_SDTR_LEN 0x03
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156#define MS_WDTR_LEN 0x02
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
158#define ASC_SG_LIST_PER_Q 7
159#define QS_FREE 0x00
160#define QS_READY 0x01
161#define QS_DISC1 0x02
162#define QS_DISC2 0x04
163#define QS_BUSY 0x08
164#define QS_ABORTED 0x40
165#define QS_DONE 0x80
166#define QC_NO_CALLBACK 0x01
167#define QC_SG_SWAP_QUEUE 0x02
168#define QC_SG_HEAD 0x04
169#define QC_DATA_IN 0x08
170#define QC_DATA_OUT 0x10
171#define QC_URGENT 0x20
172#define QC_MSG_OUT 0x40
173#define QC_REQ_SENSE 0x80
174#define QCSG_SG_XFER_LIST 0x02
175#define QCSG_SG_XFER_MORE 0x04
176#define QCSG_SG_XFER_END 0x08
177#define QD_IN_PROGRESS 0x00
178#define QD_NO_ERROR 0x01
179#define QD_ABORTED_BY_HOST 0x02
180#define QD_WITH_ERROR 0x04
181#define QD_INVALID_REQUEST 0x80
182#define QD_INVALID_HOST_NUM 0x81
183#define QD_INVALID_DEVICE 0x82
184#define QD_ERR_INTERNAL 0xFF
185#define QHSTA_NO_ERROR 0x00
186#define QHSTA_M_SEL_TIMEOUT 0x11
187#define QHSTA_M_DATA_OVER_RUN 0x12
188#define QHSTA_M_DATA_UNDER_RUN 0x12
189#define QHSTA_M_UNEXPECTED_BUS_FREE 0x13
190#define QHSTA_M_BAD_BUS_PHASE_SEQ 0x14
191#define QHSTA_D_QDONE_SG_LIST_CORRUPTED 0x21
192#define QHSTA_D_ASC_DVC_ERROR_CODE_SET 0x22
193#define QHSTA_D_HOST_ABORT_FAILED 0x23
194#define QHSTA_D_EXE_SCSI_Q_FAILED 0x24
195#define QHSTA_D_EXE_SCSI_Q_BUSY_TIMEOUT 0x25
196#define QHSTA_D_ASPI_NO_BUF_POOL 0x26
197#define QHSTA_M_WTM_TIMEOUT 0x41
198#define QHSTA_M_BAD_CMPL_STATUS_IN 0x42
199#define QHSTA_M_NO_AUTO_REQ_SENSE 0x43
200#define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
201#define QHSTA_M_TARGET_STATUS_BUSY 0x45
202#define QHSTA_M_BAD_TAG_CODE 0x46
203#define QHSTA_M_BAD_QUEUE_FULL_OR_BUSY 0x47
204#define QHSTA_M_HUNG_REQ_SCSI_BUS_RESET 0x48
205#define QHSTA_D_LRAM_CMP_ERROR 0x81
206#define QHSTA_M_MICRO_CODE_ERROR_HALT 0xA1
207#define ASC_FLAG_SCSIQ_REQ 0x01
208#define ASC_FLAG_BIOS_SCSIQ_REQ 0x02
209#define ASC_FLAG_BIOS_ASYNC_IO 0x04
210#define ASC_FLAG_SRB_LINEAR_ADDR 0x08
211#define ASC_FLAG_WIN16 0x10
212#define ASC_FLAG_WIN32 0x20
213#define ASC_FLAG_ISA_OVER_16MB 0x40
214#define ASC_FLAG_DOS_VM_CALLBACK 0x80
215#define ASC_TAG_FLAG_EXTRA_BYTES 0x10
216#define ASC_TAG_FLAG_DISABLE_DISCONNECT 0x04
217#define ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX 0x08
218#define ASC_TAG_FLAG_DISABLE_CHK_COND_INT_HOST 0x40
219#define ASC_SCSIQ_CPY_BEG 4
220#define ASC_SCSIQ_SGHD_CPY_BEG 2
221#define ASC_SCSIQ_B_FWD 0
222#define ASC_SCSIQ_B_BWD 1
223#define ASC_SCSIQ_B_STATUS 2
224#define ASC_SCSIQ_B_QNO 3
225#define ASC_SCSIQ_B_CNTL 4
226#define ASC_SCSIQ_B_SG_QUEUE_CNT 5
227#define ASC_SCSIQ_D_DATA_ADDR 8
228#define ASC_SCSIQ_D_DATA_CNT 12
229#define ASC_SCSIQ_B_SENSE_LEN 20
230#define ASC_SCSIQ_DONE_INFO_BEG 22
231#define ASC_SCSIQ_D_SRBPTR 22
232#define ASC_SCSIQ_B_TARGET_IX 26
233#define ASC_SCSIQ_B_CDB_LEN 28
234#define ASC_SCSIQ_B_TAG_CODE 29
235#define ASC_SCSIQ_W_VM_ID 30
236#define ASC_SCSIQ_DONE_STATUS 32
237#define ASC_SCSIQ_HOST_STATUS 33
238#define ASC_SCSIQ_SCSI_STATUS 34
239#define ASC_SCSIQ_CDB_BEG 36
240#define ASC_SCSIQ_DW_REMAIN_XFER_ADDR 56
241#define ASC_SCSIQ_DW_REMAIN_XFER_CNT 60
242#define ASC_SCSIQ_B_FIRST_SG_WK_QP 48
243#define ASC_SCSIQ_B_SG_WK_QP 49
244#define ASC_SCSIQ_B_SG_WK_IX 50
245#define ASC_SCSIQ_W_ALT_DC1 52
246#define ASC_SCSIQ_B_LIST_CNT 6
247#define ASC_SCSIQ_B_CUR_LIST_CNT 7
248#define ASC_SGQ_B_SG_CNTL 4
249#define ASC_SGQ_B_SG_HEAD_QP 5
250#define ASC_SGQ_B_SG_LIST_CNT 6
251#define ASC_SGQ_B_SG_CUR_LIST_CNT 7
252#define ASC_SGQ_LIST_BEG 8
253#define ASC_DEF_SCSI1_QNG 4
254#define ASC_MAX_SCSI1_QNG 4
255#define ASC_DEF_SCSI2_QNG 16
256#define ASC_MAX_SCSI2_QNG 32
257#define ASC_TAG_CODE_MASK 0x23
258#define ASC_STOP_REQ_RISC_STOP 0x01
259#define ASC_STOP_ACK_RISC_STOP 0x03
260#define ASC_STOP_CLEAN_UP_BUSY_Q 0x10
261#define ASC_STOP_CLEAN_UP_DISC_Q 0x20
262#define ASC_STOP_HOST_REQ_RISC_HALT 0x40
263#define ASC_TIDLUN_TO_IX(tid, lun) (ASC_SCSI_TIX_TYPE)((tid) + ((lun)<<ASC_SCSI_ID_BITS))
264#define ASC_TID_TO_TARGET_ID(tid) (ASC_SCSI_BIT_ID_TYPE)(0x01 << (tid))
265#define ASC_TIX_TO_TARGET_ID(tix) (0x01 << ((tix) & ASC_MAX_TID))
266#define ASC_TIX_TO_TID(tix) ((tix) & ASC_MAX_TID)
267#define ASC_TID_TO_TIX(tid) ((tid) & ASC_MAX_TID)
268#define ASC_TIX_TO_LUN(tix) (((tix) >> ASC_SCSI_ID_BITS) & ASC_MAX_LUN)
269#define ASC_QNO_TO_QADDR(q_no) ((ASC_QADR_BEG)+((int)(q_no) << 6))
270
271typedef struct asc_scsiq_1 {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400272 uchar status;
273 uchar q_no;
274 uchar cntl;
275 uchar sg_queue_cnt;
276 uchar target_id;
277 uchar target_lun;
Hannes Reinecke95cfab62015-04-24 13:18:27 +0200278 __le32 data_addr;
279 __le32 data_cnt;
280 __le32 sense_addr;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400281 uchar sense_len;
282 uchar extra_bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283} ASC_SCSIQ_1;
284
285typedef struct asc_scsiq_2 {
Hannes Reinecke9c17c622015-04-24 13:18:21 +0200286 u32 srb_tag;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400287 uchar target_ix;
288 uchar flag;
289 uchar cdb_len;
290 uchar tag_code;
291 ushort vm_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292} ASC_SCSIQ_2;
293
294typedef struct asc_scsiq_3 {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400295 uchar done_stat;
296 uchar host_stat;
297 uchar scsi_stat;
298 uchar scsi_msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299} ASC_SCSIQ_3;
300
301typedef struct asc_scsiq_4 {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400302 uchar cdb[ASC_MAX_CDB_LEN];
303 uchar y_first_sg_list_qp;
304 uchar y_working_sg_qp;
305 uchar y_working_sg_ix;
306 uchar y_res;
307 ushort x_req_count;
308 ushort x_reconnect_rtn;
Hannes Reinecke95cfab62015-04-24 13:18:27 +0200309 __le32 x_saved_data_addr;
310 __le32 x_saved_data_cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311} ASC_SCSIQ_4;
312
313typedef struct asc_q_done_info {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400314 ASC_SCSIQ_2 d2;
315 ASC_SCSIQ_3 d3;
316 uchar q_status;
317 uchar q_no;
318 uchar cntl;
319 uchar sense_len;
320 uchar extra_bytes;
321 uchar res;
Hannes Reinecke95cfab62015-04-24 13:18:27 +0200322 u32 remain_bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323} ASC_QDONE_INFO;
324
325typedef struct asc_sg_list {
Hannes Reinecke95cfab62015-04-24 13:18:27 +0200326 __le32 addr;
327 __le32 bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328} ASC_SG_LIST;
329
330typedef struct asc_sg_head {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400331 ushort entry_cnt;
332 ushort queue_cnt;
333 ushort entry_to_copy;
334 ushort res;
Matthew Wilcox05848b62007-10-02 21:55:25 -0400335 ASC_SG_LIST sg_list[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336} ASC_SG_HEAD;
337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338typedef struct asc_scsi_q {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400339 ASC_SCSIQ_1 q1;
340 ASC_SCSIQ_2 q2;
341 uchar *cdbptr;
342 ASC_SG_HEAD *sg_head;
343 ushort remain_sg_entry_cnt;
344 ushort next_sg_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345} ASC_SCSI_Q;
346
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347typedef struct asc_scsi_bios_req_q {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400348 ASC_SCSIQ_1 r1;
349 ASC_SCSIQ_2 r2;
350 uchar *cdbptr;
351 ASC_SG_HEAD *sg_head;
352 uchar *sense_ptr;
353 ASC_SCSIQ_3 r3;
354 uchar cdb[ASC_MAX_CDB_LEN];
355 uchar sense[ASC_MIN_SENSE_LEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356} ASC_SCSI_BIOS_REQ_Q;
357
358typedef struct asc_risc_q {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400359 uchar fwd;
360 uchar bwd;
361 ASC_SCSIQ_1 i1;
362 ASC_SCSIQ_2 i2;
363 ASC_SCSIQ_3 i3;
364 ASC_SCSIQ_4 i4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365} ASC_RISC_Q;
366
367typedef struct asc_sg_list_q {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400368 uchar seq_no;
369 uchar q_no;
370 uchar cntl;
371 uchar sg_head_qp;
372 uchar sg_list_cnt;
373 uchar sg_cur_list_cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374} ASC_SG_LIST_Q;
375
376typedef struct asc_risc_sg_list_q {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400377 uchar fwd;
378 uchar bwd;
379 ASC_SG_LIST_Q sg;
380 ASC_SG_LIST sg_list[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381} ASC_RISC_SG_LIST_Q;
382
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383#define ASCQ_ERR_Q_STATUS 0x0D
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384#define ASCQ_ERR_CUR_QNG 0x17
385#define ASCQ_ERR_SG_Q_LINKS 0x18
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386#define ASCQ_ERR_ISR_RE_ENTRY 0x1A
387#define ASCQ_ERR_CRITICAL_RE_ENTRY 0x1B
388#define ASCQ_ERR_ISR_ON_CRITICAL 0x1C
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
390/*
391 * Warning code values are set in ASC_DVC_VAR 'warn_code'.
392 */
393#define ASC_WARN_NO_ERROR 0x0000
394#define ASC_WARN_IO_PORT_ROTATE 0x0001
395#define ASC_WARN_EEPROM_CHKSUM 0x0002
396#define ASC_WARN_IRQ_MODIFIED 0x0004
397#define ASC_WARN_AUTO_CONFIG 0x0008
398#define ASC_WARN_CMD_QNG_CONFLICT 0x0010
399#define ASC_WARN_EEPROM_RECOVER 0x0020
400#define ASC_WARN_CFG_MSW_RECOVER 0x0040
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
402/*
Matthew Wilcox720349a2007-10-02 21:55:30 -0400403 * Error code values are set in {ASC/ADV}_DVC_VAR 'err_code'.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 */
Matthew Wilcox720349a2007-10-02 21:55:30 -0400405#define ASC_IERR_NO_CARRIER 0x0001 /* No more carrier memory */
406#define ASC_IERR_MCODE_CHKSUM 0x0002 /* micro code check sum error */
407#define ASC_IERR_SET_PC_ADDR 0x0004
408#define ASC_IERR_START_STOP_CHIP 0x0008 /* start/stop chip failed */
409#define ASC_IERR_ILLEGAL_CONNECTION 0x0010 /* Illegal cable connection */
410#define ASC_IERR_SINGLE_END_DEVICE 0x0020 /* SE device on DIFF bus */
411#define ASC_IERR_REVERSED_CABLE 0x0040 /* Narrow flat cable reversed */
412#define ASC_IERR_SET_SCSI_ID 0x0080 /* set SCSI ID failed */
413#define ASC_IERR_HVD_DEVICE 0x0100 /* HVD device on LVD port */
414#define ASC_IERR_BAD_SIGNATURE 0x0200 /* signature not found */
415#define ASC_IERR_NO_BUS_TYPE 0x0400
416#define ASC_IERR_BIST_PRE_TEST 0x0800 /* BIST pre-test error */
417#define ASC_IERR_BIST_RAM_TEST 0x1000 /* BIST RAM test error */
418#define ASC_IERR_BAD_CHIPTYPE 0x2000 /* Invalid chip_type setting */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420#define ASC_DEF_MAX_TOTAL_QNG (0xF0)
421#define ASC_MIN_TAG_Q_PER_DVC (0x04)
Matthew Wilcox95c9f162007-09-09 08:56:39 -0600422#define ASC_MIN_FREE_Q (0x02)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423#define ASC_MIN_TOTAL_QNG ((ASC_MAX_SG_QUEUE)+(ASC_MIN_FREE_Q))
424#define ASC_MAX_TOTAL_QNG 240
425#define ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG 16
426#define ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG 8
427#define ASC_MAX_PCI_INRAM_TOTAL_QNG 20
428#define ASC_MAX_INRAM_TAG_QNG 16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429#define ASC_IOADR_GAP 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430#define ASC_SYN_MAX_OFFSET 0x0F
431#define ASC_DEF_SDTR_OFFSET 0x0F
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432#define ASC_SDTR_ULTRA_PCI_10MB_INDEX 0x02
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -0400433#define ASYN_SDTR_DATA_FIX_PCI_REV_AB 0x41
434
435/* The narrow chip only supports a limited selection of transfer rates.
436 * These are encoded in the range 0..7 or 0..15 depending whether the chip
437 * is Ultra-capable or not. These tables let us convert from one to the other.
438 */
439static const unsigned char asc_syn_xfer_period[8] = {
440 25, 30, 35, 40, 50, 60, 70, 85
441};
442
443static const unsigned char asc_syn_ultra_xfer_period[16] = {
444 12, 19, 25, 32, 38, 44, 50, 57, 63, 69, 75, 82, 88, 94, 100, 107
445};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447typedef struct ext_msg {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400448 uchar msg_type;
449 uchar msg_len;
450 uchar msg_req;
451 union {
452 struct {
453 uchar sdtr_xfer_period;
454 uchar sdtr_req_ack_offset;
455 } sdtr;
456 struct {
457 uchar wdtr_width;
458 } wdtr;
459 struct {
460 uchar mdp_b3;
461 uchar mdp_b2;
462 uchar mdp_b1;
463 uchar mdp_b0;
464 } mdp;
465 } u_ext_msg;
466 uchar res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467} EXT_MSG;
468
469#define xfer_period u_ext_msg.sdtr.sdtr_xfer_period
470#define req_ack_offset u_ext_msg.sdtr.sdtr_req_ack_offset
471#define wdtr_width u_ext_msg.wdtr.wdtr_width
472#define mdp_b3 u_ext_msg.mdp_b3
473#define mdp_b2 u_ext_msg.mdp_b2
474#define mdp_b1 u_ext_msg.mdp_b1
475#define mdp_b0 u_ext_msg.mdp_b0
476
477typedef struct asc_dvc_cfg {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400478 ASC_SCSI_BIT_ID_TYPE can_tagged_qng;
479 ASC_SCSI_BIT_ID_TYPE cmd_qng_enabled;
480 ASC_SCSI_BIT_ID_TYPE disc_enable;
481 ASC_SCSI_BIT_ID_TYPE sdtr_enable;
482 uchar chip_scsi_id;
483 uchar isa_dma_speed;
484 uchar isa_dma_channel;
485 uchar chip_version;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400486 ushort mcode_date;
487 ushort mcode_version;
488 uchar max_tag_qng[ASC_MAX_TID + 1];
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400489 uchar sdtr_period_offset[ASC_MAX_TID + 1];
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400490 uchar adapter_info[6];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491} ASC_DVC_CFG;
492
493#define ASC_DEF_DVC_CNTL 0xFFFF
494#define ASC_DEF_CHIP_SCSI_ID 7
495#define ASC_DEF_ISA_DMA_SPEED 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496#define ASC_INIT_STATE_BEG_GET_CFG 0x0001
497#define ASC_INIT_STATE_END_GET_CFG 0x0002
498#define ASC_INIT_STATE_BEG_SET_CFG 0x0004
499#define ASC_INIT_STATE_END_SET_CFG 0x0008
500#define ASC_INIT_STATE_BEG_LOAD_MC 0x0010
501#define ASC_INIT_STATE_END_LOAD_MC 0x0020
502#define ASC_INIT_STATE_BEG_INQUIRY 0x0040
503#define ASC_INIT_STATE_END_INQUIRY 0x0080
504#define ASC_INIT_RESET_SCSI_DONE 0x0100
505#define ASC_INIT_STATE_WITHOUT_EEP 0x8000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506#define ASC_BUG_FIX_IF_NOT_DWB 0x0001
507#define ASC_BUG_FIX_ASYN_USE_SYN 0x0002
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508#define ASC_MIN_TAGGED_CMD 7
509#define ASC_MAX_SCSI_RESET_WAIT 30
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -0400510#define ASC_OVERRUN_BSIZE 64
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400512struct asc_dvc_var; /* Forward Declaration. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514typedef struct asc_dvc_var {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400515 PortAddr iop_base;
516 ushort err_code;
517 ushort dvc_cntl;
518 ushort bug_fix_cntl;
519 ushort bus_type;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400520 ASC_SCSI_BIT_ID_TYPE init_sdtr;
521 ASC_SCSI_BIT_ID_TYPE sdtr_done;
522 ASC_SCSI_BIT_ID_TYPE use_tagged_qng;
523 ASC_SCSI_BIT_ID_TYPE unit_not_ready;
524 ASC_SCSI_BIT_ID_TYPE queue_full_or_busy;
525 ASC_SCSI_BIT_ID_TYPE start_motor;
FUJITA Tomonori7d5d4082008-02-08 09:50:08 +0900526 uchar *overrun_buf;
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -0400527 dma_addr_t overrun_dma;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400528 uchar scsi_reset_wait;
529 uchar chip_no;
Hannes Reineckeae267592015-04-24 13:18:28 +0200530 bool is_in_int;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400531 uchar max_total_qng;
532 uchar cur_total_qng;
533 uchar in_critical_cnt;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400534 uchar last_q_shortage;
535 ushort init_state;
536 uchar cur_dvc_qng[ASC_MAX_TID + 1];
537 uchar max_dvc_qng[ASC_MAX_TID + 1];
538 ASC_SCSI_Q *scsiq_busy_head[ASC_MAX_TID + 1];
539 ASC_SCSI_Q *scsiq_busy_tail[ASC_MAX_TID + 1];
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -0400540 const uchar *sdtr_period_tbl;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400541 ASC_DVC_CFG *cfg;
542 ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer_always;
543 char redo_scam;
544 ushort res2;
545 uchar dos_int13_table[ASC_MAX_TID + 1];
Hannes Reinecke95cfab62015-04-24 13:18:27 +0200546 unsigned int max_dma_count;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400547 ASC_SCSI_BIT_ID_TYPE no_scam;
548 ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer;
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -0400549 uchar min_sdtr_index;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400550 uchar max_sdtr_index;
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400551 struct asc_board *drv_ptr;
Hannes Reinecke95cfab62015-04-24 13:18:27 +0200552 unsigned int uc_break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553} ASC_DVC_VAR;
554
555typedef struct asc_dvc_inq_info {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400556 uchar type[ASC_MAX_TID + 1][ASC_MAX_LUN + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557} ASC_DVC_INQ_INFO;
558
559typedef struct asc_cap_info {
Hannes Reinecke95cfab62015-04-24 13:18:27 +0200560 u32 lba;
561 u32 blk_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562} ASC_CAP_INFO;
563
564typedef struct asc_cap_info_array {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400565 ASC_CAP_INFO cap_info[ASC_MAX_TID + 1][ASC_MAX_LUN + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566} ASC_CAP_INFO_ARRAY;
567
568#define ASC_MCNTL_NO_SEL_TIMEOUT (ushort)0x0001
569#define ASC_MCNTL_NULL_TARGET (ushort)0x0002
570#define ASC_CNTL_INITIATOR (ushort)0x0001
571#define ASC_CNTL_BIOS_GT_1GB (ushort)0x0002
572#define ASC_CNTL_BIOS_GT_2_DISK (ushort)0x0004
573#define ASC_CNTL_BIOS_REMOVABLE (ushort)0x0008
574#define ASC_CNTL_NO_SCAM (ushort)0x0010
575#define ASC_CNTL_INT_MULTI_Q (ushort)0x0080
576#define ASC_CNTL_NO_LUN_SUPPORT (ushort)0x0040
577#define ASC_CNTL_NO_VERIFY_COPY (ushort)0x0100
578#define ASC_CNTL_RESET_SCSI (ushort)0x0200
579#define ASC_CNTL_INIT_INQUIRY (ushort)0x0400
580#define ASC_CNTL_INIT_VERBOSE (ushort)0x0800
581#define ASC_CNTL_SCSI_PARITY (ushort)0x1000
582#define ASC_CNTL_BURST_MODE (ushort)0x2000
583#define ASC_CNTL_SDTR_ENABLE_ULTRA (ushort)0x4000
584#define ASC_EEP_DVC_CFG_BEG_VL 2
585#define ASC_EEP_MAX_DVC_ADDR_VL 15
586#define ASC_EEP_DVC_CFG_BEG 32
587#define ASC_EEP_MAX_DVC_ADDR 45
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588#define ASC_EEP_MAX_RETRY 20
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
590/*
591 * These macros keep the chip SCSI id and ISA DMA speed
592 * bitfields in board order. C bitfields aren't portable
593 * between big and little-endian platforms so they are
594 * not used.
595 */
596
597#define ASC_EEP_GET_CHIP_ID(cfg) ((cfg)->id_speed & 0x0f)
598#define ASC_EEP_GET_DMA_SPD(cfg) (((cfg)->id_speed & 0xf0) >> 4)
599#define ASC_EEP_SET_CHIP_ID(cfg, sid) \
600 ((cfg)->id_speed = ((cfg)->id_speed & 0xf0) | ((sid) & ASC_MAX_TID))
601#define ASC_EEP_SET_DMA_SPD(cfg, spd) \
602 ((cfg)->id_speed = ((cfg)->id_speed & 0x0f) | ((spd) & 0x0f) << 4)
603
604typedef struct asceep_config {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400605 ushort cfg_lsw;
606 ushort cfg_msw;
607 uchar init_sdtr;
608 uchar disc_enable;
609 uchar use_cmd_qng;
610 uchar start_motor;
611 uchar max_total_qng;
612 uchar max_tag_qng;
613 uchar bios_scan;
614 uchar power_up_wait;
615 uchar no_scam;
616 uchar id_speed; /* low order 4 bits is chip scsi id */
617 /* high order 4 bits is isa dma speed */
618 uchar dos_int13_table[ASC_MAX_TID + 1];
619 uchar adapter_info[6];
620 ushort cntl;
621 ushort chksum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622} ASCEEP_CONFIG;
623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624#define ASC_EEP_CMD_READ 0x80
625#define ASC_EEP_CMD_WRITE 0x40
626#define ASC_EEP_CMD_WRITE_ABLE 0x30
627#define ASC_EEP_CMD_WRITE_DISABLE 0x00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628#define ASCV_MSGOUT_BEG 0x0000
629#define ASCV_MSGOUT_SDTR_PERIOD (ASCV_MSGOUT_BEG+3)
630#define ASCV_MSGOUT_SDTR_OFFSET (ASCV_MSGOUT_BEG+4)
631#define ASCV_BREAK_SAVED_CODE (ushort)0x0006
632#define ASCV_MSGIN_BEG (ASCV_MSGOUT_BEG+8)
633#define ASCV_MSGIN_SDTR_PERIOD (ASCV_MSGIN_BEG+3)
634#define ASCV_MSGIN_SDTR_OFFSET (ASCV_MSGIN_BEG+4)
635#define ASCV_SDTR_DATA_BEG (ASCV_MSGIN_BEG+8)
636#define ASCV_SDTR_DONE_BEG (ASCV_SDTR_DATA_BEG+8)
637#define ASCV_MAX_DVC_QNG_BEG (ushort)0x0020
638#define ASCV_BREAK_ADDR (ushort)0x0028
639#define ASCV_BREAK_NOTIFY_COUNT (ushort)0x002A
640#define ASCV_BREAK_CONTROL (ushort)0x002C
641#define ASCV_BREAK_HIT_COUNT (ushort)0x002E
642
643#define ASCV_ASCDVC_ERR_CODE_W (ushort)0x0030
644#define ASCV_MCODE_CHKSUM_W (ushort)0x0032
645#define ASCV_MCODE_SIZE_W (ushort)0x0034
646#define ASCV_STOP_CODE_B (ushort)0x0036
647#define ASCV_DVC_ERR_CODE_B (ushort)0x0037
648#define ASCV_OVERRUN_PADDR_D (ushort)0x0038
649#define ASCV_OVERRUN_BSIZE_D (ushort)0x003C
650#define ASCV_HALTCODE_W (ushort)0x0040
651#define ASCV_CHKSUM_W (ushort)0x0042
652#define ASCV_MC_DATE_W (ushort)0x0044
653#define ASCV_MC_VER_W (ushort)0x0046
654#define ASCV_NEXTRDY_B (ushort)0x0048
655#define ASCV_DONENEXT_B (ushort)0x0049
656#define ASCV_USE_TAGGED_QNG_B (ushort)0x004A
657#define ASCV_SCSIBUSY_B (ushort)0x004B
658#define ASCV_Q_DONE_IN_PROGRESS_B (ushort)0x004C
659#define ASCV_CURCDB_B (ushort)0x004D
660#define ASCV_RCLUN_B (ushort)0x004E
661#define ASCV_BUSY_QHEAD_B (ushort)0x004F
662#define ASCV_DISC1_QHEAD_B (ushort)0x0050
663#define ASCV_DISC_ENABLE_B (ushort)0x0052
664#define ASCV_CAN_TAGGED_QNG_B (ushort)0x0053
665#define ASCV_HOSTSCSI_ID_B (ushort)0x0055
666#define ASCV_MCODE_CNTL_B (ushort)0x0056
667#define ASCV_NULL_TARGET_B (ushort)0x0057
668#define ASCV_FREE_Q_HEAD_W (ushort)0x0058
669#define ASCV_DONE_Q_TAIL_W (ushort)0x005A
670#define ASCV_FREE_Q_HEAD_B (ushort)(ASCV_FREE_Q_HEAD_W+1)
671#define ASCV_DONE_Q_TAIL_B (ushort)(ASCV_DONE_Q_TAIL_W+1)
672#define ASCV_HOST_FLAG_B (ushort)0x005D
673#define ASCV_TOTAL_READY_Q_B (ushort)0x0064
674#define ASCV_VER_SERIAL_B (ushort)0x0065
675#define ASCV_HALTCODE_SAVED_W (ushort)0x0066
676#define ASCV_WTM_FLAG_B (ushort)0x0068
677#define ASCV_RISC_FLAG_B (ushort)0x006A
678#define ASCV_REQ_SG_LIST_QP (ushort)0x006B
679#define ASC_HOST_FLAG_IN_ISR 0x01
680#define ASC_HOST_FLAG_ACK_INT 0x02
681#define ASC_RISC_FLAG_GEN_INT 0x01
682#define ASC_RISC_FLAG_REQ_SG_LIST 0x02
683#define IOP_CTRL (0x0F)
684#define IOP_STATUS (0x0E)
685#define IOP_INT_ACK IOP_STATUS
686#define IOP_REG_IFC (0x0D)
687#define IOP_SYN_OFFSET (0x0B)
688#define IOP_EXTRA_CONTROL (0x0D)
689#define IOP_REG_PC (0x0C)
690#define IOP_RAM_ADDR (0x0A)
691#define IOP_RAM_DATA (0x08)
692#define IOP_EEP_DATA (0x06)
693#define IOP_EEP_CMD (0x07)
694#define IOP_VERSION (0x03)
695#define IOP_CONFIG_HIGH (0x04)
696#define IOP_CONFIG_LOW (0x02)
697#define IOP_SIG_BYTE (0x01)
698#define IOP_SIG_WORD (0x00)
699#define IOP_REG_DC1 (0x0E)
700#define IOP_REG_DC0 (0x0C)
701#define IOP_REG_SB (0x0B)
702#define IOP_REG_DA1 (0x0A)
703#define IOP_REG_DA0 (0x08)
704#define IOP_REG_SC (0x09)
705#define IOP_DMA_SPEED (0x07)
706#define IOP_REG_FLAG (0x07)
707#define IOP_FIFO_H (0x06)
708#define IOP_FIFO_L (0x04)
709#define IOP_REG_ID (0x05)
710#define IOP_REG_QP (0x03)
711#define IOP_REG_IH (0x02)
712#define IOP_REG_IX (0x01)
713#define IOP_REG_AX (0x00)
714#define IFC_REG_LOCK (0x00)
715#define IFC_REG_UNLOCK (0x09)
716#define IFC_WR_EN_FILTER (0x10)
717#define IFC_RD_NO_EEPROM (0x10)
718#define IFC_SLEW_RATE (0x20)
719#define IFC_ACT_NEG (0x40)
720#define IFC_INP_FILTER (0x80)
721#define IFC_INIT_DEFAULT (IFC_ACT_NEG | IFC_REG_UNLOCK)
722#define SC_SEL (uchar)(0x80)
723#define SC_BSY (uchar)(0x40)
724#define SC_ACK (uchar)(0x20)
725#define SC_REQ (uchar)(0x10)
726#define SC_ATN (uchar)(0x08)
727#define SC_IO (uchar)(0x04)
728#define SC_CD (uchar)(0x02)
729#define SC_MSG (uchar)(0x01)
730#define SEC_SCSI_CTL (uchar)(0x80)
731#define SEC_ACTIVE_NEGATE (uchar)(0x40)
732#define SEC_SLEW_RATE (uchar)(0x20)
733#define SEC_ENABLE_FILTER (uchar)(0x10)
734#define ASC_HALT_EXTMSG_IN (ushort)0x8000
735#define ASC_HALT_CHK_CONDITION (ushort)0x8100
736#define ASC_HALT_SS_QUEUE_FULL (ushort)0x8200
737#define ASC_HALT_DISABLE_ASYN_USE_SYN_FIX (ushort)0x8300
738#define ASC_HALT_ENABLE_ASYN_USE_SYN_FIX (ushort)0x8400
739#define ASC_HALT_SDTR_REJECTED (ushort)0x4000
740#define ASC_HALT_HOST_COPY_SG_LIST_TO_RISC ( ushort )0x2000
741#define ASC_MAX_QNO 0xF8
742#define ASC_DATA_SEC_BEG (ushort)0x0080
743#define ASC_DATA_SEC_END (ushort)0x0080
744#define ASC_CODE_SEC_BEG (ushort)0x0080
745#define ASC_CODE_SEC_END (ushort)0x0080
746#define ASC_QADR_BEG (0x4000)
747#define ASC_QADR_USED (ushort)(ASC_MAX_QNO * 64)
748#define ASC_QADR_END (ushort)0x7FFF
749#define ASC_QLAST_ADR (ushort)0x7FC0
750#define ASC_QBLK_SIZE 0x40
751#define ASC_BIOS_DATA_QBEG 0xF8
752#define ASC_MIN_ACTIVE_QNO 0x01
753#define ASC_QLINK_END 0xFF
754#define ASC_EEPROM_WORDS 0x10
755#define ASC_MAX_MGS_LEN 0x10
756#define ASC_BIOS_ADDR_DEF 0xDC00
757#define ASC_BIOS_SIZE 0x3800
758#define ASC_BIOS_RAM_OFF 0x3800
759#define ASC_BIOS_RAM_SIZE 0x800
760#define ASC_BIOS_MIN_ADDR 0xC000
761#define ASC_BIOS_MAX_ADDR 0xEC00
762#define ASC_BIOS_BANK_SIZE 0x0400
763#define ASC_MCODE_START_ADDR 0x0080
764#define ASC_CFG0_HOST_INT_ON 0x0020
765#define ASC_CFG0_BIOS_ON 0x0040
766#define ASC_CFG0_VERA_BURST_ON 0x0080
767#define ASC_CFG0_SCSI_PARITY_ON 0x0800
768#define ASC_CFG1_SCSI_TARGET_ON 0x0080
769#define ASC_CFG1_LRAM_8BITS_ON 0x0800
770#define ASC_CFG_MSW_CLR_MASK 0x3080
771#define CSW_TEST1 (ASC_CS_TYPE)0x8000
772#define CSW_AUTO_CONFIG (ASC_CS_TYPE)0x4000
773#define CSW_RESERVED1 (ASC_CS_TYPE)0x2000
774#define CSW_IRQ_WRITTEN (ASC_CS_TYPE)0x1000
775#define CSW_33MHZ_SELECTED (ASC_CS_TYPE)0x0800
776#define CSW_TEST2 (ASC_CS_TYPE)0x0400
777#define CSW_TEST3 (ASC_CS_TYPE)0x0200
778#define CSW_RESERVED2 (ASC_CS_TYPE)0x0100
779#define CSW_DMA_DONE (ASC_CS_TYPE)0x0080
780#define CSW_FIFO_RDY (ASC_CS_TYPE)0x0040
781#define CSW_EEP_READ_DONE (ASC_CS_TYPE)0x0020
782#define CSW_HALTED (ASC_CS_TYPE)0x0010
783#define CSW_SCSI_RESET_ACTIVE (ASC_CS_TYPE)0x0008
784#define CSW_PARITY_ERR (ASC_CS_TYPE)0x0004
785#define CSW_SCSI_RESET_LATCH (ASC_CS_TYPE)0x0002
786#define CSW_INT_PENDING (ASC_CS_TYPE)0x0001
787#define CIW_CLR_SCSI_RESET_INT (ASC_CS_TYPE)0x1000
788#define CIW_INT_ACK (ASC_CS_TYPE)0x0100
789#define CIW_TEST1 (ASC_CS_TYPE)0x0200
790#define CIW_TEST2 (ASC_CS_TYPE)0x0400
791#define CIW_SEL_33MHZ (ASC_CS_TYPE)0x0800
792#define CIW_IRQ_ACT (ASC_CS_TYPE)0x1000
793#define CC_CHIP_RESET (uchar)0x80
794#define CC_SCSI_RESET (uchar)0x40
795#define CC_HALT (uchar)0x20
796#define CC_SINGLE_STEP (uchar)0x10
797#define CC_DMA_ABLE (uchar)0x08
798#define CC_TEST (uchar)0x04
799#define CC_BANK_ONE (uchar)0x02
800#define CC_DIAG (uchar)0x01
801#define ASC_1000_ID0W 0x04C1
802#define ASC_1000_ID0W_FIX 0x00C1
803#define ASC_1000_ID1B 0x25
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804#define ASC_EISA_REV_IOP_MASK (0x0C83)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805#define ASC_EISA_CFG_IOP_MASK (0x0C86)
806#define ASC_GET_EISA_SLOT(iop) (PortAddr)((iop) & 0xF000)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807#define INS_HALTINT (ushort)0x6281
808#define INS_HALT (ushort)0x6280
809#define INS_SINT (ushort)0x6200
810#define INS_RFLAG_WTM (ushort)0x7380
811#define ASC_MC_SAVE_CODE_WSIZE 0x500
812#define ASC_MC_SAVE_DATA_WSIZE 0x40
813
814typedef struct asc_mc_saved {
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400815 ushort data[ASC_MC_SAVE_DATA_WSIZE];
816 ushort code[ASC_MC_SAVE_CODE_WSIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817} ASC_MC_SAVED;
818
819#define AscGetQDoneInProgress(port) AscReadLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B)
820#define AscPutQDoneInProgress(port, val) AscWriteLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B, val)
821#define AscGetVarFreeQHead(port) AscReadLramWord((port), ASCV_FREE_Q_HEAD_W)
822#define AscGetVarDoneQTail(port) AscReadLramWord((port), ASCV_DONE_Q_TAIL_W)
823#define AscPutVarFreeQHead(port, val) AscWriteLramWord((port), ASCV_FREE_Q_HEAD_W, val)
824#define AscPutVarDoneQTail(port, val) AscWriteLramWord((port), ASCV_DONE_Q_TAIL_W, val)
825#define AscGetRiscVarFreeQHead(port) AscReadLramByte((port), ASCV_NEXTRDY_B)
826#define AscGetRiscVarDoneQTail(port) AscReadLramByte((port), ASCV_DONENEXT_B)
827#define AscPutRiscVarFreeQHead(port, val) AscWriteLramByte((port), ASCV_NEXTRDY_B, val)
828#define AscPutRiscVarDoneQTail(port, val) AscWriteLramByte((port), ASCV_DONENEXT_B, val)
Matthew Wilcox51219352007-10-02 21:55:22 -0400829#define AscPutMCodeSDTRDoneAtID(port, id, data) AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id), (data))
830#define AscGetMCodeSDTRDoneAtID(port, id) AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id))
831#define AscPutMCodeInitSDTRAtID(port, id, data) AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id), data)
832#define AscGetMCodeInitSDTRAtID(port, id) AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833#define AscGetChipSignatureByte(port) (uchar)inp((port)+IOP_SIG_BYTE)
834#define AscGetChipSignatureWord(port) (ushort)inpw((port)+IOP_SIG_WORD)
835#define AscGetChipVerNo(port) (uchar)inp((port)+IOP_VERSION)
836#define AscGetChipCfgLsw(port) (ushort)inpw((port)+IOP_CONFIG_LOW)
837#define AscGetChipCfgMsw(port) (ushort)inpw((port)+IOP_CONFIG_HIGH)
838#define AscSetChipCfgLsw(port, data) outpw((port)+IOP_CONFIG_LOW, data)
839#define AscSetChipCfgMsw(port, data) outpw((port)+IOP_CONFIG_HIGH, data)
840#define AscGetChipEEPCmd(port) (uchar)inp((port)+IOP_EEP_CMD)
841#define AscSetChipEEPCmd(port, data) outp((port)+IOP_EEP_CMD, data)
842#define AscGetChipEEPData(port) (ushort)inpw((port)+IOP_EEP_DATA)
843#define AscSetChipEEPData(port, data) outpw((port)+IOP_EEP_DATA, data)
844#define AscGetChipLramAddr(port) (ushort)inpw((PortAddr)((port)+IOP_RAM_ADDR))
845#define AscSetChipLramAddr(port, addr) outpw((PortAddr)((port)+IOP_RAM_ADDR), addr)
846#define AscGetChipLramData(port) (ushort)inpw((port)+IOP_RAM_DATA)
847#define AscSetChipLramData(port, data) outpw((port)+IOP_RAM_DATA, data)
848#define AscGetChipIFC(port) (uchar)inp((port)+IOP_REG_IFC)
849#define AscSetChipIFC(port, data) outp((port)+IOP_REG_IFC, data)
850#define AscGetChipStatus(port) (ASC_CS_TYPE)inpw((port)+IOP_STATUS)
851#define AscSetChipStatus(port, cs_val) outpw((port)+IOP_STATUS, cs_val)
852#define AscGetChipControl(port) (uchar)inp((port)+IOP_CTRL)
853#define AscSetChipControl(port, cc_val) outp((port)+IOP_CTRL, cc_val)
854#define AscGetChipSyn(port) (uchar)inp((port)+IOP_SYN_OFFSET)
855#define AscSetChipSyn(port, data) outp((port)+IOP_SYN_OFFSET, data)
856#define AscSetPCAddr(port, data) outpw((port)+IOP_REG_PC, data)
857#define AscGetPCAddr(port) (ushort)inpw((port)+IOP_REG_PC)
858#define AscIsIntPending(port) (AscGetChipStatus(port) & (CSW_INT_PENDING | CSW_SCSI_RESET_LATCH))
859#define AscGetChipScsiID(port) ((AscGetChipCfgLsw(port) >> 8) & ASC_MAX_TID)
860#define AscGetExtraControl(port) (uchar)inp((port)+IOP_EXTRA_CONTROL)
861#define AscSetExtraControl(port, data) outp((port)+IOP_EXTRA_CONTROL, data)
862#define AscReadChipAX(port) (ushort)inpw((port)+IOP_REG_AX)
863#define AscWriteChipAX(port, data) outpw((port)+IOP_REG_AX, data)
864#define AscReadChipIX(port) (uchar)inp((port)+IOP_REG_IX)
865#define AscWriteChipIX(port, data) outp((port)+IOP_REG_IX, data)
866#define AscReadChipIH(port) (ushort)inpw((port)+IOP_REG_IH)
867#define AscWriteChipIH(port, data) outpw((port)+IOP_REG_IH, data)
868#define AscReadChipQP(port) (uchar)inp((port)+IOP_REG_QP)
869#define AscWriteChipQP(port, data) outp((port)+IOP_REG_QP, data)
870#define AscReadChipFIFO_L(port) (ushort)inpw((port)+IOP_REG_FIFO_L)
871#define AscWriteChipFIFO_L(port, data) outpw((port)+IOP_REG_FIFO_L, data)
872#define AscReadChipFIFO_H(port) (ushort)inpw((port)+IOP_REG_FIFO_H)
873#define AscWriteChipFIFO_H(port, data) outpw((port)+IOP_REG_FIFO_H, data)
874#define AscReadChipDmaSpeed(port) (uchar)inp((port)+IOP_DMA_SPEED)
875#define AscWriteChipDmaSpeed(port, data) outp((port)+IOP_DMA_SPEED, data)
876#define AscReadChipDA0(port) (ushort)inpw((port)+IOP_REG_DA0)
877#define AscWriteChipDA0(port) outpw((port)+IOP_REG_DA0, data)
878#define AscReadChipDA1(port) (ushort)inpw((port)+IOP_REG_DA1)
879#define AscWriteChipDA1(port) outpw((port)+IOP_REG_DA1, data)
880#define AscReadChipDC0(port) (ushort)inpw((port)+IOP_REG_DC0)
881#define AscWriteChipDC0(port) outpw((port)+IOP_REG_DC0, data)
882#define AscReadChipDC1(port) (ushort)inpw((port)+IOP_REG_DC1)
883#define AscWriteChipDC1(port) outpw((port)+IOP_REG_DC1, data)
884#define AscReadChipDvcID(port) (uchar)inp((port)+IOP_REG_ID)
885#define AscWriteChipDvcID(port, data) outp((port)+IOP_REG_ID, data)
886
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 * These macros are used to convert a virtual address to a
889 * 32-bit value. This currently can be used on Linux Alpha
890 * which uses 64-bit virtual address but a 32-bit bus address.
891 * This is likely to break in the future, but doing this now
892 * will give us time to change the HW and FW to handle 64-bit
893 * addresses.
894 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895#define ADV_U32_TO_VADDR bus_to_virt
896
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400897#define AdvPortAddr void __iomem * /* Virtual memory address size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
899/*
900 * Define Adv Library required memory access macros.
901 */
902#define ADV_MEM_READB(addr) readb(addr)
903#define ADV_MEM_READW(addr) readw(addr)
904#define ADV_MEM_WRITEB(addr, byte) writeb(byte, addr)
905#define ADV_MEM_WRITEW(addr, word) writew(word, addr)
906#define ADV_MEM_WRITEDW(addr, dword) writel(dword, addr)
907
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 * Define total number of simultaneous maximum element scatter-gather
910 * request blocks per wide adapter. ASC_DEF_MAX_HOST_QNG (253) is the
911 * maximum number of outstanding commands per wide host adapter. Each
912 * command uses one or more ADV_SG_BLOCK each with 15 scatter-gather
913 * elements. Allow each command to have at least one ADV_SG_BLOCK structure.
914 * This allows about 15 commands to have the maximum 17 ADV_SG_BLOCK
915 * structures or 255 scatter-gather elements.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 */
917#define ADV_TOT_SG_BLOCK ASC_DEF_MAX_HOST_QNG
918
919/*
Matthew Wilcox98d41c22007-10-02 21:55:37 -0400920 * Define maximum number of scatter-gather elements per request.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 */
922#define ADV_MAX_SG_LIST 255
Matthew Wilcox98d41c22007-10-02 21:55:37 -0400923#define NO_OF_SG_PER_BLOCK 15
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925#define ADV_EEP_DVC_CFG_BEGIN (0x00)
926#define ADV_EEP_DVC_CFG_END (0x15)
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400927#define ADV_EEP_DVC_CTL_BEGIN (0x16) /* location of OEM name */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928#define ADV_EEP_MAX_WORD_ADDR (0x1E)
929
930#define ADV_EEP_DELAY_MS 100
931
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400932#define ADV_EEPROM_BIG_ENDIAN 0x8000 /* EEPROM Bit 15 */
933#define ADV_EEPROM_BIOS_ENABLE 0x4000 /* EEPROM Bit 14 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934/*
935 * For the ASC3550 Bit 13 is Termination Polarity control bit.
936 * For later ICs Bit 13 controls whether the CIS (Card Information
937 * Service Section) is loaded from EEPROM.
938 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400939#define ADV_EEPROM_TERM_POL 0x2000 /* EEPROM Bit 13 */
940#define ADV_EEPROM_CIS_LD 0x2000 /* EEPROM Bit 13 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941/*
942 * ASC38C1600 Bit 11
943 *
944 * If EEPROM Bit 11 is 0 for Function 0, then Function 0 will specify
945 * INT A in the PCI Configuration Space Int Pin field. If it is 1, then
946 * Function 0 will specify INT B.
947 *
948 * If EEPROM Bit 11 is 0 for Function 1, then Function 1 will specify
949 * INT B in the PCI Configuration Space Int Pin field. If it is 1, then
950 * Function 1 will specify INT A.
951 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400952#define ADV_EEPROM_INTAB 0x0800 /* EEPROM Bit 11 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400954typedef struct adveep_3550_config {
955 /* Word Offset, Description */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400957 ushort cfg_lsw; /* 00 power up initialization */
958 /* bit 13 set - Term Polarity Control */
959 /* bit 14 set - BIOS Enable */
960 /* bit 15 set - Big Endian Mode */
961 ushort cfg_msw; /* 01 unused */
962 ushort disc_enable; /* 02 disconnect enable */
963 ushort wdtr_able; /* 03 Wide DTR able */
964 ushort sdtr_able; /* 04 Synchronous DTR able */
965 ushort start_motor; /* 05 send start up motor */
966 ushort tagqng_able; /* 06 tag queuing able */
967 ushort bios_scan; /* 07 BIOS device control */
968 ushort scam_tolerant; /* 08 no scam */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400970 uchar adapter_scsi_id; /* 09 Host Adapter ID */
971 uchar bios_boot_delay; /* power up wait */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400973 uchar scsi_reset_delay; /* 10 reset delay */
974 uchar bios_id_lun; /* first boot device scsi id & lun */
975 /* high nibble is lun */
976 /* low nibble is scsi id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400978 uchar termination; /* 11 0 - automatic */
979 /* 1 - low off / high off */
980 /* 2 - low off / high on */
981 /* 3 - low on / high on */
982 /* There is no low on / high off */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400984 uchar reserved1; /* reserved byte (not used) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
Matthew Wilcox27c868c2007-07-26 10:56:23 -0400986 ushort bios_ctrl; /* 12 BIOS control bits */
987 /* bit 0 BIOS don't act as initiator. */
988 /* bit 1 BIOS > 1 GB support */
989 /* bit 2 BIOS > 2 Disk Support */
990 /* bit 3 BIOS don't support removables */
991 /* bit 4 BIOS support bootable CD */
992 /* bit 5 BIOS scan enabled */
993 /* bit 6 BIOS support multiple LUNs */
994 /* bit 7 BIOS display of message */
995 /* bit 8 SCAM disabled */
996 /* bit 9 Reset SCSI bus during init. */
997 /* bit 10 */
998 /* bit 11 No verbose initialization. */
999 /* bit 12 SCSI parity enabled */
1000 /* bit 13 */
1001 /* bit 14 */
1002 /* bit 15 */
1003 ushort ultra_able; /* 13 ULTRA speed able */
1004 ushort reserved2; /* 14 reserved */
1005 uchar max_host_qng; /* 15 maximum host queuing */
1006 uchar max_dvc_qng; /* maximum per device queuing */
1007 ushort dvc_cntl; /* 16 control bit for driver */
1008 ushort bug_fix; /* 17 control bit for bug fix */
1009 ushort serial_number_word1; /* 18 Board serial number word 1 */
1010 ushort serial_number_word2; /* 19 Board serial number word 2 */
1011 ushort serial_number_word3; /* 20 Board serial number word 3 */
1012 ushort check_sum; /* 21 EEP check sum */
1013 uchar oem_name[16]; /* 22 OEM name */
1014 ushort dvc_err_code; /* 30 last device driver error code */
1015 ushort adv_err_code; /* 31 last uc and Adv Lib error code */
1016 ushort adv_err_addr; /* 32 last uc error address */
1017 ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
1018 ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
1019 ushort saved_adv_err_addr; /* 35 saved last uc error address */
1020 ushort num_of_err; /* 36 number of error */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021} ADVEEP_3550_CONFIG;
1022
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001023typedef struct adveep_38C0800_config {
1024 /* Word Offset, Description */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001026 ushort cfg_lsw; /* 00 power up initialization */
1027 /* bit 13 set - Load CIS */
1028 /* bit 14 set - BIOS Enable */
1029 /* bit 15 set - Big Endian Mode */
1030 ushort cfg_msw; /* 01 unused */
1031 ushort disc_enable; /* 02 disconnect enable */
1032 ushort wdtr_able; /* 03 Wide DTR able */
1033 ushort sdtr_speed1; /* 04 SDTR Speed TID 0-3 */
1034 ushort start_motor; /* 05 send start up motor */
1035 ushort tagqng_able; /* 06 tag queuing able */
1036 ushort bios_scan; /* 07 BIOS device control */
1037 ushort scam_tolerant; /* 08 no scam */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001039 uchar adapter_scsi_id; /* 09 Host Adapter ID */
1040 uchar bios_boot_delay; /* power up wait */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001042 uchar scsi_reset_delay; /* 10 reset delay */
1043 uchar bios_id_lun; /* first boot device scsi id & lun */
1044 /* high nibble is lun */
1045 /* low nibble is scsi id */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001047 uchar termination_se; /* 11 0 - automatic */
1048 /* 1 - low off / high off */
1049 /* 2 - low off / high on */
1050 /* 3 - low on / high on */
1051 /* There is no low on / high off */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001053 uchar termination_lvd; /* 11 0 - automatic */
1054 /* 1 - low off / high off */
1055 /* 2 - low off / high on */
1056 /* 3 - low on / high on */
1057 /* There is no low on / high off */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001059 ushort bios_ctrl; /* 12 BIOS control bits */
1060 /* bit 0 BIOS don't act as initiator. */
1061 /* bit 1 BIOS > 1 GB support */
1062 /* bit 2 BIOS > 2 Disk Support */
1063 /* bit 3 BIOS don't support removables */
1064 /* bit 4 BIOS support bootable CD */
1065 /* bit 5 BIOS scan enabled */
1066 /* bit 6 BIOS support multiple LUNs */
1067 /* bit 7 BIOS display of message */
1068 /* bit 8 SCAM disabled */
1069 /* bit 9 Reset SCSI bus during init. */
1070 /* bit 10 */
1071 /* bit 11 No verbose initialization. */
1072 /* bit 12 SCSI parity enabled */
1073 /* bit 13 */
1074 /* bit 14 */
1075 /* bit 15 */
1076 ushort sdtr_speed2; /* 13 SDTR speed TID 4-7 */
1077 ushort sdtr_speed3; /* 14 SDTR speed TID 8-11 */
1078 uchar max_host_qng; /* 15 maximum host queueing */
1079 uchar max_dvc_qng; /* maximum per device queuing */
1080 ushort dvc_cntl; /* 16 control bit for driver */
1081 ushort sdtr_speed4; /* 17 SDTR speed 4 TID 12-15 */
1082 ushort serial_number_word1; /* 18 Board serial number word 1 */
1083 ushort serial_number_word2; /* 19 Board serial number word 2 */
1084 ushort serial_number_word3; /* 20 Board serial number word 3 */
1085 ushort check_sum; /* 21 EEP check sum */
1086 uchar oem_name[16]; /* 22 OEM name */
1087 ushort dvc_err_code; /* 30 last device driver error code */
1088 ushort adv_err_code; /* 31 last uc and Adv Lib error code */
1089 ushort adv_err_addr; /* 32 last uc error address */
1090 ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
1091 ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
1092 ushort saved_adv_err_addr; /* 35 saved last uc error address */
1093 ushort reserved36; /* 36 reserved */
1094 ushort reserved37; /* 37 reserved */
1095 ushort reserved38; /* 38 reserved */
1096 ushort reserved39; /* 39 reserved */
1097 ushort reserved40; /* 40 reserved */
1098 ushort reserved41; /* 41 reserved */
1099 ushort reserved42; /* 42 reserved */
1100 ushort reserved43; /* 43 reserved */
1101 ushort reserved44; /* 44 reserved */
1102 ushort reserved45; /* 45 reserved */
1103 ushort reserved46; /* 46 reserved */
1104 ushort reserved47; /* 47 reserved */
1105 ushort reserved48; /* 48 reserved */
1106 ushort reserved49; /* 49 reserved */
1107 ushort reserved50; /* 50 reserved */
1108 ushort reserved51; /* 51 reserved */
1109 ushort reserved52; /* 52 reserved */
1110 ushort reserved53; /* 53 reserved */
1111 ushort reserved54; /* 54 reserved */
1112 ushort reserved55; /* 55 reserved */
1113 ushort cisptr_lsw; /* 56 CIS PTR LSW */
1114 ushort cisprt_msw; /* 57 CIS PTR MSW */
1115 ushort subsysvid; /* 58 SubSystem Vendor ID */
1116 ushort subsysid; /* 59 SubSystem ID */
1117 ushort reserved60; /* 60 reserved */
1118 ushort reserved61; /* 61 reserved */
1119 ushort reserved62; /* 62 reserved */
1120 ushort reserved63; /* 63 reserved */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121} ADVEEP_38C0800_CONFIG;
1122
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001123typedef struct adveep_38C1600_config {
1124 /* Word Offset, Description */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001126 ushort cfg_lsw; /* 00 power up initialization */
1127 /* bit 11 set - Func. 0 INTB, Func. 1 INTA */
1128 /* clear - Func. 0 INTA, Func. 1 INTB */
1129 /* bit 13 set - Load CIS */
1130 /* bit 14 set - BIOS Enable */
1131 /* bit 15 set - Big Endian Mode */
1132 ushort cfg_msw; /* 01 unused */
1133 ushort disc_enable; /* 02 disconnect enable */
1134 ushort wdtr_able; /* 03 Wide DTR able */
1135 ushort sdtr_speed1; /* 04 SDTR Speed TID 0-3 */
1136 ushort start_motor; /* 05 send start up motor */
1137 ushort tagqng_able; /* 06 tag queuing able */
1138 ushort bios_scan; /* 07 BIOS device control */
1139 ushort scam_tolerant; /* 08 no scam */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001141 uchar adapter_scsi_id; /* 09 Host Adapter ID */
1142 uchar bios_boot_delay; /* power up wait */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001144 uchar scsi_reset_delay; /* 10 reset delay */
1145 uchar bios_id_lun; /* first boot device scsi id & lun */
1146 /* high nibble is lun */
1147 /* low nibble is scsi id */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001149 uchar termination_se; /* 11 0 - automatic */
1150 /* 1 - low off / high off */
1151 /* 2 - low off / high on */
1152 /* 3 - low on / high on */
1153 /* There is no low on / high off */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001155 uchar termination_lvd; /* 11 0 - automatic */
1156 /* 1 - low off / high off */
1157 /* 2 - low off / high on */
1158 /* 3 - low on / high on */
1159 /* There is no low on / high off */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001161 ushort bios_ctrl; /* 12 BIOS control bits */
1162 /* bit 0 BIOS don't act as initiator. */
1163 /* bit 1 BIOS > 1 GB support */
1164 /* bit 2 BIOS > 2 Disk Support */
1165 /* bit 3 BIOS don't support removables */
1166 /* bit 4 BIOS support bootable CD */
1167 /* bit 5 BIOS scan enabled */
1168 /* bit 6 BIOS support multiple LUNs */
1169 /* bit 7 BIOS display of message */
1170 /* bit 8 SCAM disabled */
1171 /* bit 9 Reset SCSI bus during init. */
1172 /* bit 10 Basic Integrity Checking disabled */
1173 /* bit 11 No verbose initialization. */
1174 /* bit 12 SCSI parity enabled */
1175 /* bit 13 AIPP (Asyn. Info. Ph. Prot.) dis. */
1176 /* bit 14 */
1177 /* bit 15 */
1178 ushort sdtr_speed2; /* 13 SDTR speed TID 4-7 */
1179 ushort sdtr_speed3; /* 14 SDTR speed TID 8-11 */
1180 uchar max_host_qng; /* 15 maximum host queueing */
1181 uchar max_dvc_qng; /* maximum per device queuing */
1182 ushort dvc_cntl; /* 16 control bit for driver */
1183 ushort sdtr_speed4; /* 17 SDTR speed 4 TID 12-15 */
1184 ushort serial_number_word1; /* 18 Board serial number word 1 */
1185 ushort serial_number_word2; /* 19 Board serial number word 2 */
1186 ushort serial_number_word3; /* 20 Board serial number word 3 */
1187 ushort check_sum; /* 21 EEP check sum */
1188 uchar oem_name[16]; /* 22 OEM name */
1189 ushort dvc_err_code; /* 30 last device driver error code */
1190 ushort adv_err_code; /* 31 last uc and Adv Lib error code */
1191 ushort adv_err_addr; /* 32 last uc error address */
1192 ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
1193 ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
1194 ushort saved_adv_err_addr; /* 35 saved last uc error address */
1195 ushort reserved36; /* 36 reserved */
1196 ushort reserved37; /* 37 reserved */
1197 ushort reserved38; /* 38 reserved */
1198 ushort reserved39; /* 39 reserved */
1199 ushort reserved40; /* 40 reserved */
1200 ushort reserved41; /* 41 reserved */
1201 ushort reserved42; /* 42 reserved */
1202 ushort reserved43; /* 43 reserved */
1203 ushort reserved44; /* 44 reserved */
1204 ushort reserved45; /* 45 reserved */
1205 ushort reserved46; /* 46 reserved */
1206 ushort reserved47; /* 47 reserved */
1207 ushort reserved48; /* 48 reserved */
1208 ushort reserved49; /* 49 reserved */
1209 ushort reserved50; /* 50 reserved */
1210 ushort reserved51; /* 51 reserved */
1211 ushort reserved52; /* 52 reserved */
1212 ushort reserved53; /* 53 reserved */
1213 ushort reserved54; /* 54 reserved */
1214 ushort reserved55; /* 55 reserved */
1215 ushort cisptr_lsw; /* 56 CIS PTR LSW */
1216 ushort cisprt_msw; /* 57 CIS PTR MSW */
1217 ushort subsysvid; /* 58 SubSystem Vendor ID */
1218 ushort subsysid; /* 59 SubSystem ID */
1219 ushort reserved60; /* 60 reserved */
1220 ushort reserved61; /* 61 reserved */
1221 ushort reserved62; /* 62 reserved */
1222 ushort reserved63; /* 63 reserved */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223} ADVEEP_38C1600_CONFIG;
1224
1225/*
1226 * EEPROM Commands
1227 */
1228#define ASC_EEP_CMD_DONE 0x0200
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
1230/* bios_ctrl */
1231#define BIOS_CTRL_BIOS 0x0001
1232#define BIOS_CTRL_EXTENDED_XLAT 0x0002
1233#define BIOS_CTRL_GT_2_DISK 0x0004
1234#define BIOS_CTRL_BIOS_REMOVABLE 0x0008
1235#define BIOS_CTRL_BOOTABLE_CD 0x0010
1236#define BIOS_CTRL_MULTIPLE_LUN 0x0040
1237#define BIOS_CTRL_DISPLAY_MSG 0x0080
1238#define BIOS_CTRL_NO_SCAM 0x0100
1239#define BIOS_CTRL_RESET_SCSI_BUS 0x0200
1240#define BIOS_CTRL_INIT_VERBOSE 0x0800
1241#define BIOS_CTRL_SCSI_PARITY 0x1000
1242#define BIOS_CTRL_AIPP_DIS 0x2000
1243
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001244#define ADV_3550_MEMSIZE 0x2000 /* 8 KB Internal Memory */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001246#define ADV_38C0800_MEMSIZE 0x4000 /* 16 KB Internal Memory */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
1248/*
1249 * XXX - Since ASC38C1600 Rev.3 has a local RAM failure issue, there is
1250 * a special 16K Adv Library and Microcode version. After the issue is
1251 * resolved, should restore 32K support.
1252 *
1253 * #define ADV_38C1600_MEMSIZE 0x8000L * 32 KB Internal Memory *
1254 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001255#define ADV_38C1600_MEMSIZE 0x4000 /* 16 KB Internal Memory */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256
1257/*
1258 * Byte I/O register address from base of 'iop_base'.
1259 */
1260#define IOPB_INTR_STATUS_REG 0x00
1261#define IOPB_CHIP_ID_1 0x01
1262#define IOPB_INTR_ENABLES 0x02
1263#define IOPB_CHIP_TYPE_REV 0x03
1264#define IOPB_RES_ADDR_4 0x04
1265#define IOPB_RES_ADDR_5 0x05
1266#define IOPB_RAM_DATA 0x06
1267#define IOPB_RES_ADDR_7 0x07
1268#define IOPB_FLAG_REG 0x08
1269#define IOPB_RES_ADDR_9 0x09
1270#define IOPB_RISC_CSR 0x0A
1271#define IOPB_RES_ADDR_B 0x0B
1272#define IOPB_RES_ADDR_C 0x0C
1273#define IOPB_RES_ADDR_D 0x0D
1274#define IOPB_SOFT_OVER_WR 0x0E
1275#define IOPB_RES_ADDR_F 0x0F
1276#define IOPB_MEM_CFG 0x10
1277#define IOPB_RES_ADDR_11 0x11
1278#define IOPB_GPIO_DATA 0x12
1279#define IOPB_RES_ADDR_13 0x13
1280#define IOPB_FLASH_PAGE 0x14
1281#define IOPB_RES_ADDR_15 0x15
1282#define IOPB_GPIO_CNTL 0x16
1283#define IOPB_RES_ADDR_17 0x17
1284#define IOPB_FLASH_DATA 0x18
1285#define IOPB_RES_ADDR_19 0x19
1286#define IOPB_RES_ADDR_1A 0x1A
1287#define IOPB_RES_ADDR_1B 0x1B
1288#define IOPB_RES_ADDR_1C 0x1C
1289#define IOPB_RES_ADDR_1D 0x1D
1290#define IOPB_RES_ADDR_1E 0x1E
1291#define IOPB_RES_ADDR_1F 0x1F
1292#define IOPB_DMA_CFG0 0x20
1293#define IOPB_DMA_CFG1 0x21
1294#define IOPB_TICKLE 0x22
1295#define IOPB_DMA_REG_WR 0x23
1296#define IOPB_SDMA_STATUS 0x24
1297#define IOPB_SCSI_BYTE_CNT 0x25
1298#define IOPB_HOST_BYTE_CNT 0x26
1299#define IOPB_BYTE_LEFT_TO_XFER 0x27
1300#define IOPB_BYTE_TO_XFER_0 0x28
1301#define IOPB_BYTE_TO_XFER_1 0x29
1302#define IOPB_BYTE_TO_XFER_2 0x2A
1303#define IOPB_BYTE_TO_XFER_3 0x2B
1304#define IOPB_ACC_GRP 0x2C
1305#define IOPB_RES_ADDR_2D 0x2D
1306#define IOPB_DEV_ID 0x2E
1307#define IOPB_RES_ADDR_2F 0x2F
1308#define IOPB_SCSI_DATA 0x30
1309#define IOPB_RES_ADDR_31 0x31
1310#define IOPB_RES_ADDR_32 0x32
1311#define IOPB_SCSI_DATA_HSHK 0x33
1312#define IOPB_SCSI_CTRL 0x34
1313#define IOPB_RES_ADDR_35 0x35
1314#define IOPB_RES_ADDR_36 0x36
1315#define IOPB_RES_ADDR_37 0x37
1316#define IOPB_RAM_BIST 0x38
1317#define IOPB_PLL_TEST 0x39
1318#define IOPB_PCI_INT_CFG 0x3A
1319#define IOPB_RES_ADDR_3B 0x3B
1320#define IOPB_RFIFO_CNT 0x3C
1321#define IOPB_RES_ADDR_3D 0x3D
1322#define IOPB_RES_ADDR_3E 0x3E
1323#define IOPB_RES_ADDR_3F 0x3F
1324
1325/*
1326 * Word I/O register address from base of 'iop_base'.
1327 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001328#define IOPW_CHIP_ID_0 0x00 /* CID0 */
1329#define IOPW_CTRL_REG 0x02 /* CC */
1330#define IOPW_RAM_ADDR 0x04 /* LA */
1331#define IOPW_RAM_DATA 0x06 /* LD */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332#define IOPW_RES_ADDR_08 0x08
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001333#define IOPW_RISC_CSR 0x0A /* CSR */
1334#define IOPW_SCSI_CFG0 0x0C /* CFG0 */
1335#define IOPW_SCSI_CFG1 0x0E /* CFG1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336#define IOPW_RES_ADDR_10 0x10
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001337#define IOPW_SEL_MASK 0x12 /* SM */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338#define IOPW_RES_ADDR_14 0x14
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001339#define IOPW_FLASH_ADDR 0x16 /* FA */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340#define IOPW_RES_ADDR_18 0x18
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001341#define IOPW_EE_CMD 0x1A /* EC */
1342#define IOPW_EE_DATA 0x1C /* ED */
1343#define IOPW_SFIFO_CNT 0x1E /* SFC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344#define IOPW_RES_ADDR_20 0x20
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001345#define IOPW_Q_BASE 0x22 /* QB */
1346#define IOPW_QP 0x24 /* QP */
1347#define IOPW_IX 0x26 /* IX */
1348#define IOPW_SP 0x28 /* SP */
1349#define IOPW_PC 0x2A /* PC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350#define IOPW_RES_ADDR_2C 0x2C
1351#define IOPW_RES_ADDR_2E 0x2E
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001352#define IOPW_SCSI_DATA 0x30 /* SD */
1353#define IOPW_SCSI_DATA_HSHK 0x32 /* SDH */
1354#define IOPW_SCSI_CTRL 0x34 /* SC */
1355#define IOPW_HSHK_CFG 0x36 /* HCFG */
1356#define IOPW_SXFR_STATUS 0x36 /* SXS */
1357#define IOPW_SXFR_CNTL 0x38 /* SXL */
1358#define IOPW_SXFR_CNTH 0x3A /* SXH */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359#define IOPW_RES_ADDR_3C 0x3C
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001360#define IOPW_RFIFO_DATA 0x3E /* RFD */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
1362/*
1363 * Doubleword I/O register address from base of 'iop_base'.
1364 */
1365#define IOPDW_RES_ADDR_0 0x00
1366#define IOPDW_RAM_DATA 0x04
1367#define IOPDW_RES_ADDR_8 0x08
1368#define IOPDW_RES_ADDR_C 0x0C
1369#define IOPDW_RES_ADDR_10 0x10
1370#define IOPDW_COMMA 0x14
1371#define IOPDW_COMMB 0x18
1372#define IOPDW_RES_ADDR_1C 0x1C
1373#define IOPDW_SDMA_ADDR0 0x20
1374#define IOPDW_SDMA_ADDR1 0x24
1375#define IOPDW_SDMA_COUNT 0x28
1376#define IOPDW_SDMA_ERROR 0x2C
1377#define IOPDW_RDMA_ADDR0 0x30
1378#define IOPDW_RDMA_ADDR1 0x34
1379#define IOPDW_RDMA_COUNT 0x38
1380#define IOPDW_RDMA_ERROR 0x3C
1381
1382#define ADV_CHIP_ID_BYTE 0x25
1383#define ADV_CHIP_ID_WORD 0x04C1
1384
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385#define ADV_INTR_ENABLE_HOST_INTR 0x01
1386#define ADV_INTR_ENABLE_SEL_INTR 0x02
1387#define ADV_INTR_ENABLE_DPR_INTR 0x04
1388#define ADV_INTR_ENABLE_RTA_INTR 0x08
1389#define ADV_INTR_ENABLE_RMA_INTR 0x10
1390#define ADV_INTR_ENABLE_RST_INTR 0x20
1391#define ADV_INTR_ENABLE_DPE_INTR 0x40
1392#define ADV_INTR_ENABLE_GLOBAL_INTR 0x80
1393
1394#define ADV_INTR_STATUS_INTRA 0x01
1395#define ADV_INTR_STATUS_INTRB 0x02
1396#define ADV_INTR_STATUS_INTRC 0x04
1397
1398#define ADV_RISC_CSR_STOP (0x0000)
1399#define ADV_RISC_TEST_COND (0x2000)
1400#define ADV_RISC_CSR_RUN (0x4000)
1401#define ADV_RISC_CSR_SINGLE_STEP (0x8000)
1402
1403#define ADV_CTRL_REG_HOST_INTR 0x0100
1404#define ADV_CTRL_REG_SEL_INTR 0x0200
1405#define ADV_CTRL_REG_DPR_INTR 0x0400
1406#define ADV_CTRL_REG_RTA_INTR 0x0800
1407#define ADV_CTRL_REG_RMA_INTR 0x1000
1408#define ADV_CTRL_REG_RES_BIT14 0x2000
1409#define ADV_CTRL_REG_DPE_INTR 0x4000
1410#define ADV_CTRL_REG_POWER_DONE 0x8000
1411#define ADV_CTRL_REG_ANY_INTR 0xFF00
1412
1413#define ADV_CTRL_REG_CMD_RESET 0x00C6
1414#define ADV_CTRL_REG_CMD_WR_IO_REG 0x00C5
1415#define ADV_CTRL_REG_CMD_RD_IO_REG 0x00C4
1416#define ADV_CTRL_REG_CMD_WR_PCI_CFG_SPACE 0x00C3
1417#define ADV_CTRL_REG_CMD_RD_PCI_CFG_SPACE 0x00C2
1418
1419#define ADV_TICKLE_NOP 0x00
1420#define ADV_TICKLE_A 0x01
1421#define ADV_TICKLE_B 0x02
1422#define ADV_TICKLE_C 0x03
1423
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424#define AdvIsIntPending(port) \
1425 (AdvReadWordRegister(port, IOPW_CTRL_REG) & ADV_CTRL_REG_HOST_INTR)
1426
1427/*
1428 * SCSI_CFG0 Register bit definitions
1429 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001430#define TIMER_MODEAB 0xC000 /* Watchdog, Second, and Select. Timer Ctrl. */
1431#define PARITY_EN 0x2000 /* Enable SCSI Parity Error detection */
1432#define EVEN_PARITY 0x1000 /* Select Even Parity */
1433#define WD_LONG 0x0800 /* Watchdog Interval, 1: 57 min, 0: 13 sec */
1434#define QUEUE_128 0x0400 /* Queue Size, 1: 128 byte, 0: 64 byte */
1435#define PRIM_MODE 0x0100 /* Primitive SCSI mode */
1436#define SCAM_EN 0x0080 /* Enable SCAM selection */
1437#define SEL_TMO_LONG 0x0040 /* Sel/Resel Timeout, 1: 400 ms, 0: 1.6 ms */
1438#define CFRM_ID 0x0020 /* SCAM id sel. confirm., 1: fast, 0: 6.4 ms */
1439#define OUR_ID_EN 0x0010 /* Enable OUR_ID bits */
1440#define OUR_ID 0x000F /* SCSI ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441
1442/*
1443 * SCSI_CFG1 Register bit definitions
1444 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001445#define BIG_ENDIAN 0x8000 /* Enable Big Endian Mode MIO:15, EEP:15 */
1446#define TERM_POL 0x2000 /* Terminator Polarity Ctrl. MIO:13, EEP:13 */
1447#define SLEW_RATE 0x1000 /* SCSI output buffer slew rate */
1448#define FILTER_SEL 0x0C00 /* Filter Period Selection */
1449#define FLTR_DISABLE 0x0000 /* Input Filtering Disabled */
1450#define FLTR_11_TO_20NS 0x0800 /* Input Filtering 11ns to 20ns */
1451#define FLTR_21_TO_39NS 0x0C00 /* Input Filtering 21ns to 39ns */
1452#define ACTIVE_DBL 0x0200 /* Disable Active Negation */
1453#define DIFF_MODE 0x0100 /* SCSI differential Mode (Read-Only) */
1454#define DIFF_SENSE 0x0080 /* 1: No SE cables, 0: SE cable (Read-Only) */
1455#define TERM_CTL_SEL 0x0040 /* Enable TERM_CTL_H and TERM_CTL_L */
1456#define TERM_CTL 0x0030 /* External SCSI Termination Bits */
1457#define TERM_CTL_H 0x0020 /* Enable External SCSI Upper Termination */
1458#define TERM_CTL_L 0x0010 /* Enable External SCSI Lower Termination */
1459#define CABLE_DETECT 0x000F /* External SCSI Cable Connection Status */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460
1461/*
1462 * Addendum for ASC-38C0800 Chip
1463 *
1464 * The ASC-38C1600 Chip uses the same definitions except that the
1465 * bus mode override bits [12:10] have been moved to byte register
1466 * offset 0xE (IOPB_SOFT_OVER_WR) bits [12:10]. The [12:10] bits in
1467 * SCSI_CFG1 are read-only and always available. Bit 14 (DIS_TERM_DRV)
1468 * is not needed. The [12:10] bits in IOPB_SOFT_OVER_WR are write-only.
1469 * Also each ASC-38C1600 function or channel uses only cable bits [5:4]
1470 * and [1:0]. Bits [14], [7:6], [3:2] are unused.
1471 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001472#define DIS_TERM_DRV 0x4000 /* 1: Read c_det[3:0], 0: cannot read */
1473#define HVD_LVD_SE 0x1C00 /* Device Detect Bits */
1474#define HVD 0x1000 /* HVD Device Detect */
1475#define LVD 0x0800 /* LVD Device Detect */
1476#define SE 0x0400 /* SE Device Detect */
1477#define TERM_LVD 0x00C0 /* LVD Termination Bits */
1478#define TERM_LVD_HI 0x0080 /* Enable LVD Upper Termination */
1479#define TERM_LVD_LO 0x0040 /* Enable LVD Lower Termination */
1480#define TERM_SE 0x0030 /* SE Termination Bits */
1481#define TERM_SE_HI 0x0020 /* Enable SE Upper Termination */
1482#define TERM_SE_LO 0x0010 /* Enable SE Lower Termination */
1483#define C_DET_LVD 0x000C /* LVD Cable Detect Bits */
1484#define C_DET3 0x0008 /* Cable Detect for LVD External Wide */
1485#define C_DET2 0x0004 /* Cable Detect for LVD Internal Wide */
1486#define C_DET_SE 0x0003 /* SE Cable Detect Bits */
1487#define C_DET1 0x0002 /* Cable Detect for SE Internal Wide */
1488#define C_DET0 0x0001 /* Cable Detect for SE Internal Narrow */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489
1490#define CABLE_ILLEGAL_A 0x7
1491 /* x 0 0 0 | on on | Illegal (all 3 connectors are used) */
1492
1493#define CABLE_ILLEGAL_B 0xB
1494 /* 0 x 0 0 | on on | Illegal (all 3 connectors are used) */
1495
1496/*
1497 * MEM_CFG Register bit definitions
1498 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001499#define BIOS_EN 0x40 /* BIOS Enable MIO:14,EEP:14 */
1500#define FAST_EE_CLK 0x20 /* Diagnostic Bit */
1501#define RAM_SZ 0x1C /* Specify size of RAM to RISC */
1502#define RAM_SZ_2KB 0x00 /* 2 KB */
1503#define RAM_SZ_4KB 0x04 /* 4 KB */
1504#define RAM_SZ_8KB 0x08 /* 8 KB */
1505#define RAM_SZ_16KB 0x0C /* 16 KB */
1506#define RAM_SZ_32KB 0x10 /* 32 KB */
1507#define RAM_SZ_64KB 0x14 /* 64 KB */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508
1509/*
1510 * DMA_CFG0 Register bit definitions
1511 *
1512 * This register is only accessible to the host.
1513 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001514#define BC_THRESH_ENB 0x80 /* PCI DMA Start Conditions */
1515#define FIFO_THRESH 0x70 /* PCI DMA FIFO Threshold */
1516#define FIFO_THRESH_16B 0x00 /* 16 bytes */
1517#define FIFO_THRESH_32B 0x20 /* 32 bytes */
1518#define FIFO_THRESH_48B 0x30 /* 48 bytes */
1519#define FIFO_THRESH_64B 0x40 /* 64 bytes */
1520#define FIFO_THRESH_80B 0x50 /* 80 bytes (default) */
1521#define FIFO_THRESH_96B 0x60 /* 96 bytes */
1522#define FIFO_THRESH_112B 0x70 /* 112 bytes */
1523#define START_CTL 0x0C /* DMA start conditions */
1524#define START_CTL_TH 0x00 /* Wait threshold level (default) */
1525#define START_CTL_ID 0x04 /* Wait SDMA/SBUS idle */
1526#define START_CTL_THID 0x08 /* Wait threshold and SDMA/SBUS idle */
1527#define START_CTL_EMFU 0x0C /* Wait SDMA FIFO empty/full */
1528#define READ_CMD 0x03 /* Memory Read Method */
1529#define READ_CMD_MR 0x00 /* Memory Read */
1530#define READ_CMD_MRL 0x02 /* Memory Read Long */
1531#define READ_CMD_MRM 0x03 /* Memory Read Multiple (default) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532
1533/*
1534 * ASC-38C0800 RAM BIST Register bit definitions
1535 */
1536#define RAM_TEST_MODE 0x80
1537#define PRE_TEST_MODE 0x40
1538#define NORMAL_MODE 0x00
1539#define RAM_TEST_DONE 0x10
1540#define RAM_TEST_STATUS 0x0F
1541#define RAM_TEST_HOST_ERROR 0x08
1542#define RAM_TEST_INTRAM_ERROR 0x04
1543#define RAM_TEST_RISC_ERROR 0x02
1544#define RAM_TEST_SCSI_ERROR 0x01
1545#define RAM_TEST_SUCCESS 0x00
1546#define PRE_TEST_VALUE 0x05
1547#define NORMAL_VALUE 0x00
1548
1549/*
1550 * ASC38C1600 Definitions
1551 *
1552 * IOPB_PCI_INT_CFG Bit Field Definitions
1553 */
1554
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001555#define INTAB_LD 0x80 /* Value loaded from EEPROM Bit 11. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
1557/*
1558 * Bit 1 can be set to change the interrupt for the Function to operate in
1559 * Totem Pole mode. By default Bit 1 is 0 and the interrupt operates in
1560 * Open Drain mode. Both functions of the ASC38C1600 must be set to the same
1561 * mode, otherwise the operating mode is undefined.
1562 */
1563#define TOTEMPOLE 0x02
1564
1565/*
1566 * Bit 0 can be used to change the Int Pin for the Function. The value is
1567 * 0 by default for both Functions with Function 0 using INT A and Function
1568 * B using INT B. For Function 0 if set, INT B is used. For Function 1 if set,
1569 * INT A is used.
1570 *
1571 * EEPROM Word 0 Bit 11 for each Function may change the initial Int Pin
1572 * value specified in the PCI Configuration Space.
1573 */
1574#define INTAB 0x01
1575
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576/*
1577 * Adv Library Status Definitions
1578 */
1579#define ADV_TRUE 1
1580#define ADV_FALSE 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581#define ADV_SUCCESS 1
1582#define ADV_BUSY 0
1583#define ADV_ERROR (-1)
1584
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585/*
1586 * ADV_DVC_VAR 'warn_code' values
1587 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001588#define ASC_WARN_BUSRESET_ERROR 0x0001 /* SCSI Bus Reset error */
1589#define ASC_WARN_EEPROM_CHKSUM 0x0002 /* EEP check sum error */
1590#define ASC_WARN_EEPROM_TERMINATION 0x0004 /* EEP termination bad field */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001591#define ASC_WARN_ERROR 0xFFFF /* ADV_ERROR return */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001593#define ADV_MAX_TID 15 /* max. target identifier */
1594#define ADV_MAX_LUN 7 /* max. logical unit number */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595
1596/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 * Fixed locations of microcode operating variables.
1598 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001599#define ASC_MC_CODE_BEGIN_ADDR 0x0028 /* microcode start address */
1600#define ASC_MC_CODE_END_ADDR 0x002A /* microcode end address */
1601#define ASC_MC_CODE_CHK_SUM 0x002C /* microcode code checksum */
1602#define ASC_MC_VERSION_DATE 0x0038 /* microcode version */
1603#define ASC_MC_VERSION_NUM 0x003A /* microcode number */
1604#define ASC_MC_BIOSMEM 0x0040 /* BIOS RISC Memory Start */
1605#define ASC_MC_BIOSLEN 0x0050 /* BIOS RISC Memory Length */
1606#define ASC_MC_BIOS_SIGNATURE 0x0058 /* BIOS Signature 0x55AA */
1607#define ASC_MC_BIOS_VERSION 0x005A /* BIOS Version (2 bytes) */
1608#define ASC_MC_SDTR_SPEED1 0x0090 /* SDTR Speed for TID 0-3 */
1609#define ASC_MC_SDTR_SPEED2 0x0092 /* SDTR Speed for TID 4-7 */
1610#define ASC_MC_SDTR_SPEED3 0x0094 /* SDTR Speed for TID 8-11 */
1611#define ASC_MC_SDTR_SPEED4 0x0096 /* SDTR Speed for TID 12-15 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612#define ASC_MC_CHIP_TYPE 0x009A
1613#define ASC_MC_INTRB_CODE 0x009B
1614#define ASC_MC_WDTR_ABLE 0x009C
1615#define ASC_MC_SDTR_ABLE 0x009E
1616#define ASC_MC_TAGQNG_ABLE 0x00A0
1617#define ASC_MC_DISC_ENABLE 0x00A2
1618#define ASC_MC_IDLE_CMD_STATUS 0x00A4
1619#define ASC_MC_IDLE_CMD 0x00A6
1620#define ASC_MC_IDLE_CMD_PARAMETER 0x00A8
1621#define ASC_MC_DEFAULT_SCSI_CFG0 0x00AC
1622#define ASC_MC_DEFAULT_SCSI_CFG1 0x00AE
1623#define ASC_MC_DEFAULT_MEM_CFG 0x00B0
1624#define ASC_MC_DEFAULT_SEL_MASK 0x00B2
1625#define ASC_MC_SDTR_DONE 0x00B6
1626#define ASC_MC_NUMBER_OF_QUEUED_CMD 0x00C0
1627#define ASC_MC_NUMBER_OF_MAX_CMD 0x00D0
1628#define ASC_MC_DEVICE_HSHK_CFG_TABLE 0x0100
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001629#define ASC_MC_CONTROL_FLAG 0x0122 /* Microcode control flag. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630#define ASC_MC_WDTR_DONE 0x0124
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001631#define ASC_MC_CAM_MODE_MASK 0x015E /* CAM mode TID bitmask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632#define ASC_MC_ICQ 0x0160
1633#define ASC_MC_IRQ 0x0164
1634#define ASC_MC_PPR_ABLE 0x017A
1635
1636/*
1637 * BIOS LRAM variable absolute offsets.
1638 */
1639#define BIOS_CODESEG 0x54
1640#define BIOS_CODELEN 0x56
1641#define BIOS_SIGNATURE 0x58
1642#define BIOS_VERSION 0x5A
1643
1644/*
1645 * Microcode Control Flags
1646 *
1647 * Flags set by the Adv Library in RISC variable 'control_flag' (0x122)
1648 * and handled by the microcode.
1649 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001650#define CONTROL_FLAG_IGNORE_PERR 0x0001 /* Ignore DMA Parity Errors */
1651#define CONTROL_FLAG_ENABLE_AIPP 0x0002 /* Enabled AIPP checking. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652
1653/*
1654 * ASC_MC_DEVICE_HSHK_CFG_TABLE microcode table or HSHK_CFG register format
1655 */
1656#define HSHK_CFG_WIDE_XFR 0x8000
1657#define HSHK_CFG_RATE 0x0F00
1658#define HSHK_CFG_OFFSET 0x001F
1659
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001660#define ASC_DEF_MAX_HOST_QNG 0xFD /* Max. number of host commands (253) */
1661#define ASC_DEF_MIN_HOST_QNG 0x10 /* Min. number of host commands (16) */
1662#define ASC_DEF_MAX_DVC_QNG 0x3F /* Max. number commands per device (63) */
1663#define ASC_DEF_MIN_DVC_QNG 0x04 /* Min. number commands per device (4) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001665#define ASC_QC_DATA_CHECK 0x01 /* Require ASC_QC_DATA_OUT set or clear. */
1666#define ASC_QC_DATA_OUT 0x02 /* Data out DMA transfer. */
1667#define ASC_QC_START_MOTOR 0x04 /* Send auto-start motor before request. */
1668#define ASC_QC_NO_OVERRUN 0x08 /* Don't report overrun. */
1669#define ASC_QC_FREEZE_TIDQ 0x10 /* Freeze TID queue after request. XXX TBD */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001671#define ASC_QSC_NO_DISC 0x01 /* Don't allow disconnect for request. */
1672#define ASC_QSC_NO_TAGMSG 0x02 /* Don't allow tag queuing for request. */
1673#define ASC_QSC_NO_SYNC 0x04 /* Don't use Synch. transfer on request. */
1674#define ASC_QSC_NO_WIDE 0x08 /* Don't use Wide transfer on request. */
1675#define ASC_QSC_REDO_DTR 0x10 /* Renegotiate WDTR/SDTR before request. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676/*
1677 * Note: If a Tag Message is to be sent and neither ASC_QSC_HEAD_TAG or
1678 * ASC_QSC_ORDERED_TAG is set, then a Simple Tag Message (0x20) is used.
1679 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001680#define ASC_QSC_HEAD_TAG 0x40 /* Use Head Tag Message (0x21). */
1681#define ASC_QSC_ORDERED_TAG 0x80 /* Use Ordered Tag Message (0x22). */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682
1683/*
1684 * All fields here are accessed by the board microcode and need to be
1685 * little-endian.
1686 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001687typedef struct adv_carr_t {
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001688 __le32 carr_va; /* Carrier Virtual Address */
1689 __le32 carr_pa; /* Carrier Physical Address */
Hannes Reinecke9fef6ba2015-04-24 13:18:33 +02001690 __le32 areq_vpa; /* ADV_SCSI_REQ_Q Virtual or Physical Address */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001691 /*
1692 * next_vpa [31:4] Carrier Virtual or Physical Next Pointer
1693 *
1694 * next_vpa [3:1] Reserved Bits
1695 * next_vpa [0] Done Flag set in Response Queue.
1696 */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001697 __le32 next_vpa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698} ADV_CARR_T;
1699
1700/*
1701 * Mask used to eliminate low 4 bits of carrier 'next_vpa' field.
1702 */
Hannes Reinecke084e6c32015-04-24 13:18:35 +02001703#define ADV_NEXT_VPA_MASK 0xFFFFFFF0
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704
Hannes Reinecke084e6c32015-04-24 13:18:35 +02001705#define ADV_RQ_DONE 0x00000001
1706#define ADV_RQ_GOOD 0x00000002
1707#define ADV_CQ_STOPPER 0x00000000
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
Hannes Reinecke084e6c32015-04-24 13:18:35 +02001709#define ADV_GET_CARRP(carrp) ((carrp) & ADV_NEXT_VPA_MASK)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001711/*
1712 * Each carrier is 64 bytes, and we need three additional
1713 * carrier for icq, irq, and the termination carrier.
1714 */
1715#define ADV_CARRIER_COUNT (ASC_DEF_MAX_HOST_QNG + 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716
1717#define ADV_CARRIER_BUFSIZE \
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001718 (ADV_CARRIER_COUNT * sizeof(ADV_CARR_T))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001720#define ADV_CHIP_ASC3550 0x01 /* Ultra-Wide IC */
1721#define ADV_CHIP_ASC38C0800 0x02 /* Ultra2-Wide/LVD IC */
1722#define ADV_CHIP_ASC38C1600 0x03 /* Ultra3-Wide/LVD2 IC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723
1724/*
1725 * Adapter temporary configuration structure
1726 *
1727 * This structure can be discarded after initialization. Don't add
1728 * fields here needed after initialization.
1729 *
1730 * Field naming convention:
1731 *
1732 * *_enable indicates the field enables or disables a feature. The
1733 * value of the field is never reset.
1734 */
1735typedef struct adv_dvc_cfg {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001736 ushort disc_enable; /* enable disconnection */
1737 uchar chip_version; /* chip version */
1738 uchar termination; /* Term. Ctrl. bits 6-5 of SCSI_CFG1 register */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001739 ushort control_flag; /* Microcode Control Flag */
1740 ushort mcode_date; /* Microcode date */
1741 ushort mcode_version; /* Microcode version */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001742 ushort serial1; /* EEPROM serial number word 1 */
1743 ushort serial2; /* EEPROM serial number word 2 */
1744 ushort serial3; /* EEPROM serial number word 3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745} ADV_DVC_CFG;
1746
1747struct adv_dvc_var;
1748struct adv_scsi_req_q;
1749
Hannes Reinecke0ce53822015-04-24 13:18:25 +02001750typedef struct adv_sg_block {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001751 uchar reserved1;
1752 uchar reserved2;
1753 uchar reserved3;
1754 uchar sg_cnt; /* Valid entries in block. */
Hannes Reinecke0ce53822015-04-24 13:18:25 +02001755 __le32 sg_ptr; /* Pointer to next sg block. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001756 struct {
Hannes Reinecke0ce53822015-04-24 13:18:25 +02001757 __le32 sg_addr; /* SG element address. */
1758 __le32 sg_count; /* SG element count. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001759 } sg_list[NO_OF_SG_PER_BLOCK];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760} ADV_SG_BLOCK;
1761
1762/*
1763 * ADV_SCSI_REQ_Q - microcode request structure
1764 *
1765 * All fields in this structure up to byte 60 are used by the microcode.
1766 * The microcode makes assumptions about the size and ordering of fields
1767 * in this structure. Do not change the structure definition here without
1768 * coordinating the change with the microcode.
1769 *
1770 * All fields accessed by microcode must be maintained in little_endian
1771 * order.
1772 */
1773typedef struct adv_scsi_req_q {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001774 uchar cntl; /* Ucode flags and state (ASC_MC_QC_*). */
1775 uchar target_cmd;
1776 uchar target_id; /* Device target identifier. */
1777 uchar target_lun; /* Device target logical unit number. */
Hannes Reinecke95cfab62015-04-24 13:18:27 +02001778 __le32 data_addr; /* Data buffer physical address. */
1779 __le32 data_cnt; /* Data count. Ucode sets to residual. */
Hannes Reinecke811ddc02015-04-24 13:18:22 +02001780 __le32 sense_addr;
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001781 __le32 carr_pa;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001782 uchar mflag;
1783 uchar sense_len;
1784 uchar cdb_len; /* SCSI CDB length. Must <= 16 bytes. */
1785 uchar scsi_cntl;
1786 uchar done_status; /* Completion status. */
1787 uchar scsi_status; /* SCSI status byte. */
1788 uchar host_status; /* Ucode host status. */
1789 uchar sg_working_ix;
1790 uchar cdb[12]; /* SCSI CDB bytes 0-11. */
Hannes Reinecke95cfab62015-04-24 13:18:27 +02001791 __le32 sg_real_addr; /* SG list physical address. */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001792 __le32 scsiq_rptr;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001793 uchar cdb16[4]; /* SCSI CDB bytes 12-15. */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001794 __le32 scsiq_ptr;
1795 __le32 carr_va;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001796 /*
1797 * End of microcode structure - 60 bytes. The rest of the structure
1798 * is used by the Adv Library and ignored by the microcode.
1799 */
Hannes Reinecke9c17c622015-04-24 13:18:21 +02001800 u32 srb_tag;
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001801 ADV_SG_BLOCK *sg_list_ptr; /* SG list virtual address. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802} ADV_SCSI_REQ_Q;
1803
1804/*
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001805 * The following two structures are used to process Wide Board requests.
1806 *
1807 * The ADV_SCSI_REQ_Q structure in adv_req_t is passed to the Adv Library
Hannes Reinecke9c17c622015-04-24 13:18:21 +02001808 * and microcode with the ADV_SCSI_REQ_Q field 'srb_tag' set to the
1809 * SCSI request tag. The adv_req_t structure 'cmndp' field in turn points
1810 * to the Mid-Level SCSI request structure.
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001811 *
1812 * Zero or more ADV_SG_BLOCK are used with each ADV_SCSI_REQ_Q. Each
1813 * ADV_SG_BLOCK structure holds 15 scatter-gather elements. Under Linux
1814 * up to 255 scatter-gather elements may be used per request or
1815 * ADV_SCSI_REQ_Q.
1816 *
1817 * Both structures must be 32 byte aligned.
1818 */
1819typedef struct adv_sgblk {
1820 ADV_SG_BLOCK sg_block; /* Sgblock structure. */
Hannes Reinecke0ce53822015-04-24 13:18:25 +02001821 dma_addr_t sg_addr; /* Physical address */
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001822 struct adv_sgblk *next_sgblkp; /* Next scatter-gather structure. */
1823} adv_sgblk_t;
1824
1825typedef struct adv_req {
1826 ADV_SCSI_REQ_Q scsi_req_q; /* Adv Library request structure. */
Hannes Reinecke4b47e462015-04-24 13:18:24 +02001827 uchar align[24]; /* Request structure padding. */
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001828 struct scsi_cmnd *cmndp; /* Mid-Level SCSI command pointer. */
Hannes Reinecke4b47e462015-04-24 13:18:24 +02001829 dma_addr_t req_addr;
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001830 adv_sgblk_t *sgblkp; /* Adv Library scatter-gather pointer. */
Hannes Reinecke4b47e462015-04-24 13:18:24 +02001831} adv_req_t __aligned(32);
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001832
1833/*
1834 * Adapter operation variable structure.
1835 *
1836 * One structure is required per host adapter.
1837 *
1838 * Field naming convention:
1839 *
1840 * *_able indicates both whether a feature should be enabled or disabled
1841 * and whether a device isi capable of the feature. At initialization
1842 * this field may be set, but later if a device is found to be incapable
1843 * of the feature, the field is cleared.
1844 */
1845typedef struct adv_dvc_var {
1846 AdvPortAddr iop_base; /* I/O port address */
1847 ushort err_code; /* fatal error code */
1848 ushort bios_ctrl; /* BIOS control word, EEPROM word 12 */
1849 ushort wdtr_able; /* try WDTR for a device */
1850 ushort sdtr_able; /* try SDTR for a device */
1851 ushort ultra_able; /* try SDTR Ultra speed for a device */
1852 ushort sdtr_speed1; /* EEPROM SDTR Speed for TID 0-3 */
1853 ushort sdtr_speed2; /* EEPROM SDTR Speed for TID 4-7 */
1854 ushort sdtr_speed3; /* EEPROM SDTR Speed for TID 8-11 */
1855 ushort sdtr_speed4; /* EEPROM SDTR Speed for TID 12-15 */
1856 ushort tagqng_able; /* try tagged queuing with a device */
1857 ushort ppr_able; /* PPR message capable per TID bitmask. */
1858 uchar max_dvc_qng; /* maximum number of tagged commands per device */
1859 ushort start_motor; /* start motor command allowed */
1860 uchar scsi_reset_wait; /* delay in seconds after scsi bus reset */
1861 uchar chip_no; /* should be assigned by caller */
1862 uchar max_host_qng; /* maximum number of Q'ed command allowed */
1863 ushort no_scam; /* scam_tolerant of EEPROM */
1864 struct asc_board *drv_ptr; /* driver pointer to private structure */
1865 uchar chip_scsi_id; /* chip SCSI target ID */
1866 uchar chip_type;
1867 uchar bist_err_code;
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001868 ADV_CARR_T *carrier;
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001869 ADV_CARR_T *carr_freelist; /* Carrier free list. */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02001870 dma_addr_t carrier_addr;
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001871 ADV_CARR_T *icq_sp; /* Initiator command queue stopper pointer. */
1872 ADV_CARR_T *irq_sp; /* Initiator response queue stopper pointer. */
1873 ushort carr_pending_cnt; /* Count of pending carriers. */
Matthew Wilcox98d41c22007-10-02 21:55:37 -04001874 /*
1875 * Note: The following fields will not be used after initialization. The
1876 * driver may discard the buffer after initialization is done.
1877 */
1878 ADV_DVC_CFG *cfg; /* temporary configuration structure */
1879} ADV_DVC_VAR;
1880
1881/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 * Microcode idle loop commands
1883 */
1884#define IDLE_CMD_COMPLETED 0
1885#define IDLE_CMD_STOP_CHIP 0x0001
1886#define IDLE_CMD_STOP_CHIP_SEND_INT 0x0002
1887#define IDLE_CMD_SEND_INT 0x0004
1888#define IDLE_CMD_ABORT 0x0008
1889#define IDLE_CMD_DEVICE_RESET 0x0010
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001890#define IDLE_CMD_SCSI_RESET_START 0x0020 /* Assert SCSI Bus Reset */
1891#define IDLE_CMD_SCSI_RESET_END 0x0040 /* Deassert SCSI Bus Reset */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892#define IDLE_CMD_SCSIREQ 0x0080
1893
1894#define IDLE_CMD_STATUS_SUCCESS 0x0001
1895#define IDLE_CMD_STATUS_FAILURE 0x0002
1896
1897/*
1898 * AdvSendIdleCmd() flag definitions.
1899 */
1900#define ADV_NOWAIT 0x01
1901
1902/*
1903 * Wait loop time out values.
1904 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001905#define SCSI_WAIT_100_MSEC 100UL /* 100 milliseconds */
1906#define SCSI_US_PER_MSEC 1000 /* microseconds per millisecond */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001907#define SCSI_MAX_RETRY 10 /* retry count */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001909#define ADV_ASYNC_RDMA_FAILURE 0x01 /* Fatal RDMA failure. */
1910#define ADV_ASYNC_SCSI_BUS_RESET_DET 0x02 /* Detected SCSI Bus Reset. */
1911#define ADV_ASYNC_CARRIER_READY_FAILURE 0x03 /* Carrier Ready failure. */
1912#define ADV_RDMA_IN_CARR_AND_Q_INVALID 0x04 /* RDMAed-in data invalid. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913
Matthew Wilcox27c868c2007-07-26 10:56:23 -04001914#define ADV_HOST_SCSI_BUS_RESET 0x80 /* Host Initiated SCSI Bus Reset. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916/* Read byte from a register. */
1917#define AdvReadByteRegister(iop_base, reg_off) \
1918 (ADV_MEM_READB((iop_base) + (reg_off)))
1919
1920/* Write byte to a register. */
1921#define AdvWriteByteRegister(iop_base, reg_off, byte) \
1922 (ADV_MEM_WRITEB((iop_base) + (reg_off), (byte)))
1923
1924/* Read word (2 bytes) from a register. */
1925#define AdvReadWordRegister(iop_base, reg_off) \
1926 (ADV_MEM_READW((iop_base) + (reg_off)))
1927
1928/* Write word (2 bytes) to a register. */
1929#define AdvWriteWordRegister(iop_base, reg_off, word) \
1930 (ADV_MEM_WRITEW((iop_base) + (reg_off), (word)))
1931
1932/* Write dword (4 bytes) to a register. */
1933#define AdvWriteDWordRegister(iop_base, reg_off, dword) \
1934 (ADV_MEM_WRITEDW((iop_base) + (reg_off), (dword)))
1935
1936/* Read byte from LRAM. */
1937#define AdvReadByteLram(iop_base, addr, byte) \
1938do { \
1939 ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
1940 (byte) = ADV_MEM_READB((iop_base) + IOPB_RAM_DATA); \
1941} while (0)
1942
1943/* Write byte to LRAM. */
1944#define AdvWriteByteLram(iop_base, addr, byte) \
1945 (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
1946 ADV_MEM_WRITEB((iop_base) + IOPB_RAM_DATA, (byte)))
1947
1948/* Read word (2 bytes) from LRAM. */
1949#define AdvReadWordLram(iop_base, addr, word) \
1950do { \
1951 ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
1952 (word) = (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA)); \
1953} while (0)
1954
1955/* Write word (2 bytes) to LRAM. */
1956#define AdvWriteWordLram(iop_base, addr, word) \
1957 (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
1958 ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
1959
1960/* Write little-endian double word (4 bytes) to LRAM */
1961/* Because of unspecified C language ordering don't use auto-increment. */
1962#define AdvWriteDWordLramNoSwap(iop_base, addr, dword) \
1963 ((ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
1964 ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
1965 cpu_to_le16((ushort) ((dword) & 0xFFFF)))), \
1966 (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr) + 2), \
1967 ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
1968 cpu_to_le16((ushort) ((dword >> 16) & 0xFFFF)))))
1969
1970/* Read word (2 bytes) from LRAM assuming that the address is already set. */
1971#define AdvReadWordAutoIncLram(iop_base) \
1972 (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA))
1973
1974/* Write word (2 bytes) to LRAM assuming that the address is already set. */
1975#define AdvWriteWordAutoIncLram(iop_base, word) \
1976 (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
1977
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978/*
1979 * Define macro to check for Condor signature.
1980 *
1981 * Evaluate to ADV_TRUE if a Condor chip is found the specified port
1982 * address 'iop_base'. Otherwise evalue to ADV_FALSE.
1983 */
1984#define AdvFindSignature(iop_base) \
1985 (((AdvReadByteRegister((iop_base), IOPB_CHIP_ID_1) == \
1986 ADV_CHIP_ID_BYTE) && \
1987 (AdvReadWordRegister((iop_base), IOPW_CHIP_ID_0) == \
1988 ADV_CHIP_ID_WORD)) ? ADV_TRUE : ADV_FALSE)
1989
1990/*
1991 * Define macro to Return the version number of the chip at 'iop_base'.
1992 *
1993 * The second parameter 'bus_type' is currently unused.
1994 */
1995#define AdvGetChipVersion(iop_base, bus_type) \
1996 AdvReadByteRegister((iop_base), IOPB_CHIP_TYPE_REV)
1997
1998/*
Hannes Reinecke9c17c622015-04-24 13:18:21 +02001999 * Abort an SRB in the chip's RISC Memory. The 'srb_tag' argument must
Hannes Reinecke9fef6ba2015-04-24 13:18:33 +02002000 * match the ADV_SCSI_REQ_Q 'srb_tag' field.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 *
2002 * If the request has not yet been sent to the device it will simply be
2003 * aborted from RISC memory. If the request is disconnected it will be
2004 * aborted on reselection by sending an Abort Message to the target ID.
2005 *
2006 * Return value:
2007 * ADV_TRUE(1) - Queue was successfully aborted.
2008 * ADV_FALSE(0) - Queue was not found on the active queue list.
2009 */
Hannes Reinecke9c17c622015-04-24 13:18:21 +02002010#define AdvAbortQueue(asc_dvc, srb_tag) \
2011 AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_ABORT, \
2012 (ADV_DCNT) (srb_tag))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013
2014/*
2015 * Send a Bus Device Reset Message to the specified target ID.
2016 *
2017 * All outstanding commands will be purged if sending the
2018 * Bus Device Reset Message is successful.
2019 *
2020 * Return Value:
2021 * ADV_TRUE(1) - All requests on the target are purged.
2022 * ADV_FALSE(0) - Couldn't issue Bus Device Reset Message; Requests
2023 * are not purged.
2024 */
2025#define AdvResetDevice(asc_dvc, target_id) \
Hannes Reinecke9c17c622015-04-24 13:18:21 +02002026 AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_DEVICE_RESET, \
2027 (ADV_DCNT) (target_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028
2029/*
2030 * SCSI Wide Type definition.
2031 */
2032#define ADV_SCSI_BIT_ID_TYPE ushort
2033
2034/*
2035 * AdvInitScsiTarget() 'cntl_flag' options.
2036 */
2037#define ADV_SCAN_LUN 0x01
2038#define ADV_CAPINFO_NOLUN 0x02
2039
2040/*
2041 * Convert target id to target id bit mask.
2042 */
2043#define ADV_TID_TO_TIDMASK(tid) (0x01 << ((tid) & ADV_MAX_TID))
2044
2045/*
Hannes Reinecke9fef6ba2015-04-24 13:18:33 +02002046 * ADV_SCSI_REQ_Q 'done_status' and 'host_status' return values.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 */
2048
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002049#define QD_NO_STATUS 0x00 /* Request not completed yet. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050#define QD_NO_ERROR 0x01
2051#define QD_ABORTED_BY_HOST 0x02
2052#define QD_WITH_ERROR 0x04
2053
2054#define QHSTA_NO_ERROR 0x00
2055#define QHSTA_M_SEL_TIMEOUT 0x11
2056#define QHSTA_M_DATA_OVER_RUN 0x12
2057#define QHSTA_M_UNEXPECTED_BUS_FREE 0x13
2058#define QHSTA_M_QUEUE_ABORTED 0x15
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002059#define QHSTA_M_SXFR_SDMA_ERR 0x16 /* SXFR_STATUS SCSI DMA Error */
2060#define QHSTA_M_SXFR_SXFR_PERR 0x17 /* SXFR_STATUS SCSI Bus Parity Error */
2061#define QHSTA_M_RDMA_PERR 0x18 /* RISC PCI DMA parity error */
2062#define QHSTA_M_SXFR_OFF_UFLW 0x19 /* SXFR_STATUS Offset Underflow */
2063#define QHSTA_M_SXFR_OFF_OFLW 0x20 /* SXFR_STATUS Offset Overflow */
2064#define QHSTA_M_SXFR_WD_TMO 0x21 /* SXFR_STATUS Watchdog Timeout */
2065#define QHSTA_M_SXFR_DESELECTED 0x22 /* SXFR_STATUS Deselected */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066/* Note: QHSTA_M_SXFR_XFR_OFLW is identical to QHSTA_M_DATA_OVER_RUN. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002067#define QHSTA_M_SXFR_XFR_OFLW 0x12 /* SXFR_STATUS Transfer Overflow */
2068#define QHSTA_M_SXFR_XFR_PH_ERR 0x24 /* SXFR_STATUS Transfer Phase Error */
2069#define QHSTA_M_SXFR_UNKNOWN_ERROR 0x25 /* SXFR_STATUS Unknown Error */
2070#define QHSTA_M_SCSI_BUS_RESET 0x30 /* Request aborted from SBR */
2071#define QHSTA_M_SCSI_BUS_RESET_UNSOL 0x31 /* Request aborted from unsol. SBR */
2072#define QHSTA_M_BUS_DEVICE_RESET 0x32 /* Request aborted from BDR */
2073#define QHSTA_M_DIRECTION_ERR 0x35 /* Data Phase mismatch */
2074#define QHSTA_M_DIRECTION_ERR_HUNG 0x36 /* Data Phase mismatch and bus hang */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075#define QHSTA_M_WTM_TIMEOUT 0x41
2076#define QHSTA_M_BAD_CMPL_STATUS_IN 0x42
2077#define QHSTA_M_NO_AUTO_REQ_SENSE 0x43
2078#define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002079#define QHSTA_M_INVALID_DEVICE 0x45 /* Bad target ID */
2080#define QHSTA_M_FROZEN_TIDQ 0x46 /* TID Queue frozen. */
2081#define QHSTA_M_SGBACKUP_ERROR 0x47 /* Scatter-Gather backup error */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083/* Return the address that is aligned at the next doubleword >= to 'addr'. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084#define ADV_32BALIGN(addr) (((ulong) (addr) + 0x1F) & ~0x1F)
2085
2086/*
2087 * Total contiguous memory needed for driver SG blocks.
2088 *
2089 * ADV_MAX_SG_LIST must be defined by a driver. It is the maximum
2090 * number of scatter-gather elements the driver supports in a
2091 * single request.
2092 */
2093
2094#define ADV_SG_LIST_MAX_BYTE_SIZE \
2095 (sizeof(ADV_SG_BLOCK) * \
2096 ((ADV_MAX_SG_LIST + (NO_OF_SG_PER_BLOCK - 1))/NO_OF_SG_PER_BLOCK))
2097
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002098/* struct asc_board flags */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002099#define ASC_IS_WIDE_BOARD 0x04 /* AdvanSys Wide Board */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
2101#define ASC_NARROW_BOARD(boardp) (((boardp)->flags & ASC_IS_WIDE_BOARD) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002103#define NO_ISA_DMA 0xff /* No ISA DMA Channel Used */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002105#define ASC_INFO_SIZE 128 /* advansys_info() line size */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107/* Asc Library return codes */
2108#define ASC_TRUE 1
2109#define ASC_FALSE 0
2110#define ASC_NOERROR 1
2111#define ASC_BUSY 0
2112#define ASC_ERROR (-1)
2113
2114/* struct scsi_cmnd function return codes */
2115#define STATUS_BYTE(byte) (byte)
2116#define MSG_BYTE(byte) ((byte) << 8)
2117#define HOST_BYTE(byte) ((byte) << 16)
2118#define DRIVER_BYTE(byte) ((byte) << 24)
2119
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002120#define ASC_STATS(shost, counter) ASC_STATS_ADD(shost, counter, 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121#ifndef ADVANSYS_STATS
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002122#define ASC_STATS_ADD(shost, counter, count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123#else /* ADVANSYS_STATS */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002124#define ASC_STATS_ADD(shost, counter, count) \
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002125 (((struct asc_board *) shost_priv(shost))->asc_stats.counter += (count))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126#endif /* ADVANSYS_STATS */
2127
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128/* If the result wraps when calculating tenths, return 0. */
2129#define ASC_TENTHS(num, den) \
2130 (((10 * ((num)/(den))) > (((num) * 10)/(den))) ? \
2131 0 : ((((num) * 10)/(den)) - (10 * ((num)/(den)))))
2132
2133/*
2134 * Display a message to the console.
2135 */
2136#define ASC_PRINT(s) \
2137 { \
2138 printk("advansys: "); \
2139 printk(s); \
2140 }
2141
2142#define ASC_PRINT1(s, a1) \
2143 { \
2144 printk("advansys: "); \
2145 printk((s), (a1)); \
2146 }
2147
2148#define ASC_PRINT2(s, a1, a2) \
2149 { \
2150 printk("advansys: "); \
2151 printk((s), (a1), (a2)); \
2152 }
2153
2154#define ASC_PRINT3(s, a1, a2, a3) \
2155 { \
2156 printk("advansys: "); \
2157 printk((s), (a1), (a2), (a3)); \
2158 }
2159
2160#define ASC_PRINT4(s, a1, a2, a3, a4) \
2161 { \
2162 printk("advansys: "); \
2163 printk((s), (a1), (a2), (a3), (a4)); \
2164 }
2165
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166#ifndef ADVANSYS_DEBUG
2167
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002168#define ASC_DBG(lvl, s...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169#define ASC_DBG_PRT_SCSI_HOST(lvl, s)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170#define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp)
2171#define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
2172#define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone)
2173#define ADV_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
2174#define ASC_DBG_PRT_HEX(lvl, name, start, length)
2175#define ASC_DBG_PRT_CDB(lvl, cdb, len)
2176#define ASC_DBG_PRT_SENSE(lvl, sense, len)
2177#define ASC_DBG_PRT_INQUIRY(lvl, inq, len)
2178
2179#else /* ADVANSYS_DEBUG */
2180
2181/*
2182 * Debugging Message Levels:
2183 * 0: Errors Only
2184 * 1: High-Level Tracing
2185 * 2-N: Verbose Tracing
2186 */
2187
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002188#define ASC_DBG(lvl, format, arg...) { \
2189 if (asc_dbglvl >= (lvl)) \
2190 printk(KERN_DEBUG "%s: %s: " format, DRV_NAME, \
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07002191 __func__ , ## arg); \
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002192}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193
2194#define ASC_DBG_PRT_SCSI_HOST(lvl, s) \
2195 { \
2196 if (asc_dbglvl >= (lvl)) { \
2197 asc_prt_scsi_host(s); \
2198 } \
2199 }
2200
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201#define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp) \
2202 { \
2203 if (asc_dbglvl >= (lvl)) { \
2204 asc_prt_asc_scsi_q(scsiqp); \
2205 } \
2206 }
2207
2208#define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone) \
2209 { \
2210 if (asc_dbglvl >= (lvl)) { \
2211 asc_prt_asc_qdone_info(qdone); \
2212 } \
2213 }
2214
2215#define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp) \
2216 { \
2217 if (asc_dbglvl >= (lvl)) { \
2218 asc_prt_adv_scsi_req_q(scsiqp); \
2219 } \
2220 }
2221
2222#define ASC_DBG_PRT_HEX(lvl, name, start, length) \
2223 { \
2224 if (asc_dbglvl >= (lvl)) { \
2225 asc_prt_hex((name), (start), (length)); \
2226 } \
2227 }
2228
2229#define ASC_DBG_PRT_CDB(lvl, cdb, len) \
2230 ASC_DBG_PRT_HEX((lvl), "CDB", (uchar *) (cdb), (len));
2231
2232#define ASC_DBG_PRT_SENSE(lvl, sense, len) \
2233 ASC_DBG_PRT_HEX((lvl), "SENSE", (uchar *) (sense), (len));
2234
2235#define ASC_DBG_PRT_INQUIRY(lvl, inq, len) \
2236 ASC_DBG_PRT_HEX((lvl), "INQUIRY", (uchar *) (inq), (len));
2237#endif /* ADVANSYS_DEBUG */
2238
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239#ifdef ADVANSYS_STATS
2240
2241/* Per board statistics structure */
2242struct asc_stats {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002243 /* Driver Entrypoint Statistics */
Hannes Reinecke95cfab62015-04-24 13:18:27 +02002244 unsigned int queuecommand; /* # calls to advansys_queuecommand() */
2245 unsigned int reset; /* # calls to advansys_eh_bus_reset() */
2246 unsigned int biosparam; /* # calls to advansys_biosparam() */
2247 unsigned int interrupt; /* # advansys_interrupt() calls */
2248 unsigned int callback; /* # calls to asc/adv_isr_callback() */
2249 unsigned int done; /* # calls to request's scsi_done function */
2250 unsigned int build_error; /* # asc/adv_build_req() ASC_ERROR returns. */
2251 unsigned int adv_build_noreq; /* # adv_build_req() adv_req_t alloc. fail. */
2252 unsigned int adv_build_nosg; /* # adv_build_req() adv_sgblk_t alloc. fail. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002253 /* AscExeScsiQueue()/AdvExeScsiQueue() Statistics */
Hannes Reinecke95cfab62015-04-24 13:18:27 +02002254 unsigned int exe_noerror; /* # ASC_NOERROR returns. */
2255 unsigned int exe_busy; /* # ASC_BUSY returns. */
2256 unsigned int exe_error; /* # ASC_ERROR returns. */
2257 unsigned int exe_unknown; /* # unknown returns. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002258 /* Data Transfer Statistics */
Hannes Reinecke95cfab62015-04-24 13:18:27 +02002259 unsigned int xfer_cnt; /* # I/O requests received */
2260 unsigned int xfer_elem; /* # scatter-gather elements */
2261 unsigned int xfer_sect; /* # 512-byte blocks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262};
2263#endif /* ADVANSYS_STATS */
2264
2265/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 * Structure allocated for each board.
2267 *
Matthew Wilcox8dfb5372007-07-30 09:08:34 -06002268 * This structure is allocated by scsi_host_alloc() at the end
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 * of the 'Scsi_Host' structure starting at the 'hostdata'
2270 * field. It is guaranteed to be allocated from DMA-able memory.
2271 */
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002272struct asc_board {
Matthew Wilcox394dbf32007-07-26 11:56:40 -04002273 struct device *dev;
Hannes Reinecke9c17c622015-04-24 13:18:21 +02002274 struct Scsi_Host *shost;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002275 uint flags; /* Board flags */
Matthew Wilcoxd361db42007-10-02 21:55:29 -04002276 unsigned int irq;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002277 union {
2278 ASC_DVC_VAR asc_dvc_var; /* Narrow board */
2279 ADV_DVC_VAR adv_dvc_var; /* Wide board */
2280 } dvc_var;
2281 union {
2282 ASC_DVC_CFG asc_dvc_cfg; /* Narrow board */
2283 ADV_DVC_CFG adv_dvc_cfg; /* Wide board */
2284 } dvc_cfg;
2285 ushort asc_n_io_port; /* Number I/O ports. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002286 ADV_SCSI_BIT_ID_TYPE init_tidmask; /* Target init./valid mask */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002287 ushort reqcnt[ADV_MAX_TID + 1]; /* Starvation request count */
2288 ADV_SCSI_BIT_ID_TYPE queue_full; /* Queue full mask */
2289 ushort queue_full_cnt[ADV_MAX_TID + 1]; /* Queue full count */
2290 union {
2291 ASCEEP_CONFIG asc_eep; /* Narrow EEPROM config. */
2292 ADVEEP_3550_CONFIG adv_3550_eep; /* 3550 EEPROM config. */
2293 ADVEEP_38C0800_CONFIG adv_38C0800_eep; /* 38C0800 EEPROM config. */
2294 ADVEEP_38C1600_CONFIG adv_38C1600_eep; /* 38C1600 EEPROM config. */
2295 } eep_config;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002296 /* /proc/scsi/advansys/[0...] */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297#ifdef ADVANSYS_STATS
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002298 struct asc_stats asc_stats; /* Board statistics */
2299#endif /* ADVANSYS_STATS */
2300 /*
2301 * The following fields are used only for Narrow Boards.
2302 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002303 uchar sdtr_data[ASC_MAX_TID + 1]; /* SDTR information */
2304 /*
2305 * The following fields are used only for Wide Boards.
2306 */
2307 void __iomem *ioremap_addr; /* I/O Memory remap address. */
2308 ushort ioport; /* I/O Port address. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002309 adv_req_t *adv_reqp; /* Request structures. */
Hannes Reinecke4b47e462015-04-24 13:18:24 +02002310 dma_addr_t adv_reqp_addr;
2311 size_t adv_reqp_size;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02002312 struct dma_pool *adv_sgblk_pool; /* Scatter-gather structures. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002313 ushort bios_signature; /* BIOS Signature. */
2314 ushort bios_version; /* BIOS Version. */
2315 ushort bios_codeseg; /* BIOS Code Segment. */
2316 ushort bios_codelen; /* BIOS Code Segment Length. */
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002317};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -04002319#define asc_dvc_to_board(asc_dvc) container_of(asc_dvc, struct asc_board, \
2320 dvc_var.asc_dvc_var)
Matthew Wilcox13ac2d92007-07-30 08:10:23 -06002321#define adv_dvc_to_board(adv_dvc) container_of(adv_dvc, struct asc_board, \
2322 dvc_var.adv_dvc_var)
2323#define adv_dvc_to_pdev(adv_dvc) to_pci_dev(adv_dvc_to_board(adv_dvc)->dev)
2324
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325#ifdef ADVANSYS_DEBUG
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002326static int asc_dbglvl = 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328/*
Matthew Wilcox51219352007-10-02 21:55:22 -04002329 * asc_prt_asc_dvc_var()
2330 */
2331static void asc_prt_asc_dvc_var(ASC_DVC_VAR *h)
2332{
2333 printk("ASC_DVC_VAR at addr 0x%lx\n", (ulong)h);
2334
2335 printk(" iop_base 0x%x, err_code 0x%x, dvc_cntl 0x%x, bug_fix_cntl "
2336 "%d,\n", h->iop_base, h->err_code, h->dvc_cntl, h->bug_fix_cntl);
2337
2338 printk(" bus_type %d, init_sdtr 0x%x,\n", h->bus_type,
2339 (unsigned)h->init_sdtr);
2340
2341 printk(" sdtr_done 0x%x, use_tagged_qng 0x%x, unit_not_ready 0x%x, "
2342 "chip_no 0x%x,\n", (unsigned)h->sdtr_done,
2343 (unsigned)h->use_tagged_qng, (unsigned)h->unit_not_ready,
2344 (unsigned)h->chip_no);
2345
2346 printk(" queue_full_or_busy 0x%x, start_motor 0x%x, scsi_reset_wait "
2347 "%u,\n", (unsigned)h->queue_full_or_busy,
2348 (unsigned)h->start_motor, (unsigned)h->scsi_reset_wait);
2349
2350 printk(" is_in_int %u, max_total_qng %u, cur_total_qng %u, "
2351 "in_critical_cnt %u,\n", (unsigned)h->is_in_int,
2352 (unsigned)h->max_total_qng, (unsigned)h->cur_total_qng,
2353 (unsigned)h->in_critical_cnt);
2354
2355 printk(" last_q_shortage %u, init_state 0x%x, no_scam 0x%x, "
2356 "pci_fix_asyn_xfer 0x%x,\n", (unsigned)h->last_q_shortage,
2357 (unsigned)h->init_state, (unsigned)h->no_scam,
2358 (unsigned)h->pci_fix_asyn_xfer);
2359
Matthew Wilcoxd361db42007-10-02 21:55:29 -04002360 printk(" cfg 0x%lx\n", (ulong)h->cfg);
Matthew Wilcox51219352007-10-02 21:55:22 -04002361}
2362
2363/*
2364 * asc_prt_asc_dvc_cfg()
2365 */
2366static void asc_prt_asc_dvc_cfg(ASC_DVC_CFG *h)
2367{
2368 printk("ASC_DVC_CFG at addr 0x%lx\n", (ulong)h);
2369
2370 printk(" can_tagged_qng 0x%x, cmd_qng_enabled 0x%x,\n",
2371 h->can_tagged_qng, h->cmd_qng_enabled);
2372 printk(" disc_enable 0x%x, sdtr_enable 0x%x,\n",
2373 h->disc_enable, h->sdtr_enable);
2374
Matthew Wilcoxb08fc562007-10-02 21:55:32 -04002375 printk(" chip_scsi_id %d, isa_dma_speed %d, isa_dma_channel %d, "
2376 "chip_version %d,\n", h->chip_scsi_id, h->isa_dma_speed,
2377 h->isa_dma_channel, h->chip_version);
Matthew Wilcox51219352007-10-02 21:55:22 -04002378
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -04002379 printk(" mcode_date 0x%x, mcode_version %d\n",
2380 h->mcode_date, h->mcode_version);
Matthew Wilcox51219352007-10-02 21:55:22 -04002381}
2382
2383/*
Matthew Wilcox51219352007-10-02 21:55:22 -04002384 * asc_prt_adv_dvc_var()
2385 *
2386 * Display an ADV_DVC_VAR structure.
2387 */
2388static void asc_prt_adv_dvc_var(ADV_DVC_VAR *h)
2389{
2390 printk(" ADV_DVC_VAR at addr 0x%lx\n", (ulong)h);
2391
2392 printk(" iop_base 0x%lx, err_code 0x%x, ultra_able 0x%x\n",
2393 (ulong)h->iop_base, h->err_code, (unsigned)h->ultra_able);
2394
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002395 printk(" sdtr_able 0x%x, wdtr_able 0x%x\n",
2396 (unsigned)h->sdtr_able, (unsigned)h->wdtr_able);
Matthew Wilcox51219352007-10-02 21:55:22 -04002397
Matthew Wilcoxd361db42007-10-02 21:55:29 -04002398 printk(" start_motor 0x%x, scsi_reset_wait 0x%x\n",
2399 (unsigned)h->start_motor, (unsigned)h->scsi_reset_wait);
Matthew Wilcox51219352007-10-02 21:55:22 -04002400
Hannes Reinecke98b96a72015-04-24 13:18:23 +02002401 printk(" max_host_qng %u, max_dvc_qng %u, carr_freelist 0x%p\n",
Matthew Wilcox51219352007-10-02 21:55:22 -04002402 (unsigned)h->max_host_qng, (unsigned)h->max_dvc_qng,
Hannes Reinecke98b96a72015-04-24 13:18:23 +02002403 h->carr_freelist);
Matthew Wilcox51219352007-10-02 21:55:22 -04002404
Hannes Reinecke98b96a72015-04-24 13:18:23 +02002405 printk(" icq_sp 0x%p, irq_sp 0x%p\n", h->icq_sp, h->irq_sp);
Matthew Wilcox51219352007-10-02 21:55:22 -04002406
2407 printk(" no_scam 0x%x, tagqng_able 0x%x\n",
2408 (unsigned)h->no_scam, (unsigned)h->tagqng_able);
2409
2410 printk(" chip_scsi_id 0x%x, cfg 0x%lx\n",
2411 (unsigned)h->chip_scsi_id, (ulong)h->cfg);
2412}
2413
2414/*
2415 * asc_prt_adv_dvc_cfg()
2416 *
2417 * Display an ADV_DVC_CFG structure.
2418 */
2419static void asc_prt_adv_dvc_cfg(ADV_DVC_CFG *h)
2420{
2421 printk(" ADV_DVC_CFG at addr 0x%lx\n", (ulong)h);
2422
2423 printk(" disc_enable 0x%x, termination 0x%x\n",
2424 h->disc_enable, h->termination);
2425
2426 printk(" chip_version 0x%x, mcode_date 0x%x\n",
2427 h->chip_version, h->mcode_date);
2428
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002429 printk(" mcode_version 0x%x, control_flag 0x%x\n",
2430 h->mcode_version, h->control_flag);
Matthew Wilcox51219352007-10-02 21:55:22 -04002431}
2432
2433/*
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002434 * asc_prt_scsi_host()
Matthew Wilcox51219352007-10-02 21:55:22 -04002435 */
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002436static void asc_prt_scsi_host(struct Scsi_Host *s)
Matthew Wilcox51219352007-10-02 21:55:22 -04002437{
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002438 struct asc_board *boardp = shost_priv(s);
Matthew Wilcox51219352007-10-02 21:55:22 -04002439
Kay Sievers71610f52008-12-03 22:41:36 +01002440 printk("Scsi_Host at addr 0x%p, device %s\n", s, dev_name(boardp->dev));
Hannes Reinecke50d14a72013-10-23 10:51:17 +02002441 printk(" host_busy %u, host_no %d,\n",
Christoph Hellwig74665012014-01-22 15:29:29 +01002442 atomic_read(&s->host_busy), s->host_no);
Matthew Wilcox51219352007-10-02 21:55:22 -04002443
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002444 printk(" base 0x%lx, io_port 0x%lx, irq %d,\n",
2445 (ulong)s->base, (ulong)s->io_port, boardp->irq);
Matthew Wilcox51219352007-10-02 21:55:22 -04002446
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002447 printk(" dma_channel %d, this_id %d, can_queue %d,\n",
2448 s->dma_channel, s->this_id, s->can_queue);
Matthew Wilcox51219352007-10-02 21:55:22 -04002449
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002450 printk(" cmd_per_lun %d, sg_tablesize %d, unchecked_isa_dma %d\n",
2451 s->cmd_per_lun, s->sg_tablesize, s->unchecked_isa_dma);
Matthew Wilcox51219352007-10-02 21:55:22 -04002452
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002453 if (ASC_NARROW_BOARD(boardp)) {
2454 asc_prt_asc_dvc_var(&boardp->dvc_var.asc_dvc_var);
2455 asc_prt_asc_dvc_cfg(&boardp->dvc_cfg.asc_dvc_cfg);
2456 } else {
2457 asc_prt_adv_dvc_var(&boardp->dvc_var.adv_dvc_var);
2458 asc_prt_adv_dvc_cfg(&boardp->dvc_cfg.adv_dvc_cfg);
Matthew Wilcox51219352007-10-02 21:55:22 -04002459 }
2460}
2461
2462/*
2463 * asc_prt_hex()
2464 *
2465 * Print hexadecimal output in 4 byte groupings 32 bytes
2466 * or 8 double-words per line.
2467 */
2468static void asc_prt_hex(char *f, uchar *s, int l)
2469{
2470 int i;
2471 int j;
2472 int k;
2473 int m;
2474
2475 printk("%s: (%d bytes)\n", f, l);
2476
2477 for (i = 0; i < l; i += 32) {
2478
2479 /* Display a maximum of 8 double-words per line. */
2480 if ((k = (l - i) / 4) >= 8) {
2481 k = 8;
2482 m = 0;
2483 } else {
2484 m = (l - i) % 4;
2485 }
2486
2487 for (j = 0; j < k; j++) {
2488 printk(" %2.2X%2.2X%2.2X%2.2X",
2489 (unsigned)s[i + (j * 4)],
2490 (unsigned)s[i + (j * 4) + 1],
2491 (unsigned)s[i + (j * 4) + 2],
2492 (unsigned)s[i + (j * 4) + 3]);
2493 }
2494
2495 switch (m) {
2496 case 0:
2497 default:
2498 break;
2499 case 1:
2500 printk(" %2.2X", (unsigned)s[i + (j * 4)]);
2501 break;
2502 case 2:
2503 printk(" %2.2X%2.2X",
2504 (unsigned)s[i + (j * 4)],
2505 (unsigned)s[i + (j * 4) + 1]);
2506 break;
2507 case 3:
2508 printk(" %2.2X%2.2X%2.2X",
2509 (unsigned)s[i + (j * 4) + 1],
2510 (unsigned)s[i + (j * 4) + 2],
2511 (unsigned)s[i + (j * 4) + 3]);
2512 break;
2513 }
2514
2515 printk("\n");
2516 }
2517}
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002518
2519/*
2520 * asc_prt_asc_scsi_q()
2521 */
2522static void asc_prt_asc_scsi_q(ASC_SCSI_Q *q)
2523{
2524 ASC_SG_HEAD *sgp;
2525 int i;
2526
2527 printk("ASC_SCSI_Q at addr 0x%lx\n", (ulong)q);
2528
2529 printk
Hannes Reinecke9c17c622015-04-24 13:18:21 +02002530 (" target_ix 0x%x, target_lun %u, srb_tag 0x%x, tag_code 0x%x,\n",
2531 q->q2.target_ix, q->q1.target_lun, q->q2.srb_tag,
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002532 q->q2.tag_code);
2533
2534 printk
2535 (" data_addr 0x%lx, data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
2536 (ulong)le32_to_cpu(q->q1.data_addr),
2537 (ulong)le32_to_cpu(q->q1.data_cnt),
2538 (ulong)le32_to_cpu(q->q1.sense_addr), q->q1.sense_len);
2539
2540 printk(" cdbptr 0x%lx, cdb_len %u, sg_head 0x%lx, sg_queue_cnt %u\n",
2541 (ulong)q->cdbptr, q->q2.cdb_len,
2542 (ulong)q->sg_head, q->q1.sg_queue_cnt);
2543
2544 if (q->sg_head) {
2545 sgp = q->sg_head;
2546 printk("ASC_SG_HEAD at addr 0x%lx\n", (ulong)sgp);
2547 printk(" entry_cnt %u, queue_cnt %u\n", sgp->entry_cnt,
2548 sgp->queue_cnt);
2549 for (i = 0; i < sgp->entry_cnt; i++) {
2550 printk(" [%u]: addr 0x%lx, bytes %lu\n",
2551 i, (ulong)le32_to_cpu(sgp->sg_list[i].addr),
2552 (ulong)le32_to_cpu(sgp->sg_list[i].bytes));
2553 }
2554
2555 }
2556}
2557
2558/*
2559 * asc_prt_asc_qdone_info()
2560 */
2561static void asc_prt_asc_qdone_info(ASC_QDONE_INFO *q)
2562{
2563 printk("ASC_QDONE_INFO at addr 0x%lx\n", (ulong)q);
Hannes Reinecke9c17c622015-04-24 13:18:21 +02002564 printk(" srb_tag 0x%x, target_ix %u, cdb_len %u, tag_code %u,\n",
2565 q->d2.srb_tag, q->d2.target_ix, q->d2.cdb_len,
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002566 q->d2.tag_code);
2567 printk
2568 (" done_stat 0x%x, host_stat 0x%x, scsi_stat 0x%x, scsi_msg 0x%x\n",
2569 q->d3.done_stat, q->d3.host_stat, q->d3.scsi_stat, q->d3.scsi_msg);
2570}
2571
2572/*
2573 * asc_prt_adv_sgblock()
2574 *
2575 * Display an ADV_SG_BLOCK structure.
2576 */
2577static void asc_prt_adv_sgblock(int sgblockno, ADV_SG_BLOCK *b)
2578{
2579 int i;
2580
Hannes Reinecke0ce53822015-04-24 13:18:25 +02002581 printk(" ADV_SG_BLOCK at addr 0x%lx (sgblockno %d)\n",
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002582 (ulong)b, sgblockno);
Hannes Reinecked9748db2015-04-24 13:18:36 +02002583 printk(" sg_cnt %u, sg_ptr 0x%x\n",
2584 b->sg_cnt, (u32)le32_to_cpu(b->sg_ptr));
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002585 BUG_ON(b->sg_cnt > NO_OF_SG_PER_BLOCK);
2586 if (b->sg_ptr != 0)
2587 BUG_ON(b->sg_cnt != NO_OF_SG_PER_BLOCK);
2588 for (i = 0; i < b->sg_cnt; i++) {
Hannes Reinecked9748db2015-04-24 13:18:36 +02002589 printk(" [%u]: sg_addr 0x%x, sg_count 0x%x\n",
2590 i, (u32)le32_to_cpu(b->sg_list[i].sg_addr),
2591 (u32)le32_to_cpu(b->sg_list[i].sg_count));
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002592 }
2593}
2594
2595/*
2596 * asc_prt_adv_scsi_req_q()
2597 *
2598 * Display an ADV_SCSI_REQ_Q structure.
2599 */
2600static void asc_prt_adv_scsi_req_q(ADV_SCSI_REQ_Q *q)
2601{
2602 int sg_blk_cnt;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02002603 struct adv_sg_block *sg_ptr;
2604 adv_sgblk_t *sgblkp;
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002605
2606 printk("ADV_SCSI_REQ_Q at addr 0x%lx\n", (ulong)q);
2607
Hannes Reinecked9748db2015-04-24 13:18:36 +02002608 printk(" target_id %u, target_lun %u, srb_tag 0x%x\n",
2609 q->target_id, q->target_lun, q->srb_tag);
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002610
Hannes Reinecke98b96a72015-04-24 13:18:23 +02002611 printk(" cntl 0x%x, data_addr 0x%lx\n",
2612 q->cntl, (ulong)le32_to_cpu(q->data_addr));
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002613
2614 printk(" data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
2615 (ulong)le32_to_cpu(q->data_cnt),
2616 (ulong)le32_to_cpu(q->sense_addr), q->sense_len);
2617
2618 printk
2619 (" cdb_len %u, done_status 0x%x, host_status 0x%x, scsi_status 0x%x\n",
2620 q->cdb_len, q->done_status, q->host_status, q->scsi_status);
2621
2622 printk(" sg_working_ix 0x%x, target_cmd %u\n",
2623 q->sg_working_ix, q->target_cmd);
2624
2625 printk(" scsiq_rptr 0x%lx, sg_real_addr 0x%lx, sg_list_ptr 0x%lx\n",
2626 (ulong)le32_to_cpu(q->scsiq_rptr),
2627 (ulong)le32_to_cpu(q->sg_real_addr), (ulong)q->sg_list_ptr);
2628
2629 /* Display the request's ADV_SG_BLOCK structures. */
2630 if (q->sg_list_ptr != NULL) {
Hannes Reinecke0ce53822015-04-24 13:18:25 +02002631 sgblkp = container_of(q->sg_list_ptr, adv_sgblk_t, sg_block);
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002632 sg_blk_cnt = 0;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02002633 while (sgblkp) {
2634 sg_ptr = &sgblkp->sg_block;
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002635 asc_prt_adv_sgblock(sg_blk_cnt, sg_ptr);
2636 if (sg_ptr->sg_ptr == 0) {
2637 break;
2638 }
Hannes Reinecke0ce53822015-04-24 13:18:25 +02002639 sgblkp = sgblkp->next_sgblkp;
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002640 sg_blk_cnt++;
2641 }
2642 }
2643}
Matthew Wilcox51219352007-10-02 21:55:22 -04002644#endif /* ADVANSYS_DEBUG */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645
2646/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 * advansys_info()
2648 *
2649 * Return suitable for printing on the console with the argument
2650 * adapter's configuration information.
2651 *
2652 * Note: The information line should not exceed ASC_INFO_SIZE bytes,
2653 * otherwise the static 'info' array will be overrun.
2654 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002655static const char *advansys_info(struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656{
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002657 static char info[ASC_INFO_SIZE];
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002658 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002659 ASC_DVC_VAR *asc_dvc_varp;
2660 ADV_DVC_VAR *adv_dvc_varp;
2661 char *busname;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002662 char *widename = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002664 if (ASC_NARROW_BOARD(boardp)) {
2665 asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002666 ASC_DBG(1, "begin\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002667 if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
2668 if ((asc_dvc_varp->bus_type & ASC_IS_ISAPNP) ==
2669 ASC_IS_ISAPNP) {
2670 busname = "ISA PnP";
2671 } else {
2672 busname = "ISA";
2673 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002674 sprintf(info,
2675 "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X, DMA 0x%X",
2676 ASC_VERSION, busname,
2677 (ulong)shost->io_port,
Matthew Wilcox4a2d31c2007-07-26 11:55:34 -04002678 (ulong)shost->io_port + ASC_IOADR_GAP - 1,
Matthew Wilcoxd361db42007-10-02 21:55:29 -04002679 boardp->irq, shost->dma_channel);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002680 } else {
2681 if (asc_dvc_varp->bus_type & ASC_IS_VL) {
2682 busname = "VL";
2683 } else if (asc_dvc_varp->bus_type & ASC_IS_EISA) {
2684 busname = "EISA";
2685 } else if (asc_dvc_varp->bus_type & ASC_IS_PCI) {
2686 if ((asc_dvc_varp->bus_type & ASC_IS_PCI_ULTRA)
2687 == ASC_IS_PCI_ULTRA) {
2688 busname = "PCI Ultra";
2689 } else {
2690 busname = "PCI";
2691 }
2692 } else {
2693 busname = "?";
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04002694 shost_printk(KERN_ERR, shost, "unknown bus "
2695 "type %d\n", asc_dvc_varp->bus_type);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002696 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002697 sprintf(info,
2698 "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X",
Matthew Wilcoxecec1942007-07-30 08:08:22 -06002699 ASC_VERSION, busname, (ulong)shost->io_port,
Matthew Wilcox4a2d31c2007-07-26 11:55:34 -04002700 (ulong)shost->io_port + ASC_IOADR_GAP - 1,
Matthew Wilcoxd361db42007-10-02 21:55:29 -04002701 boardp->irq);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002702 }
2703 } else {
2704 /*
2705 * Wide Adapter Information
2706 *
2707 * Memory-mapped I/O is used instead of I/O space to access
2708 * the adapter, but display the I/O Port range. The Memory
2709 * I/O address is displayed through the driver /proc file.
2710 */
2711 adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
2712 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002713 widename = "Ultra-Wide";
2714 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002715 widename = "Ultra2-Wide";
2716 } else {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002717 widename = "Ultra3-Wide";
2718 }
2719 sprintf(info,
2720 "AdvanSys SCSI %s: PCI %s: PCIMEM 0x%lX-0x%lX, IRQ 0x%X",
2721 ASC_VERSION, widename, (ulong)adv_dvc_varp->iop_base,
Matthew Wilcoxd361db42007-10-02 21:55:29 -04002722 (ulong)adv_dvc_varp->iop_base + boardp->asc_n_io_port - 1, boardp->irq);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002723 }
Matthew Wilcoxb009bef2007-09-09 08:56:38 -06002724 BUG_ON(strlen(info) >= ASC_INFO_SIZE);
Matthew Wilcoxb352f922007-10-02 21:55:33 -04002725 ASC_DBG(1, "end\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002726 return info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727}
2728
Matthew Wilcox51219352007-10-02 21:55:22 -04002729#ifdef CONFIG_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730
2731/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 * asc_prt_board_devices()
2733 *
2734 * Print driver information for devices attached to the board.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735 */
Al Virob59fb6f2013-03-31 02:59:55 -04002736static void asc_prt_board_devices(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002738 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002739 int chip_scsi_id;
2740 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741
Al Virob59fb6f2013-03-31 02:59:55 -04002742 seq_printf(m,
2743 "\nDevice Information for AdvanSys SCSI Host %d:\n",
2744 shost->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002746 if (ASC_NARROW_BOARD(boardp)) {
2747 chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
2748 } else {
2749 chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
2750 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751
Rasmus Villemoes2f979422014-12-03 00:10:50 +01002752 seq_puts(m, "Target IDs Detected:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002753 for (i = 0; i <= ADV_MAX_TID; i++) {
Al Virob59fb6f2013-03-31 02:59:55 -04002754 if (boardp->init_tidmask & ADV_TID_TO_TIDMASK(i))
2755 seq_printf(m, " %X,", i);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002756 }
Al Virob59fb6f2013-03-31 02:59:55 -04002757 seq_printf(m, " (%X=Host Adapter)\n", chip_scsi_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758}
2759
2760/*
2761 * Display Wide Board BIOS Information.
2762 */
Al Virob59fb6f2013-03-31 02:59:55 -04002763static void asc_prt_adv_bios(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002765 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002766 ushort major, minor, letter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767
Rasmus Villemoes2f979422014-12-03 00:10:50 +01002768 seq_puts(m, "\nROM BIOS Version: ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002770 /*
2771 * If the BIOS saved a valid signature, then fill in
2772 * the BIOS code segment base address.
2773 */
2774 if (boardp->bios_signature != 0x55AA) {
Rasmus Villemoes3d300792014-12-03 00:10:53 +01002775 seq_puts(m, "Disabled or Pre-3.1\n"
2776 "BIOS either disabled or Pre-3.1. If it is pre-3.1, then a newer version\n"
2777 "can be found at the ConnectCom FTP site: ftp://ftp.connectcom.net/pub\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002778 } else {
2779 major = (boardp->bios_version >> 12) & 0xF;
2780 minor = (boardp->bios_version >> 8) & 0xF;
2781 letter = (boardp->bios_version & 0xFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782
Al Virob59fb6f2013-03-31 02:59:55 -04002783 seq_printf(m, "%d.%d%c\n",
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002784 major, minor,
2785 letter >= 26 ? '?' : letter + 'A');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002786 /*
2787 * Current available ROM BIOS release is 3.1I for UW
2788 * and 3.2I for U2W. This code doesn't differentiate
2789 * UW and U2W boards.
2790 */
2791 if (major < 3 || (major <= 3 && minor < 1) ||
2792 (major <= 3 && minor <= 1 && letter < ('I' - 'A'))) {
Rasmus Villemoes3d300792014-12-03 00:10:53 +01002793 seq_puts(m, "Newer version of ROM BIOS is available at the ConnectCom FTP site:\n"
2794 "ftp://ftp.connectcom.net/pub\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002795 }
2796 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797}
2798
2799/*
2800 * Add serial number to information bar if signature AAh
2801 * is found in at bit 15-9 (7 bits) of word 1.
2802 *
2803 * Serial Number consists fo 12 alpha-numeric digits.
2804 *
2805 * 1 - Product type (A,B,C,D..) Word0: 15-13 (3 bits)
2806 * 2 - MFG Location (A,B,C,D..) Word0: 12-10 (3 bits)
2807 * 3-4 - Product ID (0-99) Word0: 9-0 (10 bits)
2808 * 5 - Product revision (A-J) Word0: " "
2809 *
2810 * Signature Word1: 15-9 (7 bits)
2811 * 6 - Year (0-9) Word1: 8-6 (3 bits) & Word2: 15 (1 bit)
2812 * 7-8 - Week of the year (1-52) Word1: 5-0 (6 bits)
2813 *
2814 * 9-12 - Serial Number (A001-Z999) Word2: 14-0 (15 bits)
2815 *
2816 * Note 1: Only production cards will have a serial number.
2817 *
2818 * Note 2: Signature is most significant 7 bits (0xFE).
2819 *
2820 * Returns ASC_TRUE if serial number found, otherwise returns ASC_FALSE.
2821 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002822static int asc_get_eeprom_string(ushort *serialnum, uchar *cp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823{
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002824 ushort w, num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002826 if ((serialnum[1] & 0xFE00) != ((ushort)0xAA << 8)) {
2827 return ASC_FALSE;
2828 } else {
2829 /*
2830 * First word - 6 digits.
2831 */
2832 w = serialnum[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002834 /* Product type - 1st digit. */
2835 if ((*cp = 'A' + ((w & 0xE000) >> 13)) == 'H') {
2836 /* Product type is P=Prototype */
2837 *cp += 0x8;
2838 }
2839 cp++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002841 /* Manufacturing location - 2nd digit. */
2842 *cp++ = 'A' + ((w & 0x1C00) >> 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002844 /* Product ID - 3rd, 4th digits. */
2845 num = w & 0x3FF;
2846 *cp++ = '0' + (num / 100);
2847 num %= 100;
2848 *cp++ = '0' + (num / 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002850 /* Product revision - 5th digit. */
2851 *cp++ = 'A' + (num % 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002853 /*
2854 * Second word
2855 */
2856 w = serialnum[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002858 /*
2859 * Year - 6th digit.
2860 *
2861 * If bit 15 of third word is set, then the
2862 * last digit of the year is greater than 7.
2863 */
2864 if (serialnum[2] & 0x8000) {
2865 *cp++ = '8' + ((w & 0x1C0) >> 6);
2866 } else {
2867 *cp++ = '0' + ((w & 0x1C0) >> 6);
2868 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002870 /* Week of year - 7th, 8th digits. */
2871 num = w & 0x003F;
2872 *cp++ = '0' + num / 10;
2873 num %= 10;
2874 *cp++ = '0' + num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002876 /*
2877 * Third word
2878 */
2879 w = serialnum[2] & 0x7FFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002881 /* Serial number - 9th digit. */
2882 *cp++ = 'A' + (w / 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002884 /* 10th, 11th, 12th digits. */
2885 num = w % 1000;
2886 *cp++ = '0' + num / 100;
2887 num %= 100;
2888 *cp++ = '0' + num / 10;
2889 num %= 10;
2890 *cp++ = '0' + num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002892 *cp = '\0'; /* Null Terminate the string. */
2893 return ASC_TRUE;
2894 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895}
2896
2897/*
2898 * asc_prt_asc_board_eeprom()
2899 *
2900 * Print board EEPROM configuration.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 */
Al Virob59fb6f2013-03-31 02:59:55 -04002902static void asc_prt_asc_board_eeprom(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002904 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002905 ASC_DVC_VAR *asc_dvc_varp;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002906 ASCEEP_CONFIG *ep;
2907 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908#ifdef CONFIG_ISA
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002909 int isa_dma_speed[] = { 10, 8, 7, 6, 5, 4, 3, 2 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910#endif /* CONFIG_ISA */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002911 uchar serialstr[13];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002913 asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
2914 ep = &boardp->eep_config.asc_eep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915
Al Virob59fb6f2013-03-31 02:59:55 -04002916 seq_printf(m,
2917 "\nEEPROM Settings for AdvanSys SCSI Host %d:\n",
2918 shost->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002920 if (asc_get_eeprom_string((ushort *)&ep->adapter_info[0], serialstr)
Al Virob59fb6f2013-03-31 02:59:55 -04002921 == ASC_TRUE)
2922 seq_printf(m, " Serial Number: %s\n", serialstr);
2923 else if (ep->adapter_info[5] == 0xBB)
Rasmus Villemoes2f979422014-12-03 00:10:50 +01002924 seq_puts(m,
2925 " Default Settings Used for EEPROM-less Adapter.\n");
Al Virob59fb6f2013-03-31 02:59:55 -04002926 else
Rasmus Villemoes2f979422014-12-03 00:10:50 +01002927 seq_puts(m, " Serial Number Signature Not Present.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928
Al Virob59fb6f2013-03-31 02:59:55 -04002929 seq_printf(m,
2930 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
2931 ASC_EEP_GET_CHIP_ID(ep), ep->max_total_qng,
2932 ep->max_tag_qng);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933
Al Virob59fb6f2013-03-31 02:59:55 -04002934 seq_printf(m,
2935 " cntl 0x%x, no_scam 0x%x\n", ep->cntl, ep->no_scam);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936
Rasmus Villemoes2f979422014-12-03 00:10:50 +01002937 seq_puts(m, " Target ID: ");
Al Virob59fb6f2013-03-31 02:59:55 -04002938 for (i = 0; i <= ASC_MAX_TID; i++)
2939 seq_printf(m, " %d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940
Rasmus Villemoes3d300792014-12-03 00:10:53 +01002941 seq_puts(m, "\n Disconnects: ");
Al Virob59fb6f2013-03-31 02:59:55 -04002942 for (i = 0; i <= ASC_MAX_TID; i++)
2943 seq_printf(m, " %c",
2944 (ep->disc_enable & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945
Rasmus Villemoes3d300792014-12-03 00:10:53 +01002946 seq_puts(m, "\n Command Queuing: ");
Al Virob59fb6f2013-03-31 02:59:55 -04002947 for (i = 0; i <= ASC_MAX_TID; i++)
2948 seq_printf(m, " %c",
2949 (ep->use_cmd_qng & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950
Rasmus Villemoes3d300792014-12-03 00:10:53 +01002951 seq_puts(m, "\n Start Motor: ");
Al Virob59fb6f2013-03-31 02:59:55 -04002952 for (i = 0; i <= ASC_MAX_TID; i++)
2953 seq_printf(m, " %c",
2954 (ep->start_motor & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955
Rasmus Villemoes3d300792014-12-03 00:10:53 +01002956 seq_puts(m, "\n Synchronous Transfer:");
Al Virob59fb6f2013-03-31 02:59:55 -04002957 for (i = 0; i <= ASC_MAX_TID; i++)
2958 seq_printf(m, " %c",
2959 (ep->init_sdtr & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01002960 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961
2962#ifdef CONFIG_ISA
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002963 if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
Al Virob59fb6f2013-03-31 02:59:55 -04002964 seq_printf(m,
2965 " Host ISA DMA speed: %d MB/S\n",
2966 isa_dma_speed[ASC_EEP_GET_DMA_SPD(ep)]);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002967 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968#endif /* CONFIG_ISA */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969}
2970
2971/*
2972 * asc_prt_adv_board_eeprom()
2973 *
2974 * Print board EEPROM configuration.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 */
Al Virob59fb6f2013-03-31 02:59:55 -04002976static void asc_prt_adv_board_eeprom(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04002978 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002979 ADV_DVC_VAR *adv_dvc_varp;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002980 int i;
2981 char *termstr;
2982 uchar serialstr[13];
2983 ADVEEP_3550_CONFIG *ep_3550 = NULL;
2984 ADVEEP_38C0800_CONFIG *ep_38C0800 = NULL;
2985 ADVEEP_38C1600_CONFIG *ep_38C1600 = NULL;
2986 ushort word;
2987 ushort *wordp;
2988 ushort sdtr_speed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989
Matthew Wilcox27c868c2007-07-26 10:56:23 -04002990 adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
2991 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
2992 ep_3550 = &boardp->eep_config.adv_3550_eep;
2993 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
2994 ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
2995 } else {
2996 ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
2997 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998
Al Virob59fb6f2013-03-31 02:59:55 -04002999 seq_printf(m,
3000 "\nEEPROM Settings for AdvanSys SCSI Host %d:\n",
3001 shost->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003003 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
3004 wordp = &ep_3550->serial_number_word1;
3005 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
3006 wordp = &ep_38C0800->serial_number_word1;
3007 } else {
3008 wordp = &ep_38C1600->serial_number_word1;
3009 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010
Al Virob59fb6f2013-03-31 02:59:55 -04003011 if (asc_get_eeprom_string(wordp, serialstr) == ASC_TRUE)
3012 seq_printf(m, " Serial Number: %s\n", serialstr);
3013 else
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003014 seq_puts(m, " Serial Number Signature Not Present.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015
Al Virob59fb6f2013-03-31 02:59:55 -04003016 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
3017 seq_printf(m,
3018 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
3019 ep_3550->adapter_scsi_id,
3020 ep_3550->max_host_qng, ep_3550->max_dvc_qng);
3021 else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
3022 seq_printf(m,
3023 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
3024 ep_38C0800->adapter_scsi_id,
3025 ep_38C0800->max_host_qng,
3026 ep_38C0800->max_dvc_qng);
3027 else
3028 seq_printf(m,
3029 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
3030 ep_38C1600->adapter_scsi_id,
3031 ep_38C1600->max_host_qng,
3032 ep_38C1600->max_dvc_qng);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003033 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
3034 word = ep_3550->termination;
3035 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
3036 word = ep_38C0800->termination_lvd;
3037 } else {
3038 word = ep_38C1600->termination_lvd;
3039 }
3040 switch (word) {
3041 case 1:
3042 termstr = "Low Off/High Off";
3043 break;
3044 case 2:
3045 termstr = "Low Off/High On";
3046 break;
3047 case 3:
3048 termstr = "Low On/High On";
3049 break;
3050 default:
3051 case 0:
3052 termstr = "Automatic";
3053 break;
3054 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055
Al Virob59fb6f2013-03-31 02:59:55 -04003056 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
3057 seq_printf(m,
3058 " termination: %u (%s), bios_ctrl: 0x%x\n",
3059 ep_3550->termination, termstr,
3060 ep_3550->bios_ctrl);
3061 else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
3062 seq_printf(m,
3063 " termination: %u (%s), bios_ctrl: 0x%x\n",
3064 ep_38C0800->termination_lvd, termstr,
3065 ep_38C0800->bios_ctrl);
3066 else
3067 seq_printf(m,
3068 " termination: %u (%s), bios_ctrl: 0x%x\n",
3069 ep_38C1600->termination_lvd, termstr,
3070 ep_38C1600->bios_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003072 seq_puts(m, " Target ID: ");
Al Virob59fb6f2013-03-31 02:59:55 -04003073 for (i = 0; i <= ADV_MAX_TID; i++)
3074 seq_printf(m, " %X", i);
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003075 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003077 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
3078 word = ep_3550->disc_enable;
3079 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
3080 word = ep_38C0800->disc_enable;
3081 } else {
3082 word = ep_38C1600->disc_enable;
3083 }
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003084 seq_puts(m, " Disconnects: ");
Al Virob59fb6f2013-03-31 02:59:55 -04003085 for (i = 0; i <= ADV_MAX_TID; i++)
3086 seq_printf(m, " %c",
3087 (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003088 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003090 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
3091 word = ep_3550->tagqng_able;
3092 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
3093 word = ep_38C0800->tagqng_able;
3094 } else {
3095 word = ep_38C1600->tagqng_able;
3096 }
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003097 seq_puts(m, " Command Queuing: ");
Al Virob59fb6f2013-03-31 02:59:55 -04003098 for (i = 0; i <= ADV_MAX_TID; i++)
3099 seq_printf(m, " %c",
3100 (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003101 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003103 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
3104 word = ep_3550->start_motor;
3105 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
3106 word = ep_38C0800->start_motor;
3107 } else {
3108 word = ep_38C1600->start_motor;
3109 }
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003110 seq_puts(m, " Start Motor: ");
Al Virob59fb6f2013-03-31 02:59:55 -04003111 for (i = 0; i <= ADV_MAX_TID; i++)
3112 seq_printf(m, " %c",
3113 (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003114 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003116 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003117 seq_puts(m, " Synchronous Transfer:");
Al Virob59fb6f2013-03-31 02:59:55 -04003118 for (i = 0; i <= ADV_MAX_TID; i++)
3119 seq_printf(m, " %c",
3120 (ep_3550->sdtr_able & ADV_TID_TO_TIDMASK(i)) ?
3121 'Y' : 'N');
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003122 seq_putc(m, '\n');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003123 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003125 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003126 seq_puts(m, " Ultra Transfer: ");
Al Virob59fb6f2013-03-31 02:59:55 -04003127 for (i = 0; i <= ADV_MAX_TID; i++)
3128 seq_printf(m, " %c",
3129 (ep_3550->ultra_able & ADV_TID_TO_TIDMASK(i))
3130 ? 'Y' : 'N');
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003131 seq_putc(m, '\n');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003132 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003134 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
3135 word = ep_3550->wdtr_able;
3136 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
3137 word = ep_38C0800->wdtr_able;
3138 } else {
3139 word = ep_38C1600->wdtr_able;
3140 }
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003141 seq_puts(m, " Wide Transfer: ");
Al Virob59fb6f2013-03-31 02:59:55 -04003142 for (i = 0; i <= ADV_MAX_TID; i++)
3143 seq_printf(m, " %c",
3144 (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003145 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003147 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800 ||
3148 adv_dvc_varp->chip_type == ADV_CHIP_ASC38C1600) {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003149 seq_puts(m, " Synchronous Transfer Speed (Mhz):\n ");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003150 for (i = 0; i <= ADV_MAX_TID; i++) {
3151 char *speed_str;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003153 if (i == 0) {
3154 sdtr_speed = adv_dvc_varp->sdtr_speed1;
3155 } else if (i == 4) {
3156 sdtr_speed = adv_dvc_varp->sdtr_speed2;
3157 } else if (i == 8) {
3158 sdtr_speed = adv_dvc_varp->sdtr_speed3;
3159 } else if (i == 12) {
3160 sdtr_speed = adv_dvc_varp->sdtr_speed4;
3161 }
3162 switch (sdtr_speed & ADV_MAX_TID) {
3163 case 0:
3164 speed_str = "Off";
3165 break;
3166 case 1:
3167 speed_str = " 5";
3168 break;
3169 case 2:
3170 speed_str = " 10";
3171 break;
3172 case 3:
3173 speed_str = " 20";
3174 break;
3175 case 4:
3176 speed_str = " 40";
3177 break;
3178 case 5:
3179 speed_str = " 80";
3180 break;
3181 default:
3182 speed_str = "Unk";
3183 break;
3184 }
Al Virob59fb6f2013-03-31 02:59:55 -04003185 seq_printf(m, "%X:%s ", i, speed_str);
3186 if (i == 7)
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003187 seq_puts(m, "\n ");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003188 sdtr_speed >>= 4;
3189 }
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003190 seq_putc(m, '\n');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003191 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192}
3193
3194/*
3195 * asc_prt_driver_conf()
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 */
Al Virob59fb6f2013-03-31 02:59:55 -04003197static void asc_prt_driver_conf(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04003199 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003200 int chip_scsi_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201
Al Virob59fb6f2013-03-31 02:59:55 -04003202 seq_printf(m,
3203 "\nLinux Driver Configuration and Information for AdvanSys SCSI Host %d:\n",
3204 shost->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205
Al Virob59fb6f2013-03-31 02:59:55 -04003206 seq_printf(m,
Hannes Reinecke1abf6352014-06-25 15:27:38 +02003207 " host_busy %u, max_id %u, max_lun %llu, max_channel %u\n",
Christoph Hellwig74665012014-01-22 15:29:29 +01003208 atomic_read(&shost->host_busy), shost->max_id,
Al Virob59fb6f2013-03-31 02:59:55 -04003209 shost->max_lun, shost->max_channel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210
Al Virob59fb6f2013-03-31 02:59:55 -04003211 seq_printf(m,
3212 " unique_id %d, can_queue %d, this_id %d, sg_tablesize %u, cmd_per_lun %u\n",
3213 shost->unique_id, shost->can_queue, shost->this_id,
3214 shost->sg_tablesize, shost->cmd_per_lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215
Al Virob59fb6f2013-03-31 02:59:55 -04003216 seq_printf(m,
3217 " unchecked_isa_dma %d, use_clustering %d\n",
3218 shost->unchecked_isa_dma, shost->use_clustering);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219
Al Virob59fb6f2013-03-31 02:59:55 -04003220 seq_printf(m,
Al Viro31491e12013-03-31 03:04:13 -04003221 " flags 0x%x, last_reset 0x%lx, jiffies 0x%lx, asc_n_io_port 0x%x\n",
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02003222 boardp->flags, shost->last_reset, jiffies,
Al Virob59fb6f2013-03-31 02:59:55 -04003223 boardp->asc_n_io_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224
Al Viro31491e12013-03-31 03:04:13 -04003225 seq_printf(m, " io_port 0x%lx\n", shost->io_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003227 if (ASC_NARROW_BOARD(boardp)) {
3228 chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
3229 } else {
3230 chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
3231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232}
3233
3234/*
3235 * asc_prt_asc_board_info()
3236 *
3237 * Print dynamic board configuration information.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238 */
Al Virob59fb6f2013-03-31 02:59:55 -04003239static void asc_prt_asc_board_info(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04003241 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003242 int chip_scsi_id;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003243 ASC_DVC_VAR *v;
3244 ASC_DVC_CFG *c;
3245 int i;
3246 int renegotiate = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003248 v = &boardp->dvc_var.asc_dvc_var;
3249 c = &boardp->dvc_cfg.asc_dvc_cfg;
3250 chip_scsi_id = c->chip_scsi_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251
Al Virob59fb6f2013-03-31 02:59:55 -04003252 seq_printf(m,
3253 "\nAsc Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
3254 shost->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255
Al Virob59fb6f2013-03-31 02:59:55 -04003256 seq_printf(m, " chip_version %u, mcode_date 0x%x, "
3257 "mcode_version 0x%x, err_code %u\n",
3258 c->chip_version, c->mcode_date, c->mcode_version,
3259 v->err_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003261 /* Current number of commands waiting for the host. */
Al Virob59fb6f2013-03-31 02:59:55 -04003262 seq_printf(m,
3263 " Total Command Pending: %d\n", v->cur_total_qng);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003265 seq_puts(m, " Command Queuing:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003266 for (i = 0; i <= ASC_MAX_TID; i++) {
3267 if ((chip_scsi_id == i) ||
3268 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3269 continue;
3270 }
Al Virob59fb6f2013-03-31 02:59:55 -04003271 seq_printf(m, " %X:%c",
3272 i,
3273 (v->use_tagged_qng & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003274 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003276 /* Current number of commands waiting for a device. */
Rasmus Villemoes3d300792014-12-03 00:10:53 +01003277 seq_puts(m, "\n Command Queue Pending:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003278 for (i = 0; i <= ASC_MAX_TID; i++) {
3279 if ((chip_scsi_id == i) ||
3280 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3281 continue;
3282 }
Al Virob59fb6f2013-03-31 02:59:55 -04003283 seq_printf(m, " %X:%u", i, v->cur_dvc_qng[i]);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003284 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003286 /* Current limit on number of commands that can be sent to a device. */
Rasmus Villemoes3d300792014-12-03 00:10:53 +01003287 seq_puts(m, "\n Command Queue Limit:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003288 for (i = 0; i <= ASC_MAX_TID; i++) {
3289 if ((chip_scsi_id == i) ||
3290 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3291 continue;
3292 }
Al Virob59fb6f2013-03-31 02:59:55 -04003293 seq_printf(m, " %X:%u", i, v->max_dvc_qng[i]);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003294 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003296 /* Indicate whether the device has returned queue full status. */
Rasmus Villemoes3d300792014-12-03 00:10:53 +01003297 seq_puts(m, "\n Command Queue Full:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003298 for (i = 0; i <= ASC_MAX_TID; i++) {
3299 if ((chip_scsi_id == i) ||
3300 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3301 continue;
3302 }
Al Virob59fb6f2013-03-31 02:59:55 -04003303 if (boardp->queue_full & ADV_TID_TO_TIDMASK(i))
3304 seq_printf(m, " %X:Y-%d",
3305 i, boardp->queue_full_cnt[i]);
3306 else
3307 seq_printf(m, " %X:N", i);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003308 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309
Rasmus Villemoes3d300792014-12-03 00:10:53 +01003310 seq_puts(m, "\n Synchronous Transfer:");
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:%c",
3317 i,
3318 (v->sdtr_done & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003319 }
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003320 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003322 for (i = 0; i <= ASC_MAX_TID; i++) {
3323 uchar syn_period_ix;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003325 if ((chip_scsi_id == i) ||
3326 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) ||
3327 ((v->init_sdtr & ADV_TID_TO_TIDMASK(i)) == 0)) {
3328 continue;
3329 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330
Al Virob59fb6f2013-03-31 02:59:55 -04003331 seq_printf(m, " %X:", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003333 if ((boardp->sdtr_data[i] & ASC_SYN_MAX_OFFSET) == 0) {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003334 seq_puts(m, " Asynchronous");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003335 } else {
3336 syn_period_ix =
3337 (boardp->sdtr_data[i] >> 4) & (v->max_sdtr_index -
3338 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339
Al Virob59fb6f2013-03-31 02:59:55 -04003340 seq_printf(m,
3341 " Transfer Period Factor: %d (%d.%d Mhz),",
3342 v->sdtr_period_tbl[syn_period_ix],
3343 250 / v->sdtr_period_tbl[syn_period_ix],
3344 ASC_TENTHS(250,
3345 v->sdtr_period_tbl[syn_period_ix]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346
Al Virob59fb6f2013-03-31 02:59:55 -04003347 seq_printf(m, " REQ/ACK Offset: %d",
3348 boardp->sdtr_data[i] & ASC_SYN_MAX_OFFSET);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003349 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003351 if ((v->sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003352 seq_puts(m, "*\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003353 renegotiate = 1;
3354 } else {
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003355 seq_putc(m, '\n');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003356 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003357 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003359 if (renegotiate) {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003360 seq_puts(m, " * = Re-negotiation pending before next command.\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003361 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362}
3363
3364/*
3365 * asc_prt_adv_board_info()
3366 *
3367 * Print dynamic board configuration information.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368 */
Al Virob59fb6f2013-03-31 02:59:55 -04003369static void asc_prt_adv_board_info(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04003371 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003372 int i;
3373 ADV_DVC_VAR *v;
3374 ADV_DVC_CFG *c;
3375 AdvPortAddr iop_base;
3376 ushort chip_scsi_id;
3377 ushort lramword;
3378 uchar lrambyte;
3379 ushort tagqng_able;
3380 ushort sdtr_able, wdtr_able;
3381 ushort wdtr_done, sdtr_done;
3382 ushort period = 0;
3383 int renegotiate = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003385 v = &boardp->dvc_var.adv_dvc_var;
3386 c = &boardp->dvc_cfg.adv_dvc_cfg;
3387 iop_base = v->iop_base;
3388 chip_scsi_id = v->chip_scsi_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389
Al Virob59fb6f2013-03-31 02:59:55 -04003390 seq_printf(m,
3391 "\nAdv Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
3392 shost->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393
Al Virob59fb6f2013-03-31 02:59:55 -04003394 seq_printf(m,
3395 " iop_base 0x%lx, cable_detect: %X, err_code %u\n",
Al Viro31491e12013-03-31 03:04:13 -04003396 (unsigned long)v->iop_base,
Al Virob59fb6f2013-03-31 02:59:55 -04003397 AdvReadWordRegister(iop_base,IOPW_SCSI_CFG1) & CABLE_DETECT,
3398 v->err_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399
Al Virob59fb6f2013-03-31 02:59:55 -04003400 seq_printf(m, " chip_version %u, mcode_date 0x%x, "
3401 "mcode_version 0x%x\n", c->chip_version,
3402 c->mcode_date, c->mcode_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003404 AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003405 seq_puts(m, " Queuing Enabled:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003406 for (i = 0; i <= ADV_MAX_TID; i++) {
3407 if ((chip_scsi_id == i) ||
3408 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3409 continue;
3410 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411
Al Virob59fb6f2013-03-31 02:59:55 -04003412 seq_printf(m, " %X:%c",
3413 i,
3414 (tagqng_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003415 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416
Rasmus Villemoes3d300792014-12-03 00:10:53 +01003417 seq_puts(m, "\n Queue Limit:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003418 for (i = 0; i <= ADV_MAX_TID; i++) {
3419 if ((chip_scsi_id == i) ||
3420 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3421 continue;
3422 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003424 AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + i,
3425 lrambyte);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426
Al Virob59fb6f2013-03-31 02:59:55 -04003427 seq_printf(m, " %X:%d", i, lrambyte);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003428 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429
Rasmus Villemoes3d300792014-12-03 00:10:53 +01003430 seq_puts(m, "\n Command Pending:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003431 for (i = 0; i <= ADV_MAX_TID; i++) {
3432 if ((chip_scsi_id == i) ||
3433 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3434 continue;
3435 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003437 AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_QUEUED_CMD + i,
3438 lrambyte);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439
Al Virob59fb6f2013-03-31 02:59:55 -04003440 seq_printf(m, " %X:%d", i, lrambyte);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003441 }
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003442 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003444 AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003445 seq_puts(m, " Wide Enabled:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003446 for (i = 0; i <= ADV_MAX_TID; i++) {
3447 if ((chip_scsi_id == i) ||
3448 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3449 continue;
3450 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451
Al Virob59fb6f2013-03-31 02:59:55 -04003452 seq_printf(m, " %X:%c",
3453 i,
3454 (wdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003455 }
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003456 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003458 AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, wdtr_done);
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003459 seq_puts(m, " Transfer Bit Width:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003460 for (i = 0; i <= ADV_MAX_TID; i++) {
3461 if ((chip_scsi_id == i) ||
3462 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3463 continue;
3464 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003466 AdvReadWordLram(iop_base,
3467 ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i),
3468 lramword);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469
Al Virob59fb6f2013-03-31 02:59:55 -04003470 seq_printf(m, " %X:%d",
3471 i, (lramword & 0x8000) ? 16 : 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003473 if ((wdtr_able & ADV_TID_TO_TIDMASK(i)) &&
3474 (wdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003475 seq_putc(m, '*');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003476 renegotiate = 1;
3477 }
3478 }
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003479 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003481 AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003482 seq_puts(m, " Synchronous Enabled:");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003483 for (i = 0; i <= ADV_MAX_TID; i++) {
3484 if ((chip_scsi_id == i) ||
3485 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
3486 continue;
3487 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488
Al Virob59fb6f2013-03-31 02:59:55 -04003489 seq_printf(m, " %X:%c",
3490 i,
3491 (sdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003492 }
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003493 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003495 AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, sdtr_done);
3496 for (i = 0; i <= ADV_MAX_TID; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003498 AdvReadWordLram(iop_base,
3499 ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i),
3500 lramword);
3501 lramword &= ~0x8000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003502
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003503 if ((chip_scsi_id == i) ||
3504 ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) ||
3505 ((sdtr_able & ADV_TID_TO_TIDMASK(i)) == 0)) {
3506 continue;
3507 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508
Al Virob59fb6f2013-03-31 02:59:55 -04003509 seq_printf(m, " %X:", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003511 if ((lramword & 0x1F) == 0) { /* Check for REQ/ACK Offset 0. */
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003512 seq_puts(m, " Asynchronous");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003513 } else {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003514 seq_puts(m, " Transfer Period Factor: ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003516 if ((lramword & 0x1F00) == 0x1100) { /* 80 Mhz */
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003517 seq_puts(m, "9 (80.0 Mhz),");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003518 } else if ((lramword & 0x1F00) == 0x1000) { /* 40 Mhz */
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003519 seq_puts(m, "10 (40.0 Mhz),");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003520 } else { /* 20 Mhz or below. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003522 period = (((lramword >> 8) * 25) + 50) / 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003524 if (period == 0) { /* Should never happen. */
Al Viro31491e12013-03-31 03:04:13 -04003525 seq_printf(m, "%d (? Mhz), ", period);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003526 } else {
Al Virob59fb6f2013-03-31 02:59:55 -04003527 seq_printf(m,
3528 "%d (%d.%d Mhz),",
3529 period, 250 / period,
3530 ASC_TENTHS(250, period));
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003531 }
3532 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533
Al Virob59fb6f2013-03-31 02:59:55 -04003534 seq_printf(m, " REQ/ACK Offset: %d",
3535 lramword & 0x1F);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003536 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003538 if ((sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003539 seq_puts(m, "*\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003540 renegotiate = 1;
3541 } else {
Rasmus Villemoesf50332f2014-12-03 00:10:54 +01003542 seq_putc(m, '\n');
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003543 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003544 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003546 if (renegotiate) {
Rasmus Villemoes2f979422014-12-03 00:10:50 +01003547 seq_puts(m, " * = Re-negotiation pending before next command.\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003548 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549}
3550
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551#ifdef ADVANSYS_STATS
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552/*
3553 * asc_prt_board_stats()
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554 */
Al Virob59fb6f2013-03-31 02:59:55 -04003555static void asc_prt_board_stats(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04003557 struct asc_board *boardp = shost_priv(shost);
3558 struct asc_stats *s = &boardp->asc_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559
Al Virob59fb6f2013-03-31 02:59:55 -04003560 seq_printf(m,
3561 "\nLinux Driver Statistics for AdvanSys SCSI Host %d:\n",
3562 shost->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003563
Al Virob59fb6f2013-03-31 02:59:55 -04003564 seq_printf(m,
Al Viro31491e12013-03-31 03:04:13 -04003565 " queuecommand %u, reset %u, biosparam %u, interrupt %u\n",
Al Virob59fb6f2013-03-31 02:59:55 -04003566 s->queuecommand, s->reset, s->biosparam,
3567 s->interrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568
Al Virob59fb6f2013-03-31 02:59:55 -04003569 seq_printf(m,
Al Viro31491e12013-03-31 03:04:13 -04003570 " callback %u, done %u, build_error %u, build_noreq %u, build_nosg %u\n",
Al Virob59fb6f2013-03-31 02:59:55 -04003571 s->callback, s->done, s->build_error,
3572 s->adv_build_noreq, s->adv_build_nosg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573
Al Virob59fb6f2013-03-31 02:59:55 -04003574 seq_printf(m,
Al Viro31491e12013-03-31 03:04:13 -04003575 " exe_noerror %u, exe_busy %u, exe_error %u, exe_unknown %u\n",
Al Virob59fb6f2013-03-31 02:59:55 -04003576 s->exe_noerror, s->exe_busy, s->exe_error,
3577 s->exe_unknown);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003579 /*
3580 * Display data transfer statistics.
3581 */
Matthew Wilcox52c334e2007-10-02 21:55:39 -04003582 if (s->xfer_cnt > 0) {
Al Viro31491e12013-03-31 03:04:13 -04003583 seq_printf(m, " xfer_cnt %u, xfer_elem %u, ",
Al Virob59fb6f2013-03-31 02:59:55 -04003584 s->xfer_cnt, s->xfer_elem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003585
Al Viro31491e12013-03-31 03:04:13 -04003586 seq_printf(m, "xfer_bytes %u.%01u kb\n",
Al Virob59fb6f2013-03-31 02:59:55 -04003587 s->xfer_sect / 2, ASC_TENTHS(s->xfer_sect, 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003589 /* Scatter gather transfer statistics */
Al Viro31491e12013-03-31 03:04:13 -04003590 seq_printf(m, " avg_num_elem %u.%01u, ",
Al Virob59fb6f2013-03-31 02:59:55 -04003591 s->xfer_elem / s->xfer_cnt,
3592 ASC_TENTHS(s->xfer_elem, s->xfer_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593
Al Viro31491e12013-03-31 03:04:13 -04003594 seq_printf(m, "avg_elem_size %u.%01u kb, ",
Al Virob59fb6f2013-03-31 02:59:55 -04003595 (s->xfer_sect / 2) / s->xfer_elem,
3596 ASC_TENTHS((s->xfer_sect / 2), s->xfer_elem));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003597
Al Viro31491e12013-03-31 03:04:13 -04003598 seq_printf(m, "avg_xfer_size %u.%01u kb\n",
Al Virob59fb6f2013-03-31 02:59:55 -04003599 (s->xfer_sect / 2) / s->xfer_cnt,
3600 ASC_TENTHS((s->xfer_sect / 2), s->xfer_cnt));
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003601 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003602}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603#endif /* ADVANSYS_STATS */
3604
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605/*
Al Virob59fb6f2013-03-31 02:59:55 -04003606 * advansys_show_info() - /proc/scsi/advansys/{0,1,2,3,...}
Matthew Wilcox51219352007-10-02 21:55:22 -04003607 *
Al Virob59fb6f2013-03-31 02:59:55 -04003608 * m: seq_file to print into
3609 * shost: Scsi_Host
Matthew Wilcox51219352007-10-02 21:55:22 -04003610 *
3611 * Return the number of bytes read from or written to a
3612 * /proc/scsi/advansys/[0...] file.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613 */
Matthew Wilcox51219352007-10-02 21:55:22 -04003614static int
Al Virob59fb6f2013-03-31 02:59:55 -04003615advansys_show_info(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003616{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04003617 struct asc_board *boardp = shost_priv(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003618
Matthew Wilcoxb352f922007-10-02 21:55:33 -04003619 ASC_DBG(1, "begin\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003620
Matthew Wilcox51219352007-10-02 21:55:22 -04003621 /*
Matthew Wilcox51219352007-10-02 21:55:22 -04003622 * User read of /proc/scsi/advansys/[0...] file.
3623 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624
Matthew Wilcox51219352007-10-02 21:55:22 -04003625 /*
3626 * Get board configuration information.
3627 *
3628 * advansys_info() returns the board string from its own static buffer.
3629 */
Matthew Wilcox51219352007-10-02 21:55:22 -04003630 /* Copy board information. */
Al Virob59fb6f2013-03-31 02:59:55 -04003631 seq_printf(m, "%s\n", (char *)advansys_info(shost));
Matthew Wilcox51219352007-10-02 21:55:22 -04003632 /*
3633 * Display Wide Board BIOS Information.
3634 */
Al Virob59fb6f2013-03-31 02:59:55 -04003635 if (!ASC_NARROW_BOARD(boardp))
3636 asc_prt_adv_bios(m, shost);
Matthew Wilcox51219352007-10-02 21:55:22 -04003637
3638 /*
3639 * Display driver information for each device attached to the board.
3640 */
Al Virob59fb6f2013-03-31 02:59:55 -04003641 asc_prt_board_devices(m, shost);
Matthew Wilcox51219352007-10-02 21:55:22 -04003642
3643 /*
3644 * Display EEPROM configuration for the board.
3645 */
Al Virob59fb6f2013-03-31 02:59:55 -04003646 if (ASC_NARROW_BOARD(boardp))
3647 asc_prt_asc_board_eeprom(m, shost);
3648 else
3649 asc_prt_adv_board_eeprom(m, shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650
Matthew Wilcox51219352007-10-02 21:55:22 -04003651 /*
3652 * Display driver configuration and information for the board.
3653 */
Al Virob59fb6f2013-03-31 02:59:55 -04003654 asc_prt_driver_conf(m, shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655
Matthew Wilcox51219352007-10-02 21:55:22 -04003656#ifdef ADVANSYS_STATS
3657 /*
3658 * Display driver statistics for the board.
3659 */
Al Virob59fb6f2013-03-31 02:59:55 -04003660 asc_prt_board_stats(m, shost);
Matthew Wilcox51219352007-10-02 21:55:22 -04003661#endif /* ADVANSYS_STATS */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662
Matthew Wilcox51219352007-10-02 21:55:22 -04003663 /*
3664 * Display Asc Library dynamic configuration information
3665 * for the board.
3666 */
Al Virob59fb6f2013-03-31 02:59:55 -04003667 if (ASC_NARROW_BOARD(boardp))
3668 asc_prt_asc_board_info(m, shost);
3669 else
3670 asc_prt_adv_board_info(m, shost);
3671 return 0;
Matthew Wilcox51219352007-10-02 21:55:22 -04003672}
3673#endif /* CONFIG_PROC_FS */
3674
3675static void asc_scsi_done(struct scsi_cmnd *scp)
3676{
Matthew Wilcox52c334e2007-10-02 21:55:39 -04003677 scsi_dma_unmap(scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04003678 ASC_STATS(scp->device->host, done);
Matthew Wilcox51219352007-10-02 21:55:22 -04003679 scp->scsi_done(scp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003680}
3681
Matthew Wilcox51219352007-10-02 21:55:22 -04003682static void AscSetBank(PortAddr iop_base, uchar bank)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683{
Matthew Wilcox51219352007-10-02 21:55:22 -04003684 uchar val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685
Matthew Wilcox51219352007-10-02 21:55:22 -04003686 val = AscGetChipControl(iop_base) &
3687 (~
3688 (CC_SINGLE_STEP | CC_TEST | CC_DIAG | CC_SCSI_RESET |
3689 CC_CHIP_RESET));
3690 if (bank == 1) {
3691 val |= CC_BANK_ONE;
3692 } else if (bank == 2) {
3693 val |= CC_DIAG | CC_BANK_ONE;
3694 } else {
3695 val &= ~CC_BANK_ONE;
3696 }
3697 AscSetChipControl(iop_base, val);
Matthew Wilcox51219352007-10-02 21:55:22 -04003698}
3699
3700static void AscSetChipIH(PortAddr iop_base, ushort ins_code)
3701{
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003702 AscSetBank(iop_base, 1);
Matthew Wilcox51219352007-10-02 21:55:22 -04003703 AscWriteChipIH(iop_base, ins_code);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003704 AscSetBank(iop_base, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705}
3706
Matthew Wilcox51219352007-10-02 21:55:22 -04003707static int AscStartChip(PortAddr iop_base)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708{
Matthew Wilcox51219352007-10-02 21:55:22 -04003709 AscSetChipControl(iop_base, 0);
3710 if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) {
3711 return (0);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003712 }
Matthew Wilcox51219352007-10-02 21:55:22 -04003713 return (1);
3714}
3715
Hannes Reineckeae267592015-04-24 13:18:28 +02003716static bool AscStopChip(PortAddr iop_base)
Matthew Wilcox51219352007-10-02 21:55:22 -04003717{
3718 uchar cc_val;
3719
3720 cc_val =
3721 AscGetChipControl(iop_base) &
3722 (~(CC_SINGLE_STEP | CC_TEST | CC_DIAG));
3723 AscSetChipControl(iop_base, (uchar)(cc_val | CC_HALT));
3724 AscSetChipIH(iop_base, INS_HALT);
3725 AscSetChipIH(iop_base, INS_RFLAG_WTM);
3726 if ((AscGetChipStatus(iop_base) & CSW_HALTED) == 0) {
Hannes Reineckeae267592015-04-24 13:18:28 +02003727 return false;
Matthew Wilcox51219352007-10-02 21:55:22 -04003728 }
Hannes Reineckeae267592015-04-24 13:18:28 +02003729 return true;
Matthew Wilcox51219352007-10-02 21:55:22 -04003730}
3731
Hannes Reinecked647c782015-04-24 13:18:26 +02003732static bool AscIsChipHalted(PortAddr iop_base)
Matthew Wilcox51219352007-10-02 21:55:22 -04003733{
3734 if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) {
3735 if ((AscGetChipControl(iop_base) & CC_HALT) != 0) {
Hannes Reinecked647c782015-04-24 13:18:26 +02003736 return true;
Matthew Wilcox51219352007-10-02 21:55:22 -04003737 }
3738 }
Hannes Reinecked647c782015-04-24 13:18:26 +02003739 return false;
Matthew Wilcox51219352007-10-02 21:55:22 -04003740}
3741
Hannes Reinecked647c782015-04-24 13:18:26 +02003742static bool AscResetChipAndScsiBus(ASC_DVC_VAR *asc_dvc)
Matthew Wilcox51219352007-10-02 21:55:22 -04003743{
3744 PortAddr iop_base;
3745 int i = 10;
3746
3747 iop_base = asc_dvc->iop_base;
3748 while ((AscGetChipStatus(iop_base) & CSW_SCSI_RESET_ACTIVE)
3749 && (i-- > 0)) {
3750 mdelay(100);
3751 }
3752 AscStopChip(iop_base);
3753 AscSetChipControl(iop_base, CC_CHIP_RESET | CC_SCSI_RESET | CC_HALT);
3754 udelay(60);
3755 AscSetChipIH(iop_base, INS_RFLAG_WTM);
3756 AscSetChipIH(iop_base, INS_HALT);
3757 AscSetChipControl(iop_base, CC_CHIP_RESET | CC_HALT);
3758 AscSetChipControl(iop_base, CC_HALT);
3759 mdelay(200);
3760 AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
3761 AscSetChipStatus(iop_base, 0);
3762 return (AscIsChipHalted(iop_base));
3763}
3764
3765static int AscFindSignature(PortAddr iop_base)
3766{
3767 ushort sig_word;
3768
Matthew Wilcoxb352f922007-10-02 21:55:33 -04003769 ASC_DBG(1, "AscGetChipSignatureByte(0x%x) 0x%x\n",
Matthew Wilcox51219352007-10-02 21:55:22 -04003770 iop_base, AscGetChipSignatureByte(iop_base));
3771 if (AscGetChipSignatureByte(iop_base) == (uchar)ASC_1000_ID1B) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04003772 ASC_DBG(1, "AscGetChipSignatureWord(0x%x) 0x%x\n",
Matthew Wilcox51219352007-10-02 21:55:22 -04003773 iop_base, AscGetChipSignatureWord(iop_base));
3774 sig_word = AscGetChipSignatureWord(iop_base);
3775 if ((sig_word == (ushort)ASC_1000_ID0W) ||
3776 (sig_word == (ushort)ASC_1000_ID0W_FIX)) {
3777 return (1);
3778 }
3779 }
3780 return (0);
3781}
3782
3783static void AscEnableInterrupt(PortAddr iop_base)
3784{
3785 ushort cfg;
3786
3787 cfg = AscGetChipCfgLsw(iop_base);
3788 AscSetChipCfgLsw(iop_base, cfg | ASC_CFG0_HOST_INT_ON);
Matthew Wilcox51219352007-10-02 21:55:22 -04003789}
3790
3791static void AscDisableInterrupt(PortAddr iop_base)
3792{
3793 ushort cfg;
3794
3795 cfg = AscGetChipCfgLsw(iop_base);
3796 AscSetChipCfgLsw(iop_base, cfg & (~ASC_CFG0_HOST_INT_ON));
Matthew Wilcox51219352007-10-02 21:55:22 -04003797}
3798
3799static uchar AscReadLramByte(PortAddr iop_base, ushort addr)
3800{
3801 unsigned char byte_data;
3802 unsigned short word_data;
3803
3804 if (isodd_word(addr)) {
3805 AscSetChipLramAddr(iop_base, addr - 1);
3806 word_data = AscGetChipLramData(iop_base);
3807 byte_data = (word_data >> 8) & 0xFF;
3808 } else {
3809 AscSetChipLramAddr(iop_base, addr);
3810 word_data = AscGetChipLramData(iop_base);
3811 byte_data = word_data & 0xFF;
3812 }
3813 return byte_data;
3814}
3815
3816static ushort AscReadLramWord(PortAddr iop_base, ushort addr)
3817{
3818 ushort word_data;
3819
3820 AscSetChipLramAddr(iop_base, addr);
3821 word_data = AscGetChipLramData(iop_base);
3822 return (word_data);
3823}
3824
Matthew Wilcox51219352007-10-02 21:55:22 -04003825static void
3826AscMemWordSetLram(PortAddr iop_base, ushort s_addr, ushort set_wval, int words)
3827{
3828 int i;
3829
3830 AscSetChipLramAddr(iop_base, s_addr);
3831 for (i = 0; i < words; i++) {
3832 AscSetChipLramData(iop_base, set_wval);
3833 }
3834}
3835
3836static void AscWriteLramWord(PortAddr iop_base, ushort addr, ushort word_val)
3837{
3838 AscSetChipLramAddr(iop_base, addr);
3839 AscSetChipLramData(iop_base, word_val);
Matthew Wilcox51219352007-10-02 21:55:22 -04003840}
3841
3842static void AscWriteLramByte(PortAddr iop_base, ushort addr, uchar byte_val)
3843{
3844 ushort word_data;
3845
3846 if (isodd_word(addr)) {
3847 addr--;
3848 word_data = AscReadLramWord(iop_base, addr);
3849 word_data &= 0x00FF;
3850 word_data |= (((ushort)byte_val << 8) & 0xFF00);
3851 } else {
3852 word_data = AscReadLramWord(iop_base, addr);
3853 word_data &= 0xFF00;
3854 word_data |= ((ushort)byte_val & 0x00FF);
3855 }
3856 AscWriteLramWord(iop_base, addr, word_data);
Matthew Wilcox51219352007-10-02 21:55:22 -04003857}
3858
3859/*
3860 * Copy 2 bytes to LRAM.
3861 *
3862 * The source data is assumed to be in little-endian order in memory
3863 * and is maintained in little-endian order when written to LRAM.
3864 */
3865static void
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05303866AscMemWordCopyPtrToLram(PortAddr iop_base, ushort s_addr,
3867 const uchar *s_buffer, int words)
Matthew Wilcox51219352007-10-02 21:55:22 -04003868{
3869 int i;
3870
3871 AscSetChipLramAddr(iop_base, s_addr);
3872 for (i = 0; i < 2 * words; i += 2) {
3873 /*
3874 * On a little-endian system the second argument below
3875 * produces a little-endian ushort which is written to
3876 * LRAM in little-endian order. On a big-endian system
3877 * the second argument produces a big-endian ushort which
3878 * is "transparently" byte-swapped by outpw() and written
3879 * in little-endian order to LRAM.
3880 */
3881 outpw(iop_base + IOP_RAM_DATA,
3882 ((ushort)s_buffer[i + 1] << 8) | s_buffer[i]);
3883 }
Matthew Wilcox51219352007-10-02 21:55:22 -04003884}
3885
3886/*
3887 * Copy 4 bytes to LRAM.
3888 *
3889 * The source data is assumed to be in little-endian order in memory
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003890 * and is maintained in little-endian order when written to LRAM.
Matthew Wilcox51219352007-10-02 21:55:22 -04003891 */
3892static void
3893AscMemDWordCopyPtrToLram(PortAddr iop_base,
3894 ushort s_addr, uchar *s_buffer, int dwords)
3895{
3896 int i;
3897
3898 AscSetChipLramAddr(iop_base, s_addr);
3899 for (i = 0; i < 4 * dwords; i += 4) {
3900 outpw(iop_base + IOP_RAM_DATA, ((ushort)s_buffer[i + 1] << 8) | s_buffer[i]); /* LSW */
3901 outpw(iop_base + IOP_RAM_DATA, ((ushort)s_buffer[i + 3] << 8) | s_buffer[i + 2]); /* MSW */
3902 }
Matthew Wilcox51219352007-10-02 21:55:22 -04003903}
3904
3905/*
3906 * Copy 2 bytes from LRAM.
3907 *
3908 * The source data is assumed to be in little-endian order in LRAM
3909 * and is maintained in little-endian order when written to memory.
3910 */
3911static void
3912AscMemWordCopyPtrFromLram(PortAddr iop_base,
3913 ushort s_addr, uchar *d_buffer, int words)
3914{
3915 int i;
3916 ushort word;
3917
3918 AscSetChipLramAddr(iop_base, s_addr);
3919 for (i = 0; i < 2 * words; i += 2) {
3920 word = inpw(iop_base + IOP_RAM_DATA);
3921 d_buffer[i] = word & 0xff;
3922 d_buffer[i + 1] = (word >> 8) & 0xff;
3923 }
Matthew Wilcox51219352007-10-02 21:55:22 -04003924}
3925
Hannes Reinecke95cfab62015-04-24 13:18:27 +02003926static u32 AscMemSumLramWord(PortAddr iop_base, ushort s_addr, int words)
Matthew Wilcox51219352007-10-02 21:55:22 -04003927{
Hannes Reinecke95cfab62015-04-24 13:18:27 +02003928 u32 sum = 0;
Matthew Wilcox51219352007-10-02 21:55:22 -04003929 int i;
3930
Matthew Wilcox51219352007-10-02 21:55:22 -04003931 for (i = 0; i < words; i++, s_addr += 2) {
3932 sum += AscReadLramWord(iop_base, s_addr);
3933 }
3934 return (sum);
3935}
3936
Hannes Reineckef33134e2015-04-24 13:18:31 +02003937static void AscInitLram(ASC_DVC_VAR *asc_dvc)
Matthew Wilcox51219352007-10-02 21:55:22 -04003938{
3939 uchar i;
3940 ushort s_addr;
3941 PortAddr iop_base;
Matthew Wilcox51219352007-10-02 21:55:22 -04003942
3943 iop_base = asc_dvc->iop_base;
Matthew Wilcox51219352007-10-02 21:55:22 -04003944 AscMemWordSetLram(iop_base, ASC_QADR_BEG, 0,
3945 (ushort)(((int)(asc_dvc->max_total_qng + 2 + 1) *
3946 64) >> 1));
3947 i = ASC_MIN_ACTIVE_QNO;
3948 s_addr = ASC_QADR_BEG + ASC_QBLK_SIZE;
3949 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
3950 (uchar)(i + 1));
3951 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
3952 (uchar)(asc_dvc->max_total_qng));
3953 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
3954 (uchar)i);
3955 i++;
3956 s_addr += ASC_QBLK_SIZE;
3957 for (; i < asc_dvc->max_total_qng; i++, s_addr += ASC_QBLK_SIZE) {
3958 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
3959 (uchar)(i + 1));
3960 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
3961 (uchar)(i - 1));
3962 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
3963 (uchar)i);
3964 }
3965 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
3966 (uchar)ASC_QLINK_END);
3967 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
3968 (uchar)(asc_dvc->max_total_qng - 1));
3969 AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
3970 (uchar)asc_dvc->max_total_qng);
3971 i++;
3972 s_addr += ASC_QBLK_SIZE;
3973 for (; i <= (uchar)(asc_dvc->max_total_qng + 3);
3974 i++, s_addr += ASC_QBLK_SIZE) {
3975 AscWriteLramByte(iop_base,
3976 (ushort)(s_addr + (ushort)ASC_SCSIQ_B_FWD), i);
3977 AscWriteLramByte(iop_base,
3978 (ushort)(s_addr + (ushort)ASC_SCSIQ_B_BWD), i);
3979 AscWriteLramByte(iop_base,
3980 (ushort)(s_addr + (ushort)ASC_SCSIQ_B_QNO), i);
3981 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982}
3983
Hannes Reinecke95cfab62015-04-24 13:18:27 +02003984static u32
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05303985AscLoadMicroCode(PortAddr iop_base, ushort s_addr,
3986 const uchar *mcode_buf, ushort mcode_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987{
Hannes Reinecke95cfab62015-04-24 13:18:27 +02003988 u32 chksum;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003989 ushort mcode_word_size;
3990 ushort mcode_chksum;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003991
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003992 /* Write the microcode buffer starting at LRAM address 0. */
3993 mcode_word_size = (ushort)(mcode_size >> 1);
3994 AscMemWordSetLram(iop_base, s_addr, 0, mcode_word_size);
3995 AscMemWordCopyPtrToLram(iop_base, s_addr, mcode_buf, mcode_word_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003997 chksum = AscMemSumLramWord(iop_base, s_addr, mcode_word_size);
Matthew Wilcoxb352f922007-10-02 21:55:33 -04003998 ASC_DBG(1, "chksum 0x%lx\n", (ulong)chksum);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04003999 mcode_chksum = (ushort)AscMemSumLramWord(iop_base,
4000 (ushort)ASC_CODE_SEC_BEG,
4001 (ushort)((mcode_size -
4002 s_addr - (ushort)
4003 ASC_CODE_SEC_BEG) /
4004 2));
Matthew Wilcoxb352f922007-10-02 21:55:33 -04004005 ASC_DBG(1, "mcode_chksum 0x%lx\n", (ulong)mcode_chksum);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004006 AscWriteLramWord(iop_base, ASCV_MCODE_CHKSUM_W, mcode_chksum);
4007 AscWriteLramWord(iop_base, ASCV_MCODE_SIZE_W, mcode_size);
Matthew Wilcoxb352f922007-10-02 21:55:33 -04004008 return chksum;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004009}
4010
Matthew Wilcox51219352007-10-02 21:55:22 -04004011static void AscInitQLinkVar(ASC_DVC_VAR *asc_dvc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012{
Matthew Wilcox51219352007-10-02 21:55:22 -04004013 PortAddr iop_base;
4014 int i;
4015 ushort lram_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004016
Matthew Wilcox51219352007-10-02 21:55:22 -04004017 iop_base = asc_dvc->iop_base;
4018 AscPutRiscVarFreeQHead(iop_base, 1);
4019 AscPutRiscVarDoneQTail(iop_base, asc_dvc->max_total_qng);
4020 AscPutVarFreeQHead(iop_base, 1);
4021 AscPutVarDoneQTail(iop_base, asc_dvc->max_total_qng);
4022 AscWriteLramByte(iop_base, ASCV_BUSY_QHEAD_B,
4023 (uchar)((int)asc_dvc->max_total_qng + 1));
4024 AscWriteLramByte(iop_base, ASCV_DISC1_QHEAD_B,
4025 (uchar)((int)asc_dvc->max_total_qng + 2));
4026 AscWriteLramByte(iop_base, (ushort)ASCV_TOTAL_READY_Q_B,
4027 asc_dvc->max_total_qng);
4028 AscWriteLramWord(iop_base, ASCV_ASCDVC_ERR_CODE_W, 0);
4029 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
4030 AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, 0);
4031 AscWriteLramByte(iop_base, ASCV_SCSIBUSY_B, 0);
4032 AscWriteLramByte(iop_base, ASCV_WTM_FLAG_B, 0);
4033 AscPutQDoneInProgress(iop_base, 0);
4034 lram_addr = ASC_QADR_BEG;
4035 for (i = 0; i < 32; i++, lram_addr += 2) {
4036 AscWriteLramWord(iop_base, lram_addr, 0);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004037 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004038}
4039
Hannes Reineckef33134e2015-04-24 13:18:31 +02004040static int AscInitMicroCodeVar(ASC_DVC_VAR *asc_dvc)
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004041{
Matthew Wilcox51219352007-10-02 21:55:22 -04004042 int i;
Hannes Reineckef33134e2015-04-24 13:18:31 +02004043 int warn_code;
Matthew Wilcox51219352007-10-02 21:55:22 -04004044 PortAddr iop_base;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02004045 __le32 phy_addr;
4046 __le32 phy_size;
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -04004047 struct asc_board *board = asc_dvc_to_board(asc_dvc);
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004048
Matthew Wilcox51219352007-10-02 21:55:22 -04004049 iop_base = asc_dvc->iop_base;
4050 warn_code = 0;
4051 for (i = 0; i <= ASC_MAX_TID; i++) {
4052 AscPutMCodeInitSDTRAtID(iop_base, i,
4053 asc_dvc->cfg->sdtr_period_offset[i]);
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004054 }
4055
Matthew Wilcox51219352007-10-02 21:55:22 -04004056 AscInitQLinkVar(asc_dvc);
4057 AscWriteLramByte(iop_base, ASCV_DISC_ENABLE_B,
4058 asc_dvc->cfg->disc_enable);
4059 AscWriteLramByte(iop_base, ASCV_HOSTSCSI_ID_B,
4060 ASC_TID_TO_TARGET_ID(asc_dvc->cfg->chip_scsi_id));
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004061
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -04004062 /* Ensure overrun buffer is aligned on an 8 byte boundary. */
4063 BUG_ON((unsigned long)asc_dvc->overrun_buf & 7);
4064 asc_dvc->overrun_dma = dma_map_single(board->dev, asc_dvc->overrun_buf,
4065 ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -03004066 if (dma_mapping_error(board->dev, asc_dvc->overrun_dma)) {
4067 warn_code = -ENOMEM;
4068 goto err_dma_map;
4069 }
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -04004070 phy_addr = cpu_to_le32(asc_dvc->overrun_dma);
Matthew Wilcox51219352007-10-02 21:55:22 -04004071 AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_PADDR_D,
4072 (uchar *)&phy_addr, 1);
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -04004073 phy_size = cpu_to_le32(ASC_OVERRUN_BSIZE);
Matthew Wilcox51219352007-10-02 21:55:22 -04004074 AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_BSIZE_D,
4075 (uchar *)&phy_size, 1);
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004076
Matthew Wilcox51219352007-10-02 21:55:22 -04004077 asc_dvc->cfg->mcode_date =
4078 AscReadLramWord(iop_base, (ushort)ASCV_MC_DATE_W);
4079 asc_dvc->cfg->mcode_version =
4080 AscReadLramWord(iop_base, (ushort)ASCV_MC_VER_W);
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004081
Matthew Wilcox51219352007-10-02 21:55:22 -04004082 AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
4083 if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
4084 asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
Hannes Reineckef33134e2015-04-24 13:18:31 +02004085 warn_code = -EINVAL;
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -03004086 goto err_mcode_start;
Matthew Wilcox51219352007-10-02 21:55:22 -04004087 }
4088 if (AscStartChip(iop_base) != 1) {
4089 asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
Hannes Reineckef33134e2015-04-24 13:18:31 +02004090 warn_code = -EIO;
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -03004091 goto err_mcode_start;
Matthew Wilcox51219352007-10-02 21:55:22 -04004092 }
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004093
Matthew Wilcox51219352007-10-02 21:55:22 -04004094 return warn_code;
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -03004095
4096err_mcode_start:
4097 dma_unmap_single(board->dev, asc_dvc->overrun_dma,
4098 ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
4099err_dma_map:
4100 asc_dvc->overrun_dma = 0;
4101 return warn_code;
Matthew Wilcox51219352007-10-02 21:55:22 -04004102}
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004103
Hannes Reineckef33134e2015-04-24 13:18:31 +02004104static int AscInitAsc1000Driver(ASC_DVC_VAR *asc_dvc)
Matthew Wilcox51219352007-10-02 21:55:22 -04004105{
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304106 const struct firmware *fw;
4107 const char fwname[] = "advansys/mcode.bin";
4108 int err;
4109 unsigned long chksum;
Hannes Reineckef33134e2015-04-24 13:18:31 +02004110 int warn_code;
Matthew Wilcox51219352007-10-02 21:55:22 -04004111 PortAddr iop_base;
4112
4113 iop_base = asc_dvc->iop_base;
4114 warn_code = 0;
4115 if ((asc_dvc->dvc_cntl & ASC_CNTL_RESET_SCSI) &&
4116 !(asc_dvc->init_state & ASC_INIT_RESET_SCSI_DONE)) {
4117 AscResetChipAndScsiBus(asc_dvc);
4118 mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
4119 }
4120 asc_dvc->init_state |= ASC_INIT_STATE_BEG_LOAD_MC;
4121 if (asc_dvc->err_code != 0)
Hannes Reineckef33134e2015-04-24 13:18:31 +02004122 return ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04004123 if (!AscFindSignature(asc_dvc->iop_base)) {
4124 asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
4125 return warn_code;
4126 }
4127 AscDisableInterrupt(iop_base);
Hannes Reineckef33134e2015-04-24 13:18:31 +02004128 AscInitLram(asc_dvc);
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304129
4130 err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
4131 if (err) {
4132 printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
4133 fwname, err);
Herton Ronaldo Krzesinskicf747442010-03-19 19:37:26 -03004134 asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304135 return err;
4136 }
4137 if (fw->size < 4) {
4138 printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
4139 fw->size, fwname);
4140 release_firmware(fw);
Herton Ronaldo Krzesinskicf747442010-03-19 19:37:26 -03004141 asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304142 return -EINVAL;
4143 }
4144 chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
4145 (fw->data[1] << 8) | fw->data[0];
4146 ASC_DBG(1, "_asc_mcode_chksum 0x%lx\n", (ulong)chksum);
4147 if (AscLoadMicroCode(iop_base, 0, &fw->data[4],
4148 fw->size - 4) != chksum) {
Matthew Wilcox51219352007-10-02 21:55:22 -04004149 asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304150 release_firmware(fw);
Matthew Wilcox51219352007-10-02 21:55:22 -04004151 return warn_code;
4152 }
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304153 release_firmware(fw);
Matthew Wilcox51219352007-10-02 21:55:22 -04004154 warn_code |= AscInitMicroCodeVar(asc_dvc);
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -03004155 if (!asc_dvc->overrun_dma)
4156 return warn_code;
Matthew Wilcox51219352007-10-02 21:55:22 -04004157 asc_dvc->init_state |= ASC_INIT_STATE_END_LOAD_MC;
4158 AscEnableInterrupt(iop_base);
4159 return warn_code;
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004160}
4161
Linus Torvalds1da177e2005-04-16 15:20:36 -07004162/*
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004163 * Load the Microcode
4164 *
4165 * Write the microcode image to RISC memory starting at address 0.
4166 *
4167 * The microcode is stored compressed in the following format:
4168 *
4169 * 254 word (508 byte) table indexed by byte code followed
4170 * by the following byte codes:
4171 *
4172 * 1-Byte Code:
4173 * 00: Emit word 0 in table.
4174 * 01: Emit word 1 in table.
4175 * .
4176 * FD: Emit word 253 in table.
4177 *
4178 * Multi-Byte Code:
4179 * FE WW WW: (3 byte code) Word to emit is the next word WW WW.
4180 * FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
4181 *
4182 * Returns 0 or an error if the checksum doesn't match
4183 */
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304184static int AdvLoadMicrocode(AdvPortAddr iop_base, const unsigned char *buf,
4185 int size, int memsize, int chksum)
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004186{
4187 int i, j, end, len = 0;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02004188 u32 sum;
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004189
4190 AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
4191
4192 for (i = 253 * 2; i < size; i++) {
4193 if (buf[i] == 0xff) {
4194 unsigned short word = (buf[i + 3] << 8) | buf[i + 2];
4195 for (j = 0; j < buf[i + 1]; j++) {
4196 AdvWriteWordAutoIncLram(iop_base, word);
4197 len += 2;
4198 }
4199 i += 3;
4200 } else if (buf[i] == 0xfe) {
4201 unsigned short word = (buf[i + 2] << 8) | buf[i + 1];
4202 AdvWriteWordAutoIncLram(iop_base, word);
4203 i += 2;
4204 len += 2;
4205 } else {
Matthew Wilcox951b62c2007-10-05 15:57:06 -04004206 unsigned int off = buf[i] * 2;
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004207 unsigned short word = (buf[off + 1] << 8) | buf[off];
4208 AdvWriteWordAutoIncLram(iop_base, word);
4209 len += 2;
4210 }
4211 }
4212
4213 end = len;
4214
4215 while (len < memsize) {
4216 AdvWriteWordAutoIncLram(iop_base, 0);
4217 len += 2;
4218 }
4219
4220 /* Verify the microcode checksum. */
4221 sum = 0;
4222 AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
4223
4224 for (len = 0; len < end; len += 2) {
4225 sum += AdvReadWordAutoIncLram(iop_base);
4226 }
4227
4228 if (sum != chksum)
4229 return ASC_IERR_MCODE_CHKSUM;
4230
4231 return 0;
4232}
4233
Hannes Reinecke98b96a72015-04-24 13:18:23 +02004234static void AdvBuildCarrierFreelist(struct adv_dvc_var *adv_dvc)
Matthew Wilcox51219352007-10-02 21:55:22 -04004235{
Hannes Reinecke98b96a72015-04-24 13:18:23 +02004236 off_t carr_offset = 0, next_offset;
4237 dma_addr_t carr_paddr;
4238 int carr_num = ADV_CARRIER_BUFSIZE / sizeof(ADV_CARR_T), i;
Matthew Wilcox51219352007-10-02 21:55:22 -04004239
Hannes Reinecke98b96a72015-04-24 13:18:23 +02004240 for (i = 0; i < carr_num; i++) {
4241 carr_offset = i * sizeof(ADV_CARR_T);
4242 /* Get physical address of the carrier 'carrp'. */
4243 carr_paddr = adv_dvc->carrier_addr + carr_offset;
4244
4245 adv_dvc->carrier[i].carr_pa = cpu_to_le32(carr_paddr);
4246 adv_dvc->carrier[i].carr_va = cpu_to_le32(carr_offset);
4247 adv_dvc->carrier[i].areq_vpa = 0;
4248 next_offset = carr_offset + sizeof(ADV_CARR_T);
4249 if (i == carr_num)
4250 next_offset = ~0;
4251 adv_dvc->carrier[i].next_vpa = cpu_to_le32(next_offset);
4252 }
4253 /*
4254 * We cannot have a carrier with 'carr_va' of '0', as
4255 * a reference to this carrier would be interpreted as
4256 * list termination.
4257 * So start at carrier 1 with the freelist.
4258 */
4259 adv_dvc->carr_freelist = &adv_dvc->carrier[1];
4260}
4261
4262static ADV_CARR_T *adv_get_carrier(struct adv_dvc_var *adv_dvc, u32 offset)
4263{
4264 int index;
4265
4266 BUG_ON(offset > ADV_CARRIER_BUFSIZE);
4267
4268 index = offset / sizeof(ADV_CARR_T);
4269 return &adv_dvc->carrier[index];
4270}
4271
4272static ADV_CARR_T *adv_get_next_carrier(struct adv_dvc_var *adv_dvc)
4273{
4274 ADV_CARR_T *carrp = adv_dvc->carr_freelist;
4275 u32 next_vpa = le32_to_cpu(carrp->next_vpa);
4276
4277 if (next_vpa == 0 || next_vpa == ~0) {
4278 ASC_DBG(1, "invalid vpa offset 0x%x\n", next_vpa);
4279 return NULL;
Matthew Wilcox51219352007-10-02 21:55:22 -04004280 }
4281
Hannes Reinecke98b96a72015-04-24 13:18:23 +02004282 adv_dvc->carr_freelist = adv_get_carrier(adv_dvc, next_vpa);
4283 /*
4284 * insert stopper carrier to terminate list
4285 */
Hannes Reinecke084e6c32015-04-24 13:18:35 +02004286 carrp->next_vpa = cpu_to_le32(ADV_CQ_STOPPER);
Matthew Wilcox51219352007-10-02 21:55:22 -04004287
Hannes Reinecke98b96a72015-04-24 13:18:23 +02004288 return carrp;
Matthew Wilcox51219352007-10-02 21:55:22 -04004289}
4290
4291/*
Hannes Reinecke4b47e462015-04-24 13:18:24 +02004292 * 'offset' is the index in the request pointer array
4293 */
4294static adv_req_t * adv_get_reqp(struct adv_dvc_var *adv_dvc, u32 offset)
4295{
4296 struct asc_board *boardp = adv_dvc->drv_ptr;
4297
4298 BUG_ON(offset > adv_dvc->max_host_qng);
4299 return &boardp->adv_reqp[offset];
4300}
4301
4302/*
Matthew Wilcox51219352007-10-02 21:55:22 -04004303 * Send an idle command to the chip and wait for completion.
4304 *
4305 * Command completion is polled for once per microsecond.
4306 *
4307 * The function can be called from anywhere including an interrupt handler.
4308 * But the function is not re-entrant, so it uses the DvcEnter/LeaveCritical()
4309 * functions to prevent reentrancy.
4310 *
4311 * Return Values:
4312 * ADV_TRUE - command completed successfully
4313 * ADV_FALSE - command failed
4314 * ADV_ERROR - command timed out
4315 */
4316static int
4317AdvSendIdleCmd(ADV_DVC_VAR *asc_dvc,
Hannes Reinecke95cfab62015-04-24 13:18:27 +02004318 ushort idle_cmd, u32 idle_cmd_parameter)
Matthew Wilcox51219352007-10-02 21:55:22 -04004319{
Hannes Reinecke95cfab62015-04-24 13:18:27 +02004320 int result, i, j;
Matthew Wilcox51219352007-10-02 21:55:22 -04004321 AdvPortAddr iop_base;
4322
4323 iop_base = asc_dvc->iop_base;
4324
4325 /*
4326 * Clear the idle command status which is set by the microcode
4327 * to a non-zero value to indicate when the command is completed.
4328 * The non-zero result is one of the IDLE_CMD_STATUS_* values
4329 */
4330 AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS, (ushort)0);
4331
4332 /*
4333 * Write the idle command value after the idle command parameter
4334 * has been written to avoid a race condition. If the order is not
4335 * followed, the microcode may process the idle command before the
4336 * parameters have been written to LRAM.
4337 */
4338 AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IDLE_CMD_PARAMETER,
4339 cpu_to_le32(idle_cmd_parameter));
4340 AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD, idle_cmd);
4341
4342 /*
4343 * Tickle the RISC to tell it to process the idle command.
4344 */
4345 AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_B);
4346 if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
4347 /*
4348 * Clear the tickle value. In the ASC-3550 the RISC flag
4349 * command 'clr_tickle_b' does not work unless the host
4350 * value is cleared.
4351 */
4352 AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_NOP);
4353 }
4354
4355 /* Wait for up to 100 millisecond for the idle command to timeout. */
4356 for (i = 0; i < SCSI_WAIT_100_MSEC; i++) {
4357 /* Poll once each microsecond for command completion. */
4358 for (j = 0; j < SCSI_US_PER_MSEC; j++) {
4359 AdvReadWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS,
4360 result);
4361 if (result != 0)
4362 return result;
4363 udelay(1);
4364 }
4365 }
4366
4367 BUG(); /* The idle command should never timeout. */
4368 return ADV_ERROR;
4369}
4370
4371/*
4372 * Reset SCSI Bus and purge all outstanding requests.
4373 *
4374 * Return Value:
4375 * ADV_TRUE(1) - All requests are purged and SCSI Bus is reset.
4376 * ADV_FALSE(0) - Microcode command failed.
4377 * ADV_ERROR(-1) - Microcode command timed-out. Microcode or IC
4378 * may be hung which requires driver recovery.
4379 */
4380static int AdvResetSB(ADV_DVC_VAR *asc_dvc)
4381{
4382 int status;
4383
4384 /*
4385 * Send the SCSI Bus Reset idle start idle command which asserts
4386 * the SCSI Bus Reset signal.
4387 */
4388 status = AdvSendIdleCmd(asc_dvc, (ushort)IDLE_CMD_SCSI_RESET_START, 0L);
4389 if (status != ADV_TRUE) {
4390 return status;
4391 }
4392
4393 /*
4394 * Delay for the specified SCSI Bus Reset hold time.
4395 *
4396 * The hold time delay is done on the host because the RISC has no
4397 * microsecond accurate timer.
4398 */
4399 udelay(ASC_SCSI_RESET_HOLD_TIME_US);
4400
4401 /*
4402 * Send the SCSI Bus Reset end idle command which de-asserts
4403 * the SCSI Bus Reset signal and purges any pending requests.
4404 */
4405 status = AdvSendIdleCmd(asc_dvc, (ushort)IDLE_CMD_SCSI_RESET_END, 0L);
4406 if (status != ADV_TRUE) {
4407 return status;
4408 }
4409
4410 mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
4411
4412 return status;
4413}
4414
4415/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004416 * Initialize the ASC-3550.
4417 *
4418 * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
4419 *
4420 * For a non-fatal error return a warning code. If there are no warnings
4421 * then 0 is returned.
4422 *
4423 * Needed after initialization for error recovery.
4424 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004425static int AdvInitAsc3550Driver(ADV_DVC_VAR *asc_dvc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004426{
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304427 const struct firmware *fw;
4428 const char fwname[] = "advansys/3550.bin";
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004429 AdvPortAddr iop_base;
4430 ushort warn_code;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004431 int begin_addr;
4432 int end_addr;
4433 ushort code_sum;
4434 int word;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004435 int i;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304436 int err;
4437 unsigned long chksum;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004438 ushort scsi_cfg1;
4439 uchar tid;
4440 ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
4441 ushort wdtr_able = 0, sdtr_able, tagqng_able;
4442 uchar max_cmd[ADV_MAX_TID + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004443
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004444 /* If there is already an error, don't continue. */
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004445 if (asc_dvc->err_code != 0)
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004446 return ADV_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004447
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004448 /*
4449 * The caller must set 'chip_type' to ADV_CHIP_ASC3550.
4450 */
4451 if (asc_dvc->chip_type != ADV_CHIP_ASC3550) {
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004452 asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004453 return ADV_ERROR;
4454 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004455
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004456 warn_code = 0;
4457 iop_base = asc_dvc->iop_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004459 /*
4460 * Save the RISC memory BIOS region before writing the microcode.
4461 * The BIOS may already be loaded and using its RISC LRAM region
4462 * so its region must be saved and restored.
4463 *
4464 * Note: This code makes the assumption, which is currently true,
4465 * that a chip reset does not clear RISC LRAM.
4466 */
4467 for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
4468 AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
4469 bios_mem[i]);
4470 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004471
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004472 /*
4473 * Save current per TID negotiated values.
4474 */
4475 if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] == 0x55AA) {
4476 ushort bios_version, major, minor;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004477
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004478 bios_version =
4479 bios_mem[(ASC_MC_BIOS_VERSION - ASC_MC_BIOSMEM) / 2];
4480 major = (bios_version >> 12) & 0xF;
4481 minor = (bios_version >> 8) & 0xF;
4482 if (major < 3 || (major == 3 && minor == 1)) {
4483 /* BIOS 3.1 and earlier location of 'wdtr_able' variable. */
4484 AdvReadWordLram(iop_base, 0x120, wdtr_able);
4485 } else {
4486 AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
4487 }
4488 }
4489 AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
4490 AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
4491 for (tid = 0; tid <= ADV_MAX_TID; tid++) {
4492 AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
4493 max_cmd[tid]);
4494 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004495
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304496 err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
4497 if (err) {
4498 printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
4499 fwname, err);
Herton Ronaldo Krzesinskicf747442010-03-19 19:37:26 -03004500 asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304501 return err;
4502 }
4503 if (fw->size < 4) {
4504 printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
4505 fw->size, fwname);
4506 release_firmware(fw);
Herton Ronaldo Krzesinskicf747442010-03-19 19:37:26 -03004507 asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304508 return -EINVAL;
4509 }
4510 chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
4511 (fw->data[1] << 8) | fw->data[0];
4512 asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
4513 fw->size - 4, ADV_3550_MEMSIZE,
4514 chksum);
4515 release_firmware(fw);
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004516 if (asc_dvc->err_code)
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004517 return ADV_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004518
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004519 /*
4520 * Restore the RISC memory BIOS region.
4521 */
4522 for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
4523 AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
4524 bios_mem[i]);
4525 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004526
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004527 /*
4528 * Calculate and write the microcode code checksum to the microcode
4529 * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
4530 */
4531 AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
4532 AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
4533 code_sum = 0;
4534 AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
4535 for (word = begin_addr; word < end_addr; word += 2) {
4536 code_sum += AdvReadWordAutoIncLram(iop_base);
4537 }
4538 AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004539
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004540 /*
4541 * Read and save microcode version and date.
4542 */
4543 AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
4544 asc_dvc->cfg->mcode_date);
4545 AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
4546 asc_dvc->cfg->mcode_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004547
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004548 /*
4549 * Set the chip type to indicate the ASC3550.
4550 */
4551 AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC3550);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004552
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004553 /*
4554 * If the PCI Configuration Command Register "Parity Error Response
4555 * Control" Bit was clear (0), then set the microcode variable
4556 * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
4557 * to ignore DMA parity errors.
4558 */
4559 if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
4560 AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
4561 word |= CONTROL_FLAG_IGNORE_PERR;
4562 AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
4563 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004564
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004565 /*
4566 * For ASC-3550, setting the START_CTL_EMFU [3:2] bits sets a FIFO
4567 * threshold of 128 bytes. This register is only accessible to the host.
4568 */
4569 AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
4570 START_CTL_EMFU | READ_CMD_MRM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004571
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004572 /*
4573 * Microcode operating variables for WDTR, SDTR, and command tag
Matthew Wilcox47d853c2007-07-26 11:41:33 -04004574 * queuing will be set in slave_configure() based on what a
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004575 * device reports it is capable of in Inquiry byte 7.
4576 *
4577 * If SCSI Bus Resets have been disabled, then directly set
4578 * SDTR and WDTR from the EEPROM configuration. This will allow
4579 * the BIOS and warm boot to work without a SCSI bus hang on
4580 * the Inquiry caused by host and target mismatched DTR values.
4581 * Without the SCSI Bus Reset, before an Inquiry a device can't
4582 * be assumed to be in Asynchronous, Narrow mode.
4583 */
4584 if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
4585 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
4586 asc_dvc->wdtr_able);
4587 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
4588 asc_dvc->sdtr_able);
4589 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004590
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004591 /*
4592 * Set microcode operating variables for SDTR_SPEED1, SDTR_SPEED2,
4593 * SDTR_SPEED3, and SDTR_SPEED4 based on the ULTRA EEPROM per TID
4594 * bitmask. These values determine the maximum SDTR speed negotiated
4595 * with a device.
4596 *
4597 * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
4598 * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
4599 * without determining here whether the device supports SDTR.
4600 *
4601 * 4-bit speed SDTR speed name
4602 * =========== ===============
4603 * 0000b (0x0) SDTR disabled
4604 * 0001b (0x1) 5 Mhz
4605 * 0010b (0x2) 10 Mhz
4606 * 0011b (0x3) 20 Mhz (Ultra)
4607 * 0100b (0x4) 40 Mhz (LVD/Ultra2)
4608 * 0101b (0x5) 80 Mhz (LVD2/Ultra3)
4609 * 0110b (0x6) Undefined
4610 * .
4611 * 1111b (0xF) Undefined
4612 */
4613 word = 0;
4614 for (tid = 0; tid <= ADV_MAX_TID; tid++) {
4615 if (ADV_TID_TO_TIDMASK(tid) & asc_dvc->ultra_able) {
4616 /* Set Ultra speed for TID 'tid'. */
4617 word |= (0x3 << (4 * (tid % 4)));
4618 } else {
4619 /* Set Fast speed for TID 'tid'. */
4620 word |= (0x2 << (4 * (tid % 4)));
4621 }
4622 if (tid == 3) { /* Check if done with sdtr_speed1. */
4623 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, word);
4624 word = 0;
4625 } else if (tid == 7) { /* Check if done with sdtr_speed2. */
4626 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, word);
4627 word = 0;
4628 } else if (tid == 11) { /* Check if done with sdtr_speed3. */
4629 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, word);
4630 word = 0;
4631 } else if (tid == 15) { /* Check if done with sdtr_speed4. */
4632 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, word);
4633 /* End of loop. */
4634 }
4635 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004636
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004637 /*
4638 * Set microcode operating variable for the disconnect per TID bitmask.
4639 */
4640 AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
4641 asc_dvc->cfg->disc_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004642
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004643 /*
4644 * Set SCSI_CFG0 Microcode Default Value.
4645 *
4646 * The microcode will set the SCSI_CFG0 register using this value
4647 * after it is started below.
4648 */
4649 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
4650 PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
4651 asc_dvc->chip_scsi_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004652
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004653 /*
4654 * Determine SCSI_CFG1 Microcode Default Value.
4655 *
4656 * The microcode will set the SCSI_CFG1 register using this value
4657 * after it is started below.
4658 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004660 /* Read current SCSI_CFG1 Register value. */
4661 scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004663 /*
4664 * If all three connectors are in use, return an error.
4665 */
4666 if ((scsi_cfg1 & CABLE_ILLEGAL_A) == 0 ||
4667 (scsi_cfg1 & CABLE_ILLEGAL_B) == 0) {
4668 asc_dvc->err_code |= ASC_IERR_ILLEGAL_CONNECTION;
4669 return ADV_ERROR;
4670 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004671
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004672 /*
4673 * If the internal narrow cable is reversed all of the SCSI_CTRL
4674 * register signals will be set. Check for and return an error if
4675 * this condition is found.
4676 */
4677 if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
4678 asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
4679 return ADV_ERROR;
4680 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004681
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004682 /*
4683 * If this is a differential board and a single-ended device
4684 * is attached to one of the connectors, return an error.
4685 */
4686 if ((scsi_cfg1 & DIFF_MODE) && (scsi_cfg1 & DIFF_SENSE) == 0) {
4687 asc_dvc->err_code |= ASC_IERR_SINGLE_END_DEVICE;
4688 return ADV_ERROR;
4689 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004690
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004691 /*
4692 * If automatic termination control is enabled, then set the
4693 * termination value based on a table listed in a_condor.h.
4694 *
4695 * If manual termination was specified with an EEPROM setting
4696 * then 'termination' was set-up in AdvInitFrom3550EEPROM() and
4697 * is ready to be 'ored' into SCSI_CFG1.
4698 */
4699 if (asc_dvc->cfg->termination == 0) {
4700 /*
4701 * The software always controls termination by setting TERM_CTL_SEL.
4702 * If TERM_CTL_SEL were set to 0, the hardware would set termination.
4703 */
4704 asc_dvc->cfg->termination |= TERM_CTL_SEL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004705
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004706 switch (scsi_cfg1 & CABLE_DETECT) {
4707 /* TERM_CTL_H: on, TERM_CTL_L: on */
4708 case 0x3:
4709 case 0x7:
4710 case 0xB:
4711 case 0xD:
4712 case 0xE:
4713 case 0xF:
4714 asc_dvc->cfg->termination |= (TERM_CTL_H | TERM_CTL_L);
4715 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004716
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004717 /* TERM_CTL_H: on, TERM_CTL_L: off */
4718 case 0x1:
4719 case 0x5:
4720 case 0x9:
4721 case 0xA:
4722 case 0xC:
4723 asc_dvc->cfg->termination |= TERM_CTL_H;
4724 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004725
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004726 /* TERM_CTL_H: off, TERM_CTL_L: off */
4727 case 0x2:
4728 case 0x6:
4729 break;
4730 }
4731 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004732
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004733 /*
4734 * Clear any set TERM_CTL_H and TERM_CTL_L bits.
4735 */
4736 scsi_cfg1 &= ~TERM_CTL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004737
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004738 /*
4739 * Invert the TERM_CTL_H and TERM_CTL_L bits and then
4740 * set 'scsi_cfg1'. The TERM_POL bit does not need to be
4741 * referenced, because the hardware internally inverts
4742 * the Termination High and Low bits if TERM_POL is set.
4743 */
4744 scsi_cfg1 |= (TERM_CTL_SEL | (~asc_dvc->cfg->termination & TERM_CTL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004745
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004746 /*
4747 * Set SCSI_CFG1 Microcode Default Value
4748 *
4749 * Set filter value and possibly modified termination control
4750 * bits in the Microcode SCSI_CFG1 Register Value.
4751 *
4752 * The microcode will set the SCSI_CFG1 register using this value
4753 * after it is started below.
4754 */
4755 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1,
4756 FLTR_DISABLE | scsi_cfg1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004757
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004758 /*
4759 * Set MEM_CFG Microcode Default Value
4760 *
4761 * The microcode will set the MEM_CFG register using this value
4762 * after it is started below.
4763 *
4764 * MEM_CFG may be accessed as a word or byte, but only bits 0-7
4765 * are defined.
4766 *
4767 * ASC-3550 has 8KB internal memory.
4768 */
4769 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
4770 BIOS_EN | RAM_SZ_8KB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004771
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004772 /*
4773 * Set SEL_MASK Microcode Default Value
4774 *
4775 * The microcode will set the SEL_MASK register using this value
4776 * after it is started below.
4777 */
4778 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
4779 ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004780
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06004781 AdvBuildCarrierFreelist(asc_dvc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004782
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004783 /*
4784 * Set-up the Host->RISC Initiator Command Queue (ICQ).
4785 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004786
Hannes Reinecke98b96a72015-04-24 13:18:23 +02004787 asc_dvc->icq_sp = adv_get_next_carrier(asc_dvc);
4788 if (!asc_dvc->icq_sp) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004789 asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
4790 return ADV_ERROR;
4791 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004792
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004793 /*
4794 * Set RISC ICQ physical address start value.
4795 */
4796 AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004797
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004798 /*
4799 * Set-up the RISC->Host Initiator Response Queue (IRQ).
4800 */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02004801 asc_dvc->irq_sp = adv_get_next_carrier(asc_dvc);
4802 if (!asc_dvc->irq_sp) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004803 asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
4804 return ADV_ERROR;
4805 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004806
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004807 /*
4808 * Set RISC IRQ physical address start value.
4809 */
4810 AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
4811 asc_dvc->carr_pending_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004812
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004813 AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
4814 (ADV_INTR_ENABLE_HOST_INTR |
4815 ADV_INTR_ENABLE_GLOBAL_INTR));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004816
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004817 AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
4818 AdvWriteWordRegister(iop_base, IOPW_PC, word);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004819
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004820 /* finally, finally, gentlemen, start your engine */
4821 AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004822
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004823 /*
4824 * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
4825 * Resets should be performed. The RISC has to be running
4826 * to issue a SCSI Bus Reset.
4827 */
4828 if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
4829 /*
4830 * If the BIOS Signature is present in memory, restore the
4831 * BIOS Handshake Configuration Table and do not perform
4832 * a SCSI Bus Reset.
4833 */
4834 if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
4835 0x55AA) {
4836 /*
4837 * Restore per TID negotiated values.
4838 */
4839 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
4840 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
4841 AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
4842 tagqng_able);
4843 for (tid = 0; tid <= ADV_MAX_TID; tid++) {
4844 AdvWriteByteLram(iop_base,
4845 ASC_MC_NUMBER_OF_MAX_CMD + tid,
4846 max_cmd[tid]);
4847 }
4848 } else {
4849 if (AdvResetSB(asc_dvc) != ADV_TRUE) {
4850 warn_code = ASC_WARN_BUSRESET_ERROR;
4851 }
4852 }
4853 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004854
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004855 return warn_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004856}
4857
4858/*
4859 * Initialize the ASC-38C0800.
4860 *
4861 * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
4862 *
4863 * For a non-fatal error return a warning code. If there are no warnings
4864 * then 0 is returned.
4865 *
4866 * Needed after initialization for error recovery.
4867 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004868static int AdvInitAsc38C0800Driver(ADV_DVC_VAR *asc_dvc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004869{
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304870 const struct firmware *fw;
4871 const char fwname[] = "advansys/38C0800.bin";
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004872 AdvPortAddr iop_base;
4873 ushort warn_code;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004874 int begin_addr;
4875 int end_addr;
4876 ushort code_sum;
4877 int word;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004878 int i;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304879 int err;
4880 unsigned long chksum;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004881 ushort scsi_cfg1;
4882 uchar byte;
4883 uchar tid;
4884 ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
4885 ushort wdtr_able, sdtr_able, tagqng_able;
4886 uchar max_cmd[ADV_MAX_TID + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004887
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004888 /* If there is already an error, don't continue. */
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004889 if (asc_dvc->err_code != 0)
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004890 return ADV_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004891
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004892 /*
4893 * The caller must set 'chip_type' to ADV_CHIP_ASC38C0800.
4894 */
4895 if (asc_dvc->chip_type != ADV_CHIP_ASC38C0800) {
4896 asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
4897 return ADV_ERROR;
4898 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004899
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004900 warn_code = 0;
4901 iop_base = asc_dvc->iop_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004902
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004903 /*
4904 * Save the RISC memory BIOS region before writing the microcode.
4905 * The BIOS may already be loaded and using its RISC LRAM region
4906 * so its region must be saved and restored.
4907 *
4908 * Note: This code makes the assumption, which is currently true,
4909 * that a chip reset does not clear RISC LRAM.
4910 */
4911 for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
4912 AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
4913 bios_mem[i]);
4914 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004915
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004916 /*
4917 * Save current per TID negotiated values.
4918 */
4919 AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
4920 AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
4921 AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
4922 for (tid = 0; tid <= ADV_MAX_TID; tid++) {
4923 AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
4924 max_cmd[tid]);
4925 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004926
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004927 /*
4928 * RAM BIST (RAM Built-In Self Test)
4929 *
4930 * Address : I/O base + offset 0x38h register (byte).
4931 * Function: Bit 7-6(RW) : RAM mode
4932 * Normal Mode : 0x00
4933 * Pre-test Mode : 0x40
4934 * RAM Test Mode : 0x80
4935 * Bit 5 : unused
4936 * Bit 4(RO) : Done bit
4937 * Bit 3-0(RO) : Status
4938 * Host Error : 0x08
4939 * Int_RAM Error : 0x04
4940 * RISC Error : 0x02
4941 * SCSI Error : 0x01
4942 * No Error : 0x00
4943 *
4944 * Note: RAM BIST code should be put right here, before loading the
4945 * microcode and after saving the RISC memory BIOS region.
4946 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004947
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004948 /*
4949 * LRAM Pre-test
4950 *
4951 * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
4952 * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
4953 * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
4954 * to NORMAL_MODE, return an error too.
4955 */
4956 for (i = 0; i < 2; i++) {
4957 AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
Matthew Wilcoxb009bef2007-09-09 08:56:38 -06004958 mdelay(10); /* Wait for 10ms before reading back. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004959 byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
4960 if ((byte & RAM_TEST_DONE) == 0
4961 || (byte & 0x0F) != PRE_TEST_VALUE) {
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004962 asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004963 return ADV_ERROR;
4964 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004965
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004966 AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
Matthew Wilcoxb009bef2007-09-09 08:56:38 -06004967 mdelay(10); /* Wait for 10ms before reading back. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004968 if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
4969 != NORMAL_VALUE) {
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004970 asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004971 return ADV_ERROR;
4972 }
4973 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004974
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004975 /*
4976 * LRAM Test - It takes about 1.5 ms to run through the test.
4977 *
4978 * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
4979 * If Done bit not set or Status not 0, save register byte, set the
4980 * err_code, and return an error.
4981 */
4982 AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
Matthew Wilcoxb009bef2007-09-09 08:56:38 -06004983 mdelay(10); /* Wait for 10ms before checking status. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004984
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004985 byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
4986 if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
4987 /* Get here if Done bit not set or Status not 0. */
4988 asc_dvc->bist_err_code = byte; /* for BIOS display message */
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06004989 asc_dvc->err_code = ASC_IERR_BIST_RAM_TEST;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004990 return ADV_ERROR;
4991 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004992
Matthew Wilcox27c868c2007-07-26 10:56:23 -04004993 /* We need to reset back to normal mode after LRAM test passes. */
4994 AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004995
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05304996 err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
4997 if (err) {
4998 printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
4999 fwname, err);
Herton Ronaldo Krzesinskicf747442010-03-19 19:37:26 -03005000 asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05305001 return err;
5002 }
5003 if (fw->size < 4) {
5004 printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
5005 fw->size, fwname);
5006 release_firmware(fw);
Herton Ronaldo Krzesinskicf747442010-03-19 19:37:26 -03005007 asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05305008 return -EINVAL;
5009 }
5010 chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
5011 (fw->data[1] << 8) | fw->data[0];
5012 asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
5013 fw->size - 4, ADV_38C0800_MEMSIZE,
5014 chksum);
5015 release_firmware(fw);
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005016 if (asc_dvc->err_code)
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005017 return ADV_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005018
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005019 /*
5020 * Restore the RISC memory BIOS region.
5021 */
5022 for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
5023 AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
5024 bios_mem[i]);
5025 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005026
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005027 /*
5028 * Calculate and write the microcode code checksum to the microcode
5029 * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
5030 */
5031 AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
5032 AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
5033 code_sum = 0;
5034 AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
5035 for (word = begin_addr; word < end_addr; word += 2) {
5036 code_sum += AdvReadWordAutoIncLram(iop_base);
5037 }
5038 AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005039
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005040 /*
5041 * Read microcode version and date.
5042 */
5043 AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
5044 asc_dvc->cfg->mcode_date);
5045 AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
5046 asc_dvc->cfg->mcode_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005047
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005048 /*
5049 * Set the chip type to indicate the ASC38C0800.
5050 */
5051 AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C0800);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005052
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005053 /*
5054 * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
5055 * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
5056 * cable detection and then we are able to read C_DET[3:0].
5057 *
5058 * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
5059 * Microcode Default Value' section below.
5060 */
5061 scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
5062 AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1,
5063 scsi_cfg1 | DIS_TERM_DRV);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005064
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005065 /*
5066 * If the PCI Configuration Command Register "Parity Error Response
5067 * Control" Bit was clear (0), then set the microcode variable
5068 * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
5069 * to ignore DMA parity errors.
5070 */
5071 if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
5072 AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
5073 word |= CONTROL_FLAG_IGNORE_PERR;
5074 AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
5075 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005076
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005077 /*
5078 * For ASC-38C0800, set FIFO_THRESH_80B [6:4] bits and START_CTL_TH [3:2]
5079 * bits for the default FIFO threshold.
5080 *
5081 * Note: ASC-38C0800 FIFO threshold has been changed to 256 bytes.
5082 *
5083 * For DMA Errata #4 set the BC_THRESH_ENB bit.
5084 */
5085 AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
5086 BC_THRESH_ENB | FIFO_THRESH_80B | START_CTL_TH |
5087 READ_CMD_MRM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005088
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005089 /*
5090 * Microcode operating variables for WDTR, SDTR, and command tag
Matthew Wilcox47d853c2007-07-26 11:41:33 -04005091 * queuing will be set in slave_configure() based on what a
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005092 * device reports it is capable of in Inquiry byte 7.
5093 *
5094 * If SCSI Bus Resets have been disabled, then directly set
5095 * SDTR and WDTR from the EEPROM configuration. This will allow
5096 * the BIOS and warm boot to work without a SCSI bus hang on
5097 * the Inquiry caused by host and target mismatched DTR values.
5098 * Without the SCSI Bus Reset, before an Inquiry a device can't
5099 * be assumed to be in Asynchronous, Narrow mode.
5100 */
5101 if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
5102 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
5103 asc_dvc->wdtr_able);
5104 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
5105 asc_dvc->sdtr_able);
5106 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005107
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005108 /*
5109 * Set microcode operating variables for DISC and SDTR_SPEED1,
5110 * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
5111 * configuration values.
5112 *
5113 * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
5114 * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
5115 * without determining here whether the device supports SDTR.
5116 */
5117 AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
5118 asc_dvc->cfg->disc_enable);
5119 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
5120 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
5121 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
5122 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005123
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005124 /*
5125 * Set SCSI_CFG0 Microcode Default Value.
5126 *
5127 * The microcode will set the SCSI_CFG0 register using this value
5128 * after it is started below.
5129 */
5130 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
5131 PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
5132 asc_dvc->chip_scsi_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005133
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005134 /*
5135 * Determine SCSI_CFG1 Microcode Default Value.
5136 *
5137 * The microcode will set the SCSI_CFG1 register using this value
5138 * after it is started below.
5139 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005140
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005141 /* Read current SCSI_CFG1 Register value. */
5142 scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005143
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005144 /*
5145 * If the internal narrow cable is reversed all of the SCSI_CTRL
5146 * register signals will be set. Check for and return an error if
5147 * this condition is found.
5148 */
5149 if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
5150 asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
5151 return ADV_ERROR;
5152 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005153
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005154 /*
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005155 * All kind of combinations of devices attached to one of four
5156 * connectors are acceptable except HVD device attached. For example,
5157 * LVD device can be attached to SE connector while SE device attached
5158 * to LVD connector. If LVD device attached to SE connector, it only
5159 * runs up to Ultra speed.
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005160 *
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005161 * If an HVD device is attached to one of LVD connectors, return an
5162 * error. However, there is no way to detect HVD device attached to
5163 * SE connectors.
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005164 */
5165 if (scsi_cfg1 & HVD) {
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005166 asc_dvc->err_code = ASC_IERR_HVD_DEVICE;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005167 return ADV_ERROR;
5168 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005169
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005170 /*
5171 * If either SE or LVD automatic termination control is enabled, then
5172 * set the termination value based on a table listed in a_condor.h.
5173 *
5174 * If manual termination was specified with an EEPROM setting then
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005175 * 'termination' was set-up in AdvInitFrom38C0800EEPROM() and is ready
5176 * to be 'ored' into SCSI_CFG1.
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005177 */
5178 if ((asc_dvc->cfg->termination & TERM_SE) == 0) {
5179 /* SE automatic termination control is enabled. */
5180 switch (scsi_cfg1 & C_DET_SE) {
5181 /* TERM_SE_HI: on, TERM_SE_LO: on */
5182 case 0x1:
5183 case 0x2:
5184 case 0x3:
5185 asc_dvc->cfg->termination |= TERM_SE;
5186 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005187
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005188 /* TERM_SE_HI: on, TERM_SE_LO: off */
5189 case 0x0:
5190 asc_dvc->cfg->termination |= TERM_SE_HI;
5191 break;
5192 }
5193 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005194
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005195 if ((asc_dvc->cfg->termination & TERM_LVD) == 0) {
5196 /* LVD automatic termination control is enabled. */
5197 switch (scsi_cfg1 & C_DET_LVD) {
5198 /* TERM_LVD_HI: on, TERM_LVD_LO: on */
5199 case 0x4:
5200 case 0x8:
5201 case 0xC:
5202 asc_dvc->cfg->termination |= TERM_LVD;
5203 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005204
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005205 /* TERM_LVD_HI: off, TERM_LVD_LO: off */
5206 case 0x0:
5207 break;
5208 }
5209 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005210
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005211 /*
5212 * Clear any set TERM_SE and TERM_LVD bits.
5213 */
5214 scsi_cfg1 &= (~TERM_SE & ~TERM_LVD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005215
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005216 /*
5217 * Invert the TERM_SE and TERM_LVD bits and then set 'scsi_cfg1'.
5218 */
5219 scsi_cfg1 |= (~asc_dvc->cfg->termination & 0xF0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005220
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005221 /*
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005222 * Clear BIG_ENDIAN, DIS_TERM_DRV, Terminator Polarity and HVD/LVD/SE
5223 * bits and set possibly modified termination control bits in the
5224 * Microcode SCSI_CFG1 Register Value.
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005225 */
5226 scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL & ~HVD_LVD_SE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005227
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005228 /*
5229 * Set SCSI_CFG1 Microcode Default Value
5230 *
5231 * Set possibly modified termination control and reset DIS_TERM_DRV
5232 * bits in the Microcode SCSI_CFG1 Register Value.
5233 *
5234 * The microcode will set the SCSI_CFG1 register using this value
5235 * after it is started below.
5236 */
5237 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005238
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005239 /*
5240 * Set MEM_CFG Microcode Default Value
5241 *
5242 * The microcode will set the MEM_CFG register using this value
5243 * after it is started below.
5244 *
5245 * MEM_CFG may be accessed as a word or byte, but only bits 0-7
5246 * are defined.
5247 *
5248 * ASC-38C0800 has 16KB internal memory.
5249 */
5250 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
5251 BIOS_EN | RAM_SZ_16KB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005252
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005253 /*
5254 * Set SEL_MASK Microcode Default Value
5255 *
5256 * The microcode will set the SEL_MASK register using this value
5257 * after it is started below.
5258 */
5259 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
5260 ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005261
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06005262 AdvBuildCarrierFreelist(asc_dvc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005263
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005264 /*
5265 * Set-up the Host->RISC Initiator Command Queue (ICQ).
5266 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005267
Hannes Reinecke98b96a72015-04-24 13:18:23 +02005268 asc_dvc->icq_sp = adv_get_next_carrier(asc_dvc);
5269 if (!asc_dvc->icq_sp) {
5270 ASC_DBG(0, "Failed to get ICQ carrier\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005271 asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
5272 return ADV_ERROR;
5273 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005274
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005275 /*
5276 * Set RISC ICQ physical address start value.
5277 * carr_pa is LE, must be native before write
5278 */
5279 AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005280
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005281 /*
5282 * Set-up the RISC->Host Initiator Response Queue (IRQ).
5283 */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02005284 asc_dvc->irq_sp = adv_get_next_carrier(asc_dvc);
5285 if (!asc_dvc->irq_sp) {
5286 ASC_DBG(0, "Failed to get IRQ carrier\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005287 asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
5288 return ADV_ERROR;
5289 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005290
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005291 /*
5292 * Set RISC IRQ physical address start value.
5293 *
5294 * carr_pa is LE, must be native before write *
5295 */
5296 AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
5297 asc_dvc->carr_pending_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005298
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005299 AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
5300 (ADV_INTR_ENABLE_HOST_INTR |
5301 ADV_INTR_ENABLE_GLOBAL_INTR));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005302
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005303 AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
5304 AdvWriteWordRegister(iop_base, IOPW_PC, word);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005305
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005306 /* finally, finally, gentlemen, start your engine */
5307 AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005308
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005309 /*
5310 * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
5311 * Resets should be performed. The RISC has to be running
5312 * to issue a SCSI Bus Reset.
5313 */
5314 if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
5315 /*
5316 * If the BIOS Signature is present in memory, restore the
5317 * BIOS Handshake Configuration Table and do not perform
5318 * a SCSI Bus Reset.
5319 */
5320 if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
5321 0x55AA) {
5322 /*
5323 * Restore per TID negotiated values.
5324 */
5325 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
5326 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
5327 AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
5328 tagqng_able);
5329 for (tid = 0; tid <= ADV_MAX_TID; tid++) {
5330 AdvWriteByteLram(iop_base,
5331 ASC_MC_NUMBER_OF_MAX_CMD + tid,
5332 max_cmd[tid]);
5333 }
5334 } else {
5335 if (AdvResetSB(asc_dvc) != ADV_TRUE) {
5336 warn_code = ASC_WARN_BUSRESET_ERROR;
5337 }
5338 }
5339 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005340
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005341 return warn_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005342}
5343
5344/*
5345 * Initialize the ASC-38C1600.
5346 *
5347 * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
5348 *
5349 * For a non-fatal error return a warning code. If there are no warnings
5350 * then 0 is returned.
5351 *
5352 * Needed after initialization for error recovery.
5353 */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005354static int AdvInitAsc38C1600Driver(ADV_DVC_VAR *asc_dvc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005355{
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05305356 const struct firmware *fw;
5357 const char fwname[] = "advansys/38C1600.bin";
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005358 AdvPortAddr iop_base;
5359 ushort warn_code;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005360 int begin_addr;
5361 int end_addr;
5362 ushort code_sum;
5363 long word;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005364 int i;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05305365 int err;
5366 unsigned long chksum;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005367 ushort scsi_cfg1;
5368 uchar byte;
5369 uchar tid;
5370 ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
5371 ushort wdtr_able, sdtr_able, ppr_able, tagqng_able;
5372 uchar max_cmd[ASC_MAX_TID + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005373
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005374 /* If there is already an error, don't continue. */
5375 if (asc_dvc->err_code != 0) {
5376 return ADV_ERROR;
5377 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005378
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005379 /*
5380 * The caller must set 'chip_type' to ADV_CHIP_ASC38C1600.
5381 */
5382 if (asc_dvc->chip_type != ADV_CHIP_ASC38C1600) {
5383 asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
5384 return ADV_ERROR;
5385 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005386
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005387 warn_code = 0;
5388 iop_base = asc_dvc->iop_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005389
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005390 /*
5391 * Save the RISC memory BIOS region before writing the microcode.
5392 * The BIOS may already be loaded and using its RISC LRAM region
5393 * so its region must be saved and restored.
5394 *
5395 * Note: This code makes the assumption, which is currently true,
5396 * that a chip reset does not clear RISC LRAM.
5397 */
5398 for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
5399 AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
5400 bios_mem[i]);
5401 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005402
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005403 /*
5404 * Save current per TID negotiated values.
5405 */
5406 AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
5407 AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
5408 AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
5409 AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
5410 for (tid = 0; tid <= ASC_MAX_TID; tid++) {
5411 AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
5412 max_cmd[tid]);
5413 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005414
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005415 /*
5416 * RAM BIST (Built-In Self Test)
5417 *
5418 * Address : I/O base + offset 0x38h register (byte).
5419 * Function: Bit 7-6(RW) : RAM mode
5420 * Normal Mode : 0x00
5421 * Pre-test Mode : 0x40
5422 * RAM Test Mode : 0x80
5423 * Bit 5 : unused
5424 * Bit 4(RO) : Done bit
5425 * Bit 3-0(RO) : Status
5426 * Host Error : 0x08
5427 * Int_RAM Error : 0x04
5428 * RISC Error : 0x02
5429 * SCSI Error : 0x01
5430 * No Error : 0x00
5431 *
5432 * Note: RAM BIST code should be put right here, before loading the
5433 * microcode and after saving the RISC memory BIOS region.
5434 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005435
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005436 /*
5437 * LRAM Pre-test
5438 *
5439 * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
5440 * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
5441 * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
5442 * to NORMAL_MODE, return an error too.
5443 */
5444 for (i = 0; i < 2; i++) {
5445 AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
Matthew Wilcoxb009bef2007-09-09 08:56:38 -06005446 mdelay(10); /* Wait for 10ms before reading back. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005447 byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
5448 if ((byte & RAM_TEST_DONE) == 0
5449 || (byte & 0x0F) != PRE_TEST_VALUE) {
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005450 asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005451 return ADV_ERROR;
5452 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005453
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005454 AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
Matthew Wilcoxb009bef2007-09-09 08:56:38 -06005455 mdelay(10); /* Wait for 10ms before reading back. */
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005456 if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
5457 != NORMAL_VALUE) {
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005458 asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005459 return ADV_ERROR;
5460 }
5461 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005462
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005463 /*
5464 * LRAM Test - It takes about 1.5 ms to run through the test.
5465 *
5466 * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
5467 * If Done bit not set or Status not 0, save register byte, set the
5468 * err_code, and return an error.
5469 */
5470 AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
Matthew Wilcoxb009bef2007-09-09 08:56:38 -06005471 mdelay(10); /* Wait for 10ms before checking status. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005472
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005473 byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
5474 if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
5475 /* Get here if Done bit not set or Status not 0. */
5476 asc_dvc->bist_err_code = byte; /* for BIOS display message */
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005477 asc_dvc->err_code = ASC_IERR_BIST_RAM_TEST;
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005478 return ADV_ERROR;
5479 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005480
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005481 /* We need to reset back to normal mode after LRAM test passes. */
5482 AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005483
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05305484 err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
5485 if (err) {
5486 printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
5487 fwname, err);
Herton Ronaldo Krzesinskicf747442010-03-19 19:37:26 -03005488 asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05305489 return err;
5490 }
5491 if (fw->size < 4) {
5492 printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
5493 fw->size, fwname);
5494 release_firmware(fw);
Herton Ronaldo Krzesinskicf747442010-03-19 19:37:26 -03005495 asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +05305496 return -EINVAL;
5497 }
5498 chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
5499 (fw->data[1] << 8) | fw->data[0];
5500 asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
5501 fw->size - 4, ADV_38C1600_MEMSIZE,
5502 chksum);
5503 release_firmware(fw);
Matthew Wilcoxb9d96612007-09-09 08:56:28 -06005504 if (asc_dvc->err_code)
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005505 return ADV_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005506
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005507 /*
5508 * Restore the RISC memory BIOS region.
5509 */
5510 for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
5511 AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
5512 bios_mem[i]);
5513 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005514
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005515 /*
5516 * Calculate and write the microcode code checksum to the microcode
5517 * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
5518 */
5519 AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
5520 AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
5521 code_sum = 0;
5522 AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
5523 for (word = begin_addr; word < end_addr; word += 2) {
5524 code_sum += AdvReadWordAutoIncLram(iop_base);
5525 }
5526 AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005527
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005528 /*
5529 * Read microcode version and date.
5530 */
5531 AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
5532 asc_dvc->cfg->mcode_date);
5533 AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
5534 asc_dvc->cfg->mcode_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005535
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005536 /*
5537 * Set the chip type to indicate the ASC38C1600.
5538 */
5539 AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C1600);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005540
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005541 /*
5542 * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
5543 * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
5544 * cable detection and then we are able to read C_DET[3:0].
5545 *
5546 * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
5547 * Microcode Default Value' section below.
5548 */
5549 scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
5550 AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1,
5551 scsi_cfg1 | DIS_TERM_DRV);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005552
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005553 /*
5554 * If the PCI Configuration Command Register "Parity Error Response
5555 * Control" Bit was clear (0), then set the microcode variable
5556 * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
5557 * to ignore DMA parity errors.
5558 */
5559 if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
5560 AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
5561 word |= CONTROL_FLAG_IGNORE_PERR;
5562 AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
5563 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005564
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005565 /*
5566 * If the BIOS control flag AIPP (Asynchronous Information
5567 * Phase Protection) disable bit is not set, then set the firmware
5568 * 'control_flag' CONTROL_FLAG_ENABLE_AIPP bit to enable
5569 * AIPP checking and encoding.
5570 */
5571 if ((asc_dvc->bios_ctrl & BIOS_CTRL_AIPP_DIS) == 0) {
5572 AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
5573 word |= CONTROL_FLAG_ENABLE_AIPP;
5574 AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
5575 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005576
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005577 /*
5578 * For ASC-38C1600 use DMA_CFG0 default values: FIFO_THRESH_80B [6:4],
5579 * and START_CTL_TH [3:2].
5580 */
5581 AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
5582 FIFO_THRESH_80B | START_CTL_TH | READ_CMD_MRM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005583
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005584 /*
5585 * Microcode operating variables for WDTR, SDTR, and command tag
Matthew Wilcox47d853c2007-07-26 11:41:33 -04005586 * queuing will be set in slave_configure() based on what a
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005587 * device reports it is capable of in Inquiry byte 7.
5588 *
5589 * If SCSI Bus Resets have been disabled, then directly set
5590 * SDTR and WDTR from the EEPROM configuration. This will allow
5591 * the BIOS and warm boot to work without a SCSI bus hang on
5592 * the Inquiry caused by host and target mismatched DTR values.
5593 * Without the SCSI Bus Reset, before an Inquiry a device can't
5594 * be assumed to be in Asynchronous, Narrow mode.
5595 */
5596 if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
5597 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
5598 asc_dvc->wdtr_able);
5599 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
5600 asc_dvc->sdtr_able);
5601 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005602
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005603 /*
5604 * Set microcode operating variables for DISC and SDTR_SPEED1,
5605 * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
5606 * configuration values.
5607 *
5608 * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
5609 * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
5610 * without determining here whether the device supports SDTR.
5611 */
5612 AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
5613 asc_dvc->cfg->disc_enable);
5614 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
5615 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
5616 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
5617 AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005618
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005619 /*
5620 * Set SCSI_CFG0 Microcode Default Value.
5621 *
5622 * The microcode will set the SCSI_CFG0 register using this value
5623 * after it is started below.
5624 */
5625 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
5626 PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
5627 asc_dvc->chip_scsi_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005628
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005629 /*
5630 * Calculate SCSI_CFG1 Microcode Default Value.
5631 *
5632 * The microcode will set the SCSI_CFG1 register using this value
5633 * after it is started below.
5634 *
5635 * Each ASC-38C1600 function has only two cable detect bits.
5636 * The bus mode override bits are in IOPB_SOFT_OVER_WR.
5637 */
5638 scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005639
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005640 /*
5641 * If the cable is reversed all of the SCSI_CTRL register signals
5642 * will be set. Check for and return an error if this condition is
5643 * found.
5644 */
5645 if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
5646 asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
5647 return ADV_ERROR;
5648 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005649
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005650 /*
5651 * Each ASC-38C1600 function has two connectors. Only an HVD device
5652 * can not be connected to either connector. An LVD device or SE device
5653 * may be connected to either connecor. If an SE device is connected,
5654 * then at most Ultra speed (20 Mhz) can be used on both connectors.
5655 *
5656 * If an HVD device is attached, return an error.
5657 */
5658 if (scsi_cfg1 & HVD) {
5659 asc_dvc->err_code |= ASC_IERR_HVD_DEVICE;
5660 return ADV_ERROR;
5661 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005662
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005663 /*
5664 * Each function in the ASC-38C1600 uses only the SE cable detect and
5665 * termination because there are two connectors for each function. Each
5666 * function may use either LVD or SE mode. Corresponding the SE automatic
5667 * termination control EEPROM bits are used for each function. Each
5668 * function has its own EEPROM. If SE automatic control is enabled for
5669 * the function, then set the termination value based on a table listed
5670 * in a_condor.h.
5671 *
5672 * If manual termination is specified in the EEPROM for the function,
5673 * then 'termination' was set-up in AscInitFrom38C1600EEPROM() and is
5674 * ready to be 'ored' into SCSI_CFG1.
5675 */
5676 if ((asc_dvc->cfg->termination & TERM_SE) == 0) {
Matthew Wilcox13ac2d92007-07-30 08:10:23 -06005677 struct pci_dev *pdev = adv_dvc_to_pdev(asc_dvc);
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005678 /* SE automatic termination control is enabled. */
5679 switch (scsi_cfg1 & C_DET_SE) {
5680 /* TERM_SE_HI: on, TERM_SE_LO: on */
5681 case 0x1:
5682 case 0x2:
5683 case 0x3:
5684 asc_dvc->cfg->termination |= TERM_SE;
5685 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005686
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005687 case 0x0:
Matthew Wilcox13ac2d92007-07-30 08:10:23 -06005688 if (PCI_FUNC(pdev->devfn) == 0) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005689 /* Function 0 - TERM_SE_HI: off, TERM_SE_LO: off */
5690 } else {
5691 /* Function 1 - TERM_SE_HI: on, TERM_SE_LO: off */
5692 asc_dvc->cfg->termination |= TERM_SE_HI;
5693 }
5694 break;
5695 }
5696 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005697
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005698 /*
5699 * Clear any set TERM_SE bits.
5700 */
5701 scsi_cfg1 &= ~TERM_SE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005702
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005703 /*
5704 * Invert the TERM_SE bits and then set 'scsi_cfg1'.
5705 */
5706 scsi_cfg1 |= (~asc_dvc->cfg->termination & TERM_SE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005707
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005708 /*
5709 * Clear Big Endian and Terminator Polarity bits and set possibly
5710 * modified termination control bits in the Microcode SCSI_CFG1
5711 * Register Value.
5712 *
5713 * Big Endian bit is not used even on big endian machines.
5714 */
5715 scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005716
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005717 /*
5718 * Set SCSI_CFG1 Microcode Default Value
5719 *
5720 * Set possibly modified termination control bits in the Microcode
5721 * SCSI_CFG1 Register Value.
5722 *
5723 * The microcode will set the SCSI_CFG1 register using this value
5724 * after it is started below.
5725 */
5726 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005727
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005728 /*
5729 * Set MEM_CFG Microcode Default Value
5730 *
5731 * The microcode will set the MEM_CFG register using this value
5732 * after it is started below.
5733 *
5734 * MEM_CFG may be accessed as a word or byte, but only bits 0-7
5735 * are defined.
5736 *
5737 * ASC-38C1600 has 32KB internal memory.
5738 *
5739 * XXX - Since ASC38C1600 Rev.3 has a Local RAM failure issue, we come
5740 * out a special 16K Adv Library and Microcode version. After the issue
5741 * resolved, we should turn back to the 32K support. Both a_condor.h and
5742 * mcode.sas files also need to be updated.
5743 *
5744 * AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
5745 * BIOS_EN | RAM_SZ_32KB);
5746 */
5747 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
5748 BIOS_EN | RAM_SZ_16KB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005749
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005750 /*
5751 * Set SEL_MASK Microcode Default Value
5752 *
5753 * The microcode will set the SEL_MASK register using this value
5754 * after it is started below.
5755 */
5756 AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
5757 ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005758
Matthew Wilcoxa9f4a592007-09-09 08:56:27 -06005759 AdvBuildCarrierFreelist(asc_dvc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005760
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005761 /*
5762 * Set-up the Host->RISC Initiator Command Queue (ICQ).
5763 */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02005764 asc_dvc->icq_sp = adv_get_next_carrier(asc_dvc);
5765 if (!asc_dvc->icq_sp) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005766 asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
5767 return ADV_ERROR;
5768 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005769
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005770 /*
5771 * Set RISC ICQ physical address start value. Initialize the
5772 * COMMA register to the same value otherwise the RISC will
5773 * prematurely detect a command is available.
5774 */
5775 AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
5776 AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
5777 le32_to_cpu(asc_dvc->icq_sp->carr_pa));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005778
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005779 /*
5780 * Set-up the RISC->Host Initiator Response Queue (IRQ).
5781 */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02005782 asc_dvc->irq_sp = adv_get_next_carrier(asc_dvc);
5783 if (!asc_dvc->irq_sp) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005784 asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
5785 return ADV_ERROR;
5786 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005787
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005788 /*
5789 * Set RISC IRQ physical address start value.
5790 */
5791 AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
5792 asc_dvc->carr_pending_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005793
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005794 AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
5795 (ADV_INTR_ENABLE_HOST_INTR |
5796 ADV_INTR_ENABLE_GLOBAL_INTR));
5797 AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
5798 AdvWriteWordRegister(iop_base, IOPW_PC, word);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005799
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005800 /* finally, finally, gentlemen, start your engine */
5801 AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005802
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005803 /*
5804 * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
5805 * Resets should be performed. The RISC has to be running
5806 * to issue a SCSI Bus Reset.
5807 */
5808 if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
5809 /*
5810 * If the BIOS Signature is present in memory, restore the
5811 * per TID microcode operating variables.
5812 */
5813 if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
5814 0x55AA) {
5815 /*
5816 * Restore per TID negotiated values.
5817 */
5818 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
5819 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
5820 AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
5821 AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
5822 tagqng_able);
5823 for (tid = 0; tid <= ASC_MAX_TID; tid++) {
5824 AdvWriteByteLram(iop_base,
5825 ASC_MC_NUMBER_OF_MAX_CMD + tid,
5826 max_cmd[tid]);
5827 }
5828 } else {
5829 if (AdvResetSB(asc_dvc) != ADV_TRUE) {
5830 warn_code = ASC_WARN_BUSRESET_ERROR;
5831 }
5832 }
5833 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005834
Matthew Wilcox27c868c2007-07-26 10:56:23 -04005835 return warn_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005836}
5837
5838/*
Matthew Wilcox51219352007-10-02 21:55:22 -04005839 * Reset chip and SCSI Bus.
5840 *
5841 * Return Value:
5842 * ADV_TRUE(1) - Chip re-initialization and SCSI Bus Reset successful.
5843 * ADV_FALSE(0) - Chip re-initialization and SCSI Bus Reset failure.
5844 */
5845static int AdvResetChipAndSB(ADV_DVC_VAR *asc_dvc)
5846{
5847 int status;
5848 ushort wdtr_able, sdtr_able, tagqng_able;
5849 ushort ppr_able = 0;
5850 uchar tid, max_cmd[ADV_MAX_TID + 1];
5851 AdvPortAddr iop_base;
5852 ushort bios_sig;
5853
5854 iop_base = asc_dvc->iop_base;
5855
5856 /*
5857 * Save current per TID negotiated values.
5858 */
5859 AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
5860 AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
5861 if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
5862 AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
5863 }
5864 AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
5865 for (tid = 0; tid <= ADV_MAX_TID; tid++) {
5866 AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
5867 max_cmd[tid]);
5868 }
5869
5870 /*
5871 * Force the AdvInitAsc3550/38C0800Driver() function to
5872 * perform a SCSI Bus Reset by clearing the BIOS signature word.
5873 * The initialization functions assumes a SCSI Bus Reset is not
5874 * needed if the BIOS signature word is present.
5875 */
5876 AdvReadWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
5877 AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, 0);
5878
5879 /*
5880 * Stop chip and reset it.
5881 */
5882 AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_STOP);
5883 AdvWriteWordRegister(iop_base, IOPW_CTRL_REG, ADV_CTRL_REG_CMD_RESET);
5884 mdelay(100);
5885 AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
5886 ADV_CTRL_REG_CMD_WR_IO_REG);
5887
5888 /*
5889 * Reset Adv Library error code, if any, and try
5890 * re-initializing the chip.
5891 */
5892 asc_dvc->err_code = 0;
5893 if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
5894 status = AdvInitAsc38C1600Driver(asc_dvc);
5895 } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
5896 status = AdvInitAsc38C0800Driver(asc_dvc);
5897 } else {
5898 status = AdvInitAsc3550Driver(asc_dvc);
5899 }
5900
5901 /* Translate initialization return value to status value. */
5902 if (status == 0) {
5903 status = ADV_TRUE;
5904 } else {
5905 status = ADV_FALSE;
5906 }
5907
5908 /*
5909 * Restore the BIOS signature word.
5910 */
5911 AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
5912
5913 /*
5914 * Restore per TID negotiated values.
5915 */
5916 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
5917 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
5918 if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
5919 AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
5920 }
5921 AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
5922 for (tid = 0; tid <= ADV_MAX_TID; tid++) {
5923 AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
5924 max_cmd[tid]);
5925 }
5926
5927 return status;
5928}
5929
5930/*
5931 * adv_async_callback() - Adv Library asynchronous event callback function.
5932 */
5933static void adv_async_callback(ADV_DVC_VAR *adv_dvc_varp, uchar code)
5934{
5935 switch (code) {
5936 case ADV_ASYNC_SCSI_BUS_RESET_DET:
5937 /*
5938 * The firmware detected a SCSI Bus reset.
5939 */
Matthew Wilcoxb352f922007-10-02 21:55:33 -04005940 ASC_DBG(0, "ADV_ASYNC_SCSI_BUS_RESET_DET\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04005941 break;
5942
5943 case ADV_ASYNC_RDMA_FAILURE:
5944 /*
5945 * Handle RDMA failure by resetting the SCSI Bus and
5946 * possibly the chip if it is unresponsive. Log the error
5947 * with a unique code.
5948 */
Matthew Wilcoxb352f922007-10-02 21:55:33 -04005949 ASC_DBG(0, "ADV_ASYNC_RDMA_FAILURE\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04005950 AdvResetChipAndSB(adv_dvc_varp);
5951 break;
5952
5953 case ADV_HOST_SCSI_BUS_RESET:
5954 /*
5955 * Host generated SCSI bus reset occurred.
5956 */
Matthew Wilcoxb352f922007-10-02 21:55:33 -04005957 ASC_DBG(0, "ADV_HOST_SCSI_BUS_RESET\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04005958 break;
5959
5960 default:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04005961 ASC_DBG(0, "unknown code 0x%x\n", code);
Matthew Wilcox51219352007-10-02 21:55:22 -04005962 break;
5963 }
5964}
5965
5966/*
5967 * adv_isr_callback() - Second Level Interrupt Handler called by AdvISR().
5968 *
5969 * Callback function for the Wide SCSI Adv Library.
5970 */
5971static void adv_isr_callback(ADV_DVC_VAR *adv_dvc_varp, ADV_SCSI_REQ_Q *scsiqp)
5972{
Hannes Reinecke9c17c622015-04-24 13:18:21 +02005973 struct asc_board *boardp = adv_dvc_varp->drv_ptr;
5974 u32 srb_tag;
Matthew Wilcox51219352007-10-02 21:55:22 -04005975 adv_req_t *reqp;
5976 adv_sgblk_t *sgblkp;
5977 struct scsi_cmnd *scp;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02005978 u32 resid_cnt;
Hannes Reinecke811ddc02015-04-24 13:18:22 +02005979 dma_addr_t sense_addr;
Matthew Wilcox51219352007-10-02 21:55:22 -04005980
Hannes Reinecke9c17c622015-04-24 13:18:21 +02005981 ASC_DBG(1, "adv_dvc_varp 0x%p, scsiqp 0x%p\n",
5982 adv_dvc_varp, scsiqp);
Matthew Wilcox51219352007-10-02 21:55:22 -04005983 ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
5984
5985 /*
5986 * Get the adv_req_t structure for the command that has been
5987 * completed. The adv_req_t structure actually contains the
5988 * completed ADV_SCSI_REQ_Q structure.
5989 */
Hannes Reinecke9c17c622015-04-24 13:18:21 +02005990 srb_tag = le32_to_cpu(scsiqp->srb_tag);
5991 scp = scsi_host_find_tag(boardp->shost, scsiqp->srb_tag);
Matthew Wilcox51219352007-10-02 21:55:22 -04005992
Matthew Wilcoxb352f922007-10-02 21:55:33 -04005993 ASC_DBG(1, "scp 0x%p\n", scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04005994 if (scp == NULL) {
5995 ASC_PRINT
5996 ("adv_isr_callback: scp is NULL; adv_req_t dropped.\n");
5997 return;
5998 }
5999 ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
6000
Hannes Reinecke9c17c622015-04-24 13:18:21 +02006001 reqp = (adv_req_t *)scp->host_scribble;
6002 ASC_DBG(1, "reqp 0x%lx\n", (ulong)reqp);
6003 if (reqp == NULL) {
6004 ASC_PRINT("adv_isr_callback: reqp is NULL\n");
6005 return;
6006 }
6007 /*
6008 * Remove backreferences to avoid duplicate
6009 * command completions.
6010 */
6011 scp->host_scribble = NULL;
6012 reqp->cmndp = NULL;
Matthew Wilcox51219352007-10-02 21:55:22 -04006013
Hannes Reinecke9c17c622015-04-24 13:18:21 +02006014 ASC_STATS(boardp->shost, callback);
6015 ASC_DBG(1, "shost 0x%p\n", boardp->shost);
Matthew Wilcox51219352007-10-02 21:55:22 -04006016
Hannes Reinecke811ddc02015-04-24 13:18:22 +02006017 sense_addr = le32_to_cpu(scsiqp->sense_addr);
6018 dma_unmap_single(boardp->dev, sense_addr,
6019 SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
6020
Matthew Wilcox51219352007-10-02 21:55:22 -04006021 /*
6022 * 'done_status' contains the command's ending status.
6023 */
6024 switch (scsiqp->done_status) {
6025 case QD_NO_ERROR:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006026 ASC_DBG(2, "QD_NO_ERROR\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04006027 scp->result = 0;
6028
6029 /*
6030 * Check for an underrun condition.
6031 *
6032 * If there was no error and an underrun condition, then
6033 * then return the number of underrun bytes.
6034 */
6035 resid_cnt = le32_to_cpu(scsiqp->data_cnt);
Matthew Wilcox52c334e2007-10-02 21:55:39 -04006036 if (scsi_bufflen(scp) != 0 && resid_cnt != 0 &&
6037 resid_cnt <= scsi_bufflen(scp)) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006038 ASC_DBG(1, "underrun condition %lu bytes\n",
Matthew Wilcox51219352007-10-02 21:55:22 -04006039 (ulong)resid_cnt);
Matthew Wilcox52c334e2007-10-02 21:55:39 -04006040 scsi_set_resid(scp, resid_cnt);
Matthew Wilcox51219352007-10-02 21:55:22 -04006041 }
6042 break;
6043
6044 case QD_WITH_ERROR:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006045 ASC_DBG(2, "QD_WITH_ERROR\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04006046 switch (scsiqp->host_status) {
6047 case QHSTA_NO_ERROR:
6048 if (scsiqp->scsi_status == SAM_STAT_CHECK_CONDITION) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006049 ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04006050 ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09006051 SCSI_SENSE_BUFFERSIZE);
Matthew Wilcox51219352007-10-02 21:55:22 -04006052 /*
6053 * Note: The 'status_byte()' macro used by
6054 * target drivers defined in scsi.h shifts the
6055 * status byte returned by host drivers right
6056 * by 1 bit. This is why target drivers also
6057 * use right shifted status byte definitions.
6058 * For instance target drivers use
6059 * CHECK_CONDITION, defined to 0x1, instead of
6060 * the SCSI defined check condition value of
6061 * 0x2. Host drivers are supposed to return
6062 * the status byte as it is defined by SCSI.
6063 */
6064 scp->result = DRIVER_BYTE(DRIVER_SENSE) |
6065 STATUS_BYTE(scsiqp->scsi_status);
6066 } else {
6067 scp->result = STATUS_BYTE(scsiqp->scsi_status);
6068 }
6069 break;
6070
6071 default:
6072 /* Some other QHSTA error occurred. */
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006073 ASC_DBG(1, "host_status 0x%x\n", scsiqp->host_status);
Matthew Wilcox51219352007-10-02 21:55:22 -04006074 scp->result = HOST_BYTE(DID_BAD_TARGET);
6075 break;
6076 }
6077 break;
6078
6079 case QD_ABORTED_BY_HOST:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006080 ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04006081 scp->result =
6082 HOST_BYTE(DID_ABORT) | STATUS_BYTE(scsiqp->scsi_status);
6083 break;
6084
6085 default:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006086 ASC_DBG(1, "done_status 0x%x\n", scsiqp->done_status);
Matthew Wilcox51219352007-10-02 21:55:22 -04006087 scp->result =
6088 HOST_BYTE(DID_ERROR) | STATUS_BYTE(scsiqp->scsi_status);
6089 break;
6090 }
6091
6092 /*
6093 * If the 'init_tidmask' bit isn't already set for the target and the
6094 * current request finished normally, then set the bit for the target
6095 * to indicate that a device is present.
6096 */
6097 if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
6098 scsiqp->done_status == QD_NO_ERROR &&
6099 scsiqp->host_status == QHSTA_NO_ERROR) {
6100 boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
6101 }
6102
6103 asc_scsi_done(scp);
6104
6105 /*
6106 * Free all 'adv_sgblk_t' structures allocated for the request.
6107 */
6108 while ((sgblkp = reqp->sgblkp) != NULL) {
6109 /* Remove 'sgblkp' from the request list. */
6110 reqp->sgblkp = sgblkp->next_sgblkp;
6111
Hannes Reinecke0ce53822015-04-24 13:18:25 +02006112 dma_pool_free(boardp->adv_sgblk_pool, sgblkp,
6113 sgblkp->sg_addr);
Matthew Wilcox51219352007-10-02 21:55:22 -04006114 }
6115
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006116 ASC_DBG(1, "done\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04006117}
6118
6119/*
6120 * Adv Library Interrupt Service Routine
6121 *
6122 * This function is called by a driver's interrupt service routine.
6123 * The function disables and re-enables interrupts.
6124 *
6125 * When a microcode idle command is completed, the ADV_DVC_VAR
6126 * 'idle_cmd_done' field is set to ADV_TRUE.
6127 *
6128 * Note: AdvISR() can be called when interrupts are disabled or even
6129 * when there is no hardware interrupt condition present. It will
6130 * always check for completed idle commands and microcode requests.
6131 * This is an important feature that shouldn't be changed because it
6132 * allows commands to be completed from polling mode loops.
6133 *
6134 * Return:
6135 * ADV_TRUE(1) - interrupt was pending
6136 * ADV_FALSE(0) - no interrupt was pending
6137 */
6138static int AdvISR(ADV_DVC_VAR *asc_dvc)
6139{
6140 AdvPortAddr iop_base;
6141 uchar int_stat;
6142 ushort target_bit;
6143 ADV_CARR_T *free_carrp;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02006144 __le32 irq_next_vpa;
Matthew Wilcox51219352007-10-02 21:55:22 -04006145 ADV_SCSI_REQ_Q *scsiq;
Hannes Reinecke4b47e462015-04-24 13:18:24 +02006146 adv_req_t *reqp;
Matthew Wilcox51219352007-10-02 21:55:22 -04006147
6148 iop_base = asc_dvc->iop_base;
6149
6150 /* Reading the register clears the interrupt. */
6151 int_stat = AdvReadByteRegister(iop_base, IOPB_INTR_STATUS_REG);
6152
6153 if ((int_stat & (ADV_INTR_STATUS_INTRA | ADV_INTR_STATUS_INTRB |
6154 ADV_INTR_STATUS_INTRC)) == 0) {
6155 return ADV_FALSE;
6156 }
6157
6158 /*
6159 * Notify the driver of an asynchronous microcode condition by
6160 * calling the adv_async_callback function. The function
6161 * is passed the microcode ASC_MC_INTRB_CODE byte value.
6162 */
6163 if (int_stat & ADV_INTR_STATUS_INTRB) {
6164 uchar intrb_code;
6165
6166 AdvReadByteLram(iop_base, ASC_MC_INTRB_CODE, intrb_code);
6167
6168 if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
6169 asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
6170 if (intrb_code == ADV_ASYNC_CARRIER_READY_FAILURE &&
6171 asc_dvc->carr_pending_cnt != 0) {
6172 AdvWriteByteRegister(iop_base, IOPB_TICKLE,
6173 ADV_TICKLE_A);
6174 if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
6175 AdvWriteByteRegister(iop_base,
6176 IOPB_TICKLE,
6177 ADV_TICKLE_NOP);
6178 }
6179 }
6180 }
6181
6182 adv_async_callback(asc_dvc, intrb_code);
6183 }
6184
6185 /*
6186 * Check if the IRQ stopper carrier contains a completed request.
6187 */
6188 while (((irq_next_vpa =
Hannes Reinecke084e6c32015-04-24 13:18:35 +02006189 le32_to_cpu(asc_dvc->irq_sp->next_vpa)) & ADV_RQ_DONE) != 0) {
Matthew Wilcox51219352007-10-02 21:55:22 -04006190 /*
6191 * Get a pointer to the newly completed ADV_SCSI_REQ_Q structure.
6192 * The RISC will have set 'areq_vpa' to a virtual address.
6193 *
Hannes Reinecke9fef6ba2015-04-24 13:18:33 +02006194 * The firmware will have copied the ADV_SCSI_REQ_Q.scsiq_ptr
Matthew Wilcox51219352007-10-02 21:55:22 -04006195 * field to the carrier ADV_CARR_T.areq_vpa field. The conversion
Hannes Reinecke9fef6ba2015-04-24 13:18:33 +02006196 * below complements the conversion of ADV_SCSI_REQ_Q.scsiq_ptr'
Matthew Wilcox51219352007-10-02 21:55:22 -04006197 * in AdvExeScsiQueue().
6198 */
Hannes Reinecke4b47e462015-04-24 13:18:24 +02006199 u32 pa_offset = le32_to_cpu(asc_dvc->irq_sp->areq_vpa);
6200 ASC_DBG(1, "irq_sp %p areq_vpa %u\n",
6201 asc_dvc->irq_sp, pa_offset);
6202 reqp = adv_get_reqp(asc_dvc, pa_offset);
6203 scsiq = &reqp->scsi_req_q;
Matthew Wilcox51219352007-10-02 21:55:22 -04006204
6205 /*
6206 * Request finished with good status and the queue was not
6207 * DMAed to host memory by the firmware. Set all status fields
6208 * to indicate good status.
6209 */
Hannes Reinecke084e6c32015-04-24 13:18:35 +02006210 if ((irq_next_vpa & ADV_RQ_GOOD) != 0) {
Matthew Wilcox51219352007-10-02 21:55:22 -04006211 scsiq->done_status = QD_NO_ERROR;
6212 scsiq->host_status = scsiq->scsi_status = 0;
6213 scsiq->data_cnt = 0L;
6214 }
6215
6216 /*
6217 * Advance the stopper pointer to the next carrier
6218 * ignoring the lower four bits. Free the previous
6219 * stopper carrier.
6220 */
6221 free_carrp = asc_dvc->irq_sp;
Hannes Reinecke98b96a72015-04-24 13:18:23 +02006222 asc_dvc->irq_sp = adv_get_carrier(asc_dvc,
Hannes Reinecke084e6c32015-04-24 13:18:35 +02006223 ADV_GET_CARRP(irq_next_vpa));
Matthew Wilcox51219352007-10-02 21:55:22 -04006224
Hannes Reinecke98b96a72015-04-24 13:18:23 +02006225 free_carrp->next_vpa = asc_dvc->carr_freelist->carr_va;
Matthew Wilcox51219352007-10-02 21:55:22 -04006226 asc_dvc->carr_freelist = free_carrp;
6227 asc_dvc->carr_pending_cnt--;
6228
6229 target_bit = ADV_TID_TO_TIDMASK(scsiq->target_id);
6230
6231 /*
6232 * Clear request microcode control flag.
6233 */
6234 scsiq->cntl = 0;
6235
6236 /*
6237 * Notify the driver of the completed request by passing
6238 * the ADV_SCSI_REQ_Q pointer to its callback function.
6239 */
Matthew Wilcox51219352007-10-02 21:55:22 -04006240 adv_isr_callback(asc_dvc, scsiq);
6241 /*
6242 * Note: After the driver callback function is called, 'scsiq'
6243 * can no longer be referenced.
6244 *
6245 * Fall through and continue processing other completed
6246 * requests...
6247 */
6248 }
6249 return ADV_TRUE;
6250}
6251
6252static int AscSetLibErrorCode(ASC_DVC_VAR *asc_dvc, ushort err_code)
6253{
6254 if (asc_dvc->err_code == 0) {
6255 asc_dvc->err_code = err_code;
6256 AscWriteLramWord(asc_dvc->iop_base, ASCV_ASCDVC_ERR_CODE_W,
6257 err_code);
6258 }
6259 return err_code;
6260}
6261
6262static void AscAckInterrupt(PortAddr iop_base)
6263{
6264 uchar host_flag;
6265 uchar risc_flag;
6266 ushort loop;
6267
6268 loop = 0;
6269 do {
6270 risc_flag = AscReadLramByte(iop_base, ASCV_RISC_FLAG_B);
6271 if (loop++ > 0x7FFF) {
6272 break;
6273 }
6274 } while ((risc_flag & ASC_RISC_FLAG_GEN_INT) != 0);
6275 host_flag =
6276 AscReadLramByte(iop_base,
6277 ASCV_HOST_FLAG_B) & (~ASC_HOST_FLAG_ACK_INT);
6278 AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
6279 (uchar)(host_flag | ASC_HOST_FLAG_ACK_INT));
6280 AscSetChipStatus(iop_base, CIW_INT_ACK);
6281 loop = 0;
6282 while (AscGetChipStatus(iop_base) & CSW_INT_PENDING) {
6283 AscSetChipStatus(iop_base, CIW_INT_ACK);
6284 if (loop++ > 3) {
6285 break;
6286 }
6287 }
6288 AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
Matthew Wilcox51219352007-10-02 21:55:22 -04006289}
6290
6291static uchar AscGetSynPeriodIndex(ASC_DVC_VAR *asc_dvc, uchar syn_time)
6292{
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04006293 const uchar *period_table;
Matthew Wilcox51219352007-10-02 21:55:22 -04006294 int max_index;
6295 int min_index;
6296 int i;
6297
6298 period_table = asc_dvc->sdtr_period_tbl;
6299 max_index = (int)asc_dvc->max_sdtr_index;
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04006300 min_index = (int)asc_dvc->min_sdtr_index;
Matthew Wilcox51219352007-10-02 21:55:22 -04006301 if ((syn_time <= period_table[max_index])) {
6302 for (i = min_index; i < (max_index - 1); i++) {
6303 if (syn_time <= period_table[i]) {
6304 return (uchar)i;
6305 }
6306 }
6307 return (uchar)max_index;
6308 } else {
6309 return (uchar)(max_index + 1);
6310 }
6311}
6312
6313static uchar
6314AscMsgOutSDTR(ASC_DVC_VAR *asc_dvc, uchar sdtr_period, uchar sdtr_offset)
6315{
6316 EXT_MSG sdtr_buf;
6317 uchar sdtr_period_index;
6318 PortAddr iop_base;
6319
6320 iop_base = asc_dvc->iop_base;
6321 sdtr_buf.msg_type = EXTENDED_MESSAGE;
6322 sdtr_buf.msg_len = MS_SDTR_LEN;
6323 sdtr_buf.msg_req = EXTENDED_SDTR;
6324 sdtr_buf.xfer_period = sdtr_period;
6325 sdtr_offset &= ASC_SYN_MAX_OFFSET;
6326 sdtr_buf.req_ack_offset = sdtr_offset;
6327 sdtr_period_index = AscGetSynPeriodIndex(asc_dvc, sdtr_period);
6328 if (sdtr_period_index <= asc_dvc->max_sdtr_index) {
6329 AscMemWordCopyPtrToLram(iop_base, ASCV_MSGOUT_BEG,
6330 (uchar *)&sdtr_buf,
6331 sizeof(EXT_MSG) >> 1);
6332 return ((sdtr_period_index << 4) | sdtr_offset);
6333 } else {
6334 sdtr_buf.req_ack_offset = 0;
6335 AscMemWordCopyPtrToLram(iop_base, ASCV_MSGOUT_BEG,
6336 (uchar *)&sdtr_buf,
6337 sizeof(EXT_MSG) >> 1);
6338 return 0;
6339 }
6340}
6341
6342static uchar
6343AscCalSDTRData(ASC_DVC_VAR *asc_dvc, uchar sdtr_period, uchar syn_offset)
6344{
6345 uchar byte;
6346 uchar sdtr_period_ix;
6347
6348 sdtr_period_ix = AscGetSynPeriodIndex(asc_dvc, sdtr_period);
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04006349 if (sdtr_period_ix > asc_dvc->max_sdtr_index)
Matthew Wilcox51219352007-10-02 21:55:22 -04006350 return 0xFF;
Matthew Wilcox51219352007-10-02 21:55:22 -04006351 byte = (sdtr_period_ix << 4) | (syn_offset & ASC_SYN_MAX_OFFSET);
6352 return byte;
6353}
6354
Hannes Reinecked647c782015-04-24 13:18:26 +02006355static bool AscSetChipSynRegAtID(PortAddr iop_base, uchar id, uchar sdtr_data)
Matthew Wilcox51219352007-10-02 21:55:22 -04006356{
6357 ASC_SCSI_BIT_ID_TYPE org_id;
6358 int i;
Hannes Reinecked647c782015-04-24 13:18:26 +02006359 bool sta = true;
Matthew Wilcox51219352007-10-02 21:55:22 -04006360
6361 AscSetBank(iop_base, 1);
6362 org_id = AscReadChipDvcID(iop_base);
6363 for (i = 0; i <= ASC_MAX_TID; i++) {
6364 if (org_id == (0x01 << i))
6365 break;
6366 }
6367 org_id = (ASC_SCSI_BIT_ID_TYPE) i;
6368 AscWriteChipDvcID(iop_base, id);
6369 if (AscReadChipDvcID(iop_base) == (0x01 << id)) {
6370 AscSetBank(iop_base, 0);
6371 AscSetChipSyn(iop_base, sdtr_data);
6372 if (AscGetChipSyn(iop_base) != sdtr_data) {
Hannes Reinecked647c782015-04-24 13:18:26 +02006373 sta = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04006374 }
6375 } else {
Hannes Reinecked647c782015-04-24 13:18:26 +02006376 sta = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04006377 }
6378 AscSetBank(iop_base, 1);
6379 AscWriteChipDvcID(iop_base, org_id);
6380 AscSetBank(iop_base, 0);
6381 return (sta);
6382}
6383
6384static void AscSetChipSDTR(PortAddr iop_base, uchar sdtr_data, uchar tid_no)
6385{
6386 AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
6387 AscPutMCodeSDTRDoneAtID(iop_base, tid_no, sdtr_data);
6388}
6389
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006390static void AscIsrChipHalted(ASC_DVC_VAR *asc_dvc)
Matthew Wilcox51219352007-10-02 21:55:22 -04006391{
6392 EXT_MSG ext_msg;
6393 EXT_MSG out_msg;
6394 ushort halt_q_addr;
Hannes Reineckeae267592015-04-24 13:18:28 +02006395 bool sdtr_accept;
Matthew Wilcox51219352007-10-02 21:55:22 -04006396 ushort int_halt_code;
6397 ASC_SCSI_BIT_ID_TYPE scsi_busy;
6398 ASC_SCSI_BIT_ID_TYPE target_id;
6399 PortAddr iop_base;
6400 uchar tag_code;
6401 uchar q_status;
6402 uchar halt_qp;
6403 uchar sdtr_data;
6404 uchar target_ix;
6405 uchar q_cntl, tid_no;
6406 uchar cur_dvc_qng;
6407 uchar asyn_sdtr;
6408 uchar scsi_status;
Matthew Wilcoxd2411492007-10-02 21:55:31 -04006409 struct asc_board *boardp;
Matthew Wilcox51219352007-10-02 21:55:22 -04006410
6411 BUG_ON(!asc_dvc->drv_ptr);
6412 boardp = asc_dvc->drv_ptr;
6413
6414 iop_base = asc_dvc->iop_base;
6415 int_halt_code = AscReadLramWord(iop_base, ASCV_HALTCODE_W);
6416
6417 halt_qp = AscReadLramByte(iop_base, ASCV_CURCDB_B);
6418 halt_q_addr = ASC_QNO_TO_QADDR(halt_qp);
6419 target_ix = AscReadLramByte(iop_base,
6420 (ushort)(halt_q_addr +
6421 (ushort)ASC_SCSIQ_B_TARGET_IX));
6422 q_cntl = AscReadLramByte(iop_base,
6423 (ushort)(halt_q_addr + (ushort)ASC_SCSIQ_B_CNTL));
6424 tid_no = ASC_TIX_TO_TID(target_ix);
6425 target_id = (uchar)ASC_TID_TO_TARGET_ID(tid_no);
6426 if (asc_dvc->pci_fix_asyn_xfer & target_id) {
6427 asyn_sdtr = ASYN_SDTR_DATA_FIX_PCI_REV_AB;
6428 } else {
6429 asyn_sdtr = 0;
6430 }
6431 if (int_halt_code == ASC_HALT_DISABLE_ASYN_USE_SYN_FIX) {
6432 if (asc_dvc->pci_fix_asyn_xfer & target_id) {
6433 AscSetChipSDTR(iop_base, 0, tid_no);
6434 boardp->sdtr_data[tid_no] = 0;
6435 }
6436 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006437 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006438 } else if (int_halt_code == ASC_HALT_ENABLE_ASYN_USE_SYN_FIX) {
6439 if (asc_dvc->pci_fix_asyn_xfer & target_id) {
6440 AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
6441 boardp->sdtr_data[tid_no] = asyn_sdtr;
6442 }
6443 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006444 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006445 } else if (int_halt_code == ASC_HALT_EXTMSG_IN) {
6446 AscMemWordCopyPtrFromLram(iop_base,
6447 ASCV_MSGIN_BEG,
6448 (uchar *)&ext_msg,
6449 sizeof(EXT_MSG) >> 1);
6450
6451 if (ext_msg.msg_type == EXTENDED_MESSAGE &&
6452 ext_msg.msg_req == EXTENDED_SDTR &&
6453 ext_msg.msg_len == MS_SDTR_LEN) {
Hannes Reineckeae267592015-04-24 13:18:28 +02006454 sdtr_accept = true;
Matthew Wilcox51219352007-10-02 21:55:22 -04006455 if ((ext_msg.req_ack_offset > ASC_SYN_MAX_OFFSET)) {
6456
Hannes Reineckeae267592015-04-24 13:18:28 +02006457 sdtr_accept = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04006458 ext_msg.req_ack_offset = ASC_SYN_MAX_OFFSET;
6459 }
6460 if ((ext_msg.xfer_period <
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04006461 asc_dvc->sdtr_period_tbl[asc_dvc->min_sdtr_index])
Matthew Wilcox51219352007-10-02 21:55:22 -04006462 || (ext_msg.xfer_period >
6463 asc_dvc->sdtr_period_tbl[asc_dvc->
6464 max_sdtr_index])) {
Hannes Reineckeae267592015-04-24 13:18:28 +02006465 sdtr_accept = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04006466 ext_msg.xfer_period =
6467 asc_dvc->sdtr_period_tbl[asc_dvc->
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04006468 min_sdtr_index];
Matthew Wilcox51219352007-10-02 21:55:22 -04006469 }
6470 if (sdtr_accept) {
6471 sdtr_data =
6472 AscCalSDTRData(asc_dvc, ext_msg.xfer_period,
6473 ext_msg.req_ack_offset);
6474 if ((sdtr_data == 0xFF)) {
6475
6476 q_cntl |= QC_MSG_OUT;
6477 asc_dvc->init_sdtr &= ~target_id;
6478 asc_dvc->sdtr_done &= ~target_id;
6479 AscSetChipSDTR(iop_base, asyn_sdtr,
6480 tid_no);
6481 boardp->sdtr_data[tid_no] = asyn_sdtr;
6482 }
6483 }
6484 if (ext_msg.req_ack_offset == 0) {
6485
6486 q_cntl &= ~QC_MSG_OUT;
6487 asc_dvc->init_sdtr &= ~target_id;
6488 asc_dvc->sdtr_done &= ~target_id;
6489 AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
6490 } else {
6491 if (sdtr_accept && (q_cntl & QC_MSG_OUT)) {
Matthew Wilcox51219352007-10-02 21:55:22 -04006492 q_cntl &= ~QC_MSG_OUT;
6493 asc_dvc->sdtr_done |= target_id;
6494 asc_dvc->init_sdtr |= target_id;
6495 asc_dvc->pci_fix_asyn_xfer &=
6496 ~target_id;
6497 sdtr_data =
6498 AscCalSDTRData(asc_dvc,
6499 ext_msg.xfer_period,
6500 ext_msg.
6501 req_ack_offset);
6502 AscSetChipSDTR(iop_base, sdtr_data,
6503 tid_no);
6504 boardp->sdtr_data[tid_no] = sdtr_data;
6505 } else {
Matthew Wilcox51219352007-10-02 21:55:22 -04006506 q_cntl |= QC_MSG_OUT;
6507 AscMsgOutSDTR(asc_dvc,
6508 ext_msg.xfer_period,
6509 ext_msg.req_ack_offset);
6510 asc_dvc->pci_fix_asyn_xfer &=
6511 ~target_id;
6512 sdtr_data =
6513 AscCalSDTRData(asc_dvc,
6514 ext_msg.xfer_period,
6515 ext_msg.
6516 req_ack_offset);
6517 AscSetChipSDTR(iop_base, sdtr_data,
6518 tid_no);
6519 boardp->sdtr_data[tid_no] = sdtr_data;
6520 asc_dvc->sdtr_done |= target_id;
6521 asc_dvc->init_sdtr |= target_id;
6522 }
6523 }
6524
6525 AscWriteLramByte(iop_base,
6526 (ushort)(halt_q_addr +
6527 (ushort)ASC_SCSIQ_B_CNTL),
6528 q_cntl);
6529 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006530 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006531 } else if (ext_msg.msg_type == EXTENDED_MESSAGE &&
6532 ext_msg.msg_req == EXTENDED_WDTR &&
6533 ext_msg.msg_len == MS_WDTR_LEN) {
6534
6535 ext_msg.wdtr_width = 0;
6536 AscMemWordCopyPtrToLram(iop_base,
6537 ASCV_MSGOUT_BEG,
6538 (uchar *)&ext_msg,
6539 sizeof(EXT_MSG) >> 1);
6540 q_cntl |= QC_MSG_OUT;
6541 AscWriteLramByte(iop_base,
6542 (ushort)(halt_q_addr +
6543 (ushort)ASC_SCSIQ_B_CNTL),
6544 q_cntl);
6545 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006546 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006547 } else {
6548
6549 ext_msg.msg_type = MESSAGE_REJECT;
6550 AscMemWordCopyPtrToLram(iop_base,
6551 ASCV_MSGOUT_BEG,
6552 (uchar *)&ext_msg,
6553 sizeof(EXT_MSG) >> 1);
6554 q_cntl |= QC_MSG_OUT;
6555 AscWriteLramByte(iop_base,
6556 (ushort)(halt_q_addr +
6557 (ushort)ASC_SCSIQ_B_CNTL),
6558 q_cntl);
6559 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006560 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006561 }
6562 } else if (int_halt_code == ASC_HALT_CHK_CONDITION) {
6563
6564 q_cntl |= QC_REQ_SENSE;
6565
6566 if ((asc_dvc->init_sdtr & target_id) != 0) {
6567
6568 asc_dvc->sdtr_done &= ~target_id;
6569
6570 sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
6571 q_cntl |= QC_MSG_OUT;
6572 AscMsgOutSDTR(asc_dvc,
6573 asc_dvc->
6574 sdtr_period_tbl[(sdtr_data >> 4) &
6575 (uchar)(asc_dvc->
6576 max_sdtr_index -
6577 1)],
6578 (uchar)(sdtr_data & (uchar)
6579 ASC_SYN_MAX_OFFSET));
6580 }
6581
6582 AscWriteLramByte(iop_base,
6583 (ushort)(halt_q_addr +
6584 (ushort)ASC_SCSIQ_B_CNTL), q_cntl);
6585
6586 tag_code = AscReadLramByte(iop_base,
6587 (ushort)(halt_q_addr + (ushort)
6588 ASC_SCSIQ_B_TAG_CODE));
6589 tag_code &= 0xDC;
6590 if ((asc_dvc->pci_fix_asyn_xfer & target_id)
6591 && !(asc_dvc->pci_fix_asyn_xfer_always & target_id)
6592 ) {
6593
6594 tag_code |= (ASC_TAG_FLAG_DISABLE_DISCONNECT
6595 | ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX);
6596
6597 }
6598 AscWriteLramByte(iop_base,
6599 (ushort)(halt_q_addr +
6600 (ushort)ASC_SCSIQ_B_TAG_CODE),
6601 tag_code);
6602
6603 q_status = AscReadLramByte(iop_base,
6604 (ushort)(halt_q_addr + (ushort)
6605 ASC_SCSIQ_B_STATUS));
6606 q_status |= (QS_READY | QS_BUSY);
6607 AscWriteLramByte(iop_base,
6608 (ushort)(halt_q_addr +
6609 (ushort)ASC_SCSIQ_B_STATUS),
6610 q_status);
6611
6612 scsi_busy = AscReadLramByte(iop_base, (ushort)ASCV_SCSIBUSY_B);
6613 scsi_busy &= ~target_id;
6614 AscWriteLramByte(iop_base, (ushort)ASCV_SCSIBUSY_B, scsi_busy);
6615
6616 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006617 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006618 } else if (int_halt_code == ASC_HALT_SDTR_REJECTED) {
6619
6620 AscMemWordCopyPtrFromLram(iop_base,
6621 ASCV_MSGOUT_BEG,
6622 (uchar *)&out_msg,
6623 sizeof(EXT_MSG) >> 1);
6624
6625 if ((out_msg.msg_type == EXTENDED_MESSAGE) &&
6626 (out_msg.msg_len == MS_SDTR_LEN) &&
6627 (out_msg.msg_req == EXTENDED_SDTR)) {
6628
6629 asc_dvc->init_sdtr &= ~target_id;
6630 asc_dvc->sdtr_done &= ~target_id;
6631 AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
6632 boardp->sdtr_data[tid_no] = asyn_sdtr;
6633 }
6634 q_cntl &= ~QC_MSG_OUT;
6635 AscWriteLramByte(iop_base,
6636 (ushort)(halt_q_addr +
6637 (ushort)ASC_SCSIQ_B_CNTL), q_cntl);
6638 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006639 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006640 } else if (int_halt_code == ASC_HALT_SS_QUEUE_FULL) {
6641
6642 scsi_status = AscReadLramByte(iop_base,
6643 (ushort)((ushort)halt_q_addr +
6644 (ushort)
6645 ASC_SCSIQ_SCSI_STATUS));
6646 cur_dvc_qng =
6647 AscReadLramByte(iop_base,
6648 (ushort)((ushort)ASC_QADR_BEG +
6649 (ushort)target_ix));
6650 if ((cur_dvc_qng > 0) && (asc_dvc->cur_dvc_qng[tid_no] > 0)) {
6651
6652 scsi_busy = AscReadLramByte(iop_base,
6653 (ushort)ASCV_SCSIBUSY_B);
6654 scsi_busy |= target_id;
6655 AscWriteLramByte(iop_base,
6656 (ushort)ASCV_SCSIBUSY_B, scsi_busy);
6657 asc_dvc->queue_full_or_busy |= target_id;
6658
6659 if (scsi_status == SAM_STAT_TASK_SET_FULL) {
6660 if (cur_dvc_qng > ASC_MIN_TAGGED_CMD) {
6661 cur_dvc_qng -= 1;
6662 asc_dvc->max_dvc_qng[tid_no] =
6663 cur_dvc_qng;
6664
6665 AscWriteLramByte(iop_base,
6666 (ushort)((ushort)
6667 ASCV_MAX_DVC_QNG_BEG
6668 + (ushort)
6669 tid_no),
6670 cur_dvc_qng);
6671
6672 /*
6673 * Set the device queue depth to the
6674 * number of active requests when the
6675 * QUEUE FULL condition was encountered.
6676 */
6677 boardp->queue_full |= target_id;
6678 boardp->queue_full_cnt[tid_no] =
6679 cur_dvc_qng;
6680 }
6681 }
6682 }
6683 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006684 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006685 }
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02006686 return;
Matthew Wilcox51219352007-10-02 21:55:22 -04006687}
6688
6689/*
6690 * void
6691 * DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
6692 *
6693 * Calling/Exit State:
6694 * none
6695 *
6696 * Description:
6697 * Input an ASC_QDONE_INFO structure from the chip
6698 */
6699static void
6700DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
6701{
6702 int i;
6703 ushort word;
6704
6705 AscSetChipLramAddr(iop_base, s_addr);
6706 for (i = 0; i < 2 * words; i += 2) {
6707 if (i == 10) {
6708 continue;
6709 }
6710 word = inpw(iop_base + IOP_RAM_DATA);
6711 inbuf[i] = word & 0xff;
6712 inbuf[i + 1] = (word >> 8) & 0xff;
6713 }
6714 ASC_DBG_PRT_HEX(2, "DvcGetQinfo", inbuf, 2 * words);
6715}
6716
6717static uchar
6718_AscCopyLramScsiDoneQ(PortAddr iop_base,
6719 ushort q_addr,
Hannes Reinecke95cfab62015-04-24 13:18:27 +02006720 ASC_QDONE_INFO *scsiq, unsigned int max_dma_count)
Matthew Wilcox51219352007-10-02 21:55:22 -04006721{
6722 ushort _val;
6723 uchar sg_queue_cnt;
6724
6725 DvcGetQinfo(iop_base,
6726 q_addr + ASC_SCSIQ_DONE_INFO_BEG,
6727 (uchar *)scsiq,
6728 (sizeof(ASC_SCSIQ_2) + sizeof(ASC_SCSIQ_3)) / 2);
6729
6730 _val = AscReadLramWord(iop_base,
6731 (ushort)(q_addr + (ushort)ASC_SCSIQ_B_STATUS));
6732 scsiq->q_status = (uchar)_val;
6733 scsiq->q_no = (uchar)(_val >> 8);
6734 _val = AscReadLramWord(iop_base,
6735 (ushort)(q_addr + (ushort)ASC_SCSIQ_B_CNTL));
6736 scsiq->cntl = (uchar)_val;
6737 sg_queue_cnt = (uchar)(_val >> 8);
6738 _val = AscReadLramWord(iop_base,
6739 (ushort)(q_addr +
6740 (ushort)ASC_SCSIQ_B_SENSE_LEN));
6741 scsiq->sense_len = (uchar)_val;
6742 scsiq->extra_bytes = (uchar)(_val >> 8);
6743
6744 /*
6745 * Read high word of remain bytes from alternate location.
6746 */
Hannes Reinecke95cfab62015-04-24 13:18:27 +02006747 scsiq->remain_bytes = (((u32)AscReadLramWord(iop_base,
6748 (ushort)(q_addr +
6749 (ushort)
6750 ASC_SCSIQ_W_ALT_DC1)))
Matthew Wilcox51219352007-10-02 21:55:22 -04006751 << 16);
6752 /*
6753 * Read low word of remain bytes from original location.
6754 */
6755 scsiq->remain_bytes += AscReadLramWord(iop_base,
6756 (ushort)(q_addr + (ushort)
6757 ASC_SCSIQ_DW_REMAIN_XFER_CNT));
6758
6759 scsiq->remain_bytes &= max_dma_count;
6760 return sg_queue_cnt;
6761}
6762
6763/*
6764 * asc_isr_callback() - Second Level Interrupt Handler called by AscISR().
6765 *
6766 * Interrupt callback function for the Narrow SCSI Asc Library.
6767 */
6768static void asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep)
6769{
Hannes Reinecke9c17c622015-04-24 13:18:21 +02006770 struct asc_board *boardp = asc_dvc_varp->drv_ptr;
6771 u32 srb_tag;
Matthew Wilcox51219352007-10-02 21:55:22 -04006772 struct scsi_cmnd *scp;
Matthew Wilcox51219352007-10-02 21:55:22 -04006773
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006774 ASC_DBG(1, "asc_dvc_varp 0x%p, qdonep 0x%p\n", asc_dvc_varp, qdonep);
Matthew Wilcox51219352007-10-02 21:55:22 -04006775 ASC_DBG_PRT_ASC_QDONE_INFO(2, qdonep);
6776
Hannes Reinecke9c17c622015-04-24 13:18:21 +02006777 /*
6778 * Decrease the srb_tag by 1 to find the SCSI command
6779 */
6780 srb_tag = qdonep->d2.srb_tag - 1;
6781 scp = scsi_host_find_tag(boardp->shost, srb_tag);
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04006782 if (!scp)
Matthew Wilcox51219352007-10-02 21:55:22 -04006783 return;
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04006784
Matthew Wilcox51219352007-10-02 21:55:22 -04006785 ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
6786
Hannes Reinecke9c17c622015-04-24 13:18:21 +02006787 ASC_STATS(boardp->shost, callback);
Matthew Wilcox51219352007-10-02 21:55:22 -04006788
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04006789 dma_unmap_single(boardp->dev, scp->SCp.dma_handle,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09006790 SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
Matthew Wilcox51219352007-10-02 21:55:22 -04006791 /*
6792 * 'qdonep' contains the command's ending status.
6793 */
6794 switch (qdonep->d3.done_stat) {
6795 case QD_NO_ERROR:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006796 ASC_DBG(2, "QD_NO_ERROR\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04006797 scp->result = 0;
6798
6799 /*
6800 * Check for an underrun condition.
6801 *
6802 * If there was no error and an underrun condition, then
6803 * return the number of underrun bytes.
6804 */
Matthew Wilcox52c334e2007-10-02 21:55:39 -04006805 if (scsi_bufflen(scp) != 0 && qdonep->remain_bytes != 0 &&
6806 qdonep->remain_bytes <= scsi_bufflen(scp)) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006807 ASC_DBG(1, "underrun condition %u bytes\n",
Matthew Wilcox51219352007-10-02 21:55:22 -04006808 (unsigned)qdonep->remain_bytes);
Matthew Wilcox52c334e2007-10-02 21:55:39 -04006809 scsi_set_resid(scp, qdonep->remain_bytes);
Matthew Wilcox51219352007-10-02 21:55:22 -04006810 }
6811 break;
6812
6813 case QD_WITH_ERROR:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006814 ASC_DBG(2, "QD_WITH_ERROR\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04006815 switch (qdonep->d3.host_stat) {
6816 case QHSTA_NO_ERROR:
6817 if (qdonep->d3.scsi_stat == SAM_STAT_CHECK_CONDITION) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006818 ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04006819 ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09006820 SCSI_SENSE_BUFFERSIZE);
Matthew Wilcox51219352007-10-02 21:55:22 -04006821 /*
6822 * Note: The 'status_byte()' macro used by
6823 * target drivers defined in scsi.h shifts the
6824 * status byte returned by host drivers right
6825 * by 1 bit. This is why target drivers also
6826 * use right shifted status byte definitions.
6827 * For instance target drivers use
6828 * CHECK_CONDITION, defined to 0x1, instead of
6829 * the SCSI defined check condition value of
6830 * 0x2. Host drivers are supposed to return
6831 * the status byte as it is defined by SCSI.
6832 */
6833 scp->result = DRIVER_BYTE(DRIVER_SENSE) |
6834 STATUS_BYTE(qdonep->d3.scsi_stat);
6835 } else {
6836 scp->result = STATUS_BYTE(qdonep->d3.scsi_stat);
6837 }
6838 break;
6839
6840 default:
6841 /* QHSTA error occurred */
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006842 ASC_DBG(1, "host_stat 0x%x\n", qdonep->d3.host_stat);
Matthew Wilcox51219352007-10-02 21:55:22 -04006843 scp->result = HOST_BYTE(DID_BAD_TARGET);
6844 break;
6845 }
6846 break;
6847
6848 case QD_ABORTED_BY_HOST:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006849 ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04006850 scp->result =
6851 HOST_BYTE(DID_ABORT) | MSG_BYTE(qdonep->d3.
6852 scsi_msg) |
6853 STATUS_BYTE(qdonep->d3.scsi_stat);
6854 break;
6855
6856 default:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04006857 ASC_DBG(1, "done_stat 0x%x\n", qdonep->d3.done_stat);
Matthew Wilcox51219352007-10-02 21:55:22 -04006858 scp->result =
6859 HOST_BYTE(DID_ERROR) | MSG_BYTE(qdonep->d3.
6860 scsi_msg) |
6861 STATUS_BYTE(qdonep->d3.scsi_stat);
6862 break;
6863 }
6864
6865 /*
6866 * If the 'init_tidmask' bit isn't already set for the target and the
6867 * current request finished normally, then set the bit for the target
6868 * to indicate that a device is present.
6869 */
6870 if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
6871 qdonep->d3.done_stat == QD_NO_ERROR &&
6872 qdonep->d3.host_stat == QHSTA_NO_ERROR) {
6873 boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
6874 }
6875
6876 asc_scsi_done(scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04006877}
6878
6879static int AscIsrQDone(ASC_DVC_VAR *asc_dvc)
6880{
6881 uchar next_qp;
6882 uchar n_q_used;
6883 uchar sg_list_qp;
6884 uchar sg_queue_cnt;
6885 uchar q_cnt;
6886 uchar done_q_tail;
6887 uchar tid_no;
6888 ASC_SCSI_BIT_ID_TYPE scsi_busy;
6889 ASC_SCSI_BIT_ID_TYPE target_id;
6890 PortAddr iop_base;
6891 ushort q_addr;
6892 ushort sg_q_addr;
6893 uchar cur_target_qng;
6894 ASC_QDONE_INFO scsiq_buf;
6895 ASC_QDONE_INFO *scsiq;
Hannes Reineckeae267592015-04-24 13:18:28 +02006896 bool false_overrun;
Matthew Wilcox51219352007-10-02 21:55:22 -04006897
6898 iop_base = asc_dvc->iop_base;
6899 n_q_used = 1;
6900 scsiq = (ASC_QDONE_INFO *)&scsiq_buf;
6901 done_q_tail = (uchar)AscGetVarDoneQTail(iop_base);
6902 q_addr = ASC_QNO_TO_QADDR(done_q_tail);
6903 next_qp = AscReadLramByte(iop_base,
6904 (ushort)(q_addr + (ushort)ASC_SCSIQ_B_FWD));
6905 if (next_qp != ASC_QLINK_END) {
6906 AscPutVarDoneQTail(iop_base, next_qp);
6907 q_addr = ASC_QNO_TO_QADDR(next_qp);
6908 sg_queue_cnt = _AscCopyLramScsiDoneQ(iop_base, q_addr, scsiq,
6909 asc_dvc->max_dma_count);
6910 AscWriteLramByte(iop_base,
6911 (ushort)(q_addr +
6912 (ushort)ASC_SCSIQ_B_STATUS),
6913 (uchar)(scsiq->
6914 q_status & (uchar)~(QS_READY |
6915 QS_ABORTED)));
6916 tid_no = ASC_TIX_TO_TID(scsiq->d2.target_ix);
6917 target_id = ASC_TIX_TO_TARGET_ID(scsiq->d2.target_ix);
6918 if ((scsiq->cntl & QC_SG_HEAD) != 0) {
6919 sg_q_addr = q_addr;
6920 sg_list_qp = next_qp;
6921 for (q_cnt = 0; q_cnt < sg_queue_cnt; q_cnt++) {
6922 sg_list_qp = AscReadLramByte(iop_base,
6923 (ushort)(sg_q_addr
6924 + (ushort)
6925 ASC_SCSIQ_B_FWD));
6926 sg_q_addr = ASC_QNO_TO_QADDR(sg_list_qp);
6927 if (sg_list_qp == ASC_QLINK_END) {
6928 AscSetLibErrorCode(asc_dvc,
6929 ASCQ_ERR_SG_Q_LINKS);
6930 scsiq->d3.done_stat = QD_WITH_ERROR;
6931 scsiq->d3.host_stat =
6932 QHSTA_D_QDONE_SG_LIST_CORRUPTED;
6933 goto FATAL_ERR_QDONE;
6934 }
6935 AscWriteLramByte(iop_base,
6936 (ushort)(sg_q_addr + (ushort)
6937 ASC_SCSIQ_B_STATUS),
6938 QS_FREE);
6939 }
6940 n_q_used = sg_queue_cnt + 1;
6941 AscPutVarDoneQTail(iop_base, sg_list_qp);
6942 }
6943 if (asc_dvc->queue_full_or_busy & target_id) {
6944 cur_target_qng = AscReadLramByte(iop_base,
6945 (ushort)((ushort)
6946 ASC_QADR_BEG
6947 + (ushort)
6948 scsiq->d2.
6949 target_ix));
6950 if (cur_target_qng < asc_dvc->max_dvc_qng[tid_no]) {
6951 scsi_busy = AscReadLramByte(iop_base, (ushort)
6952 ASCV_SCSIBUSY_B);
6953 scsi_busy &= ~target_id;
6954 AscWriteLramByte(iop_base,
6955 (ushort)ASCV_SCSIBUSY_B,
6956 scsi_busy);
6957 asc_dvc->queue_full_or_busy &= ~target_id;
6958 }
6959 }
6960 if (asc_dvc->cur_total_qng >= n_q_used) {
6961 asc_dvc->cur_total_qng -= n_q_used;
6962 if (asc_dvc->cur_dvc_qng[tid_no] != 0) {
6963 asc_dvc->cur_dvc_qng[tid_no]--;
6964 }
6965 } else {
6966 AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CUR_QNG);
6967 scsiq->d3.done_stat = QD_WITH_ERROR;
6968 goto FATAL_ERR_QDONE;
6969 }
Hannes Reinecke9c17c622015-04-24 13:18:21 +02006970 if ((scsiq->d2.srb_tag == 0UL) ||
Matthew Wilcox51219352007-10-02 21:55:22 -04006971 ((scsiq->q_status & QS_ABORTED) != 0)) {
6972 return (0x11);
6973 } else if (scsiq->q_status == QS_DONE) {
Hannes Reineckeae267592015-04-24 13:18:28 +02006974 /*
6975 * This is also curious.
6976 * false_overrun will _always_ be set to 'false'
6977 */
6978 false_overrun = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04006979 if (scsiq->extra_bytes != 0) {
Hannes Reinecke95cfab62015-04-24 13:18:27 +02006980 scsiq->remain_bytes += scsiq->extra_bytes;
Matthew Wilcox51219352007-10-02 21:55:22 -04006981 }
6982 if (scsiq->d3.done_stat == QD_WITH_ERROR) {
6983 if (scsiq->d3.host_stat ==
6984 QHSTA_M_DATA_OVER_RUN) {
6985 if ((scsiq->
6986 cntl & (QC_DATA_IN | QC_DATA_OUT))
6987 == 0) {
6988 scsiq->d3.done_stat =
6989 QD_NO_ERROR;
6990 scsiq->d3.host_stat =
6991 QHSTA_NO_ERROR;
6992 } else if (false_overrun) {
6993 scsiq->d3.done_stat =
6994 QD_NO_ERROR;
6995 scsiq->d3.host_stat =
6996 QHSTA_NO_ERROR;
6997 }
6998 } else if (scsiq->d3.host_stat ==
6999 QHSTA_M_HUNG_REQ_SCSI_BUS_RESET) {
7000 AscStopChip(iop_base);
7001 AscSetChipControl(iop_base,
7002 (uchar)(CC_SCSI_RESET
7003 | CC_HALT));
7004 udelay(60);
7005 AscSetChipControl(iop_base, CC_HALT);
7006 AscSetChipStatus(iop_base,
7007 CIW_CLR_SCSI_RESET_INT);
7008 AscSetChipStatus(iop_base, 0);
7009 AscSetChipControl(iop_base, 0);
7010 }
7011 }
7012 if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
7013 asc_isr_callback(asc_dvc, scsiq);
7014 } else {
7015 if ((AscReadLramByte(iop_base,
7016 (ushort)(q_addr + (ushort)
7017 ASC_SCSIQ_CDB_BEG))
7018 == START_STOP)) {
7019 asc_dvc->unit_not_ready &= ~target_id;
7020 if (scsiq->d3.done_stat != QD_NO_ERROR) {
7021 asc_dvc->start_motor &=
7022 ~target_id;
7023 }
7024 }
7025 }
7026 return (1);
7027 } else {
7028 AscSetLibErrorCode(asc_dvc, ASCQ_ERR_Q_STATUS);
7029 FATAL_ERR_QDONE:
7030 if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
7031 asc_isr_callback(asc_dvc, scsiq);
7032 }
7033 return (0x80);
7034 }
7035 }
7036 return (0);
7037}
7038
7039static int AscISR(ASC_DVC_VAR *asc_dvc)
7040{
7041 ASC_CS_TYPE chipstat;
7042 PortAddr iop_base;
7043 ushort saved_ram_addr;
7044 uchar ctrl_reg;
7045 uchar saved_ctrl_reg;
7046 int int_pending;
7047 int status;
7048 uchar host_flag;
7049
7050 iop_base = asc_dvc->iop_base;
Hannes Reineckeae267592015-04-24 13:18:28 +02007051 int_pending = ASC_FALSE;
Matthew Wilcox51219352007-10-02 21:55:22 -04007052
7053 if (AscIsIntPending(iop_base) == 0)
7054 return int_pending;
7055
7056 if ((asc_dvc->init_state & ASC_INIT_STATE_END_LOAD_MC) == 0) {
Hannes Reineckeae267592015-04-24 13:18:28 +02007057 return ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04007058 }
7059 if (asc_dvc->in_critical_cnt != 0) {
7060 AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_ON_CRITICAL);
Hannes Reineckeae267592015-04-24 13:18:28 +02007061 return ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04007062 }
7063 if (asc_dvc->is_in_int) {
7064 AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_RE_ENTRY);
Hannes Reineckeae267592015-04-24 13:18:28 +02007065 return ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04007066 }
Hannes Reineckeae267592015-04-24 13:18:28 +02007067 asc_dvc->is_in_int = true;
Matthew Wilcox51219352007-10-02 21:55:22 -04007068 ctrl_reg = AscGetChipControl(iop_base);
7069 saved_ctrl_reg = ctrl_reg & (~(CC_SCSI_RESET | CC_CHIP_RESET |
7070 CC_SINGLE_STEP | CC_DIAG | CC_TEST));
7071 chipstat = AscGetChipStatus(iop_base);
7072 if (chipstat & CSW_SCSI_RESET_LATCH) {
7073 if (!(asc_dvc->bus_type & (ASC_IS_VL | ASC_IS_EISA))) {
7074 int i = 10;
Hannes Reineckeae267592015-04-24 13:18:28 +02007075 int_pending = ASC_TRUE;
Matthew Wilcox51219352007-10-02 21:55:22 -04007076 asc_dvc->sdtr_done = 0;
7077 saved_ctrl_reg &= (uchar)(~CC_HALT);
7078 while ((AscGetChipStatus(iop_base) &
7079 CSW_SCSI_RESET_ACTIVE) && (i-- > 0)) {
7080 mdelay(100);
7081 }
7082 AscSetChipControl(iop_base, (CC_CHIP_RESET | CC_HALT));
7083 AscSetChipControl(iop_base, CC_HALT);
7084 AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
7085 AscSetChipStatus(iop_base, 0);
7086 chipstat = AscGetChipStatus(iop_base);
7087 }
7088 }
7089 saved_ram_addr = AscGetChipLramAddr(iop_base);
7090 host_flag = AscReadLramByte(iop_base,
7091 ASCV_HOST_FLAG_B) &
7092 (uchar)(~ASC_HOST_FLAG_IN_ISR);
7093 AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
7094 (uchar)(host_flag | (uchar)ASC_HOST_FLAG_IN_ISR));
7095 if ((chipstat & CSW_INT_PENDING) || (int_pending)) {
7096 AscAckInterrupt(iop_base);
Hannes Reineckeae267592015-04-24 13:18:28 +02007097 int_pending = ASC_TRUE;
Matthew Wilcox51219352007-10-02 21:55:22 -04007098 if ((chipstat & CSW_HALTED) && (ctrl_reg & CC_SINGLE_STEP)) {
Hannes Reinecke6f0d2e12015-04-24 13:18:30 +02007099 AscIsrChipHalted(asc_dvc);
7100 saved_ctrl_reg &= (uchar)(~CC_HALT);
Matthew Wilcox51219352007-10-02 21:55:22 -04007101 } else {
Matthew Wilcox51219352007-10-02 21:55:22 -04007102 if ((asc_dvc->dvc_cntl & ASC_CNTL_INT_MULTI_Q) != 0) {
7103 while (((status =
7104 AscIsrQDone(asc_dvc)) & 0x01) != 0) {
7105 }
7106 } else {
7107 do {
7108 if ((status =
7109 AscIsrQDone(asc_dvc)) == 1) {
7110 break;
7111 }
7112 } while (status == 0x11);
7113 }
7114 if ((status & 0x80) != 0)
Hannes Reineckeae267592015-04-24 13:18:28 +02007115 int_pending = ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04007116 }
7117 }
7118 AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
7119 AscSetChipLramAddr(iop_base, saved_ram_addr);
7120 AscSetChipControl(iop_base, saved_ctrl_reg);
Hannes Reineckeae267592015-04-24 13:18:28 +02007121 asc_dvc->is_in_int = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04007122 return int_pending;
7123}
7124
7125/*
7126 * advansys_reset()
7127 *
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007128 * Reset the host associated with the command 'scp'.
Matthew Wilcox51219352007-10-02 21:55:22 -04007129 *
7130 * This function runs its own thread. Interrupts must be blocked but
7131 * sleeping is allowed and no locking other than for host structures is
7132 * required. Returns SUCCESS or FAILED.
7133 */
7134static int advansys_reset(struct scsi_cmnd *scp)
7135{
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007136 struct Scsi_Host *shost = scp->device->host;
Matthew Wilcoxd2411492007-10-02 21:55:31 -04007137 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007138 unsigned long flags;
Matthew Wilcox51219352007-10-02 21:55:22 -04007139 int status;
7140 int ret = SUCCESS;
7141
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007142 ASC_DBG(1, "0x%p\n", scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04007143
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007144 ASC_STATS(shost, reset);
Matthew Wilcox51219352007-10-02 21:55:22 -04007145
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007146 scmd_printk(KERN_INFO, scp, "SCSI host reset started...\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007147
7148 if (ASC_NARROW_BOARD(boardp)) {
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007149 ASC_DVC_VAR *asc_dvc = &boardp->dvc_var.asc_dvc_var;
Matthew Wilcox51219352007-10-02 21:55:22 -04007150
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007151 /* Reset the chip and SCSI bus. */
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007152 ASC_DBG(1, "before AscInitAsc1000Driver()\n");
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007153 status = AscInitAsc1000Driver(asc_dvc);
Matthew Wilcox51219352007-10-02 21:55:22 -04007154
Adam Buchbinder6070d812009-12-04 15:47:01 -05007155 /* Refer to ASC_IERR_* definitions for meaning of 'err_code'. */
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -03007156 if (asc_dvc->err_code || !asc_dvc->overrun_dma) {
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007157 scmd_printk(KERN_INFO, scp, "SCSI host reset error: "
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -03007158 "0x%x, status: 0x%x\n", asc_dvc->err_code,
7159 status);
Matthew Wilcox51219352007-10-02 21:55:22 -04007160 ret = FAILED;
7161 } else if (status) {
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007162 scmd_printk(KERN_INFO, scp, "SCSI host reset warning: "
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007163 "0x%x\n", status);
Matthew Wilcox51219352007-10-02 21:55:22 -04007164 } else {
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007165 scmd_printk(KERN_INFO, scp, "SCSI host reset "
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007166 "successful\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007167 }
7168
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007169 ASC_DBG(1, "after AscInitAsc1000Driver()\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007170 } else {
7171 /*
Matthew Wilcox51219352007-10-02 21:55:22 -04007172 * If the suggest reset bus flags are set, then reset the bus.
7173 * Otherwise only reset the device.
7174 */
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007175 ADV_DVC_VAR *adv_dvc = &boardp->dvc_var.adv_dvc_var;
Matthew Wilcox51219352007-10-02 21:55:22 -04007176
7177 /*
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007178 * Reset the chip and SCSI bus.
Matthew Wilcox51219352007-10-02 21:55:22 -04007179 */
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007180 ASC_DBG(1, "before AdvResetChipAndSB()\n");
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007181 switch (AdvResetChipAndSB(adv_dvc)) {
Matthew Wilcox51219352007-10-02 21:55:22 -04007182 case ASC_TRUE:
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007183 scmd_printk(KERN_INFO, scp, "SCSI host reset "
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007184 "successful\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007185 break;
7186 case ASC_FALSE:
7187 default:
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007188 scmd_printk(KERN_INFO, scp, "SCSI host reset error\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007189 ret = FAILED;
7190 break;
7191 }
Matthew Wilcoxf092d222007-10-02 21:55:34 -04007192 spin_lock_irqsave(shost->host_lock, flags);
Matthew Wilcox52fa0772007-10-02 21:55:26 -04007193 AdvISR(adv_dvc);
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +02007194 spin_unlock_irqrestore(shost->host_lock, flags);
Matthew Wilcox51219352007-10-02 21:55:22 -04007195 }
Matthew Wilcox51219352007-10-02 21:55:22 -04007196
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007197 ASC_DBG(1, "ret %d\n", ret);
Matthew Wilcox51219352007-10-02 21:55:22 -04007198
7199 return ret;
7200}
7201
7202/*
7203 * advansys_biosparam()
7204 *
7205 * Translate disk drive geometry if the "BIOS greater than 1 GB"
7206 * support is enabled for a drive.
7207 *
7208 * ip (information pointer) is an int array with the following definition:
7209 * ip[0]: heads
7210 * ip[1]: sectors
7211 * ip[2]: cylinders
7212 */
7213static int
7214advansys_biosparam(struct scsi_device *sdev, struct block_device *bdev,
7215 sector_t capacity, int ip[])
7216{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04007217 struct asc_board *boardp = shost_priv(sdev->host);
Matthew Wilcox51219352007-10-02 21:55:22 -04007218
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007219 ASC_DBG(1, "begin\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007220 ASC_STATS(sdev->host, biosparam);
Matthew Wilcox51219352007-10-02 21:55:22 -04007221 if (ASC_NARROW_BOARD(boardp)) {
7222 if ((boardp->dvc_var.asc_dvc_var.dvc_cntl &
7223 ASC_CNTL_BIOS_GT_1GB) && capacity > 0x200000) {
7224 ip[0] = 255;
7225 ip[1] = 63;
7226 } else {
7227 ip[0] = 64;
7228 ip[1] = 32;
7229 }
7230 } else {
7231 if ((boardp->dvc_var.adv_dvc_var.bios_ctrl &
7232 BIOS_CTRL_EXTENDED_XLAT) && capacity > 0x200000) {
7233 ip[0] = 255;
7234 ip[1] = 63;
7235 } else {
7236 ip[0] = 64;
7237 ip[1] = 32;
7238 }
7239 }
7240 ip[2] = (unsigned long)capacity / (ip[0] * ip[1]);
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007241 ASC_DBG(1, "end\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007242 return 0;
7243}
7244
7245/*
7246 * First-level interrupt handler.
7247 *
7248 * 'dev_id' is a pointer to the interrupting adapter's Scsi_Host.
7249 */
7250static irqreturn_t advansys_interrupt(int irq, void *dev_id)
7251{
Matthew Wilcox51219352007-10-02 21:55:22 -04007252 struct Scsi_Host *shost = dev_id;
Matthew Wilcoxd2411492007-10-02 21:55:31 -04007253 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox51219352007-10-02 21:55:22 -04007254 irqreturn_t result = IRQ_NONE;
7255
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007256 ASC_DBG(2, "boardp 0x%p\n", boardp);
Matthew Wilcoxf092d222007-10-02 21:55:34 -04007257 spin_lock(shost->host_lock);
Matthew Wilcox51219352007-10-02 21:55:22 -04007258 if (ASC_NARROW_BOARD(boardp)) {
7259 if (AscIsIntPending(shost->io_port)) {
7260 result = IRQ_HANDLED;
7261 ASC_STATS(shost, interrupt);
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007262 ASC_DBG(1, "before AscISR()\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007263 AscISR(&boardp->dvc_var.asc_dvc_var);
7264 }
7265 } else {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007266 ASC_DBG(1, "before AdvISR()\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007267 if (AdvISR(&boardp->dvc_var.adv_dvc_var)) {
7268 result = IRQ_HANDLED;
7269 ASC_STATS(shost, interrupt);
7270 }
7271 }
Matthew Wilcoxf092d222007-10-02 21:55:34 -04007272 spin_unlock(shost->host_lock);
Matthew Wilcox51219352007-10-02 21:55:22 -04007273
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007274 ASC_DBG(1, "end\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007275 return result;
7276}
7277
Hannes Reinecked647c782015-04-24 13:18:26 +02007278static bool AscHostReqRiscHalt(PortAddr iop_base)
Matthew Wilcox51219352007-10-02 21:55:22 -04007279{
7280 int count = 0;
Hannes Reinecked647c782015-04-24 13:18:26 +02007281 bool sta = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04007282 uchar saved_stop_code;
7283
7284 if (AscIsChipHalted(iop_base))
Hannes Reinecked647c782015-04-24 13:18:26 +02007285 return true;
Matthew Wilcox51219352007-10-02 21:55:22 -04007286 saved_stop_code = AscReadLramByte(iop_base, ASCV_STOP_CODE_B);
7287 AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
7288 ASC_STOP_HOST_REQ_RISC_HALT | ASC_STOP_REQ_RISC_STOP);
7289 do {
7290 if (AscIsChipHalted(iop_base)) {
Hannes Reinecked647c782015-04-24 13:18:26 +02007291 sta = true;
Matthew Wilcox51219352007-10-02 21:55:22 -04007292 break;
7293 }
7294 mdelay(100);
7295 } while (count++ < 20);
7296 AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, saved_stop_code);
Hannes Reinecked647c782015-04-24 13:18:26 +02007297 return sta;
Matthew Wilcox51219352007-10-02 21:55:22 -04007298}
7299
Hannes Reinecked647c782015-04-24 13:18:26 +02007300static bool
Matthew Wilcox51219352007-10-02 21:55:22 -04007301AscSetRunChipSynRegAtID(PortAddr iop_base, uchar tid_no, uchar sdtr_data)
7302{
Hannes Reinecked647c782015-04-24 13:18:26 +02007303 bool sta = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04007304
7305 if (AscHostReqRiscHalt(iop_base)) {
7306 sta = AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
7307 AscStartChip(iop_base);
7308 }
7309 return sta;
7310}
7311
7312static void AscAsyncFix(ASC_DVC_VAR *asc_dvc, struct scsi_device *sdev)
7313{
7314 char type = sdev->type;
7315 ASC_SCSI_BIT_ID_TYPE tid_bits = 1 << sdev->id;
7316
7317 if (!(asc_dvc->bug_fix_cntl & ASC_BUG_FIX_ASYN_USE_SYN))
7318 return;
7319 if (asc_dvc->init_sdtr & tid_bits)
7320 return;
7321
7322 if ((type == TYPE_ROM) && (strncmp(sdev->vendor, "HP ", 3) == 0))
7323 asc_dvc->pci_fix_asyn_xfer_always |= tid_bits;
7324
7325 asc_dvc->pci_fix_asyn_xfer |= tid_bits;
7326 if ((type == TYPE_PROCESSOR) || (type == TYPE_SCANNER) ||
7327 (type == TYPE_ROM) || (type == TYPE_TAPE))
7328 asc_dvc->pci_fix_asyn_xfer &= ~tid_bits;
7329
7330 if (asc_dvc->pci_fix_asyn_xfer & tid_bits)
7331 AscSetRunChipSynRegAtID(asc_dvc->iop_base, sdev->id,
7332 ASYN_SDTR_DATA_FIX_PCI_REV_AB);
7333}
7334
7335static void
7336advansys_narrow_slave_configure(struct scsi_device *sdev, ASC_DVC_VAR *asc_dvc)
7337{
7338 ASC_SCSI_BIT_ID_TYPE tid_bit = 1 << sdev->id;
7339 ASC_SCSI_BIT_ID_TYPE orig_use_tagged_qng = asc_dvc->use_tagged_qng;
7340
7341 if (sdev->lun == 0) {
7342 ASC_SCSI_BIT_ID_TYPE orig_init_sdtr = asc_dvc->init_sdtr;
7343 if ((asc_dvc->cfg->sdtr_enable & tid_bit) && sdev->sdtr) {
7344 asc_dvc->init_sdtr |= tid_bit;
7345 } else {
7346 asc_dvc->init_sdtr &= ~tid_bit;
7347 }
7348
7349 if (orig_init_sdtr != asc_dvc->init_sdtr)
7350 AscAsyncFix(asc_dvc, sdev);
7351 }
7352
7353 if (sdev->tagged_supported) {
7354 if (asc_dvc->cfg->cmd_qng_enabled & tid_bit) {
7355 if (sdev->lun == 0) {
7356 asc_dvc->cfg->can_tagged_qng |= tid_bit;
7357 asc_dvc->use_tagged_qng |= tid_bit;
7358 }
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01007359 scsi_change_queue_depth(sdev,
Matthew Wilcox51219352007-10-02 21:55:22 -04007360 asc_dvc->max_dvc_qng[sdev->id]);
7361 }
7362 } else {
7363 if (sdev->lun == 0) {
7364 asc_dvc->cfg->can_tagged_qng &= ~tid_bit;
7365 asc_dvc->use_tagged_qng &= ~tid_bit;
7366 }
Matthew Wilcox51219352007-10-02 21:55:22 -04007367 }
7368
7369 if ((sdev->lun == 0) &&
7370 (orig_use_tagged_qng != asc_dvc->use_tagged_qng)) {
7371 AscWriteLramByte(asc_dvc->iop_base, ASCV_DISC_ENABLE_B,
7372 asc_dvc->cfg->disc_enable);
7373 AscWriteLramByte(asc_dvc->iop_base, ASCV_USE_TAGGED_QNG_B,
7374 asc_dvc->use_tagged_qng);
7375 AscWriteLramByte(asc_dvc->iop_base, ASCV_CAN_TAGGED_QNG_B,
7376 asc_dvc->cfg->can_tagged_qng);
7377
7378 asc_dvc->max_dvc_qng[sdev->id] =
7379 asc_dvc->cfg->max_tag_qng[sdev->id];
7380 AscWriteLramByte(asc_dvc->iop_base,
7381 (ushort)(ASCV_MAX_DVC_QNG_BEG + sdev->id),
7382 asc_dvc->max_dvc_qng[sdev->id]);
7383 }
7384}
7385
7386/*
7387 * Wide Transfers
7388 *
7389 * If the EEPROM enabled WDTR for the device and the device supports wide
7390 * bus (16 bit) transfers, then turn on the device's 'wdtr_able' bit and
7391 * write the new value to the microcode.
7392 */
7393static void
7394advansys_wide_enable_wdtr(AdvPortAddr iop_base, unsigned short tidmask)
7395{
7396 unsigned short cfg_word;
7397 AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
7398 if ((cfg_word & tidmask) != 0)
7399 return;
7400
7401 cfg_word |= tidmask;
7402 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
7403
7404 /*
7405 * Clear the microcode SDTR and WDTR negotiation done indicators for
7406 * the target to cause it to negotiate with the new setting set above.
7407 * WDTR when accepted causes the target to enter asynchronous mode, so
7408 * SDTR must be negotiated.
7409 */
7410 AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
7411 cfg_word &= ~tidmask;
7412 AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
7413 AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
7414 cfg_word &= ~tidmask;
7415 AdvWriteWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
7416}
7417
7418/*
7419 * Synchronous Transfers
7420 *
7421 * If the EEPROM enabled SDTR for the device and the device
7422 * supports synchronous transfers, then turn on the device's
7423 * 'sdtr_able' bit. Write the new value to the microcode.
7424 */
7425static void
7426advansys_wide_enable_sdtr(AdvPortAddr iop_base, unsigned short tidmask)
7427{
7428 unsigned short cfg_word;
7429 AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
7430 if ((cfg_word & tidmask) != 0)
7431 return;
7432
7433 cfg_word |= tidmask;
7434 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
7435
7436 /*
7437 * Clear the microcode "SDTR negotiation" done indicator for the
7438 * target to cause it to negotiate with the new setting set above.
7439 */
7440 AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
7441 cfg_word &= ~tidmask;
7442 AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
7443}
7444
7445/*
7446 * PPR (Parallel Protocol Request) Capable
7447 *
7448 * If the device supports DT mode, then it must be PPR capable.
7449 * The PPR message will be used in place of the SDTR and WDTR
7450 * messages to negotiate synchronous speed and offset, transfer
7451 * width, and protocol options.
7452 */
7453static void advansys_wide_enable_ppr(ADV_DVC_VAR *adv_dvc,
7454 AdvPortAddr iop_base, unsigned short tidmask)
7455{
7456 AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, adv_dvc->ppr_able);
7457 adv_dvc->ppr_able |= tidmask;
7458 AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, adv_dvc->ppr_able);
7459}
7460
7461static void
7462advansys_wide_slave_configure(struct scsi_device *sdev, ADV_DVC_VAR *adv_dvc)
7463{
7464 AdvPortAddr iop_base = adv_dvc->iop_base;
7465 unsigned short tidmask = 1 << sdev->id;
7466
7467 if (sdev->lun == 0) {
7468 /*
7469 * Handle WDTR, SDTR, and Tag Queuing. If the feature
7470 * is enabled in the EEPROM and the device supports the
7471 * feature, then enable it in the microcode.
7472 */
7473
7474 if ((adv_dvc->wdtr_able & tidmask) && sdev->wdtr)
7475 advansys_wide_enable_wdtr(iop_base, tidmask);
7476 if ((adv_dvc->sdtr_able & tidmask) && sdev->sdtr)
7477 advansys_wide_enable_sdtr(iop_base, tidmask);
7478 if (adv_dvc->chip_type == ADV_CHIP_ASC38C1600 && sdev->ppr)
7479 advansys_wide_enable_ppr(adv_dvc, iop_base, tidmask);
7480
7481 /*
7482 * Tag Queuing is disabled for the BIOS which runs in polled
7483 * mode and would see no benefit from Tag Queuing. Also by
7484 * disabling Tag Queuing in the BIOS devices with Tag Queuing
7485 * bugs will at least work with the BIOS.
7486 */
7487 if ((adv_dvc->tagqng_able & tidmask) &&
7488 sdev->tagged_supported) {
7489 unsigned short cfg_word;
7490 AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, cfg_word);
7491 cfg_word |= tidmask;
7492 AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
7493 cfg_word);
7494 AdvWriteByteLram(iop_base,
7495 ASC_MC_NUMBER_OF_MAX_CMD + sdev->id,
7496 adv_dvc->max_dvc_qng);
7497 }
7498 }
7499
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01007500 if ((adv_dvc->tagqng_able & tidmask) && sdev->tagged_supported)
7501 scsi_change_queue_depth(sdev, adv_dvc->max_dvc_qng);
Matthew Wilcox51219352007-10-02 21:55:22 -04007502}
7503
7504/*
7505 * Set the number of commands to queue per device for the
7506 * specified host adapter.
7507 */
7508static int advansys_slave_configure(struct scsi_device *sdev)
7509{
Matthew Wilcoxd2411492007-10-02 21:55:31 -04007510 struct asc_board *boardp = shost_priv(sdev->host);
Matthew Wilcox51219352007-10-02 21:55:22 -04007511
Matthew Wilcox51219352007-10-02 21:55:22 -04007512 if (ASC_NARROW_BOARD(boardp))
7513 advansys_narrow_slave_configure(sdev,
7514 &boardp->dvc_var.asc_dvc_var);
7515 else
7516 advansys_wide_slave_configure(sdev,
7517 &boardp->dvc_var.adv_dvc_var);
7518
7519 return 0;
7520}
7521
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04007522static __le32 advansys_get_sense_buffer_dma(struct scsi_cmnd *scp)
7523{
7524 struct asc_board *board = shost_priv(scp->device->host);
7525 scp->SCp.dma_handle = dma_map_single(board->dev, scp->sense_buffer,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09007526 SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04007527 dma_cache_sync(board->dev, scp->sense_buffer,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09007528 SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04007529 return cpu_to_le32(scp->SCp.dma_handle);
7530}
7531
Matthew Wilcoxd2411492007-10-02 21:55:31 -04007532static int asc_build_req(struct asc_board *boardp, struct scsi_cmnd *scp,
Matthew Wilcox05848b62007-10-02 21:55:25 -04007533 struct asc_scsi_q *asc_scsi_q)
Matthew Wilcox51219352007-10-02 21:55:22 -04007534{
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04007535 struct asc_dvc_var *asc_dvc = &boardp->dvc_var.asc_dvc_var;
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007536 int use_sg;
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007537 u32 srb_tag;
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007538
Matthew Wilcox05848b62007-10-02 21:55:25 -04007539 memset(asc_scsi_q, 0, sizeof(*asc_scsi_q));
Matthew Wilcox51219352007-10-02 21:55:22 -04007540
7541 /*
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007542 * Set the srb_tag to the command tag + 1, as
7543 * srb_tag '0' is used internally by the chip.
Matthew Wilcox51219352007-10-02 21:55:22 -04007544 */
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007545 srb_tag = scp->request->tag + 1;
7546 asc_scsi_q->q2.srb_tag = srb_tag;
Matthew Wilcox51219352007-10-02 21:55:22 -04007547
7548 /*
7549 * Build the ASC_SCSI_Q request.
7550 */
Matthew Wilcox05848b62007-10-02 21:55:25 -04007551 asc_scsi_q->cdbptr = &scp->cmnd[0];
7552 asc_scsi_q->q2.cdb_len = scp->cmd_len;
7553 asc_scsi_q->q1.target_id = ASC_TID_TO_TARGET_ID(scp->device->id);
7554 asc_scsi_q->q1.target_lun = scp->device->lun;
7555 asc_scsi_q->q2.target_ix =
Matthew Wilcox51219352007-10-02 21:55:22 -04007556 ASC_TIDLUN_TO_IX(scp->device->id, scp->device->lun);
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04007557 asc_scsi_q->q1.sense_addr = advansys_get_sense_buffer_dma(scp);
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09007558 asc_scsi_q->q1.sense_len = SCSI_SENSE_BUFFERSIZE;
Matthew Wilcox51219352007-10-02 21:55:22 -04007559
7560 /*
7561 * If there are any outstanding requests for the current target,
7562 * then every 255th request send an ORDERED request. This heuristic
7563 * tries to retain the benefit of request sorting while preventing
7564 * request starvation. 255 is the max number of tags or pending commands
7565 * a device may have outstanding.
7566 *
7567 * The request count is incremented below for every successfully
7568 * started request.
7569 *
7570 */
Matthew Wilcoxb249c7f2007-10-02 21:55:40 -04007571 if ((asc_dvc->cur_dvc_qng[scp->device->id] > 0) &&
Matthew Wilcox51219352007-10-02 21:55:22 -04007572 (boardp->reqcnt[scp->device->id] % 255) == 0) {
Christoph Hellwig68d81f42014-11-24 07:07:25 -08007573 asc_scsi_q->q2.tag_code = ORDERED_QUEUE_TAG;
Matthew Wilcox51219352007-10-02 21:55:22 -04007574 } else {
Christoph Hellwig68d81f42014-11-24 07:07:25 -08007575 asc_scsi_q->q2.tag_code = SIMPLE_QUEUE_TAG;
Matthew Wilcox51219352007-10-02 21:55:22 -04007576 }
7577
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007578 /* Build ASC_SCSI_Q */
7579 use_sg = scsi_dma_map(scp);
7580 if (use_sg != 0) {
Matthew Wilcox51219352007-10-02 21:55:22 -04007581 int sgcnt;
Matthew Wilcox51219352007-10-02 21:55:22 -04007582 struct scatterlist *slp;
Matthew Wilcox05848b62007-10-02 21:55:25 -04007583 struct asc_sg_head *asc_sg_head;
Matthew Wilcox51219352007-10-02 21:55:22 -04007584
Matthew Wilcox51219352007-10-02 21:55:22 -04007585 if (use_sg > scp->device->host->sg_tablesize) {
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04007586 scmd_printk(KERN_ERR, scp, "use_sg %d > "
7587 "sg_tablesize %d\n", use_sg,
7588 scp->device->host->sg_tablesize);
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007589 scsi_dma_unmap(scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04007590 scp->result = HOST_BYTE(DID_ERROR);
7591 return ASC_ERROR;
7592 }
7593
Matthew Wilcox05848b62007-10-02 21:55:25 -04007594 asc_sg_head = kzalloc(sizeof(asc_scsi_q->sg_head) +
7595 use_sg * sizeof(struct asc_sg_list), GFP_ATOMIC);
7596 if (!asc_sg_head) {
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007597 scsi_dma_unmap(scp);
Matthew Wilcox05848b62007-10-02 21:55:25 -04007598 scp->result = HOST_BYTE(DID_SOFT_ERROR);
7599 return ASC_ERROR;
7600 }
Matthew Wilcox51219352007-10-02 21:55:22 -04007601
Matthew Wilcox05848b62007-10-02 21:55:25 -04007602 asc_scsi_q->q1.cntl |= QC_SG_HEAD;
7603 asc_scsi_q->sg_head = asc_sg_head;
7604 asc_scsi_q->q1.data_cnt = 0;
7605 asc_scsi_q->q1.data_addr = 0;
Matthew Wilcox51219352007-10-02 21:55:22 -04007606 /* This is a byte value, otherwise it would need to be swapped. */
Matthew Wilcox05848b62007-10-02 21:55:25 -04007607 asc_sg_head->entry_cnt = asc_scsi_q->q1.sg_queue_cnt = use_sg;
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007608 ASC_STATS_ADD(scp->device->host, xfer_elem,
Matthew Wilcox05848b62007-10-02 21:55:25 -04007609 asc_sg_head->entry_cnt);
Matthew Wilcox51219352007-10-02 21:55:22 -04007610
7611 /*
7612 * Convert scatter-gather list into ASC_SG_HEAD list.
7613 */
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007614 scsi_for_each_sg(scp, slp, use_sg, sgcnt) {
Matthew Wilcox05848b62007-10-02 21:55:25 -04007615 asc_sg_head->sg_list[sgcnt].addr =
Matthew Wilcox51219352007-10-02 21:55:22 -04007616 cpu_to_le32(sg_dma_address(slp));
Matthew Wilcox05848b62007-10-02 21:55:25 -04007617 asc_sg_head->sg_list[sgcnt].bytes =
Matthew Wilcox51219352007-10-02 21:55:22 -04007618 cpu_to_le32(sg_dma_len(slp));
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007619 ASC_STATS_ADD(scp->device->host, xfer_sect,
7620 DIV_ROUND_UP(sg_dma_len(slp), 512));
Matthew Wilcox51219352007-10-02 21:55:22 -04007621 }
7622 }
7623
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007624 ASC_STATS(scp->device->host, xfer_cnt);
7625
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007626 ASC_DBG_PRT_ASC_SCSI_Q(2, asc_scsi_q);
Matthew Wilcox51219352007-10-02 21:55:22 -04007627 ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
7628
7629 return ASC_NOERROR;
7630}
7631
7632/*
7633 * Build scatter-gather list for Adv Library (Wide Board).
7634 *
7635 * Additional ADV_SG_BLOCK structures will need to be allocated
7636 * if the total number of scatter-gather elements exceeds
7637 * NO_OF_SG_PER_BLOCK (15). The ADV_SG_BLOCK structures are
7638 * assumed to be physically contiguous.
7639 *
7640 * Return:
7641 * ADV_SUCCESS(1) - SG List successfully created
7642 * ADV_ERROR(-1) - SG List creation failed
7643 */
7644static int
Hannes Reinecke4b47e462015-04-24 13:18:24 +02007645adv_get_sglist(struct asc_board *boardp, adv_req_t *reqp,
7646 ADV_SCSI_REQ_Q *scsiqp, struct scsi_cmnd *scp, int use_sg)
Matthew Wilcox51219352007-10-02 21:55:22 -04007647{
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007648 adv_sgblk_t *sgblkp, *prev_sgblkp;
Matthew Wilcox51219352007-10-02 21:55:22 -04007649 struct scatterlist *slp;
7650 int sg_elem_cnt;
7651 ADV_SG_BLOCK *sg_block, *prev_sg_block;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007652 dma_addr_t sgblk_paddr;
Matthew Wilcox51219352007-10-02 21:55:22 -04007653 int i;
7654
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007655 slp = scsi_sglist(scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04007656 sg_elem_cnt = use_sg;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007657 prev_sgblkp = NULL;
Matthew Wilcox51219352007-10-02 21:55:22 -04007658 prev_sg_block = NULL;
7659 reqp->sgblkp = NULL;
7660
7661 for (;;) {
7662 /*
7663 * Allocate a 'adv_sgblk_t' structure from the board free
7664 * list. One 'adv_sgblk_t' structure holds NO_OF_SG_PER_BLOCK
7665 * (15) scatter-gather elements.
7666 */
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007667 sgblkp = dma_pool_alloc(boardp->adv_sgblk_pool, GFP_ATOMIC,
7668 &sgblk_paddr);
7669 if (!sgblkp) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007670 ASC_DBG(1, "no free adv_sgblk_t\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007671 ASC_STATS(scp->device->host, adv_build_nosg);
7672
7673 /*
7674 * Allocation failed. Free 'adv_sgblk_t' structures
7675 * already allocated for the request.
7676 */
7677 while ((sgblkp = reqp->sgblkp) != NULL) {
7678 /* Remove 'sgblkp' from the request list. */
7679 reqp->sgblkp = sgblkp->next_sgblkp;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007680 sgblkp->next_sgblkp = NULL;
7681 dma_pool_free(boardp->adv_sgblk_pool, sgblkp,
7682 sgblkp->sg_addr);
Matthew Wilcox51219352007-10-02 21:55:22 -04007683 }
7684 return ASC_BUSY;
7685 }
Matthew Wilcox51219352007-10-02 21:55:22 -04007686 /* Complete 'adv_sgblk_t' board allocation. */
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007687 sgblkp->sg_addr = sgblk_paddr;
Matthew Wilcox51219352007-10-02 21:55:22 -04007688 sgblkp->next_sgblkp = NULL;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007689 sg_block = &sgblkp->sg_block;
Matthew Wilcox51219352007-10-02 21:55:22 -04007690
7691 /*
7692 * Check if this is the first 'adv_sgblk_t' for the
7693 * request.
7694 */
7695 if (reqp->sgblkp == NULL) {
7696 /* Request's first scatter-gather block. */
7697 reqp->sgblkp = sgblkp;
7698
7699 /*
7700 * Set ADV_SCSI_REQ_T ADV_SG_BLOCK virtual and physical
7701 * address pointers.
7702 */
7703 scsiqp->sg_list_ptr = sg_block;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007704 scsiqp->sg_real_addr = cpu_to_le32(sgblk_paddr);
Matthew Wilcox51219352007-10-02 21:55:22 -04007705 } else {
7706 /* Request's second or later scatter-gather block. */
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007707 prev_sgblkp->next_sgblkp = sgblkp;
Matthew Wilcox51219352007-10-02 21:55:22 -04007708
7709 /*
7710 * Point the previous ADV_SG_BLOCK structure to
7711 * the newly allocated ADV_SG_BLOCK structure.
7712 */
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007713 prev_sg_block->sg_ptr = cpu_to_le32(sgblk_paddr);
Matthew Wilcox51219352007-10-02 21:55:22 -04007714 }
7715
7716 for (i = 0; i < NO_OF_SG_PER_BLOCK; i++) {
7717 sg_block->sg_list[i].sg_addr =
7718 cpu_to_le32(sg_dma_address(slp));
7719 sg_block->sg_list[i].sg_count =
7720 cpu_to_le32(sg_dma_len(slp));
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007721 ASC_STATS_ADD(scp->device->host, xfer_sect,
7722 DIV_ROUND_UP(sg_dma_len(slp), 512));
Matthew Wilcox51219352007-10-02 21:55:22 -04007723
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007724 if (--sg_elem_cnt == 0) {
7725 /*
7726 * Last ADV_SG_BLOCK and scatter-gather entry.
7727 */
Matthew Wilcox51219352007-10-02 21:55:22 -04007728 sg_block->sg_cnt = i + 1;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007729 sg_block->sg_ptr = 0L; /* Last ADV_SG_BLOCK in list. */
Matthew Wilcox51219352007-10-02 21:55:22 -04007730 return ADV_SUCCESS;
7731 }
7732 slp++;
7733 }
7734 sg_block->sg_cnt = NO_OF_SG_PER_BLOCK;
7735 prev_sg_block = sg_block;
Hannes Reinecke0ce53822015-04-24 13:18:25 +02007736 prev_sgblkp = sgblkp;
Matthew Wilcox51219352007-10-02 21:55:22 -04007737 }
7738}
7739
7740/*
7741 * Build a request structure for the Adv Library (Wide Board).
7742 *
7743 * If an adv_req_t can not be allocated to issue the request,
7744 * then return ASC_BUSY. If an error occurs, then return ASC_ERROR.
7745 *
Hannes Reinecke9fef6ba2015-04-24 13:18:33 +02007746 * Multi-byte fields in the ADV_SCSI_REQ_Q that are used by the
Matthew Wilcox51219352007-10-02 21:55:22 -04007747 * microcode for DMA addresses or math operations are byte swapped
7748 * to little-endian order.
7749 */
7750static int
Matthew Wilcoxd2411492007-10-02 21:55:31 -04007751adv_build_req(struct asc_board *boardp, struct scsi_cmnd *scp,
Hannes Reinecke4b47e462015-04-24 13:18:24 +02007752 adv_req_t **adv_reqpp)
Matthew Wilcox51219352007-10-02 21:55:22 -04007753{
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007754 u32 srb_tag = scp->request->tag;
Matthew Wilcox51219352007-10-02 21:55:22 -04007755 adv_req_t *reqp;
7756 ADV_SCSI_REQ_Q *scsiqp;
Matthew Wilcox51219352007-10-02 21:55:22 -04007757 int ret;
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007758 int use_sg;
Hannes Reinecke811ddc02015-04-24 13:18:22 +02007759 dma_addr_t sense_addr;
Matthew Wilcox51219352007-10-02 21:55:22 -04007760
7761 /*
7762 * Allocate an adv_req_t structure from the board to execute
7763 * the command.
7764 */
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007765 reqp = &boardp->adv_reqp[srb_tag];
7766 if (reqp->cmndp && reqp->cmndp != scp ) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04007767 ASC_DBG(1, "no free adv_req_t\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04007768 ASC_STATS(scp->device->host, adv_build_noreq);
7769 return ASC_BUSY;
Matthew Wilcox51219352007-10-02 21:55:22 -04007770 }
7771
Hannes Reinecke4b47e462015-04-24 13:18:24 +02007772 reqp->req_addr = boardp->adv_reqp_addr + (srb_tag * sizeof(adv_req_t));
7773
7774 scsiqp = &reqp->scsi_req_q;
Matthew Wilcox51219352007-10-02 21:55:22 -04007775
7776 /*
7777 * Initialize the structure.
7778 */
7779 scsiqp->cntl = scsiqp->scsi_cntl = scsiqp->done_status = 0;
7780
7781 /*
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007782 * Set the srb_tag to the command tag.
Matthew Wilcox51219352007-10-02 21:55:22 -04007783 */
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007784 scsiqp->srb_tag = srb_tag;
Matthew Wilcox51219352007-10-02 21:55:22 -04007785
7786 /*
Hannes Reinecke4b47e462015-04-24 13:18:24 +02007787 * Set 'host_scribble' to point to the adv_req_t structure.
Matthew Wilcox51219352007-10-02 21:55:22 -04007788 */
7789 reqp->cmndp = scp;
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007790 scp->host_scribble = (void *)reqp;
Matthew Wilcox51219352007-10-02 21:55:22 -04007791
7792 /*
7793 * Build the ADV_SCSI_REQ_Q request.
7794 */
7795
7796 /* Set CDB length and copy it to the request structure. */
7797 scsiqp->cdb_len = scp->cmd_len;
7798 /* Copy first 12 CDB bytes to cdb[]. */
Hannes Reinecke811ddc02015-04-24 13:18:22 +02007799 memcpy(scsiqp->cdb, scp->cmnd, scp->cmd_len < 12 ? scp->cmd_len : 12);
Matthew Wilcox51219352007-10-02 21:55:22 -04007800 /* Copy last 4 CDB bytes, if present, to cdb16[]. */
Hannes Reinecke811ddc02015-04-24 13:18:22 +02007801 if (scp->cmd_len > 12) {
7802 int cdb16_len = scp->cmd_len - 12;
7803
7804 memcpy(scsiqp->cdb16, &scp->cmnd[12], cdb16_len);
Matthew Wilcox51219352007-10-02 21:55:22 -04007805 }
7806
7807 scsiqp->target_id = scp->device->id;
7808 scsiqp->target_lun = scp->device->lun;
7809
Hannes Reinecke811ddc02015-04-24 13:18:22 +02007810 sense_addr = dma_map_single(boardp->dev, scp->sense_buffer,
7811 SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
7812 scsiqp->sense_addr = cpu_to_le32(sense_addr);
7813 scsiqp->sense_len = cpu_to_le32(SCSI_SENSE_BUFFERSIZE);
Matthew Wilcox51219352007-10-02 21:55:22 -04007814
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007815 /* Build ADV_SCSI_REQ_Q */
Matthew Wilcox51219352007-10-02 21:55:22 -04007816
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007817 use_sg = scsi_dma_map(scp);
7818 if (use_sg == 0) {
7819 /* Zero-length transfer */
Matthew Wilcox51219352007-10-02 21:55:22 -04007820 reqp->sgblkp = NULL;
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007821 scsiqp->data_cnt = 0;
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007822
7823 scsiqp->data_addr = 0;
Matthew Wilcox51219352007-10-02 21:55:22 -04007824 scsiqp->sg_list_ptr = NULL;
7825 scsiqp->sg_real_addr = 0;
Matthew Wilcox51219352007-10-02 21:55:22 -04007826 } else {
Matthew Wilcox51219352007-10-02 21:55:22 -04007827 if (use_sg > ADV_MAX_SG_LIST) {
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04007828 scmd_printk(KERN_ERR, scp, "use_sg %d > "
7829 "ADV_MAX_SG_LIST %d\n", use_sg,
Matthew Wilcox51219352007-10-02 21:55:22 -04007830 scp->device->host->sg_tablesize);
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007831 scsi_dma_unmap(scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04007832 scp->result = HOST_BYTE(DID_ERROR);
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007833 reqp->cmndp = NULL;
7834 scp->host_scribble = NULL;
Matthew Wilcox51219352007-10-02 21:55:22 -04007835
7836 return ASC_ERROR;
7837 }
7838
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007839 scsiqp->data_cnt = cpu_to_le32(scsi_bufflen(scp));
7840
Hannes Reinecke4b47e462015-04-24 13:18:24 +02007841 ret = adv_get_sglist(boardp, reqp, scsiqp, scp, use_sg);
Matthew Wilcox51219352007-10-02 21:55:22 -04007842 if (ret != ADV_SUCCESS) {
Hannes Reinecke9c17c622015-04-24 13:18:21 +02007843 scsi_dma_unmap(scp);
7844 scp->result = HOST_BYTE(DID_ERROR);
7845 reqp->cmndp = NULL;
7846 scp->host_scribble = NULL;
Matthew Wilcox51219352007-10-02 21:55:22 -04007847
7848 return ret;
7849 }
7850
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007851 ASC_STATS_ADD(scp->device->host, xfer_elem, use_sg);
Matthew Wilcox51219352007-10-02 21:55:22 -04007852 }
7853
Matthew Wilcox52c334e2007-10-02 21:55:39 -04007854 ASC_STATS(scp->device->host, xfer_cnt);
7855
Matthew Wilcox51219352007-10-02 21:55:22 -04007856 ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
7857 ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
7858
Hannes Reinecke4b47e462015-04-24 13:18:24 +02007859 *adv_reqpp = reqp;
Matthew Wilcox51219352007-10-02 21:55:22 -04007860
7861 return ASC_NOERROR;
7862}
7863
7864static int AscSgListToQueue(int sg_list)
7865{
7866 int n_sg_list_qs;
7867
7868 n_sg_list_qs = ((sg_list - 1) / ASC_SG_LIST_PER_Q);
7869 if (((sg_list - 1) % ASC_SG_LIST_PER_Q) != 0)
7870 n_sg_list_qs++;
7871 return n_sg_list_qs + 1;
7872}
7873
7874static uint
7875AscGetNumOfFreeQueue(ASC_DVC_VAR *asc_dvc, uchar target_ix, uchar n_qs)
7876{
7877 uint cur_used_qs;
7878 uint cur_free_qs;
7879 ASC_SCSI_BIT_ID_TYPE target_id;
7880 uchar tid_no;
7881
7882 target_id = ASC_TIX_TO_TARGET_ID(target_ix);
7883 tid_no = ASC_TIX_TO_TID(target_ix);
7884 if ((asc_dvc->unit_not_ready & target_id) ||
7885 (asc_dvc->queue_full_or_busy & target_id)) {
7886 return 0;
7887 }
7888 if (n_qs == 1) {
7889 cur_used_qs = (uint) asc_dvc->cur_total_qng +
7890 (uint) asc_dvc->last_q_shortage + (uint) ASC_MIN_FREE_Q;
7891 } else {
7892 cur_used_qs = (uint) asc_dvc->cur_total_qng +
7893 (uint) ASC_MIN_FREE_Q;
7894 }
7895 if ((uint) (cur_used_qs + n_qs) <= (uint) asc_dvc->max_total_qng) {
7896 cur_free_qs = (uint) asc_dvc->max_total_qng - cur_used_qs;
7897 if (asc_dvc->cur_dvc_qng[tid_no] >=
7898 asc_dvc->max_dvc_qng[tid_no]) {
7899 return 0;
7900 }
7901 return cur_free_qs;
7902 }
7903 if (n_qs > 1) {
7904 if ((n_qs > asc_dvc->last_q_shortage)
7905 && (n_qs <= (asc_dvc->max_total_qng - ASC_MIN_FREE_Q))) {
7906 asc_dvc->last_q_shortage = n_qs;
7907 }
7908 }
7909 return 0;
7910}
7911
7912static uchar AscAllocFreeQueue(PortAddr iop_base, uchar free_q_head)
7913{
7914 ushort q_addr;
7915 uchar next_qp;
7916 uchar q_status;
7917
7918 q_addr = ASC_QNO_TO_QADDR(free_q_head);
7919 q_status = (uchar)AscReadLramByte(iop_base,
7920 (ushort)(q_addr +
7921 ASC_SCSIQ_B_STATUS));
7922 next_qp = AscReadLramByte(iop_base, (ushort)(q_addr + ASC_SCSIQ_B_FWD));
7923 if (((q_status & QS_READY) == 0) && (next_qp != ASC_QLINK_END))
7924 return next_qp;
7925 return ASC_QLINK_END;
7926}
7927
7928static uchar
7929AscAllocMultipleFreeQueue(PortAddr iop_base, uchar free_q_head, uchar n_free_q)
7930{
7931 uchar i;
7932
7933 for (i = 0; i < n_free_q; i++) {
7934 free_q_head = AscAllocFreeQueue(iop_base, free_q_head);
7935 if (free_q_head == ASC_QLINK_END)
7936 break;
7937 }
7938 return free_q_head;
7939}
7940
7941/*
7942 * void
7943 * DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
7944 *
7945 * Calling/Exit State:
7946 * none
7947 *
7948 * Description:
7949 * Output an ASC_SCSI_Q structure to the chip
7950 */
7951static void
7952DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
7953{
7954 int i;
7955
7956 ASC_DBG_PRT_HEX(2, "DvcPutScsiQ", outbuf, 2 * words);
7957 AscSetChipLramAddr(iop_base, s_addr);
7958 for (i = 0; i < 2 * words; i += 2) {
7959 if (i == 4 || i == 20) {
7960 continue;
7961 }
7962 outpw(iop_base + IOP_RAM_DATA,
7963 ((ushort)outbuf[i + 1] << 8) | outbuf[i]);
7964 }
7965}
7966
7967static int AscPutReadyQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar q_no)
7968{
7969 ushort q_addr;
7970 uchar tid_no;
7971 uchar sdtr_data;
7972 uchar syn_period_ix;
7973 uchar syn_offset;
7974 PortAddr iop_base;
7975
7976 iop_base = asc_dvc->iop_base;
7977 if (((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) &&
7978 ((asc_dvc->sdtr_done & scsiq->q1.target_id) == 0)) {
7979 tid_no = ASC_TIX_TO_TID(scsiq->q2.target_ix);
7980 sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
7981 syn_period_ix =
7982 (sdtr_data >> 4) & (asc_dvc->max_sdtr_index - 1);
7983 syn_offset = sdtr_data & ASC_SYN_MAX_OFFSET;
7984 AscMsgOutSDTR(asc_dvc,
7985 asc_dvc->sdtr_period_tbl[syn_period_ix],
7986 syn_offset);
7987 scsiq->q1.cntl |= QC_MSG_OUT;
7988 }
7989 q_addr = ASC_QNO_TO_QADDR(q_no);
7990 if ((scsiq->q1.target_id & asc_dvc->use_tagged_qng) == 0) {
Christoph Hellwig68d81f42014-11-24 07:07:25 -08007991 scsiq->q2.tag_code &= ~SIMPLE_QUEUE_TAG;
Matthew Wilcox51219352007-10-02 21:55:22 -04007992 }
7993 scsiq->q1.status = QS_FREE;
7994 AscMemWordCopyPtrToLram(iop_base,
7995 q_addr + ASC_SCSIQ_CDB_BEG,
7996 (uchar *)scsiq->cdbptr, scsiq->q2.cdb_len >> 1);
7997
7998 DvcPutScsiQ(iop_base,
7999 q_addr + ASC_SCSIQ_CPY_BEG,
8000 (uchar *)&scsiq->q1.cntl,
8001 ((sizeof(ASC_SCSIQ_1) + sizeof(ASC_SCSIQ_2)) / 2) - 1);
8002 AscWriteLramWord(iop_base,
8003 (ushort)(q_addr + (ushort)ASC_SCSIQ_B_STATUS),
8004 (ushort)(((ushort)scsiq->q1.
8005 q_no << 8) | (ushort)QS_READY));
8006 return 1;
8007}
8008
8009static int
8010AscPutReadySgListQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar q_no)
8011{
8012 int sta;
8013 int i;
8014 ASC_SG_HEAD *sg_head;
8015 ASC_SG_LIST_Q scsi_sg_q;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008016 __le32 saved_data_addr;
8017 __le32 saved_data_cnt;
Matthew Wilcox51219352007-10-02 21:55:22 -04008018 PortAddr iop_base;
8019 ushort sg_list_dwords;
8020 ushort sg_index;
8021 ushort sg_entry_cnt;
8022 ushort q_addr;
8023 uchar next_qp;
8024
8025 iop_base = asc_dvc->iop_base;
8026 sg_head = scsiq->sg_head;
8027 saved_data_addr = scsiq->q1.data_addr;
8028 saved_data_cnt = scsiq->q1.data_cnt;
Hannes Reinecke37f64602015-04-24 13:18:32 +02008029 scsiq->q1.data_addr = cpu_to_le32(sg_head->sg_list[0].addr);
8030 scsiq->q1.data_cnt = cpu_to_le32(sg_head->sg_list[0].bytes);
Matthew Wilcox51219352007-10-02 21:55:22 -04008031 /*
Hannes Reinecke96aabb22015-04-24 13:18:34 +02008032 * Set sg_entry_cnt to be the number of SG elements that
8033 * will fit in the allocated SG queues. It is minus 1, because
8034 * the first SG element is handled above.
Matthew Wilcox51219352007-10-02 21:55:22 -04008035 */
Hannes Reinecke96aabb22015-04-24 13:18:34 +02008036 sg_entry_cnt = sg_head->entry_cnt - 1;
Matthew Wilcox51219352007-10-02 21:55:22 -04008037
Matthew Wilcox51219352007-10-02 21:55:22 -04008038 if (sg_entry_cnt != 0) {
8039 scsiq->q1.cntl |= QC_SG_HEAD;
8040 q_addr = ASC_QNO_TO_QADDR(q_no);
8041 sg_index = 1;
8042 scsiq->q1.sg_queue_cnt = sg_head->queue_cnt;
8043 scsi_sg_q.sg_head_qp = q_no;
8044 scsi_sg_q.cntl = QCSG_SG_XFER_LIST;
8045 for (i = 0; i < sg_head->queue_cnt; i++) {
8046 scsi_sg_q.seq_no = i + 1;
8047 if (sg_entry_cnt > ASC_SG_LIST_PER_Q) {
8048 sg_list_dwords = (uchar)(ASC_SG_LIST_PER_Q * 2);
8049 sg_entry_cnt -= ASC_SG_LIST_PER_Q;
8050 if (i == 0) {
8051 scsi_sg_q.sg_list_cnt =
8052 ASC_SG_LIST_PER_Q;
8053 scsi_sg_q.sg_cur_list_cnt =
8054 ASC_SG_LIST_PER_Q;
8055 } else {
8056 scsi_sg_q.sg_list_cnt =
8057 ASC_SG_LIST_PER_Q - 1;
8058 scsi_sg_q.sg_cur_list_cnt =
8059 ASC_SG_LIST_PER_Q - 1;
8060 }
8061 } else {
Hannes Reinecke96aabb22015-04-24 13:18:34 +02008062 scsi_sg_q.cntl |= QCSG_SG_XFER_END;
Matthew Wilcox51219352007-10-02 21:55:22 -04008063 sg_list_dwords = sg_entry_cnt << 1;
8064 if (i == 0) {
8065 scsi_sg_q.sg_list_cnt = sg_entry_cnt;
8066 scsi_sg_q.sg_cur_list_cnt =
8067 sg_entry_cnt;
8068 } else {
8069 scsi_sg_q.sg_list_cnt =
8070 sg_entry_cnt - 1;
8071 scsi_sg_q.sg_cur_list_cnt =
8072 sg_entry_cnt - 1;
8073 }
8074 sg_entry_cnt = 0;
8075 }
8076 next_qp = AscReadLramByte(iop_base,
8077 (ushort)(q_addr +
8078 ASC_SCSIQ_B_FWD));
8079 scsi_sg_q.q_no = next_qp;
8080 q_addr = ASC_QNO_TO_QADDR(next_qp);
8081 AscMemWordCopyPtrToLram(iop_base,
8082 q_addr + ASC_SCSIQ_SGHD_CPY_BEG,
8083 (uchar *)&scsi_sg_q,
8084 sizeof(ASC_SG_LIST_Q) >> 1);
8085 AscMemDWordCopyPtrToLram(iop_base,
8086 q_addr + ASC_SGQ_LIST_BEG,
8087 (uchar *)&sg_head->
8088 sg_list[sg_index],
8089 sg_list_dwords);
8090 sg_index += ASC_SG_LIST_PER_Q;
8091 scsiq->next_sg_index = sg_index;
8092 }
8093 } else {
8094 scsiq->q1.cntl &= ~QC_SG_HEAD;
8095 }
8096 sta = AscPutReadyQueue(asc_dvc, scsiq, q_no);
8097 scsiq->q1.data_addr = saved_data_addr;
8098 scsiq->q1.data_cnt = saved_data_cnt;
8099 return (sta);
8100}
8101
8102static int
8103AscSendScsiQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar n_q_required)
8104{
8105 PortAddr iop_base;
8106 uchar free_q_head;
8107 uchar next_qp;
8108 uchar tid_no;
8109 uchar target_ix;
8110 int sta;
8111
8112 iop_base = asc_dvc->iop_base;
8113 target_ix = scsiq->q2.target_ix;
8114 tid_no = ASC_TIX_TO_TID(target_ix);
8115 sta = 0;
8116 free_q_head = (uchar)AscGetVarFreeQHead(iop_base);
8117 if (n_q_required > 1) {
8118 next_qp = AscAllocMultipleFreeQueue(iop_base, free_q_head,
8119 (uchar)n_q_required);
8120 if (next_qp != ASC_QLINK_END) {
8121 asc_dvc->last_q_shortage = 0;
8122 scsiq->sg_head->queue_cnt = n_q_required - 1;
8123 scsiq->q1.q_no = free_q_head;
8124 sta = AscPutReadySgListQueue(asc_dvc, scsiq,
8125 free_q_head);
8126 }
8127 } else if (n_q_required == 1) {
8128 next_qp = AscAllocFreeQueue(iop_base, free_q_head);
8129 if (next_qp != ASC_QLINK_END) {
8130 scsiq->q1.q_no = free_q_head;
8131 sta = AscPutReadyQueue(asc_dvc, scsiq, free_q_head);
8132 }
8133 }
8134 if (sta == 1) {
8135 AscPutVarFreeQHead(iop_base, next_qp);
8136 asc_dvc->cur_total_qng += n_q_required;
8137 asc_dvc->cur_dvc_qng[tid_no]++;
8138 }
8139 return sta;
8140}
8141
8142#define ASC_SYN_OFFSET_ONE_DISABLE_LIST 16
8143static uchar _syn_offset_one_disable_cmd[ASC_SYN_OFFSET_ONE_DISABLE_LIST] = {
8144 INQUIRY,
8145 REQUEST_SENSE,
8146 READ_CAPACITY,
8147 READ_TOC,
8148 MODE_SELECT,
8149 MODE_SENSE,
8150 MODE_SELECT_10,
8151 MODE_SENSE_10,
8152 0xFF,
8153 0xFF,
8154 0xFF,
8155 0xFF,
8156 0xFF,
8157 0xFF,
8158 0xFF,
8159 0xFF
8160};
8161
8162static int AscExeScsiQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq)
8163{
8164 PortAddr iop_base;
8165 int sta;
8166 int n_q_required;
Hannes Reineckeae267592015-04-24 13:18:28 +02008167 bool disable_syn_offset_one_fix;
Matthew Wilcox51219352007-10-02 21:55:22 -04008168 int i;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008169 u32 addr;
Matthew Wilcox51219352007-10-02 21:55:22 -04008170 ushort sg_entry_cnt = 0;
8171 ushort sg_entry_cnt_minus_one = 0;
8172 uchar target_ix;
8173 uchar tid_no;
8174 uchar sdtr_data;
8175 uchar extra_bytes;
8176 uchar scsi_cmd;
8177 uchar disable_cmd;
8178 ASC_SG_HEAD *sg_head;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008179 unsigned long data_cnt;
Matthew Wilcox51219352007-10-02 21:55:22 -04008180
8181 iop_base = asc_dvc->iop_base;
8182 sg_head = scsiq->sg_head;
8183 if (asc_dvc->err_code != 0)
Hannes Reineckef1138a82015-04-24 13:18:29 +02008184 return ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04008185 scsiq->q1.q_no = 0;
8186 if ((scsiq->q2.tag_code & ASC_TAG_FLAG_EXTRA_BYTES) == 0) {
8187 scsiq->q1.extra_bytes = 0;
8188 }
8189 sta = 0;
8190 target_ix = scsiq->q2.target_ix;
8191 tid_no = ASC_TIX_TO_TID(target_ix);
8192 n_q_required = 1;
8193 if (scsiq->cdbptr[0] == REQUEST_SENSE) {
8194 if ((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) {
8195 asc_dvc->sdtr_done &= ~scsiq->q1.target_id;
8196 sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
8197 AscMsgOutSDTR(asc_dvc,
8198 asc_dvc->
8199 sdtr_period_tbl[(sdtr_data >> 4) &
8200 (uchar)(asc_dvc->
8201 max_sdtr_index -
8202 1)],
8203 (uchar)(sdtr_data & (uchar)
8204 ASC_SYN_MAX_OFFSET));
8205 scsiq->q1.cntl |= (QC_MSG_OUT | QC_URGENT);
8206 }
8207 }
8208 if (asc_dvc->in_critical_cnt != 0) {
8209 AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CRITICAL_RE_ENTRY);
Hannes Reineckef1138a82015-04-24 13:18:29 +02008210 return ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04008211 }
8212 asc_dvc->in_critical_cnt++;
8213 if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
8214 if ((sg_entry_cnt = sg_head->entry_cnt) == 0) {
8215 asc_dvc->in_critical_cnt--;
Hannes Reineckef1138a82015-04-24 13:18:29 +02008216 return ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04008217 }
Matthew Wilcox51219352007-10-02 21:55:22 -04008218 if (sg_entry_cnt > ASC_MAX_SG_LIST) {
8219 asc_dvc->in_critical_cnt--;
Hannes Reineckef1138a82015-04-24 13:18:29 +02008220 return ASC_ERROR;
Matthew Wilcox51219352007-10-02 21:55:22 -04008221 }
Matthew Wilcox51219352007-10-02 21:55:22 -04008222 if (sg_entry_cnt == 1) {
Hannes Reinecke37f64602015-04-24 13:18:32 +02008223 scsiq->q1.data_addr = cpu_to_le32(sg_head->sg_list[0].addr);
8224 scsiq->q1.data_cnt = cpu_to_le32(sg_head->sg_list[0].bytes);
Matthew Wilcox51219352007-10-02 21:55:22 -04008225 scsiq->q1.cntl &= ~(QC_SG_HEAD | QC_SG_SWAP_QUEUE);
8226 }
8227 sg_entry_cnt_minus_one = sg_entry_cnt - 1;
8228 }
8229 scsi_cmd = scsiq->cdbptr[0];
Hannes Reineckeae267592015-04-24 13:18:28 +02008230 disable_syn_offset_one_fix = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04008231 if ((asc_dvc->pci_fix_asyn_xfer & scsiq->q1.target_id) &&
8232 !(asc_dvc->pci_fix_asyn_xfer_always & scsiq->q1.target_id)) {
8233 if (scsiq->q1.cntl & QC_SG_HEAD) {
8234 data_cnt = 0;
8235 for (i = 0; i < sg_entry_cnt; i++) {
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008236 data_cnt += le32_to_cpu(sg_head->sg_list[i].
8237 bytes);
Matthew Wilcox51219352007-10-02 21:55:22 -04008238 }
8239 } else {
8240 data_cnt = le32_to_cpu(scsiq->q1.data_cnt);
8241 }
8242 if (data_cnt != 0UL) {
8243 if (data_cnt < 512UL) {
Hannes Reineckeae267592015-04-24 13:18:28 +02008244 disable_syn_offset_one_fix = true;
Matthew Wilcox51219352007-10-02 21:55:22 -04008245 } else {
8246 for (i = 0; i < ASC_SYN_OFFSET_ONE_DISABLE_LIST;
8247 i++) {
8248 disable_cmd =
8249 _syn_offset_one_disable_cmd[i];
8250 if (disable_cmd == 0xFF) {
8251 break;
8252 }
8253 if (scsi_cmd == disable_cmd) {
8254 disable_syn_offset_one_fix =
Hannes Reineckeae267592015-04-24 13:18:28 +02008255 true;
Matthew Wilcox51219352007-10-02 21:55:22 -04008256 break;
8257 }
8258 }
8259 }
8260 }
8261 }
8262 if (disable_syn_offset_one_fix) {
Christoph Hellwig68d81f42014-11-24 07:07:25 -08008263 scsiq->q2.tag_code &= ~SIMPLE_QUEUE_TAG;
Matthew Wilcox51219352007-10-02 21:55:22 -04008264 scsiq->q2.tag_code |= (ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX |
8265 ASC_TAG_FLAG_DISABLE_DISCONNECT);
8266 } else {
8267 scsiq->q2.tag_code &= 0x27;
8268 }
8269 if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
8270 if (asc_dvc->bug_fix_cntl) {
8271 if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
8272 if ((scsi_cmd == READ_6) ||
8273 (scsi_cmd == READ_10)) {
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008274 addr = le32_to_cpu(sg_head->
Matthew Wilcox51219352007-10-02 21:55:22 -04008275 sg_list
8276 [sg_entry_cnt_minus_one].
8277 addr) +
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008278 le32_to_cpu(sg_head->
Matthew Wilcox51219352007-10-02 21:55:22 -04008279 sg_list
8280 [sg_entry_cnt_minus_one].
8281 bytes);
8282 extra_bytes =
8283 (uchar)((ushort)addr & 0x0003);
8284 if ((extra_bytes != 0)
8285 &&
8286 ((scsiq->q2.
8287 tag_code &
8288 ASC_TAG_FLAG_EXTRA_BYTES)
8289 == 0)) {
8290 scsiq->q2.tag_code |=
8291 ASC_TAG_FLAG_EXTRA_BYTES;
8292 scsiq->q1.extra_bytes =
8293 extra_bytes;
8294 data_cnt =
8295 le32_to_cpu(sg_head->
8296 sg_list
8297 [sg_entry_cnt_minus_one].
8298 bytes);
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008299 data_cnt -= extra_bytes;
Matthew Wilcox51219352007-10-02 21:55:22 -04008300 sg_head->
8301 sg_list
8302 [sg_entry_cnt_minus_one].
8303 bytes =
8304 cpu_to_le32(data_cnt);
8305 }
8306 }
8307 }
8308 }
8309 sg_head->entry_to_copy = sg_head->entry_cnt;
Matthew Wilcox51219352007-10-02 21:55:22 -04008310 n_q_required = AscSgListToQueue(sg_entry_cnt);
8311 if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, n_q_required) >=
8312 (uint) n_q_required)
8313 || ((scsiq->q1.cntl & QC_URGENT) != 0)) {
8314 if ((sta =
8315 AscSendScsiQueue(asc_dvc, scsiq,
8316 n_q_required)) == 1) {
8317 asc_dvc->in_critical_cnt--;
8318 return (sta);
8319 }
8320 }
8321 } else {
8322 if (asc_dvc->bug_fix_cntl) {
8323 if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
8324 if ((scsi_cmd == READ_6) ||
8325 (scsi_cmd == READ_10)) {
8326 addr =
8327 le32_to_cpu(scsiq->q1.data_addr) +
8328 le32_to_cpu(scsiq->q1.data_cnt);
8329 extra_bytes =
8330 (uchar)((ushort)addr & 0x0003);
8331 if ((extra_bytes != 0)
8332 &&
8333 ((scsiq->q2.
8334 tag_code &
8335 ASC_TAG_FLAG_EXTRA_BYTES)
8336 == 0)) {
8337 data_cnt =
8338 le32_to_cpu(scsiq->q1.
8339 data_cnt);
8340 if (((ushort)data_cnt & 0x01FF)
8341 == 0) {
8342 scsiq->q2.tag_code |=
8343 ASC_TAG_FLAG_EXTRA_BYTES;
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008344 data_cnt -= extra_bytes;
Matthew Wilcox51219352007-10-02 21:55:22 -04008345 scsiq->q1.data_cnt =
8346 cpu_to_le32
8347 (data_cnt);
8348 scsiq->q1.extra_bytes =
8349 extra_bytes;
8350 }
8351 }
8352 }
8353 }
8354 }
8355 n_q_required = 1;
8356 if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, 1) >= 1) ||
8357 ((scsiq->q1.cntl & QC_URGENT) != 0)) {
8358 if ((sta = AscSendScsiQueue(asc_dvc, scsiq,
8359 n_q_required)) == 1) {
8360 asc_dvc->in_critical_cnt--;
8361 return (sta);
8362 }
8363 }
8364 }
8365 asc_dvc->in_critical_cnt--;
8366 return (sta);
8367}
8368
8369/*
8370 * AdvExeScsiQueue() - Send a request to the RISC microcode program.
8371 *
8372 * Allocate a carrier structure, point the carrier to the ADV_SCSI_REQ_Q,
8373 * add the carrier to the ICQ (Initiator Command Queue), and tickle the
8374 * RISC to notify it a new command is ready to be executed.
8375 *
8376 * If 'done_status' is not set to QD_DO_RETRY, then 'error_retry' will be
8377 * set to SCSI_MAX_RETRY.
8378 *
Hannes Reinecke9fef6ba2015-04-24 13:18:33 +02008379 * Multi-byte fields in the ADV_SCSI_REQ_Q that are used by the microcode
Matthew Wilcox51219352007-10-02 21:55:22 -04008380 * for DMA addresses or math operations are byte swapped to little-endian
8381 * order.
8382 *
8383 * Return:
8384 * ADV_SUCCESS(1) - The request was successfully queued.
8385 * ADV_BUSY(0) - Resource unavailable; Retry again after pending
8386 * request completes.
8387 * ADV_ERROR(-1) - Invalid ADV_SCSI_REQ_Q request structure
8388 * host IC error.
8389 */
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008390static int AdvExeScsiQueue(ADV_DVC_VAR *asc_dvc, adv_req_t *reqp)
Matthew Wilcox51219352007-10-02 21:55:22 -04008391{
8392 AdvPortAddr iop_base;
Matthew Wilcox51219352007-10-02 21:55:22 -04008393 ADV_CARR_T *new_carrp;
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008394 ADV_SCSI_REQ_Q *scsiq = &reqp->scsi_req_q;
Matthew Wilcox51219352007-10-02 21:55:22 -04008395
8396 /*
8397 * The ADV_SCSI_REQ_Q 'target_id' field should never exceed ADV_MAX_TID.
8398 */
8399 if (scsiq->target_id > ADV_MAX_TID) {
8400 scsiq->host_status = QHSTA_M_INVALID_DEVICE;
8401 scsiq->done_status = QD_WITH_ERROR;
8402 return ADV_ERROR;
8403 }
8404
8405 iop_base = asc_dvc->iop_base;
8406
8407 /*
8408 * Allocate a carrier ensuring at least one carrier always
8409 * remains on the freelist and initialize fields.
8410 */
Hannes Reinecke98b96a72015-04-24 13:18:23 +02008411 new_carrp = adv_get_next_carrier(asc_dvc);
8412 if (!new_carrp) {
8413 ASC_DBG(1, "No free carriers\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04008414 return ADV_BUSY;
8415 }
Matthew Wilcox51219352007-10-02 21:55:22 -04008416
Hannes Reinecke98b96a72015-04-24 13:18:23 +02008417 asc_dvc->carr_pending_cnt++;
Matthew Wilcox51219352007-10-02 21:55:22 -04008418
Matthew Wilcox51219352007-10-02 21:55:22 -04008419 /* Save virtual and physical address of ADV_SCSI_REQ_Q and carrier. */
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008420 scsiq->scsiq_ptr = cpu_to_le32(scsiq->srb_tag);
8421 scsiq->scsiq_rptr = cpu_to_le32(reqp->req_addr);
Matthew Wilcox51219352007-10-02 21:55:22 -04008422
Hannes Reinecke98b96a72015-04-24 13:18:23 +02008423 scsiq->carr_va = asc_dvc->icq_sp->carr_va;
Matthew Wilcox51219352007-10-02 21:55:22 -04008424 scsiq->carr_pa = asc_dvc->icq_sp->carr_pa;
8425
8426 /*
8427 * Use the current stopper to send the ADV_SCSI_REQ_Q command to
8428 * the microcode. The newly allocated stopper will become the new
8429 * stopper.
8430 */
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008431 asc_dvc->icq_sp->areq_vpa = scsiq->scsiq_rptr;
Matthew Wilcox51219352007-10-02 21:55:22 -04008432
8433 /*
8434 * Set the 'next_vpa' pointer for the old stopper to be the
8435 * physical address of the new stopper. The RISC can only
8436 * follow physical addresses.
8437 */
8438 asc_dvc->icq_sp->next_vpa = new_carrp->carr_pa;
8439
8440 /*
8441 * Set the host adapter stopper pointer to point to the new carrier.
8442 */
8443 asc_dvc->icq_sp = new_carrp;
8444
8445 if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
8446 asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
8447 /*
8448 * Tickle the RISC to tell it to read its Command Queue Head pointer.
8449 */
8450 AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_A);
8451 if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
8452 /*
8453 * Clear the tickle value. In the ASC-3550 the RISC flag
8454 * command 'clr_tickle_a' does not work unless the host
8455 * value is cleared.
8456 */
8457 AdvWriteByteRegister(iop_base, IOPB_TICKLE,
8458 ADV_TICKLE_NOP);
8459 }
8460 } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
8461 /*
8462 * Notify the RISC a carrier is ready by writing the physical
8463 * address of the new carrier stopper to the COMMA register.
8464 */
8465 AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
8466 le32_to_cpu(new_carrp->carr_pa));
8467 }
8468
8469 return ADV_SUCCESS;
8470}
8471
8472/*
8473 * Execute a single 'Scsi_Cmnd'.
Matthew Wilcox51219352007-10-02 21:55:22 -04008474 */
8475static int asc_execute_scsi_cmnd(struct scsi_cmnd *scp)
8476{
Matthew Wilcox41d24932007-10-02 21:55:24 -04008477 int ret, err_code;
Matthew Wilcoxd2411492007-10-02 21:55:31 -04008478 struct asc_board *boardp = shost_priv(scp->device->host);
Matthew Wilcox51219352007-10-02 21:55:22 -04008479
Matthew Wilcoxb352f922007-10-02 21:55:33 -04008480 ASC_DBG(1, "scp 0x%p\n", scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04008481
8482 if (ASC_NARROW_BOARD(boardp)) {
Matthew Wilcox41d24932007-10-02 21:55:24 -04008483 ASC_DVC_VAR *asc_dvc = &boardp->dvc_var.asc_dvc_var;
Matthew Wilcox05848b62007-10-02 21:55:25 -04008484 struct asc_scsi_q asc_scsi_q;
Matthew Wilcox51219352007-10-02 21:55:22 -04008485
Matthew Wilcox41d24932007-10-02 21:55:24 -04008486 /* asc_build_req() can not return ASC_BUSY. */
Matthew Wilcox05848b62007-10-02 21:55:25 -04008487 ret = asc_build_req(boardp, scp, &asc_scsi_q);
8488 if (ret == ASC_ERROR) {
Matthew Wilcox51219352007-10-02 21:55:22 -04008489 ASC_STATS(scp->device->host, build_error);
8490 return ASC_ERROR;
8491 }
8492
Matthew Wilcox41d24932007-10-02 21:55:24 -04008493 ret = AscExeScsiQueue(asc_dvc, &asc_scsi_q);
Matthew Wilcox05848b62007-10-02 21:55:25 -04008494 kfree(asc_scsi_q.sg_head);
Matthew Wilcox41d24932007-10-02 21:55:24 -04008495 err_code = asc_dvc->err_code;
Matthew Wilcox51219352007-10-02 21:55:22 -04008496 } else {
Matthew Wilcox41d24932007-10-02 21:55:24 -04008497 ADV_DVC_VAR *adv_dvc = &boardp->dvc_var.adv_dvc_var;
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008498 adv_req_t *adv_reqp;
Matthew Wilcox51219352007-10-02 21:55:22 -04008499
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008500 switch (adv_build_req(boardp, scp, &adv_reqp)) {
Matthew Wilcox51219352007-10-02 21:55:22 -04008501 case ASC_NOERROR:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04008502 ASC_DBG(3, "adv_build_req ASC_NOERROR\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04008503 break;
8504 case ASC_BUSY:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04008505 ASC_DBG(1, "adv_build_req ASC_BUSY\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04008506 /*
8507 * The asc_stats fields 'adv_build_noreq' and
8508 * 'adv_build_nosg' count wide board busy conditions.
8509 * They are updated in adv_build_req and
8510 * adv_get_sglist, respectively.
8511 */
8512 return ASC_BUSY;
8513 case ASC_ERROR:
8514 default:
Matthew Wilcoxb352f922007-10-02 21:55:33 -04008515 ASC_DBG(1, "adv_build_req ASC_ERROR\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04008516 ASC_STATS(scp->device->host, build_error);
8517 return ASC_ERROR;
8518 }
8519
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008520 ret = AdvExeScsiQueue(adv_dvc, adv_reqp);
Matthew Wilcox41d24932007-10-02 21:55:24 -04008521 err_code = adv_dvc->err_code;
8522 }
8523
8524 switch (ret) {
8525 case ASC_NOERROR:
8526 ASC_STATS(scp->device->host, exe_noerror);
8527 /*
8528 * Increment monotonically increasing per device
8529 * successful request counter. Wrapping doesn't matter.
8530 */
8531 boardp->reqcnt[scp->device->id]++;
Matthew Wilcoxb352f922007-10-02 21:55:33 -04008532 ASC_DBG(1, "ExeScsiQueue() ASC_NOERROR\n");
Matthew Wilcox41d24932007-10-02 21:55:24 -04008533 break;
8534 case ASC_BUSY:
Hannes Reinecke4b47e462015-04-24 13:18:24 +02008535 ASC_DBG(1, "ExeScsiQueue() ASC_BUSY\n");
Matthew Wilcox41d24932007-10-02 21:55:24 -04008536 ASC_STATS(scp->device->host, exe_busy);
8537 break;
8538 case ASC_ERROR:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04008539 scmd_printk(KERN_ERR, scp, "ExeScsiQueue() ASC_ERROR, "
8540 "err_code 0x%x\n", err_code);
Matthew Wilcox41d24932007-10-02 21:55:24 -04008541 ASC_STATS(scp->device->host, exe_error);
8542 scp->result = HOST_BYTE(DID_ERROR);
8543 break;
8544 default:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04008545 scmd_printk(KERN_ERR, scp, "ExeScsiQueue() unknown, "
8546 "err_code 0x%x\n", err_code);
Matthew Wilcox41d24932007-10-02 21:55:24 -04008547 ASC_STATS(scp->device->host, exe_unknown);
8548 scp->result = HOST_BYTE(DID_ERROR);
8549 break;
Matthew Wilcox51219352007-10-02 21:55:22 -04008550 }
8551
Matthew Wilcoxb352f922007-10-02 21:55:33 -04008552 ASC_DBG(1, "end\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04008553 return ret;
8554}
8555
8556/*
8557 * advansys_queuecommand() - interrupt-driven I/O entrypoint.
8558 *
8559 * This function always returns 0. Command return status is saved
8560 * in the 'scp' result field.
8561 */
8562static int
Jeff Garzikf2812332010-11-16 02:10:29 -05008563advansys_queuecommand_lck(struct scsi_cmnd *scp, void (*done)(struct scsi_cmnd *))
Matthew Wilcox51219352007-10-02 21:55:22 -04008564{
8565 struct Scsi_Host *shost = scp->device->host;
Matthew Wilcox51219352007-10-02 21:55:22 -04008566 int asc_res, result = 0;
8567
8568 ASC_STATS(shost, queuecommand);
8569 scp->scsi_done = done;
8570
Matthew Wilcox51219352007-10-02 21:55:22 -04008571 asc_res = asc_execute_scsi_cmnd(scp);
Matthew Wilcox51219352007-10-02 21:55:22 -04008572
8573 switch (asc_res) {
8574 case ASC_NOERROR:
8575 break;
8576 case ASC_BUSY:
8577 result = SCSI_MLQUEUE_HOST_BUSY;
8578 break;
8579 case ASC_ERROR:
8580 default:
8581 asc_scsi_done(scp);
8582 break;
8583 }
8584
8585 return result;
8586}
8587
Jeff Garzikf2812332010-11-16 02:10:29 -05008588static DEF_SCSI_QCMD(advansys_queuecommand)
8589
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008590static ushort AscGetEisaChipCfg(PortAddr iop_base)
Matthew Wilcox51219352007-10-02 21:55:22 -04008591{
8592 PortAddr eisa_cfg_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
8593 (PortAddr) (ASC_EISA_CFG_IOP_MASK);
8594 return inpw(eisa_cfg_iop);
8595}
8596
8597/*
8598 * Return the BIOS address of the adapter at the specified
8599 * I/O port and with the specified bus type.
8600 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008601static unsigned short AscGetChipBiosAddress(PortAddr iop_base,
8602 unsigned short bus_type)
Matthew Wilcox51219352007-10-02 21:55:22 -04008603{
8604 unsigned short cfg_lsw;
8605 unsigned short bios_addr;
8606
8607 /*
8608 * The PCI BIOS is re-located by the motherboard BIOS. Because
8609 * of this the driver can not determine where a PCI BIOS is
8610 * loaded and executes.
8611 */
8612 if (bus_type & ASC_IS_PCI)
8613 return 0;
8614
8615 if ((bus_type & ASC_IS_EISA) != 0) {
8616 cfg_lsw = AscGetEisaChipCfg(iop_base);
8617 cfg_lsw &= 0x000F;
8618 bios_addr = ASC_BIOS_MIN_ADDR + cfg_lsw * ASC_BIOS_BANK_SIZE;
8619 return bios_addr;
8620 }
8621
8622 cfg_lsw = AscGetChipCfgLsw(iop_base);
8623
8624 /*
8625 * ISA PnP uses the top bit as the 32K BIOS flag
8626 */
8627 if (bus_type == ASC_IS_ISAPNP)
8628 cfg_lsw &= 0x7FFF;
8629 bios_addr = ASC_BIOS_MIN_ADDR + (cfg_lsw >> 12) * ASC_BIOS_BANK_SIZE;
8630 return bios_addr;
8631}
8632
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008633static uchar AscSetChipScsiID(PortAddr iop_base, uchar new_host_id)
Matthew Wilcox51219352007-10-02 21:55:22 -04008634{
8635 ushort cfg_lsw;
8636
8637 if (AscGetChipScsiID(iop_base) == new_host_id) {
8638 return (new_host_id);
8639 }
8640 cfg_lsw = AscGetChipCfgLsw(iop_base);
8641 cfg_lsw &= 0xF8FF;
8642 cfg_lsw |= (ushort)((new_host_id & ASC_MAX_TID) << 8);
8643 AscSetChipCfgLsw(iop_base, cfg_lsw);
8644 return (AscGetChipScsiID(iop_base));
8645}
8646
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008647static unsigned char AscGetChipScsiCtrl(PortAddr iop_base)
Matthew Wilcox51219352007-10-02 21:55:22 -04008648{
8649 unsigned char sc;
8650
8651 AscSetBank(iop_base, 1);
8652 sc = inp(iop_base + IOP_REG_SC);
8653 AscSetBank(iop_base, 0);
8654 return sc;
8655}
8656
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008657static unsigned char AscGetChipVersion(PortAddr iop_base,
8658 unsigned short bus_type)
Matthew Wilcox51219352007-10-02 21:55:22 -04008659{
8660 if (bus_type & ASC_IS_EISA) {
8661 PortAddr eisa_iop;
8662 unsigned char revision;
8663 eisa_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
8664 (PortAddr) ASC_EISA_REV_IOP_MASK;
8665 revision = inp(eisa_iop);
8666 return ASC_CHIP_MIN_VER_EISA - 1 + revision;
8667 }
8668 return AscGetChipVerNo(iop_base);
8669}
8670
Matthew Wilcox51219352007-10-02 21:55:22 -04008671#ifdef CONFIG_ISA
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008672static void AscEnableIsaDma(uchar dma_channel)
Matthew Wilcox51219352007-10-02 21:55:22 -04008673{
8674 if (dma_channel < 4) {
8675 outp(0x000B, (ushort)(0xC0 | dma_channel));
8676 outp(0x000A, dma_channel);
8677 } else if (dma_channel < 8) {
8678 outp(0x00D6, (ushort)(0xC0 | (dma_channel - 4)));
8679 outp(0x00D4, (ushort)(dma_channel - 4));
8680 }
Matthew Wilcox51219352007-10-02 21:55:22 -04008681}
8682#endif /* CONFIG_ISA */
8683
8684static int AscStopQueueExe(PortAddr iop_base)
8685{
8686 int count = 0;
8687
8688 if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) == 0) {
8689 AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
8690 ASC_STOP_REQ_RISC_STOP);
8691 do {
8692 if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) &
8693 ASC_STOP_ACK_RISC_STOP) {
8694 return (1);
8695 }
8696 mdelay(100);
8697 } while (count++ < 20);
8698 }
8699 return (0);
8700}
8701
Hannes Reinecke95cfab62015-04-24 13:18:27 +02008702static unsigned int AscGetMaxDmaCount(ushort bus_type)
Matthew Wilcox51219352007-10-02 21:55:22 -04008703{
8704 if (bus_type & ASC_IS_ISA)
8705 return ASC_MAX_ISA_DMA_COUNT;
8706 else if (bus_type & (ASC_IS_EISA | ASC_IS_VL))
8707 return ASC_MAX_VL_DMA_COUNT;
8708 return ASC_MAX_PCI_DMA_COUNT;
8709}
8710
8711#ifdef CONFIG_ISA
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008712static ushort AscGetIsaDmaChannel(PortAddr iop_base)
Matthew Wilcox51219352007-10-02 21:55:22 -04008713{
8714 ushort channel;
8715
8716 channel = AscGetChipCfgLsw(iop_base) & 0x0003;
8717 if (channel == 0x03)
8718 return (0);
8719 else if (channel == 0x00)
8720 return (7);
8721 return (channel + 4);
8722}
8723
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008724static ushort AscSetIsaDmaChannel(PortAddr iop_base, ushort dma_channel)
Matthew Wilcox51219352007-10-02 21:55:22 -04008725{
8726 ushort cfg_lsw;
8727 uchar value;
8728
8729 if ((dma_channel >= 5) && (dma_channel <= 7)) {
8730 if (dma_channel == 7)
8731 value = 0x00;
8732 else
8733 value = dma_channel - 4;
8734 cfg_lsw = AscGetChipCfgLsw(iop_base) & 0xFFFC;
8735 cfg_lsw |= value;
8736 AscSetChipCfgLsw(iop_base, cfg_lsw);
8737 return (AscGetIsaDmaChannel(iop_base));
8738 }
8739 return 0;
8740}
8741
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008742static uchar AscGetIsaDmaSpeed(PortAddr iop_base)
Matthew Wilcox51219352007-10-02 21:55:22 -04008743{
8744 uchar speed_value;
8745
8746 AscSetBank(iop_base, 1);
8747 speed_value = AscReadChipDmaSpeed(iop_base);
8748 speed_value &= 0x07;
8749 AscSetBank(iop_base, 0);
8750 return speed_value;
8751}
8752
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008753static uchar AscSetIsaDmaSpeed(PortAddr iop_base, uchar speed_value)
Matthew Wilcox51219352007-10-02 21:55:22 -04008754{
8755 speed_value &= 0x07;
8756 AscSetBank(iop_base, 1);
8757 AscWriteChipDmaSpeed(iop_base, speed_value);
8758 AscSetBank(iop_base, 0);
8759 return AscGetIsaDmaSpeed(iop_base);
8760}
8761#endif /* CONFIG_ISA */
8762
Hannes Reineckef33134e2015-04-24 13:18:31 +02008763static void AscInitAscDvcVar(ASC_DVC_VAR *asc_dvc)
Matthew Wilcox51219352007-10-02 21:55:22 -04008764{
8765 int i;
8766 PortAddr iop_base;
Matthew Wilcox51219352007-10-02 21:55:22 -04008767 uchar chip_version;
8768
8769 iop_base = asc_dvc->iop_base;
Matthew Wilcox51219352007-10-02 21:55:22 -04008770 asc_dvc->err_code = 0;
8771 if ((asc_dvc->bus_type &
8772 (ASC_IS_ISA | ASC_IS_PCI | ASC_IS_EISA | ASC_IS_VL)) == 0) {
8773 asc_dvc->err_code |= ASC_IERR_NO_BUS_TYPE;
8774 }
8775 AscSetChipControl(iop_base, CC_HALT);
8776 AscSetChipStatus(iop_base, 0);
8777 asc_dvc->bug_fix_cntl = 0;
8778 asc_dvc->pci_fix_asyn_xfer = 0;
8779 asc_dvc->pci_fix_asyn_xfer_always = 0;
Uwe Kleine-König421f91d2010-06-11 12:17:00 +02008780 /* asc_dvc->init_state initialized in AscInitGetConfig(). */
Matthew Wilcox51219352007-10-02 21:55:22 -04008781 asc_dvc->sdtr_done = 0;
8782 asc_dvc->cur_total_qng = 0;
Hannes Reineckeae267592015-04-24 13:18:28 +02008783 asc_dvc->is_in_int = false;
Matthew Wilcox51219352007-10-02 21:55:22 -04008784 asc_dvc->in_critical_cnt = 0;
8785 asc_dvc->last_q_shortage = 0;
8786 asc_dvc->use_tagged_qng = 0;
8787 asc_dvc->no_scam = 0;
8788 asc_dvc->unit_not_ready = 0;
8789 asc_dvc->queue_full_or_busy = 0;
8790 asc_dvc->redo_scam = 0;
8791 asc_dvc->res2 = 0;
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04008792 asc_dvc->min_sdtr_index = 0;
Matthew Wilcox51219352007-10-02 21:55:22 -04008793 asc_dvc->cfg->can_tagged_qng = 0;
8794 asc_dvc->cfg->cmd_qng_enabled = 0;
8795 asc_dvc->dvc_cntl = ASC_DEF_DVC_CNTL;
8796 asc_dvc->init_sdtr = 0;
8797 asc_dvc->max_total_qng = ASC_DEF_MAX_TOTAL_QNG;
8798 asc_dvc->scsi_reset_wait = 3;
8799 asc_dvc->start_motor = ASC_SCSI_WIDTH_BIT_SET;
8800 asc_dvc->max_dma_count = AscGetMaxDmaCount(asc_dvc->bus_type);
8801 asc_dvc->cfg->sdtr_enable = ASC_SCSI_WIDTH_BIT_SET;
8802 asc_dvc->cfg->disc_enable = ASC_SCSI_WIDTH_BIT_SET;
8803 asc_dvc->cfg->chip_scsi_id = ASC_DEF_CHIP_SCSI_ID;
Matthew Wilcox51219352007-10-02 21:55:22 -04008804 chip_version = AscGetChipVersion(iop_base, asc_dvc->bus_type);
8805 asc_dvc->cfg->chip_version = chip_version;
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04008806 asc_dvc->sdtr_period_tbl = asc_syn_xfer_period;
Matthew Wilcox51219352007-10-02 21:55:22 -04008807 asc_dvc->max_sdtr_index = 7;
8808 if ((asc_dvc->bus_type & ASC_IS_PCI) &&
8809 (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3150)) {
8810 asc_dvc->bus_type = ASC_IS_PCI_ULTRA;
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04008811 asc_dvc->sdtr_period_tbl = asc_syn_ultra_xfer_period;
Matthew Wilcox51219352007-10-02 21:55:22 -04008812 asc_dvc->max_sdtr_index = 15;
8813 if (chip_version == ASC_CHIP_VER_PCI_ULTRA_3150) {
8814 AscSetExtraControl(iop_base,
8815 (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
8816 } else if (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3050) {
8817 AscSetExtraControl(iop_base,
8818 (SEC_ACTIVE_NEGATE |
8819 SEC_ENABLE_FILTER));
8820 }
8821 }
8822 if (asc_dvc->bus_type == ASC_IS_PCI) {
8823 AscSetExtraControl(iop_base,
8824 (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
8825 }
8826
8827 asc_dvc->cfg->isa_dma_speed = ASC_DEF_ISA_DMA_SPEED;
8828#ifdef CONFIG_ISA
8829 if ((asc_dvc->bus_type & ASC_IS_ISA) != 0) {
8830 if (chip_version >= ASC_CHIP_MIN_VER_ISA_PNP) {
8831 AscSetChipIFC(iop_base, IFC_INIT_DEFAULT);
8832 asc_dvc->bus_type = ASC_IS_ISAPNP;
8833 }
8834 asc_dvc->cfg->isa_dma_channel =
8835 (uchar)AscGetIsaDmaChannel(iop_base);
8836 }
8837#endif /* CONFIG_ISA */
8838 for (i = 0; i <= ASC_MAX_TID; i++) {
8839 asc_dvc->cur_dvc_qng[i] = 0;
8840 asc_dvc->max_dvc_qng[i] = ASC_MAX_SCSI1_QNG;
8841 asc_dvc->scsiq_busy_head[i] = (ASC_SCSI_Q *)0L;
8842 asc_dvc->scsiq_busy_tail[i] = (ASC_SCSI_Q *)0L;
8843 asc_dvc->cfg->max_tag_qng[i] = ASC_MAX_INRAM_TAG_QNG;
8844 }
Matthew Wilcox51219352007-10-02 21:55:22 -04008845}
8846
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008847static int AscWriteEEPCmdReg(PortAddr iop_base, uchar cmd_reg)
Matthew Wilcox51219352007-10-02 21:55:22 -04008848{
8849 int retry;
8850
8851 for (retry = 0; retry < ASC_EEP_MAX_RETRY; retry++) {
8852 unsigned char read_back;
8853 AscSetChipEEPCmd(iop_base, cmd_reg);
8854 mdelay(1);
8855 read_back = AscGetChipEEPCmd(iop_base);
8856 if (read_back == cmd_reg)
8857 return 1;
8858 }
8859 return 0;
8860}
8861
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008862static void AscWaitEEPRead(void)
Matthew Wilcox51219352007-10-02 21:55:22 -04008863{
8864 mdelay(1);
8865}
8866
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008867static ushort AscReadEEPWord(PortAddr iop_base, uchar addr)
Matthew Wilcox51219352007-10-02 21:55:22 -04008868{
8869 ushort read_wval;
8870 uchar cmd_reg;
8871
8872 AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
8873 AscWaitEEPRead();
8874 cmd_reg = addr | ASC_EEP_CMD_READ;
8875 AscWriteEEPCmdReg(iop_base, cmd_reg);
8876 AscWaitEEPRead();
8877 read_wval = AscGetChipEEPData(iop_base);
8878 AscWaitEEPRead();
8879 return read_wval;
8880}
8881
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008882static ushort AscGetEEPConfig(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf,
8883 ushort bus_type)
Matthew Wilcox51219352007-10-02 21:55:22 -04008884{
8885 ushort wval;
8886 ushort sum;
8887 ushort *wbuf;
8888 int cfg_beg;
8889 int cfg_end;
8890 int uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
8891 int s_addr;
8892
8893 wbuf = (ushort *)cfg_buf;
8894 sum = 0;
8895 /* Read two config words; Byte-swapping done by AscReadEEPWord(). */
8896 for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
8897 *wbuf = AscReadEEPWord(iop_base, (uchar)s_addr);
8898 sum += *wbuf;
8899 }
8900 if (bus_type & ASC_IS_VL) {
8901 cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
8902 cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
8903 } else {
8904 cfg_beg = ASC_EEP_DVC_CFG_BEG;
8905 cfg_end = ASC_EEP_MAX_DVC_ADDR;
8906 }
8907 for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
8908 wval = AscReadEEPWord(iop_base, (uchar)s_addr);
8909 if (s_addr <= uchar_end_in_config) {
8910 /*
8911 * Swap all char fields - must unswap bytes already swapped
8912 * by AscReadEEPWord().
8913 */
8914 *wbuf = le16_to_cpu(wval);
8915 } else {
8916 /* Don't swap word field at the end - cntl field. */
8917 *wbuf = wval;
8918 }
8919 sum += wval; /* Checksum treats all EEPROM data as words. */
8920 }
8921 /*
8922 * Read the checksum word which will be compared against 'sum'
8923 * by the caller. Word field already swapped.
8924 */
8925 *wbuf = AscReadEEPWord(iop_base, (uchar)s_addr);
8926 return sum;
8927}
8928
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008929static int AscTestExternalLram(ASC_DVC_VAR *asc_dvc)
Matthew Wilcox51219352007-10-02 21:55:22 -04008930{
8931 PortAddr iop_base;
8932 ushort q_addr;
8933 ushort saved_word;
8934 int sta;
8935
8936 iop_base = asc_dvc->iop_base;
8937 sta = 0;
8938 q_addr = ASC_QNO_TO_QADDR(241);
8939 saved_word = AscReadLramWord(iop_base, q_addr);
8940 AscSetChipLramAddr(iop_base, q_addr);
8941 AscSetChipLramData(iop_base, 0x55AA);
8942 mdelay(10);
8943 AscSetChipLramAddr(iop_base, q_addr);
8944 if (AscGetChipLramData(iop_base) == 0x55AA) {
8945 sta = 1;
8946 AscWriteLramWord(iop_base, q_addr, saved_word);
8947 }
8948 return (sta);
8949}
8950
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008951static void AscWaitEEPWrite(void)
Matthew Wilcox51219352007-10-02 21:55:22 -04008952{
8953 mdelay(20);
Matthew Wilcox51219352007-10-02 21:55:22 -04008954}
8955
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008956static int AscWriteEEPDataReg(PortAddr iop_base, ushort data_reg)
Matthew Wilcox51219352007-10-02 21:55:22 -04008957{
8958 ushort read_back;
8959 int retry;
8960
8961 retry = 0;
Hannes Reineckeae267592015-04-24 13:18:28 +02008962 while (true) {
Matthew Wilcox51219352007-10-02 21:55:22 -04008963 AscSetChipEEPData(iop_base, data_reg);
8964 mdelay(1);
8965 read_back = AscGetChipEEPData(iop_base);
8966 if (read_back == data_reg) {
8967 return (1);
8968 }
8969 if (retry++ > ASC_EEP_MAX_RETRY) {
8970 return (0);
8971 }
8972 }
8973}
8974
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008975static ushort AscWriteEEPWord(PortAddr iop_base, uchar addr, ushort word_val)
Matthew Wilcox51219352007-10-02 21:55:22 -04008976{
8977 ushort read_wval;
8978
8979 read_wval = AscReadEEPWord(iop_base, addr);
8980 if (read_wval != word_val) {
8981 AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_ABLE);
8982 AscWaitEEPRead();
8983 AscWriteEEPDataReg(iop_base, word_val);
8984 AscWaitEEPRead();
8985 AscWriteEEPCmdReg(iop_base,
8986 (uchar)((uchar)ASC_EEP_CMD_WRITE | addr));
8987 AscWaitEEPWrite();
8988 AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
8989 AscWaitEEPRead();
8990 return (AscReadEEPWord(iop_base, addr));
8991 }
8992 return (read_wval);
8993}
8994
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008995static int AscSetEEPConfigOnce(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf,
8996 ushort bus_type)
Matthew Wilcox51219352007-10-02 21:55:22 -04008997{
8998 int n_error;
8999 ushort *wbuf;
9000 ushort word;
9001 ushort sum;
9002 int s_addr;
9003 int cfg_beg;
9004 int cfg_end;
9005 int uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
9006
9007 wbuf = (ushort *)cfg_buf;
9008 n_error = 0;
9009 sum = 0;
9010 /* Write two config words; AscWriteEEPWord() will swap bytes. */
9011 for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
9012 sum += *wbuf;
9013 if (*wbuf != AscWriteEEPWord(iop_base, (uchar)s_addr, *wbuf)) {
9014 n_error++;
9015 }
9016 }
9017 if (bus_type & ASC_IS_VL) {
9018 cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
9019 cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
9020 } else {
9021 cfg_beg = ASC_EEP_DVC_CFG_BEG;
9022 cfg_end = ASC_EEP_MAX_DVC_ADDR;
9023 }
9024 for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
9025 if (s_addr <= uchar_end_in_config) {
9026 /*
9027 * This is a char field. Swap char fields before they are
9028 * swapped again by AscWriteEEPWord().
9029 */
9030 word = cpu_to_le16(*wbuf);
9031 if (word !=
9032 AscWriteEEPWord(iop_base, (uchar)s_addr, word)) {
9033 n_error++;
9034 }
9035 } else {
9036 /* Don't swap word field at the end - cntl field. */
9037 if (*wbuf !=
9038 AscWriteEEPWord(iop_base, (uchar)s_addr, *wbuf)) {
9039 n_error++;
9040 }
9041 }
9042 sum += *wbuf; /* Checksum calculated from word values. */
9043 }
9044 /* Write checksum word. It will be swapped by AscWriteEEPWord(). */
9045 *wbuf = sum;
9046 if (sum != AscWriteEEPWord(iop_base, (uchar)s_addr, sum)) {
9047 n_error++;
9048 }
9049
9050 /* Read EEPROM back again. */
9051 wbuf = (ushort *)cfg_buf;
9052 /*
9053 * Read two config words; Byte-swapping done by AscReadEEPWord().
9054 */
9055 for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
9056 if (*wbuf != AscReadEEPWord(iop_base, (uchar)s_addr)) {
9057 n_error++;
9058 }
9059 }
9060 if (bus_type & ASC_IS_VL) {
9061 cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
9062 cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
9063 } else {
9064 cfg_beg = ASC_EEP_DVC_CFG_BEG;
9065 cfg_end = ASC_EEP_MAX_DVC_ADDR;
9066 }
9067 for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
9068 if (s_addr <= uchar_end_in_config) {
9069 /*
9070 * Swap all char fields. Must unswap bytes already swapped
9071 * by AscReadEEPWord().
9072 */
9073 word =
9074 le16_to_cpu(AscReadEEPWord
9075 (iop_base, (uchar)s_addr));
9076 } else {
9077 /* Don't swap word field at the end - cntl field. */
9078 word = AscReadEEPWord(iop_base, (uchar)s_addr);
9079 }
9080 if (*wbuf != word) {
9081 n_error++;
9082 }
9083 }
9084 /* Read checksum; Byte swapping not needed. */
9085 if (AscReadEEPWord(iop_base, (uchar)s_addr) != sum) {
9086 n_error++;
9087 }
9088 return n_error;
9089}
9090
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009091static int AscSetEEPConfig(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf,
9092 ushort bus_type)
Matthew Wilcox51219352007-10-02 21:55:22 -04009093{
9094 int retry;
9095 int n_error;
9096
9097 retry = 0;
Hannes Reineckeae267592015-04-24 13:18:28 +02009098 while (true) {
Matthew Wilcox51219352007-10-02 21:55:22 -04009099 if ((n_error = AscSetEEPConfigOnce(iop_base, cfg_buf,
9100 bus_type)) == 0) {
9101 break;
9102 }
9103 if (++retry > ASC_EEP_MAX_RETRY) {
9104 break;
9105 }
9106 }
9107 return n_error;
9108}
9109
Hannes Reineckef33134e2015-04-24 13:18:31 +02009110static int AscInitFromEEP(ASC_DVC_VAR *asc_dvc)
Matthew Wilcox51219352007-10-02 21:55:22 -04009111{
9112 ASCEEP_CONFIG eep_config_buf;
9113 ASCEEP_CONFIG *eep_config;
9114 PortAddr iop_base;
9115 ushort chksum;
9116 ushort warn_code;
9117 ushort cfg_msw, cfg_lsw;
9118 int i;
9119 int write_eep = 0;
9120
9121 iop_base = asc_dvc->iop_base;
9122 warn_code = 0;
9123 AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0x00FE);
9124 AscStopQueueExe(iop_base);
Hannes Reineckeae267592015-04-24 13:18:28 +02009125 if ((AscStopChip(iop_base)) ||
Matthew Wilcox51219352007-10-02 21:55:22 -04009126 (AscGetChipScsiCtrl(iop_base) != 0)) {
9127 asc_dvc->init_state |= ASC_INIT_RESET_SCSI_DONE;
9128 AscResetChipAndScsiBus(asc_dvc);
9129 mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
9130 }
Hannes Reinecked647c782015-04-24 13:18:26 +02009131 if (!AscIsChipHalted(iop_base)) {
Matthew Wilcox51219352007-10-02 21:55:22 -04009132 asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
9133 return (warn_code);
9134 }
9135 AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
9136 if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
9137 asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
9138 return (warn_code);
9139 }
9140 eep_config = (ASCEEP_CONFIG *)&eep_config_buf;
9141 cfg_msw = AscGetChipCfgMsw(iop_base);
9142 cfg_lsw = AscGetChipCfgLsw(iop_base);
9143 if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
9144 cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
9145 warn_code |= ASC_WARN_CFG_MSW_RECOVER;
9146 AscSetChipCfgMsw(iop_base, cfg_msw);
9147 }
9148 chksum = AscGetEEPConfig(iop_base, eep_config, asc_dvc->bus_type);
Matthew Wilcoxb352f922007-10-02 21:55:33 -04009149 ASC_DBG(1, "chksum 0x%x\n", chksum);
Matthew Wilcox51219352007-10-02 21:55:22 -04009150 if (chksum == 0) {
9151 chksum = 0xaa55;
9152 }
9153 if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
9154 warn_code |= ASC_WARN_AUTO_CONFIG;
9155 if (asc_dvc->cfg->chip_version == 3) {
9156 if (eep_config->cfg_lsw != cfg_lsw) {
9157 warn_code |= ASC_WARN_EEPROM_RECOVER;
9158 eep_config->cfg_lsw =
9159 AscGetChipCfgLsw(iop_base);
9160 }
9161 if (eep_config->cfg_msw != cfg_msw) {
9162 warn_code |= ASC_WARN_EEPROM_RECOVER;
9163 eep_config->cfg_msw =
9164 AscGetChipCfgMsw(iop_base);
9165 }
9166 }
9167 }
9168 eep_config->cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
9169 eep_config->cfg_lsw |= ASC_CFG0_HOST_INT_ON;
Matthew Wilcoxb352f922007-10-02 21:55:33 -04009170 ASC_DBG(1, "eep_config->chksum 0x%x\n", eep_config->chksum);
Matthew Wilcox51219352007-10-02 21:55:22 -04009171 if (chksum != eep_config->chksum) {
9172 if (AscGetChipVersion(iop_base, asc_dvc->bus_type) ==
9173 ASC_CHIP_VER_PCI_ULTRA_3050) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -04009174 ASC_DBG(1, "chksum error ignored; EEPROM-less board\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009175 eep_config->init_sdtr = 0xFF;
9176 eep_config->disc_enable = 0xFF;
9177 eep_config->start_motor = 0xFF;
9178 eep_config->use_cmd_qng = 0;
9179 eep_config->max_total_qng = 0xF0;
9180 eep_config->max_tag_qng = 0x20;
9181 eep_config->cntl = 0xBFFF;
9182 ASC_EEP_SET_CHIP_ID(eep_config, 7);
9183 eep_config->no_scam = 0;
9184 eep_config->adapter_info[0] = 0;
9185 eep_config->adapter_info[1] = 0;
9186 eep_config->adapter_info[2] = 0;
9187 eep_config->adapter_info[3] = 0;
9188 eep_config->adapter_info[4] = 0;
9189 /* Indicate EEPROM-less board. */
9190 eep_config->adapter_info[5] = 0xBB;
9191 } else {
9192 ASC_PRINT
9193 ("AscInitFromEEP: EEPROM checksum error; Will try to re-write EEPROM.\n");
9194 write_eep = 1;
9195 warn_code |= ASC_WARN_EEPROM_CHKSUM;
9196 }
9197 }
9198 asc_dvc->cfg->sdtr_enable = eep_config->init_sdtr;
9199 asc_dvc->cfg->disc_enable = eep_config->disc_enable;
9200 asc_dvc->cfg->cmd_qng_enabled = eep_config->use_cmd_qng;
9201 asc_dvc->cfg->isa_dma_speed = ASC_EEP_GET_DMA_SPD(eep_config);
9202 asc_dvc->start_motor = eep_config->start_motor;
9203 asc_dvc->dvc_cntl = eep_config->cntl;
9204 asc_dvc->no_scam = eep_config->no_scam;
9205 asc_dvc->cfg->adapter_info[0] = eep_config->adapter_info[0];
9206 asc_dvc->cfg->adapter_info[1] = eep_config->adapter_info[1];
9207 asc_dvc->cfg->adapter_info[2] = eep_config->adapter_info[2];
9208 asc_dvc->cfg->adapter_info[3] = eep_config->adapter_info[3];
9209 asc_dvc->cfg->adapter_info[4] = eep_config->adapter_info[4];
9210 asc_dvc->cfg->adapter_info[5] = eep_config->adapter_info[5];
9211 if (!AscTestExternalLram(asc_dvc)) {
9212 if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) ==
9213 ASC_IS_PCI_ULTRA)) {
9214 eep_config->max_total_qng =
9215 ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG;
9216 eep_config->max_tag_qng =
9217 ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG;
9218 } else {
9219 eep_config->cfg_msw |= 0x0800;
9220 cfg_msw |= 0x0800;
9221 AscSetChipCfgMsw(iop_base, cfg_msw);
9222 eep_config->max_total_qng = ASC_MAX_PCI_INRAM_TOTAL_QNG;
9223 eep_config->max_tag_qng = ASC_MAX_INRAM_TAG_QNG;
9224 }
9225 } else {
9226 }
9227 if (eep_config->max_total_qng < ASC_MIN_TOTAL_QNG) {
9228 eep_config->max_total_qng = ASC_MIN_TOTAL_QNG;
9229 }
9230 if (eep_config->max_total_qng > ASC_MAX_TOTAL_QNG) {
9231 eep_config->max_total_qng = ASC_MAX_TOTAL_QNG;
9232 }
9233 if (eep_config->max_tag_qng > eep_config->max_total_qng) {
9234 eep_config->max_tag_qng = eep_config->max_total_qng;
9235 }
9236 if (eep_config->max_tag_qng < ASC_MIN_TAG_Q_PER_DVC) {
9237 eep_config->max_tag_qng = ASC_MIN_TAG_Q_PER_DVC;
9238 }
9239 asc_dvc->max_total_qng = eep_config->max_total_qng;
9240 if ((eep_config->use_cmd_qng & eep_config->disc_enable) !=
9241 eep_config->use_cmd_qng) {
9242 eep_config->disc_enable = eep_config->use_cmd_qng;
9243 warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
9244 }
Matthew Wilcox51219352007-10-02 21:55:22 -04009245 ASC_EEP_SET_CHIP_ID(eep_config,
9246 ASC_EEP_GET_CHIP_ID(eep_config) & ASC_MAX_TID);
9247 asc_dvc->cfg->chip_scsi_id = ASC_EEP_GET_CHIP_ID(eep_config);
9248 if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) &&
9249 !(asc_dvc->dvc_cntl & ASC_CNTL_SDTR_ENABLE_ULTRA)) {
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04009250 asc_dvc->min_sdtr_index = ASC_SDTR_ULTRA_PCI_10MB_INDEX;
Matthew Wilcox51219352007-10-02 21:55:22 -04009251 }
9252
9253 for (i = 0; i <= ASC_MAX_TID; i++) {
9254 asc_dvc->dos_int13_table[i] = eep_config->dos_int13_table[i];
9255 asc_dvc->cfg->max_tag_qng[i] = eep_config->max_tag_qng;
9256 asc_dvc->cfg->sdtr_period_offset[i] =
9257 (uchar)(ASC_DEF_SDTR_OFFSET |
Matthew Wilcoxafbb68c2007-10-02 21:55:36 -04009258 (asc_dvc->min_sdtr_index << 4));
Matthew Wilcox51219352007-10-02 21:55:22 -04009259 }
9260 eep_config->cfg_msw = AscGetChipCfgMsw(iop_base);
9261 if (write_eep) {
9262 if ((i = AscSetEEPConfig(iop_base, eep_config,
9263 asc_dvc->bus_type)) != 0) {
9264 ASC_PRINT1
9265 ("AscInitFromEEP: Failed to re-write EEPROM with %d errors.\n",
9266 i);
9267 } else {
9268 ASC_PRINT
9269 ("AscInitFromEEP: Successfully re-wrote EEPROM.\n");
9270 }
9271 }
9272 return (warn_code);
9273}
9274
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009275static int AscInitGetConfig(struct Scsi_Host *shost)
Matthew Wilcox51219352007-10-02 21:55:22 -04009276{
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009277 struct asc_board *board = shost_priv(shost);
9278 ASC_DVC_VAR *asc_dvc = &board->dvc_var.asc_dvc_var;
Matthew Wilcox51219352007-10-02 21:55:22 -04009279 unsigned short warn_code = 0;
9280
9281 asc_dvc->init_state = ASC_INIT_STATE_BEG_GET_CFG;
9282 if (asc_dvc->err_code != 0)
9283 return asc_dvc->err_code;
9284
9285 if (AscFindSignature(asc_dvc->iop_base)) {
Hannes Reineckef33134e2015-04-24 13:18:31 +02009286 AscInitAscDvcVar(asc_dvc);
9287 warn_code = AscInitFromEEP(asc_dvc);
Matthew Wilcox51219352007-10-02 21:55:22 -04009288 asc_dvc->init_state |= ASC_INIT_STATE_END_GET_CFG;
9289 if (asc_dvc->scsi_reset_wait > ASC_MAX_SCSI_RESET_WAIT)
9290 asc_dvc->scsi_reset_wait = ASC_MAX_SCSI_RESET_WAIT;
9291 } else {
9292 asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
9293 }
9294
9295 switch (warn_code) {
9296 case 0: /* No error */
9297 break;
9298 case ASC_WARN_IO_PORT_ROTATE:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009299 shost_printk(KERN_WARNING, shost, "I/O port address "
9300 "modified\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009301 break;
9302 case ASC_WARN_AUTO_CONFIG:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009303 shost_printk(KERN_WARNING, shost, "I/O port increment switch "
9304 "enabled\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009305 break;
9306 case ASC_WARN_EEPROM_CHKSUM:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009307 shost_printk(KERN_WARNING, shost, "EEPROM checksum error\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009308 break;
9309 case ASC_WARN_IRQ_MODIFIED:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009310 shost_printk(KERN_WARNING, shost, "IRQ modified\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009311 break;
9312 case ASC_WARN_CMD_QNG_CONFLICT:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009313 shost_printk(KERN_WARNING, shost, "tag queuing enabled w/o "
9314 "disconnects\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009315 break;
9316 default:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009317 shost_printk(KERN_WARNING, shost, "unknown warning: 0x%x\n",
9318 warn_code);
Matthew Wilcox51219352007-10-02 21:55:22 -04009319 break;
9320 }
9321
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009322 if (asc_dvc->err_code != 0)
9323 shost_printk(KERN_ERR, shost, "error 0x%x at init_state "
9324 "0x%x\n", asc_dvc->err_code, asc_dvc->init_state);
Matthew Wilcox51219352007-10-02 21:55:22 -04009325
9326 return asc_dvc->err_code;
9327}
9328
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009329static int AscInitSetConfig(struct pci_dev *pdev, struct Scsi_Host *shost)
Matthew Wilcox51219352007-10-02 21:55:22 -04009330{
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009331 struct asc_board *board = shost_priv(shost);
9332 ASC_DVC_VAR *asc_dvc = &board->dvc_var.asc_dvc_var;
Matthew Wilcox51219352007-10-02 21:55:22 -04009333 PortAddr iop_base = asc_dvc->iop_base;
9334 unsigned short cfg_msw;
9335 unsigned short warn_code = 0;
9336
9337 asc_dvc->init_state |= ASC_INIT_STATE_BEG_SET_CFG;
9338 if (asc_dvc->err_code != 0)
9339 return asc_dvc->err_code;
9340 if (!AscFindSignature(asc_dvc->iop_base)) {
9341 asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
9342 return asc_dvc->err_code;
9343 }
9344
9345 cfg_msw = AscGetChipCfgMsw(iop_base);
9346 if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
9347 cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
9348 warn_code |= ASC_WARN_CFG_MSW_RECOVER;
9349 AscSetChipCfgMsw(iop_base, cfg_msw);
9350 }
9351 if ((asc_dvc->cfg->cmd_qng_enabled & asc_dvc->cfg->disc_enable) !=
9352 asc_dvc->cfg->cmd_qng_enabled) {
9353 asc_dvc->cfg->disc_enable = asc_dvc->cfg->cmd_qng_enabled;
9354 warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
9355 }
9356 if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
9357 warn_code |= ASC_WARN_AUTO_CONFIG;
9358 }
Matthew Wilcox51219352007-10-02 21:55:22 -04009359#ifdef CONFIG_PCI
9360 if (asc_dvc->bus_type & ASC_IS_PCI) {
9361 cfg_msw &= 0xFFC0;
9362 AscSetChipCfgMsw(iop_base, cfg_msw);
9363 if ((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) {
9364 } else {
9365 if ((pdev->device == PCI_DEVICE_ID_ASP_1200A) ||
9366 (pdev->device == PCI_DEVICE_ID_ASP_ABP940)) {
9367 asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_IF_NOT_DWB;
9368 asc_dvc->bug_fix_cntl |=
9369 ASC_BUG_FIX_ASYN_USE_SYN;
9370 }
9371 }
9372 } else
9373#endif /* CONFIG_PCI */
9374 if (asc_dvc->bus_type == ASC_IS_ISAPNP) {
9375 if (AscGetChipVersion(iop_base, asc_dvc->bus_type)
9376 == ASC_CHIP_VER_ASYN_BUG) {
9377 asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_ASYN_USE_SYN;
9378 }
9379 }
9380 if (AscSetChipScsiID(iop_base, asc_dvc->cfg->chip_scsi_id) !=
9381 asc_dvc->cfg->chip_scsi_id) {
9382 asc_dvc->err_code |= ASC_IERR_SET_SCSI_ID;
9383 }
9384#ifdef CONFIG_ISA
9385 if (asc_dvc->bus_type & ASC_IS_ISA) {
9386 AscSetIsaDmaChannel(iop_base, asc_dvc->cfg->isa_dma_channel);
9387 AscSetIsaDmaSpeed(iop_base, asc_dvc->cfg->isa_dma_speed);
9388 }
9389#endif /* CONFIG_ISA */
9390
9391 asc_dvc->init_state |= ASC_INIT_STATE_END_SET_CFG;
9392
9393 switch (warn_code) {
9394 case 0: /* No error. */
9395 break;
9396 case ASC_WARN_IO_PORT_ROTATE:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009397 shost_printk(KERN_WARNING, shost, "I/O port address "
9398 "modified\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009399 break;
9400 case ASC_WARN_AUTO_CONFIG:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009401 shost_printk(KERN_WARNING, shost, "I/O port increment switch "
9402 "enabled\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009403 break;
9404 case ASC_WARN_EEPROM_CHKSUM:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009405 shost_printk(KERN_WARNING, shost, "EEPROM checksum error\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009406 break;
9407 case ASC_WARN_IRQ_MODIFIED:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009408 shost_printk(KERN_WARNING, shost, "IRQ modified\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009409 break;
9410 case ASC_WARN_CMD_QNG_CONFLICT:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009411 shost_printk(KERN_WARNING, shost, "tag queuing w/o "
9412 "disconnects\n");
Matthew Wilcox51219352007-10-02 21:55:22 -04009413 break;
9414 default:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009415 shost_printk(KERN_WARNING, shost, "unknown warning: 0x%x\n",
9416 warn_code);
Matthew Wilcox51219352007-10-02 21:55:22 -04009417 break;
9418 }
9419
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -04009420 if (asc_dvc->err_code != 0)
9421 shost_printk(KERN_ERR, shost, "error 0x%x at init_state "
9422 "0x%x\n", asc_dvc->err_code, asc_dvc->init_state);
Matthew Wilcox51219352007-10-02 21:55:22 -04009423
9424 return asc_dvc->err_code;
9425}
9426
9427/*
9428 * EEPROM Configuration.
9429 *
9430 * All drivers should use this structure to set the default EEPROM
9431 * configuration. The BIOS now uses this structure when it is built.
9432 * Additional structure information can be found in a_condor.h where
9433 * the structure is defined.
9434 *
9435 * The *_Field_IsChar structs are needed to correct for endianness.
9436 * These values are read from the board 16 bits at a time directly
9437 * into the structs. Because some fields are char, the values will be
9438 * in the wrong order. The *_Field_IsChar tells when to flip the
9439 * bytes. Data read and written to PCI memory is automatically swapped
9440 * on big-endian platforms so char fields read as words are actually being
9441 * unswapped on big-endian platforms.
9442 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009443static ADVEEP_3550_CONFIG Default_3550_EEPROM_Config = {
Matthew Wilcox51219352007-10-02 21:55:22 -04009444 ADV_EEPROM_BIOS_ENABLE, /* cfg_lsw */
9445 0x0000, /* cfg_msw */
9446 0xFFFF, /* disc_enable */
9447 0xFFFF, /* wdtr_able */
9448 0xFFFF, /* sdtr_able */
9449 0xFFFF, /* start_motor */
9450 0xFFFF, /* tagqng_able */
9451 0xFFFF, /* bios_scan */
9452 0, /* scam_tolerant */
9453 7, /* adapter_scsi_id */
9454 0, /* bios_boot_delay */
9455 3, /* scsi_reset_delay */
9456 0, /* bios_id_lun */
9457 0, /* termination */
9458 0, /* reserved1 */
9459 0xFFE7, /* bios_ctrl */
9460 0xFFFF, /* ultra_able */
9461 0, /* reserved2 */
9462 ASC_DEF_MAX_HOST_QNG, /* max_host_qng */
9463 ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
9464 0, /* dvc_cntl */
9465 0, /* bug_fix */
9466 0, /* serial_number_word1 */
9467 0, /* serial_number_word2 */
9468 0, /* serial_number_word3 */
9469 0, /* check_sum */
9470 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
9471 , /* oem_name[16] */
9472 0, /* dvc_err_code */
9473 0, /* adv_err_code */
9474 0, /* adv_err_addr */
9475 0, /* saved_dvc_err_code */
9476 0, /* saved_adv_err_code */
9477 0, /* saved_adv_err_addr */
9478 0 /* num_of_err */
9479};
9480
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009481static ADVEEP_3550_CONFIG ADVEEP_3550_Config_Field_IsChar = {
Matthew Wilcox51219352007-10-02 21:55:22 -04009482 0, /* cfg_lsw */
9483 0, /* cfg_msw */
9484 0, /* -disc_enable */
9485 0, /* wdtr_able */
9486 0, /* sdtr_able */
9487 0, /* start_motor */
9488 0, /* tagqng_able */
9489 0, /* bios_scan */
9490 0, /* scam_tolerant */
9491 1, /* adapter_scsi_id */
9492 1, /* bios_boot_delay */
9493 1, /* scsi_reset_delay */
9494 1, /* bios_id_lun */
9495 1, /* termination */
9496 1, /* reserved1 */
9497 0, /* bios_ctrl */
9498 0, /* ultra_able */
9499 0, /* reserved2 */
9500 1, /* max_host_qng */
9501 1, /* max_dvc_qng */
9502 0, /* dvc_cntl */
9503 0, /* bug_fix */
9504 0, /* serial_number_word1 */
9505 0, /* serial_number_word2 */
9506 0, /* serial_number_word3 */
9507 0, /* check_sum */
9508 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
9509 , /* oem_name[16] */
9510 0, /* dvc_err_code */
9511 0, /* adv_err_code */
9512 0, /* adv_err_addr */
9513 0, /* saved_dvc_err_code */
9514 0, /* saved_adv_err_code */
9515 0, /* saved_adv_err_addr */
9516 0 /* num_of_err */
9517};
9518
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009519static ADVEEP_38C0800_CONFIG Default_38C0800_EEPROM_Config = {
Matthew Wilcox51219352007-10-02 21:55:22 -04009520 ADV_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */
9521 0x0000, /* 01 cfg_msw */
9522 0xFFFF, /* 02 disc_enable */
9523 0xFFFF, /* 03 wdtr_able */
9524 0x4444, /* 04 sdtr_speed1 */
9525 0xFFFF, /* 05 start_motor */
9526 0xFFFF, /* 06 tagqng_able */
9527 0xFFFF, /* 07 bios_scan */
9528 0, /* 08 scam_tolerant */
9529 7, /* 09 adapter_scsi_id */
9530 0, /* bios_boot_delay */
9531 3, /* 10 scsi_reset_delay */
9532 0, /* bios_id_lun */
9533 0, /* 11 termination_se */
9534 0, /* termination_lvd */
9535 0xFFE7, /* 12 bios_ctrl */
9536 0x4444, /* 13 sdtr_speed2 */
9537 0x4444, /* 14 sdtr_speed3 */
9538 ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
9539 ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
9540 0, /* 16 dvc_cntl */
9541 0x4444, /* 17 sdtr_speed4 */
9542 0, /* 18 serial_number_word1 */
9543 0, /* 19 serial_number_word2 */
9544 0, /* 20 serial_number_word3 */
9545 0, /* 21 check_sum */
9546 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
9547 , /* 22-29 oem_name[16] */
9548 0, /* 30 dvc_err_code */
9549 0, /* 31 adv_err_code */
9550 0, /* 32 adv_err_addr */
9551 0, /* 33 saved_dvc_err_code */
9552 0, /* 34 saved_adv_err_code */
9553 0, /* 35 saved_adv_err_addr */
9554 0, /* 36 reserved */
9555 0, /* 37 reserved */
9556 0, /* 38 reserved */
9557 0, /* 39 reserved */
9558 0, /* 40 reserved */
9559 0, /* 41 reserved */
9560 0, /* 42 reserved */
9561 0, /* 43 reserved */
9562 0, /* 44 reserved */
9563 0, /* 45 reserved */
9564 0, /* 46 reserved */
9565 0, /* 47 reserved */
9566 0, /* 48 reserved */
9567 0, /* 49 reserved */
9568 0, /* 50 reserved */
9569 0, /* 51 reserved */
9570 0, /* 52 reserved */
9571 0, /* 53 reserved */
9572 0, /* 54 reserved */
9573 0, /* 55 reserved */
9574 0, /* 56 cisptr_lsw */
9575 0, /* 57 cisprt_msw */
9576 PCI_VENDOR_ID_ASP, /* 58 subsysvid */
9577 PCI_DEVICE_ID_38C0800_REV1, /* 59 subsysid */
9578 0, /* 60 reserved */
9579 0, /* 61 reserved */
9580 0, /* 62 reserved */
9581 0 /* 63 reserved */
9582};
9583
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009584static ADVEEP_38C0800_CONFIG ADVEEP_38C0800_Config_Field_IsChar = {
Matthew Wilcox51219352007-10-02 21:55:22 -04009585 0, /* 00 cfg_lsw */
9586 0, /* 01 cfg_msw */
9587 0, /* 02 disc_enable */
9588 0, /* 03 wdtr_able */
9589 0, /* 04 sdtr_speed1 */
9590 0, /* 05 start_motor */
9591 0, /* 06 tagqng_able */
9592 0, /* 07 bios_scan */
9593 0, /* 08 scam_tolerant */
9594 1, /* 09 adapter_scsi_id */
9595 1, /* bios_boot_delay */
9596 1, /* 10 scsi_reset_delay */
9597 1, /* bios_id_lun */
9598 1, /* 11 termination_se */
9599 1, /* termination_lvd */
9600 0, /* 12 bios_ctrl */
9601 0, /* 13 sdtr_speed2 */
9602 0, /* 14 sdtr_speed3 */
9603 1, /* 15 max_host_qng */
9604 1, /* max_dvc_qng */
9605 0, /* 16 dvc_cntl */
9606 0, /* 17 sdtr_speed4 */
9607 0, /* 18 serial_number_word1 */
9608 0, /* 19 serial_number_word2 */
9609 0, /* 20 serial_number_word3 */
9610 0, /* 21 check_sum */
9611 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
9612 , /* 22-29 oem_name[16] */
9613 0, /* 30 dvc_err_code */
9614 0, /* 31 adv_err_code */
9615 0, /* 32 adv_err_addr */
9616 0, /* 33 saved_dvc_err_code */
9617 0, /* 34 saved_adv_err_code */
9618 0, /* 35 saved_adv_err_addr */
9619 0, /* 36 reserved */
9620 0, /* 37 reserved */
9621 0, /* 38 reserved */
9622 0, /* 39 reserved */
9623 0, /* 40 reserved */
9624 0, /* 41 reserved */
9625 0, /* 42 reserved */
9626 0, /* 43 reserved */
9627 0, /* 44 reserved */
9628 0, /* 45 reserved */
9629 0, /* 46 reserved */
9630 0, /* 47 reserved */
9631 0, /* 48 reserved */
9632 0, /* 49 reserved */
9633 0, /* 50 reserved */
9634 0, /* 51 reserved */
9635 0, /* 52 reserved */
9636 0, /* 53 reserved */
9637 0, /* 54 reserved */
9638 0, /* 55 reserved */
9639 0, /* 56 cisptr_lsw */
9640 0, /* 57 cisprt_msw */
9641 0, /* 58 subsysvid */
9642 0, /* 59 subsysid */
9643 0, /* 60 reserved */
9644 0, /* 61 reserved */
9645 0, /* 62 reserved */
9646 0 /* 63 reserved */
9647};
9648
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009649static ADVEEP_38C1600_CONFIG Default_38C1600_EEPROM_Config = {
Matthew Wilcox51219352007-10-02 21:55:22 -04009650 ADV_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */
9651 0x0000, /* 01 cfg_msw */
9652 0xFFFF, /* 02 disc_enable */
9653 0xFFFF, /* 03 wdtr_able */
9654 0x5555, /* 04 sdtr_speed1 */
9655 0xFFFF, /* 05 start_motor */
9656 0xFFFF, /* 06 tagqng_able */
9657 0xFFFF, /* 07 bios_scan */
9658 0, /* 08 scam_tolerant */
9659 7, /* 09 adapter_scsi_id */
9660 0, /* bios_boot_delay */
9661 3, /* 10 scsi_reset_delay */
9662 0, /* bios_id_lun */
9663 0, /* 11 termination_se */
9664 0, /* termination_lvd */
9665 0xFFE7, /* 12 bios_ctrl */
9666 0x5555, /* 13 sdtr_speed2 */
9667 0x5555, /* 14 sdtr_speed3 */
9668 ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
9669 ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
9670 0, /* 16 dvc_cntl */
9671 0x5555, /* 17 sdtr_speed4 */
9672 0, /* 18 serial_number_word1 */
9673 0, /* 19 serial_number_word2 */
9674 0, /* 20 serial_number_word3 */
9675 0, /* 21 check_sum */
9676 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
9677 , /* 22-29 oem_name[16] */
9678 0, /* 30 dvc_err_code */
9679 0, /* 31 adv_err_code */
9680 0, /* 32 adv_err_addr */
9681 0, /* 33 saved_dvc_err_code */
9682 0, /* 34 saved_adv_err_code */
9683 0, /* 35 saved_adv_err_addr */
9684 0, /* 36 reserved */
9685 0, /* 37 reserved */
9686 0, /* 38 reserved */
9687 0, /* 39 reserved */
9688 0, /* 40 reserved */
9689 0, /* 41 reserved */
9690 0, /* 42 reserved */
9691 0, /* 43 reserved */
9692 0, /* 44 reserved */
9693 0, /* 45 reserved */
9694 0, /* 46 reserved */
9695 0, /* 47 reserved */
9696 0, /* 48 reserved */
9697 0, /* 49 reserved */
9698 0, /* 50 reserved */
9699 0, /* 51 reserved */
9700 0, /* 52 reserved */
9701 0, /* 53 reserved */
9702 0, /* 54 reserved */
9703 0, /* 55 reserved */
9704 0, /* 56 cisptr_lsw */
9705 0, /* 57 cisprt_msw */
9706 PCI_VENDOR_ID_ASP, /* 58 subsysvid */
9707 PCI_DEVICE_ID_38C1600_REV1, /* 59 subsysid */
9708 0, /* 60 reserved */
9709 0, /* 61 reserved */
9710 0, /* 62 reserved */
9711 0 /* 63 reserved */
9712};
9713
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009714static ADVEEP_38C1600_CONFIG ADVEEP_38C1600_Config_Field_IsChar = {
Matthew Wilcox51219352007-10-02 21:55:22 -04009715 0, /* 00 cfg_lsw */
9716 0, /* 01 cfg_msw */
9717 0, /* 02 disc_enable */
9718 0, /* 03 wdtr_able */
9719 0, /* 04 sdtr_speed1 */
9720 0, /* 05 start_motor */
9721 0, /* 06 tagqng_able */
9722 0, /* 07 bios_scan */
9723 0, /* 08 scam_tolerant */
9724 1, /* 09 adapter_scsi_id */
9725 1, /* bios_boot_delay */
9726 1, /* 10 scsi_reset_delay */
9727 1, /* bios_id_lun */
9728 1, /* 11 termination_se */
9729 1, /* termination_lvd */
9730 0, /* 12 bios_ctrl */
9731 0, /* 13 sdtr_speed2 */
9732 0, /* 14 sdtr_speed3 */
9733 1, /* 15 max_host_qng */
9734 1, /* max_dvc_qng */
9735 0, /* 16 dvc_cntl */
9736 0, /* 17 sdtr_speed4 */
9737 0, /* 18 serial_number_word1 */
9738 0, /* 19 serial_number_word2 */
9739 0, /* 20 serial_number_word3 */
9740 0, /* 21 check_sum */
9741 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
9742 , /* 22-29 oem_name[16] */
9743 0, /* 30 dvc_err_code */
9744 0, /* 31 adv_err_code */
9745 0, /* 32 adv_err_addr */
9746 0, /* 33 saved_dvc_err_code */
9747 0, /* 34 saved_adv_err_code */
9748 0, /* 35 saved_adv_err_addr */
9749 0, /* 36 reserved */
9750 0, /* 37 reserved */
9751 0, /* 38 reserved */
9752 0, /* 39 reserved */
9753 0, /* 40 reserved */
9754 0, /* 41 reserved */
9755 0, /* 42 reserved */
9756 0, /* 43 reserved */
9757 0, /* 44 reserved */
9758 0, /* 45 reserved */
9759 0, /* 46 reserved */
9760 0, /* 47 reserved */
9761 0, /* 48 reserved */
9762 0, /* 49 reserved */
9763 0, /* 50 reserved */
9764 0, /* 51 reserved */
9765 0, /* 52 reserved */
9766 0, /* 53 reserved */
9767 0, /* 54 reserved */
9768 0, /* 55 reserved */
9769 0, /* 56 cisptr_lsw */
9770 0, /* 57 cisprt_msw */
9771 0, /* 58 subsysvid */
9772 0, /* 59 subsysid */
9773 0, /* 60 reserved */
9774 0, /* 61 reserved */
9775 0, /* 62 reserved */
9776 0 /* 63 reserved */
9777};
9778
9779#ifdef CONFIG_PCI
9780/*
9781 * Wait for EEPROM command to complete
9782 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009783static void AdvWaitEEPCmd(AdvPortAddr iop_base)
Matthew Wilcox51219352007-10-02 21:55:22 -04009784{
9785 int eep_delay_ms;
9786
9787 for (eep_delay_ms = 0; eep_delay_ms < ADV_EEP_DELAY_MS; eep_delay_ms++) {
9788 if (AdvReadWordRegister(iop_base, IOPW_EE_CMD) &
9789 ASC_EEP_CMD_DONE) {
9790 break;
9791 }
9792 mdelay(1);
9793 }
9794 if ((AdvReadWordRegister(iop_base, IOPW_EE_CMD) & ASC_EEP_CMD_DONE) ==
9795 0)
9796 BUG();
9797}
9798
9799/*
9800 * Read the EEPROM from specified location
9801 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009802static ushort AdvReadEEPWord(AdvPortAddr iop_base, int eep_word_addr)
Matthew Wilcox51219352007-10-02 21:55:22 -04009803{
9804 AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
9805 ASC_EEP_CMD_READ | eep_word_addr);
9806 AdvWaitEEPCmd(iop_base);
9807 return AdvReadWordRegister(iop_base, IOPW_EE_DATA);
9808}
9809
9810/*
9811 * Write the EEPROM from 'cfg_buf'.
9812 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009813static void AdvSet3550EEPConfig(AdvPortAddr iop_base,
9814 ADVEEP_3550_CONFIG *cfg_buf)
Matthew Wilcox51219352007-10-02 21:55:22 -04009815{
9816 ushort *wbuf;
9817 ushort addr, chksum;
9818 ushort *charfields;
9819
9820 wbuf = (ushort *)cfg_buf;
9821 charfields = (ushort *)&ADVEEP_3550_Config_Field_IsChar;
9822 chksum = 0;
9823
9824 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
9825 AdvWaitEEPCmd(iop_base);
9826
9827 /*
9828 * Write EEPROM from word 0 to word 20.
9829 */
9830 for (addr = ADV_EEP_DVC_CFG_BEGIN;
9831 addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
9832 ushort word;
9833
9834 if (*charfields++) {
9835 word = cpu_to_le16(*wbuf);
9836 } else {
9837 word = *wbuf;
9838 }
9839 chksum += *wbuf; /* Checksum is calculated from word values. */
9840 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
9841 AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
9842 ASC_EEP_CMD_WRITE | addr);
9843 AdvWaitEEPCmd(iop_base);
9844 mdelay(ADV_EEP_DELAY_MS);
9845 }
9846
9847 /*
9848 * Write EEPROM checksum at word 21.
9849 */
9850 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
9851 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
9852 AdvWaitEEPCmd(iop_base);
9853 wbuf++;
9854 charfields++;
9855
9856 /*
9857 * Write EEPROM OEM name at words 22 to 29.
9858 */
9859 for (addr = ADV_EEP_DVC_CTL_BEGIN;
9860 addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
9861 ushort word;
9862
9863 if (*charfields++) {
9864 word = cpu_to_le16(*wbuf);
9865 } else {
9866 word = *wbuf;
9867 }
9868 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
9869 AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
9870 ASC_EEP_CMD_WRITE | addr);
9871 AdvWaitEEPCmd(iop_base);
9872 }
9873 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
9874 AdvWaitEEPCmd(iop_base);
9875}
9876
9877/*
9878 * Write the EEPROM from 'cfg_buf'.
9879 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009880static void AdvSet38C0800EEPConfig(AdvPortAddr iop_base,
9881 ADVEEP_38C0800_CONFIG *cfg_buf)
Matthew Wilcox51219352007-10-02 21:55:22 -04009882{
9883 ushort *wbuf;
9884 ushort *charfields;
9885 ushort addr, chksum;
9886
9887 wbuf = (ushort *)cfg_buf;
9888 charfields = (ushort *)&ADVEEP_38C0800_Config_Field_IsChar;
9889 chksum = 0;
9890
9891 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
9892 AdvWaitEEPCmd(iop_base);
9893
9894 /*
9895 * Write EEPROM from word 0 to word 20.
9896 */
9897 for (addr = ADV_EEP_DVC_CFG_BEGIN;
9898 addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
9899 ushort word;
9900
9901 if (*charfields++) {
9902 word = cpu_to_le16(*wbuf);
9903 } else {
9904 word = *wbuf;
9905 }
9906 chksum += *wbuf; /* Checksum is calculated from word values. */
9907 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
9908 AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
9909 ASC_EEP_CMD_WRITE | addr);
9910 AdvWaitEEPCmd(iop_base);
9911 mdelay(ADV_EEP_DELAY_MS);
9912 }
9913
9914 /*
9915 * Write EEPROM checksum at word 21.
9916 */
9917 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
9918 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
9919 AdvWaitEEPCmd(iop_base);
9920 wbuf++;
9921 charfields++;
9922
9923 /*
9924 * Write EEPROM OEM name at words 22 to 29.
9925 */
9926 for (addr = ADV_EEP_DVC_CTL_BEGIN;
9927 addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
9928 ushort word;
9929
9930 if (*charfields++) {
9931 word = cpu_to_le16(*wbuf);
9932 } else {
9933 word = *wbuf;
9934 }
9935 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
9936 AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
9937 ASC_EEP_CMD_WRITE | addr);
9938 AdvWaitEEPCmd(iop_base);
9939 }
9940 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
9941 AdvWaitEEPCmd(iop_base);
9942}
9943
9944/*
9945 * Write the EEPROM from 'cfg_buf'.
9946 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009947static void AdvSet38C1600EEPConfig(AdvPortAddr iop_base,
9948 ADVEEP_38C1600_CONFIG *cfg_buf)
Matthew Wilcox51219352007-10-02 21:55:22 -04009949{
9950 ushort *wbuf;
9951 ushort *charfields;
9952 ushort addr, chksum;
9953
9954 wbuf = (ushort *)cfg_buf;
9955 charfields = (ushort *)&ADVEEP_38C1600_Config_Field_IsChar;
9956 chksum = 0;
9957
9958 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
9959 AdvWaitEEPCmd(iop_base);
9960
9961 /*
9962 * Write EEPROM from word 0 to word 20.
9963 */
9964 for (addr = ADV_EEP_DVC_CFG_BEGIN;
9965 addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
9966 ushort word;
9967
9968 if (*charfields++) {
9969 word = cpu_to_le16(*wbuf);
9970 } else {
9971 word = *wbuf;
9972 }
9973 chksum += *wbuf; /* Checksum is calculated from word values. */
9974 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
9975 AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
9976 ASC_EEP_CMD_WRITE | addr);
9977 AdvWaitEEPCmd(iop_base);
9978 mdelay(ADV_EEP_DELAY_MS);
9979 }
9980
9981 /*
9982 * Write EEPROM checksum at word 21.
9983 */
9984 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
9985 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
9986 AdvWaitEEPCmd(iop_base);
9987 wbuf++;
9988 charfields++;
9989
9990 /*
9991 * Write EEPROM OEM name at words 22 to 29.
9992 */
9993 for (addr = ADV_EEP_DVC_CTL_BEGIN;
9994 addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
9995 ushort word;
9996
9997 if (*charfields++) {
9998 word = cpu_to_le16(*wbuf);
9999 } else {
10000 word = *wbuf;
10001 }
10002 AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
10003 AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
10004 ASC_EEP_CMD_WRITE | addr);
10005 AdvWaitEEPCmd(iop_base);
10006 }
10007 AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
10008 AdvWaitEEPCmd(iop_base);
10009}
10010
10011/*
10012 * Read EEPROM configuration into the specified buffer.
10013 *
10014 * Return a checksum based on the EEPROM configuration read.
10015 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010016static ushort AdvGet3550EEPConfig(AdvPortAddr iop_base,
10017 ADVEEP_3550_CONFIG *cfg_buf)
Matthew Wilcox51219352007-10-02 21:55:22 -040010018{
10019 ushort wval, chksum;
10020 ushort *wbuf;
10021 int eep_addr;
10022 ushort *charfields;
10023
10024 charfields = (ushort *)&ADVEEP_3550_Config_Field_IsChar;
10025 wbuf = (ushort *)cfg_buf;
10026 chksum = 0;
10027
10028 for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
10029 eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
10030 wval = AdvReadEEPWord(iop_base, eep_addr);
10031 chksum += wval; /* Checksum is calculated from word values. */
10032 if (*charfields++) {
10033 *wbuf = le16_to_cpu(wval);
10034 } else {
10035 *wbuf = wval;
10036 }
10037 }
10038 /* Read checksum word. */
10039 *wbuf = AdvReadEEPWord(iop_base, eep_addr);
10040 wbuf++;
10041 charfields++;
10042
10043 /* Read rest of EEPROM not covered by the checksum. */
10044 for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
10045 eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
10046 *wbuf = AdvReadEEPWord(iop_base, eep_addr);
10047 if (*charfields++) {
10048 *wbuf = le16_to_cpu(*wbuf);
10049 }
10050 }
10051 return chksum;
10052}
10053
10054/*
10055 * Read EEPROM configuration into the specified buffer.
10056 *
10057 * Return a checksum based on the EEPROM configuration read.
10058 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010059static ushort AdvGet38C0800EEPConfig(AdvPortAddr iop_base,
10060 ADVEEP_38C0800_CONFIG *cfg_buf)
Matthew Wilcox51219352007-10-02 21:55:22 -040010061{
10062 ushort wval, chksum;
10063 ushort *wbuf;
10064 int eep_addr;
10065 ushort *charfields;
10066
10067 charfields = (ushort *)&ADVEEP_38C0800_Config_Field_IsChar;
10068 wbuf = (ushort *)cfg_buf;
10069 chksum = 0;
10070
10071 for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
10072 eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
10073 wval = AdvReadEEPWord(iop_base, eep_addr);
10074 chksum += wval; /* Checksum is calculated from word values. */
10075 if (*charfields++) {
10076 *wbuf = le16_to_cpu(wval);
10077 } else {
10078 *wbuf = wval;
10079 }
10080 }
10081 /* Read checksum word. */
10082 *wbuf = AdvReadEEPWord(iop_base, eep_addr);
10083 wbuf++;
10084 charfields++;
10085
10086 /* Read rest of EEPROM not covered by the checksum. */
10087 for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
10088 eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
10089 *wbuf = AdvReadEEPWord(iop_base, eep_addr);
10090 if (*charfields++) {
10091 *wbuf = le16_to_cpu(*wbuf);
10092 }
10093 }
10094 return chksum;
10095}
10096
10097/*
10098 * Read EEPROM configuration into the specified buffer.
10099 *
10100 * Return a checksum based on the EEPROM configuration read.
10101 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010102static ushort AdvGet38C1600EEPConfig(AdvPortAddr iop_base,
10103 ADVEEP_38C1600_CONFIG *cfg_buf)
Matthew Wilcox51219352007-10-02 21:55:22 -040010104{
10105 ushort wval, chksum;
10106 ushort *wbuf;
10107 int eep_addr;
10108 ushort *charfields;
10109
10110 charfields = (ushort *)&ADVEEP_38C1600_Config_Field_IsChar;
10111 wbuf = (ushort *)cfg_buf;
10112 chksum = 0;
10113
10114 for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
10115 eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
10116 wval = AdvReadEEPWord(iop_base, eep_addr);
10117 chksum += wval; /* Checksum is calculated from word values. */
10118 if (*charfields++) {
10119 *wbuf = le16_to_cpu(wval);
10120 } else {
10121 *wbuf = wval;
10122 }
10123 }
10124 /* Read checksum word. */
10125 *wbuf = AdvReadEEPWord(iop_base, eep_addr);
10126 wbuf++;
10127 charfields++;
10128
10129 /* Read rest of EEPROM not covered by the checksum. */
10130 for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
10131 eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
10132 *wbuf = AdvReadEEPWord(iop_base, eep_addr);
10133 if (*charfields++) {
10134 *wbuf = le16_to_cpu(*wbuf);
10135 }
10136 }
10137 return chksum;
10138}
10139
10140/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070010141 * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
10142 * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
10143 * all of this is done.
10144 *
10145 * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
10146 *
10147 * For a non-fatal error return a warning code. If there are no warnings
10148 * then 0 is returned.
10149 *
10150 * Note: Chip is stopped on entry.
10151 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010152static int AdvInitFrom3550EEP(ADV_DVC_VAR *asc_dvc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070010153{
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010154 AdvPortAddr iop_base;
10155 ushort warn_code;
10156 ADVEEP_3550_CONFIG eep_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010157
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010158 iop_base = asc_dvc->iop_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010159
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010160 warn_code = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010161
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010162 /*
10163 * Read the board's EEPROM configuration.
10164 *
10165 * Set default values if a bad checksum is found.
10166 */
10167 if (AdvGet3550EEPConfig(iop_base, &eep_config) != eep_config.check_sum) {
10168 warn_code |= ASC_WARN_EEPROM_CHKSUM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010169
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010170 /*
10171 * Set EEPROM default values.
10172 */
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010173 memcpy(&eep_config, &Default_3550_EEPROM_Config,
10174 sizeof(ADVEEP_3550_CONFIG));
Linus Torvalds1da177e2005-04-16 15:20:36 -070010175
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010176 /*
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010177 * Assume the 6 byte board serial number that was read from
10178 * EEPROM is correct even if the EEPROM checksum failed.
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010179 */
10180 eep_config.serial_number_word3 =
10181 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010182
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010183 eep_config.serial_number_word2 =
10184 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010185
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010186 eep_config.serial_number_word1 =
10187 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010188
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010189 AdvSet3550EEPConfig(iop_base, &eep_config);
10190 }
10191 /*
10192 * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
10193 * EEPROM configuration that was read.
10194 *
10195 * This is the mapping of EEPROM fields to Adv Library fields.
10196 */
10197 asc_dvc->wdtr_able = eep_config.wdtr_able;
10198 asc_dvc->sdtr_able = eep_config.sdtr_able;
10199 asc_dvc->ultra_able = eep_config.ultra_able;
10200 asc_dvc->tagqng_able = eep_config.tagqng_able;
10201 asc_dvc->cfg->disc_enable = eep_config.disc_enable;
10202 asc_dvc->max_host_qng = eep_config.max_host_qng;
10203 asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
10204 asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
10205 asc_dvc->start_motor = eep_config.start_motor;
10206 asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
10207 asc_dvc->bios_ctrl = eep_config.bios_ctrl;
10208 asc_dvc->no_scam = eep_config.scam_tolerant;
10209 asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
10210 asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
10211 asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010212
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010213 /*
10214 * Set the host maximum queuing (max. 253, min. 16) and the per device
10215 * maximum queuing (max. 63, min. 4).
10216 */
10217 if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
10218 eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
10219 } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
10220 /* If the value is zero, assume it is uninitialized. */
10221 if (eep_config.max_host_qng == 0) {
10222 eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
10223 } else {
10224 eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
10225 }
10226 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010227
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010228 if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
10229 eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
10230 } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
10231 /* If the value is zero, assume it is uninitialized. */
10232 if (eep_config.max_dvc_qng == 0) {
10233 eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
10234 } else {
10235 eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
10236 }
10237 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010238
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010239 /*
10240 * If 'max_dvc_qng' is greater than 'max_host_qng', then
10241 * set 'max_dvc_qng' to 'max_host_qng'.
10242 */
10243 if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
10244 eep_config.max_dvc_qng = eep_config.max_host_qng;
10245 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010246
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010247 /*
10248 * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
10249 * values based on possibly adjusted EEPROM values.
10250 */
10251 asc_dvc->max_host_qng = eep_config.max_host_qng;
10252 asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010253
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010254 /*
10255 * If the EEPROM 'termination' field is set to automatic (0), then set
10256 * the ADV_DVC_CFG 'termination' field to automatic also.
10257 *
10258 * If the termination is specified with a non-zero 'termination'
10259 * value check that a legal value is set and set the ADV_DVC_CFG
10260 * 'termination' field appropriately.
10261 */
10262 if (eep_config.termination == 0) {
10263 asc_dvc->cfg->termination = 0; /* auto termination */
10264 } else {
10265 /* Enable manual control with low off / high off. */
10266 if (eep_config.termination == 1) {
10267 asc_dvc->cfg->termination = TERM_CTL_SEL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010268
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010269 /* Enable manual control with low off / high on. */
10270 } else if (eep_config.termination == 2) {
10271 asc_dvc->cfg->termination = TERM_CTL_SEL | TERM_CTL_H;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010272
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010273 /* Enable manual control with low on / high on. */
10274 } else if (eep_config.termination == 3) {
10275 asc_dvc->cfg->termination =
10276 TERM_CTL_SEL | TERM_CTL_H | TERM_CTL_L;
10277 } else {
10278 /*
10279 * The EEPROM 'termination' field contains a bad value. Use
10280 * automatic termination instead.
10281 */
10282 asc_dvc->cfg->termination = 0;
10283 warn_code |= ASC_WARN_EEPROM_TERMINATION;
10284 }
10285 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010286
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010287 return warn_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010288}
10289
10290/*
10291 * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
10292 * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
10293 * all of this is done.
10294 *
10295 * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
10296 *
10297 * For a non-fatal error return a warning code. If there are no warnings
10298 * then 0 is returned.
10299 *
10300 * Note: Chip is stopped on entry.
10301 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010302static int AdvInitFrom38C0800EEP(ADV_DVC_VAR *asc_dvc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070010303{
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010304 AdvPortAddr iop_base;
10305 ushort warn_code;
10306 ADVEEP_38C0800_CONFIG eep_config;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010307 uchar tid, termination;
10308 ushort sdtr_speed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010309
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010310 iop_base = asc_dvc->iop_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010311
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010312 warn_code = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010313
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010314 /*
10315 * Read the board's EEPROM configuration.
10316 *
10317 * Set default values if a bad checksum is found.
10318 */
10319 if (AdvGet38C0800EEPConfig(iop_base, &eep_config) !=
10320 eep_config.check_sum) {
10321 warn_code |= ASC_WARN_EEPROM_CHKSUM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010322
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010323 /*
10324 * Set EEPROM default values.
10325 */
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010326 memcpy(&eep_config, &Default_38C0800_EEPROM_Config,
10327 sizeof(ADVEEP_38C0800_CONFIG));
Linus Torvalds1da177e2005-04-16 15:20:36 -070010328
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010329 /*
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010330 * Assume the 6 byte board serial number that was read from
10331 * EEPROM is correct even if the EEPROM checksum failed.
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010332 */
10333 eep_config.serial_number_word3 =
10334 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010335
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010336 eep_config.serial_number_word2 =
10337 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010338
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010339 eep_config.serial_number_word1 =
10340 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010341
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010342 AdvSet38C0800EEPConfig(iop_base, &eep_config);
10343 }
10344 /*
10345 * Set ADV_DVC_VAR and ADV_DVC_CFG variables from the
10346 * EEPROM configuration that was read.
10347 *
10348 * This is the mapping of EEPROM fields to Adv Library fields.
10349 */
10350 asc_dvc->wdtr_able = eep_config.wdtr_able;
10351 asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
10352 asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
10353 asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
10354 asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
10355 asc_dvc->tagqng_able = eep_config.tagqng_able;
10356 asc_dvc->cfg->disc_enable = eep_config.disc_enable;
10357 asc_dvc->max_host_qng = eep_config.max_host_qng;
10358 asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
10359 asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
10360 asc_dvc->start_motor = eep_config.start_motor;
10361 asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
10362 asc_dvc->bios_ctrl = eep_config.bios_ctrl;
10363 asc_dvc->no_scam = eep_config.scam_tolerant;
10364 asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
10365 asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
10366 asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010367
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010368 /*
10369 * For every Target ID if any of its 'sdtr_speed[1234]' bits
10370 * are set, then set an 'sdtr_able' bit for it.
10371 */
10372 asc_dvc->sdtr_able = 0;
10373 for (tid = 0; tid <= ADV_MAX_TID; tid++) {
10374 if (tid == 0) {
10375 sdtr_speed = asc_dvc->sdtr_speed1;
10376 } else if (tid == 4) {
10377 sdtr_speed = asc_dvc->sdtr_speed2;
10378 } else if (tid == 8) {
10379 sdtr_speed = asc_dvc->sdtr_speed3;
10380 } else if (tid == 12) {
10381 sdtr_speed = asc_dvc->sdtr_speed4;
10382 }
10383 if (sdtr_speed & ADV_MAX_TID) {
10384 asc_dvc->sdtr_able |= (1 << tid);
10385 }
10386 sdtr_speed >>= 4;
10387 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010388
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010389 /*
10390 * Set the host maximum queuing (max. 253, min. 16) and the per device
10391 * maximum queuing (max. 63, min. 4).
10392 */
10393 if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
10394 eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
10395 } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
10396 /* If the value is zero, assume it is uninitialized. */
10397 if (eep_config.max_host_qng == 0) {
10398 eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
10399 } else {
10400 eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
10401 }
10402 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010403
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010404 if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
10405 eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
10406 } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
10407 /* If the value is zero, assume it is uninitialized. */
10408 if (eep_config.max_dvc_qng == 0) {
10409 eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
10410 } else {
10411 eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
10412 }
10413 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010414
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010415 /*
10416 * If 'max_dvc_qng' is greater than 'max_host_qng', then
10417 * set 'max_dvc_qng' to 'max_host_qng'.
10418 */
10419 if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
10420 eep_config.max_dvc_qng = eep_config.max_host_qng;
10421 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010422
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010423 /*
10424 * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
10425 * values based on possibly adjusted EEPROM values.
10426 */
10427 asc_dvc->max_host_qng = eep_config.max_host_qng;
10428 asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010429
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010430 /*
10431 * If the EEPROM 'termination' field is set to automatic (0), then set
10432 * the ADV_DVC_CFG 'termination' field to automatic also.
10433 *
10434 * If the termination is specified with a non-zero 'termination'
10435 * value check that a legal value is set and set the ADV_DVC_CFG
10436 * 'termination' field appropriately.
10437 */
10438 if (eep_config.termination_se == 0) {
10439 termination = 0; /* auto termination for SE */
10440 } else {
10441 /* Enable manual control with low off / high off. */
10442 if (eep_config.termination_se == 1) {
10443 termination = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010444
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010445 /* Enable manual control with low off / high on. */
10446 } else if (eep_config.termination_se == 2) {
10447 termination = TERM_SE_HI;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010448
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010449 /* Enable manual control with low on / high on. */
10450 } else if (eep_config.termination_se == 3) {
10451 termination = TERM_SE;
10452 } else {
10453 /*
10454 * The EEPROM 'termination_se' field contains a bad value.
10455 * Use automatic termination instead.
10456 */
10457 termination = 0;
10458 warn_code |= ASC_WARN_EEPROM_TERMINATION;
10459 }
10460 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010461
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010462 if (eep_config.termination_lvd == 0) {
10463 asc_dvc->cfg->termination = termination; /* auto termination for LVD */
10464 } else {
10465 /* Enable manual control with low off / high off. */
10466 if (eep_config.termination_lvd == 1) {
10467 asc_dvc->cfg->termination = termination;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010468
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010469 /* Enable manual control with low off / high on. */
10470 } else if (eep_config.termination_lvd == 2) {
10471 asc_dvc->cfg->termination = termination | TERM_LVD_HI;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010472
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010473 /* Enable manual control with low on / high on. */
10474 } else if (eep_config.termination_lvd == 3) {
10475 asc_dvc->cfg->termination = termination | TERM_LVD;
10476 } else {
10477 /*
10478 * The EEPROM 'termination_lvd' field contains a bad value.
10479 * Use automatic termination instead.
10480 */
10481 asc_dvc->cfg->termination = termination;
10482 warn_code |= ASC_WARN_EEPROM_TERMINATION;
10483 }
10484 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010485
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010486 return warn_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010487}
10488
10489/*
10490 * Read the board's EEPROM configuration. Set fields in ASC_DVC_VAR and
10491 * ASC_DVC_CFG based on the EEPROM settings. The chip is stopped while
10492 * all of this is done.
10493 *
10494 * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
10495 *
10496 * For a non-fatal error return a warning code. If there are no warnings
10497 * then 0 is returned.
10498 *
10499 * Note: Chip is stopped on entry.
10500 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010501static int AdvInitFrom38C1600EEP(ADV_DVC_VAR *asc_dvc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070010502{
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010503 AdvPortAddr iop_base;
10504 ushort warn_code;
10505 ADVEEP_38C1600_CONFIG eep_config;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010506 uchar tid, termination;
10507 ushort sdtr_speed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010508
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010509 iop_base = asc_dvc->iop_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010510
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010511 warn_code = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010512
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010513 /*
10514 * Read the board's EEPROM configuration.
10515 *
10516 * Set default values if a bad checksum is found.
10517 */
10518 if (AdvGet38C1600EEPConfig(iop_base, &eep_config) !=
10519 eep_config.check_sum) {
Matthew Wilcox13ac2d92007-07-30 08:10:23 -060010520 struct pci_dev *pdev = adv_dvc_to_pdev(asc_dvc);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010521 warn_code |= ASC_WARN_EEPROM_CHKSUM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010522
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010523 /*
10524 * Set EEPROM default values.
10525 */
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010526 memcpy(&eep_config, &Default_38C1600_EEPROM_Config,
10527 sizeof(ADVEEP_38C1600_CONFIG));
Linus Torvalds1da177e2005-04-16 15:20:36 -070010528
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010529 if (PCI_FUNC(pdev->devfn) != 0) {
10530 u8 ints;
10531 /*
10532 * Disable Bit 14 (BIOS_ENABLE) to fix SPARC Ultra 60
10533 * and old Mac system booting problem. The Expansion
10534 * ROM must be disabled in Function 1 for these systems
10535 */
10536 eep_config.cfg_lsw &= ~ADV_EEPROM_BIOS_ENABLE;
10537 /*
10538 * Clear the INTAB (bit 11) if the GPIO 0 input
10539 * indicates the Function 1 interrupt line is wired
10540 * to INTB.
10541 *
10542 * Set/Clear Bit 11 (INTAB) from the GPIO bit 0 input:
10543 * 1 - Function 1 interrupt line wired to INT A.
10544 * 0 - Function 1 interrupt line wired to INT B.
10545 *
10546 * Note: Function 0 is always wired to INTA.
10547 * Put all 5 GPIO bits in input mode and then read
10548 * their input values.
10549 */
10550 AdvWriteByteRegister(iop_base, IOPB_GPIO_CNTL, 0);
10551 ints = AdvReadByteRegister(iop_base, IOPB_GPIO_DATA);
10552 if ((ints & 0x01) == 0)
10553 eep_config.cfg_lsw &= ~ADV_EEPROM_INTAB;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010554 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010555
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010556 /*
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010557 * Assume the 6 byte board serial number that was read from
10558 * EEPROM is correct even if the EEPROM checksum failed.
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010559 */
10560 eep_config.serial_number_word3 =
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010561 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010562 eep_config.serial_number_word2 =
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010563 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010564 eep_config.serial_number_word1 =
Matthew Wilcoxd68f4322007-07-26 11:58:12 -040010565 AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010566
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010567 AdvSet38C1600EEPConfig(iop_base, &eep_config);
10568 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010569
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010570 /*
10571 * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
10572 * EEPROM configuration that was read.
10573 *
10574 * This is the mapping of EEPROM fields to Adv Library fields.
10575 */
10576 asc_dvc->wdtr_able = eep_config.wdtr_able;
10577 asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
10578 asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
10579 asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
10580 asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
10581 asc_dvc->ppr_able = 0;
10582 asc_dvc->tagqng_able = eep_config.tagqng_able;
10583 asc_dvc->cfg->disc_enable = eep_config.disc_enable;
10584 asc_dvc->max_host_qng = eep_config.max_host_qng;
10585 asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
10586 asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ASC_MAX_TID);
10587 asc_dvc->start_motor = eep_config.start_motor;
10588 asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
10589 asc_dvc->bios_ctrl = eep_config.bios_ctrl;
10590 asc_dvc->no_scam = eep_config.scam_tolerant;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010591
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010592 /*
10593 * For every Target ID if any of its 'sdtr_speed[1234]' bits
10594 * are set, then set an 'sdtr_able' bit for it.
10595 */
10596 asc_dvc->sdtr_able = 0;
10597 for (tid = 0; tid <= ASC_MAX_TID; tid++) {
10598 if (tid == 0) {
10599 sdtr_speed = asc_dvc->sdtr_speed1;
10600 } else if (tid == 4) {
10601 sdtr_speed = asc_dvc->sdtr_speed2;
10602 } else if (tid == 8) {
10603 sdtr_speed = asc_dvc->sdtr_speed3;
10604 } else if (tid == 12) {
10605 sdtr_speed = asc_dvc->sdtr_speed4;
10606 }
10607 if (sdtr_speed & ASC_MAX_TID) {
10608 asc_dvc->sdtr_able |= (1 << tid);
10609 }
10610 sdtr_speed >>= 4;
10611 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010612
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010613 /*
10614 * Set the host maximum queuing (max. 253, min. 16) and the per device
10615 * maximum queuing (max. 63, min. 4).
10616 */
10617 if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
10618 eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
10619 } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
10620 /* If the value is zero, assume it is uninitialized. */
10621 if (eep_config.max_host_qng == 0) {
10622 eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
10623 } else {
10624 eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
10625 }
10626 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010627
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010628 if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
10629 eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
10630 } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
10631 /* If the value is zero, assume it is uninitialized. */
10632 if (eep_config.max_dvc_qng == 0) {
10633 eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
10634 } else {
10635 eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
10636 }
10637 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010638
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010639 /*
10640 * If 'max_dvc_qng' is greater than 'max_host_qng', then
10641 * set 'max_dvc_qng' to 'max_host_qng'.
10642 */
10643 if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
10644 eep_config.max_dvc_qng = eep_config.max_host_qng;
10645 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010646
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010647 /*
10648 * Set ASC_DVC_VAR 'max_host_qng' and ASC_DVC_VAR 'max_dvc_qng'
10649 * values based on possibly adjusted EEPROM values.
10650 */
10651 asc_dvc->max_host_qng = eep_config.max_host_qng;
10652 asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010653
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010654 /*
10655 * If the EEPROM 'termination' field is set to automatic (0), then set
10656 * the ASC_DVC_CFG 'termination' field to automatic also.
10657 *
10658 * If the termination is specified with a non-zero 'termination'
10659 * value check that a legal value is set and set the ASC_DVC_CFG
10660 * 'termination' field appropriately.
10661 */
10662 if (eep_config.termination_se == 0) {
10663 termination = 0; /* auto termination for SE */
10664 } else {
10665 /* Enable manual control with low off / high off. */
10666 if (eep_config.termination_se == 1) {
10667 termination = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010668
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010669 /* Enable manual control with low off / high on. */
10670 } else if (eep_config.termination_se == 2) {
10671 termination = TERM_SE_HI;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010672
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010673 /* Enable manual control with low on / high on. */
10674 } else if (eep_config.termination_se == 3) {
10675 termination = TERM_SE;
10676 } else {
10677 /*
10678 * The EEPROM 'termination_se' field contains a bad value.
10679 * Use automatic termination instead.
10680 */
10681 termination = 0;
10682 warn_code |= ASC_WARN_EEPROM_TERMINATION;
10683 }
10684 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010685
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010686 if (eep_config.termination_lvd == 0) {
10687 asc_dvc->cfg->termination = termination; /* auto termination for LVD */
10688 } else {
10689 /* Enable manual control with low off / high off. */
10690 if (eep_config.termination_lvd == 1) {
10691 asc_dvc->cfg->termination = termination;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010692
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010693 /* Enable manual control with low off / high on. */
10694 } else if (eep_config.termination_lvd == 2) {
10695 asc_dvc->cfg->termination = termination | TERM_LVD_HI;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010696
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010697 /* Enable manual control with low on / high on. */
10698 } else if (eep_config.termination_lvd == 3) {
10699 asc_dvc->cfg->termination = termination | TERM_LVD;
10700 } else {
10701 /*
10702 * The EEPROM 'termination_lvd' field contains a bad value.
10703 * Use automatic termination instead.
10704 */
10705 asc_dvc->cfg->termination = termination;
10706 warn_code |= ASC_WARN_EEPROM_TERMINATION;
10707 }
10708 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010709
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010710 return warn_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010711}
10712
10713/*
Matthew Wilcox51219352007-10-02 21:55:22 -040010714 * Initialize the ADV_DVC_VAR structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010715 *
Matthew Wilcox51219352007-10-02 21:55:22 -040010716 * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010717 *
Matthew Wilcox51219352007-10-02 21:55:22 -040010718 * For a non-fatal error return a warning code. If there are no warnings
10719 * then 0 is returned.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010720 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010721static int AdvInitGetConfig(struct pci_dev *pdev, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -070010722{
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040010723 struct asc_board *board = shost_priv(shost);
10724 ADV_DVC_VAR *asc_dvc = &board->dvc_var.adv_dvc_var;
Matthew Wilcox51219352007-10-02 21:55:22 -040010725 unsigned short warn_code = 0;
10726 AdvPortAddr iop_base = asc_dvc->iop_base;
10727 u16 cmd;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010728 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010729
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010730 asc_dvc->err_code = 0;
Matthew Wilcox51219352007-10-02 21:55:22 -040010731
10732 /*
10733 * Save the state of the PCI Configuration Command Register
10734 * "Parity Error Response Control" Bit. If the bit is clear (0),
10735 * in AdvInitAsc3550/38C0800Driver() tell the microcode to ignore
10736 * DMA parity errors.
10737 */
10738 asc_dvc->cfg->control_flag = 0;
10739 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
10740 if ((cmd & PCI_COMMAND_PARITY) == 0)
10741 asc_dvc->cfg->control_flag |= CONTROL_FLAG_IGNORE_PERR;
10742
Matthew Wilcox51219352007-10-02 21:55:22 -040010743 asc_dvc->cfg->chip_version =
10744 AdvGetChipVersion(iop_base, asc_dvc->bus_type);
10745
Matthew Wilcoxb352f922007-10-02 21:55:33 -040010746 ASC_DBG(1, "iopb_chip_id_1: 0x%x 0x%x\n",
Matthew Wilcox51219352007-10-02 21:55:22 -040010747 (ushort)AdvReadByteRegister(iop_base, IOPB_CHIP_ID_1),
10748 (ushort)ADV_CHIP_ID_BYTE);
10749
Matthew Wilcoxb352f922007-10-02 21:55:33 -040010750 ASC_DBG(1, "iopw_chip_id_0: 0x%x 0x%x\n",
Matthew Wilcox51219352007-10-02 21:55:22 -040010751 (ushort)AdvReadWordRegister(iop_base, IOPW_CHIP_ID_0),
10752 (ushort)ADV_CHIP_ID_WORD);
10753
10754 /*
10755 * Reset the chip to start and allow register writes.
10756 */
10757 if (AdvFindSignature(iop_base) == 0) {
10758 asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
10759 return ADV_ERROR;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010760 } else {
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010761 /*
Matthew Wilcox51219352007-10-02 21:55:22 -040010762 * The caller must set 'chip_type' to a valid setting.
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010763 */
Matthew Wilcox51219352007-10-02 21:55:22 -040010764 if (asc_dvc->chip_type != ADV_CHIP_ASC3550 &&
10765 asc_dvc->chip_type != ADV_CHIP_ASC38C0800 &&
10766 asc_dvc->chip_type != ADV_CHIP_ASC38C1600) {
10767 asc_dvc->err_code |= ASC_IERR_BAD_CHIPTYPE;
10768 return ADV_ERROR;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010769 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010770
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010771 /*
Matthew Wilcox51219352007-10-02 21:55:22 -040010772 * Reset Chip.
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010773 */
Matthew Wilcox51219352007-10-02 21:55:22 -040010774 AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
10775 ADV_CTRL_REG_CMD_RESET);
10776 mdelay(100);
10777 AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
10778 ADV_CTRL_REG_CMD_WR_IO_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010779
Matthew Wilcox51219352007-10-02 21:55:22 -040010780 if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
10781 status = AdvInitFrom38C1600EEP(asc_dvc);
10782 } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
10783 status = AdvInitFrom38C0800EEP(asc_dvc);
10784 } else {
10785 status = AdvInitFrom3550EEP(asc_dvc);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010786 }
Matthew Wilcox51219352007-10-02 21:55:22 -040010787 warn_code |= status;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010788 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070010789
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040010790 if (warn_code != 0)
10791 shost_printk(KERN_WARNING, shost, "warning: 0x%x\n", warn_code);
Matthew Wilcox51219352007-10-02 21:55:22 -040010792
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040010793 if (asc_dvc->err_code)
10794 shost_printk(KERN_ERR, shost, "error code 0x%x\n",
10795 asc_dvc->err_code);
Matthew Wilcox51219352007-10-02 21:55:22 -040010796
10797 return asc_dvc->err_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010798}
Matthew Wilcox51219352007-10-02 21:55:22 -040010799#endif
10800
10801static struct scsi_host_template advansys_template = {
10802 .proc_name = DRV_NAME,
10803#ifdef CONFIG_PROC_FS
Al Virob59fb6f2013-03-31 02:59:55 -040010804 .show_info = advansys_show_info,
Matthew Wilcox51219352007-10-02 21:55:22 -040010805#endif
10806 .name = DRV_NAME,
10807 .info = advansys_info,
10808 .queuecommand = advansys_queuecommand,
Hannes Reineckeeac0b0c2015-04-24 13:18:20 +020010809 .eh_host_reset_handler = advansys_reset,
Matthew Wilcox51219352007-10-02 21:55:22 -040010810 .bios_param = advansys_biosparam,
10811 .slave_configure = advansys_slave_configure,
10812 /*
10813 * Because the driver may control an ISA adapter 'unchecked_isa_dma'
10814 * must be set. The flag will be cleared in advansys_board_found
10815 * for non-ISA adapters.
10816 */
Hannes Reineckeae267592015-04-24 13:18:28 +020010817 .unchecked_isa_dma = true,
Matthew Wilcox51219352007-10-02 21:55:22 -040010818 /*
10819 * All adapters controlled by this driver are capable of large
10820 * scatter-gather lists. According to the mid-level SCSI documentation
10821 * this obviates any performance gain provided by setting
10822 * 'use_clustering'. But empirically while CPU utilization is increased
10823 * by enabling clustering, I/O throughput increases as well.
10824 */
10825 .use_clustering = ENABLE_CLUSTERING,
Hannes Reinecke9c17c622015-04-24 13:18:21 +020010826 .use_blk_tags = 1,
Matthew Wilcox51219352007-10-02 21:55:22 -040010827};
Linus Torvalds1da177e2005-04-16 15:20:36 -070010828
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010829static int advansys_wide_init_chip(struct Scsi_Host *shost)
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060010830{
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040010831 struct asc_board *board = shost_priv(shost);
10832 struct adv_dvc_var *adv_dvc = &board->dvc_var.adv_dvc_var;
Hannes Reinecke0ce53822015-04-24 13:18:25 +020010833 size_t sgblk_pool_size;
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060010834 int warn_code, err_code;
10835
10836 /*
10837 * Allocate buffer carrier structures. The total size
Hannes Reinecke98b96a72015-04-24 13:18:23 +020010838 * is about 8 KB, so allocate all at once.
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060010839 */
Hannes Reinecke98b96a72015-04-24 13:18:23 +020010840 adv_dvc->carrier = dma_alloc_coherent(board->dev,
10841 ADV_CARRIER_BUFSIZE, &adv_dvc->carrier_addr, GFP_KERNEL);
10842 ASC_DBG(1, "carrier 0x%p\n", adv_dvc->carrier);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060010843
Hannes Reinecke98b96a72015-04-24 13:18:23 +020010844 if (!adv_dvc->carrier)
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060010845 goto kmalloc_failed;
10846
10847 /*
10848 * Allocate up to 'max_host_qng' request structures for the Wide
10849 * board. The total size is about 16 KB, so allocate all at once.
10850 * If the allocation fails decrement and try again.
10851 */
Hannes Reinecke4b47e462015-04-24 13:18:24 +020010852 board->adv_reqp_size = adv_dvc->max_host_qng * sizeof(adv_req_t);
10853 if (board->adv_reqp_size & 0x1f) {
10854 ASC_DBG(1, "unaligned reqp %lu bytes\n", sizeof(adv_req_t));
10855 board->adv_reqp_size = ADV_32BALIGN(board->adv_reqp_size);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060010856 }
Hannes Reinecke4b47e462015-04-24 13:18:24 +020010857 board->adv_reqp = dma_alloc_coherent(board->dev, board->adv_reqp_size,
10858 &board->adv_reqp_addr, GFP_KERNEL);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060010859
Hannes Reinecke4b47e462015-04-24 13:18:24 +020010860 if (!board->adv_reqp)
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060010861 goto kmalloc_failed;
10862
Hannes Reinecke4b47e462015-04-24 13:18:24 +020010863 ASC_DBG(1, "reqp 0x%p, req_cnt %d, bytes %lu\n", board->adv_reqp,
10864 adv_dvc->max_host_qng, board->adv_reqp_size);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060010865
10866 /*
10867 * Allocate up to ADV_TOT_SG_BLOCK request structures for
10868 * the Wide board. Each structure is about 136 bytes.
10869 */
Hannes Reinecke0ce53822015-04-24 13:18:25 +020010870 sgblk_pool_size = sizeof(adv_sgblk_t) * ADV_TOT_SG_BLOCK;
10871 board->adv_sgblk_pool = dma_pool_create("adv_sgblk", board->dev,
10872 sgblk_pool_size, 32, 0);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060010873
Hannes Reinecke0ce53822015-04-24 13:18:25 +020010874 ASC_DBG(1, "sg_cnt %d * %lu = %lu bytes\n", ADV_TOT_SG_BLOCK,
10875 sizeof(adv_sgblk_t), sgblk_pool_size);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060010876
Hannes Reinecke0ce53822015-04-24 13:18:25 +020010877 if (!board->adv_sgblk_pool)
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060010878 goto kmalloc_failed;
10879
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040010880 if (adv_dvc->chip_type == ADV_CHIP_ASC3550) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040010881 ASC_DBG(2, "AdvInitAsc3550Driver()\n");
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040010882 warn_code = AdvInitAsc3550Driver(adv_dvc);
10883 } else if (adv_dvc->chip_type == ADV_CHIP_ASC38C0800) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040010884 ASC_DBG(2, "AdvInitAsc38C0800Driver()\n");
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040010885 warn_code = AdvInitAsc38C0800Driver(adv_dvc);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060010886 } else {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040010887 ASC_DBG(2, "AdvInitAsc38C1600Driver()\n");
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040010888 warn_code = AdvInitAsc38C1600Driver(adv_dvc);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060010889 }
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040010890 err_code = adv_dvc->err_code;
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060010891
10892 if (warn_code || err_code) {
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040010893 shost_printk(KERN_WARNING, shost, "error: warn 0x%x, error "
10894 "0x%x\n", warn_code, err_code);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060010895 }
10896
10897 goto exit;
10898
10899 kmalloc_failed:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040010900 shost_printk(KERN_ERR, shost, "error: kmalloc() failed\n");
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060010901 err_code = ADV_ERROR;
10902 exit:
10903 return err_code;
10904}
10905
Matthew Wilcox98d41c22007-10-02 21:55:37 -040010906static void advansys_wide_free_mem(struct asc_board *board)
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060010907{
Matthew Wilcox98d41c22007-10-02 21:55:37 -040010908 struct adv_dvc_var *adv_dvc = &board->dvc_var.adv_dvc_var;
Hannes Reinecke98b96a72015-04-24 13:18:23 +020010909
10910 if (adv_dvc->carrier) {
10911 dma_free_coherent(board->dev, ADV_CARRIER_BUFSIZE,
10912 adv_dvc->carrier, adv_dvc->carrier_addr);
10913 adv_dvc->carrier = NULL;
10914 }
Hannes Reinecke4b47e462015-04-24 13:18:24 +020010915 if (board->adv_reqp) {
10916 dma_free_coherent(board->dev, board->adv_reqp_size,
10917 board->adv_reqp, board->adv_reqp_addr);
10918 board->adv_reqp = NULL;
10919 }
Hannes Reinecke0ce53822015-04-24 13:18:25 +020010920 if (board->adv_sgblk_pool) {
10921 dma_pool_destroy(board->adv_sgblk_pool);
10922 board->adv_sgblk_pool = NULL;
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060010923 }
10924}
10925
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010926static int advansys_board_found(struct Scsi_Host *shost, unsigned int iop,
10927 int bus_type)
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010928{
Matthew Wilcoxd361db42007-10-02 21:55:29 -040010929 struct pci_dev *pdev;
Matthew Wilcoxd2411492007-10-02 21:55:31 -040010930 struct asc_board *boardp = shost_priv(shost);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010931 ASC_DVC_VAR *asc_dvc_varp = NULL;
10932 ADV_DVC_VAR *adv_dvc_varp = NULL;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040010933 int share_irq, warn_code, ret;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010934
Matthew Wilcoxd361db42007-10-02 21:55:29 -040010935 pdev = (bus_type == ASC_IS_PCI) ? to_pci_dev(boardp->dev) : NULL;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010936
10937 if (ASC_NARROW_BOARD(boardp)) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040010938 ASC_DBG(1, "narrow board\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010939 asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
10940 asc_dvc_varp->bus_type = bus_type;
10941 asc_dvc_varp->drv_ptr = boardp;
10942 asc_dvc_varp->cfg = &boardp->dvc_cfg.asc_dvc_cfg;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010943 asc_dvc_varp->iop_base = iop;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010944 } else {
Matthew Wilcox57ba5fe2007-07-26 11:55:07 -040010945#ifdef CONFIG_PCI
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010946 adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
10947 adv_dvc_varp->drv_ptr = boardp;
10948 adv_dvc_varp->cfg = &boardp->dvc_cfg.adv_dvc_cfg;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010949 if (pdev->device == PCI_DEVICE_ID_ASP_ABP940UW) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040010950 ASC_DBG(1, "wide board ASC-3550\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010951 adv_dvc_varp->chip_type = ADV_CHIP_ASC3550;
10952 } else if (pdev->device == PCI_DEVICE_ID_38C0800_REV1) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040010953 ASC_DBG(1, "wide board ASC-38C0800\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010954 adv_dvc_varp->chip_type = ADV_CHIP_ASC38C0800;
10955 } else {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040010956 ASC_DBG(1, "wide board ASC-38C1600\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010957 adv_dvc_varp->chip_type = ADV_CHIP_ASC38C1600;
10958 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010959
Matthew Wilcox57ba5fe2007-07-26 11:55:07 -040010960 boardp->asc_n_io_port = pci_resource_len(pdev, 1);
Arjan van de Ven25729a72008-09-28 16:18:02 -070010961 boardp->ioremap_addr = pci_ioremap_bar(pdev, 1);
Matthew Wilcox57ba5fe2007-07-26 11:55:07 -040010962 if (!boardp->ioremap_addr) {
Matthew Wilcox9d511a42007-10-02 21:55:42 -040010963 shost_printk(KERN_ERR, shost, "ioremap(%lx, %d) "
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040010964 "returned NULL\n",
Matthew Wilcox9d511a42007-10-02 21:55:42 -040010965 (long)pci_resource_start(pdev, 1),
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040010966 boardp->asc_n_io_port);
Matthew Wilcoxd361db42007-10-02 21:55:29 -040010967 ret = -ENODEV;
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060010968 goto err_shost;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010969 }
Matthew Wilcoxb352f922007-10-02 21:55:33 -040010970 adv_dvc_varp->iop_base = (AdvPortAddr)boardp->ioremap_addr;
10971 ASC_DBG(1, "iop_base: 0x%p\n", adv_dvc_varp->iop_base);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010972
10973 /*
10974 * Even though it isn't used to access wide boards, other
10975 * than for the debug line below, save I/O Port address so
10976 * that it can be reported.
10977 */
10978 boardp->ioport = iop;
10979
Matthew Wilcoxb352f922007-10-02 21:55:33 -040010980 ASC_DBG(1, "iopb_chip_id_1 0x%x, iopw_chip_id_0 0x%x\n",
10981 (ushort)inp(iop + 1), (ushort)inpw(iop));
Matthew Wilcox57ba5fe2007-07-26 11:55:07 -040010982#endif /* CONFIG_PCI */
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010983 }
10984
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010985 if (ASC_NARROW_BOARD(boardp)) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010986 /*
10987 * Set the board bus type and PCI IRQ before
10988 * calling AscInitGetConfig().
10989 */
10990 switch (asc_dvc_varp->bus_type) {
10991#ifdef CONFIG_ISA
10992 case ASC_IS_ISA:
Hannes Reineckeae267592015-04-24 13:18:28 +020010993 shost->unchecked_isa_dma = true;
Matthew Wilcox074c8fe2007-07-28 23:11:05 -060010994 share_irq = 0;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010995 break;
10996 case ASC_IS_VL:
Hannes Reineckeae267592015-04-24 13:18:28 +020010997 shost->unchecked_isa_dma = false;
Matthew Wilcox074c8fe2007-07-28 23:11:05 -060010998 share_irq = 0;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040010999 break;
11000 case ASC_IS_EISA:
Hannes Reineckeae267592015-04-24 13:18:28 +020011001 shost->unchecked_isa_dma = false;
Matthew Wilcox074c8fe2007-07-28 23:11:05 -060011002 share_irq = IRQF_SHARED;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011003 break;
11004#endif /* CONFIG_ISA */
11005#ifdef CONFIG_PCI
11006 case ASC_IS_PCI:
Hannes Reineckeae267592015-04-24 13:18:28 +020011007 shost->unchecked_isa_dma = false;
Matthew Wilcox074c8fe2007-07-28 23:11:05 -060011008 share_irq = IRQF_SHARED;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011009 break;
11010#endif /* CONFIG_PCI */
11011 default:
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011012 shost_printk(KERN_ERR, shost, "unknown adapter type: "
11013 "%d\n", asc_dvc_varp->bus_type);
Hannes Reineckeae267592015-04-24 13:18:28 +020011014 shost->unchecked_isa_dma = false;
Matthew Wilcox074c8fe2007-07-28 23:11:05 -060011015 share_irq = 0;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011016 break;
11017 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011018
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011019 /*
11020 * NOTE: AscInitGetConfig() may change the board's
11021 * bus_type value. The bus_type value should no
11022 * longer be used. If the bus_type field must be
11023 * referenced only use the bit-wise AND operator "&".
11024 */
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011025 ASC_DBG(2, "AscInitGetConfig()\n");
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011026 ret = AscInitGetConfig(shost) ? -ENODEV : 0;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011027 } else {
Matthew Wilcoxc2dce2f2007-09-09 08:56:30 -060011028#ifdef CONFIG_PCI
11029 /*
11030 * For Wide boards set PCI information before calling
11031 * AdvInitGetConfig().
11032 */
Hannes Reineckeae267592015-04-24 13:18:28 +020011033 shost->unchecked_isa_dma = false;
Matthew Wilcoxc2dce2f2007-09-09 08:56:30 -060011034 share_irq = IRQF_SHARED;
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011035 ASC_DBG(2, "AdvInitGetConfig()\n");
Matthew Wilcox394dbf32007-07-26 11:56:40 -040011036
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011037 ret = AdvInitGetConfig(pdev, shost) ? -ENODEV : 0;
Matthew Wilcoxc2dce2f2007-09-09 08:56:30 -060011038#endif /* CONFIG_PCI */
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011039 }
11040
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011041 if (ret)
Al Virob59fb6f2013-03-31 02:59:55 -040011042 goto err_unmap;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011043
11044 /*
11045 * Save the EEPROM configuration so that it can be displayed
11046 * from /proc/scsi/advansys/[0...].
11047 */
11048 if (ASC_NARROW_BOARD(boardp)) {
11049
11050 ASCEEP_CONFIG *ep;
11051
11052 /*
11053 * Set the adapter's target id bit in the 'init_tidmask' field.
11054 */
11055 boardp->init_tidmask |=
11056 ADV_TID_TO_TIDMASK(asc_dvc_varp->cfg->chip_scsi_id);
11057
11058 /*
11059 * Save EEPROM settings for the board.
11060 */
11061 ep = &boardp->eep_config.asc_eep;
11062
11063 ep->init_sdtr = asc_dvc_varp->cfg->sdtr_enable;
11064 ep->disc_enable = asc_dvc_varp->cfg->disc_enable;
11065 ep->use_cmd_qng = asc_dvc_varp->cfg->cmd_qng_enabled;
11066 ASC_EEP_SET_DMA_SPD(ep, asc_dvc_varp->cfg->isa_dma_speed);
11067 ep->start_motor = asc_dvc_varp->start_motor;
11068 ep->cntl = asc_dvc_varp->dvc_cntl;
11069 ep->no_scam = asc_dvc_varp->no_scam;
11070 ep->max_total_qng = asc_dvc_varp->max_total_qng;
11071 ASC_EEP_SET_CHIP_ID(ep, asc_dvc_varp->cfg->chip_scsi_id);
11072 /* 'max_tag_qng' is set to the same value for every device. */
11073 ep->max_tag_qng = asc_dvc_varp->cfg->max_tag_qng[0];
11074 ep->adapter_info[0] = asc_dvc_varp->cfg->adapter_info[0];
11075 ep->adapter_info[1] = asc_dvc_varp->cfg->adapter_info[1];
11076 ep->adapter_info[2] = asc_dvc_varp->cfg->adapter_info[2];
11077 ep->adapter_info[3] = asc_dvc_varp->cfg->adapter_info[3];
11078 ep->adapter_info[4] = asc_dvc_varp->cfg->adapter_info[4];
11079 ep->adapter_info[5] = asc_dvc_varp->cfg->adapter_info[5];
11080
11081 /*
11082 * Modify board configuration.
11083 */
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011084 ASC_DBG(2, "AscInitSetConfig()\n");
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011085 ret = AscInitSetConfig(pdev, shost) ? -ENODEV : 0;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011086 if (ret)
Al Virob59fb6f2013-03-31 02:59:55 -040011087 goto err_unmap;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011088 } else {
11089 ADVEEP_3550_CONFIG *ep_3550;
11090 ADVEEP_38C0800_CONFIG *ep_38C0800;
11091 ADVEEP_38C1600_CONFIG *ep_38C1600;
11092
11093 /*
11094 * Save Wide EEP Configuration Information.
11095 */
11096 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
11097 ep_3550 = &boardp->eep_config.adv_3550_eep;
11098
11099 ep_3550->adapter_scsi_id = adv_dvc_varp->chip_scsi_id;
11100 ep_3550->max_host_qng = adv_dvc_varp->max_host_qng;
11101 ep_3550->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
11102 ep_3550->termination = adv_dvc_varp->cfg->termination;
11103 ep_3550->disc_enable = adv_dvc_varp->cfg->disc_enable;
11104 ep_3550->bios_ctrl = adv_dvc_varp->bios_ctrl;
11105 ep_3550->wdtr_able = adv_dvc_varp->wdtr_able;
11106 ep_3550->sdtr_able = adv_dvc_varp->sdtr_able;
11107 ep_3550->ultra_able = adv_dvc_varp->ultra_able;
11108 ep_3550->tagqng_able = adv_dvc_varp->tagqng_able;
11109 ep_3550->start_motor = adv_dvc_varp->start_motor;
11110 ep_3550->scsi_reset_delay =
11111 adv_dvc_varp->scsi_reset_wait;
11112 ep_3550->serial_number_word1 =
11113 adv_dvc_varp->cfg->serial1;
11114 ep_3550->serial_number_word2 =
11115 adv_dvc_varp->cfg->serial2;
11116 ep_3550->serial_number_word3 =
11117 adv_dvc_varp->cfg->serial3;
11118 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
11119 ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
11120
11121 ep_38C0800->adapter_scsi_id =
11122 adv_dvc_varp->chip_scsi_id;
11123 ep_38C0800->max_host_qng = adv_dvc_varp->max_host_qng;
11124 ep_38C0800->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
11125 ep_38C0800->termination_lvd =
11126 adv_dvc_varp->cfg->termination;
11127 ep_38C0800->disc_enable =
11128 adv_dvc_varp->cfg->disc_enable;
11129 ep_38C0800->bios_ctrl = adv_dvc_varp->bios_ctrl;
11130 ep_38C0800->wdtr_able = adv_dvc_varp->wdtr_able;
11131 ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
11132 ep_38C0800->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
11133 ep_38C0800->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
11134 ep_38C0800->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
11135 ep_38C0800->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
11136 ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
11137 ep_38C0800->start_motor = adv_dvc_varp->start_motor;
11138 ep_38C0800->scsi_reset_delay =
11139 adv_dvc_varp->scsi_reset_wait;
11140 ep_38C0800->serial_number_word1 =
11141 adv_dvc_varp->cfg->serial1;
11142 ep_38C0800->serial_number_word2 =
11143 adv_dvc_varp->cfg->serial2;
11144 ep_38C0800->serial_number_word3 =
11145 adv_dvc_varp->cfg->serial3;
11146 } else {
11147 ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
11148
11149 ep_38C1600->adapter_scsi_id =
11150 adv_dvc_varp->chip_scsi_id;
11151 ep_38C1600->max_host_qng = adv_dvc_varp->max_host_qng;
11152 ep_38C1600->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
11153 ep_38C1600->termination_lvd =
11154 adv_dvc_varp->cfg->termination;
11155 ep_38C1600->disc_enable =
11156 adv_dvc_varp->cfg->disc_enable;
11157 ep_38C1600->bios_ctrl = adv_dvc_varp->bios_ctrl;
11158 ep_38C1600->wdtr_able = adv_dvc_varp->wdtr_able;
11159 ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
11160 ep_38C1600->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
11161 ep_38C1600->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
11162 ep_38C1600->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
11163 ep_38C1600->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
11164 ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
11165 ep_38C1600->start_motor = adv_dvc_varp->start_motor;
11166 ep_38C1600->scsi_reset_delay =
11167 adv_dvc_varp->scsi_reset_wait;
11168 ep_38C1600->serial_number_word1 =
11169 adv_dvc_varp->cfg->serial1;
11170 ep_38C1600->serial_number_word2 =
11171 adv_dvc_varp->cfg->serial2;
11172 ep_38C1600->serial_number_word3 =
11173 adv_dvc_varp->cfg->serial3;
11174 }
11175
11176 /*
11177 * Set the adapter's target id bit in the 'init_tidmask' field.
11178 */
11179 boardp->init_tidmask |=
11180 ADV_TID_TO_TIDMASK(adv_dvc_varp->chip_scsi_id);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011181 }
11182
11183 /*
11184 * Channels are numbered beginning with 0. For AdvanSys one host
11185 * structure supports one channel. Multi-channel boards have a
11186 * separate host structure for each channel.
11187 */
11188 shost->max_channel = 0;
11189 if (ASC_NARROW_BOARD(boardp)) {
11190 shost->max_id = ASC_MAX_TID + 1;
11191 shost->max_lun = ASC_MAX_LUN + 1;
Matthew Wilcoxf05ec592007-09-09 08:56:36 -060011192 shost->max_cmd_len = ASC_MAX_CDB_LEN;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011193
11194 shost->io_port = asc_dvc_varp->iop_base;
11195 boardp->asc_n_io_port = ASC_IOADR_GAP;
11196 shost->this_id = asc_dvc_varp->cfg->chip_scsi_id;
11197
11198 /* Set maximum number of queues the adapter can handle. */
11199 shost->can_queue = asc_dvc_varp->max_total_qng;
11200 } else {
11201 shost->max_id = ADV_MAX_TID + 1;
11202 shost->max_lun = ADV_MAX_LUN + 1;
Matthew Wilcoxf05ec592007-09-09 08:56:36 -060011203 shost->max_cmd_len = ADV_MAX_CDB_LEN;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011204
11205 /*
11206 * Save the I/O Port address and length even though
11207 * I/O ports are not used to access Wide boards.
11208 * Instead the Wide boards are accessed with
11209 * PCI Memory Mapped I/O.
11210 */
11211 shost->io_port = iop;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011212
11213 shost->this_id = adv_dvc_varp->chip_scsi_id;
11214
11215 /* Set maximum number of queues the adapter can handle. */
11216 shost->can_queue = adv_dvc_varp->max_host_qng;
11217 }
Hannes Reinecke9c17c622015-04-24 13:18:21 +020011218 ret = scsi_init_shared_tag_map(shost, shost->can_queue);
11219 if (ret) {
11220 shost_printk(KERN_ERR, shost, "init tag map failed\n");
11221 goto err_free_dma;
11222 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011223
11224 /*
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011225 * Following v1.3.89, 'cmd_per_lun' is no longer needed
11226 * and should be set to zero.
11227 *
11228 * But because of a bug introduced in v1.3.89 if the driver is
11229 * compiled as a module and 'cmd_per_lun' is zero, the Mid-Level
11230 * SCSI function 'allocate_device' will panic. To allow the driver
11231 * to work as a module in these kernels set 'cmd_per_lun' to 1.
11232 *
11233 * Note: This is wrong. cmd_per_lun should be set to the depth
11234 * you want on untagged devices always.
11235 #ifdef MODULE
11236 */
11237 shost->cmd_per_lun = 1;
11238/* #else
11239 shost->cmd_per_lun = 0;
11240#endif */
11241
11242 /*
11243 * Set the maximum number of scatter-gather elements the
11244 * adapter can handle.
11245 */
11246 if (ASC_NARROW_BOARD(boardp)) {
11247 /*
11248 * Allow two commands with 'sg_tablesize' scatter-gather
11249 * elements to be executed simultaneously. This value is
11250 * the theoretical hardware limit. It may be decreased
11251 * below.
11252 */
11253 shost->sg_tablesize =
11254 (((asc_dvc_varp->max_total_qng - 2) / 2) *
11255 ASC_SG_LIST_PER_Q) + 1;
11256 } else {
11257 shost->sg_tablesize = ADV_MAX_SG_LIST;
11258 }
11259
11260 /*
11261 * The value of 'sg_tablesize' can not exceed the SCSI
11262 * mid-level driver definition of SG_ALL. SG_ALL also
11263 * must not be exceeded, because it is used to define the
11264 * size of the scatter-gather table in 'struct asc_sg_head'.
11265 */
11266 if (shost->sg_tablesize > SG_ALL) {
11267 shost->sg_tablesize = SG_ALL;
11268 }
11269
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011270 ASC_DBG(1, "sg_tablesize: %d\n", shost->sg_tablesize);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011271
11272 /* BIOS start address. */
11273 if (ASC_NARROW_BOARD(boardp)) {
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011274 shost->base = AscGetChipBiosAddress(asc_dvc_varp->iop_base,
11275 asc_dvc_varp->bus_type);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011276 } else {
11277 /*
11278 * Fill-in BIOS board variables. The Wide BIOS saves
11279 * information in LRAM that is used by the driver.
11280 */
11281 AdvReadWordLram(adv_dvc_varp->iop_base,
11282 BIOS_SIGNATURE, boardp->bios_signature);
11283 AdvReadWordLram(adv_dvc_varp->iop_base,
11284 BIOS_VERSION, boardp->bios_version);
11285 AdvReadWordLram(adv_dvc_varp->iop_base,
11286 BIOS_CODESEG, boardp->bios_codeseg);
11287 AdvReadWordLram(adv_dvc_varp->iop_base,
11288 BIOS_CODELEN, boardp->bios_codelen);
11289
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011290 ASC_DBG(1, "bios_signature 0x%x, bios_version 0x%x\n",
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011291 boardp->bios_signature, boardp->bios_version);
11292
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011293 ASC_DBG(1, "bios_codeseg 0x%x, bios_codelen 0x%x\n",
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011294 boardp->bios_codeseg, boardp->bios_codelen);
11295
11296 /*
11297 * If the BIOS saved a valid signature, then fill in
11298 * the BIOS code segment base address.
11299 */
11300 if (boardp->bios_signature == 0x55AA) {
11301 /*
11302 * Convert x86 realmode code segment to a linear
11303 * address by shifting left 4.
11304 */
11305 shost->base = ((ulong)boardp->bios_codeseg << 4);
11306 } else {
11307 shost->base = 0;
11308 }
11309 }
11310
11311 /*
11312 * Register Board Resources - I/O Port, DMA, IRQ
11313 */
11314
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011315 /* Register DMA Channel for Narrow boards. */
11316 shost->dma_channel = NO_ISA_DMA; /* Default to no ISA DMA. */
11317#ifdef CONFIG_ISA
11318 if (ASC_NARROW_BOARD(boardp)) {
11319 /* Register DMA channel for ISA bus. */
11320 if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
11321 shost->dma_channel = asc_dvc_varp->cfg->isa_dma_channel;
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060011322 ret = request_dma(shost->dma_channel, DRV_NAME);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011323 if (ret) {
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011324 shost_printk(KERN_ERR, shost, "request_dma() "
11325 "%d failed %d\n",
11326 shost->dma_channel, ret);
Al Virob59fb6f2013-03-31 02:59:55 -040011327 goto err_unmap;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011328 }
11329 AscEnableIsaDma(shost->dma_channel);
11330 }
11331 }
11332#endif /* CONFIG_ISA */
11333
11334 /* Register IRQ Number. */
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011335 ASC_DBG(2, "request_irq(%d, %p)\n", boardp->irq, shost);
Matthew Wilcox074c8fe2007-07-28 23:11:05 -060011336
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011337 ret = request_irq(boardp->irq, advansys_interrupt, share_irq,
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060011338 DRV_NAME, shost);
Matthew Wilcox074c8fe2007-07-28 23:11:05 -060011339
11340 if (ret) {
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011341 if (ret == -EBUSY) {
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011342 shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
11343 "already in use\n", boardp->irq);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011344 } else if (ret == -EINVAL) {
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011345 shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
11346 "not valid\n", boardp->irq);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011347 } else {
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011348 shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
11349 "failed with %d\n", boardp->irq, ret);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011350 }
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011351 goto err_free_dma;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011352 }
11353
11354 /*
11355 * Initialize board RISC chip and enable interrupts.
11356 */
11357 if (ASC_NARROW_BOARD(boardp)) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011358 ASC_DBG(2, "AscInitAsc1000Driver()\n");
FUJITA Tomonori7d5d4082008-02-08 09:50:08 +090011359
11360 asc_dvc_varp->overrun_buf = kzalloc(ASC_OVERRUN_BSIZE, GFP_KERNEL);
11361 if (!asc_dvc_varp->overrun_buf) {
11362 ret = -ENOMEM;
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -030011363 goto err_free_irq;
FUJITA Tomonori7d5d4082008-02-08 09:50:08 +090011364 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011365 warn_code = AscInitAsc1000Driver(asc_dvc_varp);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011366
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011367 if (warn_code || asc_dvc_varp->err_code) {
Matthew Wilcox9d0e96e2007-10-02 21:55:35 -040011368 shost_printk(KERN_ERR, shost, "error: init_state 0x%x, "
11369 "warn 0x%x, error 0x%x\n",
11370 asc_dvc_varp->init_state, warn_code,
11371 asc_dvc_varp->err_code);
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -030011372 if (!asc_dvc_varp->overrun_dma) {
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011373 ret = -ENODEV;
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -030011374 goto err_free_mem;
FUJITA Tomonori7d5d4082008-02-08 09:50:08 +090011375 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011376 }
11377 } else {
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -030011378 if (advansys_wide_init_chip(shost)) {
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011379 ret = -ENODEV;
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -030011380 goto err_free_mem;
11381 }
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011382 }
11383
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011384 ASC_DBG_PRT_SCSI_HOST(2, shost);
11385
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011386 ret = scsi_add_host(shost, boardp->dev);
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060011387 if (ret)
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -030011388 goto err_free_mem;
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060011389
11390 scsi_scan_host(shost);
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011391 return 0;
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011392
Herton Ronaldo Krzesinski9a908c12010-03-30 13:35:38 -030011393 err_free_mem:
11394 if (ASC_NARROW_BOARD(boardp)) {
11395 if (asc_dvc_varp->overrun_dma)
11396 dma_unmap_single(boardp->dev, asc_dvc_varp->overrun_dma,
11397 ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
11398 kfree(asc_dvc_varp->overrun_buf);
11399 } else
11400 advansys_wide_free_mem(boardp);
11401 err_free_irq:
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011402 free_irq(boardp->irq, shost);
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011403 err_free_dma:
Al Viro30037812008-11-22 17:34:54 +000011404#ifdef CONFIG_ISA
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011405 if (shost->dma_channel != NO_ISA_DMA)
11406 free_dma(shost->dma_channel);
Al Viro30037812008-11-22 17:34:54 +000011407#endif
Matthew Wilcoxb2c16f52007-07-29 17:30:28 -060011408 err_unmap:
11409 if (boardp->ioremap_addr)
11410 iounmap(boardp->ioremap_addr);
11411 err_shost:
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011412 return ret;
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011413}
11414
11415/*
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011416 * advansys_release()
11417 *
11418 * Release resources allocated for a single AdvanSys adapter.
11419 */
11420static int advansys_release(struct Scsi_Host *shost)
11421{
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -040011422 struct asc_board *board = shost_priv(shost);
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011423 ASC_DBG(1, "begin\n");
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060011424 scsi_remove_host(shost);
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -040011425 free_irq(board->irq, shost);
Al Viro30037812008-11-22 17:34:54 +000011426#ifdef CONFIG_ISA
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011427 if (shost->dma_channel != NO_ISA_DMA) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011428 ASC_DBG(1, "free_dma()\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011429 free_dma(shost->dma_channel);
11430 }
Al Viro30037812008-11-22 17:34:54 +000011431#endif
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -040011432 if (ASC_NARROW_BOARD(board)) {
11433 dma_unmap_single(board->dev,
11434 board->dvc_var.asc_dvc_var.overrun_dma,
11435 ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
FUJITA Tomonori7d5d4082008-02-08 09:50:08 +090011436 kfree(board->dvc_var.asc_dvc_var.overrun_buf);
Matthew Wilcoxd10fb2c2007-10-02 21:55:41 -040011437 } else {
11438 iounmap(board->ioremap_addr);
11439 advansys_wide_free_mem(board);
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011440 }
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060011441 scsi_host_put(shost);
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011442 ASC_DBG(1, "end\n");
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011443 return 0;
11444}
11445
Matthew Wilcox95c9f162007-09-09 08:56:39 -060011446#define ASC_IOADR_TABLE_MAX_IX 11
11447
Randy Dunlap747d0162008-01-14 00:55:18 -080011448static PortAddr _asc_def_iop_base[ASC_IOADR_TABLE_MAX_IX] = {
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011449 0x100, 0x0110, 0x120, 0x0130, 0x140, 0x0150, 0x0190,
11450 0x0210, 0x0230, 0x0250, 0x0330
11451};
11452
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011453/*
11454 * The ISA IRQ number is found in bits 2 and 3 of the CfgLsw. It decodes as:
11455 * 00: 10
11456 * 01: 11
11457 * 10: 12
11458 * 11: 15
11459 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011460static unsigned int advansys_isa_irq_no(PortAddr iop_base)
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011461{
11462 unsigned short cfg_lsw = AscGetChipCfgLsw(iop_base);
11463 unsigned int chip_irq = ((cfg_lsw >> 2) & 0x03) + 10;
11464 if (chip_irq == 13)
11465 chip_irq = 15;
11466 return chip_irq;
11467}
11468
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011469static int advansys_isa_probe(struct device *dev, unsigned int id)
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011470{
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011471 int err = -ENODEV;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011472 PortAddr iop_base = _asc_def_iop_base[id];
11473 struct Scsi_Host *shost;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011474 struct asc_board *board;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011475
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060011476 if (!request_region(iop_base, ASC_IOADR_GAP, DRV_NAME)) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011477 ASC_DBG(1, "I/O port 0x%x busy\n", iop_base);
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011478 return -ENODEV;
11479 }
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011480 ASC_DBG(1, "probing I/O port 0x%x\n", iop_base);
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011481 if (!AscFindSignature(iop_base))
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011482 goto release_region;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011483 if (!(AscGetChipVersion(iop_base, ASC_IS_ISA) & ASC_CHIP_VER_ISA_BIT))
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011484 goto release_region;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011485
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011486 err = -ENOMEM;
11487 shost = scsi_host_alloc(&advansys_template, sizeof(*board));
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011488 if (!shost)
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011489 goto release_region;
11490
Matthew Wilcoxd2411492007-10-02 21:55:31 -040011491 board = shost_priv(shost);
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011492 board->irq = advansys_isa_irq_no(iop_base);
11493 board->dev = dev;
Hannes Reinecke9c17c622015-04-24 13:18:21 +020011494 board->shost = shost;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011495
11496 err = advansys_board_found(shost, iop_base, ASC_IS_ISA);
11497 if (err)
11498 goto free_host;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011499
11500 dev_set_drvdata(dev, shost);
11501 return 0;
11502
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011503 free_host:
11504 scsi_host_put(shost);
11505 release_region:
Matthew Wilcox71f36112007-07-30 08:04:53 -060011506 release_region(iop_base, ASC_IOADR_GAP);
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011507 return err;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011508}
11509
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011510static int advansys_isa_remove(struct device *dev, unsigned int id)
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011511{
Matthew Wilcox71f36112007-07-30 08:04:53 -060011512 int ioport = _asc_def_iop_base[id];
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011513 advansys_release(dev_get_drvdata(dev));
Matthew Wilcox71f36112007-07-30 08:04:53 -060011514 release_region(ioport, ASC_IOADR_GAP);
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011515 return 0;
11516}
11517
11518static struct isa_driver advansys_isa_driver = {
11519 .probe = advansys_isa_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011520 .remove = advansys_isa_remove,
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011521 .driver = {
11522 .owner = THIS_MODULE,
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060011523 .name = DRV_NAME,
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011524 },
11525};
11526
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011527/*
11528 * The VLB IRQ number is found in bits 2 to 4 of the CfgLsw. It decodes as:
11529 * 000: invalid
11530 * 001: 10
11531 * 010: 11
11532 * 011: 12
11533 * 100: invalid
11534 * 101: 14
11535 * 110: 15
11536 * 111: invalid
11537 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011538static unsigned int advansys_vlb_irq_no(PortAddr iop_base)
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011539{
11540 unsigned short cfg_lsw = AscGetChipCfgLsw(iop_base);
11541 unsigned int chip_irq = ((cfg_lsw >> 2) & 0x07) + 9;
11542 if ((chip_irq < 10) || (chip_irq == 13) || (chip_irq > 15))
11543 return 0;
11544 return chip_irq;
11545}
11546
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011547static int advansys_vlb_probe(struct device *dev, unsigned int id)
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011548{
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011549 int err = -ENODEV;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011550 PortAddr iop_base = _asc_def_iop_base[id];
11551 struct Scsi_Host *shost;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011552 struct asc_board *board;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011553
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060011554 if (!request_region(iop_base, ASC_IOADR_GAP, DRV_NAME)) {
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011555 ASC_DBG(1, "I/O port 0x%x busy\n", iop_base);
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011556 return -ENODEV;
11557 }
Matthew Wilcoxb352f922007-10-02 21:55:33 -040011558 ASC_DBG(1, "probing I/O port 0x%x\n", iop_base);
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011559 if (!AscFindSignature(iop_base))
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011560 goto release_region;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011561 /*
11562 * I don't think this condition can actually happen, but the old
11563 * driver did it, and the chances of finding a VLB setup in 2007
11564 * to do testing with is slight to none.
11565 */
11566 if (AscGetChipVersion(iop_base, ASC_IS_VL) > ASC_CHIP_MAX_VER_VL)
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011567 goto release_region;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011568
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011569 err = -ENOMEM;
11570 shost = scsi_host_alloc(&advansys_template, sizeof(*board));
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011571 if (!shost)
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011572 goto release_region;
11573
Matthew Wilcoxd2411492007-10-02 21:55:31 -040011574 board = shost_priv(shost);
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011575 board->irq = advansys_vlb_irq_no(iop_base);
11576 board->dev = dev;
Hannes Reinecke9c17c622015-04-24 13:18:21 +020011577 board->shost = shost;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011578
11579 err = advansys_board_found(shost, iop_base, ASC_IS_VL);
11580 if (err)
11581 goto free_host;
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011582
11583 dev_set_drvdata(dev, shost);
11584 return 0;
11585
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011586 free_host:
11587 scsi_host_put(shost);
11588 release_region:
Matthew Wilcox71f36112007-07-30 08:04:53 -060011589 release_region(iop_base, ASC_IOADR_GAP);
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011590 return -ENODEV;
11591}
11592
11593static struct isa_driver advansys_vlb_driver = {
11594 .probe = advansys_vlb_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011595 .remove = advansys_isa_remove,
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011596 .driver = {
11597 .owner = THIS_MODULE,
Matthew Wilcoxb8e5152b2007-09-09 08:56:26 -060011598 .name = "advansys_vlb",
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011599 },
11600};
11601
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011602static struct eisa_device_id advansys_eisa_table[] = {
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011603 { "ABP7401" },
11604 { "ABP7501" },
11605 { "" }
11606};
11607
11608MODULE_DEVICE_TABLE(eisa, advansys_eisa_table);
11609
11610/*
11611 * EISA is a little more tricky than PCI; each EISA device may have two
11612 * channels, and this driver is written to make each channel its own Scsi_Host
11613 */
11614struct eisa_scsi_data {
11615 struct Scsi_Host *host[2];
11616};
11617
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011618/*
11619 * The EISA IRQ number is found in bits 8 to 10 of the CfgLsw. It decodes as:
11620 * 000: 10
11621 * 001: 11
11622 * 010: 12
11623 * 011: invalid
11624 * 100: 14
11625 * 101: 15
11626 * 110: invalid
11627 * 111: invalid
11628 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011629static unsigned int advansys_eisa_irq_no(struct eisa_device *edev)
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011630{
11631 unsigned short cfg_lsw = inw(edev->base_addr + 0xc86);
11632 unsigned int chip_irq = ((cfg_lsw >> 8) & 0x07) + 10;
11633 if ((chip_irq == 13) || (chip_irq > 15))
11634 return 0;
11635 return chip_irq;
11636}
11637
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011638static int advansys_eisa_probe(struct device *dev)
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011639{
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011640 int i, ioport, irq = 0;
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011641 int err;
11642 struct eisa_device *edev = to_eisa_device(dev);
11643 struct eisa_scsi_data *data;
11644
11645 err = -ENOMEM;
11646 data = kzalloc(sizeof(*data), GFP_KERNEL);
11647 if (!data)
11648 goto fail;
11649 ioport = edev->base_addr + 0xc30;
11650
11651 err = -ENODEV;
11652 for (i = 0; i < 2; i++, ioport += 0x20) {
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011653 struct asc_board *board;
11654 struct Scsi_Host *shost;
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060011655 if (!request_region(ioport, ASC_IOADR_GAP, DRV_NAME)) {
Matthew Wilcox71f36112007-07-30 08:04:53 -060011656 printk(KERN_WARNING "Region %x-%x busy\n", ioport,
11657 ioport + ASC_IOADR_GAP - 1);
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011658 continue;
Matthew Wilcox71f36112007-07-30 08:04:53 -060011659 }
11660 if (!AscFindSignature(ioport)) {
11661 release_region(ioport, ASC_IOADR_GAP);
11662 continue;
11663 }
11664
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011665 /*
11666 * I don't know why we need to do this for EISA chips, but
11667 * not for any others. It looks to be equivalent to
11668 * AscGetChipCfgMsw, but I may have overlooked something,
11669 * so I'm not converting it until I get an EISA board to
11670 * test with.
11671 */
11672 inw(ioport + 4);
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011673
11674 if (!irq)
11675 irq = advansys_eisa_irq_no(edev);
11676
11677 err = -ENOMEM;
11678 shost = scsi_host_alloc(&advansys_template, sizeof(*board));
11679 if (!shost)
11680 goto release_region;
11681
Matthew Wilcoxd2411492007-10-02 21:55:31 -040011682 board = shost_priv(shost);
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011683 board->irq = irq;
11684 board->dev = dev;
Hannes Reinecke9c17c622015-04-24 13:18:21 +020011685 board->shost = shost;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011686
11687 err = advansys_board_found(shost, ioport, ASC_IS_EISA);
11688 if (!err) {
11689 data->host[i] = shost;
11690 continue;
Matthew Wilcox71f36112007-07-30 08:04:53 -060011691 }
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011692
11693 scsi_host_put(shost);
11694 release_region:
11695 release_region(ioport, ASC_IOADR_GAP);
11696 break;
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011697 }
11698
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011699 if (err)
11700 goto free_data;
11701 dev_set_drvdata(dev, data);
11702 return 0;
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011703
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011704 free_data:
11705 kfree(data->host[0]);
11706 kfree(data->host[1]);
11707 kfree(data);
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011708 fail:
11709 return err;
11710}
11711
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011712static int advansys_eisa_remove(struct device *dev)
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011713{
11714 int i;
11715 struct eisa_scsi_data *data = dev_get_drvdata(dev);
11716
11717 for (i = 0; i < 2; i++) {
Matthew Wilcox71f36112007-07-30 08:04:53 -060011718 int ioport;
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011719 struct Scsi_Host *shost = data->host[i];
11720 if (!shost)
11721 continue;
Matthew Wilcox71f36112007-07-30 08:04:53 -060011722 ioport = shost->io_port;
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011723 advansys_release(shost);
Matthew Wilcox71f36112007-07-30 08:04:53 -060011724 release_region(ioport, ASC_IOADR_GAP);
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011725 }
11726
11727 kfree(data);
11728 return 0;
11729}
11730
11731static struct eisa_driver advansys_eisa_driver = {
11732 .id_table = advansys_eisa_table,
11733 .driver = {
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060011734 .name = DRV_NAME,
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011735 .probe = advansys_eisa_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011736 .remove = advansys_eisa_remove,
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011737 }
11738};
11739
Dave Jones2672ea82006-08-02 17:11:49 -040011740/* PCI Devices supported by this driver */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011741static struct pci_device_id advansys_pci_tbl[] = {
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011742 {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_1200A,
11743 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
11744 {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940,
11745 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
11746 {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940U,
11747 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
11748 {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940UW,
11749 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
11750 {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_38C0800_REV1,
11751 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
11752 {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_38C1600_REV1,
11753 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
11754 {}
Dave Jones2672ea82006-08-02 17:11:49 -040011755};
Matthew Wilcox27c868c2007-07-26 10:56:23 -040011756
Dave Jones2672ea82006-08-02 17:11:49 -040011757MODULE_DEVICE_TABLE(pci, advansys_pci_tbl);
Matthew Wilcox78e77d82007-07-29 21:46:15 -060011758
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011759static void advansys_set_latency(struct pci_dev *pdev)
Matthew Wilcox9649af32007-07-26 21:51:47 -060011760{
11761 if ((pdev->device == PCI_DEVICE_ID_ASP_1200A) ||
11762 (pdev->device == PCI_DEVICE_ID_ASP_ABP940)) {
11763 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0);
11764 } else {
11765 u8 latency;
11766 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency);
11767 if (latency < 0x20)
11768 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x20);
11769 }
11770}
11771
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011772static int advansys_pci_probe(struct pci_dev *pdev,
11773 const struct pci_device_id *ent)
Matthew Wilcox78e77d82007-07-29 21:46:15 -060011774{
11775 int err, ioport;
11776 struct Scsi_Host *shost;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011777 struct asc_board *board;
Matthew Wilcox78e77d82007-07-29 21:46:15 -060011778
11779 err = pci_enable_device(pdev);
11780 if (err)
11781 goto fail;
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060011782 err = pci_request_regions(pdev, DRV_NAME);
Matthew Wilcox71f36112007-07-30 08:04:53 -060011783 if (err)
11784 goto disable_device;
Matthew Wilcox9649af32007-07-26 21:51:47 -060011785 pci_set_master(pdev);
11786 advansys_set_latency(pdev);
Matthew Wilcox78e77d82007-07-29 21:46:15 -060011787
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011788 err = -ENODEV;
Matthew Wilcox78e77d82007-07-29 21:46:15 -060011789 if (pci_resource_len(pdev, 0) == 0)
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011790 goto release_region;
Matthew Wilcox78e77d82007-07-29 21:46:15 -060011791
11792 ioport = pci_resource_start(pdev, 0);
Matthew Wilcox78e77d82007-07-29 21:46:15 -060011793
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011794 err = -ENOMEM;
11795 shost = scsi_host_alloc(&advansys_template, sizeof(*board));
Matthew Wilcox78e77d82007-07-29 21:46:15 -060011796 if (!shost)
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011797 goto release_region;
11798
Matthew Wilcoxd2411492007-10-02 21:55:31 -040011799 board = shost_priv(shost);
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011800 board->irq = pdev->irq;
11801 board->dev = &pdev->dev;
Hannes Reinecke9c17c622015-04-24 13:18:21 +020011802 board->shost = shost;
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011803
11804 if (pdev->device == PCI_DEVICE_ID_ASP_ABP940UW ||
11805 pdev->device == PCI_DEVICE_ID_38C0800_REV1 ||
11806 pdev->device == PCI_DEVICE_ID_38C1600_REV1) {
11807 board->flags |= ASC_IS_WIDE_BOARD;
11808 }
11809
11810 err = advansys_board_found(shost, ioport, ASC_IS_PCI);
11811 if (err)
11812 goto free_host;
Matthew Wilcox78e77d82007-07-29 21:46:15 -060011813
11814 pci_set_drvdata(pdev, shost);
11815 return 0;
11816
Matthew Wilcoxd361db42007-10-02 21:55:29 -040011817 free_host:
11818 scsi_host_put(shost);
11819 release_region:
Matthew Wilcox71f36112007-07-30 08:04:53 -060011820 pci_release_regions(pdev);
11821 disable_device:
Matthew Wilcox78e77d82007-07-29 21:46:15 -060011822 pci_disable_device(pdev);
11823 fail:
11824 return err;
11825}
11826
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011827static void advansys_pci_remove(struct pci_dev *pdev)
Matthew Wilcox78e77d82007-07-29 21:46:15 -060011828{
11829 advansys_release(pci_get_drvdata(pdev));
Matthew Wilcox71f36112007-07-30 08:04:53 -060011830 pci_release_regions(pdev);
Matthew Wilcox78e77d82007-07-29 21:46:15 -060011831 pci_disable_device(pdev);
11832}
11833
11834static struct pci_driver advansys_pci_driver = {
Matthew Wilcox01fbfe02007-09-09 08:56:40 -060011835 .name = DRV_NAME,
Matthew Wilcox78e77d82007-07-29 21:46:15 -060011836 .id_table = advansys_pci_tbl,
11837 .probe = advansys_pci_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011838 .remove = advansys_pci_remove,
Matthew Wilcox78e77d82007-07-29 21:46:15 -060011839};
Matthew Wilcox8c6af9e2007-07-26 11:03:19 -040011840
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060011841static int __init advansys_init(void)
11842{
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011843 int error;
11844
11845 error = isa_register_driver(&advansys_isa_driver,
11846 ASC_IOADR_TABLE_MAX_IX);
11847 if (error)
11848 goto fail;
11849
11850 error = isa_register_driver(&advansys_vlb_driver,
11851 ASC_IOADR_TABLE_MAX_IX);
11852 if (error)
11853 goto unregister_isa;
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011854
11855 error = eisa_driver_register(&advansys_eisa_driver);
Matthew Wilcox78e77d82007-07-29 21:46:15 -060011856 if (error)
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011857 goto unregister_vlb;
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060011858
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011859 error = pci_register_driver(&advansys_pci_driver);
11860 if (error)
11861 goto unregister_eisa;
11862
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060011863 return 0;
Matthew Wilcox78e77d82007-07-29 21:46:15 -060011864
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011865 unregister_eisa:
11866 eisa_driver_unregister(&advansys_eisa_driver);
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011867 unregister_vlb:
11868 isa_unregister_driver(&advansys_vlb_driver);
11869 unregister_isa:
11870 isa_unregister_driver(&advansys_isa_driver);
Matthew Wilcox78e77d82007-07-29 21:46:15 -060011871 fail:
Matthew Wilcox78e77d82007-07-29 21:46:15 -060011872 return error;
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060011873}
11874
11875static void __exit advansys_exit(void)
11876{
Matthew Wilcox78e77d82007-07-29 21:46:15 -060011877 pci_unregister_driver(&advansys_pci_driver);
Matthew Wilcoxb09e05a2007-07-30 09:14:52 -060011878 eisa_driver_unregister(&advansys_eisa_driver);
Matthew Wilcoxc304ec92007-07-30 09:18:45 -060011879 isa_unregister_driver(&advansys_vlb_driver);
11880 isa_unregister_driver(&advansys_isa_driver);
Matthew Wilcox8dfb5372007-07-30 09:08:34 -060011881}
11882
11883module_init(advansys_init);
11884module_exit(advansys_exit);
11885
Matthew Wilcox8c6af9e2007-07-26 11:03:19 -040011886MODULE_LICENSE("GPL");
Jaswinder Singh Rajput989bb5f2009-04-02 11:28:06 +053011887MODULE_FIRMWARE("advansys/mcode.bin");
11888MODULE_FIRMWARE("advansys/3550.bin");
11889MODULE_FIRMWARE("advansys/38C0800.bin");
11890MODULE_FIRMWARE("advansys/38C1600.bin");