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