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