diff options
author | Christof Schmitt <christof.schmitt@de.ibm.com> | 2008-06-10 12:20:54 -0400 |
---|---|---|
committer | James Bottomley <James.Bottomley@HansenPartnership.com> | 2008-07-12 09:22:25 -0400 |
commit | 24073b475d6d2bad8880434a16343ee1da816ea5 (patch) | |
tree | 27cf64817f5aa9020692b88366a46743b11db6d3 /drivers/s390/scsi/zfcp_fc.c | |
parent | 6362abd3e00d3161affad996fa53cc69a01fc6d1 (diff) |
[SCSI] zfcp: Move FC code to new file
Move all Fibre Channel related code to new file and cleanup the code
while doing so.
Signed-off-by: Christof Schmitt <christof.schmitt@de.ibm.com>
Signed-off-by: Swen Schillig <swen@vnet.ibm.com>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Diffstat (limited to 'drivers/s390/scsi/zfcp_fc.c')
-rw-r--r-- | drivers/s390/scsi/zfcp_fc.c | 305 |
1 files changed, 305 insertions, 0 deletions
diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c new file mode 100644 index 000000000000..bb07c3bf2258 --- /dev/null +++ b/drivers/s390/scsi/zfcp_fc.c | |||
@@ -0,0 +1,305 @@ | |||
1 | /* | ||
2 | * zfcp device driver | ||
3 | * | ||
4 | * Fibre Channel related functions for the zfcp device driver. | ||
5 | * | ||
6 | * Copyright IBM Corporation 2008 | ||
7 | */ | ||
8 | |||
9 | #include "zfcp_ext.h" | ||
10 | |||
11 | static void _zfcp_fc_incoming_rscn(struct zfcp_fsf_req *fsf_req, u32 range, | ||
12 | struct fcp_rscn_element *elem) | ||
13 | { | ||
14 | unsigned long flags; | ||
15 | struct zfcp_port *port; | ||
16 | |||
17 | read_lock_irqsave(&zfcp_data.config_lock, flags); | ||
18 | list_for_each_entry(port, &fsf_req->adapter->port_list_head, list) { | ||
19 | if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status)) | ||
20 | continue; | ||
21 | /* FIXME: ZFCP_STATUS_PORT_DID_DID check is racy */ | ||
22 | if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) | ||
23 | /* Try to connect to unused ports anyway. */ | ||
24 | zfcp_erp_port_reopen(port, | ||
25 | ZFCP_STATUS_COMMON_ERP_FAILED, | ||
26 | 82, fsf_req); | ||
27 | else if ((port->d_id & range) == (elem->nport_did & range)) | ||
28 | /* Check connection status for connected ports */ | ||
29 | zfcp_test_link(port); | ||
30 | } | ||
31 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); | ||
32 | } | ||
33 | |||
34 | static void zfcp_fc_incoming_rscn(struct zfcp_fsf_req *fsf_req) | ||
35 | { | ||
36 | struct fsf_status_read_buffer *status_buffer = (void *)fsf_req->data; | ||
37 | struct fcp_rscn_head *fcp_rscn_head; | ||
38 | struct fcp_rscn_element *fcp_rscn_element; | ||
39 | u16 i; | ||
40 | u16 no_entries; | ||
41 | u32 range_mask; | ||
42 | |||
43 | fcp_rscn_head = (struct fcp_rscn_head *) status_buffer->payload; | ||
44 | fcp_rscn_element = (struct fcp_rscn_element *) status_buffer->payload; | ||
45 | |||
46 | /* see FC-FS */ | ||
47 | no_entries = fcp_rscn_head->payload_len / | ||
48 | sizeof(struct fcp_rscn_element); | ||
49 | |||
50 | for (i = 1; i < no_entries; i++) { | ||
51 | /* skip head and start with 1st element */ | ||
52 | fcp_rscn_element++; | ||
53 | switch (fcp_rscn_element->addr_format) { | ||
54 | case ZFCP_PORT_ADDRESS: | ||
55 | range_mask = ZFCP_PORTS_RANGE_PORT; | ||
56 | break; | ||
57 | case ZFCP_AREA_ADDRESS: | ||
58 | range_mask = ZFCP_PORTS_RANGE_AREA; | ||
59 | break; | ||
60 | case ZFCP_DOMAIN_ADDRESS: | ||
61 | range_mask = ZFCP_PORTS_RANGE_DOMAIN; | ||
62 | break; | ||
63 | case ZFCP_FABRIC_ADDRESS: | ||
64 | range_mask = ZFCP_PORTS_RANGE_FABRIC; | ||
65 | break; | ||
66 | default: | ||
67 | continue; | ||
68 | } | ||
69 | _zfcp_fc_incoming_rscn(fsf_req, range_mask, fcp_rscn_element); | ||
70 | } | ||
71 | } | ||
72 | |||
73 | static void zfcp_fc_incoming_wwpn(struct zfcp_fsf_req *req, wwn_t wwpn) | ||
74 | { | ||
75 | struct zfcp_adapter *adapter = req->adapter; | ||
76 | struct zfcp_port *port; | ||
77 | unsigned long flags; | ||
78 | |||
79 | read_lock_irqsave(&zfcp_data.config_lock, flags); | ||
80 | list_for_each_entry(port, &adapter->port_list_head, list) | ||
81 | if (port->wwpn == wwpn) | ||
82 | break; | ||
83 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); | ||
84 | |||
85 | if (port && (port->wwpn == wwpn)) | ||
86 | zfcp_erp_port_forced_reopen(port, 0, 83, req); | ||
87 | } | ||
88 | |||
89 | static void zfcp_fc_incoming_plogi(struct zfcp_fsf_req *req) | ||
90 | { | ||
91 | struct fsf_status_read_buffer *status_buffer = | ||
92 | (struct fsf_status_read_buffer *)req->data; | ||
93 | struct fsf_plogi *els_plogi = | ||
94 | (struct fsf_plogi *) status_buffer->payload; | ||
95 | |||
96 | zfcp_fc_incoming_wwpn(req, els_plogi->serv_param.wwpn); | ||
97 | } | ||
98 | |||
99 | static void zfcp_fc_incoming_logo(struct zfcp_fsf_req *req) | ||
100 | { | ||
101 | struct fsf_status_read_buffer *status_buffer = | ||
102 | (struct fsf_status_read_buffer *)req->data; | ||
103 | struct fcp_logo *els_logo = (struct fcp_logo *) status_buffer->payload; | ||
104 | |||
105 | zfcp_fc_incoming_wwpn(req, els_logo->nport_wwpn); | ||
106 | } | ||
107 | |||
108 | /** | ||
109 | * zfcp_fc_incoming_els - handle incoming ELS | ||
110 | * @fsf_req - request which contains incoming ELS | ||
111 | */ | ||
112 | void zfcp_fc_incoming_els(struct zfcp_fsf_req *fsf_req) | ||
113 | { | ||
114 | struct fsf_status_read_buffer *status_buffer = | ||
115 | (struct fsf_status_read_buffer *) fsf_req->data; | ||
116 | unsigned int els_type = status_buffer->payload[0]; | ||
117 | |||
118 | zfcp_san_dbf_event_incoming_els(fsf_req); | ||
119 | if (els_type == LS_PLOGI) | ||
120 | zfcp_fc_incoming_plogi(fsf_req); | ||
121 | else if (els_type == LS_LOGO) | ||
122 | zfcp_fc_incoming_logo(fsf_req); | ||
123 | else if (els_type == LS_RSCN) | ||
124 | zfcp_fc_incoming_rscn(fsf_req); | ||
125 | } | ||
126 | |||
127 | static void zfcp_ns_gid_pn_handler(unsigned long data) | ||
128 | { | ||
129 | struct zfcp_gid_pn_data *gid_pn = (struct zfcp_gid_pn_data *) data; | ||
130 | struct zfcp_send_ct *ct = &gid_pn->ct; | ||
131 | struct ct_iu_gid_pn_req *ct_iu_req = sg_virt(ct->req); | ||
132 | struct ct_iu_gid_pn_resp *ct_iu_resp = sg_virt(ct->resp); | ||
133 | struct zfcp_port *port = gid_pn->port; | ||
134 | |||
135 | if (ct->status) | ||
136 | goto out; | ||
137 | if (ct_iu_resp->header.cmd_rsp_code != ZFCP_CT_ACCEPT) { | ||
138 | atomic_set_mask(ZFCP_STATUS_PORT_INVALID_WWPN, &port->status); | ||
139 | goto out; | ||
140 | } | ||
141 | /* paranoia */ | ||
142 | if (ct_iu_req->wwpn != port->wwpn) | ||
143 | goto out; | ||
144 | /* looks like a valid d_id */ | ||
145 | port->d_id = ct_iu_resp->d_id & ZFCP_DID_MASK; | ||
146 | atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status); | ||
147 | out: | ||
148 | mempool_free(gid_pn, port->adapter->pool.data_gid_pn); | ||
149 | } | ||
150 | |||
151 | /** | ||
152 | * zfcp_fc_ns_gid_pn_request - initiate GID_PN nameserver request | ||
153 | * @erp_action: pointer to zfcp_erp_action where GID_PN request is needed | ||
154 | * return: -ENOMEM on error, 0 otherwise | ||
155 | */ | ||
156 | int zfcp_fc_ns_gid_pn_request(struct zfcp_erp_action *erp_action) | ||
157 | { | ||
158 | int ret; | ||
159 | struct zfcp_gid_pn_data *gid_pn; | ||
160 | struct zfcp_adapter *adapter = erp_action->adapter; | ||
161 | |||
162 | gid_pn = mempool_alloc(adapter->pool.data_gid_pn, GFP_ATOMIC); | ||
163 | if (!gid_pn) | ||
164 | return -ENOMEM; | ||
165 | |||
166 | memset(gid_pn, 0, sizeof(*gid_pn)); | ||
167 | |||
168 | /* setup parameters for send generic command */ | ||
169 | gid_pn->port = erp_action->port; | ||
170 | gid_pn->ct.port = adapter->nameserver_port; | ||
171 | gid_pn->ct.handler = zfcp_ns_gid_pn_handler; | ||
172 | gid_pn->ct.handler_data = (unsigned long) gid_pn; | ||
173 | gid_pn->ct.timeout = ZFCP_NS_GID_PN_TIMEOUT; | ||
174 | gid_pn->ct.req = &gid_pn->req; | ||
175 | gid_pn->ct.resp = &gid_pn->resp; | ||
176 | gid_pn->ct.req_count = 1; | ||
177 | gid_pn->ct.resp_count = 1; | ||
178 | sg_init_one(&gid_pn->req, &gid_pn->ct_iu_req, | ||
179 | sizeof(struct ct_iu_gid_pn_req)); | ||
180 | sg_init_one(&gid_pn->resp, &gid_pn->ct_iu_resp, | ||
181 | sizeof(struct ct_iu_gid_pn_resp)); | ||
182 | |||
183 | /* setup nameserver request */ | ||
184 | gid_pn->ct_iu_req.header.revision = ZFCP_CT_REVISION; | ||
185 | gid_pn->ct_iu_req.header.gs_type = ZFCP_CT_DIRECTORY_SERVICE; | ||
186 | gid_pn->ct_iu_req.header.gs_subtype = ZFCP_CT_NAME_SERVER; | ||
187 | gid_pn->ct_iu_req.header.options = ZFCP_CT_SYNCHRONOUS; | ||
188 | gid_pn->ct_iu_req.header.cmd_rsp_code = ZFCP_CT_GID_PN; | ||
189 | gid_pn->ct_iu_req.header.max_res_size = ZFCP_CT_MAX_SIZE; | ||
190 | gid_pn->ct_iu_req.wwpn = erp_action->port->wwpn; | ||
191 | |||
192 | ret = zfcp_fsf_send_ct(&gid_pn->ct, adapter->pool.fsf_req_erp, | ||
193 | erp_action); | ||
194 | if (ret) | ||
195 | mempool_free(gid_pn, adapter->pool.data_gid_pn); | ||
196 | return ret; | ||
197 | } | ||
198 | |||
199 | /** | ||
200 | * zfcp_fc_plogi_evaluate - evaluate PLOGI playload | ||
201 | * @port: zfcp_port structure | ||
202 | * @plogi: plogi payload | ||
203 | * | ||
204 | * Evaluate PLOGI playload and copy important fields into zfcp_port structure | ||
205 | */ | ||
206 | void zfcp_fc_plogi_evaluate(struct zfcp_port *port, struct fsf_plogi *plogi) | ||
207 | { | ||
208 | port->maxframe_size = plogi->serv_param.common_serv_param[7] | | ||
209 | ((plogi->serv_param.common_serv_param[6] & 0x0F) << 8); | ||
210 | if (plogi->serv_param.class1_serv_param[0] & 0x80) | ||
211 | port->supported_classes |= FC_COS_CLASS1; | ||
212 | if (plogi->serv_param.class2_serv_param[0] & 0x80) | ||
213 | port->supported_classes |= FC_COS_CLASS2; | ||
214 | if (plogi->serv_param.class3_serv_param[0] & 0x80) | ||
215 | port->supported_classes |= FC_COS_CLASS3; | ||
216 | if (plogi->serv_param.class4_serv_param[0] & 0x80) | ||
217 | port->supported_classes |= FC_COS_CLASS4; | ||
218 | } | ||
219 | |||
220 | struct zfcp_els_adisc { | ||
221 | struct zfcp_send_els els; | ||
222 | struct scatterlist req; | ||
223 | struct scatterlist resp; | ||
224 | struct zfcp_ls_adisc ls_adisc; | ||
225 | struct zfcp_ls_adisc_acc ls_adisc_acc; | ||
226 | }; | ||
227 | |||
228 | static void zfcp_fc_adisc_handler(unsigned long data) | ||
229 | { | ||
230 | struct zfcp_els_adisc *adisc = (struct zfcp_els_adisc *) data; | ||
231 | struct zfcp_port *port = adisc->els.port; | ||
232 | struct zfcp_ls_adisc_acc *ls_adisc = &adisc->ls_adisc_acc; | ||
233 | |||
234 | if (!adisc->els.status) { | ||
235 | /* request rejected or timed out */ | ||
236 | zfcp_erp_port_forced_reopen(port, 0, 63, NULL); | ||
237 | goto out; | ||
238 | } | ||
239 | |||
240 | if (!port->wwnn) | ||
241 | port->wwnn = ls_adisc->wwnn; | ||
242 | |||
243 | if (port->wwpn != ls_adisc->wwpn) | ||
244 | zfcp_erp_port_reopen(port, 0, 64, NULL); | ||
245 | |||
246 | out: | ||
247 | zfcp_port_put(port); | ||
248 | kfree(adisc); | ||
249 | } | ||
250 | |||
251 | static int zfcp_fc_adisc(struct zfcp_port *port) | ||
252 | { | ||
253 | struct zfcp_els_adisc *adisc; | ||
254 | struct zfcp_adapter *adapter = port->adapter; | ||
255 | |||
256 | adisc = kzalloc(sizeof(struct zfcp_els_adisc), GFP_ATOMIC); | ||
257 | if (!adisc) | ||
258 | return -ENOMEM; | ||
259 | |||
260 | adisc->els.req = &adisc->req; | ||
261 | adisc->els.resp = &adisc->resp; | ||
262 | sg_init_one(adisc->els.req, &adisc->ls_adisc, | ||
263 | sizeof(struct zfcp_ls_adisc)); | ||
264 | sg_init_one(adisc->els.resp, &adisc->ls_adisc_acc, | ||
265 | sizeof(struct zfcp_ls_adisc_acc)); | ||
266 | |||
267 | adisc->els.req_count = 1; | ||
268 | adisc->els.resp_count = 1; | ||
269 | adisc->els.adapter = adapter; | ||
270 | adisc->els.port = port; | ||
271 | adisc->els.d_id = port->d_id; | ||
272 | adisc->els.handler = zfcp_fc_adisc_handler; | ||
273 | adisc->els.handler_data = (unsigned long) adisc; | ||
274 | adisc->els.ls_code = adisc->ls_adisc.code = ZFCP_LS_ADISC; | ||
275 | |||
276 | /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports | ||
277 | without FC-AL-2 capability, so we don't set it */ | ||
278 | adisc->ls_adisc.wwpn = fc_host_port_name(adapter->scsi_host); | ||
279 | adisc->ls_adisc.wwnn = fc_host_node_name(adapter->scsi_host); | ||
280 | adisc->ls_adisc.nport_id = fc_host_port_id(adapter->scsi_host); | ||
281 | |||
282 | return zfcp_fsf_send_els(&adisc->els); | ||
283 | } | ||
284 | |||
285 | /** | ||
286 | * zfcp_test_link - lightweight link test procedure | ||
287 | * @port: port to be tested | ||
288 | * | ||
289 | * Test status of a link to a remote port using the ELS command ADISC. | ||
290 | * If there is a problem with the remote port, error recovery steps | ||
291 | * will be triggered. | ||
292 | */ | ||
293 | void zfcp_test_link(struct zfcp_port *port) | ||
294 | { | ||
295 | int retval; | ||
296 | |||
297 | zfcp_port_get(port); | ||
298 | retval = zfcp_fc_adisc(port); | ||
299 | if (retval == 0 || retval == -EBUSY) | ||
300 | return; | ||
301 | |||
302 | /* send of ADISC was not possible */ | ||
303 | zfcp_port_put(port); | ||
304 | zfcp_erp_port_forced_reopen(port, 0, 65, NULL); | ||
305 | } | ||