2 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
5 * (C) Copyright IBM Corp. 2002, 2006
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)
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.
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.
24 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
26 static int zfcp_ccw_probe(struct ccw_device
*);
27 static void zfcp_ccw_remove(struct ccw_device
*);
28 static int zfcp_ccw_set_online(struct ccw_device
*);
29 static int zfcp_ccw_set_offline(struct ccw_device
*);
30 static int zfcp_ccw_notify(struct ccw_device
*, int);
31 static void zfcp_ccw_shutdown(struct ccw_device
*);
33 static struct ccw_device_id zfcp_ccw_device_id
[] = {
34 {CCW_DEVICE_DEVTYPE(ZFCP_CONTROL_UNIT_TYPE
,
35 ZFCP_CONTROL_UNIT_MODEL
,
38 {CCW_DEVICE_DEVTYPE(ZFCP_CONTROL_UNIT_TYPE
,
39 ZFCP_CONTROL_UNIT_MODEL
,
41 ZFCP_DEVICE_MODEL_PRIV
)},
45 static struct ccw_driver zfcp_ccw_driver
= {
48 .ids
= zfcp_ccw_device_id
,
49 .probe
= zfcp_ccw_probe
,
50 .remove
= zfcp_ccw_remove
,
51 .set_online
= zfcp_ccw_set_online
,
52 .set_offline
= zfcp_ccw_set_offline
,
53 .notify
= zfcp_ccw_notify
,
54 .shutdown
= zfcp_ccw_shutdown
,
56 .groups
= zfcp_driver_attr_groups
,
60 MODULE_DEVICE_TABLE(ccw
, zfcp_ccw_device_id
);
63 * zfcp_ccw_probe - probe function of zfcp driver
64 * @ccw_device: pointer to belonging ccw device
66 * This function gets called by the common i/o layer and sets up the initial
67 * data structures for each fcp adapter, which was detected by the system.
68 * Also the sysfs files for this adapter will be created by this function.
69 * In addition the nameserver port will be added to the ports of the adapter
70 * and its sysfs representation will be created too.
73 zfcp_ccw_probe(struct ccw_device
*ccw_device
)
75 struct zfcp_adapter
*adapter
;
78 down(&zfcp_data
.config_sema
);
79 adapter
= zfcp_adapter_enqueue(ccw_device
);
83 ZFCP_LOG_DEBUG("Probed adapter %s\n",
84 zfcp_get_busid_by_adapter(adapter
));
85 up(&zfcp_data
.config_sema
);
90 * zfcp_ccw_remove - remove function of zfcp driver
91 * @ccw_device: pointer to belonging ccw device
93 * This function gets called by the common i/o layer and removes an adapter
94 * from the system. Task of this function is to get rid of all units and
95 * ports that belong to this adapter. And in addition all resources of this
96 * adapter will be freed too.
99 zfcp_ccw_remove(struct ccw_device
*ccw_device
)
101 struct zfcp_adapter
*adapter
;
102 struct zfcp_port
*port
, *p
;
103 struct zfcp_unit
*unit
, *u
;
105 ccw_device_set_offline(ccw_device
);
106 down(&zfcp_data
.config_sema
);
107 adapter
= dev_get_drvdata(&ccw_device
->dev
);
109 ZFCP_LOG_DEBUG("Removing adapter %s\n",
110 zfcp_get_busid_by_adapter(adapter
));
111 write_lock_irq(&zfcp_data
.config_lock
);
112 list_for_each_entry_safe(port
, p
, &adapter
->port_list_head
, list
) {
113 list_for_each_entry_safe(unit
, u
, &port
->unit_list_head
, list
) {
114 list_move(&unit
->list
, &port
->unit_remove_lh
);
115 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE
,
118 list_move(&port
->list
, &adapter
->port_remove_lh
);
119 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE
, &port
->status
);
121 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE
, &adapter
->status
);
122 write_unlock_irq(&zfcp_data
.config_lock
);
124 list_for_each_entry_safe(port
, p
, &adapter
->port_remove_lh
, list
) {
125 list_for_each_entry_safe(unit
, u
, &port
->unit_remove_lh
, list
) {
126 if (atomic_test_mask(ZFCP_STATUS_UNIT_REGISTERED
,
128 scsi_remove_device(unit
->device
);
129 zfcp_unit_dequeue(unit
);
131 zfcp_port_dequeue(port
);
133 zfcp_adapter_wait(adapter
);
134 zfcp_adapter_dequeue(adapter
);
136 up(&zfcp_data
.config_sema
);
140 * zfcp_ccw_set_online - set_online function of zfcp driver
141 * @ccw_device: pointer to belonging ccw device
143 * This function gets called by the common i/o layer and sets an adapter
144 * into state online. Setting an fcp device online means that it will be
145 * registered with the SCSI stack, that the QDIO queues will be set up
146 * and that the adapter will be opened (asynchronously).
149 zfcp_ccw_set_online(struct ccw_device
*ccw_device
)
151 struct zfcp_adapter
*adapter
;
154 down(&zfcp_data
.config_sema
);
155 adapter
= dev_get_drvdata(&ccw_device
->dev
);
157 retval
= zfcp_erp_thread_setup(adapter
);
159 ZFCP_LOG_INFO("error: start of error recovery thread for "
160 "adapter %s failed\n",
161 zfcp_get_busid_by_adapter(adapter
));
165 retval
= zfcp_adapter_scsi_register(adapter
);
167 goto out_scsi_register
;
169 /* initialize request counter */
170 BUG_ON(!zfcp_reqlist_isempty(adapter
));
173 zfcp_erp_modify_adapter_status(adapter
, 10, NULL
,
174 ZFCP_STATUS_COMMON_RUNNING
, ZFCP_SET
);
175 zfcp_erp_adapter_reopen(adapter
, ZFCP_STATUS_COMMON_ERP_FAILED
, 85,
177 zfcp_erp_wait(adapter
);
181 zfcp_erp_thread_kill(adapter
);
183 up(&zfcp_data
.config_sema
);
188 * zfcp_ccw_set_offline - set_offline function of zfcp driver
189 * @ccw_device: pointer to belonging ccw device
191 * This function gets called by the common i/o layer and sets an adapter
192 * into state offline.
195 zfcp_ccw_set_offline(struct ccw_device
*ccw_device
)
197 struct zfcp_adapter
*adapter
;
199 down(&zfcp_data
.config_sema
);
200 adapter
= dev_get_drvdata(&ccw_device
->dev
);
201 zfcp_erp_adapter_shutdown(adapter
, 0, 86, NULL
);
202 zfcp_erp_wait(adapter
);
203 zfcp_erp_thread_kill(adapter
);
204 up(&zfcp_data
.config_sema
);
210 * @ccw_device: pointer to belonging ccw device
211 * @event: indicates if adapter was detached or attached
213 * This function gets called by the common i/o layer if an adapter has gone
217 zfcp_ccw_notify(struct ccw_device
*ccw_device
, int event
)
219 struct zfcp_adapter
*adapter
;
221 down(&zfcp_data
.config_sema
);
222 adapter
= dev_get_drvdata(&ccw_device
->dev
);
225 ZFCP_LOG_NORMAL("adapter %s: device gone\n",
226 zfcp_get_busid_by_adapter(adapter
));
227 zfcp_erp_adapter_shutdown(adapter
, 0, 87, NULL
);
230 ZFCP_LOG_NORMAL("adapter %s: no path\n",
231 zfcp_get_busid_by_adapter(adapter
));
232 zfcp_erp_adapter_shutdown(adapter
, 0, 88, NULL
);
235 ZFCP_LOG_NORMAL("adapter %s: operational again\n",
236 zfcp_get_busid_by_adapter(adapter
));
237 zfcp_erp_modify_adapter_status(adapter
, 11, NULL
,
238 ZFCP_STATUS_COMMON_RUNNING
,
240 zfcp_erp_adapter_reopen(adapter
, ZFCP_STATUS_COMMON_ERP_FAILED
,
244 zfcp_erp_wait(adapter
);
245 up(&zfcp_data
.config_sema
);
250 * zfcp_ccw_register - ccw register function
252 * Registers the driver at the common i/o layer. This function will be called
253 * at module load time/system start.
256 zfcp_ccw_register(void)
258 return ccw_driver_register(&zfcp_ccw_driver
);
262 * zfcp_ccw_shutdown - gets called on reboot/shutdown
264 * Makes sure that QDIO queues are down when the system gets stopped.
267 zfcp_ccw_shutdown(struct ccw_device
*cdev
)
269 struct zfcp_adapter
*adapter
;
271 down(&zfcp_data
.config_sema
);
272 adapter
= dev_get_drvdata(&cdev
->dev
);
273 zfcp_erp_adapter_shutdown(adapter
, 0, 90, NULL
);
274 zfcp_erp_wait(adapter
);
275 up(&zfcp_data
.config_sema
);