2 * Copyright (C) 2005-2006 Dell Inc.
3 * Released under GPL v2.
5 * Serial Attached SCSI (SAS) transport class.
7 * The SAS transport class contains common code to deal with SAS HBAs,
8 * an aproximated representation of SAS topologies in the driver model,
9 * and various sysfs attributes to expose these topologies and managment
10 * interfaces to userspace.
12 * In addition to the basic SCSI core objects this transport class
13 * introduces two additional intermediate objects: The SAS PHY
14 * as represented by struct sas_phy defines an "outgoing" PHY on
15 * a SAS HBA or Expander, and the SAS remote PHY represented by
16 * struct sas_rphy defines an "incoming" PHY on a SAS Expander or
17 * end device. Note that this is purely a software concept, the
18 * underlying hardware for a PHY and a remote PHY is the exactly
21 * There is no concept of a SAS port in this code, users can see
22 * what PHYs form a wide port based on the port_identifier attribute,
23 * which is the same for all PHYs in a port.
26 #include <linux/init.h>
27 #include <linux/module.h>
28 #include <linux/err.h>
29 #include <linux/slab.h>
30 #include <linux/string.h>
32 #include <scsi/scsi.h>
33 #include <scsi/scsi_device.h>
34 #include <scsi/scsi_host.h>
35 #include <scsi/scsi_transport.h>
36 #include <scsi/scsi_transport_sas.h>
39 #define SAS_HOST_ATTRS 0
40 #define SAS_PORT_ATTRS 17
41 #define SAS_RPORT_ATTRS 7
44 struct scsi_transport_template t;
45 struct sas_function_template *f;
47 struct class_device_attribute private_host_attrs[SAS_HOST_ATTRS];
48 struct class_device_attribute private_phy_attrs[SAS_PORT_ATTRS];
49 struct class_device_attribute private_rphy_attrs[SAS_RPORT_ATTRS];
51 struct transport_container phy_attr_cont;
52 struct transport_container rphy_attr_cont;
55 * The array of null terminated pointers to attributes
56 * needed by scsi_sysfs.c
58 struct class_device_attribute *host_attrs[SAS_HOST_ATTRS + 1];
59 struct class_device_attribute *phy_attrs[SAS_PORT_ATTRS + 1];
60 struct class_device_attribute *rphy_attrs[SAS_RPORT_ATTRS + 1];
62 #define to_sas_internal(tmpl) container_of(tmpl, struct sas_internal, t)
64 struct sas_host_attrs {
65 struct list_head rphy_list;
69 #define to_sas_host_attrs(host) ((struct sas_host_attrs *)(host)->shost_data)
73 * Hack to allow attributes of the same name in different objects.
75 #define SAS_CLASS_DEVICE_ATTR(_prefix,_name,_mode,_show,_store) \
76 struct class_device_attribute class_device_attr_##_prefix##_##_name = \
77 __ATTR(_name,_mode,_show,_store)
81 * Pretty printing helpers
84 #define sas_bitfield_name_match(title, table) \
86 get_sas_##title##_names(u32 table_key, char *buf) \
92 for (i = 0; i < sizeof(table)/sizeof(table[0]); i++) { \
93 if (table[i].value & table_key) { \
94 len += sprintf(buf + len, "%s%s", \
95 prefix, table[i].name); \
99 len += sprintf(buf + len, "\n"); \
103 #define sas_bitfield_name_search(title, table) \
105 get_sas_##title##_names(u32 table_key, char *buf) \
110 for (i = 0; i < sizeof(table)/sizeof(table[0]); i++) { \
111 if (table[i].value == table_key) { \
112 len += sprintf(buf + len, "%s", \
117 len += sprintf(buf + len, "\n"); \
124 } sas_device_type_names[] = {
125 { SAS_PHY_UNUSED, "unused" },
126 { SAS_END_DEVICE, "end device" },
127 { SAS_EDGE_EXPANDER_DEVICE, "edge expander" },
128 { SAS_FANOUT_EXPANDER_DEVICE, "fanout expander" },
130 sas_bitfield_name_search(device_type, sas_device_type_names)
136 } sas_protocol_names[] = {
137 { SAS_PROTOCOL_SATA, "sata" },
138 { SAS_PROTOCOL_SMP, "smp" },
139 { SAS_PROTOCOL_STP, "stp" },
140 { SAS_PROTOCOL_SSP, "ssp" },
142 sas_bitfield_name_match(protocol, sas_protocol_names)
147 } sas_linkspeed_names[] = {
148 { SAS_LINK_RATE_UNKNOWN, "Unknown" },
149 { SAS_PHY_DISABLED, "Phy disabled" },
150 { SAS_LINK_RATE_FAILED, "Link Rate failed" },
151 { SAS_SATA_SPINUP_HOLD, "Spin-up hold" },
152 { SAS_LINK_RATE_1_5_GBPS, "1.5 Gbit" },
153 { SAS_LINK_RATE_3_0_GBPS, "3.0 Gbit" },
154 { SAS_LINK_RATE_6_0_GBPS, "6.0 Gbit" },
156 sas_bitfield_name_search(linkspeed, sas_linkspeed_names)
160 * SAS host attributes
163 static int sas_host_setup(struct transport_container *tc, struct device *dev,
164 struct class_device *cdev)
166 struct Scsi_Host *shost = dev_to_shost(dev);
167 struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
169 INIT_LIST_HEAD(&sas_host->rphy_list);
170 mutex_init(&sas_host->lock);
171 sas_host->next_target_id = 0;
175 static DECLARE_TRANSPORT_CLASS(sas_host_class,
176 "sas_host", sas_host_setup, NULL, NULL);
178 static int sas_host_match(struct attribute_container *cont,
181 struct Scsi_Host *shost;
182 struct sas_internal *i;
184 if (!scsi_is_host_device(dev))
186 shost = dev_to_shost(dev);
188 if (!shost->transportt)
190 if (shost->transportt->host_attrs.ac.class !=
191 &sas_host_class.class)
194 i = to_sas_internal(shost->transportt);
195 return &i->t.host_attrs.ac == cont;
198 static int do_sas_phy_delete(struct device *dev, void *data)
200 if (scsi_is_sas_phy(dev))
201 sas_phy_delete(dev_to_phy(dev));
206 * sas_remove_host -- tear down a Scsi_Host's SAS data structures
207 * @shost: Scsi Host that is torn down
209 * Removes all SAS PHYs and remote PHYs for a given Scsi_Host.
210 * Must be called just before scsi_remove_host for SAS HBAs.
212 void sas_remove_host(struct Scsi_Host *shost)
214 device_for_each_child(&shost->shost_gendev, NULL, do_sas_phy_delete);
216 EXPORT_SYMBOL(sas_remove_host);
220 * SAS Port attributes
223 #define sas_phy_show_simple(field, name, format_string, cast) \
225 show_sas_phy_##name(struct class_device *cdev, char *buf) \
227 struct sas_phy *phy = transport_class_to_phy(cdev); \
229 return snprintf(buf, 20, format_string, cast phy->field); \
232 #define sas_phy_simple_attr(field, name, format_string, type) \
233 sas_phy_show_simple(field, name, format_string, (type)) \
234 static CLASS_DEVICE_ATTR(name, S_IRUGO, show_sas_phy_##name, NULL)
236 #define sas_phy_show_protocol(field, name) \
238 show_sas_phy_##name(struct class_device *cdev, char *buf) \
240 struct sas_phy *phy = transport_class_to_phy(cdev); \
243 return snprintf(buf, 20, "none\n"); \
244 return get_sas_protocol_names(phy->field, buf); \
247 #define sas_phy_protocol_attr(field, name) \
248 sas_phy_show_protocol(field, name) \
249 static CLASS_DEVICE_ATTR(name, S_IRUGO, show_sas_phy_##name, NULL)
251 #define sas_phy_show_linkspeed(field) \
253 show_sas_phy_##field(struct class_device *cdev, char *buf) \
255 struct sas_phy *phy = transport_class_to_phy(cdev); \
257 return get_sas_linkspeed_names(phy->field, buf); \
260 #define sas_phy_linkspeed_attr(field) \
261 sas_phy_show_linkspeed(field) \
262 static CLASS_DEVICE_ATTR(field, S_IRUGO, show_sas_phy_##field, NULL)
264 #define sas_phy_show_linkerror(field) \
266 show_sas_phy_##field(struct class_device *cdev, char *buf) \
268 struct sas_phy *phy = transport_class_to_phy(cdev); \
269 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); \
270 struct sas_internal *i = to_sas_internal(shost->transportt); \
273 if (!phy->local_attached) \
276 error = i->f->get_linkerrors(phy); \
279 return snprintf(buf, 20, "%u\n", phy->field); \
282 #define sas_phy_linkerror_attr(field) \
283 sas_phy_show_linkerror(field) \
284 static CLASS_DEVICE_ATTR(field, S_IRUGO, show_sas_phy_##field, NULL)
288 show_sas_device_type(struct class_device *cdev, char *buf)
290 struct sas_phy *phy = transport_class_to_phy(cdev);
292 if (!phy->identify.device_type)
293 return snprintf(buf, 20, "none\n");
294 return get_sas_device_type_names(phy->identify.device_type, buf);
296 static CLASS_DEVICE_ATTR(device_type, S_IRUGO, show_sas_device_type, NULL);
298 static ssize_t do_sas_phy_reset(struct class_device *cdev,
299 size_t count, int hard_reset)
301 struct sas_phy *phy = transport_class_to_phy(cdev);
302 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
303 struct sas_internal *i = to_sas_internal(shost->transportt);
306 if (!phy->local_attached)
309 error = i->f->phy_reset(phy, hard_reset);
315 static ssize_t store_sas_link_reset(struct class_device *cdev,
316 const char *buf, size_t count)
318 return do_sas_phy_reset(cdev, count, 0);
320 static CLASS_DEVICE_ATTR(link_reset, S_IWUSR, NULL, store_sas_link_reset);
322 static ssize_t store_sas_hard_reset(struct class_device *cdev,
323 const char *buf, size_t count)
325 return do_sas_phy_reset(cdev, count, 1);
327 static CLASS_DEVICE_ATTR(hard_reset, S_IWUSR, NULL, store_sas_hard_reset);
329 sas_phy_protocol_attr(identify.initiator_port_protocols,
330 initiator_port_protocols);
331 sas_phy_protocol_attr(identify.target_port_protocols,
332 target_port_protocols);
333 sas_phy_simple_attr(identify.sas_address, sas_address, "0x%016llx\n",
335 sas_phy_simple_attr(identify.phy_identifier, phy_identifier, "%d\n", u8);
336 sas_phy_simple_attr(port_identifier, port_identifier, "%d\n", u8);
337 sas_phy_linkspeed_attr(negotiated_linkrate);
338 sas_phy_linkspeed_attr(minimum_linkrate_hw);
339 sas_phy_linkspeed_attr(minimum_linkrate);
340 sas_phy_linkspeed_attr(maximum_linkrate_hw);
341 sas_phy_linkspeed_attr(maximum_linkrate);
342 sas_phy_linkerror_attr(invalid_dword_count);
343 sas_phy_linkerror_attr(running_disparity_error_count);
344 sas_phy_linkerror_attr(loss_of_dword_sync_count);
345 sas_phy_linkerror_attr(phy_reset_problem_count);
348 static DECLARE_TRANSPORT_CLASS(sas_phy_class,
349 "sas_phy", NULL, NULL, NULL);
351 static int sas_phy_match(struct attribute_container *cont, struct device *dev)
353 struct Scsi_Host *shost;
354 struct sas_internal *i;
356 if (!scsi_is_sas_phy(dev))
358 shost = dev_to_shost(dev->parent);
360 if (!shost->transportt)
362 if (shost->transportt->host_attrs.ac.class !=
363 &sas_host_class.class)
366 i = to_sas_internal(shost->transportt);
367 return &i->phy_attr_cont.ac == cont;
370 static void sas_phy_release(struct device *dev)
372 struct sas_phy *phy = dev_to_phy(dev);
374 put_device(dev->parent);
379 * sas_phy_alloc -- allocates and initialize a SAS PHY structure
380 * @parent: Parent device
383 * Allocates an SAS PHY structure. It will be added in the device tree
384 * below the device specified by @parent, which has to be either a Scsi_Host
388 * SAS PHY allocated or %NULL if the allocation failed.
390 struct sas_phy *sas_phy_alloc(struct device *parent, int number)
392 struct Scsi_Host *shost = dev_to_shost(parent);
395 phy = kzalloc(sizeof(*phy), GFP_KERNEL);
401 phy->number = number;
403 device_initialize(&phy->dev);
404 phy->dev.parent = get_device(parent);
405 phy->dev.release = sas_phy_release;
406 sprintf(phy->dev.bus_id, "phy-%d:%d", shost->host_no, number);
408 transport_setup_device(&phy->dev);
412 EXPORT_SYMBOL(sas_phy_alloc);
415 * sas_phy_add -- add a SAS PHY to the device hierachy
416 * @phy: The PHY to be added
418 * Publishes a SAS PHY to the rest of the system.
420 int sas_phy_add(struct sas_phy *phy)
424 error = device_add(&phy->dev);
426 transport_add_device(&phy->dev);
427 transport_configure_device(&phy->dev);
432 EXPORT_SYMBOL(sas_phy_add);
435 * sas_phy_free -- free a SAS PHY
436 * @phy: SAS PHY to free
438 * Frees the specified SAS PHY.
441 * This function must only be called on a PHY that has not
442 * sucessfully been added using sas_phy_add().
444 void sas_phy_free(struct sas_phy *phy)
446 transport_destroy_device(&phy->dev);
447 put_device(phy->dev.parent);
448 put_device(phy->dev.parent);
449 put_device(phy->dev.parent);
452 EXPORT_SYMBOL(sas_phy_free);
455 * sas_phy_delete -- remove SAS PHY
456 * @phy: SAS PHY to remove
458 * Removes the specified SAS PHY. If the SAS PHY has an
459 * associated remote PHY it is removed before.
462 sas_phy_delete(struct sas_phy *phy)
464 struct device *dev = &phy->dev;
467 sas_rphy_delete(phy->rphy);
469 transport_remove_device(dev);
471 transport_destroy_device(dev);
472 put_device(dev->parent);
474 EXPORT_SYMBOL(sas_phy_delete);
477 * scsi_is_sas_phy -- check if a struct device represents a SAS PHY
478 * @dev: device to check
481 * %1 if the device represents a SAS PHY, %0 else
483 int scsi_is_sas_phy(const struct device *dev)
485 return dev->release == sas_phy_release;
487 EXPORT_SYMBOL(scsi_is_sas_phy);
490 * SAS remote PHY attributes.
493 #define sas_rphy_show_simple(field, name, format_string, cast) \
495 show_sas_rphy_##name(struct class_device *cdev, char *buf) \
497 struct sas_rphy *rphy = transport_class_to_rphy(cdev); \
499 return snprintf(buf, 20, format_string, cast rphy->field); \
502 #define sas_rphy_simple_attr(field, name, format_string, type) \
503 sas_rphy_show_simple(field, name, format_string, (type)) \
504 static SAS_CLASS_DEVICE_ATTR(rphy, name, S_IRUGO, \
505 show_sas_rphy_##name, NULL)
507 #define sas_rphy_show_protocol(field, name) \
509 show_sas_rphy_##name(struct class_device *cdev, char *buf) \
511 struct sas_rphy *rphy = transport_class_to_rphy(cdev); \
514 return snprintf(buf, 20, "none\n"); \
515 return get_sas_protocol_names(rphy->field, buf); \
518 #define sas_rphy_protocol_attr(field, name) \
519 sas_rphy_show_protocol(field, name) \
520 static SAS_CLASS_DEVICE_ATTR(rphy, name, S_IRUGO, \
521 show_sas_rphy_##name, NULL)
524 show_sas_rphy_device_type(struct class_device *cdev, char *buf)
526 struct sas_rphy *rphy = transport_class_to_rphy(cdev);
528 if (!rphy->identify.device_type)
529 return snprintf(buf, 20, "none\n");
530 return get_sas_device_type_names(
531 rphy->identify.device_type, buf);
534 static SAS_CLASS_DEVICE_ATTR(rphy, device_type, S_IRUGO,
535 show_sas_rphy_device_type, NULL);
538 show_sas_rphy_enclosure_identifier(struct class_device *cdev, char *buf)
540 struct sas_rphy *rphy = transport_class_to_rphy(cdev);
541 struct sas_phy *phy = dev_to_phy(rphy->dev.parent);
542 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
543 struct sas_internal *i = to_sas_internal(shost->transportt);
548 * Only devices behind an expander are supported, because the
549 * enclosure identifier is a SMP feature.
551 if (phy->local_attached)
554 error = i->f->get_enclosure_identifier(rphy, &identifier);
557 return sprintf(buf, "0x%llx\n", (unsigned long long)identifier);
560 static SAS_CLASS_DEVICE_ATTR(rphy, enclosure_identifier, S_IRUGO,
561 show_sas_rphy_enclosure_identifier, NULL);
564 show_sas_rphy_bay_identifier(struct class_device *cdev, char *buf)
566 struct sas_rphy *rphy = transport_class_to_rphy(cdev);
567 struct sas_phy *phy = dev_to_phy(rphy->dev.parent);
568 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
569 struct sas_internal *i = to_sas_internal(shost->transportt);
572 if (phy->local_attached)
575 val = i->f->get_bay_identifier(rphy);
578 return sprintf(buf, "%d\n", val);
581 static SAS_CLASS_DEVICE_ATTR(rphy, bay_identifier, S_IRUGO,
582 show_sas_rphy_bay_identifier, NULL);
584 sas_rphy_protocol_attr(identify.initiator_port_protocols,
585 initiator_port_protocols);
586 sas_rphy_protocol_attr(identify.target_port_protocols, target_port_protocols);
587 sas_rphy_simple_attr(identify.sas_address, sas_address, "0x%016llx\n",
589 sas_rphy_simple_attr(identify.phy_identifier, phy_identifier, "%d\n", u8);
591 static DECLARE_TRANSPORT_CLASS(sas_rphy_class,
592 "sas_rphy", NULL, NULL, NULL);
594 static int sas_rphy_match(struct attribute_container *cont, struct device *dev)
596 struct Scsi_Host *shost;
597 struct sas_internal *i;
599 if (!scsi_is_sas_rphy(dev))
601 shost = dev_to_shost(dev->parent->parent);
603 if (!shost->transportt)
605 if (shost->transportt->host_attrs.ac.class !=
606 &sas_host_class.class)
609 i = to_sas_internal(shost->transportt);
610 return &i->rphy_attr_cont.ac == cont;
613 static void sas_rphy_release(struct device *dev)
615 struct sas_rphy *rphy = dev_to_rphy(dev);
617 put_device(dev->parent);
622 * sas_rphy_alloc -- allocates and initialize a SAS remote PHY structure
623 * @parent: SAS PHY this remote PHY is conneted to
625 * Allocates an SAS remote PHY structure, connected to @parent.
628 * SAS PHY allocated or %NULL if the allocation failed.
630 struct sas_rphy *sas_rphy_alloc(struct sas_phy *parent)
632 struct Scsi_Host *shost = dev_to_shost(&parent->dev);
633 struct sas_rphy *rphy;
635 rphy = kzalloc(sizeof(*rphy), GFP_KERNEL);
637 put_device(&parent->dev);
641 device_initialize(&rphy->dev);
642 rphy->dev.parent = get_device(&parent->dev);
643 rphy->dev.release = sas_rphy_release;
644 sprintf(rphy->dev.bus_id, "rphy-%d:%d-%d",
645 shost->host_no, parent->port_identifier, parent->number);
646 transport_setup_device(&rphy->dev);
650 EXPORT_SYMBOL(sas_rphy_alloc);
653 * sas_rphy_add -- add a SAS remote PHY to the device hierachy
654 * @rphy: The remote PHY to be added
656 * Publishes a SAS remote PHY to the rest of the system.
658 int sas_rphy_add(struct sas_rphy *rphy)
660 struct sas_phy *parent = dev_to_phy(rphy->dev.parent);
661 struct Scsi_Host *shost = dev_to_shost(parent->dev.parent);
662 struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
663 struct sas_identify *identify = &rphy->identify;
670 error = device_add(&rphy->dev);
673 transport_add_device(&rphy->dev);
674 transport_configure_device(&rphy->dev);
676 mutex_lock(&sas_host->lock);
677 list_add_tail(&rphy->list, &sas_host->rphy_list);
678 if (identify->device_type == SAS_END_DEVICE &&
679 (identify->target_port_protocols &
680 (SAS_PROTOCOL_SSP|SAS_PROTOCOL_STP|SAS_PROTOCOL_SATA)))
681 rphy->scsi_target_id = sas_host->next_target_id++;
683 rphy->scsi_target_id = -1;
684 mutex_unlock(&sas_host->lock);
686 if (rphy->scsi_target_id != -1) {
687 scsi_scan_target(&rphy->dev, parent->port_identifier,
688 rphy->scsi_target_id, ~0, 0);
693 EXPORT_SYMBOL(sas_rphy_add);
696 * sas_rphy_free -- free a SAS remote PHY
697 * @rphy SAS remote PHY to free
699 * Frees the specified SAS remote PHY.
702 * This function must only be called on a remote
703 * PHY that has not sucessfully been added using
706 void sas_rphy_free(struct sas_rphy *rphy)
708 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
709 struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
711 mutex_lock(&sas_host->lock);
712 list_del(&rphy->list);
713 mutex_unlock(&sas_host->lock);
715 transport_destroy_device(&rphy->dev);
716 put_device(rphy->dev.parent);
717 put_device(rphy->dev.parent);
718 put_device(rphy->dev.parent);
721 EXPORT_SYMBOL(sas_rphy_free);
724 * sas_rphy_delete -- remove SAS remote PHY
725 * @rphy: SAS remote PHY to remove
727 * Removes the specified SAS remote PHY.
730 sas_rphy_delete(struct sas_rphy *rphy)
732 struct device *dev = &rphy->dev;
733 struct sas_phy *parent = dev_to_phy(dev->parent);
734 struct Scsi_Host *shost = dev_to_shost(parent->dev.parent);
735 struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
737 switch (rphy->identify.device_type) {
739 scsi_remove_target(dev);
741 case SAS_EDGE_EXPANDER_DEVICE:
742 case SAS_FANOUT_EXPANDER_DEVICE:
743 device_for_each_child(dev, NULL, do_sas_phy_delete);
749 transport_remove_device(dev);
751 transport_destroy_device(dev);
753 mutex_lock(&sas_host->lock);
754 list_del(&rphy->list);
755 mutex_unlock(&sas_host->lock);
759 put_device(&parent->dev);
761 EXPORT_SYMBOL(sas_rphy_delete);
764 * scsi_is_sas_rphy -- check if a struct device represents a SAS remote PHY
765 * @dev: device to check
768 * %1 if the device represents a SAS remote PHY, %0 else
770 int scsi_is_sas_rphy(const struct device *dev)
772 return dev->release == sas_rphy_release;
774 EXPORT_SYMBOL(scsi_is_sas_rphy);
781 static int sas_user_scan(struct Scsi_Host *shost, uint channel,
784 struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
785 struct sas_rphy *rphy;
787 mutex_lock(&sas_host->lock);
788 list_for_each_entry(rphy, &sas_host->rphy_list, list) {
789 struct sas_phy *parent = dev_to_phy(rphy->dev.parent);
791 if (rphy->scsi_target_id == -1)
794 if ((channel == SCAN_WILD_CARD || channel == parent->port_identifier) &&
795 (id == SCAN_WILD_CARD || id == rphy->scsi_target_id)) {
796 scsi_scan_target(&rphy->dev, parent->port_identifier,
797 rphy->scsi_target_id, lun, 1);
800 mutex_unlock(&sas_host->lock);
807 * Setup / Teardown code
810 #define SETUP_RPORT_ATTRIBUTE(field) \
811 i->private_rphy_attrs[count] = class_device_attr_##field; \
812 i->private_rphy_attrs[count].attr.mode = S_IRUGO; \
813 i->private_rphy_attrs[count].store = NULL; \
814 i->rphy_attrs[count] = &i->private_rphy_attrs[count]; \
817 #define SETUP_PORT_ATTRIBUTE(field) \
818 i->private_phy_attrs[count] = class_device_attr_##field; \
819 i->private_phy_attrs[count].attr.mode = S_IRUGO; \
820 i->private_phy_attrs[count].store = NULL; \
821 i->phy_attrs[count] = &i->private_phy_attrs[count]; \
824 #define SETUP_PORT_ATTRIBUTE_WRONLY(field) \
825 i->private_phy_attrs[count] = class_device_attr_##field; \
826 i->private_phy_attrs[count].attr.mode = S_IWUGO; \
827 i->private_phy_attrs[count].show = NULL; \
828 i->phy_attrs[count] = &i->private_phy_attrs[count]; \
833 * sas_attach_transport -- instantiate SAS transport template
834 * @ft: SAS transport class function template
836 struct scsi_transport_template *
837 sas_attach_transport(struct sas_function_template *ft)
839 struct sas_internal *i;
842 i = kzalloc(sizeof(struct sas_internal), GFP_KERNEL);
846 i->t.user_scan = sas_user_scan;
848 i->t.host_attrs.ac.attrs = &i->host_attrs[0];
849 i->t.host_attrs.ac.class = &sas_host_class.class;
850 i->t.host_attrs.ac.match = sas_host_match;
851 transport_container_register(&i->t.host_attrs);
852 i->t.host_size = sizeof(struct sas_host_attrs);
854 i->phy_attr_cont.ac.class = &sas_phy_class.class;
855 i->phy_attr_cont.ac.attrs = &i->phy_attrs[0];
856 i->phy_attr_cont.ac.match = sas_phy_match;
857 transport_container_register(&i->phy_attr_cont);
859 i->rphy_attr_cont.ac.class = &sas_rphy_class.class;
860 i->rphy_attr_cont.ac.attrs = &i->rphy_attrs[0];
861 i->rphy_attr_cont.ac.match = sas_rphy_match;
862 transport_container_register(&i->rphy_attr_cont);
867 i->host_attrs[count] = NULL;
870 SETUP_PORT_ATTRIBUTE(initiator_port_protocols);
871 SETUP_PORT_ATTRIBUTE(target_port_protocols);
872 SETUP_PORT_ATTRIBUTE(device_type);
873 SETUP_PORT_ATTRIBUTE(sas_address);
874 SETUP_PORT_ATTRIBUTE(phy_identifier);
875 SETUP_PORT_ATTRIBUTE(port_identifier);
876 SETUP_PORT_ATTRIBUTE(negotiated_linkrate);
877 SETUP_PORT_ATTRIBUTE(minimum_linkrate_hw);
878 SETUP_PORT_ATTRIBUTE(minimum_linkrate);
879 SETUP_PORT_ATTRIBUTE(maximum_linkrate_hw);
880 SETUP_PORT_ATTRIBUTE(maximum_linkrate);
882 SETUP_PORT_ATTRIBUTE(invalid_dword_count);
883 SETUP_PORT_ATTRIBUTE(running_disparity_error_count);
884 SETUP_PORT_ATTRIBUTE(loss_of_dword_sync_count);
885 SETUP_PORT_ATTRIBUTE(phy_reset_problem_count);
886 SETUP_PORT_ATTRIBUTE_WRONLY(link_reset);
887 SETUP_PORT_ATTRIBUTE_WRONLY(hard_reset);
888 i->phy_attrs[count] = NULL;
891 SETUP_RPORT_ATTRIBUTE(rphy_initiator_port_protocols);
892 SETUP_RPORT_ATTRIBUTE(rphy_target_port_protocols);
893 SETUP_RPORT_ATTRIBUTE(rphy_device_type);
894 SETUP_RPORT_ATTRIBUTE(rphy_sas_address);
895 SETUP_RPORT_ATTRIBUTE(rphy_phy_identifier);
896 SETUP_RPORT_ATTRIBUTE(rphy_enclosure_identifier);
897 SETUP_RPORT_ATTRIBUTE(rphy_bay_identifier);
898 i->rphy_attrs[count] = NULL;
902 EXPORT_SYMBOL(sas_attach_transport);
905 * sas_release_transport -- release SAS transport template instance
906 * @t: transport template instance
908 void sas_release_transport(struct scsi_transport_template *t)
910 struct sas_internal *i = to_sas_internal(t);
912 transport_container_unregister(&i->t.host_attrs);
913 transport_container_unregister(&i->phy_attr_cont);
914 transport_container_unregister(&i->rphy_attr_cont);
918 EXPORT_SYMBOL(sas_release_transport);
920 static __init int sas_transport_init(void)
924 error = transport_class_register(&sas_host_class);
927 error = transport_class_register(&sas_phy_class);
929 goto out_unregister_transport;
930 error = transport_class_register(&sas_rphy_class);
932 goto out_unregister_phy;
937 transport_class_unregister(&sas_phy_class);
938 out_unregister_transport:
939 transport_class_unregister(&sas_host_class);
945 static void __exit sas_transport_exit(void)
947 transport_class_unregister(&sas_host_class);
948 transport_class_unregister(&sas_phy_class);
949 transport_class_unregister(&sas_rphy_class);
952 MODULE_AUTHOR("Christoph Hellwig");
953 MODULE_DESCRIPTION("SAS Transphy Attributes");
954 MODULE_LICENSE("GPL");
956 module_init(sas_transport_init);
957 module_exit(sas_transport_exit);