^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) * Generic Macintosh NCR5380 driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 1998, Michael Schmitz <mschmitz@lbl.gov>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright 2019 Finn Thain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * derived in part from:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Generic Generic NCR5380 driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Copyright 1995, Russell King
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <asm/hwtest.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <asm/macintosh.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <asm/macints.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /* Definitions for the core NCR5380 driver. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define NCR5380_implementation_fields int pdma_residual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define NCR5380_read(reg) in_8(hostdata->io + ((reg) << 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define NCR5380_write(reg, value) out_8(hostdata->io + ((reg) << 4), value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define NCR5380_dma_xfer_len macscsi_dma_xfer_len
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define NCR5380_dma_recv_setup macscsi_pread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define NCR5380_dma_send_setup macscsi_pwrite
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define NCR5380_dma_residual macscsi_dma_residual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define NCR5380_intr macscsi_intr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define NCR5380_queue_command macscsi_queue_command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define NCR5380_abort macscsi_abort
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define NCR5380_host_reset macscsi_host_reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define NCR5380_info macscsi_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #include "NCR5380.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static int setup_can_queue = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) module_param(setup_can_queue, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static int setup_cmd_per_lun = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) module_param(setup_cmd_per_lun, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static int setup_sg_tablesize = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) module_param(setup_sg_tablesize, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static int setup_use_pdma = 512;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) module_param(setup_use_pdma, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static int setup_hostid = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) module_param(setup_hostid, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static int setup_toshiba_delay = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) module_param(setup_toshiba_delay, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #ifndef MODULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static int __init mac_scsi_setup(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) int ints[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) (void)get_options(str, ARRAY_SIZE(ints), ints);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (ints[0] < 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) pr_err("Usage: mac5380=<can_queue>[,<cmd_per_lun>[,<sg_tablesize>[,<hostid>[,<use_tags>[,<use_pdma>[,<toshiba_delay>]]]]]]\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (ints[0] >= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) setup_can_queue = ints[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (ints[0] >= 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) setup_cmd_per_lun = ints[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (ints[0] >= 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) setup_sg_tablesize = ints[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (ints[0] >= 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) setup_hostid = ints[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /* ints[5] (use_tagged_queuing) is ignored */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (ints[0] >= 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) setup_use_pdma = ints[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (ints[0] >= 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) setup_toshiba_delay = ints[7];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) __setup("mac5380=", mac_scsi_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #endif /* !MODULE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * According to "Inside Macintosh: Devices", Mac OS requires disk drivers to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * specify the number of bytes between the delays expected from a SCSI target.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * This allows the operating system to "prevent bus errors when a target fails
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * to deliver the next byte within the processor bus error timeout period."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * Linux SCSI drivers lack knowledge of the timing behaviour of SCSI targets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * so bus errors are unavoidable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * If a MOVE.B instruction faults, we assume that zero bytes were transferred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * and simply retry. That assumption probably depends on target behaviour but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * seems to hold up okay. The NOP provides synchronization: without it the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * fault can sometimes occur after the program counter has moved past the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * offending instruction. Post-increment addressing can't be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #define MOVE_BYTE(operands) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) asm volatile ( \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) "1: moveb " operands " \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) "11: nop \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) " addq #1,%0 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) " subq #1,%1 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) "40: \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) " \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) ".section .fixup,\"ax\" \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) ".even \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) "90: movel #1, %2 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) " jra 40b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) ".previous \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) " \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) ".section __ex_table,\"a\" \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) ".align 4 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) ".long 1b,90b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) ".long 11b,90b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) ".previous \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) : "+a" (addr), "+r" (n), "+r" (result) : "a" (io))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * If a MOVE.W (or MOVE.L) instruction faults, it cannot be retried because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * the residual byte count would be uncertain. In that situation the MOVE_WORD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * macro clears n in the fixup section to abort the transfer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #define MOVE_WORD(operands) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) asm volatile ( \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) "1: movew " operands " \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) "11: nop \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) " subq #2,%1 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) "40: \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) " \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) ".section .fixup,\"ax\" \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) ".even \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) "90: movel #0, %1 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) " movel #2, %2 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) " jra 40b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) ".previous \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) " \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) ".section __ex_table,\"a\" \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) ".align 4 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) ".long 1b,90b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) ".long 11b,90b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) ".previous \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) : "+a" (addr), "+r" (n), "+r" (result) : "a" (io))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) #define MOVE_16_WORDS(operands) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) asm volatile ( \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) "1: movew " operands " \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) "2: movew " operands " \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) "3: movew " operands " \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) "4: movew " operands " \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) "5: movew " operands " \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) "6: movew " operands " \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) "7: movew " operands " \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) "8: movew " operands " \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) "9: movew " operands " \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) "10: movew " operands " \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) "11: movew " operands " \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) "12: movew " operands " \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) "13: movew " operands " \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) "14: movew " operands " \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) "15: movew " operands " \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) "16: movew " operands " \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) "17: nop \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) " subl #32,%1 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) "40: \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) " \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) ".section .fixup,\"ax\" \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) ".even \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) "90: movel #0, %1 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) " movel #2, %2 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) " jra 40b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) ".previous \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) " \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) ".section __ex_table,\"a\" \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) ".align 4 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) ".long 1b,90b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) ".long 2b,90b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) ".long 3b,90b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) ".long 4b,90b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) ".long 5b,90b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) ".long 6b,90b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) ".long 7b,90b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) ".long 8b,90b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) ".long 9b,90b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) ".long 10b,90b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) ".long 11b,90b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) ".long 12b,90b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) ".long 13b,90b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) ".long 14b,90b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) ".long 15b,90b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) ".long 16b,90b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) ".long 17b,90b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) ".previous \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) : "+a" (addr), "+r" (n), "+r" (result) : "a" (io))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) #define MAC_PDMA_DELAY 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static inline int mac_pdma_recv(void __iomem *io, unsigned char *start, int n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) unsigned char *addr = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (n >= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) MOVE_BYTE("%3@,%0@");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (n >= 1 && ((unsigned long)addr & 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) MOVE_BYTE("%3@,%0@");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) while (n >= 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) MOVE_16_WORDS("%3@,%0@+");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) while (n >= 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) MOVE_WORD("%3@,%0@+");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return start - addr; /* Negated to indicate uncertain length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (n == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) MOVE_BYTE("%3@,%0@");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return addr - start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static inline int mac_pdma_send(unsigned char *start, void __iomem *io, int n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) unsigned char *addr = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (n >= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) MOVE_BYTE("%0@,%3@");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (n >= 1 && ((unsigned long)addr & 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) MOVE_BYTE("%0@,%3@");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) while (n >= 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) MOVE_16_WORDS("%0@+,%3@");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) while (n >= 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) MOVE_WORD("%0@+,%3@");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return start - addr; /* Negated to indicate uncertain length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (n == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) MOVE_BYTE("%0@,%3@");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return addr - start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) /* The "SCSI DMA" chip on the IIfx implements this register. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) #define CTRL_REG 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) #define CTRL_INTERRUPTS_ENABLE BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) #define CTRL_HANDSHAKE_MODE BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static inline void write_ctrl_reg(struct NCR5380_hostdata *hostdata, u32 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) out_be32(hostdata->io + (CTRL_REG << 4), value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static inline int macscsi_pread(struct NCR5380_hostdata *hostdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) unsigned char *dst, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) u8 __iomem *s = hostdata->pdma_io + (INPUT_DATA_REG << 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) unsigned char *d = dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) hostdata->pdma_residual = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) while (!NCR5380_poll_politely(hostdata, BUS_AND_STATUS_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) BASR_DRQ | BASR_PHASE_MATCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) BASR_DRQ | BASR_PHASE_MATCH, HZ / 64)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) int bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (macintosh_config->ident == MAC_MODEL_IIFX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) write_ctrl_reg(hostdata, CTRL_HANDSHAKE_MODE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) CTRL_INTERRUPTS_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) bytes = mac_pdma_recv(s, d, min(hostdata->pdma_residual, 512));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (bytes > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) d += bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) hostdata->pdma_residual -= bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) if (hostdata->pdma_residual == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) if (NCR5380_poll_politely2(hostdata, STATUS_REG, SR_REQ, SR_REQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) BUS_AND_STATUS_REG, BASR_ACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) BASR_ACK, HZ / 64) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) scmd_printk(KERN_DEBUG, hostdata->connected,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) "%s: !REQ and !ACK\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (bytes == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) udelay(MAC_PDMA_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (bytes >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) dsprintk(NDEBUG_PSEUDO_DMA, hostdata->host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) "%s: bus error (%d/%d)\n", __func__, d - dst, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) NCR5380_dprint(NDEBUG_PSEUDO_DMA, hostdata->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) result = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) scmd_printk(KERN_ERR, hostdata->connected,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) "%s: phase mismatch or !DRQ\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) NCR5380_dprint(NDEBUG_PSEUDO_DMA, hostdata->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) result = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) if (macintosh_config->ident == MAC_MODEL_IIFX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) write_ctrl_reg(hostdata, CTRL_INTERRUPTS_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) static inline int macscsi_pwrite(struct NCR5380_hostdata *hostdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) unsigned char *src, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) unsigned char *s = src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) u8 __iomem *d = hostdata->pdma_io + (OUTPUT_DATA_REG << 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) hostdata->pdma_residual = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) while (!NCR5380_poll_politely(hostdata, BUS_AND_STATUS_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) BASR_DRQ | BASR_PHASE_MATCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) BASR_DRQ | BASR_PHASE_MATCH, HZ / 64)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) int bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) if (macintosh_config->ident == MAC_MODEL_IIFX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) write_ctrl_reg(hostdata, CTRL_HANDSHAKE_MODE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) CTRL_INTERRUPTS_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) bytes = mac_pdma_send(s, d, min(hostdata->pdma_residual, 512));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) if (bytes > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) s += bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) hostdata->pdma_residual -= bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) if (hostdata->pdma_residual == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) if (NCR5380_poll_politely(hostdata, TARGET_COMMAND_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) TCR_LAST_BYTE_SENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) TCR_LAST_BYTE_SENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) HZ / 64) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) scmd_printk(KERN_ERR, hostdata->connected,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) "%s: Last Byte Sent timeout\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) result = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) if (NCR5380_poll_politely2(hostdata, STATUS_REG, SR_REQ, SR_REQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) BUS_AND_STATUS_REG, BASR_ACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) BASR_ACK, HZ / 64) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) scmd_printk(KERN_DEBUG, hostdata->connected,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) "%s: !REQ and !ACK\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) if (bytes == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) udelay(MAC_PDMA_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) if (bytes >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) dsprintk(NDEBUG_PSEUDO_DMA, hostdata->host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) "%s: bus error (%d/%d)\n", __func__, s - src, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) NCR5380_dprint(NDEBUG_PSEUDO_DMA, hostdata->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) result = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) scmd_printk(KERN_ERR, hostdata->connected,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) "%s: phase mismatch or !DRQ\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) NCR5380_dprint(NDEBUG_PSEUDO_DMA, hostdata->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) result = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if (macintosh_config->ident == MAC_MODEL_IIFX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) write_ctrl_reg(hostdata, CTRL_INTERRUPTS_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) static int macscsi_dma_xfer_len(struct NCR5380_hostdata *hostdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) if (hostdata->flags & FLAG_NO_PSEUDO_DMA ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) cmd->SCp.this_residual < setup_use_pdma)
^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) return cmd->SCp.this_residual;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) static int macscsi_dma_residual(struct NCR5380_hostdata *hostdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) return hostdata->pdma_residual;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) #include "NCR5380.c"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) #define DRV_MODULE_NAME "mac_scsi"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) #define PFX DRV_MODULE_NAME ": "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) static struct scsi_host_template mac_scsi_template = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) .module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) .proc_name = DRV_MODULE_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) .name = "Macintosh NCR5380 SCSI",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) .info = macscsi_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) .queuecommand = macscsi_queue_command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) .eh_abort_handler = macscsi_abort,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) .eh_host_reset_handler = macscsi_host_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) .can_queue = 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) .this_id = 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) .sg_tablesize = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) .cmd_per_lun = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) .dma_boundary = PAGE_SIZE - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) .cmd_size = NCR5380_CMD_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) .max_sectors = 128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) static int __init mac_scsi_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) struct Scsi_Host *instance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) struct NCR5380_hostdata *hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) int host_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) struct resource *irq, *pio_mem, *pdma_mem = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) pio_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) if (!pio_mem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) pdma_mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) if (!hwreg_present((unsigned char *)pio_mem->start +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) (STATUS_REG << 4))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) pr_info(PFX "no device detected at %pap\n", &pio_mem->start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) if (setup_can_queue > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) mac_scsi_template.can_queue = setup_can_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) if (setup_cmd_per_lun > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) mac_scsi_template.cmd_per_lun = setup_cmd_per_lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) if (setup_sg_tablesize > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) mac_scsi_template.sg_tablesize = setup_sg_tablesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) if (setup_hostid >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) mac_scsi_template.this_id = setup_hostid & 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) instance = scsi_host_alloc(&mac_scsi_template,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) sizeof(struct NCR5380_hostdata));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) if (!instance)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) if (irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) instance->irq = irq->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) instance->irq = NO_IRQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) hostdata = shost_priv(instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) hostdata->base = pio_mem->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) hostdata->io = (u8 __iomem *)pio_mem->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) if (pdma_mem && setup_use_pdma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) hostdata->pdma_io = (u8 __iomem *)pdma_mem->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) host_flags |= FLAG_NO_PSEUDO_DMA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) host_flags |= setup_toshiba_delay > 0 ? FLAG_TOSHIBA_DELAY : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) error = NCR5380_init(instance, host_flags | FLAG_LATE_DMA_SETUP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) goto fail_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) if (instance->irq != NO_IRQ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) error = request_irq(instance->irq, macscsi_intr, IRQF_SHARED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) "NCR5380", instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) goto fail_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) NCR5380_maybe_reset_bus(instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) error = scsi_add_host(instance, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) goto fail_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) platform_set_drvdata(pdev, instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) scsi_scan_host(instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) fail_host:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) if (instance->irq != NO_IRQ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) free_irq(instance->irq, instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) fail_irq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) NCR5380_exit(instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) fail_init:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) scsi_host_put(instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) static int __exit mac_scsi_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) struct Scsi_Host *instance = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) scsi_remove_host(instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) if (instance->irq != NO_IRQ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) free_irq(instance->irq, instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) NCR5380_exit(instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) scsi_host_put(instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) static struct platform_driver mac_scsi_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) .remove = __exit_p(mac_scsi_remove),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) .name = DRV_MODULE_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) module_platform_driver_probe(mac_scsi_driver, mac_scsi_probe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) MODULE_ALIAS("platform:" DRV_MODULE_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) MODULE_LICENSE("GPL");