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