Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * QLOGIC LINUX SOFTWARE | |
3 | * | |
4 | * QLogic ISP2x00 device driver for Linux 2.6.x | |
5 | * Copyright (C) 2003-2004 QLogic Corporation | |
6 | * (www.qlogic.com) | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU General Public License as published by the | |
10 | * Free Software Foundation; either version 2, or (at your option) any | |
11 | * later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
18 | */ | |
19 | ||
20 | ||
21 | static __inline__ uint16_t qla2x00_debounce_register(volatile uint16_t __iomem *); | |
22 | /* | |
23 | * qla2x00_debounce_register | |
24 | * Debounce register. | |
25 | * | |
26 | * Input: | |
27 | * port = register address. | |
28 | * | |
29 | * Returns: | |
30 | * register value. | |
31 | */ | |
32 | static __inline__ uint16_t | |
33 | qla2x00_debounce_register(volatile uint16_t __iomem *addr) | |
34 | { | |
35 | volatile uint16_t first; | |
36 | volatile uint16_t second; | |
37 | ||
38 | do { | |
39 | first = RD_REG_WORD(addr); | |
40 | barrier(); | |
41 | cpu_relax(); | |
42 | second = RD_REG_WORD(addr); | |
43 | } while (first != second); | |
44 | ||
45 | return (first); | |
46 | } | |
47 | ||
48 | static __inline__ int qla2x00_normalize_dma_addr( | |
49 | dma_addr_t *e_addr, uint32_t *e_len, | |
50 | dma_addr_t *ne_addr, uint32_t *ne_len); | |
51 | ||
52 | /** | |
53 | * qla2x00_normalize_dma_addr() - Normalize an DMA address. | |
54 | * @e_addr: Raw DMA address | |
55 | * @e_len: Raw DMA length | |
56 | * @ne_addr: Normalized second DMA address | |
57 | * @ne_len: Normalized second DMA length | |
58 | * | |
59 | * If the address does not span a 4GB page boundary, the contents of @ne_addr | |
60 | * and @ne_len are undefined. @e_len is updated to reflect a normalization. | |
61 | * | |
62 | * Example: | |
63 | * | |
64 | * ffffabc0ffffeeee (e_addr) start of DMA address | |
65 | * 0000000020000000 (e_len) length of DMA transfer | |
66 | * ffffabc11fffeeed end of DMA transfer | |
67 | * | |
68 | * Is the 4GB boundary crossed? | |
69 | * | |
70 | * ffffabc0ffffeeee (e_addr) | |
71 | * ffffabc11fffeeed (e_addr + e_len - 1) | |
72 | * 00000001e0000003 ((e_addr ^ (e_addr + e_len - 1)) | |
73 | * 0000000100000000 ((e_addr ^ (e_addr + e_len - 1)) & ~(0xffffffff) | |
74 | * | |
75 | * Compute start of second DMA segment: | |
76 | * | |
77 | * ffffabc0ffffeeee (e_addr) | |
78 | * ffffabc1ffffeeee (0x100000000 + e_addr) | |
79 | * ffffabc100000000 (0x100000000 + e_addr) & ~(0xffffffff) | |
80 | * ffffabc100000000 (ne_addr) | |
81 | * | |
82 | * Compute length of second DMA segment: | |
83 | * | |
84 | * 00000000ffffeeee (e_addr & 0xffffffff) | |
85 | * 0000000000001112 (0x100000000 - (e_addr & 0xffffffff)) | |
86 | * 000000001fffeeee (e_len - (0x100000000 - (e_addr & 0xffffffff)) | |
87 | * 000000001fffeeee (ne_len) | |
88 | * | |
89 | * Adjust length of first DMA segment | |
90 | * | |
91 | * 0000000020000000 (e_len) | |
92 | * 0000000000001112 (e_len - ne_len) | |
93 | * 0000000000001112 (e_len) | |
94 | * | |
95 | * Returns non-zero if the specified address was normalized, else zero. | |
96 | */ | |
97 | static __inline__ int | |
98 | qla2x00_normalize_dma_addr( | |
99 | dma_addr_t *e_addr, uint32_t *e_len, | |
100 | dma_addr_t *ne_addr, uint32_t *ne_len) | |
101 | { | |
102 | int normalized; | |
103 | ||
104 | normalized = 0; | |
105 | if ((*e_addr ^ (*e_addr + *e_len - 1)) & ~(0xFFFFFFFFULL)) { | |
106 | /* Compute normalized crossed address and len */ | |
107 | *ne_addr = (0x100000000ULL + *e_addr) & ~(0xFFFFFFFFULL); | |
108 | *ne_len = *e_len - (0x100000000ULL - (*e_addr & 0xFFFFFFFFULL)); | |
109 | *e_len -= *ne_len; | |
110 | ||
111 | normalized++; | |
112 | } | |
113 | return (normalized); | |
114 | } | |
115 | ||
116 | static __inline__ void qla2x00_poll(scsi_qla_host_t *); | |
117 | static inline void | |
118 | qla2x00_poll(scsi_qla_host_t *ha) | |
119 | { | |
abbd8870 | 120 | ha->isp_ops.intr_handler(0, ha, NULL); |
1da177e4 LT |
121 | } |
122 | ||
1da177e4 LT |
123 | static __inline__ int qla2x00_is_wwn_zero(uint8_t *); |
124 | ||
125 | /* | |
126 | * qla2x00_is_wwn_zero - Check for zero node name | |
127 | * | |
128 | * Input: | |
129 | * wwn = Pointer to WW name to check | |
130 | * | |
131 | * Returns: | |
132 | * 1 if name is 0x00 else 0 | |
133 | * | |
134 | * Context: | |
135 | * Kernel context. | |
136 | */ | |
137 | static __inline__ int | |
138 | qla2x00_is_wwn_zero(uint8_t *wwn) | |
139 | { | |
140 | int cnt; | |
141 | ||
142 | for (cnt = 0; cnt < WWN_SIZE ; cnt++, wwn++) { | |
143 | if (*wwn != 0) | |
144 | break; | |
145 | } | |
146 | /* if zero return 1 */ | |
147 | if (cnt == WWN_SIZE) | |
148 | return (1); | |
149 | else | |
150 | return (0); | |
151 | } | |
152 | ||
1da177e4 LT |
153 | static __inline__ void qla2x00_check_fabric_devices(scsi_qla_host_t *); |
154 | /* | |
155 | * This routine will wait for fabric devices for | |
156 | * the reset delay. | |
157 | */ | |
158 | static __inline__ void qla2x00_check_fabric_devices(scsi_qla_host_t *ha) | |
159 | { | |
160 | uint16_t fw_state; | |
161 | ||
162 | qla2x00_get_firmware_state(ha, &fw_state); | |
163 | } | |
164 | ||
165 | /** | |
166 | * qla2x00_issue_marker() - Issue a Marker IOCB if necessary. | |
167 | * @ha: HA context | |
168 | * @ha_locked: is function called with the hardware lock | |
169 | * | |
170 | * Returns non-zero if a failure occured, else zero. | |
171 | */ | |
172 | static inline int | |
173 | qla2x00_issue_marker(scsi_qla_host_t *ha, int ha_locked) | |
174 | { | |
175 | /* Send marker if required */ | |
176 | if (ha->marker_needed != 0) { | |
177 | if (ha_locked) { | |
178 | if (__qla2x00_marker(ha, 0, 0, MK_SYNC_ALL) != | |
179 | QLA_SUCCESS) | |
180 | return (QLA_FUNCTION_FAILED); | |
181 | } else { | |
182 | if (qla2x00_marker(ha, 0, 0, MK_SYNC_ALL) != | |
183 | QLA_SUCCESS) | |
184 | return (QLA_FUNCTION_FAILED); | |
185 | } | |
186 | ha->marker_needed = 0; | |
187 | } | |
188 | return (QLA_SUCCESS); | |
189 | } | |
190 | ||
191 | static __inline__ void qla2x00_add_timer_to_cmd(srb_t *, int); | |
192 | static __inline__ void qla2x00_delete_timer_from_cmd(srb_t *); | |
193 | ||
194 | /************************************************************************** | |
195 | * qla2x00_add_timer_to_cmd | |
196 | * | |
197 | * Description: | |
198 | * Creates a timer for the specified command. The timeout is usually | |
199 | * the command time from kernel minus 2 secs. | |
200 | * | |
201 | * Input: | |
202 | * sp - pointer to validate | |
203 | * | |
204 | * Returns: | |
205 | * None. | |
206 | **************************************************************************/ | |
207 | static inline void | |
208 | qla2x00_add_timer_to_cmd(srb_t *sp, int timeout) | |
209 | { | |
210 | init_timer(&sp->timer); | |
211 | sp->timer.expires = jiffies + timeout * HZ; | |
212 | sp->timer.data = (unsigned long) sp; | |
213 | sp->timer.function = (void (*) (unsigned long))qla2x00_cmd_timeout; | |
214 | add_timer(&sp->timer); | |
215 | } | |
216 | ||
217 | /************************************************************************** | |
218 | * qla2x00_delete_timer_from_cmd | |
219 | * | |
220 | * Description: | |
221 | * Delete the timer for the specified command. | |
222 | * | |
223 | * Input: | |
224 | * sp - pointer to validate | |
225 | * | |
226 | * Returns: | |
227 | * None. | |
228 | **************************************************************************/ | |
229 | static inline void | |
230 | qla2x00_delete_timer_from_cmd(srb_t *sp) | |
231 | { | |
232 | if (sp->timer.function != NULL) { | |
233 | del_timer(&sp->timer); | |
234 | sp->timer.function = NULL; | |
235 | sp->timer.data = (unsigned long) NULL; | |
236 | } | |
237 | } | |
238 | ||
2b6c0cee AV |
239 | static inline uint8_t *host_to_fcp_swap(uint8_t *, uint32_t); |
240 | static inline uint8_t * | |
241 | host_to_fcp_swap(uint8_t *fcp, uint32_t bsize) | |
242 | { | |
243 | uint32_t *ifcp = (uint32_t *) fcp; | |
244 | uint32_t *ofcp = (uint32_t *) fcp; | |
245 | uint32_t iter = bsize >> 2; | |
246 | ||
247 | for (; iter ; iter--) | |
248 | *ofcp++ = swab32(*ifcp++); | |
249 | ||
250 | return fcp; | |
251 | } | |
3d71644c AV |
252 | |
253 | static inline int qla2x00_is_reserved_id(scsi_qla_host_t *, uint16_t); | |
254 | static inline int | |
255 | qla2x00_is_reserved_id(scsi_qla_host_t *ha, uint16_t loop_id) | |
256 | { | |
257 | if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) | |
258 | return (loop_id > NPH_LAST_HANDLE); | |
259 | ||
260 | return ((loop_id > ha->last_loop_id && loop_id < SNS_FIRST_LOOP_ID) || | |
261 | loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST); | |
262 | }; |