/*
 *  Copyright 2008 ioogle, Inc.  All rights reserved.
 *	Released under GPL v2.
 *
 * Libata transport class.
 *
 * The ATA transport class contains common code to deal with ATA HBAs,
 * an approximated representation of ATA topologies in the driver model,
 * and various sysfs attributes to expose these topologies and management
 * interfaces to user-space.
 *
 * There are 3 objects defined in in this class:
 * - ata_port
 * - ata_link
 * - ata_device
 * Each port has a link object. Each link can have up to two devices for PATA
 * and generally one for SATA.
 * If there is SATA port multiplier [PMP], 15 additional ata_link object are
 * created.
 *
 * These objects are created when the ata host is initialized and when a PMP is
 * found. They are removed only when the HBA is removed, cleaned before the
 * error handler runs.
 */


#include <linux/kernel.h>
#include <linux/blkdev.h>
#include <linux/spinlock.h>
#include <linux/slab.h>
#include <scsi/scsi_transport.h>
#include <linux/libata.h>
#include <linux/hdreg.h>
#include <linux/uaccess.h>
#include <linux/pm_runtime.h>

#include "libata.h"
#include "libata-transport.h"

#define ATA_PORT_ATTRS		3
#define ATA_LINK_ATTRS		3
#define ATA_DEV_ATTRS		9

struct scsi_transport_template;
struct scsi_transport_template *ata_scsi_transport_template;

struct ata_internal {
	struct scsi_transport_template t;

	struct device_attribute private_port_attrs[ATA_PORT_ATTRS];
	struct device_attribute private_link_attrs[ATA_LINK_ATTRS];
	struct device_attribute private_dev_attrs[ATA_DEV_ATTRS];

	struct transport_container link_attr_cont;
	struct transport_container dev_attr_cont;

	/*
	 * The array of null terminated pointers to attributes
	 * needed by scsi_sysfs.c
	 */
	struct device_attribute *link_attrs[ATA_LINK_ATTRS + 1];
	struct device_attribute *port_attrs[ATA_PORT_ATTRS + 1];
	struct device_attribute *dev_attrs[ATA_DEV_ATTRS + 1];
};
#define to_ata_internal(tmpl)	container_of(tmpl, struct ata_internal, t)


#define tdev_to_device(d)					\
	container_of((d), struct ata_device, tdev)
#define transport_class_to_dev(dev)				\
	tdev_to_device((dev)->parent)

#define tdev_to_link(d)						\
	container_of((d), struct ata_link, tdev)
#define transport_class_to_link(dev)				\
	tdev_to_link((dev)->parent)

#define tdev_to_port(d)						\
	container_of((d), struct ata_port, tdev)
#define transport_class_to_port(dev)				\
	tdev_to_port((dev)->parent)


/* Device objects are always created whit link objects */
static int ata_tdev_add(struct ata_device *dev);
static void ata_tdev_delete(struct ata_device *dev);


/*
 * Hack to allow attributes of the same name in different objects.
 */
#define ATA_DEVICE_ATTR(_prefix,_name,_mode,_show,_store) \
	struct device_attribute device_attr_##_prefix##_##_name = \
	__ATTR(_name,_mode,_show,_store)

#define ata_bitfield_name_match(title, table)			\
static ssize_t							\
get_ata_##title##_names(u32 table_key, char *buf)		\
{								\
	char *prefix = "";					\
	ssize_t len = 0;					\
	int i;							\
								\
	for (i = 0; i < ARRAY_SIZE(table); i++) {		\
		if (table[i].value & table_key) {		\
			len += sprintf(buf + len, "%s%s",	\
				prefix, table[i].name);		\
			prefix = ", ";				\
		}						\
	}							\
	len += sprintf(buf + len, "\n");			\
	return len;						\
}

#define ata_bitfield_name_search(title, table)			\
static ssize_t							\
get_ata_##title##_names(u32 table_key, char *buf)		\
{								\
	ssize_t len = 0;					\
	int i;							\
								\
	for (i = 0; i < ARRAY_SIZE(table); i++) {		\
		if (table[i].value == table_key) {		\
			len += sprintf(buf + len, "%s",		\
				table[i].name);			\
			break;					\
		}						\
	}							\
	len += sprintf(buf + len, "\n");			\
	return len;						\
}

