3737#include "libata.h"
3838#include "libata-transport.h"
3939
40- #define ATA_PORT_ATTRS 3
41- #define ATA_LINK_ATTRS 3
42- #define ATA_DEV_ATTRS 9
43-
4440struct scsi_transport_template ;
4541struct scsi_transport_template * ata_scsi_transport_template ;
4642
4743struct ata_internal {
4844 struct scsi_transport_template t ;
4945
50- struct device_attribute private_port_attrs [ATA_PORT_ATTRS ];
51- struct device_attribute private_link_attrs [ATA_LINK_ATTRS ];
52- struct device_attribute private_dev_attrs [ATA_DEV_ATTRS ];
53-
5446 struct transport_container link_attr_cont ;
5547 struct transport_container dev_attr_cont ;
56-
57- /*
58- * The array of null terminated pointers to attributes
59- * needed by scsi_sysfs.c
60- */
61- struct device_attribute * link_attrs [ATA_LINK_ATTRS + 1 ];
62- struct device_attribute * port_attrs [ATA_PORT_ATTRS + 1 ];
63- struct device_attribute * dev_attrs [ATA_DEV_ATTRS + 1 ];
6448};
6549#define to_ata_internal (tmpl ) container_of(tmpl, struct ata_internal, t)
6650
67-
6851#define tdev_to_device (d ) \
6952 container_of((d), struct ata_device, tdev)
7053#define transport_class_to_dev (dev ) \
@@ -80,13 +63,6 @@ struct ata_internal {
8063#define transport_class_to_port (dev ) \
8164 tdev_to_port((dev)->parent)
8265
83- /*
84- * Hack to allow attributes of the same name in different objects.
85- */
86- #define ATA_DEVICE_ATTR (_prefix ,_name ,_mode ,_show ,_store ) \
87- struct device_attribute device_attr_##_prefix##_##_name = \
88- __ATTR(_name,_mode,_show,_store)
89-
9066#define ata_bitfield_name_match (title , table ) \
9167static ssize_t \
9268get_ata_##title##_names(u32 table_key, char *buf) \
@@ -214,6 +190,17 @@ ata_port_simple_attr(stats.idle_irq, idle_irq, "%ld\n", unsigned long);
214190/* We want the port_no sysfs attibute to start at 1 (ap->port_no starts at 0) */
215191ata_port_simple_attr (port_no + 1 , port_no , "%u\n" , unsigned int );
216192
193+ static const struct attribute * const ata_port_attr_attrs [] = {
194+ & dev_attr_nr_pmp_links .attr ,
195+ & dev_attr_idle_irq .attr ,
196+ & dev_attr_port_no .attr ,
197+ NULL
198+ };
199+
200+ static const struct attribute_group ata_port_attr_group = {
201+ .attrs_const = ata_port_attr_attrs ,
202+ };
203+
217204static DECLARE_TRANSPORT_CLASS (ata_port_class ,
218205 "ata_port ", NULL, NULL, NULL) ;
219206
@@ -496,6 +483,23 @@ show_ata_dev_trim(struct device *dev,
496483
497484static DEVICE_ATTR (trim , S_IRUGO , show_ata_dev_trim , NULL) ;
498485
486+ static const struct attribute * const ata_device_attr_attrs [] = {
487+ & dev_attr_class .attr ,
488+ & dev_attr_pio_mode .attr ,
489+ & dev_attr_dma_mode .attr ,
490+ & dev_attr_xfer_mode .attr ,
491+ & dev_attr_spdn_cnt .attr ,
492+ & dev_attr_ering .attr ,
493+ & dev_attr_id .attr ,
494+ & dev_attr_gscr .attr ,
495+ & dev_attr_trim .attr ,
496+ NULL
497+ };
498+
499+ static const struct attribute_group ata_device_attr_group = {
500+ .attrs_const = ata_device_attr_attrs ,
501+ };
502+
499503static DECLARE_TRANSPORT_CLASS (ata_dev_class ,
500504 "ata_device ", NULL, NULL, NULL) ;
501505
@@ -626,6 +630,17 @@ ata_link_linkspeed_attr(hw_sata_spd_limit, fls);
626630ata_link_linkspeed_attr (sata_spd_limit , fls );
627631ata_link_linkspeed_attr (sata_spd , noop );
628632
633+ static const struct attribute * const ata_link_attr_attrs [] = {
634+ & dev_attr_hw_sata_spd_limit .attr ,
635+ & dev_attr_sata_spd_limit .attr ,
636+ & dev_attr_sata_spd .attr ,
637+ NULL
638+ };
639+
640+ static const struct attribute_group ata_link_attr_group = {
641+ .attrs_const = ata_link_attr_attrs ,
642+ };
643+
629644static DECLARE_TRANSPORT_CLASS (ata_link_class ,
630645 "ata_link ", NULL, NULL, NULL) ;
631646
@@ -734,29 +749,12 @@ int ata_tlink_add(struct ata_link *link)
734749 * Setup / Teardown code
735750 */
736751
737- #define SETUP_TEMPLATE (attrb , field , perm , test ) \
738- i->private_##attrb[count] = dev_attr_##field; \
739- i->private_##attrb[count].attr.mode = perm; \
740- i->attrb[count] = &i->private_##attrb[count]; \
741- if (test) \
742- count++
743-
744- #define SETUP_LINK_ATTRIBUTE (field ) \
745- SETUP_TEMPLATE(link_attrs, field, S_IRUGO, 1)
746-
747- #define SETUP_PORT_ATTRIBUTE (field ) \
748- SETUP_TEMPLATE(port_attrs, field, S_IRUGO, 1)
749-
750- #define SETUP_DEV_ATTRIBUTE (field ) \
751- SETUP_TEMPLATE(dev_attrs, field, S_IRUGO, 1)
752-
753752/**
754753 * ata_attach_transport -- instantiate ATA transport template
755754 */
756755struct scsi_transport_template * ata_attach_transport (void )
757756{
758757 struct ata_internal * i ;
759- int count ;
760758
761759 i = kzalloc_obj (struct ata_internal );
762760 if (!i )
@@ -765,48 +763,21 @@ struct scsi_transport_template *ata_attach_transport(void)
765763 i -> t .eh_strategy_handler = ata_scsi_error ;
766764 i -> t .user_scan = ata_scsi_user_scan ;
767765
768- i -> t .host_attrs .ac .attrs = & i -> port_attrs [0 ];
769766 i -> t .host_attrs .ac .class = & ata_port_class .class ;
767+ i -> t .host_attrs .ac .grp = & ata_port_attr_group ;
770768 i -> t .host_attrs .ac .match = ata_tport_match ;
771769 transport_container_register (& i -> t .host_attrs );
772770
773771 i -> link_attr_cont .ac .class = & ata_link_class .class ;
774- i -> link_attr_cont .ac .attrs = & i -> link_attrs [ 0 ] ;
772+ i -> link_attr_cont .ac .grp = & ata_link_attr_group ;
775773 i -> link_attr_cont .ac .match = ata_tlink_match ;
776774 transport_container_register (& i -> link_attr_cont );
777775
778776 i -> dev_attr_cont .ac .class = & ata_dev_class .class ;
779- i -> dev_attr_cont .ac .attrs = & i -> dev_attrs [ 0 ] ;
777+ i -> dev_attr_cont .ac .grp = & ata_device_attr_group ;
780778 i -> dev_attr_cont .ac .match = ata_tdev_match ;
781779 transport_container_register (& i -> dev_attr_cont );
782780
783- count = 0 ;
784- SETUP_PORT_ATTRIBUTE (nr_pmp_links );
785- SETUP_PORT_ATTRIBUTE (idle_irq );
786- SETUP_PORT_ATTRIBUTE (port_no );
787- BUG_ON (count > ATA_PORT_ATTRS );
788- i -> port_attrs [count ] = NULL ;
789-
790- count = 0 ;
791- SETUP_LINK_ATTRIBUTE (hw_sata_spd_limit );
792- SETUP_LINK_ATTRIBUTE (sata_spd_limit );
793- SETUP_LINK_ATTRIBUTE (sata_spd );
794- BUG_ON (count > ATA_LINK_ATTRS );
795- i -> link_attrs [count ] = NULL ;
796-
797- count = 0 ;
798- SETUP_DEV_ATTRIBUTE (class );
799- SETUP_DEV_ATTRIBUTE (pio_mode );
800- SETUP_DEV_ATTRIBUTE (dma_mode );
801- SETUP_DEV_ATTRIBUTE (xfer_mode );
802- SETUP_DEV_ATTRIBUTE (spdn_cnt );
803- SETUP_DEV_ATTRIBUTE (ering );
804- SETUP_DEV_ATTRIBUTE (id );
805- SETUP_DEV_ATTRIBUTE (gscr );
806- SETUP_DEV_ATTRIBUTE (trim );
807- BUG_ON (count > ATA_DEV_ATTRS );
808- i -> dev_attrs [count ] = NULL ;
809-
810781 return & i -> t ;
811782}
812783
0 commit comments