• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/drivers/scsi/sym53c8xx_2/
1/*
2 * Device driver for the SYMBIOS/LSILOGIC 53C8XX and 53C1010 family
3 * of PCI-SCSI IO processors.
4 *
5 * Copyright (C) 1999-2001  Gerard Roudier <groudier@free.fr>
6 * Copyright (c) 2003-2005  Matthew Wilcox <matthew@wil.cx>
7 *
8 * This driver is derived from the Linux sym53c8xx driver.
9 * Copyright (C) 1998-2000  Gerard Roudier
10 *
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.
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
18 *
19 * Other major contributions:
20 *
21 * NVRAM detection and reading.
22 * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
23 *
24 *-----------------------------------------------------------------------------
25 *
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.
30 *
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.
35 *
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
39 */
40#include <linux/ctype.h>
41#include <linux/init.h>
42#include <linux/module.h>
43#include <linux/moduleparam.h>
44#include <linux/spinlock.h>
45#include <scsi/scsi.h>
46#include <scsi/scsi_tcq.h>
47#include <scsi/scsi_device.h>
48#include <scsi/scsi_transport.h>
49
50#include "sym_glue.h"
51#include "sym_nvram.h"
52
53#define NAME53C		"sym53c"
54#define NAME53C8XX	"sym53c8xx"
55
56struct sym_driver_setup sym_driver_setup = SYM_LINUX_DRIVER_SETUP;
57unsigned int sym_debug_flags = 0;
58
59static char *excl_string;
60static char *safe_string;
61module_param_named(cmd_per_lun, sym_driver_setup.max_tag, ushort, 0);
62module_param_named(burst, sym_driver_setup.burst_order, byte, 0);
63module_param_named(led, sym_driver_setup.scsi_led, byte, 0);
64module_param_named(diff, sym_driver_setup.scsi_diff, byte, 0);
65module_param_named(irqm, sym_driver_setup.irq_mode, byte, 0);
66module_param_named(buschk, sym_driver_setup.scsi_bus_check, byte, 0);
67module_param_named(hostid, sym_driver_setup.host_id, byte, 0);
68module_param_named(verb, sym_driver_setup.verbose, byte, 0);
69module_param_named(debug, sym_debug_flags, uint, 0);
70module_param_named(settle, sym_driver_setup.settle_delay, byte, 0);
71module_param_named(nvram, sym_driver_setup.use_nvram, byte, 0);
72module_param_named(excl, excl_string, charp, 0);
73module_param_named(safe, safe_string, charp, 0);
74
75MODULE_PARM_DESC(cmd_per_lun, "The maximum number of tags to use by default");
76MODULE_PARM_DESC(burst, "Maximum burst.  0 to disable, 255 to read from registers");
77MODULE_PARM_DESC(led, "Set to 1 to enable LED support");
78MODULE_PARM_DESC(diff, "0 for no differential mode, 1 for BIOS, 2 for always, 3 for not GPIO3");
79MODULE_PARM_DESC(irqm, "0 for open drain, 1 to leave alone, 2 for totem pole");
80MODULE_PARM_DESC(buschk, "0 to not check, 1 for detach on error, 2 for warn on error");
81MODULE_PARM_DESC(hostid, "The SCSI ID to use for the host adapters");
82MODULE_PARM_DESC(verb, "0 for minimal verbosity, 1 for normal, 2 for excessive");
83MODULE_PARM_DESC(debug, "Set bits to enable debugging");
84MODULE_PARM_DESC(settle, "Settle delay in seconds.  Default 3");
85MODULE_PARM_DESC(nvram, "Option currently not used");
86MODULE_PARM_DESC(excl, "List ioport addresses here to prevent controllers from being attached");
87MODULE_PARM_DESC(safe, "Set other settings to a \"safe mode\"");
88
89MODULE_LICENSE("GPL");
90MODULE_VERSION(SYM_VERSION);
91MODULE_AUTHOR("Matthew Wilcox <matthew@wil.cx>");
92MODULE_DESCRIPTION("NCR, Symbios and LSI 8xx and 1010 PCI SCSI adapters");
93
94static void sym2_setup_params(void)
95{
96	char *p = excl_string;
97	int xi = 0;
98
99	while (p && (xi < 8)) {
100		char *next_p;
101		int val = (int) simple_strtoul(p, &next_p, 0);
102		sym_driver_setup.excludes[xi++] = val;
103		p = next_p;
104	}
105
106	if (safe_string) {
107		if (*safe_string == 'y') {
108			sym_driver_setup.max_tag = 0;
109			sym_driver_setup.burst_order = 0;
110			sym_driver_setup.scsi_led = 0;
111			sym_driver_setup.scsi_diff = 1;
112			sym_driver_setup.irq_mode = 0;
113			sym_driver_setup.scsi_bus_check = 2;
114			sym_driver_setup.host_id = 7;
115			sym_driver_setup.verbose = 2;
116			sym_driver_setup.settle_delay = 10;
117			sym_driver_setup.use_nvram = 1;
118		} else if (*safe_string != 'n') {
119			printk(KERN_WARNING NAME53C8XX "Ignoring parameter %s"
120					" passed to safe option", safe_string);
121		}
122	}
123}
124
125static struct scsi_transport_template *sym2_transport_template = NULL;
126
127/*
128 *  Driver private area in the SCSI command structure.
129 */
130struct sym_ucmd {		/* Override the SCSI pointer structure */
131	struct completion *eh_done;		/* SCSI error handling */
132};
133
134#define SYM_UCMD_PTR(cmd)  ((struct sym_ucmd *)(&(cmd)->SCp))
135#define SYM_SOFTC_PTR(cmd) sym_get_hcb(cmd->device->host)
136
137/*
138 *  Complete a pending CAM CCB.
139 */
140void sym_xpt_done(struct sym_hcb *np, struct scsi_cmnd *cmd)
141{
142	struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
143	BUILD_BUG_ON(sizeof(struct scsi_pointer) < sizeof(struct sym_ucmd));
144
145	if (ucmd->eh_done)
146		complete(ucmd->eh_done);
147
148	scsi_dma_unmap(cmd);
149	cmd->scsi_done(cmd);
150}
151
152/*
153 *  Tell the SCSI layer about a BUS RESET.
154 */
155void sym_xpt_async_bus_reset(struct sym_hcb *np)
156{
157	printf_notice("%s: SCSI BUS has been reset.\n", sym_name(np));
158	np->s.settle_time = jiffies + sym_driver_setup.settle_delay * HZ;
159	np->s.settle_time_valid = 1;
160	if (sym_verbose >= 2)
161		printf_info("%s: command processing suspended for %d seconds\n",
162			    sym_name(np), sym_driver_setup.settle_delay);
163}
164
165/*
166 *  Choose the more appropriate CAM status if
167 *  the IO encountered an extended error.
168 */
169static int sym_xerr_cam_status(int cam_status, int x_status)
170{
171	if (x_status) {
172		if	(x_status & XE_PARITY_ERR)
173			cam_status = DID_PARITY;
174		else if	(x_status &(XE_EXTRA_DATA|XE_SODL_UNRUN|XE_SWIDE_OVRUN))
175			cam_status = DID_ERROR;
176		else if	(x_status & XE_BAD_PHASE)
177			cam_status = DID_ERROR;
178		else
179			cam_status = DID_ERROR;
180	}
181	return cam_status;
182}
183
184/*
185 *  Build CAM result for a failed or auto-sensed IO.
186 */
187void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid)
188{
189	struct scsi_cmnd *cmd = cp->cmd;
190	u_int cam_status, scsi_status, drv_status;
191
192	drv_status  = 0;
193	cam_status  = DID_OK;
194	scsi_status = cp->ssss_status;
195
196	if (cp->host_flags & HF_SENSE) {
197		scsi_status = cp->sv_scsi_status;
198		resid = cp->sv_resid;
199		if (sym_verbose && cp->sv_xerr_status)
200			sym_print_xerr(cmd, cp->sv_xerr_status);
201		if (cp->host_status == HS_COMPLETE &&
202		    cp->ssss_status == S_GOOD &&
203		    cp->xerr_status == 0) {
204			cam_status = sym_xerr_cam_status(DID_OK,
205							 cp->sv_xerr_status);
206			drv_status = DRIVER_SENSE;
207			/*
208			 *  Bounce back the sense data to user.
209			 */
210			memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
211			memcpy(cmd->sense_buffer, cp->sns_bbuf,
212			       min(SCSI_SENSE_BUFFERSIZE, SYM_SNS_BBUF_LEN));
213		} else {
214			/*
215			 * Error return from our internal request sense.  This
216			 * is bad: we must clear the contingent allegiance
217			 * condition otherwise the device will always return
218			 * BUSY.  Use a big stick.
219			 */
220			sym_reset_scsi_target(np, cmd->device->id);
221			cam_status = DID_ERROR;
222		}
223	} else if (cp->host_status == HS_COMPLETE) 	/* Bad SCSI status */
224		cam_status = DID_OK;
225	else if (cp->host_status == HS_SEL_TIMEOUT)	/* Selection timeout */
226		cam_status = DID_NO_CONNECT;
227	else if (cp->host_status == HS_UNEXPECTED)	/* Unexpected BUS FREE*/
228		cam_status = DID_ERROR;
229	else {						/* Extended error */
230		if (sym_verbose) {
231			sym_print_addr(cmd, "COMMAND FAILED (%x %x %x).\n",
232				cp->host_status, cp->ssss_status,
233				cp->xerr_status);
234		}
235		/*
236		 *  Set the most appropriate value for CAM status.
237		 */
238		cam_status = sym_xerr_cam_status(DID_ERROR, cp->xerr_status);
239	}
240	scsi_set_resid(cmd, resid);
241	cmd->result = (drv_status << 24) + (cam_status << 16) + scsi_status;
242}
243
244static int sym_scatter(struct sym_hcb *np, struct sym_ccb *cp, struct scsi_cmnd *cmd)
245{
246	int segment;
247	int use_sg;
248
249	cp->data_len = 0;
250
251	use_sg = scsi_dma_map(cmd);
252	if (use_sg > 0) {
253		struct scatterlist *sg;
254		struct sym_tcb *tp = &np->target[cp->target];
255		struct sym_tblmove *data;
256
257		if (use_sg > SYM_CONF_MAX_SG) {
258			scsi_dma_unmap(cmd);
259			return -1;
260		}
261
262		data = &cp->phys.data[SYM_CONF_MAX_SG - use_sg];
263
264		scsi_for_each_sg(cmd, sg, use_sg, segment) {
265			dma_addr_t baddr = sg_dma_address(sg);
266			unsigned int len = sg_dma_len(sg);
267
268			if ((len & 1) && (tp->head.wval & EWS)) {
269				len++;
270				cp->odd_byte_adjustment++;
271			}
272
273			sym_build_sge(np, &data[segment], baddr, len);
274			cp->data_len += len;
275		}
276	} else {
277		segment = -2;
278	}
279
280	return segment;
281}
282
283/*
284 *  Queue a SCSI command.
285 */
286static int sym_queue_command(struct sym_hcb *np, struct scsi_cmnd *cmd)
287{
288	struct scsi_device *sdev = cmd->device;
289	struct sym_tcb *tp;
290	struct sym_lcb *lp;
291	struct sym_ccb *cp;
292	int	order;
293
294	/*
295	 *  Retrieve the target descriptor.
296	 */
297	tp = &np->target[sdev->id];
298
299	/*
300	 *  Select tagged/untagged.
301	 */
302	lp = sym_lp(tp, sdev->lun);
303	order = (lp && lp->s.reqtags) ? M_SIMPLE_TAG : 0;
304
305	/*
306	 *  Queue the SCSI IO.
307	 */
308	cp = sym_get_ccb(np, cmd, order);
309	if (!cp)
310		return 1;	/* Means resource shortage */
311	sym_queue_scsiio(np, cmd, cp);
312	return 0;
313}
314
315/*
316 *  Setup buffers and pointers that address the CDB.
317 */
318static inline int sym_setup_cdb(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp)
319{
320	memcpy(cp->cdb_buf, cmd->cmnd, cmd->cmd_len);
321
322	cp->phys.cmd.addr = CCB_BA(cp, cdb_buf[0]);
323	cp->phys.cmd.size = cpu_to_scr(cmd->cmd_len);
324
325	return 0;
326}
327
328/*
329 *  Setup pointers that address the data and start the I/O.
330 */
331int sym_setup_data_and_start(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp)
332{
333	u32 lastp, goalp;
334	int dir;
335
336	/*
337	 *  Build the CDB.
338	 */
339	if (sym_setup_cdb(np, cmd, cp))
340		goto out_abort;
341
342	/*
343	 *  No direction means no data.
344	 */
345	dir = cmd->sc_data_direction;
346	if (dir != DMA_NONE) {
347		cp->segments = sym_scatter(np, cp, cmd);
348		if (cp->segments < 0) {
349			sym_set_cam_status(cmd, DID_ERROR);
350			goto out_abort;
351		}
352
353		/*
354		 *  No segments means no data.
355		 */
356		if (!cp->segments)
357			dir = DMA_NONE;
358	} else {
359		cp->data_len = 0;
360		cp->segments = 0;
361	}
362
363	/*
364	 *  Set the data pointer.
365	 */
366	switch (dir) {
367	case DMA_BIDIRECTIONAL:
368		scmd_printk(KERN_INFO, cmd, "got DMA_BIDIRECTIONAL command");
369		sym_set_cam_status(cmd, DID_ERROR);
370		goto out_abort;
371	case DMA_TO_DEVICE:
372		goalp = SCRIPTA_BA(np, data_out2) + 8;
373		lastp = goalp - 8 - (cp->segments * (2*4));
374		break;
375	case DMA_FROM_DEVICE:
376		cp->host_flags |= HF_DATA_IN;
377		goalp = SCRIPTA_BA(np, data_in2) + 8;
378		lastp = goalp - 8 - (cp->segments * (2*4));
379		break;
380	case DMA_NONE:
381	default:
382		lastp = goalp = SCRIPTB_BA(np, no_data);
383		break;
384	}
385
386	/*
387	 *  Set all pointers values needed by SCRIPTS.
388	 */
389	cp->phys.head.lastp = cpu_to_scr(lastp);
390	cp->phys.head.savep = cpu_to_scr(lastp);
391	cp->startp	    = cp->phys.head.savep;
392	cp->goalp	    = cpu_to_scr(goalp);
393
394	/*
395	 *  When `#ifed 1', the code below makes the driver
396	 *  panic on the first attempt to write to a SCSI device.
397	 *  It is the first test we want to do after a driver
398	 *  change that does not seem obviously safe. :)
399	 */
400
401	/*
402	 *	activate this job.
403	 */
404	sym_put_start_queue(np, cp);
405	return 0;
406
407out_abort:
408	sym_free_ccb(np, cp);
409	sym_xpt_done(np, cmd);
410	return 0;
411}
412
413
414/*
415 *  timer daemon.
416 *
417 *  Misused to keep the driver running when
418 *  interrupts are not configured correctly.
419 */
420static void sym_timer(struct sym_hcb *np)
421{
422	unsigned long thistime = jiffies;
423
424	/*
425	 *  Restart the timer.
426	 */
427	np->s.timer.expires = thistime + SYM_CONF_TIMER_INTERVAL;
428	add_timer(&np->s.timer);
429
430	/*
431	 *  If we are resetting the ncr, wait for settle_time before
432	 *  clearing it. Then command processing will be resumed.
433	 */
434	if (np->s.settle_time_valid) {
435		if (time_before_eq(np->s.settle_time, thistime)) {
436			if (sym_verbose >= 2 )
437				printk("%s: command processing resumed\n",
438				       sym_name(np));
439			np->s.settle_time_valid = 0;
440		}
441		return;
442	}
443
444	/*
445	 *	Nothing to do for now, but that may come.
446	 */
447	if (np->s.lasttime + 4*HZ < thistime) {
448		np->s.lasttime = thistime;
449	}
450
451#ifdef SYM_CONF_PCIQ_MAY_MISS_COMPLETIONS
452	/*
453	 *  Some way-broken PCI bridges may lead to
454	 *  completions being lost when the clearing
455	 *  of the INTFLY flag by the CPU occurs
456	 *  concurrently with the chip raising this flag.
457	 *  If this ever happen, lost completions will
458	 * be reaped here.
459	 */
460	sym_wakeup_done(np);
461#endif
462}
463
464
465/*
466 *  PCI BUS error handler.
467 */
468void sym_log_bus_error(struct Scsi_Host *shost)
469{
470	struct sym_data *sym_data = shost_priv(shost);
471	struct pci_dev *pdev = sym_data->pdev;
472	unsigned short pci_sts;
473	pci_read_config_word(pdev, PCI_STATUS, &pci_sts);
474	if (pci_sts & 0xf900) {
475		pci_write_config_word(pdev, PCI_STATUS, pci_sts);
476		shost_printk(KERN_WARNING, shost,
477			"PCI bus error: status = 0x%04x\n", pci_sts & 0xf900);
478	}
479}
480
481/*
482 * queuecommand method.  Entered with the host adapter lock held and
483 * interrupts disabled.
484 */
485static int sym53c8xx_queue_command(struct scsi_cmnd *cmd,
486					void (*done)(struct scsi_cmnd *))
487{
488	struct sym_hcb *np = SYM_SOFTC_PTR(cmd);
489	struct sym_ucmd *ucp = SYM_UCMD_PTR(cmd);
490	int sts = 0;
491
492	cmd->scsi_done = done;
493	memset(ucp, 0, sizeof(*ucp));
494
495	/*
496	 *  Shorten our settle_time if needed for
497	 *  this command not to time out.
498	 */
499	if (np->s.settle_time_valid && cmd->request->timeout) {
500		unsigned long tlimit = jiffies + cmd->request->timeout;
501		tlimit -= SYM_CONF_TIMER_INTERVAL*2;
502		if (time_after(np->s.settle_time, tlimit)) {
503			np->s.settle_time = tlimit;
504		}
505	}
506
507	if (np->s.settle_time_valid)
508		return SCSI_MLQUEUE_HOST_BUSY;
509
510	sts = sym_queue_command(np, cmd);
511	if (sts)
512		return SCSI_MLQUEUE_HOST_BUSY;
513	return 0;
514}
515
516/*
517 *  Linux entry point of the interrupt handler.
518 */
519static irqreturn_t sym53c8xx_intr(int irq, void *dev_id)
520{
521	struct Scsi_Host *shost = dev_id;
522	struct sym_data *sym_data = shost_priv(shost);
523	irqreturn_t result;
524
525	/* Avoid spinloop trying to handle interrupts on frozen device */
526	if (pci_channel_offline(sym_data->pdev))
527		return IRQ_NONE;
528
529	if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("[");
530
531	spin_lock(shost->host_lock);
532	result = sym_interrupt(shost);
533	spin_unlock(shost->host_lock);
534
535	if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("]\n");
536
537	return result;
538}
539
540/*
541 *  Linux entry point of the timer handler
542 */
543static void sym53c8xx_timer(unsigned long npref)
544{
545	struct sym_hcb *np = (struct sym_hcb *)npref;
546	unsigned long flags;
547
548	spin_lock_irqsave(np->s.host->host_lock, flags);
549	sym_timer(np);
550	spin_unlock_irqrestore(np->s.host->host_lock, flags);
551}
552
553
554/*
555 *  What the eh thread wants us to perform.
556 */
557#define SYM_EH_ABORT		0
558#define SYM_EH_DEVICE_RESET	1
559#define SYM_EH_BUS_RESET	2
560#define SYM_EH_HOST_RESET	3
561
562/*
563 *  Generic method for our eh processing.
564 *  The 'op' argument tells what we have to do.
565 */
566static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd)
567{
568	struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
569	struct Scsi_Host *shost = cmd->device->host;
570	struct sym_data *sym_data = shost_priv(shost);
571	struct pci_dev *pdev = sym_data->pdev;
572	struct sym_hcb *np = sym_data->ncb;
573	SYM_QUEHEAD *qp;
574	int cmd_queued = 0;
575	int sts = -1;
576	struct completion eh_done;
577
578	scmd_printk(KERN_WARNING, cmd, "%s operation started\n", opname);
579
580	/* We may be in an error condition because the PCI bus
581	 * went down. In this case, we need to wait until the
582	 * PCI bus is reset, the card is reset, and only then
583	 * proceed with the scsi error recovery.  There's no
584	 * point in hurrying; take a leisurely wait.
585	 */
586#define WAIT_FOR_PCI_RECOVERY	35
587	if (pci_channel_offline(pdev)) {
588		int finished_reset = 0;
589		init_completion(&eh_done);
590		spin_lock_irq(shost->host_lock);
591		/* Make sure we didn't race */
592		if (pci_channel_offline(pdev)) {
593			BUG_ON(sym_data->io_reset);
594			sym_data->io_reset = &eh_done;
595		} else {
596			finished_reset = 1;
597		}
598		spin_unlock_irq(shost->host_lock);
599		if (!finished_reset)
600			finished_reset = wait_for_completion_timeout
601						(sym_data->io_reset,
602						WAIT_FOR_PCI_RECOVERY*HZ);
603		spin_lock_irq(shost->host_lock);
604		sym_data->io_reset = NULL;
605		spin_unlock_irq(shost->host_lock);
606		if (!finished_reset)
607			return SCSI_FAILED;
608	}
609
610	spin_lock_irq(shost->host_lock);
611	/* This one is queued in some place -> to wait for completion */
612	FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
613		struct sym_ccb *cp = sym_que_entry(qp, struct sym_ccb, link_ccbq);
614		if (cp->cmd == cmd) {
615			cmd_queued = 1;
616			break;
617		}
618	}
619
620	/* Try to proceed the operation we have been asked for */
621	sts = -1;
622	switch(op) {
623	case SYM_EH_ABORT:
624		sts = sym_abort_scsiio(np, cmd, 1);
625		break;
626	case SYM_EH_DEVICE_RESET:
627		sts = sym_reset_scsi_target(np, cmd->device->id);
628		break;
629	case SYM_EH_BUS_RESET:
630		sym_reset_scsi_bus(np, 1);
631		sts = 0;
632		break;
633	case SYM_EH_HOST_RESET:
634		sym_reset_scsi_bus(np, 0);
635		sym_start_up(shost, 1);
636		sts = 0;
637		break;
638	default:
639		break;
640	}
641
642	/* On error, restore everything and cross fingers :) */
643	if (sts)
644		cmd_queued = 0;
645
646	if (cmd_queued) {
647		init_completion(&eh_done);
648		ucmd->eh_done = &eh_done;
649		spin_unlock_irq(shost->host_lock);
650		if (!wait_for_completion_timeout(&eh_done, 5*HZ)) {
651			ucmd->eh_done = NULL;
652			sts = -2;
653		}
654	} else {
655		spin_unlock_irq(shost->host_lock);
656	}
657
658	dev_warn(&cmd->device->sdev_gendev, "%s operation %s.\n", opname,
659			sts==0 ? "complete" :sts==-2 ? "timed-out" : "failed");
660	return sts ? SCSI_FAILED : SCSI_SUCCESS;
661}
662
663
664/*
665 * Error handlers called from the eh thread (one thread per HBA).
666 */
667static int sym53c8xx_eh_abort_handler(struct scsi_cmnd *cmd)
668{
669	return sym_eh_handler(SYM_EH_ABORT, "ABORT", cmd);
670}
671
672static int sym53c8xx_eh_device_reset_handler(struct scsi_cmnd *cmd)
673{
674	return sym_eh_handler(SYM_EH_DEVICE_RESET, "DEVICE RESET", cmd);
675}
676
677static int sym53c8xx_eh_bus_reset_handler(struct scsi_cmnd *cmd)
678{
679	return sym_eh_handler(SYM_EH_BUS_RESET, "BUS RESET", cmd);
680}
681
682static int sym53c8xx_eh_host_reset_handler(struct scsi_cmnd *cmd)
683{
684	return sym_eh_handler(SYM_EH_HOST_RESET, "HOST RESET", cmd);
685}
686
687/*
688 *  Tune device queuing depth, according to various limits.
689 */
690static void sym_tune_dev_queuing(struct sym_tcb *tp, int lun, u_short reqtags)
691{
692	struct sym_lcb *lp = sym_lp(tp, lun);
693	u_short	oldtags;
694
695	if (!lp)
696		return;
697
698	oldtags = lp->s.reqtags;
699
700	if (reqtags > lp->s.scdev_depth)
701		reqtags = lp->s.scdev_depth;
702
703	lp->s.reqtags     = reqtags;
704
705	if (reqtags != oldtags) {
706		dev_info(&tp->starget->dev,
707		         "tagged command queuing %s, command queue depth %d.\n",
708		          lp->s.reqtags ? "enabled" : "disabled", reqtags);
709	}
710}
711
712static int sym53c8xx_slave_alloc(struct scsi_device *sdev)
713{
714	struct sym_hcb *np = sym_get_hcb(sdev->host);
715	struct sym_tcb *tp = &np->target[sdev->id];
716	struct sym_lcb *lp;
717	unsigned long flags;
718	int error;
719
720	if (sdev->id >= SYM_CONF_MAX_TARGET || sdev->lun >= SYM_CONF_MAX_LUN)
721		return -ENXIO;
722
723	spin_lock_irqsave(np->s.host->host_lock, flags);
724
725	/*
726	 * Fail the device init if the device is flagged NOSCAN at BOOT in
727	 * the NVRAM.  This may speed up boot and maintain coherency with
728	 * BIOS device numbering.  Clearing the flag allows the user to
729	 * rescan skipped devices later.  We also return an error for
730	 * devices not flagged for SCAN LUNS in the NVRAM since some single
731	 * lun devices behave badly when asked for a non zero LUN.
732	 */
733
734	if (tp->usrflags & SYM_SCAN_BOOT_DISABLED) {
735		tp->usrflags &= ~SYM_SCAN_BOOT_DISABLED;
736		starget_printk(KERN_INFO, sdev->sdev_target,
737				"Scan at boot disabled in NVRAM\n");
738		error = -ENXIO;
739		goto out;
740	}
741
742	if (tp->usrflags & SYM_SCAN_LUNS_DISABLED) {
743		if (sdev->lun != 0) {
744			error = -ENXIO;
745			goto out;
746		}
747		starget_printk(KERN_INFO, sdev->sdev_target,
748				"Multiple LUNs disabled in NVRAM\n");
749	}
750
751	lp = sym_alloc_lcb(np, sdev->id, sdev->lun);
752	if (!lp) {
753		error = -ENOMEM;
754		goto out;
755	}
756	if (tp->nlcb == 1)
757		tp->starget = sdev->sdev_target;
758
759	spi_min_period(tp->starget) = tp->usr_period;
760	spi_max_width(tp->starget) = tp->usr_width;
761
762	error = 0;
763out:
764	spin_unlock_irqrestore(np->s.host->host_lock, flags);
765
766	return error;
767}
768
769/*
770 * Linux entry point for device queue sizing.
771 */
772static int sym53c8xx_slave_configure(struct scsi_device *sdev)
773{
774	struct sym_hcb *np = sym_get_hcb(sdev->host);
775	struct sym_tcb *tp = &np->target[sdev->id];
776	struct sym_lcb *lp = sym_lp(tp, sdev->lun);
777	int reqtags, depth_to_use;
778
779	/*
780	 *  Get user flags.
781	 */
782	lp->curr_flags = lp->user_flags;
783
784	/*
785	 *  Select queue depth from driver setup.
786	 *  Do not use more than configured by user.
787	 *  Use at least 1.
788	 *  Do not use more than our maximum.
789	 */
790	reqtags = sym_driver_setup.max_tag;
791	if (reqtags > tp->usrtags)
792		reqtags = tp->usrtags;
793	if (!sdev->tagged_supported)
794		reqtags = 0;
795	if (reqtags > SYM_CONF_MAX_TAG)
796		reqtags = SYM_CONF_MAX_TAG;
797	depth_to_use = reqtags ? reqtags : 1;
798	scsi_adjust_queue_depth(sdev,
799				sdev->tagged_supported ? MSG_SIMPLE_TAG : 0,
800				depth_to_use);
801	lp->s.scdev_depth = depth_to_use;
802	sym_tune_dev_queuing(tp, sdev->lun, reqtags);
803
804	if (!spi_initial_dv(sdev->sdev_target))
805		spi_dv_device(sdev);
806
807	return 0;
808}
809
810static void sym53c8xx_slave_destroy(struct scsi_device *sdev)
811{
812	struct sym_hcb *np = sym_get_hcb(sdev->host);
813	struct sym_tcb *tp = &np->target[sdev->id];
814	struct sym_lcb *lp = sym_lp(tp, sdev->lun);
815	unsigned long flags;
816
817	spin_lock_irqsave(np->s.host->host_lock, flags);
818
819	if (lp->busy_itlq || lp->busy_itl) {
820		/*
821		 * This really shouldn't happen, but we can't return an error
822		 * so let's try to stop all on-going I/O.
823		 */
824		starget_printk(KERN_WARNING, tp->starget,
825			       "Removing busy LCB (%d)\n", sdev->lun);
826		sym_reset_scsi_bus(np, 1);
827	}
828
829	if (sym_free_lcb(np, sdev->id, sdev->lun) == 0) {
830		/*
831		 * It was the last unit for this target.
832		 */
833		tp->head.sval        = 0;
834		tp->head.wval        = np->rv_scntl3;
835		tp->head.uval        = 0;
836		tp->tgoal.check_nego = 1;
837		tp->starget	     = NULL;
838	}
839
840	spin_unlock_irqrestore(np->s.host->host_lock, flags);
841}
842
843/*
844 *  Linux entry point for info() function
845 */
846static const char *sym53c8xx_info (struct Scsi_Host *host)
847{
848	return SYM_DRIVER_NAME;
849}
850
851
852#ifdef SYM_LINUX_PROC_INFO_SUPPORT
853/*
854 *  Proc file system stuff
855 *
856 *  A read operation returns adapter information.
857 *  A write operation is a control command.
858 *  The string is parsed in the driver code and the command is passed
859 *  to the sym_usercmd() function.
860 */
861
862#ifdef SYM_LINUX_USER_COMMAND_SUPPORT
863
864struct	sym_usrcmd {
865	u_long	target;
866	u_long	lun;
867	u_long	data;
868	u_long	cmd;
869};
870
871#define UC_SETSYNC      10
872#define UC_SETTAGS	11
873#define UC_SETDEBUG	12
874#define UC_SETWIDE	14
875#define UC_SETFLAG	15
876#define UC_SETVERBOSE	17
877#define UC_RESETDEV	18
878#define UC_CLEARDEV	19
879
880static void sym_exec_user_command (struct sym_hcb *np, struct sym_usrcmd *uc)
881{
882	struct sym_tcb *tp;
883	int t, l;
884
885	switch (uc->cmd) {
886	case 0: return;
887
888#ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
889	case UC_SETDEBUG:
890		sym_debug_flags = uc->data;
891		break;
892#endif
893	case UC_SETVERBOSE:
894		np->verbose = uc->data;
895		break;
896	default:
897		/*
898		 * We assume that other commands apply to targets.
899		 * This should always be the case and avoid the below
900		 * 4 lines to be repeated 6 times.
901		 */
902		for (t = 0; t < SYM_CONF_MAX_TARGET; t++) {
903			if (!((uc->target >> t) & 1))
904				continue;
905			tp = &np->target[t];
906			if (!tp->nlcb)
907				continue;
908
909			switch (uc->cmd) {
910
911			case UC_SETSYNC:
912				if (!uc->data || uc->data >= 255) {
913					tp->tgoal.iu = tp->tgoal.dt =
914						tp->tgoal.qas = 0;
915					tp->tgoal.offset = 0;
916				} else if (uc->data <= 9 && np->minsync_dt) {
917					if (uc->data < np->minsync_dt)
918						uc->data = np->minsync_dt;
919					tp->tgoal.iu = tp->tgoal.dt =
920						tp->tgoal.qas = 1;
921					tp->tgoal.width = 1;
922					tp->tgoal.period = uc->data;
923					tp->tgoal.offset = np->maxoffs_dt;
924				} else {
925					if (uc->data < np->minsync)
926						uc->data = np->minsync;
927					tp->tgoal.iu = tp->tgoal.dt =
928						tp->tgoal.qas = 0;
929					tp->tgoal.period = uc->data;
930					tp->tgoal.offset = np->maxoffs;
931				}
932				tp->tgoal.check_nego = 1;
933				break;
934			case UC_SETWIDE:
935				tp->tgoal.width = uc->data ? 1 : 0;
936				tp->tgoal.check_nego = 1;
937				break;
938			case UC_SETTAGS:
939				for (l = 0; l < SYM_CONF_MAX_LUN; l++)
940					sym_tune_dev_queuing(tp, l, uc->data);
941				break;
942			case UC_RESETDEV:
943				tp->to_reset = 1;
944				np->istat_sem = SEM;
945				OUTB(np, nc_istat, SIGP|SEM);
946				break;
947			case UC_CLEARDEV:
948				for (l = 0; l < SYM_CONF_MAX_LUN; l++) {
949					struct sym_lcb *lp = sym_lp(tp, l);
950					if (lp) lp->to_clear = 1;
951				}
952				np->istat_sem = SEM;
953				OUTB(np, nc_istat, SIGP|SEM);
954				break;
955			case UC_SETFLAG:
956				tp->usrflags = uc->data;
957				break;
958			}
959		}
960		break;
961	}
962}
963
964static int sym_skip_spaces(char *ptr, int len)
965{
966	int cnt, c;
967
968	for (cnt = len; cnt > 0 && (c = *ptr++) && isspace(c); cnt--);
969
970	return (len - cnt);
971}
972
973static int get_int_arg(char *ptr, int len, u_long *pv)
974{
975	char *end;
976
977	*pv = simple_strtoul(ptr, &end, 10);
978	return (end - ptr);
979}
980
981static int is_keyword(char *ptr, int len, char *verb)
982{
983	int verb_len = strlen(verb);
984
985	if (len >= verb_len && !memcmp(verb, ptr, verb_len))
986		return verb_len;
987	else
988		return 0;
989}
990
991#define SKIP_SPACES(ptr, len)						\
992	if ((arg_len = sym_skip_spaces(ptr, len)) < 1)			\
993		return -EINVAL;						\
994	ptr += arg_len; len -= arg_len;
995
996#define GET_INT_ARG(ptr, len, v)					\
997	if (!(arg_len = get_int_arg(ptr, len, &(v))))			\
998		return -EINVAL;						\
999	ptr += arg_len; len -= arg_len;
1000
1001
1002/*
1003 * Parse a control command
1004 */
1005
1006static int sym_user_command(struct Scsi_Host *shost, char *buffer, int length)
1007{
1008	struct sym_hcb *np = sym_get_hcb(shost);
1009	char *ptr	= buffer;
1010	int len		= length;
1011	struct sym_usrcmd cmd, *uc = &cmd;
1012	int		arg_len;
1013	u_long 		target;
1014
1015	memset(uc, 0, sizeof(*uc));
1016
1017	if (len > 0 && ptr[len-1] == '\n')
1018		--len;
1019
1020	if	((arg_len = is_keyword(ptr, len, "setsync")) != 0)
1021		uc->cmd = UC_SETSYNC;
1022	else if	((arg_len = is_keyword(ptr, len, "settags")) != 0)
1023		uc->cmd = UC_SETTAGS;
1024	else if	((arg_len = is_keyword(ptr, len, "setverbose")) != 0)
1025		uc->cmd = UC_SETVERBOSE;
1026	else if	((arg_len = is_keyword(ptr, len, "setwide")) != 0)
1027		uc->cmd = UC_SETWIDE;
1028#ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1029	else if	((arg_len = is_keyword(ptr, len, "setdebug")) != 0)
1030		uc->cmd = UC_SETDEBUG;
1031#endif
1032	else if	((arg_len = is_keyword(ptr, len, "setflag")) != 0)
1033		uc->cmd = UC_SETFLAG;
1034	else if	((arg_len = is_keyword(ptr, len, "resetdev")) != 0)
1035		uc->cmd = UC_RESETDEV;
1036	else if	((arg_len = is_keyword(ptr, len, "cleardev")) != 0)
1037		uc->cmd = UC_CLEARDEV;
1038	else
1039		arg_len = 0;
1040
1041#ifdef DEBUG_PROC_INFO
1042printk("sym_user_command: arg_len=%d, cmd=%ld\n", arg_len, uc->cmd);
1043#endif
1044
1045	if (!arg_len)
1046		return -EINVAL;
1047	ptr += arg_len; len -= arg_len;
1048
1049	switch(uc->cmd) {
1050	case UC_SETSYNC:
1051	case UC_SETTAGS:
1052	case UC_SETWIDE:
1053	case UC_SETFLAG:
1054	case UC_RESETDEV:
1055	case UC_CLEARDEV:
1056		SKIP_SPACES(ptr, len);
1057		if ((arg_len = is_keyword(ptr, len, "all")) != 0) {
1058			ptr += arg_len; len -= arg_len;
1059			uc->target = ~0;
1060		} else {
1061			GET_INT_ARG(ptr, len, target);
1062			uc->target = (1<<target);
1063#ifdef DEBUG_PROC_INFO
1064printk("sym_user_command: target=%ld\n", target);
1065#endif
1066		}
1067		break;
1068	}
1069
1070	switch(uc->cmd) {
1071	case UC_SETVERBOSE:
1072	case UC_SETSYNC:
1073	case UC_SETTAGS:
1074	case UC_SETWIDE:
1075		SKIP_SPACES(ptr, len);
1076		GET_INT_ARG(ptr, len, uc->data);
1077#ifdef DEBUG_PROC_INFO
1078printk("sym_user_command: data=%ld\n", uc->data);
1079#endif
1080		break;
1081#ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1082	case UC_SETDEBUG:
1083		while (len > 0) {
1084			SKIP_SPACES(ptr, len);
1085			if	((arg_len = is_keyword(ptr, len, "alloc")))
1086				uc->data |= DEBUG_ALLOC;
1087			else if	((arg_len = is_keyword(ptr, len, "phase")))
1088				uc->data |= DEBUG_PHASE;
1089			else if	((arg_len = is_keyword(ptr, len, "queue")))
1090				uc->data |= DEBUG_QUEUE;
1091			else if	((arg_len = is_keyword(ptr, len, "result")))
1092				uc->data |= DEBUG_RESULT;
1093			else if	((arg_len = is_keyword(ptr, len, "scatter")))
1094				uc->data |= DEBUG_SCATTER;
1095			else if	((arg_len = is_keyword(ptr, len, "script")))
1096				uc->data |= DEBUG_SCRIPT;
1097			else if	((arg_len = is_keyword(ptr, len, "tiny")))
1098				uc->data |= DEBUG_TINY;
1099			else if	((arg_len = is_keyword(ptr, len, "timing")))
1100				uc->data |= DEBUG_TIMING;
1101			else if	((arg_len = is_keyword(ptr, len, "nego")))
1102				uc->data |= DEBUG_NEGO;
1103			else if	((arg_len = is_keyword(ptr, len, "tags")))
1104				uc->data |= DEBUG_TAGS;
1105			else if	((arg_len = is_keyword(ptr, len, "pointer")))
1106				uc->data |= DEBUG_POINTER;
1107			else
1108				return -EINVAL;
1109			ptr += arg_len; len -= arg_len;
1110		}
1111#ifdef DEBUG_PROC_INFO
1112printk("sym_user_command: data=%ld\n", uc->data);
1113#endif
1114		break;
1115#endif /* SYM_LINUX_DEBUG_CONTROL_SUPPORT */
1116	case UC_SETFLAG:
1117		while (len > 0) {
1118			SKIP_SPACES(ptr, len);
1119			if	((arg_len = is_keyword(ptr, len, "no_disc")))
1120				uc->data &= ~SYM_DISC_ENABLED;
1121			else
1122				return -EINVAL;
1123			ptr += arg_len; len -= arg_len;
1124		}
1125		break;
1126	default:
1127		break;
1128	}
1129
1130	if (len)
1131		return -EINVAL;
1132	else {
1133		unsigned long flags;
1134
1135		spin_lock_irqsave(shost->host_lock, flags);
1136		sym_exec_user_command(np, uc);
1137		spin_unlock_irqrestore(shost->host_lock, flags);
1138	}
1139	return length;
1140}
1141
1142#endif	/* SYM_LINUX_USER_COMMAND_SUPPORT */
1143
1144
1145#ifdef SYM_LINUX_USER_INFO_SUPPORT
1146/*
1147 *  Informations through the proc file system.
1148 */
1149struct info_str {
1150	char *buffer;
1151	int length;
1152	int offset;
1153	int pos;
1154};
1155
1156static void copy_mem_info(struct info_str *info, char *data, int len)
1157{
1158	if (info->pos + len > info->length)
1159		len = info->length - info->pos;
1160
1161	if (info->pos + len < info->offset) {
1162		info->pos += len;
1163		return;
1164	}
1165	if (info->pos < info->offset) {
1166		data += (info->offset - info->pos);
1167		len  -= (info->offset - info->pos);
1168	}
1169
1170	if (len > 0) {
1171		memcpy(info->buffer + info->pos, data, len);
1172		info->pos += len;
1173	}
1174}
1175
1176static int copy_info(struct info_str *info, char *fmt, ...)
1177{
1178	va_list args;
1179	char buf[81];
1180	int len;
1181
1182	va_start(args, fmt);
1183	len = vsprintf(buf, fmt, args);
1184	va_end(args);
1185
1186	copy_mem_info(info, buf, len);
1187	return len;
1188}
1189
1190/*
1191 *  Copy formatted information into the input buffer.
1192 */
1193static int sym_host_info(struct Scsi_Host *shost, char *ptr, off_t offset, int len)
1194{
1195	struct sym_data *sym_data = shost_priv(shost);
1196	struct pci_dev *pdev = sym_data->pdev;
1197	struct sym_hcb *np = sym_data->ncb;
1198	struct info_str info;
1199
1200	info.buffer	= ptr;
1201	info.length	= len;
1202	info.offset	= offset;
1203	info.pos	= 0;
1204
1205	copy_info(&info, "Chip " NAME53C "%s, device id 0x%x, "
1206			 "revision id 0x%x\n", np->s.chip_name,
1207			 pdev->device, pdev->revision);
1208	copy_info(&info, "At PCI address %s, IRQ %u\n",
1209			 pci_name(pdev), pdev->irq);
1210	copy_info(&info, "Min. period factor %d, %s SCSI BUS%s\n",
1211			 (int) (np->minsync_dt ? np->minsync_dt : np->minsync),
1212			 np->maxwide ? "Wide" : "Narrow",
1213			 np->minsync_dt ? ", DT capable" : "");
1214
1215	copy_info(&info, "Max. started commands %d, "
1216			 "max. commands per LUN %d\n",
1217			 SYM_CONF_MAX_START, SYM_CONF_MAX_TAG);
1218
1219	return info.pos > info.offset? info.pos - info.offset : 0;
1220}
1221#endif /* SYM_LINUX_USER_INFO_SUPPORT */
1222
1223/*
1224 *  Entry point of the scsi proc fs of the driver.
1225 *  - func = 0 means read  (returns adapter infos)
1226 *  - func = 1 means write (not yet merget from sym53c8xx)
1227 */
1228static int sym53c8xx_proc_info(struct Scsi_Host *shost, char *buffer,
1229			char **start, off_t offset, int length, int func)
1230{
1231	int retv;
1232
1233	if (func) {
1234#ifdef	SYM_LINUX_USER_COMMAND_SUPPORT
1235		retv = sym_user_command(shost, buffer, length);
1236#else
1237		retv = -EINVAL;
1238#endif
1239	} else {
1240		if (start)
1241			*start = buffer;
1242#ifdef SYM_LINUX_USER_INFO_SUPPORT
1243		retv = sym_host_info(shost, buffer, offset, length);
1244#else
1245		retv = -EINVAL;
1246#endif
1247	}
1248
1249	return retv;
1250}
1251#endif /* SYM_LINUX_PROC_INFO_SUPPORT */
1252
1253/*
1254 * Free resources claimed by sym_iomap_device().  Note that
1255 * sym_free_resources() should be used instead of this function after calling
1256 * sym_attach().
1257 */
1258static void __devinit
1259sym_iounmap_device(struct sym_device *device)
1260{
1261	if (device->s.ioaddr)
1262		pci_iounmap(device->pdev, device->s.ioaddr);
1263	if (device->s.ramaddr)
1264		pci_iounmap(device->pdev, device->s.ramaddr);
1265}
1266
1267/*
1268 *	Free controller resources.
1269 */
1270static void sym_free_resources(struct sym_hcb *np, struct pci_dev *pdev,
1271		int do_free_irq)
1272{
1273	/*
1274	 *  Free O/S specific resources.
1275	 */
1276	if (do_free_irq)
1277		free_irq(pdev->irq, np->s.host);
1278	if (np->s.ioaddr)
1279		pci_iounmap(pdev, np->s.ioaddr);
1280	if (np->s.ramaddr)
1281		pci_iounmap(pdev, np->s.ramaddr);
1282	/*
1283	 *  Free O/S independent resources.
1284	 */
1285	sym_hcb_free(np);
1286
1287	sym_mfree_dma(np, sizeof(*np), "HCB");
1288}
1289
1290/*
1291 *  Host attach and initialisations.
1292 *
1293 *  Allocate host data and ncb structure.
1294 *  Remap MMIO region.
1295 *  Do chip initialization.
1296 *  If all is OK, install interrupt handling and
1297 *  start the timer daemon.
1298 */
1299static struct Scsi_Host * __devinit sym_attach(struct scsi_host_template *tpnt,
1300		int unit, struct sym_device *dev)
1301{
1302	struct sym_data *sym_data;
1303	struct sym_hcb *np = NULL;
1304	struct Scsi_Host *shost = NULL;
1305	struct pci_dev *pdev = dev->pdev;
1306	unsigned long flags;
1307	struct sym_fw *fw;
1308	int do_free_irq = 0;
1309
1310	printk(KERN_INFO "sym%d: <%s> rev 0x%x at pci %s irq %u\n",
1311		unit, dev->chip.name, pdev->revision, pci_name(pdev),
1312		pdev->irq);
1313
1314	/*
1315	 *  Get the firmware for this chip.
1316	 */
1317	fw = sym_find_firmware(&dev->chip);
1318	if (!fw)
1319		goto attach_failed;
1320
1321	shost = scsi_host_alloc(tpnt, sizeof(*sym_data));
1322	if (!shost)
1323		goto attach_failed;
1324	sym_data = shost_priv(shost);
1325
1326	/*
1327	 *  Allocate immediately the host control block,
1328	 *  since we are only expecting to succeed. :)
1329	 *  We keep track in the HCB of all the resources that
1330	 *  are to be released on error.
1331	 */
1332	np = __sym_calloc_dma(&pdev->dev, sizeof(*np), "HCB");
1333	if (!np)
1334		goto attach_failed;
1335	np->bus_dmat = &pdev->dev; /* Result in 1 DMA pool per HBA */
1336	sym_data->ncb = np;
1337	sym_data->pdev = pdev;
1338	np->s.host = shost;
1339
1340	pci_set_drvdata(pdev, shost);
1341
1342	/*
1343	 *  Copy some useful infos to the HCB.
1344	 */
1345	np->hcb_ba	= vtobus(np);
1346	np->verbose	= sym_driver_setup.verbose;
1347	np->s.unit	= unit;
1348	np->features	= dev->chip.features;
1349	np->clock_divn	= dev->chip.nr_divisor;
1350	np->maxoffs	= dev->chip.offset_max;
1351	np->maxburst	= dev->chip.burst_max;
1352	np->myaddr	= dev->host_id;
1353	np->mmio_ba	= (u32)dev->mmio_base;
1354	np->ram_ba	= (u32)dev->ram_base;
1355	np->s.ioaddr	= dev->s.ioaddr;
1356	np->s.ramaddr	= dev->s.ramaddr;
1357
1358	/*
1359	 *  Edit its name.
1360	 */
1361	strlcpy(np->s.chip_name, dev->chip.name, sizeof(np->s.chip_name));
1362	sprintf(np->s.inst_name, "sym%d", np->s.unit);
1363
1364	if ((SYM_CONF_DMA_ADDRESSING_MODE > 0) && (np->features & FE_DAC) &&
1365			!pci_set_dma_mask(pdev, DMA_DAC_MASK)) {
1366		set_dac(np);
1367	} else if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
1368		printf_warning("%s: No suitable DMA available\n", sym_name(np));
1369		goto attach_failed;
1370	}
1371
1372	if (sym_hcb_attach(shost, fw, dev->nvram))
1373		goto attach_failed;
1374
1375	/*
1376	 *  Install the interrupt handler.
1377	 *  If we synchonize the C code with SCRIPTS on interrupt,
1378	 *  we do not want to share the INTR line at all.
1379	 */
1380	if (request_irq(pdev->irq, sym53c8xx_intr, IRQF_SHARED, NAME53C8XX,
1381			shost)) {
1382		printf_err("%s: request irq %u failure\n",
1383			sym_name(np), pdev->irq);
1384		goto attach_failed;
1385	}
1386	do_free_irq = 1;
1387
1388	/*
1389	 *  After SCSI devices have been opened, we cannot
1390	 *  reset the bus safely, so we do it here.
1391	 */
1392	spin_lock_irqsave(shost->host_lock, flags);
1393	if (sym_reset_scsi_bus(np, 0))
1394		goto reset_failed;
1395
1396	/*
1397	 *  Start the SCRIPTS.
1398	 */
1399	sym_start_up(shost, 1);
1400
1401	/*
1402	 *  Start the timer daemon
1403	 */
1404	init_timer(&np->s.timer);
1405	np->s.timer.data     = (unsigned long) np;
1406	np->s.timer.function = sym53c8xx_timer;
1407	np->s.lasttime=0;
1408	sym_timer (np);
1409
1410	/*
1411	 *  Fill Linux host instance structure
1412	 *  and return success.
1413	 */
1414	shost->max_channel	= 0;
1415	shost->this_id		= np->myaddr;
1416	shost->max_id		= np->maxwide ? 16 : 8;
1417	shost->max_lun		= SYM_CONF_MAX_LUN;
1418	shost->unique_id	= pci_resource_start(pdev, 0);
1419	shost->cmd_per_lun	= SYM_CONF_MAX_TAG;
1420	shost->can_queue	= (SYM_CONF_MAX_START-2);
1421	shost->sg_tablesize	= SYM_CONF_MAX_SG;
1422	shost->max_cmd_len	= 16;
1423	BUG_ON(sym2_transport_template == NULL);
1424	shost->transportt	= sym2_transport_template;
1425
1426	/* 53c896 rev 1 errata: DMA may not cross 16MB boundary */
1427	if (pdev->device == PCI_DEVICE_ID_NCR_53C896 && pdev->revision < 2)
1428		shost->dma_boundary = 0xFFFFFF;
1429
1430	spin_unlock_irqrestore(shost->host_lock, flags);
1431
1432	return shost;
1433
1434 reset_failed:
1435	printf_err("%s: FATAL ERROR: CHECK SCSI BUS - CABLES, "
1436		   "TERMINATION, DEVICE POWER etc.!\n", sym_name(np));
1437	spin_unlock_irqrestore(shost->host_lock, flags);
1438 attach_failed:
1439	printf_info("sym%d: giving up ...\n", unit);
1440	if (np)
1441		sym_free_resources(np, pdev, do_free_irq);
1442	else
1443		sym_iounmap_device(dev);
1444	if (shost)
1445		scsi_host_put(shost);
1446
1447	return NULL;
1448 }
1449
1450
1451/*
1452 *    Detect and try to read SYMBIOS and TEKRAM NVRAM.
1453 */
1454#if SYM_CONF_NVRAM_SUPPORT
1455static void __devinit sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
1456{
1457	devp->nvram = nvp;
1458	nvp->type = 0;
1459
1460	sym_read_nvram(devp, nvp);
1461}
1462#else
1463static inline void sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
1464{
1465}
1466#endif	/* SYM_CONF_NVRAM_SUPPORT */
1467
1468static int __devinit sym_check_supported(struct sym_device *device)
1469{
1470	struct sym_chip *chip;
1471	struct pci_dev *pdev = device->pdev;
1472	unsigned long io_port = pci_resource_start(pdev, 0);
1473	int i;
1474
1475	/*
1476	 *  If user excluded this chip, do not initialize it.
1477	 *  I hate this code so much.  Must kill it.
1478	 */
1479	if (io_port) {
1480		for (i = 0 ; i < 8 ; i++) {
1481			if (sym_driver_setup.excludes[i] == io_port)
1482				return -ENODEV;
1483		}
1484	}
1485
1486	/*
1487	 * Check if the chip is supported.  Then copy the chip description
1488	 * to our device structure so we can make it match the actual device
1489	 * and options.
1490	 */
1491	chip = sym_lookup_chip_table(pdev->device, pdev->revision);
1492	if (!chip) {
1493		dev_info(&pdev->dev, "device not supported\n");
1494		return -ENODEV;
1495	}
1496	memcpy(&device->chip, chip, sizeof(device->chip));
1497
1498	return 0;
1499}
1500
1501/*
1502 * Ignore Symbios chips controlled by various RAID controllers.
1503 * These controllers set value 0x52414944 at RAM end - 16.
1504 */
1505static int __devinit sym_check_raid(struct sym_device *device)
1506{
1507	unsigned int ram_size, ram_val;
1508
1509	if (!device->s.ramaddr)
1510		return 0;
1511
1512	if (device->chip.features & FE_RAM8K)
1513		ram_size = 8192;
1514	else
1515		ram_size = 4096;
1516
1517	ram_val = readl(device->s.ramaddr + ram_size - 16);
1518	if (ram_val != 0x52414944)
1519		return 0;
1520
1521	dev_info(&device->pdev->dev,
1522			"not initializing, driven by RAID controller.\n");
1523	return -ENODEV;
1524}
1525
1526static int __devinit sym_set_workarounds(struct sym_device *device)
1527{
1528	struct sym_chip *chip = &device->chip;
1529	struct pci_dev *pdev = device->pdev;
1530	u_short status_reg;
1531
1532	/*
1533	 *  (ITEM 12 of a DEL about the 896 I haven't yet).
1534	 *  We must ensure the chip will use WRITE AND INVALIDATE.
1535	 *  The revision number limit is for now arbitrary.
1536	 */
1537	if (pdev->device == PCI_DEVICE_ID_NCR_53C896 && pdev->revision < 0x4) {
1538		chip->features	|= (FE_WRIE | FE_CLSE);
1539	}
1540
1541	/* If the chip can do Memory Write Invalidate, enable it */
1542	if (chip->features & FE_WRIE) {
1543		if (pci_set_mwi(pdev))
1544			return -ENODEV;
1545	}
1546
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;
1551	} else {
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);
1556		}
1557	}
1558
1559	return 0;
1560}
1561
1562/*
1563 * Map HBA registers and on-chip SRAM (if present).
1564 */
1565static int __devinit
1566sym_iomap_device(struct sym_device *device)
1567{
1568	struct pci_dev *pdev = device->pdev;
1569	struct pci_bus_region bus_addr;
1570	int i = 2;
1571
1572	pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[1]);
1573	device->mmio_base = bus_addr.start;
1574
1575	if (device->chip.features & FE_RAM) {
1576		/*
1577		 * If the BAR is 64-bit, resource 2 will be occupied by the
1578		 * upper 32 bits
1579		 */
1580		if (!pdev->resource[i].flags)
1581			i++;
1582		pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[i]);
1583		device->ram_base = bus_addr.start;
1584	}
1585
1586#ifdef CONFIG_SCSI_SYM53C8XX_MMIO
1587	if (device->mmio_base)
1588		device->s.ioaddr = pci_iomap(pdev, 1,
1589						pci_resource_len(pdev, 1));
1590#endif
1591	if (!device->s.ioaddr)
1592		device->s.ioaddr = pci_iomap(pdev, 0,
1593						pci_resource_len(pdev, 0));
1594	if (!device->s.ioaddr) {
1595		dev_err(&pdev->dev, "could not map registers; giving up.\n");
1596		return -EIO;
1597	}
1598	if (device->ram_base) {
1599		device->s.ramaddr = pci_iomap(pdev, i,
1600						pci_resource_len(pdev, i));
1601		if (!device->s.ramaddr) {
1602			dev_warn(&pdev->dev,
1603				"could not map SRAM; continuing anyway.\n");
1604			device->ram_base = 0;
1605		}
1606	}
1607
1608	return 0;
1609}
1610
1611/*
1612 * The NCR PQS and PDS cards are constructed as a DEC bridge
1613 * behind which sits a proprietary NCR memory controller and
1614 * either four or two 53c875s as separate devices.  We can tell
1615 * if an 875 is part of a PQS/PDS or not since if it is, it will
1616 * be on the same bus as the memory controller.  In its usual
1617 * mode of operation, the 875s are slaved to the memory
1618 * controller for all transfers.  To operate with the Linux
1619 * driver, the memory controller is disabled and the 875s
1620 * freed to function independently.  The only wrinkle is that
1621 * the preset SCSI ID (which may be zero) must be read in from
1622 * a special configuration space register of the 875.
1623 */
1624static void sym_config_pqs(struct pci_dev *pdev, struct sym_device *sym_dev)
1625{
1626	int slot;
1627	u8 tmp;
1628
1629	for (slot = 0; slot < 256; slot++) {
1630		struct pci_dev *memc = pci_get_slot(pdev->bus, slot);
1631
1632		if (!memc || memc->vendor != 0x101a || memc->device == 0x0009) {
1633			pci_dev_put(memc);
1634			continue;
1635		}
1636
1637		/* bit 1: allow individual 875 configuration */
1638		pci_read_config_byte(memc, 0x44, &tmp);
1639		if ((tmp & 0x2) == 0) {
1640			tmp |= 0x2;
1641			pci_write_config_byte(memc, 0x44, tmp);
1642		}
1643
1644		/* bit 2: drive individual 875 interrupts to the bus */
1645		pci_read_config_byte(memc, 0x45, &tmp);
1646		if ((tmp & 0x4) == 0) {
1647			tmp |= 0x4;
1648			pci_write_config_byte(memc, 0x45, tmp);
1649		}
1650
1651		pci_dev_put(memc);
1652		break;
1653	}
1654
1655	pci_read_config_byte(pdev, 0x84, &tmp);
1656	sym_dev->host_id = tmp;
1657}
1658
1659/*
1660 *  Called before unloading the module.
1661 *  Detach the host.
1662 *  We have to free resources and halt the NCR chip.
1663 */
1664static int sym_detach(struct Scsi_Host *shost, struct pci_dev *pdev)
1665{
1666	struct sym_hcb *np = sym_get_hcb(shost);
1667	printk("%s: detaching ...\n", sym_name(np));
1668
1669	del_timer_sync(&np->s.timer);
1670
1671	/*
1672	 * Reset NCR chip.
1673	 * We should use sym_soft_reset(), but we don't want to do
1674	 * so, since we may not be safe if interrupts occur.
1675	 */
1676	printk("%s: resetting chip\n", sym_name(np));
1677	OUTB(np, nc_istat, SRST);
1678	INB(np, nc_mbox1);
1679	udelay(10);
1680	OUTB(np, nc_istat, 0);
1681
1682	sym_free_resources(np, pdev, 1);
1683	scsi_host_put(shost);
1684
1685	return 1;
1686}
1687
1688/*
1689 * Driver host template.
1690 */
1691static struct scsi_host_template sym2_template = {
1692	.module			= THIS_MODULE,
1693	.name			= "sym53c8xx",
1694	.info			= sym53c8xx_info,
1695	.queuecommand		= sym53c8xx_queue_command,
1696	.slave_alloc		= sym53c8xx_slave_alloc,
1697	.slave_configure	= sym53c8xx_slave_configure,
1698	.slave_destroy		= sym53c8xx_slave_destroy,
1699	.eh_abort_handler	= sym53c8xx_eh_abort_handler,
1700	.eh_device_reset_handler = sym53c8xx_eh_device_reset_handler,
1701	.eh_bus_reset_handler	= sym53c8xx_eh_bus_reset_handler,
1702	.eh_host_reset_handler	= sym53c8xx_eh_host_reset_handler,
1703	.this_id		= 7,
1704	.use_clustering		= ENABLE_CLUSTERING,
1705	.max_sectors		= 0xFFFF,
1706#ifdef SYM_LINUX_PROC_INFO_SUPPORT
1707	.proc_info		= sym53c8xx_proc_info,
1708	.proc_name		= NAME53C8XX,
1709#endif
1710};
1711
1712static int attach_count;
1713
1714static int __devinit sym2_probe(struct pci_dev *pdev,
1715				const struct pci_device_id *ent)
1716{
1717	struct sym_device sym_dev;
1718	struct sym_nvram nvram;
1719	struct Scsi_Host *shost;
1720	int do_iounmap = 0;
1721	int do_disable_device = 1;
1722
1723	memset(&sym_dev, 0, sizeof(sym_dev));
1724	memset(&nvram, 0, sizeof(nvram));
1725	sym_dev.pdev = pdev;
1726	sym_dev.host_id = SYM_SETUP_HOST_ID;
1727
1728	if (pci_enable_device(pdev))
1729		goto leave;
1730
1731	pci_set_master(pdev);
1732
1733	if (pci_request_regions(pdev, NAME53C8XX))
1734		goto disable;
1735
1736	if (sym_check_supported(&sym_dev))
1737		goto free;
1738
1739	if (sym_iomap_device(&sym_dev))
1740		goto free;
1741	do_iounmap = 1;
1742
1743	if (sym_check_raid(&sym_dev)) {
1744		do_disable_device = 0;	/* Don't disable the device */
1745		goto free;
1746	}
1747
1748	if (sym_set_workarounds(&sym_dev))
1749		goto free;
1750
1751	sym_config_pqs(pdev, &sym_dev);
1752
1753	sym_get_nvram(&sym_dev, &nvram);
1754
1755	do_iounmap = 0; /* Don't sym_iounmap_device() after sym_attach(). */
1756	shost = sym_attach(&sym2_template, attach_count, &sym_dev);
1757	if (!shost)
1758		goto free;
1759
1760	if (scsi_add_host(shost, &pdev->dev))
1761		goto detach;
1762	scsi_scan_host(shost);
1763
1764	attach_count++;
1765
1766	return 0;
1767
1768 detach:
1769	sym_detach(pci_get_drvdata(pdev), pdev);
1770 free:
1771	if (do_iounmap)
1772		sym_iounmap_device(&sym_dev);
1773	pci_release_regions(pdev);
1774 disable:
1775	if (do_disable_device)
1776		pci_disable_device(pdev);
1777 leave:
1778	return -ENODEV;
1779}
1780
1781static void sym2_remove(struct pci_dev *pdev)
1782{
1783	struct Scsi_Host *shost = pci_get_drvdata(pdev);
1784
1785	scsi_remove_host(shost);
1786	sym_detach(shost, pdev);
1787	pci_release_regions(pdev);
1788	pci_disable_device(pdev);
1789
1790	attach_count--;
1791}
1792
1793/**
1794 * sym2_io_error_detected() - called when PCI error is detected
1795 * @pdev: pointer to PCI device
1796 * @state: current state of the PCI slot
1797 */
1798static pci_ers_result_t sym2_io_error_detected(struct pci_dev *pdev,
1799                                         enum pci_channel_state state)
1800{
1801	/* If slot is permanently frozen, turn everything off */
1802	if (state == pci_channel_io_perm_failure) {
1803		sym2_remove(pdev);
1804		return PCI_ERS_RESULT_DISCONNECT;
1805	}
1806
1807	disable_irq(pdev->irq);
1808	pci_disable_device(pdev);
1809
1810	/* Request that MMIO be enabled, so register dump can be taken. */
1811	return PCI_ERS_RESULT_CAN_RECOVER;
1812}
1813
1814/**
1815 * sym2_io_slot_dump - Enable MMIO and dump debug registers
1816 * @pdev: pointer to PCI device
1817 */
1818static pci_ers_result_t sym2_io_slot_dump(struct pci_dev *pdev)
1819{
1820	struct Scsi_Host *shost = pci_get_drvdata(pdev);
1821
1822	sym_dump_registers(shost);
1823
1824	/* Request a slot reset. */
1825	return PCI_ERS_RESULT_NEED_RESET;
1826}
1827
1828/**
1829 * sym2_reset_workarounds - hardware-specific work-arounds
1830 *
1831 * This routine is similar to sym_set_workarounds(), except
1832 * that, at this point, we already know that the device was
1833 * successfully intialized at least once before, and so most
1834 * of the steps taken there are un-needed here.
1835 */
1836static void sym2_reset_workarounds(struct pci_dev *pdev)
1837{
1838	u_short status_reg;
1839	struct sym_chip *chip;
1840
1841	chip = sym_lookup_chip_table(pdev->device, pdev->revision);
1842
1843	pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1844	if (!(chip->features & FE_66MHZ) && (status_reg & PCI_STATUS_66MHZ)) {
1845		status_reg = PCI_STATUS_66MHZ;
1846		pci_write_config_word(pdev, PCI_STATUS, status_reg);
1847		pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1848	}
1849}
1850
1851/**
1852 * sym2_io_slot_reset() - called when the pci bus has been reset.
1853 * @pdev: pointer to PCI device
1854 *
1855 * Restart the card from scratch.
1856 */
1857static pci_ers_result_t sym2_io_slot_reset(struct pci_dev *pdev)
1858{
1859	struct Scsi_Host *shost = pci_get_drvdata(pdev);
1860	struct sym_hcb *np = sym_get_hcb(shost);
1861
1862	printk(KERN_INFO "%s: recovering from a PCI slot reset\n",
1863	          sym_name(np));
1864
1865	if (pci_enable_device(pdev)) {
1866		printk(KERN_ERR "%s: Unable to enable after PCI reset\n",
1867		        sym_name(np));
1868		return PCI_ERS_RESULT_DISCONNECT;
1869	}
1870
1871	pci_set_master(pdev);
1872	enable_irq(pdev->irq);
1873
1874	/* If the chip can do Memory Write Invalidate, enable it */
1875	if (np->features & FE_WRIE) {
1876		if (pci_set_mwi(pdev))
1877			return PCI_ERS_RESULT_DISCONNECT;
1878	}
1879
1880	/* Perform work-arounds, analogous to sym_set_workarounds() */
1881	sym2_reset_workarounds(pdev);
1882
1883	/* Perform host reset only on one instance of the card */
1884	if (PCI_FUNC(pdev->devfn) == 0) {
1885		if (sym_reset_scsi_bus(np, 0)) {
1886			printk(KERN_ERR "%s: Unable to reset scsi host\n",
1887			        sym_name(np));
1888			return PCI_ERS_RESULT_DISCONNECT;
1889		}
1890		sym_start_up(shost, 1);
1891	}
1892
1893	return PCI_ERS_RESULT_RECOVERED;
1894}
1895
1896/**
1897 * sym2_io_resume() - resume normal ops after PCI reset
1898 * @pdev: pointer to PCI device
1899 *
1900 * Called when the error recovery driver tells us that its
1901 * OK to resume normal operation. Use completion to allow
1902 * halted scsi ops to resume.
1903 */
1904static void sym2_io_resume(struct pci_dev *pdev)
1905{
1906	struct Scsi_Host *shost = pci_get_drvdata(pdev);
1907	struct sym_data *sym_data = shost_priv(shost);
1908
1909	spin_lock_irq(shost->host_lock);
1910	if (sym_data->io_reset)
1911		complete_all(sym_data->io_reset);
1912	spin_unlock_irq(shost->host_lock);
1913}
1914
1915static void sym2_get_signalling(struct Scsi_Host *shost)
1916{
1917	struct sym_hcb *np = sym_get_hcb(shost);
1918	enum spi_signal_type type;
1919
1920	switch (np->scsi_mode) {
1921	case SMODE_SE:
1922		type = SPI_SIGNAL_SE;
1923		break;
1924	case SMODE_LVD:
1925		type = SPI_SIGNAL_LVD;
1926		break;
1927	case SMODE_HVD:
1928		type = SPI_SIGNAL_HVD;
1929		break;
1930	default:
1931		type = SPI_SIGNAL_UNKNOWN;
1932		break;
1933	}
1934	spi_signalling(shost) = type;
1935}
1936
1937static void sym2_set_offset(struct scsi_target *starget, int offset)
1938{
1939	struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1940	struct sym_hcb *np = sym_get_hcb(shost);
1941	struct sym_tcb *tp = &np->target[starget->id];
1942
1943	tp->tgoal.offset = offset;
1944	tp->tgoal.check_nego = 1;
1945}
1946
1947static void sym2_set_period(struct scsi_target *starget, int period)
1948{
1949	struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1950	struct sym_hcb *np = sym_get_hcb(shost);
1951	struct sym_tcb *tp = &np->target[starget->id];
1952
1953	/* have to have DT for these transfers, but DT will also
1954	 * set width, so check that this is allowed */
1955	if (period <= np->minsync && spi_width(starget))
1956		tp->tgoal.dt = 1;
1957
1958	tp->tgoal.period = period;
1959	tp->tgoal.check_nego = 1;
1960}
1961
1962static void sym2_set_width(struct scsi_target *starget, int width)
1963{
1964	struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1965	struct sym_hcb *np = sym_get_hcb(shost);
1966	struct sym_tcb *tp = &np->target[starget->id];
1967
1968	/* It is illegal to have DT set on narrow transfers.  If DT is
1969	 * clear, we must also clear IU and QAS.  */
1970	if (width == 0)
1971		tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
1972
1973	tp->tgoal.width = width;
1974	tp->tgoal.check_nego = 1;
1975}
1976
1977static void sym2_set_dt(struct scsi_target *starget, int dt)
1978{
1979	struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1980	struct sym_hcb *np = sym_get_hcb(shost);
1981	struct sym_tcb *tp = &np->target[starget->id];
1982
1983	/* We must clear QAS and IU if DT is clear */
1984	if (dt)
1985		tp->tgoal.dt = 1;
1986	else
1987		tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
1988	tp->tgoal.check_nego = 1;
1989}
1990
1991
1992static struct spi_function_template sym2_transport_functions = {
1993	.set_offset	= sym2_set_offset,
1994	.show_offset	= 1,
1995	.set_period	= sym2_set_period,
1996	.show_period	= 1,
1997	.set_width	= sym2_set_width,
1998	.show_width	= 1,
1999	.set_dt		= sym2_set_dt,
2000	.show_dt	= 1,
2001	.get_signalling	= sym2_get_signalling,
2002};
2003
2004static struct pci_device_id sym2_id_table[] __devinitdata = {
2005	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C810,
2006	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2007	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C820,
2008	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
2009	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C825,
2010	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2011	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C815,
2012	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2013	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C810AP,
2014	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
2015	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C860,
2016	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2017	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1510,
2018	  PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SCSI<<8,  0xffff00, 0UL },
2019	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C896,
2020	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2021	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C895,
2022	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2023	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C885,
2024	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2025	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875,
2026	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2027	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C1510,
2028	  PCI_ANY_ID, PCI_ANY_ID,  PCI_CLASS_STORAGE_SCSI<<8,  0xffff00, 0UL }, /* new */
2029	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C895A,
2030	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2031	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C875A,
2032	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2033	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_33,
2034	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2035	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_66,
2036	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2037	{ PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875J,
2038	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2039	{ 0, }
2040};
2041
2042MODULE_DEVICE_TABLE(pci, sym2_id_table);
2043
2044static struct pci_error_handlers sym2_err_handler = {
2045	.error_detected	= sym2_io_error_detected,
2046	.mmio_enabled	= sym2_io_slot_dump,
2047	.slot_reset	= sym2_io_slot_reset,
2048	.resume		= sym2_io_resume,
2049};
2050
2051static struct pci_driver sym2_driver = {
2052	.name		= NAME53C8XX,
2053	.id_table	= sym2_id_table,
2054	.probe		= sym2_probe,
2055	.remove		= sym2_remove,
2056	.err_handler 	= &sym2_err_handler,
2057};
2058
2059static int __init sym2_init(void)
2060{
2061	int error;
2062
2063	sym2_setup_params();
2064	sym2_transport_template = spi_attach_transport(&sym2_transport_functions);
2065	if (!sym2_transport_template)
2066		return -ENODEV;
2067
2068	error = pci_register_driver(&sym2_driver);
2069	if (error)
2070		spi_release_transport(sym2_transport_template);
2071	return error;
2072}
2073
2074static void __exit sym2_exit(void)
2075{
2076	pci_unregister_driver(&sym2_driver);
2077	spi_release_transport(sym2_transport_template);
2078}
2079
2080module_init(sym2_init);
2081module_exit(sym2_exit);
2082