hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/scsi/mac_esp.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /* mac_esp.c: ESP front-end for Macintosh Quadra systems.
23 *
34 * Adapted from jazz_esp.c and the old mac_esp.c.
....@@ -52,14 +53,12 @@
5253 struct esp *esp;
5354 void __iomem *pdma_regs;
5455 void __iomem *pdma_io;
55
- int error;
5656 };
5757 static struct esp *esp_chips[2];
5858 static DEFINE_SPINLOCK(esp_chips_lock);
5959
6060 #define MAC_ESP_GET_PRIV(esp) ((struct mac_esp_priv *) \
61
- platform_get_drvdata((struct platform_device *) \
62
- (esp->dev)))
61
+ dev_get_drvdata((esp)->dev))
6362
6463 static inline void mac_esp_write8(struct esp *esp, u8 val, unsigned long reg)
6564 {
....@@ -69,38 +68,6 @@
6968 static inline u8 mac_esp_read8(struct esp *esp, unsigned long reg)
7069 {
7170 return nubus_readb(esp->regs + reg * 16);
72
-}
73
-
74
-/* For pseudo DMA and PIO we need the virtual address
75
- * so this address mapping is the identity mapping.
76
- */
77
-
78
-static dma_addr_t mac_esp_map_single(struct esp *esp, void *buf,
79
- size_t sz, int dir)
80
-{
81
- return (dma_addr_t)buf;
82
-}
83
-
84
-static int mac_esp_map_sg(struct esp *esp, struct scatterlist *sg,
85
- int num_sg, int dir)
86
-{
87
- int i;
88
-
89
- for (i = 0; i < num_sg; i++)
90
- sg[i].dma_address = (u32)sg_virt(&sg[i]);
91
- return num_sg;
92
-}
93
-
94
-static void mac_esp_unmap_single(struct esp *esp, dma_addr_t addr,
95
- size_t sz, int dir)
96
-{
97
- /* Nothing to do. */
98
-}
99
-
100
-static void mac_esp_unmap_sg(struct esp *esp, struct scatterlist *sg,
101
- int num_sg, int dir)
102
-{
103
- /* Nothing to do. */
10471 }
10572
10673 static void mac_esp_reset_dma(struct esp *esp)
....@@ -120,12 +87,11 @@
12087
12188 static int mac_esp_dma_error(struct esp *esp)
12289 {
123
- return MAC_ESP_GET_PRIV(esp)->error;
90
+ return esp->send_cmd_error;
12491 }
12592
12693 static inline int mac_esp_wait_for_empty_fifo(struct esp *esp)
12794 {
128
- struct mac_esp_priv *mep = MAC_ESP_GET_PRIV(esp);
12995 int i = 500000;
13096
13197 do {
....@@ -140,7 +106,7 @@
140106
141107 printk(KERN_ERR PFX "FIFO is not empty (sreg %02x)\n",
142108 esp_read8(ESP_STATUS));
143
- mep->error = 1;
109
+ esp->send_cmd_error = 1;
144110 return 1;
145111 }
146112
....@@ -166,7 +132,7 @@
166132
167133 printk(KERN_ERR PFX "PDMA timeout (sreg %02x)\n",
168134 esp_read8(ESP_STATUS));
169
- mep->error = 1;
135
+ esp->send_cmd_error = 1;
170136 return 1;
171137 }
172138
....@@ -233,7 +199,7 @@
233199 {
234200 struct mac_esp_priv *mep = MAC_ESP_GET_PRIV(esp);
235201
236
- mep->error = 0;
202
+ esp->send_cmd_error = 0;
237203
238204 if (!write)
239205 scsi_esp_cmd(esp, ESP_CMD_FLUSH);
....@@ -269,166 +235,6 @@
269235 esp_count = n;
270236 }
271237 } while (esp_count);
272
-}
273
-
274
-/*
275
- * Programmed IO routines follow.
276
- */
277
-
278
-static inline unsigned int mac_esp_wait_for_fifo(struct esp *esp)
279
-{
280
- int i = 500000;
281
-
282
- do {
283
- unsigned int fbytes = esp_read8(ESP_FFLAGS) & ESP_FF_FBYTES;
284
-
285
- if (fbytes)
286
- return fbytes;
287
-
288
- udelay(2);
289
- } while (--i);
290
-
291
- printk(KERN_ERR PFX "FIFO is empty (sreg %02x)\n",
292
- esp_read8(ESP_STATUS));
293
- return 0;
294
-}
295
-
296
-static inline int mac_esp_wait_for_intr(struct esp *esp)
297
-{
298
- struct mac_esp_priv *mep = MAC_ESP_GET_PRIV(esp);
299
- int i = 500000;
300
-
301
- do {
302
- esp->sreg = esp_read8(ESP_STATUS);
303
- if (esp->sreg & ESP_STAT_INTR)
304
- return 0;
305
-
306
- udelay(2);
307
- } while (--i);
308
-
309
- printk(KERN_ERR PFX "IRQ timeout (sreg %02x)\n", esp->sreg);
310
- mep->error = 1;
311
- return 1;
312
-}
313
-
314
-#define MAC_ESP_PIO_LOOP(operands, reg1) \
315
- asm volatile ( \
316
- "1: moveb " operands " \n" \
317
- " subqw #1,%1 \n" \
318
- " jbne 1b \n" \
319
- : "+a" (addr), "+r" (reg1) \
320
- : "a" (fifo))
321
-
322
-#define MAC_ESP_PIO_FILL(operands, reg1) \
323
- asm volatile ( \
324
- " moveb " operands " \n" \
325
- " moveb " operands " \n" \
326
- " moveb " operands " \n" \
327
- " moveb " operands " \n" \
328
- " moveb " operands " \n" \
329
- " moveb " operands " \n" \
330
- " moveb " operands " \n" \
331
- " moveb " operands " \n" \
332
- " moveb " operands " \n" \
333
- " moveb " operands " \n" \
334
- " moveb " operands " \n" \
335
- " moveb " operands " \n" \
336
- " moveb " operands " \n" \
337
- " moveb " operands " \n" \
338
- " moveb " operands " \n" \
339
- " moveb " operands " \n" \
340
- " subqw #8,%1 \n" \
341
- " subqw #8,%1 \n" \
342
- : "+a" (addr), "+r" (reg1) \
343
- : "a" (fifo))
344
-
345
-#define MAC_ESP_FIFO_SIZE 16
346
-
347
-static void mac_esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count,
348
- u32 dma_count, int write, u8 cmd)
349
-{
350
- struct mac_esp_priv *mep = MAC_ESP_GET_PRIV(esp);
351
- u8 __iomem *fifo = esp->regs + ESP_FDATA * 16;
352
- u8 phase = esp->sreg & ESP_STAT_PMASK;
353
-
354
- cmd &= ~ESP_CMD_DMA;
355
- mep->error = 0;
356
-
357
- if (write) {
358
- u8 *dst = (u8 *)addr;
359
- u8 mask = ~(phase == ESP_MIP ? ESP_INTR_FDONE : ESP_INTR_BSERV);
360
-
361
- scsi_esp_cmd(esp, cmd);
362
-
363
- while (1) {
364
- if (!mac_esp_wait_for_fifo(esp))
365
- break;
366
-
367
- *dst++ = esp_read8(ESP_FDATA);
368
- --esp_count;
369
-
370
- if (!esp_count)
371
- break;
372
-
373
- if (mac_esp_wait_for_intr(esp))
374
- break;
375
-
376
- if ((esp->sreg & ESP_STAT_PMASK) != phase)
377
- break;
378
-
379
- esp->ireg = esp_read8(ESP_INTRPT);
380
- if (esp->ireg & mask) {
381
- mep->error = 1;
382
- break;
383
- }
384
-
385
- if (phase == ESP_MIP)
386
- scsi_esp_cmd(esp, ESP_CMD_MOK);
387
-
388
- scsi_esp_cmd(esp, ESP_CMD_TI);
389
- }
390
- } else {
391
- scsi_esp_cmd(esp, ESP_CMD_FLUSH);
392
-
393
- if (esp_count >= MAC_ESP_FIFO_SIZE)
394
- MAC_ESP_PIO_FILL("%0@+,%2@", esp_count);
395
- else
396
- MAC_ESP_PIO_LOOP("%0@+,%2@", esp_count);
397
-
398
- scsi_esp_cmd(esp, cmd);
399
-
400
- while (esp_count) {
401
- unsigned int n;
402
-
403
- if (mac_esp_wait_for_intr(esp))
404
- break;
405
-
406
- if ((esp->sreg & ESP_STAT_PMASK) != phase)
407
- break;
408
-
409
- esp->ireg = esp_read8(ESP_INTRPT);
410
- if (esp->ireg & ~ESP_INTR_BSERV) {
411
- mep->error = 1;
412
- break;
413
- }
414
-
415
- n = MAC_ESP_FIFO_SIZE -
416
- (esp_read8(ESP_FFLAGS) & ESP_FF_FBYTES);
417
- if (n > esp_count)
418
- n = esp_count;
419
-
420
- if (n == MAC_ESP_FIFO_SIZE) {
421
- MAC_ESP_PIO_FILL("%0@+,%2@", esp_count);
422
- } else {
423
- esp_count -= n;
424
- MAC_ESP_PIO_LOOP("%0@+,%2@", n);
425
- }
426
-
427
- scsi_esp_cmd(esp, ESP_CMD_TI);
428
- }
429
- }
430
-
431
- esp->send_cmd_residual = esp_count;
432238 }
433239
434240 static int mac_esp_irq_pending(struct esp *esp)
....@@ -472,10 +278,6 @@
472278 static struct esp_driver_ops mac_esp_ops = {
473279 .esp_write8 = mac_esp_write8,
474280 .esp_read8 = mac_esp_read8,
475
- .map_single = mac_esp_map_single,
476
- .map_sg = mac_esp_map_sg,
477
- .unmap_single = mac_esp_unmap_single,
478
- .unmap_sg = mac_esp_unmap_sg,
479281 .irq_pending = mac_esp_irq_pending,
480282 .dma_length_limit = mac_esp_dma_length_limit,
481283 .reset_dma = mac_esp_reset_dma,
....@@ -506,11 +308,11 @@
506308 goto fail;
507309
508310 host->max_id = 8;
509
- host->use_clustering = DISABLE_CLUSTERING;
311
+ host->dma_boundary = PAGE_SIZE - 1;
510312 esp = shost_priv(host);
511313
512314 esp->host = host;
513
- esp->dev = dev;
315
+ esp->dev = &dev->dev;
514316
515317 esp->command_block = kzalloc(16, GFP_KERNEL);
516318 if (!esp->command_block)
....@@ -553,14 +355,16 @@
553355 mep->pdma_regs = NULL;
554356 break;
555357 }
358
+ esp->fifo_reg = esp->regs + ESP_FDATA * 16;
556359
557360 esp->ops = &mac_esp_ops;
361
+ esp->flags = ESP_FLAG_NO_DMA_MAP;
558362 if (mep->pdma_io == NULL) {
559363 printk(KERN_INFO PFX "using PIO for controller %d\n", dev->id);
560364 esp_write8(0, ESP_TCLOW);
561365 esp_write8(0, ESP_TCMED);
562
- esp->flags = ESP_FLAG_DISABLE_SYNC;
563
- mac_esp_ops.send_dma_cmd = mac_esp_send_pio_cmd;
366
+ esp->flags |= ESP_FLAG_DISABLE_SYNC;
367
+ mac_esp_ops.send_dma_cmd = esp_send_pio_cmd;
564368 } else {
565369 printk(KERN_INFO PFX "using PDMA for controller %d\n", dev->id);
566370 }
....@@ -579,7 +383,7 @@
579383 esp_chips[dev->id] = esp;
580384 spin_unlock(&esp_chips_lock);
581385
582
- err = scsi_esp_register(esp, &dev->dev);
386
+ err = scsi_esp_register(esp);
583387 if (err)
584388 goto fail_free_irq;
585389
....@@ -635,22 +439,10 @@
635439 .name = DRV_MODULE_NAME,
636440 },
637441 };
638
-
639
-static int __init mac_esp_init(void)
640
-{
641
- return platform_driver_register(&esp_mac_driver);
642
-}
643
-
644
-static void __exit mac_esp_exit(void)
645
-{
646
- platform_driver_unregister(&esp_mac_driver);
647
-}
442
+module_platform_driver(esp_mac_driver);
648443
649444 MODULE_DESCRIPTION("Mac ESP SCSI driver");
650445 MODULE_AUTHOR("Finn Thain");
651446 MODULE_LICENSE("GPL v2");
652447 MODULE_VERSION(DRV_VERSION);
653448 MODULE_ALIAS("platform:" DRV_MODULE_NAME);
654
-
655
-module_init(mac_esp_init);
656
-module_exit(mac_esp_exit);