2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
8 #include "qla_target.h"
10 * qla24xx_calc_iocbs() - Determine number of Command Type 3 and
11 * Continuation Type 1 IOCBs to allocate.
14 * @dsds: number of data segment decriptors needed
16 * Returns the number of IOCB entries needed to store @dsds.
18 static inline uint16_t
19 qla24xx_calc_iocbs(scsi_qla_host_t *vha, uint16_t dsds)
25 iocbs += (dsds - 1) / 5;
33 * qla2x00_debounce_register
37 * port = register address.
42 static __inline__ uint16_t
43 qla2x00_debounce_register(volatile uint16_t __iomem *addr)
45 volatile uint16_t first;
46 volatile uint16_t second;
49 first = RD_REG_WORD(addr);
52 second = RD_REG_WORD(addr);
53 } while (first != second);
59 qla2x00_poll(struct rsp_que *rsp)
61 struct qla_hw_data *ha = rsp->hw;
66 ha->isp_ops->intr_handler(0, rsp);
69 static inline uint8_t *
70 host_to_fcp_swap(uint8_t *fcp, uint32_t bsize)
72 uint32_t *ifcp = (uint32_t *) fcp;
73 uint32_t *ofcp = (uint32_t *) fcp;
74 uint32_t iter = bsize >> 2;
77 *ofcp++ = swab32(*ifcp++);
83 host_to_adap(uint8_t *src, uint8_t *dst, uint32_t bsize)
85 uint32_t *isrc = (uint32_t *) src;
86 __le32 *odest = (__le32 *) dst;
87 uint32_t iter = bsize >> 2;
89 for ( ; iter--; isrc++)
90 *odest++ = cpu_to_le32(*isrc);
94 qla2x00_clean_dsd_pool(struct qla_hw_data *ha, struct crc_context *ctx)
96 struct dsd_dma *dsd, *tdsd;
98 /* clean up allocated prev pool */
99 list_for_each_entry_safe(dsd, tdsd, &ctx->dsd_list, list) {
100 dma_pool_free(ha->dl_dma_pool, dsd->dsd_addr,
102 list_del(&dsd->list);
105 INIT_LIST_HEAD(&ctx->dsd_list);
109 qla2x00_hba_err_chk_enabled(srb_t *sp)
112 * Uncomment when corresponding SCSI changes are done.
114 if (!sp->cmd->prot_chk)
118 switch (scsi_get_prot_op(GET_CMD_SP(sp))) {
119 case SCSI_PROT_READ_STRIP:
120 case SCSI_PROT_WRITE_INSERT:
121 if (ql2xenablehba_err_chk >= 1)
124 case SCSI_PROT_READ_PASS:
125 case SCSI_PROT_WRITE_PASS:
126 if (ql2xenablehba_err_chk >= 2)
129 case SCSI_PROT_READ_INSERT:
130 case SCSI_PROT_WRITE_STRIP:
137 qla2x00_reset_active(scsi_qla_host_t *vha)
139 scsi_qla_host_t *base_vha = pci_get_drvdata(vha->hw->pdev);
141 /* Test appropriate base-vha and vha flags. */
142 return test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) ||
143 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
144 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
145 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
146 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
150 qla2x00_chip_is_down(scsi_qla_host_t *vha)
152 return (qla2x00_reset_active(vha) || !vha->hw->flags.fw_started);
155 static void qla2xxx_init_sp(srb_t *sp, scsi_qla_host_t *vha,
156 struct qla_qpair *qpair, fc_port_t *fcport)
158 memset(sp, 0, sizeof(*sp));
163 sp->cmd_type = TYPE_SRB;
164 INIT_LIST_HEAD(&sp->elem);
167 static inline srb_t *
168 qla2xxx_get_qpair_sp(scsi_qla_host_t *vha, struct qla_qpair *qpair,
169 fc_port_t *fcport, gfp_t flag)
174 QLA_QPAIR_MARK_BUSY(qpair, bail);
178 sp = mempool_alloc(qpair->srb_mempool, flag);
180 qla2xxx_init_sp(sp, vha, qpair, fcport);
182 QLA_QPAIR_MARK_NOT_BUSY(qpair);
187 qla2xxx_rel_qpair_sp(struct qla_qpair *qpair, srb_t *sp)
190 mempool_free(sp, qpair->srb_mempool);
191 QLA_QPAIR_MARK_NOT_BUSY(qpair);
194 static inline srb_t *
195 qla2x00_get_sp(scsi_qla_host_t *vha, fc_port_t *fcport, gfp_t flag)
199 struct qla_qpair *qpair;
201 QLA_VHA_MARK_BUSY(vha, bail);
205 qpair = vha->hw->base_qpair;
206 sp = qla2xxx_get_qpair_sp(vha, qpair, fcport, flag);
213 QLA_VHA_MARK_NOT_BUSY(vha);
218 qla2x00_rel_sp(srb_t *sp)
220 QLA_VHA_MARK_NOT_BUSY(sp->vha);
221 qla2xxx_rel_qpair_sp(sp->qpair, sp);
225 qla2x00_gid_list_size(struct qla_hw_data *ha)
228 return sizeof(uint32_t) * 32;
230 return sizeof(struct gid_list_info) * ha->max_fibre_devices;
234 qla2x00_handle_mbx_completion(struct qla_hw_data *ha, int status)
236 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
237 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
238 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
239 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
240 complete(&ha->mbx_intr_comp);
245 qla2x00_set_retry_delay_timestamp(fc_port_t *fcport, uint16_t retry_delay)
248 fcport->retry_delay_timestamp = jiffies +
249 (retry_delay * HZ / 10);
253 qla_is_exch_offld_enabled(struct scsi_qla_host *vha)
255 if (qla_ini_mode_enabled(vha) &&
256 (vha->ql2xiniexchg > FW_DEF_EXCHANGES_CNT))
258 else if (qla_tgt_mode_enabled(vha) &&
259 (vha->ql2xexchoffld > FW_DEF_EXCHANGES_CNT))
261 else if (qla_dual_mode_enabled(vha) &&
262 ((vha->ql2xiniexchg + vha->ql2xexchoffld) > FW_DEF_EXCHANGES_CNT))
269 qla_cpu_update(struct qla_qpair *qpair, uint16_t cpuid)
271 qpair->cpuid = cpuid;
273 if (!list_empty(&qpair->hints_list)) {
274 struct qla_qpair_hint *h;
276 list_for_each_entry(h, &qpair->hints_list, hint_elem)
277 h->cpuid = qpair->cpuid;
281 static inline struct qla_qpair_hint *
282 qla_qpair_to_hint(struct qla_tgt *tgt, struct qla_qpair *qpair)
284 struct qla_qpair_hint *h;
287 for (i = 0; i < tgt->ha->max_qpairs + 1; i++) {
288 h = &tgt->qphints[i];
289 if (h->qpair == qpair)
297 qla_83xx_start_iocbs(struct qla_qpair *qpair)
299 struct req_que *req = qpair->req;
302 if (req->ring_index == req->length) {
304 req->ring_ptr = req->ring;
308 WRT_REG_DWORD(req->req_q_in, req->ring_index);
312 qla2xxx_get_fc4_priority(struct scsi_qla_host *vha)
317 ((uint8_t *)vha->hw->nvram)[NVRAM_DUAL_FCP_NVME_FLAG_OFFSET];
320 return (data >> 6) & BIT_0 ? FC4_PRIORITY_FCP : FC4_PRIORITY_NVME;