Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * transport_class.c - implementation of generic transport classes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *                     using attribute_containers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (c) 2005 - James Bottomley <James.Bottomley@steeleye.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * The basic idea here is to allow any "device controller" (which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * would most often be a Host Bus Adapter to use the services of one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * or more tranport classes for performing transport specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * services.  Transport specific services are things that the generic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * command layer doesn't want to know about (speed settings, line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * condidtioning, etc), but which the user might be interested in.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * Thus, the HBA's use the routines exported by the transport classes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * to perform these functions.  The transport classes export certain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * values to the user via sysfs using attribute containers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * Note: because not every HBA will care about every transport
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * attribute, there's a many to one relationship that goes like this:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * transport class<-----attribute container<----class device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * Usually the attribute container is per-HBA, but the design doesn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * mandate that.  Although most of the services will be specific to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * the actual external storage connection used by the HBA, the generic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * transport class is framed entirely in terms of generic devices to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * allow it to be used by any physical HBA in the system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/attribute_container.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/transport_class.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static int transport_remove_classdev(struct attribute_container *cont,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 				     struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 				     struct device *classdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * transport_class_register - register an initial transport class
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * @tclass:	a pointer to the transport class structure to be initialised
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * The transport class contains an embedded class which is used to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * identify it.  The caller should initialise this structure with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * zeros and then generic class must have been initialised with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * actual transport class unique name.  There's a macro
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * DECLARE_TRANSPORT_CLASS() to do this (declared classes still must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * be registered).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * Returns 0 on success or error on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) int transport_class_register(struct transport_class *tclass)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	return class_register(&tclass->class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) EXPORT_SYMBOL_GPL(transport_class_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * transport_class_unregister - unregister a previously registered class
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * @tclass: The transport class to unregister
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * Must be called prior to deallocating the memory for the transport
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * class.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) void transport_class_unregister(struct transport_class *tclass)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	class_unregister(&tclass->class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) EXPORT_SYMBOL_GPL(transport_class_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static int anon_transport_dummy_function(struct transport_container *tc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 					 struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 					 struct device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	/* do nothing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * anon_transport_class_register - register an anonymous class
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  * @atc: The anon transport class to register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  * The anonymous transport class contains both a transport class and a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  * container.  The idea of an anonymous class is that it never
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  * actually has any device attributes associated with it (and thus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  * saves on container storage).  So it can only be used for triggering
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  * events.  Use prezero and then use DECLARE_ANON_TRANSPORT_CLASS() to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  * initialise the anon transport class storage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) int anon_transport_class_register(struct anon_transport_class *atc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	atc->container.class = &atc->tclass.class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	attribute_container_set_no_classdevs(&atc->container);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	error = attribute_container_register(&atc->container);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	atc->tclass.setup = anon_transport_dummy_function;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	atc->tclass.remove = anon_transport_dummy_function;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) EXPORT_SYMBOL_GPL(anon_transport_class_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  * anon_transport_class_unregister - unregister an anon class
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  * @atc: Pointer to the anon transport class to unregister
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  * Must be called prior to deallocating the memory for the anon
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  * transport class.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) void anon_transport_class_unregister(struct anon_transport_class *atc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (unlikely(attribute_container_unregister(&atc->container)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) EXPORT_SYMBOL_GPL(anon_transport_class_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static int transport_setup_classdev(struct attribute_container *cont,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 				    struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 				    struct device *classdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	struct transport_class *tclass = class_to_transport_class(cont->class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	struct transport_container *tcont = attribute_container_to_transport_container(cont);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if (tclass->setup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		tclass->setup(tcont, dev, classdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  * transport_setup_device - declare a new dev for transport class association but don't make it visible yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  * @dev: the generic device representing the entity being added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  * Usually, dev represents some component in the HBA system (either
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  * the HBA itself or a device remote across the HBA bus).  This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  * routine is simply a trigger point to see if any set of transport
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)  * classes wishes to associate with the added device.  This allocates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)  * storage for the class device and initialises it, but does not yet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  * add it to the system or add attributes to it (you do this with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  * transport_add_device).  If you have no need for a separate setup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  * and add operations, use transport_register_device (see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  * transport_class.h).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) void transport_setup_device(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	attribute_container_add_device(dev, transport_setup_classdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) EXPORT_SYMBOL_GPL(transport_setup_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static int transport_add_class_device(struct attribute_container *cont,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 				      struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 				      struct device *classdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	int error = attribute_container_add_class_device(classdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	struct transport_container *tcont = 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		attribute_container_to_transport_container(cont);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	if (!error && tcont->statistics)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		error = sysfs_create_group(&classdev->kobj, tcont->statistics);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)  * transport_add_device - declare a new dev for transport class association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)  * @dev: the generic device representing the entity being added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)  * Usually, dev represents some component in the HBA system (either
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)  * the HBA itself or a device remote across the HBA bus).  This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)  * routine is simply a trigger point used to add the device to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  * system and register attributes for it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) int transport_add_device(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	return attribute_container_device_trigger_safe(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 					transport_add_class_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 					transport_remove_classdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) EXPORT_SYMBOL_GPL(transport_add_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static int transport_configure(struct attribute_container *cont,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			       struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			       struct device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	struct transport_class *tclass = class_to_transport_class(cont->class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	struct transport_container *tcont = attribute_container_to_transport_container(cont);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (tclass->configure)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		tclass->configure(tcont, dev, cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)  * transport_configure_device - configure an already set up device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)  * @dev: generic device representing device to be configured
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)  * The idea of configure is simply to provide a point within the setup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)  * process to allow the transport class to extract information from a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)  * device after it has been setup.  This is used in SCSI because we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)  * have to have a setup device to begin using the HBA, but after we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)  * send the initial inquiry, we use configure to extract the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)  * parameters.  The device need not have been added to be configured.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) void transport_configure_device(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	attribute_container_device_trigger(dev, transport_configure);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) EXPORT_SYMBOL_GPL(transport_configure_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) static int transport_remove_classdev(struct attribute_container *cont,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 				     struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 				     struct device *classdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	struct transport_container *tcont = 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		attribute_container_to_transport_container(cont);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	struct transport_class *tclass = class_to_transport_class(cont->class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	if (tclass->remove)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		tclass->remove(tcont, dev, classdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	if (tclass->remove != anon_transport_dummy_function) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		if (tcont->statistics)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			sysfs_remove_group(&classdev->kobj, tcont->statistics);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		attribute_container_class_device_del(classdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)  * transport_remove_device - remove the visibility of a device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)  * @dev: generic device to remove
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)  * This call removes the visibility of the device (to the user from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)  * sysfs), but does not destroy it.  To eliminate a device entirely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)  * you must also call transport_destroy_device.  If you don't need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  * do remove and destroy as separate operations, use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  * transport_unregister_device() (see transport_class.h) which will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  * perform both calls for you.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) void transport_remove_device(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	attribute_container_device_trigger(dev, transport_remove_classdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) EXPORT_SYMBOL_GPL(transport_remove_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) static void transport_destroy_classdev(struct attribute_container *cont,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 				      struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 				      struct device *classdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	struct transport_class *tclass = class_to_transport_class(cont->class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	if (tclass->remove != anon_transport_dummy_function)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		put_device(classdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)  * transport_destroy_device - destroy a removed device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)  * @dev: device to eliminate from the transport class.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)  * This call triggers the elimination of storage associated with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)  * transport classdev.  Note: all it really does is relinquish a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)  * reference to the classdev.  The memory will not be freed until the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)  * last reference goes to zero.  Note also that the classdev retains a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)  * reference count on dev, so dev too will remain for as long as the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)  * transport class device remains around.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) void transport_destroy_device(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	attribute_container_remove_device(dev, transport_destroy_classdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) EXPORT_SYMBOL_GPL(transport_destroy_device);