27 #include <linux/kernel.h>
30 #include <linux/slab.h>
40 #define ATA_PORT_ATTRS 2
41 #define ATA_LINK_ATTRS 3
42 #define ATA_DEV_ATTRS 9
65 #define to_ata_internal(tmpl) container_of(tmpl, struct ata_internal, t)
68 #define tdev_to_device(d) \
69 container_of((d), struct ata_device, tdev)
70 #define transport_class_to_dev(dev) \
71 tdev_to_device((dev)->parent)
73 #define tdev_to_link(d) \
74 container_of((d), struct ata_link, tdev)
75 #define transport_class_to_link(dev) \
76 tdev_to_link((dev)->parent)
78 #define tdev_to_port(d) \
79 container_of((d), struct ata_port, tdev)
80 #define transport_class_to_port(dev) \
81 tdev_to_port((dev)->parent)
92 #define ATA_DEVICE_ATTR(_prefix,_name,_mode,_show,_store) \
93 struct device_attribute device_attr_##_prefix##_##_name = \
94 __ATTR(_name,_mode,_show,_store)
96 #define ata_bitfield_name_match(title, table) \
98 get_ata_##title##_names(u32 table_key, char *buf) \
104 for (i = 0; i < ARRAY_SIZE(table); i++) { \
105 if (table[i].value & table_key) { \
106 len += sprintf(buf + len, "%s%s", \
107 prefix, table[i].name); \
111 len += sprintf(buf + len, "\n"); \
115 #define ata_bitfield_name_search(title, table) \
117 get_ata_##title##_names(u32 table_key, char *buf) \
122 for (i = 0; i < ARRAY_SIZE(table); i++) { \
123 if (table[i].value == table_key) { \
124 len += sprintf(buf + len, "%s", \
129 len += sprintf(buf + len, "\n"); \
136 } ata_class_names[] = {
203 #define ata_port_show_simple(field, name, format_string, cast) \
205 show_ata_port_##name(struct device *dev, \
206 struct device_attribute *attr, char *buf) \
208 struct ata_port *ap = transport_class_to_port(dev); \
210 return snprintf(buf, 20, format_string, cast ap->field); \
213 #define ata_port_simple_attr(field, name, format_string, type) \
214 ata_port_show_simple(field, name, format_string, (type)) \
215 static DEVICE_ATTR(name, S_IRUGO, show_ata_port_##name, NULL)
223 static void ata_tport_release(
struct device *
dev)
235 static int ata_is_port(
const struct device *
dev)
237 return dev->
release == ata_tport_release;
243 if (!ata_is_port(dev))
286 dev->
release = ata_tport_release;
294 device_enable_async_suspend(dev);
295 pm_runtime_set_active(dev);
324 #define ata_link_show_linkspeed(field) \
326 show_ata_link_##field(struct device *dev, \
327 struct device_attribute *attr, char *buf) \
329 struct ata_link *link = transport_class_to_link(dev); \
331 return sprintf(buf,"%s\n", sata_spd_string(fls(link->field))); \
334 #define ata_link_linkspeed_attr(field) \
335 ata_link_show_linkspeed(field) \
336 static DEVICE_ATTR(field, S_IRUGO, show_ata_link_##field, NULL)
346 static void ata_tlink_release(
struct device *dev)
358 static int ata_is_link(
const struct device *dev)
360 return dev->
release == ata_tlink_release;
367 if (!ata_is_link(dev))
384 ata_tdev_delete(ata_dev);
411 dev->
release = ata_tlink_release;
412 if (ata_is_host_link(link))
428 error = ata_tdev_add(ata_dev);
435 while (--ata_dev >= link->
device) {
436 ata_tdev_delete(ata_dev);
450 #define ata_dev_show_class(title, field) \
452 show_ata_dev_##field(struct device *dev, \
453 struct device_attribute *attr, char *buf) \
455 struct ata_device *ata_dev = transport_class_to_dev(dev); \
457 return get_ata_##title##_names(ata_dev->field, buf); \
460 #define ata_dev_attr(title, field) \
461 ata_dev_show_class(title, field) \
462 static DEVICE_ATTR(field, S_IRUGO, show_ata_dev_##field, NULL)
470 #define ata_dev_show_simple(field, format_string, cast) \
472 show_ata_dev_##field(struct device *dev, \
473 struct device_attribute *attr, char *buf) \
475 struct ata_device *ata_dev = transport_class_to_dev(dev); \
477 return snprintf(buf, 20, format_string, cast ata_dev->field); \
480 #define ata_dev_simple_attr(field, format_string, type) \
481 ata_dev_show_simple(field, format_string, (type)) \
482 static DEVICE_ATTR(field, S_IRUGO, \
483 show_ata_dev_##field, NULL)
507 show_ata_dev_ering(
struct device *dev,
521 show_ata_dev_id(
struct device *dev,
525 int written = 0, i = 0;
530 written +=
snprintf(buf+written, 20,
"%04x%c",
532 ((i+1) & 7) ?
' ' :
'\n');
540 show_ata_dev_gscr(
struct device *dev,
544 int written = 0, i = 0;
549 written +=
snprintf(buf+written, 20,
"%08x%c",
551 ((i+1) & 3) ?
' ' :
'\n');
553 if (SATA_PMP_GSCR_DWORDS & 3)
554 buf[written-1] =
'\n';
563 static void ata_tdev_release(
struct device *dev)
575 static int ata_is_ata_dev(
const struct device *dev)
577 return dev->
release == ata_tdev_release;
584 if (!ata_is_ata_dev(dev))
599 static void ata_tdev_free(
struct ata_device *dev)
611 static void ata_tdev_delete(
struct ata_device *ata_dev)
617 ata_tdev_free(ata_dev);
630 static int ata_tdev_add(
struct ata_device *ata_dev)
639 dev->
release = ata_tdev_release;
640 if (ata_is_host_link(link))
648 ata_tdev_free(ata_dev);
662 #define SETUP_TEMPLATE(attrb, field, perm, test) \
663 i->private_##attrb[count] = dev_attr_##field; \
664 i->private_##attrb[count].attr.mode = perm; \
665 i->attrb[count] = &i->private_##attrb[count]; \
669 #define SETUP_LINK_ATTRIBUTE(field) \
670 SETUP_TEMPLATE(link_attrs, field, S_IRUGO, 1)
672 #define SETUP_PORT_ATTRIBUTE(field) \
673 SETUP_TEMPLATE(port_attrs, field, S_IRUGO, 1)
675 #define SETUP_DEV_ATTRIBUTE(field) \
676 SETUP_TEMPLATE(dev_attrs, field, S_IRUGO, 1)
695 i->
t.host_attrs.ac.class = &ata_port_class.class;
696 i->
t.host_attrs.ac.match = ata_tport_match;
697 transport_container_register(&i->
t.host_attrs);
745 transport_container_unregister(&i->
t.host_attrs);
758 goto out_unregister_transport;
761 goto out_unregister_link;
764 goto out_unregister_port;
771 out_unregister_transport: