aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata/pata_hpt37x.c
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2008-03-24 23:22:49 -0400
committerJeff Garzik <jgarzik@redhat.com>2008-04-17 15:44:17 -0400
commit029cfd6b74fc5c517865fad78cf4a3ea8d9b664a (patch)
tree4a40f44f29321e433497a51d2f6cfe1922ae1d58 /drivers/ata/pata_hpt37x.c
parent68d1d07b510bb57a504588adc2bd2758adea0965 (diff)
libata: implement and use ops inheritance
libata lets low level drivers build ata_port_operations table and register it with libata core layer. This allows low level drivers high level of flexibility but also burdens them with lots of boilerplate entries. This becomes worse for drivers which support related similar controllers which differ slightly. They share most of the operations except for a few. However, the driver still needs to list all operations for each variant. This results in large number of duplicate entries, which is not only inefficient but also error-prone as it becomes very difficult to tell what the actual differences are. This duplicate boilerplates all over the low level drivers also make updating the core layer exteremely difficult and error-prone. When compounded with multi-branched development model, it ends up accumulating inconsistencies over time. Some of those inconsistencies cause immediate problems and fixed. Others just remain there dormant making maintenance increasingly difficult. To rectify the problem, this patch implements ata_port_operations inheritance. To allow LLDs to easily re-use their own ops tables overriding only specific methods, this patch implements poor man's class inheritance. An ops table has ->inherits field which can be set to any ops table as long as it doesn't create a loop. When the host is started, the inheritance chain is followed and any operation which isn't specified is taken from the nearest ancestor which has it specified. This operation is called finalization and done only once per an ops table and the LLD doesn't have to do anything special about it other than making the ops table non-const such that libata can update it. libata provides four base ops tables lower drivers can inherit from - base, sata, pmp, sff and bmdma. To avoid overriding these ops accidentaly, these ops are declared const and LLDs should always inherit these instead of using them directly. After finalization, all the ops table are identical before and after the patch except for setting .irq_handler to ata_interrupt in drivers which didn't use to. The .irq_handler doesn't have any actual effect and the field will soon be removed by later patch. * sata_sx4 is still using old style EH and currently doesn't take advantage of ops inheritance. Signed-off-by: Tejun Heo <htejun@gmail.com>
Diffstat (limited to 'drivers/ata/pata_hpt37x.c')
-rw-r--r--drivers/ata/pata_hpt37x.c122
1 files changed, 11 insertions, 111 deletions
diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
index 7d6fac43e2f9..c42eec70d297 100644
--- a/drivers/ata/pata_hpt37x.c
+++ b/drivers/ata/pata_hpt37x.c
@@ -627,36 +627,15 @@ static struct scsi_host_template hpt37x_sht = {
627 */ 627 */
628 628
629static struct ata_port_operations hpt370_port_ops = { 629static struct ata_port_operations hpt370_port_ops = {
630 .set_piomode = hpt370_set_piomode, 630 .inherits = &ata_bmdma_port_ops,
631 .set_dmamode = hpt370_set_dmamode,
632 .mode_filter = hpt370_filter,
633
634 .tf_load = ata_tf_load,
635 .tf_read = ata_tf_read,
636 .check_status = ata_check_status,
637 .exec_command = ata_exec_command,
638 .dev_select = ata_std_dev_select,
639
640 .freeze = ata_bmdma_freeze,
641 .thaw = ata_bmdma_thaw,
642 .error_handler = hpt37x_error_handler,
643 .post_internal_cmd = ata_bmdma_post_internal_cmd,
644 631
645 .bmdma_setup = ata_bmdma_setup,
646 .bmdma_start = hpt370_bmdma_start, 632 .bmdma_start = hpt370_bmdma_start,
647 .bmdma_stop = hpt370_bmdma_stop, 633 .bmdma_stop = hpt370_bmdma_stop,
648 .bmdma_status = ata_bmdma_status,
649 634
650 .qc_prep = ata_qc_prep, 635 .mode_filter = hpt370_filter,
651 .qc_issue = ata_qc_issue_prot, 636 .set_piomode = hpt370_set_piomode,
652 637 .set_dmamode = hpt370_set_dmamode,
653 .data_xfer = ata_data_xfer, 638 .error_handler = hpt37x_error_handler,
654
655 .irq_handler = ata_interrupt,
656 .irq_clear = ata_bmdma_irq_clear,
657 .irq_on = ata_irq_on,
658
659 .port_start = ata_sff_port_start,
660}; 639};
661 640
662/* 641/*
@@ -664,36 +643,8 @@ static struct ata_port_operations hpt370_port_ops = {
664 */ 643 */
665 644
666static struct ata_port_operations hpt370a_port_ops = { 645static struct ata_port_operations hpt370a_port_ops = {
667 .set_piomode = hpt370_set_piomode, 646 .inherits = &hpt370_port_ops,
668 .set_dmamode = hpt370_set_dmamode,
669 .mode_filter = hpt370a_filter, 647 .mode_filter = hpt370a_filter,
670
671 .tf_load = ata_tf_load,
672 .tf_read = ata_tf_read,
673 .check_status = ata_check_status,
674 .exec_command = ata_exec_command,
675 .dev_select = ata_std_dev_select,
676
677 .freeze = ata_bmdma_freeze,
678 .thaw = ata_bmdma_thaw,
679 .error_handler = hpt37x_error_handler,
680 .post_internal_cmd = ata_bmdma_post_internal_cmd,
681
682 .bmdma_setup = ata_bmdma_setup,
683 .bmdma_start = hpt370_bmdma_start,
684 .bmdma_stop = hpt370_bmdma_stop,
685 .bmdma_status = ata_bmdma_status,
686
687 .qc_prep = ata_qc_prep,
688 .qc_issue = ata_qc_issue_prot,
689
690 .data_xfer = ata_data_xfer,
691
692 .irq_handler = ata_interrupt,
693 .irq_clear = ata_bmdma_irq_clear,
694 .irq_on = ata_irq_on,
695
696 .port_start = ata_sff_port_start,
697}; 648};
698 649
699/* 650/*
@@ -702,36 +653,13 @@ static struct ata_port_operations hpt370a_port_ops = {
702 */ 653 */
703 654
704static struct ata_port_operations hpt372_port_ops = { 655static struct ata_port_operations hpt372_port_ops = {
705 .set_piomode = hpt372_set_piomode, 656 .inherits = &ata_bmdma_port_ops,
706 .set_dmamode = hpt372_set_dmamode,
707 .mode_filter = ata_pci_default_filter,
708
709 .tf_load = ata_tf_load,
710 .tf_read = ata_tf_read,
711 .check_status = ata_check_status,
712 .exec_command = ata_exec_command,
713 .dev_select = ata_std_dev_select,
714
715 .freeze = ata_bmdma_freeze,
716 .thaw = ata_bmdma_thaw,
717 .error_handler = hpt37x_error_handler,
718 .post_internal_cmd = ata_bmdma_post_internal_cmd,
719 657
720 .bmdma_setup = ata_bmdma_setup,
721 .bmdma_start = ata_bmdma_start,
722 .bmdma_stop = hpt37x_bmdma_stop, 658 .bmdma_stop = hpt37x_bmdma_stop,
723 .bmdma_status = ata_bmdma_status,
724
725 .qc_prep = ata_qc_prep,
726 .qc_issue = ata_qc_issue_prot,
727
728 .data_xfer = ata_data_xfer,
729 659
730 .irq_handler = ata_interrupt, 660 .set_piomode = hpt372_set_piomode,
731 .irq_clear = ata_bmdma_irq_clear, 661 .set_dmamode = hpt372_set_dmamode,
732 .irq_on = ata_irq_on, 662 .error_handler = hpt37x_error_handler,
733
734 .port_start = ata_sff_port_start,
735}; 663};
736 664
737/* 665/*
@@ -740,36 +668,8 @@ static struct ata_port_operations hpt372_port_ops = {
740 */ 668 */
741 669
742static struct ata_port_operations hpt374_port_ops = { 670static struct ata_port_operations hpt374_port_ops = {
743 .set_piomode = hpt372_set_piomode, 671 .inherits = &hpt372_port_ops,
744 .set_dmamode = hpt372_set_dmamode,
745 .mode_filter = ata_pci_default_filter,
746
747 .tf_load = ata_tf_load,
748 .tf_read = ata_tf_read,
749 .check_status = ata_check_status,
750 .exec_command = ata_exec_command,
751 .dev_select = ata_std_dev_select,
752
753 .freeze = ata_bmdma_freeze,
754 .thaw = ata_bmdma_thaw,
755 .error_handler = hpt374_error_handler, 672 .error_handler = hpt374_error_handler,
756 .post_internal_cmd = ata_bmdma_post_internal_cmd,
757
758 .bmdma_setup = ata_bmdma_setup,
759 .bmdma_start = ata_bmdma_start,
760 .bmdma_stop = hpt37x_bmdma_stop,
761 .bmdma_status = ata_bmdma_status,
762
763 .qc_prep = ata_qc_prep,
764 .qc_issue = ata_qc_issue_prot,
765
766 .data_xfer = ata_data_xfer,
767
768 .irq_handler = ata_interrupt,
769 .irq_clear = ata_bmdma_irq_clear,
770 .irq_on = ata_irq_on,
771
772 .port_start = ata_sff_port_start,
773}; 673};
774 674
775/** 675/**