sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / ata / libata-transport.c
blob7ef16c08505879127a3b433979119455e17d1ff4
1 /*
2 * Copyright 2008 ioogle, Inc. All rights reserved.
3 * Released under GPL v2.
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 in this class:
13 * - ata_port
14 * - ata_link
15 * - ata_device
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
19 * created.
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
23 * error handler runs.
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>
37 #include "libata.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;
47 struct ata_internal {
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) \
97 static ssize_t \
98 get_ata_##title##_names(u32 table_key, char *buf) \
99 { \
100 char *prefix = ""; \
101 ssize_t len = 0; \
102 int i; \
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); \
108 prefix = ", "; \
111 len += sprintf(buf + len, "\n"); \
112 return len; \
115 #define ata_bitfield_name_search(title, table) \
116 static ssize_t \
117 get_ata_##title##_names(u32 table_key, char *buf) \
119 ssize_t len = 0; \
120 int i; \
122 for (i = 0; i < ARRAY_SIZE(table); i++) { \
123 if (table[i].value == table_key) { \
124 len += sprintf(buf + len, "%s", \
125 table[i].name); \
126 break; \
129 len += sprintf(buf + len, "\n"); \
130 return len; \
133 static struct {
134 u32 value;
135 char *name;
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)
152 static struct {
153 u32 value;
154 char *name;
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)
170 static struct {
171 u32 value;
172 char *name;
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_match(xfer,ata_xfer_names)
202 * ATA Port attributes
204 #define ata_port_show_simple(field, name, format_string, cast) \
205 static ssize_t \
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 snprintf(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 put_device(dev->parent);
231 * ata_is_port -- check if a struct device represents a ATA port
232 * @dev: device to check
234 * Returns:
235 * %1 if the device represents a ATA Port, %0 else
237 static int ata_is_port(const struct device *dev)
239 return dev->release == ata_tport_release;
242 static int ata_tport_match(struct attribute_container *cont,
243 struct device *dev)
245 if (!ata_is_port(dev))
246 return 0;
247 return &ata_scsi_transport_template->host_attrs.ac == cont;
251 * ata_tport_delete -- remove ATA PORT
252 * @port: ATA PORT to remove
254 * Removes the specified ATA PORT. Remove the associated link as well.
256 void ata_tport_delete(struct ata_port *ap)
258 struct device *dev = &ap->tdev;
260 ata_tlink_delete(&ap->link);
262 transport_remove_device(dev);
263 device_del(dev);
264 transport_destroy_device(dev);
265 put_device(dev);
268 /** ata_tport_add - initialize a transport ATA port structure
270 * @parent: parent device
271 * @ap: existing ata_port structure
273 * Initialize a ATA port structure for sysfs. It will be added to the device
274 * tree below the device specified by @parent which could be a PCI device.
276 * Returns %0 on success
278 int ata_tport_add(struct device *parent,
279 struct ata_port *ap)
281 int error;
282 struct device *dev = &ap->tdev;
284 device_initialize(dev);
285 dev->type = &ata_port_type;
287 dev->parent = get_device(parent);
288 dev->release = ata_tport_release;
289 dev_set_name(dev, "ata%d", ap->print_id);
290 transport_setup_device(dev);
291 ata_acpi_bind_port(ap);
292 error = device_add(dev);
293 if (error) {
294 goto tport_err;
297 device_enable_async_suspend(dev);
298 pm_runtime_set_active(dev);
299 pm_runtime_enable(dev);
300 pm_runtime_forbid(dev);
302 transport_add_device(dev);
303 transport_configure_device(dev);
305 error = ata_tlink_add(&ap->link);
306 if (error) {
307 goto tport_link_err;
309 return 0;
311 tport_link_err:
312 transport_remove_device(dev);
313 device_del(dev);
315 tport_err:
316 transport_destroy_device(dev);
317 put_device(dev);
318 return error;
323 * ATA link attributes
325 static int noop(int x) { return x; }
327 #define ata_link_show_linkspeed(field, format) \
328 static ssize_t \
329 show_ata_link_##field(struct device *dev, \
330 struct device_attribute *attr, char *buf) \
332 struct ata_link *link = transport_class_to_link(dev); \
334 return sprintf(buf, "%s\n", sata_spd_string(format(link->field))); \
337 #define ata_link_linkspeed_attr(field, format) \
338 ata_link_show_linkspeed(field, format) \
339 static DEVICE_ATTR(field, S_IRUGO, show_ata_link_##field, NULL)
341 ata_link_linkspeed_attr(hw_sata_spd_limit, fls);
342 ata_link_linkspeed_attr(sata_spd_limit, fls);
343 ata_link_linkspeed_attr(sata_spd, noop);
346 static DECLARE_TRANSPORT_CLASS(ata_link_class,
347 "ata_link", NULL, NULL, NULL);
349 static void ata_tlink_release(struct device *dev)
351 put_device(dev->parent);
355 * ata_is_link -- check if a struct device represents a ATA link
356 * @dev: device to check
358 * Returns:
359 * %1 if the device represents a ATA link, %0 else
361 static int ata_is_link(const struct device *dev)
363 return dev->release == ata_tlink_release;
366 static int ata_tlink_match(struct attribute_container *cont,
367 struct device *dev)
369 struct ata_internal* i = to_ata_internal(ata_scsi_transport_template);
370 if (!ata_is_link(dev))
371 return 0;
372 return &i->link_attr_cont.ac == cont;
376 * ata_tlink_delete -- remove ATA LINK
377 * @port: ATA LINK to remove
379 * Removes the specified ATA LINK. remove associated ATA device(s) as well.
381 void ata_tlink_delete(struct ata_link *link)
383 struct device *dev = &link->tdev;
384 struct ata_device *ata_dev;
386 ata_for_each_dev(ata_dev, link, ALL) {
387 ata_tdev_delete(ata_dev);
390 transport_remove_device(dev);
391 device_del(dev);
392 transport_destroy_device(dev);
393 put_device(dev);
397 * ata_tlink_add -- initialize a transport ATA link structure
398 * @link: allocated ata_link structure.
400 * Initialize an ATA LINK structure for sysfs. It will be added in the
401 * device tree below the ATA PORT it belongs to.
403 * Returns %0 on success
405 int ata_tlink_add(struct ata_link *link)
407 struct device *dev = &link->tdev;
408 struct ata_port *ap = link->ap;
409 struct ata_device *ata_dev;
410 int error;
412 device_initialize(dev);
413 dev->parent = get_device(&ap->tdev);
414 dev->release = ata_tlink_release;
415 if (ata_is_host_link(link))
416 dev_set_name(dev, "link%d", ap->print_id);
417 else
418 dev_set_name(dev, "link%d.%d", ap->print_id, link->pmp);
420 transport_setup_device(dev);
422 error = device_add(dev);
423 if (error) {
424 goto tlink_err;
427 transport_add_device(dev);
428 transport_configure_device(dev);
430 ata_for_each_dev(ata_dev, link, ALL) {
431 error = ata_tdev_add(ata_dev);
432 if (error) {
433 goto tlink_dev_err;
436 return 0;
437 tlink_dev_err:
438 while (--ata_dev >= link->device) {
439 ata_tdev_delete(ata_dev);
441 transport_remove_device(dev);
442 device_del(dev);
443 tlink_err:
444 transport_destroy_device(dev);
445 put_device(dev);
446 return error;
450 * ATA device attributes
453 #define ata_dev_show_class(title, field) \
454 static ssize_t \
455 show_ata_dev_##field(struct device *dev, \
456 struct device_attribute *attr, char *buf) \
458 struct ata_device *ata_dev = transport_class_to_dev(dev); \
460 return get_ata_##title##_names(ata_dev->field, buf); \
463 #define ata_dev_attr(title, field) \
464 ata_dev_show_class(title, field) \
465 static DEVICE_ATTR(field, S_IRUGO, show_ata_dev_##field, NULL)
467 ata_dev_attr(class, class);
468 ata_dev_attr(xfer, pio_mode);
469 ata_dev_attr(xfer, dma_mode);
470 ata_dev_attr(xfer, xfer_mode);
473 #define ata_dev_show_simple(field, format_string, cast) \
474 static ssize_t \
475 show_ata_dev_##field(struct device *dev, \
476 struct device_attribute *attr, char *buf) \
478 struct ata_device *ata_dev = transport_class_to_dev(dev); \
480 return snprintf(buf, 20, format_string, cast ata_dev->field); \
483 #define ata_dev_simple_attr(field, format_string, type) \
484 ata_dev_show_simple(field, format_string, (type)) \
485 static DEVICE_ATTR(field, S_IRUGO, \
486 show_ata_dev_##field, NULL)
488 ata_dev_simple_attr(spdn_cnt, "%d\n", int);
490 struct ata_show_ering_arg {
491 char* buf;
492 int written;
495 static int ata_show_ering(struct ata_ering_entry *ent, void *void_arg)
497 struct ata_show_ering_arg* arg = void_arg;
498 u64 seconds;
499 u32 rem;
501 seconds = div_u64_rem(ent->timestamp, HZ, &rem);
502 arg->written += sprintf(arg->buf + arg->written,
503 "[%5llu.%09lu]", seconds,
504 rem * NSEC_PER_SEC / HZ);
505 arg->written += get_ata_err_names(ent->err_mask,
506 arg->buf + arg->written);
507 return 0;
510 static ssize_t
511 show_ata_dev_ering(struct device *dev,
512 struct device_attribute *attr, char *buf)
514 struct ata_device *ata_dev = transport_class_to_dev(dev);
515 struct ata_show_ering_arg arg = { buf, 0 };
517 ata_ering_map(&ata_dev->ering, ata_show_ering, &arg);
518 return arg.written;
522 static DEVICE_ATTR(ering, S_IRUGO, show_ata_dev_ering, NULL);
524 static ssize_t
525 show_ata_dev_id(struct device *dev,
526 struct device_attribute *attr, char *buf)
528 struct ata_device *ata_dev = transport_class_to_dev(dev);
529 int written = 0, i = 0;
531 if (ata_dev->class == ATA_DEV_PMP)
532 return 0;
533 for(i=0;i<ATA_ID_WORDS;i++) {
534 written += snprintf(buf+written, 20, "%04x%c",
535 ata_dev->id[i],
536 ((i+1) & 7) ? ' ' : '\n');
538 return written;
541 static DEVICE_ATTR(id, S_IRUGO, show_ata_dev_id, NULL);
543 static ssize_t
544 show_ata_dev_gscr(struct device *dev,
545 struct device_attribute *attr, char *buf)
547 struct ata_device *ata_dev = transport_class_to_dev(dev);
548 int written = 0, i = 0;
550 if (ata_dev->class != ATA_DEV_PMP)
551 return 0;
552 for(i=0;i<SATA_PMP_GSCR_DWORDS;i++) {
553 written += snprintf(buf+written, 20, "%08x%c",
554 ata_dev->gscr[i],
555 ((i+1) & 3) ? ' ' : '\n');
557 if (SATA_PMP_GSCR_DWORDS & 3)
558 buf[written-1] = '\n';
559 return written;
562 static DEVICE_ATTR(gscr, S_IRUGO, show_ata_dev_gscr, NULL);
564 static ssize_t
565 show_ata_dev_trim(struct device *dev,
566 struct device_attribute *attr, char *buf)
568 struct ata_device *ata_dev = transport_class_to_dev(dev);
569 unsigned char *mode;
571 if (!ata_id_has_trim(ata_dev->id))
572 mode = "unsupported";
573 else if (ata_dev->horkage & ATA_HORKAGE_NOTRIM)
574 mode = "forced_unsupported";
575 else if (ata_dev->horkage & ATA_HORKAGE_NO_NCQ_TRIM)
576 mode = "forced_unqueued";
577 else if (ata_fpdma_dsm_supported(ata_dev))
578 mode = "queued";
579 else
580 mode = "unqueued";
582 return snprintf(buf, 20, "%s\n", mode);
585 static DEVICE_ATTR(trim, S_IRUGO, show_ata_dev_trim, NULL);
587 static DECLARE_TRANSPORT_CLASS(ata_dev_class,
588 "ata_device", NULL, NULL, NULL);
590 static void ata_tdev_release(struct device *dev)
592 put_device(dev->parent);
596 * ata_is_ata_dev -- check if a struct device represents a ATA device
597 * @dev: device to check
599 * Returns:
600 * %1 if the device represents a ATA device, %0 else
602 static int ata_is_ata_dev(const struct device *dev)
604 return dev->release == ata_tdev_release;
607 static int ata_tdev_match(struct attribute_container *cont,
608 struct device *dev)
610 struct ata_internal* i = to_ata_internal(ata_scsi_transport_template);
611 if (!ata_is_ata_dev(dev))
612 return 0;
613 return &i->dev_attr_cont.ac == cont;
617 * ata_tdev_free -- free a ATA LINK
618 * @dev: ATA PHY to free
620 * Frees the specified ATA PHY.
622 * Note:
623 * This function must only be called on a PHY that has not
624 * successfully been added using ata_tdev_add().
626 static void ata_tdev_free(struct ata_device *dev)
628 transport_destroy_device(&dev->tdev);
629 put_device(&dev->tdev);
633 * ata_tdev_delete -- remove ATA device
634 * @port: ATA PORT to remove
636 * Removes the specified ATA device.
638 static void ata_tdev_delete(struct ata_device *ata_dev)
640 struct device *dev = &ata_dev->tdev;
642 transport_remove_device(dev);
643 device_del(dev);
644 ata_tdev_free(ata_dev);
649 * ata_tdev_add -- initialize a transport ATA device structure.
650 * @ata_dev: ata_dev structure.
652 * Initialize an ATA device structure for sysfs. It will be added in the
653 * device tree below the ATA LINK device it belongs to.
655 * Returns %0 on success
657 static int ata_tdev_add(struct ata_device *ata_dev)
659 struct device *dev = &ata_dev->tdev;
660 struct ata_link *link = ata_dev->link;
661 struct ata_port *ap = link->ap;
662 int error;
664 device_initialize(dev);
665 dev->parent = get_device(&link->tdev);
666 dev->release = ata_tdev_release;
667 if (ata_is_host_link(link))
668 dev_set_name(dev, "dev%d.%d", ap->print_id,ata_dev->devno);
669 else
670 dev_set_name(dev, "dev%d.%d.0", ap->print_id, link->pmp);
672 transport_setup_device(dev);
673 ata_acpi_bind_dev(ata_dev);
674 error = device_add(dev);
675 if (error) {
676 ata_tdev_free(ata_dev);
677 return error;
680 transport_add_device(dev);
681 transport_configure_device(dev);
682 return 0;
687 * Setup / Teardown code
690 #define SETUP_TEMPLATE(attrb, field, perm, test) \
691 i->private_##attrb[count] = dev_attr_##field; \
692 i->private_##attrb[count].attr.mode = perm; \
693 i->attrb[count] = &i->private_##attrb[count]; \
694 if (test) \
695 count++
697 #define SETUP_LINK_ATTRIBUTE(field) \
698 SETUP_TEMPLATE(link_attrs, field, S_IRUGO, 1)
700 #define SETUP_PORT_ATTRIBUTE(field) \
701 SETUP_TEMPLATE(port_attrs, field, S_IRUGO, 1)
703 #define SETUP_DEV_ATTRIBUTE(field) \
704 SETUP_TEMPLATE(dev_attrs, field, S_IRUGO, 1)
707 * ata_attach_transport -- instantiate ATA transport template
709 struct scsi_transport_template *ata_attach_transport(void)
711 struct ata_internal *i;
712 int count;
714 i = kzalloc(sizeof(struct ata_internal), GFP_KERNEL);
715 if (!i)
716 return NULL;
718 i->t.eh_strategy_handler = ata_scsi_error;
719 i->t.eh_timed_out = ata_scsi_timed_out;
720 i->t.user_scan = ata_scsi_user_scan;
722 i->t.host_attrs.ac.attrs = &i->port_attrs[0];
723 i->t.host_attrs.ac.class = &ata_port_class.class;
724 i->t.host_attrs.ac.match = ata_tport_match;
725 transport_container_register(&i->t.host_attrs);
727 i->link_attr_cont.ac.class = &ata_link_class.class;
728 i->link_attr_cont.ac.attrs = &i->link_attrs[0];
729 i->link_attr_cont.ac.match = ata_tlink_match;
730 transport_container_register(&i->link_attr_cont);
732 i->dev_attr_cont.ac.class = &ata_dev_class.class;
733 i->dev_attr_cont.ac.attrs = &i->dev_attrs[0];
734 i->dev_attr_cont.ac.match = ata_tdev_match;
735 transport_container_register(&i->dev_attr_cont);
737 count = 0;
738 SETUP_PORT_ATTRIBUTE(nr_pmp_links);
739 SETUP_PORT_ATTRIBUTE(idle_irq);
740 SETUP_PORT_ATTRIBUTE(port_no);
741 BUG_ON(count > ATA_PORT_ATTRS);
742 i->port_attrs[count] = NULL;
744 count = 0;
745 SETUP_LINK_ATTRIBUTE(hw_sata_spd_limit);
746 SETUP_LINK_ATTRIBUTE(sata_spd_limit);
747 SETUP_LINK_ATTRIBUTE(sata_spd);
748 BUG_ON(count > ATA_LINK_ATTRS);
749 i->link_attrs[count] = NULL;
751 count = 0;
752 SETUP_DEV_ATTRIBUTE(class);
753 SETUP_DEV_ATTRIBUTE(pio_mode);
754 SETUP_DEV_ATTRIBUTE(dma_mode);
755 SETUP_DEV_ATTRIBUTE(xfer_mode);
756 SETUP_DEV_ATTRIBUTE(spdn_cnt);
757 SETUP_DEV_ATTRIBUTE(ering);
758 SETUP_DEV_ATTRIBUTE(id);
759 SETUP_DEV_ATTRIBUTE(gscr);
760 SETUP_DEV_ATTRIBUTE(trim);
761 BUG_ON(count > ATA_DEV_ATTRS);
762 i->dev_attrs[count] = NULL;
764 return &i->t;
768 * ata_release_transport -- release ATA transport template instance
769 * @t: transport template instance
771 void ata_release_transport(struct scsi_transport_template *t)
773 struct ata_internal *i = to_ata_internal(t);
775 transport_container_unregister(&i->t.host_attrs);
776 transport_container_unregister(&i->link_attr_cont);
777 transport_container_unregister(&i->dev_attr_cont);
779 kfree(i);
782 __init int libata_transport_init(void)
784 int error;
786 error = transport_class_register(&ata_link_class);
787 if (error)
788 goto out_unregister_transport;
789 error = transport_class_register(&ata_port_class);
790 if (error)
791 goto out_unregister_link;
792 error = transport_class_register(&ata_dev_class);
793 if (error)
794 goto out_unregister_port;
795 return 0;
797 out_unregister_port:
798 transport_class_unregister(&ata_port_class);
799 out_unregister_link:
800 transport_class_unregister(&ata_link_class);
801 out_unregister_transport:
802 return error;
806 void __exit libata_transport_exit(void)
808 transport_class_unregister(&ata_link_class);
809 transport_class_unregister(&ata_port_class);
810 transport_class_unregister(&ata_dev_class);