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