blob: e2b8e68b57e7b3dfe1a467e0046a9d83318713c1 [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 */
Jeff Garzikf2812332010-11-16 02:10:29 -0500508static int sym53c8xx_queue_command_lck(struct scsi_cmnd *cmd,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 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
Jeff Garzikf2812332010-11-16 02:10:29 -0500539static DEF_SCSI_QCMD(sym53c8xx_queue_command)
540
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541/*
542 * Linux entry point of the interrupt handler.
543 */
David Howells7d12e782006-10-05 14:55:46 +0100544static irqreturn_t sym53c8xx_intr(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545{
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -0400546 struct Scsi_Host *shost = dev_id;
547 struct sym_data *sym_data = shost_priv(shost);
548 irqreturn_t result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
Linas Vepstasd68cd752007-10-05 15:55:04 -0400550 /* Avoid spinloop trying to handle interrupts on frozen device */
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -0400551 if (pci_channel_offline(sym_data->pdev))
Linas Vepstasd68cd752007-10-05 15:55:04 -0400552 return IRQ_NONE;
553
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("[");
555
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -0400556 spin_lock(shost->host_lock);
557 result = sym_interrupt(shost);
558 spin_unlock(shost->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
560 if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("]\n");
561
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -0400562 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563}
564
565/*
566 * Linux entry point of the timer handler
567 */
568static void sym53c8xx_timer(unsigned long npref)
569{
570 struct sym_hcb *np = (struct sym_hcb *)npref;
571 unsigned long flags;
572
573 spin_lock_irqsave(np->s.host->host_lock, flags);
574 sym_timer(np);
575 spin_unlock_irqrestore(np->s.host->host_lock, flags);
576}
577
578
579/*
580 * What the eh thread wants us to perform.
581 */
582#define SYM_EH_ABORT 0
583#define SYM_EH_DEVICE_RESET 1
584#define SYM_EH_BUS_RESET 2
585#define SYM_EH_HOST_RESET 3
586
587/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 * Generic method for our eh processing.
589 * The 'op' argument tells what we have to do.
590 */
591static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd)
592{
Matthew Wilcoxb4e93a72006-03-28 11:03:44 -0500593 struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400594 struct Scsi_Host *shost = cmd->device->host;
595 struct sym_data *sym_data = shost_priv(shost);
596 struct pci_dev *pdev = sym_data->pdev;
597 struct sym_hcb *np = sym_data->ncb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 SYM_QUEHEAD *qp;
Matthew Wilcox2ba65362007-10-05 15:55:03 -0400599 int cmd_queued = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 int sts = -1;
Matthew Wilcoxd637c452006-03-29 14:45:18 -0700601 struct completion eh_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400603 scmd_printk(KERN_WARNING, cmd, "%s operation started\n", opname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
Linas Vepstasd68cd752007-10-05 15:55:04 -0400605 /* We may be in an error condition because the PCI bus
606 * went down. In this case, we need to wait until the
607 * PCI bus is reset, the card is reset, and only then
608 * proceed with the scsi error recovery. There's no
609 * point in hurrying; take a leisurely wait.
610 */
611#define WAIT_FOR_PCI_RECOVERY 35
612 if (pci_channel_offline(pdev)) {
Linas Vepstasd68cd752007-10-05 15:55:04 -0400613 int finished_reset = 0;
614 init_completion(&eh_done);
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400615 spin_lock_irq(shost->host_lock);
Linas Vepstasd68cd752007-10-05 15:55:04 -0400616 /* Make sure we didn't race */
617 if (pci_channel_offline(pdev)) {
Krzysztof Heltd9aa3af2008-01-11 21:50:46 +0100618 BUG_ON(sym_data->io_reset);
619 sym_data->io_reset = &eh_done;
Linas Vepstasd68cd752007-10-05 15:55:04 -0400620 } else {
Linas Vepstasd68cd752007-10-05 15:55:04 -0400621 finished_reset = 1;
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -0400622 }
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400623 spin_unlock_irq(shost->host_lock);
Linas Vepstasd68cd752007-10-05 15:55:04 -0400624 if (!finished_reset)
Krzysztof Heltd9aa3af2008-01-11 21:50:46 +0100625 finished_reset = wait_for_completion_timeout
626 (sym_data->io_reset,
Linas Vepstasd68cd752007-10-05 15:55:04 -0400627 WAIT_FOR_PCI_RECOVERY*HZ);
Krzysztof Heltd9aa3af2008-01-11 21:50:46 +0100628 spin_lock_irq(shost->host_lock);
629 sym_data->io_reset = NULL;
630 spin_unlock_irq(shost->host_lock);
Linas Vepstasd68cd752007-10-05 15:55:04 -0400631 if (!finished_reset)
632 return SCSI_FAILED;
633 }
634
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400635 spin_lock_irq(shost->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 /* This one is queued in some place -> to wait for completion */
637 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
638 struct sym_ccb *cp = sym_que_entry(qp, struct sym_ccb, link_ccbq);
639 if (cp->cmd == cmd) {
Matthew Wilcox2ba65362007-10-05 15:55:03 -0400640 cmd_queued = 1;
Matthew Wilcoxab19d522006-03-28 11:03:44 -0500641 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 }
643 }
644
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 /* Try to proceed the operation we have been asked for */
646 sts = -1;
647 switch(op) {
648 case SYM_EH_ABORT:
649 sts = sym_abort_scsiio(np, cmd, 1);
650 break;
651 case SYM_EH_DEVICE_RESET:
652 sts = sym_reset_scsi_target(np, cmd->device->id);
653 break;
654 case SYM_EH_BUS_RESET:
655 sym_reset_scsi_bus(np, 1);
656 sts = 0;
657 break;
658 case SYM_EH_HOST_RESET:
659 sym_reset_scsi_bus(np, 0);
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400660 sym_start_up(shost, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 sts = 0;
662 break;
663 default:
664 break;
665 }
666
667 /* On error, restore everything and cross fingers :) */
Matthew Wilcox2ba65362007-10-05 15:55:03 -0400668 if (sts)
669 cmd_queued = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
Matthew Wilcox2ba65362007-10-05 15:55:03 -0400671 if (cmd_queued) {
672 init_completion(&eh_done);
673 ucmd->eh_done = &eh_done;
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400674 spin_unlock_irq(shost->host_lock);
Matthew Wilcoxd637c452006-03-29 14:45:18 -0700675 if (!wait_for_completion_timeout(&eh_done, 5*HZ)) {
Matthew Wilcox2ba65362007-10-05 15:55:03 -0400676 ucmd->eh_done = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 sts = -2;
Matthew Wilcoxb4e93a72006-03-28 11:03:44 -0500678 }
Matthew Wilcox2ba65362007-10-05 15:55:03 -0400679 } else {
Matthew Wilcox5111eef2007-10-05 15:55:13 -0400680 spin_unlock_irq(shost->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 }
Matthew Wilcox2ba65362007-10-05 15:55:03 -0400682
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 dev_warn(&cmd->device->sdev_gendev, "%s operation %s.\n", opname,
684 sts==0 ? "complete" :sts==-2 ? "timed-out" : "failed");
685 return sts ? SCSI_FAILED : SCSI_SUCCESS;
686}
687
688
689/*
690 * Error handlers called from the eh thread (one thread per HBA).
691 */
692static int sym53c8xx_eh_abort_handler(struct scsi_cmnd *cmd)
693{
Matthew Wilcoxab19d522006-03-28 11:03:44 -0500694 return sym_eh_handler(SYM_EH_ABORT, "ABORT", cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695}
696
697static int sym53c8xx_eh_device_reset_handler(struct scsi_cmnd *cmd)
698{
Matthew Wilcoxab19d522006-03-28 11:03:44 -0500699 return sym_eh_handler(SYM_EH_DEVICE_RESET, "DEVICE RESET", cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700}
701
702static int sym53c8xx_eh_bus_reset_handler(struct scsi_cmnd *cmd)
703{
Matthew Wilcoxab19d522006-03-28 11:03:44 -0500704 return sym_eh_handler(SYM_EH_BUS_RESET, "BUS RESET", cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705}
706
707static int sym53c8xx_eh_host_reset_handler(struct scsi_cmnd *cmd)
708{
Matthew Wilcoxab19d522006-03-28 11:03:44 -0500709 return sym_eh_handler(SYM_EH_HOST_RESET, "HOST RESET", cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710}
711
712/*
713 * Tune device queuing depth, according to various limits.
714 */
715static void sym_tune_dev_queuing(struct sym_tcb *tp, int lun, u_short reqtags)
716{
717 struct sym_lcb *lp = sym_lp(tp, lun);
718 u_short oldtags;
719
720 if (!lp)
721 return;
722
723 oldtags = lp->s.reqtags;
724
725 if (reqtags > lp->s.scdev_depth)
726 reqtags = lp->s.scdev_depth;
727
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 lp->s.reqtags = reqtags;
729
730 if (reqtags != oldtags) {
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100731 dev_info(&tp->starget->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 "tagged command queuing %s, command queue depth %d.\n",
Matthew Wilcox3bea15a2006-03-28 11:03:44 -0500733 lp->s.reqtags ? "enabled" : "disabled", reqtags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 }
735}
736
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100737static int sym53c8xx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738{
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500739 struct sym_hcb *np = sym_get_hcb(sdev->host);
740 struct sym_tcb *tp = &np->target[sdev->id];
741 struct sym_lcb *lp;
Aaro Koskinenfa858452009-04-14 15:47:00 -0500742 unsigned long flags;
743 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100745 if (sdev->id >= SYM_CONF_MAX_TARGET || sdev->lun >= SYM_CONF_MAX_LUN)
746 return -ENXIO;
747
Aaro Koskinenfa858452009-04-14 15:47:00 -0500748 spin_lock_irqsave(np->s.host->host_lock, flags);
749
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100750 /*
751 * Fail the device init if the device is flagged NOSCAN at BOOT in
752 * the NVRAM. This may speed up boot and maintain coherency with
753 * BIOS device numbering. Clearing the flag allows the user to
754 * rescan skipped devices later. We also return an error for
755 * devices not flagged for SCAN LUNS in the NVRAM since some single
756 * lun devices behave badly when asked for a non zero LUN.
757 */
758
Matthew Wilcox66e8d1c2005-11-29 23:08:46 -0500759 if (tp->usrflags & SYM_SCAN_BOOT_DISABLED) {
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100760 tp->usrflags &= ~SYM_SCAN_BOOT_DISABLED;
Aaro Koskinenfa858452009-04-14 15:47:00 -0500761 starget_printk(KERN_INFO, sdev->sdev_target,
Matthew Wilcox66e8d1c2005-11-29 23:08:46 -0500762 "Scan at boot disabled in NVRAM\n");
Aaro Koskinenfa858452009-04-14 15:47:00 -0500763 error = -ENXIO;
764 goto out;
Matthew Wilcox 53222b92005-05-20 19:15:43 +0100765 }
766
Matthew Wilcox66e8d1c2005-11-29 23:08:46 -0500767 if (tp->usrflags & SYM_SCAN_LUNS_DISABLED) {
Aaro Koskinenfa858452009-04-14 15:47:00 -0500768 if (sdev->lun != 0) {
769 error = -ENXIO;
770 goto out;
771 }
772 starget_printk(KERN_INFO, sdev->sdev_target,
Matthew Wilcox66e8d1c2005-11-29 23:08:46 -0500773 "Multiple LUNs disabled in NVRAM\n");
774 }
775
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500776 lp = sym_alloc_lcb(np, sdev->id, sdev->lun);
Aaro Koskinenfa858452009-04-14 15:47:00 -0500777 if (!lp) {
778 error = -ENOMEM;
779 goto out;
780 }
781 if (tp->nlcb == 1)
782 tp->starget = sdev->sdev_target;
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500783
Matthew Wilcoxb37df482005-11-29 23:08:44 -0500784 spi_min_period(tp->starget) = tp->usr_period;
785 spi_max_width(tp->starget) = tp->usr_width;
786
Aaro Koskinenfa858452009-04-14 15:47:00 -0500787 error = 0;
788out:
789 spin_unlock_irqrestore(np->s.host->host_lock, flags);
790
791 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792}
793
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794/*
795 * Linux entry point for device queue sizing.
796 */
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500797static int sym53c8xx_slave_configure(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798{
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500799 struct sym_hcb *np = sym_get_hcb(sdev->host);
800 struct sym_tcb *tp = &np->target[sdev->id];
801 struct sym_lcb *lp = sym_lp(tp, sdev->lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 int reqtags, depth_to_use;
803
804 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 * Get user flags.
806 */
807 lp->curr_flags = lp->user_flags;
808
809 /*
810 * Select queue depth from driver setup.
Tony Battersbyc2fd2062009-01-08 12:58:04 -0500811 * Do not use more than configured by user.
812 * Use at least 1.
813 * Do not use more than our maximum.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 */
Matthew Wilcoxa44131b2007-10-05 15:55:08 -0400815 reqtags = sym_driver_setup.max_tag;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 if (reqtags > tp->usrtags)
817 reqtags = tp->usrtags;
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500818 if (!sdev->tagged_supported)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 reqtags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 if (reqtags > SYM_CONF_MAX_TAG)
821 reqtags = SYM_CONF_MAX_TAG;
Tony Battersbyc2fd2062009-01-08 12:58:04 -0500822 depth_to_use = reqtags ? reqtags : 1;
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500823 scsi_adjust_queue_depth(sdev,
Matthew Wilcoxa44131b2007-10-05 15:55:08 -0400824 sdev->tagged_supported ? MSG_SIMPLE_TAG : 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 depth_to_use);
826 lp->s.scdev_depth = depth_to_use;
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500827 sym_tune_dev_queuing(tp, sdev->lun, reqtags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500829 if (!spi_initial_dv(sdev->sdev_target))
830 spi_dv_device(sdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
832 return 0;
833}
834
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500835static void sym53c8xx_slave_destroy(struct scsi_device *sdev)
836{
837 struct sym_hcb *np = sym_get_hcb(sdev->host);
Aaro Koskinenfa858452009-04-14 15:47:00 -0500838 struct sym_tcb *tp = &np->target[sdev->id];
839 struct sym_lcb *lp = sym_lp(tp, sdev->lun);
840 unsigned long flags;
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500841
Stratos Psomadakiscced5042011-12-04 02:23:54 +0200842 /* if slave_alloc returned before allocating a sym_lcb, return */
843 if (!lp)
844 return;
845
Aaro Koskinenfa858452009-04-14 15:47:00 -0500846 spin_lock_irqsave(np->s.host->host_lock, flags);
847
848 if (lp->busy_itlq || lp->busy_itl) {
849 /*
850 * This really shouldn't happen, but we can't return an error
851 * so let's try to stop all on-going I/O.
852 */
853 starget_printk(KERN_WARNING, tp->starget,
854 "Removing busy LCB (%d)\n", sdev->lun);
855 sym_reset_scsi_bus(np, 1);
856 }
857
858 if (sym_free_lcb(np, sdev->id, sdev->lun) == 0) {
859 /*
860 * It was the last unit for this target.
861 */
862 tp->head.sval = 0;
863 tp->head.wval = np->rv_scntl3;
864 tp->head.uval = 0;
865 tp->tgoal.check_nego = 1;
866 tp->starget = NULL;
867 }
868
869 spin_unlock_irqrestore(np->s.host->host_lock, flags);
Matthew Wilcox84e203a2005-11-29 23:08:31 -0500870}
871
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872/*
873 * Linux entry point for info() function
874 */
875static const char *sym53c8xx_info (struct Scsi_Host *host)
876{
877 return SYM_DRIVER_NAME;
878}
879
880
881#ifdef SYM_LINUX_PROC_INFO_SUPPORT
882/*
883 * Proc file system stuff
884 *
885 * A read operation returns adapter information.
886 * A write operation is a control command.
887 * The string is parsed in the driver code and the command is passed
888 * to the sym_usercmd() function.
889 */
890
891#ifdef SYM_LINUX_USER_COMMAND_SUPPORT
892
893struct sym_usrcmd {
894 u_long target;
895 u_long lun;
896 u_long data;
897 u_long cmd;
898};
899
900#define UC_SETSYNC 10
901#define UC_SETTAGS 11
902#define UC_SETDEBUG 12
903#define UC_SETWIDE 14
904#define UC_SETFLAG 15
905#define UC_SETVERBOSE 17
906#define UC_RESETDEV 18
907#define UC_CLEARDEV 19
908
909static void sym_exec_user_command (struct sym_hcb *np, struct sym_usrcmd *uc)
910{
911 struct sym_tcb *tp;
912 int t, l;
913
914 switch (uc->cmd) {
915 case 0: return;
916
917#ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
918 case UC_SETDEBUG:
919 sym_debug_flags = uc->data;
920 break;
921#endif
922 case UC_SETVERBOSE:
923 np->verbose = uc->data;
924 break;
925 default:
926 /*
927 * We assume that other commands apply to targets.
928 * This should always be the case and avoid the below
929 * 4 lines to be repeated 6 times.
930 */
931 for (t = 0; t < SYM_CONF_MAX_TARGET; t++) {
932 if (!((uc->target >> t) & 1))
933 continue;
934 tp = &np->target[t];
Aaro Koskinenfa858452009-04-14 15:47:00 -0500935 if (!tp->nlcb)
936 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
938 switch (uc->cmd) {
939
940 case UC_SETSYNC:
941 if (!uc->data || uc->data >= 255) {
942 tp->tgoal.iu = tp->tgoal.dt =
943 tp->tgoal.qas = 0;
944 tp->tgoal.offset = 0;
945 } else if (uc->data <= 9 && np->minsync_dt) {
946 if (uc->data < np->minsync_dt)
947 uc->data = np->minsync_dt;
948 tp->tgoal.iu = tp->tgoal.dt =
949 tp->tgoal.qas = 1;
950 tp->tgoal.width = 1;
951 tp->tgoal.period = uc->data;
952 tp->tgoal.offset = np->maxoffs_dt;
953 } else {
954 if (uc->data < np->minsync)
955 uc->data = np->minsync;
956 tp->tgoal.iu = tp->tgoal.dt =
957 tp->tgoal.qas = 0;
958 tp->tgoal.period = uc->data;
959 tp->tgoal.offset = np->maxoffs;
960 }
961 tp->tgoal.check_nego = 1;
962 break;
963 case UC_SETWIDE:
964 tp->tgoal.width = uc->data ? 1 : 0;
965 tp->tgoal.check_nego = 1;
966 break;
967 case UC_SETTAGS:
968 for (l = 0; l < SYM_CONF_MAX_LUN; l++)
969 sym_tune_dev_queuing(tp, l, uc->data);
970 break;
971 case UC_RESETDEV:
972 tp->to_reset = 1;
973 np->istat_sem = SEM;
974 OUTB(np, nc_istat, SIGP|SEM);
975 break;
976 case UC_CLEARDEV:
977 for (l = 0; l < SYM_CONF_MAX_LUN; l++) {
978 struct sym_lcb *lp = sym_lp(tp, l);
979 if (lp) lp->to_clear = 1;
980 }
981 np->istat_sem = SEM;
982 OUTB(np, nc_istat, SIGP|SEM);
983 break;
984 case UC_SETFLAG:
985 tp->usrflags = uc->data;
986 break;
987 }
988 }
989 break;
990 }
991}
992
Andrew Morton4e62b092009-12-14 18:01:02 -0800993static int sym_skip_spaces(char *ptr, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994{
995 int cnt, c;
996
997 for (cnt = len; cnt > 0 && (c = *ptr++) && isspace(c); cnt--);
998
999 return (len - cnt);
1000}
1001
1002static int get_int_arg(char *ptr, int len, u_long *pv)
1003{
1004 char *end;
1005
1006 *pv = simple_strtoul(ptr, &end, 10);
1007 return (end - ptr);
1008}
1009
1010static int is_keyword(char *ptr, int len, char *verb)
1011{
1012 int verb_len = strlen(verb);
1013
1014 if (len >= verb_len && !memcmp(verb, ptr, verb_len))
1015 return verb_len;
1016 else
1017 return 0;
1018}
1019
1020#define SKIP_SPACES(ptr, len) \
Andrew Morton4e62b092009-12-14 18:01:02 -08001021 if ((arg_len = sym_skip_spaces(ptr, len)) < 1) \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 return -EINVAL; \
1023 ptr += arg_len; len -= arg_len;
1024
1025#define GET_INT_ARG(ptr, len, v) \
1026 if (!(arg_len = get_int_arg(ptr, len, &(v)))) \
1027 return -EINVAL; \
1028 ptr += arg_len; len -= arg_len;
1029
1030
1031/*
1032 * Parse a control command
1033 */
1034
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001035static int sym_user_command(struct Scsi_Host *shost, char *buffer, int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036{
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001037 struct sym_hcb *np = sym_get_hcb(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 char *ptr = buffer;
1039 int len = length;
1040 struct sym_usrcmd cmd, *uc = &cmd;
1041 int arg_len;
1042 u_long target;
1043
1044 memset(uc, 0, sizeof(*uc));
1045
1046 if (len > 0 && ptr[len-1] == '\n')
1047 --len;
1048
1049 if ((arg_len = is_keyword(ptr, len, "setsync")) != 0)
1050 uc->cmd = UC_SETSYNC;
1051 else if ((arg_len = is_keyword(ptr, len, "settags")) != 0)
1052 uc->cmd = UC_SETTAGS;
1053 else if ((arg_len = is_keyword(ptr, len, "setverbose")) != 0)
1054 uc->cmd = UC_SETVERBOSE;
1055 else if ((arg_len = is_keyword(ptr, len, "setwide")) != 0)
1056 uc->cmd = UC_SETWIDE;
1057#ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1058 else if ((arg_len = is_keyword(ptr, len, "setdebug")) != 0)
1059 uc->cmd = UC_SETDEBUG;
1060#endif
1061 else if ((arg_len = is_keyword(ptr, len, "setflag")) != 0)
1062 uc->cmd = UC_SETFLAG;
1063 else if ((arg_len = is_keyword(ptr, len, "resetdev")) != 0)
1064 uc->cmd = UC_RESETDEV;
1065 else if ((arg_len = is_keyword(ptr, len, "cleardev")) != 0)
1066 uc->cmd = UC_CLEARDEV;
1067 else
1068 arg_len = 0;
1069
1070#ifdef DEBUG_PROC_INFO
1071printk("sym_user_command: arg_len=%d, cmd=%ld\n", arg_len, uc->cmd);
1072#endif
1073
1074 if (!arg_len)
1075 return -EINVAL;
1076 ptr += arg_len; len -= arg_len;
1077
1078 switch(uc->cmd) {
1079 case UC_SETSYNC:
1080 case UC_SETTAGS:
1081 case UC_SETWIDE:
1082 case UC_SETFLAG:
1083 case UC_RESETDEV:
1084 case UC_CLEARDEV:
1085 SKIP_SPACES(ptr, len);
1086 if ((arg_len = is_keyword(ptr, len, "all")) != 0) {
1087 ptr += arg_len; len -= arg_len;
1088 uc->target = ~0;
1089 } else {
1090 GET_INT_ARG(ptr, len, target);
1091 uc->target = (1<<target);
1092#ifdef DEBUG_PROC_INFO
1093printk("sym_user_command: target=%ld\n", target);
1094#endif
1095 }
1096 break;
1097 }
1098
1099 switch(uc->cmd) {
1100 case UC_SETVERBOSE:
1101 case UC_SETSYNC:
1102 case UC_SETTAGS:
1103 case UC_SETWIDE:
1104 SKIP_SPACES(ptr, len);
1105 GET_INT_ARG(ptr, len, uc->data);
1106#ifdef DEBUG_PROC_INFO
1107printk("sym_user_command: data=%ld\n", uc->data);
1108#endif
1109 break;
1110#ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1111 case UC_SETDEBUG:
1112 while (len > 0) {
1113 SKIP_SPACES(ptr, len);
1114 if ((arg_len = is_keyword(ptr, len, "alloc")))
1115 uc->data |= DEBUG_ALLOC;
1116 else if ((arg_len = is_keyword(ptr, len, "phase")))
1117 uc->data |= DEBUG_PHASE;
1118 else if ((arg_len = is_keyword(ptr, len, "queue")))
1119 uc->data |= DEBUG_QUEUE;
1120 else if ((arg_len = is_keyword(ptr, len, "result")))
1121 uc->data |= DEBUG_RESULT;
1122 else if ((arg_len = is_keyword(ptr, len, "scatter")))
1123 uc->data |= DEBUG_SCATTER;
1124 else if ((arg_len = is_keyword(ptr, len, "script")))
1125 uc->data |= DEBUG_SCRIPT;
1126 else if ((arg_len = is_keyword(ptr, len, "tiny")))
1127 uc->data |= DEBUG_TINY;
1128 else if ((arg_len = is_keyword(ptr, len, "timing")))
1129 uc->data |= DEBUG_TIMING;
1130 else if ((arg_len = is_keyword(ptr, len, "nego")))
1131 uc->data |= DEBUG_NEGO;
1132 else if ((arg_len = is_keyword(ptr, len, "tags")))
1133 uc->data |= DEBUG_TAGS;
1134 else if ((arg_len = is_keyword(ptr, len, "pointer")))
1135 uc->data |= DEBUG_POINTER;
1136 else
1137 return -EINVAL;
1138 ptr += arg_len; len -= arg_len;
1139 }
1140#ifdef DEBUG_PROC_INFO
1141printk("sym_user_command: data=%ld\n", uc->data);
1142#endif
1143 break;
1144#endif /* SYM_LINUX_DEBUG_CONTROL_SUPPORT */
1145 case UC_SETFLAG:
1146 while (len > 0) {
1147 SKIP_SPACES(ptr, len);
1148 if ((arg_len = is_keyword(ptr, len, "no_disc")))
1149 uc->data &= ~SYM_DISC_ENABLED;
1150 else
1151 return -EINVAL;
1152 ptr += arg_len; len -= arg_len;
1153 }
1154 break;
1155 default:
1156 break;
1157 }
1158
1159 if (len)
1160 return -EINVAL;
1161 else {
1162 unsigned long flags;
1163
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001164 spin_lock_irqsave(shost->host_lock, flags);
1165 sym_exec_user_command(np, uc);
1166 spin_unlock_irqrestore(shost->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 }
1168 return length;
1169}
1170
1171#endif /* SYM_LINUX_USER_COMMAND_SUPPORT */
1172
1173
1174#ifdef SYM_LINUX_USER_INFO_SUPPORT
1175/*
1176 * Informations through the proc file system.
1177 */
1178struct info_str {
1179 char *buffer;
1180 int length;
1181 int offset;
1182 int pos;
1183};
1184
1185static void copy_mem_info(struct info_str *info, char *data, int len)
1186{
1187 if (info->pos + len > info->length)
1188 len = info->length - info->pos;
1189
1190 if (info->pos + len < info->offset) {
1191 info->pos += len;
1192 return;
1193 }
1194 if (info->pos < info->offset) {
1195 data += (info->offset - info->pos);
1196 len -= (info->offset - info->pos);
1197 }
1198
1199 if (len > 0) {
1200 memcpy(info->buffer + info->pos, data, len);
1201 info->pos += len;
1202 }
1203}
1204
1205static int copy_info(struct info_str *info, char *fmt, ...)
1206{
1207 va_list args;
1208 char buf[81];
1209 int len;
1210
1211 va_start(args, fmt);
1212 len = vsprintf(buf, fmt, args);
1213 va_end(args);
1214
1215 copy_mem_info(info, buf, len);
1216 return len;
1217}
1218
1219/*
1220 * Copy formatted information into the input buffer.
1221 */
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001222static int sym_host_info(struct Scsi_Host *shost, char *ptr, off_t offset, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223{
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001224 struct sym_data *sym_data = shost_priv(shost);
1225 struct pci_dev *pdev = sym_data->pdev;
1226 struct sym_hcb *np = sym_data->ncb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 struct info_str info;
1228
1229 info.buffer = ptr;
1230 info.length = len;
1231 info.offset = offset;
1232 info.pos = 0;
1233
1234 copy_info(&info, "Chip " NAME53C "%s, device id 0x%x, "
Matthew Wilcoxbd678452007-10-05 15:55:05 -04001235 "revision id 0x%x\n", np->s.chip_name,
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001236 pdev->device, pdev->revision);
Matthew Wilcox8022fbd2007-10-05 15:55:11 -04001237 copy_info(&info, "At PCI address %s, IRQ %u\n",
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001238 pci_name(pdev), pdev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 copy_info(&info, "Min. period factor %d, %s SCSI BUS%s\n",
1240 (int) (np->minsync_dt ? np->minsync_dt : np->minsync),
1241 np->maxwide ? "Wide" : "Narrow",
1242 np->minsync_dt ? ", DT capable" : "");
1243
1244 copy_info(&info, "Max. started commands %d, "
1245 "max. commands per LUN %d\n",
1246 SYM_CONF_MAX_START, SYM_CONF_MAX_TAG);
1247
1248 return info.pos > info.offset? info.pos - info.offset : 0;
1249}
1250#endif /* SYM_LINUX_USER_INFO_SUPPORT */
1251
1252/*
1253 * Entry point of the scsi proc fs of the driver.
1254 * - func = 0 means read (returns adapter infos)
1255 * - func = 1 means write (not yet merget from sym53c8xx)
1256 */
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001257static int sym53c8xx_proc_info(struct Scsi_Host *shost, char *buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 char **start, off_t offset, int length, int func)
1259{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 int retv;
1261
1262 if (func) {
1263#ifdef SYM_LINUX_USER_COMMAND_SUPPORT
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001264 retv = sym_user_command(shost, buffer, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265#else
1266 retv = -EINVAL;
1267#endif
1268 } else {
1269 if (start)
1270 *start = buffer;
1271#ifdef SYM_LINUX_USER_INFO_SUPPORT
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001272 retv = sym_host_info(shost, buffer, offset, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273#else
1274 retv = -EINVAL;
1275#endif
1276 }
1277
1278 return retv;
1279}
1280#endif /* SYM_LINUX_PROC_INFO_SUPPORT */
1281
1282/*
Tony Battersby783fa732009-01-08 12:56:58 -05001283 * Free resources claimed by sym_iomap_device(). Note that
Tony Battersbya71d0352009-01-08 12:55:52 -05001284 * sym_free_resources() should be used instead of this function after calling
1285 * sym_attach().
1286 */
1287static void __devinit
1288sym_iounmap_device(struct sym_device *device)
1289{
1290 if (device->s.ioaddr)
1291 pci_iounmap(device->pdev, device->s.ioaddr);
1292 if (device->s.ramaddr)
1293 pci_iounmap(device->pdev, device->s.ramaddr);
1294}
1295
1296/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 * Free controller resources.
1298 */
Tony Battersbyb4090632009-01-08 12:54:45 -05001299static void sym_free_resources(struct sym_hcb *np, struct pci_dev *pdev,
1300 int do_free_irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301{
1302 /*
1303 * Free O/S specific resources.
1304 */
Tony Battersbyb4090632009-01-08 12:54:45 -05001305 if (do_free_irq)
Tony Battersby7ee24132007-11-06 14:40:54 -05001306 free_irq(pdev->irq, np->s.host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 if (np->s.ioaddr)
1308 pci_iounmap(pdev, np->s.ioaddr);
1309 if (np->s.ramaddr)
1310 pci_iounmap(pdev, np->s.ramaddr);
1311 /*
1312 * Free O/S independent resources.
1313 */
1314 sym_hcb_free(np);
1315
1316 sym_mfree_dma(np, sizeof(*np), "HCB");
1317}
1318
1319/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 * Host attach and initialisations.
1321 *
1322 * Allocate host data and ncb structure.
1323 * Remap MMIO region.
1324 * Do chip initialization.
1325 * If all is OK, install interrupt handling and
1326 * start the timer daemon.
1327 */
1328static struct Scsi_Host * __devinit sym_attach(struct scsi_host_template *tpnt,
1329 int unit, struct sym_device *dev)
1330{
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001331 struct sym_data *sym_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 struct sym_hcb *np = NULL;
Tony Battersbya71d0352009-01-08 12:55:52 -05001333 struct Scsi_Host *shost = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 struct pci_dev *pdev = dev->pdev;
1335 unsigned long flags;
1336 struct sym_fw *fw;
Tony Battersbyb4090632009-01-08 12:54:45 -05001337 int do_free_irq = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
Matthew Wilcox8022fbd2007-10-05 15:55:11 -04001339 printk(KERN_INFO "sym%d: <%s> rev 0x%x at pci %s irq %u\n",
Matthew Wilcoxbd678452007-10-05 15:55:05 -04001340 unit, dev->chip.name, pdev->revision, pci_name(pdev),
Matthew Wilcox8022fbd2007-10-05 15:55:11 -04001341 pdev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
1343 /*
1344 * Get the firmware for this chip.
1345 */
1346 fw = sym_find_firmware(&dev->chip);
1347 if (!fw)
Tony Battersbya71d0352009-01-08 12:55:52 -05001348 goto attach_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001350 shost = scsi_host_alloc(tpnt, sizeof(*sym_data));
1351 if (!shost)
Tony Battersbya71d0352009-01-08 12:55:52 -05001352 goto attach_failed;
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001353 sym_data = shost_priv(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
1355 /*
1356 * Allocate immediately the host control block,
1357 * since we are only expecting to succeed. :)
1358 * We keep track in the HCB of all the resources that
1359 * are to be released on error.
1360 */
1361 np = __sym_calloc_dma(&pdev->dev, sizeof(*np), "HCB");
1362 if (!np)
1363 goto attach_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 np->bus_dmat = &pdev->dev; /* Result in 1 DMA pool per HBA */
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001365 sym_data->ncb = np;
1366 sym_data->pdev = pdev;
1367 np->s.host = shost;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001369 pci_set_drvdata(pdev, shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370
1371 /*
1372 * Copy some useful infos to the HCB.
1373 */
1374 np->hcb_ba = vtobus(np);
1375 np->verbose = sym_driver_setup.verbose;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 np->s.unit = unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 np->features = dev->chip.features;
1378 np->clock_divn = dev->chip.nr_divisor;
1379 np->maxoffs = dev->chip.offset_max;
1380 np->maxburst = dev->chip.burst_max;
1381 np->myaddr = dev->host_id;
Tony Battersbya71d0352009-01-08 12:55:52 -05001382 np->mmio_ba = (u32)dev->mmio_base;
Tony Battersby783fa732009-01-08 12:56:58 -05001383 np->ram_ba = (u32)dev->ram_base;
Tony Battersbya71d0352009-01-08 12:55:52 -05001384 np->s.ioaddr = dev->s.ioaddr;
1385 np->s.ramaddr = dev->s.ramaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386
1387 /*
1388 * Edit its name.
1389 */
1390 strlcpy(np->s.chip_name, dev->chip.name, sizeof(np->s.chip_name));
1391 sprintf(np->s.inst_name, "sym%d", np->s.unit);
1392
Matthew Wilcox4d85b472007-10-05 15:55:09 -04001393 if ((SYM_CONF_DMA_ADDRESSING_MODE > 0) && (np->features & FE_DAC) &&
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001394 !pci_set_dma_mask(pdev, DMA_DAC_MASK)) {
Matthew Wilcox4d85b472007-10-05 15:55:09 -04001395 set_dac(np);
Yang Hongyang284901a2009-04-06 19:01:15 -07001396 } else if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
Matthew Wilcox4d85b472007-10-05 15:55:09 -04001397 printf_warning("%s: No suitable DMA available\n", sym_name(np));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 goto attach_failed;
Matthew Wilcox4d85b472007-10-05 15:55:09 -04001399 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001401 if (sym_hcb_attach(shost, fw, dev->nvram))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 goto attach_failed;
1403
1404 /*
1405 * Install the interrupt handler.
1406 * If we synchonize the C code with SCRIPTS on interrupt,
1407 * we do not want to share the INTR line at all.
1408 */
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001409 if (request_irq(pdev->irq, sym53c8xx_intr, IRQF_SHARED, NAME53C8XX,
1410 shost)) {
Matthew Wilcox8022fbd2007-10-05 15:55:11 -04001411 printf_err("%s: request irq %u failure\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 sym_name(np), pdev->irq);
1413 goto attach_failed;
1414 }
Tony Battersbyb4090632009-01-08 12:54:45 -05001415 do_free_irq = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416
1417 /*
1418 * After SCSI devices have been opened, we cannot
1419 * reset the bus safely, so we do it here.
1420 */
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001421 spin_lock_irqsave(shost->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 if (sym_reset_scsi_bus(np, 0))
1423 goto reset_failed;
1424
1425 /*
1426 * Start the SCRIPTS.
1427 */
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001428 sym_start_up(shost, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
1430 /*
1431 * Start the timer daemon
1432 */
1433 init_timer(&np->s.timer);
1434 np->s.timer.data = (unsigned long) np;
1435 np->s.timer.function = sym53c8xx_timer;
1436 np->s.lasttime=0;
1437 sym_timer (np);
1438
1439 /*
1440 * Fill Linux host instance structure
1441 * and return success.
1442 */
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001443 shost->max_channel = 0;
1444 shost->this_id = np->myaddr;
1445 shost->max_id = np->maxwide ? 16 : 8;
1446 shost->max_lun = SYM_CONF_MAX_LUN;
1447 shost->unique_id = pci_resource_start(pdev, 0);
1448 shost->cmd_per_lun = SYM_CONF_MAX_TAG;
1449 shost->can_queue = (SYM_CONF_MAX_START-2);
1450 shost->sg_tablesize = SYM_CONF_MAX_SG;
1451 shost->max_cmd_len = 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 BUG_ON(sym2_transport_template == NULL);
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001453 shost->transportt = sym2_transport_template;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454
Kai Makisara34996ac2007-10-05 15:54:58 -04001455 /* 53c896 rev 1 errata: DMA may not cross 16MB boundary */
Matthew Wilcoxbd678452007-10-05 15:55:05 -04001456 if (pdev->device == PCI_DEVICE_ID_NCR_53C896 && pdev->revision < 2)
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001457 shost->dma_boundary = 0xFFFFFF;
Kai Makisara34996ac2007-10-05 15:54:58 -04001458
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001459 spin_unlock_irqrestore(shost->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001461 return shost;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
1463 reset_failed:
1464 printf_err("%s: FATAL ERROR: CHECK SCSI BUS - CABLES, "
1465 "TERMINATION, DEVICE POWER etc.!\n", sym_name(np));
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001466 spin_unlock_irqrestore(shost->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 attach_failed:
Tony Battersby07b9d812009-01-08 12:53:37 -05001468 printf_info("sym%d: giving up ...\n", unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 if (np)
Tony Battersbyb4090632009-01-08 12:54:45 -05001470 sym_free_resources(np, pdev, do_free_irq);
Tony Battersbya71d0352009-01-08 12:55:52 -05001471 else
1472 sym_iounmap_device(dev);
1473 if (shost)
1474 scsi_host_put(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
1476 return NULL;
1477 }
1478
1479
1480/*
1481 * Detect and try to read SYMBIOS and TEKRAM NVRAM.
1482 */
1483#if SYM_CONF_NVRAM_SUPPORT
1484static void __devinit sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
1485{
1486 devp->nvram = nvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 nvp->type = 0;
1488
1489 sym_read_nvram(devp, nvp);
1490}
1491#else
1492static inline void sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
1493{
1494}
1495#endif /* SYM_CONF_NVRAM_SUPPORT */
1496
1497static int __devinit sym_check_supported(struct sym_device *device)
1498{
1499 struct sym_chip *chip;
1500 struct pci_dev *pdev = device->pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 unsigned long io_port = pci_resource_start(pdev, 0);
1502 int i;
1503
1504 /*
1505 * If user excluded this chip, do not initialize it.
1506 * I hate this code so much. Must kill it.
1507 */
1508 if (io_port) {
1509 for (i = 0 ; i < 8 ; i++) {
1510 if (sym_driver_setup.excludes[i] == io_port)
1511 return -ENODEV;
1512 }
1513 }
1514
1515 /*
1516 * Check if the chip is supported. Then copy the chip description
1517 * to our device structure so we can make it match the actual device
1518 * and options.
1519 */
Matthew Wilcoxbd678452007-10-05 15:55:05 -04001520 chip = sym_lookup_chip_table(pdev->device, pdev->revision);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 if (!chip) {
1522 dev_info(&pdev->dev, "device not supported\n");
1523 return -ENODEV;
1524 }
1525 memcpy(&device->chip, chip, sizeof(device->chip));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
1527 return 0;
1528}
1529
1530/*
1531 * Ignore Symbios chips controlled by various RAID controllers.
1532 * These controllers set value 0x52414944 at RAM end - 16.
1533 */
1534static int __devinit sym_check_raid(struct sym_device *device)
1535{
1536 unsigned int ram_size, ram_val;
1537
1538 if (!device->s.ramaddr)
1539 return 0;
1540
1541 if (device->chip.features & FE_RAM8K)
1542 ram_size = 8192;
1543 else
1544 ram_size = 4096;
1545
1546 ram_val = readl(device->s.ramaddr + ram_size - 16);
1547 if (ram_val != 0x52414944)
1548 return 0;
1549
1550 dev_info(&device->pdev->dev,
1551 "not initializing, driven by RAID controller.\n");
1552 return -ENODEV;
1553}
1554
1555static int __devinit sym_set_workarounds(struct sym_device *device)
1556{
1557 struct sym_chip *chip = &device->chip;
1558 struct pci_dev *pdev = device->pdev;
1559 u_short status_reg;
1560
1561 /*
1562 * (ITEM 12 of a DEL about the 896 I haven't yet).
1563 * We must ensure the chip will use WRITE AND INVALIDATE.
1564 * The revision number limit is for now arbitrary.
1565 */
Matthew Wilcoxbd678452007-10-05 15:55:05 -04001566 if (pdev->device == PCI_DEVICE_ID_NCR_53C896 && pdev->revision < 0x4) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 chip->features |= (FE_WRIE | FE_CLSE);
1568 }
1569
1570 /* If the chip can do Memory Write Invalidate, enable it */
1571 if (chip->features & FE_WRIE) {
1572 if (pci_set_mwi(pdev))
1573 return -ENODEV;
1574 }
1575
1576 /*
1577 * Work around for errant bit in 895A. The 66Mhz
1578 * capable bit is set erroneously. Clear this bit.
1579 * (Item 1 DEL 533)
1580 *
1581 * Make sure Config space and Features agree.
1582 *
1583 * Recall: writes are not normal to status register -
1584 * write a 1 to clear and a 0 to leave unchanged.
1585 * Can only reset bits.
1586 */
1587 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1588 if (chip->features & FE_66MHZ) {
1589 if (!(status_reg & PCI_STATUS_66MHZ))
1590 chip->features &= ~FE_66MHZ;
1591 } else {
1592 if (status_reg & PCI_STATUS_66MHZ) {
1593 status_reg = PCI_STATUS_66MHZ;
1594 pci_write_config_word(pdev, PCI_STATUS, status_reg);
1595 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1596 }
1597 }
1598
1599 return 0;
1600}
1601
1602/*
Tony Battersby783fa732009-01-08 12:56:58 -05001603 * Map HBA registers and on-chip SRAM (if present).
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 */
Tony Battersby783fa732009-01-08 12:56:58 -05001605static int __devinit
1606sym_iomap_device(struct sym_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607{
Tony Battersby783fa732009-01-08 12:56:58 -05001608 struct pci_dev *pdev = device->pdev;
Matthew Wilcoxb6d105d2006-03-28 11:03:44 -05001609 struct pci_bus_region bus_addr;
Tony Battersby783fa732009-01-08 12:56:58 -05001610 int i = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
Matthew Wilcoxb6d105d2006-03-28 11:03:44 -05001612 pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[1]);
1613 device->mmio_base = bus_addr.start;
1614
Tony Battersby783fa732009-01-08 12:56:58 -05001615 if (device->chip.features & FE_RAM) {
1616 /*
1617 * If the BAR is 64-bit, resource 2 will be occupied by the
1618 * upper 32 bits
1619 */
1620 if (!pdev->resource[i].flags)
1621 i++;
1622 pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[i]);
1623 device->ram_base = bus_addr.start;
1624 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625
Matthew Wilcox1f61d822006-03-28 11:03:43 -05001626#ifdef CONFIG_SCSI_SYM53C8XX_MMIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 if (device->mmio_base)
1628 device->s.ioaddr = pci_iomap(pdev, 1,
1629 pci_resource_len(pdev, 1));
1630#endif
1631 if (!device->s.ioaddr)
1632 device->s.ioaddr = pci_iomap(pdev, 0,
1633 pci_resource_len(pdev, 0));
Tony Battersby783fa732009-01-08 12:56:58 -05001634 if (!device->s.ioaddr) {
1635 dev_err(&pdev->dev, "could not map registers; giving up.\n");
1636 return -EIO;
1637 }
1638 if (device->ram_base) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 device->s.ramaddr = pci_iomap(pdev, i,
1640 pci_resource_len(pdev, i));
Tony Battersby783fa732009-01-08 12:56:58 -05001641 if (!device->s.ramaddr) {
1642 dev_warn(&pdev->dev,
1643 "could not map SRAM; continuing anyway.\n");
1644 device->ram_base = 0;
1645 }
1646 }
1647
1648 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649}
1650
1651/*
1652 * The NCR PQS and PDS cards are constructed as a DEC bridge
1653 * behind which sits a proprietary NCR memory controller and
1654 * either four or two 53c875s as separate devices. We can tell
1655 * if an 875 is part of a PQS/PDS or not since if it is, it will
1656 * be on the same bus as the memory controller. In its usual
1657 * mode of operation, the 875s are slaved to the memory
1658 * controller for all transfers. To operate with the Linux
1659 * driver, the memory controller is disabled and the 875s
1660 * freed to function independently. The only wrinkle is that
1661 * the preset SCSI ID (which may be zero) must be read in from
1662 * a special configuration space register of the 875.
1663 */
1664static void sym_config_pqs(struct pci_dev *pdev, struct sym_device *sym_dev)
1665{
1666 int slot;
1667 u8 tmp;
1668
1669 for (slot = 0; slot < 256; slot++) {
1670 struct pci_dev *memc = pci_get_slot(pdev->bus, slot);
1671
1672 if (!memc || memc->vendor != 0x101a || memc->device == 0x0009) {
1673 pci_dev_put(memc);
1674 continue;
1675 }
1676
1677 /* bit 1: allow individual 875 configuration */
1678 pci_read_config_byte(memc, 0x44, &tmp);
1679 if ((tmp & 0x2) == 0) {
1680 tmp |= 0x2;
1681 pci_write_config_byte(memc, 0x44, tmp);
1682 }
1683
1684 /* bit 2: drive individual 875 interrupts to the bus */
1685 pci_read_config_byte(memc, 0x45, &tmp);
1686 if ((tmp & 0x4) == 0) {
1687 tmp |= 0x4;
1688 pci_write_config_byte(memc, 0x45, tmp);
1689 }
1690
1691 pci_dev_put(memc);
1692 break;
1693 }
1694
1695 pci_read_config_byte(pdev, 0x84, &tmp);
1696 sym_dev->host_id = tmp;
1697}
1698
1699/*
1700 * Called before unloading the module.
1701 * Detach the host.
1702 * We have to free resources and halt the NCR chip.
1703 */
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001704static int sym_detach(struct Scsi_Host *shost, struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705{
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001706 struct sym_hcb *np = sym_get_hcb(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 printk("%s: detaching ...\n", sym_name(np));
1708
1709 del_timer_sync(&np->s.timer);
1710
1711 /*
1712 * Reset NCR chip.
1713 * We should use sym_soft_reset(), but we don't want to do
1714 * so, since we may not be safe if interrupts occur.
1715 */
1716 printk("%s: resetting chip\n", sym_name(np));
1717 OUTB(np, nc_istat, SRST);
Matthew Wilcox 53222b92005-05-20 19:15:43 +01001718 INB(np, nc_mbox1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 udelay(10);
1720 OUTB(np, nc_istat, 0);
1721
Tony Battersbyb4090632009-01-08 12:54:45 -05001722 sym_free_resources(np, pdev, 1);
Tony Battersbyd3ce65d2009-01-08 12:52:32 -05001723 scsi_host_put(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
1725 return 1;
1726}
1727
1728/*
1729 * Driver host template.
1730 */
1731static struct scsi_host_template sym2_template = {
1732 .module = THIS_MODULE,
1733 .name = "sym53c8xx",
1734 .info = sym53c8xx_info,
1735 .queuecommand = sym53c8xx_queue_command,
1736 .slave_alloc = sym53c8xx_slave_alloc,
1737 .slave_configure = sym53c8xx_slave_configure,
Matthew Wilcox84e203a2005-11-29 23:08:31 -05001738 .slave_destroy = sym53c8xx_slave_destroy,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 .eh_abort_handler = sym53c8xx_eh_abort_handler,
1740 .eh_device_reset_handler = sym53c8xx_eh_device_reset_handler,
1741 .eh_bus_reset_handler = sym53c8xx_eh_bus_reset_handler,
1742 .eh_host_reset_handler = sym53c8xx_eh_host_reset_handler,
1743 .this_id = 7,
Matthew Wilcox14ac8bf2006-03-28 11:03:44 -05001744 .use_clustering = ENABLE_CLUSTERING,
1745 .max_sectors = 0xFFFF,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746#ifdef SYM_LINUX_PROC_INFO_SUPPORT
1747 .proc_info = sym53c8xx_proc_info,
1748 .proc_name = NAME53C8XX,
1749#endif
1750};
1751
1752static int attach_count;
1753
1754static int __devinit sym2_probe(struct pci_dev *pdev,
1755 const struct pci_device_id *ent)
1756{
1757 struct sym_device sym_dev;
1758 struct sym_nvram nvram;
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001759 struct Scsi_Host *shost;
Tony Battersbya71d0352009-01-08 12:55:52 -05001760 int do_iounmap = 0;
1761 int do_disable_device = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762
1763 memset(&sym_dev, 0, sizeof(sym_dev));
1764 memset(&nvram, 0, sizeof(nvram));
Tony Battersby783fa732009-01-08 12:56:58 -05001765 sym_dev.pdev = pdev;
1766 sym_dev.host_id = SYM_SETUP_HOST_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767
1768 if (pci_enable_device(pdev))
1769 goto leave;
1770
1771 pci_set_master(pdev);
1772
1773 if (pci_request_regions(pdev, NAME53C8XX))
1774 goto disable;
1775
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 if (sym_check_supported(&sym_dev))
1777 goto free;
1778
Tony Battersby783fa732009-01-08 12:56:58 -05001779 if (sym_iomap_device(&sym_dev))
1780 goto free;
1781 do_iounmap = 1;
1782
Tony Battersbya71d0352009-01-08 12:55:52 -05001783 if (sym_check_raid(&sym_dev)) {
1784 do_disable_device = 0; /* Don't disable the device */
1785 goto free;
1786 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787
1788 if (sym_set_workarounds(&sym_dev))
1789 goto free;
1790
1791 sym_config_pqs(pdev, &sym_dev);
1792
1793 sym_get_nvram(&sym_dev, &nvram);
1794
Tony Battersbya71d0352009-01-08 12:55:52 -05001795 do_iounmap = 0; /* Don't sym_iounmap_device() after sym_attach(). */
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001796 shost = sym_attach(&sym2_template, attach_count, &sym_dev);
1797 if (!shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 goto free;
1799
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001800 if (scsi_add_host(shost, &pdev->dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 goto detach;
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001802 scsi_scan_host(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803
1804 attach_count++;
1805
1806 return 0;
1807
1808 detach:
1809 sym_detach(pci_get_drvdata(pdev), pdev);
1810 free:
Tony Battersbya71d0352009-01-08 12:55:52 -05001811 if (do_iounmap)
1812 sym_iounmap_device(&sym_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 pci_release_regions(pdev);
1814 disable:
Tony Battersbya71d0352009-01-08 12:55:52 -05001815 if (do_disable_device)
1816 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 leave:
1818 return -ENODEV;
1819}
1820
Randy Dunlap864473b2007-10-29 11:20:40 -07001821static void sym2_remove(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822{
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001823 struct Scsi_Host *shost = pci_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001825 scsi_remove_host(shost);
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001826 sym_detach(shost, pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 pci_release_regions(pdev);
1828 pci_disable_device(pdev);
1829
1830 attach_count--;
1831}
1832
Linas Vepstasd68cd752007-10-05 15:55:04 -04001833/**
1834 * sym2_io_error_detected() - called when PCI error is detected
1835 * @pdev: pointer to PCI device
1836 * @state: current state of the PCI slot
1837 */
1838static pci_ers_result_t sym2_io_error_detected(struct pci_dev *pdev,
1839 enum pci_channel_state state)
1840{
1841 /* If slot is permanently frozen, turn everything off */
1842 if (state == pci_channel_io_perm_failure) {
1843 sym2_remove(pdev);
1844 return PCI_ERS_RESULT_DISCONNECT;
1845 }
1846
1847 disable_irq(pdev->irq);
1848 pci_disable_device(pdev);
1849
1850 /* Request that MMIO be enabled, so register dump can be taken. */
1851 return PCI_ERS_RESULT_CAN_RECOVER;
1852}
1853
1854/**
1855 * sym2_io_slot_dump - Enable MMIO and dump debug registers
1856 * @pdev: pointer to PCI device
1857 */
1858static pci_ers_result_t sym2_io_slot_dump(struct pci_dev *pdev)
1859{
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001860 struct Scsi_Host *shost = pci_get_drvdata(pdev);
Linas Vepstasd68cd752007-10-05 15:55:04 -04001861
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001862 sym_dump_registers(shost);
Linas Vepstasd68cd752007-10-05 15:55:04 -04001863
1864 /* Request a slot reset. */
1865 return PCI_ERS_RESULT_NEED_RESET;
1866}
1867
1868/**
1869 * sym2_reset_workarounds - hardware-specific work-arounds
1870 *
1871 * This routine is similar to sym_set_workarounds(), except
1872 * that, at this point, we already know that the device was
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001873 * successfully initialized at least once before, and so most
Linas Vepstasd68cd752007-10-05 15:55:04 -04001874 * of the steps taken there are un-needed here.
1875 */
1876static void sym2_reset_workarounds(struct pci_dev *pdev)
1877{
Linas Vepstasd68cd752007-10-05 15:55:04 -04001878 u_short status_reg;
1879 struct sym_chip *chip;
1880
Matthew Wilcoxbd678452007-10-05 15:55:05 -04001881 chip = sym_lookup_chip_table(pdev->device, pdev->revision);
Linas Vepstasd68cd752007-10-05 15:55:04 -04001882
1883 /* Work around for errant bit in 895A, in a fashion
1884 * similar to what is done in sym_set_workarounds().
1885 */
1886 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1887 if (!(chip->features & FE_66MHZ) && (status_reg & PCI_STATUS_66MHZ)) {
1888 status_reg = PCI_STATUS_66MHZ;
1889 pci_write_config_word(pdev, PCI_STATUS, status_reg);
1890 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1891 }
1892}
1893
1894/**
1895 * sym2_io_slot_reset() - called when the pci bus has been reset.
1896 * @pdev: pointer to PCI device
1897 *
1898 * Restart the card from scratch.
1899 */
1900static pci_ers_result_t sym2_io_slot_reset(struct pci_dev *pdev)
1901{
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001902 struct Scsi_Host *shost = pci_get_drvdata(pdev);
1903 struct sym_hcb *np = sym_get_hcb(shost);
Linas Vepstasd68cd752007-10-05 15:55:04 -04001904
1905 printk(KERN_INFO "%s: recovering from a PCI slot reset\n",
1906 sym_name(np));
1907
1908 if (pci_enable_device(pdev)) {
1909 printk(KERN_ERR "%s: Unable to enable after PCI reset\n",
1910 sym_name(np));
1911 return PCI_ERS_RESULT_DISCONNECT;
1912 }
1913
1914 pci_set_master(pdev);
1915 enable_irq(pdev->irq);
1916
1917 /* If the chip can do Memory Write Invalidate, enable it */
1918 if (np->features & FE_WRIE) {
1919 if (pci_set_mwi(pdev))
1920 return PCI_ERS_RESULT_DISCONNECT;
1921 }
1922
1923 /* Perform work-arounds, analogous to sym_set_workarounds() */
1924 sym2_reset_workarounds(pdev);
1925
1926 /* Perform host reset only on one instance of the card */
1927 if (PCI_FUNC(pdev->devfn) == 0) {
1928 if (sym_reset_scsi_bus(np, 0)) {
1929 printk(KERN_ERR "%s: Unable to reset scsi host\n",
1930 sym_name(np));
1931 return PCI_ERS_RESULT_DISCONNECT;
1932 }
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001933 sym_start_up(shost, 1);
Linas Vepstasd68cd752007-10-05 15:55:04 -04001934 }
1935
1936 return PCI_ERS_RESULT_RECOVERED;
1937}
1938
1939/**
1940 * sym2_io_resume() - resume normal ops after PCI reset
1941 * @pdev: pointer to PCI device
1942 *
1943 * Called when the error recovery driver tells us that its
1944 * OK to resume normal operation. Use completion to allow
1945 * halted scsi ops to resume.
1946 */
1947static void sym2_io_resume(struct pci_dev *pdev)
1948{
Matthew Wilcox5111eef2007-10-05 15:55:13 -04001949 struct Scsi_Host *shost = pci_get_drvdata(pdev);
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001950 struct sym_data *sym_data = shost_priv(shost);
Linas Vepstasd68cd752007-10-05 15:55:04 -04001951
1952 spin_lock_irq(shost->host_lock);
Matthew Wilcox99c9e0a2007-10-05 15:55:12 -04001953 if (sym_data->io_reset)
1954 complete_all(sym_data->io_reset);
Linas Vepstasd68cd752007-10-05 15:55:04 -04001955 spin_unlock_irq(shost->host_lock);
1956}
1957
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958static void sym2_get_signalling(struct Scsi_Host *shost)
1959{
1960 struct sym_hcb *np = sym_get_hcb(shost);
1961 enum spi_signal_type type;
1962
1963 switch (np->scsi_mode) {
1964 case SMODE_SE:
1965 type = SPI_SIGNAL_SE;
1966 break;
1967 case SMODE_LVD:
1968 type = SPI_SIGNAL_LVD;
1969 break;
1970 case SMODE_HVD:
1971 type = SPI_SIGNAL_HVD;
1972 break;
1973 default:
1974 type = SPI_SIGNAL_UNKNOWN;
1975 break;
1976 }
1977 spi_signalling(shost) = type;
1978}
1979
1980static void sym2_set_offset(struct scsi_target *starget, int offset)
1981{
1982 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1983 struct sym_hcb *np = sym_get_hcb(shost);
1984 struct sym_tcb *tp = &np->target[starget->id];
1985
1986 tp->tgoal.offset = offset;
1987 tp->tgoal.check_nego = 1;
1988}
1989
1990static void sym2_set_period(struct scsi_target *starget, int period)
1991{
1992 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1993 struct sym_hcb *np = sym_get_hcb(shost);
1994 struct sym_tcb *tp = &np->target[starget->id];
1995
James Bottomleye4862fe2005-05-06 13:14:48 -05001996 /* have to have DT for these transfers, but DT will also
1997 * set width, so check that this is allowed */
1998 if (period <= np->minsync && spi_width(starget))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 tp->tgoal.dt = 1;
2000
2001 tp->tgoal.period = period;
2002 tp->tgoal.check_nego = 1;
2003}
2004
2005static void sym2_set_width(struct scsi_target *starget, int width)
2006{
2007 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2008 struct sym_hcb *np = sym_get_hcb(shost);
2009 struct sym_tcb *tp = &np->target[starget->id];
2010
2011 /* It is illegal to have DT set on narrow transfers. If DT is
2012 * clear, we must also clear IU and QAS. */
2013 if (width == 0)
2014 tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
2015
2016 tp->tgoal.width = width;
2017 tp->tgoal.check_nego = 1;
2018}
2019
2020static void sym2_set_dt(struct scsi_target *starget, int dt)
2021{
2022 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2023 struct sym_hcb *np = sym_get_hcb(shost);
2024 struct sym_tcb *tp = &np->target[starget->id];
2025
2026 /* We must clear QAS and IU if DT is clear */
2027 if (dt)
2028 tp->tgoal.dt = 1;
2029 else
2030 tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
2031 tp->tgoal.check_nego = 1;
2032}
2033
Matthew Wilcox8b2f8132005-11-29 23:08:38 -05002034#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035static void sym2_set_iu(struct scsi_target *starget, int iu)
2036{
2037 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2038 struct sym_hcb *np = sym_get_hcb(shost);
2039 struct sym_tcb *tp = &np->target[starget->id];
2040
2041 if (iu)
2042 tp->tgoal.iu = tp->tgoal.dt = 1;
2043 else
2044 tp->tgoal.iu = 0;
2045 tp->tgoal.check_nego = 1;
2046}
2047
2048static void sym2_set_qas(struct scsi_target *starget, int qas)
2049{
2050 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2051 struct sym_hcb *np = sym_get_hcb(shost);
2052 struct sym_tcb *tp = &np->target[starget->id];
2053
2054 if (qas)
2055 tp->tgoal.dt = tp->tgoal.qas = 1;
2056 else
2057 tp->tgoal.qas = 0;
2058 tp->tgoal.check_nego = 1;
2059}
Matthew Wilcox8b2f8132005-11-29 23:08:38 -05002060#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061
2062static struct spi_function_template sym2_transport_functions = {
2063 .set_offset = sym2_set_offset,
2064 .show_offset = 1,
2065 .set_period = sym2_set_period,
2066 .show_period = 1,
2067 .set_width = sym2_set_width,
2068 .show_width = 1,
2069 .set_dt = sym2_set_dt,
2070 .show_dt = 1,
Matthew Wilcox8b2f8132005-11-29 23:08:38 -05002071#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 .set_iu = sym2_set_iu,
2073 .show_iu = 1,
2074 .set_qas = sym2_set_qas,
2075 .show_qas = 1,
Matthew Wilcox8b2f8132005-11-29 23:08:38 -05002076#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 .get_signalling = sym2_get_signalling,
2078};
2079
2080static struct pci_device_id sym2_id_table[] __devinitdata = {
2081 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C810,
2082 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2083 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C820,
2084 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
2085 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C825,
2086 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2087 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C815,
2088 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2089 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C810AP,
2090 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
2091 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C860,
2092 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2093 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1510,
Grant Grundlerb2b3c122006-07-17 07:22:45 -06002094 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SCSI<<8, 0xffff00, 0UL },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C896,
2096 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2097 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C895,
2098 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2099 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C885,
2100 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2101 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875,
2102 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2103 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C1510,
Chip Coldwell147e5052007-05-23 14:41:38 -07002104 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SCSI<<8, 0xffff00, 0UL }, /* new */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C895A,
2106 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2107 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C875A,
2108 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2109 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_33,
2110 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2111 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_66,
2112 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2113 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875J,
2114 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2115 { 0, }
2116};
2117
2118MODULE_DEVICE_TABLE(pci, sym2_id_table);
2119
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07002120static const struct pci_error_handlers sym2_err_handler = {
Linas Vepstasd68cd752007-10-05 15:55:04 -04002121 .error_detected = sym2_io_error_detected,
2122 .mmio_enabled = sym2_io_slot_dump,
2123 .slot_reset = sym2_io_slot_reset,
2124 .resume = sym2_io_resume,
2125};
2126
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127static struct pci_driver sym2_driver = {
2128 .name = NAME53C8XX,
2129 .id_table = sym2_id_table,
2130 .probe = sym2_probe,
Randy Dunlap864473b2007-10-29 11:20:40 -07002131 .remove = sym2_remove,
Linas Vepstasd68cd752007-10-05 15:55:04 -04002132 .err_handler = &sym2_err_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133};
2134
2135static int __init sym2_init(void)
2136{
2137 int error;
2138
2139 sym2_setup_params();
2140 sym2_transport_template = spi_attach_transport(&sym2_transport_functions);
2141 if (!sym2_transport_template)
2142 return -ENODEV;
2143
2144 error = pci_register_driver(&sym2_driver);
2145 if (error)
2146 spi_release_transport(sym2_transport_template);
2147 return error;
2148}
2149
2150static void __exit sym2_exit(void)
2151{
2152 pci_unregister_driver(&sym2_driver);
2153 spi_release_transport(sym2_transport_template);
2154}
2155
2156module_init(sym2_init);
2157module_exit(sym2_exit);