Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
transport_class.c
Go to the documentation of this file.
1 /*
2  * transport_class.c - implementation of generic transport classes
3  * using attribute_containers
4  *
5  * Copyright (c) 2005 - James Bottomley <[email protected]>
6  *
7  * This file is licensed under GPLv2
8  *
9  * The basic idea here is to allow any "device controller" (which
10  * would most often be a Host Bus Adapter to use the services of one
11  * or more tranport classes for performing transport specific
12  * services. Transport specific services are things that the generic
13  * command layer doesn't want to know about (speed settings, line
14  * condidtioning, etc), but which the user might be interested in.
15  * Thus, the HBA's use the routines exported by the transport classes
16  * to perform these functions. The transport classes export certain
17  * values to the user via sysfs using attribute containers.
18  *
19  * Note: because not every HBA will care about every transport
20  * attribute, there's a many to one relationship that goes like this:
21  *
22  * transport class<-----attribute container<----class device
23  *
24  * Usually the attribute container is per-HBA, but the design doesn't
25  * mandate that. Although most of the services will be specific to
26  * the actual external storage connection used by the HBA, the generic
27  * transport class is framed entirely in terms of generic devices to
28  * allow it to be used by any physical HBA in the system.
29  */
30 #include <linux/export.h>
32 #include <linux/transport_class.h>
33 
49 {
50  return class_register(&tclass->class);
51 }
53 
63 {
64  class_unregister(&tclass->class);
65 }
67 
68 static int anon_transport_dummy_function(struct transport_container *tc,
69  struct device *dev,
70  struct device *cdev)
71 {
72  /* do nothing */
73  return 0;
74 }
75 
89 {
90  int error;
91  atc->container.class = &atc->tclass.class;
92  attribute_container_set_no_classdevs(&atc->container);
94  if (error)
95  return error;
96  atc->tclass.setup = anon_transport_dummy_function;
97  atc->tclass.remove = anon_transport_dummy_function;
98  return 0;
99 }
101 
111 {
113  BUG();
114 }
116 
117 static int transport_setup_classdev(struct attribute_container *cont,
118  struct device *dev,
119  struct device *classdev)
120 {
121  struct transport_class *tclass = class_to_transport_class(cont->class);
123 
124  if (tclass->setup)
125  tclass->setup(tcont, dev, classdev);
126 
127  return 0;
128 }
129 
146 {
147  attribute_container_add_device(dev, transport_setup_classdev);
148 }
150 
151 static int transport_add_class_device(struct attribute_container *cont,
152  struct device *dev,
153  struct device *classdev)
154 {
156  struct transport_container *tcont =
158 
159  if (!error && tcont->statistics)
160  error = sysfs_create_group(&classdev->kobj, tcont->statistics);
161 
162  return error;
163 }
164 
165 
177 void transport_add_device(struct device *dev)
178 {
179  attribute_container_device_trigger(dev, transport_add_class_device);
180 }
182 
183 static int transport_configure(struct attribute_container *cont,
184  struct device *dev,
185  struct device *cdev)
186 {
187  struct transport_class *tclass = class_to_transport_class(cont->class);
189 
190  if (tclass->configure)
191  tclass->configure(tcont, dev, cdev);
192 
193  return 0;
194 }
195 
209 {
210  attribute_container_device_trigger(dev, transport_configure);
211 }
213 
214 static int transport_remove_classdev(struct attribute_container *cont,
215  struct device *dev,
216  struct device *classdev)
217 {
218  struct transport_container *tcont =
220  struct transport_class *tclass = class_to_transport_class(cont->class);
221 
222  if (tclass->remove)
223  tclass->remove(tcont, dev, classdev);
224 
225  if (tclass->remove != anon_transport_dummy_function) {
226  if (tcont->statistics)
227  sysfs_remove_group(&classdev->kobj, tcont->statistics);
229  }
230 
231  return 0;
232 }
233 
234 
248 {
249  attribute_container_device_trigger(dev, transport_remove_classdev);
250 }
252 
253 static void transport_destroy_classdev(struct attribute_container *cont,
254  struct device *dev,
255  struct device *classdev)
256 {
257  struct transport_class *tclass = class_to_transport_class(cont->class);
258 
259  if (tclass->remove != anon_transport_dummy_function)
260  put_device(classdev);
261 }
262 
263 
277 {
278  attribute_container_remove_device(dev, transport_destroy_classdev);
279 }