blob: f8cfeb0e91a6b6fa48753d9e4c6819644efb33e7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez01e58d82008-04-03 13:13:13 -07003 * Copyright (c) 2003-2008 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
8
9#include <linux/delay.h>
Andrew Vasquez0107109e2005-07-06 10:31:37 -070010#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
12#include "qla_devtbl.h"
13
David Miller4e08df32007-04-16 12:37:43 -070014#ifdef CONFIG_SPARC
15#include <asm/prom.h>
David Miller4e08df32007-04-16 12:37:43 -070016#endif
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018/*
19* QLogic ISP2x00 Hardware Support Function Prototypes.
20*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070021static int qla2x00_isp_firmware(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070022static void qla2x00_resize_request_q(scsi_qla_host_t *);
23static int qla2x00_setup_chip(scsi_qla_host_t *);
24static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
25static int qla2x00_init_rings(scsi_qla_host_t *);
26static int qla2x00_fw_ready(scsi_qla_host_t *);
27static int qla2x00_configure_hba(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028static int qla2x00_configure_loop(scsi_qla_host_t *);
29static int qla2x00_configure_local_loop(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static int qla2x00_configure_fabric(scsi_qla_host_t *);
31static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
32static int qla2x00_device_resync(scsi_qla_host_t *);
33static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
34 uint16_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36static int qla2x00_restart_isp(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Adrian Bunk413975a2006-06-30 02:33:06 -070038static int qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev);
39
Harihara Kadayam4d4df192008-04-03 13:13:26 -070040static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
41static int qla84xx_init_chip(scsi_qla_host_t *);
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043/****************************************************************************/
44/* QLogic ISP2x00 Hardware Support Functions. */
45/****************************************************************************/
46
47/*
48* qla2x00_initialize_adapter
49* Initialize board.
50*
51* Input:
52* ha = adapter block pointer.
53*
54* Returns:
55* 0 = success
56*/
57int
58qla2x00_initialize_adapter(scsi_qla_host_t *ha)
59{
60 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62 /* Clear adapter flags. */
63 ha->flags.online = 0;
64 ha->flags.reset_active = 0;
65 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
66 atomic_set(&ha->loop_state, LOOP_DOWN);
Andrew Vasquez26032212007-01-29 10:22:23 -080067 ha->device_flags = DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 ha->dpc_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 ha->flags.management_server_logged_in = 0;
70 ha->marker_needed = 0;
71 ha->mbx_flags = 0;
72 ha->isp_abort_cnt = 0;
73 ha->beacon_blink_led = 0;
Andrew Vasquezcca53352005-08-26 19:08:30 -070074 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Andrew Vasquez0107109e2005-07-06 10:31:37 -070076 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
Andrew Vasquezfd34f552007-07-19 15:06:00 -070077 rval = ha->isp_ops->pci_config(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 if (rval) {
Andrew Vasquez7c98a042007-01-29 10:22:29 -080079 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 ha->host_no));
81 return (rval);
82 }
83
Andrew Vasquezfd34f552007-07-19 15:06:00 -070084 ha->isp_ops->reset_chip(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Andrew Vasquezfd34f552007-07-19 15:06:00 -070086 ha->isp_ops->get_flash_version(ha, ha->request_ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -080087
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -070089
Andrew Vasquezfd34f552007-07-19 15:06:00 -070090 ha->isp_ops->nvram_config(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Andrew Vasquezd4c760c2006-06-23 16:10:39 -070092 if (ha->flags.disable_serdes) {
93 /* Mask HBA via NVRAM settings? */
94 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
95 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
96 ha->port_name[0], ha->port_name[1],
97 ha->port_name[2], ha->port_name[3],
98 ha->port_name[4], ha->port_name[5],
99 ha->port_name[6], ha->port_name[7]);
100 return QLA_FUNCTION_FAILED;
101 }
102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
104
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800105 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700106 rval = ha->isp_ops->chip_diag(ha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800107 if (rval)
108 return (rval);
109 rval = qla2x00_setup_chip(ha);
110 if (rval)
111 return (rval);
Andrew Vasquez7d232c72008-04-03 13:13:22 -0700112 qla2xxx_get_flash_info(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700114 if (IS_QLA84XX(ha)) {
115 ha->cs84xx = qla84xx_get_chip(ha);
116 if (!ha->cs84xx) {
117 qla_printk(KERN_ERR, ha,
118 "Unable to configure ISP84XX.\n");
119 return QLA_FUNCTION_FAILED;
120 }
121 }
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800122 rval = qla2x00_init_rings(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124 return (rval);
125}
126
127/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700128 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 * @ha: HA context
130 *
131 * Returns 0 on success.
132 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700133int
134qla2100_pci_config(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700136 uint16_t w;
Adam Kropelin27b2f672005-09-16 19:28:20 -0700137 uint32_t d;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700138 unsigned long flags;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700139 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700142 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700145 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
147
148 /* Reset expansion ROM address decode enable */
Adam Kropelin27b2f672005-09-16 19:28:20 -0700149 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
150 d &= ~PCI_ROM_ADDRESS_ENABLE;
151 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700153 /* Get PCI bus information. */
154 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700155 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700156 spin_unlock_irqrestore(&ha->hardware_lock, flags);
157
158 return QLA_SUCCESS;
159}
160
161/**
162 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
163 * @ha: HA context
164 *
165 * Returns 0 on success.
166 */
167int
168qla2300_pci_config(scsi_qla_host_t *ha)
169{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700170 uint16_t w;
Adam Kropelin27b2f672005-09-16 19:28:20 -0700171 uint32_t d;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700172 unsigned long flags = 0;
173 uint32_t cnt;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700174 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700175
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700176 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700177 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700178
179 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700180 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700181
182 if (IS_QLA2322(ha) || IS_QLA6322(ha))
183 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700184 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700185
186 /*
187 * If this is a 2300 card and not 2312, reset the
188 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
189 * the 2310 also reports itself as a 2300 so we need to get the
190 * fb revision level -- a 6 indicates it really is a 2300 and
191 * not a 2310.
192 */
193 if (IS_QLA2300(ha)) {
194 spin_lock_irqsave(&ha->hardware_lock, flags);
195
196 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700197 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700198 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700199 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700200 break;
201
202 udelay(10);
203 }
204
205 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700206 WRT_REG_WORD(&reg->ctrl_status, 0x20);
207 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700208
209 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700210 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700211
212 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700213 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700214
215 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700216 WRT_REG_WORD(&reg->ctrl_status, 0x0);
217 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700218
219 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700220 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700221 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700222 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700223 break;
224
225 udelay(10);
226 }
227
228 spin_unlock_irqrestore(&ha->hardware_lock, flags);
229 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700230
231 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
232
233 /* Reset expansion ROM address decode enable */
Adam Kropelin27b2f672005-09-16 19:28:20 -0700234 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
235 d &= ~PCI_ROM_ADDRESS_ENABLE;
236 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700237
238 /* Get PCI bus information. */
239 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700240 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700241 spin_unlock_irqrestore(&ha->hardware_lock, flags);
242
243 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244}
245
246/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700247 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
248 * @ha: HA context
249 *
250 * Returns 0 on success.
251 */
252int
253qla24xx_pci_config(scsi_qla_host_t *ha)
254{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700255 uint16_t w;
Adam Kropelin27b2f672005-09-16 19:28:20 -0700256 uint32_t d;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700257 unsigned long flags = 0;
258 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700259
260 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700261 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700262
263 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700264 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700265 w &= ~PCI_COMMAND_INTX_DISABLE;
266 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
267
268 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
269
270 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700271 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
272 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700273
274 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700275 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
276 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700277
278 /* Reset expansion ROM address decode enable */
Adam Kropelin27b2f672005-09-16 19:28:20 -0700279 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
280 d &= ~PCI_ROM_ADDRESS_ENABLE;
281 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700282
Auke Kok44c10132007-06-08 15:46:36 -0700283 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800284
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700285 /* Get PCI bus information. */
286 spin_lock_irqsave(&ha->hardware_lock, flags);
287 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
288 spin_unlock_irqrestore(&ha->hardware_lock, flags);
289
290 return QLA_SUCCESS;
291}
292
293/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700294 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
295 * @ha: HA context
296 *
297 * Returns 0 on success.
298 */
299int
300qla25xx_pci_config(scsi_qla_host_t *ha)
301{
302 uint16_t w;
303 uint32_t d;
304
305 pci_set_master(ha->pdev);
306 pci_try_set_mwi(ha->pdev);
307
308 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
309 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
310 w &= ~PCI_COMMAND_INTX_DISABLE;
311 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
312
313 /* PCIe -- adjust Maximum Read Request Size (2048). */
314 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
315 pcie_set_readrq(ha->pdev, 2048);
316
317 /* Reset expansion ROM address decode enable */
318 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
319 d &= ~PCI_ROM_ADDRESS_ENABLE;
320 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
321
322 ha->chip_revision = ha->pdev->revision;
323
324 return QLA_SUCCESS;
325}
326
327/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 * qla2x00_isp_firmware() - Choose firmware image.
329 * @ha: HA context
330 *
331 * Returns 0 on success.
332 */
333static int
334qla2x00_isp_firmware(scsi_qla_host_t *ha)
335{
336 int rval;
337
338 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700339 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
341 if (ha->flags.disable_risc_code_load) {
342 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
343 ha->host_no));
344 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
345
346 /* Verify checksum of loaded RISC code. */
Andrew Vasquez441d1072006-05-17 15:09:34 -0700347 rval = qla2x00_verify_checksum(ha, ha->fw_srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 }
349
350 if (rval) {
351 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
352 ha->host_no));
353 }
354
355 return (rval);
356}
357
358/**
359 * qla2x00_reset_chip() - Reset ISP chip.
360 * @ha: HA context
361 *
362 * Returns 0 on success.
363 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700364void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700365qla2x00_reset_chip(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366{
367 unsigned long flags = 0;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700368 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 uint16_t cmd;
371
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700372 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374 spin_lock_irqsave(&ha->hardware_lock, flags);
375
376 /* Turn off master enable */
377 cmd = 0;
378 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
379 cmd &= ~PCI_COMMAND_MASTER;
380 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
381
382 if (!IS_QLA2100(ha)) {
383 /* Pause RISC. */
384 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
385 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
386 for (cnt = 0; cnt < 30000; cnt++) {
387 if ((RD_REG_WORD(&reg->hccr) &
388 HCCR_RISC_PAUSE) != 0)
389 break;
390 udelay(100);
391 }
392 } else {
393 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
394 udelay(10);
395 }
396
397 /* Select FPM registers. */
398 WRT_REG_WORD(&reg->ctrl_status, 0x20);
399 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
400
401 /* FPM Soft Reset. */
402 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
403 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
404
405 /* Toggle Fpm Reset. */
406 if (!IS_QLA2200(ha)) {
407 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
408 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
409 }
410
411 /* Select frame buffer registers. */
412 WRT_REG_WORD(&reg->ctrl_status, 0x10);
413 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
414
415 /* Reset frame buffer FIFOs. */
416 if (IS_QLA2200(ha)) {
417 WRT_FB_CMD_REG(ha, reg, 0xa000);
418 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
419 } else {
420 WRT_FB_CMD_REG(ha, reg, 0x00fc);
421
422 /* Read back fb_cmd until zero or 3 seconds max */
423 for (cnt = 0; cnt < 3000; cnt++) {
424 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
425 break;
426 udelay(100);
427 }
428 }
429
430 /* Select RISC module registers. */
431 WRT_REG_WORD(&reg->ctrl_status, 0);
432 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
433
434 /* Reset RISC processor. */
435 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
436 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
437
438 /* Release RISC processor. */
439 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
440 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
441 }
442
443 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
444 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
445
446 /* Reset ISP chip. */
447 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
448
449 /* Wait for RISC to recover from reset. */
450 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
451 /*
452 * It is necessary to for a delay here since the card doesn't
453 * respond to PCI reads during a reset. On some architectures
454 * this will result in an MCA.
455 */
456 udelay(20);
457 for (cnt = 30000; cnt; cnt--) {
458 if ((RD_REG_WORD(&reg->ctrl_status) &
459 CSR_ISP_SOFT_RESET) == 0)
460 break;
461 udelay(100);
462 }
463 } else
464 udelay(10);
465
466 /* Reset RISC processor. */
467 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
468
469 WRT_REG_WORD(&reg->semaphore, 0);
470
471 /* Release RISC processor. */
472 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
473 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
474
475 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
476 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700477 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
480 udelay(100);
481 }
482 } else
483 udelay(100);
484
485 /* Turn on master enable */
486 cmd |= PCI_COMMAND_MASTER;
487 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
488
489 /* Disable RISC pause on FPM parity error. */
490 if (!IS_QLA2100(ha)) {
491 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
492 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
493 }
494
495 spin_unlock_irqrestore(&ha->hardware_lock, flags);
496}
497
498/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700499 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700500 * @ha: HA context
501 *
502 * Returns 0 on success.
503 */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700504static inline void
505qla24xx_reset_risc(scsi_qla_host_t *ha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700506{
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -0700507 int hw_evt = 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700508 unsigned long flags = 0;
509 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
510 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800511 uint16_t wd;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700512
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700513 spin_lock_irqsave(&ha->hardware_lock, flags);
514
515 /* Reset RISC. */
516 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
517 for (cnt = 0; cnt < 30000; cnt++) {
518 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
519 break;
520
521 udelay(10);
522 }
523
524 WRT_REG_DWORD(&reg->ctrl_status,
525 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800526 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700527
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800528 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700529 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700530 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
531 for (cnt = 10000 ; cnt && d2; cnt--) {
532 udelay(5);
533 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
534 barrier();
535 }
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -0700536 if (cnt == 0)
537 hw_evt = 1;
Andrew Vasquez88c26662005-07-08 17:59:26 -0700538
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800539 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700540 d2 = RD_REG_DWORD(&reg->ctrl_status);
541 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
542 udelay(5);
543 d2 = RD_REG_DWORD(&reg->ctrl_status);
544 barrier();
545 }
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -0700546 if (cnt == 0 || hw_evt)
547 qla2xxx_hw_event_log(ha, HW_EVENT_RESET_ERR,
548 RD_REG_WORD(&reg->mailbox1), RD_REG_WORD(&reg->mailbox2),
549 RD_REG_WORD(&reg->mailbox3));
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700550
551 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
552 RD_REG_DWORD(&reg->hccr);
553
554 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
555 RD_REG_DWORD(&reg->hccr);
556
557 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
558 RD_REG_DWORD(&reg->hccr);
559
560 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
561 for (cnt = 6000000 ; cnt && d2; cnt--) {
562 udelay(5);
563 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
564 barrier();
565 }
566
567 spin_unlock_irqrestore(&ha->hardware_lock, flags);
568}
569
570/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700571 * qla24xx_reset_chip() - Reset ISP24xx chip.
572 * @ha: HA context
573 *
574 * Returns 0 on success.
575 */
576void
577qla24xx_reset_chip(scsi_qla_host_t *ha)
578{
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700579 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700580
581 /* Perform RISC reset. */
582 qla24xx_reset_risc(ha);
583}
584
585/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 * qla2x00_chip_diag() - Test chip for proper operation.
587 * @ha: HA context
588 *
589 * Returns 0 on success.
590 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700591int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592qla2x00_chip_diag(scsi_qla_host_t *ha)
593{
594 int rval;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700595 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 unsigned long flags = 0;
597 uint16_t data;
598 uint32_t cnt;
599 uint16_t mb[5];
600
601 /* Assume a failed state */
602 rval = QLA_FUNCTION_FAILED;
603
604 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
605 ha->host_no, (u_long)&reg->flash_address));
606
607 spin_lock_irqsave(&ha->hardware_lock, flags);
608
609 /* Reset ISP chip. */
610 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
611
612 /*
613 * We need to have a delay here since the card will not respond while
614 * in reset causing an MCA on some architectures.
615 */
616 udelay(20);
617 data = qla2x00_debounce_register(&reg->ctrl_status);
618 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
619 udelay(5);
620 data = RD_REG_WORD(&reg->ctrl_status);
621 barrier();
622 }
623
624 if (!cnt)
625 goto chip_diag_failed;
626
627 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
628 ha->host_no));
629
630 /* Reset RISC processor. */
631 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
632 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
633
634 /* Workaround for QLA2312 PCI parity error */
635 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
636 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
637 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
638 udelay(5);
639 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700640 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 }
642 } else
643 udelay(10);
644
645 if (!cnt)
646 goto chip_diag_failed;
647
648 /* Check product ID of chip */
649 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
650
651 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
652 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
653 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
654 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
655 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
656 mb[3] != PROD_ID_3) {
657 qla_printk(KERN_WARNING, ha,
658 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
659
660 goto chip_diag_failed;
661 }
662 ha->product_id[0] = mb[1];
663 ha->product_id[1] = mb[2];
664 ha->product_id[2] = mb[3];
665 ha->product_id[3] = mb[4];
666
667 /* Adjust fw RISC transfer size */
668 if (ha->request_q_length > 1024)
669 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
670 else
671 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
672 ha->request_q_length;
673
674 if (IS_QLA2200(ha) &&
675 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
676 /* Limit firmware transfer size with a 2200A */
677 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
678 ha->host_no));
679
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -0800680 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 ha->fw_transfer_size = 128;
682 }
683
684 /* Wrap Incoming Mailboxes Test. */
685 spin_unlock_irqrestore(&ha->hardware_lock, flags);
686
687 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
688 rval = qla2x00_mbx_reg_test(ha);
689 if (rval) {
690 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
691 ha->host_no));
692 qla_printk(KERN_WARNING, ha,
693 "Failed mailbox send register test\n");
694 }
695 else {
696 /* Flag a successful rval */
697 rval = QLA_SUCCESS;
698 }
699 spin_lock_irqsave(&ha->hardware_lock, flags);
700
701chip_diag_failed:
702 if (rval)
703 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
704 "****\n", ha->host_no));
705
706 spin_unlock_irqrestore(&ha->hardware_lock, flags);
707
708 return (rval);
709}
710
711/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700712 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
713 * @ha: HA context
714 *
715 * Returns 0 on success.
716 */
717int
718qla24xx_chip_diag(scsi_qla_host_t *ha)
719{
720 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700721
Andrew Vasquez88c26662005-07-08 17:59:26 -0700722 /* Perform RISC reset. */
723 qla24xx_reset_risc(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700724
725 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
726
727 rval = qla2x00_mbx_reg_test(ha);
728 if (rval) {
729 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
730 ha->host_no));
731 qla_printk(KERN_WARNING, ha,
732 "Failed mailbox send register test\n");
733 } else {
734 /* Flag a successful rval */
735 rval = QLA_SUCCESS;
736 }
737
738 return rval;
739}
740
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700741void
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700742qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
743{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700744 int rval;
745 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800746 eft_size, fce_size;
747 dma_addr_t tc_dma;
748 void *tc;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700749
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700750 if (ha->fw_dump) {
751 qla_printk(KERN_WARNING, ha,
752 "Firmware dump previously allocated.\n");
753 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700754 }
755
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700756 ha->fw_dumped = 0;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800757 fixed_size = mem_size = eft_size = fce_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700758 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
759 fixed_size = sizeof(struct qla2100_fw_dump);
760 } else if (IS_QLA23XX(ha)) {
761 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
762 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
763 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -0700764 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700765 fixed_size = IS_QLA25XX(ha) ?
766 offsetof(struct qla25xx_fw_dump, ext_mem):
767 offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700768 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
769 sizeof(uint32_t);
770
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700771 /* Allocate memory for Fibre Channel Event Buffer. */
772 if (!IS_QLA25XX(ha))
773 goto try_eft;
774
775 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
776 GFP_KERNEL);
777 if (!tc) {
778 qla_printk(KERN_WARNING, ha, "Unable to allocate "
779 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
780 goto try_eft;
781 }
782
783 memset(tc, 0, FCE_SIZE);
784 rval = qla2x00_enable_fce_trace(ha, tc_dma, FCE_NUM_BUFFERS,
785 ha->fce_mb, &ha->fce_bufs);
786 if (rval) {
787 qla_printk(KERN_WARNING, ha, "Unable to initialize "
788 "FCE (%d).\n", rval);
789 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
790 tc_dma);
791 ha->flags.fce_enabled = 0;
792 goto try_eft;
793 }
794
795 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
796 FCE_SIZE / 1024);
797
798 fce_size = sizeof(struct qla2xxx_fce_chain) + EFT_SIZE;
799 ha->flags.fce_enabled = 1;
800 ha->fce_dma = tc_dma;
801 ha->fce = tc;
802try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700803 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800804 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700805 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800806 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700807 qla_printk(KERN_WARNING, ha, "Unable to allocate "
808 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
809 goto cont_alloc;
810 }
811
Andrew Vasquezfc447652008-01-17 09:02:18 -0800812 memset(tc, 0, EFT_SIZE);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800813 rval = qla2x00_enable_eft_trace(ha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700814 if (rval) {
815 qla_printk(KERN_WARNING, ha, "Unable to initialize "
816 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800817 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
818 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700819 goto cont_alloc;
820 }
821
822 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
823 EFT_SIZE / 1024);
824
825 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800826 ha->eft_dma = tc_dma;
827 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700828 }
829cont_alloc:
830 req_q_size = ha->request_q_length * sizeof(request_t);
831 rsp_q_size = ha->response_q_length * sizeof(response_t);
832
833 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
834 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800835 eft_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700836
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700837 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700838 if (!ha->fw_dump) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700839 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700840 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700841
842 if (ha->eft) {
843 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
844 ha->eft_dma);
845 ha->eft = NULL;
846 ha->eft_dma = 0;
847 }
848 return;
849 }
850
851 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
852 dump_size / 1024);
853
854 ha->fw_dump_len = dump_size;
855 ha->fw_dump->signature[0] = 'Q';
856 ha->fw_dump->signature[1] = 'L';
857 ha->fw_dump->signature[2] = 'G';
858 ha->fw_dump->signature[3] = 'C';
859 ha->fw_dump->version = __constant_htonl(1);
860
861 ha->fw_dump->fixed_size = htonl(fixed_size);
862 ha->fw_dump->mem_size = htonl(mem_size);
863 ha->fw_dump->req_q_size = htonl(req_q_size);
864 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
865
866 ha->fw_dump->eft_size = htonl(eft_size);
867 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
868 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
869
870 ha->fw_dump->header_size =
871 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700872}
873
874/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
876 * @ha: HA context
877 *
878 * Returns 0 on success.
879 */
880static void
881qla2x00_resize_request_q(scsi_qla_host_t *ha)
882{
883 int rval;
884 uint16_t fw_iocb_cnt = 0;
885 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
886 dma_addr_t request_dma;
887 request_t *request_ring;
888
889 /* Valid only on recent ISPs. */
890 if (IS_QLA2100(ha) || IS_QLA2200(ha))
891 return;
892
893 /* Retrieve IOCB counts available to the firmware. */
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700894 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt,
895 &ha->max_npiv_vports);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 if (rval)
897 return;
898 /* No point in continuing if current settings are sufficient. */
899 if (fw_iocb_cnt < 1024)
900 return;
901 if (ha->request_q_length >= request_q_length)
902 return;
903
904 /* Attempt to claim larger area for request queue. */
905 request_ring = dma_alloc_coherent(&ha->pdev->dev,
906 (request_q_length + 1) * sizeof(request_t), &request_dma,
907 GFP_KERNEL);
908 if (request_ring == NULL)
909 return;
910
911 /* Resize successful, report extensions. */
912 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
913 (ha->fw_memory_size + 1) / 1024);
914 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
915 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
916
917 /* Clear old allocations. */
918 dma_free_coherent(&ha->pdev->dev,
919 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
920 ha->request_dma);
921
922 /* Begin using larger queue. */
923 ha->request_q_length = request_q_length;
924 ha->request_ring = request_ring;
925 ha->request_dma = request_dma;
926}
927
928/**
929 * qla2x00_setup_chip() - Load and start RISC firmware.
930 * @ha: HA context
931 *
932 * Returns 0 on success.
933 */
934static int
935qla2x00_setup_chip(scsi_qla_host_t *ha)
936{
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700937 int rval;
938 uint32_t srisc_address = 0;
Andrew Vasquez3db06522008-01-31 12:33:49 -0800939 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
940 unsigned long flags;
941
942 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
943 /* Disable SRAM, Instruction RAM and GP RAM parity. */
944 spin_lock_irqsave(&ha->hardware_lock, flags);
945 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
946 RD_REG_WORD(&reg->hccr);
947 spin_unlock_irqrestore(&ha->hardware_lock, flags);
948 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
950 /* Load firmware sequences */
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700951 rval = ha->isp_ops->load_risc(ha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700952 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
954 "code.\n", ha->host_no));
955
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700956 rval = qla2x00_verify_checksum(ha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 if (rval == QLA_SUCCESS) {
958 /* Start firmware execution. */
959 DEBUG(printk("scsi(%ld): Checksum OK, start "
960 "firmware.\n", ha->host_no));
961
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700962 rval = qla2x00_execute_fw(ha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 /* Retrieve firmware information. */
964 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
965 qla2x00_get_fw_version(ha,
966 &ha->fw_major_version,
967 &ha->fw_minor_version,
968 &ha->fw_subminor_version,
969 &ha->fw_attributes, &ha->fw_memory_size);
970 qla2x00_resize_request_q(ha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700971 ha->flags.npiv_supported = 0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700972 if ((IS_QLA24XX(ha) || IS_QLA25XX(ha)) &&
973 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700974 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700975 if ((!ha->max_npiv_vports) ||
976 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800977 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700978 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800979 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700980 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700981
982 if (ql2xallocfwdump)
983 qla2x00_alloc_fw_dump(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 }
985 } else {
986 DEBUG2(printk(KERN_INFO
987 "scsi(%ld): ISP Firmware failed checksum.\n",
988 ha->host_no));
989 }
990 }
991
Andrew Vasquez3db06522008-01-31 12:33:49 -0800992 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
993 /* Enable proper parity. */
994 spin_lock_irqsave(&ha->hardware_lock, flags);
995 if (IS_QLA2300(ha))
996 /* SRAM parity */
997 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
998 else
999 /* SRAM, Instruction RAM and GP RAM parity */
1000 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1001 RD_REG_WORD(&reg->hccr);
1002 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1003 }
1004
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 if (rval) {
1006 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
1007 ha->host_no));
1008 }
1009
1010 return (rval);
1011}
1012
1013/**
1014 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1015 * @ha: HA context
1016 *
1017 * Beginning of request ring has initialization control block already built
1018 * by nvram config routine.
1019 *
1020 * Returns 0 on success.
1021 */
1022static void
1023qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
1024{
1025 uint16_t cnt;
1026 response_t *pkt;
1027
1028 pkt = ha->response_ring_ptr;
1029 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
1030 pkt->signature = RESPONSE_PROCESSED;
1031 pkt++;
1032 }
1033
1034}
1035
1036/**
1037 * qla2x00_update_fw_options() - Read and process firmware options.
1038 * @ha: HA context
1039 *
1040 * Returns 0 on success.
1041 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001042void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043qla2x00_update_fw_options(scsi_qla_host_t *ha)
1044{
1045 uint16_t swing, emphasis, tx_sens, rx_sens;
1046
1047 memset(ha->fw_options, 0, sizeof(ha->fw_options));
1048 qla2x00_get_fw_options(ha, ha->fw_options);
1049
1050 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1051 return;
1052
1053 /* Serial Link options. */
1054 DEBUG3(printk("scsi(%ld): Serial link options:\n",
1055 ha->host_no));
1056 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1057 sizeof(ha->fw_seriallink_options)));
1058
1059 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1060 if (ha->fw_seriallink_options[3] & BIT_2) {
1061 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1062
1063 /* 1G settings */
1064 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1065 emphasis = (ha->fw_seriallink_options[2] &
1066 (BIT_4 | BIT_3)) >> 3;
1067 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001068 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 rx_sens = (ha->fw_seriallink_options[0] &
1070 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1071 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1072 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1073 if (rx_sens == 0x0)
1074 rx_sens = 0x3;
1075 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1076 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1077 ha->fw_options[10] |= BIT_5 |
1078 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1079 (tx_sens & (BIT_1 | BIT_0));
1080
1081 /* 2G settings */
1082 swing = (ha->fw_seriallink_options[2] &
1083 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1084 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1085 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001086 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 rx_sens = (ha->fw_seriallink_options[1] &
1088 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1089 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1090 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1091 if (rx_sens == 0x0)
1092 rx_sens = 0x3;
1093 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1094 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1095 ha->fw_options[11] |= BIT_5 |
1096 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1097 (tx_sens & (BIT_1 | BIT_0));
1098 }
1099
1100 /* FCP2 options. */
1101 /* Return command IOCBs without waiting for an ABTS to complete. */
1102 ha->fw_options[3] |= BIT_13;
1103
1104 /* LED scheme. */
1105 if (ha->flags.enable_led_scheme)
1106 ha->fw_options[2] |= BIT_12;
1107
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001108 /* Detect ISP6312. */
1109 if (IS_QLA6312(ha))
1110 ha->fw_options[2] |= BIT_13;
1111
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 /* Update firmware options. */
1113 qla2x00_set_fw_options(ha, ha->fw_options);
1114}
1115
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001116void
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001117qla24xx_update_fw_options(scsi_qla_host_t *ha)
1118{
1119 int rval;
1120
1121 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001122 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001123 return;
1124
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001125 rval = qla2x00_set_serdes_params(ha,
1126 le16_to_cpu(ha->fw_seriallink_options24[1]),
1127 le16_to_cpu(ha->fw_seriallink_options24[2]),
1128 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001129 if (rval != QLA_SUCCESS) {
1130 qla_printk(KERN_WARNING, ha,
1131 "Unable to update Serial Link options (%x).\n", rval);
1132 }
1133}
1134
1135void
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001136qla2x00_config_rings(struct scsi_qla_host *ha)
1137{
Andrew Vasquez3d716442005-07-06 10:30:26 -07001138 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001139
1140 /* Setup ring parameters in initialization control block. */
1141 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1142 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1143 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1144 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1145 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1146 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1147 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1148 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1149
1150 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1151 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1152 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1153 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1154 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1155}
1156
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001157void
1158qla24xx_config_rings(struct scsi_qla_host *ha)
1159{
1160 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1161 struct init_cb_24xx *icb;
1162
1163 /* Setup ring parameters in initialization control block. */
1164 icb = (struct init_cb_24xx *)ha->init_cb;
1165 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1166 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1167 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1168 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1169 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1170 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1171 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1172 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1173
1174 WRT_REG_DWORD(&reg->req_q_in, 0);
1175 WRT_REG_DWORD(&reg->req_q_out, 0);
1176 WRT_REG_DWORD(&reg->rsp_q_in, 0);
1177 WRT_REG_DWORD(&reg->rsp_q_out, 0);
1178 RD_REG_DWORD(&reg->rsp_q_out);
1179}
1180
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181/**
1182 * qla2x00_init_rings() - Initializes firmware.
1183 * @ha: HA context
1184 *
1185 * Beginning of request ring has initialization control block already built
1186 * by nvram config routine.
1187 *
1188 * Returns 0 on success.
1189 */
1190static int
1191qla2x00_init_rings(scsi_qla_host_t *ha)
1192{
1193 int rval;
1194 unsigned long flags = 0;
1195 int cnt;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001196 struct mid_init_cb_24xx *mid_init_cb =
1197 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198
1199 spin_lock_irqsave(&ha->hardware_lock, flags);
1200
1201 /* Clear outstanding commands array. */
1202 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1203 ha->outstanding_cmds[cnt] = NULL;
1204
1205 ha->current_outstanding_cmd = 0;
1206
1207 /* Clear RSCN queue. */
1208 ha->rscn_in_ptr = 0;
1209 ha->rscn_out_ptr = 0;
1210
1211 /* Initialize firmware. */
1212 ha->request_ring_ptr = ha->request_ring;
1213 ha->req_ring_index = 0;
1214 ha->req_q_cnt = ha->request_q_length;
1215 ha->response_ring_ptr = ha->response_ring;
1216 ha->rsp_ring_index = 0;
1217
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 /* Initialize response queue entries */
1219 qla2x00_init_response_q_entries(ha);
1220
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001221 ha->isp_ops->config_rings(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222
1223 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1224
1225 /* Update any ISP specific firmware options before initialization. */
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001226 ha->isp_ops->update_fw_options(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227
1228 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001229
Seokmann Juc48339d2008-01-17 09:02:19 -08001230 if (ha->flags.npiv_supported)
1231 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
1232
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001233 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001234
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001235 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 if (rval) {
1237 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1238 ha->host_no));
1239 } else {
1240 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1241 ha->host_no));
1242 }
1243
1244 return (rval);
1245}
1246
1247/**
1248 * qla2x00_fw_ready() - Waits for firmware ready.
1249 * @ha: HA context
1250 *
1251 * Returns 0 on success.
1252 */
1253static int
1254qla2x00_fw_ready(scsi_qla_host_t *ha)
1255{
1256 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001257 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 uint16_t min_wait; /* Minimum wait time if loop is down */
1259 uint16_t wait_time; /* Wait time if loop is coming ready */
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001260 uint16_t state[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
1262 rval = QLA_SUCCESS;
1263
1264 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001265 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
1267 /*
1268 * Firmware should take at most one RATOV to login, plus 5 seconds for
1269 * our own processing.
1270 */
1271 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1272 wait_time = min_wait;
1273 }
1274
1275 /* Min wait time if loop down */
1276 mtime = jiffies + (min_wait * HZ);
1277
1278 /* wait time before firmware ready */
1279 wtime = jiffies + (wait_time * HZ);
1280
1281 /* Wait for ISP to finish LIP */
1282 if (!ha->flags.init_done)
1283 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1284
1285 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1286 ha->host_no));
1287
1288 do {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001289 rval = qla2x00_get_firmware_state(ha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001291 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 ha->device_flags &= ~DFLG_NO_CABLE;
1293 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001294 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1295 DEBUG16(printk("scsi(%ld): fw_state=%x "
1296 "84xx=%x.\n", ha->host_no, state[0],
1297 state[2]));
1298 if ((state[2] & FSTATE_LOGGED_IN) &&
1299 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1300 DEBUG16(printk("scsi(%ld): Sending "
1301 "verify iocb.\n", ha->host_no));
1302
1303 cs84xx_time = jiffies;
1304 rval = qla84xx_init_chip(ha);
1305 if (rval != QLA_SUCCESS)
1306 break;
1307
1308 /* Add time taken to initialize. */
1309 cs84xx_time = jiffies - cs84xx_time;
1310 wtime += cs84xx_time;
1311 mtime += cs84xx_time;
1312 DEBUG16(printk("scsi(%ld): Increasing "
1313 "wait time by %ld. New time %ld\n",
1314 ha->host_no, cs84xx_time, wtime));
1315 }
1316 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1318 ha->host_no));
1319
1320 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1321 &ha->login_timeout, &ha->r_a_tov);
1322
1323 rval = QLA_SUCCESS;
1324 break;
1325 }
1326
1327 rval = QLA_FUNCTION_FAILED;
1328
1329 if (atomic_read(&ha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001330 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001332 * other than Wait for Login.
1333 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 if (time_after_eq(jiffies, mtime)) {
1335 qla_printk(KERN_INFO, ha,
1336 "Cable is unplugged...\n");
1337
1338 ha->device_flags |= DFLG_NO_CABLE;
1339 break;
1340 }
1341 }
1342 } else {
1343 /* Mailbox cmd failed. Timeout on min_wait. */
1344 if (time_after_eq(jiffies, mtime))
1345 break;
1346 }
1347
1348 if (time_after_eq(jiffies, wtime))
1349 break;
1350
1351 /* Delay for a while */
1352 msleep(500);
1353
1354 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001355 ha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 } while (1);
1357
1358 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001359 ha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
1361 if (rval) {
1362 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1363 ha->host_no));
1364 }
1365
1366 return (rval);
1367}
1368
1369/*
1370* qla2x00_configure_hba
1371* Setup adapter context.
1372*
1373* Input:
1374* ha = adapter state pointer.
1375*
1376* Returns:
1377* 0 = success
1378*
1379* Context:
1380* Kernel context.
1381*/
1382static int
1383qla2x00_configure_hba(scsi_qla_host_t *ha)
1384{
1385 int rval;
1386 uint16_t loop_id;
1387 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001388 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 uint8_t al_pa;
1390 uint8_t area;
1391 uint8_t domain;
1392 char connect_type[22];
1393
1394 /* Get host addresses. */
1395 rval = qla2x00_get_adapter_id(ha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001396 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 if (rval != QLA_SUCCESS) {
Andrew Vasquez23443b12005-12-06 10:57:06 -08001398 if (LOOP_TRANSITION(ha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001399 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1400 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1401 __func__, ha->host_no));
1402 } else {
1403 qla_printk(KERN_WARNING, ha,
1404 "ERROR -- Unable to get host loop ID.\n");
1405 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1406 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 return (rval);
1408 }
1409
1410 if (topo == 4) {
1411 qla_printk(KERN_INFO, ha,
1412 "Cannot get topology - retrying.\n");
1413 return (QLA_FUNCTION_FAILED);
1414 }
1415
1416 ha->loop_id = loop_id;
1417
1418 /* initialize */
1419 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1420 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001421 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422
1423 switch (topo) {
1424 case 0:
1425 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1426 ha->host_no));
1427 ha->current_topology = ISP_CFG_NL;
1428 strcpy(connect_type, "(Loop)");
1429 break;
1430
1431 case 1:
1432 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1433 ha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001434 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 ha->current_topology = ISP_CFG_FL;
1436 strcpy(connect_type, "(FL_Port)");
1437 break;
1438
1439 case 2:
1440 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1441 ha->host_no));
1442 ha->operating_mode = P2P;
1443 ha->current_topology = ISP_CFG_N;
1444 strcpy(connect_type, "(N_Port-to-N_Port)");
1445 break;
1446
1447 case 3:
1448 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1449 ha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001450 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 ha->operating_mode = P2P;
1452 ha->current_topology = ISP_CFG_F;
1453 strcpy(connect_type, "(F_Port)");
1454 break;
1455
1456 default:
1457 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1458 "Using NL.\n",
1459 ha->host_no, topo));
1460 ha->current_topology = ISP_CFG_NL;
1461 strcpy(connect_type, "(Loop)");
1462 break;
1463 }
1464
1465 /* Save Host port and loop ID. */
1466 /* byte order - Big Endian */
1467 ha->d_id.b.domain = domain;
1468 ha->d_id.b.area = area;
1469 ha->d_id.b.al_pa = al_pa;
1470
1471 if (!ha->flags.init_done)
1472 qla_printk(KERN_INFO, ha,
1473 "Topology - %s, Host Loop address 0x%x\n",
1474 connect_type, ha->loop_id);
1475
1476 if (rval) {
1477 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1478 } else {
1479 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1480 }
1481
1482 return(rval);
1483}
1484
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001485static inline void
1486qla2x00_set_model_info(scsi_qla_host_t *ha, uint8_t *model, size_t len, char *def)
1487{
1488 char *st, *en;
1489 uint16_t index;
1490
1491 if (memcmp(model, BINZERO, len) != 0) {
1492 strncpy(ha->model_number, model, len);
1493 st = en = ha->model_number;
1494 en += len - 1;
1495 while (en > st) {
1496 if (*en != 0x20 && *en != 0x00)
1497 break;
1498 *en-- = '\0';
1499 }
1500
1501 index = (ha->pdev->subsystem_device & 0xff);
1502 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1503 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001504 strncpy(ha->model_desc,
1505 qla2x00_model_name[index * 2 + 1],
1506 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001507 } else {
1508 index = (ha->pdev->subsystem_device & 0xff);
1509 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1510 index < QLA_MODEL_NAMES) {
1511 strcpy(ha->model_number,
1512 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001513 strncpy(ha->model_desc,
1514 qla2x00_model_name[index * 2 + 1],
1515 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001516 } else {
1517 strcpy(ha->model_number, def);
1518 }
1519 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001520 if (IS_FWI2_CAPABLE(ha))
1521 qla2xxx_get_vpd_field(ha, "\x82", ha->model_desc,
1522 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001523}
1524
David Miller4e08df32007-04-16 12:37:43 -07001525/* On sparc systems, obtain port and node WWN from firmware
1526 * properties.
1527 */
1528static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, nvram_t *nv)
1529{
1530#ifdef CONFIG_SPARC
1531 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07001532 struct device_node *dp = pci_device_to_OF_node(pdev);
1533 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07001534 int len;
1535
1536 val = of_get_property(dp, "port-wwn", &len);
1537 if (val && len >= WWN_SIZE)
1538 memcpy(nv->port_name, val, WWN_SIZE);
1539
1540 val = of_get_property(dp, "node-wwn", &len);
1541 if (val && len >= WWN_SIZE)
1542 memcpy(nv->node_name, val, WWN_SIZE);
1543#endif
1544}
1545
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546/*
1547* NVRAM configuration for ISP 2xxx
1548*
1549* Input:
1550* ha = adapter block pointer.
1551*
1552* Output:
1553* initialization control block in response_ring
1554* host adapters parameters in host adapter block
1555*
1556* Returns:
1557* 0 = success.
1558*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001559int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560qla2x00_nvram_config(scsi_qla_host_t *ha)
1561{
David Miller4e08df32007-04-16 12:37:43 -07001562 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001563 uint8_t chksum = 0;
1564 uint16_t cnt;
1565 uint8_t *dptr1, *dptr2;
1566 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07001567 nvram_t *nv = ha->nvram;
1568 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001569 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570
David Miller4e08df32007-04-16 12:37:43 -07001571 rval = QLA_SUCCESS;
1572
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001574 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 ha->nvram_base = 0;
1576 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1577 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
1578 ha->nvram_base = 0x80;
1579
1580 /* Get NVRAM data and calculate checksum. */
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001581 ha->isp_ops->read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001582 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1583 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
1585 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07001586 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587
1588 /* Bad NVRAM data, set defaults parameters. */
1589 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1590 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1591 /* Reset NVRAM data. */
1592 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1593 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1594 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07001595 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1596 "invalid -- WWPN) defaults.\n");
1597
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001598 if (chksum)
1599 qla2xxx_hw_event_log(ha, HW_EVENT_NVRAM_CHKSUM_ERR, 0,
1600 MSW(chksum), LSW(chksum));
1601
David Miller4e08df32007-04-16 12:37:43 -07001602 /*
1603 * Set default initialization control block.
1604 */
1605 memset(nv, 0, ha->nvram_size);
1606 nv->parameter_block_version = ICB_VERSION;
1607
1608 if (IS_QLA23XX(ha)) {
1609 nv->firmware_options[0] = BIT_2 | BIT_1;
1610 nv->firmware_options[1] = BIT_7 | BIT_5;
1611 nv->add_firmware_options[0] = BIT_5;
1612 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1613 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1614 nv->special_options[1] = BIT_7;
1615 } else if (IS_QLA2200(ha)) {
1616 nv->firmware_options[0] = BIT_2 | BIT_1;
1617 nv->firmware_options[1] = BIT_7 | BIT_5;
1618 nv->add_firmware_options[0] = BIT_5;
1619 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1620 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1621 } else if (IS_QLA2100(ha)) {
1622 nv->firmware_options[0] = BIT_3 | BIT_1;
1623 nv->firmware_options[1] = BIT_5;
1624 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1625 }
1626
1627 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1628 nv->execution_throttle = __constant_cpu_to_le16(16);
1629 nv->retry_count = 8;
1630 nv->retry_delay = 1;
1631
1632 nv->port_name[0] = 33;
1633 nv->port_name[3] = 224;
1634 nv->port_name[4] = 139;
1635
1636 qla2xxx_nvram_wwn_from_ofw(ha, nv);
1637
1638 nv->login_timeout = 4;
1639
1640 /*
1641 * Set default host adapter parameters
1642 */
1643 nv->host_p[1] = BIT_2;
1644 nv->reset_delay = 5;
1645 nv->port_down_retry_count = 8;
1646 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1647 nv->link_down_timeout = 60;
1648
1649 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 }
1651
1652#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1653 /*
1654 * The SN2 does not provide BIOS emulation which means you can't change
1655 * potentially bogus BIOS settings. Force the use of default settings
1656 * for link rate and frame size. Hope that the rest of the settings
1657 * are valid.
1658 */
1659 if (ia64_platform_is("sn2")) {
1660 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1661 if (IS_QLA23XX(ha))
1662 nv->special_options[1] = BIT_7;
1663 }
1664#endif
1665
1666 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001667 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668
1669 /*
1670 * Setup driver NVRAM options.
1671 */
1672 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1673 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1674 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1675 nv->firmware_options[1] &= ~BIT_4;
1676
1677 if (IS_QLA23XX(ha)) {
1678 nv->firmware_options[0] |= BIT_2;
1679 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001680 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681
1682 if (IS_QLA2300(ha)) {
1683 if (ha->fb_rev == FPM_2310) {
1684 strcpy(ha->model_number, "QLA2310");
1685 } else {
1686 strcpy(ha->model_number, "QLA2300");
1687 }
1688 } else {
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001689 qla2x00_set_model_info(ha, nv->model_number,
1690 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 }
1692 } else if (IS_QLA2200(ha)) {
1693 nv->firmware_options[0] |= BIT_2;
1694 /*
1695 * 'Point-to-point preferred, else loop' is not a safe
1696 * connection mode setting.
1697 */
1698 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1699 (BIT_5 | BIT_4)) {
1700 /* Force 'loop preferred, else point-to-point'. */
1701 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1702 nv->add_firmware_options[0] |= BIT_5;
1703 }
1704 strcpy(ha->model_number, "QLA22xx");
1705 } else /*if (IS_QLA2100(ha))*/ {
1706 strcpy(ha->model_number, "QLA2100");
1707 }
1708
1709 /*
1710 * Copy over NVRAM RISC parameter block to initialization control block.
1711 */
1712 dptr1 = (uint8_t *)icb;
1713 dptr2 = (uint8_t *)&nv->parameter_block_version;
1714 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1715 while (cnt--)
1716 *dptr1++ = *dptr2++;
1717
1718 /* Copy 2nd half. */
1719 dptr1 = (uint8_t *)icb->add_firmware_options;
1720 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1721 while (cnt--)
1722 *dptr1++ = *dptr2++;
1723
Andrew Vasquez5341e862006-05-17 15:09:16 -07001724 /* Use alternate WWN? */
1725 if (nv->host_p[1] & BIT_7) {
1726 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1727 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1728 }
1729
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 /* Prepare nodename */
1731 if ((icb->firmware_options[1] & BIT_6) == 0) {
1732 /*
1733 * Firmware will apply the following mask if the nodename was
1734 * not provided.
1735 */
1736 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1737 icb->node_name[0] &= 0xF0;
1738 }
1739
1740 /*
1741 * Set host adapter parameters.
1742 */
Andrew Vasquez01819442006-06-23 16:11:10 -07001743 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07001744 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1746 /* Always load RISC code on non ISP2[12]00 chips. */
1747 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1748 ha->flags.disable_risc_code_load = 0;
1749 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1750 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1751 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07001752 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001753 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754
1755 ha->operating_mode =
1756 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1757
1758 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1759 sizeof(ha->fw_seriallink_options));
1760
1761 /* save HBA serial number */
1762 ha->serial0 = icb->port_name[5];
1763 ha->serial1 = icb->port_name[6];
1764 ha->serial2 = icb->port_name[7];
Andrew Vasquez3d716442005-07-06 10:30:26 -07001765 ha->node_name = icb->node_name;
1766 ha->port_name = icb->port_name;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767
1768 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1769
1770 ha->retry_count = nv->retry_count;
1771
1772 /* Set minimum login_timeout to 4 seconds. */
1773 if (nv->login_timeout < ql2xlogintimeout)
1774 nv->login_timeout = ql2xlogintimeout;
1775 if (nv->login_timeout < 4)
1776 nv->login_timeout = 4;
1777 ha->login_timeout = nv->login_timeout;
1778 icb->login_timeout = nv->login_timeout;
1779
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001780 /* Set minimum RATOV to 100 tenths of a second. */
1781 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 ha->loop_reset_delay = nv->reset_delay;
1784
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 /* Link Down Timeout = 0:
1786 *
1787 * When Port Down timer expires we will start returning
1788 * I/O's to OS with "DID_NO_CONNECT".
1789 *
1790 * Link Down Timeout != 0:
1791 *
1792 * The driver waits for the link to come up after link down
1793 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001794 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 if (nv->link_down_timeout == 0) {
1796 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001797 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 } else {
1799 ha->link_down_timeout = nv->link_down_timeout;
1800 ha->loop_down_abort_time =
1801 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001802 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 /*
1805 * Need enough time to try and get the port back.
1806 */
1807 ha->port_down_retry_count = nv->port_down_retry_count;
1808 if (qlport_down_retry)
1809 ha->port_down_retry_count = qlport_down_retry;
1810 /* Set login_retry_count */
1811 ha->login_retry_count = nv->retry_count;
1812 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1813 ha->port_down_retry_count > 3)
1814 ha->login_retry_count = ha->port_down_retry_count;
1815 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1816 ha->login_retry_count = ha->port_down_retry_count;
1817 if (ql2xloginretrycount)
1818 ha->login_retry_count = ql2xloginretrycount;
1819
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 icb->lun_enables = __constant_cpu_to_le16(0);
1821 icb->command_resource_count = 0;
1822 icb->immediate_notify_resource_count = 0;
1823 icb->timeout = __constant_cpu_to_le16(0);
1824
1825 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1826 /* Enable RIO */
1827 icb->firmware_options[0] &= ~BIT_3;
1828 icb->add_firmware_options[0] &=
1829 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1830 icb->add_firmware_options[0] |= BIT_2;
1831 icb->response_accumulation_timer = 3;
1832 icb->interrupt_delay_timer = 5;
1833
1834 ha->flags.process_response_queue = 1;
1835 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001836 /* Enable ZIO. */
1837 if (!ha->flags.init_done) {
1838 ha->zio_mode = icb->add_firmware_options[0] &
1839 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1840 ha->zio_timer = icb->interrupt_delay_timer ?
1841 icb->interrupt_delay_timer: 2;
1842 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 icb->add_firmware_options[0] &=
1844 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001845 ha->flags.process_response_queue = 0;
1846 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001847 ha->zio_mode = QLA_ZIO_MODE_6;
1848
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001849 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1850 "delay (%d us).\n", ha->host_no, ha->zio_mode,
1851 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001853 "ZIO mode %d enabled; timer delay (%d us).\n",
1854 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001856 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1857 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 ha->flags.process_response_queue = 1;
1859 }
1860 }
1861
David Miller4e08df32007-04-16 12:37:43 -07001862 if (rval) {
1863 DEBUG2_3(printk(KERN_WARNING
1864 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1865 }
1866 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867}
1868
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001869static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001870qla2x00_rport_del(void *data)
1871{
1872 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001873 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001874
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001875 spin_lock_irq(fcport->ha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001876 rport = fcport->drport;
1877 fcport->drport = NULL;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001878 spin_unlock_irq(fcport->ha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001879 if (rport)
1880 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001881}
1882
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883/**
1884 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1885 * @ha: HA context
1886 * @flags: allocation flags
1887 *
1888 * Returns a pointer to the allocated fcport, or NULL, if none available.
1889 */
Adrian Bunk413975a2006-06-30 02:33:06 -07001890static fc_port_t *
Al Viroc53033f2005-10-21 03:22:08 -04001891qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892{
1893 fc_port_t *fcport;
1894
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001895 fcport = kzalloc(sizeof(fc_port_t), flags);
1896 if (!fcport)
1897 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898
1899 /* Setup fcport template structure. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 fcport->ha = ha;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001901 fcport->vp_idx = ha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 fcport->port_type = FCT_UNKNOWN;
1903 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1905 fcport->flags = FCF_RLC_SUPPORT;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001906 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001908 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909}
1910
1911/*
1912 * qla2x00_configure_loop
1913 * Updates Fibre Channel Device Database with what is actually on loop.
1914 *
1915 * Input:
1916 * ha = adapter block pointer.
1917 *
1918 * Returns:
1919 * 0 = success.
1920 * 1 = error.
1921 * 2 = database was full and device was not configured.
1922 */
1923static int
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001924qla2x00_configure_loop(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925{
1926 int rval;
1927 unsigned long flags, save_flags;
1928
1929 rval = QLA_SUCCESS;
1930
1931 /* Get Initiator ID */
1932 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1933 rval = qla2x00_configure_hba(ha);
1934 if (rval != QLA_SUCCESS) {
1935 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1936 ha->host_no));
1937 return (rval);
1938 }
1939 }
1940
1941 save_flags = flags = ha->dpc_flags;
1942 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1943 ha->host_no, flags));
1944
1945 /*
1946 * If we have both an RSCN and PORT UPDATE pending then handle them
1947 * both at the same time.
1948 */
1949 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1950 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951
1952 /* Determine what we need to do */
1953 if (ha->current_topology == ISP_CFG_FL &&
1954 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1955
1956 ha->flags.rscn_queue_overflow = 1;
1957 set_bit(RSCN_UPDATE, &flags);
1958
1959 } else if (ha->current_topology == ISP_CFG_F &&
1960 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1961
1962 ha->flags.rscn_queue_overflow = 1;
1963 set_bit(RSCN_UPDATE, &flags);
1964 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1965
Andrew Vasquez21333b42006-05-17 15:09:56 -07001966 } else if (ha->current_topology == ISP_CFG_N) {
1967 clear_bit(RSCN_UPDATE, &flags);
1968
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 } else if (!ha->flags.online ||
1970 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1971
1972 ha->flags.rscn_queue_overflow = 1;
1973 set_bit(RSCN_UPDATE, &flags);
1974 set_bit(LOCAL_LOOP_UPDATE, &flags);
1975 }
1976
1977 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1978 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1979 rval = QLA_FUNCTION_FAILED;
1980 } else {
1981 rval = qla2x00_configure_local_loop(ha);
1982 }
1983 }
1984
1985 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Andrew Vasquez23443b12005-12-06 10:57:06 -08001986 if (LOOP_TRANSITION(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 rval = QLA_FUNCTION_FAILED;
1988 } else {
1989 rval = qla2x00_configure_fabric(ha);
1990 }
1991 }
1992
1993 if (rval == QLA_SUCCESS) {
1994 if (atomic_read(&ha->loop_down_timer) ||
1995 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1996 rval = QLA_FUNCTION_FAILED;
1997 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 atomic_set(&ha->loop_state, LOOP_READY);
1999
2000 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
2001 }
2002 }
2003
2004 if (rval) {
2005 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
2006 __func__, ha->host_no));
2007 } else {
2008 DEBUG3(printk("%s: exiting normally\n", __func__));
2009 }
2010
2011 /* Restore state if a resync event occured during processing */
2012 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
2013 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
2014 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
Seokmann Ju5de1f702008-07-10 16:55:58 -07002015 if (test_bit(RSCN_UPDATE, &save_flags)) {
2016 ha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 set_bit(RSCN_UPDATE, &ha->dpc_flags);
Seokmann Ju5de1f702008-07-10 16:55:58 -07002018 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 }
2020
2021 return (rval);
2022}
2023
2024
2025
2026/*
2027 * qla2x00_configure_local_loop
2028 * Updates Fibre Channel Device Database with local loop devices.
2029 *
2030 * Input:
2031 * ha = adapter block pointer.
2032 *
2033 * Returns:
2034 * 0 = success.
2035 */
2036static int
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002037qla2x00_configure_local_loop(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038{
2039 int rval, rval2;
2040 int found_devs;
2041 int found;
2042 fc_port_t *fcport, *new_fcport;
2043
2044 uint16_t index;
2045 uint16_t entries;
2046 char *id_iter;
2047 uint16_t loop_id;
2048 uint8_t domain, area, al_pa;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002049 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050
2051 found_devs = 0;
2052 new_fcport = NULL;
2053 entries = MAX_FIBRE_DEVICES;
2054
2055 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
2056 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
2057
2058 /* Get list of logged in devices. */
2059 memset(ha->gid_list, 0, GID_LIST_SIZE);
2060 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
2061 &entries);
2062 if (rval != QLA_SUCCESS)
2063 goto cleanup_allocation;
2064
2065 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2066 ha->host_no, entries));
2067 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2068 entries * sizeof(struct gid_list_info)));
2069
2070 /* Allocate temporary fcport for any new fcports discovered. */
2071 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2072 if (new_fcport == NULL) {
2073 rval = QLA_MEMORY_ALLOC_FAILED;
2074 goto cleanup_allocation;
2075 }
2076 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2077
2078 /*
2079 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2080 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002081 list_for_each_entry(fcport, &pha->fcports, list) {
2082 if (fcport->vp_idx != ha->vp_idx)
2083 continue;
2084
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2086 fcport->port_type != FCT_BROADCAST &&
2087 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2088
2089 DEBUG(printk("scsi(%ld): Marking port lost, "
2090 "loop_id=0x%04x\n",
2091 ha->host_no, fcport->loop_id));
2092
2093 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2094 fcport->flags &= ~FCF_FARP_DONE;
2095 }
2096 }
2097
2098 /* Add devices to port list. */
2099 id_iter = (char *)ha->gid_list;
2100 for (index = 0; index < entries; index++) {
2101 domain = ((struct gid_list_info *)id_iter)->domain;
2102 area = ((struct gid_list_info *)id_iter)->area;
2103 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002104 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 loop_id = (uint16_t)
2106 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002107 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 loop_id = le16_to_cpu(
2109 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002110 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111
2112 /* Bypass reserved domain fields. */
2113 if ((domain & 0xf0) == 0xf0)
2114 continue;
2115
2116 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002117 if (area && domain &&
2118 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 continue;
2120
2121 /* Bypass invalid local loop ID. */
2122 if (loop_id > LAST_LOCAL_LOOP_ID)
2123 continue;
2124
2125 /* Fill in member data. */
2126 new_fcport->d_id.b.domain = domain;
2127 new_fcport->d_id.b.area = area;
2128 new_fcport->d_id.b.al_pa = al_pa;
2129 new_fcport->loop_id = loop_id;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002130 new_fcport->vp_idx = ha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
2132 if (rval2 != QLA_SUCCESS) {
2133 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2134 "information -- get_port_database=%x, "
2135 "loop_id=0x%04x\n",
2136 ha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002137 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2138 ha->host_no));
2139 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 continue;
2141 }
2142
2143 /* Check for matching device in port list. */
2144 found = 0;
2145 fcport = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002146 list_for_each_entry(fcport, &pha->fcports, list) {
2147 if (fcport->vp_idx != ha->vp_idx)
2148 continue;
2149
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 if (memcmp(new_fcport->port_name, fcport->port_name,
2151 WWN_SIZE))
2152 continue;
2153
2154 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2155 FCF_PERSISTENT_BOUND);
2156 fcport->loop_id = new_fcport->loop_id;
2157 fcport->port_type = new_fcport->port_type;
2158 fcport->d_id.b24 = new_fcport->d_id.b24;
2159 memcpy(fcport->node_name, new_fcport->node_name,
2160 WWN_SIZE);
2161
2162 found++;
2163 break;
2164 }
2165
2166 if (!found) {
2167 /* New device, add to fcports list. */
2168 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002169 if (ha->parent) {
2170 new_fcport->ha = ha;
2171 new_fcport->vp_idx = ha->vp_idx;
2172 list_add_tail(&new_fcport->vp_fcport,
2173 &ha->vp_fcports);
2174 }
2175 list_add_tail(&new_fcport->list, &pha->fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176
2177 /* Allocate a new replacement fcport. */
2178 fcport = new_fcport;
2179 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2180 if (new_fcport == NULL) {
2181 rval = QLA_MEMORY_ALLOC_FAILED;
2182 goto cleanup_allocation;
2183 }
2184 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2185 }
2186
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002187 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002188 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002189
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 qla2x00_update_fcport(ha, fcport);
2191
2192 found_devs++;
2193 }
2194
2195cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002196 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197
2198 if (rval != QLA_SUCCESS) {
2199 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2200 "rval=%x\n", ha->host_no, rval));
2201 }
2202
2203 if (found_devs) {
2204 ha->device_flags |= DFLG_LOCAL_DEVICES;
2205 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
2206 }
2207
2208 return (rval);
2209}
2210
2211static void
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002212qla2x00_iidma_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2213{
2214#define LS_UNKNOWN 2
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002215 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002216 int rval;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002217 uint16_t mb[6];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002218
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002219 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002220 return;
2221
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002222 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2223 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002224 return;
2225
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002226 rval = qla2x00_set_idma_speed(ha, fcport->loop_id, fcport->fp_speed,
2227 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002228 if (rval != QLA_SUCCESS) {
2229 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2230 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2231 ha->host_no, fcport->port_name[0], fcport->port_name[1],
2232 fcport->port_name[2], fcport->port_name[3],
2233 fcport->port_name[4], fcport->port_name[5],
2234 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002235 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002236 } else {
2237 DEBUG2(qla_printk(KERN_INFO, ha,
2238 "iIDMA adjusted to %s GB/s on "
2239 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002240 link_speeds[fcport->fp_speed], fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002241 fcport->port_name[1], fcport->port_name[2],
2242 fcport->port_name[3], fcport->port_name[4],
2243 fcport->port_name[5], fcport->port_name[6],
2244 fcport->port_name[7]));
2245 }
2246}
2247
Adrian Bunk23be3312006-11-24 02:46:01 +01002248static void
8482e1182005-04-17 15:04:54 -05002249qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2250{
2251 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002252 struct fc_rport *rport;
8482e1182005-04-17 15:04:54 -05002253
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002254 if (fcport->drport)
2255 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002256
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002257 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2258 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002259 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2260 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2261 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07002262 fcport->rport = rport = fc_remote_port_add(ha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002263 if (!rport) {
2264 qla_printk(KERN_WARNING, ha,
2265 "Unable to allocate fc remote port!\n");
2266 return;
2267 }
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07002268 spin_lock_irq(fcport->ha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002269 *((fc_port_t **)rport->dd_data) = fcport;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07002270 spin_unlock_irq(fcport->ha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002271
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002272 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002273
2274 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002275 if (fcport->port_type == FCT_INITIATOR)
2276 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2277 if (fcport->port_type == FCT_TARGET)
2278 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002279 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002280}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281
2282/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002283 * qla2x00_update_fcport
2284 * Updates device on list.
2285 *
2286 * Input:
2287 * ha = adapter block pointer.
2288 * fcport = port structure pointer.
2289 *
2290 * Return:
2291 * 0 - Success
2292 * BIT_0 - error
2293 *
2294 * Context:
2295 * Kernel context.
2296 */
2297void
2298qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2299{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002300 scsi_qla_host_t *pha = to_qla_parent(ha);
2301
Adrian Bunk23be3312006-11-24 02:46:01 +01002302 fcport->ha = ha;
2303 fcport->login_retry = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002304 fcport->port_login_retry_count = pha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002305 PORT_RETRY_TIME;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002306 atomic_set(&fcport->port_down_timer, pha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002307 PORT_RETRY_TIME);
2308 fcport->flags &= ~FCF_LOGIN_NEEDED;
2309
2310 qla2x00_iidma_fcport(ha, fcport);
2311
2312 atomic_set(&fcport->state, FCS_ONLINE);
2313
2314 qla2x00_reg_remote_port(ha, fcport);
2315}
2316
2317/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 * qla2x00_configure_fabric
2319 * Setup SNS devices with loop ID's.
2320 *
2321 * Input:
2322 * ha = adapter block pointer.
2323 *
2324 * Returns:
2325 * 0 = success.
2326 * BIT_0 = error
2327 */
2328static int
2329qla2x00_configure_fabric(scsi_qla_host_t *ha)
2330{
2331 int rval, rval2;
2332 fc_port_t *fcport, *fcptemp;
2333 uint16_t next_loopid;
2334 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002335 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 LIST_HEAD(new_fcports);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002337 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338
2339 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002340 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002341 loop_id = NPH_F_PORT;
2342 else
2343 loop_id = SNS_FL_PORT;
Andrew Vasquez90991c82006-10-02 12:00:46 -07002344 rval = qla2x00_get_port_name(ha, loop_id, ha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 if (rval != QLA_SUCCESS) {
2346 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2347 "Port\n", ha->host_no));
2348
2349 ha->device_flags &= ~SWITCH_FOUND;
2350 return (QLA_SUCCESS);
2351 }
Andrew Vasquez90991c82006-10-02 12:00:46 -07002352 ha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353
2354 /* Mark devices that need re-synchronization. */
2355 rval2 = qla2x00_device_resync(ha);
2356 if (rval2 == QLA_RSCNS_HANDLED) {
2357 /* No point doing the scan, just continue. */
2358 return (QLA_SUCCESS);
2359 }
2360 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002361 /* FDMI support. */
2362 if (ql2xfdmienable &&
2363 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2364 qla2x00_fdmi_register(ha);
2365
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002367 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002368 loop_id = NPH_SNS;
2369 else
2370 loop_id = SIMPLE_NAME_SERVER;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002371 ha->isp_ops->fabric_login(ha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002372 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 if (mb[0] != MBS_COMMAND_COMPLETE) {
2374 DEBUG2(qla_printk(KERN_INFO, ha,
2375 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002376 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 mb[0], mb[1], mb[2], mb[6], mb[7]));
2378 return (QLA_SUCCESS);
2379 }
2380
2381 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2382 if (qla2x00_rft_id(ha)) {
2383 /* EMPTY */
2384 DEBUG2(printk("scsi(%ld): Register FC-4 "
2385 "TYPE failed.\n", ha->host_no));
2386 }
2387 if (qla2x00_rff_id(ha)) {
2388 /* EMPTY */
2389 DEBUG2(printk("scsi(%ld): Register FC-4 "
2390 "Features failed.\n", ha->host_no));
2391 }
2392 if (qla2x00_rnn_id(ha)) {
2393 /* EMPTY */
2394 DEBUG2(printk("scsi(%ld): Register Node Name "
2395 "failed.\n", ha->host_no));
2396 } else if (qla2x00_rsnn_nn(ha)) {
2397 /* EMPTY */
2398 DEBUG2(printk("scsi(%ld): Register Symbolic "
2399 "Node Name failed.\n", ha->host_no));
2400 }
2401 }
2402
2403 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2404 if (rval != QLA_SUCCESS)
2405 break;
2406
2407 /*
2408 * Logout all previous fabric devices marked lost, except
2409 * tape devices.
2410 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002411 list_for_each_entry(fcport, &pha->fcports, list) {
2412 if (fcport->vp_idx !=ha->vp_idx)
2413 continue;
2414
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2416 break;
2417
2418 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2419 continue;
2420
2421 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2422 qla2x00_mark_device_lost(ha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002423 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 if (fcport->loop_id != FC_NO_LOOP_ID &&
2425 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2426 fcport->port_type != FCT_INITIATOR &&
2427 fcport->port_type != FCT_BROADCAST) {
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002428 ha->isp_ops->fabric_logout(ha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002429 fcport->loop_id,
2430 fcport->d_id.b.domain,
2431 fcport->d_id.b.area,
2432 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 fcport->loop_id = FC_NO_LOOP_ID;
2434 }
2435 }
2436 }
2437
2438 /* Starting free loop ID. */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002439 next_loopid = pha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440
2441 /*
2442 * Scan through our port list and login entries that need to be
2443 * logged in.
2444 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002445 list_for_each_entry(fcport, &pha->fcports, list) {
2446 if (fcport->vp_idx != ha->vp_idx)
2447 continue;
2448
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 if (atomic_read(&ha->loop_down_timer) ||
2450 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2451 break;
2452
2453 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2454 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2455 continue;
2456
2457 if (fcport->loop_id == FC_NO_LOOP_ID) {
2458 fcport->loop_id = next_loopid;
Seokmann Jud4486fd62008-04-03 13:13:28 -07002459 rval = qla2x00_find_new_loop_id(
2460 to_qla_parent(ha), fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 if (rval != QLA_SUCCESS) {
2462 /* Ran out of IDs to use */
2463 break;
2464 }
2465 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 /* Login and update database */
2467 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2468 }
2469
2470 /* Exit if out of loop IDs. */
2471 if (rval != QLA_SUCCESS) {
2472 break;
2473 }
2474
2475 /*
2476 * Login and add the new devices to our port list.
2477 */
2478 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2479 if (atomic_read(&ha->loop_down_timer) ||
2480 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2481 break;
2482
2483 /* Find a new loop ID to use. */
2484 fcport->loop_id = next_loopid;
Seokmann Jud4486fd62008-04-03 13:13:28 -07002485 rval = qla2x00_find_new_loop_id(to_qla_parent(ha),
2486 fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 if (rval != QLA_SUCCESS) {
2488 /* Ran out of IDs to use */
2489 break;
2490 }
2491
bdf79622005-04-17 15:06:53 -05002492 /* Login and update database */
2493 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002494
2495 if (ha->parent) {
2496 fcport->ha = ha;
2497 fcport->vp_idx = ha->vp_idx;
2498 list_add_tail(&fcport->vp_fcport,
2499 &ha->vp_fcports);
2500 list_move_tail(&fcport->list,
2501 &ha->parent->fcports);
2502 } else
2503 list_move_tail(&fcport->list, &ha->fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 }
2505 } while (0);
2506
2507 /* Free all new device structures not processed. */
2508 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2509 list_del(&fcport->list);
2510 kfree(fcport);
2511 }
2512
2513 if (rval) {
2514 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2515 "rval=%d\n", ha->host_no, rval));
2516 }
2517
2518 return (rval);
2519}
2520
2521
2522/*
2523 * qla2x00_find_all_fabric_devs
2524 *
2525 * Input:
2526 * ha = adapter block pointer.
2527 * dev = database device entry pointer.
2528 *
2529 * Returns:
2530 * 0 = success.
2531 *
2532 * Context:
2533 * Kernel context.
2534 */
2535static int
2536qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2537{
2538 int rval;
2539 uint16_t loop_id;
2540 fc_port_t *fcport, *new_fcport, *fcptemp;
2541 int found;
2542
2543 sw_info_t *swl;
2544 int swl_idx;
2545 int first_dev, last_dev;
2546 port_id_t wrap, nxt_d_id;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002547 int vp_index;
2548 int empty_vp_index;
2549 int found_vp;
2550 scsi_qla_host_t *vha;
2551 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552
2553 rval = QLA_SUCCESS;
2554
2555 /* Try GID_PT to get device list, else GAN. */
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002556 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_ATOMIC);
2557 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 /*EMPTY*/
2559 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2560 "on GA_NXT\n", ha->host_no));
2561 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2563 kfree(swl);
2564 swl = NULL;
2565 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2566 kfree(swl);
2567 swl = NULL;
2568 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2569 kfree(swl);
2570 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07002571 } else if (ql2xiidmaenable &&
2572 qla2x00_gfpn_id(ha, swl) == QLA_SUCCESS) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002573 qla2x00_gpsc(ha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 }
2575 }
2576 swl_idx = 0;
2577
2578 /* Allocate temporary fcport for any new fcports discovered. */
2579 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2580 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002581 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 return (QLA_MEMORY_ALLOC_FAILED);
2583 }
2584 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002585 new_fcport->vp_idx = ha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 /* Set start port ID scan at adapter ID. */
2587 first_dev = 1;
2588 last_dev = 0;
2589
2590 /* Starting free loop ID. */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002591 loop_id = pha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 for (; loop_id <= ha->last_loop_id; loop_id++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -07002593 if (qla2x00_is_reserved_id(ha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 continue;
2595
Andrew Vasquez23443b12005-12-06 10:57:06 -08002596 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 break;
2598
2599 if (swl != NULL) {
2600 if (last_dev) {
2601 wrap.b24 = new_fcport->d_id.b24;
2602 } else {
2603 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2604 memcpy(new_fcport->node_name,
2605 swl[swl_idx].node_name, WWN_SIZE);
2606 memcpy(new_fcport->port_name,
2607 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002608 memcpy(new_fcport->fabric_port_name,
2609 swl[swl_idx].fabric_port_name, WWN_SIZE);
2610 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611
2612 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2613 last_dev = 1;
2614 }
2615 swl_idx++;
2616 }
2617 } else {
2618 /* Send GA_NXT to the switch */
2619 rval = qla2x00_ga_nxt(ha, new_fcport);
2620 if (rval != QLA_SUCCESS) {
2621 qla_printk(KERN_WARNING, ha,
2622 "SNS scan failed -- assuming zero-entry "
2623 "result...\n");
2624 list_for_each_entry_safe(fcport, fcptemp,
2625 new_fcports, list) {
2626 list_del(&fcport->list);
2627 kfree(fcport);
2628 }
2629 rval = QLA_SUCCESS;
2630 break;
2631 }
2632 }
2633
2634 /* If wrap on switch device list, exit. */
2635 if (first_dev) {
2636 wrap.b24 = new_fcport->d_id.b24;
2637 first_dev = 0;
2638 } else if (new_fcport->d_id.b24 == wrap.b24) {
2639 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2640 ha->host_no, new_fcport->d_id.b.domain,
2641 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2642 break;
2643 }
2644
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002645 /* Bypass if same physical adapter. */
2646 if (new_fcport->d_id.b24 == pha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 continue;
2648
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002649 /* Bypass virtual ports of the same host. */
2650 if (pha->num_vhosts) {
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08002651 for_each_mapped_vp_idx(pha, vp_index) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002652 empty_vp_index = 1;
2653 found_vp = 0;
2654 list_for_each_entry(vha, &pha->vp_list,
2655 vp_list) {
2656 if (vp_index == vha->vp_idx) {
2657 empty_vp_index = 0;
2658 found_vp = 1;
2659 break;
2660 }
2661 }
2662
2663 if (empty_vp_index)
2664 continue;
2665
2666 if (found_vp &&
2667 new_fcport->d_id.b24 == vha->d_id.b24)
2668 break;
2669 }
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08002670
2671 if (vp_index <= pha->max_npiv_vports)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002672 continue;
2673 }
2674
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002675 /* Bypass if same domain and area of adapter. */
2676 if (((new_fcport->d_id.b24 & 0xffff00) ==
2677 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2678 ISP_CFG_FL)
2679 continue;
2680
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 /* Bypass reserved domain fields. */
2682 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2683 continue;
2684
2685 /* Locate matching device in database. */
2686 found = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002687 list_for_each_entry(fcport, &pha->fcports, list) {
2688 if (new_fcport->vp_idx != fcport->vp_idx)
2689 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 if (memcmp(new_fcport->port_name, fcport->port_name,
2691 WWN_SIZE))
2692 continue;
2693
2694 found++;
2695
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002696 /* Update port state. */
2697 memcpy(fcport->fabric_port_name,
2698 new_fcport->fabric_port_name, WWN_SIZE);
2699 fcport->fp_speed = new_fcport->fp_speed;
2700
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 /*
2702 * If address the same and state FCS_ONLINE, nothing
2703 * changed.
2704 */
2705 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2706 atomic_read(&fcport->state) == FCS_ONLINE) {
2707 break;
2708 }
2709
2710 /*
2711 * If device was not a fabric device before.
2712 */
2713 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2714 fcport->d_id.b24 = new_fcport->d_id.b24;
2715 fcport->loop_id = FC_NO_LOOP_ID;
2716 fcport->flags |= (FCF_FABRIC_DEVICE |
2717 FCF_LOGIN_NEEDED);
2718 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2719 break;
2720 }
2721
2722 /*
2723 * Port ID changed or device was marked to be updated;
2724 * Log it out if still logged in and mark it for
2725 * relogin later.
2726 */
2727 fcport->d_id.b24 = new_fcport->d_id.b24;
2728 fcport->flags |= FCF_LOGIN_NEEDED;
2729 if (fcport->loop_id != FC_NO_LOOP_ID &&
2730 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2731 fcport->port_type != FCT_INITIATOR &&
2732 fcport->port_type != FCT_BROADCAST) {
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002733 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002734 fcport->d_id.b.domain, fcport->d_id.b.area,
2735 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 fcport->loop_id = FC_NO_LOOP_ID;
2737 }
2738
2739 break;
2740 }
2741
2742 if (found)
2743 continue;
2744
2745 /* If device was not in our fcports list, then add it. */
2746 list_add_tail(&new_fcport->list, new_fcports);
2747
2748 /* Allocate a new replacement fcport. */
2749 nxt_d_id.b24 = new_fcport->d_id.b24;
2750 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2751 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002752 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 return (QLA_MEMORY_ALLOC_FAILED);
2754 }
2755 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2756 new_fcport->d_id.b24 = nxt_d_id.b24;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002757 new_fcport->vp_idx = ha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758 }
2759
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002760 kfree(swl);
2761 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762
2763 if (!list_empty(new_fcports))
2764 ha->device_flags |= DFLG_FABRIC_DEVICES;
2765
2766 return (rval);
2767}
2768
2769/*
2770 * qla2x00_find_new_loop_id
2771 * Scan through our port list and find a new usable loop ID.
2772 *
2773 * Input:
2774 * ha: adapter state pointer.
2775 * dev: port structure pointer.
2776 *
2777 * Returns:
2778 * qla2x00 local function return status code.
2779 *
2780 * Context:
2781 * Kernel context.
2782 */
Adrian Bunk413975a2006-06-30 02:33:06 -07002783static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2785{
2786 int rval;
2787 int found;
2788 fc_port_t *fcport;
2789 uint16_t first_loop_id;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002790 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791
2792 rval = QLA_SUCCESS;
2793
2794 /* Save starting loop ID. */
2795 first_loop_id = dev->loop_id;
2796
2797 for (;;) {
2798 /* Skip loop ID if already used by adapter. */
2799 if (dev->loop_id == ha->loop_id) {
2800 dev->loop_id++;
2801 }
2802
2803 /* Skip reserved loop IDs. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07002804 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 dev->loop_id++;
2806 }
2807
2808 /* Reset loop ID if passed the end. */
2809 if (dev->loop_id > ha->last_loop_id) {
2810 /* first loop ID. */
2811 dev->loop_id = ha->min_external_loopid;
2812 }
2813
2814 /* Check for loop ID being already in use. */
2815 found = 0;
2816 fcport = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002817 list_for_each_entry(fcport, &pha->fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2819 /* ID possibly in use */
2820 found++;
2821 break;
2822 }
2823 }
2824
2825 /* If not in use then it is free to use. */
2826 if (!found) {
2827 break;
2828 }
2829
2830 /* ID in use. Try next value. */
2831 dev->loop_id++;
2832
2833 /* If wrap around. No free ID to use. */
2834 if (dev->loop_id == first_loop_id) {
2835 dev->loop_id = FC_NO_LOOP_ID;
2836 rval = QLA_FUNCTION_FAILED;
2837 break;
2838 }
2839 }
2840
2841 return (rval);
2842}
2843
2844/*
2845 * qla2x00_device_resync
2846 * Marks devices in the database that needs resynchronization.
2847 *
2848 * Input:
2849 * ha = adapter block pointer.
2850 *
2851 * Context:
2852 * Kernel context.
2853 */
2854static int
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002855qla2x00_device_resync(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856{
2857 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 uint32_t mask;
2859 fc_port_t *fcport;
2860 uint32_t rscn_entry;
2861 uint8_t rscn_out_iter;
2862 uint8_t format;
2863 port_id_t d_id;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002864 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865
2866 rval = QLA_RSCNS_HANDLED;
2867
2868 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2869 ha->flags.rscn_queue_overflow) {
2870
2871 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2872 format = MSB(MSW(rscn_entry));
2873 d_id.b.domain = LSB(MSW(rscn_entry));
2874 d_id.b.area = MSB(LSW(rscn_entry));
2875 d_id.b.al_pa = LSB(LSW(rscn_entry));
2876
2877 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2878 "[%02x/%02x%02x%02x].\n",
2879 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2880 d_id.b.area, d_id.b.al_pa));
2881
2882 ha->rscn_out_ptr++;
2883 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2884 ha->rscn_out_ptr = 0;
2885
2886 /* Skip duplicate entries. */
2887 for (rscn_out_iter = ha->rscn_out_ptr;
2888 !ha->flags.rscn_queue_overflow &&
2889 rscn_out_iter != ha->rscn_in_ptr;
2890 rscn_out_iter = (rscn_out_iter ==
2891 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2892
2893 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2894 break;
2895
2896 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2897 "entry found at [%d].\n", ha->host_no,
2898 rscn_out_iter));
2899
2900 ha->rscn_out_ptr = rscn_out_iter;
2901 }
2902
2903 /* Queue overflow, set switch default case. */
2904 if (ha->flags.rscn_queue_overflow) {
2905 DEBUG(printk("scsi(%ld): device_resync: rscn "
2906 "overflow.\n", ha->host_no));
2907
2908 format = 3;
2909 ha->flags.rscn_queue_overflow = 0;
2910 }
2911
2912 switch (format) {
2913 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 mask = 0xffffff;
2915 break;
2916 case 1:
2917 mask = 0xffff00;
2918 break;
2919 case 2:
2920 mask = 0xff0000;
2921 break;
2922 default:
2923 mask = 0x0;
2924 d_id.b24 = 0;
2925 ha->rscn_out_ptr = ha->rscn_in_ptr;
2926 break;
2927 }
2928
2929 rval = QLA_SUCCESS;
2930
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002931 list_for_each_entry(fcport, &pha->fcports, list) {
2932 if (fcport->vp_idx != ha->vp_idx)
2933 continue;
2934
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2936 (fcport->d_id.b24 & mask) != d_id.b24 ||
2937 fcport->port_type == FCT_BROADCAST)
2938 continue;
2939
2940 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2941 if (format != 3 ||
2942 fcport->port_type != FCT_INITIATOR) {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002943 qla2x00_mark_device_lost(ha, fcport,
2944 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 }
2946 }
2947 fcport->flags &= ~FCF_FARP_DONE;
2948 }
2949 }
2950 return (rval);
2951}
2952
2953/*
2954 * qla2x00_fabric_dev_login
2955 * Login fabric target device and update FC port database.
2956 *
2957 * Input:
2958 * ha: adapter state pointer.
2959 * fcport: port structure list pointer.
2960 * next_loopid: contains value of a new loop ID that can be used
2961 * by the next login attempt.
2962 *
2963 * Returns:
2964 * qla2x00 local function return status code.
2965 *
2966 * Context:
2967 * Kernel context.
2968 */
2969static int
2970qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2971 uint16_t *next_loopid)
2972{
2973 int rval;
2974 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002975 uint8_t opts;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976
2977 rval = QLA_SUCCESS;
2978 retry = 0;
2979
2980 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2981 if (rval == QLA_SUCCESS) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002982 /* Send an ADISC to tape devices.*/
2983 opts = 0;
2984 if (fcport->flags & FCF_TAPE_PRESENT)
2985 opts |= BIT_1;
2986 rval = qla2x00_get_port_database(ha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 if (rval != QLA_SUCCESS) {
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002988 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002989 fcport->d_id.b.domain, fcport->d_id.b.area,
2990 fcport->d_id.b.al_pa);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002991 qla2x00_mark_device_lost(ha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 } else {
2993 qla2x00_update_fcport(ha, fcport);
2994 }
2995 }
2996
2997 return (rval);
2998}
2999
3000/*
3001 * qla2x00_fabric_login
3002 * Issue fabric login command.
3003 *
3004 * Input:
3005 * ha = adapter block pointer.
3006 * device = pointer to FC device type structure.
3007 *
3008 * Returns:
3009 * 0 - Login successfully
3010 * 1 - Login failed
3011 * 2 - Initiator device
3012 * 3 - Fatal error
3013 */
3014int
3015qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
3016 uint16_t *next_loopid)
3017{
3018 int rval;
3019 int retry;
3020 uint16_t tmp_loopid;
3021 uint16_t mb[MAILBOX_REGISTER_COUNT];
3022
3023 retry = 0;
3024 tmp_loopid = 0;
3025
3026 for (;;) {
3027 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3028 "for port %02x%02x%02x.\n",
3029 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
3030 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3031
3032 /* Login fcport on switch. */
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003033 ha->isp_ops->fabric_login(ha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 fcport->d_id.b.domain, fcport->d_id.b.area,
3035 fcport->d_id.b.al_pa, mb, BIT_0);
3036 if (mb[0] == MBS_PORT_ID_USED) {
3037 /*
3038 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003039 * recommends the driver perform an implicit login with
3040 * the specified ID again. The ID we just used is save
3041 * here so we return with an ID that can be tried by
3042 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 */
3044 retry++;
3045 tmp_loopid = fcport->loop_id;
3046 fcport->loop_id = mb[1];
3047
3048 DEBUG(printk("Fabric Login: port in use - next "
3049 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3050 fcport->loop_id, fcport->d_id.b.domain,
3051 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3052
3053 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3054 /*
3055 * Login succeeded.
3056 */
3057 if (retry) {
3058 /* A retry occurred before. */
3059 *next_loopid = tmp_loopid;
3060 } else {
3061 /*
3062 * No retry occurred before. Just increment the
3063 * ID value for next login.
3064 */
3065 *next_loopid = (fcport->loop_id + 1);
3066 }
3067
3068 if (mb[1] & BIT_0) {
3069 fcport->port_type = FCT_INITIATOR;
3070 } else {
3071 fcport->port_type = FCT_TARGET;
3072 if (mb[1] & BIT_1) {
3073 fcport->flags |= FCF_TAPE_PRESENT;
3074 }
3075 }
3076
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003077 if (mb[10] & BIT_0)
3078 fcport->supported_classes |= FC_COS_CLASS2;
3079 if (mb[10] & BIT_1)
3080 fcport->supported_classes |= FC_COS_CLASS3;
3081
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082 rval = QLA_SUCCESS;
3083 break;
3084 } else if (mb[0] == MBS_LOOP_ID_USED) {
3085 /*
3086 * Loop ID already used, try next loop ID.
3087 */
3088 fcport->loop_id++;
3089 rval = qla2x00_find_new_loop_id(ha, fcport);
3090 if (rval != QLA_SUCCESS) {
3091 /* Ran out of loop IDs to use */
3092 break;
3093 }
3094 } else if (mb[0] == MBS_COMMAND_ERROR) {
3095 /*
3096 * Firmware possibly timed out during login. If NO
3097 * retries are left to do then the device is declared
3098 * dead.
3099 */
3100 *next_loopid = fcport->loop_id;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003101 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003102 fcport->d_id.b.domain, fcport->d_id.b.area,
3103 fcport->d_id.b.al_pa);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003104 qla2x00_mark_device_lost(ha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105
3106 rval = 1;
3107 break;
3108 } else {
3109 /*
3110 * unrecoverable / not handled error
3111 */
3112 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003113 "loop_id=%x jiffies=%lx.\n",
3114 __func__, ha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115 fcport->d_id.b.domain, fcport->d_id.b.area,
3116 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3117
3118 *next_loopid = fcport->loop_id;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003119 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003120 fcport->d_id.b.domain, fcport->d_id.b.area,
3121 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003123 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124
3125 rval = 3;
3126 break;
3127 }
3128 }
3129
3130 return (rval);
3131}
3132
3133/*
3134 * qla2x00_local_device_login
3135 * Issue local device login command.
3136 *
3137 * Input:
3138 * ha = adapter block pointer.
3139 * loop_id = loop id of device to login to.
3140 *
3141 * Returns (Where's the #define!!!!):
3142 * 0 - Login successfully
3143 * 1 - Login failed
3144 * 3 - Fatal error
3145 */
3146int
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08003147qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148{
3149 int rval;
3150 uint16_t mb[MAILBOX_REGISTER_COUNT];
3151
3152 memset(mb, 0, sizeof(mb));
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08003153 rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154 if (rval == QLA_SUCCESS) {
3155 /* Interrogate mailbox registers for any errors */
3156 if (mb[0] == MBS_COMMAND_ERROR)
3157 rval = 1;
3158 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3159 /* device not in PCB table */
3160 rval = 3;
3161 }
3162
3163 return (rval);
3164}
3165
3166/*
3167 * qla2x00_loop_resync
3168 * Resync with fibre channel devices.
3169 *
3170 * Input:
3171 * ha = adapter block pointer.
3172 *
3173 * Returns:
3174 * 0 = success
3175 */
3176int
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003177qla2x00_loop_resync(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178{
3179 int rval;
3180 uint32_t wait_time;
3181
3182 rval = QLA_SUCCESS;
3183
3184 atomic_set(&ha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3186 if (ha->flags.online) {
3187 if (!(rval = qla2x00_fw_ready(ha))) {
3188 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3189 wait_time = 256;
3190 do {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 atomic_set(&ha->loop_state, LOOP_UPDATE);
3192
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003193 /* Issue a marker after FW becomes ready. */
3194 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3195 ha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196
3197 /* Remap devices on Loop. */
3198 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3199
3200 qla2x00_configure_loop(ha);
3201 wait_time--;
3202 } while (!atomic_read(&ha->loop_down_timer) &&
3203 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3204 wait_time &&
3205 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3206 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 }
3208
3209 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3210 return (QLA_FUNCTION_FAILED);
3211 }
3212
3213 if (rval) {
3214 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3215 }
3216
3217 return (rval);
3218}
3219
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220void
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003221qla2x00_update_fcports(scsi_qla_host_t *ha)
3222{
3223 fc_port_t *fcport;
3224
3225 /* Go with deferred removal of rport references. */
3226 list_for_each_entry(fcport, &ha->fcports, list)
3227 if (fcport->drport)
3228 qla2x00_rport_del(fcport);
3229}
3230
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231/*
3232* qla2x00_abort_isp
3233* Resets ISP and aborts all outstanding commands.
3234*
3235* Input:
3236* ha = adapter block pointer.
3237*
3238* Returns:
3239* 0 = success
3240*/
3241int
3242qla2x00_abort_isp(scsi_qla_host_t *ha)
3243{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003244 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245 uint8_t status = 0;
3246
3247 if (ha->flags.online) {
3248 ha->flags.online = 0;
3249 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07003250 ha->qla_stats.total_isp_aborts++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251
3252 qla_printk(KERN_INFO, ha,
3253 "Performing ISP error recovery - ha= %p.\n", ha);
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003254 ha->isp_ops->reset_chip(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255
3256 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3257 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
3258 atomic_set(&ha->loop_state, LOOP_DOWN);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003259 qla2x00_mark_all_devices_lost(ha, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260 } else {
3261 if (!atomic_read(&ha->loop_down_timer))
3262 atomic_set(&ha->loop_down_timer,
3263 LOOP_DOWN_TIME);
3264 }
3265
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 /* Requeue all commands in outstanding command list. */
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08003267 qla2x00_abort_all_cmds(ha, DID_RESET << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003269 ha->isp_ops->get_flash_version(ha, ha->request_ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003270
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003271 ha->isp_ops->nvram_config(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272
3273 if (!qla2x00_restart_isp(ha)) {
3274 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3275
3276 if (!atomic_read(&ha->loop_down_timer)) {
3277 /*
3278 * Issue marker command only when we are going
3279 * to start the I/O .
3280 */
3281 ha->marker_needed = 1;
3282 }
3283
3284 ha->flags.online = 1;
3285
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003286 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003288 ha->isp_abort_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003290
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003291 if (ha->fce) {
3292 ha->flags.fce_enabled = 1;
3293 memset(ha->fce, 0,
3294 fce_calc_size(ha->fce_bufs));
3295 rval = qla2x00_enable_fce_trace(ha,
3296 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3297 &ha->fce_bufs);
3298 if (rval) {
3299 qla_printk(KERN_WARNING, ha,
3300 "Unable to reinitialize FCE "
3301 "(%d).\n", rval);
3302 ha->flags.fce_enabled = 0;
3303 }
3304 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003305
3306 if (ha->eft) {
3307 memset(ha->eft, 0, EFT_SIZE);
3308 rval = qla2x00_enable_eft_trace(ha,
3309 ha->eft_dma, EFT_NUM_BUFFERS);
3310 if (rval) {
3311 qla_printk(KERN_WARNING, ha,
3312 "Unable to reinitialize EFT "
3313 "(%d).\n", rval);
3314 }
3315 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316 } else { /* failed the ISP abort */
3317 ha->flags.online = 1;
3318 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3319 if (ha->isp_abort_cnt == 0) {
3320 qla_printk(KERN_WARNING, ha,
3321 "ISP error recovery failed - "
3322 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003323 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324 * The next call disables the board
3325 * completely.
3326 */
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003327 ha->isp_ops->reset_adapter(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328 ha->flags.online = 0;
3329 clear_bit(ISP_ABORT_RETRY,
3330 &ha->dpc_flags);
3331 status = 0;
3332 } else { /* schedule another ISP abort */
3333 ha->isp_abort_cnt--;
3334 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003335 "retry remaining %d\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003336 ha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337 status = 1;
3338 }
3339 } else {
3340 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3341 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3342 "- retrying (%d) more times\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003343 ha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3345 status = 1;
3346 }
3347 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003348
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 }
3350
3351 if (status) {
3352 qla_printk(KERN_INFO, ha,
3353 "qla2x00_abort_isp: **** FAILED ****\n");
3354 } else {
3355 DEBUG(printk(KERN_INFO
3356 "qla2x00_abort_isp(%ld): exiting.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003357 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358 }
3359
3360 return(status);
3361}
3362
3363/*
3364* qla2x00_restart_isp
3365* restarts the ISP after a reset
3366*
3367* Input:
3368* ha = adapter block pointer.
3369*
3370* Returns:
3371* 0 = success
3372*/
3373static int
3374qla2x00_restart_isp(scsi_qla_host_t *ha)
3375{
3376 uint8_t status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377 uint32_t wait_time;
3378
3379 /* If firmware needs to be loaded */
3380 if (qla2x00_isp_firmware(ha)) {
3381 ha->flags.online = 0;
Andrew Vasquez3db06522008-01-31 12:33:49 -08003382 if (!(status = ha->isp_ops->chip_diag(ha)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383 status = qla2x00_setup_chip(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384 }
3385
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386 if (!status && !(status = qla2x00_init_rings(ha))) {
3387 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3388 if (!(status = qla2x00_fw_ready(ha))) {
3389 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003390 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003391
3392 /* Issue a marker after FW becomes ready. */
3393 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3394
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395 ha->flags.online = 1;
3396 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3397 wait_time = 256;
3398 do {
3399 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3400 qla2x00_configure_loop(ha);
3401 wait_time--;
3402 } while (!atomic_read(&ha->loop_down_timer) &&
3403 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3404 wait_time &&
3405 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3406 }
3407
3408 /* if no cable then assume it's good */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003409 if ((ha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 status = 0;
3411
3412 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3413 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003414 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415 }
3416 return (status);
3417}
3418
3419/*
3420* qla2x00_reset_adapter
3421* Reset adapter.
3422*
3423* Input:
3424* ha = adapter block pointer.
3425*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003426void
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427qla2x00_reset_adapter(scsi_qla_host_t *ha)
3428{
3429 unsigned long flags = 0;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003430 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431
3432 ha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003433 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435 spin_lock_irqsave(&ha->hardware_lock, flags);
3436 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3437 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3438 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3439 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3440 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3441}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003442
3443void
3444qla24xx_reset_adapter(scsi_qla_host_t *ha)
3445{
3446 unsigned long flags = 0;
3447 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3448
3449 ha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003450 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003451
3452 spin_lock_irqsave(&ha->hardware_lock, flags);
3453 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3454 RD_REG_DWORD(&reg->hccr);
3455 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3456 RD_REG_DWORD(&reg->hccr);
3457 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3458}
3459
David Miller4e08df32007-04-16 12:37:43 -07003460/* On sparc systems, obtain port and node WWN from firmware
3461 * properties.
3462 */
3463static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, struct nvram_24xx *nv)
3464{
3465#ifdef CONFIG_SPARC
3466 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003467 struct device_node *dp = pci_device_to_OF_node(pdev);
3468 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003469 int len;
3470
3471 val = of_get_property(dp, "port-wwn", &len);
3472 if (val && len >= WWN_SIZE)
3473 memcpy(nv->port_name, val, WWN_SIZE);
3474
3475 val = of_get_property(dp, "node-wwn", &len);
3476 if (val && len >= WWN_SIZE)
3477 memcpy(nv->node_name, val, WWN_SIZE);
3478#endif
3479}
3480
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003481int
3482qla24xx_nvram_config(scsi_qla_host_t *ha)
3483{
David Miller4e08df32007-04-16 12:37:43 -07003484 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003485 struct init_cb_24xx *icb;
3486 struct nvram_24xx *nv;
3487 uint32_t *dptr;
3488 uint8_t *dptr1, *dptr2;
3489 uint32_t chksum;
3490 uint16_t cnt;
3491
David Miller4e08df32007-04-16 12:37:43 -07003492 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003493 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003494 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003495
3496 /* Determine NVRAM starting address. */
3497 ha->nvram_size = sizeof(struct nvram_24xx);
3498 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003499 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3500 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3501 if (PCI_FUNC(ha->pdev->devfn)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003502 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003503 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3504 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003505
Seokmann Ju281afe12007-07-26 13:43:34 -07003506 /* Get VPD data into cache */
3507 ha->vpd = ha->nvram + VPD_OFFSET;
3508 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->vpd,
3509 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3510
3511 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003512 dptr = (uint32_t *)nv;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003513 ha->isp_ops->read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003514 ha->nvram_size);
3515 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3516 chksum += le32_to_cpu(*dptr++);
3517
3518 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07003519 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003520
3521 /* Bad NVRAM data, set defaults parameters. */
3522 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3523 || nv->id[3] != ' ' ||
3524 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3525 /* Reset NVRAM data. */
3526 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3527 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3528 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07003529 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3530 "invalid -- WWPN) defaults.\n");
3531
3532 /*
3533 * Set default initialization control block.
3534 */
3535 memset(nv, 0, ha->nvram_size);
3536 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3537 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3538 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3539 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3540 nv->exchange_count = __constant_cpu_to_le16(0);
3541 nv->hard_address = __constant_cpu_to_le16(124);
3542 nv->port_name[0] = 0x21;
3543 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3544 nv->port_name[2] = 0x00;
3545 nv->port_name[3] = 0xe0;
3546 nv->port_name[4] = 0x8b;
3547 nv->port_name[5] = 0x1c;
3548 nv->port_name[6] = 0x55;
3549 nv->port_name[7] = 0x86;
3550 nv->node_name[0] = 0x20;
3551 nv->node_name[1] = 0x00;
3552 nv->node_name[2] = 0x00;
3553 nv->node_name[3] = 0xe0;
3554 nv->node_name[4] = 0x8b;
3555 nv->node_name[5] = 0x1c;
3556 nv->node_name[6] = 0x55;
3557 nv->node_name[7] = 0x86;
3558 qla24xx_nvram_wwn_from_ofw(ha, nv);
3559 nv->login_retry_count = __constant_cpu_to_le16(8);
3560 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3561 nv->login_timeout = __constant_cpu_to_le16(0);
3562 nv->firmware_options_1 =
3563 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3564 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3565 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3566 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3567 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3568 nv->efi_parameters = __constant_cpu_to_le32(0);
3569 nv->reset_delay = 5;
3570 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3571 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3572 nv->link_down_timeout = __constant_cpu_to_le16(30);
3573
3574 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003575 }
3576
3577 /* Reset Initialization control block */
3578 memset(icb, 0, sizeof(struct init_cb_24xx));
3579
3580 /* Copy 1st segment. */
3581 dptr1 = (uint8_t *)icb;
3582 dptr2 = (uint8_t *)&nv->version;
3583 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3584 while (cnt--)
3585 *dptr1++ = *dptr2++;
3586
3587 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07003588 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003589
3590 /* Copy 2nd segment. */
3591 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3592 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3593 cnt = (uint8_t *)&icb->reserved_3 -
3594 (uint8_t *)&icb->interrupt_delay_timer;
3595 while (cnt--)
3596 *dptr1++ = *dptr2++;
3597
3598 /*
3599 * Setup driver NVRAM options.
3600 */
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003601 qla2x00_set_model_info(ha, nv->model_name, sizeof(nv->model_name),
3602 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003603
Andrew Vasquez5341e862006-05-17 15:09:16 -07003604 /* Use alternate WWN? */
3605 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3606 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3607 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3608 }
3609
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003610 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003611 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003612 /*
3613 * Firmware will apply the following mask if the nodename was
3614 * not provided.
3615 */
3616 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3617 icb->node_name[0] &= 0xF0;
3618 }
3619
3620 /* Set host adapter parameters. */
3621 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08003622 ha->flags.enable_lip_reset = 0;
3623 ha->flags.enable_lip_full_login =
3624 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3625 ha->flags.enable_target_reset =
3626 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003627 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07003628 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003629
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003630 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3631 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003632
3633 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3634 sizeof(ha->fw_seriallink_options24));
3635
3636 /* save HBA serial number */
3637 ha->serial0 = icb->port_name[5];
3638 ha->serial1 = icb->port_name[6];
3639 ha->serial2 = icb->port_name[7];
3640 ha->node_name = icb->node_name;
3641 ha->port_name = icb->port_name;
3642
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08003643 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3644
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003645 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3646
3647 /* Set minimum login_timeout to 4 seconds. */
3648 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3649 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3650 if (le16_to_cpu(nv->login_timeout) < 4)
3651 nv->login_timeout = __constant_cpu_to_le16(4);
3652 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07003653 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003654
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003655 /* Set minimum RATOV to 100 tenths of a second. */
3656 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003657
3658 ha->loop_reset_delay = nv->reset_delay;
3659
3660 /* Link Down Timeout = 0:
3661 *
3662 * When Port Down timer expires we will start returning
3663 * I/O's to OS with "DID_NO_CONNECT".
3664 *
3665 * Link Down Timeout != 0:
3666 *
3667 * The driver waits for the link to come up after link down
3668 * before returning I/Os to OS with "DID_NO_CONNECT".
3669 */
3670 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3671 ha->loop_down_abort_time =
3672 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3673 } else {
3674 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3675 ha->loop_down_abort_time =
3676 (LOOP_DOWN_TIME - ha->link_down_timeout);
3677 }
3678
3679 /* Need enough time to try and get the port back. */
3680 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3681 if (qlport_down_retry)
3682 ha->port_down_retry_count = qlport_down_retry;
3683
3684 /* Set login_retry_count */
3685 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3686 if (ha->port_down_retry_count ==
3687 le16_to_cpu(nv->port_down_retry_count) &&
3688 ha->port_down_retry_count > 3)
3689 ha->login_retry_count = ha->port_down_retry_count;
3690 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3691 ha->login_retry_count = ha->port_down_retry_count;
3692 if (ql2xloginretrycount)
3693 ha->login_retry_count = ql2xloginretrycount;
3694
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003695 /* Enable ZIO. */
3696 if (!ha->flags.init_done) {
3697 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3698 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3699 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3700 le16_to_cpu(icb->interrupt_delay_timer): 2;
3701 }
3702 icb->firmware_options_2 &= __constant_cpu_to_le32(
3703 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3704 ha->flags.process_response_queue = 0;
3705 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08003706 ha->zio_mode = QLA_ZIO_MODE_6;
3707
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003708 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3709 "(%d us).\n", ha->host_no, ha->zio_mode,
3710 ha->zio_timer * 100));
3711 qla_printk(KERN_INFO, ha,
3712 "ZIO mode %d enabled; timer delay (%d us).\n",
3713 ha->zio_mode, ha->zio_timer * 100);
3714
3715 icb->firmware_options_2 |= cpu_to_le32(
3716 (uint32_t)ha->zio_mode);
3717 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3718 ha->flags.process_response_queue = 1;
3719 }
3720
David Miller4e08df32007-04-16 12:37:43 -07003721 if (rval) {
3722 DEBUG2_3(printk(KERN_WARNING
3723 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3724 }
3725 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003726}
3727
Adrian Bunk413975a2006-06-30 02:33:06 -07003728static int
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003729qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3730{
3731 int rval;
3732 int segments, fragment;
3733 uint32_t faddr;
3734 uint32_t *dcode, dlen;
3735 uint32_t risc_addr;
3736 uint32_t risc_size;
3737 uint32_t i;
3738
3739 rval = QLA_SUCCESS;
3740
3741 segments = FA_RISC_CODE_SEGMENTS;
3742 faddr = FA_RISC_CODE_ADDR;
3743 dcode = (uint32_t *)ha->request_ring;
3744 *srisc_addr = 0;
3745
3746 /* Validate firmware image by checking version. */
3747 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3748 for (i = 0; i < 4; i++)
3749 dcode[i] = be32_to_cpu(dcode[i]);
3750 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3751 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3752 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3753 dcode[3] == 0)) {
3754 qla_printk(KERN_WARNING, ha,
3755 "Unable to verify integrity of flash firmware image!\n");
3756 qla_printk(KERN_WARNING, ha,
3757 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3758 dcode[1], dcode[2], dcode[3]);
3759
3760 return QLA_FUNCTION_FAILED;
3761 }
3762
3763 while (segments && rval == QLA_SUCCESS) {
3764 /* Read segment's load information. */
3765 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3766
3767 risc_addr = be32_to_cpu(dcode[2]);
3768 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3769 risc_size = be32_to_cpu(dcode[3]);
3770
3771 fragment = 0;
3772 while (risc_size > 0 && rval == QLA_SUCCESS) {
3773 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3774 if (dlen > risc_size)
3775 dlen = risc_size;
3776
3777 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3778 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3779 ha->host_no, risc_addr, dlen, faddr));
3780
3781 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3782 for (i = 0; i < dlen; i++)
3783 dcode[i] = swab32(dcode[i]);
3784
3785 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3786 dlen);
3787 if (rval) {
3788 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3789 "segment %d of firmware\n", ha->host_no,
3790 fragment));
3791 qla_printk(KERN_WARNING, ha,
3792 "[ERROR] Failed to load segment %d of "
3793 "firmware\n", fragment);
3794 break;
3795 }
3796
3797 faddr += dlen;
3798 risc_addr += dlen;
3799 risc_size -= dlen;
3800 fragment++;
3801 }
3802
3803 /* Next segment. */
3804 segments--;
3805 }
3806
3807 return rval;
3808}
3809
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003810#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3811
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003812int
Andrew Vasquez54333832005-11-09 15:49:04 -08003813qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3814{
3815 int rval;
3816 int i, fragment;
3817 uint16_t *wcode, *fwcode;
3818 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3819 struct fw_blob *blob;
3820
3821 /* Load firmware blob. */
3822 blob = qla2x00_request_firmware(ha);
3823 if (!blob) {
3824 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003825 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3826 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08003827 return QLA_FUNCTION_FAILED;
3828 }
3829
3830 rval = QLA_SUCCESS;
3831
3832 wcode = (uint16_t *)ha->request_ring;
3833 *srisc_addr = 0;
3834 fwcode = (uint16_t *)blob->fw->data;
3835 fwclen = 0;
3836
3837 /* Validate firmware image by checking version. */
3838 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3839 qla_printk(KERN_WARNING, ha,
3840 "Unable to verify integrity of firmware image (%Zd)!\n",
3841 blob->fw->size);
3842 goto fail_fw_integrity;
3843 }
3844 for (i = 0; i < 4; i++)
3845 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3846 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3847 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3848 wcode[2] == 0 && wcode[3] == 0)) {
3849 qla_printk(KERN_WARNING, ha,
3850 "Unable to verify integrity of firmware image!\n");
3851 qla_printk(KERN_WARNING, ha,
3852 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3853 wcode[1], wcode[2], wcode[3]);
3854 goto fail_fw_integrity;
3855 }
3856
3857 seg = blob->segs;
3858 while (*seg && rval == QLA_SUCCESS) {
3859 risc_addr = *seg;
3860 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3861 risc_size = be16_to_cpu(fwcode[3]);
3862
3863 /* Validate firmware image size. */
3864 fwclen += risc_size * sizeof(uint16_t);
3865 if (blob->fw->size < fwclen) {
3866 qla_printk(KERN_WARNING, ha,
3867 "Unable to verify integrity of firmware image "
3868 "(%Zd)!\n", blob->fw->size);
3869 goto fail_fw_integrity;
3870 }
3871
3872 fragment = 0;
3873 while (risc_size > 0 && rval == QLA_SUCCESS) {
3874 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3875 if (wlen > risc_size)
3876 wlen = risc_size;
3877
3878 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3879 "addr %x, number of words 0x%x.\n", ha->host_no,
3880 risc_addr, wlen));
3881
3882 for (i = 0; i < wlen; i++)
3883 wcode[i] = swab16(fwcode[i]);
3884
3885 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3886 wlen);
3887 if (rval) {
3888 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3889 "segment %d of firmware\n", ha->host_no,
3890 fragment));
3891 qla_printk(KERN_WARNING, ha,
3892 "[ERROR] Failed to load segment %d of "
3893 "firmware\n", fragment);
3894 break;
3895 }
3896
3897 fwcode += wlen;
3898 risc_addr += wlen;
3899 risc_size -= wlen;
3900 fragment++;
3901 }
3902
3903 /* Next segment. */
3904 seg++;
3905 }
3906 return rval;
3907
3908fail_fw_integrity:
3909 return QLA_FUNCTION_FAILED;
3910}
3911
3912int
3913qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003914{
3915 int rval;
3916 int segments, fragment;
3917 uint32_t *dcode, dlen;
3918 uint32_t risc_addr;
3919 uint32_t risc_size;
3920 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08003921 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003922 uint32_t *fwcode, fwclen;
3923
Andrew Vasquez54333832005-11-09 15:49:04 -08003924 /* Load firmware blob. */
3925 blob = qla2x00_request_firmware(ha);
3926 if (!blob) {
3927 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003928 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3929 "from: " QLA_FW_URL ".\n");
3930
3931 /* Try to load RISC code from flash. */
3932 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
3933 "outdated) firmware from flash.\n");
3934 return qla24xx_load_risc_flash(ha, srisc_addr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003935 }
3936
3937 rval = QLA_SUCCESS;
3938
3939 segments = FA_RISC_CODE_SEGMENTS;
3940 dcode = (uint32_t *)ha->request_ring;
3941 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08003942 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003943 fwclen = 0;
3944
3945 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08003946 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003947 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08003948 "Unable to verify integrity of firmware image (%Zd)!\n",
3949 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003950 goto fail_fw_integrity;
3951 }
3952 for (i = 0; i < 4; i++)
3953 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3954 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3955 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3956 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3957 dcode[3] == 0)) {
3958 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08003959 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003960 qla_printk(KERN_WARNING, ha,
3961 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3962 dcode[1], dcode[2], dcode[3]);
3963 goto fail_fw_integrity;
3964 }
3965
3966 while (segments && rval == QLA_SUCCESS) {
3967 risc_addr = be32_to_cpu(fwcode[2]);
3968 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3969 risc_size = be32_to_cpu(fwcode[3]);
3970
3971 /* Validate firmware image size. */
3972 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08003973 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003974 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08003975 "Unable to verify integrity of firmware image "
3976 "(%Zd)!\n", blob->fw->size);
3977
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003978 goto fail_fw_integrity;
3979 }
3980
3981 fragment = 0;
3982 while (risc_size > 0 && rval == QLA_SUCCESS) {
3983 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3984 if (dlen > risc_size)
3985 dlen = risc_size;
3986
3987 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3988 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3989 risc_addr, dlen));
3990
3991 for (i = 0; i < dlen; i++)
3992 dcode[i] = swab32(fwcode[i]);
3993
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08003994 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3995 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003996 if (rval) {
3997 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3998 "segment %d of firmware\n", ha->host_no,
3999 fragment));
4000 qla_printk(KERN_WARNING, ha,
4001 "[ERROR] Failed to load segment %d of "
4002 "firmware\n", fragment);
4003 break;
4004 }
4005
4006 fwcode += dlen;
4007 risc_addr += dlen;
4008 risc_size -= dlen;
4009 fragment++;
4010 }
4011
4012 /* Next segment. */
4013 segments--;
4014 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004015 return rval;
4016
4017fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004018 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004019}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004020
4021void
4022qla2x00_try_to_stop_firmware(scsi_qla_host_t *ha)
4023{
4024 int ret, retries;
4025
Andrew Vasqueze4289242007-07-19 15:05:56 -07004026 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004027 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004028 if (!ha->fw_major_version)
4029 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004030
4031 ret = qla2x00_stop_firmware(ha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004032 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
4033 retries ; retries--) {
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004034 qla2x00_reset_chip(ha);
4035 if (qla2x00_chip_diag(ha) != QLA_SUCCESS)
4036 continue;
4037 if (qla2x00_setup_chip(ha) != QLA_SUCCESS)
4038 continue;
4039 qla_printk(KERN_INFO, ha,
4040 "Attempting retry of stop-firmware command...\n");
4041 ret = qla2x00_stop_firmware(ha);
4042 }
4043}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004044
4045int
4046qla24xx_configure_vhba(scsi_qla_host_t *ha)
4047{
4048 int rval = QLA_SUCCESS;
4049 uint16_t mb[MAILBOX_REGISTER_COUNT];
4050
4051 if (!ha->parent)
4052 return -EINVAL;
4053
Seokmann Jud4486fd62008-04-03 13:13:28 -07004054 rval = qla2x00_fw_ready(ha->parent);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004055 if (rval == QLA_SUCCESS) {
4056 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
Seokmann Ju246de422008-07-10 16:55:55 -07004057 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004058 }
4059
4060 ha->flags.management_server_logged_in = 0;
4061
4062 /* Login to SNS first */
Seokmann Jud4486fd62008-04-03 13:13:28 -07004063 qla24xx_login_fabric(ha->parent, NPH_SNS, 0xff, 0xff, 0xfc,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004064 mb, BIT_1);
4065 if (mb[0] != MBS_COMMAND_COMPLETE) {
4066 DEBUG15(qla_printk(KERN_INFO, ha,
4067 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4068 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4069 mb[0], mb[1], mb[2], mb[6], mb[7]));
4070 return (QLA_FUNCTION_FAILED);
4071 }
4072
4073 atomic_set(&ha->loop_down_timer, 0);
4074 atomic_set(&ha->loop_state, LOOP_UP);
4075 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
4076 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
Seokmann Jud4486fd62008-04-03 13:13:28 -07004077 rval = qla2x00_loop_resync(ha->parent);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004078
4079 return rval;
4080}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004081
4082/* 84XX Support **************************************************************/
4083
4084static LIST_HEAD(qla_cs84xx_list);
4085static DEFINE_MUTEX(qla_cs84xx_mutex);
4086
4087static struct qla_chip_state_84xx *
4088qla84xx_get_chip(struct scsi_qla_host *ha)
4089{
4090 struct qla_chip_state_84xx *cs84xx;
4091
4092 mutex_lock(&qla_cs84xx_mutex);
4093
4094 /* Find any shared 84xx chip. */
4095 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4096 if (cs84xx->bus == ha->pdev->bus) {
4097 kref_get(&cs84xx->kref);
4098 goto done;
4099 }
4100 }
4101
4102 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4103 if (!cs84xx)
4104 goto done;
4105
4106 kref_init(&cs84xx->kref);
4107 spin_lock_init(&cs84xx->access_lock);
4108 mutex_init(&cs84xx->fw_update_mutex);
4109 cs84xx->bus = ha->pdev->bus;
4110
4111 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4112done:
4113 mutex_unlock(&qla_cs84xx_mutex);
4114 return cs84xx;
4115}
4116
4117static void
4118__qla84xx_chip_release(struct kref *kref)
4119{
4120 struct qla_chip_state_84xx *cs84xx =
4121 container_of(kref, struct qla_chip_state_84xx, kref);
4122
4123 mutex_lock(&qla_cs84xx_mutex);
4124 list_del(&cs84xx->list);
4125 mutex_unlock(&qla_cs84xx_mutex);
4126 kfree(cs84xx);
4127}
4128
4129void
4130qla84xx_put_chip(struct scsi_qla_host *ha)
4131{
4132 if (ha->cs84xx)
4133 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4134}
4135
4136static int
4137qla84xx_init_chip(scsi_qla_host_t *ha)
4138{
4139 int rval;
4140 uint16_t status[2];
4141
4142 mutex_lock(&ha->cs84xx->fw_update_mutex);
4143
4144 rval = qla84xx_verify_chip(ha, status);
4145
4146 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4147
4148 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4149 QLA_SUCCESS;
4150}