Blame view

drivers/scsi/mac53c94.c 15 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  /*
   * SCSI low-level driver for the 53c94 SCSI bus adaptor found
   * on Power Macintosh computers, controlling the external SCSI chain.
   * We assume the 53c94 is connected to a DBDMA (descriptor-based DMA)
   * controller.
   *
   * Paul Mackerras, August 1996.
   * Copyright (C) 1996 Paul Mackerras.
   */
  #include <linux/kernel.h>
  #include <linux/delay.h>
  #include <linux/types.h>
  #include <linux/string.h>
  #include <linux/slab.h>
  #include <linux/blkdev.h>
  #include <linux/proc_fs.h>
  #include <linux/stat.h>
  #include <linux/spinlock.h>
  #include <linux/interrupt.h>
  #include <asm/dbdma.h>
  #include <asm/io.h>
  #include <asm/pgtable.h>
  #include <asm/prom.h>
  #include <asm/system.h>
  #include <asm/pci-bridge.h>
  #include <asm/macio.h>
  
  #include <scsi/scsi.h>
  #include <scsi/scsi_cmnd.h>
  #include <scsi/scsi_device.h>
  #include <scsi/scsi_host.h>
  
  #include "mac53c94.h"
  
  enum fsc_phase {
  	idle,
  	selecting,
  	dataing,
  	completing,
  	busfreeing,
  };
  
  struct fsc_state {
  	struct	mac53c94_regs __iomem *regs;
  	int	intr;
  	struct	dbdma_regs __iomem *dma;
  	int	dmaintr;
  	int	clk_freq;
  	struct	Scsi_Host *host;
  	struct scsi_cmnd *request_q;
  	struct scsi_cmnd *request_qtail;
  	struct scsi_cmnd *current_req;		/* req we're currently working on */
  	enum fsc_phase phase;		/* what we're currently trying to do */
  	struct dbdma_cmd *dma_cmds;	/* space for dbdma commands, aligned */
  	void	*dma_cmd_space;
  	struct	pci_dev *pdev;
  	dma_addr_t dma_addr;
  	struct macio_dev *mdev;
  };
  
  static void mac53c94_init(struct fsc_state *);
  static void mac53c94_start(struct fsc_state *);
7d12e780e   David Howells   IRQ: Maintain reg...
63
64
  static void mac53c94_interrupt(int, void *);
  static irqreturn_t do_mac53c94_interrupt(int, void *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
65
66
  static void cmd_done(struct fsc_state *, int result);
  static void set_dma_cmds(struct fsc_state *, struct scsi_cmnd *);
f281233d3   Jeff Garzik   SCSI host lock pu...
67
  static int mac53c94_queue_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
68
69
70
71
72
73
74
75
  {
  	struct fsc_state *state;
  
  #if 0
  	if (cmd->sc_data_direction == DMA_TO_DEVICE) {
  		int i;
  		printk(KERN_DEBUG "mac53c94_queue %p: command is", cmd);
  		for (i = 0; i < cmd->cmd_len; ++i)
ad361c988   Joe Perches   Remove multiple K...
76
77
78
79
80
  			printk(KERN_CONT " %.2x", cmd->cmnd[i]);
  		printk(KERN_CONT "
  ");
  		printk(KERN_DEBUG "use_sg=%d request_bufflen=%d request_buffer=%p
  ",
646158c20   FUJITA Tomonori   [SCSI] mac53c94: ...
81
  		       scsi_sg_count(cmd), scsi_bufflen(cmd), scsi_sglist(cmd));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
  	}
  #endif
  
  	cmd->scsi_done = done;
  	cmd->host_scribble = NULL;
  
  	state = (struct fsc_state *) cmd->device->host->hostdata;
  
  	if (state->request_q == NULL)
  		state->request_q = cmd;
  	else
  		state->request_qtail->host_scribble = (void *) cmd;
  	state->request_qtail = cmd;
  
  	if (state->phase == idle)
  		mac53c94_start(state);
  
  	return 0;
  }
f281233d3   Jeff Garzik   SCSI host lock pu...
101
  static DEF_SCSI_QCMD(mac53c94_queue)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
102
103
104
105
106
  static int mac53c94_host_reset(struct scsi_cmnd *cmd)
  {
  	struct fsc_state *state = (struct fsc_state *) cmd->device->host->hostdata;
  	struct mac53c94_regs __iomem *regs = state->regs;
  	struct dbdma_regs __iomem *dma = state->dma;
df0ae2497   Jeff Garzik   [SCSI] allow slee...
107
108
109
  	unsigned long flags;
  
  	spin_lock_irqsave(cmd->device->host->host_lock, flags);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
110
111
112
113
114
115
116
117
  
  	writel((RUN|PAUSE|FLUSH|WAKE) << 16, &dma->control);
  	writeb(CMD_SCSI_RESET, &regs->command);	/* assert RST */
  	udelay(100);			/* leave it on for a while (>= 25us) */
  	writeb(CMD_RESET, &regs->command);
  	udelay(20);
  	mac53c94_init(state);
  	writeb(CMD_NOP, &regs->command);
df0ae2497   Jeff Garzik   [SCSI] allow slee...
118
119
  
  	spin_unlock_irqrestore(cmd->device->host->host_lock, flags);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
  	return SUCCESS;
  }
  
  static void mac53c94_init(struct fsc_state *state)
  {
  	struct mac53c94_regs __iomem *regs = state->regs;
  	struct dbdma_regs __iomem *dma = state->dma;
  	int x;
  
  	writeb(state->host->this_id | CF1_PAR_ENABLE, &regs->config1);
  	writeb(TIMO_VAL(250), &regs->sel_timeout);	/* 250ms */
  	writeb(CLKF_VAL(state->clk_freq), &regs->clk_factor);
  	writeb(CF2_FEATURE_EN, &regs->config2);
  	writeb(0, &regs->config3);
  	writeb(0, &regs->sync_period);
  	writeb(0, &regs->sync_offset);
  	x = readb(&regs->interrupt);
  	writel((RUN|PAUSE|FLUSH|WAKE) << 16, &dma->control);
  }
  
  /*
   * Start the next command for a 53C94.
   * Should be called with interrupts disabled.
   */
  static void mac53c94_start(struct fsc_state *state)
  {
  	struct scsi_cmnd *cmd;
  	struct mac53c94_regs __iomem *regs = state->regs;
  	int i;
  
  	if (state->phase != idle || state->current_req != NULL)
  		panic("inappropriate mac53c94_start (state=%p)", state);
  	if (state->request_q == NULL)
  		return;
  	state->current_req = cmd = state->request_q;
  	state->request_q = (struct scsi_cmnd *) cmd->host_scribble;
  
  	/* Off we go */
  	writeb(0, &regs->count_lo);
  	writeb(0, &regs->count_mid);
  	writeb(0, &regs->count_hi);
  	writeb(CMD_NOP + CMD_DMA_MODE, &regs->command);
  	udelay(1);
  	writeb(CMD_FLUSH, &regs->command);
  	udelay(1);
  	writeb(cmd->device->id, &regs->dest_id);
  	writeb(0, &regs->sync_period);
  	writeb(0, &regs->sync_offset);
  
  	/* load the command into the FIFO */
  	for (i = 0; i < cmd->cmd_len; ++i)
  		writeb(cmd->cmnd[i], &regs->fifo);
  
  	/* do select without ATN XXX */
  	writeb(CMD_SELECT, &regs->command);
  	state->phase = selecting;
646158c20   FUJITA Tomonori   [SCSI] mac53c94: ...
176
  	set_dma_cmds(state, cmd);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
177
  }
7d12e780e   David Howells   IRQ: Maintain reg...
178
  static irqreturn_t do_mac53c94_interrupt(int irq, void *dev_id)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
179
180
181
182
183
  {
  	unsigned long flags;
  	struct Scsi_Host *dev = ((struct fsc_state *) dev_id)->current_req->device->host;
  	
  	spin_lock_irqsave(dev->host_lock, flags);
7d12e780e   David Howells   IRQ: Maintain reg...
184
  	mac53c94_interrupt(irq, dev_id);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
185
186
187
  	spin_unlock_irqrestore(dev->host_lock, flags);
  	return IRQ_HANDLED;
  }
7d12e780e   David Howells   IRQ: Maintain reg...
188
  static void mac53c94_interrupt(int irq, void *dev_id)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
  {
  	struct fsc_state *state = (struct fsc_state *) dev_id;
  	struct mac53c94_regs __iomem *regs = state->regs;
  	struct dbdma_regs __iomem *dma = state->dma;
  	struct scsi_cmnd *cmd = state->current_req;
  	int nb, stat, seq, intr;
  	static int mac53c94_errors;
  
  	/*
  	 * Apparently, reading the interrupt register unlatches
  	 * the status and sequence step registers.
  	 */
  	seq = readb(&regs->seqstep);
  	stat = readb(&regs->status);
  	intr = readb(&regs->interrupt);
  
  #if 0
  	printk(KERN_DEBUG "mac53c94_intr, intr=%x stat=%x seq=%x phase=%d
  ",
  	       intr, stat, seq, state->phase);
  #endif
  
  	if (intr & INTR_RESET) {
  		/* SCSI bus was reset */
  		printk(KERN_INFO "external SCSI bus reset detected
  ");
  		writeb(CMD_NOP, &regs->command);
  		writel(RUN << 16, &dma->control);	/* stop dma */
  		cmd_done(state, DID_RESET << 16);
  		return;
  	}
  	if (intr & INTR_ILL_CMD) {
  		printk(KERN_ERR "53c94: invalid cmd, intr=%x stat=%x seq=%x phase=%d
  ",
  		       intr, stat, seq, state->phase);
  		cmd_done(state, DID_ERROR << 16);
  		return;
  	}
  	if (stat & STAT_ERROR) {
  #if 0
  		/* XXX these seem to be harmless? */
  		printk("53c94: bad error, intr=%x stat=%x seq=%x phase=%d
  ",
  		       intr, stat, seq, state->phase);
  #endif
  		++mac53c94_errors;
  		writeb(CMD_NOP + CMD_DMA_MODE, &regs->command);
  	}
  	if (cmd == 0) {
  		printk(KERN_DEBUG "53c94: interrupt with no command active?
  ");
  		return;
  	}
  	if (stat & STAT_PARITY) {
  		printk(KERN_ERR "mac53c94: parity error
  ");
  		cmd_done(state, DID_PARITY << 16);
  		return;
  	}
  	switch (state->phase) {
  	case selecting:
  		if (intr & INTR_DISCONNECT) {
  			/* selection timed out */
  			cmd_done(state, DID_BAD_TARGET << 16);
  			return;
  		}
  		if (intr != INTR_BUS_SERV + INTR_DONE) {
  			printk(KERN_DEBUG "got intr %x during selection
  ", intr);
  			cmd_done(state, DID_ERROR << 16);
  			return;
  		}
  		if ((seq & SS_MASK) != SS_DONE) {
  			printk(KERN_DEBUG "seq step %x after command
  ", seq);
  			cmd_done(state, DID_ERROR << 16);
  			return;
  		}
  		writeb(CMD_NOP, &regs->command);
  		/* set DMA controller going if any data to transfer */
  		if ((stat & (STAT_MSG|STAT_CD)) == 0
646158c20   FUJITA Tomonori   [SCSI] mac53c94: ...
270
  		    && (scsi_sg_count(cmd) > 0 || scsi_bufflen(cmd))) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
  			nb = cmd->SCp.this_residual;
  			if (nb > 0xfff0)
  				nb = 0xfff0;
  			cmd->SCp.this_residual -= nb;
  			writeb(nb, &regs->count_lo);
  			writeb(nb >> 8, &regs->count_mid);
  			writeb(CMD_DMA_MODE + CMD_NOP, &regs->command);
  			writel(virt_to_phys(state->dma_cmds), &dma->cmdptr);
  			writel((RUN << 16) | RUN, &dma->control);
  			writeb(CMD_DMA_MODE + CMD_XFER_DATA, &regs->command);
  			state->phase = dataing;
  			break;
  		} else if ((stat & STAT_PHASE) == STAT_CD + STAT_IO) {
  			/* up to status phase already */
  			writeb(CMD_I_COMPLETE, &regs->command);
  			state->phase = completing;
  		} else {
  			printk(KERN_DEBUG "in unexpected phase %x after cmd
  ",
  			       stat & STAT_PHASE);
  			cmd_done(state, DID_ERROR << 16);
  			return;
  		}
  		break;
  
  	case dataing:
  		if (intr != INTR_BUS_SERV) {
  			printk(KERN_DEBUG "got intr %x before status
  ", intr);
  			cmd_done(state, DID_ERROR << 16);
  			return;
  		}
  		if (cmd->SCp.this_residual != 0
  		    && (stat & (STAT_MSG|STAT_CD)) == 0) {
  			/* Set up the count regs to transfer more */
  			nb = cmd->SCp.this_residual;
  			if (nb > 0xfff0)
  				nb = 0xfff0;
  			cmd->SCp.this_residual -= nb;
  			writeb(nb, &regs->count_lo);
  			writeb(nb >> 8, &regs->count_mid);
  			writeb(CMD_DMA_MODE + CMD_NOP, &regs->command);
  			writeb(CMD_DMA_MODE + CMD_XFER_DATA, &regs->command);
  			break;
  		}
  		if ((stat & STAT_PHASE) != STAT_CD + STAT_IO) {
  			printk(KERN_DEBUG "intr %x before data xfer complete
  ", intr);
  		}
  		writel(RUN << 16, &dma->control);	/* stop dma */
646158c20   FUJITA Tomonori   [SCSI] mac53c94: ...
321
  		scsi_dma_unmap(cmd);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
  		/* should check dma status */
  		writeb(CMD_I_COMPLETE, &regs->command);
  		state->phase = completing;
  		break;
  	case completing:
  		if (intr != INTR_DONE) {
  			printk(KERN_DEBUG "got intr %x on completion
  ", intr);
  			cmd_done(state, DID_ERROR << 16);
  			return;
  		}
  		cmd->SCp.Status = readb(&regs->fifo);
  		cmd->SCp.Message = readb(&regs->fifo);
  		cmd->result = CMD_ACCEPT_MSG;
  		writeb(CMD_ACCEPT_MSG, &regs->command);
  		state->phase = busfreeing;
  		break;
  	case busfreeing:
  		if (intr != INTR_DISCONNECT) {
  			printk(KERN_DEBUG "got intr %x when expected disconnect
  ", intr);
  		}
  		cmd_done(state, (DID_OK << 16) + (cmd->SCp.Message << 8)
  			 + cmd->SCp.Status);
  		break;
  	default:
  		printk(KERN_DEBUG "don't know about phase %d
  ", state->phase);
  	}
  }
  
  static void cmd_done(struct fsc_state *state, int result)
  {
  	struct scsi_cmnd *cmd;
  
  	cmd = state->current_req;
  	if (cmd != 0) {
  		cmd->result = result;
  		(*cmd->scsi_done)(cmd);
  		state->current_req = NULL;
  	}
  	state->phase = idle;
  	mac53c94_start(state);
  }
  
  /*
   * Set up DMA commands for transferring data.
   */
  static void set_dma_cmds(struct fsc_state *state, struct scsi_cmnd *cmd)
  {
646158c20   FUJITA Tomonori   [SCSI] mac53c94: ...
372
  	int i, dma_cmd, total, nseg;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
373
374
375
376
  	struct scatterlist *scl;
  	struct dbdma_cmd *dcmds;
  	dma_addr_t dma_addr;
  	u32 dma_len;
646158c20   FUJITA Tomonori   [SCSI] mac53c94: ...
377
378
379
380
  	nseg = scsi_dma_map(cmd);
  	BUG_ON(nseg < 0);
  	if (!nseg)
  		return;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
381
382
383
  	dma_cmd = cmd->sc_data_direction == DMA_TO_DEVICE ?
  			OUTPUT_MORE : INPUT_MORE;
  	dcmds = state->dma_cmds;
646158c20   FUJITA Tomonori   [SCSI] mac53c94: ...
384
385
386
387
388
389
390
391
392
393
  	total = 0;
  
  	scsi_for_each_sg(cmd, scl, nseg, i) {
  		dma_addr = sg_dma_address(scl);
  		dma_len = sg_dma_len(scl);
  		if (dma_len > 0xffff)
  			panic("mac53c94: scatterlist element >= 64k");
  		total += dma_len;
  		st_le16(&dcmds->req_count, dma_len);
  		st_le16(&dcmds->command, dma_cmd);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
394
395
396
397
  		st_le32(&dcmds->phy_addr, dma_addr);
  		dcmds->xfer_status = 0;
  		++dcmds;
  	}
646158c20   FUJITA Tomonori   [SCSI] mac53c94: ...
398

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
399
400
401
402
403
404
405
406
407
408
  	dma_cmd += OUTPUT_LAST - OUTPUT_MORE;
  	st_le16(&dcmds[-1].command, dma_cmd);
  	st_le16(&dcmds->command, DBDMA_STOP);
  	cmd->SCp.this_residual = total;
  }
  
  static struct scsi_host_template mac53c94_template = {
  	.proc_name	= "53c94",
  	.name		= "53C94",
  	.queuecommand	= mac53c94_queue,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
409
410
411
412
413
414
415
  	.eh_host_reset_handler = mac53c94_host_reset,
  	.can_queue	= 1,
  	.this_id	= 7,
  	.sg_tablesize	= SG_ALL,
  	.cmd_per_lun	= 1,
  	.use_clustering	= DISABLE_CLUSTERING,
  };
5e6557722   Jeff Mahoney   [PATCH] openfirmw...
416
  static int mac53c94_probe(struct macio_dev *mdev, const struct of_device_id *match)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
417
418
419
420
421
422
  {
  	struct device_node *node = macio_get_of_node(mdev);
  	struct pci_dev *pdev = macio_get_pci_dev(mdev);
  	struct fsc_state *state;
  	struct Scsi_Host *host;
  	void *dma_cmd_space;
294ef16a2   Jeremy Kerr   [POWERPC] scsi: C...
423
  	const unsigned char *clkprop;
cc5d0189b   Benjamin Herrenschmidt   [PATCH] powerpc: ...
424
  	int proplen, rc = -ENODEV;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
425
426
  
  	if (macio_resource_count(mdev) != 2 || macio_irq_count(mdev) != 2) {
cc5d0189b   Benjamin Herrenschmidt   [PATCH] powerpc: ...
427
428
429
430
  		printk(KERN_ERR "mac53c94: expected 2 addrs and intrs"
  		       " (got %d/%d)
  ",
  		       macio_resource_count(mdev), macio_irq_count(mdev));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
431
432
433
434
435
436
437
438
439
440
441
  		return -ENODEV;
  	}
  
  	if (macio_request_resources(mdev, "mac53c94") != 0) {
         		printk(KERN_ERR "mac53c94: unable to request memory resources");
  		return -EBUSY;
  	}
  
         	host = scsi_host_alloc(&mac53c94_template, sizeof(struct fsc_state));
  	if (host == NULL) {
  		printk(KERN_ERR "mac53c94: couldn't register host");
cc5d0189b   Benjamin Herrenschmidt   [PATCH] powerpc: ...
442
  		rc = -ENOMEM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
  		goto out_release;
  	}
  
  	state = (struct fsc_state *) host->hostdata;
  	macio_set_drvdata(mdev, state);
  	state->host = host;
  	state->pdev = pdev;
  	state->mdev = mdev;
  
  	state->regs = (struct mac53c94_regs __iomem *)
  		ioremap(macio_resource_start(mdev, 0), 0x1000);
  	state->intr = macio_irq(mdev, 0);
  	state->dma = (struct dbdma_regs __iomem *)
  		ioremap(macio_resource_start(mdev, 1), 0x1000);
  	state->dmaintr = macio_irq(mdev, 1);
  	if (state->regs == NULL || state->dma == NULL) {
  		printk(KERN_ERR "mac53c94: ioremap failed for %s
  ",
  		       node->full_name);
  		goto out_free;
  	}
40cd3a456   Stephen Rothwell   [POWERPC] Rename ...
464
  	clkprop = of_get_property(node, "clock-frequency", &proplen);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
         	if (clkprop == NULL || proplen != sizeof(int)) {
         		printk(KERN_ERR "%s: can't get clock frequency, "
         		       "assuming 25MHz
  ", node->full_name);
         		state->clk_freq = 25000000;
         	} else
         		state->clk_freq = *(int *)clkprop;
  
         	/* Space for dma command list: +1 for stop command,
         	 * +1 to allow for aligning.
  	 * XXX FIXME: Use DMA consistent routines
  	 */
         	dma_cmd_space = kmalloc((host->sg_tablesize + 2) *
         				sizeof(struct dbdma_cmd), GFP_KERNEL);
         	if (dma_cmd_space == 0) {
         		printk(KERN_ERR "mac53c94: couldn't allocate dma "
         		       "command space for %s
  ", node->full_name);
cc5d0189b   Benjamin Herrenschmidt   [PATCH] powerpc: ...
483
  		rc = -ENOMEM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
484
485
486
487
488
489
490
491
         		goto out_free;
         	}
  	state->dma_cmds = (struct dbdma_cmd *)DBDMA_ALIGN(dma_cmd_space);
  	memset(state->dma_cmds, 0, (host->sg_tablesize + 1)
  	       * sizeof(struct dbdma_cmd));
  	state->dma_cmd_space = dma_cmd_space;
  
  	mac53c94_init(state);
cc5d0189b   Benjamin Herrenschmidt   [PATCH] powerpc: ...
492
  	if (request_irq(state->intr, do_mac53c94_interrupt, 0, "53C94",state)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
493
494
495
496
497
  		printk(KERN_ERR "mac53C94: can't get irq %d for %s
  ",
  		       state->intr, node->full_name);
  		goto out_free_dma;
  	}
cc5d0189b   Benjamin Herrenschmidt   [PATCH] powerpc: ...
498
499
500
  	rc = scsi_add_host(host, &mdev->ofdev.dev);
  	if (rc != 0)
  		goto out_release_irq;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
501

cc5d0189b   Benjamin Herrenschmidt   [PATCH] powerpc: ...
502
  	scsi_scan_host(host);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
503
  	return 0;
cc5d0189b   Benjamin Herrenschmidt   [PATCH] powerpc: ...
504
505
   out_release_irq:
  	free_irq(state->intr, state);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
506
507
508
509
510
511
512
513
514
515
   out_free_dma:
  	kfree(state->dma_cmd_space);
   out_free:
  	if (state->dma != NULL)
  		iounmap(state->dma);
  	if (state->regs != NULL)
  		iounmap(state->regs);
  	scsi_host_put(host);
   out_release:
  	macio_release_resources(mdev);
cc5d0189b   Benjamin Herrenschmidt   [PATCH] powerpc: ...
516
  	return rc;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
517
518
519
520
521
522
523
524
525
526
527
528
  }
  
  static int mac53c94_remove(struct macio_dev *mdev)
  {
  	struct fsc_state *fp = (struct fsc_state *)macio_get_drvdata(mdev);
  	struct Scsi_Host *host = fp->host;
  
  	scsi_remove_host(host);
  
  	free_irq(fp->intr, fp);
  
  	if (fp->regs)
7be7cbf68   Al Viro   [PATCH] drivers/s...
529
  		iounmap(fp->regs);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
530
  	if (fp->dma)
7be7cbf68   Al Viro   [PATCH] drivers/s...
531
  		iounmap(fp->dma);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
532
533
534
535
536
537
538
539
  	kfree(fp->dma_cmd_space);
  
  	scsi_host_put(host);
  
  	macio_release_resources(mdev);
  
  	return 0;
  }
5e6557722   Jeff Mahoney   [PATCH] openfirmw...
540
  static struct of_device_id mac53c94_match[] = 
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
541
542
543
  {
  	{
  	.name 		= "53c94",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
544
545
546
  	},
  	{},
  };
5e6557722   Jeff Mahoney   [PATCH] openfirmw...
547
  MODULE_DEVICE_TABLE (of, mac53c94_match);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
548
549
550
  
  static struct macio_driver mac53c94_driver = 
  {
c2cdf6aba   Benjamin Herrenschmidt   powerpc/macio: Fi...
551
552
553
554
555
  	.driver = {
  		.name 		= "mac53c94",
  		.owner		= THIS_MODULE,
  		.of_match_table	= mac53c94_match,
  	},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
  	.probe		= mac53c94_probe,
  	.remove		= mac53c94_remove,
  };
  
  
  static int __init init_mac53c94(void)
  {
  	return macio_register_driver(&mac53c94_driver);
  }
  
  static void __exit exit_mac53c94(void)
  {
  	return macio_unregister_driver(&mac53c94_driver);
  }
  
  module_init(init_mac53c94);
  module_exit(exit_mac53c94);
  
  MODULE_DESCRIPTION("PowerMac 53c94 SCSI driver");
  MODULE_AUTHOR("Paul Mackerras <paulus@samba.org>");
  MODULE_LICENSE("GPL");