static struct {
	u32		value;
	char		*name;
} ata_class_names[] = {
	{ ATA_DEV_UNKNOWN,		"unknown" },
	{ ATA_DEV_ATA,			"ata" },
	{ ATA_DEV_ATA_UNSUP,		"ata" },
	{ ATA_DEV_ATAPI,		"atapi" },
	{ ATA_DEV_ATAPI_UNSUP,		"atapi" },
	{ ATA_DEV_PMP,			"pmp" },
	{ ATA_DEV_PMP_UNSUP,		"pmp" },
	{ ATA_DEV_SEMB,			"semb" },
	{ ATA_DEV_SEMB_UNSUP,		"semb" },
	{ ATA_DEV_ZAC,			"zac" },
	{ ATA_DEV_NONE,			"none" }
};
ata_bitfield_name_search(class, ata_class_names)


static struct {
	u32		value;
	char		*name;
} ata_err_names[] = {
	{ AC_ERR_DEV,			"DeviceError" },
	{ AC_ERR_HSM,			"HostStateMachineError" },
	{ AC_ERR_TIMEOUT,		"Timeout" },
	{ AC_ERR_MEDIA,			"MediaError" },
	{ AC_ERR_ATA_BUS,		"BusError" },
	{ AC_ERR_HOST_BUS,		"HostBusError" },
	{ AC_ERR_SYSTEM,		"SystemError" },
	{ AC_ERR_INVALID,		"InvalidArg" },
	{ AC_ERR_OTHER,			"Unknown" },
	{ AC_ERR_NODEV_HINT,		"NoDeviceHint" },
	{ AC_ERR_NCQ,		 	"NCQError" }
};
ata_bitfield_name_match(err, ata_err_names)

static struct {
	u32		value;
	char		*name;
} ata_xfer_names[] = {
	{ XFER_UDMA_7,			"XFER_UDMA_7" },
	{ XFER_UDMA_6,			"XFER_UDMA_6" },
	{ XFER_UDMA_5,			"XFER_UDMA_5" },
	{ XFER_UDMA_4,			"XFER_UDMA_4" },
	{ XFER_UDMA_3,			"XFER_UDMA_3" },
	{ XFER_UDMA_2,			"XFER_UDMA_2" },
	{ XFER_UDMA_1,			"XFER_UDMA_1" },
	{ XFER_UDMA_0,			"XFER_UDMA_0" },
	{ XFER_MW_DMA_4,		"XFER_MW_DMA_4" },
	{ XFER_MW_DMA_3,		"XFER_MW_DMA_3" },
	{ XFER_MW_DMA_2,		"XFER_MW_DMA_2" },
	{ XFER_MW_DMA_1,		"XFER_MW_DMA_1" },
	{ XFER_MW_DMA_0,		"XFER_MW_DMA_0" },
	{ XFER_SW_DMA_2,		"XFER_SW_DMA_2" },
	{ XFER_SW_DMA_1,		"XFER_SW_DMA_1" },
	{ XFER_SW_DMA_0,		"XFER_SW_DMA_0" },
	{ XFER_PIO_6,			"XFER_PIO_6" },
	{ XFER_PIO_5,			"XFER_PIO_5" },
	{ XFER_PIO_4,			"XFER_PIO_4" },
	{ XFER_PIO_3,			"XFER_PIO_3" },
	{ XFER_PIO_2,			"XFER_PIO_2" },
	{ XFER_PIO_1,			"XFER_PIO_1" },
	{ XFER_PIO_0,			"XFER_PIO_0" },
	{ XFER_PIO_SLOW,		"XFER_PIO_SLOW" }
};
ata_bitfield_name_search(xfer, ata_xfer_names)

/*
 * ATA Port attributes
 */
#define ata_port_show_simple(field, name, format_string, cast)		\
static ssize_t								\
show_ata_port_##name(struct device *dev,				\
		     struct device_attribute *attr, char *buf)		\
{									\
	struct ata_port *ap = transport_class_to_port(dev);		\
									\
	return snprintf(buf, 20, format_string, cast ap->field);	\
}

#define ata_port_simple_attr(field, name, format_string, type)		\
	ata_port_show_simple(field, name, format_string, (type))	\
