fs: use kmem_cache_zalloc instead
[pv_ops_mirror.git] / drivers / scsi / qla2xxx / qla_inline.h
blob8e3b04464cff26903b69a87a164ec34f58176ac2
1 /*
2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
6 */
8 static __inline__ uint16_t qla2x00_debounce_register(volatile uint16_t __iomem *);
9 /*
10 * qla2x00_debounce_register
11 * Debounce register.
13 * Input:
14 * port = register address.
16 * Returns:
17 * register value.
19 static __inline__ uint16_t
20 qla2x00_debounce_register(volatile uint16_t __iomem *addr)
22 volatile uint16_t first;
23 volatile uint16_t second;
25 do {
26 first = RD_REG_WORD(addr);
27 barrier();
28 cpu_relax();
29 second = RD_REG_WORD(addr);
30 } while (first != second);
32 return (first);
35 static __inline__ int qla2x00_normalize_dma_addr(
36 dma_addr_t *e_addr, uint32_t *e_len,
37 dma_addr_t *ne_addr, uint32_t *ne_len);
39 /**
40 * qla2x00_normalize_dma_addr() - Normalize an DMA address.
41 * @e_addr: Raw DMA address
42 * @e_len: Raw DMA length
43 * @ne_addr: Normalized second DMA address
44 * @ne_len: Normalized second DMA length
46 * If the address does not span a 4GB page boundary, the contents of @ne_addr
47 * and @ne_len are undefined. @e_len is updated to reflect a normalization.
49 * Example:
51 * ffffabc0ffffeeee (e_addr) start of DMA address
52 * 0000000020000000 (e_len) length of DMA transfer
53 * ffffabc11fffeeed end of DMA transfer
55 * Is the 4GB boundary crossed?
57 * ffffabc0ffffeeee (e_addr)
58 * ffffabc11fffeeed (e_addr + e_len - 1)
59 * 00000001e0000003 ((e_addr ^ (e_addr + e_len - 1))
60 * 0000000100000000 ((e_addr ^ (e_addr + e_len - 1)) & ~(0xffffffff)
62 * Compute start of second DMA segment:
64 * ffffabc0ffffeeee (e_addr)
65 * ffffabc1ffffeeee (0x100000000 + e_addr)
66 * ffffabc100000000 (0x100000000 + e_addr) & ~(0xffffffff)
67 * ffffabc100000000 (ne_addr)
69 * Compute length of second DMA segment:
71 * 00000000ffffeeee (e_addr & 0xffffffff)
72 * 0000000000001112 (0x100000000 - (e_addr & 0xffffffff))
73 * 000000001fffeeee (e_len - (0x100000000 - (e_addr & 0xffffffff))
74 * 000000001fffeeee (ne_len)
76 * Adjust length of first DMA segment
78 * 0000000020000000 (e_len)
79 * 0000000000001112 (e_len - ne_len)
80 * 0000000000001112 (e_len)
82 * Returns non-zero if the specified address was normalized, else zero.
84 static __inline__ int
85 qla2x00_normalize_dma_addr(
86 dma_addr_t *e_addr, uint32_t *e_len,
87 dma_addr_t *ne_addr, uint32_t *ne_len)
89 int normalized;
91 normalized = 0;
92 if ((*e_addr ^ (*e_addr + *e_len - 1)) & ~(0xFFFFFFFFULL)) {
93 /* Compute normalized crossed address and len */
94 *ne_addr = (0x100000000ULL + *e_addr) & ~(0xFFFFFFFFULL);
95 *ne_len = *e_len - (0x100000000ULL - (*e_addr & 0xFFFFFFFFULL));
96 *e_len -= *ne_len;
98 normalized++;
100 return (normalized);
103 static __inline__ void qla2x00_poll(scsi_qla_host_t *);
104 static inline void
105 qla2x00_poll(scsi_qla_host_t *ha)
107 ha->isp_ops->intr_handler(0, ha);
110 static __inline__ void qla2x00_check_fabric_devices(scsi_qla_host_t *);
112 * This routine will wait for fabric devices for
113 * the reset delay.
115 static __inline__ void qla2x00_check_fabric_devices(scsi_qla_host_t *ha)
117 uint16_t fw_state;
119 qla2x00_get_firmware_state(ha, &fw_state);
123 * qla2x00_issue_marker() - Issue a Marker IOCB if necessary.
124 * @ha: HA context
125 * @ha_locked: is function called with the hardware lock
127 * Returns non-zero if a failure occured, else zero.
129 static inline int
130 qla2x00_issue_marker(scsi_qla_host_t *ha, int ha_locked)
132 /* Send marker if required */
133 if (ha->marker_needed != 0) {
134 if (ha_locked) {
135 if (__qla2x00_marker(ha, 0, 0, MK_SYNC_ALL) !=
136 QLA_SUCCESS)
137 return (QLA_FUNCTION_FAILED);
138 } else {
139 if (qla2x00_marker(ha, 0, 0, MK_SYNC_ALL) !=
140 QLA_SUCCESS)
141 return (QLA_FUNCTION_FAILED);
143 ha->marker_needed = 0;
145 return (QLA_SUCCESS);
148 static inline uint8_t *host_to_fcp_swap(uint8_t *, uint32_t);
149 static inline uint8_t *
150 host_to_fcp_swap(uint8_t *fcp, uint32_t bsize)
152 uint32_t *ifcp = (uint32_t *) fcp;
153 uint32_t *ofcp = (uint32_t *) fcp;
154 uint32_t iter = bsize >> 2;
156 for (; iter ; iter--)
157 *ofcp++ = swab32(*ifcp++);
159 return fcp;
162 static inline int qla2x00_is_reserved_id(scsi_qla_host_t *, uint16_t);
163 static inline int
164 qla2x00_is_reserved_id(scsi_qla_host_t *ha, uint16_t loop_id)
166 if (IS_FWI2_CAPABLE(ha))
167 return (loop_id > NPH_LAST_HANDLE);
169 return ((loop_id > ha->last_loop_id && loop_id < SNS_FIRST_LOOP_ID) ||
170 loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST);