@@ -80,12 +80,6 @@ struct ata_internal {
8080#define transport_class_to_port (dev ) \
8181 tdev_to_port((dev)->parent)
8282
83-
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 );
87-
88-
8983/*
9084 * Hack to allow attributes of the same name in different objects.
9185 */
@@ -364,135 +358,6 @@ unsigned int ata_port_classify(struct ata_port *ap,
364358}
365359EXPORT_SYMBOL_GPL (ata_port_classify );
366360
367- /*
368- * ATA link attributes
369- */
370- static int noop (int x ) { return x ; }
371-
372- #define ata_link_show_linkspeed (field , format ) \
373- static ssize_t \
374- show_ata_link_##field(struct device *dev, \
375- struct device_attribute *attr, char *buf) \
376- { \
377- struct ata_link *link = transport_class_to_link(dev); \
378- \
379- return sprintf(buf, "%s\n", sata_spd_string(format(link->field))); \
380- }
381-
382- #define ata_link_linkspeed_attr (field , format ) \
383- ata_link_show_linkspeed(field, format) \
384- static DEVICE_ATTR(field, S_IRUGO, show_ata_link_##field, NULL)
385-
386- ata_link_linkspeed_attr (hw_sata_spd_limit , fls );
387- ata_link_linkspeed_attr (sata_spd_limit , fls );
388- ata_link_linkspeed_attr (sata_spd , noop );
389-
390-
391- static DECLARE_TRANSPORT_CLASS (ata_link_class ,
392- "ata_link ", NULL, NULL, NULL) ;
393-
394- static void ata_tlink_release (struct device * dev )
395- {
396- }
397-
398- /**
399- * ata_is_link -- check if a struct device represents a ATA link
400- * @dev: device to check
401- *
402- * Returns:
403- * %1 if the device represents a ATA link, %0 else
404- */
405- static int ata_is_link (const struct device * dev )
406- {
407- return dev -> release == ata_tlink_release ;
408- }
409-
410- static int ata_tlink_match (struct attribute_container * cont ,
411- struct device * dev )
412- {
413- struct ata_internal * i = to_ata_internal (ata_scsi_transport_template );
414- if (!ata_is_link (dev ))
415- return 0 ;
416- return & i -> link_attr_cont .ac == cont ;
417- }
418-
419- /**
420- * ata_tlink_delete -- remove ATA LINK
421- * @link: ATA LINK to remove
422- *
423- * Removes the specified ATA LINK. remove associated ATA device(s) as well.
424- */
425- void ata_tlink_delete (struct ata_link * link )
426- {
427- struct device * dev = & link -> tdev ;
428- struct ata_device * ata_dev ;
429-
430- ata_for_each_dev (ata_dev , link , ALL ) {
431- ata_tdev_delete (ata_dev );
432- }
433-
434- transport_remove_device (dev );
435- device_del (dev );
436- transport_destroy_device (dev );
437- put_device (dev );
438- }
439-
440- /**
441- * ata_tlink_add -- initialize a transport ATA link structure
442- * @link: allocated ata_link structure.
443- *
444- * Initialize an ATA LINK structure for sysfs. It will be added in the
445- * device tree below the ATA PORT it belongs to.
446- *
447- * Returns %0 on success
448- */
449- int ata_tlink_add (struct ata_link * link )
450- {
451- struct device * dev = & link -> tdev ;
452- struct ata_port * ap = link -> ap ;
453- struct ata_device * ata_dev ;
454- int error ;
455-
456- device_initialize (dev );
457- dev -> parent = & ap -> tdev ;
458- dev -> release = ata_tlink_release ;
459- if (ata_is_host_link (link ))
460- dev_set_name (dev , "link%d" , ap -> print_id );
461- else
462- dev_set_name (dev , "link%d.%d" , ap -> print_id , link -> pmp );
463-
464- transport_setup_device (dev );
465-
466- error = device_add (dev );
467- if (error ) {
468- goto tlink_err ;
469- }
470-
471- error = transport_add_device (dev );
472- if (error )
473- goto tlink_transport_err ;
474- transport_configure_device (dev );
475-
476- ata_for_each_dev (ata_dev , link , ALL ) {
477- error = ata_tdev_add (ata_dev );
478- if (error ) {
479- goto tlink_dev_err ;
480- }
481- }
482- return 0 ;
483- tlink_dev_err :
484- while (-- ata_dev >= link -> device ) {
485- ata_tdev_delete (ata_dev );
486- }
487- transport_remove_device (dev );
488- tlink_transport_err :
489- device_del (dev );
490- tlink_err :
491- transport_destroy_device (dev );
492- put_device (dev );
493- return error ;
494- }
495-
496361/*
497362 * ATA device attributes
498363 */
@@ -643,31 +508,32 @@ static void ata_tdev_release(struct device *dev)
643508 * @dev: device to check
644509 *
645510 * Returns:
646- * %1 if the device represents a ATA device, %0 else
511+ * true if the device represents a ATA device, false otherwise
647512 */
648- static int ata_is_ata_dev (const struct device * dev )
513+ static bool ata_is_ata_dev (const struct device * dev )
649514{
650515 return dev -> release == ata_tdev_release ;
651516}
652517
653518static int ata_tdev_match (struct attribute_container * cont ,
654519 struct device * dev )
655520{
656- struct ata_internal * i = to_ata_internal (ata_scsi_transport_template );
521+ struct ata_internal * i = to_ata_internal (ata_scsi_transport_template );
522+
657523 if (!ata_is_ata_dev (dev ))
658524 return 0 ;
659525 return & i -> dev_attr_cont .ac == cont ;
660526}
661527
662528/**
663- * ata_tdev_free -- free a ATA LINK
664- * @dev: ATA PHY to free
529+ * ata_tdev_free -- free an ATA transport device
530+ * @dev: struct ata_device owning the transport device to free
665531 *
666- * Frees the specified ATA PHY .
532+ * Free the ATA transport device for the specified ATA device .
667533 *
668534 * Note:
669- * This function must only be called on a PHY that has not
670- * successfully been added using ata_tdev_add().
535+ * This function must only be called for a ATA transport device that has not
536+ * yet successfully been added using ata_tdev_add().
671537 */
672538static void ata_tdev_free (struct ata_device * dev )
673539{
@@ -676,10 +542,10 @@ static void ata_tdev_free(struct ata_device *dev)
676542}
677543
678544/**
679- * ata_tdev_delete -- remove ATA device
680- * @ata_dev: ATA device to remove
545+ * ata_tdev_delete -- remove an ATA transport device
546+ * @ata_dev: struct ata_device owning the transport device to delete
681547 *
682- * Removes the specified ATA device.
548+ * Removes the ATA transport device for the specified ATA device.
683549 */
684550static void ata_tdev_delete (struct ata_device * ata_dev )
685551{
@@ -690,15 +556,14 @@ static void ata_tdev_delete(struct ata_device *ata_dev)
690556 ata_tdev_free (ata_dev );
691557}
692558
693-
694559/**
695- * ata_tdev_add -- initialize a transport ATA device structure.
696- * @ata_dev: ata_dev structure.
560+ * ata_tdev_add -- initialize an ATA transport device
561+ * @ata_dev: struct ata_device owning the transport device to add
697562 *
698- * Initialize an ATA device structure for sysfs. It will be added in the
699- * device tree below the ATA LINK device it belongs to.
563+ * Initialize an ATA transport device for sysfs. It will be added in the
564+ * device tree below the ATA link device it belongs to.
700565 *
701- * Returns %0 on success
566+ * Returns %0 on success and a negative error code on error.
702567 */
703568static int ata_tdev_add (struct ata_device * ata_dev )
704569{
@@ -734,6 +599,136 @@ static int ata_tdev_add(struct ata_device *ata_dev)
734599 return 0 ;
735600}
736601
602+ /*
603+ * ATA link attributes
604+ */
605+ static int noop (int x )
606+ {
607+ return x ;
608+ }
609+
610+ #define ata_link_show_linkspeed (field , format ) \
611+ static ssize_t \
612+ show_ata_link_##field(struct device *dev, \
613+ struct device_attribute *attr, char *buf) \
614+ { \
615+ struct ata_link *link = transport_class_to_link(dev); \
616+ \
617+ return sprintf(buf, "%s\n", \
618+ sata_spd_string(format(link->field))); \
619+ }
620+
621+ #define ata_link_linkspeed_attr (field , format ) \
622+ ata_link_show_linkspeed(field, format) \
623+ static DEVICE_ATTR(field, 0444, show_ata_link_##field, NULL)
624+
625+ ata_link_linkspeed_attr (hw_sata_spd_limit , fls );
626+ ata_link_linkspeed_attr (sata_spd_limit , fls );
627+ ata_link_linkspeed_attr (sata_spd , noop );
628+
629+ static DECLARE_TRANSPORT_CLASS (ata_link_class ,
630+ "ata_link ", NULL, NULL, NULL) ;
631+
632+ static void ata_tlink_release (struct device * dev )
633+ {
634+ }
635+
636+ /**
637+ * ata_is_link -- check if a struct device represents a ATA link
638+ * @dev: device to check
639+ *
640+ * Returns:
641+ * true if the device represents a ATA link, false otherwise
642+ */
643+ static bool ata_is_link (const struct device * dev )
644+ {
645+ return dev -> release == ata_tlink_release ;
646+ }
647+
648+ static int ata_tlink_match (struct attribute_container * cont ,
649+ struct device * dev )
650+ {
651+ struct ata_internal * i = to_ata_internal (ata_scsi_transport_template );
652+
653+ if (!ata_is_link (dev ))
654+ return 0 ;
655+ return & i -> link_attr_cont .ac == cont ;
656+ }
657+
658+ /**
659+ * ata_tlink_delete -- remove an ATA link transport device
660+ * @link: struct ata_link owning the link transport device to remove
661+ *
662+ * Removes the link transport device of the specified ATA link. This also
663+ * removes the ATA device(s) associated with the link as well.
664+ */
665+ void ata_tlink_delete (struct ata_link * link )
666+ {
667+ struct device * dev = & link -> tdev ;
668+ struct ata_device * ata_dev ;
669+
670+ ata_for_each_dev (ata_dev , link , ALL ) {
671+ ata_tdev_delete (ata_dev );
672+ }
673+
674+ transport_remove_device (dev );
675+ device_del (dev );
676+ transport_destroy_device (dev );
677+ put_device (dev );
678+ }
679+
680+ /**
681+ * ata_tlink_add -- initialize an ATA link transport device
682+ * @ata_link: struct ata_link owning the link transport device to initialize
683+ *
684+ * Initialize an ATA link transport device for sysfs. It will be added in the
685+ * device tree below the ATA port it belongs to.
686+ *
687+ * Returns %0 on success and a negative error code on error.
688+ */
689+ int ata_tlink_add (struct ata_link * link )
690+ {
691+ struct device * dev = & link -> tdev ;
692+ struct ata_port * ap = link -> ap ;
693+ struct ata_device * ata_dev ;
694+ int error ;
695+
696+ device_initialize (dev );
697+ dev -> parent = & ap -> tdev ;
698+ dev -> release = ata_tlink_release ;
699+ if (ata_is_host_link (link ))
700+ dev_set_name (dev , "link%d" , ap -> print_id );
701+ else
702+ dev_set_name (dev , "link%d.%d" , ap -> print_id , link -> pmp );
703+
704+ transport_setup_device (dev );
705+
706+ error = device_add (dev );
707+ if (error )
708+ goto tlink_err ;
709+
710+ error = transport_add_device (dev );
711+ if (error )
712+ goto tlink_transport_err ;
713+ transport_configure_device (dev );
714+
715+ ata_for_each_dev (ata_dev , link , ALL ) {
716+ error = ata_tdev_add (ata_dev );
717+ if (error )
718+ goto tlink_dev_err ;
719+ }
720+ return 0 ;
721+ tlink_dev_err :
722+ while (-- ata_dev >= link -> device )
723+ ata_tdev_delete (ata_dev );
724+ transport_remove_device (dev );
725+ tlink_transport_err :
726+ device_del (dev );
727+ tlink_err :
728+ transport_destroy_device (dev );
729+ put_device (dev );
730+ return error ;
731+ }
737732
738733/*
739734 * Setup / Teardown code
0 commit comments