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>
13 /* BSG support for ELS/CT pass through */
15 qla2x00_bsg_job_done(void *data, void *ptr, int res)
17 srb_t *sp = (srb_t *)ptr;
18 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
19 struct fc_bsg_job *bsg_job = sp->u.bsg_job;
21 bsg_job->reply->result = res;
22 bsg_job->job_done(bsg_job);
27 qla2x00_bsg_sp_free(void *data, void *ptr)
29 srb_t *sp = (srb_t *)ptr;
30 struct scsi_qla_host *vha = sp->fcport->vha;
31 struct fc_bsg_job *bsg_job = sp->u.bsg_job;
32 struct qla_hw_data *ha = vha->hw;
33 struct qla_mt_iocb_rqst_fx00 *piocb_rqst;
35 if (sp->type == SRB_FXIOCB_BCMD) {
36 piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *)
37 &bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
39 if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID)
40 dma_unmap_sg(&ha->pdev->dev,
41 bsg_job->request_payload.sg_list,
42 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
44 if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID)
45 dma_unmap_sg(&ha->pdev->dev,
46 bsg_job->reply_payload.sg_list,
47 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
49 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
50 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
52 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
53 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
56 if (sp->type == SRB_CT_CMD ||
57 sp->type == SRB_FXIOCB_BCMD ||
58 sp->type == SRB_ELS_CMD_HST)
60 qla2x00_rel_sp(vha, sp);
64 qla24xx_fcp_prio_cfg_valid(scsi_qla_host_t *vha,
65 struct qla_fcp_prio_cfg *pri_cfg, uint8_t flag)
67 int i, ret, num_valid;
69 struct qla_fcp_prio_entry *pri_entry;
70 uint32_t *bcode_val_ptr, bcode_val;
74 bcode = (uint8_t *)pri_cfg;
75 bcode_val_ptr = (uint32_t *)pri_cfg;
76 bcode_val = (uint32_t)(*bcode_val_ptr);
78 if (bcode_val == 0xFFFFFFFF) {
79 /* No FCP Priority config data in flash */
80 ql_dbg(ql_dbg_user, vha, 0x7051,
81 "No FCP Priority config data.\n");
85 if (bcode[0] != 'H' || bcode[1] != 'Q' || bcode[2] != 'O' ||
87 /* Invalid FCP priority data header*/
88 ql_dbg(ql_dbg_user, vha, 0x7052,
89 "Invalid FCP Priority data header. bcode=0x%x.\n",
96 pri_entry = &pri_cfg->entry[0];
97 for (i = 0; i < pri_cfg->num_entries; i++) {
98 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
103 if (num_valid == 0) {
104 /* No valid FCP priority data entries */
105 ql_dbg(ql_dbg_user, vha, 0x7053,
106 "No valid FCP Priority data entries.\n");
109 /* FCP priority data is valid */
110 ql_dbg(ql_dbg_user, vha, 0x7054,
111 "Valid FCP priority data. num entries = %d.\n",
119 qla24xx_proc_fcp_prio_cfg_cmd(struct fc_bsg_job *bsg_job)
121 struct Scsi_Host *host = bsg_job->shost;
122 scsi_qla_host_t *vha = shost_priv(host);
123 struct qla_hw_data *ha = vha->hw;
128 if (!(IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || IS_P3P_TYPE(ha))) {
130 goto exit_fcp_prio_cfg;
133 /* Get the sub command */
134 oper = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
136 /* Only set config is allowed if config memory is not allocated */
137 if (!ha->fcp_prio_cfg && (oper != QLFC_FCP_PRIO_SET_CONFIG)) {
139 goto exit_fcp_prio_cfg;
142 case QLFC_FCP_PRIO_DISABLE:
143 if (ha->flags.fcp_prio_enabled) {
144 ha->flags.fcp_prio_enabled = 0;
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;
156 case QLFC_FCP_PRIO_ENABLE:
157 if (!ha->flags.fcp_prio_enabled) {
158 if (ha->fcp_prio_cfg) {
159 ha->flags.fcp_prio_enabled = 1;
160 ha->fcp_prio_cfg->attributes |=
161 FCP_PRIO_ATTR_ENABLE;
162 qla24xx_update_all_fcp_prio(vha);
163 bsg_job->reply->result = DID_OK;
166 bsg_job->reply->result = (DID_ERROR << 16);
167 goto exit_fcp_prio_cfg;
172 case QLFC_FCP_PRIO_GET_CONFIG:
173 len = bsg_job->reply_payload.payload_len;
174 if (!len || len > FCP_PRIO_CFG_SIZE) {
176 bsg_job->reply->result = (DID_ERROR << 16);
177 goto exit_fcp_prio_cfg;
180 bsg_job->reply->result = DID_OK;
181 bsg_job->reply->reply_payload_rcv_len =
183 bsg_job->reply_payload.sg_list,
184 bsg_job->reply_payload.sg_cnt, ha->fcp_prio_cfg,
189 case QLFC_FCP_PRIO_SET_CONFIG:
190 len = bsg_job->request_payload.payload_len;
191 if (!len || len > FCP_PRIO_CFG_SIZE) {
192 bsg_job->reply->result = (DID_ERROR << 16);
194 goto exit_fcp_prio_cfg;
197 if (!ha->fcp_prio_cfg) {
198 ha->fcp_prio_cfg = vmalloc(FCP_PRIO_CFG_SIZE);
199 if (!ha->fcp_prio_cfg) {
200 ql_log(ql_log_warn, vha, 0x7050,
201 "Unable to allocate memory for fcp prio "
202 "config data (%x).\n", FCP_PRIO_CFG_SIZE);
203 bsg_job->reply->result = (DID_ERROR << 16);
205 goto exit_fcp_prio_cfg;
209 memset(ha->fcp_prio_cfg, 0, FCP_PRIO_CFG_SIZE);
210 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
211 bsg_job->request_payload.sg_cnt, ha->fcp_prio_cfg,
214 /* validate fcp priority data */
216 if (!qla24xx_fcp_prio_cfg_valid(vha,
217 (struct qla_fcp_prio_cfg *) ha->fcp_prio_cfg, 1)) {
218 bsg_job->reply->result = (DID_ERROR << 16);
220 /* If buffer was invalidatic int
221 * fcp_prio_cfg is of no use
223 vfree(ha->fcp_prio_cfg);
224 ha->fcp_prio_cfg = NULL;
225 goto exit_fcp_prio_cfg;
228 ha->flags.fcp_prio_enabled = 0;
229 if (ha->fcp_prio_cfg->attributes & FCP_PRIO_ATTR_ENABLE)
230 ha->flags.fcp_prio_enabled = 1;
231 qla24xx_update_all_fcp_prio(vha);
232 bsg_job->reply->result = DID_OK;
240 bsg_job->job_done(bsg_job);
245 qla2x00_process_els(struct fc_bsg_job *bsg_job)
247 struct fc_rport *rport;
248 fc_port_t *fcport = NULL;
249 struct Scsi_Host *host;
250 scsi_qla_host_t *vha;
251 struct qla_hw_data *ha;
254 int req_sg_cnt, rsp_sg_cnt;
255 int rval = (DID_ERROR << 16);
256 uint16_t nextlid = 0;
258 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
259 rport = bsg_job->rport;
260 fcport = *(fc_port_t **) rport->dd_data;
261 host = rport_to_shost(rport);
262 vha = shost_priv(host);
264 type = "FC_BSG_RPT_ELS";
266 host = bsg_job->shost;
267 vha = shost_priv(host);
269 type = "FC_BSG_HST_ELS_NOLOGIN";
272 if (!vha->flags.online) {
273 ql_log(ql_log_warn, vha, 0x7005, "Host not online.\n");
278 /* pass through is supported only for ISP 4Gb or higher */
279 if (!IS_FWI2_CAPABLE(ha)) {
280 ql_dbg(ql_dbg_user, vha, 0x7001,
281 "ELS passthru not supported for ISP23xx based adapters.\n");
286 /* Multiple SG's are not supported for ELS requests */
287 if (bsg_job->request_payload.sg_cnt > 1 ||
288 bsg_job->reply_payload.sg_cnt > 1) {
289 ql_dbg(ql_dbg_user, vha, 0x7002,
290 "Multiple SG's are not suppored for ELS requests, "
291 "request_sg_cnt=%x reply_sg_cnt=%x.\n",
292 bsg_job->request_payload.sg_cnt,
293 bsg_job->reply_payload.sg_cnt);
298 /* ELS request for rport */
299 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
300 /* make sure the rport is logged in,
301 * if not perform fabric login
303 if (qla2x00_fabric_login(vha, fcport, &nextlid)) {
304 ql_dbg(ql_dbg_user, vha, 0x7003,
305 "Failed to login port %06X for ELS passthru.\n",
311 /* Allocate a dummy fcport structure, since functions
312 * preparing the IOCB and mailbox command retrieves port
313 * specific information from fcport structure. For Host based
314 * ELS commands there will be no fcport structure allocated
316 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
322 /* Initialize all required fields of fcport */
324 fcport->d_id.b.al_pa =
325 bsg_job->request->rqst_data.h_els.port_id[0];
326 fcport->d_id.b.area =
327 bsg_job->request->rqst_data.h_els.port_id[1];
328 fcport->d_id.b.domain =
329 bsg_job->request->rqst_data.h_els.port_id[2];
331 (fcport->d_id.b.al_pa == 0xFD) ?
332 NPH_FABRIC_CONTROLLER : NPH_F_PORT;
336 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
337 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
339 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
340 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
342 goto done_free_fcport;
345 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
346 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
348 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
349 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
351 goto done_free_fcport;
354 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
355 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
356 ql_log(ql_log_warn, vha, 0x7008,
357 "dma mapping resulted in different sg counts, "
358 "request_sg_cnt: %x dma_request_sg_cnt:%x reply_sg_cnt:%x "
359 "dma_reply_sg_cnt:%x.\n", bsg_job->request_payload.sg_cnt,
360 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
365 /* Alloc SRB structure */
366 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
373 (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
374 SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
376 (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
377 "bsg_els_rpt" : "bsg_els_hst");
378 sp->u.bsg_job = bsg_job;
379 sp->free = qla2x00_bsg_sp_free;
380 sp->done = qla2x00_bsg_job_done;
382 ql_dbg(ql_dbg_user, vha, 0x700a,
383 "bsg rqst type: %s els type: %x - loop-id=%x "
384 "portid=%-2x%02x%02x.\n", type,
385 bsg_job->request->rqst_data.h_els.command_code, fcport->loop_id,
386 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa);
388 rval = qla2x00_start_sp(sp);
389 if (rval != QLA_SUCCESS) {
390 ql_log(ql_log_warn, vha, 0x700e,
391 "qla2x00_start_sp failed = %d\n", rval);
392 qla2x00_rel_sp(vha, sp);
399 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
400 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
401 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
402 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
403 goto done_free_fcport;
406 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS)
412 static inline uint16_t
413 qla24xx_calc_ct_iocbs(uint16_t dsds)
419 iocbs += (dsds - 2) / 5;
427 qla2x00_process_ct(struct fc_bsg_job *bsg_job)
430 struct Scsi_Host *host = bsg_job->shost;
431 scsi_qla_host_t *vha = shost_priv(host);
432 struct qla_hw_data *ha = vha->hw;
433 int rval = (DID_ERROR << 16);
434 int req_sg_cnt, rsp_sg_cnt;
436 struct fc_port *fcport;
437 char *type = "FC_BSG_HST_CT";
440 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
441 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
443 ql_log(ql_log_warn, vha, 0x700f,
444 "dma_map_sg return %d for request\n", req_sg_cnt);
449 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
450 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
452 ql_log(ql_log_warn, vha, 0x7010,
453 "dma_map_sg return %d for reply\n", rsp_sg_cnt);
458 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
459 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
460 ql_log(ql_log_warn, vha, 0x7011,
461 "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
462 "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
463 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
468 if (!vha->flags.online) {
469 ql_log(ql_log_warn, vha, 0x7012,
470 "Host is not online.\n");
476 (bsg_job->request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
480 loop_id = cpu_to_le16(NPH_SNS);
483 loop_id = vha->mgmt_svr_loop_id;
486 ql_dbg(ql_dbg_user, vha, 0x7013,
487 "Unknown loop id: %x.\n", loop_id);
492 /* Allocate a dummy fcport structure, since functions preparing the
493 * IOCB and mailbox command retrieves port specific information
494 * from fcport structure. For Host based ELS commands there will be
495 * no fcport structure allocated
497 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
499 ql_log(ql_log_warn, vha, 0x7014,
500 "Failed to allocate fcport.\n");
505 /* Initialize all required fields of fcport */
507 fcport->d_id.b.al_pa = bsg_job->request->rqst_data.h_ct.port_id[0];
508 fcport->d_id.b.area = bsg_job->request->rqst_data.h_ct.port_id[1];
509 fcport->d_id.b.domain = bsg_job->request->rqst_data.h_ct.port_id[2];
510 fcport->loop_id = loop_id;
512 /* Alloc SRB structure */
513 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
515 ql_log(ql_log_warn, vha, 0x7015,
516 "qla2x00_get_sp failed.\n");
518 goto done_free_fcport;
521 sp->type = SRB_CT_CMD;
523 sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
524 sp->u.bsg_job = bsg_job;
525 sp->free = qla2x00_bsg_sp_free;
526 sp->done = qla2x00_bsg_job_done;
528 ql_dbg(ql_dbg_user, vha, 0x7016,
529 "bsg rqst type: %s else type: %x - "
530 "loop-id=%x portid=%02x%02x%02x.\n", type,
531 (bsg_job->request->rqst_data.h_ct.preamble_word2 >> 16),
532 fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
533 fcport->d_id.b.al_pa);
535 rval = qla2x00_start_sp(sp);
536 if (rval != QLA_SUCCESS) {
537 ql_log(ql_log_warn, vha, 0x7017,
538 "qla2x00_start_sp failed=%d.\n", rval);
539 qla2x00_rel_sp(vha, sp);
541 goto done_free_fcport;
548 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
549 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
550 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
551 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
556 /* Disable loopback mode */
558 qla81xx_reset_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
563 uint16_t new_config[4];
564 struct qla_hw_data *ha = vha->hw;
566 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha))
567 goto done_reset_internal;
569 memset(new_config, 0 , sizeof(new_config));
570 if ((config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
571 ENABLE_INTERNAL_LOOPBACK ||
572 (config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
573 ENABLE_EXTERNAL_LOOPBACK) {
574 new_config[0] = config[0] & ~INTERNAL_LOOPBACK_MASK;
575 ql_dbg(ql_dbg_user, vha, 0x70bf, "new_config[0]=%02x\n",
576 (new_config[0] & INTERNAL_LOOPBACK_MASK));
577 memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ;
579 ha->notify_dcbx_comp = wait;
580 ha->notify_lb_portup_comp = wait2;
582 ret = qla81xx_set_port_config(vha, new_config);
583 if (ret != QLA_SUCCESS) {
584 ql_log(ql_log_warn, vha, 0x7025,
585 "Set port config failed.\n");
586 ha->notify_dcbx_comp = 0;
587 ha->notify_lb_portup_comp = 0;
589 goto done_reset_internal;
592 /* Wait for DCBX complete event */
593 if (wait && !wait_for_completion_timeout(&ha->dcbx_comp,
594 (DCBX_COMP_TIMEOUT * HZ))) {
595 ql_dbg(ql_dbg_user, vha, 0x7026,
596 "DCBX completion not received.\n");
597 ha->notify_dcbx_comp = 0;
598 ha->notify_lb_portup_comp = 0;
600 goto done_reset_internal;
602 ql_dbg(ql_dbg_user, vha, 0x7027,
603 "DCBX completion received.\n");
606 !wait_for_completion_timeout(&ha->lb_portup_comp,
607 (LB_PORTUP_COMP_TIMEOUT * HZ))) {
608 ql_dbg(ql_dbg_user, vha, 0x70c5,
609 "Port up completion not received.\n");
610 ha->notify_lb_portup_comp = 0;
612 goto done_reset_internal;
614 ql_dbg(ql_dbg_user, vha, 0x70c6,
615 "Port up completion received.\n");
617 ha->notify_dcbx_comp = 0;
618 ha->notify_lb_portup_comp = 0;
625 * Set the port configuration to enable the internal or external loopback
626 * depending on the loopback mode.
629 qla81xx_set_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
630 uint16_t *new_config, uint16_t mode)
634 unsigned long rem_tmo = 0, current_tmo = 0;
635 struct qla_hw_data *ha = vha->hw;
637 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha))
638 goto done_set_internal;
640 if (mode == INTERNAL_LOOPBACK)
641 new_config[0] = config[0] | (ENABLE_INTERNAL_LOOPBACK << 1);
642 else if (mode == EXTERNAL_LOOPBACK)
643 new_config[0] = config[0] | (ENABLE_EXTERNAL_LOOPBACK << 1);
644 ql_dbg(ql_dbg_user, vha, 0x70be,
645 "new_config[0]=%02x\n", (new_config[0] & INTERNAL_LOOPBACK_MASK));
647 memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3);
649 ha->notify_dcbx_comp = 1;
650 ret = qla81xx_set_port_config(vha, new_config);
651 if (ret != QLA_SUCCESS) {
652 ql_log(ql_log_warn, vha, 0x7021,
653 "set port config failed.\n");
654 ha->notify_dcbx_comp = 0;
656 goto done_set_internal;
659 /* Wait for DCBX complete event */
660 current_tmo = DCBX_COMP_TIMEOUT * HZ;
662 rem_tmo = wait_for_completion_timeout(&ha->dcbx_comp,
664 if (!ha->idc_extend_tmo || rem_tmo) {
665 ha->idc_extend_tmo = 0;
668 current_tmo = ha->idc_extend_tmo * HZ;
669 ha->idc_extend_tmo = 0;
673 ql_dbg(ql_dbg_user, vha, 0x7022,
674 "DCBX completion not received.\n");
675 ret = qla81xx_reset_loopback_mode(vha, new_config, 0, 0);
677 * If the reset of the loopback mode doesn't work take a FCoE
678 * dump and reset the chip.
681 ha->isp_ops->fw_dump(vha, 0);
682 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
686 if (ha->flags.idc_compl_status) {
687 ql_dbg(ql_dbg_user, vha, 0x70c3,
688 "Bad status in IDC Completion AEN\n");
690 ha->flags.idc_compl_status = 0;
692 ql_dbg(ql_dbg_user, vha, 0x7023,
693 "DCBX completion received.\n");
696 ha->notify_dcbx_comp = 0;
697 ha->idc_extend_tmo = 0;
704 qla2x00_process_loopback(struct fc_bsg_job *bsg_job)
706 struct Scsi_Host *host = bsg_job->shost;
707 scsi_qla_host_t *vha = shost_priv(host);
708 struct qla_hw_data *ha = vha->hw;
710 uint8_t command_sent;
712 struct msg_echo_lb elreq;
713 uint16_t response[MAILBOX_REGISTER_COUNT];
714 uint16_t config[4], new_config[4];
716 uint8_t *req_data = NULL;
717 dma_addr_t req_data_dma;
718 uint32_t req_data_len;
719 uint8_t *rsp_data = NULL;
720 dma_addr_t rsp_data_dma;
721 uint32_t rsp_data_len;
723 if (!vha->flags.online) {
724 ql_log(ql_log_warn, vha, 0x7019, "Host is not online.\n");
728 memset(&elreq, 0, sizeof(elreq));
730 elreq.req_sg_cnt = dma_map_sg(&ha->pdev->dev,
731 bsg_job->request_payload.sg_list, bsg_job->request_payload.sg_cnt,
734 if (!elreq.req_sg_cnt) {
735 ql_log(ql_log_warn, vha, 0x701a,
736 "dma_map_sg returned %d for request.\n", elreq.req_sg_cnt);
740 elreq.rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
741 bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
744 if (!elreq.rsp_sg_cnt) {
745 ql_log(ql_log_warn, vha, 0x701b,
746 "dma_map_sg returned %d for reply.\n", elreq.rsp_sg_cnt);
748 goto done_unmap_req_sg;
751 if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
752 (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
753 ql_log(ql_log_warn, vha, 0x701c,
754 "dma mapping resulted in different sg counts, "
755 "request_sg_cnt: %x dma_request_sg_cnt: %x "
756 "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
757 bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
758 bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt);
762 req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
763 req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
764 &req_data_dma, GFP_KERNEL);
766 ql_log(ql_log_warn, vha, 0x701d,
767 "dma alloc failed for req_data.\n");
772 rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
773 &rsp_data_dma, GFP_KERNEL);
775 ql_log(ql_log_warn, vha, 0x7004,
776 "dma alloc failed for rsp_data.\n");
778 goto done_free_dma_req;
781 /* Copy the request buffer in req_data now */
782 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
783 bsg_job->request_payload.sg_cnt, req_data, req_data_len);
785 elreq.send_dma = req_data_dma;
786 elreq.rcv_dma = rsp_data_dma;
787 elreq.transfer_size = req_data_len;
789 elreq.options = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
790 elreq.iteration_count =
791 bsg_job->request->rqst_data.h_vendor.vendor_cmd[2];
793 if (atomic_read(&vha->loop_state) == LOOP_READY &&
794 (ha->current_topology == ISP_CFG_F ||
795 (le32_to_cpu(*(uint32_t *)req_data) == ELS_OPCODE_BYTE &&
796 req_data_len == MAX_ELS_FRAME_PAYLOAD)) &&
797 elreq.options == EXTERNAL_LOOPBACK) {
798 type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
799 ql_dbg(ql_dbg_user, vha, 0x701e,
800 "BSG request type: %s.\n", type);
801 command_sent = INT_DEF_LB_ECHO_CMD;
802 rval = qla2x00_echo_test(vha, &elreq, response);
804 if (IS_QLA81XX(ha) || IS_QLA8031(ha) || IS_QLA8044(ha)) {
805 memset(config, 0, sizeof(config));
806 memset(new_config, 0, sizeof(new_config));
808 if (qla81xx_get_port_config(vha, config)) {
809 ql_log(ql_log_warn, vha, 0x701f,
810 "Get port config failed.\n");
812 goto done_free_dma_rsp;
815 if ((config[0] & INTERNAL_LOOPBACK_MASK) != 0) {
816 ql_dbg(ql_dbg_user, vha, 0x70c4,
817 "Loopback operation already in "
820 goto done_free_dma_rsp;
823 ql_dbg(ql_dbg_user, vha, 0x70c0,
824 "elreq.options=%04x\n", elreq.options);
826 if (elreq.options == EXTERNAL_LOOPBACK)
827 if (IS_QLA8031(ha) || IS_QLA8044(ha))
828 rval = qla81xx_set_loopback_mode(vha,
829 config, new_config, elreq.options);
831 rval = qla81xx_reset_loopback_mode(vha,
834 rval = qla81xx_set_loopback_mode(vha, config,
835 new_config, elreq.options);
839 goto done_free_dma_rsp;
842 type = "FC_BSG_HST_VENDOR_LOOPBACK";
843 ql_dbg(ql_dbg_user, vha, 0x7028,
844 "BSG request type: %s.\n", type);
846 command_sent = INT_DEF_LB_LOOPBACK_CMD;
847 rval = qla2x00_loopback_test(vha, &elreq, response);
849 if (response[0] == MBS_COMMAND_ERROR &&
850 response[1] == MBS_LB_RESET) {
851 ql_log(ql_log_warn, vha, 0x7029,
852 "MBX command error, Aborting ISP.\n");
853 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
854 qla2xxx_wake_dpc(vha);
855 qla2x00_wait_for_chip_reset(vha);
856 /* Also reset the MPI */
857 if (IS_QLA81XX(ha)) {
858 if (qla81xx_restart_mpi_firmware(vha) !=
860 ql_log(ql_log_warn, vha, 0x702a,
861 "MPI reset failed.\n");
866 goto done_free_dma_rsp;
872 /* Revert back to original port config
873 * Also clear internal loopback
875 ret = qla81xx_reset_loopback_mode(vha,
879 * If the reset of the loopback mode
880 * doesn't work take FCoE dump and then
883 ha->isp_ops->fw_dump(vha, 0);
884 set_bit(ISP_ABORT_NEEDED,
891 type = "FC_BSG_HST_VENDOR_LOOPBACK";
892 ql_dbg(ql_dbg_user, vha, 0x702b,
893 "BSG request type: %s.\n", type);
894 command_sent = INT_DEF_LB_LOOPBACK_CMD;
895 rval = qla2x00_loopback_test(vha, &elreq, response);
900 ql_log(ql_log_warn, vha, 0x702c,
901 "Vendor request %s failed.\n", type);
904 bsg_job->reply->result = (DID_ERROR << 16);
905 bsg_job->reply->reply_payload_rcv_len = 0;
907 ql_dbg(ql_dbg_user, vha, 0x702d,
908 "Vendor request %s completed.\n", type);
909 bsg_job->reply->result = (DID_OK << 16);
910 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
911 bsg_job->reply_payload.sg_cnt, rsp_data,
915 bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
916 sizeof(response) + sizeof(uint8_t);
917 fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) +
918 sizeof(struct fc_bsg_reply);
919 memcpy(fw_sts_ptr, response, sizeof(response));
920 fw_sts_ptr += sizeof(response);
921 *fw_sts_ptr = command_sent;
924 dma_free_coherent(&ha->pdev->dev, rsp_data_len,
925 rsp_data, rsp_data_dma);
927 dma_free_coherent(&ha->pdev->dev, req_data_len,
928 req_data, req_data_dma);
930 dma_unmap_sg(&ha->pdev->dev,
931 bsg_job->reply_payload.sg_list,
932 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
934 dma_unmap_sg(&ha->pdev->dev,
935 bsg_job->request_payload.sg_list,
936 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
938 bsg_job->job_done(bsg_job);
943 qla84xx_reset(struct fc_bsg_job *bsg_job)
945 struct Scsi_Host *host = bsg_job->shost;
946 scsi_qla_host_t *vha = shost_priv(host);
947 struct qla_hw_data *ha = vha->hw;
951 if (!IS_QLA84XX(ha)) {
952 ql_dbg(ql_dbg_user, vha, 0x702f, "Not 84xx, exiting.\n");
956 flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
958 rval = qla84xx_reset_chip(vha, flag == A84_ISSUE_RESET_DIAG_FW);
961 ql_log(ql_log_warn, vha, 0x7030,
962 "Vendor request 84xx reset failed.\n");
963 rval = (DID_ERROR << 16);
966 ql_dbg(ql_dbg_user, vha, 0x7031,
967 "Vendor request 84xx reset completed.\n");
968 bsg_job->reply->result = DID_OK;
969 bsg_job->job_done(bsg_job);
976 qla84xx_updatefw(struct fc_bsg_job *bsg_job)
978 struct Scsi_Host *host = bsg_job->shost;
979 scsi_qla_host_t *vha = shost_priv(host);
980 struct qla_hw_data *ha = vha->hw;
981 struct verify_chip_entry_84xx *mn = NULL;
982 dma_addr_t mn_dma, fw_dma;
991 if (!IS_QLA84XX(ha)) {
992 ql_dbg(ql_dbg_user, vha, 0x7032,
993 "Not 84xx, exiting.\n");
997 sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
998 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1000 ql_log(ql_log_warn, vha, 0x7033,
1001 "dma_map_sg returned %d for request.\n", sg_cnt);
1005 if (sg_cnt != bsg_job->request_payload.sg_cnt) {
1006 ql_log(ql_log_warn, vha, 0x7034,
1007 "DMA mapping resulted in different sg counts, "
1008 "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
1009 bsg_job->request_payload.sg_cnt, sg_cnt);
1014 data_len = bsg_job->request_payload.payload_len;
1015 fw_buf = dma_alloc_coherent(&ha->pdev->dev, data_len,
1016 &fw_dma, GFP_KERNEL);
1018 ql_log(ql_log_warn, vha, 0x7035,
1019 "DMA alloc failed for fw_buf.\n");
1024 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1025 bsg_job->request_payload.sg_cnt, fw_buf, data_len);
1027 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
1029 ql_log(ql_log_warn, vha, 0x7036,
1030 "DMA alloc failed for fw buffer.\n");
1032 goto done_free_fw_buf;
1035 flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1036 fw_ver = le32_to_cpu(*((uint32_t *)((uint32_t *)fw_buf + 2)));
1038 memset(mn, 0, sizeof(struct access_chip_84xx));
1039 mn->entry_type = VERIFY_CHIP_IOCB_TYPE;
1040 mn->entry_count = 1;
1042 options = VCO_FORCE_UPDATE | VCO_END_OF_DATA;
1043 if (flag == A84_ISSUE_UPDATE_DIAGFW_CMD)
1044 options |= VCO_DIAG_FW;
1046 mn->options = cpu_to_le16(options);
1047 mn->fw_ver = cpu_to_le32(fw_ver);
1048 mn->fw_size = cpu_to_le32(data_len);
1049 mn->fw_seq_size = cpu_to_le32(data_len);
1050 mn->dseg_address[0] = cpu_to_le32(LSD(fw_dma));
1051 mn->dseg_address[1] = cpu_to_le32(MSD(fw_dma));
1052 mn->dseg_length = cpu_to_le32(data_len);
1053 mn->data_seg_cnt = cpu_to_le16(1);
1055 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
1058 ql_log(ql_log_warn, vha, 0x7037,
1059 "Vendor request 84xx updatefw failed.\n");
1061 rval = (DID_ERROR << 16);
1063 ql_dbg(ql_dbg_user, vha, 0x7038,
1064 "Vendor request 84xx updatefw completed.\n");
1066 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1067 bsg_job->reply->result = DID_OK;
1070 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
1073 dma_free_coherent(&ha->pdev->dev, data_len, fw_buf, fw_dma);
1076 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1077 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1080 bsg_job->job_done(bsg_job);
1085 qla84xx_mgmt_cmd(struct fc_bsg_job *bsg_job)
1087 struct Scsi_Host *host = bsg_job->shost;
1088 scsi_qla_host_t *vha = shost_priv(host);
1089 struct qla_hw_data *ha = vha->hw;
1090 struct access_chip_84xx *mn = NULL;
1091 dma_addr_t mn_dma, mgmt_dma;
1092 void *mgmt_b = NULL;
1094 struct qla_bsg_a84_mgmt *ql84_mgmt;
1096 uint32_t data_len = 0;
1097 uint32_t dma_direction = DMA_NONE;
1099 if (!IS_QLA84XX(ha)) {
1100 ql_log(ql_log_warn, vha, 0x703a,
1101 "Not 84xx, exiting.\n");
1105 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
1107 ql_log(ql_log_warn, vha, 0x703c,
1108 "DMA alloc failed for fw buffer.\n");
1112 memset(mn, 0, sizeof(struct access_chip_84xx));
1113 mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
1114 mn->entry_count = 1;
1115 ql84_mgmt = (void *)bsg_job->request + sizeof(struct fc_bsg_request);
1116 switch (ql84_mgmt->mgmt.cmd) {
1117 case QLA84_MGMT_READ_MEM:
1118 case QLA84_MGMT_GET_INFO:
1119 sg_cnt = dma_map_sg(&ha->pdev->dev,
1120 bsg_job->reply_payload.sg_list,
1121 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1123 ql_log(ql_log_warn, vha, 0x703d,
1124 "dma_map_sg returned %d for reply.\n", sg_cnt);
1129 dma_direction = DMA_FROM_DEVICE;
1131 if (sg_cnt != bsg_job->reply_payload.sg_cnt) {
1132 ql_log(ql_log_warn, vha, 0x703e,
1133 "DMA mapping resulted in different sg counts, "
1134 "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
1135 bsg_job->reply_payload.sg_cnt, sg_cnt);
1140 data_len = bsg_job->reply_payload.payload_len;
1142 mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
1143 &mgmt_dma, GFP_KERNEL);
1145 ql_log(ql_log_warn, vha, 0x703f,
1146 "DMA alloc failed for mgmt_b.\n");
1151 if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) {
1152 mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
1155 ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
1157 } else if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO) {
1158 mn->options = cpu_to_le16(ACO_REQUEST_INFO);
1160 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.info.type);
1164 ql84_mgmt->mgmt.mgmtp.u.info.context);
1168 case QLA84_MGMT_WRITE_MEM:
1169 sg_cnt = dma_map_sg(&ha->pdev->dev,
1170 bsg_job->request_payload.sg_list,
1171 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1174 ql_log(ql_log_warn, vha, 0x7040,
1175 "dma_map_sg returned %d.\n", sg_cnt);
1180 dma_direction = DMA_TO_DEVICE;
1182 if (sg_cnt != bsg_job->request_payload.sg_cnt) {
1183 ql_log(ql_log_warn, vha, 0x7041,
1184 "DMA mapping resulted in different sg counts, "
1185 "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
1186 bsg_job->request_payload.sg_cnt, sg_cnt);
1191 data_len = bsg_job->request_payload.payload_len;
1192 mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
1193 &mgmt_dma, GFP_KERNEL);
1195 ql_log(ql_log_warn, vha, 0x7042,
1196 "DMA alloc failed for mgmt_b.\n");
1201 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1202 bsg_job->request_payload.sg_cnt, mgmt_b, data_len);
1204 mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
1206 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
1209 case QLA84_MGMT_CHNG_CONFIG:
1210 mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
1212 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.id);
1215 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param0);
1218 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param1);
1226 if (ql84_mgmt->mgmt.cmd != QLA84_MGMT_CHNG_CONFIG) {
1227 mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->mgmt.len);
1228 mn->dseg_count = cpu_to_le16(1);
1229 mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma));
1230 mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma));
1231 mn->dseg_length = cpu_to_le32(ql84_mgmt->mgmt.len);
1234 rval = qla2x00_issue_iocb(vha, mn, mn_dma, 0);
1237 ql_log(ql_log_warn, vha, 0x7043,
1238 "Vendor request 84xx mgmt failed.\n");
1240 rval = (DID_ERROR << 16);
1243 ql_dbg(ql_dbg_user, vha, 0x7044,
1244 "Vendor request 84xx mgmt completed.\n");
1246 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1247 bsg_job->reply->result = DID_OK;
1249 if ((ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) ||
1250 (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO)) {
1251 bsg_job->reply->reply_payload_rcv_len =
1252 bsg_job->reply_payload.payload_len;
1254 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1255 bsg_job->reply_payload.sg_cnt, mgmt_b,
1262 dma_free_coherent(&ha->pdev->dev, data_len, mgmt_b, mgmt_dma);
1264 if (dma_direction == DMA_TO_DEVICE)
1265 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1266 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1267 else if (dma_direction == DMA_FROM_DEVICE)
1268 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
1269 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1272 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
1275 bsg_job->job_done(bsg_job);
1280 qla24xx_iidma(struct fc_bsg_job *bsg_job)
1282 struct Scsi_Host *host = bsg_job->shost;
1283 scsi_qla_host_t *vha = shost_priv(host);
1285 struct qla_port_param *port_param = NULL;
1286 fc_port_t *fcport = NULL;
1288 uint16_t mb[MAILBOX_REGISTER_COUNT];
1289 uint8_t *rsp_ptr = NULL;
1291 if (!IS_IIDMA_CAPABLE(vha->hw)) {
1292 ql_log(ql_log_info, vha, 0x7046, "iiDMA not supported.\n");
1296 port_param = (void *)bsg_job->request + sizeof(struct fc_bsg_request);
1297 if (port_param->fc_scsi_addr.dest_type != EXT_DEF_TYPE_WWPN) {
1298 ql_log(ql_log_warn, vha, 0x7048,
1299 "Invalid destination type.\n");
1303 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1304 if (fcport->port_type != FCT_TARGET)
1307 if (memcmp(port_param->fc_scsi_addr.dest_addr.wwpn,
1308 fcport->port_name, sizeof(fcport->port_name)))
1316 ql_log(ql_log_warn, vha, 0x7049,
1317 "Failed to find port.\n");
1321 if (atomic_read(&fcport->state) != FCS_ONLINE) {
1322 ql_log(ql_log_warn, vha, 0x704a,
1323 "Port is not online.\n");
1327 if (fcport->flags & FCF_LOGIN_NEEDED) {
1328 ql_log(ql_log_warn, vha, 0x704b,
1329 "Remote port not logged in flags = 0x%x.\n", fcport->flags);
1333 if (port_param->mode)
1334 rval = qla2x00_set_idma_speed(vha, fcport->loop_id,
1335 port_param->speed, mb);
1337 rval = qla2x00_get_idma_speed(vha, fcport->loop_id,
1338 &port_param->speed, mb);
1341 ql_log(ql_log_warn, vha, 0x704c,
1342 "iIDMA cmd failed for %8phN -- "
1343 "%04x %x %04x %04x.\n", fcport->port_name,
1344 rval, fcport->fp_speed, mb[0], mb[1]);
1345 rval = (DID_ERROR << 16);
1347 if (!port_param->mode) {
1348 bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
1349 sizeof(struct qla_port_param);
1351 rsp_ptr = ((uint8_t *)bsg_job->reply) +
1352 sizeof(struct fc_bsg_reply);
1354 memcpy(rsp_ptr, port_param,
1355 sizeof(struct qla_port_param));
1358 bsg_job->reply->result = DID_OK;
1359 bsg_job->job_done(bsg_job);
1366 qla2x00_optrom_setup(struct fc_bsg_job *bsg_job, scsi_qla_host_t *vha,
1371 struct qla_hw_data *ha = vha->hw;
1373 if (unlikely(pci_channel_offline(ha->pdev)))
1376 start = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1377 if (start > ha->optrom_size) {
1378 ql_log(ql_log_warn, vha, 0x7055,
1379 "start %d > optrom_size %d.\n", start, ha->optrom_size);
1383 if (ha->optrom_state != QLA_SWAITING) {
1384 ql_log(ql_log_info, vha, 0x7056,
1385 "optrom_state %d.\n", ha->optrom_state);
1389 ha->optrom_region_start = start;
1390 ql_dbg(ql_dbg_user, vha, 0x7057, "is_update=%d.\n", is_update);
1392 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
1394 else if (start == (ha->flt_region_boot * 4) ||
1395 start == (ha->flt_region_fw * 4))
1397 else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
1398 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha))
1401 ql_log(ql_log_warn, vha, 0x7058,
1402 "Invalid start region 0x%x/0x%x.\n", start,
1403 bsg_job->request_payload.payload_len);
1407 ha->optrom_region_size = start +
1408 bsg_job->request_payload.payload_len > ha->optrom_size ?
1409 ha->optrom_size - start :
1410 bsg_job->request_payload.payload_len;
1411 ha->optrom_state = QLA_SWRITING;
1413 ha->optrom_region_size = start +
1414 bsg_job->reply_payload.payload_len > ha->optrom_size ?
1415 ha->optrom_size - start :
1416 bsg_job->reply_payload.payload_len;
1417 ha->optrom_state = QLA_SREADING;
1420 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
1421 if (!ha->optrom_buffer) {
1422 ql_log(ql_log_warn, vha, 0x7059,
1423 "Read: Unable to allocate memory for optrom retrieval "
1424 "(%x)\n", ha->optrom_region_size);
1426 ha->optrom_state = QLA_SWAITING;
1430 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
1435 qla2x00_read_optrom(struct fc_bsg_job *bsg_job)
1437 struct Scsi_Host *host = bsg_job->shost;
1438 scsi_qla_host_t *vha = shost_priv(host);
1439 struct qla_hw_data *ha = vha->hw;
1442 if (ha->flags.nic_core_reset_hdlr_active)
1445 mutex_lock(&ha->optrom_mutex);
1446 rval = qla2x00_optrom_setup(bsg_job, vha, 0);
1448 mutex_unlock(&ha->optrom_mutex);
1452 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
1453 ha->optrom_region_start, ha->optrom_region_size);
1455 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1456 bsg_job->reply_payload.sg_cnt, ha->optrom_buffer,
1457 ha->optrom_region_size);
1459 bsg_job->reply->reply_payload_rcv_len = ha->optrom_region_size;
1460 bsg_job->reply->result = DID_OK;
1461 vfree(ha->optrom_buffer);
1462 ha->optrom_buffer = NULL;
1463 ha->optrom_state = QLA_SWAITING;
1464 mutex_unlock(&ha->optrom_mutex);
1465 bsg_job->job_done(bsg_job);
1470 qla2x00_update_optrom(struct fc_bsg_job *bsg_job)
1472 struct Scsi_Host *host = bsg_job->shost;
1473 scsi_qla_host_t *vha = shost_priv(host);
1474 struct qla_hw_data *ha = vha->hw;
1477 mutex_lock(&ha->optrom_mutex);
1478 rval = qla2x00_optrom_setup(bsg_job, vha, 1);
1480 mutex_unlock(&ha->optrom_mutex);
1484 /* Set the isp82xx_no_md_cap not to capture minidump */
1485 ha->flags.isp82xx_no_md_cap = 1;
1487 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1488 bsg_job->request_payload.sg_cnt, ha->optrom_buffer,
1489 ha->optrom_region_size);
1491 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
1492 ha->optrom_region_start, ha->optrom_region_size);
1494 bsg_job->reply->result = DID_OK;
1495 vfree(ha->optrom_buffer);
1496 ha->optrom_buffer = NULL;
1497 ha->optrom_state = QLA_SWAITING;
1498 mutex_unlock(&ha->optrom_mutex);
1499 bsg_job->job_done(bsg_job);
1504 qla2x00_update_fru_versions(struct fc_bsg_job *bsg_job)
1506 struct Scsi_Host *host = bsg_job->shost;
1507 scsi_qla_host_t *vha = shost_priv(host);
1508 struct qla_hw_data *ha = vha->hw;
1510 uint8_t bsg[DMA_POOL_SIZE];
1511 struct qla_image_version_list *list = (void *)bsg;
1512 struct qla_image_version *image;
1515 void *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1517 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1518 EXT_STATUS_NO_MEMORY;
1522 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1523 bsg_job->request_payload.sg_cnt, list, sizeof(bsg));
1525 image = list->version;
1526 count = list->count;
1528 memcpy(sfp, &image->field_info, sizeof(image->field_info));
1529 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1530 image->field_address.device, image->field_address.offset,
1531 sizeof(image->field_info), image->field_address.option);
1533 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1540 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1543 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1546 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1547 bsg_job->reply->result = DID_OK << 16;
1548 bsg_job->job_done(bsg_job);
1554 qla2x00_read_fru_status(struct fc_bsg_job *bsg_job)
1556 struct Scsi_Host *host = bsg_job->shost;
1557 scsi_qla_host_t *vha = shost_priv(host);
1558 struct qla_hw_data *ha = vha->hw;
1560 uint8_t bsg[DMA_POOL_SIZE];
1561 struct qla_status_reg *sr = (void *)bsg;
1563 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1565 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1566 EXT_STATUS_NO_MEMORY;
1570 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1571 bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
1573 rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
1574 sr->field_address.device, sr->field_address.offset,
1575 sizeof(sr->status_reg), sr->field_address.option);
1576 sr->status_reg = *sfp;
1579 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1584 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1585 bsg_job->reply_payload.sg_cnt, sr, sizeof(*sr));
1587 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1590 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1593 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1594 bsg_job->reply->reply_payload_rcv_len = sizeof(*sr);
1595 bsg_job->reply->result = DID_OK << 16;
1596 bsg_job->job_done(bsg_job);
1602 qla2x00_write_fru_status(struct fc_bsg_job *bsg_job)
1604 struct Scsi_Host *host = bsg_job->shost;
1605 scsi_qla_host_t *vha = shost_priv(host);
1606 struct qla_hw_data *ha = vha->hw;
1608 uint8_t bsg[DMA_POOL_SIZE];
1609 struct qla_status_reg *sr = (void *)bsg;
1611 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1613 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1614 EXT_STATUS_NO_MEMORY;
1618 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1619 bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
1621 *sfp = sr->status_reg;
1622 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1623 sr->field_address.device, sr->field_address.offset,
1624 sizeof(sr->status_reg), sr->field_address.option);
1627 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1632 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1635 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1638 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1639 bsg_job->reply->result = DID_OK << 16;
1640 bsg_job->job_done(bsg_job);
1646 qla2x00_write_i2c(struct fc_bsg_job *bsg_job)
1648 struct Scsi_Host *host = bsg_job->shost;
1649 scsi_qla_host_t *vha = shost_priv(host);
1650 struct qla_hw_data *ha = vha->hw;
1652 uint8_t bsg[DMA_POOL_SIZE];
1653 struct qla_i2c_access *i2c = (void *)bsg;
1655 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1657 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1658 EXT_STATUS_NO_MEMORY;
1662 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1663 bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
1665 memcpy(sfp, i2c->buffer, i2c->length);
1666 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1667 i2c->device, i2c->offset, i2c->length, i2c->option);
1670 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1675 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1678 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1681 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1682 bsg_job->reply->result = DID_OK << 16;
1683 bsg_job->job_done(bsg_job);
1689 qla2x00_read_i2c(struct fc_bsg_job *bsg_job)
1691 struct Scsi_Host *host = bsg_job->shost;
1692 scsi_qla_host_t *vha = shost_priv(host);
1693 struct qla_hw_data *ha = vha->hw;
1695 uint8_t bsg[DMA_POOL_SIZE];
1696 struct qla_i2c_access *i2c = (void *)bsg;
1698 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1700 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1701 EXT_STATUS_NO_MEMORY;
1705 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1706 bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
1708 rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
1709 i2c->device, i2c->offset, i2c->length, i2c->option);
1712 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1717 memcpy(i2c->buffer, sfp, i2c->length);
1718 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1719 bsg_job->reply_payload.sg_cnt, i2c, sizeof(*i2c));
1721 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1724 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1727 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1728 bsg_job->reply->reply_payload_rcv_len = sizeof(*i2c);
1729 bsg_job->reply->result = DID_OK << 16;
1730 bsg_job->job_done(bsg_job);
1736 qla24xx_process_bidir_cmd(struct fc_bsg_job *bsg_job)
1738 struct Scsi_Host *host = bsg_job->shost;
1739 scsi_qla_host_t *vha = shost_priv(host);
1740 struct qla_hw_data *ha = vha->hw;
1741 uint32_t rval = EXT_STATUS_OK;
1742 uint16_t req_sg_cnt = 0;
1743 uint16_t rsp_sg_cnt = 0;
1744 uint16_t nextlid = 0;
1747 uint32_t req_data_len;
1748 uint32_t rsp_data_len;
1750 /* Check the type of the adapter */
1751 if (!IS_BIDI_CAPABLE(ha)) {
1752 ql_log(ql_log_warn, vha, 0x70a0,
1753 "This adapter is not supported\n");
1754 rval = EXT_STATUS_NOT_SUPPORTED;
1758 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
1759 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1760 test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
1761 rval = EXT_STATUS_BUSY;
1765 /* Check if host is online */
1766 if (!vha->flags.online) {
1767 ql_log(ql_log_warn, vha, 0x70a1,
1768 "Host is not online\n");
1769 rval = EXT_STATUS_DEVICE_OFFLINE;
1773 /* Check if cable is plugged in or not */
1774 if (vha->device_flags & DFLG_NO_CABLE) {
1775 ql_log(ql_log_warn, vha, 0x70a2,
1776 "Cable is unplugged...\n");
1777 rval = EXT_STATUS_INVALID_CFG;
1781 /* Check if the switch is connected or not */
1782 if (ha->current_topology != ISP_CFG_F) {
1783 ql_log(ql_log_warn, vha, 0x70a3,
1784 "Host is not connected to the switch\n");
1785 rval = EXT_STATUS_INVALID_CFG;
1789 /* Check if operating mode is P2P */
1790 if (ha->operating_mode != P2P) {
1791 ql_log(ql_log_warn, vha, 0x70a4,
1792 "Host is operating mode is not P2p\n");
1793 rval = EXT_STATUS_INVALID_CFG;
1797 mutex_lock(&ha->selflogin_lock);
1798 if (vha->self_login_loop_id == 0) {
1799 /* Initialize all required fields of fcport */
1800 vha->bidir_fcport.vha = vha;
1801 vha->bidir_fcport.d_id.b.al_pa = vha->d_id.b.al_pa;
1802 vha->bidir_fcport.d_id.b.area = vha->d_id.b.area;
1803 vha->bidir_fcport.d_id.b.domain = vha->d_id.b.domain;
1804 vha->bidir_fcport.loop_id = vha->loop_id;
1806 if (qla2x00_fabric_login(vha, &(vha->bidir_fcport), &nextlid)) {
1807 ql_log(ql_log_warn, vha, 0x70a7,
1808 "Failed to login port %06X for bidirectional IOCB\n",
1809 vha->bidir_fcport.d_id.b24);
1810 mutex_unlock(&ha->selflogin_lock);
1811 rval = EXT_STATUS_MAILBOX;
1814 vha->self_login_loop_id = nextlid - 1;
1817 /* Assign the self login loop id to fcport */
1818 mutex_unlock(&ha->selflogin_lock);
1820 vha->bidir_fcport.loop_id = vha->self_login_loop_id;
1822 req_sg_cnt = dma_map_sg(&ha->pdev->dev,
1823 bsg_job->request_payload.sg_list,
1824 bsg_job->request_payload.sg_cnt,
1828 rval = EXT_STATUS_NO_MEMORY;
1832 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
1833 bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
1837 rval = EXT_STATUS_NO_MEMORY;
1838 goto done_unmap_req_sg;
1841 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
1842 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
1843 ql_dbg(ql_dbg_user, vha, 0x70a9,
1844 "Dma mapping resulted in different sg counts "
1845 "[request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt: "
1846 "%x dma_reply_sg_cnt: %x]\n",
1847 bsg_job->request_payload.sg_cnt, req_sg_cnt,
1848 bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
1849 rval = EXT_STATUS_NO_MEMORY;
1853 req_data_len = bsg_job->request_payload.payload_len;
1854 rsp_data_len = bsg_job->reply_payload.payload_len;
1856 if (req_data_len != rsp_data_len) {
1857 rval = EXT_STATUS_BUSY;
1858 ql_log(ql_log_warn, vha, 0x70aa,
1859 "req_data_len != rsp_data_len\n");
1863 /* Alloc SRB structure */
1864 sp = qla2x00_get_sp(vha, &(vha->bidir_fcport), GFP_KERNEL);
1866 ql_dbg(ql_dbg_user, vha, 0x70ac,
1867 "Alloc SRB structure failed\n");
1868 rval = EXT_STATUS_NO_MEMORY;
1872 /*Populate srb->ctx with bidir ctx*/
1873 sp->u.bsg_job = bsg_job;
1874 sp->free = qla2x00_bsg_sp_free;
1875 sp->type = SRB_BIDI_CMD;
1876 sp->done = qla2x00_bsg_job_done;
1878 /* Add the read and write sg count */
1879 tot_dsds = rsp_sg_cnt + req_sg_cnt;
1881 rval = qla2x00_start_bidir(sp, vha, tot_dsds);
1882 if (rval != EXT_STATUS_OK)
1884 /* the bsg request will be completed in the interrupt handler */
1888 mempool_free(sp, ha->srb_mempool);
1890 dma_unmap_sg(&ha->pdev->dev,
1891 bsg_job->reply_payload.sg_list,
1892 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1894 dma_unmap_sg(&ha->pdev->dev,
1895 bsg_job->request_payload.sg_list,
1896 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1899 /* Return an error vendor specific response
1900 * and complete the bsg request
1902 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
1903 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1904 bsg_job->reply->reply_payload_rcv_len = 0;
1905 bsg_job->reply->result = (DID_OK) << 16;
1906 bsg_job->job_done(bsg_job);
1907 /* Always return success, vendor rsp carries correct status */
1912 qlafx00_mgmt_cmd(struct fc_bsg_job *bsg_job)
1914 struct Scsi_Host *host = bsg_job->shost;
1915 scsi_qla_host_t *vha = shost_priv(host);
1916 struct qla_hw_data *ha = vha->hw;
1917 int rval = (DID_ERROR << 16);
1918 struct qla_mt_iocb_rqst_fx00 *piocb_rqst;
1920 int req_sg_cnt = 0, rsp_sg_cnt = 0;
1921 struct fc_port *fcport;
1922 char *type = "FC_BSG_HST_FX_MGMT";
1924 /* Copy the IOCB specific information */
1925 piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *)
1926 &bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1928 /* Dump the vendor information */
1929 ql_dump_buffer(ql_dbg_user + ql_dbg_verbose , vha, 0x70cf,
1930 (uint8_t *)piocb_rqst, sizeof(struct qla_mt_iocb_rqst_fx00));
1932 if (!vha->flags.online) {
1933 ql_log(ql_log_warn, vha, 0x70d0,
1934 "Host is not online.\n");
1939 if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID) {
1940 req_sg_cnt = dma_map_sg(&ha->pdev->dev,
1941 bsg_job->request_payload.sg_list,
1942 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1944 ql_log(ql_log_warn, vha, 0x70c7,
1945 "dma_map_sg return %d for request\n", req_sg_cnt);
1951 if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID) {
1952 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
1953 bsg_job->reply_payload.sg_list,
1954 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1956 ql_log(ql_log_warn, vha, 0x70c8,
1957 "dma_map_sg return %d for reply\n", rsp_sg_cnt);
1959 goto done_unmap_req_sg;
1963 ql_dbg(ql_dbg_user, vha, 0x70c9,
1964 "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
1965 "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
1966 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
1968 /* Allocate a dummy fcport structure, since functions preparing the
1969 * IOCB and mailbox command retrieves port specific information
1970 * from fcport structure. For Host based ELS commands there will be
1971 * no fcport structure allocated
1973 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
1975 ql_log(ql_log_warn, vha, 0x70ca,
1976 "Failed to allocate fcport.\n");
1978 goto done_unmap_rsp_sg;
1981 /* Alloc SRB structure */
1982 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1984 ql_log(ql_log_warn, vha, 0x70cb,
1985 "qla2x00_get_sp failed.\n");
1987 goto done_free_fcport;
1990 /* Initialize all required fields of fcport */
1992 fcport->loop_id = piocb_rqst->dataword;
1994 sp->type = SRB_FXIOCB_BCMD;
1995 sp->name = "bsg_fx_mgmt";
1996 sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
1997 sp->u.bsg_job = bsg_job;
1998 sp->free = qla2x00_bsg_sp_free;
1999 sp->done = qla2x00_bsg_job_done;
2001 ql_dbg(ql_dbg_user, vha, 0x70cc,
2002 "bsg rqst type: %s fx_mgmt_type: %x id=%x\n",
2003 type, piocb_rqst->func_type, fcport->loop_id);
2005 rval = qla2x00_start_sp(sp);
2006 if (rval != QLA_SUCCESS) {
2007 ql_log(ql_log_warn, vha, 0x70cd,
2008 "qla2x00_start_sp failed=%d.\n", rval);
2009 mempool_free(sp, ha->srb_mempool);
2011 goto done_free_fcport;
2019 if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID)
2020 dma_unmap_sg(&ha->pdev->dev,
2021 bsg_job->reply_payload.sg_list,
2022 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
2024 if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID)
2025 dma_unmap_sg(&ha->pdev->dev,
2026 bsg_job->request_payload.sg_list,
2027 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
2034 qla26xx_serdes_op(struct fc_bsg_job *bsg_job)
2036 struct Scsi_Host *host = bsg_job->shost;
2037 scsi_qla_host_t *vha = shost_priv(host);
2039 struct qla_serdes_reg sr;
2041 memset(&sr, 0, sizeof(sr));
2043 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2044 bsg_job->request_payload.sg_cnt, &sr, sizeof(sr));
2047 case INT_SC_SERDES_WRITE_REG:
2048 rval = qla2x00_write_serdes_word(vha, sr.addr, sr.val);
2049 bsg_job->reply->reply_payload_rcv_len = 0;
2051 case INT_SC_SERDES_READ_REG:
2052 rval = qla2x00_read_serdes_word(vha, sr.addr, &sr.val);
2053 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2054 bsg_job->reply_payload.sg_cnt, &sr, sizeof(sr));
2055 bsg_job->reply->reply_payload_rcv_len = sizeof(sr);
2058 ql_dbg(ql_dbg_user, vha, 0x708c,
2059 "Unknown serdes cmd %x.\n", sr.cmd);
2064 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
2065 rval ? EXT_STATUS_MAILBOX : 0;
2067 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2068 bsg_job->reply->result = DID_OK << 16;
2069 bsg_job->job_done(bsg_job);
2074 qla8044_serdes_op(struct fc_bsg_job *bsg_job)
2076 struct Scsi_Host *host = bsg_job->shost;
2077 scsi_qla_host_t *vha = shost_priv(host);
2079 struct qla_serdes_reg_ex sr;
2081 memset(&sr, 0, sizeof(sr));
2083 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2084 bsg_job->request_payload.sg_cnt, &sr, sizeof(sr));
2087 case INT_SC_SERDES_WRITE_REG:
2088 rval = qla8044_write_serdes_word(vha, sr.addr, sr.val);
2089 bsg_job->reply->reply_payload_rcv_len = 0;
2091 case INT_SC_SERDES_READ_REG:
2092 rval = qla8044_read_serdes_word(vha, sr.addr, &sr.val);
2093 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2094 bsg_job->reply_payload.sg_cnt, &sr, sizeof(sr));
2095 bsg_job->reply->reply_payload_rcv_len = sizeof(sr);
2098 ql_dbg(ql_dbg_user, vha, 0x70cf,
2099 "Unknown serdes cmd %x.\n", sr.cmd);
2104 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
2105 rval ? EXT_STATUS_MAILBOX : 0;
2107 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2108 bsg_job->reply->result = DID_OK << 16;
2109 bsg_job->job_done(bsg_job);
2114 qla27xx_get_flash_upd_cap(struct fc_bsg_job *bsg_job)
2116 struct Scsi_Host *host = bsg_job->shost;
2117 scsi_qla_host_t *vha = shost_priv(host);
2118 struct qla_hw_data *ha = vha->hw;
2119 struct qla_flash_update_caps cap;
2121 if (!(IS_QLA27XX(ha)))
2124 memset(&cap, 0, sizeof(cap));
2125 cap.capabilities = (uint64_t)ha->fw_attributes_ext[1] << 48 |
2126 (uint64_t)ha->fw_attributes_ext[0] << 32 |
2127 (uint64_t)ha->fw_attributes_h << 16 |
2128 (uint64_t)ha->fw_attributes;
2130 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2131 bsg_job->reply_payload.sg_cnt, &cap, sizeof(cap));
2132 bsg_job->reply->reply_payload_rcv_len = sizeof(cap);
2134 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
2137 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2138 bsg_job->reply->result = DID_OK << 16;
2139 bsg_job->job_done(bsg_job);
2144 qla27xx_set_flash_upd_cap(struct fc_bsg_job *bsg_job)
2146 struct Scsi_Host *host = bsg_job->shost;
2147 scsi_qla_host_t *vha = shost_priv(host);
2148 struct qla_hw_data *ha = vha->hw;
2149 uint64_t online_fw_attr = 0;
2150 struct qla_flash_update_caps cap;
2152 if (!(IS_QLA27XX(ha)))
2155 memset(&cap, 0, sizeof(cap));
2156 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2157 bsg_job->request_payload.sg_cnt, &cap, sizeof(cap));
2159 online_fw_attr = (uint64_t)ha->fw_attributes_ext[1] << 48 |
2160 (uint64_t)ha->fw_attributes_ext[0] << 32 |
2161 (uint64_t)ha->fw_attributes_h << 16 |
2162 (uint64_t)ha->fw_attributes;
2164 if (online_fw_attr != cap.capabilities) {
2165 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
2166 EXT_STATUS_INVALID_PARAM;
2170 if (cap.outage_duration < MAX_LOOP_TIMEOUT) {
2171 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
2172 EXT_STATUS_INVALID_PARAM;
2176 bsg_job->reply->reply_payload_rcv_len = 0;
2178 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
2181 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2182 bsg_job->reply->result = DID_OK << 16;
2183 bsg_job->job_done(bsg_job);
2188 qla27xx_get_bbcr_data(struct fc_bsg_job *bsg_job)
2190 struct Scsi_Host *host = bsg_job->shost;
2191 scsi_qla_host_t *vha = shost_priv(host);
2192 struct qla_hw_data *ha = vha->hw;
2193 struct qla_bbcr_data bbcr;
2194 uint16_t loop_id, topo, sw_cap;
2195 uint8_t domain, area, al_pa, state;
2198 if (!(IS_QLA27XX(ha)))
2201 memset(&bbcr, 0, sizeof(bbcr));
2203 if (vha->flags.bbcr_enable)
2204 bbcr.status = QLA_BBCR_STATUS_ENABLED;
2206 bbcr.status = QLA_BBCR_STATUS_DISABLED;
2208 if (bbcr.status == QLA_BBCR_STATUS_ENABLED) {
2209 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2210 &area, &domain, &topo, &sw_cap);
2211 if (rval != QLA_SUCCESS) {
2212 bbcr.status = QLA_BBCR_STATUS_UNKNOWN;
2213 bbcr.state = QLA_BBCR_STATE_OFFLINE;
2214 bbcr.mbx1 = loop_id;
2218 state = (vha->bbcr >> 12) & 0x1;
2221 bbcr.state = QLA_BBCR_STATE_OFFLINE;
2222 bbcr.offline_reason_code = QLA_BBCR_REASON_LOGIN_REJECT;
2224 bbcr.state = QLA_BBCR_STATE_ONLINE;
2225 bbcr.negotiated_bbscn = (vha->bbcr >> 8) & 0xf;
2228 bbcr.configured_bbscn = vha->bbcr & 0xf;
2232 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2233 bsg_job->reply_payload.sg_cnt, &bbcr, sizeof(bbcr));
2234 bsg_job->reply->reply_payload_rcv_len = sizeof(bbcr);
2236 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = EXT_STATUS_OK;
2238 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2239 bsg_job->reply->result = DID_OK << 16;
2240 bsg_job->job_done(bsg_job);
2245 qla2x00_get_priv_stats(struct fc_bsg_job *bsg_job)
2247 struct Scsi_Host *host = bsg_job->shost;
2248 scsi_qla_host_t *vha = shost_priv(host);
2249 struct qla_hw_data *ha = vha->hw;
2250 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2251 struct link_statistics *stats = NULL;
2252 dma_addr_t stats_dma;
2254 uint32_t *cmd = bsg_job->request->rqst_data.h_vendor.vendor_cmd;
2255 uint options = cmd[0] == QL_VND_GET_PRIV_STATS_EX ? cmd[1] : 0;
2257 if (test_bit(UNLOADING, &vha->dpc_flags))
2260 if (unlikely(pci_channel_offline(ha->pdev)))
2263 if (qla2x00_reset_active(vha))
2266 if (!IS_FWI2_CAPABLE(ha))
2269 stats = dma_alloc_coherent(&ha->pdev->dev,
2270 sizeof(*stats), &stats_dma, GFP_KERNEL);
2272 ql_log(ql_log_warn, vha, 0x70e2,
2273 "Failed to allocate memory for stats.\n");
2277 memset(stats, 0, sizeof(*stats));
2279 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma, options);
2281 if (rval == QLA_SUCCESS) {
2282 ql_dump_buffer(ql_dbg_user + ql_dbg_verbose, vha, 0x70e3,
2283 (uint8_t *)stats, sizeof(*stats));
2284 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2285 bsg_job->reply_payload.sg_cnt, stats, sizeof(*stats));
2288 bsg_job->reply->reply_payload_rcv_len = sizeof(*stats);
2289 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
2290 rval ? EXT_STATUS_MAILBOX : EXT_STATUS_OK;
2292 bsg_job->reply_len = sizeof(*bsg_job->reply);
2293 bsg_job->reply->result = DID_OK << 16;
2294 bsg_job->job_done(bsg_job);
2296 dma_free_coherent(&ha->pdev->dev, sizeof(*stats),
2303 qla2x00_do_dport_diagnostics(struct fc_bsg_job *bsg_job)
2305 struct Scsi_Host *host = bsg_job->shost;
2306 scsi_qla_host_t *vha = shost_priv(host);
2308 struct qla_dport_diag *dd;
2310 if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw))
2313 dd = kmalloc(sizeof(*dd), GFP_KERNEL);
2315 ql_log(ql_log_warn, vha, 0x70db,
2316 "Failed to allocate memory for dport.\n");
2320 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2321 bsg_job->request_payload.sg_cnt, dd, sizeof(*dd));
2323 rval = qla26xx_dport_diagnostics(
2324 vha, dd->buf, sizeof(dd->buf), dd->options);
2325 if (rval == QLA_SUCCESS) {
2326 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2327 bsg_job->reply_payload.sg_cnt, dd, sizeof(*dd));
2330 bsg_job->reply->reply_payload_rcv_len = sizeof(*dd);
2331 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
2332 rval ? EXT_STATUS_MAILBOX : EXT_STATUS_OK;
2334 bsg_job->reply_len = sizeof(*bsg_job->reply);
2335 bsg_job->reply->result = DID_OK << 16;
2336 bsg_job->job_done(bsg_job);
2344 qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
2346 switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) {
2347 case QL_VND_LOOPBACK:
2348 return qla2x00_process_loopback(bsg_job);
2350 case QL_VND_A84_RESET:
2351 return qla84xx_reset(bsg_job);
2353 case QL_VND_A84_UPDATE_FW:
2354 return qla84xx_updatefw(bsg_job);
2356 case QL_VND_A84_MGMT_CMD:
2357 return qla84xx_mgmt_cmd(bsg_job);
2360 return qla24xx_iidma(bsg_job);
2362 case QL_VND_FCP_PRIO_CFG_CMD:
2363 return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job);
2365 case QL_VND_READ_FLASH:
2366 return qla2x00_read_optrom(bsg_job);
2368 case QL_VND_UPDATE_FLASH:
2369 return qla2x00_update_optrom(bsg_job);
2371 case QL_VND_SET_FRU_VERSION:
2372 return qla2x00_update_fru_versions(bsg_job);
2374 case QL_VND_READ_FRU_STATUS:
2375 return qla2x00_read_fru_status(bsg_job);
2377 case QL_VND_WRITE_FRU_STATUS:
2378 return qla2x00_write_fru_status(bsg_job);
2380 case QL_VND_WRITE_I2C:
2381 return qla2x00_write_i2c(bsg_job);
2383 case QL_VND_READ_I2C:
2384 return qla2x00_read_i2c(bsg_job);
2386 case QL_VND_DIAG_IO_CMD:
2387 return qla24xx_process_bidir_cmd(bsg_job);
2389 case QL_VND_FX00_MGMT_CMD:
2390 return qlafx00_mgmt_cmd(bsg_job);
2392 case QL_VND_SERDES_OP:
2393 return qla26xx_serdes_op(bsg_job);
2395 case QL_VND_SERDES_OP_EX:
2396 return qla8044_serdes_op(bsg_job);
2398 case QL_VND_GET_FLASH_UPDATE_CAPS:
2399 return qla27xx_get_flash_upd_cap(bsg_job);
2401 case QL_VND_SET_FLASH_UPDATE_CAPS:
2402 return qla27xx_set_flash_upd_cap(bsg_job);
2404 case QL_VND_GET_BBCR_DATA:
2405 return qla27xx_get_bbcr_data(bsg_job);
2407 case QL_VND_GET_PRIV_STATS:
2408 case QL_VND_GET_PRIV_STATS_EX:
2409 return qla2x00_get_priv_stats(bsg_job);
2411 case QL_VND_DPORT_DIAGNOSTICS:
2412 return qla2x00_do_dport_diagnostics(bsg_job);
2420 qla24xx_bsg_request(struct fc_bsg_job *bsg_job)
2423 struct fc_rport *rport;
2424 struct Scsi_Host *host;
2425 scsi_qla_host_t *vha;
2427 /* In case no data transferred. */
2428 bsg_job->reply->reply_payload_rcv_len = 0;
2430 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
2431 rport = bsg_job->rport;
2432 host = rport_to_shost(rport);
2433 vha = shost_priv(host);
2435 host = bsg_job->shost;
2436 vha = shost_priv(host);
2439 if (qla2x00_reset_active(vha)) {
2440 ql_dbg(ql_dbg_user, vha, 0x709f,
2441 "BSG: ISP abort active/needed -- cmd=%d.\n",
2442 bsg_job->request->msgcode);
2446 ql_dbg(ql_dbg_user, vha, 0x7000,
2447 "Entered %s msgcode=0x%x.\n", __func__, bsg_job->request->msgcode);
2449 switch (bsg_job->request->msgcode) {
2450 case FC_BSG_RPT_ELS:
2451 case FC_BSG_HST_ELS_NOLOGIN:
2452 ret = qla2x00_process_els(bsg_job);
2455 ret = qla2x00_process_ct(bsg_job);
2457 case FC_BSG_HST_VENDOR:
2458 ret = qla2x00_process_vendor_specific(bsg_job);
2460 case FC_BSG_HST_ADD_RPORT:
2461 case FC_BSG_HST_DEL_RPORT:
2464 ql_log(ql_log_warn, vha, 0x705a, "Unsupported BSG request.\n");
2471 qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job)
2473 scsi_qla_host_t *vha = shost_priv(bsg_job->shost);
2474 struct qla_hw_data *ha = vha->hw;
2477 unsigned long flags;
2478 struct req_que *req;
2480 /* find the bsg job from the active list of commands */
2481 spin_lock_irqsave(&ha->hardware_lock, flags);
2482 for (que = 0; que < ha->max_req_queues; que++) {
2483 req = ha->req_q_map[que];
2487 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
2488 sp = req->outstanding_cmds[cnt];
2490 if (((sp->type == SRB_CT_CMD) ||
2491 (sp->type == SRB_ELS_CMD_HST) ||
2492 (sp->type == SRB_FXIOCB_BCMD))
2493 && (sp->u.bsg_job == bsg_job)) {
2494 req->outstanding_cmds[cnt] = NULL;
2495 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2496 if (ha->isp_ops->abort_command(sp)) {
2497 ql_log(ql_log_warn, vha, 0x7089,
2498 "mbx abort_command "
2500 bsg_job->req->errors =
2501 bsg_job->reply->result = -EIO;
2503 ql_dbg(ql_dbg_user, vha, 0x708a,
2504 "mbx abort_command "
2506 bsg_job->req->errors =
2507 bsg_job->reply->result = 0;
2509 spin_lock_irqsave(&ha->hardware_lock, flags);
2515 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2516 ql_log(ql_log_info, vha, 0x708b, "SRB not found to abort.\n");
2517 bsg_job->req->errors = bsg_job->reply->result = -ENXIO;
2521 spin_unlock_irqrestore(&ha->hardware_lock, flags);