| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* mac_esp.c: ESP front-end for Macintosh Quadra systems. |
|---|
| 2 | 3 | * |
|---|
| 3 | 4 | * Adapted from jazz_esp.c and the old mac_esp.c. |
|---|
| .. | .. |
|---|
| 52 | 53 | struct esp *esp; |
|---|
| 53 | 54 | void __iomem *pdma_regs; |
|---|
| 54 | 55 | void __iomem *pdma_io; |
|---|
| 55 | | - int error; |
|---|
| 56 | 56 | }; |
|---|
| 57 | 57 | static struct esp *esp_chips[2]; |
|---|
| 58 | 58 | static DEFINE_SPINLOCK(esp_chips_lock); |
|---|
| 59 | 59 | |
|---|
| 60 | 60 | #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)) |
|---|
| 63 | 62 | |
|---|
| 64 | 63 | static inline void mac_esp_write8(struct esp *esp, u8 val, unsigned long reg) |
|---|
| 65 | 64 | { |
|---|
| .. | .. |
|---|
| 69 | 68 | static inline u8 mac_esp_read8(struct esp *esp, unsigned long reg) |
|---|
| 70 | 69 | { |
|---|
| 71 | 70 | 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. */ |
|---|
| 104 | 71 | } |
|---|
| 105 | 72 | |
|---|
| 106 | 73 | static void mac_esp_reset_dma(struct esp *esp) |
|---|
| .. | .. |
|---|
| 120 | 87 | |
|---|
| 121 | 88 | static int mac_esp_dma_error(struct esp *esp) |
|---|
| 122 | 89 | { |
|---|
| 123 | | - return MAC_ESP_GET_PRIV(esp)->error; |
|---|
| 90 | + return esp->send_cmd_error; |
|---|
| 124 | 91 | } |
|---|
| 125 | 92 | |
|---|
| 126 | 93 | static inline int mac_esp_wait_for_empty_fifo(struct esp *esp) |
|---|
| 127 | 94 | { |
|---|
| 128 | | - struct mac_esp_priv *mep = MAC_ESP_GET_PRIV(esp); |
|---|
| 129 | 95 | int i = 500000; |
|---|
| 130 | 96 | |
|---|
| 131 | 97 | do { |
|---|
| .. | .. |
|---|
| 140 | 106 | |
|---|
| 141 | 107 | printk(KERN_ERR PFX "FIFO is not empty (sreg %02x)\n", |
|---|
| 142 | 108 | esp_read8(ESP_STATUS)); |
|---|
| 143 | | - mep->error = 1; |
|---|
| 109 | + esp->send_cmd_error = 1; |
|---|
| 144 | 110 | return 1; |
|---|
| 145 | 111 | } |
|---|
| 146 | 112 | |
|---|
| .. | .. |
|---|
| 166 | 132 | |
|---|
| 167 | 133 | printk(KERN_ERR PFX "PDMA timeout (sreg %02x)\n", |
|---|
| 168 | 134 | esp_read8(ESP_STATUS)); |
|---|
| 169 | | - mep->error = 1; |
|---|
| 135 | + esp->send_cmd_error = 1; |
|---|
| 170 | 136 | return 1; |
|---|
| 171 | 137 | } |
|---|
| 172 | 138 | |
|---|
| .. | .. |
|---|
| 233 | 199 | { |
|---|
| 234 | 200 | struct mac_esp_priv *mep = MAC_ESP_GET_PRIV(esp); |
|---|
| 235 | 201 | |
|---|
| 236 | | - mep->error = 0; |
|---|
| 202 | + esp->send_cmd_error = 0; |
|---|
| 237 | 203 | |
|---|
| 238 | 204 | if (!write) |
|---|
| 239 | 205 | scsi_esp_cmd(esp, ESP_CMD_FLUSH); |
|---|
| .. | .. |
|---|
| 269 | 235 | esp_count = n; |
|---|
| 270 | 236 | } |
|---|
| 271 | 237 | } 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; |
|---|
| 432 | 238 | } |
|---|
| 433 | 239 | |
|---|
| 434 | 240 | static int mac_esp_irq_pending(struct esp *esp) |
|---|
| .. | .. |
|---|
| 472 | 278 | static struct esp_driver_ops mac_esp_ops = { |
|---|
| 473 | 279 | .esp_write8 = mac_esp_write8, |
|---|
| 474 | 280 | .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, |
|---|
| 479 | 281 | .irq_pending = mac_esp_irq_pending, |
|---|
| 480 | 282 | .dma_length_limit = mac_esp_dma_length_limit, |
|---|
| 481 | 283 | .reset_dma = mac_esp_reset_dma, |
|---|
| .. | .. |
|---|
| 506 | 308 | goto fail; |
|---|
| 507 | 309 | |
|---|
| 508 | 310 | host->max_id = 8; |
|---|
| 509 | | - host->use_clustering = DISABLE_CLUSTERING; |
|---|
| 311 | + host->dma_boundary = PAGE_SIZE - 1; |
|---|
| 510 | 312 | esp = shost_priv(host); |
|---|
| 511 | 313 | |
|---|
| 512 | 314 | esp->host = host; |
|---|
| 513 | | - esp->dev = dev; |
|---|
| 315 | + esp->dev = &dev->dev; |
|---|
| 514 | 316 | |
|---|
| 515 | 317 | esp->command_block = kzalloc(16, GFP_KERNEL); |
|---|
| 516 | 318 | if (!esp->command_block) |
|---|
| .. | .. |
|---|
| 553 | 355 | mep->pdma_regs = NULL; |
|---|
| 554 | 356 | break; |
|---|
| 555 | 357 | } |
|---|
| 358 | + esp->fifo_reg = esp->regs + ESP_FDATA * 16; |
|---|
| 556 | 359 | |
|---|
| 557 | 360 | esp->ops = &mac_esp_ops; |
|---|
| 361 | + esp->flags = ESP_FLAG_NO_DMA_MAP; |
|---|
| 558 | 362 | if (mep->pdma_io == NULL) { |
|---|
| 559 | 363 | printk(KERN_INFO PFX "using PIO for controller %d\n", dev->id); |
|---|
| 560 | 364 | esp_write8(0, ESP_TCLOW); |
|---|
| 561 | 365 | 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; |
|---|
| 564 | 368 | } else { |
|---|
| 565 | 369 | printk(KERN_INFO PFX "using PDMA for controller %d\n", dev->id); |
|---|
| 566 | 370 | } |
|---|
| .. | .. |
|---|
| 579 | 383 | esp_chips[dev->id] = esp; |
|---|
| 580 | 384 | spin_unlock(&esp_chips_lock); |
|---|
| 581 | 385 | |
|---|
| 582 | | - err = scsi_esp_register(esp, &dev->dev); |
|---|
| 386 | + err = scsi_esp_register(esp); |
|---|
| 583 | 387 | if (err) |
|---|
| 584 | 388 | goto fail_free_irq; |
|---|
| 585 | 389 | |
|---|
| .. | .. |
|---|
| 635 | 439 | .name = DRV_MODULE_NAME, |
|---|
| 636 | 440 | }, |
|---|
| 637 | 441 | }; |
|---|
| 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); |
|---|
| 648 | 443 | |
|---|
| 649 | 444 | MODULE_DESCRIPTION("Mac ESP SCSI driver"); |
|---|
| 650 | 445 | MODULE_AUTHOR("Finn Thain"); |
|---|
| 651 | 446 | MODULE_LICENSE("GPL v2"); |
|---|
| 652 | 447 | MODULE_VERSION(DRV_VERSION); |
|---|
| 653 | 448 | MODULE_ALIAS("platform:" DRV_MODULE_NAME); |
|---|
| 654 | | - |
|---|
| 655 | | -module_init(mac_esp_init); |
|---|
| 656 | | -module_exit(mac_esp_exit); |
|---|