net: ethernet: sun: niu set correct packet size in skb
[linux/fpc-iii.git] / drivers / scsi / qla2xxx / qla_inline.h
blob4d32426393c702fa6335440a41d714a787b0b252
1 /*
2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
6 */
8 #include "qla_target.h"
9 /**
10 * qla24xx_calc_iocbs() - Determine number of Command Type 3 and
11 * Continuation Type 1 IOCBs to allocate.
13 * @dsds: number of data segment decriptors needed
15 * Returns the number of IOCB entries needed to store @dsds.
17 static inline uint16_t
18 qla24xx_calc_iocbs(scsi_qla_host_t *vha, uint16_t dsds)
20 uint16_t iocbs;
22 iocbs = 1;
23 if (dsds > 1) {
24 iocbs += (dsds - 1) / 5;
25 if ((dsds - 1) % 5)
26 iocbs++;
28 return iocbs;
32 * qla2x00_debounce_register
33 * Debounce register.
35 * Input:
36 * port = register address.
38 * Returns:
39 * register value.
41 static __inline__ uint16_t
42 qla2x00_debounce_register(volatile uint16_t __iomem *addr)
44 volatile uint16_t first;
45 volatile uint16_t second;
47 do {
48 first = RD_REG_WORD(addr);
49 barrier();
50 cpu_relax();
51 second = RD_REG_WORD(addr);
52 } while (first != second);
54 return (first);
57 static inline void
58 qla2x00_poll(struct rsp_que *rsp)
60 unsigned long flags;
61 struct qla_hw_data *ha = rsp->hw;
62 local_irq_save(flags);
63 if (IS_P3P_TYPE(ha))
64 qla82xx_poll(0, rsp);
65 else
66 ha->isp_ops->intr_handler(0, rsp);
67 local_irq_restore(flags);
70 static inline uint8_t *
71 host_to_fcp_swap(uint8_t *fcp, uint32_t bsize)
73 uint32_t *ifcp = (uint32_t *) fcp;
74 uint32_t *ofcp = (uint32_t *) fcp;
75 uint32_t iter = bsize >> 2;
77 for (; iter ; iter--)
78 *ofcp++ = swab32(*ifcp++);
80 return fcp;
83 static inline void
84 host_to_adap(uint8_t *src, uint8_t *dst, uint32_t bsize)
86 uint32_t *isrc = (uint32_t *) src;
87 __le32 *odest = (__le32 *) dst;
88 uint32_t iter = bsize >> 2;
90 for ( ; iter--; isrc++)
91 *odest++ = cpu_to_le32(*isrc);
94 static inline void
95 qla2x00_set_reserved_loop_ids(struct qla_hw_data *ha)
97 int i;
99 if (IS_FWI2_CAPABLE(ha))
100 return;
102 for (i = 0; i < SNS_FIRST_LOOP_ID; i++)
103 set_bit(i, ha->loop_id_map);
104 set_bit(MANAGEMENT_SERVER, ha->loop_id_map);
105 set_bit(BROADCAST, ha->loop_id_map);
108 static inline int
109 qla2x00_is_reserved_id(scsi_qla_host_t *vha, uint16_t loop_id)
111 struct qla_hw_data *ha = vha->hw;
112 if (IS_FWI2_CAPABLE(ha))
113 return (loop_id > NPH_LAST_HANDLE);
115 return ((loop_id > ha->max_loop_id && loop_id < SNS_FIRST_LOOP_ID) ||
116 loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST);
119 static inline void
120 qla2x00_clear_loop_id(fc_port_t *fcport) {
121 struct qla_hw_data *ha = fcport->vha->hw;
123 if (fcport->loop_id == FC_NO_LOOP_ID ||
124 qla2x00_is_reserved_id(fcport->vha, fcport->loop_id))
125 return;
127 clear_bit(fcport->loop_id, ha->loop_id_map);
128 fcport->loop_id = FC_NO_LOOP_ID;
131 static inline void
132 qla2x00_clean_dsd_pool(struct qla_hw_data *ha, struct crc_context *ctx)
134 struct dsd_dma *dsd, *tdsd;
136 /* clean up allocated prev pool */
137 list_for_each_entry_safe(dsd, tdsd, &ctx->dsd_list, list) {
138 dma_pool_free(ha->dl_dma_pool, dsd->dsd_addr,
139 dsd->dsd_list_dma);
140 list_del(&dsd->list);
141 kfree(dsd);
143 INIT_LIST_HEAD(&ctx->dsd_list);
146 static inline void
147 qla2x00_set_fcport_state(fc_port_t *fcport, int state)
149 int old_state;
151 old_state = atomic_read(&fcport->state);
152 atomic_set(&fcport->state, state);
154 /* Don't print state transitions during initial allocation of fcport */
155 if (old_state && old_state != state) {
156 ql_dbg(ql_dbg_disc, fcport->vha, 0x207d,
157 "FCPort %8phC state transitioned from %s to %s - "
158 "portid=%02x%02x%02x.\n", fcport->port_name,
159 port_state_str[old_state], port_state_str[state],
160 fcport->d_id.b.domain, fcport->d_id.b.area,
161 fcport->d_id.b.al_pa);
165 static inline int
166 qla2x00_hba_err_chk_enabled(srb_t *sp)
169 * Uncomment when corresponding SCSI changes are done.
171 if (!sp->cmd->prot_chk)
172 return 0;
175 switch (scsi_get_prot_op(GET_CMD_SP(sp))) {
176 case SCSI_PROT_READ_STRIP:
177 case SCSI_PROT_WRITE_INSERT:
178 if (ql2xenablehba_err_chk >= 1)
179 return 1;
180 break;
181 case SCSI_PROT_READ_PASS:
182 case SCSI_PROT_WRITE_PASS:
183 if (ql2xenablehba_err_chk >= 2)
184 return 1;
185 break;
186 case SCSI_PROT_READ_INSERT:
187 case SCSI_PROT_WRITE_STRIP:
188 return 1;
190 return 0;
193 static inline int
194 qla2x00_reset_active(scsi_qla_host_t *vha)
196 scsi_qla_host_t *base_vha = pci_get_drvdata(vha->hw->pdev);
198 /* Test appropriate base-vha and vha flags. */
199 return test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) ||
200 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
201 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
202 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
203 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
206 static inline srb_t *
207 qla2xxx_get_qpair_sp(struct qla_qpair *qpair, fc_port_t *fcport, gfp_t flag)
209 srb_t *sp = NULL;
210 uint8_t bail;
212 QLA_QPAIR_MARK_BUSY(qpair, bail);
213 if (unlikely(bail))
214 return NULL;
216 sp = mempool_alloc(qpair->srb_mempool, flag);
217 if (!sp)
218 goto done;
220 memset(sp, 0, sizeof(*sp));
221 sp->fcport = fcport;
222 sp->iocbs = 1;
223 sp->vha = qpair->vha;
224 done:
225 if (!sp)
226 QLA_QPAIR_MARK_NOT_BUSY(qpair);
227 return sp;
230 static inline void
231 qla2xxx_rel_qpair_sp(struct qla_qpair *qpair, srb_t *sp)
233 mempool_free(sp, qpair->srb_mempool);
234 QLA_QPAIR_MARK_NOT_BUSY(qpair);
237 static inline srb_t *
238 qla2x00_get_sp(scsi_qla_host_t *vha, fc_port_t *fcport, gfp_t flag)
240 srb_t *sp = NULL;
241 uint8_t bail;
243 QLA_VHA_MARK_BUSY(vha, bail);
244 if (unlikely(bail))
245 return NULL;
247 sp = mempool_alloc(vha->hw->srb_mempool, flag);
248 if (!sp)
249 goto done;
251 memset(sp, 0, sizeof(*sp));
252 sp->fcport = fcport;
253 sp->cmd_type = TYPE_SRB;
254 sp->iocbs = 1;
255 sp->vha = vha;
256 done:
257 if (!sp)
258 QLA_VHA_MARK_NOT_BUSY(vha);
259 return sp;
262 static inline void
263 qla2x00_rel_sp(srb_t *sp)
265 QLA_VHA_MARK_NOT_BUSY(sp->vha);
266 mempool_free(sp, sp->vha->hw->srb_mempool);
269 static inline void
270 qla2x00_init_timer(srb_t *sp, unsigned long tmo)
272 timer_setup(&sp->u.iocb_cmd.timer, qla2x00_sp_timeout, 0);
273 sp->u.iocb_cmd.timer.expires = jiffies + tmo * HZ;
274 add_timer(&sp->u.iocb_cmd.timer);
275 sp->free = qla2x00_sp_free;
276 init_completion(&sp->comp);
277 if (IS_QLAFX00(sp->vha->hw) && (sp->type == SRB_FXIOCB_DCMD))
278 init_completion(&sp->u.iocb_cmd.u.fxiocb.fxiocb_comp);
279 if (sp->type == SRB_ELS_DCMD)
280 init_completion(&sp->u.iocb_cmd.u.els_logo.comp);
283 static inline int
284 qla2x00_gid_list_size(struct qla_hw_data *ha)
286 if (IS_QLAFX00(ha))
287 return sizeof(uint32_t) * 32;
288 else
289 return sizeof(struct gid_list_info) * ha->max_fibre_devices;
292 static inline void
293 qla2x00_handle_mbx_completion(struct qla_hw_data *ha, int status)
295 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
296 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
297 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
298 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
299 complete(&ha->mbx_intr_comp);
303 static inline void
304 qla2x00_set_retry_delay_timestamp(fc_port_t *fcport, uint16_t retry_delay)
306 if (retry_delay)
307 fcport->retry_delay_timestamp = jiffies +
308 (retry_delay * HZ / 10);
311 static inline bool
312 qla_is_exch_offld_enabled(struct scsi_qla_host *vha)
314 if (qla_ini_mode_enabled(vha) &&
315 (ql2xiniexchg > FW_DEF_EXCHANGES_CNT))
316 return true;
317 else if (qla_tgt_mode_enabled(vha) &&
318 (ql2xexchoffld > FW_DEF_EXCHANGES_CNT))
319 return true;
320 else if (qla_dual_mode_enabled(vha) &&
321 ((ql2xiniexchg + ql2xexchoffld) > FW_DEF_EXCHANGES_CNT))
322 return true;
323 else
324 return false;
327 static inline void
328 qla_cpu_update(struct qla_qpair *qpair, uint16_t cpuid)
330 qpair->cpuid = cpuid;
332 if (!list_empty(&qpair->hints_list)) {
333 struct qla_qpair_hint *h;
335 list_for_each_entry(h, &qpair->hints_list, hint_elem)
336 h->cpuid = qpair->cpuid;
340 static inline struct qla_qpair_hint *
341 qla_qpair_to_hint(struct qla_tgt *tgt, struct qla_qpair *qpair)
343 struct qla_qpair_hint *h;
344 u16 i;
346 for (i = 0; i < tgt->ha->max_qpairs + 1; i++) {
347 h = &tgt->qphints[i];
348 if (h->qpair == qpair)
349 return h;
352 return NULL;
355 static inline void
356 qla_83xx_start_iocbs(struct qla_qpair *qpair)
358 struct req_que *req = qpair->req;
360 req->ring_index++;
361 if (req->ring_index == req->length) {
362 req->ring_index = 0;
363 req->ring_ptr = req->ring;
364 } else
365 req->ring_ptr++;
367 WRT_REG_DWORD(req->req_q_in, req->ring_index);