1 #define DRV_NAME "advansys"
2 #define ASC_VERSION "3.4" /* AdvanSys Driver Version */
5 * advansys.c - Linux Host Driver for AdvanSys SCSI Adapters
7 * Copyright (c) 1995-2000 Advanced System Products, Inc.
8 * Copyright (c) 2000-2001 ConnectCom Solutions, Inc.
9 * Copyright (c) 2007 Matthew Wilcox <matthew@wil.cx>
10 * All Rights Reserved.
12 * 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.
19 * As of March 8, 2000 Advanced System Products, Inc. (AdvanSys)
20 * changed its name to ConnectCom Solutions, Inc.
21 * On June 18, 2001 Initio Corp. acquired ConnectCom's SCSI assets
24 #include <linux/module.h>
25 #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>
33 #include <linux/proc_fs.h>
34 #include <linux/init.h>
35 #include <linux/blkdev.h>
36 #include <linux/isa.h>
37 #include <linux/eisa.h>
38 #include <linux/pci.h>
39 #include <linux/spinlock.h>
40 #include <linux/dma-mapping.h>
41 #include <linux/firmware.h>
44 #include <asm/system.h>
47 #include <scsi/scsi_cmnd.h>
48 #include <scsi/scsi_device.h>
49 #include <scsi/scsi_tcq.h>
50 #include <scsi/scsi.h>
51 #include <scsi/scsi_host.h>
55 * 1. Although all of the necessary command mapping places have the
56 * appropriate dma_map.. APIs, the driver still processes its internal
57 * queue using bus_to_virt() and virt_to_bus() which are illegal under
58 * the API. The entire queue processing structure will need to be
59 * altered to fix this.
60 * 2. Need to add memory mapping workaround. Test the memory mapping.
61 * If it doesn't work revert to I/O port access. Can a test be done
63 * 3. Handle an interrupt not working. Keep an interrupt counter in
64 * the interrupt handler. In the timeout function if the interrupt
65 * has not occurred then print a message and run in polled mode.
66 * 4. Need to add support for target mode commands, cf. CAM XPT.
67 * 5. check DMA mapping functions for failure
68 * 6. Use scsi_transport_spi
69 * 7. advansys_info is not safe against multiple simultaneous callers
70 * 8. Add module_param to override ISA/VLB ioport array
72 #warning this driver is still not properly converted to the DMA API
74 /* Enable driver /proc statistics. */
75 #define ADVANSYS_STATS
77 /* Enable driver tracing. */
83 * Any instance where a 32-bit long or pointer type is assumed
84 * for precision or HW defined structures, the following define
85 * types must be used. In Linux the char, short, and int types
86 * are all consistent at 8, 16, and 32 bits respectively. Pointers
87 * and long types are 64 bits on Alpha and UltraSPARC.
89 #define ASC_PADDR __u32 /* Physical/Bus address data type. */
90 #define ASC_VADDR __u32 /* Virtual address data type. */
91 #define ASC_DCNT __u32 /* Unsigned Data count type. */
92 #define ASC_SDCNT __s32 /* Signed Data count type. */
94 typedef unsigned char uchar
;
104 #define UW_ERR (uint)(0xFFFF)
105 #define isodd_word(val) ((((uint)val) & (uint)0x0001) != 0)
107 #define PCI_VENDOR_ID_ASP 0x10cd
108 #define PCI_DEVICE_ID_ASP_1200A 0x1100
109 #define PCI_DEVICE_ID_ASP_ABP940 0x1200
110 #define PCI_DEVICE_ID_ASP_ABP940U 0x1300
111 #define PCI_DEVICE_ID_ASP_ABP940UW 0x2300
112 #define PCI_DEVICE_ID_38C0800_REV1 0x2500
113 #define PCI_DEVICE_ID_38C1600_REV1 0x2700
116 * Enable CC_VERY_LONG_SG_LIST to support up to 64K element SG lists.
117 * The SRB structure will have to be changed and the ASC_SRB2SCSIQ()
118 * macro re-defined to be able to obtain a ASC_SCSI_Q pointer from the
121 #define CC_VERY_LONG_SG_LIST 0
122 #define ASC_SRB2SCSIQ(srb_ptr) (srb_ptr)
124 #define PortAddr unsigned int /* port address size */
125 #define inp(port) inb(port)
126 #define outp(port, byte) outb((byte), (port))
128 #define inpw(port) inw(port)
129 #define outpw(port, word) outw((word), (port))
131 #define ASC_MAX_SG_QUEUE 7
132 #define ASC_MAX_SG_LIST 255
134 #define ASC_CS_TYPE unsigned short
136 #define ASC_IS_ISA (0x0001)
137 #define ASC_IS_ISAPNP (0x0081)
138 #define ASC_IS_EISA (0x0002)
139 #define ASC_IS_PCI (0x0004)
140 #define ASC_IS_PCI_ULTRA (0x0104)
141 #define ASC_IS_PCMCIA (0x0008)
142 #define ASC_IS_MCA (0x0020)
143 #define ASC_IS_VL (0x0040)
144 #define ASC_IS_WIDESCSI_16 (0x0100)
145 #define ASC_IS_WIDESCSI_32 (0x0200)
146 #define ASC_IS_BIG_ENDIAN (0x8000)
148 #define ASC_CHIP_MIN_VER_VL (0x01)
149 #define ASC_CHIP_MAX_VER_VL (0x07)
150 #define ASC_CHIP_MIN_VER_PCI (0x09)
151 #define ASC_CHIP_MAX_VER_PCI (0x0F)
152 #define ASC_CHIP_VER_PCI_BIT (0x08)
153 #define ASC_CHIP_MIN_VER_ISA (0x11)
154 #define ASC_CHIP_MIN_VER_ISA_PNP (0x21)
155 #define ASC_CHIP_MAX_VER_ISA (0x27)
156 #define ASC_CHIP_VER_ISA_BIT (0x30)
157 #define ASC_CHIP_VER_ISAPNP_BIT (0x20)
158 #define ASC_CHIP_VER_ASYN_BUG (0x21)
159 #define ASC_CHIP_VER_PCI 0x08
160 #define ASC_CHIP_VER_PCI_ULTRA_3150 (ASC_CHIP_VER_PCI | 0x02)
161 #define ASC_CHIP_VER_PCI_ULTRA_3050 (ASC_CHIP_VER_PCI | 0x03)
162 #define ASC_CHIP_MIN_VER_EISA (0x41)
163 #define ASC_CHIP_MAX_VER_EISA (0x47)
164 #define ASC_CHIP_VER_EISA_BIT (0x40)
165 #define ASC_CHIP_LATEST_VER_EISA ((ASC_CHIP_MIN_VER_EISA - 1) + 3)
166 #define ASC_MAX_VL_DMA_COUNT (0x07FFFFFFL)
167 #define ASC_MAX_PCI_DMA_COUNT (0xFFFFFFFFL)
168 #define ASC_MAX_ISA_DMA_COUNT (0x00FFFFFFL)
170 #define ASC_SCSI_ID_BITS 3
171 #define ASC_SCSI_TIX_TYPE uchar
172 #define ASC_ALL_DEVICE_BIT_SET 0xFF
173 #define ASC_SCSI_BIT_ID_TYPE uchar
174 #define ASC_MAX_TID 7
175 #define ASC_MAX_LUN 7
176 #define ASC_SCSI_WIDTH_BIT_SET 0xFF
177 #define ASC_MAX_SENSE_LEN 32
178 #define ASC_MIN_SENSE_LEN 14
179 #define ASC_SCSI_RESET_HOLD_TIME_US 60
182 * Narrow boards only support 12-byte commands, while wide boards
183 * extend to 16-byte commands.
185 #define ASC_MAX_CDB_LEN 12
186 #define ADV_MAX_CDB_LEN 16
188 #define MS_SDTR_LEN 0x03
189 #define MS_WDTR_LEN 0x02
191 #define ASC_SG_LIST_PER_Q 7
193 #define QS_READY 0x01
194 #define QS_DISC1 0x02
195 #define QS_DISC2 0x04
197 #define QS_ABORTED 0x40
199 #define QC_NO_CALLBACK 0x01
200 #define QC_SG_SWAP_QUEUE 0x02
201 #define QC_SG_HEAD 0x04
202 #define QC_DATA_IN 0x08
203 #define QC_DATA_OUT 0x10
204 #define QC_URGENT 0x20
205 #define QC_MSG_OUT 0x40
206 #define QC_REQ_SENSE 0x80
207 #define QCSG_SG_XFER_LIST 0x02
208 #define QCSG_SG_XFER_MORE 0x04
209 #define QCSG_SG_XFER_END 0x08
210 #define QD_IN_PROGRESS 0x00
211 #define QD_NO_ERROR 0x01
212 #define QD_ABORTED_BY_HOST 0x02
213 #define QD_WITH_ERROR 0x04
214 #define QD_INVALID_REQUEST 0x80
215 #define QD_INVALID_HOST_NUM 0x81
216 #define QD_INVALID_DEVICE 0x82
217 #define QD_ERR_INTERNAL 0xFF
218 #define QHSTA_NO_ERROR 0x00
219 #define QHSTA_M_SEL_TIMEOUT 0x11
220 #define QHSTA_M_DATA_OVER_RUN 0x12
221 #define QHSTA_M_DATA_UNDER_RUN 0x12
222 #define QHSTA_M_UNEXPECTED_BUS_FREE 0x13
223 #define QHSTA_M_BAD_BUS_PHASE_SEQ 0x14
224 #define QHSTA_D_QDONE_SG_LIST_CORRUPTED 0x21
225 #define QHSTA_D_ASC_DVC_ERROR_CODE_SET 0x22
226 #define QHSTA_D_HOST_ABORT_FAILED 0x23
227 #define QHSTA_D_EXE_SCSI_Q_FAILED 0x24
228 #define QHSTA_D_EXE_SCSI_Q_BUSY_TIMEOUT 0x25
229 #define QHSTA_D_ASPI_NO_BUF_POOL 0x26
230 #define QHSTA_M_WTM_TIMEOUT 0x41
231 #define QHSTA_M_BAD_CMPL_STATUS_IN 0x42
232 #define QHSTA_M_NO_AUTO_REQ_SENSE 0x43
233 #define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
234 #define QHSTA_M_TARGET_STATUS_BUSY 0x45
235 #define QHSTA_M_BAD_TAG_CODE 0x46
236 #define QHSTA_M_BAD_QUEUE_FULL_OR_BUSY 0x47
237 #define QHSTA_M_HUNG_REQ_SCSI_BUS_RESET 0x48
238 #define QHSTA_D_LRAM_CMP_ERROR 0x81
239 #define QHSTA_M_MICRO_CODE_ERROR_HALT 0xA1
240 #define ASC_FLAG_SCSIQ_REQ 0x01
241 #define ASC_FLAG_BIOS_SCSIQ_REQ 0x02
242 #define ASC_FLAG_BIOS_ASYNC_IO 0x04
243 #define ASC_FLAG_SRB_LINEAR_ADDR 0x08
244 #define ASC_FLAG_WIN16 0x10
245 #define ASC_FLAG_WIN32 0x20
246 #define ASC_FLAG_ISA_OVER_16MB 0x40
247 #define ASC_FLAG_DOS_VM_CALLBACK 0x80
248 #define ASC_TAG_FLAG_EXTRA_BYTES 0x10
249 #define ASC_TAG_FLAG_DISABLE_DISCONNECT 0x04
250 #define ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX 0x08
251 #define ASC_TAG_FLAG_DISABLE_CHK_COND_INT_HOST 0x40
252 #define ASC_SCSIQ_CPY_BEG 4
253 #define ASC_SCSIQ_SGHD_CPY_BEG 2
254 #define ASC_SCSIQ_B_FWD 0
255 #define ASC_SCSIQ_B_BWD 1
256 #define ASC_SCSIQ_B_STATUS 2
257 #define ASC_SCSIQ_B_QNO 3
258 #define ASC_SCSIQ_B_CNTL 4
259 #define ASC_SCSIQ_B_SG_QUEUE_CNT 5
260 #define ASC_SCSIQ_D_DATA_ADDR 8
261 #define ASC_SCSIQ_D_DATA_CNT 12
262 #define ASC_SCSIQ_B_SENSE_LEN 20
263 #define ASC_SCSIQ_DONE_INFO_BEG 22
264 #define ASC_SCSIQ_D_SRBPTR 22
265 #define ASC_SCSIQ_B_TARGET_IX 26
266 #define ASC_SCSIQ_B_CDB_LEN 28
267 #define ASC_SCSIQ_B_TAG_CODE 29
268 #define ASC_SCSIQ_W_VM_ID 30
269 #define ASC_SCSIQ_DONE_STATUS 32
270 #define ASC_SCSIQ_HOST_STATUS 33
271 #define ASC_SCSIQ_SCSI_STATUS 34
272 #define ASC_SCSIQ_CDB_BEG 36
273 #define ASC_SCSIQ_DW_REMAIN_XFER_ADDR 56
274 #define ASC_SCSIQ_DW_REMAIN_XFER_CNT 60
275 #define ASC_SCSIQ_B_FIRST_SG_WK_QP 48
276 #define ASC_SCSIQ_B_SG_WK_QP 49
277 #define ASC_SCSIQ_B_SG_WK_IX 50
278 #define ASC_SCSIQ_W_ALT_DC1 52
279 #define ASC_SCSIQ_B_LIST_CNT 6
280 #define ASC_SCSIQ_B_CUR_LIST_CNT 7
281 #define ASC_SGQ_B_SG_CNTL 4
282 #define ASC_SGQ_B_SG_HEAD_QP 5
283 #define ASC_SGQ_B_SG_LIST_CNT 6
284 #define ASC_SGQ_B_SG_CUR_LIST_CNT 7
285 #define ASC_SGQ_LIST_BEG 8
286 #define ASC_DEF_SCSI1_QNG 4
287 #define ASC_MAX_SCSI1_QNG 4
288 #define ASC_DEF_SCSI2_QNG 16
289 #define ASC_MAX_SCSI2_QNG 32
290 #define ASC_TAG_CODE_MASK 0x23
291 #define ASC_STOP_REQ_RISC_STOP 0x01
292 #define ASC_STOP_ACK_RISC_STOP 0x03
293 #define ASC_STOP_CLEAN_UP_BUSY_Q 0x10
294 #define ASC_STOP_CLEAN_UP_DISC_Q 0x20
295 #define ASC_STOP_HOST_REQ_RISC_HALT 0x40
296 #define ASC_TIDLUN_TO_IX(tid, lun) (ASC_SCSI_TIX_TYPE)((tid) + ((lun)<<ASC_SCSI_ID_BITS))
297 #define ASC_TID_TO_TARGET_ID(tid) (ASC_SCSI_BIT_ID_TYPE)(0x01 << (tid))
298 #define ASC_TIX_TO_TARGET_ID(tix) (0x01 << ((tix) & ASC_MAX_TID))
299 #define ASC_TIX_TO_TID(tix) ((tix) & ASC_MAX_TID)
300 #define ASC_TID_TO_TIX(tid) ((tid) & ASC_MAX_TID)
301 #define ASC_TIX_TO_LUN(tix) (((tix) >> ASC_SCSI_ID_BITS) & ASC_MAX_LUN)
302 #define ASC_QNO_TO_QADDR(q_no) ((ASC_QADR_BEG)+((int)(q_no) << 6))
304 typedef struct asc_scsiq_1
{
313 ASC_PADDR sense_addr
;
318 typedef struct asc_scsiq_2
{
327 typedef struct asc_scsiq_3
{
334 typedef struct asc_scsiq_4
{
335 uchar cdb
[ASC_MAX_CDB_LEN
];
336 uchar y_first_sg_list_qp
;
337 uchar y_working_sg_qp
;
338 uchar y_working_sg_ix
;
341 ushort x_reconnect_rtn
;
342 ASC_PADDR x_saved_data_addr
;
343 ASC_DCNT x_saved_data_cnt
;
346 typedef struct asc_q_done_info
{
355 ASC_DCNT remain_bytes
;
358 typedef struct asc_sg_list
{
363 typedef struct asc_sg_head
{
366 ushort entry_to_copy
;
368 ASC_SG_LIST sg_list
[0];
371 typedef struct asc_scsi_q
{
375 ASC_SG_HEAD
*sg_head
;
376 ushort remain_sg_entry_cnt
;
377 ushort next_sg_index
;
380 typedef struct asc_scsi_req_q
{
384 ASC_SG_HEAD
*sg_head
;
387 uchar cdb
[ASC_MAX_CDB_LEN
];
388 uchar sense
[ASC_MIN_SENSE_LEN
];
391 typedef struct asc_scsi_bios_req_q
{
395 ASC_SG_HEAD
*sg_head
;
398 uchar cdb
[ASC_MAX_CDB_LEN
];
399 uchar sense
[ASC_MIN_SENSE_LEN
];
400 } ASC_SCSI_BIOS_REQ_Q
;
402 typedef struct asc_risc_q
{
411 typedef struct asc_sg_list_q
{
417 uchar sg_cur_list_cnt
;
420 typedef struct asc_risc_sg_list_q
{
424 ASC_SG_LIST sg_list
[7];
425 } ASC_RISC_SG_LIST_Q
;
427 #define ASCQ_ERR_Q_STATUS 0x0D
428 #define ASCQ_ERR_CUR_QNG 0x17
429 #define ASCQ_ERR_SG_Q_LINKS 0x18
430 #define ASCQ_ERR_ISR_RE_ENTRY 0x1A
431 #define ASCQ_ERR_CRITICAL_RE_ENTRY 0x1B
432 #define ASCQ_ERR_ISR_ON_CRITICAL 0x1C
435 * Warning code values are set in ASC_DVC_VAR 'warn_code'.
437 #define ASC_WARN_NO_ERROR 0x0000
438 #define ASC_WARN_IO_PORT_ROTATE 0x0001
439 #define ASC_WARN_EEPROM_CHKSUM 0x0002
440 #define ASC_WARN_IRQ_MODIFIED 0x0004
441 #define ASC_WARN_AUTO_CONFIG 0x0008
442 #define ASC_WARN_CMD_QNG_CONFLICT 0x0010
443 #define ASC_WARN_EEPROM_RECOVER 0x0020
444 #define ASC_WARN_CFG_MSW_RECOVER 0x0040
447 * Error code values are set in {ASC/ADV}_DVC_VAR 'err_code'.
449 #define ASC_IERR_NO_CARRIER 0x0001 /* No more carrier memory */
450 #define ASC_IERR_MCODE_CHKSUM 0x0002 /* micro code check sum error */
451 #define ASC_IERR_SET_PC_ADDR 0x0004
452 #define ASC_IERR_START_STOP_CHIP 0x0008 /* start/stop chip failed */
453 #define ASC_IERR_ILLEGAL_CONNECTION 0x0010 /* Illegal cable connection */
454 #define ASC_IERR_SINGLE_END_DEVICE 0x0020 /* SE device on DIFF bus */
455 #define ASC_IERR_REVERSED_CABLE 0x0040 /* Narrow flat cable reversed */
456 #define ASC_IERR_SET_SCSI_ID 0x0080 /* set SCSI ID failed */
457 #define ASC_IERR_HVD_DEVICE 0x0100 /* HVD device on LVD port */
458 #define ASC_IERR_BAD_SIGNATURE 0x0200 /* signature not found */
459 #define ASC_IERR_NO_BUS_TYPE 0x0400
460 #define ASC_IERR_BIST_PRE_TEST 0x0800 /* BIST pre-test error */
461 #define ASC_IERR_BIST_RAM_TEST 0x1000 /* BIST RAM test error */
462 #define ASC_IERR_BAD_CHIPTYPE 0x2000 /* Invalid chip_type setting */
464 #define ASC_DEF_MAX_TOTAL_QNG (0xF0)
465 #define ASC_MIN_TAG_Q_PER_DVC (0x04)
466 #define ASC_MIN_FREE_Q (0x02)
467 #define ASC_MIN_TOTAL_QNG ((ASC_MAX_SG_QUEUE)+(ASC_MIN_FREE_Q))
468 #define ASC_MAX_TOTAL_QNG 240
469 #define ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG 16
470 #define ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG 8
471 #define ASC_MAX_PCI_INRAM_TOTAL_QNG 20
472 #define ASC_MAX_INRAM_TAG_QNG 16
473 #define ASC_IOADR_GAP 0x10
474 #define ASC_SYN_MAX_OFFSET 0x0F
475 #define ASC_DEF_SDTR_OFFSET 0x0F
476 #define ASC_SDTR_ULTRA_PCI_10MB_INDEX 0x02
477 #define ASYN_SDTR_DATA_FIX_PCI_REV_AB 0x41
479 /* The narrow chip only supports a limited selection of transfer rates.
480 * These are encoded in the range 0..7 or 0..15 depending whether the chip
481 * is Ultra-capable or not. These tables let us convert from one to the other.
483 static const unsigned char asc_syn_xfer_period
[8] = {
484 25, 30, 35, 40, 50, 60, 70, 85
487 static const unsigned char asc_syn_ultra_xfer_period
[16] = {
488 12, 19, 25, 32, 38, 44, 50, 57, 63, 69, 75, 82, 88, 94, 100, 107
491 typedef struct ext_msg
{
497 uchar sdtr_xfer_period
;
498 uchar sdtr_req_ack_offset
;
513 #define xfer_period u_ext_msg.sdtr.sdtr_xfer_period
514 #define req_ack_offset u_ext_msg.sdtr.sdtr_req_ack_offset
515 #define wdtr_width u_ext_msg.wdtr.wdtr_width
516 #define mdp_b3 u_ext_msg.mdp_b3
517 #define mdp_b2 u_ext_msg.mdp_b2
518 #define mdp_b1 u_ext_msg.mdp_b1
519 #define mdp_b0 u_ext_msg.mdp_b0
521 typedef struct asc_dvc_cfg
{
522 ASC_SCSI_BIT_ID_TYPE can_tagged_qng
;
523 ASC_SCSI_BIT_ID_TYPE cmd_qng_enabled
;
524 ASC_SCSI_BIT_ID_TYPE disc_enable
;
525 ASC_SCSI_BIT_ID_TYPE sdtr_enable
;
528 uchar isa_dma_channel
;
531 ushort mcode_version
;
532 uchar max_tag_qng
[ASC_MAX_TID
+ 1];
533 uchar sdtr_period_offset
[ASC_MAX_TID
+ 1];
534 uchar adapter_info
[6];
537 #define ASC_DEF_DVC_CNTL 0xFFFF
538 #define ASC_DEF_CHIP_SCSI_ID 7
539 #define ASC_DEF_ISA_DMA_SPEED 4
540 #define ASC_INIT_STATE_BEG_GET_CFG 0x0001
541 #define ASC_INIT_STATE_END_GET_CFG 0x0002
542 #define ASC_INIT_STATE_BEG_SET_CFG 0x0004
543 #define ASC_INIT_STATE_END_SET_CFG 0x0008
544 #define ASC_INIT_STATE_BEG_LOAD_MC 0x0010
545 #define ASC_INIT_STATE_END_LOAD_MC 0x0020
546 #define ASC_INIT_STATE_BEG_INQUIRY 0x0040
547 #define ASC_INIT_STATE_END_INQUIRY 0x0080
548 #define ASC_INIT_RESET_SCSI_DONE 0x0100
549 #define ASC_INIT_STATE_WITHOUT_EEP 0x8000
550 #define ASC_BUG_FIX_IF_NOT_DWB 0x0001
551 #define ASC_BUG_FIX_ASYN_USE_SYN 0x0002
552 #define ASC_MIN_TAGGED_CMD 7
553 #define ASC_MAX_SCSI_RESET_WAIT 30
554 #define ASC_OVERRUN_BSIZE 64
556 struct asc_dvc_var
; /* Forward Declaration. */
558 typedef struct asc_dvc_var
{
564 ASC_SCSI_BIT_ID_TYPE init_sdtr
;
565 ASC_SCSI_BIT_ID_TYPE sdtr_done
;
566 ASC_SCSI_BIT_ID_TYPE use_tagged_qng
;
567 ASC_SCSI_BIT_ID_TYPE unit_not_ready
;
568 ASC_SCSI_BIT_ID_TYPE queue_full_or_busy
;
569 ASC_SCSI_BIT_ID_TYPE start_motor
;
571 dma_addr_t overrun_dma
;
572 uchar scsi_reset_wait
;
577 uchar in_critical_cnt
;
578 uchar last_q_shortage
;
580 uchar cur_dvc_qng
[ASC_MAX_TID
+ 1];
581 uchar max_dvc_qng
[ASC_MAX_TID
+ 1];
582 ASC_SCSI_Q
*scsiq_busy_head
[ASC_MAX_TID
+ 1];
583 ASC_SCSI_Q
*scsiq_busy_tail
[ASC_MAX_TID
+ 1];
584 const uchar
*sdtr_period_tbl
;
586 ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer_always
;
589 uchar dos_int13_table
[ASC_MAX_TID
+ 1];
590 ASC_DCNT max_dma_count
;
591 ASC_SCSI_BIT_ID_TYPE no_scam
;
592 ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer
;
593 uchar min_sdtr_index
;
594 uchar max_sdtr_index
;
595 struct asc_board
*drv_ptr
;
601 typedef struct asc_dvc_inq_info
{
602 uchar type
[ASC_MAX_TID
+ 1][ASC_MAX_LUN
+ 1];
605 typedef struct asc_cap_info
{
610 typedef struct asc_cap_info_array
{
611 ASC_CAP_INFO cap_info
[ASC_MAX_TID
+ 1][ASC_MAX_LUN
+ 1];
612 } ASC_CAP_INFO_ARRAY
;
614 #define ASC_MCNTL_NO_SEL_TIMEOUT (ushort)0x0001
615 #define ASC_MCNTL_NULL_TARGET (ushort)0x0002
616 #define ASC_CNTL_INITIATOR (ushort)0x0001
617 #define ASC_CNTL_BIOS_GT_1GB (ushort)0x0002
618 #define ASC_CNTL_BIOS_GT_2_DISK (ushort)0x0004
619 #define ASC_CNTL_BIOS_REMOVABLE (ushort)0x0008
620 #define ASC_CNTL_NO_SCAM (ushort)0x0010
621 #define ASC_CNTL_INT_MULTI_Q (ushort)0x0080
622 #define ASC_CNTL_NO_LUN_SUPPORT (ushort)0x0040
623 #define ASC_CNTL_NO_VERIFY_COPY (ushort)0x0100
624 #define ASC_CNTL_RESET_SCSI (ushort)0x0200
625 #define ASC_CNTL_INIT_INQUIRY (ushort)0x0400
626 #define ASC_CNTL_INIT_VERBOSE (ushort)0x0800
627 #define ASC_CNTL_SCSI_PARITY (ushort)0x1000
628 #define ASC_CNTL_BURST_MODE (ushort)0x2000
629 #define ASC_CNTL_SDTR_ENABLE_ULTRA (ushort)0x4000
630 #define ASC_EEP_DVC_CFG_BEG_VL 2
631 #define ASC_EEP_MAX_DVC_ADDR_VL 15
632 #define ASC_EEP_DVC_CFG_BEG 32
633 #define ASC_EEP_MAX_DVC_ADDR 45
634 #define ASC_EEP_MAX_RETRY 20
637 * These macros keep the chip SCSI id and ISA DMA speed
638 * bitfields in board order. C bitfields aren't portable
639 * between big and little-endian platforms so they are
643 #define ASC_EEP_GET_CHIP_ID(cfg) ((cfg)->id_speed & 0x0f)
644 #define ASC_EEP_GET_DMA_SPD(cfg) (((cfg)->id_speed & 0xf0) >> 4)
645 #define ASC_EEP_SET_CHIP_ID(cfg, sid) \
646 ((cfg)->id_speed = ((cfg)->id_speed & 0xf0) | ((sid) & ASC_MAX_TID))
647 #define ASC_EEP_SET_DMA_SPD(cfg, spd) \
648 ((cfg)->id_speed = ((cfg)->id_speed & 0x0f) | ((spd) & 0x0f) << 4)
650 typedef struct asceep_config
{
662 uchar id_speed
; /* low order 4 bits is chip scsi id */
663 /* high order 4 bits is isa dma speed */
664 uchar dos_int13_table
[ASC_MAX_TID
+ 1];
665 uchar adapter_info
[6];
670 #define ASC_EEP_CMD_READ 0x80
671 #define ASC_EEP_CMD_WRITE 0x40
672 #define ASC_EEP_CMD_WRITE_ABLE 0x30
673 #define ASC_EEP_CMD_WRITE_DISABLE 0x00
674 #define ASCV_MSGOUT_BEG 0x0000
675 #define ASCV_MSGOUT_SDTR_PERIOD (ASCV_MSGOUT_BEG+3)
676 #define ASCV_MSGOUT_SDTR_OFFSET (ASCV_MSGOUT_BEG+4)
677 #define ASCV_BREAK_SAVED_CODE (ushort)0x0006
678 #define ASCV_MSGIN_BEG (ASCV_MSGOUT_BEG+8)
679 #define ASCV_MSGIN_SDTR_PERIOD (ASCV_MSGIN_BEG+3)
680 #define ASCV_MSGIN_SDTR_OFFSET (ASCV_MSGIN_BEG+4)
681 #define ASCV_SDTR_DATA_BEG (ASCV_MSGIN_BEG+8)
682 #define ASCV_SDTR_DONE_BEG (ASCV_SDTR_DATA_BEG+8)
683 #define ASCV_MAX_DVC_QNG_BEG (ushort)0x0020
684 #define ASCV_BREAK_ADDR (ushort)0x0028
685 #define ASCV_BREAK_NOTIFY_COUNT (ushort)0x002A
686 #define ASCV_BREAK_CONTROL (ushort)0x002C
687 #define ASCV_BREAK_HIT_COUNT (ushort)0x002E
689 #define ASCV_ASCDVC_ERR_CODE_W (ushort)0x0030
690 #define ASCV_MCODE_CHKSUM_W (ushort)0x0032
691 #define ASCV_MCODE_SIZE_W (ushort)0x0034
692 #define ASCV_STOP_CODE_B (ushort)0x0036
693 #define ASCV_DVC_ERR_CODE_B (ushort)0x0037
694 #define ASCV_OVERRUN_PADDR_D (ushort)0x0038
695 #define ASCV_OVERRUN_BSIZE_D (ushort)0x003C
696 #define ASCV_HALTCODE_W (ushort)0x0040
697 #define ASCV_CHKSUM_W (ushort)0x0042
698 #define ASCV_MC_DATE_W (ushort)0x0044
699 #define ASCV_MC_VER_W (ushort)0x0046
700 #define ASCV_NEXTRDY_B (ushort)0x0048
701 #define ASCV_DONENEXT_B (ushort)0x0049
702 #define ASCV_USE_TAGGED_QNG_B (ushort)0x004A
703 #define ASCV_SCSIBUSY_B (ushort)0x004B
704 #define ASCV_Q_DONE_IN_PROGRESS_B (ushort)0x004C
705 #define ASCV_CURCDB_B (ushort)0x004D
706 #define ASCV_RCLUN_B (ushort)0x004E
707 #define ASCV_BUSY_QHEAD_B (ushort)0x004F
708 #define ASCV_DISC1_QHEAD_B (ushort)0x0050
709 #define ASCV_DISC_ENABLE_B (ushort)0x0052
710 #define ASCV_CAN_TAGGED_QNG_B (ushort)0x0053
711 #define ASCV_HOSTSCSI_ID_B (ushort)0x0055
712 #define ASCV_MCODE_CNTL_B (ushort)0x0056
713 #define ASCV_NULL_TARGET_B (ushort)0x0057
714 #define ASCV_FREE_Q_HEAD_W (ushort)0x0058
715 #define ASCV_DONE_Q_TAIL_W (ushort)0x005A
716 #define ASCV_FREE_Q_HEAD_B (ushort)(ASCV_FREE_Q_HEAD_W+1)
717 #define ASCV_DONE_Q_TAIL_B (ushort)(ASCV_DONE_Q_TAIL_W+1)
718 #define ASCV_HOST_FLAG_B (ushort)0x005D
719 #define ASCV_TOTAL_READY_Q_B (ushort)0x0064
720 #define ASCV_VER_SERIAL_B (ushort)0x0065
721 #define ASCV_HALTCODE_SAVED_W (ushort)0x0066
722 #define ASCV_WTM_FLAG_B (ushort)0x0068
723 #define ASCV_RISC_FLAG_B (ushort)0x006A
724 #define ASCV_REQ_SG_LIST_QP (ushort)0x006B
725 #define ASC_HOST_FLAG_IN_ISR 0x01
726 #define ASC_HOST_FLAG_ACK_INT 0x02
727 #define ASC_RISC_FLAG_GEN_INT 0x01
728 #define ASC_RISC_FLAG_REQ_SG_LIST 0x02
729 #define IOP_CTRL (0x0F)
730 #define IOP_STATUS (0x0E)
731 #define IOP_INT_ACK IOP_STATUS
732 #define IOP_REG_IFC (0x0D)
733 #define IOP_SYN_OFFSET (0x0B)
734 #define IOP_EXTRA_CONTROL (0x0D)
735 #define IOP_REG_PC (0x0C)
736 #define IOP_RAM_ADDR (0x0A)
737 #define IOP_RAM_DATA (0x08)
738 #define IOP_EEP_DATA (0x06)
739 #define IOP_EEP_CMD (0x07)
740 #define IOP_VERSION (0x03)
741 #define IOP_CONFIG_HIGH (0x04)
742 #define IOP_CONFIG_LOW (0x02)
743 #define IOP_SIG_BYTE (0x01)
744 #define IOP_SIG_WORD (0x00)
745 #define IOP_REG_DC1 (0x0E)
746 #define IOP_REG_DC0 (0x0C)
747 #define IOP_REG_SB (0x0B)
748 #define IOP_REG_DA1 (0x0A)
749 #define IOP_REG_DA0 (0x08)
750 #define IOP_REG_SC (0x09)
751 #define IOP_DMA_SPEED (0x07)
752 #define IOP_REG_FLAG (0x07)
753 #define IOP_FIFO_H (0x06)
754 #define IOP_FIFO_L (0x04)
755 #define IOP_REG_ID (0x05)
756 #define IOP_REG_QP (0x03)
757 #define IOP_REG_IH (0x02)
758 #define IOP_REG_IX (0x01)
759 #define IOP_REG_AX (0x00)
760 #define IFC_REG_LOCK (0x00)
761 #define IFC_REG_UNLOCK (0x09)
762 #define IFC_WR_EN_FILTER (0x10)
763 #define IFC_RD_NO_EEPROM (0x10)
764 #define IFC_SLEW_RATE (0x20)
765 #define IFC_ACT_NEG (0x40)
766 #define IFC_INP_FILTER (0x80)
767 #define IFC_INIT_DEFAULT (IFC_ACT_NEG | IFC_REG_UNLOCK)
768 #define SC_SEL (uchar)(0x80)
769 #define SC_BSY (uchar)(0x40)
770 #define SC_ACK (uchar)(0x20)
771 #define SC_REQ (uchar)(0x10)
772 #define SC_ATN (uchar)(0x08)
773 #define SC_IO (uchar)(0x04)
774 #define SC_CD (uchar)(0x02)
775 #define SC_MSG (uchar)(0x01)
776 #define SEC_SCSI_CTL (uchar)(0x80)
777 #define SEC_ACTIVE_NEGATE (uchar)(0x40)
778 #define SEC_SLEW_RATE (uchar)(0x20)
779 #define SEC_ENABLE_FILTER (uchar)(0x10)
780 #define ASC_HALT_EXTMSG_IN (ushort)0x8000
781 #define ASC_HALT_CHK_CONDITION (ushort)0x8100
782 #define ASC_HALT_SS_QUEUE_FULL (ushort)0x8200
783 #define ASC_HALT_DISABLE_ASYN_USE_SYN_FIX (ushort)0x8300
784 #define ASC_HALT_ENABLE_ASYN_USE_SYN_FIX (ushort)0x8400
785 #define ASC_HALT_SDTR_REJECTED (ushort)0x4000
786 #define ASC_HALT_HOST_COPY_SG_LIST_TO_RISC ( ushort )0x2000
787 #define ASC_MAX_QNO 0xF8
788 #define ASC_DATA_SEC_BEG (ushort)0x0080
789 #define ASC_DATA_SEC_END (ushort)0x0080
790 #define ASC_CODE_SEC_BEG (ushort)0x0080
791 #define ASC_CODE_SEC_END (ushort)0x0080
792 #define ASC_QADR_BEG (0x4000)
793 #define ASC_QADR_USED (ushort)(ASC_MAX_QNO * 64)
794 #define ASC_QADR_END (ushort)0x7FFF
795 #define ASC_QLAST_ADR (ushort)0x7FC0
796 #define ASC_QBLK_SIZE 0x40
797 #define ASC_BIOS_DATA_QBEG 0xF8
798 #define ASC_MIN_ACTIVE_QNO 0x01
799 #define ASC_QLINK_END 0xFF
800 #define ASC_EEPROM_WORDS 0x10
801 #define ASC_MAX_MGS_LEN 0x10
802 #define ASC_BIOS_ADDR_DEF 0xDC00
803 #define ASC_BIOS_SIZE 0x3800
804 #define ASC_BIOS_RAM_OFF 0x3800
805 #define ASC_BIOS_RAM_SIZE 0x800
806 #define ASC_BIOS_MIN_ADDR 0xC000
807 #define ASC_BIOS_MAX_ADDR 0xEC00
808 #define ASC_BIOS_BANK_SIZE 0x0400
809 #define ASC_MCODE_START_ADDR 0x0080
810 #define ASC_CFG0_HOST_INT_ON 0x0020
811 #define ASC_CFG0_BIOS_ON 0x0040
812 #define ASC_CFG0_VERA_BURST_ON 0x0080
813 #define ASC_CFG0_SCSI_PARITY_ON 0x0800
814 #define ASC_CFG1_SCSI_TARGET_ON 0x0080
815 #define ASC_CFG1_LRAM_8BITS_ON 0x0800
816 #define ASC_CFG_MSW_CLR_MASK 0x3080
817 #define CSW_TEST1 (ASC_CS_TYPE)0x8000
818 #define CSW_AUTO_CONFIG (ASC_CS_TYPE)0x4000
819 #define CSW_RESERVED1 (ASC_CS_TYPE)0x2000
820 #define CSW_IRQ_WRITTEN (ASC_CS_TYPE)0x1000
821 #define CSW_33MHZ_SELECTED (ASC_CS_TYPE)0x0800
822 #define CSW_TEST2 (ASC_CS_TYPE)0x0400
823 #define CSW_TEST3 (ASC_CS_TYPE)0x0200
824 #define CSW_RESERVED2 (ASC_CS_TYPE)0x0100
825 #define CSW_DMA_DONE (ASC_CS_TYPE)0x0080
826 #define CSW_FIFO_RDY (ASC_CS_TYPE)0x0040
827 #define CSW_EEP_READ_DONE (ASC_CS_TYPE)0x0020
828 #define CSW_HALTED (ASC_CS_TYPE)0x0010
829 #define CSW_SCSI_RESET_ACTIVE (ASC_CS_TYPE)0x0008
830 #define CSW_PARITY_ERR (ASC_CS_TYPE)0x0004
831 #define CSW_SCSI_RESET_LATCH (ASC_CS_TYPE)0x0002
832 #define CSW_INT_PENDING (ASC_CS_TYPE)0x0001
833 #define CIW_CLR_SCSI_RESET_INT (ASC_CS_TYPE)0x1000
834 #define CIW_INT_ACK (ASC_CS_TYPE)0x0100
835 #define CIW_TEST1 (ASC_CS_TYPE)0x0200
836 #define CIW_TEST2 (ASC_CS_TYPE)0x0400
837 #define CIW_SEL_33MHZ (ASC_CS_TYPE)0x0800
838 #define CIW_IRQ_ACT (ASC_CS_TYPE)0x1000
839 #define CC_CHIP_RESET (uchar)0x80
840 #define CC_SCSI_RESET (uchar)0x40
841 #define CC_HALT (uchar)0x20
842 #define CC_SINGLE_STEP (uchar)0x10
843 #define CC_DMA_ABLE (uchar)0x08
844 #define CC_TEST (uchar)0x04
845 #define CC_BANK_ONE (uchar)0x02
846 #define CC_DIAG (uchar)0x01
847 #define ASC_1000_ID0W 0x04C1
848 #define ASC_1000_ID0W_FIX 0x00C1
849 #define ASC_1000_ID1B 0x25
850 #define ASC_EISA_REV_IOP_MASK (0x0C83)
851 #define ASC_EISA_CFG_IOP_MASK (0x0C86)
852 #define ASC_GET_EISA_SLOT(iop) (PortAddr)((iop) & 0xF000)
853 #define INS_HALTINT (ushort)0x6281
854 #define INS_HALT (ushort)0x6280
855 #define INS_SINT (ushort)0x6200
856 #define INS_RFLAG_WTM (ushort)0x7380
857 #define ASC_MC_SAVE_CODE_WSIZE 0x500
858 #define ASC_MC_SAVE_DATA_WSIZE 0x40
860 typedef struct asc_mc_saved
{
861 ushort data
[ASC_MC_SAVE_DATA_WSIZE
];
862 ushort code
[ASC_MC_SAVE_CODE_WSIZE
];
865 #define AscGetQDoneInProgress(port) AscReadLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B)
866 #define AscPutQDoneInProgress(port, val) AscWriteLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B, val)
867 #define AscGetVarFreeQHead(port) AscReadLramWord((port), ASCV_FREE_Q_HEAD_W)
868 #define AscGetVarDoneQTail(port) AscReadLramWord((port), ASCV_DONE_Q_TAIL_W)
869 #define AscPutVarFreeQHead(port, val) AscWriteLramWord((port), ASCV_FREE_Q_HEAD_W, val)
870 #define AscPutVarDoneQTail(port, val) AscWriteLramWord((port), ASCV_DONE_Q_TAIL_W, val)
871 #define AscGetRiscVarFreeQHead(port) AscReadLramByte((port), ASCV_NEXTRDY_B)
872 #define AscGetRiscVarDoneQTail(port) AscReadLramByte((port), ASCV_DONENEXT_B)
873 #define AscPutRiscVarFreeQHead(port, val) AscWriteLramByte((port), ASCV_NEXTRDY_B, val)
874 #define AscPutRiscVarDoneQTail(port, val) AscWriteLramByte((port), ASCV_DONENEXT_B, val)
875 #define AscPutMCodeSDTRDoneAtID(port, id, data) AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id), (data))
876 #define AscGetMCodeSDTRDoneAtID(port, id) AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id))
877 #define AscPutMCodeInitSDTRAtID(port, id, data) AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id), data)
878 #define AscGetMCodeInitSDTRAtID(port, id) AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id))
879 #define AscGetChipSignatureByte(port) (uchar)inp((port)+IOP_SIG_BYTE)
880 #define AscGetChipSignatureWord(port) (ushort)inpw((port)+IOP_SIG_WORD)
881 #define AscGetChipVerNo(port) (uchar)inp((port)+IOP_VERSION)
882 #define AscGetChipCfgLsw(port) (ushort)inpw((port)+IOP_CONFIG_LOW)
883 #define AscGetChipCfgMsw(port) (ushort)inpw((port)+IOP_CONFIG_HIGH)
884 #define AscSetChipCfgLsw(port, data) outpw((port)+IOP_CONFIG_LOW, data)
885 #define AscSetChipCfgMsw(port, data) outpw((port)+IOP_CONFIG_HIGH, data)
886 #define AscGetChipEEPCmd(port) (uchar)inp((port)+IOP_EEP_CMD)
887 #define AscSetChipEEPCmd(port, data) outp((port)+IOP_EEP_CMD, data)
888 #define AscGetChipEEPData(port) (ushort)inpw((port)+IOP_EEP_DATA)
889 #define AscSetChipEEPData(port, data) outpw((port)+IOP_EEP_DATA, data)
890 #define AscGetChipLramAddr(port) (ushort)inpw((PortAddr)((port)+IOP_RAM_ADDR))
891 #define AscSetChipLramAddr(port, addr) outpw((PortAddr)((port)+IOP_RAM_ADDR), addr)
892 #define AscGetChipLramData(port) (ushort)inpw((port)+IOP_RAM_DATA)
893 #define AscSetChipLramData(port, data) outpw((port)+IOP_RAM_DATA, data)
894 #define AscGetChipIFC(port) (uchar)inp((port)+IOP_REG_IFC)
895 #define AscSetChipIFC(port, data) outp((port)+IOP_REG_IFC, data)
896 #define AscGetChipStatus(port) (ASC_CS_TYPE)inpw((port)+IOP_STATUS)
897 #define AscSetChipStatus(port, cs_val) outpw((port)+IOP_STATUS, cs_val)
898 #define AscGetChipControl(port) (uchar)inp((port)+IOP_CTRL)
899 #define AscSetChipControl(port, cc_val) outp((port)+IOP_CTRL, cc_val)
900 #define AscGetChipSyn(port) (uchar)inp((port)+IOP_SYN_OFFSET)
901 #define AscSetChipSyn(port, data) outp((port)+IOP_SYN_OFFSET, data)
902 #define AscSetPCAddr(port, data) outpw((port)+IOP_REG_PC, data)
903 #define AscGetPCAddr(port) (ushort)inpw((port)+IOP_REG_PC)
904 #define AscIsIntPending(port) (AscGetChipStatus(port) & (CSW_INT_PENDING | CSW_SCSI_RESET_LATCH))
905 #define AscGetChipScsiID(port) ((AscGetChipCfgLsw(port) >> 8) & ASC_MAX_TID)
906 #define AscGetExtraControl(port) (uchar)inp((port)+IOP_EXTRA_CONTROL)
907 #define AscSetExtraControl(port, data) outp((port)+IOP_EXTRA_CONTROL, data)
908 #define AscReadChipAX(port) (ushort)inpw((port)+IOP_REG_AX)
909 #define AscWriteChipAX(port, data) outpw((port)+IOP_REG_AX, data)
910 #define AscReadChipIX(port) (uchar)inp((port)+IOP_REG_IX)
911 #define AscWriteChipIX(port, data) outp((port)+IOP_REG_IX, data)
912 #define AscReadChipIH(port) (ushort)inpw((port)+IOP_REG_IH)
913 #define AscWriteChipIH(port, data) outpw((port)+IOP_REG_IH, data)
914 #define AscReadChipQP(port) (uchar)inp((port)+IOP_REG_QP)
915 #define AscWriteChipQP(port, data) outp((port)+IOP_REG_QP, data)
916 #define AscReadChipFIFO_L(port) (ushort)inpw((port)+IOP_REG_FIFO_L)
917 #define AscWriteChipFIFO_L(port, data) outpw((port)+IOP_REG_FIFO_L, data)
918 #define AscReadChipFIFO_H(port) (ushort)inpw((port)+IOP_REG_FIFO_H)
919 #define AscWriteChipFIFO_H(port, data) outpw((port)+IOP_REG_FIFO_H, data)
920 #define AscReadChipDmaSpeed(port) (uchar)inp((port)+IOP_DMA_SPEED)
921 #define AscWriteChipDmaSpeed(port, data) outp((port)+IOP_DMA_SPEED, data)
922 #define AscReadChipDA0(port) (ushort)inpw((port)+IOP_REG_DA0)
923 #define AscWriteChipDA0(port) outpw((port)+IOP_REG_DA0, data)
924 #define AscReadChipDA1(port) (ushort)inpw((port)+IOP_REG_DA1)
925 #define AscWriteChipDA1(port) outpw((port)+IOP_REG_DA1, data)
926 #define AscReadChipDC0(port) (ushort)inpw((port)+IOP_REG_DC0)
927 #define AscWriteChipDC0(port) outpw((port)+IOP_REG_DC0, data)
928 #define AscReadChipDC1(port) (ushort)inpw((port)+IOP_REG_DC1)
929 #define AscWriteChipDC1(port) outpw((port)+IOP_REG_DC1, data)
930 #define AscReadChipDvcID(port) (uchar)inp((port)+IOP_REG_ID)
931 #define AscWriteChipDvcID(port, data) outp((port)+IOP_REG_ID, data)
934 * Portable Data Types
936 * Any instance where a 32-bit long or pointer type is assumed
937 * for precision or HW defined structures, the following define
938 * types must be used. In Linux the char, short, and int types
939 * are all consistent at 8, 16, and 32 bits respectively. Pointers
940 * and long types are 64 bits on Alpha and UltraSPARC.
942 #define ADV_PADDR __u32 /* Physical address data type. */
943 #define ADV_VADDR __u32 /* Virtual address data type. */
944 #define ADV_DCNT __u32 /* Unsigned Data count type. */
945 #define ADV_SDCNT __s32 /* Signed Data count type. */
948 * These macros are used to convert a virtual address to a
949 * 32-bit value. This currently can be used on Linux Alpha
950 * which uses 64-bit virtual address but a 32-bit bus address.
951 * This is likely to break in the future, but doing this now
952 * will give us time to change the HW and FW to handle 64-bit
955 #define ADV_VADDR_TO_U32 virt_to_bus
956 #define ADV_U32_TO_VADDR bus_to_virt
958 #define AdvPortAddr void __iomem * /* Virtual memory address size */
961 * Define Adv Library required memory access macros.
963 #define ADV_MEM_READB(addr) readb(addr)
964 #define ADV_MEM_READW(addr) readw(addr)
965 #define ADV_MEM_WRITEB(addr, byte) writeb(byte, addr)
966 #define ADV_MEM_WRITEW(addr, word) writew(word, addr)
967 #define ADV_MEM_WRITEDW(addr, dword) writel(dword, addr)
969 #define ADV_CARRIER_COUNT (ASC_DEF_MAX_HOST_QNG + 15)
972 * Define total number of simultaneous maximum element scatter-gather
973 * request blocks per wide adapter. ASC_DEF_MAX_HOST_QNG (253) is the
974 * maximum number of outstanding commands per wide host adapter. Each
975 * command uses one or more ADV_SG_BLOCK each with 15 scatter-gather
976 * elements. Allow each command to have at least one ADV_SG_BLOCK structure.
977 * This allows about 15 commands to have the maximum 17 ADV_SG_BLOCK
978 * structures or 255 scatter-gather elements.
980 #define ADV_TOT_SG_BLOCK ASC_DEF_MAX_HOST_QNG
983 * Define maximum number of scatter-gather elements per request.
985 #define ADV_MAX_SG_LIST 255
986 #define NO_OF_SG_PER_BLOCK 15
988 #define ADV_EEP_DVC_CFG_BEGIN (0x00)
989 #define ADV_EEP_DVC_CFG_END (0x15)
990 #define ADV_EEP_DVC_CTL_BEGIN (0x16) /* location of OEM name */
991 #define ADV_EEP_MAX_WORD_ADDR (0x1E)
993 #define ADV_EEP_DELAY_MS 100
995 #define ADV_EEPROM_BIG_ENDIAN 0x8000 /* EEPROM Bit 15 */
996 #define ADV_EEPROM_BIOS_ENABLE 0x4000 /* EEPROM Bit 14 */
998 * For the ASC3550 Bit 13 is Termination Polarity control bit.
999 * For later ICs Bit 13 controls whether the CIS (Card Information
1000 * Service Section) is loaded from EEPROM.
1002 #define ADV_EEPROM_TERM_POL 0x2000 /* EEPROM Bit 13 */
1003 #define ADV_EEPROM_CIS_LD 0x2000 /* EEPROM Bit 13 */
1007 * If EEPROM Bit 11 is 0 for Function 0, then Function 0 will specify
1008 * INT A in the PCI Configuration Space Int Pin field. If it is 1, then
1009 * Function 0 will specify INT B.
1011 * If EEPROM Bit 11 is 0 for Function 1, then Function 1 will specify
1012 * INT B in the PCI Configuration Space Int Pin field. If it is 1, then
1013 * Function 1 will specify INT A.
1015 #define ADV_EEPROM_INTAB 0x0800 /* EEPROM Bit 11 */
1017 typedef struct adveep_3550_config
{
1018 /* Word Offset, Description */
1020 ushort cfg_lsw
; /* 00 power up initialization */
1021 /* bit 13 set - Term Polarity Control */
1022 /* bit 14 set - BIOS Enable */
1023 /* bit 15 set - Big Endian Mode */
1024 ushort cfg_msw
; /* 01 unused */
1025 ushort disc_enable
; /* 02 disconnect enable */
1026 ushort wdtr_able
; /* 03 Wide DTR able */
1027 ushort sdtr_able
; /* 04 Synchronous DTR able */
1028 ushort start_motor
; /* 05 send start up motor */
1029 ushort tagqng_able
; /* 06 tag queuing able */
1030 ushort bios_scan
; /* 07 BIOS device control */
1031 ushort scam_tolerant
; /* 08 no scam */
1033 uchar adapter_scsi_id
; /* 09 Host Adapter ID */
1034 uchar bios_boot_delay
; /* power up wait */
1036 uchar scsi_reset_delay
; /* 10 reset delay */
1037 uchar bios_id_lun
; /* first boot device scsi id & lun */
1038 /* high nibble is lun */
1039 /* low nibble is scsi id */
1041 uchar termination
; /* 11 0 - automatic */
1042 /* 1 - low off / high off */
1043 /* 2 - low off / high on */
1044 /* 3 - low on / high on */
1045 /* There is no low on / high off */
1047 uchar reserved1
; /* reserved byte (not used) */
1049 ushort bios_ctrl
; /* 12 BIOS control bits */
1050 /* bit 0 BIOS don't act as initiator. */
1051 /* bit 1 BIOS > 1 GB support */
1052 /* bit 2 BIOS > 2 Disk Support */
1053 /* bit 3 BIOS don't support removables */
1054 /* bit 4 BIOS support bootable CD */
1055 /* bit 5 BIOS scan enabled */
1056 /* bit 6 BIOS support multiple LUNs */
1057 /* bit 7 BIOS display of message */
1058 /* bit 8 SCAM disabled */
1059 /* bit 9 Reset SCSI bus during init. */
1061 /* bit 11 No verbose initialization. */
1062 /* bit 12 SCSI parity enabled */
1066 ushort ultra_able
; /* 13 ULTRA speed able */
1067 ushort reserved2
; /* 14 reserved */
1068 uchar max_host_qng
; /* 15 maximum host queuing */
1069 uchar max_dvc_qng
; /* maximum per device queuing */
1070 ushort dvc_cntl
; /* 16 control bit for driver */
1071 ushort bug_fix
; /* 17 control bit for bug fix */
1072 ushort serial_number_word1
; /* 18 Board serial number word 1 */
1073 ushort serial_number_word2
; /* 19 Board serial number word 2 */
1074 ushort serial_number_word3
; /* 20 Board serial number word 3 */
1075 ushort check_sum
; /* 21 EEP check sum */
1076 uchar oem_name
[16]; /* 22 OEM name */
1077 ushort dvc_err_code
; /* 30 last device driver error code */
1078 ushort adv_err_code
; /* 31 last uc and Adv Lib error code */
1079 ushort adv_err_addr
; /* 32 last uc error address */
1080 ushort saved_dvc_err_code
; /* 33 saved last dev. driver error code */
1081 ushort saved_adv_err_code
; /* 34 saved last uc and Adv Lib error code */
1082 ushort saved_adv_err_addr
; /* 35 saved last uc error address */
1083 ushort num_of_err
; /* 36 number of error */
1084 } ADVEEP_3550_CONFIG
;
1086 typedef struct adveep_38C0800_config
{
1087 /* Word Offset, Description */
1089 ushort cfg_lsw
; /* 00 power up initialization */
1090 /* bit 13 set - Load CIS */
1091 /* bit 14 set - BIOS Enable */
1092 /* bit 15 set - Big Endian Mode */
1093 ushort cfg_msw
; /* 01 unused */
1094 ushort disc_enable
; /* 02 disconnect enable */
1095 ushort wdtr_able
; /* 03 Wide DTR able */
1096 ushort sdtr_speed1
; /* 04 SDTR Speed TID 0-3 */
1097 ushort start_motor
; /* 05 send start up motor */
1098 ushort tagqng_able
; /* 06 tag queuing able */
1099 ushort bios_scan
; /* 07 BIOS device control */
1100 ushort scam_tolerant
; /* 08 no scam */
1102 uchar adapter_scsi_id
; /* 09 Host Adapter ID */
1103 uchar bios_boot_delay
; /* power up wait */
1105 uchar scsi_reset_delay
; /* 10 reset delay */
1106 uchar bios_id_lun
; /* first boot device scsi id & lun */
1107 /* high nibble is lun */
1108 /* low nibble is scsi id */
1110 uchar termination_se
; /* 11 0 - automatic */
1111 /* 1 - low off / high off */
1112 /* 2 - low off / high on */
1113 /* 3 - low on / high on */
1114 /* There is no low on / high off */
1116 uchar termination_lvd
; /* 11 0 - automatic */
1117 /* 1 - low off / high off */
1118 /* 2 - low off / high on */
1119 /* 3 - low on / high on */
1120 /* There is no low on / high off */
1122 ushort bios_ctrl
; /* 12 BIOS control bits */
1123 /* bit 0 BIOS don't act as initiator. */
1124 /* bit 1 BIOS > 1 GB support */
1125 /* bit 2 BIOS > 2 Disk Support */
1126 /* bit 3 BIOS don't support removables */
1127 /* bit 4 BIOS support bootable CD */
1128 /* bit 5 BIOS scan enabled */
1129 /* bit 6 BIOS support multiple LUNs */
1130 /* bit 7 BIOS display of message */
1131 /* bit 8 SCAM disabled */
1132 /* bit 9 Reset SCSI bus during init. */
1134 /* bit 11 No verbose initialization. */
1135 /* bit 12 SCSI parity enabled */
1139 ushort sdtr_speed2
; /* 13 SDTR speed TID 4-7 */
1140 ushort sdtr_speed3
; /* 14 SDTR speed TID 8-11 */
1141 uchar max_host_qng
; /* 15 maximum host queueing */
1142 uchar max_dvc_qng
; /* maximum per device queuing */
1143 ushort dvc_cntl
; /* 16 control bit for driver */
1144 ushort sdtr_speed4
; /* 17 SDTR speed 4 TID 12-15 */
1145 ushort serial_number_word1
; /* 18 Board serial number word 1 */
1146 ushort serial_number_word2
; /* 19 Board serial number word 2 */
1147 ushort serial_number_word3
; /* 20 Board serial number word 3 */
1148 ushort check_sum
; /* 21 EEP check sum */
1149 uchar oem_name
[16]; /* 22 OEM name */
1150 ushort dvc_err_code
; /* 30 last device driver error code */
1151 ushort adv_err_code
; /* 31 last uc and Adv Lib error code */
1152 ushort adv_err_addr
; /* 32 last uc error address */
1153 ushort saved_dvc_err_code
; /* 33 saved last dev. driver error code */
1154 ushort saved_adv_err_code
; /* 34 saved last uc and Adv Lib error code */
1155 ushort saved_adv_err_addr
; /* 35 saved last uc error address */
1156 ushort reserved36
; /* 36 reserved */
1157 ushort reserved37
; /* 37 reserved */
1158 ushort reserved38
; /* 38 reserved */
1159 ushort reserved39
; /* 39 reserved */
1160 ushort reserved40
; /* 40 reserved */
1161 ushort reserved41
; /* 41 reserved */
1162 ushort reserved42
; /* 42 reserved */
1163 ushort reserved43
; /* 43 reserved */
1164 ushort reserved44
; /* 44 reserved */
1165 ushort reserved45
; /* 45 reserved */
1166 ushort reserved46
; /* 46 reserved */
1167 ushort reserved47
; /* 47 reserved */
1168 ushort reserved48
; /* 48 reserved */
1169 ushort reserved49
; /* 49 reserved */
1170 ushort reserved50
; /* 50 reserved */
1171 ushort reserved51
; /* 51 reserved */
1172 ushort reserved52
; /* 52 reserved */
1173 ushort reserved53
; /* 53 reserved */
1174 ushort reserved54
; /* 54 reserved */
1175 ushort reserved55
; /* 55 reserved */
1176 ushort cisptr_lsw
; /* 56 CIS PTR LSW */
1177 ushort cisprt_msw
; /* 57 CIS PTR MSW */
1178 ushort subsysvid
; /* 58 SubSystem Vendor ID */
1179 ushort subsysid
; /* 59 SubSystem ID */
1180 ushort reserved60
; /* 60 reserved */
1181 ushort reserved61
; /* 61 reserved */
1182 ushort reserved62
; /* 62 reserved */
1183 ushort reserved63
; /* 63 reserved */
1184 } ADVEEP_38C0800_CONFIG
;
1186 typedef struct adveep_38C1600_config
{
1187 /* Word Offset, Description */
1189 ushort cfg_lsw
; /* 00 power up initialization */
1190 /* bit 11 set - Func. 0 INTB, Func. 1 INTA */
1191 /* clear - Func. 0 INTA, Func. 1 INTB */
1192 /* bit 13 set - Load CIS */
1193 /* bit 14 set - BIOS Enable */
1194 /* bit 15 set - Big Endian Mode */
1195 ushort cfg_msw
; /* 01 unused */
1196 ushort disc_enable
; /* 02 disconnect enable */
1197 ushort wdtr_able
; /* 03 Wide DTR able */
1198 ushort sdtr_speed1
; /* 04 SDTR Speed TID 0-3 */
1199 ushort start_motor
; /* 05 send start up motor */
1200 ushort tagqng_able
; /* 06 tag queuing able */
1201 ushort bios_scan
; /* 07 BIOS device control */
1202 ushort scam_tolerant
; /* 08 no scam */
1204 uchar adapter_scsi_id
; /* 09 Host Adapter ID */
1205 uchar bios_boot_delay
; /* power up wait */
1207 uchar scsi_reset_delay
; /* 10 reset delay */
1208 uchar bios_id_lun
; /* first boot device scsi id & lun */
1209 /* high nibble is lun */
1210 /* low nibble is scsi id */
1212 uchar termination_se
; /* 11 0 - automatic */
1213 /* 1 - low off / high off */
1214 /* 2 - low off / high on */
1215 /* 3 - low on / high on */
1216 /* There is no low on / high off */
1218 uchar termination_lvd
; /* 11 0 - automatic */
1219 /* 1 - low off / high off */
1220 /* 2 - low off / high on */
1221 /* 3 - low on / high on */
1222 /* There is no low on / high off */
1224 ushort bios_ctrl
; /* 12 BIOS control bits */
1225 /* bit 0 BIOS don't act as initiator. */
1226 /* bit 1 BIOS > 1 GB support */
1227 /* bit 2 BIOS > 2 Disk Support */
1228 /* bit 3 BIOS don't support removables */
1229 /* bit 4 BIOS support bootable CD */
1230 /* bit 5 BIOS scan enabled */
1231 /* bit 6 BIOS support multiple LUNs */
1232 /* bit 7 BIOS display of message */
1233 /* bit 8 SCAM disabled */
1234 /* bit 9 Reset SCSI bus during init. */
1235 /* bit 10 Basic Integrity Checking disabled */
1236 /* bit 11 No verbose initialization. */
1237 /* bit 12 SCSI parity enabled */
1238 /* bit 13 AIPP (Asyn. Info. Ph. Prot.) dis. */
1241 ushort sdtr_speed2
; /* 13 SDTR speed TID 4-7 */
1242 ushort sdtr_speed3
; /* 14 SDTR speed TID 8-11 */
1243 uchar max_host_qng
; /* 15 maximum host queueing */
1244 uchar max_dvc_qng
; /* maximum per device queuing */
1245 ushort dvc_cntl
; /* 16 control bit for driver */
1246 ushort sdtr_speed4
; /* 17 SDTR speed 4 TID 12-15 */
1247 ushort serial_number_word1
; /* 18 Board serial number word 1 */
1248 ushort serial_number_word2
; /* 19 Board serial number word 2 */
1249 ushort serial_number_word3
; /* 20 Board serial number word 3 */
1250 ushort check_sum
; /* 21 EEP check sum */
1251 uchar oem_name
[16]; /* 22 OEM name */
1252 ushort dvc_err_code
; /* 30 last device driver error code */
1253 ushort adv_err_code
; /* 31 last uc and Adv Lib error code */
1254 ushort adv_err_addr
; /* 32 last uc error address */
1255 ushort saved_dvc_err_code
; /* 33 saved last dev. driver error code */
1256 ushort saved_adv_err_code
; /* 34 saved last uc and Adv Lib error code */
1257 ushort saved_adv_err_addr
; /* 35 saved last uc error address */
1258 ushort reserved36
; /* 36 reserved */
1259 ushort reserved37
; /* 37 reserved */
1260 ushort reserved38
; /* 38 reserved */
1261 ushort reserved39
; /* 39 reserved */
1262 ushort reserved40
; /* 40 reserved */
1263 ushort reserved41
; /* 41 reserved */
1264 ushort reserved42
; /* 42 reserved */
1265 ushort reserved43
; /* 43 reserved */
1266 ushort reserved44
; /* 44 reserved */
1267 ushort reserved45
; /* 45 reserved */
1268 ushort reserved46
; /* 46 reserved */
1269 ushort reserved47
; /* 47 reserved */
1270 ushort reserved48
; /* 48 reserved */
1271 ushort reserved49
; /* 49 reserved */
1272 ushort reserved50
; /* 50 reserved */
1273 ushort reserved51
; /* 51 reserved */
1274 ushort reserved52
; /* 52 reserved */
1275 ushort reserved53
; /* 53 reserved */
1276 ushort reserved54
; /* 54 reserved */
1277 ushort reserved55
; /* 55 reserved */
1278 ushort cisptr_lsw
; /* 56 CIS PTR LSW */
1279 ushort cisprt_msw
; /* 57 CIS PTR MSW */
1280 ushort subsysvid
; /* 58 SubSystem Vendor ID */
1281 ushort subsysid
; /* 59 SubSystem ID */
1282 ushort reserved60
; /* 60 reserved */
1283 ushort reserved61
; /* 61 reserved */
1284 ushort reserved62
; /* 62 reserved */
1285 ushort reserved63
; /* 63 reserved */
1286 } ADVEEP_38C1600_CONFIG
;
1291 #define ASC_EEP_CMD_DONE 0x0200
1294 #define BIOS_CTRL_BIOS 0x0001
1295 #define BIOS_CTRL_EXTENDED_XLAT 0x0002
1296 #define BIOS_CTRL_GT_2_DISK 0x0004
1297 #define BIOS_CTRL_BIOS_REMOVABLE 0x0008
1298 #define BIOS_CTRL_BOOTABLE_CD 0x0010
1299 #define BIOS_CTRL_MULTIPLE_LUN 0x0040
1300 #define BIOS_CTRL_DISPLAY_MSG 0x0080
1301 #define BIOS_CTRL_NO_SCAM 0x0100
1302 #define BIOS_CTRL_RESET_SCSI_BUS 0x0200
1303 #define BIOS_CTRL_INIT_VERBOSE 0x0800
1304 #define BIOS_CTRL_SCSI_PARITY 0x1000
1305 #define BIOS_CTRL_AIPP_DIS 0x2000
1307 #define ADV_3550_MEMSIZE 0x2000 /* 8 KB Internal Memory */
1309 #define ADV_38C0800_MEMSIZE 0x4000 /* 16 KB Internal Memory */
1312 * XXX - Since ASC38C1600 Rev.3 has a local RAM failure issue, there is
1313 * a special 16K Adv Library and Microcode version. After the issue is
1314 * resolved, should restore 32K support.
1316 * #define ADV_38C1600_MEMSIZE 0x8000L * 32 KB Internal Memory *
1318 #define ADV_38C1600_MEMSIZE 0x4000 /* 16 KB Internal Memory */
1321 * Byte I/O register address from base of 'iop_base'.
1323 #define IOPB_INTR_STATUS_REG 0x00
1324 #define IOPB_CHIP_ID_1 0x01
1325 #define IOPB_INTR_ENABLES 0x02
1326 #define IOPB_CHIP_TYPE_REV 0x03
1327 #define IOPB_RES_ADDR_4 0x04
1328 #define IOPB_RES_ADDR_5 0x05
1329 #define IOPB_RAM_DATA 0x06
1330 #define IOPB_RES_ADDR_7 0x07
1331 #define IOPB_FLAG_REG 0x08
1332 #define IOPB_RES_ADDR_9 0x09
1333 #define IOPB_RISC_CSR 0x0A
1334 #define IOPB_RES_ADDR_B 0x0B
1335 #define IOPB_RES_ADDR_C 0x0C
1336 #define IOPB_RES_ADDR_D 0x0D
1337 #define IOPB_SOFT_OVER_WR 0x0E
1338 #define IOPB_RES_ADDR_F 0x0F
1339 #define IOPB_MEM_CFG 0x10
1340 #define IOPB_RES_ADDR_11 0x11
1341 #define IOPB_GPIO_DATA 0x12
1342 #define IOPB_RES_ADDR_13 0x13
1343 #define IOPB_FLASH_PAGE 0x14
1344 #define IOPB_RES_ADDR_15 0x15
1345 #define IOPB_GPIO_CNTL 0x16
1346 #define IOPB_RES_ADDR_17 0x17
1347 #define IOPB_FLASH_DATA 0x18
1348 #define IOPB_RES_ADDR_19 0x19
1349 #define IOPB_RES_ADDR_1A 0x1A
1350 #define IOPB_RES_ADDR_1B 0x1B
1351 #define IOPB_RES_ADDR_1C 0x1C
1352 #define IOPB_RES_ADDR_1D 0x1D
1353 #define IOPB_RES_ADDR_1E 0x1E
1354 #define IOPB_RES_ADDR_1F 0x1F
1355 #define IOPB_DMA_CFG0 0x20
1356 #define IOPB_DMA_CFG1 0x21
1357 #define IOPB_TICKLE 0x22
1358 #define IOPB_DMA_REG_WR 0x23
1359 #define IOPB_SDMA_STATUS 0x24
1360 #define IOPB_SCSI_BYTE_CNT 0x25
1361 #define IOPB_HOST_BYTE_CNT 0x26
1362 #define IOPB_BYTE_LEFT_TO_XFER 0x27
1363 #define IOPB_BYTE_TO_XFER_0 0x28
1364 #define IOPB_BYTE_TO_XFER_1 0x29
1365 #define IOPB_BYTE_TO_XFER_2 0x2A
1366 #define IOPB_BYTE_TO_XFER_3 0x2B
1367 #define IOPB_ACC_GRP 0x2C
1368 #define IOPB_RES_ADDR_2D 0x2D
1369 #define IOPB_DEV_ID 0x2E
1370 #define IOPB_RES_ADDR_2F 0x2F
1371 #define IOPB_SCSI_DATA 0x30
1372 #define IOPB_RES_ADDR_31 0x31
1373 #define IOPB_RES_ADDR_32 0x32
1374 #define IOPB_SCSI_DATA_HSHK 0x33
1375 #define IOPB_SCSI_CTRL 0x34
1376 #define IOPB_RES_ADDR_35 0x35
1377 #define IOPB_RES_ADDR_36 0x36
1378 #define IOPB_RES_ADDR_37 0x37
1379 #define IOPB_RAM_BIST 0x38
1380 #define IOPB_PLL_TEST 0x39
1381 #define IOPB_PCI_INT_CFG 0x3A
1382 #define IOPB_RES_ADDR_3B 0x3B
1383 #define IOPB_RFIFO_CNT 0x3C
1384 #define IOPB_RES_ADDR_3D 0x3D
1385 #define IOPB_RES_ADDR_3E 0x3E
1386 #define IOPB_RES_ADDR_3F 0x3F
1389 * Word I/O register address from base of 'iop_base'.
1391 #define IOPW_CHIP_ID_0 0x00 /* CID0 */
1392 #define IOPW_CTRL_REG 0x02 /* CC */
1393 #define IOPW_RAM_ADDR 0x04 /* LA */
1394 #define IOPW_RAM_DATA 0x06 /* LD */
1395 #define IOPW_RES_ADDR_08 0x08
1396 #define IOPW_RISC_CSR 0x0A /* CSR */
1397 #define IOPW_SCSI_CFG0 0x0C /* CFG0 */
1398 #define IOPW_SCSI_CFG1 0x0E /* CFG1 */
1399 #define IOPW_RES_ADDR_10 0x10
1400 #define IOPW_SEL_MASK 0x12 /* SM */
1401 #define IOPW_RES_ADDR_14 0x14
1402 #define IOPW_FLASH_ADDR 0x16 /* FA */
1403 #define IOPW_RES_ADDR_18 0x18
1404 #define IOPW_EE_CMD 0x1A /* EC */
1405 #define IOPW_EE_DATA 0x1C /* ED */
1406 #define IOPW_SFIFO_CNT 0x1E /* SFC */
1407 #define IOPW_RES_ADDR_20 0x20
1408 #define IOPW_Q_BASE 0x22 /* QB */
1409 #define IOPW_QP 0x24 /* QP */
1410 #define IOPW_IX 0x26 /* IX */
1411 #define IOPW_SP 0x28 /* SP */
1412 #define IOPW_PC 0x2A /* PC */
1413 #define IOPW_RES_ADDR_2C 0x2C
1414 #define IOPW_RES_ADDR_2E 0x2E
1415 #define IOPW_SCSI_DATA 0x30 /* SD */
1416 #define IOPW_SCSI_DATA_HSHK 0x32 /* SDH */
1417 #define IOPW_SCSI_CTRL 0x34 /* SC */
1418 #define IOPW_HSHK_CFG 0x36 /* HCFG */
1419 #define IOPW_SXFR_STATUS 0x36 /* SXS */
1420 #define IOPW_SXFR_CNTL 0x38 /* SXL */
1421 #define IOPW_SXFR_CNTH 0x3A /* SXH */
1422 #define IOPW_RES_ADDR_3C 0x3C
1423 #define IOPW_RFIFO_DATA 0x3E /* RFD */
1426 * Doubleword I/O register address from base of 'iop_base'.
1428 #define IOPDW_RES_ADDR_0 0x00
1429 #define IOPDW_RAM_DATA 0x04
1430 #define IOPDW_RES_ADDR_8 0x08
1431 #define IOPDW_RES_ADDR_C 0x0C
1432 #define IOPDW_RES_ADDR_10 0x10
1433 #define IOPDW_COMMA 0x14
1434 #define IOPDW_COMMB 0x18
1435 #define IOPDW_RES_ADDR_1C 0x1C
1436 #define IOPDW_SDMA_ADDR0 0x20
1437 #define IOPDW_SDMA_ADDR1 0x24
1438 #define IOPDW_SDMA_COUNT 0x28
1439 #define IOPDW_SDMA_ERROR 0x2C
1440 #define IOPDW_RDMA_ADDR0 0x30
1441 #define IOPDW_RDMA_ADDR1 0x34
1442 #define IOPDW_RDMA_COUNT 0x38
1443 #define IOPDW_RDMA_ERROR 0x3C
1445 #define ADV_CHIP_ID_BYTE 0x25
1446 #define ADV_CHIP_ID_WORD 0x04C1
1448 #define ADV_INTR_ENABLE_HOST_INTR 0x01
1449 #define ADV_INTR_ENABLE_SEL_INTR 0x02
1450 #define ADV_INTR_ENABLE_DPR_INTR 0x04
1451 #define ADV_INTR_ENABLE_RTA_INTR 0x08
1452 #define ADV_INTR_ENABLE_RMA_INTR 0x10
1453 #define ADV_INTR_ENABLE_RST_INTR 0x20
1454 #define ADV_INTR_ENABLE_DPE_INTR 0x40
1455 #define ADV_INTR_ENABLE_GLOBAL_INTR 0x80
1457 #define ADV_INTR_STATUS_INTRA 0x01
1458 #define ADV_INTR_STATUS_INTRB 0x02
1459 #define ADV_INTR_STATUS_INTRC 0x04
1461 #define ADV_RISC_CSR_STOP (0x0000)
1462 #define ADV_RISC_TEST_COND (0x2000)
1463 #define ADV_RISC_CSR_RUN (0x4000)
1464 #define ADV_RISC_CSR_SINGLE_STEP (0x8000)
1466 #define ADV_CTRL_REG_HOST_INTR 0x0100
1467 #define ADV_CTRL_REG_SEL_INTR 0x0200
1468 #define ADV_CTRL_REG_DPR_INTR 0x0400
1469 #define ADV_CTRL_REG_RTA_INTR 0x0800
1470 #define ADV_CTRL_REG_RMA_INTR 0x1000
1471 #define ADV_CTRL_REG_RES_BIT14 0x2000
1472 #define ADV_CTRL_REG_DPE_INTR 0x4000
1473 #define ADV_CTRL_REG_POWER_DONE 0x8000
1474 #define ADV_CTRL_REG_ANY_INTR 0xFF00
1476 #define ADV_CTRL_REG_CMD_RESET 0x00C6
1477 #define ADV_CTRL_REG_CMD_WR_IO_REG 0x00C5
1478 #define ADV_CTRL_REG_CMD_RD_IO_REG 0x00C4
1479 #define ADV_CTRL_REG_CMD_WR_PCI_CFG_SPACE 0x00C3
1480 #define ADV_CTRL_REG_CMD_RD_PCI_CFG_SPACE 0x00C2
1482 #define ADV_TICKLE_NOP 0x00
1483 #define ADV_TICKLE_A 0x01
1484 #define ADV_TICKLE_B 0x02
1485 #define ADV_TICKLE_C 0x03
1487 #define AdvIsIntPending(port) \
1488 (AdvReadWordRegister(port, IOPW_CTRL_REG) & ADV_CTRL_REG_HOST_INTR)
1491 * SCSI_CFG0 Register bit definitions
1493 #define TIMER_MODEAB 0xC000 /* Watchdog, Second, and Select. Timer Ctrl. */
1494 #define PARITY_EN 0x2000 /* Enable SCSI Parity Error detection */
1495 #define EVEN_PARITY 0x1000 /* Select Even Parity */
1496 #define WD_LONG 0x0800 /* Watchdog Interval, 1: 57 min, 0: 13 sec */
1497 #define QUEUE_128 0x0400 /* Queue Size, 1: 128 byte, 0: 64 byte */
1498 #define PRIM_MODE 0x0100 /* Primitive SCSI mode */
1499 #define SCAM_EN 0x0080 /* Enable SCAM selection */
1500 #define SEL_TMO_LONG 0x0040 /* Sel/Resel Timeout, 1: 400 ms, 0: 1.6 ms */
1501 #define CFRM_ID 0x0020 /* SCAM id sel. confirm., 1: fast, 0: 6.4 ms */
1502 #define OUR_ID_EN 0x0010 /* Enable OUR_ID bits */
1503 #define OUR_ID 0x000F /* SCSI ID */
1506 * SCSI_CFG1 Register bit definitions
1508 #define BIG_ENDIAN 0x8000 /* Enable Big Endian Mode MIO:15, EEP:15 */
1509 #define TERM_POL 0x2000 /* Terminator Polarity Ctrl. MIO:13, EEP:13 */
1510 #define SLEW_RATE 0x1000 /* SCSI output buffer slew rate */
1511 #define FILTER_SEL 0x0C00 /* Filter Period Selection */
1512 #define FLTR_DISABLE 0x0000 /* Input Filtering Disabled */
1513 #define FLTR_11_TO_20NS 0x0800 /* Input Filtering 11ns to 20ns */
1514 #define FLTR_21_TO_39NS 0x0C00 /* Input Filtering 21ns to 39ns */
1515 #define ACTIVE_DBL 0x0200 /* Disable Active Negation */
1516 #define DIFF_MODE 0x0100 /* SCSI differential Mode (Read-Only) */
1517 #define DIFF_SENSE 0x0080 /* 1: No SE cables, 0: SE cable (Read-Only) */
1518 #define TERM_CTL_SEL 0x0040 /* Enable TERM_CTL_H and TERM_CTL_L */
1519 #define TERM_CTL 0x0030 /* External SCSI Termination Bits */
1520 #define TERM_CTL_H 0x0020 /* Enable External SCSI Upper Termination */
1521 #define TERM_CTL_L 0x0010 /* Enable External SCSI Lower Termination */
1522 #define CABLE_DETECT 0x000F /* External SCSI Cable Connection Status */
1525 * Addendum for ASC-38C0800 Chip
1527 * The ASC-38C1600 Chip uses the same definitions except that the
1528 * bus mode override bits [12:10] have been moved to byte register
1529 * offset 0xE (IOPB_SOFT_OVER_WR) bits [12:10]. The [12:10] bits in
1530 * SCSI_CFG1 are read-only and always available. Bit 14 (DIS_TERM_DRV)
1531 * is not needed. The [12:10] bits in IOPB_SOFT_OVER_WR are write-only.
1532 * Also each ASC-38C1600 function or channel uses only cable bits [5:4]
1533 * and [1:0]. Bits [14], [7:6], [3:2] are unused.
1535 #define DIS_TERM_DRV 0x4000 /* 1: Read c_det[3:0], 0: cannot read */
1536 #define HVD_LVD_SE 0x1C00 /* Device Detect Bits */
1537 #define HVD 0x1000 /* HVD Device Detect */
1538 #define LVD 0x0800 /* LVD Device Detect */
1539 #define SE 0x0400 /* SE Device Detect */
1540 #define TERM_LVD 0x00C0 /* LVD Termination Bits */
1541 #define TERM_LVD_HI 0x0080 /* Enable LVD Upper Termination */
1542 #define TERM_LVD_LO 0x0040 /* Enable LVD Lower Termination */
1543 #define TERM_SE 0x0030 /* SE Termination Bits */
1544 #define TERM_SE_HI 0x0020 /* Enable SE Upper Termination */
1545 #define TERM_SE_LO 0x0010 /* Enable SE Lower Termination */
1546 #define C_DET_LVD 0x000C /* LVD Cable Detect Bits */
1547 #define C_DET3 0x0008 /* Cable Detect for LVD External Wide */
1548 #define C_DET2 0x0004 /* Cable Detect for LVD Internal Wide */
1549 #define C_DET_SE 0x0003 /* SE Cable Detect Bits */
1550 #define C_DET1 0x0002 /* Cable Detect for SE Internal Wide */
1551 #define C_DET0 0x0001 /* Cable Detect for SE Internal Narrow */
1553 #define CABLE_ILLEGAL_A 0x7
1554 /* x 0 0 0 | on on | Illegal (all 3 connectors are used) */
1556 #define CABLE_ILLEGAL_B 0xB
1557 /* 0 x 0 0 | on on | Illegal (all 3 connectors are used) */
1560 * MEM_CFG Register bit definitions
1562 #define BIOS_EN 0x40 /* BIOS Enable MIO:14,EEP:14 */
1563 #define FAST_EE_CLK 0x20 /* Diagnostic Bit */
1564 #define RAM_SZ 0x1C /* Specify size of RAM to RISC */
1565 #define RAM_SZ_2KB 0x00 /* 2 KB */
1566 #define RAM_SZ_4KB 0x04 /* 4 KB */
1567 #define RAM_SZ_8KB 0x08 /* 8 KB */
1568 #define RAM_SZ_16KB 0x0C /* 16 KB */
1569 #define RAM_SZ_32KB 0x10 /* 32 KB */
1570 #define RAM_SZ_64KB 0x14 /* 64 KB */
1573 * DMA_CFG0 Register bit definitions
1575 * This register is only accessible to the host.
1577 #define BC_THRESH_ENB 0x80 /* PCI DMA Start Conditions */
1578 #define FIFO_THRESH 0x70 /* PCI DMA FIFO Threshold */
1579 #define FIFO_THRESH_16B 0x00 /* 16 bytes */
1580 #define FIFO_THRESH_32B 0x20 /* 32 bytes */
1581 #define FIFO_THRESH_48B 0x30 /* 48 bytes */
1582 #define FIFO_THRESH_64B 0x40 /* 64 bytes */
1583 #define FIFO_THRESH_80B 0x50 /* 80 bytes (default) */
1584 #define FIFO_THRESH_96B 0x60 /* 96 bytes */
1585 #define FIFO_THRESH_112B 0x70 /* 112 bytes */
1586 #define START_CTL 0x0C /* DMA start conditions */
1587 #define START_CTL_TH 0x00 /* Wait threshold level (default) */
1588 #define START_CTL_ID 0x04 /* Wait SDMA/SBUS idle */
1589 #define START_CTL_THID 0x08 /* Wait threshold and SDMA/SBUS idle */
1590 #define START_CTL_EMFU 0x0C /* Wait SDMA FIFO empty/full */
1591 #define READ_CMD 0x03 /* Memory Read Method */
1592 #define READ_CMD_MR 0x00 /* Memory Read */
1593 #define READ_CMD_MRL 0x02 /* Memory Read Long */
1594 #define READ_CMD_MRM 0x03 /* Memory Read Multiple (default) */
1597 * ASC-38C0800 RAM BIST Register bit definitions
1599 #define RAM_TEST_MODE 0x80
1600 #define PRE_TEST_MODE 0x40
1601 #define NORMAL_MODE 0x00
1602 #define RAM_TEST_DONE 0x10
1603 #define RAM_TEST_STATUS 0x0F
1604 #define RAM_TEST_HOST_ERROR 0x08
1605 #define RAM_TEST_INTRAM_ERROR 0x04
1606 #define RAM_TEST_RISC_ERROR 0x02
1607 #define RAM_TEST_SCSI_ERROR 0x01
1608 #define RAM_TEST_SUCCESS 0x00
1609 #define PRE_TEST_VALUE 0x05
1610 #define NORMAL_VALUE 0x00
1613 * ASC38C1600 Definitions
1615 * IOPB_PCI_INT_CFG Bit Field Definitions
1618 #define INTAB_LD 0x80 /* Value loaded from EEPROM Bit 11. */
1621 * Bit 1 can be set to change the interrupt for the Function to operate in
1622 * Totem Pole mode. By default Bit 1 is 0 and the interrupt operates in
1623 * Open Drain mode. Both functions of the ASC38C1600 must be set to the same
1624 * mode, otherwise the operating mode is undefined.
1626 #define TOTEMPOLE 0x02
1629 * Bit 0 can be used to change the Int Pin for the Function. The value is
1630 * 0 by default for both Functions with Function 0 using INT A and Function
1631 * B using INT B. For Function 0 if set, INT B is used. For Function 1 if set,
1634 * EEPROM Word 0 Bit 11 for each Function may change the initial Int Pin
1635 * value specified in the PCI Configuration Space.
1640 * Adv Library Status Definitions
1644 #define ADV_SUCCESS 1
1646 #define ADV_ERROR (-1)
1649 * ADV_DVC_VAR 'warn_code' values
1651 #define ASC_WARN_BUSRESET_ERROR 0x0001 /* SCSI Bus Reset error */
1652 #define ASC_WARN_EEPROM_CHKSUM 0x0002 /* EEP check sum error */
1653 #define ASC_WARN_EEPROM_TERMINATION 0x0004 /* EEP termination bad field */
1654 #define ASC_WARN_ERROR 0xFFFF /* ADV_ERROR return */
1656 #define ADV_MAX_TID 15 /* max. target identifier */
1657 #define ADV_MAX_LUN 7 /* max. logical unit number */
1660 * Fixed locations of microcode operating variables.
1662 #define ASC_MC_CODE_BEGIN_ADDR 0x0028 /* microcode start address */
1663 #define ASC_MC_CODE_END_ADDR 0x002A /* microcode end address */
1664 #define ASC_MC_CODE_CHK_SUM 0x002C /* microcode code checksum */
1665 #define ASC_MC_VERSION_DATE 0x0038 /* microcode version */
1666 #define ASC_MC_VERSION_NUM 0x003A /* microcode number */
1667 #define ASC_MC_BIOSMEM 0x0040 /* BIOS RISC Memory Start */
1668 #define ASC_MC_BIOSLEN 0x0050 /* BIOS RISC Memory Length */
1669 #define ASC_MC_BIOS_SIGNATURE 0x0058 /* BIOS Signature 0x55AA */
1670 #define ASC_MC_BIOS_VERSION 0x005A /* BIOS Version (2 bytes) */
1671 #define ASC_MC_SDTR_SPEED1 0x0090 /* SDTR Speed for TID 0-3 */
1672 #define ASC_MC_SDTR_SPEED2 0x0092 /* SDTR Speed for TID 4-7 */
1673 #define ASC_MC_SDTR_SPEED3 0x0094 /* SDTR Speed for TID 8-11 */
1674 #define ASC_MC_SDTR_SPEED4 0x0096 /* SDTR Speed for TID 12-15 */
1675 #define ASC_MC_CHIP_TYPE 0x009A
1676 #define ASC_MC_INTRB_CODE 0x009B
1677 #define ASC_MC_WDTR_ABLE 0x009C
1678 #define ASC_MC_SDTR_ABLE 0x009E
1679 #define ASC_MC_TAGQNG_ABLE 0x00A0
1680 #define ASC_MC_DISC_ENABLE 0x00A2
1681 #define ASC_MC_IDLE_CMD_STATUS 0x00A4
1682 #define ASC_MC_IDLE_CMD 0x00A6
1683 #define ASC_MC_IDLE_CMD_PARAMETER 0x00A8
1684 #define ASC_MC_DEFAULT_SCSI_CFG0 0x00AC
1685 #define ASC_MC_DEFAULT_SCSI_CFG1 0x00AE
1686 #define ASC_MC_DEFAULT_MEM_CFG 0x00B0
1687 #define ASC_MC_DEFAULT_SEL_MASK 0x00B2
1688 #define ASC_MC_SDTR_DONE 0x00B6
1689 #define ASC_MC_NUMBER_OF_QUEUED_CMD 0x00C0
1690 #define ASC_MC_NUMBER_OF_MAX_CMD 0x00D0
1691 #define ASC_MC_DEVICE_HSHK_CFG_TABLE 0x0100
1692 #define ASC_MC_CONTROL_FLAG 0x0122 /* Microcode control flag. */
1693 #define ASC_MC_WDTR_DONE 0x0124
1694 #define ASC_MC_CAM_MODE_MASK 0x015E /* CAM mode TID bitmask. */
1695 #define ASC_MC_ICQ 0x0160
1696 #define ASC_MC_IRQ 0x0164
1697 #define ASC_MC_PPR_ABLE 0x017A
1700 * BIOS LRAM variable absolute offsets.
1702 #define BIOS_CODESEG 0x54
1703 #define BIOS_CODELEN 0x56
1704 #define BIOS_SIGNATURE 0x58
1705 #define BIOS_VERSION 0x5A
1708 * Microcode Control Flags
1710 * Flags set by the Adv Library in RISC variable 'control_flag' (0x122)
1711 * and handled by the microcode.
1713 #define CONTROL_FLAG_IGNORE_PERR 0x0001 /* Ignore DMA Parity Errors */
1714 #define CONTROL_FLAG_ENABLE_AIPP 0x0002 /* Enabled AIPP checking. */
1717 * ASC_MC_DEVICE_HSHK_CFG_TABLE microcode table or HSHK_CFG register format
1719 #define HSHK_CFG_WIDE_XFR 0x8000
1720 #define HSHK_CFG_RATE 0x0F00
1721 #define HSHK_CFG_OFFSET 0x001F
1723 #define ASC_DEF_MAX_HOST_QNG 0xFD /* Max. number of host commands (253) */
1724 #define ASC_DEF_MIN_HOST_QNG 0x10 /* Min. number of host commands (16) */
1725 #define ASC_DEF_MAX_DVC_QNG 0x3F /* Max. number commands per device (63) */
1726 #define ASC_DEF_MIN_DVC_QNG 0x04 /* Min. number commands per device (4) */
1728 #define ASC_QC_DATA_CHECK 0x01 /* Require ASC_QC_DATA_OUT set or clear. */
1729 #define ASC_QC_DATA_OUT 0x02 /* Data out DMA transfer. */
1730 #define ASC_QC_START_MOTOR 0x04 /* Send auto-start motor before request. */
1731 #define ASC_QC_NO_OVERRUN 0x08 /* Don't report overrun. */
1732 #define ASC_QC_FREEZE_TIDQ 0x10 /* Freeze TID queue after request. XXX TBD */
1734 #define ASC_QSC_NO_DISC 0x01 /* Don't allow disconnect for request. */
1735 #define ASC_QSC_NO_TAGMSG 0x02 /* Don't allow tag queuing for request. */
1736 #define ASC_QSC_NO_SYNC 0x04 /* Don't use Synch. transfer on request. */
1737 #define ASC_QSC_NO_WIDE 0x08 /* Don't use Wide transfer on request. */
1738 #define ASC_QSC_REDO_DTR 0x10 /* Renegotiate WDTR/SDTR before request. */
1740 * Note: If a Tag Message is to be sent and neither ASC_QSC_HEAD_TAG or
1741 * ASC_QSC_ORDERED_TAG is set, then a Simple Tag Message (0x20) is used.
1743 #define ASC_QSC_HEAD_TAG 0x40 /* Use Head Tag Message (0x21). */
1744 #define ASC_QSC_ORDERED_TAG 0x80 /* Use Ordered Tag Message (0x22). */
1747 * All fields here are accessed by the board microcode and need to be
1750 typedef struct adv_carr_t
{
1751 ADV_VADDR carr_va
; /* Carrier Virtual Address */
1752 ADV_PADDR carr_pa
; /* Carrier Physical Address */
1753 ADV_VADDR areq_vpa
; /* ASC_SCSI_REQ_Q Virtual or Physical Address */
1755 * next_vpa [31:4] Carrier Virtual or Physical Next Pointer
1757 * next_vpa [3:1] Reserved Bits
1758 * next_vpa [0] Done Flag set in Response Queue.
1764 * Mask used to eliminate low 4 bits of carrier 'next_vpa' field.
1766 #define ASC_NEXT_VPA_MASK 0xFFFFFFF0
1768 #define ASC_RQ_DONE 0x00000001
1769 #define ASC_RQ_GOOD 0x00000002
1770 #define ASC_CQ_STOPPER 0x00000000
1772 #define ASC_GET_CARRP(carrp) ((carrp) & ASC_NEXT_VPA_MASK)
1774 #define ADV_CARRIER_NUM_PAGE_CROSSING \
1775 (((ADV_CARRIER_COUNT * sizeof(ADV_CARR_T)) + (PAGE_SIZE - 1))/PAGE_SIZE)
1777 #define ADV_CARRIER_BUFSIZE \
1778 ((ADV_CARRIER_COUNT + ADV_CARRIER_NUM_PAGE_CROSSING) * sizeof(ADV_CARR_T))
1781 * ASC_SCSI_REQ_Q 'a_flag' definitions
1783 * The Adv Library should limit use to the lower nibble (4 bits) of
1784 * a_flag. Drivers are free to use the upper nibble (4 bits) of a_flag.
1786 #define ADV_POLL_REQUEST 0x01 /* poll for request completion */
1787 #define ADV_SCSIQ_DONE 0x02 /* request done */
1788 #define ADV_DONT_RETRY 0x08 /* don't do retry */
1790 #define ADV_CHIP_ASC3550 0x01 /* Ultra-Wide IC */
1791 #define ADV_CHIP_ASC38C0800 0x02 /* Ultra2-Wide/LVD IC */
1792 #define ADV_CHIP_ASC38C1600 0x03 /* Ultra3-Wide/LVD2 IC */
1795 * Adapter temporary configuration structure
1797 * This structure can be discarded after initialization. Don't add
1798 * fields here needed after initialization.
1800 * Field naming convention:
1802 * *_enable indicates the field enables or disables a feature. The
1803 * value of the field is never reset.
1805 typedef struct adv_dvc_cfg
{
1806 ushort disc_enable
; /* enable disconnection */
1807 uchar chip_version
; /* chip version */
1808 uchar termination
; /* Term. Ctrl. bits 6-5 of SCSI_CFG1 register */
1809 ushort control_flag
; /* Microcode Control Flag */
1810 ushort mcode_date
; /* Microcode date */
1811 ushort mcode_version
; /* Microcode version */
1812 ushort serial1
; /* EEPROM serial number word 1 */
1813 ushort serial2
; /* EEPROM serial number word 2 */
1814 ushort serial3
; /* EEPROM serial number word 3 */
1818 struct adv_scsi_req_q
;
1820 typedef struct asc_sg_block
{
1824 uchar sg_cnt
; /* Valid entries in block. */
1825 ADV_PADDR sg_ptr
; /* Pointer to next sg block. */
1827 ADV_PADDR sg_addr
; /* SG element address. */
1828 ADV_DCNT sg_count
; /* SG element count. */
1829 } sg_list
[NO_OF_SG_PER_BLOCK
];
1833 * ADV_SCSI_REQ_Q - microcode request structure
1835 * All fields in this structure up to byte 60 are used by the microcode.
1836 * The microcode makes assumptions about the size and ordering of fields
1837 * in this structure. Do not change the structure definition here without
1838 * coordinating the change with the microcode.
1840 * All fields accessed by microcode must be maintained in little_endian
1843 typedef struct adv_scsi_req_q
{
1844 uchar cntl
; /* Ucode flags and state (ASC_MC_QC_*). */
1846 uchar target_id
; /* Device target identifier. */
1847 uchar target_lun
; /* Device target logical unit number. */
1848 ADV_PADDR data_addr
; /* Data buffer physical address. */
1849 ADV_DCNT data_cnt
; /* Data count. Ucode sets to residual. */
1850 ADV_PADDR sense_addr
;
1854 uchar cdb_len
; /* SCSI CDB length. Must <= 16 bytes. */
1856 uchar done_status
; /* Completion status. */
1857 uchar scsi_status
; /* SCSI status byte. */
1858 uchar host_status
; /* Ucode host status. */
1859 uchar sg_working_ix
;
1860 uchar cdb
[12]; /* SCSI CDB bytes 0-11. */
1861 ADV_PADDR sg_real_addr
; /* SG list physical address. */
1862 ADV_PADDR scsiq_rptr
;
1863 uchar cdb16
[4]; /* SCSI CDB bytes 12-15. */
1864 ADV_VADDR scsiq_ptr
;
1867 * End of microcode structure - 60 bytes. The rest of the structure
1868 * is used by the Adv Library and ignored by the microcode.
1871 ADV_SG_BLOCK
*sg_list_ptr
; /* SG list virtual address. */
1872 char *vdata_addr
; /* Data buffer virtual address. */
1874 uchar pad
[2]; /* Pad out to a word boundary. */
1878 * The following two structures are used to process Wide Board requests.
1880 * The ADV_SCSI_REQ_Q structure in adv_req_t is passed to the Adv Library
1881 * and microcode with the ADV_SCSI_REQ_Q field 'srb_ptr' pointing to the
1882 * adv_req_t. The adv_req_t structure 'cmndp' field in turn points to the
1883 * Mid-Level SCSI request structure.
1885 * Zero or more ADV_SG_BLOCK are used with each ADV_SCSI_REQ_Q. Each
1886 * ADV_SG_BLOCK structure holds 15 scatter-gather elements. Under Linux
1887 * up to 255 scatter-gather elements may be used per request or
1890 * Both structures must be 32 byte aligned.
1892 typedef struct adv_sgblk
{
1893 ADV_SG_BLOCK sg_block
; /* Sgblock structure. */
1894 uchar align
[32]; /* Sgblock structure padding. */
1895 struct adv_sgblk
*next_sgblkp
; /* Next scatter-gather structure. */
1898 typedef struct adv_req
{
1899 ADV_SCSI_REQ_Q scsi_req_q
; /* Adv Library request structure. */
1900 uchar align
[32]; /* Request structure padding. */
1901 struct scsi_cmnd
*cmndp
; /* Mid-Level SCSI command pointer. */
1902 adv_sgblk_t
*sgblkp
; /* Adv Library scatter-gather pointer. */
1903 struct adv_req
*next_reqp
; /* Next Request Structure. */
1907 * Adapter operation variable structure.
1909 * One structure is required per host adapter.
1911 * Field naming convention:
1913 * *_able indicates both whether a feature should be enabled or disabled
1914 * and whether a device isi capable of the feature. At initialization
1915 * this field may be set, but later if a device is found to be incapable
1916 * of the feature, the field is cleared.
1918 typedef struct adv_dvc_var
{
1919 AdvPortAddr iop_base
; /* I/O port address */
1920 ushort err_code
; /* fatal error code */
1921 ushort bios_ctrl
; /* BIOS control word, EEPROM word 12 */
1922 ushort wdtr_able
; /* try WDTR for a device */
1923 ushort sdtr_able
; /* try SDTR for a device */
1924 ushort ultra_able
; /* try SDTR Ultra speed for a device */
1925 ushort sdtr_speed1
; /* EEPROM SDTR Speed for TID 0-3 */
1926 ushort sdtr_speed2
; /* EEPROM SDTR Speed for TID 4-7 */
1927 ushort sdtr_speed3
; /* EEPROM SDTR Speed for TID 8-11 */
1928 ushort sdtr_speed4
; /* EEPROM SDTR Speed for TID 12-15 */
1929 ushort tagqng_able
; /* try tagged queuing with a device */
1930 ushort ppr_able
; /* PPR message capable per TID bitmask. */
1931 uchar max_dvc_qng
; /* maximum number of tagged commands per device */
1932 ushort start_motor
; /* start motor command allowed */
1933 uchar scsi_reset_wait
; /* delay in seconds after scsi bus reset */
1934 uchar chip_no
; /* should be assigned by caller */
1935 uchar max_host_qng
; /* maximum number of Q'ed command allowed */
1936 ushort no_scam
; /* scam_tolerant of EEPROM */
1937 struct asc_board
*drv_ptr
; /* driver pointer to private structure */
1938 uchar chip_scsi_id
; /* chip SCSI target ID */
1940 uchar bist_err_code
;
1941 ADV_CARR_T
*carrier_buf
;
1942 ADV_CARR_T
*carr_freelist
; /* Carrier free list. */
1943 ADV_CARR_T
*icq_sp
; /* Initiator command queue stopper pointer. */
1944 ADV_CARR_T
*irq_sp
; /* Initiator response queue stopper pointer. */
1945 ushort carr_pending_cnt
; /* Count of pending carriers. */
1946 struct adv_req
*orig_reqp
; /* adv_req_t memory block. */
1948 * Note: The following fields will not be used after initialization. The
1949 * driver may discard the buffer after initialization is done.
1951 ADV_DVC_CFG
*cfg
; /* temporary configuration structure */
1955 * Microcode idle loop commands
1957 #define IDLE_CMD_COMPLETED 0
1958 #define IDLE_CMD_STOP_CHIP 0x0001
1959 #define IDLE_CMD_STOP_CHIP_SEND_INT 0x0002
1960 #define IDLE_CMD_SEND_INT 0x0004
1961 #define IDLE_CMD_ABORT 0x0008
1962 #define IDLE_CMD_DEVICE_RESET 0x0010
1963 #define IDLE_CMD_SCSI_RESET_START 0x0020 /* Assert SCSI Bus Reset */
1964 #define IDLE_CMD_SCSI_RESET_END 0x0040 /* Deassert SCSI Bus Reset */
1965 #define IDLE_CMD_SCSIREQ 0x0080
1967 #define IDLE_CMD_STATUS_SUCCESS 0x0001
1968 #define IDLE_CMD_STATUS_FAILURE 0x0002
1971 * AdvSendIdleCmd() flag definitions.
1973 #define ADV_NOWAIT 0x01
1976 * Wait loop time out values.
1978 #define SCSI_WAIT_100_MSEC 100UL /* 100 milliseconds */
1979 #define SCSI_US_PER_MSEC 1000 /* microseconds per millisecond */
1980 #define SCSI_MAX_RETRY 10 /* retry count */
1982 #define ADV_ASYNC_RDMA_FAILURE 0x01 /* Fatal RDMA failure. */
1983 #define ADV_ASYNC_SCSI_BUS_RESET_DET 0x02 /* Detected SCSI Bus Reset. */
1984 #define ADV_ASYNC_CARRIER_READY_FAILURE 0x03 /* Carrier Ready failure. */
1985 #define ADV_RDMA_IN_CARR_AND_Q_INVALID 0x04 /* RDMAed-in data invalid. */
1987 #define ADV_HOST_SCSI_BUS_RESET 0x80 /* Host Initiated SCSI Bus Reset. */
1989 /* Read byte from a register. */
1990 #define AdvReadByteRegister(iop_base, reg_off) \
1991 (ADV_MEM_READB((iop_base) + (reg_off)))
1993 /* Write byte to a register. */
1994 #define AdvWriteByteRegister(iop_base, reg_off, byte) \
1995 (ADV_MEM_WRITEB((iop_base) + (reg_off), (byte)))
1997 /* Read word (2 bytes) from a register. */
1998 #define AdvReadWordRegister(iop_base, reg_off) \
1999 (ADV_MEM_READW((iop_base) + (reg_off)))
2001 /* Write word (2 bytes) to a register. */
2002 #define AdvWriteWordRegister(iop_base, reg_off, word) \
2003 (ADV_MEM_WRITEW((iop_base) + (reg_off), (word)))
2005 /* Write dword (4 bytes) to a register. */
2006 #define AdvWriteDWordRegister(iop_base, reg_off, dword) \
2007 (ADV_MEM_WRITEDW((iop_base) + (reg_off), (dword)))
2009 /* Read byte from LRAM. */
2010 #define AdvReadByteLram(iop_base, addr, byte) \
2012 ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
2013 (byte) = ADV_MEM_READB((iop_base) + IOPB_RAM_DATA); \
2016 /* Write byte to LRAM. */
2017 #define AdvWriteByteLram(iop_base, addr, byte) \
2018 (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
2019 ADV_MEM_WRITEB((iop_base) + IOPB_RAM_DATA, (byte)))
2021 /* Read word (2 bytes) from LRAM. */
2022 #define AdvReadWordLram(iop_base, addr, word) \
2024 ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
2025 (word) = (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA)); \
2028 /* Write word (2 bytes) to LRAM. */
2029 #define AdvWriteWordLram(iop_base, addr, word) \
2030 (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
2031 ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
2033 /* Write little-endian double word (4 bytes) to LRAM */
2034 /* Because of unspecified C language ordering don't use auto-increment. */
2035 #define AdvWriteDWordLramNoSwap(iop_base, addr, dword) \
2036 ((ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
2037 ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
2038 cpu_to_le16((ushort) ((dword) & 0xFFFF)))), \
2039 (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr) + 2), \
2040 ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
2041 cpu_to_le16((ushort) ((dword >> 16) & 0xFFFF)))))
2043 /* Read word (2 bytes) from LRAM assuming that the address is already set. */
2044 #define AdvReadWordAutoIncLram(iop_base) \
2045 (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA))
2047 /* Write word (2 bytes) to LRAM assuming that the address is already set. */
2048 #define AdvWriteWordAutoIncLram(iop_base, word) \
2049 (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
2052 * Define macro to check for Condor signature.
2054 * Evaluate to ADV_TRUE if a Condor chip is found the specified port
2055 * address 'iop_base'. Otherwise evalue to ADV_FALSE.
2057 #define AdvFindSignature(iop_base) \
2058 (((AdvReadByteRegister((iop_base), IOPB_CHIP_ID_1) == \
2059 ADV_CHIP_ID_BYTE) && \
2060 (AdvReadWordRegister((iop_base), IOPW_CHIP_ID_0) == \
2061 ADV_CHIP_ID_WORD)) ? ADV_TRUE : ADV_FALSE)
2064 * Define macro to Return the version number of the chip at 'iop_base'.
2066 * The second parameter 'bus_type' is currently unused.
2068 #define AdvGetChipVersion(iop_base, bus_type) \
2069 AdvReadByteRegister((iop_base), IOPB_CHIP_TYPE_REV)
2072 * Abort an SRB in the chip's RISC Memory. The 'srb_ptr' argument must
2073 * match the ASC_SCSI_REQ_Q 'srb_ptr' field.
2075 * If the request has not yet been sent to the device it will simply be
2076 * aborted from RISC memory. If the request is disconnected it will be
2077 * aborted on reselection by sending an Abort Message to the target ID.
2080 * ADV_TRUE(1) - Queue was successfully aborted.
2081 * ADV_FALSE(0) - Queue was not found on the active queue list.
2083 #define AdvAbortQueue(asc_dvc, scsiq) \
2084 AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_ABORT, \
2088 * Send a Bus Device Reset Message to the specified target ID.
2090 * All outstanding commands will be purged if sending the
2091 * Bus Device Reset Message is successful.
2094 * ADV_TRUE(1) - All requests on the target are purged.
2095 * ADV_FALSE(0) - Couldn't issue Bus Device Reset Message; Requests
2098 #define AdvResetDevice(asc_dvc, target_id) \
2099 AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_DEVICE_RESET, \
2100 (ADV_DCNT) (target_id))
2103 * SCSI Wide Type definition.
2105 #define ADV_SCSI_BIT_ID_TYPE ushort
2108 * AdvInitScsiTarget() 'cntl_flag' options.
2110 #define ADV_SCAN_LUN 0x01
2111 #define ADV_CAPINFO_NOLUN 0x02
2114 * Convert target id to target id bit mask.
2116 #define ADV_TID_TO_TIDMASK(tid) (0x01 << ((tid) & ADV_MAX_TID))
2119 * ASC_SCSI_REQ_Q 'done_status' and 'host_status' return values.
2122 #define QD_NO_STATUS 0x00 /* Request not completed yet. */
2123 #define QD_NO_ERROR 0x01
2124 #define QD_ABORTED_BY_HOST 0x02
2125 #define QD_WITH_ERROR 0x04
2127 #define QHSTA_NO_ERROR 0x00
2128 #define QHSTA_M_SEL_TIMEOUT 0x11
2129 #define QHSTA_M_DATA_OVER_RUN 0x12
2130 #define QHSTA_M_UNEXPECTED_BUS_FREE 0x13
2131 #define QHSTA_M_QUEUE_ABORTED 0x15
2132 #define QHSTA_M_SXFR_SDMA_ERR 0x16 /* SXFR_STATUS SCSI DMA Error */
2133 #define QHSTA_M_SXFR_SXFR_PERR 0x17 /* SXFR_STATUS SCSI Bus Parity Error */
2134 #define QHSTA_M_RDMA_PERR 0x18 /* RISC PCI DMA parity error */
2135 #define QHSTA_M_SXFR_OFF_UFLW 0x19 /* SXFR_STATUS Offset Underflow */
2136 #define QHSTA_M_SXFR_OFF_OFLW 0x20 /* SXFR_STATUS Offset Overflow */
2137 #define QHSTA_M_SXFR_WD_TMO 0x21 /* SXFR_STATUS Watchdog Timeout */
2138 #define QHSTA_M_SXFR_DESELECTED 0x22 /* SXFR_STATUS Deselected */
2139 /* Note: QHSTA_M_SXFR_XFR_OFLW is identical to QHSTA_M_DATA_OVER_RUN. */
2140 #define QHSTA_M_SXFR_XFR_OFLW 0x12 /* SXFR_STATUS Transfer Overflow */
2141 #define QHSTA_M_SXFR_XFR_PH_ERR 0x24 /* SXFR_STATUS Transfer Phase Error */
2142 #define QHSTA_M_SXFR_UNKNOWN_ERROR 0x25 /* SXFR_STATUS Unknown Error */
2143 #define QHSTA_M_SCSI_BUS_RESET 0x30 /* Request aborted from SBR */
2144 #define QHSTA_M_SCSI_BUS_RESET_UNSOL 0x31 /* Request aborted from unsol. SBR */
2145 #define QHSTA_M_BUS_DEVICE_RESET 0x32 /* Request aborted from BDR */
2146 #define QHSTA_M_DIRECTION_ERR 0x35 /* Data Phase mismatch */
2147 #define QHSTA_M_DIRECTION_ERR_HUNG 0x36 /* Data Phase mismatch and bus hang */
2148 #define QHSTA_M_WTM_TIMEOUT 0x41
2149 #define QHSTA_M_BAD_CMPL_STATUS_IN 0x42
2150 #define QHSTA_M_NO_AUTO_REQ_SENSE 0x43
2151 #define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
2152 #define QHSTA_M_INVALID_DEVICE 0x45 /* Bad target ID */
2153 #define QHSTA_M_FROZEN_TIDQ 0x46 /* TID Queue frozen. */
2154 #define QHSTA_M_SGBACKUP_ERROR 0x47 /* Scatter-Gather backup error */
2156 /* Return the address that is aligned at the next doubleword >= to 'addr'. */
2157 #define ADV_8BALIGN(addr) (((ulong) (addr) + 0x7) & ~0x7)
2158 #define ADV_16BALIGN(addr) (((ulong) (addr) + 0xF) & ~0xF)
2159 #define ADV_32BALIGN(addr) (((ulong) (addr) + 0x1F) & ~0x1F)
2162 * Total contiguous memory needed for driver SG blocks.
2164 * ADV_MAX_SG_LIST must be defined by a driver. It is the maximum
2165 * number of scatter-gather elements the driver supports in a
2169 #define ADV_SG_LIST_MAX_BYTE_SIZE \
2170 (sizeof(ADV_SG_BLOCK) * \
2171 ((ADV_MAX_SG_LIST + (NO_OF_SG_PER_BLOCK - 1))/NO_OF_SG_PER_BLOCK))
2173 /* struct asc_board flags */
2174 #define ASC_IS_WIDE_BOARD 0x04 /* AdvanSys Wide Board */
2176 #define ASC_NARROW_BOARD(boardp) (((boardp)->flags & ASC_IS_WIDE_BOARD) == 0)
2178 #define NO_ISA_DMA 0xff /* No ISA DMA Channel Used */
2180 #define ASC_INFO_SIZE 128 /* advansys_info() line size */
2182 #ifdef CONFIG_PROC_FS
2183 /* /proc/scsi/advansys/[0...] related definitions */
2184 #define ASC_PRTBUF_SIZE 2048
2185 #define ASC_PRTLINE_SIZE 160
2187 #define ASC_PRT_NEXT() \
2191 if (leftlen == 0) { \
2196 #endif /* CONFIG_PROC_FS */
2198 /* Asc Library return codes */
2201 #define ASC_NOERROR 1
2203 #define ASC_ERROR (-1)
2205 /* struct scsi_cmnd function return codes */
2206 #define STATUS_BYTE(byte) (byte)
2207 #define MSG_BYTE(byte) ((byte) << 8)
2208 #define HOST_BYTE(byte) ((byte) << 16)
2209 #define DRIVER_BYTE(byte) ((byte) << 24)
2211 #define ASC_STATS(shost, counter) ASC_STATS_ADD(shost, counter, 1)
2212 #ifndef ADVANSYS_STATS
2213 #define ASC_STATS_ADD(shost, counter, count)
2214 #else /* ADVANSYS_STATS */
2215 #define ASC_STATS_ADD(shost, counter, count) \
2216 (((struct asc_board *) shost_priv(shost))->asc_stats.counter += (count))
2217 #endif /* ADVANSYS_STATS */
2219 /* If the result wraps when calculating tenths, return 0. */
2220 #define ASC_TENTHS(num, den) \
2221 (((10 * ((num)/(den))) > (((num) * 10)/(den))) ? \
2222 0 : ((((num) * 10)/(den)) - (10 * ((num)/(den)))))
2225 * Display a message to the console.
2227 #define ASC_PRINT(s) \
2229 printk("advansys: "); \
2233 #define ASC_PRINT1(s, a1) \
2235 printk("advansys: "); \
2236 printk((s), (a1)); \
2239 #define ASC_PRINT2(s, a1, a2) \
2241 printk("advansys: "); \
2242 printk((s), (a1), (a2)); \
2245 #define ASC_PRINT3(s, a1, a2, a3) \
2247 printk("advansys: "); \
2248 printk((s), (a1), (a2), (a3)); \
2251 #define ASC_PRINT4(s, a1, a2, a3, a4) \
2253 printk("advansys: "); \
2254 printk((s), (a1), (a2), (a3), (a4)); \
2257 #ifndef ADVANSYS_DEBUG
2259 #define ASC_DBG(lvl, s...)
2260 #define ASC_DBG_PRT_SCSI_HOST(lvl, s)
2261 #define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp)
2262 #define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
2263 #define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone)
2264 #define ADV_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
2265 #define ASC_DBG_PRT_HEX(lvl, name, start, length)
2266 #define ASC_DBG_PRT_CDB(lvl, cdb, len)
2267 #define ASC_DBG_PRT_SENSE(lvl, sense, len)
2268 #define ASC_DBG_PRT_INQUIRY(lvl, inq, len)
2270 #else /* ADVANSYS_DEBUG */
2273 * Debugging Message Levels:
2275 * 1: High-Level Tracing
2276 * 2-N: Verbose Tracing
2279 #define ASC_DBG(lvl, format, arg...) { \
2280 if (asc_dbglvl >= (lvl)) \
2281 printk(KERN_DEBUG "%s: %s: " format, DRV_NAME, \
2282 __func__ , ## arg); \
2285 #define ASC_DBG_PRT_SCSI_HOST(lvl, s) \
2287 if (asc_dbglvl >= (lvl)) { \
2288 asc_prt_scsi_host(s); \
2292 #define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp) \
2294 if (asc_dbglvl >= (lvl)) { \
2295 asc_prt_asc_scsi_q(scsiqp); \
2299 #define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone) \
2301 if (asc_dbglvl >= (lvl)) { \
2302 asc_prt_asc_qdone_info(qdone); \
2306 #define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp) \
2308 if (asc_dbglvl >= (lvl)) { \
2309 asc_prt_adv_scsi_req_q(scsiqp); \
2313 #define ASC_DBG_PRT_HEX(lvl, name, start, length) \
2315 if (asc_dbglvl >= (lvl)) { \
2316 asc_prt_hex((name), (start), (length)); \
2320 #define ASC_DBG_PRT_CDB(lvl, cdb, len) \
2321 ASC_DBG_PRT_HEX((lvl), "CDB", (uchar *) (cdb), (len));
2323 #define ASC_DBG_PRT_SENSE(lvl, sense, len) \
2324 ASC_DBG_PRT_HEX((lvl), "SENSE", (uchar *) (sense), (len));
2326 #define ASC_DBG_PRT_INQUIRY(lvl, inq, len) \
2327 ASC_DBG_PRT_HEX((lvl), "INQUIRY", (uchar *) (inq), (len));
2328 #endif /* ADVANSYS_DEBUG */
2330 #ifdef ADVANSYS_STATS
2332 /* Per board statistics structure */
2334 /* Driver Entrypoint Statistics */
2335 ADV_DCNT queuecommand
; /* # calls to advansys_queuecommand() */
2336 ADV_DCNT reset
; /* # calls to advansys_eh_bus_reset() */
2337 ADV_DCNT biosparam
; /* # calls to advansys_biosparam() */
2338 ADV_DCNT interrupt
; /* # advansys_interrupt() calls */
2339 ADV_DCNT callback
; /* # calls to asc/adv_isr_callback() */
2340 ADV_DCNT done
; /* # calls to request's scsi_done function */
2341 ADV_DCNT build_error
; /* # asc/adv_build_req() ASC_ERROR returns. */
2342 ADV_DCNT adv_build_noreq
; /* # adv_build_req() adv_req_t alloc. fail. */
2343 ADV_DCNT adv_build_nosg
; /* # adv_build_req() adv_sgblk_t alloc. fail. */
2344 /* AscExeScsiQueue()/AdvExeScsiQueue() Statistics */
2345 ADV_DCNT exe_noerror
; /* # ASC_NOERROR returns. */
2346 ADV_DCNT exe_busy
; /* # ASC_BUSY returns. */
2347 ADV_DCNT exe_error
; /* # ASC_ERROR returns. */
2348 ADV_DCNT exe_unknown
; /* # unknown returns. */
2349 /* Data Transfer Statistics */
2350 ADV_DCNT xfer_cnt
; /* # I/O requests received */
2351 ADV_DCNT xfer_elem
; /* # scatter-gather elements */
2352 ADV_DCNT xfer_sect
; /* # 512-byte blocks */
2354 #endif /* ADVANSYS_STATS */
2357 * Structure allocated for each board.
2359 * This structure is allocated by scsi_host_alloc() at the end
2360 * of the 'Scsi_Host' structure starting at the 'hostdata'
2361 * field. It is guaranteed to be allocated from DMA-able memory.
2365 uint flags
; /* Board flags */
2368 ASC_DVC_VAR asc_dvc_var
; /* Narrow board */
2369 ADV_DVC_VAR adv_dvc_var
; /* Wide board */
2372 ASC_DVC_CFG asc_dvc_cfg
; /* Narrow board */
2373 ADV_DVC_CFG adv_dvc_cfg
; /* Wide board */
2375 ushort asc_n_io_port
; /* Number I/O ports. */
2376 ADV_SCSI_BIT_ID_TYPE init_tidmask
; /* Target init./valid mask */
2377 ushort reqcnt
[ADV_MAX_TID
+ 1]; /* Starvation request count */
2378 ADV_SCSI_BIT_ID_TYPE queue_full
; /* Queue full mask */
2379 ushort queue_full_cnt
[ADV_MAX_TID
+ 1]; /* Queue full count */
2381 ASCEEP_CONFIG asc_eep
; /* Narrow EEPROM config. */
2382 ADVEEP_3550_CONFIG adv_3550_eep
; /* 3550 EEPROM config. */
2383 ADVEEP_38C0800_CONFIG adv_38C0800_eep
; /* 38C0800 EEPROM config. */
2384 ADVEEP_38C1600_CONFIG adv_38C1600_eep
; /* 38C1600 EEPROM config. */
2386 ulong last_reset
; /* Saved last reset time */
2387 /* /proc/scsi/advansys/[0...] */
2388 char *prtbuf
; /* /proc print buffer */
2389 #ifdef ADVANSYS_STATS
2390 struct asc_stats asc_stats
; /* Board statistics */
2391 #endif /* ADVANSYS_STATS */
2393 * The following fields are used only for Narrow Boards.
2395 uchar sdtr_data
[ASC_MAX_TID
+ 1]; /* SDTR information */
2397 * The following fields are used only for Wide Boards.
2399 void __iomem
*ioremap_addr
; /* I/O Memory remap address. */
2400 ushort ioport
; /* I/O Port address. */
2401 adv_req_t
*adv_reqp
; /* Request structures. */
2402 adv_sgblk_t
*adv_sgblkp
; /* Scatter-gather structures. */
2403 ushort bios_signature
; /* BIOS Signature. */
2404 ushort bios_version
; /* BIOS Version. */
2405 ushort bios_codeseg
; /* BIOS Code Segment. */
2406 ushort bios_codelen
; /* BIOS Code Segment Length. */
2409 #define asc_dvc_to_board(asc_dvc) container_of(asc_dvc, struct asc_board, \
2410 dvc_var.asc_dvc_var)
2411 #define adv_dvc_to_board(adv_dvc) container_of(adv_dvc, struct asc_board, \
2412 dvc_var.adv_dvc_var)
2413 #define adv_dvc_to_pdev(adv_dvc) to_pci_dev(adv_dvc_to_board(adv_dvc)->dev)
2415 #ifdef ADVANSYS_DEBUG
2416 static int asc_dbglvl
= 3;
2419 * asc_prt_asc_dvc_var()
2421 static void asc_prt_asc_dvc_var(ASC_DVC_VAR
*h
)
2423 printk("ASC_DVC_VAR at addr 0x%lx\n", (ulong
)h
);
2425 printk(" iop_base 0x%x, err_code 0x%x, dvc_cntl 0x%x, bug_fix_cntl "
2426 "%d,\n", h
->iop_base
, h
->err_code
, h
->dvc_cntl
, h
->bug_fix_cntl
);
2428 printk(" bus_type %d, init_sdtr 0x%x,\n", h
->bus_type
,
2429 (unsigned)h
->init_sdtr
);
2431 printk(" sdtr_done 0x%x, use_tagged_qng 0x%x, unit_not_ready 0x%x, "
2432 "chip_no 0x%x,\n", (unsigned)h
->sdtr_done
,
2433 (unsigned)h
->use_tagged_qng
, (unsigned)h
->unit_not_ready
,
2434 (unsigned)h
->chip_no
);
2436 printk(" queue_full_or_busy 0x%x, start_motor 0x%x, scsi_reset_wait "
2437 "%u,\n", (unsigned)h
->queue_full_or_busy
,
2438 (unsigned)h
->start_motor
, (unsigned)h
->scsi_reset_wait
);
2440 printk(" is_in_int %u, max_total_qng %u, cur_total_qng %u, "
2441 "in_critical_cnt %u,\n", (unsigned)h
->is_in_int
,
2442 (unsigned)h
->max_total_qng
, (unsigned)h
->cur_total_qng
,
2443 (unsigned)h
->in_critical_cnt
);
2445 printk(" last_q_shortage %u, init_state 0x%x, no_scam 0x%x, "
2446 "pci_fix_asyn_xfer 0x%x,\n", (unsigned)h
->last_q_shortage
,
2447 (unsigned)h
->init_state
, (unsigned)h
->no_scam
,
2448 (unsigned)h
->pci_fix_asyn_xfer
);
2450 printk(" cfg 0x%lx\n", (ulong
)h
->cfg
);
2454 * asc_prt_asc_dvc_cfg()
2456 static void asc_prt_asc_dvc_cfg(ASC_DVC_CFG
*h
)
2458 printk("ASC_DVC_CFG at addr 0x%lx\n", (ulong
)h
);
2460 printk(" can_tagged_qng 0x%x, cmd_qng_enabled 0x%x,\n",
2461 h
->can_tagged_qng
, h
->cmd_qng_enabled
);
2462 printk(" disc_enable 0x%x, sdtr_enable 0x%x,\n",
2463 h
->disc_enable
, h
->sdtr_enable
);
2465 printk(" chip_scsi_id %d, isa_dma_speed %d, isa_dma_channel %d, "
2466 "chip_version %d,\n", h
->chip_scsi_id
, h
->isa_dma_speed
,
2467 h
->isa_dma_channel
, h
->chip_version
);
2469 printk(" mcode_date 0x%x, mcode_version %d\n",
2470 h
->mcode_date
, h
->mcode_version
);
2474 * asc_prt_adv_dvc_var()
2476 * Display an ADV_DVC_VAR structure.
2478 static void asc_prt_adv_dvc_var(ADV_DVC_VAR
*h
)
2480 printk(" ADV_DVC_VAR at addr 0x%lx\n", (ulong
)h
);
2482 printk(" iop_base 0x%lx, err_code 0x%x, ultra_able 0x%x\n",
2483 (ulong
)h
->iop_base
, h
->err_code
, (unsigned)h
->ultra_able
);
2485 printk(" sdtr_able 0x%x, wdtr_able 0x%x\n",
2486 (unsigned)h
->sdtr_able
, (unsigned)h
->wdtr_able
);
2488 printk(" start_motor 0x%x, scsi_reset_wait 0x%x\n",
2489 (unsigned)h
->start_motor
, (unsigned)h
->scsi_reset_wait
);
2491 printk(" max_host_qng %u, max_dvc_qng %u, carr_freelist 0x%lxn\n",
2492 (unsigned)h
->max_host_qng
, (unsigned)h
->max_dvc_qng
,
2493 (ulong
)h
->carr_freelist
);
2495 printk(" icq_sp 0x%lx, irq_sp 0x%lx\n",
2496 (ulong
)h
->icq_sp
, (ulong
)h
->irq_sp
);
2498 printk(" no_scam 0x%x, tagqng_able 0x%x\n",
2499 (unsigned)h
->no_scam
, (unsigned)h
->tagqng_able
);
2501 printk(" chip_scsi_id 0x%x, cfg 0x%lx\n",
2502 (unsigned)h
->chip_scsi_id
, (ulong
)h
->cfg
);
2506 * asc_prt_adv_dvc_cfg()
2508 * Display an ADV_DVC_CFG structure.
2510 static void asc_prt_adv_dvc_cfg(ADV_DVC_CFG
*h
)
2512 printk(" ADV_DVC_CFG at addr 0x%lx\n", (ulong
)h
);
2514 printk(" disc_enable 0x%x, termination 0x%x\n",
2515 h
->disc_enable
, h
->termination
);
2517 printk(" chip_version 0x%x, mcode_date 0x%x\n",
2518 h
->chip_version
, h
->mcode_date
);
2520 printk(" mcode_version 0x%x, control_flag 0x%x\n",
2521 h
->mcode_version
, h
->control_flag
);
2525 * asc_prt_scsi_host()
2527 static void asc_prt_scsi_host(struct Scsi_Host
*s
)
2529 struct asc_board
*boardp
= shost_priv(s
);
2531 printk("Scsi_Host at addr 0x%p, device %s\n", s
, dev_name(boardp
->dev
));
2532 printk(" host_busy %u, host_no %d, last_reset %d,\n",
2533 s
->host_busy
, s
->host_no
, (unsigned)s
->last_reset
);
2535 printk(" base 0x%lx, io_port 0x%lx, irq %d,\n",
2536 (ulong
)s
->base
, (ulong
)s
->io_port
, boardp
->irq
);
2538 printk(" dma_channel %d, this_id %d, can_queue %d,\n",
2539 s
->dma_channel
, s
->this_id
, s
->can_queue
);
2541 printk(" cmd_per_lun %d, sg_tablesize %d, unchecked_isa_dma %d\n",
2542 s
->cmd_per_lun
, s
->sg_tablesize
, s
->unchecked_isa_dma
);
2544 if (ASC_NARROW_BOARD(boardp
)) {
2545 asc_prt_asc_dvc_var(&boardp
->dvc_var
.asc_dvc_var
);
2546 asc_prt_asc_dvc_cfg(&boardp
->dvc_cfg
.asc_dvc_cfg
);
2548 asc_prt_adv_dvc_var(&boardp
->dvc_var
.adv_dvc_var
);
2549 asc_prt_adv_dvc_cfg(&boardp
->dvc_cfg
.adv_dvc_cfg
);
2556 * Print hexadecimal output in 4 byte groupings 32 bytes
2557 * or 8 double-words per line.
2559 static void asc_prt_hex(char *f
, uchar
*s
, int l
)
2566 printk("%s: (%d bytes)\n", f
, l
);
2568 for (i
= 0; i
< l
; i
+= 32) {
2570 /* Display a maximum of 8 double-words per line. */
2571 if ((k
= (l
- i
) / 4) >= 8) {
2578 for (j
= 0; j
< k
; j
++) {
2579 printk(" %2.2X%2.2X%2.2X%2.2X",
2580 (unsigned)s
[i
+ (j
* 4)],
2581 (unsigned)s
[i
+ (j
* 4) + 1],
2582 (unsigned)s
[i
+ (j
* 4) + 2],
2583 (unsigned)s
[i
+ (j
* 4) + 3]);
2591 printk(" %2.2X", (unsigned)s
[i
+ (j
* 4)]);
2594 printk(" %2.2X%2.2X",
2595 (unsigned)s
[i
+ (j
* 4)],
2596 (unsigned)s
[i
+ (j
* 4) + 1]);
2599 printk(" %2.2X%2.2X%2.2X",
2600 (unsigned)s
[i
+ (j
* 4) + 1],
2601 (unsigned)s
[i
+ (j
* 4) + 2],
2602 (unsigned)s
[i
+ (j
* 4) + 3]);
2611 * asc_prt_asc_scsi_q()
2613 static void asc_prt_asc_scsi_q(ASC_SCSI_Q
*q
)
2618 printk("ASC_SCSI_Q at addr 0x%lx\n", (ulong
)q
);
2621 (" target_ix 0x%x, target_lun %u, srb_ptr 0x%lx, tag_code 0x%x,\n",
2622 q
->q2
.target_ix
, q
->q1
.target_lun
, (ulong
)q
->q2
.srb_ptr
,
2626 (" data_addr 0x%lx, data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
2627 (ulong
)le32_to_cpu(q
->q1
.data_addr
),
2628 (ulong
)le32_to_cpu(q
->q1
.data_cnt
),
2629 (ulong
)le32_to_cpu(q
->q1
.sense_addr
), q
->q1
.sense_len
);
2631 printk(" cdbptr 0x%lx, cdb_len %u, sg_head 0x%lx, sg_queue_cnt %u\n",
2632 (ulong
)q
->cdbptr
, q
->q2
.cdb_len
,
2633 (ulong
)q
->sg_head
, q
->q1
.sg_queue_cnt
);
2637 printk("ASC_SG_HEAD at addr 0x%lx\n", (ulong
)sgp
);
2638 printk(" entry_cnt %u, queue_cnt %u\n", sgp
->entry_cnt
,
2640 for (i
= 0; i
< sgp
->entry_cnt
; i
++) {
2641 printk(" [%u]: addr 0x%lx, bytes %lu\n",
2642 i
, (ulong
)le32_to_cpu(sgp
->sg_list
[i
].addr
),
2643 (ulong
)le32_to_cpu(sgp
->sg_list
[i
].bytes
));
2650 * asc_prt_asc_qdone_info()
2652 static void asc_prt_asc_qdone_info(ASC_QDONE_INFO
*q
)
2654 printk("ASC_QDONE_INFO at addr 0x%lx\n", (ulong
)q
);
2655 printk(" srb_ptr 0x%lx, target_ix %u, cdb_len %u, tag_code %u,\n",
2656 (ulong
)q
->d2
.srb_ptr
, q
->d2
.target_ix
, q
->d2
.cdb_len
,
2659 (" done_stat 0x%x, host_stat 0x%x, scsi_stat 0x%x, scsi_msg 0x%x\n",
2660 q
->d3
.done_stat
, q
->d3
.host_stat
, q
->d3
.scsi_stat
, q
->d3
.scsi_msg
);
2664 * asc_prt_adv_sgblock()
2666 * Display an ADV_SG_BLOCK structure.
2668 static void asc_prt_adv_sgblock(int sgblockno
, ADV_SG_BLOCK
*b
)
2672 printk(" ASC_SG_BLOCK at addr 0x%lx (sgblockno %d)\n",
2673 (ulong
)b
, sgblockno
);
2674 printk(" sg_cnt %u, sg_ptr 0x%lx\n",
2675 b
->sg_cnt
, (ulong
)le32_to_cpu(b
->sg_ptr
));
2676 BUG_ON(b
->sg_cnt
> NO_OF_SG_PER_BLOCK
);
2678 BUG_ON(b
->sg_cnt
!= NO_OF_SG_PER_BLOCK
);
2679 for (i
= 0; i
< b
->sg_cnt
; i
++) {
2680 printk(" [%u]: sg_addr 0x%lx, sg_count 0x%lx\n",
2681 i
, (ulong
)b
->sg_list
[i
].sg_addr
,
2682 (ulong
)b
->sg_list
[i
].sg_count
);
2687 * asc_prt_adv_scsi_req_q()
2689 * Display an ADV_SCSI_REQ_Q structure.
2691 static void asc_prt_adv_scsi_req_q(ADV_SCSI_REQ_Q
*q
)
2694 struct asc_sg_block
*sg_ptr
;
2696 printk("ADV_SCSI_REQ_Q at addr 0x%lx\n", (ulong
)q
);
2698 printk(" target_id %u, target_lun %u, srb_ptr 0x%lx, a_flag 0x%x\n",
2699 q
->target_id
, q
->target_lun
, (ulong
)q
->srb_ptr
, q
->a_flag
);
2701 printk(" cntl 0x%x, data_addr 0x%lx, vdata_addr 0x%lx\n",
2702 q
->cntl
, (ulong
)le32_to_cpu(q
->data_addr
), (ulong
)q
->vdata_addr
);
2704 printk(" data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
2705 (ulong
)le32_to_cpu(q
->data_cnt
),
2706 (ulong
)le32_to_cpu(q
->sense_addr
), q
->sense_len
);
2709 (" cdb_len %u, done_status 0x%x, host_status 0x%x, scsi_status 0x%x\n",
2710 q
->cdb_len
, q
->done_status
, q
->host_status
, q
->scsi_status
);
2712 printk(" sg_working_ix 0x%x, target_cmd %u\n",
2713 q
->sg_working_ix
, q
->target_cmd
);
2715 printk(" scsiq_rptr 0x%lx, sg_real_addr 0x%lx, sg_list_ptr 0x%lx\n",
2716 (ulong
)le32_to_cpu(q
->scsiq_rptr
),
2717 (ulong
)le32_to_cpu(q
->sg_real_addr
), (ulong
)q
->sg_list_ptr
);
2719 /* Display the request's ADV_SG_BLOCK structures. */
2720 if (q
->sg_list_ptr
!= NULL
) {
2724 * 'sg_ptr' is a physical address. Convert it to a virtual
2725 * address by indexing 'sg_blk_cnt' into the virtual address
2726 * array 'sg_list_ptr'.
2728 * XXX - Assumes all SG physical blocks are virtually contiguous.
2731 &(((ADV_SG_BLOCK
*)(q
->sg_list_ptr
))[sg_blk_cnt
]);
2732 asc_prt_adv_sgblock(sg_blk_cnt
, sg_ptr
);
2733 if (sg_ptr
->sg_ptr
== 0) {
2740 #endif /* ADVANSYS_DEBUG */
2743 * The advansys chip/microcode contains a 32-bit identifier for each command
2744 * known as the 'srb'. I don't know what it stands for. The driver used
2745 * to encode the scsi_cmnd pointer by calling virt_to_bus and retrieve it
2746 * with bus_to_virt. Now the driver keeps a per-host map of integers to
2747 * pointers. It auto-expands when full, unless it can't allocate memory.
2748 * Note that an srb of 0 is treated specially by the chip/firmware, hence
2749 * the return of i+1 in this routine, and the corresponding subtraction in
2750 * the inverse routine.
2753 static u32
advansys_ptr_to_srb(struct asc_dvc_var
*asc_dvc
, void *ptr
)
2758 for (i
= 0; i
< asc_dvc
->ptr_map_count
; i
++) {
2759 if (!asc_dvc
->ptr_map
[i
])
2763 if (asc_dvc
->ptr_map_count
== 0)
2764 asc_dvc
->ptr_map_count
= 1;
2766 asc_dvc
->ptr_map_count
*= 2;
2768 new_ptr
= krealloc(asc_dvc
->ptr_map
,
2769 asc_dvc
->ptr_map_count
* sizeof(void *), GFP_ATOMIC
);
2772 asc_dvc
->ptr_map
= new_ptr
;
2774 ASC_DBG(3, "Putting ptr %p into array offset %d\n", ptr
, i
);
2775 asc_dvc
->ptr_map
[i
] = ptr
;
2779 static void * advansys_srb_to_ptr(struct asc_dvc_var
*asc_dvc
, u32 srb
)
2784 if (srb
>= asc_dvc
->ptr_map_count
) {
2785 printk("advansys: bad SRB %u, max %u\n", srb
,
2786 asc_dvc
->ptr_map_count
);
2789 ptr
= asc_dvc
->ptr_map
[srb
];
2790 asc_dvc
->ptr_map
[srb
] = NULL
;
2791 ASC_DBG(3, "Returning ptr %p from array offset %d\n", ptr
, srb
);
2798 * Return suitable for printing on the console with the argument
2799 * adapter's configuration information.
2801 * Note: The information line should not exceed ASC_INFO_SIZE bytes,
2802 * otherwise the static 'info' array will be overrun.
2804 static const char *advansys_info(struct Scsi_Host
*shost
)
2806 static char info
[ASC_INFO_SIZE
];
2807 struct asc_board
*boardp
= shost_priv(shost
);
2808 ASC_DVC_VAR
*asc_dvc_varp
;
2809 ADV_DVC_VAR
*adv_dvc_varp
;
2811 char *widename
= NULL
;
2813 if (ASC_NARROW_BOARD(boardp
)) {
2814 asc_dvc_varp
= &boardp
->dvc_var
.asc_dvc_var
;
2815 ASC_DBG(1, "begin\n");
2816 if (asc_dvc_varp
->bus_type
& ASC_IS_ISA
) {
2817 if ((asc_dvc_varp
->bus_type
& ASC_IS_ISAPNP
) ==
2819 busname
= "ISA PnP";
2824 "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X, DMA 0x%X",
2825 ASC_VERSION
, busname
,
2826 (ulong
)shost
->io_port
,
2827 (ulong
)shost
->io_port
+ ASC_IOADR_GAP
- 1,
2828 boardp
->irq
, shost
->dma_channel
);
2830 if (asc_dvc_varp
->bus_type
& ASC_IS_VL
) {
2832 } else if (asc_dvc_varp
->bus_type
& ASC_IS_EISA
) {
2834 } else if (asc_dvc_varp
->bus_type
& ASC_IS_PCI
) {
2835 if ((asc_dvc_varp
->bus_type
& ASC_IS_PCI_ULTRA
)
2836 == ASC_IS_PCI_ULTRA
) {
2837 busname
= "PCI Ultra";
2843 shost_printk(KERN_ERR
, shost
, "unknown bus "
2844 "type %d\n", asc_dvc_varp
->bus_type
);
2847 "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X",
2848 ASC_VERSION
, busname
, (ulong
)shost
->io_port
,
2849 (ulong
)shost
->io_port
+ ASC_IOADR_GAP
- 1,
2854 * Wide Adapter Information
2856 * Memory-mapped I/O is used instead of I/O space to access
2857 * the adapter, but display the I/O Port range. The Memory
2858 * I/O address is displayed through the driver /proc file.
2860 adv_dvc_varp
= &boardp
->dvc_var
.adv_dvc_var
;
2861 if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC3550
) {
2862 widename
= "Ultra-Wide";
2863 } else if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC38C0800
) {
2864 widename
= "Ultra2-Wide";
2866 widename
= "Ultra3-Wide";
2869 "AdvanSys SCSI %s: PCI %s: PCIMEM 0x%lX-0x%lX, IRQ 0x%X",
2870 ASC_VERSION
, widename
, (ulong
)adv_dvc_varp
->iop_base
,
2871 (ulong
)adv_dvc_varp
->iop_base
+ boardp
->asc_n_io_port
- 1, boardp
->irq
);
2873 BUG_ON(strlen(info
) >= ASC_INFO_SIZE
);
2874 ASC_DBG(1, "end\n");
2878 #ifdef CONFIG_PROC_FS
2882 * If 'cp' is NULL print to the console, otherwise print to a buffer.
2884 * Return 0 if printing to the console, otherwise return the number of
2885 * bytes written to the buffer.
2887 * Note: If any single line is greater than ASC_PRTLINE_SIZE bytes the stack
2888 * will be corrupted. 's[]' is defined to be ASC_PRTLINE_SIZE bytes.
2890 static int asc_prt_line(char *buf
, int buflen
, char *fmt
, ...)
2894 char s
[ASC_PRTLINE_SIZE
];
2896 va_start(args
, fmt
);
2897 ret
= vsprintf(s
, fmt
, args
);
2898 BUG_ON(ret
>= ASC_PRTLINE_SIZE
);
2903 ret
= min(buflen
, ret
);
2904 memcpy(buf
, s
, ret
);
2911 * asc_prt_board_devices()
2913 * Print driver information for devices attached to the board.
2915 * Note: no single line should be greater than ASC_PRTLINE_SIZE,
2916 * cf. asc_prt_line().
2918 * Return the number of characters copied into 'cp'. No more than
2919 * 'cplen' characters will be copied to 'cp'.
2921 static int asc_prt_board_devices(struct Scsi_Host
*shost
, char *cp
, int cplen
)
2923 struct asc_board
*boardp
= shost_priv(shost
);
2933 len
= asc_prt_line(cp
, leftlen
,
2934 "\nDevice Information for AdvanSys SCSI Host %d:\n",
2938 if (ASC_NARROW_BOARD(boardp
)) {
2939 chip_scsi_id
= boardp
->dvc_cfg
.asc_dvc_cfg
.chip_scsi_id
;
2941 chip_scsi_id
= boardp
->dvc_var
.adv_dvc_var
.chip_scsi_id
;
2944 len
= asc_prt_line(cp
, leftlen
, "Target IDs Detected:");
2946 for (i
= 0; i
<= ADV_MAX_TID
; i
++) {
2947 if (boardp
->init_tidmask
& ADV_TID_TO_TIDMASK(i
)) {
2948 len
= asc_prt_line(cp
, leftlen
, " %X,", i
);
2952 len
= asc_prt_line(cp
, leftlen
, " (%X=Host Adapter)\n", chip_scsi_id
);
2959 * Display Wide Board BIOS Information.
2961 static int asc_prt_adv_bios(struct Scsi_Host
*shost
, char *cp
, int cplen
)
2963 struct asc_board
*boardp
= shost_priv(shost
);
2967 ushort major
, minor
, letter
;
2972 len
= asc_prt_line(cp
, leftlen
, "\nROM BIOS Version: ");
2976 * If the BIOS saved a valid signature, then fill in
2977 * the BIOS code segment base address.
2979 if (boardp
->bios_signature
!= 0x55AA) {
2980 len
= asc_prt_line(cp
, leftlen
, "Disabled or Pre-3.1\n");
2982 len
= asc_prt_line(cp
, leftlen
,
2983 "BIOS either disabled or Pre-3.1. If it is pre-3.1, then a newer version\n");
2985 len
= asc_prt_line(cp
, leftlen
,
2986 "can be found at the ConnectCom FTP site: ftp://ftp.connectcom.net/pub\n");
2989 major
= (boardp
->bios_version
>> 12) & 0xF;
2990 minor
= (boardp
->bios_version
>> 8) & 0xF;
2991 letter
= (boardp
->bios_version
& 0xFF);
2993 len
= asc_prt_line(cp
, leftlen
, "%d.%d%c\n",
2995 letter
>= 26 ? '?' : letter
+ 'A');
2999 * Current available ROM BIOS release is 3.1I for UW
3000 * and 3.2I for U2W. This code doesn't differentiate
3001 * UW and U2W boards.
3003 if (major
< 3 || (major
<= 3 && minor
< 1) ||
3004 (major
<= 3 && minor
<= 1 && letter
< ('I' - 'A'))) {
3005 len
= asc_prt_line(cp
, leftlen
,
3006 "Newer version of ROM BIOS is available at the ConnectCom FTP site:\n");
3008 len
= asc_prt_line(cp
, leftlen
,
3009 "ftp://ftp.connectcom.net/pub\n");
3018 * Add serial number to information bar if signature AAh
3019 * is found in at bit 15-9 (7 bits) of word 1.
3021 * Serial Number consists fo 12 alpha-numeric digits.
3023 * 1 - Product type (A,B,C,D..) Word0: 15-13 (3 bits)
3024 * 2 - MFG Location (A,B,C,D..) Word0: 12-10 (3 bits)
3025 * 3-4 - Product ID (0-99) Word0: 9-0 (10 bits)
3026 * 5 - Product revision (A-J) Word0: " "
3028 * Signature Word1: 15-9 (7 bits)
3029 * 6 - Year (0-9) Word1: 8-6 (3 bits) & Word2: 15 (1 bit)
3030 * 7-8 - Week of the year (1-52) Word1: 5-0 (6 bits)
3032 * 9-12 - Serial Number (A001-Z999) Word2: 14-0 (15 bits)
3034 * Note 1: Only production cards will have a serial number.
3036 * Note 2: Signature is most significant 7 bits (0xFE).
3038 * Returns ASC_TRUE if serial number found, otherwise returns ASC_FALSE.
3040 static int asc_get_eeprom_string(ushort
*serialnum
, uchar
*cp
)
3044 if ((serialnum
[1] & 0xFE00) != ((ushort
)0xAA << 8)) {
3048 * First word - 6 digits.
3052 /* Product type - 1st digit. */
3053 if ((*cp
= 'A' + ((w
& 0xE000) >> 13)) == 'H') {
3054 /* Product type is P=Prototype */
3059 /* Manufacturing location - 2nd digit. */
3060 *cp
++ = 'A' + ((w
& 0x1C00) >> 10);
3062 /* Product ID - 3rd, 4th digits. */
3064 *cp
++ = '0' + (num
/ 100);
3066 *cp
++ = '0' + (num
/ 10);
3068 /* Product revision - 5th digit. */
3069 *cp
++ = 'A' + (num
% 10);
3079 * If bit 15 of third word is set, then the
3080 * last digit of the year is greater than 7.
3082 if (serialnum
[2] & 0x8000) {
3083 *cp
++ = '8' + ((w
& 0x1C0) >> 6);
3085 *cp
++ = '0' + ((w
& 0x1C0) >> 6);
3088 /* Week of year - 7th, 8th digits. */
3090 *cp
++ = '0' + num
/ 10;
3097 w
= serialnum
[2] & 0x7FFF;
3099 /* Serial number - 9th digit. */
3100 *cp
++ = 'A' + (w
/ 1000);
3102 /* 10th, 11th, 12th digits. */
3104 *cp
++ = '0' + num
/ 100;
3106 *cp
++ = '0' + num
/ 10;
3110 *cp
= '\0'; /* Null Terminate the string. */
3116 * asc_prt_asc_board_eeprom()
3118 * Print board EEPROM configuration.
3120 * Note: no single line should be greater than ASC_PRTLINE_SIZE,
3121 * cf. asc_prt_line().
3123 * Return the number of characters copied into 'cp'. No more than
3124 * 'cplen' characters will be copied to 'cp'.
3126 static int asc_prt_asc_board_eeprom(struct Scsi_Host
*shost
, char *cp
, int cplen
)
3128 struct asc_board
*boardp
= shost_priv(shost
);
3129 ASC_DVC_VAR
*asc_dvc_varp
;
3136 int isa_dma_speed
[] = { 10, 8, 7, 6, 5, 4, 3, 2 };
3137 #endif /* CONFIG_ISA */
3138 uchar serialstr
[13];
3140 asc_dvc_varp
= &boardp
->dvc_var
.asc_dvc_var
;
3141 ep
= &boardp
->eep_config
.asc_eep
;
3146 len
= asc_prt_line(cp
, leftlen
,
3147 "\nEEPROM Settings for AdvanSys SCSI Host %d:\n",
3151 if (asc_get_eeprom_string((ushort
*)&ep
->adapter_info
[0], serialstr
)
3154 asc_prt_line(cp
, leftlen
, " Serial Number: %s\n",
3158 if (ep
->adapter_info
[5] == 0xBB) {
3159 len
= asc_prt_line(cp
, leftlen
,
3160 " Default Settings Used for EEPROM-less Adapter.\n");
3163 len
= asc_prt_line(cp
, leftlen
,
3164 " Serial Number Signature Not Present.\n");
3169 len
= asc_prt_line(cp
, leftlen
,
3170 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
3171 ASC_EEP_GET_CHIP_ID(ep
), ep
->max_total_qng
,
3175 len
= asc_prt_line(cp
, leftlen
,
3176 " cntl 0x%x, no_scam 0x%x\n", ep
->cntl
, ep
->no_scam
);
3179 len
= asc_prt_line(cp
, leftlen
, " Target ID: ");
3181 for (i
= 0; i
<= ASC_MAX_TID
; i
++) {
3182 len
= asc_prt_line(cp
, leftlen
, " %d", i
);
3185 len
= asc_prt_line(cp
, leftlen
, "\n");
3188 len
= asc_prt_line(cp
, leftlen
, " Disconnects: ");
3190 for (i
= 0; i
<= ASC_MAX_TID
; i
++) {
3191 len
= asc_prt_line(cp
, leftlen
, " %c",
3193 disc_enable
& ADV_TID_TO_TIDMASK(i
)) ? 'Y' :
3197 len
= asc_prt_line(cp
, leftlen
, "\n");
3200 len
= asc_prt_line(cp
, leftlen
, " Command Queuing: ");
3202 for (i
= 0; i
<= ASC_MAX_TID
; i
++) {
3203 len
= asc_prt_line(cp
, leftlen
, " %c",
3205 use_cmd_qng
& ADV_TID_TO_TIDMASK(i
)) ? 'Y' :
3209 len
= asc_prt_line(cp
, leftlen
, "\n");
3212 len
= asc_prt_line(cp
, leftlen
, " Start Motor: ");
3214 for (i
= 0; i
<= ASC_MAX_TID
; i
++) {
3215 len
= asc_prt_line(cp
, leftlen
, " %c",
3217 start_motor
& ADV_TID_TO_TIDMASK(i
)) ? 'Y' :
3221 len
= asc_prt_line(cp
, leftlen
, "\n");
3224 len
= asc_prt_line(cp
, leftlen
, " Synchronous Transfer:");
3226 for (i
= 0; i
<= ASC_MAX_TID
; i
++) {
3227 len
= asc_prt_line(cp
, leftlen
, " %c",
3229 init_sdtr
& ADV_TID_TO_TIDMASK(i
)) ? 'Y' :
3233 len
= asc_prt_line(cp
, leftlen
, "\n");
3237 if (asc_dvc_varp
->bus_type
& ASC_IS_ISA
) {
3238 len
= asc_prt_line(cp
, leftlen
,
3239 " Host ISA DMA speed: %d MB/S\n",
3240 isa_dma_speed
[ASC_EEP_GET_DMA_SPD(ep
)]);
3243 #endif /* CONFIG_ISA */
3249 * asc_prt_adv_board_eeprom()
3251 * Print board EEPROM configuration.
3253 * Note: no single line should be greater than ASC_PRTLINE_SIZE,
3254 * cf. asc_prt_line().
3256 * Return the number of characters copied into 'cp'. No more than
3257 * 'cplen' characters will be copied to 'cp'.
3259 static int asc_prt_adv_board_eeprom(struct Scsi_Host
*shost
, char *cp
, int cplen
)
3261 struct asc_board
*boardp
= shost_priv(shost
);
3262 ADV_DVC_VAR
*adv_dvc_varp
;
3268 uchar serialstr
[13];
3269 ADVEEP_3550_CONFIG
*ep_3550
= NULL
;
3270 ADVEEP_38C0800_CONFIG
*ep_38C0800
= NULL
;
3271 ADVEEP_38C1600_CONFIG
*ep_38C1600
= NULL
;
3274 ushort sdtr_speed
= 0;
3276 adv_dvc_varp
= &boardp
->dvc_var
.adv_dvc_var
;
3277 if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC3550
) {
3278 ep_3550
= &boardp
->eep_config
.adv_3550_eep
;
3279 } else if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC38C0800
) {
3280 ep_38C0800
= &boardp
->eep_config
.adv_38C0800_eep
;
3282 ep_38C1600
= &boardp
->eep_config
.adv_38C1600_eep
;
3288 len
= asc_prt_line(cp
, leftlen
,
3289 "\nEEPROM Settings for AdvanSys SCSI Host %d:\n",
3293 if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC3550
) {
3294 wordp
= &ep_3550
->serial_number_word1
;
3295 } else if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC38C0800
) {
3296 wordp
= &ep_38C0800
->serial_number_word1
;
3298 wordp
= &ep_38C1600
->serial_number_word1
;
3301 if (asc_get_eeprom_string(wordp
, serialstr
) == ASC_TRUE
) {
3303 asc_prt_line(cp
, leftlen
, " Serial Number: %s\n",
3307 len
= asc_prt_line(cp
, leftlen
,
3308 " Serial Number Signature Not Present.\n");
3312 if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC3550
) {
3313 len
= asc_prt_line(cp
, leftlen
,
3314 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
3315 ep_3550
->adapter_scsi_id
,
3316 ep_3550
->max_host_qng
, ep_3550
->max_dvc_qng
);
3318 } else if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC38C0800
) {
3319 len
= asc_prt_line(cp
, leftlen
,
3320 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
3321 ep_38C0800
->adapter_scsi_id
,
3322 ep_38C0800
->max_host_qng
,
3323 ep_38C0800
->max_dvc_qng
);
3326 len
= asc_prt_line(cp
, leftlen
,
3327 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
3328 ep_38C1600
->adapter_scsi_id
,
3329 ep_38C1600
->max_host_qng
,
3330 ep_38C1600
->max_dvc_qng
);
3333 if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC3550
) {
3334 word
= ep_3550
->termination
;
3335 } else if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC38C0800
) {
3336 word
= ep_38C0800
->termination_lvd
;
3338 word
= ep_38C1600
->termination_lvd
;
3342 termstr
= "Low Off/High Off";
3345 termstr
= "Low Off/High On";
3348 termstr
= "Low On/High On";
3352 termstr
= "Automatic";
3356 if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC3550
) {
3357 len
= asc_prt_line(cp
, leftlen
,
3358 " termination: %u (%s), bios_ctrl: 0x%x\n",
3359 ep_3550
->termination
, termstr
,
3360 ep_3550
->bios_ctrl
);
3362 } else if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC38C0800
) {
3363 len
= asc_prt_line(cp
, leftlen
,
3364 " termination: %u (%s), bios_ctrl: 0x%x\n",
3365 ep_38C0800
->termination_lvd
, termstr
,
3366 ep_38C0800
->bios_ctrl
);
3369 len
= asc_prt_line(cp
, leftlen
,
3370 " termination: %u (%s), bios_ctrl: 0x%x\n",
3371 ep_38C1600
->termination_lvd
, termstr
,
3372 ep_38C1600
->bios_ctrl
);
3376 len
= asc_prt_line(cp
, leftlen
, " Target ID: ");
3378 for (i
= 0; i
<= ADV_MAX_TID
; i
++) {
3379 len
= asc_prt_line(cp
, leftlen
, " %X", i
);
3382 len
= asc_prt_line(cp
, leftlen
, "\n");
3385 if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC3550
) {
3386 word
= ep_3550
->disc_enable
;
3387 } else if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC38C0800
) {
3388 word
= ep_38C0800
->disc_enable
;
3390 word
= ep_38C1600
->disc_enable
;
3392 len
= asc_prt_line(cp
, leftlen
, " Disconnects: ");
3394 for (i
= 0; i
<= ADV_MAX_TID
; i
++) {
3395 len
= asc_prt_line(cp
, leftlen
, " %c",
3396 (word
& ADV_TID_TO_TIDMASK(i
)) ? 'Y' : 'N');
3399 len
= asc_prt_line(cp
, leftlen
, "\n");
3402 if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC3550
) {
3403 word
= ep_3550
->tagqng_able
;
3404 } else if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC38C0800
) {
3405 word
= ep_38C0800
->tagqng_able
;
3407 word
= ep_38C1600
->tagqng_able
;
3409 len
= asc_prt_line(cp
, leftlen
, " Command Queuing: ");
3411 for (i
= 0; i
<= ADV_MAX_TID
; i
++) {
3412 len
= asc_prt_line(cp
, leftlen
, " %c",
3413 (word
& ADV_TID_TO_TIDMASK(i
)) ? 'Y' : 'N');
3416 len
= asc_prt_line(cp
, leftlen
, "\n");
3419 if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC3550
) {
3420 word
= ep_3550
->start_motor
;
3421 } else if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC38C0800
) {
3422 word
= ep_38C0800
->start_motor
;
3424 word
= ep_38C1600
->start_motor
;
3426 len
= asc_prt_line(cp
, leftlen
, " Start Motor: ");
3428 for (i
= 0; i
<= ADV_MAX_TID
; i
++) {
3429 len
= asc_prt_line(cp
, leftlen
, " %c",
3430 (word
& ADV_TID_TO_TIDMASK(i
)) ? 'Y' : 'N');
3433 len
= asc_prt_line(cp
, leftlen
, "\n");
3436 if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC3550
) {
3437 len
= asc_prt_line(cp
, leftlen
, " Synchronous Transfer:");
3439 for (i
= 0; i
<= ADV_MAX_TID
; i
++) {
3440 len
= asc_prt_line(cp
, leftlen
, " %c",
3442 sdtr_able
& ADV_TID_TO_TIDMASK(i
)) ?
3446 len
= asc_prt_line(cp
, leftlen
, "\n");
3450 if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC3550
) {
3451 len
= asc_prt_line(cp
, leftlen
, " Ultra Transfer: ");
3453 for (i
= 0; i
<= ADV_MAX_TID
; i
++) {
3454 len
= asc_prt_line(cp
, leftlen
, " %c",
3456 ultra_able
& ADV_TID_TO_TIDMASK(i
))
3460 len
= asc_prt_line(cp
, leftlen
, "\n");
3464 if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC3550
) {
3465 word
= ep_3550
->wdtr_able
;
3466 } else if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC38C0800
) {
3467 word
= ep_38C0800
->wdtr_able
;
3469 word
= ep_38C1600
->wdtr_able
;
3471 len
= asc_prt_line(cp
, leftlen
, " Wide Transfer: ");
3473 for (i
= 0; i
<= ADV_MAX_TID
; i
++) {
3474 len
= asc_prt_line(cp
, leftlen
, " %c",
3475 (word
& ADV_TID_TO_TIDMASK(i
)) ? 'Y' : 'N');
3478 len
= asc_prt_line(cp
, leftlen
, "\n");
3481 if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC38C0800
||
3482 adv_dvc_varp
->chip_type
== ADV_CHIP_ASC38C1600
) {
3483 len
= asc_prt_line(cp
, leftlen
,
3484 " Synchronous Transfer Speed (Mhz):\n ");
3486 for (i
= 0; i
<= ADV_MAX_TID
; i
++) {
3490 sdtr_speed
= adv_dvc_varp
->sdtr_speed1
;
3491 } else if (i
== 4) {
3492 sdtr_speed
= adv_dvc_varp
->sdtr_speed2
;
3493 } else if (i
== 8) {
3494 sdtr_speed
= adv_dvc_varp
->sdtr_speed3
;
3495 } else if (i
== 12) {
3496 sdtr_speed
= adv_dvc_varp
->sdtr_speed4
;
3498 switch (sdtr_speed
& ADV_MAX_TID
) {
3521 len
= asc_prt_line(cp
, leftlen
, "%X:%s ", i
, speed_str
);
3524 len
= asc_prt_line(cp
, leftlen
, "\n ");
3529 len
= asc_prt_line(cp
, leftlen
, "\n");
3537 * asc_prt_driver_conf()
3539 * Note: no single line should be greater than ASC_PRTLINE_SIZE,
3540 * cf. asc_prt_line().
3542 * Return the number of characters copied into 'cp'. No more than
3543 * 'cplen' characters will be copied to 'cp'.
3545 static int asc_prt_driver_conf(struct Scsi_Host
*shost
, char *cp
, int cplen
)
3547 struct asc_board
*boardp
= shost_priv(shost
);
3556 len
= asc_prt_line(cp
, leftlen
,
3557 "\nLinux Driver Configuration and Information for AdvanSys SCSI Host %d:\n",
3561 len
= asc_prt_line(cp
, leftlen
,
3562 " host_busy %u, last_reset %u, max_id %u, max_lun %u, max_channel %u\n",
3563 shost
->host_busy
, shost
->last_reset
, shost
->max_id
,
3564 shost
->max_lun
, shost
->max_channel
);
3567 len
= asc_prt_line(cp
, leftlen
,
3568 " unique_id %d, can_queue %d, this_id %d, sg_tablesize %u, cmd_per_lun %u\n",
3569 shost
->unique_id
, shost
->can_queue
, shost
->this_id
,
3570 shost
->sg_tablesize
, shost
->cmd_per_lun
);
3573 len
= asc_prt_line(cp
, leftlen
,
3574 " unchecked_isa_dma %d, use_clustering %d\n",
3575 shost
->unchecked_isa_dma
, shost
->use_clustering
);
3578 len
= asc_prt_line(cp
, leftlen
,
3579 " flags 0x%x, last_reset 0x%x, jiffies 0x%x, asc_n_io_port 0x%x\n",
3580 boardp
->flags
, boardp
->last_reset
, jiffies
,
3581 boardp
->asc_n_io_port
);
3584 len
= asc_prt_line(cp
, leftlen
, " io_port 0x%x\n", shost
->io_port
);
3587 if (ASC_NARROW_BOARD(boardp
)) {
3588 chip_scsi_id
= boardp
->dvc_cfg
.asc_dvc_cfg
.chip_scsi_id
;
3590 chip_scsi_id
= boardp
->dvc_var
.adv_dvc_var
.chip_scsi_id
;
3597 * asc_prt_asc_board_info()
3599 * Print dynamic board configuration information.
3601 * Note: no single line should be greater than ASC_PRTLINE_SIZE,
3602 * cf. asc_prt_line().
3604 * Return the number of characters copied into 'cp'. No more than
3605 * 'cplen' characters will be copied to 'cp'.
3607 static int asc_prt_asc_board_info(struct Scsi_Host
*shost
, char *cp
, int cplen
)
3609 struct asc_board
*boardp
= shost_priv(shost
);
3617 int renegotiate
= 0;
3619 v
= &boardp
->dvc_var
.asc_dvc_var
;
3620 c
= &boardp
->dvc_cfg
.asc_dvc_cfg
;
3621 chip_scsi_id
= c
->chip_scsi_id
;
3626 len
= asc_prt_line(cp
, leftlen
,
3627 "\nAsc Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
3631 len
= asc_prt_line(cp
, leftlen
, " chip_version %u, mcode_date 0x%x, "
3632 "mcode_version 0x%x, err_code %u\n",
3633 c
->chip_version
, c
->mcode_date
, c
->mcode_version
,
3637 /* Current number of commands waiting for the host. */
3638 len
= asc_prt_line(cp
, leftlen
,
3639 " Total Command Pending: %d\n", v
->cur_total_qng
);
3642 len
= asc_prt_line(cp
, leftlen
, " Command Queuing:");
3644 for (i
= 0; i
<= ASC_MAX_TID
; i
++) {
3645 if ((chip_scsi_id
== i
) ||
3646 ((boardp
->init_tidmask
& ADV_TID_TO_TIDMASK(i
)) == 0)) {
3649 len
= asc_prt_line(cp
, leftlen
, " %X:%c",
3652 use_tagged_qng
& ADV_TID_TO_TIDMASK(i
)) ?
3656 len
= asc_prt_line(cp
, leftlen
, "\n");
3659 /* Current number of commands waiting for a device. */
3660 len
= asc_prt_line(cp
, leftlen
, " Command Queue Pending:");
3662 for (i
= 0; i
<= ASC_MAX_TID
; i
++) {
3663 if ((chip_scsi_id
== i
) ||
3664 ((boardp
->init_tidmask
& ADV_TID_TO_TIDMASK(i
)) == 0)) {
3667 len
= asc_prt_line(cp
, leftlen
, " %X:%u", i
, v
->cur_dvc_qng
[i
]);
3670 len
= asc_prt_line(cp
, leftlen
, "\n");
3673 /* Current limit on number of commands that can be sent to a device. */
3674 len
= asc_prt_line(cp
, leftlen
, " Command Queue Limit:");
3676 for (i
= 0; i
<= ASC_MAX_TID
; i
++) {
3677 if ((chip_scsi_id
== i
) ||
3678 ((boardp
->init_tidmask
& ADV_TID_TO_TIDMASK(i
)) == 0)) {
3681 len
= asc_prt_line(cp
, leftlen
, " %X:%u", i
, v
->max_dvc_qng
[i
]);
3684 len
= asc_prt_line(cp
, leftlen
, "\n");
3687 /* Indicate whether the device has returned queue full status. */
3688 len
= asc_prt_line(cp
, leftlen
, " Command Queue Full:");
3690 for (i
= 0; i
<= ASC_MAX_TID
; i
++) {
3691 if ((chip_scsi_id
== i
) ||
3692 ((boardp
->init_tidmask
& ADV_TID_TO_TIDMASK(i
)) == 0)) {
3695 if (boardp
->queue_full
& ADV_TID_TO_TIDMASK(i
)) {
3696 len
= asc_prt_line(cp
, leftlen
, " %X:Y-%d",
3697 i
, boardp
->queue_full_cnt
[i
]);
3699 len
= asc_prt_line(cp
, leftlen
, " %X:N", i
);
3703 len
= asc_prt_line(cp
, leftlen
, "\n");
3706 len
= asc_prt_line(cp
, leftlen
, " Synchronous Transfer:");
3708 for (i
= 0; i
<= ASC_MAX_TID
; i
++) {
3709 if ((chip_scsi_id
== i
) ||
3710 ((boardp
->init_tidmask
& ADV_TID_TO_TIDMASK(i
)) == 0)) {
3713 len
= asc_prt_line(cp
, leftlen
, " %X:%c",
3716 sdtr_done
& ADV_TID_TO_TIDMASK(i
)) ? 'Y' :
3720 len
= asc_prt_line(cp
, leftlen
, "\n");
3723 for (i
= 0; i
<= ASC_MAX_TID
; i
++) {
3724 uchar syn_period_ix
;
3726 if ((chip_scsi_id
== i
) ||
3727 ((boardp
->init_tidmask
& ADV_TID_TO_TIDMASK(i
)) == 0) ||
3728 ((v
->init_sdtr
& ADV_TID_TO_TIDMASK(i
)) == 0)) {
3732 len
= asc_prt_line(cp
, leftlen
, " %X:", i
);
3735 if ((boardp
->sdtr_data
[i
] & ASC_SYN_MAX_OFFSET
) == 0) {
3736 len
= asc_prt_line(cp
, leftlen
, " Asynchronous");
3740 (boardp
->sdtr_data
[i
] >> 4) & (v
->max_sdtr_index
-
3743 len
= asc_prt_line(cp
, leftlen
,
3744 " Transfer Period Factor: %d (%d.%d Mhz),",
3745 v
->sdtr_period_tbl
[syn_period_ix
],
3747 v
->sdtr_period_tbl
[syn_period_ix
],
3754 len
= asc_prt_line(cp
, leftlen
, " REQ/ACK Offset: %d",
3756 sdtr_data
[i
] & ASC_SYN_MAX_OFFSET
);
3760 if ((v
->sdtr_done
& ADV_TID_TO_TIDMASK(i
)) == 0) {
3761 len
= asc_prt_line(cp
, leftlen
, "*\n");
3764 len
= asc_prt_line(cp
, leftlen
, "\n");
3770 len
= asc_prt_line(cp
, leftlen
,
3771 " * = Re-negotiation pending before next command.\n");
3779 * asc_prt_adv_board_info()
3781 * Print dynamic board configuration information.
3783 * Note: no single line should be greater than ASC_PRTLINE_SIZE,
3784 * cf. asc_prt_line().
3786 * Return the number of characters copied into 'cp'. No more than
3787 * 'cplen' characters will be copied to 'cp'.
3789 static int asc_prt_adv_board_info(struct Scsi_Host
*shost
, char *cp
, int cplen
)
3791 struct asc_board
*boardp
= shost_priv(shost
);
3798 AdvPortAddr iop_base
;
3799 ushort chip_scsi_id
;
3803 ushort sdtr_able
, wdtr_able
;
3804 ushort wdtr_done
, sdtr_done
;
3806 int renegotiate
= 0;
3808 v
= &boardp
->dvc_var
.adv_dvc_var
;
3809 c
= &boardp
->dvc_cfg
.adv_dvc_cfg
;
3810 iop_base
= v
->iop_base
;
3811 chip_scsi_id
= v
->chip_scsi_id
;
3816 len
= asc_prt_line(cp
, leftlen
,
3817 "\nAdv Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
3821 len
= asc_prt_line(cp
, leftlen
,
3822 " iop_base 0x%lx, cable_detect: %X, err_code %u\n",
3824 AdvReadWordRegister(iop_base
,
3825 IOPW_SCSI_CFG1
) & CABLE_DETECT
,
3829 len
= asc_prt_line(cp
, leftlen
, " chip_version %u, mcode_date 0x%x, "
3830 "mcode_version 0x%x\n", c
->chip_version
,
3831 c
->mcode_date
, c
->mcode_version
);
3834 AdvReadWordLram(iop_base
, ASC_MC_TAGQNG_ABLE
, tagqng_able
);
3835 len
= asc_prt_line(cp
, leftlen
, " Queuing Enabled:");
3837 for (i
= 0; i
<= ADV_MAX_TID
; i
++) {
3838 if ((chip_scsi_id
== i
) ||
3839 ((boardp
->init_tidmask
& ADV_TID_TO_TIDMASK(i
)) == 0)) {
3843 len
= asc_prt_line(cp
, leftlen
, " %X:%c",
3845 (tagqng_able
& ADV_TID_TO_TIDMASK(i
)) ? 'Y' :
3849 len
= asc_prt_line(cp
, leftlen
, "\n");
3852 len
= asc_prt_line(cp
, leftlen
, " Queue Limit:");
3854 for (i
= 0; i
<= ADV_MAX_TID
; i
++) {
3855 if ((chip_scsi_id
== i
) ||
3856 ((boardp
->init_tidmask
& ADV_TID_TO_TIDMASK(i
)) == 0)) {
3860 AdvReadByteLram(iop_base
, ASC_MC_NUMBER_OF_MAX_CMD
+ i
,
3863 len
= asc_prt_line(cp
, leftlen
, " %X:%d", i
, lrambyte
);
3866 len
= asc_prt_line(cp
, leftlen
, "\n");
3869 len
= asc_prt_line(cp
, leftlen
, " Command Pending:");
3871 for (i
= 0; i
<= ADV_MAX_TID
; i
++) {
3872 if ((chip_scsi_id
== i
) ||
3873 ((boardp
->init_tidmask
& ADV_TID_TO_TIDMASK(i
)) == 0)) {
3877 AdvReadByteLram(iop_base
, ASC_MC_NUMBER_OF_QUEUED_CMD
+ i
,
3880 len
= asc_prt_line(cp
, leftlen
, " %X:%d", i
, lrambyte
);
3883 len
= asc_prt_line(cp
, leftlen
, "\n");
3886 AdvReadWordLram(iop_base
, ASC_MC_WDTR_ABLE
, wdtr_able
);
3887 len
= asc_prt_line(cp
, leftlen
, " Wide Enabled:");
3889 for (i
= 0; i
<= ADV_MAX_TID
; i
++) {
3890 if ((chip_scsi_id
== i
) ||
3891 ((boardp
->init_tidmask
& ADV_TID_TO_TIDMASK(i
)) == 0)) {
3895 len
= asc_prt_line(cp
, leftlen
, " %X:%c",
3897 (wdtr_able
& ADV_TID_TO_TIDMASK(i
)) ? 'Y' :
3901 len
= asc_prt_line(cp
, leftlen
, "\n");
3904 AdvReadWordLram(iop_base
, ASC_MC_WDTR_DONE
, wdtr_done
);
3905 len
= asc_prt_line(cp
, leftlen
, " Transfer Bit Width:");
3907 for (i
= 0; i
<= ADV_MAX_TID
; i
++) {
3908 if ((chip_scsi_id
== i
) ||
3909 ((boardp
->init_tidmask
& ADV_TID_TO_TIDMASK(i
)) == 0)) {
3913 AdvReadWordLram(iop_base
,
3914 ASC_MC_DEVICE_HSHK_CFG_TABLE
+ (2 * i
),
3917 len
= asc_prt_line(cp
, leftlen
, " %X:%d",
3918 i
, (lramword
& 0x8000) ? 16 : 8);
3921 if ((wdtr_able
& ADV_TID_TO_TIDMASK(i
)) &&
3922 (wdtr_done
& ADV_TID_TO_TIDMASK(i
)) == 0) {
3923 len
= asc_prt_line(cp
, leftlen
, "*");
3928 len
= asc_prt_line(cp
, leftlen
, "\n");
3931 AdvReadWordLram(iop_base
, ASC_MC_SDTR_ABLE
, sdtr_able
);
3932 len
= asc_prt_line(cp
, leftlen
, " Synchronous Enabled:");
3934 for (i
= 0; i
<= ADV_MAX_TID
; i
++) {
3935 if ((chip_scsi_id
== i
) ||
3936 ((boardp
->init_tidmask
& ADV_TID_TO_TIDMASK(i
)) == 0)) {
3940 len
= asc_prt_line(cp
, leftlen
, " %X:%c",
3942 (sdtr_able
& ADV_TID_TO_TIDMASK(i
)) ? 'Y' :
3946 len
= asc_prt_line(cp
, leftlen
, "\n");
3949 AdvReadWordLram(iop_base
, ASC_MC_SDTR_DONE
, sdtr_done
);
3950 for (i
= 0; i
<= ADV_MAX_TID
; i
++) {
3952 AdvReadWordLram(iop_base
,
3953 ASC_MC_DEVICE_HSHK_CFG_TABLE
+ (2 * i
),
3955 lramword
&= ~0x8000;
3957 if ((chip_scsi_id
== i
) ||
3958 ((boardp
->init_tidmask
& ADV_TID_TO_TIDMASK(i
)) == 0) ||
3959 ((sdtr_able
& ADV_TID_TO_TIDMASK(i
)) == 0)) {
3963 len
= asc_prt_line(cp
, leftlen
, " %X:", i
);
3966 if ((lramword
& 0x1F) == 0) { /* Check for REQ/ACK Offset 0. */
3967 len
= asc_prt_line(cp
, leftlen
, " Asynchronous");
3971 asc_prt_line(cp
, leftlen
,
3972 " Transfer Period Factor: ");
3975 if ((lramword
& 0x1F00) == 0x1100) { /* 80 Mhz */
3977 asc_prt_line(cp
, leftlen
, "9 (80.0 Mhz),");
3979 } else if ((lramword
& 0x1F00) == 0x1000) { /* 40 Mhz */
3981 asc_prt_line(cp
, leftlen
, "10 (40.0 Mhz),");
3983 } else { /* 20 Mhz or below. */
3985 period
= (((lramword
>> 8) * 25) + 50) / 4;
3987 if (period
== 0) { /* Should never happen. */
3989 asc_prt_line(cp
, leftlen
,
3993 len
= asc_prt_line(cp
, leftlen
,
3995 period
, 250 / period
,
4002 len
= asc_prt_line(cp
, leftlen
, " REQ/ACK Offset: %d",
4007 if ((sdtr_done
& ADV_TID_TO_TIDMASK(i
)) == 0) {
4008 len
= asc_prt_line(cp
, leftlen
, "*\n");
4011 len
= asc_prt_line(cp
, leftlen
, "\n");
4017 len
= asc_prt_line(cp
, leftlen
,
4018 " * = Re-negotiation pending before next command.\n");
4028 * Copy proc information to a read buffer taking into account the current
4029 * read offset in the file and the remaining space in the read buffer.
4032 asc_proc_copy(off_t advoffset
, off_t offset
, char *curbuf
, int leftlen
,
4033 char *cp
, int cplen
)
4037 ASC_DBG(2, "offset %d, advoffset %d, cplen %d\n",
4038 (unsigned)offset
, (unsigned)advoffset
, cplen
);
4039 if (offset
<= advoffset
) {
4040 /* Read offset below current offset, copy everything. */
4041 cnt
= min(cplen
, leftlen
);
4042 ASC_DBG(2, "curbuf 0x%lx, cp 0x%lx, cnt %d\n",
4043 (ulong
)curbuf
, (ulong
)cp
, cnt
);
4044 memcpy(curbuf
, cp
, cnt
);
4045 } else if (offset
< advoffset
+ cplen
) {
4046 /* Read offset within current range, partial copy. */
4047 cnt
= (advoffset
+ cplen
) - offset
;
4048 cp
= (cp
+ cplen
) - cnt
;
4049 cnt
= min(cnt
, leftlen
);
4050 ASC_DBG(2, "curbuf 0x%lx, cp 0x%lx, cnt %d\n",
4051 (ulong
)curbuf
, (ulong
)cp
, cnt
);
4052 memcpy(curbuf
, cp
, cnt
);
4057 #ifdef ADVANSYS_STATS
4059 * asc_prt_board_stats()
4061 * Note: no single line should be greater than ASC_PRTLINE_SIZE,
4062 * cf. asc_prt_line().
4064 * Return the number of characters copied into 'cp'. No more than
4065 * 'cplen' characters will be copied to 'cp'.
4067 static int asc_prt_board_stats(struct Scsi_Host
*shost
, char *cp
, int cplen
)
4069 struct asc_board
*boardp
= shost_priv(shost
);
4070 struct asc_stats
*s
= &boardp
->asc_stats
;
4072 int leftlen
= cplen
;
4073 int len
, totlen
= 0;
4075 len
= asc_prt_line(cp
, leftlen
,
4076 "\nLinux Driver Statistics for AdvanSys SCSI Host %d:\n",
4080 len
= asc_prt_line(cp
, leftlen
,
4081 " queuecommand %lu, reset %lu, biosparam %lu, interrupt %lu\n",
4082 s
->queuecommand
, s
->reset
, s
->biosparam
,
4086 len
= asc_prt_line(cp
, leftlen
,
4087 " callback %lu, done %lu, build_error %lu, build_noreq %lu, build_nosg %lu\n",
4088 s
->callback
, s
->done
, s
->build_error
,
4089 s
->adv_build_noreq
, s
->adv_build_nosg
);
4092 len
= asc_prt_line(cp
, leftlen
,
4093 " exe_noerror %lu, exe_busy %lu, exe_error %lu, exe_unknown %lu\n",
4094 s
->exe_noerror
, s
->exe_busy
, s
->exe_error
,
4099 * Display data transfer statistics.
4101 if (s
->xfer_cnt
> 0) {
4102 len
= asc_prt_line(cp
, leftlen
, " xfer_cnt %lu, xfer_elem %lu, ",
4103 s
->xfer_cnt
, s
->xfer_elem
);
4106 len
= asc_prt_line(cp
, leftlen
, "xfer_bytes %lu.%01lu kb\n",
4107 s
->xfer_sect
/ 2, ASC_TENTHS(s
->xfer_sect
, 2));
4110 /* Scatter gather transfer statistics */
4111 len
= asc_prt_line(cp
, leftlen
, " avg_num_elem %lu.%01lu, ",
4112 s
->xfer_elem
/ s
->xfer_cnt
,
4113 ASC_TENTHS(s
->xfer_elem
, s
->xfer_cnt
));
4116 len
= asc_prt_line(cp
, leftlen
, "avg_elem_size %lu.%01lu kb, ",
4117 (s
->xfer_sect
/ 2) / s
->xfer_elem
,
4118 ASC_TENTHS((s
->xfer_sect
/ 2), s
->xfer_elem
));
4121 len
= asc_prt_line(cp
, leftlen
, "avg_xfer_size %lu.%01lu kb\n",
4122 (s
->xfer_sect
/ 2) / s
->xfer_cnt
,
4123 ASC_TENTHS((s
->xfer_sect
/ 2), s
->xfer_cnt
));
4129 #endif /* ADVANSYS_STATS */
4132 * advansys_proc_info() - /proc/scsi/advansys/{0,1,2,3,...}
4134 * *buffer: I/O buffer
4135 * **start: if inout == FALSE pointer into buffer where user read should start
4136 * offset: current offset into a /proc/scsi/advansys/[0...] file
4137 * length: length of buffer
4138 * hostno: Scsi_Host host_no
4139 * inout: TRUE - user is writing; FALSE - user is reading
4141 * Return the number of bytes read from or written to a
4142 * /proc/scsi/advansys/[0...] file.
4144 * Note: This function uses the per board buffer 'prtbuf' which is
4145 * allocated when the board is initialized in advansys_detect(). The
4146 * buffer is ASC_PRTBUF_SIZE bytes. The function asc_proc_copy() is
4147 * used to write to the buffer. The way asc_proc_copy() is written
4148 * if 'prtbuf' is too small it will not be overwritten. Instead the
4149 * user just won't get all the available statistics.
4152 advansys_proc_info(struct Scsi_Host
*shost
, char *buffer
, char **start
,
4153 off_t offset
, int length
, int inout
)
4155 struct asc_board
*boardp
= shost_priv(shost
);
4164 ASC_DBG(1, "begin\n");
4167 * User write not supported.
4173 * User read of /proc/scsi/advansys/[0...] file.
4176 /* Copy read data starting at the beginning of the buffer. */
4184 * Get board configuration information.
4186 * advansys_info() returns the board string from its own static buffer.
4188 cp
= (char *)advansys_info(shost
);
4191 /* Copy board information. */
4192 cnt
= asc_proc_copy(advoffset
, offset
, curbuf
, leftlen
, cp
, cplen
);
4196 ASC_DBG(1, "totcnt %d\n", totcnt
);
4203 * Display Wide Board BIOS Information.
4205 if (!ASC_NARROW_BOARD(boardp
)) {
4206 cp
= boardp
->prtbuf
;
4207 cplen
= asc_prt_adv_bios(shost
, cp
, ASC_PRTBUF_SIZE
);
4208 BUG_ON(cplen
>= ASC_PRTBUF_SIZE
);
4209 cnt
= asc_proc_copy(advoffset
, offset
, curbuf
, leftlen
, cp
,
4214 ASC_DBG(1, "totcnt %d\n", totcnt
);
4222 * Display driver information for each device attached to the board.
4224 cp
= boardp
->prtbuf
;
4225 cplen
= asc_prt_board_devices(shost
, cp
, ASC_PRTBUF_SIZE
);
4226 BUG_ON(cplen
>= ASC_PRTBUF_SIZE
);
4227 cnt
= asc_proc_copy(advoffset
, offset
, curbuf
, leftlen
, cp
, cplen
);
4231 ASC_DBG(1, "totcnt %d\n", totcnt
);
4238 * Display EEPROM configuration for the board.
4240 cp
= boardp
->prtbuf
;
4241 if (ASC_NARROW_BOARD(boardp
)) {
4242 cplen
= asc_prt_asc_board_eeprom(shost
, cp
, ASC_PRTBUF_SIZE
);
4244 cplen
= asc_prt_adv_board_eeprom(shost
, cp
, ASC_PRTBUF_SIZE
);
4246 BUG_ON(cplen
>= ASC_PRTBUF_SIZE
);
4247 cnt
= asc_proc_copy(advoffset
, offset
, curbuf
, leftlen
, cp
, cplen
);
4251 ASC_DBG(1, "totcnt %d\n", totcnt
);
4258 * Display driver configuration and information for the board.
4260 cp
= boardp
->prtbuf
;
4261 cplen
= asc_prt_driver_conf(shost
, cp
, ASC_PRTBUF_SIZE
);
4262 BUG_ON(cplen
>= ASC_PRTBUF_SIZE
);
4263 cnt
= asc_proc_copy(advoffset
, offset
, curbuf
, leftlen
, cp
, cplen
);
4267 ASC_DBG(1, "totcnt %d\n", totcnt
);
4273 #ifdef ADVANSYS_STATS
4275 * Display driver statistics for the board.
4277 cp
= boardp
->prtbuf
;
4278 cplen
= asc_prt_board_stats(shost
, cp
, ASC_PRTBUF_SIZE
);
4279 BUG_ON(cplen
>= ASC_PRTBUF_SIZE
);
4280 cnt
= asc_proc_copy(advoffset
, offset
, curbuf
, leftlen
, cp
, cplen
);
4284 ASC_DBG(1, "totcnt %d\n", totcnt
);
4289 #endif /* ADVANSYS_STATS */
4292 * Display Asc Library dynamic configuration information
4295 cp
= boardp
->prtbuf
;
4296 if (ASC_NARROW_BOARD(boardp
)) {
4297 cplen
= asc_prt_asc_board_info(shost
, cp
, ASC_PRTBUF_SIZE
);
4299 cplen
= asc_prt_adv_board_info(shost
, cp
, ASC_PRTBUF_SIZE
);
4301 BUG_ON(cplen
>= ASC_PRTBUF_SIZE
);
4302 cnt
= asc_proc_copy(advoffset
, offset
, curbuf
, leftlen
, cp
, cplen
);
4306 ASC_DBG(1, "totcnt %d\n", totcnt
);
4312 ASC_DBG(1, "totcnt %d\n", totcnt
);
4316 #endif /* CONFIG_PROC_FS */
4318 static void asc_scsi_done(struct scsi_cmnd
*scp
)
4320 scsi_dma_unmap(scp
);
4321 ASC_STATS(scp
->device
->host
, done
);
4322 scp
->scsi_done(scp
);
4325 static void AscSetBank(PortAddr iop_base
, uchar bank
)
4329 val
= AscGetChipControl(iop_base
) &
4331 (CC_SINGLE_STEP
| CC_TEST
| CC_DIAG
| CC_SCSI_RESET
|
4335 } else if (bank
== 2) {
4336 val
|= CC_DIAG
| CC_BANK_ONE
;
4338 val
&= ~CC_BANK_ONE
;
4340 AscSetChipControl(iop_base
, val
);
4343 static void AscSetChipIH(PortAddr iop_base
, ushort ins_code
)
4345 AscSetBank(iop_base
, 1);
4346 AscWriteChipIH(iop_base
, ins_code
);
4347 AscSetBank(iop_base
, 0);
4350 static int AscStartChip(PortAddr iop_base
)
4352 AscSetChipControl(iop_base
, 0);
4353 if ((AscGetChipStatus(iop_base
) & CSW_HALTED
) != 0) {
4359 static int AscStopChip(PortAddr iop_base
)
4364 AscGetChipControl(iop_base
) &
4365 (~(CC_SINGLE_STEP
| CC_TEST
| CC_DIAG
));
4366 AscSetChipControl(iop_base
, (uchar
)(cc_val
| CC_HALT
));
4367 AscSetChipIH(iop_base
, INS_HALT
);
4368 AscSetChipIH(iop_base
, INS_RFLAG_WTM
);
4369 if ((AscGetChipStatus(iop_base
) & CSW_HALTED
) == 0) {
4375 static int AscIsChipHalted(PortAddr iop_base
)
4377 if ((AscGetChipStatus(iop_base
) & CSW_HALTED
) != 0) {
4378 if ((AscGetChipControl(iop_base
) & CC_HALT
) != 0) {
4385 static int AscResetChipAndScsiBus(ASC_DVC_VAR
*asc_dvc
)
4390 iop_base
= asc_dvc
->iop_base
;
4391 while ((AscGetChipStatus(iop_base
) & CSW_SCSI_RESET_ACTIVE
)
4395 AscStopChip(iop_base
);
4396 AscSetChipControl(iop_base
, CC_CHIP_RESET
| CC_SCSI_RESET
| CC_HALT
);
4398 AscSetChipIH(iop_base
, INS_RFLAG_WTM
);
4399 AscSetChipIH(iop_base
, INS_HALT
);
4400 AscSetChipControl(iop_base
, CC_CHIP_RESET
| CC_HALT
);
4401 AscSetChipControl(iop_base
, CC_HALT
);
4403 AscSetChipStatus(iop_base
, CIW_CLR_SCSI_RESET_INT
);
4404 AscSetChipStatus(iop_base
, 0);
4405 return (AscIsChipHalted(iop_base
));
4408 static int AscFindSignature(PortAddr iop_base
)
4412 ASC_DBG(1, "AscGetChipSignatureByte(0x%x) 0x%x\n",
4413 iop_base
, AscGetChipSignatureByte(iop_base
));
4414 if (AscGetChipSignatureByte(iop_base
) == (uchar
)ASC_1000_ID1B
) {
4415 ASC_DBG(1, "AscGetChipSignatureWord(0x%x) 0x%x\n",
4416 iop_base
, AscGetChipSignatureWord(iop_base
));
4417 sig_word
= AscGetChipSignatureWord(iop_base
);
4418 if ((sig_word
== (ushort
)ASC_1000_ID0W
) ||
4419 (sig_word
== (ushort
)ASC_1000_ID0W_FIX
)) {
4426 static void AscEnableInterrupt(PortAddr iop_base
)
4430 cfg
= AscGetChipCfgLsw(iop_base
);
4431 AscSetChipCfgLsw(iop_base
, cfg
| ASC_CFG0_HOST_INT_ON
);
4434 static void AscDisableInterrupt(PortAddr iop_base
)
4438 cfg
= AscGetChipCfgLsw(iop_base
);
4439 AscSetChipCfgLsw(iop_base
, cfg
& (~ASC_CFG0_HOST_INT_ON
));
4442 static uchar
AscReadLramByte(PortAddr iop_base
, ushort addr
)
4444 unsigned char byte_data
;
4445 unsigned short word_data
;
4447 if (isodd_word(addr
)) {
4448 AscSetChipLramAddr(iop_base
, addr
- 1);
4449 word_data
= AscGetChipLramData(iop_base
);
4450 byte_data
= (word_data
>> 8) & 0xFF;
4452 AscSetChipLramAddr(iop_base
, addr
);
4453 word_data
= AscGetChipLramData(iop_base
);
4454 byte_data
= word_data
& 0xFF;
4459 static ushort
AscReadLramWord(PortAddr iop_base
, ushort addr
)
4463 AscSetChipLramAddr(iop_base
, addr
);
4464 word_data
= AscGetChipLramData(iop_base
);
4468 #if CC_VERY_LONG_SG_LIST
4469 static ASC_DCNT
AscReadLramDWord(PortAddr iop_base
, ushort addr
)
4471 ushort val_low
, val_high
;
4472 ASC_DCNT dword_data
;
4474 AscSetChipLramAddr(iop_base
, addr
);
4475 val_low
= AscGetChipLramData(iop_base
);
4476 val_high
= AscGetChipLramData(iop_base
);
4477 dword_data
= ((ASC_DCNT
) val_high
<< 16) | (ASC_DCNT
) val_low
;
4478 return (dword_data
);
4480 #endif /* CC_VERY_LONG_SG_LIST */
4483 AscMemWordSetLram(PortAddr iop_base
, ushort s_addr
, ushort set_wval
, int words
)
4487 AscSetChipLramAddr(iop_base
, s_addr
);
4488 for (i
= 0; i
< words
; i
++) {
4489 AscSetChipLramData(iop_base
, set_wval
);
4493 static void AscWriteLramWord(PortAddr iop_base
, ushort addr
, ushort word_val
)
4495 AscSetChipLramAddr(iop_base
, addr
);
4496 AscSetChipLramData(iop_base
, word_val
);
4499 static void AscWriteLramByte(PortAddr iop_base
, ushort addr
, uchar byte_val
)
4503 if (isodd_word(addr
)) {
4505 word_data
= AscReadLramWord(iop_base
, addr
);
4506 word_data
&= 0x00FF;
4507 word_data
|= (((ushort
)byte_val
<< 8) & 0xFF00);
4509 word_data
= AscReadLramWord(iop_base
, addr
);
4510 word_data
&= 0xFF00;
4511 word_data
|= ((ushort
)byte_val
& 0x00FF);
4513 AscWriteLramWord(iop_base
, addr
, word_data
);
4517 * Copy 2 bytes to LRAM.
4519 * The source data is assumed to be in little-endian order in memory
4520 * and is maintained in little-endian order when written to LRAM.
4523 AscMemWordCopyPtrToLram(PortAddr iop_base
, ushort s_addr
,
4524 const uchar
*s_buffer
, int words
)
4528 AscSetChipLramAddr(iop_base
, s_addr
);
4529 for (i
= 0; i
< 2 * words
; i
+= 2) {
4531 * On a little-endian system the second argument below
4532 * produces a little-endian ushort which is written to
4533 * LRAM in little-endian order. On a big-endian system
4534 * the second argument produces a big-endian ushort which
4535 * is "transparently" byte-swapped by outpw() and written
4536 * in little-endian order to LRAM.
4538 outpw(iop_base
+ IOP_RAM_DATA
,
4539 ((ushort
)s_buffer
[i
+ 1] << 8) | s_buffer
[i
]);
4544 * Copy 4 bytes to LRAM.
4546 * The source data is assumed to be in little-endian order in memory
4547 * and is maintained in little-endian order when writen to LRAM.
4550 AscMemDWordCopyPtrToLram(PortAddr iop_base
,
4551 ushort s_addr
, uchar
*s_buffer
, int dwords
)
4555 AscSetChipLramAddr(iop_base
, s_addr
);
4556 for (i
= 0; i
< 4 * dwords
; i
+= 4) {
4557 outpw(iop_base
+ IOP_RAM_DATA
, ((ushort
)s_buffer
[i
+ 1] << 8) | s_buffer
[i
]); /* LSW */
4558 outpw(iop_base
+ IOP_RAM_DATA
, ((ushort
)s_buffer
[i
+ 3] << 8) | s_buffer
[i
+ 2]); /* MSW */
4563 * Copy 2 bytes from LRAM.
4565 * The source data is assumed to be in little-endian order in LRAM
4566 * and is maintained in little-endian order when written to memory.
4569 AscMemWordCopyPtrFromLram(PortAddr iop_base
,
4570 ushort s_addr
, uchar
*d_buffer
, int words
)
4575 AscSetChipLramAddr(iop_base
, s_addr
);
4576 for (i
= 0; i
< 2 * words
; i
+= 2) {
4577 word
= inpw(iop_base
+ IOP_RAM_DATA
);
4578 d_buffer
[i
] = word
& 0xff;
4579 d_buffer
[i
+ 1] = (word
>> 8) & 0xff;
4583 static ASC_DCNT
AscMemSumLramWord(PortAddr iop_base
, ushort s_addr
, int words
)
4589 for (i
= 0; i
< words
; i
++, s_addr
+= 2) {
4590 sum
+= AscReadLramWord(iop_base
, s_addr
);
4595 static ushort
AscInitLram(ASC_DVC_VAR
*asc_dvc
)
4602 iop_base
= asc_dvc
->iop_base
;
4604 AscMemWordSetLram(iop_base
, ASC_QADR_BEG
, 0,
4605 (ushort
)(((int)(asc_dvc
->max_total_qng
+ 2 + 1) *
4607 i
= ASC_MIN_ACTIVE_QNO
;
4608 s_addr
= ASC_QADR_BEG
+ ASC_QBLK_SIZE
;
4609 AscWriteLramByte(iop_base
, (ushort
)(s_addr
+ ASC_SCSIQ_B_FWD
),
4611 AscWriteLramByte(iop_base
, (ushort
)(s_addr
+ ASC_SCSIQ_B_BWD
),
4612 (uchar
)(asc_dvc
->max_total_qng
));
4613 AscWriteLramByte(iop_base
, (ushort
)(s_addr
+ ASC_SCSIQ_B_QNO
),
4616 s_addr
+= ASC_QBLK_SIZE
;
4617 for (; i
< asc_dvc
->max_total_qng
; i
++, s_addr
+= ASC_QBLK_SIZE
) {
4618 AscWriteLramByte(iop_base
, (ushort
)(s_addr
+ ASC_SCSIQ_B_FWD
),
4620 AscWriteLramByte(iop_base
, (ushort
)(s_addr
+ ASC_SCSIQ_B_BWD
),
4622 AscWriteLramByte(iop_base
, (ushort
)(s_addr
+ ASC_SCSIQ_B_QNO
),
4625 AscWriteLramByte(iop_base
, (ushort
)(s_addr
+ ASC_SCSIQ_B_FWD
),
4626 (uchar
)ASC_QLINK_END
);
4627 AscWriteLramByte(iop_base
, (ushort
)(s_addr
+ ASC_SCSIQ_B_BWD
),
4628 (uchar
)(asc_dvc
->max_total_qng
- 1));
4629 AscWriteLramByte(iop_base
, (ushort
)(s_addr
+ ASC_SCSIQ_B_QNO
),
4630 (uchar
)asc_dvc
->max_total_qng
);
4632 s_addr
+= ASC_QBLK_SIZE
;
4633 for (; i
<= (uchar
)(asc_dvc
->max_total_qng
+ 3);
4634 i
++, s_addr
+= ASC_QBLK_SIZE
) {
4635 AscWriteLramByte(iop_base
,
4636 (ushort
)(s_addr
+ (ushort
)ASC_SCSIQ_B_FWD
), i
);
4637 AscWriteLramByte(iop_base
,
4638 (ushort
)(s_addr
+ (ushort
)ASC_SCSIQ_B_BWD
), i
);
4639 AscWriteLramByte(iop_base
,
4640 (ushort
)(s_addr
+ (ushort
)ASC_SCSIQ_B_QNO
), i
);
4646 AscLoadMicroCode(PortAddr iop_base
, ushort s_addr
,
4647 const uchar
*mcode_buf
, ushort mcode_size
)
4650 ushort mcode_word_size
;
4651 ushort mcode_chksum
;
4653 /* Write the microcode buffer starting at LRAM address 0. */
4654 mcode_word_size
= (ushort
)(mcode_size
>> 1);
4655 AscMemWordSetLram(iop_base
, s_addr
, 0, mcode_word_size
);
4656 AscMemWordCopyPtrToLram(iop_base
, s_addr
, mcode_buf
, mcode_word_size
);
4658 chksum
= AscMemSumLramWord(iop_base
, s_addr
, mcode_word_size
);
4659 ASC_DBG(1, "chksum 0x%lx\n", (ulong
)chksum
);
4660 mcode_chksum
= (ushort
)AscMemSumLramWord(iop_base
,
4661 (ushort
)ASC_CODE_SEC_BEG
,
4662 (ushort
)((mcode_size
-
4666 ASC_DBG(1, "mcode_chksum 0x%lx\n", (ulong
)mcode_chksum
);
4667 AscWriteLramWord(iop_base
, ASCV_MCODE_CHKSUM_W
, mcode_chksum
);
4668 AscWriteLramWord(iop_base
, ASCV_MCODE_SIZE_W
, mcode_size
);
4672 static void AscInitQLinkVar(ASC_DVC_VAR
*asc_dvc
)
4678 iop_base
= asc_dvc
->iop_base
;
4679 AscPutRiscVarFreeQHead(iop_base
, 1);
4680 AscPutRiscVarDoneQTail(iop_base
, asc_dvc
->max_total_qng
);
4681 AscPutVarFreeQHead(iop_base
, 1);
4682 AscPutVarDoneQTail(iop_base
, asc_dvc
->max_total_qng
);
4683 AscWriteLramByte(iop_base
, ASCV_BUSY_QHEAD_B
,
4684 (uchar
)((int)asc_dvc
->max_total_qng
+ 1));
4685 AscWriteLramByte(iop_base
, ASCV_DISC1_QHEAD_B
,
4686 (uchar
)((int)asc_dvc
->max_total_qng
+ 2));
4687 AscWriteLramByte(iop_base
, (ushort
)ASCV_TOTAL_READY_Q_B
,
4688 asc_dvc
->max_total_qng
);
4689 AscWriteLramWord(iop_base
, ASCV_ASCDVC_ERR_CODE_W
, 0);
4690 AscWriteLramWord(iop_base
, ASCV_HALTCODE_W
, 0);
4691 AscWriteLramByte(iop_base
, ASCV_STOP_CODE_B
, 0);
4692 AscWriteLramByte(iop_base
, ASCV_SCSIBUSY_B
, 0);
4693 AscWriteLramByte(iop_base
, ASCV_WTM_FLAG_B
, 0);
4694 AscPutQDoneInProgress(iop_base
, 0);
4695 lram_addr
= ASC_QADR_BEG
;
4696 for (i
= 0; i
< 32; i
++, lram_addr
+= 2) {
4697 AscWriteLramWord(iop_base
, lram_addr
, 0);
4701 static ushort
AscInitMicroCodeVar(ASC_DVC_VAR
*asc_dvc
)
4708 struct asc_board
*board
= asc_dvc_to_board(asc_dvc
);
4710 iop_base
= asc_dvc
->iop_base
;
4712 for (i
= 0; i
<= ASC_MAX_TID
; i
++) {
4713 AscPutMCodeInitSDTRAtID(iop_base
, i
,
4714 asc_dvc
->cfg
->sdtr_period_offset
[i
]);
4717 AscInitQLinkVar(asc_dvc
);
4718 AscWriteLramByte(iop_base
, ASCV_DISC_ENABLE_B
,
4719 asc_dvc
->cfg
->disc_enable
);
4720 AscWriteLramByte(iop_base
, ASCV_HOSTSCSI_ID_B
,
4721 ASC_TID_TO_TARGET_ID(asc_dvc
->cfg
->chip_scsi_id
));
4723 /* Ensure overrun buffer is aligned on an 8 byte boundary. */
4724 BUG_ON((unsigned long)asc_dvc
->overrun_buf
& 7);
4725 asc_dvc
->overrun_dma
= dma_map_single(board
->dev
, asc_dvc
->overrun_buf
,
4726 ASC_OVERRUN_BSIZE
, DMA_FROM_DEVICE
);
4727 phy_addr
= cpu_to_le32(asc_dvc
->overrun_dma
);
4728 AscMemDWordCopyPtrToLram(iop_base
, ASCV_OVERRUN_PADDR_D
,
4729 (uchar
*)&phy_addr
, 1);
4730 phy_size
= cpu_to_le32(ASC_OVERRUN_BSIZE
);
4731 AscMemDWordCopyPtrToLram(iop_base
, ASCV_OVERRUN_BSIZE_D
,
4732 (uchar
*)&phy_size
, 1);
4734 asc_dvc
->cfg
->mcode_date
=
4735 AscReadLramWord(iop_base
, (ushort
)ASCV_MC_DATE_W
);
4736 asc_dvc
->cfg
->mcode_version
=
4737 AscReadLramWord(iop_base
, (ushort
)ASCV_MC_VER_W
);
4739 AscSetPCAddr(iop_base
, ASC_MCODE_START_ADDR
);
4740 if (AscGetPCAddr(iop_base
) != ASC_MCODE_START_ADDR
) {
4741 asc_dvc
->err_code
|= ASC_IERR_SET_PC_ADDR
;
4744 if (AscStartChip(iop_base
) != 1) {
4745 asc_dvc
->err_code
|= ASC_IERR_START_STOP_CHIP
;
4752 static ushort
AscInitAsc1000Driver(ASC_DVC_VAR
*asc_dvc
)
4754 const struct firmware
*fw
;
4755 const char fwname
[] = "advansys/mcode.bin";
4757 unsigned long chksum
;
4761 iop_base
= asc_dvc
->iop_base
;
4763 if ((asc_dvc
->dvc_cntl
& ASC_CNTL_RESET_SCSI
) &&
4764 !(asc_dvc
->init_state
& ASC_INIT_RESET_SCSI_DONE
)) {
4765 AscResetChipAndScsiBus(asc_dvc
);
4766 mdelay(asc_dvc
->scsi_reset_wait
* 1000); /* XXX: msleep? */
4768 asc_dvc
->init_state
|= ASC_INIT_STATE_BEG_LOAD_MC
;
4769 if (asc_dvc
->err_code
!= 0)
4771 if (!AscFindSignature(asc_dvc
->iop_base
)) {
4772 asc_dvc
->err_code
= ASC_IERR_BAD_SIGNATURE
;
4775 AscDisableInterrupt(iop_base
);
4776 warn_code
|= AscInitLram(asc_dvc
);
4777 if (asc_dvc
->err_code
!= 0)
4780 err
= request_firmware(&fw
, fwname
, asc_dvc
->drv_ptr
->dev
);
4782 printk(KERN_ERR
"Failed to load image \"%s\" err %d\n",
4784 asc_dvc
->err_code
|= ASC_IERR_MCODE_CHKSUM
;
4788 printk(KERN_ERR
"Bogus length %zu in image \"%s\"\n",
4790 release_firmware(fw
);
4791 asc_dvc
->err_code
|= ASC_IERR_MCODE_CHKSUM
;
4794 chksum
= (fw
->data
[3] << 24) | (fw
->data
[2] << 16) |
4795 (fw
->data
[1] << 8) | fw
->data
[0];
4796 ASC_DBG(1, "_asc_mcode_chksum 0x%lx\n", (ulong
)chksum
);
4797 if (AscLoadMicroCode(iop_base
, 0, &fw
->data
[4],
4798 fw
->size
- 4) != chksum
) {
4799 asc_dvc
->err_code
|= ASC_IERR_MCODE_CHKSUM
;
4800 release_firmware(fw
);
4803 release_firmware(fw
);
4804 warn_code
|= AscInitMicroCodeVar(asc_dvc
);
4805 asc_dvc
->init_state
|= ASC_INIT_STATE_END_LOAD_MC
;
4806 AscEnableInterrupt(iop_base
);
4811 * Load the Microcode
4813 * Write the microcode image to RISC memory starting at address 0.
4815 * The microcode is stored compressed in the following format:
4817 * 254 word (508 byte) table indexed by byte code followed
4818 * by the following byte codes:
4821 * 00: Emit word 0 in table.
4822 * 01: Emit word 1 in table.
4824 * FD: Emit word 253 in table.
4827 * FE WW WW: (3 byte code) Word to emit is the next word WW WW.
4828 * FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
4830 * Returns 0 or an error if the checksum doesn't match
4832 static int AdvLoadMicrocode(AdvPortAddr iop_base
, const unsigned char *buf
,
4833 int size
, int memsize
, int chksum
)
4835 int i
, j
, end
, len
= 0;
4838 AdvWriteWordRegister(iop_base
, IOPW_RAM_ADDR
, 0);
4840 for (i
= 253 * 2; i
< size
; i
++) {
4841 if (buf
[i
] == 0xff) {
4842 unsigned short word
= (buf
[i
+ 3] << 8) | buf
[i
+ 2];
4843 for (j
= 0; j
< buf
[i
+ 1]; j
++) {
4844 AdvWriteWordAutoIncLram(iop_base
, word
);
4848 } else if (buf
[i
] == 0xfe) {
4849 unsigned short word
= (buf
[i
+ 2] << 8) | buf
[i
+ 1];
4850 AdvWriteWordAutoIncLram(iop_base
, word
);
4854 unsigned int off
= buf
[i
] * 2;
4855 unsigned short word
= (buf
[off
+ 1] << 8) | buf
[off
];
4856 AdvWriteWordAutoIncLram(iop_base
, word
);
4863 while (len
< memsize
) {
4864 AdvWriteWordAutoIncLram(iop_base
, 0);
4868 /* Verify the microcode checksum. */
4870 AdvWriteWordRegister(iop_base
, IOPW_RAM_ADDR
, 0);
4872 for (len
= 0; len
< end
; len
+= 2) {
4873 sum
+= AdvReadWordAutoIncLram(iop_base
);
4877 return ASC_IERR_MCODE_CHKSUM
;
4882 static void AdvBuildCarrierFreelist(struct adv_dvc_var
*asc_dvc
)
4886 ADV_PADDR carr_paddr
;
4888 carrp
= (ADV_CARR_T
*) ADV_16BALIGN(asc_dvc
->carrier_buf
);
4889 asc_dvc
->carr_freelist
= NULL
;
4890 if (carrp
== asc_dvc
->carrier_buf
) {
4891 buf_size
= ADV_CARRIER_BUFSIZE
;
4893 buf_size
= ADV_CARRIER_BUFSIZE
- sizeof(ADV_CARR_T
);
4897 /* Get physical address of the carrier 'carrp'. */
4898 carr_paddr
= cpu_to_le32(virt_to_bus(carrp
));
4900 buf_size
-= sizeof(ADV_CARR_T
);
4902 carrp
->carr_pa
= carr_paddr
;
4903 carrp
->carr_va
= cpu_to_le32(ADV_VADDR_TO_U32(carrp
));
4906 * Insert the carrier at the beginning of the freelist.
4909 cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc
->carr_freelist
));
4910 asc_dvc
->carr_freelist
= carrp
;
4913 } while (buf_size
> 0);
4917 * Send an idle command to the chip and wait for completion.
4919 * Command completion is polled for once per microsecond.
4921 * The function can be called from anywhere including an interrupt handler.
4922 * But the function is not re-entrant, so it uses the DvcEnter/LeaveCritical()
4923 * functions to prevent reentrancy.
4926 * ADV_TRUE - command completed successfully
4927 * ADV_FALSE - command failed
4928 * ADV_ERROR - command timed out
4931 AdvSendIdleCmd(ADV_DVC_VAR
*asc_dvc
,
4932 ushort idle_cmd
, ADV_DCNT idle_cmd_parameter
)
4936 AdvPortAddr iop_base
;
4938 iop_base
= asc_dvc
->iop_base
;
4941 * Clear the idle command status which is set by the microcode
4942 * to a non-zero value to indicate when the command is completed.
4943 * The non-zero result is one of the IDLE_CMD_STATUS_* values
4945 AdvWriteWordLram(iop_base
, ASC_MC_IDLE_CMD_STATUS
, (ushort
)0);
4948 * Write the idle command value after the idle command parameter
4949 * has been written to avoid a race condition. If the order is not
4950 * followed, the microcode may process the idle command before the
4951 * parameters have been written to LRAM.
4953 AdvWriteDWordLramNoSwap(iop_base
, ASC_MC_IDLE_CMD_PARAMETER
,
4954 cpu_to_le32(idle_cmd_parameter
));
4955 AdvWriteWordLram(iop_base
, ASC_MC_IDLE_CMD
, idle_cmd
);
4958 * Tickle the RISC to tell it to process the idle command.
4960 AdvWriteByteRegister(iop_base
, IOPB_TICKLE
, ADV_TICKLE_B
);
4961 if (asc_dvc
->chip_type
== ADV_CHIP_ASC3550
) {
4963 * Clear the tickle value. In the ASC-3550 the RISC flag
4964 * command 'clr_tickle_b' does not work unless the host
4967 AdvWriteByteRegister(iop_base
, IOPB_TICKLE
, ADV_TICKLE_NOP
);
4970 /* Wait for up to 100 millisecond for the idle command to timeout. */
4971 for (i
= 0; i
< SCSI_WAIT_100_MSEC
; i
++) {
4972 /* Poll once each microsecond for command completion. */
4973 for (j
= 0; j
< SCSI_US_PER_MSEC
; j
++) {
4974 AdvReadWordLram(iop_base
, ASC_MC_IDLE_CMD_STATUS
,
4982 BUG(); /* The idle command should never timeout. */
4987 * Reset SCSI Bus and purge all outstanding requests.
4990 * ADV_TRUE(1) - All requests are purged and SCSI Bus is reset.
4991 * ADV_FALSE(0) - Microcode command failed.
4992 * ADV_ERROR(-1) - Microcode command timed-out. Microcode or IC
4993 * may be hung which requires driver recovery.
4995 static int AdvResetSB(ADV_DVC_VAR
*asc_dvc
)
5000 * Send the SCSI Bus Reset idle start idle command which asserts
5001 * the SCSI Bus Reset signal.
5003 status
= AdvSendIdleCmd(asc_dvc
, (ushort
)IDLE_CMD_SCSI_RESET_START
, 0L);
5004 if (status
!= ADV_TRUE
) {
5009 * Delay for the specified SCSI Bus Reset hold time.
5011 * The hold time delay is done on the host because the RISC has no
5012 * microsecond accurate timer.
5014 udelay(ASC_SCSI_RESET_HOLD_TIME_US
);
5017 * Send the SCSI Bus Reset end idle command which de-asserts
5018 * the SCSI Bus Reset signal and purges any pending requests.
5020 status
= AdvSendIdleCmd(asc_dvc
, (ushort
)IDLE_CMD_SCSI_RESET_END
, 0L);
5021 if (status
!= ADV_TRUE
) {
5025 mdelay(asc_dvc
->scsi_reset_wait
* 1000); /* XXX: msleep? */
5031 * Initialize the ASC-3550.
5033 * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
5035 * For a non-fatal error return a warning code. If there are no warnings
5036 * then 0 is returned.
5038 * Needed after initialization for error recovery.
5040 static int AdvInitAsc3550Driver(ADV_DVC_VAR
*asc_dvc
)
5042 const struct firmware
*fw
;
5043 const char fwname
[] = "advansys/3550.bin";
5044 AdvPortAddr iop_base
;
5052 unsigned long chksum
;
5055 ushort bios_mem
[ASC_MC_BIOSLEN
/ 2]; /* BIOS RISC Memory 0x40-0x8F. */
5056 ushort wdtr_able
= 0, sdtr_able
, tagqng_able
;
5057 uchar max_cmd
[ADV_MAX_TID
+ 1];
5059 /* If there is already an error, don't continue. */
5060 if (asc_dvc
->err_code
!= 0)
5064 * The caller must set 'chip_type' to ADV_CHIP_ASC3550.
5066 if (asc_dvc
->chip_type
!= ADV_CHIP_ASC3550
) {
5067 asc_dvc
->err_code
= ASC_IERR_BAD_CHIPTYPE
;
5072 iop_base
= asc_dvc
->iop_base
;
5075 * Save the RISC memory BIOS region before writing the microcode.
5076 * The BIOS may already be loaded and using its RISC LRAM region
5077 * so its region must be saved and restored.
5079 * Note: This code makes the assumption, which is currently true,
5080 * that a chip reset does not clear RISC LRAM.
5082 for (i
= 0; i
< ASC_MC_BIOSLEN
/ 2; i
++) {
5083 AdvReadWordLram(iop_base
, ASC_MC_BIOSMEM
+ (2 * i
),
5088 * Save current per TID negotiated values.
5090 if (bios_mem
[(ASC_MC_BIOS_SIGNATURE
- ASC_MC_BIOSMEM
) / 2] == 0x55AA) {
5091 ushort bios_version
, major
, minor
;
5094 bios_mem
[(ASC_MC_BIOS_VERSION
- ASC_MC_BIOSMEM
) / 2];
5095 major
= (bios_version
>> 12) & 0xF;
5096 minor
= (bios_version
>> 8) & 0xF;
5097 if (major
< 3 || (major
== 3 && minor
== 1)) {
5098 /* BIOS 3.1 and earlier location of 'wdtr_able' variable. */
5099 AdvReadWordLram(iop_base
, 0x120, wdtr_able
);
5101 AdvReadWordLram(iop_base
, ASC_MC_WDTR_ABLE
, wdtr_able
);
5104 AdvReadWordLram(iop_base
, ASC_MC_SDTR_ABLE
, sdtr_able
);
5105 AdvReadWordLram(iop_base
, ASC_MC_TAGQNG_ABLE
, tagqng_able
);
5106 for (tid
= 0; tid
<= ADV_MAX_TID
; tid
++) {
5107 AdvReadByteLram(iop_base
, ASC_MC_NUMBER_OF_MAX_CMD
+ tid
,
5111 err
= request_firmware(&fw
, fwname
, asc_dvc
->drv_ptr
->dev
);
5113 printk(KERN_ERR
"Failed to load image \"%s\" err %d\n",
5115 asc_dvc
->err_code
= ASC_IERR_MCODE_CHKSUM
;
5119 printk(KERN_ERR
"Bogus length %zu in image \"%s\"\n",
5121 release_firmware(fw
);
5122 asc_dvc
->err_code
= ASC_IERR_MCODE_CHKSUM
;
5125 chksum
= (fw
->data
[3] << 24) | (fw
->data
[2] << 16) |
5126 (fw
->data
[1] << 8) | fw
->data
[0];
5127 asc_dvc
->err_code
= AdvLoadMicrocode(iop_base
, &fw
->data
[4],
5128 fw
->size
- 4, ADV_3550_MEMSIZE
,
5130 release_firmware(fw
);
5131 if (asc_dvc
->err_code
)
5135 * Restore the RISC memory BIOS region.
5137 for (i
= 0; i
< ASC_MC_BIOSLEN
/ 2; i
++) {
5138 AdvWriteWordLram(iop_base
, ASC_MC_BIOSMEM
+ (2 * i
),
5143 * Calculate and write the microcode code checksum to the microcode
5144 * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
5146 AdvReadWordLram(iop_base
, ASC_MC_CODE_BEGIN_ADDR
, begin_addr
);
5147 AdvReadWordLram(iop_base
, ASC_MC_CODE_END_ADDR
, end_addr
);
5149 AdvWriteWordRegister(iop_base
, IOPW_RAM_ADDR
, begin_addr
);
5150 for (word
= begin_addr
; word
< end_addr
; word
+= 2) {
5151 code_sum
+= AdvReadWordAutoIncLram(iop_base
);
5153 AdvWriteWordLram(iop_base
, ASC_MC_CODE_CHK_SUM
, code_sum
);
5156 * Read and save microcode version and date.
5158 AdvReadWordLram(iop_base
, ASC_MC_VERSION_DATE
,
5159 asc_dvc
->cfg
->mcode_date
);
5160 AdvReadWordLram(iop_base
, ASC_MC_VERSION_NUM
,
5161 asc_dvc
->cfg
->mcode_version
);
5164 * Set the chip type to indicate the ASC3550.
5166 AdvWriteWordLram(iop_base
, ASC_MC_CHIP_TYPE
, ADV_CHIP_ASC3550
);
5169 * If the PCI Configuration Command Register "Parity Error Response
5170 * Control" Bit was clear (0), then set the microcode variable
5171 * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
5172 * to ignore DMA parity errors.
5174 if (asc_dvc
->cfg
->control_flag
& CONTROL_FLAG_IGNORE_PERR
) {
5175 AdvReadWordLram(iop_base
, ASC_MC_CONTROL_FLAG
, word
);
5176 word
|= CONTROL_FLAG_IGNORE_PERR
;
5177 AdvWriteWordLram(iop_base
, ASC_MC_CONTROL_FLAG
, word
);
5181 * For ASC-3550, setting the START_CTL_EMFU [3:2] bits sets a FIFO
5182 * threshold of 128 bytes. This register is only accessible to the host.
5184 AdvWriteByteRegister(iop_base
, IOPB_DMA_CFG0
,
5185 START_CTL_EMFU
| READ_CMD_MRM
);
5188 * Microcode operating variables for WDTR, SDTR, and command tag
5189 * queuing will be set in slave_configure() based on what a
5190 * device reports it is capable of in Inquiry byte 7.
5192 * If SCSI Bus Resets have been disabled, then directly set
5193 * SDTR and WDTR from the EEPROM configuration. This will allow
5194 * the BIOS and warm boot to work without a SCSI bus hang on
5195 * the Inquiry caused by host and target mismatched DTR values.
5196 * Without the SCSI Bus Reset, before an Inquiry a device can't
5197 * be assumed to be in Asynchronous, Narrow mode.
5199 if ((asc_dvc
->bios_ctrl
& BIOS_CTRL_RESET_SCSI_BUS
) == 0) {
5200 AdvWriteWordLram(iop_base
, ASC_MC_WDTR_ABLE
,
5201 asc_dvc
->wdtr_able
);
5202 AdvWriteWordLram(iop_base
, ASC_MC_SDTR_ABLE
,
5203 asc_dvc
->sdtr_able
);
5207 * Set microcode operating variables for SDTR_SPEED1, SDTR_SPEED2,
5208 * SDTR_SPEED3, and SDTR_SPEED4 based on the ULTRA EEPROM per TID
5209 * bitmask. These values determine the maximum SDTR speed negotiated
5212 * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
5213 * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
5214 * without determining here whether the device supports SDTR.
5216 * 4-bit speed SDTR speed name
5217 * =========== ===============
5218 * 0000b (0x0) SDTR disabled
5220 * 0010b (0x2) 10 Mhz
5221 * 0011b (0x3) 20 Mhz (Ultra)
5222 * 0100b (0x4) 40 Mhz (LVD/Ultra2)
5223 * 0101b (0x5) 80 Mhz (LVD2/Ultra3)
5224 * 0110b (0x6) Undefined
5226 * 1111b (0xF) Undefined
5229 for (tid
= 0; tid
<= ADV_MAX_TID
; tid
++) {
5230 if (ADV_TID_TO_TIDMASK(tid
) & asc_dvc
->ultra_able
) {
5231 /* Set Ultra speed for TID 'tid'. */
5232 word
|= (0x3 << (4 * (tid
% 4)));
5234 /* Set Fast speed for TID 'tid'. */
5235 word
|= (0x2 << (4 * (tid
% 4)));
5237 if (tid
== 3) { /* Check if done with sdtr_speed1. */
5238 AdvWriteWordLram(iop_base
, ASC_MC_SDTR_SPEED1
, word
);
5240 } else if (tid
== 7) { /* Check if done with sdtr_speed2. */
5241 AdvWriteWordLram(iop_base
, ASC_MC_SDTR_SPEED2
, word
);
5243 } else if (tid
== 11) { /* Check if done with sdtr_speed3. */
5244 AdvWriteWordLram(iop_base
, ASC_MC_SDTR_SPEED3
, word
);
5246 } else if (tid
== 15) { /* Check if done with sdtr_speed4. */
5247 AdvWriteWordLram(iop_base
, ASC_MC_SDTR_SPEED4
, word
);
5253 * Set microcode operating variable for the disconnect per TID bitmask.
5255 AdvWriteWordLram(iop_base
, ASC_MC_DISC_ENABLE
,
5256 asc_dvc
->cfg
->disc_enable
);
5259 * Set SCSI_CFG0 Microcode Default Value.
5261 * The microcode will set the SCSI_CFG0 register using this value
5262 * after it is started below.
5264 AdvWriteWordLram(iop_base
, ASC_MC_DEFAULT_SCSI_CFG0
,
5265 PARITY_EN
| QUEUE_128
| SEL_TMO_LONG
| OUR_ID_EN
|
5266 asc_dvc
->chip_scsi_id
);
5269 * Determine SCSI_CFG1 Microcode Default Value.
5271 * The microcode will set the SCSI_CFG1 register using this value
5272 * after it is started below.
5275 /* Read current SCSI_CFG1 Register value. */
5276 scsi_cfg1
= AdvReadWordRegister(iop_base
, IOPW_SCSI_CFG1
);
5279 * If all three connectors are in use, return an error.
5281 if ((scsi_cfg1
& CABLE_ILLEGAL_A
) == 0 ||
5282 (scsi_cfg1
& CABLE_ILLEGAL_B
) == 0) {
5283 asc_dvc
->err_code
|= ASC_IERR_ILLEGAL_CONNECTION
;
5288 * If the internal narrow cable is reversed all of the SCSI_CTRL
5289 * register signals will be set. Check for and return an error if
5290 * this condition is found.
5292 if ((AdvReadWordRegister(iop_base
, IOPW_SCSI_CTRL
) & 0x3F07) == 0x3F07) {
5293 asc_dvc
->err_code
|= ASC_IERR_REVERSED_CABLE
;
5298 * If this is a differential board and a single-ended device
5299 * is attached to one of the connectors, return an error.
5301 if ((scsi_cfg1
& DIFF_MODE
) && (scsi_cfg1
& DIFF_SENSE
) == 0) {
5302 asc_dvc
->err_code
|= ASC_IERR_SINGLE_END_DEVICE
;
5307 * If automatic termination control is enabled, then set the
5308 * termination value based on a table listed in a_condor.h.
5310 * If manual termination was specified with an EEPROM setting
5311 * then 'termination' was set-up in AdvInitFrom3550EEPROM() and
5312 * is ready to be 'ored' into SCSI_CFG1.
5314 if (asc_dvc
->cfg
->termination
== 0) {
5316 * The software always controls termination by setting TERM_CTL_SEL.
5317 * If TERM_CTL_SEL were set to 0, the hardware would set termination.
5319 asc_dvc
->cfg
->termination
|= TERM_CTL_SEL
;
5321 switch (scsi_cfg1
& CABLE_DETECT
) {
5322 /* TERM_CTL_H: on, TERM_CTL_L: on */
5329 asc_dvc
->cfg
->termination
|= (TERM_CTL_H
| TERM_CTL_L
);
5332 /* TERM_CTL_H: on, TERM_CTL_L: off */
5338 asc_dvc
->cfg
->termination
|= TERM_CTL_H
;
5341 /* TERM_CTL_H: off, TERM_CTL_L: off */
5349 * Clear any set TERM_CTL_H and TERM_CTL_L bits.
5351 scsi_cfg1
&= ~TERM_CTL
;
5354 * Invert the TERM_CTL_H and TERM_CTL_L bits and then
5355 * set 'scsi_cfg1'. The TERM_POL bit does not need to be
5356 * referenced, because the hardware internally inverts
5357 * the Termination High and Low bits if TERM_POL is set.
5359 scsi_cfg1
|= (TERM_CTL_SEL
| (~asc_dvc
->cfg
->termination
& TERM_CTL
));
5362 * Set SCSI_CFG1 Microcode Default Value
5364 * Set filter value and possibly modified termination control
5365 * bits in the Microcode SCSI_CFG1 Register Value.
5367 * The microcode will set the SCSI_CFG1 register using this value
5368 * after it is started below.
5370 AdvWriteWordLram(iop_base
, ASC_MC_DEFAULT_SCSI_CFG1
,
5371 FLTR_DISABLE
| scsi_cfg1
);
5374 * Set MEM_CFG Microcode Default Value
5376 * The microcode will set the MEM_CFG register using this value
5377 * after it is started below.
5379 * MEM_CFG may be accessed as a word or byte, but only bits 0-7
5382 * ASC-3550 has 8KB internal memory.
5384 AdvWriteWordLram(iop_base
, ASC_MC_DEFAULT_MEM_CFG
,
5385 BIOS_EN
| RAM_SZ_8KB
);
5388 * Set SEL_MASK Microcode Default Value
5390 * The microcode will set the SEL_MASK register using this value
5391 * after it is started below.
5393 AdvWriteWordLram(iop_base
, ASC_MC_DEFAULT_SEL_MASK
,
5394 ADV_TID_TO_TIDMASK(asc_dvc
->chip_scsi_id
));
5396 AdvBuildCarrierFreelist(asc_dvc
);
5399 * Set-up the Host->RISC Initiator Command Queue (ICQ).
5402 if ((asc_dvc
->icq_sp
= asc_dvc
->carr_freelist
) == NULL
) {
5403 asc_dvc
->err_code
|= ASC_IERR_NO_CARRIER
;
5406 asc_dvc
->carr_freelist
= (ADV_CARR_T
*)
5407 ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc
->icq_sp
->next_vpa
));
5410 * The first command issued will be placed in the stopper carrier.
5412 asc_dvc
->icq_sp
->next_vpa
= cpu_to_le32(ASC_CQ_STOPPER
);
5415 * Set RISC ICQ physical address start value.
5417 AdvWriteDWordLramNoSwap(iop_base
, ASC_MC_ICQ
, asc_dvc
->icq_sp
->carr_pa
);
5420 * Set-up the RISC->Host Initiator Response Queue (IRQ).
5422 if ((asc_dvc
->irq_sp
= asc_dvc
->carr_freelist
) == NULL
) {
5423 asc_dvc
->err_code
|= ASC_IERR_NO_CARRIER
;
5426 asc_dvc
->carr_freelist
= (ADV_CARR_T
*)
5427 ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc
->irq_sp
->next_vpa
));
5430 * The first command completed by the RISC will be placed in
5433 * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
5434 * completed the RISC will set the ASC_RQ_STOPPER bit.
5436 asc_dvc
->irq_sp
->next_vpa
= cpu_to_le32(ASC_CQ_STOPPER
);
5439 * Set RISC IRQ physical address start value.
5441 AdvWriteDWordLramNoSwap(iop_base
, ASC_MC_IRQ
, asc_dvc
->irq_sp
->carr_pa
);
5442 asc_dvc
->carr_pending_cnt
= 0;
5444 AdvWriteByteRegister(iop_base
, IOPB_INTR_ENABLES
,
5445 (ADV_INTR_ENABLE_HOST_INTR
|
5446 ADV_INTR_ENABLE_GLOBAL_INTR
));
5448 AdvReadWordLram(iop_base
, ASC_MC_CODE_BEGIN_ADDR
, word
);
5449 AdvWriteWordRegister(iop_base
, IOPW_PC
, word
);
5451 /* finally, finally, gentlemen, start your engine */
5452 AdvWriteWordRegister(iop_base
, IOPW_RISC_CSR
, ADV_RISC_CSR_RUN
);
5455 * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
5456 * Resets should be performed. The RISC has to be running
5457 * to issue a SCSI Bus Reset.
5459 if (asc_dvc
->bios_ctrl
& BIOS_CTRL_RESET_SCSI_BUS
) {
5461 * If the BIOS Signature is present in memory, restore the
5462 * BIOS Handshake Configuration Table and do not perform
5465 if (bios_mem
[(ASC_MC_BIOS_SIGNATURE
- ASC_MC_BIOSMEM
) / 2] ==
5468 * Restore per TID negotiated values.
5470 AdvWriteWordLram(iop_base
, ASC_MC_WDTR_ABLE
, wdtr_able
);
5471 AdvWriteWordLram(iop_base
, ASC_MC_SDTR_ABLE
, sdtr_able
);
5472 AdvWriteWordLram(iop_base
, ASC_MC_TAGQNG_ABLE
,
5474 for (tid
= 0; tid
<= ADV_MAX_TID
; tid
++) {
5475 AdvWriteByteLram(iop_base
,
5476 ASC_MC_NUMBER_OF_MAX_CMD
+ tid
,
5480 if (AdvResetSB(asc_dvc
) != ADV_TRUE
) {
5481 warn_code
= ASC_WARN_BUSRESET_ERROR
;
5490 * Initialize the ASC-38C0800.
5492 * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
5494 * For a non-fatal error return a warning code. If there are no warnings
5495 * then 0 is returned.
5497 * Needed after initialization for error recovery.
5499 static int AdvInitAsc38C0800Driver(ADV_DVC_VAR
*asc_dvc
)
5501 const struct firmware
*fw
;
5502 const char fwname
[] = "advansys/38C0800.bin";
5503 AdvPortAddr iop_base
;
5511 unsigned long chksum
;
5515 ushort bios_mem
[ASC_MC_BIOSLEN
/ 2]; /* BIOS RISC Memory 0x40-0x8F. */
5516 ushort wdtr_able
, sdtr_able
, tagqng_able
;
5517 uchar max_cmd
[ADV_MAX_TID
+ 1];
5519 /* If there is already an error, don't continue. */
5520 if (asc_dvc
->err_code
!= 0)
5524 * The caller must set 'chip_type' to ADV_CHIP_ASC38C0800.
5526 if (asc_dvc
->chip_type
!= ADV_CHIP_ASC38C0800
) {
5527 asc_dvc
->err_code
= ASC_IERR_BAD_CHIPTYPE
;
5532 iop_base
= asc_dvc
->iop_base
;
5535 * Save the RISC memory BIOS region before writing the microcode.
5536 * The BIOS may already be loaded and using its RISC LRAM region
5537 * so its region must be saved and restored.
5539 * Note: This code makes the assumption, which is currently true,
5540 * that a chip reset does not clear RISC LRAM.
5542 for (i
= 0; i
< ASC_MC_BIOSLEN
/ 2; i
++) {
5543 AdvReadWordLram(iop_base
, ASC_MC_BIOSMEM
+ (2 * i
),
5548 * Save current per TID negotiated values.
5550 AdvReadWordLram(iop_base
, ASC_MC_WDTR_ABLE
, wdtr_able
);
5551 AdvReadWordLram(iop_base
, ASC_MC_SDTR_ABLE
, sdtr_able
);
5552 AdvReadWordLram(iop_base
, ASC_MC_TAGQNG_ABLE
, tagqng_able
);
5553 for (tid
= 0; tid
<= ADV_MAX_TID
; tid
++) {
5554 AdvReadByteLram(iop_base
, ASC_MC_NUMBER_OF_MAX_CMD
+ tid
,
5559 * RAM BIST (RAM Built-In Self Test)
5561 * Address : I/O base + offset 0x38h register (byte).
5562 * Function: Bit 7-6(RW) : RAM mode
5563 * Normal Mode : 0x00
5564 * Pre-test Mode : 0x40
5565 * RAM Test Mode : 0x80
5567 * Bit 4(RO) : Done bit
5568 * Bit 3-0(RO) : Status
5570 * Int_RAM Error : 0x04
5575 * Note: RAM BIST code should be put right here, before loading the
5576 * microcode and after saving the RISC memory BIOS region.
5582 * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
5583 * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
5584 * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
5585 * to NORMAL_MODE, return an error too.
5587 for (i
= 0; i
< 2; i
++) {
5588 AdvWriteByteRegister(iop_base
, IOPB_RAM_BIST
, PRE_TEST_MODE
);
5589 mdelay(10); /* Wait for 10ms before reading back. */
5590 byte
= AdvReadByteRegister(iop_base
, IOPB_RAM_BIST
);
5591 if ((byte
& RAM_TEST_DONE
) == 0
5592 || (byte
& 0x0F) != PRE_TEST_VALUE
) {
5593 asc_dvc
->err_code
= ASC_IERR_BIST_PRE_TEST
;
5597 AdvWriteByteRegister(iop_base
, IOPB_RAM_BIST
, NORMAL_MODE
);
5598 mdelay(10); /* Wait for 10ms before reading back. */
5599 if (AdvReadByteRegister(iop_base
, IOPB_RAM_BIST
)
5601 asc_dvc
->err_code
= ASC_IERR_BIST_PRE_TEST
;
5607 * LRAM Test - It takes about 1.5 ms to run through the test.
5609 * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
5610 * If Done bit not set or Status not 0, save register byte, set the
5611 * err_code, and return an error.
5613 AdvWriteByteRegister(iop_base
, IOPB_RAM_BIST
, RAM_TEST_MODE
);
5614 mdelay(10); /* Wait for 10ms before checking status. */
5616 byte
= AdvReadByteRegister(iop_base
, IOPB_RAM_BIST
);
5617 if ((byte
& RAM_TEST_DONE
) == 0 || (byte
& RAM_TEST_STATUS
) != 0) {
5618 /* Get here if Done bit not set or Status not 0. */
5619 asc_dvc
->bist_err_code
= byte
; /* for BIOS display message */
5620 asc_dvc
->err_code
= ASC_IERR_BIST_RAM_TEST
;
5624 /* We need to reset back to normal mode after LRAM test passes. */
5625 AdvWriteByteRegister(iop_base
, IOPB_RAM_BIST
, NORMAL_MODE
);
5627 err
= request_firmware(&fw
, fwname
, asc_dvc
->drv_ptr
->dev
);
5629 printk(KERN_ERR
"Failed to load image \"%s\" err %d\n",
5631 asc_dvc
->err_code
= ASC_IERR_MCODE_CHKSUM
;
5635 printk(KERN_ERR
"Bogus length %zu in image \"%s\"\n",
5637 release_firmware(fw
);
5638 asc_dvc
->err_code
= ASC_IERR_MCODE_CHKSUM
;
5641 chksum
= (fw
->data
[3] << 24) | (fw
->data
[2] << 16) |
5642 (fw
->data
[1] << 8) | fw
->data
[0];
5643 asc_dvc
->err_code
= AdvLoadMicrocode(iop_base
, &fw
->data
[4],
5644 fw
->size
- 4, ADV_38C0800_MEMSIZE
,
5646 release_firmware(fw
);
5647 if (asc_dvc
->err_code
)
5651 * Restore the RISC memory BIOS region.
5653 for (i
= 0; i
< ASC_MC_BIOSLEN
/ 2; i
++) {
5654 AdvWriteWordLram(iop_base
, ASC_MC_BIOSMEM
+ (2 * i
),
5659 * Calculate and write the microcode code checksum to the microcode
5660 * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
5662 AdvReadWordLram(iop_base
, ASC_MC_CODE_BEGIN_ADDR
, begin_addr
);
5663 AdvReadWordLram(iop_base
, ASC_MC_CODE_END_ADDR
, end_addr
);
5665 AdvWriteWordRegister(iop_base
, IOPW_RAM_ADDR
, begin_addr
);
5666 for (word
= begin_addr
; word
< end_addr
; word
+= 2) {
5667 code_sum
+= AdvReadWordAutoIncLram(iop_base
);
5669 AdvWriteWordLram(iop_base
, ASC_MC_CODE_CHK_SUM
, code_sum
);
5672 * Read microcode version and date.
5674 AdvReadWordLram(iop_base
, ASC_MC_VERSION_DATE
,
5675 asc_dvc
->cfg
->mcode_date
);
5676 AdvReadWordLram(iop_base
, ASC_MC_VERSION_NUM
,
5677 asc_dvc
->cfg
->mcode_version
);
5680 * Set the chip type to indicate the ASC38C0800.
5682 AdvWriteWordLram(iop_base
, ASC_MC_CHIP_TYPE
, ADV_CHIP_ASC38C0800
);
5685 * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
5686 * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
5687 * cable detection and then we are able to read C_DET[3:0].
5689 * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
5690 * Microcode Default Value' section below.
5692 scsi_cfg1
= AdvReadWordRegister(iop_base
, IOPW_SCSI_CFG1
);
5693 AdvWriteWordRegister(iop_base
, IOPW_SCSI_CFG1
,
5694 scsi_cfg1
| DIS_TERM_DRV
);
5697 * If the PCI Configuration Command Register "Parity Error Response
5698 * Control" Bit was clear (0), then set the microcode variable
5699 * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
5700 * to ignore DMA parity errors.
5702 if (asc_dvc
->cfg
->control_flag
& CONTROL_FLAG_IGNORE_PERR
) {
5703 AdvReadWordLram(iop_base
, ASC_MC_CONTROL_FLAG
, word
);
5704 word
|= CONTROL_FLAG_IGNORE_PERR
;
5705 AdvWriteWordLram(iop_base
, ASC_MC_CONTROL_FLAG
, word
);
5709 * For ASC-38C0800, set FIFO_THRESH_80B [6:4] bits and START_CTL_TH [3:2]
5710 * bits for the default FIFO threshold.
5712 * Note: ASC-38C0800 FIFO threshold has been changed to 256 bytes.
5714 * For DMA Errata #4 set the BC_THRESH_ENB bit.
5716 AdvWriteByteRegister(iop_base
, IOPB_DMA_CFG0
,
5717 BC_THRESH_ENB
| FIFO_THRESH_80B
| START_CTL_TH
|
5721 * Microcode operating variables for WDTR, SDTR, and command tag
5722 * queuing will be set in slave_configure() based on what a
5723 * device reports it is capable of in Inquiry byte 7.
5725 * If SCSI Bus Resets have been disabled, then directly set
5726 * SDTR and WDTR from the EEPROM configuration. This will allow
5727 * the BIOS and warm boot to work without a SCSI bus hang on
5728 * the Inquiry caused by host and target mismatched DTR values.
5729 * Without the SCSI Bus Reset, before an Inquiry a device can't
5730 * be assumed to be in Asynchronous, Narrow mode.
5732 if ((asc_dvc
->bios_ctrl
& BIOS_CTRL_RESET_SCSI_BUS
) == 0) {
5733 AdvWriteWordLram(iop_base
, ASC_MC_WDTR_ABLE
,
5734 asc_dvc
->wdtr_able
);
5735 AdvWriteWordLram(iop_base
, ASC_MC_SDTR_ABLE
,
5736 asc_dvc
->sdtr_able
);
5740 * Set microcode operating variables for DISC and SDTR_SPEED1,
5741 * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
5742 * configuration values.
5744 * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
5745 * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
5746 * without determining here whether the device supports SDTR.
5748 AdvWriteWordLram(iop_base
, ASC_MC_DISC_ENABLE
,
5749 asc_dvc
->cfg
->disc_enable
);
5750 AdvWriteWordLram(iop_base
, ASC_MC_SDTR_SPEED1
, asc_dvc
->sdtr_speed1
);
5751 AdvWriteWordLram(iop_base
, ASC_MC_SDTR_SPEED2
, asc_dvc
->sdtr_speed2
);
5752 AdvWriteWordLram(iop_base
, ASC_MC_SDTR_SPEED3
, asc_dvc
->sdtr_speed3
);
5753 AdvWriteWordLram(iop_base
, ASC_MC_SDTR_SPEED4
, asc_dvc
->sdtr_speed4
);
5756 * Set SCSI_CFG0 Microcode Default Value.
5758 * The microcode will set the SCSI_CFG0 register using this value
5759 * after it is started below.
5761 AdvWriteWordLram(iop_base
, ASC_MC_DEFAULT_SCSI_CFG0
,
5762 PARITY_EN
| QUEUE_128
| SEL_TMO_LONG
| OUR_ID_EN
|
5763 asc_dvc
->chip_scsi_id
);
5766 * Determine SCSI_CFG1 Microcode Default Value.
5768 * The microcode will set the SCSI_CFG1 register using this value
5769 * after it is started below.
5772 /* Read current SCSI_CFG1 Register value. */
5773 scsi_cfg1
= AdvReadWordRegister(iop_base
, IOPW_SCSI_CFG1
);
5776 * If the internal narrow cable is reversed all of the SCSI_CTRL
5777 * register signals will be set. Check for and return an error if
5778 * this condition is found.
5780 if ((AdvReadWordRegister(iop_base
, IOPW_SCSI_CTRL
) & 0x3F07) == 0x3F07) {
5781 asc_dvc
->err_code
|= ASC_IERR_REVERSED_CABLE
;
5786 * All kind of combinations of devices attached to one of four
5787 * connectors are acceptable except HVD device attached. For example,
5788 * LVD device can be attached to SE connector while SE device attached
5789 * to LVD connector. If LVD device attached to SE connector, it only
5790 * runs up to Ultra speed.
5792 * If an HVD device is attached to one of LVD connectors, return an
5793 * error. However, there is no way to detect HVD device attached to
5796 if (scsi_cfg1
& HVD
) {
5797 asc_dvc
->err_code
= ASC_IERR_HVD_DEVICE
;
5802 * If either SE or LVD automatic termination control is enabled, then
5803 * set the termination value based on a table listed in a_condor.h.
5805 * If manual termination was specified with an EEPROM setting then
5806 * 'termination' was set-up in AdvInitFrom38C0800EEPROM() and is ready
5807 * to be 'ored' into SCSI_CFG1.
5809 if ((asc_dvc
->cfg
->termination
& TERM_SE
) == 0) {
5810 /* SE automatic termination control is enabled. */
5811 switch (scsi_cfg1
& C_DET_SE
) {
5812 /* TERM_SE_HI: on, TERM_SE_LO: on */
5816 asc_dvc
->cfg
->termination
|= TERM_SE
;
5819 /* TERM_SE_HI: on, TERM_SE_LO: off */
5821 asc_dvc
->cfg
->termination
|= TERM_SE_HI
;
5826 if ((asc_dvc
->cfg
->termination
& TERM_LVD
) == 0) {
5827 /* LVD automatic termination control is enabled. */
5828 switch (scsi_cfg1
& C_DET_LVD
) {
5829 /* TERM_LVD_HI: on, TERM_LVD_LO: on */
5833 asc_dvc
->cfg
->termination
|= TERM_LVD
;
5836 /* TERM_LVD_HI: off, TERM_LVD_LO: off */
5843 * Clear any set TERM_SE and TERM_LVD bits.
5845 scsi_cfg1
&= (~TERM_SE
& ~TERM_LVD
);
5848 * Invert the TERM_SE and TERM_LVD bits and then set 'scsi_cfg1'.
5850 scsi_cfg1
|= (~asc_dvc
->cfg
->termination
& 0xF0);
5853 * Clear BIG_ENDIAN, DIS_TERM_DRV, Terminator Polarity and HVD/LVD/SE
5854 * bits and set possibly modified termination control bits in the
5855 * Microcode SCSI_CFG1 Register Value.
5857 scsi_cfg1
&= (~BIG_ENDIAN
& ~DIS_TERM_DRV
& ~TERM_POL
& ~HVD_LVD_SE
);
5860 * Set SCSI_CFG1 Microcode Default Value
5862 * Set possibly modified termination control and reset DIS_TERM_DRV
5863 * bits in the Microcode SCSI_CFG1 Register Value.
5865 * The microcode will set the SCSI_CFG1 register using this value
5866 * after it is started below.
5868 AdvWriteWordLram(iop_base
, ASC_MC_DEFAULT_SCSI_CFG1
, scsi_cfg1
);
5871 * Set MEM_CFG Microcode Default Value
5873 * The microcode will set the MEM_CFG register using this value
5874 * after it is started below.
5876 * MEM_CFG may be accessed as a word or byte, but only bits 0-7
5879 * ASC-38C0800 has 16KB internal memory.
5881 AdvWriteWordLram(iop_base
, ASC_MC_DEFAULT_MEM_CFG
,
5882 BIOS_EN
| RAM_SZ_16KB
);
5885 * Set SEL_MASK Microcode Default Value
5887 * The microcode will set the SEL_MASK register using this value
5888 * after it is started below.
5890 AdvWriteWordLram(iop_base
, ASC_MC_DEFAULT_SEL_MASK
,
5891 ADV_TID_TO_TIDMASK(asc_dvc
->chip_scsi_id
));
5893 AdvBuildCarrierFreelist(asc_dvc
);
5896 * Set-up the Host->RISC Initiator Command Queue (ICQ).
5899 if ((asc_dvc
->icq_sp
= asc_dvc
->carr_freelist
) == NULL
) {
5900 asc_dvc
->err_code
|= ASC_IERR_NO_CARRIER
;
5903 asc_dvc
->carr_freelist
= (ADV_CARR_T
*)
5904 ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc
->icq_sp
->next_vpa
));
5907 * The first command issued will be placed in the stopper carrier.
5909 asc_dvc
->icq_sp
->next_vpa
= cpu_to_le32(ASC_CQ_STOPPER
);
5912 * Set RISC ICQ physical address start value.
5913 * carr_pa is LE, must be native before write
5915 AdvWriteDWordLramNoSwap(iop_base
, ASC_MC_ICQ
, asc_dvc
->icq_sp
->carr_pa
);
5918 * Set-up the RISC->Host Initiator Response Queue (IRQ).
5920 if ((asc_dvc
->irq_sp
= asc_dvc
->carr_freelist
) == NULL
) {
5921 asc_dvc
->err_code
|= ASC_IERR_NO_CARRIER
;
5924 asc_dvc
->carr_freelist
= (ADV_CARR_T
*)
5925 ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc
->irq_sp
->next_vpa
));
5928 * The first command completed by the RISC will be placed in
5931 * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
5932 * completed the RISC will set the ASC_RQ_STOPPER bit.
5934 asc_dvc
->irq_sp
->next_vpa
= cpu_to_le32(ASC_CQ_STOPPER
);
5937 * Set RISC IRQ physical address start value.
5939 * carr_pa is LE, must be native before write *
5941 AdvWriteDWordLramNoSwap(iop_base
, ASC_MC_IRQ
, asc_dvc
->irq_sp
->carr_pa
);
5942 asc_dvc
->carr_pending_cnt
= 0;
5944 AdvWriteByteRegister(iop_base
, IOPB_INTR_ENABLES
,
5945 (ADV_INTR_ENABLE_HOST_INTR
|
5946 ADV_INTR_ENABLE_GLOBAL_INTR
));
5948 AdvReadWordLram(iop_base
, ASC_MC_CODE_BEGIN_ADDR
, word
);
5949 AdvWriteWordRegister(iop_base
, IOPW_PC
, word
);
5951 /* finally, finally, gentlemen, start your engine */
5952 AdvWriteWordRegister(iop_base
, IOPW_RISC_CSR
, ADV_RISC_CSR_RUN
);
5955 * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
5956 * Resets should be performed. The RISC has to be running
5957 * to issue a SCSI Bus Reset.
5959 if (asc_dvc
->bios_ctrl
& BIOS_CTRL_RESET_SCSI_BUS
) {
5961 * If the BIOS Signature is present in memory, restore the
5962 * BIOS Handshake Configuration Table and do not perform
5965 if (bios_mem
[(ASC_MC_BIOS_SIGNATURE
- ASC_MC_BIOSMEM
) / 2] ==
5968 * Restore per TID negotiated values.
5970 AdvWriteWordLram(iop_base
, ASC_MC_WDTR_ABLE
, wdtr_able
);
5971 AdvWriteWordLram(iop_base
, ASC_MC_SDTR_ABLE
, sdtr_able
);
5972 AdvWriteWordLram(iop_base
, ASC_MC_TAGQNG_ABLE
,
5974 for (tid
= 0; tid
<= ADV_MAX_TID
; tid
++) {
5975 AdvWriteByteLram(iop_base
,
5976 ASC_MC_NUMBER_OF_MAX_CMD
+ tid
,
5980 if (AdvResetSB(asc_dvc
) != ADV_TRUE
) {
5981 warn_code
= ASC_WARN_BUSRESET_ERROR
;
5990 * Initialize the ASC-38C1600.
5992 * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
5994 * For a non-fatal error return a warning code. If there are no warnings
5995 * then 0 is returned.
5997 * Needed after initialization for error recovery.
5999 static int AdvInitAsc38C1600Driver(ADV_DVC_VAR
*asc_dvc
)
6001 const struct firmware
*fw
;
6002 const char fwname
[] = "advansys/38C1600.bin";
6003 AdvPortAddr iop_base
;
6011 unsigned long chksum
;
6015 ushort bios_mem
[ASC_MC_BIOSLEN
/ 2]; /* BIOS RISC Memory 0x40-0x8F. */
6016 ushort wdtr_able
, sdtr_able
, ppr_able
, tagqng_able
;
6017 uchar max_cmd
[ASC_MAX_TID
+ 1];
6019 /* If there is already an error, don't continue. */
6020 if (asc_dvc
->err_code
!= 0) {
6025 * The caller must set 'chip_type' to ADV_CHIP_ASC38C1600.
6027 if (asc_dvc
->chip_type
!= ADV_CHIP_ASC38C1600
) {
6028 asc_dvc
->err_code
= ASC_IERR_BAD_CHIPTYPE
;
6033 iop_base
= asc_dvc
->iop_base
;
6036 * Save the RISC memory BIOS region before writing the microcode.
6037 * The BIOS may already be loaded and using its RISC LRAM region
6038 * so its region must be saved and restored.
6040 * Note: This code makes the assumption, which is currently true,
6041 * that a chip reset does not clear RISC LRAM.
6043 for (i
= 0; i
< ASC_MC_BIOSLEN
/ 2; i
++) {
6044 AdvReadWordLram(iop_base
, ASC_MC_BIOSMEM
+ (2 * i
),
6049 * Save current per TID negotiated values.
6051 AdvReadWordLram(iop_base
, ASC_MC_WDTR_ABLE
, wdtr_able
);
6052 AdvReadWordLram(iop_base
, ASC_MC_SDTR_ABLE
, sdtr_able
);
6053 AdvReadWordLram(iop_base
, ASC_MC_PPR_ABLE
, ppr_able
);
6054 AdvReadWordLram(iop_base
, ASC_MC_TAGQNG_ABLE
, tagqng_able
);
6055 for (tid
= 0; tid
<= ASC_MAX_TID
; tid
++) {
6056 AdvReadByteLram(iop_base
, ASC_MC_NUMBER_OF_MAX_CMD
+ tid
,
6061 * RAM BIST (Built-In Self Test)
6063 * Address : I/O base + offset 0x38h register (byte).
6064 * Function: Bit 7-6(RW) : RAM mode
6065 * Normal Mode : 0x00
6066 * Pre-test Mode : 0x40
6067 * RAM Test Mode : 0x80
6069 * Bit 4(RO) : Done bit
6070 * Bit 3-0(RO) : Status
6072 * Int_RAM Error : 0x04
6077 * Note: RAM BIST code should be put right here, before loading the
6078 * microcode and after saving the RISC memory BIOS region.
6084 * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
6085 * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
6086 * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
6087 * to NORMAL_MODE, return an error too.
6089 for (i
= 0; i
< 2; i
++) {
6090 AdvWriteByteRegister(iop_base
, IOPB_RAM_BIST
, PRE_TEST_MODE
);
6091 mdelay(10); /* Wait for 10ms before reading back. */
6092 byte
= AdvReadByteRegister(iop_base
, IOPB_RAM_BIST
);
6093 if ((byte
& RAM_TEST_DONE
) == 0
6094 || (byte
& 0x0F) != PRE_TEST_VALUE
) {
6095 asc_dvc
->err_code
= ASC_IERR_BIST_PRE_TEST
;
6099 AdvWriteByteRegister(iop_base
, IOPB_RAM_BIST
, NORMAL_MODE
);
6100 mdelay(10); /* Wait for 10ms before reading back. */
6101 if (AdvReadByteRegister(iop_base
, IOPB_RAM_BIST
)
6103 asc_dvc
->err_code
= ASC_IERR_BIST_PRE_TEST
;
6109 * LRAM Test - It takes about 1.5 ms to run through the test.
6111 * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
6112 * If Done bit not set or Status not 0, save register byte, set the
6113 * err_code, and return an error.
6115 AdvWriteByteRegister(iop_base
, IOPB_RAM_BIST
, RAM_TEST_MODE
);
6116 mdelay(10); /* Wait for 10ms before checking status. */
6118 byte
= AdvReadByteRegister(iop_base
, IOPB_RAM_BIST
);
6119 if ((byte
& RAM_TEST_DONE
) == 0 || (byte
& RAM_TEST_STATUS
) != 0) {
6120 /* Get here if Done bit not set or Status not 0. */
6121 asc_dvc
->bist_err_code
= byte
; /* for BIOS display message */
6122 asc_dvc
->err_code
= ASC_IERR_BIST_RAM_TEST
;
6126 /* We need to reset back to normal mode after LRAM test passes. */
6127 AdvWriteByteRegister(iop_base
, IOPB_RAM_BIST
, NORMAL_MODE
);
6129 err
= request_firmware(&fw
, fwname
, asc_dvc
->drv_ptr
->dev
);
6131 printk(KERN_ERR
"Failed to load image \"%s\" err %d\n",
6133 asc_dvc
->err_code
= ASC_IERR_MCODE_CHKSUM
;
6137 printk(KERN_ERR
"Bogus length %zu in image \"%s\"\n",
6139 release_firmware(fw
);
6140 asc_dvc
->err_code
= ASC_IERR_MCODE_CHKSUM
;
6143 chksum
= (fw
->data
[3] << 24) | (fw
->data
[2] << 16) |
6144 (fw
->data
[1] << 8) | fw
->data
[0];
6145 asc_dvc
->err_code
= AdvLoadMicrocode(iop_base
, &fw
->data
[4],
6146 fw
->size
- 4, ADV_38C1600_MEMSIZE
,
6148 release_firmware(fw
);
6149 if (asc_dvc
->err_code
)
6153 * Restore the RISC memory BIOS region.
6155 for (i
= 0; i
< ASC_MC_BIOSLEN
/ 2; i
++) {
6156 AdvWriteWordLram(iop_base
, ASC_MC_BIOSMEM
+ (2 * i
),
6161 * Calculate and write the microcode code checksum to the microcode
6162 * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
6164 AdvReadWordLram(iop_base
, ASC_MC_CODE_BEGIN_ADDR
, begin_addr
);
6165 AdvReadWordLram(iop_base
, ASC_MC_CODE_END_ADDR
, end_addr
);
6167 AdvWriteWordRegister(iop_base
, IOPW_RAM_ADDR
, begin_addr
);
6168 for (word
= begin_addr
; word
< end_addr
; word
+= 2) {
6169 code_sum
+= AdvReadWordAutoIncLram(iop_base
);
6171 AdvWriteWordLram(iop_base
, ASC_MC_CODE_CHK_SUM
, code_sum
);
6174 * Read microcode version and date.
6176 AdvReadWordLram(iop_base
, ASC_MC_VERSION_DATE
,
6177 asc_dvc
->cfg
->mcode_date
);
6178 AdvReadWordLram(iop_base
, ASC_MC_VERSION_NUM
,
6179 asc_dvc
->cfg
->mcode_version
);
6182 * Set the chip type to indicate the ASC38C1600.
6184 AdvWriteWordLram(iop_base
, ASC_MC_CHIP_TYPE
, ADV_CHIP_ASC38C1600
);
6187 * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
6188 * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
6189 * cable detection and then we are able to read C_DET[3:0].
6191 * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
6192 * Microcode Default Value' section below.
6194 scsi_cfg1
= AdvReadWordRegister(iop_base
, IOPW_SCSI_CFG1
);
6195 AdvWriteWordRegister(iop_base
, IOPW_SCSI_CFG1
,
6196 scsi_cfg1
| DIS_TERM_DRV
);
6199 * If the PCI Configuration Command Register "Parity Error Response
6200 * Control" Bit was clear (0), then set the microcode variable
6201 * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
6202 * to ignore DMA parity errors.
6204 if (asc_dvc
->cfg
->control_flag
& CONTROL_FLAG_IGNORE_PERR
) {
6205 AdvReadWordLram(iop_base
, ASC_MC_CONTROL_FLAG
, word
);
6206 word
|= CONTROL_FLAG_IGNORE_PERR
;
6207 AdvWriteWordLram(iop_base
, ASC_MC_CONTROL_FLAG
, word
);
6211 * If the BIOS control flag AIPP (Asynchronous Information
6212 * Phase Protection) disable bit is not set, then set the firmware
6213 * 'control_flag' CONTROL_FLAG_ENABLE_AIPP bit to enable
6214 * AIPP checking and encoding.
6216 if ((asc_dvc
->bios_ctrl
& BIOS_CTRL_AIPP_DIS
) == 0) {
6217 AdvReadWordLram(iop_base
, ASC_MC_CONTROL_FLAG
, word
);
6218 word
|= CONTROL_FLAG_ENABLE_AIPP
;
6219 AdvWriteWordLram(iop_base
, ASC_MC_CONTROL_FLAG
, word
);
6223 * For ASC-38C1600 use DMA_CFG0 default values: FIFO_THRESH_80B [6:4],
6224 * and START_CTL_TH [3:2].
6226 AdvWriteByteRegister(iop_base
, IOPB_DMA_CFG0
,
6227 FIFO_THRESH_80B
| START_CTL_TH
| READ_CMD_MRM
);
6230 * Microcode operating variables for WDTR, SDTR, and command tag
6231 * queuing will be set in slave_configure() based on what a
6232 * device reports it is capable of in Inquiry byte 7.
6234 * If SCSI Bus Resets have been disabled, then directly set
6235 * SDTR and WDTR from the EEPROM configuration. This will allow
6236 * the BIOS and warm boot to work without a SCSI bus hang on
6237 * the Inquiry caused by host and target mismatched DTR values.
6238 * Without the SCSI Bus Reset, before an Inquiry a device can't
6239 * be assumed to be in Asynchronous, Narrow mode.
6241 if ((asc_dvc
->bios_ctrl
& BIOS_CTRL_RESET_SCSI_BUS
) == 0) {
6242 AdvWriteWordLram(iop_base
, ASC_MC_WDTR_ABLE
,
6243 asc_dvc
->wdtr_able
);
6244 AdvWriteWordLram(iop_base
, ASC_MC_SDTR_ABLE
,
6245 asc_dvc
->sdtr_able
);
6249 * Set microcode operating variables for DISC and SDTR_SPEED1,
6250 * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
6251 * configuration values.
6253 * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
6254 * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
6255 * without determining here whether the device supports SDTR.
6257 AdvWriteWordLram(iop_base
, ASC_MC_DISC_ENABLE
,
6258 asc_dvc
->cfg
->disc_enable
);
6259 AdvWriteWordLram(iop_base
, ASC_MC_SDTR_SPEED1
, asc_dvc
->sdtr_speed1
);
6260 AdvWriteWordLram(iop_base
, ASC_MC_SDTR_SPEED2
, asc_dvc
->sdtr_speed2
);
6261 AdvWriteWordLram(iop_base
, ASC_MC_SDTR_SPEED3
, asc_dvc
->sdtr_speed3
);
6262 AdvWriteWordLram(iop_base
, ASC_MC_SDTR_SPEED4
, asc_dvc
->sdtr_speed4
);
6265 * Set SCSI_CFG0 Microcode Default Value.
6267 * The microcode will set the SCSI_CFG0 register using this value
6268 * after it is started below.
6270 AdvWriteWordLram(iop_base
, ASC_MC_DEFAULT_SCSI_CFG0
,
6271 PARITY_EN
| QUEUE_128
| SEL_TMO_LONG
| OUR_ID_EN
|
6272 asc_dvc
->chip_scsi_id
);
6275 * Calculate SCSI_CFG1 Microcode Default Value.
6277 * The microcode will set the SCSI_CFG1 register using this value
6278 * after it is started below.
6280 * Each ASC-38C1600 function has only two cable detect bits.
6281 * The bus mode override bits are in IOPB_SOFT_OVER_WR.
6283 scsi_cfg1
= AdvReadWordRegister(iop_base
, IOPW_SCSI_CFG1
);
6286 * If the cable is reversed all of the SCSI_CTRL register signals
6287 * will be set. Check for and return an error if this condition is
6290 if ((AdvReadWordRegister(iop_base
, IOPW_SCSI_CTRL
) & 0x3F07) == 0x3F07) {
6291 asc_dvc
->err_code
|= ASC_IERR_REVERSED_CABLE
;
6296 * Each ASC-38C1600 function has two connectors. Only an HVD device
6297 * can not be connected to either connector. An LVD device or SE device
6298 * may be connected to either connecor. If an SE device is connected,
6299 * then at most Ultra speed (20 Mhz) can be used on both connectors.
6301 * If an HVD device is attached, return an error.
6303 if (scsi_cfg1
& HVD
) {
6304 asc_dvc
->err_code
|= ASC_IERR_HVD_DEVICE
;
6309 * Each function in the ASC-38C1600 uses only the SE cable detect and
6310 * termination because there are two connectors for each function. Each
6311 * function may use either LVD or SE mode. Corresponding the SE automatic
6312 * termination control EEPROM bits are used for each function. Each
6313 * function has its own EEPROM. If SE automatic control is enabled for
6314 * the function, then set the termination value based on a table listed
6317 * If manual termination is specified in the EEPROM for the function,
6318 * then 'termination' was set-up in AscInitFrom38C1600EEPROM() and is
6319 * ready to be 'ored' into SCSI_CFG1.
6321 if ((asc_dvc
->cfg
->termination
& TERM_SE
) == 0) {
6322 struct pci_dev
*pdev
= adv_dvc_to_pdev(asc_dvc
);
6323 /* SE automatic termination control is enabled. */
6324 switch (scsi_cfg1
& C_DET_SE
) {
6325 /* TERM_SE_HI: on, TERM_SE_LO: on */
6329 asc_dvc
->cfg
->termination
|= TERM_SE
;
6333 if (PCI_FUNC(pdev
->devfn
) == 0) {
6334 /* Function 0 - TERM_SE_HI: off, TERM_SE_LO: off */
6336 /* Function 1 - TERM_SE_HI: on, TERM_SE_LO: off */
6337 asc_dvc
->cfg
->termination
|= TERM_SE_HI
;
6344 * Clear any set TERM_SE bits.
6346 scsi_cfg1
&= ~TERM_SE
;
6349 * Invert the TERM_SE bits and then set 'scsi_cfg1'.
6351 scsi_cfg1
|= (~asc_dvc
->cfg
->termination
& TERM_SE
);
6354 * Clear Big Endian and Terminator Polarity bits and set possibly
6355 * modified termination control bits in the Microcode SCSI_CFG1
6358 * Big Endian bit is not used even on big endian machines.
6360 scsi_cfg1
&= (~BIG_ENDIAN
& ~DIS_TERM_DRV
& ~TERM_POL
);
6363 * Set SCSI_CFG1 Microcode Default Value
6365 * Set possibly modified termination control bits in the Microcode
6366 * SCSI_CFG1 Register Value.
6368 * The microcode will set the SCSI_CFG1 register using this value
6369 * after it is started below.
6371 AdvWriteWordLram(iop_base
, ASC_MC_DEFAULT_SCSI_CFG1
, scsi_cfg1
);
6374 * Set MEM_CFG Microcode Default Value
6376 * The microcode will set the MEM_CFG register using this value
6377 * after it is started below.
6379 * MEM_CFG may be accessed as a word or byte, but only bits 0-7
6382 * ASC-38C1600 has 32KB internal memory.
6384 * XXX - Since ASC38C1600 Rev.3 has a Local RAM failure issue, we come
6385 * out a special 16K Adv Library and Microcode version. After the issue
6386 * resolved, we should turn back to the 32K support. Both a_condor.h and
6387 * mcode.sas files also need to be updated.
6389 * AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
6390 * BIOS_EN | RAM_SZ_32KB);
6392 AdvWriteWordLram(iop_base
, ASC_MC_DEFAULT_MEM_CFG
,
6393 BIOS_EN
| RAM_SZ_16KB
);
6396 * Set SEL_MASK Microcode Default Value
6398 * The microcode will set the SEL_MASK register using this value
6399 * after it is started below.
6401 AdvWriteWordLram(iop_base
, ASC_MC_DEFAULT_SEL_MASK
,
6402 ADV_TID_TO_TIDMASK(asc_dvc
->chip_scsi_id
));
6404 AdvBuildCarrierFreelist(asc_dvc
);
6407 * Set-up the Host->RISC Initiator Command Queue (ICQ).
6409 if ((asc_dvc
->icq_sp
= asc_dvc
->carr_freelist
) == NULL
) {
6410 asc_dvc
->err_code
|= ASC_IERR_NO_CARRIER
;
6413 asc_dvc
->carr_freelist
= (ADV_CARR_T
*)
6414 ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc
->icq_sp
->next_vpa
));
6417 * The first command issued will be placed in the stopper carrier.
6419 asc_dvc
->icq_sp
->next_vpa
= cpu_to_le32(ASC_CQ_STOPPER
);
6422 * Set RISC ICQ physical address start value. Initialize the
6423 * COMMA register to the same value otherwise the RISC will
6424 * prematurely detect a command is available.
6426 AdvWriteDWordLramNoSwap(iop_base
, ASC_MC_ICQ
, asc_dvc
->icq_sp
->carr_pa
);
6427 AdvWriteDWordRegister(iop_base
, IOPDW_COMMA
,
6428 le32_to_cpu(asc_dvc
->icq_sp
->carr_pa
));
6431 * Set-up the RISC->Host Initiator Response Queue (IRQ).
6433 if ((asc_dvc
->irq_sp
= asc_dvc
->carr_freelist
) == NULL
) {
6434 asc_dvc
->err_code
|= ASC_IERR_NO_CARRIER
;
6437 asc_dvc
->carr_freelist
= (ADV_CARR_T
*)
6438 ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc
->irq_sp
->next_vpa
));
6441 * The first command completed by the RISC will be placed in
6444 * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
6445 * completed the RISC will set the ASC_RQ_STOPPER bit.
6447 asc_dvc
->irq_sp
->next_vpa
= cpu_to_le32(ASC_CQ_STOPPER
);
6450 * Set RISC IRQ physical address start value.
6452 AdvWriteDWordLramNoSwap(iop_base
, ASC_MC_IRQ
, asc_dvc
->irq_sp
->carr_pa
);
6453 asc_dvc
->carr_pending_cnt
= 0;
6455 AdvWriteByteRegister(iop_base
, IOPB_INTR_ENABLES
,
6456 (ADV_INTR_ENABLE_HOST_INTR
|
6457 ADV_INTR_ENABLE_GLOBAL_INTR
));
6458 AdvReadWordLram(iop_base
, ASC_MC_CODE_BEGIN_ADDR
, word
);
6459 AdvWriteWordRegister(iop_base
, IOPW_PC
, word
);
6461 /* finally, finally, gentlemen, start your engine */
6462 AdvWriteWordRegister(iop_base
, IOPW_RISC_CSR
, ADV_RISC_CSR_RUN
);
6465 * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
6466 * Resets should be performed. The RISC has to be running
6467 * to issue a SCSI Bus Reset.
6469 if (asc_dvc
->bios_ctrl
& BIOS_CTRL_RESET_SCSI_BUS
) {
6471 * If the BIOS Signature is present in memory, restore the
6472 * per TID microcode operating variables.
6474 if (bios_mem
[(ASC_MC_BIOS_SIGNATURE
- ASC_MC_BIOSMEM
) / 2] ==
6477 * Restore per TID negotiated values.
6479 AdvWriteWordLram(iop_base
, ASC_MC_WDTR_ABLE
, wdtr_able
);
6480 AdvWriteWordLram(iop_base
, ASC_MC_SDTR_ABLE
, sdtr_able
);
6481 AdvWriteWordLram(iop_base
, ASC_MC_PPR_ABLE
, ppr_able
);
6482 AdvWriteWordLram(iop_base
, ASC_MC_TAGQNG_ABLE
,
6484 for (tid
= 0; tid
<= ASC_MAX_TID
; tid
++) {
6485 AdvWriteByteLram(iop_base
,
6486 ASC_MC_NUMBER_OF_MAX_CMD
+ tid
,
6490 if (AdvResetSB(asc_dvc
) != ADV_TRUE
) {
6491 warn_code
= ASC_WARN_BUSRESET_ERROR
;
6500 * Reset chip and SCSI Bus.
6503 * ADV_TRUE(1) - Chip re-initialization and SCSI Bus Reset successful.
6504 * ADV_FALSE(0) - Chip re-initialization and SCSI Bus Reset failure.
6506 static int AdvResetChipAndSB(ADV_DVC_VAR
*asc_dvc
)
6509 ushort wdtr_able
, sdtr_able
, tagqng_able
;
6510 ushort ppr_able
= 0;
6511 uchar tid
, max_cmd
[ADV_MAX_TID
+ 1];
6512 AdvPortAddr iop_base
;
6515 iop_base
= asc_dvc
->iop_base
;
6518 * Save current per TID negotiated values.
6520 AdvReadWordLram(iop_base
, ASC_MC_WDTR_ABLE
, wdtr_able
);
6521 AdvReadWordLram(iop_base
, ASC_MC_SDTR_ABLE
, sdtr_able
);
6522 if (asc_dvc
->chip_type
== ADV_CHIP_ASC38C1600
) {
6523 AdvReadWordLram(iop_base
, ASC_MC_PPR_ABLE
, ppr_able
);
6525 AdvReadWordLram(iop_base
, ASC_MC_TAGQNG_ABLE
, tagqng_able
);
6526 for (tid
= 0; tid
<= ADV_MAX_TID
; tid
++) {
6527 AdvReadByteLram(iop_base
, ASC_MC_NUMBER_OF_MAX_CMD
+ tid
,
6532 * Force the AdvInitAsc3550/38C0800Driver() function to
6533 * perform a SCSI Bus Reset by clearing the BIOS signature word.
6534 * The initialization functions assumes a SCSI Bus Reset is not
6535 * needed if the BIOS signature word is present.
6537 AdvReadWordLram(iop_base
, ASC_MC_BIOS_SIGNATURE
, bios_sig
);
6538 AdvWriteWordLram(iop_base
, ASC_MC_BIOS_SIGNATURE
, 0);
6541 * Stop chip and reset it.
6543 AdvWriteWordRegister(iop_base
, IOPW_RISC_CSR
, ADV_RISC_CSR_STOP
);
6544 AdvWriteWordRegister(iop_base
, IOPW_CTRL_REG
, ADV_CTRL_REG_CMD_RESET
);
6546 AdvWriteWordRegister(iop_base
, IOPW_CTRL_REG
,
6547 ADV_CTRL_REG_CMD_WR_IO_REG
);
6550 * Reset Adv Library error code, if any, and try
6551 * re-initializing the chip.
6553 asc_dvc
->err_code
= 0;
6554 if (asc_dvc
->chip_type
== ADV_CHIP_ASC38C1600
) {
6555 status
= AdvInitAsc38C1600Driver(asc_dvc
);
6556 } else if (asc_dvc
->chip_type
== ADV_CHIP_ASC38C0800
) {
6557 status
= AdvInitAsc38C0800Driver(asc_dvc
);
6559 status
= AdvInitAsc3550Driver(asc_dvc
);
6562 /* Translate initialization return value to status value. */
6570 * Restore the BIOS signature word.
6572 AdvWriteWordLram(iop_base
, ASC_MC_BIOS_SIGNATURE
, bios_sig
);
6575 * Restore per TID negotiated values.
6577 AdvWriteWordLram(iop_base
, ASC_MC_WDTR_ABLE
, wdtr_able
);
6578 AdvWriteWordLram(iop_base
, ASC_MC_SDTR_ABLE
, sdtr_able
);
6579 if (asc_dvc
->chip_type
== ADV_CHIP_ASC38C1600
) {
6580 AdvWriteWordLram(iop_base
, ASC_MC_PPR_ABLE
, ppr_able
);
6582 AdvWriteWordLram(iop_base
, ASC_MC_TAGQNG_ABLE
, tagqng_able
);
6583 for (tid
= 0; tid
<= ADV_MAX_TID
; tid
++) {
6584 AdvWriteByteLram(iop_base
, ASC_MC_NUMBER_OF_MAX_CMD
+ tid
,
6592 * adv_async_callback() - Adv Library asynchronous event callback function.
6594 static void adv_async_callback(ADV_DVC_VAR
*adv_dvc_varp
, uchar code
)
6597 case ADV_ASYNC_SCSI_BUS_RESET_DET
:
6599 * The firmware detected a SCSI Bus reset.
6601 ASC_DBG(0, "ADV_ASYNC_SCSI_BUS_RESET_DET\n");
6604 case ADV_ASYNC_RDMA_FAILURE
:
6606 * Handle RDMA failure by resetting the SCSI Bus and
6607 * possibly the chip if it is unresponsive. Log the error
6608 * with a unique code.
6610 ASC_DBG(0, "ADV_ASYNC_RDMA_FAILURE\n");
6611 AdvResetChipAndSB(adv_dvc_varp
);
6614 case ADV_HOST_SCSI_BUS_RESET
:
6616 * Host generated SCSI bus reset occurred.
6618 ASC_DBG(0, "ADV_HOST_SCSI_BUS_RESET\n");
6622 ASC_DBG(0, "unknown code 0x%x\n", code
);
6628 * adv_isr_callback() - Second Level Interrupt Handler called by AdvISR().
6630 * Callback function for the Wide SCSI Adv Library.
6632 static void adv_isr_callback(ADV_DVC_VAR
*adv_dvc_varp
, ADV_SCSI_REQ_Q
*scsiqp
)
6634 struct asc_board
*boardp
;
6636 adv_sgblk_t
*sgblkp
;
6637 struct scsi_cmnd
*scp
;
6638 struct Scsi_Host
*shost
;
6641 ASC_DBG(1, "adv_dvc_varp 0x%lx, scsiqp 0x%lx\n",
6642 (ulong
)adv_dvc_varp
, (ulong
)scsiqp
);
6643 ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp
);
6646 * Get the adv_req_t structure for the command that has been
6647 * completed. The adv_req_t structure actually contains the
6648 * completed ADV_SCSI_REQ_Q structure.
6650 reqp
= (adv_req_t
*)ADV_U32_TO_VADDR(scsiqp
->srb_ptr
);
6651 ASC_DBG(1, "reqp 0x%lx\n", (ulong
)reqp
);
6653 ASC_PRINT("adv_isr_callback: reqp is NULL\n");
6658 * Get the struct scsi_cmnd structure and Scsi_Host structure for the
6659 * command that has been completed.
6661 * Note: The adv_req_t request structure and adv_sgblk_t structure,
6662 * if any, are dropped, because a board structure pointer can not be
6666 ASC_DBG(1, "scp 0x%p\n", scp
);
6669 ("adv_isr_callback: scp is NULL; adv_req_t dropped.\n");
6672 ASC_DBG_PRT_CDB(2, scp
->cmnd
, scp
->cmd_len
);
6674 shost
= scp
->device
->host
;
6675 ASC_STATS(shost
, callback
);
6676 ASC_DBG(1, "shost 0x%p\n", shost
);
6678 boardp
= shost_priv(shost
);
6679 BUG_ON(adv_dvc_varp
!= &boardp
->dvc_var
.adv_dvc_var
);
6682 * 'done_status' contains the command's ending status.
6684 switch (scsiqp
->done_status
) {
6686 ASC_DBG(2, "QD_NO_ERROR\n");
6690 * Check for an underrun condition.
6692 * If there was no error and an underrun condition, then
6693 * then return the number of underrun bytes.
6695 resid_cnt
= le32_to_cpu(scsiqp
->data_cnt
);
6696 if (scsi_bufflen(scp
) != 0 && resid_cnt
!= 0 &&
6697 resid_cnt
<= scsi_bufflen(scp
)) {
6698 ASC_DBG(1, "underrun condition %lu bytes\n",
6700 scsi_set_resid(scp
, resid_cnt
);
6705 ASC_DBG(2, "QD_WITH_ERROR\n");
6706 switch (scsiqp
->host_status
) {
6707 case QHSTA_NO_ERROR
:
6708 if (scsiqp
->scsi_status
== SAM_STAT_CHECK_CONDITION
) {
6709 ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
6710 ASC_DBG_PRT_SENSE(2, scp
->sense_buffer
,
6711 SCSI_SENSE_BUFFERSIZE
);
6713 * Note: The 'status_byte()' macro used by
6714 * target drivers defined in scsi.h shifts the
6715 * status byte returned by host drivers right
6716 * by 1 bit. This is why target drivers also
6717 * use right shifted status byte definitions.
6718 * For instance target drivers use
6719 * CHECK_CONDITION, defined to 0x1, instead of
6720 * the SCSI defined check condition value of
6721 * 0x2. Host drivers are supposed to return
6722 * the status byte as it is defined by SCSI.
6724 scp
->result
= DRIVER_BYTE(DRIVER_SENSE
) |
6725 STATUS_BYTE(scsiqp
->scsi_status
);
6727 scp
->result
= STATUS_BYTE(scsiqp
->scsi_status
);
6732 /* Some other QHSTA error occurred. */
6733 ASC_DBG(1, "host_status 0x%x\n", scsiqp
->host_status
);
6734 scp
->result
= HOST_BYTE(DID_BAD_TARGET
);
6739 case QD_ABORTED_BY_HOST
:
6740 ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
6742 HOST_BYTE(DID_ABORT
) | STATUS_BYTE(scsiqp
->scsi_status
);
6746 ASC_DBG(1, "done_status 0x%x\n", scsiqp
->done_status
);
6748 HOST_BYTE(DID_ERROR
) | STATUS_BYTE(scsiqp
->scsi_status
);
6753 * If the 'init_tidmask' bit isn't already set for the target and the
6754 * current request finished normally, then set the bit for the target
6755 * to indicate that a device is present.
6757 if ((boardp
->init_tidmask
& ADV_TID_TO_TIDMASK(scp
->device
->id
)) == 0 &&
6758 scsiqp
->done_status
== QD_NO_ERROR
&&
6759 scsiqp
->host_status
== QHSTA_NO_ERROR
) {
6760 boardp
->init_tidmask
|= ADV_TID_TO_TIDMASK(scp
->device
->id
);
6766 * Free all 'adv_sgblk_t' structures allocated for the request.
6768 while ((sgblkp
= reqp
->sgblkp
) != NULL
) {
6769 /* Remove 'sgblkp' from the request list. */
6770 reqp
->sgblkp
= sgblkp
->next_sgblkp
;
6772 /* Add 'sgblkp' to the board free list. */
6773 sgblkp
->next_sgblkp
= boardp
->adv_sgblkp
;
6774 boardp
->adv_sgblkp
= sgblkp
;
6778 * Free the adv_req_t structure used with the command by adding
6779 * it back to the board free list.
6781 reqp
->next_reqp
= boardp
->adv_reqp
;
6782 boardp
->adv_reqp
= reqp
;
6784 ASC_DBG(1, "done\n");
6788 * Adv Library Interrupt Service Routine
6790 * This function is called by a driver's interrupt service routine.
6791 * The function disables and re-enables interrupts.
6793 * When a microcode idle command is completed, the ADV_DVC_VAR
6794 * 'idle_cmd_done' field is set to ADV_TRUE.
6796 * Note: AdvISR() can be called when interrupts are disabled or even
6797 * when there is no hardware interrupt condition present. It will
6798 * always check for completed idle commands and microcode requests.
6799 * This is an important feature that shouldn't be changed because it
6800 * allows commands to be completed from polling mode loops.
6803 * ADV_TRUE(1) - interrupt was pending
6804 * ADV_FALSE(0) - no interrupt was pending
6806 static int AdvISR(ADV_DVC_VAR
*asc_dvc
)
6808 AdvPortAddr iop_base
;
6811 ADV_CARR_T
*free_carrp
;
6812 ADV_VADDR irq_next_vpa
;
6813 ADV_SCSI_REQ_Q
*scsiq
;
6815 iop_base
= asc_dvc
->iop_base
;
6817 /* Reading the register clears the interrupt. */
6818 int_stat
= AdvReadByteRegister(iop_base
, IOPB_INTR_STATUS_REG
);
6820 if ((int_stat
& (ADV_INTR_STATUS_INTRA
| ADV_INTR_STATUS_INTRB
|
6821 ADV_INTR_STATUS_INTRC
)) == 0) {
6826 * Notify the driver of an asynchronous microcode condition by
6827 * calling the adv_async_callback function. The function
6828 * is passed the microcode ASC_MC_INTRB_CODE byte value.
6830 if (int_stat
& ADV_INTR_STATUS_INTRB
) {
6833 AdvReadByteLram(iop_base
, ASC_MC_INTRB_CODE
, intrb_code
);
6835 if (asc_dvc
->chip_type
== ADV_CHIP_ASC3550
||
6836 asc_dvc
->chip_type
== ADV_CHIP_ASC38C0800
) {
6837 if (intrb_code
== ADV_ASYNC_CARRIER_READY_FAILURE
&&
6838 asc_dvc
->carr_pending_cnt
!= 0) {
6839 AdvWriteByteRegister(iop_base
, IOPB_TICKLE
,
6841 if (asc_dvc
->chip_type
== ADV_CHIP_ASC3550
) {
6842 AdvWriteByteRegister(iop_base
,
6849 adv_async_callback(asc_dvc
, intrb_code
);
6853 * Check if the IRQ stopper carrier contains a completed request.
6855 while (((irq_next_vpa
=
6856 le32_to_cpu(asc_dvc
->irq_sp
->next_vpa
)) & ASC_RQ_DONE
) != 0) {
6858 * Get a pointer to the newly completed ADV_SCSI_REQ_Q structure.
6859 * The RISC will have set 'areq_vpa' to a virtual address.
6861 * The firmware will have copied the ASC_SCSI_REQ_Q.scsiq_ptr
6862 * field to the carrier ADV_CARR_T.areq_vpa field. The conversion
6863 * below complements the conversion of ASC_SCSI_REQ_Q.scsiq_ptr'
6864 * in AdvExeScsiQueue().
6866 scsiq
= (ADV_SCSI_REQ_Q
*)
6867 ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc
->irq_sp
->areq_vpa
));
6870 * Request finished with good status and the queue was not
6871 * DMAed to host memory by the firmware. Set all status fields
6872 * to indicate good status.
6874 if ((irq_next_vpa
& ASC_RQ_GOOD
) != 0) {
6875 scsiq
->done_status
= QD_NO_ERROR
;
6876 scsiq
->host_status
= scsiq
->scsi_status
= 0;
6877 scsiq
->data_cnt
= 0L;
6881 * Advance the stopper pointer to the next carrier
6882 * ignoring the lower four bits. Free the previous
6885 free_carrp
= asc_dvc
->irq_sp
;
6886 asc_dvc
->irq_sp
= (ADV_CARR_T
*)
6887 ADV_U32_TO_VADDR(ASC_GET_CARRP(irq_next_vpa
));
6889 free_carrp
->next_vpa
=
6890 cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc
->carr_freelist
));
6891 asc_dvc
->carr_freelist
= free_carrp
;
6892 asc_dvc
->carr_pending_cnt
--;
6894 target_bit
= ADV_TID_TO_TIDMASK(scsiq
->target_id
);
6897 * Clear request microcode control flag.
6902 * Notify the driver of the completed request by passing
6903 * the ADV_SCSI_REQ_Q pointer to its callback function.
6905 scsiq
->a_flag
|= ADV_SCSIQ_DONE
;
6906 adv_isr_callback(asc_dvc
, scsiq
);
6908 * Note: After the driver callback function is called, 'scsiq'
6909 * can no longer be referenced.
6911 * Fall through and continue processing other completed
6918 static int AscSetLibErrorCode(ASC_DVC_VAR
*asc_dvc
, ushort err_code
)
6920 if (asc_dvc
->err_code
== 0) {
6921 asc_dvc
->err_code
= err_code
;
6922 AscWriteLramWord(asc_dvc
->iop_base
, ASCV_ASCDVC_ERR_CODE_W
,
6928 static void AscAckInterrupt(PortAddr iop_base
)
6936 risc_flag
= AscReadLramByte(iop_base
, ASCV_RISC_FLAG_B
);
6937 if (loop
++ > 0x7FFF) {
6940 } while ((risc_flag
& ASC_RISC_FLAG_GEN_INT
) != 0);
6942 AscReadLramByte(iop_base
,
6943 ASCV_HOST_FLAG_B
) & (~ASC_HOST_FLAG_ACK_INT
);
6944 AscWriteLramByte(iop_base
, ASCV_HOST_FLAG_B
,
6945 (uchar
)(host_flag
| ASC_HOST_FLAG_ACK_INT
));
6946 AscSetChipStatus(iop_base
, CIW_INT_ACK
);
6948 while (AscGetChipStatus(iop_base
) & CSW_INT_PENDING
) {
6949 AscSetChipStatus(iop_base
, CIW_INT_ACK
);
6954 AscWriteLramByte(iop_base
, ASCV_HOST_FLAG_B
, host_flag
);
6957 static uchar
AscGetSynPeriodIndex(ASC_DVC_VAR
*asc_dvc
, uchar syn_time
)
6959 const uchar
*period_table
;
6964 period_table
= asc_dvc
->sdtr_period_tbl
;
6965 max_index
= (int)asc_dvc
->max_sdtr_index
;
6966 min_index
= (int)asc_dvc
->min_sdtr_index
;
6967 if ((syn_time
<= period_table
[max_index
])) {
6968 for (i
= min_index
; i
< (max_index
- 1); i
++) {
6969 if (syn_time
<= period_table
[i
]) {
6973 return (uchar
)max_index
;
6975 return (uchar
)(max_index
+ 1);
6980 AscMsgOutSDTR(ASC_DVC_VAR
*asc_dvc
, uchar sdtr_period
, uchar sdtr_offset
)
6983 uchar sdtr_period_index
;
6986 iop_base
= asc_dvc
->iop_base
;
6987 sdtr_buf
.msg_type
= EXTENDED_MESSAGE
;
6988 sdtr_buf
.msg_len
= MS_SDTR_LEN
;
6989 sdtr_buf
.msg_req
= EXTENDED_SDTR
;
6990 sdtr_buf
.xfer_period
= sdtr_period
;
6991 sdtr_offset
&= ASC_SYN_MAX_OFFSET
;
6992 sdtr_buf
.req_ack_offset
= sdtr_offset
;
6993 sdtr_period_index
= AscGetSynPeriodIndex(asc_dvc
, sdtr_period
);
6994 if (sdtr_period_index
<= asc_dvc
->max_sdtr_index
) {
6995 AscMemWordCopyPtrToLram(iop_base
, ASCV_MSGOUT_BEG
,
6997 sizeof(EXT_MSG
) >> 1);
6998 return ((sdtr_period_index
<< 4) | sdtr_offset
);
7000 sdtr_buf
.req_ack_offset
= 0;
7001 AscMemWordCopyPtrToLram(iop_base
, ASCV_MSGOUT_BEG
,
7003 sizeof(EXT_MSG
) >> 1);
7009 AscCalSDTRData(ASC_DVC_VAR
*asc_dvc
, uchar sdtr_period
, uchar syn_offset
)
7012 uchar sdtr_period_ix
;
7014 sdtr_period_ix
= AscGetSynPeriodIndex(asc_dvc
, sdtr_period
);
7015 if (sdtr_period_ix
> asc_dvc
->max_sdtr_index
)
7017 byte
= (sdtr_period_ix
<< 4) | (syn_offset
& ASC_SYN_MAX_OFFSET
);
7021 static int AscSetChipSynRegAtID(PortAddr iop_base
, uchar id
, uchar sdtr_data
)
7023 ASC_SCSI_BIT_ID_TYPE org_id
;
7027 AscSetBank(iop_base
, 1);
7028 org_id
= AscReadChipDvcID(iop_base
);
7029 for (i
= 0; i
<= ASC_MAX_TID
; i
++) {
7030 if (org_id
== (0x01 << i
))
7033 org_id
= (ASC_SCSI_BIT_ID_TYPE
) i
;
7034 AscWriteChipDvcID(iop_base
, id
);
7035 if (AscReadChipDvcID(iop_base
) == (0x01 << id
)) {
7036 AscSetBank(iop_base
, 0);
7037 AscSetChipSyn(iop_base
, sdtr_data
);
7038 if (AscGetChipSyn(iop_base
) != sdtr_data
) {
7044 AscSetBank(iop_base
, 1);
7045 AscWriteChipDvcID(iop_base
, org_id
);
7046 AscSetBank(iop_base
, 0);
7050 static void AscSetChipSDTR(PortAddr iop_base
, uchar sdtr_data
, uchar tid_no
)
7052 AscSetChipSynRegAtID(iop_base
, tid_no
, sdtr_data
);
7053 AscPutMCodeSDTRDoneAtID(iop_base
, tid_no
, sdtr_data
);
7056 static int AscIsrChipHalted(ASC_DVC_VAR
*asc_dvc
)
7062 ushort int_halt_code
;
7063 ASC_SCSI_BIT_ID_TYPE scsi_busy
;
7064 ASC_SCSI_BIT_ID_TYPE target_id
;
7071 uchar q_cntl
, tid_no
;
7075 struct asc_board
*boardp
;
7077 BUG_ON(!asc_dvc
->drv_ptr
);
7078 boardp
= asc_dvc
->drv_ptr
;
7080 iop_base
= asc_dvc
->iop_base
;
7081 int_halt_code
= AscReadLramWord(iop_base
, ASCV_HALTCODE_W
);
7083 halt_qp
= AscReadLramByte(iop_base
, ASCV_CURCDB_B
);
7084 halt_q_addr
= ASC_QNO_TO_QADDR(halt_qp
);
7085 target_ix
= AscReadLramByte(iop_base
,
7086 (ushort
)(halt_q_addr
+
7087 (ushort
)ASC_SCSIQ_B_TARGET_IX
));
7088 q_cntl
= AscReadLramByte(iop_base
,
7089 (ushort
)(halt_q_addr
+ (ushort
)ASC_SCSIQ_B_CNTL
));
7090 tid_no
= ASC_TIX_TO_TID(target_ix
);
7091 target_id
= (uchar
)ASC_TID_TO_TARGET_ID(tid_no
);
7092 if (asc_dvc
->pci_fix_asyn_xfer
& target_id
) {
7093 asyn_sdtr
= ASYN_SDTR_DATA_FIX_PCI_REV_AB
;
7097 if (int_halt_code
== ASC_HALT_DISABLE_ASYN_USE_SYN_FIX
) {
7098 if (asc_dvc
->pci_fix_asyn_xfer
& target_id
) {
7099 AscSetChipSDTR(iop_base
, 0, tid_no
);
7100 boardp
->sdtr_data
[tid_no
] = 0;
7102 AscWriteLramWord(iop_base
, ASCV_HALTCODE_W
, 0);
7104 } else if (int_halt_code
== ASC_HALT_ENABLE_ASYN_USE_SYN_FIX
) {
7105 if (asc_dvc
->pci_fix_asyn_xfer
& target_id
) {
7106 AscSetChipSDTR(iop_base
, asyn_sdtr
, tid_no
);
7107 boardp
->sdtr_data
[tid_no
] = asyn_sdtr
;
7109 AscWriteLramWord(iop_base
, ASCV_HALTCODE_W
, 0);
7111 } else if (int_halt_code
== ASC_HALT_EXTMSG_IN
) {
7112 AscMemWordCopyPtrFromLram(iop_base
,
7115 sizeof(EXT_MSG
) >> 1);
7117 if (ext_msg
.msg_type
== EXTENDED_MESSAGE
&&
7118 ext_msg
.msg_req
== EXTENDED_SDTR
&&
7119 ext_msg
.msg_len
== MS_SDTR_LEN
) {
7121 if ((ext_msg
.req_ack_offset
> ASC_SYN_MAX_OFFSET
)) {
7123 sdtr_accept
= FALSE
;
7124 ext_msg
.req_ack_offset
= ASC_SYN_MAX_OFFSET
;
7126 if ((ext_msg
.xfer_period
<
7127 asc_dvc
->sdtr_period_tbl
[asc_dvc
->min_sdtr_index
])
7128 || (ext_msg
.xfer_period
>
7129 asc_dvc
->sdtr_period_tbl
[asc_dvc
->
7131 sdtr_accept
= FALSE
;
7132 ext_msg
.xfer_period
=
7133 asc_dvc
->sdtr_period_tbl
[asc_dvc
->
7138 AscCalSDTRData(asc_dvc
, ext_msg
.xfer_period
,
7139 ext_msg
.req_ack_offset
);
7140 if ((sdtr_data
== 0xFF)) {
7142 q_cntl
|= QC_MSG_OUT
;
7143 asc_dvc
->init_sdtr
&= ~target_id
;
7144 asc_dvc
->sdtr_done
&= ~target_id
;
7145 AscSetChipSDTR(iop_base
, asyn_sdtr
,
7147 boardp
->sdtr_data
[tid_no
] = asyn_sdtr
;
7150 if (ext_msg
.req_ack_offset
== 0) {
7152 q_cntl
&= ~QC_MSG_OUT
;
7153 asc_dvc
->init_sdtr
&= ~target_id
;
7154 asc_dvc
->sdtr_done
&= ~target_id
;
7155 AscSetChipSDTR(iop_base
, asyn_sdtr
, tid_no
);
7157 if (sdtr_accept
&& (q_cntl
& QC_MSG_OUT
)) {
7158 q_cntl
&= ~QC_MSG_OUT
;
7159 asc_dvc
->sdtr_done
|= target_id
;
7160 asc_dvc
->init_sdtr
|= target_id
;
7161 asc_dvc
->pci_fix_asyn_xfer
&=
7164 AscCalSDTRData(asc_dvc
,
7165 ext_msg
.xfer_period
,
7168 AscSetChipSDTR(iop_base
, sdtr_data
,
7170 boardp
->sdtr_data
[tid_no
] = sdtr_data
;
7172 q_cntl
|= QC_MSG_OUT
;
7173 AscMsgOutSDTR(asc_dvc
,
7174 ext_msg
.xfer_period
,
7175 ext_msg
.req_ack_offset
);
7176 asc_dvc
->pci_fix_asyn_xfer
&=
7179 AscCalSDTRData(asc_dvc
,
7180 ext_msg
.xfer_period
,
7183 AscSetChipSDTR(iop_base
, sdtr_data
,
7185 boardp
->sdtr_data
[tid_no
] = sdtr_data
;
7186 asc_dvc
->sdtr_done
|= target_id
;
7187 asc_dvc
->init_sdtr
|= target_id
;
7191 AscWriteLramByte(iop_base
,
7192 (ushort
)(halt_q_addr
+
7193 (ushort
)ASC_SCSIQ_B_CNTL
),
7195 AscWriteLramWord(iop_base
, ASCV_HALTCODE_W
, 0);
7197 } else if (ext_msg
.msg_type
== EXTENDED_MESSAGE
&&
7198 ext_msg
.msg_req
== EXTENDED_WDTR
&&
7199 ext_msg
.msg_len
== MS_WDTR_LEN
) {
7201 ext_msg
.wdtr_width
= 0;
7202 AscMemWordCopyPtrToLram(iop_base
,
7205 sizeof(EXT_MSG
) >> 1);
7206 q_cntl
|= QC_MSG_OUT
;
7207 AscWriteLramByte(iop_base
,
7208 (ushort
)(halt_q_addr
+
7209 (ushort
)ASC_SCSIQ_B_CNTL
),
7211 AscWriteLramWord(iop_base
, ASCV_HALTCODE_W
, 0);
7215 ext_msg
.msg_type
= MESSAGE_REJECT
;
7216 AscMemWordCopyPtrToLram(iop_base
,
7219 sizeof(EXT_MSG
) >> 1);
7220 q_cntl
|= QC_MSG_OUT
;
7221 AscWriteLramByte(iop_base
,
7222 (ushort
)(halt_q_addr
+
7223 (ushort
)ASC_SCSIQ_B_CNTL
),
7225 AscWriteLramWord(iop_base
, ASCV_HALTCODE_W
, 0);
7228 } else if (int_halt_code
== ASC_HALT_CHK_CONDITION
) {
7230 q_cntl
|= QC_REQ_SENSE
;
7232 if ((asc_dvc
->init_sdtr
& target_id
) != 0) {
7234 asc_dvc
->sdtr_done
&= ~target_id
;
7236 sdtr_data
= AscGetMCodeInitSDTRAtID(iop_base
, tid_no
);
7237 q_cntl
|= QC_MSG_OUT
;
7238 AscMsgOutSDTR(asc_dvc
,
7240 sdtr_period_tbl
[(sdtr_data
>> 4) &
7244 (uchar
)(sdtr_data
& (uchar
)
7245 ASC_SYN_MAX_OFFSET
));
7248 AscWriteLramByte(iop_base
,
7249 (ushort
)(halt_q_addr
+
7250 (ushort
)ASC_SCSIQ_B_CNTL
), q_cntl
);
7252 tag_code
= AscReadLramByte(iop_base
,
7253 (ushort
)(halt_q_addr
+ (ushort
)
7254 ASC_SCSIQ_B_TAG_CODE
));
7256 if ((asc_dvc
->pci_fix_asyn_xfer
& target_id
)
7257 && !(asc_dvc
->pci_fix_asyn_xfer_always
& target_id
)
7260 tag_code
|= (ASC_TAG_FLAG_DISABLE_DISCONNECT
7261 | ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX
);
7264 AscWriteLramByte(iop_base
,
7265 (ushort
)(halt_q_addr
+
7266 (ushort
)ASC_SCSIQ_B_TAG_CODE
),
7269 q_status
= AscReadLramByte(iop_base
,
7270 (ushort
)(halt_q_addr
+ (ushort
)
7271 ASC_SCSIQ_B_STATUS
));
7272 q_status
|= (QS_READY
| QS_BUSY
);
7273 AscWriteLramByte(iop_base
,
7274 (ushort
)(halt_q_addr
+
7275 (ushort
)ASC_SCSIQ_B_STATUS
),
7278 scsi_busy
= AscReadLramByte(iop_base
, (ushort
)ASCV_SCSIBUSY_B
);
7279 scsi_busy
&= ~target_id
;
7280 AscWriteLramByte(iop_base
, (ushort
)ASCV_SCSIBUSY_B
, scsi_busy
);
7282 AscWriteLramWord(iop_base
, ASCV_HALTCODE_W
, 0);
7284 } else if (int_halt_code
== ASC_HALT_SDTR_REJECTED
) {
7286 AscMemWordCopyPtrFromLram(iop_base
,
7289 sizeof(EXT_MSG
) >> 1);
7291 if ((out_msg
.msg_type
== EXTENDED_MESSAGE
) &&
7292 (out_msg
.msg_len
== MS_SDTR_LEN
) &&
7293 (out_msg
.msg_req
== EXTENDED_SDTR
)) {
7295 asc_dvc
->init_sdtr
&= ~target_id
;
7296 asc_dvc
->sdtr_done
&= ~target_id
;
7297 AscSetChipSDTR(iop_base
, asyn_sdtr
, tid_no
);
7298 boardp
->sdtr_data
[tid_no
] = asyn_sdtr
;
7300 q_cntl
&= ~QC_MSG_OUT
;
7301 AscWriteLramByte(iop_base
,
7302 (ushort
)(halt_q_addr
+
7303 (ushort
)ASC_SCSIQ_B_CNTL
), q_cntl
);
7304 AscWriteLramWord(iop_base
, ASCV_HALTCODE_W
, 0);
7306 } else if (int_halt_code
== ASC_HALT_SS_QUEUE_FULL
) {
7308 scsi_status
= AscReadLramByte(iop_base
,
7309 (ushort
)((ushort
)halt_q_addr
+
7311 ASC_SCSIQ_SCSI_STATUS
));
7313 AscReadLramByte(iop_base
,
7314 (ushort
)((ushort
)ASC_QADR_BEG
+
7315 (ushort
)target_ix
));
7316 if ((cur_dvc_qng
> 0) && (asc_dvc
->cur_dvc_qng
[tid_no
] > 0)) {
7318 scsi_busy
= AscReadLramByte(iop_base
,
7319 (ushort
)ASCV_SCSIBUSY_B
);
7320 scsi_busy
|= target_id
;
7321 AscWriteLramByte(iop_base
,
7322 (ushort
)ASCV_SCSIBUSY_B
, scsi_busy
);
7323 asc_dvc
->queue_full_or_busy
|= target_id
;
7325 if (scsi_status
== SAM_STAT_TASK_SET_FULL
) {
7326 if (cur_dvc_qng
> ASC_MIN_TAGGED_CMD
) {
7328 asc_dvc
->max_dvc_qng
[tid_no
] =
7331 AscWriteLramByte(iop_base
,
7333 ASCV_MAX_DVC_QNG_BEG
7339 * Set the device queue depth to the
7340 * number of active requests when the
7341 * QUEUE FULL condition was encountered.
7343 boardp
->queue_full
|= target_id
;
7344 boardp
->queue_full_cnt
[tid_no
] =
7349 AscWriteLramWord(iop_base
, ASCV_HALTCODE_W
, 0);
7352 #if CC_VERY_LONG_SG_LIST
7353 else if (int_halt_code
== ASC_HALT_HOST_COPY_SG_LIST_TO_RISC
) {
7357 uchar first_sg_wk_q_no
;
7358 ASC_SCSI_Q
*scsiq
; /* Ptr to driver request. */
7359 ASC_SG_HEAD
*sg_head
; /* Ptr to driver SG request. */
7360 ASC_SG_LIST_Q scsi_sg_q
; /* Structure written to queue. */
7361 ushort sg_list_dwords
;
7362 ushort sg_entry_cnt
;
7366 q_no
= AscReadLramByte(iop_base
, (ushort
)ASCV_REQ_SG_LIST_QP
);
7367 if (q_no
== ASC_QLINK_END
)
7370 q_addr
= ASC_QNO_TO_QADDR(q_no
);
7373 * Convert the request's SRB pointer to a host ASC_SCSI_REQ
7374 * structure pointer using a macro provided by the driver.
7375 * The ASC_SCSI_REQ pointer provides a pointer to the
7376 * host ASC_SG_HEAD structure.
7378 /* Read request's SRB pointer. */
7379 scsiq
= (ASC_SCSI_Q
*)
7380 ASC_SRB2SCSIQ(ASC_U32_TO_VADDR(AscReadLramDWord(iop_base
,
7383 ASC_SCSIQ_D_SRBPTR
))));
7386 * Get request's first and working SG queue.
7388 sg_wk_q_no
= AscReadLramByte(iop_base
,
7390 ASC_SCSIQ_B_SG_WK_QP
));
7392 first_sg_wk_q_no
= AscReadLramByte(iop_base
,
7394 ASC_SCSIQ_B_FIRST_SG_WK_QP
));
7397 * Reset request's working SG queue back to the
7400 AscWriteLramByte(iop_base
,
7402 (ushort
)ASC_SCSIQ_B_SG_WK_QP
),
7405 sg_head
= scsiq
->sg_head
;
7408 * Set sg_entry_cnt to the number of SG elements
7409 * that will be completed on this interrupt.
7411 * Note: The allocated SG queues contain ASC_MAX_SG_LIST - 1
7412 * SG elements. The data_cnt and data_addr fields which
7413 * add 1 to the SG element capacity are not used when
7414 * restarting SG handling after a halt.
7416 if (scsiq
->remain_sg_entry_cnt
> (ASC_MAX_SG_LIST
- 1)) {
7417 sg_entry_cnt
= ASC_MAX_SG_LIST
- 1;
7420 * Keep track of remaining number of SG elements that
7421 * will need to be handled on the next interrupt.
7423 scsiq
->remain_sg_entry_cnt
-= (ASC_MAX_SG_LIST
- 1);
7425 sg_entry_cnt
= scsiq
->remain_sg_entry_cnt
;
7426 scsiq
->remain_sg_entry_cnt
= 0;
7430 * Copy SG elements into the list of allocated SG queues.
7432 * Last index completed is saved in scsiq->next_sg_index.
7434 next_qp
= first_sg_wk_q_no
;
7435 q_addr
= ASC_QNO_TO_QADDR(next_qp
);
7436 scsi_sg_q
.sg_head_qp
= q_no
;
7437 scsi_sg_q
.cntl
= QCSG_SG_XFER_LIST
;
7438 for (i
= 0; i
< sg_head
->queue_cnt
; i
++) {
7439 scsi_sg_q
.seq_no
= i
+ 1;
7440 if (sg_entry_cnt
> ASC_SG_LIST_PER_Q
) {
7441 sg_list_dwords
= (uchar
)(ASC_SG_LIST_PER_Q
* 2);
7442 sg_entry_cnt
-= ASC_SG_LIST_PER_Q
;
7444 * After very first SG queue RISC FW uses next
7445 * SG queue first element then checks sg_list_cnt
7446 * against zero and then decrements, so set
7447 * sg_list_cnt 1 less than number of SG elements
7450 scsi_sg_q
.sg_list_cnt
= ASC_SG_LIST_PER_Q
- 1;
7451 scsi_sg_q
.sg_cur_list_cnt
=
7452 ASC_SG_LIST_PER_Q
- 1;
7455 * This is the last SG queue in the list of
7456 * allocated SG queues. If there are more
7457 * SG elements than will fit in the allocated
7458 * queues, then set the QCSG_SG_XFER_MORE flag.
7460 if (scsiq
->remain_sg_entry_cnt
!= 0) {
7461 scsi_sg_q
.cntl
|= QCSG_SG_XFER_MORE
;
7463 scsi_sg_q
.cntl
|= QCSG_SG_XFER_END
;
7465 /* equals sg_entry_cnt * 2 */
7466 sg_list_dwords
= sg_entry_cnt
<< 1;
7467 scsi_sg_q
.sg_list_cnt
= sg_entry_cnt
- 1;
7468 scsi_sg_q
.sg_cur_list_cnt
= sg_entry_cnt
- 1;
7472 scsi_sg_q
.q_no
= next_qp
;
7473 AscMemWordCopyPtrToLram(iop_base
,
7474 q_addr
+ ASC_SCSIQ_SGHD_CPY_BEG
,
7475 (uchar
*)&scsi_sg_q
,
7476 sizeof(ASC_SG_LIST_Q
) >> 1);
7478 AscMemDWordCopyPtrToLram(iop_base
,
7479 q_addr
+ ASC_SGQ_LIST_BEG
,
7481 sg_list
[scsiq
->next_sg_index
],
7484 scsiq
->next_sg_index
+= ASC_SG_LIST_PER_Q
;
7487 * If the just completed SG queue contained the
7488 * last SG element, then no more SG queues need
7491 if (scsi_sg_q
.cntl
& QCSG_SG_XFER_END
) {
7495 next_qp
= AscReadLramByte(iop_base
,
7498 q_addr
= ASC_QNO_TO_QADDR(next_qp
);
7502 * Clear the halt condition so the RISC will be restarted
7505 AscWriteLramWord(iop_base
, ASCV_HALTCODE_W
, 0);
7508 #endif /* CC_VERY_LONG_SG_LIST */
7514 * DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
7516 * Calling/Exit State:
7520 * Input an ASC_QDONE_INFO structure from the chip
7523 DvcGetQinfo(PortAddr iop_base
, ushort s_addr
, uchar
*inbuf
, int words
)
7528 AscSetChipLramAddr(iop_base
, s_addr
);
7529 for (i
= 0; i
< 2 * words
; i
+= 2) {
7533 word
= inpw(iop_base
+ IOP_RAM_DATA
);
7534 inbuf
[i
] = word
& 0xff;
7535 inbuf
[i
+ 1] = (word
>> 8) & 0xff;
7537 ASC_DBG_PRT_HEX(2, "DvcGetQinfo", inbuf
, 2 * words
);
7541 _AscCopyLramScsiDoneQ(PortAddr iop_base
,
7543 ASC_QDONE_INFO
*scsiq
, ASC_DCNT max_dma_count
)
7548 DvcGetQinfo(iop_base
,
7549 q_addr
+ ASC_SCSIQ_DONE_INFO_BEG
,
7551 (sizeof(ASC_SCSIQ_2
) + sizeof(ASC_SCSIQ_3
)) / 2);
7553 _val
= AscReadLramWord(iop_base
,
7554 (ushort
)(q_addr
+ (ushort
)ASC_SCSIQ_B_STATUS
));
7555 scsiq
->q_status
= (uchar
)_val
;
7556 scsiq
->q_no
= (uchar
)(_val
>> 8);
7557 _val
= AscReadLramWord(iop_base
,
7558 (ushort
)(q_addr
+ (ushort
)ASC_SCSIQ_B_CNTL
));
7559 scsiq
->cntl
= (uchar
)_val
;
7560 sg_queue_cnt
= (uchar
)(_val
>> 8);
7561 _val
= AscReadLramWord(iop_base
,
7563 (ushort
)ASC_SCSIQ_B_SENSE_LEN
));
7564 scsiq
->sense_len
= (uchar
)_val
;
7565 scsiq
->extra_bytes
= (uchar
)(_val
>> 8);
7568 * Read high word of remain bytes from alternate location.
7570 scsiq
->remain_bytes
= (((ADV_DCNT
)AscReadLramWord(iop_base
,
7573 ASC_SCSIQ_W_ALT_DC1
)))
7576 * Read low word of remain bytes from original location.
7578 scsiq
->remain_bytes
+= AscReadLramWord(iop_base
,
7579 (ushort
)(q_addr
+ (ushort
)
7580 ASC_SCSIQ_DW_REMAIN_XFER_CNT
));
7582 scsiq
->remain_bytes
&= max_dma_count
;
7583 return sg_queue_cnt
;
7587 * asc_isr_callback() - Second Level Interrupt Handler called by AscISR().
7589 * Interrupt callback function for the Narrow SCSI Asc Library.
7591 static void asc_isr_callback(ASC_DVC_VAR
*asc_dvc_varp
, ASC_QDONE_INFO
*qdonep
)
7593 struct asc_board
*boardp
;
7594 struct scsi_cmnd
*scp
;
7595 struct Scsi_Host
*shost
;
7597 ASC_DBG(1, "asc_dvc_varp 0x%p, qdonep 0x%p\n", asc_dvc_varp
, qdonep
);
7598 ASC_DBG_PRT_ASC_QDONE_INFO(2, qdonep
);
7600 scp
= advansys_srb_to_ptr(asc_dvc_varp
, qdonep
->d2
.srb_ptr
);
7604 ASC_DBG_PRT_CDB(2, scp
->cmnd
, scp
->cmd_len
);
7606 shost
= scp
->device
->host
;
7607 ASC_STATS(shost
, callback
);
7608 ASC_DBG(1, "shost 0x%p\n", shost
);
7610 boardp
= shost_priv(shost
);
7611 BUG_ON(asc_dvc_varp
!= &boardp
->dvc_var
.asc_dvc_var
);
7613 dma_unmap_single(boardp
->dev
, scp
->SCp
.dma_handle
,
7614 SCSI_SENSE_BUFFERSIZE
, DMA_FROM_DEVICE
);
7616 * 'qdonep' contains the command's ending status.
7618 switch (qdonep
->d3
.done_stat
) {
7620 ASC_DBG(2, "QD_NO_ERROR\n");
7624 * Check for an underrun condition.
7626 * If there was no error and an underrun condition, then
7627 * return the number of underrun bytes.
7629 if (scsi_bufflen(scp
) != 0 && qdonep
->remain_bytes
!= 0 &&
7630 qdonep
->remain_bytes
<= scsi_bufflen(scp
)) {
7631 ASC_DBG(1, "underrun condition %u bytes\n",
7632 (unsigned)qdonep
->remain_bytes
);
7633 scsi_set_resid(scp
, qdonep
->remain_bytes
);
7638 ASC_DBG(2, "QD_WITH_ERROR\n");
7639 switch (qdonep
->d3
.host_stat
) {
7640 case QHSTA_NO_ERROR
:
7641 if (qdonep
->d3
.scsi_stat
== SAM_STAT_CHECK_CONDITION
) {
7642 ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
7643 ASC_DBG_PRT_SENSE(2, scp
->sense_buffer
,
7644 SCSI_SENSE_BUFFERSIZE
);
7646 * Note: The 'status_byte()' macro used by
7647 * target drivers defined in scsi.h shifts the
7648 * status byte returned by host drivers right
7649 * by 1 bit. This is why target drivers also
7650 * use right shifted status byte definitions.
7651 * For instance target drivers use
7652 * CHECK_CONDITION, defined to 0x1, instead of
7653 * the SCSI defined check condition value of
7654 * 0x2. Host drivers are supposed to return
7655 * the status byte as it is defined by SCSI.
7657 scp
->result
= DRIVER_BYTE(DRIVER_SENSE
) |
7658 STATUS_BYTE(qdonep
->d3
.scsi_stat
);
7660 scp
->result
= STATUS_BYTE(qdonep
->d3
.scsi_stat
);
7665 /* QHSTA error occurred */
7666 ASC_DBG(1, "host_stat 0x%x\n", qdonep
->d3
.host_stat
);
7667 scp
->result
= HOST_BYTE(DID_BAD_TARGET
);
7672 case QD_ABORTED_BY_HOST
:
7673 ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
7675 HOST_BYTE(DID_ABORT
) | MSG_BYTE(qdonep
->d3
.
7677 STATUS_BYTE(qdonep
->d3
.scsi_stat
);
7681 ASC_DBG(1, "done_stat 0x%x\n", qdonep
->d3
.done_stat
);
7683 HOST_BYTE(DID_ERROR
) | MSG_BYTE(qdonep
->d3
.
7685 STATUS_BYTE(qdonep
->d3
.scsi_stat
);
7690 * If the 'init_tidmask' bit isn't already set for the target and the
7691 * current request finished normally, then set the bit for the target
7692 * to indicate that a device is present.
7694 if ((boardp
->init_tidmask
& ADV_TID_TO_TIDMASK(scp
->device
->id
)) == 0 &&
7695 qdonep
->d3
.done_stat
== QD_NO_ERROR
&&
7696 qdonep
->d3
.host_stat
== QHSTA_NO_ERROR
) {
7697 boardp
->init_tidmask
|= ADV_TID_TO_TIDMASK(scp
->device
->id
);
7703 static int AscIsrQDone(ASC_DVC_VAR
*asc_dvc
)
7712 ASC_SCSI_BIT_ID_TYPE scsi_busy
;
7713 ASC_SCSI_BIT_ID_TYPE target_id
;
7717 uchar cur_target_qng
;
7718 ASC_QDONE_INFO scsiq_buf
;
7719 ASC_QDONE_INFO
*scsiq
;
7722 iop_base
= asc_dvc
->iop_base
;
7724 scsiq
= (ASC_QDONE_INFO
*)&scsiq_buf
;
7725 done_q_tail
= (uchar
)AscGetVarDoneQTail(iop_base
);
7726 q_addr
= ASC_QNO_TO_QADDR(done_q_tail
);
7727 next_qp
= AscReadLramByte(iop_base
,
7728 (ushort
)(q_addr
+ (ushort
)ASC_SCSIQ_B_FWD
));
7729 if (next_qp
!= ASC_QLINK_END
) {
7730 AscPutVarDoneQTail(iop_base
, next_qp
);
7731 q_addr
= ASC_QNO_TO_QADDR(next_qp
);
7732 sg_queue_cnt
= _AscCopyLramScsiDoneQ(iop_base
, q_addr
, scsiq
,
7733 asc_dvc
->max_dma_count
);
7734 AscWriteLramByte(iop_base
,
7736 (ushort
)ASC_SCSIQ_B_STATUS
),
7738 q_status
& (uchar
)~(QS_READY
|
7740 tid_no
= ASC_TIX_TO_TID(scsiq
->d2
.target_ix
);
7741 target_id
= ASC_TIX_TO_TARGET_ID(scsiq
->d2
.target_ix
);
7742 if ((scsiq
->cntl
& QC_SG_HEAD
) != 0) {
7744 sg_list_qp
= next_qp
;
7745 for (q_cnt
= 0; q_cnt
< sg_queue_cnt
; q_cnt
++) {
7746 sg_list_qp
= AscReadLramByte(iop_base
,
7750 sg_q_addr
= ASC_QNO_TO_QADDR(sg_list_qp
);
7751 if (sg_list_qp
== ASC_QLINK_END
) {
7752 AscSetLibErrorCode(asc_dvc
,
7753 ASCQ_ERR_SG_Q_LINKS
);
7754 scsiq
->d3
.done_stat
= QD_WITH_ERROR
;
7755 scsiq
->d3
.host_stat
=
7756 QHSTA_D_QDONE_SG_LIST_CORRUPTED
;
7757 goto FATAL_ERR_QDONE
;
7759 AscWriteLramByte(iop_base
,
7760 (ushort
)(sg_q_addr
+ (ushort
)
7761 ASC_SCSIQ_B_STATUS
),
7764 n_q_used
= sg_queue_cnt
+ 1;
7765 AscPutVarDoneQTail(iop_base
, sg_list_qp
);
7767 if (asc_dvc
->queue_full_or_busy
& target_id
) {
7768 cur_target_qng
= AscReadLramByte(iop_base
,
7774 if (cur_target_qng
< asc_dvc
->max_dvc_qng
[tid_no
]) {
7775 scsi_busy
= AscReadLramByte(iop_base
, (ushort
)
7777 scsi_busy
&= ~target_id
;
7778 AscWriteLramByte(iop_base
,
7779 (ushort
)ASCV_SCSIBUSY_B
,
7781 asc_dvc
->queue_full_or_busy
&= ~target_id
;
7784 if (asc_dvc
->cur_total_qng
>= n_q_used
) {
7785 asc_dvc
->cur_total_qng
-= n_q_used
;
7786 if (asc_dvc
->cur_dvc_qng
[tid_no
] != 0) {
7787 asc_dvc
->cur_dvc_qng
[tid_no
]--;
7790 AscSetLibErrorCode(asc_dvc
, ASCQ_ERR_CUR_QNG
);
7791 scsiq
->d3
.done_stat
= QD_WITH_ERROR
;
7792 goto FATAL_ERR_QDONE
;
7794 if ((scsiq
->d2
.srb_ptr
== 0UL) ||
7795 ((scsiq
->q_status
& QS_ABORTED
) != 0)) {
7797 } else if (scsiq
->q_status
== QS_DONE
) {
7798 false_overrun
= FALSE
;
7799 if (scsiq
->extra_bytes
!= 0) {
7800 scsiq
->remain_bytes
+=
7801 (ADV_DCNT
)scsiq
->extra_bytes
;
7803 if (scsiq
->d3
.done_stat
== QD_WITH_ERROR
) {
7804 if (scsiq
->d3
.host_stat
==
7805 QHSTA_M_DATA_OVER_RUN
) {
7807 cntl
& (QC_DATA_IN
| QC_DATA_OUT
))
7809 scsiq
->d3
.done_stat
=
7811 scsiq
->d3
.host_stat
=
7813 } else if (false_overrun
) {
7814 scsiq
->d3
.done_stat
=
7816 scsiq
->d3
.host_stat
=
7819 } else if (scsiq
->d3
.host_stat
==
7820 QHSTA_M_HUNG_REQ_SCSI_BUS_RESET
) {
7821 AscStopChip(iop_base
);
7822 AscSetChipControl(iop_base
,
7823 (uchar
)(CC_SCSI_RESET
7826 AscSetChipControl(iop_base
, CC_HALT
);
7827 AscSetChipStatus(iop_base
,
7828 CIW_CLR_SCSI_RESET_INT
);
7829 AscSetChipStatus(iop_base
, 0);
7830 AscSetChipControl(iop_base
, 0);
7833 if ((scsiq
->cntl
& QC_NO_CALLBACK
) == 0) {
7834 asc_isr_callback(asc_dvc
, scsiq
);
7836 if ((AscReadLramByte(iop_base
,
7837 (ushort
)(q_addr
+ (ushort
)
7840 asc_dvc
->unit_not_ready
&= ~target_id
;
7841 if (scsiq
->d3
.done_stat
!= QD_NO_ERROR
) {
7842 asc_dvc
->start_motor
&=
7849 AscSetLibErrorCode(asc_dvc
, ASCQ_ERR_Q_STATUS
);
7851 if ((scsiq
->cntl
& QC_NO_CALLBACK
) == 0) {
7852 asc_isr_callback(asc_dvc
, scsiq
);
7860 static int AscISR(ASC_DVC_VAR
*asc_dvc
)
7862 ASC_CS_TYPE chipstat
;
7864 ushort saved_ram_addr
;
7866 uchar saved_ctrl_reg
;
7871 iop_base
= asc_dvc
->iop_base
;
7872 int_pending
= FALSE
;
7874 if (AscIsIntPending(iop_base
) == 0)
7877 if ((asc_dvc
->init_state
& ASC_INIT_STATE_END_LOAD_MC
) == 0) {
7880 if (asc_dvc
->in_critical_cnt
!= 0) {
7881 AscSetLibErrorCode(asc_dvc
, ASCQ_ERR_ISR_ON_CRITICAL
);
7884 if (asc_dvc
->is_in_int
) {
7885 AscSetLibErrorCode(asc_dvc
, ASCQ_ERR_ISR_RE_ENTRY
);
7888 asc_dvc
->is_in_int
= TRUE
;
7889 ctrl_reg
= AscGetChipControl(iop_base
);
7890 saved_ctrl_reg
= ctrl_reg
& (~(CC_SCSI_RESET
| CC_CHIP_RESET
|
7891 CC_SINGLE_STEP
| CC_DIAG
| CC_TEST
));
7892 chipstat
= AscGetChipStatus(iop_base
);
7893 if (chipstat
& CSW_SCSI_RESET_LATCH
) {
7894 if (!(asc_dvc
->bus_type
& (ASC_IS_VL
| ASC_IS_EISA
))) {
7897 asc_dvc
->sdtr_done
= 0;
7898 saved_ctrl_reg
&= (uchar
)(~CC_HALT
);
7899 while ((AscGetChipStatus(iop_base
) &
7900 CSW_SCSI_RESET_ACTIVE
) && (i
-- > 0)) {
7903 AscSetChipControl(iop_base
, (CC_CHIP_RESET
| CC_HALT
));
7904 AscSetChipControl(iop_base
, CC_HALT
);
7905 AscSetChipStatus(iop_base
, CIW_CLR_SCSI_RESET_INT
);
7906 AscSetChipStatus(iop_base
, 0);
7907 chipstat
= AscGetChipStatus(iop_base
);
7910 saved_ram_addr
= AscGetChipLramAddr(iop_base
);
7911 host_flag
= AscReadLramByte(iop_base
,
7913 (uchar
)(~ASC_HOST_FLAG_IN_ISR
);
7914 AscWriteLramByte(iop_base
, ASCV_HOST_FLAG_B
,
7915 (uchar
)(host_flag
| (uchar
)ASC_HOST_FLAG_IN_ISR
));
7916 if ((chipstat
& CSW_INT_PENDING
) || (int_pending
)) {
7917 AscAckInterrupt(iop_base
);
7919 if ((chipstat
& CSW_HALTED
) && (ctrl_reg
& CC_SINGLE_STEP
)) {
7920 if (AscIsrChipHalted(asc_dvc
) == ERR
) {
7921 goto ISR_REPORT_QDONE_FATAL_ERROR
;
7923 saved_ctrl_reg
&= (uchar
)(~CC_HALT
);
7926 ISR_REPORT_QDONE_FATAL_ERROR
:
7927 if ((asc_dvc
->dvc_cntl
& ASC_CNTL_INT_MULTI_Q
) != 0) {
7929 AscIsrQDone(asc_dvc
)) & 0x01) != 0) {
7934 AscIsrQDone(asc_dvc
)) == 1) {
7937 } while (status
== 0x11);
7939 if ((status
& 0x80) != 0)
7943 AscWriteLramByte(iop_base
, ASCV_HOST_FLAG_B
, host_flag
);
7944 AscSetChipLramAddr(iop_base
, saved_ram_addr
);
7945 AscSetChipControl(iop_base
, saved_ctrl_reg
);
7946 asc_dvc
->is_in_int
= FALSE
;
7953 * Reset the bus associated with the command 'scp'.
7955 * This function runs its own thread. Interrupts must be blocked but
7956 * sleeping is allowed and no locking other than for host structures is
7957 * required. Returns SUCCESS or FAILED.
7959 static int advansys_reset(struct scsi_cmnd
*scp
)
7961 struct Scsi_Host
*shost
= scp
->device
->host
;
7962 struct asc_board
*boardp
= shost_priv(shost
);
7963 unsigned long flags
;
7967 ASC_DBG(1, "0x%p\n", scp
);
7969 ASC_STATS(shost
, reset
);
7971 scmd_printk(KERN_INFO
, scp
, "SCSI bus reset started...\n");
7973 if (ASC_NARROW_BOARD(boardp
)) {
7974 ASC_DVC_VAR
*asc_dvc
= &boardp
->dvc_var
.asc_dvc_var
;
7976 /* Reset the chip and SCSI bus. */
7977 ASC_DBG(1, "before AscInitAsc1000Driver()\n");
7978 status
= AscInitAsc1000Driver(asc_dvc
);
7980 /* Refer to ASC_IERR_* definitions for meaning of 'err_code'. */
7981 if (asc_dvc
->err_code
) {
7982 scmd_printk(KERN_INFO
, scp
, "SCSI bus reset error: "
7983 "0x%x\n", asc_dvc
->err_code
);
7985 } else if (status
) {
7986 scmd_printk(KERN_INFO
, scp
, "SCSI bus reset warning: "
7989 scmd_printk(KERN_INFO
, scp
, "SCSI bus reset "
7993 ASC_DBG(1, "after AscInitAsc1000Driver()\n");
7994 spin_lock_irqsave(shost
->host_lock
, flags
);
7997 * If the suggest reset bus flags are set, then reset the bus.
7998 * Otherwise only reset the device.
8000 ADV_DVC_VAR
*adv_dvc
= &boardp
->dvc_var
.adv_dvc_var
;
8003 * Reset the target's SCSI bus.
8005 ASC_DBG(1, "before AdvResetChipAndSB()\n");
8006 switch (AdvResetChipAndSB(adv_dvc
)) {
8008 scmd_printk(KERN_INFO
, scp
, "SCSI bus reset "
8013 scmd_printk(KERN_INFO
, scp
, "SCSI bus reset error\n");
8017 spin_lock_irqsave(shost
->host_lock
, flags
);
8021 /* Save the time of the most recently completed reset. */
8022 boardp
->last_reset
= jiffies
;
8023 spin_unlock_irqrestore(shost
->host_lock
, flags
);
8025 ASC_DBG(1, "ret %d\n", ret
);
8031 * advansys_biosparam()
8033 * Translate disk drive geometry if the "BIOS greater than 1 GB"
8034 * support is enabled for a drive.
8036 * ip (information pointer) is an int array with the following definition:
8042 advansys_biosparam(struct scsi_device
*sdev
, struct block_device
*bdev
,
8043 sector_t capacity
, int ip
[])
8045 struct asc_board
*boardp
= shost_priv(sdev
->host
);
8047 ASC_DBG(1, "begin\n");
8048 ASC_STATS(sdev
->host
, biosparam
);
8049 if (ASC_NARROW_BOARD(boardp
)) {
8050 if ((boardp
->dvc_var
.asc_dvc_var
.dvc_cntl
&
8051 ASC_CNTL_BIOS_GT_1GB
) && capacity
> 0x200000) {
8059 if ((boardp
->dvc_var
.adv_dvc_var
.bios_ctrl
&
8060 BIOS_CTRL_EXTENDED_XLAT
) && capacity
> 0x200000) {
8068 ip
[2] = (unsigned long)capacity
/ (ip
[0] * ip
[1]);
8069 ASC_DBG(1, "end\n");
8074 * First-level interrupt handler.
8076 * 'dev_id' is a pointer to the interrupting adapter's Scsi_Host.
8078 static irqreturn_t
advansys_interrupt(int irq
, void *dev_id
)
8080 struct Scsi_Host
*shost
= dev_id
;
8081 struct asc_board
*boardp
= shost_priv(shost
);
8082 irqreturn_t result
= IRQ_NONE
;
8084 ASC_DBG(2, "boardp 0x%p\n", boardp
);
8085 spin_lock(shost
->host_lock
);
8086 if (ASC_NARROW_BOARD(boardp
)) {
8087 if (AscIsIntPending(shost
->io_port
)) {
8088 result
= IRQ_HANDLED
;
8089 ASC_STATS(shost
, interrupt
);
8090 ASC_DBG(1, "before AscISR()\n");
8091 AscISR(&boardp
->dvc_var
.asc_dvc_var
);
8094 ASC_DBG(1, "before AdvISR()\n");
8095 if (AdvISR(&boardp
->dvc_var
.adv_dvc_var
)) {
8096 result
= IRQ_HANDLED
;
8097 ASC_STATS(shost
, interrupt
);
8100 spin_unlock(shost
->host_lock
);
8102 ASC_DBG(1, "end\n");
8106 static int AscHostReqRiscHalt(PortAddr iop_base
)
8110 uchar saved_stop_code
;
8112 if (AscIsChipHalted(iop_base
))
8114 saved_stop_code
= AscReadLramByte(iop_base
, ASCV_STOP_CODE_B
);
8115 AscWriteLramByte(iop_base
, ASCV_STOP_CODE_B
,
8116 ASC_STOP_HOST_REQ_RISC_HALT
| ASC_STOP_REQ_RISC_STOP
);
8118 if (AscIsChipHalted(iop_base
)) {
8123 } while (count
++ < 20);
8124 AscWriteLramByte(iop_base
, ASCV_STOP_CODE_B
, saved_stop_code
);
8129 AscSetRunChipSynRegAtID(PortAddr iop_base
, uchar tid_no
, uchar sdtr_data
)
8133 if (AscHostReqRiscHalt(iop_base
)) {
8134 sta
= AscSetChipSynRegAtID(iop_base
, tid_no
, sdtr_data
);
8135 AscStartChip(iop_base
);
8140 static void AscAsyncFix(ASC_DVC_VAR
*asc_dvc
, struct scsi_device
*sdev
)
8142 char type
= sdev
->type
;
8143 ASC_SCSI_BIT_ID_TYPE tid_bits
= 1 << sdev
->id
;
8145 if (!(asc_dvc
->bug_fix_cntl
& ASC_BUG_FIX_ASYN_USE_SYN
))
8147 if (asc_dvc
->init_sdtr
& tid_bits
)
8150 if ((type
== TYPE_ROM
) && (strncmp(sdev
->vendor
, "HP ", 3) == 0))
8151 asc_dvc
->pci_fix_asyn_xfer_always
|= tid_bits
;
8153 asc_dvc
->pci_fix_asyn_xfer
|= tid_bits
;
8154 if ((type
== TYPE_PROCESSOR
) || (type
== TYPE_SCANNER
) ||
8155 (type
== TYPE_ROM
) || (type
== TYPE_TAPE
))
8156 asc_dvc
->pci_fix_asyn_xfer
&= ~tid_bits
;
8158 if (asc_dvc
->pci_fix_asyn_xfer
& tid_bits
)
8159 AscSetRunChipSynRegAtID(asc_dvc
->iop_base
, sdev
->id
,
8160 ASYN_SDTR_DATA_FIX_PCI_REV_AB
);
8164 advansys_narrow_slave_configure(struct scsi_device
*sdev
, ASC_DVC_VAR
*asc_dvc
)
8166 ASC_SCSI_BIT_ID_TYPE tid_bit
= 1 << sdev
->id
;
8167 ASC_SCSI_BIT_ID_TYPE orig_use_tagged_qng
= asc_dvc
->use_tagged_qng
;
8169 if (sdev
->lun
== 0) {
8170 ASC_SCSI_BIT_ID_TYPE orig_init_sdtr
= asc_dvc
->init_sdtr
;
8171 if ((asc_dvc
->cfg
->sdtr_enable
& tid_bit
) && sdev
->sdtr
) {
8172 asc_dvc
->init_sdtr
|= tid_bit
;
8174 asc_dvc
->init_sdtr
&= ~tid_bit
;
8177 if (orig_init_sdtr
!= asc_dvc
->init_sdtr
)
8178 AscAsyncFix(asc_dvc
, sdev
);
8181 if (sdev
->tagged_supported
) {
8182 if (asc_dvc
->cfg
->cmd_qng_enabled
& tid_bit
) {
8183 if (sdev
->lun
== 0) {
8184 asc_dvc
->cfg
->can_tagged_qng
|= tid_bit
;
8185 asc_dvc
->use_tagged_qng
|= tid_bit
;
8187 scsi_adjust_queue_depth(sdev
, MSG_ORDERED_TAG
,
8188 asc_dvc
->max_dvc_qng
[sdev
->id
]);
8191 if (sdev
->lun
== 0) {
8192 asc_dvc
->cfg
->can_tagged_qng
&= ~tid_bit
;
8193 asc_dvc
->use_tagged_qng
&= ~tid_bit
;
8195 scsi_adjust_queue_depth(sdev
, 0, sdev
->host
->cmd_per_lun
);
8198 if ((sdev
->lun
== 0) &&
8199 (orig_use_tagged_qng
!= asc_dvc
->use_tagged_qng
)) {
8200 AscWriteLramByte(asc_dvc
->iop_base
, ASCV_DISC_ENABLE_B
,
8201 asc_dvc
->cfg
->disc_enable
);
8202 AscWriteLramByte(asc_dvc
->iop_base
, ASCV_USE_TAGGED_QNG_B
,
8203 asc_dvc
->use_tagged_qng
);
8204 AscWriteLramByte(asc_dvc
->iop_base
, ASCV_CAN_TAGGED_QNG_B
,
8205 asc_dvc
->cfg
->can_tagged_qng
);
8207 asc_dvc
->max_dvc_qng
[sdev
->id
] =
8208 asc_dvc
->cfg
->max_tag_qng
[sdev
->id
];
8209 AscWriteLramByte(asc_dvc
->iop_base
,
8210 (ushort
)(ASCV_MAX_DVC_QNG_BEG
+ sdev
->id
),
8211 asc_dvc
->max_dvc_qng
[sdev
->id
]);
8218 * If the EEPROM enabled WDTR for the device and the device supports wide
8219 * bus (16 bit) transfers, then turn on the device's 'wdtr_able' bit and
8220 * write the new value to the microcode.
8223 advansys_wide_enable_wdtr(AdvPortAddr iop_base
, unsigned short tidmask
)
8225 unsigned short cfg_word
;
8226 AdvReadWordLram(iop_base
, ASC_MC_WDTR_ABLE
, cfg_word
);
8227 if ((cfg_word
& tidmask
) != 0)
8230 cfg_word
|= tidmask
;
8231 AdvWriteWordLram(iop_base
, ASC_MC_WDTR_ABLE
, cfg_word
);
8234 * Clear the microcode SDTR and WDTR negotiation done indicators for
8235 * the target to cause it to negotiate with the new setting set above.
8236 * WDTR when accepted causes the target to enter asynchronous mode, so
8237 * SDTR must be negotiated.
8239 AdvReadWordLram(iop_base
, ASC_MC_SDTR_DONE
, cfg_word
);
8240 cfg_word
&= ~tidmask
;
8241 AdvWriteWordLram(iop_base
, ASC_MC_SDTR_DONE
, cfg_word
);
8242 AdvReadWordLram(iop_base
, ASC_MC_WDTR_DONE
, cfg_word
);
8243 cfg_word
&= ~tidmask
;
8244 AdvWriteWordLram(iop_base
, ASC_MC_WDTR_DONE
, cfg_word
);
8248 * Synchronous Transfers
8250 * If the EEPROM enabled SDTR for the device and the device
8251 * supports synchronous transfers, then turn on the device's
8252 * 'sdtr_able' bit. Write the new value to the microcode.
8255 advansys_wide_enable_sdtr(AdvPortAddr iop_base
, unsigned short tidmask
)
8257 unsigned short cfg_word
;
8258 AdvReadWordLram(iop_base
, ASC_MC_SDTR_ABLE
, cfg_word
);
8259 if ((cfg_word
& tidmask
) != 0)
8262 cfg_word
|= tidmask
;
8263 AdvWriteWordLram(iop_base
, ASC_MC_SDTR_ABLE
, cfg_word
);
8266 * Clear the microcode "SDTR negotiation" done indicator for the
8267 * target to cause it to negotiate with the new setting set above.
8269 AdvReadWordLram(iop_base
, ASC_MC_SDTR_DONE
, cfg_word
);
8270 cfg_word
&= ~tidmask
;
8271 AdvWriteWordLram(iop_base
, ASC_MC_SDTR_DONE
, cfg_word
);
8275 * PPR (Parallel Protocol Request) Capable
8277 * If the device supports DT mode, then it must be PPR capable.
8278 * The PPR message will be used in place of the SDTR and WDTR
8279 * messages to negotiate synchronous speed and offset, transfer
8280 * width, and protocol options.
8282 static void advansys_wide_enable_ppr(ADV_DVC_VAR
*adv_dvc
,
8283 AdvPortAddr iop_base
, unsigned short tidmask
)
8285 AdvReadWordLram(iop_base
, ASC_MC_PPR_ABLE
, adv_dvc
->ppr_able
);
8286 adv_dvc
->ppr_able
|= tidmask
;
8287 AdvWriteWordLram(iop_base
, ASC_MC_PPR_ABLE
, adv_dvc
->ppr_able
);
8291 advansys_wide_slave_configure(struct scsi_device
*sdev
, ADV_DVC_VAR
*adv_dvc
)
8293 AdvPortAddr iop_base
= adv_dvc
->iop_base
;
8294 unsigned short tidmask
= 1 << sdev
->id
;
8296 if (sdev
->lun
== 0) {
8298 * Handle WDTR, SDTR, and Tag Queuing. If the feature
8299 * is enabled in the EEPROM and the device supports the
8300 * feature, then enable it in the microcode.
8303 if ((adv_dvc
->wdtr_able
& tidmask
) && sdev
->wdtr
)
8304 advansys_wide_enable_wdtr(iop_base
, tidmask
);
8305 if ((adv_dvc
->sdtr_able
& tidmask
) && sdev
->sdtr
)
8306 advansys_wide_enable_sdtr(iop_base
, tidmask
);
8307 if (adv_dvc
->chip_type
== ADV_CHIP_ASC38C1600
&& sdev
->ppr
)
8308 advansys_wide_enable_ppr(adv_dvc
, iop_base
, tidmask
);
8311 * Tag Queuing is disabled for the BIOS which runs in polled
8312 * mode and would see no benefit from Tag Queuing. Also by
8313 * disabling Tag Queuing in the BIOS devices with Tag Queuing
8314 * bugs will at least work with the BIOS.
8316 if ((adv_dvc
->tagqng_able
& tidmask
) &&
8317 sdev
->tagged_supported
) {
8318 unsigned short cfg_word
;
8319 AdvReadWordLram(iop_base
, ASC_MC_TAGQNG_ABLE
, cfg_word
);
8320 cfg_word
|= tidmask
;
8321 AdvWriteWordLram(iop_base
, ASC_MC_TAGQNG_ABLE
,
8323 AdvWriteByteLram(iop_base
,
8324 ASC_MC_NUMBER_OF_MAX_CMD
+ sdev
->id
,
8325 adv_dvc
->max_dvc_qng
);
8329 if ((adv_dvc
->tagqng_able
& tidmask
) && sdev
->tagged_supported
) {
8330 scsi_adjust_queue_depth(sdev
, MSG_ORDERED_TAG
,
8331 adv_dvc
->max_dvc_qng
);
8333 scsi_adjust_queue_depth(sdev
, 0, sdev
->host
->cmd_per_lun
);
8338 * Set the number of commands to queue per device for the
8339 * specified host adapter.
8341 static int advansys_slave_configure(struct scsi_device
*sdev
)
8343 struct asc_board
*boardp
= shost_priv(sdev
->host
);
8345 if (ASC_NARROW_BOARD(boardp
))
8346 advansys_narrow_slave_configure(sdev
,
8347 &boardp
->dvc_var
.asc_dvc_var
);
8349 advansys_wide_slave_configure(sdev
,
8350 &boardp
->dvc_var
.adv_dvc_var
);
8355 static __le32
advansys_get_sense_buffer_dma(struct scsi_cmnd
*scp
)
8357 struct asc_board
*board
= shost_priv(scp
->device
->host
);
8358 scp
->SCp
.dma_handle
= dma_map_single(board
->dev
, scp
->sense_buffer
,
8359 SCSI_SENSE_BUFFERSIZE
, DMA_FROM_DEVICE
);
8360 dma_cache_sync(board
->dev
, scp
->sense_buffer
,
8361 SCSI_SENSE_BUFFERSIZE
, DMA_FROM_DEVICE
);
8362 return cpu_to_le32(scp
->SCp
.dma_handle
);
8365 static int asc_build_req(struct asc_board
*boardp
, struct scsi_cmnd
*scp
,
8366 struct asc_scsi_q
*asc_scsi_q
)
8368 struct asc_dvc_var
*asc_dvc
= &boardp
->dvc_var
.asc_dvc_var
;
8371 memset(asc_scsi_q
, 0, sizeof(*asc_scsi_q
));
8374 * Point the ASC_SCSI_Q to the 'struct scsi_cmnd'.
8376 asc_scsi_q
->q2
.srb_ptr
= advansys_ptr_to_srb(asc_dvc
, scp
);
8377 if (asc_scsi_q
->q2
.srb_ptr
== BAD_SRB
) {
8378 scp
->result
= HOST_BYTE(DID_SOFT_ERROR
);
8383 * Build the ASC_SCSI_Q request.
8385 asc_scsi_q
->cdbptr
= &scp
->cmnd
[0];
8386 asc_scsi_q
->q2
.cdb_len
= scp
->cmd_len
;
8387 asc_scsi_q
->q1
.target_id
= ASC_TID_TO_TARGET_ID(scp
->device
->id
);
8388 asc_scsi_q
->q1
.target_lun
= scp
->device
->lun
;
8389 asc_scsi_q
->q2
.target_ix
=
8390 ASC_TIDLUN_TO_IX(scp
->device
->id
, scp
->device
->lun
);
8391 asc_scsi_q
->q1
.sense_addr
= advansys_get_sense_buffer_dma(scp
);
8392 asc_scsi_q
->q1
.sense_len
= SCSI_SENSE_BUFFERSIZE
;
8395 * If there are any outstanding requests for the current target,
8396 * then every 255th request send an ORDERED request. This heuristic
8397 * tries to retain the benefit of request sorting while preventing
8398 * request starvation. 255 is the max number of tags or pending commands
8399 * a device may have outstanding.
8401 * The request count is incremented below for every successfully
8405 if ((asc_dvc
->cur_dvc_qng
[scp
->device
->id
] > 0) &&
8406 (boardp
->reqcnt
[scp
->device
->id
] % 255) == 0) {
8407 asc_scsi_q
->q2
.tag_code
= MSG_ORDERED_TAG
;
8409 asc_scsi_q
->q2
.tag_code
= MSG_SIMPLE_TAG
;
8412 /* Build ASC_SCSI_Q */
8413 use_sg
= scsi_dma_map(scp
);
8416 struct scatterlist
*slp
;
8417 struct asc_sg_head
*asc_sg_head
;
8419 if (use_sg
> scp
->device
->host
->sg_tablesize
) {
8420 scmd_printk(KERN_ERR
, scp
, "use_sg %d > "
8421 "sg_tablesize %d\n", use_sg
,
8422 scp
->device
->host
->sg_tablesize
);
8423 scsi_dma_unmap(scp
);
8424 scp
->result
= HOST_BYTE(DID_ERROR
);
8428 asc_sg_head
= kzalloc(sizeof(asc_scsi_q
->sg_head
) +
8429 use_sg
* sizeof(struct asc_sg_list
), GFP_ATOMIC
);
8431 scsi_dma_unmap(scp
);
8432 scp
->result
= HOST_BYTE(DID_SOFT_ERROR
);
8436 asc_scsi_q
->q1
.cntl
|= QC_SG_HEAD
;
8437 asc_scsi_q
->sg_head
= asc_sg_head
;
8438 asc_scsi_q
->q1
.data_cnt
= 0;
8439 asc_scsi_q
->q1
.data_addr
= 0;
8440 /* This is a byte value, otherwise it would need to be swapped. */
8441 asc_sg_head
->entry_cnt
= asc_scsi_q
->q1
.sg_queue_cnt
= use_sg
;
8442 ASC_STATS_ADD(scp
->device
->host
, xfer_elem
,
8443 asc_sg_head
->entry_cnt
);
8446 * Convert scatter-gather list into ASC_SG_HEAD list.
8448 scsi_for_each_sg(scp
, slp
, use_sg
, sgcnt
) {
8449 asc_sg_head
->sg_list
[sgcnt
].addr
=
8450 cpu_to_le32(sg_dma_address(slp
));
8451 asc_sg_head
->sg_list
[sgcnt
].bytes
=
8452 cpu_to_le32(sg_dma_len(slp
));
8453 ASC_STATS_ADD(scp
->device
->host
, xfer_sect
,
8454 DIV_ROUND_UP(sg_dma_len(slp
), 512));
8458 ASC_STATS(scp
->device
->host
, xfer_cnt
);
8460 ASC_DBG_PRT_ASC_SCSI_Q(2, asc_scsi_q
);
8461 ASC_DBG_PRT_CDB(1, scp
->cmnd
, scp
->cmd_len
);
8467 * Build scatter-gather list for Adv Library (Wide Board).
8469 * Additional ADV_SG_BLOCK structures will need to be allocated
8470 * if the total number of scatter-gather elements exceeds
8471 * NO_OF_SG_PER_BLOCK (15). The ADV_SG_BLOCK structures are
8472 * assumed to be physically contiguous.
8475 * ADV_SUCCESS(1) - SG List successfully created
8476 * ADV_ERROR(-1) - SG List creation failed
8479 adv_get_sglist(struct asc_board
*boardp
, adv_req_t
*reqp
, struct scsi_cmnd
*scp
,
8482 adv_sgblk_t
*sgblkp
;
8483 ADV_SCSI_REQ_Q
*scsiqp
;
8484 struct scatterlist
*slp
;
8486 ADV_SG_BLOCK
*sg_block
, *prev_sg_block
;
8487 ADV_PADDR sg_block_paddr
;
8490 scsiqp
= (ADV_SCSI_REQ_Q
*)ADV_32BALIGN(&reqp
->scsi_req_q
);
8491 slp
= scsi_sglist(scp
);
8492 sg_elem_cnt
= use_sg
;
8493 prev_sg_block
= NULL
;
8494 reqp
->sgblkp
= NULL
;
8498 * Allocate a 'adv_sgblk_t' structure from the board free
8499 * list. One 'adv_sgblk_t' structure holds NO_OF_SG_PER_BLOCK
8500 * (15) scatter-gather elements.
8502 if ((sgblkp
= boardp
->adv_sgblkp
) == NULL
) {
8503 ASC_DBG(1, "no free adv_sgblk_t\n");
8504 ASC_STATS(scp
->device
->host
, adv_build_nosg
);
8507 * Allocation failed. Free 'adv_sgblk_t' structures
8508 * already allocated for the request.
8510 while ((sgblkp
= reqp
->sgblkp
) != NULL
) {
8511 /* Remove 'sgblkp' from the request list. */
8512 reqp
->sgblkp
= sgblkp
->next_sgblkp
;
8514 /* Add 'sgblkp' to the board free list. */
8515 sgblkp
->next_sgblkp
= boardp
->adv_sgblkp
;
8516 boardp
->adv_sgblkp
= sgblkp
;
8521 /* Complete 'adv_sgblk_t' board allocation. */
8522 boardp
->adv_sgblkp
= sgblkp
->next_sgblkp
;
8523 sgblkp
->next_sgblkp
= NULL
;
8526 * Get 8 byte aligned virtual and physical addresses
8527 * for the allocated ADV_SG_BLOCK structure.
8529 sg_block
= (ADV_SG_BLOCK
*)ADV_8BALIGN(&sgblkp
->sg_block
);
8530 sg_block_paddr
= virt_to_bus(sg_block
);
8533 * Check if this is the first 'adv_sgblk_t' for the
8536 if (reqp
->sgblkp
== NULL
) {
8537 /* Request's first scatter-gather block. */
8538 reqp
->sgblkp
= sgblkp
;
8541 * Set ADV_SCSI_REQ_T ADV_SG_BLOCK virtual and physical
8544 scsiqp
->sg_list_ptr
= sg_block
;
8545 scsiqp
->sg_real_addr
= cpu_to_le32(sg_block_paddr
);
8547 /* Request's second or later scatter-gather block. */
8548 sgblkp
->next_sgblkp
= reqp
->sgblkp
;
8549 reqp
->sgblkp
= sgblkp
;
8552 * Point the previous ADV_SG_BLOCK structure to
8553 * the newly allocated ADV_SG_BLOCK structure.
8555 prev_sg_block
->sg_ptr
= cpu_to_le32(sg_block_paddr
);
8558 for (i
= 0; i
< NO_OF_SG_PER_BLOCK
; i
++) {
8559 sg_block
->sg_list
[i
].sg_addr
=
8560 cpu_to_le32(sg_dma_address(slp
));
8561 sg_block
->sg_list
[i
].sg_count
=
8562 cpu_to_le32(sg_dma_len(slp
));
8563 ASC_STATS_ADD(scp
->device
->host
, xfer_sect
,
8564 DIV_ROUND_UP(sg_dma_len(slp
), 512));
8566 if (--sg_elem_cnt
== 0) { /* Last ADV_SG_BLOCK and scatter-gather entry. */
8567 sg_block
->sg_cnt
= i
+ 1;
8568 sg_block
->sg_ptr
= 0L; /* Last ADV_SG_BLOCK in list. */
8573 sg_block
->sg_cnt
= NO_OF_SG_PER_BLOCK
;
8574 prev_sg_block
= sg_block
;
8579 * Build a request structure for the Adv Library (Wide Board).
8581 * If an adv_req_t can not be allocated to issue the request,
8582 * then return ASC_BUSY. If an error occurs, then return ASC_ERROR.
8584 * Multi-byte fields in the ASC_SCSI_REQ_Q that are used by the
8585 * microcode for DMA addresses or math operations are byte swapped
8586 * to little-endian order.
8589 adv_build_req(struct asc_board
*boardp
, struct scsi_cmnd
*scp
,
8590 ADV_SCSI_REQ_Q
**adv_scsiqpp
)
8593 ADV_SCSI_REQ_Q
*scsiqp
;
8599 * Allocate an adv_req_t structure from the board to execute
8602 if (boardp
->adv_reqp
== NULL
) {
8603 ASC_DBG(1, "no free adv_req_t\n");
8604 ASC_STATS(scp
->device
->host
, adv_build_noreq
);
8607 reqp
= boardp
->adv_reqp
;
8608 boardp
->adv_reqp
= reqp
->next_reqp
;
8609 reqp
->next_reqp
= NULL
;
8613 * Get 32-byte aligned ADV_SCSI_REQ_Q and ADV_SG_BLOCK pointers.
8615 scsiqp
= (ADV_SCSI_REQ_Q
*)ADV_32BALIGN(&reqp
->scsi_req_q
);
8618 * Initialize the structure.
8620 scsiqp
->cntl
= scsiqp
->scsi_cntl
= scsiqp
->done_status
= 0;
8623 * Set the ADV_SCSI_REQ_Q 'srb_ptr' to point to the adv_req_t structure.
8625 scsiqp
->srb_ptr
= ADV_VADDR_TO_U32(reqp
);
8628 * Set the adv_req_t 'cmndp' to point to the struct scsi_cmnd structure.
8633 * Build the ADV_SCSI_REQ_Q request.
8636 /* Set CDB length and copy it to the request structure. */
8637 scsiqp
->cdb_len
= scp
->cmd_len
;
8638 /* Copy first 12 CDB bytes to cdb[]. */
8639 for (i
= 0; i
< scp
->cmd_len
&& i
< 12; i
++) {
8640 scsiqp
->cdb
[i
] = scp
->cmnd
[i
];
8642 /* Copy last 4 CDB bytes, if present, to cdb16[]. */
8643 for (; i
< scp
->cmd_len
; i
++) {
8644 scsiqp
->cdb16
[i
- 12] = scp
->cmnd
[i
];
8647 scsiqp
->target_id
= scp
->device
->id
;
8648 scsiqp
->target_lun
= scp
->device
->lun
;
8650 scsiqp
->sense_addr
= cpu_to_le32(virt_to_bus(&scp
->sense_buffer
[0]));
8651 scsiqp
->sense_len
= SCSI_SENSE_BUFFERSIZE
;
8653 /* Build ADV_SCSI_REQ_Q */
8655 use_sg
= scsi_dma_map(scp
);
8657 /* Zero-length transfer */
8658 reqp
->sgblkp
= NULL
;
8659 scsiqp
->data_cnt
= 0;
8660 scsiqp
->vdata_addr
= NULL
;
8662 scsiqp
->data_addr
= 0;
8663 scsiqp
->sg_list_ptr
= NULL
;
8664 scsiqp
->sg_real_addr
= 0;
8666 if (use_sg
> ADV_MAX_SG_LIST
) {
8667 scmd_printk(KERN_ERR
, scp
, "use_sg %d > "
8668 "ADV_MAX_SG_LIST %d\n", use_sg
,
8669 scp
->device
->host
->sg_tablesize
);
8670 scsi_dma_unmap(scp
);
8671 scp
->result
= HOST_BYTE(DID_ERROR
);
8674 * Free the 'adv_req_t' structure by adding it back
8675 * to the board free list.
8677 reqp
->next_reqp
= boardp
->adv_reqp
;
8678 boardp
->adv_reqp
= reqp
;
8683 scsiqp
->data_cnt
= cpu_to_le32(scsi_bufflen(scp
));
8685 ret
= adv_get_sglist(boardp
, reqp
, scp
, use_sg
);
8686 if (ret
!= ADV_SUCCESS
) {
8688 * Free the adv_req_t structure by adding it back to
8689 * the board free list.
8691 reqp
->next_reqp
= boardp
->adv_reqp
;
8692 boardp
->adv_reqp
= reqp
;
8697 ASC_STATS_ADD(scp
->device
->host
, xfer_elem
, use_sg
);
8700 ASC_STATS(scp
->device
->host
, xfer_cnt
);
8702 ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp
);
8703 ASC_DBG_PRT_CDB(1, scp
->cmnd
, scp
->cmd_len
);
8705 *adv_scsiqpp
= scsiqp
;
8710 static int AscSgListToQueue(int sg_list
)
8714 n_sg_list_qs
= ((sg_list
- 1) / ASC_SG_LIST_PER_Q
);
8715 if (((sg_list
- 1) % ASC_SG_LIST_PER_Q
) != 0)
8717 return n_sg_list_qs
+ 1;
8721 AscGetNumOfFreeQueue(ASC_DVC_VAR
*asc_dvc
, uchar target_ix
, uchar n_qs
)
8725 ASC_SCSI_BIT_ID_TYPE target_id
;
8728 target_id
= ASC_TIX_TO_TARGET_ID(target_ix
);
8729 tid_no
= ASC_TIX_TO_TID(target_ix
);
8730 if ((asc_dvc
->unit_not_ready
& target_id
) ||
8731 (asc_dvc
->queue_full_or_busy
& target_id
)) {
8735 cur_used_qs
= (uint
) asc_dvc
->cur_total_qng
+
8736 (uint
) asc_dvc
->last_q_shortage
+ (uint
) ASC_MIN_FREE_Q
;
8738 cur_used_qs
= (uint
) asc_dvc
->cur_total_qng
+
8739 (uint
) ASC_MIN_FREE_Q
;
8741 if ((uint
) (cur_used_qs
+ n_qs
) <= (uint
) asc_dvc
->max_total_qng
) {
8742 cur_free_qs
= (uint
) asc_dvc
->max_total_qng
- cur_used_qs
;
8743 if (asc_dvc
->cur_dvc_qng
[tid_no
] >=
8744 asc_dvc
->max_dvc_qng
[tid_no
]) {
8750 if ((n_qs
> asc_dvc
->last_q_shortage
)
8751 && (n_qs
<= (asc_dvc
->max_total_qng
- ASC_MIN_FREE_Q
))) {
8752 asc_dvc
->last_q_shortage
= n_qs
;
8758 static uchar
AscAllocFreeQueue(PortAddr iop_base
, uchar free_q_head
)
8764 q_addr
= ASC_QNO_TO_QADDR(free_q_head
);
8765 q_status
= (uchar
)AscReadLramByte(iop_base
,
8767 ASC_SCSIQ_B_STATUS
));
8768 next_qp
= AscReadLramByte(iop_base
, (ushort
)(q_addr
+ ASC_SCSIQ_B_FWD
));
8769 if (((q_status
& QS_READY
) == 0) && (next_qp
!= ASC_QLINK_END
))
8771 return ASC_QLINK_END
;
8775 AscAllocMultipleFreeQueue(PortAddr iop_base
, uchar free_q_head
, uchar n_free_q
)
8779 for (i
= 0; i
< n_free_q
; i
++) {
8780 free_q_head
= AscAllocFreeQueue(iop_base
, free_q_head
);
8781 if (free_q_head
== ASC_QLINK_END
)
8789 * DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
8791 * Calling/Exit State:
8795 * Output an ASC_SCSI_Q structure to the chip
8798 DvcPutScsiQ(PortAddr iop_base
, ushort s_addr
, uchar
*outbuf
, int words
)
8802 ASC_DBG_PRT_HEX(2, "DvcPutScsiQ", outbuf
, 2 * words
);
8803 AscSetChipLramAddr(iop_base
, s_addr
);
8804 for (i
= 0; i
< 2 * words
; i
+= 2) {
8805 if (i
== 4 || i
== 20) {
8808 outpw(iop_base
+ IOP_RAM_DATA
,
8809 ((ushort
)outbuf
[i
+ 1] << 8) | outbuf
[i
]);
8813 static int AscPutReadyQueue(ASC_DVC_VAR
*asc_dvc
, ASC_SCSI_Q
*scsiq
, uchar q_no
)
8818 uchar syn_period_ix
;
8822 iop_base
= asc_dvc
->iop_base
;
8823 if (((asc_dvc
->init_sdtr
& scsiq
->q1
.target_id
) != 0) &&
8824 ((asc_dvc
->sdtr_done
& scsiq
->q1
.target_id
) == 0)) {
8825 tid_no
= ASC_TIX_TO_TID(scsiq
->q2
.target_ix
);
8826 sdtr_data
= AscGetMCodeInitSDTRAtID(iop_base
, tid_no
);
8828 (sdtr_data
>> 4) & (asc_dvc
->max_sdtr_index
- 1);
8829 syn_offset
= sdtr_data
& ASC_SYN_MAX_OFFSET
;
8830 AscMsgOutSDTR(asc_dvc
,
8831 asc_dvc
->sdtr_period_tbl
[syn_period_ix
],
8833 scsiq
->q1
.cntl
|= QC_MSG_OUT
;
8835 q_addr
= ASC_QNO_TO_QADDR(q_no
);
8836 if ((scsiq
->q1
.target_id
& asc_dvc
->use_tagged_qng
) == 0) {
8837 scsiq
->q2
.tag_code
&= ~MSG_SIMPLE_TAG
;
8839 scsiq
->q1
.status
= QS_FREE
;
8840 AscMemWordCopyPtrToLram(iop_base
,
8841 q_addr
+ ASC_SCSIQ_CDB_BEG
,
8842 (uchar
*)scsiq
->cdbptr
, scsiq
->q2
.cdb_len
>> 1);
8844 DvcPutScsiQ(iop_base
,
8845 q_addr
+ ASC_SCSIQ_CPY_BEG
,
8846 (uchar
*)&scsiq
->q1
.cntl
,
8847 ((sizeof(ASC_SCSIQ_1
) + sizeof(ASC_SCSIQ_2
)) / 2) - 1);
8848 AscWriteLramWord(iop_base
,
8849 (ushort
)(q_addr
+ (ushort
)ASC_SCSIQ_B_STATUS
),
8850 (ushort
)(((ushort
)scsiq
->q1
.
8851 q_no
<< 8) | (ushort
)QS_READY
));
8856 AscPutReadySgListQueue(ASC_DVC_VAR
*asc_dvc
, ASC_SCSI_Q
*scsiq
, uchar q_no
)
8860 ASC_SG_HEAD
*sg_head
;
8861 ASC_SG_LIST_Q scsi_sg_q
;
8862 ASC_DCNT saved_data_addr
;
8863 ASC_DCNT saved_data_cnt
;
8865 ushort sg_list_dwords
;
8867 ushort sg_entry_cnt
;
8871 iop_base
= asc_dvc
->iop_base
;
8872 sg_head
= scsiq
->sg_head
;
8873 saved_data_addr
= scsiq
->q1
.data_addr
;
8874 saved_data_cnt
= scsiq
->q1
.data_cnt
;
8875 scsiq
->q1
.data_addr
= (ASC_PADDR
) sg_head
->sg_list
[0].addr
;
8876 scsiq
->q1
.data_cnt
= (ASC_DCNT
) sg_head
->sg_list
[0].bytes
;
8877 #if CC_VERY_LONG_SG_LIST
8879 * If sg_head->entry_cnt is greater than ASC_MAX_SG_LIST
8880 * then not all SG elements will fit in the allocated queues.
8881 * The rest of the SG elements will be copied when the RISC
8882 * completes the SG elements that fit and halts.
8884 if (sg_head
->entry_cnt
> ASC_MAX_SG_LIST
) {
8886 * Set sg_entry_cnt to be the number of SG elements that
8887 * will fit in the allocated SG queues. It is minus 1, because
8888 * the first SG element is handled above. ASC_MAX_SG_LIST is
8889 * already inflated by 1 to account for this. For example it
8890 * may be 50 which is 1 + 7 queues * 7 SG elements.
8892 sg_entry_cnt
= ASC_MAX_SG_LIST
- 1;
8895 * Keep track of remaining number of SG elements that will
8896 * need to be handled from a_isr.c.
8898 scsiq
->remain_sg_entry_cnt
=
8899 sg_head
->entry_cnt
- ASC_MAX_SG_LIST
;
8901 #endif /* CC_VERY_LONG_SG_LIST */
8903 * Set sg_entry_cnt to be the number of SG elements that
8904 * will fit in the allocated SG queues. It is minus 1, because
8905 * the first SG element is handled above.
8907 sg_entry_cnt
= sg_head
->entry_cnt
- 1;
8908 #if CC_VERY_LONG_SG_LIST
8910 #endif /* CC_VERY_LONG_SG_LIST */
8911 if (sg_entry_cnt
!= 0) {
8912 scsiq
->q1
.cntl
|= QC_SG_HEAD
;
8913 q_addr
= ASC_QNO_TO_QADDR(q_no
);
8915 scsiq
->q1
.sg_queue_cnt
= sg_head
->queue_cnt
;
8916 scsi_sg_q
.sg_head_qp
= q_no
;
8917 scsi_sg_q
.cntl
= QCSG_SG_XFER_LIST
;
8918 for (i
= 0; i
< sg_head
->queue_cnt
; i
++) {
8919 scsi_sg_q
.seq_no
= i
+ 1;
8920 if (sg_entry_cnt
> ASC_SG_LIST_PER_Q
) {
8921 sg_list_dwords
= (uchar
)(ASC_SG_LIST_PER_Q
* 2);
8922 sg_entry_cnt
-= ASC_SG_LIST_PER_Q
;
8924 scsi_sg_q
.sg_list_cnt
=
8926 scsi_sg_q
.sg_cur_list_cnt
=
8929 scsi_sg_q
.sg_list_cnt
=
8930 ASC_SG_LIST_PER_Q
- 1;
8931 scsi_sg_q
.sg_cur_list_cnt
=
8932 ASC_SG_LIST_PER_Q
- 1;
8935 #if CC_VERY_LONG_SG_LIST
8937 * This is the last SG queue in the list of
8938 * allocated SG queues. If there are more
8939 * SG elements than will fit in the allocated
8940 * queues, then set the QCSG_SG_XFER_MORE flag.
8942 if (sg_head
->entry_cnt
> ASC_MAX_SG_LIST
) {
8943 scsi_sg_q
.cntl
|= QCSG_SG_XFER_MORE
;
8945 #endif /* CC_VERY_LONG_SG_LIST */
8946 scsi_sg_q
.cntl
|= QCSG_SG_XFER_END
;
8947 #if CC_VERY_LONG_SG_LIST
8949 #endif /* CC_VERY_LONG_SG_LIST */
8950 sg_list_dwords
= sg_entry_cnt
<< 1;
8952 scsi_sg_q
.sg_list_cnt
= sg_entry_cnt
;
8953 scsi_sg_q
.sg_cur_list_cnt
=
8956 scsi_sg_q
.sg_list_cnt
=
8958 scsi_sg_q
.sg_cur_list_cnt
=
8963 next_qp
= AscReadLramByte(iop_base
,
8966 scsi_sg_q
.q_no
= next_qp
;
8967 q_addr
= ASC_QNO_TO_QADDR(next_qp
);
8968 AscMemWordCopyPtrToLram(iop_base
,
8969 q_addr
+ ASC_SCSIQ_SGHD_CPY_BEG
,
8970 (uchar
*)&scsi_sg_q
,
8971 sizeof(ASC_SG_LIST_Q
) >> 1);
8972 AscMemDWordCopyPtrToLram(iop_base
,
8973 q_addr
+ ASC_SGQ_LIST_BEG
,
8977 sg_index
+= ASC_SG_LIST_PER_Q
;
8978 scsiq
->next_sg_index
= sg_index
;
8981 scsiq
->q1
.cntl
&= ~QC_SG_HEAD
;
8983 sta
= AscPutReadyQueue(asc_dvc
, scsiq
, q_no
);
8984 scsiq
->q1
.data_addr
= saved_data_addr
;
8985 scsiq
->q1
.data_cnt
= saved_data_cnt
;
8990 AscSendScsiQueue(ASC_DVC_VAR
*asc_dvc
, ASC_SCSI_Q
*scsiq
, uchar n_q_required
)
8999 iop_base
= asc_dvc
->iop_base
;
9000 target_ix
= scsiq
->q2
.target_ix
;
9001 tid_no
= ASC_TIX_TO_TID(target_ix
);
9003 free_q_head
= (uchar
)AscGetVarFreeQHead(iop_base
);
9004 if (n_q_required
> 1) {
9005 next_qp
= AscAllocMultipleFreeQueue(iop_base
, free_q_head
,
9006 (uchar
)n_q_required
);
9007 if (next_qp
!= ASC_QLINK_END
) {
9008 asc_dvc
->last_q_shortage
= 0;
9009 scsiq
->sg_head
->queue_cnt
= n_q_required
- 1;
9010 scsiq
->q1
.q_no
= free_q_head
;
9011 sta
= AscPutReadySgListQueue(asc_dvc
, scsiq
,
9014 } else if (n_q_required
== 1) {
9015 next_qp
= AscAllocFreeQueue(iop_base
, free_q_head
);
9016 if (next_qp
!= ASC_QLINK_END
) {
9017 scsiq
->q1
.q_no
= free_q_head
;
9018 sta
= AscPutReadyQueue(asc_dvc
, scsiq
, free_q_head
);
9022 AscPutVarFreeQHead(iop_base
, next_qp
);
9023 asc_dvc
->cur_total_qng
+= n_q_required
;
9024 asc_dvc
->cur_dvc_qng
[tid_no
]++;
9029 #define ASC_SYN_OFFSET_ONE_DISABLE_LIST 16
9030 static uchar _syn_offset_one_disable_cmd
[ASC_SYN_OFFSET_ONE_DISABLE_LIST
] = {
9049 static int AscExeScsiQueue(ASC_DVC_VAR
*asc_dvc
, ASC_SCSI_Q
*scsiq
)
9054 int disable_syn_offset_one_fix
;
9057 ushort sg_entry_cnt
= 0;
9058 ushort sg_entry_cnt_minus_one
= 0;
9065 ASC_SG_HEAD
*sg_head
;
9068 iop_base
= asc_dvc
->iop_base
;
9069 sg_head
= scsiq
->sg_head
;
9070 if (asc_dvc
->err_code
!= 0)
9073 if ((scsiq
->q2
.tag_code
& ASC_TAG_FLAG_EXTRA_BYTES
) == 0) {
9074 scsiq
->q1
.extra_bytes
= 0;
9077 target_ix
= scsiq
->q2
.target_ix
;
9078 tid_no
= ASC_TIX_TO_TID(target_ix
);
9080 if (scsiq
->cdbptr
[0] == REQUEST_SENSE
) {
9081 if ((asc_dvc
->init_sdtr
& scsiq
->q1
.target_id
) != 0) {
9082 asc_dvc
->sdtr_done
&= ~scsiq
->q1
.target_id
;
9083 sdtr_data
= AscGetMCodeInitSDTRAtID(iop_base
, tid_no
);
9084 AscMsgOutSDTR(asc_dvc
,
9086 sdtr_period_tbl
[(sdtr_data
>> 4) &
9090 (uchar
)(sdtr_data
& (uchar
)
9091 ASC_SYN_MAX_OFFSET
));
9092 scsiq
->q1
.cntl
|= (QC_MSG_OUT
| QC_URGENT
);
9095 if (asc_dvc
->in_critical_cnt
!= 0) {
9096 AscSetLibErrorCode(asc_dvc
, ASCQ_ERR_CRITICAL_RE_ENTRY
);
9099 asc_dvc
->in_critical_cnt
++;
9100 if ((scsiq
->q1
.cntl
& QC_SG_HEAD
) != 0) {
9101 if ((sg_entry_cnt
= sg_head
->entry_cnt
) == 0) {
9102 asc_dvc
->in_critical_cnt
--;
9105 #if !CC_VERY_LONG_SG_LIST
9106 if (sg_entry_cnt
> ASC_MAX_SG_LIST
) {
9107 asc_dvc
->in_critical_cnt
--;
9110 #endif /* !CC_VERY_LONG_SG_LIST */
9111 if (sg_entry_cnt
== 1) {
9112 scsiq
->q1
.data_addr
=
9113 (ADV_PADDR
)sg_head
->sg_list
[0].addr
;
9114 scsiq
->q1
.data_cnt
=
9115 (ADV_DCNT
)sg_head
->sg_list
[0].bytes
;
9116 scsiq
->q1
.cntl
&= ~(QC_SG_HEAD
| QC_SG_SWAP_QUEUE
);
9118 sg_entry_cnt_minus_one
= sg_entry_cnt
- 1;
9120 scsi_cmd
= scsiq
->cdbptr
[0];
9121 disable_syn_offset_one_fix
= FALSE
;
9122 if ((asc_dvc
->pci_fix_asyn_xfer
& scsiq
->q1
.target_id
) &&
9123 !(asc_dvc
->pci_fix_asyn_xfer_always
& scsiq
->q1
.target_id
)) {
9124 if (scsiq
->q1
.cntl
& QC_SG_HEAD
) {
9126 for (i
= 0; i
< sg_entry_cnt
; i
++) {
9128 (ADV_DCNT
)le32_to_cpu(sg_head
->sg_list
[i
].
9132 data_cnt
= le32_to_cpu(scsiq
->q1
.data_cnt
);
9134 if (data_cnt
!= 0UL) {
9135 if (data_cnt
< 512UL) {
9136 disable_syn_offset_one_fix
= TRUE
;
9138 for (i
= 0; i
< ASC_SYN_OFFSET_ONE_DISABLE_LIST
;
9141 _syn_offset_one_disable_cmd
[i
];
9142 if (disable_cmd
== 0xFF) {
9145 if (scsi_cmd
== disable_cmd
) {
9146 disable_syn_offset_one_fix
=
9154 if (disable_syn_offset_one_fix
) {
9155 scsiq
->q2
.tag_code
&= ~MSG_SIMPLE_TAG
;
9156 scsiq
->q2
.tag_code
|= (ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX
|
9157 ASC_TAG_FLAG_DISABLE_DISCONNECT
);
9159 scsiq
->q2
.tag_code
&= 0x27;
9161 if ((scsiq
->q1
.cntl
& QC_SG_HEAD
) != 0) {
9162 if (asc_dvc
->bug_fix_cntl
) {
9163 if (asc_dvc
->bug_fix_cntl
& ASC_BUG_FIX_IF_NOT_DWB
) {
9164 if ((scsi_cmd
== READ_6
) ||
9165 (scsi_cmd
== READ_10
)) {
9167 (ADV_PADDR
)le32_to_cpu(sg_head
->
9169 [sg_entry_cnt_minus_one
].
9171 (ADV_DCNT
)le32_to_cpu(sg_head
->
9173 [sg_entry_cnt_minus_one
].
9176 (uchar
)((ushort
)addr
& 0x0003);
9177 if ((extra_bytes
!= 0)
9181 ASC_TAG_FLAG_EXTRA_BYTES
)
9183 scsiq
->q2
.tag_code
|=
9184 ASC_TAG_FLAG_EXTRA_BYTES
;
9185 scsiq
->q1
.extra_bytes
=
9188 le32_to_cpu(sg_head
->
9190 [sg_entry_cnt_minus_one
].
9193 (ASC_DCNT
) extra_bytes
;
9196 [sg_entry_cnt_minus_one
].
9198 cpu_to_le32(data_cnt
);
9203 sg_head
->entry_to_copy
= sg_head
->entry_cnt
;
9204 #if CC_VERY_LONG_SG_LIST
9206 * Set the sg_entry_cnt to the maximum possible. The rest of
9207 * the SG elements will be copied when the RISC completes the
9208 * SG elements that fit and halts.
9210 if (sg_entry_cnt
> ASC_MAX_SG_LIST
) {
9211 sg_entry_cnt
= ASC_MAX_SG_LIST
;
9213 #endif /* CC_VERY_LONG_SG_LIST */
9214 n_q_required
= AscSgListToQueue(sg_entry_cnt
);
9215 if ((AscGetNumOfFreeQueue(asc_dvc
, target_ix
, n_q_required
) >=
9216 (uint
) n_q_required
)
9217 || ((scsiq
->q1
.cntl
& QC_URGENT
) != 0)) {
9219 AscSendScsiQueue(asc_dvc
, scsiq
,
9220 n_q_required
)) == 1) {
9221 asc_dvc
->in_critical_cnt
--;
9226 if (asc_dvc
->bug_fix_cntl
) {
9227 if (asc_dvc
->bug_fix_cntl
& ASC_BUG_FIX_IF_NOT_DWB
) {
9228 if ((scsi_cmd
== READ_6
) ||
9229 (scsi_cmd
== READ_10
)) {
9231 le32_to_cpu(scsiq
->q1
.data_addr
) +
9232 le32_to_cpu(scsiq
->q1
.data_cnt
);
9234 (uchar
)((ushort
)addr
& 0x0003);
9235 if ((extra_bytes
!= 0)
9239 ASC_TAG_FLAG_EXTRA_BYTES
)
9242 le32_to_cpu(scsiq
->q1
.
9244 if (((ushort
)data_cnt
& 0x01FF)
9246 scsiq
->q2
.tag_code
|=
9247 ASC_TAG_FLAG_EXTRA_BYTES
;
9248 data_cnt
-= (ASC_DCNT
)
9250 scsiq
->q1
.data_cnt
=
9253 scsiq
->q1
.extra_bytes
=
9261 if ((AscGetNumOfFreeQueue(asc_dvc
, target_ix
, 1) >= 1) ||
9262 ((scsiq
->q1
.cntl
& QC_URGENT
) != 0)) {
9263 if ((sta
= AscSendScsiQueue(asc_dvc
, scsiq
,
9264 n_q_required
)) == 1) {
9265 asc_dvc
->in_critical_cnt
--;
9270 asc_dvc
->in_critical_cnt
--;
9275 * AdvExeScsiQueue() - Send a request to the RISC microcode program.
9277 * Allocate a carrier structure, point the carrier to the ADV_SCSI_REQ_Q,
9278 * add the carrier to the ICQ (Initiator Command Queue), and tickle the
9279 * RISC to notify it a new command is ready to be executed.
9281 * If 'done_status' is not set to QD_DO_RETRY, then 'error_retry' will be
9282 * set to SCSI_MAX_RETRY.
9284 * Multi-byte fields in the ASC_SCSI_REQ_Q that are used by the microcode
9285 * for DMA addresses or math operations are byte swapped to little-endian
9289 * ADV_SUCCESS(1) - The request was successfully queued.
9290 * ADV_BUSY(0) - Resource unavailable; Retry again after pending
9291 * request completes.
9292 * ADV_ERROR(-1) - Invalid ADV_SCSI_REQ_Q request structure
9295 static int AdvExeScsiQueue(ADV_DVC_VAR
*asc_dvc
, ADV_SCSI_REQ_Q
*scsiq
)
9297 AdvPortAddr iop_base
;
9298 ADV_PADDR req_paddr
;
9299 ADV_CARR_T
*new_carrp
;
9302 * The ADV_SCSI_REQ_Q 'target_id' field should never exceed ADV_MAX_TID.
9304 if (scsiq
->target_id
> ADV_MAX_TID
) {
9305 scsiq
->host_status
= QHSTA_M_INVALID_DEVICE
;
9306 scsiq
->done_status
= QD_WITH_ERROR
;
9310 iop_base
= asc_dvc
->iop_base
;
9313 * Allocate a carrier ensuring at least one carrier always
9314 * remains on the freelist and initialize fields.
9316 if ((new_carrp
= asc_dvc
->carr_freelist
) == NULL
) {
9319 asc_dvc
->carr_freelist
= (ADV_CARR_T
*)
9320 ADV_U32_TO_VADDR(le32_to_cpu(new_carrp
->next_vpa
));
9321 asc_dvc
->carr_pending_cnt
++;
9324 * Set the carrier to be a stopper by setting 'next_vpa'
9325 * to the stopper value. The current stopper will be changed
9326 * below to point to the new stopper.
9328 new_carrp
->next_vpa
= cpu_to_le32(ASC_CQ_STOPPER
);
9331 * Clear the ADV_SCSI_REQ_Q done flag.
9333 scsiq
->a_flag
&= ~ADV_SCSIQ_DONE
;
9335 req_paddr
= virt_to_bus(scsiq
);
9336 BUG_ON(req_paddr
& 31);
9337 /* Wait for assertion before making little-endian */
9338 req_paddr
= cpu_to_le32(req_paddr
);
9340 /* Save virtual and physical address of ADV_SCSI_REQ_Q and carrier. */
9341 scsiq
->scsiq_ptr
= cpu_to_le32(ADV_VADDR_TO_U32(scsiq
));
9342 scsiq
->scsiq_rptr
= req_paddr
;
9344 scsiq
->carr_va
= cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc
->icq_sp
));
9346 * Every ADV_CARR_T.carr_pa is byte swapped to little-endian
9347 * order during initialization.
9349 scsiq
->carr_pa
= asc_dvc
->icq_sp
->carr_pa
;
9352 * Use the current stopper to send the ADV_SCSI_REQ_Q command to
9353 * the microcode. The newly allocated stopper will become the new
9356 asc_dvc
->icq_sp
->areq_vpa
= req_paddr
;
9359 * Set the 'next_vpa' pointer for the old stopper to be the
9360 * physical address of the new stopper. The RISC can only
9361 * follow physical addresses.
9363 asc_dvc
->icq_sp
->next_vpa
= new_carrp
->carr_pa
;
9366 * Set the host adapter stopper pointer to point to the new carrier.
9368 asc_dvc
->icq_sp
= new_carrp
;
9370 if (asc_dvc
->chip_type
== ADV_CHIP_ASC3550
||
9371 asc_dvc
->chip_type
== ADV_CHIP_ASC38C0800
) {
9373 * Tickle the RISC to tell it to read its Command Queue Head pointer.
9375 AdvWriteByteRegister(iop_base
, IOPB_TICKLE
, ADV_TICKLE_A
);
9376 if (asc_dvc
->chip_type
== ADV_CHIP_ASC3550
) {
9378 * Clear the tickle value. In the ASC-3550 the RISC flag
9379 * command 'clr_tickle_a' does not work unless the host
9382 AdvWriteByteRegister(iop_base
, IOPB_TICKLE
,
9385 } else if (asc_dvc
->chip_type
== ADV_CHIP_ASC38C1600
) {
9387 * Notify the RISC a carrier is ready by writing the physical
9388 * address of the new carrier stopper to the COMMA register.
9390 AdvWriteDWordRegister(iop_base
, IOPDW_COMMA
,
9391 le32_to_cpu(new_carrp
->carr_pa
));
9398 * Execute a single 'Scsi_Cmnd'.
9400 static int asc_execute_scsi_cmnd(struct scsi_cmnd
*scp
)
9403 struct asc_board
*boardp
= shost_priv(scp
->device
->host
);
9405 ASC_DBG(1, "scp 0x%p\n", scp
);
9407 if (ASC_NARROW_BOARD(boardp
)) {
9408 ASC_DVC_VAR
*asc_dvc
= &boardp
->dvc_var
.asc_dvc_var
;
9409 struct asc_scsi_q asc_scsi_q
;
9411 /* asc_build_req() can not return ASC_BUSY. */
9412 ret
= asc_build_req(boardp
, scp
, &asc_scsi_q
);
9413 if (ret
== ASC_ERROR
) {
9414 ASC_STATS(scp
->device
->host
, build_error
);
9418 ret
= AscExeScsiQueue(asc_dvc
, &asc_scsi_q
);
9419 kfree(asc_scsi_q
.sg_head
);
9420 err_code
= asc_dvc
->err_code
;
9422 ADV_DVC_VAR
*adv_dvc
= &boardp
->dvc_var
.adv_dvc_var
;
9423 ADV_SCSI_REQ_Q
*adv_scsiqp
;
9425 switch (adv_build_req(boardp
, scp
, &adv_scsiqp
)) {
9427 ASC_DBG(3, "adv_build_req ASC_NOERROR\n");
9430 ASC_DBG(1, "adv_build_req ASC_BUSY\n");
9432 * The asc_stats fields 'adv_build_noreq' and
9433 * 'adv_build_nosg' count wide board busy conditions.
9434 * They are updated in adv_build_req and
9435 * adv_get_sglist, respectively.
9440 ASC_DBG(1, "adv_build_req ASC_ERROR\n");
9441 ASC_STATS(scp
->device
->host
, build_error
);
9445 ret
= AdvExeScsiQueue(adv_dvc
, adv_scsiqp
);
9446 err_code
= adv_dvc
->err_code
;
9451 ASC_STATS(scp
->device
->host
, exe_noerror
);
9453 * Increment monotonically increasing per device
9454 * successful request counter. Wrapping doesn't matter.
9456 boardp
->reqcnt
[scp
->device
->id
]++;
9457 ASC_DBG(1, "ExeScsiQueue() ASC_NOERROR\n");
9460 ASC_STATS(scp
->device
->host
, exe_busy
);
9463 scmd_printk(KERN_ERR
, scp
, "ExeScsiQueue() ASC_ERROR, "
9464 "err_code 0x%x\n", err_code
);
9465 ASC_STATS(scp
->device
->host
, exe_error
);
9466 scp
->result
= HOST_BYTE(DID_ERROR
);
9469 scmd_printk(KERN_ERR
, scp
, "ExeScsiQueue() unknown, "
9470 "err_code 0x%x\n", err_code
);
9471 ASC_STATS(scp
->device
->host
, exe_unknown
);
9472 scp
->result
= HOST_BYTE(DID_ERROR
);
9476 ASC_DBG(1, "end\n");
9481 * advansys_queuecommand() - interrupt-driven I/O entrypoint.
9483 * This function always returns 0. Command return status is saved
9484 * in the 'scp' result field.
9487 advansys_queuecommand(struct scsi_cmnd
*scp
, void (*done
)(struct scsi_cmnd
*))
9489 struct Scsi_Host
*shost
= scp
->device
->host
;
9490 int asc_res
, result
= 0;
9492 ASC_STATS(shost
, queuecommand
);
9493 scp
->scsi_done
= done
;
9495 asc_res
= asc_execute_scsi_cmnd(scp
);
9501 result
= SCSI_MLQUEUE_HOST_BUSY
;
9512 static ushort __devinit
AscGetEisaChipCfg(PortAddr iop_base
)
9514 PortAddr eisa_cfg_iop
= (PortAddr
) ASC_GET_EISA_SLOT(iop_base
) |
9515 (PortAddr
) (ASC_EISA_CFG_IOP_MASK
);
9516 return inpw(eisa_cfg_iop
);
9520 * Return the BIOS address of the adapter at the specified
9521 * I/O port and with the specified bus type.
9523 static unsigned short __devinit
9524 AscGetChipBiosAddress(PortAddr iop_base
, unsigned short bus_type
)
9526 unsigned short cfg_lsw
;
9527 unsigned short bios_addr
;
9530 * The PCI BIOS is re-located by the motherboard BIOS. Because
9531 * of this the driver can not determine where a PCI BIOS is
9532 * loaded and executes.
9534 if (bus_type
& ASC_IS_PCI
)
9537 if ((bus_type
& ASC_IS_EISA
) != 0) {
9538 cfg_lsw
= AscGetEisaChipCfg(iop_base
);
9540 bios_addr
= ASC_BIOS_MIN_ADDR
+ cfg_lsw
* ASC_BIOS_BANK_SIZE
;
9544 cfg_lsw
= AscGetChipCfgLsw(iop_base
);
9547 * ISA PnP uses the top bit as the 32K BIOS flag
9549 if (bus_type
== ASC_IS_ISAPNP
)
9551 bios_addr
= ASC_BIOS_MIN_ADDR
+ (cfg_lsw
>> 12) * ASC_BIOS_BANK_SIZE
;
9555 static uchar __devinit
AscSetChipScsiID(PortAddr iop_base
, uchar new_host_id
)
9559 if (AscGetChipScsiID(iop_base
) == new_host_id
) {
9560 return (new_host_id
);
9562 cfg_lsw
= AscGetChipCfgLsw(iop_base
);
9564 cfg_lsw
|= (ushort
)((new_host_id
& ASC_MAX_TID
) << 8);
9565 AscSetChipCfgLsw(iop_base
, cfg_lsw
);
9566 return (AscGetChipScsiID(iop_base
));
9569 static unsigned char __devinit
AscGetChipScsiCtrl(PortAddr iop_base
)
9573 AscSetBank(iop_base
, 1);
9574 sc
= inp(iop_base
+ IOP_REG_SC
);
9575 AscSetBank(iop_base
, 0);
9579 static unsigned char __devinit
9580 AscGetChipVersion(PortAddr iop_base
, unsigned short bus_type
)
9582 if (bus_type
& ASC_IS_EISA
) {
9584 unsigned char revision
;
9585 eisa_iop
= (PortAddr
) ASC_GET_EISA_SLOT(iop_base
) |
9586 (PortAddr
) ASC_EISA_REV_IOP_MASK
;
9587 revision
= inp(eisa_iop
);
9588 return ASC_CHIP_MIN_VER_EISA
- 1 + revision
;
9590 return AscGetChipVerNo(iop_base
);
9594 static void __devinit
AscEnableIsaDma(uchar dma_channel
)
9596 if (dma_channel
< 4) {
9597 outp(0x000B, (ushort
)(0xC0 | dma_channel
));
9598 outp(0x000A, dma_channel
);
9599 } else if (dma_channel
< 8) {
9600 outp(0x00D6, (ushort
)(0xC0 | (dma_channel
- 4)));
9601 outp(0x00D4, (ushort
)(dma_channel
- 4));
9604 #endif /* CONFIG_ISA */
9606 static int AscStopQueueExe(PortAddr iop_base
)
9610 if (AscReadLramByte(iop_base
, ASCV_STOP_CODE_B
) == 0) {
9611 AscWriteLramByte(iop_base
, ASCV_STOP_CODE_B
,
9612 ASC_STOP_REQ_RISC_STOP
);
9614 if (AscReadLramByte(iop_base
, ASCV_STOP_CODE_B
) &
9615 ASC_STOP_ACK_RISC_STOP
) {
9619 } while (count
++ < 20);
9624 static ASC_DCNT __devinit
AscGetMaxDmaCount(ushort bus_type
)
9626 if (bus_type
& ASC_IS_ISA
)
9627 return ASC_MAX_ISA_DMA_COUNT
;
9628 else if (bus_type
& (ASC_IS_EISA
| ASC_IS_VL
))
9629 return ASC_MAX_VL_DMA_COUNT
;
9630 return ASC_MAX_PCI_DMA_COUNT
;
9634 static ushort __devinit
AscGetIsaDmaChannel(PortAddr iop_base
)
9638 channel
= AscGetChipCfgLsw(iop_base
) & 0x0003;
9639 if (channel
== 0x03)
9641 else if (channel
== 0x00)
9643 return (channel
+ 4);
9646 static ushort __devinit
AscSetIsaDmaChannel(PortAddr iop_base
, ushort dma_channel
)
9651 if ((dma_channel
>= 5) && (dma_channel
<= 7)) {
9652 if (dma_channel
== 7)
9655 value
= dma_channel
- 4;
9656 cfg_lsw
= AscGetChipCfgLsw(iop_base
) & 0xFFFC;
9658 AscSetChipCfgLsw(iop_base
, cfg_lsw
);
9659 return (AscGetIsaDmaChannel(iop_base
));
9664 static uchar __devinit
AscGetIsaDmaSpeed(PortAddr iop_base
)
9668 AscSetBank(iop_base
, 1);
9669 speed_value
= AscReadChipDmaSpeed(iop_base
);
9670 speed_value
&= 0x07;
9671 AscSetBank(iop_base
, 0);
9675 static uchar __devinit
AscSetIsaDmaSpeed(PortAddr iop_base
, uchar speed_value
)
9677 speed_value
&= 0x07;
9678 AscSetBank(iop_base
, 1);
9679 AscWriteChipDmaSpeed(iop_base
, speed_value
);
9680 AscSetBank(iop_base
, 0);
9681 return AscGetIsaDmaSpeed(iop_base
);
9683 #endif /* CONFIG_ISA */
9685 static ushort __devinit
AscInitAscDvcVar(ASC_DVC_VAR
*asc_dvc
)
9692 iop_base
= asc_dvc
->iop_base
;
9694 asc_dvc
->err_code
= 0;
9695 if ((asc_dvc
->bus_type
&
9696 (ASC_IS_ISA
| ASC_IS_PCI
| ASC_IS_EISA
| ASC_IS_VL
)) == 0) {
9697 asc_dvc
->err_code
|= ASC_IERR_NO_BUS_TYPE
;
9699 AscSetChipControl(iop_base
, CC_HALT
);
9700 AscSetChipStatus(iop_base
, 0);
9701 asc_dvc
->bug_fix_cntl
= 0;
9702 asc_dvc
->pci_fix_asyn_xfer
= 0;
9703 asc_dvc
->pci_fix_asyn_xfer_always
= 0;
9704 /* asc_dvc->init_state initalized in AscInitGetConfig(). */
9705 asc_dvc
->sdtr_done
= 0;
9706 asc_dvc
->cur_total_qng
= 0;
9707 asc_dvc
->is_in_int
= 0;
9708 asc_dvc
->in_critical_cnt
= 0;
9709 asc_dvc
->last_q_shortage
= 0;
9710 asc_dvc
->use_tagged_qng
= 0;
9711 asc_dvc
->no_scam
= 0;
9712 asc_dvc
->unit_not_ready
= 0;
9713 asc_dvc
->queue_full_or_busy
= 0;
9714 asc_dvc
->redo_scam
= 0;
9716 asc_dvc
->min_sdtr_index
= 0;
9717 asc_dvc
->cfg
->can_tagged_qng
= 0;
9718 asc_dvc
->cfg
->cmd_qng_enabled
= 0;
9719 asc_dvc
->dvc_cntl
= ASC_DEF_DVC_CNTL
;
9720 asc_dvc
->init_sdtr
= 0;
9721 asc_dvc
->max_total_qng
= ASC_DEF_MAX_TOTAL_QNG
;
9722 asc_dvc
->scsi_reset_wait
= 3;
9723 asc_dvc
->start_motor
= ASC_SCSI_WIDTH_BIT_SET
;
9724 asc_dvc
->max_dma_count
= AscGetMaxDmaCount(asc_dvc
->bus_type
);
9725 asc_dvc
->cfg
->sdtr_enable
= ASC_SCSI_WIDTH_BIT_SET
;
9726 asc_dvc
->cfg
->disc_enable
= ASC_SCSI_WIDTH_BIT_SET
;
9727 asc_dvc
->cfg
->chip_scsi_id
= ASC_DEF_CHIP_SCSI_ID
;
9728 chip_version
= AscGetChipVersion(iop_base
, asc_dvc
->bus_type
);
9729 asc_dvc
->cfg
->chip_version
= chip_version
;
9730 asc_dvc
->sdtr_period_tbl
= asc_syn_xfer_period
;
9731 asc_dvc
->max_sdtr_index
= 7;
9732 if ((asc_dvc
->bus_type
& ASC_IS_PCI
) &&
9733 (chip_version
>= ASC_CHIP_VER_PCI_ULTRA_3150
)) {
9734 asc_dvc
->bus_type
= ASC_IS_PCI_ULTRA
;
9735 asc_dvc
->sdtr_period_tbl
= asc_syn_ultra_xfer_period
;
9736 asc_dvc
->max_sdtr_index
= 15;
9737 if (chip_version
== ASC_CHIP_VER_PCI_ULTRA_3150
) {
9738 AscSetExtraControl(iop_base
,
9739 (SEC_ACTIVE_NEGATE
| SEC_SLEW_RATE
));
9740 } else if (chip_version
>= ASC_CHIP_VER_PCI_ULTRA_3050
) {
9741 AscSetExtraControl(iop_base
,
9742 (SEC_ACTIVE_NEGATE
|
9743 SEC_ENABLE_FILTER
));
9746 if (asc_dvc
->bus_type
== ASC_IS_PCI
) {
9747 AscSetExtraControl(iop_base
,
9748 (SEC_ACTIVE_NEGATE
| SEC_SLEW_RATE
));
9751 asc_dvc
->cfg
->isa_dma_speed
= ASC_DEF_ISA_DMA_SPEED
;
9753 if ((asc_dvc
->bus_type
& ASC_IS_ISA
) != 0) {
9754 if (chip_version
>= ASC_CHIP_MIN_VER_ISA_PNP
) {
9755 AscSetChipIFC(iop_base
, IFC_INIT_DEFAULT
);
9756 asc_dvc
->bus_type
= ASC_IS_ISAPNP
;
9758 asc_dvc
->cfg
->isa_dma_channel
=
9759 (uchar
)AscGetIsaDmaChannel(iop_base
);
9761 #endif /* CONFIG_ISA */
9762 for (i
= 0; i
<= ASC_MAX_TID
; i
++) {
9763 asc_dvc
->cur_dvc_qng
[i
] = 0;
9764 asc_dvc
->max_dvc_qng
[i
] = ASC_MAX_SCSI1_QNG
;
9765 asc_dvc
->scsiq_busy_head
[i
] = (ASC_SCSI_Q
*)0L;
9766 asc_dvc
->scsiq_busy_tail
[i
] = (ASC_SCSI_Q
*)0L;
9767 asc_dvc
->cfg
->max_tag_qng
[i
] = ASC_MAX_INRAM_TAG_QNG
;
9772 static int __devinit
AscWriteEEPCmdReg(PortAddr iop_base
, uchar cmd_reg
)
9776 for (retry
= 0; retry
< ASC_EEP_MAX_RETRY
; retry
++) {
9777 unsigned char read_back
;
9778 AscSetChipEEPCmd(iop_base
, cmd_reg
);
9780 read_back
= AscGetChipEEPCmd(iop_base
);
9781 if (read_back
== cmd_reg
)
9787 static void __devinit
AscWaitEEPRead(void)
9792 static ushort __devinit
AscReadEEPWord(PortAddr iop_base
, uchar addr
)
9797 AscWriteEEPCmdReg(iop_base
, ASC_EEP_CMD_WRITE_DISABLE
);
9799 cmd_reg
= addr
| ASC_EEP_CMD_READ
;
9800 AscWriteEEPCmdReg(iop_base
, cmd_reg
);
9802 read_wval
= AscGetChipEEPData(iop_base
);
9807 static ushort __devinit
9808 AscGetEEPConfig(PortAddr iop_base
, ASCEEP_CONFIG
*cfg_buf
, ushort bus_type
)
9815 int uchar_end_in_config
= ASC_EEP_MAX_DVC_ADDR
- 2;
9818 wbuf
= (ushort
*)cfg_buf
;
9820 /* Read two config words; Byte-swapping done by AscReadEEPWord(). */
9821 for (s_addr
= 0; s_addr
< 2; s_addr
++, wbuf
++) {
9822 *wbuf
= AscReadEEPWord(iop_base
, (uchar
)s_addr
);
9825 if (bus_type
& ASC_IS_VL
) {
9826 cfg_beg
= ASC_EEP_DVC_CFG_BEG_VL
;
9827 cfg_end
= ASC_EEP_MAX_DVC_ADDR_VL
;
9829 cfg_beg
= ASC_EEP_DVC_CFG_BEG
;
9830 cfg_end
= ASC_EEP_MAX_DVC_ADDR
;
9832 for (s_addr
= cfg_beg
; s_addr
<= (cfg_end
- 1); s_addr
++, wbuf
++) {
9833 wval
= AscReadEEPWord(iop_base
, (uchar
)s_addr
);
9834 if (s_addr
<= uchar_end_in_config
) {
9836 * Swap all char fields - must unswap bytes already swapped
9837 * by AscReadEEPWord().
9839 *wbuf
= le16_to_cpu(wval
);
9841 /* Don't swap word field at the end - cntl field. */
9844 sum
+= wval
; /* Checksum treats all EEPROM data as words. */
9847 * Read the checksum word which will be compared against 'sum'
9848 * by the caller. Word field already swapped.
9850 *wbuf
= AscReadEEPWord(iop_base
, (uchar
)s_addr
);
9854 static int __devinit
AscTestExternalLram(ASC_DVC_VAR
*asc_dvc
)
9861 iop_base
= asc_dvc
->iop_base
;
9863 q_addr
= ASC_QNO_TO_QADDR(241);
9864 saved_word
= AscReadLramWord(iop_base
, q_addr
);
9865 AscSetChipLramAddr(iop_base
, q_addr
);
9866 AscSetChipLramData(iop_base
, 0x55AA);
9868 AscSetChipLramAddr(iop_base
, q_addr
);
9869 if (AscGetChipLramData(iop_base
) == 0x55AA) {
9871 AscWriteLramWord(iop_base
, q_addr
, saved_word
);
9876 static void __devinit
AscWaitEEPWrite(void)
9881 static int __devinit
AscWriteEEPDataReg(PortAddr iop_base
, ushort data_reg
)
9888 AscSetChipEEPData(iop_base
, data_reg
);
9890 read_back
= AscGetChipEEPData(iop_base
);
9891 if (read_back
== data_reg
) {
9894 if (retry
++ > ASC_EEP_MAX_RETRY
) {
9900 static ushort __devinit
9901 AscWriteEEPWord(PortAddr iop_base
, uchar addr
, ushort word_val
)
9905 read_wval
= AscReadEEPWord(iop_base
, addr
);
9906 if (read_wval
!= word_val
) {
9907 AscWriteEEPCmdReg(iop_base
, ASC_EEP_CMD_WRITE_ABLE
);
9909 AscWriteEEPDataReg(iop_base
, word_val
);
9911 AscWriteEEPCmdReg(iop_base
,
9912 (uchar
)((uchar
)ASC_EEP_CMD_WRITE
| addr
));
9914 AscWriteEEPCmdReg(iop_base
, ASC_EEP_CMD_WRITE_DISABLE
);
9916 return (AscReadEEPWord(iop_base
, addr
));
9921 static int __devinit
9922 AscSetEEPConfigOnce(PortAddr iop_base
, ASCEEP_CONFIG
*cfg_buf
, ushort bus_type
)
9931 int uchar_end_in_config
= ASC_EEP_MAX_DVC_ADDR
- 2;
9933 wbuf
= (ushort
*)cfg_buf
;
9936 /* Write two config words; AscWriteEEPWord() will swap bytes. */
9937 for (s_addr
= 0; s_addr
< 2; s_addr
++, wbuf
++) {
9939 if (*wbuf
!= AscWriteEEPWord(iop_base
, (uchar
)s_addr
, *wbuf
)) {
9943 if (bus_type
& ASC_IS_VL
) {
9944 cfg_beg
= ASC_EEP_DVC_CFG_BEG_VL
;
9945 cfg_end
= ASC_EEP_MAX_DVC_ADDR_VL
;
9947 cfg_beg
= ASC_EEP_DVC_CFG_BEG
;
9948 cfg_end
= ASC_EEP_MAX_DVC_ADDR
;
9950 for (s_addr
= cfg_beg
; s_addr
<= (cfg_end
- 1); s_addr
++, wbuf
++) {
9951 if (s_addr
<= uchar_end_in_config
) {
9953 * This is a char field. Swap char fields before they are
9954 * swapped again by AscWriteEEPWord().
9956 word
= cpu_to_le16(*wbuf
);
9958 AscWriteEEPWord(iop_base
, (uchar
)s_addr
, word
)) {
9962 /* Don't swap word field at the end - cntl field. */
9964 AscWriteEEPWord(iop_base
, (uchar
)s_addr
, *wbuf
)) {
9968 sum
+= *wbuf
; /* Checksum calculated from word values. */
9970 /* Write checksum word. It will be swapped by AscWriteEEPWord(). */
9972 if (sum
!= AscWriteEEPWord(iop_base
, (uchar
)s_addr
, sum
)) {
9976 /* Read EEPROM back again. */
9977 wbuf
= (ushort
*)cfg_buf
;
9979 * Read two config words; Byte-swapping done by AscReadEEPWord().
9981 for (s_addr
= 0; s_addr
< 2; s_addr
++, wbuf
++) {
9982 if (*wbuf
!= AscReadEEPWord(iop_base
, (uchar
)s_addr
)) {
9986 if (bus_type
& ASC_IS_VL
) {
9987 cfg_beg
= ASC_EEP_DVC_CFG_BEG_VL
;
9988 cfg_end
= ASC_EEP_MAX_DVC_ADDR_VL
;
9990 cfg_beg
= ASC_EEP_DVC_CFG_BEG
;
9991 cfg_end
= ASC_EEP_MAX_DVC_ADDR
;
9993 for (s_addr
= cfg_beg
; s_addr
<= (cfg_end
- 1); s_addr
++, wbuf
++) {
9994 if (s_addr
<= uchar_end_in_config
) {
9996 * Swap all char fields. Must unswap bytes already swapped
9997 * by AscReadEEPWord().
10000 le16_to_cpu(AscReadEEPWord
10001 (iop_base
, (uchar
)s_addr
));
10003 /* Don't swap word field at the end - cntl field. */
10004 word
= AscReadEEPWord(iop_base
, (uchar
)s_addr
);
10006 if (*wbuf
!= word
) {
10010 /* Read checksum; Byte swapping not needed. */
10011 if (AscReadEEPWord(iop_base
, (uchar
)s_addr
) != sum
) {
10017 static int __devinit
10018 AscSetEEPConfig(PortAddr iop_base
, ASCEEP_CONFIG
*cfg_buf
, ushort bus_type
)
10025 if ((n_error
= AscSetEEPConfigOnce(iop_base
, cfg_buf
,
10029 if (++retry
> ASC_EEP_MAX_RETRY
) {
10036 static ushort __devinit
AscInitFromEEP(ASC_DVC_VAR
*asc_dvc
)
10038 ASCEEP_CONFIG eep_config_buf
;
10039 ASCEEP_CONFIG
*eep_config
;
10043 ushort cfg_msw
, cfg_lsw
;
10047 iop_base
= asc_dvc
->iop_base
;
10049 AscWriteLramWord(iop_base
, ASCV_HALTCODE_W
, 0x00FE);
10050 AscStopQueueExe(iop_base
);
10051 if ((AscStopChip(iop_base
) == FALSE
) ||
10052 (AscGetChipScsiCtrl(iop_base
) != 0)) {
10053 asc_dvc
->init_state
|= ASC_INIT_RESET_SCSI_DONE
;
10054 AscResetChipAndScsiBus(asc_dvc
);
10055 mdelay(asc_dvc
->scsi_reset_wait
* 1000); /* XXX: msleep? */
10057 if (AscIsChipHalted(iop_base
) == FALSE
) {
10058 asc_dvc
->err_code
|= ASC_IERR_START_STOP_CHIP
;
10059 return (warn_code
);
10061 AscSetPCAddr(iop_base
, ASC_MCODE_START_ADDR
);
10062 if (AscGetPCAddr(iop_base
) != ASC_MCODE_START_ADDR
) {
10063 asc_dvc
->err_code
|= ASC_IERR_SET_PC_ADDR
;
10064 return (warn_code
);
10066 eep_config
= (ASCEEP_CONFIG
*)&eep_config_buf
;
10067 cfg_msw
= AscGetChipCfgMsw(iop_base
);
10068 cfg_lsw
= AscGetChipCfgLsw(iop_base
);
10069 if ((cfg_msw
& ASC_CFG_MSW_CLR_MASK
) != 0) {
10070 cfg_msw
&= ~ASC_CFG_MSW_CLR_MASK
;
10071 warn_code
|= ASC_WARN_CFG_MSW_RECOVER
;
10072 AscSetChipCfgMsw(iop_base
, cfg_msw
);
10074 chksum
= AscGetEEPConfig(iop_base
, eep_config
, asc_dvc
->bus_type
);
10075 ASC_DBG(1, "chksum 0x%x\n", chksum
);
10079 if (AscGetChipStatus(iop_base
) & CSW_AUTO_CONFIG
) {
10080 warn_code
|= ASC_WARN_AUTO_CONFIG
;
10081 if (asc_dvc
->cfg
->chip_version
== 3) {
10082 if (eep_config
->cfg_lsw
!= cfg_lsw
) {
10083 warn_code
|= ASC_WARN_EEPROM_RECOVER
;
10084 eep_config
->cfg_lsw
=
10085 AscGetChipCfgLsw(iop_base
);
10087 if (eep_config
->cfg_msw
!= cfg_msw
) {
10088 warn_code
|= ASC_WARN_EEPROM_RECOVER
;
10089 eep_config
->cfg_msw
=
10090 AscGetChipCfgMsw(iop_base
);
10094 eep_config
->cfg_msw
&= ~ASC_CFG_MSW_CLR_MASK
;
10095 eep_config
->cfg_lsw
|= ASC_CFG0_HOST_INT_ON
;
10096 ASC_DBG(1, "eep_config->chksum 0x%x\n", eep_config
->chksum
);
10097 if (chksum
!= eep_config
->chksum
) {
10098 if (AscGetChipVersion(iop_base
, asc_dvc
->bus_type
) ==
10099 ASC_CHIP_VER_PCI_ULTRA_3050
) {
10100 ASC_DBG(1, "chksum error ignored; EEPROM-less board\n");
10101 eep_config
->init_sdtr
= 0xFF;
10102 eep_config
->disc_enable
= 0xFF;
10103 eep_config
->start_motor
= 0xFF;
10104 eep_config
->use_cmd_qng
= 0;
10105 eep_config
->max_total_qng
= 0xF0;
10106 eep_config
->max_tag_qng
= 0x20;
10107 eep_config
->cntl
= 0xBFFF;
10108 ASC_EEP_SET_CHIP_ID(eep_config
, 7);
10109 eep_config
->no_scam
= 0;
10110 eep_config
->adapter_info
[0] = 0;
10111 eep_config
->adapter_info
[1] = 0;
10112 eep_config
->adapter_info
[2] = 0;
10113 eep_config
->adapter_info
[3] = 0;
10114 eep_config
->adapter_info
[4] = 0;
10115 /* Indicate EEPROM-less board. */
10116 eep_config
->adapter_info
[5] = 0xBB;
10119 ("AscInitFromEEP: EEPROM checksum error; Will try to re-write EEPROM.\n");
10121 warn_code
|= ASC_WARN_EEPROM_CHKSUM
;
10124 asc_dvc
->cfg
->sdtr_enable
= eep_config
->init_sdtr
;
10125 asc_dvc
->cfg
->disc_enable
= eep_config
->disc_enable
;
10126 asc_dvc
->cfg
->cmd_qng_enabled
= eep_config
->use_cmd_qng
;
10127 asc_dvc
->cfg
->isa_dma_speed
= ASC_EEP_GET_DMA_SPD(eep_config
);
10128 asc_dvc
->start_motor
= eep_config
->start_motor
;
10129 asc_dvc
->dvc_cntl
= eep_config
->cntl
;
10130 asc_dvc
->no_scam
= eep_config
->no_scam
;
10131 asc_dvc
->cfg
->adapter_info
[0] = eep_config
->adapter_info
[0];
10132 asc_dvc
->cfg
->adapter_info
[1] = eep_config
->adapter_info
[1];
10133 asc_dvc
->cfg
->adapter_info
[2] = eep_config
->adapter_info
[2];
10134 asc_dvc
->cfg
->adapter_info
[3] = eep_config
->adapter_info
[3];
10135 asc_dvc
->cfg
->adapter_info
[4] = eep_config
->adapter_info
[4];
10136 asc_dvc
->cfg
->adapter_info
[5] = eep_config
->adapter_info
[5];
10137 if (!AscTestExternalLram(asc_dvc
)) {
10138 if (((asc_dvc
->bus_type
& ASC_IS_PCI_ULTRA
) ==
10139 ASC_IS_PCI_ULTRA
)) {
10140 eep_config
->max_total_qng
=
10141 ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG
;
10142 eep_config
->max_tag_qng
=
10143 ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG
;
10145 eep_config
->cfg_msw
|= 0x0800;
10147 AscSetChipCfgMsw(iop_base
, cfg_msw
);
10148 eep_config
->max_total_qng
= ASC_MAX_PCI_INRAM_TOTAL_QNG
;
10149 eep_config
->max_tag_qng
= ASC_MAX_INRAM_TAG_QNG
;
10153 if (eep_config
->max_total_qng
< ASC_MIN_TOTAL_QNG
) {
10154 eep_config
->max_total_qng
= ASC_MIN_TOTAL_QNG
;
10156 if (eep_config
->max_total_qng
> ASC_MAX_TOTAL_QNG
) {
10157 eep_config
->max_total_qng
= ASC_MAX_TOTAL_QNG
;
10159 if (eep_config
->max_tag_qng
> eep_config
->max_total_qng
) {
10160 eep_config
->max_tag_qng
= eep_config
->max_total_qng
;
10162 if (eep_config
->max_tag_qng
< ASC_MIN_TAG_Q_PER_DVC
) {
10163 eep_config
->max_tag_qng
= ASC_MIN_TAG_Q_PER_DVC
;
10165 asc_dvc
->max_total_qng
= eep_config
->max_total_qng
;
10166 if ((eep_config
->use_cmd_qng
& eep_config
->disc_enable
) !=
10167 eep_config
->use_cmd_qng
) {
10168 eep_config
->disc_enable
= eep_config
->use_cmd_qng
;
10169 warn_code
|= ASC_WARN_CMD_QNG_CONFLICT
;
10171 ASC_EEP_SET_CHIP_ID(eep_config
,
10172 ASC_EEP_GET_CHIP_ID(eep_config
) & ASC_MAX_TID
);
10173 asc_dvc
->cfg
->chip_scsi_id
= ASC_EEP_GET_CHIP_ID(eep_config
);
10174 if (((asc_dvc
->bus_type
& ASC_IS_PCI_ULTRA
) == ASC_IS_PCI_ULTRA
) &&
10175 !(asc_dvc
->dvc_cntl
& ASC_CNTL_SDTR_ENABLE_ULTRA
)) {
10176 asc_dvc
->min_sdtr_index
= ASC_SDTR_ULTRA_PCI_10MB_INDEX
;
10179 for (i
= 0; i
<= ASC_MAX_TID
; i
++) {
10180 asc_dvc
->dos_int13_table
[i
] = eep_config
->dos_int13_table
[i
];
10181 asc_dvc
->cfg
->max_tag_qng
[i
] = eep_config
->max_tag_qng
;
10182 asc_dvc
->cfg
->sdtr_period_offset
[i
] =
10183 (uchar
)(ASC_DEF_SDTR_OFFSET
|
10184 (asc_dvc
->min_sdtr_index
<< 4));
10186 eep_config
->cfg_msw
= AscGetChipCfgMsw(iop_base
);
10188 if ((i
= AscSetEEPConfig(iop_base
, eep_config
,
10189 asc_dvc
->bus_type
)) != 0) {
10191 ("AscInitFromEEP: Failed to re-write EEPROM with %d errors.\n",
10195 ("AscInitFromEEP: Successfully re-wrote EEPROM.\n");
10198 return (warn_code
);
10201 static int __devinit
AscInitGetConfig(struct Scsi_Host
*shost
)
10203 struct asc_board
*board
= shost_priv(shost
);
10204 ASC_DVC_VAR
*asc_dvc
= &board
->dvc_var
.asc_dvc_var
;
10205 unsigned short warn_code
= 0;
10207 asc_dvc
->init_state
= ASC_INIT_STATE_BEG_GET_CFG
;
10208 if (asc_dvc
->err_code
!= 0)
10209 return asc_dvc
->err_code
;
10211 if (AscFindSignature(asc_dvc
->iop_base
)) {
10212 warn_code
|= AscInitAscDvcVar(asc_dvc
);
10213 warn_code
|= AscInitFromEEP(asc_dvc
);
10214 asc_dvc
->init_state
|= ASC_INIT_STATE_END_GET_CFG
;
10215 if (asc_dvc
->scsi_reset_wait
> ASC_MAX_SCSI_RESET_WAIT
)
10216 asc_dvc
->scsi_reset_wait
= ASC_MAX_SCSI_RESET_WAIT
;
10218 asc_dvc
->err_code
= ASC_IERR_BAD_SIGNATURE
;
10221 switch (warn_code
) {
10222 case 0: /* No error */
10224 case ASC_WARN_IO_PORT_ROTATE
:
10225 shost_printk(KERN_WARNING
, shost
, "I/O port address "
10228 case ASC_WARN_AUTO_CONFIG
:
10229 shost_printk(KERN_WARNING
, shost
, "I/O port increment switch "
10232 case ASC_WARN_EEPROM_CHKSUM
:
10233 shost_printk(KERN_WARNING
, shost
, "EEPROM checksum error\n");
10235 case ASC_WARN_IRQ_MODIFIED
:
10236 shost_printk(KERN_WARNING
, shost
, "IRQ modified\n");
10238 case ASC_WARN_CMD_QNG_CONFLICT
:
10239 shost_printk(KERN_WARNING
, shost
, "tag queuing enabled w/o "
10243 shost_printk(KERN_WARNING
, shost
, "unknown warning: 0x%x\n",
10248 if (asc_dvc
->err_code
!= 0)
10249 shost_printk(KERN_ERR
, shost
, "error 0x%x at init_state "
10250 "0x%x\n", asc_dvc
->err_code
, asc_dvc
->init_state
);
10252 return asc_dvc
->err_code
;
10255 static int __devinit
AscInitSetConfig(struct pci_dev
*pdev
, struct Scsi_Host
*shost
)
10257 struct asc_board
*board
= shost_priv(shost
);
10258 ASC_DVC_VAR
*asc_dvc
= &board
->dvc_var
.asc_dvc_var
;
10259 PortAddr iop_base
= asc_dvc
->iop_base
;
10260 unsigned short cfg_msw
;
10261 unsigned short warn_code
= 0;
10263 asc_dvc
->init_state
|= ASC_INIT_STATE_BEG_SET_CFG
;
10264 if (asc_dvc
->err_code
!= 0)
10265 return asc_dvc
->err_code
;
10266 if (!AscFindSignature(asc_dvc
->iop_base
)) {
10267 asc_dvc
->err_code
= ASC_IERR_BAD_SIGNATURE
;
10268 return asc_dvc
->err_code
;
10271 cfg_msw
= AscGetChipCfgMsw(iop_base
);
10272 if ((cfg_msw
& ASC_CFG_MSW_CLR_MASK
) != 0) {
10273 cfg_msw
&= ~ASC_CFG_MSW_CLR_MASK
;
10274 warn_code
|= ASC_WARN_CFG_MSW_RECOVER
;
10275 AscSetChipCfgMsw(iop_base
, cfg_msw
);
10277 if ((asc_dvc
->cfg
->cmd_qng_enabled
& asc_dvc
->cfg
->disc_enable
) !=
10278 asc_dvc
->cfg
->cmd_qng_enabled
) {
10279 asc_dvc
->cfg
->disc_enable
= asc_dvc
->cfg
->cmd_qng_enabled
;
10280 warn_code
|= ASC_WARN_CMD_QNG_CONFLICT
;
10282 if (AscGetChipStatus(iop_base
) & CSW_AUTO_CONFIG
) {
10283 warn_code
|= ASC_WARN_AUTO_CONFIG
;
10286 if (asc_dvc
->bus_type
& ASC_IS_PCI
) {
10288 AscSetChipCfgMsw(iop_base
, cfg_msw
);
10289 if ((asc_dvc
->bus_type
& ASC_IS_PCI_ULTRA
) == ASC_IS_PCI_ULTRA
) {
10291 if ((pdev
->device
== PCI_DEVICE_ID_ASP_1200A
) ||
10292 (pdev
->device
== PCI_DEVICE_ID_ASP_ABP940
)) {
10293 asc_dvc
->bug_fix_cntl
|= ASC_BUG_FIX_IF_NOT_DWB
;
10294 asc_dvc
->bug_fix_cntl
|=
10295 ASC_BUG_FIX_ASYN_USE_SYN
;
10299 #endif /* CONFIG_PCI */
10300 if (asc_dvc
->bus_type
== ASC_IS_ISAPNP
) {
10301 if (AscGetChipVersion(iop_base
, asc_dvc
->bus_type
)
10302 == ASC_CHIP_VER_ASYN_BUG
) {
10303 asc_dvc
->bug_fix_cntl
|= ASC_BUG_FIX_ASYN_USE_SYN
;
10306 if (AscSetChipScsiID(iop_base
, asc_dvc
->cfg
->chip_scsi_id
) !=
10307 asc_dvc
->cfg
->chip_scsi_id
) {
10308 asc_dvc
->err_code
|= ASC_IERR_SET_SCSI_ID
;
10311 if (asc_dvc
->bus_type
& ASC_IS_ISA
) {
10312 AscSetIsaDmaChannel(iop_base
, asc_dvc
->cfg
->isa_dma_channel
);
10313 AscSetIsaDmaSpeed(iop_base
, asc_dvc
->cfg
->isa_dma_speed
);
10315 #endif /* CONFIG_ISA */
10317 asc_dvc
->init_state
|= ASC_INIT_STATE_END_SET_CFG
;
10319 switch (warn_code
) {
10320 case 0: /* No error. */
10322 case ASC_WARN_IO_PORT_ROTATE
:
10323 shost_printk(KERN_WARNING
, shost
, "I/O port address "
10326 case ASC_WARN_AUTO_CONFIG
:
10327 shost_printk(KERN_WARNING
, shost
, "I/O port increment switch "
10330 case ASC_WARN_EEPROM_CHKSUM
:
10331 shost_printk(KERN_WARNING
, shost
, "EEPROM checksum error\n");
10333 case ASC_WARN_IRQ_MODIFIED
:
10334 shost_printk(KERN_WARNING
, shost
, "IRQ modified\n");
10336 case ASC_WARN_CMD_QNG_CONFLICT
:
10337 shost_printk(KERN_WARNING
, shost
, "tag queuing w/o "
10341 shost_printk(KERN_WARNING
, shost
, "unknown warning: 0x%x\n",
10346 if (asc_dvc
->err_code
!= 0)
10347 shost_printk(KERN_ERR
, shost
, "error 0x%x at init_state "
10348 "0x%x\n", asc_dvc
->err_code
, asc_dvc
->init_state
);
10350 return asc_dvc
->err_code
;
10354 * EEPROM Configuration.
10356 * All drivers should use this structure to set the default EEPROM
10357 * configuration. The BIOS now uses this structure when it is built.
10358 * Additional structure information can be found in a_condor.h where
10359 * the structure is defined.
10361 * The *_Field_IsChar structs are needed to correct for endianness.
10362 * These values are read from the board 16 bits at a time directly
10363 * into the structs. Because some fields are char, the values will be
10364 * in the wrong order. The *_Field_IsChar tells when to flip the
10365 * bytes. Data read and written to PCI memory is automatically swapped
10366 * on big-endian platforms so char fields read as words are actually being
10367 * unswapped on big-endian platforms.
10369 static ADVEEP_3550_CONFIG Default_3550_EEPROM_Config __devinitdata
= {
10370 ADV_EEPROM_BIOS_ENABLE
, /* cfg_lsw */
10371 0x0000, /* cfg_msw */
10372 0xFFFF, /* disc_enable */
10373 0xFFFF, /* wdtr_able */
10374 0xFFFF, /* sdtr_able */
10375 0xFFFF, /* start_motor */
10376 0xFFFF, /* tagqng_able */
10377 0xFFFF, /* bios_scan */
10378 0, /* scam_tolerant */
10379 7, /* adapter_scsi_id */
10380 0, /* bios_boot_delay */
10381 3, /* scsi_reset_delay */
10382 0, /* bios_id_lun */
10383 0, /* termination */
10385 0xFFE7, /* bios_ctrl */
10386 0xFFFF, /* ultra_able */
10388 ASC_DEF_MAX_HOST_QNG
, /* max_host_qng */
10389 ASC_DEF_MAX_DVC_QNG
, /* max_dvc_qng */
10392 0, /* serial_number_word1 */
10393 0, /* serial_number_word2 */
10394 0, /* serial_number_word3 */
10396 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
10397 , /* oem_name[16] */
10398 0, /* dvc_err_code */
10399 0, /* adv_err_code */
10400 0, /* adv_err_addr */
10401 0, /* saved_dvc_err_code */
10402 0, /* saved_adv_err_code */
10403 0, /* saved_adv_err_addr */
10407 static ADVEEP_3550_CONFIG ADVEEP_3550_Config_Field_IsChar __devinitdata
= {
10410 0, /* -disc_enable */
10413 0, /* start_motor */
10414 0, /* tagqng_able */
10416 0, /* scam_tolerant */
10417 1, /* adapter_scsi_id */
10418 1, /* bios_boot_delay */
10419 1, /* scsi_reset_delay */
10420 1, /* bios_id_lun */
10421 1, /* termination */
10424 0, /* ultra_able */
10426 1, /* max_host_qng */
10427 1, /* max_dvc_qng */
10430 0, /* serial_number_word1 */
10431 0, /* serial_number_word2 */
10432 0, /* serial_number_word3 */
10434 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
10435 , /* oem_name[16] */
10436 0, /* dvc_err_code */
10437 0, /* adv_err_code */
10438 0, /* adv_err_addr */
10439 0, /* saved_dvc_err_code */
10440 0, /* saved_adv_err_code */
10441 0, /* saved_adv_err_addr */
10445 static ADVEEP_38C0800_CONFIG Default_38C0800_EEPROM_Config __devinitdata
= {
10446 ADV_EEPROM_BIOS_ENABLE
, /* 00 cfg_lsw */
10447 0x0000, /* 01 cfg_msw */
10448 0xFFFF, /* 02 disc_enable */
10449 0xFFFF, /* 03 wdtr_able */
10450 0x4444, /* 04 sdtr_speed1 */
10451 0xFFFF, /* 05 start_motor */
10452 0xFFFF, /* 06 tagqng_able */
10453 0xFFFF, /* 07 bios_scan */
10454 0, /* 08 scam_tolerant */
10455 7, /* 09 adapter_scsi_id */
10456 0, /* bios_boot_delay */
10457 3, /* 10 scsi_reset_delay */
10458 0, /* bios_id_lun */
10459 0, /* 11 termination_se */
10460 0, /* termination_lvd */
10461 0xFFE7, /* 12 bios_ctrl */
10462 0x4444, /* 13 sdtr_speed2 */
10463 0x4444, /* 14 sdtr_speed3 */
10464 ASC_DEF_MAX_HOST_QNG
, /* 15 max_host_qng */
10465 ASC_DEF_MAX_DVC_QNG
, /* max_dvc_qng */
10466 0, /* 16 dvc_cntl */
10467 0x4444, /* 17 sdtr_speed4 */
10468 0, /* 18 serial_number_word1 */
10469 0, /* 19 serial_number_word2 */
10470 0, /* 20 serial_number_word3 */
10471 0, /* 21 check_sum */
10472 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
10473 , /* 22-29 oem_name[16] */
10474 0, /* 30 dvc_err_code */
10475 0, /* 31 adv_err_code */
10476 0, /* 32 adv_err_addr */
10477 0, /* 33 saved_dvc_err_code */
10478 0, /* 34 saved_adv_err_code */
10479 0, /* 35 saved_adv_err_addr */
10480 0, /* 36 reserved */
10481 0, /* 37 reserved */
10482 0, /* 38 reserved */
10483 0, /* 39 reserved */
10484 0, /* 40 reserved */
10485 0, /* 41 reserved */
10486 0, /* 42 reserved */
10487 0, /* 43 reserved */
10488 0, /* 44 reserved */
10489 0, /* 45 reserved */
10490 0, /* 46 reserved */
10491 0, /* 47 reserved */
10492 0, /* 48 reserved */
10493 0, /* 49 reserved */
10494 0, /* 50 reserved */
10495 0, /* 51 reserved */
10496 0, /* 52 reserved */
10497 0, /* 53 reserved */
10498 0, /* 54 reserved */
10499 0, /* 55 reserved */
10500 0, /* 56 cisptr_lsw */
10501 0, /* 57 cisprt_msw */
10502 PCI_VENDOR_ID_ASP
, /* 58 subsysvid */
10503 PCI_DEVICE_ID_38C0800_REV1
, /* 59 subsysid */
10504 0, /* 60 reserved */
10505 0, /* 61 reserved */
10506 0, /* 62 reserved */
10507 0 /* 63 reserved */
10510 static ADVEEP_38C0800_CONFIG ADVEEP_38C0800_Config_Field_IsChar __devinitdata
= {
10511 0, /* 00 cfg_lsw */
10512 0, /* 01 cfg_msw */
10513 0, /* 02 disc_enable */
10514 0, /* 03 wdtr_able */
10515 0, /* 04 sdtr_speed1 */
10516 0, /* 05 start_motor */
10517 0, /* 06 tagqng_able */
10518 0, /* 07 bios_scan */
10519 0, /* 08 scam_tolerant */
10520 1, /* 09 adapter_scsi_id */
10521 1, /* bios_boot_delay */
10522 1, /* 10 scsi_reset_delay */
10523 1, /* bios_id_lun */
10524 1, /* 11 termination_se */
10525 1, /* termination_lvd */
10526 0, /* 12 bios_ctrl */
10527 0, /* 13 sdtr_speed2 */
10528 0, /* 14 sdtr_speed3 */
10529 1, /* 15 max_host_qng */
10530 1, /* max_dvc_qng */
10531 0, /* 16 dvc_cntl */
10532 0, /* 17 sdtr_speed4 */
10533 0, /* 18 serial_number_word1 */
10534 0, /* 19 serial_number_word2 */
10535 0, /* 20 serial_number_word3 */
10536 0, /* 21 check_sum */
10537 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
10538 , /* 22-29 oem_name[16] */
10539 0, /* 30 dvc_err_code */
10540 0, /* 31 adv_err_code */
10541 0, /* 32 adv_err_addr */
10542 0, /* 33 saved_dvc_err_code */
10543 0, /* 34 saved_adv_err_code */
10544 0, /* 35 saved_adv_err_addr */
10545 0, /* 36 reserved */
10546 0, /* 37 reserved */
10547 0, /* 38 reserved */
10548 0, /* 39 reserved */
10549 0, /* 40 reserved */
10550 0, /* 41 reserved */
10551 0, /* 42 reserved */
10552 0, /* 43 reserved */
10553 0, /* 44 reserved */
10554 0, /* 45 reserved */
10555 0, /* 46 reserved */
10556 0, /* 47 reserved */
10557 0, /* 48 reserved */
10558 0, /* 49 reserved */
10559 0, /* 50 reserved */
10560 0, /* 51 reserved */
10561 0, /* 52 reserved */
10562 0, /* 53 reserved */
10563 0, /* 54 reserved */
10564 0, /* 55 reserved */
10565 0, /* 56 cisptr_lsw */
10566 0, /* 57 cisprt_msw */
10567 0, /* 58 subsysvid */
10568 0, /* 59 subsysid */
10569 0, /* 60 reserved */
10570 0, /* 61 reserved */
10571 0, /* 62 reserved */
10572 0 /* 63 reserved */
10575 static ADVEEP_38C1600_CONFIG Default_38C1600_EEPROM_Config __devinitdata
= {
10576 ADV_EEPROM_BIOS_ENABLE
, /* 00 cfg_lsw */
10577 0x0000, /* 01 cfg_msw */
10578 0xFFFF, /* 02 disc_enable */
10579 0xFFFF, /* 03 wdtr_able */
10580 0x5555, /* 04 sdtr_speed1 */
10581 0xFFFF, /* 05 start_motor */
10582 0xFFFF, /* 06 tagqng_able */
10583 0xFFFF, /* 07 bios_scan */
10584 0, /* 08 scam_tolerant */
10585 7, /* 09 adapter_scsi_id */
10586 0, /* bios_boot_delay */
10587 3, /* 10 scsi_reset_delay */
10588 0, /* bios_id_lun */
10589 0, /* 11 termination_se */
10590 0, /* termination_lvd */
10591 0xFFE7, /* 12 bios_ctrl */
10592 0x5555, /* 13 sdtr_speed2 */
10593 0x5555, /* 14 sdtr_speed3 */
10594 ASC_DEF_MAX_HOST_QNG
, /* 15 max_host_qng */
10595 ASC_DEF_MAX_DVC_QNG
, /* max_dvc_qng */
10596 0, /* 16 dvc_cntl */
10597 0x5555, /* 17 sdtr_speed4 */
10598 0, /* 18 serial_number_word1 */
10599 0, /* 19 serial_number_word2 */
10600 0, /* 20 serial_number_word3 */
10601 0, /* 21 check_sum */
10602 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
10603 , /* 22-29 oem_name[16] */
10604 0, /* 30 dvc_err_code */
10605 0, /* 31 adv_err_code */
10606 0, /* 32 adv_err_addr */
10607 0, /* 33 saved_dvc_err_code */
10608 0, /* 34 saved_adv_err_code */
10609 0, /* 35 saved_adv_err_addr */
10610 0, /* 36 reserved */
10611 0, /* 37 reserved */
10612 0, /* 38 reserved */
10613 0, /* 39 reserved */
10614 0, /* 40 reserved */
10615 0, /* 41 reserved */
10616 0, /* 42 reserved */
10617 0, /* 43 reserved */
10618 0, /* 44 reserved */
10619 0, /* 45 reserved */
10620 0, /* 46 reserved */
10621 0, /* 47 reserved */
10622 0, /* 48 reserved */
10623 0, /* 49 reserved */
10624 0, /* 50 reserved */
10625 0, /* 51 reserved */
10626 0, /* 52 reserved */
10627 0, /* 53 reserved */
10628 0, /* 54 reserved */
10629 0, /* 55 reserved */
10630 0, /* 56 cisptr_lsw */
10631 0, /* 57 cisprt_msw */
10632 PCI_VENDOR_ID_ASP
, /* 58 subsysvid */
10633 PCI_DEVICE_ID_38C1600_REV1
, /* 59 subsysid */
10634 0, /* 60 reserved */
10635 0, /* 61 reserved */
10636 0, /* 62 reserved */
10637 0 /* 63 reserved */
10640 static ADVEEP_38C1600_CONFIG ADVEEP_38C1600_Config_Field_IsChar __devinitdata
= {
10641 0, /* 00 cfg_lsw */
10642 0, /* 01 cfg_msw */
10643 0, /* 02 disc_enable */
10644 0, /* 03 wdtr_able */
10645 0, /* 04 sdtr_speed1 */
10646 0, /* 05 start_motor */
10647 0, /* 06 tagqng_able */
10648 0, /* 07 bios_scan */
10649 0, /* 08 scam_tolerant */
10650 1, /* 09 adapter_scsi_id */
10651 1, /* bios_boot_delay */
10652 1, /* 10 scsi_reset_delay */
10653 1, /* bios_id_lun */
10654 1, /* 11 termination_se */
10655 1, /* termination_lvd */
10656 0, /* 12 bios_ctrl */
10657 0, /* 13 sdtr_speed2 */
10658 0, /* 14 sdtr_speed3 */
10659 1, /* 15 max_host_qng */
10660 1, /* max_dvc_qng */
10661 0, /* 16 dvc_cntl */
10662 0, /* 17 sdtr_speed4 */
10663 0, /* 18 serial_number_word1 */
10664 0, /* 19 serial_number_word2 */
10665 0, /* 20 serial_number_word3 */
10666 0, /* 21 check_sum */
10667 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
10668 , /* 22-29 oem_name[16] */
10669 0, /* 30 dvc_err_code */
10670 0, /* 31 adv_err_code */
10671 0, /* 32 adv_err_addr */
10672 0, /* 33 saved_dvc_err_code */
10673 0, /* 34 saved_adv_err_code */
10674 0, /* 35 saved_adv_err_addr */
10675 0, /* 36 reserved */
10676 0, /* 37 reserved */
10677 0, /* 38 reserved */
10678 0, /* 39 reserved */
10679 0, /* 40 reserved */
10680 0, /* 41 reserved */
10681 0, /* 42 reserved */
10682 0, /* 43 reserved */
10683 0, /* 44 reserved */
10684 0, /* 45 reserved */
10685 0, /* 46 reserved */
10686 0, /* 47 reserved */
10687 0, /* 48 reserved */
10688 0, /* 49 reserved */
10689 0, /* 50 reserved */
10690 0, /* 51 reserved */
10691 0, /* 52 reserved */
10692 0, /* 53 reserved */
10693 0, /* 54 reserved */
10694 0, /* 55 reserved */
10695 0, /* 56 cisptr_lsw */
10696 0, /* 57 cisprt_msw */
10697 0, /* 58 subsysvid */
10698 0, /* 59 subsysid */
10699 0, /* 60 reserved */
10700 0, /* 61 reserved */
10701 0, /* 62 reserved */
10702 0 /* 63 reserved */
10707 * Wait for EEPROM command to complete
10709 static void __devinit
AdvWaitEEPCmd(AdvPortAddr iop_base
)
10713 for (eep_delay_ms
= 0; eep_delay_ms
< ADV_EEP_DELAY_MS
; eep_delay_ms
++) {
10714 if (AdvReadWordRegister(iop_base
, IOPW_EE_CMD
) &
10715 ASC_EEP_CMD_DONE
) {
10720 if ((AdvReadWordRegister(iop_base
, IOPW_EE_CMD
) & ASC_EEP_CMD_DONE
) ==
10726 * Read the EEPROM from specified location
10728 static ushort __devinit
AdvReadEEPWord(AdvPortAddr iop_base
, int eep_word_addr
)
10730 AdvWriteWordRegister(iop_base
, IOPW_EE_CMD
,
10731 ASC_EEP_CMD_READ
| eep_word_addr
);
10732 AdvWaitEEPCmd(iop_base
);
10733 return AdvReadWordRegister(iop_base
, IOPW_EE_DATA
);
10737 * Write the EEPROM from 'cfg_buf'.
10739 static void __devinit
10740 AdvSet3550EEPConfig(AdvPortAddr iop_base
, ADVEEP_3550_CONFIG
*cfg_buf
)
10743 ushort addr
, chksum
;
10744 ushort
*charfields
;
10746 wbuf
= (ushort
*)cfg_buf
;
10747 charfields
= (ushort
*)&ADVEEP_3550_Config_Field_IsChar
;
10750 AdvWriteWordRegister(iop_base
, IOPW_EE_CMD
, ASC_EEP_CMD_WRITE_ABLE
);
10751 AdvWaitEEPCmd(iop_base
);
10754 * Write EEPROM from word 0 to word 20.
10756 for (addr
= ADV_EEP_DVC_CFG_BEGIN
;
10757 addr
< ADV_EEP_DVC_CFG_END
; addr
++, wbuf
++) {
10760 if (*charfields
++) {
10761 word
= cpu_to_le16(*wbuf
);
10765 chksum
+= *wbuf
; /* Checksum is calculated from word values. */
10766 AdvWriteWordRegister(iop_base
, IOPW_EE_DATA
, word
);
10767 AdvWriteWordRegister(iop_base
, IOPW_EE_CMD
,
10768 ASC_EEP_CMD_WRITE
| addr
);
10769 AdvWaitEEPCmd(iop_base
);
10770 mdelay(ADV_EEP_DELAY_MS
);
10774 * Write EEPROM checksum at word 21.
10776 AdvWriteWordRegister(iop_base
, IOPW_EE_DATA
, chksum
);
10777 AdvWriteWordRegister(iop_base
, IOPW_EE_CMD
, ASC_EEP_CMD_WRITE
| addr
);
10778 AdvWaitEEPCmd(iop_base
);
10783 * Write EEPROM OEM name at words 22 to 29.
10785 for (addr
= ADV_EEP_DVC_CTL_BEGIN
;
10786 addr
< ADV_EEP_MAX_WORD_ADDR
; addr
++, wbuf
++) {
10789 if (*charfields
++) {
10790 word
= cpu_to_le16(*wbuf
);
10794 AdvWriteWordRegister(iop_base
, IOPW_EE_DATA
, word
);
10795 AdvWriteWordRegister(iop_base
, IOPW_EE_CMD
,
10796 ASC_EEP_CMD_WRITE
| addr
);
10797 AdvWaitEEPCmd(iop_base
);
10799 AdvWriteWordRegister(iop_base
, IOPW_EE_CMD
, ASC_EEP_CMD_WRITE_DISABLE
);
10800 AdvWaitEEPCmd(iop_base
);
10804 * Write the EEPROM from 'cfg_buf'.
10806 static void __devinit
10807 AdvSet38C0800EEPConfig(AdvPortAddr iop_base
, ADVEEP_38C0800_CONFIG
*cfg_buf
)
10810 ushort
*charfields
;
10811 ushort addr
, chksum
;
10813 wbuf
= (ushort
*)cfg_buf
;
10814 charfields
= (ushort
*)&ADVEEP_38C0800_Config_Field_IsChar
;
10817 AdvWriteWordRegister(iop_base
, IOPW_EE_CMD
, ASC_EEP_CMD_WRITE_ABLE
);
10818 AdvWaitEEPCmd(iop_base
);
10821 * Write EEPROM from word 0 to word 20.
10823 for (addr
= ADV_EEP_DVC_CFG_BEGIN
;
10824 addr
< ADV_EEP_DVC_CFG_END
; addr
++, wbuf
++) {
10827 if (*charfields
++) {
10828 word
= cpu_to_le16(*wbuf
);
10832 chksum
+= *wbuf
; /* Checksum is calculated from word values. */
10833 AdvWriteWordRegister(iop_base
, IOPW_EE_DATA
, word
);
10834 AdvWriteWordRegister(iop_base
, IOPW_EE_CMD
,
10835 ASC_EEP_CMD_WRITE
| addr
);
10836 AdvWaitEEPCmd(iop_base
);
10837 mdelay(ADV_EEP_DELAY_MS
);
10841 * Write EEPROM checksum at word 21.
10843 AdvWriteWordRegister(iop_base
, IOPW_EE_DATA
, chksum
);
10844 AdvWriteWordRegister(iop_base
, IOPW_EE_CMD
, ASC_EEP_CMD_WRITE
| addr
);
10845 AdvWaitEEPCmd(iop_base
);
10850 * Write EEPROM OEM name at words 22 to 29.
10852 for (addr
= ADV_EEP_DVC_CTL_BEGIN
;
10853 addr
< ADV_EEP_MAX_WORD_ADDR
; addr
++, wbuf
++) {
10856 if (*charfields
++) {
10857 word
= cpu_to_le16(*wbuf
);
10861 AdvWriteWordRegister(iop_base
, IOPW_EE_DATA
, word
);
10862 AdvWriteWordRegister(iop_base
, IOPW_EE_CMD
,
10863 ASC_EEP_CMD_WRITE
| addr
);
10864 AdvWaitEEPCmd(iop_base
);
10866 AdvWriteWordRegister(iop_base
, IOPW_EE_CMD
, ASC_EEP_CMD_WRITE_DISABLE
);
10867 AdvWaitEEPCmd(iop_base
);
10871 * Write the EEPROM from 'cfg_buf'.
10873 static void __devinit
10874 AdvSet38C1600EEPConfig(AdvPortAddr iop_base
, ADVEEP_38C1600_CONFIG
*cfg_buf
)
10877 ushort
*charfields
;
10878 ushort addr
, chksum
;
10880 wbuf
= (ushort
*)cfg_buf
;
10881 charfields
= (ushort
*)&ADVEEP_38C1600_Config_Field_IsChar
;
10884 AdvWriteWordRegister(iop_base
, IOPW_EE_CMD
, ASC_EEP_CMD_WRITE_ABLE
);
10885 AdvWaitEEPCmd(iop_base
);
10888 * Write EEPROM from word 0 to word 20.
10890 for (addr
= ADV_EEP_DVC_CFG_BEGIN
;
10891 addr
< ADV_EEP_DVC_CFG_END
; addr
++, wbuf
++) {
10894 if (*charfields
++) {
10895 word
= cpu_to_le16(*wbuf
);
10899 chksum
+= *wbuf
; /* Checksum is calculated from word values. */
10900 AdvWriteWordRegister(iop_base
, IOPW_EE_DATA
, word
);
10901 AdvWriteWordRegister(iop_base
, IOPW_EE_CMD
,
10902 ASC_EEP_CMD_WRITE
| addr
);
10903 AdvWaitEEPCmd(iop_base
);
10904 mdelay(ADV_EEP_DELAY_MS
);
10908 * Write EEPROM checksum at word 21.
10910 AdvWriteWordRegister(iop_base
, IOPW_EE_DATA
, chksum
);
10911 AdvWriteWordRegister(iop_base
, IOPW_EE_CMD
, ASC_EEP_CMD_WRITE
| addr
);
10912 AdvWaitEEPCmd(iop_base
);
10917 * Write EEPROM OEM name at words 22 to 29.
10919 for (addr
= ADV_EEP_DVC_CTL_BEGIN
;
10920 addr
< ADV_EEP_MAX_WORD_ADDR
; addr
++, wbuf
++) {
10923 if (*charfields
++) {
10924 word
= cpu_to_le16(*wbuf
);
10928 AdvWriteWordRegister(iop_base
, IOPW_EE_DATA
, word
);
10929 AdvWriteWordRegister(iop_base
, IOPW_EE_CMD
,
10930 ASC_EEP_CMD_WRITE
| addr
);
10931 AdvWaitEEPCmd(iop_base
);
10933 AdvWriteWordRegister(iop_base
, IOPW_EE_CMD
, ASC_EEP_CMD_WRITE_DISABLE
);
10934 AdvWaitEEPCmd(iop_base
);
10938 * Read EEPROM configuration into the specified buffer.
10940 * Return a checksum based on the EEPROM configuration read.
10942 static ushort __devinit
10943 AdvGet3550EEPConfig(AdvPortAddr iop_base
, ADVEEP_3550_CONFIG
*cfg_buf
)
10945 ushort wval
, chksum
;
10948 ushort
*charfields
;
10950 charfields
= (ushort
*)&ADVEEP_3550_Config_Field_IsChar
;
10951 wbuf
= (ushort
*)cfg_buf
;
10954 for (eep_addr
= ADV_EEP_DVC_CFG_BEGIN
;
10955 eep_addr
< ADV_EEP_DVC_CFG_END
; eep_addr
++, wbuf
++) {
10956 wval
= AdvReadEEPWord(iop_base
, eep_addr
);
10957 chksum
+= wval
; /* Checksum is calculated from word values. */
10958 if (*charfields
++) {
10959 *wbuf
= le16_to_cpu(wval
);
10964 /* Read checksum word. */
10965 *wbuf
= AdvReadEEPWord(iop_base
, eep_addr
);
10969 /* Read rest of EEPROM not covered by the checksum. */
10970 for (eep_addr
= ADV_EEP_DVC_CTL_BEGIN
;
10971 eep_addr
< ADV_EEP_MAX_WORD_ADDR
; eep_addr
++, wbuf
++) {
10972 *wbuf
= AdvReadEEPWord(iop_base
, eep_addr
);
10973 if (*charfields
++) {
10974 *wbuf
= le16_to_cpu(*wbuf
);
10981 * Read EEPROM configuration into the specified buffer.
10983 * Return a checksum based on the EEPROM configuration read.
10985 static ushort __devinit
10986 AdvGet38C0800EEPConfig(AdvPortAddr iop_base
, ADVEEP_38C0800_CONFIG
*cfg_buf
)
10988 ushort wval
, chksum
;
10991 ushort
*charfields
;
10993 charfields
= (ushort
*)&ADVEEP_38C0800_Config_Field_IsChar
;
10994 wbuf
= (ushort
*)cfg_buf
;
10997 for (eep_addr
= ADV_EEP_DVC_CFG_BEGIN
;
10998 eep_addr
< ADV_EEP_DVC_CFG_END
; eep_addr
++, wbuf
++) {
10999 wval
= AdvReadEEPWord(iop_base
, eep_addr
);
11000 chksum
+= wval
; /* Checksum is calculated from word values. */
11001 if (*charfields
++) {
11002 *wbuf
= le16_to_cpu(wval
);
11007 /* Read checksum word. */
11008 *wbuf
= AdvReadEEPWord(iop_base
, eep_addr
);
11012 /* Read rest of EEPROM not covered by the checksum. */
11013 for (eep_addr
= ADV_EEP_DVC_CTL_BEGIN
;
11014 eep_addr
< ADV_EEP_MAX_WORD_ADDR
; eep_addr
++, wbuf
++) {
11015 *wbuf
= AdvReadEEPWord(iop_base
, eep_addr
);
11016 if (*charfields
++) {
11017 *wbuf
= le16_to_cpu(*wbuf
);
11024 * Read EEPROM configuration into the specified buffer.
11026 * Return a checksum based on the EEPROM configuration read.
11028 static ushort __devinit
11029 AdvGet38C1600EEPConfig(AdvPortAddr iop_base
, ADVEEP_38C1600_CONFIG
*cfg_buf
)
11031 ushort wval
, chksum
;
11034 ushort
*charfields
;
11036 charfields
= (ushort
*)&ADVEEP_38C1600_Config_Field_IsChar
;
11037 wbuf
= (ushort
*)cfg_buf
;
11040 for (eep_addr
= ADV_EEP_DVC_CFG_BEGIN
;
11041 eep_addr
< ADV_EEP_DVC_CFG_END
; eep_addr
++, wbuf
++) {
11042 wval
= AdvReadEEPWord(iop_base
, eep_addr
);
11043 chksum
+= wval
; /* Checksum is calculated from word values. */
11044 if (*charfields
++) {
11045 *wbuf
= le16_to_cpu(wval
);
11050 /* Read checksum word. */
11051 *wbuf
= AdvReadEEPWord(iop_base
, eep_addr
);
11055 /* Read rest of EEPROM not covered by the checksum. */
11056 for (eep_addr
= ADV_EEP_DVC_CTL_BEGIN
;
11057 eep_addr
< ADV_EEP_MAX_WORD_ADDR
; eep_addr
++, wbuf
++) {
11058 *wbuf
= AdvReadEEPWord(iop_base
, eep_addr
);
11059 if (*charfields
++) {
11060 *wbuf
= le16_to_cpu(*wbuf
);
11067 * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
11068 * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
11069 * all of this is done.
11071 * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
11073 * For a non-fatal error return a warning code. If there are no warnings
11074 * then 0 is returned.
11076 * Note: Chip is stopped on entry.
11078 static int __devinit
AdvInitFrom3550EEP(ADV_DVC_VAR
*asc_dvc
)
11080 AdvPortAddr iop_base
;
11082 ADVEEP_3550_CONFIG eep_config
;
11084 iop_base
= asc_dvc
->iop_base
;
11089 * Read the board's EEPROM configuration.
11091 * Set default values if a bad checksum is found.
11093 if (AdvGet3550EEPConfig(iop_base
, &eep_config
) != eep_config
.check_sum
) {
11094 warn_code
|= ASC_WARN_EEPROM_CHKSUM
;
11097 * Set EEPROM default values.
11099 memcpy(&eep_config
, &Default_3550_EEPROM_Config
,
11100 sizeof(ADVEEP_3550_CONFIG
));
11103 * Assume the 6 byte board serial number that was read from
11104 * EEPROM is correct even if the EEPROM checksum failed.
11106 eep_config
.serial_number_word3
=
11107 AdvReadEEPWord(iop_base
, ADV_EEP_DVC_CFG_END
- 1);
11109 eep_config
.serial_number_word2
=
11110 AdvReadEEPWord(iop_base
, ADV_EEP_DVC_CFG_END
- 2);
11112 eep_config
.serial_number_word1
=
11113 AdvReadEEPWord(iop_base
, ADV_EEP_DVC_CFG_END
- 3);
11115 AdvSet3550EEPConfig(iop_base
, &eep_config
);
11118 * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
11119 * EEPROM configuration that was read.
11121 * This is the mapping of EEPROM fields to Adv Library fields.
11123 asc_dvc
->wdtr_able
= eep_config
.wdtr_able
;
11124 asc_dvc
->sdtr_able
= eep_config
.sdtr_able
;
11125 asc_dvc
->ultra_able
= eep_config
.ultra_able
;
11126 asc_dvc
->tagqng_able
= eep_config
.tagqng_able
;
11127 asc_dvc
->cfg
->disc_enable
= eep_config
.disc_enable
;
11128 asc_dvc
->max_host_qng
= eep_config
.max_host_qng
;
11129 asc_dvc
->max_dvc_qng
= eep_config
.max_dvc_qng
;
11130 asc_dvc
->chip_scsi_id
= (eep_config
.adapter_scsi_id
& ADV_MAX_TID
);
11131 asc_dvc
->start_motor
= eep_config
.start_motor
;
11132 asc_dvc
->scsi_reset_wait
= eep_config
.scsi_reset_delay
;
11133 asc_dvc
->bios_ctrl
= eep_config
.bios_ctrl
;
11134 asc_dvc
->no_scam
= eep_config
.scam_tolerant
;
11135 asc_dvc
->cfg
->serial1
= eep_config
.serial_number_word1
;
11136 asc_dvc
->cfg
->serial2
= eep_config
.serial_number_word2
;
11137 asc_dvc
->cfg
->serial3
= eep_config
.serial_number_word3
;
11140 * Set the host maximum queuing (max. 253, min. 16) and the per device
11141 * maximum queuing (max. 63, min. 4).
11143 if (eep_config
.max_host_qng
> ASC_DEF_MAX_HOST_QNG
) {
11144 eep_config
.max_host_qng
= ASC_DEF_MAX_HOST_QNG
;
11145 } else if (eep_config
.max_host_qng
< ASC_DEF_MIN_HOST_QNG
) {
11146 /* If the value is zero, assume it is uninitialized. */
11147 if (eep_config
.max_host_qng
== 0) {
11148 eep_config
.max_host_qng
= ASC_DEF_MAX_HOST_QNG
;
11150 eep_config
.max_host_qng
= ASC_DEF_MIN_HOST_QNG
;
11154 if (eep_config
.max_dvc_qng
> ASC_DEF_MAX_DVC_QNG
) {
11155 eep_config
.max_dvc_qng
= ASC_DEF_MAX_DVC_QNG
;
11156 } else if (eep_config
.max_dvc_qng
< ASC_DEF_MIN_DVC_QNG
) {
11157 /* If the value is zero, assume it is uninitialized. */
11158 if (eep_config
.max_dvc_qng
== 0) {
11159 eep_config
.max_dvc_qng
= ASC_DEF_MAX_DVC_QNG
;
11161 eep_config
.max_dvc_qng
= ASC_DEF_MIN_DVC_QNG
;
11166 * If 'max_dvc_qng' is greater than 'max_host_qng', then
11167 * set 'max_dvc_qng' to 'max_host_qng'.
11169 if (eep_config
.max_dvc_qng
> eep_config
.max_host_qng
) {
11170 eep_config
.max_dvc_qng
= eep_config
.max_host_qng
;
11174 * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
11175 * values based on possibly adjusted EEPROM values.
11177 asc_dvc
->max_host_qng
= eep_config
.max_host_qng
;
11178 asc_dvc
->max_dvc_qng
= eep_config
.max_dvc_qng
;
11181 * If the EEPROM 'termination' field is set to automatic (0), then set
11182 * the ADV_DVC_CFG 'termination' field to automatic also.
11184 * If the termination is specified with a non-zero 'termination'
11185 * value check that a legal value is set and set the ADV_DVC_CFG
11186 * 'termination' field appropriately.
11188 if (eep_config
.termination
== 0) {
11189 asc_dvc
->cfg
->termination
= 0; /* auto termination */
11191 /* Enable manual control with low off / high off. */
11192 if (eep_config
.termination
== 1) {
11193 asc_dvc
->cfg
->termination
= TERM_CTL_SEL
;
11195 /* Enable manual control with low off / high on. */
11196 } else if (eep_config
.termination
== 2) {
11197 asc_dvc
->cfg
->termination
= TERM_CTL_SEL
| TERM_CTL_H
;
11199 /* Enable manual control with low on / high on. */
11200 } else if (eep_config
.termination
== 3) {
11201 asc_dvc
->cfg
->termination
=
11202 TERM_CTL_SEL
| TERM_CTL_H
| TERM_CTL_L
;
11205 * The EEPROM 'termination' field contains a bad value. Use
11206 * automatic termination instead.
11208 asc_dvc
->cfg
->termination
= 0;
11209 warn_code
|= ASC_WARN_EEPROM_TERMINATION
;
11217 * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
11218 * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
11219 * all of this is done.
11221 * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
11223 * For a non-fatal error return a warning code. If there are no warnings
11224 * then 0 is returned.
11226 * Note: Chip is stopped on entry.
11228 static int __devinit
AdvInitFrom38C0800EEP(ADV_DVC_VAR
*asc_dvc
)
11230 AdvPortAddr iop_base
;
11232 ADVEEP_38C0800_CONFIG eep_config
;
11233 uchar tid
, termination
;
11234 ushort sdtr_speed
= 0;
11236 iop_base
= asc_dvc
->iop_base
;
11241 * Read the board's EEPROM configuration.
11243 * Set default values if a bad checksum is found.
11245 if (AdvGet38C0800EEPConfig(iop_base
, &eep_config
) !=
11246 eep_config
.check_sum
) {
11247 warn_code
|= ASC_WARN_EEPROM_CHKSUM
;
11250 * Set EEPROM default values.
11252 memcpy(&eep_config
, &Default_38C0800_EEPROM_Config
,
11253 sizeof(ADVEEP_38C0800_CONFIG
));
11256 * Assume the 6 byte board serial number that was read from
11257 * EEPROM is correct even if the EEPROM checksum failed.
11259 eep_config
.serial_number_word3
=
11260 AdvReadEEPWord(iop_base
, ADV_EEP_DVC_CFG_END
- 1);
11262 eep_config
.serial_number_word2
=
11263 AdvReadEEPWord(iop_base
, ADV_EEP_DVC_CFG_END
- 2);
11265 eep_config
.serial_number_word1
=
11266 AdvReadEEPWord(iop_base
, ADV_EEP_DVC_CFG_END
- 3);
11268 AdvSet38C0800EEPConfig(iop_base
, &eep_config
);
11271 * Set ADV_DVC_VAR and ADV_DVC_CFG variables from the
11272 * EEPROM configuration that was read.
11274 * This is the mapping of EEPROM fields to Adv Library fields.
11276 asc_dvc
->wdtr_able
= eep_config
.wdtr_able
;
11277 asc_dvc
->sdtr_speed1
= eep_config
.sdtr_speed1
;
11278 asc_dvc
->sdtr_speed2
= eep_config
.sdtr_speed2
;
11279 asc_dvc
->sdtr_speed3
= eep_config
.sdtr_speed3
;
11280 asc_dvc
->sdtr_speed4
= eep_config
.sdtr_speed4
;
11281 asc_dvc
->tagqng_able
= eep_config
.tagqng_able
;
11282 asc_dvc
->cfg
->disc_enable
= eep_config
.disc_enable
;
11283 asc_dvc
->max_host_qng
= eep_config
.max_host_qng
;
11284 asc_dvc
->max_dvc_qng
= eep_config
.max_dvc_qng
;
11285 asc_dvc
->chip_scsi_id
= (eep_config
.adapter_scsi_id
& ADV_MAX_TID
);
11286 asc_dvc
->start_motor
= eep_config
.start_motor
;
11287 asc_dvc
->scsi_reset_wait
= eep_config
.scsi_reset_delay
;
11288 asc_dvc
->bios_ctrl
= eep_config
.bios_ctrl
;
11289 asc_dvc
->no_scam
= eep_config
.scam_tolerant
;
11290 asc_dvc
->cfg
->serial1
= eep_config
.serial_number_word1
;
11291 asc_dvc
->cfg
->serial2
= eep_config
.serial_number_word2
;
11292 asc_dvc
->cfg
->serial3
= eep_config
.serial_number_word3
;
11295 * For every Target ID if any of its 'sdtr_speed[1234]' bits
11296 * are set, then set an 'sdtr_able' bit for it.
11298 asc_dvc
->sdtr_able
= 0;
11299 for (tid
= 0; tid
<= ADV_MAX_TID
; tid
++) {
11301 sdtr_speed
= asc_dvc
->sdtr_speed1
;
11302 } else if (tid
== 4) {
11303 sdtr_speed
= asc_dvc
->sdtr_speed2
;
11304 } else if (tid
== 8) {
11305 sdtr_speed
= asc_dvc
->sdtr_speed3
;
11306 } else if (tid
== 12) {
11307 sdtr_speed
= asc_dvc
->sdtr_speed4
;
11309 if (sdtr_speed
& ADV_MAX_TID
) {
11310 asc_dvc
->sdtr_able
|= (1 << tid
);
11316 * Set the host maximum queuing (max. 253, min. 16) and the per device
11317 * maximum queuing (max. 63, min. 4).
11319 if (eep_config
.max_host_qng
> ASC_DEF_MAX_HOST_QNG
) {
11320 eep_config
.max_host_qng
= ASC_DEF_MAX_HOST_QNG
;
11321 } else if (eep_config
.max_host_qng
< ASC_DEF_MIN_HOST_QNG
) {
11322 /* If the value is zero, assume it is uninitialized. */
11323 if (eep_config
.max_host_qng
== 0) {
11324 eep_config
.max_host_qng
= ASC_DEF_MAX_HOST_QNG
;
11326 eep_config
.max_host_qng
= ASC_DEF_MIN_HOST_QNG
;
11330 if (eep_config
.max_dvc_qng
> ASC_DEF_MAX_DVC_QNG
) {
11331 eep_config
.max_dvc_qng
= ASC_DEF_MAX_DVC_QNG
;
11332 } else if (eep_config
.max_dvc_qng
< ASC_DEF_MIN_DVC_QNG
) {
11333 /* If the value is zero, assume it is uninitialized. */
11334 if (eep_config
.max_dvc_qng
== 0) {
11335 eep_config
.max_dvc_qng
= ASC_DEF_MAX_DVC_QNG
;
11337 eep_config
.max_dvc_qng
= ASC_DEF_MIN_DVC_QNG
;
11342 * If 'max_dvc_qng' is greater than 'max_host_qng', then
11343 * set 'max_dvc_qng' to 'max_host_qng'.
11345 if (eep_config
.max_dvc_qng
> eep_config
.max_host_qng
) {
11346 eep_config
.max_dvc_qng
= eep_config
.max_host_qng
;
11350 * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
11351 * values based on possibly adjusted EEPROM values.
11353 asc_dvc
->max_host_qng
= eep_config
.max_host_qng
;
11354 asc_dvc
->max_dvc_qng
= eep_config
.max_dvc_qng
;
11357 * If the EEPROM 'termination' field is set to automatic (0), then set
11358 * the ADV_DVC_CFG 'termination' field to automatic also.
11360 * If the termination is specified with a non-zero 'termination'
11361 * value check that a legal value is set and set the ADV_DVC_CFG
11362 * 'termination' field appropriately.
11364 if (eep_config
.termination_se
== 0) {
11365 termination
= 0; /* auto termination for SE */
11367 /* Enable manual control with low off / high off. */
11368 if (eep_config
.termination_se
== 1) {
11371 /* Enable manual control with low off / high on. */
11372 } else if (eep_config
.termination_se
== 2) {
11373 termination
= TERM_SE_HI
;
11375 /* Enable manual control with low on / high on. */
11376 } else if (eep_config
.termination_se
== 3) {
11377 termination
= TERM_SE
;
11380 * The EEPROM 'termination_se' field contains a bad value.
11381 * Use automatic termination instead.
11384 warn_code
|= ASC_WARN_EEPROM_TERMINATION
;
11388 if (eep_config
.termination_lvd
== 0) {
11389 asc_dvc
->cfg
->termination
= termination
; /* auto termination for LVD */
11391 /* Enable manual control with low off / high off. */
11392 if (eep_config
.termination_lvd
== 1) {
11393 asc_dvc
->cfg
->termination
= termination
;
11395 /* Enable manual control with low off / high on. */
11396 } else if (eep_config
.termination_lvd
== 2) {
11397 asc_dvc
->cfg
->termination
= termination
| TERM_LVD_HI
;
11399 /* Enable manual control with low on / high on. */
11400 } else if (eep_config
.termination_lvd
== 3) {
11401 asc_dvc
->cfg
->termination
= termination
| TERM_LVD
;
11404 * The EEPROM 'termination_lvd' field contains a bad value.
11405 * Use automatic termination instead.
11407 asc_dvc
->cfg
->termination
= termination
;
11408 warn_code
|= ASC_WARN_EEPROM_TERMINATION
;
11416 * Read the board's EEPROM configuration. Set fields in ASC_DVC_VAR and
11417 * ASC_DVC_CFG based on the EEPROM settings. The chip is stopped while
11418 * all of this is done.
11420 * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
11422 * For a non-fatal error return a warning code. If there are no warnings
11423 * then 0 is returned.
11425 * Note: Chip is stopped on entry.
11427 static int __devinit
AdvInitFrom38C1600EEP(ADV_DVC_VAR
*asc_dvc
)
11429 AdvPortAddr iop_base
;
11431 ADVEEP_38C1600_CONFIG eep_config
;
11432 uchar tid
, termination
;
11433 ushort sdtr_speed
= 0;
11435 iop_base
= asc_dvc
->iop_base
;
11440 * Read the board's EEPROM configuration.
11442 * Set default values if a bad checksum is found.
11444 if (AdvGet38C1600EEPConfig(iop_base
, &eep_config
) !=
11445 eep_config
.check_sum
) {
11446 struct pci_dev
*pdev
= adv_dvc_to_pdev(asc_dvc
);
11447 warn_code
|= ASC_WARN_EEPROM_CHKSUM
;
11450 * Set EEPROM default values.
11452 memcpy(&eep_config
, &Default_38C1600_EEPROM_Config
,
11453 sizeof(ADVEEP_38C1600_CONFIG
));
11455 if (PCI_FUNC(pdev
->devfn
) != 0) {
11458 * Disable Bit 14 (BIOS_ENABLE) to fix SPARC Ultra 60
11459 * and old Mac system booting problem. The Expansion
11460 * ROM must be disabled in Function 1 for these systems
11462 eep_config
.cfg_lsw
&= ~ADV_EEPROM_BIOS_ENABLE
;
11464 * Clear the INTAB (bit 11) if the GPIO 0 input
11465 * indicates the Function 1 interrupt line is wired
11468 * Set/Clear Bit 11 (INTAB) from the GPIO bit 0 input:
11469 * 1 - Function 1 interrupt line wired to INT A.
11470 * 0 - Function 1 interrupt line wired to INT B.
11472 * Note: Function 0 is always wired to INTA.
11473 * Put all 5 GPIO bits in input mode and then read
11474 * their input values.
11476 AdvWriteByteRegister(iop_base
, IOPB_GPIO_CNTL
, 0);
11477 ints
= AdvReadByteRegister(iop_base
, IOPB_GPIO_DATA
);
11478 if ((ints
& 0x01) == 0)
11479 eep_config
.cfg_lsw
&= ~ADV_EEPROM_INTAB
;
11483 * Assume the 6 byte board serial number that was read from
11484 * EEPROM is correct even if the EEPROM checksum failed.
11486 eep_config
.serial_number_word3
=
11487 AdvReadEEPWord(iop_base
, ADV_EEP_DVC_CFG_END
- 1);
11488 eep_config
.serial_number_word2
=
11489 AdvReadEEPWord(iop_base
, ADV_EEP_DVC_CFG_END
- 2);
11490 eep_config
.serial_number_word1
=
11491 AdvReadEEPWord(iop_base
, ADV_EEP_DVC_CFG_END
- 3);
11493 AdvSet38C1600EEPConfig(iop_base
, &eep_config
);
11497 * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
11498 * EEPROM configuration that was read.
11500 * This is the mapping of EEPROM fields to Adv Library fields.
11502 asc_dvc
->wdtr_able
= eep_config
.wdtr_able
;
11503 asc_dvc
->sdtr_speed1
= eep_config
.sdtr_speed1
;
11504 asc_dvc
->sdtr_speed2
= eep_config
.sdtr_speed2
;
11505 asc_dvc
->sdtr_speed3
= eep_config
.sdtr_speed3
;
11506 asc_dvc
->sdtr_speed4
= eep_config
.sdtr_speed4
;
11507 asc_dvc
->ppr_able
= 0;
11508 asc_dvc
->tagqng_able
= eep_config
.tagqng_able
;
11509 asc_dvc
->cfg
->disc_enable
= eep_config
.disc_enable
;
11510 asc_dvc
->max_host_qng
= eep_config
.max_host_qng
;
11511 asc_dvc
->max_dvc_qng
= eep_config
.max_dvc_qng
;
11512 asc_dvc
->chip_scsi_id
= (eep_config
.adapter_scsi_id
& ASC_MAX_TID
);
11513 asc_dvc
->start_motor
= eep_config
.start_motor
;
11514 asc_dvc
->scsi_reset_wait
= eep_config
.scsi_reset_delay
;
11515 asc_dvc
->bios_ctrl
= eep_config
.bios_ctrl
;
11516 asc_dvc
->no_scam
= eep_config
.scam_tolerant
;
11519 * For every Target ID if any of its 'sdtr_speed[1234]' bits
11520 * are set, then set an 'sdtr_able' bit for it.
11522 asc_dvc
->sdtr_able
= 0;
11523 for (tid
= 0; tid
<= ASC_MAX_TID
; tid
++) {
11525 sdtr_speed
= asc_dvc
->sdtr_speed1
;
11526 } else if (tid
== 4) {
11527 sdtr_speed
= asc_dvc
->sdtr_speed2
;
11528 } else if (tid
== 8) {
11529 sdtr_speed
= asc_dvc
->sdtr_speed3
;
11530 } else if (tid
== 12) {
11531 sdtr_speed
= asc_dvc
->sdtr_speed4
;
11533 if (sdtr_speed
& ASC_MAX_TID
) {
11534 asc_dvc
->sdtr_able
|= (1 << tid
);
11540 * Set the host maximum queuing (max. 253, min. 16) and the per device
11541 * maximum queuing (max. 63, min. 4).
11543 if (eep_config
.max_host_qng
> ASC_DEF_MAX_HOST_QNG
) {
11544 eep_config
.max_host_qng
= ASC_DEF_MAX_HOST_QNG
;
11545 } else if (eep_config
.max_host_qng
< ASC_DEF_MIN_HOST_QNG
) {
11546 /* If the value is zero, assume it is uninitialized. */
11547 if (eep_config
.max_host_qng
== 0) {
11548 eep_config
.max_host_qng
= ASC_DEF_MAX_HOST_QNG
;
11550 eep_config
.max_host_qng
= ASC_DEF_MIN_HOST_QNG
;
11554 if (eep_config
.max_dvc_qng
> ASC_DEF_MAX_DVC_QNG
) {
11555 eep_config
.max_dvc_qng
= ASC_DEF_MAX_DVC_QNG
;
11556 } else if (eep_config
.max_dvc_qng
< ASC_DEF_MIN_DVC_QNG
) {
11557 /* If the value is zero, assume it is uninitialized. */
11558 if (eep_config
.max_dvc_qng
== 0) {
11559 eep_config
.max_dvc_qng
= ASC_DEF_MAX_DVC_QNG
;
11561 eep_config
.max_dvc_qng
= ASC_DEF_MIN_DVC_QNG
;
11566 * If 'max_dvc_qng' is greater than 'max_host_qng', then
11567 * set 'max_dvc_qng' to 'max_host_qng'.
11569 if (eep_config
.max_dvc_qng
> eep_config
.max_host_qng
) {
11570 eep_config
.max_dvc_qng
= eep_config
.max_host_qng
;
11574 * Set ASC_DVC_VAR 'max_host_qng' and ASC_DVC_VAR 'max_dvc_qng'
11575 * values based on possibly adjusted EEPROM values.
11577 asc_dvc
->max_host_qng
= eep_config
.max_host_qng
;
11578 asc_dvc
->max_dvc_qng
= eep_config
.max_dvc_qng
;
11581 * If the EEPROM 'termination' field is set to automatic (0), then set
11582 * the ASC_DVC_CFG 'termination' field to automatic also.
11584 * If the termination is specified with a non-zero 'termination'
11585 * value check that a legal value is set and set the ASC_DVC_CFG
11586 * 'termination' field appropriately.
11588 if (eep_config
.termination_se
== 0) {
11589 termination
= 0; /* auto termination for SE */
11591 /* Enable manual control with low off / high off. */
11592 if (eep_config
.termination_se
== 1) {
11595 /* Enable manual control with low off / high on. */
11596 } else if (eep_config
.termination_se
== 2) {
11597 termination
= TERM_SE_HI
;
11599 /* Enable manual control with low on / high on. */
11600 } else if (eep_config
.termination_se
== 3) {
11601 termination
= TERM_SE
;
11604 * The EEPROM 'termination_se' field contains a bad value.
11605 * Use automatic termination instead.
11608 warn_code
|= ASC_WARN_EEPROM_TERMINATION
;
11612 if (eep_config
.termination_lvd
== 0) {
11613 asc_dvc
->cfg
->termination
= termination
; /* auto termination for LVD */
11615 /* Enable manual control with low off / high off. */
11616 if (eep_config
.termination_lvd
== 1) {
11617 asc_dvc
->cfg
->termination
= termination
;
11619 /* Enable manual control with low off / high on. */
11620 } else if (eep_config
.termination_lvd
== 2) {
11621 asc_dvc
->cfg
->termination
= termination
| TERM_LVD_HI
;
11623 /* Enable manual control with low on / high on. */
11624 } else if (eep_config
.termination_lvd
== 3) {
11625 asc_dvc
->cfg
->termination
= termination
| TERM_LVD
;
11628 * The EEPROM 'termination_lvd' field contains a bad value.
11629 * Use automatic termination instead.
11631 asc_dvc
->cfg
->termination
= termination
;
11632 warn_code
|= ASC_WARN_EEPROM_TERMINATION
;
11640 * Initialize the ADV_DVC_VAR structure.
11642 * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
11644 * For a non-fatal error return a warning code. If there are no warnings
11645 * then 0 is returned.
11647 static int __devinit
11648 AdvInitGetConfig(struct pci_dev
*pdev
, struct Scsi_Host
*shost
)
11650 struct asc_board
*board
= shost_priv(shost
);
11651 ADV_DVC_VAR
*asc_dvc
= &board
->dvc_var
.adv_dvc_var
;
11652 unsigned short warn_code
= 0;
11653 AdvPortAddr iop_base
= asc_dvc
->iop_base
;
11657 asc_dvc
->err_code
= 0;
11660 * Save the state of the PCI Configuration Command Register
11661 * "Parity Error Response Control" Bit. If the bit is clear (0),
11662 * in AdvInitAsc3550/38C0800Driver() tell the microcode to ignore
11663 * DMA parity errors.
11665 asc_dvc
->cfg
->control_flag
= 0;
11666 pci_read_config_word(pdev
, PCI_COMMAND
, &cmd
);
11667 if ((cmd
& PCI_COMMAND_PARITY
) == 0)
11668 asc_dvc
->cfg
->control_flag
|= CONTROL_FLAG_IGNORE_PERR
;
11670 asc_dvc
->cfg
->chip_version
=
11671 AdvGetChipVersion(iop_base
, asc_dvc
->bus_type
);
11673 ASC_DBG(1, "iopb_chip_id_1: 0x%x 0x%x\n",
11674 (ushort
)AdvReadByteRegister(iop_base
, IOPB_CHIP_ID_1
),
11675 (ushort
)ADV_CHIP_ID_BYTE
);
11677 ASC_DBG(1, "iopw_chip_id_0: 0x%x 0x%x\n",
11678 (ushort
)AdvReadWordRegister(iop_base
, IOPW_CHIP_ID_0
),
11679 (ushort
)ADV_CHIP_ID_WORD
);
11682 * Reset the chip to start and allow register writes.
11684 if (AdvFindSignature(iop_base
) == 0) {
11685 asc_dvc
->err_code
= ASC_IERR_BAD_SIGNATURE
;
11689 * The caller must set 'chip_type' to a valid setting.
11691 if (asc_dvc
->chip_type
!= ADV_CHIP_ASC3550
&&
11692 asc_dvc
->chip_type
!= ADV_CHIP_ASC38C0800
&&
11693 asc_dvc
->chip_type
!= ADV_CHIP_ASC38C1600
) {
11694 asc_dvc
->err_code
|= ASC_IERR_BAD_CHIPTYPE
;
11701 AdvWriteWordRegister(iop_base
, IOPW_CTRL_REG
,
11702 ADV_CTRL_REG_CMD_RESET
);
11704 AdvWriteWordRegister(iop_base
, IOPW_CTRL_REG
,
11705 ADV_CTRL_REG_CMD_WR_IO_REG
);
11707 if (asc_dvc
->chip_type
== ADV_CHIP_ASC38C1600
) {
11708 status
= AdvInitFrom38C1600EEP(asc_dvc
);
11709 } else if (asc_dvc
->chip_type
== ADV_CHIP_ASC38C0800
) {
11710 status
= AdvInitFrom38C0800EEP(asc_dvc
);
11712 status
= AdvInitFrom3550EEP(asc_dvc
);
11714 warn_code
|= status
;
11717 if (warn_code
!= 0)
11718 shost_printk(KERN_WARNING
, shost
, "warning: 0x%x\n", warn_code
);
11720 if (asc_dvc
->err_code
)
11721 shost_printk(KERN_ERR
, shost
, "error code 0x%x\n",
11722 asc_dvc
->err_code
);
11724 return asc_dvc
->err_code
;
11728 static struct scsi_host_template advansys_template
= {
11729 .proc_name
= DRV_NAME
,
11730 #ifdef CONFIG_PROC_FS
11731 .proc_info
= advansys_proc_info
,
11734 .info
= advansys_info
,
11735 .queuecommand
= advansys_queuecommand
,
11736 .eh_bus_reset_handler
= advansys_reset
,
11737 .bios_param
= advansys_biosparam
,
11738 .slave_configure
= advansys_slave_configure
,
11740 * Because the driver may control an ISA adapter 'unchecked_isa_dma'
11741 * must be set. The flag will be cleared in advansys_board_found
11742 * for non-ISA adapters.
11744 .unchecked_isa_dma
= 1,
11746 * All adapters controlled by this driver are capable of large
11747 * scatter-gather lists. According to the mid-level SCSI documentation
11748 * this obviates any performance gain provided by setting
11749 * 'use_clustering'. But empirically while CPU utilization is increased
11750 * by enabling clustering, I/O throughput increases as well.
11752 .use_clustering
= ENABLE_CLUSTERING
,
11755 static int __devinit
advansys_wide_init_chip(struct Scsi_Host
*shost
)
11757 struct asc_board
*board
= shost_priv(shost
);
11758 struct adv_dvc_var
*adv_dvc
= &board
->dvc_var
.adv_dvc_var
;
11760 adv_req_t
*reqp
= NULL
;
11763 int warn_code
, err_code
;
11766 * Allocate buffer carrier structures. The total size
11767 * is about 4 KB, so allocate all at once.
11769 adv_dvc
->carrier_buf
= kmalloc(ADV_CARRIER_BUFSIZE
, GFP_KERNEL
);
11770 ASC_DBG(1, "carrier_buf 0x%p\n", adv_dvc
->carrier_buf
);
11772 if (!adv_dvc
->carrier_buf
)
11773 goto kmalloc_failed
;
11776 * Allocate up to 'max_host_qng' request structures for the Wide
11777 * board. The total size is about 16 KB, so allocate all at once.
11778 * If the allocation fails decrement and try again.
11780 for (req_cnt
= adv_dvc
->max_host_qng
; req_cnt
> 0; req_cnt
--) {
11781 reqp
= kmalloc(sizeof(adv_req_t
) * req_cnt
, GFP_KERNEL
);
11783 ASC_DBG(1, "reqp 0x%p, req_cnt %d, bytes %lu\n", reqp
, req_cnt
,
11784 (ulong
)sizeof(adv_req_t
) * req_cnt
);
11791 goto kmalloc_failed
;
11793 adv_dvc
->orig_reqp
= reqp
;
11796 * Allocate up to ADV_TOT_SG_BLOCK request structures for
11797 * the Wide board. Each structure is about 136 bytes.
11799 board
->adv_sgblkp
= NULL
;
11800 for (sg_cnt
= 0; sg_cnt
< ADV_TOT_SG_BLOCK
; sg_cnt
++) {
11801 sgp
= kmalloc(sizeof(adv_sgblk_t
), GFP_KERNEL
);
11806 sgp
->next_sgblkp
= board
->adv_sgblkp
;
11807 board
->adv_sgblkp
= sgp
;
11811 ASC_DBG(1, "sg_cnt %d * %lu = %lu bytes\n", sg_cnt
, sizeof(adv_sgblk_t
),
11812 sizeof(adv_sgblk_t
) * sg_cnt
);
11814 if (!board
->adv_sgblkp
)
11815 goto kmalloc_failed
;
11818 * Point 'adv_reqp' to the request structures and
11819 * link them together.
11822 reqp
[req_cnt
].next_reqp
= NULL
;
11823 for (; req_cnt
> 0; req_cnt
--) {
11824 reqp
[req_cnt
- 1].next_reqp
= &reqp
[req_cnt
];
11826 board
->adv_reqp
= &reqp
[0];
11828 if (adv_dvc
->chip_type
== ADV_CHIP_ASC3550
) {
11829 ASC_DBG(2, "AdvInitAsc3550Driver()\n");
11830 warn_code
= AdvInitAsc3550Driver(adv_dvc
);
11831 } else if (adv_dvc
->chip_type
== ADV_CHIP_ASC38C0800
) {
11832 ASC_DBG(2, "AdvInitAsc38C0800Driver()\n");
11833 warn_code
= AdvInitAsc38C0800Driver(adv_dvc
);
11835 ASC_DBG(2, "AdvInitAsc38C1600Driver()\n");
11836 warn_code
= AdvInitAsc38C1600Driver(adv_dvc
);
11838 err_code
= adv_dvc
->err_code
;
11840 if (warn_code
|| err_code
) {
11841 shost_printk(KERN_WARNING
, shost
, "error: warn 0x%x, error "
11842 "0x%x\n", warn_code
, err_code
);
11848 shost_printk(KERN_ERR
, shost
, "error: kmalloc() failed\n");
11849 err_code
= ADV_ERROR
;
11854 static void advansys_wide_free_mem(struct asc_board
*board
)
11856 struct adv_dvc_var
*adv_dvc
= &board
->dvc_var
.adv_dvc_var
;
11857 kfree(adv_dvc
->carrier_buf
);
11858 adv_dvc
->carrier_buf
= NULL
;
11859 kfree(adv_dvc
->orig_reqp
);
11860 adv_dvc
->orig_reqp
= board
->adv_reqp
= NULL
;
11861 while (board
->adv_sgblkp
) {
11862 adv_sgblk_t
*sgp
= board
->adv_sgblkp
;
11863 board
->adv_sgblkp
= sgp
->next_sgblkp
;
11868 static int __devinit
advansys_board_found(struct Scsi_Host
*shost
,
11869 unsigned int iop
, int bus_type
)
11871 struct pci_dev
*pdev
;
11872 struct asc_board
*boardp
= shost_priv(shost
);
11873 ASC_DVC_VAR
*asc_dvc_varp
= NULL
;
11874 ADV_DVC_VAR
*adv_dvc_varp
= NULL
;
11875 int share_irq
, warn_code
, ret
;
11877 pdev
= (bus_type
== ASC_IS_PCI
) ? to_pci_dev(boardp
->dev
) : NULL
;
11879 if (ASC_NARROW_BOARD(boardp
)) {
11880 ASC_DBG(1, "narrow board\n");
11881 asc_dvc_varp
= &boardp
->dvc_var
.asc_dvc_var
;
11882 asc_dvc_varp
->bus_type
= bus_type
;
11883 asc_dvc_varp
->drv_ptr
= boardp
;
11884 asc_dvc_varp
->cfg
= &boardp
->dvc_cfg
.asc_dvc_cfg
;
11885 asc_dvc_varp
->iop_base
= iop
;
11888 adv_dvc_varp
= &boardp
->dvc_var
.adv_dvc_var
;
11889 adv_dvc_varp
->drv_ptr
= boardp
;
11890 adv_dvc_varp
->cfg
= &boardp
->dvc_cfg
.adv_dvc_cfg
;
11891 if (pdev
->device
== PCI_DEVICE_ID_ASP_ABP940UW
) {
11892 ASC_DBG(1, "wide board ASC-3550\n");
11893 adv_dvc_varp
->chip_type
= ADV_CHIP_ASC3550
;
11894 } else if (pdev
->device
== PCI_DEVICE_ID_38C0800_REV1
) {
11895 ASC_DBG(1, "wide board ASC-38C0800\n");
11896 adv_dvc_varp
->chip_type
= ADV_CHIP_ASC38C0800
;
11898 ASC_DBG(1, "wide board ASC-38C1600\n");
11899 adv_dvc_varp
->chip_type
= ADV_CHIP_ASC38C1600
;
11902 boardp
->asc_n_io_port
= pci_resource_len(pdev
, 1);
11903 boardp
->ioremap_addr
= pci_ioremap_bar(pdev
, 1);
11904 if (!boardp
->ioremap_addr
) {
11905 shost_printk(KERN_ERR
, shost
, "ioremap(%lx, %d) "
11907 (long)pci_resource_start(pdev
, 1),
11908 boardp
->asc_n_io_port
);
11912 adv_dvc_varp
->iop_base
= (AdvPortAddr
)boardp
->ioremap_addr
;
11913 ASC_DBG(1, "iop_base: 0x%p\n", adv_dvc_varp
->iop_base
);
11916 * Even though it isn't used to access wide boards, other
11917 * than for the debug line below, save I/O Port address so
11918 * that it can be reported.
11920 boardp
->ioport
= iop
;
11922 ASC_DBG(1, "iopb_chip_id_1 0x%x, iopw_chip_id_0 0x%x\n",
11923 (ushort
)inp(iop
+ 1), (ushort
)inpw(iop
));
11924 #endif /* CONFIG_PCI */
11927 #ifdef CONFIG_PROC_FS
11929 * Allocate buffer for printing information from
11930 * /proc/scsi/advansys/[0...].
11932 boardp
->prtbuf
= kmalloc(ASC_PRTBUF_SIZE
, GFP_KERNEL
);
11933 if (!boardp
->prtbuf
) {
11934 shost_printk(KERN_ERR
, shost
, "kmalloc(%d) returned NULL\n",
11939 #endif /* CONFIG_PROC_FS */
11941 if (ASC_NARROW_BOARD(boardp
)) {
11943 * Set the board bus type and PCI IRQ before
11944 * calling AscInitGetConfig().
11946 switch (asc_dvc_varp
->bus_type
) {
11949 shost
->unchecked_isa_dma
= TRUE
;
11953 shost
->unchecked_isa_dma
= FALSE
;
11957 shost
->unchecked_isa_dma
= FALSE
;
11958 share_irq
= IRQF_SHARED
;
11960 #endif /* CONFIG_ISA */
11963 shost
->unchecked_isa_dma
= FALSE
;
11964 share_irq
= IRQF_SHARED
;
11966 #endif /* CONFIG_PCI */
11968 shost_printk(KERN_ERR
, shost
, "unknown adapter type: "
11969 "%d\n", asc_dvc_varp
->bus_type
);
11970 shost
->unchecked_isa_dma
= TRUE
;
11976 * NOTE: AscInitGetConfig() may change the board's
11977 * bus_type value. The bus_type value should no
11978 * longer be used. If the bus_type field must be
11979 * referenced only use the bit-wise AND operator "&".
11981 ASC_DBG(2, "AscInitGetConfig()\n");
11982 ret
= AscInitGetConfig(shost
) ? -ENODEV
: 0;
11986 * For Wide boards set PCI information before calling
11987 * AdvInitGetConfig().
11989 shost
->unchecked_isa_dma
= FALSE
;
11990 share_irq
= IRQF_SHARED
;
11991 ASC_DBG(2, "AdvInitGetConfig()\n");
11993 ret
= AdvInitGetConfig(pdev
, shost
) ? -ENODEV
: 0;
11994 #endif /* CONFIG_PCI */
11998 goto err_free_proc
;
12001 * Save the EEPROM configuration so that it can be displayed
12002 * from /proc/scsi/advansys/[0...].
12004 if (ASC_NARROW_BOARD(boardp
)) {
12009 * Set the adapter's target id bit in the 'init_tidmask' field.
12011 boardp
->init_tidmask
|=
12012 ADV_TID_TO_TIDMASK(asc_dvc_varp
->cfg
->chip_scsi_id
);
12015 * Save EEPROM settings for the board.
12017 ep
= &boardp
->eep_config
.asc_eep
;
12019 ep
->init_sdtr
= asc_dvc_varp
->cfg
->sdtr_enable
;
12020 ep
->disc_enable
= asc_dvc_varp
->cfg
->disc_enable
;
12021 ep
->use_cmd_qng
= asc_dvc_varp
->cfg
->cmd_qng_enabled
;
12022 ASC_EEP_SET_DMA_SPD(ep
, asc_dvc_varp
->cfg
->isa_dma_speed
);
12023 ep
->start_motor
= asc_dvc_varp
->start_motor
;
12024 ep
->cntl
= asc_dvc_varp
->dvc_cntl
;
12025 ep
->no_scam
= asc_dvc_varp
->no_scam
;
12026 ep
->max_total_qng
= asc_dvc_varp
->max_total_qng
;
12027 ASC_EEP_SET_CHIP_ID(ep
, asc_dvc_varp
->cfg
->chip_scsi_id
);
12028 /* 'max_tag_qng' is set to the same value for every device. */
12029 ep
->max_tag_qng
= asc_dvc_varp
->cfg
->max_tag_qng
[0];
12030 ep
->adapter_info
[0] = asc_dvc_varp
->cfg
->adapter_info
[0];
12031 ep
->adapter_info
[1] = asc_dvc_varp
->cfg
->adapter_info
[1];
12032 ep
->adapter_info
[2] = asc_dvc_varp
->cfg
->adapter_info
[2];
12033 ep
->adapter_info
[3] = asc_dvc_varp
->cfg
->adapter_info
[3];
12034 ep
->adapter_info
[4] = asc_dvc_varp
->cfg
->adapter_info
[4];
12035 ep
->adapter_info
[5] = asc_dvc_varp
->cfg
->adapter_info
[5];
12038 * Modify board configuration.
12040 ASC_DBG(2, "AscInitSetConfig()\n");
12041 ret
= AscInitSetConfig(pdev
, shost
) ? -ENODEV
: 0;
12043 goto err_free_proc
;
12045 ADVEEP_3550_CONFIG
*ep_3550
;
12046 ADVEEP_38C0800_CONFIG
*ep_38C0800
;
12047 ADVEEP_38C1600_CONFIG
*ep_38C1600
;
12050 * Save Wide EEP Configuration Information.
12052 if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC3550
) {
12053 ep_3550
= &boardp
->eep_config
.adv_3550_eep
;
12055 ep_3550
->adapter_scsi_id
= adv_dvc_varp
->chip_scsi_id
;
12056 ep_3550
->max_host_qng
= adv_dvc_varp
->max_host_qng
;
12057 ep_3550
->max_dvc_qng
= adv_dvc_varp
->max_dvc_qng
;
12058 ep_3550
->termination
= adv_dvc_varp
->cfg
->termination
;
12059 ep_3550
->disc_enable
= adv_dvc_varp
->cfg
->disc_enable
;
12060 ep_3550
->bios_ctrl
= adv_dvc_varp
->bios_ctrl
;
12061 ep_3550
->wdtr_able
= adv_dvc_varp
->wdtr_able
;
12062 ep_3550
->sdtr_able
= adv_dvc_varp
->sdtr_able
;
12063 ep_3550
->ultra_able
= adv_dvc_varp
->ultra_able
;
12064 ep_3550
->tagqng_able
= adv_dvc_varp
->tagqng_able
;
12065 ep_3550
->start_motor
= adv_dvc_varp
->start_motor
;
12066 ep_3550
->scsi_reset_delay
=
12067 adv_dvc_varp
->scsi_reset_wait
;
12068 ep_3550
->serial_number_word1
=
12069 adv_dvc_varp
->cfg
->serial1
;
12070 ep_3550
->serial_number_word2
=
12071 adv_dvc_varp
->cfg
->serial2
;
12072 ep_3550
->serial_number_word3
=
12073 adv_dvc_varp
->cfg
->serial3
;
12074 } else if (adv_dvc_varp
->chip_type
== ADV_CHIP_ASC38C0800
) {
12075 ep_38C0800
= &boardp
->eep_config
.adv_38C0800_eep
;
12077 ep_38C0800
->adapter_scsi_id
=
12078 adv_dvc_varp
->chip_scsi_id
;
12079 ep_38C0800
->max_host_qng
= adv_dvc_varp
->max_host_qng
;
12080 ep_38C0800
->max_dvc_qng
= adv_dvc_varp
->max_dvc_qng
;
12081 ep_38C0800
->termination_lvd
=
12082 adv_dvc_varp
->cfg
->termination
;
12083 ep_38C0800
->disc_enable
=
12084 adv_dvc_varp
->cfg
->disc_enable
;
12085 ep_38C0800
->bios_ctrl
= adv_dvc_varp
->bios_ctrl
;
12086 ep_38C0800
->wdtr_able
= adv_dvc_varp
->wdtr_able
;
12087 ep_38C0800
->tagqng_able
= adv_dvc_varp
->tagqng_able
;
12088 ep_38C0800
->sdtr_speed1
= adv_dvc_varp
->sdtr_speed1
;
12089 ep_38C0800
->sdtr_speed2
= adv_dvc_varp
->sdtr_speed2
;
12090 ep_38C0800
->sdtr_speed3
= adv_dvc_varp
->sdtr_speed3
;
12091 ep_38C0800
->sdtr_speed4
= adv_dvc_varp
->sdtr_speed4
;
12092 ep_38C0800
->tagqng_able
= adv_dvc_varp
->tagqng_able
;
12093 ep_38C0800
->start_motor
= adv_dvc_varp
->start_motor
;
12094 ep_38C0800
->scsi_reset_delay
=
12095 adv_dvc_varp
->scsi_reset_wait
;
12096 ep_38C0800
->serial_number_word1
=
12097 adv_dvc_varp
->cfg
->serial1
;
12098 ep_38C0800
->serial_number_word2
=
12099 adv_dvc_varp
->cfg
->serial2
;
12100 ep_38C0800
->serial_number_word3
=
12101 adv_dvc_varp
->cfg
->serial3
;
12103 ep_38C1600
= &boardp
->eep_config
.adv_38C1600_eep
;
12105 ep_38C1600
->adapter_scsi_id
=
12106 adv_dvc_varp
->chip_scsi_id
;
12107 ep_38C1600
->max_host_qng
= adv_dvc_varp
->max_host_qng
;
12108 ep_38C1600
->max_dvc_qng
= adv_dvc_varp
->max_dvc_qng
;
12109 ep_38C1600
->termination_lvd
=
12110 adv_dvc_varp
->cfg
->termination
;
12111 ep_38C1600
->disc_enable
=
12112 adv_dvc_varp
->cfg
->disc_enable
;
12113 ep_38C1600
->bios_ctrl
= adv_dvc_varp
->bios_ctrl
;
12114 ep_38C1600
->wdtr_able
= adv_dvc_varp
->wdtr_able
;
12115 ep_38C1600
->tagqng_able
= adv_dvc_varp
->tagqng_able
;
12116 ep_38C1600
->sdtr_speed1
= adv_dvc_varp
->sdtr_speed1
;
12117 ep_38C1600
->sdtr_speed2
= adv_dvc_varp
->sdtr_speed2
;
12118 ep_38C1600
->sdtr_speed3
= adv_dvc_varp
->sdtr_speed3
;
12119 ep_38C1600
->sdtr_speed4
= adv_dvc_varp
->sdtr_speed4
;
12120 ep_38C1600
->tagqng_able
= adv_dvc_varp
->tagqng_able
;
12121 ep_38C1600
->start_motor
= adv_dvc_varp
->start_motor
;
12122 ep_38C1600
->scsi_reset_delay
=
12123 adv_dvc_varp
->scsi_reset_wait
;
12124 ep_38C1600
->serial_number_word1
=
12125 adv_dvc_varp
->cfg
->serial1
;
12126 ep_38C1600
->serial_number_word2
=
12127 adv_dvc_varp
->cfg
->serial2
;
12128 ep_38C1600
->serial_number_word3
=
12129 adv_dvc_varp
->cfg
->serial3
;
12133 * Set the adapter's target id bit in the 'init_tidmask' field.
12135 boardp
->init_tidmask
|=
12136 ADV_TID_TO_TIDMASK(adv_dvc_varp
->chip_scsi_id
);
12140 * Channels are numbered beginning with 0. For AdvanSys one host
12141 * structure supports one channel. Multi-channel boards have a
12142 * separate host structure for each channel.
12144 shost
->max_channel
= 0;
12145 if (ASC_NARROW_BOARD(boardp
)) {
12146 shost
->max_id
= ASC_MAX_TID
+ 1;
12147 shost
->max_lun
= ASC_MAX_LUN
+ 1;
12148 shost
->max_cmd_len
= ASC_MAX_CDB_LEN
;
12150 shost
->io_port
= asc_dvc_varp
->iop_base
;
12151 boardp
->asc_n_io_port
= ASC_IOADR_GAP
;
12152 shost
->this_id
= asc_dvc_varp
->cfg
->chip_scsi_id
;
12154 /* Set maximum number of queues the adapter can handle. */
12155 shost
->can_queue
= asc_dvc_varp
->max_total_qng
;
12157 shost
->max_id
= ADV_MAX_TID
+ 1;
12158 shost
->max_lun
= ADV_MAX_LUN
+ 1;
12159 shost
->max_cmd_len
= ADV_MAX_CDB_LEN
;
12162 * Save the I/O Port address and length even though
12163 * I/O ports are not used to access Wide boards.
12164 * Instead the Wide boards are accessed with
12165 * PCI Memory Mapped I/O.
12167 shost
->io_port
= iop
;
12169 shost
->this_id
= adv_dvc_varp
->chip_scsi_id
;
12171 /* Set maximum number of queues the adapter can handle. */
12172 shost
->can_queue
= adv_dvc_varp
->max_host_qng
;
12176 * Following v1.3.89, 'cmd_per_lun' is no longer needed
12177 * and should be set to zero.
12179 * But because of a bug introduced in v1.3.89 if the driver is
12180 * compiled as a module and 'cmd_per_lun' is zero, the Mid-Level
12181 * SCSI function 'allocate_device' will panic. To allow the driver
12182 * to work as a module in these kernels set 'cmd_per_lun' to 1.
12184 * Note: This is wrong. cmd_per_lun should be set to the depth
12185 * you want on untagged devices always.
12188 shost
->cmd_per_lun
= 1;
12190 shost->cmd_per_lun = 0;
12194 * Set the maximum number of scatter-gather elements the
12195 * adapter can handle.
12197 if (ASC_NARROW_BOARD(boardp
)) {
12199 * Allow two commands with 'sg_tablesize' scatter-gather
12200 * elements to be executed simultaneously. This value is
12201 * the theoretical hardware limit. It may be decreased
12204 shost
->sg_tablesize
=
12205 (((asc_dvc_varp
->max_total_qng
- 2) / 2) *
12206 ASC_SG_LIST_PER_Q
) + 1;
12208 shost
->sg_tablesize
= ADV_MAX_SG_LIST
;
12212 * The value of 'sg_tablesize' can not exceed the SCSI
12213 * mid-level driver definition of SG_ALL. SG_ALL also
12214 * must not be exceeded, because it is used to define the
12215 * size of the scatter-gather table in 'struct asc_sg_head'.
12217 if (shost
->sg_tablesize
> SG_ALL
) {
12218 shost
->sg_tablesize
= SG_ALL
;
12221 ASC_DBG(1, "sg_tablesize: %d\n", shost
->sg_tablesize
);
12223 /* BIOS start address. */
12224 if (ASC_NARROW_BOARD(boardp
)) {
12225 shost
->base
= AscGetChipBiosAddress(asc_dvc_varp
->iop_base
,
12226 asc_dvc_varp
->bus_type
);
12229 * Fill-in BIOS board variables. The Wide BIOS saves
12230 * information in LRAM that is used by the driver.
12232 AdvReadWordLram(adv_dvc_varp
->iop_base
,
12233 BIOS_SIGNATURE
, boardp
->bios_signature
);
12234 AdvReadWordLram(adv_dvc_varp
->iop_base
,
12235 BIOS_VERSION
, boardp
->bios_version
);
12236 AdvReadWordLram(adv_dvc_varp
->iop_base
,
12237 BIOS_CODESEG
, boardp
->bios_codeseg
);
12238 AdvReadWordLram(adv_dvc_varp
->iop_base
,
12239 BIOS_CODELEN
, boardp
->bios_codelen
);
12241 ASC_DBG(1, "bios_signature 0x%x, bios_version 0x%x\n",
12242 boardp
->bios_signature
, boardp
->bios_version
);
12244 ASC_DBG(1, "bios_codeseg 0x%x, bios_codelen 0x%x\n",
12245 boardp
->bios_codeseg
, boardp
->bios_codelen
);
12248 * If the BIOS saved a valid signature, then fill in
12249 * the BIOS code segment base address.
12251 if (boardp
->bios_signature
== 0x55AA) {
12253 * Convert x86 realmode code segment to a linear
12254 * address by shifting left 4.
12256 shost
->base
= ((ulong
)boardp
->bios_codeseg
<< 4);
12263 * Register Board Resources - I/O Port, DMA, IRQ
12266 /* Register DMA Channel for Narrow boards. */
12267 shost
->dma_channel
= NO_ISA_DMA
; /* Default to no ISA DMA. */
12269 if (ASC_NARROW_BOARD(boardp
)) {
12270 /* Register DMA channel for ISA bus. */
12271 if (asc_dvc_varp
->bus_type
& ASC_IS_ISA
) {
12272 shost
->dma_channel
= asc_dvc_varp
->cfg
->isa_dma_channel
;
12273 ret
= request_dma(shost
->dma_channel
, DRV_NAME
);
12275 shost_printk(KERN_ERR
, shost
, "request_dma() "
12277 shost
->dma_channel
, ret
);
12278 goto err_free_proc
;
12280 AscEnableIsaDma(shost
->dma_channel
);
12283 #endif /* CONFIG_ISA */
12285 /* Register IRQ Number. */
12286 ASC_DBG(2, "request_irq(%d, %p)\n", boardp
->irq
, shost
);
12288 ret
= request_irq(boardp
->irq
, advansys_interrupt
, share_irq
,
12292 if (ret
== -EBUSY
) {
12293 shost_printk(KERN_ERR
, shost
, "request_irq(): IRQ 0x%x "
12294 "already in use\n", boardp
->irq
);
12295 } else if (ret
== -EINVAL
) {
12296 shost_printk(KERN_ERR
, shost
, "request_irq(): IRQ 0x%x "
12297 "not valid\n", boardp
->irq
);
12299 shost_printk(KERN_ERR
, shost
, "request_irq(): IRQ 0x%x "
12300 "failed with %d\n", boardp
->irq
, ret
);
12306 * Initialize board RISC chip and enable interrupts.
12308 if (ASC_NARROW_BOARD(boardp
)) {
12309 ASC_DBG(2, "AscInitAsc1000Driver()\n");
12311 asc_dvc_varp
->overrun_buf
= kzalloc(ASC_OVERRUN_BSIZE
, GFP_KERNEL
);
12312 if (!asc_dvc_varp
->overrun_buf
) {
12314 goto err_free_wide_mem
;
12316 warn_code
= AscInitAsc1000Driver(asc_dvc_varp
);
12318 if (warn_code
|| asc_dvc_varp
->err_code
) {
12319 shost_printk(KERN_ERR
, shost
, "error: init_state 0x%x, "
12320 "warn 0x%x, error 0x%x\n",
12321 asc_dvc_varp
->init_state
, warn_code
,
12322 asc_dvc_varp
->err_code
);
12323 if (asc_dvc_varp
->err_code
) {
12325 kfree(asc_dvc_varp
->overrun_buf
);
12329 if (advansys_wide_init_chip(shost
))
12334 goto err_free_wide_mem
;
12336 ASC_DBG_PRT_SCSI_HOST(2, shost
);
12338 ret
= scsi_add_host(shost
, boardp
->dev
);
12340 goto err_free_wide_mem
;
12342 scsi_scan_host(shost
);
12346 advansys_wide_free_mem(boardp
);
12347 free_irq(boardp
->irq
, shost
);
12350 if (shost
->dma_channel
!= NO_ISA_DMA
)
12351 free_dma(shost
->dma_channel
);
12354 kfree(boardp
->prtbuf
);
12356 if (boardp
->ioremap_addr
)
12357 iounmap(boardp
->ioremap_addr
);
12363 * advansys_release()
12365 * Release resources allocated for a single AdvanSys adapter.
12367 static int advansys_release(struct Scsi_Host
*shost
)
12369 struct asc_board
*board
= shost_priv(shost
);
12370 ASC_DBG(1, "begin\n");
12371 scsi_remove_host(shost
);
12372 free_irq(board
->irq
, shost
);
12374 if (shost
->dma_channel
!= NO_ISA_DMA
) {
12375 ASC_DBG(1, "free_dma()\n");
12376 free_dma(shost
->dma_channel
);
12379 if (ASC_NARROW_BOARD(board
)) {
12380 dma_unmap_single(board
->dev
,
12381 board
->dvc_var
.asc_dvc_var
.overrun_dma
,
12382 ASC_OVERRUN_BSIZE
, DMA_FROM_DEVICE
);
12383 kfree(board
->dvc_var
.asc_dvc_var
.overrun_buf
);
12385 iounmap(board
->ioremap_addr
);
12386 advansys_wide_free_mem(board
);
12388 kfree(board
->prtbuf
);
12389 scsi_host_put(shost
);
12390 ASC_DBG(1, "end\n");
12394 #define ASC_IOADR_TABLE_MAX_IX 11
12396 static PortAddr _asc_def_iop_base
[ASC_IOADR_TABLE_MAX_IX
] = {
12397 0x100, 0x0110, 0x120, 0x0130, 0x140, 0x0150, 0x0190,
12398 0x0210, 0x0230, 0x0250, 0x0330
12402 * The ISA IRQ number is found in bits 2 and 3 of the CfgLsw. It decodes as:
12408 static unsigned int __devinit
advansys_isa_irq_no(PortAddr iop_base
)
12410 unsigned short cfg_lsw
= AscGetChipCfgLsw(iop_base
);
12411 unsigned int chip_irq
= ((cfg_lsw
>> 2) & 0x03) + 10;
12412 if (chip_irq
== 13)
12417 static int __devinit
advansys_isa_probe(struct device
*dev
, unsigned int id
)
12420 PortAddr iop_base
= _asc_def_iop_base
[id
];
12421 struct Scsi_Host
*shost
;
12422 struct asc_board
*board
;
12424 if (!request_region(iop_base
, ASC_IOADR_GAP
, DRV_NAME
)) {
12425 ASC_DBG(1, "I/O port 0x%x busy\n", iop_base
);
12428 ASC_DBG(1, "probing I/O port 0x%x\n", iop_base
);
12429 if (!AscFindSignature(iop_base
))
12430 goto release_region
;
12431 if (!(AscGetChipVersion(iop_base
, ASC_IS_ISA
) & ASC_CHIP_VER_ISA_BIT
))
12432 goto release_region
;
12435 shost
= scsi_host_alloc(&advansys_template
, sizeof(*board
));
12437 goto release_region
;
12439 board
= shost_priv(shost
);
12440 board
->irq
= advansys_isa_irq_no(iop_base
);
12443 err
= advansys_board_found(shost
, iop_base
, ASC_IS_ISA
);
12447 dev_set_drvdata(dev
, shost
);
12451 scsi_host_put(shost
);
12453 release_region(iop_base
, ASC_IOADR_GAP
);
12457 static int __devexit
advansys_isa_remove(struct device
*dev
, unsigned int id
)
12459 int ioport
= _asc_def_iop_base
[id
];
12460 advansys_release(dev_get_drvdata(dev
));
12461 release_region(ioport
, ASC_IOADR_GAP
);
12465 static struct isa_driver advansys_isa_driver
= {
12466 .probe
= advansys_isa_probe
,
12467 .remove
= __devexit_p(advansys_isa_remove
),
12469 .owner
= THIS_MODULE
,
12475 * The VLB IRQ number is found in bits 2 to 4 of the CfgLsw. It decodes as:
12485 static unsigned int __devinit
advansys_vlb_irq_no(PortAddr iop_base
)
12487 unsigned short cfg_lsw
= AscGetChipCfgLsw(iop_base
);
12488 unsigned int chip_irq
= ((cfg_lsw
>> 2) & 0x07) + 9;
12489 if ((chip_irq
< 10) || (chip_irq
== 13) || (chip_irq
> 15))
12494 static int __devinit
advansys_vlb_probe(struct device
*dev
, unsigned int id
)
12497 PortAddr iop_base
= _asc_def_iop_base
[id
];
12498 struct Scsi_Host
*shost
;
12499 struct asc_board
*board
;
12501 if (!request_region(iop_base
, ASC_IOADR_GAP
, DRV_NAME
)) {
12502 ASC_DBG(1, "I/O port 0x%x busy\n", iop_base
);
12505 ASC_DBG(1, "probing I/O port 0x%x\n", iop_base
);
12506 if (!AscFindSignature(iop_base
))
12507 goto release_region
;
12509 * I don't think this condition can actually happen, but the old
12510 * driver did it, and the chances of finding a VLB setup in 2007
12511 * to do testing with is slight to none.
12513 if (AscGetChipVersion(iop_base
, ASC_IS_VL
) > ASC_CHIP_MAX_VER_VL
)
12514 goto release_region
;
12517 shost
= scsi_host_alloc(&advansys_template
, sizeof(*board
));
12519 goto release_region
;
12521 board
= shost_priv(shost
);
12522 board
->irq
= advansys_vlb_irq_no(iop_base
);
12525 err
= advansys_board_found(shost
, iop_base
, ASC_IS_VL
);
12529 dev_set_drvdata(dev
, shost
);
12533 scsi_host_put(shost
);
12535 release_region(iop_base
, ASC_IOADR_GAP
);
12539 static struct isa_driver advansys_vlb_driver
= {
12540 .probe
= advansys_vlb_probe
,
12541 .remove
= __devexit_p(advansys_isa_remove
),
12543 .owner
= THIS_MODULE
,
12544 .name
= "advansys_vlb",
12548 static struct eisa_device_id advansys_eisa_table
[] __devinitdata
= {
12554 MODULE_DEVICE_TABLE(eisa
, advansys_eisa_table
);
12557 * EISA is a little more tricky than PCI; each EISA device may have two
12558 * channels, and this driver is written to make each channel its own Scsi_Host
12560 struct eisa_scsi_data
{
12561 struct Scsi_Host
*host
[2];
12565 * The EISA IRQ number is found in bits 8 to 10 of the CfgLsw. It decodes as:
12575 static unsigned int __devinit
advansys_eisa_irq_no(struct eisa_device
*edev
)
12577 unsigned short cfg_lsw
= inw(edev
->base_addr
+ 0xc86);
12578 unsigned int chip_irq
= ((cfg_lsw
>> 8) & 0x07) + 10;
12579 if ((chip_irq
== 13) || (chip_irq
> 15))
12584 static int __devinit
advansys_eisa_probe(struct device
*dev
)
12586 int i
, ioport
, irq
= 0;
12588 struct eisa_device
*edev
= to_eisa_device(dev
);
12589 struct eisa_scsi_data
*data
;
12592 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
12595 ioport
= edev
->base_addr
+ 0xc30;
12598 for (i
= 0; i
< 2; i
++, ioport
+= 0x20) {
12599 struct asc_board
*board
;
12600 struct Scsi_Host
*shost
;
12601 if (!request_region(ioport
, ASC_IOADR_GAP
, DRV_NAME
)) {
12602 printk(KERN_WARNING
"Region %x-%x busy\n", ioport
,
12603 ioport
+ ASC_IOADR_GAP
- 1);
12606 if (!AscFindSignature(ioport
)) {
12607 release_region(ioport
, ASC_IOADR_GAP
);
12612 * I don't know why we need to do this for EISA chips, but
12613 * not for any others. It looks to be equivalent to
12614 * AscGetChipCfgMsw, but I may have overlooked something,
12615 * so I'm not converting it until I get an EISA board to
12621 irq
= advansys_eisa_irq_no(edev
);
12624 shost
= scsi_host_alloc(&advansys_template
, sizeof(*board
));
12626 goto release_region
;
12628 board
= shost_priv(shost
);
12632 err
= advansys_board_found(shost
, ioport
, ASC_IS_EISA
);
12634 data
->host
[i
] = shost
;
12638 scsi_host_put(shost
);
12640 release_region(ioport
, ASC_IOADR_GAP
);
12646 dev_set_drvdata(dev
, data
);
12650 kfree(data
->host
[0]);
12651 kfree(data
->host
[1]);
12657 static __devexit
int advansys_eisa_remove(struct device
*dev
)
12660 struct eisa_scsi_data
*data
= dev_get_drvdata(dev
);
12662 for (i
= 0; i
< 2; i
++) {
12664 struct Scsi_Host
*shost
= data
->host
[i
];
12667 ioport
= shost
->io_port
;
12668 advansys_release(shost
);
12669 release_region(ioport
, ASC_IOADR_GAP
);
12676 static struct eisa_driver advansys_eisa_driver
= {
12677 .id_table
= advansys_eisa_table
,
12680 .probe
= advansys_eisa_probe
,
12681 .remove
= __devexit_p(advansys_eisa_remove
),
12685 /* PCI Devices supported by this driver */
12686 static struct pci_device_id advansys_pci_tbl
[] __devinitdata
= {
12687 {PCI_VENDOR_ID_ASP
, PCI_DEVICE_ID_ASP_1200A
,
12688 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
12689 {PCI_VENDOR_ID_ASP
, PCI_DEVICE_ID_ASP_ABP940
,
12690 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
12691 {PCI_VENDOR_ID_ASP
, PCI_DEVICE_ID_ASP_ABP940U
,
12692 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
12693 {PCI_VENDOR_ID_ASP
, PCI_DEVICE_ID_ASP_ABP940UW
,
12694 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
12695 {PCI_VENDOR_ID_ASP
, PCI_DEVICE_ID_38C0800_REV1
,
12696 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
12697 {PCI_VENDOR_ID_ASP
, PCI_DEVICE_ID_38C1600_REV1
,
12698 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
12702 MODULE_DEVICE_TABLE(pci
, advansys_pci_tbl
);
12704 static void __devinit
advansys_set_latency(struct pci_dev
*pdev
)
12706 if ((pdev
->device
== PCI_DEVICE_ID_ASP_1200A
) ||
12707 (pdev
->device
== PCI_DEVICE_ID_ASP_ABP940
)) {
12708 pci_write_config_byte(pdev
, PCI_LATENCY_TIMER
, 0);
12711 pci_read_config_byte(pdev
, PCI_LATENCY_TIMER
, &latency
);
12712 if (latency
< 0x20)
12713 pci_write_config_byte(pdev
, PCI_LATENCY_TIMER
, 0x20);
12717 static int __devinit
12718 advansys_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
12721 struct Scsi_Host
*shost
;
12722 struct asc_board
*board
;
12724 err
= pci_enable_device(pdev
);
12727 err
= pci_request_regions(pdev
, DRV_NAME
);
12729 goto disable_device
;
12730 pci_set_master(pdev
);
12731 advansys_set_latency(pdev
);
12734 if (pci_resource_len(pdev
, 0) == 0)
12735 goto release_region
;
12737 ioport
= pci_resource_start(pdev
, 0);
12740 shost
= scsi_host_alloc(&advansys_template
, sizeof(*board
));
12742 goto release_region
;
12744 board
= shost_priv(shost
);
12745 board
->irq
= pdev
->irq
;
12746 board
->dev
= &pdev
->dev
;
12748 if (pdev
->device
== PCI_DEVICE_ID_ASP_ABP940UW
||
12749 pdev
->device
== PCI_DEVICE_ID_38C0800_REV1
||
12750 pdev
->device
== PCI_DEVICE_ID_38C1600_REV1
) {
12751 board
->flags
|= ASC_IS_WIDE_BOARD
;
12754 err
= advansys_board_found(shost
, ioport
, ASC_IS_PCI
);
12758 pci_set_drvdata(pdev
, shost
);
12762 scsi_host_put(shost
);
12764 pci_release_regions(pdev
);
12766 pci_disable_device(pdev
);
12771 static void __devexit
advansys_pci_remove(struct pci_dev
*pdev
)
12773 advansys_release(pci_get_drvdata(pdev
));
12774 pci_release_regions(pdev
);
12775 pci_disable_device(pdev
);
12778 static struct pci_driver advansys_pci_driver
= {
12780 .id_table
= advansys_pci_tbl
,
12781 .probe
= advansys_pci_probe
,
12782 .remove
= __devexit_p(advansys_pci_remove
),
12785 static int __init
advansys_init(void)
12789 error
= isa_register_driver(&advansys_isa_driver
,
12790 ASC_IOADR_TABLE_MAX_IX
);
12794 error
= isa_register_driver(&advansys_vlb_driver
,
12795 ASC_IOADR_TABLE_MAX_IX
);
12797 goto unregister_isa
;
12799 error
= eisa_driver_register(&advansys_eisa_driver
);
12801 goto unregister_vlb
;
12803 error
= pci_register_driver(&advansys_pci_driver
);
12805 goto unregister_eisa
;
12810 eisa_driver_unregister(&advansys_eisa_driver
);
12812 isa_unregister_driver(&advansys_vlb_driver
);
12814 isa_unregister_driver(&advansys_isa_driver
);
12819 static void __exit
advansys_exit(void)
12821 pci_unregister_driver(&advansys_pci_driver
);
12822 eisa_driver_unregister(&advansys_eisa_driver
);
12823 isa_unregister_driver(&advansys_vlb_driver
);
12824 isa_unregister_driver(&advansys_isa_driver
);
12827 module_init(advansys_init
);
12828 module_exit(advansys_exit
);
12830 MODULE_LICENSE("GPL");
12831 MODULE_FIRMWARE("advansys/mcode.bin");
12832 MODULE_FIRMWARE("advansys/3550.bin");
12833 MODULE_FIRMWARE("advansys/38C0800.bin");
12834 MODULE_FIRMWARE("advansys/38C1600.bin");