aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/atari_scsi.c
diff options
context:
space:
mode:
authorFinn Thain <fthain@telegraphics.com.au>2014-11-12 00:12:09 -0500
committerChristoph Hellwig <hch@lst.de>2014-11-20 03:11:14 -0500
commit3ff228af84b57767645d81a89c166c777646ad61 (patch)
tree85b68500170df132eff06a9526409bfe488ddd58 /drivers/scsi/atari_scsi.c
parent16b29e75a78ae03250233468b68f7ae467d3dc7a (diff)
atari_scsi: Convert to platform device
Convert atari_scsi to platform device and eliminate scsi_register(). Validate __setup options later on so that module options are checked as well. Remove the comment about the scsi mid-layer disabling the host irq as it is no longer true (AFAICT). Also remove the obsolete slow interrupt stuff (IRQ_TYPE_SLOW == 0 anyway). Signed-off-by: Finn Thain <fthain@telegraphics.com.au> Reviewed-by: Hannes Reinecke <hare@suse.de> Tested-by: Michael Schmitz <schmitzmic@gmail.com> Acked-by: Geert Uytterhoeven <geert@linux-m68k.org> Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'drivers/scsi/atari_scsi.c')
-rw-r--r--drivers/scsi/atari_scsi.c424
1 files changed, 210 insertions, 214 deletions
diff --git a/drivers/scsi/atari_scsi.c b/drivers/scsi/atari_scsi.c
index b2e86d0630ce..b765e1c2277f 100644
--- a/drivers/scsi/atari_scsi.c
+++ b/drivers/scsi/atari_scsi.c
@@ -74,33 +74,26 @@
74#define MAX_TAGS 32 74#define MAX_TAGS 32
75 75
76#include <linux/types.h> 76#include <linux/types.h>
77#include <linux/stddef.h>
78#include <linux/ctype.h>
79#include <linux/delay.h> 77#include <linux/delay.h>
80#include <linux/mm.h>
81#include <linux/blkdev.h> 78#include <linux/blkdev.h>
82#include <linux/interrupt.h> 79#include <linux/interrupt.h>
83#include <linux/init.h> 80#include <linux/init.h>
84#include <linux/nvram.h> 81#include <linux/nvram.h>
85#include <linux/bitops.h> 82#include <linux/bitops.h>
86#include <linux/wait.h> 83#include <linux/wait.h>
84#include <linux/platform_device.h>
87 85
88#include <asm/setup.h> 86#include <asm/setup.h>
89#include <asm/atarihw.h> 87#include <asm/atarihw.h>
90#include <asm/atariints.h> 88#include <asm/atariints.h>
91#include <asm/page.h>
92#include <asm/pgtable.h>
93#include <asm/irq.h>
94#include <asm/traps.h>
95
96#include <scsi/scsi_host.h>
97#include "atari_scsi.h"
98#include "NCR5380.h"
99#include <asm/atari_stdma.h> 89#include <asm/atari_stdma.h>
100#include <asm/atari_stram.h> 90#include <asm/atari_stram.h>
101#include <asm/io.h> 91#include <asm/io.h>
102 92
103#include <linux/stat.h> 93#include <scsi/scsi_host.h>
94
95#include "atari_scsi.h"
96#include "NCR5380.h"
104 97
105#define IS_A_TT() ATARIHW_PRESENT(TT_SCSI) 98#define IS_A_TT() ATARIHW_PRESENT(TT_SCSI)
106 99
@@ -176,25 +169,9 @@ static inline void DISABLE_IRQ(void)
176#define AFTER_RESET_DELAY (5*HZ/2) 169#define AFTER_RESET_DELAY (5*HZ/2)
177#endif 170#endif
178 171
179/***************************** Prototypes *****************************/
180
181#ifdef REAL_DMA 172#ifdef REAL_DMA
182static void atari_scsi_fetch_restbytes(void); 173static void atari_scsi_fetch_restbytes(void);
183#endif 174#endif
184static irqreturn_t scsi_tt_intr(int irq, void *dummy);
185static irqreturn_t scsi_falcon_intr(int irq, void *dummy);
186static void falcon_release_lock_if_possible(struct NCR5380_hostdata *hostdata);
187static int falcon_get_lock(void);
188#ifdef CONFIG_ATARI_SCSI_RESET_BOOT
189static void atari_scsi_reset_boot(void);
190#endif
191static unsigned char atari_scsi_tt_reg_read(unsigned char reg);
192static void atari_scsi_tt_reg_write(unsigned char reg, unsigned char value);
193static unsigned char atari_scsi_falcon_reg_read(unsigned char reg);
194static void atari_scsi_falcon_reg_write(unsigned char reg, unsigned char value);
195
196/************************* End of Prototypes **************************/
197
198 175
199static struct Scsi_Host *atari_scsi_host; 176static struct Scsi_Host *atari_scsi_host;
200static unsigned char (*atari_scsi_reg_read)(unsigned char reg); 177static unsigned char (*atari_scsi_reg_read)(unsigned char reg);
@@ -517,160 +494,12 @@ static int falcon_get_lock(void)
517 return 1; 494 return 1;
518} 495}
519 496
520
521static int __init atari_scsi_detect(struct scsi_host_template *host)
522{
523 static int called = 0;
524 struct Scsi_Host *instance;
525
526 if (!MACH_IS_ATARI ||
527 (!ATARIHW_PRESENT(ST_SCSI) && !ATARIHW_PRESENT(TT_SCSI)) ||
528 called)
529 return 0;
530
531 host->proc_name = "Atari";
532
533 atari_scsi_reg_read = IS_A_TT() ? atari_scsi_tt_reg_read :
534 atari_scsi_falcon_reg_read;
535 atari_scsi_reg_write = IS_A_TT() ? atari_scsi_tt_reg_write :
536 atari_scsi_falcon_reg_write;
537
538 /* setup variables */
539 host->can_queue =
540 (setup_can_queue > 0) ? setup_can_queue :
541 IS_A_TT() ? ATARI_TT_CAN_QUEUE : ATARI_FALCON_CAN_QUEUE;
542 host->cmd_per_lun =
543 (setup_cmd_per_lun > 0) ? setup_cmd_per_lun :
544 IS_A_TT() ? ATARI_TT_CMD_PER_LUN : ATARI_FALCON_CMD_PER_LUN;
545 /* Force sg_tablesize to 0 on a Falcon! */
546 host->sg_tablesize =
547 !IS_A_TT() ? ATARI_FALCON_SG_TABLESIZE :
548 (setup_sg_tablesize >= 0) ? setup_sg_tablesize : ATARI_TT_SG_TABLESIZE;
549
550 if (setup_hostid >= 0)
551 host->this_id = setup_hostid;
552 else {
553 /* use 7 as default */
554 host->this_id = 7;
555 /* Test if a host id is set in the NVRam */
556 if (ATARIHW_PRESENT(TT_CLK) && nvram_check_checksum()) {
557 unsigned char b = nvram_read_byte( 14 );
558 /* Arbitration enabled? (for TOS) If yes, use configured host ID */
559 if (b & 0x80)
560 host->this_id = b & 7;
561 }
562 }
563
564#ifdef SUPPORT_TAGS
565 if (setup_use_tagged_queuing < 0)
566 setup_use_tagged_queuing = 0;
567#endif
568#ifdef REAL_DMA
569 /* If running on a Falcon and if there's TT-Ram (i.e., more than one
570 * memory block, since there's always ST-Ram in a Falcon), then allocate a
571 * STRAM_BUFFER_SIZE byte dribble buffer for transfers from/to alternative
572 * Ram.
573 */
574 if (MACH_IS_ATARI && ATARIHW_PRESENT(ST_SCSI) &&
575 !ATARIHW_PRESENT(EXTD_DMA) && m68k_num_memory > 1) {
576 atari_dma_buffer = atari_stram_alloc(STRAM_BUFFER_SIZE, "SCSI");
577 if (!atari_dma_buffer) {
578 printk(KERN_ERR "atari_scsi_detect: can't allocate ST-RAM "
579 "double buffer\n");
580 return 0;
581 }
582 atari_dma_phys_buffer = atari_stram_to_phys(atari_dma_buffer);
583 atari_dma_orig_addr = 0;
584 }
585#endif
586 instance = scsi_register(host, sizeof(struct NCR5380_hostdata));
587 if (instance == NULL) {
588 atari_stram_free(atari_dma_buffer);
589 atari_dma_buffer = 0;
590 return 0;
591 }
592 atari_scsi_host = instance;
593 /*
594 * Set irq to 0, to avoid that the mid-level code disables our interrupt
595 * during queue_command calls. This is completely unnecessary, and even
596 * worse causes bad problems on the Falcon, where the int is shared with
597 * IDE and floppy!
598 */
599 instance->irq = 0;
600
601#ifdef CONFIG_ATARI_SCSI_RESET_BOOT
602 atari_scsi_reset_boot();
603#endif
604 NCR5380_init(instance, 0);
605
606 if (IS_A_TT()) {
607
608 /* This int is actually "pseudo-slow", i.e. it acts like a slow
609 * interrupt after having cleared the pending flag for the DMA
610 * interrupt. */
611 if (request_irq(IRQ_TT_MFP_SCSI, scsi_tt_intr, IRQ_TYPE_SLOW,
612 "SCSI NCR5380", instance)) {
613 printk(KERN_ERR "atari_scsi_detect: cannot allocate irq %d, aborting",IRQ_TT_MFP_SCSI);
614 scsi_unregister(atari_scsi_host);
615 atari_stram_free(atari_dma_buffer);
616 atari_dma_buffer = 0;
617 return 0;
618 }
619 tt_mfp.active_edge |= 0x80; /* SCSI int on L->H */
620#ifdef REAL_DMA
621 tt_scsi_dma.dma_ctrl = 0;
622 atari_dma_residual = 0;
623
624 if (MACH_IS_MEDUSA) {
625 /* While the read overruns (described by Drew Eckhardt in
626 * NCR5380.c) never happened on TTs, they do in fact on the Medusa
627 * (This was the cause why SCSI didn't work right for so long
628 * there.) Since handling the overruns slows down a bit, I turned
629 * the #ifdef's into a runtime condition.
630 *
631 * In principle it should be sufficient to do max. 1 byte with
632 * PIO, but there is another problem on the Medusa with the DMA
633 * rest data register. So 'atari_read_overruns' is currently set
634 * to 4 to avoid having transfers that aren't a multiple of 4. If
635 * the rest data bug is fixed, this can be lowered to 1.
636 */
637 atari_read_overruns = 4;
638 }
639#endif /*REAL_DMA*/
640 } else { /* ! IS_A_TT */
641
642 /* Nothing to do for the interrupt: the ST-DMA is initialized
643 * already by atari_init_INTS()
644 */
645
646#ifdef REAL_DMA
647 atari_dma_residual = 0;
648 atari_dma_active = 0;
649 atari_dma_stram_mask = (ATARIHW_PRESENT(EXTD_DMA) ? 0x00000000
650 : 0xff000000);
651#endif
652 }
653
654 called = 1;
655 return 1;
656}
657
658static int atari_scsi_release(struct Scsi_Host *sh)
659{
660 if (IS_A_TT())
661 free_irq(IRQ_TT_MFP_SCSI, sh);
662 if (atari_dma_buffer)
663 atari_stram_free(atari_dma_buffer);
664 NCR5380_exit(sh);
665 return 1;
666}
667
668#ifndef MODULE 497#ifndef MODULE
669static int __init atari_scsi_setup(char *str) 498static int __init atari_scsi_setup(char *str)
670{ 499{
671 /* Format of atascsi parameter is: 500 /* Format of atascsi parameter is:
672 * atascsi=<can_queue>,<cmd_per_lun>,<sg_tablesize>,<hostid>,<use_tags> 501 * atascsi=<can_queue>,<cmd_per_lun>,<sg_tablesize>,<hostid>,<use_tags>
673 * Defaults depend on TT or Falcon, hostid determined at run time. 502 * Defaults depend on TT or Falcon, determined at run time.
674 * Negative values mean don't change. 503 * Negative values mean don't change.
675 */ 504 */
676 int ints[6]; 505 int ints[6];
@@ -681,36 +510,17 @@ static int __init atari_scsi_setup(char *str)
681 printk("atari_scsi_setup: no arguments!\n"); 510 printk("atari_scsi_setup: no arguments!\n");
682 return 0; 511 return 0;
683 } 512 }
684 513 if (ints[0] >= 1)
685 if (ints[0] >= 1) { 514 setup_can_queue = ints[1];
686 if (ints[1] > 0) 515 if (ints[0] >= 2)
687 /* no limits on this, just > 0 */ 516 setup_cmd_per_lun = ints[2];
688 setup_can_queue = ints[1]; 517 if (ints[0] >= 3)
689 } 518 setup_sg_tablesize = ints[3];
690 if (ints[0] >= 2) { 519 if (ints[0] >= 4)
691 if (ints[2] > 0) 520 setup_hostid = ints[4];
692 setup_cmd_per_lun = ints[2];
693 }
694 if (ints[0] >= 3) {
695 if (ints[3] >= 0) {
696 setup_sg_tablesize = ints[3];
697 /* Must be <= SG_ALL (255) */
698 if (setup_sg_tablesize > SG_ALL)
699 setup_sg_tablesize = SG_ALL;
700 }
701 }
702 if (ints[0] >= 4) {
703 /* Must be between 0 and 7 */
704 if (ints[4] >= 0 && ints[4] <= 7)
705 setup_hostid = ints[4];
706 else if (ints[4] > 7)
707 printk("atari_scsi_setup: invalid host ID %d !\n", ints[4]);
708 }
709#ifdef SUPPORT_TAGS 521#ifdef SUPPORT_TAGS
710 if (ints[0] >= 5) { 522 if (ints[0] >= 5)
711 if (ints[5] >= 0) 523 setup_use_tagged_queuing = ints[5];
712 setup_use_tagged_queuing = !!ints[5];
713 }
714#endif 524#endif
715 525
716 return 1; 526 return 1;
@@ -1019,23 +829,209 @@ static int atari_scsi_bus_reset(struct scsi_cmnd *cmd)
1019 return rv; 829 return rv;
1020} 830}
1021 831
1022static struct scsi_host_template driver_template = { 832#define DRV_MODULE_NAME "atari_scsi"
833#define PFX DRV_MODULE_NAME ": "
834
835static struct scsi_host_template atari_scsi_template = {
836 .module = THIS_MODULE,
837 .proc_name = DRV_MODULE_NAME,
1023 .show_info = atari_scsi_show_info, 838 .show_info = atari_scsi_show_info,
1024 .name = "Atari native SCSI", 839 .name = "Atari native SCSI",
1025 .detect = atari_scsi_detect,
1026 .release = atari_scsi_release,
1027 .info = atari_scsi_info, 840 .info = atari_scsi_info,
1028 .queuecommand = atari_scsi_queue_command, 841 .queuecommand = atari_scsi_queue_command,
1029 .eh_abort_handler = atari_scsi_abort, 842 .eh_abort_handler = atari_scsi_abort,
1030 .eh_bus_reset_handler = atari_scsi_bus_reset, 843 .eh_bus_reset_handler = atari_scsi_bus_reset,
1031 .can_queue = 0, /* initialized at run-time */ 844 .this_id = 7,
1032 .this_id = 0, /* initialized at run-time */
1033 .sg_tablesize = 0, /* initialized at run-time */
1034 .cmd_per_lun = 0, /* initialized at run-time */
1035 .use_clustering = DISABLE_CLUSTERING 845 .use_clustering = DISABLE_CLUSTERING
1036}; 846};
1037 847
848static int __init atari_scsi_probe(struct platform_device *pdev)
849{
850 struct Scsi_Host *instance;
851 int error;
852 struct resource *irq;
853
854 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
855 if (!irq)
856 return -ENODEV;
857
858 if (ATARIHW_PRESENT(TT_SCSI)) {
859 atari_scsi_reg_read = atari_scsi_tt_reg_read;
860 atari_scsi_reg_write = atari_scsi_tt_reg_write;
861 } else {
862 atari_scsi_reg_read = atari_scsi_falcon_reg_read;
863 atari_scsi_reg_write = atari_scsi_falcon_reg_write;
864 }
865
866 /* The values for CMD_PER_LUN and CAN_QUEUE are somehow arbitrary.
867 * Higher values should work, too; try it!
868 * (But cmd_per_lun costs memory!)
869 *
870 * But there seems to be a bug somewhere that requires CAN_QUEUE to be
871 * 2*CMD_PER_LUN. At least on a TT, no spurious timeouts seen since
872 * changed CMD_PER_LUN...
873 *
874 * Note: The Falcon currently uses 8/1 setting due to unsolved problems
875 * with cmd_per_lun != 1
876 */
877 if (ATARIHW_PRESENT(TT_SCSI)) {
878 atari_scsi_template.can_queue = 16;
879 atari_scsi_template.cmd_per_lun = 8;
880 atari_scsi_template.sg_tablesize = SG_ALL;
881 } else {
882 atari_scsi_template.can_queue = 8;
883 atari_scsi_template.cmd_per_lun = 1;
884 atari_scsi_template.sg_tablesize = SG_NONE;
885 }
886
887 if (setup_can_queue > 0)
888 atari_scsi_template.can_queue = setup_can_queue;
889
890 if (setup_cmd_per_lun > 0)
891 atari_scsi_template.cmd_per_lun = setup_cmd_per_lun;
892
893 /* Leave sg_tablesize at 0 on a Falcon! */
894 if (ATARIHW_PRESENT(TT_SCSI) && setup_sg_tablesize >= 0)
895 atari_scsi_template.sg_tablesize = setup_sg_tablesize;
896
897 if (setup_hostid >= 0) {
898 atari_scsi_template.this_id = setup_hostid & 7;
899 } else {
900 /* Test if a host id is set in the NVRam */
901 if (ATARIHW_PRESENT(TT_CLK) && nvram_check_checksum()) {
902 unsigned char b = nvram_read_byte(14);
903
904 /* Arbitration enabled? (for TOS)
905 * If yes, use configured host ID
906 */
907 if (b & 0x80)
908 atari_scsi_template.this_id = b & 7;
909 }
910 }
911
912#ifdef SUPPORT_TAGS
913 if (setup_use_tagged_queuing < 0)
914 setup_use_tagged_queuing = 0;
915#endif
916
917#ifdef REAL_DMA
918 /* If running on a Falcon and if there's TT-Ram (i.e., more than one
919 * memory block, since there's always ST-Ram in a Falcon), then
920 * allocate a STRAM_BUFFER_SIZE byte dribble buffer for transfers
921 * from/to alternative Ram.
922 */
923 if (ATARIHW_PRESENT(ST_SCSI) && !ATARIHW_PRESENT(EXTD_DMA) &&
924 m68k_num_memory > 1) {
925 atari_dma_buffer = atari_stram_alloc(STRAM_BUFFER_SIZE, "SCSI");
926 if (!atari_dma_buffer) {
927 pr_err(PFX "can't allocate ST-RAM double buffer\n");
928 return -ENOMEM;
929 }
930 atari_dma_phys_buffer = atari_stram_to_phys(atari_dma_buffer);
931 atari_dma_orig_addr = 0;
932 }
933#endif
934
935 instance = scsi_host_alloc(&atari_scsi_template,
936 sizeof(struct NCR5380_hostdata));
937 if (!instance) {
938 error = -ENOMEM;
939 goto fail_alloc;
940 }
941 atari_scsi_host = instance;
942
943#ifdef CONFIG_ATARI_SCSI_RESET_BOOT
944 atari_scsi_reset_boot();
945#endif
946
947 instance->irq = irq->start;
948
949 NCR5380_init(instance, 0);
950
951 if (IS_A_TT()) {
952 error = request_irq(instance->irq, scsi_tt_intr, 0,
953 "NCR5380", instance);
954 if (error) {
955 pr_err(PFX "request irq %d failed, aborting\n",
956 instance->irq);
957 goto fail_irq;
958 }
959 tt_mfp.active_edge |= 0x80; /* SCSI int on L->H */
960#ifdef REAL_DMA
961 tt_scsi_dma.dma_ctrl = 0;
962 atari_dma_residual = 0;
963
964 /* While the read overruns (described by Drew Eckhardt in
965 * NCR5380.c) never happened on TTs, they do in fact on the
966 * Medusa (This was the cause why SCSI didn't work right for
967 * so long there.) Since handling the overruns slows down
968 * a bit, I turned the #ifdef's into a runtime condition.
969 *
970 * In principle it should be sufficient to do max. 1 byte with
971 * PIO, but there is another problem on the Medusa with the DMA
972 * rest data register. So 'atari_read_overruns' is currently set
973 * to 4 to avoid having transfers that aren't a multiple of 4.
974 * If the rest data bug is fixed, this can be lowered to 1.
975 */
976 if (MACH_IS_MEDUSA)
977 atari_read_overruns = 4;
978#endif
979 } else {
980 /* Nothing to do for the interrupt: the ST-DMA is initialized
981 * already.
982 */
983#ifdef REAL_DMA
984 atari_dma_residual = 0;
985 atari_dma_active = 0;
986 atari_dma_stram_mask = (ATARIHW_PRESENT(EXTD_DMA) ? 0x00000000
987 : 0xff000000);
988#endif
989 }
990
991 error = scsi_add_host(instance, NULL);
992 if (error)
993 goto fail_host;
994
995 platform_set_drvdata(pdev, instance);
996
997 scsi_scan_host(instance);
998 return 0;
999
1000fail_host:
1001 if (IS_A_TT())
1002 free_irq(instance->irq, instance);
1003fail_irq:
1004 NCR5380_exit(instance);
1005 scsi_host_put(instance);
1006fail_alloc:
1007 if (atari_dma_buffer)
1008 atari_stram_free(atari_dma_buffer);
1009 return error;
1010}
1011
1012static int __exit atari_scsi_remove(struct platform_device *pdev)
1013{
1014 struct Scsi_Host *instance = platform_get_drvdata(pdev);
1015
1016 scsi_remove_host(instance);
1017 if (IS_A_TT())
1018 free_irq(instance->irq, instance);
1019 NCR5380_exit(instance);
1020 scsi_host_put(instance);
1021 if (atari_dma_buffer)
1022 atari_stram_free(atari_dma_buffer);
1023 return 0;
1024}
1025
1026static struct platform_driver atari_scsi_driver = {
1027 .remove = __exit_p(atari_scsi_remove),
1028 .driver = {
1029 .name = DRV_MODULE_NAME,
1030 .owner = THIS_MODULE,
1031 },
1032};
1038 1033
1039#include "scsi_module.c" 1034module_platform_driver_probe(atari_scsi_driver, atari_scsi_probe);
1040 1035
1036MODULE_ALIAS("platform:" DRV_MODULE_NAME);
1041MODULE_LICENSE("GPL"); 1037MODULE_LICENSE("GPL");