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>
7
* This driver is derived from the Linux sym53c8xx driver.
8
* Copyright (C) 1998-2000 Gerard Roudier
10
* The sym53c8xx driver is derived from the ncr53c8xx driver that had been
11
* a port of the FreeBSD ncr driver to Linux-1.2.13.
13
* The original ncr driver has been written for 386bsd and FreeBSD by
14
* Wolfgang Stanglmeier <wolf@cologne.de>
15
* Stefan Esser <se@mi.Uni-Koeln.de>
16
* Copyright (C) 1994 Wolfgang Stanglmeier
18
* Other major contributions:
20
* NVRAM detection and reading.
21
* Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
23
*-----------------------------------------------------------------------------
25
* Redistribution and use in source and binary forms, with or without
26
* modification, are permitted provided that the following conditions
28
* 1. Redistributions of source code must retain the above copyright
29
* notice, this list of conditions and the following disclaimer.
30
* 2. The name of the author may not be used to endorse or promote products
31
* derived from this software without specific prior written permission.
33
* Where this Software is combined with software released under the terms of
34
* the GNU Public License ("GPL") and the terms of the GPL would require the
35
* combined work to also be released under the terms of the GPL, the terms
36
* and conditions of this License will apply in addition to those of the
37
* GPL with the exception of any terms or conditions of this License that
38
* conflict with, or are expressly prohibited by, the GPL.
40
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
41
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
44
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54
#include <linux/module.h>
57
#define NAME53C "sym53c"
58
#define NAME53C8XX "sym53c8xx"
61
* Simple Wrapper to kernel PCI bus interface.
64
typedef struct pci_dev *pcidev_t;
65
#define PCIDEV_NULL (0)
66
#define PciBusNumber(d) (d)->bus->number
67
#define PciDeviceFn(d) (d)->devfn
68
#define PciVendorId(d) (d)->vendor
69
#define PciDeviceId(d) (d)->device
70
#define PciIrqLine(d) (d)->irq
73
pci_get_base_cookie(struct pci_dev *pdev, int index)
77
#if LINUX_VERSION_CODE > LinuxVersionCode(2,3,12)
78
base = pdev->resource[index].start;
80
base = pdev->base_address[index];
81
#if BITS_PER_LONG > 32
82
if ((base & 0x7) == 0x4)
83
base |= (((u_long)pdev->base_address[++index]) << 32);
86
return (base & ~0x7ul);
90
pci_get_base_address(struct pci_dev *pdev, int index, u_long *base)
93
#define PCI_BAR_OFFSET(index) (PCI_BASE_ADDRESS_0 + (index<<2))
95
pci_read_config_dword(pdev, PCI_BAR_OFFSET(index), &tmp);
98
if ((tmp & 0x7) == 0x4) {
99
#if BITS_PER_LONG > 32
100
pci_read_config_dword(pdev, PCI_BAR_OFFSET(index), &tmp);
101
*base |= (((u_long)tmp) << 32);
106
#undef PCI_BAR_OFFSET
109
#if LINUX_VERSION_CODE < LinuxVersionCode(2,4,0)
110
#define pci_enable_device(pdev) (0)
113
#if LINUX_VERSION_CODE < LinuxVersionCode(2,4,4)
114
#define scsi_set_pci_device(inst, pdev) do { ;} while (0)
118
* Insert a delay in micro-seconds and milli-seconds.
120
void sym_udelay(int us) { udelay(us); }
121
void sym_mdelay(int ms) { mdelay(ms); }
126
* The whole SCSI sub-system under Linux is basically single-threaded.
127
* Everything, including low-level driver interrupt routine, happens
128
* with the `io_request_lock' held.
129
* The sym53c8xx-1.x drivers series ran their interrupt code using a
130
* spin mutex per controller. This added complexity without improving
131
* scalability significantly. the sym-2 driver still use a spinlock
132
* per controller for safety, but basically runs with the damned
133
* io_request_lock held.
136
spinlock_t sym53c8xx_lock = SPIN_LOCK_UNLOCKED;
138
#define SYM_LOCK_DRIVER(flags) spin_lock_irqsave(&sym53c8xx_lock, flags)
139
#define SYM_UNLOCK_DRIVER(flags) spin_unlock_irqrestore(&sym53c8xx_lock,flags)
141
#define SYM_INIT_LOCK_HCB(np) spin_lock_init(&np->s.smp_lock);
142
#define SYM_LOCK_HCB(np, flags) spin_lock_irqsave(&np->s.smp_lock, flags)
143
#define SYM_UNLOCK_HCB(np, flags) spin_unlock_irqrestore(&np->s.smp_lock, flags)
145
#define SYM_LOCK_SCSI(np, flags) \
146
spin_lock_irqsave(&io_request_lock, flags)
147
#define SYM_UNLOCK_SCSI(np, flags) \
148
spin_unlock_irqrestore(&io_request_lock, flags)
150
/* Ugly, but will make things easier if this locking will ever disappear */
151
#define SYM_LOCK_SCSI_NOSAVE(np) spin_lock_irq(&io_request_lock)
152
#define SYM_UNLOCK_SCSI_NORESTORE(np) spin_unlock_irq(&io_request_lock)
155
* These simple macros limit expression involving
156
* kernel time values (jiffies) to some that have
157
* chance not to be too much incorrect. :-)
159
#define ktime_get(o) (jiffies + (u_long) o)
160
#define ktime_exp(b) ((long)(jiffies) - (long)(b) >= 0)
161
#define ktime_dif(a, b) ((long)(a) - (long)(b))
162
#define ktime_add(a, o) ((a) + (u_long)(o))
163
#define ktime_sub(a, o) ((a) - (u_long)(o))
166
* Wrappers to the generic memory allocator.
168
void *sym_calloc(int size, char *name)
172
SYM_LOCK_DRIVER(flags);
173
m = sym_calloc_unlocked(size, name);
174
SYM_UNLOCK_DRIVER(flags);
178
void sym_mfree(void *m, int size, char *name)
181
SYM_LOCK_DRIVER(flags);
182
sym_mfree_unlocked(m, size, name);
183
SYM_UNLOCK_DRIVER(flags);
186
#ifdef SYM_LINUX_DYNAMIC_DMA_MAPPING
188
void *__sym_calloc_dma(m_pool_ident_t dev_dmat, int size, char *name)
192
SYM_LOCK_DRIVER(flags);
193
m = __sym_calloc_dma_unlocked(dev_dmat, size, name);
194
SYM_UNLOCK_DRIVER(flags);
198
void __sym_mfree_dma(m_pool_ident_t dev_dmat, void *m, int size, char *name)
201
SYM_LOCK_DRIVER(flags);
202
__sym_mfree_dma_unlocked(dev_dmat, m, size, name);
203
SYM_UNLOCK_DRIVER(flags);
206
m_addr_t __vtobus(m_pool_ident_t dev_dmat, void *m)
210
SYM_LOCK_DRIVER(flags);
211
b = __vtobus_unlocked(dev_dmat, m);
212
SYM_UNLOCK_DRIVER(flags);
216
#endif /* SYM_LINUX_DYNAMIC_DMA_MAPPING */
220
* Map/unmap a PCI memory window.
222
#ifndef SYM_OPT_NO_BUS_MEMORY_MAPPING
223
static u_long __init pci_map_mem(u_long base, u_long size)
225
u_long page_base = ((u_long) base) & PAGE_MASK;
226
u_long page_offs = ((u_long) base) - page_base;
227
u_long page_remapped = (u_long) ioremap(page_base, page_offs+size);
229
return page_remapped? (page_remapped + page_offs) : 0UL;
232
static void __init pci_unmap_mem(u_long vaddr, u_long size)
235
iounmap((void *) (vaddr & PAGE_MASK));
240
* Used to retrieve the host structure when the
241
* driver is called from the proc FS.
243
static struct Scsi_Host *first_host = NULL;
246
* /proc directory entry and proc_info.
248
#if LINUX_VERSION_CODE < LinuxVersionCode(2,3,27)
249
static struct proc_dir_entry proc_scsi_sym53c8xx = {
250
PROC_SCSI_SYM53C8XX, 9, NAME53C8XX,
251
S_IFDIR | S_IRUGO | S_IXUGO, 2
258
* Until some linux kernel version near 2.3.40, low-level scsi
259
* drivers were not told about data transfer direction.
261
#if LINUX_VERSION_CODE > LinuxVersionCode(2, 3, 40)
263
#define scsi_data_direction(cmd) (cmd->sc_data_direction)
267
static __inline__ int scsi_data_direction(Scsi_Cmnd *cmd)
271
switch((int) cmd->cmnd[0]) {
272
case 0x08: /* READ(6) 08 */
273
case 0x28: /* READ(10) 28 */
274
case 0xA8: /* READ(12) A8 */
275
direction = SCSI_DATA_READ;
277
case 0x0A: /* WRITE(6) 0A */
278
case 0x2A: /* WRITE(10) 2A */
279
case 0xAA: /* WRITE(12) AA */
280
direction = SCSI_DATA_WRITE;
283
direction = SCSI_DATA_UNKNOWN;
293
* Driver host data structure.
300
* Some type that fit DMA addresses as seen from BUS.
302
#ifndef SYM_LINUX_DYNAMIC_DMA_MAPPING
303
typedef u_long bus_addr_t;
305
#if SYM_CONF_DMA_ADDRESSING_MODE > 0
306
typedef dma64_addr_t bus_addr_t;
308
typedef dma_addr_t bus_addr_t;
313
* Used by the eh thread to wait for command completion.
314
* It is allocated on the eh thread stack.
319
struct semaphore sem;
321
struct timer_list timer;
322
void (*old_done)(Scsi_Cmnd *);
328
* Driver private area in the SCSI command structure.
330
struct sym_ucmd { /* Override the SCSI pointer structure */
331
SYM_QUEHEAD link_cmdq; /* Must stay at offset ZERO */
332
#ifdef SYM_LINUX_DYNAMIC_DMA_MAPPING
333
bus_addr_t data_mapping;
336
struct sym_eh_wait *eh_wait;
339
typedef struct sym_ucmd *ucmd_p;
341
#define SYM_UCMD_PTR(cmd) ((ucmd_p)(&(cmd)->SCp))
342
#define SYM_SCMD_PTR(ucmd) sym_que_entry(ucmd, Scsi_Cmnd, SCp)
343
#define SYM_SOFTC_PTR(cmd) (((struct host_data *)cmd->host->hostdata)->ncb)
346
* Deal with DMA mapping/unmapping.
349
#ifndef SYM_LINUX_DYNAMIC_DMA_MAPPING
351
/* Linux versions prior to pci bus iommu kernel interface */
353
#define __unmap_scsi_data(pdev, cmd) do {; } while (0)
354
#define __map_scsi_single_data(pdev, cmd) (__vtobus(pdev,(cmd)->request_buffer))
355
#define __map_scsi_sg_data(pdev, cmd) ((cmd)->use_sg)
356
#define __sync_scsi_data(pdev, cmd) do {; } while (0)
358
#define bus_sg_dma_address(sc) vtobus((sc)->address)
359
#define bus_sg_dma_len(sc) ((sc)->length)
361
#else /* Linux version with pci bus iommu kernel interface */
363
#define bus_unmap_sg(pdev, sgptr, sgcnt, dir) \
364
pci_unmap_sg(pdev, sgptr, sgcnt, dir)
366
#define bus_unmap_single(pdev, mapping, bufptr, dir) \
367
pci_unmap_single(pdev, mapping, bufptr, dir)
369
#define bus_map_single(pdev, bufptr, bufsiz, dir) \
370
pci_map_single(pdev, bufptr, bufsiz, dir)
372
#define bus_map_sg(pdev, sgptr, sgcnt, dir) \
373
pci_map_sg(pdev, sgptr, sgcnt, dir)
375
#define bus_dma_sync_sg(pdev, sgptr, sgcnt, dir) \
376
pci_dma_sync_sg(pdev, sgptr, sgcnt, dir)
378
#define bus_dma_sync_single(pdev, mapping, bufsiz, dir) \
379
pci_dma_sync_single(pdev, mapping, bufsiz, dir)
381
#define bus_sg_dma_address(sc) sg_dma_address(sc)
382
#define bus_sg_dma_len(sc) sg_dma_len(sc)
384
static void __unmap_scsi_data(pcidev_t pdev, Scsi_Cmnd *cmd)
386
int dma_dir = scsi_to_pci_dma_dir(cmd->sc_data_direction);
388
switch(SYM_UCMD_PTR(cmd)->data_mapped) {
390
bus_unmap_sg(pdev, cmd->buffer, cmd->use_sg, dma_dir);
393
bus_unmap_single(pdev, SYM_UCMD_PTR(cmd)->data_mapping,
394
cmd->request_bufflen, dma_dir);
397
SYM_UCMD_PTR(cmd)->data_mapped = 0;
400
static bus_addr_t __map_scsi_single_data(pcidev_t pdev, Scsi_Cmnd *cmd)
403
int dma_dir = scsi_to_pci_dma_dir(cmd->sc_data_direction);
405
mapping = bus_map_single(pdev, cmd->request_buffer,
406
cmd->request_bufflen, dma_dir);
408
SYM_UCMD_PTR(cmd)->data_mapped = 1;
409
SYM_UCMD_PTR(cmd)->data_mapping = mapping;
415
static int __map_scsi_sg_data(pcidev_t pdev, Scsi_Cmnd *cmd)
418
int dma_dir = scsi_to_pci_dma_dir(cmd->sc_data_direction);
420
use_sg = bus_map_sg(pdev, cmd->buffer, cmd->use_sg, dma_dir);
422
SYM_UCMD_PTR(cmd)->data_mapped = 2;
423
SYM_UCMD_PTR(cmd)->data_mapping = use_sg;
429
static void __sync_scsi_data(pcidev_t pdev, Scsi_Cmnd *cmd)
431
int dma_dir = scsi_to_pci_dma_dir(cmd->sc_data_direction);
433
switch(SYM_UCMD_PTR(cmd)->data_mapped) {
435
bus_dma_sync_sg(pdev, cmd->buffer, cmd->use_sg, dma_dir);
438
bus_dma_sync_single(pdev, SYM_UCMD_PTR(cmd)->data_mapping,
439
cmd->request_bufflen, dma_dir);
444
#endif /* SYM_LINUX_DYNAMIC_DMA_MAPPING */
446
#define unmap_scsi_data(np, cmd) \
447
__unmap_scsi_data(np->s.device, cmd)
448
#define map_scsi_single_data(np, cmd) \
449
__map_scsi_single_data(np->s.device, cmd)
450
#define map_scsi_sg_data(np, cmd) \
451
__map_scsi_sg_data(np->s.device, cmd)
452
#define sync_scsi_data(np, cmd) \
453
__sync_scsi_data(np->s.device, cmd)
456
* Complete a pending CAM CCB.
458
void sym_xpt_done(hcb_p np, Scsi_Cmnd *ccb)
460
sym_remque(&SYM_UCMD_PTR(ccb)->link_cmdq);
461
unmap_scsi_data(np, ccb);
465
void sym_xpt_done2(hcb_p np, Scsi_Cmnd *ccb, int cam_status)
467
sym_set_cam_status(ccb, cam_status);
468
sym_xpt_done(np, ccb);
473
* Print something that identifies the IO.
475
void sym_print_addr (ccb_p cp)
477
Scsi_Cmnd *cmd = cp->cam_ccb;
479
printf("%s:%d:%d:", sym_name(SYM_SOFTC_PTR(cmd)),
480
cmd->target,cmd->lun);
484
* Tell the SCSI layer about a BUS RESET.
486
void sym_xpt_async_bus_reset(hcb_p np)
488
printf_notice("%s: SCSI BUS has been reset.\n", sym_name(np));
489
np->s.settle_time = ktime_get(sym_driver_setup.settle_delay * HZ);
490
np->s.settle_time_valid = 1;
491
if (sym_verbose >= 2)
492
printf_info("%s: command processing suspended for %d seconds\n",
493
sym_name(np), sym_driver_setup.settle_delay);
497
* Tell the SCSI layer about a BUS DEVICE RESET message sent.
499
void sym_xpt_async_sent_bdr(hcb_p np, int target)
501
printf_notice("%s: TARGET %d has been reset.\n", sym_name(np), target);
505
* Tell the SCSI layer about the new transfer parameters.
507
void sym_xpt_async_nego_wide(hcb_p np, int target)
511
sym_announce_transfer_rate(np, target);
515
* Choose the more appropriate CAM status if
516
* the IO encountered an extended error.
518
static int sym_xerr_cam_status(int cam_status, int x_status)
521
if (x_status & XE_PARITY_ERR)
522
cam_status = DID_PARITY;
523
else if (x_status &(XE_EXTRA_DATA|XE_SODL_UNRUN|XE_SWIDE_OVRUN))
524
cam_status = DID_ERROR;
525
else if (x_status & XE_BAD_PHASE)
526
cam_status = DID_ERROR;
528
cam_status = DID_ERROR;
534
* Build CAM result for a failed or auto-sensed IO.
536
void sym_set_cam_result_error(hcb_p np, ccb_p cp, int resid)
538
Scsi_Cmnd *csio = cp->cam_ccb;
539
u_int cam_status, scsi_status, drv_status;
543
scsi_status = cp->ssss_status;
545
if (cp->host_flags & HF_SENSE) {
546
scsi_status = cp->sv_scsi_status;
547
resid = cp->sv_resid;
548
if (sym_verbose && cp->sv_xerr_status)
549
sym_print_xerr(cp, cp->sv_xerr_status);
550
if (cp->host_status == HS_COMPLETE &&
551
cp->ssss_status == S_GOOD &&
552
cp->xerr_status == 0) {
553
cam_status = sym_xerr_cam_status(DID_OK,
555
drv_status = DRIVER_SENSE;
557
* Bounce back the sense data to user.
559
bzero(&csio->sense_buffer, sizeof(csio->sense_buffer));
560
bcopy(cp->sns_bbuf, csio->sense_buffer,
561
MIN(sizeof(csio->sense_buffer),SYM_SNS_BBUF_LEN));
564
* If the device reports a UNIT ATTENTION condition
565
* due to a RESET condition, we should consider all
566
* disconnect CCBs for this unit as aborted.
570
p = (u_char *) csio->sense_data;
571
if (p[0]==0x70 && p[2]==0x6 && p[12]==0x29)
572
sym_clear_tasks(np, DID_ABORT,
573
cp->target,cp->lun, -1);
578
cam_status = DID_ERROR;
580
else if (cp->host_status == HS_COMPLETE) /* Bad SCSI status */
582
else if (cp->host_status == HS_SEL_TIMEOUT) /* Selection timeout */
583
cam_status = DID_NO_CONNECT;
584
else if (cp->host_status == HS_UNEXPECTED) /* Unexpected BUS FREE*/
585
cam_status = DID_ERROR;
586
else { /* Extended error */
589
printf ("COMMAND FAILED (%x %x %x).\n",
590
cp->host_status, cp->ssss_status,
594
* Set the most appropriate value for CAM status.
596
cam_status = sym_xerr_cam_status(DID_ERROR, cp->xerr_status);
598
#if LINUX_VERSION_CODE >= LinuxVersionCode(2,3,99)
601
csio->result = (drv_status << 24) + (cam_status << 16) + scsi_status;
606
* Called on successfull INQUIRY response.
608
void sym_sniff_inquiry(hcb_p np, Scsi_Cmnd *cmd, int resid)
612
if (!cmd || cmd->use_sg)
615
sync_scsi_data(np, cmd);
616
retv = __sym_sniff_inquiry(np, cmd->target, cmd->lun,
617
(u_char *) cmd->request_buffer,
618
cmd->request_bufflen - resid);
622
sym_update_trans_settings(np, &np->target[cmd->target]);
626
* Build the scatter/gather array for an I/O.
629
static int sym_scatter_no_sglist(hcb_p np, ccb_p cp, Scsi_Cmnd *cmd)
631
struct sym_tblmove *data = &cp->phys.data[SYM_CONF_MAX_SG-1];
634
cp->data_len = cmd->request_bufflen;
636
if (cmd->request_bufflen) {
637
bus_addr_t baddr = map_scsi_single_data(np, cmd);
639
sym_build_sge(np, data, baddr, cmd->request_bufflen);
651
static int sym_scatter(hcb_p np, ccb_p cp, Scsi_Cmnd *cmd)
654
int use_sg = (int) cmd->use_sg;
659
segment = sym_scatter_no_sglist(np, cp, cmd);
660
else if (use_sg > SYM_CONF_MAX_SG)
662
else if ((use_sg = map_scsi_sg_data(np, cmd)) > 0) {
663
struct scatterlist *scatter = (struct scatterlist *)cmd->buffer;
664
struct sym_tblmove *data;
666
data = &cp->phys.data[SYM_CONF_MAX_SG - use_sg];
668
for (segment = 0; segment < use_sg; segment++) {
669
bus_addr_t baddr = bus_sg_dma_address(&scatter[segment]);
670
unsigned int len = bus_sg_dma_len(&scatter[segment]);
672
sym_build_sge(np, &data[segment], baddr, len);
683
* Queue a SCSI command.
685
static int sym_queue_command(hcb_p np, Scsi_Cmnd *ccb)
687
/* Scsi_Device *device = ccb->device; */
694
* Minimal checkings, so that we will not
695
* go outside our tables.
697
if (ccb->target == np->myaddr ||
698
ccb->target >= SYM_CONF_MAX_TARGET ||
699
ccb->lun >= SYM_CONF_MAX_LUN) {
700
sym_xpt_done2(np, ccb, CAM_DEV_NOT_THERE);
705
* Retreive the target descriptor.
707
tp = &np->target[ccb->target];
710
* Complete the 1st INQUIRY command with error
711
* condition if the device is flagged NOSCAN
712
* at BOOT in the NVRAM. This may speed up
713
* the boot and maintain coherency with BIOS
714
* device numbering. Clearing the flag allows
715
* user to rescan skipped devices later.
716
* We also return error for devices not flagged
717
* for SCAN LUNS in the NVRAM since some mono-lun
718
* devices behave badly when asked for some non
719
* zero LUN. Btw, this is an absolute hack.:-)
721
if (ccb->cmnd[0] == 0x12 || ccb->cmnd[0] == 0x0) {
722
if ((tp->usrflags & SYM_SCAN_BOOT_DISABLED) ||
723
((tp->usrflags & SYM_SCAN_LUNS_DISABLED) &&
725
tp->usrflags &= ~SYM_SCAN_BOOT_DISABLED;
726
sym_xpt_done2(np, ccb, CAM_DEV_NOT_THERE);
732
* Select tagged/untagged.
734
lp = sym_lp(np, tp, ccb->lun);
735
order = (lp && lp->s.reqtags) ? M_SIMPLE_TAG : 0;
740
cp = sym_get_ccb(np, ccb->target, ccb->lun, order);
742
return 1; /* Means resource shortage */
743
(void) sym_queue_scsiio(np, ccb, cp);
748
* Setup buffers and pointers that address the CDB.
750
static int __inline sym_setup_cdb(hcb_p np, Scsi_Cmnd *ccb, ccb_p cp)
756
* CDB is 16 bytes max.
758
if (ccb->cmd_len > sizeof(cp->cdb_buf)) {
759
sym_set_cam_status(cp->cam_ccb, CAM_REQ_INVALID);
763
bcopy(ccb->cmnd, cp->cdb_buf, ccb->cmd_len);
764
cmd_ba = CCB_BA (cp, cdb_buf[0]);
765
cmd_len = ccb->cmd_len;
767
cp->phys.cmd.addr = cpu_to_scr(cmd_ba);
768
cp->phys.cmd.size = cpu_to_scr(cmd_len);
774
* Setup pointers that address the data and start the I/O.
776
int sym_setup_data_and_start(hcb_p np, Scsi_Cmnd *csio, ccb_p cp)
779
tcb_p tp = &np->target[cp->target];
780
lcb_p lp = sym_lp(np, tp, cp->lun);
785
if (sym_setup_cdb(np, csio, cp))
789
* No direction means no data.
791
dir = scsi_data_direction(csio);
792
if (dir != SCSI_DATA_NONE) {
793
cp->segments = sym_scatter (np, cp, csio);
794
if (cp->segments < 0) {
795
if (cp->segments == -2)
796
sym_set_cam_status(csio, CAM_RESRC_UNAVAIL);
798
sym_set_cam_status(csio, CAM_REQ_TOO_BIG);
810
sym_setup_data_pointers(np, cp, dir);
813
* When `#ifed 1', the code below makes the driver
814
* panic on the first attempt to write to a SCSI device.
815
* It is the first test we want to do after a driver
816
* change that does not seem obviously safe. :)
819
switch (cp->cdb_buf[0]) {
820
case 0x0A: case 0x2A: case 0xAA:
821
panic("XXXXXXXXXXXXX WRITE NOT YET ALLOWED XXXXXXXXXXXXXX\n");
833
sym_start_next_ccbs(np, lp, 2);
835
sym_put_start_queue(np, cp);
839
sym_free_ccb(np, cp);
840
sym_xpt_done(np, csio);
848
* Misused to keep the driver running when
849
* interrupts are not configured correctly.
851
static void sym_timer (hcb_p np)
853
u_long thistime = ktime_get(0);
855
#if LINUX_VERSION_CODE < LinuxVersionCode(2, 4, 0)
857
* If release process in progress, let's go
858
* Set the release stage from 1 to 2 to synchronize
859
* with the release process.
862
if (np->s.release_stage) {
863
if (np->s.release_stage == 1)
864
np->s.release_stage = 2;
872
#ifdef SYM_CONF_PCIQ_BROKEN_INTR
873
np->s.timer.expires = ktime_get((HZ+99)/100);
875
np->s.timer.expires = ktime_get(SYM_CONF_TIMER_INTERVAL);
877
add_timer(&np->s.timer);
880
* If we are resetting the ncr, wait for settle_time before
881
* clearing it. Then command processing will be resumed.
883
if (np->s.settle_time_valid) {
884
if (ktime_dif(np->s.settle_time, thistime) <= 0){
885
if (sym_verbose >= 2 )
886
printk("%s: command processing resumed\n",
888
np->s.settle_time_valid = 0;
894
* Nothing to do for now, but that may come.
896
if (np->s.lasttime + 4*HZ < thistime) {
897
np->s.lasttime = thistime;
900
#ifdef SYM_CONF_PCIQ_MAY_MISS_COMPLETIONS
902
* Some way-broken PCI bridges may lead to
903
* completions being lost when the clearing
904
* of the INTFLY flag by the CPU occurs
905
* concurrently with the chip raising this flag.
906
* If this ever happen, lost completions will
912
#ifdef SYM_CONF_PCIQ_BROKEN_INTR
913
if (INB(nc_istat) & (INTF|SIP|DIP)) {
916
** Process pending interrupts.
918
if (DEBUG_FLAGS & DEBUG_TINY) printk ("{");
920
if (DEBUG_FLAGS & DEBUG_TINY) printk ("}");
922
#endif /* SYM_CONF_PCIQ_BROKEN_INTR */
927
* PCI BUS error handler.
929
void sym_log_bus_error(hcb_p np)
932
pci_read_config_word(np->s.device, PCI_STATUS, &pci_sts);
933
if (pci_sts & 0xf900) {
934
pci_write_config_word(np->s.device, PCI_STATUS,
936
printf("%s: PCI STATUS = 0x%04x\n",
937
sym_name(np), pci_sts & 0xf900);
943
* Requeue awaiting commands.
945
static void sym_requeue_awaiting_cmds(hcb_p np)
948
ucmd_p ucp = SYM_UCMD_PTR(cmd);
949
SYM_QUEHEAD tmp_cmdq;
952
sym_que_move(&np->s.wait_cmdq, &tmp_cmdq);
954
while ((ucp = (ucmd_p) sym_remque_head(&tmp_cmdq)) != 0) {
955
sym_insque_tail(&ucp->link_cmdq, &np->s.busy_cmdq);
956
cmd = SYM_SCMD_PTR(ucp);
957
sts = sym_queue_command(np, cmd);
959
sym_remque(&ucp->link_cmdq);
960
sym_insque_head(&ucp->link_cmdq, &np->s.wait_cmdq);
966
* Linux entry point of the queuecommand() function
968
int sym53c8xx_queue_command (Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
970
hcb_p np = SYM_SOFTC_PTR(cmd);
971
ucmd_p ucp = SYM_UCMD_PTR(cmd);
975
cmd->scsi_done = done;
976
cmd->host_scribble = NULL;
977
memset(ucp, 0, sizeof(*ucp));
979
SYM_LOCK_HCB(np, flags);
982
* Shorten our settle_time if needed for
983
* this command not to time out.
985
if (np->s.settle_time_valid && cmd->timeout_per_command) {
986
u_long tlimit = ktime_get(cmd->timeout_per_command);
987
tlimit = ktime_sub(tlimit, SYM_CONF_TIMER_INTERVAL*2);
988
if (ktime_dif(np->s.settle_time, tlimit) > 0) {
989
np->s.settle_time = tlimit;
993
if (np->s.settle_time_valid || !sym_que_empty(&np->s.wait_cmdq)) {
994
sym_insque_tail(&ucp->link_cmdq, &np->s.wait_cmdq);
998
sym_insque_tail(&ucp->link_cmdq, &np->s.busy_cmdq);
999
sts = sym_queue_command(np, cmd);
1001
sym_remque(&ucp->link_cmdq);
1002
sym_insque_tail(&ucp->link_cmdq, &np->s.wait_cmdq);
1005
SYM_UNLOCK_HCB(np, flags);
1011
* Linux entry point of the interrupt handler.
1013
static void sym53c8xx_intr(int irq, void *dev_id, struct pt_regs * regs)
1015
unsigned long flags;
1016
unsigned long flags1;
1017
hcb_p np = (hcb_p) dev_id;
1019
if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("[");
1021
SYM_LOCK_SCSI(np, flags1);
1022
SYM_LOCK_HCB(np, flags);
1026
if (!sym_que_empty(&np->s.wait_cmdq) && !np->s.settle_time_valid)
1027
sym_requeue_awaiting_cmds(np);
1029
SYM_UNLOCK_HCB(np, flags);
1030
SYM_UNLOCK_SCSI(np, flags1);
1032
if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("]\n");
1036
* Linux entry point of the timer handler
1038
static void sym53c8xx_timer(unsigned long npref)
1040
hcb_p np = (hcb_p) npref;
1041
unsigned long flags;
1042
unsigned long flags1;
1044
SYM_LOCK_SCSI(np, flags1);
1045
SYM_LOCK_HCB(np, flags);
1049
if (!sym_que_empty(&np->s.wait_cmdq) && !np->s.settle_time_valid)
1050
sym_requeue_awaiting_cmds(np);
1052
SYM_UNLOCK_HCB(np, flags);
1053
SYM_UNLOCK_SCSI(np, flags1);
1058
* What the eh thread wants us to perform.
1060
#define SYM_EH_ABORT 0
1061
#define SYM_EH_DEVICE_RESET 1
1062
#define SYM_EH_BUS_RESET 2
1063
#define SYM_EH_HOST_RESET 3
1066
* What we will do regarding the involved SCSI command.
1068
#define SYM_EH_DO_IGNORE 0
1069
#define SYM_EH_DO_COMPLETE 1
1070
#define SYM_EH_DO_WAIT 2
1073
* Our general completion handler.
1075
static void __sym_eh_done(Scsi_Cmnd *cmd, int timed_out)
1077
struct sym_eh_wait *ep = SYM_UCMD_PTR(cmd)->eh_wait;
1081
/* Try to avoid a race here (not 100% safe) */
1084
if (ep->to_do == SYM_EH_DO_WAIT && !del_timer(&ep->timer))
1088
/* Revert everything */
1089
SYM_UCMD_PTR(cmd)->eh_wait = 0;
1090
cmd->scsi_done = ep->old_done;
1092
/* Wake up the eh thread if it wants to sleep */
1093
/* SAE: No sleeping... */
1095
if (ep->to_do == SYM_EH_DO_WAIT)
1102
* scsi_done() alias when error recovery is in progress.
1104
static void sym_eh_done(Scsi_Cmnd *cmd) { __sym_eh_done(cmd, 0); }
1107
* Some timeout handler to avoid waiting too long.
1109
static void sym_eh_timeout(u_long p) { __sym_eh_done((Scsi_Cmnd *)p, 1); }
1112
* Generic method for our eh processing.
1113
* The 'op' argument tells what we have to do.
1115
static int sym_eh_handler(int op, char *opname, Scsi_Cmnd *cmd)
1117
hcb_p np = SYM_SOFTC_PTR(cmd);
1118
unsigned long flags;
1120
int to_do = SYM_EH_DO_IGNORE;
1122
struct sym_eh_wait eh, *ep = &eh;
1125
sprintf(devname, "%s:%d:%d", sym_name(np), cmd->target, cmd->lun);
1127
printf_warning("%s: %s operation started.\n", devname, opname);
1129
SYM_LOCK_HCB(np, flags);
1132
/* This one should be the result of some race, thus to ignore */
1133
if (cmd->serial_number != cmd->serial_number_at_timeout)
1137
/* This one is not queued to the core driver -> to complete here */
1138
FOR_EACH_QUEUED_ELEMENT(&np->s.wait_cmdq, qp) {
1139
if (SYM_SCMD_PTR(qp) == cmd) {
1140
to_do = SYM_EH_DO_COMPLETE;
1145
/* This one is queued in some place -> to wait for completion */
1146
FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
1147
ccb_p cp = sym_que_entry(qp, struct sym_ccb, link_ccbq);
1148
if (cp->cam_ccb == cmd) {
1149
to_do = SYM_EH_DO_WAIT;
1155
/* Prepare stuff to either ignore, complete or wait for completion */
1158
case SYM_EH_DO_IGNORE:
1161
case SYM_EH_DO_WAIT:
1164
#if LINUX_VERSION_CODE > LinuxVersionCode(2,3,0)
1165
init_MUTEX_LOCKED(&ep->sem);
1167
ep->sem = MUTEX_LOCKED;
1169
#endif /* XENO_KILLED */
1173
case SYM_EH_DO_COMPLETE:
1174
ep->old_done = cmd->scsi_done;
1175
cmd->scsi_done = sym_eh_done;
1176
SYM_UCMD_PTR(cmd)->eh_wait = ep;
1179
/* Try to proceed the operation we have been asked for */
1183
sts = sym_abort_scsiio(np, cmd, 1);
1185
case SYM_EH_DEVICE_RESET:
1186
sts = sym_reset_scsi_target(np, cmd->target);
1188
case SYM_EH_BUS_RESET:
1189
sym_reset_scsi_bus(np, 1);
1192
case SYM_EH_HOST_RESET:
1193
sym_reset_scsi_bus(np, 0);
1194
sym_start_up (np, 1);
1201
/* On error, restore everything and cross fingers :) */
1203
SYM_UCMD_PTR(cmd)->eh_wait = 0;
1204
cmd->scsi_done = ep->old_done;
1205
to_do = SYM_EH_DO_IGNORE;
1210
/* Complete the command with locks held as required by the driver */
1211
if (to_do == SYM_EH_DO_COMPLETE)
1212
sym_xpt_done2(np, cmd, CAM_REQ_ABORTED);
1214
SYM_UNLOCK_HCB(np, flags);
1216
/* Wait for completion with locks released, as required by kernel */
1217
if (to_do == SYM_EH_DO_WAIT) {
1220
init_timer(&ep->timer);
1221
ep->timer.expires = jiffies + (5*HZ);
1222
ep->timer.function = sym_eh_timeout;
1223
ep->timer.data = (u_long)cmd;
1224
ep->timed_out = 1; /* Be pessimistic for once :) */
1225
add_timer(&ep->timer);
1226
SYM_UNLOCK_SCSI_NORESTORE(np);
1228
SYM_LOCK_SCSI_NOSAVE(np);
1235
printf_warning("%s: %s operation %s.\n", devname, opname,
1236
sts==0?"complete":sts==-2?"timed-out":"failed");
1237
return sts? SCSI_FAILED : SCSI_SUCCESS;
1242
* Error handlers called from the eh thread (one thread per HBA).
1244
int sym53c8xx_eh_abort_handler(Scsi_Cmnd *cmd)
1246
return sym_eh_handler(SYM_EH_ABORT, "ABORT", cmd);
1249
int sym53c8xx_eh_device_reset_handler(Scsi_Cmnd *cmd)
1251
return sym_eh_handler(SYM_EH_DEVICE_RESET, "DEVICE RESET", cmd);
1254
int sym53c8xx_eh_bus_reset_handler(Scsi_Cmnd *cmd)
1256
return sym_eh_handler(SYM_EH_BUS_RESET, "BUS RESET", cmd);
1259
int sym53c8xx_eh_host_reset_handler(Scsi_Cmnd *cmd)
1261
return sym_eh_handler(SYM_EH_HOST_RESET, "HOST RESET", cmd);
1265
* Tune device queuing depth, according to various limits.
1268
sym_tune_dev_queuing(hcb_p np, int target, int lun, u_short reqtags)
1270
tcb_p tp = &np->target[target];
1271
lcb_p lp = sym_lp(np, tp, lun);
1277
oldtags = lp->s.reqtags;
1279
if (reqtags > lp->s.scdev_depth)
1280
reqtags = lp->s.scdev_depth;
1282
lp->started_limit = reqtags ? reqtags : 2;
1283
lp->started_max = 1;
1284
lp->s.reqtags = reqtags;
1286
if (reqtags != oldtags) {
1287
printf_info("%s:%d:%d: "
1288
"tagged command queuing %s, command queue depth %d.\n",
1289
sym_name(np), target, lun,
1290
lp->s.reqtags ? "enabled" : "disabled",
1295
#ifdef SYM_LINUX_BOOT_COMMAND_LINE_SUPPORT
1297
* Linux select queue depths function
1299
#define DEF_DEPTH (sym_driver_setup.max_tag)
1300
#define ALL_TARGETS -2
1301
#define NO_TARGET -1
1305
static int device_queue_depth(hcb_p np, int target, int lun)
1308
char *p = sym_driver_setup.tag_ctrl;
1314
while ((c = *p++) != 0) {
1315
v = simple_strtoul(p, &ep, 0);
1324
t = (target == v) ? v : NO_TARGET;
1329
u = (lun == v) ? v : NO_LUN;
1332
if (h == np->s.unit &&
1333
(t == ALL_TARGETS || t == target) &&
1334
(u == ALL_LUNS || u == lun))
1349
#define device_queue_depth(np, t, l) (sym_driver_setup.max_tag)
1350
#endif /* SYM_LINUX_BOOT_COMMAND_LINE_SUPPORT */
1353
* Linux entry point for device queue sizing.
1356
sym53c8xx_select_queue_depths(struct Scsi_Host *host,
1357
struct scsi_device *devlist)
1359
struct scsi_device *device;
1361
for (device = devlist; device; device = device->next) {
1367
if (device->host != host)
1370
np = ((struct host_data *) host->hostdata)->ncb;
1371
tp = &np->target[device->id];
1374
* Get user settings for transfer parameters.
1376
tp->inq_byte7_valid = (INQ7_SYNC|INQ7_WIDE16);
1377
sym_update_trans_settings(np, tp);
1380
* Allocate the LCB if not yet.
1381
* If it fail, we may well be in the sh*t. :)
1383
lp = sym_alloc_lcb(np, device->id, device->lun);
1385
device->queue_depth = 1;
1392
lp->curr_flags = lp->user_flags;
1395
* Select queue depth from driver setup.
1396
* Donnot use more than configured by user.
1398
* Donnot use more than our maximum.
1400
reqtags = device_queue_depth(np, device->id, device->lun);
1401
if (reqtags > tp->usrtags)
1402
reqtags = tp->usrtags;
1403
if (!device->tagged_supported)
1405
#if 1 /* Avoid to locally queue commands for no good reasons */
1406
if (reqtags > SYM_CONF_MAX_TAG)
1407
reqtags = SYM_CONF_MAX_TAG;
1408
device->queue_depth = reqtags ? reqtags : 2;
1410
device->queue_depth = reqtags ? SYM_CONF_MAX_TAG : 2;
1412
lp->s.scdev_depth = device->queue_depth;
1413
sym_tune_dev_queuing(np, device->id, device->lun, reqtags);
1418
* Linux entry point for info() function
1420
const char *sym53c8xx_info (struct Scsi_Host *host)
1422
return sym_driver_name();
1426
#ifdef SYM_LINUX_PROC_INFO_SUPPORT
1428
* Proc file system stuff
1430
* A read operation returns adapter information.
1431
* A write operation is a control command.
1432
* The string is parsed in the driver code and the command is passed
1433
* to the sym_usercmd() function.
1436
#ifdef SYM_LINUX_USER_COMMAND_SUPPORT
1445
#define UC_SETSYNC 10
1446
#define UC_SETTAGS 11
1447
#define UC_SETDEBUG 12
1448
#define UC_SETWIDE 14
1449
#define UC_SETFLAG 15
1450
#define UC_SETVERBOSE 17
1451
#define UC_RESETDEV 18
1452
#define UC_CLEARDEV 19
1454
static void sym_exec_user_command (hcb_p np, struct sym_usrcmd *uc)
1462
#ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1464
sym_debug_flags = uc->data;
1468
np->verbose = uc->data;
1472
* We assume that other commands apply to targets.
1473
* This should always be the case and avoid the below
1474
* 4 lines to be repeated 6 times.
1476
for (t = 0; t < SYM_CONF_MAX_TARGET; t++) {
1477
if (!((uc->target >> t) & 1))
1479
tp = &np->target[t];
1484
if (!uc->data || uc->data >= 255) {
1485
tp->tinfo.goal.options = 0;
1486
tp->tinfo.goal.offset = 0;
1489
if (uc->data <= 9 && np->minsync_dt) {
1490
if (uc->data < np->minsync_dt)
1491
uc->data = np->minsync_dt;
1492
tp->tinfo.goal.options = PPR_OPT_DT;
1493
tp->tinfo.goal.width = 1;
1494
tp->tinfo.goal.period = uc->data;
1495
tp->tinfo.goal.offset = np->maxoffs_dt;
1498
if (uc->data < np->minsync)
1499
uc->data = np->minsync;
1500
tp->tinfo.goal.options = 0;
1501
tp->tinfo.goal.period = uc->data;
1502
tp->tinfo.goal.offset = np->maxoffs;
1506
tp->tinfo.goal.width = uc->data ? 1 : 0;
1509
for (l = 0; l < SYM_CONF_MAX_LUN; l++)
1510
sym_tune_dev_queuing(np, t,l, uc->data);
1514
np->istat_sem = SEM;
1515
OUTB (nc_istat, SIGP|SEM);
1518
for (l = 0; l < SYM_CONF_MAX_LUN; l++) {
1519
lcb_p lp = sym_lp(np, tp, l);
1520
if (lp) lp->to_clear = 1;
1522
np->istat_sem = SEM;
1523
OUTB (nc_istat, SIGP|SEM);
1526
tp->usrflags = uc->data;
1534
#define is_digit(c) ((c) >= '0' && (c) <= '9')
1535
#define digit_to_bin(c) ((c) - '0')
1536
#define is_space(c) ((c) == ' ' || (c) == '\t')
1538
static int skip_spaces(char *ptr, int len)
1542
for (cnt = len; cnt > 0 && (c = *ptr++) && is_space(c); cnt--);
1547
static int get_int_arg(char *ptr, int len, u_long *pv)
1552
for (v = 0, cnt = len; cnt > 0 && (c = *ptr++) && is_digit(c); cnt--) {
1553
v = (v * 10) + digit_to_bin(c);
1562
static int is_keyword(char *ptr, int len, char *verb)
1564
int verb_len = strlen(verb);
1566
if (len >= strlen(verb) && !memcmp(verb, ptr, verb_len))
1573
#define SKIP_SPACES(min_spaces) \
1574
if ((arg_len = skip_spaces(ptr, len)) < (min_spaces)) \
1576
ptr += arg_len; len -= arg_len;
1578
#define GET_INT_ARG(v) \
1579
if (!(arg_len = get_int_arg(ptr, len, &(v)))) \
1581
ptr += arg_len; len -= arg_len;
1585
* Parse a control command
1588
static int sym_user_command(hcb_p np, char *buffer, int length)
1592
struct sym_usrcmd cmd, *uc = &cmd;
1596
bzero(uc, sizeof(*uc));
1598
if (len > 0 && ptr[len-1] == '\n')
1601
if ((arg_len = is_keyword(ptr, len, "setsync")) != 0)
1602
uc->cmd = UC_SETSYNC;
1603
else if ((arg_len = is_keyword(ptr, len, "settags")) != 0)
1604
uc->cmd = UC_SETTAGS;
1605
else if ((arg_len = is_keyword(ptr, len, "setverbose")) != 0)
1606
uc->cmd = UC_SETVERBOSE;
1607
else if ((arg_len = is_keyword(ptr, len, "setwide")) != 0)
1608
uc->cmd = UC_SETWIDE;
1609
#ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1610
else if ((arg_len = is_keyword(ptr, len, "setdebug")) != 0)
1611
uc->cmd = UC_SETDEBUG;
1613
else if ((arg_len = is_keyword(ptr, len, "setflag")) != 0)
1614
uc->cmd = UC_SETFLAG;
1615
else if ((arg_len = is_keyword(ptr, len, "resetdev")) != 0)
1616
uc->cmd = UC_RESETDEV;
1617
else if ((arg_len = is_keyword(ptr, len, "cleardev")) != 0)
1618
uc->cmd = UC_CLEARDEV;
1622
#ifdef DEBUG_PROC_INFO
1623
printk("sym_user_command: arg_len=%d, cmd=%ld\n", arg_len, uc->cmd);
1628
ptr += arg_len; len -= arg_len;
1638
if ((arg_len = is_keyword(ptr, len, "all")) != 0) {
1639
ptr += arg_len; len -= arg_len;
1642
GET_INT_ARG(target);
1643
uc->target = (1<<target);
1644
#ifdef DEBUG_PROC_INFO
1645
printk("sym_user_command: target=%ld\n", target);
1657
GET_INT_ARG(uc->data);
1658
#ifdef DEBUG_PROC_INFO
1659
printk("sym_user_command: data=%ld\n", uc->data);
1662
#ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1666
if ((arg_len = is_keyword(ptr, len, "alloc")))
1667
uc->data |= DEBUG_ALLOC;
1668
else if ((arg_len = is_keyword(ptr, len, "phase")))
1669
uc->data |= DEBUG_PHASE;
1670
else if ((arg_len = is_keyword(ptr, len, "queue")))
1671
uc->data |= DEBUG_QUEUE;
1672
else if ((arg_len = is_keyword(ptr, len, "result")))
1673
uc->data |= DEBUG_RESULT;
1674
else if ((arg_len = is_keyword(ptr, len, "scatter")))
1675
uc->data |= DEBUG_SCATTER;
1676
else if ((arg_len = is_keyword(ptr, len, "script")))
1677
uc->data |= DEBUG_SCRIPT;
1678
else if ((arg_len = is_keyword(ptr, len, "tiny")))
1679
uc->data |= DEBUG_TINY;
1680
else if ((arg_len = is_keyword(ptr, len, "timing")))
1681
uc->data |= DEBUG_TIMING;
1682
else if ((arg_len = is_keyword(ptr, len, "nego")))
1683
uc->data |= DEBUG_NEGO;
1684
else if ((arg_len = is_keyword(ptr, len, "tags")))
1685
uc->data |= DEBUG_TAGS;
1686
else if ((arg_len = is_keyword(ptr, len, "pointer")))
1687
uc->data |= DEBUG_POINTER;
1690
ptr += arg_len; len -= arg_len;
1692
#ifdef DEBUG_PROC_INFO
1693
printk("sym_user_command: data=%ld\n", uc->data);
1696
#endif /* SYM_LINUX_DEBUG_CONTROL_SUPPORT */
1700
if ((arg_len = is_keyword(ptr, len, "no_disc")))
1701
uc->data &= ~SYM_DISC_ENABLED;
1704
ptr += arg_len; len -= arg_len;
1716
SYM_LOCK_HCB(np, flags);
1717
sym_exec_user_command (np, uc);
1718
SYM_UNLOCK_HCB(np, flags);
1723
#endif /* SYM_LINUX_USER_COMMAND_SUPPORT */
1726
#ifdef SYM_LINUX_USER_INFO_SUPPORT
1728
* Informations through the proc file system.
1737
static void copy_mem_info(struct info_str *info, char *data, int len)
1739
if (info->pos + len > info->length)
1740
len = info->length - info->pos;
1742
if (info->pos + len < info->offset) {
1746
if (info->pos < info->offset) {
1747
data += (info->offset - info->pos);
1748
len -= (info->offset - info->pos);
1752
memcpy(info->buffer + info->pos, data, len);
1757
static int copy_info(struct info_str *info, char *fmt, ...)
1763
va_start(args, fmt);
1764
len = vsprintf(buf, fmt, args);
1767
copy_mem_info(info, buf, len);
1772
* Copy formatted information into the input buffer.
1774
/* SAE: Again with the off_t */
1778
static int sym_host_info(hcb_p np, char *ptr, off_t offset, int len)
1780
struct info_str info;
1784
info.offset = offset;
1787
copy_info(&info, "Chip " NAME53C "%s, device id 0x%x, "
1788
"revision id 0x%x\n",
1789
np->s.chip_name, np->device_id, np->revision_id);
1790
copy_info(&info, "On PCI bus %d, device %d, function %d, "
1796
np->s.bus, (np->s.device_fn & 0xf8) >> 3, np->s.device_fn & 7,
1798
__irq_itoa(np->s.irq));
1802
copy_info(&info, "Min. period factor %d, %s SCSI BUS%s\n",
1803
(int) (np->minsync_dt ? np->minsync_dt : np->minsync),
1804
np->maxwide ? "Wide" : "Narrow",
1805
np->minsync_dt ? ", DT capable" : "");
1807
copy_info(&info, "Max. started commands %d, "
1808
"max. commands per LUN %d\n",
1809
SYM_CONF_MAX_START, SYM_CONF_MAX_TAG);
1811
return info.pos > info.offset? info.pos - info.offset : 0;
1813
#endif /* SYM_LINUX_USER_INFO_SUPPORT */
1816
* Entry point of the scsi proc fs of the driver.
1817
* - func = 0 means read (returns adapter infos)
1818
* - func = 1 means write (not yet merget from sym53c8xx)
1820
static int sym53c8xx_proc_info(char *buffer, char **start, off_t offset,
1821
int length, int hostno, int func)
1823
struct Scsi_Host *host;
1824
struct host_data *host_data;
1828
for (host = first_host; host; host = host->next) {
1829
if (host->hostt != first_host->hostt)
1831
if (host->host_no == hostno) {
1832
host_data = (struct host_data *) host->hostdata;
1833
np = host_data->ncb;
1842
#ifdef SYM_LINUX_USER_COMMAND_SUPPORT
1843
retv = sym_user_command(np, buffer, length);
1851
#ifdef SYM_LINUX_USER_INFO_SUPPORT
1852
retv = sym_host_info(np, buffer, offset, length);
1860
#endif /* SYM_LINUX_PROC_INFO_SUPPORT */
1863
* Free controller resources.
1865
static void sym_free_resources(hcb_p np)
1868
* Free O/S specific resources.
1871
free_irq(np->s.irq, np);
1873
release_region(np->s.io_port, np->s.io_ws);
1874
#ifndef SYM_OPT_NO_BUS_MEMORY_MAPPING
1876
pci_unmap_mem(np->s.mmio_va, np->s.io_ws);
1878
pci_unmap_mem(np->s.ram_va, np->ram_ws);
1881
* Free O/S independant resources.
1885
sym_mfree_dma(np, sizeof(*np), "HCB");
1889
* Ask/tell the system about DMA addressing.
1891
#ifdef SYM_LINUX_DYNAMIC_DMA_MAPPING
1892
static int sym_setup_bus_dma_mask(hcb_p np)
1894
#if LINUX_VERSION_CODE < LinuxVersionCode(2,4,3)
1895
if (!pci_dma_supported(np->s.device, 0xffffffffUL))
1898
#if SYM_CONF_DMA_ADDRESSING_MODE == 0
1899
if (pci_set_dma_mask(np->s.device, 0xffffffffUL))
1902
#if SYM_CONF_DMA_ADDRESSING_MODE == 1
1903
#define PciDmaMask 0xffffffffff
1904
#elif SYM_CONF_DMA_ADDRESSING_MODE == 2
1905
#define PciDmaMask 0xffffffffffffffff
1907
if (np->features & FE_DAC) {
1908
if (!pci_set_dma_mask(np->s.device, PciDmaMask)) {
1910
printf_info("%s: using 64 bit DMA addressing\n",
1914
if (pci_set_dma_mask(np->s.device, 0xffffffffUL))
1924
printf_warning("%s: 32 BIT DMA ADDRESSING NOT SUPPORTED\n",
1928
#endif /* SYM_LINUX_DYNAMIC_DMA_MAPPING */
1931
* Host attach and initialisations.
1933
* Allocate host data and ncb structure.
1934
* Request IO region and remap MMIO region.
1935
* Do chip initialization.
1936
* If all is OK, install interrupt handling and
1937
* start the timer daemon.
1940
sym_attach (Scsi_Host_Template *tpnt, int unit, sym_device *dev)
1942
struct host_data *host_data;
1944
struct Scsi_Host *instance = 0;
1946
sym_nvram *nvram = dev->nvram;
1950
"sym%d: <%s> rev 0x%x on pci bus %d device %d function %d "
1952
unit, dev->chip.name, dev->chip.revision_id,
1953
dev->s.bus, (dev->s.device_fn & 0xf8) >> 3,
1954
dev->s.device_fn & 7,
1957
/* SAE: No sparc in Xen... */
1964
unit, dev->chip.name, dev->chip.revision_id,
1965
dev->s.bus, (dev->s.device_fn & 0xf8) >> 3,
1966
dev->s.device_fn & 7,
1968
__irq_itoa(dev->s.irq));
1972
#endif /* XENO_KILLED */
1975
* Get the firmware for this chip.
1977
fw = sym_find_firmware(&dev->chip);
1982
* Allocate host_data structure
1984
if (!(instance = scsi_register(tpnt, sizeof(*host_data))))
1986
host_data = (struct host_data *) instance->hostdata;
1989
* Allocate immediately the host control block,
1990
* since we are only expecting to succeed. :)
1991
* We keep track in the HCB of all the resources that
1992
* are to be released on error.
1994
#ifdef SYM_LINUX_DYNAMIC_DMA_MAPPING
1995
np = __sym_calloc_dma(dev->pdev, sizeof(*np), "HCB");
1997
np->s.device = dev->pdev;
1998
np->bus_dmat = dev->pdev; /* Result in 1 DMA pool per HBA */
2003
np = sym_calloc_dma(sizeof(*np), "HCB");
2007
host_data->ncb = np;
2009
SYM_INIT_LOCK_HCB(np);
2012
* Copy some useful infos to the HCB.
2014
np->hcb_ba = vtobus(np);
2015
np->verbose = sym_driver_setup.verbose;
2016
np->s.device = dev->pdev;
2018
np->device_id = dev->chip.device_id;
2019
np->revision_id = dev->chip.revision_id;
2020
np->s.bus = dev->s.bus;
2021
np->s.device_fn = dev->s.device_fn;
2022
np->features = dev->chip.features;
2023
np->clock_divn = dev->chip.nr_divisor;
2024
np->maxoffs = dev->chip.offset_max;
2025
np->maxburst = dev->chip.burst_max;
2026
np->myaddr = dev->host_id;
2031
strncpy(np->s.chip_name, dev->chip.name, sizeof(np->s.chip_name)-1);
2032
sprintf(np->s.inst_name, "sym%d", np->s.unit);
2035
* Ask/tell the system about DMA addressing.
2037
#ifdef SYM_LINUX_DYNAMIC_DMA_MAPPING
2038
if (sym_setup_bus_dma_mask(np))
2043
* Try to map the controller chip to
2044
* virtual and physical memory.
2046
np->mmio_ba = (u32)dev->s.base;
2047
np->s.io_ws = (np->features & FE_IO256)? 256 : 128;
2049
#ifndef SYM_CONF_IOMAPPED
2050
np->s.mmio_va = pci_map_mem(dev->s.base_c, np->s.io_ws);
2051
if (!np->s.mmio_va) {
2052
printf_err("%s: can't map PCI MMIO region\n", sym_name(np));
2055
else if (sym_verbose > 1)
2056
printf_info("%s: using memory mapped IO\n", sym_name(np));
2057
#endif /* !defined SYM_CONF_IOMAPPED */
2060
* Try to map the controller chip into iospace.
2062
if (dev->s.io_port) {
2063
request_region(dev->s.io_port, np->s.io_ws, NAME53C8XX);
2064
np->s.io_port = dev->s.io_port;
2068
* Map on-chip RAM if present and supported.
2070
if (!(np->features & FE_RAM))
2072
if (dev->s.base_2) {
2073
np->ram_ba = (u32)dev->s.base_2;
2074
if (np->features & FE_RAM8K)
2078
#ifndef SYM_OPT_NO_BUS_MEMORY_MAPPING
2079
np->s.ram_va = pci_map_mem(dev->s.base_2_c, np->ram_ws);
2080
if (!np->s.ram_va) {
2081
printf_err("%s: can't map PCI MEMORY region\n",
2089
* Perform O/S independant stuff.
2091
if (sym_hcb_attach(np, fw, nvram))
2096
* Install the interrupt handler.
2097
* If we synchonize the C code with SCRIPTS on interrupt,
2098
* we donnot want to share the INTR line at all.
2100
if (request_irq(dev->s.irq, sym53c8xx_intr, SA_SHIRQ,
2102
printf_err("%s: request irq %d failure\n",
2103
sym_name(np), dev->s.irq);
2106
np->s.irq = dev->s.irq;
2109
* After SCSI devices have been opened, we cannot
2110
* reset the bus safely, so we do it here.
2112
SYM_LOCK_HCB(np, flags);
2113
if (sym_reset_scsi_bus(np, 0)) {
2114
printf_err("%s: FATAL ERROR: CHECK SCSI BUS - CABLES, "
2115
"TERMINATION, DEVICE POWER etc.!\n", sym_name(np));
2116
SYM_UNLOCK_HCB(np, flags);
2121
* Initialize some queue headers.
2123
sym_que_init(&np->s.wait_cmdq);
2124
sym_que_init(&np->s.busy_cmdq);
2127
* Start the SCRIPTS.
2129
sym_start_up (np, 1);
2132
* Start the timer daemon
2134
init_timer(&np->s.timer);
2135
np->s.timer.data = (unsigned long) np;
2136
np->s.timer.function = sym53c8xx_timer;
2144
first_host = instance;
2147
* Fill Linux host instance structure
2148
* and return success.
2150
instance->max_channel = 0;
2151
instance->this_id = np->myaddr;
2152
instance->max_id = np->maxwide ? 16 : 8;
2153
instance->max_lun = SYM_CONF_MAX_LUN;
2154
#ifndef SYM_CONF_IOMAPPED
2155
#if LINUX_VERSION_CODE >= LinuxVersionCode(2,3,29)
2156
instance->base = (unsigned long) np->s.mmio_va;
2158
instance->base = (char *) np->s.mmio_va;
2161
instance->irq = np->s.irq;
2162
instance->unique_id = np->s.io_port;
2163
instance->io_port = np->s.io_port;
2164
instance->n_io_port = np->s.io_ws;
2165
instance->dma_channel = 0;
2166
instance->cmd_per_lun = SYM_CONF_MAX_TAG;
2167
instance->can_queue = (SYM_CONF_MAX_START-2);
2168
instance->sg_tablesize = SYM_CONF_MAX_SG;
2169
#if LINUX_VERSION_CODE >= LinuxVersionCode(2,4,0)
2170
instance->max_cmd_len = 16;
2172
instance->select_queue_depths = sym53c8xx_select_queue_depths;
2175
instance->highmem_io = 1;
2178
SYM_UNLOCK_HCB(np, flags);
2180
scsi_set_pci_device(instance, dev->pdev);
2183
* Now let the generic SCSI driver
2184
* look for the SCSI devices on the bus ..
2189
if (!instance) return -1;
2190
printf_info("%s: giving up ...\n", sym_name(np));
2192
sym_free_resources(np);
2193
scsi_unregister(instance);
2200
* Detect and try to read SYMBIOS and TEKRAM NVRAM.
2202
#if SYM_CONF_NVRAM_SUPPORT
2203
static void __init sym_get_nvram(sym_device *devp, sym_nvram *nvp)
2209
devp->device_id = devp->chip.device_id;
2213
* Get access to chip IO registers
2215
#ifdef SYM_CONF_IOMAPPED
2216
request_region(devp->s.io_port, 128, NAME53C8XX);
2218
devp->s.mmio_va = pci_map_mem(devp->s.base_c, 128);
2219
if (!devp->s.mmio_va)
2224
* Try to read SYMBIOS|TEKRAM nvram.
2226
(void) sym_read_nvram(devp, nvp);
2229
* Release access to chip IO registers
2231
#ifdef SYM_CONF_IOMAPPED
2232
release_region(devp->s.io_port, 128);
2234
pci_unmap_mem((u_long) devp->s.mmio_va, 128ul);
2237
#endif /* SYM_CONF_NVRAM_SUPPORT */
2240
* Driver setup from the boot command line
2242
#ifdef SYM_LINUX_BOOT_COMMAND_LINE_SUPPORT
2244
static struct sym_driver_setup
2245
sym_driver_safe_setup __initdata = SYM_LINUX_DRIVER_SAFE_SETUP;
2247
char *sym53c8xx = 0; /* command line passed by insmod */
2248
MODULE_PARM(sym53c8xx, "s");
2251
static void __init sym53c8xx_print_driver_setup(void)
2253
printf_info (NAME53C8XX ": setup="
2254
"mpar:%d,spar:%d,tags:%d,sync:%d,burst:%d,"
2255
"led:%d,wide:%d,diff:%d,irqm:%d, buschk:%d\n",
2256
sym_driver_setup.pci_parity,
2257
sym_driver_setup.scsi_parity,
2258
sym_driver_setup.max_tag,
2259
sym_driver_setup.min_sync,
2260
sym_driver_setup.burst_order,
2261
sym_driver_setup.scsi_led,
2262
sym_driver_setup.max_wide,
2263
sym_driver_setup.scsi_diff,
2264
sym_driver_setup.irq_mode,
2265
sym_driver_setup.scsi_bus_check);
2266
printf_info (NAME53C8XX ": setup="
2267
"hostid:%d,offs:%d,luns:%d,pcifix:%d,revprob:%d,"
2268
"verb:%d,debug:0x%x,setlle_delay:%d\n",
2269
sym_driver_setup.host_id,
2270
sym_driver_setup.max_offs,
2271
sym_driver_setup.max_lun,
2272
sym_driver_setup.pci_fix_up,
2273
sym_driver_setup.reverse_probe,
2274
sym_driver_setup.verbose,
2275
sym_driver_setup.debug,
2276
sym_driver_setup.settle_delay);
2282
#define OPT_PCI_PARITY 1
2283
#define OPT_SCSI_PARITY 2
2284
#define OPT_MAX_TAG 3
2285
#define OPT_MIN_SYNC 4
2286
#define OPT_BURST_ORDER 5
2287
#define OPT_SCSI_LED 6
2288
#define OPT_MAX_WIDE 7
2289
#define OPT_SCSI_DIFF 8
2290
#define OPT_IRQ_MODE 9
2291
#define OPT_SCSI_BUS_CHECK 10
2292
#define OPT_HOST_ID 11
2293
#define OPT_MAX_OFFS 12
2294
#define OPT_MAX_LUN 13
2295
#define OPT_PCI_FIX_UP 14
2297
#define OPT_REVERSE_PROBE 15
2298
#define OPT_VERBOSE 16
2299
#define OPT_DEBUG 17
2300
#define OPT_SETTLE_DELAY 18
2301
#define OPT_USE_NVRAM 19
2302
#define OPT_EXCLUDE 20
2303
#define OPT_SAFE_SETUP 21
2305
static char setup_token[] __initdata =
2325
static int __init get_setup_token(char *p)
2327
char *cur = setup_token;
2331
while (cur != NULL && (pc = strchr(cur, ':')) != NULL) {
2334
if (!strncmp(p, cur, pc - cur))
2340
#endif /* SYM_LINUX_BOOT_COMMAND_LINE_SUPPORT */
2342
int __init sym53c8xx_setup(char *str)
2344
#ifdef SYM_LINUX_BOOT_COMMAND_LINE_SUPPORT
2351
while (cur != NULL && (pc = strchr(cur, ':')) != NULL) {
2363
val = (int) simple_strtoul(pv, &pe, 0);
2365
switch (get_setup_token(cur)) {
2367
sym_driver_setup.max_tag = val;
2368
if (!(pe && *pe == '/'))
2371
while (*pe && *pe != ARG_SEP &&
2372
i < sizeof(sym_driver_setup.tag_ctrl)-1) {
2373
sym_driver_setup.tag_ctrl[i++] = *pe++;
2375
sym_driver_setup.tag_ctrl[i] = '\0';
2377
case OPT_SAFE_SETUP:
2378
memcpy(&sym_driver_setup, &sym_driver_safe_setup,
2379
sizeof(sym_driver_setup));
2383
sym_driver_setup.excludes[xi++] = val;
2386
#define __SIMPLE_OPTION(NAME, name) \
2387
case OPT_ ## NAME : \
2388
sym_driver_setup.name = val;\
2391
__SIMPLE_OPTION(PCI_PARITY, pci_parity)
2392
__SIMPLE_OPTION(SCSI_PARITY, scsi_parity)
2393
__SIMPLE_OPTION(MIN_SYNC, min_sync)
2394
__SIMPLE_OPTION(BURST_ORDER, burst_order)
2395
__SIMPLE_OPTION(SCSI_LED, scsi_led)
2396
__SIMPLE_OPTION(MAX_WIDE, max_wide)
2397
__SIMPLE_OPTION(SCSI_DIFF, scsi_diff)
2398
__SIMPLE_OPTION(IRQ_MODE, irq_mode)
2399
__SIMPLE_OPTION(SCSI_BUS_CHECK, scsi_bus_check)
2400
__SIMPLE_OPTION(HOST_ID, host_id)
2401
__SIMPLE_OPTION(MAX_OFFS, max_offs)
2402
__SIMPLE_OPTION(MAX_LUN, max_lun)
2403
__SIMPLE_OPTION(PCI_FIX_UP, pci_fix_up)
2404
__SIMPLE_OPTION(REVERSE_PROBE, reverse_probe)
2405
__SIMPLE_OPTION(VERBOSE, verbose)
2406
__SIMPLE_OPTION(DEBUG, debug)
2407
__SIMPLE_OPTION(SETTLE_DELAY, settle_delay)
2408
__SIMPLE_OPTION(USE_NVRAM, use_nvram)
2410
#undef __SIMPLE_OPTION
2413
printk("sym53c8xx_setup: unexpected boot option '%.*s' ignored\n", (int)(pc-cur+1), cur);
2417
if ((cur = strchr(cur, ARG_SEP)) != NULL)
2420
#endif /* SYM_LINUX_BOOT_COMMAND_LINE_SUPPORT */
2424
#if LINUX_VERSION_CODE >= LinuxVersionCode(2,3,13)
2426
__setup("sym53c8xx=", sym53c8xx_setup);
2430
#ifdef SYM_CONF_PQS_PDS_SUPPORT
2432
* Detect all NCR PQS/PDS boards and keep track of their bus nr.
2434
* The NCR PQS or PDS card is constructed as a DEC bridge
2435
* behind which sit a proprietary NCR memory controller and
2436
* four or two 53c875s as separate devices. In its usual mode
2437
* of operation, the 875s are slaved to the memory controller
2438
* for all transfers. We can tell if an 875 is part of a
2439
* PQS/PDS or not since if it is, it will be on the same bus
2440
* as the memory controller. To operate with the Linux
2441
* driver, the memory controller is disabled and the 875s
2442
* freed to function independently. The only wrinkle is that
2443
* the preset SCSI ID (which may be zero) must be read in from
2444
* a special configuration space register of the 875
2446
#ifndef SYM_CONF_MAX_PQS_BUS
2447
#define SYM_CONF_MAX_PQS_BUS 16
2449
static int pqs_bus[SYM_CONF_MAX_PQS_BUS] __initdata = { 0 };
2451
static void __init sym_detect_pqs_pds(void)
2454
pcidev_t dev = PCIDEV_NULL;
2456
for(index=0; index < SYM_CONF_MAX_PQS_BUS; index++) {
2459
dev = pci_find_device(0x101a, 0x0009, dev);
2460
if (dev == PCIDEV_NULL) {
2461
pqs_bus[index] = -1;
2464
printf_info(NAME53C8XX ": NCR PQS/PDS memory controller detected on bus %d\n", PciBusNumber(dev));
2465
pci_read_config_byte(dev, 0x44, &tmp);
2466
/* bit 1: allow individual 875 configuration */
2468
pci_write_config_byte(dev, 0x44, tmp);
2469
pci_read_config_byte(dev, 0x45, &tmp);
2470
/* bit 2: drive individual 875 interrupts to the bus */
2472
pci_write_config_byte(dev, 0x45, tmp);
2474
pqs_bus[index] = PciBusNumber(dev);
2477
#endif /* SYM_CONF_PQS_PDS_SUPPORT */
2480
* Read and check the PCI configuration for any detected NCR
2481
* boards and save data for attaching after all boards have
2485
sym53c8xx_pci_init(Scsi_Host_Template *tpnt, pcidev_t pdev, sym_device *device)
2487
u_short vendor_id, device_id, command, status_reg;
2488
u_char cache_line_size;
2489
u_char suggested_cache_line_size = 0;
2490
u_char pci_fix_up = SYM_SETUP_PCI_FIX_UP;
2493
u_long base, base_2, base_io;
2494
u_long base_c, base_2_c, io_port;
2498
/* Choose some short name for this device */
2499
sprintf(device->s.inst_name, "sym.%d.%d.%d",
2501
(int) (PciDeviceFn(pdev) & 0xf8) >> 3,
2502
(int) (PciDeviceFn(pdev) & 7));
2505
* Read needed minimal info from the PCI config space.
2507
vendor_id = PciVendorId(pdev);
2508
device_id = PciDeviceId(pdev);
2509
irq = PciIrqLine(pdev);
2511
i = pci_get_base_address(pdev, 0, &base_io);
2512
io_port = pci_get_base_cookie(pdev, 0);
2514
base_c = pci_get_base_cookie(pdev, i);
2515
i = pci_get_base_address(pdev, i, &base);
2517
base_2_c = pci_get_base_cookie(pdev, i);
2518
(void) pci_get_base_address(pdev, i, &base_2);
2520
io_port &= PCI_BASE_ADDRESS_IO_MASK;
2521
base &= PCI_BASE_ADDRESS_MEM_MASK;
2522
base_2 &= PCI_BASE_ADDRESS_MEM_MASK;
2524
pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
2527
* If user excluded this chip, donnot initialize it.
2530
for (i = 0 ; i < 8 ; i++) {
2531
if (sym_driver_setup.excludes[i] == base_io)
2537
* Leave here if another driver attached the chip.
2539
if (io_port && check_region (io_port, 128)) {
2540
printf_info("%s: IO region 0x%lx[0..127] is in use\n",
2541
sym_name(device), (long) io_port);
2546
* Check if the chip is supported.
2548
chip = sym_lookup_pci_chip_table(device_id, revision);
2550
printf_info("%s: device not supported\n", sym_name(device));
2555
* Check if the chip has been assigned resources we need.
2557
#ifdef SYM_CONF_IOMAPPED
2559
printf_info("%s: IO base address disabled.\n",
2565
printf_info("%s: MMIO base address disabled.\n",
2572
* Ignore Symbios chips controlled by various RAID controllers.
2573
* These controllers set value 0x52414944 at RAM end - 16.
2575
#if defined(__i386__) && !defined(SYM_OPT_NO_BUS_MEMORY_MAPPING)
2577
unsigned int ram_size, ram_val;
2580
if (chip->features & FE_RAM8K)
2585
ram_ptr = pci_map_mem(base_2_c, ram_size);
2587
ram_val = readl_raw(ram_ptr + ram_size - 16);
2588
pci_unmap_mem(ram_ptr, ram_size);
2589
if (ram_val == 0x52414944) {
2590
printf_info("%s: not initializing, "
2591
"driven by RAID controller.\n",
2597
#endif /* i386 and PCI MEMORY accessible */
2600
* Copy the chip description to our device structure,
2601
* so we can make it match the actual device and options.
2603
bcopy(chip, &device->chip, sizeof(device->chip));
2604
device->chip.revision_id = revision;
2607
* Read additionnal info from the configuration space.
2609
pci_read_config_word(pdev, PCI_COMMAND, &command);
2610
pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &cache_line_size);
2613
* Enable missing capabilities in the PCI COMMAND register.
2615
#ifdef SYM_CONF_IOMAPPED
2616
#define PCI_COMMAND_BITS_TO_ENABLE (PCI_COMMAND_IO | \
2617
PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_PARITY)
2619
#define PCI_COMMAND_BITS_TO_ENABLE \
2620
(PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_PARITY)
2622
if ((command & PCI_COMMAND_BITS_TO_ENABLE)
2623
!= PCI_COMMAND_BITS_TO_ENABLE) {
2624
printf_info("%s: setting%s%s%s%s...\n", sym_name(device),
2625
(command & PCI_COMMAND_IO) ? "" : " PCI_COMMAND_IO",
2626
(command & PCI_COMMAND_MEMORY) ? "" : " PCI_COMMAND_MEMORY",
2627
(command & PCI_COMMAND_MASTER) ? "" : " PCI_COMMAND_MASTER",
2628
(command & PCI_COMMAND_PARITY) ? "" : " PCI_COMMAND_PARITY");
2629
command |= PCI_COMMAND_BITS_TO_ENABLE;
2630
pci_write_config_word(pdev, PCI_COMMAND, command);
2632
#undef PCI_COMMAND_BITS_TO_ENABLE
2635
* If cache line size is not configured, suggest
2636
* a value for well known CPUs.
2638
#if defined(__i386__) && !defined(MODULE)
2639
if (!cache_line_size && boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) {
2640
switch(boot_cpu_data.x86) {
2641
case 4: suggested_cache_line_size = 4; break;
2642
case 6: if (boot_cpu_data.x86_model > 8) break;
2643
case 5: suggested_cache_line_size = 8; break;
2646
#endif /* __i386__ */
2649
* Some features are required to be enabled in order to
2650
* work around some chip problems. :) ;)
2651
* (ITEM 12 of a DEL about the 896 I haven't yet).
2652
* We must ensure the chip will use WRITE AND INVALIDATE.
2653
* The revision number limit is for now arbitrary.
2655
if (device_id == PCI_DEVICE_ID_NCR_53C896 && revision < 0x4) {
2656
chip->features |= (FE_WRIE | FE_CLSE);
2657
pci_fix_up |= 3; /* Force appropriate PCI fix-up */
2660
#ifdef SYM_CONF_PCI_FIX_UP
2662
* Try to fix up PCI config according to wished features.
2664
if ((pci_fix_up & 1) && (chip->features & FE_CLSE) &&
2665
!cache_line_size && suggested_cache_line_size) {
2666
cache_line_size = suggested_cache_line_size;
2667
pci_write_config_byte(pdev,
2668
PCI_CACHE_LINE_SIZE, cache_line_size);
2669
printf_info("%s: PCI_CACHE_LINE_SIZE set to %d.\n",
2670
sym_name(device), cache_line_size);
2673
if ((pci_fix_up & 2) && cache_line_size &&
2674
(chip->features & FE_WRIE) && !(command & PCI_COMMAND_INVALIDATE)) {
2675
printf_info("%s: setting PCI_COMMAND_INVALIDATE.\n",
2677
command |= PCI_COMMAND_INVALIDATE;
2678
pci_write_config_word(pdev, PCI_COMMAND, command);
2680
#endif /* SYM_CONF_PCI_FIX_UP */
2683
* Work around for errant bit in 895A. The 66Mhz
2684
* capable bit is set erroneously. Clear this bit.
2687
* Make sure Config space and Features agree.
2689
* Recall: writes are not normal to status register -
2690
* write a 1 to clear and a 0 to leave unchanged.
2691
* Can only reset bits.
2693
pci_read_config_word(pdev, PCI_STATUS, &status_reg);
2694
if (chip->features & FE_66MHZ) {
2695
if (!(status_reg & PCI_STATUS_66MHZ))
2696
chip->features &= ~FE_66MHZ;
2699
if (status_reg & PCI_STATUS_66MHZ) {
2700
status_reg = PCI_STATUS_66MHZ;
2701
pci_write_config_word(pdev, PCI_STATUS, status_reg);
2702
pci_read_config_word(pdev, PCI_STATUS, &status_reg);
2707
* Initialise device structure with items required by sym_attach.
2709
device->pdev = pdev;
2710
device->s.bus = PciBusNumber(pdev);
2711
device->s.device_fn = PciDeviceFn(pdev);
2712
device->s.base = base;
2713
device->s.base_2 = base_2;
2714
device->s.base_c = base_c;
2715
device->s.base_2_c = base_2_c;
2716
device->s.io_port = io_port;
2717
device->s.irq = irq;
2718
device->attach_done = 0;
2724
* List of supported NCR chip ids
2726
static u_short sym_chip_ids[] __initdata = {
2744
* Detect all 53c8xx hosts and then attach them.
2746
* If we are using NVRAM, once all hosts are detected, we need to
2747
* check any NVRAM for boot order in case detect and boot order
2748
* differ and attach them using the order in the NVRAM.
2750
* If no NVRAM is found or data appears invalid attach boards in
2751
* the order they are detected.
2753
int __init sym53c8xx_detect(Scsi_Host_Template *tpnt)
2756
int i, j, chips, hosts, count;
2757
int attach_count = 0;
2758
sym_device *devtbl, *devp;
2760
#if SYM_CONF_NVRAM_SUPPORT
2761
sym_nvram nvram0, *nvp;
2771
* Initialize driver general stuff.
2775
#ifdef SYM_LINUX_PROC_INFO_SUPPORT
2776
#if LINUX_VERSION_CODE < LinuxVersionCode(2,3,27)
2777
tpnt->proc_dir = &proc_scsi_sym53c8xx;
2779
tpnt->proc_name = NAME53C8XX;
2781
tpnt->proc_info = sym53c8xx_proc_info;
2783
#endif /* XENO_KILLED */
2785
#ifdef SYM_LINUX_BOOT_COMMAND_LINE_SUPPORT
2788
sym53c8xx_setup(sym53c8xx);
2790
#ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
2791
sym_debug_flags = sym_driver_setup.debug;
2793
if (boot_verbose >= 2)
2794
sym53c8xx_print_driver_setup();
2795
#endif /* SYM_LINUX_BOOT_COMMAND_LINE_SUPPORT */
2798
* Allocate the device table since we donnot want to
2799
* overflow the kernel stack.
2800
* 1 x 4K PAGE is enough for more than 40 devices for i386.
2802
devtbl = sym_calloc(PAGE_SIZE, "DEVTBL");
2807
* Detect all NCR PQS/PDS memory controllers.
2809
#ifdef SYM_CONF_PQS_PDS_SUPPORT
2810
sym_detect_pqs_pds();
2814
* Detect all 53c8xx hosts.
2815
* Save the first Symbios NVRAM content if any
2816
* for the boot order.
2818
chips = sizeof(sym_chip_ids) / sizeof(sym_chip_ids[0]);
2819
hosts = PAGE_SIZE / sizeof(*devtbl);
2820
#if SYM_CONF_NVRAM_SUPPORT
2821
nvp = (sym_driver_setup.use_nvram & 0x1) ? &nvram0 : 0;
2825
pcidev = PCIDEV_NULL;
2832
i = sym_driver_setup.reverse_probe ? chips - 1 - j : j;
2833
pcidev = pci_find_device(PCI_VENDOR_ID_NCR, sym_chip_ids[i],
2835
if (pcidev == PCIDEV_NULL) {
2839
/* This one is guaranteed by AC to do nothing :-) */
2840
if (pci_enable_device(pcidev))
2842
/* Some HW as the HP LH4 may report twice PCI devices */
2843
for (i = 0; i < count ; i++) {
2844
if (devtbl[i].s.bus == PciBusNumber(pcidev) &&
2845
devtbl[i].s.device_fn == PciDeviceFn(pcidev))
2848
if (i != count) /* Ignore this device if we already have it */
2850
devp = &devtbl[count];
2851
devp->host_id = SYM_SETUP_HOST_ID;
2852
devp->attach_done = 0;
2853
if (sym53c8xx_pci_init(tpnt, pcidev, devp)) {
2857
#if SYM_CONF_NVRAM_SUPPORT
2859
sym_get_nvram(devp, nvp);
2861
case SYM_SYMBIOS_NVRAM:
2863
* Switch to the other nvram buffer, so that
2864
* nvram0 will contain the first Symbios
2865
* format NVRAM content with boot order.
2868
msg = "with Symbios NVRAM";
2870
case SYM_TEKRAM_NVRAM:
2871
msg = "with Tekram NVRAM";
2876
#ifdef SYM_CONF_PQS_PDS_SUPPORT
2878
* Match the BUS number for PQS/PDS devices.
2879
* Read the SCSI ID from a special register mapped
2880
* into the configuration space of the individual
2881
* 875s. This register is set up by the PQS bios
2883
for(i = 0; i < SYM_CONF_MAX_PQS_BUS && pqs_bus[i] != -1; i++) {
2885
if (pqs_bus[i] == PciBusNumber(pcidev)) {
2886
pci_read_config_byte(pcidev, 0x84, &tmp);
2888
devp->host_id = tmp;
2893
msg = "(NCR PQS/PDS)";
2896
printf_info("%s: 53c%s detected %s\n",
2897
sym_name(devp), devp->chip.name, msg);
2901
* If we have found a SYMBIOS NVRAM, use first the NVRAM boot
2902
* sequence as device boot order.
2903
* check devices in the boot record against devices detected.
2904
* attach devices if we find a match. boot table records that
2905
* do not match any detected devices will be ignored.
2906
* devices that do not match any boot table will not be attached
2907
* here but will attempt to be attached during the device table
2910
#if SYM_CONF_NVRAM_SUPPORT
2911
if (!nvp || nvram0.type != SYM_SYMBIOS_NVRAM)
2913
for (i = 0; i < 4; i++) {
2914
Symbios_host *h = &nvram0.data.Symbios.host[i];
2915
for (j = 0 ; j < count ; j++) {
2917
if (h->device_fn != devp->s.device_fn ||
2918
h->bus_nr != devp->s.bus ||
2919
h->device_id != devp->chip.device_id)
2921
if (devp->attach_done)
2923
if (h->flags & SYMBIOS_INIT_SCAN_AT_BOOT) {
2924
sym_get_nvram(devp, nvp);
2925
if (!sym_attach (tpnt, attach_count, devp))
2928
else if (!(sym_driver_setup.use_nvram & 0x80))
2930
"%s: 53c%s state OFF thus not attached\n",
2931
sym_name(devp), devp->chip.name);
2935
devp->attach_done = 1;
2943
* Rescan device list to make sure all boards attached.
2944
* Devices without boot records will not be attached yet
2945
* so try to attach them here.
2947
for (i= 0; i < count; i++) {
2949
if (!devp->attach_done) {
2950
devp->nvram = &nvram;
2952
#if SYM_CONF_NVRAM_SUPPORT
2953
sym_get_nvram(devp, nvp);
2955
if (!sym_attach (tpnt, attach_count, devp))
2960
sym_mfree(devtbl, PAGE_SIZE, "DEVTBL");
2962
return attach_count;
2969
* Linux release module stuff.
2971
* Called before unloading the module.
2973
* We have to free resources and halt the NCR chip.
2976
static int sym_detach(hcb_p np)
2978
printk("%s: detaching ...\n", sym_name(np));
2981
* Try to delete the timer.
2982
* In the unlikely situation where this failed,
2983
* try to synchronize with the timer handler.
2985
#if LINUX_VERSION_CODE < LinuxVersionCode(2, 4, 0)
2986
np->s.release_stage = 1;
2987
if (!del_timer(&np->s.timer)) {
2992
SYM_LOCK_HCB(np, flags);
2993
k = np->s.release_stage;
2994
SYM_UNLOCK_HCB(np, flags);
3000
printk("%s: failed to kill timer!\n", sym_name(np));
3002
np->s.release_stage = 2;
3004
(void)del_timer_sync(&np->s.timer);
3009
* We should use sym_soft_reset(), but we donnot want to do
3010
* so, since we may not be safe if interrupts occur.
3012
printk("%s: resetting chip\n", sym_name(np));
3013
OUTB (nc_istat, SRST);
3018
* Free host resources
3020
sym_free_resources(np);
3025
int sym53c8xx_release(struct Scsi_Host *host)
3027
sym_detach(((struct host_data *) host->hostdata)->ncb);
3034
* For bigots to keep silent. :)
3036
#ifdef MODULE_LICENSE
3037
MODULE_LICENSE("Dual BSD/GPL");
3041
* Driver host template.
3043
#if LINUX_VERSION_CODE >= LinuxVersionCode(2,4,0)
3046
#if LINUX_VERSION_CODE >= LinuxVersionCode(2,4,0) || defined(MODULE)
3047
Scsi_Host_Template driver_template = SYM53C8XX;
3048
#include "../scsi_module.c.inc"