blob: dd6057359d7c6e681544b9f7b2be5393b39c7f1a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Generic Macintosh NCR5380 driver
3 *
4 * Copyright 1998, Michael Schmitz <mschmitz@lbl.gov>
5 *
6 * derived in part from:
7 */
8/*
9 * Generic Generic NCR5380 driver
10 *
11 * Copyright 1995, Russell King
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 */
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/ioport.h>
17#include <linux/init.h>
18#include <linux/blkdev.h>
19#include <linux/interrupt.h>
Finn Thaincbad48d2014-11-12 16:12:07 +110020#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Finn Thaincbad48d2014-11-12 16:12:07 +110022#include <asm/hwtest.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/macints.h>
Finn Thaincbad48d2014-11-12 16:12:07 +110025#include <asm/setup.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <scsi/scsi_host.h>
Finn Thain92de3832014-11-12 16:12:04 +110028
29/* Definitions for the core NCR5380 driver. */
Boaz Harroshe744fde2007-10-16 10:25:01 +020030
Finn Thain820682b2016-10-10 00:46:53 -040031#define NCR5380_implementation_fields int pdma_residual
Finn Thain92de3832014-11-12 16:12:04 +110032
Finn Thain61e1ce52016-10-10 00:46:53 -040033#define NCR5380_read(reg) in_8(hostdata->io + ((reg) << 4))
34#define NCR5380_write(reg, value) out_8(hostdata->io + ((reg) << 4), value)
Finn Thain92de3832014-11-12 16:12:04 +110035
Finn Thain4a98f892016-10-10 00:46:53 -040036#define NCR5380_dma_xfer_len macscsi_dma_xfer_len
Finn Thain6c4b88c2016-03-23 21:10:17 +110037#define NCR5380_dma_recv_setup macscsi_pread
38#define NCR5380_dma_send_setup macscsi_pwrite
Finn Thain4a98f892016-10-10 00:46:53 -040039#define NCR5380_dma_residual macscsi_dma_residual
Finn Thain92de3832014-11-12 16:12:04 +110040
41#define NCR5380_intr macscsi_intr
42#define NCR5380_queue_command macscsi_queue_command
43#define NCR5380_abort macscsi_abort
Hannes Reinecke12e5fc62017-08-25 13:57:10 +020044#define NCR5380_host_reset macscsi_host_reset
Finn Thain92de3832014-11-12 16:12:04 +110045#define NCR5380_info macscsi_info
Finn Thain92de3832014-11-12 16:12:04 +110046
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include "NCR5380.h"
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049static int setup_can_queue = -1;
Finn Thain6e9ae6d2014-11-12 16:12:05 +110050module_param(setup_can_queue, int, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051static int setup_cmd_per_lun = -1;
Finn Thain6e9ae6d2014-11-12 16:12:05 +110052module_param(setup_cmd_per_lun, int, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053static int setup_sg_tablesize = -1;
Finn Thain6e9ae6d2014-11-12 16:12:05 +110054module_param(setup_sg_tablesize, int, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055static int setup_use_pdma = -1;
Finn Thain6e9ae6d2014-11-12 16:12:05 +110056module_param(setup_use_pdma, int, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057static int setup_hostid = -1;
Finn Thain6e9ae6d2014-11-12 16:12:05 +110058module_param(setup_hostid, int, 0);
Finn Thain9c3f0e22016-01-03 16:05:11 +110059static int setup_toshiba_delay = -1;
60module_param(setup_toshiba_delay, int, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Finn Thain6e9ae6d2014-11-12 16:12:05 +110062#ifndef MODULE
63static int __init mac_scsi_setup(char *str)
64{
Finn Thain9c3f0e22016-01-03 16:05:11 +110065 int ints[8];
Finn Thain6e9ae6d2014-11-12 16:12:05 +110066
67 (void)get_options(str, ARRAY_SIZE(ints), ints);
68
Finn Thain9c3f0e22016-01-03 16:05:11 +110069 if (ints[0] < 1) {
70 pr_err("Usage: mac5380=<can_queue>[,<cmd_per_lun>[,<sg_tablesize>[,<hostid>[,<use_tags>[,<use_pdma>[,<toshiba_delay>]]]]]]\n");
Finn Thain6e9ae6d2014-11-12 16:12:05 +110071 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 }
Finn Thain6e9ae6d2014-11-12 16:12:05 +110073 if (ints[0] >= 1)
74 setup_can_queue = ints[1];
75 if (ints[0] >= 2)
76 setup_cmd_per_lun = ints[2];
77 if (ints[0] >= 3)
78 setup_sg_tablesize = ints[3];
79 if (ints[0] >= 4)
80 setup_hostid = ints[4];
Finn Thainc4ec6f92016-03-23 21:10:22 +110081 /* ints[5] (use_tagged_queuing) is ignored */
Finn Thain6e9ae6d2014-11-12 16:12:05 +110082 if (ints[0] >= 6)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 setup_use_pdma = ints[6];
Finn Thain9c3f0e22016-01-03 16:05:11 +110084 if (ints[0] >= 7)
85 setup_toshiba_delay = ints[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 return 1;
87}
88
89__setup("mac5380=", mac_scsi_setup);
Finn Thain6e9ae6d2014-11-12 16:12:05 +110090#endif /* !MODULE */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Finn Thain3a0f64b2016-03-23 21:10:31 +110092/* Pseudo DMA asm originally by Ove Edlund */
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Finn Thain3a0f64b2016-03-23 21:10:31 +110094#define CP_IO_TO_MEM(s,d,n) \
Linus Torvalds1da177e2005-04-16 15:20:36 -070095__asm__ __volatile__ \
96 (" cmp.w #4,%2\n" \
97 " bls 8f\n" \
98 " move.w %1,%%d0\n" \
99 " neg.b %%d0\n" \
100 " and.w #3,%%d0\n" \
101 " sub.w %%d0,%2\n" \
102 " bra 2f\n" \
103 " 1: move.b (%0),(%1)+\n" \
104 " 2: dbf %%d0,1b\n" \
105 " move.w %2,%%d0\n" \
106 " lsr.w #5,%%d0\n" \
107 " bra 4f\n" \
108 " 3: move.l (%0),(%1)+\n" \
109 "31: move.l (%0),(%1)+\n" \
110 "32: move.l (%0),(%1)+\n" \
111 "33: move.l (%0),(%1)+\n" \
112 "34: move.l (%0),(%1)+\n" \
113 "35: move.l (%0),(%1)+\n" \
114 "36: move.l (%0),(%1)+\n" \
115 "37: move.l (%0),(%1)+\n" \
116 " 4: dbf %%d0,3b\n" \
117 " move.w %2,%%d0\n" \
118 " lsr.w #2,%%d0\n" \
119 " and.w #7,%%d0\n" \
120 " bra 6f\n" \
121 " 5: move.l (%0),(%1)+\n" \
122 " 6: dbf %%d0,5b\n" \
123 " and.w #3,%2\n" \
124 " bra 8f\n" \
125 " 7: move.b (%0),(%1)+\n" \
126 " 8: dbf %2,7b\n" \
127 " moveq.l #0, %2\n" \
128 " 9: \n" \
129 ".section .fixup,\"ax\"\n" \
130 " .even\n" \
Finn Thain3a0f64b2016-03-23 21:10:31 +1100131 "91: moveq.l #1, %2\n" \
132 " jra 9b\n" \
133 "94: moveq.l #4, %2\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 " jra 9b\n" \
135 ".previous\n" \
136 ".section __ex_table,\"a\"\n" \
137 " .align 4\n" \
Finn Thain3a0f64b2016-03-23 21:10:31 +1100138 " .long 1b,91b\n" \
139 " .long 3b,94b\n" \
140 " .long 31b,94b\n" \
141 " .long 32b,94b\n" \
142 " .long 33b,94b\n" \
143 " .long 34b,94b\n" \
144 " .long 35b,94b\n" \
145 " .long 36b,94b\n" \
146 " .long 37b,94b\n" \
147 " .long 5b,94b\n" \
148 " .long 7b,91b\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 ".previous" \
Finn Thain3a0f64b2016-03-23 21:10:31 +1100150 : "=a"(s), "=a"(d), "=d"(n) \
151 : "0"(s), "1"(d), "2"(n) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 : "d0")
153
Finn Thain4a98f892016-10-10 00:46:53 -0400154static inline int macscsi_pread(struct NCR5380_hostdata *hostdata,
155 unsigned char *dst, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
Finn Thain4ab2a782017-01-15 18:50:57 -0500157 u8 __iomem *s = hostdata->pdma_io + (INPUT_DATA_REG << 4);
Finn Thain3a0f64b2016-03-23 21:10:31 +1100158 unsigned char *d = dst;
159 int n = len;
160 int transferred;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Finn Thaind5d37a02016-10-10 00:46:53 -0400162 while (!NCR5380_poll_politely(hostdata, BUS_AND_STATUS_REG,
Finn Thain3a0f64b2016-03-23 21:10:31 +1100163 BASR_DRQ | BASR_PHASE_MATCH,
164 BASR_DRQ | BASR_PHASE_MATCH, HZ / 64)) {
165 CP_IO_TO_MEM(s, d, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Finn Thain3a0f64b2016-03-23 21:10:31 +1100167 transferred = d - dst - n;
168 hostdata->pdma_residual = len - transferred;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
Finn Thain3a0f64b2016-03-23 21:10:31 +1100170 /* No bus error. */
171 if (n == 0)
172 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Finn Thain3a0f64b2016-03-23 21:10:31 +1100174 /* Target changed phase early? */
Finn Thaind5d37a02016-10-10 00:46:53 -0400175 if (NCR5380_poll_politely2(hostdata, STATUS_REG, SR_REQ, SR_REQ,
Finn Thain3a0f64b2016-03-23 21:10:31 +1100176 BUS_AND_STATUS_REG, BASR_ACK, BASR_ACK, HZ / 64) < 0)
177 scmd_printk(KERN_ERR, hostdata->connected,
178 "%s: !REQ and !ACK\n", __func__);
179 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH))
180 return 0;
181
Finn Thain4a98f892016-10-10 00:46:53 -0400182 dsprintk(NDEBUG_PSEUDO_DMA, hostdata->host,
Finn Thain3a0f64b2016-03-23 21:10:31 +1100183 "%s: bus error (%d/%d)\n", __func__, transferred, len);
Finn Thain4a98f892016-10-10 00:46:53 -0400184 NCR5380_dprint(NDEBUG_PSEUDO_DMA, hostdata->host);
Finn Thain3a0f64b2016-03-23 21:10:31 +1100185 d = dst + transferred;
186 n = len - transferred;
Finn Thainffdede62014-11-12 16:12:06 +1100187 }
188
Finn Thain3a0f64b2016-03-23 21:10:31 +1100189 scmd_printk(KERN_ERR, hostdata->connected,
190 "%s: phase mismatch or !DRQ\n", __func__);
Finn Thain4a98f892016-10-10 00:46:53 -0400191 NCR5380_dprint(NDEBUG_PSEUDO_DMA, hostdata->host);
Finn Thain3a0f64b2016-03-23 21:10:31 +1100192 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193}
194
195
Finn Thain3a0f64b2016-03-23 21:10:31 +1100196#define CP_MEM_TO_IO(s,d,n) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197__asm__ __volatile__ \
198 (" cmp.w #4,%2\n" \
199 " bls 8f\n" \
200 " move.w %0,%%d0\n" \
201 " neg.b %%d0\n" \
202 " and.w #3,%%d0\n" \
203 " sub.w %%d0,%2\n" \
204 " bra 2f\n" \
205 " 1: move.b (%0)+,(%1)\n" \
206 " 2: dbf %%d0,1b\n" \
207 " move.w %2,%%d0\n" \
208 " lsr.w #5,%%d0\n" \
209 " bra 4f\n" \
210 " 3: move.l (%0)+,(%1)\n" \
211 "31: move.l (%0)+,(%1)\n" \
212 "32: move.l (%0)+,(%1)\n" \
213 "33: move.l (%0)+,(%1)\n" \
214 "34: move.l (%0)+,(%1)\n" \
215 "35: move.l (%0)+,(%1)\n" \
216 "36: move.l (%0)+,(%1)\n" \
217 "37: move.l (%0)+,(%1)\n" \
218 " 4: dbf %%d0,3b\n" \
219 " move.w %2,%%d0\n" \
220 " lsr.w #2,%%d0\n" \
221 " and.w #7,%%d0\n" \
222 " bra 6f\n" \
223 " 5: move.l (%0)+,(%1)\n" \
224 " 6: dbf %%d0,5b\n" \
225 " and.w #3,%2\n" \
226 " bra 8f\n" \
227 " 7: move.b (%0)+,(%1)\n" \
228 " 8: dbf %2,7b\n" \
229 " moveq.l #0, %2\n" \
230 " 9: \n" \
231 ".section .fixup,\"ax\"\n" \
232 " .even\n" \
Finn Thain3a0f64b2016-03-23 21:10:31 +1100233 "91: moveq.l #1, %2\n" \
234 " jra 9b\n" \
235 "94: moveq.l #4, %2\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 " jra 9b\n" \
237 ".previous\n" \
238 ".section __ex_table,\"a\"\n" \
239 " .align 4\n" \
Finn Thain3a0f64b2016-03-23 21:10:31 +1100240 " .long 1b,91b\n" \
241 " .long 3b,94b\n" \
242 " .long 31b,94b\n" \
243 " .long 32b,94b\n" \
244 " .long 33b,94b\n" \
245 " .long 34b,94b\n" \
246 " .long 35b,94b\n" \
247 " .long 36b,94b\n" \
248 " .long 37b,94b\n" \
249 " .long 5b,94b\n" \
250 " .long 7b,91b\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 ".previous" \
Finn Thain3a0f64b2016-03-23 21:10:31 +1100252 : "=a"(s), "=a"(d), "=d"(n) \
253 : "0"(s), "1"(d), "2"(n) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 : "d0")
255
Finn Thain4a98f892016-10-10 00:46:53 -0400256static inline int macscsi_pwrite(struct NCR5380_hostdata *hostdata,
257 unsigned char *src, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
Finn Thain3a0f64b2016-03-23 21:10:31 +1100259 unsigned char *s = src;
Finn Thain4ab2a782017-01-15 18:50:57 -0500260 u8 __iomem *d = hostdata->pdma_io + (OUTPUT_DATA_REG << 4);
Finn Thain3a0f64b2016-03-23 21:10:31 +1100261 int n = len;
262 int transferred;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
Finn Thaind5d37a02016-10-10 00:46:53 -0400264 while (!NCR5380_poll_politely(hostdata, BUS_AND_STATUS_REG,
Finn Thain3a0f64b2016-03-23 21:10:31 +1100265 BASR_DRQ | BASR_PHASE_MATCH,
266 BASR_DRQ | BASR_PHASE_MATCH, HZ / 64)) {
267 CP_MEM_TO_IO(s, d, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Finn Thain3a0f64b2016-03-23 21:10:31 +1100269 transferred = s - src - n;
270 hostdata->pdma_residual = len - transferred;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Finn Thain3a0f64b2016-03-23 21:10:31 +1100272 /* Target changed phase early? */
Finn Thaind5d37a02016-10-10 00:46:53 -0400273 if (NCR5380_poll_politely2(hostdata, STATUS_REG, SR_REQ, SR_REQ,
Finn Thain3a0f64b2016-03-23 21:10:31 +1100274 BUS_AND_STATUS_REG, BASR_ACK, BASR_ACK, HZ / 64) < 0)
275 scmd_printk(KERN_ERR, hostdata->connected,
276 "%s: !REQ and !ACK\n", __func__);
277 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH))
278 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Finn Thain3a0f64b2016-03-23 21:10:31 +1100280 /* No bus error. */
281 if (n == 0) {
Finn Thaind5d37a02016-10-10 00:46:53 -0400282 if (NCR5380_poll_politely(hostdata, TARGET_COMMAND_REG,
Finn Thain3a0f64b2016-03-23 21:10:31 +1100283 TCR_LAST_BYTE_SENT,
284 TCR_LAST_BYTE_SENT, HZ / 64) < 0)
285 scmd_printk(KERN_ERR, hostdata->connected,
286 "%s: Last Byte Sent timeout\n", __func__);
287 return 0;
288 }
289
Finn Thain4a98f892016-10-10 00:46:53 -0400290 dsprintk(NDEBUG_PSEUDO_DMA, hostdata->host,
Finn Thain3a0f64b2016-03-23 21:10:31 +1100291 "%s: bus error (%d/%d)\n", __func__, transferred, len);
Finn Thain4a98f892016-10-10 00:46:53 -0400292 NCR5380_dprint(NDEBUG_PSEUDO_DMA, hostdata->host);
Finn Thain3a0f64b2016-03-23 21:10:31 +1100293 s = src + transferred;
294 n = len - transferred;
Finn Thainffdede62014-11-12 16:12:06 +1100295 }
296
Finn Thain3a0f64b2016-03-23 21:10:31 +1100297 scmd_printk(KERN_ERR, hostdata->connected,
298 "%s: phase mismatch or !DRQ\n", __func__);
Finn Thain4a98f892016-10-10 00:46:53 -0400299 NCR5380_dprint(NDEBUG_PSEUDO_DMA, hostdata->host);
Finn Thainffdede62014-11-12 16:12:06 +1100300
Finn Thain3a0f64b2016-03-23 21:10:31 +1100301 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Finn Thain4a98f892016-10-10 00:46:53 -0400304static int macscsi_dma_xfer_len(struct NCR5380_hostdata *hostdata,
Finn Thain7e9ec8d2016-03-23 21:10:11 +1100305 struct scsi_cmnd *cmd)
306{
Finn Thain3a0f64b2016-03-23 21:10:31 +1100307 if (hostdata->flags & FLAG_NO_PSEUDO_DMA ||
308 cmd->SCp.this_residual < 16)
Finn Thain7e9ec8d2016-03-23 21:10:11 +1100309 return 0;
310
Finn Thain3a0f64b2016-03-23 21:10:31 +1100311 return cmd->SCp.this_residual;
Finn Thain7e9ec8d2016-03-23 21:10:11 +1100312}
313
Finn Thain4a98f892016-10-10 00:46:53 -0400314static int macscsi_dma_residual(struct NCR5380_hostdata *hostdata)
315{
316 return hostdata->pdma_residual;
317}
318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319#include "NCR5380.c"
320
Finn Thaincbad48d2014-11-12 16:12:07 +1100321#define DRV_MODULE_NAME "mac_scsi"
322#define PFX DRV_MODULE_NAME ": "
323
324static struct scsi_host_template mac_scsi_template = {
Finn Thainaa2e2cb2016-01-03 16:05:48 +1100325 .module = THIS_MODULE,
326 .proc_name = DRV_MODULE_NAME,
Finn Thainaa2e2cb2016-01-03 16:05:48 +1100327 .name = "Macintosh NCR5380 SCSI",
328 .info = macscsi_info,
329 .queuecommand = macscsi_queue_command,
330 .eh_abort_handler = macscsi_abort,
Hannes Reinecke12e5fc62017-08-25 13:57:10 +0200331 .eh_host_reset_handler = macscsi_host_reset,
Finn Thainaa2e2cb2016-01-03 16:05:48 +1100332 .can_queue = 16,
333 .this_id = 7,
Finn Thain3a0f64b2016-03-23 21:10:31 +1100334 .sg_tablesize = 1,
Finn Thainaa2e2cb2016-01-03 16:05:48 +1100335 .cmd_per_lun = 2,
336 .use_clustering = DISABLE_CLUSTERING,
Finn Thain32b26a12016-01-03 16:05:58 +1100337 .cmd_size = NCR5380_CMD_SIZE,
Finn Thain0a4e3612016-01-03 16:06:07 +1100338 .max_sectors = 128,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339};
340
Finn Thaincbad48d2014-11-12 16:12:07 +1100341static int __init mac_scsi_probe(struct platform_device *pdev)
342{
343 struct Scsi_Host *instance;
Finn Thain820682b2016-10-10 00:46:53 -0400344 struct NCR5380_hostdata *hostdata;
Finn Thaincbad48d2014-11-12 16:12:07 +1100345 int error;
346 int host_flags = 0;
347 struct resource *irq, *pio_mem, *pdma_mem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
Finn Thaincbad48d2014-11-12 16:12:07 +1100349 pio_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
350 if (!pio_mem)
351 return -ENODEV;
Finn Thain6e9ae6d2014-11-12 16:12:05 +1100352
Finn Thaincbad48d2014-11-12 16:12:07 +1100353 pdma_mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
Finn Thaincbad48d2014-11-12 16:12:07 +1100354
355 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
356
357 if (!hwreg_present((unsigned char *)pio_mem->start +
358 (STATUS_REG << 4))) {
359 pr_info(PFX "no device detected at %pap\n", &pio_mem->start);
360 return -ENODEV;
361 }
362
363 if (setup_can_queue > 0)
364 mac_scsi_template.can_queue = setup_can_queue;
365 if (setup_cmd_per_lun > 0)
366 mac_scsi_template.cmd_per_lun = setup_cmd_per_lun;
367 if (setup_sg_tablesize >= 0)
368 mac_scsi_template.sg_tablesize = setup_sg_tablesize;
369 if (setup_hostid >= 0)
370 mac_scsi_template.this_id = setup_hostid & 7;
Finn Thaincbad48d2014-11-12 16:12:07 +1100371
372 instance = scsi_host_alloc(&mac_scsi_template,
373 sizeof(struct NCR5380_hostdata));
374 if (!instance)
375 return -ENOMEM;
376
Finn Thaincbad48d2014-11-12 16:12:07 +1100377 if (irq)
378 instance->irq = irq->start;
379 else
380 instance->irq = NO_IRQ;
381
Finn Thain820682b2016-10-10 00:46:53 -0400382 hostdata = shost_priv(instance);
383 hostdata->base = pio_mem->start;
Finn Thain4ab2a782017-01-15 18:50:57 -0500384 hostdata->io = (u8 __iomem *)pio_mem->start;
Finn Thaincbad48d2014-11-12 16:12:07 +1100385
Finn Thain820682b2016-10-10 00:46:53 -0400386 if (pdma_mem && setup_use_pdma)
Finn Thain4ab2a782017-01-15 18:50:57 -0500387 hostdata->pdma_io = (u8 __iomem *)pdma_mem->start;
Finn Thain820682b2016-10-10 00:46:53 -0400388 else
Finn Thaincbad48d2014-11-12 16:12:07 +1100389 host_flags |= FLAG_NO_PSEUDO_DMA;
390
Finn Thain9c3f0e22016-01-03 16:05:11 +1100391 host_flags |= setup_toshiba_delay > 0 ? FLAG_TOSHIBA_DELAY : 0;
Finn Thainca513fc2014-11-12 16:12:19 +1100392
Finn Thain8053b0e2016-03-23 21:10:19 +1100393 error = NCR5380_init(instance, host_flags | FLAG_LATE_DMA_SETUP);
Finn Thain0ad0eff2016-01-03 16:05:21 +1100394 if (error)
395 goto fail_init;
Finn Thaincbad48d2014-11-12 16:12:07 +1100396
397 if (instance->irq != NO_IRQ) {
398 error = request_irq(instance->irq, macscsi_intr, IRQF_SHARED,
399 "NCR5380", instance);
400 if (error)
401 goto fail_irq;
402 }
403
Finn Thain9c3f0e22016-01-03 16:05:11 +1100404 NCR5380_maybe_reset_bus(instance);
405
Finn Thaincbad48d2014-11-12 16:12:07 +1100406 error = scsi_add_host(instance, NULL);
407 if (error)
408 goto fail_host;
409
410 platform_set_drvdata(pdev, instance);
411
412 scsi_scan_host(instance);
413 return 0;
414
415fail_host:
416 if (instance->irq != NO_IRQ)
417 free_irq(instance->irq, instance);
418fail_irq:
419 NCR5380_exit(instance);
Finn Thain0ad0eff2016-01-03 16:05:21 +1100420fail_init:
Finn Thaincbad48d2014-11-12 16:12:07 +1100421 scsi_host_put(instance);
422 return error;
423}
424
425static int __exit mac_scsi_remove(struct platform_device *pdev)
426{
427 struct Scsi_Host *instance = platform_get_drvdata(pdev);
428
429 scsi_remove_host(instance);
430 if (instance->irq != NO_IRQ)
431 free_irq(instance->irq, instance);
432 NCR5380_exit(instance);
433 scsi_host_put(instance);
434 return 0;
435}
436
437static struct platform_driver mac_scsi_driver = {
438 .remove = __exit_p(mac_scsi_remove),
439 .driver = {
440 .name = DRV_MODULE_NAME,
Finn Thaincbad48d2014-11-12 16:12:07 +1100441 },
442};
443
444module_platform_driver_probe(mac_scsi_driver, mac_scsi_probe);
445
446MODULE_ALIAS("platform:" DRV_MODULE_NAME);
Finn Thain6e9ae6d2014-11-12 16:12:05 +1100447MODULE_LICENSE("GPL");