2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2011 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_get_ctx_bsg_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size)
18 struct qla_hw_data *ha = vha->hw;
21 sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
24 ctx = kzalloc(size, GFP_KERNEL);
26 mempool_free(sp, ha->srb_mempool);
31 memset(sp, 0, sizeof(*sp));
40 qla24xx_fcp_prio_cfg_valid(scsi_qla_host_t *vha,
41 struct qla_fcp_prio_cfg *pri_cfg, uint8_t flag)
43 int i, ret, num_valid;
45 struct qla_fcp_prio_entry *pri_entry;
46 uint32_t *bcode_val_ptr, bcode_val;
50 bcode = (uint8_t *)pri_cfg;
51 bcode_val_ptr = (uint32_t *)pri_cfg;
52 bcode_val = (uint32_t)(*bcode_val_ptr);
54 if (bcode_val == 0xFFFFFFFF) {
55 /* No FCP Priority config data in flash */
56 ql_dbg(ql_dbg_user, vha, 0x7051,
57 "No FCP Priority config data.\n");
61 if (bcode[0] != 'H' || bcode[1] != 'Q' || bcode[2] != 'O' ||
63 /* Invalid FCP priority data header*/
64 ql_dbg(ql_dbg_user, vha, 0x7052,
65 "Invalid FCP Priority data header. bcode=0x%x.\n",
72 pri_entry = &pri_cfg->entry[0];
73 for (i = 0; i < pri_cfg->num_entries; i++) {
74 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
80 /* No valid FCP priority data entries */
81 ql_dbg(ql_dbg_user, vha, 0x7053,
82 "No valid FCP Priority data entries.\n");
85 /* FCP priority data is valid */
86 ql_dbg(ql_dbg_user, vha, 0x7054,
87 "Valid FCP priority data. num entries = %d.\n",
95 qla24xx_proc_fcp_prio_cfg_cmd(struct fc_bsg_job *bsg_job)
97 struct Scsi_Host *host = bsg_job->shost;
98 scsi_qla_host_t *vha = shost_priv(host);
99 struct qla_hw_data *ha = vha->hw;
104 bsg_job->reply->reply_payload_rcv_len = 0;
106 if (!(IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || IS_QLA82XX(ha))) {
108 goto exit_fcp_prio_cfg;
111 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
112 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
113 test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
115 goto exit_fcp_prio_cfg;
118 /* Get the sub command */
119 oper = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
121 /* Only set config is allowed if config memory is not allocated */
122 if (!ha->fcp_prio_cfg && (oper != QLFC_FCP_PRIO_SET_CONFIG)) {
124 goto exit_fcp_prio_cfg;
127 case QLFC_FCP_PRIO_DISABLE:
128 if (ha->flags.fcp_prio_enabled) {
129 ha->flags.fcp_prio_enabled = 0;
130 ha->fcp_prio_cfg->attributes &=
131 ~FCP_PRIO_ATTR_ENABLE;
132 qla24xx_update_all_fcp_prio(vha);
133 bsg_job->reply->result = DID_OK;
136 bsg_job->reply->result = (DID_ERROR << 16);
137 goto exit_fcp_prio_cfg;
141 case QLFC_FCP_PRIO_ENABLE:
142 if (!ha->flags.fcp_prio_enabled) {
143 if (ha->fcp_prio_cfg) {
144 ha->flags.fcp_prio_enabled = 1;
145 ha->fcp_prio_cfg->attributes |=
146 FCP_PRIO_ATTR_ENABLE;
147 qla24xx_update_all_fcp_prio(vha);
148 bsg_job->reply->result = DID_OK;
151 bsg_job->reply->result = (DID_ERROR << 16);
152 goto exit_fcp_prio_cfg;
157 case QLFC_FCP_PRIO_GET_CONFIG:
158 len = bsg_job->reply_payload.payload_len;
159 if (!len || len > FCP_PRIO_CFG_SIZE) {
161 bsg_job->reply->result = (DID_ERROR << 16);
162 goto exit_fcp_prio_cfg;
165 bsg_job->reply->result = DID_OK;
166 bsg_job->reply->reply_payload_rcv_len =
168 bsg_job->reply_payload.sg_list,
169 bsg_job->reply_payload.sg_cnt, ha->fcp_prio_cfg,
174 case QLFC_FCP_PRIO_SET_CONFIG:
175 len = bsg_job->request_payload.payload_len;
176 if (!len || len > FCP_PRIO_CFG_SIZE) {
177 bsg_job->reply->result = (DID_ERROR << 16);
179 goto exit_fcp_prio_cfg;
182 if (!ha->fcp_prio_cfg) {
183 ha->fcp_prio_cfg = vmalloc(FCP_PRIO_CFG_SIZE);
184 if (!ha->fcp_prio_cfg) {
185 ql_log(ql_log_warn, vha, 0x7050,
186 "Unable to allocate memory for fcp prio "
187 "config data (%x).\n", FCP_PRIO_CFG_SIZE);
188 bsg_job->reply->result = (DID_ERROR << 16);
190 goto exit_fcp_prio_cfg;
194 memset(ha->fcp_prio_cfg, 0, FCP_PRIO_CFG_SIZE);
195 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
196 bsg_job->request_payload.sg_cnt, ha->fcp_prio_cfg,
199 /* validate fcp priority data */
201 if (!qla24xx_fcp_prio_cfg_valid(vha,
202 (struct qla_fcp_prio_cfg *) ha->fcp_prio_cfg, 1)) {
203 bsg_job->reply->result = (DID_ERROR << 16);
205 /* If buffer was invalidatic int
206 * fcp_prio_cfg is of no use
208 vfree(ha->fcp_prio_cfg);
209 ha->fcp_prio_cfg = NULL;
210 goto exit_fcp_prio_cfg;
213 ha->flags.fcp_prio_enabled = 0;
214 if (ha->fcp_prio_cfg->attributes & FCP_PRIO_ATTR_ENABLE)
215 ha->flags.fcp_prio_enabled = 1;
216 qla24xx_update_all_fcp_prio(vha);
217 bsg_job->reply->result = DID_OK;
224 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;
242 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
243 rport = bsg_job->rport;
244 fcport = *(fc_port_t **) rport->dd_data;
245 host = rport_to_shost(rport);
246 vha = shost_priv(host);
248 type = "FC_BSG_RPT_ELS";
250 host = bsg_job->shost;
251 vha = shost_priv(host);
253 type = "FC_BSG_HST_ELS_NOLOGIN";
256 /* pass through is supported only for ISP 4Gb or higher */
257 if (!IS_FWI2_CAPABLE(ha)) {
258 ql_dbg(ql_dbg_user, vha, 0x7001,
259 "ELS passthru not supported for ISP23xx based adapters.\n");
264 /* Multiple SG's are not supported for ELS requests */
265 if (bsg_job->request_payload.sg_cnt > 1 ||
266 bsg_job->reply_payload.sg_cnt > 1) {
267 ql_dbg(ql_dbg_user, vha, 0x7002,
268 "Multiple SG's are not suppored for ELS requests, "
269 "request_sg_cnt=%x reply_sg_cnt=%x.\n",
270 bsg_job->request_payload.sg_cnt,
271 bsg_job->reply_payload.sg_cnt);
276 /* ELS request for rport */
277 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
278 /* make sure the rport is logged in,
279 * if not perform fabric login
281 if (qla2x00_fabric_login(vha, fcport, &nextlid)) {
282 ql_dbg(ql_dbg_user, vha, 0x7003,
283 "Failed to login port %06X for ELS passthru.\n",
289 /* Allocate a dummy fcport structure, since functions
290 * preparing the IOCB and mailbox command retrieves port
291 * specific information from fcport structure. For Host based
292 * ELS commands there will be no fcport structure allocated
294 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
300 /* Initialize all required fields of fcport */
302 fcport->vp_idx = vha->vp_idx;
303 fcport->d_id.b.al_pa =
304 bsg_job->request->rqst_data.h_els.port_id[0];
305 fcport->d_id.b.area =
306 bsg_job->request->rqst_data.h_els.port_id[1];
307 fcport->d_id.b.domain =
308 bsg_job->request->rqst_data.h_els.port_id[2];
310 (fcport->d_id.b.al_pa == 0xFD) ?
311 NPH_FABRIC_CONTROLLER : NPH_F_PORT;
314 if (!vha->flags.online) {
315 ql_log(ql_log_warn, vha, 0x7005, "Host not online.\n");
321 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
322 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
325 goto done_free_fcport;
328 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
329 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
332 goto done_free_fcport;
335 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
336 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
337 ql_log(ql_log_warn, vha, 0x7008,
338 "dma mapping resulted in different sg counts, "
339 "request_sg_cnt: %x dma_request_sg_cnt:%x reply_sg_cnt:%x "
340 "dma_reply_sg_cnt:%x.\n", bsg_job->request_payload.sg_cnt,
341 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
346 /* Alloc SRB structure */
347 sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_ctx));
355 (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
356 SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
358 (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
359 "bsg_els_rpt" : "bsg_els_hst");
360 els->u.bsg_job = bsg_job;
362 ql_dbg(ql_dbg_user, vha, 0x700a,
363 "bsg rqst type: %s els type: %x - loop-id=%x "
364 "portid=%-2x%02x%02x.\n", type,
365 bsg_job->request->rqst_data.h_els.command_code, fcport->loop_id,
366 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa);
368 rval = qla2x00_start_sp(sp);
369 if (rval != QLA_SUCCESS) {
370 ql_log(ql_log_warn, vha, 0x700e,
371 "qla2x00_start_sp failed = %d\n", rval);
373 mempool_free(sp, ha->srb_mempool);
380 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
381 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
382 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
383 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
384 goto done_free_fcport;
387 if (bsg_job->request->msgcode == FC_BSG_HST_ELS_NOLOGIN)
394 qla24xx_calc_ct_iocbs(uint16_t dsds)
400 iocbs += (dsds - 2) / 5;
408 qla2x00_process_ct(struct fc_bsg_job *bsg_job)
411 struct Scsi_Host *host = bsg_job->shost;
412 scsi_qla_host_t *vha = shost_priv(host);
413 struct qla_hw_data *ha = vha->hw;
414 int rval = (DRIVER_ERROR << 16);
415 int req_sg_cnt, rsp_sg_cnt;
417 struct fc_port *fcport;
418 char *type = "FC_BSG_HST_CT";
422 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
423 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
425 ql_log(ql_log_warn, vha, 0x700f,
426 "dma_map_sg return %d for request\n", req_sg_cnt);
431 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
432 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
434 ql_log(ql_log_warn, vha, 0x7010,
435 "dma_map_sg return %d for reply\n", rsp_sg_cnt);
440 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
441 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
442 ql_log(ql_log_warn, vha, 0x7011,
443 "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
444 "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
445 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
450 if (!vha->flags.online) {
451 ql_log(ql_log_warn, vha, 0x7012,
452 "Host is not online.\n");
458 (bsg_job->request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
462 loop_id = cpu_to_le16(NPH_SNS);
465 loop_id = vha->mgmt_svr_loop_id;
468 ql_dbg(ql_dbg_user, vha, 0x7013,
469 "Unknown loop id: %x.\n", loop_id);
474 /* Allocate a dummy fcport structure, since functions preparing the
475 * IOCB and mailbox command retrieves port specific information
476 * from fcport structure. For Host based ELS commands there will be
477 * no fcport structure allocated
479 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
481 ql_log(ql_log_warn, vha, 0x7014,
482 "Failed to allocate fcport.\n");
487 /* Initialize all required fields of fcport */
489 fcport->vp_idx = vha->vp_idx;
490 fcport->d_id.b.al_pa = bsg_job->request->rqst_data.h_ct.port_id[0];
491 fcport->d_id.b.area = bsg_job->request->rqst_data.h_ct.port_id[1];
492 fcport->d_id.b.domain = bsg_job->request->rqst_data.h_ct.port_id[2];
493 fcport->loop_id = loop_id;
495 /* Alloc SRB structure */
496 sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_ctx));
498 ql_log(ql_log_warn, vha, 0x7015,
499 "qla2x00_get_ctx_bsg_sp failed.\n");
501 goto done_free_fcport;
505 ct->type = SRB_CT_CMD;
507 ct->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
508 ct->u.bsg_job = bsg_job;
510 ql_dbg(ql_dbg_user, vha, 0x7016,
511 "bsg rqst type: %s else type: %x - "
512 "loop-id=%x portid=%02x%02x%02x.\n", type,
513 (bsg_job->request->rqst_data.h_ct.preamble_word2 >> 16),
514 fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
515 fcport->d_id.b.al_pa);
517 rval = qla2x00_start_sp(sp);
518 if (rval != QLA_SUCCESS) {
519 ql_log(ql_log_warn, vha, 0x7017,
520 "qla2x00_start_sp failed=%d.\n", rval);
522 mempool_free(sp, ha->srb_mempool);
524 goto done_free_fcport;
531 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
532 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
533 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
534 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
539 /* Set the port configuration to enable the
540 * internal loopback on ISP81XX
543 qla81xx_set_internal_loopback(scsi_qla_host_t *vha, uint16_t *config,
544 uint16_t *new_config)
548 struct qla_hw_data *ha = vha->hw;
551 goto done_set_internal;
553 new_config[0] = config[0] | (ENABLE_INTERNAL_LOOPBACK << 1);
554 memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ;
556 ha->notify_dcbx_comp = 1;
557 ret = qla81xx_set_port_config(vha, new_config);
558 if (ret != QLA_SUCCESS) {
559 ql_log(ql_log_warn, vha, 0x7021,
560 "set port config failed.\n");
561 ha->notify_dcbx_comp = 0;
563 goto done_set_internal;
566 /* Wait for DCBX complete event */
567 if (!wait_for_completion_timeout(&ha->dcbx_comp, (20 * HZ))) {
568 ql_dbg(ql_dbg_user, vha, 0x7022,
569 "State change notification not received.\n");
571 ql_dbg(ql_dbg_user, vha, 0x7023,
572 "State change received.\n");
574 ha->notify_dcbx_comp = 0;
580 /* Set the port configuration to disable the
581 * internal loopback on ISP81XX
584 qla81xx_reset_internal_loopback(scsi_qla_host_t *vha, uint16_t *config,
589 uint16_t new_config[4];
590 struct qla_hw_data *ha = vha->hw;
593 goto done_reset_internal;
595 memset(new_config, 0 , sizeof(new_config));
596 if ((config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
597 ENABLE_INTERNAL_LOOPBACK) {
598 new_config[0] = config[0] & ~INTERNAL_LOOPBACK_MASK;
599 memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ;
601 ha->notify_dcbx_comp = wait;
602 ret = qla81xx_set_port_config(vha, new_config);
603 if (ret != QLA_SUCCESS) {
604 ql_log(ql_log_warn, vha, 0x7025,
605 "Set port config failed.\n");
606 ha->notify_dcbx_comp = 0;
608 goto done_reset_internal;
611 /* Wait for DCBX complete event */
612 if (wait && !wait_for_completion_timeout(&ha->dcbx_comp,
614 ql_dbg(ql_dbg_user, vha, 0x7026,
615 "State change notification not received.\n");
616 ha->notify_dcbx_comp = 0;
618 goto done_reset_internal;
620 ql_dbg(ql_dbg_user, vha, 0x7027,
621 "State change received.\n");
623 ha->notify_dcbx_comp = 0;
630 qla2x00_process_loopback(struct fc_bsg_job *bsg_job)
632 struct Scsi_Host *host = bsg_job->shost;
633 scsi_qla_host_t *vha = shost_priv(host);
634 struct qla_hw_data *ha = vha->hw;
636 uint8_t command_sent;
638 struct msg_echo_lb elreq;
639 uint16_t response[MAILBOX_REGISTER_COUNT];
640 uint16_t config[4], new_config[4];
642 uint8_t *req_data = NULL;
643 dma_addr_t req_data_dma;
644 uint32_t req_data_len;
645 uint8_t *rsp_data = NULL;
646 dma_addr_t rsp_data_dma;
647 uint32_t rsp_data_len;
649 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
650 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
651 test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
652 ql_log(ql_log_warn, vha, 0x7018, "Abort active or needed.\n");
656 if (!vha->flags.online) {
657 ql_log(ql_log_warn, vha, 0x7019, "Host is not online.\n");
661 elreq.req_sg_cnt = dma_map_sg(&ha->pdev->dev,
662 bsg_job->request_payload.sg_list, bsg_job->request_payload.sg_cnt,
665 if (!elreq.req_sg_cnt) {
666 ql_log(ql_log_warn, vha, 0x701a,
667 "dma_map_sg returned %d for request.\n", elreq.req_sg_cnt);
671 elreq.rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
672 bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
675 if (!elreq.rsp_sg_cnt) {
676 ql_log(ql_log_warn, vha, 0x701b,
677 "dma_map_sg returned %d for reply.\n", elreq.rsp_sg_cnt);
679 goto done_unmap_req_sg;
682 if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
683 (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
684 ql_log(ql_log_warn, vha, 0x701c,
685 "dma mapping resulted in different sg counts, "
686 "request_sg_cnt: %x dma_request_sg_cnt: %x "
687 "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
688 bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
689 bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt);
693 req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
694 req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
695 &req_data_dma, GFP_KERNEL);
697 ql_log(ql_log_warn, vha, 0x701d,
698 "dma alloc failed for req_data.\n");
703 rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
704 &rsp_data_dma, GFP_KERNEL);
706 ql_log(ql_log_warn, vha, 0x7004,
707 "dma alloc failed for rsp_data.\n");
709 goto done_free_dma_req;
712 /* Copy the request buffer in req_data now */
713 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
714 bsg_job->request_payload.sg_cnt, req_data, req_data_len);
716 elreq.send_dma = req_data_dma;
717 elreq.rcv_dma = rsp_data_dma;
718 elreq.transfer_size = req_data_len;
720 elreq.options = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
722 if ((ha->current_topology == ISP_CFG_F ||
723 (atomic_read(&vha->loop_state) == LOOP_DOWN) ||
725 le32_to_cpu(*(uint32_t *)req_data) == ELS_OPCODE_BYTE
726 && req_data_len == MAX_ELS_FRAME_PAYLOAD)) &&
727 elreq.options == EXTERNAL_LOOPBACK) {
728 type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
729 ql_dbg(ql_dbg_user, vha, 0x701e,
730 "BSG request type: %s.\n", type);
731 command_sent = INT_DEF_LB_ECHO_CMD;
732 rval = qla2x00_echo_test(vha, &elreq, response);
734 if (IS_QLA81XX(ha)) {
735 memset(config, 0, sizeof(config));
736 memset(new_config, 0, sizeof(new_config));
737 if (qla81xx_get_port_config(vha, config)) {
738 ql_log(ql_log_warn, vha, 0x701f,
739 "Get port config failed.\n");
740 bsg_job->reply->reply_payload_rcv_len = 0;
741 bsg_job->reply->result = (DID_ERROR << 16);
743 goto done_free_dma_req;
746 if (elreq.options != EXTERNAL_LOOPBACK) {
747 ql_dbg(ql_dbg_user, vha, 0x7020,
748 "Internal: curent port config = %x\n",
750 if (qla81xx_set_internal_loopback(vha, config,
752 ql_log(ql_log_warn, vha, 0x7024,
753 "Internal loopback failed.\n");
754 bsg_job->reply->reply_payload_rcv_len =
756 bsg_job->reply->result =
759 goto done_free_dma_req;
762 /* For external loopback to work
763 * ensure internal loopback is disabled
765 if (qla81xx_reset_internal_loopback(vha,
767 bsg_job->reply->reply_payload_rcv_len =
769 bsg_job->reply->result =
772 goto done_free_dma_req;
776 type = "FC_BSG_HST_VENDOR_LOOPBACK";
777 ql_dbg(ql_dbg_user, vha, 0x7028,
778 "BSG request type: %s.\n", type);
780 command_sent = INT_DEF_LB_LOOPBACK_CMD;
781 rval = qla2x00_loopback_test(vha, &elreq, response);
784 /* Revert back to original port config
785 * Also clear internal loopback
787 qla81xx_reset_internal_loopback(vha,
791 if (response[0] == MBS_COMMAND_ERROR &&
792 response[1] == MBS_LB_RESET) {
793 ql_log(ql_log_warn, vha, 0x7029,
794 "MBX command error, Aborting ISP.\n");
795 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
796 qla2xxx_wake_dpc(vha);
797 qla2x00_wait_for_chip_reset(vha);
798 /* Also reset the MPI */
799 if (qla81xx_restart_mpi_firmware(vha) !=
801 ql_log(ql_log_warn, vha, 0x702a,
802 "MPI reset failed.\n");
805 bsg_job->reply->reply_payload_rcv_len = 0;
806 bsg_job->reply->result = (DID_ERROR << 16);
808 goto done_free_dma_req;
811 type = "FC_BSG_HST_VENDOR_LOOPBACK";
812 ql_dbg(ql_dbg_user, vha, 0x702b,
813 "BSG request type: %s.\n", type);
814 command_sent = INT_DEF_LB_LOOPBACK_CMD;
815 rval = qla2x00_loopback_test(vha, &elreq, response);
820 ql_log(ql_log_warn, vha, 0x702c,
821 "Vendor request %s failed.\n", type);
823 fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) +
824 sizeof(struct fc_bsg_reply);
826 memcpy(fw_sts_ptr, response, sizeof(response));
827 fw_sts_ptr += sizeof(response);
828 *fw_sts_ptr = command_sent;
830 bsg_job->reply->reply_payload_rcv_len = 0;
831 bsg_job->reply->result = (DID_ERROR << 16);
833 ql_dbg(ql_dbg_user, vha, 0x702d,
834 "Vendor request %s completed.\n", type);
836 bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
837 sizeof(response) + sizeof(uint8_t);
838 bsg_job->reply->reply_payload_rcv_len =
839 bsg_job->reply_payload.payload_len;
840 fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) +
841 sizeof(struct fc_bsg_reply);
842 memcpy(fw_sts_ptr, response, sizeof(response));
843 fw_sts_ptr += sizeof(response);
844 *fw_sts_ptr = command_sent;
845 bsg_job->reply->result = DID_OK;
846 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
847 bsg_job->reply_payload.sg_cnt, rsp_data,
850 bsg_job->job_done(bsg_job);
852 dma_free_coherent(&ha->pdev->dev, rsp_data_len,
853 rsp_data, rsp_data_dma);
855 dma_free_coherent(&ha->pdev->dev, req_data_len,
856 req_data, req_data_dma);
858 dma_unmap_sg(&ha->pdev->dev,
859 bsg_job->reply_payload.sg_list,
860 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
862 dma_unmap_sg(&ha->pdev->dev,
863 bsg_job->request_payload.sg_list,
864 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
869 qla84xx_reset(struct fc_bsg_job *bsg_job)
871 struct Scsi_Host *host = bsg_job->shost;
872 scsi_qla_host_t *vha = shost_priv(host);
873 struct qla_hw_data *ha = vha->hw;
877 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
878 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
879 test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
880 ql_log(ql_log_warn, vha, 0x702e, "Abort active or needed.\n");
884 if (!IS_QLA84XX(ha)) {
885 ql_dbg(ql_dbg_user, vha, 0x702f, "Not 84xx, exiting.\n");
889 flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
891 rval = qla84xx_reset_chip(vha, flag == A84_ISSUE_RESET_DIAG_FW);
894 ql_log(ql_log_warn, vha, 0x7030,
895 "Vendor request 84xx reset failed.\n");
896 rval = bsg_job->reply->reply_payload_rcv_len = 0;
897 bsg_job->reply->result = (DID_ERROR << 16);
900 ql_dbg(ql_dbg_user, vha, 0x7031,
901 "Vendor request 84xx reset completed.\n");
902 bsg_job->reply->result = DID_OK;
905 bsg_job->job_done(bsg_job);
910 qla84xx_updatefw(struct fc_bsg_job *bsg_job)
912 struct Scsi_Host *host = bsg_job->shost;
913 scsi_qla_host_t *vha = shost_priv(host);
914 struct qla_hw_data *ha = vha->hw;
915 struct verify_chip_entry_84xx *mn = NULL;
916 dma_addr_t mn_dma, fw_dma;
925 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
926 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
927 test_bit(ISP_ABORT_RETRY, &vha->dpc_flags))
930 if (!IS_QLA84XX(ha)) {
931 ql_dbg(ql_dbg_user, vha, 0x7032,
932 "Not 84xx, exiting.\n");
936 sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
937 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
939 ql_log(ql_log_warn, vha, 0x7033,
940 "dma_map_sg returned %d for request.\n", sg_cnt);
944 if (sg_cnt != bsg_job->request_payload.sg_cnt) {
945 ql_log(ql_log_warn, vha, 0x7034,
946 "DMA mapping resulted in different sg counts, "
947 "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
948 bsg_job->request_payload.sg_cnt, sg_cnt);
953 data_len = bsg_job->request_payload.payload_len;
954 fw_buf = dma_alloc_coherent(&ha->pdev->dev, data_len,
955 &fw_dma, GFP_KERNEL);
957 ql_log(ql_log_warn, vha, 0x7035,
958 "DMA alloc failed for fw_buf.\n");
963 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
964 bsg_job->request_payload.sg_cnt, fw_buf, data_len);
966 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
968 ql_log(ql_log_warn, vha, 0x7036,
969 "DMA alloc failed for fw buffer.\n");
971 goto done_free_fw_buf;
974 flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
975 fw_ver = le32_to_cpu(*((uint32_t *)((uint32_t *)fw_buf + 2)));
977 memset(mn, 0, sizeof(struct access_chip_84xx));
978 mn->entry_type = VERIFY_CHIP_IOCB_TYPE;
981 options = VCO_FORCE_UPDATE | VCO_END_OF_DATA;
982 if (flag == A84_ISSUE_UPDATE_DIAGFW_CMD)
983 options |= VCO_DIAG_FW;
985 mn->options = cpu_to_le16(options);
986 mn->fw_ver = cpu_to_le32(fw_ver);
987 mn->fw_size = cpu_to_le32(data_len);
988 mn->fw_seq_size = cpu_to_le32(data_len);
989 mn->dseg_address[0] = cpu_to_le32(LSD(fw_dma));
990 mn->dseg_address[1] = cpu_to_le32(MSD(fw_dma));
991 mn->dseg_length = cpu_to_le32(data_len);
992 mn->data_seg_cnt = cpu_to_le16(1);
994 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
997 ql_log(ql_log_warn, vha, 0x7037,
998 "Vendor request 84xx updatefw failed.\n");
1000 rval = bsg_job->reply->reply_payload_rcv_len = 0;
1001 bsg_job->reply->result = (DID_ERROR << 16);
1004 ql_dbg(ql_dbg_user, vha, 0x7038,
1005 "Vendor request 84xx updatefw completed.\n");
1007 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1008 bsg_job->reply->result = DID_OK;
1011 bsg_job->job_done(bsg_job);
1012 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
1015 dma_free_coherent(&ha->pdev->dev, data_len, fw_buf, fw_dma);
1018 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1019 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1025 qla84xx_mgmt_cmd(struct fc_bsg_job *bsg_job)
1027 struct Scsi_Host *host = bsg_job->shost;
1028 scsi_qla_host_t *vha = shost_priv(host);
1029 struct qla_hw_data *ha = vha->hw;
1030 struct access_chip_84xx *mn = NULL;
1031 dma_addr_t mn_dma, mgmt_dma;
1032 void *mgmt_b = NULL;
1034 struct qla_bsg_a84_mgmt *ql84_mgmt;
1036 uint32_t data_len = 0;
1037 uint32_t dma_direction = DMA_NONE;
1039 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
1040 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1041 test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
1042 ql_log(ql_log_warn, vha, 0x7039,
1043 "Abort active or needed.\n");
1047 if (!IS_QLA84XX(ha)) {
1048 ql_log(ql_log_warn, vha, 0x703a,
1049 "Not 84xx, exiting.\n");
1053 ql84_mgmt = (struct qla_bsg_a84_mgmt *)((char *)bsg_job->request +
1054 sizeof(struct fc_bsg_request));
1056 ql_log(ql_log_warn, vha, 0x703b,
1057 "MGMT header not provided, exiting.\n");
1061 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
1063 ql_log(ql_log_warn, vha, 0x703c,
1064 "DMA alloc failed for fw buffer.\n");
1068 memset(mn, 0, sizeof(struct access_chip_84xx));
1069 mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
1070 mn->entry_count = 1;
1072 switch (ql84_mgmt->mgmt.cmd) {
1073 case QLA84_MGMT_READ_MEM:
1074 case QLA84_MGMT_GET_INFO:
1075 sg_cnt = dma_map_sg(&ha->pdev->dev,
1076 bsg_job->reply_payload.sg_list,
1077 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1079 ql_log(ql_log_warn, vha, 0x703d,
1080 "dma_map_sg returned %d for reply.\n", sg_cnt);
1085 dma_direction = DMA_FROM_DEVICE;
1087 if (sg_cnt != bsg_job->reply_payload.sg_cnt) {
1088 ql_log(ql_log_warn, vha, 0x703e,
1089 "DMA mapping resulted in different sg counts, "
1090 "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
1091 bsg_job->reply_payload.sg_cnt, sg_cnt);
1096 data_len = bsg_job->reply_payload.payload_len;
1098 mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
1099 &mgmt_dma, GFP_KERNEL);
1101 ql_log(ql_log_warn, vha, 0x703f,
1102 "DMA alloc failed for mgmt_b.\n");
1107 if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) {
1108 mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
1111 ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
1113 } else if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO) {
1114 mn->options = cpu_to_le16(ACO_REQUEST_INFO);
1116 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.info.type);
1120 ql84_mgmt->mgmt.mgmtp.u.info.context);
1124 case QLA84_MGMT_WRITE_MEM:
1125 sg_cnt = dma_map_sg(&ha->pdev->dev,
1126 bsg_job->request_payload.sg_list,
1127 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1130 ql_log(ql_log_warn, vha, 0x7040,
1131 "dma_map_sg returned %d.\n", sg_cnt);
1136 dma_direction = DMA_TO_DEVICE;
1138 if (sg_cnt != bsg_job->request_payload.sg_cnt) {
1139 ql_log(ql_log_warn, vha, 0x7041,
1140 "DMA mapping resulted in different sg counts, "
1141 "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
1142 bsg_job->request_payload.sg_cnt, sg_cnt);
1147 data_len = bsg_job->request_payload.payload_len;
1148 mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
1149 &mgmt_dma, GFP_KERNEL);
1151 ql_log(ql_log_warn, vha, 0x7042,
1152 "DMA alloc failed for mgmt_b.\n");
1157 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1158 bsg_job->request_payload.sg_cnt, mgmt_b, data_len);
1160 mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
1162 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
1165 case QLA84_MGMT_CHNG_CONFIG:
1166 mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
1168 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.id);
1171 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param0);
1174 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param1);
1182 if (ql84_mgmt->mgmt.cmd != QLA84_MGMT_CHNG_CONFIG) {
1183 mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->mgmt.len);
1184 mn->dseg_count = cpu_to_le16(1);
1185 mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma));
1186 mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma));
1187 mn->dseg_length = cpu_to_le32(ql84_mgmt->mgmt.len);
1190 rval = qla2x00_issue_iocb(vha, mn, mn_dma, 0);
1193 ql_log(ql_log_warn, vha, 0x7043,
1194 "Vendor request 84xx mgmt failed.\n");
1196 rval = bsg_job->reply->reply_payload_rcv_len = 0;
1197 bsg_job->reply->result = (DID_ERROR << 16);
1200 ql_dbg(ql_dbg_user, vha, 0x7044,
1201 "Vendor request 84xx mgmt completed.\n");
1203 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1204 bsg_job->reply->result = DID_OK;
1206 if ((ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) ||
1207 (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO)) {
1208 bsg_job->reply->reply_payload_rcv_len =
1209 bsg_job->reply_payload.payload_len;
1211 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1212 bsg_job->reply_payload.sg_cnt, mgmt_b,
1217 bsg_job->job_done(bsg_job);
1221 dma_free_coherent(&ha->pdev->dev, data_len, mgmt_b, mgmt_dma);
1223 if (dma_direction == DMA_TO_DEVICE)
1224 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1225 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1226 else if (dma_direction == DMA_FROM_DEVICE)
1227 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
1228 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1231 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
1237 qla24xx_iidma(struct fc_bsg_job *bsg_job)
1239 struct Scsi_Host *host = bsg_job->shost;
1240 scsi_qla_host_t *vha = shost_priv(host);
1242 struct qla_port_param *port_param = NULL;
1243 fc_port_t *fcport = NULL;
1244 uint16_t mb[MAILBOX_REGISTER_COUNT];
1245 uint8_t *rsp_ptr = NULL;
1247 bsg_job->reply->reply_payload_rcv_len = 0;
1249 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
1250 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1251 test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
1252 ql_log(ql_log_warn, vha, 0x7045, "abort active or needed.\n");
1256 if (!IS_IIDMA_CAPABLE(vha->hw)) {
1257 ql_log(ql_log_info, vha, 0x7046, "iiDMA not supported.\n");
1261 port_param = (struct qla_port_param *)((char *)bsg_job->request +
1262 sizeof(struct fc_bsg_request));
1264 ql_log(ql_log_warn, vha, 0x7047,
1265 "port_param header not provided.\n");
1269 if (port_param->fc_scsi_addr.dest_type != EXT_DEF_TYPE_WWPN) {
1270 ql_log(ql_log_warn, vha, 0x7048,
1271 "Invalid destination type.\n");
1275 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1276 if (fcport->port_type != FCT_TARGET)
1279 if (memcmp(port_param->fc_scsi_addr.dest_addr.wwpn,
1280 fcport->port_name, sizeof(fcport->port_name)))
1286 ql_log(ql_log_warn, vha, 0x7049,
1287 "Failed to find port.\n");
1291 if (atomic_read(&fcport->state) != FCS_ONLINE) {
1292 ql_log(ql_log_warn, vha, 0x704a,
1293 "Port is not online.\n");
1297 if (fcport->flags & FCF_LOGIN_NEEDED) {
1298 ql_log(ql_log_warn, vha, 0x704b,
1299 "Remote port not logged in flags = 0x%x.\n", fcport->flags);
1303 if (port_param->mode)
1304 rval = qla2x00_set_idma_speed(vha, fcport->loop_id,
1305 port_param->speed, mb);
1307 rval = qla2x00_get_idma_speed(vha, fcport->loop_id,
1308 &port_param->speed, mb);
1311 ql_log(ql_log_warn, vha, 0x704c,
1312 "iIDMA cmd failed for %02x%02x%02x%02x%02x%02x%02x%02x -- "
1313 "%04x %x %04x %04x.\n", fcport->port_name[0],
1314 fcport->port_name[1], fcport->port_name[2],
1315 fcport->port_name[3], fcport->port_name[4],
1316 fcport->port_name[5], fcport->port_name[6],
1317 fcport->port_name[7], rval, fcport->fp_speed, mb[0], mb[1]);
1319 bsg_job->reply->result = (DID_ERROR << 16);
1322 if (!port_param->mode) {
1323 bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
1324 sizeof(struct qla_port_param);
1326 rsp_ptr = ((uint8_t *)bsg_job->reply) +
1327 sizeof(struct fc_bsg_reply);
1329 memcpy(rsp_ptr, port_param,
1330 sizeof(struct qla_port_param));
1333 bsg_job->reply->result = DID_OK;
1336 bsg_job->job_done(bsg_job);
1341 qla2x00_optrom_setup(struct fc_bsg_job *bsg_job, scsi_qla_host_t *vha,
1346 struct qla_hw_data *ha = vha->hw;
1348 bsg_job->reply->reply_payload_rcv_len = 0;
1350 if (unlikely(pci_channel_offline(ha->pdev)))
1353 start = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1354 if (start > ha->optrom_size) {
1355 ql_log(ql_log_warn, vha, 0x7055,
1356 "start %d > optrom_size %d.\n", start, ha->optrom_size);
1360 if (ha->optrom_state != QLA_SWAITING) {
1361 ql_log(ql_log_info, vha, 0x7056,
1362 "optrom_state %d.\n", ha->optrom_state);
1366 ha->optrom_region_start = start;
1367 ql_dbg(ql_dbg_user, vha, 0x7057, "is_update=%d.\n", is_update);
1369 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
1371 else if (start == (ha->flt_region_boot * 4) ||
1372 start == (ha->flt_region_fw * 4))
1374 else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
1375 IS_QLA8XXX_TYPE(ha))
1378 ql_log(ql_log_warn, vha, 0x7058,
1379 "Invalid start region 0x%x/0x%x.\n", start,
1380 bsg_job->request_payload.payload_len);
1384 ha->optrom_region_size = start +
1385 bsg_job->request_payload.payload_len > ha->optrom_size ?
1386 ha->optrom_size - start :
1387 bsg_job->request_payload.payload_len;
1388 ha->optrom_state = QLA_SWRITING;
1390 ha->optrom_region_size = start +
1391 bsg_job->reply_payload.payload_len > ha->optrom_size ?
1392 ha->optrom_size - start :
1393 bsg_job->reply_payload.payload_len;
1394 ha->optrom_state = QLA_SREADING;
1397 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
1398 if (!ha->optrom_buffer) {
1399 ql_log(ql_log_warn, vha, 0x7059,
1400 "Read: Unable to allocate memory for optrom retrieval "
1401 "(%x)\n", ha->optrom_region_size);
1403 ha->optrom_state = QLA_SWAITING;
1407 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
1412 qla2x00_read_optrom(struct fc_bsg_job *bsg_job)
1414 struct Scsi_Host *host = bsg_job->shost;
1415 scsi_qla_host_t *vha = shost_priv(host);
1416 struct qla_hw_data *ha = vha->hw;
1419 rval = qla2x00_optrom_setup(bsg_job, vha, 0);
1423 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
1424 ha->optrom_region_start, ha->optrom_region_size);
1426 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1427 bsg_job->reply_payload.sg_cnt, ha->optrom_buffer,
1428 ha->optrom_region_size);
1430 bsg_job->reply->reply_payload_rcv_len = ha->optrom_region_size;
1431 bsg_job->reply->result = DID_OK;
1432 vfree(ha->optrom_buffer);
1433 ha->optrom_buffer = NULL;
1434 ha->optrom_state = QLA_SWAITING;
1435 bsg_job->job_done(bsg_job);
1440 qla2x00_update_optrom(struct fc_bsg_job *bsg_job)
1442 struct Scsi_Host *host = bsg_job->shost;
1443 scsi_qla_host_t *vha = shost_priv(host);
1444 struct qla_hw_data *ha = vha->hw;
1447 rval = qla2x00_optrom_setup(bsg_job, vha, 1);
1451 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1452 bsg_job->request_payload.sg_cnt, ha->optrom_buffer,
1453 ha->optrom_region_size);
1455 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
1456 ha->optrom_region_start, ha->optrom_region_size);
1458 bsg_job->reply->result = DID_OK;
1459 vfree(ha->optrom_buffer);
1460 ha->optrom_buffer = NULL;
1461 ha->optrom_state = QLA_SWAITING;
1462 bsg_job->job_done(bsg_job);
1467 qla2x00_update_fru_versions(struct fc_bsg_job *bsg_job)
1469 struct Scsi_Host *host = bsg_job->shost;
1470 scsi_qla_host_t *vha = shost_priv(host);
1471 struct qla_hw_data *ha = vha->hw;
1473 uint8_t bsg[DMA_POOL_SIZE];
1474 struct qla_image_version_list *list = (void *)bsg;
1475 struct qla_image_version *image;
1478 void *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1480 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1481 EXT_STATUS_NO_MEMORY;
1485 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1486 bsg_job->request_payload.sg_cnt, list, sizeof(bsg));
1488 image = list->version;
1489 count = list->count;
1491 memcpy(sfp, &image->field_info, sizeof(image->field_info));
1492 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1493 image->field_address.device, image->field_address.offset,
1494 sizeof(image->field_info), image->field_address.option);
1496 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1503 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1506 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1509 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1510 bsg_job->reply->result = DID_OK << 16;
1511 bsg_job->job_done(bsg_job);
1517 qla2x00_read_fru_status(struct fc_bsg_job *bsg_job)
1519 struct Scsi_Host *host = bsg_job->shost;
1520 scsi_qla_host_t *vha = shost_priv(host);
1521 struct qla_hw_data *ha = vha->hw;
1523 uint8_t bsg[DMA_POOL_SIZE];
1524 struct qla_status_reg *sr = (void *)bsg;
1526 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1528 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1529 EXT_STATUS_NO_MEMORY;
1533 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1534 bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
1536 rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
1537 sr->field_address.device, sr->field_address.offset,
1538 sizeof(sr->status_reg), sr->field_address.option);
1539 sr->status_reg = *sfp;
1542 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1547 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1548 bsg_job->reply_payload.sg_cnt, sr, sizeof(*sr));
1550 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1553 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1556 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1557 bsg_job->reply->reply_payload_rcv_len = sizeof(*sr);
1558 bsg_job->reply->result = DID_OK << 16;
1559 bsg_job->job_done(bsg_job);
1565 qla2x00_write_fru_status(struct fc_bsg_job *bsg_job)
1567 struct Scsi_Host *host = bsg_job->shost;
1568 scsi_qla_host_t *vha = shost_priv(host);
1569 struct qla_hw_data *ha = vha->hw;
1571 uint8_t bsg[DMA_POOL_SIZE];
1572 struct qla_status_reg *sr = (void *)bsg;
1574 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1576 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1577 EXT_STATUS_NO_MEMORY;
1581 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1582 bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
1584 *sfp = sr->status_reg;
1585 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1586 sr->field_address.device, sr->field_address.offset,
1587 sizeof(sr->status_reg), sr->field_address.option);
1590 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1595 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1598 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1601 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1602 bsg_job->reply->result = DID_OK << 16;
1603 bsg_job->job_done(bsg_job);
1609 qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
1611 switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) {
1612 case QL_VND_LOOPBACK:
1613 return qla2x00_process_loopback(bsg_job);
1615 case QL_VND_A84_RESET:
1616 return qla84xx_reset(bsg_job);
1618 case QL_VND_A84_UPDATE_FW:
1619 return qla84xx_updatefw(bsg_job);
1621 case QL_VND_A84_MGMT_CMD:
1622 return qla84xx_mgmt_cmd(bsg_job);
1625 return qla24xx_iidma(bsg_job);
1627 case QL_VND_FCP_PRIO_CFG_CMD:
1628 return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job);
1630 case QL_VND_READ_FLASH:
1631 return qla2x00_read_optrom(bsg_job);
1633 case QL_VND_UPDATE_FLASH:
1634 return qla2x00_update_optrom(bsg_job);
1636 case QL_VND_SET_FRU_VERSION:
1637 return qla2x00_update_fru_versions(bsg_job);
1639 case QL_VND_READ_FRU_STATUS:
1640 return qla2x00_read_fru_status(bsg_job);
1642 case QL_VND_WRITE_FRU_STATUS:
1643 return qla2x00_write_fru_status(bsg_job);
1646 bsg_job->reply->result = (DID_ERROR << 16);
1647 bsg_job->job_done(bsg_job);
1653 qla24xx_bsg_request(struct fc_bsg_job *bsg_job)
1656 struct fc_rport *rport;
1657 fc_port_t *fcport = NULL;
1658 struct Scsi_Host *host;
1659 scsi_qla_host_t *vha;
1661 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
1662 rport = bsg_job->rport;
1663 fcport = *(fc_port_t **) rport->dd_data;
1664 host = rport_to_shost(rport);
1665 vha = shost_priv(host);
1667 host = bsg_job->shost;
1668 vha = shost_priv(host);
1671 ql_dbg(ql_dbg_user, vha, 0x7000,
1672 "Entered %s msgcode=0x%x.\n", __func__, bsg_job->request->msgcode);
1674 switch (bsg_job->request->msgcode) {
1675 case FC_BSG_RPT_ELS:
1676 case FC_BSG_HST_ELS_NOLOGIN:
1677 ret = qla2x00_process_els(bsg_job);
1680 ret = qla2x00_process_ct(bsg_job);
1682 case FC_BSG_HST_VENDOR:
1683 ret = qla2x00_process_vendor_specific(bsg_job);
1685 case FC_BSG_HST_ADD_RPORT:
1686 case FC_BSG_HST_DEL_RPORT:
1689 ql_log(ql_log_warn, vha, 0x705a, "Unsupported BSG request.\n");
1696 qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job)
1698 scsi_qla_host_t *vha = shost_priv(bsg_job->shost);
1699 struct qla_hw_data *ha = vha->hw;
1702 unsigned long flags;
1703 struct req_que *req;
1704 struct srb_ctx *sp_bsg;
1706 /* find the bsg job from the active list of commands */
1707 spin_lock_irqsave(&ha->hardware_lock, flags);
1708 for (que = 0; que < ha->max_req_queues; que++) {
1709 req = ha->req_q_map[que];
1713 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1714 sp = req->outstanding_cmds[cnt];
1718 if (((sp_bsg->type == SRB_CT_CMD) ||
1719 (sp_bsg->type == SRB_ELS_CMD_HST))
1720 && (sp_bsg->u.bsg_job == bsg_job)) {
1721 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1722 if (ha->isp_ops->abort_command(sp)) {
1723 ql_log(ql_log_warn, vha, 0x7089,
1724 "mbx abort_command "
1726 bsg_job->req->errors =
1727 bsg_job->reply->result = -EIO;
1729 ql_dbg(ql_dbg_user, vha, 0x708a,
1730 "mbx abort_command "
1732 bsg_job->req->errors =
1733 bsg_job->reply->result = 0;
1735 spin_lock_irqsave(&ha->hardware_lock, flags);
1741 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1742 ql_log(ql_log_info, vha, 0x708b, "SRB not found to abort.\n");
1743 bsg_job->req->errors = bsg_job->reply->result = -ENXIO;
1747 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1748 if (bsg_job->request->msgcode == FC_BSG_HST_CT)
1751 mempool_free(sp, ha->srb_mempool);