Commit | Line | Data |
---|---|---|
6e98016c GM |
1 | /* |
2 | * QLogic Fibre Channel HBA Driver | |
3 | * Copyright (c) 2003-2008 QLogic Corporation | |
4 | * | |
5 | * See LICENSE.qla2xxx for copyright and licensing details. | |
6 | */ | |
7 | #include "qla_def.h" | |
8 | ||
9 | #include <linux/kthread.h> | |
10 | #include <linux/vmalloc.h> | |
11 | #include <linux/delay.h> | |
12 | ||
13 | /* BSG support for ELS/CT pass through */ | |
14 | inline srb_t * | |
15 | qla2x00_get_ctx_bsg_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size) | |
16 | { | |
17 | srb_t *sp; | |
18 | struct qla_hw_data *ha = vha->hw; | |
4916392b | 19 | struct srb_ctx *ctx; |
6e98016c GM |
20 | |
21 | sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL); | |
22 | if (!sp) | |
23 | goto done; | |
24 | ctx = kzalloc(size, GFP_KERNEL); | |
25 | if (!ctx) { | |
26 | mempool_free(sp, ha->srb_mempool); | |
27 | sp = NULL; | |
28 | goto done; | |
29 | } | |
30 | ||
31 | memset(sp, 0, sizeof(*sp)); | |
32 | sp->fcport = fcport; | |
33 | sp->ctx = ctx; | |
34 | done: | |
35 | return sp; | |
36 | } | |
37 | ||
09ff701a SR |
38 | int |
39 | qla24xx_fcp_prio_cfg_valid(struct qla_fcp_prio_cfg *pri_cfg, uint8_t flag) | |
40 | { | |
41 | int i, ret, num_valid; | |
42 | uint8_t *bcode; | |
43 | struct qla_fcp_prio_entry *pri_entry; | |
44 | ||
45 | ret = 1; | |
46 | num_valid = 0; | |
47 | bcode = (uint8_t *)pri_cfg; | |
48 | ||
49 | if (bcode[0x0] != 'H' || bcode[0x1] != 'Q' || bcode[0x2] != 'O' || | |
50 | bcode[0x3] != 'S') { | |
51 | return 0; | |
52 | } | |
53 | if (flag != 1) | |
54 | return ret; | |
55 | ||
56 | pri_entry = &pri_cfg->entry[0]; | |
57 | for (i = 0; i < pri_cfg->num_entries; i++) { | |
58 | if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID) | |
59 | num_valid++; | |
60 | pri_entry++; | |
61 | } | |
62 | ||
63 | if (num_valid == 0) | |
64 | ret = 0; | |
65 | ||
66 | return ret; | |
67 | } | |
68 | ||
69 | static int | |
70 | qla24xx_proc_fcp_prio_cfg_cmd(struct fc_bsg_job *bsg_job) | |
71 | { | |
72 | struct Scsi_Host *host = bsg_job->shost; | |
73 | scsi_qla_host_t *vha = shost_priv(host); | |
74 | struct qla_hw_data *ha = vha->hw; | |
75 | int ret = 0; | |
76 | uint32_t len; | |
77 | uint32_t oper; | |
78 | ||
79 | bsg_job->reply->reply_payload_rcv_len = 0; | |
80 | ||
81 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) || | |
82 | test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) || | |
83 | test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) { | |
84 | ret = -EBUSY; | |
85 | goto exit_fcp_prio_cfg; | |
86 | } | |
87 | ||
88 | /* Get the sub command */ | |
89 | oper = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1]; | |
90 | ||
91 | /* Only set config is allowed if config memory is not allocated */ | |
92 | if (!ha->fcp_prio_cfg && (oper != QLFC_FCP_PRIO_SET_CONFIG)) { | |
93 | ret = -EINVAL; | |
94 | goto exit_fcp_prio_cfg; | |
95 | } | |
96 | switch (oper) { | |
97 | case QLFC_FCP_PRIO_DISABLE: | |
98 | if (ha->flags.fcp_prio_enabled) { | |
99 | ha->flags.fcp_prio_enabled = 0; | |
100 | ha->fcp_prio_cfg->attributes &= | |
101 | ~FCP_PRIO_ATTR_ENABLE; | |
102 | qla24xx_update_all_fcp_prio(vha); | |
103 | bsg_job->reply->result = DID_OK; | |
104 | } else { | |
105 | ret = -EINVAL; | |
106 | bsg_job->reply->result = (DID_ERROR << 16); | |
107 | goto exit_fcp_prio_cfg; | |
108 | } | |
109 | break; | |
110 | ||
111 | case QLFC_FCP_PRIO_ENABLE: | |
112 | if (!ha->flags.fcp_prio_enabled) { | |
113 | if (ha->fcp_prio_cfg) { | |
114 | ha->flags.fcp_prio_enabled = 1; | |
115 | ha->fcp_prio_cfg->attributes |= | |
116 | FCP_PRIO_ATTR_ENABLE; | |
117 | qla24xx_update_all_fcp_prio(vha); | |
118 | bsg_job->reply->result = DID_OK; | |
119 | } else { | |
120 | ret = -EINVAL; | |
121 | bsg_job->reply->result = (DID_ERROR << 16); | |
122 | goto exit_fcp_prio_cfg; | |
123 | } | |
124 | } | |
125 | break; | |
126 | ||
127 | case QLFC_FCP_PRIO_GET_CONFIG: | |
128 | len = bsg_job->reply_payload.payload_len; | |
129 | if (!len || len > FCP_PRIO_CFG_SIZE) { | |
130 | ret = -EINVAL; | |
131 | bsg_job->reply->result = (DID_ERROR << 16); | |
132 | goto exit_fcp_prio_cfg; | |
133 | } | |
134 | ||
135 | bsg_job->reply->result = DID_OK; | |
136 | bsg_job->reply->reply_payload_rcv_len = | |
137 | sg_copy_from_buffer( | |
138 | bsg_job->reply_payload.sg_list, | |
139 | bsg_job->reply_payload.sg_cnt, ha->fcp_prio_cfg, | |
140 | len); | |
141 | ||
142 | break; | |
143 | ||
144 | case QLFC_FCP_PRIO_SET_CONFIG: | |
145 | len = bsg_job->request_payload.payload_len; | |
146 | if (!len || len > FCP_PRIO_CFG_SIZE) { | |
147 | bsg_job->reply->result = (DID_ERROR << 16); | |
148 | ret = -EINVAL; | |
149 | goto exit_fcp_prio_cfg; | |
150 | } | |
151 | ||
152 | if (!ha->fcp_prio_cfg) { | |
153 | ha->fcp_prio_cfg = vmalloc(FCP_PRIO_CFG_SIZE); | |
154 | if (!ha->fcp_prio_cfg) { | |
155 | qla_printk(KERN_WARNING, ha, | |
156 | "Unable to allocate memory " | |
157 | "for fcp prio config data (%x).\n", | |
158 | FCP_PRIO_CFG_SIZE); | |
159 | bsg_job->reply->result = (DID_ERROR << 16); | |
160 | ret = -ENOMEM; | |
161 | goto exit_fcp_prio_cfg; | |
162 | } | |
163 | } | |
164 | ||
165 | memset(ha->fcp_prio_cfg, 0, FCP_PRIO_CFG_SIZE); | |
166 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, | |
167 | bsg_job->request_payload.sg_cnt, ha->fcp_prio_cfg, | |
168 | FCP_PRIO_CFG_SIZE); | |
169 | ||
170 | /* validate fcp priority data */ | |
171 | if (!qla24xx_fcp_prio_cfg_valid( | |
172 | (struct qla_fcp_prio_cfg *) | |
173 | ha->fcp_prio_cfg, 1)) { | |
174 | bsg_job->reply->result = (DID_ERROR << 16); | |
175 | ret = -EINVAL; | |
176 | /* If buffer was invalidatic int | |
177 | * fcp_prio_cfg is of no use | |
178 | */ | |
179 | vfree(ha->fcp_prio_cfg); | |
180 | ha->fcp_prio_cfg = NULL; | |
181 | goto exit_fcp_prio_cfg; | |
182 | } | |
183 | ||
184 | ha->flags.fcp_prio_enabled = 0; | |
185 | if (ha->fcp_prio_cfg->attributes & FCP_PRIO_ATTR_ENABLE) | |
186 | ha->flags.fcp_prio_enabled = 1; | |
187 | qla24xx_update_all_fcp_prio(vha); | |
188 | bsg_job->reply->result = DID_OK; | |
189 | break; | |
190 | default: | |
191 | ret = -EINVAL; | |
192 | break; | |
193 | } | |
194 | exit_fcp_prio_cfg: | |
195 | bsg_job->job_done(bsg_job); | |
196 | return ret; | |
197 | } | |
6e98016c GM |
198 | static int |
199 | qla2x00_process_els(struct fc_bsg_job *bsg_job) | |
200 | { | |
201 | struct fc_rport *rport; | |
202 | fc_port_t *fcport; | |
203 | struct Scsi_Host *host; | |
204 | scsi_qla_host_t *vha; | |
205 | struct qla_hw_data *ha; | |
206 | srb_t *sp; | |
207 | const char *type; | |
208 | int req_sg_cnt, rsp_sg_cnt; | |
209 | int rval = (DRIVER_ERROR << 16); | |
210 | uint16_t nextlid = 0; | |
4916392b | 211 | struct srb_ctx *els; |
6e98016c GM |
212 | |
213 | /* Multiple SG's are not supported for ELS requests */ | |
214 | if (bsg_job->request_payload.sg_cnt > 1 || | |
215 | bsg_job->reply_payload.sg_cnt > 1) { | |
216 | DEBUG2(printk(KERN_INFO | |
217 | "multiple SG's are not supported for ELS requests" | |
218 | " [request_sg_cnt: %x reply_sg_cnt: %x]\n", | |
219 | bsg_job->request_payload.sg_cnt, | |
220 | bsg_job->reply_payload.sg_cnt)); | |
221 | rval = -EPERM; | |
222 | goto done; | |
223 | } | |
224 | ||
225 | /* ELS request for rport */ | |
226 | if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) { | |
227 | rport = bsg_job->rport; | |
228 | fcport = *(fc_port_t **) rport->dd_data; | |
229 | host = rport_to_shost(rport); | |
230 | vha = shost_priv(host); | |
231 | ha = vha->hw; | |
232 | type = "FC_BSG_RPT_ELS"; | |
233 | ||
234 | /* make sure the rport is logged in, | |
235 | * if not perform fabric login | |
236 | */ | |
237 | if (qla2x00_fabric_login(vha, fcport, &nextlid)) { | |
238 | DEBUG2(qla_printk(KERN_WARNING, ha, | |
239 | "failed to login port %06X for ELS passthru\n", | |
240 | fcport->d_id.b24)); | |
241 | rval = -EIO; | |
242 | goto done; | |
243 | } | |
244 | } else { | |
245 | host = bsg_job->shost; | |
246 | vha = shost_priv(host); | |
247 | ha = vha->hw; | |
248 | type = "FC_BSG_HST_ELS_NOLOGIN"; | |
249 | ||
250 | /* Allocate a dummy fcport structure, since functions | |
251 | * preparing the IOCB and mailbox command retrieves port | |
252 | * specific information from fcport structure. For Host based | |
253 | * ELS commands there will be no fcport structure allocated | |
254 | */ | |
255 | fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); | |
256 | if (!fcport) { | |
257 | rval = -ENOMEM; | |
258 | goto done; | |
259 | } | |
260 | ||
261 | /* Initialize all required fields of fcport */ | |
262 | fcport->vha = vha; | |
263 | fcport->vp_idx = vha->vp_idx; | |
264 | fcport->d_id.b.al_pa = | |
265 | bsg_job->request->rqst_data.h_els.port_id[0]; | |
266 | fcport->d_id.b.area = | |
267 | bsg_job->request->rqst_data.h_els.port_id[1]; | |
268 | fcport->d_id.b.domain = | |
269 | bsg_job->request->rqst_data.h_els.port_id[2]; | |
270 | fcport->loop_id = | |
271 | (fcport->d_id.b.al_pa == 0xFD) ? | |
272 | NPH_FABRIC_CONTROLLER : NPH_F_PORT; | |
273 | } | |
274 | ||
275 | if (!vha->flags.online) { | |
276 | DEBUG2(qla_printk(KERN_WARNING, ha, | |
6c452a45 | 277 | "host not online\n")); |
6e98016c GM |
278 | rval = -EIO; |
279 | goto done; | |
280 | } | |
281 | ||
282 | req_sg_cnt = | |
283 | dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, | |
284 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
285 | if (!req_sg_cnt) { | |
286 | rval = -ENOMEM; | |
287 | goto done_free_fcport; | |
288 | } | |
6c452a45 AV |
289 | |
290 | rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list, | |
291 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
6e98016c GM |
292 | if (!rsp_sg_cnt) { |
293 | rval = -ENOMEM; | |
294 | goto done_free_fcport; | |
295 | } | |
296 | ||
297 | if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) || | |
6c452a45 | 298 | (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) { |
6e98016c GM |
299 | DEBUG2(printk(KERN_INFO |
300 | "dma mapping resulted in different sg counts \ | |
301 | [request_sg_cnt: %x dma_request_sg_cnt: %x\ | |
302 | reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n", | |
303 | bsg_job->request_payload.sg_cnt, req_sg_cnt, | |
304 | bsg_job->reply_payload.sg_cnt, rsp_sg_cnt)); | |
305 | rval = -EAGAIN; | |
306 | goto done_unmap_sg; | |
307 | } | |
308 | ||
309 | /* Alloc SRB structure */ | |
4916392b | 310 | sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_ctx)); |
6e98016c GM |
311 | if (!sp) { |
312 | rval = -ENOMEM; | |
6c452a45 | 313 | goto done_unmap_sg; |
6e98016c GM |
314 | } |
315 | ||
316 | els = sp->ctx; | |
4916392b | 317 | els->type = |
6e98016c GM |
318 | (bsg_job->request->msgcode == FC_BSG_RPT_ELS ? |
319 | SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST); | |
3822263e MI |
320 | els->name = |
321 | (bsg_job->request->msgcode == FC_BSG_RPT_ELS ? | |
322 | "bsg_els_rpt" : "bsg_els_hst"); | |
4916392b | 323 | els->u.bsg_job = bsg_job; |
6e98016c GM |
324 | |
325 | DEBUG2(qla_printk(KERN_INFO, ha, | |
326 | "scsi(%ld:%x): bsg rqst type: %s els type: %x - loop-id=%x " | |
327 | "portid=%02x%02x%02x.\n", vha->host_no, sp->handle, type, | |
328 | bsg_job->request->rqst_data.h_els.command_code, | |
329 | fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area, | |
330 | fcport->d_id.b.al_pa)); | |
331 | ||
332 | rval = qla2x00_start_sp(sp); | |
333 | if (rval != QLA_SUCCESS) { | |
334 | kfree(sp->ctx); | |
335 | mempool_free(sp, ha->srb_mempool); | |
336 | rval = -EIO; | |
337 | goto done_unmap_sg; | |
338 | } | |
339 | return rval; | |
340 | ||
341 | done_unmap_sg: | |
342 | dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, | |
343 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
344 | dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list, | |
345 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
346 | goto done_free_fcport; | |
347 | ||
348 | done_free_fcport: | |
349 | if (bsg_job->request->msgcode == FC_BSG_HST_ELS_NOLOGIN) | |
350 | kfree(fcport); | |
351 | done: | |
352 | return rval; | |
353 | } | |
354 | ||
355 | static int | |
356 | qla2x00_process_ct(struct fc_bsg_job *bsg_job) | |
357 | { | |
358 | srb_t *sp; | |
359 | struct Scsi_Host *host = bsg_job->shost; | |
360 | scsi_qla_host_t *vha = shost_priv(host); | |
361 | struct qla_hw_data *ha = vha->hw; | |
362 | int rval = (DRIVER_ERROR << 16); | |
363 | int req_sg_cnt, rsp_sg_cnt; | |
364 | uint16_t loop_id; | |
365 | struct fc_port *fcport; | |
366 | char *type = "FC_BSG_HST_CT"; | |
4916392b | 367 | struct srb_ctx *ct; |
6e98016c GM |
368 | |
369 | /* pass through is supported only for ISP 4Gb or higher */ | |
6c452a45 | 370 | if (!IS_FWI2_CAPABLE(ha)) { |
6e98016c | 371 | DEBUG2(qla_printk(KERN_INFO, ha, |
6c452a45 AV |
372 | "scsi(%ld):Firmware is not capable to support FC " |
373 | "CT pass thru\n", vha->host_no)); | |
6e98016c GM |
374 | rval = -EPERM; |
375 | goto done; | |
376 | } | |
377 | ||
378 | req_sg_cnt = | |
379 | dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, | |
380 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
6c452a45 | 381 | if (!req_sg_cnt) { |
6e98016c GM |
382 | rval = -ENOMEM; |
383 | goto done; | |
384 | } | |
385 | ||
386 | rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list, | |
387 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
388 | if (!rsp_sg_cnt) { | |
389 | rval = -ENOMEM; | |
390 | goto done; | |
391 | } | |
392 | ||
393 | if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) || | |
6c452a45 | 394 | (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) { |
6e98016c | 395 | DEBUG2(qla_printk(KERN_WARNING, ha, |
6c452a45 AV |
396 | "[request_sg_cnt: %x dma_request_sg_cnt: %x\ |
397 | reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n", | |
398 | bsg_job->request_payload.sg_cnt, req_sg_cnt, | |
399 | bsg_job->reply_payload.sg_cnt, rsp_sg_cnt)); | |
6e98016c | 400 | rval = -EAGAIN; |
6c452a45 | 401 | goto done_unmap_sg; |
6e98016c GM |
402 | } |
403 | ||
404 | if (!vha->flags.online) { | |
405 | DEBUG2(qla_printk(KERN_WARNING, ha, | |
406 | "host not online\n")); | |
407 | rval = -EIO; | |
408 | goto done_unmap_sg; | |
409 | } | |
410 | ||
411 | loop_id = | |
412 | (bsg_job->request->rqst_data.h_ct.preamble_word1 & 0xFF000000) | |
413 | >> 24; | |
414 | switch (loop_id) { | |
6c452a45 AV |
415 | case 0xFC: |
416 | loop_id = cpu_to_le16(NPH_SNS); | |
417 | break; | |
418 | case 0xFA: | |
419 | loop_id = vha->mgmt_svr_loop_id; | |
420 | break; | |
421 | default: | |
422 | DEBUG2(qla_printk(KERN_INFO, ha, | |
423 | "Unknown loop id: %x\n", loop_id)); | |
424 | rval = -EINVAL; | |
425 | goto done_unmap_sg; | |
6e98016c GM |
426 | } |
427 | ||
428 | /* Allocate a dummy fcport structure, since functions preparing the | |
429 | * IOCB and mailbox command retrieves port specific information | |
430 | * from fcport structure. For Host based ELS commands there will be | |
431 | * no fcport structure allocated | |
432 | */ | |
433 | fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); | |
6c452a45 | 434 | if (!fcport) { |
6e98016c | 435 | rval = -ENOMEM; |
6c452a45 | 436 | goto done_unmap_sg; |
6e98016c GM |
437 | } |
438 | ||
439 | /* Initialize all required fields of fcport */ | |
440 | fcport->vha = vha; | |
441 | fcport->vp_idx = vha->vp_idx; | |
442 | fcport->d_id.b.al_pa = bsg_job->request->rqst_data.h_ct.port_id[0]; | |
443 | fcport->d_id.b.area = bsg_job->request->rqst_data.h_ct.port_id[1]; | |
444 | fcport->d_id.b.domain = bsg_job->request->rqst_data.h_ct.port_id[2]; | |
445 | fcport->loop_id = loop_id; | |
446 | ||
447 | /* Alloc SRB structure */ | |
4916392b | 448 | sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_ctx)); |
6e98016c GM |
449 | if (!sp) { |
450 | rval = -ENOMEM; | |
451 | goto done_free_fcport; | |
452 | } | |
453 | ||
454 | ct = sp->ctx; | |
4916392b | 455 | ct->type = SRB_CT_CMD; |
3822263e | 456 | ct->name = "bsg_ct"; |
4916392b | 457 | ct->u.bsg_job = bsg_job; |
6e98016c GM |
458 | |
459 | DEBUG2(qla_printk(KERN_INFO, ha, | |
460 | "scsi(%ld:%x): bsg rqst type: %s els type: %x - loop-id=%x " | |
461 | "portid=%02x%02x%02x.\n", vha->host_no, sp->handle, type, | |
462 | (bsg_job->request->rqst_data.h_ct.preamble_word2 >> 16), | |
463 | fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area, | |
464 | fcport->d_id.b.al_pa)); | |
465 | ||
466 | rval = qla2x00_start_sp(sp); | |
467 | if (rval != QLA_SUCCESS) { | |
468 | kfree(sp->ctx); | |
469 | mempool_free(sp, ha->srb_mempool); | |
470 | rval = -EIO; | |
471 | goto done_free_fcport; | |
472 | } | |
473 | return rval; | |
474 | ||
475 | done_free_fcport: | |
476 | kfree(fcport); | |
477 | done_unmap_sg: | |
478 | dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, | |
479 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
480 | dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list, | |
481 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
482 | done: | |
483 | return rval; | |
484 | } | |
485 | ||
23f2ebd1 SR |
486 | /* Set the port configuration to enable the |
487 | * internal loopback on ISP81XX | |
488 | */ | |
489 | static inline int | |
490 | qla81xx_set_internal_loopback(scsi_qla_host_t *vha, uint16_t *config, | |
491 | uint16_t *new_config) | |
492 | { | |
493 | int ret = 0; | |
494 | int rval = 0; | |
495 | struct qla_hw_data *ha = vha->hw; | |
496 | ||
497 | if (!IS_QLA81XX(ha)) | |
498 | goto done_set_internal; | |
499 | ||
500 | new_config[0] = config[0] | (ENABLE_INTERNAL_LOOPBACK << 1); | |
501 | memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ; | |
502 | ||
503 | ha->notify_dcbx_comp = 1; | |
504 | ret = qla81xx_set_port_config(vha, new_config); | |
505 | if (ret != QLA_SUCCESS) { | |
506 | DEBUG2(printk(KERN_ERR | |
507 | "%s(%lu): Set port config failed\n", | |
508 | __func__, vha->host_no)); | |
509 | ha->notify_dcbx_comp = 0; | |
510 | rval = -EINVAL; | |
511 | goto done_set_internal; | |
512 | } | |
513 | ||
514 | /* Wait for DCBX complete event */ | |
515 | if (!wait_for_completion_timeout(&ha->dcbx_comp, (20 * HZ))) { | |
516 | DEBUG2(qla_printk(KERN_WARNING, ha, | |
517 | "State change notificaition not received.\n")); | |
518 | } else | |
519 | DEBUG2(qla_printk(KERN_INFO, ha, | |
520 | "State change RECEIVED\n")); | |
521 | ||
522 | ha->notify_dcbx_comp = 0; | |
523 | ||
524 | done_set_internal: | |
525 | return rval; | |
526 | } | |
527 | ||
528 | /* Set the port configuration to disable the | |
529 | * internal loopback on ISP81XX | |
530 | */ | |
531 | static inline int | |
532 | qla81xx_reset_internal_loopback(scsi_qla_host_t *vha, uint16_t *config, | |
533 | int wait) | |
534 | { | |
535 | int ret = 0; | |
536 | int rval = 0; | |
537 | uint16_t new_config[4]; | |
538 | struct qla_hw_data *ha = vha->hw; | |
539 | ||
540 | if (!IS_QLA81XX(ha)) | |
541 | goto done_reset_internal; | |
542 | ||
543 | memset(new_config, 0 , sizeof(new_config)); | |
544 | if ((config[0] & INTERNAL_LOOPBACK_MASK) >> 1 == | |
545 | ENABLE_INTERNAL_LOOPBACK) { | |
546 | new_config[0] = config[0] & ~INTERNAL_LOOPBACK_MASK; | |
547 | memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ; | |
548 | ||
549 | ha->notify_dcbx_comp = wait; | |
550 | ret = qla81xx_set_port_config(vha, new_config); | |
551 | if (ret != QLA_SUCCESS) { | |
552 | DEBUG2(printk(KERN_ERR | |
553 | "%s(%lu): Set port config failed\n", | |
554 | __func__, vha->host_no)); | |
555 | ha->notify_dcbx_comp = 0; | |
556 | rval = -EINVAL; | |
557 | goto done_reset_internal; | |
558 | } | |
559 | ||
560 | /* Wait for DCBX complete event */ | |
561 | if (wait && !wait_for_completion_timeout(&ha->dcbx_comp, | |
562 | (20 * HZ))) { | |
563 | DEBUG2(qla_printk(KERN_WARNING, ha, | |
564 | "State change notificaition not received.\n")); | |
565 | ha->notify_dcbx_comp = 0; | |
566 | rval = -EINVAL; | |
567 | goto done_reset_internal; | |
568 | } else | |
569 | DEBUG2(qla_printk(KERN_INFO, ha, | |
570 | "State change RECEIVED\n")); | |
571 | ||
572 | ha->notify_dcbx_comp = 0; | |
573 | } | |
574 | done_reset_internal: | |
575 | return rval; | |
576 | } | |
577 | ||
6e98016c GM |
578 | static int |
579 | qla2x00_process_loopback(struct fc_bsg_job *bsg_job) | |
580 | { | |
581 | struct Scsi_Host *host = bsg_job->shost; | |
582 | scsi_qla_host_t *vha = shost_priv(host); | |
583 | struct qla_hw_data *ha = vha->hw; | |
584 | int rval; | |
585 | uint8_t command_sent; | |
586 | char *type; | |
587 | struct msg_echo_lb elreq; | |
588 | uint16_t response[MAILBOX_REGISTER_COUNT]; | |
23f2ebd1 | 589 | uint16_t config[4], new_config[4]; |
6c452a45 | 590 | uint8_t *fw_sts_ptr; |
6e98016c GM |
591 | uint8_t *req_data = NULL; |
592 | dma_addr_t req_data_dma; | |
593 | uint32_t req_data_len; | |
594 | uint8_t *rsp_data = NULL; | |
595 | dma_addr_t rsp_data_dma; | |
596 | uint32_t rsp_data_len; | |
597 | ||
598 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) || | |
599 | test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) || | |
600 | test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) | |
601 | return -EBUSY; | |
602 | ||
603 | if (!vha->flags.online) { | |
604 | DEBUG2(qla_printk(KERN_WARNING, ha, "host not online\n")); | |
605 | return -EIO; | |
606 | } | |
607 | ||
608 | elreq.req_sg_cnt = dma_map_sg(&ha->pdev->dev, | |
609 | bsg_job->request_payload.sg_list, bsg_job->request_payload.sg_cnt, | |
610 | DMA_TO_DEVICE); | |
611 | ||
612 | if (!elreq.req_sg_cnt) | |
613 | return -ENOMEM; | |
614 | ||
615 | elreq.rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, | |
616 | bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt, | |
617 | DMA_FROM_DEVICE); | |
618 | ||
619 | if (!elreq.rsp_sg_cnt) { | |
620 | rval = -ENOMEM; | |
621 | goto done_unmap_req_sg; | |
6c452a45 | 622 | } |
6e98016c GM |
623 | |
624 | if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) || | |
625 | (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) { | |
626 | DEBUG2(printk(KERN_INFO | |
627 | "dma mapping resulted in different sg counts " | |
628 | "[request_sg_cnt: %x dma_request_sg_cnt: %x " | |
629 | "reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n", | |
630 | bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt, | |
631 | bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt)); | |
632 | rval = -EAGAIN; | |
633 | goto done_unmap_sg; | |
634 | } | |
635 | req_data_len = rsp_data_len = bsg_job->request_payload.payload_len; | |
636 | req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len, | |
637 | &req_data_dma, GFP_KERNEL); | |
638 | if (!req_data) { | |
639 | DEBUG2(printk(KERN_ERR "%s: dma alloc for req_data " | |
640 | "failed for host=%lu\n", __func__, vha->host_no)); | |
641 | rval = -ENOMEM; | |
642 | goto done_unmap_sg; | |
643 | } | |
644 | ||
645 | rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len, | |
646 | &rsp_data_dma, GFP_KERNEL); | |
647 | if (!rsp_data) { | |
648 | DEBUG2(printk(KERN_ERR "%s: dma alloc for rsp_data " | |
649 | "failed for host=%lu\n", __func__, vha->host_no)); | |
650 | rval = -ENOMEM; | |
651 | goto done_free_dma_req; | |
652 | } | |
653 | ||
654 | /* Copy the request buffer in req_data now */ | |
655 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, | |
656 | bsg_job->request_payload.sg_cnt, req_data, req_data_len); | |
657 | ||
658 | elreq.send_dma = req_data_dma; | |
659 | elreq.rcv_dma = rsp_data_dma; | |
660 | elreq.transfer_size = req_data_len; | |
661 | ||
662 | elreq.options = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1]; | |
663 | ||
23f2ebd1 SR |
664 | if ((ha->current_topology == ISP_CFG_F || |
665 | (IS_QLA81XX(ha) && | |
666 | le32_to_cpu(*(uint32_t *)req_data) == ELS_OPCODE_BYTE | |
667 | && req_data_len == MAX_ELS_FRAME_PAYLOAD)) && | |
668 | elreq.options == EXTERNAL_LOOPBACK) { | |
669 | type = "FC_BSG_HST_VENDOR_ECHO_DIAG"; | |
6e98016c | 670 | DEBUG2(qla_printk(KERN_INFO, ha, |
23f2ebd1 SR |
671 | "scsi(%ld) bsg rqst type: %s\n", vha->host_no, type)); |
672 | command_sent = INT_DEF_LB_ECHO_CMD; | |
673 | rval = qla2x00_echo_test(vha, &elreq, response); | |
674 | } else { | |
6e98016c | 675 | if (IS_QLA81XX(ha)) { |
23f2ebd1 SR |
676 | memset(config, 0, sizeof(config)); |
677 | memset(new_config, 0, sizeof(new_config)); | |
678 | if (qla81xx_get_port_config(vha, config)) { | |
679 | DEBUG2(printk(KERN_ERR | |
680 | "%s(%lu): Get port config failed\n", | |
681 | __func__, vha->host_no)); | |
682 | bsg_job->reply->reply_payload_rcv_len = 0; | |
683 | bsg_job->reply->result = (DID_ERROR << 16); | |
684 | rval = -EPERM; | |
685 | goto done_free_dma_req; | |
686 | } | |
687 | ||
688 | if (elreq.options != EXTERNAL_LOOPBACK) { | |
689 | DEBUG2(qla_printk(KERN_INFO, ha, | |
690 | "Internal: current port config = %x\n", | |
691 | config[0])); | |
692 | if (qla81xx_set_internal_loopback(vha, config, | |
693 | new_config)) { | |
694 | bsg_job->reply->reply_payload_rcv_len = | |
695 | 0; | |
696 | bsg_job->reply->result = | |
697 | (DID_ERROR << 16); | |
698 | rval = -EPERM; | |
699 | goto done_free_dma_req; | |
700 | } | |
701 | } else { | |
702 | /* For external loopback to work | |
703 | * ensure internal loopback is disabled | |
704 | */ | |
705 | if (qla81xx_reset_internal_loopback(vha, | |
706 | config, 1)) { | |
707 | bsg_job->reply->reply_payload_rcv_len = | |
708 | 0; | |
709 | bsg_job->reply->result = | |
710 | (DID_ERROR << 16); | |
711 | rval = -EPERM; | |
712 | goto done_free_dma_req; | |
713 | } | |
714 | } | |
715 | ||
716 | type = "FC_BSG_HST_VENDOR_LOOPBACK"; | |
717 | DEBUG2(qla_printk(KERN_INFO, ha, | |
718 | "scsi(%ld) bsg rqst type: %s\n", | |
719 | vha->host_no, type)); | |
720 | ||
721 | command_sent = INT_DEF_LB_LOOPBACK_CMD; | |
722 | rval = qla2x00_loopback_test(vha, &elreq, response); | |
723 | ||
724 | if (new_config[1]) { | |
725 | /* Revert back to original port config | |
726 | * Also clear internal loopback | |
727 | */ | |
728 | qla81xx_reset_internal_loopback(vha, | |
729 | new_config, 0); | |
730 | } | |
731 | ||
6e98016c | 732 | if (response[0] == MBS_COMMAND_ERROR && |
23f2ebd1 | 733 | response[1] == MBS_LB_RESET) { |
6e98016c | 734 | DEBUG2(printk(KERN_ERR "%s(%ld): ABORTing " |
23f2ebd1 | 735 | "ISP\n", __func__, vha->host_no)); |
6e98016c GM |
736 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
737 | qla2xxx_wake_dpc(vha); | |
23f2ebd1 SR |
738 | qla2x00_wait_for_chip_reset(vha); |
739 | /* Also reset the MPI */ | |
740 | if (qla81xx_restart_mpi_firmware(vha) != | |
741 | QLA_SUCCESS) { | |
742 | qla_printk(KERN_INFO, ha, | |
743 | "MPI reset failed for host%ld.\n", | |
744 | vha->host_no); | |
745 | } | |
746 | ||
747 | bsg_job->reply->reply_payload_rcv_len = 0; | |
748 | bsg_job->reply->result = (DID_ERROR << 16); | |
749 | rval = -EIO; | |
750 | goto done_free_dma_req; | |
6e98016c | 751 | } |
23f2ebd1 SR |
752 | } else { |
753 | type = "FC_BSG_HST_VENDOR_LOOPBACK"; | |
754 | DEBUG2(qla_printk(KERN_INFO, ha, | |
755 | "scsi(%ld) bsg rqst type: %s\n", | |
756 | vha->host_no, type)); | |
757 | command_sent = INT_DEF_LB_LOOPBACK_CMD; | |
758 | rval = qla2x00_loopback_test(vha, &elreq, response); | |
6e98016c | 759 | } |
6e98016c GM |
760 | } |
761 | ||
762 | if (rval) { | |
763 | DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor " | |
6c452a45 | 764 | "request %s failed\n", vha->host_no, type)); |
6e98016c GM |
765 | |
766 | fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) + | |
6c452a45 | 767 | sizeof(struct fc_bsg_reply); |
6e98016c GM |
768 | |
769 | memcpy(fw_sts_ptr, response, sizeof(response)); | |
770 | fw_sts_ptr += sizeof(response); | |
6c452a45 | 771 | *fw_sts_ptr = command_sent; |
6e98016c GM |
772 | rval = 0; |
773 | bsg_job->reply->reply_payload_rcv_len = 0; | |
774 | bsg_job->reply->result = (DID_ERROR << 16); | |
775 | } else { | |
776 | DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor " | |
777 | "request %s completed\n", vha->host_no, type)); | |
778 | ||
779 | bsg_job->reply_len = sizeof(struct fc_bsg_reply) + | |
780 | sizeof(response) + sizeof(uint8_t); | |
781 | bsg_job->reply->reply_payload_rcv_len = | |
782 | bsg_job->reply_payload.payload_len; | |
783 | fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) + | |
784 | sizeof(struct fc_bsg_reply); | |
785 | memcpy(fw_sts_ptr, response, sizeof(response)); | |
786 | fw_sts_ptr += sizeof(response); | |
787 | *fw_sts_ptr = command_sent; | |
788 | bsg_job->reply->result = DID_OK; | |
789 | sg_copy_from_buffer(bsg_job->reply_payload.sg_list, | |
790 | bsg_job->reply_payload.sg_cnt, rsp_data, | |
791 | rsp_data_len); | |
792 | } | |
793 | bsg_job->job_done(bsg_job); | |
794 | ||
795 | dma_free_coherent(&ha->pdev->dev, rsp_data_len, | |
796 | rsp_data, rsp_data_dma); | |
797 | done_free_dma_req: | |
798 | dma_free_coherent(&ha->pdev->dev, req_data_len, | |
799 | req_data, req_data_dma); | |
800 | done_unmap_sg: | |
801 | dma_unmap_sg(&ha->pdev->dev, | |
802 | bsg_job->reply_payload.sg_list, | |
803 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
804 | done_unmap_req_sg: | |
805 | dma_unmap_sg(&ha->pdev->dev, | |
806 | bsg_job->request_payload.sg_list, | |
807 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
6c452a45 | 808 | return rval; |
6e98016c GM |
809 | } |
810 | ||
811 | static int | |
812 | qla84xx_reset(struct fc_bsg_job *bsg_job) | |
813 | { | |
814 | struct Scsi_Host *host = bsg_job->shost; | |
815 | scsi_qla_host_t *vha = shost_priv(host); | |
816 | struct qla_hw_data *ha = vha->hw; | |
817 | int rval = 0; | |
818 | uint32_t flag; | |
819 | ||
820 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) || | |
821 | test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) || | |
822 | test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) | |
823 | return -EBUSY; | |
824 | ||
825 | if (!IS_QLA84XX(ha)) { | |
826 | DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld): Not 84xx, " | |
827 | "exiting.\n", vha->host_no)); | |
828 | return -EINVAL; | |
829 | } | |
830 | ||
831 | flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1]; | |
832 | ||
833 | rval = qla84xx_reset_chip(vha, flag == A84_ISSUE_RESET_DIAG_FW); | |
834 | ||
835 | if (rval) { | |
836 | DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor " | |
837 | "request 84xx reset failed\n", vha->host_no)); | |
838 | rval = bsg_job->reply->reply_payload_rcv_len = 0; | |
839 | bsg_job->reply->result = (DID_ERROR << 16); | |
840 | ||
841 | } else { | |
842 | DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor " | |
843 | "request 84xx reset completed\n", vha->host_no)); | |
844 | bsg_job->reply->result = DID_OK; | |
845 | } | |
846 | ||
847 | bsg_job->job_done(bsg_job); | |
848 | return rval; | |
849 | } | |
850 | ||
851 | static int | |
852 | qla84xx_updatefw(struct fc_bsg_job *bsg_job) | |
853 | { | |
854 | struct Scsi_Host *host = bsg_job->shost; | |
855 | scsi_qla_host_t *vha = shost_priv(host); | |
856 | struct qla_hw_data *ha = vha->hw; | |
857 | struct verify_chip_entry_84xx *mn = NULL; | |
858 | dma_addr_t mn_dma, fw_dma; | |
859 | void *fw_buf = NULL; | |
860 | int rval = 0; | |
861 | uint32_t sg_cnt; | |
862 | uint32_t data_len; | |
863 | uint16_t options; | |
864 | uint32_t flag; | |
865 | uint32_t fw_ver; | |
866 | ||
867 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) || | |
868 | test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) || | |
869 | test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) | |
870 | return -EBUSY; | |
871 | ||
872 | if (!IS_QLA84XX(ha)) { | |
873 | DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld): Not 84xx, " | |
874 | "exiting.\n", vha->host_no)); | |
875 | return -EINVAL; | |
876 | } | |
877 | ||
878 | sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, | |
879 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
880 | if (!sg_cnt) | |
881 | return -ENOMEM; | |
882 | ||
883 | if (sg_cnt != bsg_job->request_payload.sg_cnt) { | |
884 | DEBUG2(printk(KERN_INFO | |
885 | "dma mapping resulted in different sg counts " | |
886 | "request_sg_cnt: %x dma_request_sg_cnt: %x ", | |
887 | bsg_job->request_payload.sg_cnt, sg_cnt)); | |
888 | rval = -EAGAIN; | |
889 | goto done_unmap_sg; | |
890 | } | |
891 | ||
892 | data_len = bsg_job->request_payload.payload_len; | |
893 | fw_buf = dma_alloc_coherent(&ha->pdev->dev, data_len, | |
894 | &fw_dma, GFP_KERNEL); | |
895 | if (!fw_buf) { | |
896 | DEBUG2(printk(KERN_ERR "%s: dma alloc for fw_buf " | |
897 | "failed for host=%lu\n", __func__, vha->host_no)); | |
898 | rval = -ENOMEM; | |
899 | goto done_unmap_sg; | |
900 | } | |
901 | ||
902 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, | |
903 | bsg_job->request_payload.sg_cnt, fw_buf, data_len); | |
904 | ||
905 | mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma); | |
906 | if (!mn) { | |
907 | DEBUG2(printk(KERN_ERR "%s: dma alloc for fw buffer " | |
908 | "failed for host=%lu\n", __func__, vha->host_no)); | |
909 | rval = -ENOMEM; | |
910 | goto done_free_fw_buf; | |
911 | } | |
912 | ||
913 | flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1]; | |
914 | fw_ver = le32_to_cpu(*((uint32_t *)((uint32_t *)fw_buf + 2))); | |
915 | ||
916 | memset(mn, 0, sizeof(struct access_chip_84xx)); | |
917 | mn->entry_type = VERIFY_CHIP_IOCB_TYPE; | |
918 | mn->entry_count = 1; | |
919 | ||
920 | options = VCO_FORCE_UPDATE | VCO_END_OF_DATA; | |
921 | if (flag == A84_ISSUE_UPDATE_DIAGFW_CMD) | |
922 | options |= VCO_DIAG_FW; | |
923 | ||
924 | mn->options = cpu_to_le16(options); | |
925 | mn->fw_ver = cpu_to_le32(fw_ver); | |
926 | mn->fw_size = cpu_to_le32(data_len); | |
927 | mn->fw_seq_size = cpu_to_le32(data_len); | |
928 | mn->dseg_address[0] = cpu_to_le32(LSD(fw_dma)); | |
929 | mn->dseg_address[1] = cpu_to_le32(MSD(fw_dma)); | |
930 | mn->dseg_length = cpu_to_le32(data_len); | |
931 | mn->data_seg_cnt = cpu_to_le16(1); | |
932 | ||
933 | rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120); | |
934 | ||
935 | if (rval) { | |
936 | DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor " | |
937 | "request 84xx updatefw failed\n", vha->host_no)); | |
938 | ||
939 | rval = bsg_job->reply->reply_payload_rcv_len = 0; | |
940 | bsg_job->reply->result = (DID_ERROR << 16); | |
941 | ||
942 | } else { | |
943 | DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor " | |
944 | "request 84xx updatefw completed\n", vha->host_no)); | |
945 | ||
946 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); | |
947 | bsg_job->reply->result = DID_OK; | |
948 | } | |
949 | ||
950 | bsg_job->job_done(bsg_job); | |
951 | dma_pool_free(ha->s_dma_pool, mn, mn_dma); | |
952 | ||
953 | done_free_fw_buf: | |
954 | dma_free_coherent(&ha->pdev->dev, data_len, fw_buf, fw_dma); | |
955 | ||
956 | done_unmap_sg: | |
957 | dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, | |
958 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
959 | ||
960 | return rval; | |
961 | } | |
962 | ||
963 | static int | |
964 | qla84xx_mgmt_cmd(struct fc_bsg_job *bsg_job) | |
965 | { | |
966 | struct Scsi_Host *host = bsg_job->shost; | |
967 | scsi_qla_host_t *vha = shost_priv(host); | |
968 | struct qla_hw_data *ha = vha->hw; | |
969 | struct access_chip_84xx *mn = NULL; | |
970 | dma_addr_t mn_dma, mgmt_dma; | |
971 | void *mgmt_b = NULL; | |
972 | int rval = 0; | |
973 | struct qla_bsg_a84_mgmt *ql84_mgmt; | |
974 | uint32_t sg_cnt; | |
d5459083 | 975 | uint32_t data_len = 0; |
6e98016c GM |
976 | uint32_t dma_direction = DMA_NONE; |
977 | ||
978 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) || | |
979 | test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) || | |
980 | test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) | |
981 | return -EBUSY; | |
982 | ||
983 | if (!IS_QLA84XX(ha)) { | |
984 | DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld): Not 84xx, " | |
985 | "exiting.\n", vha->host_no)); | |
986 | return -EINVAL; | |
987 | } | |
988 | ||
989 | ql84_mgmt = (struct qla_bsg_a84_mgmt *)((char *)bsg_job->request + | |
990 | sizeof(struct fc_bsg_request)); | |
991 | if (!ql84_mgmt) { | |
992 | DEBUG2(printk("%s(%ld): mgmt header not provided, exiting.\n", | |
993 | __func__, vha->host_no)); | |
994 | return -EINVAL; | |
995 | } | |
996 | ||
997 | mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma); | |
998 | if (!mn) { | |
999 | DEBUG2(printk(KERN_ERR "%s: dma alloc for fw buffer " | |
1000 | "failed for host=%lu\n", __func__, vha->host_no)); | |
1001 | return -ENOMEM; | |
1002 | } | |
1003 | ||
1004 | memset(mn, 0, sizeof(struct access_chip_84xx)); | |
1005 | mn->entry_type = ACCESS_CHIP_IOCB_TYPE; | |
1006 | mn->entry_count = 1; | |
1007 | ||
1008 | switch (ql84_mgmt->mgmt.cmd) { | |
1009 | case QLA84_MGMT_READ_MEM: | |
1010 | case QLA84_MGMT_GET_INFO: | |
1011 | sg_cnt = dma_map_sg(&ha->pdev->dev, | |
1012 | bsg_job->reply_payload.sg_list, | |
1013 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
1014 | if (!sg_cnt) { | |
1015 | rval = -ENOMEM; | |
1016 | goto exit_mgmt; | |
1017 | } | |
1018 | ||
1019 | dma_direction = DMA_FROM_DEVICE; | |
1020 | ||
1021 | if (sg_cnt != bsg_job->reply_payload.sg_cnt) { | |
1022 | DEBUG2(printk(KERN_INFO | |
1023 | "dma mapping resulted in different sg counts " | |
1024 | "reply_sg_cnt: %x dma_reply_sg_cnt: %x\n", | |
1025 | bsg_job->reply_payload.sg_cnt, sg_cnt)); | |
1026 | rval = -EAGAIN; | |
1027 | goto done_unmap_sg; | |
1028 | } | |
1029 | ||
1030 | data_len = bsg_job->reply_payload.payload_len; | |
1031 | ||
1032 | mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len, | |
1033 | &mgmt_dma, GFP_KERNEL); | |
1034 | if (!mgmt_b) { | |
1035 | DEBUG2(printk(KERN_ERR "%s: dma alloc for mgmt_b " | |
1036 | "failed for host=%lu\n", | |
1037 | __func__, vha->host_no)); | |
1038 | rval = -ENOMEM; | |
1039 | goto done_unmap_sg; | |
1040 | } | |
1041 | ||
1042 | if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) { | |
1043 | mn->options = cpu_to_le16(ACO_DUMP_MEMORY); | |
1044 | mn->parameter1 = | |
1045 | cpu_to_le32( | |
1046 | ql84_mgmt->mgmt.mgmtp.u.mem.start_addr); | |
1047 | ||
1048 | } else if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO) { | |
1049 | mn->options = cpu_to_le16(ACO_REQUEST_INFO); | |
1050 | mn->parameter1 = | |
1051 | cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.info.type); | |
1052 | ||
1053 | mn->parameter2 = | |
1054 | cpu_to_le32( | |
1055 | ql84_mgmt->mgmt.mgmtp.u.info.context); | |
1056 | } | |
1057 | break; | |
1058 | ||
1059 | case QLA84_MGMT_WRITE_MEM: | |
1060 | sg_cnt = dma_map_sg(&ha->pdev->dev, | |
1061 | bsg_job->request_payload.sg_list, | |
1062 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
1063 | ||
1064 | if (!sg_cnt) { | |
1065 | rval = -ENOMEM; | |
1066 | goto exit_mgmt; | |
1067 | } | |
1068 | ||
1069 | dma_direction = DMA_TO_DEVICE; | |
1070 | ||
1071 | if (sg_cnt != bsg_job->request_payload.sg_cnt) { | |
1072 | DEBUG2(printk(KERN_INFO | |
1073 | "dma mapping resulted in different sg counts " | |
1074 | "request_sg_cnt: %x dma_request_sg_cnt: %x ", | |
1075 | bsg_job->request_payload.sg_cnt, sg_cnt)); | |
1076 | rval = -EAGAIN; | |
1077 | goto done_unmap_sg; | |
1078 | } | |
1079 | ||
1080 | data_len = bsg_job->request_payload.payload_len; | |
1081 | mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len, | |
1082 | &mgmt_dma, GFP_KERNEL); | |
1083 | if (!mgmt_b) { | |
1084 | DEBUG2(printk(KERN_ERR "%s: dma alloc for mgmt_b " | |
1085 | "failed for host=%lu\n", | |
1086 | __func__, vha->host_no)); | |
1087 | rval = -ENOMEM; | |
1088 | goto done_unmap_sg; | |
1089 | } | |
1090 | ||
1091 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, | |
1092 | bsg_job->request_payload.sg_cnt, mgmt_b, data_len); | |
1093 | ||
1094 | mn->options = cpu_to_le16(ACO_LOAD_MEMORY); | |
1095 | mn->parameter1 = | |
1096 | cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.mem.start_addr); | |
1097 | break; | |
1098 | ||
1099 | case QLA84_MGMT_CHNG_CONFIG: | |
1100 | mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM); | |
1101 | mn->parameter1 = | |
1102 | cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.id); | |
1103 | ||
1104 | mn->parameter2 = | |
1105 | cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param0); | |
1106 | ||
1107 | mn->parameter3 = | |
1108 | cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param1); | |
1109 | break; | |
1110 | ||
1111 | default: | |
1112 | rval = -EIO; | |
1113 | goto exit_mgmt; | |
1114 | } | |
1115 | ||
1116 | if (ql84_mgmt->mgmt.cmd != QLA84_MGMT_CHNG_CONFIG) { | |
1117 | mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->mgmt.len); | |
1118 | mn->dseg_count = cpu_to_le16(1); | |
1119 | mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma)); | |
1120 | mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma)); | |
1121 | mn->dseg_length = cpu_to_le32(ql84_mgmt->mgmt.len); | |
1122 | } | |
1123 | ||
1124 | rval = qla2x00_issue_iocb(vha, mn, mn_dma, 0); | |
1125 | ||
1126 | if (rval) { | |
1127 | DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor " | |
1128 | "request 84xx mgmt failed\n", vha->host_no)); | |
1129 | ||
1130 | rval = bsg_job->reply->reply_payload_rcv_len = 0; | |
1131 | bsg_job->reply->result = (DID_ERROR << 16); | |
1132 | ||
1133 | } else { | |
1134 | DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor " | |
1135 | "request 84xx mgmt completed\n", vha->host_no)); | |
1136 | ||
1137 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); | |
1138 | bsg_job->reply->result = DID_OK; | |
1139 | ||
1140 | if ((ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) || | |
1141 | (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO)) { | |
1142 | bsg_job->reply->reply_payload_rcv_len = | |
1143 | bsg_job->reply_payload.payload_len; | |
1144 | ||
1145 | sg_copy_from_buffer(bsg_job->reply_payload.sg_list, | |
6c452a45 AV |
1146 | bsg_job->reply_payload.sg_cnt, mgmt_b, |
1147 | data_len); | |
6e98016c GM |
1148 | } |
1149 | } | |
1150 | ||
1151 | bsg_job->job_done(bsg_job); | |
6e98016c GM |
1152 | |
1153 | done_unmap_sg: | |
d5459083 HZ |
1154 | if (mgmt_b) |
1155 | dma_free_coherent(&ha->pdev->dev, data_len, mgmt_b, mgmt_dma); | |
1156 | ||
6e98016c GM |
1157 | if (dma_direction == DMA_TO_DEVICE) |
1158 | dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, | |
1159 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
1160 | else if (dma_direction == DMA_FROM_DEVICE) | |
1161 | dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list, | |
1162 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
1163 | ||
1164 | exit_mgmt: | |
1165 | dma_pool_free(ha->s_dma_pool, mn, mn_dma); | |
1166 | ||
1167 | return rval; | |
1168 | } | |
1169 | ||
1170 | static int | |
1171 | qla24xx_iidma(struct fc_bsg_job *bsg_job) | |
1172 | { | |
1173 | struct Scsi_Host *host = bsg_job->shost; | |
1174 | scsi_qla_host_t *vha = shost_priv(host); | |
1175 | struct qla_hw_data *ha = vha->hw; | |
1176 | int rval = 0; | |
1177 | struct qla_port_param *port_param = NULL; | |
1178 | fc_port_t *fcport = NULL; | |
1179 | uint16_t mb[MAILBOX_REGISTER_COUNT]; | |
1180 | uint8_t *rsp_ptr = NULL; | |
1181 | ||
1182 | bsg_job->reply->reply_payload_rcv_len = 0; | |
1183 | ||
1184 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) || | |
1185 | test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) || | |
1186 | test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) | |
1187 | return -EBUSY; | |
1188 | ||
1189 | if (!IS_IIDMA_CAPABLE(vha->hw)) { | |
1190 | DEBUG2(qla_printk(KERN_WARNING, ha, "%s(%lu): iiDMA not " | |
1191 | "supported\n", __func__, vha->host_no)); | |
1192 | return -EINVAL; | |
1193 | } | |
1194 | ||
1195 | port_param = (struct qla_port_param *)((char *)bsg_job->request + | |
1196 | sizeof(struct fc_bsg_request)); | |
1197 | if (!port_param) { | |
1198 | DEBUG2(printk("%s(%ld): port_param header not provided, " | |
1199 | "exiting.\n", __func__, vha->host_no)); | |
1200 | return -EINVAL; | |
1201 | } | |
1202 | ||
1203 | if (port_param->fc_scsi_addr.dest_type != EXT_DEF_TYPE_WWPN) { | |
1204 | DEBUG2(printk(KERN_ERR "%s(%ld): Invalid destination type\n", | |
1205 | __func__, vha->host_no)); | |
1206 | return -EINVAL; | |
1207 | } | |
1208 | ||
1209 | list_for_each_entry(fcport, &vha->vp_fcports, list) { | |
1210 | if (fcport->port_type != FCT_TARGET) | |
1211 | continue; | |
1212 | ||
1213 | if (memcmp(port_param->fc_scsi_addr.dest_addr.wwpn, | |
1214 | fcport->port_name, sizeof(fcport->port_name))) | |
1215 | continue; | |
1216 | break; | |
1217 | } | |
1218 | ||
1219 | if (!fcport) { | |
1220 | DEBUG2(printk(KERN_ERR "%s(%ld): Failed to find port\n", | |
1221 | __func__, vha->host_no)); | |
1222 | return -EINVAL; | |
1223 | } | |
1224 | ||
17cf2c5d MI |
1225 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
1226 | DEBUG2(printk(KERN_ERR "%s(%ld): Invalid port loop id, " | |
1227 | "loop_id = 0x%x\n", | |
1228 | __func__, vha->host_no, fcport->loop_id)); | |
1229 | return -EINVAL; | |
1230 | } | |
1231 | ||
6e98016c GM |
1232 | if (port_param->mode) |
1233 | rval = qla2x00_set_idma_speed(vha, fcport->loop_id, | |
1234 | port_param->speed, mb); | |
1235 | else | |
1236 | rval = qla2x00_get_idma_speed(vha, fcport->loop_id, | |
1237 | &port_param->speed, mb); | |
1238 | ||
1239 | if (rval) { | |
1240 | DEBUG16(printk(KERN_ERR "scsi(%ld): iIDMA cmd failed for " | |
6c452a45 AV |
1241 | "%02x%02x%02x%02x%02x%02x%02x%02x -- " |
1242 | "%04x %x %04x %04x.\n", | |
6e98016c GM |
1243 | vha->host_no, fcport->port_name[0], |
1244 | fcport->port_name[1], | |
1245 | fcport->port_name[2], fcport->port_name[3], | |
1246 | fcport->port_name[4], fcport->port_name[5], | |
1247 | fcport->port_name[6], fcport->port_name[7], rval, | |
1248 | fcport->fp_speed, mb[0], mb[1])); | |
1249 | rval = 0; | |
1250 | bsg_job->reply->result = (DID_ERROR << 16); | |
1251 | ||
1252 | } else { | |
1253 | if (!port_param->mode) { | |
1254 | bsg_job->reply_len = sizeof(struct fc_bsg_reply) + | |
1255 | sizeof(struct qla_port_param); | |
1256 | ||
1257 | rsp_ptr = ((uint8_t *)bsg_job->reply) + | |
1258 | sizeof(struct fc_bsg_reply); | |
1259 | ||
1260 | memcpy(rsp_ptr, port_param, | |
1261 | sizeof(struct qla_port_param)); | |
1262 | } | |
1263 | ||
1264 | bsg_job->reply->result = DID_OK; | |
1265 | } | |
1266 | ||
1267 | bsg_job->job_done(bsg_job); | |
1268 | return rval; | |
1269 | } | |
1270 | ||
1271 | static int | |
1272 | qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job) | |
1273 | { | |
1274 | switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) { | |
1275 | case QL_VND_LOOPBACK: | |
1276 | return qla2x00_process_loopback(bsg_job); | |
1277 | ||
1278 | case QL_VND_A84_RESET: | |
1279 | return qla84xx_reset(bsg_job); | |
1280 | ||
1281 | case QL_VND_A84_UPDATE_FW: | |
1282 | return qla84xx_updatefw(bsg_job); | |
1283 | ||
1284 | case QL_VND_A84_MGMT_CMD: | |
1285 | return qla84xx_mgmt_cmd(bsg_job); | |
1286 | ||
1287 | case QL_VND_IIDMA: | |
1288 | return qla24xx_iidma(bsg_job); | |
1289 | ||
09ff701a SR |
1290 | case QL_VND_FCP_PRIO_CFG_CMD: |
1291 | return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job); | |
1292 | ||
6e98016c GM |
1293 | default: |
1294 | bsg_job->reply->result = (DID_ERROR << 16); | |
1295 | bsg_job->job_done(bsg_job); | |
1296 | return -ENOSYS; | |
1297 | } | |
1298 | } | |
1299 | ||
1300 | int | |
1301 | qla24xx_bsg_request(struct fc_bsg_job *bsg_job) | |
1302 | { | |
1303 | int ret = -EINVAL; | |
1304 | ||
1305 | switch (bsg_job->request->msgcode) { | |
1306 | case FC_BSG_RPT_ELS: | |
1307 | case FC_BSG_HST_ELS_NOLOGIN: | |
1308 | ret = qla2x00_process_els(bsg_job); | |
1309 | break; | |
1310 | case FC_BSG_HST_CT: | |
1311 | ret = qla2x00_process_ct(bsg_job); | |
1312 | break; | |
1313 | case FC_BSG_HST_VENDOR: | |
1314 | ret = qla2x00_process_vendor_specific(bsg_job); | |
1315 | break; | |
1316 | case FC_BSG_HST_ADD_RPORT: | |
1317 | case FC_BSG_HST_DEL_RPORT: | |
1318 | case FC_BSG_RPT_CT: | |
1319 | default: | |
1320 | DEBUG2(printk("qla2xxx: unsupported BSG request\n")); | |
1321 | break; | |
6c452a45 | 1322 | } |
6e98016c GM |
1323 | return ret; |
1324 | } | |
1325 | ||
1326 | int | |
1327 | qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job) | |
1328 | { | |
1329 | scsi_qla_host_t *vha = shost_priv(bsg_job->shost); | |
1330 | struct qla_hw_data *ha = vha->hw; | |
1331 | srb_t *sp; | |
1332 | int cnt, que; | |
1333 | unsigned long flags; | |
1334 | struct req_que *req; | |
4916392b | 1335 | struct srb_ctx *sp_bsg; |
6e98016c GM |
1336 | |
1337 | /* find the bsg job from the active list of commands */ | |
1338 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
1339 | for (que = 0; que < ha->max_req_queues; que++) { | |
1340 | req = ha->req_q_map[que]; | |
1341 | if (!req) | |
1342 | continue; | |
1343 | ||
6c452a45 | 1344 | for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) { |
6e98016c | 1345 | sp = req->outstanding_cmds[cnt]; |
6e98016c | 1346 | if (sp) { |
4916392b | 1347 | sp_bsg = sp->ctx; |
6e98016c | 1348 | |
4916392b MI |
1349 | if (((sp_bsg->type == SRB_CT_CMD) || |
1350 | (sp_bsg->type == SRB_ELS_CMD_HST)) | |
1351 | && (sp_bsg->u.bsg_job == bsg_job)) { | |
6e98016c GM |
1352 | if (ha->isp_ops->abort_command(sp)) { |
1353 | DEBUG2(qla_printk(KERN_INFO, ha, | |
6c452a45 AV |
1354 | "scsi(%ld): mbx " |
1355 | "abort_command failed\n", | |
1356 | vha->host_no)); | |
6e98016c GM |
1357 | bsg_job->req->errors = |
1358 | bsg_job->reply->result = -EIO; | |
1359 | } else { | |
1360 | DEBUG2(qla_printk(KERN_INFO, ha, | |
6c452a45 AV |
1361 | "scsi(%ld): mbx " |
1362 | "abort_command success\n", | |
1363 | vha->host_no)); | |
6e98016c GM |
1364 | bsg_job->req->errors = |
1365 | bsg_job->reply->result = 0; | |
1366 | } | |
1367 | goto done; | |
1368 | } | |
1369 | } | |
1370 | } | |
1371 | } | |
1372 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1373 | DEBUG2(qla_printk(KERN_INFO, ha, | |
1374 | "scsi(%ld) SRB not found to abort\n", vha->host_no)); | |
1375 | bsg_job->req->errors = bsg_job->reply->result = -ENXIO; | |
1376 | return 0; | |
1377 | ||
1378 | done: | |
1379 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1380 | if (bsg_job->request->msgcode == FC_BSG_HST_CT) | |
1381 | kfree(sp->fcport); | |
1382 | kfree(sp->ctx); | |
1383 | mempool_free(sp, ha->srb_mempool); | |
1384 | return 0; | |
1385 | } |