132 #include <linux/slab.h>
141 #ifdef CONFIG_AIC7XXX_RESET_DELAY_MS
142 #define AIC7XXX_RESET_DELAY CONFIG_AIC7XXX_RESET_DELAY_MS
144 #define AIC7XXX_RESET_DELAY 5000
153 #ifdef CONFIG_AIC7XXX_PROC_STATS
154 #define AIC7XXX_PROC_STATS
215 #ifdef CONFIG_AIC7XXX_CMDS_PER_DEVICE
216 #define AIC7XXX_CMDS_PER_DEVICE CONFIG_AIC7XXX_CMDS_PER_DEVICE
218 #define AIC7XXX_CMDS_PER_DEVICE AHC_MAX_QUEUE
221 #define AIC7XXX_CONFIGED_TAG_COMMANDS { \
222 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
223 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
224 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
225 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
226 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
227 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
228 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
229 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE \
260 #define DID_UNDERFLOW DID_ERROR
265 printk(
"(scsi%d:%c:%d:%d): ",
302 static uint32_t aic7xxx_pci_parity = ~0;
332 static uint32_t aic7xxx_periodic_otag;
337 static char *aic7xxx =
NULL;
345 "period-delimited options string:\n"
346 " verbose Enable verbose/diagnostic logging\n"
347 " allow_memio Allow device registers to be memory mapped\n"
348 " debug Bitmask of debug values to enable\n"
349 " no_probe Toggle EISA/VLB controller probing\n"
350 " probe_eisa_vl Toggle EISA/VLB controller probing\n"
351 " no_reset Suppress initial bus resets\n"
352 " extended Enable extended geometry on all controllers\n"
353 " periodic_otag Send an ordered tagged transaction\n"
354 " periodically to prevent tag starvation.\n"
355 " This may be required by some older disk\n"
356 " drives or RAID arrays.\n"
357 " tag_info:<tag_str> Set per-target tag depth\n"
358 " global_tag_depth:<int> Global tag depth for every target\n"
360 " seltime:<int> Selection Timeout\n"
361 " (0/256ms,1/128ms,2/64ms,3/32ms)\n"
363 " Sample modprobe configuration file:\n"
364 " # Toggle EISA/VLB probing\n"
365 " # Set tag depth on Controller 1/Target 1 to 10 tags\n"
366 " # Shorten the selection timeout to 128ms\n"
368 " options aic7xxx 'aic7xxx=probe_eisa_vl.tag_info:{{}.{.10}}.seltime:1'\n"
371 static void ahc_linux_handle_scsi_status(
struct ahc_softc *,
374 static void ahc_linux_queue_cmd_complete(
struct ahc_softc *ahc,
376 static void ahc_linux_freeze_simq(
struct ahc_softc *ahc);
377 static void ahc_linux_release_simq(
struct ahc_softc *ahc);
379 static void ahc_linux_initialize_scsi_bus(
struct ahc_softc *ahc);
382 static void ahc_linux_device_queue_depth(
struct scsi_device *);
383 static int ahc_linux_run_command(
struct ahc_softc*,
386 static void ahc_linux_setup_tag_info_global(
char *
p);
387 static int aic7xxx_setup(
char *
s);
389 static int ahc_linux_unit;
443 for (i = 0; i <
count; i++)
457 for (i = 0; i <
count; i++)
462 static void ahc_linux_unmap_scb(
struct ahc_softc*,
struct scb*);
486 panic(
"Too few segs for dma mapping. "
487 "Increase AHC_NSEG\n");
513 ahc = *(
struct ahc_softc **)host->hostdata;
514 memset(bp, 0,
sizeof(buffer));
540 ahc_lock(ahc, &flags);
544 rtn = ahc_linux_run_command(ahc, dev, cmd);
546 ahc_unlock(ahc, &flags);
557 *((
struct ahc_softc **)dev_to_shost(&starget->dev)->hostdata);
558 unsigned int target_offset;
560 target_offset = starget->id;
561 if (starget->channel != 0)
568 ahc_linux_target_alloc(
struct scsi_target *starget)
571 *((
struct ahc_softc **)dev_to_shost(&starget->
dev)->hostdata);
574 struct scsi_target **ahc_targp = ahc_linux_target_in_softc(starget);
575 unsigned short scsirate;
580 unsigned int our_id = ahc->
our_id;
581 unsigned int target_offset;
583 target_offset = starget->
id;
590 ahc_lock(ahc, &flags);
594 *ahc_targp = starget;
608 if(ultra && (flags &
CFXFER) == 0x04) {
614 scsirate = (flags &
CFXFER) | (ultra ? 0x8 : 0);
616 scsirate = (flags &
CFXFER) << 4;
627 starget->
id, &tstate);
636 ahc_unlock(ahc, &flags);
642 ahc_linux_target_destroy(
struct scsi_target *starget)
644 struct scsi_target **ahc_targp = ahc_linux_target_in_softc(starget);
658 printk(
"%s: Slave Alloc %d\n", ahc_name(ahc), sdev->
id);
660 dev = scsi_transport_device_data(sdev);
661 memset(dev, 0,
sizeof(*dev));
682 ahc_linux_slave_configure(
struct scsi_device *sdev)
691 ahc_linux_device_queue_depth(sdev);
700 #if defined(__i386__)
718 channel = sdev_channel(sdev);
723 &geom[2], &geom[0], &geom[1]);
730 cylinders = aic_sector_div(capacity, heads, sectors);
732 if (aic7xxx_extended != 0)
734 else if (channel == 0)
738 if (extended && cylinders >= 1024) {
741 cylinders = aic_sector_div(capacity, heads, sectors);
758 error = ahc_linux_queue_recovery_cmd(cmd,
SCB_ABORT);
760 printk(
"aic7xxx_abort returns 0x%x\n", error);
768 ahc_linux_dev_reset(
struct scsi_cmnd *cmd)
774 printk(
"aic7xxx_dev_reset returns 0x%x\n", error);
782 ahc_linux_bus_reset(
struct scsi_cmnd *cmd)
790 ahc_lock(ahc, &flags);
793 ahc_unlock(ahc, &flags);
796 printk(
"%s: SCSI bus reset delivered. "
797 "%d SCBs aborted.\n", ahc_name(ahc), found);
805 .proc_name =
"aic7xxx",
807 .info = ahc_linux_info,
808 .queuecommand = ahc_linux_queue,
809 .eh_abort_handler = ahc_linux_abort,
810 .eh_device_reset_handler = ahc_linux_dev_reset,
811 .eh_bus_reset_handler = ahc_linux_bus_reset,
812 #if defined(__i386__)
813 .bios_param = ahc_linux_biosparam,
820 .slave_alloc = ahc_linux_slave_alloc,
821 .slave_configure = ahc_linux_slave_configure,
822 .target_alloc = ahc_linux_target_alloc,
823 .target_destroy = ahc_linux_target_destroy,
829 #define BUILD_SCSIID(ahc, cmd) \
830 ((((cmd)->device->id << TID_SHIFT) & TID) \
831 | (((cmd)->device->channel == 0) ? (ahc)->our_id : (ahc)->our_id_b) \
832 | (((cmd)->device->channel == 0) ? 0 : TWIN_CHNLB))
891 void *cb_arg,
int flags)
901 cb(cb_arg, &stack_sg, 1, 0);
918 ahc_linux_setup_tag_info_global(
char *
p)
923 printk(
"Setting Global Tags= %d\n", tags);
925 for (i = 0; i <
ARRAY_SIZE(aic7xxx_tag_info); i++) {
936 if ((instance >= 0) && (targ >= 0)
939 aic7xxx_tag_info[instance].
tag_commands[targ] = value & 0xff;
941 printk(
"tag_info[%d:%d] = %d\n", instance, targ, value);
946 ahc_parse_brace_option(
char *opt_name,
char *opt_arg,
char *
end,
int depth,
956 char tok_list[] = {
'.',
',',
'{',
'}',
'\0'};
969 tok_end =
strchr(opt_arg,
'\0');
975 if (instance == -1) {
982 printk(
"Malformed Option %s\n",
992 else if (instance != -1)
1002 else if (instance >= 0)
1011 for (i = 0; tok_list[
i]; i++) {
1012 tok_end2 =
strchr(opt_arg, tok_list[i]);
1013 if ((tok_end2) && (tok_end2 < tok_end))
1016 callback(callback_arg, instance, targ,
1031 aic7xxx_setup(
char *
s)
1037 static const struct {
1041 {
"extended", &aic7xxx_extended },
1042 {
"no_reset", &aic7xxx_no_reset },
1046 {
"debug", &ahc_debug },
1048 {
"periodic_otag", &aic7xxx_periodic_otag },
1049 {
"pci_parity", &aic7xxx_pci_parity },
1050 {
"seltime", &aic7xxx_seltime },
1051 {
"tag_info",
NULL },
1052 {
"global_tag_depth",
NULL },
1076 if (
strncmp(p,
"global_tag_depth", n) == 0) {
1077 ahc_linux_setup_tag_info_global(p + n);
1078 }
else if (
strncmp(p,
"tag_info", n) == 0) {
1079 s = ahc_parse_brace_option(
"tag_info", p + n, end,
1080 2, ahc_linux_setup_tag_info, 0);
1081 }
else if (p[n] ==
':') {
1083 }
else if (
strncmp(p,
"verbose", n) == 0) {
1092 __setup(
"aic7xxx=", aic7xxx_setup);
1110 *((
struct ahc_softc **)host->hostdata) = ahc;
1123 ahc_unlock(ahc, &s);
1126 if (new_name !=
NULL) {
1131 ahc_linux_initialize_scsi_bus(ahc);
1134 host->
transportt = ahc_linux_transport_template;
1136 retval = scsi_add_host(host,
1154 ahc_linux_initialize_scsi_bus(
struct ahc_softc *ahc)
1165 if (aic7xxx_no_reset != 0)
1188 for (; i < numtarg; i++) {
1205 target_id, &tstate);
1211 ahc_unlock(ahc, &s);
1214 ahc_linux_freeze_simq(ahc);
1216 ahc_linux_release_simq(ahc);
1231 ahc->
seltime = (aic7xxx_seltime & 0x3) << 4;
1232 ahc->
seltime_b = (aic7xxx_seltime & 0x3) << 4;
1233 if (aic7xxx_pci_parity == 0)
1249 if (starget !=
NULL) {
1292 dev = scsi_transport_device_data(sdev);
1308 && (was_queuing != now_queuing)
1318 usertags = ahc_linux_user_tagdepth(ahc, devinfo);
1335 if (aic7xxx_periodic_otag != 0)
1360 scsi_deactivate_tcq(sdev, 2);
1375 static int warned_user;
1381 if (warned_user == 0) {
1384 "aic7xxx: WARNING: Insufficient tag_info instances\n"
1385 "aic7xxx: for installed controllers. Using defaults\n"
1386 "aic7xxx: Please update the aic7xxx_tag_info array in\n"
1387 "aic7xxx: the aic7xxx_osm..c source file.\n");
1394 tag_info = &aic7xxx_tag_info[ahc->
unit];
1407 ahc_linux_device_queue_depth(
struct scsi_device *sdev)
1419 tags = ahc_linux_user_tagdepth(ahc, &devinfo);
1426 printk(
"Tagged Queuing enabled. Depth %d\n", tags);
1443 struct scb_tailq *untagged_q =
NULL;
1459 if (!blk_rq_tagged(cmd->
request)
1463 target_offset = cmd->
device->id + cmd->
device->channel * 8;
1501 if ((tstate->
ultraenb & mask) != 0)
1516 msg_bytes = scsi_populate_tag_msg(cmd, tag_msgs);
1539 ahc_set_residual(scb, 0);
1540 ahc_set_sense_residual(scb, 0);
1561 consumed = ahc_linux_map_seg(ahc, scb,
1583 scb->
hscb->dataptr = 0;
1584 scb->
hscb->datacnt = 0;
1615 ahc_lock(ahc, &flags);
1617 ahc_unlock(ahc, &flags);
1636 struct ahc_linux_target *targ;
1641 unsigned int target_ppr_options;
1650 channel ==
'A' ? ahc->
our_id
1658 if (tinfo->
curr.period != tinfo->
goal.period
1659 || tinfo->
curr.width != tinfo->
goal.width
1660 || tinfo->
curr.offset != tinfo->
goal.offset
1661 || tinfo->
curr.ppr_options != tinfo->
goal.ppr_options)
1673 if (starget ==
NULL)
1675 targ = scsi_transport_target_data(starget);
1677 target_ppr_options =
1685 && tinfo->
curr.ppr_options == target_ppr_options)
1702 channel -
'A', target);
1712 panic(
"ahc_send_async: Unexpected async event");
1727 struct scb_tailq *untagged_q;
1740 printk(
"SCB %d done'd twice\n", scb->
hscb->tag);
1742 panic(
"Stopping for safety");
1752 ahc_linux_unmap_scb(ahc, scb);
1765 ahc_get_transfer_length(scb) - ahc_get_residual(scb);
1768 if ((ahc_debug & AHC_SHOW_MISC) != 0) {
1770 printk(
"Set CAM_UNCOR_PARITY\n");
1774 #ifdef AHC_REPORT_UNDERFLOWS
1784 }
else if (amount_xferred < scb->io_ctx->underflow) {
1793 printk(
"Saw underflow (%ld of %ld bytes). "
1794 "Treated as error\n",
1795 ahc_get_residual(scb),
1796 ahc_get_transfer_length(scb));
1803 ahc_linux_handle_scsi_status(ahc, cmd->
device, scb);
1826 printk(
"Recovery SCB completes\n");
1836 ahc_linux_queue_cmd_complete(ahc, cmd);
1840 ahc_linux_handle_scsi_status(
struct ahc_softc *ahc,
1862 switch (ahc_get_scsi_status(scb)) {
1879 - ahc_get_sense_residual(scb),
1888 if (ahc_debug & AHC_SHOW_SENSE) {
1891 printk(
"Copied %d bytes of sense data:",
1893 for (i = 0; i < sense_size; i++) {
1940 printk(
"Locking max tag count at %d\n",
1980 switch (ahc_cmd_get_transaction_status(cmd)) {
2032 ahc_cmd_set_transaction_status(cmd, new_status);
2039 ahc_linux_freeze_simq(
struct ahc_softc *ahc)
2053 ahc_unlock(ahc, &s);
2057 ahc_linux_release_simq(
struct ahc_softc *ahc)
2068 ahc_unlock(ahc, &s);
2084 struct scb *pending_scb;
2086 u_int active_scb_index;
2095 unsigned long flags;
2103 flag ==
SCB_ABORT ?
"n ABORT" :
" TARGET RESET");
2106 for (cdb_byte = 0; cdb_byte < cmd->
cmd_len; cdb_byte++)
2110 ahc_lock(ahc, &flags);
2119 dev = scsi_transport_device_data(cmd->
device);
2126 printk(
"%s:%d:%d:%d: Is not an active device\n",
2135 cmd->
device->channel +
'A',
2138 printk(
"%s:%d:%d:%d: Command found on untagged queue\n",
2149 if (pending_scb->
io_ctx == cmd)
2165 if (pending_scb ==
NULL) {
2192 printk(
"%s: At time of recovery, card was %spaused\n",
2193 ahc_name(ahc), was_paused ?
"" :
"not ");
2196 disconnected =
TRUE;
2199 cmd->
device->channel +
'A',
2201 pending_scb->
hscb->tag,
2204 printk(
"%s:%d:%d:%d: Cmd aborted from QINFIFO\n",
2205 ahc_name(ahc), cmd->
device->channel,
2211 cmd->
device->channel +
'A',
2215 disconnected =
FALSE;
2219 struct scb *bus_scb;
2222 if (bus_scb == pending_scb)
2223 disconnected =
FALSE;
2225 &&
ahc_inb(ahc, SAVED_SCSIID) == pending_scb->
hscb->scsiid
2227 disconnected =
FALSE;
2241 saved_scsiid =
ahc_inb(ahc, SAVED_SCSIID);
2243 && (pending_scb->
hscb->tag == active_scb_index
2257 }
else if (disconnected) {
2286 cmd->
device->channel +
'A',
2311 cmd->
device->channel +
'A',
2318 printk(
"Device is disconnected, re-queuing SCB\n");
2341 ahc_unlock(ahc, &flags);
2343 printk(
"Recovery code sleeping\n");
2345 ahc_lock(ahc, &flags);
2347 ahc_unlock(ahc, &flags);
2349 printk(
"Timer Expired\n");
2352 printk(
"Recovery code awake\n");
2354 ahc_unlock(ahc, &flags);
2368 unsigned long flags;
2372 ahc_lock(ahc, &flags);
2374 ahc_unlock(ahc, &flags);
2387 unsigned int ppr_options = tinfo->
goal.ppr_options;
2388 unsigned long flags;
2415 ahc_lock(ahc, &flags);
2418 ahc_unlock(ahc, &flags);
2421 static void ahc_linux_set_offset(
struct scsi_target *starget,
int offset)
2423 struct Scsi_Host *shost = dev_to_shost(starget->
dev.parent);
2431 unsigned int ppr_options = 0;
2432 unsigned int period = 0;
2433 unsigned long flags;
2440 period = tinfo->
goal.period;
2441 ppr_options = tinfo->
goal.ppr_options;
2443 ahc_lock(ahc, &flags);
2446 ahc_unlock(ahc, &flags);
2449 static void ahc_linux_set_dt(
struct scsi_target *starget,
int dt)
2451 struct Scsi_Host *shost = dev_to_shost(starget->
dev.parent);
2459 unsigned int ppr_options = tinfo->
goal.ppr_options
2461 unsigned int period = tinfo->
goal.period;
2463 unsigned long flags;
2469 ahc_linux_set_width(starget, 1);
2470 }
else if (period == 9)
2476 ahc_lock(ahc, &flags);
2479 ahc_unlock(ahc, &flags);
2487 static void ahc_linux_set_qas(
struct scsi_target *starget,
int qas)
2489 struct Scsi_Host *shost = dev_to_shost(starget->
dev.parent);
2497 unsigned int ppr_options = tinfo->
goal.ppr_options
2499 unsigned int period = tinfo->
goal.period;
2500 unsigned long flags;
2509 ahc_lock(ahc, &flags);
2512 ahc_unlock(ahc, &flags);
2515 static void ahc_linux_set_iu(
struct scsi_target *starget,
int iu)
2517 struct Scsi_Host *shost = dev_to_shost(starget->
dev.parent);
2525 unsigned int ppr_options = tinfo->
goal.ppr_options
2527 unsigned int period = tinfo->
goal.period;
2528 unsigned long flags;
2537 ahc_lock(ahc, &flags);
2540 ahc_unlock(ahc, &flags);
2544 static void ahc_linux_get_signalling(
struct Scsi_Host *shost)
2547 unsigned long flags;
2559 ahc_lock(ahc, &flags);
2563 ahc_unlock(ahc, &flags);
2574 .set_offset = ahc_linux_set_offset,
2576 .set_period = ahc_linux_set_period,
2578 .set_width = ahc_linux_set_width,
2580 .set_dt = ahc_linux_set_dt,
2583 .set_iu = ahc_linux_set_iu,
2585 .set_qas = ahc_linux_set_qas,
2588 .get_signalling = ahc_linux_get_signalling,
2594 ahc_linux_init(
void)
2600 aic7xxx_setup(aic7xxx);
2602 ahc_linux_transport_template =
2604 if (!ahc_linux_transport_template)
2607 scsi_transport_reserve_device(ahc_linux_transport_template,
2616 ahc_linux_exit(
void)