2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2012 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/kthread.h>
10 #include <linux/vmalloc.h>
11 #include <linux/delay.h>
13 /* BSG support for ELS/CT pass through */
15 qla2x00_bsg_job_done(void *data, void *ptr, int res)
17 srb_t *sp = (srb_t *)ptr;
18 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
19 struct fc_bsg_job *bsg_job = sp->u.bsg_job;
21 bsg_job->reply->result = res;
22 bsg_job->job_done(bsg_job);
27 qla2x00_bsg_sp_free(void *data, void *ptr)
29 srb_t *sp = (srb_t *)ptr;
30 struct scsi_qla_host *vha = sp->fcport->vha;
31 struct fc_bsg_job *bsg_job = sp->u.bsg_job;
32 struct qla_hw_data *ha = vha->hw;
34 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
35 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
37 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
38 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
40 if (sp->type == SRB_CT_CMD ||
41 sp->type == SRB_ELS_CMD_HST)
43 qla2x00_rel_sp(vha, sp);
47 qla24xx_fcp_prio_cfg_valid(scsi_qla_host_t *vha,
48 struct qla_fcp_prio_cfg *pri_cfg, uint8_t flag)
50 int i, ret, num_valid;
52 struct qla_fcp_prio_entry *pri_entry;
53 uint32_t *bcode_val_ptr, bcode_val;
57 bcode = (uint8_t *)pri_cfg;
58 bcode_val_ptr = (uint32_t *)pri_cfg;
59 bcode_val = (uint32_t)(*bcode_val_ptr);
61 if (bcode_val == 0xFFFFFFFF) {
62 /* No FCP Priority config data in flash */
63 ql_dbg(ql_dbg_user, vha, 0x7051,
64 "No FCP Priority config data.\n");
68 if (bcode[0] != 'H' || bcode[1] != 'Q' || bcode[2] != 'O' ||
70 /* Invalid FCP priority data header*/
71 ql_dbg(ql_dbg_user, vha, 0x7052,
72 "Invalid FCP Priority data header. bcode=0x%x.\n",
79 pri_entry = &pri_cfg->entry[0];
80 for (i = 0; i < pri_cfg->num_entries; i++) {
81 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
87 /* No valid FCP priority data entries */
88 ql_dbg(ql_dbg_user, vha, 0x7053,
89 "No valid FCP Priority data entries.\n");
92 /* FCP priority data is valid */
93 ql_dbg(ql_dbg_user, vha, 0x7054,
94 "Valid FCP priority data. num entries = %d.\n",
102 qla24xx_proc_fcp_prio_cfg_cmd(struct fc_bsg_job *bsg_job)
104 struct Scsi_Host *host = bsg_job->shost;
105 scsi_qla_host_t *vha = shost_priv(host);
106 struct qla_hw_data *ha = vha->hw;
111 if (!(IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || IS_QLA82XX(ha))) {
113 goto exit_fcp_prio_cfg;
116 /* Get the sub command */
117 oper = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
119 /* Only set config is allowed if config memory is not allocated */
120 if (!ha->fcp_prio_cfg && (oper != QLFC_FCP_PRIO_SET_CONFIG)) {
122 goto exit_fcp_prio_cfg;
125 case QLFC_FCP_PRIO_DISABLE:
126 if (ha->flags.fcp_prio_enabled) {
127 ha->flags.fcp_prio_enabled = 0;
128 ha->fcp_prio_cfg->attributes &=
129 ~FCP_PRIO_ATTR_ENABLE;
130 qla24xx_update_all_fcp_prio(vha);
131 bsg_job->reply->result = DID_OK;
134 bsg_job->reply->result = (DID_ERROR << 16);
135 goto exit_fcp_prio_cfg;
139 case QLFC_FCP_PRIO_ENABLE:
140 if (!ha->flags.fcp_prio_enabled) {
141 if (ha->fcp_prio_cfg) {
142 ha->flags.fcp_prio_enabled = 1;
143 ha->fcp_prio_cfg->attributes |=
144 FCP_PRIO_ATTR_ENABLE;
145 qla24xx_update_all_fcp_prio(vha);
146 bsg_job->reply->result = DID_OK;
149 bsg_job->reply->result = (DID_ERROR << 16);
150 goto exit_fcp_prio_cfg;
155 case QLFC_FCP_PRIO_GET_CONFIG:
156 len = bsg_job->reply_payload.payload_len;
157 if (!len || len > FCP_PRIO_CFG_SIZE) {
159 bsg_job->reply->result = (DID_ERROR << 16);
160 goto exit_fcp_prio_cfg;
163 bsg_job->reply->result = DID_OK;
164 bsg_job->reply->reply_payload_rcv_len =
166 bsg_job->reply_payload.sg_list,
167 bsg_job->reply_payload.sg_cnt, ha->fcp_prio_cfg,
172 case QLFC_FCP_PRIO_SET_CONFIG:
173 len = bsg_job->request_payload.payload_len;
174 if (!len || len > FCP_PRIO_CFG_SIZE) {
175 bsg_job->reply->result = (DID_ERROR << 16);
177 goto exit_fcp_prio_cfg;
180 if (!ha->fcp_prio_cfg) {
181 ha->fcp_prio_cfg = vmalloc(FCP_PRIO_CFG_SIZE);
182 if (!ha->fcp_prio_cfg) {
183 ql_log(ql_log_warn, vha, 0x7050,
184 "Unable to allocate memory for fcp prio "
185 "config data (%x).\n", FCP_PRIO_CFG_SIZE);
186 bsg_job->reply->result = (DID_ERROR << 16);
188 goto exit_fcp_prio_cfg;
192 memset(ha->fcp_prio_cfg, 0, FCP_PRIO_CFG_SIZE);
193 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
194 bsg_job->request_payload.sg_cnt, ha->fcp_prio_cfg,
197 /* validate fcp priority data */
199 if (!qla24xx_fcp_prio_cfg_valid(vha,
200 (struct qla_fcp_prio_cfg *) ha->fcp_prio_cfg, 1)) {
201 bsg_job->reply->result = (DID_ERROR << 16);
203 /* If buffer was invalidatic int
204 * fcp_prio_cfg is of no use
206 vfree(ha->fcp_prio_cfg);
207 ha->fcp_prio_cfg = NULL;
208 goto exit_fcp_prio_cfg;
211 ha->flags.fcp_prio_enabled = 0;
212 if (ha->fcp_prio_cfg->attributes & FCP_PRIO_ATTR_ENABLE)
213 ha->flags.fcp_prio_enabled = 1;
214 qla24xx_update_all_fcp_prio(vha);
215 bsg_job->reply->result = DID_OK;
223 bsg_job->job_done(bsg_job);
228 qla2x00_process_els(struct fc_bsg_job *bsg_job)
230 struct fc_rport *rport;
231 fc_port_t *fcport = NULL;
232 struct Scsi_Host *host;
233 scsi_qla_host_t *vha;
234 struct qla_hw_data *ha;
237 int req_sg_cnt, rsp_sg_cnt;
238 int rval = (DRIVER_ERROR << 16);
239 uint16_t nextlid = 0;
241 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
242 rport = bsg_job->rport;
243 fcport = *(fc_port_t **) rport->dd_data;
244 host = rport_to_shost(rport);
245 vha = shost_priv(host);
247 type = "FC_BSG_RPT_ELS";
249 host = bsg_job->shost;
250 vha = shost_priv(host);
252 type = "FC_BSG_HST_ELS_NOLOGIN";
255 /* pass through is supported only for ISP 4Gb or higher */
256 if (!IS_FWI2_CAPABLE(ha)) {
257 ql_dbg(ql_dbg_user, vha, 0x7001,
258 "ELS passthru not supported for ISP23xx based adapters.\n");
263 /* Multiple SG's are not supported for ELS requests */
264 if (bsg_job->request_payload.sg_cnt > 1 ||
265 bsg_job->reply_payload.sg_cnt > 1) {
266 ql_dbg(ql_dbg_user, vha, 0x7002,
267 "Multiple SG's are not suppored for ELS requests, "
268 "request_sg_cnt=%x reply_sg_cnt=%x.\n",
269 bsg_job->request_payload.sg_cnt,
270 bsg_job->reply_payload.sg_cnt);
275 /* ELS request for rport */
276 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
277 /* make sure the rport is logged in,
278 * if not perform fabric login
280 if (qla2x00_fabric_login(vha, fcport, &nextlid)) {
281 ql_dbg(ql_dbg_user, vha, 0x7003,
282 "Failed to login port %06X for ELS passthru.\n",
288 /* Allocate a dummy fcport structure, since functions
289 * preparing the IOCB and mailbox command retrieves port
290 * specific information from fcport structure. For Host based
291 * ELS commands there will be no fcport structure allocated
293 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
299 /* Initialize all required fields of fcport */
301 fcport->d_id.b.al_pa =
302 bsg_job->request->rqst_data.h_els.port_id[0];
303 fcport->d_id.b.area =
304 bsg_job->request->rqst_data.h_els.port_id[1];
305 fcport->d_id.b.domain =
306 bsg_job->request->rqst_data.h_els.port_id[2];
308 (fcport->d_id.b.al_pa == 0xFD) ?
309 NPH_FABRIC_CONTROLLER : NPH_F_PORT;
312 if (!vha->flags.online) {
313 ql_log(ql_log_warn, vha, 0x7005, "Host not online.\n");
319 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
320 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
323 goto done_free_fcport;
326 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
327 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
330 goto done_free_fcport;
333 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
334 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
335 ql_log(ql_log_warn, vha, 0x7008,
336 "dma mapping resulted in different sg counts, "
337 "request_sg_cnt: %x dma_request_sg_cnt:%x reply_sg_cnt:%x "
338 "dma_reply_sg_cnt:%x.\n", bsg_job->request_payload.sg_cnt,
339 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
344 /* Alloc SRB structure */
345 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
352 (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
353 SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
355 (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
356 "bsg_els_rpt" : "bsg_els_hst");
357 sp->u.bsg_job = bsg_job;
358 sp->free = qla2x00_bsg_sp_free;
359 sp->done = qla2x00_bsg_job_done;
361 ql_dbg(ql_dbg_user, vha, 0x700a,
362 "bsg rqst type: %s els type: %x - loop-id=%x "
363 "portid=%-2x%02x%02x.\n", type,
364 bsg_job->request->rqst_data.h_els.command_code, fcport->loop_id,
365 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa);
367 rval = qla2x00_start_sp(sp);
368 if (rval != QLA_SUCCESS) {
369 ql_log(ql_log_warn, vha, 0x700e,
370 "qla2x00_start_sp failed = %d\n", rval);
371 qla2x00_rel_sp(vha, sp);
378 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
379 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
380 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
381 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
382 goto done_free_fcport;
385 if (bsg_job->request->msgcode == FC_BSG_HST_ELS_NOLOGIN)
392 qla24xx_calc_ct_iocbs(uint16_t dsds)
398 iocbs += (dsds - 2) / 5;
406 qla2x00_process_ct(struct fc_bsg_job *bsg_job)
409 struct Scsi_Host *host = bsg_job->shost;
410 scsi_qla_host_t *vha = shost_priv(host);
411 struct qla_hw_data *ha = vha->hw;
412 int rval = (DRIVER_ERROR << 16);
413 int req_sg_cnt, rsp_sg_cnt;
415 struct fc_port *fcport;
416 char *type = "FC_BSG_HST_CT";
419 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
420 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
422 ql_log(ql_log_warn, vha, 0x700f,
423 "dma_map_sg return %d for request\n", req_sg_cnt);
428 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
429 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
431 ql_log(ql_log_warn, vha, 0x7010,
432 "dma_map_sg return %d for reply\n", rsp_sg_cnt);
437 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
438 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
439 ql_log(ql_log_warn, vha, 0x7011,
440 "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
441 "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
442 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
447 if (!vha->flags.online) {
448 ql_log(ql_log_warn, vha, 0x7012,
449 "Host is not online.\n");
455 (bsg_job->request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
459 loop_id = cpu_to_le16(NPH_SNS);
462 loop_id = vha->mgmt_svr_loop_id;
465 ql_dbg(ql_dbg_user, vha, 0x7013,
466 "Unknown loop id: %x.\n", loop_id);
471 /* Allocate a dummy fcport structure, since functions preparing the
472 * IOCB and mailbox command retrieves port specific information
473 * from fcport structure. For Host based ELS commands there will be
474 * no fcport structure allocated
476 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
478 ql_log(ql_log_warn, vha, 0x7014,
479 "Failed to allocate fcport.\n");
484 /* Initialize all required fields of fcport */
486 fcport->d_id.b.al_pa = bsg_job->request->rqst_data.h_ct.port_id[0];
487 fcport->d_id.b.area = bsg_job->request->rqst_data.h_ct.port_id[1];
488 fcport->d_id.b.domain = bsg_job->request->rqst_data.h_ct.port_id[2];
489 fcport->loop_id = loop_id;
491 /* Alloc SRB structure */
492 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
494 ql_log(ql_log_warn, vha, 0x7015,
495 "qla2x00_get_sp failed.\n");
497 goto done_free_fcport;
500 sp->type = SRB_CT_CMD;
502 sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
503 sp->u.bsg_job = bsg_job;
504 sp->free = qla2x00_bsg_sp_free;
505 sp->done = qla2x00_bsg_job_done;
507 ql_dbg(ql_dbg_user, vha, 0x7016,
508 "bsg rqst type: %s else type: %x - "
509 "loop-id=%x portid=%02x%02x%02x.\n", type,
510 (bsg_job->request->rqst_data.h_ct.preamble_word2 >> 16),
511 fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
512 fcport->d_id.b.al_pa);
514 rval = qla2x00_start_sp(sp);
515 if (rval != QLA_SUCCESS) {
516 ql_log(ql_log_warn, vha, 0x7017,
517 "qla2x00_start_sp failed=%d.\n", rval);
518 qla2x00_rel_sp(vha, sp);
520 goto done_free_fcport;
527 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
528 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
529 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
530 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
535 /* Disable loopback mode */
537 qla81xx_reset_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
542 uint16_t new_config[4];
543 struct qla_hw_data *ha = vha->hw;
545 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
546 goto done_reset_internal;
548 memset(new_config, 0 , sizeof(new_config));
549 if ((config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
550 ENABLE_INTERNAL_LOOPBACK ||
551 (config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
552 ENABLE_EXTERNAL_LOOPBACK) {
553 new_config[0] = config[0] & ~INTERNAL_LOOPBACK_MASK;
554 ql_dbg(ql_dbg_user, vha, 0x70bf, "new_config[0]=%02x\n",
555 (new_config[0] & INTERNAL_LOOPBACK_MASK));
556 memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ;
558 ha->notify_dcbx_comp = wait;
559 ha->notify_lb_portup_comp = wait2;
561 ret = qla81xx_set_port_config(vha, new_config);
562 if (ret != QLA_SUCCESS) {
563 ql_log(ql_log_warn, vha, 0x7025,
564 "Set port config failed.\n");
565 ha->notify_dcbx_comp = 0;
566 ha->notify_lb_portup_comp = 0;
568 goto done_reset_internal;
571 /* Wait for DCBX complete event */
572 if (wait && !wait_for_completion_timeout(&ha->dcbx_comp,
573 (DCBX_COMP_TIMEOUT * HZ))) {
574 ql_dbg(ql_dbg_user, vha, 0x7026,
575 "DCBX completion not received.\n");
576 ha->notify_dcbx_comp = 0;
577 ha->notify_lb_portup_comp = 0;
579 goto done_reset_internal;
581 ql_dbg(ql_dbg_user, vha, 0x7027,
582 "DCBX completion received.\n");
585 !wait_for_completion_timeout(&ha->lb_portup_comp,
586 (LB_PORTUP_COMP_TIMEOUT * HZ))) {
587 ql_dbg(ql_dbg_user, vha, 0x70c5,
588 "Port up completion not received.\n");
589 ha->notify_lb_portup_comp = 0;
591 goto done_reset_internal;
593 ql_dbg(ql_dbg_user, vha, 0x70c6,
594 "Port up completion received.\n");
596 ha->notify_dcbx_comp = 0;
597 ha->notify_lb_portup_comp = 0;
604 * Set the port configuration to enable the internal or external loopback
605 * depending on the loopback mode.
608 qla81xx_set_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
609 uint16_t *new_config, uint16_t mode)
613 struct qla_hw_data *ha = vha->hw;
615 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
616 goto done_set_internal;
618 if (mode == INTERNAL_LOOPBACK)
619 new_config[0] = config[0] | (ENABLE_INTERNAL_LOOPBACK << 1);
620 else if (mode == EXTERNAL_LOOPBACK)
621 new_config[0] = config[0] | (ENABLE_EXTERNAL_LOOPBACK << 1);
622 ql_dbg(ql_dbg_user, vha, 0x70be,
623 "new_config[0]=%02x\n", (new_config[0] & INTERNAL_LOOPBACK_MASK));
625 memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3);
627 ha->notify_dcbx_comp = 1;
628 ret = qla81xx_set_port_config(vha, new_config);
629 if (ret != QLA_SUCCESS) {
630 ql_log(ql_log_warn, vha, 0x7021,
631 "set port config failed.\n");
632 ha->notify_dcbx_comp = 0;
634 goto done_set_internal;
637 /* Wait for DCBX complete event */
638 if (!wait_for_completion_timeout(&ha->dcbx_comp,
639 (DCBX_COMP_TIMEOUT * HZ))) {
640 ql_dbg(ql_dbg_user, vha, 0x7022,
641 "DCBX completion not received.\n");
642 ret = qla81xx_reset_loopback_mode(vha, new_config, 0, 0);
644 * If the reset of the loopback mode doesn't work take a FCoE
645 * dump and reset the chip.
648 ha->isp_ops->fw_dump(vha, 0);
649 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
653 if (ha->flags.idc_compl_status) {
654 ql_dbg(ql_dbg_user, vha, 0x70c3,
655 "Bad status in IDC Completion AEN\n");
657 ha->flags.idc_compl_status = 0;
659 ql_dbg(ql_dbg_user, vha, 0x7023,
660 "DCBX completion received.\n");
663 ha->notify_dcbx_comp = 0;
670 qla2x00_process_loopback(struct fc_bsg_job *bsg_job)
672 struct Scsi_Host *host = bsg_job->shost;
673 scsi_qla_host_t *vha = shost_priv(host);
674 struct qla_hw_data *ha = vha->hw;
676 uint8_t command_sent;
678 struct msg_echo_lb elreq;
679 uint16_t response[MAILBOX_REGISTER_COUNT];
680 uint16_t config[4], new_config[4];
682 uint8_t *req_data = NULL;
683 dma_addr_t req_data_dma;
684 uint32_t req_data_len;
685 uint8_t *rsp_data = NULL;
686 dma_addr_t rsp_data_dma;
687 uint32_t rsp_data_len;
689 if (!vha->flags.online) {
690 ql_log(ql_log_warn, vha, 0x7019, "Host is not online.\n");
694 elreq.req_sg_cnt = dma_map_sg(&ha->pdev->dev,
695 bsg_job->request_payload.sg_list, bsg_job->request_payload.sg_cnt,
698 if (!elreq.req_sg_cnt) {
699 ql_log(ql_log_warn, vha, 0x701a,
700 "dma_map_sg returned %d for request.\n", elreq.req_sg_cnt);
704 elreq.rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
705 bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
708 if (!elreq.rsp_sg_cnt) {
709 ql_log(ql_log_warn, vha, 0x701b,
710 "dma_map_sg returned %d for reply.\n", elreq.rsp_sg_cnt);
712 goto done_unmap_req_sg;
715 if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
716 (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
717 ql_log(ql_log_warn, vha, 0x701c,
718 "dma mapping resulted in different sg counts, "
719 "request_sg_cnt: %x dma_request_sg_cnt: %x "
720 "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
721 bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
722 bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt);
726 req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
727 req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
728 &req_data_dma, GFP_KERNEL);
730 ql_log(ql_log_warn, vha, 0x701d,
731 "dma alloc failed for req_data.\n");
736 rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
737 &rsp_data_dma, GFP_KERNEL);
739 ql_log(ql_log_warn, vha, 0x7004,
740 "dma alloc failed for rsp_data.\n");
742 goto done_free_dma_req;
745 /* Copy the request buffer in req_data now */
746 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
747 bsg_job->request_payload.sg_cnt, req_data, req_data_len);
749 elreq.send_dma = req_data_dma;
750 elreq.rcv_dma = rsp_data_dma;
751 elreq.transfer_size = req_data_len;
753 elreq.options = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
755 if (atomic_read(&vha->loop_state) == LOOP_READY &&
756 (ha->current_topology == ISP_CFG_F ||
757 ((IS_QLA81XX(ha) || IS_QLA8031(ha)) &&
758 le32_to_cpu(*(uint32_t *)req_data) == ELS_OPCODE_BYTE
759 && req_data_len == MAX_ELS_FRAME_PAYLOAD)) &&
760 elreq.options == EXTERNAL_LOOPBACK) {
761 type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
762 ql_dbg(ql_dbg_user, vha, 0x701e,
763 "BSG request type: %s.\n", type);
764 command_sent = INT_DEF_LB_ECHO_CMD;
765 rval = qla2x00_echo_test(vha, &elreq, response);
767 if (IS_QLA81XX(ha) || IS_QLA8031(ha)) {
768 memset(config, 0, sizeof(config));
769 memset(new_config, 0, sizeof(new_config));
771 if (qla81xx_get_port_config(vha, config)) {
772 ql_log(ql_log_warn, vha, 0x701f,
773 "Get port config failed.\n");
775 goto done_free_dma_rsp;
778 if ((config[0] & INTERNAL_LOOPBACK_MASK) != 0) {
779 ql_dbg(ql_dbg_user, vha, 0x70c4,
780 "Loopback operation already in "
783 goto done_free_dma_rsp;
786 ql_dbg(ql_dbg_user, vha, 0x70c0,
787 "elreq.options=%04x\n", elreq.options);
789 if (elreq.options == EXTERNAL_LOOPBACK)
791 rval = qla81xx_set_loopback_mode(vha,
792 config, new_config, elreq.options);
794 rval = qla81xx_reset_loopback_mode(vha,
797 rval = qla81xx_set_loopback_mode(vha, config,
798 new_config, elreq.options);
802 goto done_free_dma_rsp;
805 type = "FC_BSG_HST_VENDOR_LOOPBACK";
806 ql_dbg(ql_dbg_user, vha, 0x7028,
807 "BSG request type: %s.\n", type);
809 command_sent = INT_DEF_LB_LOOPBACK_CMD;
810 rval = qla2x00_loopback_test(vha, &elreq, response);
812 if (response[0] == MBS_COMMAND_ERROR &&
813 response[1] == MBS_LB_RESET) {
814 ql_log(ql_log_warn, vha, 0x7029,
815 "MBX command error, Aborting ISP.\n");
816 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
817 qla2xxx_wake_dpc(vha);
818 qla2x00_wait_for_chip_reset(vha);
819 /* Also reset the MPI */
820 if (IS_QLA81XX(ha)) {
821 if (qla81xx_restart_mpi_firmware(vha) !=
823 ql_log(ql_log_warn, vha, 0x702a,
824 "MPI reset failed.\n");
829 goto done_free_dma_rsp;
835 /* Revert back to original port config
836 * Also clear internal loopback
838 ret = qla81xx_reset_loopback_mode(vha,
842 * If the reset of the loopback mode
843 * doesn't work take FCoE dump and then
846 ha->isp_ops->fw_dump(vha, 0);
847 set_bit(ISP_ABORT_NEEDED,
854 type = "FC_BSG_HST_VENDOR_LOOPBACK";
855 ql_dbg(ql_dbg_user, vha, 0x702b,
856 "BSG request type: %s.\n", type);
857 command_sent = INT_DEF_LB_LOOPBACK_CMD;
858 rval = qla2x00_loopback_test(vha, &elreq, response);
863 ql_log(ql_log_warn, vha, 0x702c,
864 "Vendor request %s failed.\n", type);
867 bsg_job->reply->result = (DID_ERROR << 16);
868 bsg_job->reply->reply_payload_rcv_len = 0;
870 ql_dbg(ql_dbg_user, vha, 0x702d,
871 "Vendor request %s completed.\n", type);
872 bsg_job->reply->result = (DID_OK << 16);
873 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
874 bsg_job->reply_payload.sg_cnt, rsp_data,
878 bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
879 sizeof(response) + sizeof(uint8_t);
880 fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) +
881 sizeof(struct fc_bsg_reply);
882 memcpy(fw_sts_ptr, response, sizeof(response));
883 fw_sts_ptr += sizeof(response);
884 *fw_sts_ptr = command_sent;
887 dma_free_coherent(&ha->pdev->dev, rsp_data_len,
888 rsp_data, rsp_data_dma);
890 dma_free_coherent(&ha->pdev->dev, req_data_len,
891 req_data, req_data_dma);
893 dma_unmap_sg(&ha->pdev->dev,
894 bsg_job->reply_payload.sg_list,
895 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
897 dma_unmap_sg(&ha->pdev->dev,
898 bsg_job->request_payload.sg_list,
899 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
901 bsg_job->job_done(bsg_job);
906 qla84xx_reset(struct fc_bsg_job *bsg_job)
908 struct Scsi_Host *host = bsg_job->shost;
909 scsi_qla_host_t *vha = shost_priv(host);
910 struct qla_hw_data *ha = vha->hw;
914 if (!IS_QLA84XX(ha)) {
915 ql_dbg(ql_dbg_user, vha, 0x702f, "Not 84xx, exiting.\n");
919 flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
921 rval = qla84xx_reset_chip(vha, flag == A84_ISSUE_RESET_DIAG_FW);
924 ql_log(ql_log_warn, vha, 0x7030,
925 "Vendor request 84xx reset failed.\n");
926 rval = (DID_ERROR << 16);
929 ql_dbg(ql_dbg_user, vha, 0x7031,
930 "Vendor request 84xx reset completed.\n");
931 bsg_job->reply->result = DID_OK;
932 bsg_job->job_done(bsg_job);
939 qla84xx_updatefw(struct fc_bsg_job *bsg_job)
941 struct Scsi_Host *host = bsg_job->shost;
942 scsi_qla_host_t *vha = shost_priv(host);
943 struct qla_hw_data *ha = vha->hw;
944 struct verify_chip_entry_84xx *mn = NULL;
945 dma_addr_t mn_dma, fw_dma;
954 if (!IS_QLA84XX(ha)) {
955 ql_dbg(ql_dbg_user, vha, 0x7032,
956 "Not 84xx, exiting.\n");
960 sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
961 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
963 ql_log(ql_log_warn, vha, 0x7033,
964 "dma_map_sg returned %d for request.\n", sg_cnt);
968 if (sg_cnt != bsg_job->request_payload.sg_cnt) {
969 ql_log(ql_log_warn, vha, 0x7034,
970 "DMA mapping resulted in different sg counts, "
971 "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
972 bsg_job->request_payload.sg_cnt, sg_cnt);
977 data_len = bsg_job->request_payload.payload_len;
978 fw_buf = dma_alloc_coherent(&ha->pdev->dev, data_len,
979 &fw_dma, GFP_KERNEL);
981 ql_log(ql_log_warn, vha, 0x7035,
982 "DMA alloc failed for fw_buf.\n");
987 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
988 bsg_job->request_payload.sg_cnt, fw_buf, data_len);
990 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
992 ql_log(ql_log_warn, vha, 0x7036,
993 "DMA alloc failed for fw buffer.\n");
995 goto done_free_fw_buf;
998 flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
999 fw_ver = le32_to_cpu(*((uint32_t *)((uint32_t *)fw_buf + 2)));
1001 memset(mn, 0, sizeof(struct access_chip_84xx));
1002 mn->entry_type = VERIFY_CHIP_IOCB_TYPE;
1003 mn->entry_count = 1;
1005 options = VCO_FORCE_UPDATE | VCO_END_OF_DATA;
1006 if (flag == A84_ISSUE_UPDATE_DIAGFW_CMD)
1007 options |= VCO_DIAG_FW;
1009 mn->options = cpu_to_le16(options);
1010 mn->fw_ver = cpu_to_le32(fw_ver);
1011 mn->fw_size = cpu_to_le32(data_len);
1012 mn->fw_seq_size = cpu_to_le32(data_len);
1013 mn->dseg_address[0] = cpu_to_le32(LSD(fw_dma));
1014 mn->dseg_address[1] = cpu_to_le32(MSD(fw_dma));
1015 mn->dseg_length = cpu_to_le32(data_len);
1016 mn->data_seg_cnt = cpu_to_le16(1);
1018 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
1021 ql_log(ql_log_warn, vha, 0x7037,
1022 "Vendor request 84xx updatefw failed.\n");
1024 rval = (DID_ERROR << 16);
1026 ql_dbg(ql_dbg_user, vha, 0x7038,
1027 "Vendor request 84xx updatefw completed.\n");
1029 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1030 bsg_job->reply->result = DID_OK;
1033 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
1036 dma_free_coherent(&ha->pdev->dev, data_len, fw_buf, fw_dma);
1039 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1040 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1043 bsg_job->job_done(bsg_job);
1048 qla84xx_mgmt_cmd(struct fc_bsg_job *bsg_job)
1050 struct Scsi_Host *host = bsg_job->shost;
1051 scsi_qla_host_t *vha = shost_priv(host);
1052 struct qla_hw_data *ha = vha->hw;
1053 struct access_chip_84xx *mn = NULL;
1054 dma_addr_t mn_dma, mgmt_dma;
1055 void *mgmt_b = NULL;
1057 struct qla_bsg_a84_mgmt *ql84_mgmt;
1059 uint32_t data_len = 0;
1060 uint32_t dma_direction = DMA_NONE;
1062 if (!IS_QLA84XX(ha)) {
1063 ql_log(ql_log_warn, vha, 0x703a,
1064 "Not 84xx, exiting.\n");
1068 ql84_mgmt = (struct qla_bsg_a84_mgmt *)((char *)bsg_job->request +
1069 sizeof(struct fc_bsg_request));
1071 ql_log(ql_log_warn, vha, 0x703b,
1072 "MGMT header not provided, exiting.\n");
1076 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
1078 ql_log(ql_log_warn, vha, 0x703c,
1079 "DMA alloc failed for fw buffer.\n");
1083 memset(mn, 0, sizeof(struct access_chip_84xx));
1084 mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
1085 mn->entry_count = 1;
1087 switch (ql84_mgmt->mgmt.cmd) {
1088 case QLA84_MGMT_READ_MEM:
1089 case QLA84_MGMT_GET_INFO:
1090 sg_cnt = dma_map_sg(&ha->pdev->dev,
1091 bsg_job->reply_payload.sg_list,
1092 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1094 ql_log(ql_log_warn, vha, 0x703d,
1095 "dma_map_sg returned %d for reply.\n", sg_cnt);
1100 dma_direction = DMA_FROM_DEVICE;
1102 if (sg_cnt != bsg_job->reply_payload.sg_cnt) {
1103 ql_log(ql_log_warn, vha, 0x703e,
1104 "DMA mapping resulted in different sg counts, "
1105 "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
1106 bsg_job->reply_payload.sg_cnt, sg_cnt);
1111 data_len = bsg_job->reply_payload.payload_len;
1113 mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
1114 &mgmt_dma, GFP_KERNEL);
1116 ql_log(ql_log_warn, vha, 0x703f,
1117 "DMA alloc failed for mgmt_b.\n");
1122 if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) {
1123 mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
1126 ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
1128 } else if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO) {
1129 mn->options = cpu_to_le16(ACO_REQUEST_INFO);
1131 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.info.type);
1135 ql84_mgmt->mgmt.mgmtp.u.info.context);
1139 case QLA84_MGMT_WRITE_MEM:
1140 sg_cnt = dma_map_sg(&ha->pdev->dev,
1141 bsg_job->request_payload.sg_list,
1142 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1145 ql_log(ql_log_warn, vha, 0x7040,
1146 "dma_map_sg returned %d.\n", sg_cnt);
1151 dma_direction = DMA_TO_DEVICE;
1153 if (sg_cnt != bsg_job->request_payload.sg_cnt) {
1154 ql_log(ql_log_warn, vha, 0x7041,
1155 "DMA mapping resulted in different sg counts, "
1156 "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
1157 bsg_job->request_payload.sg_cnt, sg_cnt);
1162 data_len = bsg_job->request_payload.payload_len;
1163 mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
1164 &mgmt_dma, GFP_KERNEL);
1166 ql_log(ql_log_warn, vha, 0x7042,
1167 "DMA alloc failed for mgmt_b.\n");
1172 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1173 bsg_job->request_payload.sg_cnt, mgmt_b, data_len);
1175 mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
1177 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
1180 case QLA84_MGMT_CHNG_CONFIG:
1181 mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
1183 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.id);
1186 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param0);
1189 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param1);
1197 if (ql84_mgmt->mgmt.cmd != QLA84_MGMT_CHNG_CONFIG) {
1198 mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->mgmt.len);
1199 mn->dseg_count = cpu_to_le16(1);
1200 mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma));
1201 mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma));
1202 mn->dseg_length = cpu_to_le32(ql84_mgmt->mgmt.len);
1205 rval = qla2x00_issue_iocb(vha, mn, mn_dma, 0);
1208 ql_log(ql_log_warn, vha, 0x7043,
1209 "Vendor request 84xx mgmt failed.\n");
1211 rval = (DID_ERROR << 16);
1214 ql_dbg(ql_dbg_user, vha, 0x7044,
1215 "Vendor request 84xx mgmt completed.\n");
1217 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1218 bsg_job->reply->result = DID_OK;
1220 if ((ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) ||
1221 (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO)) {
1222 bsg_job->reply->reply_payload_rcv_len =
1223 bsg_job->reply_payload.payload_len;
1225 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1226 bsg_job->reply_payload.sg_cnt, mgmt_b,
1233 dma_free_coherent(&ha->pdev->dev, data_len, mgmt_b, mgmt_dma);
1235 if (dma_direction == DMA_TO_DEVICE)
1236 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1237 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1238 else if (dma_direction == DMA_FROM_DEVICE)
1239 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
1240 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1243 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
1246 bsg_job->job_done(bsg_job);
1251 qla24xx_iidma(struct fc_bsg_job *bsg_job)
1253 struct Scsi_Host *host = bsg_job->shost;
1254 scsi_qla_host_t *vha = shost_priv(host);
1256 struct qla_port_param *port_param = NULL;
1257 fc_port_t *fcport = NULL;
1258 uint16_t mb[MAILBOX_REGISTER_COUNT];
1259 uint8_t *rsp_ptr = NULL;
1261 if (!IS_IIDMA_CAPABLE(vha->hw)) {
1262 ql_log(ql_log_info, vha, 0x7046, "iiDMA not supported.\n");
1266 port_param = (struct qla_port_param *)((char *)bsg_job->request +
1267 sizeof(struct fc_bsg_request));
1269 ql_log(ql_log_warn, vha, 0x7047,
1270 "port_param header not provided.\n");
1274 if (port_param->fc_scsi_addr.dest_type != EXT_DEF_TYPE_WWPN) {
1275 ql_log(ql_log_warn, vha, 0x7048,
1276 "Invalid destination type.\n");
1280 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1281 if (fcport->port_type != FCT_TARGET)
1284 if (memcmp(port_param->fc_scsi_addr.dest_addr.wwpn,
1285 fcport->port_name, sizeof(fcport->port_name)))
1291 ql_log(ql_log_warn, vha, 0x7049,
1292 "Failed to find port.\n");
1296 if (atomic_read(&fcport->state) != FCS_ONLINE) {
1297 ql_log(ql_log_warn, vha, 0x704a,
1298 "Port is not online.\n");
1302 if (fcport->flags & FCF_LOGIN_NEEDED) {
1303 ql_log(ql_log_warn, vha, 0x704b,
1304 "Remote port not logged in flags = 0x%x.\n", fcport->flags);
1308 if (port_param->mode)
1309 rval = qla2x00_set_idma_speed(vha, fcport->loop_id,
1310 port_param->speed, mb);
1312 rval = qla2x00_get_idma_speed(vha, fcport->loop_id,
1313 &port_param->speed, mb);
1316 ql_log(ql_log_warn, vha, 0x704c,
1317 "iIDMA cmd failed for %02x%02x%02x%02x%02x%02x%02x%02x -- "
1318 "%04x %x %04x %04x.\n", fcport->port_name[0],
1319 fcport->port_name[1], fcport->port_name[2],
1320 fcport->port_name[3], fcport->port_name[4],
1321 fcport->port_name[5], fcport->port_name[6],
1322 fcport->port_name[7], rval, fcport->fp_speed, mb[0], mb[1]);
1323 rval = (DID_ERROR << 16);
1325 if (!port_param->mode) {
1326 bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
1327 sizeof(struct qla_port_param);
1329 rsp_ptr = ((uint8_t *)bsg_job->reply) +
1330 sizeof(struct fc_bsg_reply);
1332 memcpy(rsp_ptr, port_param,
1333 sizeof(struct qla_port_param));
1336 bsg_job->reply->result = DID_OK;
1337 bsg_job->job_done(bsg_job);
1344 qla2x00_optrom_setup(struct fc_bsg_job *bsg_job, scsi_qla_host_t *vha,
1349 struct qla_hw_data *ha = vha->hw;
1351 if (unlikely(pci_channel_offline(ha->pdev)))
1354 start = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1355 if (start > ha->optrom_size) {
1356 ql_log(ql_log_warn, vha, 0x7055,
1357 "start %d > optrom_size %d.\n", start, ha->optrom_size);
1361 if (ha->optrom_state != QLA_SWAITING) {
1362 ql_log(ql_log_info, vha, 0x7056,
1363 "optrom_state %d.\n", ha->optrom_state);
1367 ha->optrom_region_start = start;
1368 ql_dbg(ql_dbg_user, vha, 0x7057, "is_update=%d.\n", is_update);
1370 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
1372 else if (start == (ha->flt_region_boot * 4) ||
1373 start == (ha->flt_region_fw * 4))
1375 else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
1376 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
1379 ql_log(ql_log_warn, vha, 0x7058,
1380 "Invalid start region 0x%x/0x%x.\n", start,
1381 bsg_job->request_payload.payload_len);
1385 ha->optrom_region_size = start +
1386 bsg_job->request_payload.payload_len > ha->optrom_size ?
1387 ha->optrom_size - start :
1388 bsg_job->request_payload.payload_len;
1389 ha->optrom_state = QLA_SWRITING;
1391 ha->optrom_region_size = start +
1392 bsg_job->reply_payload.payload_len > ha->optrom_size ?
1393 ha->optrom_size - start :
1394 bsg_job->reply_payload.payload_len;
1395 ha->optrom_state = QLA_SREADING;
1398 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
1399 if (!ha->optrom_buffer) {
1400 ql_log(ql_log_warn, vha, 0x7059,
1401 "Read: Unable to allocate memory for optrom retrieval "
1402 "(%x)\n", ha->optrom_region_size);
1404 ha->optrom_state = QLA_SWAITING;
1408 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
1413 qla2x00_read_optrom(struct fc_bsg_job *bsg_job)
1415 struct Scsi_Host *host = bsg_job->shost;
1416 scsi_qla_host_t *vha = shost_priv(host);
1417 struct qla_hw_data *ha = vha->hw;
1420 if (ha->flags.nic_core_reset_hdlr_active)
1423 rval = qla2x00_optrom_setup(bsg_job, vha, 0);
1427 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
1428 ha->optrom_region_start, ha->optrom_region_size);
1430 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1431 bsg_job->reply_payload.sg_cnt, ha->optrom_buffer,
1432 ha->optrom_region_size);
1434 bsg_job->reply->reply_payload_rcv_len = ha->optrom_region_size;
1435 bsg_job->reply->result = DID_OK;
1436 vfree(ha->optrom_buffer);
1437 ha->optrom_buffer = NULL;
1438 ha->optrom_state = QLA_SWAITING;
1439 bsg_job->job_done(bsg_job);
1444 qla2x00_update_optrom(struct fc_bsg_job *bsg_job)
1446 struct Scsi_Host *host = bsg_job->shost;
1447 scsi_qla_host_t *vha = shost_priv(host);
1448 struct qla_hw_data *ha = vha->hw;
1451 rval = qla2x00_optrom_setup(bsg_job, vha, 1);
1455 /* Set the isp82xx_no_md_cap not to capture minidump */
1456 ha->flags.isp82xx_no_md_cap = 1;
1458 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1459 bsg_job->request_payload.sg_cnt, ha->optrom_buffer,
1460 ha->optrom_region_size);
1462 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
1463 ha->optrom_region_start, ha->optrom_region_size);
1465 bsg_job->reply->result = DID_OK;
1466 vfree(ha->optrom_buffer);
1467 ha->optrom_buffer = NULL;
1468 ha->optrom_state = QLA_SWAITING;
1469 bsg_job->job_done(bsg_job);
1474 qla2x00_update_fru_versions(struct fc_bsg_job *bsg_job)
1476 struct Scsi_Host *host = bsg_job->shost;
1477 scsi_qla_host_t *vha = shost_priv(host);
1478 struct qla_hw_data *ha = vha->hw;
1480 uint8_t bsg[DMA_POOL_SIZE];
1481 struct qla_image_version_list *list = (void *)bsg;
1482 struct qla_image_version *image;
1485 void *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1487 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1488 EXT_STATUS_NO_MEMORY;
1492 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1493 bsg_job->request_payload.sg_cnt, list, sizeof(bsg));
1495 image = list->version;
1496 count = list->count;
1498 memcpy(sfp, &image->field_info, sizeof(image->field_info));
1499 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1500 image->field_address.device, image->field_address.offset,
1501 sizeof(image->field_info), image->field_address.option);
1503 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1510 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1513 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1516 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1517 bsg_job->reply->result = DID_OK << 16;
1518 bsg_job->job_done(bsg_job);
1524 qla2x00_read_fru_status(struct fc_bsg_job *bsg_job)
1526 struct Scsi_Host *host = bsg_job->shost;
1527 scsi_qla_host_t *vha = shost_priv(host);
1528 struct qla_hw_data *ha = vha->hw;
1530 uint8_t bsg[DMA_POOL_SIZE];
1531 struct qla_status_reg *sr = (void *)bsg;
1533 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1535 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1536 EXT_STATUS_NO_MEMORY;
1540 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1541 bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
1543 rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
1544 sr->field_address.device, sr->field_address.offset,
1545 sizeof(sr->status_reg), sr->field_address.option);
1546 sr->status_reg = *sfp;
1549 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1554 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1555 bsg_job->reply_payload.sg_cnt, sr, sizeof(*sr));
1557 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1560 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1563 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1564 bsg_job->reply->reply_payload_rcv_len = sizeof(*sr);
1565 bsg_job->reply->result = DID_OK << 16;
1566 bsg_job->job_done(bsg_job);
1572 qla2x00_write_fru_status(struct fc_bsg_job *bsg_job)
1574 struct Scsi_Host *host = bsg_job->shost;
1575 scsi_qla_host_t *vha = shost_priv(host);
1576 struct qla_hw_data *ha = vha->hw;
1578 uint8_t bsg[DMA_POOL_SIZE];
1579 struct qla_status_reg *sr = (void *)bsg;
1581 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1583 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1584 EXT_STATUS_NO_MEMORY;
1588 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1589 bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
1591 *sfp = sr->status_reg;
1592 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1593 sr->field_address.device, sr->field_address.offset,
1594 sizeof(sr->status_reg), sr->field_address.option);
1597 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1602 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1605 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1608 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1609 bsg_job->reply->result = DID_OK << 16;
1610 bsg_job->job_done(bsg_job);
1616 qla2x00_write_i2c(struct fc_bsg_job *bsg_job)
1618 struct Scsi_Host *host = bsg_job->shost;
1619 scsi_qla_host_t *vha = shost_priv(host);
1620 struct qla_hw_data *ha = vha->hw;
1622 uint8_t bsg[DMA_POOL_SIZE];
1623 struct qla_i2c_access *i2c = (void *)bsg;
1625 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1627 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1628 EXT_STATUS_NO_MEMORY;
1632 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1633 bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
1635 memcpy(sfp, i2c->buffer, i2c->length);
1636 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1637 i2c->device, i2c->offset, i2c->length, i2c->option);
1640 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1645 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1648 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1651 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1652 bsg_job->reply->result = DID_OK << 16;
1653 bsg_job->job_done(bsg_job);
1659 qla2x00_read_i2c(struct fc_bsg_job *bsg_job)
1661 struct Scsi_Host *host = bsg_job->shost;
1662 scsi_qla_host_t *vha = shost_priv(host);
1663 struct qla_hw_data *ha = vha->hw;
1665 uint8_t bsg[DMA_POOL_SIZE];
1666 struct qla_i2c_access *i2c = (void *)bsg;
1668 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1670 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1671 EXT_STATUS_NO_MEMORY;
1675 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1676 bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
1678 rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
1679 i2c->device, i2c->offset, i2c->length, i2c->option);
1682 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1687 memcpy(i2c->buffer, sfp, i2c->length);
1688 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1689 bsg_job->reply_payload.sg_cnt, i2c, sizeof(*i2c));
1691 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1694 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1697 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1698 bsg_job->reply->reply_payload_rcv_len = sizeof(*i2c);
1699 bsg_job->reply->result = DID_OK << 16;
1700 bsg_job->job_done(bsg_job);
1706 qla24xx_process_bidir_cmd(struct fc_bsg_job *bsg_job)
1708 struct Scsi_Host *host = bsg_job->shost;
1709 scsi_qla_host_t *vha = shost_priv(host);
1710 struct qla_hw_data *ha = vha->hw;
1712 uint32_t rval = EXT_STATUS_OK;
1713 uint16_t req_sg_cnt = 0;
1714 uint16_t rsp_sg_cnt = 0;
1715 uint16_t nextlid = 0;
1718 uint32_t req_data_len = 0;
1719 uint32_t rsp_data_len = 0;
1721 /* Check the type of the adapter */
1722 if (!IS_BIDI_CAPABLE(ha)) {
1723 ql_log(ql_log_warn, vha, 0x70a0,
1724 "This adapter is not supported\n");
1725 rval = EXT_STATUS_NOT_SUPPORTED;
1729 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
1730 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1731 test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
1732 rval = EXT_STATUS_BUSY;
1736 /* Check if host is online */
1737 if (!vha->flags.online) {
1738 ql_log(ql_log_warn, vha, 0x70a1,
1739 "Host is not online\n");
1740 rval = EXT_STATUS_DEVICE_OFFLINE;
1744 /* Check if cable is plugged in or not */
1745 if (vha->device_flags & DFLG_NO_CABLE) {
1746 ql_log(ql_log_warn, vha, 0x70a2,
1747 "Cable is unplugged...\n");
1748 rval = EXT_STATUS_INVALID_CFG;
1752 /* Check if the switch is connected or not */
1753 if (ha->current_topology != ISP_CFG_F) {
1754 ql_log(ql_log_warn, vha, 0x70a3,
1755 "Host is not connected to the switch\n");
1756 rval = EXT_STATUS_INVALID_CFG;
1760 /* Check if operating mode is P2P */
1761 if (ha->operating_mode != P2P) {
1762 ql_log(ql_log_warn, vha, 0x70a4,
1763 "Host is operating mode is not P2p\n");
1764 rval = EXT_STATUS_INVALID_CFG;
1768 thread_id = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1770 mutex_lock(&ha->selflogin_lock);
1771 if (vha->self_login_loop_id == 0) {
1772 /* Initialize all required fields of fcport */
1773 vha->bidir_fcport.vha = vha;
1774 vha->bidir_fcport.d_id.b.al_pa = vha->d_id.b.al_pa;
1775 vha->bidir_fcport.d_id.b.area = vha->d_id.b.area;
1776 vha->bidir_fcport.d_id.b.domain = vha->d_id.b.domain;
1777 vha->bidir_fcport.loop_id = vha->loop_id;
1779 if (qla2x00_fabric_login(vha, &(vha->bidir_fcport), &nextlid)) {
1780 ql_log(ql_log_warn, vha, 0x70a7,
1781 "Failed to login port %06X for bidirectional IOCB\n",
1782 vha->bidir_fcport.d_id.b24);
1783 mutex_unlock(&ha->selflogin_lock);
1784 rval = EXT_STATUS_MAILBOX;
1787 vha->self_login_loop_id = nextlid - 1;
1790 /* Assign the self login loop id to fcport */
1791 mutex_unlock(&ha->selflogin_lock);
1793 vha->bidir_fcport.loop_id = vha->self_login_loop_id;
1795 req_sg_cnt = dma_map_sg(&ha->pdev->dev,
1796 bsg_job->request_payload.sg_list,
1797 bsg_job->request_payload.sg_cnt,
1801 rval = EXT_STATUS_NO_MEMORY;
1805 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
1806 bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
1810 rval = EXT_STATUS_NO_MEMORY;
1811 goto done_unmap_req_sg;
1814 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
1815 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
1816 ql_dbg(ql_dbg_user, vha, 0x70a9,
1817 "Dma mapping resulted in different sg counts "
1818 "[request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt: "
1819 "%x dma_reply_sg_cnt: %x]\n",
1820 bsg_job->request_payload.sg_cnt, req_sg_cnt,
1821 bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
1822 rval = EXT_STATUS_NO_MEMORY;
1826 if (req_data_len != rsp_data_len) {
1827 rval = EXT_STATUS_BUSY;
1828 ql_log(ql_log_warn, vha, 0x70aa,
1829 "req_data_len != rsp_data_len\n");
1833 req_data_len = bsg_job->request_payload.payload_len;
1834 rsp_data_len = bsg_job->reply_payload.payload_len;
1837 /* Alloc SRB structure */
1838 sp = qla2x00_get_sp(vha, &(vha->bidir_fcport), GFP_KERNEL);
1840 ql_dbg(ql_dbg_user, vha, 0x70ac,
1841 "Alloc SRB structure failed\n");
1842 rval = EXT_STATUS_NO_MEMORY;
1846 /*Populate srb->ctx with bidir ctx*/
1847 sp->u.bsg_job = bsg_job;
1848 sp->free = qla2x00_bsg_sp_free;
1849 sp->type = SRB_BIDI_CMD;
1850 sp->done = qla2x00_bsg_job_done;
1852 /* Add the read and write sg count */
1853 tot_dsds = rsp_sg_cnt + req_sg_cnt;
1855 rval = qla2x00_start_bidir(sp, vha, tot_dsds);
1856 if (rval != EXT_STATUS_OK)
1858 /* the bsg request will be completed in the interrupt handler */
1862 mempool_free(sp, ha->srb_mempool);
1864 dma_unmap_sg(&ha->pdev->dev,
1865 bsg_job->reply_payload.sg_list,
1866 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1868 dma_unmap_sg(&ha->pdev->dev,
1869 bsg_job->request_payload.sg_list,
1870 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1873 /* Return an error vendor specific response
1874 * and complete the bsg request
1876 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
1877 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1878 bsg_job->reply->reply_payload_rcv_len = 0;
1879 bsg_job->reply->result = (DID_OK) << 16;
1880 bsg_job->job_done(bsg_job);
1881 /* Always retrun success, vendor rsp carries correct status */
1886 qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
1888 switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) {
1889 case QL_VND_LOOPBACK:
1890 return qla2x00_process_loopback(bsg_job);
1892 case QL_VND_A84_RESET:
1893 return qla84xx_reset(bsg_job);
1895 case QL_VND_A84_UPDATE_FW:
1896 return qla84xx_updatefw(bsg_job);
1898 case QL_VND_A84_MGMT_CMD:
1899 return qla84xx_mgmt_cmd(bsg_job);
1902 return qla24xx_iidma(bsg_job);
1904 case QL_VND_FCP_PRIO_CFG_CMD:
1905 return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job);
1907 case QL_VND_READ_FLASH:
1908 return qla2x00_read_optrom(bsg_job);
1910 case QL_VND_UPDATE_FLASH:
1911 return qla2x00_update_optrom(bsg_job);
1913 case QL_VND_SET_FRU_VERSION:
1914 return qla2x00_update_fru_versions(bsg_job);
1916 case QL_VND_READ_FRU_STATUS:
1917 return qla2x00_read_fru_status(bsg_job);
1919 case QL_VND_WRITE_FRU_STATUS:
1920 return qla2x00_write_fru_status(bsg_job);
1922 case QL_VND_WRITE_I2C:
1923 return qla2x00_write_i2c(bsg_job);
1925 case QL_VND_READ_I2C:
1926 return qla2x00_read_i2c(bsg_job);
1928 case QL_VND_DIAG_IO_CMD:
1929 return qla24xx_process_bidir_cmd(bsg_job);
1937 qla24xx_bsg_request(struct fc_bsg_job *bsg_job)
1940 struct fc_rport *rport;
1941 fc_port_t *fcport = NULL;
1942 struct Scsi_Host *host;
1943 scsi_qla_host_t *vha;
1945 /* In case no data transferred. */
1946 bsg_job->reply->reply_payload_rcv_len = 0;
1948 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
1949 rport = bsg_job->rport;
1950 fcport = *(fc_port_t **) rport->dd_data;
1951 host = rport_to_shost(rport);
1952 vha = shost_priv(host);
1954 host = bsg_job->shost;
1955 vha = shost_priv(host);
1958 if (qla2x00_reset_active(vha)) {
1959 ql_dbg(ql_dbg_user, vha, 0x709f,
1960 "BSG: ISP abort active/needed -- cmd=%d.\n",
1961 bsg_job->request->msgcode);
1965 ql_dbg(ql_dbg_user, vha, 0x7000,
1966 "Entered %s msgcode=0x%x.\n", __func__, bsg_job->request->msgcode);
1968 switch (bsg_job->request->msgcode) {
1969 case FC_BSG_RPT_ELS:
1970 case FC_BSG_HST_ELS_NOLOGIN:
1971 ret = qla2x00_process_els(bsg_job);
1974 ret = qla2x00_process_ct(bsg_job);
1976 case FC_BSG_HST_VENDOR:
1977 ret = qla2x00_process_vendor_specific(bsg_job);
1979 case FC_BSG_HST_ADD_RPORT:
1980 case FC_BSG_HST_DEL_RPORT:
1983 ql_log(ql_log_warn, vha, 0x705a, "Unsupported BSG request.\n");
1990 qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job)
1992 scsi_qla_host_t *vha = shost_priv(bsg_job->shost);
1993 struct qla_hw_data *ha = vha->hw;
1996 unsigned long flags;
1997 struct req_que *req;
1999 /* find the bsg job from the active list of commands */
2000 spin_lock_irqsave(&ha->hardware_lock, flags);
2001 for (que = 0; que < ha->max_req_queues; que++) {
2002 req = ha->req_q_map[que];
2006 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
2007 sp = req->outstanding_cmds[cnt];
2009 if (((sp->type == SRB_CT_CMD) ||
2010 (sp->type == SRB_ELS_CMD_HST))
2011 && (sp->u.bsg_job == bsg_job)) {
2012 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2013 if (ha->isp_ops->abort_command(sp)) {
2014 ql_log(ql_log_warn, vha, 0x7089,
2015 "mbx abort_command "
2017 bsg_job->req->errors =
2018 bsg_job->reply->result = -EIO;
2020 ql_dbg(ql_dbg_user, vha, 0x708a,
2021 "mbx abort_command "
2023 bsg_job->req->errors =
2024 bsg_job->reply->result = 0;
2026 spin_lock_irqsave(&ha->hardware_lock, flags);
2032 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2033 ql_log(ql_log_info, vha, 0x708b, "SRB not found to abort.\n");
2034 bsg_job->req->errors = bsg_job->reply->result = -ENXIO;
2038 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2039 if (bsg_job->request->msgcode == FC_BSG_HST_CT)
2041 qla2x00_rel_sp(vha, sp);