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