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