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