Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]
  1 /*
  2  * This file is part of the zfcp device driver for
  3  * FCP adapters for IBM System z9 and zSeries.
  4  *
  5  * (C) Copyright IBM Corp. 2002, 2006
  6  *
  7  * This program is free software; you can redistribute it and/or modify
  8  * it under the terms of the GNU General Public License as published by
  9  * the Free Software Foundation; either version 2, or (at your option)
 10  * any later version.
 11  *
 12  * This program is distributed in the hope that it will be useful,
 13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15  * GNU General Public License for more details.
 16  *
 17  * You should have received a copy of the GNU General Public License
 18  * along with this program; if not, write to the Free Software
 19  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 20  */
 21 
 22 #include "zfcp_ext.h"
 23 
 24 #define ZFCP_LOG_AREA                   ZFCP_LOG_AREA_CONFIG
 25 
 26 /**
 27  * ZFCP_DEFINE_ADAPTER_ATTR
 28  * @_name:   name of show attribute
 29  * @_format: format string
 30  * @_value:  value to print
 31  *
 32  * Generates attributes for an adapter.
 33  */
 34 #define ZFCP_DEFINE_ADAPTER_ATTR(_name, _format, _value)                      \
 35 static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, struct device_attribute *attr,          \
 36                                                  char *buf)                   \
 37 {                                                                             \
 38         struct zfcp_adapter *adapter;                                         \
 39                                                                               \
 40         adapter = dev_get_drvdata(dev);                                       \
 41         return sprintf(buf, _format, _value);                                 \
 42 }                                                                             \
 43                                                                               \
 44 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_adapter_##_name##_show, NULL);
 45 
 46 ZFCP_DEFINE_ADAPTER_ATTR(status, "0x%08x\n", atomic_read(&adapter->status));
 47 ZFCP_DEFINE_ADAPTER_ATTR(peer_wwnn, "0x%016llx\n", adapter->peer_wwnn);
 48 ZFCP_DEFINE_ADAPTER_ATTR(peer_wwpn, "0x%016llx\n", adapter->peer_wwpn);
 49 ZFCP_DEFINE_ADAPTER_ATTR(peer_d_id, "0x%06x\n", adapter->peer_d_id);
 50 ZFCP_DEFINE_ADAPTER_ATTR(card_version, "0x%04x\n", adapter->hydra_version);
 51 ZFCP_DEFINE_ADAPTER_ATTR(lic_version, "0x%08x\n", adapter->fsf_lic_version);
 52 ZFCP_DEFINE_ADAPTER_ATTR(hardware_version, "0x%08x\n",
 53                          adapter->hardware_version);
 54 ZFCP_DEFINE_ADAPTER_ATTR(in_recovery, "%d\n", atomic_test_mask
 55                          (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status));
 56 
 57 /**
 58  * zfcp_sysfs_port_add_store - add a port to sysfs tree
 59  * @dev: pointer to belonging device
 60  * @buf: pointer to input buffer
 61  * @count: number of bytes in buffer
 62  *
 63  * Store function of the "port_add" attribute of an adapter.
 64  */
 65 static ssize_t
 66 zfcp_sysfs_port_add_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 67 {
 68         wwn_t wwpn;
 69         char *endp;
 70         struct zfcp_adapter *adapter;
 71         struct zfcp_port *port;
 72         int retval = -EINVAL;
 73 
 74         down(&zfcp_data.config_sema);
 75 
 76         adapter = dev_get_drvdata(dev);
 77         if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
 78                 retval = -EBUSY;
 79                 goto out;
 80         }
 81 
 82         wwpn = simple_strtoull(buf, &endp, 0);
 83         if ((endp + 1) < (buf + count))
 84                 goto out;
 85 
 86         port = zfcp_port_enqueue(adapter, wwpn, 0, 0);
 87         if (!port)
 88                 goto out;
 89 
 90         retval = 0;
 91 
 92         zfcp_erp_port_reopen(port, 0);
 93         zfcp_erp_wait(port->adapter);
 94         zfcp_port_put(port);
 95  out:
 96         up(&zfcp_data.config_sema);
 97         return retval ? retval : (ssize_t) count;
 98 }
 99 
