2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 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>
12 #include <linux/bsg-lib.h>
14 /* BSG support for ELS/CT pass through */
16 qla2x00_bsg_job_done(void *ptr, int res)
19 struct bsg_job *bsg_job = sp->u.bsg_job;
20 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
22 bsg_reply->result = res;
23 bsg_job_done(bsg_job, bsg_reply->result,
24 bsg_reply->reply_payload_rcv_len);
29 qla2x00_bsg_sp_free(void *ptr)
32 struct qla_hw_data *ha = sp->vha->hw;
33 struct bsg_job *bsg_job = sp->u.bsg_job;
34 struct fc_bsg_request *bsg_request = bsg_job->request;
35 struct qla_mt_iocb_rqst_fx00 *piocb_rqst;
37 if (sp->type == SRB_FXIOCB_BCMD) {
38 piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *)
39 &bsg_request->rqst_data.h_vendor.vendor_cmd[1];
41 if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID)
42 dma_unmap_sg(&ha->pdev->dev,
43 bsg_job->request_payload.sg_list,
44 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
46 if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID)
47 dma_unmap_sg(&ha->pdev->dev,
48 bsg_job->reply_payload.sg_list,
49 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
51 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
52 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
54 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
55 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
58 if (sp->type == SRB_CT_CMD ||
59 sp->type == SRB_FXIOCB_BCMD ||
60 sp->type == SRB_ELS_CMD_HST)
66 qla24xx_fcp_prio_cfg_valid(scsi_qla_host_t *vha,
67 struct qla_fcp_prio_cfg *pri_cfg, uint8_t flag)
69 int i, ret, num_valid;
71 struct qla_fcp_prio_entry *pri_entry;
72 uint32_t *bcode_val_ptr, bcode_val;
76 bcode = (uint8_t *)pri_cfg;
77 bcode_val_ptr = (uint32_t *)pri_cfg;
78 bcode_val = (uint32_t)(*bcode_val_ptr);
80 if (bcode_val == 0xFFFFFFFF) {
81 /* No FCP Priority config data in flash */
82 ql_dbg(ql_dbg_user, vha, 0x7051,
83 "No FCP Priority config data.\n");
87 if (memcmp(bcode, "HQOS", 4)) {
88 /* Invalid FCP priority data header*/
89 ql_dbg(ql_dbg_user, vha, 0x7052,
90 "Invalid FCP Priority data header. bcode=0x%x.\n",
97 pri_entry = &pri_cfg->entry[0];
98 for (i = 0; i < pri_cfg->num_entries; i++) {
99 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
104 if (num_valid == 0) {
105 /* No valid FCP priority data entries */
106 ql_dbg(ql_dbg_user, vha, 0x7053,
107 "No valid FCP Priority data entries.\n");
110 /* FCP priority data is valid */
111 ql_dbg(ql_dbg_user, vha, 0x7054,
112 "Valid FCP priority data. num entries = %d.\n",
120 qla24xx_proc_fcp_prio_cfg_cmd(struct bsg_job *bsg_job)
122 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
123 struct fc_bsg_request *bsg_request = bsg_job->request;
124 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
125 scsi_qla_host_t *vha = shost_priv(host);
126 struct qla_hw_data *ha = vha->hw;
131 if (!(IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || IS_P3P_TYPE(ha))) {
133 goto exit_fcp_prio_cfg;
136 /* Get the sub command */
137 oper = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
139 /* Only set config is allowed if config memory is not allocated */
140 if (!ha->fcp_prio_cfg && (oper != QLFC_FCP_PRIO_SET_CONFIG)) {
142 goto exit_fcp_prio_cfg;
145 case QLFC_FCP_PRIO_DISABLE:
146 if (ha->flags.fcp_prio_enabled) {
147 ha->flags.fcp_prio_enabled = 0;
148 ha->fcp_prio_cfg->attributes &=
149 ~FCP_PRIO_ATTR_ENABLE;
150 qla24xx_update_all_fcp_prio(vha);
151 bsg_reply->result = DID_OK;
154 bsg_reply->result = (DID_ERROR << 16);
155 goto exit_fcp_prio_cfg;
159 case QLFC_FCP_PRIO_ENABLE:
160 if (!ha->flags.fcp_prio_enabled) {
161 if (ha->fcp_prio_cfg) {
162 ha->flags.fcp_prio_enabled = 1;
163 ha->fcp_prio_cfg->attributes |=
164 FCP_PRIO_ATTR_ENABLE;
165 qla24xx_update_all_fcp_prio(vha);
166 bsg_reply->result = DID_OK;
169 bsg_reply->result = (DID_ERROR << 16);
170 goto exit_fcp_prio_cfg;
175 case QLFC_FCP_PRIO_GET_CONFIG:
176 len = bsg_job->reply_payload.payload_len;
177 if (!len || len > FCP_PRIO_CFG_SIZE) {
179 bsg_reply->result = (DID_ERROR << 16);
180 goto exit_fcp_prio_cfg;
183 bsg_reply->result = DID_OK;
184 bsg_reply->reply_payload_rcv_len =
186 bsg_job->reply_payload.sg_list,
187 bsg_job->reply_payload.sg_cnt, ha->fcp_prio_cfg,
192 case QLFC_FCP_PRIO_SET_CONFIG:
193 len = bsg_job->request_payload.payload_len;
194 if (!len || len > FCP_PRIO_CFG_SIZE) {
195 bsg_reply->result = (DID_ERROR << 16);
197 goto exit_fcp_prio_cfg;
200 if (!ha->fcp_prio_cfg) {
201 ha->fcp_prio_cfg = vmalloc(FCP_PRIO_CFG_SIZE);
202 if (!ha->fcp_prio_cfg) {
203 ql_log(ql_log_warn, vha, 0x7050,
204 "Unable to allocate memory for fcp prio "
205 "config data (%x).\n", FCP_PRIO_CFG_SIZE);
206 bsg_reply->result = (DID_ERROR << 16);
208 goto exit_fcp_prio_cfg;
212 memset(ha->fcp_prio_cfg, 0, FCP_PRIO_CFG_SIZE);
213 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
214 bsg_job->request_payload.sg_cnt, ha->fcp_prio_cfg,
217 /* validate fcp priority data */
219 if (!qla24xx_fcp_prio_cfg_valid(vha,
220 (struct qla_fcp_prio_cfg *) ha->fcp_prio_cfg, 1)) {
221 bsg_reply->result = (DID_ERROR << 16);
223 /* If buffer was invalidatic int
224 * fcp_prio_cfg is of no use
226 vfree(ha->fcp_prio_cfg);
227 ha->fcp_prio_cfg = NULL;
228 goto exit_fcp_prio_cfg;
231 ha->flags.fcp_prio_enabled = 0;
232 if (ha->fcp_prio_cfg->attributes & FCP_PRIO_ATTR_ENABLE)
233 ha->flags.fcp_prio_enabled = 1;
234 qla24xx_update_all_fcp_prio(vha);
235 bsg_reply->result = DID_OK;
243 bsg_job_done(bsg_job, bsg_reply->result,
244 bsg_reply->reply_payload_rcv_len);
249 qla2x00_process_els(struct bsg_job *bsg_job)
251 struct fc_bsg_request *bsg_request = bsg_job->request;
252 struct fc_rport *rport;
253 fc_port_t *fcport = NULL;
254 struct Scsi_Host *host;
255 scsi_qla_host_t *vha;
256 struct qla_hw_data *ha;
259 int req_sg_cnt, rsp_sg_cnt;
260 int rval = (DRIVER_ERROR << 16);
261 uint16_t nextlid = 0;
263 if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
264 rport = fc_bsg_to_rport(bsg_job);
265 fcport = *(fc_port_t **) rport->dd_data;
266 host = rport_to_shost(rport);
267 vha = shost_priv(host);
269 type = "FC_BSG_RPT_ELS";
271 host = fc_bsg_to_shost(bsg_job);
272 vha = shost_priv(host);
274 type = "FC_BSG_HST_ELS_NOLOGIN";
277 if (!vha->flags.online) {
278 ql_log(ql_log_warn, vha, 0x7005, "Host not online.\n");
283 /* pass through is supported only for ISP 4Gb or higher */
284 if (!IS_FWI2_CAPABLE(ha)) {
285 ql_dbg(ql_dbg_user, vha, 0x7001,
286 "ELS passthru not supported for ISP23xx based adapters.\n");
291 /* Multiple SG's are not supported for ELS requests */
292 if (bsg_job->request_payload.sg_cnt > 1 ||
293 bsg_job->reply_payload.sg_cnt > 1) {
294 ql_dbg(ql_dbg_user, vha, 0x7002,
295 "Multiple SG's are not supported for ELS requests, "
296 "request_sg_cnt=%x reply_sg_cnt=%x.\n",
297 bsg_job->request_payload.sg_cnt,
298 bsg_job->reply_payload.sg_cnt);
303 /* ELS request for rport */
304 if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
305 /* make sure the rport is logged in,
306 * if not perform fabric login
308 if (qla2x00_fabric_login(vha, fcport, &nextlid)) {
309 ql_dbg(ql_dbg_user, vha, 0x7003,
310 "Failed to login port %06X for ELS passthru.\n",
316 /* Allocate a dummy fcport structure, since functions
317 * preparing the IOCB and mailbox command retrieves port
318 * specific information from fcport structure. For Host based
319 * ELS commands there will be no fcport structure allocated
321 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
327 /* Initialize all required fields of fcport */
329 fcport->d_id.b.al_pa =
330 bsg_request->rqst_data.h_els.port_id[0];
331 fcport->d_id.b.area =
332 bsg_request->rqst_data.h_els.port_id[1];
333 fcport->d_id.b.domain =
334 bsg_request->rqst_data.h_els.port_id[2];
336 (fcport->d_id.b.al_pa == 0xFD) ?
337 NPH_FABRIC_CONTROLLER : NPH_F_PORT;
341 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
342 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
345 goto done_free_fcport;
348 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
349 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
352 goto done_free_fcport;
355 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
356 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
357 ql_log(ql_log_warn, vha, 0x7008,
358 "dma mapping resulted in different sg counts, "
359 "request_sg_cnt: %x dma_request_sg_cnt:%x reply_sg_cnt:%x "
360 "dma_reply_sg_cnt:%x.\n", bsg_job->request_payload.sg_cnt,
361 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
366 /* Alloc SRB structure */
367 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
374 (bsg_request->msgcode == FC_BSG_RPT_ELS ?
375 SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
377 (bsg_request->msgcode == FC_BSG_RPT_ELS ?
378 "bsg_els_rpt" : "bsg_els_hst");
379 sp->u.bsg_job = bsg_job;
380 sp->free = qla2x00_bsg_sp_free;
381 sp->done = qla2x00_bsg_job_done;
383 ql_dbg(ql_dbg_user, vha, 0x700a,
384 "bsg rqst type: %s els type: %x - loop-id=%x "
385 "portid=%-2x%02x%02x.\n", type,
386 bsg_request->rqst_data.h_els.command_code, fcport->loop_id,
387 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa);
389 rval = qla2x00_start_sp(sp);
390 if (rval != QLA_SUCCESS) {
391 ql_log(ql_log_warn, vha, 0x700e,
392 "qla2x00_start_sp failed = %d\n", rval);
400 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
401 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
402 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
403 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
404 goto done_free_fcport;
407 if (bsg_request->msgcode == FC_BSG_RPT_ELS)
413 static inline uint16_t
414 qla24xx_calc_ct_iocbs(uint16_t dsds)
420 iocbs += (dsds - 2) / 5;
428 qla2x00_process_ct(struct bsg_job *bsg_job)
431 struct fc_bsg_request *bsg_request = bsg_job->request;
432 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
433 scsi_qla_host_t *vha = shost_priv(host);
434 struct qla_hw_data *ha = vha->hw;
435 int rval = (DRIVER_ERROR << 16);
436 int req_sg_cnt, rsp_sg_cnt;
438 struct fc_port *fcport;
439 char *type = "FC_BSG_HST_CT";
442 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
443 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
445 ql_log(ql_log_warn, vha, 0x700f,
446 "dma_map_sg return %d for request\n", req_sg_cnt);
451 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
452 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
454 ql_log(ql_log_warn, vha, 0x7010,
455 "dma_map_sg return %d for reply\n", rsp_sg_cnt);
460 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
461 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
462 ql_log(ql_log_warn, vha, 0x7011,
463 "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
464 "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
465 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
470 if (!vha->flags.online) {
471 ql_log(ql_log_warn, vha, 0x7012,
472 "Host is not online.\n");
478 (bsg_request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
482 loop_id = cpu_to_le16(NPH_SNS);
485 loop_id = vha->mgmt_svr_loop_id;
488 ql_dbg(ql_dbg_user, vha, 0x7013,
489 "Unknown loop id: %x.\n", loop_id);
494 /* Allocate a dummy fcport structure, since functions preparing the
495 * IOCB and mailbox command retrieves port specific information
496 * from fcport structure. For Host based ELS commands there will be
497 * no fcport structure allocated
499 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
501 ql_log(ql_log_warn, vha, 0x7014,
502 "Failed to allocate fcport.\n");
507 /* Initialize all required fields of fcport */
509 fcport->d_id.b.al_pa = bsg_request->rqst_data.h_ct.port_id[0];
510 fcport->d_id.b.area = bsg_request->rqst_data.h_ct.port_id[1];
511 fcport->d_id.b.domain = bsg_request->rqst_data.h_ct.port_id[2];
512 fcport->loop_id = loop_id;
514 /* Alloc SRB structure */
515 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
517 ql_log(ql_log_warn, vha, 0x7015,
518 "qla2x00_get_sp failed.\n");
520 goto done_free_fcport;
523 sp->type = SRB_CT_CMD;
525 sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
526 sp->u.bsg_job = bsg_job;
527 sp->free = qla2x00_bsg_sp_free;
528 sp->done = qla2x00_bsg_job_done;
530 ql_dbg(ql_dbg_user, vha, 0x7016,
531 "bsg rqst type: %s else type: %x - "
532 "loop-id=%x portid=%02x%02x%02x.\n", type,
533 (bsg_request->rqst_data.h_ct.preamble_word2 >> 16),
534 fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
535 fcport->d_id.b.al_pa);
537 rval = qla2x00_start_sp(sp);
538 if (rval != QLA_SUCCESS) {
539 ql_log(ql_log_warn, vha, 0x7017,
540 "qla2x00_start_sp failed=%d.\n", rval);
543 goto done_free_fcport;
550 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
551 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
552 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
553 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
558 /* Disable loopback mode */
560 qla81xx_reset_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
565 uint16_t new_config[4];
566 struct qla_hw_data *ha = vha->hw;
568 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha))
569 goto done_reset_internal;
571 memset(new_config, 0 , sizeof(new_config));
572 if ((config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
573 ENABLE_INTERNAL_LOOPBACK ||
574 (config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
575 ENABLE_EXTERNAL_LOOPBACK) {
576 new_config[0] = config[0] & ~INTERNAL_LOOPBACK_MASK;
577 ql_dbg(ql_dbg_user, vha, 0x70bf, "new_config[0]=%02x\n",
578 (new_config[0] & INTERNAL_LOOPBACK_MASK));
579 memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ;
581 ha->notify_dcbx_comp = wait;
582 ha->notify_lb_portup_comp = wait2;
584 ret = qla81xx_set_port_config(vha, new_config);
585 if (ret != QLA_SUCCESS) {
586 ql_log(ql_log_warn, vha, 0x7025,
587 "Set port config failed.\n");
588 ha->notify_dcbx_comp = 0;
589 ha->notify_lb_portup_comp = 0;
591 goto done_reset_internal;
594 /* Wait for DCBX complete event */
595 if (wait && !wait_for_completion_timeout(&ha->dcbx_comp,
596 (DCBX_COMP_TIMEOUT * HZ))) {
597 ql_dbg(ql_dbg_user, vha, 0x7026,
598 "DCBX completion not received.\n");
599 ha->notify_dcbx_comp = 0;
600 ha->notify_lb_portup_comp = 0;
602 goto done_reset_internal;
604 ql_dbg(ql_dbg_user, vha, 0x7027,
605 "DCBX completion received.\n");
608 !wait_for_completion_timeout(&ha->lb_portup_comp,
609 (LB_PORTUP_COMP_TIMEOUT * HZ))) {
610 ql_dbg(ql_dbg_user, vha, 0x70c5,
611 "Port up completion not received.\n");
612 ha->notify_lb_portup_comp = 0;
614 goto done_reset_internal;
616 ql_dbg(ql_dbg_user, vha, 0x70c6,
617 "Port up completion received.\n");
619 ha->notify_dcbx_comp = 0;
620 ha->notify_lb_portup_comp = 0;
627 * Set the port configuration to enable the internal or external loopback
628 * depending on the loopback mode.
631 qla81xx_set_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
632 uint16_t *new_config, uint16_t mode)
636 unsigned long rem_tmo = 0, current_tmo = 0;
637 struct qla_hw_data *ha = vha->hw;
639 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha))
640 goto done_set_internal;
642 if (mode == INTERNAL_LOOPBACK)
643 new_config[0] = config[0] | (ENABLE_INTERNAL_LOOPBACK << 1);
644 else if (mode == EXTERNAL_LOOPBACK)
645 new_config[0] = config[0] | (ENABLE_EXTERNAL_LOOPBACK << 1);
646 ql_dbg(ql_dbg_user, vha, 0x70be,
647 "new_config[0]=%02x\n", (new_config[0] & INTERNAL_LOOPBACK_MASK));
649 memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3);
651 ha->notify_dcbx_comp = 1;
652 ret = qla81xx_set_port_config(vha, new_config);
653 if (ret != QLA_SUCCESS) {
654 ql_log(ql_log_warn, vha, 0x7021,
655 "set port config failed.\n");
656 ha->notify_dcbx_comp = 0;
658 goto done_set_internal;
661 /* Wait for DCBX complete event */
662 current_tmo = DCBX_COMP_TIMEOUT * HZ;
664 rem_tmo = wait_for_completion_timeout(&ha->dcbx_comp,
666 if (!ha->idc_extend_tmo || rem_tmo) {
667 ha->idc_extend_tmo = 0;
670 current_tmo = ha->idc_extend_tmo * HZ;
671 ha->idc_extend_tmo = 0;
675 ql_dbg(ql_dbg_user, vha, 0x7022,
676 "DCBX completion not received.\n");
677 ret = qla81xx_reset_loopback_mode(vha, new_config, 0, 0);
679 * If the reset of the loopback mode doesn't work take a FCoE
680 * dump and reset the chip.
683 ha->isp_ops->fw_dump(vha, 0);
684 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
688 if (ha->flags.idc_compl_status) {
689 ql_dbg(ql_dbg_user, vha, 0x70c3,
690 "Bad status in IDC Completion AEN\n");
692 ha->flags.idc_compl_status = 0;
694 ql_dbg(ql_dbg_user, vha, 0x7023,
695 "DCBX completion received.\n");
698 ha->notify_dcbx_comp = 0;
699 ha->idc_extend_tmo = 0;
706 qla2x00_process_loopback(struct bsg_job *bsg_job)
708 struct fc_bsg_request *bsg_request = bsg_job->request;
709 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
710 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
711 scsi_qla_host_t *vha = shost_priv(host);
712 struct qla_hw_data *ha = vha->hw;
714 uint8_t command_sent;
716 struct msg_echo_lb elreq;
717 uint16_t response[MAILBOX_REGISTER_COUNT];
718 uint16_t config[4], new_config[4];
720 uint8_t *req_data = NULL;
721 dma_addr_t req_data_dma;
722 uint32_t req_data_len;
723 uint8_t *rsp_data = NULL;
724 dma_addr_t rsp_data_dma;
725 uint32_t rsp_data_len;
727 if (!vha->flags.online) {
728 ql_log(ql_log_warn, vha, 0x7019, "Host is not online.\n");
732 memset(&elreq, 0, sizeof(elreq));
734 elreq.req_sg_cnt = dma_map_sg(&ha->pdev->dev,
735 bsg_job->request_payload.sg_list, bsg_job->request_payload.sg_cnt,
738 if (!elreq.req_sg_cnt) {
739 ql_log(ql_log_warn, vha, 0x701a,
740 "dma_map_sg returned %d for request.\n", elreq.req_sg_cnt);
744 elreq.rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
745 bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
748 if (!elreq.rsp_sg_cnt) {
749 ql_log(ql_log_warn, vha, 0x701b,
750 "dma_map_sg returned %d for reply.\n", elreq.rsp_sg_cnt);
752 goto done_unmap_req_sg;
755 if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
756 (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
757 ql_log(ql_log_warn, vha, 0x701c,
758 "dma mapping resulted in different sg counts, "
759 "request_sg_cnt: %x dma_request_sg_cnt: %x "
760 "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
761 bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
762 bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt);
766 req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
767 req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
768 &req_data_dma, GFP_KERNEL);
770 ql_log(ql_log_warn, vha, 0x701d,
771 "dma alloc failed for req_data.\n");
776 rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
777 &rsp_data_dma, GFP_KERNEL);
779 ql_log(ql_log_warn, vha, 0x7004,
780 "dma alloc failed for rsp_data.\n");
782 goto done_free_dma_req;
785 /* Copy the request buffer in req_data now */
786 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
787 bsg_job->request_payload.sg_cnt, req_data, req_data_len);
789 elreq.send_dma = req_data_dma;
790 elreq.rcv_dma = rsp_data_dma;
791 elreq.transfer_size = req_data_len;
793 elreq.options = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
794 elreq.iteration_count =
795 bsg_request->rqst_data.h_vendor.vendor_cmd[2];
797 if (atomic_read(&vha->loop_state) == LOOP_READY &&
798 (ha->current_topology == ISP_CFG_F ||
799 (le32_to_cpu(*(uint32_t *)req_data) == ELS_OPCODE_BYTE &&
800 req_data_len == MAX_ELS_FRAME_PAYLOAD)) &&
801 elreq.options == EXTERNAL_LOOPBACK) {
802 type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
803 ql_dbg(ql_dbg_user, vha, 0x701e,
804 "BSG request type: %s.\n", type);
805 command_sent = INT_DEF_LB_ECHO_CMD;
806 rval = qla2x00_echo_test(vha, &elreq, response);
808 if (IS_QLA81XX(ha) || IS_QLA8031(ha) || IS_QLA8044(ha)) {
809 memset(config, 0, sizeof(config));
810 memset(new_config, 0, sizeof(new_config));
812 if (qla81xx_get_port_config(vha, config)) {
813 ql_log(ql_log_warn, vha, 0x701f,
814 "Get port config failed.\n");
816 goto done_free_dma_rsp;
819 if ((config[0] & INTERNAL_LOOPBACK_MASK) != 0) {
820 ql_dbg(ql_dbg_user, vha, 0x70c4,
821 "Loopback operation already in "
824 goto done_free_dma_rsp;
827 ql_dbg(ql_dbg_user, vha, 0x70c0,
828 "elreq.options=%04x\n", elreq.options);
830 if (elreq.options == EXTERNAL_LOOPBACK)
831 if (IS_QLA8031(ha) || IS_QLA8044(ha))
832 rval = qla81xx_set_loopback_mode(vha,
833 config, new_config, elreq.options);
835 rval = qla81xx_reset_loopback_mode(vha,
838 rval = qla81xx_set_loopback_mode(vha, config,
839 new_config, elreq.options);
843 goto done_free_dma_rsp;
846 type = "FC_BSG_HST_VENDOR_LOOPBACK";
847 ql_dbg(ql_dbg_user, vha, 0x7028,
848 "BSG request type: %s.\n", type);
850 command_sent = INT_DEF_LB_LOOPBACK_CMD;
851 rval = qla2x00_loopback_test(vha, &elreq, response);
853 if (response[0] == MBS_COMMAND_ERROR &&
854 response[1] == MBS_LB_RESET) {
855 ql_log(ql_log_warn, vha, 0x7029,
856 "MBX command error, Aborting ISP.\n");
857 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
858 qla2xxx_wake_dpc(vha);
859 qla2x00_wait_for_chip_reset(vha);
860 /* Also reset the MPI */
861 if (IS_QLA81XX(ha)) {
862 if (qla81xx_restart_mpi_firmware(vha) !=
864 ql_log(ql_log_warn, vha, 0x702a,
865 "MPI reset failed.\n");
870 goto done_free_dma_rsp;
876 /* Revert back to original port config
877 * Also clear internal loopback
879 ret = qla81xx_reset_loopback_mode(vha,
883 * If the reset of the loopback mode
884 * doesn't work take FCoE dump and then
887 ha->isp_ops->fw_dump(vha, 0);
888 set_bit(ISP_ABORT_NEEDED,
895 type = "FC_BSG_HST_VENDOR_LOOPBACK";
896 ql_dbg(ql_dbg_user, vha, 0x702b,
897 "BSG request type: %s.\n", type);
898 command_sent = INT_DEF_LB_LOOPBACK_CMD;
899 rval = qla2x00_loopback_test(vha, &elreq, response);
904 ql_log(ql_log_warn, vha, 0x702c,
905 "Vendor request %s failed.\n", type);
908 bsg_reply->result = (DID_ERROR << 16);
909 bsg_reply->reply_payload_rcv_len = 0;
911 ql_dbg(ql_dbg_user, vha, 0x702d,
912 "Vendor request %s completed.\n", type);
913 bsg_reply->result = (DID_OK << 16);
914 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
915 bsg_job->reply_payload.sg_cnt, rsp_data,
919 bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
920 sizeof(response) + sizeof(uint8_t);
921 fw_sts_ptr = bsg_job->reply + sizeof(struct fc_bsg_reply);
922 memcpy(bsg_job->reply + sizeof(struct fc_bsg_reply), response,
924 fw_sts_ptr += sizeof(response);
925 *fw_sts_ptr = command_sent;
928 dma_free_coherent(&ha->pdev->dev, rsp_data_len,
929 rsp_data, rsp_data_dma);
931 dma_free_coherent(&ha->pdev->dev, req_data_len,
932 req_data, req_data_dma);
934 dma_unmap_sg(&ha->pdev->dev,
935 bsg_job->reply_payload.sg_list,
936 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
938 dma_unmap_sg(&ha->pdev->dev,
939 bsg_job->request_payload.sg_list,
940 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
942 bsg_job_done(bsg_job, bsg_reply->result,
943 bsg_reply->reply_payload_rcv_len);
948 qla84xx_reset(struct bsg_job *bsg_job)
950 struct fc_bsg_request *bsg_request = bsg_job->request;
951 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
952 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
953 scsi_qla_host_t *vha = shost_priv(host);
954 struct qla_hw_data *ha = vha->hw;
958 if (!IS_QLA84XX(ha)) {
959 ql_dbg(ql_dbg_user, vha, 0x702f, "Not 84xx, exiting.\n");
963 flag = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
965 rval = qla84xx_reset_chip(vha, flag == A84_ISSUE_RESET_DIAG_FW);
968 ql_log(ql_log_warn, vha, 0x7030,
969 "Vendor request 84xx reset failed.\n");
970 rval = (DID_ERROR << 16);
973 ql_dbg(ql_dbg_user, vha, 0x7031,
974 "Vendor request 84xx reset completed.\n");
975 bsg_reply->result = DID_OK;
976 bsg_job_done(bsg_job, bsg_reply->result,
977 bsg_reply->reply_payload_rcv_len);
984 qla84xx_updatefw(struct bsg_job *bsg_job)
986 struct fc_bsg_request *bsg_request = bsg_job->request;
987 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
988 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
989 scsi_qla_host_t *vha = shost_priv(host);
990 struct qla_hw_data *ha = vha->hw;
991 struct verify_chip_entry_84xx *mn = NULL;
992 dma_addr_t mn_dma, fw_dma;
1001 if (!IS_QLA84XX(ha)) {
1002 ql_dbg(ql_dbg_user, vha, 0x7032,
1003 "Not 84xx, exiting.\n");
1007 sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1008 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1010 ql_log(ql_log_warn, vha, 0x7033,
1011 "dma_map_sg returned %d for request.\n", sg_cnt);
1015 if (sg_cnt != bsg_job->request_payload.sg_cnt) {
1016 ql_log(ql_log_warn, vha, 0x7034,
1017 "DMA mapping resulted in different sg counts, "
1018 "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
1019 bsg_job->request_payload.sg_cnt, sg_cnt);
1024 data_len = bsg_job->request_payload.payload_len;
1025 fw_buf = dma_alloc_coherent(&ha->pdev->dev, data_len,
1026 &fw_dma, GFP_KERNEL);
1028 ql_log(ql_log_warn, vha, 0x7035,
1029 "DMA alloc failed for fw_buf.\n");
1034 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1035 bsg_job->request_payload.sg_cnt, fw_buf, data_len);
1037 mn = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
1039 ql_log(ql_log_warn, vha, 0x7036,
1040 "DMA alloc failed for fw buffer.\n");
1042 goto done_free_fw_buf;
1045 flag = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
1046 fw_ver = get_unaligned_le32((uint32_t *)fw_buf + 2);
1048 mn->entry_type = VERIFY_CHIP_IOCB_TYPE;
1049 mn->entry_count = 1;
1051 options = VCO_FORCE_UPDATE | VCO_END_OF_DATA;
1052 if (flag == A84_ISSUE_UPDATE_DIAGFW_CMD)
1053 options |= VCO_DIAG_FW;
1055 mn->options = cpu_to_le16(options);
1056 mn->fw_ver = cpu_to_le32(fw_ver);
1057 mn->fw_size = cpu_to_le32(data_len);
1058 mn->fw_seq_size = cpu_to_le32(data_len);
1059 put_unaligned_le64(fw_dma, &mn->dsd.address);
1060 mn->dsd.length = cpu_to_le32(data_len);
1061 mn->data_seg_cnt = cpu_to_le16(1);
1063 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
1066 ql_log(ql_log_warn, vha, 0x7037,
1067 "Vendor request 84xx updatefw failed.\n");
1069 rval = (DID_ERROR << 16);
1071 ql_dbg(ql_dbg_user, vha, 0x7038,
1072 "Vendor request 84xx updatefw completed.\n");
1074 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1075 bsg_reply->result = DID_OK;
1078 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
1081 dma_free_coherent(&ha->pdev->dev, data_len, fw_buf, fw_dma);
1084 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1085 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1088 bsg_job_done(bsg_job, bsg_reply->result,
1089 bsg_reply->reply_payload_rcv_len);
1094 qla84xx_mgmt_cmd(struct bsg_job *bsg_job)
1096 struct fc_bsg_request *bsg_request = bsg_job->request;
1097 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1098 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1099 scsi_qla_host_t *vha = shost_priv(host);
1100 struct qla_hw_data *ha = vha->hw;
1101 struct access_chip_84xx *mn = NULL;
1102 dma_addr_t mn_dma, mgmt_dma;
1103 void *mgmt_b = NULL;
1105 struct qla_bsg_a84_mgmt *ql84_mgmt;
1107 uint32_t data_len = 0;
1108 uint32_t dma_direction = DMA_NONE;
1110 if (!IS_QLA84XX(ha)) {
1111 ql_log(ql_log_warn, vha, 0x703a,
1112 "Not 84xx, exiting.\n");
1116 mn = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
1118 ql_log(ql_log_warn, vha, 0x703c,
1119 "DMA alloc failed for fw buffer.\n");
1123 mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
1124 mn->entry_count = 1;
1125 ql84_mgmt = (void *)bsg_request + sizeof(struct fc_bsg_request);
1126 switch (ql84_mgmt->mgmt.cmd) {
1127 case QLA84_MGMT_READ_MEM:
1128 case QLA84_MGMT_GET_INFO:
1129 sg_cnt = dma_map_sg(&ha->pdev->dev,
1130 bsg_job->reply_payload.sg_list,
1131 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1133 ql_log(ql_log_warn, vha, 0x703d,
1134 "dma_map_sg returned %d for reply.\n", sg_cnt);
1139 dma_direction = DMA_FROM_DEVICE;
1141 if (sg_cnt != bsg_job->reply_payload.sg_cnt) {
1142 ql_log(ql_log_warn, vha, 0x703e,
1143 "DMA mapping resulted in different sg counts, "
1144 "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
1145 bsg_job->reply_payload.sg_cnt, sg_cnt);
1150 data_len = bsg_job->reply_payload.payload_len;
1152 mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
1153 &mgmt_dma, GFP_KERNEL);
1155 ql_log(ql_log_warn, vha, 0x703f,
1156 "DMA alloc failed for mgmt_b.\n");
1161 if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) {
1162 mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
1165 ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
1167 } else if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO) {
1168 mn->options = cpu_to_le16(ACO_REQUEST_INFO);
1170 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.info.type);
1174 ql84_mgmt->mgmt.mgmtp.u.info.context);
1178 case QLA84_MGMT_WRITE_MEM:
1179 sg_cnt = dma_map_sg(&ha->pdev->dev,
1180 bsg_job->request_payload.sg_list,
1181 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1184 ql_log(ql_log_warn, vha, 0x7040,
1185 "dma_map_sg returned %d.\n", sg_cnt);
1190 dma_direction = DMA_TO_DEVICE;
1192 if (sg_cnt != bsg_job->request_payload.sg_cnt) {
1193 ql_log(ql_log_warn, vha, 0x7041,
1194 "DMA mapping resulted in different sg counts, "
1195 "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
1196 bsg_job->request_payload.sg_cnt, sg_cnt);
1201 data_len = bsg_job->request_payload.payload_len;
1202 mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
1203 &mgmt_dma, GFP_KERNEL);
1205 ql_log(ql_log_warn, vha, 0x7042,
1206 "DMA alloc failed for mgmt_b.\n");
1211 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1212 bsg_job->request_payload.sg_cnt, mgmt_b, data_len);
1214 mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
1216 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
1219 case QLA84_MGMT_CHNG_CONFIG:
1220 mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
1222 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.id);
1225 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param0);
1228 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param1);
1236 if (ql84_mgmt->mgmt.cmd != QLA84_MGMT_CHNG_CONFIG) {
1237 mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->mgmt.len);
1238 mn->dseg_count = cpu_to_le16(1);
1239 put_unaligned_le64(mgmt_dma, &mn->dsd.address);
1240 mn->dsd.length = cpu_to_le32(ql84_mgmt->mgmt.len);
1243 rval = qla2x00_issue_iocb(vha, mn, mn_dma, 0);
1246 ql_log(ql_log_warn, vha, 0x7043,
1247 "Vendor request 84xx mgmt failed.\n");
1249 rval = (DID_ERROR << 16);
1252 ql_dbg(ql_dbg_user, vha, 0x7044,
1253 "Vendor request 84xx mgmt completed.\n");
1255 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1256 bsg_reply->result = DID_OK;
1258 if ((ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) ||
1259 (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO)) {
1260 bsg_reply->reply_payload_rcv_len =
1261 bsg_job->reply_payload.payload_len;
1263 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1264 bsg_job->reply_payload.sg_cnt, mgmt_b,
1271 dma_free_coherent(&ha->pdev->dev, data_len, mgmt_b, mgmt_dma);
1273 if (dma_direction == DMA_TO_DEVICE)
1274 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1275 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1276 else if (dma_direction == DMA_FROM_DEVICE)
1277 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
1278 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1281 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
1284 bsg_job_done(bsg_job, bsg_reply->result,
1285 bsg_reply->reply_payload_rcv_len);
1290 qla24xx_iidma(struct bsg_job *bsg_job)
1292 struct fc_bsg_request *bsg_request = bsg_job->request;
1293 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1294 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1295 scsi_qla_host_t *vha = shost_priv(host);
1297 struct qla_port_param *port_param = NULL;
1298 fc_port_t *fcport = NULL;
1300 uint16_t mb[MAILBOX_REGISTER_COUNT];
1301 uint8_t *rsp_ptr = NULL;
1303 if (!IS_IIDMA_CAPABLE(vha->hw)) {
1304 ql_log(ql_log_info, vha, 0x7046, "iiDMA not supported.\n");
1308 port_param = (void *)bsg_request + sizeof(struct fc_bsg_request);
1309 if (port_param->fc_scsi_addr.dest_type != EXT_DEF_TYPE_WWPN) {
1310 ql_log(ql_log_warn, vha, 0x7048,
1311 "Invalid destination type.\n");
1315 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1316 if (fcport->port_type != FCT_TARGET)
1319 if (memcmp(port_param->fc_scsi_addr.dest_addr.wwpn,
1320 fcport->port_name, sizeof(fcport->port_name)))
1328 ql_log(ql_log_warn, vha, 0x7049,
1329 "Failed to find port.\n");
1333 if (atomic_read(&fcport->state) != FCS_ONLINE) {
1334 ql_log(ql_log_warn, vha, 0x704a,
1335 "Port is not online.\n");
1339 if (fcport->flags & FCF_LOGIN_NEEDED) {
1340 ql_log(ql_log_warn, vha, 0x704b,
1341 "Remote port not logged in flags = 0x%x.\n", fcport->flags);
1345 if (port_param->mode)
1346 rval = qla2x00_set_idma_speed(vha, fcport->loop_id,
1347 port_param->speed, mb);
1349 rval = qla2x00_get_idma_speed(vha, fcport->loop_id,
1350 &port_param->speed, mb);
1353 ql_log(ql_log_warn, vha, 0x704c,
1354 "iiDMA cmd failed for %8phN -- "
1355 "%04x %x %04x %04x.\n", fcport->port_name,
1356 rval, fcport->fp_speed, mb[0], mb[1]);
1357 rval = (DID_ERROR << 16);
1359 if (!port_param->mode) {
1360 bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
1361 sizeof(struct qla_port_param);
1363 rsp_ptr = ((uint8_t *)bsg_reply) +
1364 sizeof(struct fc_bsg_reply);
1366 memcpy(rsp_ptr, port_param,
1367 sizeof(struct qla_port_param));
1370 bsg_reply->result = DID_OK;
1371 bsg_job_done(bsg_job, bsg_reply->result,
1372 bsg_reply->reply_payload_rcv_len);
1379 qla2x00_optrom_setup(struct bsg_job *bsg_job, scsi_qla_host_t *vha,
1382 struct fc_bsg_request *bsg_request = bsg_job->request;
1385 struct qla_hw_data *ha = vha->hw;
1387 if (unlikely(pci_channel_offline(ha->pdev)))
1390 start = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
1391 if (start > ha->optrom_size) {
1392 ql_log(ql_log_warn, vha, 0x7055,
1393 "start %d > optrom_size %d.\n", start, ha->optrom_size);
1397 if (ha->optrom_state != QLA_SWAITING) {
1398 ql_log(ql_log_info, vha, 0x7056,
1399 "optrom_state %d.\n", ha->optrom_state);
1403 ha->optrom_region_start = start;
1404 ql_dbg(ql_dbg_user, vha, 0x7057, "is_update=%d.\n", is_update);
1406 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
1408 else if (start == (ha->flt_region_boot * 4) ||
1409 start == (ha->flt_region_fw * 4))
1411 else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
1412 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
1416 ql_log(ql_log_warn, vha, 0x7058,
1417 "Invalid start region 0x%x/0x%x.\n", start,
1418 bsg_job->request_payload.payload_len);
1422 ha->optrom_region_size = start +
1423 bsg_job->request_payload.payload_len > ha->optrom_size ?
1424 ha->optrom_size - start :
1425 bsg_job->request_payload.payload_len;
1426 ha->optrom_state = QLA_SWRITING;
1428 ha->optrom_region_size = start +
1429 bsg_job->reply_payload.payload_len > ha->optrom_size ?
1430 ha->optrom_size - start :
1431 bsg_job->reply_payload.payload_len;
1432 ha->optrom_state = QLA_SREADING;
1435 ha->optrom_buffer = vzalloc(ha->optrom_region_size);
1436 if (!ha->optrom_buffer) {
1437 ql_log(ql_log_warn, vha, 0x7059,
1438 "Read: Unable to allocate memory for optrom retrieval "
1439 "(%x)\n", ha->optrom_region_size);
1441 ha->optrom_state = QLA_SWAITING;
1449 qla2x00_read_optrom(struct bsg_job *bsg_job)
1451 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1452 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1453 scsi_qla_host_t *vha = shost_priv(host);
1454 struct qla_hw_data *ha = vha->hw;
1457 if (ha->flags.nic_core_reset_hdlr_active)
1460 mutex_lock(&ha->optrom_mutex);
1461 rval = qla2x00_optrom_setup(bsg_job, vha, 0);
1463 mutex_unlock(&ha->optrom_mutex);
1467 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
1468 ha->optrom_region_start, ha->optrom_region_size);
1470 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1471 bsg_job->reply_payload.sg_cnt, ha->optrom_buffer,
1472 ha->optrom_region_size);
1474 bsg_reply->reply_payload_rcv_len = ha->optrom_region_size;
1475 bsg_reply->result = DID_OK;
1476 vfree(ha->optrom_buffer);
1477 ha->optrom_buffer = NULL;
1478 ha->optrom_state = QLA_SWAITING;
1479 mutex_unlock(&ha->optrom_mutex);
1480 bsg_job_done(bsg_job, bsg_reply->result,
1481 bsg_reply->reply_payload_rcv_len);
1486 qla2x00_update_optrom(struct bsg_job *bsg_job)
1488 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1489 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1490 scsi_qla_host_t *vha = shost_priv(host);
1491 struct qla_hw_data *ha = vha->hw;
1494 mutex_lock(&ha->optrom_mutex);
1495 rval = qla2x00_optrom_setup(bsg_job, vha, 1);
1497 mutex_unlock(&ha->optrom_mutex);
1501 /* Set the isp82xx_no_md_cap not to capture minidump */
1502 ha->flags.isp82xx_no_md_cap = 1;
1504 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1505 bsg_job->request_payload.sg_cnt, ha->optrom_buffer,
1506 ha->optrom_region_size);
1508 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
1509 ha->optrom_region_start, ha->optrom_region_size);
1511 bsg_reply->result = DID_OK;
1512 vfree(ha->optrom_buffer);
1513 ha->optrom_buffer = NULL;
1514 ha->optrom_state = QLA_SWAITING;
1515 mutex_unlock(&ha->optrom_mutex);
1516 bsg_job_done(bsg_job, bsg_reply->result,
1517 bsg_reply->reply_payload_rcv_len);
1522 qla2x00_update_fru_versions(struct bsg_job *bsg_job)
1524 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1525 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1526 scsi_qla_host_t *vha = shost_priv(host);
1527 struct qla_hw_data *ha = vha->hw;
1529 uint8_t bsg[DMA_POOL_SIZE];
1530 struct qla_image_version_list *list = (void *)bsg;
1531 struct qla_image_version *image;
1534 void *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1537 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1538 EXT_STATUS_NO_MEMORY;
1542 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1543 bsg_job->request_payload.sg_cnt, list, sizeof(bsg));
1545 image = list->version;
1546 count = list->count;
1548 memcpy(sfp, &image->field_info, sizeof(image->field_info));
1549 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1550 image->field_address.device, image->field_address.offset,
1551 sizeof(image->field_info), image->field_address.option);
1553 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1560 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1563 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1566 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1567 bsg_reply->result = DID_OK << 16;
1568 bsg_job_done(bsg_job, bsg_reply->result,
1569 bsg_reply->reply_payload_rcv_len);
1575 qla2x00_read_fru_status(struct bsg_job *bsg_job)
1577 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1578 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1579 scsi_qla_host_t *vha = shost_priv(host);
1580 struct qla_hw_data *ha = vha->hw;
1582 uint8_t bsg[DMA_POOL_SIZE];
1583 struct qla_status_reg *sr = (void *)bsg;
1585 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1588 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1589 EXT_STATUS_NO_MEMORY;
1593 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1594 bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
1596 rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
1597 sr->field_address.device, sr->field_address.offset,
1598 sizeof(sr->status_reg), sr->field_address.option);
1599 sr->status_reg = *sfp;
1602 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1607 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1608 bsg_job->reply_payload.sg_cnt, sr, sizeof(*sr));
1610 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1613 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1616 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1617 bsg_reply->reply_payload_rcv_len = sizeof(*sr);
1618 bsg_reply->result = DID_OK << 16;
1619 bsg_job_done(bsg_job, bsg_reply->result,
1620 bsg_reply->reply_payload_rcv_len);
1626 qla2x00_write_fru_status(struct bsg_job *bsg_job)
1628 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1629 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1630 scsi_qla_host_t *vha = shost_priv(host);
1631 struct qla_hw_data *ha = vha->hw;
1633 uint8_t bsg[DMA_POOL_SIZE];
1634 struct qla_status_reg *sr = (void *)bsg;
1636 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1639 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1640 EXT_STATUS_NO_MEMORY;
1644 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1645 bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
1647 *sfp = sr->status_reg;
1648 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1649 sr->field_address.device, sr->field_address.offset,
1650 sizeof(sr->status_reg), sr->field_address.option);
1653 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1658 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1661 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1664 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1665 bsg_reply->result = DID_OK << 16;
1666 bsg_job_done(bsg_job, bsg_reply->result,
1667 bsg_reply->reply_payload_rcv_len);
1673 qla2x00_write_i2c(struct bsg_job *bsg_job)
1675 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1676 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1677 scsi_qla_host_t *vha = shost_priv(host);
1678 struct qla_hw_data *ha = vha->hw;
1680 uint8_t bsg[DMA_POOL_SIZE];
1681 struct qla_i2c_access *i2c = (void *)bsg;
1683 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1686 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1687 EXT_STATUS_NO_MEMORY;
1691 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1692 bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
1694 memcpy(sfp, i2c->buffer, i2c->length);
1695 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1696 i2c->device, i2c->offset, i2c->length, i2c->option);
1699 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1704 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1707 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1710 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1711 bsg_reply->result = DID_OK << 16;
1712 bsg_job_done(bsg_job, bsg_reply->result,
1713 bsg_reply->reply_payload_rcv_len);
1719 qla2x00_read_i2c(struct bsg_job *bsg_job)
1721 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1722 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1723 scsi_qla_host_t *vha = shost_priv(host);
1724 struct qla_hw_data *ha = vha->hw;
1726 uint8_t bsg[DMA_POOL_SIZE];
1727 struct qla_i2c_access *i2c = (void *)bsg;
1729 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1732 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1733 EXT_STATUS_NO_MEMORY;
1737 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1738 bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
1740 rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
1741 i2c->device, i2c->offset, i2c->length, i2c->option);
1744 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1749 memcpy(i2c->buffer, sfp, i2c->length);
1750 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1751 bsg_job->reply_payload.sg_cnt, i2c, sizeof(*i2c));
1753 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1756 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1759 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1760 bsg_reply->reply_payload_rcv_len = sizeof(*i2c);
1761 bsg_reply->result = DID_OK << 16;
1762 bsg_job_done(bsg_job, bsg_reply->result,
1763 bsg_reply->reply_payload_rcv_len);
1769 qla24xx_process_bidir_cmd(struct bsg_job *bsg_job)
1771 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1772 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1773 scsi_qla_host_t *vha = shost_priv(host);
1774 struct qla_hw_data *ha = vha->hw;
1775 uint32_t rval = EXT_STATUS_OK;
1776 uint16_t req_sg_cnt = 0;
1777 uint16_t rsp_sg_cnt = 0;
1778 uint16_t nextlid = 0;
1781 uint32_t req_data_len = 0;
1782 uint32_t rsp_data_len = 0;
1784 /* Check the type of the adapter */
1785 if (!IS_BIDI_CAPABLE(ha)) {
1786 ql_log(ql_log_warn, vha, 0x70a0,
1787 "This adapter is not supported\n");
1788 rval = EXT_STATUS_NOT_SUPPORTED;
1792 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
1793 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1794 test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
1795 rval = EXT_STATUS_BUSY;
1799 /* Check if host is online */
1800 if (!vha->flags.online) {
1801 ql_log(ql_log_warn, vha, 0x70a1,
1802 "Host is not online\n");
1803 rval = EXT_STATUS_DEVICE_OFFLINE;
1807 /* Check if cable is plugged in or not */
1808 if (vha->device_flags & DFLG_NO_CABLE) {
1809 ql_log(ql_log_warn, vha, 0x70a2,
1810 "Cable is unplugged...\n");
1811 rval = EXT_STATUS_INVALID_CFG;
1815 /* Check if the switch is connected or not */
1816 if (ha->current_topology != ISP_CFG_F) {
1817 ql_log(ql_log_warn, vha, 0x70a3,
1818 "Host is not connected to the switch\n");
1819 rval = EXT_STATUS_INVALID_CFG;
1823 /* Check if operating mode is P2P */
1824 if (ha->operating_mode != P2P) {
1825 ql_log(ql_log_warn, vha, 0x70a4,
1826 "Host operating mode is not P2p\n");
1827 rval = EXT_STATUS_INVALID_CFG;
1831 mutex_lock(&ha->selflogin_lock);
1832 if (vha->self_login_loop_id == 0) {
1833 /* Initialize all required fields of fcport */
1834 vha->bidir_fcport.vha = vha;
1835 vha->bidir_fcport.d_id.b.al_pa = vha->d_id.b.al_pa;
1836 vha->bidir_fcport.d_id.b.area = vha->d_id.b.area;
1837 vha->bidir_fcport.d_id.b.domain = vha->d_id.b.domain;
1838 vha->bidir_fcport.loop_id = vha->loop_id;
1840 if (qla2x00_fabric_login(vha, &(vha->bidir_fcport), &nextlid)) {
1841 ql_log(ql_log_warn, vha, 0x70a7,
1842 "Failed to login port %06X for bidirectional IOCB\n",
1843 vha->bidir_fcport.d_id.b24);
1844 mutex_unlock(&ha->selflogin_lock);
1845 rval = EXT_STATUS_MAILBOX;
1848 vha->self_login_loop_id = nextlid - 1;
1851 /* Assign the self login loop id to fcport */
1852 mutex_unlock(&ha->selflogin_lock);
1854 vha->bidir_fcport.loop_id = vha->self_login_loop_id;
1856 req_sg_cnt = dma_map_sg(&ha->pdev->dev,
1857 bsg_job->request_payload.sg_list,
1858 bsg_job->request_payload.sg_cnt,
1862 rval = EXT_STATUS_NO_MEMORY;
1866 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
1867 bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
1871 rval = EXT_STATUS_NO_MEMORY;
1872 goto done_unmap_req_sg;
1875 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
1876 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
1877 ql_dbg(ql_dbg_user, vha, 0x70a9,
1878 "Dma mapping resulted in different sg counts "
1879 "[request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt: "
1880 "%x dma_reply_sg_cnt: %x]\n",
1881 bsg_job->request_payload.sg_cnt, req_sg_cnt,
1882 bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
1883 rval = EXT_STATUS_NO_MEMORY;
1887 if (req_data_len != rsp_data_len) {
1888 rval = EXT_STATUS_BUSY;
1889 ql_log(ql_log_warn, vha, 0x70aa,
1890 "req_data_len != rsp_data_len\n");
1894 req_data_len = bsg_job->request_payload.payload_len;
1895 rsp_data_len = bsg_job->reply_payload.payload_len;
1898 /* Alloc SRB structure */
1899 sp = qla2x00_get_sp(vha, &(vha->bidir_fcport), GFP_KERNEL);
1901 ql_dbg(ql_dbg_user, vha, 0x70ac,
1902 "Alloc SRB structure failed\n");
1903 rval = EXT_STATUS_NO_MEMORY;
1907 /*Populate srb->ctx with bidir ctx*/
1908 sp->u.bsg_job = bsg_job;
1909 sp->free = qla2x00_bsg_sp_free;
1910 sp->type = SRB_BIDI_CMD;
1911 sp->done = qla2x00_bsg_job_done;
1913 /* Add the read and write sg count */
1914 tot_dsds = rsp_sg_cnt + req_sg_cnt;
1916 rval = qla2x00_start_bidir(sp, vha, tot_dsds);
1917 if (rval != EXT_STATUS_OK)
1919 /* the bsg request will be completed in the interrupt handler */
1923 mempool_free(sp, ha->srb_mempool);
1925 dma_unmap_sg(&ha->pdev->dev,
1926 bsg_job->reply_payload.sg_list,
1927 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1929 dma_unmap_sg(&ha->pdev->dev,
1930 bsg_job->request_payload.sg_list,
1931 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1934 /* Return an error vendor specific response
1935 * and complete the bsg request
1937 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
1938 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1939 bsg_reply->reply_payload_rcv_len = 0;
1940 bsg_reply->result = (DID_OK) << 16;
1941 bsg_job_done(bsg_job, bsg_reply->result,
1942 bsg_reply->reply_payload_rcv_len);
1943 /* Always return success, vendor rsp carries correct status */
1948 qlafx00_mgmt_cmd(struct bsg_job *bsg_job)
1950 struct fc_bsg_request *bsg_request = bsg_job->request;
1951 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1952 scsi_qla_host_t *vha = shost_priv(host);
1953 struct qla_hw_data *ha = vha->hw;
1954 int rval = (DRIVER_ERROR << 16);
1955 struct qla_mt_iocb_rqst_fx00 *piocb_rqst;
1957 int req_sg_cnt = 0, rsp_sg_cnt = 0;
1958 struct fc_port *fcport;
1959 char *type = "FC_BSG_HST_FX_MGMT";
1961 /* Copy the IOCB specific information */
1962 piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *)
1963 &bsg_request->rqst_data.h_vendor.vendor_cmd[1];
1965 /* Dump the vendor information */
1966 ql_dump_buffer(ql_dbg_user + ql_dbg_verbose , vha, 0x70cf,
1967 piocb_rqst, sizeof(*piocb_rqst));
1969 if (!vha->flags.online) {
1970 ql_log(ql_log_warn, vha, 0x70d0,
1971 "Host is not online.\n");
1976 if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID) {
1977 req_sg_cnt = dma_map_sg(&ha->pdev->dev,
1978 bsg_job->request_payload.sg_list,
1979 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1981 ql_log(ql_log_warn, vha, 0x70c7,
1982 "dma_map_sg return %d for request\n", req_sg_cnt);
1988 if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID) {
1989 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
1990 bsg_job->reply_payload.sg_list,
1991 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1993 ql_log(ql_log_warn, vha, 0x70c8,
1994 "dma_map_sg return %d for reply\n", rsp_sg_cnt);
1996 goto done_unmap_req_sg;
2000 ql_dbg(ql_dbg_user, vha, 0x70c9,
2001 "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
2002 "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
2003 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
2005 /* Allocate a dummy fcport structure, since functions preparing the
2006 * IOCB and mailbox command retrieves port specific information
2007 * from fcport structure. For Host based ELS commands there will be
2008 * no fcport structure allocated
2010 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2012 ql_log(ql_log_warn, vha, 0x70ca,
2013 "Failed to allocate fcport.\n");
2015 goto done_unmap_rsp_sg;
2018 /* Alloc SRB structure */
2019 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
2021 ql_log(ql_log_warn, vha, 0x70cb,
2022 "qla2x00_get_sp failed.\n");
2024 goto done_free_fcport;
2027 /* Initialize all required fields of fcport */
2029 fcport->loop_id = piocb_rqst->dataword;
2031 sp->type = SRB_FXIOCB_BCMD;
2032 sp->name = "bsg_fx_mgmt";
2033 sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
2034 sp->u.bsg_job = bsg_job;
2035 sp->free = qla2x00_bsg_sp_free;
2036 sp->done = qla2x00_bsg_job_done;
2038 ql_dbg(ql_dbg_user, vha, 0x70cc,
2039 "bsg rqst type: %s fx_mgmt_type: %x id=%x\n",
2040 type, piocb_rqst->func_type, fcport->loop_id);
2042 rval = qla2x00_start_sp(sp);
2043 if (rval != QLA_SUCCESS) {
2044 ql_log(ql_log_warn, vha, 0x70cd,
2045 "qla2x00_start_sp failed=%d.\n", rval);
2046 mempool_free(sp, ha->srb_mempool);
2048 goto done_free_fcport;
2056 if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID)
2057 dma_unmap_sg(&ha->pdev->dev,
2058 bsg_job->reply_payload.sg_list,
2059 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
2061 if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID)
2062 dma_unmap_sg(&ha->pdev->dev,
2063 bsg_job->request_payload.sg_list,
2064 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
2071 qla26xx_serdes_op(struct bsg_job *bsg_job)
2073 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2074 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
2075 scsi_qla_host_t *vha = shost_priv(host);
2077 struct qla_serdes_reg sr;
2079 memset(&sr, 0, sizeof(sr));
2081 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2082 bsg_job->request_payload.sg_cnt, &sr, sizeof(sr));
2085 case INT_SC_SERDES_WRITE_REG:
2086 rval = qla2x00_write_serdes_word(vha, sr.addr, sr.val);
2087 bsg_reply->reply_payload_rcv_len = 0;
2089 case INT_SC_SERDES_READ_REG:
2090 rval = qla2x00_read_serdes_word(vha, sr.addr, &sr.val);
2091 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2092 bsg_job->reply_payload.sg_cnt, &sr, sizeof(sr));
2093 bsg_reply->reply_payload_rcv_len = sizeof(sr);
2096 ql_dbg(ql_dbg_user, vha, 0x708c,
2097 "Unknown serdes cmd %x.\n", sr.cmd);
2102 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
2103 rval ? EXT_STATUS_MAILBOX : 0;
2105 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2106 bsg_reply->result = DID_OK << 16;
2107 bsg_job_done(bsg_job, bsg_reply->result,
2108 bsg_reply->reply_payload_rcv_len);
2113 qla8044_serdes_op(struct bsg_job *bsg_job)
2115 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2116 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
2117 scsi_qla_host_t *vha = shost_priv(host);
2119 struct qla_serdes_reg_ex sr;
2121 memset(&sr, 0, sizeof(sr));
2123 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2124 bsg_job->request_payload.sg_cnt, &sr, sizeof(sr));
2127 case INT_SC_SERDES_WRITE_REG:
2128 rval = qla8044_write_serdes_word(vha, sr.addr, sr.val);
2129 bsg_reply->reply_payload_rcv_len = 0;
2131 case INT_SC_SERDES_READ_REG:
2132 rval = qla8044_read_serdes_word(vha, sr.addr, &sr.val);
2133 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2134 bsg_job->reply_payload.sg_cnt, &sr, sizeof(sr));
2135 bsg_reply->reply_payload_rcv_len = sizeof(sr);
2138 ql_dbg(ql_dbg_user, vha, 0x7020,
2139 "Unknown serdes cmd %x.\n", sr.cmd);
2144 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
2145 rval ? EXT_STATUS_MAILBOX : 0;
2147 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2148 bsg_reply->result = DID_OK << 16;
2149 bsg_job_done(bsg_job, bsg_reply->result,
2150 bsg_reply->reply_payload_rcv_len);
2155 qla27xx_get_flash_upd_cap(struct bsg_job *bsg_job)
2157 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2158 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
2159 scsi_qla_host_t *vha = shost_priv(host);
2160 struct qla_hw_data *ha = vha->hw;
2161 struct qla_flash_update_caps cap;
2163 if (!(IS_QLA27XX(ha)) && !IS_QLA28XX(ha))
2166 memset(&cap, 0, sizeof(cap));
2167 cap.capabilities = (uint64_t)ha->fw_attributes_ext[1] << 48 |
2168 (uint64_t)ha->fw_attributes_ext[0] << 32 |
2169 (uint64_t)ha->fw_attributes_h << 16 |
2170 (uint64_t)ha->fw_attributes;
2172 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2173 bsg_job->reply_payload.sg_cnt, &cap, sizeof(cap));
2174 bsg_reply->reply_payload_rcv_len = sizeof(cap);
2176 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
2179 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2180 bsg_reply->result = DID_OK << 16;
2181 bsg_job_done(bsg_job, bsg_reply->result,
2182 bsg_reply->reply_payload_rcv_len);
2187 qla27xx_set_flash_upd_cap(struct bsg_job *bsg_job)
2189 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2190 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
2191 scsi_qla_host_t *vha = shost_priv(host);
2192 struct qla_hw_data *ha = vha->hw;
2193 uint64_t online_fw_attr = 0;
2194 struct qla_flash_update_caps cap;
2196 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
2199 memset(&cap, 0, sizeof(cap));
2200 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2201 bsg_job->request_payload.sg_cnt, &cap, sizeof(cap));
2203 online_fw_attr = (uint64_t)ha->fw_attributes_ext[1] << 48 |
2204 (uint64_t)ha->fw_attributes_ext[0] << 32 |
2205 (uint64_t)ha->fw_attributes_h << 16 |
2206 (uint64_t)ha->fw_attributes;
2208 if (online_fw_attr != cap.capabilities) {
2209 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
2210 EXT_STATUS_INVALID_PARAM;
2214 if (cap.outage_duration < MAX_LOOP_TIMEOUT) {
2215 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
2216 EXT_STATUS_INVALID_PARAM;
2220 bsg_reply->reply_payload_rcv_len = 0;
2222 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
2225 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2226 bsg_reply->result = DID_OK << 16;
2227 bsg_job_done(bsg_job, bsg_reply->result,
2228 bsg_reply->reply_payload_rcv_len);
2233 qla27xx_get_bbcr_data(struct bsg_job *bsg_job)
2235 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2236 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
2237 scsi_qla_host_t *vha = shost_priv(host);
2238 struct qla_hw_data *ha = vha->hw;
2239 struct qla_bbcr_data bbcr;
2240 uint16_t loop_id, topo, sw_cap;
2241 uint8_t domain, area, al_pa, state;
2244 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
2247 memset(&bbcr, 0, sizeof(bbcr));
2249 if (vha->flags.bbcr_enable)
2250 bbcr.status = QLA_BBCR_STATUS_ENABLED;
2252 bbcr.status = QLA_BBCR_STATUS_DISABLED;
2254 if (bbcr.status == QLA_BBCR_STATUS_ENABLED) {
2255 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2256 &area, &domain, &topo, &sw_cap);
2257 if (rval != QLA_SUCCESS) {
2258 bbcr.status = QLA_BBCR_STATUS_UNKNOWN;
2259 bbcr.state = QLA_BBCR_STATE_OFFLINE;
2260 bbcr.mbx1 = loop_id;
2264 state = (vha->bbcr >> 12) & 0x1;
2267 bbcr.state = QLA_BBCR_STATE_OFFLINE;
2268 bbcr.offline_reason_code = QLA_BBCR_REASON_LOGIN_REJECT;
2270 bbcr.state = QLA_BBCR_STATE_ONLINE;
2271 bbcr.negotiated_bbscn = (vha->bbcr >> 8) & 0xf;
2274 bbcr.configured_bbscn = vha->bbcr & 0xf;
2278 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2279 bsg_job->reply_payload.sg_cnt, &bbcr, sizeof(bbcr));
2280 bsg_reply->reply_payload_rcv_len = sizeof(bbcr);
2282 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = EXT_STATUS_OK;
2284 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2285 bsg_reply->result = DID_OK << 16;
2286 bsg_job_done(bsg_job, bsg_reply->result,
2287 bsg_reply->reply_payload_rcv_len);
2292 qla2x00_get_priv_stats(struct bsg_job *bsg_job)
2294 struct fc_bsg_request *bsg_request = bsg_job->request;
2295 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2296 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
2297 scsi_qla_host_t *vha = shost_priv(host);
2298 struct qla_hw_data *ha = vha->hw;
2299 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2300 struct link_statistics *stats = NULL;
2301 dma_addr_t stats_dma;
2303 uint32_t *cmd = bsg_request->rqst_data.h_vendor.vendor_cmd;
2304 uint options = cmd[0] == QL_VND_GET_PRIV_STATS_EX ? cmd[1] : 0;
2306 if (test_bit(UNLOADING, &vha->dpc_flags))
2309 if (unlikely(pci_channel_offline(ha->pdev)))
2312 if (qla2x00_reset_active(vha))
2315 if (!IS_FWI2_CAPABLE(ha))
2318 stats = dma_alloc_coherent(&ha->pdev->dev, sizeof(*stats), &stats_dma,
2321 ql_log(ql_log_warn, vha, 0x70e2,
2322 "Failed to allocate memory for stats.\n");
2326 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma, options);
2328 if (rval == QLA_SUCCESS) {
2329 ql_dump_buffer(ql_dbg_user + ql_dbg_verbose, vha, 0x70e5,
2330 stats, sizeof(*stats));
2331 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2332 bsg_job->reply_payload.sg_cnt, stats, sizeof(*stats));
2335 bsg_reply->reply_payload_rcv_len = sizeof(*stats);
2336 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
2337 rval ? EXT_STATUS_MAILBOX : EXT_STATUS_OK;
2339 bsg_job->reply_len = sizeof(*bsg_reply);
2340 bsg_reply->result = DID_OK << 16;
2341 bsg_job_done(bsg_job, bsg_reply->result,
2342 bsg_reply->reply_payload_rcv_len);
2344 dma_free_coherent(&ha->pdev->dev, sizeof(*stats),
2351 qla2x00_do_dport_diagnostics(struct bsg_job *bsg_job)
2353 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2354 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
2355 scsi_qla_host_t *vha = shost_priv(host);
2357 struct qla_dport_diag *dd;
2359 if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw) &&
2360 !IS_QLA28XX(vha->hw))
2363 dd = kmalloc(sizeof(*dd), GFP_KERNEL);
2365 ql_log(ql_log_warn, vha, 0x70db,
2366 "Failed to allocate memory for dport.\n");
2370 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2371 bsg_job->request_payload.sg_cnt, dd, sizeof(*dd));
2373 rval = qla26xx_dport_diagnostics(
2374 vha, dd->buf, sizeof(dd->buf), dd->options);
2375 if (rval == QLA_SUCCESS) {
2376 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2377 bsg_job->reply_payload.sg_cnt, dd, sizeof(*dd));
2380 bsg_reply->reply_payload_rcv_len = sizeof(*dd);
2381 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
2382 rval ? EXT_STATUS_MAILBOX : EXT_STATUS_OK;
2384 bsg_job->reply_len = sizeof(*bsg_reply);
2385 bsg_reply->result = DID_OK << 16;
2386 bsg_job_done(bsg_job, bsg_reply->result,
2387 bsg_reply->reply_payload_rcv_len);
2395 qla2x00_get_flash_image_status(struct bsg_job *bsg_job)
2397 scsi_qla_host_t *vha = shost_priv(fc_bsg_to_shost(bsg_job));
2398 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2399 struct qla_hw_data *ha = vha->hw;
2400 struct qla_active_regions regions = { };
2401 struct active_regions active_regions = { };
2403 qla28xx_get_aux_images(vha, &active_regions);
2404 regions.global_image = active_regions.global;
2406 if (IS_QLA28XX(ha)) {
2407 qla27xx_get_active_image(vha, &active_regions);
2408 regions.board_config = active_regions.aux.board_config;
2409 regions.vpd_nvram = active_regions.aux.vpd_nvram;
2410 regions.npiv_config_0_1 = active_regions.aux.npiv_config_0_1;
2411 regions.npiv_config_2_3 = active_regions.aux.npiv_config_2_3;
2414 ql_dbg(ql_dbg_user, vha, 0x70e1,
2415 "%s(%lu): FW=%u BCFG=%u VPDNVR=%u NPIV01=%u NPIV02=%u\n",
2416 __func__, vha->host_no, regions.global_image,
2417 regions.board_config, regions.vpd_nvram,
2418 regions.npiv_config_0_1, regions.npiv_config_2_3);
2420 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2421 bsg_job->reply_payload.sg_cnt, ®ions, sizeof(regions));
2423 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = EXT_STATUS_OK;
2424 bsg_reply->reply_payload_rcv_len = sizeof(regions);
2425 bsg_reply->result = DID_OK << 16;
2426 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2427 bsg_job_done(bsg_job, bsg_reply->result,
2428 bsg_reply->reply_payload_rcv_len);
2434 qla2x00_process_vendor_specific(struct bsg_job *bsg_job)
2436 struct fc_bsg_request *bsg_request = bsg_job->request;
2438 switch (bsg_request->rqst_data.h_vendor.vendor_cmd[0]) {
2439 case QL_VND_LOOPBACK:
2440 return qla2x00_process_loopback(bsg_job);
2442 case QL_VND_A84_RESET:
2443 return qla84xx_reset(bsg_job);
2445 case QL_VND_A84_UPDATE_FW:
2446 return qla84xx_updatefw(bsg_job);
2448 case QL_VND_A84_MGMT_CMD:
2449 return qla84xx_mgmt_cmd(bsg_job);
2452 return qla24xx_iidma(bsg_job);
2454 case QL_VND_FCP_PRIO_CFG_CMD:
2455 return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job);
2457 case QL_VND_READ_FLASH:
2458 return qla2x00_read_optrom(bsg_job);
2460 case QL_VND_UPDATE_FLASH:
2461 return qla2x00_update_optrom(bsg_job);
2463 case QL_VND_SET_FRU_VERSION:
2464 return qla2x00_update_fru_versions(bsg_job);
2466 case QL_VND_READ_FRU_STATUS:
2467 return qla2x00_read_fru_status(bsg_job);
2469 case QL_VND_WRITE_FRU_STATUS:
2470 return qla2x00_write_fru_status(bsg_job);
2472 case QL_VND_WRITE_I2C:
2473 return qla2x00_write_i2c(bsg_job);
2475 case QL_VND_READ_I2C:
2476 return qla2x00_read_i2c(bsg_job);
2478 case QL_VND_DIAG_IO_CMD:
2479 return qla24xx_process_bidir_cmd(bsg_job);
2481 case QL_VND_FX00_MGMT_CMD:
2482 return qlafx00_mgmt_cmd(bsg_job);
2484 case QL_VND_SERDES_OP:
2485 return qla26xx_serdes_op(bsg_job);
2487 case QL_VND_SERDES_OP_EX:
2488 return qla8044_serdes_op(bsg_job);
2490 case QL_VND_GET_FLASH_UPDATE_CAPS:
2491 return qla27xx_get_flash_upd_cap(bsg_job);
2493 case QL_VND_SET_FLASH_UPDATE_CAPS:
2494 return qla27xx_set_flash_upd_cap(bsg_job);
2496 case QL_VND_GET_BBCR_DATA:
2497 return qla27xx_get_bbcr_data(bsg_job);
2499 case QL_VND_GET_PRIV_STATS:
2500 case QL_VND_GET_PRIV_STATS_EX:
2501 return qla2x00_get_priv_stats(bsg_job);
2503 case QL_VND_DPORT_DIAGNOSTICS:
2504 return qla2x00_do_dport_diagnostics(bsg_job);
2506 case QL_VND_SS_GET_FLASH_IMAGE_STATUS:
2507 return qla2x00_get_flash_image_status(bsg_job);
2515 qla24xx_bsg_request(struct bsg_job *bsg_job)
2517 struct fc_bsg_request *bsg_request = bsg_job->request;
2518 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2520 struct fc_rport *rport;
2521 struct Scsi_Host *host;
2522 scsi_qla_host_t *vha;
2524 /* In case no data transferred. */
2525 bsg_reply->reply_payload_rcv_len = 0;
2527 if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
2528 rport = fc_bsg_to_rport(bsg_job);
2529 host = rport_to_shost(rport);
2530 vha = shost_priv(host);
2532 host = fc_bsg_to_shost(bsg_job);
2533 vha = shost_priv(host);
2536 if (qla2x00_chip_is_down(vha)) {
2537 ql_dbg(ql_dbg_user, vha, 0x709f,
2538 "BSG: ISP abort active/needed -- cmd=%d.\n",
2539 bsg_request->msgcode);
2543 ql_dbg(ql_dbg_user, vha, 0x7000,
2544 "Entered %s msgcode=0x%x.\n", __func__, bsg_request->msgcode);
2546 switch (bsg_request->msgcode) {
2547 case FC_BSG_RPT_ELS:
2548 case FC_BSG_HST_ELS_NOLOGIN:
2549 ret = qla2x00_process_els(bsg_job);
2552 ret = qla2x00_process_ct(bsg_job);
2554 case FC_BSG_HST_VENDOR:
2555 ret = qla2x00_process_vendor_specific(bsg_job);
2557 case FC_BSG_HST_ADD_RPORT:
2558 case FC_BSG_HST_DEL_RPORT:
2561 ql_log(ql_log_warn, vha, 0x705a, "Unsupported BSG request.\n");
2568 qla24xx_bsg_timeout(struct bsg_job *bsg_job)
2570 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2571 scsi_qla_host_t *vha = shost_priv(fc_bsg_to_shost(bsg_job));
2572 struct qla_hw_data *ha = vha->hw;
2575 unsigned long flags;
2576 struct req_que *req;
2578 /* find the bsg job from the active list of commands */
2579 spin_lock_irqsave(&ha->hardware_lock, flags);
2580 for (que = 0; que < ha->max_req_queues; que++) {
2581 req = ha->req_q_map[que];
2585 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
2586 sp = req->outstanding_cmds[cnt];
2588 if (((sp->type == SRB_CT_CMD) ||
2589 (sp->type == SRB_ELS_CMD_HST) ||
2590 (sp->type == SRB_FXIOCB_BCMD))
2591 && (sp->u.bsg_job == bsg_job)) {
2592 req->outstanding_cmds[cnt] = NULL;
2593 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2594 if (ha->isp_ops->abort_command(sp)) {
2595 ql_log(ql_log_warn, vha, 0x7089,
2596 "mbx abort_command "
2598 bsg_reply->result = -EIO;
2600 ql_dbg(ql_dbg_user, vha, 0x708a,
2601 "mbx abort_command "
2603 bsg_reply->result = 0;
2605 spin_lock_irqsave(&ha->hardware_lock, flags);
2611 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2612 ql_log(ql_log_info, vha, 0x708b, "SRB not found to abort.\n");
2613 bsg_reply->result = -ENXIO;
2617 spin_unlock_irqrestore(&ha->hardware_lock, flags);