]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/s390/scsi/zfcp_ccw.c
[SCSI] zfcp: Correctly query end flag in gpn_ft response
[mirror_ubuntu-bionic-kernel.git] / drivers / s390 / scsi / zfcp_ccw.c
CommitLineData
1da177e4 1/*
fa04c281 2 * zfcp device driver
1da177e4 3 *
fa04c281 4 * Registration and callback for the s390 common I/O layer.
1da177e4 5 *
fa04c281 6 * Copyright IBM Corporation 2002, 2008
1da177e4
LT
7 */
8
1da177e4
LT
9#include "zfcp_ext.h"
10
1da177e4
LT
11/**
12 * zfcp_ccw_probe - probe function of zfcp driver
13 * @ccw_device: pointer to belonging ccw device
14 *
15 * This function gets called by the common i/o layer and sets up the initial
16 * data structures for each fcp adapter, which was detected by the system.
17 * Also the sysfs files for this adapter will be created by this function.
18 * In addition the nameserver port will be added to the ports of the adapter
19 * and its sysfs representation will be created too.
20 */
fa04c281 21static int zfcp_ccw_probe(struct ccw_device *ccw_device)
1da177e4 22{
1da177e4
LT
23 int retval = 0;
24
25 down(&zfcp_data.config_sema);
317e6b65 26 if (zfcp_adapter_enqueue(ccw_device)) {
fa04c281
CS
27 dev_err(&ccw_device->dev,
28 "Setup of data structures failed.\n");
1da177e4 29 retval = -EINVAL;
fa04c281 30 }
1da177e4
LT
31 up(&zfcp_data.config_sema);
32 return retval;
33}
34
35/**
36 * zfcp_ccw_remove - remove function of zfcp driver
37 * @ccw_device: pointer to belonging ccw device
38 *
39 * This function gets called by the common i/o layer and removes an adapter
40 * from the system. Task of this function is to get rid of all units and
41 * ports that belong to this adapter. And in addition all resources of this
42 * adapter will be freed too.
43 */
fa04c281 44static void zfcp_ccw_remove(struct ccw_device *ccw_device)
1da177e4
LT
45{
46 struct zfcp_adapter *adapter;
47 struct zfcp_port *port, *p;
48 struct zfcp_unit *unit, *u;
49
50 ccw_device_set_offline(ccw_device);
51 down(&zfcp_data.config_sema);
52 adapter = dev_get_drvdata(&ccw_device->dev);
53
1da177e4
LT
54 write_lock_irq(&zfcp_data.config_lock);
55 list_for_each_entry_safe(port, p, &adapter->port_list_head, list) {
56 list_for_each_entry_safe(unit, u, &port->unit_list_head, list) {
57 list_move(&unit->list, &port->unit_remove_lh);
58 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE,
59 &unit->status);
60 }
61 list_move(&port->list, &adapter->port_remove_lh);
62 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
63 }
64 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
65 write_unlock_irq(&zfcp_data.config_lock);
66
67 list_for_each_entry_safe(port, p, &adapter->port_remove_lh, list) {
68 list_for_each_entry_safe(unit, u, &port->unit_remove_lh, list) {
e39c8877
CS
69 if (atomic_test_mask(ZFCP_STATUS_UNIT_REGISTERED,
70 &unit->status))
71 scsi_remove_device(unit->device);
1da177e4
LT
72 zfcp_unit_dequeue(unit);
73 }
74 zfcp_port_dequeue(port);
75 }
76 zfcp_adapter_wait(adapter);
77 zfcp_adapter_dequeue(adapter);
78
79 up(&zfcp_data.config_sema);
80}
81
82/**
83 * zfcp_ccw_set_online - set_online function of zfcp driver
84 * @ccw_device: pointer to belonging ccw device
85 *
86 * This function gets called by the common i/o layer and sets an adapter
87 * into state online. Setting an fcp device online means that it will be
88 * registered with the SCSI stack, that the QDIO queues will be set up
89 * and that the adapter will be opened (asynchronously).
90 */
fa04c281 91static int zfcp_ccw_set_online(struct ccw_device *ccw_device)
1da177e4
LT
92{
93 struct zfcp_adapter *adapter;
94 int retval;
95
96 down(&zfcp_data.config_sema);
97 adapter = dev_get_drvdata(&ccw_device->dev);
98
1da177e4 99 retval = zfcp_erp_thread_setup(adapter);
fa04c281 100 if (retval)
ff17a29d 101 goto out;
1da177e4
LT
102
103 retval = zfcp_adapter_scsi_register(adapter);
104 if (retval)
105 goto out_scsi_register;
fea9d6c7
VS
106
107 /* initialize request counter */
108 BUG_ON(!zfcp_reqlist_isempty(adapter));
109 adapter->req_no = 0;
110
1f6f7129 111 zfcp_erp_modify_adapter_status(adapter, 10, NULL,
698ec016 112 ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
1f6f7129
MP
113 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 85,
114 NULL);
1da177e4
LT
115 zfcp_erp_wait(adapter);
116 goto out;
117
118 out_scsi_register:
119 zfcp_erp_thread_kill(adapter);
1da177e4
LT
120 out:
121 up(&zfcp_data.config_sema);
122 return retval;
123}
124
125/**
126 * zfcp_ccw_set_offline - set_offline function of zfcp driver
127 * @ccw_device: pointer to belonging ccw device
128 *
129 * This function gets called by the common i/o layer and sets an adapter
9f28745a 130 * into state offline.
1da177e4 131 */
fa04c281 132static int zfcp_ccw_set_offline(struct ccw_device *ccw_device)
1da177e4
LT
133{
134 struct zfcp_adapter *adapter;
135
136 down(&zfcp_data.config_sema);
137 adapter = dev_get_drvdata(&ccw_device->dev);
1f6f7129 138 zfcp_erp_adapter_shutdown(adapter, 0, 86, NULL);
1da177e4 139 zfcp_erp_wait(adapter);
1da177e4 140 zfcp_erp_thread_kill(adapter);
1da177e4
LT
141 up(&zfcp_data.config_sema);
142 return 0;
143}
144
145/**
fa04c281 146 * zfcp_ccw_notify - ccw notify function
1da177e4
LT
147 * @ccw_device: pointer to belonging ccw device
148 * @event: indicates if adapter was detached or attached
149 *
150 * This function gets called by the common i/o layer if an adapter has gone
151 * or reappeared.
152 */
fa04c281 153static int zfcp_ccw_notify(struct ccw_device *ccw_device, int event)
1da177e4
LT
154{
155 struct zfcp_adapter *adapter;
156
157 down(&zfcp_data.config_sema);
158 adapter = dev_get_drvdata(&ccw_device->dev);
159 switch (event) {
160 case CIO_GONE:
fa04c281 161 dev_warn(&adapter->ccw_device->dev, "device gone\n");
1f6f7129 162 zfcp_erp_adapter_shutdown(adapter, 0, 87, NULL);
1da177e4
LT
163 break;
164 case CIO_NO_PATH:
fa04c281 165 dev_warn(&adapter->ccw_device->dev, "no path\n");
1f6f7129 166 zfcp_erp_adapter_shutdown(adapter, 0, 88, NULL);
1da177e4
LT
167 break;
168 case CIO_OPER:
fa04c281 169 dev_info(&adapter->ccw_device->dev, "operational again\n");
1f6f7129 170 zfcp_erp_modify_adapter_status(adapter, 11, NULL,
1da177e4
LT
171 ZFCP_STATUS_COMMON_RUNNING,
172 ZFCP_SET);
1f6f7129
MP
173 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
174 89, NULL);
1da177e4
LT
175 break;
176 }
177 zfcp_erp_wait(adapter);
178 up(&zfcp_data.config_sema);
179 return 1;
180}
181
182/**
fa04c281
CS
183 * zfcp_ccw_shutdown - handle shutdown from cio
184 * @cdev: device for adapter to shutdown.
1da177e4 185 */
fa04c281 186static void zfcp_ccw_shutdown(struct ccw_device *cdev)
1da177e4
LT
187{
188 struct zfcp_adapter *adapter;
189
190 down(&zfcp_data.config_sema);
958974fb 191 adapter = dev_get_drvdata(&cdev->dev);
1f6f7129 192 zfcp_erp_adapter_shutdown(adapter, 0, 90, NULL);
1da177e4
LT
193 zfcp_erp_wait(adapter);
194 up(&zfcp_data.config_sema);
195}
196
fa04c281
CS
197static struct ccw_device_id zfcp_ccw_device_id[] = {
198 { CCW_DEVICE_DEVTYPE(0x1731, 0x3, 0x1732, 0x3) },
199 { CCW_DEVICE_DEVTYPE(0x1731, 0x3, 0x1732, 0x4) }, /* priv. */
200 {},
201};
202
203MODULE_DEVICE_TABLE(ccw, zfcp_ccw_device_id);
204
205static struct ccw_driver zfcp_ccw_driver = {
206 .owner = THIS_MODULE,
207 .name = "zfcp",
208 .ids = zfcp_ccw_device_id,
209 .probe = zfcp_ccw_probe,
210 .remove = zfcp_ccw_remove,
211 .set_online = zfcp_ccw_set_online,
212 .set_offline = zfcp_ccw_set_offline,
213 .notify = zfcp_ccw_notify,
214 .shutdown = zfcp_ccw_shutdown,
215};
216
217/**
218 * zfcp_ccw_register - ccw register function
219 *
220 * Registers the driver at the common i/o layer. This function will be called
221 * at module load time/system start.
222 */
223int __init zfcp_ccw_register(void)
224{
225 return ccw_driver_register(&zfcp_ccw_driver);
226}