1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2008 ioogle, Inc. All rights reserved.
5 * Libata transport class.
7 * The ATA transport class contains common code to deal with ATA HBAs,
8 * an approximated representation of ATA topologies in the driver model,
9 * and various sysfs attributes to expose these topologies and management
10 * interfaces to user-space.
12 * There are 3 objects defined in this class:
16 * Each port has a link object. Each link can have up to two devices for PATA
17 * and generally one for SATA.
18 * If there is SATA port multiplier [PMP], 15 additional ata_link object are
21 * These objects are created when the ata host is initialized and when a PMP is
22 * found. They are removed only when the HBA is removed, cleaned before the
27 #include <linux/kernel.h>
28 #include <linux/blkdev.h>
29 #include <linux/spinlock.h>
30 #include <linux/slab.h>
31 #include <scsi/scsi_transport.h>
32 #include <linux/libata.h>
33 #include <linux/hdreg.h>
34 #include <linux/uaccess.h>
35 #include <linux/pm_runtime.h>
38 #include "libata-transport.h"
40 #define ATA_PORT_ATTRS 3
41 #define ATA_LINK_ATTRS 3
42 #define ATA_DEV_ATTRS 9
44 struct scsi_transport_template
;
45 struct scsi_transport_template
*ata_scsi_transport_template
;
48 struct scsi_transport_template t
;
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
];
54 struct transport_container link_attr_cont
;
55 struct transport_container dev_attr_cont
;
58 * The array of null terminated pointers to attributes
59 * needed by scsi_sysfs.c
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];
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)
84 /* Device objects are always created whit link objects */
85 static int ata_tdev_add(struct ata_device
*dev
);
86 static void ata_tdev_delete(struct ata_device
*dev
);
90 * Hack to allow attributes of the same name in different objects.
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
[] = {
137 { ATA_DEV_UNKNOWN
, "unknown" },
138 { ATA_DEV_ATA
, "ata" },
139 { ATA_DEV_ATA_UNSUP
, "ata" },
140 { ATA_DEV_ATAPI
, "atapi" },
141 { ATA_DEV_ATAPI_UNSUP
, "atapi" },
142 { ATA_DEV_PMP
, "pmp" },
143 { ATA_DEV_PMP_UNSUP
, "pmp" },
144 { ATA_DEV_SEMB
, "semb" },
145 { ATA_DEV_SEMB_UNSUP
, "semb" },
146 { ATA_DEV_ZAC
, "zac" },
147 { ATA_DEV_NONE
, "none" }
149 ata_bitfield_name_search(class, ata_class_names
)
155 } ata_err_names
[] = {
156 { AC_ERR_DEV
, "DeviceError" },
157 { AC_ERR_HSM
, "HostStateMachineError" },
158 { AC_ERR_TIMEOUT
, "Timeout" },
159 { AC_ERR_MEDIA
, "MediaError" },
160 { AC_ERR_ATA_BUS
, "BusError" },
161 { AC_ERR_HOST_BUS
, "HostBusError" },
162 { AC_ERR_SYSTEM
, "SystemError" },
163 { AC_ERR_INVALID
, "InvalidArg" },
164 { AC_ERR_OTHER
, "Unknown" },
165 { AC_ERR_NODEV_HINT
, "NoDeviceHint" },
166 { AC_ERR_NCQ
, "NCQError" }
168 ata_bitfield_name_match(err
, ata_err_names
)
173 } ata_xfer_names
[] = {
174 { XFER_UDMA_7
, "XFER_UDMA_7" },
175 { XFER_UDMA_6
, "XFER_UDMA_6" },
176 { XFER_UDMA_5
, "XFER_UDMA_5" },
177 { XFER_UDMA_4
, "XFER_UDMA_4" },
178 { XFER_UDMA_3
, "XFER_UDMA_3" },
179 { XFER_UDMA_2
, "XFER_UDMA_2" },
180 { XFER_UDMA_1
, "XFER_UDMA_1" },
181 { XFER_UDMA_0
, "XFER_UDMA_0" },
182 { XFER_MW_DMA_4
, "XFER_MW_DMA_4" },
183 { XFER_MW_DMA_3
, "XFER_MW_DMA_3" },
184 { XFER_MW_DMA_2
, "XFER_MW_DMA_2" },
185 { XFER_MW_DMA_1
, "XFER_MW_DMA_1" },
186 { XFER_MW_DMA_0
, "XFER_MW_DMA_0" },
187 { XFER_SW_DMA_2
, "XFER_SW_DMA_2" },
188 { XFER_SW_DMA_1
, "XFER_SW_DMA_1" },
189 { XFER_SW_DMA_0
, "XFER_SW_DMA_0" },
190 { XFER_PIO_6
, "XFER_PIO_6" },
191 { XFER_PIO_5
, "XFER_PIO_5" },
192 { XFER_PIO_4
, "XFER_PIO_4" },
193 { XFER_PIO_3
, "XFER_PIO_3" },
194 { XFER_PIO_2
, "XFER_PIO_2" },
195 { XFER_PIO_1
, "XFER_PIO_1" },
196 { XFER_PIO_0
, "XFER_PIO_0" },
197 { XFER_PIO_SLOW
, "XFER_PIO_SLOW" }
199 ata_bitfield_name_search(xfer
, ata_xfer_names
)
202 * ATA Port attributes
204 #define ata_port_show_simple(field, name, format_string, cast) \
206 show_ata_port_##name(struct device *dev, \
207 struct device_attribute *attr, char *buf) \
209 struct ata_port *ap = transport_class_to_port(dev); \
211 return scnprintf(buf, 20, format_string, cast ap->field); \
214 #define ata_port_simple_attr(field, name, format_string, type) \
215 ata_port_show_simple(field, name, format_string, (type)) \
216 static DEVICE_ATTR(name, S_IRUGO, show_ata_port_##name, NULL)
218 ata_port_simple_attr(nr_pmp_links
, nr_pmp_links
, "%d\n", int);
219 ata_port_simple_attr(stats
.idle_irq
, idle_irq
, "%ld\n", unsigned long);
220 ata_port_simple_attr(local_port_no
, port_no
, "%u\n", unsigned int);
222 static DECLARE_TRANSPORT_CLASS(ata_port_class
,
223 "ata_port", NULL
, NULL
, NULL
);
225 static void ata_tport_release(struct device
*dev
)
227 struct ata_port
*ap
= tdev_to_port(dev
);
228 ata_host_put(ap
->host
);
232 * ata_is_port -- check if a struct device represents a ATA port
233 * @dev: device to check
236 * %1 if the device represents a ATA Port, %0 else
238 static int ata_is_port(const struct device
*dev
)
240 return dev
->release
== ata_tport_release
;
243 static int ata_tport_match(struct attribute_container
*cont
,
246 if (!ata_is_port(dev
))
248 return &ata_scsi_transport_template
->host_attrs
.ac
== cont
;
252 * ata_tport_delete -- remove ATA PORT
253 * @ap: ATA PORT to remove
255 * Removes the specified ATA PORT. Remove the associated link as well.
257 void ata_tport_delete(struct ata_port
*ap
)
259 struct device
*dev
= &ap
->tdev
;
261 ata_tlink_delete(&ap
->link
);
263 transport_remove_device(dev
);
265 transport_destroy_device(dev
);
269 static const struct device_type ata_port_sas_type
= {
270 .name
= ATA_PORT_TYPE_NAME
,
273 /** ata_tport_add - initialize a transport ATA port structure
275 * @parent: parent device
276 * @ap: existing ata_port structure
278 * Initialize a ATA port structure for sysfs. It will be added to the device
279 * tree below the device specified by @parent which could be a PCI device.
281 * Returns %0 on success
283 int ata_tport_add(struct device
*parent
,
287 struct device
*dev
= &ap
->tdev
;
289 device_initialize(dev
);
290 if (ap
->flags
& ATA_FLAG_SAS_HOST
)
291 dev
->type
= &ata_port_sas_type
;
293 dev
->type
= &ata_port_type
;
295 dev
->parent
= parent
;
296 ata_host_get(ap
->host
);
297 dev
->release
= ata_tport_release
;
298 dev_set_name(dev
, "ata%d", ap
->print_id
);
299 transport_setup_device(dev
);
300 ata_acpi_bind_port(ap
);
301 error
= device_add(dev
);
306 device_enable_async_suspend(dev
);
307 pm_runtime_set_active(dev
);
308 pm_runtime_enable(dev
);
309 pm_runtime_forbid(dev
);
311 error
= transport_add_device(dev
);
313 goto tport_transport_add_err
;
314 transport_configure_device(dev
);
316 error
= ata_tlink_add(&ap
->link
);
323 transport_remove_device(dev
);
324 tport_transport_add_err
:
328 transport_destroy_device(dev
);
334 * ata_port_classify - determine device type based on ATA-spec signature
335 * @ap: ATA port device on which the classification should be run
336 * @tf: ATA taskfile register set for device to be identified
338 * A wrapper around ata_dev_classify() to provide additional logging
341 * Device type, %ATA_DEV_ATA, %ATA_DEV_ATAPI, %ATA_DEV_PMP,
342 * %ATA_DEV_ZAC, or %ATA_DEV_UNKNOWN the event of failure.
344 unsigned int ata_port_classify(struct ata_port
*ap
,
345 const struct ata_taskfile
*tf
)
348 unsigned int class = ata_dev_classify(tf
);
350 /* Start with index '1' to skip the 'unknown' entry */
351 for (i
= 1; i
< ARRAY_SIZE(ata_class_names
); i
++) {
352 if (ata_class_names
[i
].value
== class) {
353 ata_port_dbg(ap
, "found %s device by sig\n",
354 ata_class_names
[i
].name
);
359 ata_port_info(ap
, "found unknown device (class %u)\n", class);
362 EXPORT_SYMBOL_GPL(ata_port_classify
);
365 * ATA link attributes
367 static int noop(int x
) { return x
; }
369 #define ata_link_show_linkspeed(field, format) \
371 show_ata_link_##field(struct device *dev, \
372 struct device_attribute *attr, char *buf) \
374 struct ata_link *link = transport_class_to_link(dev); \
376 return sprintf(buf, "%s\n", sata_spd_string(format(link->field))); \
379 #define ata_link_linkspeed_attr(field, format) \
380 ata_link_show_linkspeed(field, format) \
381 static DEVICE_ATTR(field, S_IRUGO, show_ata_link_##field, NULL)
383 ata_link_linkspeed_attr(hw_sata_spd_limit
, fls
);
384 ata_link_linkspeed_attr(sata_spd_limit
, fls
);
385 ata_link_linkspeed_attr(sata_spd
, noop
);
388 static DECLARE_TRANSPORT_CLASS(ata_link_class
,
389 "ata_link", NULL
, NULL
, NULL
);
391 static void ata_tlink_release(struct device
*dev
)
396 * ata_is_link -- check if a struct device represents a ATA link
397 * @dev: device to check
400 * %1 if the device represents a ATA link, %0 else
402 static int ata_is_link(const struct device
*dev
)
404 return dev
->release
== ata_tlink_release
;
407 static int ata_tlink_match(struct attribute_container
*cont
,
410 struct ata_internal
* i
= to_ata_internal(ata_scsi_transport_template
);
411 if (!ata_is_link(dev
))
413 return &i
->link_attr_cont
.ac
== cont
;
417 * ata_tlink_delete -- remove ATA LINK
418 * @link: ATA LINK to remove
420 * Removes the specified ATA LINK. remove associated ATA device(s) as well.
422 void ata_tlink_delete(struct ata_link
*link
)
424 struct device
*dev
= &link
->tdev
;
425 struct ata_device
*ata_dev
;
427 ata_for_each_dev(ata_dev
, link
, ALL
) {
428 ata_tdev_delete(ata_dev
);
431 transport_remove_device(dev
);
433 transport_destroy_device(dev
);
438 * ata_tlink_add -- initialize a transport ATA link structure
439 * @link: allocated ata_link structure.
441 * Initialize an ATA LINK structure for sysfs. It will be added in the
442 * device tree below the ATA PORT it belongs to.
444 * Returns %0 on success
446 int ata_tlink_add(struct ata_link
*link
)
448 struct device
*dev
= &link
->tdev
;
449 struct ata_port
*ap
= link
->ap
;
450 struct ata_device
*ata_dev
;
453 device_initialize(dev
);
454 dev
->parent
= &ap
->tdev
;
455 dev
->release
= ata_tlink_release
;
456 if (ata_is_host_link(link
))
457 dev_set_name(dev
, "link%d", ap
->print_id
);
459 dev_set_name(dev
, "link%d.%d", ap
->print_id
, link
->pmp
);
461 transport_setup_device(dev
);
463 error
= device_add(dev
);
468 error
= transport_add_device(dev
);
470 goto tlink_transport_err
;
471 transport_configure_device(dev
);
473 ata_for_each_dev(ata_dev
, link
, ALL
) {
474 error
= ata_tdev_add(ata_dev
);
481 while (--ata_dev
>= link
->device
) {
482 ata_tdev_delete(ata_dev
);
484 transport_remove_device(dev
);
488 transport_destroy_device(dev
);
494 * ATA device attributes
497 #define ata_dev_show_class(title, field) \
499 show_ata_dev_##field(struct device *dev, \
500 struct device_attribute *attr, char *buf) \
502 struct ata_device *ata_dev = transport_class_to_dev(dev); \
504 return get_ata_##title##_names(ata_dev->field, buf); \
507 #define ata_dev_attr(title, field) \
508 ata_dev_show_class(title, field) \
509 static DEVICE_ATTR(field, S_IRUGO, show_ata_dev_##field, NULL)
511 ata_dev_attr(class, class);
512 ata_dev_attr(xfer
, pio_mode
);
513 ata_dev_attr(xfer
, dma_mode
);
514 ata_dev_attr(xfer
, xfer_mode
);
517 #define ata_dev_show_simple(field, format_string, cast) \
519 show_ata_dev_##field(struct device *dev, \
520 struct device_attribute *attr, char *buf) \
522 struct ata_device *ata_dev = transport_class_to_dev(dev); \
524 return scnprintf(buf, 20, format_string, cast ata_dev->field); \
527 #define ata_dev_simple_attr(field, format_string, type) \
528 ata_dev_show_simple(field, format_string, (type)) \
529 static DEVICE_ATTR(field, S_IRUGO, \
530 show_ata_dev_##field, NULL)
532 ata_dev_simple_attr(spdn_cnt
, "%d\n", int);
534 struct ata_show_ering_arg
{
539 static int ata_show_ering(struct ata_ering_entry
*ent
, void *void_arg
)
541 struct ata_show_ering_arg
* arg
= void_arg
;
545 seconds
= div_u64_rem(ent
->timestamp
, HZ
, &rem
);
546 arg
->written
+= sprintf(arg
->buf
+ arg
->written
,
547 "[%5llu.%09lu]", seconds
,
548 rem
* NSEC_PER_SEC
/ HZ
);
549 arg
->written
+= get_ata_err_names(ent
->err_mask
,
550 arg
->buf
+ arg
->written
);
555 show_ata_dev_ering(struct device
*dev
,
556 struct device_attribute
*attr
, char *buf
)
558 struct ata_device
*ata_dev
= transport_class_to_dev(dev
);
559 struct ata_show_ering_arg arg
= { buf
, 0 };
561 ata_ering_map(&ata_dev
->ering
, ata_show_ering
, &arg
);
566 static DEVICE_ATTR(ering
, S_IRUGO
, show_ata_dev_ering
, NULL
);
569 show_ata_dev_id(struct device
*dev
,
570 struct device_attribute
*attr
, char *buf
)
572 struct ata_device
*ata_dev
= transport_class_to_dev(dev
);
573 int written
= 0, i
= 0;
575 if (ata_dev
->class == ATA_DEV_PMP
)
577 for(i
=0;i
<ATA_ID_WORDS
;i
++) {
578 written
+= scnprintf(buf
+written
, 20, "%04x%c",
580 ((i
+1) & 7) ? ' ' : '\n');
585 static DEVICE_ATTR(id
, S_IRUGO
, show_ata_dev_id
, NULL
);
588 show_ata_dev_gscr(struct device
*dev
,
589 struct device_attribute
*attr
, char *buf
)
591 struct ata_device
*ata_dev
= transport_class_to_dev(dev
);
592 int written
= 0, i
= 0;
594 if (ata_dev
->class != ATA_DEV_PMP
)
596 for(i
=0;i
<SATA_PMP_GSCR_DWORDS
;i
++) {
597 written
+= scnprintf(buf
+written
, 20, "%08x%c",
599 ((i
+1) & 3) ? ' ' : '\n');
601 if (SATA_PMP_GSCR_DWORDS
& 3)
602 buf
[written
-1] = '\n';
606 static DEVICE_ATTR(gscr
, S_IRUGO
, show_ata_dev_gscr
, NULL
);
609 show_ata_dev_trim(struct device
*dev
,
610 struct device_attribute
*attr
, char *buf
)
612 struct ata_device
*ata_dev
= transport_class_to_dev(dev
);
615 if (!ata_id_has_trim(ata_dev
->id
))
616 mode
= "unsupported";
617 else if (ata_dev
->horkage
& ATA_HORKAGE_NOTRIM
)
618 mode
= "forced_unsupported";
619 else if (ata_dev
->horkage
& ATA_HORKAGE_NO_NCQ_TRIM
)
620 mode
= "forced_unqueued";
621 else if (ata_fpdma_dsm_supported(ata_dev
))
626 return scnprintf(buf
, 20, "%s\n", mode
);
629 static DEVICE_ATTR(trim
, S_IRUGO
, show_ata_dev_trim
, NULL
);
631 static DECLARE_TRANSPORT_CLASS(ata_dev_class
,
632 "ata_device", NULL
, NULL
, NULL
);
634 static void ata_tdev_release(struct device
*dev
)
639 * ata_is_ata_dev -- check if a struct device represents a ATA device
640 * @dev: device to check
643 * %1 if the device represents a ATA device, %0 else
645 static int ata_is_ata_dev(const struct device
*dev
)
647 return dev
->release
== ata_tdev_release
;
650 static int ata_tdev_match(struct attribute_container
*cont
,
653 struct ata_internal
* i
= to_ata_internal(ata_scsi_transport_template
);
654 if (!ata_is_ata_dev(dev
))
656 return &i
->dev_attr_cont
.ac
== cont
;
660 * ata_tdev_free -- free a ATA LINK
661 * @dev: ATA PHY to free
663 * Frees the specified ATA PHY.
666 * This function must only be called on a PHY that has not
667 * successfully been added using ata_tdev_add().
669 static void ata_tdev_free(struct ata_device
*dev
)
671 transport_destroy_device(&dev
->tdev
);
672 put_device(&dev
->tdev
);
676 * ata_tdev_delete -- remove ATA device
677 * @ata_dev: ATA device to remove
679 * Removes the specified ATA device.
681 static void ata_tdev_delete(struct ata_device
*ata_dev
)
683 struct device
*dev
= &ata_dev
->tdev
;
685 transport_remove_device(dev
);
687 ata_tdev_free(ata_dev
);
692 * ata_tdev_add -- initialize a transport ATA device structure.
693 * @ata_dev: ata_dev structure.
695 * Initialize an ATA device structure for sysfs. It will be added in the
696 * device tree below the ATA LINK device it belongs to.
698 * Returns %0 on success
700 static int ata_tdev_add(struct ata_device
*ata_dev
)
702 struct device
*dev
= &ata_dev
->tdev
;
703 struct ata_link
*link
= ata_dev
->link
;
704 struct ata_port
*ap
= link
->ap
;
707 device_initialize(dev
);
708 dev
->parent
= &link
->tdev
;
709 dev
->release
= ata_tdev_release
;
710 if (ata_is_host_link(link
))
711 dev_set_name(dev
, "dev%d.%d", ap
->print_id
,ata_dev
->devno
);
713 dev_set_name(dev
, "dev%d.%d.0", ap
->print_id
, link
->pmp
);
715 transport_setup_device(dev
);
716 ata_acpi_bind_dev(ata_dev
);
717 error
= device_add(dev
);
719 ata_tdev_free(ata_dev
);
723 error
= transport_add_device(dev
);
726 ata_tdev_free(ata_dev
);
730 transport_configure_device(dev
);
736 * Setup / Teardown code
739 #define SETUP_TEMPLATE(attrb, field, perm, test) \
740 i->private_##attrb[count] = dev_attr_##field; \
741 i->private_##attrb[count].attr.mode = perm; \
742 i->attrb[count] = &i->private_##attrb[count]; \
746 #define SETUP_LINK_ATTRIBUTE(field) \
747 SETUP_TEMPLATE(link_attrs, field, S_IRUGO, 1)
749 #define SETUP_PORT_ATTRIBUTE(field) \
750 SETUP_TEMPLATE(port_attrs, field, S_IRUGO, 1)
752 #define SETUP_DEV_ATTRIBUTE(field) \
753 SETUP_TEMPLATE(dev_attrs, field, S_IRUGO, 1)
756 * ata_attach_transport -- instantiate ATA transport template
758 struct scsi_transport_template
*ata_attach_transport(void)
760 struct ata_internal
*i
;
763 i
= kzalloc(sizeof(struct ata_internal
), GFP_KERNEL
);
767 i
->t
.eh_strategy_handler
= ata_scsi_error
;
768 i
->t
.user_scan
= ata_scsi_user_scan
;
770 i
->t
.host_attrs
.ac
.attrs
= &i
->port_attrs
[0];
771 i
->t
.host_attrs
.ac
.class = &ata_port_class
.class;
772 i
->t
.host_attrs
.ac
.match
= ata_tport_match
;
773 transport_container_register(&i
->t
.host_attrs
);
775 i
->link_attr_cont
.ac
.class = &ata_link_class
.class;
776 i
->link_attr_cont
.ac
.attrs
= &i
->link_attrs
[0];
777 i
->link_attr_cont
.ac
.match
= ata_tlink_match
;
778 transport_container_register(&i
->link_attr_cont
);
780 i
->dev_attr_cont
.ac
.class = &ata_dev_class
.class;
781 i
->dev_attr_cont
.ac
.attrs
= &i
->dev_attrs
[0];
782 i
->dev_attr_cont
.ac
.match
= ata_tdev_match
;
783 transport_container_register(&i
->dev_attr_cont
);
786 SETUP_PORT_ATTRIBUTE(nr_pmp_links
);
787 SETUP_PORT_ATTRIBUTE(idle_irq
);
788 SETUP_PORT_ATTRIBUTE(port_no
);
789 BUG_ON(count
> ATA_PORT_ATTRS
);
790 i
->port_attrs
[count
] = NULL
;
793 SETUP_LINK_ATTRIBUTE(hw_sata_spd_limit
);
794 SETUP_LINK_ATTRIBUTE(sata_spd_limit
);
795 SETUP_LINK_ATTRIBUTE(sata_spd
);
796 BUG_ON(count
> ATA_LINK_ATTRS
);
797 i
->link_attrs
[count
] = NULL
;
800 SETUP_DEV_ATTRIBUTE(class);
801 SETUP_DEV_ATTRIBUTE(pio_mode
);
802 SETUP_DEV_ATTRIBUTE(dma_mode
);
803 SETUP_DEV_ATTRIBUTE(xfer_mode
);
804 SETUP_DEV_ATTRIBUTE(spdn_cnt
);
805 SETUP_DEV_ATTRIBUTE(ering
);
806 SETUP_DEV_ATTRIBUTE(id
);
807 SETUP_DEV_ATTRIBUTE(gscr
);
808 SETUP_DEV_ATTRIBUTE(trim
);
809 BUG_ON(count
> ATA_DEV_ATTRS
);
810 i
->dev_attrs
[count
] = NULL
;
816 * ata_release_transport -- release ATA transport template instance
817 * @t: transport template instance
819 void ata_release_transport(struct scsi_transport_template
*t
)
821 struct ata_internal
*i
= to_ata_internal(t
);
823 transport_container_unregister(&i
->t
.host_attrs
);
824 transport_container_unregister(&i
->link_attr_cont
);
825 transport_container_unregister(&i
->dev_attr_cont
);
830 __init
int libata_transport_init(void)
834 error
= transport_class_register(&ata_link_class
);
836 goto out_unregister_transport
;
837 error
= transport_class_register(&ata_port_class
);
839 goto out_unregister_link
;
840 error
= transport_class_register(&ata_dev_class
);
842 goto out_unregister_port
;
846 transport_class_unregister(&ata_port_class
);
848 transport_class_unregister(&ata_link_class
);
849 out_unregister_transport
:
854 void __exit
libata_transport_exit(void)
856 transport_class_unregister(&ata_link_class
);
857 transport_class_unregister(&ata_port_class
);
858 transport_class_unregister(&ata_dev_class
);