2 * Device driver for the SYMBIOS/LSILOGIC 53C8XX and 53C1010 family
3 * of PCI-SCSI IO processors.
5 * Copyright (C) 1999-2001 Gerard Roudier <groudier@free.fr>
6 * Copyright (c) 2003-2005 Matthew Wilcox <matthew@wil.cx>
8 * This driver is derived from the Linux sym53c8xx driver.
9 * Copyright (C) 1998-2000 Gerard Roudier
11 * The sym53c8xx driver is derived from the ncr53c8xx driver that had been
12 * a port of the FreeBSD ncr driver to Linux-1.2.13.
14 * The original ncr driver has been written for 386bsd and FreeBSD by
15 * Wolfgang Stanglmeier <wolf@cologne.de>
16 * Stefan Esser <se@mi.Uni-Koeln.de>
17 * Copyright (C) 1994 Wolfgang Stanglmeier
19 * Other major contributions:
21 * NVRAM detection and reading.
22 * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
24 *-----------------------------------------------------------------------------
26 * This program is free software; you can redistribute it and/or modify
27 * it under the terms of the GNU General Public License as published by
28 * the Free Software Foundation; either version 2 of the License, or
29 * (at your option) any later version.
31 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU General Public License for more details.
36 * You should have received a copy of the GNU General Public License
37 * along with this program; if not, write to the Free Software
38 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
40 #include <linux/ctype.h>
41 #include <linux/init.h>
42 #include <linux/interrupt.h>
43 #include <linux/module.h>
44 #include <linux/moduleparam.h>
45 #include <linux/spinlock.h>
46 #include <scsi/scsi.h>
47 #include <scsi/scsi_tcq.h>
48 #include <scsi/scsi_device.h>
49 #include <scsi/scsi_transport.h>
52 #include "sym_nvram.h"
54 #define NAME53C "sym53c"
55 #define NAME53C8XX "sym53c8xx"
58 #define IRQ_PRM(x) (x)
60 struct sym_driver_setup sym_driver_setup
= SYM_LINUX_DRIVER_SETUP
;
61 unsigned int sym_debug_flags
= 0;
63 static char *excl_string
;
64 static char *safe_string
;
65 module_param_named(cmd_per_lun
, sym_driver_setup
.max_tag
, ushort
, 0);
66 module_param_named(burst
, sym_driver_setup
.burst_order
, byte
, 0);
67 module_param_named(led
, sym_driver_setup
.scsi_led
, byte
, 0);
68 module_param_named(diff
, sym_driver_setup
.scsi_diff
, byte
, 0);
69 module_param_named(irqm
, sym_driver_setup
.irq_mode
, byte
, 0);
70 module_param_named(buschk
, sym_driver_setup
.scsi_bus_check
, byte
, 0);
71 module_param_named(hostid
, sym_driver_setup
.host_id
, byte
, 0);
72 module_param_named(verb
, sym_driver_setup
.verbose
, byte
, 0);
73 module_param_named(debug
, sym_debug_flags
, uint
, 0);
74 module_param_named(settle
, sym_driver_setup
.settle_delay
, byte
, 0);
75 module_param_named(nvram
, sym_driver_setup
.use_nvram
, byte
, 0);
76 module_param_named(excl
, excl_string
, charp
, 0);
77 module_param_named(safe
, safe_string
, charp
, 0);
79 MODULE_PARM_DESC(cmd_per_lun
, "The maximum number of tags to use by default");
80 MODULE_PARM_DESC(burst
, "Maximum burst. 0 to disable, 255 to read from registers");
81 MODULE_PARM_DESC(led
, "Set to 1 to enable LED support");
82 MODULE_PARM_DESC(diff
, "0 for no differential mode, 1 for BIOS, 2 for always, 3 for not GPIO3");
83 MODULE_PARM_DESC(irqm
, "0 for open drain, 1 to leave alone, 2 for totem pole");
84 MODULE_PARM_DESC(buschk
, "0 to not check, 1 for detach on error, 2 for warn on error");
85 MODULE_PARM_DESC(hostid
, "The SCSI ID to use for the host adapters");
86 MODULE_PARM_DESC(verb
, "0 for minimal verbosity, 1 for normal, 2 for excessive");
87 MODULE_PARM_DESC(debug
, "Set bits to enable debugging");
88 MODULE_PARM_DESC(settle
, "Settle delay in seconds. Default 3");
89 MODULE_PARM_DESC(nvram
, "Option currently not used");
90 MODULE_PARM_DESC(excl
, "List ioport addresses here to prevent controllers from being attached");
91 MODULE_PARM_DESC(safe
, "Set other settings to a \"safe mode\"");
93 MODULE_LICENSE("GPL");
94 MODULE_VERSION(SYM_VERSION
);
95 MODULE_AUTHOR("Matthew Wilcox <matthew@wil.cx>");
96 MODULE_DESCRIPTION("NCR, Symbios and LSI 8xx and 1010 PCI SCSI adapters");
98 static void sym2_setup_params(void)
100 char *p
= excl_string
;
103 while (p
&& (xi
< 8)) {
105 int val
= (int) simple_strtoul(p
, &next_p
, 0);
106 sym_driver_setup
.excludes
[xi
++] = val
;
111 if (*safe_string
== 'y') {
112 sym_driver_setup
.max_tag
= 0;
113 sym_driver_setup
.burst_order
= 0;
114 sym_driver_setup
.scsi_led
= 0;
115 sym_driver_setup
.scsi_diff
= 1;
116 sym_driver_setup
.irq_mode
= 0;
117 sym_driver_setup
.scsi_bus_check
= 2;
118 sym_driver_setup
.host_id
= 7;
119 sym_driver_setup
.verbose
= 2;
120 sym_driver_setup
.settle_delay
= 10;
121 sym_driver_setup
.use_nvram
= 1;
122 } else if (*safe_string
!= 'n') {
123 printk(KERN_WARNING NAME53C8XX
"Ignoring parameter %s"
124 " passed to safe option", safe_string
);
129 static struct scsi_transport_template
*sym2_transport_template
= NULL
;
132 * Driver private area in the SCSI command structure.
134 struct sym_ucmd
{ /* Override the SCSI pointer structure */
135 struct completion
*eh_done
; /* SCSI error handling */
138 #define SYM_UCMD_PTR(cmd) ((struct sym_ucmd *)(&(cmd)->SCp))
139 #define SYM_SOFTC_PTR(cmd) sym_get_hcb(cmd->device->host)
142 * Complete a pending CAM CCB.
144 void sym_xpt_done(struct sym_hcb
*np
, struct scsi_cmnd
*cmd
)
146 struct sym_ucmd
*ucmd
= SYM_UCMD_PTR(cmd
);
147 BUILD_BUG_ON(sizeof(struct scsi_pointer
) < sizeof(struct sym_ucmd
));
150 complete(ucmd
->eh_done
);
157 * Tell the SCSI layer about a BUS RESET.
159 void sym_xpt_async_bus_reset(struct sym_hcb
*np
)
161 printf_notice("%s: SCSI BUS has been reset.\n", sym_name(np
));
162 np
->s
.settle_time
= jiffies
+ sym_driver_setup
.settle_delay
* HZ
;
163 np
->s
.settle_time_valid
= 1;
164 if (sym_verbose
>= 2)
165 printf_info("%s: command processing suspended for %d seconds\n",
166 sym_name(np
), sym_driver_setup
.settle_delay
);
170 * Tell the SCSI layer about a BUS DEVICE RESET message sent.
172 void sym_xpt_async_sent_bdr(struct sym_hcb
*np
, int target
)
174 printf_notice("%s: TARGET %d has been reset.\n", sym_name(np
), target
);
178 * Choose the more appropriate CAM status if
179 * the IO encountered an extended error.
181 static int sym_xerr_cam_status(int cam_status
, int x_status
)
184 if (x_status
& XE_PARITY_ERR
)
185 cam_status
= DID_PARITY
;
186 else if (x_status
&(XE_EXTRA_DATA
|XE_SODL_UNRUN
|XE_SWIDE_OVRUN
))
187 cam_status
= DID_ERROR
;
188 else if (x_status
& XE_BAD_PHASE
)
189 cam_status
= DID_ERROR
;
191 cam_status
= DID_ERROR
;
197 * Build CAM result for a failed or auto-sensed IO.
199 void sym_set_cam_result_error(struct sym_hcb
*np
, struct sym_ccb
*cp
, int resid
)
201 struct scsi_cmnd
*cmd
= cp
->cmd
;
202 u_int cam_status
, scsi_status
, drv_status
;
206 scsi_status
= cp
->ssss_status
;
208 if (cp
->host_flags
& HF_SENSE
) {
209 scsi_status
= cp
->sv_scsi_status
;
210 resid
= cp
->sv_resid
;
211 if (sym_verbose
&& cp
->sv_xerr_status
)
212 sym_print_xerr(cmd
, cp
->sv_xerr_status
);
213 if (cp
->host_status
== HS_COMPLETE
&&
214 cp
->ssss_status
== S_GOOD
&&
215 cp
->xerr_status
== 0) {
216 cam_status
= sym_xerr_cam_status(DID_OK
,
218 drv_status
= DRIVER_SENSE
;
220 * Bounce back the sense data to user.
222 memset(&cmd
->sense_buffer
, 0, sizeof(cmd
->sense_buffer
));
223 memcpy(cmd
->sense_buffer
, cp
->sns_bbuf
,
224 min(sizeof(cmd
->sense_buffer
),
225 (size_t)SYM_SNS_BBUF_LEN
));
228 * If the device reports a UNIT ATTENTION condition
229 * due to a RESET condition, we should consider all
230 * disconnect CCBs for this unit as aborted.
234 p
= (u_char
*) cmd
->sense_data
;
235 if (p
[0]==0x70 && p
[2]==0x6 && p
[12]==0x29)
236 sym_clear_tasks(np
, DID_ABORT
,
237 cp
->target
,cp
->lun
, -1);
242 * Error return from our internal request sense. This
243 * is bad: we must clear the contingent allegiance
244 * condition otherwise the device will always return
245 * BUSY. Use a big stick.
247 sym_reset_scsi_target(np
, cmd
->device
->id
);
248 cam_status
= DID_ERROR
;
250 } else if (cp
->host_status
== HS_COMPLETE
) /* Bad SCSI status */
252 else if (cp
->host_status
== HS_SEL_TIMEOUT
) /* Selection timeout */
253 cam_status
= DID_NO_CONNECT
;
254 else if (cp
->host_status
== HS_UNEXPECTED
) /* Unexpected BUS FREE*/
255 cam_status
= DID_ERROR
;
256 else { /* Extended error */
258 sym_print_addr(cmd
, "COMMAND FAILED (%x %x %x).\n",
259 cp
->host_status
, cp
->ssss_status
,
263 * Set the most appropriate value for CAM status.
265 cam_status
= sym_xerr_cam_status(DID_ERROR
, cp
->xerr_status
);
267 scsi_set_resid(cmd
, resid
);
268 cmd
->result
= (drv_status
<< 24) + (cam_status
<< 16) + scsi_status
;
271 static int sym_scatter(struct sym_hcb
*np
, struct sym_ccb
*cp
, struct scsi_cmnd
*cmd
)
278 use_sg
= scsi_dma_map(cmd
);
280 struct scatterlist
*sg
;
281 struct sym_tcb
*tp
= &np
->target
[cp
->target
];
282 struct sym_tblmove
*data
;
284 if (use_sg
> SYM_CONF_MAX_SG
) {
289 data
= &cp
->phys
.data
[SYM_CONF_MAX_SG
- use_sg
];
291 scsi_for_each_sg(cmd
, sg
, use_sg
, segment
) {
292 dma_addr_t baddr
= sg_dma_address(sg
);
293 unsigned int len
= sg_dma_len(sg
);
295 if ((len
& 1) && (tp
->head
.wval
& EWS
)) {
297 cp
->odd_byte_adjustment
++;
300 sym_build_sge(np
, &data
[segment
], baddr
, len
);
311 * Queue a SCSI command.
313 static int sym_queue_command(struct sym_hcb
*np
, struct scsi_cmnd
*cmd
)
315 struct scsi_device
*sdev
= cmd
->device
;
322 * Retrieve the target descriptor.
324 tp
= &np
->target
[sdev
->id
];
327 * Select tagged/untagged.
329 lp
= sym_lp(tp
, sdev
->lun
);
330 order
= (lp
&& lp
->s
.reqtags
) ? M_SIMPLE_TAG
: 0;
335 cp
= sym_get_ccb(np
, cmd
, order
);
337 return 1; /* Means resource shortage */
338 sym_queue_scsiio(np
, cmd
, cp
);
343 * Setup buffers and pointers that address the CDB.
345 static inline int sym_setup_cdb(struct sym_hcb
*np
, struct scsi_cmnd
*cmd
, struct sym_ccb
*cp
)
347 memcpy(cp
->cdb_buf
, cmd
->cmnd
, cmd
->cmd_len
);
349 cp
->phys
.cmd
.addr
= CCB_BA(cp
, cdb_buf
[0]);
350 cp
->phys
.cmd
.size
= cpu_to_scr(cmd
->cmd_len
);
356 * Setup pointers that address the data and start the I/O.
358 int sym_setup_data_and_start(struct sym_hcb
*np
, struct scsi_cmnd
*cmd
, struct sym_ccb
*cp
)
366 if (sym_setup_cdb(np
, cmd
, cp
))
370 * No direction means no data.
372 dir
= cmd
->sc_data_direction
;
373 if (dir
!= DMA_NONE
) {
374 cp
->segments
= sym_scatter(np
, cp
, cmd
);
375 if (cp
->segments
< 0) {
376 sym_set_cam_status(cmd
, DID_ERROR
);
381 * No segments means no data.
391 * Set the data pointer.
394 case DMA_BIDIRECTIONAL
:
395 scmd_printk(KERN_INFO
, cmd
, "got DMA_BIDIRECTIONAL command");
396 sym_set_cam_status(cmd
, DID_ERROR
);
399 goalp
= SCRIPTA_BA(np
, data_out2
) + 8;
400 lastp
= goalp
- 8 - (cp
->segments
* (2*4));
402 case DMA_FROM_DEVICE
:
403 cp
->host_flags
|= HF_DATA_IN
;
404 goalp
= SCRIPTA_BA(np
, data_in2
) + 8;
405 lastp
= goalp
- 8 - (cp
->segments
* (2*4));
409 lastp
= goalp
= SCRIPTB_BA(np
, no_data
);
414 * Set all pointers values needed by SCRIPTS.
416 cp
->phys
.head
.lastp
= cpu_to_scr(lastp
);
417 cp
->phys
.head
.savep
= cpu_to_scr(lastp
);
418 cp
->startp
= cp
->phys
.head
.savep
;
419 cp
->goalp
= cpu_to_scr(goalp
);
422 * When `#ifed 1', the code below makes the driver
423 * panic on the first attempt to write to a SCSI device.
424 * It is the first test we want to do after a driver
425 * change that does not seem obviously safe. :)
428 switch (cp
->cdb_buf
[0]) {
429 case 0x0A: case 0x2A: case 0xAA:
430 panic("XXXXXXXXXXXXX WRITE NOT YET ALLOWED XXXXXXXXXXXXXX\n");
440 sym_put_start_queue(np
, cp
);
444 sym_free_ccb(np
, cp
);
445 sym_xpt_done(np
, cmd
);
453 * Misused to keep the driver running when
454 * interrupts are not configured correctly.
456 static void sym_timer(struct sym_hcb
*np
)
458 unsigned long thistime
= jiffies
;
463 np
->s
.timer
.expires
= thistime
+ SYM_CONF_TIMER_INTERVAL
;
464 add_timer(&np
->s
.timer
);
467 * If we are resetting the ncr, wait for settle_time before
468 * clearing it. Then command processing will be resumed.
470 if (np
->s
.settle_time_valid
) {
471 if (time_before_eq(np
->s
.settle_time
, thistime
)) {
472 if (sym_verbose
>= 2 )
473 printk("%s: command processing resumed\n",
475 np
->s
.settle_time_valid
= 0;
481 * Nothing to do for now, but that may come.
483 if (np
->s
.lasttime
+ 4*HZ
< thistime
) {
484 np
->s
.lasttime
= thistime
;
487 #ifdef SYM_CONF_PCIQ_MAY_MISS_COMPLETIONS
489 * Some way-broken PCI bridges may lead to
490 * completions being lost when the clearing
491 * of the INTFLY flag by the CPU occurs
492 * concurrently with the chip raising this flag.
493 * If this ever happen, lost completions will
502 * PCI BUS error handler.
504 void sym_log_bus_error(struct sym_hcb
*np
)
507 pci_read_config_word(np
->s
.device
, PCI_STATUS
, &pci_sts
);
508 if (pci_sts
& 0xf900) {
509 pci_write_config_word(np
->s
.device
, PCI_STATUS
, pci_sts
);
510 printf("%s: PCI STATUS = 0x%04x\n",
511 sym_name(np
), pci_sts
& 0xf900);
516 * queuecommand method. Entered with the host adapter lock held and
517 * interrupts disabled.
519 static int sym53c8xx_queue_command(struct scsi_cmnd
*cmd
,
520 void (*done
)(struct scsi_cmnd
*))
522 struct sym_hcb
*np
= SYM_SOFTC_PTR(cmd
);
523 struct sym_ucmd
*ucp
= SYM_UCMD_PTR(cmd
);
526 cmd
->scsi_done
= done
;
527 memset(ucp
, 0, sizeof(*ucp
));
530 * Shorten our settle_time if needed for
531 * this command not to time out.
533 if (np
->s
.settle_time_valid
&& cmd
->timeout_per_command
) {
534 unsigned long tlimit
= jiffies
+ cmd
->timeout_per_command
;
535 tlimit
-= SYM_CONF_TIMER_INTERVAL
*2;
536 if (time_after(np
->s
.settle_time
, tlimit
)) {
537 np
->s
.settle_time
= tlimit
;
541 if (np
->s
.settle_time_valid
)
542 return SCSI_MLQUEUE_HOST_BUSY
;
544 sts
= sym_queue_command(np
, cmd
);
546 return SCSI_MLQUEUE_HOST_BUSY
;
551 * Linux entry point of the interrupt handler.
553 static irqreturn_t
sym53c8xx_intr(int irq
, void *dev_id
)
555 struct sym_hcb
*np
= dev_id
;
557 /* Avoid spinloop trying to handle interrupts on frozen device */
558 if (pci_channel_offline(np
->s
.device
))
561 if (DEBUG_FLAGS
& DEBUG_TINY
) printf_debug ("[");
563 spin_lock(np
->s
.host
->host_lock
);
565 spin_unlock(np
->s
.host
->host_lock
);
567 if (DEBUG_FLAGS
& DEBUG_TINY
) printf_debug ("]\n");
573 * Linux entry point of the timer handler
575 static void sym53c8xx_timer(unsigned long npref
)
577 struct sym_hcb
*np
= (struct sym_hcb
*)npref
;
580 spin_lock_irqsave(np
->s
.host
->host_lock
, flags
);
582 spin_unlock_irqrestore(np
->s
.host
->host_lock
, flags
);
587 * What the eh thread wants us to perform.
589 #define SYM_EH_ABORT 0
590 #define SYM_EH_DEVICE_RESET 1
591 #define SYM_EH_BUS_RESET 2
592 #define SYM_EH_HOST_RESET 3
595 * Generic method for our eh processing.
596 * The 'op' argument tells what we have to do.
598 static int sym_eh_handler(int op
, char *opname
, struct scsi_cmnd
*cmd
)
600 struct sym_hcb
*np
= SYM_SOFTC_PTR(cmd
);
601 struct sym_ucmd
*ucmd
= SYM_UCMD_PTR(cmd
);
602 struct Scsi_Host
*host
= cmd
->device
->host
;
603 struct pci_dev
*pdev
= np
->s
.device
;
607 struct completion eh_done
;
609 scmd_printk(KERN_WARNING
, cmd
, "%s operation started.\n", opname
);
611 /* We may be in an error condition because the PCI bus
612 * went down. In this case, we need to wait until the
613 * PCI bus is reset, the card is reset, and only then
614 * proceed with the scsi error recovery. There's no
615 * point in hurrying; take a leisurely wait.
617 #define WAIT_FOR_PCI_RECOVERY 35
618 if (pci_channel_offline(pdev
)) {
619 struct host_data
*hostdata
= shost_priv(host
);
620 struct completion
*io_reset
;
621 int finished_reset
= 0;
622 init_completion(&eh_done
);
623 spin_lock_irq(host
->host_lock
);
624 /* Make sure we didn't race */
625 if (pci_channel_offline(pdev
)) {
626 if (!hostdata
->io_reset
)
627 hostdata
->io_reset
= &eh_done
;
628 io_reset
= hostdata
->io_reset
;
633 if (!pci_channel_offline(pdev
))
635 spin_unlock_irq(host
->host_lock
);
637 finished_reset
= wait_for_completion_timeout(io_reset
,
638 WAIT_FOR_PCI_RECOVERY
*HZ
);
643 spin_lock_irq(host
->host_lock
);
644 /* This one is queued in some place -> to wait for completion */
645 FOR_EACH_QUEUED_ELEMENT(&np
->busy_ccbq
, qp
) {
646 struct sym_ccb
*cp
= sym_que_entry(qp
, struct sym_ccb
, link_ccbq
);
647 if (cp
->cmd
== cmd
) {
653 /* Try to proceed the operation we have been asked for */
657 sts
= sym_abort_scsiio(np
, cmd
, 1);
659 case SYM_EH_DEVICE_RESET
:
660 sts
= sym_reset_scsi_target(np
, cmd
->device
->id
);
662 case SYM_EH_BUS_RESET
:
663 sym_reset_scsi_bus(np
, 1);
666 case SYM_EH_HOST_RESET
:
667 sym_reset_scsi_bus(np
, 0);
675 /* On error, restore everything and cross fingers :) */
680 init_completion(&eh_done
);
681 ucmd
->eh_done
= &eh_done
;
682 spin_unlock_irq(host
->host_lock
);
683 if (!wait_for_completion_timeout(&eh_done
, 5*HZ
)) {
684 ucmd
->eh_done
= NULL
;
688 spin_unlock_irq(host
->host_lock
);
691 dev_warn(&cmd
->device
->sdev_gendev
, "%s operation %s.\n", opname
,
692 sts
==0 ? "complete" :sts
==-2 ? "timed-out" : "failed");
693 return sts
? SCSI_FAILED
: SCSI_SUCCESS
;
698 * Error handlers called from the eh thread (one thread per HBA).
700 static int sym53c8xx_eh_abort_handler(struct scsi_cmnd
*cmd
)
702 return sym_eh_handler(SYM_EH_ABORT
, "ABORT", cmd
);
705 static int sym53c8xx_eh_device_reset_handler(struct scsi_cmnd
*cmd
)
707 return sym_eh_handler(SYM_EH_DEVICE_RESET
, "DEVICE RESET", cmd
);
710 static int sym53c8xx_eh_bus_reset_handler(struct scsi_cmnd
*cmd
)
712 return sym_eh_handler(SYM_EH_BUS_RESET
, "BUS RESET", cmd
);
715 static int sym53c8xx_eh_host_reset_handler(struct scsi_cmnd
*cmd
)
717 return sym_eh_handler(SYM_EH_HOST_RESET
, "HOST RESET", cmd
);
721 * Tune device queuing depth, according to various limits.
723 static void sym_tune_dev_queuing(struct sym_tcb
*tp
, int lun
, u_short reqtags
)
725 struct sym_lcb
*lp
= sym_lp(tp
, lun
);
731 oldtags
= lp
->s
.reqtags
;
733 if (reqtags
> lp
->s
.scdev_depth
)
734 reqtags
= lp
->s
.scdev_depth
;
736 lp
->s
.reqtags
= reqtags
;
738 if (reqtags
!= oldtags
) {
739 dev_info(&tp
->starget
->dev
,
740 "tagged command queuing %s, command queue depth %d.\n",
741 lp
->s
.reqtags
? "enabled" : "disabled", reqtags
);
745 static int sym53c8xx_slave_alloc(struct scsi_device
*sdev
)
747 struct sym_hcb
*np
= sym_get_hcb(sdev
->host
);
748 struct sym_tcb
*tp
= &np
->target
[sdev
->id
];
751 if (sdev
->id
>= SYM_CONF_MAX_TARGET
|| sdev
->lun
>= SYM_CONF_MAX_LUN
)
754 tp
->starget
= sdev
->sdev_target
;
756 * Fail the device init if the device is flagged NOSCAN at BOOT in
757 * the NVRAM. This may speed up boot and maintain coherency with
758 * BIOS device numbering. Clearing the flag allows the user to
759 * rescan skipped devices later. We also return an error for
760 * devices not flagged for SCAN LUNS in the NVRAM since some single
761 * lun devices behave badly when asked for a non zero LUN.
764 if (tp
->usrflags
& SYM_SCAN_BOOT_DISABLED
) {
765 tp
->usrflags
&= ~SYM_SCAN_BOOT_DISABLED
;
766 starget_printk(KERN_INFO
, tp
->starget
,
767 "Scan at boot disabled in NVRAM\n");
771 if (tp
->usrflags
& SYM_SCAN_LUNS_DISABLED
) {
774 starget_printk(KERN_INFO
, tp
->starget
,
775 "Multiple LUNs disabled in NVRAM\n");
778 lp
= sym_alloc_lcb(np
, sdev
->id
, sdev
->lun
);
782 spi_min_period(tp
->starget
) = tp
->usr_period
;
783 spi_max_width(tp
->starget
) = tp
->usr_width
;
789 * Linux entry point for device queue sizing.
791 static int sym53c8xx_slave_configure(struct scsi_device
*sdev
)
793 struct sym_hcb
*np
= sym_get_hcb(sdev
->host
);
794 struct sym_tcb
*tp
= &np
->target
[sdev
->id
];
795 struct sym_lcb
*lp
= sym_lp(tp
, sdev
->lun
);
796 int reqtags
, depth_to_use
;
801 lp
->curr_flags
= lp
->user_flags
;
804 * Select queue depth from driver setup.
805 * Donnot use more than configured by user.
807 * Donnot use more than our maximum.
809 reqtags
= sym_driver_setup
.max_tag
;
810 if (reqtags
> tp
->usrtags
)
811 reqtags
= tp
->usrtags
;
812 if (!sdev
->tagged_supported
)
814 if (reqtags
> SYM_CONF_MAX_TAG
)
815 reqtags
= SYM_CONF_MAX_TAG
;
816 depth_to_use
= reqtags
? reqtags
: 2;
817 scsi_adjust_queue_depth(sdev
,
818 sdev
->tagged_supported
? MSG_SIMPLE_TAG
: 0,
820 lp
->s
.scdev_depth
= depth_to_use
;
821 sym_tune_dev_queuing(tp
, sdev
->lun
, reqtags
);
823 if (!spi_initial_dv(sdev
->sdev_target
))
829 static void sym53c8xx_slave_destroy(struct scsi_device
*sdev
)
831 struct sym_hcb
*np
= sym_get_hcb(sdev
->host
);
832 struct sym_lcb
*lp
= sym_lp(&np
->target
[sdev
->id
], sdev
->lun
);
835 sym_mfree_dma(lp
->itlq_tbl
, SYM_CONF_MAX_TASK
* 4, "ITLQ_TBL");
837 sym_mfree_dma(lp
, sizeof(*lp
), "LCB");
841 * Linux entry point for info() function
843 static const char *sym53c8xx_info (struct Scsi_Host
*host
)
845 return SYM_DRIVER_NAME
;
849 #ifdef SYM_LINUX_PROC_INFO_SUPPORT
851 * Proc file system stuff
853 * A read operation returns adapter information.
854 * A write operation is a control command.
855 * The string is parsed in the driver code and the command is passed
856 * to the sym_usercmd() function.
859 #ifdef SYM_LINUX_USER_COMMAND_SUPPORT
868 #define UC_SETSYNC 10
869 #define UC_SETTAGS 11
870 #define UC_SETDEBUG 12
871 #define UC_SETWIDE 14
872 #define UC_SETFLAG 15
873 #define UC_SETVERBOSE 17
874 #define UC_RESETDEV 18
875 #define UC_CLEARDEV 19
877 static void sym_exec_user_command (struct sym_hcb
*np
, struct sym_usrcmd
*uc
)
885 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
887 sym_debug_flags
= uc
->data
;
891 np
->verbose
= uc
->data
;
895 * We assume that other commands apply to targets.
896 * This should always be the case and avoid the below
897 * 4 lines to be repeated 6 times.
899 for (t
= 0; t
< SYM_CONF_MAX_TARGET
; t
++) {
900 if (!((uc
->target
>> t
) & 1))
907 if (!uc
->data
|| uc
->data
>= 255) {
908 tp
->tgoal
.iu
= tp
->tgoal
.dt
=
910 tp
->tgoal
.offset
= 0;
911 } else if (uc
->data
<= 9 && np
->minsync_dt
) {
912 if (uc
->data
< np
->minsync_dt
)
913 uc
->data
= np
->minsync_dt
;
914 tp
->tgoal
.iu
= tp
->tgoal
.dt
=
917 tp
->tgoal
.period
= uc
->data
;
918 tp
->tgoal
.offset
= np
->maxoffs_dt
;
920 if (uc
->data
< np
->minsync
)
921 uc
->data
= np
->minsync
;
922 tp
->tgoal
.iu
= tp
->tgoal
.dt
=
924 tp
->tgoal
.period
= uc
->data
;
925 tp
->tgoal
.offset
= np
->maxoffs
;
927 tp
->tgoal
.check_nego
= 1;
930 tp
->tgoal
.width
= uc
->data
? 1 : 0;
931 tp
->tgoal
.check_nego
= 1;
934 for (l
= 0; l
< SYM_CONF_MAX_LUN
; l
++)
935 sym_tune_dev_queuing(tp
, l
, uc
->data
);
940 OUTB(np
, nc_istat
, SIGP
|SEM
);
943 for (l
= 0; l
< SYM_CONF_MAX_LUN
; l
++) {
944 struct sym_lcb
*lp
= sym_lp(tp
, l
);
945 if (lp
) lp
->to_clear
= 1;
948 OUTB(np
, nc_istat
, SIGP
|SEM
);
951 tp
->usrflags
= uc
->data
;
959 static int skip_spaces(char *ptr
, int len
)
963 for (cnt
= len
; cnt
> 0 && (c
= *ptr
++) && isspace(c
); cnt
--);
968 static int get_int_arg(char *ptr
, int len
, u_long
*pv
)
972 *pv
= simple_strtoul(ptr
, &end
, 10);
976 static int is_keyword(char *ptr
, int len
, char *verb
)
978 int verb_len
= strlen(verb
);
980 if (len
>= verb_len
&& !memcmp(verb
, ptr
, verb_len
))
986 #define SKIP_SPACES(ptr, len) \
987 if ((arg_len = skip_spaces(ptr, len)) < 1) \
989 ptr += arg_len; len -= arg_len;
991 #define GET_INT_ARG(ptr, len, v) \
992 if (!(arg_len = get_int_arg(ptr, len, &(v)))) \
994 ptr += arg_len; len -= arg_len;
998 * Parse a control command
1001 static int sym_user_command(struct sym_hcb
*np
, char *buffer
, int length
)
1005 struct sym_usrcmd cmd
, *uc
= &cmd
;
1009 memset(uc
, 0, sizeof(*uc
));
1011 if (len
> 0 && ptr
[len
-1] == '\n')
1014 if ((arg_len
= is_keyword(ptr
, len
, "setsync")) != 0)
1015 uc
->cmd
= UC_SETSYNC
;
1016 else if ((arg_len
= is_keyword(ptr
, len
, "settags")) != 0)
1017 uc
->cmd
= UC_SETTAGS
;
1018 else if ((arg_len
= is_keyword(ptr
, len
, "setverbose")) != 0)
1019 uc
->cmd
= UC_SETVERBOSE
;
1020 else if ((arg_len
= is_keyword(ptr
, len
, "setwide")) != 0)
1021 uc
->cmd
= UC_SETWIDE
;
1022 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1023 else if ((arg_len
= is_keyword(ptr
, len
, "setdebug")) != 0)
1024 uc
->cmd
= UC_SETDEBUG
;
1026 else if ((arg_len
= is_keyword(ptr
, len
, "setflag")) != 0)
1027 uc
->cmd
= UC_SETFLAG
;
1028 else if ((arg_len
= is_keyword(ptr
, len
, "resetdev")) != 0)
1029 uc
->cmd
= UC_RESETDEV
;
1030 else if ((arg_len
= is_keyword(ptr
, len
, "cleardev")) != 0)
1031 uc
->cmd
= UC_CLEARDEV
;
1035 #ifdef DEBUG_PROC_INFO
1036 printk("sym_user_command: arg_len=%d, cmd=%ld\n", arg_len
, uc
->cmd
);
1041 ptr
+= arg_len
; len
-= arg_len
;
1050 SKIP_SPACES(ptr
, len
);
1051 if ((arg_len
= is_keyword(ptr
, len
, "all")) != 0) {
1052 ptr
+= arg_len
; len
-= arg_len
;
1055 GET_INT_ARG(ptr
, len
, target
);
1056 uc
->target
= (1<<target
);
1057 #ifdef DEBUG_PROC_INFO
1058 printk("sym_user_command: target=%ld\n", target
);
1069 SKIP_SPACES(ptr
, len
);
1070 GET_INT_ARG(ptr
, len
, uc
->data
);
1071 #ifdef DEBUG_PROC_INFO
1072 printk("sym_user_command: data=%ld\n", uc
->data
);
1075 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1078 SKIP_SPACES(ptr
, len
);
1079 if ((arg_len
= is_keyword(ptr
, len
, "alloc")))
1080 uc
->data
|= DEBUG_ALLOC
;
1081 else if ((arg_len
= is_keyword(ptr
, len
, "phase")))
1082 uc
->data
|= DEBUG_PHASE
;
1083 else if ((arg_len
= is_keyword(ptr
, len
, "queue")))
1084 uc
->data
|= DEBUG_QUEUE
;
1085 else if ((arg_len
= is_keyword(ptr
, len
, "result")))
1086 uc
->data
|= DEBUG_RESULT
;
1087 else if ((arg_len
= is_keyword(ptr
, len
, "scatter")))
1088 uc
->data
|= DEBUG_SCATTER
;
1089 else if ((arg_len
= is_keyword(ptr
, len
, "script")))
1090 uc
->data
|= DEBUG_SCRIPT
;
1091 else if ((arg_len
= is_keyword(ptr
, len
, "tiny")))
1092 uc
->data
|= DEBUG_TINY
;
1093 else if ((arg_len
= is_keyword(ptr
, len
, "timing")))
1094 uc
->data
|= DEBUG_TIMING
;
1095 else if ((arg_len
= is_keyword(ptr
, len
, "nego")))
1096 uc
->data
|= DEBUG_NEGO
;
1097 else if ((arg_len
= is_keyword(ptr
, len
, "tags")))
1098 uc
->data
|= DEBUG_TAGS
;
1099 else if ((arg_len
= is_keyword(ptr
, len
, "pointer")))
1100 uc
->data
|= DEBUG_POINTER
;
1103 ptr
+= arg_len
; len
-= arg_len
;
1105 #ifdef DEBUG_PROC_INFO
1106 printk("sym_user_command: data=%ld\n", uc
->data
);
1109 #endif /* SYM_LINUX_DEBUG_CONTROL_SUPPORT */
1112 SKIP_SPACES(ptr
, len
);
1113 if ((arg_len
= is_keyword(ptr
, len
, "no_disc")))
1114 uc
->data
&= ~SYM_DISC_ENABLED
;
1117 ptr
+= arg_len
; len
-= arg_len
;
1127 unsigned long flags
;
1129 spin_lock_irqsave(np
->s
.host
->host_lock
, flags
);
1130 sym_exec_user_command (np
, uc
);
1131 spin_unlock_irqrestore(np
->s
.host
->host_lock
, flags
);
1136 #endif /* SYM_LINUX_USER_COMMAND_SUPPORT */
1139 #ifdef SYM_LINUX_USER_INFO_SUPPORT
1141 * Informations through the proc file system.
1150 static void copy_mem_info(struct info_str
*info
, char *data
, int len
)
1152 if (info
->pos
+ len
> info
->length
)
1153 len
= info
->length
- info
->pos
;
1155 if (info
->pos
+ len
< info
->offset
) {
1159 if (info
->pos
< info
->offset
) {
1160 data
+= (info
->offset
- info
->pos
);
1161 len
-= (info
->offset
- info
->pos
);
1165 memcpy(info
->buffer
+ info
->pos
, data
, len
);
1170 static int copy_info(struct info_str
*info
, char *fmt
, ...)
1176 va_start(args
, fmt
);
1177 len
= vsprintf(buf
, fmt
, args
);
1180 copy_mem_info(info
, buf
, len
);
1185 * Copy formatted information into the input buffer.
1187 static int sym_host_info(struct sym_hcb
*np
, char *ptr
, off_t offset
, int len
)
1189 struct info_str info
;
1193 info
.offset
= offset
;
1196 copy_info(&info
, "Chip " NAME53C
"%s, device id 0x%x, "
1197 "revision id 0x%x\n", np
->s
.chip_name
,
1198 np
->s
.device
->device
, np
->s
.device
->revision
);
1199 copy_info(&info
, "At PCI address %s, IRQ " IRQ_FMT
"\n",
1200 pci_name(np
->s
.device
), IRQ_PRM(np
->s
.device
->irq
));
1201 copy_info(&info
, "Min. period factor %d, %s SCSI BUS%s\n",
1202 (int) (np
->minsync_dt
? np
->minsync_dt
: np
->minsync
),
1203 np
->maxwide
? "Wide" : "Narrow",
1204 np
->minsync_dt
? ", DT capable" : "");
1206 copy_info(&info
, "Max. started commands %d, "
1207 "max. commands per LUN %d\n",
1208 SYM_CONF_MAX_START
, SYM_CONF_MAX_TAG
);
1210 return info
.pos
> info
.offset
? info
.pos
- info
.offset
: 0;
1212 #endif /* SYM_LINUX_USER_INFO_SUPPORT */
1215 * Entry point of the scsi proc fs of the driver.
1216 * - func = 0 means read (returns adapter infos)
1217 * - func = 1 means write (not yet merget from sym53c8xx)
1219 static int sym53c8xx_proc_info(struct Scsi_Host
*host
, char *buffer
,
1220 char **start
, off_t offset
, int length
, int func
)
1222 struct sym_hcb
*np
= sym_get_hcb(host
);
1226 #ifdef SYM_LINUX_USER_COMMAND_SUPPORT
1227 retv
= sym_user_command(np
, buffer
, length
);
1234 #ifdef SYM_LINUX_USER_INFO_SUPPORT
1235 retv
= sym_host_info(np
, buffer
, offset
, length
);
1243 #endif /* SYM_LINUX_PROC_INFO_SUPPORT */
1246 * Free controller resources.
1248 static void sym_free_resources(struct sym_hcb
*np
, struct pci_dev
*pdev
)
1251 * Free O/S specific resources.
1254 free_irq(pdev
->irq
, np
);
1256 pci_iounmap(pdev
, np
->s
.ioaddr
);
1258 pci_iounmap(pdev
, np
->s
.ramaddr
);
1260 * Free O/S independent resources.
1264 sym_mfree_dma(np
, sizeof(*np
), "HCB");
1268 * Host attach and initialisations.
1270 * Allocate host data and ncb structure.
1271 * Remap MMIO region.
1272 * Do chip initialization.
1273 * If all is OK, install interrupt handling and
1274 * start the timer daemon.
1276 static struct Scsi_Host
* __devinit
sym_attach(struct scsi_host_template
*tpnt
,
1277 int unit
, struct sym_device
*dev
)
1279 struct host_data
*host_data
;
1280 struct sym_hcb
*np
= NULL
;
1281 struct Scsi_Host
*instance
= NULL
;
1282 struct pci_dev
*pdev
= dev
->pdev
;
1283 unsigned long flags
;
1286 printk(KERN_INFO
"sym%d: <%s> rev 0x%x at pci %s irq " IRQ_FMT
"\n",
1287 unit
, dev
->chip
.name
, pdev
->revision
, pci_name(pdev
),
1288 IRQ_PRM(pdev
->irq
));
1291 * Get the firmware for this chip.
1293 fw
= sym_find_firmware(&dev
->chip
);
1298 * Allocate host_data structure
1300 instance
= scsi_host_alloc(tpnt
, sizeof(*host_data
));
1303 host_data
= (struct host_data
*) instance
->hostdata
;
1306 * Allocate immediately the host control block,
1307 * since we are only expecting to succeed. :)
1308 * We keep track in the HCB of all the resources that
1309 * are to be released on error.
1311 np
= __sym_calloc_dma(&pdev
->dev
, sizeof(*np
), "HCB");
1314 np
->s
.device
= pdev
;
1315 np
->bus_dmat
= &pdev
->dev
; /* Result in 1 DMA pool per HBA */
1316 host_data
->ncb
= np
;
1317 np
->s
.host
= instance
;
1319 pci_set_drvdata(pdev
, np
);
1322 * Copy some useful infos to the HCB.
1324 np
->hcb_ba
= vtobus(np
);
1325 np
->verbose
= sym_driver_setup
.verbose
;
1326 np
->s
.device
= pdev
;
1328 np
->features
= dev
->chip
.features
;
1329 np
->clock_divn
= dev
->chip
.nr_divisor
;
1330 np
->maxoffs
= dev
->chip
.offset_max
;
1331 np
->maxburst
= dev
->chip
.burst_max
;
1332 np
->myaddr
= dev
->host_id
;
1337 strlcpy(np
->s
.chip_name
, dev
->chip
.name
, sizeof(np
->s
.chip_name
));
1338 sprintf(np
->s
.inst_name
, "sym%d", np
->s
.unit
);
1340 if ((SYM_CONF_DMA_ADDRESSING_MODE
> 0) && (np
->features
& FE_DAC
) &&
1341 !pci_set_dma_mask(np
->s
.device
, DMA_DAC_MASK
)) {
1343 } else if (pci_set_dma_mask(np
->s
.device
, DMA_32BIT_MASK
)) {
1344 printf_warning("%s: No suitable DMA available\n", sym_name(np
));
1349 * Try to map the controller chip to
1350 * virtual and physical memory.
1352 np
->mmio_ba
= (u32
)dev
->mmio_base
;
1353 np
->s
.ioaddr
= dev
->s
.ioaddr
;
1354 np
->s
.ramaddr
= dev
->s
.ramaddr
;
1357 * Map on-chip RAM if present and supported.
1359 if (!(np
->features
& FE_RAM
))
1362 np
->ram_ba
= (u32
)dev
->ram_base
;
1364 if (sym_hcb_attach(instance
, fw
, dev
->nvram
))
1368 * Install the interrupt handler.
1369 * If we synchonize the C code with SCRIPTS on interrupt,
1370 * we do not want to share the INTR line at all.
1372 if (request_irq(pdev
->irq
, sym53c8xx_intr
, IRQF_SHARED
, NAME53C8XX
, np
)) {
1373 printf_err("%s: request irq %d failure\n",
1374 sym_name(np
), pdev
->irq
);
1379 * After SCSI devices have been opened, we cannot
1380 * reset the bus safely, so we do it here.
1382 spin_lock_irqsave(instance
->host_lock
, flags
);
1383 if (sym_reset_scsi_bus(np
, 0))
1387 * Start the SCRIPTS.
1389 sym_start_up(np
, 1);
1392 * Start the timer daemon
1394 init_timer(&np
->s
.timer
);
1395 np
->s
.timer
.data
= (unsigned long) np
;
1396 np
->s
.timer
.function
= sym53c8xx_timer
;
1401 * Fill Linux host instance structure
1402 * and return success.
1404 instance
->max_channel
= 0;
1405 instance
->this_id
= np
->myaddr
;
1406 instance
->max_id
= np
->maxwide
? 16 : 8;
1407 instance
->max_lun
= SYM_CONF_MAX_LUN
;
1408 instance
->unique_id
= pci_resource_start(pdev
, 0);
1409 instance
->cmd_per_lun
= SYM_CONF_MAX_TAG
;
1410 instance
->can_queue
= (SYM_CONF_MAX_START
-2);
1411 instance
->sg_tablesize
= SYM_CONF_MAX_SG
;
1412 instance
->max_cmd_len
= 16;
1413 BUG_ON(sym2_transport_template
== NULL
);
1414 instance
->transportt
= sym2_transport_template
;
1416 /* 53c896 rev 1 errata: DMA may not cross 16MB boundary */
1417 if (pdev
->device
== PCI_DEVICE_ID_NCR_53C896
&& pdev
->revision
< 2)
1418 instance
->dma_boundary
= 0xFFFFFF;
1420 spin_unlock_irqrestore(instance
->host_lock
, flags
);
1425 printf_err("%s: FATAL ERROR: CHECK SCSI BUS - CABLES, "
1426 "TERMINATION, DEVICE POWER etc.!\n", sym_name(np
));
1427 spin_unlock_irqrestore(instance
->host_lock
, flags
);
1431 printf_info("%s: giving up ...\n", sym_name(np
));
1433 sym_free_resources(np
, pdev
);
1434 scsi_host_put(instance
);
1441 * Detect and try to read SYMBIOS and TEKRAM NVRAM.
1443 #if SYM_CONF_NVRAM_SUPPORT
1444 static void __devinit
sym_get_nvram(struct sym_device
*devp
, struct sym_nvram
*nvp
)
1449 sym_read_nvram(devp
, nvp
);
1452 static inline void sym_get_nvram(struct sym_device
*devp
, struct sym_nvram
*nvp
)
1455 #endif /* SYM_CONF_NVRAM_SUPPORT */
1457 static int __devinit
sym_check_supported(struct sym_device
*device
)
1459 struct sym_chip
*chip
;
1460 struct pci_dev
*pdev
= device
->pdev
;
1461 unsigned long io_port
= pci_resource_start(pdev
, 0);
1465 * If user excluded this chip, do not initialize it.
1466 * I hate this code so much. Must kill it.
1469 for (i
= 0 ; i
< 8 ; i
++) {
1470 if (sym_driver_setup
.excludes
[i
] == io_port
)
1476 * Check if the chip is supported. Then copy the chip description
1477 * to our device structure so we can make it match the actual device
1480 chip
= sym_lookup_chip_table(pdev
->device
, pdev
->revision
);
1482 dev_info(&pdev
->dev
, "device not supported\n");
1485 memcpy(&device
->chip
, chip
, sizeof(device
->chip
));
1491 * Ignore Symbios chips controlled by various RAID controllers.
1492 * These controllers set value 0x52414944 at RAM end - 16.
1494 static int __devinit
sym_check_raid(struct sym_device
*device
)
1496 unsigned int ram_size
, ram_val
;
1498 if (!device
->s
.ramaddr
)
1501 if (device
->chip
.features
& FE_RAM8K
)
1506 ram_val
= readl(device
->s
.ramaddr
+ ram_size
- 16);
1507 if (ram_val
!= 0x52414944)
1510 dev_info(&device
->pdev
->dev
,
1511 "not initializing, driven by RAID controller.\n");
1515 static int __devinit
sym_set_workarounds(struct sym_device
*device
)
1517 struct sym_chip
*chip
= &device
->chip
;
1518 struct pci_dev
*pdev
= device
->pdev
;
1522 * (ITEM 12 of a DEL about the 896 I haven't yet).
1523 * We must ensure the chip will use WRITE AND INVALIDATE.
1524 * The revision number limit is for now arbitrary.
1526 if (pdev
->device
== PCI_DEVICE_ID_NCR_53C896
&& pdev
->revision
< 0x4) {
1527 chip
->features
|= (FE_WRIE
| FE_CLSE
);
1530 /* If the chip can do Memory Write Invalidate, enable it */
1531 if (chip
->features
& FE_WRIE
) {
1532 if (pci_set_mwi(pdev
))
1537 * Work around for errant bit in 895A. The 66Mhz
1538 * capable bit is set erroneously. Clear this bit.
1541 * Make sure Config space and Features agree.
1543 * Recall: writes are not normal to status register -
1544 * write a 1 to clear and a 0 to leave unchanged.
1545 * Can only reset bits.
1547 pci_read_config_word(pdev
, PCI_STATUS
, &status_reg
);
1548 if (chip
->features
& FE_66MHZ
) {
1549 if (!(status_reg
& PCI_STATUS_66MHZ
))
1550 chip
->features
&= ~FE_66MHZ
;
1552 if (status_reg
& PCI_STATUS_66MHZ
) {
1553 status_reg
= PCI_STATUS_66MHZ
;
1554 pci_write_config_word(pdev
, PCI_STATUS
, status_reg
);
1555 pci_read_config_word(pdev
, PCI_STATUS
, &status_reg
);
1563 * Read and check the PCI configuration for any detected NCR
1564 * boards and save data for attaching after all boards have
1567 static void __devinit
1568 sym_init_device(struct pci_dev
*pdev
, struct sym_device
*device
)
1571 struct pci_bus_region bus_addr
;
1573 device
->host_id
= SYM_SETUP_HOST_ID
;
1574 device
->pdev
= pdev
;
1576 pcibios_resource_to_bus(pdev
, &bus_addr
, &pdev
->resource
[1]);
1577 device
->mmio_base
= bus_addr
.start
;
1580 * If the BAR is 64-bit, resource 2 will be occupied by the
1583 if (!pdev
->resource
[i
].flags
)
1585 pcibios_resource_to_bus(pdev
, &bus_addr
, &pdev
->resource
[i
]);
1586 device
->ram_base
= bus_addr
.start
;
1588 #ifdef CONFIG_SCSI_SYM53C8XX_MMIO
1589 if (device
->mmio_base
)
1590 device
->s
.ioaddr
= pci_iomap(pdev
, 1,
1591 pci_resource_len(pdev
, 1));
1593 if (!device
->s
.ioaddr
)
1594 device
->s
.ioaddr
= pci_iomap(pdev
, 0,
1595 pci_resource_len(pdev
, 0));
1596 if (device
->ram_base
)
1597 device
->s
.ramaddr
= pci_iomap(pdev
, i
,
1598 pci_resource_len(pdev
, i
));
1602 * The NCR PQS and PDS cards are constructed as a DEC bridge
1603 * behind which sits a proprietary NCR memory controller and
1604 * either four or two 53c875s as separate devices. We can tell
1605 * if an 875 is part of a PQS/PDS or not since if it is, it will
1606 * be on the same bus as the memory controller. In its usual
1607 * mode of operation, the 875s are slaved to the memory
1608 * controller for all transfers. To operate with the Linux
1609 * driver, the memory controller is disabled and the 875s
1610 * freed to function independently. The only wrinkle is that
1611 * the preset SCSI ID (which may be zero) must be read in from
1612 * a special configuration space register of the 875.
1614 static void sym_config_pqs(struct pci_dev
*pdev
, struct sym_device
*sym_dev
)
1619 for (slot
= 0; slot
< 256; slot
++) {
1620 struct pci_dev
*memc
= pci_get_slot(pdev
->bus
, slot
);
1622 if (!memc
|| memc
->vendor
!= 0x101a || memc
->device
== 0x0009) {
1627 /* bit 1: allow individual 875 configuration */
1628 pci_read_config_byte(memc
, 0x44, &tmp
);
1629 if ((tmp
& 0x2) == 0) {
1631 pci_write_config_byte(memc
, 0x44, tmp
);
1634 /* bit 2: drive individual 875 interrupts to the bus */
1635 pci_read_config_byte(memc
, 0x45, &tmp
);
1636 if ((tmp
& 0x4) == 0) {
1638 pci_write_config_byte(memc
, 0x45, tmp
);
1645 pci_read_config_byte(pdev
, 0x84, &tmp
);
1646 sym_dev
->host_id
= tmp
;
1650 * Called before unloading the module.
1652 * We have to free resources and halt the NCR chip.
1654 static int sym_detach(struct sym_hcb
*np
, struct pci_dev
*pdev
)
1656 printk("%s: detaching ...\n", sym_name(np
));
1658 del_timer_sync(&np
->s
.timer
);
1662 * We should use sym_soft_reset(), but we don't want to do
1663 * so, since we may not be safe if interrupts occur.
1665 printk("%s: resetting chip\n", sym_name(np
));
1666 OUTB(np
, nc_istat
, SRST
);
1669 OUTB(np
, nc_istat
, 0);
1671 sym_free_resources(np
, pdev
);
1677 * Driver host template.
1679 static struct scsi_host_template sym2_template
= {
1680 .module
= THIS_MODULE
,
1681 .name
= "sym53c8xx",
1682 .info
= sym53c8xx_info
,
1683 .queuecommand
= sym53c8xx_queue_command
,
1684 .slave_alloc
= sym53c8xx_slave_alloc
,
1685 .slave_configure
= sym53c8xx_slave_configure
,
1686 .slave_destroy
= sym53c8xx_slave_destroy
,
1687 .eh_abort_handler
= sym53c8xx_eh_abort_handler
,
1688 .eh_device_reset_handler
= sym53c8xx_eh_device_reset_handler
,
1689 .eh_bus_reset_handler
= sym53c8xx_eh_bus_reset_handler
,
1690 .eh_host_reset_handler
= sym53c8xx_eh_host_reset_handler
,
1692 .use_clustering
= ENABLE_CLUSTERING
,
1693 .use_sg_chaining
= ENABLE_SG_CHAINING
,
1694 .max_sectors
= 0xFFFF,
1695 #ifdef SYM_LINUX_PROC_INFO_SUPPORT
1696 .proc_info
= sym53c8xx_proc_info
,
1697 .proc_name
= NAME53C8XX
,
1701 static int attach_count
;
1703 static int __devinit
sym2_probe(struct pci_dev
*pdev
,
1704 const struct pci_device_id
*ent
)
1706 struct sym_device sym_dev
;
1707 struct sym_nvram nvram
;
1708 struct Scsi_Host
*instance
;
1710 memset(&sym_dev
, 0, sizeof(sym_dev
));
1711 memset(&nvram
, 0, sizeof(nvram
));
1713 if (pci_enable_device(pdev
))
1716 pci_set_master(pdev
);
1718 if (pci_request_regions(pdev
, NAME53C8XX
))
1721 sym_init_device(pdev
, &sym_dev
);
1722 if (sym_check_supported(&sym_dev
))
1725 if (sym_check_raid(&sym_dev
))
1726 goto leave
; /* Don't disable the device */
1728 if (sym_set_workarounds(&sym_dev
))
1731 sym_config_pqs(pdev
, &sym_dev
);
1733 sym_get_nvram(&sym_dev
, &nvram
);
1735 instance
= sym_attach(&sym2_template
, attach_count
, &sym_dev
);
1739 if (scsi_add_host(instance
, &pdev
->dev
))
1741 scsi_scan_host(instance
);
1748 sym_detach(pci_get_drvdata(pdev
), pdev
);
1750 pci_release_regions(pdev
);
1752 pci_disable_device(pdev
);
1757 static void __devexit
sym2_remove(struct pci_dev
*pdev
)
1759 struct sym_hcb
*np
= pci_get_drvdata(pdev
);
1760 struct Scsi_Host
*host
= np
->s
.host
;
1762 scsi_remove_host(host
);
1763 scsi_host_put(host
);
1765 sym_detach(np
, pdev
);
1767 pci_release_regions(pdev
);
1768 pci_disable_device(pdev
);
1774 * sym2_io_error_detected() - called when PCI error is detected
1775 * @pdev: pointer to PCI device
1776 * @state: current state of the PCI slot
1778 static pci_ers_result_t
sym2_io_error_detected(struct pci_dev
*pdev
,
1779 enum pci_channel_state state
)
1781 /* If slot is permanently frozen, turn everything off */
1782 if (state
== pci_channel_io_perm_failure
) {
1784 return PCI_ERS_RESULT_DISCONNECT
;
1787 disable_irq(pdev
->irq
);
1788 pci_disable_device(pdev
);
1790 /* Request that MMIO be enabled, so register dump can be taken. */
1791 return PCI_ERS_RESULT_CAN_RECOVER
;
1795 * sym2_io_slot_dump - Enable MMIO and dump debug registers
1796 * @pdev: pointer to PCI device
1798 static pci_ers_result_t
sym2_io_slot_dump(struct pci_dev
*pdev
)
1800 struct sym_hcb
*np
= pci_get_drvdata(pdev
);
1802 sym_dump_registers(np
);
1804 /* Request a slot reset. */
1805 return PCI_ERS_RESULT_NEED_RESET
;
1809 * sym2_reset_workarounds - hardware-specific work-arounds
1811 * This routine is similar to sym_set_workarounds(), except
1812 * that, at this point, we already know that the device was
1813 * succesfully intialized at least once before, and so most
1814 * of the steps taken there are un-needed here.
1816 static void sym2_reset_workarounds(struct pci_dev
*pdev
)
1819 struct sym_chip
*chip
;
1821 chip
= sym_lookup_chip_table(pdev
->device
, pdev
->revision
);
1823 /* Work around for errant bit in 895A, in a fashion
1824 * similar to what is done in sym_set_workarounds().
1826 pci_read_config_word(pdev
, PCI_STATUS
, &status_reg
);
1827 if (!(chip
->features
& FE_66MHZ
) && (status_reg
& PCI_STATUS_66MHZ
)) {
1828 status_reg
= PCI_STATUS_66MHZ
;
1829 pci_write_config_word(pdev
, PCI_STATUS
, status_reg
);
1830 pci_read_config_word(pdev
, PCI_STATUS
, &status_reg
);
1835 * sym2_io_slot_reset() - called when the pci bus has been reset.
1836 * @pdev: pointer to PCI device
1838 * Restart the card from scratch.
1840 static pci_ers_result_t
sym2_io_slot_reset(struct pci_dev
*pdev
)
1842 struct sym_hcb
*np
= pci_get_drvdata(pdev
);
1844 printk(KERN_INFO
"%s: recovering from a PCI slot reset\n",
1847 if (pci_enable_device(pdev
)) {
1848 printk(KERN_ERR
"%s: Unable to enable after PCI reset\n",
1850 return PCI_ERS_RESULT_DISCONNECT
;
1853 pci_set_master(pdev
);
1854 enable_irq(pdev
->irq
);
1856 /* If the chip can do Memory Write Invalidate, enable it */
1857 if (np
->features
& FE_WRIE
) {
1858 if (pci_set_mwi(pdev
))
1859 return PCI_ERS_RESULT_DISCONNECT
;
1862 /* Perform work-arounds, analogous to sym_set_workarounds() */
1863 sym2_reset_workarounds(pdev
);
1865 /* Perform host reset only on one instance of the card */
1866 if (PCI_FUNC(pdev
->devfn
) == 0) {
1867 if (sym_reset_scsi_bus(np
, 0)) {
1868 printk(KERN_ERR
"%s: Unable to reset scsi host\n",
1870 return PCI_ERS_RESULT_DISCONNECT
;
1872 sym_start_up(np
, 1);
1875 return PCI_ERS_RESULT_RECOVERED
;
1879 * sym2_io_resume() - resume normal ops after PCI reset
1880 * @pdev: pointer to PCI device
1882 * Called when the error recovery driver tells us that its
1883 * OK to resume normal operation. Use completion to allow
1884 * halted scsi ops to resume.
1886 static void sym2_io_resume(struct pci_dev
*pdev
)
1888 struct sym_hcb
*np
= pci_get_drvdata(pdev
);
1889 struct Scsi_Host
*shost
= np
->s
.host
;
1890 struct host_data
*hostdata
= shost_priv(shost
);
1892 spin_lock_irq(shost
->host_lock
);
1893 if (hostdata
->io_reset
)
1894 complete_all(hostdata
->io_reset
);
1895 hostdata
->io_reset
= NULL
;
1896 spin_unlock_irq(shost
->host_lock
);
1899 static void sym2_get_signalling(struct Scsi_Host
*shost
)
1901 struct sym_hcb
*np
= sym_get_hcb(shost
);
1902 enum spi_signal_type type
;
1904 switch (np
->scsi_mode
) {
1906 type
= SPI_SIGNAL_SE
;
1909 type
= SPI_SIGNAL_LVD
;
1912 type
= SPI_SIGNAL_HVD
;
1915 type
= SPI_SIGNAL_UNKNOWN
;
1918 spi_signalling(shost
) = type
;
1921 static void sym2_set_offset(struct scsi_target
*starget
, int offset
)
1923 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
1924 struct sym_hcb
*np
= sym_get_hcb(shost
);
1925 struct sym_tcb
*tp
= &np
->target
[starget
->id
];
1927 tp
->tgoal
.offset
= offset
;
1928 tp
->tgoal
.check_nego
= 1;
1931 static void sym2_set_period(struct scsi_target
*starget
, int period
)
1933 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
1934 struct sym_hcb
*np
= sym_get_hcb(shost
);
1935 struct sym_tcb
*tp
= &np
->target
[starget
->id
];
1937 /* have to have DT for these transfers, but DT will also
1938 * set width, so check that this is allowed */
1939 if (period
<= np
->minsync
&& spi_width(starget
))
1942 tp
->tgoal
.period
= period
;
1943 tp
->tgoal
.check_nego
= 1;
1946 static void sym2_set_width(struct scsi_target
*starget
, int width
)
1948 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
1949 struct sym_hcb
*np
= sym_get_hcb(shost
);
1950 struct sym_tcb
*tp
= &np
->target
[starget
->id
];
1952 /* It is illegal to have DT set on narrow transfers. If DT is
1953 * clear, we must also clear IU and QAS. */
1955 tp
->tgoal
.iu
= tp
->tgoal
.dt
= tp
->tgoal
.qas
= 0;
1957 tp
->tgoal
.width
= width
;
1958 tp
->tgoal
.check_nego
= 1;
1961 static void sym2_set_dt(struct scsi_target
*starget
, int dt
)
1963 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
1964 struct sym_hcb
*np
= sym_get_hcb(shost
);
1965 struct sym_tcb
*tp
= &np
->target
[starget
->id
];
1967 /* We must clear QAS and IU if DT is clear */
1971 tp
->tgoal
.iu
= tp
->tgoal
.dt
= tp
->tgoal
.qas
= 0;
1972 tp
->tgoal
.check_nego
= 1;
1976 static void sym2_set_iu(struct scsi_target
*starget
, int iu
)
1978 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
1979 struct sym_hcb
*np
= sym_get_hcb(shost
);
1980 struct sym_tcb
*tp
= &np
->target
[starget
->id
];
1983 tp
->tgoal
.iu
= tp
->tgoal
.dt
= 1;
1986 tp
->tgoal
.check_nego
= 1;
1989 static void sym2_set_qas(struct scsi_target
*starget
, int qas
)
1991 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
1992 struct sym_hcb
*np
= sym_get_hcb(shost
);
1993 struct sym_tcb
*tp
= &np
->target
[starget
->id
];
1996 tp
->tgoal
.dt
= tp
->tgoal
.qas
= 1;
1999 tp
->tgoal
.check_nego
= 1;
2003 static struct spi_function_template sym2_transport_functions
= {
2004 .set_offset
= sym2_set_offset
,
2006 .set_period
= sym2_set_period
,
2008 .set_width
= sym2_set_width
,
2010 .set_dt
= sym2_set_dt
,
2013 .set_iu
= sym2_set_iu
,
2015 .set_qas
= sym2_set_qas
,
2018 .get_signalling
= sym2_get_signalling
,
2021 static struct pci_device_id sym2_id_table
[] __devinitdata
= {
2022 { PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_NCR_53C810
,
2023 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0UL },
2024 { PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_NCR_53C820
,
2025 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0UL }, /* new */
2026 { PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_NCR_53C825
,
2027 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0UL },
2028 { PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_NCR_53C815
,
2029 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0UL },
2030 { PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_53C810AP
,
2031 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0UL }, /* new */
2032 { PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_NCR_53C860
,
2033 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0UL },
2034 { PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_53C1510
,
2035 PCI_ANY_ID
, PCI_ANY_ID
, PCI_CLASS_STORAGE_SCSI
<<8, 0xffff00, 0UL },
2036 { PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_NCR_53C896
,
2037 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0UL },
2038 { PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_NCR_53C895
,
2039 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0UL },
2040 { PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_NCR_53C885
,
2041 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0UL },
2042 { PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_NCR_53C875
,
2043 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0UL },
2044 { PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_NCR_53C1510
,
2045 PCI_ANY_ID
, PCI_ANY_ID
, PCI_CLASS_STORAGE_SCSI
<<8, 0xffff00, 0UL }, /* new */
2046 { PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_53C895A
,
2047 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0UL },
2048 { PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_53C875A
,
2049 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0UL },
2050 { PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_53C1010_33
,
2051 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0UL },
2052 { PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_53C1010_66
,
2053 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0UL },
2054 { PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_NCR_53C875J
,
2055 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0UL },
2059 MODULE_DEVICE_TABLE(pci
, sym2_id_table
);
2061 static struct pci_error_handlers sym2_err_handler
= {
2062 .error_detected
= sym2_io_error_detected
,
2063 .mmio_enabled
= sym2_io_slot_dump
,
2064 .slot_reset
= sym2_io_slot_reset
,
2065 .resume
= sym2_io_resume
,
2068 static struct pci_driver sym2_driver
= {
2070 .id_table
= sym2_id_table
,
2071 .probe
= sym2_probe
,
2072 .remove
= __devexit_p(sym2_remove
),
2073 .err_handler
= &sym2_err_handler
,
2076 static int __init
sym2_init(void)
2080 sym2_setup_params();
2081 sym2_transport_template
= spi_attach_transport(&sym2_transport_functions
);
2082 if (!sym2_transport_template
)
2085 error
= pci_register_driver(&sym2_driver
);
2087 spi_release_transport(sym2_transport_template
);
2091 static void __exit
sym2_exit(void)
2093 pci_unregister_driver(&sym2_driver
);
2094 spi_release_transport(sym2_transport_template
);
2097 module_init(sym2_init
);
2098 module_exit(sym2_exit
);