]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
fa90c54f | 2 | * QLogic Fibre Channel HBA Driver |
de7c5d05 | 3 | * Copyright (c) 2003-2010 QLogic Corporation |
1da177e4 | 4 | * |
fa90c54f | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
1da177e4 LT |
6 | */ |
7 | #include "qla_def.h" | |
73208dfd | 8 | #include "qla_gbl.h" |
1da177e4 LT |
9 | |
10 | #include <linux/delay.h> | |
5a0e3ad6 | 11 | #include <linux/slab.h> |
0107109e | 12 | #include <linux/vmalloc.h> |
1da177e4 LT |
13 | |
14 | #include "qla_devtbl.h" | |
15 | ||
4e08df3f DM |
16 | #ifdef CONFIG_SPARC |
17 | #include <asm/prom.h> | |
4e08df3f DM |
18 | #endif |
19 | ||
1da177e4 LT |
20 | /* |
21 | * QLogic ISP2x00 Hardware Support Function Prototypes. | |
22 | */ | |
1da177e4 | 23 | static int qla2x00_isp_firmware(scsi_qla_host_t *); |
1da177e4 | 24 | static int qla2x00_setup_chip(scsi_qla_host_t *); |
1da177e4 LT |
25 | static int qla2x00_init_rings(scsi_qla_host_t *); |
26 | static int qla2x00_fw_ready(scsi_qla_host_t *); | |
27 | static int qla2x00_configure_hba(scsi_qla_host_t *); | |
1da177e4 LT |
28 | static int qla2x00_configure_loop(scsi_qla_host_t *); |
29 | static int qla2x00_configure_local_loop(scsi_qla_host_t *); | |
1da177e4 LT |
30 | static int qla2x00_configure_fabric(scsi_qla_host_t *); |
31 | static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *); | |
32 | static int qla2x00_device_resync(scsi_qla_host_t *); | |
33 | static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *, | |
34 | uint16_t *); | |
1da177e4 LT |
35 | |
36 | static int qla2x00_restart_isp(scsi_qla_host_t *); | |
1da177e4 | 37 | |
e315cd28 | 38 | static int qla2x00_find_new_loop_id(scsi_qla_host_t *, fc_port_t *); |
413975a0 | 39 | |
4d4df193 HK |
40 | static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *); |
41 | static int qla84xx_init_chip(scsi_qla_host_t *); | |
73208dfd | 42 | static int qla25xx_init_queues(struct qla_hw_data *); |
4d4df193 | 43 | |
ac280b67 AV |
44 | /* SRB Extensions ---------------------------------------------------------- */ |
45 | ||
46 | static void | |
47 | qla2x00_ctx_sp_timeout(unsigned long __data) | |
48 | { | |
49 | srb_t *sp = (srb_t *)__data; | |
50 | struct srb_ctx *ctx; | |
4916392b | 51 | struct srb_iocb *iocb; |
ac280b67 AV |
52 | fc_port_t *fcport = sp->fcport; |
53 | struct qla_hw_data *ha = fcport->vha->hw; | |
54 | struct req_que *req; | |
55 | unsigned long flags; | |
56 | ||
57 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
58 | req = ha->req_q_map[0]; | |
59 | req->outstanding_cmds[sp->handle] = NULL; | |
60 | ctx = sp->ctx; | |
4916392b MI |
61 | iocb = ctx->u.iocb_cmd; |
62 | iocb->timeout(sp); | |
4916392b | 63 | iocb->free(sp); |
6ac52608 | 64 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
ac280b67 AV |
65 | } |
66 | ||
3dbe756a | 67 | static void |
ac280b67 AV |
68 | qla2x00_ctx_sp_free(srb_t *sp) |
69 | { | |
70 | struct srb_ctx *ctx = sp->ctx; | |
4916392b | 71 | struct srb_iocb *iocb = ctx->u.iocb_cmd; |
feafb7b1 | 72 | struct scsi_qla_host *vha = sp->fcport->vha; |
ac280b67 | 73 | |
4d97cc53 | 74 | del_timer(&iocb->timer); |
4916392b | 75 | kfree(iocb); |
ac280b67 AV |
76 | kfree(ctx); |
77 | mempool_free(sp, sp->fcport->vha->hw->srb_mempool); | |
feafb7b1 AE |
78 | |
79 | QLA_VHA_MARK_NOT_BUSY(vha); | |
ac280b67 AV |
80 | } |
81 | ||
82 | inline srb_t * | |
83 | qla2x00_get_ctx_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size, | |
84 | unsigned long tmo) | |
85 | { | |
feafb7b1 | 86 | srb_t *sp = NULL; |
ac280b67 AV |
87 | struct qla_hw_data *ha = vha->hw; |
88 | struct srb_ctx *ctx; | |
4916392b | 89 | struct srb_iocb *iocb; |
feafb7b1 AE |
90 | uint8_t bail; |
91 | ||
92 | QLA_VHA_MARK_BUSY(vha, bail); | |
93 | if (bail) | |
94 | return NULL; | |
ac280b67 AV |
95 | |
96 | sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL); | |
97 | if (!sp) | |
98 | goto done; | |
99 | ctx = kzalloc(size, GFP_KERNEL); | |
100 | if (!ctx) { | |
101 | mempool_free(sp, ha->srb_mempool); | |
4916392b MI |
102 | sp = NULL; |
103 | goto done; | |
104 | } | |
105 | iocb = kzalloc(sizeof(struct srb_iocb), GFP_KERNEL); | |
106 | if (!iocb) { | |
107 | mempool_free(sp, ha->srb_mempool); | |
108 | sp = NULL; | |
109 | kfree(ctx); | |
ac280b67 AV |
110 | goto done; |
111 | } | |
112 | ||
113 | memset(sp, 0, sizeof(*sp)); | |
114 | sp->fcport = fcport; | |
115 | sp->ctx = ctx; | |
4916392b MI |
116 | ctx->u.iocb_cmd = iocb; |
117 | iocb->free = qla2x00_ctx_sp_free; | |
ac280b67 | 118 | |
4916392b | 119 | init_timer(&iocb->timer); |
ac280b67 AV |
120 | if (!tmo) |
121 | goto done; | |
4916392b MI |
122 | iocb->timer.expires = jiffies + tmo * HZ; |
123 | iocb->timer.data = (unsigned long)sp; | |
124 | iocb->timer.function = qla2x00_ctx_sp_timeout; | |
125 | add_timer(&iocb->timer); | |
ac280b67 | 126 | done: |
feafb7b1 AE |
127 | if (!sp) |
128 | QLA_VHA_MARK_NOT_BUSY(vha); | |
ac280b67 AV |
129 | return sp; |
130 | } | |
131 | ||
132 | /* Asynchronous Login/Logout Routines -------------------------------------- */ | |
133 | ||
5b91490e AV |
134 | static inline unsigned long |
135 | qla2x00_get_async_timeout(struct scsi_qla_host *vha) | |
136 | { | |
137 | unsigned long tmo; | |
138 | struct qla_hw_data *ha = vha->hw; | |
139 | ||
140 | /* Firmware should use switch negotiated r_a_tov for timeout. */ | |
141 | tmo = ha->r_a_tov / 10 * 2; | |
142 | if (!IS_FWI2_CAPABLE(ha)) { | |
143 | /* | |
144 | * Except for earlier ISPs where the timeout is seeded from the | |
145 | * initialization control block. | |
146 | */ | |
147 | tmo = ha->login_timeout; | |
148 | } | |
149 | return tmo; | |
150 | } | |
ac280b67 AV |
151 | |
152 | static void | |
3822263e | 153 | qla2x00_async_iocb_timeout(srb_t *sp) |
ac280b67 AV |
154 | { |
155 | fc_port_t *fcport = sp->fcport; | |
4916392b | 156 | struct srb_ctx *ctx = sp->ctx; |
ac280b67 AV |
157 | |
158 | DEBUG2(printk(KERN_WARNING | |
d3fa9e7d AV |
159 | "scsi(%ld:%x): Async-%s timeout - portid=%02x%02x%02x.\n", |
160 | fcport->vha->host_no, sp->handle, | |
161 | ctx->name, fcport->d_id.b.domain, | |
162 | fcport->d_id.b.area, fcport->d_id.b.al_pa)); | |
ac280b67 | 163 | |
5ff1d584 | 164 | fcport->flags &= ~FCF_ASYNC_SENT; |
6ac52608 AV |
165 | if (ctx->type == SRB_LOGIN_CMD) { |
166 | struct srb_iocb *lio = ctx->u.iocb_cmd; | |
ac280b67 | 167 | qla2x00_post_async_logout_work(fcport->vha, fcport, NULL); |
6ac52608 AV |
168 | /* Retry as needed. */ |
169 | lio->u.logio.data[0] = MBS_COMMAND_ERROR; | |
170 | lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ? | |
171 | QLA_LOGIO_LOGIN_RETRIED : 0; | |
172 | qla2x00_post_async_login_done_work(fcport->vha, fcport, | |
173 | lio->u.logio.data); | |
174 | } | |
ac280b67 AV |
175 | } |
176 | ||
99b0bec7 AV |
177 | static void |
178 | qla2x00_async_login_ctx_done(srb_t *sp) | |
179 | { | |
4916392b MI |
180 | struct srb_ctx *ctx = sp->ctx; |
181 | struct srb_iocb *lio = ctx->u.iocb_cmd; | |
99b0bec7 AV |
182 | |
183 | qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport, | |
4916392b MI |
184 | lio->u.logio.data); |
185 | lio->free(sp); | |
99b0bec7 AV |
186 | } |
187 | ||
ac280b67 AV |
188 | int |
189 | qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport, | |
190 | uint16_t *data) | |
191 | { | |
ac280b67 | 192 | srb_t *sp; |
4916392b MI |
193 | struct srb_ctx *ctx; |
194 | struct srb_iocb *lio; | |
ac280b67 AV |
195 | int rval; |
196 | ||
197 | rval = QLA_FUNCTION_FAILED; | |
4916392b | 198 | sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx), |
5b91490e | 199 | qla2x00_get_async_timeout(vha) + 2); |
ac280b67 AV |
200 | if (!sp) |
201 | goto done; | |
202 | ||
4916392b MI |
203 | ctx = sp->ctx; |
204 | ctx->type = SRB_LOGIN_CMD; | |
205 | ctx->name = "login"; | |
206 | lio = ctx->u.iocb_cmd; | |
3822263e | 207 | lio->timeout = qla2x00_async_iocb_timeout; |
4916392b MI |
208 | lio->done = qla2x00_async_login_ctx_done; |
209 | lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI; | |
ac280b67 | 210 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
4916392b | 211 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
ac280b67 AV |
212 | rval = qla2x00_start_sp(sp); |
213 | if (rval != QLA_SUCCESS) | |
214 | goto done_free_sp; | |
215 | ||
216 | DEBUG2(printk(KERN_DEBUG | |
217 | "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x " | |
218 | "retries=%d.\n", fcport->vha->host_no, sp->handle, fcport->loop_id, | |
219 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa, | |
220 | fcport->login_retry)); | |
221 | return rval; | |
222 | ||
223 | done_free_sp: | |
4916392b | 224 | lio->free(sp); |
ac280b67 AV |
225 | done: |
226 | return rval; | |
227 | } | |
228 | ||
99b0bec7 AV |
229 | static void |
230 | qla2x00_async_logout_ctx_done(srb_t *sp) | |
231 | { | |
4916392b MI |
232 | struct srb_ctx *ctx = sp->ctx; |
233 | struct srb_iocb *lio = ctx->u.iocb_cmd; | |
99b0bec7 AV |
234 | |
235 | qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport, | |
4916392b MI |
236 | lio->u.logio.data); |
237 | lio->free(sp); | |
99b0bec7 AV |
238 | } |
239 | ||
ac280b67 AV |
240 | int |
241 | qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport) | |
242 | { | |
ac280b67 | 243 | srb_t *sp; |
4916392b MI |
244 | struct srb_ctx *ctx; |
245 | struct srb_iocb *lio; | |
ac280b67 AV |
246 | int rval; |
247 | ||
248 | rval = QLA_FUNCTION_FAILED; | |
4916392b | 249 | sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx), |
5b91490e | 250 | qla2x00_get_async_timeout(vha) + 2); |
ac280b67 AV |
251 | if (!sp) |
252 | goto done; | |
253 | ||
4916392b MI |
254 | ctx = sp->ctx; |
255 | ctx->type = SRB_LOGOUT_CMD; | |
256 | ctx->name = "logout"; | |
257 | lio = ctx->u.iocb_cmd; | |
3822263e | 258 | lio->timeout = qla2x00_async_iocb_timeout; |
4916392b | 259 | lio->done = qla2x00_async_logout_ctx_done; |
ac280b67 AV |
260 | rval = qla2x00_start_sp(sp); |
261 | if (rval != QLA_SUCCESS) | |
262 | goto done_free_sp; | |
263 | ||
264 | DEBUG2(printk(KERN_DEBUG | |
265 | "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n", | |
266 | fcport->vha->host_no, sp->handle, fcport->loop_id, | |
267 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa)); | |
268 | return rval; | |
269 | ||
270 | done_free_sp: | |
4916392b | 271 | lio->free(sp); |
ac280b67 AV |
272 | done: |
273 | return rval; | |
274 | } | |
275 | ||
5ff1d584 AV |
276 | static void |
277 | qla2x00_async_adisc_ctx_done(srb_t *sp) | |
278 | { | |
4916392b MI |
279 | struct srb_ctx *ctx = sp->ctx; |
280 | struct srb_iocb *lio = ctx->u.iocb_cmd; | |
5ff1d584 AV |
281 | |
282 | qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport, | |
4916392b MI |
283 | lio->u.logio.data); |
284 | lio->free(sp); | |
5ff1d584 AV |
285 | } |
286 | ||
287 | int | |
288 | qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport, | |
289 | uint16_t *data) | |
290 | { | |
5ff1d584 | 291 | srb_t *sp; |
4916392b MI |
292 | struct srb_ctx *ctx; |
293 | struct srb_iocb *lio; | |
5ff1d584 AV |
294 | int rval; |
295 | ||
296 | rval = QLA_FUNCTION_FAILED; | |
4916392b | 297 | sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx), |
5b91490e | 298 | qla2x00_get_async_timeout(vha) + 2); |
5ff1d584 AV |
299 | if (!sp) |
300 | goto done; | |
301 | ||
4916392b MI |
302 | ctx = sp->ctx; |
303 | ctx->type = SRB_ADISC_CMD; | |
304 | ctx->name = "adisc"; | |
305 | lio = ctx->u.iocb_cmd; | |
3822263e | 306 | lio->timeout = qla2x00_async_iocb_timeout; |
4916392b | 307 | lio->done = qla2x00_async_adisc_ctx_done; |
5ff1d584 | 308 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
4916392b | 309 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
5ff1d584 AV |
310 | rval = qla2x00_start_sp(sp); |
311 | if (rval != QLA_SUCCESS) | |
312 | goto done_free_sp; | |
313 | ||
314 | DEBUG2(printk(KERN_DEBUG | |
315 | "scsi(%ld:%x): Async-adisc - loop-id=%x portid=%02x%02x%02x.\n", | |
316 | fcport->vha->host_no, sp->handle, fcport->loop_id, | |
317 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa)); | |
318 | ||
319 | return rval; | |
320 | ||
321 | done_free_sp: | |
4916392b | 322 | lio->free(sp); |
5ff1d584 AV |
323 | done: |
324 | return rval; | |
325 | } | |
326 | ||
3822263e MI |
327 | static void |
328 | qla2x00_async_tm_cmd_ctx_done(srb_t *sp) | |
329 | { | |
330 | struct srb_ctx *ctx = sp->ctx; | |
331 | struct srb_iocb *iocb = (struct srb_iocb *)ctx->u.iocb_cmd; | |
332 | ||
333 | qla2x00_async_tm_cmd_done(sp->fcport->vha, sp->fcport, iocb); | |
334 | iocb->free(sp); | |
335 | } | |
336 | ||
337 | int | |
338 | qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun, | |
339 | uint32_t tag) | |
340 | { | |
341 | struct scsi_qla_host *vha = fcport->vha; | |
3822263e MI |
342 | srb_t *sp; |
343 | struct srb_ctx *ctx; | |
344 | struct srb_iocb *tcf; | |
345 | int rval; | |
346 | ||
347 | rval = QLA_FUNCTION_FAILED; | |
348 | sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx), | |
5b91490e | 349 | qla2x00_get_async_timeout(vha) + 2); |
3822263e MI |
350 | if (!sp) |
351 | goto done; | |
352 | ||
353 | ctx = sp->ctx; | |
354 | ctx->type = SRB_TM_CMD; | |
355 | ctx->name = "tmf"; | |
356 | tcf = ctx->u.iocb_cmd; | |
357 | tcf->u.tmf.flags = flags; | |
358 | tcf->u.tmf.lun = lun; | |
359 | tcf->u.tmf.data = tag; | |
360 | tcf->timeout = qla2x00_async_iocb_timeout; | |
361 | tcf->done = qla2x00_async_tm_cmd_ctx_done; | |
362 | ||
363 | rval = qla2x00_start_sp(sp); | |
364 | if (rval != QLA_SUCCESS) | |
365 | goto done_free_sp; | |
366 | ||
367 | DEBUG2(printk(KERN_DEBUG | |
368 | "scsi(%ld:%x): Async-tmf - loop-id=%x portid=%02x%02x%02x.\n", | |
369 | fcport->vha->host_no, sp->handle, fcport->loop_id, | |
370 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa)); | |
371 | ||
372 | return rval; | |
373 | ||
374 | done_free_sp: | |
375 | tcf->free(sp); | |
376 | done: | |
377 | return rval; | |
378 | } | |
379 | ||
4916392b | 380 | void |
ac280b67 AV |
381 | qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
382 | uint16_t *data) | |
383 | { | |
384 | int rval; | |
ac280b67 AV |
385 | |
386 | switch (data[0]) { | |
387 | case MBS_COMMAND_COMPLETE: | |
99b0bec7 | 388 | if (fcport->flags & FCF_FCP2_DEVICE) { |
5ff1d584 AV |
389 | fcport->flags |= FCF_ASYNC_SENT; |
390 | qla2x00_post_async_adisc_work(vha, fcport, data); | |
391 | break; | |
99b0bec7 AV |
392 | } |
393 | qla2x00_update_fcport(vha, fcport); | |
ac280b67 AV |
394 | break; |
395 | case MBS_COMMAND_ERROR: | |
5ff1d584 | 396 | fcport->flags &= ~FCF_ASYNC_SENT; |
ac280b67 AV |
397 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
398 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); | |
399 | else | |
6ac52608 | 400 | qla2x00_mark_device_lost(vha, fcport, 1, 1); |
ac280b67 AV |
401 | break; |
402 | case MBS_PORT_ID_USED: | |
403 | fcport->loop_id = data[1]; | |
6ac52608 | 404 | qla2x00_post_async_logout_work(vha, fcport, NULL); |
ac280b67 AV |
405 | qla2x00_post_async_login_work(vha, fcport, NULL); |
406 | break; | |
407 | case MBS_LOOP_ID_USED: | |
408 | fcport->loop_id++; | |
409 | rval = qla2x00_find_new_loop_id(vha, fcport); | |
410 | if (rval != QLA_SUCCESS) { | |
5ff1d584 | 411 | fcport->flags &= ~FCF_ASYNC_SENT; |
6ac52608 | 412 | qla2x00_mark_device_lost(vha, fcport, 1, 1); |
ac280b67 AV |
413 | break; |
414 | } | |
415 | qla2x00_post_async_login_work(vha, fcport, NULL); | |
416 | break; | |
417 | } | |
4916392b | 418 | return; |
ac280b67 AV |
419 | } |
420 | ||
4916392b | 421 | void |
ac280b67 AV |
422 | qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
423 | uint16_t *data) | |
424 | { | |
425 | qla2x00_mark_device_lost(vha, fcport, 1, 0); | |
4916392b | 426 | return; |
ac280b67 AV |
427 | } |
428 | ||
4916392b | 429 | void |
5ff1d584 AV |
430 | qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
431 | uint16_t *data) | |
432 | { | |
433 | if (data[0] == MBS_COMMAND_COMPLETE) { | |
434 | qla2x00_update_fcport(vha, fcport); | |
435 | ||
4916392b | 436 | return; |
5ff1d584 AV |
437 | } |
438 | ||
439 | /* Retry login. */ | |
440 | fcport->flags &= ~FCF_ASYNC_SENT; | |
441 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) | |
442 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); | |
443 | else | |
6ac52608 | 444 | qla2x00_mark_device_lost(vha, fcport, 1, 1); |
5ff1d584 | 445 | |
4916392b | 446 | return; |
5ff1d584 AV |
447 | } |
448 | ||
3822263e MI |
449 | void |
450 | qla2x00_async_tm_cmd_done(struct scsi_qla_host *vha, fc_port_t *fcport, | |
451 | struct srb_iocb *iocb) | |
452 | { | |
453 | int rval; | |
454 | uint32_t flags; | |
455 | uint16_t lun; | |
456 | ||
457 | flags = iocb->u.tmf.flags; | |
458 | lun = (uint16_t)iocb->u.tmf.lun; | |
459 | ||
460 | /* Issue Marker IOCB */ | |
d94d10e7 GM |
461 | rval = qla2x00_marker(vha, vha->hw->req_q_map[0], |
462 | vha->hw->rsp_q_map[0], fcport->loop_id, lun, | |
3822263e MI |
463 | flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID); |
464 | ||
465 | if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) { | |
466 | DEBUG2_3_11(printk(KERN_WARNING | |
467 | "%s(%ld): TM IOCB failed (%x).\n", | |
468 | __func__, vha->host_no, rval)); | |
469 | } | |
470 | ||
471 | return; | |
472 | } | |
473 | ||
1da177e4 LT |
474 | /****************************************************************************/ |
475 | /* QLogic ISP2x00 Hardware Support Functions. */ | |
476 | /****************************************************************************/ | |
477 | ||
478 | /* | |
479 | * qla2x00_initialize_adapter | |
480 | * Initialize board. | |
481 | * | |
482 | * Input: | |
483 | * ha = adapter block pointer. | |
484 | * | |
485 | * Returns: | |
486 | * 0 = success | |
487 | */ | |
488 | int | |
e315cd28 | 489 | qla2x00_initialize_adapter(scsi_qla_host_t *vha) |
1da177e4 LT |
490 | { |
491 | int rval; | |
e315cd28 | 492 | struct qla_hw_data *ha = vha->hw; |
73208dfd | 493 | struct req_que *req = ha->req_q_map[0]; |
2533cf67 | 494 | |
1da177e4 | 495 | /* Clear adapter flags. */ |
e315cd28 | 496 | vha->flags.online = 0; |
2533cf67 | 497 | ha->flags.chip_reset_done = 0; |
e315cd28 | 498 | vha->flags.reset_active = 0; |
85880801 AV |
499 | ha->flags.pci_channel_io_perm_failure = 0; |
500 | ha->flags.eeh_busy = 0; | |
794a5691 | 501 | ha->flags.thermal_supported = 1; |
e315cd28 AC |
502 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
503 | atomic_set(&vha->loop_state, LOOP_DOWN); | |
504 | vha->device_flags = DFLG_NO_CABLE; | |
505 | vha->dpc_flags = 0; | |
506 | vha->flags.management_server_logged_in = 0; | |
507 | vha->marker_needed = 0; | |
1da177e4 LT |
508 | ha->isp_abort_cnt = 0; |
509 | ha->beacon_blink_led = 0; | |
510 | ||
73208dfd AC |
511 | set_bit(0, ha->req_qid_map); |
512 | set_bit(0, ha->rsp_qid_map); | |
513 | ||
0107109e | 514 | qla_printk(KERN_INFO, ha, "Configuring PCI space...\n"); |
e315cd28 | 515 | rval = ha->isp_ops->pci_config(vha); |
1da177e4 | 516 | if (rval) { |
7c98a046 | 517 | DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n", |
e315cd28 | 518 | vha->host_no)); |
1da177e4 LT |
519 | return (rval); |
520 | } | |
521 | ||
e315cd28 | 522 | ha->isp_ops->reset_chip(vha); |
1da177e4 | 523 | |
e315cd28 | 524 | rval = qla2xxx_get_flash_info(vha); |
c00d8994 AV |
525 | if (rval) { |
526 | DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n", | |
e315cd28 | 527 | vha->host_no)); |
c00d8994 AV |
528 | return (rval); |
529 | } | |
530 | ||
73208dfd | 531 | ha->isp_ops->get_flash_version(vha, req->ring); |
30c47662 | 532 | |
1da177e4 | 533 | qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n"); |
0107109e | 534 | |
e315cd28 | 535 | ha->isp_ops->nvram_config(vha); |
1da177e4 | 536 | |
d4c760c2 AV |
537 | if (ha->flags.disable_serdes) { |
538 | /* Mask HBA via NVRAM settings? */ | |
539 | qla_printk(KERN_INFO, ha, "Masking HBA WWPN " | |
540 | "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n", | |
e315cd28 AC |
541 | vha->port_name[0], vha->port_name[1], |
542 | vha->port_name[2], vha->port_name[3], | |
543 | vha->port_name[4], vha->port_name[5], | |
544 | vha->port_name[6], vha->port_name[7]); | |
d4c760c2 AV |
545 | return QLA_FUNCTION_FAILED; |
546 | } | |
547 | ||
1da177e4 LT |
548 | qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n"); |
549 | ||
e315cd28 AC |
550 | if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) { |
551 | rval = ha->isp_ops->chip_diag(vha); | |
d19044c3 AV |
552 | if (rval) |
553 | return (rval); | |
e315cd28 | 554 | rval = qla2x00_setup_chip(vha); |
d19044c3 AV |
555 | if (rval) |
556 | return (rval); | |
1da177e4 | 557 | } |
a9083016 | 558 | |
4d4df193 | 559 | if (IS_QLA84XX(ha)) { |
e315cd28 | 560 | ha->cs84xx = qla84xx_get_chip(vha); |
4d4df193 HK |
561 | if (!ha->cs84xx) { |
562 | qla_printk(KERN_ERR, ha, | |
563 | "Unable to configure ISP84XX.\n"); | |
564 | return QLA_FUNCTION_FAILED; | |
565 | } | |
566 | } | |
e315cd28 | 567 | rval = qla2x00_init_rings(vha); |
2533cf67 | 568 | ha->flags.chip_reset_done = 1; |
1da177e4 | 569 | |
9a069e19 | 570 | if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) { |
6c452a45 | 571 | /* Issue verify 84xx FW IOCB to complete 84xx initialization */ |
9a069e19 GM |
572 | rval = qla84xx_init_chip(vha); |
573 | if (rval != QLA_SUCCESS) { | |
574 | qla_printk(KERN_ERR, ha, | |
575 | "Unable to initialize ISP84XX.\n"); | |
576 | qla84xx_put_chip(vha); | |
577 | } | |
578 | } | |
579 | ||
2f0f3f4f MI |
580 | if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) |
581 | qla24xx_read_fcp_prio_cfg(vha); | |
09ff701a | 582 | |
1da177e4 LT |
583 | return (rval); |
584 | } | |
585 | ||
586 | /** | |
abbd8870 | 587 | * qla2100_pci_config() - Setup ISP21xx PCI configuration registers. |
1da177e4 LT |
588 | * @ha: HA context |
589 | * | |
590 | * Returns 0 on success. | |
591 | */ | |
abbd8870 | 592 | int |
e315cd28 | 593 | qla2100_pci_config(scsi_qla_host_t *vha) |
1da177e4 | 594 | { |
a157b101 | 595 | uint16_t w; |
abbd8870 | 596 | unsigned long flags; |
e315cd28 | 597 | struct qla_hw_data *ha = vha->hw; |
3d71644c | 598 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
1da177e4 | 599 | |
1da177e4 | 600 | pci_set_master(ha->pdev); |
af6177d8 | 601 | pci_try_set_mwi(ha->pdev); |
1da177e4 | 602 | |
1da177e4 | 603 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
a157b101 | 604 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
abbd8870 AV |
605 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
606 | ||
737faece | 607 | pci_disable_rom(ha->pdev); |
1da177e4 LT |
608 | |
609 | /* Get PCI bus information. */ | |
610 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
3d71644c | 611 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
1da177e4 LT |
612 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
613 | ||
abbd8870 AV |
614 | return QLA_SUCCESS; |
615 | } | |
1da177e4 | 616 | |
abbd8870 AV |
617 | /** |
618 | * qla2300_pci_config() - Setup ISP23xx PCI configuration registers. | |
619 | * @ha: HA context | |
620 | * | |
621 | * Returns 0 on success. | |
622 | */ | |
623 | int | |
e315cd28 | 624 | qla2300_pci_config(scsi_qla_host_t *vha) |
abbd8870 | 625 | { |
a157b101 | 626 | uint16_t w; |
abbd8870 AV |
627 | unsigned long flags = 0; |
628 | uint32_t cnt; | |
e315cd28 | 629 | struct qla_hw_data *ha = vha->hw; |
3d71644c | 630 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
1da177e4 | 631 | |
abbd8870 | 632 | pci_set_master(ha->pdev); |
af6177d8 | 633 | pci_try_set_mwi(ha->pdev); |
1da177e4 | 634 | |
abbd8870 | 635 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
a157b101 | 636 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
1da177e4 | 637 | |
abbd8870 AV |
638 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
639 | w &= ~PCI_COMMAND_INTX_DISABLE; | |
a157b101 | 640 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
1da177e4 | 641 | |
abbd8870 AV |
642 | /* |
643 | * If this is a 2300 card and not 2312, reset the | |
644 | * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately, | |
645 | * the 2310 also reports itself as a 2300 so we need to get the | |
646 | * fb revision level -- a 6 indicates it really is a 2300 and | |
647 | * not a 2310. | |
648 | */ | |
649 | if (IS_QLA2300(ha)) { | |
650 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
1da177e4 | 651 | |
abbd8870 | 652 | /* Pause RISC. */ |
3d71644c | 653 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
abbd8870 | 654 | for (cnt = 0; cnt < 30000; cnt++) { |
3d71644c | 655 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0) |
abbd8870 | 656 | break; |
1da177e4 | 657 | |
abbd8870 AV |
658 | udelay(10); |
659 | } | |
1da177e4 | 660 | |
abbd8870 | 661 | /* Select FPM registers. */ |
3d71644c AV |
662 | WRT_REG_WORD(®->ctrl_status, 0x20); |
663 | RD_REG_WORD(®->ctrl_status); | |
abbd8870 AV |
664 | |
665 | /* Get the fb rev level */ | |
3d71644c | 666 | ha->fb_rev = RD_FB_CMD_REG(ha, reg); |
abbd8870 AV |
667 | |
668 | if (ha->fb_rev == FPM_2300) | |
a157b101 | 669 | pci_clear_mwi(ha->pdev); |
abbd8870 AV |
670 | |
671 | /* Deselect FPM registers. */ | |
3d71644c AV |
672 | WRT_REG_WORD(®->ctrl_status, 0x0); |
673 | RD_REG_WORD(®->ctrl_status); | |
abbd8870 AV |
674 | |
675 | /* Release RISC module. */ | |
3d71644c | 676 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
abbd8870 | 677 | for (cnt = 0; cnt < 30000; cnt++) { |
3d71644c | 678 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0) |
abbd8870 AV |
679 | break; |
680 | ||
681 | udelay(10); | |
1da177e4 | 682 | } |
1da177e4 | 683 | |
abbd8870 AV |
684 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
685 | } | |
1da177e4 | 686 | |
abbd8870 AV |
687 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
688 | ||
737faece | 689 | pci_disable_rom(ha->pdev); |
1da177e4 | 690 | |
abbd8870 AV |
691 | /* Get PCI bus information. */ |
692 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
3d71644c | 693 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
abbd8870 AV |
694 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
695 | ||
696 | return QLA_SUCCESS; | |
1da177e4 LT |
697 | } |
698 | ||
0107109e AV |
699 | /** |
700 | * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers. | |
701 | * @ha: HA context | |
702 | * | |
703 | * Returns 0 on success. | |
704 | */ | |
705 | int | |
e315cd28 | 706 | qla24xx_pci_config(scsi_qla_host_t *vha) |
0107109e | 707 | { |
a157b101 | 708 | uint16_t w; |
0107109e | 709 | unsigned long flags = 0; |
e315cd28 | 710 | struct qla_hw_data *ha = vha->hw; |
0107109e | 711 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
0107109e AV |
712 | |
713 | pci_set_master(ha->pdev); | |
af6177d8 | 714 | pci_try_set_mwi(ha->pdev); |
0107109e AV |
715 | |
716 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); | |
a157b101 | 717 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
0107109e AV |
718 | w &= ~PCI_COMMAND_INTX_DISABLE; |
719 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); | |
720 | ||
721 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); | |
722 | ||
723 | /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */ | |
f85ec187 AV |
724 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX)) |
725 | pcix_set_mmrbc(ha->pdev, 2048); | |
0107109e AV |
726 | |
727 | /* PCIe -- adjust Maximum Read Request Size (2048). */ | |
f85ec187 AV |
728 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP)) |
729 | pcie_set_readrq(ha->pdev, 2048); | |
0107109e | 730 | |
737faece | 731 | pci_disable_rom(ha->pdev); |
0107109e | 732 | |
44c10138 | 733 | ha->chip_revision = ha->pdev->revision; |
a8488abe | 734 | |
0107109e AV |
735 | /* Get PCI bus information. */ |
736 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
737 | ha->pci_attr = RD_REG_DWORD(®->ctrl_status); | |
738 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
739 | ||
740 | return QLA_SUCCESS; | |
741 | } | |
742 | ||
c3a2f0df AV |
743 | /** |
744 | * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers. | |
745 | * @ha: HA context | |
746 | * | |
747 | * Returns 0 on success. | |
748 | */ | |
749 | int | |
e315cd28 | 750 | qla25xx_pci_config(scsi_qla_host_t *vha) |
c3a2f0df AV |
751 | { |
752 | uint16_t w; | |
e315cd28 | 753 | struct qla_hw_data *ha = vha->hw; |
c3a2f0df AV |
754 | |
755 | pci_set_master(ha->pdev); | |
756 | pci_try_set_mwi(ha->pdev); | |
757 | ||
758 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); | |
759 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); | |
760 | w &= ~PCI_COMMAND_INTX_DISABLE; | |
761 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); | |
762 | ||
763 | /* PCIe -- adjust Maximum Read Request Size (2048). */ | |
764 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP)) | |
765 | pcie_set_readrq(ha->pdev, 2048); | |
766 | ||
737faece | 767 | pci_disable_rom(ha->pdev); |
c3a2f0df AV |
768 | |
769 | ha->chip_revision = ha->pdev->revision; | |
770 | ||
771 | return QLA_SUCCESS; | |
772 | } | |
773 | ||
1da177e4 LT |
774 | /** |
775 | * qla2x00_isp_firmware() - Choose firmware image. | |
776 | * @ha: HA context | |
777 | * | |
778 | * Returns 0 on success. | |
779 | */ | |
780 | static int | |
e315cd28 | 781 | qla2x00_isp_firmware(scsi_qla_host_t *vha) |
1da177e4 LT |
782 | { |
783 | int rval; | |
42e421b1 AV |
784 | uint16_t loop_id, topo, sw_cap; |
785 | uint8_t domain, area, al_pa; | |
e315cd28 | 786 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
787 | |
788 | /* Assume loading risc code */ | |
fa2a1ce5 | 789 | rval = QLA_FUNCTION_FAILED; |
1da177e4 LT |
790 | |
791 | if (ha->flags.disable_risc_code_load) { | |
792 | DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n", | |
e315cd28 | 793 | vha->host_no)); |
1da177e4 LT |
794 | qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n"); |
795 | ||
796 | /* Verify checksum of loaded RISC code. */ | |
e315cd28 | 797 | rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address); |
42e421b1 AV |
798 | if (rval == QLA_SUCCESS) { |
799 | /* And, verify we are not in ROM code. */ | |
e315cd28 | 800 | rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa, |
42e421b1 AV |
801 | &area, &domain, &topo, &sw_cap); |
802 | } | |
1da177e4 LT |
803 | } |
804 | ||
805 | if (rval) { | |
806 | DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n", | |
e315cd28 | 807 | vha->host_no)); |
1da177e4 LT |
808 | } |
809 | ||
810 | return (rval); | |
811 | } | |
812 | ||
813 | /** | |
814 | * qla2x00_reset_chip() - Reset ISP chip. | |
815 | * @ha: HA context | |
816 | * | |
817 | * Returns 0 on success. | |
818 | */ | |
abbd8870 | 819 | void |
e315cd28 | 820 | qla2x00_reset_chip(scsi_qla_host_t *vha) |
1da177e4 LT |
821 | { |
822 | unsigned long flags = 0; | |
e315cd28 | 823 | struct qla_hw_data *ha = vha->hw; |
3d71644c | 824 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
1da177e4 | 825 | uint32_t cnt; |
1da177e4 LT |
826 | uint16_t cmd; |
827 | ||
85880801 AV |
828 | if (unlikely(pci_channel_offline(ha->pdev))) |
829 | return; | |
830 | ||
fd34f556 | 831 | ha->isp_ops->disable_intrs(ha); |
1da177e4 LT |
832 | |
833 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
834 | ||
835 | /* Turn off master enable */ | |
836 | cmd = 0; | |
837 | pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd); | |
838 | cmd &= ~PCI_COMMAND_MASTER; | |
839 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); | |
840 | ||
841 | if (!IS_QLA2100(ha)) { | |
842 | /* Pause RISC. */ | |
843 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); | |
844 | if (IS_QLA2200(ha) || IS_QLA2300(ha)) { | |
845 | for (cnt = 0; cnt < 30000; cnt++) { | |
846 | if ((RD_REG_WORD(®->hccr) & | |
847 | HCCR_RISC_PAUSE) != 0) | |
848 | break; | |
849 | udelay(100); | |
850 | } | |
851 | } else { | |
852 | RD_REG_WORD(®->hccr); /* PCI Posting. */ | |
853 | udelay(10); | |
854 | } | |
855 | ||
856 | /* Select FPM registers. */ | |
857 | WRT_REG_WORD(®->ctrl_status, 0x20); | |
858 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ | |
859 | ||
860 | /* FPM Soft Reset. */ | |
861 | WRT_REG_WORD(®->fpm_diag_config, 0x100); | |
862 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ | |
863 | ||
864 | /* Toggle Fpm Reset. */ | |
865 | if (!IS_QLA2200(ha)) { | |
866 | WRT_REG_WORD(®->fpm_diag_config, 0x0); | |
867 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ | |
868 | } | |
869 | ||
870 | /* Select frame buffer registers. */ | |
871 | WRT_REG_WORD(®->ctrl_status, 0x10); | |
872 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ | |
873 | ||
874 | /* Reset frame buffer FIFOs. */ | |
875 | if (IS_QLA2200(ha)) { | |
876 | WRT_FB_CMD_REG(ha, reg, 0xa000); | |
877 | RD_FB_CMD_REG(ha, reg); /* PCI Posting. */ | |
878 | } else { | |
879 | WRT_FB_CMD_REG(ha, reg, 0x00fc); | |
880 | ||
881 | /* Read back fb_cmd until zero or 3 seconds max */ | |
882 | for (cnt = 0; cnt < 3000; cnt++) { | |
883 | if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0) | |
884 | break; | |
885 | udelay(100); | |
886 | } | |
887 | } | |
888 | ||
889 | /* Select RISC module registers. */ | |
890 | WRT_REG_WORD(®->ctrl_status, 0); | |
891 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ | |
892 | ||
893 | /* Reset RISC processor. */ | |
894 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); | |
895 | RD_REG_WORD(®->hccr); /* PCI Posting. */ | |
896 | ||
897 | /* Release RISC processor. */ | |
898 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); | |
899 | RD_REG_WORD(®->hccr); /* PCI Posting. */ | |
900 | } | |
901 | ||
902 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); | |
903 | WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT); | |
904 | ||
905 | /* Reset ISP chip. */ | |
906 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); | |
907 | ||
908 | /* Wait for RISC to recover from reset. */ | |
909 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { | |
910 | /* | |
911 | * It is necessary to for a delay here since the card doesn't | |
912 | * respond to PCI reads during a reset. On some architectures | |
913 | * this will result in an MCA. | |
914 | */ | |
915 | udelay(20); | |
916 | for (cnt = 30000; cnt; cnt--) { | |
917 | if ((RD_REG_WORD(®->ctrl_status) & | |
918 | CSR_ISP_SOFT_RESET) == 0) | |
919 | break; | |
920 | udelay(100); | |
921 | } | |
922 | } else | |
923 | udelay(10); | |
924 | ||
925 | /* Reset RISC processor. */ | |
926 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); | |
927 | ||
928 | WRT_REG_WORD(®->semaphore, 0); | |
929 | ||
930 | /* Release RISC processor. */ | |
931 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); | |
932 | RD_REG_WORD(®->hccr); /* PCI Posting. */ | |
933 | ||
934 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { | |
935 | for (cnt = 0; cnt < 30000; cnt++) { | |
ffb39f03 | 936 | if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) |
1da177e4 | 937 | break; |
1da177e4 LT |
938 | |
939 | udelay(100); | |
940 | } | |
941 | } else | |
942 | udelay(100); | |
943 | ||
944 | /* Turn on master enable */ | |
945 | cmd |= PCI_COMMAND_MASTER; | |
946 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); | |
947 | ||
948 | /* Disable RISC pause on FPM parity error. */ | |
949 | if (!IS_QLA2100(ha)) { | |
950 | WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE); | |
951 | RD_REG_WORD(®->hccr); /* PCI Posting. */ | |
952 | } | |
953 | ||
954 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
955 | } | |
956 | ||
b1d46989 MI |
957 | /** |
958 | * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC. | |
959 | * | |
960 | * Returns 0 on success. | |
961 | */ | |
962 | int | |
963 | qla81xx_reset_mpi(scsi_qla_host_t *vha) | |
964 | { | |
965 | uint16_t mb[4] = {0x1010, 0, 1, 0}; | |
966 | ||
967 | return qla81xx_write_mpi_register(vha, mb); | |
968 | } | |
969 | ||
0107109e | 970 | /** |
88c26663 | 971 | * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC. |
0107109e AV |
972 | * @ha: HA context |
973 | * | |
974 | * Returns 0 on success. | |
975 | */ | |
88c26663 | 976 | static inline void |
e315cd28 | 977 | qla24xx_reset_risc(scsi_qla_host_t *vha) |
0107109e AV |
978 | { |
979 | unsigned long flags = 0; | |
e315cd28 | 980 | struct qla_hw_data *ha = vha->hw; |
0107109e AV |
981 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
982 | uint32_t cnt, d2; | |
335a1cc9 | 983 | uint16_t wd; |
b1d46989 | 984 | static int abts_cnt; /* ISP abort retry counts */ |
0107109e | 985 | |
0107109e AV |
986 | spin_lock_irqsave(&ha->hardware_lock, flags); |
987 | ||
988 | /* Reset RISC. */ | |
989 | WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); | |
990 | for (cnt = 0; cnt < 30000; cnt++) { | |
991 | if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0) | |
992 | break; | |
993 | ||
994 | udelay(10); | |
995 | } | |
996 | ||
997 | WRT_REG_DWORD(®->ctrl_status, | |
998 | CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); | |
335a1cc9 | 999 | pci_read_config_word(ha->pdev, PCI_COMMAND, &wd); |
88c26663 | 1000 | |
335a1cc9 | 1001 | udelay(100); |
88c26663 | 1002 | /* Wait for firmware to complete NVRAM accesses. */ |
88c26663 AV |
1003 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
1004 | for (cnt = 10000 ; cnt && d2; cnt--) { | |
1005 | udelay(5); | |
1006 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); | |
1007 | barrier(); | |
1008 | } | |
1009 | ||
335a1cc9 | 1010 | /* Wait for soft-reset to complete. */ |
0107109e AV |
1011 | d2 = RD_REG_DWORD(®->ctrl_status); |
1012 | for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) { | |
1013 | udelay(5); | |
1014 | d2 = RD_REG_DWORD(®->ctrl_status); | |
1015 | barrier(); | |
1016 | } | |
1017 | ||
b1d46989 MI |
1018 | /* If required, do an MPI FW reset now */ |
1019 | if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) { | |
1020 | if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) { | |
1021 | if (++abts_cnt < 5) { | |
1022 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | |
1023 | set_bit(MPI_RESET_NEEDED, &vha->dpc_flags); | |
1024 | } else { | |
1025 | /* | |
1026 | * We exhausted the ISP abort retries. We have to | |
1027 | * set the board offline. | |
1028 | */ | |
1029 | abts_cnt = 0; | |
1030 | vha->flags.online = 0; | |
1031 | } | |
1032 | } | |
1033 | } | |
1034 | ||
0107109e AV |
1035 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
1036 | RD_REG_DWORD(®->hccr); | |
1037 | ||
1038 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); | |
1039 | RD_REG_DWORD(®->hccr); | |
1040 | ||
1041 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET); | |
1042 | RD_REG_DWORD(®->hccr); | |
1043 | ||
1044 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); | |
1045 | for (cnt = 6000000 ; cnt && d2; cnt--) { | |
1046 | udelay(5); | |
1047 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); | |
1048 | barrier(); | |
1049 | } | |
1050 | ||
1051 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
124f85e6 AV |
1052 | |
1053 | if (IS_NOPOLLING_TYPE(ha)) | |
1054 | ha->isp_ops->enable_intrs(ha); | |
0107109e AV |
1055 | } |
1056 | ||
88c26663 AV |
1057 | /** |
1058 | * qla24xx_reset_chip() - Reset ISP24xx chip. | |
1059 | * @ha: HA context | |
1060 | * | |
1061 | * Returns 0 on success. | |
1062 | */ | |
1063 | void | |
e315cd28 | 1064 | qla24xx_reset_chip(scsi_qla_host_t *vha) |
88c26663 | 1065 | { |
e315cd28 | 1066 | struct qla_hw_data *ha = vha->hw; |
85880801 AV |
1067 | |
1068 | if (pci_channel_offline(ha->pdev) && | |
1069 | ha->flags.pci_channel_io_perm_failure) { | |
1070 | return; | |
1071 | } | |
1072 | ||
fd34f556 | 1073 | ha->isp_ops->disable_intrs(ha); |
88c26663 AV |
1074 | |
1075 | /* Perform RISC reset. */ | |
e315cd28 | 1076 | qla24xx_reset_risc(vha); |
88c26663 AV |
1077 | } |
1078 | ||
1da177e4 LT |
1079 | /** |
1080 | * qla2x00_chip_diag() - Test chip for proper operation. | |
1081 | * @ha: HA context | |
1082 | * | |
1083 | * Returns 0 on success. | |
1084 | */ | |
abbd8870 | 1085 | int |
e315cd28 | 1086 | qla2x00_chip_diag(scsi_qla_host_t *vha) |
1da177e4 LT |
1087 | { |
1088 | int rval; | |
e315cd28 | 1089 | struct qla_hw_data *ha = vha->hw; |
3d71644c | 1090 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
1da177e4 LT |
1091 | unsigned long flags = 0; |
1092 | uint16_t data; | |
1093 | uint32_t cnt; | |
1094 | uint16_t mb[5]; | |
73208dfd | 1095 | struct req_que *req = ha->req_q_map[0]; |
1da177e4 LT |
1096 | |
1097 | /* Assume a failed state */ | |
1098 | rval = QLA_FUNCTION_FAILED; | |
1099 | ||
1100 | DEBUG3(printk("scsi(%ld): Testing device at %lx.\n", | |
e315cd28 | 1101 | vha->host_no, (u_long)®->flash_address)); |
1da177e4 LT |
1102 | |
1103 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
1104 | ||
1105 | /* Reset ISP chip. */ | |
1106 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); | |
1107 | ||
1108 | /* | |
1109 | * We need to have a delay here since the card will not respond while | |
1110 | * in reset causing an MCA on some architectures. | |
1111 | */ | |
1112 | udelay(20); | |
1113 | data = qla2x00_debounce_register(®->ctrl_status); | |
1114 | for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) { | |
1115 | udelay(5); | |
1116 | data = RD_REG_WORD(®->ctrl_status); | |
1117 | barrier(); | |
1118 | } | |
1119 | ||
1120 | if (!cnt) | |
1121 | goto chip_diag_failed; | |
1122 | ||
1123 | DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n", | |
7640335e | 1124 | vha->host_no)); |
1da177e4 LT |
1125 | |
1126 | /* Reset RISC processor. */ | |
1127 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); | |
1128 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); | |
1129 | ||
1130 | /* Workaround for QLA2312 PCI parity error */ | |
1131 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { | |
1132 | data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0)); | |
1133 | for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) { | |
1134 | udelay(5); | |
1135 | data = RD_MAILBOX_REG(ha, reg, 0); | |
fa2a1ce5 | 1136 | barrier(); |
1da177e4 LT |
1137 | } |
1138 | } else | |
1139 | udelay(10); | |
1140 | ||
1141 | if (!cnt) | |
1142 | goto chip_diag_failed; | |
1143 | ||
1144 | /* Check product ID of chip */ | |
7640335e | 1145 | DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no)); |
1da177e4 LT |
1146 | |
1147 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); | |
1148 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); | |
1149 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); | |
1150 | mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4)); | |
1151 | if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) || | |
1152 | mb[3] != PROD_ID_3) { | |
1153 | qla_printk(KERN_WARNING, ha, | |
1154 | "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]); | |
1155 | ||
1156 | goto chip_diag_failed; | |
1157 | } | |
1158 | ha->product_id[0] = mb[1]; | |
1159 | ha->product_id[1] = mb[2]; | |
1160 | ha->product_id[2] = mb[3]; | |
1161 | ha->product_id[3] = mb[4]; | |
1162 | ||
1163 | /* Adjust fw RISC transfer size */ | |
73208dfd | 1164 | if (req->length > 1024) |
1da177e4 LT |
1165 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024; |
1166 | else | |
1167 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * | |
73208dfd | 1168 | req->length; |
1da177e4 LT |
1169 | |
1170 | if (IS_QLA2200(ha) && | |
1171 | RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) { | |
1172 | /* Limit firmware transfer size with a 2200A */ | |
1173 | DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n", | |
e315cd28 | 1174 | vha->host_no)); |
1da177e4 | 1175 | |
ea5b6382 | 1176 | ha->device_type |= DT_ISP2200A; |
1da177e4 LT |
1177 | ha->fw_transfer_size = 128; |
1178 | } | |
1179 | ||
1180 | /* Wrap Incoming Mailboxes Test. */ | |
1181 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1182 | ||
e315cd28 AC |
1183 | DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no)); |
1184 | rval = qla2x00_mbx_reg_test(vha); | |
1da177e4 LT |
1185 | if (rval) { |
1186 | DEBUG(printk("scsi(%ld): Failed mailbox send register test\n", | |
e315cd28 | 1187 | vha->host_no)); |
1da177e4 LT |
1188 | qla_printk(KERN_WARNING, ha, |
1189 | "Failed mailbox send register test\n"); | |
1190 | } | |
1191 | else { | |
1192 | /* Flag a successful rval */ | |
1193 | rval = QLA_SUCCESS; | |
1194 | } | |
1195 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
1196 | ||
1197 | chip_diag_failed: | |
1198 | if (rval) | |
1199 | DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED " | |
e315cd28 | 1200 | "****\n", vha->host_no)); |
1da177e4 LT |
1201 | |
1202 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1203 | ||
1204 | return (rval); | |
1205 | } | |
1206 | ||
0107109e AV |
1207 | /** |
1208 | * qla24xx_chip_diag() - Test ISP24xx for proper operation. | |
1209 | * @ha: HA context | |
1210 | * | |
1211 | * Returns 0 on success. | |
1212 | */ | |
1213 | int | |
e315cd28 | 1214 | qla24xx_chip_diag(scsi_qla_host_t *vha) |
0107109e AV |
1215 | { |
1216 | int rval; | |
e315cd28 | 1217 | struct qla_hw_data *ha = vha->hw; |
73208dfd | 1218 | struct req_que *req = ha->req_q_map[0]; |
0107109e | 1219 | |
a9083016 GM |
1220 | if (IS_QLA82XX(ha)) |
1221 | return QLA_SUCCESS; | |
1222 | ||
73208dfd | 1223 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length; |
0107109e | 1224 | |
e315cd28 | 1225 | rval = qla2x00_mbx_reg_test(vha); |
0107109e AV |
1226 | if (rval) { |
1227 | DEBUG(printk("scsi(%ld): Failed mailbox send register test\n", | |
e315cd28 | 1228 | vha->host_no)); |
0107109e AV |
1229 | qla_printk(KERN_WARNING, ha, |
1230 | "Failed mailbox send register test\n"); | |
1231 | } else { | |
1232 | /* Flag a successful rval */ | |
1233 | rval = QLA_SUCCESS; | |
1234 | } | |
1235 | ||
1236 | return rval; | |
1237 | } | |
1238 | ||
a7a167bf | 1239 | void |
e315cd28 | 1240 | qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) |
0107109e | 1241 | { |
a7a167bf AV |
1242 | int rval; |
1243 | uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size, | |
73208dfd | 1244 | eft_size, fce_size, mq_size; |
df613b96 AV |
1245 | dma_addr_t tc_dma; |
1246 | void *tc; | |
e315cd28 | 1247 | struct qla_hw_data *ha = vha->hw; |
73208dfd AC |
1248 | struct req_que *req = ha->req_q_map[0]; |
1249 | struct rsp_que *rsp = ha->rsp_q_map[0]; | |
a7a167bf AV |
1250 | |
1251 | if (ha->fw_dump) { | |
1252 | qla_printk(KERN_WARNING, ha, | |
1253 | "Firmware dump previously allocated.\n"); | |
1254 | return; | |
1255 | } | |
d4e3e04d | 1256 | |
0107109e | 1257 | ha->fw_dumped = 0; |
73208dfd | 1258 | fixed_size = mem_size = eft_size = fce_size = mq_size = 0; |
d4e3e04d | 1259 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
a7a167bf | 1260 | fixed_size = sizeof(struct qla2100_fw_dump); |
d4e3e04d | 1261 | } else if (IS_QLA23XX(ha)) { |
a7a167bf AV |
1262 | fixed_size = offsetof(struct qla2300_fw_dump, data_ram); |
1263 | mem_size = (ha->fw_memory_size - 0x11000 + 1) * | |
1264 | sizeof(uint16_t); | |
e428924c | 1265 | } else if (IS_FWI2_CAPABLE(ha)) { |
3a03eb79 AV |
1266 | if (IS_QLA81XX(ha)) |
1267 | fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem); | |
1268 | else if (IS_QLA25XX(ha)) | |
1269 | fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem); | |
1270 | else | |
1271 | fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem); | |
a7a167bf AV |
1272 | mem_size = (ha->fw_memory_size - 0x100000 + 1) * |
1273 | sizeof(uint32_t); | |
73208dfd AC |
1274 | if (ha->mqenable) |
1275 | mq_size = sizeof(struct qla2xxx_mq_chain); | |
df613b96 | 1276 | /* Allocate memory for Fibre Channel Event Buffer. */ |
3a03eb79 | 1277 | if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)) |
436a7b11 | 1278 | goto try_eft; |
df613b96 AV |
1279 | |
1280 | tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma, | |
1281 | GFP_KERNEL); | |
1282 | if (!tc) { | |
1283 | qla_printk(KERN_WARNING, ha, "Unable to allocate " | |
1284 | "(%d KB) for FCE.\n", FCE_SIZE / 1024); | |
17d98630 | 1285 | goto try_eft; |
df613b96 AV |
1286 | } |
1287 | ||
1288 | memset(tc, 0, FCE_SIZE); | |
e315cd28 | 1289 | rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS, |
df613b96 AV |
1290 | ha->fce_mb, &ha->fce_bufs); |
1291 | if (rval) { | |
1292 | qla_printk(KERN_WARNING, ha, "Unable to initialize " | |
1293 | "FCE (%d).\n", rval); | |
1294 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, | |
1295 | tc_dma); | |
1296 | ha->flags.fce_enabled = 0; | |
17d98630 | 1297 | goto try_eft; |
df613b96 AV |
1298 | } |
1299 | ||
1300 | qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n", | |
1301 | FCE_SIZE / 1024); | |
1302 | ||
7d9dade3 | 1303 | fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE; |
df613b96 AV |
1304 | ha->flags.fce_enabled = 1; |
1305 | ha->fce_dma = tc_dma; | |
1306 | ha->fce = tc; | |
436a7b11 AV |
1307 | try_eft: |
1308 | /* Allocate memory for Extended Trace Buffer. */ | |
1309 | tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma, | |
1310 | GFP_KERNEL); | |
1311 | if (!tc) { | |
1312 | qla_printk(KERN_WARNING, ha, "Unable to allocate " | |
1313 | "(%d KB) for EFT.\n", EFT_SIZE / 1024); | |
1314 | goto cont_alloc; | |
1315 | } | |
1316 | ||
1317 | memset(tc, 0, EFT_SIZE); | |
e315cd28 | 1318 | rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS); |
436a7b11 AV |
1319 | if (rval) { |
1320 | qla_printk(KERN_WARNING, ha, "Unable to initialize " | |
1321 | "EFT (%d).\n", rval); | |
1322 | dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, | |
1323 | tc_dma); | |
1324 | goto cont_alloc; | |
1325 | } | |
1326 | ||
1327 | qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n", | |
1328 | EFT_SIZE / 1024); | |
1329 | ||
1330 | eft_size = EFT_SIZE; | |
1331 | ha->eft_dma = tc_dma; | |
1332 | ha->eft = tc; | |
d4e3e04d | 1333 | } |
a7a167bf | 1334 | cont_alloc: |
73208dfd AC |
1335 | req_q_size = req->length * sizeof(request_t); |
1336 | rsp_q_size = rsp->length * sizeof(response_t); | |
a7a167bf AV |
1337 | |
1338 | dump_size = offsetof(struct qla2xxx_fw_dump, isp); | |
2afa19a9 | 1339 | dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size; |
bb99de67 AV |
1340 | ha->chain_offset = dump_size; |
1341 | dump_size += mq_size + fce_size; | |
d4e3e04d AV |
1342 | |
1343 | ha->fw_dump = vmalloc(dump_size); | |
a7a167bf | 1344 | if (!ha->fw_dump) { |
0107109e | 1345 | qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for " |
d4e3e04d | 1346 | "firmware dump!!!\n", dump_size / 1024); |
a7a167bf | 1347 | |
e30d1756 MI |
1348 | if (ha->fce) { |
1349 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce, | |
1350 | ha->fce_dma); | |
1351 | ha->fce = NULL; | |
1352 | ha->fce_dma = 0; | |
1353 | } | |
1354 | ||
a7a167bf AV |
1355 | if (ha->eft) { |
1356 | dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft, | |
1357 | ha->eft_dma); | |
1358 | ha->eft = NULL; | |
1359 | ha->eft_dma = 0; | |
1360 | } | |
1361 | return; | |
1362 | } | |
a7a167bf AV |
1363 | qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n", |
1364 | dump_size / 1024); | |
1365 | ||
1366 | ha->fw_dump_len = dump_size; | |
1367 | ha->fw_dump->signature[0] = 'Q'; | |
1368 | ha->fw_dump->signature[1] = 'L'; | |
1369 | ha->fw_dump->signature[2] = 'G'; | |
1370 | ha->fw_dump->signature[3] = 'C'; | |
1371 | ha->fw_dump->version = __constant_htonl(1); | |
1372 | ||
1373 | ha->fw_dump->fixed_size = htonl(fixed_size); | |
1374 | ha->fw_dump->mem_size = htonl(mem_size); | |
1375 | ha->fw_dump->req_q_size = htonl(req_q_size); | |
1376 | ha->fw_dump->rsp_q_size = htonl(rsp_q_size); | |
1377 | ||
1378 | ha->fw_dump->eft_size = htonl(eft_size); | |
1379 | ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma)); | |
1380 | ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma)); | |
1381 | ||
1382 | ha->fw_dump->header_size = | |
1383 | htonl(offsetof(struct qla2xxx_fw_dump, isp)); | |
0107109e AV |
1384 | } |
1385 | ||
18e7555a AV |
1386 | static int |
1387 | qla81xx_mpi_sync(scsi_qla_host_t *vha) | |
1388 | { | |
1389 | #define MPS_MASK 0xe0 | |
1390 | int rval; | |
1391 | uint16_t dc; | |
1392 | uint32_t dw; | |
1393 | struct qla_hw_data *ha = vha->hw; | |
1394 | ||
1395 | if (!IS_QLA81XX(vha->hw)) | |
1396 | return QLA_SUCCESS; | |
1397 | ||
1398 | rval = qla2x00_write_ram_word(vha, 0x7c00, 1); | |
1399 | if (rval != QLA_SUCCESS) { | |
1400 | DEBUG2(qla_printk(KERN_WARNING, ha, | |
1401 | "Sync-MPI: Unable to acquire semaphore.\n")); | |
1402 | goto done; | |
1403 | } | |
1404 | ||
1405 | pci_read_config_word(vha->hw->pdev, 0x54, &dc); | |
1406 | rval = qla2x00_read_ram_word(vha, 0x7a15, &dw); | |
1407 | if (rval != QLA_SUCCESS) { | |
1408 | DEBUG2(qla_printk(KERN_WARNING, ha, | |
1409 | "Sync-MPI: Unable to read sync.\n")); | |
1410 | goto done_release; | |
1411 | } | |
1412 | ||
1413 | dc &= MPS_MASK; | |
1414 | if (dc == (dw & MPS_MASK)) | |
1415 | goto done_release; | |
1416 | ||
1417 | dw &= ~MPS_MASK; | |
1418 | dw |= dc; | |
1419 | rval = qla2x00_write_ram_word(vha, 0x7a15, dw); | |
1420 | if (rval != QLA_SUCCESS) { | |
1421 | DEBUG2(qla_printk(KERN_WARNING, ha, | |
1422 | "Sync-MPI: Unable to gain sync.\n")); | |
1423 | } | |
1424 | ||
1425 | done_release: | |
1426 | rval = qla2x00_write_ram_word(vha, 0x7c00, 0); | |
1427 | if (rval != QLA_SUCCESS) { | |
1428 | DEBUG2(qla_printk(KERN_WARNING, ha, | |
1429 | "Sync-MPI: Unable to release semaphore.\n")); | |
1430 | } | |
1431 | ||
1432 | done: | |
1433 | return rval; | |
1434 | } | |
1435 | ||
1da177e4 LT |
1436 | /** |
1437 | * qla2x00_setup_chip() - Load and start RISC firmware. | |
1438 | * @ha: HA context | |
1439 | * | |
1440 | * Returns 0 on success. | |
1441 | */ | |
1442 | static int | |
e315cd28 | 1443 | qla2x00_setup_chip(scsi_qla_host_t *vha) |
1da177e4 | 1444 | { |
0107109e AV |
1445 | int rval; |
1446 | uint32_t srisc_address = 0; | |
e315cd28 | 1447 | struct qla_hw_data *ha = vha->hw; |
3db0652e AV |
1448 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
1449 | unsigned long flags; | |
dda772e8 | 1450 | uint16_t fw_major_version; |
3db0652e | 1451 | |
a9083016 GM |
1452 | if (IS_QLA82XX(ha)) { |
1453 | rval = ha->isp_ops->load_risc(vha, &srisc_address); | |
14e303d9 AV |
1454 | if (rval == QLA_SUCCESS) { |
1455 | qla2x00_stop_firmware(vha); | |
a9083016 | 1456 | goto enable_82xx_npiv; |
14e303d9 | 1457 | } else |
b963752f | 1458 | goto failed; |
a9083016 GM |
1459 | } |
1460 | ||
3db0652e AV |
1461 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
1462 | /* Disable SRAM, Instruction RAM and GP RAM parity. */ | |
1463 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
1464 | WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0)); | |
1465 | RD_REG_WORD(®->hccr); | |
1466 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1467 | } | |
1da177e4 | 1468 | |
18e7555a AV |
1469 | qla81xx_mpi_sync(vha); |
1470 | ||
1da177e4 | 1471 | /* Load firmware sequences */ |
e315cd28 | 1472 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
0107109e | 1473 | if (rval == QLA_SUCCESS) { |
1da177e4 | 1474 | DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC " |
e315cd28 | 1475 | "code.\n", vha->host_no)); |
1da177e4 | 1476 | |
e315cd28 | 1477 | rval = qla2x00_verify_checksum(vha, srisc_address); |
1da177e4 LT |
1478 | if (rval == QLA_SUCCESS) { |
1479 | /* Start firmware execution. */ | |
1480 | DEBUG(printk("scsi(%ld): Checksum OK, start " | |
e315cd28 | 1481 | "firmware.\n", vha->host_no)); |
1da177e4 | 1482 | |
e315cd28 | 1483 | rval = qla2x00_execute_fw(vha, srisc_address); |
1da177e4 | 1484 | /* Retrieve firmware information. */ |
dda772e8 | 1485 | if (rval == QLA_SUCCESS) { |
a9083016 | 1486 | enable_82xx_npiv: |
dda772e8 | 1487 | fw_major_version = ha->fw_major_version; |
ca9e9c3e | 1488 | rval = qla2x00_get_fw_version(vha, |
1da177e4 LT |
1489 | &ha->fw_major_version, |
1490 | &ha->fw_minor_version, | |
1491 | &ha->fw_subminor_version, | |
3a03eb79 | 1492 | &ha->fw_attributes, &ha->fw_memory_size, |
55a96158 AV |
1493 | ha->mpi_version, &ha->mpi_capabilities, |
1494 | ha->phy_version); | |
ca9e9c3e AV |
1495 | if (rval != QLA_SUCCESS) |
1496 | goto failed; | |
2c3dfe3f | 1497 | ha->flags.npiv_supported = 0; |
e315cd28 | 1498 | if (IS_QLA2XXX_MIDTYPE(ha) && |
946fb891 | 1499 | (ha->fw_attributes & BIT_2)) { |
2c3dfe3f | 1500 | ha->flags.npiv_supported = 1; |
4d0ea247 SJ |
1501 | if ((!ha->max_npiv_vports) || |
1502 | ((ha->max_npiv_vports + 1) % | |
eb66dc60 | 1503 | MIN_MULTI_ID_FABRIC)) |
4d0ea247 | 1504 | ha->max_npiv_vports = |
eb66dc60 | 1505 | MIN_MULTI_ID_FABRIC - 1; |
4d0ea247 | 1506 | } |
24a08138 AV |
1507 | qla2x00_get_resource_cnts(vha, NULL, |
1508 | &ha->fw_xcb_count, NULL, NULL, | |
f3a0a77e | 1509 | &ha->max_npiv_vports, NULL); |
d743de66 | 1510 | |
a9083016 GM |
1511 | if (!fw_major_version && ql2xallocfwdump) { |
1512 | if (!IS_QLA82XX(ha)) | |
1513 | qla2x00_alloc_fw_dump(vha); | |
1514 | } | |
1da177e4 LT |
1515 | } |
1516 | } else { | |
1517 | DEBUG2(printk(KERN_INFO | |
1518 | "scsi(%ld): ISP Firmware failed checksum.\n", | |
e315cd28 | 1519 | vha->host_no)); |
1da177e4 LT |
1520 | } |
1521 | } | |
1522 | ||
3db0652e AV |
1523 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
1524 | /* Enable proper parity. */ | |
1525 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
1526 | if (IS_QLA2300(ha)) | |
1527 | /* SRAM parity */ | |
1528 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1); | |
1529 | else | |
1530 | /* SRAM, Instruction RAM and GP RAM parity */ | |
1531 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7); | |
1532 | RD_REG_WORD(®->hccr); | |
1533 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1534 | } | |
1535 | ||
1d2874de JC |
1536 | if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) { |
1537 | uint32_t size; | |
1538 | ||
1539 | rval = qla81xx_fac_get_sector_size(vha, &size); | |
1540 | if (rval == QLA_SUCCESS) { | |
1541 | ha->flags.fac_supported = 1; | |
1542 | ha->fdt_block_size = size << 2; | |
1543 | } else { | |
1544 | qla_printk(KERN_ERR, ha, | |
1545 | "Unsupported FAC firmware (%d.%02d.%02d).\n", | |
1546 | ha->fw_major_version, ha->fw_minor_version, | |
1547 | ha->fw_subminor_version); | |
1548 | } | |
1549 | } | |
ca9e9c3e | 1550 | failed: |
1da177e4 LT |
1551 | if (rval) { |
1552 | DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n", | |
e315cd28 | 1553 | vha->host_no)); |
1da177e4 LT |
1554 | } |
1555 | ||
1556 | return (rval); | |
1557 | } | |
1558 | ||
1559 | /** | |
1560 | * qla2x00_init_response_q_entries() - Initializes response queue entries. | |
1561 | * @ha: HA context | |
1562 | * | |
1563 | * Beginning of request ring has initialization control block already built | |
1564 | * by nvram config routine. | |
1565 | * | |
1566 | * Returns 0 on success. | |
1567 | */ | |
73208dfd AC |
1568 | void |
1569 | qla2x00_init_response_q_entries(struct rsp_que *rsp) | |
1da177e4 LT |
1570 | { |
1571 | uint16_t cnt; | |
1572 | response_t *pkt; | |
1573 | ||
2afa19a9 AC |
1574 | rsp->ring_ptr = rsp->ring; |
1575 | rsp->ring_index = 0; | |
1576 | rsp->status_srb = NULL; | |
e315cd28 AC |
1577 | pkt = rsp->ring_ptr; |
1578 | for (cnt = 0; cnt < rsp->length; cnt++) { | |
1da177e4 LT |
1579 | pkt->signature = RESPONSE_PROCESSED; |
1580 | pkt++; | |
1581 | } | |
1da177e4 LT |
1582 | } |
1583 | ||
1584 | /** | |
1585 | * qla2x00_update_fw_options() - Read and process firmware options. | |
1586 | * @ha: HA context | |
1587 | * | |
1588 | * Returns 0 on success. | |
1589 | */ | |
abbd8870 | 1590 | void |
e315cd28 | 1591 | qla2x00_update_fw_options(scsi_qla_host_t *vha) |
1da177e4 LT |
1592 | { |
1593 | uint16_t swing, emphasis, tx_sens, rx_sens; | |
e315cd28 | 1594 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
1595 | |
1596 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); | |
e315cd28 | 1597 | qla2x00_get_fw_options(vha, ha->fw_options); |
1da177e4 LT |
1598 | |
1599 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) | |
1600 | return; | |
1601 | ||
1602 | /* Serial Link options. */ | |
1603 | DEBUG3(printk("scsi(%ld): Serial link options:\n", | |
e315cd28 | 1604 | vha->host_no)); |
1da177e4 LT |
1605 | DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options, |
1606 | sizeof(ha->fw_seriallink_options))); | |
1607 | ||
1608 | ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING; | |
1609 | if (ha->fw_seriallink_options[3] & BIT_2) { | |
1610 | ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING; | |
1611 | ||
1612 | /* 1G settings */ | |
1613 | swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0); | |
1614 | emphasis = (ha->fw_seriallink_options[2] & | |
1615 | (BIT_4 | BIT_3)) >> 3; | |
1616 | tx_sens = ha->fw_seriallink_options[0] & | |
fa2a1ce5 | 1617 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
1da177e4 LT |
1618 | rx_sens = (ha->fw_seriallink_options[0] & |
1619 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; | |
1620 | ha->fw_options[10] = (emphasis << 14) | (swing << 8); | |
1621 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { | |
1622 | if (rx_sens == 0x0) | |
1623 | rx_sens = 0x3; | |
1624 | ha->fw_options[10] |= (tx_sens << 4) | rx_sens; | |
1625 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) | |
1626 | ha->fw_options[10] |= BIT_5 | | |
1627 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | | |
1628 | (tx_sens & (BIT_1 | BIT_0)); | |
1629 | ||
1630 | /* 2G settings */ | |
1631 | swing = (ha->fw_seriallink_options[2] & | |
1632 | (BIT_7 | BIT_6 | BIT_5)) >> 5; | |
1633 | emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0); | |
1634 | tx_sens = ha->fw_seriallink_options[1] & | |
fa2a1ce5 | 1635 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
1da177e4 LT |
1636 | rx_sens = (ha->fw_seriallink_options[1] & |
1637 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; | |
1638 | ha->fw_options[11] = (emphasis << 14) | (swing << 8); | |
1639 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { | |
1640 | if (rx_sens == 0x0) | |
1641 | rx_sens = 0x3; | |
1642 | ha->fw_options[11] |= (tx_sens << 4) | rx_sens; | |
1643 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) | |
1644 | ha->fw_options[11] |= BIT_5 | | |
1645 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | | |
1646 | (tx_sens & (BIT_1 | BIT_0)); | |
1647 | } | |
1648 | ||
1649 | /* FCP2 options. */ | |
1650 | /* Return command IOCBs without waiting for an ABTS to complete. */ | |
1651 | ha->fw_options[3] |= BIT_13; | |
1652 | ||
1653 | /* LED scheme. */ | |
1654 | if (ha->flags.enable_led_scheme) | |
1655 | ha->fw_options[2] |= BIT_12; | |
1656 | ||
48c02fde AV |
1657 | /* Detect ISP6312. */ |
1658 | if (IS_QLA6312(ha)) | |
1659 | ha->fw_options[2] |= BIT_13; | |
1660 | ||
1da177e4 | 1661 | /* Update firmware options. */ |
e315cd28 | 1662 | qla2x00_set_fw_options(vha, ha->fw_options); |
1da177e4 LT |
1663 | } |
1664 | ||
0107109e | 1665 | void |
e315cd28 | 1666 | qla24xx_update_fw_options(scsi_qla_host_t *vha) |
0107109e AV |
1667 | { |
1668 | int rval; | |
e315cd28 | 1669 | struct qla_hw_data *ha = vha->hw; |
0107109e | 1670 | |
a9083016 GM |
1671 | if (IS_QLA82XX(ha)) |
1672 | return; | |
1673 | ||
0107109e | 1674 | /* Update Serial Link options. */ |
f94097ed | 1675 | if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0) |
0107109e AV |
1676 | return; |
1677 | ||
e315cd28 | 1678 | rval = qla2x00_set_serdes_params(vha, |
f94097ed AV |
1679 | le16_to_cpu(ha->fw_seriallink_options24[1]), |
1680 | le16_to_cpu(ha->fw_seriallink_options24[2]), | |
1681 | le16_to_cpu(ha->fw_seriallink_options24[3])); | |
0107109e AV |
1682 | if (rval != QLA_SUCCESS) { |
1683 | qla_printk(KERN_WARNING, ha, | |
1684 | "Unable to update Serial Link options (%x).\n", rval); | |
1685 | } | |
1686 | } | |
1687 | ||
abbd8870 | 1688 | void |
e315cd28 | 1689 | qla2x00_config_rings(struct scsi_qla_host *vha) |
abbd8870 | 1690 | { |
e315cd28 | 1691 | struct qla_hw_data *ha = vha->hw; |
3d71644c | 1692 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
73208dfd AC |
1693 | struct req_que *req = ha->req_q_map[0]; |
1694 | struct rsp_que *rsp = ha->rsp_q_map[0]; | |
abbd8870 AV |
1695 | |
1696 | /* Setup ring parameters in initialization control block. */ | |
1697 | ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0); | |
1698 | ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0); | |
e315cd28 AC |
1699 | ha->init_cb->request_q_length = cpu_to_le16(req->length); |
1700 | ha->init_cb->response_q_length = cpu_to_le16(rsp->length); | |
1701 | ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); | |
1702 | ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); | |
1703 | ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); | |
1704 | ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma)); | |
abbd8870 AV |
1705 | |
1706 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0); | |
1707 | WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0); | |
1708 | WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0); | |
1709 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0); | |
1710 | RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */ | |
1711 | } | |
1712 | ||
0107109e | 1713 | void |
e315cd28 | 1714 | qla24xx_config_rings(struct scsi_qla_host *vha) |
0107109e | 1715 | { |
e315cd28 | 1716 | struct qla_hw_data *ha = vha->hw; |
73208dfd AC |
1717 | device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0); |
1718 | struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp; | |
1719 | struct qla_msix_entry *msix; | |
0107109e | 1720 | struct init_cb_24xx *icb; |
73208dfd AC |
1721 | uint16_t rid = 0; |
1722 | struct req_que *req = ha->req_q_map[0]; | |
1723 | struct rsp_que *rsp = ha->rsp_q_map[0]; | |
0107109e | 1724 | |
73208dfd | 1725 | /* Setup ring parameters in initialization control block. */ |
0107109e AV |
1726 | icb = (struct init_cb_24xx *)ha->init_cb; |
1727 | icb->request_q_outpointer = __constant_cpu_to_le16(0); | |
1728 | icb->response_q_inpointer = __constant_cpu_to_le16(0); | |
e315cd28 AC |
1729 | icb->request_q_length = cpu_to_le16(req->length); |
1730 | icb->response_q_length = cpu_to_le16(rsp->length); | |
1731 | icb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); | |
1732 | icb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); | |
1733 | icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); | |
1734 | icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma)); | |
0107109e | 1735 | |
73208dfd AC |
1736 | if (ha->mqenable) { |
1737 | icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS); | |
1738 | icb->rid = __constant_cpu_to_le16(rid); | |
1739 | if (ha->flags.msix_enabled) { | |
1740 | msix = &ha->msix_entries[1]; | |
1741 | DEBUG2_17(printk(KERN_INFO | |
2afa19a9 | 1742 | "Registering vector 0x%x for base que\n", msix->entry)); |
73208dfd AC |
1743 | icb->msix = cpu_to_le16(msix->entry); |
1744 | } | |
1745 | /* Use alternate PCI bus number */ | |
1746 | if (MSB(rid)) | |
1747 | icb->firmware_options_2 |= | |
1748 | __constant_cpu_to_le32(BIT_19); | |
1749 | /* Use alternate PCI devfn */ | |
1750 | if (LSB(rid)) | |
1751 | icb->firmware_options_2 |= | |
1752 | __constant_cpu_to_le32(BIT_18); | |
1753 | ||
3155754a AC |
1754 | /* Use Disable MSIX Handshake mode for capable adapters */ |
1755 | if (IS_MSIX_NACK_CAPABLE(ha)) { | |
1756 | icb->firmware_options_2 &= | |
1757 | __constant_cpu_to_le32(~BIT_22); | |
1758 | ha->flags.disable_msix_handshake = 1; | |
1759 | qla_printk(KERN_INFO, ha, | |
1760 | "MSIX Handshake Disable Mode turned on\n"); | |
1761 | } else { | |
1762 | icb->firmware_options_2 |= | |
1763 | __constant_cpu_to_le32(BIT_22); | |
1764 | } | |
73208dfd | 1765 | icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23); |
73208dfd AC |
1766 | |
1767 | WRT_REG_DWORD(®->isp25mq.req_q_in, 0); | |
1768 | WRT_REG_DWORD(®->isp25mq.req_q_out, 0); | |
1769 | WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0); | |
1770 | WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0); | |
1771 | } else { | |
1772 | WRT_REG_DWORD(®->isp24.req_q_in, 0); | |
1773 | WRT_REG_DWORD(®->isp24.req_q_out, 0); | |
1774 | WRT_REG_DWORD(®->isp24.rsp_q_in, 0); | |
1775 | WRT_REG_DWORD(®->isp24.rsp_q_out, 0); | |
1776 | } | |
1777 | /* PCI posting */ | |
1778 | RD_REG_DWORD(&ioreg->hccr); | |
0107109e AV |
1779 | } |
1780 | ||
1da177e4 LT |
1781 | /** |
1782 | * qla2x00_init_rings() - Initializes firmware. | |
1783 | * @ha: HA context | |
1784 | * | |
1785 | * Beginning of request ring has initialization control block already built | |
1786 | * by nvram config routine. | |
1787 | * | |
1788 | * Returns 0 on success. | |
1789 | */ | |
1790 | static int | |
e315cd28 | 1791 | qla2x00_init_rings(scsi_qla_host_t *vha) |
1da177e4 LT |
1792 | { |
1793 | int rval; | |
1794 | unsigned long flags = 0; | |
29bdccbe | 1795 | int cnt, que; |
e315cd28 | 1796 | struct qla_hw_data *ha = vha->hw; |
29bdccbe AC |
1797 | struct req_que *req; |
1798 | struct rsp_que *rsp; | |
1799 | struct scsi_qla_host *vp; | |
2c3dfe3f SJ |
1800 | struct mid_init_cb_24xx *mid_init_cb = |
1801 | (struct mid_init_cb_24xx *) ha->init_cb; | |
1da177e4 LT |
1802 | |
1803 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
1804 | ||
1805 | /* Clear outstanding commands array. */ | |
2afa19a9 | 1806 | for (que = 0; que < ha->max_req_queues; que++) { |
29bdccbe AC |
1807 | req = ha->req_q_map[que]; |
1808 | if (!req) | |
1809 | continue; | |
2afa19a9 | 1810 | for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) |
29bdccbe | 1811 | req->outstanding_cmds[cnt] = NULL; |
1da177e4 | 1812 | |
2afa19a9 | 1813 | req->current_outstanding_cmd = 1; |
1da177e4 | 1814 | |
29bdccbe AC |
1815 | /* Initialize firmware. */ |
1816 | req->ring_ptr = req->ring; | |
1817 | req->ring_index = 0; | |
1818 | req->cnt = req->length; | |
1819 | } | |
1da177e4 | 1820 | |
2afa19a9 | 1821 | for (que = 0; que < ha->max_rsp_queues; que++) { |
29bdccbe AC |
1822 | rsp = ha->rsp_q_map[que]; |
1823 | if (!rsp) | |
1824 | continue; | |
29bdccbe AC |
1825 | /* Initialize response queue entries */ |
1826 | qla2x00_init_response_q_entries(rsp); | |
1827 | } | |
1da177e4 | 1828 | |
542bce1f | 1829 | spin_lock(&ha->vport_slock); |
29bdccbe AC |
1830 | /* Clear RSCN queue. */ |
1831 | list_for_each_entry(vp, &ha->vp_list, list) { | |
1832 | vp->rscn_in_ptr = 0; | |
1833 | vp->rscn_out_ptr = 0; | |
1834 | } | |
feafb7b1 | 1835 | |
542bce1f | 1836 | spin_unlock(&ha->vport_slock); |
feafb7b1 | 1837 | |
e315cd28 | 1838 | ha->isp_ops->config_rings(vha); |
1da177e4 LT |
1839 | |
1840 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1841 | ||
1842 | /* Update any ISP specific firmware options before initialization. */ | |
e315cd28 | 1843 | ha->isp_ops->update_fw_options(vha); |
1da177e4 | 1844 | |
e315cd28 | 1845 | DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no)); |
2c3dfe3f | 1846 | |
605aa2bc LC |
1847 | if (ha->flags.npiv_supported) { |
1848 | if (ha->operating_mode == LOOP) | |
1849 | ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1; | |
c48339de | 1850 | mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports); |
605aa2bc LC |
1851 | } |
1852 | ||
24a08138 AV |
1853 | if (IS_FWI2_CAPABLE(ha)) { |
1854 | mid_init_cb->options = __constant_cpu_to_le16(BIT_1); | |
1855 | mid_init_cb->init_cb.execution_throttle = | |
1856 | cpu_to_le16(ha->fw_xcb_count); | |
1857 | } | |
2c3dfe3f | 1858 | |
e315cd28 | 1859 | rval = qla2x00_init_firmware(vha, ha->init_cb_size); |
1da177e4 LT |
1860 | if (rval) { |
1861 | DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n", | |
e315cd28 | 1862 | vha->host_no)); |
1da177e4 LT |
1863 | } else { |
1864 | DEBUG3(printk("scsi(%ld): Init firmware -- success.\n", | |
e315cd28 | 1865 | vha->host_no)); |
1da177e4 LT |
1866 | } |
1867 | ||
1868 | return (rval); | |
1869 | } | |
1870 | ||
1871 | /** | |
1872 | * qla2x00_fw_ready() - Waits for firmware ready. | |
1873 | * @ha: HA context | |
1874 | * | |
1875 | * Returns 0 on success. | |
1876 | */ | |
1877 | static int | |
e315cd28 | 1878 | qla2x00_fw_ready(scsi_qla_host_t *vha) |
1da177e4 LT |
1879 | { |
1880 | int rval; | |
4d4df193 | 1881 | unsigned long wtime, mtime, cs84xx_time; |
1da177e4 LT |
1882 | uint16_t min_wait; /* Minimum wait time if loop is down */ |
1883 | uint16_t wait_time; /* Wait time if loop is coming ready */ | |
656e8912 | 1884 | uint16_t state[5]; |
e315cd28 | 1885 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
1886 | |
1887 | rval = QLA_SUCCESS; | |
1888 | ||
1889 | /* 20 seconds for loop down. */ | |
fa2a1ce5 | 1890 | min_wait = 20; |
1da177e4 LT |
1891 | |
1892 | /* | |
1893 | * Firmware should take at most one RATOV to login, plus 5 seconds for | |
1894 | * our own processing. | |
1895 | */ | |
1896 | if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) { | |
1897 | wait_time = min_wait; | |
1898 | } | |
1899 | ||
1900 | /* Min wait time if loop down */ | |
1901 | mtime = jiffies + (min_wait * HZ); | |
1902 | ||
1903 | /* wait time before firmware ready */ | |
1904 | wtime = jiffies + (wait_time * HZ); | |
1905 | ||
1906 | /* Wait for ISP to finish LIP */ | |
e315cd28 | 1907 | if (!vha->flags.init_done) |
1da177e4 LT |
1908 | qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n"); |
1909 | ||
1910 | DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n", | |
e315cd28 | 1911 | vha->host_no)); |
1da177e4 LT |
1912 | |
1913 | do { | |
e315cd28 | 1914 | rval = qla2x00_get_firmware_state(vha, state); |
1da177e4 | 1915 | if (rval == QLA_SUCCESS) { |
4d4df193 | 1916 | if (state[0] < FSTATE_LOSS_OF_SYNC) { |
e315cd28 | 1917 | vha->device_flags &= ~DFLG_NO_CABLE; |
1da177e4 | 1918 | } |
4d4df193 HK |
1919 | if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) { |
1920 | DEBUG16(printk("scsi(%ld): fw_state=%x " | |
e315cd28 | 1921 | "84xx=%x.\n", vha->host_no, state[0], |
4d4df193 HK |
1922 | state[2])); |
1923 | if ((state[2] & FSTATE_LOGGED_IN) && | |
1924 | (state[2] & FSTATE_WAITING_FOR_VERIFY)) { | |
1925 | DEBUG16(printk("scsi(%ld): Sending " | |
e315cd28 | 1926 | "verify iocb.\n", vha->host_no)); |
4d4df193 HK |
1927 | |
1928 | cs84xx_time = jiffies; | |
e315cd28 | 1929 | rval = qla84xx_init_chip(vha); |
4d4df193 HK |
1930 | if (rval != QLA_SUCCESS) |
1931 | break; | |
1932 | ||
1933 | /* Add time taken to initialize. */ | |
1934 | cs84xx_time = jiffies - cs84xx_time; | |
1935 | wtime += cs84xx_time; | |
1936 | mtime += cs84xx_time; | |
1937 | DEBUG16(printk("scsi(%ld): Increasing " | |
1938 | "wait time by %ld. New time %ld\n", | |
e315cd28 | 1939 | vha->host_no, cs84xx_time, wtime)); |
4d4df193 HK |
1940 | } |
1941 | } else if (state[0] == FSTATE_READY) { | |
1da177e4 | 1942 | DEBUG(printk("scsi(%ld): F/W Ready - OK \n", |
e315cd28 | 1943 | vha->host_no)); |
1da177e4 | 1944 | |
e315cd28 | 1945 | qla2x00_get_retry_cnt(vha, &ha->retry_count, |
1da177e4 LT |
1946 | &ha->login_timeout, &ha->r_a_tov); |
1947 | ||
1948 | rval = QLA_SUCCESS; | |
1949 | break; | |
1950 | } | |
1951 | ||
1952 | rval = QLA_FUNCTION_FAILED; | |
1953 | ||
e315cd28 | 1954 | if (atomic_read(&vha->loop_down_timer) && |
4d4df193 | 1955 | state[0] != FSTATE_READY) { |
1da177e4 | 1956 | /* Loop down. Timeout on min_wait for states |
fa2a1ce5 AV |
1957 | * other than Wait for Login. |
1958 | */ | |
1da177e4 LT |
1959 | if (time_after_eq(jiffies, mtime)) { |
1960 | qla_printk(KERN_INFO, ha, | |
1961 | "Cable is unplugged...\n"); | |
1962 | ||
e315cd28 | 1963 | vha->device_flags |= DFLG_NO_CABLE; |
1da177e4 LT |
1964 | break; |
1965 | } | |
1966 | } | |
1967 | } else { | |
1968 | /* Mailbox cmd failed. Timeout on min_wait. */ | |
cdbb0a4f SV |
1969 | if (time_after_eq(jiffies, mtime) || |
1970 | (IS_QLA82XX(ha) && ha->flags.fw_hung)) | |
1da177e4 LT |
1971 | break; |
1972 | } | |
1973 | ||
1974 | if (time_after_eq(jiffies, wtime)) | |
1975 | break; | |
1976 | ||
1977 | /* Delay for a while */ | |
1978 | msleep(500); | |
1979 | ||
1980 | DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n", | |
e315cd28 | 1981 | vha->host_no, state[0], jiffies)); |
1da177e4 LT |
1982 | } while (1); |
1983 | ||
656e8912 AV |
1984 | DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n", |
1985 | vha->host_no, state[0], state[1], state[2], state[3], state[4], | |
1986 | jiffies)); | |
1da177e4 LT |
1987 | |
1988 | if (rval) { | |
1989 | DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n", | |
e315cd28 | 1990 | vha->host_no)); |
1da177e4 LT |
1991 | } |
1992 | ||
1993 | return (rval); | |
1994 | } | |
1995 | ||
1996 | /* | |
1997 | * qla2x00_configure_hba | |
1998 | * Setup adapter context. | |
1999 | * | |
2000 | * Input: | |
2001 | * ha = adapter state pointer. | |
2002 | * | |
2003 | * Returns: | |
2004 | * 0 = success | |
2005 | * | |
2006 | * Context: | |
2007 | * Kernel context. | |
2008 | */ | |
2009 | static int | |
e315cd28 | 2010 | qla2x00_configure_hba(scsi_qla_host_t *vha) |
1da177e4 LT |
2011 | { |
2012 | int rval; | |
2013 | uint16_t loop_id; | |
2014 | uint16_t topo; | |
2c3dfe3f | 2015 | uint16_t sw_cap; |
1da177e4 LT |
2016 | uint8_t al_pa; |
2017 | uint8_t area; | |
2018 | uint8_t domain; | |
2019 | char connect_type[22]; | |
e315cd28 | 2020 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
2021 | |
2022 | /* Get host addresses. */ | |
e315cd28 | 2023 | rval = qla2x00_get_adapter_id(vha, |
2c3dfe3f | 2024 | &loop_id, &al_pa, &area, &domain, &topo, &sw_cap); |
1da177e4 | 2025 | if (rval != QLA_SUCCESS) { |
e315cd28 | 2026 | if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) || |
7a44b86e | 2027 | IS_QLA8XXX_TYPE(ha) || |
33135aa2 RA |
2028 | (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) { |
2029 | DEBUG2(printk("%s(%ld) Loop is in a transition state\n", | |
e315cd28 | 2030 | __func__, vha->host_no)); |
33135aa2 RA |
2031 | } else { |
2032 | qla_printk(KERN_WARNING, ha, | |
2033 | "ERROR -- Unable to get host loop ID.\n"); | |
e315cd28 | 2034 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
33135aa2 | 2035 | } |
1da177e4 LT |
2036 | return (rval); |
2037 | } | |
2038 | ||
2039 | if (topo == 4) { | |
2040 | qla_printk(KERN_INFO, ha, | |
2041 | "Cannot get topology - retrying.\n"); | |
2042 | return (QLA_FUNCTION_FAILED); | |
2043 | } | |
2044 | ||
e315cd28 | 2045 | vha->loop_id = loop_id; |
1da177e4 LT |
2046 | |
2047 | /* initialize */ | |
2048 | ha->min_external_loopid = SNS_FIRST_LOOP_ID; | |
2049 | ha->operating_mode = LOOP; | |
2c3dfe3f | 2050 | ha->switch_cap = 0; |
1da177e4 LT |
2051 | |
2052 | switch (topo) { | |
2053 | case 0: | |
2054 | DEBUG3(printk("scsi(%ld): HBA in NL topology.\n", | |
e315cd28 | 2055 | vha->host_no)); |
1da177e4 LT |
2056 | ha->current_topology = ISP_CFG_NL; |
2057 | strcpy(connect_type, "(Loop)"); | |
2058 | break; | |
2059 | ||
2060 | case 1: | |
2061 | DEBUG3(printk("scsi(%ld): HBA in FL topology.\n", | |
e315cd28 | 2062 | vha->host_no)); |
2c3dfe3f | 2063 | ha->switch_cap = sw_cap; |
1da177e4 LT |
2064 | ha->current_topology = ISP_CFG_FL; |
2065 | strcpy(connect_type, "(FL_Port)"); | |
2066 | break; | |
2067 | ||
2068 | case 2: | |
2069 | DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n", | |
e315cd28 | 2070 | vha->host_no)); |
1da177e4 LT |
2071 | ha->operating_mode = P2P; |
2072 | ha->current_topology = ISP_CFG_N; | |
2073 | strcpy(connect_type, "(N_Port-to-N_Port)"); | |
2074 | break; | |
2075 | ||
2076 | case 3: | |
2077 | DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n", | |
e315cd28 | 2078 | vha->host_no)); |
2c3dfe3f | 2079 | ha->switch_cap = sw_cap; |
1da177e4 LT |
2080 | ha->operating_mode = P2P; |
2081 | ha->current_topology = ISP_CFG_F; | |
2082 | strcpy(connect_type, "(F_Port)"); | |
2083 | break; | |
2084 | ||
2085 | default: | |
2086 | DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. " | |
2087 | "Using NL.\n", | |
e315cd28 | 2088 | vha->host_no, topo)); |
1da177e4 LT |
2089 | ha->current_topology = ISP_CFG_NL; |
2090 | strcpy(connect_type, "(Loop)"); | |
2091 | break; | |
2092 | } | |
2093 | ||
2094 | /* Save Host port and loop ID. */ | |
2095 | /* byte order - Big Endian */ | |
e315cd28 AC |
2096 | vha->d_id.b.domain = domain; |
2097 | vha->d_id.b.area = area; | |
2098 | vha->d_id.b.al_pa = al_pa; | |
1da177e4 | 2099 | |
e315cd28 | 2100 | if (!vha->flags.init_done) |
1da177e4 LT |
2101 | qla_printk(KERN_INFO, ha, |
2102 | "Topology - %s, Host Loop address 0x%x\n", | |
e315cd28 | 2103 | connect_type, vha->loop_id); |
1da177e4 LT |
2104 | |
2105 | if (rval) { | |
e315cd28 | 2106 | DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no)); |
1da177e4 | 2107 | } else { |
e315cd28 | 2108 | DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no)); |
1da177e4 LT |
2109 | } |
2110 | ||
2111 | return(rval); | |
2112 | } | |
2113 | ||
a9083016 | 2114 | inline void |
e315cd28 AC |
2115 | qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len, |
2116 | char *def) | |
9bb9fcf2 AV |
2117 | { |
2118 | char *st, *en; | |
2119 | uint16_t index; | |
e315cd28 | 2120 | struct qla_hw_data *ha = vha->hw; |
ab671149 | 2121 | int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) && |
a9083016 | 2122 | !IS_QLA8XXX_TYPE(ha); |
9bb9fcf2 AV |
2123 | |
2124 | if (memcmp(model, BINZERO, len) != 0) { | |
2125 | strncpy(ha->model_number, model, len); | |
2126 | st = en = ha->model_number; | |
2127 | en += len - 1; | |
2128 | while (en > st) { | |
2129 | if (*en != 0x20 && *en != 0x00) | |
2130 | break; | |
2131 | *en-- = '\0'; | |
2132 | } | |
2133 | ||
2134 | index = (ha->pdev->subsystem_device & 0xff); | |
7d0dba17 AV |
2135 | if (use_tbl && |
2136 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && | |
9bb9fcf2 | 2137 | index < QLA_MODEL_NAMES) |
1ee27146 JC |
2138 | strncpy(ha->model_desc, |
2139 | qla2x00_model_name[index * 2 + 1], | |
2140 | sizeof(ha->model_desc) - 1); | |
9bb9fcf2 AV |
2141 | } else { |
2142 | index = (ha->pdev->subsystem_device & 0xff); | |
7d0dba17 AV |
2143 | if (use_tbl && |
2144 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && | |
9bb9fcf2 AV |
2145 | index < QLA_MODEL_NAMES) { |
2146 | strcpy(ha->model_number, | |
2147 | qla2x00_model_name[index * 2]); | |
1ee27146 JC |
2148 | strncpy(ha->model_desc, |
2149 | qla2x00_model_name[index * 2 + 1], | |
2150 | sizeof(ha->model_desc) - 1); | |
9bb9fcf2 AV |
2151 | } else { |
2152 | strcpy(ha->model_number, def); | |
2153 | } | |
2154 | } | |
1ee27146 | 2155 | if (IS_FWI2_CAPABLE(ha)) |
e315cd28 | 2156 | qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc, |
1ee27146 | 2157 | sizeof(ha->model_desc)); |
9bb9fcf2 AV |
2158 | } |
2159 | ||
4e08df3f DM |
2160 | /* On sparc systems, obtain port and node WWN from firmware |
2161 | * properties. | |
2162 | */ | |
e315cd28 | 2163 | static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv) |
4e08df3f DM |
2164 | { |
2165 | #ifdef CONFIG_SPARC | |
e315cd28 | 2166 | struct qla_hw_data *ha = vha->hw; |
4e08df3f | 2167 | struct pci_dev *pdev = ha->pdev; |
15576bc8 DM |
2168 | struct device_node *dp = pci_device_to_OF_node(pdev); |
2169 | const u8 *val; | |
4e08df3f DM |
2170 | int len; |
2171 | ||
2172 | val = of_get_property(dp, "port-wwn", &len); | |
2173 | if (val && len >= WWN_SIZE) | |
2174 | memcpy(nv->port_name, val, WWN_SIZE); | |
2175 | ||
2176 | val = of_get_property(dp, "node-wwn", &len); | |
2177 | if (val && len >= WWN_SIZE) | |
2178 | memcpy(nv->node_name, val, WWN_SIZE); | |
2179 | #endif | |
2180 | } | |
2181 | ||
1da177e4 LT |
2182 | /* |
2183 | * NVRAM configuration for ISP 2xxx | |
2184 | * | |
2185 | * Input: | |
2186 | * ha = adapter block pointer. | |
2187 | * | |
2188 | * Output: | |
2189 | * initialization control block in response_ring | |
2190 | * host adapters parameters in host adapter block | |
2191 | * | |
2192 | * Returns: | |
2193 | * 0 = success. | |
2194 | */ | |
abbd8870 | 2195 | int |
e315cd28 | 2196 | qla2x00_nvram_config(scsi_qla_host_t *vha) |
1da177e4 | 2197 | { |
4e08df3f | 2198 | int rval; |
0107109e AV |
2199 | uint8_t chksum = 0; |
2200 | uint16_t cnt; | |
2201 | uint8_t *dptr1, *dptr2; | |
e315cd28 | 2202 | struct qla_hw_data *ha = vha->hw; |
0107109e | 2203 | init_cb_t *icb = ha->init_cb; |
281afe19 SJ |
2204 | nvram_t *nv = ha->nvram; |
2205 | uint8_t *ptr = ha->nvram; | |
3d71644c | 2206 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
1da177e4 | 2207 | |
4e08df3f DM |
2208 | rval = QLA_SUCCESS; |
2209 | ||
1da177e4 | 2210 | /* Determine NVRAM starting address. */ |
0107109e | 2211 | ha->nvram_size = sizeof(nvram_t); |
1da177e4 LT |
2212 | ha->nvram_base = 0; |
2213 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) | |
2214 | if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1) | |
2215 | ha->nvram_base = 0x80; | |
2216 | ||
2217 | /* Get NVRAM data and calculate checksum. */ | |
e315cd28 | 2218 | ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size); |
0107109e AV |
2219 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++) |
2220 | chksum += *ptr++; | |
1da177e4 | 2221 | |
e315cd28 | 2222 | DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no)); |
281afe19 | 2223 | DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size)); |
1da177e4 LT |
2224 | |
2225 | /* Bad NVRAM data, set defaults parameters. */ | |
2226 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || | |
2227 | nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) { | |
2228 | /* Reset NVRAM data. */ | |
2229 | qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: " | |
2230 | "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0], | |
2231 | nv->nvram_version); | |
4e08df3f DM |
2232 | qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet " |
2233 | "invalid -- WWPN) defaults.\n"); | |
2234 | ||
2235 | /* | |
2236 | * Set default initialization control block. | |
2237 | */ | |
2238 | memset(nv, 0, ha->nvram_size); | |
2239 | nv->parameter_block_version = ICB_VERSION; | |
2240 | ||
2241 | if (IS_QLA23XX(ha)) { | |
2242 | nv->firmware_options[0] = BIT_2 | BIT_1; | |
2243 | nv->firmware_options[1] = BIT_7 | BIT_5; | |
2244 | nv->add_firmware_options[0] = BIT_5; | |
2245 | nv->add_firmware_options[1] = BIT_5 | BIT_4; | |
2246 | nv->frame_payload_size = __constant_cpu_to_le16(2048); | |
2247 | nv->special_options[1] = BIT_7; | |
2248 | } else if (IS_QLA2200(ha)) { | |
2249 | nv->firmware_options[0] = BIT_2 | BIT_1; | |
2250 | nv->firmware_options[1] = BIT_7 | BIT_5; | |
2251 | nv->add_firmware_options[0] = BIT_5; | |
2252 | nv->add_firmware_options[1] = BIT_5 | BIT_4; | |
2253 | nv->frame_payload_size = __constant_cpu_to_le16(1024); | |
2254 | } else if (IS_QLA2100(ha)) { | |
2255 | nv->firmware_options[0] = BIT_3 | BIT_1; | |
2256 | nv->firmware_options[1] = BIT_5; | |
2257 | nv->frame_payload_size = __constant_cpu_to_le16(1024); | |
2258 | } | |
2259 | ||
2260 | nv->max_iocb_allocation = __constant_cpu_to_le16(256); | |
2261 | nv->execution_throttle = __constant_cpu_to_le16(16); | |
2262 | nv->retry_count = 8; | |
2263 | nv->retry_delay = 1; | |
2264 | ||
2265 | nv->port_name[0] = 33; | |
2266 | nv->port_name[3] = 224; | |
2267 | nv->port_name[4] = 139; | |
2268 | ||
e315cd28 | 2269 | qla2xxx_nvram_wwn_from_ofw(vha, nv); |
4e08df3f DM |
2270 | |
2271 | nv->login_timeout = 4; | |
2272 | ||
2273 | /* | |
2274 | * Set default host adapter parameters | |
2275 | */ | |
2276 | nv->host_p[1] = BIT_2; | |
2277 | nv->reset_delay = 5; | |
2278 | nv->port_down_retry_count = 8; | |
2279 | nv->max_luns_per_target = __constant_cpu_to_le16(8); | |
2280 | nv->link_down_timeout = 60; | |
2281 | ||
2282 | rval = 1; | |
1da177e4 LT |
2283 | } |
2284 | ||
2285 | #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2) | |
2286 | /* | |
2287 | * The SN2 does not provide BIOS emulation which means you can't change | |
2288 | * potentially bogus BIOS settings. Force the use of default settings | |
2289 | * for link rate and frame size. Hope that the rest of the settings | |
2290 | * are valid. | |
2291 | */ | |
2292 | if (ia64_platform_is("sn2")) { | |
2293 | nv->frame_payload_size = __constant_cpu_to_le16(2048); | |
2294 | if (IS_QLA23XX(ha)) | |
2295 | nv->special_options[1] = BIT_7; | |
2296 | } | |
2297 | #endif | |
2298 | ||
2299 | /* Reset Initialization control block */ | |
0107109e | 2300 | memset(icb, 0, ha->init_cb_size); |
1da177e4 LT |
2301 | |
2302 | /* | |
2303 | * Setup driver NVRAM options. | |
2304 | */ | |
2305 | nv->firmware_options[0] |= (BIT_6 | BIT_1); | |
2306 | nv->firmware_options[0] &= ~(BIT_5 | BIT_4); | |
2307 | nv->firmware_options[1] |= (BIT_5 | BIT_0); | |
2308 | nv->firmware_options[1] &= ~BIT_4; | |
2309 | ||
2310 | if (IS_QLA23XX(ha)) { | |
2311 | nv->firmware_options[0] |= BIT_2; | |
2312 | nv->firmware_options[0] &= ~BIT_3; | |
5ff1d584 | 2313 | nv->firmware_options[0] &= ~BIT_6; |
0107109e | 2314 | nv->add_firmware_options[1] |= BIT_5 | BIT_4; |
1da177e4 LT |
2315 | |
2316 | if (IS_QLA2300(ha)) { | |
2317 | if (ha->fb_rev == FPM_2310) { | |
2318 | strcpy(ha->model_number, "QLA2310"); | |
2319 | } else { | |
2320 | strcpy(ha->model_number, "QLA2300"); | |
2321 | } | |
2322 | } else { | |
e315cd28 | 2323 | qla2x00_set_model_info(vha, nv->model_number, |
9bb9fcf2 | 2324 | sizeof(nv->model_number), "QLA23xx"); |
1da177e4 LT |
2325 | } |
2326 | } else if (IS_QLA2200(ha)) { | |
2327 | nv->firmware_options[0] |= BIT_2; | |
2328 | /* | |
2329 | * 'Point-to-point preferred, else loop' is not a safe | |
2330 | * connection mode setting. | |
2331 | */ | |
2332 | if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) == | |
2333 | (BIT_5 | BIT_4)) { | |
2334 | /* Force 'loop preferred, else point-to-point'. */ | |
2335 | nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4); | |
2336 | nv->add_firmware_options[0] |= BIT_5; | |
2337 | } | |
2338 | strcpy(ha->model_number, "QLA22xx"); | |
2339 | } else /*if (IS_QLA2100(ha))*/ { | |
2340 | strcpy(ha->model_number, "QLA2100"); | |
2341 | } | |
2342 | ||
2343 | /* | |
2344 | * Copy over NVRAM RISC parameter block to initialization control block. | |
2345 | */ | |
2346 | dptr1 = (uint8_t *)icb; | |
2347 | dptr2 = (uint8_t *)&nv->parameter_block_version; | |
2348 | cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version; | |
2349 | while (cnt--) | |
2350 | *dptr1++ = *dptr2++; | |
2351 | ||
2352 | /* Copy 2nd half. */ | |
2353 | dptr1 = (uint8_t *)icb->add_firmware_options; | |
2354 | cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options; | |
2355 | while (cnt--) | |
2356 | *dptr1++ = *dptr2++; | |
2357 | ||
5341e868 AV |
2358 | /* Use alternate WWN? */ |
2359 | if (nv->host_p[1] & BIT_7) { | |
2360 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); | |
2361 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); | |
2362 | } | |
2363 | ||
1da177e4 LT |
2364 | /* Prepare nodename */ |
2365 | if ((icb->firmware_options[1] & BIT_6) == 0) { | |
2366 | /* | |
2367 | * Firmware will apply the following mask if the nodename was | |
2368 | * not provided. | |
2369 | */ | |
2370 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); | |
2371 | icb->node_name[0] &= 0xF0; | |
2372 | } | |
2373 | ||
2374 | /* | |
2375 | * Set host adapter parameters. | |
2376 | */ | |
0181944f | 2377 | if (nv->host_p[0] & BIT_7) |
11010fec | 2378 | ql2xextended_error_logging = 1; |
1da177e4 LT |
2379 | ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0); |
2380 | /* Always load RISC code on non ISP2[12]00 chips. */ | |
2381 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) | |
2382 | ha->flags.disable_risc_code_load = 0; | |
2383 | ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0); | |
2384 | ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0); | |
2385 | ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0); | |
06c22bd1 | 2386 | ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0; |
d4c760c2 | 2387 | ha->flags.disable_serdes = 0; |
1da177e4 LT |
2388 | |
2389 | ha->operating_mode = | |
2390 | (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4; | |
2391 | ||
2392 | memcpy(ha->fw_seriallink_options, nv->seriallink_options, | |
2393 | sizeof(ha->fw_seriallink_options)); | |
2394 | ||
2395 | /* save HBA serial number */ | |
2396 | ha->serial0 = icb->port_name[5]; | |
2397 | ha->serial1 = icb->port_name[6]; | |
2398 | ha->serial2 = icb->port_name[7]; | |
e315cd28 AC |
2399 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
2400 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); | |
1da177e4 LT |
2401 | |
2402 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); | |
2403 | ||
2404 | ha->retry_count = nv->retry_count; | |
2405 | ||
2406 | /* Set minimum login_timeout to 4 seconds. */ | |
5b91490e | 2407 | if (nv->login_timeout != ql2xlogintimeout) |
1da177e4 LT |
2408 | nv->login_timeout = ql2xlogintimeout; |
2409 | if (nv->login_timeout < 4) | |
2410 | nv->login_timeout = 4; | |
2411 | ha->login_timeout = nv->login_timeout; | |
2412 | icb->login_timeout = nv->login_timeout; | |
2413 | ||
00a537b8 AV |
2414 | /* Set minimum RATOV to 100 tenths of a second. */ |
2415 | ha->r_a_tov = 100; | |
1da177e4 | 2416 | |
1da177e4 LT |
2417 | ha->loop_reset_delay = nv->reset_delay; |
2418 | ||
1da177e4 LT |
2419 | /* Link Down Timeout = 0: |
2420 | * | |
2421 | * When Port Down timer expires we will start returning | |
2422 | * I/O's to OS with "DID_NO_CONNECT". | |
2423 | * | |
2424 | * Link Down Timeout != 0: | |
2425 | * | |
2426 | * The driver waits for the link to come up after link down | |
2427 | * before returning I/Os to OS with "DID_NO_CONNECT". | |
fa2a1ce5 | 2428 | */ |
1da177e4 LT |
2429 | if (nv->link_down_timeout == 0) { |
2430 | ha->loop_down_abort_time = | |
354d6b21 | 2431 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
1da177e4 LT |
2432 | } else { |
2433 | ha->link_down_timeout = nv->link_down_timeout; | |
2434 | ha->loop_down_abort_time = | |
2435 | (LOOP_DOWN_TIME - ha->link_down_timeout); | |
fa2a1ce5 | 2436 | } |
1da177e4 | 2437 | |
1da177e4 LT |
2438 | /* |
2439 | * Need enough time to try and get the port back. | |
2440 | */ | |
2441 | ha->port_down_retry_count = nv->port_down_retry_count; | |
2442 | if (qlport_down_retry) | |
2443 | ha->port_down_retry_count = qlport_down_retry; | |
2444 | /* Set login_retry_count */ | |
2445 | ha->login_retry_count = nv->retry_count; | |
2446 | if (ha->port_down_retry_count == nv->port_down_retry_count && | |
2447 | ha->port_down_retry_count > 3) | |
2448 | ha->login_retry_count = ha->port_down_retry_count; | |
2449 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) | |
2450 | ha->login_retry_count = ha->port_down_retry_count; | |
2451 | if (ql2xloginretrycount) | |
2452 | ha->login_retry_count = ql2xloginretrycount; | |
2453 | ||
1da177e4 LT |
2454 | icb->lun_enables = __constant_cpu_to_le16(0); |
2455 | icb->command_resource_count = 0; | |
2456 | icb->immediate_notify_resource_count = 0; | |
2457 | icb->timeout = __constant_cpu_to_le16(0); | |
2458 | ||
2459 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { | |
2460 | /* Enable RIO */ | |
2461 | icb->firmware_options[0] &= ~BIT_3; | |
2462 | icb->add_firmware_options[0] &= | |
2463 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); | |
2464 | icb->add_firmware_options[0] |= BIT_2; | |
2465 | icb->response_accumulation_timer = 3; | |
2466 | icb->interrupt_delay_timer = 5; | |
2467 | ||
e315cd28 | 2468 | vha->flags.process_response_queue = 1; |
1da177e4 | 2469 | } else { |
4fdfefe5 | 2470 | /* Enable ZIO. */ |
e315cd28 | 2471 | if (!vha->flags.init_done) { |
4fdfefe5 AV |
2472 | ha->zio_mode = icb->add_firmware_options[0] & |
2473 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); | |
2474 | ha->zio_timer = icb->interrupt_delay_timer ? | |
2475 | icb->interrupt_delay_timer: 2; | |
2476 | } | |
1da177e4 LT |
2477 | icb->add_firmware_options[0] &= |
2478 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); | |
e315cd28 | 2479 | vha->flags.process_response_queue = 0; |
4fdfefe5 | 2480 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
4a59f71d AV |
2481 | ha->zio_mode = QLA_ZIO_MODE_6; |
2482 | ||
4fdfefe5 | 2483 | DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer " |
e315cd28 | 2484 | "delay (%d us).\n", vha->host_no, ha->zio_mode, |
4fdfefe5 | 2485 | ha->zio_timer * 100)); |
1da177e4 | 2486 | qla_printk(KERN_INFO, ha, |
4fdfefe5 AV |
2487 | "ZIO mode %d enabled; timer delay (%d us).\n", |
2488 | ha->zio_mode, ha->zio_timer * 100); | |
1da177e4 | 2489 | |
4fdfefe5 AV |
2490 | icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode; |
2491 | icb->interrupt_delay_timer = (uint8_t)ha->zio_timer; | |
e315cd28 | 2492 | vha->flags.process_response_queue = 1; |
1da177e4 LT |
2493 | } |
2494 | } | |
2495 | ||
4e08df3f DM |
2496 | if (rval) { |
2497 | DEBUG2_3(printk(KERN_WARNING | |
e315cd28 | 2498 | "scsi(%ld): NVRAM configuration failed!\n", vha->host_no)); |
4e08df3f DM |
2499 | } |
2500 | return (rval); | |
1da177e4 LT |
2501 | } |
2502 | ||
19a7b4ae JSEC |
2503 | static void |
2504 | qla2x00_rport_del(void *data) | |
2505 | { | |
2506 | fc_port_t *fcport = data; | |
d97994dc | 2507 | struct fc_rport *rport; |
d97994dc | 2508 | |
e315cd28 | 2509 | spin_lock_irq(fcport->vha->host->host_lock); |
ac280b67 | 2510 | rport = fcport->drport ? fcport->drport: fcport->rport; |
d97994dc | 2511 | fcport->drport = NULL; |
e315cd28 | 2512 | spin_unlock_irq(fcport->vha->host->host_lock); |
d97994dc AV |
2513 | if (rport) |
2514 | fc_remote_port_delete(rport); | |
19a7b4ae JSEC |
2515 | } |
2516 | ||
1da177e4 LT |
2517 | /** |
2518 | * qla2x00_alloc_fcport() - Allocate a generic fcport. | |
2519 | * @ha: HA context | |
2520 | * @flags: allocation flags | |
2521 | * | |
2522 | * Returns a pointer to the allocated fcport, or NULL, if none available. | |
2523 | */ | |
9a069e19 | 2524 | fc_port_t * |
e315cd28 | 2525 | qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags) |
1da177e4 LT |
2526 | { |
2527 | fc_port_t *fcport; | |
2528 | ||
bbfbbbc1 MK |
2529 | fcport = kzalloc(sizeof(fc_port_t), flags); |
2530 | if (!fcport) | |
2531 | return NULL; | |
1da177e4 LT |
2532 | |
2533 | /* Setup fcport template structure. */ | |
e315cd28 AC |
2534 | fcport->vha = vha; |
2535 | fcport->vp_idx = vha->vp_idx; | |
1da177e4 LT |
2536 | fcport->port_type = FCT_UNKNOWN; |
2537 | fcport->loop_id = FC_NO_LOOP_ID; | |
1da177e4 | 2538 | atomic_set(&fcport->state, FCS_UNCONFIGURED); |
ad3e0eda | 2539 | fcport->supported_classes = FC_COS_UNSPECIFIED; |
1da177e4 | 2540 | |
bbfbbbc1 | 2541 | return fcport; |
1da177e4 LT |
2542 | } |
2543 | ||
2544 | /* | |
2545 | * qla2x00_configure_loop | |
2546 | * Updates Fibre Channel Device Database with what is actually on loop. | |
2547 | * | |
2548 | * Input: | |
2549 | * ha = adapter block pointer. | |
2550 | * | |
2551 | * Returns: | |
2552 | * 0 = success. | |
2553 | * 1 = error. | |
2554 | * 2 = database was full and device was not configured. | |
2555 | */ | |
2556 | static int | |
e315cd28 | 2557 | qla2x00_configure_loop(scsi_qla_host_t *vha) |
1da177e4 LT |
2558 | { |
2559 | int rval; | |
2560 | unsigned long flags, save_flags; | |
e315cd28 | 2561 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
2562 | rval = QLA_SUCCESS; |
2563 | ||
2564 | /* Get Initiator ID */ | |
e315cd28 AC |
2565 | if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) { |
2566 | rval = qla2x00_configure_hba(vha); | |
1da177e4 LT |
2567 | if (rval != QLA_SUCCESS) { |
2568 | DEBUG(printk("scsi(%ld): Unable to configure HBA.\n", | |
e315cd28 | 2569 | vha->host_no)); |
1da177e4 LT |
2570 | return (rval); |
2571 | } | |
2572 | } | |
2573 | ||
e315cd28 | 2574 | save_flags = flags = vha->dpc_flags; |
1da177e4 | 2575 | DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n", |
e315cd28 | 2576 | vha->host_no, flags)); |
1da177e4 LT |
2577 | |
2578 | /* | |
2579 | * If we have both an RSCN and PORT UPDATE pending then handle them | |
2580 | * both at the same time. | |
2581 | */ | |
e315cd28 AC |
2582 | clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
2583 | clear_bit(RSCN_UPDATE, &vha->dpc_flags); | |
1da177e4 | 2584 | |
3064ff39 MH |
2585 | qla2x00_get_data_rate(vha); |
2586 | ||
1da177e4 LT |
2587 | /* Determine what we need to do */ |
2588 | if (ha->current_topology == ISP_CFG_FL && | |
2589 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { | |
2590 | ||
e315cd28 | 2591 | vha->flags.rscn_queue_overflow = 1; |
1da177e4 LT |
2592 | set_bit(RSCN_UPDATE, &flags); |
2593 | ||
2594 | } else if (ha->current_topology == ISP_CFG_F && | |
2595 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { | |
2596 | ||
e315cd28 | 2597 | vha->flags.rscn_queue_overflow = 1; |
1da177e4 LT |
2598 | set_bit(RSCN_UPDATE, &flags); |
2599 | clear_bit(LOCAL_LOOP_UPDATE, &flags); | |
21333b48 AV |
2600 | |
2601 | } else if (ha->current_topology == ISP_CFG_N) { | |
2602 | clear_bit(RSCN_UPDATE, &flags); | |
1da177e4 | 2603 | |
e315cd28 | 2604 | } else if (!vha->flags.online || |
1da177e4 LT |
2605 | (test_bit(ABORT_ISP_ACTIVE, &flags))) { |
2606 | ||
e315cd28 | 2607 | vha->flags.rscn_queue_overflow = 1; |
1da177e4 LT |
2608 | set_bit(RSCN_UPDATE, &flags); |
2609 | set_bit(LOCAL_LOOP_UPDATE, &flags); | |
2610 | } | |
2611 | ||
2612 | if (test_bit(LOCAL_LOOP_UPDATE, &flags)) { | |
e315cd28 | 2613 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
1da177e4 | 2614 | rval = QLA_FUNCTION_FAILED; |
e315cd28 AC |
2615 | else |
2616 | rval = qla2x00_configure_local_loop(vha); | |
1da177e4 LT |
2617 | } |
2618 | ||
2619 | if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) { | |
e315cd28 | 2620 | if (LOOP_TRANSITION(vha)) |
1da177e4 | 2621 | rval = QLA_FUNCTION_FAILED; |
e315cd28 AC |
2622 | else |
2623 | rval = qla2x00_configure_fabric(vha); | |
1da177e4 LT |
2624 | } |
2625 | ||
2626 | if (rval == QLA_SUCCESS) { | |
e315cd28 AC |
2627 | if (atomic_read(&vha->loop_down_timer) || |
2628 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { | |
1da177e4 LT |
2629 | rval = QLA_FUNCTION_FAILED; |
2630 | } else { | |
e315cd28 | 2631 | atomic_set(&vha->loop_state, LOOP_READY); |
1da177e4 | 2632 | |
e315cd28 | 2633 | DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no)); |
1da177e4 LT |
2634 | } |
2635 | } | |
2636 | ||
2637 | if (rval) { | |
2638 | DEBUG2_3(printk("%s(%ld): *** FAILED ***\n", | |
e315cd28 | 2639 | __func__, vha->host_no)); |
1da177e4 LT |
2640 | } else { |
2641 | DEBUG3(printk("%s: exiting normally\n", __func__)); | |
2642 | } | |
2643 | ||
cc3ef7bc | 2644 | /* Restore state if a resync event occurred during processing */ |
e315cd28 | 2645 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
1da177e4 | 2646 | if (test_bit(LOCAL_LOOP_UPDATE, &save_flags)) |
e315cd28 | 2647 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
f4658b6c | 2648 | if (test_bit(RSCN_UPDATE, &save_flags)) { |
e315cd28 | 2649 | set_bit(RSCN_UPDATE, &vha->dpc_flags); |
3a6478df GM |
2650 | if (!IS_ALOGIO_CAPABLE(ha)) |
2651 | vha->flags.rscn_queue_overflow = 1; | |
f4658b6c | 2652 | } |
1da177e4 LT |
2653 | } |
2654 | ||
2655 | return (rval); | |
2656 | } | |
2657 | ||
2658 | ||
2659 | ||
2660 | /* | |
2661 | * qla2x00_configure_local_loop | |
2662 | * Updates Fibre Channel Device Database with local loop devices. | |
2663 | * | |
2664 | * Input: | |
2665 | * ha = adapter block pointer. | |
2666 | * | |
2667 | * Returns: | |
2668 | * 0 = success. | |
2669 | */ | |
2670 | static int | |
e315cd28 | 2671 | qla2x00_configure_local_loop(scsi_qla_host_t *vha) |
1da177e4 LT |
2672 | { |
2673 | int rval, rval2; | |
2674 | int found_devs; | |
2675 | int found; | |
2676 | fc_port_t *fcport, *new_fcport; | |
2677 | ||
2678 | uint16_t index; | |
2679 | uint16_t entries; | |
2680 | char *id_iter; | |
2681 | uint16_t loop_id; | |
2682 | uint8_t domain, area, al_pa; | |
e315cd28 | 2683 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
2684 | |
2685 | found_devs = 0; | |
2686 | new_fcport = NULL; | |
2687 | entries = MAX_FIBRE_DEVICES; | |
2688 | ||
e315cd28 AC |
2689 | DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no)); |
2690 | DEBUG3(qla2x00_get_fcal_position_map(vha, NULL)); | |
1da177e4 LT |
2691 | |
2692 | /* Get list of logged in devices. */ | |
2693 | memset(ha->gid_list, 0, GID_LIST_SIZE); | |
e315cd28 | 2694 | rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma, |
1da177e4 LT |
2695 | &entries); |
2696 | if (rval != QLA_SUCCESS) | |
2697 | goto cleanup_allocation; | |
2698 | ||
2699 | DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n", | |
7640335e | 2700 | vha->host_no, entries)); |
1da177e4 LT |
2701 | DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list, |
2702 | entries * sizeof(struct gid_list_info))); | |
2703 | ||
2704 | /* Allocate temporary fcport for any new fcports discovered. */ | |
e315cd28 | 2705 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
1da177e4 LT |
2706 | if (new_fcport == NULL) { |
2707 | rval = QLA_MEMORY_ALLOC_FAILED; | |
2708 | goto cleanup_allocation; | |
2709 | } | |
2710 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; | |
2711 | ||
2712 | /* | |
2713 | * Mark local devices that were present with FCF_DEVICE_LOST for now. | |
2714 | */ | |
e315cd28 | 2715 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
1da177e4 LT |
2716 | if (atomic_read(&fcport->state) == FCS_ONLINE && |
2717 | fcport->port_type != FCT_BROADCAST && | |
2718 | (fcport->flags & FCF_FABRIC_DEVICE) == 0) { | |
2719 | ||
2720 | DEBUG(printk("scsi(%ld): Marking port lost, " | |
2721 | "loop_id=0x%04x\n", | |
e315cd28 | 2722 | vha->host_no, fcport->loop_id)); |
1da177e4 LT |
2723 | |
2724 | atomic_set(&fcport->state, FCS_DEVICE_LOST); | |
1da177e4 LT |
2725 | } |
2726 | } | |
2727 | ||
2728 | /* Add devices to port list. */ | |
2729 | id_iter = (char *)ha->gid_list; | |
2730 | for (index = 0; index < entries; index++) { | |
2731 | domain = ((struct gid_list_info *)id_iter)->domain; | |
2732 | area = ((struct gid_list_info *)id_iter)->area; | |
2733 | al_pa = ((struct gid_list_info *)id_iter)->al_pa; | |
abbd8870 | 2734 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
1da177e4 LT |
2735 | loop_id = (uint16_t) |
2736 | ((struct gid_list_info *)id_iter)->loop_id_2100; | |
abbd8870 | 2737 | else |
1da177e4 LT |
2738 | loop_id = le16_to_cpu( |
2739 | ((struct gid_list_info *)id_iter)->loop_id); | |
abbd8870 | 2740 | id_iter += ha->gid_list_info_size; |
1da177e4 LT |
2741 | |
2742 | /* Bypass reserved domain fields. */ | |
2743 | if ((domain & 0xf0) == 0xf0) | |
2744 | continue; | |
2745 | ||
2746 | /* Bypass if not same domain and area of adapter. */ | |
f7d289f6 | 2747 | if (area && domain && |
e315cd28 | 2748 | (area != vha->d_id.b.area || domain != vha->d_id.b.domain)) |
1da177e4 LT |
2749 | continue; |
2750 | ||
2751 | /* Bypass invalid local loop ID. */ | |
2752 | if (loop_id > LAST_LOCAL_LOOP_ID) | |
2753 | continue; | |
2754 | ||
2755 | /* Fill in member data. */ | |
2756 | new_fcport->d_id.b.domain = domain; | |
2757 | new_fcport->d_id.b.area = area; | |
2758 | new_fcport->d_id.b.al_pa = al_pa; | |
2759 | new_fcport->loop_id = loop_id; | |
e315cd28 AC |
2760 | new_fcport->vp_idx = vha->vp_idx; |
2761 | rval2 = qla2x00_get_port_database(vha, new_fcport, 0); | |
1da177e4 LT |
2762 | if (rval2 != QLA_SUCCESS) { |
2763 | DEBUG2(printk("scsi(%ld): Failed to retrieve fcport " | |
2764 | "information -- get_port_database=%x, " | |
2765 | "loop_id=0x%04x\n", | |
e315cd28 | 2766 | vha->host_no, rval2, new_fcport->loop_id)); |
c9d02acf | 2767 | DEBUG2(printk("scsi(%ld): Scheduling resync...\n", |
e315cd28 AC |
2768 | vha->host_no)); |
2769 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); | |
1da177e4 LT |
2770 | continue; |
2771 | } | |
2772 | ||
2773 | /* Check for matching device in port list. */ | |
2774 | found = 0; | |
2775 | fcport = NULL; | |
e315cd28 | 2776 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
1da177e4 LT |
2777 | if (memcmp(new_fcport->port_name, fcport->port_name, |
2778 | WWN_SIZE)) | |
2779 | continue; | |
2780 | ||
ddb9b126 | 2781 | fcport->flags &= ~FCF_FABRIC_DEVICE; |
1da177e4 LT |
2782 | fcport->loop_id = new_fcport->loop_id; |
2783 | fcport->port_type = new_fcport->port_type; | |
2784 | fcport->d_id.b24 = new_fcport->d_id.b24; | |
2785 | memcpy(fcport->node_name, new_fcport->node_name, | |
2786 | WWN_SIZE); | |
2787 | ||
2788 | found++; | |
2789 | break; | |
2790 | } | |
2791 | ||
2792 | if (!found) { | |
2793 | /* New device, add to fcports list. */ | |
e315cd28 AC |
2794 | if (vha->vp_idx) { |
2795 | new_fcport->vha = vha; | |
2796 | new_fcport->vp_idx = vha->vp_idx; | |
2c3dfe3f | 2797 | } |
e315cd28 | 2798 | list_add_tail(&new_fcport->list, &vha->vp_fcports); |
1da177e4 LT |
2799 | |
2800 | /* Allocate a new replacement fcport. */ | |
2801 | fcport = new_fcport; | |
e315cd28 | 2802 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
1da177e4 LT |
2803 | if (new_fcport == NULL) { |
2804 | rval = QLA_MEMORY_ALLOC_FAILED; | |
2805 | goto cleanup_allocation; | |
2806 | } | |
2807 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; | |
2808 | } | |
2809 | ||
d8b45213 | 2810 | /* Base iIDMA settings on HBA port speed. */ |
a3cbdfad | 2811 | fcport->fp_speed = ha->link_data_rate; |
d8b45213 | 2812 | |
e315cd28 | 2813 | qla2x00_update_fcport(vha, fcport); |
1da177e4 LT |
2814 | |
2815 | found_devs++; | |
2816 | } | |
2817 | ||
2818 | cleanup_allocation: | |
c9475cb0 | 2819 | kfree(new_fcport); |
1da177e4 LT |
2820 | |
2821 | if (rval != QLA_SUCCESS) { | |
2822 | DEBUG2(printk("scsi(%ld): Configure local loop error exit: " | |
e315cd28 | 2823 | "rval=%x\n", vha->host_no, rval)); |
1da177e4 LT |
2824 | } |
2825 | ||
1da177e4 LT |
2826 | return (rval); |
2827 | } | |
2828 | ||
d8b45213 | 2829 | static void |
e315cd28 | 2830 | qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
d8b45213 AV |
2831 | { |
2832 | #define LS_UNKNOWN 2 | |
9f8fddee AV |
2833 | static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" }; |
2834 | char *link_speed; | |
d8b45213 | 2835 | int rval; |
1bb39548 | 2836 | uint16_t mb[4]; |
e315cd28 | 2837 | struct qla_hw_data *ha = vha->hw; |
d8b45213 | 2838 | |
c76f2c01 | 2839 | if (!IS_IIDMA_CAPABLE(ha)) |
d8b45213 AV |
2840 | return; |
2841 | ||
c9afb9a2 GM |
2842 | if (atomic_read(&fcport->state) != FCS_ONLINE) |
2843 | return; | |
2844 | ||
39bd9622 AV |
2845 | if (fcport->fp_speed == PORT_SPEED_UNKNOWN || |
2846 | fcport->fp_speed > ha->link_data_rate) | |
d8b45213 AV |
2847 | return; |
2848 | ||
e315cd28 | 2849 | rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed, |
a3cbdfad | 2850 | mb); |
d8b45213 AV |
2851 | if (rval != QLA_SUCCESS) { |
2852 | DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA " | |
2853 | "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n", | |
e315cd28 | 2854 | vha->host_no, fcport->port_name[0], fcport->port_name[1], |
d8b45213 AV |
2855 | fcport->port_name[2], fcport->port_name[3], |
2856 | fcport->port_name[4], fcport->port_name[5], | |
2857 | fcport->port_name[6], fcport->port_name[7], rval, | |
a3cbdfad | 2858 | fcport->fp_speed, mb[0], mb[1])); |
d8b45213 | 2859 | } else { |
9f8fddee AV |
2860 | link_speed = link_speeds[LS_UNKNOWN]; |
2861 | if (fcport->fp_speed < 5) | |
2862 | link_speed = link_speeds[fcport->fp_speed]; | |
2863 | else if (fcport->fp_speed == 0x13) | |
2864 | link_speed = link_speeds[5]; | |
d8b45213 AV |
2865 | DEBUG2(qla_printk(KERN_INFO, ha, |
2866 | "iIDMA adjusted to %s GB/s on " | |
2867 | "%02x%02x%02x%02x%02x%02x%02x%02x.\n", | |
9f8fddee | 2868 | link_speed, fcport->port_name[0], |
d8b45213 AV |
2869 | fcport->port_name[1], fcport->port_name[2], |
2870 | fcport->port_name[3], fcport->port_name[4], | |
2871 | fcport->port_name[5], fcport->port_name[6], | |
2872 | fcport->port_name[7])); | |
2873 | } | |
2874 | } | |
2875 | ||
23be331d | 2876 | static void |
e315cd28 | 2877 | qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport) |
8482e118 AV |
2878 | { |
2879 | struct fc_rport_identifiers rport_ids; | |
bdf79621 | 2880 | struct fc_rport *rport; |
e315cd28 | 2881 | struct qla_hw_data *ha = vha->hw; |
8482e118 | 2882 | |
ac280b67 | 2883 | qla2x00_rport_del(fcport); |
8482e118 | 2884 | |
f8b02a85 AV |
2885 | rport_ids.node_name = wwn_to_u64(fcport->node_name); |
2886 | rport_ids.port_name = wwn_to_u64(fcport->port_name); | |
8482e118 AV |
2887 | rport_ids.port_id = fcport->d_id.b.domain << 16 | |
2888 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; | |
77d74143 | 2889 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
e315cd28 | 2890 | fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids); |
77d74143 AV |
2891 | if (!rport) { |
2892 | qla_printk(KERN_WARNING, ha, | |
2893 | "Unable to allocate fc remote port!\n"); | |
2894 | return; | |
2895 | } | |
e315cd28 | 2896 | spin_lock_irq(fcport->vha->host->host_lock); |
19a7b4ae | 2897 | *((fc_port_t **)rport->dd_data) = fcport; |
e315cd28 | 2898 | spin_unlock_irq(fcport->vha->host->host_lock); |
d97994dc | 2899 | |
ad3e0eda | 2900 | rport->supported_classes = fcport->supported_classes; |
77d74143 | 2901 | |
8482e118 AV |
2902 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
2903 | if (fcport->port_type == FCT_INITIATOR) | |
2904 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; | |
2905 | if (fcport->port_type == FCT_TARGET) | |
2906 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; | |
77d74143 | 2907 | fc_remote_port_rolechg(rport, rport_ids.roles); |
1da177e4 LT |
2908 | } |
2909 | ||
23be331d AB |
2910 | /* |
2911 | * qla2x00_update_fcport | |
2912 | * Updates device on list. | |
2913 | * | |
2914 | * Input: | |
2915 | * ha = adapter block pointer. | |
2916 | * fcport = port structure pointer. | |
2917 | * | |
2918 | * Return: | |
2919 | * 0 - Success | |
2920 | * BIT_0 - error | |
2921 | * | |
2922 | * Context: | |
2923 | * Kernel context. | |
2924 | */ | |
2925 | void | |
e315cd28 | 2926 | qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
23be331d | 2927 | { |
e315cd28 | 2928 | fcport->vha = vha; |
23be331d | 2929 | fcport->login_retry = 0; |
5ff1d584 | 2930 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
23be331d | 2931 | |
e315cd28 | 2932 | qla2x00_iidma_fcport(vha, fcport); |
21090cbe | 2933 | qla24xx_update_fcport_fcp_prio(vha, fcport); |
e315cd28 | 2934 | qla2x00_reg_remote_port(vha, fcport); |
38170fa8 | 2935 | atomic_set(&fcport->state, FCS_ONLINE); |
23be331d AB |
2936 | } |
2937 | ||
1da177e4 LT |
2938 | /* |
2939 | * qla2x00_configure_fabric | |
2940 | * Setup SNS devices with loop ID's. | |
2941 | * | |
2942 | * Input: | |
2943 | * ha = adapter block pointer. | |
2944 | * | |
2945 | * Returns: | |
2946 | * 0 = success. | |
2947 | * BIT_0 = error | |
2948 | */ | |
2949 | static int | |
e315cd28 | 2950 | qla2x00_configure_fabric(scsi_qla_host_t *vha) |
1da177e4 LT |
2951 | { |
2952 | int rval, rval2; | |
2953 | fc_port_t *fcport, *fcptemp; | |
2954 | uint16_t next_loopid; | |
2955 | uint16_t mb[MAILBOX_REGISTER_COUNT]; | |
0107109e | 2956 | uint16_t loop_id; |
1da177e4 | 2957 | LIST_HEAD(new_fcports); |
e315cd28 AC |
2958 | struct qla_hw_data *ha = vha->hw; |
2959 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); | |
1da177e4 LT |
2960 | |
2961 | /* If FL port exists, then SNS is present */ | |
e428924c | 2962 | if (IS_FWI2_CAPABLE(ha)) |
0107109e AV |
2963 | loop_id = NPH_F_PORT; |
2964 | else | |
2965 | loop_id = SNS_FL_PORT; | |
e315cd28 | 2966 | rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1); |
1da177e4 LT |
2967 | if (rval != QLA_SUCCESS) { |
2968 | DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL " | |
e315cd28 | 2969 | "Port\n", vha->host_no)); |
1da177e4 | 2970 | |
e315cd28 | 2971 | vha->device_flags &= ~SWITCH_FOUND; |
1da177e4 LT |
2972 | return (QLA_SUCCESS); |
2973 | } | |
e315cd28 | 2974 | vha->device_flags |= SWITCH_FOUND; |
1da177e4 LT |
2975 | |
2976 | /* Mark devices that need re-synchronization. */ | |
e315cd28 | 2977 | rval2 = qla2x00_device_resync(vha); |
1da177e4 LT |
2978 | if (rval2 == QLA_RSCNS_HANDLED) { |
2979 | /* No point doing the scan, just continue. */ | |
2980 | return (QLA_SUCCESS); | |
2981 | } | |
2982 | do { | |
cca5335c AV |
2983 | /* FDMI support. */ |
2984 | if (ql2xfdmienable && | |
e315cd28 AC |
2985 | test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags)) |
2986 | qla2x00_fdmi_register(vha); | |
cca5335c | 2987 | |
1da177e4 | 2988 | /* Ensure we are logged into the SNS. */ |
e428924c | 2989 | if (IS_FWI2_CAPABLE(ha)) |
0107109e AV |
2990 | loop_id = NPH_SNS; |
2991 | else | |
2992 | loop_id = SIMPLE_NAME_SERVER; | |
e315cd28 | 2993 | ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff, |
abbd8870 | 2994 | 0xfc, mb, BIT_1 | BIT_0); |
1da177e4 LT |
2995 | if (mb[0] != MBS_COMMAND_COMPLETE) { |
2996 | DEBUG2(qla_printk(KERN_INFO, ha, | |
2997 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " | |
0107109e | 2998 | "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id, |
1da177e4 LT |
2999 | mb[0], mb[1], mb[2], mb[6], mb[7])); |
3000 | return (QLA_SUCCESS); | |
3001 | } | |
3002 | ||
e315cd28 AC |
3003 | if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) { |
3004 | if (qla2x00_rft_id(vha)) { | |
1da177e4 LT |
3005 | /* EMPTY */ |
3006 | DEBUG2(printk("scsi(%ld): Register FC-4 " | |
e315cd28 | 3007 | "TYPE failed.\n", vha->host_no)); |
1da177e4 | 3008 | } |
e315cd28 | 3009 | if (qla2x00_rff_id(vha)) { |
1da177e4 LT |
3010 | /* EMPTY */ |
3011 | DEBUG2(printk("scsi(%ld): Register FC-4 " | |
e315cd28 | 3012 | "Features failed.\n", vha->host_no)); |
1da177e4 | 3013 | } |
e315cd28 | 3014 | if (qla2x00_rnn_id(vha)) { |
1da177e4 LT |
3015 | /* EMPTY */ |
3016 | DEBUG2(printk("scsi(%ld): Register Node Name " | |
e315cd28 AC |
3017 | "failed.\n", vha->host_no)); |
3018 | } else if (qla2x00_rsnn_nn(vha)) { | |
1da177e4 LT |
3019 | /* EMPTY */ |
3020 | DEBUG2(printk("scsi(%ld): Register Symbolic " | |
e315cd28 | 3021 | "Node Name failed.\n", vha->host_no)); |
1da177e4 LT |
3022 | } |
3023 | } | |
3024 | ||
e315cd28 | 3025 | rval = qla2x00_find_all_fabric_devs(vha, &new_fcports); |
1da177e4 LT |
3026 | if (rval != QLA_SUCCESS) |
3027 | break; | |
3028 | ||
3029 | /* | |
3030 | * Logout all previous fabric devices marked lost, except | |
f08b7251 | 3031 | * FCP2 devices. |
1da177e4 | 3032 | */ |
e315cd28 AC |
3033 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
3034 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) | |
1da177e4 LT |
3035 | break; |
3036 | ||
3037 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) | |
3038 | continue; | |
3039 | ||
3040 | if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) { | |
e315cd28 | 3041 | qla2x00_mark_device_lost(vha, fcport, |
d97994dc | 3042 | ql2xplogiabsentdevice, 0); |
1da177e4 | 3043 | if (fcport->loop_id != FC_NO_LOOP_ID && |
f08b7251 | 3044 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
1da177e4 LT |
3045 | fcport->port_type != FCT_INITIATOR && |
3046 | fcport->port_type != FCT_BROADCAST) { | |
e315cd28 | 3047 | ha->isp_ops->fabric_logout(vha, |
1c7c6357 AV |
3048 | fcport->loop_id, |
3049 | fcport->d_id.b.domain, | |
3050 | fcport->d_id.b.area, | |
3051 | fcport->d_id.b.al_pa); | |
1da177e4 LT |
3052 | fcport->loop_id = FC_NO_LOOP_ID; |
3053 | } | |
3054 | } | |
3055 | } | |
3056 | ||
3057 | /* Starting free loop ID. */ | |
e315cd28 | 3058 | next_loopid = ha->min_external_loopid; |
1da177e4 LT |
3059 | |
3060 | /* | |
3061 | * Scan through our port list and login entries that need to be | |
3062 | * logged in. | |
3063 | */ | |
e315cd28 AC |
3064 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
3065 | if (atomic_read(&vha->loop_down_timer) || | |
3066 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) | |
1da177e4 LT |
3067 | break; |
3068 | ||
3069 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 || | |
3070 | (fcport->flags & FCF_LOGIN_NEEDED) == 0) | |
3071 | continue; | |
3072 | ||
3073 | if (fcport->loop_id == FC_NO_LOOP_ID) { | |
3074 | fcport->loop_id = next_loopid; | |
d4486fd6 | 3075 | rval = qla2x00_find_new_loop_id( |
e315cd28 | 3076 | base_vha, fcport); |
1da177e4 LT |
3077 | if (rval != QLA_SUCCESS) { |
3078 | /* Ran out of IDs to use */ | |
3079 | break; | |
3080 | } | |
3081 | } | |
1da177e4 | 3082 | /* Login and update database */ |
e315cd28 | 3083 | qla2x00_fabric_dev_login(vha, fcport, &next_loopid); |
1da177e4 LT |
3084 | } |
3085 | ||
3086 | /* Exit if out of loop IDs. */ | |
3087 | if (rval != QLA_SUCCESS) { | |
3088 | break; | |
3089 | } | |
3090 | ||
3091 | /* | |
3092 | * Login and add the new devices to our port list. | |
3093 | */ | |
3094 | list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) { | |
e315cd28 AC |
3095 | if (atomic_read(&vha->loop_down_timer) || |
3096 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) | |
1da177e4 LT |
3097 | break; |
3098 | ||
3099 | /* Find a new loop ID to use. */ | |
3100 | fcport->loop_id = next_loopid; | |
e315cd28 | 3101 | rval = qla2x00_find_new_loop_id(base_vha, fcport); |
1da177e4 LT |
3102 | if (rval != QLA_SUCCESS) { |
3103 | /* Ran out of IDs to use */ | |
3104 | break; | |
3105 | } | |
3106 | ||
bdf79621 | 3107 | /* Login and update database */ |
e315cd28 AC |
3108 | qla2x00_fabric_dev_login(vha, fcport, &next_loopid); |
3109 | ||
3110 | if (vha->vp_idx) { | |
3111 | fcport->vha = vha; | |
3112 | fcport->vp_idx = vha->vp_idx; | |
3113 | } | |
3114 | list_move_tail(&fcport->list, &vha->vp_fcports); | |
1da177e4 LT |
3115 | } |
3116 | } while (0); | |
3117 | ||
3118 | /* Free all new device structures not processed. */ | |
3119 | list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) { | |
3120 | list_del(&fcport->list); | |
3121 | kfree(fcport); | |
3122 | } | |
3123 | ||
3124 | if (rval) { | |
3125 | DEBUG2(printk("scsi(%ld): Configure fabric error exit: " | |
e315cd28 | 3126 | "rval=%d\n", vha->host_no, rval)); |
1da177e4 LT |
3127 | } |
3128 | ||
3129 | return (rval); | |
3130 | } | |
3131 | ||
1da177e4 LT |
3132 | /* |
3133 | * qla2x00_find_all_fabric_devs | |
3134 | * | |
3135 | * Input: | |
3136 | * ha = adapter block pointer. | |
3137 | * dev = database device entry pointer. | |
3138 | * | |
3139 | * Returns: | |
3140 | * 0 = success. | |
3141 | * | |
3142 | * Context: | |
3143 | * Kernel context. | |
3144 | */ | |
3145 | static int | |
e315cd28 AC |
3146 | qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha, |
3147 | struct list_head *new_fcports) | |
1da177e4 LT |
3148 | { |
3149 | int rval; | |
3150 | uint16_t loop_id; | |
3151 | fc_port_t *fcport, *new_fcport, *fcptemp; | |
3152 | int found; | |
3153 | ||
3154 | sw_info_t *swl; | |
3155 | int swl_idx; | |
3156 | int first_dev, last_dev; | |
1516ef44 | 3157 | port_id_t wrap = {}, nxt_d_id; |
e315cd28 AC |
3158 | struct qla_hw_data *ha = vha->hw; |
3159 | struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev); | |
ee546b6e | 3160 | struct scsi_qla_host *tvp; |
1da177e4 LT |
3161 | |
3162 | rval = QLA_SUCCESS; | |
3163 | ||
3164 | /* Try GID_PT to get device list, else GAN. */ | |
4b89258c | 3165 | swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL); |
bbfbbbc1 | 3166 | if (!swl) { |
1da177e4 LT |
3167 | /*EMPTY*/ |
3168 | DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback " | |
e315cd28 | 3169 | "on GA_NXT\n", vha->host_no)); |
1da177e4 | 3170 | } else { |
e315cd28 | 3171 | if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) { |
1da177e4 LT |
3172 | kfree(swl); |
3173 | swl = NULL; | |
e315cd28 | 3174 | } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) { |
1da177e4 LT |
3175 | kfree(swl); |
3176 | swl = NULL; | |
e315cd28 | 3177 | } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) { |
1da177e4 LT |
3178 | kfree(swl); |
3179 | swl = NULL; | |
e5896bd5 | 3180 | } else if (ql2xiidmaenable && |
e315cd28 AC |
3181 | qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) { |
3182 | qla2x00_gpsc(vha, swl); | |
1da177e4 | 3183 | } |
e8c72ba5 CD |
3184 | |
3185 | /* If other queries succeeded probe for FC-4 type */ | |
3186 | if (swl) | |
3187 | qla2x00_gff_id(vha, swl); | |
1da177e4 LT |
3188 | } |
3189 | swl_idx = 0; | |
3190 | ||
3191 | /* Allocate temporary fcport for any new fcports discovered. */ | |
e315cd28 | 3192 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
1da177e4 | 3193 | if (new_fcport == NULL) { |
c9475cb0 | 3194 | kfree(swl); |
1da177e4 LT |
3195 | return (QLA_MEMORY_ALLOC_FAILED); |
3196 | } | |
3197 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); | |
1da177e4 LT |
3198 | /* Set start port ID scan at adapter ID. */ |
3199 | first_dev = 1; | |
3200 | last_dev = 0; | |
3201 | ||
3202 | /* Starting free loop ID. */ | |
e315cd28 AC |
3203 | loop_id = ha->min_external_loopid; |
3204 | for (; loop_id <= ha->max_loop_id; loop_id++) { | |
3205 | if (qla2x00_is_reserved_id(vha, loop_id)) | |
1da177e4 LT |
3206 | continue; |
3207 | ||
3a6478df GM |
3208 | if (ha->current_topology == ISP_CFG_FL && |
3209 | (atomic_read(&vha->loop_down_timer) || | |
3210 | LOOP_TRANSITION(vha))) { | |
bb2d52b2 AV |
3211 | atomic_set(&vha->loop_down_timer, 0); |
3212 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); | |
3213 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); | |
1da177e4 | 3214 | break; |
bb2d52b2 | 3215 | } |
1da177e4 LT |
3216 | |
3217 | if (swl != NULL) { | |
3218 | if (last_dev) { | |
3219 | wrap.b24 = new_fcport->d_id.b24; | |
3220 | } else { | |
3221 | new_fcport->d_id.b24 = swl[swl_idx].d_id.b24; | |
3222 | memcpy(new_fcport->node_name, | |
3223 | swl[swl_idx].node_name, WWN_SIZE); | |
3224 | memcpy(new_fcport->port_name, | |
3225 | swl[swl_idx].port_name, WWN_SIZE); | |
d8b45213 AV |
3226 | memcpy(new_fcport->fabric_port_name, |
3227 | swl[swl_idx].fabric_port_name, WWN_SIZE); | |
3228 | new_fcport->fp_speed = swl[swl_idx].fp_speed; | |
e8c72ba5 | 3229 | new_fcport->fc4_type = swl[swl_idx].fc4_type; |
1da177e4 LT |
3230 | |
3231 | if (swl[swl_idx].d_id.b.rsvd_1 != 0) { | |
3232 | last_dev = 1; | |
3233 | } | |
3234 | swl_idx++; | |
3235 | } | |
3236 | } else { | |
3237 | /* Send GA_NXT to the switch */ | |
e315cd28 | 3238 | rval = qla2x00_ga_nxt(vha, new_fcport); |
1da177e4 LT |
3239 | if (rval != QLA_SUCCESS) { |
3240 | qla_printk(KERN_WARNING, ha, | |
3241 | "SNS scan failed -- assuming zero-entry " | |
3242 | "result...\n"); | |
3243 | list_for_each_entry_safe(fcport, fcptemp, | |
3244 | new_fcports, list) { | |
3245 | list_del(&fcport->list); | |
3246 | kfree(fcport); | |
3247 | } | |
3248 | rval = QLA_SUCCESS; | |
3249 | break; | |
3250 | } | |
3251 | } | |
3252 | ||
3253 | /* If wrap on switch device list, exit. */ | |
3254 | if (first_dev) { | |
3255 | wrap.b24 = new_fcport->d_id.b24; | |
3256 | first_dev = 0; | |
3257 | } else if (new_fcport->d_id.b24 == wrap.b24) { | |
3258 | DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n", | |
e315cd28 | 3259 | vha->host_no, new_fcport->d_id.b.domain, |
1da177e4 LT |
3260 | new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa)); |
3261 | break; | |
3262 | } | |
3263 | ||
2c3dfe3f | 3264 | /* Bypass if same physical adapter. */ |
e315cd28 | 3265 | if (new_fcport->d_id.b24 == base_vha->d_id.b24) |
1da177e4 LT |
3266 | continue; |
3267 | ||
2c3dfe3f | 3268 | /* Bypass virtual ports of the same host. */ |
e315cd28 AC |
3269 | found = 0; |
3270 | if (ha->num_vhosts) { | |
feafb7b1 AE |
3271 | unsigned long flags; |
3272 | ||
3273 | spin_lock_irqsave(&ha->vport_slock, flags); | |
ee546b6e | 3274 | list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) { |
e315cd28 AC |
3275 | if (new_fcport->d_id.b24 == vp->d_id.b24) { |
3276 | found = 1; | |
2c3dfe3f | 3277 | break; |
e315cd28 | 3278 | } |
2c3dfe3f | 3279 | } |
feafb7b1 AE |
3280 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
3281 | ||
e315cd28 | 3282 | if (found) |
2c3dfe3f SJ |
3283 | continue; |
3284 | } | |
3285 | ||
f7d289f6 AV |
3286 | /* Bypass if same domain and area of adapter. */ |
3287 | if (((new_fcport->d_id.b24 & 0xffff00) == | |
e315cd28 | 3288 | (vha->d_id.b24 & 0xffff00)) && ha->current_topology == |
f7d289f6 AV |
3289 | ISP_CFG_FL) |
3290 | continue; | |
3291 | ||
1da177e4 LT |
3292 | /* Bypass reserved domain fields. */ |
3293 | if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0) | |
3294 | continue; | |
3295 | ||
e8c72ba5 | 3296 | /* Bypass ports whose FCP-4 type is not FCP_SCSI */ |
4da26e16 CD |
3297 | if (ql2xgffidenable && |
3298 | (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI && | |
3299 | new_fcport->fc4_type != FC4_TYPE_UNKNOWN)) | |
e8c72ba5 CD |
3300 | continue; |
3301 | ||
1da177e4 LT |
3302 | /* Locate matching device in database. */ |
3303 | found = 0; | |
e315cd28 | 3304 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
1da177e4 LT |
3305 | if (memcmp(new_fcport->port_name, fcport->port_name, |
3306 | WWN_SIZE)) | |
3307 | continue; | |
3308 | ||
3309 | found++; | |
3310 | ||
d8b45213 AV |
3311 | /* Update port state. */ |
3312 | memcpy(fcport->fabric_port_name, | |
3313 | new_fcport->fabric_port_name, WWN_SIZE); | |
3314 | fcport->fp_speed = new_fcport->fp_speed; | |
3315 | ||
1da177e4 LT |
3316 | /* |
3317 | * If address the same and state FCS_ONLINE, nothing | |
3318 | * changed. | |
3319 | */ | |
3320 | if (fcport->d_id.b24 == new_fcport->d_id.b24 && | |
3321 | atomic_read(&fcport->state) == FCS_ONLINE) { | |
3322 | break; | |
3323 | } | |
3324 | ||
3325 | /* | |
3326 | * If device was not a fabric device before. | |
3327 | */ | |
3328 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) { | |
3329 | fcport->d_id.b24 = new_fcport->d_id.b24; | |
3330 | fcport->loop_id = FC_NO_LOOP_ID; | |
3331 | fcport->flags |= (FCF_FABRIC_DEVICE | | |
3332 | FCF_LOGIN_NEEDED); | |
1da177e4 LT |
3333 | break; |
3334 | } | |
3335 | ||
3336 | /* | |
3337 | * Port ID changed or device was marked to be updated; | |
3338 | * Log it out if still logged in and mark it for | |
3339 | * relogin later. | |
3340 | */ | |
3341 | fcport->d_id.b24 = new_fcport->d_id.b24; | |
3342 | fcport->flags |= FCF_LOGIN_NEEDED; | |
3343 | if (fcport->loop_id != FC_NO_LOOP_ID && | |
f08b7251 | 3344 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
1da177e4 LT |
3345 | fcport->port_type != FCT_INITIATOR && |
3346 | fcport->port_type != FCT_BROADCAST) { | |
e315cd28 | 3347 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
1c7c6357 AV |
3348 | fcport->d_id.b.domain, fcport->d_id.b.area, |
3349 | fcport->d_id.b.al_pa); | |
1da177e4 LT |
3350 | fcport->loop_id = FC_NO_LOOP_ID; |
3351 | } | |
3352 | ||
3353 | break; | |
3354 | } | |
3355 | ||
3356 | if (found) | |
3357 | continue; | |
1da177e4 LT |
3358 | /* If device was not in our fcports list, then add it. */ |
3359 | list_add_tail(&new_fcport->list, new_fcports); | |
3360 | ||
3361 | /* Allocate a new replacement fcport. */ | |
3362 | nxt_d_id.b24 = new_fcport->d_id.b24; | |
e315cd28 | 3363 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
1da177e4 | 3364 | if (new_fcport == NULL) { |
c9475cb0 | 3365 | kfree(swl); |
1da177e4 LT |
3366 | return (QLA_MEMORY_ALLOC_FAILED); |
3367 | } | |
3368 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); | |
3369 | new_fcport->d_id.b24 = nxt_d_id.b24; | |
3370 | } | |
3371 | ||
c9475cb0 JJ |
3372 | kfree(swl); |
3373 | kfree(new_fcport); | |
1da177e4 | 3374 | |
1da177e4 LT |
3375 | return (rval); |
3376 | } | |
3377 | ||
3378 | /* | |
3379 | * qla2x00_find_new_loop_id | |
3380 | * Scan through our port list and find a new usable loop ID. | |
3381 | * | |
3382 | * Input: | |
3383 | * ha: adapter state pointer. | |
3384 | * dev: port structure pointer. | |
3385 | * | |
3386 | * Returns: | |
3387 | * qla2x00 local function return status code. | |
3388 | * | |
3389 | * Context: | |
3390 | * Kernel context. | |
3391 | */ | |
413975a0 | 3392 | static int |
e315cd28 | 3393 | qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev) |
1da177e4 LT |
3394 | { |
3395 | int rval; | |
3396 | int found; | |
3397 | fc_port_t *fcport; | |
3398 | uint16_t first_loop_id; | |
e315cd28 AC |
3399 | struct qla_hw_data *ha = vha->hw; |
3400 | struct scsi_qla_host *vp; | |
ee546b6e | 3401 | struct scsi_qla_host *tvp; |
feafb7b1 | 3402 | unsigned long flags = 0; |
1da177e4 LT |
3403 | |
3404 | rval = QLA_SUCCESS; | |
3405 | ||
3406 | /* Save starting loop ID. */ | |
3407 | first_loop_id = dev->loop_id; | |
3408 | ||
3409 | for (;;) { | |
3410 | /* Skip loop ID if already used by adapter. */ | |
e315cd28 | 3411 | if (dev->loop_id == vha->loop_id) |
1da177e4 | 3412 | dev->loop_id++; |
1da177e4 LT |
3413 | |
3414 | /* Skip reserved loop IDs. */ | |
e315cd28 | 3415 | while (qla2x00_is_reserved_id(vha, dev->loop_id)) |
1da177e4 | 3416 | dev->loop_id++; |
1da177e4 LT |
3417 | |
3418 | /* Reset loop ID if passed the end. */ | |
e315cd28 | 3419 | if (dev->loop_id > ha->max_loop_id) { |
1da177e4 LT |
3420 | /* first loop ID. */ |
3421 | dev->loop_id = ha->min_external_loopid; | |
3422 | } | |
3423 | ||
3424 | /* Check for loop ID being already in use. */ | |
3425 | found = 0; | |
3426 | fcport = NULL; | |
feafb7b1 AE |
3427 | |
3428 | spin_lock_irqsave(&ha->vport_slock, flags); | |
ee546b6e | 3429 | list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) { |
e315cd28 AC |
3430 | list_for_each_entry(fcport, &vp->vp_fcports, list) { |
3431 | if (fcport->loop_id == dev->loop_id && | |
3432 | fcport != dev) { | |
3433 | /* ID possibly in use */ | |
3434 | found++; | |
3435 | break; | |
3436 | } | |
1da177e4 | 3437 | } |
e315cd28 AC |
3438 | if (found) |
3439 | break; | |
1da177e4 | 3440 | } |
feafb7b1 | 3441 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
1da177e4 LT |
3442 | |
3443 | /* If not in use then it is free to use. */ | |
3444 | if (!found) { | |
3445 | break; | |
3446 | } | |
3447 | ||
3448 | /* ID in use. Try next value. */ | |
3449 | dev->loop_id++; | |
3450 | ||
3451 | /* If wrap around. No free ID to use. */ | |
3452 | if (dev->loop_id == first_loop_id) { | |
3453 | dev->loop_id = FC_NO_LOOP_ID; | |
3454 | rval = QLA_FUNCTION_FAILED; | |
3455 | break; | |
3456 | } | |
3457 | } | |
3458 | ||
3459 | return (rval); | |
3460 | } | |
3461 | ||
3462 | /* | |
3463 | * qla2x00_device_resync | |
3464 | * Marks devices in the database that needs resynchronization. | |
3465 | * | |
3466 | * Input: | |
3467 | * ha = adapter block pointer. | |
3468 | * | |
3469 | * Context: | |
3470 | * Kernel context. | |
3471 | */ | |
3472 | static int | |
e315cd28 | 3473 | qla2x00_device_resync(scsi_qla_host_t *vha) |
1da177e4 LT |
3474 | { |
3475 | int rval; | |
1da177e4 LT |
3476 | uint32_t mask; |
3477 | fc_port_t *fcport; | |
3478 | uint32_t rscn_entry; | |
3479 | uint8_t rscn_out_iter; | |
3480 | uint8_t format; | |
1516ef44 | 3481 | port_id_t d_id = {}; |
1da177e4 LT |
3482 | |
3483 | rval = QLA_RSCNS_HANDLED; | |
3484 | ||
e315cd28 AC |
3485 | while (vha->rscn_out_ptr != vha->rscn_in_ptr || |
3486 | vha->flags.rscn_queue_overflow) { | |
1da177e4 | 3487 | |
e315cd28 | 3488 | rscn_entry = vha->rscn_queue[vha->rscn_out_ptr]; |
1da177e4 LT |
3489 | format = MSB(MSW(rscn_entry)); |
3490 | d_id.b.domain = LSB(MSW(rscn_entry)); | |
3491 | d_id.b.area = MSB(LSW(rscn_entry)); | |
3492 | d_id.b.al_pa = LSB(LSW(rscn_entry)); | |
3493 | ||
3494 | DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = " | |
3495 | "[%02x/%02x%02x%02x].\n", | |
e315cd28 | 3496 | vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain, |
1da177e4 LT |
3497 | d_id.b.area, d_id.b.al_pa)); |
3498 | ||
e315cd28 AC |
3499 | vha->rscn_out_ptr++; |
3500 | if (vha->rscn_out_ptr == MAX_RSCN_COUNT) | |
3501 | vha->rscn_out_ptr = 0; | |
1da177e4 LT |
3502 | |
3503 | /* Skip duplicate entries. */ | |
e315cd28 AC |
3504 | for (rscn_out_iter = vha->rscn_out_ptr; |
3505 | !vha->flags.rscn_queue_overflow && | |
3506 | rscn_out_iter != vha->rscn_in_ptr; | |
1da177e4 LT |
3507 | rscn_out_iter = (rscn_out_iter == |
3508 | (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) { | |
3509 | ||
e315cd28 | 3510 | if (rscn_entry != vha->rscn_queue[rscn_out_iter]) |
1da177e4 LT |
3511 | break; |
3512 | ||
3513 | DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue " | |
e315cd28 | 3514 | "entry found at [%d].\n", vha->host_no, |
1da177e4 LT |
3515 | rscn_out_iter)); |
3516 | ||
e315cd28 | 3517 | vha->rscn_out_ptr = rscn_out_iter; |
1da177e4 LT |
3518 | } |
3519 | ||
3520 | /* Queue overflow, set switch default case. */ | |
e315cd28 | 3521 | if (vha->flags.rscn_queue_overflow) { |
1da177e4 | 3522 | DEBUG(printk("scsi(%ld): device_resync: rscn " |
e315cd28 | 3523 | "overflow.\n", vha->host_no)); |
1da177e4 LT |
3524 | |
3525 | format = 3; | |
e315cd28 | 3526 | vha->flags.rscn_queue_overflow = 0; |
1da177e4 LT |
3527 | } |
3528 | ||
3529 | switch (format) { | |
3530 | case 0: | |
1da177e4 LT |
3531 | mask = 0xffffff; |
3532 | break; | |
3533 | case 1: | |
3534 | mask = 0xffff00; | |
3535 | break; | |
3536 | case 2: | |
3537 | mask = 0xff0000; | |
3538 | break; | |
3539 | default: | |
3540 | mask = 0x0; | |
3541 | d_id.b24 = 0; | |
e315cd28 | 3542 | vha->rscn_out_ptr = vha->rscn_in_ptr; |
1da177e4 LT |
3543 | break; |
3544 | } | |
3545 | ||
3546 | rval = QLA_SUCCESS; | |
3547 | ||
e315cd28 | 3548 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
1da177e4 LT |
3549 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 || |
3550 | (fcport->d_id.b24 & mask) != d_id.b24 || | |
3551 | fcport->port_type == FCT_BROADCAST) | |
3552 | continue; | |
3553 | ||
3554 | if (atomic_read(&fcport->state) == FCS_ONLINE) { | |
3555 | if (format != 3 || | |
3556 | fcport->port_type != FCT_INITIATOR) { | |
e315cd28 | 3557 | qla2x00_mark_device_lost(vha, fcport, |
d97994dc | 3558 | 0, 0); |
1da177e4 LT |
3559 | } |
3560 | } | |
1da177e4 LT |
3561 | } |
3562 | } | |
3563 | return (rval); | |
3564 | } | |
3565 | ||
3566 | /* | |
3567 | * qla2x00_fabric_dev_login | |
3568 | * Login fabric target device and update FC port database. | |
3569 | * | |
3570 | * Input: | |
3571 | * ha: adapter state pointer. | |
3572 | * fcport: port structure list pointer. | |
3573 | * next_loopid: contains value of a new loop ID that can be used | |
3574 | * by the next login attempt. | |
3575 | * | |
3576 | * Returns: | |
3577 | * qla2x00 local function return status code. | |
3578 | * | |
3579 | * Context: | |
3580 | * Kernel context. | |
3581 | */ | |
3582 | static int | |
e315cd28 | 3583 | qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport, |
1da177e4 LT |
3584 | uint16_t *next_loopid) |
3585 | { | |
3586 | int rval; | |
3587 | int retry; | |
0107109e | 3588 | uint8_t opts; |
e315cd28 | 3589 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
3590 | |
3591 | rval = QLA_SUCCESS; | |
3592 | retry = 0; | |
3593 | ||
ac280b67 | 3594 | if (IS_ALOGIO_CAPABLE(ha)) { |
5ff1d584 AV |
3595 | if (fcport->flags & FCF_ASYNC_SENT) |
3596 | return rval; | |
3597 | fcport->flags |= FCF_ASYNC_SENT; | |
ac280b67 AV |
3598 | rval = qla2x00_post_async_login_work(vha, fcport, NULL); |
3599 | if (!rval) | |
3600 | return rval; | |
3601 | } | |
3602 | ||
5ff1d584 | 3603 | fcport->flags &= ~FCF_ASYNC_SENT; |
e315cd28 | 3604 | rval = qla2x00_fabric_login(vha, fcport, next_loopid); |
1da177e4 | 3605 | if (rval == QLA_SUCCESS) { |
f08b7251 | 3606 | /* Send an ADISC to FCP2 devices.*/ |
0107109e | 3607 | opts = 0; |
f08b7251 | 3608 | if (fcport->flags & FCF_FCP2_DEVICE) |
0107109e | 3609 | opts |= BIT_1; |
e315cd28 | 3610 | rval = qla2x00_get_port_database(vha, fcport, opts); |
1da177e4 | 3611 | if (rval != QLA_SUCCESS) { |
e315cd28 | 3612 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
1c7c6357 AV |
3613 | fcport->d_id.b.domain, fcport->d_id.b.area, |
3614 | fcport->d_id.b.al_pa); | |
e315cd28 | 3615 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
1da177e4 | 3616 | } else { |
e315cd28 | 3617 | qla2x00_update_fcport(vha, fcport); |
1da177e4 LT |
3618 | } |
3619 | } | |
3620 | ||
3621 | return (rval); | |
3622 | } | |
3623 | ||
3624 | /* | |
3625 | * qla2x00_fabric_login | |
3626 | * Issue fabric login command. | |
3627 | * | |
3628 | * Input: | |
3629 | * ha = adapter block pointer. | |
3630 | * device = pointer to FC device type structure. | |
3631 | * | |
3632 | * Returns: | |
3633 | * 0 - Login successfully | |
3634 | * 1 - Login failed | |
3635 | * 2 - Initiator device | |
3636 | * 3 - Fatal error | |
3637 | */ | |
3638 | int | |
e315cd28 | 3639 | qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport, |
1da177e4 LT |
3640 | uint16_t *next_loopid) |
3641 | { | |
3642 | int rval; | |
3643 | int retry; | |
3644 | uint16_t tmp_loopid; | |
3645 | uint16_t mb[MAILBOX_REGISTER_COUNT]; | |
e315cd28 | 3646 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
3647 | |
3648 | retry = 0; | |
3649 | tmp_loopid = 0; | |
3650 | ||
3651 | for (;;) { | |
3652 | DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x " | |
3653 | "for port %02x%02x%02x.\n", | |
e315cd28 | 3654 | vha->host_no, fcport->loop_id, fcport->d_id.b.domain, |
1da177e4 LT |
3655 | fcport->d_id.b.area, fcport->d_id.b.al_pa)); |
3656 | ||
3657 | /* Login fcport on switch. */ | |
e315cd28 | 3658 | ha->isp_ops->fabric_login(vha, fcport->loop_id, |
1da177e4 LT |
3659 | fcport->d_id.b.domain, fcport->d_id.b.area, |
3660 | fcport->d_id.b.al_pa, mb, BIT_0); | |
3661 | if (mb[0] == MBS_PORT_ID_USED) { | |
3662 | /* | |
3663 | * Device has another loop ID. The firmware team | |
0107109e AV |
3664 | * recommends the driver perform an implicit login with |
3665 | * the specified ID again. The ID we just used is save | |
3666 | * here so we return with an ID that can be tried by | |
3667 | * the next login. | |
1da177e4 LT |
3668 | */ |
3669 | retry++; | |
3670 | tmp_loopid = fcport->loop_id; | |
3671 | fcport->loop_id = mb[1]; | |
3672 | ||
3673 | DEBUG(printk("Fabric Login: port in use - next " | |
3674 | "loop id=0x%04x, port Id=%02x%02x%02x.\n", | |
3675 | fcport->loop_id, fcport->d_id.b.domain, | |
3676 | fcport->d_id.b.area, fcport->d_id.b.al_pa)); | |
3677 | ||
3678 | } else if (mb[0] == MBS_COMMAND_COMPLETE) { | |
3679 | /* | |
3680 | * Login succeeded. | |
3681 | */ | |
3682 | if (retry) { | |
3683 | /* A retry occurred before. */ | |
3684 | *next_loopid = tmp_loopid; | |
3685 | } else { | |
3686 | /* | |
3687 | * No retry occurred before. Just increment the | |
3688 | * ID value for next login. | |
3689 | */ | |
3690 | *next_loopid = (fcport->loop_id + 1); | |
3691 | } | |
3692 | ||
3693 | if (mb[1] & BIT_0) { | |
3694 | fcport->port_type = FCT_INITIATOR; | |
3695 | } else { | |
3696 | fcport->port_type = FCT_TARGET; | |
3697 | if (mb[1] & BIT_1) { | |
8474f3a0 | 3698 | fcport->flags |= FCF_FCP2_DEVICE; |
1da177e4 LT |
3699 | } |
3700 | } | |
3701 | ||
ad3e0eda AV |
3702 | if (mb[10] & BIT_0) |
3703 | fcport->supported_classes |= FC_COS_CLASS2; | |
3704 | if (mb[10] & BIT_1) | |
3705 | fcport->supported_classes |= FC_COS_CLASS3; | |
3706 | ||
1da177e4 LT |
3707 | rval = QLA_SUCCESS; |
3708 | break; | |
3709 | } else if (mb[0] == MBS_LOOP_ID_USED) { | |
3710 | /* | |
3711 | * Loop ID already used, try next loop ID. | |
3712 | */ | |
3713 | fcport->loop_id++; | |
e315cd28 | 3714 | rval = qla2x00_find_new_loop_id(vha, fcport); |
1da177e4 LT |
3715 | if (rval != QLA_SUCCESS) { |
3716 | /* Ran out of loop IDs to use */ | |
3717 | break; | |
3718 | } | |
3719 | } else if (mb[0] == MBS_COMMAND_ERROR) { | |
3720 | /* | |
3721 | * Firmware possibly timed out during login. If NO | |
3722 | * retries are left to do then the device is declared | |
3723 | * dead. | |
3724 | */ | |
3725 | *next_loopid = fcport->loop_id; | |
e315cd28 | 3726 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
1c7c6357 AV |
3727 | fcport->d_id.b.domain, fcport->d_id.b.area, |
3728 | fcport->d_id.b.al_pa); | |
e315cd28 | 3729 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
1da177e4 LT |
3730 | |
3731 | rval = 1; | |
3732 | break; | |
3733 | } else { | |
3734 | /* | |
3735 | * unrecoverable / not handled error | |
3736 | */ | |
3737 | DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x " | |
fa2a1ce5 | 3738 | "loop_id=%x jiffies=%lx.\n", |
e315cd28 | 3739 | __func__, vha->host_no, mb[0], |
1da177e4 LT |
3740 | fcport->d_id.b.domain, fcport->d_id.b.area, |
3741 | fcport->d_id.b.al_pa, fcport->loop_id, jiffies)); | |
3742 | ||
3743 | *next_loopid = fcport->loop_id; | |
e315cd28 | 3744 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
1c7c6357 AV |
3745 | fcport->d_id.b.domain, fcport->d_id.b.area, |
3746 | fcport->d_id.b.al_pa); | |
1da177e4 | 3747 | fcport->loop_id = FC_NO_LOOP_ID; |
0eedfcf0 | 3748 | fcport->login_retry = 0; |
1da177e4 LT |
3749 | |
3750 | rval = 3; | |
3751 | break; | |
3752 | } | |
3753 | } | |
3754 | ||
3755 | return (rval); | |
3756 | } | |
3757 | ||
3758 | /* | |
3759 | * qla2x00_local_device_login | |
3760 | * Issue local device login command. | |
3761 | * | |
3762 | * Input: | |
3763 | * ha = adapter block pointer. | |
3764 | * loop_id = loop id of device to login to. | |
3765 | * | |
3766 | * Returns (Where's the #define!!!!): | |
3767 | * 0 - Login successfully | |
3768 | * 1 - Login failed | |
3769 | * 3 - Fatal error | |
3770 | */ | |
3771 | int | |
e315cd28 | 3772 | qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport) |
1da177e4 LT |
3773 | { |
3774 | int rval; | |
3775 | uint16_t mb[MAILBOX_REGISTER_COUNT]; | |
3776 | ||
3777 | memset(mb, 0, sizeof(mb)); | |
e315cd28 | 3778 | rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0); |
1da177e4 LT |
3779 | if (rval == QLA_SUCCESS) { |
3780 | /* Interrogate mailbox registers for any errors */ | |
3781 | if (mb[0] == MBS_COMMAND_ERROR) | |
3782 | rval = 1; | |
3783 | else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR) | |
3784 | /* device not in PCB table */ | |
3785 | rval = 3; | |
3786 | } | |
3787 | ||
3788 | return (rval); | |
3789 | } | |
3790 | ||
3791 | /* | |
3792 | * qla2x00_loop_resync | |
3793 | * Resync with fibre channel devices. | |
3794 | * | |
3795 | * Input: | |
3796 | * ha = adapter block pointer. | |
3797 | * | |
3798 | * Returns: | |
3799 | * 0 = success | |
3800 | */ | |
3801 | int | |
e315cd28 | 3802 | qla2x00_loop_resync(scsi_qla_host_t *vha) |
1da177e4 | 3803 | { |
73208dfd | 3804 | int rval = QLA_SUCCESS; |
1da177e4 | 3805 | uint32_t wait_time; |
67c2e93a AC |
3806 | struct req_que *req; |
3807 | struct rsp_que *rsp; | |
3808 | ||
7163ea81 | 3809 | if (vha->hw->flags.cpu_affinity_enabled) |
67c2e93a AC |
3810 | req = vha->hw->req_q_map[0]; |
3811 | else | |
3812 | req = vha->req; | |
3813 | rsp = req->rsp; | |
1da177e4 | 3814 | |
e315cd28 AC |
3815 | atomic_set(&vha->loop_state, LOOP_UPDATE); |
3816 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); | |
3817 | if (vha->flags.online) { | |
3818 | if (!(rval = qla2x00_fw_ready(vha))) { | |
1da177e4 LT |
3819 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
3820 | wait_time = 256; | |
3821 | do { | |
e315cd28 | 3822 | atomic_set(&vha->loop_state, LOOP_UPDATE); |
1da177e4 | 3823 | |
0107109e | 3824 | /* Issue a marker after FW becomes ready. */ |
73208dfd AC |
3825 | qla2x00_marker(vha, req, rsp, 0, 0, |
3826 | MK_SYNC_ALL); | |
e315cd28 | 3827 | vha->marker_needed = 0; |
1da177e4 LT |
3828 | |
3829 | /* Remap devices on Loop. */ | |
e315cd28 | 3830 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
1da177e4 | 3831 | |
e315cd28 | 3832 | qla2x00_configure_loop(vha); |
1da177e4 | 3833 | wait_time--; |
e315cd28 AC |
3834 | } while (!atomic_read(&vha->loop_down_timer) && |
3835 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) | |
3836 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, | |
3837 | &vha->dpc_flags))); | |
1da177e4 | 3838 | } |
1da177e4 LT |
3839 | } |
3840 | ||
e315cd28 | 3841 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
1da177e4 | 3842 | return (QLA_FUNCTION_FAILED); |
1da177e4 | 3843 | |
e315cd28 | 3844 | if (rval) |
1da177e4 | 3845 | DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__)); |
1da177e4 LT |
3846 | |
3847 | return (rval); | |
3848 | } | |
3849 | ||
579d12b5 SK |
3850 | /* |
3851 | * qla2x00_perform_loop_resync | |
3852 | * Description: This function will set the appropriate flags and call | |
3853 | * qla2x00_loop_resync. If successful loop will be resynced | |
3854 | * Arguments : scsi_qla_host_t pointer | |
3855 | * returm : Success or Failure | |
3856 | */ | |
3857 | ||
3858 | int qla2x00_perform_loop_resync(scsi_qla_host_t *ha) | |
3859 | { | |
3860 | int32_t rval = 0; | |
3861 | ||
3862 | if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) { | |
3863 | /*Configure the flags so that resync happens properly*/ | |
3864 | atomic_set(&ha->loop_down_timer, 0); | |
3865 | if (!(ha->device_flags & DFLG_NO_CABLE)) { | |
3866 | atomic_set(&ha->loop_state, LOOP_UP); | |
3867 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); | |
3868 | set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags); | |
3869 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); | |
3870 | ||
3871 | rval = qla2x00_loop_resync(ha); | |
3872 | } else | |
3873 | atomic_set(&ha->loop_state, LOOP_DEAD); | |
3874 | ||
3875 | clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags); | |
3876 | } | |
3877 | ||
3878 | return rval; | |
3879 | } | |
3880 | ||
d97994dc | 3881 | void |
67becc00 | 3882 | qla2x00_update_fcports(scsi_qla_host_t *base_vha) |
d97994dc AV |
3883 | { |
3884 | fc_port_t *fcport; | |
feafb7b1 AE |
3885 | struct scsi_qla_host *vha; |
3886 | struct qla_hw_data *ha = base_vha->hw; | |
3887 | unsigned long flags; | |
d97994dc | 3888 | |
feafb7b1 | 3889 | spin_lock_irqsave(&ha->vport_slock, flags); |
d97994dc | 3890 | /* Go with deferred removal of rport references. */ |
feafb7b1 AE |
3891 | list_for_each_entry(vha, &base_vha->hw->vp_list, list) { |
3892 | atomic_inc(&vha->vref_count); | |
3893 | list_for_each_entry(fcport, &vha->vp_fcports, list) { | |
8ae598d0 | 3894 | if (fcport->drport && |
feafb7b1 AE |
3895 | atomic_read(&fcport->state) != FCS_UNCONFIGURED) { |
3896 | spin_unlock_irqrestore(&ha->vport_slock, flags); | |
3897 | ||
67becc00 | 3898 | qla2x00_rport_del(fcport); |
feafb7b1 AE |
3899 | |
3900 | spin_lock_irqsave(&ha->vport_slock, flags); | |
3901 | } | |
3902 | } | |
3903 | atomic_dec(&vha->vref_count); | |
3904 | } | |
3905 | spin_unlock_irqrestore(&ha->vport_slock, flags); | |
d97994dc AV |
3906 | } |
3907 | ||
579d12b5 SK |
3908 | /* |
3909 | * qla82xx_quiescent_state_cleanup | |
3910 | * Description: This function will block the new I/Os | |
3911 | * Its not aborting any I/Os as context | |
3912 | * is not destroyed during quiescence | |
3913 | * Arguments: scsi_qla_host_t | |
3914 | * return : void | |
3915 | */ | |
3916 | void | |
3917 | qla82xx_quiescent_state_cleanup(scsi_qla_host_t *vha) | |
3918 | { | |
3919 | struct qla_hw_data *ha = vha->hw; | |
3920 | struct scsi_qla_host *vp; | |
3921 | ||
3922 | qla_printk(KERN_INFO, ha, | |
3923 | "Performing ISP error recovery - ha= %p.\n", ha); | |
3924 | ||
3925 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); | |
3926 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { | |
3927 | atomic_set(&vha->loop_state, LOOP_DOWN); | |
3928 | qla2x00_mark_all_devices_lost(vha, 0); | |
3929 | list_for_each_entry(vp, &ha->vp_list, list) | |
3930 | qla2x00_mark_all_devices_lost(vha, 0); | |
3931 | } else { | |
3932 | if (!atomic_read(&vha->loop_down_timer)) | |
3933 | atomic_set(&vha->loop_down_timer, | |
3934 | LOOP_DOWN_TIME); | |
3935 | } | |
3936 | /* Wait for pending cmds to complete */ | |
3937 | qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST); | |
3938 | } | |
3939 | ||
a9083016 GM |
3940 | void |
3941 | qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha) | |
3942 | { | |
3943 | struct qla_hw_data *ha = vha->hw; | |
579d12b5 | 3944 | struct scsi_qla_host *vp; |
feafb7b1 | 3945 | unsigned long flags; |
a9083016 GM |
3946 | |
3947 | vha->flags.online = 0; | |
3948 | ha->flags.chip_reset_done = 0; | |
3949 | clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | |
3950 | ha->qla_stats.total_isp_aborts++; | |
3951 | ||
3952 | qla_printk(KERN_INFO, ha, | |
3953 | "Performing ISP error recovery - ha= %p.\n", ha); | |
3954 | ||
3955 | /* Chip reset does not apply to 82XX */ | |
3956 | if (!IS_QLA82XX(ha)) | |
3957 | ha->isp_ops->reset_chip(vha); | |
3958 | ||
3959 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); | |
3960 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { | |
3961 | atomic_set(&vha->loop_state, LOOP_DOWN); | |
3962 | qla2x00_mark_all_devices_lost(vha, 0); | |
feafb7b1 AE |
3963 | |
3964 | spin_lock_irqsave(&ha->vport_slock, flags); | |
579d12b5 | 3965 | list_for_each_entry(vp, &ha->vp_list, list) { |
feafb7b1 AE |
3966 | atomic_inc(&vp->vref_count); |
3967 | spin_unlock_irqrestore(&ha->vport_slock, flags); | |
3968 | ||
a9083016 | 3969 | qla2x00_mark_all_devices_lost(vp, 0); |
feafb7b1 AE |
3970 | |
3971 | spin_lock_irqsave(&ha->vport_slock, flags); | |
3972 | atomic_dec(&vp->vref_count); | |
3973 | } | |
3974 | spin_unlock_irqrestore(&ha->vport_slock, flags); | |
a9083016 GM |
3975 | } else { |
3976 | if (!atomic_read(&vha->loop_down_timer)) | |
3977 | atomic_set(&vha->loop_down_timer, | |
3978 | LOOP_DOWN_TIME); | |
3979 | } | |
3980 | ||
bddd2d65 LC |
3981 | if (!ha->flags.eeh_busy) { |
3982 | /* Make sure for ISP 82XX IO DMA is complete */ | |
3983 | if (IS_QLA82XX(ha)) { | |
3984 | if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, | |
3985 | WAIT_HOST) == QLA_SUCCESS) { | |
3986 | DEBUG2(qla_printk(KERN_INFO, ha, | |
3987 | "Done wait for pending commands\n")); | |
3988 | } | |
4d78c973 | 3989 | } |
a9083016 | 3990 | |
bddd2d65 LC |
3991 | /* Requeue all commands in outstanding command list. */ |
3992 | qla2x00_abort_all_cmds(vha, DID_RESET << 16); | |
3993 | } | |
a9083016 GM |
3994 | } |
3995 | ||
1da177e4 LT |
3996 | /* |
3997 | * qla2x00_abort_isp | |
3998 | * Resets ISP and aborts all outstanding commands. | |
3999 | * | |
4000 | * Input: | |
4001 | * ha = adapter block pointer. | |
4002 | * | |
4003 | * Returns: | |
4004 | * 0 = success | |
4005 | */ | |
4006 | int | |
e315cd28 | 4007 | qla2x00_abort_isp(scsi_qla_host_t *vha) |
1da177e4 | 4008 | { |
476e8978 | 4009 | int rval; |
1da177e4 | 4010 | uint8_t status = 0; |
e315cd28 AC |
4011 | struct qla_hw_data *ha = vha->hw; |
4012 | struct scsi_qla_host *vp; | |
73208dfd | 4013 | struct req_que *req = ha->req_q_map[0]; |
feafb7b1 | 4014 | unsigned long flags; |
1da177e4 | 4015 | |
e315cd28 | 4016 | if (vha->flags.online) { |
a9083016 | 4017 | qla2x00_abort_isp_cleanup(vha); |
1da177e4 | 4018 | |
85880801 AV |
4019 | if (unlikely(pci_channel_offline(ha->pdev) && |
4020 | ha->flags.pci_channel_io_perm_failure)) { | |
4021 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); | |
4022 | status = 0; | |
4023 | return status; | |
4024 | } | |
4025 | ||
73208dfd | 4026 | ha->isp_ops->get_flash_version(vha, req->ring); |
30c47662 | 4027 | |
e315cd28 | 4028 | ha->isp_ops->nvram_config(vha); |
1da177e4 | 4029 | |
e315cd28 AC |
4030 | if (!qla2x00_restart_isp(vha)) { |
4031 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); | |
1da177e4 | 4032 | |
e315cd28 | 4033 | if (!atomic_read(&vha->loop_down_timer)) { |
1da177e4 LT |
4034 | /* |
4035 | * Issue marker command only when we are going | |
4036 | * to start the I/O . | |
4037 | */ | |
e315cd28 | 4038 | vha->marker_needed = 1; |
1da177e4 LT |
4039 | } |
4040 | ||
e315cd28 | 4041 | vha->flags.online = 1; |
1da177e4 | 4042 | |
fd34f556 | 4043 | ha->isp_ops->enable_intrs(ha); |
1da177e4 | 4044 | |
fa2a1ce5 | 4045 | ha->isp_abort_cnt = 0; |
e315cd28 | 4046 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
476e8978 | 4047 | |
29c5397f LC |
4048 | if (IS_QLA81XX(ha)) |
4049 | qla2x00_get_fw_version(vha, | |
4050 | &ha->fw_major_version, | |
4051 | &ha->fw_minor_version, | |
4052 | &ha->fw_subminor_version, | |
4053 | &ha->fw_attributes, &ha->fw_memory_size, | |
4054 | ha->mpi_version, &ha->mpi_capabilities, | |
4055 | ha->phy_version); | |
4056 | ||
df613b96 AV |
4057 | if (ha->fce) { |
4058 | ha->flags.fce_enabled = 1; | |
4059 | memset(ha->fce, 0, | |
4060 | fce_calc_size(ha->fce_bufs)); | |
e315cd28 | 4061 | rval = qla2x00_enable_fce_trace(vha, |
df613b96 AV |
4062 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
4063 | &ha->fce_bufs); | |
4064 | if (rval) { | |
4065 | qla_printk(KERN_WARNING, ha, | |
4066 | "Unable to reinitialize FCE " | |
4067 | "(%d).\n", rval); | |
4068 | ha->flags.fce_enabled = 0; | |
4069 | } | |
4070 | } | |
436a7b11 AV |
4071 | |
4072 | if (ha->eft) { | |
4073 | memset(ha->eft, 0, EFT_SIZE); | |
e315cd28 | 4074 | rval = qla2x00_enable_eft_trace(vha, |
436a7b11 AV |
4075 | ha->eft_dma, EFT_NUM_BUFFERS); |
4076 | if (rval) { | |
4077 | qla_printk(KERN_WARNING, ha, | |
4078 | "Unable to reinitialize EFT " | |
4079 | "(%d).\n", rval); | |
4080 | } | |
4081 | } | |
1da177e4 | 4082 | } else { /* failed the ISP abort */ |
e315cd28 AC |
4083 | vha->flags.online = 1; |
4084 | if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) { | |
1da177e4 LT |
4085 | if (ha->isp_abort_cnt == 0) { |
4086 | qla_printk(KERN_WARNING, ha, | |
4087 | "ISP error recovery failed - " | |
4088 | "board disabled\n"); | |
fa2a1ce5 | 4089 | /* |
1da177e4 LT |
4090 | * The next call disables the board |
4091 | * completely. | |
4092 | */ | |
e315cd28 AC |
4093 | ha->isp_ops->reset_adapter(vha); |
4094 | vha->flags.online = 0; | |
1da177e4 | 4095 | clear_bit(ISP_ABORT_RETRY, |
e315cd28 | 4096 | &vha->dpc_flags); |
1da177e4 LT |
4097 | status = 0; |
4098 | } else { /* schedule another ISP abort */ | |
4099 | ha->isp_abort_cnt--; | |
4100 | DEBUG(printk("qla%ld: ISP abort - " | |
0107109e | 4101 | "retry remaining %d\n", |
e315cd28 | 4102 | vha->host_no, ha->isp_abort_cnt)); |
1da177e4 LT |
4103 | status = 1; |
4104 | } | |
4105 | } else { | |
4106 | ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT; | |
4107 | DEBUG(printk("qla2x00(%ld): ISP error recovery " | |
4108 | "- retrying (%d) more times\n", | |
e315cd28 AC |
4109 | vha->host_no, ha->isp_abort_cnt)); |
4110 | set_bit(ISP_ABORT_RETRY, &vha->dpc_flags); | |
1da177e4 LT |
4111 | status = 1; |
4112 | } | |
4113 | } | |
fa2a1ce5 | 4114 | |
1da177e4 LT |
4115 | } |
4116 | ||
e315cd28 AC |
4117 | if (!status) { |
4118 | DEBUG(printk(KERN_INFO | |
4119 | "qla2x00_abort_isp(%ld): succeeded.\n", | |
4120 | vha->host_no)); | |
feafb7b1 AE |
4121 | |
4122 | spin_lock_irqsave(&ha->vport_slock, flags); | |
4123 | list_for_each_entry(vp, &ha->vp_list, list) { | |
4124 | if (vp->vp_idx) { | |
4125 | atomic_inc(&vp->vref_count); | |
4126 | spin_unlock_irqrestore(&ha->vport_slock, flags); | |
4127 | ||
e315cd28 | 4128 | qla2x00_vp_abort_isp(vp); |
feafb7b1 AE |
4129 | |
4130 | spin_lock_irqsave(&ha->vport_slock, flags); | |
4131 | atomic_dec(&vp->vref_count); | |
4132 | } | |
e315cd28 | 4133 | } |
feafb7b1 AE |
4134 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
4135 | ||
e315cd28 | 4136 | } else { |
1da177e4 LT |
4137 | qla_printk(KERN_INFO, ha, |
4138 | "qla2x00_abort_isp: **** FAILED ****\n"); | |
1da177e4 LT |
4139 | } |
4140 | ||
4141 | return(status); | |
4142 | } | |
4143 | ||
4144 | /* | |
4145 | * qla2x00_restart_isp | |
4146 | * restarts the ISP after a reset | |
4147 | * | |
4148 | * Input: | |
4149 | * ha = adapter block pointer. | |
4150 | * | |
4151 | * Returns: | |
4152 | * 0 = success | |
4153 | */ | |
4154 | static int | |
e315cd28 | 4155 | qla2x00_restart_isp(scsi_qla_host_t *vha) |
1da177e4 | 4156 | { |
c6b2fca8 | 4157 | int status = 0; |
1da177e4 | 4158 | uint32_t wait_time; |
e315cd28 | 4159 | struct qla_hw_data *ha = vha->hw; |
73208dfd AC |
4160 | struct req_que *req = ha->req_q_map[0]; |
4161 | struct rsp_que *rsp = ha->rsp_q_map[0]; | |
1da177e4 LT |
4162 | |
4163 | /* If firmware needs to be loaded */ | |
e315cd28 AC |
4164 | if (qla2x00_isp_firmware(vha)) { |
4165 | vha->flags.online = 0; | |
4166 | status = ha->isp_ops->chip_diag(vha); | |
4167 | if (!status) | |
4168 | status = qla2x00_setup_chip(vha); | |
1da177e4 LT |
4169 | } |
4170 | ||
e315cd28 AC |
4171 | if (!status && !(status = qla2x00_init_rings(vha))) { |
4172 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); | |
2533cf67 | 4173 | ha->flags.chip_reset_done = 1; |
73208dfd AC |
4174 | /* Initialize the queues in use */ |
4175 | qla25xx_init_queues(ha); | |
4176 | ||
e315cd28 AC |
4177 | status = qla2x00_fw_ready(vha); |
4178 | if (!status) { | |
1da177e4 | 4179 | DEBUG(printk("%s(): Start configure loop, " |
744f11fd | 4180 | "status = %d\n", __func__, status)); |
0107109e AV |
4181 | |
4182 | /* Issue a marker after FW becomes ready. */ | |
73208dfd | 4183 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
0107109e | 4184 | |
e315cd28 | 4185 | vha->flags.online = 1; |
1da177e4 LT |
4186 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
4187 | wait_time = 256; | |
4188 | do { | |
e315cd28 AC |
4189 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
4190 | qla2x00_configure_loop(vha); | |
1da177e4 | 4191 | wait_time--; |
e315cd28 AC |
4192 | } while (!atomic_read(&vha->loop_down_timer) && |
4193 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) | |
4194 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, | |
4195 | &vha->dpc_flags))); | |
1da177e4 LT |
4196 | } |
4197 | ||
4198 | /* if no cable then assume it's good */ | |
e315cd28 | 4199 | if ((vha->device_flags & DFLG_NO_CABLE)) |
1da177e4 LT |
4200 | status = 0; |
4201 | ||
4202 | DEBUG(printk("%s(): Configure loop done, status = 0x%x\n", | |
4203 | __func__, | |
744f11fd | 4204 | status)); |
1da177e4 LT |
4205 | } |
4206 | return (status); | |
4207 | } | |
4208 | ||
73208dfd AC |
4209 | static int |
4210 | qla25xx_init_queues(struct qla_hw_data *ha) | |
4211 | { | |
4212 | struct rsp_que *rsp = NULL; | |
4213 | struct req_que *req = NULL; | |
4214 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); | |
4215 | int ret = -1; | |
4216 | int i; | |
4217 | ||
2afa19a9 | 4218 | for (i = 1; i < ha->max_rsp_queues; i++) { |
73208dfd AC |
4219 | rsp = ha->rsp_q_map[i]; |
4220 | if (rsp) { | |
4221 | rsp->options &= ~BIT_0; | |
618a7523 | 4222 | ret = qla25xx_init_rsp_que(base_vha, rsp); |
73208dfd AC |
4223 | if (ret != QLA_SUCCESS) |
4224 | DEBUG2_17(printk(KERN_WARNING | |
4225 | "%s Rsp que:%d init failed\n", __func__, | |
4226 | rsp->id)); | |
4227 | else | |
4228 | DEBUG2_17(printk(KERN_INFO | |
4229 | "%s Rsp que:%d inited\n", __func__, | |
4230 | rsp->id)); | |
4231 | } | |
2afa19a9 AC |
4232 | } |
4233 | for (i = 1; i < ha->max_req_queues; i++) { | |
73208dfd AC |
4234 | req = ha->req_q_map[i]; |
4235 | if (req) { | |
29bdccbe | 4236 | /* Clear outstanding commands array. */ |
73208dfd | 4237 | req->options &= ~BIT_0; |
618a7523 | 4238 | ret = qla25xx_init_req_que(base_vha, req); |
73208dfd AC |
4239 | if (ret != QLA_SUCCESS) |
4240 | DEBUG2_17(printk(KERN_WARNING | |
4241 | "%s Req que:%d init failed\n", __func__, | |
4242 | req->id)); | |
4243 | else | |
4244 | DEBUG2_17(printk(KERN_WARNING | |
29bdccbe | 4245 | "%s Req que:%d inited\n", __func__, |
73208dfd AC |
4246 | req->id)); |
4247 | } | |
4248 | } | |
4249 | return ret; | |
4250 | } | |
4251 | ||
1da177e4 LT |
4252 | /* |
4253 | * qla2x00_reset_adapter | |
4254 | * Reset adapter. | |
4255 | * | |
4256 | * Input: | |
4257 | * ha = adapter block pointer. | |
4258 | */ | |
abbd8870 | 4259 | void |
e315cd28 | 4260 | qla2x00_reset_adapter(scsi_qla_host_t *vha) |
1da177e4 LT |
4261 | { |
4262 | unsigned long flags = 0; | |
e315cd28 | 4263 | struct qla_hw_data *ha = vha->hw; |
3d71644c | 4264 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
1da177e4 | 4265 | |
e315cd28 | 4266 | vha->flags.online = 0; |
fd34f556 | 4267 | ha->isp_ops->disable_intrs(ha); |
1da177e4 | 4268 | |
1da177e4 LT |
4269 | spin_lock_irqsave(&ha->hardware_lock, flags); |
4270 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); | |
4271 | RD_REG_WORD(®->hccr); /* PCI Posting. */ | |
4272 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); | |
4273 | RD_REG_WORD(®->hccr); /* PCI Posting. */ | |
4274 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
4275 | } | |
0107109e AV |
4276 | |
4277 | void | |
e315cd28 | 4278 | qla24xx_reset_adapter(scsi_qla_host_t *vha) |
0107109e AV |
4279 | { |
4280 | unsigned long flags = 0; | |
e315cd28 | 4281 | struct qla_hw_data *ha = vha->hw; |
0107109e AV |
4282 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
4283 | ||
a9083016 GM |
4284 | if (IS_QLA82XX(ha)) |
4285 | return; | |
4286 | ||
e315cd28 | 4287 | vha->flags.online = 0; |
fd34f556 | 4288 | ha->isp_ops->disable_intrs(ha); |
0107109e AV |
4289 | |
4290 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
4291 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); | |
4292 | RD_REG_DWORD(®->hccr); | |
4293 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); | |
4294 | RD_REG_DWORD(®->hccr); | |
4295 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
09ff36d3 AV |
4296 | |
4297 | if (IS_NOPOLLING_TYPE(ha)) | |
4298 | ha->isp_ops->enable_intrs(ha); | |
0107109e AV |
4299 | } |
4300 | ||
4e08df3f DM |
4301 | /* On sparc systems, obtain port and node WWN from firmware |
4302 | * properties. | |
4303 | */ | |
e315cd28 AC |
4304 | static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, |
4305 | struct nvram_24xx *nv) | |
4e08df3f DM |
4306 | { |
4307 | #ifdef CONFIG_SPARC | |
e315cd28 | 4308 | struct qla_hw_data *ha = vha->hw; |
4e08df3f | 4309 | struct pci_dev *pdev = ha->pdev; |
15576bc8 DM |
4310 | struct device_node *dp = pci_device_to_OF_node(pdev); |
4311 | const u8 *val; | |
4e08df3f DM |
4312 | int len; |
4313 | ||
4314 | val = of_get_property(dp, "port-wwn", &len); | |
4315 | if (val && len >= WWN_SIZE) | |
4316 | memcpy(nv->port_name, val, WWN_SIZE); | |
4317 | ||
4318 | val = of_get_property(dp, "node-wwn", &len); | |
4319 | if (val && len >= WWN_SIZE) | |
4320 | memcpy(nv->node_name, val, WWN_SIZE); | |
4321 | #endif | |
4322 | } | |
4323 | ||
0107109e | 4324 | int |
e315cd28 | 4325 | qla24xx_nvram_config(scsi_qla_host_t *vha) |
0107109e | 4326 | { |
4e08df3f | 4327 | int rval; |
0107109e AV |
4328 | struct init_cb_24xx *icb; |
4329 | struct nvram_24xx *nv; | |
4330 | uint32_t *dptr; | |
4331 | uint8_t *dptr1, *dptr2; | |
4332 | uint32_t chksum; | |
4333 | uint16_t cnt; | |
e315cd28 | 4334 | struct qla_hw_data *ha = vha->hw; |
0107109e | 4335 | |
4e08df3f | 4336 | rval = QLA_SUCCESS; |
0107109e | 4337 | icb = (struct init_cb_24xx *)ha->init_cb; |
281afe19 | 4338 | nv = ha->nvram; |
0107109e AV |
4339 | |
4340 | /* Determine NVRAM starting address. */ | |
e5b68a61 AC |
4341 | if (ha->flags.port0) { |
4342 | ha->nvram_base = FA_NVRAM_FUNC0_ADDR; | |
4343 | ha->vpd_base = FA_NVRAM_VPD0_ADDR; | |
4344 | } else { | |
0107109e | 4345 | ha->nvram_base = FA_NVRAM_FUNC1_ADDR; |
6f641790 AV |
4346 | ha->vpd_base = FA_NVRAM_VPD1_ADDR; |
4347 | } | |
e5b68a61 AC |
4348 | ha->nvram_size = sizeof(struct nvram_24xx); |
4349 | ha->vpd_size = FA_NVRAM_VPD_SIZE; | |
a9083016 GM |
4350 | if (IS_QLA82XX(ha)) |
4351 | ha->vpd_size = FA_VPD_SIZE_82XX; | |
0107109e | 4352 | |
281afe19 SJ |
4353 | /* Get VPD data into cache */ |
4354 | ha->vpd = ha->nvram + VPD_OFFSET; | |
e315cd28 | 4355 | ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, |
281afe19 SJ |
4356 | ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4); |
4357 | ||
4358 | /* Get NVRAM data into cache and calculate checksum. */ | |
0107109e | 4359 | dptr = (uint32_t *)nv; |
e315cd28 | 4360 | ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base, |
0107109e AV |
4361 | ha->nvram_size); |
4362 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++) | |
4363 | chksum += le32_to_cpu(*dptr++); | |
4364 | ||
7640335e | 4365 | DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no)); |
281afe19 | 4366 | DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size)); |
0107109e AV |
4367 | |
4368 | /* Bad NVRAM data, set defaults parameters. */ | |
4369 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' | |
4370 | || nv->id[3] != ' ' || | |
4371 | nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) { | |
4372 | /* Reset NVRAM data. */ | |
4373 | qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: " | |
4374 | "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0], | |
4375 | le16_to_cpu(nv->nvram_version)); | |
4e08df3f DM |
4376 | qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet " |
4377 | "invalid -- WWPN) defaults.\n"); | |
4378 | ||
4379 | /* | |
4380 | * Set default initialization control block. | |
4381 | */ | |
4382 | memset(nv, 0, ha->nvram_size); | |
4383 | nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION); | |
4384 | nv->version = __constant_cpu_to_le16(ICB_VERSION); | |
4385 | nv->frame_payload_size = __constant_cpu_to_le16(2048); | |
4386 | nv->execution_throttle = __constant_cpu_to_le16(0xFFFF); | |
4387 | nv->exchange_count = __constant_cpu_to_le16(0); | |
4388 | nv->hard_address = __constant_cpu_to_le16(124); | |
4389 | nv->port_name[0] = 0x21; | |
e5b68a61 | 4390 | nv->port_name[1] = 0x00 + ha->port_no; |
4e08df3f DM |
4391 | nv->port_name[2] = 0x00; |
4392 | nv->port_name[3] = 0xe0; | |
4393 | nv->port_name[4] = 0x8b; | |
4394 | nv->port_name[5] = 0x1c; | |
4395 | nv->port_name[6] = 0x55; | |
4396 | nv->port_name[7] = 0x86; | |
4397 | nv->node_name[0] = 0x20; | |
4398 | nv->node_name[1] = 0x00; | |
4399 | nv->node_name[2] = 0x00; | |
4400 | nv->node_name[3] = 0xe0; | |
4401 | nv->node_name[4] = 0x8b; | |
4402 | nv->node_name[5] = 0x1c; | |
4403 | nv->node_name[6] = 0x55; | |
4404 | nv->node_name[7] = 0x86; | |
e315cd28 | 4405 | qla24xx_nvram_wwn_from_ofw(vha, nv); |
4e08df3f DM |
4406 | nv->login_retry_count = __constant_cpu_to_le16(8); |
4407 | nv->interrupt_delay_timer = __constant_cpu_to_le16(0); | |
4408 | nv->login_timeout = __constant_cpu_to_le16(0); | |
4409 | nv->firmware_options_1 = | |
4410 | __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); | |
4411 | nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4); | |
4412 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12); | |
4413 | nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13); | |
4414 | nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10); | |
4415 | nv->efi_parameters = __constant_cpu_to_le32(0); | |
4416 | nv->reset_delay = 5; | |
4417 | nv->max_luns_per_target = __constant_cpu_to_le16(128); | |
4418 | nv->port_down_retry_count = __constant_cpu_to_le16(30); | |
4419 | nv->link_down_timeout = __constant_cpu_to_le16(30); | |
4420 | ||
4421 | rval = 1; | |
0107109e AV |
4422 | } |
4423 | ||
4424 | /* Reset Initialization control block */ | |
e315cd28 | 4425 | memset(icb, 0, ha->init_cb_size); |
0107109e AV |
4426 | |
4427 | /* Copy 1st segment. */ | |
4428 | dptr1 = (uint8_t *)icb; | |
4429 | dptr2 = (uint8_t *)&nv->version; | |
4430 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; | |
4431 | while (cnt--) | |
4432 | *dptr1++ = *dptr2++; | |
4433 | ||
4434 | icb->login_retry_count = nv->login_retry_count; | |
3ea66e28 | 4435 | icb->link_down_on_nos = nv->link_down_on_nos; |
0107109e AV |
4436 | |
4437 | /* Copy 2nd segment. */ | |
4438 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; | |
4439 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; | |
4440 | cnt = (uint8_t *)&icb->reserved_3 - | |
4441 | (uint8_t *)&icb->interrupt_delay_timer; | |
4442 | while (cnt--) | |
4443 | *dptr1++ = *dptr2++; | |
4444 | ||
4445 | /* | |
4446 | * Setup driver NVRAM options. | |
4447 | */ | |
e315cd28 | 4448 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
9bb9fcf2 | 4449 | "QLA2462"); |
0107109e | 4450 | |
5341e868 AV |
4451 | /* Use alternate WWN? */ |
4452 | if (nv->host_p & __constant_cpu_to_le32(BIT_15)) { | |
4453 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); | |
4454 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); | |
4455 | } | |
4456 | ||
0107109e | 4457 | /* Prepare nodename */ |
fd0e7e4d | 4458 | if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) { |
0107109e AV |
4459 | /* |
4460 | * Firmware will apply the following mask if the nodename was | |
4461 | * not provided. | |
4462 | */ | |
4463 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); | |
4464 | icb->node_name[0] &= 0xF0; | |
4465 | } | |
4466 | ||
4467 | /* Set host adapter parameters. */ | |
4468 | ha->flags.disable_risc_code_load = 0; | |
0c8c39af AV |
4469 | ha->flags.enable_lip_reset = 0; |
4470 | ha->flags.enable_lip_full_login = | |
4471 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; | |
4472 | ha->flags.enable_target_reset = | |
4473 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; | |
0107109e | 4474 | ha->flags.enable_led_scheme = 0; |
d4c760c2 | 4475 | ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; |
0107109e | 4476 | |
fd0e7e4d AV |
4477 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
4478 | (BIT_6 | BIT_5 | BIT_4)) >> 4; | |
0107109e AV |
4479 | |
4480 | memcpy(ha->fw_seriallink_options24, nv->seriallink_options, | |
4481 | sizeof(ha->fw_seriallink_options24)); | |
4482 | ||
4483 | /* save HBA serial number */ | |
4484 | ha->serial0 = icb->port_name[5]; | |
4485 | ha->serial1 = icb->port_name[6]; | |
4486 | ha->serial2 = icb->port_name[7]; | |
e315cd28 AC |
4487 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
4488 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); | |
0107109e | 4489 | |
bc8fb3cb AV |
4490 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
4491 | ||
0107109e AV |
4492 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
4493 | ||
4494 | /* Set minimum login_timeout to 4 seconds. */ | |
4495 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) | |
4496 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); | |
4497 | if (le16_to_cpu(nv->login_timeout) < 4) | |
4498 | nv->login_timeout = __constant_cpu_to_le16(4); | |
4499 | ha->login_timeout = le16_to_cpu(nv->login_timeout); | |
c6852c4c | 4500 | icb->login_timeout = nv->login_timeout; |
0107109e | 4501 | |
00a537b8 AV |
4502 | /* Set minimum RATOV to 100 tenths of a second. */ |
4503 | ha->r_a_tov = 100; | |
0107109e AV |
4504 | |
4505 | ha->loop_reset_delay = nv->reset_delay; | |
4506 | ||
4507 | /* Link Down Timeout = 0: | |
4508 | * | |
4509 | * When Port Down timer expires we will start returning | |
4510 | * I/O's to OS with "DID_NO_CONNECT". | |
4511 | * | |
4512 | * Link Down Timeout != 0: | |
4513 | * | |
4514 | * The driver waits for the link to come up after link down | |
4515 | * before returning I/Os to OS with "DID_NO_CONNECT". | |
4516 | */ | |
4517 | if (le16_to_cpu(nv->link_down_timeout) == 0) { | |
4518 | ha->loop_down_abort_time = | |
4519 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); | |
4520 | } else { | |
4521 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); | |
4522 | ha->loop_down_abort_time = | |
4523 | (LOOP_DOWN_TIME - ha->link_down_timeout); | |
4524 | } | |
4525 | ||
4526 | /* Need enough time to try and get the port back. */ | |
4527 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); | |
4528 | if (qlport_down_retry) | |
4529 | ha->port_down_retry_count = qlport_down_retry; | |
4530 | ||
4531 | /* Set login_retry_count */ | |
4532 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); | |
4533 | if (ha->port_down_retry_count == | |
4534 | le16_to_cpu(nv->port_down_retry_count) && | |
4535 | ha->port_down_retry_count > 3) | |
4536 | ha->login_retry_count = ha->port_down_retry_count; | |
4537 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) | |
4538 | ha->login_retry_count = ha->port_down_retry_count; | |
4539 | if (ql2xloginretrycount) | |
4540 | ha->login_retry_count = ql2xloginretrycount; | |
4541 | ||
4fdfefe5 | 4542 | /* Enable ZIO. */ |
e315cd28 | 4543 | if (!vha->flags.init_done) { |
4fdfefe5 AV |
4544 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
4545 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); | |
4546 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? | |
4547 | le16_to_cpu(icb->interrupt_delay_timer): 2; | |
4548 | } | |
4549 | icb->firmware_options_2 &= __constant_cpu_to_le32( | |
4550 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); | |
e315cd28 | 4551 | vha->flags.process_response_queue = 0; |
4fdfefe5 | 4552 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
4a59f71d AV |
4553 | ha->zio_mode = QLA_ZIO_MODE_6; |
4554 | ||
4fdfefe5 | 4555 | DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay " |
e315cd28 | 4556 | "(%d us).\n", vha->host_no, ha->zio_mode, |
4fdfefe5 AV |
4557 | ha->zio_timer * 100)); |
4558 | qla_printk(KERN_INFO, ha, | |
4559 | "ZIO mode %d enabled; timer delay (%d us).\n", | |
4560 | ha->zio_mode, ha->zio_timer * 100); | |
4561 | ||
4562 | icb->firmware_options_2 |= cpu_to_le32( | |
4563 | (uint32_t)ha->zio_mode); | |
4564 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); | |
e315cd28 | 4565 | vha->flags.process_response_queue = 1; |
4fdfefe5 AV |
4566 | } |
4567 | ||
4e08df3f DM |
4568 | if (rval) { |
4569 | DEBUG2_3(printk(KERN_WARNING | |
e315cd28 | 4570 | "scsi(%ld): NVRAM configuration failed!\n", vha->host_no)); |
4e08df3f DM |
4571 | } |
4572 | return (rval); | |
0107109e AV |
4573 | } |
4574 | ||
413975a0 | 4575 | static int |
cbc8eb67 AV |
4576 | qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr, |
4577 | uint32_t faddr) | |
d1c61909 | 4578 | { |
73208dfd | 4579 | int rval = QLA_SUCCESS; |
d1c61909 | 4580 | int segments, fragment; |
d1c61909 AV |
4581 | uint32_t *dcode, dlen; |
4582 | uint32_t risc_addr; | |
4583 | uint32_t risc_size; | |
4584 | uint32_t i; | |
e315cd28 | 4585 | struct qla_hw_data *ha = vha->hw; |
73208dfd | 4586 | struct req_que *req = ha->req_q_map[0]; |
eaac30be AV |
4587 | |
4588 | qla_printk(KERN_INFO, ha, | |
cbc8eb67 | 4589 | "FW: Loading from flash (%x)...\n", faddr); |
eaac30be | 4590 | |
d1c61909 AV |
4591 | rval = QLA_SUCCESS; |
4592 | ||
4593 | segments = FA_RISC_CODE_SEGMENTS; | |
73208dfd | 4594 | dcode = (uint32_t *)req->ring; |
d1c61909 AV |
4595 | *srisc_addr = 0; |
4596 | ||
4597 | /* Validate firmware image by checking version. */ | |
e315cd28 | 4598 | qla24xx_read_flash_data(vha, dcode, faddr + 4, 4); |
d1c61909 AV |
4599 | for (i = 0; i < 4; i++) |
4600 | dcode[i] = be32_to_cpu(dcode[i]); | |
4601 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && | |
4602 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || | |
4603 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && | |
4604 | dcode[3] == 0)) { | |
4605 | qla_printk(KERN_WARNING, ha, | |
4606 | "Unable to verify integrity of flash firmware image!\n"); | |
4607 | qla_printk(KERN_WARNING, ha, | |
4608 | "Firmware data: %08x %08x %08x %08x!\n", dcode[0], | |
4609 | dcode[1], dcode[2], dcode[3]); | |
4610 | ||
4611 | return QLA_FUNCTION_FAILED; | |
4612 | } | |
4613 | ||
4614 | while (segments && rval == QLA_SUCCESS) { | |
4615 | /* Read segment's load information. */ | |
e315cd28 | 4616 | qla24xx_read_flash_data(vha, dcode, faddr, 4); |
d1c61909 AV |
4617 | |
4618 | risc_addr = be32_to_cpu(dcode[2]); | |
4619 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; | |
4620 | risc_size = be32_to_cpu(dcode[3]); | |
4621 | ||
4622 | fragment = 0; | |
4623 | while (risc_size > 0 && rval == QLA_SUCCESS) { | |
4624 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); | |
4625 | if (dlen > risc_size) | |
4626 | dlen = risc_size; | |
4627 | ||
4628 | DEBUG7(printk("scsi(%ld): Loading risc segment@ risc " | |
4629 | "addr %x, number of dwords 0x%x, offset 0x%x.\n", | |
e315cd28 | 4630 | vha->host_no, risc_addr, dlen, faddr)); |
d1c61909 | 4631 | |
e315cd28 | 4632 | qla24xx_read_flash_data(vha, dcode, faddr, dlen); |
d1c61909 AV |
4633 | for (i = 0; i < dlen; i++) |
4634 | dcode[i] = swab32(dcode[i]); | |
4635 | ||
73208dfd | 4636 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
d1c61909 AV |
4637 | dlen); |
4638 | if (rval) { | |
4639 | DEBUG(printk("scsi(%ld):[ERROR] Failed to load " | |
e315cd28 | 4640 | "segment %d of firmware\n", vha->host_no, |
d1c61909 AV |
4641 | fragment)); |
4642 | qla_printk(KERN_WARNING, ha, | |
4643 | "[ERROR] Failed to load segment %d of " | |
4644 | "firmware\n", fragment); | |
4645 | break; | |
4646 | } | |
4647 | ||
4648 | faddr += dlen; | |
4649 | risc_addr += dlen; | |
4650 | risc_size -= dlen; | |
4651 | fragment++; | |
4652 | } | |
4653 | ||
4654 | /* Next segment. */ | |
4655 | segments--; | |
4656 | } | |
4657 | ||
4658 | return rval; | |
4659 | } | |
4660 | ||
d1c61909 AV |
4661 | #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/" |
4662 | ||
0107109e | 4663 | int |
e315cd28 | 4664 | qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
5433383e AV |
4665 | { |
4666 | int rval; | |
4667 | int i, fragment; | |
4668 | uint16_t *wcode, *fwcode; | |
4669 | uint32_t risc_addr, risc_size, fwclen, wlen, *seg; | |
4670 | struct fw_blob *blob; | |
e315cd28 | 4671 | struct qla_hw_data *ha = vha->hw; |
73208dfd | 4672 | struct req_que *req = ha->req_q_map[0]; |
5433383e AV |
4673 | |
4674 | /* Load firmware blob. */ | |
e315cd28 | 4675 | blob = qla2x00_request_firmware(vha); |
5433383e AV |
4676 | if (!blob) { |
4677 | qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n"); | |
d1c61909 AV |
4678 | qla_printk(KERN_ERR, ha, "Firmware images can be retrieved " |
4679 | "from: " QLA_FW_URL ".\n"); | |
5433383e AV |
4680 | return QLA_FUNCTION_FAILED; |
4681 | } | |
4682 | ||
4683 | rval = QLA_SUCCESS; | |
4684 | ||
73208dfd | 4685 | wcode = (uint16_t *)req->ring; |
5433383e AV |
4686 | *srisc_addr = 0; |
4687 | fwcode = (uint16_t *)blob->fw->data; | |
4688 | fwclen = 0; | |
4689 | ||
4690 | /* Validate firmware image by checking version. */ | |
4691 | if (blob->fw->size < 8 * sizeof(uint16_t)) { | |
4692 | qla_printk(KERN_WARNING, ha, | |
4693 | "Unable to verify integrity of firmware image (%Zd)!\n", | |
4694 | blob->fw->size); | |
4695 | goto fail_fw_integrity; | |
4696 | } | |
4697 | for (i = 0; i < 4; i++) | |
4698 | wcode[i] = be16_to_cpu(fwcode[i + 4]); | |
4699 | if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff && | |
4700 | wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 && | |
4701 | wcode[2] == 0 && wcode[3] == 0)) { | |
4702 | qla_printk(KERN_WARNING, ha, | |
4703 | "Unable to verify integrity of firmware image!\n"); | |
4704 | qla_printk(KERN_WARNING, ha, | |
4705 | "Firmware data: %04x %04x %04x %04x!\n", wcode[0], | |
4706 | wcode[1], wcode[2], wcode[3]); | |
4707 | goto fail_fw_integrity; | |
4708 | } | |
4709 | ||
4710 | seg = blob->segs; | |
4711 | while (*seg && rval == QLA_SUCCESS) { | |
4712 | risc_addr = *seg; | |
4713 | *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr; | |
4714 | risc_size = be16_to_cpu(fwcode[3]); | |
4715 | ||
4716 | /* Validate firmware image size. */ | |
4717 | fwclen += risc_size * sizeof(uint16_t); | |
4718 | if (blob->fw->size < fwclen) { | |
4719 | qla_printk(KERN_WARNING, ha, | |
4720 | "Unable to verify integrity of firmware image " | |
4721 | "(%Zd)!\n", blob->fw->size); | |
4722 | goto fail_fw_integrity; | |
4723 | } | |
4724 | ||
4725 | fragment = 0; | |
4726 | while (risc_size > 0 && rval == QLA_SUCCESS) { | |
4727 | wlen = (uint16_t)(ha->fw_transfer_size >> 1); | |
4728 | if (wlen > risc_size) | |
4729 | wlen = risc_size; | |
4730 | ||
4731 | DEBUG7(printk("scsi(%ld): Loading risc segment@ risc " | |
e315cd28 | 4732 | "addr %x, number of words 0x%x.\n", vha->host_no, |
5433383e AV |
4733 | risc_addr, wlen)); |
4734 | ||
4735 | for (i = 0; i < wlen; i++) | |
4736 | wcode[i] = swab16(fwcode[i]); | |
4737 | ||
73208dfd | 4738 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
5433383e AV |
4739 | wlen); |
4740 | if (rval) { | |
4741 | DEBUG(printk("scsi(%ld):[ERROR] Failed to load " | |
e315cd28 | 4742 | "segment %d of firmware\n", vha->host_no, |
5433383e AV |
4743 | fragment)); |
4744 | qla_printk(KERN_WARNING, ha, | |
4745 | "[ERROR] Failed to load segment %d of " | |
4746 | "firmware\n", fragment); | |
4747 | break; | |
4748 | } | |
4749 | ||
4750 | fwcode += wlen; | |
4751 | risc_addr += wlen; | |
4752 | risc_size -= wlen; | |
4753 | fragment++; | |
4754 | } | |
4755 | ||
4756 | /* Next segment. */ | |
4757 | seg++; | |
4758 | } | |
4759 | return rval; | |
4760 | ||
4761 | fail_fw_integrity: | |
4762 | return QLA_FUNCTION_FAILED; | |
4763 | } | |
4764 | ||
eaac30be AV |
4765 | static int |
4766 | qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr) | |
0107109e AV |
4767 | { |
4768 | int rval; | |
4769 | int segments, fragment; | |
4770 | uint32_t *dcode, dlen; | |
4771 | uint32_t risc_addr; | |
4772 | uint32_t risc_size; | |
4773 | uint32_t i; | |
5433383e | 4774 | struct fw_blob *blob; |
0107109e | 4775 | uint32_t *fwcode, fwclen; |
e315cd28 | 4776 | struct qla_hw_data *ha = vha->hw; |
73208dfd | 4777 | struct req_que *req = ha->req_q_map[0]; |
0107109e | 4778 | |
5433383e | 4779 | /* Load firmware blob. */ |
e315cd28 | 4780 | blob = qla2x00_request_firmware(vha); |
5433383e AV |
4781 | if (!blob) { |
4782 | qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n"); | |
d1c61909 AV |
4783 | qla_printk(KERN_ERR, ha, "Firmware images can be retrieved " |
4784 | "from: " QLA_FW_URL ".\n"); | |
4785 | ||
eaac30be | 4786 | return QLA_FUNCTION_FAILED; |
0107109e AV |
4787 | } |
4788 | ||
eaac30be AV |
4789 | qla_printk(KERN_INFO, ha, |
4790 | "FW: Loading via request-firmware...\n"); | |
4791 | ||
0107109e AV |
4792 | rval = QLA_SUCCESS; |
4793 | ||
4794 | segments = FA_RISC_CODE_SEGMENTS; | |
73208dfd | 4795 | dcode = (uint32_t *)req->ring; |
0107109e | 4796 | *srisc_addr = 0; |
5433383e | 4797 | fwcode = (uint32_t *)blob->fw->data; |
0107109e AV |
4798 | fwclen = 0; |
4799 | ||
4800 | /* Validate firmware image by checking version. */ | |
5433383e | 4801 | if (blob->fw->size < 8 * sizeof(uint32_t)) { |
0107109e | 4802 | qla_printk(KERN_WARNING, ha, |
5433383e AV |
4803 | "Unable to verify integrity of firmware image (%Zd)!\n", |
4804 | blob->fw->size); | |
0107109e AV |
4805 | goto fail_fw_integrity; |
4806 | } | |
4807 | for (i = 0; i < 4; i++) | |
4808 | dcode[i] = be32_to_cpu(fwcode[i + 4]); | |
4809 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && | |
4810 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || | |
4811 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && | |
4812 | dcode[3] == 0)) { | |
4813 | qla_printk(KERN_WARNING, ha, | |
5433383e | 4814 | "Unable to verify integrity of firmware image!\n"); |
0107109e AV |
4815 | qla_printk(KERN_WARNING, ha, |
4816 | "Firmware data: %08x %08x %08x %08x!\n", dcode[0], | |
4817 | dcode[1], dcode[2], dcode[3]); | |
4818 | goto fail_fw_integrity; | |
4819 | } | |
4820 | ||
4821 | while (segments && rval == QLA_SUCCESS) { | |
4822 | risc_addr = be32_to_cpu(fwcode[2]); | |
4823 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; | |
4824 | risc_size = be32_to_cpu(fwcode[3]); | |
4825 | ||
4826 | /* Validate firmware image size. */ | |
4827 | fwclen += risc_size * sizeof(uint32_t); | |
5433383e | 4828 | if (blob->fw->size < fwclen) { |
0107109e | 4829 | qla_printk(KERN_WARNING, ha, |
5433383e AV |
4830 | "Unable to verify integrity of firmware image " |
4831 | "(%Zd)!\n", blob->fw->size); | |
4832 | ||
0107109e AV |
4833 | goto fail_fw_integrity; |
4834 | } | |
4835 | ||
4836 | fragment = 0; | |
4837 | while (risc_size > 0 && rval == QLA_SUCCESS) { | |
4838 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); | |
4839 | if (dlen > risc_size) | |
4840 | dlen = risc_size; | |
4841 | ||
4842 | DEBUG7(printk("scsi(%ld): Loading risc segment@ risc " | |
e315cd28 | 4843 | "addr %x, number of dwords 0x%x.\n", vha->host_no, |
0107109e AV |
4844 | risc_addr, dlen)); |
4845 | ||
4846 | for (i = 0; i < dlen; i++) | |
4847 | dcode[i] = swab32(fwcode[i]); | |
4848 | ||
73208dfd | 4849 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
590f98e5 | 4850 | dlen); |
0107109e AV |
4851 | if (rval) { |
4852 | DEBUG(printk("scsi(%ld):[ERROR] Failed to load " | |
e315cd28 | 4853 | "segment %d of firmware\n", vha->host_no, |
0107109e AV |
4854 | fragment)); |
4855 | qla_printk(KERN_WARNING, ha, | |
4856 | "[ERROR] Failed to load segment %d of " | |
4857 | "firmware\n", fragment); | |
4858 | break; | |
4859 | } | |
4860 | ||
4861 | fwcode += dlen; | |
4862 | risc_addr += dlen; | |
4863 | risc_size -= dlen; | |
4864 | fragment++; | |
4865 | } | |
4866 | ||
4867 | /* Next segment. */ | |
4868 | segments--; | |
4869 | } | |
0107109e AV |
4870 | return rval; |
4871 | ||
4872 | fail_fw_integrity: | |
0107109e | 4873 | return QLA_FUNCTION_FAILED; |
0107109e | 4874 | } |
18c6c127 | 4875 | |
eaac30be AV |
4876 | int |
4877 | qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) | |
4878 | { | |
4879 | int rval; | |
4880 | ||
e337d907 AV |
4881 | if (ql2xfwloadbin == 1) |
4882 | return qla81xx_load_risc(vha, srisc_addr); | |
4883 | ||
eaac30be AV |
4884 | /* |
4885 | * FW Load priority: | |
4886 | * 1) Firmware via request-firmware interface (.bin file). | |
4887 | * 2) Firmware residing in flash. | |
4888 | */ | |
4889 | rval = qla24xx_load_risc_blob(vha, srisc_addr); | |
4890 | if (rval == QLA_SUCCESS) | |
4891 | return rval; | |
4892 | ||
cbc8eb67 AV |
4893 | return qla24xx_load_risc_flash(vha, srisc_addr, |
4894 | vha->hw->flt_region_fw); | |
eaac30be AV |
4895 | } |
4896 | ||
4897 | int | |
4898 | qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) | |
4899 | { | |
4900 | int rval; | |
cbc8eb67 | 4901 | struct qla_hw_data *ha = vha->hw; |
eaac30be | 4902 | |
e337d907 | 4903 | if (ql2xfwloadbin == 2) |
cbc8eb67 | 4904 | goto try_blob_fw; |
e337d907 | 4905 | |
eaac30be AV |
4906 | /* |
4907 | * FW Load priority: | |
4908 | * 1) Firmware residing in flash. | |
4909 | * 2) Firmware via request-firmware interface (.bin file). | |
cbc8eb67 | 4910 | * 3) Golden-Firmware residing in flash -- limited operation. |
eaac30be | 4911 | */ |
cbc8eb67 | 4912 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw); |
eaac30be AV |
4913 | if (rval == QLA_SUCCESS) |
4914 | return rval; | |
4915 | ||
cbc8eb67 AV |
4916 | try_blob_fw: |
4917 | rval = qla24xx_load_risc_blob(vha, srisc_addr); | |
4918 | if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw) | |
4919 | return rval; | |
4920 | ||
4921 | qla_printk(KERN_ERR, ha, | |
4922 | "FW: Attempting to fallback to golden firmware...\n"); | |
4923 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw); | |
4924 | if (rval != QLA_SUCCESS) | |
4925 | return rval; | |
4926 | ||
4927 | qla_printk(KERN_ERR, ha, | |
4928 | "FW: Please update operational firmware...\n"); | |
4929 | ha->flags.running_gold_fw = 1; | |
4930 | ||
4931 | return rval; | |
eaac30be AV |
4932 | } |
4933 | ||
18c6c127 | 4934 | void |
e315cd28 | 4935 | qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha) |
18c6c127 AV |
4936 | { |
4937 | int ret, retries; | |
e315cd28 | 4938 | struct qla_hw_data *ha = vha->hw; |
18c6c127 | 4939 | |
85880801 AV |
4940 | if (ha->flags.pci_channel_io_perm_failure) |
4941 | return; | |
e428924c | 4942 | if (!IS_FWI2_CAPABLE(ha)) |
18c6c127 | 4943 | return; |
75edf81d AV |
4944 | if (!ha->fw_major_version) |
4945 | return; | |
18c6c127 | 4946 | |
e315cd28 | 4947 | ret = qla2x00_stop_firmware(vha); |
7c7f1f29 | 4948 | for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT && |
b469a7cb | 4949 | ret != QLA_INVALID_COMMAND && retries ; retries--) { |
e315cd28 AC |
4950 | ha->isp_ops->reset_chip(vha); |
4951 | if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS) | |
18c6c127 | 4952 | continue; |
e315cd28 | 4953 | if (qla2x00_setup_chip(vha) != QLA_SUCCESS) |
18c6c127 AV |
4954 | continue; |
4955 | qla_printk(KERN_INFO, ha, | |
4956 | "Attempting retry of stop-firmware command...\n"); | |
e315cd28 | 4957 | ret = qla2x00_stop_firmware(vha); |
18c6c127 AV |
4958 | } |
4959 | } | |
2c3dfe3f SJ |
4960 | |
4961 | int | |
e315cd28 | 4962 | qla24xx_configure_vhba(scsi_qla_host_t *vha) |
2c3dfe3f SJ |
4963 | { |
4964 | int rval = QLA_SUCCESS; | |
4965 | uint16_t mb[MAILBOX_REGISTER_COUNT]; | |
e315cd28 AC |
4966 | struct qla_hw_data *ha = vha->hw; |
4967 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); | |
67c2e93a AC |
4968 | struct req_que *req; |
4969 | struct rsp_que *rsp; | |
2c3dfe3f | 4970 | |
e315cd28 | 4971 | if (!vha->vp_idx) |
2c3dfe3f SJ |
4972 | return -EINVAL; |
4973 | ||
e315cd28 | 4974 | rval = qla2x00_fw_ready(base_vha); |
7163ea81 | 4975 | if (ha->flags.cpu_affinity_enabled) |
67c2e93a AC |
4976 | req = ha->req_q_map[0]; |
4977 | else | |
4978 | req = vha->req; | |
4979 | rsp = req->rsp; | |
4980 | ||
2c3dfe3f | 4981 | if (rval == QLA_SUCCESS) { |
e315cd28 | 4982 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
73208dfd | 4983 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
2c3dfe3f SJ |
4984 | } |
4985 | ||
e315cd28 | 4986 | vha->flags.management_server_logged_in = 0; |
2c3dfe3f SJ |
4987 | |
4988 | /* Login to SNS first */ | |
e315cd28 | 4989 | ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1); |
2c3dfe3f SJ |
4990 | if (mb[0] != MBS_COMMAND_COMPLETE) { |
4991 | DEBUG15(qla_printk(KERN_INFO, ha, | |
4992 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " | |
4993 | "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS, | |
4994 | mb[0], mb[1], mb[2], mb[6], mb[7])); | |
4995 | return (QLA_FUNCTION_FAILED); | |
4996 | } | |
4997 | ||
e315cd28 AC |
4998 | atomic_set(&vha->loop_down_timer, 0); |
4999 | atomic_set(&vha->loop_state, LOOP_UP); | |
5000 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); | |
5001 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); | |
5002 | rval = qla2x00_loop_resync(base_vha); | |
2c3dfe3f SJ |
5003 | |
5004 | return rval; | |
5005 | } | |
4d4df193 HK |
5006 | |
5007 | /* 84XX Support **************************************************************/ | |
5008 | ||
5009 | static LIST_HEAD(qla_cs84xx_list); | |
5010 | static DEFINE_MUTEX(qla_cs84xx_mutex); | |
5011 | ||
5012 | static struct qla_chip_state_84xx * | |
e315cd28 | 5013 | qla84xx_get_chip(struct scsi_qla_host *vha) |
4d4df193 HK |
5014 | { |
5015 | struct qla_chip_state_84xx *cs84xx; | |
e315cd28 | 5016 | struct qla_hw_data *ha = vha->hw; |
4d4df193 HK |
5017 | |
5018 | mutex_lock(&qla_cs84xx_mutex); | |
5019 | ||
5020 | /* Find any shared 84xx chip. */ | |
5021 | list_for_each_entry(cs84xx, &qla_cs84xx_list, list) { | |
5022 | if (cs84xx->bus == ha->pdev->bus) { | |
5023 | kref_get(&cs84xx->kref); | |
5024 | goto done; | |
5025 | } | |
5026 | } | |
5027 | ||
5028 | cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL); | |
5029 | if (!cs84xx) | |
5030 | goto done; | |
5031 | ||
5032 | kref_init(&cs84xx->kref); | |
5033 | spin_lock_init(&cs84xx->access_lock); | |
5034 | mutex_init(&cs84xx->fw_update_mutex); | |
5035 | cs84xx->bus = ha->pdev->bus; | |
5036 | ||
5037 | list_add_tail(&cs84xx->list, &qla_cs84xx_list); | |
5038 | done: | |
5039 | mutex_unlock(&qla_cs84xx_mutex); | |
5040 | return cs84xx; | |
5041 | } | |
5042 | ||
5043 | static void | |
5044 | __qla84xx_chip_release(struct kref *kref) | |
5045 | { | |
5046 | struct qla_chip_state_84xx *cs84xx = | |
5047 | container_of(kref, struct qla_chip_state_84xx, kref); | |
5048 | ||
5049 | mutex_lock(&qla_cs84xx_mutex); | |
5050 | list_del(&cs84xx->list); | |
5051 | mutex_unlock(&qla_cs84xx_mutex); | |
5052 | kfree(cs84xx); | |
5053 | } | |
5054 | ||
5055 | void | |
e315cd28 | 5056 | qla84xx_put_chip(struct scsi_qla_host *vha) |
4d4df193 | 5057 | { |
e315cd28 | 5058 | struct qla_hw_data *ha = vha->hw; |
4d4df193 HK |
5059 | if (ha->cs84xx) |
5060 | kref_put(&ha->cs84xx->kref, __qla84xx_chip_release); | |
5061 | } | |
5062 | ||
5063 | static int | |
e315cd28 | 5064 | qla84xx_init_chip(scsi_qla_host_t *vha) |
4d4df193 HK |
5065 | { |
5066 | int rval; | |
5067 | uint16_t status[2]; | |
e315cd28 | 5068 | struct qla_hw_data *ha = vha->hw; |
4d4df193 HK |
5069 | |
5070 | mutex_lock(&ha->cs84xx->fw_update_mutex); | |
5071 | ||
e315cd28 | 5072 | rval = qla84xx_verify_chip(vha, status); |
4d4df193 HK |
5073 | |
5074 | mutex_unlock(&ha->cs84xx->fw_update_mutex); | |
5075 | ||
5076 | return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED: | |
5077 | QLA_SUCCESS; | |
5078 | } | |
3a03eb79 AV |
5079 | |
5080 | /* 81XX Support **************************************************************/ | |
5081 | ||
5082 | int | |
5083 | qla81xx_nvram_config(scsi_qla_host_t *vha) | |
5084 | { | |
5085 | int rval; | |
5086 | struct init_cb_81xx *icb; | |
5087 | struct nvram_81xx *nv; | |
5088 | uint32_t *dptr; | |
5089 | uint8_t *dptr1, *dptr2; | |
5090 | uint32_t chksum; | |
5091 | uint16_t cnt; | |
5092 | struct qla_hw_data *ha = vha->hw; | |
5093 | ||
5094 | rval = QLA_SUCCESS; | |
5095 | icb = (struct init_cb_81xx *)ha->init_cb; | |
5096 | nv = ha->nvram; | |
5097 | ||
5098 | /* Determine NVRAM starting address. */ | |
5099 | ha->nvram_size = sizeof(struct nvram_81xx); | |
3a03eb79 | 5100 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
3a03eb79 AV |
5101 | |
5102 | /* Get VPD data into cache */ | |
5103 | ha->vpd = ha->nvram + VPD_OFFSET; | |
3d79038f AV |
5104 | ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2, |
5105 | ha->vpd_size); | |
3a03eb79 AV |
5106 | |
5107 | /* Get NVRAM data into cache and calculate checksum. */ | |
3d79038f | 5108 | ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2, |
3a03eb79 | 5109 | ha->nvram_size); |
3d79038f | 5110 | dptr = (uint32_t *)nv; |
3a03eb79 AV |
5111 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++) |
5112 | chksum += le32_to_cpu(*dptr++); | |
5113 | ||
7640335e | 5114 | DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no)); |
3a03eb79 AV |
5115 | DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size)); |
5116 | ||
5117 | /* Bad NVRAM data, set defaults parameters. */ | |
5118 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' | |
5119 | || nv->id[3] != ' ' || | |
5120 | nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) { | |
5121 | /* Reset NVRAM data. */ | |
5122 | qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: " | |
5123 | "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0], | |
5124 | le16_to_cpu(nv->nvram_version)); | |
5125 | qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet " | |
5126 | "invalid -- WWPN) defaults.\n"); | |
5127 | ||
5128 | /* | |
5129 | * Set default initialization control block. | |
5130 | */ | |
5131 | memset(nv, 0, ha->nvram_size); | |
5132 | nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION); | |
5133 | nv->version = __constant_cpu_to_le16(ICB_VERSION); | |
5134 | nv->frame_payload_size = __constant_cpu_to_le16(2048); | |
5135 | nv->execution_throttle = __constant_cpu_to_le16(0xFFFF); | |
5136 | nv->exchange_count = __constant_cpu_to_le16(0); | |
5137 | nv->port_name[0] = 0x21; | |
e5b68a61 | 5138 | nv->port_name[1] = 0x00 + ha->port_no; |
3a03eb79 AV |
5139 | nv->port_name[2] = 0x00; |
5140 | nv->port_name[3] = 0xe0; | |
5141 | nv->port_name[4] = 0x8b; | |
5142 | nv->port_name[5] = 0x1c; | |
5143 | nv->port_name[6] = 0x55; | |
5144 | nv->port_name[7] = 0x86; | |
5145 | nv->node_name[0] = 0x20; | |
5146 | nv->node_name[1] = 0x00; | |
5147 | nv->node_name[2] = 0x00; | |
5148 | nv->node_name[3] = 0xe0; | |
5149 | nv->node_name[4] = 0x8b; | |
5150 | nv->node_name[5] = 0x1c; | |
5151 | nv->node_name[6] = 0x55; | |
5152 | nv->node_name[7] = 0x86; | |
5153 | nv->login_retry_count = __constant_cpu_to_le16(8); | |
5154 | nv->interrupt_delay_timer = __constant_cpu_to_le16(0); | |
5155 | nv->login_timeout = __constant_cpu_to_le16(0); | |
5156 | nv->firmware_options_1 = | |
5157 | __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); | |
5158 | nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4); | |
5159 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12); | |
5160 | nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13); | |
5161 | nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10); | |
5162 | nv->efi_parameters = __constant_cpu_to_le32(0); | |
5163 | nv->reset_delay = 5; | |
5164 | nv->max_luns_per_target = __constant_cpu_to_le16(128); | |
5165 | nv->port_down_retry_count = __constant_cpu_to_le16(30); | |
5166 | nv->link_down_timeout = __constant_cpu_to_le16(30); | |
eeebcc92 | 5167 | nv->enode_mac[0] = 0x00; |
3a03eb79 AV |
5168 | nv->enode_mac[1] = 0x02; |
5169 | nv->enode_mac[2] = 0x03; | |
5170 | nv->enode_mac[3] = 0x04; | |
5171 | nv->enode_mac[4] = 0x05; | |
e5b68a61 | 5172 | nv->enode_mac[5] = 0x06 + ha->port_no; |
3a03eb79 AV |
5173 | |
5174 | rval = 1; | |
5175 | } | |
5176 | ||
5177 | /* Reset Initialization control block */ | |
5178 | memset(icb, 0, sizeof(struct init_cb_81xx)); | |
5179 | ||
5180 | /* Copy 1st segment. */ | |
5181 | dptr1 = (uint8_t *)icb; | |
5182 | dptr2 = (uint8_t *)&nv->version; | |
5183 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; | |
5184 | while (cnt--) | |
5185 | *dptr1++ = *dptr2++; | |
5186 | ||
5187 | icb->login_retry_count = nv->login_retry_count; | |
5188 | ||
5189 | /* Copy 2nd segment. */ | |
5190 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; | |
5191 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; | |
5192 | cnt = (uint8_t *)&icb->reserved_5 - | |
5193 | (uint8_t *)&icb->interrupt_delay_timer; | |
5194 | while (cnt--) | |
5195 | *dptr1++ = *dptr2++; | |
5196 | ||
5197 | memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac)); | |
5198 | /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */ | |
5199 | if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) { | |
5200 | icb->enode_mac[0] = 0x01; | |
5201 | icb->enode_mac[1] = 0x02; | |
5202 | icb->enode_mac[2] = 0x03; | |
5203 | icb->enode_mac[3] = 0x04; | |
5204 | icb->enode_mac[4] = 0x05; | |
e5b68a61 | 5205 | icb->enode_mac[5] = 0x06 + ha->port_no; |
3a03eb79 AV |
5206 | } |
5207 | ||
b64b0e8f AV |
5208 | /* Use extended-initialization control block. */ |
5209 | memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb)); | |
5210 | ||
3a03eb79 AV |
5211 | /* |
5212 | * Setup driver NVRAM options. | |
5213 | */ | |
5214 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), | |
a9083016 | 5215 | "QLE8XXX"); |
3a03eb79 AV |
5216 | |
5217 | /* Use alternate WWN? */ | |
5218 | if (nv->host_p & __constant_cpu_to_le32(BIT_15)) { | |
5219 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); | |
5220 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); | |
5221 | } | |
5222 | ||
5223 | /* Prepare nodename */ | |
5224 | if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) { | |
5225 | /* | |
5226 | * Firmware will apply the following mask if the nodename was | |
5227 | * not provided. | |
5228 | */ | |
5229 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); | |
5230 | icb->node_name[0] &= 0xF0; | |
5231 | } | |
5232 | ||
5233 | /* Set host adapter parameters. */ | |
5234 | ha->flags.disable_risc_code_load = 0; | |
5235 | ha->flags.enable_lip_reset = 0; | |
5236 | ha->flags.enable_lip_full_login = | |
5237 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; | |
5238 | ha->flags.enable_target_reset = | |
5239 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; | |
5240 | ha->flags.enable_led_scheme = 0; | |
5241 | ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; | |
5242 | ||
5243 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & | |
5244 | (BIT_6 | BIT_5 | BIT_4)) >> 4; | |
5245 | ||
5246 | /* save HBA serial number */ | |
5247 | ha->serial0 = icb->port_name[5]; | |
5248 | ha->serial1 = icb->port_name[6]; | |
5249 | ha->serial2 = icb->port_name[7]; | |
5250 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); | |
5251 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); | |
5252 | ||
5253 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); | |
5254 | ||
5255 | ha->retry_count = le16_to_cpu(nv->login_retry_count); | |
5256 | ||
5257 | /* Set minimum login_timeout to 4 seconds. */ | |
5258 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) | |
5259 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); | |
5260 | if (le16_to_cpu(nv->login_timeout) < 4) | |
5261 | nv->login_timeout = __constant_cpu_to_le16(4); | |
5262 | ha->login_timeout = le16_to_cpu(nv->login_timeout); | |
5263 | icb->login_timeout = nv->login_timeout; | |
5264 | ||
5265 | /* Set minimum RATOV to 100 tenths of a second. */ | |
5266 | ha->r_a_tov = 100; | |
5267 | ||
5268 | ha->loop_reset_delay = nv->reset_delay; | |
5269 | ||
5270 | /* Link Down Timeout = 0: | |
5271 | * | |
5272 | * When Port Down timer expires we will start returning | |
5273 | * I/O's to OS with "DID_NO_CONNECT". | |
5274 | * | |
5275 | * Link Down Timeout != 0: | |
5276 | * | |
5277 | * The driver waits for the link to come up after link down | |
5278 | * before returning I/Os to OS with "DID_NO_CONNECT". | |
5279 | */ | |
5280 | if (le16_to_cpu(nv->link_down_timeout) == 0) { | |
5281 | ha->loop_down_abort_time = | |
5282 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); | |
5283 | } else { | |
5284 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); | |
5285 | ha->loop_down_abort_time = | |
5286 | (LOOP_DOWN_TIME - ha->link_down_timeout); | |
5287 | } | |
5288 | ||
5289 | /* Need enough time to try and get the port back. */ | |
5290 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); | |
5291 | if (qlport_down_retry) | |
5292 | ha->port_down_retry_count = qlport_down_retry; | |
5293 | ||
5294 | /* Set login_retry_count */ | |
5295 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); | |
5296 | if (ha->port_down_retry_count == | |
5297 | le16_to_cpu(nv->port_down_retry_count) && | |
5298 | ha->port_down_retry_count > 3) | |
5299 | ha->login_retry_count = ha->port_down_retry_count; | |
5300 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) | |
5301 | ha->login_retry_count = ha->port_down_retry_count; | |
5302 | if (ql2xloginretrycount) | |
5303 | ha->login_retry_count = ql2xloginretrycount; | |
5304 | ||
5305 | /* Enable ZIO. */ | |
5306 | if (!vha->flags.init_done) { | |
5307 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & | |
5308 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); | |
5309 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? | |
5310 | le16_to_cpu(icb->interrupt_delay_timer): 2; | |
5311 | } | |
5312 | icb->firmware_options_2 &= __constant_cpu_to_le32( | |
5313 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); | |
5314 | vha->flags.process_response_queue = 0; | |
5315 | if (ha->zio_mode != QLA_ZIO_DISABLED) { | |
5316 | ha->zio_mode = QLA_ZIO_MODE_6; | |
5317 | ||
5318 | DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay " | |
5319 | "(%d us).\n", vha->host_no, ha->zio_mode, | |
5320 | ha->zio_timer * 100)); | |
5321 | qla_printk(KERN_INFO, ha, | |
5322 | "ZIO mode %d enabled; timer delay (%d us).\n", | |
5323 | ha->zio_mode, ha->zio_timer * 100); | |
5324 | ||
5325 | icb->firmware_options_2 |= cpu_to_le32( | |
5326 | (uint32_t)ha->zio_mode); | |
5327 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); | |
5328 | vha->flags.process_response_queue = 1; | |
5329 | } | |
5330 | ||
5331 | if (rval) { | |
5332 | DEBUG2_3(printk(KERN_WARNING | |
5333 | "scsi(%ld): NVRAM configuration failed!\n", vha->host_no)); | |
5334 | } | |
5335 | return (rval); | |
5336 | } | |
5337 | ||
a9083016 GM |
5338 | int |
5339 | qla82xx_restart_isp(scsi_qla_host_t *vha) | |
5340 | { | |
5341 | int status, rval; | |
5342 | uint32_t wait_time; | |
5343 | struct qla_hw_data *ha = vha->hw; | |
5344 | struct req_que *req = ha->req_q_map[0]; | |
5345 | struct rsp_que *rsp = ha->rsp_q_map[0]; | |
5346 | struct scsi_qla_host *vp; | |
feafb7b1 | 5347 | unsigned long flags; |
a9083016 GM |
5348 | |
5349 | status = qla2x00_init_rings(vha); | |
5350 | if (!status) { | |
5351 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); | |
5352 | ha->flags.chip_reset_done = 1; | |
5353 | ||
5354 | status = qla2x00_fw_ready(vha); | |
5355 | if (!status) { | |
5356 | qla_printk(KERN_INFO, ha, | |
5357 | "%s(): Start configure loop, " | |
5358 | "status = %d\n", __func__, status); | |
5359 | ||
5360 | /* Issue a marker after FW becomes ready. */ | |
5361 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); | |
5362 | ||
5363 | vha->flags.online = 1; | |
5364 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ | |
5365 | wait_time = 256; | |
5366 | do { | |
5367 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); | |
5368 | qla2x00_configure_loop(vha); | |
5369 | wait_time--; | |
5370 | } while (!atomic_read(&vha->loop_down_timer) && | |
5371 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) && | |
5372 | wait_time && | |
5373 | (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))); | |
5374 | } | |
5375 | ||
5376 | /* if no cable then assume it's good */ | |
5377 | if ((vha->device_flags & DFLG_NO_CABLE)) | |
5378 | status = 0; | |
5379 | ||
5380 | qla_printk(KERN_INFO, ha, | |
5381 | "%s(): Configure loop done, status = 0x%x\n", | |
5382 | __func__, status); | |
5383 | } | |
5384 | ||
5385 | if (!status) { | |
5386 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); | |
5387 | ||
5388 | if (!atomic_read(&vha->loop_down_timer)) { | |
5389 | /* | |
5390 | * Issue marker command only when we are going | |
5391 | * to start the I/O . | |
5392 | */ | |
5393 | vha->marker_needed = 1; | |
5394 | } | |
5395 | ||
5396 | vha->flags.online = 1; | |
5397 | ||
5398 | ha->isp_ops->enable_intrs(ha); | |
5399 | ||
5400 | ha->isp_abort_cnt = 0; | |
5401 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); | |
5402 | ||
5403 | if (ha->fce) { | |
5404 | ha->flags.fce_enabled = 1; | |
5405 | memset(ha->fce, 0, | |
5406 | fce_calc_size(ha->fce_bufs)); | |
5407 | rval = qla2x00_enable_fce_trace(vha, | |
5408 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, | |
5409 | &ha->fce_bufs); | |
5410 | if (rval) { | |
5411 | qla_printk(KERN_WARNING, ha, | |
5412 | "Unable to reinitialize FCE " | |
5413 | "(%d).\n", rval); | |
5414 | ha->flags.fce_enabled = 0; | |
5415 | } | |
5416 | } | |
5417 | ||
5418 | if (ha->eft) { | |
5419 | memset(ha->eft, 0, EFT_SIZE); | |
5420 | rval = qla2x00_enable_eft_trace(vha, | |
5421 | ha->eft_dma, EFT_NUM_BUFFERS); | |
5422 | if (rval) { | |
5423 | qla_printk(KERN_WARNING, ha, | |
5424 | "Unable to reinitialize EFT " | |
5425 | "(%d).\n", rval); | |
5426 | } | |
5427 | } | |
a9083016 GM |
5428 | } |
5429 | ||
5430 | if (!status) { | |
5431 | DEBUG(printk(KERN_INFO | |
5432 | "qla82xx_restart_isp(%ld): succeeded.\n", | |
5433 | vha->host_no)); | |
feafb7b1 AE |
5434 | |
5435 | spin_lock_irqsave(&ha->vport_slock, flags); | |
5436 | list_for_each_entry(vp, &ha->vp_list, list) { | |
5437 | if (vp->vp_idx) { | |
5438 | atomic_inc(&vp->vref_count); | |
5439 | spin_unlock_irqrestore(&ha->vport_slock, flags); | |
5440 | ||
a9083016 | 5441 | qla2x00_vp_abort_isp(vp); |
feafb7b1 AE |
5442 | |
5443 | spin_lock_irqsave(&ha->vport_slock, flags); | |
5444 | atomic_dec(&vp->vref_count); | |
5445 | } | |
a9083016 | 5446 | } |
feafb7b1 AE |
5447 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
5448 | ||
a9083016 GM |
5449 | } else { |
5450 | qla_printk(KERN_INFO, ha, | |
5451 | "qla82xx_restart_isp: **** FAILED ****\n"); | |
5452 | } | |
5453 | ||
5454 | return status; | |
5455 | } | |
5456 | ||
3a03eb79 | 5457 | void |
ae97c91e | 5458 | qla81xx_update_fw_options(scsi_qla_host_t *vha) |
3a03eb79 | 5459 | { |
ae97c91e AV |
5460 | struct qla_hw_data *ha = vha->hw; |
5461 | ||
5462 | if (!ql2xetsenable) | |
5463 | return; | |
5464 | ||
5465 | /* Enable ETS Burst. */ | |
5466 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); | |
5467 | ha->fw_options[2] |= BIT_9; | |
5468 | qla2x00_set_fw_options(vha, ha->fw_options); | |
3a03eb79 | 5469 | } |
09ff701a SR |
5470 | |
5471 | /* | |
5472 | * qla24xx_get_fcp_prio | |
5473 | * Gets the fcp cmd priority value for the logged in port. | |
5474 | * Looks for a match of the port descriptors within | |
5475 | * each of the fcp prio config entries. If a match is found, | |
5476 | * the tag (priority) value is returned. | |
5477 | * | |
5478 | * Input: | |
21090cbe | 5479 | * vha = scsi host structure pointer. |
09ff701a SR |
5480 | * fcport = port structure pointer. |
5481 | * | |
5482 | * Return: | |
6c452a45 | 5483 | * non-zero (if found) |
09ff701a SR |
5484 | * 0 (if not found) |
5485 | * | |
5486 | * Context: | |
5487 | * Kernel context | |
5488 | */ | |
5489 | uint8_t | |
5490 | qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport) | |
5491 | { | |
5492 | int i, entries; | |
5493 | uint8_t pid_match, wwn_match; | |
5494 | uint8_t priority; | |
5495 | uint32_t pid1, pid2; | |
5496 | uint64_t wwn1, wwn2; | |
5497 | struct qla_fcp_prio_entry *pri_entry; | |
5498 | struct qla_hw_data *ha = vha->hw; | |
5499 | ||
5500 | if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled) | |
5501 | return 0; | |
5502 | ||
5503 | priority = 0; | |
5504 | entries = ha->fcp_prio_cfg->num_entries; | |
5505 | pri_entry = &ha->fcp_prio_cfg->entry[0]; | |
5506 | ||
5507 | for (i = 0; i < entries; i++) { | |
5508 | pid_match = wwn_match = 0; | |
5509 | ||
5510 | if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) { | |
5511 | pri_entry++; | |
5512 | continue; | |
5513 | } | |
5514 | ||
5515 | /* check source pid for a match */ | |
5516 | if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) { | |
5517 | pid1 = pri_entry->src_pid & INVALID_PORT_ID; | |
5518 | pid2 = vha->d_id.b24 & INVALID_PORT_ID; | |
5519 | if (pid1 == INVALID_PORT_ID) | |
5520 | pid_match++; | |
5521 | else if (pid1 == pid2) | |
5522 | pid_match++; | |
5523 | } | |
5524 | ||
5525 | /* check destination pid for a match */ | |
5526 | if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) { | |
5527 | pid1 = pri_entry->dst_pid & INVALID_PORT_ID; | |
5528 | pid2 = fcport->d_id.b24 & INVALID_PORT_ID; | |
5529 | if (pid1 == INVALID_PORT_ID) | |
5530 | pid_match++; | |
5531 | else if (pid1 == pid2) | |
5532 | pid_match++; | |
5533 | } | |
5534 | ||
5535 | /* check source WWN for a match */ | |
5536 | if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) { | |
5537 | wwn1 = wwn_to_u64(vha->port_name); | |
5538 | wwn2 = wwn_to_u64(pri_entry->src_wwpn); | |
5539 | if (wwn2 == (uint64_t)-1) | |
5540 | wwn_match++; | |
5541 | else if (wwn1 == wwn2) | |
5542 | wwn_match++; | |
5543 | } | |
5544 | ||
5545 | /* check destination WWN for a match */ | |
5546 | if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) { | |
5547 | wwn1 = wwn_to_u64(fcport->port_name); | |
5548 | wwn2 = wwn_to_u64(pri_entry->dst_wwpn); | |
5549 | if (wwn2 == (uint64_t)-1) | |
5550 | wwn_match++; | |
5551 | else if (wwn1 == wwn2) | |
5552 | wwn_match++; | |
5553 | } | |
5554 | ||
5555 | if (pid_match == 2 || wwn_match == 2) { | |
5556 | /* Found a matching entry */ | |
5557 | if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID) | |
5558 | priority = pri_entry->tag; | |
5559 | break; | |
5560 | } | |
5561 | ||
5562 | pri_entry++; | |
5563 | } | |
5564 | ||
5565 | return priority; | |
5566 | } | |
5567 | ||
5568 | /* | |
5569 | * qla24xx_update_fcport_fcp_prio | |
5570 | * Activates fcp priority for the logged in fc port | |
5571 | * | |
5572 | * Input: | |
21090cbe | 5573 | * vha = scsi host structure pointer. |
09ff701a SR |
5574 | * fcp = port structure pointer. |
5575 | * | |
5576 | * Return: | |
5577 | * QLA_SUCCESS or QLA_FUNCTION_FAILED | |
5578 | * | |
5579 | * Context: | |
5580 | * Kernel context. | |
5581 | */ | |
5582 | int | |
21090cbe | 5583 | qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport) |
09ff701a SR |
5584 | { |
5585 | int ret; | |
5586 | uint8_t priority; | |
5587 | uint16_t mb[5]; | |
5588 | ||
21090cbe MI |
5589 | if (fcport->port_type != FCT_TARGET || |
5590 | fcport->loop_id == FC_NO_LOOP_ID) | |
09ff701a SR |
5591 | return QLA_FUNCTION_FAILED; |
5592 | ||
21090cbe MI |
5593 | priority = qla24xx_get_fcp_prio(vha, fcport); |
5594 | ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb); | |
09ff701a SR |
5595 | if (ret == QLA_SUCCESS) |
5596 | fcport->fcp_prio = priority; | |
5597 | else | |
5598 | DEBUG2(printk(KERN_WARNING | |
5599 | "scsi(%ld): Unable to activate fcp priority, " | |
21090cbe | 5600 | " ret=0x%x\n", vha->host_no, ret)); |
09ff701a SR |
5601 | |
5602 | return ret; | |
5603 | } | |
5604 | ||
5605 | /* | |
5606 | * qla24xx_update_all_fcp_prio | |
5607 | * Activates fcp priority for all the logged in ports | |
5608 | * | |
5609 | * Input: | |
5610 | * ha = adapter block pointer. | |
5611 | * | |
5612 | * Return: | |
5613 | * QLA_SUCCESS or QLA_FUNCTION_FAILED | |
5614 | * | |
5615 | * Context: | |
5616 | * Kernel context. | |
5617 | */ | |
5618 | int | |
5619 | qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha) | |
5620 | { | |
5621 | int ret; | |
5622 | fc_port_t *fcport; | |
5623 | ||
5624 | ret = QLA_FUNCTION_FAILED; | |
5625 | /* We need to set priority for all logged in ports */ | |
5626 | list_for_each_entry(fcport, &vha->vp_fcports, list) | |
5627 | ret = qla24xx_update_fcport_fcp_prio(vha, fcport); | |
5628 | ||
5629 | return ret; | |
5630 | } |