blob: 584c52d134fa7def3b508b27f4b7d0158cba4cff [file] [log] [blame]
Giridhar Malavali6e980162010-03-19 17:03:58 -07001/*
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 */
14inline srb_t *
15qla2x00_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;
19 struct srb_bsg_ctx *ctx;
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;
34done:
35 return sp;
36}
37
Sarang Radke09ff7012010-03-19 17:03:59 -070038int
39qla24xx_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
69static int
70qla24xx_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 }
194exit_fcp_prio_cfg:
195 bsg_job->job_done(bsg_job);
196 return ret;
197}
Giridhar Malavali6e980162010-03-19 17:03:58 -0700198static int
199qla2x00_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;
211 struct srb_bsg *els;
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,
277 "host not online\n"));
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 }
289 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
290 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
291 if (!rsp_sg_cnt) {
292 rval = -ENOMEM;
293 goto done_free_fcport;
294 }
295
296 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
297 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt))
298 {
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 */
310 sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_bsg));
311 if (!sp) {
312 rval = -ENOMEM;
313 goto done_unmap_sg;
314 }
315
316 els = sp->ctx;
317 els->ctx.type =
318 (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
319 SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
320 els->bsg_job = bsg_job;
321
322 DEBUG2(qla_printk(KERN_INFO, ha,
323 "scsi(%ld:%x): bsg rqst type: %s els type: %x - loop-id=%x "
324 "portid=%02x%02x%02x.\n", vha->host_no, sp->handle, type,
325 bsg_job->request->rqst_data.h_els.command_code,
326 fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
327 fcport->d_id.b.al_pa));
328
329 rval = qla2x00_start_sp(sp);
330 if (rval != QLA_SUCCESS) {
331 kfree(sp->ctx);
332 mempool_free(sp, ha->srb_mempool);
333 rval = -EIO;
334 goto done_unmap_sg;
335 }
336 return rval;
337
338done_unmap_sg:
339 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
340 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
341 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
342 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
343 goto done_free_fcport;
344
345done_free_fcport:
346 if (bsg_job->request->msgcode == FC_BSG_HST_ELS_NOLOGIN)
347 kfree(fcport);
348done:
349 return rval;
350}
351
352static int
353qla2x00_process_ct(struct fc_bsg_job *bsg_job)
354{
355 srb_t *sp;
356 struct Scsi_Host *host = bsg_job->shost;
357 scsi_qla_host_t *vha = shost_priv(host);
358 struct qla_hw_data *ha = vha->hw;
359 int rval = (DRIVER_ERROR << 16);
360 int req_sg_cnt, rsp_sg_cnt;
361 uint16_t loop_id;
362 struct fc_port *fcport;
363 char *type = "FC_BSG_HST_CT";
364 struct srb_bsg *ct;
365
366 /* pass through is supported only for ISP 4Gb or higher */
367 if (!IS_FWI2_CAPABLE(ha)) {
368 DEBUG2(qla_printk(KERN_INFO, ha,
369 "scsi(%ld):Firmware is not capable to support FC "
370 "CT pass thru\n", vha->host_no));
371 rval = -EPERM;
372 goto done;
373 }
374
375 req_sg_cnt =
376 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
377 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
378 if (!req_sg_cnt) {
379 rval = -ENOMEM;
380 goto done;
381 }
382
383 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
384 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
385 if (!rsp_sg_cnt) {
386 rval = -ENOMEM;
387 goto done;
388 }
389
390 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
391 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt))
392 {
393 DEBUG2(qla_printk(KERN_WARNING, ha,
394 "[request_sg_cnt: %x dma_request_sg_cnt: %x\
395 reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
396 bsg_job->request_payload.sg_cnt, req_sg_cnt,
397 bsg_job->reply_payload.sg_cnt, rsp_sg_cnt));
398 rval = -EAGAIN;
399 goto done_unmap_sg;
400 }
401
402 if (!vha->flags.online) {
403 DEBUG2(qla_printk(KERN_WARNING, ha,
404 "host not online\n"));
405 rval = -EIO;
406 goto done_unmap_sg;
407 }
408
409 loop_id =
410 (bsg_job->request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
411 >> 24;
412 switch (loop_id) {
413 case 0xFC:
414 loop_id = cpu_to_le16(NPH_SNS);
415 break;
416 case 0xFA:
417 loop_id = vha->mgmt_svr_loop_id;
418 break;
419 default:
420 DEBUG2(qla_printk(KERN_INFO, ha,
421 "Unknown loop id: %x\n", loop_id));
422 rval = -EINVAL;
423 goto done_unmap_sg;
424 }
425
426 /* Allocate a dummy fcport structure, since functions preparing the
427 * IOCB and mailbox command retrieves port specific information
428 * from fcport structure. For Host based ELS commands there will be
429 * no fcport structure allocated
430 */
431 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
432 if (!fcport)
433 {
434 rval = -ENOMEM;
435 goto done_unmap_sg;
436 }
437
438 /* Initialize all required fields of fcport */
439 fcport->vha = vha;
440 fcport->vp_idx = vha->vp_idx;
441 fcport->d_id.b.al_pa = bsg_job->request->rqst_data.h_ct.port_id[0];
442 fcport->d_id.b.area = bsg_job->request->rqst_data.h_ct.port_id[1];
443 fcport->d_id.b.domain = bsg_job->request->rqst_data.h_ct.port_id[2];
444 fcport->loop_id = loop_id;
445
446 /* Alloc SRB structure */
447 sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_bsg));
448 if (!sp) {
449 rval = -ENOMEM;
450 goto done_free_fcport;
451 }
452
453 ct = sp->ctx;
454 ct->ctx.type = SRB_CT_CMD;
455 ct->bsg_job = bsg_job;
456
457 DEBUG2(qla_printk(KERN_INFO, ha,
458 "scsi(%ld:%x): bsg rqst type: %s els type: %x - loop-id=%x "
459 "portid=%02x%02x%02x.\n", vha->host_no, sp->handle, type,
460 (bsg_job->request->rqst_data.h_ct.preamble_word2 >> 16),
461 fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
462 fcport->d_id.b.al_pa));
463
464 rval = qla2x00_start_sp(sp);
465 if (rval != QLA_SUCCESS) {
466 kfree(sp->ctx);
467 mempool_free(sp, ha->srb_mempool);
468 rval = -EIO;
469 goto done_free_fcport;
470 }
471 return rval;
472
473done_free_fcport:
474 kfree(fcport);
475done_unmap_sg:
476 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
477 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
478 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
479 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
480done:
481 return rval;
482}
483
484static int
485qla2x00_process_loopback(struct fc_bsg_job *bsg_job)
486{
487 struct Scsi_Host *host = bsg_job->shost;
488 scsi_qla_host_t *vha = shost_priv(host);
489 struct qla_hw_data *ha = vha->hw;
490 int rval;
491 uint8_t command_sent;
492 char *type;
493 struct msg_echo_lb elreq;
494 uint16_t response[MAILBOX_REGISTER_COUNT];
495 uint8_t* fw_sts_ptr;
496 uint8_t *req_data = NULL;
497 dma_addr_t req_data_dma;
498 uint32_t req_data_len;
499 uint8_t *rsp_data = NULL;
500 dma_addr_t rsp_data_dma;
501 uint32_t rsp_data_len;
502
503 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
504 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
505 test_bit(ISP_ABORT_RETRY, &vha->dpc_flags))
506 return -EBUSY;
507
508 if (!vha->flags.online) {
509 DEBUG2(qla_printk(KERN_WARNING, ha, "host not online\n"));
510 return -EIO;
511 }
512
513 elreq.req_sg_cnt = dma_map_sg(&ha->pdev->dev,
514 bsg_job->request_payload.sg_list, bsg_job->request_payload.sg_cnt,
515 DMA_TO_DEVICE);
516
517 if (!elreq.req_sg_cnt)
518 return -ENOMEM;
519
520 elreq.rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
521 bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
522 DMA_FROM_DEVICE);
523
524 if (!elreq.rsp_sg_cnt) {
525 rval = -ENOMEM;
526 goto done_unmap_req_sg;
527}
528
529 if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
530 (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
531 DEBUG2(printk(KERN_INFO
532 "dma mapping resulted in different sg counts "
533 "[request_sg_cnt: %x dma_request_sg_cnt: %x "
534 "reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
535 bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
536 bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt));
537 rval = -EAGAIN;
538 goto done_unmap_sg;
539 }
540 req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
541 req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
542 &req_data_dma, GFP_KERNEL);
543 if (!req_data) {
544 DEBUG2(printk(KERN_ERR "%s: dma alloc for req_data "
545 "failed for host=%lu\n", __func__, vha->host_no));
546 rval = -ENOMEM;
547 goto done_unmap_sg;
548 }
549
550 rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
551 &rsp_data_dma, GFP_KERNEL);
552 if (!rsp_data) {
553 DEBUG2(printk(KERN_ERR "%s: dma alloc for rsp_data "
554 "failed for host=%lu\n", __func__, vha->host_no));
555 rval = -ENOMEM;
556 goto done_free_dma_req;
557 }
558
559 /* Copy the request buffer in req_data now */
560 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
561 bsg_job->request_payload.sg_cnt, req_data, req_data_len);
562
563 elreq.send_dma = req_data_dma;
564 elreq.rcv_dma = rsp_data_dma;
565 elreq.transfer_size = req_data_len;
566
567 elreq.options = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
568
569 if (ha->current_topology != ISP_CFG_F) {
570 type = "FC_BSG_HST_VENDOR_LOOPBACK";
571 DEBUG2(qla_printk(KERN_INFO, ha,
572 "scsi(%ld) bsg rqst type: %s\n",
573 vha->host_no, type));
574
575 command_sent = INT_DEF_LB_LOOPBACK_CMD;
576 rval = qla2x00_loopback_test(vha, &elreq, response);
577 if (IS_QLA81XX(ha)) {
578 if (response[0] == MBS_COMMAND_ERROR &&
579 response[1] == MBS_LB_RESET) {
580 DEBUG2(printk(KERN_ERR "%s(%ld): ABORTing "
581 "ISP\n", __func__, vha->host_no));
582 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
583 qla2xxx_wake_dpc(vha);
584 }
585 }
586 } else {
587 type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
588 DEBUG2(qla_printk(KERN_INFO, ha,
589 "scsi(%ld) bsg rqst type: %s\n" ,vha->host_no, type));
590 command_sent = INT_DEF_LB_ECHO_CMD;
591 rval = qla2x00_echo_test(vha, &elreq, response);
592 }
593
594 if (rval) {
595 DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor "
596 "request %s failed\n", vha->host_no, type));
597
598 fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) +
599 sizeof(struct fc_bsg_reply);
600
601 memcpy(fw_sts_ptr, response, sizeof(response));
602 fw_sts_ptr += sizeof(response);
603 *fw_sts_ptr = command_sent;
604 rval = 0;
605 bsg_job->reply->reply_payload_rcv_len = 0;
606 bsg_job->reply->result = (DID_ERROR << 16);
607 } else {
608 DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor "
609 "request %s completed\n", vha->host_no, type));
610
611 bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
612 sizeof(response) + sizeof(uint8_t);
613 bsg_job->reply->reply_payload_rcv_len =
614 bsg_job->reply_payload.payload_len;
615 fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) +
616 sizeof(struct fc_bsg_reply);
617 memcpy(fw_sts_ptr, response, sizeof(response));
618 fw_sts_ptr += sizeof(response);
619 *fw_sts_ptr = command_sent;
620 bsg_job->reply->result = DID_OK;
621 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
622 bsg_job->reply_payload.sg_cnt, rsp_data,
623 rsp_data_len);
624 }
625 bsg_job->job_done(bsg_job);
626
627 dma_free_coherent(&ha->pdev->dev, rsp_data_len,
628 rsp_data, rsp_data_dma);
629done_free_dma_req:
630 dma_free_coherent(&ha->pdev->dev, req_data_len,
631 req_data, req_data_dma);
632done_unmap_sg:
633 dma_unmap_sg(&ha->pdev->dev,
634 bsg_job->reply_payload.sg_list,
635 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
636done_unmap_req_sg:
637 dma_unmap_sg(&ha->pdev->dev,
638 bsg_job->request_payload.sg_list,
639 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
640 return rval;
641}
642
643static int
644qla84xx_reset(struct fc_bsg_job *bsg_job)
645{
646 struct Scsi_Host *host = bsg_job->shost;
647 scsi_qla_host_t *vha = shost_priv(host);
648 struct qla_hw_data *ha = vha->hw;
649 int rval = 0;
650 uint32_t flag;
651
652 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
653 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
654 test_bit(ISP_ABORT_RETRY, &vha->dpc_flags))
655 return -EBUSY;
656
657 if (!IS_QLA84XX(ha)) {
658 DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld): Not 84xx, "
659 "exiting.\n", vha->host_no));
660 return -EINVAL;
661 }
662
663 flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
664
665 rval = qla84xx_reset_chip(vha, flag == A84_ISSUE_RESET_DIAG_FW);
666
667 if (rval) {
668 DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor "
669 "request 84xx reset failed\n", vha->host_no));
670 rval = bsg_job->reply->reply_payload_rcv_len = 0;
671 bsg_job->reply->result = (DID_ERROR << 16);
672
673 } else {
674 DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor "
675 "request 84xx reset completed\n", vha->host_no));
676 bsg_job->reply->result = DID_OK;
677 }
678
679 bsg_job->job_done(bsg_job);
680 return rval;
681}
682
683static int
684qla84xx_updatefw(struct fc_bsg_job *bsg_job)
685{
686 struct Scsi_Host *host = bsg_job->shost;
687 scsi_qla_host_t *vha = shost_priv(host);
688 struct qla_hw_data *ha = vha->hw;
689 struct verify_chip_entry_84xx *mn = NULL;
690 dma_addr_t mn_dma, fw_dma;
691 void *fw_buf = NULL;
692 int rval = 0;
693 uint32_t sg_cnt;
694 uint32_t data_len;
695 uint16_t options;
696 uint32_t flag;
697 uint32_t fw_ver;
698
699 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
700 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
701 test_bit(ISP_ABORT_RETRY, &vha->dpc_flags))
702 return -EBUSY;
703
704 if (!IS_QLA84XX(ha)) {
705 DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld): Not 84xx, "
706 "exiting.\n", vha->host_no));
707 return -EINVAL;
708 }
709
710 sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
711 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
712 if (!sg_cnt)
713 return -ENOMEM;
714
715 if (sg_cnt != bsg_job->request_payload.sg_cnt) {
716 DEBUG2(printk(KERN_INFO
717 "dma mapping resulted in different sg counts "
718 "request_sg_cnt: %x dma_request_sg_cnt: %x ",
719 bsg_job->request_payload.sg_cnt, sg_cnt));
720 rval = -EAGAIN;
721 goto done_unmap_sg;
722 }
723
724 data_len = bsg_job->request_payload.payload_len;
725 fw_buf = dma_alloc_coherent(&ha->pdev->dev, data_len,
726 &fw_dma, GFP_KERNEL);
727 if (!fw_buf) {
728 DEBUG2(printk(KERN_ERR "%s: dma alloc for fw_buf "
729 "failed for host=%lu\n", __func__, vha->host_no));
730 rval = -ENOMEM;
731 goto done_unmap_sg;
732 }
733
734 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
735 bsg_job->request_payload.sg_cnt, fw_buf, data_len);
736
737 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
738 if (!mn) {
739 DEBUG2(printk(KERN_ERR "%s: dma alloc for fw buffer "
740 "failed for host=%lu\n", __func__, vha->host_no));
741 rval = -ENOMEM;
742 goto done_free_fw_buf;
743 }
744
745 flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
746 fw_ver = le32_to_cpu(*((uint32_t *)((uint32_t *)fw_buf + 2)));
747
748 memset(mn, 0, sizeof(struct access_chip_84xx));
749 mn->entry_type = VERIFY_CHIP_IOCB_TYPE;
750 mn->entry_count = 1;
751
752 options = VCO_FORCE_UPDATE | VCO_END_OF_DATA;
753 if (flag == A84_ISSUE_UPDATE_DIAGFW_CMD)
754 options |= VCO_DIAG_FW;
755
756 mn->options = cpu_to_le16(options);
757 mn->fw_ver = cpu_to_le32(fw_ver);
758 mn->fw_size = cpu_to_le32(data_len);
759 mn->fw_seq_size = cpu_to_le32(data_len);
760 mn->dseg_address[0] = cpu_to_le32(LSD(fw_dma));
761 mn->dseg_address[1] = cpu_to_le32(MSD(fw_dma));
762 mn->dseg_length = cpu_to_le32(data_len);
763 mn->data_seg_cnt = cpu_to_le16(1);
764
765 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
766
767 if (rval) {
768 DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor "
769 "request 84xx updatefw failed\n", vha->host_no));
770
771 rval = bsg_job->reply->reply_payload_rcv_len = 0;
772 bsg_job->reply->result = (DID_ERROR << 16);
773
774 } else {
775 DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor "
776 "request 84xx updatefw completed\n", vha->host_no));
777
778 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
779 bsg_job->reply->result = DID_OK;
780 }
781
782 bsg_job->job_done(bsg_job);
783 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
784
785done_free_fw_buf:
786 dma_free_coherent(&ha->pdev->dev, data_len, fw_buf, fw_dma);
787
788done_unmap_sg:
789 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
790 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
791
792 return rval;
793}
794
795static int
796qla84xx_mgmt_cmd(struct fc_bsg_job *bsg_job)
797{
798 struct Scsi_Host *host = bsg_job->shost;
799 scsi_qla_host_t *vha = shost_priv(host);
800 struct qla_hw_data *ha = vha->hw;
801 struct access_chip_84xx *mn = NULL;
802 dma_addr_t mn_dma, mgmt_dma;
803 void *mgmt_b = NULL;
804 int rval = 0;
805 struct qla_bsg_a84_mgmt *ql84_mgmt;
806 uint32_t sg_cnt;
Harish Zunjarraod5459082010-03-19 17:04:00 -0700807 uint32_t data_len = 0;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700808 uint32_t dma_direction = DMA_NONE;
809
810 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
811 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
812 test_bit(ISP_ABORT_RETRY, &vha->dpc_flags))
813 return -EBUSY;
814
815 if (!IS_QLA84XX(ha)) {
816 DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld): Not 84xx, "
817 "exiting.\n", vha->host_no));
818 return -EINVAL;
819 }
820
821 ql84_mgmt = (struct qla_bsg_a84_mgmt *)((char *)bsg_job->request +
822 sizeof(struct fc_bsg_request));
823 if (!ql84_mgmt) {
824 DEBUG2(printk("%s(%ld): mgmt header not provided, exiting.\n",
825 __func__, vha->host_no));
826 return -EINVAL;
827 }
828
829 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
830 if (!mn) {
831 DEBUG2(printk(KERN_ERR "%s: dma alloc for fw buffer "
832 "failed for host=%lu\n", __func__, vha->host_no));
833 return -ENOMEM;
834 }
835
836 memset(mn, 0, sizeof(struct access_chip_84xx));
837 mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
838 mn->entry_count = 1;
839
840 switch (ql84_mgmt->mgmt.cmd) {
841 case QLA84_MGMT_READ_MEM:
842 case QLA84_MGMT_GET_INFO:
843 sg_cnt = dma_map_sg(&ha->pdev->dev,
844 bsg_job->reply_payload.sg_list,
845 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
846 if (!sg_cnt) {
847 rval = -ENOMEM;
848 goto exit_mgmt;
849 }
850
851 dma_direction = DMA_FROM_DEVICE;
852
853 if (sg_cnt != bsg_job->reply_payload.sg_cnt) {
854 DEBUG2(printk(KERN_INFO
855 "dma mapping resulted in different sg counts "
856 "reply_sg_cnt: %x dma_reply_sg_cnt: %x\n",
857 bsg_job->reply_payload.sg_cnt, sg_cnt));
858 rval = -EAGAIN;
859 goto done_unmap_sg;
860 }
861
862 data_len = bsg_job->reply_payload.payload_len;
863
864 mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
865 &mgmt_dma, GFP_KERNEL);
866 if (!mgmt_b) {
867 DEBUG2(printk(KERN_ERR "%s: dma alloc for mgmt_b "
868 "failed for host=%lu\n",
869 __func__, vha->host_no));
870 rval = -ENOMEM;
871 goto done_unmap_sg;
872 }
873
874 if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) {
875 mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
876 mn->parameter1 =
877 cpu_to_le32(
878 ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
879
880 } else if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO) {
881 mn->options = cpu_to_le16(ACO_REQUEST_INFO);
882 mn->parameter1 =
883 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.info.type);
884
885 mn->parameter2 =
886 cpu_to_le32(
887 ql84_mgmt->mgmt.mgmtp.u.info.context);
888 }
889 break;
890
891 case QLA84_MGMT_WRITE_MEM:
892 sg_cnt = dma_map_sg(&ha->pdev->dev,
893 bsg_job->request_payload.sg_list,
894 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
895
896 if (!sg_cnt) {
897 rval = -ENOMEM;
898 goto exit_mgmt;
899 }
900
901 dma_direction = DMA_TO_DEVICE;
902
903 if (sg_cnt != bsg_job->request_payload.sg_cnt) {
904 DEBUG2(printk(KERN_INFO
905 "dma mapping resulted in different sg counts "
906 "request_sg_cnt: %x dma_request_sg_cnt: %x ",
907 bsg_job->request_payload.sg_cnt, sg_cnt));
908 rval = -EAGAIN;
909 goto done_unmap_sg;
910 }
911
912 data_len = bsg_job->request_payload.payload_len;
913 mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
914 &mgmt_dma, GFP_KERNEL);
915 if (!mgmt_b) {
916 DEBUG2(printk(KERN_ERR "%s: dma alloc for mgmt_b "
917 "failed for host=%lu\n",
918 __func__, vha->host_no));
919 rval = -ENOMEM;
920 goto done_unmap_sg;
921 }
922
923 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
924 bsg_job->request_payload.sg_cnt, mgmt_b, data_len);
925
926 mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
927 mn->parameter1 =
928 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
929 break;
930
931 case QLA84_MGMT_CHNG_CONFIG:
932 mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
933 mn->parameter1 =
934 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.id);
935
936 mn->parameter2 =
937 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param0);
938
939 mn->parameter3 =
940 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param1);
941 break;
942
943 default:
944 rval = -EIO;
945 goto exit_mgmt;
946 }
947
948 if (ql84_mgmt->mgmt.cmd != QLA84_MGMT_CHNG_CONFIG) {
949 mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->mgmt.len);
950 mn->dseg_count = cpu_to_le16(1);
951 mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma));
952 mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma));
953 mn->dseg_length = cpu_to_le32(ql84_mgmt->mgmt.len);
954 }
955
956 rval = qla2x00_issue_iocb(vha, mn, mn_dma, 0);
957
958 if (rval) {
959 DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor "
960 "request 84xx mgmt failed\n", vha->host_no));
961
962 rval = bsg_job->reply->reply_payload_rcv_len = 0;
963 bsg_job->reply->result = (DID_ERROR << 16);
964
965 } else {
966 DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor "
967 "request 84xx mgmt completed\n", vha->host_no));
968
969 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
970 bsg_job->reply->result = DID_OK;
971
972 if ((ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) ||
973 (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO)) {
974 bsg_job->reply->reply_payload_rcv_len =
975 bsg_job->reply_payload.payload_len;
976
977 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
978 bsg_job->reply_payload.sg_cnt, mgmt_b, data_len);
979 }
980 }
981
982 bsg_job->job_done(bsg_job);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700983
984done_unmap_sg:
Harish Zunjarraod5459082010-03-19 17:04:00 -0700985 if (mgmt_b)
986 dma_free_coherent(&ha->pdev->dev, data_len, mgmt_b, mgmt_dma);
987
Giridhar Malavali6e980162010-03-19 17:03:58 -0700988 if (dma_direction == DMA_TO_DEVICE)
989 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
990 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
991 else if (dma_direction == DMA_FROM_DEVICE)
992 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
993 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
994
995exit_mgmt:
996 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
997
998 return rval;
999}
1000
1001static int
1002qla24xx_iidma(struct fc_bsg_job *bsg_job)
1003{
1004 struct Scsi_Host *host = bsg_job->shost;
1005 scsi_qla_host_t *vha = shost_priv(host);
1006 struct qla_hw_data *ha = vha->hw;
1007 int rval = 0;
1008 struct qla_port_param *port_param = NULL;
1009 fc_port_t *fcport = NULL;
1010 uint16_t mb[MAILBOX_REGISTER_COUNT];
1011 uint8_t *rsp_ptr = NULL;
1012
1013 bsg_job->reply->reply_payload_rcv_len = 0;
1014
1015 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
1016 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1017 test_bit(ISP_ABORT_RETRY, &vha->dpc_flags))
1018 return -EBUSY;
1019
1020 if (!IS_IIDMA_CAPABLE(vha->hw)) {
1021 DEBUG2(qla_printk(KERN_WARNING, ha, "%s(%lu): iiDMA not "
1022 "supported\n", __func__, vha->host_no));
1023 return -EINVAL;
1024 }
1025
1026 port_param = (struct qla_port_param *)((char *)bsg_job->request +
1027 sizeof(struct fc_bsg_request));
1028 if (!port_param) {
1029 DEBUG2(printk("%s(%ld): port_param header not provided, "
1030 "exiting.\n", __func__, vha->host_no));
1031 return -EINVAL;
1032 }
1033
1034 if (port_param->fc_scsi_addr.dest_type != EXT_DEF_TYPE_WWPN) {
1035 DEBUG2(printk(KERN_ERR "%s(%ld): Invalid destination type\n",
1036 __func__, vha->host_no));
1037 return -EINVAL;
1038 }
1039
1040 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1041 if (fcport->port_type != FCT_TARGET)
1042 continue;
1043
1044 if (memcmp(port_param->fc_scsi_addr.dest_addr.wwpn,
1045 fcport->port_name, sizeof(fcport->port_name)))
1046 continue;
1047 break;
1048 }
1049
1050 if (!fcport) {
1051 DEBUG2(printk(KERN_ERR "%s(%ld): Failed to find port\n",
1052 __func__, vha->host_no));
1053 return -EINVAL;
1054 }
1055
1056 if (port_param->mode)
1057 rval = qla2x00_set_idma_speed(vha, fcport->loop_id,
1058 port_param->speed, mb);
1059 else
1060 rval = qla2x00_get_idma_speed(vha, fcport->loop_id,
1061 &port_param->speed, mb);
1062
1063 if (rval) {
1064 DEBUG16(printk(KERN_ERR "scsi(%ld): iIDMA cmd failed for "
1065 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
1066 vha->host_no, fcport->port_name[0],
1067 fcport->port_name[1],
1068 fcport->port_name[2], fcport->port_name[3],
1069 fcport->port_name[4], fcport->port_name[5],
1070 fcport->port_name[6], fcport->port_name[7], rval,
1071 fcport->fp_speed, mb[0], mb[1]));
1072 rval = 0;
1073 bsg_job->reply->result = (DID_ERROR << 16);
1074
1075 } else {
1076 if (!port_param->mode) {
1077 bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
1078 sizeof(struct qla_port_param);
1079
1080 rsp_ptr = ((uint8_t *)bsg_job->reply) +
1081 sizeof(struct fc_bsg_reply);
1082
1083 memcpy(rsp_ptr, port_param,
1084 sizeof(struct qla_port_param));
1085 }
1086
1087 bsg_job->reply->result = DID_OK;
1088 }
1089
1090 bsg_job->job_done(bsg_job);
1091 return rval;
1092}
1093
1094static int
1095qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
1096{
1097 switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) {
1098 case QL_VND_LOOPBACK:
1099 return qla2x00_process_loopback(bsg_job);
1100
1101 case QL_VND_A84_RESET:
1102 return qla84xx_reset(bsg_job);
1103
1104 case QL_VND_A84_UPDATE_FW:
1105 return qla84xx_updatefw(bsg_job);
1106
1107 case QL_VND_A84_MGMT_CMD:
1108 return qla84xx_mgmt_cmd(bsg_job);
1109
1110 case QL_VND_IIDMA:
1111 return qla24xx_iidma(bsg_job);
1112
Sarang Radke09ff7012010-03-19 17:03:59 -07001113 case QL_VND_FCP_PRIO_CFG_CMD:
1114 return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job);
1115
Giridhar Malavali6e980162010-03-19 17:03:58 -07001116 default:
1117 bsg_job->reply->result = (DID_ERROR << 16);
1118 bsg_job->job_done(bsg_job);
1119 return -ENOSYS;
1120 }
1121}
1122
1123int
1124qla24xx_bsg_request(struct fc_bsg_job *bsg_job)
1125{
1126 int ret = -EINVAL;
1127
1128 switch (bsg_job->request->msgcode) {
1129 case FC_BSG_RPT_ELS:
1130 case FC_BSG_HST_ELS_NOLOGIN:
1131 ret = qla2x00_process_els(bsg_job);
1132 break;
1133 case FC_BSG_HST_CT:
1134 ret = qla2x00_process_ct(bsg_job);
1135 break;
1136 case FC_BSG_HST_VENDOR:
1137 ret = qla2x00_process_vendor_specific(bsg_job);
1138 break;
1139 case FC_BSG_HST_ADD_RPORT:
1140 case FC_BSG_HST_DEL_RPORT:
1141 case FC_BSG_RPT_CT:
1142 default:
1143 DEBUG2(printk("qla2xxx: unsupported BSG request\n"));
1144 break;
1145 }
1146 return ret;
1147}
1148
1149int
1150qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job)
1151{
1152 scsi_qla_host_t *vha = shost_priv(bsg_job->shost);
1153 struct qla_hw_data *ha = vha->hw;
1154 srb_t *sp;
1155 int cnt, que;
1156 unsigned long flags;
1157 struct req_que *req;
1158 struct srb_bsg *sp_bsg;
1159
1160 /* find the bsg job from the active list of commands */
1161 spin_lock_irqsave(&ha->hardware_lock, flags);
1162 for (que = 0; que < ha->max_req_queues; que++) {
1163 req = ha->req_q_map[que];
1164 if (!req)
1165 continue;
1166
1167 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++ ) {
1168 sp = req->outstanding_cmds[cnt];
1169
1170 if (sp) {
1171 sp_bsg = (struct srb_bsg*)sp->ctx;
1172
1173 if (((sp_bsg->ctx.type == SRB_CT_CMD) ||
1174 (sp_bsg->ctx.type == SRB_ELS_CMD_HST))
1175 && (sp_bsg->bsg_job == bsg_job)) {
1176 if (ha->isp_ops->abort_command(sp)) {
1177 DEBUG2(qla_printk(KERN_INFO, ha,
1178 "scsi(%ld): mbx abort_command failed\n", vha->host_no));
1179 bsg_job->req->errors =
1180 bsg_job->reply->result = -EIO;
1181 } else {
1182 DEBUG2(qla_printk(KERN_INFO, ha,
1183 "scsi(%ld): mbx abort_command success\n", vha->host_no));
1184 bsg_job->req->errors =
1185 bsg_job->reply->result = 0;
1186 }
1187 goto done;
1188 }
1189 }
1190 }
1191 }
1192 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1193 DEBUG2(qla_printk(KERN_INFO, ha,
1194 "scsi(%ld) SRB not found to abort\n", vha->host_no));
1195 bsg_job->req->errors = bsg_job->reply->result = -ENXIO;
1196 return 0;
1197
1198done:
1199 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1200 if (bsg_job->request->msgcode == FC_BSG_HST_CT)
1201 kfree(sp->fcport);
1202 kfree(sp->ctx);
1203 mempool_free(sp, ha->srb_mempool);
1204 return 0;
1205}