blob: 23e782015880173a47684b166bff6196ea864963 [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 */
Nathan Lynchde15c202008-01-26 16:07:30 -0600210 memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 memcpy(cmd->sense_buffer, cp->sns_bbuf,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +0900212 min(SCSI_SENSE_BUFFERSIZE, SYM_SNS_BBUF_LEN));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213#if 0
214 /*
215 * If the device reports a UNIT ATTENTION condition
216 * due to a RESET condition, we should consider all
217 * disconnect CCBs for this unit as aborted.
218 */
219 if (1) {
220 u_char *p;
221 p = (u_char *) cmd->sense_data;
222 if (p[0]==0x70 && p[2]==0x6 && p[12]==0x29)
223 sym_clear_tasks(np, DID_ABORT,
224 cp->target,cp->lun, -1);
225 }
226#endif
227 } else {
228 /*
229 * Error return from our internal request sense. This
230 * is bad: we must clear the contingent allegiance
231 * condition otherwise the device will always return
232 * BUSY. Use a big stick.
233 */
234 sym_reset_scsi_target(np, cmd->device->id);
235 cam_status = DID_ERROR;
236 }
237 } else if (cp->host_status == HS_COMPLETE) /* Bad SCSI status */
238 cam_status = DID_OK;
239 else if (cp->host_status == HS_SEL_TIMEOUT) /* Selection timeout */
240 cam_status = DID_NO_CONNECT;
241 else if (cp->host_status == HS_UNEXPECTED) /* Unexpected BUS FREE*/
242 cam_status = DID_ERROR;
243 else { /* Extended error */
244 if (sym_verbose) {
245 sym_print_addr(cmd, "COMMAND FAILED (%x %x %x).\n",
246 cp->host_status, cp->ssss_status,
247 cp->xerr_status);
248 }
249 /*
250 * Set the most appropriate value for CAM status.
251 */
252 cam_status = sym_xerr_cam_status(DID_ERROR, cp->xerr_status);
253 }
FUJITA Tomonori938febd2007-05-26 02:31:17 +0900254 scsi_set_resid(cmd, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 cmd->result = (drv_status << 24) + (cam_status << 16) + scsi_status;
256}
257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258static int sym_scatter(struct sym_hcb *np, struct sym_ccb *cp, struct scsi_cmnd *cmd)
259{
260 int segment;
FUJITA Tomonori938febd2007-05-26 02:31:17 +0900261 int use_sg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
263 cp->data_len = 0;
264
Matthew Wilcox39c05d12007-10-05 15:55:00 -0400265 use_sg = scsi_dma_map(cmd);
FUJITA Tomonori938febd2007-05-26 02:31:17 +0900266 if (use_sg > 0) {
267 struct scatterlist *sg;
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100268 struct sym_tcb *tp = &np->target[cp->target];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 struct sym_tblmove *data;
270
271 if (use_sg > SYM_CONF_MAX_SG) {
Matthew Wilcox39c05d12007-10-05 15:55:00 -0400272 scsi_dma_unmap(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 return -1;
274 }
275
276 data = &cp->phys.data[SYM_CONF_MAX_SG - use_sg];
277
FUJITA Tomonori938febd2007-05-26 02:31:17 +0900278 scsi_for_each_sg(cmd, sg, use_sg, segment) {
279 dma_addr_t baddr = sg_dma_address(sg);
280 unsigned int len = sg_dma_len(sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100282 if ((len & 1) && (tp->head.wval & EWS)) {
283 len++;
284 cp->odd_byte_adjustment++;
285 }
286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 sym_build_sge(np, &data[segment], baddr, len);
288 cp->data_len += len;
289 }
290 } else {
291 segment = -2;
292 }
293
294 return segment;
295}
296
297/*
298 * Queue a SCSI command.
299 */
300static int sym_queue_command(struct sym_hcb *np, struct scsi_cmnd *cmd)
301{
302 struct scsi_device *sdev = cmd->device;
303 struct sym_tcb *tp;
304 struct sym_lcb *lp;
305 struct sym_ccb *cp;
306 int order;
307
308 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 * Retrieve the target descriptor.
310 */
311 tp = &np->target[sdev->id];
312
313 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 * Select tagged/untagged.
315 */
316 lp = sym_lp(tp, sdev->lun);
317 order = (lp && lp->s.reqtags) ? M_SIMPLE_TAG : 0;
318
319 /*
320 * Queue the SCSI IO.
321 */
322 cp = sym_get_ccb(np, cmd, order);
323 if (!cp)
324 return 1; /* Means resource shortage */
325 sym_queue_scsiio(np, cmd, cp);
326 return 0;
327}
328
329/*
330 * Setup buffers and pointers that address the CDB.
331 */
332static inline int sym_setup_cdb(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp)
333{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 memcpy(cp->cdb_buf, cmd->cmnd, cmd->cmd_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100336 cp->phys.cmd.addr = CCB_BA(cp, cdb_buf[0]);
337 cp->phys.cmd.size = cpu_to_scr(cmd->cmd_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339 return 0;
340}
341
342/*
343 * Setup pointers that address the data and start the I/O.
344 */
345int sym_setup_data_and_start(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp)
346{
Matthew Wilcox44f30b0f2005-11-29 23:08:33 -0500347 u32 lastp, goalp;
348 int dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
350 /*
351 * Build the CDB.
352 */
353 if (sym_setup_cdb(np, cmd, cp))
354 goto out_abort;
355
356 /*
357 * No direction means no data.
358 */
359 dir = cmd->sc_data_direction;
360 if (dir != DMA_NONE) {
361 cp->segments = sym_scatter(np, cp, cmd);
362 if (cp->segments < 0) {
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100363 sym_set_cam_status(cmd, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 goto out_abort;
365 }
Matthew Wilcox44f30b0f2005-11-29 23:08:33 -0500366
367 /*
368 * No segments means no data.
369 */
370 if (!cp->segments)
371 dir = DMA_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 } else {
373 cp->data_len = 0;
374 cp->segments = 0;
375 }
376
377 /*
Matthew Wilcox44f30b0f2005-11-29 23:08:33 -0500378 * Set the data pointer.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 */
Matthew Wilcox44f30b0f2005-11-29 23:08:33 -0500380 switch (dir) {
381 case DMA_BIDIRECTIONAL:
Matthew Wilcox3fb364e2007-10-05 15:55:10 -0400382 scmd_printk(KERN_INFO, cmd, "got DMA_BIDIRECTIONAL command");
Matthew Wilcox44f30b0f2005-11-29 23:08:33 -0500383 sym_set_cam_status(cmd, DID_ERROR);
384 goto out_abort;
385 case DMA_TO_DEVICE:
386 goalp = SCRIPTA_BA(np, data_out2) + 8;
387 lastp = goalp - 8 - (cp->segments * (2*4));
388 break;
389 case DMA_FROM_DEVICE:
390 cp->host_flags |= HF_DATA_IN;
391 goalp = SCRIPTA_BA(np, data_in2) + 8;
392 lastp = goalp - 8 - (cp->segments * (2*4));
393 break;
394 case DMA_NONE:
395 default:
396 lastp = goalp = SCRIPTB_BA(np, no_data);
397 break;
398 }
399
400 /*
401 * Set all pointers values needed by SCRIPTS.
402 */
403 cp->phys.head.lastp = cpu_to_scr(lastp);
404 cp->phys.head.savep = cpu_to_scr(lastp);
405 cp->startp = cp->phys.head.savep;
406 cp->goalp = cpu_to_scr(goalp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
408 /*
409 * When `#ifed 1', the code below makes the driver
410 * panic on the first attempt to write to a SCSI device.
411 * It is the first test we want to do after a driver
412 * change that does not seem obviously safe. :)
413 */
414#if 0
415 switch (cp->cdb_buf[0]) {
416 case 0x0A: case 0x2A: case 0xAA:
417 panic("XXXXXXXXXXXXX WRITE NOT YET ALLOWED XXXXXXXXXXXXXX\n");
418 break;
419 default:
420 break;
421 }
422#endif
423
424 /*
425 * activate this job.
426 */
Matthew Wilcox3bea15a2006-03-28 11:03:44 -0500427 sym_put_start_queue(np, cp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 return 0;
429
430out_abort:
431 sym_free_ccb(np, cp);
432 sym_xpt_done(np, cmd);
433 return 0;
434}
435
436
437/*
438 * timer daemon.
439 *
440 * Misused to keep the driver running when
441 * interrupts are not configured correctly.
442 */
443static void sym_timer(struct sym_hcb *np)
444{
445 unsigned long thistime = jiffies;
446
447 /*
448 * Restart the timer.
449 */
450 np->s.timer.expires = thistime + SYM_CONF_TIMER_INTERVAL;
451 add_timer(&np->s.timer);
452
453 /*
454 * If we are resetting the ncr, wait for settle_time before
455 * clearing it. Then command processing will be resumed.
456 */
457 if (np->s.settle_time_valid) {
458 if (time_before_eq(np->s.settle_time, thistime)) {
459 if (sym_verbose >= 2 )
460 printk("%s: command processing resumed\n",
461 sym_name(np));
462 np->s.settle_time_valid = 0;
463 }
464 return;
465 }
466
467 /*
468 * Nothing to do for now, but that may come.
469 */
470 if (np->s.lasttime + 4*HZ < thistime) {
471 np->s.lasttime = thistime;
472 }
473
474#ifdef SYM_CONF_PCIQ_MAY_MISS_COMPLETIONS
475 /*
476 * Some way-broken PCI bridges may lead to
477 * completions being lost when the clearing
478 * of the INTFLY flag by the CPU occurs
479 * concurrently with the chip raising this flag.
480 * If this ever happen, lost completions will
481 * be reaped here.
482 */
483 sym_wakeup_done(np);
484#endif
485}
486
487
488/*
489 * PCI BUS error handler.
490 */
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400491void sym_log_bus_error(struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492{
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400493 struct sym_data *sym_data = shost_priv(shost);
494 struct pci_dev *pdev = sym_data->pdev;
495 unsigned short pci_sts;
496 pci_read_config_word(pdev, PCI_STATUS, &pci_sts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 if (pci_sts & 0xf900) {
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400498 pci_write_config_word(pdev, PCI_STATUS, pci_sts);
499 shost_printk(KERN_WARNING, shost,
500 "PCI bus error: status = 0x%04x\n", pci_sts & 0xf900);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 }
502}
503
504/*
505 * queuecommand method. Entered with the host adapter lock held and
506 * interrupts disabled.
507 */
508static int sym53c8xx_queue_command(struct scsi_cmnd *cmd,
509 void (*done)(struct scsi_cmnd *))
510{
511 struct sym_hcb *np = SYM_SOFTC_PTR(cmd);
512 struct sym_ucmd *ucp = SYM_UCMD_PTR(cmd);
513 int sts = 0;
514
Matthew Wilcox71c222d2007-10-05 15:55:01 -0400515 cmd->scsi_done = done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 memset(ucp, 0, sizeof(*ucp));
517
518 /*
519 * Shorten our settle_time if needed for
520 * this command not to time out.
521 */
Jens Axboe242f9dc2008-09-14 05:55:09 -0700522 if (np->s.settle_time_valid && cmd->request->timeout) {
523 unsigned long tlimit = jiffies + cmd->request->timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 tlimit -= SYM_CONF_TIMER_INTERVAL*2;
525 if (time_after(np->s.settle_time, tlimit)) {
526 np->s.settle_time = tlimit;
527 }
528 }
529
530 if (np->s.settle_time_valid)
531 return SCSI_MLQUEUE_HOST_BUSY;
532
533 sts = sym_queue_command(np, cmd);
534 if (sts)
535 return SCSI_MLQUEUE_HOST_BUSY;
536 return 0;
537}
538
539/*
540 * Linux entry point of the interrupt handler.
541 */
David Howells7d12e782006-10-05 14:55:46 +0100542static irqreturn_t sym53c8xx_intr(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543{
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -0400544 struct Scsi_Host *shost = dev_id;
545 struct sym_data *sym_data = shost_priv(shost);
546 irqreturn_t result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Linas Vepstasd68cd752007-10-05 15:55:04 -0400548 /* Avoid spinloop trying to handle interrupts on frozen device */
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -0400549 if (pci_channel_offline(sym_data->pdev))
Linas Vepstasd68cd752007-10-05 15:55:04 -0400550 return IRQ_NONE;
551
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("[");
553
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -0400554 spin_lock(shost->host_lock);
555 result = sym_interrupt(shost);
556 spin_unlock(shost->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
558 if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("]\n");
559
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -0400560 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561}
562
563/*
564 * Linux entry point of the timer handler
565 */
566static void sym53c8xx_timer(unsigned long npref)
567{
568 struct sym_hcb *np = (struct sym_hcb *)npref;
569 unsigned long flags;
570
571 spin_lock_irqsave(np->s.host->host_lock, flags);
572 sym_timer(np);
573 spin_unlock_irqrestore(np->s.host->host_lock, flags);
574}
575
576
577/*
578 * What the eh thread wants us to perform.
579 */
580#define SYM_EH_ABORT 0
581#define SYM_EH_DEVICE_RESET 1
582#define SYM_EH_BUS_RESET 2
583#define SYM_EH_HOST_RESET 3
584
585/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 * Generic method for our eh processing.
587 * The 'op' argument tells what we have to do.
588 */
589static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd)
590{
Matthew Wilcoxb4e93a72006-03-28 11:03:44 -0500591 struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400592 struct Scsi_Host *shost = cmd->device->host;
593 struct sym_data *sym_data = shost_priv(shost);
594 struct pci_dev *pdev = sym_data->pdev;
595 struct sym_hcb *np = sym_data->ncb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 SYM_QUEHEAD *qp;
Matthew Wilcox2ba65362007-10-05 15:55:03 -0400597 int cmd_queued = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 int sts = -1;
Matthew Wilcoxd637c452006-03-29 14:45:18 -0700599 struct completion eh_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400601 scmd_printk(KERN_WARNING, cmd, "%s operation started\n", opname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Linas Vepstasd68cd752007-10-05 15:55:04 -0400603 /* We may be in an error condition because the PCI bus
604 * went down. In this case, we need to wait until the
605 * PCI bus is reset, the card is reset, and only then
606 * proceed with the scsi error recovery. There's no
607 * point in hurrying; take a leisurely wait.
608 */
609#define WAIT_FOR_PCI_RECOVERY 35
610 if (pci_channel_offline(pdev)) {
Linas Vepstasd68cd752007-10-05 15:55:04 -0400611 int finished_reset = 0;
612 init_completion(&eh_done);
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400613 spin_lock_irq(shost->host_lock);
Linas Vepstasd68cd752007-10-05 15:55:04 -0400614 /* Make sure we didn't race */
615 if (pci_channel_offline(pdev)) {
Krzysztof Heltd9aa3af2008-01-11 21:50:46 +0100616 BUG_ON(sym_data->io_reset);
617 sym_data->io_reset = &eh_done;
Linas Vepstasd68cd752007-10-05 15:55:04 -0400618 } else {
Linas Vepstasd68cd752007-10-05 15:55:04 -0400619 finished_reset = 1;
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -0400620 }
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400621 spin_unlock_irq(shost->host_lock);
Linas Vepstasd68cd752007-10-05 15:55:04 -0400622 if (!finished_reset)
Krzysztof Heltd9aa3af2008-01-11 21:50:46 +0100623 finished_reset = wait_for_completion_timeout
624 (sym_data->io_reset,
Linas Vepstasd68cd752007-10-05 15:55:04 -0400625 WAIT_FOR_PCI_RECOVERY*HZ);
Krzysztof Heltd9aa3af2008-01-11 21:50:46 +0100626 spin_lock_irq(shost->host_lock);
627 sym_data->io_reset = NULL;
628 spin_unlock_irq(shost->host_lock);
Linas Vepstasd68cd752007-10-05 15:55:04 -0400629 if (!finished_reset)
630 return SCSI_FAILED;
631 }
632
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400633 spin_lock_irq(shost->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 /* This one is queued in some place -> to wait for completion */
635 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
636 struct sym_ccb *cp = sym_que_entry(qp, struct sym_ccb, link_ccbq);
637 if (cp->cmd == cmd) {
Matthew Wilcox2ba65362007-10-05 15:55:03 -0400638 cmd_queued = 1;
Matthew Wilcoxab19d522006-03-28 11:03:44 -0500639 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 }
641 }
642
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 /* Try to proceed the operation we have been asked for */
644 sts = -1;
645 switch(op) {
646 case SYM_EH_ABORT:
647 sts = sym_abort_scsiio(np, cmd, 1);
648 break;
649 case SYM_EH_DEVICE_RESET:
650 sts = sym_reset_scsi_target(np, cmd->device->id);
651 break;
652 case SYM_EH_BUS_RESET:
653 sym_reset_scsi_bus(np, 1);
654 sts = 0;
655 break;
656 case SYM_EH_HOST_RESET:
657 sym_reset_scsi_bus(np, 0);
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400658 sym_start_up(shost, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 sts = 0;
660 break;
661 default:
662 break;
663 }
664
665 /* On error, restore everything and cross fingers :) */
Matthew Wilcox2ba65362007-10-05 15:55:03 -0400666 if (sts)
667 cmd_queued = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
Matthew Wilcox2ba65362007-10-05 15:55:03 -0400669 if (cmd_queued) {
670 init_completion(&eh_done);
671 ucmd->eh_done = &eh_done;
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400672 spin_unlock_irq(shost->host_lock);
Matthew Wilcoxd637c452006-03-29 14:45:18 -0700673 if (!wait_for_completion_timeout(&eh_done, 5*HZ)) {
Matthew Wilcox2ba65362007-10-05 15:55:03 -0400674 ucmd->eh_done = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 sts = -2;
Matthew Wilcoxb4e93a72006-03-28 11:03:44 -0500676 }
Matthew Wilcox2ba65362007-10-05 15:55:03 -0400677 } else {
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400678 spin_unlock_irq(shost->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 }
Matthew Wilcox2ba65362007-10-05 15:55:03 -0400680
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 dev_warn(&cmd->device->sdev_gendev, "%s operation %s.\n", opname,
682 sts==0 ? "complete" :sts==-2 ? "timed-out" : "failed");
683 return sts ? SCSI_FAILED : SCSI_SUCCESS;
684}
685
686
687/*
688 * Error handlers called from the eh thread (one thread per HBA).
689 */
690static int sym53c8xx_eh_abort_handler(struct scsi_cmnd *cmd)
691{
Matthew Wilcoxab19d522006-03-28 11:03:44 -0500692 return sym_eh_handler(SYM_EH_ABORT, "ABORT", cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693}
694
695static int sym53c8xx_eh_device_reset_handler(struct scsi_cmnd *cmd)
696{
Matthew Wilcoxab19d522006-03-28 11:03:44 -0500697 return sym_eh_handler(SYM_EH_DEVICE_RESET, "DEVICE RESET", cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698}
699
700static int sym53c8xx_eh_bus_reset_handler(struct scsi_cmnd *cmd)
701{
Matthew Wilcoxab19d522006-03-28 11:03:44 -0500702 return sym_eh_handler(SYM_EH_BUS_RESET, "BUS RESET", cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703}
704
705static int sym53c8xx_eh_host_reset_handler(struct scsi_cmnd *cmd)
706{
Matthew Wilcoxab19d522006-03-28 11:03:44 -0500707 return sym_eh_handler(SYM_EH_HOST_RESET, "HOST RESET", cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708}
709
710/*
711 * Tune device queuing depth, according to various limits.
712 */
713static void sym_tune_dev_queuing(struct sym_tcb *tp, int lun, u_short reqtags)
714{
715 struct sym_lcb *lp = sym_lp(tp, lun);
716 u_short oldtags;
717
718 if (!lp)
719 return;
720
721 oldtags = lp->s.reqtags;
722
723 if (reqtags > lp->s.scdev_depth)
724 reqtags = lp->s.scdev_depth;
725
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 lp->s.reqtags = reqtags;
727
728 if (reqtags != oldtags) {
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100729 dev_info(&tp->starget->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 "tagged command queuing %s, command queue depth %d.\n",
Matthew Wilcox3bea15a2006-03-28 11:03:44 -0500731 lp->s.reqtags ? "enabled" : "disabled", reqtags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 }
733}
734
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100735static int sym53c8xx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736{
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500737 struct sym_hcb *np = sym_get_hcb(sdev->host);
738 struct sym_tcb *tp = &np->target[sdev->id];
739 struct sym_lcb *lp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100741 if (sdev->id >= SYM_CONF_MAX_TARGET || sdev->lun >= SYM_CONF_MAX_LUN)
742 return -ENXIO;
743
Matthew Wilcox66e8d1c2005-11-29 23:08:46 -0500744 tp->starget = sdev->sdev_target;
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100745 /*
746 * Fail the device init if the device is flagged NOSCAN at BOOT in
747 * the NVRAM. This may speed up boot and maintain coherency with
748 * BIOS device numbering. Clearing the flag allows the user to
749 * rescan skipped devices later. We also return an error for
750 * devices not flagged for SCAN LUNS in the NVRAM since some single
751 * lun devices behave badly when asked for a non zero LUN.
752 */
753
Matthew Wilcox66e8d1c2005-11-29 23:08:46 -0500754 if (tp->usrflags & SYM_SCAN_BOOT_DISABLED) {
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100755 tp->usrflags &= ~SYM_SCAN_BOOT_DISABLED;
Matthew Wilcox66e8d1c2005-11-29 23:08:46 -0500756 starget_printk(KERN_INFO, tp->starget,
757 "Scan at boot disabled in NVRAM\n");
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100758 return -ENXIO;
759 }
760
Matthew Wilcox66e8d1c2005-11-29 23:08:46 -0500761 if (tp->usrflags & SYM_SCAN_LUNS_DISABLED) {
762 if (sdev->lun != 0)
763 return -ENXIO;
764 starget_printk(KERN_INFO, tp->starget,
765 "Multiple LUNs disabled in NVRAM\n");
766 }
767
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500768 lp = sym_alloc_lcb(np, sdev->id, sdev->lun);
769 if (!lp)
770 return -ENOMEM;
771
Matthew Wilcoxb37df482005-11-29 23:08:44 -0500772 spi_min_period(tp->starget) = tp->usr_period;
773 spi_max_width(tp->starget) = tp->usr_width;
774
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 return 0;
776}
777
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778/*
779 * Linux entry point for device queue sizing.
780 */
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500781static int sym53c8xx_slave_configure(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782{
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500783 struct sym_hcb *np = sym_get_hcb(sdev->host);
784 struct sym_tcb *tp = &np->target[sdev->id];
785 struct sym_lcb *lp = sym_lp(tp, sdev->lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 int reqtags, depth_to_use;
787
788 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 * Get user flags.
790 */
791 lp->curr_flags = lp->user_flags;
792
793 /*
794 * Select queue depth from driver setup.
Tony Battersbyc2fd2062009-01-08 12:58:04 -0500795 * Do not use more than configured by user.
796 * Use at least 1.
797 * Do not use more than our maximum.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 */
Matthew Wilcoxa44131b2007-10-05 15:55:08 -0400799 reqtags = sym_driver_setup.max_tag;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 if (reqtags > tp->usrtags)
801 reqtags = tp->usrtags;
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500802 if (!sdev->tagged_supported)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 reqtags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 if (reqtags > SYM_CONF_MAX_TAG)
805 reqtags = SYM_CONF_MAX_TAG;
Tony Battersbyc2fd2062009-01-08 12:58:04 -0500806 depth_to_use = reqtags ? reqtags : 1;
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500807 scsi_adjust_queue_depth(sdev,
Matthew Wilcoxa44131b2007-10-05 15:55:08 -0400808 sdev->tagged_supported ? MSG_SIMPLE_TAG : 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 depth_to_use);
810 lp->s.scdev_depth = depth_to_use;
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500811 sym_tune_dev_queuing(tp, sdev->lun, reqtags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500813 if (!spi_initial_dv(sdev->sdev_target))
814 spi_dv_device(sdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
816 return 0;
817}
818
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500819static void sym53c8xx_slave_destroy(struct scsi_device *sdev)
820{
821 struct sym_hcb *np = sym_get_hcb(sdev->host);
822 struct sym_lcb *lp = sym_lp(&np->target[sdev->id], sdev->lun);
823
824 if (lp->itlq_tbl)
825 sym_mfree_dma(lp->itlq_tbl, SYM_CONF_MAX_TASK * 4, "ITLQ_TBL");
826 kfree(lp->cb_tags);
827 sym_mfree_dma(lp, sizeof(*lp), "LCB");
828}
829
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830/*
831 * Linux entry point for info() function
832 */
833static const char *sym53c8xx_info (struct Scsi_Host *host)
834{
835 return SYM_DRIVER_NAME;
836}
837
838
839#ifdef SYM_LINUX_PROC_INFO_SUPPORT
840/*
841 * Proc file system stuff
842 *
843 * A read operation returns adapter information.
844 * A write operation is a control command.
845 * The string is parsed in the driver code and the command is passed
846 * to the sym_usercmd() function.
847 */
848
849#ifdef SYM_LINUX_USER_COMMAND_SUPPORT
850
851struct sym_usrcmd {
852 u_long target;
853 u_long lun;
854 u_long data;
855 u_long cmd;
856};
857
858#define UC_SETSYNC 10
859#define UC_SETTAGS 11
860#define UC_SETDEBUG 12
861#define UC_SETWIDE 14
862#define UC_SETFLAG 15
863#define UC_SETVERBOSE 17
864#define UC_RESETDEV 18
865#define UC_CLEARDEV 19
866
867static void sym_exec_user_command (struct sym_hcb *np, struct sym_usrcmd *uc)
868{
869 struct sym_tcb *tp;
870 int t, l;
871
872 switch (uc->cmd) {
873 case 0: return;
874
875#ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
876 case UC_SETDEBUG:
877 sym_debug_flags = uc->data;
878 break;
879#endif
880 case UC_SETVERBOSE:
881 np->verbose = uc->data;
882 break;
883 default:
884 /*
885 * We assume that other commands apply to targets.
886 * This should always be the case and avoid the below
887 * 4 lines to be repeated 6 times.
888 */
889 for (t = 0; t < SYM_CONF_MAX_TARGET; t++) {
890 if (!((uc->target >> t) & 1))
891 continue;
892 tp = &np->target[t];
893
894 switch (uc->cmd) {
895
896 case UC_SETSYNC:
897 if (!uc->data || uc->data >= 255) {
898 tp->tgoal.iu = tp->tgoal.dt =
899 tp->tgoal.qas = 0;
900 tp->tgoal.offset = 0;
901 } else if (uc->data <= 9 && np->minsync_dt) {
902 if (uc->data < np->minsync_dt)
903 uc->data = np->minsync_dt;
904 tp->tgoal.iu = tp->tgoal.dt =
905 tp->tgoal.qas = 1;
906 tp->tgoal.width = 1;
907 tp->tgoal.period = uc->data;
908 tp->tgoal.offset = np->maxoffs_dt;
909 } else {
910 if (uc->data < np->minsync)
911 uc->data = np->minsync;
912 tp->tgoal.iu = tp->tgoal.dt =
913 tp->tgoal.qas = 0;
914 tp->tgoal.period = uc->data;
915 tp->tgoal.offset = np->maxoffs;
916 }
917 tp->tgoal.check_nego = 1;
918 break;
919 case UC_SETWIDE:
920 tp->tgoal.width = uc->data ? 1 : 0;
921 tp->tgoal.check_nego = 1;
922 break;
923 case UC_SETTAGS:
924 for (l = 0; l < SYM_CONF_MAX_LUN; l++)
925 sym_tune_dev_queuing(tp, l, uc->data);
926 break;
927 case UC_RESETDEV:
928 tp->to_reset = 1;
929 np->istat_sem = SEM;
930 OUTB(np, nc_istat, SIGP|SEM);
931 break;
932 case UC_CLEARDEV:
933 for (l = 0; l < SYM_CONF_MAX_LUN; l++) {
934 struct sym_lcb *lp = sym_lp(tp, l);
935 if (lp) lp->to_clear = 1;
936 }
937 np->istat_sem = SEM;
938 OUTB(np, nc_istat, SIGP|SEM);
939 break;
940 case UC_SETFLAG:
941 tp->usrflags = uc->data;
942 break;
943 }
944 }
945 break;
946 }
947}
948
949static int skip_spaces(char *ptr, int len)
950{
951 int cnt, c;
952
953 for (cnt = len; cnt > 0 && (c = *ptr++) && isspace(c); cnt--);
954
955 return (len - cnt);
956}
957
958static int get_int_arg(char *ptr, int len, u_long *pv)
959{
960 char *end;
961
962 *pv = simple_strtoul(ptr, &end, 10);
963 return (end - ptr);
964}
965
966static int is_keyword(char *ptr, int len, char *verb)
967{
968 int verb_len = strlen(verb);
969
970 if (len >= verb_len && !memcmp(verb, ptr, verb_len))
971 return verb_len;
972 else
973 return 0;
974}
975
976#define SKIP_SPACES(ptr, len) \
977 if ((arg_len = skip_spaces(ptr, len)) < 1) \
978 return -EINVAL; \
979 ptr += arg_len; len -= arg_len;
980
981#define GET_INT_ARG(ptr, len, v) \
982 if (!(arg_len = get_int_arg(ptr, len, &(v)))) \
983 return -EINVAL; \
984 ptr += arg_len; len -= arg_len;
985
986
987/*
988 * Parse a control command
989 */
990
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400991static int sym_user_command(struct Scsi_Host *shost, char *buffer, int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992{
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400993 struct sym_hcb *np = sym_get_hcb(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 char *ptr = buffer;
995 int len = length;
996 struct sym_usrcmd cmd, *uc = &cmd;
997 int arg_len;
998 u_long target;
999
1000 memset(uc, 0, sizeof(*uc));
1001
1002 if (len > 0 && ptr[len-1] == '\n')
1003 --len;
1004
1005 if ((arg_len = is_keyword(ptr, len, "setsync")) != 0)
1006 uc->cmd = UC_SETSYNC;
1007 else if ((arg_len = is_keyword(ptr, len, "settags")) != 0)
1008 uc->cmd = UC_SETTAGS;
1009 else if ((arg_len = is_keyword(ptr, len, "setverbose")) != 0)
1010 uc->cmd = UC_SETVERBOSE;
1011 else if ((arg_len = is_keyword(ptr, len, "setwide")) != 0)
1012 uc->cmd = UC_SETWIDE;
1013#ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1014 else if ((arg_len = is_keyword(ptr, len, "setdebug")) != 0)
1015 uc->cmd = UC_SETDEBUG;
1016#endif
1017 else if ((arg_len = is_keyword(ptr, len, "setflag")) != 0)
1018 uc->cmd = UC_SETFLAG;
1019 else if ((arg_len = is_keyword(ptr, len, "resetdev")) != 0)
1020 uc->cmd = UC_RESETDEV;
1021 else if ((arg_len = is_keyword(ptr, len, "cleardev")) != 0)
1022 uc->cmd = UC_CLEARDEV;
1023 else
1024 arg_len = 0;
1025
1026#ifdef DEBUG_PROC_INFO
1027printk("sym_user_command: arg_len=%d, cmd=%ld\n", arg_len, uc->cmd);
1028#endif
1029
1030 if (!arg_len)
1031 return -EINVAL;
1032 ptr += arg_len; len -= arg_len;
1033
1034 switch(uc->cmd) {
1035 case UC_SETSYNC:
1036 case UC_SETTAGS:
1037 case UC_SETWIDE:
1038 case UC_SETFLAG:
1039 case UC_RESETDEV:
1040 case UC_CLEARDEV:
1041 SKIP_SPACES(ptr, len);
1042 if ((arg_len = is_keyword(ptr, len, "all")) != 0) {
1043 ptr += arg_len; len -= arg_len;
1044 uc->target = ~0;
1045 } else {
1046 GET_INT_ARG(ptr, len, target);
1047 uc->target = (1<<target);
1048#ifdef DEBUG_PROC_INFO
1049printk("sym_user_command: target=%ld\n", target);
1050#endif
1051 }
1052 break;
1053 }
1054
1055 switch(uc->cmd) {
1056 case UC_SETVERBOSE:
1057 case UC_SETSYNC:
1058 case UC_SETTAGS:
1059 case UC_SETWIDE:
1060 SKIP_SPACES(ptr, len);
1061 GET_INT_ARG(ptr, len, uc->data);
1062#ifdef DEBUG_PROC_INFO
1063printk("sym_user_command: data=%ld\n", uc->data);
1064#endif
1065 break;
1066#ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1067 case UC_SETDEBUG:
1068 while (len > 0) {
1069 SKIP_SPACES(ptr, len);
1070 if ((arg_len = is_keyword(ptr, len, "alloc")))
1071 uc->data |= DEBUG_ALLOC;
1072 else if ((arg_len = is_keyword(ptr, len, "phase")))
1073 uc->data |= DEBUG_PHASE;
1074 else if ((arg_len = is_keyword(ptr, len, "queue")))
1075 uc->data |= DEBUG_QUEUE;
1076 else if ((arg_len = is_keyword(ptr, len, "result")))
1077 uc->data |= DEBUG_RESULT;
1078 else if ((arg_len = is_keyword(ptr, len, "scatter")))
1079 uc->data |= DEBUG_SCATTER;
1080 else if ((arg_len = is_keyword(ptr, len, "script")))
1081 uc->data |= DEBUG_SCRIPT;
1082 else if ((arg_len = is_keyword(ptr, len, "tiny")))
1083 uc->data |= DEBUG_TINY;
1084 else if ((arg_len = is_keyword(ptr, len, "timing")))
1085 uc->data |= DEBUG_TIMING;
1086 else if ((arg_len = is_keyword(ptr, len, "nego")))
1087 uc->data |= DEBUG_NEGO;
1088 else if ((arg_len = is_keyword(ptr, len, "tags")))
1089 uc->data |= DEBUG_TAGS;
1090 else if ((arg_len = is_keyword(ptr, len, "pointer")))
1091 uc->data |= DEBUG_POINTER;
1092 else
1093 return -EINVAL;
1094 ptr += arg_len; len -= arg_len;
1095 }
1096#ifdef DEBUG_PROC_INFO
1097printk("sym_user_command: data=%ld\n", uc->data);
1098#endif
1099 break;
1100#endif /* SYM_LINUX_DEBUG_CONTROL_SUPPORT */
1101 case UC_SETFLAG:
1102 while (len > 0) {
1103 SKIP_SPACES(ptr, len);
1104 if ((arg_len = is_keyword(ptr, len, "no_disc")))
1105 uc->data &= ~SYM_DISC_ENABLED;
1106 else
1107 return -EINVAL;
1108 ptr += arg_len; len -= arg_len;
1109 }
1110 break;
1111 default:
1112 break;
1113 }
1114
1115 if (len)
1116 return -EINVAL;
1117 else {
1118 unsigned long flags;
1119
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001120 spin_lock_irqsave(shost->host_lock, flags);
1121 sym_exec_user_command(np, uc);
1122 spin_unlock_irqrestore(shost->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 }
1124 return length;
1125}
1126
1127#endif /* SYM_LINUX_USER_COMMAND_SUPPORT */
1128
1129
1130#ifdef SYM_LINUX_USER_INFO_SUPPORT
1131/*
1132 * Informations through the proc file system.
1133 */
1134struct info_str {
1135 char *buffer;
1136 int length;
1137 int offset;
1138 int pos;
1139};
1140
1141static void copy_mem_info(struct info_str *info, char *data, int len)
1142{
1143 if (info->pos + len > info->length)
1144 len = info->length - info->pos;
1145
1146 if (info->pos + len < info->offset) {
1147 info->pos += len;
1148 return;
1149 }
1150 if (info->pos < info->offset) {
1151 data += (info->offset - info->pos);
1152 len -= (info->offset - info->pos);
1153 }
1154
1155 if (len > 0) {
1156 memcpy(info->buffer + info->pos, data, len);
1157 info->pos += len;
1158 }
1159}
1160
1161static int copy_info(struct info_str *info, char *fmt, ...)
1162{
1163 va_list args;
1164 char buf[81];
1165 int len;
1166
1167 va_start(args, fmt);
1168 len = vsprintf(buf, fmt, args);
1169 va_end(args);
1170
1171 copy_mem_info(info, buf, len);
1172 return len;
1173}
1174
1175/*
1176 * Copy formatted information into the input buffer.
1177 */
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001178static int sym_host_info(struct Scsi_Host *shost, char *ptr, off_t offset, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179{
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001180 struct sym_data *sym_data = shost_priv(shost);
1181 struct pci_dev *pdev = sym_data->pdev;
1182 struct sym_hcb *np = sym_data->ncb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 struct info_str info;
1184
1185 info.buffer = ptr;
1186 info.length = len;
1187 info.offset = offset;
1188 info.pos = 0;
1189
1190 copy_info(&info, "Chip " NAME53C "%s, device id 0x%x, "
Matthew Wilcoxbd678452007-10-05 15:55:05 -04001191 "revision id 0x%x\n", np->s.chip_name,
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001192 pdev->device, pdev->revision);
Matthew Wilcox8022fbd2007-10-05 15:55:11 -04001193 copy_info(&info, "At PCI address %s, IRQ %u\n",
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001194 pci_name(pdev), pdev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 copy_info(&info, "Min. period factor %d, %s SCSI BUS%s\n",
1196 (int) (np->minsync_dt ? np->minsync_dt : np->minsync),
1197 np->maxwide ? "Wide" : "Narrow",
1198 np->minsync_dt ? ", DT capable" : "");
1199
1200 copy_info(&info, "Max. started commands %d, "
1201 "max. commands per LUN %d\n",
1202 SYM_CONF_MAX_START, SYM_CONF_MAX_TAG);
1203
1204 return info.pos > info.offset? info.pos - info.offset : 0;
1205}
1206#endif /* SYM_LINUX_USER_INFO_SUPPORT */
1207
1208/*
1209 * Entry point of the scsi proc fs of the driver.
1210 * - func = 0 means read (returns adapter infos)
1211 * - func = 1 means write (not yet merget from sym53c8xx)
1212 */
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001213static int sym53c8xx_proc_info(struct Scsi_Host *shost, char *buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 char **start, off_t offset, int length, int func)
1215{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 int retv;
1217
1218 if (func) {
1219#ifdef SYM_LINUX_USER_COMMAND_SUPPORT
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001220 retv = sym_user_command(shost, buffer, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221#else
1222 retv = -EINVAL;
1223#endif
1224 } else {
1225 if (start)
1226 *start = buffer;
1227#ifdef SYM_LINUX_USER_INFO_SUPPORT
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001228 retv = sym_host_info(shost, buffer, offset, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229#else
1230 retv = -EINVAL;
1231#endif
1232 }
1233
1234 return retv;
1235}
1236#endif /* SYM_LINUX_PROC_INFO_SUPPORT */
1237
1238/*
Tony Battersby783fa732009-01-08 12:56:58 -05001239 * Free resources claimed by sym_iomap_device(). Note that
Tony Battersbya71d0352009-01-08 12:55:52 -05001240 * sym_free_resources() should be used instead of this function after calling
1241 * sym_attach().
1242 */
1243static void __devinit
1244sym_iounmap_device(struct sym_device *device)
1245{
1246 if (device->s.ioaddr)
1247 pci_iounmap(device->pdev, device->s.ioaddr);
1248 if (device->s.ramaddr)
1249 pci_iounmap(device->pdev, device->s.ramaddr);
1250}
1251
1252/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 * Free controller resources.
1254 */
Tony Battersbyb4090632009-01-08 12:54:45 -05001255static void sym_free_resources(struct sym_hcb *np, struct pci_dev *pdev,
1256 int do_free_irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257{
1258 /*
1259 * Free O/S specific resources.
1260 */
Tony Battersbyb4090632009-01-08 12:54:45 -05001261 if (do_free_irq)
Tony Battersby7ee24132007-11-06 14:40:54 -05001262 free_irq(pdev->irq, np->s.host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 if (np->s.ioaddr)
1264 pci_iounmap(pdev, np->s.ioaddr);
1265 if (np->s.ramaddr)
1266 pci_iounmap(pdev, np->s.ramaddr);
1267 /*
1268 * Free O/S independent resources.
1269 */
1270 sym_hcb_free(np);
1271
1272 sym_mfree_dma(np, sizeof(*np), "HCB");
1273}
1274
1275/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 * Host attach and initialisations.
1277 *
1278 * Allocate host data and ncb structure.
1279 * Remap MMIO region.
1280 * Do chip initialization.
1281 * If all is OK, install interrupt handling and
1282 * start the timer daemon.
1283 */
1284static struct Scsi_Host * __devinit sym_attach(struct scsi_host_template *tpnt,
1285 int unit, struct sym_device *dev)
1286{
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001287 struct sym_data *sym_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 struct sym_hcb *np = NULL;
Tony Battersbya71d0352009-01-08 12:55:52 -05001289 struct Scsi_Host *shost = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 struct pci_dev *pdev = dev->pdev;
1291 unsigned long flags;
1292 struct sym_fw *fw;
Tony Battersbyb4090632009-01-08 12:54:45 -05001293 int do_free_irq = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
Matthew Wilcox8022fbd2007-10-05 15:55:11 -04001295 printk(KERN_INFO "sym%d: <%s> rev 0x%x at pci %s irq %u\n",
Matthew Wilcoxbd678452007-10-05 15:55:05 -04001296 unit, dev->chip.name, pdev->revision, pci_name(pdev),
Matthew Wilcox8022fbd2007-10-05 15:55:11 -04001297 pdev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298
1299 /*
1300 * Get the firmware for this chip.
1301 */
1302 fw = sym_find_firmware(&dev->chip);
1303 if (!fw)
Tony Battersbya71d0352009-01-08 12:55:52 -05001304 goto attach_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001306 shost = scsi_host_alloc(tpnt, sizeof(*sym_data));
1307 if (!shost)
Tony Battersbya71d0352009-01-08 12:55:52 -05001308 goto attach_failed;
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001309 sym_data = shost_priv(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310
1311 /*
1312 * Allocate immediately the host control block,
1313 * since we are only expecting to succeed. :)
1314 * We keep track in the HCB of all the resources that
1315 * are to be released on error.
1316 */
1317 np = __sym_calloc_dma(&pdev->dev, sizeof(*np), "HCB");
1318 if (!np)
1319 goto attach_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 np->bus_dmat = &pdev->dev; /* Result in 1 DMA pool per HBA */
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001321 sym_data->ncb = np;
1322 sym_data->pdev = pdev;
1323 np->s.host = shost;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001325 pci_set_drvdata(pdev, shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326
1327 /*
1328 * Copy some useful infos to the HCB.
1329 */
1330 np->hcb_ba = vtobus(np);
1331 np->verbose = sym_driver_setup.verbose;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 np->s.unit = unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 np->features = dev->chip.features;
1334 np->clock_divn = dev->chip.nr_divisor;
1335 np->maxoffs = dev->chip.offset_max;
1336 np->maxburst = dev->chip.burst_max;
1337 np->myaddr = dev->host_id;
Tony Battersbya71d0352009-01-08 12:55:52 -05001338 np->mmio_ba = (u32)dev->mmio_base;
Tony Battersby783fa732009-01-08 12:56:58 -05001339 np->ram_ba = (u32)dev->ram_base;
Tony Battersbya71d0352009-01-08 12:55:52 -05001340 np->s.ioaddr = dev->s.ioaddr;
1341 np->s.ramaddr = dev->s.ramaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
1343 /*
1344 * Edit its name.
1345 */
1346 strlcpy(np->s.chip_name, dev->chip.name, sizeof(np->s.chip_name));
1347 sprintf(np->s.inst_name, "sym%d", np->s.unit);
1348
Matthew Wilcox4d85b472007-10-05 15:55:09 -04001349 if ((SYM_CONF_DMA_ADDRESSING_MODE > 0) && (np->features & FE_DAC) &&
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001350 !pci_set_dma_mask(pdev, DMA_DAC_MASK)) {
Matthew Wilcox4d85b472007-10-05 15:55:09 -04001351 set_dac(np);
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001352 } else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
Matthew Wilcox4d85b472007-10-05 15:55:09 -04001353 printf_warning("%s: No suitable DMA available\n", sym_name(np));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 goto attach_failed;
Matthew Wilcox4d85b472007-10-05 15:55:09 -04001355 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001357 if (sym_hcb_attach(shost, fw, dev->nvram))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 goto attach_failed;
1359
1360 /*
1361 * Install the interrupt handler.
1362 * If we synchonize the C code with SCRIPTS on interrupt,
1363 * we do not want to share the INTR line at all.
1364 */
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001365 if (request_irq(pdev->irq, sym53c8xx_intr, IRQF_SHARED, NAME53C8XX,
1366 shost)) {
Matthew Wilcox8022fbd2007-10-05 15:55:11 -04001367 printf_err("%s: request irq %u failure\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 sym_name(np), pdev->irq);
1369 goto attach_failed;
1370 }
Tony Battersbyb4090632009-01-08 12:54:45 -05001371 do_free_irq = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372
1373 /*
1374 * After SCSI devices have been opened, we cannot
1375 * reset the bus safely, so we do it here.
1376 */
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001377 spin_lock_irqsave(shost->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 if (sym_reset_scsi_bus(np, 0))
1379 goto reset_failed;
1380
1381 /*
1382 * Start the SCRIPTS.
1383 */
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001384 sym_start_up(shost, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
1386 /*
1387 * Start the timer daemon
1388 */
1389 init_timer(&np->s.timer);
1390 np->s.timer.data = (unsigned long) np;
1391 np->s.timer.function = sym53c8xx_timer;
1392 np->s.lasttime=0;
1393 sym_timer (np);
1394
1395 /*
1396 * Fill Linux host instance structure
1397 * and return success.
1398 */
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001399 shost->max_channel = 0;
1400 shost->this_id = np->myaddr;
1401 shost->max_id = np->maxwide ? 16 : 8;
1402 shost->max_lun = SYM_CONF_MAX_LUN;
1403 shost->unique_id = pci_resource_start(pdev, 0);
1404 shost->cmd_per_lun = SYM_CONF_MAX_TAG;
1405 shost->can_queue = (SYM_CONF_MAX_START-2);
1406 shost->sg_tablesize = SYM_CONF_MAX_SG;
1407 shost->max_cmd_len = 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 BUG_ON(sym2_transport_template == NULL);
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001409 shost->transportt = sym2_transport_template;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410
Kai Makisara34996ac2007-10-05 15:54:58 -04001411 /* 53c896 rev 1 errata: DMA may not cross 16MB boundary */
Matthew Wilcoxbd678452007-10-05 15:55:05 -04001412 if (pdev->device == PCI_DEVICE_ID_NCR_53C896 && pdev->revision < 2)
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001413 shost->dma_boundary = 0xFFFFFF;
Kai Makisara34996ac2007-10-05 15:54:58 -04001414
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001415 spin_unlock_irqrestore(shost->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001417 return shost;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
1419 reset_failed:
1420 printf_err("%s: FATAL ERROR: CHECK SCSI BUS - CABLES, "
1421 "TERMINATION, DEVICE POWER etc.!\n", sym_name(np));
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001422 spin_unlock_irqrestore(shost->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 attach_failed:
Tony Battersby07b9d812009-01-08 12:53:37 -05001424 printf_info("sym%d: giving up ...\n", unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 if (np)
Tony Battersbyb4090632009-01-08 12:54:45 -05001426 sym_free_resources(np, pdev, do_free_irq);
Tony Battersbya71d0352009-01-08 12:55:52 -05001427 else
1428 sym_iounmap_device(dev);
1429 if (shost)
1430 scsi_host_put(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431
1432 return NULL;
1433 }
1434
1435
1436/*
1437 * Detect and try to read SYMBIOS and TEKRAM NVRAM.
1438 */
1439#if SYM_CONF_NVRAM_SUPPORT
1440static void __devinit sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
1441{
1442 devp->nvram = nvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 nvp->type = 0;
1444
1445 sym_read_nvram(devp, nvp);
1446}
1447#else
1448static inline void sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
1449{
1450}
1451#endif /* SYM_CONF_NVRAM_SUPPORT */
1452
1453static int __devinit sym_check_supported(struct sym_device *device)
1454{
1455 struct sym_chip *chip;
1456 struct pci_dev *pdev = device->pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 unsigned long io_port = pci_resource_start(pdev, 0);
1458 int i;
1459
1460 /*
1461 * If user excluded this chip, do not initialize it.
1462 * I hate this code so much. Must kill it.
1463 */
1464 if (io_port) {
1465 for (i = 0 ; i < 8 ; i++) {
1466 if (sym_driver_setup.excludes[i] == io_port)
1467 return -ENODEV;
1468 }
1469 }
1470
1471 /*
1472 * Check if the chip is supported. Then copy the chip description
1473 * to our device structure so we can make it match the actual device
1474 * and options.
1475 */
Matthew Wilcoxbd678452007-10-05 15:55:05 -04001476 chip = sym_lookup_chip_table(pdev->device, pdev->revision);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 if (!chip) {
1478 dev_info(&pdev->dev, "device not supported\n");
1479 return -ENODEV;
1480 }
1481 memcpy(&device->chip, chip, sizeof(device->chip));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
1483 return 0;
1484}
1485
1486/*
1487 * Ignore Symbios chips controlled by various RAID controllers.
1488 * These controllers set value 0x52414944 at RAM end - 16.
1489 */
1490static int __devinit sym_check_raid(struct sym_device *device)
1491{
1492 unsigned int ram_size, ram_val;
1493
1494 if (!device->s.ramaddr)
1495 return 0;
1496
1497 if (device->chip.features & FE_RAM8K)
1498 ram_size = 8192;
1499 else
1500 ram_size = 4096;
1501
1502 ram_val = readl(device->s.ramaddr + ram_size - 16);
1503 if (ram_val != 0x52414944)
1504 return 0;
1505
1506 dev_info(&device->pdev->dev,
1507 "not initializing, driven by RAID controller.\n");
1508 return -ENODEV;
1509}
1510
1511static int __devinit sym_set_workarounds(struct sym_device *device)
1512{
1513 struct sym_chip *chip = &device->chip;
1514 struct pci_dev *pdev = device->pdev;
1515 u_short status_reg;
1516
1517 /*
1518 * (ITEM 12 of a DEL about the 896 I haven't yet).
1519 * We must ensure the chip will use WRITE AND INVALIDATE.
1520 * The revision number limit is for now arbitrary.
1521 */
Matthew Wilcoxbd678452007-10-05 15:55:05 -04001522 if (pdev->device == PCI_DEVICE_ID_NCR_53C896 && pdev->revision < 0x4) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 chip->features |= (FE_WRIE | FE_CLSE);
1524 }
1525
1526 /* If the chip can do Memory Write Invalidate, enable it */
1527 if (chip->features & FE_WRIE) {
1528 if (pci_set_mwi(pdev))
1529 return -ENODEV;
1530 }
1531
1532 /*
1533 * Work around for errant bit in 895A. The 66Mhz
1534 * capable bit is set erroneously. Clear this bit.
1535 * (Item 1 DEL 533)
1536 *
1537 * Make sure Config space and Features agree.
1538 *
1539 * Recall: writes are not normal to status register -
1540 * write a 1 to clear and a 0 to leave unchanged.
1541 * Can only reset bits.
1542 */
1543 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1544 if (chip->features & FE_66MHZ) {
1545 if (!(status_reg & PCI_STATUS_66MHZ))
1546 chip->features &= ~FE_66MHZ;
1547 } else {
1548 if (status_reg & PCI_STATUS_66MHZ) {
1549 status_reg = PCI_STATUS_66MHZ;
1550 pci_write_config_word(pdev, PCI_STATUS, status_reg);
1551 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1552 }
1553 }
1554
1555 return 0;
1556}
1557
1558/*
Tony Battersby783fa732009-01-08 12:56:58 -05001559 * Map HBA registers and on-chip SRAM (if present).
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 */
Tony Battersby783fa732009-01-08 12:56:58 -05001561static int __devinit
1562sym_iomap_device(struct sym_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563{
Tony Battersby783fa732009-01-08 12:56:58 -05001564 struct pci_dev *pdev = device->pdev;
Matthew Wilcoxb6d105d2006-03-28 11:03:44 -05001565 struct pci_bus_region bus_addr;
Tony Battersby783fa732009-01-08 12:56:58 -05001566 int i = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567
Matthew Wilcoxb6d105d2006-03-28 11:03:44 -05001568 pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[1]);
1569 device->mmio_base = bus_addr.start;
1570
Tony Battersby783fa732009-01-08 12:56:58 -05001571 if (device->chip.features & FE_RAM) {
1572 /*
1573 * If the BAR is 64-bit, resource 2 will be occupied by the
1574 * upper 32 bits
1575 */
1576 if (!pdev->resource[i].flags)
1577 i++;
1578 pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[i]);
1579 device->ram_base = bus_addr.start;
1580 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
Matthew Wilcox1f61d822006-03-28 11:03:43 -05001582#ifdef CONFIG_SCSI_SYM53C8XX_MMIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 if (device->mmio_base)
1584 device->s.ioaddr = pci_iomap(pdev, 1,
1585 pci_resource_len(pdev, 1));
1586#endif
1587 if (!device->s.ioaddr)
1588 device->s.ioaddr = pci_iomap(pdev, 0,
1589 pci_resource_len(pdev, 0));
Tony Battersby783fa732009-01-08 12:56:58 -05001590 if (!device->s.ioaddr) {
1591 dev_err(&pdev->dev, "could not map registers; giving up.\n");
1592 return -EIO;
1593 }
1594 if (device->ram_base) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 device->s.ramaddr = pci_iomap(pdev, i,
1596 pci_resource_len(pdev, i));
Tony Battersby783fa732009-01-08 12:56:58 -05001597 if (!device->s.ramaddr) {
1598 dev_warn(&pdev->dev,
1599 "could not map SRAM; continuing anyway.\n");
1600 device->ram_base = 0;
1601 }
1602 }
1603
1604 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605}
1606
1607/*
1608 * The NCR PQS and PDS cards are constructed as a DEC bridge
1609 * behind which sits a proprietary NCR memory controller and
1610 * either four or two 53c875s as separate devices. We can tell
1611 * if an 875 is part of a PQS/PDS or not since if it is, it will
1612 * be on the same bus as the memory controller. In its usual
1613 * mode of operation, the 875s are slaved to the memory
1614 * controller for all transfers. To operate with the Linux
1615 * driver, the memory controller is disabled and the 875s
1616 * freed to function independently. The only wrinkle is that
1617 * the preset SCSI ID (which may be zero) must be read in from
1618 * a special configuration space register of the 875.
1619 */
1620static void sym_config_pqs(struct pci_dev *pdev, struct sym_device *sym_dev)
1621{
1622 int slot;
1623 u8 tmp;
1624
1625 for (slot = 0; slot < 256; slot++) {
1626 struct pci_dev *memc = pci_get_slot(pdev->bus, slot);
1627
1628 if (!memc || memc->vendor != 0x101a || memc->device == 0x0009) {
1629 pci_dev_put(memc);
1630 continue;
1631 }
1632
1633 /* bit 1: allow individual 875 configuration */
1634 pci_read_config_byte(memc, 0x44, &tmp);
1635 if ((tmp & 0x2) == 0) {
1636 tmp |= 0x2;
1637 pci_write_config_byte(memc, 0x44, tmp);
1638 }
1639
1640 /* bit 2: drive individual 875 interrupts to the bus */
1641 pci_read_config_byte(memc, 0x45, &tmp);
1642 if ((tmp & 0x4) == 0) {
1643 tmp |= 0x4;
1644 pci_write_config_byte(memc, 0x45, tmp);
1645 }
1646
1647 pci_dev_put(memc);
1648 break;
1649 }
1650
1651 pci_read_config_byte(pdev, 0x84, &tmp);
1652 sym_dev->host_id = tmp;
1653}
1654
1655/*
1656 * Called before unloading the module.
1657 * Detach the host.
1658 * We have to free resources and halt the NCR chip.
1659 */
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001660static int sym_detach(struct Scsi_Host *shost, struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661{
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001662 struct sym_hcb *np = sym_get_hcb(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 printk("%s: detaching ...\n", sym_name(np));
1664
1665 del_timer_sync(&np->s.timer);
1666
1667 /*
1668 * Reset NCR chip.
1669 * We should use sym_soft_reset(), but we don't want to do
1670 * so, since we may not be safe if interrupts occur.
1671 */
1672 printk("%s: resetting chip\n", sym_name(np));
1673 OUTB(np, nc_istat, SRST);
Matthew Wilcox 53222b92005-05-20 19:15:43 +01001674 INB(np, nc_mbox1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 udelay(10);
1676 OUTB(np, nc_istat, 0);
1677
Tony Battersbyb4090632009-01-08 12:54:45 -05001678 sym_free_resources(np, pdev, 1);
Tony Battersbyd3ce65d2009-01-08 12:52:32 -05001679 scsi_host_put(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680
1681 return 1;
1682}
1683
1684/*
1685 * Driver host template.
1686 */
1687static struct scsi_host_template sym2_template = {
1688 .module = THIS_MODULE,
1689 .name = "sym53c8xx",
1690 .info = sym53c8xx_info,
1691 .queuecommand = sym53c8xx_queue_command,
1692 .slave_alloc = sym53c8xx_slave_alloc,
1693 .slave_configure = sym53c8xx_slave_configure,
Matthew Wilcox84e203a2005-11-29 23:08:31 -05001694 .slave_destroy = sym53c8xx_slave_destroy,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 .eh_abort_handler = sym53c8xx_eh_abort_handler,
1696 .eh_device_reset_handler = sym53c8xx_eh_device_reset_handler,
1697 .eh_bus_reset_handler = sym53c8xx_eh_bus_reset_handler,
1698 .eh_host_reset_handler = sym53c8xx_eh_host_reset_handler,
1699 .this_id = 7,
Matthew Wilcox14ac8bf2006-03-28 11:03:44 -05001700 .use_clustering = ENABLE_CLUSTERING,
1701 .max_sectors = 0xFFFF,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702#ifdef SYM_LINUX_PROC_INFO_SUPPORT
1703 .proc_info = sym53c8xx_proc_info,
1704 .proc_name = NAME53C8XX,
1705#endif
1706};
1707
1708static int attach_count;
1709
1710static int __devinit sym2_probe(struct pci_dev *pdev,
1711 const struct pci_device_id *ent)
1712{
1713 struct sym_device sym_dev;
1714 struct sym_nvram nvram;
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001715 struct Scsi_Host *shost;
Tony Battersbya71d0352009-01-08 12:55:52 -05001716 int do_iounmap = 0;
1717 int do_disable_device = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718
1719 memset(&sym_dev, 0, sizeof(sym_dev));
1720 memset(&nvram, 0, sizeof(nvram));
Tony Battersby783fa732009-01-08 12:56:58 -05001721 sym_dev.pdev = pdev;
1722 sym_dev.host_id = SYM_SETUP_HOST_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723
1724 if (pci_enable_device(pdev))
1725 goto leave;
1726
1727 pci_set_master(pdev);
1728
1729 if (pci_request_regions(pdev, NAME53C8XX))
1730 goto disable;
1731
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 if (sym_check_supported(&sym_dev))
1733 goto free;
1734
Tony Battersby783fa732009-01-08 12:56:58 -05001735 if (sym_iomap_device(&sym_dev))
1736 goto free;
1737 do_iounmap = 1;
1738
Tony Battersbya71d0352009-01-08 12:55:52 -05001739 if (sym_check_raid(&sym_dev)) {
1740 do_disable_device = 0; /* Don't disable the device */
1741 goto free;
1742 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743
1744 if (sym_set_workarounds(&sym_dev))
1745 goto free;
1746
1747 sym_config_pqs(pdev, &sym_dev);
1748
1749 sym_get_nvram(&sym_dev, &nvram);
1750
Tony Battersbya71d0352009-01-08 12:55:52 -05001751 do_iounmap = 0; /* Don't sym_iounmap_device() after sym_attach(). */
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001752 shost = sym_attach(&sym2_template, attach_count, &sym_dev);
1753 if (!shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 goto free;
1755
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001756 if (scsi_add_host(shost, &pdev->dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 goto detach;
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001758 scsi_scan_host(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759
1760 attach_count++;
1761
1762 return 0;
1763
1764 detach:
1765 sym_detach(pci_get_drvdata(pdev), pdev);
1766 free:
Tony Battersbya71d0352009-01-08 12:55:52 -05001767 if (do_iounmap)
1768 sym_iounmap_device(&sym_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 pci_release_regions(pdev);
1770 disable:
Tony Battersbya71d0352009-01-08 12:55:52 -05001771 if (do_disable_device)
1772 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 leave:
1774 return -ENODEV;
1775}
1776
Randy Dunlap864473b2007-10-29 11:20:40 -07001777static void sym2_remove(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778{
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001779 struct Scsi_Host *shost = pci_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001781 scsi_remove_host(shost);
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001782 sym_detach(shost, pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 pci_release_regions(pdev);
1784 pci_disable_device(pdev);
1785
1786 attach_count--;
1787}
1788
Linas Vepstasd68cd752007-10-05 15:55:04 -04001789/**
1790 * sym2_io_error_detected() - called when PCI error is detected
1791 * @pdev: pointer to PCI device
1792 * @state: current state of the PCI slot
1793 */
1794static pci_ers_result_t sym2_io_error_detected(struct pci_dev *pdev,
1795 enum pci_channel_state state)
1796{
1797 /* If slot is permanently frozen, turn everything off */
1798 if (state == pci_channel_io_perm_failure) {
1799 sym2_remove(pdev);
1800 return PCI_ERS_RESULT_DISCONNECT;
1801 }
1802
1803 disable_irq(pdev->irq);
1804 pci_disable_device(pdev);
1805
1806 /* Request that MMIO be enabled, so register dump can be taken. */
1807 return PCI_ERS_RESULT_CAN_RECOVER;
1808}
1809
1810/**
1811 * sym2_io_slot_dump - Enable MMIO and dump debug registers
1812 * @pdev: pointer to PCI device
1813 */
1814static pci_ers_result_t sym2_io_slot_dump(struct pci_dev *pdev)
1815{
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001816 struct Scsi_Host *shost = pci_get_drvdata(pdev);
Linas Vepstasd68cd752007-10-05 15:55:04 -04001817
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001818 sym_dump_registers(shost);
Linas Vepstasd68cd752007-10-05 15:55:04 -04001819
1820 /* Request a slot reset. */
1821 return PCI_ERS_RESULT_NEED_RESET;
1822}
1823
1824/**
1825 * sym2_reset_workarounds - hardware-specific work-arounds
1826 *
1827 * This routine is similar to sym_set_workarounds(), except
1828 * that, at this point, we already know that the device was
1829 * succesfully intialized at least once before, and so most
1830 * of the steps taken there are un-needed here.
1831 */
1832static void sym2_reset_workarounds(struct pci_dev *pdev)
1833{
Linas Vepstasd68cd752007-10-05 15:55:04 -04001834 u_short status_reg;
1835 struct sym_chip *chip;
1836
Matthew Wilcoxbd678452007-10-05 15:55:05 -04001837 chip = sym_lookup_chip_table(pdev->device, pdev->revision);
Linas Vepstasd68cd752007-10-05 15:55:04 -04001838
1839 /* Work around for errant bit in 895A, in a fashion
1840 * similar to what is done in sym_set_workarounds().
1841 */
1842 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1843 if (!(chip->features & FE_66MHZ) && (status_reg & PCI_STATUS_66MHZ)) {
1844 status_reg = PCI_STATUS_66MHZ;
1845 pci_write_config_word(pdev, PCI_STATUS, status_reg);
1846 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1847 }
1848}
1849
1850/**
1851 * sym2_io_slot_reset() - called when the pci bus has been reset.
1852 * @pdev: pointer to PCI device
1853 *
1854 * Restart the card from scratch.
1855 */
1856static pci_ers_result_t sym2_io_slot_reset(struct pci_dev *pdev)
1857{
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001858 struct Scsi_Host *shost = pci_get_drvdata(pdev);
1859 struct sym_hcb *np = sym_get_hcb(shost);
Linas Vepstasd68cd752007-10-05 15:55:04 -04001860
1861 printk(KERN_INFO "%s: recovering from a PCI slot reset\n",
1862 sym_name(np));
1863
1864 if (pci_enable_device(pdev)) {
1865 printk(KERN_ERR "%s: Unable to enable after PCI reset\n",
1866 sym_name(np));
1867 return PCI_ERS_RESULT_DISCONNECT;
1868 }
1869
1870 pci_set_master(pdev);
1871 enable_irq(pdev->irq);
1872
1873 /* If the chip can do Memory Write Invalidate, enable it */
1874 if (np->features & FE_WRIE) {
1875 if (pci_set_mwi(pdev))
1876 return PCI_ERS_RESULT_DISCONNECT;
1877 }
1878
1879 /* Perform work-arounds, analogous to sym_set_workarounds() */
1880 sym2_reset_workarounds(pdev);
1881
1882 /* Perform host reset only on one instance of the card */
1883 if (PCI_FUNC(pdev->devfn) == 0) {
1884 if (sym_reset_scsi_bus(np, 0)) {
1885 printk(KERN_ERR "%s: Unable to reset scsi host\n",
1886 sym_name(np));
1887 return PCI_ERS_RESULT_DISCONNECT;
1888 }
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001889 sym_start_up(shost, 1);
Linas Vepstasd68cd752007-10-05 15:55:04 -04001890 }
1891
1892 return PCI_ERS_RESULT_RECOVERED;
1893}
1894
1895/**
1896 * sym2_io_resume() - resume normal ops after PCI reset
1897 * @pdev: pointer to PCI device
1898 *
1899 * Called when the error recovery driver tells us that its
1900 * OK to resume normal operation. Use completion to allow
1901 * halted scsi ops to resume.
1902 */
1903static void sym2_io_resume(struct pci_dev *pdev)
1904{
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001905 struct Scsi_Host *shost = pci_get_drvdata(pdev);
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001906 struct sym_data *sym_data = shost_priv(shost);
Linas Vepstasd68cd752007-10-05 15:55:04 -04001907
1908 spin_lock_irq(shost->host_lock);
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001909 if (sym_data->io_reset)
1910 complete_all(sym_data->io_reset);
Linas Vepstasd68cd752007-10-05 15:55:04 -04001911 spin_unlock_irq(shost->host_lock);
1912}
1913
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914static void sym2_get_signalling(struct Scsi_Host *shost)
1915{
1916 struct sym_hcb *np = sym_get_hcb(shost);
1917 enum spi_signal_type type;
1918
1919 switch (np->scsi_mode) {
1920 case SMODE_SE:
1921 type = SPI_SIGNAL_SE;
1922 break;
1923 case SMODE_LVD:
1924 type = SPI_SIGNAL_LVD;
1925 break;
1926 case SMODE_HVD:
1927 type = SPI_SIGNAL_HVD;
1928 break;
1929 default:
1930 type = SPI_SIGNAL_UNKNOWN;
1931 break;
1932 }
1933 spi_signalling(shost) = type;
1934}
1935
1936static void sym2_set_offset(struct scsi_target *starget, int offset)
1937{
1938 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1939 struct sym_hcb *np = sym_get_hcb(shost);
1940 struct sym_tcb *tp = &np->target[starget->id];
1941
1942 tp->tgoal.offset = offset;
1943 tp->tgoal.check_nego = 1;
1944}
1945
1946static void sym2_set_period(struct scsi_target *starget, int period)
1947{
1948 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1949 struct sym_hcb *np = sym_get_hcb(shost);
1950 struct sym_tcb *tp = &np->target[starget->id];
1951
James Bottomleye4862fe2005-05-06 13:14:48 -05001952 /* have to have DT for these transfers, but DT will also
1953 * set width, so check that this is allowed */
1954 if (period <= np->minsync && spi_width(starget))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 tp->tgoal.dt = 1;
1956
1957 tp->tgoal.period = period;
1958 tp->tgoal.check_nego = 1;
1959}
1960
1961static void sym2_set_width(struct scsi_target *starget, int width)
1962{
1963 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1964 struct sym_hcb *np = sym_get_hcb(shost);
1965 struct sym_tcb *tp = &np->target[starget->id];
1966
1967 /* It is illegal to have DT set on narrow transfers. If DT is
1968 * clear, we must also clear IU and QAS. */
1969 if (width == 0)
1970 tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
1971
1972 tp->tgoal.width = width;
1973 tp->tgoal.check_nego = 1;
1974}
1975
1976static void sym2_set_dt(struct scsi_target *starget, int dt)
1977{
1978 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1979 struct sym_hcb *np = sym_get_hcb(shost);
1980 struct sym_tcb *tp = &np->target[starget->id];
1981
1982 /* We must clear QAS and IU if DT is clear */
1983 if (dt)
1984 tp->tgoal.dt = 1;
1985 else
1986 tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
1987 tp->tgoal.check_nego = 1;
1988}
1989
Matthew Wilcox8b2f8132005-11-29 23:08:38 -05001990#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991static void sym2_set_iu(struct scsi_target *starget, int iu)
1992{
1993 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1994 struct sym_hcb *np = sym_get_hcb(shost);
1995 struct sym_tcb *tp = &np->target[starget->id];
1996
1997 if (iu)
1998 tp->tgoal.iu = tp->tgoal.dt = 1;
1999 else
2000 tp->tgoal.iu = 0;
2001 tp->tgoal.check_nego = 1;
2002}
2003
2004static void sym2_set_qas(struct scsi_target *starget, int qas)
2005{
2006 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2007 struct sym_hcb *np = sym_get_hcb(shost);
2008 struct sym_tcb *tp = &np->target[starget->id];
2009
2010 if (qas)
2011 tp->tgoal.dt = tp->tgoal.qas = 1;
2012 else
2013 tp->tgoal.qas = 0;
2014 tp->tgoal.check_nego = 1;
2015}
Matthew Wilcox8b2f8132005-11-29 23:08:38 -05002016#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017
2018static struct spi_function_template sym2_transport_functions = {
2019 .set_offset = sym2_set_offset,
2020 .show_offset = 1,
2021 .set_period = sym2_set_period,
2022 .show_period = 1,
2023 .set_width = sym2_set_width,
2024 .show_width = 1,
2025 .set_dt = sym2_set_dt,
2026 .show_dt = 1,
Matthew Wilcox8b2f8132005-11-29 23:08:38 -05002027#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 .set_iu = sym2_set_iu,
2029 .show_iu = 1,
2030 .set_qas = sym2_set_qas,
2031 .show_qas = 1,
Matthew Wilcox8b2f8132005-11-29 23:08:38 -05002032#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 .get_signalling = sym2_get_signalling,
2034};
2035
2036static struct pci_device_id sym2_id_table[] __devinitdata = {
2037 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C810,
2038 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2039 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C820,
2040 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
2041 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C825,
2042 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2043 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C815,
2044 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2045 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C810AP,
2046 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
2047 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C860,
2048 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2049 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1510,
Grant Grundlerb2b3c122006-07-17 07:22:45 -06002050 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SCSI<<8, 0xffff00, 0UL },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C896,
2052 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2053 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C895,
2054 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2055 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C885,
2056 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2057 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875,
2058 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2059 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C1510,
Chip Coldwell147e5052007-05-23 14:41:38 -07002060 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SCSI<<8, 0xffff00, 0UL }, /* new */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C895A,
2062 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2063 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C875A,
2064 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2065 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_33,
2066 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2067 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_66,
2068 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2069 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875J,
2070 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2071 { 0, }
2072};
2073
2074MODULE_DEVICE_TABLE(pci, sym2_id_table);
2075
Linas Vepstasd68cd752007-10-05 15:55:04 -04002076static struct pci_error_handlers sym2_err_handler = {
2077 .error_detected = sym2_io_error_detected,
2078 .mmio_enabled = sym2_io_slot_dump,
2079 .slot_reset = sym2_io_slot_reset,
2080 .resume = sym2_io_resume,
2081};
2082
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083static struct pci_driver sym2_driver = {
2084 .name = NAME53C8XX,
2085 .id_table = sym2_id_table,
2086 .probe = sym2_probe,
Randy Dunlap864473b2007-10-29 11:20:40 -07002087 .remove = sym2_remove,
Linas Vepstasd68cd752007-10-05 15:55:04 -04002088 .err_handler = &sym2_err_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089};
2090
2091static int __init sym2_init(void)
2092{
2093 int error;
2094
2095 sym2_setup_params();
2096 sym2_transport_template = spi_attach_transport(&sym2_transport_functions);
2097 if (!sym2_transport_template)
2098 return -ENODEV;
2099
2100 error = pci_register_driver(&sym2_driver);
2101 if (error)
2102 spi_release_transport(sym2_transport_template);
2103 return error;
2104}
2105
2106static void __exit sym2_exit(void)
2107{
2108 pci_unregister_driver(&sym2_driver);
2109 spi_release_transport(sym2_transport_template);
2110}
2111
2112module_init(sym2_init);
2113module_exit(sym2_exit);