static DEVICE_ATTR(name, S_IRUGO, show_ata_port_##name, NULL)

ata_port_simple_attr(nr_pmp_links, nr_pmp_links, "%d\n", int);
ata_port_simple_attr(stats.idle_irq, idle_irq, "%ld\n", unsigned long);
ata_port_simple_attr(local_port_no, port_no, "%u\n", unsigned int);

static DECLARE_TRANSPORT_CLASS(ata_port_class,
			       "ata_port", NULL, NULL, NULL);

static void ata_tport_release(struct device *dev)
{
}

/**
 * ata_is_port --  check if a struct device represents a ATA port
 * @dev:	device to check
 *
 * Returns:
 *	%1 if the device represents a ATA Port, %0 else
 */
static int ata_is_port(const struct device *dev)
{
	return dev->release == ata_tport_release;
}

static int ata_tport_match(struct attribute_container *cont,
			   struct device *dev)
{
	if (!ata_is_port(dev))
		return 0;
	return &ata_scsi_transport_template->host_attrs.ac == cont;
}

/**
 * ata_tport_delete  --  remove ATA PORT
 * @port:	ATA PORT to remove
 *
 * Removes the specified ATA PORT.  Remove the associated link as well.
 */
void ata_tport_delete(struct ata_port *ap)
{
	struct device *dev = &ap->tdev;

	ata_tlink_delete(&ap->link);

	transport_remove_device(dev);
	device_del(dev);
	transport_destroy_device(dev);
	put_device(dev);
}

static const struct device_type ata_port_sas_type = {
	.name = ATA_PORT_TYPE_NAME,
};

/** ata_tport_add - initialize a transport ATA port structure
 *
 * @parent:	parent device
 * @ap:		existing ata_port structure
 *
 * Initialize a ATA port structure for sysfs.  It will be added to the device
 * tree below the device specified by @parent which could be a PCI device.
 *
 * Returns %0 on success
 */
int ata_tport_add(struct device *parent,
		  struct ata_port *ap)
{
	int error;
	struct device *dev = &ap->tdev;

	device_initialize(dev);
	if (ap->flags & ATA_FLAG_SAS_HOST)
		dev->type = &ata_port_sas_type;
	else
		dev->type = &ata_port_type;

	dev->parent = parent;
	dev->release = ata_tport_release;
	dev_set_name(dev, "ata%d", ap->print_id);
	transport_setup_device(dev);
	ata_acpi_bind_port(ap);
	error = device_add(dev);
	if (error) {
		goto tport_err;
	}

	device_enable_async_suspend(dev);
	pm_runtime_set_active(dev);
	pm_runtime_enable(dev);
	pm_runtime_forbid(dev);

	transport_add_device(dev);
	transport_configure_device(dev);

	error = ata_tlink_add(&ap->link);
	if (error) {
		goto tport_link_err;
	}
	return 0;

 tport_link_err:
	transport_remove_device(dev);
	device_del(dev);

 tport_err:
	transport_destroy_device(dev);
	put_device(dev);
	return error;
}


/*
 * ATA link attributes
 */
static int noop(int x) { return x; }

#define ata_link_show_linkspeed(field, format)			        \
static ssize_t								\
show_ata_link_##field(struct device *dev,				\
		      struct device_attribute *attr, char *buf)		\
{									\
	struct ata_link *link = transport_class_to_link(dev);		\
									\
	return sprintf(buf, "%s\n", sata_spd_string(format(link->field))); \
}

#define ata_link_linkspeed_attr(field, format)				\
	ata_link_show_linkspeed(field, format)				\
static DEVICE_ATTR(field, S_IRUGO, show_ata_link_##field, NULL)

ata_link_linkspeed_attr(hw_sata_spd_limit, fls);
ata_link_linkspeed_attr(sata_spd_limit, fls);
ata_link_linkspeed_attr(sata_spd, noop);


static DECLARE_TRANSPORT_CLASS(ata_link_class,
		"ata_link", NULL, NULL, NULL);

static void ata_tlink_release(struct device *dev)
{
}

/**
 * ata_is_link --  check if a struct device represents a ATA link
 * @dev:	device to check
 *
 * Returns:
 *	%1 if the device represents a ATA link, %0 else
 */
static int ata_is_link(const struct device *dev)
{
	return dev->release == ata_tlink_release;
}

static int ata_tlink_match(struct attribute_container *cont,
			   struct device *dev)
{
	struct ata_internal* i = to_ata_internal(ata_scsi_transport_template);
	if (!ata_is_link(dev))
		return 0;
	return &i->link_attr_cont.ac == cont;
}

/**
 * ata_tlink_delete  --  remove ATA LINK
 * @port:	ATA LINK to remove
 *
 * Removes the specified ATA LINK.  remove associated ATA device(s) as well.
 */
void ata_tlink_delete(struct ata_link *link)
{
	struct device *dev = &link->tdev;
	struct ata_device *ata_dev;

	ata_for_each_dev(ata_dev, link, ALL) {
		ata_tdev_delete(ata_dev);
	}

	transport_remove_device(dev);
	device_del(dev);
	transport_destroy_device(dev);
	put_device(dev);
}

/**
 * ata_tlink_add  --  initialize a transport ATA link structure
 * @link:	allocated ata_link structure.
 *
 * Initialize an ATA LINK structure for sysfs.  It will be added in the
 * device tree below the ATA PORT it belongs to.
 *
 * Returns %0 on success
 */
int ata_tlink_add(struct ata_link *link)
{
	struct device *dev = &link->tdev;
	struct ata_port *ap = link->ap;
	struct ata_device *ata_dev;
	int error;

	device_initialize(dev);
	dev->parent = &ap->tdev;
	dev->release = ata_tlink_release;
	if (ata_is_host_link(link))
		dev_set_name(dev, "link%d", ap->print_id);
        else
		dev_set_name(dev, "link%d.%d", ap->print_id, link->pmp);

	transport_setup_device(dev);

	error = device_add(dev);
	if (error) {
		goto tlink_err;
	}

	transport_add_device(dev);
	transport_configure_device(dev);

	ata_for_each_dev(ata_dev, link, ALL) {
		error = ata_tdev_add(ata_dev);
		if (error) {
			goto tlink_dev_err;
		}
	}
	return 0;
  tlink_dev_err:
	while (--ata_dev >= link->device) {
		ata_tdev_delete(ata_dev);
	}
	transport_remove_device(dev);
	device_del(dev);
  tlink_err:
	transport_destroy_device(dev);
	put_device(dev);
	return error;
}

/*
 * ATA device attributes
 */

#define ata_dev_show_class(title, field)				\
static ssize_t								\
show_ata_dev_##field(struct device *dev,				\
		     struct device_attribute *attr, char *buf)		\
{									\
	struct ata_device *ata_dev = transport_class_to_dev(dev);	\
									\
	return get_ata_##title##_names(ata_dev->field, buf);		\
}

#define ata_dev_attr(title, field)					\
	ata_dev_show_class(title, field)				\
static DEVICE_ATTR(field, S_IRUGO, show_ata_dev_##field, NULL)

ata_dev_attr(class, class);
ata_dev_attr(xfer, pio_mode);
ata_dev_attr(xfer, dma_mode);
ata_dev_attr(xfer, xfer_mode);


#define ata_dev_show_simple(field, format_string, cast)		\
static ssize_t								\
show_ata_dev_##field(struct device *dev,				\
		     struct device_attribute *attr, char *buf)		\
{									\
	struct ata_device *ata_dev = transport_class_to_dev(dev);	\
									\
	return snprintf(buf, 20, format_string, cast ata_dev->field);	\
}

#define ata_dev_simple_attr(field, format_string, type)	\
	ata_dev_show_simple(field, format_string, (type))	\
