blob: dc9af8f8f2605ecaa8e312594de86855669d6af5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#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
Linus Torvalds1da177e2005-04-16 15:20:36 -070056struct 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062module_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");
Linus Torvalds1da177e2005-04-16 15:20:36 -070076MODULE_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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125static struct scsi_transport_template *sym2_transport_template = NULL;
126
127/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 * Driver private area in the SCSI command structure.
129 */
130struct sym_ucmd { /* Override the SCSI pointer structure */
Linas Vepstasd68cd752007-10-05 15:55:04 -0400131 struct completion *eh_done; /* SCSI error handling */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132};
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137/*
138 * Complete a pending CAM CCB.
139 */
140void sym_xpt_done(struct sym_hcb *np, struct scsi_cmnd *cmd)
141{
Matthew Wilcox2ba65362007-10-05 15:55:03 -0400142 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
Matthew Wilcox39c05d12007-10-05 15:55:00 -0400148 scsi_dma_unmap(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 cmd->scsi_done(cmd);
150}
151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152/*
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/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 * 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, sizeof(cmd->sense_buffer));
211 memcpy(cmd->sense_buffer, cp->sns_bbuf,
212 min(sizeof(cmd->sense_buffer),
213 (size_t)SYM_SNS_BBUF_LEN));
214#if 0
215 /*
216 * If the device reports a UNIT ATTENTION condition
217 * due to a RESET condition, we should consider all
218 * disconnect CCBs for this unit as aborted.
219 */
220 if (1) {
221 u_char *p;
222 p = (u_char *) cmd->sense_data;
223 if (p[0]==0x70 && p[2]==0x6 && p[12]==0x29)
224 sym_clear_tasks(np, DID_ABORT,
225 cp->target,cp->lun, -1);
226 }
227#endif
228 } else {
229 /*
230 * Error return from our internal request sense. This
231 * is bad: we must clear the contingent allegiance
232 * condition otherwise the device will always return
233 * BUSY. Use a big stick.
234 */
235 sym_reset_scsi_target(np, cmd->device->id);
236 cam_status = DID_ERROR;
237 }
238 } else if (cp->host_status == HS_COMPLETE) /* Bad SCSI status */
239 cam_status = DID_OK;
240 else if (cp->host_status == HS_SEL_TIMEOUT) /* Selection timeout */
241 cam_status = DID_NO_CONNECT;
242 else if (cp->host_status == HS_UNEXPECTED) /* Unexpected BUS FREE*/
243 cam_status = DID_ERROR;
244 else { /* Extended error */
245 if (sym_verbose) {
246 sym_print_addr(cmd, "COMMAND FAILED (%x %x %x).\n",
247 cp->host_status, cp->ssss_status,
248 cp->xerr_status);
249 }
250 /*
251 * Set the most appropriate value for CAM status.
252 */
253 cam_status = sym_xerr_cam_status(DID_ERROR, cp->xerr_status);
254 }
FUJITA Tomonori938febd2007-05-26 02:31:17 +0900255 scsi_set_resid(cmd, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 cmd->result = (drv_status << 24) + (cam_status << 16) + scsi_status;
257}
258
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259static int sym_scatter(struct sym_hcb *np, struct sym_ccb *cp, struct scsi_cmnd *cmd)
260{
261 int segment;
FUJITA Tomonori938febd2007-05-26 02:31:17 +0900262 int use_sg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
264 cp->data_len = 0;
265
Matthew Wilcox39c05d12007-10-05 15:55:00 -0400266 use_sg = scsi_dma_map(cmd);
FUJITA Tomonori938febd2007-05-26 02:31:17 +0900267 if (use_sg > 0) {
268 struct scatterlist *sg;
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100269 struct sym_tcb *tp = &np->target[cp->target];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 struct sym_tblmove *data;
271
272 if (use_sg > SYM_CONF_MAX_SG) {
Matthew Wilcox39c05d12007-10-05 15:55:00 -0400273 scsi_dma_unmap(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 return -1;
275 }
276
277 data = &cp->phys.data[SYM_CONF_MAX_SG - use_sg];
278
FUJITA Tomonori938febd2007-05-26 02:31:17 +0900279 scsi_for_each_sg(cmd, sg, use_sg, segment) {
280 dma_addr_t baddr = sg_dma_address(sg);
281 unsigned int len = sg_dma_len(sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100283 if ((len & 1) && (tp->head.wval & EWS)) {
284 len++;
285 cp->odd_byte_adjustment++;
286 }
287
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 sym_build_sge(np, &data[segment], baddr, len);
289 cp->data_len += len;
290 }
291 } else {
292 segment = -2;
293 }
294
295 return segment;
296}
297
298/*
299 * Queue a SCSI command.
300 */
301static int sym_queue_command(struct sym_hcb *np, struct scsi_cmnd *cmd)
302{
303 struct scsi_device *sdev = cmd->device;
304 struct sym_tcb *tp;
305 struct sym_lcb *lp;
306 struct sym_ccb *cp;
307 int order;
308
309 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 * Retrieve the target descriptor.
311 */
312 tp = &np->target[sdev->id];
313
314 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 * Select tagged/untagged.
316 */
317 lp = sym_lp(tp, sdev->lun);
318 order = (lp && lp->s.reqtags) ? M_SIMPLE_TAG : 0;
319
320 /*
321 * Queue the SCSI IO.
322 */
323 cp = sym_get_ccb(np, cmd, order);
324 if (!cp)
325 return 1; /* Means resource shortage */
326 sym_queue_scsiio(np, cmd, cp);
327 return 0;
328}
329
330/*
331 * Setup buffers and pointers that address the CDB.
332 */
333static inline int sym_setup_cdb(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp)
334{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 memcpy(cp->cdb_buf, cmd->cmnd, cmd->cmd_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100337 cp->phys.cmd.addr = CCB_BA(cp, cdb_buf[0]);
338 cp->phys.cmd.size = cpu_to_scr(cmd->cmd_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
340 return 0;
341}
342
343/*
344 * Setup pointers that address the data and start the I/O.
345 */
346int sym_setup_data_and_start(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp)
347{
Matthew Wilcox44f30b0f2005-11-29 23:08:33 -0500348 u32 lastp, goalp;
349 int dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
351 /*
352 * Build the CDB.
353 */
354 if (sym_setup_cdb(np, cmd, cp))
355 goto out_abort;
356
357 /*
358 * No direction means no data.
359 */
360 dir = cmd->sc_data_direction;
361 if (dir != DMA_NONE) {
362 cp->segments = sym_scatter(np, cp, cmd);
363 if (cp->segments < 0) {
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100364 sym_set_cam_status(cmd, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 goto out_abort;
366 }
Matthew Wilcox44f30b0f2005-11-29 23:08:33 -0500367
368 /*
369 * No segments means no data.
370 */
371 if (!cp->segments)
372 dir = DMA_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 } else {
374 cp->data_len = 0;
375 cp->segments = 0;
376 }
377
378 /*
Matthew Wilcox44f30b0f2005-11-29 23:08:33 -0500379 * Set the data pointer.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 */
Matthew Wilcox44f30b0f2005-11-29 23:08:33 -0500381 switch (dir) {
382 case DMA_BIDIRECTIONAL:
Matthew Wilcox3fb364e2007-10-05 15:55:10 -0400383 scmd_printk(KERN_INFO, cmd, "got DMA_BIDIRECTIONAL command");
Matthew Wilcox44f30b0f2005-11-29 23:08:33 -0500384 sym_set_cam_status(cmd, DID_ERROR);
385 goto out_abort;
386 case DMA_TO_DEVICE:
387 goalp = SCRIPTA_BA(np, data_out2) + 8;
388 lastp = goalp - 8 - (cp->segments * (2*4));
389 break;
390 case DMA_FROM_DEVICE:
391 cp->host_flags |= HF_DATA_IN;
392 goalp = SCRIPTA_BA(np, data_in2) + 8;
393 lastp = goalp - 8 - (cp->segments * (2*4));
394 break;
395 case DMA_NONE:
396 default:
397 lastp = goalp = SCRIPTB_BA(np, no_data);
398 break;
399 }
400
401 /*
402 * Set all pointers values needed by SCRIPTS.
403 */
404 cp->phys.head.lastp = cpu_to_scr(lastp);
405 cp->phys.head.savep = cpu_to_scr(lastp);
406 cp->startp = cp->phys.head.savep;
407 cp->goalp = cpu_to_scr(goalp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409 /*
410 * When `#ifed 1', the code below makes the driver
411 * panic on the first attempt to write to a SCSI device.
412 * It is the first test we want to do after a driver
413 * change that does not seem obviously safe. :)
414 */
415#if 0
416 switch (cp->cdb_buf[0]) {
417 case 0x0A: case 0x2A: case 0xAA:
418 panic("XXXXXXXXXXXXX WRITE NOT YET ALLOWED XXXXXXXXXXXXXX\n");
419 break;
420 default:
421 break;
422 }
423#endif
424
425 /*
426 * activate this job.
427 */
Matthew Wilcox3bea15a2006-03-28 11:03:44 -0500428 sym_put_start_queue(np, cp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 return 0;
430
431out_abort:
432 sym_free_ccb(np, cp);
433 sym_xpt_done(np, cmd);
434 return 0;
435}
436
437
438/*
439 * timer daemon.
440 *
441 * Misused to keep the driver running when
442 * interrupts are not configured correctly.
443 */
444static void sym_timer(struct sym_hcb *np)
445{
446 unsigned long thistime = jiffies;
447
448 /*
449 * Restart the timer.
450 */
451 np->s.timer.expires = thistime + SYM_CONF_TIMER_INTERVAL;
452 add_timer(&np->s.timer);
453
454 /*
455 * If we are resetting the ncr, wait for settle_time before
456 * clearing it. Then command processing will be resumed.
457 */
458 if (np->s.settle_time_valid) {
459 if (time_before_eq(np->s.settle_time, thistime)) {
460 if (sym_verbose >= 2 )
461 printk("%s: command processing resumed\n",
462 sym_name(np));
463 np->s.settle_time_valid = 0;
464 }
465 return;
466 }
467
468 /*
469 * Nothing to do for now, but that may come.
470 */
471 if (np->s.lasttime + 4*HZ < thistime) {
472 np->s.lasttime = thistime;
473 }
474
475#ifdef SYM_CONF_PCIQ_MAY_MISS_COMPLETIONS
476 /*
477 * Some way-broken PCI bridges may lead to
478 * completions being lost when the clearing
479 * of the INTFLY flag by the CPU occurs
480 * concurrently with the chip raising this flag.
481 * If this ever happen, lost completions will
482 * be reaped here.
483 */
484 sym_wakeup_done(np);
485#endif
486}
487
488
489/*
490 * PCI BUS error handler.
491 */
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400492void sym_log_bus_error(struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493{
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400494 struct sym_data *sym_data = shost_priv(shost);
495 struct pci_dev *pdev = sym_data->pdev;
496 unsigned short pci_sts;
497 pci_read_config_word(pdev, PCI_STATUS, &pci_sts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 if (pci_sts & 0xf900) {
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400499 pci_write_config_word(pdev, PCI_STATUS, pci_sts);
500 shost_printk(KERN_WARNING, shost,
501 "PCI bus error: status = 0x%04x\n", pci_sts & 0xf900);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 }
503}
504
505/*
506 * queuecommand method. Entered with the host adapter lock held and
507 * interrupts disabled.
508 */
509static int sym53c8xx_queue_command(struct scsi_cmnd *cmd,
510 void (*done)(struct scsi_cmnd *))
511{
512 struct sym_hcb *np = SYM_SOFTC_PTR(cmd);
513 struct sym_ucmd *ucp = SYM_UCMD_PTR(cmd);
514 int sts = 0;
515
Matthew Wilcox71c222d2007-10-05 15:55:01 -0400516 cmd->scsi_done = done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 memset(ucp, 0, sizeof(*ucp));
518
519 /*
520 * Shorten our settle_time if needed for
521 * this command not to time out.
522 */
523 if (np->s.settle_time_valid && cmd->timeout_per_command) {
524 unsigned long tlimit = jiffies + cmd->timeout_per_command;
525 tlimit -= SYM_CONF_TIMER_INTERVAL*2;
526 if (time_after(np->s.settle_time, tlimit)) {
527 np->s.settle_time = tlimit;
528 }
529 }
530
531 if (np->s.settle_time_valid)
532 return SCSI_MLQUEUE_HOST_BUSY;
533
534 sts = sym_queue_command(np, cmd);
535 if (sts)
536 return SCSI_MLQUEUE_HOST_BUSY;
537 return 0;
538}
539
540/*
541 * Linux entry point of the interrupt handler.
542 */
David Howells7d12e782006-10-05 14:55:46 +0100543static irqreturn_t sym53c8xx_intr(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544{
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -0400545 struct Scsi_Host *shost = dev_id;
546 struct sym_data *sym_data = shost_priv(shost);
547 irqreturn_t result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
Linas Vepstasd68cd752007-10-05 15:55:04 -0400549 /* Avoid spinloop trying to handle interrupts on frozen device */
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -0400550 if (pci_channel_offline(sym_data->pdev))
Linas Vepstasd68cd752007-10-05 15:55:04 -0400551 return IRQ_NONE;
552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("[");
554
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -0400555 spin_lock(shost->host_lock);
556 result = sym_interrupt(shost);
557 spin_unlock(shost->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
559 if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("]\n");
560
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -0400561 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562}
563
564/*
565 * Linux entry point of the timer handler
566 */
567static void sym53c8xx_timer(unsigned long npref)
568{
569 struct sym_hcb *np = (struct sym_hcb *)npref;
570 unsigned long flags;
571
572 spin_lock_irqsave(np->s.host->host_lock, flags);
573 sym_timer(np);
574 spin_unlock_irqrestore(np->s.host->host_lock, flags);
575}
576
577
578/*
579 * What the eh thread wants us to perform.
580 */
581#define SYM_EH_ABORT 0
582#define SYM_EH_DEVICE_RESET 1
583#define SYM_EH_BUS_RESET 2
584#define SYM_EH_HOST_RESET 3
585
586/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 * Generic method for our eh processing.
588 * The 'op' argument tells what we have to do.
589 */
590static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd)
591{
Matthew Wilcoxb4e93a72006-03-28 11:03:44 -0500592 struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400593 struct Scsi_Host *shost = cmd->device->host;
594 struct sym_data *sym_data = shost_priv(shost);
595 struct pci_dev *pdev = sym_data->pdev;
596 struct sym_hcb *np = sym_data->ncb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 SYM_QUEHEAD *qp;
Matthew Wilcox2ba65362007-10-05 15:55:03 -0400598 int cmd_queued = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 int sts = -1;
Matthew Wilcoxd637c452006-03-29 14:45:18 -0700600 struct completion eh_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400602 scmd_printk(KERN_WARNING, cmd, "%s operation started\n", opname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
Linas Vepstasd68cd752007-10-05 15:55:04 -0400604 /* We may be in an error condition because the PCI bus
605 * went down. In this case, we need to wait until the
606 * PCI bus is reset, the card is reset, and only then
607 * proceed with the scsi error recovery. There's no
608 * point in hurrying; take a leisurely wait.
609 */
610#define WAIT_FOR_PCI_RECOVERY 35
611 if (pci_channel_offline(pdev)) {
Linas Vepstasd68cd752007-10-05 15:55:04 -0400612 int finished_reset = 0;
613 init_completion(&eh_done);
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400614 spin_lock_irq(shost->host_lock);
Linas Vepstasd68cd752007-10-05 15:55:04 -0400615 /* Make sure we didn't race */
616 if (pci_channel_offline(pdev)) {
Krzysztof Heltd9aa3af2008-01-11 21:50:46 +0100617 BUG_ON(sym_data->io_reset);
618 sym_data->io_reset = &eh_done;
Linas Vepstasd68cd752007-10-05 15:55:04 -0400619 } else {
Linas Vepstasd68cd752007-10-05 15:55:04 -0400620 finished_reset = 1;
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -0400621 }
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400622 spin_unlock_irq(shost->host_lock);
Linas Vepstasd68cd752007-10-05 15:55:04 -0400623 if (!finished_reset)
Krzysztof Heltd9aa3af2008-01-11 21:50:46 +0100624 finished_reset = wait_for_completion_timeout
625 (sym_data->io_reset,
Linas Vepstasd68cd752007-10-05 15:55:04 -0400626 WAIT_FOR_PCI_RECOVERY*HZ);
Krzysztof Heltd9aa3af2008-01-11 21:50:46 +0100627 spin_lock_irq(shost->host_lock);
628 sym_data->io_reset = NULL;
629 spin_unlock_irq(shost->host_lock);
Linas Vepstasd68cd752007-10-05 15:55:04 -0400630 if (!finished_reset)
631 return SCSI_FAILED;
632 }
633
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400634 spin_lock_irq(shost->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 /* This one is queued in some place -> to wait for completion */
636 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
637 struct sym_ccb *cp = sym_que_entry(qp, struct sym_ccb, link_ccbq);
638 if (cp->cmd == cmd) {
Matthew Wilcox2ba65362007-10-05 15:55:03 -0400639 cmd_queued = 1;
Matthew Wilcoxab19d522006-03-28 11:03:44 -0500640 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 }
642 }
643
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 /* Try to proceed the operation we have been asked for */
645 sts = -1;
646 switch(op) {
647 case SYM_EH_ABORT:
648 sts = sym_abort_scsiio(np, cmd, 1);
649 break;
650 case SYM_EH_DEVICE_RESET:
651 sts = sym_reset_scsi_target(np, cmd->device->id);
652 break;
653 case SYM_EH_BUS_RESET:
654 sym_reset_scsi_bus(np, 1);
655 sts = 0;
656 break;
657 case SYM_EH_HOST_RESET:
658 sym_reset_scsi_bus(np, 0);
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400659 sym_start_up(shost, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 sts = 0;
661 break;
662 default:
663 break;
664 }
665
666 /* On error, restore everything and cross fingers :) */
Matthew Wilcox2ba65362007-10-05 15:55:03 -0400667 if (sts)
668 cmd_queued = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
Matthew Wilcox2ba65362007-10-05 15:55:03 -0400670 if (cmd_queued) {
671 init_completion(&eh_done);
672 ucmd->eh_done = &eh_done;
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400673 spin_unlock_irq(shost->host_lock);
Matthew Wilcoxd637c452006-03-29 14:45:18 -0700674 if (!wait_for_completion_timeout(&eh_done, 5*HZ)) {
Matthew Wilcox2ba65362007-10-05 15:55:03 -0400675 ucmd->eh_done = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 sts = -2;
Matthew Wilcoxb4e93a72006-03-28 11:03:44 -0500677 }
Matthew Wilcox2ba65362007-10-05 15:55:03 -0400678 } else {
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400679 spin_unlock_irq(shost->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 }
Matthew Wilcox2ba65362007-10-05 15:55:03 -0400681
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 dev_warn(&cmd->device->sdev_gendev, "%s operation %s.\n", opname,
683 sts==0 ? "complete" :sts==-2 ? "timed-out" : "failed");
684 return sts ? SCSI_FAILED : SCSI_SUCCESS;
685}
686
687
688/*
689 * Error handlers called from the eh thread (one thread per HBA).
690 */
691static int sym53c8xx_eh_abort_handler(struct scsi_cmnd *cmd)
692{
Matthew Wilcoxab19d522006-03-28 11:03:44 -0500693 return sym_eh_handler(SYM_EH_ABORT, "ABORT", cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694}
695
696static int sym53c8xx_eh_device_reset_handler(struct scsi_cmnd *cmd)
697{
Matthew Wilcoxab19d522006-03-28 11:03:44 -0500698 return sym_eh_handler(SYM_EH_DEVICE_RESET, "DEVICE RESET", cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699}
700
701static int sym53c8xx_eh_bus_reset_handler(struct scsi_cmnd *cmd)
702{
Matthew Wilcoxab19d522006-03-28 11:03:44 -0500703 return sym_eh_handler(SYM_EH_BUS_RESET, "BUS RESET", cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704}
705
706static int sym53c8xx_eh_host_reset_handler(struct scsi_cmnd *cmd)
707{
Matthew Wilcoxab19d522006-03-28 11:03:44 -0500708 return sym_eh_handler(SYM_EH_HOST_RESET, "HOST RESET", cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709}
710
711/*
712 * Tune device queuing depth, according to various limits.
713 */
714static void sym_tune_dev_queuing(struct sym_tcb *tp, int lun, u_short reqtags)
715{
716 struct sym_lcb *lp = sym_lp(tp, lun);
717 u_short oldtags;
718
719 if (!lp)
720 return;
721
722 oldtags = lp->s.reqtags;
723
724 if (reqtags > lp->s.scdev_depth)
725 reqtags = lp->s.scdev_depth;
726
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 lp->s.reqtags = reqtags;
728
729 if (reqtags != oldtags) {
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100730 dev_info(&tp->starget->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 "tagged command queuing %s, command queue depth %d.\n",
Matthew Wilcox3bea15a2006-03-28 11:03:44 -0500732 lp->s.reqtags ? "enabled" : "disabled", reqtags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 }
734}
735
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100736static int sym53c8xx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737{
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500738 struct sym_hcb *np = sym_get_hcb(sdev->host);
739 struct sym_tcb *tp = &np->target[sdev->id];
740 struct sym_lcb *lp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100742 if (sdev->id >= SYM_CONF_MAX_TARGET || sdev->lun >= SYM_CONF_MAX_LUN)
743 return -ENXIO;
744
Matthew Wilcox66e8d1c2005-11-29 23:08:46 -0500745 tp->starget = sdev->sdev_target;
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100746 /*
747 * Fail the device init if the device is flagged NOSCAN at BOOT in
748 * the NVRAM. This may speed up boot and maintain coherency with
749 * BIOS device numbering. Clearing the flag allows the user to
750 * rescan skipped devices later. We also return an error for
751 * devices not flagged for SCAN LUNS in the NVRAM since some single
752 * lun devices behave badly when asked for a non zero LUN.
753 */
754
Matthew Wilcox66e8d1c2005-11-29 23:08:46 -0500755 if (tp->usrflags & SYM_SCAN_BOOT_DISABLED) {
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100756 tp->usrflags &= ~SYM_SCAN_BOOT_DISABLED;
Matthew Wilcox66e8d1c2005-11-29 23:08:46 -0500757 starget_printk(KERN_INFO, tp->starget,
758 "Scan at boot disabled in NVRAM\n");
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100759 return -ENXIO;
760 }
761
Matthew Wilcox66e8d1c2005-11-29 23:08:46 -0500762 if (tp->usrflags & SYM_SCAN_LUNS_DISABLED) {
763 if (sdev->lun != 0)
764 return -ENXIO;
765 starget_printk(KERN_INFO, tp->starget,
766 "Multiple LUNs disabled in NVRAM\n");
767 }
768
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500769 lp = sym_alloc_lcb(np, sdev->id, sdev->lun);
770 if (!lp)
771 return -ENOMEM;
772
Matthew Wilcoxb37df482005-11-29 23:08:44 -0500773 spi_min_period(tp->starget) = tp->usr_period;
774 spi_max_width(tp->starget) = tp->usr_width;
775
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 return 0;
777}
778
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779/*
780 * Linux entry point for device queue sizing.
781 */
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500782static int sym53c8xx_slave_configure(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783{
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500784 struct sym_hcb *np = sym_get_hcb(sdev->host);
785 struct sym_tcb *tp = &np->target[sdev->id];
786 struct sym_lcb *lp = sym_lp(tp, sdev->lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 int reqtags, depth_to_use;
788
789 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 * Get user flags.
791 */
792 lp->curr_flags = lp->user_flags;
793
794 /*
795 * Select queue depth from driver setup.
796 * Donnot use more than configured by user.
797 * Use at least 2.
798 * Donnot use more than our maximum.
799 */
Matthew Wilcoxa44131b2007-10-05 15:55:08 -0400800 reqtags = sym_driver_setup.max_tag;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 if (reqtags > tp->usrtags)
802 reqtags = tp->usrtags;
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500803 if (!sdev->tagged_supported)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 reqtags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 if (reqtags > SYM_CONF_MAX_TAG)
806 reqtags = SYM_CONF_MAX_TAG;
Matthew Wilcoxa44131b2007-10-05 15:55:08 -0400807 depth_to_use = reqtags ? reqtags : 2;
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500808 scsi_adjust_queue_depth(sdev,
Matthew Wilcoxa44131b2007-10-05 15:55:08 -0400809 sdev->tagged_supported ? MSG_SIMPLE_TAG : 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 depth_to_use);
811 lp->s.scdev_depth = depth_to_use;
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500812 sym_tune_dev_queuing(tp, sdev->lun, reqtags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500814 if (!spi_initial_dv(sdev->sdev_target))
815 spi_dv_device(sdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
817 return 0;
818}
819
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500820static void sym53c8xx_slave_destroy(struct scsi_device *sdev)
821{
822 struct sym_hcb *np = sym_get_hcb(sdev->host);
823 struct sym_lcb *lp = sym_lp(&np->target[sdev->id], sdev->lun);
824
825 if (lp->itlq_tbl)
826 sym_mfree_dma(lp->itlq_tbl, SYM_CONF_MAX_TASK * 4, "ITLQ_TBL");
827 kfree(lp->cb_tags);
828 sym_mfree_dma(lp, sizeof(*lp), "LCB");
829}
830
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831/*
832 * Linux entry point for info() function
833 */
834static const char *sym53c8xx_info (struct Scsi_Host *host)
835{
836 return SYM_DRIVER_NAME;
837}
838
839
840#ifdef SYM_LINUX_PROC_INFO_SUPPORT
841/*
842 * Proc file system stuff
843 *
844 * A read operation returns adapter information.
845 * A write operation is a control command.
846 * The string is parsed in the driver code and the command is passed
847 * to the sym_usercmd() function.
848 */
849
850#ifdef SYM_LINUX_USER_COMMAND_SUPPORT
851
852struct sym_usrcmd {
853 u_long target;
854 u_long lun;
855 u_long data;
856 u_long cmd;
857};
858
859#define UC_SETSYNC 10
860#define UC_SETTAGS 11
861#define UC_SETDEBUG 12
862#define UC_SETWIDE 14
863#define UC_SETFLAG 15
864#define UC_SETVERBOSE 17
865#define UC_RESETDEV 18
866#define UC_CLEARDEV 19
867
868static void sym_exec_user_command (struct sym_hcb *np, struct sym_usrcmd *uc)
869{
870 struct sym_tcb *tp;
871 int t, l;
872
873 switch (uc->cmd) {
874 case 0: return;
875
876#ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
877 case UC_SETDEBUG:
878 sym_debug_flags = uc->data;
879 break;
880#endif
881 case UC_SETVERBOSE:
882 np->verbose = uc->data;
883 break;
884 default:
885 /*
886 * We assume that other commands apply to targets.
887 * This should always be the case and avoid the below
888 * 4 lines to be repeated 6 times.
889 */
890 for (t = 0; t < SYM_CONF_MAX_TARGET; t++) {
891 if (!((uc->target >> t) & 1))
892 continue;
893 tp = &np->target[t];
894
895 switch (uc->cmd) {
896
897 case UC_SETSYNC:
898 if (!uc->data || uc->data >= 255) {
899 tp->tgoal.iu = tp->tgoal.dt =
900 tp->tgoal.qas = 0;
901 tp->tgoal.offset = 0;
902 } else if (uc->data <= 9 && np->minsync_dt) {
903 if (uc->data < np->minsync_dt)
904 uc->data = np->minsync_dt;
905 tp->tgoal.iu = tp->tgoal.dt =
906 tp->tgoal.qas = 1;
907 tp->tgoal.width = 1;
908 tp->tgoal.period = uc->data;
909 tp->tgoal.offset = np->maxoffs_dt;
910 } else {
911 if (uc->data < np->minsync)
912 uc->data = np->minsync;
913 tp->tgoal.iu = tp->tgoal.dt =
914 tp->tgoal.qas = 0;
915 tp->tgoal.period = uc->data;
916 tp->tgoal.offset = np->maxoffs;
917 }
918 tp->tgoal.check_nego = 1;
919 break;
920 case UC_SETWIDE:
921 tp->tgoal.width = uc->data ? 1 : 0;
922 tp->tgoal.check_nego = 1;
923 break;
924 case UC_SETTAGS:
925 for (l = 0; l < SYM_CONF_MAX_LUN; l++)
926 sym_tune_dev_queuing(tp, l, uc->data);
927 break;
928 case UC_RESETDEV:
929 tp->to_reset = 1;
930 np->istat_sem = SEM;
931 OUTB(np, nc_istat, SIGP|SEM);
932 break;
933 case UC_CLEARDEV:
934 for (l = 0; l < SYM_CONF_MAX_LUN; l++) {
935 struct sym_lcb *lp = sym_lp(tp, l);
936 if (lp) lp->to_clear = 1;
937 }
938 np->istat_sem = SEM;
939 OUTB(np, nc_istat, SIGP|SEM);
940 break;
941 case UC_SETFLAG:
942 tp->usrflags = uc->data;
943 break;
944 }
945 }
946 break;
947 }
948}
949
950static int skip_spaces(char *ptr, int len)
951{
952 int cnt, c;
953
954 for (cnt = len; cnt > 0 && (c = *ptr++) && isspace(c); cnt--);
955
956 return (len - cnt);
957}
958
959static int get_int_arg(char *ptr, int len, u_long *pv)
960{
961 char *end;
962
963 *pv = simple_strtoul(ptr, &end, 10);
964 return (end - ptr);
965}
966
967static int is_keyword(char *ptr, int len, char *verb)
968{
969 int verb_len = strlen(verb);
970
971 if (len >= verb_len && !memcmp(verb, ptr, verb_len))
972 return verb_len;
973 else
974 return 0;
975}
976
977#define SKIP_SPACES(ptr, len) \
978 if ((arg_len = skip_spaces(ptr, len)) < 1) \
979 return -EINVAL; \
980 ptr += arg_len; len -= arg_len;
981
982#define GET_INT_ARG(ptr, len, v) \
983 if (!(arg_len = get_int_arg(ptr, len, &(v)))) \
984 return -EINVAL; \
985 ptr += arg_len; len -= arg_len;
986
987
988/*
989 * Parse a control command
990 */
991
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400992static int sym_user_command(struct Scsi_Host *shost, char *buffer, int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993{
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400994 struct sym_hcb *np = sym_get_hcb(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 char *ptr = buffer;
996 int len = length;
997 struct sym_usrcmd cmd, *uc = &cmd;
998 int arg_len;
999 u_long target;
1000
1001 memset(uc, 0, sizeof(*uc));
1002
1003 if (len > 0 && ptr[len-1] == '\n')
1004 --len;
1005
1006 if ((arg_len = is_keyword(ptr, len, "setsync")) != 0)
1007 uc->cmd = UC_SETSYNC;
1008 else if ((arg_len = is_keyword(ptr, len, "settags")) != 0)
1009 uc->cmd = UC_SETTAGS;
1010 else if ((arg_len = is_keyword(ptr, len, "setverbose")) != 0)
1011 uc->cmd = UC_SETVERBOSE;
1012 else if ((arg_len = is_keyword(ptr, len, "setwide")) != 0)
1013 uc->cmd = UC_SETWIDE;
1014#ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1015 else if ((arg_len = is_keyword(ptr, len, "setdebug")) != 0)
1016 uc->cmd = UC_SETDEBUG;
1017#endif
1018 else if ((arg_len = is_keyword(ptr, len, "setflag")) != 0)
1019 uc->cmd = UC_SETFLAG;
1020 else if ((arg_len = is_keyword(ptr, len, "resetdev")) != 0)
1021 uc->cmd = UC_RESETDEV;
1022 else if ((arg_len = is_keyword(ptr, len, "cleardev")) != 0)
1023 uc->cmd = UC_CLEARDEV;
1024 else
1025 arg_len = 0;
1026
1027#ifdef DEBUG_PROC_INFO
1028printk("sym_user_command: arg_len=%d, cmd=%ld\n", arg_len, uc->cmd);
1029#endif
1030
1031 if (!arg_len)
1032 return -EINVAL;
1033 ptr += arg_len; len -= arg_len;
1034
1035 switch(uc->cmd) {
1036 case UC_SETSYNC:
1037 case UC_SETTAGS:
1038 case UC_SETWIDE:
1039 case UC_SETFLAG:
1040 case UC_RESETDEV:
1041 case UC_CLEARDEV:
1042 SKIP_SPACES(ptr, len);
1043 if ((arg_len = is_keyword(ptr, len, "all")) != 0) {
1044 ptr += arg_len; len -= arg_len;
1045 uc->target = ~0;
1046 } else {
1047 GET_INT_ARG(ptr, len, target);
1048 uc->target = (1<<target);
1049#ifdef DEBUG_PROC_INFO
1050printk("sym_user_command: target=%ld\n", target);
1051#endif
1052 }
1053 break;
1054 }
1055
1056 switch(uc->cmd) {
1057 case UC_SETVERBOSE:
1058 case UC_SETSYNC:
1059 case UC_SETTAGS:
1060 case UC_SETWIDE:
1061 SKIP_SPACES(ptr, len);
1062 GET_INT_ARG(ptr, len, uc->data);
1063#ifdef DEBUG_PROC_INFO
1064printk("sym_user_command: data=%ld\n", uc->data);
1065#endif
1066 break;
1067#ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1068 case UC_SETDEBUG:
1069 while (len > 0) {
1070 SKIP_SPACES(ptr, len);
1071 if ((arg_len = is_keyword(ptr, len, "alloc")))
1072 uc->data |= DEBUG_ALLOC;
1073 else if ((arg_len = is_keyword(ptr, len, "phase")))
1074 uc->data |= DEBUG_PHASE;
1075 else if ((arg_len = is_keyword(ptr, len, "queue")))
1076 uc->data |= DEBUG_QUEUE;
1077 else if ((arg_len = is_keyword(ptr, len, "result")))
1078 uc->data |= DEBUG_RESULT;
1079 else if ((arg_len = is_keyword(ptr, len, "scatter")))
1080 uc->data |= DEBUG_SCATTER;
1081 else if ((arg_len = is_keyword(ptr, len, "script")))
1082 uc->data |= DEBUG_SCRIPT;
1083 else if ((arg_len = is_keyword(ptr, len, "tiny")))
1084 uc->data |= DEBUG_TINY;
1085 else if ((arg_len = is_keyword(ptr, len, "timing")))
1086 uc->data |= DEBUG_TIMING;
1087 else if ((arg_len = is_keyword(ptr, len, "nego")))
1088 uc->data |= DEBUG_NEGO;
1089 else if ((arg_len = is_keyword(ptr, len, "tags")))
1090 uc->data |= DEBUG_TAGS;
1091 else if ((arg_len = is_keyword(ptr, len, "pointer")))
1092 uc->data |= DEBUG_POINTER;
1093 else
1094 return -EINVAL;
1095 ptr += arg_len; len -= arg_len;
1096 }
1097#ifdef DEBUG_PROC_INFO
1098printk("sym_user_command: data=%ld\n", uc->data);
1099#endif
1100 break;
1101#endif /* SYM_LINUX_DEBUG_CONTROL_SUPPORT */
1102 case UC_SETFLAG:
1103 while (len > 0) {
1104 SKIP_SPACES(ptr, len);
1105 if ((arg_len = is_keyword(ptr, len, "no_disc")))
1106 uc->data &= ~SYM_DISC_ENABLED;
1107 else
1108 return -EINVAL;
1109 ptr += arg_len; len -= arg_len;
1110 }
1111 break;
1112 default:
1113 break;
1114 }
1115
1116 if (len)
1117 return -EINVAL;
1118 else {
1119 unsigned long flags;
1120
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001121 spin_lock_irqsave(shost->host_lock, flags);
1122 sym_exec_user_command(np, uc);
1123 spin_unlock_irqrestore(shost->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 }
1125 return length;
1126}
1127
1128#endif /* SYM_LINUX_USER_COMMAND_SUPPORT */
1129
1130
1131#ifdef SYM_LINUX_USER_INFO_SUPPORT
1132/*
1133 * Informations through the proc file system.
1134 */
1135struct info_str {
1136 char *buffer;
1137 int length;
1138 int offset;
1139 int pos;
1140};
1141
1142static void copy_mem_info(struct info_str *info, char *data, int len)
1143{
1144 if (info->pos + len > info->length)
1145 len = info->length - info->pos;
1146
1147 if (info->pos + len < info->offset) {
1148 info->pos += len;
1149 return;
1150 }
1151 if (info->pos < info->offset) {
1152 data += (info->offset - info->pos);
1153 len -= (info->offset - info->pos);
1154 }
1155
1156 if (len > 0) {
1157 memcpy(info->buffer + info->pos, data, len);
1158 info->pos += len;
1159 }
1160}
1161
1162static int copy_info(struct info_str *info, char *fmt, ...)
1163{
1164 va_list args;
1165 char buf[81];
1166 int len;
1167
1168 va_start(args, fmt);
1169 len = vsprintf(buf, fmt, args);
1170 va_end(args);
1171
1172 copy_mem_info(info, buf, len);
1173 return len;
1174}
1175
1176/*
1177 * Copy formatted information into the input buffer.
1178 */
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001179static int sym_host_info(struct Scsi_Host *shost, char *ptr, off_t offset, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180{
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001181 struct sym_data *sym_data = shost_priv(shost);
1182 struct pci_dev *pdev = sym_data->pdev;
1183 struct sym_hcb *np = sym_data->ncb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 struct info_str info;
1185
1186 info.buffer = ptr;
1187 info.length = len;
1188 info.offset = offset;
1189 info.pos = 0;
1190
1191 copy_info(&info, "Chip " NAME53C "%s, device id 0x%x, "
Matthew Wilcoxbd678452007-10-05 15:55:05 -04001192 "revision id 0x%x\n", np->s.chip_name,
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001193 pdev->device, pdev->revision);
Matthew Wilcox8022fbd2007-10-05 15:55:11 -04001194 copy_info(&info, "At PCI address %s, IRQ %u\n",
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001195 pci_name(pdev), pdev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 copy_info(&info, "Min. period factor %d, %s SCSI BUS%s\n",
1197 (int) (np->minsync_dt ? np->minsync_dt : np->minsync),
1198 np->maxwide ? "Wide" : "Narrow",
1199 np->minsync_dt ? ", DT capable" : "");
1200
1201 copy_info(&info, "Max. started commands %d, "
1202 "max. commands per LUN %d\n",
1203 SYM_CONF_MAX_START, SYM_CONF_MAX_TAG);
1204
1205 return info.pos > info.offset? info.pos - info.offset : 0;
1206}
1207#endif /* SYM_LINUX_USER_INFO_SUPPORT */
1208
1209/*
1210 * Entry point of the scsi proc fs of the driver.
1211 * - func = 0 means read (returns adapter infos)
1212 * - func = 1 means write (not yet merget from sym53c8xx)
1213 */
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001214static int sym53c8xx_proc_info(struct Scsi_Host *shost, char *buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 char **start, off_t offset, int length, int func)
1216{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 int retv;
1218
1219 if (func) {
1220#ifdef SYM_LINUX_USER_COMMAND_SUPPORT
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001221 retv = sym_user_command(shost, buffer, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222#else
1223 retv = -EINVAL;
1224#endif
1225 } else {
1226 if (start)
1227 *start = buffer;
1228#ifdef SYM_LINUX_USER_INFO_SUPPORT
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001229 retv = sym_host_info(shost, buffer, offset, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230#else
1231 retv = -EINVAL;
1232#endif
1233 }
1234
1235 return retv;
1236}
1237#endif /* SYM_LINUX_PROC_INFO_SUPPORT */
1238
1239/*
1240 * Free controller resources.
1241 */
1242static void sym_free_resources(struct sym_hcb *np, struct pci_dev *pdev)
1243{
1244 /*
1245 * Free O/S specific resources.
1246 */
Matthew Wilcoxf363abf2007-10-05 15:54:59 -04001247 if (pdev->irq)
Tony Battersby7ee24132007-11-06 14:40:54 -05001248 free_irq(pdev->irq, np->s.host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 if (np->s.ioaddr)
1250 pci_iounmap(pdev, np->s.ioaddr);
1251 if (np->s.ramaddr)
1252 pci_iounmap(pdev, np->s.ramaddr);
1253 /*
1254 * Free O/S independent resources.
1255 */
1256 sym_hcb_free(np);
1257
1258 sym_mfree_dma(np, sizeof(*np), "HCB");
1259}
1260
1261/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 * Host attach and initialisations.
1263 *
1264 * Allocate host data and ncb structure.
1265 * Remap MMIO region.
1266 * Do chip initialization.
1267 * If all is OK, install interrupt handling and
1268 * start the timer daemon.
1269 */
1270static struct Scsi_Host * __devinit sym_attach(struct scsi_host_template *tpnt,
1271 int unit, struct sym_device *dev)
1272{
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001273 struct sym_data *sym_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 struct sym_hcb *np = NULL;
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001275 struct Scsi_Host *shost;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 struct pci_dev *pdev = dev->pdev;
1277 unsigned long flags;
1278 struct sym_fw *fw;
1279
Matthew Wilcox8022fbd2007-10-05 15:55:11 -04001280 printk(KERN_INFO "sym%d: <%s> rev 0x%x at pci %s irq %u\n",
Matthew Wilcoxbd678452007-10-05 15:55:05 -04001281 unit, dev->chip.name, pdev->revision, pci_name(pdev),
Matthew Wilcox8022fbd2007-10-05 15:55:11 -04001282 pdev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
1284 /*
1285 * Get the firmware for this chip.
1286 */
1287 fw = sym_find_firmware(&dev->chip);
1288 if (!fw)
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001289 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001291 shost = scsi_host_alloc(tpnt, sizeof(*sym_data));
1292 if (!shost)
1293 return NULL;
1294 sym_data = shost_priv(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
1296 /*
1297 * Allocate immediately the host control block,
1298 * since we are only expecting to succeed. :)
1299 * We keep track in the HCB of all the resources that
1300 * are to be released on error.
1301 */
1302 np = __sym_calloc_dma(&pdev->dev, sizeof(*np), "HCB");
1303 if (!np)
1304 goto attach_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 np->bus_dmat = &pdev->dev; /* Result in 1 DMA pool per HBA */
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001306 sym_data->ncb = np;
1307 sym_data->pdev = pdev;
1308 np->s.host = shost;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001310 pci_set_drvdata(pdev, shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
1312 /*
1313 * Copy some useful infos to the HCB.
1314 */
1315 np->hcb_ba = vtobus(np);
1316 np->verbose = sym_driver_setup.verbose;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 np->s.unit = unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 np->features = dev->chip.features;
1319 np->clock_divn = dev->chip.nr_divisor;
1320 np->maxoffs = dev->chip.offset_max;
1321 np->maxburst = dev->chip.burst_max;
1322 np->myaddr = dev->host_id;
1323
1324 /*
1325 * Edit its name.
1326 */
1327 strlcpy(np->s.chip_name, dev->chip.name, sizeof(np->s.chip_name));
1328 sprintf(np->s.inst_name, "sym%d", np->s.unit);
1329
Matthew Wilcox4d85b472007-10-05 15:55:09 -04001330 if ((SYM_CONF_DMA_ADDRESSING_MODE > 0) && (np->features & FE_DAC) &&
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001331 !pci_set_dma_mask(pdev, DMA_DAC_MASK)) {
Matthew Wilcox4d85b472007-10-05 15:55:09 -04001332 set_dac(np);
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001333 } else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
Matthew Wilcox4d85b472007-10-05 15:55:09 -04001334 printf_warning("%s: No suitable DMA available\n", sym_name(np));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 goto attach_failed;
Matthew Wilcox4d85b472007-10-05 15:55:09 -04001336 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337
1338 /*
1339 * Try to map the controller chip to
1340 * virtual and physical memory.
1341 */
1342 np->mmio_ba = (u32)dev->mmio_base;
1343 np->s.ioaddr = dev->s.ioaddr;
1344 np->s.ramaddr = dev->s.ramaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
1346 /*
1347 * Map on-chip RAM if present and supported.
1348 */
1349 if (!(np->features & FE_RAM))
1350 dev->ram_base = 0;
Matthew Wilcox8637baa2007-10-05 15:55:07 -04001351 if (dev->ram_base)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 np->ram_ba = (u32)dev->ram_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001354 if (sym_hcb_attach(shost, fw, dev->nvram))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 goto attach_failed;
1356
1357 /*
1358 * Install the interrupt handler.
1359 * If we synchonize the C code with SCRIPTS on interrupt,
1360 * we do not want to share the INTR line at all.
1361 */
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001362 if (request_irq(pdev->irq, sym53c8xx_intr, IRQF_SHARED, NAME53C8XX,
1363 shost)) {
Matthew Wilcox8022fbd2007-10-05 15:55:11 -04001364 printf_err("%s: request irq %u failure\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 sym_name(np), pdev->irq);
1366 goto attach_failed;
1367 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368
1369 /*
1370 * After SCSI devices have been opened, we cannot
1371 * reset the bus safely, so we do it here.
1372 */
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001373 spin_lock_irqsave(shost->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 if (sym_reset_scsi_bus(np, 0))
1375 goto reset_failed;
1376
1377 /*
1378 * Start the SCRIPTS.
1379 */
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001380 sym_start_up(shost, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381
1382 /*
1383 * Start the timer daemon
1384 */
1385 init_timer(&np->s.timer);
1386 np->s.timer.data = (unsigned long) np;
1387 np->s.timer.function = sym53c8xx_timer;
1388 np->s.lasttime=0;
1389 sym_timer (np);
1390
1391 /*
1392 * Fill Linux host instance structure
1393 * and return success.
1394 */
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001395 shost->max_channel = 0;
1396 shost->this_id = np->myaddr;
1397 shost->max_id = np->maxwide ? 16 : 8;
1398 shost->max_lun = SYM_CONF_MAX_LUN;
1399 shost->unique_id = pci_resource_start(pdev, 0);
1400 shost->cmd_per_lun = SYM_CONF_MAX_TAG;
1401 shost->can_queue = (SYM_CONF_MAX_START-2);
1402 shost->sg_tablesize = SYM_CONF_MAX_SG;
1403 shost->max_cmd_len = 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 BUG_ON(sym2_transport_template == NULL);
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001405 shost->transportt = sym2_transport_template;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406
Kai Makisara34996ac2007-10-05 15:54:58 -04001407 /* 53c896 rev 1 errata: DMA may not cross 16MB boundary */
Matthew Wilcoxbd678452007-10-05 15:55:05 -04001408 if (pdev->device == PCI_DEVICE_ID_NCR_53C896 && pdev->revision < 2)
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001409 shost->dma_boundary = 0xFFFFFF;
Kai Makisara34996ac2007-10-05 15:54:58 -04001410
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001411 spin_unlock_irqrestore(shost->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001413 return shost;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
1415 reset_failed:
1416 printf_err("%s: FATAL ERROR: CHECK SCSI BUS - CABLES, "
1417 "TERMINATION, DEVICE POWER etc.!\n", sym_name(np));
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001418 spin_unlock_irqrestore(shost->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 attach_failed:
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001420 if (!shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 return NULL;
1422 printf_info("%s: giving up ...\n", sym_name(np));
1423 if (np)
1424 sym_free_resources(np, pdev);
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001425 scsi_host_put(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426
1427 return NULL;
1428 }
1429
1430
1431/*
1432 * Detect and try to read SYMBIOS and TEKRAM NVRAM.
1433 */
1434#if SYM_CONF_NVRAM_SUPPORT
1435static void __devinit sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
1436{
1437 devp->nvram = nvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 nvp->type = 0;
1439
1440 sym_read_nvram(devp, nvp);
1441}
1442#else
1443static inline void sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
1444{
1445}
1446#endif /* SYM_CONF_NVRAM_SUPPORT */
1447
1448static int __devinit sym_check_supported(struct sym_device *device)
1449{
1450 struct sym_chip *chip;
1451 struct pci_dev *pdev = device->pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 unsigned long io_port = pci_resource_start(pdev, 0);
1453 int i;
1454
1455 /*
1456 * If user excluded this chip, do not initialize it.
1457 * I hate this code so much. Must kill it.
1458 */
1459 if (io_port) {
1460 for (i = 0 ; i < 8 ; i++) {
1461 if (sym_driver_setup.excludes[i] == io_port)
1462 return -ENODEV;
1463 }
1464 }
1465
1466 /*
1467 * Check if the chip is supported. Then copy the chip description
1468 * to our device structure so we can make it match the actual device
1469 * and options.
1470 */
Matthew Wilcoxbd678452007-10-05 15:55:05 -04001471 chip = sym_lookup_chip_table(pdev->device, pdev->revision);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 if (!chip) {
1473 dev_info(&pdev->dev, "device not supported\n");
1474 return -ENODEV;
1475 }
1476 memcpy(&device->chip, chip, sizeof(device->chip));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
1478 return 0;
1479}
1480
1481/*
1482 * Ignore Symbios chips controlled by various RAID controllers.
1483 * These controllers set value 0x52414944 at RAM end - 16.
1484 */
1485static int __devinit sym_check_raid(struct sym_device *device)
1486{
1487 unsigned int ram_size, ram_val;
1488
1489 if (!device->s.ramaddr)
1490 return 0;
1491
1492 if (device->chip.features & FE_RAM8K)
1493 ram_size = 8192;
1494 else
1495 ram_size = 4096;
1496
1497 ram_val = readl(device->s.ramaddr + ram_size - 16);
1498 if (ram_val != 0x52414944)
1499 return 0;
1500
1501 dev_info(&device->pdev->dev,
1502 "not initializing, driven by RAID controller.\n");
1503 return -ENODEV;
1504}
1505
1506static int __devinit sym_set_workarounds(struct sym_device *device)
1507{
1508 struct sym_chip *chip = &device->chip;
1509 struct pci_dev *pdev = device->pdev;
1510 u_short status_reg;
1511
1512 /*
1513 * (ITEM 12 of a DEL about the 896 I haven't yet).
1514 * We must ensure the chip will use WRITE AND INVALIDATE.
1515 * The revision number limit is for now arbitrary.
1516 */
Matthew Wilcoxbd678452007-10-05 15:55:05 -04001517 if (pdev->device == PCI_DEVICE_ID_NCR_53C896 && pdev->revision < 0x4) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 chip->features |= (FE_WRIE | FE_CLSE);
1519 }
1520
1521 /* If the chip can do Memory Write Invalidate, enable it */
1522 if (chip->features & FE_WRIE) {
1523 if (pci_set_mwi(pdev))
1524 return -ENODEV;
1525 }
1526
1527 /*
1528 * Work around for errant bit in 895A. The 66Mhz
1529 * capable bit is set erroneously. Clear this bit.
1530 * (Item 1 DEL 533)
1531 *
1532 * Make sure Config space and Features agree.
1533 *
1534 * Recall: writes are not normal to status register -
1535 * write a 1 to clear and a 0 to leave unchanged.
1536 * Can only reset bits.
1537 */
1538 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1539 if (chip->features & FE_66MHZ) {
1540 if (!(status_reg & PCI_STATUS_66MHZ))
1541 chip->features &= ~FE_66MHZ;
1542 } else {
1543 if (status_reg & PCI_STATUS_66MHZ) {
1544 status_reg = PCI_STATUS_66MHZ;
1545 pci_write_config_word(pdev, PCI_STATUS, status_reg);
1546 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1547 }
1548 }
1549
1550 return 0;
1551}
1552
1553/*
1554 * Read and check the PCI configuration for any detected NCR
1555 * boards and save data for attaching after all boards have
1556 * been detected.
1557 */
1558static void __devinit
1559sym_init_device(struct pci_dev *pdev, struct sym_device *device)
1560{
Matthew Wilcoxb6d105d2006-03-28 11:03:44 -05001561 int i = 2;
1562 struct pci_bus_region bus_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
1564 device->host_id = SYM_SETUP_HOST_ID;
1565 device->pdev = pdev;
1566
Matthew Wilcoxb6d105d2006-03-28 11:03:44 -05001567 pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[1]);
1568 device->mmio_base = bus_addr.start;
1569
1570 /*
1571 * If the BAR is 64-bit, resource 2 will be occupied by the
1572 * upper 32 bits
1573 */
1574 if (!pdev->resource[i].flags)
1575 i++;
1576 pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[i]);
1577 device->ram_base = bus_addr.start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
Matthew Wilcox1f61d822006-03-28 11:03:43 -05001579#ifdef CONFIG_SCSI_SYM53C8XX_MMIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 if (device->mmio_base)
1581 device->s.ioaddr = pci_iomap(pdev, 1,
1582 pci_resource_len(pdev, 1));
1583#endif
1584 if (!device->s.ioaddr)
1585 device->s.ioaddr = pci_iomap(pdev, 0,
1586 pci_resource_len(pdev, 0));
1587 if (device->ram_base)
1588 device->s.ramaddr = pci_iomap(pdev, i,
1589 pci_resource_len(pdev, i));
1590}
1591
1592/*
1593 * The NCR PQS and PDS cards are constructed as a DEC bridge
1594 * behind which sits a proprietary NCR memory controller and
1595 * either four or two 53c875s as separate devices. We can tell
1596 * if an 875 is part of a PQS/PDS or not since if it is, it will
1597 * be on the same bus as the memory controller. In its usual
1598 * mode of operation, the 875s are slaved to the memory
1599 * controller for all transfers. To operate with the Linux
1600 * driver, the memory controller is disabled and the 875s
1601 * freed to function independently. The only wrinkle is that
1602 * the preset SCSI ID (which may be zero) must be read in from
1603 * a special configuration space register of the 875.
1604 */
1605static void sym_config_pqs(struct pci_dev *pdev, struct sym_device *sym_dev)
1606{
1607 int slot;
1608 u8 tmp;
1609
1610 for (slot = 0; slot < 256; slot++) {
1611 struct pci_dev *memc = pci_get_slot(pdev->bus, slot);
1612
1613 if (!memc || memc->vendor != 0x101a || memc->device == 0x0009) {
1614 pci_dev_put(memc);
1615 continue;
1616 }
1617
1618 /* bit 1: allow individual 875 configuration */
1619 pci_read_config_byte(memc, 0x44, &tmp);
1620 if ((tmp & 0x2) == 0) {
1621 tmp |= 0x2;
1622 pci_write_config_byte(memc, 0x44, tmp);
1623 }
1624
1625 /* bit 2: drive individual 875 interrupts to the bus */
1626 pci_read_config_byte(memc, 0x45, &tmp);
1627 if ((tmp & 0x4) == 0) {
1628 tmp |= 0x4;
1629 pci_write_config_byte(memc, 0x45, tmp);
1630 }
1631
1632 pci_dev_put(memc);
1633 break;
1634 }
1635
1636 pci_read_config_byte(pdev, 0x84, &tmp);
1637 sym_dev->host_id = tmp;
1638}
1639
1640/*
1641 * Called before unloading the module.
1642 * Detach the host.
1643 * We have to free resources and halt the NCR chip.
1644 */
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001645static int sym_detach(struct Scsi_Host *shost, struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646{
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001647 struct sym_hcb *np = sym_get_hcb(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 printk("%s: detaching ...\n", sym_name(np));
1649
1650 del_timer_sync(&np->s.timer);
1651
1652 /*
1653 * Reset NCR chip.
1654 * We should use sym_soft_reset(), but we don't want to do
1655 * so, since we may not be safe if interrupts occur.
1656 */
1657 printk("%s: resetting chip\n", sym_name(np));
1658 OUTB(np, nc_istat, SRST);
Matthew Wilcox 53222b92005-05-20 19:15:43 +01001659 INB(np, nc_mbox1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 udelay(10);
1661 OUTB(np, nc_istat, 0);
1662
1663 sym_free_resources(np, pdev);
1664
1665 return 1;
1666}
1667
1668/*
1669 * Driver host template.
1670 */
1671static struct scsi_host_template sym2_template = {
1672 .module = THIS_MODULE,
1673 .name = "sym53c8xx",
1674 .info = sym53c8xx_info,
1675 .queuecommand = sym53c8xx_queue_command,
1676 .slave_alloc = sym53c8xx_slave_alloc,
1677 .slave_configure = sym53c8xx_slave_configure,
Matthew Wilcox84e203a2005-11-29 23:08:31 -05001678 .slave_destroy = sym53c8xx_slave_destroy,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 .eh_abort_handler = sym53c8xx_eh_abort_handler,
1680 .eh_device_reset_handler = sym53c8xx_eh_device_reset_handler,
1681 .eh_bus_reset_handler = sym53c8xx_eh_bus_reset_handler,
1682 .eh_host_reset_handler = sym53c8xx_eh_host_reset_handler,
1683 .this_id = 7,
Matthew Wilcox14ac8bf2006-03-28 11:03:44 -05001684 .use_clustering = ENABLE_CLUSTERING,
FUJITA Tomonori9cb83c72007-10-16 11:24:32 +02001685 .use_sg_chaining = ENABLE_SG_CHAINING,
Matthew Wilcox14ac8bf2006-03-28 11:03:44 -05001686 .max_sectors = 0xFFFF,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687#ifdef SYM_LINUX_PROC_INFO_SUPPORT
1688 .proc_info = sym53c8xx_proc_info,
1689 .proc_name = NAME53C8XX,
1690#endif
1691};
1692
1693static int attach_count;
1694
1695static int __devinit sym2_probe(struct pci_dev *pdev,
1696 const struct pci_device_id *ent)
1697{
1698 struct sym_device sym_dev;
1699 struct sym_nvram nvram;
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001700 struct Scsi_Host *shost;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701
1702 memset(&sym_dev, 0, sizeof(sym_dev));
1703 memset(&nvram, 0, sizeof(nvram));
1704
1705 if (pci_enable_device(pdev))
1706 goto leave;
1707
1708 pci_set_master(pdev);
1709
1710 if (pci_request_regions(pdev, NAME53C8XX))
1711 goto disable;
1712
1713 sym_init_device(pdev, &sym_dev);
1714 if (sym_check_supported(&sym_dev))
1715 goto free;
1716
1717 if (sym_check_raid(&sym_dev))
1718 goto leave; /* Don't disable the device */
1719
1720 if (sym_set_workarounds(&sym_dev))
1721 goto free;
1722
1723 sym_config_pqs(pdev, &sym_dev);
1724
1725 sym_get_nvram(&sym_dev, &nvram);
1726
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001727 shost = sym_attach(&sym2_template, attach_count, &sym_dev);
1728 if (!shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 goto free;
1730
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001731 if (scsi_add_host(shost, &pdev->dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 goto detach;
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001733 scsi_scan_host(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
1735 attach_count++;
1736
1737 return 0;
1738
1739 detach:
1740 sym_detach(pci_get_drvdata(pdev), pdev);
1741 free:
1742 pci_release_regions(pdev);
1743 disable:
1744 pci_disable_device(pdev);
1745 leave:
1746 return -ENODEV;
1747}
1748
Randy Dunlap864473b2007-10-29 11:20:40 -07001749static void sym2_remove(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750{
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001751 struct Scsi_Host *shost = pci_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001753 scsi_remove_host(shost);
1754 scsi_host_put(shost);
1755 sym_detach(shost, pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 pci_release_regions(pdev);
1757 pci_disable_device(pdev);
1758
1759 attach_count--;
1760}
1761
Linas Vepstasd68cd752007-10-05 15:55:04 -04001762/**
1763 * sym2_io_error_detected() - called when PCI error is detected
1764 * @pdev: pointer to PCI device
1765 * @state: current state of the PCI slot
1766 */
1767static pci_ers_result_t sym2_io_error_detected(struct pci_dev *pdev,
1768 enum pci_channel_state state)
1769{
1770 /* If slot is permanently frozen, turn everything off */
1771 if (state == pci_channel_io_perm_failure) {
1772 sym2_remove(pdev);
1773 return PCI_ERS_RESULT_DISCONNECT;
1774 }
1775
1776 disable_irq(pdev->irq);
1777 pci_disable_device(pdev);
1778
1779 /* Request that MMIO be enabled, so register dump can be taken. */
1780 return PCI_ERS_RESULT_CAN_RECOVER;
1781}
1782
1783/**
1784 * sym2_io_slot_dump - Enable MMIO and dump debug registers
1785 * @pdev: pointer to PCI device
1786 */
1787static pci_ers_result_t sym2_io_slot_dump(struct pci_dev *pdev)
1788{
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001789 struct Scsi_Host *shost = pci_get_drvdata(pdev);
Linas Vepstasd68cd752007-10-05 15:55:04 -04001790
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001791 sym_dump_registers(shost);
Linas Vepstasd68cd752007-10-05 15:55:04 -04001792
1793 /* Request a slot reset. */
1794 return PCI_ERS_RESULT_NEED_RESET;
1795}
1796
1797/**
1798 * sym2_reset_workarounds - hardware-specific work-arounds
1799 *
1800 * This routine is similar to sym_set_workarounds(), except
1801 * that, at this point, we already know that the device was
1802 * succesfully intialized at least once before, and so most
1803 * of the steps taken there are un-needed here.
1804 */
1805static void sym2_reset_workarounds(struct pci_dev *pdev)
1806{
Linas Vepstasd68cd752007-10-05 15:55:04 -04001807 u_short status_reg;
1808 struct sym_chip *chip;
1809
Matthew Wilcoxbd678452007-10-05 15:55:05 -04001810 chip = sym_lookup_chip_table(pdev->device, pdev->revision);
Linas Vepstasd68cd752007-10-05 15:55:04 -04001811
1812 /* Work around for errant bit in 895A, in a fashion
1813 * similar to what is done in sym_set_workarounds().
1814 */
1815 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1816 if (!(chip->features & FE_66MHZ) && (status_reg & PCI_STATUS_66MHZ)) {
1817 status_reg = PCI_STATUS_66MHZ;
1818 pci_write_config_word(pdev, PCI_STATUS, status_reg);
1819 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1820 }
1821}
1822
1823/**
1824 * sym2_io_slot_reset() - called when the pci bus has been reset.
1825 * @pdev: pointer to PCI device
1826 *
1827 * Restart the card from scratch.
1828 */
1829static pci_ers_result_t sym2_io_slot_reset(struct pci_dev *pdev)
1830{
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001831 struct Scsi_Host *shost = pci_get_drvdata(pdev);
1832 struct sym_hcb *np = sym_get_hcb(shost);
Linas Vepstasd68cd752007-10-05 15:55:04 -04001833
1834 printk(KERN_INFO "%s: recovering from a PCI slot reset\n",
1835 sym_name(np));
1836
1837 if (pci_enable_device(pdev)) {
1838 printk(KERN_ERR "%s: Unable to enable after PCI reset\n",
1839 sym_name(np));
1840 return PCI_ERS_RESULT_DISCONNECT;
1841 }
1842
1843 pci_set_master(pdev);
1844 enable_irq(pdev->irq);
1845
1846 /* If the chip can do Memory Write Invalidate, enable it */
1847 if (np->features & FE_WRIE) {
1848 if (pci_set_mwi(pdev))
1849 return PCI_ERS_RESULT_DISCONNECT;
1850 }
1851
1852 /* Perform work-arounds, analogous to sym_set_workarounds() */
1853 sym2_reset_workarounds(pdev);
1854
1855 /* Perform host reset only on one instance of the card */
1856 if (PCI_FUNC(pdev->devfn) == 0) {
1857 if (sym_reset_scsi_bus(np, 0)) {
1858 printk(KERN_ERR "%s: Unable to reset scsi host\n",
1859 sym_name(np));
1860 return PCI_ERS_RESULT_DISCONNECT;
1861 }
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001862 sym_start_up(shost, 1);
Linas Vepstasd68cd752007-10-05 15:55:04 -04001863 }
1864
1865 return PCI_ERS_RESULT_RECOVERED;
1866}
1867
1868/**
1869 * sym2_io_resume() - resume normal ops after PCI reset
1870 * @pdev: pointer to PCI device
1871 *
1872 * Called when the error recovery driver tells us that its
1873 * OK to resume normal operation. Use completion to allow
1874 * halted scsi ops to resume.
1875 */
1876static void sym2_io_resume(struct pci_dev *pdev)
1877{
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001878 struct Scsi_Host *shost = pci_get_drvdata(pdev);
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001879 struct sym_data *sym_data = shost_priv(shost);
Linas Vepstasd68cd752007-10-05 15:55:04 -04001880
1881 spin_lock_irq(shost->host_lock);
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001882 if (sym_data->io_reset)
1883 complete_all(sym_data->io_reset);
Linas Vepstasd68cd752007-10-05 15:55:04 -04001884 spin_unlock_irq(shost->host_lock);
1885}
1886
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887static void sym2_get_signalling(struct Scsi_Host *shost)
1888{
1889 struct sym_hcb *np = sym_get_hcb(shost);
1890 enum spi_signal_type type;
1891
1892 switch (np->scsi_mode) {
1893 case SMODE_SE:
1894 type = SPI_SIGNAL_SE;
1895 break;
1896 case SMODE_LVD:
1897 type = SPI_SIGNAL_LVD;
1898 break;
1899 case SMODE_HVD:
1900 type = SPI_SIGNAL_HVD;
1901 break;
1902 default:
1903 type = SPI_SIGNAL_UNKNOWN;
1904 break;
1905 }
1906 spi_signalling(shost) = type;
1907}
1908
1909static void sym2_set_offset(struct scsi_target *starget, int offset)
1910{
1911 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1912 struct sym_hcb *np = sym_get_hcb(shost);
1913 struct sym_tcb *tp = &np->target[starget->id];
1914
1915 tp->tgoal.offset = offset;
1916 tp->tgoal.check_nego = 1;
1917}
1918
1919static void sym2_set_period(struct scsi_target *starget, int period)
1920{
1921 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1922 struct sym_hcb *np = sym_get_hcb(shost);
1923 struct sym_tcb *tp = &np->target[starget->id];
1924
James Bottomleye4862fe2005-05-06 13:14:48 -05001925 /* have to have DT for these transfers, but DT will also
1926 * set width, so check that this is allowed */
1927 if (period <= np->minsync && spi_width(starget))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 tp->tgoal.dt = 1;
1929
1930 tp->tgoal.period = period;
1931 tp->tgoal.check_nego = 1;
1932}
1933
1934static void sym2_set_width(struct scsi_target *starget, int width)
1935{
1936 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1937 struct sym_hcb *np = sym_get_hcb(shost);
1938 struct sym_tcb *tp = &np->target[starget->id];
1939
1940 /* It is illegal to have DT set on narrow transfers. If DT is
1941 * clear, we must also clear IU and QAS. */
1942 if (width == 0)
1943 tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
1944
1945 tp->tgoal.width = width;
1946 tp->tgoal.check_nego = 1;
1947}
1948
1949static void sym2_set_dt(struct scsi_target *starget, int dt)
1950{
1951 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1952 struct sym_hcb *np = sym_get_hcb(shost);
1953 struct sym_tcb *tp = &np->target[starget->id];
1954
1955 /* We must clear QAS and IU if DT is clear */
1956 if (dt)
1957 tp->tgoal.dt = 1;
1958 else
1959 tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
1960 tp->tgoal.check_nego = 1;
1961}
1962
Matthew Wilcox8b2f8132005-11-29 23:08:38 -05001963#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964static void sym2_set_iu(struct scsi_target *starget, int iu)
1965{
1966 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1967 struct sym_hcb *np = sym_get_hcb(shost);
1968 struct sym_tcb *tp = &np->target[starget->id];
1969
1970 if (iu)
1971 tp->tgoal.iu = tp->tgoal.dt = 1;
1972 else
1973 tp->tgoal.iu = 0;
1974 tp->tgoal.check_nego = 1;
1975}
1976
1977static void sym2_set_qas(struct scsi_target *starget, int qas)
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 if (qas)
1984 tp->tgoal.dt = tp->tgoal.qas = 1;
1985 else
1986 tp->tgoal.qas = 0;
1987 tp->tgoal.check_nego = 1;
1988}
Matthew Wilcox8b2f8132005-11-29 23:08:38 -05001989#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990
1991static struct spi_function_template sym2_transport_functions = {
1992 .set_offset = sym2_set_offset,
1993 .show_offset = 1,
1994 .set_period = sym2_set_period,
1995 .show_period = 1,
1996 .set_width = sym2_set_width,
1997 .show_width = 1,
1998 .set_dt = sym2_set_dt,
1999 .show_dt = 1,
Matthew Wilcox8b2f8132005-11-29 23:08:38 -05002000#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 .set_iu = sym2_set_iu,
2002 .show_iu = 1,
2003 .set_qas = sym2_set_qas,
2004 .show_qas = 1,
Matthew Wilcox8b2f8132005-11-29 23:08:38 -05002005#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 .get_signalling = sym2_get_signalling,
2007};
2008
2009static struct pci_device_id sym2_id_table[] __devinitdata = {
2010 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C810,
2011 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2012 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C820,
2013 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
2014 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C825,
2015 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2016 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C815,
2017 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2018 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C810AP,
2019 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
2020 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C860,
2021 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2022 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1510,
Grant Grundlerb2b3c122006-07-17 07:22:45 -06002023 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SCSI<<8, 0xffff00, 0UL },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C896,
2025 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2026 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C895,
2027 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2028 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C885,
2029 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2030 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875,
2031 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2032 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C1510,
Chip Coldwell147e5052007-05-23 14:41:38 -07002033 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SCSI<<8, 0xffff00, 0UL }, /* new */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C895A,
2035 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2036 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C875A,
2037 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2038 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_33,
2039 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2040 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_66,
2041 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2042 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875J,
2043 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2044 { 0, }
2045};
2046
2047MODULE_DEVICE_TABLE(pci, sym2_id_table);
2048
Linas Vepstasd68cd752007-10-05 15:55:04 -04002049static struct pci_error_handlers sym2_err_handler = {
2050 .error_detected = sym2_io_error_detected,
2051 .mmio_enabled = sym2_io_slot_dump,
2052 .slot_reset = sym2_io_slot_reset,
2053 .resume = sym2_io_resume,
2054};
2055
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056static struct pci_driver sym2_driver = {
2057 .name = NAME53C8XX,
2058 .id_table = sym2_id_table,
2059 .probe = sym2_probe,
Randy Dunlap864473b2007-10-29 11:20:40 -07002060 .remove = sym2_remove,
Linas Vepstasd68cd752007-10-05 15:55:04 -04002061 .err_handler = &sym2_err_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062};
2063
2064static int __init sym2_init(void)
2065{
2066 int error;
2067
2068 sym2_setup_params();
2069 sym2_transport_template = spi_attach_transport(&sym2_transport_functions);
2070 if (!sym2_transport_template)
2071 return -ENODEV;
2072
2073 error = pci_register_driver(&sym2_driver);
2074 if (error)
2075 spi_release_transport(sym2_transport_template);
2076 return error;
2077}
2078
2079static void __exit sym2_exit(void)
2080{
2081 pci_unregister_driver(&sym2_driver);
2082 spi_release_transport(sym2_transport_template);
2083}
2084
2085module_init(sym2_init);
2086module_exit(sym2_exit);