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