static DEVICE_ATTR(field, S_IRUGO, 			\
		   show_ata_dev_##field, NULL)

ata_dev_simple_attr(spdn_cnt, "%d\n", int);

struct ata_show_ering_arg {
	char* buf;
	int written;
};

static int ata_show_ering(struct ata_ering_entry *ent, void *void_arg)
{
	struct ata_show_ering_arg* arg = void_arg;
	u64 seconds;
	u32 rem;

	seconds = div_u64_rem(ent->timestamp, HZ, &rem);
	arg->written += sprintf(arg->buf + arg->written,
			        "[%5llu.%09lu]", seconds,
				rem * NSEC_PER_SEC / HZ);
	arg->written += get_ata_err_names(ent->err_mask,
					  arg->buf + arg->written);
	return 0;
}

static ssize_t
show_ata_dev_ering(struct device *dev,
		   struct device_attribute *attr, char *buf)
{
	struct ata_device *ata_dev = transport_class_to_dev(dev);
	struct ata_show_ering_arg arg = { buf, 0 };

	ata_ering_map(&ata_dev->ering, ata_show_ering, &arg);
	return arg.written;
}


static DEVICE_ATTR(ering, S_IRUGO, show_ata_dev_ering, NULL);

static ssize_t
show_ata_dev_id(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	struct ata_device *ata_dev = transport_class_to_dev(dev);
	int written = 0, i = 0;

	if (ata_dev->class == ATA_DEV_PMP)
		return 0;
	for(i=0;i<ATA_ID_WORDS;i++)  {
		written += snprintf(buf+written, 20, "%04x%c",
				    ata_dev->id[i],
				    ((i+1) & 7) ? ' ' : '\n');
	}
	return written;
}

static DEVICE_ATTR(id, S_IRUGO, show_ata_dev_id, NULL);

static ssize_t
show_ata_dev_gscr(struct device *dev,
		  struct device_attribute *attr, char *buf)
{
	struct ata_device *ata_dev = transport_class_to_dev(dev);
	int written = 0, i = 0;

	if (ata_dev->class != ATA_DEV_PMP)
		return 0;
	for(i=0;i<SATA_PMP_GSCR_DWORDS;i++)  {
		written += snprintf(buf+written, 20, "%08x%c",
				    ata_dev->gscr[i],
				    ((i+1) & 3) ? ' ' : '\n');
	}
	if (SATA_PMP_GSCR_DWORDS & 3)
		buf[written-1] = '\n';
	return written;
}

static DEVICE_ATTR(gscr, S_IRUGO, show_ata_dev_gscr, NULL);

static ssize_t
show_ata_dev_trim(struct device *dev,
		  struct device_attribute *attr, char *buf)
{
	struct ata_device *ata_dev = transport_class_to_dev(dev);
	unsigned char *mode;

	if (!ata_id_has_trim(ata_dev->id))
		mode = "unsupported";
	else if (ata_dev->horkage & ATA_HORKAGE_NOTRIM)
		mode = "forced_unsupported";
	else if (ata_dev->horkage & ATA_HORKAGE_NO_NCQ_TRIM)
			mode = "forced_unqueued";
	else if (ata_fpdma_dsm_supported(ata_dev))
		mode = "queued";
	else
		mode = "unqueued";

	return snprintf(buf, 20, "%s\n", mode);
}

static DEVICE_ATTR(trim, S_IRUGO, show_ata_dev_trim, NULL);

static DECLARE_TRANSPORT_CLASS(ata_dev_class,
			       "ata_device", NULL, NULL, NULL);

static void ata_tdev_release(struct device *dev)
{
}

/**
 * ata_is_ata_dev  --  check if a struct device represents a ATA device
 * @dev:	device to check
 *
 * Returns:
 *	%1 if the device represents a ATA device, %0 else
 */
static int ata_is_ata_dev(const struct device *dev)
{
	return dev->release == ata_tdev_release;
}

static int ata_tdev_match(struct attribute_container *cont,
			  struct device *dev)
{
	struct ata_internal* i = to_ata_internal(ata_scsi_transport_template);
	if (!ata_is_ata_dev(dev))
		return 0;
	return &i->dev_attr_cont.ac == cont;
}

/**
 * ata_tdev_free  --  free a ATA LINK
 * @dev:	ATA PHY to free
 *
 * Frees the specified ATA PHY.
 *
 * Note:
 *   This function must only be called on a PHY that has not
 *   successfully been added using ata_tdev_add().
 */
static void ata_tdev_free(struct ata_device *dev)
{
	transport_destroy_device(&dev->tdev);
	put_device(&dev->tdev);
}

/**
 * ata_tdev_delete  --  remove ATA device
 * @port:	ATA PORT to remove
 *
 * Removes the specified ATA device.
 */
static void ata_tdev_delete(struct ata_device *ata_dev)
{
	struct device *dev = &ata_dev->tdev;

	transport_remove_device(dev);
	device_del(dev);
	ata_tdev_free(ata_dev);
}


/**
 * ata_tdev_add  --  initialize a transport ATA device structure.
 * @ata_dev:	ata_dev structure.
 *
 * Initialize an ATA device structure for sysfs.  It will be added in the
 * device tree below the ATA LINK device it belongs to.
 *
 * Returns %0 on success
 */
static int ata_tdev_add(struct ata_device *ata_dev)
{
	struct device *dev = &ata_dev->tdev;
	struct ata_link *link = ata_dev->link;
	struct ata_port *ap = link->ap;
	int error;

	device_initialize(dev);
	dev->parent = &link->tdev;
	dev->release = ata_tdev_release;
	if (ata_is_host_link(link))
		dev_set_name(dev, "dev%d.%d", ap->print_id,ata_dev->devno);
        else
		dev_set_name(dev, "dev%d.%d.0", ap->print_id, link->pmp);

	transport_setup_device(dev);
	ata_acpi_bind_dev(ata_dev);
	error = device_add(dev);
	if (error) {
		ata_tdev_free(ata_dev);
		return error;
	}

	transport_add_device(dev);
	transport_configure_device(dev);
	return 0;
}


/*
 * Setup / Teardown code
 */

#define SETUP_TEMPLATE(attrb, field, perm, test)			\
	i->private_##attrb[count] = dev_attr_##field;		       	\
	i->private_##attrb[count].attr.mode = perm;			\
	i->attrb[count] = &i->private_##attrb[count];			\
	if (test)							\
		count++

#define SETUP_LINK_ATTRIBUTE(field)					\
	SETUP_TEMPLATE(link_attrs, field, S_IRUGO, 1)

#define SETUP_PORT_ATTRIBUTE(field)					\
	SETUP_TEMPLATE(port_attrs, field, S_IRUGO, 1)

#define SETUP_DEV_ATTRIBUTE(field)					\
	SETUP_TEMPLATE(dev_attrs, field, S_IRUGO, 1)

/**
 * ata_attach_transport  --  instantiate ATA transport template
 */
struct scsi_transport_template *ata_attach_transport(void)
{
	struct ata_internal *i;
	int count;

	i = kzalloc(sizeof(struct ata_internal), GFP_KERNEL);
	if (!i)
		return NULL;

	i->t.eh_strategy_handler	= ata_scsi_error;
	i->t.user_scan			= ata_scsi_user_scan;

	i->t.host_attrs.ac.attrs = &i->port_attrs[0];
	i->t.host_attrs.ac.class = &ata_port_class.class;
	i->t.host_attrs.ac.match = ata_tport_match;
	transport_container_register(&i->t.host_attrs);

	i->link_attr_cont.ac.class = &ata_link_class.class;
	i->link_attr_cont.ac.attrs = &i->link_attrs[0];
	i->link_attr_cont.ac.match = ata_tlink_match;
	transport_container_register(&i->link_attr_cont);

	i->dev_attr_cont.ac.class = &ata_dev_class.class;
	i->dev_attr_cont.ac.attrs = &i->dev_attrs[0];
	i->dev_attr_cont.ac.match = ata_tdev_match;
	transport_container_register(&i->dev_attr_cont);

	count = 0;
	SETUP_PORT_ATTRIBUTE(nr_pmp_links);
	SETUP_PORT_ATTRIBUTE(idle_irq);
	SETUP_PORT_ATTRIBUTE(port_no);
	BUG_ON(count > ATA_PORT_ATTRS);
	i->port_attrs[count] = NULL;

	count = 0;
	SETUP_LINK_ATTRIBUTE(hw_sata_spd_limit);
	SETUP_LINK_ATTRIBUTE(sata_spd_limit);
	SETUP_LINK_ATTRIBUTE(sata_spd);
	BUG_ON(count > ATA_LINK_ATTRS);
	i->link_attrs[count] = NULL;

	count = 0;
	SETUP_DEV_ATTRIBUTE(class);
	SETUP_DEV_ATTRIBUTE(pio_mode);
	SETUP_DEV_ATTRIBUTE(dma_mode);
	SETUP_DEV_ATTRIBUTE(xfer_mode);
	SETUP_DEV_ATTRIBUTE(spdn_cnt);
	SETUP_DEV_ATTRIBUTE(ering);
	SETUP_DEV_ATTRIBUTE(id);
	SETUP_DEV_ATTRIBUTE(gscr);
	SETUP_DEV_ATTRIBUTE(trim);
	BUG_ON(count > ATA_DEV_ATTRS);
	i->dev_attrs[count] = NULL;

	return &i->t;
}

/**
 * ata_release_transport  --  release ATA transport template instance
 * @t:		transport template instance
 */
void ata_release_transport(struct scsi_transport_template *t)
{
	struct ata_internal *i = to_ata_internal(t);

	transport_container_unregister(&i->t.host_attrs);
	transport_container_unregister(&i->link_attr_cont);
	transport_container_unregister(&i->dev_attr_cont);

	kfree(i);
}

__init int libata_transport_init(void)
{
	int error;

	error = transport_class_register(&ata_link_class);
	if (error)
		goto out_unregister_transport;
	error = transport_class_register(&ata_port_class);
	if (error)
		goto out_unregister_link;
	error = transport_class_register(&ata_dev_class);
	if (error)
		goto out_unregister_port;
	return 0;

 out_unregister_port:
	transport_class_unregister(&ata_port_class);
 out_unregister_link:
	transport_class_unregister(&ata_link_class);
 out_unregister_transport:
	return error;

}

void __exit libata_transport_exit(void)
{
	transport_class_unregister(&ata_link_class);
	transport_class_unregister(&ata_port_class);
	transport_class_unregister(&ata_dev_class);
}
