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