2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2013 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 * qla24xx_calc_iocbs() - Determine number of Command Type 3 and
10 * Continuation Type 1 IOCBs to allocate.
12 * @dsds: number of data segment decriptors needed
14 * Returns the number of IOCB entries needed to store @dsds.
16 static inline uint16_t
17 qla24xx_calc_iocbs(scsi_qla_host_t *vha, uint16_t dsds)
23 iocbs += (dsds - 1) / 5;
31 * qla2x00_debounce_register
35 * port = register address.
40 static __inline__ uint16_t
41 qla2x00_debounce_register(volatile uint16_t __iomem *addr)
43 volatile uint16_t first;
44 volatile uint16_t second;
47 first = RD_REG_WORD(addr);
50 second = RD_REG_WORD(addr);
51 } while (first != second);
57 qla2x00_poll(struct rsp_que *rsp)
60 struct qla_hw_data *ha = rsp->hw;
61 local_irq_save(flags);
65 ha->isp_ops->intr_handler(0, rsp);
66 local_irq_restore(flags);
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;
90 *odest++ = cpu_to_le32(*isrc++);
94 qla2x00_set_reserved_loop_ids(struct qla_hw_data *ha)
98 if (IS_FWI2_CAPABLE(ha))
101 for (i = 0; i < SNS_FIRST_LOOP_ID; i++)
102 set_bit(i, ha->loop_id_map);
103 set_bit(MANAGEMENT_SERVER, ha->loop_id_map);
104 set_bit(BROADCAST, ha->loop_id_map);
108 qla2x00_is_reserved_id(scsi_qla_host_t *vha, uint16_t loop_id)
110 struct qla_hw_data *ha = vha->hw;
111 if (IS_FWI2_CAPABLE(ha))
112 return (loop_id > NPH_LAST_HANDLE);
114 return ((loop_id > ha->max_loop_id && loop_id < SNS_FIRST_LOOP_ID) ||
115 loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST);
119 qla2x00_clear_loop_id(fc_port_t *fcport) {
120 struct qla_hw_data *ha = fcport->vha->hw;
122 if (fcport->loop_id == FC_NO_LOOP_ID ||
123 qla2x00_is_reserved_id(fcport->vha, fcport->loop_id))
126 clear_bit(fcport->loop_id, ha->loop_id_map);
127 fcport->loop_id = FC_NO_LOOP_ID;
131 qla2x00_clean_dsd_pool(struct qla_hw_data *ha, srb_t *sp)
133 struct dsd_dma *dsd_ptr, *tdsd_ptr;
134 struct crc_context *ctx;
136 ctx = (struct crc_context *)GET_CMD_CTX_SP(sp);
138 /* clean up allocated prev pool */
139 list_for_each_entry_safe(dsd_ptr, tdsd_ptr,
140 &ctx->dsd_list, list) {
141 dma_pool_free(ha->dl_dma_pool, dsd_ptr->dsd_addr,
142 dsd_ptr->dsd_list_dma);
143 list_del(&dsd_ptr->list);
146 INIT_LIST_HEAD(&ctx->dsd_list);
150 qla2x00_set_fcport_state(fc_port_t *fcport, int state)
154 old_state = atomic_read(&fcport->state);
155 atomic_set(&fcport->state, state);
157 /* Don't print state transitions during initial allocation of fcport */
158 if (old_state && old_state != state) {
159 ql_dbg(ql_dbg_disc, fcport->vha, 0x207d,
160 "FCPort state transitioned from %s to %s - "
161 "portid=%02x%02x%02x.\n",
162 port_state_str[old_state], port_state_str[state],
163 fcport->d_id.b.domain, fcport->d_id.b.area,
164 fcport->d_id.b.al_pa);
169 qla2x00_hba_err_chk_enabled(srb_t *sp)
172 * Uncomment when corresponding SCSI changes are done.
174 if (!sp->cmd->prot_chk)
178 switch (scsi_get_prot_op(GET_CMD_SP(sp))) {
179 case SCSI_PROT_READ_STRIP:
180 case SCSI_PROT_WRITE_INSERT:
181 if (ql2xenablehba_err_chk >= 1)
184 case SCSI_PROT_READ_PASS:
185 case SCSI_PROT_WRITE_PASS:
186 if (ql2xenablehba_err_chk >= 2)
189 case SCSI_PROT_READ_INSERT:
190 case SCSI_PROT_WRITE_STRIP:
197 qla2x00_reset_active(scsi_qla_host_t *vha)
199 scsi_qla_host_t *base_vha = pci_get_drvdata(vha->hw->pdev);
201 /* Test appropriate base-vha and vha flags. */
202 return test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) ||
203 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
204 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
205 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
206 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
209 static inline srb_t *
210 qla2x00_get_sp(scsi_qla_host_t *vha, fc_port_t *fcport, gfp_t flag)
213 struct qla_hw_data *ha = vha->hw;
216 QLA_VHA_MARK_BUSY(vha, bail);
220 sp = mempool_alloc(ha->srb_mempool, flag);
224 memset(sp, 0, sizeof(*sp));
229 QLA_VHA_MARK_NOT_BUSY(vha);
234 qla2x00_rel_sp(scsi_qla_host_t *vha, srb_t *sp)
236 mempool_free(sp, vha->hw->srb_mempool);
237 QLA_VHA_MARK_NOT_BUSY(vha);
241 qla2x00_init_timer(srb_t *sp, unsigned long tmo)
243 init_timer(&sp->u.iocb_cmd.timer);
244 sp->u.iocb_cmd.timer.expires = jiffies + tmo * HZ;
245 sp->u.iocb_cmd.timer.data = (unsigned long)sp;
246 sp->u.iocb_cmd.timer.function = qla2x00_sp_timeout;
247 add_timer(&sp->u.iocb_cmd.timer);
248 sp->free = qla2x00_sp_free;
249 if ((IS_QLAFX00(sp->fcport->vha->hw)) &&
250 (sp->type == SRB_FXIOCB_DCMD))
251 init_completion(&sp->u.iocb_cmd.u.fxiocb.fxiocb_comp);
255 qla2x00_gid_list_size(struct qla_hw_data *ha)
258 return sizeof(uint32_t) * 32;
260 return sizeof(struct gid_list_info) * ha->max_fibre_devices;
264 qla2x00_handle_mbx_completion(struct qla_hw_data *ha, int status)
266 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
267 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
268 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
269 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
270 complete(&ha->mbx_intr_comp);