Commit | Line | Data |
---|---|---|
24073b47 CS |
1 | /* |
2 | * zfcp device driver | |
3 | * | |
4 | * Fibre Channel related functions for the zfcp device driver. | |
5 | * | |
a2fa0aed | 6 | * Copyright IBM Corporation 2008, 2009 |
24073b47 CS |
7 | */ |
8 | ||
ecf39d42 CS |
9 | #define KMSG_COMPONENT "zfcp" |
10 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt | |
11 | ||
24073b47 CS |
12 | #include "zfcp_ext.h" |
13 | ||
e0d7fcb5 CS |
14 | enum rscn_address_format { |
15 | RSCN_PORT_ADDRESS = 0x0, | |
16 | RSCN_AREA_ADDRESS = 0x1, | |
17 | RSCN_DOMAIN_ADDRESS = 0x2, | |
18 | RSCN_FABRIC_ADDRESS = 0x3, | |
19 | }; | |
20 | ||
21 | static u32 rscn_range_mask[] = { | |
22 | [RSCN_PORT_ADDRESS] = 0xFFFFFF, | |
23 | [RSCN_AREA_ADDRESS] = 0xFFFF00, | |
24 | [RSCN_DOMAIN_ADDRESS] = 0xFF0000, | |
25 | [RSCN_FABRIC_ADDRESS] = 0x000000, | |
26 | }; | |
27 | ||
cc8c2829 SS |
28 | struct gpn_ft_resp_acc { |
29 | u8 control; | |
30 | u8 port_id[3]; | |
31 | u8 reserved[4]; | |
32 | u64 wwpn; | |
33 | } __attribute__ ((packed)); | |
34 | ||
39eb7e9a CS |
35 | #define ZFCP_CT_SIZE_ONE_PAGE (PAGE_SIZE - sizeof(struct ct_hdr)) |
36 | #define ZFCP_GPN_FT_ENTRIES (ZFCP_CT_SIZE_ONE_PAGE \ | |
37 | / sizeof(struct gpn_ft_resp_acc)) | |
cc8c2829 | 38 | #define ZFCP_GPN_FT_BUFFERS 4 |
39eb7e9a CS |
39 | #define ZFCP_GPN_FT_MAX_SIZE (ZFCP_GPN_FT_BUFFERS * PAGE_SIZE \ |
40 | - sizeof(struct ct_hdr)) | |
cc8c2829 SS |
41 | #define ZFCP_GPN_FT_MAX_ENTRIES ZFCP_GPN_FT_BUFFERS * (ZFCP_GPN_FT_ENTRIES + 1) |
42 | ||
43 | struct ct_iu_gpn_ft_resp { | |
44 | struct ct_hdr header; | |
45 | struct gpn_ft_resp_acc accept[ZFCP_GPN_FT_ENTRIES]; | |
46 | } __attribute__ ((packed)); | |
47 | ||
48 | struct zfcp_gpn_ft { | |
49 | struct zfcp_send_ct ct; | |
50 | struct scatterlist sg_req; | |
51 | struct scatterlist sg_resp[ZFCP_GPN_FT_BUFFERS]; | |
52 | }; | |
53 | ||
5ab944f9 SS |
54 | struct zfcp_fc_ns_handler_data { |
55 | struct completion done; | |
56 | void (*handler)(unsigned long); | |
57 | unsigned long handler_data; | |
58 | }; | |
59 | ||
60 | static int zfcp_wka_port_get(struct zfcp_wka_port *wka_port) | |
61 | { | |
62 | if (mutex_lock_interruptible(&wka_port->mutex)) | |
63 | return -ERESTARTSYS; | |
64 | ||
1c1cba17 CS |
65 | if (wka_port->status == ZFCP_WKA_PORT_OFFLINE || |
66 | wka_port->status == ZFCP_WKA_PORT_CLOSING) { | |
5ab944f9 SS |
67 | wka_port->status = ZFCP_WKA_PORT_OPENING; |
68 | if (zfcp_fsf_open_wka_port(wka_port)) | |
69 | wka_port->status = ZFCP_WKA_PORT_OFFLINE; | |
70 | } | |
71 | ||
72 | mutex_unlock(&wka_port->mutex); | |
73 | ||
27f492cc SS |
74 | wait_event(wka_port->completion_wq, |
75 | wka_port->status == ZFCP_WKA_PORT_ONLINE || | |
76 | wka_port->status == ZFCP_WKA_PORT_OFFLINE); | |
5ab944f9 SS |
77 | |
78 | if (wka_port->status == ZFCP_WKA_PORT_ONLINE) { | |
79 | atomic_inc(&wka_port->refcount); | |
80 | return 0; | |
81 | } | |
82 | return -EIO; | |
83 | } | |
84 | ||
85 | static void zfcp_wka_port_offline(struct work_struct *work) | |
86 | { | |
bf6aede7 | 87 | struct delayed_work *dw = to_delayed_work(work); |
5ab944f9 SS |
88 | struct zfcp_wka_port *wka_port = |
89 | container_of(dw, struct zfcp_wka_port, work); | |
90 | ||
5ab944f9 SS |
91 | mutex_lock(&wka_port->mutex); |
92 | if ((atomic_read(&wka_port->refcount) != 0) || | |
93 | (wka_port->status != ZFCP_WKA_PORT_ONLINE)) | |
94 | goto out; | |
95 | ||
96 | wka_port->status = ZFCP_WKA_PORT_CLOSING; | |
97 | if (zfcp_fsf_close_wka_port(wka_port)) { | |
98 | wka_port->status = ZFCP_WKA_PORT_OFFLINE; | |
99 | wake_up(&wka_port->completion_wq); | |
100 | } | |
101 | out: | |
102 | mutex_unlock(&wka_port->mutex); | |
103 | } | |
104 | ||
105 | static void zfcp_wka_port_put(struct zfcp_wka_port *wka_port) | |
106 | { | |
107 | if (atomic_dec_return(&wka_port->refcount) != 0) | |
108 | return; | |
19af5cdb | 109 | /* wait 10 milliseconds, other reqs might pop in */ |
5ab944f9 SS |
110 | schedule_delayed_work(&wka_port->work, HZ / 100); |
111 | } | |
112 | ||
9d544f2b SS |
113 | static void zfcp_fc_wka_port_init(struct zfcp_wka_port *wka_port, u32 d_id, |
114 | struct zfcp_adapter *adapter) | |
5ab944f9 | 115 | { |
5ab944f9 SS |
116 | init_waitqueue_head(&wka_port->completion_wq); |
117 | ||
118 | wka_port->adapter = adapter; | |
9d544f2b | 119 | wka_port->d_id = d_id; |
5ab944f9 SS |
120 | |
121 | wka_port->status = ZFCP_WKA_PORT_OFFLINE; | |
122 | atomic_set(&wka_port->refcount, 0); | |
123 | mutex_init(&wka_port->mutex); | |
124 | INIT_DELAYED_WORK(&wka_port->work, zfcp_wka_port_offline); | |
125 | } | |
126 | ||
55c770fa | 127 | static void zfcp_fc_wka_port_force_offline(struct zfcp_wka_port *wka) |
828bc121 SS |
128 | { |
129 | cancel_delayed_work_sync(&wka->work); | |
130 | mutex_lock(&wka->mutex); | |
131 | wka->status = ZFCP_WKA_PORT_OFFLINE; | |
132 | mutex_unlock(&wka->mutex); | |
133 | } | |
134 | ||
55c770fa CS |
135 | void zfcp_fc_wka_ports_force_offline(struct zfcp_wka_ports *gs) |
136 | { | |
137 | zfcp_fc_wka_port_force_offline(&gs->ms); | |
138 | zfcp_fc_wka_port_force_offline(&gs->ts); | |
139 | zfcp_fc_wka_port_force_offline(&gs->ds); | |
140 | zfcp_fc_wka_port_force_offline(&gs->as); | |
141 | zfcp_fc_wka_port_force_offline(&gs->ks); | |
142 | } | |
143 | ||
9d544f2b SS |
144 | void zfcp_fc_wka_ports_init(struct zfcp_adapter *adapter) |
145 | { | |
146 | struct zfcp_wka_ports *gs = adapter->gs; | |
147 | ||
148 | zfcp_fc_wka_port_init(&gs->ms, FC_FID_MGMT_SERV, adapter); | |
149 | zfcp_fc_wka_port_init(&gs->ts, FC_FID_TIME_SERV, adapter); | |
150 | zfcp_fc_wka_port_init(&gs->ds, FC_FID_DIR_SERV, adapter); | |
151 | zfcp_fc_wka_port_init(&gs->as, FC_FID_ALIASES, adapter); | |
152 | zfcp_fc_wka_port_init(&gs->ks, FC_FID_SEC_KEY, adapter); | |
153 | } | |
154 | ||
24073b47 CS |
155 | static void _zfcp_fc_incoming_rscn(struct zfcp_fsf_req *fsf_req, u32 range, |
156 | struct fcp_rscn_element *elem) | |
157 | { | |
158 | unsigned long flags; | |
159 | struct zfcp_port *port; | |
160 | ||
161 | read_lock_irqsave(&zfcp_data.config_lock, flags); | |
ea460a81 | 162 | list_for_each_entry(port, &fsf_req->adapter->port_list_head, list) { |
24095490 | 163 | if ((port->d_id & range) == (elem->nport_did & range)) |
24073b47 | 164 | zfcp_test_link(port); |
ea460a81 SS |
165 | if (!port->d_id) |
166 | zfcp_erp_port_reopen(port, | |
167 | ZFCP_STATUS_COMMON_ERP_FAILED, | |
168 | "fcrscn1", NULL); | |
169 | } | |
24095490 | 170 | |
24073b47 CS |
171 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
172 | } | |
173 | ||
174 | static void zfcp_fc_incoming_rscn(struct zfcp_fsf_req *fsf_req) | |
175 | { | |
176 | struct fsf_status_read_buffer *status_buffer = (void *)fsf_req->data; | |
177 | struct fcp_rscn_head *fcp_rscn_head; | |
178 | struct fcp_rscn_element *fcp_rscn_element; | |
179 | u16 i; | |
180 | u16 no_entries; | |
181 | u32 range_mask; | |
182 | ||
c41f8cbd SS |
183 | fcp_rscn_head = (struct fcp_rscn_head *) status_buffer->payload.data; |
184 | fcp_rscn_element = (struct fcp_rscn_element *) fcp_rscn_head; | |
24073b47 CS |
185 | |
186 | /* see FC-FS */ | |
187 | no_entries = fcp_rscn_head->payload_len / | |
188 | sizeof(struct fcp_rscn_element); | |
189 | ||
190 | for (i = 1; i < no_entries; i++) { | |
191 | /* skip head and start with 1st element */ | |
192 | fcp_rscn_element++; | |
e0d7fcb5 | 193 | range_mask = rscn_range_mask[fcp_rscn_element->addr_format]; |
24073b47 CS |
194 | _zfcp_fc_incoming_rscn(fsf_req, range_mask, fcp_rscn_element); |
195 | } | |
cc8c2829 | 196 | schedule_work(&fsf_req->adapter->scan_work); |
24073b47 CS |
197 | } |
198 | ||
7ba58c9c | 199 | static void zfcp_fc_incoming_wwpn(struct zfcp_fsf_req *req, u64 wwpn) |
24073b47 CS |
200 | { |
201 | struct zfcp_adapter *adapter = req->adapter; | |
202 | struct zfcp_port *port; | |
203 | unsigned long flags; | |
204 | ||
205 | read_lock_irqsave(&zfcp_data.config_lock, flags); | |
206 | list_for_each_entry(port, &adapter->port_list_head, list) | |
207 | if (port->wwpn == wwpn) | |
208 | break; | |
209 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); | |
210 | ||
211 | if (port && (port->wwpn == wwpn)) | |
5ffd51a5 | 212 | zfcp_erp_port_forced_reopen(port, 0, "fciwwp1", req); |
24073b47 CS |
213 | } |
214 | ||
215 | static void zfcp_fc_incoming_plogi(struct zfcp_fsf_req *req) | |
216 | { | |
217 | struct fsf_status_read_buffer *status_buffer = | |
218 | (struct fsf_status_read_buffer *)req->data; | |
219 | struct fsf_plogi *els_plogi = | |
c41f8cbd | 220 | (struct fsf_plogi *) status_buffer->payload.data; |
24073b47 CS |
221 | |
222 | zfcp_fc_incoming_wwpn(req, els_plogi->serv_param.wwpn); | |
223 | } | |
224 | ||
225 | static void zfcp_fc_incoming_logo(struct zfcp_fsf_req *req) | |
226 | { | |
227 | struct fsf_status_read_buffer *status_buffer = | |
228 | (struct fsf_status_read_buffer *)req->data; | |
c41f8cbd SS |
229 | struct fcp_logo *els_logo = |
230 | (struct fcp_logo *) status_buffer->payload.data; | |
24073b47 CS |
231 | |
232 | zfcp_fc_incoming_wwpn(req, els_logo->nport_wwpn); | |
233 | } | |
234 | ||
235 | /** | |
236 | * zfcp_fc_incoming_els - handle incoming ELS | |
237 | * @fsf_req - request which contains incoming ELS | |
238 | */ | |
239 | void zfcp_fc_incoming_els(struct zfcp_fsf_req *fsf_req) | |
240 | { | |
241 | struct fsf_status_read_buffer *status_buffer = | |
242 | (struct fsf_status_read_buffer *) fsf_req->data; | |
c41f8cbd | 243 | unsigned int els_type = status_buffer->payload.data[0]; |
24073b47 CS |
244 | |
245 | zfcp_san_dbf_event_incoming_els(fsf_req); | |
246 | if (els_type == LS_PLOGI) | |
247 | zfcp_fc_incoming_plogi(fsf_req); | |
248 | else if (els_type == LS_LOGO) | |
249 | zfcp_fc_incoming_logo(fsf_req); | |
250 | else if (els_type == LS_RSCN) | |
251 | zfcp_fc_incoming_rscn(fsf_req); | |
252 | } | |
253 | ||
5ab944f9 SS |
254 | static void zfcp_fc_ns_handler(unsigned long data) |
255 | { | |
256 | struct zfcp_fc_ns_handler_data *compl_rec = | |
257 | (struct zfcp_fc_ns_handler_data *) data; | |
258 | ||
259 | if (compl_rec->handler) | |
260 | compl_rec->handler(compl_rec->handler_data); | |
261 | ||
262 | complete(&compl_rec->done); | |
263 | } | |
264 | ||
265 | static void zfcp_fc_ns_gid_pn_eval(unsigned long data) | |
24073b47 CS |
266 | { |
267 | struct zfcp_gid_pn_data *gid_pn = (struct zfcp_gid_pn_data *) data; | |
268 | struct zfcp_send_ct *ct = &gid_pn->ct; | |
269 | struct ct_iu_gid_pn_req *ct_iu_req = sg_virt(ct->req); | |
270 | struct ct_iu_gid_pn_resp *ct_iu_resp = sg_virt(ct->resp); | |
271 | struct zfcp_port *port = gid_pn->port; | |
272 | ||
273 | if (ct->status) | |
5ab944f9 | 274 | return; |
a5b11dda | 275 | if (ct_iu_resp->header.cmd_rsp_code != ZFCP_CT_ACCEPT) |
5ab944f9 | 276 | return; |
a5b11dda | 277 | |
24073b47 CS |
278 | /* paranoia */ |
279 | if (ct_iu_req->wwpn != port->wwpn) | |
5ab944f9 | 280 | return; |
24073b47 CS |
281 | /* looks like a valid d_id */ |
282 | port->d_id = ct_iu_resp->d_id & ZFCP_DID_MASK; | |
24073b47 CS |
283 | } |
284 | ||
5ab944f9 SS |
285 | int static zfcp_fc_ns_gid_pn_request(struct zfcp_erp_action *erp_action, |
286 | struct zfcp_gid_pn_data *gid_pn) | |
24073b47 | 287 | { |
24073b47 | 288 | struct zfcp_adapter *adapter = erp_action->adapter; |
5ab944f9 SS |
289 | struct zfcp_fc_ns_handler_data compl_rec; |
290 | int ret; | |
24073b47 CS |
291 | |
292 | /* setup parameters for send generic command */ | |
293 | gid_pn->port = erp_action->port; | |
9d544f2b | 294 | gid_pn->ct.wka_port = &adapter->gs->ds; |
5ab944f9 SS |
295 | gid_pn->ct.handler = zfcp_fc_ns_handler; |
296 | gid_pn->ct.handler_data = (unsigned long) &compl_rec; | |
24073b47 CS |
297 | gid_pn->ct.timeout = ZFCP_NS_GID_PN_TIMEOUT; |
298 | gid_pn->ct.req = &gid_pn->req; | |
299 | gid_pn->ct.resp = &gid_pn->resp; | |
24073b47 CS |
300 | sg_init_one(&gid_pn->req, &gid_pn->ct_iu_req, |
301 | sizeof(struct ct_iu_gid_pn_req)); | |
302 | sg_init_one(&gid_pn->resp, &gid_pn->ct_iu_resp, | |
303 | sizeof(struct ct_iu_gid_pn_resp)); | |
304 | ||
305 | /* setup nameserver request */ | |
306 | gid_pn->ct_iu_req.header.revision = ZFCP_CT_REVISION; | |
307 | gid_pn->ct_iu_req.header.gs_type = ZFCP_CT_DIRECTORY_SERVICE; | |
308 | gid_pn->ct_iu_req.header.gs_subtype = ZFCP_CT_NAME_SERVER; | |
309 | gid_pn->ct_iu_req.header.options = ZFCP_CT_SYNCHRONOUS; | |
310 | gid_pn->ct_iu_req.header.cmd_rsp_code = ZFCP_CT_GID_PN; | |
39eb7e9a | 311 | gid_pn->ct_iu_req.header.max_res_size = ZFCP_CT_SIZE_ONE_PAGE / 4; |
24073b47 CS |
312 | gid_pn->ct_iu_req.wwpn = erp_action->port->wwpn; |
313 | ||
5ab944f9 SS |
314 | init_completion(&compl_rec.done); |
315 | compl_rec.handler = zfcp_fc_ns_gid_pn_eval; | |
316 | compl_rec.handler_data = (unsigned long) gid_pn; | |
a4623c46 | 317 | ret = zfcp_fsf_send_ct(&gid_pn->ct, adapter->pool.erp_req, erp_action); |
5ab944f9 SS |
318 | if (!ret) |
319 | wait_for_completion(&compl_rec.done); | |
320 | return ret; | |
321 | } | |
322 | ||
323 | /** | |
324 | * zfcp_fc_ns_gid_pn_request - initiate GID_PN nameserver request | |
325 | * @erp_action: pointer to zfcp_erp_action where GID_PN request is needed | |
326 | * return: -ENOMEM on error, 0 otherwise | |
327 | */ | |
328 | int zfcp_fc_ns_gid_pn(struct zfcp_erp_action *erp_action) | |
329 | { | |
330 | int ret; | |
331 | struct zfcp_gid_pn_data *gid_pn; | |
332 | struct zfcp_adapter *adapter = erp_action->adapter; | |
333 | ||
a4623c46 | 334 | gid_pn = mempool_alloc(adapter->pool.gid_pn_data, GFP_ATOMIC); |
5ab944f9 SS |
335 | if (!gid_pn) |
336 | return -ENOMEM; | |
337 | ||
338 | memset(gid_pn, 0, sizeof(*gid_pn)); | |
339 | ||
9d544f2b | 340 | ret = zfcp_wka_port_get(&adapter->gs->ds); |
24073b47 | 341 | if (ret) |
5ab944f9 SS |
342 | goto out; |
343 | ||
344 | ret = zfcp_fc_ns_gid_pn_request(erp_action, gid_pn); | |
345 | ||
9d544f2b | 346 | zfcp_wka_port_put(&adapter->gs->ds); |
5ab944f9 | 347 | out: |
a4623c46 | 348 | mempool_free(gid_pn, adapter->pool.gid_pn_data); |
24073b47 CS |
349 | return ret; |
350 | } | |
351 | ||
352 | /** | |
353 | * zfcp_fc_plogi_evaluate - evaluate PLOGI playload | |
354 | * @port: zfcp_port structure | |
355 | * @plogi: plogi payload | |
356 | * | |
357 | * Evaluate PLOGI playload and copy important fields into zfcp_port structure | |
358 | */ | |
359 | void zfcp_fc_plogi_evaluate(struct zfcp_port *port, struct fsf_plogi *plogi) | |
360 | { | |
361 | port->maxframe_size = plogi->serv_param.common_serv_param[7] | | |
362 | ((plogi->serv_param.common_serv_param[6] & 0x0F) << 8); | |
363 | if (plogi->serv_param.class1_serv_param[0] & 0x80) | |
364 | port->supported_classes |= FC_COS_CLASS1; | |
365 | if (plogi->serv_param.class2_serv_param[0] & 0x80) | |
366 | port->supported_classes |= FC_COS_CLASS2; | |
367 | if (plogi->serv_param.class3_serv_param[0] & 0x80) | |
368 | port->supported_classes |= FC_COS_CLASS3; | |
369 | if (plogi->serv_param.class4_serv_param[0] & 0x80) | |
370 | port->supported_classes |= FC_COS_CLASS4; | |
371 | } | |
372 | ||
373 | struct zfcp_els_adisc { | |
374 | struct zfcp_send_els els; | |
375 | struct scatterlist req; | |
376 | struct scatterlist resp; | |
377 | struct zfcp_ls_adisc ls_adisc; | |
44cc76f2 | 378 | struct zfcp_ls_adisc ls_adisc_acc; |
24073b47 CS |
379 | }; |
380 | ||
381 | static void zfcp_fc_adisc_handler(unsigned long data) | |
382 | { | |
383 | struct zfcp_els_adisc *adisc = (struct zfcp_els_adisc *) data; | |
384 | struct zfcp_port *port = adisc->els.port; | |
44cc76f2 | 385 | struct zfcp_ls_adisc *ls_adisc = &adisc->ls_adisc_acc; |
24073b47 | 386 | |
3968ce80 | 387 | if (adisc->els.status) { |
24073b47 | 388 | /* request rejected or timed out */ |
5b43e719 SS |
389 | zfcp_erp_port_forced_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, |
390 | "fcadh_1", NULL); | |
24073b47 CS |
391 | goto out; |
392 | } | |
393 | ||
394 | if (!port->wwnn) | |
395 | port->wwnn = ls_adisc->wwnn; | |
396 | ||
24095490 | 397 | if ((port->wwpn != ls_adisc->wwpn) || |
a2fa0aed | 398 | !(atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)) { |
24095490 SS |
399 | zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, |
400 | "fcadh_2", NULL); | |
a2fa0aed CS |
401 | goto out; |
402 | } | |
24073b47 | 403 | |
a2fa0aed CS |
404 | /* port is good, unblock rport without going through erp */ |
405 | zfcp_scsi_schedule_rport_register(port); | |
24073b47 | 406 | out: |
14e242ea | 407 | atomic_clear_mask(ZFCP_STATUS_PORT_LINK_TEST, &port->status); |
24073b47 CS |
408 | zfcp_port_put(port); |
409 | kfree(adisc); | |
410 | } | |
411 | ||
412 | static int zfcp_fc_adisc(struct zfcp_port *port) | |
413 | { | |
414 | struct zfcp_els_adisc *adisc; | |
415 | struct zfcp_adapter *adapter = port->adapter; | |
416 | ||
417 | adisc = kzalloc(sizeof(struct zfcp_els_adisc), GFP_ATOMIC); | |
418 | if (!adisc) | |
419 | return -ENOMEM; | |
420 | ||
421 | adisc->els.req = &adisc->req; | |
422 | adisc->els.resp = &adisc->resp; | |
423 | sg_init_one(adisc->els.req, &adisc->ls_adisc, | |
424 | sizeof(struct zfcp_ls_adisc)); | |
425 | sg_init_one(adisc->els.resp, &adisc->ls_adisc_acc, | |
44cc76f2 | 426 | sizeof(struct zfcp_ls_adisc)); |
24073b47 | 427 | |
24073b47 CS |
428 | adisc->els.adapter = adapter; |
429 | adisc->els.port = port; | |
430 | adisc->els.d_id = port->d_id; | |
431 | adisc->els.handler = zfcp_fc_adisc_handler; | |
432 | adisc->els.handler_data = (unsigned long) adisc; | |
433 | adisc->els.ls_code = adisc->ls_adisc.code = ZFCP_LS_ADISC; | |
434 | ||
435 | /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports | |
436 | without FC-AL-2 capability, so we don't set it */ | |
437 | adisc->ls_adisc.wwpn = fc_host_port_name(adapter->scsi_host); | |
438 | adisc->ls_adisc.wwnn = fc_host_node_name(adapter->scsi_host); | |
439 | adisc->ls_adisc.nport_id = fc_host_port_id(adapter->scsi_host); | |
440 | ||
441 | return zfcp_fsf_send_els(&adisc->els); | |
442 | } | |
443 | ||
8fdf30d5 | 444 | void zfcp_fc_link_test_work(struct work_struct *work) |
24073b47 | 445 | { |
8fdf30d5 CS |
446 | struct zfcp_port *port = |
447 | container_of(work, struct zfcp_port, test_link_work); | |
24073b47 CS |
448 | int retval; |
449 | ||
a2fa0aed CS |
450 | zfcp_port_get(port); |
451 | port->rport_task = RPORT_DEL; | |
452 | zfcp_scsi_rport_work(&port->rport_work); | |
453 | ||
14e242ea CS |
454 | /* only issue one test command at one time per port */ |
455 | if (atomic_read(&port->status) & ZFCP_STATUS_PORT_LINK_TEST) | |
456 | goto out; | |
457 | ||
458 | atomic_set_mask(ZFCP_STATUS_PORT_LINK_TEST, &port->status); | |
459 | ||
24073b47 | 460 | retval = zfcp_fc_adisc(port); |
9528539c | 461 | if (retval == 0) |
24073b47 CS |
462 | return; |
463 | ||
464 | /* send of ADISC was not possible */ | |
14e242ea | 465 | atomic_clear_mask(ZFCP_STATUS_PORT_LINK_TEST, &port->status); |
a2fa0aed CS |
466 | zfcp_erp_port_forced_reopen(port, 0, "fcltwk1", NULL); |
467 | ||
14e242ea | 468 | out: |
24073b47 | 469 | zfcp_port_put(port); |
24073b47 | 470 | } |
cc8c2829 | 471 | |
8fdf30d5 CS |
472 | /** |
473 | * zfcp_test_link - lightweight link test procedure | |
474 | * @port: port to be tested | |
475 | * | |
476 | * Test status of a link to a remote port using the ELS command ADISC. | |
477 | * If there is a problem with the remote port, error recovery steps | |
478 | * will be triggered. | |
479 | */ | |
480 | void zfcp_test_link(struct zfcp_port *port) | |
481 | { | |
482 | zfcp_port_get(port); | |
483 | if (!queue_work(zfcp_data.work_queue, &port->test_link_work)) | |
484 | zfcp_port_put(port); | |
485 | } | |
486 | ||
39eb7e9a | 487 | static void zfcp_free_sg_env(struct zfcp_gpn_ft *gpn_ft, int buf_num) |
cc8c2829 SS |
488 | { |
489 | struct scatterlist *sg = &gpn_ft->sg_req; | |
490 | ||
a4623c46 | 491 | kmem_cache_free(zfcp_data.gpn_ft_cache, sg_virt(sg)); |
39eb7e9a | 492 | zfcp_sg_free_table(gpn_ft->sg_resp, buf_num); |
cc8c2829 SS |
493 | |
494 | kfree(gpn_ft); | |
495 | } | |
496 | ||
39eb7e9a | 497 | static struct zfcp_gpn_ft *zfcp_alloc_sg_env(int buf_num) |
cc8c2829 SS |
498 | { |
499 | struct zfcp_gpn_ft *gpn_ft; | |
500 | struct ct_iu_gpn_ft_req *req; | |
501 | ||
502 | gpn_ft = kzalloc(sizeof(*gpn_ft), GFP_KERNEL); | |
503 | if (!gpn_ft) | |
504 | return NULL; | |
505 | ||
a4623c46 | 506 | req = kmem_cache_alloc(zfcp_data.gpn_ft_cache, GFP_KERNEL); |
cc8c2829 SS |
507 | if (!req) { |
508 | kfree(gpn_ft); | |
509 | gpn_ft = NULL; | |
510 | goto out; | |
511 | } | |
512 | sg_init_one(&gpn_ft->sg_req, req, sizeof(*req)); | |
513 | ||
39eb7e9a CS |
514 | if (zfcp_sg_setup_table(gpn_ft->sg_resp, buf_num)) { |
515 | zfcp_free_sg_env(gpn_ft, buf_num); | |
cc8c2829 SS |
516 | gpn_ft = NULL; |
517 | } | |
518 | out: | |
519 | return gpn_ft; | |
520 | } | |
521 | ||
522 | ||
523 | static int zfcp_scan_issue_gpn_ft(struct zfcp_gpn_ft *gpn_ft, | |
39eb7e9a CS |
524 | struct zfcp_adapter *adapter, |
525 | int max_bytes) | |
cc8c2829 SS |
526 | { |
527 | struct zfcp_send_ct *ct = &gpn_ft->ct; | |
528 | struct ct_iu_gpn_ft_req *req = sg_virt(&gpn_ft->sg_req); | |
5ab944f9 | 529 | struct zfcp_fc_ns_handler_data compl_rec; |
cc8c2829 SS |
530 | int ret; |
531 | ||
532 | /* prepare CT IU for GPN_FT */ | |
533 | req->header.revision = ZFCP_CT_REVISION; | |
534 | req->header.gs_type = ZFCP_CT_DIRECTORY_SERVICE; | |
535 | req->header.gs_subtype = ZFCP_CT_NAME_SERVER; | |
536 | req->header.options = ZFCP_CT_SYNCHRONOUS; | |
537 | req->header.cmd_rsp_code = ZFCP_CT_GPN_FT; | |
39eb7e9a | 538 | req->header.max_res_size = max_bytes / 4; |
cc8c2829 SS |
539 | req->flags = 0; |
540 | req->domain_id_scope = 0; | |
541 | req->area_id_scope = 0; | |
542 | req->fc4_type = ZFCP_CT_SCSI_FCP; | |
543 | ||
544 | /* prepare zfcp_send_ct */ | |
9d544f2b | 545 | ct->wka_port = &adapter->gs->ds; |
5ab944f9 SS |
546 | ct->handler = zfcp_fc_ns_handler; |
547 | ct->handler_data = (unsigned long)&compl_rec; | |
cc8c2829 SS |
548 | ct->timeout = 10; |
549 | ct->req = &gpn_ft->sg_req; | |
550 | ct->resp = gpn_ft->sg_resp; | |
cc8c2829 | 551 | |
5ab944f9 SS |
552 | init_completion(&compl_rec.done); |
553 | compl_rec.handler = NULL; | |
cc8c2829 SS |
554 | ret = zfcp_fsf_send_ct(ct, NULL, NULL); |
555 | if (!ret) | |
5ab944f9 | 556 | wait_for_completion(&compl_rec.done); |
cc8c2829 SS |
557 | return ret; |
558 | } | |
559 | ||
560 | static void zfcp_validate_port(struct zfcp_port *port) | |
561 | { | |
562 | struct zfcp_adapter *adapter = port->adapter; | |
563 | ||
6ab35c07 MP |
564 | if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC)) |
565 | return; | |
566 | ||
cc8c2829 SS |
567 | atomic_clear_mask(ZFCP_STATUS_COMMON_NOESC, &port->status); |
568 | ||
0406289e CS |
569 | if ((port->supported_classes != 0) || |
570 | !list_empty(&port->unit_list_head)) { | |
cc8c2829 SS |
571 | zfcp_port_put(port); |
572 | return; | |
573 | } | |
5ffd51a5 | 574 | zfcp_erp_port_shutdown(port, 0, "fcpval1", NULL); |
cc8c2829 SS |
575 | zfcp_erp_wait(adapter); |
576 | zfcp_port_put(port); | |
577 | zfcp_port_dequeue(port); | |
578 | } | |
579 | ||
39eb7e9a | 580 | static int zfcp_scan_eval_gpn_ft(struct zfcp_gpn_ft *gpn_ft, int max_entries) |
cc8c2829 SS |
581 | { |
582 | struct zfcp_send_ct *ct = &gpn_ft->ct; | |
583 | struct scatterlist *sg = gpn_ft->sg_resp; | |
584 | struct ct_hdr *hdr = sg_virt(sg); | |
585 | struct gpn_ft_resp_acc *acc = sg_virt(sg); | |
5ab944f9 | 586 | struct zfcp_adapter *adapter = ct->wka_port->adapter; |
cc8c2829 SS |
587 | struct zfcp_port *port, *tmp; |
588 | u32 d_id; | |
47f7bba5 | 589 | int ret = 0, x, last = 0; |
cc8c2829 SS |
590 | |
591 | if (ct->status) | |
592 | return -EIO; | |
593 | ||
594 | if (hdr->cmd_rsp_code != ZFCP_CT_ACCEPT) { | |
595 | if (hdr->reason_code == ZFCP_CT_UNABLE_TO_PERFORM_CMD) | |
596 | return -EAGAIN; /* might be a temporary condition */ | |
597 | return -EIO; | |
598 | } | |
599 | ||
39eb7e9a CS |
600 | if (hdr->max_res_size) { |
601 | dev_warn(&adapter->ccw_device->dev, | |
602 | "The name server reported %d words residual data\n", | |
603 | hdr->max_res_size); | |
cc8c2829 | 604 | return -E2BIG; |
39eb7e9a | 605 | } |
cc8c2829 SS |
606 | |
607 | down(&zfcp_data.config_sema); | |
608 | ||
609 | /* first entry is the header */ | |
39eb7e9a | 610 | for (x = 1; x < max_entries && !last; x++) { |
cc8c2829 SS |
611 | if (x % (ZFCP_GPN_FT_ENTRIES + 1)) |
612 | acc++; | |
613 | else | |
614 | acc = sg_virt(++sg); | |
615 | ||
47f7bba5 | 616 | last = acc->control & 0x80; |
cc8c2829 SS |
617 | d_id = acc->port_id[0] << 16 | acc->port_id[1] << 8 | |
618 | acc->port_id[2]; | |
619 | ||
5ab944f9 SS |
620 | /* don't attach ports with a well known address */ |
621 | if ((d_id & ZFCP_DID_WKA) == ZFCP_DID_WKA) | |
622 | continue; | |
cc8c2829 | 623 | /* skip the adapter's port and known remote ports */ |
9528539c | 624 | if (acc->wwpn == fc_host_port_name(adapter->scsi_host)) |
cc8c2829 | 625 | continue; |
9528539c | 626 | port = zfcp_get_port_by_wwpn(adapter, acc->wwpn); |
6ab35c07 | 627 | if (port) |
9528539c | 628 | continue; |
cc8c2829 SS |
629 | |
630 | port = zfcp_port_enqueue(adapter, acc->wwpn, | |
cc8c2829 | 631 | ZFCP_STATUS_COMMON_NOESC, d_id); |
317e6b65 SS |
632 | if (IS_ERR(port)) |
633 | ret = PTR_ERR(port); | |
cc8c2829 | 634 | else |
5ffd51a5 | 635 | zfcp_erp_port_reopen(port, 0, "fcegpf1", NULL); |
cc8c2829 SS |
636 | } |
637 | ||
638 | zfcp_erp_wait(adapter); | |
639 | list_for_each_entry_safe(port, tmp, &adapter->port_list_head, list) | |
640 | zfcp_validate_port(port); | |
641 | up(&zfcp_data.config_sema); | |
642 | return ret; | |
643 | } | |
644 | ||
645 | /** | |
646 | * zfcp_scan_ports - scan remote ports and attach new ports | |
647 | * @adapter: pointer to struct zfcp_adapter | |
648 | */ | |
649 | int zfcp_scan_ports(struct zfcp_adapter *adapter) | |
650 | { | |
651 | int ret, i; | |
652 | struct zfcp_gpn_ft *gpn_ft; | |
39eb7e9a CS |
653 | int chain, max_entries, buf_num, max_bytes; |
654 | ||
655 | chain = adapter->adapter_features & FSF_FEATURE_ELS_CT_CHAINED_SBALS; | |
656 | buf_num = chain ? ZFCP_GPN_FT_BUFFERS : 1; | |
657 | max_entries = chain ? ZFCP_GPN_FT_MAX_ENTRIES : ZFCP_GPN_FT_ENTRIES; | |
658 | max_bytes = chain ? ZFCP_GPN_FT_MAX_SIZE : ZFCP_CT_SIZE_ONE_PAGE; | |
cc8c2829 | 659 | |
306b6edc SS |
660 | if (fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPORT && |
661 | fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPIV) | |
cc8c2829 SS |
662 | return 0; |
663 | ||
9d544f2b | 664 | ret = zfcp_wka_port_get(&adapter->gs->ds); |
cc8c2829 SS |
665 | if (ret) |
666 | return ret; | |
667 | ||
39eb7e9a | 668 | gpn_ft = zfcp_alloc_sg_env(buf_num); |
5ab944f9 SS |
669 | if (!gpn_ft) { |
670 | ret = -ENOMEM; | |
671 | goto out; | |
672 | } | |
cc8c2829 SS |
673 | |
674 | for (i = 0; i < 3; i++) { | |
39eb7e9a | 675 | ret = zfcp_scan_issue_gpn_ft(gpn_ft, adapter, max_bytes); |
cc8c2829 | 676 | if (!ret) { |
39eb7e9a | 677 | ret = zfcp_scan_eval_gpn_ft(gpn_ft, max_entries); |
cc8c2829 SS |
678 | if (ret == -EAGAIN) |
679 | ssleep(1); | |
680 | else | |
681 | break; | |
682 | } | |
683 | } | |
39eb7e9a | 684 | zfcp_free_sg_env(gpn_ft, buf_num); |
5ab944f9 | 685 | out: |
9d544f2b | 686 | zfcp_wka_port_put(&adapter->gs->ds); |
cc8c2829 SS |
687 | return ret; |
688 | } | |
689 | ||
690 | ||
691 | void _zfcp_scan_ports_later(struct work_struct *work) | |
692 | { | |
693 | zfcp_scan_ports(container_of(work, struct zfcp_adapter, scan_work)); | |
694 | } | |
9d544f2b SS |
695 | |
696 | struct zfcp_els_fc_job { | |
697 | struct zfcp_send_els els; | |
698 | struct fc_bsg_job *job; | |
699 | }; | |
700 | ||
701 | static void zfcp_fc_generic_els_handler(unsigned long data) | |
702 | { | |
703 | struct zfcp_els_fc_job *els_fc_job = (struct zfcp_els_fc_job *) data; | |
704 | struct fc_bsg_job *job = els_fc_job->job; | |
705 | struct fc_bsg_reply *reply = job->reply; | |
706 | ||
707 | if (els_fc_job->els.status) { | |
708 | /* request rejected or timed out */ | |
709 | reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_REJECT; | |
710 | goto out; | |
711 | } | |
712 | ||
713 | reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK; | |
dc577d55 | 714 | reply->reply_payload_rcv_len = job->reply_payload.payload_len; |
9d544f2b SS |
715 | |
716 | out: | |
717 | job->state_flags = FC_RQST_STATE_DONE; | |
718 | job->job_done(job); | |
719 | kfree(els_fc_job); | |
720 | } | |
721 | ||
722 | int zfcp_fc_execute_els_fc_job(struct fc_bsg_job *job) | |
723 | { | |
724 | struct zfcp_els_fc_job *els_fc_job; | |
725 | struct fc_rport *rport = job->rport; | |
726 | struct Scsi_Host *shost; | |
727 | struct zfcp_adapter *adapter; | |
728 | struct zfcp_port *port; | |
729 | u8 *port_did; | |
730 | ||
731 | shost = rport ? rport_to_shost(rport) : job->shost; | |
732 | adapter = (struct zfcp_adapter *)shost->hostdata[0]; | |
733 | ||
734 | if (!(atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN)) | |
735 | return -EINVAL; | |
736 | ||
737 | els_fc_job = kzalloc(sizeof(struct zfcp_els_fc_job), GFP_KERNEL); | |
738 | if (!els_fc_job) | |
739 | return -ENOMEM; | |
740 | ||
741 | els_fc_job->els.adapter = adapter; | |
742 | if (rport) { | |
743 | read_lock_irq(&zfcp_data.config_lock); | |
744 | port = rport->dd_data; | |
745 | if (port) | |
dc577d55 | 746 | els_fc_job->els.d_id = port->d_id; |
9d544f2b SS |
747 | read_unlock_irq(&zfcp_data.config_lock); |
748 | if (!port) { | |
749 | kfree(els_fc_job); | |
750 | return -EINVAL; | |
751 | } | |
9d544f2b SS |
752 | } else { |
753 | port_did = job->request->rqst_data.h_els.port_id; | |
754 | els_fc_job->els.d_id = (port_did[0] << 16) + | |
755 | (port_did[1] << 8) + port_did[2]; | |
756 | } | |
757 | ||
758 | els_fc_job->els.req = job->request_payload.sg_list; | |
759 | els_fc_job->els.resp = job->reply_payload.sg_list; | |
760 | els_fc_job->els.handler = zfcp_fc_generic_els_handler; | |
761 | els_fc_job->els.handler_data = (unsigned long) els_fc_job; | |
762 | els_fc_job->job = job; | |
763 | ||
764 | return zfcp_fsf_send_els(&els_fc_job->els); | |
765 | } | |
766 | ||
767 | struct zfcp_ct_fc_job { | |
768 | struct zfcp_send_ct ct; | |
769 | struct fc_bsg_job *job; | |
770 | }; | |
771 | ||
772 | static void zfcp_fc_generic_ct_handler(unsigned long data) | |
773 | { | |
774 | struct zfcp_ct_fc_job *ct_fc_job = (struct zfcp_ct_fc_job *) data; | |
775 | struct fc_bsg_job *job = ct_fc_job->job; | |
776 | ||
777 | job->reply->reply_data.ctels_reply.status = ct_fc_job->ct.status ? | |
778 | FC_CTELS_STATUS_REJECT : FC_CTELS_STATUS_OK; | |
dc577d55 | 779 | job->reply->reply_payload_rcv_len = job->reply_payload.payload_len; |
9d544f2b | 780 | job->state_flags = FC_RQST_STATE_DONE; |
9d544f2b SS |
781 | job->job_done(job); |
782 | ||
783 | zfcp_wka_port_put(ct_fc_job->ct.wka_port); | |
784 | ||
785 | kfree(ct_fc_job); | |
786 | } | |
787 | ||
788 | int zfcp_fc_execute_ct_fc_job(struct fc_bsg_job *job) | |
789 | { | |
790 | int ret; | |
791 | u8 gs_type; | |
792 | struct fc_rport *rport = job->rport; | |
793 | struct Scsi_Host *shost; | |
794 | struct zfcp_adapter *adapter; | |
795 | struct zfcp_ct_fc_job *ct_fc_job; | |
796 | u32 preamble_word1; | |
797 | ||
798 | shost = rport ? rport_to_shost(rport) : job->shost; | |
799 | ||
800 | adapter = (struct zfcp_adapter *)shost->hostdata[0]; | |
801 | if (!(atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN)) | |
802 | return -EINVAL; | |
803 | ||
804 | ct_fc_job = kzalloc(sizeof(struct zfcp_ct_fc_job), GFP_KERNEL); | |
805 | if (!ct_fc_job) | |
806 | return -ENOMEM; | |
807 | ||
808 | preamble_word1 = job->request->rqst_data.r_ct.preamble_word1; | |
809 | gs_type = (preamble_word1 & 0xff000000) >> 24; | |
810 | ||
811 | switch (gs_type) { | |
812 | case FC_FST_ALIAS: | |
813 | ct_fc_job->ct.wka_port = &adapter->gs->as; | |
814 | break; | |
815 | case FC_FST_MGMT: | |
816 | ct_fc_job->ct.wka_port = &adapter->gs->ms; | |
817 | break; | |
818 | case FC_FST_TIME: | |
819 | ct_fc_job->ct.wka_port = &adapter->gs->ts; | |
820 | break; | |
821 | case FC_FST_DIR: | |
822 | ct_fc_job->ct.wka_port = &adapter->gs->ds; | |
823 | break; | |
824 | default: | |
825 | kfree(ct_fc_job); | |
826 | return -EINVAL; /* no such service */ | |
827 | } | |
828 | ||
829 | ret = zfcp_wka_port_get(ct_fc_job->ct.wka_port); | |
830 | if (ret) { | |
831 | kfree(ct_fc_job); | |
832 | return ret; | |
833 | } | |
834 | ||
835 | ct_fc_job->ct.req = job->request_payload.sg_list; | |
836 | ct_fc_job->ct.resp = job->reply_payload.sg_list; | |
837 | ct_fc_job->ct.timeout = ZFCP_FSF_REQUEST_TIMEOUT; | |
838 | ct_fc_job->ct.handler = zfcp_fc_generic_ct_handler; | |
839 | ct_fc_job->ct.handler_data = (unsigned long) ct_fc_job; | |
840 | ct_fc_job->ct.completion = NULL; | |
841 | ct_fc_job->job = job; | |
842 | ||
843 | ret = zfcp_fsf_send_ct(&ct_fc_job->ct, NULL, NULL); | |
844 | if (ret) { | |
845 | kfree(ct_fc_job); | |
846 | zfcp_wka_port_put(ct_fc_job->ct.wka_port); | |
847 | } | |
848 | return ret; | |
849 | } |