blob: 2d4f32b4df5c831caccd46e0f73c8d2a8b750942 [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"
Anirban Chakraborty73208df2008-12-09 16:45:39 -08008#include "qla_gbl.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10#include <linux/delay.h>
Andrew Vasquez0107109e2005-07-06 10:31:37 -070011#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
13#include "qla_devtbl.h"
14
David Miller4e08df32007-04-16 12:37:43 -070015#ifdef CONFIG_SPARC
16#include <asm/prom.h>
David Miller4e08df32007-04-16 12:37:43 -070017#endif
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019/*
20* QLogic ISP2x00 Hardware Support Function Prototypes.
21*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070022static int qla2x00_isp_firmware(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070023static void qla2x00_resize_request_q(scsi_qla_host_t *);
24static int qla2x00_setup_chip(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070025static 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
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080038static int qla2x00_find_new_loop_id(scsi_qla_host_t *, fc_port_t *);
Adrian Bunk413975a2006-06-30 02:33:06 -070039
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 *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080042static int qla25xx_init_queues(struct qla_hw_data *);
Harihara Kadayam4d4df192008-04-03 13:13:26 -070043
Linus Torvalds1da177e2005-04-16 15:20:36 -070044/****************************************************************************/
45/* QLogic ISP2x00 Hardware Support Functions. */
46/****************************************************************************/
47
48/*
49* qla2x00_initialize_adapter
50* Initialize board.
51*
52* Input:
53* ha = adapter block pointer.
54*
55* Returns:
56* 0 = success
57*/
58int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080059qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
61 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080062 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -080063 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080065 vha->flags.online = 0;
66 vha->flags.reset_active = 0;
67 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
68 atomic_set(&vha->loop_state, LOOP_DOWN);
69 vha->device_flags = DFLG_NO_CABLE;
70 vha->dpc_flags = 0;
71 vha->flags.management_server_logged_in = 0;
72 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 ha->mbx_flags = 0;
74 ha->isp_abort_cnt = 0;
75 ha->beacon_blink_led = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080076 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Anirban Chakraborty73208df2008-12-09 16:45:39 -080078 set_bit(0, ha->req_qid_map);
79 set_bit(0, ha->rsp_qid_map);
80
Andrew Vasquez0107109e2005-07-06 10:31:37 -070081 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080082 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 if (rval) {
Andrew Vasquez7c98a042007-01-29 10:22:29 -080084 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080085 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 return (rval);
87 }
88
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080089 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080091 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -070092 if (rval) {
93 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080094 vha->host_no));
Andrew Vasquezc00d8992008-09-11 21:22:49 -070095 return (rval);
96 }
97
Anirban Chakraborty73208df2008-12-09 16:45:39 -080098 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -080099
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700101
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800102 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700104 if (ha->flags.disable_serdes) {
105 /* Mask HBA via NVRAM settings? */
106 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
107 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800108 vha->port_name[0], vha->port_name[1],
109 vha->port_name[2], vha->port_name[3],
110 vha->port_name[4], vha->port_name[5],
111 vha->port_name[6], vha->port_name[7]);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700112 return QLA_FUNCTION_FAILED;
113 }
114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
116
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800117 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
118 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800119 if (rval)
120 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800121 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800122 if (rval)
123 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700125 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800126 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700127 if (!ha->cs84xx) {
128 qla_printk(KERN_ERR, ha,
129 "Unable to configure ISP84XX.\n");
130 return QLA_FUNCTION_FAILED;
131 }
132 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800133 rval = qla2x00_init_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135 return (rval);
136}
137
138/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700139 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 * @ha: HA context
141 *
142 * Returns 0 on success.
143 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700144int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800145qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700147 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700148 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800149 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700150 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700153 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700156 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
158
Andrew Vasquez737faec2008-10-24 15:13:45 -0700159 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700161 /* Get PCI bus information. */
162 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700163 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700164 spin_unlock_irqrestore(&ha->hardware_lock, flags);
165
166 return QLA_SUCCESS;
167}
168
169/**
170 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
171 * @ha: HA context
172 *
173 * Returns 0 on success.
174 */
175int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800176qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700177{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700178 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700179 unsigned long flags = 0;
180 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800181 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700182 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700183
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700184 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700185 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700186
187 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700188 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700189
190 if (IS_QLA2322(ha) || IS_QLA6322(ha))
191 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700192 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700193
194 /*
195 * If this is a 2300 card and not 2312, reset the
196 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
197 * the 2310 also reports itself as a 2300 so we need to get the
198 * fb revision level -- a 6 indicates it really is a 2300 and
199 * not a 2310.
200 */
201 if (IS_QLA2300(ha)) {
202 spin_lock_irqsave(&ha->hardware_lock, flags);
203
204 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700205 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700206 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700207 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700208 break;
209
210 udelay(10);
211 }
212
213 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700214 WRT_REG_WORD(&reg->ctrl_status, 0x20);
215 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700216
217 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700218 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700219
220 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700221 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700222
223 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700224 WRT_REG_WORD(&reg->ctrl_status, 0x0);
225 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700226
227 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700228 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700229 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700230 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700231 break;
232
233 udelay(10);
234 }
235
236 spin_unlock_irqrestore(&ha->hardware_lock, flags);
237 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700238
239 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
240
Andrew Vasquez737faec2008-10-24 15:13:45 -0700241 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700242
243 /* Get PCI bus information. */
244 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700245 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700246 spin_unlock_irqrestore(&ha->hardware_lock, flags);
247
248 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249}
250
251/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700252 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
253 * @ha: HA context
254 *
255 * Returns 0 on success.
256 */
257int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800258qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700259{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700260 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700261 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800262 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700263 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700264
265 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700266 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700267
268 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700269 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700270 w &= ~PCI_COMMAND_INTX_DISABLE;
271 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
272
273 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
274
275 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700276 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
277 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700278
279 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700280 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
281 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700282
Andrew Vasquez737faec2008-10-24 15:13:45 -0700283 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700284
Auke Kok44c10132007-06-08 15:46:36 -0700285 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800286
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700287 /* Get PCI bus information. */
288 spin_lock_irqsave(&ha->hardware_lock, flags);
289 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
290 spin_unlock_irqrestore(&ha->hardware_lock, flags);
291
292 return QLA_SUCCESS;
293}
294
295/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700296 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
297 * @ha: HA context
298 *
299 * Returns 0 on success.
300 */
301int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800302qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700303{
304 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800305 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700306
307 pci_set_master(ha->pdev);
308 pci_try_set_mwi(ha->pdev);
309
310 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
311 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
312 w &= ~PCI_COMMAND_INTX_DISABLE;
313 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
314
315 /* PCIe -- adjust Maximum Read Request Size (2048). */
316 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
317 pcie_set_readrq(ha->pdev, 2048);
318
Andrew Vasquez737faec2008-10-24 15:13:45 -0700319 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700320
321 ha->chip_revision = ha->pdev->revision;
322
323 return QLA_SUCCESS;
324}
325
326/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 * qla2x00_isp_firmware() - Choose firmware image.
328 * @ha: HA context
329 *
330 * Returns 0 on success.
331 */
332static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800333qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
335 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700336 uint16_t loop_id, topo, sw_cap;
337 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800338 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
340 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700341 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343 if (ha->flags.disable_risc_code_load) {
344 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800345 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
347
348 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800349 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700350 if (rval == QLA_SUCCESS) {
351 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800352 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700353 &area, &domain, &topo, &sw_cap);
354 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 }
356
357 if (rval) {
358 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800359 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 }
361
362 return (rval);
363}
364
365/**
366 * qla2x00_reset_chip() - Reset ISP chip.
367 * @ha: HA context
368 *
369 * Returns 0 on success.
370 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700371void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800372qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
374 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800375 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700376 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 uint16_t cmd;
379
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700380 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
382 spin_lock_irqsave(&ha->hardware_lock, flags);
383
384 /* Turn off master enable */
385 cmd = 0;
386 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
387 cmd &= ~PCI_COMMAND_MASTER;
388 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
389
390 if (!IS_QLA2100(ha)) {
391 /* Pause RISC. */
392 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
393 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
394 for (cnt = 0; cnt < 30000; cnt++) {
395 if ((RD_REG_WORD(&reg->hccr) &
396 HCCR_RISC_PAUSE) != 0)
397 break;
398 udelay(100);
399 }
400 } else {
401 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
402 udelay(10);
403 }
404
405 /* Select FPM registers. */
406 WRT_REG_WORD(&reg->ctrl_status, 0x20);
407 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
408
409 /* FPM Soft Reset. */
410 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
411 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
412
413 /* Toggle Fpm Reset. */
414 if (!IS_QLA2200(ha)) {
415 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
416 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
417 }
418
419 /* Select frame buffer registers. */
420 WRT_REG_WORD(&reg->ctrl_status, 0x10);
421 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
422
423 /* Reset frame buffer FIFOs. */
424 if (IS_QLA2200(ha)) {
425 WRT_FB_CMD_REG(ha, reg, 0xa000);
426 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
427 } else {
428 WRT_FB_CMD_REG(ha, reg, 0x00fc);
429
430 /* Read back fb_cmd until zero or 3 seconds max */
431 for (cnt = 0; cnt < 3000; cnt++) {
432 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
433 break;
434 udelay(100);
435 }
436 }
437
438 /* Select RISC module registers. */
439 WRT_REG_WORD(&reg->ctrl_status, 0);
440 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
441
442 /* Reset RISC processor. */
443 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
444 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
445
446 /* Release RISC processor. */
447 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
448 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
449 }
450
451 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
452 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
453
454 /* Reset ISP chip. */
455 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
456
457 /* Wait for RISC to recover from reset. */
458 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
459 /*
460 * It is necessary to for a delay here since the card doesn't
461 * respond to PCI reads during a reset. On some architectures
462 * this will result in an MCA.
463 */
464 udelay(20);
465 for (cnt = 30000; cnt; cnt--) {
466 if ((RD_REG_WORD(&reg->ctrl_status) &
467 CSR_ISP_SOFT_RESET) == 0)
468 break;
469 udelay(100);
470 }
471 } else
472 udelay(10);
473
474 /* Reset RISC processor. */
475 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
476
477 WRT_REG_WORD(&reg->semaphore, 0);
478
479 /* Release RISC processor. */
480 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
481 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
482
483 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
484 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700485 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
488 udelay(100);
489 }
490 } else
491 udelay(100);
492
493 /* Turn on master enable */
494 cmd |= PCI_COMMAND_MASTER;
495 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
496
497 /* Disable RISC pause on FPM parity error. */
498 if (!IS_QLA2100(ha)) {
499 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
500 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
501 }
502
503 spin_unlock_irqrestore(&ha->hardware_lock, flags);
504}
505
506/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700507 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700508 * @ha: HA context
509 *
510 * Returns 0 on success.
511 */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700512static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800513qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700514{
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -0700515 int hw_evt = 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700516 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800517 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700518 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
519 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800520 uint16_t wd;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700521
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700522 spin_lock_irqsave(&ha->hardware_lock, flags);
523
524 /* Reset RISC. */
525 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
526 for (cnt = 0; cnt < 30000; cnt++) {
527 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
528 break;
529
530 udelay(10);
531 }
532
533 WRT_REG_DWORD(&reg->ctrl_status,
534 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800535 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700536
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800537 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700538 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700539 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
540 for (cnt = 10000 ; cnt && d2; cnt--) {
541 udelay(5);
542 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
543 barrier();
544 }
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -0700545 if (cnt == 0)
546 hw_evt = 1;
Andrew Vasquez88c26662005-07-08 17:59:26 -0700547
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800548 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700549 d2 = RD_REG_DWORD(&reg->ctrl_status);
550 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
551 udelay(5);
552 d2 = RD_REG_DWORD(&reg->ctrl_status);
553 barrier();
554 }
555
556 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
557 RD_REG_DWORD(&reg->hccr);
558
559 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
560 RD_REG_DWORD(&reg->hccr);
561
562 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
563 RD_REG_DWORD(&reg->hccr);
564
565 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
566 for (cnt = 6000000 ; cnt && d2; cnt--) {
567 udelay(5);
568 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
569 barrier();
570 }
571
572 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800573
574 if (IS_NOPOLLING_TYPE(ha))
575 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700576}
577
578/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700579 * qla24xx_reset_chip() - Reset ISP24xx chip.
580 * @ha: HA context
581 *
582 * Returns 0 on success.
583 */
584void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800585qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -0700586{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800587 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700588 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700589
590 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800591 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700592}
593
594/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 * qla2x00_chip_diag() - Test chip for proper operation.
596 * @ha: HA context
597 *
598 * Returns 0 on success.
599 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700600int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800601qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
603 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800604 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700605 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 unsigned long flags = 0;
607 uint16_t data;
608 uint32_t cnt;
609 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800610 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
612 /* Assume a failed state */
613 rval = QLA_FUNCTION_FAILED;
614
615 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800616 vha->host_no, (u_long)&reg->flash_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
618 spin_lock_irqsave(&ha->hardware_lock, flags);
619
620 /* Reset ISP chip. */
621 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
622
623 /*
624 * We need to have a delay here since the card will not respond while
625 * in reset causing an MCA on some architectures.
626 */
627 udelay(20);
628 data = qla2x00_debounce_register(&reg->ctrl_status);
629 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
630 udelay(5);
631 data = RD_REG_WORD(&reg->ctrl_status);
632 barrier();
633 }
634
635 if (!cnt)
636 goto chip_diag_failed;
637
638 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
639 ha->host_no));
640
641 /* Reset RISC processor. */
642 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
643 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
644
645 /* Workaround for QLA2312 PCI parity error */
646 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
647 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
648 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
649 udelay(5);
650 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700651 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 }
653 } else
654 udelay(10);
655
656 if (!cnt)
657 goto chip_diag_failed;
658
659 /* Check product ID of chip */
660 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
661
662 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
663 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
664 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
665 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
666 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
667 mb[3] != PROD_ID_3) {
668 qla_printk(KERN_WARNING, ha,
669 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
670
671 goto chip_diag_failed;
672 }
673 ha->product_id[0] = mb[1];
674 ha->product_id[1] = mb[2];
675 ha->product_id[2] = mb[3];
676 ha->product_id[3] = mb[4];
677
678 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800679 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
681 else
682 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800683 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684
685 if (IS_QLA2200(ha) &&
686 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
687 /* Limit firmware transfer size with a 2200A */
688 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800689 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -0800691 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 ha->fw_transfer_size = 128;
693 }
694
695 /* Wrap Incoming Mailboxes Test. */
696 spin_unlock_irqrestore(&ha->hardware_lock, flags);
697
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800698 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
699 rval = qla2x00_mbx_reg_test(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 if (rval) {
701 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800702 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 qla_printk(KERN_WARNING, ha,
704 "Failed mailbox send register test\n");
705 }
706 else {
707 /* Flag a successful rval */
708 rval = QLA_SUCCESS;
709 }
710 spin_lock_irqsave(&ha->hardware_lock, flags);
711
712chip_diag_failed:
713 if (rval)
714 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800715 "****\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
717 spin_unlock_irqrestore(&ha->hardware_lock, flags);
718
719 return (rval);
720}
721
722/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700723 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
724 * @ha: HA context
725 *
726 * Returns 0 on success.
727 */
728int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800729qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700730{
731 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800732 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800733 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700734
Andrew Vasquez88c26662005-07-08 17:59:26 -0700735 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800736 qla24xx_reset_risc(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700737
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800738 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700739
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800740 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700741 if (rval) {
742 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800743 vha->host_no));
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700744 qla_printk(KERN_WARNING, ha,
745 "Failed mailbox send register test\n");
746 } else {
747 /* Flag a successful rval */
748 rval = QLA_SUCCESS;
749 }
750
751 return rval;
752}
753
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700754void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800755qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700756{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700757 int rval;
758 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800759 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800760 dma_addr_t tc_dma;
761 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800762 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800763 struct req_que *req = ha->req_q_map[0];
764 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700765
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700766 if (ha->fw_dump) {
767 qla_printk(KERN_WARNING, ha,
768 "Firmware dump previously allocated.\n");
769 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700770 }
771
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700772 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800773 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700774 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
775 fixed_size = sizeof(struct qla2100_fw_dump);
776 } else if (IS_QLA23XX(ha)) {
777 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
778 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
779 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -0700780 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800781 if (IS_QLA81XX(ha))
782 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
783 else if (IS_QLA25XX(ha))
784 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
785 else
786 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700787 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
788 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800789 if (ha->mqenable)
790 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700791
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700792 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800793 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700794 goto try_eft;
795
796 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
797 GFP_KERNEL);
798 if (!tc) {
799 qla_printk(KERN_WARNING, ha, "Unable to allocate "
800 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800801 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700802 }
803
804 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800805 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700806 ha->fce_mb, &ha->fce_bufs);
807 if (rval) {
808 qla_printk(KERN_WARNING, ha, "Unable to initialize "
809 "FCE (%d).\n", rval);
810 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
811 tc_dma);
812 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800813 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700814 }
815
816 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
817 FCE_SIZE / 1024);
818
819 fce_size = sizeof(struct qla2xxx_fce_chain) + EFT_SIZE;
820 ha->flags.fce_enabled = 1;
821 ha->fce_dma = tc_dma;
822 ha->fce = tc;
823try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700824 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800825 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700826 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800827 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700828 qla_printk(KERN_WARNING, ha, "Unable to allocate "
829 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
830 goto cont_alloc;
831 }
832
Andrew Vasquezfc447652008-01-17 09:02:18 -0800833 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800834 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700835 if (rval) {
836 qla_printk(KERN_WARNING, ha, "Unable to initialize "
837 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800838 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
839 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700840 goto cont_alloc;
841 }
842
843 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
844 EFT_SIZE / 1024);
845
846 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800847 ha->eft_dma = tc_dma;
848 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700849 }
850cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800851 req_q_size = req->length * sizeof(request_t);
852 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700853
854 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
855 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
Andrew Vasquezbb99de62009-01-05 11:18:08 -0800856 eft_size;
857 ha->chain_offset = dump_size;
858 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700859
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700860 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700861 if (!ha->fw_dump) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700862 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700863 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700864
865 if (ha->eft) {
866 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
867 ha->eft_dma);
868 ha->eft = NULL;
869 ha->eft_dma = 0;
870 }
871 return;
872 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700873 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
874 dump_size / 1024);
875
876 ha->fw_dump_len = dump_size;
877 ha->fw_dump->signature[0] = 'Q';
878 ha->fw_dump->signature[1] = 'L';
879 ha->fw_dump->signature[2] = 'G';
880 ha->fw_dump->signature[3] = 'C';
881 ha->fw_dump->version = __constant_htonl(1);
882
883 ha->fw_dump->fixed_size = htonl(fixed_size);
884 ha->fw_dump->mem_size = htonl(mem_size);
885 ha->fw_dump->req_q_size = htonl(req_q_size);
886 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
887
888 ha->fw_dump->eft_size = htonl(eft_size);
889 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
890 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
891
892 ha->fw_dump->header_size =
893 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700894}
895
896/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
898 * @ha: HA context
899 *
900 * Returns 0 on success.
901 */
902static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800903qla2x00_resize_request_q(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904{
905 int rval;
906 uint16_t fw_iocb_cnt = 0;
907 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
908 dma_addr_t request_dma;
909 request_t *request_ring;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800910 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800911 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
913 /* Valid only on recent ISPs. */
914 if (IS_QLA2100(ha) || IS_QLA2200(ha))
915 return;
916
917 /* Retrieve IOCB counts available to the firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800918 rval = qla2x00_get_resource_cnts(vha, NULL, NULL, NULL, &fw_iocb_cnt,
919 &ha->max_npiv_vports);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 if (rval)
921 return;
922 /* No point in continuing if current settings are sufficient. */
923 if (fw_iocb_cnt < 1024)
924 return;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800925 if (req->length >= request_q_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 return;
927
928 /* Attempt to claim larger area for request queue. */
929 request_ring = dma_alloc_coherent(&ha->pdev->dev,
930 (request_q_length + 1) * sizeof(request_t), &request_dma,
931 GFP_KERNEL);
932 if (request_ring == NULL)
933 return;
934
935 /* Resize successful, report extensions. */
936 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
937 (ha->fw_memory_size + 1) / 1024);
938 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800939 "(%d -> %d)...\n", req->length, request_q_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
941 /* Clear old allocations. */
942 dma_free_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800943 (req->length + 1) * sizeof(request_t), req->ring,
944 req->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
946 /* Begin using larger queue. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800947 req->length = request_q_length;
948 req->ring = request_ring;
949 req->dma = request_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950}
951
952/**
953 * qla2x00_setup_chip() - Load and start RISC firmware.
954 * @ha: HA context
955 *
956 * Returns 0 on success.
957 */
958static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800959qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960{
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700961 int rval;
962 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800963 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -0800964 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
965 unsigned long flags;
966
967 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
968 /* Disable SRAM, Instruction RAM and GP RAM parity. */
969 spin_lock_irqsave(&ha->hardware_lock, flags);
970 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
971 RD_REG_WORD(&reg->hccr);
972 spin_unlock_irqrestore(&ha->hardware_lock, flags);
973 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
975 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800976 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700977 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800979 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800981 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 if (rval == QLA_SUCCESS) {
983 /* Start firmware execution. */
984 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800985 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800987 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 /* Retrieve firmware information. */
989 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800990 qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 &ha->fw_major_version,
992 &ha->fw_minor_version,
993 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800994 &ha->fw_attributes, &ha->fw_memory_size,
995 ha->mpi_version, &ha->mpi_capabilities);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700996 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800997 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -0700998 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700999 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001000 if ((!ha->max_npiv_vports) ||
1001 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001002 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001003 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001004 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001005 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001006 qla2x00_resize_request_q(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001007
1008 if (ql2xallocfwdump)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001009 qla2x00_alloc_fw_dump(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 }
1011 } else {
1012 DEBUG2(printk(KERN_INFO
1013 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001014 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 }
1016 }
1017
Andrew Vasquez3db06522008-01-31 12:33:49 -08001018 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1019 /* Enable proper parity. */
1020 spin_lock_irqsave(&ha->hardware_lock, flags);
1021 if (IS_QLA2300(ha))
1022 /* SRAM parity */
1023 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1024 else
1025 /* SRAM, Instruction RAM and GP RAM parity */
1026 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1027 RD_REG_WORD(&reg->hccr);
1028 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1029 }
1030
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 if (rval) {
1032 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001033 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 }
1035
1036 return (rval);
1037}
1038
1039/**
1040 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1041 * @ha: HA context
1042 *
1043 * Beginning of request ring has initialization control block already built
1044 * by nvram config routine.
1045 *
1046 * Returns 0 on success.
1047 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001048void
1049qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050{
1051 uint16_t cnt;
1052 response_t *pkt;
1053
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001054 pkt = rsp->ring_ptr;
1055 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 pkt->signature = RESPONSE_PROCESSED;
1057 pkt++;
1058 }
1059
1060}
1061
1062/**
1063 * qla2x00_update_fw_options() - Read and process firmware options.
1064 * @ha: HA context
1065 *
1066 * Returns 0 on success.
1067 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001068void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001069qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070{
1071 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001072 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073
1074 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001075 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076
1077 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1078 return;
1079
1080 /* Serial Link options. */
1081 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001082 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1084 sizeof(ha->fw_seriallink_options)));
1085
1086 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1087 if (ha->fw_seriallink_options[3] & BIT_2) {
1088 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1089
1090 /* 1G settings */
1091 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1092 emphasis = (ha->fw_seriallink_options[2] &
1093 (BIT_4 | BIT_3)) >> 3;
1094 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001095 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 rx_sens = (ha->fw_seriallink_options[0] &
1097 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1098 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1099 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1100 if (rx_sens == 0x0)
1101 rx_sens = 0x3;
1102 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1103 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1104 ha->fw_options[10] |= BIT_5 |
1105 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1106 (tx_sens & (BIT_1 | BIT_0));
1107
1108 /* 2G settings */
1109 swing = (ha->fw_seriallink_options[2] &
1110 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1111 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1112 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001113 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 rx_sens = (ha->fw_seriallink_options[1] &
1115 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1116 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1117 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1118 if (rx_sens == 0x0)
1119 rx_sens = 0x3;
1120 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1121 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1122 ha->fw_options[11] |= BIT_5 |
1123 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1124 (tx_sens & (BIT_1 | BIT_0));
1125 }
1126
1127 /* FCP2 options. */
1128 /* Return command IOCBs without waiting for an ABTS to complete. */
1129 ha->fw_options[3] |= BIT_13;
1130
1131 /* LED scheme. */
1132 if (ha->flags.enable_led_scheme)
1133 ha->fw_options[2] |= BIT_12;
1134
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001135 /* Detect ISP6312. */
1136 if (IS_QLA6312(ha))
1137 ha->fw_options[2] |= BIT_13;
1138
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001140 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141}
1142
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001143void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001144qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001145{
1146 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001147 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001148
1149 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001150 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001151 return;
1152
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001153 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001154 le16_to_cpu(ha->fw_seriallink_options24[1]),
1155 le16_to_cpu(ha->fw_seriallink_options24[2]),
1156 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001157 if (rval != QLA_SUCCESS) {
1158 qla_printk(KERN_WARNING, ha,
1159 "Unable to update Serial Link options (%x).\n", rval);
1160 }
1161}
1162
1163void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001164qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001165{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001166 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001167 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001168 struct req_que *req = ha->req_q_map[0];
1169 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001170
1171 /* Setup ring parameters in initialization control block. */
1172 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1173 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001174 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1175 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1176 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1177 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1178 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1179 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001180
1181 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1182 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1183 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1184 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1185 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1186}
1187
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001188void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001189qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001190{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001191 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001192 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1193 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1194 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001195 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001196 uint16_t rid = 0;
1197 struct req_que *req = ha->req_q_map[0];
1198 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001199
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001200/* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001201 icb = (struct init_cb_24xx *)ha->init_cb;
1202 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1203 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001204 icb->request_q_length = cpu_to_le16(req->length);
1205 icb->response_q_length = cpu_to_le16(rsp->length);
1206 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1207 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1208 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1209 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001210
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001211 if (ha->mqenable) {
1212 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1213 icb->rid = __constant_cpu_to_le16(rid);
1214 if (ha->flags.msix_enabled) {
1215 msix = &ha->msix_entries[1];
1216 DEBUG2_17(printk(KERN_INFO
1217 "Reistering vector 0x%x for base que\n", msix->entry));
1218 icb->msix = cpu_to_le16(msix->entry);
1219 }
1220 /* Use alternate PCI bus number */
1221 if (MSB(rid))
1222 icb->firmware_options_2 |=
1223 __constant_cpu_to_le32(BIT_19);
1224 /* Use alternate PCI devfn */
1225 if (LSB(rid))
1226 icb->firmware_options_2 |=
1227 __constant_cpu_to_le32(BIT_18);
1228
1229 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22);
1230 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
1231 ha->rsp_q_map[0]->options = icb->firmware_options_2;
1232
1233 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1234 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1235 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1236 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1237 } else {
1238 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1239 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1240 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1241 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1242 }
1243 /* PCI posting */
1244 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001245}
1246
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247/**
1248 * qla2x00_init_rings() - Initializes firmware.
1249 * @ha: HA context
1250 *
1251 * Beginning of request ring has initialization control block already built
1252 * by nvram config routine.
1253 *
1254 * Returns 0 on success.
1255 */
1256static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001257qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258{
1259 int rval;
1260 unsigned long flags = 0;
1261 int cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001262 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001263 struct req_que *req = ha->req_q_map[0];
1264 struct rsp_que *rsp = ha->rsp_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001265 struct mid_init_cb_24xx *mid_init_cb =
1266 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
1268 spin_lock_irqsave(&ha->hardware_lock, flags);
1269
1270 /* Clear outstanding commands array. */
1271 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001272 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001274 req->current_outstanding_cmd = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
1276 /* Clear RSCN queue. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001277 vha->rscn_in_ptr = 0;
1278 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
1280 /* Initialize firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001281 req->ring_ptr = req->ring;
1282 req->ring_index = 0;
1283 req->cnt = req->length;
1284 rsp->ring_ptr = rsp->ring;
1285 rsp->ring_index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 /* Initialize response queue entries */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001288 qla2x00_init_response_q_entries(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001290 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
1292 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1293
1294 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001295 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001297 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001298
Seokmann Juc48339d2008-01-17 09:02:19 -08001299 if (ha->flags.npiv_supported)
1300 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
1301
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001302 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001303
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001304 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 if (rval) {
1306 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001307 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 } else {
1309 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001310 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 }
1312
1313 return (rval);
1314}
1315
1316/**
1317 * qla2x00_fw_ready() - Waits for firmware ready.
1318 * @ha: HA context
1319 *
1320 * Returns 0 on success.
1321 */
1322static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001323qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324{
1325 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001326 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 uint16_t min_wait; /* Minimum wait time if loop is down */
1328 uint16_t wait_time; /* Wait time if loop is coming ready */
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001329 uint16_t state[3];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001330 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
1332 rval = QLA_SUCCESS;
1333
1334 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001335 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
1337 /*
1338 * Firmware should take at most one RATOV to login, plus 5 seconds for
1339 * our own processing.
1340 */
1341 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1342 wait_time = min_wait;
1343 }
1344
1345 /* Min wait time if loop down */
1346 mtime = jiffies + (min_wait * HZ);
1347
1348 /* wait time before firmware ready */
1349 wtime = jiffies + (wait_time * HZ);
1350
1351 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001352 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1354
1355 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001356 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
1358 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001359 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001361 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001362 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001364 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1365 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001366 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001367 state[2]));
1368 if ((state[2] & FSTATE_LOGGED_IN) &&
1369 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1370 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001371 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001372
1373 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001374 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001375 if (rval != QLA_SUCCESS)
1376 break;
1377
1378 /* Add time taken to initialize. */
1379 cs84xx_time = jiffies - cs84xx_time;
1380 wtime += cs84xx_time;
1381 mtime += cs84xx_time;
1382 DEBUG16(printk("scsi(%ld): Increasing "
1383 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001384 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001385 }
1386 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001388 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001390 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 &ha->login_timeout, &ha->r_a_tov);
1392
1393 rval = QLA_SUCCESS;
1394 break;
1395 }
1396
1397 rval = QLA_FUNCTION_FAILED;
1398
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001399 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001400 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001402 * other than Wait for Login.
1403 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 if (time_after_eq(jiffies, mtime)) {
1405 qla_printk(KERN_INFO, ha,
1406 "Cable is unplugged...\n");
1407
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001408 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 break;
1410 }
1411 }
1412 } else {
1413 /* Mailbox cmd failed. Timeout on min_wait. */
1414 if (time_after_eq(jiffies, mtime))
1415 break;
1416 }
1417
1418 if (time_after_eq(jiffies, wtime))
1419 break;
1420
1421 /* Delay for a while */
1422 msleep(500);
1423
1424 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001425 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 } while (1);
1427
1428 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001429 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
1431 if (rval) {
1432 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001433 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 }
1435
1436 return (rval);
1437}
1438
1439/*
1440* qla2x00_configure_hba
1441* Setup adapter context.
1442*
1443* Input:
1444* ha = adapter state pointer.
1445*
1446* Returns:
1447* 0 = success
1448*
1449* Context:
1450* Kernel context.
1451*/
1452static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001453qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454{
1455 int rval;
1456 uint16_t loop_id;
1457 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001458 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 uint8_t al_pa;
1460 uint8_t area;
1461 uint8_t domain;
1462 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001463 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
1465 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001466 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001467 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001469 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001470 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1471 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001472 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08001473 } else {
1474 qla_printk(KERN_WARNING, ha,
1475 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001476 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08001477 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 return (rval);
1479 }
1480
1481 if (topo == 4) {
1482 qla_printk(KERN_INFO, ha,
1483 "Cannot get topology - retrying.\n");
1484 return (QLA_FUNCTION_FAILED);
1485 }
1486
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001487 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
1489 /* initialize */
1490 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1491 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001492 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493
1494 switch (topo) {
1495 case 0:
1496 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001497 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 ha->current_topology = ISP_CFG_NL;
1499 strcpy(connect_type, "(Loop)");
1500 break;
1501
1502 case 1:
1503 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001504 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001505 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 ha->current_topology = ISP_CFG_FL;
1507 strcpy(connect_type, "(FL_Port)");
1508 break;
1509
1510 case 2:
1511 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001512 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 ha->operating_mode = P2P;
1514 ha->current_topology = ISP_CFG_N;
1515 strcpy(connect_type, "(N_Port-to-N_Port)");
1516 break;
1517
1518 case 3:
1519 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001520 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001521 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 ha->operating_mode = P2P;
1523 ha->current_topology = ISP_CFG_F;
1524 strcpy(connect_type, "(F_Port)");
1525 break;
1526
1527 default:
1528 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1529 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001530 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 ha->current_topology = ISP_CFG_NL;
1532 strcpy(connect_type, "(Loop)");
1533 break;
1534 }
1535
1536 /* Save Host port and loop ID. */
1537 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001538 vha->d_id.b.domain = domain;
1539 vha->d_id.b.area = area;
1540 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001542 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 qla_printk(KERN_INFO, ha,
1544 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001545 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546
1547 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001548 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001550 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 }
1552
1553 return(rval);
1554}
1555
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001556static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001557qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1558 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001559{
1560 char *st, *en;
1561 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001562 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001563
1564 if (memcmp(model, BINZERO, len) != 0) {
1565 strncpy(ha->model_number, model, len);
1566 st = en = ha->model_number;
1567 en += len - 1;
1568 while (en > st) {
1569 if (*en != 0x20 && *en != 0x00)
1570 break;
1571 *en-- = '\0';
1572 }
1573
1574 index = (ha->pdev->subsystem_device & 0xff);
1575 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1576 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001577 strncpy(ha->model_desc,
1578 qla2x00_model_name[index * 2 + 1],
1579 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001580 } else {
1581 index = (ha->pdev->subsystem_device & 0xff);
1582 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1583 index < QLA_MODEL_NAMES) {
1584 strcpy(ha->model_number,
1585 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001586 strncpy(ha->model_desc,
1587 qla2x00_model_name[index * 2 + 1],
1588 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001589 } else {
1590 strcpy(ha->model_number, def);
1591 }
1592 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001593 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001594 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001595 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001596}
1597
David Miller4e08df32007-04-16 12:37:43 -07001598/* On sparc systems, obtain port and node WWN from firmware
1599 * properties.
1600 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001601static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07001602{
1603#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001604 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07001605 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07001606 struct device_node *dp = pci_device_to_OF_node(pdev);
1607 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07001608 int len;
1609
1610 val = of_get_property(dp, "port-wwn", &len);
1611 if (val && len >= WWN_SIZE)
1612 memcpy(nv->port_name, val, WWN_SIZE);
1613
1614 val = of_get_property(dp, "node-wwn", &len);
1615 if (val && len >= WWN_SIZE)
1616 memcpy(nv->node_name, val, WWN_SIZE);
1617#endif
1618}
1619
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620/*
1621* NVRAM configuration for ISP 2xxx
1622*
1623* Input:
1624* ha = adapter block pointer.
1625*
1626* Output:
1627* initialization control block in response_ring
1628* host adapters parameters in host adapter block
1629*
1630* Returns:
1631* 0 = success.
1632*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001633int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001634qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635{
David Miller4e08df32007-04-16 12:37:43 -07001636 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001637 uint8_t chksum = 0;
1638 uint16_t cnt;
1639 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001640 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001641 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07001642 nvram_t *nv = ha->nvram;
1643 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001644 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645
David Miller4e08df32007-04-16 12:37:43 -07001646 rval = QLA_SUCCESS;
1647
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001649 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 ha->nvram_base = 0;
1651 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1652 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
1653 ha->nvram_base = 0x80;
1654
1655 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001656 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001657 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1658 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001660 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07001661 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662
1663 /* Bad NVRAM data, set defaults parameters. */
1664 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1665 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1666 /* Reset NVRAM data. */
1667 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1668 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1669 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07001670 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1671 "invalid -- WWPN) defaults.\n");
1672
1673 /*
1674 * Set default initialization control block.
1675 */
1676 memset(nv, 0, ha->nvram_size);
1677 nv->parameter_block_version = ICB_VERSION;
1678
1679 if (IS_QLA23XX(ha)) {
1680 nv->firmware_options[0] = BIT_2 | BIT_1;
1681 nv->firmware_options[1] = BIT_7 | BIT_5;
1682 nv->add_firmware_options[0] = BIT_5;
1683 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1684 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1685 nv->special_options[1] = BIT_7;
1686 } else if (IS_QLA2200(ha)) {
1687 nv->firmware_options[0] = BIT_2 | BIT_1;
1688 nv->firmware_options[1] = BIT_7 | BIT_5;
1689 nv->add_firmware_options[0] = BIT_5;
1690 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1691 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1692 } else if (IS_QLA2100(ha)) {
1693 nv->firmware_options[0] = BIT_3 | BIT_1;
1694 nv->firmware_options[1] = BIT_5;
1695 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1696 }
1697
1698 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1699 nv->execution_throttle = __constant_cpu_to_le16(16);
1700 nv->retry_count = 8;
1701 nv->retry_delay = 1;
1702
1703 nv->port_name[0] = 33;
1704 nv->port_name[3] = 224;
1705 nv->port_name[4] = 139;
1706
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001707 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07001708
1709 nv->login_timeout = 4;
1710
1711 /*
1712 * Set default host adapter parameters
1713 */
1714 nv->host_p[1] = BIT_2;
1715 nv->reset_delay = 5;
1716 nv->port_down_retry_count = 8;
1717 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1718 nv->link_down_timeout = 60;
1719
1720 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 }
1722
1723#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1724 /*
1725 * The SN2 does not provide BIOS emulation which means you can't change
1726 * potentially bogus BIOS settings. Force the use of default settings
1727 * for link rate and frame size. Hope that the rest of the settings
1728 * are valid.
1729 */
1730 if (ia64_platform_is("sn2")) {
1731 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1732 if (IS_QLA23XX(ha))
1733 nv->special_options[1] = BIT_7;
1734 }
1735#endif
1736
1737 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001738 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739
1740 /*
1741 * Setup driver NVRAM options.
1742 */
1743 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1744 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1745 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1746 nv->firmware_options[1] &= ~BIT_4;
1747
1748 if (IS_QLA23XX(ha)) {
1749 nv->firmware_options[0] |= BIT_2;
1750 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001751 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752
1753 if (IS_QLA2300(ha)) {
1754 if (ha->fb_rev == FPM_2310) {
1755 strcpy(ha->model_number, "QLA2310");
1756 } else {
1757 strcpy(ha->model_number, "QLA2300");
1758 }
1759 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001760 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001761 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 }
1763 } else if (IS_QLA2200(ha)) {
1764 nv->firmware_options[0] |= BIT_2;
1765 /*
1766 * 'Point-to-point preferred, else loop' is not a safe
1767 * connection mode setting.
1768 */
1769 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1770 (BIT_5 | BIT_4)) {
1771 /* Force 'loop preferred, else point-to-point'. */
1772 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1773 nv->add_firmware_options[0] |= BIT_5;
1774 }
1775 strcpy(ha->model_number, "QLA22xx");
1776 } else /*if (IS_QLA2100(ha))*/ {
1777 strcpy(ha->model_number, "QLA2100");
1778 }
1779
1780 /*
1781 * Copy over NVRAM RISC parameter block to initialization control block.
1782 */
1783 dptr1 = (uint8_t *)icb;
1784 dptr2 = (uint8_t *)&nv->parameter_block_version;
1785 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1786 while (cnt--)
1787 *dptr1++ = *dptr2++;
1788
1789 /* Copy 2nd half. */
1790 dptr1 = (uint8_t *)icb->add_firmware_options;
1791 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1792 while (cnt--)
1793 *dptr1++ = *dptr2++;
1794
Andrew Vasquez5341e862006-05-17 15:09:16 -07001795 /* Use alternate WWN? */
1796 if (nv->host_p[1] & BIT_7) {
1797 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1798 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1799 }
1800
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 /* Prepare nodename */
1802 if ((icb->firmware_options[1] & BIT_6) == 0) {
1803 /*
1804 * Firmware will apply the following mask if the nodename was
1805 * not provided.
1806 */
1807 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1808 icb->node_name[0] &= 0xF0;
1809 }
1810
1811 /*
1812 * Set host adapter parameters.
1813 */
Andrew Vasquez01819442006-06-23 16:11:10 -07001814 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07001815 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1817 /* Always load RISC code on non ISP2[12]00 chips. */
1818 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1819 ha->flags.disable_risc_code_load = 0;
1820 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1821 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1822 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07001823 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001824 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825
1826 ha->operating_mode =
1827 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1828
1829 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1830 sizeof(ha->fw_seriallink_options));
1831
1832 /* save HBA serial number */
1833 ha->serial0 = icb->port_name[5];
1834 ha->serial1 = icb->port_name[6];
1835 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001836 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
1837 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838
1839 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1840
1841 ha->retry_count = nv->retry_count;
1842
1843 /* Set minimum login_timeout to 4 seconds. */
1844 if (nv->login_timeout < ql2xlogintimeout)
1845 nv->login_timeout = ql2xlogintimeout;
1846 if (nv->login_timeout < 4)
1847 nv->login_timeout = 4;
1848 ha->login_timeout = nv->login_timeout;
1849 icb->login_timeout = nv->login_timeout;
1850
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001851 /* Set minimum RATOV to 100 tenths of a second. */
1852 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 ha->loop_reset_delay = nv->reset_delay;
1855
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 /* Link Down Timeout = 0:
1857 *
1858 * When Port Down timer expires we will start returning
1859 * I/O's to OS with "DID_NO_CONNECT".
1860 *
1861 * Link Down Timeout != 0:
1862 *
1863 * The driver waits for the link to come up after link down
1864 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001865 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 if (nv->link_down_timeout == 0) {
1867 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001868 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 } else {
1870 ha->link_down_timeout = nv->link_down_timeout;
1871 ha->loop_down_abort_time =
1872 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001873 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 /*
1876 * Need enough time to try and get the port back.
1877 */
1878 ha->port_down_retry_count = nv->port_down_retry_count;
1879 if (qlport_down_retry)
1880 ha->port_down_retry_count = qlport_down_retry;
1881 /* Set login_retry_count */
1882 ha->login_retry_count = nv->retry_count;
1883 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1884 ha->port_down_retry_count > 3)
1885 ha->login_retry_count = ha->port_down_retry_count;
1886 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1887 ha->login_retry_count = ha->port_down_retry_count;
1888 if (ql2xloginretrycount)
1889 ha->login_retry_count = ql2xloginretrycount;
1890
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 icb->lun_enables = __constant_cpu_to_le16(0);
1892 icb->command_resource_count = 0;
1893 icb->immediate_notify_resource_count = 0;
1894 icb->timeout = __constant_cpu_to_le16(0);
1895
1896 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1897 /* Enable RIO */
1898 icb->firmware_options[0] &= ~BIT_3;
1899 icb->add_firmware_options[0] &=
1900 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1901 icb->add_firmware_options[0] |= BIT_2;
1902 icb->response_accumulation_timer = 3;
1903 icb->interrupt_delay_timer = 5;
1904
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001905 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001907 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001908 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001909 ha->zio_mode = icb->add_firmware_options[0] &
1910 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1911 ha->zio_timer = icb->interrupt_delay_timer ?
1912 icb->interrupt_delay_timer: 2;
1913 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 icb->add_firmware_options[0] &=
1915 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001916 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001917 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001918 ha->zio_mode = QLA_ZIO_MODE_6;
1919
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001920 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001921 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001922 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001924 "ZIO mode %d enabled; timer delay (%d us).\n",
1925 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001927 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1928 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001929 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 }
1931 }
1932
David Miller4e08df32007-04-16 12:37:43 -07001933 if (rval) {
1934 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001935 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07001936 }
1937 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938}
1939
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001940static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001941qla2x00_rport_del(void *data)
1942{
1943 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001944 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001945
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001946 spin_lock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001947 rport = fcport->drport;
1948 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001949 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001950 if (rport)
1951 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001952}
1953
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954/**
1955 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1956 * @ha: HA context
1957 * @flags: allocation flags
1958 *
1959 * Returns a pointer to the allocated fcport, or NULL, if none available.
1960 */
Adrian Bunk413975a2006-06-30 02:33:06 -07001961static fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001962qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963{
1964 fc_port_t *fcport;
1965
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001966 fcport = kzalloc(sizeof(fc_port_t), flags);
1967 if (!fcport)
1968 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969
1970 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001971 fcport->vha = vha;
1972 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 fcport->port_type = FCT_UNKNOWN;
1974 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1976 fcport->flags = FCF_RLC_SUPPORT;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001977 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001979 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980}
1981
1982/*
1983 * qla2x00_configure_loop
1984 * Updates Fibre Channel Device Database with what is actually on loop.
1985 *
1986 * Input:
1987 * ha = adapter block pointer.
1988 *
1989 * Returns:
1990 * 0 = success.
1991 * 1 = error.
1992 * 2 = database was full and device was not configured.
1993 */
1994static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001995qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996{
1997 int rval;
1998 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001999 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 rval = QLA_SUCCESS;
2001
2002 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002003 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2004 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 if (rval != QLA_SUCCESS) {
2006 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002007 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 return (rval);
2009 }
2010 }
2011
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002012 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002014 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015
2016 /*
2017 * If we have both an RSCN and PORT UPDATE pending then handle them
2018 * both at the same time.
2019 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002020 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2021 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022
2023 /* Determine what we need to do */
2024 if (ha->current_topology == ISP_CFG_FL &&
2025 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2026
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002027 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 set_bit(RSCN_UPDATE, &flags);
2029
2030 } else if (ha->current_topology == ISP_CFG_F &&
2031 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2032
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002033 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 set_bit(RSCN_UPDATE, &flags);
2035 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2036
Andrew Vasquez21333b42006-05-17 15:09:56 -07002037 } else if (ha->current_topology == ISP_CFG_N) {
2038 clear_bit(RSCN_UPDATE, &flags);
2039
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002040 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2042
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002043 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 set_bit(RSCN_UPDATE, &flags);
2045 set_bit(LOCAL_LOOP_UPDATE, &flags);
2046 }
2047
2048 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002049 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002051 else
2052 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 }
2054
2055 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002056 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002058 else
2059 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 }
2061
2062 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002063 if (atomic_read(&vha->loop_down_timer) ||
2064 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 rval = QLA_FUNCTION_FAILED;
2066 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002067 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002069 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 }
2071 }
2072
2073 if (rval) {
2074 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002075 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 } else {
2077 DEBUG3(printk("%s: exiting normally\n", __func__));
2078 }
2079
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002080 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002081 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002083 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002084 if (test_bit(RSCN_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002085 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 }
2087
2088 return (rval);
2089}
2090
2091
2092
2093/*
2094 * qla2x00_configure_local_loop
2095 * Updates Fibre Channel Device Database with local loop devices.
2096 *
2097 * Input:
2098 * ha = adapter block pointer.
2099 *
2100 * Returns:
2101 * 0 = success.
2102 */
2103static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002104qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105{
2106 int rval, rval2;
2107 int found_devs;
2108 int found;
2109 fc_port_t *fcport, *new_fcport;
2110
2111 uint16_t index;
2112 uint16_t entries;
2113 char *id_iter;
2114 uint16_t loop_id;
2115 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002116 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117
2118 found_devs = 0;
2119 new_fcport = NULL;
2120 entries = MAX_FIBRE_DEVICES;
2121
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002122 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2123 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124
2125 /* Get list of logged in devices. */
2126 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002127 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 &entries);
2129 if (rval != QLA_SUCCESS)
2130 goto cleanup_allocation;
2131
2132 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2133 ha->host_no, entries));
2134 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2135 entries * sizeof(struct gid_list_info)));
2136
2137 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002138 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 if (new_fcport == NULL) {
2140 rval = QLA_MEMORY_ALLOC_FAILED;
2141 goto cleanup_allocation;
2142 }
2143 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2144
2145 /*
2146 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2147 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002148 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2150 fcport->port_type != FCT_BROADCAST &&
2151 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2152
2153 DEBUG(printk("scsi(%ld): Marking port lost, "
2154 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002155 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156
2157 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2158 fcport->flags &= ~FCF_FARP_DONE;
2159 }
2160 }
2161
2162 /* Add devices to port list. */
2163 id_iter = (char *)ha->gid_list;
2164 for (index = 0; index < entries; index++) {
2165 domain = ((struct gid_list_info *)id_iter)->domain;
2166 area = ((struct gid_list_info *)id_iter)->area;
2167 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002168 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 loop_id = (uint16_t)
2170 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002171 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 loop_id = le16_to_cpu(
2173 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002174 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175
2176 /* Bypass reserved domain fields. */
2177 if ((domain & 0xf0) == 0xf0)
2178 continue;
2179
2180 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002181 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002182 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 continue;
2184
2185 /* Bypass invalid local loop ID. */
2186 if (loop_id > LAST_LOCAL_LOOP_ID)
2187 continue;
2188
2189 /* Fill in member data. */
2190 new_fcport->d_id.b.domain = domain;
2191 new_fcport->d_id.b.area = area;
2192 new_fcport->d_id.b.al_pa = al_pa;
2193 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002194 new_fcport->vp_idx = vha->vp_idx;
2195 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 if (rval2 != QLA_SUCCESS) {
2197 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2198 "information -- get_port_database=%x, "
2199 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002200 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002201 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002202 vha->host_no));
2203 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 continue;
2205 }
2206
2207 /* Check for matching device in port list. */
2208 found = 0;
2209 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002210 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 if (memcmp(new_fcport->port_name, fcport->port_name,
2212 WWN_SIZE))
2213 continue;
2214
2215 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2216 FCF_PERSISTENT_BOUND);
2217 fcport->loop_id = new_fcport->loop_id;
2218 fcport->port_type = new_fcport->port_type;
2219 fcport->d_id.b24 = new_fcport->d_id.b24;
2220 memcpy(fcport->node_name, new_fcport->node_name,
2221 WWN_SIZE);
2222
2223 found++;
2224 break;
2225 }
2226
2227 if (!found) {
2228 /* New device, add to fcports list. */
2229 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002230 if (vha->vp_idx) {
2231 new_fcport->vha = vha;
2232 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002233 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002234 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235
2236 /* Allocate a new replacement fcport. */
2237 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002238 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 if (new_fcport == NULL) {
2240 rval = QLA_MEMORY_ALLOC_FAILED;
2241 goto cleanup_allocation;
2242 }
2243 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2244 }
2245
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002246 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002247 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002248
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002249 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250
2251 found_devs++;
2252 }
2253
2254cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002255 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256
2257 if (rval != QLA_SUCCESS) {
2258 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002259 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 }
2261
2262 if (found_devs) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002263 vha->device_flags |= DFLG_LOCAL_DEVICES;
2264 vha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 }
2266
2267 return (rval);
2268}
2269
2270static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002271qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002272{
2273#define LS_UNKNOWN 2
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002274 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002275 int rval;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002276 uint16_t mb[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002277 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002278
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002279 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002280 return;
2281
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002282 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2283 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002284 return;
2285
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002286 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002287 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002288 if (rval != QLA_SUCCESS) {
2289 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2290 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002291 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002292 fcport->port_name[2], fcport->port_name[3],
2293 fcport->port_name[4], fcport->port_name[5],
2294 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002295 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002296 } else {
2297 DEBUG2(qla_printk(KERN_INFO, ha,
2298 "iIDMA adjusted to %s GB/s on "
2299 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002300 link_speeds[fcport->fp_speed], fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002301 fcport->port_name[1], fcport->port_name[2],
2302 fcport->port_name[3], fcport->port_name[4],
2303 fcport->port_name[5], fcport->port_name[6],
2304 fcport->port_name[7]));
2305 }
2306}
2307
Adrian Bunk23be3312006-11-24 02:46:01 +01002308static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002309qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002310{
2311 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002312 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002313 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05002314
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002315 if (fcport->drport)
2316 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002317
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002318 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2319 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002320 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2321 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2322 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002323 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002324 if (!rport) {
2325 qla_printk(KERN_WARNING, ha,
2326 "Unable to allocate fc remote port!\n");
2327 return;
2328 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002329 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002330 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002331 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002332
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002333 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002334
2335 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002336 if (fcport->port_type == FCT_INITIATOR)
2337 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2338 if (fcport->port_type == FCT_TARGET)
2339 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002340 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002341}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342
2343/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002344 * qla2x00_update_fcport
2345 * Updates device on list.
2346 *
2347 * Input:
2348 * ha = adapter block pointer.
2349 * fcport = port structure pointer.
2350 *
2351 * Return:
2352 * 0 - Success
2353 * BIT_0 - error
2354 *
2355 * Context:
2356 * Kernel context.
2357 */
2358void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002359qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002360{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002361 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002362
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002363 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002364 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002365 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002366 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002367 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002368 PORT_RETRY_TIME);
2369 fcport->flags &= ~FCF_LOGIN_NEEDED;
2370
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002371 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002372
2373 atomic_set(&fcport->state, FCS_ONLINE);
2374
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002375 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002376}
2377
2378/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 * qla2x00_configure_fabric
2380 * Setup SNS devices with loop ID's.
2381 *
2382 * Input:
2383 * ha = adapter block pointer.
2384 *
2385 * Returns:
2386 * 0 = success.
2387 * BIT_0 = error
2388 */
2389static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002390qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391{
2392 int rval, rval2;
2393 fc_port_t *fcport, *fcptemp;
2394 uint16_t next_loopid;
2395 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002396 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002398 struct qla_hw_data *ha = vha->hw;
2399 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400
2401 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002402 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002403 loop_id = NPH_F_PORT;
2404 else
2405 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002406 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 if (rval != QLA_SUCCESS) {
2408 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002409 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002411 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 return (QLA_SUCCESS);
2413 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002414 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415
2416 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002417 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 if (rval2 == QLA_RSCNS_HANDLED) {
2419 /* No point doing the scan, just continue. */
2420 return (QLA_SUCCESS);
2421 }
2422 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002423 /* FDMI support. */
2424 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002425 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2426 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002427
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002429 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002430 loop_id = NPH_SNS;
2431 else
2432 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002433 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002434 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 if (mb[0] != MBS_COMMAND_COMPLETE) {
2436 DEBUG2(qla_printk(KERN_INFO, ha,
2437 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002438 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 mb[0], mb[1], mb[2], mb[6], mb[7]));
2440 return (QLA_SUCCESS);
2441 }
2442
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002443 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2444 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 /* EMPTY */
2446 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002447 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002449 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 /* EMPTY */
2451 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002452 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002454 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 /* EMPTY */
2456 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002457 "failed.\n", vha->host_no));
2458 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 /* EMPTY */
2460 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002461 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 }
2463 }
2464
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002465 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 if (rval != QLA_SUCCESS)
2467 break;
2468
2469 /*
2470 * Logout all previous fabric devices marked lost, except
2471 * tape devices.
2472 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002473 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2474 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 break;
2476
2477 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2478 continue;
2479
2480 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002481 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002482 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 if (fcport->loop_id != FC_NO_LOOP_ID &&
2484 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2485 fcport->port_type != FCT_INITIATOR &&
2486 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002487 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002488 fcport->loop_id,
2489 fcport->d_id.b.domain,
2490 fcport->d_id.b.area,
2491 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 fcport->loop_id = FC_NO_LOOP_ID;
2493 }
2494 }
2495 }
2496
2497 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002498 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499
2500 /*
2501 * Scan through our port list and login entries that need to be
2502 * logged in.
2503 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002504 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2505 if (atomic_read(&vha->loop_down_timer) ||
2506 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 break;
2508
2509 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2510 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2511 continue;
2512
2513 if (fcport->loop_id == FC_NO_LOOP_ID) {
2514 fcport->loop_id = next_loopid;
Seokmann Jud4486fd62008-04-03 13:13:28 -07002515 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002516 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 if (rval != QLA_SUCCESS) {
2518 /* Ran out of IDs to use */
2519 break;
2520 }
2521 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002523 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 }
2525
2526 /* Exit if out of loop IDs. */
2527 if (rval != QLA_SUCCESS) {
2528 break;
2529 }
2530
2531 /*
2532 * Login and add the new devices to our port list.
2533 */
2534 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002535 if (atomic_read(&vha->loop_down_timer) ||
2536 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 break;
2538
2539 /* Find a new loop ID to use. */
2540 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002541 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 if (rval != QLA_SUCCESS) {
2543 /* Ran out of IDs to use */
2544 break;
2545 }
2546
bdf79622005-04-17 15:06:53 -05002547 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002548 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002549
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002550 if (vha->vp_idx) {
2551 fcport->vha = vha;
2552 fcport->vp_idx = vha->vp_idx;
2553 }
2554 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 }
2556 } while (0);
2557
2558 /* Free all new device structures not processed. */
2559 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2560 list_del(&fcport->list);
2561 kfree(fcport);
2562 }
2563
2564 if (rval) {
2565 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002566 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567 }
2568
2569 return (rval);
2570}
2571
2572
2573/*
2574 * qla2x00_find_all_fabric_devs
2575 *
2576 * Input:
2577 * ha = adapter block pointer.
2578 * dev = database device entry pointer.
2579 *
2580 * Returns:
2581 * 0 = success.
2582 *
2583 * Context:
2584 * Kernel context.
2585 */
2586static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002587qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2588 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589{
2590 int rval;
2591 uint16_t loop_id;
2592 fc_port_t *fcport, *new_fcport, *fcptemp;
2593 int found;
2594
2595 sw_info_t *swl;
2596 int swl_idx;
2597 int first_dev, last_dev;
2598 port_id_t wrap, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002599 struct qla_hw_data *ha = vha->hw;
2600 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601
2602 rval = QLA_SUCCESS;
2603
2604 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07002605 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002606 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 /*EMPTY*/
2608 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002609 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002611 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 kfree(swl);
2613 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002614 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 kfree(swl);
2616 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002617 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 kfree(swl);
2619 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07002620 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002621 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2622 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 }
2624 }
2625 swl_idx = 0;
2626
2627 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002628 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002630 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 return (QLA_MEMORY_ALLOC_FAILED);
2632 }
2633 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 /* Set start port ID scan at adapter ID. */
2635 first_dev = 1;
2636 last_dev = 0;
2637
2638 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002639 loop_id = ha->min_external_loopid;
2640 for (; loop_id <= ha->max_loop_id; loop_id++) {
2641 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 continue;
2643
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002644 if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 break;
2646
2647 if (swl != NULL) {
2648 if (last_dev) {
2649 wrap.b24 = new_fcport->d_id.b24;
2650 } else {
2651 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2652 memcpy(new_fcport->node_name,
2653 swl[swl_idx].node_name, WWN_SIZE);
2654 memcpy(new_fcport->port_name,
2655 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002656 memcpy(new_fcport->fabric_port_name,
2657 swl[swl_idx].fabric_port_name, WWN_SIZE);
2658 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659
2660 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2661 last_dev = 1;
2662 }
2663 swl_idx++;
2664 }
2665 } else {
2666 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002667 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 if (rval != QLA_SUCCESS) {
2669 qla_printk(KERN_WARNING, ha,
2670 "SNS scan failed -- assuming zero-entry "
2671 "result...\n");
2672 list_for_each_entry_safe(fcport, fcptemp,
2673 new_fcports, list) {
2674 list_del(&fcport->list);
2675 kfree(fcport);
2676 }
2677 rval = QLA_SUCCESS;
2678 break;
2679 }
2680 }
2681
2682 /* If wrap on switch device list, exit. */
2683 if (first_dev) {
2684 wrap.b24 = new_fcport->d_id.b24;
2685 first_dev = 0;
2686 } else if (new_fcport->d_id.b24 == wrap.b24) {
2687 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002688 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2690 break;
2691 }
2692
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002693 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002694 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 continue;
2696
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002697 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002698 found = 0;
2699 if (ha->num_vhosts) {
2700 list_for_each_entry(vp, &ha->vp_list, list) {
2701 if (new_fcport->d_id.b24 == vp->d_id.b24) {
2702 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002703 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002704 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002705 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002706 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002707 continue;
2708 }
2709
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002710 /* Bypass if same domain and area of adapter. */
2711 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002712 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002713 ISP_CFG_FL)
2714 continue;
2715
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 /* Bypass reserved domain fields. */
2717 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2718 continue;
2719
2720 /* Locate matching device in database. */
2721 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002722 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723 if (memcmp(new_fcport->port_name, fcport->port_name,
2724 WWN_SIZE))
2725 continue;
2726
2727 found++;
2728
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002729 /* Update port state. */
2730 memcpy(fcport->fabric_port_name,
2731 new_fcport->fabric_port_name, WWN_SIZE);
2732 fcport->fp_speed = new_fcport->fp_speed;
2733
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 /*
2735 * If address the same and state FCS_ONLINE, nothing
2736 * changed.
2737 */
2738 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2739 atomic_read(&fcport->state) == FCS_ONLINE) {
2740 break;
2741 }
2742
2743 /*
2744 * If device was not a fabric device before.
2745 */
2746 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2747 fcport->d_id.b24 = new_fcport->d_id.b24;
2748 fcport->loop_id = FC_NO_LOOP_ID;
2749 fcport->flags |= (FCF_FABRIC_DEVICE |
2750 FCF_LOGIN_NEEDED);
2751 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2752 break;
2753 }
2754
2755 /*
2756 * Port ID changed or device was marked to be updated;
2757 * Log it out if still logged in and mark it for
2758 * relogin later.
2759 */
2760 fcport->d_id.b24 = new_fcport->d_id.b24;
2761 fcport->flags |= FCF_LOGIN_NEEDED;
2762 if (fcport->loop_id != FC_NO_LOOP_ID &&
2763 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2764 fcport->port_type != FCT_INITIATOR &&
2765 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002766 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002767 fcport->d_id.b.domain, fcport->d_id.b.area,
2768 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 fcport->loop_id = FC_NO_LOOP_ID;
2770 }
2771
2772 break;
2773 }
2774
2775 if (found)
2776 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 /* If device was not in our fcports list, then add it. */
2778 list_add_tail(&new_fcport->list, new_fcports);
2779
2780 /* Allocate a new replacement fcport. */
2781 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002782 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002784 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 return (QLA_MEMORY_ALLOC_FAILED);
2786 }
2787 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2788 new_fcport->d_id.b24 = nxt_d_id.b24;
2789 }
2790
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002791 kfree(swl);
2792 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793
2794 if (!list_empty(new_fcports))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002795 vha->device_flags |= DFLG_FABRIC_DEVICES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796
2797 return (rval);
2798}
2799
2800/*
2801 * qla2x00_find_new_loop_id
2802 * Scan through our port list and find a new usable loop ID.
2803 *
2804 * Input:
2805 * ha: adapter state pointer.
2806 * dev: port structure pointer.
2807 *
2808 * Returns:
2809 * qla2x00 local function return status code.
2810 *
2811 * Context:
2812 * Kernel context.
2813 */
Adrian Bunk413975a2006-06-30 02:33:06 -07002814static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002815qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816{
2817 int rval;
2818 int found;
2819 fc_port_t *fcport;
2820 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002821 struct qla_hw_data *ha = vha->hw;
2822 struct scsi_qla_host *vp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823
2824 rval = QLA_SUCCESS;
2825
2826 /* Save starting loop ID. */
2827 first_loop_id = dev->loop_id;
2828
2829 for (;;) {
2830 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002831 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833
2834 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002835 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837
2838 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002839 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840 /* first loop ID. */
2841 dev->loop_id = ha->min_external_loopid;
2842 }
2843
2844 /* Check for loop ID being already in use. */
2845 found = 0;
2846 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002847 list_for_each_entry(vp, &ha->vp_list, list) {
2848 list_for_each_entry(fcport, &vp->vp_fcports, list) {
2849 if (fcport->loop_id == dev->loop_id &&
2850 fcport != dev) {
2851 /* ID possibly in use */
2852 found++;
2853 break;
2854 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002856 if (found)
2857 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 }
2859
2860 /* If not in use then it is free to use. */
2861 if (!found) {
2862 break;
2863 }
2864
2865 /* ID in use. Try next value. */
2866 dev->loop_id++;
2867
2868 /* If wrap around. No free ID to use. */
2869 if (dev->loop_id == first_loop_id) {
2870 dev->loop_id = FC_NO_LOOP_ID;
2871 rval = QLA_FUNCTION_FAILED;
2872 break;
2873 }
2874 }
2875
2876 return (rval);
2877}
2878
2879/*
2880 * qla2x00_device_resync
2881 * Marks devices in the database that needs resynchronization.
2882 *
2883 * Input:
2884 * ha = adapter block pointer.
2885 *
2886 * Context:
2887 * Kernel context.
2888 */
2889static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002890qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891{
2892 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 uint32_t mask;
2894 fc_port_t *fcport;
2895 uint32_t rscn_entry;
2896 uint8_t rscn_out_iter;
2897 uint8_t format;
2898 port_id_t d_id;
2899
2900 rval = QLA_RSCNS_HANDLED;
2901
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002902 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
2903 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002905 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 format = MSB(MSW(rscn_entry));
2907 d_id.b.domain = LSB(MSW(rscn_entry));
2908 d_id.b.area = MSB(LSW(rscn_entry));
2909 d_id.b.al_pa = LSB(LSW(rscn_entry));
2910
2911 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2912 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002913 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 d_id.b.area, d_id.b.al_pa));
2915
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002916 vha->rscn_out_ptr++;
2917 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
2918 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919
2920 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002921 for (rscn_out_iter = vha->rscn_out_ptr;
2922 !vha->flags.rscn_queue_overflow &&
2923 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 rscn_out_iter = (rscn_out_iter ==
2925 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2926
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002927 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 break;
2929
2930 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002931 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932 rscn_out_iter));
2933
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002934 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 }
2936
2937 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002938 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002940 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941
2942 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002943 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 }
2945
2946 switch (format) {
2947 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 mask = 0xffffff;
2949 break;
2950 case 1:
2951 mask = 0xffff00;
2952 break;
2953 case 2:
2954 mask = 0xff0000;
2955 break;
2956 default:
2957 mask = 0x0;
2958 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002959 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 break;
2961 }
2962
2963 rval = QLA_SUCCESS;
2964
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002965 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2967 (fcport->d_id.b24 & mask) != d_id.b24 ||
2968 fcport->port_type == FCT_BROADCAST)
2969 continue;
2970
2971 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2972 if (format != 3 ||
2973 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002974 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002975 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976 }
2977 }
2978 fcport->flags &= ~FCF_FARP_DONE;
2979 }
2980 }
2981 return (rval);
2982}
2983
2984/*
2985 * qla2x00_fabric_dev_login
2986 * Login fabric target device and update FC port database.
2987 *
2988 * Input:
2989 * ha: adapter state pointer.
2990 * fcport: port structure list pointer.
2991 * next_loopid: contains value of a new loop ID that can be used
2992 * by the next login attempt.
2993 *
2994 * Returns:
2995 * qla2x00 local function return status code.
2996 *
2997 * Context:
2998 * Kernel context.
2999 */
3000static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003001qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002 uint16_t *next_loopid)
3003{
3004 int rval;
3005 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003006 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003007 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008
3009 rval = QLA_SUCCESS;
3010 retry = 0;
3011
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003012 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 if (rval == QLA_SUCCESS) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003014 /* Send an ADISC to tape devices.*/
3015 opts = 0;
3016 if (fcport->flags & FCF_TAPE_PRESENT)
3017 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003018 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003020 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003021 fcport->d_id.b.domain, fcport->d_id.b.area,
3022 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003023 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003025 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 }
3027 }
3028
3029 return (rval);
3030}
3031
3032/*
3033 * qla2x00_fabric_login
3034 * Issue fabric login command.
3035 *
3036 * Input:
3037 * ha = adapter block pointer.
3038 * device = pointer to FC device type structure.
3039 *
3040 * Returns:
3041 * 0 - Login successfully
3042 * 1 - Login failed
3043 * 2 - Initiator device
3044 * 3 - Fatal error
3045 */
3046int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003047qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048 uint16_t *next_loopid)
3049{
3050 int rval;
3051 int retry;
3052 uint16_t tmp_loopid;
3053 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003054 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055
3056 retry = 0;
3057 tmp_loopid = 0;
3058
3059 for (;;) {
3060 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3061 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003062 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3064
3065 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003066 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067 fcport->d_id.b.domain, fcport->d_id.b.area,
3068 fcport->d_id.b.al_pa, mb, BIT_0);
3069 if (mb[0] == MBS_PORT_ID_USED) {
3070 /*
3071 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003072 * recommends the driver perform an implicit login with
3073 * the specified ID again. The ID we just used is save
3074 * here so we return with an ID that can be tried by
3075 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 */
3077 retry++;
3078 tmp_loopid = fcport->loop_id;
3079 fcport->loop_id = mb[1];
3080
3081 DEBUG(printk("Fabric Login: port in use - next "
3082 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3083 fcport->loop_id, fcport->d_id.b.domain,
3084 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3085
3086 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3087 /*
3088 * Login succeeded.
3089 */
3090 if (retry) {
3091 /* A retry occurred before. */
3092 *next_loopid = tmp_loopid;
3093 } else {
3094 /*
3095 * No retry occurred before. Just increment the
3096 * ID value for next login.
3097 */
3098 *next_loopid = (fcport->loop_id + 1);
3099 }
3100
3101 if (mb[1] & BIT_0) {
3102 fcport->port_type = FCT_INITIATOR;
3103 } else {
3104 fcport->port_type = FCT_TARGET;
3105 if (mb[1] & BIT_1) {
3106 fcport->flags |= FCF_TAPE_PRESENT;
3107 }
3108 }
3109
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003110 if (mb[10] & BIT_0)
3111 fcport->supported_classes |= FC_COS_CLASS2;
3112 if (mb[10] & BIT_1)
3113 fcport->supported_classes |= FC_COS_CLASS3;
3114
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115 rval = QLA_SUCCESS;
3116 break;
3117 } else if (mb[0] == MBS_LOOP_ID_USED) {
3118 /*
3119 * Loop ID already used, try next loop ID.
3120 */
3121 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003122 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 if (rval != QLA_SUCCESS) {
3124 /* Ran out of loop IDs to use */
3125 break;
3126 }
3127 } else if (mb[0] == MBS_COMMAND_ERROR) {
3128 /*
3129 * Firmware possibly timed out during login. If NO
3130 * retries are left to do then the device is declared
3131 * dead.
3132 */
3133 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003134 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003135 fcport->d_id.b.domain, fcport->d_id.b.area,
3136 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003137 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138
3139 rval = 1;
3140 break;
3141 } else {
3142 /*
3143 * unrecoverable / not handled error
3144 */
3145 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003146 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003147 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148 fcport->d_id.b.domain, fcport->d_id.b.area,
3149 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3150
3151 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003152 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003153 fcport->d_id.b.domain, fcport->d_id.b.area,
3154 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003156 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157
3158 rval = 3;
3159 break;
3160 }
3161 }
3162
3163 return (rval);
3164}
3165
3166/*
3167 * qla2x00_local_device_login
3168 * Issue local device login command.
3169 *
3170 * Input:
3171 * ha = adapter block pointer.
3172 * loop_id = loop id of device to login to.
3173 *
3174 * Returns (Where's the #define!!!!):
3175 * 0 - Login successfully
3176 * 1 - Login failed
3177 * 3 - Fatal error
3178 */
3179int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003180qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181{
3182 int rval;
3183 uint16_t mb[MAILBOX_REGISTER_COUNT];
3184
3185 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003186 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 if (rval == QLA_SUCCESS) {
3188 /* Interrogate mailbox registers for any errors */
3189 if (mb[0] == MBS_COMMAND_ERROR)
3190 rval = 1;
3191 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3192 /* device not in PCB table */
3193 rval = 3;
3194 }
3195
3196 return (rval);
3197}
3198
3199/*
3200 * qla2x00_loop_resync
3201 * Resync with fibre channel devices.
3202 *
3203 * Input:
3204 * ha = adapter block pointer.
3205 *
3206 * Returns:
3207 * 0 = success
3208 */
3209int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003210qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003212 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 uint32_t wait_time;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003214 struct qla_hw_data *ha = vha->hw;
3215 struct req_que *req = ha->req_q_map[0];
3216 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003218 atomic_set(&vha->loop_state, LOOP_UPDATE);
3219 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3220 if (vha->flags.online) {
3221 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3223 wait_time = 256;
3224 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003225 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003227 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003228 qla2x00_marker(vha, req, rsp, 0, 0,
3229 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003230 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231
3232 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003233 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003235 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003237 } while (!atomic_read(&vha->loop_down_timer) &&
3238 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3239 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3240 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242 }
3243
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003244 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003247 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249
3250 return (rval);
3251}
3252
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003254qla2x00_update_fcports(scsi_qla_host_t *vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003255{
3256 fc_port_t *fcport;
3257
3258 /* Go with deferred removal of rport references. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003259 list_for_each_entry(fcport, &vha->vp_fcports, list)
3260 if (fcport && fcport->drport &&
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07003261 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003262 qla2x00_rport_del(fcport);
3263}
3264
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265/*
3266* qla2x00_abort_isp
3267* Resets ISP and aborts all outstanding commands.
3268*
3269* Input:
3270* ha = adapter block pointer.
3271*
3272* Returns:
3273* 0 = success
3274*/
3275int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003276qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003278 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003280 struct qla_hw_data *ha = vha->hw;
3281 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003282 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003284 if (vha->flags.online) {
3285 vha->flags.online = 0;
3286 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07003287 ha->qla_stats.total_isp_aborts++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288
3289 qla_printk(KERN_INFO, ha,
3290 "Performing ISP error recovery - ha= %p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003291 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003293 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3294 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3295 atomic_set(&vha->loop_state, LOOP_DOWN);
3296 qla2x00_mark_all_devices_lost(vha, 0);
3297 list_for_each_entry(vp, &ha->vp_list, list)
3298 qla2x00_mark_all_devices_lost(vp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003300 if (!atomic_read(&vha->loop_down_timer))
3301 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302 LOOP_DOWN_TIME);
3303 }
3304
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305 /* Requeue all commands in outstanding command list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003306 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003308 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003309
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003310 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003312 if (!qla2x00_restart_isp(vha)) {
3313 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003315 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316 /*
3317 * Issue marker command only when we are going
3318 * to start the I/O .
3319 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003320 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 }
3322
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003323 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003325 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003327 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003328 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003329
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003330 if (ha->fce) {
3331 ha->flags.fce_enabled = 1;
3332 memset(ha->fce, 0,
3333 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003334 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003335 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3336 &ha->fce_bufs);
3337 if (rval) {
3338 qla_printk(KERN_WARNING, ha,
3339 "Unable to reinitialize FCE "
3340 "(%d).\n", rval);
3341 ha->flags.fce_enabled = 0;
3342 }
3343 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003344
3345 if (ha->eft) {
3346 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003347 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003348 ha->eft_dma, EFT_NUM_BUFFERS);
3349 if (rval) {
3350 qla_printk(KERN_WARNING, ha,
3351 "Unable to reinitialize EFT "
3352 "(%d).\n", rval);
3353 }
3354 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003356 vha->flags.online = 1;
3357 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358 if (ha->isp_abort_cnt == 0) {
3359 qla_printk(KERN_WARNING, ha,
3360 "ISP error recovery failed - "
3361 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003362 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363 * The next call disables the board
3364 * completely.
3365 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003366 ha->isp_ops->reset_adapter(vha);
3367 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003369 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370 status = 0;
3371 } else { /* schedule another ISP abort */
3372 ha->isp_abort_cnt--;
3373 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003374 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003375 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376 status = 1;
3377 }
3378 } else {
3379 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3380 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3381 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003382 vha->host_no, ha->isp_abort_cnt));
3383 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384 status = 1;
3385 }
3386 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003387
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 }
3389
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003390 if (!status) {
3391 DEBUG(printk(KERN_INFO
3392 "qla2x00_abort_isp(%ld): succeeded.\n",
3393 vha->host_no));
3394 list_for_each_entry(vp, &ha->vp_list, list) {
3395 if (vp->vp_idx)
3396 qla2x00_vp_abort_isp(vp);
3397 }
3398 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399 qla_printk(KERN_INFO, ha,
3400 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003401 }
3402
3403 return(status);
3404}
3405
3406/*
3407* qla2x00_restart_isp
3408* restarts the ISP after a reset
3409*
3410* Input:
3411* ha = adapter block pointer.
3412*
3413* Returns:
3414* 0 = success
3415*/
3416static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003417qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418{
3419 uint8_t status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003421 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003422 struct req_que *req = ha->req_q_map[0];
3423 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424
3425 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003426 if (qla2x00_isp_firmware(vha)) {
3427 vha->flags.online = 0;
3428 status = ha->isp_ops->chip_diag(vha);
3429 if (!status)
3430 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431 }
3432
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003433 if (!status && !(status = qla2x00_init_rings(vha))) {
3434 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003435 /* Initialize the queues in use */
3436 qla25xx_init_queues(ha);
3437
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003438 status = qla2x00_fw_ready(vha);
3439 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003441 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003442
3443 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003444 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003445
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003446 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3448 wait_time = 256;
3449 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003450 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3451 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003453 } while (!atomic_read(&vha->loop_down_timer) &&
3454 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3455 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3456 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 }
3458
3459 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003460 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003461 status = 0;
3462
3463 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3464 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003465 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003466 }
3467 return (status);
3468}
3469
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003470static int
3471qla25xx_init_queues(struct qla_hw_data *ha)
3472{
3473 struct rsp_que *rsp = NULL;
3474 struct req_que *req = NULL;
3475 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3476 int ret = -1;
3477 int i;
3478
3479 for (i = 1; i < ha->max_queues; i++) {
3480 rsp = ha->rsp_q_map[i];
3481 if (rsp) {
3482 rsp->options &= ~BIT_0;
3483 ret = qla25xx_init_rsp_que(base_vha, rsp, rsp->options);
3484 if (ret != QLA_SUCCESS)
3485 DEBUG2_17(printk(KERN_WARNING
3486 "%s Rsp que:%d init failed\n", __func__,
3487 rsp->id));
3488 else
3489 DEBUG2_17(printk(KERN_INFO
3490 "%s Rsp que:%d inited\n", __func__,
3491 rsp->id));
3492 }
3493 req = ha->req_q_map[i];
3494 if (req) {
3495 req->options &= ~BIT_0;
3496 ret = qla25xx_init_req_que(base_vha, req, req->options);
3497 if (ret != QLA_SUCCESS)
3498 DEBUG2_17(printk(KERN_WARNING
3499 "%s Req que:%d init failed\n", __func__,
3500 req->id));
3501 else
3502 DEBUG2_17(printk(KERN_WARNING
3503 "%s Rsp que:%d inited\n", __func__,
3504 req->id));
3505 }
3506 }
3507 return ret;
3508}
3509
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510/*
3511* qla2x00_reset_adapter
3512* Reset adapter.
3513*
3514* Input:
3515* ha = adapter block pointer.
3516*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003517void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003518qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519{
3520 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003521 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003522 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003524 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003525 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527 spin_lock_irqsave(&ha->hardware_lock, flags);
3528 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3529 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3530 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3531 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3532 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3533}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003534
3535void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003536qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003537{
3538 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003539 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003540 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3541
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003542 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003543 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003544
3545 spin_lock_irqsave(&ha->hardware_lock, flags);
3546 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3547 RD_REG_DWORD(&reg->hccr);
3548 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3549 RD_REG_DWORD(&reg->hccr);
3550 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3551}
3552
David Miller4e08df32007-04-16 12:37:43 -07003553/* On sparc systems, obtain port and node WWN from firmware
3554 * properties.
3555 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003556static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3557 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07003558{
3559#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003560 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003561 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003562 struct device_node *dp = pci_device_to_OF_node(pdev);
3563 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003564 int len;
3565
3566 val = of_get_property(dp, "port-wwn", &len);
3567 if (val && len >= WWN_SIZE)
3568 memcpy(nv->port_name, val, WWN_SIZE);
3569
3570 val = of_get_property(dp, "node-wwn", &len);
3571 if (val && len >= WWN_SIZE)
3572 memcpy(nv->node_name, val, WWN_SIZE);
3573#endif
3574}
3575
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003576int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003577qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003578{
David Miller4e08df32007-04-16 12:37:43 -07003579 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003580 struct init_cb_24xx *icb;
3581 struct nvram_24xx *nv;
3582 uint32_t *dptr;
3583 uint8_t *dptr1, *dptr2;
3584 uint32_t chksum;
3585 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003586 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003587
David Miller4e08df32007-04-16 12:37:43 -07003588 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003589 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003590 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003591
3592 /* Determine NVRAM starting address. */
3593 ha->nvram_size = sizeof(struct nvram_24xx);
3594 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003595 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3596 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3597 if (PCI_FUNC(ha->pdev->devfn)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003598 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003599 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3600 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003601
Seokmann Ju281afe12007-07-26 13:43:34 -07003602 /* Get VPD data into cache */
3603 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003604 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07003605 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3606
3607 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003608 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003609 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003610 ha->nvram_size);
3611 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3612 chksum += le32_to_cpu(*dptr++);
3613
3614 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07003615 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003616
3617 /* Bad NVRAM data, set defaults parameters. */
3618 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3619 || nv->id[3] != ' ' ||
3620 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3621 /* Reset NVRAM data. */
3622 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3623 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3624 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07003625 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3626 "invalid -- WWPN) defaults.\n");
3627
3628 /*
3629 * Set default initialization control block.
3630 */
3631 memset(nv, 0, ha->nvram_size);
3632 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3633 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3634 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3635 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3636 nv->exchange_count = __constant_cpu_to_le16(0);
3637 nv->hard_address = __constant_cpu_to_le16(124);
3638 nv->port_name[0] = 0x21;
3639 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3640 nv->port_name[2] = 0x00;
3641 nv->port_name[3] = 0xe0;
3642 nv->port_name[4] = 0x8b;
3643 nv->port_name[5] = 0x1c;
3644 nv->port_name[6] = 0x55;
3645 nv->port_name[7] = 0x86;
3646 nv->node_name[0] = 0x20;
3647 nv->node_name[1] = 0x00;
3648 nv->node_name[2] = 0x00;
3649 nv->node_name[3] = 0xe0;
3650 nv->node_name[4] = 0x8b;
3651 nv->node_name[5] = 0x1c;
3652 nv->node_name[6] = 0x55;
3653 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003654 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07003655 nv->login_retry_count = __constant_cpu_to_le16(8);
3656 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3657 nv->login_timeout = __constant_cpu_to_le16(0);
3658 nv->firmware_options_1 =
3659 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3660 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3661 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3662 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3663 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3664 nv->efi_parameters = __constant_cpu_to_le32(0);
3665 nv->reset_delay = 5;
3666 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3667 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3668 nv->link_down_timeout = __constant_cpu_to_le16(30);
3669
3670 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003671 }
3672
3673 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003674 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003675
3676 /* Copy 1st segment. */
3677 dptr1 = (uint8_t *)icb;
3678 dptr2 = (uint8_t *)&nv->version;
3679 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3680 while (cnt--)
3681 *dptr1++ = *dptr2++;
3682
3683 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07003684 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003685
3686 /* Copy 2nd segment. */
3687 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3688 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3689 cnt = (uint8_t *)&icb->reserved_3 -
3690 (uint8_t *)&icb->interrupt_delay_timer;
3691 while (cnt--)
3692 *dptr1++ = *dptr2++;
3693
3694 /*
3695 * Setup driver NVRAM options.
3696 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003697 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003698 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003699
Andrew Vasquez5341e862006-05-17 15:09:16 -07003700 /* Use alternate WWN? */
3701 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3702 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3703 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3704 }
3705
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003706 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003707 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003708 /*
3709 * Firmware will apply the following mask if the nodename was
3710 * not provided.
3711 */
3712 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3713 icb->node_name[0] &= 0xF0;
3714 }
3715
3716 /* Set host adapter parameters. */
3717 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08003718 ha->flags.enable_lip_reset = 0;
3719 ha->flags.enable_lip_full_login =
3720 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3721 ha->flags.enable_target_reset =
3722 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003723 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07003724 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003725
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003726 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3727 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003728
3729 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3730 sizeof(ha->fw_seriallink_options24));
3731
3732 /* save HBA serial number */
3733 ha->serial0 = icb->port_name[5];
3734 ha->serial1 = icb->port_name[6];
3735 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003736 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
3737 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003738
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08003739 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3740
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003741 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3742
3743 /* Set minimum login_timeout to 4 seconds. */
3744 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3745 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3746 if (le16_to_cpu(nv->login_timeout) < 4)
3747 nv->login_timeout = __constant_cpu_to_le16(4);
3748 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07003749 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003750
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003751 /* Set minimum RATOV to 100 tenths of a second. */
3752 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003753
3754 ha->loop_reset_delay = nv->reset_delay;
3755
3756 /* Link Down Timeout = 0:
3757 *
3758 * When Port Down timer expires we will start returning
3759 * I/O's to OS with "DID_NO_CONNECT".
3760 *
3761 * Link Down Timeout != 0:
3762 *
3763 * The driver waits for the link to come up after link down
3764 * before returning I/Os to OS with "DID_NO_CONNECT".
3765 */
3766 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3767 ha->loop_down_abort_time =
3768 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3769 } else {
3770 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3771 ha->loop_down_abort_time =
3772 (LOOP_DOWN_TIME - ha->link_down_timeout);
3773 }
3774
3775 /* Need enough time to try and get the port back. */
3776 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3777 if (qlport_down_retry)
3778 ha->port_down_retry_count = qlport_down_retry;
3779
3780 /* Set login_retry_count */
3781 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3782 if (ha->port_down_retry_count ==
3783 le16_to_cpu(nv->port_down_retry_count) &&
3784 ha->port_down_retry_count > 3)
3785 ha->login_retry_count = ha->port_down_retry_count;
3786 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3787 ha->login_retry_count = ha->port_down_retry_count;
3788 if (ql2xloginretrycount)
3789 ha->login_retry_count = ql2xloginretrycount;
3790
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003791 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003792 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003793 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3794 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3795 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3796 le16_to_cpu(icb->interrupt_delay_timer): 2;
3797 }
3798 icb->firmware_options_2 &= __constant_cpu_to_le32(
3799 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003800 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003801 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08003802 ha->zio_mode = QLA_ZIO_MODE_6;
3803
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003804 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003805 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003806 ha->zio_timer * 100));
3807 qla_printk(KERN_INFO, ha,
3808 "ZIO mode %d enabled; timer delay (%d us).\n",
3809 ha->zio_mode, ha->zio_timer * 100);
3810
3811 icb->firmware_options_2 |= cpu_to_le32(
3812 (uint32_t)ha->zio_mode);
3813 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003814 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003815 }
3816
David Miller4e08df32007-04-16 12:37:43 -07003817 if (rval) {
3818 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003819 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07003820 }
3821 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003822}
3823
Adrian Bunk413975a2006-06-30 02:33:06 -07003824static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003825qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003826{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003827 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003828 int segments, fragment;
3829 uint32_t faddr;
3830 uint32_t *dcode, dlen;
3831 uint32_t risc_addr;
3832 uint32_t risc_size;
3833 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003834 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003835 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003836 rval = QLA_SUCCESS;
3837
3838 segments = FA_RISC_CODE_SEGMENTS;
Andrew Vasquezc00d8992008-09-11 21:22:49 -07003839 faddr = ha->flt_region_fw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003840 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003841 *srisc_addr = 0;
3842
3843 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003844 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003845 for (i = 0; i < 4; i++)
3846 dcode[i] = be32_to_cpu(dcode[i]);
3847 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3848 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3849 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3850 dcode[3] == 0)) {
3851 qla_printk(KERN_WARNING, ha,
3852 "Unable to verify integrity of flash firmware image!\n");
3853 qla_printk(KERN_WARNING, ha,
3854 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3855 dcode[1], dcode[2], dcode[3]);
3856
3857 return QLA_FUNCTION_FAILED;
3858 }
3859
3860 while (segments && rval == QLA_SUCCESS) {
3861 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003862 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003863
3864 risc_addr = be32_to_cpu(dcode[2]);
3865 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3866 risc_size = be32_to_cpu(dcode[3]);
3867
3868 fragment = 0;
3869 while (risc_size > 0 && rval == QLA_SUCCESS) {
3870 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3871 if (dlen > risc_size)
3872 dlen = risc_size;
3873
3874 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3875 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003876 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003877
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003878 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003879 for (i = 0; i < dlen; i++)
3880 dcode[i] = swab32(dcode[i]);
3881
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003882 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003883 dlen);
3884 if (rval) {
3885 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003886 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003887 fragment));
3888 qla_printk(KERN_WARNING, ha,
3889 "[ERROR] Failed to load segment %d of "
3890 "firmware\n", fragment);
3891 break;
3892 }
3893
3894 faddr += dlen;
3895 risc_addr += dlen;
3896 risc_size -= dlen;
3897 fragment++;
3898 }
3899
3900 /* Next segment. */
3901 segments--;
3902 }
3903
3904 return rval;
3905}
3906
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003907#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3908
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003909int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003910qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08003911{
3912 int rval;
3913 int i, fragment;
3914 uint16_t *wcode, *fwcode;
3915 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3916 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003917 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003918 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08003919
3920 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003921 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08003922 if (!blob) {
3923 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003924 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3925 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08003926 return QLA_FUNCTION_FAILED;
3927 }
3928
3929 rval = QLA_SUCCESS;
3930
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003931 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08003932 *srisc_addr = 0;
3933 fwcode = (uint16_t *)blob->fw->data;
3934 fwclen = 0;
3935
3936 /* Validate firmware image by checking version. */
3937 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3938 qla_printk(KERN_WARNING, ha,
3939 "Unable to verify integrity of firmware image (%Zd)!\n",
3940 blob->fw->size);
3941 goto fail_fw_integrity;
3942 }
3943 for (i = 0; i < 4; i++)
3944 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3945 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3946 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3947 wcode[2] == 0 && wcode[3] == 0)) {
3948 qla_printk(KERN_WARNING, ha,
3949 "Unable to verify integrity of firmware image!\n");
3950 qla_printk(KERN_WARNING, ha,
3951 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3952 wcode[1], wcode[2], wcode[3]);
3953 goto fail_fw_integrity;
3954 }
3955
3956 seg = blob->segs;
3957 while (*seg && rval == QLA_SUCCESS) {
3958 risc_addr = *seg;
3959 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3960 risc_size = be16_to_cpu(fwcode[3]);
3961
3962 /* Validate firmware image size. */
3963 fwclen += risc_size * sizeof(uint16_t);
3964 if (blob->fw->size < fwclen) {
3965 qla_printk(KERN_WARNING, ha,
3966 "Unable to verify integrity of firmware image "
3967 "(%Zd)!\n", blob->fw->size);
3968 goto fail_fw_integrity;
3969 }
3970
3971 fragment = 0;
3972 while (risc_size > 0 && rval == QLA_SUCCESS) {
3973 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3974 if (wlen > risc_size)
3975 wlen = risc_size;
3976
3977 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003978 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08003979 risc_addr, wlen));
3980
3981 for (i = 0; i < wlen; i++)
3982 wcode[i] = swab16(fwcode[i]);
3983
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003984 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08003985 wlen);
3986 if (rval) {
3987 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003988 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08003989 fragment));
3990 qla_printk(KERN_WARNING, ha,
3991 "[ERROR] Failed to load segment %d of "
3992 "firmware\n", fragment);
3993 break;
3994 }
3995
3996 fwcode += wlen;
3997 risc_addr += wlen;
3998 risc_size -= wlen;
3999 fragment++;
4000 }
4001
4002 /* Next segment. */
4003 seg++;
4004 }
4005 return rval;
4006
4007fail_fw_integrity:
4008 return QLA_FUNCTION_FAILED;
4009}
4010
4011int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004012qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004013{
4014 int rval;
4015 int segments, fragment;
4016 uint32_t *dcode, dlen;
4017 uint32_t risc_addr;
4018 uint32_t risc_size;
4019 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004020 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004021 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004022 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004023 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004024
Andrew Vasquez54333832005-11-09 15:49:04 -08004025 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004026 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004027 if (!blob) {
4028 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004029 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4030 "from: " QLA_FW_URL ".\n");
4031
4032 /* Try to load RISC code from flash. */
4033 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
4034 "outdated) firmware from flash.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004035 return qla24xx_load_risc_flash(vha, srisc_addr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004036 }
4037
4038 rval = QLA_SUCCESS;
4039
4040 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004041 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004042 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004043 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004044 fwclen = 0;
4045
4046 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004047 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004048 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004049 "Unable to verify integrity of firmware image (%Zd)!\n",
4050 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004051 goto fail_fw_integrity;
4052 }
4053 for (i = 0; i < 4; i++)
4054 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4055 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4056 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4057 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4058 dcode[3] == 0)) {
4059 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004060 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004061 qla_printk(KERN_WARNING, ha,
4062 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4063 dcode[1], dcode[2], dcode[3]);
4064 goto fail_fw_integrity;
4065 }
4066
4067 while (segments && rval == QLA_SUCCESS) {
4068 risc_addr = be32_to_cpu(fwcode[2]);
4069 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4070 risc_size = be32_to_cpu(fwcode[3]);
4071
4072 /* Validate firmware image size. */
4073 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004074 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004075 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004076 "Unable to verify integrity of firmware image "
4077 "(%Zd)!\n", blob->fw->size);
4078
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004079 goto fail_fw_integrity;
4080 }
4081
4082 fragment = 0;
4083 while (risc_size > 0 && rval == QLA_SUCCESS) {
4084 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4085 if (dlen > risc_size)
4086 dlen = risc_size;
4087
4088 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004089 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004090 risc_addr, dlen));
4091
4092 for (i = 0; i < dlen; i++)
4093 dcode[i] = swab32(fwcode[i]);
4094
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004095 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004096 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004097 if (rval) {
4098 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004099 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004100 fragment));
4101 qla_printk(KERN_WARNING, ha,
4102 "[ERROR] Failed to load segment %d of "
4103 "firmware\n", fragment);
4104 break;
4105 }
4106
4107 fwcode += dlen;
4108 risc_addr += dlen;
4109 risc_size -= dlen;
4110 fragment++;
4111 }
4112
4113 /* Next segment. */
4114 segments--;
4115 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004116 return rval;
4117
4118fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004119 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004120}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004121
4122void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004123qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004124{
4125 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004126 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004127
Andrew Vasqueze4289242007-07-19 15:05:56 -07004128 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004129 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004130 if (!ha->fw_major_version)
4131 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004132
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004133 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004134 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
4135 retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004136 ha->isp_ops->reset_chip(vha);
4137 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004138 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004139 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004140 continue;
4141 qla_printk(KERN_INFO, ha,
4142 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004143 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004144 }
4145}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004146
4147int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004148qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004149{
4150 int rval = QLA_SUCCESS;
4151 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004152 struct qla_hw_data *ha = vha->hw;
4153 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004154 struct req_que *req = ha->req_q_map[0];
4155 struct rsp_que *rsp = ha->rsp_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004156
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004157 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004158 return -EINVAL;
4159
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004160 rval = qla2x00_fw_ready(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004161 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004162 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004163 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004164 }
4165
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004166 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004167
4168 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004169 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004170 if (mb[0] != MBS_COMMAND_COMPLETE) {
4171 DEBUG15(qla_printk(KERN_INFO, ha,
4172 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4173 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4174 mb[0], mb[1], mb[2], mb[6], mb[7]));
4175 return (QLA_FUNCTION_FAILED);
4176 }
4177
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004178 atomic_set(&vha->loop_down_timer, 0);
4179 atomic_set(&vha->loop_state, LOOP_UP);
4180 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4181 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4182 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004183
4184 return rval;
4185}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004186
4187/* 84XX Support **************************************************************/
4188
4189static LIST_HEAD(qla_cs84xx_list);
4190static DEFINE_MUTEX(qla_cs84xx_mutex);
4191
4192static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004193qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004194{
4195 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004196 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004197
4198 mutex_lock(&qla_cs84xx_mutex);
4199
4200 /* Find any shared 84xx chip. */
4201 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4202 if (cs84xx->bus == ha->pdev->bus) {
4203 kref_get(&cs84xx->kref);
4204 goto done;
4205 }
4206 }
4207
4208 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4209 if (!cs84xx)
4210 goto done;
4211
4212 kref_init(&cs84xx->kref);
4213 spin_lock_init(&cs84xx->access_lock);
4214 mutex_init(&cs84xx->fw_update_mutex);
4215 cs84xx->bus = ha->pdev->bus;
4216
4217 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4218done:
4219 mutex_unlock(&qla_cs84xx_mutex);
4220 return cs84xx;
4221}
4222
4223static void
4224__qla84xx_chip_release(struct kref *kref)
4225{
4226 struct qla_chip_state_84xx *cs84xx =
4227 container_of(kref, struct qla_chip_state_84xx, kref);
4228
4229 mutex_lock(&qla_cs84xx_mutex);
4230 list_del(&cs84xx->list);
4231 mutex_unlock(&qla_cs84xx_mutex);
4232 kfree(cs84xx);
4233}
4234
4235void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004236qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004237{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004238 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004239 if (ha->cs84xx)
4240 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4241}
4242
4243static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004244qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004245{
4246 int rval;
4247 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004248 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004249
4250 mutex_lock(&ha->cs84xx->fw_update_mutex);
4251
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004252 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004253
4254 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4255
4256 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4257 QLA_SUCCESS;
4258}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004259
4260/* 81XX Support **************************************************************/
4261
4262int
4263qla81xx_nvram_config(scsi_qla_host_t *vha)
4264{
4265 int rval;
4266 struct init_cb_81xx *icb;
4267 struct nvram_81xx *nv;
4268 uint32_t *dptr;
4269 uint8_t *dptr1, *dptr2;
4270 uint32_t chksum;
4271 uint16_t cnt;
4272 struct qla_hw_data *ha = vha->hw;
4273
4274 rval = QLA_SUCCESS;
4275 icb = (struct init_cb_81xx *)ha->init_cb;
4276 nv = ha->nvram;
4277
4278 /* Determine NVRAM starting address. */
4279 ha->nvram_size = sizeof(struct nvram_81xx);
4280 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4281 ha->vpd_size = FA_NVRAM_VPD_SIZE;
4282 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4283 if (PCI_FUNC(ha->pdev->devfn) & 1) {
4284 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
4285 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4286 }
4287
4288 /* Get VPD data into cache */
4289 ha->vpd = ha->nvram + VPD_OFFSET;
4290 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
4291 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4292
4293 /* Get NVRAM data into cache and calculate checksum. */
4294 dptr = (uint32_t *)nv;
4295 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
4296 ha->nvram_size);
4297 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4298 chksum += le32_to_cpu(*dptr++);
4299
4300 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
4301 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4302
4303 /* Bad NVRAM data, set defaults parameters. */
4304 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4305 || nv->id[3] != ' ' ||
4306 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4307 /* Reset NVRAM data. */
4308 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4309 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4310 le16_to_cpu(nv->nvram_version));
4311 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4312 "invalid -- WWPN) defaults.\n");
4313
4314 /*
4315 * Set default initialization control block.
4316 */
4317 memset(nv, 0, ha->nvram_size);
4318 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4319 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4320 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4321 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4322 nv->exchange_count = __constant_cpu_to_le16(0);
4323 nv->port_name[0] = 0x21;
4324 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
4325 nv->port_name[2] = 0x00;
4326 nv->port_name[3] = 0xe0;
4327 nv->port_name[4] = 0x8b;
4328 nv->port_name[5] = 0x1c;
4329 nv->port_name[6] = 0x55;
4330 nv->port_name[7] = 0x86;
4331 nv->node_name[0] = 0x20;
4332 nv->node_name[1] = 0x00;
4333 nv->node_name[2] = 0x00;
4334 nv->node_name[3] = 0xe0;
4335 nv->node_name[4] = 0x8b;
4336 nv->node_name[5] = 0x1c;
4337 nv->node_name[6] = 0x55;
4338 nv->node_name[7] = 0x86;
4339 nv->login_retry_count = __constant_cpu_to_le16(8);
4340 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4341 nv->login_timeout = __constant_cpu_to_le16(0);
4342 nv->firmware_options_1 =
4343 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4344 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4345 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4346 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4347 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4348 nv->efi_parameters = __constant_cpu_to_le32(0);
4349 nv->reset_delay = 5;
4350 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4351 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4352 nv->link_down_timeout = __constant_cpu_to_le16(30);
4353 nv->enode_mac[0] = 0x01;
4354 nv->enode_mac[1] = 0x02;
4355 nv->enode_mac[2] = 0x03;
4356 nv->enode_mac[3] = 0x04;
4357 nv->enode_mac[4] = 0x05;
4358 nv->enode_mac[5] = 0x06 + PCI_FUNC(ha->pdev->devfn);
4359
4360 rval = 1;
4361 }
4362
4363 /* Reset Initialization control block */
4364 memset(icb, 0, sizeof(struct init_cb_81xx));
4365
4366 /* Copy 1st segment. */
4367 dptr1 = (uint8_t *)icb;
4368 dptr2 = (uint8_t *)&nv->version;
4369 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4370 while (cnt--)
4371 *dptr1++ = *dptr2++;
4372
4373 icb->login_retry_count = nv->login_retry_count;
4374
4375 /* Copy 2nd segment. */
4376 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4377 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4378 cnt = (uint8_t *)&icb->reserved_5 -
4379 (uint8_t *)&icb->interrupt_delay_timer;
4380 while (cnt--)
4381 *dptr1++ = *dptr2++;
4382
4383 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
4384 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4385 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
4386 icb->enode_mac[0] = 0x01;
4387 icb->enode_mac[1] = 0x02;
4388 icb->enode_mac[2] = 0x03;
4389 icb->enode_mac[3] = 0x04;
4390 icb->enode_mac[4] = 0x05;
4391 icb->enode_mac[5] = 0x06 + PCI_FUNC(ha->pdev->devfn);
4392 }
4393
4394 /*
4395 * Setup driver NVRAM options.
4396 */
4397 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
4398 "QLE81XX");
4399
4400 /* Use alternate WWN? */
4401 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4402 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4403 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4404 }
4405
4406 /* Prepare nodename */
4407 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4408 /*
4409 * Firmware will apply the following mask if the nodename was
4410 * not provided.
4411 */
4412 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4413 icb->node_name[0] &= 0xF0;
4414 }
4415
4416 /* Set host adapter parameters. */
4417 ha->flags.disable_risc_code_load = 0;
4418 ha->flags.enable_lip_reset = 0;
4419 ha->flags.enable_lip_full_login =
4420 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4421 ha->flags.enable_target_reset =
4422 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4423 ha->flags.enable_led_scheme = 0;
4424 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4425
4426 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4427 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4428
4429 /* save HBA serial number */
4430 ha->serial0 = icb->port_name[5];
4431 ha->serial1 = icb->port_name[6];
4432 ha->serial2 = icb->port_name[7];
4433 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4434 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4435
4436 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4437
4438 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4439
4440 /* Set minimum login_timeout to 4 seconds. */
4441 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4442 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4443 if (le16_to_cpu(nv->login_timeout) < 4)
4444 nv->login_timeout = __constant_cpu_to_le16(4);
4445 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4446 icb->login_timeout = nv->login_timeout;
4447
4448 /* Set minimum RATOV to 100 tenths of a second. */
4449 ha->r_a_tov = 100;
4450
4451 ha->loop_reset_delay = nv->reset_delay;
4452
4453 /* Link Down Timeout = 0:
4454 *
4455 * When Port Down timer expires we will start returning
4456 * I/O's to OS with "DID_NO_CONNECT".
4457 *
4458 * Link Down Timeout != 0:
4459 *
4460 * The driver waits for the link to come up after link down
4461 * before returning I/Os to OS with "DID_NO_CONNECT".
4462 */
4463 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4464 ha->loop_down_abort_time =
4465 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4466 } else {
4467 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4468 ha->loop_down_abort_time =
4469 (LOOP_DOWN_TIME - ha->link_down_timeout);
4470 }
4471
4472 /* Need enough time to try and get the port back. */
4473 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4474 if (qlport_down_retry)
4475 ha->port_down_retry_count = qlport_down_retry;
4476
4477 /* Set login_retry_count */
4478 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4479 if (ha->port_down_retry_count ==
4480 le16_to_cpu(nv->port_down_retry_count) &&
4481 ha->port_down_retry_count > 3)
4482 ha->login_retry_count = ha->port_down_retry_count;
4483 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4484 ha->login_retry_count = ha->port_down_retry_count;
4485 if (ql2xloginretrycount)
4486 ha->login_retry_count = ql2xloginretrycount;
4487
4488 /* Enable ZIO. */
4489 if (!vha->flags.init_done) {
4490 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4491 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4492 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4493 le16_to_cpu(icb->interrupt_delay_timer): 2;
4494 }
4495 icb->firmware_options_2 &= __constant_cpu_to_le32(
4496 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4497 vha->flags.process_response_queue = 0;
4498 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4499 ha->zio_mode = QLA_ZIO_MODE_6;
4500
4501 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4502 "(%d us).\n", vha->host_no, ha->zio_mode,
4503 ha->zio_timer * 100));
4504 qla_printk(KERN_INFO, ha,
4505 "ZIO mode %d enabled; timer delay (%d us).\n",
4506 ha->zio_mode, ha->zio_timer * 100);
4507
4508 icb->firmware_options_2 |= cpu_to_le32(
4509 (uint32_t)ha->zio_mode);
4510 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4511 vha->flags.process_response_queue = 1;
4512 }
4513
4514 if (rval) {
4515 DEBUG2_3(printk(KERN_WARNING
4516 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4517 }
4518 return (rval);
4519}
4520
4521void
4522qla81xx_update_fw_options(scsi_qla_host_t *ha)
4523{
4524}