Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *  Driver for Adaptec AHA-1542 SCSI host adapters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *  Copyright (C) 1992  Tommy Thorn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *  Copyright (C) 1993, 1994, 1995 Eric Youngdale
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *  Copyright (C) 2015 Ondrej Zary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/isa.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/pnp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <asm/dma.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <scsi/scsi_cmnd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <scsi/scsi_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include "aha1542.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #define MAXBOARDS 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) static bool isapnp = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) module_param(isapnp, bool, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) MODULE_PARM_DESC(isapnp, "enable PnP support (default=1)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) static int io[MAXBOARDS] = { 0x330, 0x334, 0, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) module_param_hw_array(io, int, ioport, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) MODULE_PARM_DESC(io, "base IO address of controller (0x130,0x134,0x230,0x234,0x330,0x334, default=0x330,0x334)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) /* time AHA spends on the AT-bus during data transfer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) static int bus_on[MAXBOARDS] = { -1, -1, -1, -1 }; /* power-on default: 11us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) module_param_array(bus_on, int, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) MODULE_PARM_DESC(bus_on, "bus on time [us] (2-15, default=-1 [HW default: 11])");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) /* time AHA spends off the bus (not to monopolize it) during data transfer  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) static int bus_off[MAXBOARDS] = { -1, -1, -1, -1 }; /* power-on default: 4us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) module_param_array(bus_off, int, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) MODULE_PARM_DESC(bus_off, "bus off time [us] (1-64, default=-1 [HW default: 4])");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) /* default is jumper selected (J1 on 1542A), factory default = 5 MB/s */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) static int dma_speed[MAXBOARDS] = { -1, -1, -1, -1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) module_param_array(dma_speed, int, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) MODULE_PARM_DESC(dma_speed, "DMA speed [MB/s] (5,6,7,8,10, default=-1 [by jumper])");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #define BIOS_TRANSLATION_6432 1	/* Default case these days */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #define BIOS_TRANSLATION_25563 2	/* Big disk case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) struct aha1542_hostdata {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 	/* This will effectively start both of them at the first mailbox */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 	int bios_translation;	/* Mapping bios uses - for compatibility */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 	int aha1542_last_mbi_used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 	int aha1542_last_mbo_used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 	struct scsi_cmnd *int_cmds[AHA1542_MAILBOXES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 	struct mailbox *mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 	dma_addr_t mb_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 	struct ccb *ccb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 	dma_addr_t ccb_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) struct aha1542_cmd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 	struct chain *chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 	dma_addr_t chain_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) static inline void aha1542_intr_reset(u16 base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	outb(IRST, CONTROL(base));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) static inline bool wait_mask(u16 port, u8 mask, u8 allof, u8 noneof, int timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	bool delayed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 	if (timeout == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 		timeout = 3000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 		delayed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 		u8 bits = inb(port) & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 		if ((bits & allof) == allof && ((bits & noneof) == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 		if (delayed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 			mdelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 		if (--timeout == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) static int aha1542_outb(unsigned int base, u8 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	if (!wait_mask(STATUS(base), CDF, 0, CDF, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	outb(val, DATA(base));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) static int aha1542_out(unsigned int base, u8 *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	while (len--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 		if (!wait_mask(STATUS(base), CDF, 0, CDF, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 		outb(*buf++, DATA(base));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	if (!wait_mask(INTRFLAGS(base), INTRMASK, HACC, 0, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) /* Only used at boot time, so we do not need to worry about latency as much
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123)    here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) static int aha1542_in(unsigned int base, u8 *buf, int len, int timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	while (len--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 		if (!wait_mask(STATUS(base), DF, DF, 0, timeout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 		*buf++ = inb(DATA(base));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) static int makecode(unsigned hosterr, unsigned scsierr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	switch (hosterr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	case 0x0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	case 0xa:		/* Linked command complete without error and linked normally */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	case 0xb:		/* Linked command complete without error, interrupt generated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 		hosterr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	case 0x11:		/* Selection time out-The initiator selection or target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 				   reselection was not complete within the SCSI Time out period */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 		hosterr = DID_TIME_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	case 0x12:		/* Data overrun/underrun-The target attempted to transfer more data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 				   than was allocated by the Data Length field or the sum of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 				   Scatter / Gather Data Length fields. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	case 0x13:		/* Unexpected bus free-The target dropped the SCSI BSY at an unexpected time. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	case 0x15:		/* MBO command was not 00, 01 or 02-The first byte of the CB was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 				   invalid. This usually indicates a software failure. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	case 0x16:		/* Invalid CCB Operation Code-The first byte of the CCB was invalid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 				   This usually indicates a software failure. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 	case 0x17:		/* Linked CCB does not have the same LUN-A subsequent CCB of a set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 				   of linked CCB's does not specify the same logical unit number as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 				   the first. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	case 0x18:		/* Invalid Target Direction received from Host-The direction of a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 				   Target Mode CCB was invalid. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	case 0x19:		/* Duplicate CCB Received in Target Mode-More than once CCB was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 				   received to service data transfer between the same target LUN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 				   and initiator SCSI ID in the same direction. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	case 0x1a:		/* Invalid CCB or Segment List Parameter-A segment list with a zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 				   length segment or invalid segment list boundaries was received.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 				   A CCB parameter was invalid. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 		printk("Aha1542: %x %x\n", hosterr, scsierr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 		hosterr = DID_ERROR;	/* Couldn't find any better */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	case 0x14:		/* Target bus phase sequence failure-An invalid bus phase or bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 				   phase sequence was requested by the target. The host adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 				   will generate a SCSI Reset Condition, notifying the host with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 				   a SCRD interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 		hosterr = DID_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 		printk(KERN_ERR "aha1542: makecode: unknown hoststatus %x\n", hosterr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	return scsierr | (hosterr << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) static int aha1542_test_port(struct Scsi_Host *sh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	u8 inquiry_result[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	/* Quick and dirty test for presence of the card. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	if (inb(STATUS(sh->io_port)) == 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	/* Reset the adapter. I ought to make a hard reset, but it's not really necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	/* In case some other card was probing here, reset interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	aha1542_intr_reset(sh->io_port);	/* reset interrupts, so they don't block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	outb(SRST | IRST /*|SCRST */ , CONTROL(sh->io_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	mdelay(20);		/* Wait a little bit for things to settle down. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	/* Expect INIT and IDLE, any of the others are bad */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	if (!wait_mask(STATUS(sh->io_port), STATMASK, INIT | IDLE, STST | DIAGF | INVDCMD | DF | CDF, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	/* Shouldn't have generated any interrupts during reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	if (inb(INTRFLAGS(sh->io_port)) & INTRMASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	/* Perform a host adapter inquiry instead so we do not need to set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	   up the mailboxes ahead of time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	aha1542_outb(sh->io_port, CMD_INQUIRY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	for (i = 0; i < 4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 		if (!wait_mask(STATUS(sh->io_port), DF, DF, 0, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 		inquiry_result[i] = inb(DATA(sh->io_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	/* Reading port should reset DF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	if (inb(STATUS(sh->io_port)) & DF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	/* When HACC, command is completed, and we're though testing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	if (!wait_mask(INTRFLAGS(sh->io_port), HACC, HACC, 0, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	/* Clear interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	outb(IRST, CONTROL(sh->io_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) static void aha1542_free_cmd(struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	struct aha1542_cmd *acmd = scsi_cmd_priv(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	struct device *dev = cmd->device->host->dma_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	size_t len = scsi_sg_count(cmd) * sizeof(struct chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	if (acmd->chain) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 		dma_unmap_single(dev, acmd->chain_handle, len, DMA_TO_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 		kfree(acmd->chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	acmd->chain = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	scsi_dma_unmap(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) static irqreturn_t aha1542_interrupt(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	struct Scsi_Host *sh = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	struct aha1542_hostdata *aha1542 = shost_priv(sh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	void (*my_done)(struct scsi_cmnd *) = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	int errstatus, mbi, mbo, mbistatus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	int number_serviced;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	struct scsi_cmnd *tmp_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	int flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	struct mailbox *mb = aha1542->mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	struct ccb *ccb = aha1542->ccb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 		flag = inb(INTRFLAGS(sh->io_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 		shost_printk(KERN_DEBUG, sh, "aha1542_intr_handle: ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 		if (!(flag & ANYINTR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 			printk("no interrupt?");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 		if (flag & MBIF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 			printk("MBIF ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 		if (flag & MBOA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 			printk("MBOF ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 		if (flag & HACC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 			printk("HACC ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 		if (flag & SCRD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 			printk("SCRD ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 		printk("status %02x\n", inb(STATUS(sh->io_port)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	number_serviced = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	spin_lock_irqsave(sh->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 		flag = inb(INTRFLAGS(sh->io_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 		/* Check for unusual interrupts.  If any of these happen, we should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 		   probably do something special, but for now just printing a message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 		   is sufficient.  A SCSI reset detected is something that we really
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 		   need to deal with in some way. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 		if (flag & ~MBIF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 			if (flag & MBOA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 				printk("MBOF ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 			if (flag & HACC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 				printk("HACC ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 			if (flag & SCRD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 				printk("SCRD ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 		aha1542_intr_reset(sh->io_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 		mbi = aha1542->aha1542_last_mbi_used + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 		if (mbi >= 2 * AHA1542_MAILBOXES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 			mbi = AHA1542_MAILBOXES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 		do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 			if (mb[mbi].status != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 			mbi++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 			if (mbi >= 2 * AHA1542_MAILBOXES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 				mbi = AHA1542_MAILBOXES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 		} while (mbi != aha1542->aha1542_last_mbi_used);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		if (mb[mbi].status == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 			spin_unlock_irqrestore(sh->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 			/* Hmm, no mail.  Must have read it the last time around */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 			if (!number_serviced)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 				shost_printk(KERN_WARNING, sh, "interrupt received, but no mail.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 			return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 		mbo = (scsi2int(mb[mbi].ccbptr) - (unsigned long)aha1542->ccb_handle) / sizeof(struct ccb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 		mbistatus = mb[mbi].status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 		mb[mbi].status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 		aha1542->aha1542_last_mbi_used = mbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 		if (ccb[mbo].tarstat | ccb[mbo].hastat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 			shost_printk(KERN_DEBUG, sh, "aha1542_command: returning %x (status %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 			       ccb[mbo].tarstat + ((int) ccb[mbo].hastat << 16), mb[mbi].status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 		if (mbistatus == 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 			continue;	/* Aborted command not found */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 		shost_printk(KERN_DEBUG, sh, "...done %d %d\n", mbo, mbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 		tmp_cmd = aha1542->int_cmds[mbo];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 		if (!tmp_cmd || !tmp_cmd->scsi_done) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 			spin_unlock_irqrestore(sh->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 			shost_printk(KERN_WARNING, sh, "Unexpected interrupt\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 			shost_printk(KERN_WARNING, sh, "tarstat=%x, hastat=%x idlun=%x ccb#=%d\n", ccb[mbo].tarstat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 			       ccb[mbo].hastat, ccb[mbo].idlun, mbo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 			return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 		my_done = tmp_cmd->scsi_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 		aha1542_free_cmd(tmp_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 		/* Fetch the sense data, and tuck it away, in the required slot.  The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 		   Adaptec automatically fetches it, and there is no guarantee that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 		   we will still have it in the cdb when we come back */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 		if (ccb[mbo].tarstat == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 			memcpy(tmp_cmd->sense_buffer, &ccb[mbo].cdb[ccb[mbo].cdblen],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 			       SCSI_SENSE_BUFFERSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 		/* is there mail :-) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 		/* more error checking left out here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 		if (mbistatus != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 			/* This is surely wrong, but I don't know what's right */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 			errstatus = makecode(ccb[mbo].hastat, ccb[mbo].tarstat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 			errstatus = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 		if (errstatus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 			shost_printk(KERN_DEBUG, sh, "(aha1542 error:%x %x %x) ", errstatus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 			       ccb[mbo].hastat, ccb[mbo].tarstat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 		if (ccb[mbo].tarstat == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 			print_hex_dump_bytes("sense: ", DUMP_PREFIX_NONE, &ccb[mbo].cdb[ccb[mbo].cdblen], 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 		if (errstatus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 			printk("aha1542_intr_handle: returning %6x\n", errstatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		tmp_cmd->result = errstatus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 		aha1542->int_cmds[mbo] = NULL;	/* This effectively frees up the mailbox slot, as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 						   far as queuecommand is concerned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 		my_done(tmp_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 		number_serviced++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) static int aha1542_queuecommand(struct Scsi_Host *sh, struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	struct aha1542_cmd *acmd = scsi_cmd_priv(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	struct aha1542_hostdata *aha1542 = shost_priv(sh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	u8 direction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	u8 target = cmd->device->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	u8 lun = cmd->device->lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	int bufflen = scsi_bufflen(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	int mbo, sg_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	struct mailbox *mb = aha1542->mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	struct ccb *ccb = aha1542->ccb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	if (*cmd->cmnd == REQUEST_SENSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		/* Don't do the command - we have the sense data already */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 		cmd->result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		cmd->scsi_done(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 		int i = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 		if (*cmd->cmnd == READ_10 || *cmd->cmnd == WRITE_10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 			i = xscsi2int(cmd->cmnd + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 		else if (*cmd->cmnd == READ_6 || *cmd->cmnd == WRITE_6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 			i = scsi2int(cmd->cmnd + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 		shost_printk(KERN_DEBUG, sh, "aha1542_queuecommand: dev %d cmd %02x pos %d len %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 						target, *cmd->cmnd, i, bufflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 		print_hex_dump_bytes("command: ", DUMP_PREFIX_NONE, cmd->cmnd, cmd->cmd_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	sg_count = scsi_dma_map(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	if (sg_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 		size_t len = sg_count * sizeof(struct chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 		acmd->chain = kmalloc(len, GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 		if (!acmd->chain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 			goto out_unmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 		acmd->chain_handle = dma_map_single(sh->dma_dev, acmd->chain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 				len, DMA_TO_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 		if (dma_mapping_error(sh->dma_dev, acmd->chain_handle))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 			goto out_free_chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	/* Use the outgoing mailboxes in a round-robin fashion, because this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	   is how the host adapter will scan for them */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	spin_lock_irqsave(sh->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	mbo = aha1542->aha1542_last_mbo_used + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	if (mbo >= AHA1542_MAILBOXES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 		mbo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 		if (mb[mbo].status == 0 && aha1542->int_cmds[mbo] == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 		mbo++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		if (mbo >= AHA1542_MAILBOXES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 			mbo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	} while (mbo != aha1542->aha1542_last_mbo_used);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	if (mb[mbo].status || aha1542->int_cmds[mbo])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 		panic("Unable to find empty mailbox for aha1542.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	aha1542->int_cmds[mbo] = cmd;	/* This will effectively prevent someone else from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 					   screwing with this cdb. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	aha1542->aha1542_last_mbo_used = mbo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	shost_printk(KERN_DEBUG, sh, "Sending command (%d %p)...", mbo, cmd->scsi_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	/* This gets trashed for some reason */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	any2scsi(mb[mbo].ccbptr, aha1542->ccb_handle + mbo * sizeof(*ccb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	memset(&ccb[mbo], 0, sizeof(struct ccb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	ccb[mbo].cdblen = cmd->cmd_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	direction = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	if (*cmd->cmnd == READ_10 || *cmd->cmnd == READ_6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 		direction = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	else if (*cmd->cmnd == WRITE_10 || *cmd->cmnd == WRITE_6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 		direction = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	memcpy(ccb[mbo].cdb, cmd->cmnd, ccb[mbo].cdblen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	if (bufflen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 		struct scatterlist *sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 		ccb[mbo].op = 2;	/* SCSI Initiator Command  w/scatter-gather */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 		scsi_for_each_sg(cmd, sg, sg_count, i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 			any2scsi(acmd->chain[i].dataptr, sg_dma_address(sg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 			any2scsi(acmd->chain[i].datalen, sg_dma_len(sg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 		any2scsi(ccb[mbo].datalen, sg_count * sizeof(struct chain));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 		any2scsi(ccb[mbo].dataptr, acmd->chain_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 		shost_printk(KERN_DEBUG, sh, "cptr %p: ", acmd->chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 		print_hex_dump_bytes("cptr: ", DUMP_PREFIX_NONE, acmd->chain, 18);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 		ccb[mbo].op = 0;	/* SCSI Initiator Command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 		any2scsi(ccb[mbo].datalen, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 		any2scsi(ccb[mbo].dataptr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	ccb[mbo].idlun = (target & 7) << 5 | direction | (lun & 7);	/*SCSI Target Id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	ccb[mbo].rsalen = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	ccb[mbo].linkptr[0] = ccb[mbo].linkptr[1] = ccb[mbo].linkptr[2] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	ccb[mbo].commlinkid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	print_hex_dump_bytes("sending: ", DUMP_PREFIX_NONE, &ccb[mbo], sizeof(ccb[mbo]) - 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	printk("aha1542_queuecommand: now waiting for interrupt ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	mb[mbo].status = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	aha1542_outb(cmd->device->host->io_port, CMD_START_SCSI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	spin_unlock_irqrestore(sh->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) out_free_chain:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	kfree(acmd->chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	acmd->chain = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) out_unmap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	scsi_dma_unmap(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	return SCSI_MLQUEUE_HOST_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) /* Initialize mailboxes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) static void setup_mailboxes(struct Scsi_Host *sh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	struct aha1542_hostdata *aha1542 = shost_priv(sh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	u8 mb_cmd[5] = { CMD_MBINIT, AHA1542_MAILBOXES, 0, 0, 0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	for (i = 0; i < AHA1542_MAILBOXES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 		aha1542->mb[i].status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 		any2scsi(aha1542->mb[i].ccbptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 			 aha1542->ccb_handle + i * sizeof(struct ccb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 		aha1542->mb[AHA1542_MAILBOXES + i].status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	aha1542_intr_reset(sh->io_port);	/* reset interrupts, so they don't block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	any2scsi(mb_cmd + 2, aha1542->mb_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	if (aha1542_out(sh->io_port, mb_cmd, 5))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 		shost_printk(KERN_ERR, sh, "failed setting up mailboxes\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	aha1542_intr_reset(sh->io_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) static int aha1542_getconfig(struct Scsi_Host *sh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 	u8 inquiry_result[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	i = inb(STATUS(sh->io_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	if (i & DF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 		i = inb(DATA(sh->io_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	aha1542_outb(sh->io_port, CMD_RETCONF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	aha1542_in(sh->io_port, inquiry_result, 3, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	if (!wait_mask(INTRFLAGS(sh->io_port), INTRMASK, HACC, 0, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 		shost_printk(KERN_ERR, sh, "error querying board settings\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	aha1542_intr_reset(sh->io_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	switch (inquiry_result[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	case 0x80:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 		sh->dma_channel = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	case 0x40:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 		sh->dma_channel = 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	case 0x20:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 		sh->dma_channel = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	case 0x01:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 		sh->dma_channel = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 		/* This means that the adapter, although Adaptec 1542 compatible, doesn't use a DMA channel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 		   Currently only aware of the BusLogic BT-445S VL-Bus adapter which needs this. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 		sh->dma_channel = 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 		shost_printk(KERN_ERR, sh, "Unable to determine DMA channel.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	switch (inquiry_result[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	case 0x40:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 		sh->irq = 15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	case 0x20:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 		sh->irq = 14;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	case 0x8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 		sh->irq = 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	case 0x4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 		sh->irq = 11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	case 0x2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 		sh->irq = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	case 0x1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 		sh->irq = 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 		shost_printk(KERN_ERR, sh, "Unable to determine IRQ level.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	sh->this_id = inquiry_result[2] & 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) /* This function should only be called for 1542C boards - we can detect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604)    the special firmware settings and unlock the board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) static int aha1542_mbenable(struct Scsi_Host *sh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	static u8 mbenable_cmd[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	static u8 mbenable_result[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	retval = BIOS_TRANSLATION_6432;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	aha1542_outb(sh->io_port, CMD_EXTBIOS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	if (aha1542_in(sh->io_port, mbenable_result, 2, 100))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	if (!wait_mask(INTRFLAGS(sh->io_port), INTRMASK, HACC, 0, 100))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	aha1542_intr_reset(sh->io_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	if ((mbenable_result[0] & 0x08) || mbenable_result[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 		mbenable_cmd[0] = CMD_MBENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 		mbenable_cmd[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 		mbenable_cmd[2] = mbenable_result[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 		if ((mbenable_result[0] & 0x08) && (mbenable_result[1] & 0x03))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 			retval = BIOS_TRANSLATION_25563;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 		if (aha1542_out(sh->io_port, mbenable_cmd, 3))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	while (0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 		shost_printk(KERN_ERR, sh, "Mailbox init failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	aha1542_intr_reset(sh->io_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) /* Query the board to find out if it is a 1542 or a 1740, or whatever. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) static int aha1542_query(struct Scsi_Host *sh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	struct aha1542_hostdata *aha1542 = shost_priv(sh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	u8 inquiry_result[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	i = inb(STATUS(sh->io_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	if (i & DF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 		i = inb(DATA(sh->io_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	aha1542_outb(sh->io_port, CMD_INQUIRY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	aha1542_in(sh->io_port, inquiry_result, 4, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	if (!wait_mask(INTRFLAGS(sh->io_port), INTRMASK, HACC, 0, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 		shost_printk(KERN_ERR, sh, "error querying card type\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	aha1542_intr_reset(sh->io_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	aha1542->bios_translation = BIOS_TRANSLATION_6432;	/* Default case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	/* For an AHA1740 series board, we ignore the board since there is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	   hardware bug which can lead to wrong blocks being returned if the board
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	   is operating in the 1542 emulation mode.  Since there is an extended mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	   driver, we simply ignore the board and let the 1740 driver pick it up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	if (inquiry_result[0] == 0x43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 		shost_printk(KERN_INFO, sh, "Emulation mode not supported for AHA-1740 hardware, use aha1740 driver instead.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	/* Always call this - boards that do not support extended bios translation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	   will ignore the command, and we will set the proper default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	aha1542->bios_translation = aha1542_mbenable(sh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) static u8 dma_speed_hw(int dma_speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	switch (dma_speed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	case 5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 		return 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	case 6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 		return 0x04;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	case 7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 		return 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	case 8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 		return 0x02;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	case 10:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 		return 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 	return 0xff;	/* invalid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) /* Set the Bus on/off-times as not to ruin floppy performance */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) static void aha1542_set_bus_times(struct Scsi_Host *sh, int bus_on, int bus_off, int dma_speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	if (bus_on > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 		u8 oncmd[] = { CMD_BUSON_TIME, clamp(bus_on, 2, 15) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 		aha1542_intr_reset(sh->io_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 		if (aha1542_out(sh->io_port, oncmd, 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	if (bus_off > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 		u8 offcmd[] = { CMD_BUSOFF_TIME, clamp(bus_off, 1, 64) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 		aha1542_intr_reset(sh->io_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 		if (aha1542_out(sh->io_port, offcmd, 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	if (dma_speed_hw(dma_speed) != 0xff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 		u8 dmacmd[] = { CMD_DMASPEED, dma_speed_hw(dma_speed) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 		aha1542_intr_reset(sh->io_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 		if (aha1542_out(sh->io_port, dmacmd, 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	aha1542_intr_reset(sh->io_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	shost_printk(KERN_ERR, sh, "setting bus on/off-time failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	aha1542_intr_reset(sh->io_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) /* return non-zero on detection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) static struct Scsi_Host *aha1542_hw_init(struct scsi_host_template *tpnt, struct device *pdev, int indx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	unsigned int base_io = io[indx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	struct Scsi_Host *sh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	struct aha1542_hostdata *aha1542;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	char dma_info[] = "no DMA";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	if (base_io == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	if (!request_region(base_io, AHA1542_REGION_SIZE, "aha1542"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	sh = scsi_host_alloc(tpnt, sizeof(struct aha1542_hostdata));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	if (!sh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 		goto release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	aha1542 = shost_priv(sh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	sh->unique_id = base_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	sh->io_port = base_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	sh->n_io_port = AHA1542_REGION_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	aha1542->aha1542_last_mbi_used = 2 * AHA1542_MAILBOXES - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	aha1542->aha1542_last_mbo_used = AHA1542_MAILBOXES - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	if (!aha1542_test_port(sh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 		goto unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	aha1542_set_bus_times(sh, bus_on[indx], bus_off[indx], dma_speed[indx]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	if (aha1542_query(sh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 		goto unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	if (aha1542_getconfig(sh) == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 		goto unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	if (sh->dma_channel != 0xFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 		snprintf(dma_info, sizeof(dma_info), "DMA %d", sh->dma_channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	shost_printk(KERN_INFO, sh, "Adaptec AHA-1542 (SCSI-ID %d) at IO 0x%x, IRQ %d, %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 				sh->this_id, base_io, sh->irq, dma_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	if (aha1542->bios_translation == BIOS_TRANSLATION_25563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 		shost_printk(KERN_INFO, sh, "Using extended bios translation\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	if (dma_set_mask_and_coherent(pdev, DMA_BIT_MASK(24)) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 		goto unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	aha1542->mb = dma_alloc_coherent(pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 			AHA1542_MAILBOXES * 2 * sizeof(struct mailbox),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 			&aha1542->mb_handle, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	if (!aha1542->mb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 		goto unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	aha1542->ccb = dma_alloc_coherent(pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 			AHA1542_MAILBOXES * sizeof(struct ccb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 			&aha1542->ccb_handle, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	if (!aha1542->ccb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 		goto free_mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	setup_mailboxes(sh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	if (request_irq(sh->irq, aha1542_interrupt, 0, "aha1542", sh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 		shost_printk(KERN_ERR, sh, "Unable to allocate IRQ.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 		goto free_ccb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	if (sh->dma_channel != 0xFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 		if (request_dma(sh->dma_channel, "aha1542")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 			shost_printk(KERN_ERR, sh, "Unable to allocate DMA channel.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 			goto free_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 		if (sh->dma_channel == 0 || sh->dma_channel >= 5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 			set_dma_mode(sh->dma_channel, DMA_MODE_CASCADE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 			enable_dma(sh->dma_channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	if (scsi_add_host(sh, pdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 		goto free_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	scsi_scan_host(sh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	return sh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) free_dma:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	if (sh->dma_channel != 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 		free_dma(sh->dma_channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) free_irq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	free_irq(sh->irq, sh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) free_ccb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	dma_free_coherent(pdev, AHA1542_MAILBOXES * sizeof(struct ccb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 			  aha1542->ccb, aha1542->ccb_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) free_mb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 	dma_free_coherent(pdev, AHA1542_MAILBOXES * 2 * sizeof(struct mailbox),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 			  aha1542->mb, aha1542->mb_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) unregister:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	scsi_host_put(sh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	release_region(base_io, AHA1542_REGION_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) static int aha1542_release(struct Scsi_Host *sh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	struct aha1542_hostdata *aha1542 = shost_priv(sh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	struct device *dev = sh->dma_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	scsi_remove_host(sh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	if (sh->dma_channel != 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 		free_dma(sh->dma_channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	dma_free_coherent(dev, AHA1542_MAILBOXES * sizeof(struct ccb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 			  aha1542->ccb, aha1542->ccb_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	dma_free_coherent(dev, AHA1542_MAILBOXES * 2 * sizeof(struct mailbox),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 			  aha1542->mb, aha1542->mb_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	if (sh->irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 		free_irq(sh->irq, sh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	if (sh->io_port && sh->n_io_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 		release_region(sh->io_port, sh->n_io_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	scsi_host_put(sh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849)  * This is a device reset.  This is handled by sending a special command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850)  * to the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) static int aha1542_dev_reset(struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	struct Scsi_Host *sh = cmd->device->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	struct aha1542_hostdata *aha1542 = shost_priv(sh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	struct mailbox *mb = aha1542->mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	u8 target = cmd->device->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	u8 lun = cmd->device->lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	int mbo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	struct ccb *ccb = aha1542->ccb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	spin_lock_irqsave(sh->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	mbo = aha1542->aha1542_last_mbo_used + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	if (mbo >= AHA1542_MAILBOXES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 		mbo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 		if (mb[mbo].status == 0 && aha1542->int_cmds[mbo] == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 		mbo++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 		if (mbo >= AHA1542_MAILBOXES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 			mbo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	} while (mbo != aha1542->aha1542_last_mbo_used);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	if (mb[mbo].status || aha1542->int_cmds[mbo])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 		panic("Unable to find empty mailbox for aha1542.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	aha1542->int_cmds[mbo] = cmd;	/* This will effectively
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 					   prevent someone else from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 					   screwing with this cdb. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	aha1542->aha1542_last_mbo_used = mbo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	/* This gets trashed for some reason */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	any2scsi(mb[mbo].ccbptr, aha1542->ccb_handle + mbo * sizeof(*ccb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	memset(&ccb[mbo], 0, sizeof(struct ccb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	ccb[mbo].op = 0x81;	/* BUS DEVICE RESET */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	ccb[mbo].idlun = (target & 7) << 5 | (lun & 7);		/*SCSI Target Id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	ccb[mbo].linkptr[0] = ccb[mbo].linkptr[1] = ccb[mbo].linkptr[2] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	ccb[mbo].commlinkid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	/* 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	 * Now tell the 1542 to flush all pending commands for this 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	 * target 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	aha1542_outb(sh->io_port, CMD_START_SCSI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	spin_unlock_irqrestore(sh->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	scmd_printk(KERN_WARNING, cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 		"Trying device reset for target\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	return SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) static int aha1542_reset(struct scsi_cmnd *cmd, u8 reset_cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	struct Scsi_Host *sh = cmd->device->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	struct aha1542_hostdata *aha1542 = shost_priv(sh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	spin_lock_irqsave(sh->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	/* 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	 * This does a scsi reset for all devices on the bus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	 * In principle, we could also reset the 1542 - should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	 * we do this?  Try this first, and we can add that later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	 * if it turns out to be useful.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	outb(reset_cmd, CONTROL(cmd->device->host->io_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	if (!wait_mask(STATUS(cmd->device->host->io_port),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	     STATMASK, IDLE, STST | DIAGF | INVDCMD | DF | CDF, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 		spin_unlock_irqrestore(sh->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 		return FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	 * We need to do this too before the 1542 can interact with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	 * us again after host reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	if (reset_cmd & HRST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 		setup_mailboxes(cmd->device->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	 * Now try to pick up the pieces.  For all pending commands,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	 * free any internal data structures, and basically clear things
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	 * out.  We do not try and restart any commands or anything - 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	 * the strategy handler takes care of that crap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	shost_printk(KERN_WARNING, cmd->device->host, "Sent BUS RESET to scsi host %d\n", cmd->device->host->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	for (i = 0; i < AHA1542_MAILBOXES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 		if (aha1542->int_cmds[i] != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 			struct scsi_cmnd *tmp_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 			tmp_cmd = aha1542->int_cmds[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 			if (tmp_cmd->device->soft_reset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 				 * If this device implements the soft reset option,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 				 * then it is still holding onto the command, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 				 * may yet complete it.  In this case, we don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 				 * flush the data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 			aha1542_free_cmd(tmp_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 			aha1542->int_cmds[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 			aha1542->mb[i].status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	spin_unlock_irqrestore(sh->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	return SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) static int aha1542_bus_reset(struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	return aha1542_reset(cmd, SCRST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) static int aha1542_host_reset(struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	return aha1542_reset(cmd, HRST | SCRST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) static int aha1542_biosparam(struct scsi_device *sdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 		struct block_device *bdev, sector_t capacity, int geom[])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	struct aha1542_hostdata *aha1542 = shost_priv(sdev->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	if (capacity >= 0x200000 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 			aha1542->bios_translation == BIOS_TRANSLATION_25563) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 		/* Please verify that this is the same as what DOS returns */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 		geom[0] = 255;	/* heads */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 		geom[1] = 63;	/* sectors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 		geom[0] = 64;	/* heads */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 		geom[1] = 32;	/* sectors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	geom[2] = sector_div(capacity, geom[0] * geom[1]);	/* cylinders */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) static struct scsi_host_template driver_template = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	.module			= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	.proc_name		= "aha1542",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	.name			= "Adaptec 1542",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	.cmd_size		= sizeof(struct aha1542_cmd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	.queuecommand		= aha1542_queuecommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	.eh_device_reset_handler= aha1542_dev_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	.eh_bus_reset_handler	= aha1542_bus_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	.eh_host_reset_handler	= aha1542_host_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	.bios_param		= aha1542_biosparam,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	.can_queue		= AHA1542_MAILBOXES, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	.this_id		= 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	.sg_tablesize		= 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	.unchecked_isa_dma	= 1, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) static int aha1542_isa_match(struct device *pdev, unsigned int ndev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	struct Scsi_Host *sh = aha1542_hw_init(&driver_template, pdev, ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	if (!sh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	dev_set_drvdata(pdev, sh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) static int aha1542_isa_remove(struct device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 				    unsigned int ndev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	aha1542_release(dev_get_drvdata(pdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 	dev_set_drvdata(pdev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) static struct isa_driver aha1542_isa_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	.match		= aha1542_isa_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 	.remove		= aha1542_isa_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 		.name	= "aha1542"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) static int isa_registered;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) #ifdef CONFIG_PNP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) static const struct pnp_device_id aha1542_pnp_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	{ .id = "ADP1542" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	{ .id = "" }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) MODULE_DEVICE_TABLE(pnp, aha1542_pnp_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) static int aha1542_pnp_probe(struct pnp_dev *pdev, const struct pnp_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	int indx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	struct Scsi_Host *sh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	for (indx = 0; indx < ARRAY_SIZE(io); indx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 		if (io[indx])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 		if (pnp_activate_dev(pdev) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 		io[indx] = pnp_port_start(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 		/* The card can be queried for its DMA, we have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 		   the DMA set up that is enough */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 		dev_info(&pdev->dev, "ISAPnP found an AHA1535 at I/O 0x%03X", io[indx]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	sh = aha1542_hw_init(&driver_template, &pdev->dev, indx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	if (!sh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	pnp_set_drvdata(pdev, sh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) static void aha1542_pnp_remove(struct pnp_dev *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	aha1542_release(pnp_get_drvdata(pdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	pnp_set_drvdata(pdev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) static struct pnp_driver aha1542_pnp_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	.name		= "aha1542",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	.id_table	= aha1542_pnp_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	.probe		= aha1542_pnp_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	.remove		= aha1542_pnp_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) static int pnp_registered;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) #endif /* CONFIG_PNP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) static int __init aha1542_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) #ifdef CONFIG_PNP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 	if (isapnp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 		ret = pnp_register_driver(&aha1542_pnp_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 		if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 			pnp_registered = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	ret = isa_register_driver(&aha1542_isa_driver, MAXBOARDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 		isa_registered = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) #ifdef CONFIG_PNP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	if (pnp_registered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	if (isa_registered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) static void __exit aha1542_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) #ifdef CONFIG_PNP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	if (pnp_registered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 		pnp_unregister_driver(&aha1542_pnp_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	if (isa_registered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 		isa_unregister_driver(&aha1542_isa_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) module_init(aha1542_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) module_exit(aha1542_exit);