blob: 9a7f0ea565df6c6066d7e64465c8385b81014a01 [file] [log] [blame]
Gwendal Grignoud9027472010-05-25 12:31:38 -07001/*
2 * Copyright 2008 ioogle, Inc. All rights reserved.
3 * Released under GPL v2.
4 *
5 * Libata transport class.
6 *
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.
11 *
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.
20 *
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.
24 */
25
26
27#include <linux/kernel.h>
28#include <linux/blkdev.h>
29#include <linux/spinlock.h>
Jeff Garzik6a2148c2010-08-19 16:11:32 -040030#include <linux/slab.h>
Gwendal Grignoud9027472010-05-25 12:31:38 -070031#include <scsi/scsi_transport.h>
32#include <linux/libata.h>
33#include <linux/hdreg.h>
34#include <linux/uaccess.h>
Lin Ming9ee4f392011-12-05 09:20:28 +080035#include <linux/pm_runtime.h>
Gwendal Grignoud9027472010-05-25 12:31:38 -070036
37#include "libata.h"
38#include "libata-transport.h"
39
40#define ATA_PORT_ATTRS 2
41#define ATA_LINK_ATTRS 3
42#define ATA_DEV_ATTRS 9
43
44struct scsi_transport_template;
45struct scsi_transport_template *ata_scsi_transport_template;
46
47struct ata_internal {
48 struct scsi_transport_template t;
49
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
54 struct transport_container link_attr_cont;
55 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];
64};
65#define to_ata_internal(tmpl) container_of(tmpl, struct ata_internal, t)
66
67
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)
72
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)
77
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)
82
83
84/* Device objects are always created whit link objects */
85static int ata_tdev_add(struct ata_device *dev);
86static void ata_tdev_delete(struct ata_device *dev);
87
88
89/*
90 * Hack to allow attributes of the same name in different objects.
91 */
92#define ATA_DEVICE_ATTR(_prefix,_name,_mode,_show,_store) \
93 struct device_attribute device_attr_##_prefix##_##_name = \
94 __ATTR(_name,_mode,_show,_store)
95
96#define ata_bitfield_name_match(title, table) \
97static ssize_t \
98get_ata_##title##_names(u32 table_key, char *buf) \
99{ \
100 char *prefix = ""; \
101 ssize_t len = 0; \
102 int i; \
103 \
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 = ", "; \
109 } \
110 } \
111 len += sprintf(buf + len, "\n"); \
112 return len; \
113}
114
115#define ata_bitfield_name_search(title, table) \
116static ssize_t \
117get_ata_##title##_names(u32 table_key, char *buf) \
118{ \
119 ssize_t len = 0; \
120 int i; \
121 \
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; \
127 } \
128 } \
129 len += sprintf(buf + len, "\n"); \
130 return len; \
131}
132
133static 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_NONE, "none" }
147};
148ata_bitfield_name_search(class, ata_class_names)
149
150
151static struct {
152 u32 value;
153 char *name;
154} ata_err_names[] = {
155 { AC_ERR_DEV, "DeviceError" },
156 { AC_ERR_HSM, "HostStateMachineError" },
157 { AC_ERR_TIMEOUT, "Timeout" },
158 { AC_ERR_MEDIA, "MediaError" },
159 { AC_ERR_ATA_BUS, "BusError" },
160 { AC_ERR_HOST_BUS, "HostBusError" },
161 { AC_ERR_SYSTEM, "SystemError" },
162 { AC_ERR_INVALID, "InvalidArg" },
163 { AC_ERR_OTHER, "Unknown" },
164 { AC_ERR_NODEV_HINT, "NoDeviceHint" },
165 { AC_ERR_NCQ, "NCQError" }
166};
167ata_bitfield_name_match(err, ata_err_names)
168
169static struct {
170 u32 value;
171 char *name;
172} ata_xfer_names[] = {
173 { XFER_UDMA_7, "XFER_UDMA_7" },
174 { XFER_UDMA_6, "XFER_UDMA_6" },
175 { XFER_UDMA_5, "XFER_UDMA_5" },
176 { XFER_UDMA_4, "XFER_UDMA_4" },
177 { XFER_UDMA_3, "XFER_UDMA_3" },
178 { XFER_UDMA_2, "XFER_UDMA_2" },
179 { XFER_UDMA_1, "XFER_UDMA_1" },
180 { XFER_UDMA_0, "XFER_UDMA_0" },
181 { XFER_MW_DMA_4, "XFER_MW_DMA_4" },
182 { XFER_MW_DMA_3, "XFER_MW_DMA_3" },
183 { XFER_MW_DMA_2, "XFER_MW_DMA_2" },
184 { XFER_MW_DMA_1, "XFER_MW_DMA_1" },
185 { XFER_MW_DMA_0, "XFER_MW_DMA_0" },
186 { XFER_SW_DMA_2, "XFER_SW_DMA_2" },
187 { XFER_SW_DMA_1, "XFER_SW_DMA_1" },
188 { XFER_SW_DMA_0, "XFER_SW_DMA_0" },
189 { XFER_PIO_6, "XFER_PIO_6" },
190 { XFER_PIO_5, "XFER_PIO_5" },
191 { XFER_PIO_4, "XFER_PIO_4" },
192 { XFER_PIO_3, "XFER_PIO_3" },
193 { XFER_PIO_2, "XFER_PIO_2" },
194 { XFER_PIO_1, "XFER_PIO_1" },
195 { XFER_PIO_0, "XFER_PIO_0" },
196 { XFER_PIO_SLOW, "XFER_PIO_SLOW" }
197};
198ata_bitfield_name_match(xfer,ata_xfer_names)
199
200/*
201 * ATA Port attributes
202 */
203#define ata_port_show_simple(field, name, format_string, cast) \
204static ssize_t \
205show_ata_port_##name(struct device *dev, \
206 struct device_attribute *attr, char *buf) \
207{ \
208 struct ata_port *ap = transport_class_to_port(dev); \
209 \
210 return snprintf(buf, 20, format_string, cast ap->field); \
211}
212
213#define ata_port_simple_attr(field, name, format_string, type) \
214 ata_port_show_simple(field, name, format_string, (type)) \
215static DEVICE_ATTR(name, S_IRUGO, show_ata_port_##name, NULL)
216
217ata_port_simple_attr(nr_pmp_links, nr_pmp_links, "%d\n", int);
218ata_port_simple_attr(stats.idle_irq, idle_irq, "%ld\n", unsigned long);
219
220static DECLARE_TRANSPORT_CLASS(ata_port_class,
221 "ata_port", NULL, NULL, NULL);
222
223static void ata_tport_release(struct device *dev)
224{
225 put_device(dev->parent);
226}
227
228/**
229 * ata_is_port -- check if a struct device represents a ATA port
230 * @dev: device to check
231 *
232 * Returns:
233 * %1 if the device represents a ATA Port, %0 else
234 */
235int ata_is_port(const struct device *dev)
236{
237 return dev->release == ata_tport_release;
238}
239
240static int ata_tport_match(struct attribute_container *cont,
241 struct device *dev)
242{
243 if (!ata_is_port(dev))
244 return 0;
245 return &ata_scsi_transport_template->host_attrs.ac == cont;
246}
247
248/**
249 * ata_tport_delete -- remove ATA PORT
250 * @port: ATA PORT to remove
251 *
252 * Removes the specified ATA PORT. Remove the associated link as well.
253 */
254void ata_tport_delete(struct ata_port *ap)
255{
256 struct device *dev = &ap->tdev;
257
258 ata_tlink_delete(&ap->link);
259
260 transport_remove_device(dev);
261 device_del(dev);
262 transport_destroy_device(dev);
263 put_device(dev);
264}
265
266/** ata_tport_add - initialize a transport ATA port structure
267 *
268 * @parent: parent device
269 * @ap: existing ata_port structure
270 *
271 * Initialize a ATA port structure for sysfs. It will be added to the device
272 * tree below the device specified by @parent which could be a PCI device.
273 *
274 * Returns %0 on success
275 */
276int ata_tport_add(struct device *parent,
277 struct ata_port *ap)
278{
279 int error;
280 struct device *dev = &ap->tdev;
281
282 device_initialize(dev);
Lin Ming5ef41082011-12-05 09:20:27 +0800283 dev->type = &ata_port_type;
Gwendal Grignoud9027472010-05-25 12:31:38 -0700284
285 dev->parent = get_device(parent);
286 dev->release = ata_tport_release;
287 dev_set_name(dev, "ata%d", ap->print_id);
288 transport_setup_device(dev);
289 error = device_add(dev);
290 if (error) {
291 goto tport_err;
292 }
293
Lin Ming9ee4f392011-12-05 09:20:28 +0800294 pm_runtime_set_active(dev);
295 pm_runtime_enable(dev);
296
Gwendal Grignoud9027472010-05-25 12:31:38 -0700297 transport_add_device(dev);
298 transport_configure_device(dev);
299
300 error = ata_tlink_add(&ap->link);
301 if (error) {
302 goto tport_link_err;
303 }
304 return 0;
305
306 tport_link_err:
307 transport_remove_device(dev);
308 device_del(dev);
309
310 tport_err:
311 transport_destroy_device(dev);
312 put_device(dev);
313 return error;
314}
315
316
317/*
318 * ATA link attributes
319 */
320
321
322#define ata_link_show_linkspeed(field) \
323static ssize_t \
324show_ata_link_##field(struct device *dev, \
325 struct device_attribute *attr, char *buf) \
326{ \
327 struct ata_link *link = transport_class_to_link(dev); \
328 \
329 return sprintf(buf,"%s\n", sata_spd_string(fls(link->field))); \
330}
331
332#define ata_link_linkspeed_attr(field) \
333 ata_link_show_linkspeed(field) \
334static DEVICE_ATTR(field, S_IRUGO, show_ata_link_##field, NULL)
335
336ata_link_linkspeed_attr(hw_sata_spd_limit);
337ata_link_linkspeed_attr(sata_spd_limit);
338ata_link_linkspeed_attr(sata_spd);
339
340
341static DECLARE_TRANSPORT_CLASS(ata_link_class,
342 "ata_link", NULL, NULL, NULL);
343
344static void ata_tlink_release(struct device *dev)
345{
346 put_device(dev->parent);
347}
348
349/**
350 * ata_is_link -- check if a struct device represents a ATA link
351 * @dev: device to check
352 *
353 * Returns:
354 * %1 if the device represents a ATA link, %0 else
355 */
356int ata_is_link(const struct device *dev)
357{
358 return dev->release == ata_tlink_release;
359}
360
361static int ata_tlink_match(struct attribute_container *cont,
362 struct device *dev)
363{
364 struct ata_internal* i = to_ata_internal(ata_scsi_transport_template);
365 if (!ata_is_link(dev))
366 return 0;
367 return &i->link_attr_cont.ac == cont;
368}
369
370/**
371 * ata_tlink_delete -- remove ATA LINK
372 * @port: ATA LINK to remove
373 *
374 * Removes the specified ATA LINK. remove associated ATA device(s) as well.
375 */
376void ata_tlink_delete(struct ata_link *link)
377{
378 struct device *dev = &link->tdev;
379 struct ata_device *ata_dev;
380
381 ata_for_each_dev(ata_dev, link, ALL) {
382 ata_tdev_delete(ata_dev);
383 }
384
385 transport_remove_device(dev);
386 device_del(dev);
387 transport_destroy_device(dev);
388 put_device(dev);
389}
390
391/**
392 * ata_tlink_add -- initialize a transport ATA link structure
393 * @link: allocated ata_link structure.
394 *
395 * Initialize an ATA LINK structure for sysfs. It will be added in the
396 * device tree below the ATA PORT it belongs to.
397 *
398 * Returns %0 on success
399 */
400int ata_tlink_add(struct ata_link *link)
401{
402 struct device *dev = &link->tdev;
403 struct ata_port *ap = link->ap;
404 struct ata_device *ata_dev;
405 int error;
406
407 device_initialize(dev);
408 dev->parent = get_device(&ap->tdev);
409 dev->release = ata_tlink_release;
410 if (ata_is_host_link(link))
411 dev_set_name(dev, "link%d", ap->print_id);
412 else
413 dev_set_name(dev, "link%d.%d", ap->print_id, link->pmp);
414
415 transport_setup_device(dev);
416
417 error = device_add(dev);
418 if (error) {
419 goto tlink_err;
420 }
421
422 transport_add_device(dev);
423 transport_configure_device(dev);
424
425 ata_for_each_dev(ata_dev, link, ALL) {
426 error = ata_tdev_add(ata_dev);
427 if (error) {
428 goto tlink_dev_err;
429 }
430 }
431 return 0;
432 tlink_dev_err:
433 while (--ata_dev >= link->device) {
434 ata_tdev_delete(ata_dev);
435 }
436 transport_remove_device(dev);
437 device_del(dev);
438 tlink_err:
439 transport_destroy_device(dev);
440 put_device(dev);
441 return error;
442}
443
444/*
445 * ATA device attributes
446 */
447
448#define ata_dev_show_class(title, field) \
449static ssize_t \
450show_ata_dev_##field(struct device *dev, \
451 struct device_attribute *attr, char *buf) \
452{ \
453 struct ata_device *ata_dev = transport_class_to_dev(dev); \
454 \
455 return get_ata_##title##_names(ata_dev->field, buf); \
456}
457
458#define ata_dev_attr(title, field) \
459 ata_dev_show_class(title, field) \
460static DEVICE_ATTR(field, S_IRUGO, show_ata_dev_##field, NULL)
461
462ata_dev_attr(class, class);
463ata_dev_attr(xfer, pio_mode);
464ata_dev_attr(xfer, dma_mode);
465ata_dev_attr(xfer, xfer_mode);
466
467
468#define ata_dev_show_simple(field, format_string, cast) \
469static ssize_t \
470show_ata_dev_##field(struct device *dev, \
471 struct device_attribute *attr, char *buf) \
472{ \
473 struct ata_device *ata_dev = transport_class_to_dev(dev); \
474 \
475 return snprintf(buf, 20, format_string, cast ata_dev->field); \
476}
477
478#define ata_dev_simple_attr(field, format_string, type) \
479 ata_dev_show_simple(field, format_string, (type)) \
480static DEVICE_ATTR(field, S_IRUGO, \
481 show_ata_dev_##field, NULL)
482
483ata_dev_simple_attr(spdn_cnt, "%d\n", int);
484
485struct ata_show_ering_arg {
486 char* buf;
487 int written;
488};
489
490static int ata_show_ering(struct ata_ering_entry *ent, void *void_arg)
491{
492 struct ata_show_ering_arg* arg = void_arg;
493 struct timespec time;
494
495 jiffies_to_timespec(ent->timestamp,&time);
496 arg->written += sprintf(arg->buf + arg->written,
497 "[%5lu.%06lu]",
498 time.tv_sec, time.tv_nsec);
499 arg->written += get_ata_err_names(ent->err_mask,
500 arg->buf + arg->written);
501 return 0;
502}
503
504static ssize_t
505show_ata_dev_ering(struct device *dev,
506 struct device_attribute *attr, char *buf)
507{
508 struct ata_device *ata_dev = transport_class_to_dev(dev);
509 struct ata_show_ering_arg arg = { buf, 0 };
510
511 ata_ering_map(&ata_dev->ering, ata_show_ering, &arg);
512 return arg.written;
513}
514
515
516static DEVICE_ATTR(ering, S_IRUGO, show_ata_dev_ering, NULL);
517
518static ssize_t
519show_ata_dev_id(struct device *dev,
520 struct device_attribute *attr, char *buf)
521{
522 struct ata_device *ata_dev = transport_class_to_dev(dev);
523 int written = 0, i = 0;
524
525 if (ata_dev->class == ATA_DEV_PMP)
526 return 0;
527 for(i=0;i<ATA_ID_WORDS;i++) {
528 written += snprintf(buf+written, 20, "%04x%c",
529 ata_dev->id[i],
530 ((i+1) & 7) ? ' ' : '\n');
531 }
532 return written;
533}
534
535static DEVICE_ATTR(id, S_IRUGO, show_ata_dev_id, NULL);
536
537static ssize_t
538show_ata_dev_gscr(struct device *dev,
539 struct device_attribute *attr, char *buf)
540{
541 struct ata_device *ata_dev = transport_class_to_dev(dev);
542 int written = 0, i = 0;
543
544 if (ata_dev->class != ATA_DEV_PMP)
545 return 0;
546 for(i=0;i<SATA_PMP_GSCR_DWORDS;i++) {
547 written += snprintf(buf+written, 20, "%08x%c",
548 ata_dev->gscr[i],
549 ((i+1) & 3) ? ' ' : '\n');
550 }
551 if (SATA_PMP_GSCR_DWORDS & 3)
552 buf[written-1] = '\n';
553 return written;
554}
555
556static DEVICE_ATTR(gscr, S_IRUGO, show_ata_dev_gscr, NULL);
557
558static DECLARE_TRANSPORT_CLASS(ata_dev_class,
559 "ata_device", NULL, NULL, NULL);
560
561static void ata_tdev_release(struct device *dev)
562{
563 put_device(dev->parent);
564}
565
566/**
567 * ata_is_ata_dev -- check if a struct device represents a ATA device
568 * @dev: device to check
569 *
570 * Returns:
571 * %1 if the device represents a ATA device, %0 else
572 */
573int ata_is_ata_dev(const struct device *dev)
574{
575 return dev->release == ata_tdev_release;
576}
577
578static int ata_tdev_match(struct attribute_container *cont,
579 struct device *dev)
580{
581 struct ata_internal* i = to_ata_internal(ata_scsi_transport_template);
582 if (!ata_is_ata_dev(dev))
583 return 0;
584 return &i->dev_attr_cont.ac == cont;
585}
586
587/**
588 * ata_tdev_free -- free a ATA LINK
589 * @dev: ATA PHY to free
590 *
591 * Frees the specified ATA PHY.
592 *
593 * Note:
594 * This function must only be called on a PHY that has not
595 * successfully been added using ata_tdev_add().
596 */
597static void ata_tdev_free(struct ata_device *dev)
598{
599 transport_destroy_device(&dev->tdev);
600 put_device(&dev->tdev);
601}
602
603/**
604 * ata_tdev_delete -- remove ATA device
605 * @port: ATA PORT to remove
606 *
607 * Removes the specified ATA device.
608 */
609static void ata_tdev_delete(struct ata_device *ata_dev)
610{
611 struct device *dev = &ata_dev->tdev;
612
613 transport_remove_device(dev);
614 device_del(dev);
615 ata_tdev_free(ata_dev);
616}
617
618
619/**
620 * ata_tdev_add -- initialize a transport ATA device structure.
621 * @ata_dev: ata_dev structure.
622 *
623 * Initialize an ATA device structure for sysfs. It will be added in the
624 * device tree below the ATA LINK device it belongs to.
625 *
626 * Returns %0 on success
627 */
628static int ata_tdev_add(struct ata_device *ata_dev)
629{
630 struct device *dev = &ata_dev->tdev;
631 struct ata_link *link = ata_dev->link;
632 struct ata_port *ap = link->ap;
633 int error;
634
635 device_initialize(dev);
636 dev->parent = get_device(&link->tdev);
637 dev->release = ata_tdev_release;
638 if (ata_is_host_link(link))
639 dev_set_name(dev, "dev%d.%d", ap->print_id,ata_dev->devno);
640 else
641 dev_set_name(dev, "dev%d.%d.0", ap->print_id, link->pmp);
642
643 transport_setup_device(dev);
644 error = device_add(dev);
645 if (error) {
646 ata_tdev_free(ata_dev);
647 return error;
648 }
649
650 transport_add_device(dev);
651 transport_configure_device(dev);
652 return 0;
653}
654
655
656/*
657 * Setup / Teardown code
658 */
659
660#define SETUP_TEMPLATE(attrb, field, perm, test) \
661 i->private_##attrb[count] = dev_attr_##field; \
662 i->private_##attrb[count].attr.mode = perm; \
663 i->attrb[count] = &i->private_##attrb[count]; \
664 if (test) \
665 count++
666
667#define SETUP_LINK_ATTRIBUTE(field) \
668 SETUP_TEMPLATE(link_attrs, field, S_IRUGO, 1)
669
670#define SETUP_PORT_ATTRIBUTE(field) \
671 SETUP_TEMPLATE(port_attrs, field, S_IRUGO, 1)
672
673#define SETUP_DEV_ATTRIBUTE(field) \
674 SETUP_TEMPLATE(dev_attrs, field, S_IRUGO, 1)
675
676/**
677 * ata_attach_transport -- instantiate ATA transport template
678 */
679struct scsi_transport_template *ata_attach_transport(void)
680{
681 struct ata_internal *i;
682 int count;
683
684 i = kzalloc(sizeof(struct ata_internal), GFP_KERNEL);
685 if (!i)
686 return NULL;
687
688 i->t.eh_strategy_handler = ata_scsi_error;
689 i->t.eh_timed_out = ata_scsi_timed_out;
690 i->t.user_scan = ata_scsi_user_scan;
691
692 i->t.host_attrs.ac.attrs = &i->port_attrs[0];
693 i->t.host_attrs.ac.class = &ata_port_class.class;
694 i->t.host_attrs.ac.match = ata_tport_match;
695 transport_container_register(&i->t.host_attrs);
696
697 i->link_attr_cont.ac.class = &ata_link_class.class;
698 i->link_attr_cont.ac.attrs = &i->link_attrs[0];
699 i->link_attr_cont.ac.match = ata_tlink_match;
700 transport_container_register(&i->link_attr_cont);
701
702 i->dev_attr_cont.ac.class = &ata_dev_class.class;
703 i->dev_attr_cont.ac.attrs = &i->dev_attrs[0];
704 i->dev_attr_cont.ac.match = ata_tdev_match;
705 transport_container_register(&i->dev_attr_cont);
706
707 count = 0;
708 SETUP_PORT_ATTRIBUTE(nr_pmp_links);
709 SETUP_PORT_ATTRIBUTE(idle_irq);
710 BUG_ON(count > ATA_PORT_ATTRS);
711 i->port_attrs[count] = NULL;
712
713 count = 0;
714 SETUP_LINK_ATTRIBUTE(hw_sata_spd_limit);
715 SETUP_LINK_ATTRIBUTE(sata_spd_limit);
716 SETUP_LINK_ATTRIBUTE(sata_spd);
717 BUG_ON(count > ATA_LINK_ATTRS);
718 i->link_attrs[count] = NULL;
719
720 count = 0;
721 SETUP_DEV_ATTRIBUTE(class);
722 SETUP_DEV_ATTRIBUTE(pio_mode);
723 SETUP_DEV_ATTRIBUTE(dma_mode);
724 SETUP_DEV_ATTRIBUTE(xfer_mode);
725 SETUP_DEV_ATTRIBUTE(spdn_cnt);
726 SETUP_DEV_ATTRIBUTE(ering);
727 SETUP_DEV_ATTRIBUTE(id);
728 SETUP_DEV_ATTRIBUTE(gscr);
729 BUG_ON(count > ATA_DEV_ATTRS);
730 i->dev_attrs[count] = NULL;
731
732 return &i->t;
733}
734
735/**
736 * ata_release_transport -- release ATA transport template instance
737 * @t: transport template instance
738 */
739void ata_release_transport(struct scsi_transport_template *t)
740{
741 struct ata_internal *i = to_ata_internal(t);
742
743 transport_container_unregister(&i->t.host_attrs);
744 transport_container_unregister(&i->link_attr_cont);
745 transport_container_unregister(&i->dev_attr_cont);
746
747 kfree(i);
748}
749
750__init int libata_transport_init(void)
751{
752 int error;
753
754 error = transport_class_register(&ata_link_class);
755 if (error)
756 goto out_unregister_transport;
757 error = transport_class_register(&ata_port_class);
758 if (error)
759 goto out_unregister_link;
760 error = transport_class_register(&ata_dev_class);
761 if (error)
762 goto out_unregister_port;
763 return 0;
764
765 out_unregister_port:
766 transport_class_unregister(&ata_port_class);
767 out_unregister_link:
768 transport_class_unregister(&ata_link_class);
769 out_unregister_transport:
770 return error;
771
772}
773
774void __exit libata_transport_exit(void)
775{
776 transport_class_unregister(&ata_link_class);
777 transport_class_unregister(&ata_port_class);
778 transport_class_unregister(&ata_dev_class);
779}