100 static DEVICE_ATTR(port_add, S_IWUSR, NULL, zfcp_sysfs_port_add_store);
101 
102 /**
103  * zfcp_sysfs_port_remove_store - remove a port from sysfs tree
104  * @dev: pointer to belonging device
105  * @buf: pointer to input buffer
106  * @count: number of bytes in buffer
107  *
108  * Store function of the "port_remove" attribute of an adapter.
109  */
110 static ssize_t
111 zfcp_sysfs_port_remove_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
112 {
113         struct zfcp_adapter *adapter;
114         struct zfcp_port *port;
115         wwn_t wwpn;
116         char *endp;
117         int retval = 0;
118 
119         down(&zfcp_data.config_sema);
120 
121         adapter = dev_get_drvdata(dev);
122         if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
123                 retval = -EBUSY;
124                 goto out;
125         }
126 
127         wwpn = simple_strtoull(buf, &endp, 0);
128         if ((endp + 1) < (buf + count)) {
129                 retval = -EINVAL;
130                 goto out;
131         }
132 
133         write_lock_irq(&zfcp_data.config_lock);
134         port = zfcp_get_port_by_wwpn(adapter, wwpn);
135         if (port && (atomic_read(&port->refcount) == 0)) {
136                 zfcp_port_get(port);
137                 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
138                 list_move(&port->list, &adapter->port_remove_lh);
139         }
140         else {
141                 port = NULL;
142         }
143         write_unlock_irq(&zfcp_data.config_lock);
144 
145         if (!port) {
146                 retval = -ENXIO;
147                 goto out;
148         }
149 
150         zfcp_erp_port_shutdown(port, 0);
151         zfcp_erp_wait(adapter);
152         zfcp_port_put(port);
153         zfcp_port_dequeue(port);
154  out:
155         up(&zfcp_data.config_sema);
156         return retval ? retval : (ssize_t) count;
157 }
158 
159 static DEVICE_ATTR(port_remove, S_IWUSR, NULL, zfcp_sysfs_port_remove_store);
160 
161 /**
162  * zfcp_sysfs_adapter_failed_store - failed state of adapter
163  * @dev: pointer to belonging device
164  * @buf: pointer to input buffer
165  * @count: number of bytes in buffer
166  *
167  * Store function of the "failed" attribute of an adapter.
168  * If a "" gets written to "failed", error recovery will be
169  * started for the belonging adapter.
170  */
171 static ssize_t
172 zfcp_sysfs_adapter_failed_store(struct device *dev, struct device_attribute *attr,
173                                 const char *buf, size_t count)
174 {
175         struct zfcp_adapter *adapter;
176         unsigned int val;
177         char *endp;
178         int retval = 0;
179 
180         down(&zfcp_data.config_sema);
181 
182         adapter = dev_get_drvdata(dev);
183         if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
184                 retval = -EBUSY;
185                 goto out;
186         }
187 
188         val = simple_strtoul(buf, &endp, 0);
189         if (((endp + 1) < (buf + count)) || (val != 0)) {
190                 retval = -EINVAL;
191                 goto out;
192         }
193 
194         zfcp_erp_modify_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING,
195                                        ZFCP_SET);
196         zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
197         zfcp_erp_wait(adapter);
198  out:
199         up(&zfcp_data.config_sema);
200         return retval ? retval : (ssize_t) count;
201 }
202 
203 /**
204  * zfcp_sysfs_adapter_failed_show - failed state of adapter
205  * @dev: pointer to belonging device
206  * @buf: pointer to input buffer
207  *
208  * Show function of "failed" attribute of adapter. Will be
209  * "" if adapter is working, otherwise "1".
210  */
211 static ssize_t
212 zfcp_sysfs_adapter_failed_show(struct device *dev, struct device_attribute *attr, char *buf)
213 {
214         struct zfcp_adapter *adapter;
215 
216         adapter = dev_get_drvdata(dev);
217         if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status))
218                 return sprintf(buf, "1\n");
219         else
220                 return sprintf(buf, "\n");
221 }
222 
223 static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_adapter_failed_show,
224                    zfcp_sysfs_adapter_failed_store);
225 
226 static struct attribute *zfcp_adapter_attrs[] = {
227         &dev_attr_failed.attr,
228         &dev_attr_in_recovery.attr,
229         &dev_attr_port_remove.attr,
230         &dev_attr_port_add.attr,
231         &dev_attr_peer_wwnn.attr,
232         &dev_attr_peer_wwpn.attr,
233         &dev_attr_peer_d_id.attr,
234         &dev_attr_card_version.attr,
235         &dev_attr_lic_version.attr,
236         &dev_attr_status.attr,
237         &dev_attr_hardware_version.attr,
238         NULL
239 };
240 
241 static struct attribute_group zfcp_adapter_attr_group = {
242         .attrs = zfcp_adapter_attrs,
243 };
244 
245 /**
246  * zfcp_sysfs_create_adapter_files - create sysfs adapter files
247  * @dev: pointer to belonging device
248  *
249  * Create all attributes of the sysfs representation of an adapter.
250  */
251 int
252 zfcp_sysfs_adapter_create_files(struct device *dev)
253 {
254         return sysfs_create_group(&dev->kobj, &zfcp_adapter_attr_group);
255 }
256 
257 /**
258  * zfcp_sysfs_remove_adapter_files - remove sysfs adapter files
259  * @dev: pointer to belonging device
260  *
261  * Remove all attributes of the sysfs representation of an adapter.
262  */
263 void
264 zfcp_sysfs_adapter_remove_files(struct device *dev)
265 {
266         sysfs_remove_group(&dev->kobj, &zfcp_adapter_attr_group);
267 }
268 
269 #undef ZFCP_LOG_AREA
270 
  This page was automatically generated by the LXR engine.