blob: c37888e8747d17b5213df3ac46a427db2fac7c60 [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
Giridhar Malavali7d9dade2009-03-24 09:07:58 -0700819 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700820 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;
Andrew Vasquezdda772e2009-03-24 09:08:00 -0700966 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -0800967
968 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
969 /* Disable SRAM, Instruction RAM and GP RAM parity. */
970 spin_lock_irqsave(&ha->hardware_lock, flags);
971 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
972 RD_REG_WORD(&reg->hccr);
973 spin_unlock_irqrestore(&ha->hardware_lock, flags);
974 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
976 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800977 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700978 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800980 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800982 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 if (rval == QLA_SUCCESS) {
984 /* Start firmware execution. */
985 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800986 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800988 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -0700990 if (rval == QLA_SUCCESS) {
991 fw_major_version = ha->fw_major_version;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800992 qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 &ha->fw_major_version,
994 &ha->fw_minor_version,
995 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800996 &ha->fw_attributes, &ha->fw_memory_size,
Andrew Vasquez55a96152009-03-24 09:08:03 -0700997 ha->mpi_version, &ha->mpi_capabilities,
998 ha->phy_version);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700999 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001000 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001001 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001002 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001003 if ((!ha->max_npiv_vports) ||
1004 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001005 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001006 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001007 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001008 }
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001009 if (!fw_major_version) {
1010 qla2x00_resize_request_q(vha);
1011 if (ql2xallocfwdump)
1012 qla2x00_alloc_fw_dump(vha);
1013 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 }
1015 } else {
1016 DEBUG2(printk(KERN_INFO
1017 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001018 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 }
1020 }
1021
Andrew Vasquez3db06522008-01-31 12:33:49 -08001022 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1023 /* Enable proper parity. */
1024 spin_lock_irqsave(&ha->hardware_lock, flags);
1025 if (IS_QLA2300(ha))
1026 /* SRAM parity */
1027 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1028 else
1029 /* SRAM, Instruction RAM and GP RAM parity */
1030 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1031 RD_REG_WORD(&reg->hccr);
1032 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1033 }
1034
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001035 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1036 uint32_t size;
1037
1038 rval = qla81xx_fac_get_sector_size(vha, &size);
1039 if (rval == QLA_SUCCESS) {
1040 ha->flags.fac_supported = 1;
1041 ha->fdt_block_size = size << 2;
1042 } else {
1043 qla_printk(KERN_ERR, ha,
1044 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1045 ha->fw_major_version, ha->fw_minor_version,
1046 ha->fw_subminor_version);
1047 }
1048 }
1049
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 if (rval) {
1051 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001052 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 }
1054
1055 return (rval);
1056}
1057
1058/**
1059 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1060 * @ha: HA context
1061 *
1062 * Beginning of request ring has initialization control block already built
1063 * by nvram config routine.
1064 *
1065 * Returns 0 on success.
1066 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001067void
1068qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069{
1070 uint16_t cnt;
1071 response_t *pkt;
1072
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001073 pkt = rsp->ring_ptr;
1074 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 pkt->signature = RESPONSE_PROCESSED;
1076 pkt++;
1077 }
1078
1079}
1080
1081/**
1082 * qla2x00_update_fw_options() - Read and process firmware options.
1083 * @ha: HA context
1084 *
1085 * Returns 0 on success.
1086 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001087void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001088qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089{
1090 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001091 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
1093 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001094 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
1096 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1097 return;
1098
1099 /* Serial Link options. */
1100 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001101 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1103 sizeof(ha->fw_seriallink_options)));
1104
1105 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1106 if (ha->fw_seriallink_options[3] & BIT_2) {
1107 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1108
1109 /* 1G settings */
1110 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1111 emphasis = (ha->fw_seriallink_options[2] &
1112 (BIT_4 | BIT_3)) >> 3;
1113 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001114 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 rx_sens = (ha->fw_seriallink_options[0] &
1116 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1117 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1118 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1119 if (rx_sens == 0x0)
1120 rx_sens = 0x3;
1121 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1122 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1123 ha->fw_options[10] |= BIT_5 |
1124 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1125 (tx_sens & (BIT_1 | BIT_0));
1126
1127 /* 2G settings */
1128 swing = (ha->fw_seriallink_options[2] &
1129 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1130 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1131 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001132 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 rx_sens = (ha->fw_seriallink_options[1] &
1134 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1135 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1136 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1137 if (rx_sens == 0x0)
1138 rx_sens = 0x3;
1139 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1140 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1141 ha->fw_options[11] |= BIT_5 |
1142 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1143 (tx_sens & (BIT_1 | BIT_0));
1144 }
1145
1146 /* FCP2 options. */
1147 /* Return command IOCBs without waiting for an ABTS to complete. */
1148 ha->fw_options[3] |= BIT_13;
1149
1150 /* LED scheme. */
1151 if (ha->flags.enable_led_scheme)
1152 ha->fw_options[2] |= BIT_12;
1153
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001154 /* Detect ISP6312. */
1155 if (IS_QLA6312(ha))
1156 ha->fw_options[2] |= BIT_13;
1157
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001159 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160}
1161
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001162void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001163qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001164{
1165 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001166 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001167
1168 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001169 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001170 return;
1171
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001172 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001173 le16_to_cpu(ha->fw_seriallink_options24[1]),
1174 le16_to_cpu(ha->fw_seriallink_options24[2]),
1175 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001176 if (rval != QLA_SUCCESS) {
1177 qla_printk(KERN_WARNING, ha,
1178 "Unable to update Serial Link options (%x).\n", rval);
1179 }
1180}
1181
1182void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001183qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001184{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001185 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001186 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001187 struct req_que *req = ha->req_q_map[0];
1188 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001189
1190 /* Setup ring parameters in initialization control block. */
1191 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1192 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001193 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1194 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1195 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1196 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1197 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1198 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001199
1200 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1201 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1202 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1203 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1204 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1205}
1206
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001207void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001208qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001209{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001210 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001211 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1212 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1213 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001214 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001215 uint16_t rid = 0;
1216 struct req_que *req = ha->req_q_map[0];
1217 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001218
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001219/* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001220 icb = (struct init_cb_24xx *)ha->init_cb;
1221 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1222 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001223 icb->request_q_length = cpu_to_le16(req->length);
1224 icb->response_q_length = cpu_to_le16(rsp->length);
1225 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1226 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1227 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1228 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001229
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001230 if (ha->mqenable) {
1231 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1232 icb->rid = __constant_cpu_to_le16(rid);
1233 if (ha->flags.msix_enabled) {
1234 msix = &ha->msix_entries[1];
1235 DEBUG2_17(printk(KERN_INFO
1236 "Reistering vector 0x%x for base que\n", msix->entry));
1237 icb->msix = cpu_to_le16(msix->entry);
1238 }
1239 /* Use alternate PCI bus number */
1240 if (MSB(rid))
1241 icb->firmware_options_2 |=
1242 __constant_cpu_to_le32(BIT_19);
1243 /* Use alternate PCI devfn */
1244 if (LSB(rid))
1245 icb->firmware_options_2 |=
1246 __constant_cpu_to_le32(BIT_18);
1247
Anirban Chakraborty618a7522009-02-08 20:50:11 -08001248 icb->firmware_options_2 &= __constant_cpu_to_le32(~BIT_22);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001249 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001250
1251 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1252 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1253 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1254 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1255 } else {
1256 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1257 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1258 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1259 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1260 }
1261 /* PCI posting */
1262 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001263}
1264
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265/**
1266 * qla2x00_init_rings() - Initializes firmware.
1267 * @ha: HA context
1268 *
1269 * Beginning of request ring has initialization control block already built
1270 * by nvram config routine.
1271 *
1272 * Returns 0 on success.
1273 */
1274static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001275qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276{
1277 int rval;
1278 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001279 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001280 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001281 struct req_que *req;
1282 struct rsp_que *rsp;
1283 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001284 struct mid_init_cb_24xx *mid_init_cb =
1285 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
1287 spin_lock_irqsave(&ha->hardware_lock, flags);
1288
1289 /* Clear outstanding commands array. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001290 for (que = 0; que < ha->max_queues; que++) {
1291 req = ha->req_q_map[que];
1292 if (!req)
1293 continue;
1294 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1295 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001297 req->current_outstanding_cmd = 0;
1298
1299 /* Initialize firmware. */
1300 req->ring_ptr = req->ring;
1301 req->ring_index = 0;
1302 req->cnt = req->length;
1303 }
1304
1305 for (que = 0; que < ha->max_queues; que++) {
1306 rsp = ha->rsp_q_map[que];
1307 if (!rsp)
1308 continue;
1309 rsp->ring_ptr = rsp->ring;
1310 rsp->ring_index = 0;
1311
1312 /* Initialize response queue entries */
1313 qla2x00_init_response_q_entries(rsp);
1314 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
1316 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001317 list_for_each_entry(vp, &ha->vp_list, list) {
1318 vp->rscn_in_ptr = 0;
1319 vp->rscn_out_ptr = 0;
1320 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001321 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322
1323 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1324
1325 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001326 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001328 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001329
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001330 if (ha->flags.npiv_supported) {
1331 if (ha->operating_mode == LOOP)
1332 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001333 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001334 }
1335
Seokmann Juc48339d2008-01-17 09:02:19 -08001336
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001337 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001338
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001339 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 if (rval) {
1341 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001342 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 } else {
1344 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001345 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 }
1347
1348 return (rval);
1349}
1350
1351/**
1352 * qla2x00_fw_ready() - Waits for firmware ready.
1353 * @ha: HA context
1354 *
1355 * Returns 0 on success.
1356 */
1357static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001358qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359{
1360 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001361 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 uint16_t min_wait; /* Minimum wait time if loop is down */
1363 uint16_t wait_time; /* Wait time if loop is coming ready */
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001364 uint16_t state[3];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001365 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
1367 rval = QLA_SUCCESS;
1368
1369 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001370 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371
1372 /*
1373 * Firmware should take at most one RATOV to login, plus 5 seconds for
1374 * our own processing.
1375 */
1376 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1377 wait_time = min_wait;
1378 }
1379
1380 /* Min wait time if loop down */
1381 mtime = jiffies + (min_wait * HZ);
1382
1383 /* wait time before firmware ready */
1384 wtime = jiffies + (wait_time * HZ);
1385
1386 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001387 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1389
1390 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001391 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392
1393 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001394 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001396 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001397 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001399 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1400 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001401 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001402 state[2]));
1403 if ((state[2] & FSTATE_LOGGED_IN) &&
1404 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1405 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001406 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001407
1408 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001409 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001410 if (rval != QLA_SUCCESS)
1411 break;
1412
1413 /* Add time taken to initialize. */
1414 cs84xx_time = jiffies - cs84xx_time;
1415 wtime += cs84xx_time;
1416 mtime += cs84xx_time;
1417 DEBUG16(printk("scsi(%ld): Increasing "
1418 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001419 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001420 }
1421 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001423 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001425 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 &ha->login_timeout, &ha->r_a_tov);
1427
1428 rval = QLA_SUCCESS;
1429 break;
1430 }
1431
1432 rval = QLA_FUNCTION_FAILED;
1433
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001434 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001435 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001437 * other than Wait for Login.
1438 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 if (time_after_eq(jiffies, mtime)) {
1440 qla_printk(KERN_INFO, ha,
1441 "Cable is unplugged...\n");
1442
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001443 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 break;
1445 }
1446 }
1447 } else {
1448 /* Mailbox cmd failed. Timeout on min_wait. */
1449 if (time_after_eq(jiffies, mtime))
1450 break;
1451 }
1452
1453 if (time_after_eq(jiffies, wtime))
1454 break;
1455
1456 /* Delay for a while */
1457 msleep(500);
1458
1459 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001460 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 } while (1);
1462
1463 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001464 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465
1466 if (rval) {
1467 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001468 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 }
1470
1471 return (rval);
1472}
1473
1474/*
1475* qla2x00_configure_hba
1476* Setup adapter context.
1477*
1478* Input:
1479* ha = adapter state pointer.
1480*
1481* Returns:
1482* 0 = success
1483*
1484* Context:
1485* Kernel context.
1486*/
1487static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001488qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489{
1490 int rval;
1491 uint16_t loop_id;
1492 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001493 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 uint8_t al_pa;
1495 uint8_t area;
1496 uint8_t domain;
1497 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001498 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499
1500 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001501 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001502 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001504 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001505 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1506 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001507 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08001508 } else {
1509 qla_printk(KERN_WARNING, ha,
1510 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001511 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08001512 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 return (rval);
1514 }
1515
1516 if (topo == 4) {
1517 qla_printk(KERN_INFO, ha,
1518 "Cannot get topology - retrying.\n");
1519 return (QLA_FUNCTION_FAILED);
1520 }
1521
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001522 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
1524 /* initialize */
1525 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1526 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001527 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
1529 switch (topo) {
1530 case 0:
1531 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001532 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 ha->current_topology = ISP_CFG_NL;
1534 strcpy(connect_type, "(Loop)");
1535 break;
1536
1537 case 1:
1538 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001539 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001540 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 ha->current_topology = ISP_CFG_FL;
1542 strcpy(connect_type, "(FL_Port)");
1543 break;
1544
1545 case 2:
1546 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001547 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 ha->operating_mode = P2P;
1549 ha->current_topology = ISP_CFG_N;
1550 strcpy(connect_type, "(N_Port-to-N_Port)");
1551 break;
1552
1553 case 3:
1554 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001555 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001556 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 ha->operating_mode = P2P;
1558 ha->current_topology = ISP_CFG_F;
1559 strcpy(connect_type, "(F_Port)");
1560 break;
1561
1562 default:
1563 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1564 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001565 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 ha->current_topology = ISP_CFG_NL;
1567 strcpy(connect_type, "(Loop)");
1568 break;
1569 }
1570
1571 /* Save Host port and loop ID. */
1572 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001573 vha->d_id.b.domain = domain;
1574 vha->d_id.b.area = area;
1575 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001577 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 qla_printk(KERN_INFO, ha,
1579 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001580 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
1582 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001583 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001585 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 }
1587
1588 return(rval);
1589}
1590
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001591static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001592qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1593 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001594{
1595 char *st, *en;
1596 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001597 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001598
1599 if (memcmp(model, BINZERO, len) != 0) {
1600 strncpy(ha->model_number, model, len);
1601 st = en = ha->model_number;
1602 en += len - 1;
1603 while (en > st) {
1604 if (*en != 0x20 && *en != 0x00)
1605 break;
1606 *en-- = '\0';
1607 }
1608
1609 index = (ha->pdev->subsystem_device & 0xff);
1610 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1611 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001612 strncpy(ha->model_desc,
1613 qla2x00_model_name[index * 2 + 1],
1614 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001615 } else {
1616 index = (ha->pdev->subsystem_device & 0xff);
1617 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1618 index < QLA_MODEL_NAMES) {
1619 strcpy(ha->model_number,
1620 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001621 strncpy(ha->model_desc,
1622 qla2x00_model_name[index * 2 + 1],
1623 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001624 } else {
1625 strcpy(ha->model_number, def);
1626 }
1627 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001628 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001629 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001630 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001631}
1632
David Miller4e08df32007-04-16 12:37:43 -07001633/* On sparc systems, obtain port and node WWN from firmware
1634 * properties.
1635 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001636static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07001637{
1638#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001639 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07001640 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07001641 struct device_node *dp = pci_device_to_OF_node(pdev);
1642 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07001643 int len;
1644
1645 val = of_get_property(dp, "port-wwn", &len);
1646 if (val && len >= WWN_SIZE)
1647 memcpy(nv->port_name, val, WWN_SIZE);
1648
1649 val = of_get_property(dp, "node-wwn", &len);
1650 if (val && len >= WWN_SIZE)
1651 memcpy(nv->node_name, val, WWN_SIZE);
1652#endif
1653}
1654
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655/*
1656* NVRAM configuration for ISP 2xxx
1657*
1658* Input:
1659* ha = adapter block pointer.
1660*
1661* Output:
1662* initialization control block in response_ring
1663* host adapters parameters in host adapter block
1664*
1665* Returns:
1666* 0 = success.
1667*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001668int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001669qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670{
David Miller4e08df32007-04-16 12:37:43 -07001671 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001672 uint8_t chksum = 0;
1673 uint16_t cnt;
1674 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001675 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001676 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07001677 nvram_t *nv = ha->nvram;
1678 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001679 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680
David Miller4e08df32007-04-16 12:37:43 -07001681 rval = QLA_SUCCESS;
1682
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001684 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 ha->nvram_base = 0;
1686 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1687 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
1688 ha->nvram_base = 0x80;
1689
1690 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001691 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001692 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1693 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001695 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07001696 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
1698 /* Bad NVRAM data, set defaults parameters. */
1699 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1700 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1701 /* Reset NVRAM data. */
1702 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1703 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1704 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07001705 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1706 "invalid -- WWPN) defaults.\n");
1707
1708 /*
1709 * Set default initialization control block.
1710 */
1711 memset(nv, 0, ha->nvram_size);
1712 nv->parameter_block_version = ICB_VERSION;
1713
1714 if (IS_QLA23XX(ha)) {
1715 nv->firmware_options[0] = BIT_2 | BIT_1;
1716 nv->firmware_options[1] = BIT_7 | BIT_5;
1717 nv->add_firmware_options[0] = BIT_5;
1718 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1719 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1720 nv->special_options[1] = BIT_7;
1721 } else if (IS_QLA2200(ha)) {
1722 nv->firmware_options[0] = BIT_2 | BIT_1;
1723 nv->firmware_options[1] = BIT_7 | BIT_5;
1724 nv->add_firmware_options[0] = BIT_5;
1725 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1726 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1727 } else if (IS_QLA2100(ha)) {
1728 nv->firmware_options[0] = BIT_3 | BIT_1;
1729 nv->firmware_options[1] = BIT_5;
1730 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1731 }
1732
1733 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1734 nv->execution_throttle = __constant_cpu_to_le16(16);
1735 nv->retry_count = 8;
1736 nv->retry_delay = 1;
1737
1738 nv->port_name[0] = 33;
1739 nv->port_name[3] = 224;
1740 nv->port_name[4] = 139;
1741
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001742 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07001743
1744 nv->login_timeout = 4;
1745
1746 /*
1747 * Set default host adapter parameters
1748 */
1749 nv->host_p[1] = BIT_2;
1750 nv->reset_delay = 5;
1751 nv->port_down_retry_count = 8;
1752 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1753 nv->link_down_timeout = 60;
1754
1755 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 }
1757
1758#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1759 /*
1760 * The SN2 does not provide BIOS emulation which means you can't change
1761 * potentially bogus BIOS settings. Force the use of default settings
1762 * for link rate and frame size. Hope that the rest of the settings
1763 * are valid.
1764 */
1765 if (ia64_platform_is("sn2")) {
1766 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1767 if (IS_QLA23XX(ha))
1768 nv->special_options[1] = BIT_7;
1769 }
1770#endif
1771
1772 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001773 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
1775 /*
1776 * Setup driver NVRAM options.
1777 */
1778 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1779 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1780 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1781 nv->firmware_options[1] &= ~BIT_4;
1782
1783 if (IS_QLA23XX(ha)) {
1784 nv->firmware_options[0] |= BIT_2;
1785 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001786 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787
1788 if (IS_QLA2300(ha)) {
1789 if (ha->fb_rev == FPM_2310) {
1790 strcpy(ha->model_number, "QLA2310");
1791 } else {
1792 strcpy(ha->model_number, "QLA2300");
1793 }
1794 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001795 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001796 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 }
1798 } else if (IS_QLA2200(ha)) {
1799 nv->firmware_options[0] |= BIT_2;
1800 /*
1801 * 'Point-to-point preferred, else loop' is not a safe
1802 * connection mode setting.
1803 */
1804 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1805 (BIT_5 | BIT_4)) {
1806 /* Force 'loop preferred, else point-to-point'. */
1807 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1808 nv->add_firmware_options[0] |= BIT_5;
1809 }
1810 strcpy(ha->model_number, "QLA22xx");
1811 } else /*if (IS_QLA2100(ha))*/ {
1812 strcpy(ha->model_number, "QLA2100");
1813 }
1814
1815 /*
1816 * Copy over NVRAM RISC parameter block to initialization control block.
1817 */
1818 dptr1 = (uint8_t *)icb;
1819 dptr2 = (uint8_t *)&nv->parameter_block_version;
1820 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1821 while (cnt--)
1822 *dptr1++ = *dptr2++;
1823
1824 /* Copy 2nd half. */
1825 dptr1 = (uint8_t *)icb->add_firmware_options;
1826 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1827 while (cnt--)
1828 *dptr1++ = *dptr2++;
1829
Andrew Vasquez5341e862006-05-17 15:09:16 -07001830 /* Use alternate WWN? */
1831 if (nv->host_p[1] & BIT_7) {
1832 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1833 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1834 }
1835
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 /* Prepare nodename */
1837 if ((icb->firmware_options[1] & BIT_6) == 0) {
1838 /*
1839 * Firmware will apply the following mask if the nodename was
1840 * not provided.
1841 */
1842 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1843 icb->node_name[0] &= 0xF0;
1844 }
1845
1846 /*
1847 * Set host adapter parameters.
1848 */
Andrew Vasquez01819442006-06-23 16:11:10 -07001849 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07001850 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1852 /* Always load RISC code on non ISP2[12]00 chips. */
1853 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1854 ha->flags.disable_risc_code_load = 0;
1855 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1856 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1857 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07001858 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001859 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860
1861 ha->operating_mode =
1862 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1863
1864 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1865 sizeof(ha->fw_seriallink_options));
1866
1867 /* save HBA serial number */
1868 ha->serial0 = icb->port_name[5];
1869 ha->serial1 = icb->port_name[6];
1870 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001871 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
1872 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873
1874 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1875
1876 ha->retry_count = nv->retry_count;
1877
1878 /* Set minimum login_timeout to 4 seconds. */
1879 if (nv->login_timeout < ql2xlogintimeout)
1880 nv->login_timeout = ql2xlogintimeout;
1881 if (nv->login_timeout < 4)
1882 nv->login_timeout = 4;
1883 ha->login_timeout = nv->login_timeout;
1884 icb->login_timeout = nv->login_timeout;
1885
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001886 /* Set minimum RATOV to 100 tenths of a second. */
1887 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 ha->loop_reset_delay = nv->reset_delay;
1890
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 /* Link Down Timeout = 0:
1892 *
1893 * When Port Down timer expires we will start returning
1894 * I/O's to OS with "DID_NO_CONNECT".
1895 *
1896 * Link Down Timeout != 0:
1897 *
1898 * The driver waits for the link to come up after link down
1899 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001900 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 if (nv->link_down_timeout == 0) {
1902 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001903 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 } else {
1905 ha->link_down_timeout = nv->link_down_timeout;
1906 ha->loop_down_abort_time =
1907 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001908 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 /*
1911 * Need enough time to try and get the port back.
1912 */
1913 ha->port_down_retry_count = nv->port_down_retry_count;
1914 if (qlport_down_retry)
1915 ha->port_down_retry_count = qlport_down_retry;
1916 /* Set login_retry_count */
1917 ha->login_retry_count = nv->retry_count;
1918 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1919 ha->port_down_retry_count > 3)
1920 ha->login_retry_count = ha->port_down_retry_count;
1921 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1922 ha->login_retry_count = ha->port_down_retry_count;
1923 if (ql2xloginretrycount)
1924 ha->login_retry_count = ql2xloginretrycount;
1925
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 icb->lun_enables = __constant_cpu_to_le16(0);
1927 icb->command_resource_count = 0;
1928 icb->immediate_notify_resource_count = 0;
1929 icb->timeout = __constant_cpu_to_le16(0);
1930
1931 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1932 /* Enable RIO */
1933 icb->firmware_options[0] &= ~BIT_3;
1934 icb->add_firmware_options[0] &=
1935 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1936 icb->add_firmware_options[0] |= BIT_2;
1937 icb->response_accumulation_timer = 3;
1938 icb->interrupt_delay_timer = 5;
1939
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001940 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001942 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001943 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001944 ha->zio_mode = icb->add_firmware_options[0] &
1945 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1946 ha->zio_timer = icb->interrupt_delay_timer ?
1947 icb->interrupt_delay_timer: 2;
1948 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 icb->add_firmware_options[0] &=
1950 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001951 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001952 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001953 ha->zio_mode = QLA_ZIO_MODE_6;
1954
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001955 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001956 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001957 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001959 "ZIO mode %d enabled; timer delay (%d us).\n",
1960 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001962 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1963 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001964 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 }
1966 }
1967
David Miller4e08df32007-04-16 12:37:43 -07001968 if (rval) {
1969 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001970 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07001971 }
1972 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973}
1974
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001975static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001976qla2x00_rport_del(void *data)
1977{
1978 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001979 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001980
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001981 spin_lock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001982 rport = fcport->drport;
1983 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001984 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001985 if (rport)
1986 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001987}
1988
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989/**
1990 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1991 * @ha: HA context
1992 * @flags: allocation flags
1993 *
1994 * Returns a pointer to the allocated fcport, or NULL, if none available.
1995 */
Adrian Bunk413975a2006-06-30 02:33:06 -07001996static fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001997qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998{
1999 fc_port_t *fcport;
2000
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002001 fcport = kzalloc(sizeof(fc_port_t), flags);
2002 if (!fcport)
2003 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004
2005 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002006 fcport->vha = vha;
2007 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 fcport->port_type = FCT_UNKNOWN;
2009 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 atomic_set(&fcport->state, FCS_UNCONFIGURED);
2011 fcport->flags = FCF_RLC_SUPPORT;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002012 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002014 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015}
2016
2017/*
2018 * qla2x00_configure_loop
2019 * Updates Fibre Channel Device Database with what is actually on loop.
2020 *
2021 * Input:
2022 * ha = adapter block pointer.
2023 *
2024 * Returns:
2025 * 0 = success.
2026 * 1 = error.
2027 * 2 = database was full and device was not configured.
2028 */
2029static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002030qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031{
2032 int rval;
2033 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002034 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 rval = QLA_SUCCESS;
2036
2037 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002038 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2039 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 if (rval != QLA_SUCCESS) {
2041 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002042 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 return (rval);
2044 }
2045 }
2046
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002047 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002049 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050
2051 /*
2052 * If we have both an RSCN and PORT UPDATE pending then handle them
2053 * both at the same time.
2054 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002055 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2056 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057
2058 /* Determine what we need to do */
2059 if (ha->current_topology == ISP_CFG_FL &&
2060 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2061
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002062 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 set_bit(RSCN_UPDATE, &flags);
2064
2065 } else if (ha->current_topology == ISP_CFG_F &&
2066 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2067
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002068 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 set_bit(RSCN_UPDATE, &flags);
2070 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2071
Andrew Vasquez21333b42006-05-17 15:09:56 -07002072 } else if (ha->current_topology == ISP_CFG_N) {
2073 clear_bit(RSCN_UPDATE, &flags);
2074
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002075 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2077
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002078 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 set_bit(RSCN_UPDATE, &flags);
2080 set_bit(LOCAL_LOOP_UPDATE, &flags);
2081 }
2082
2083 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002084 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002086 else
2087 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 }
2089
2090 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002091 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002093 else
2094 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 }
2096
2097 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002098 if (atomic_read(&vha->loop_down_timer) ||
2099 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 rval = QLA_FUNCTION_FAILED;
2101 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002102 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002104 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 }
2106 }
2107
2108 if (rval) {
2109 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002110 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 } else {
2112 DEBUG3(printk("%s: exiting normally\n", __func__));
2113 }
2114
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002115 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002116 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002118 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002119 if (test_bit(RSCN_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002120 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 }
2122
2123 return (rval);
2124}
2125
2126
2127
2128/*
2129 * qla2x00_configure_local_loop
2130 * Updates Fibre Channel Device Database with local loop devices.
2131 *
2132 * Input:
2133 * ha = adapter block pointer.
2134 *
2135 * Returns:
2136 * 0 = success.
2137 */
2138static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002139qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140{
2141 int rval, rval2;
2142 int found_devs;
2143 int found;
2144 fc_port_t *fcport, *new_fcport;
2145
2146 uint16_t index;
2147 uint16_t entries;
2148 char *id_iter;
2149 uint16_t loop_id;
2150 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002151 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152
2153 found_devs = 0;
2154 new_fcport = NULL;
2155 entries = MAX_FIBRE_DEVICES;
2156
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002157 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2158 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159
2160 /* Get list of logged in devices. */
2161 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002162 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 &entries);
2164 if (rval != QLA_SUCCESS)
2165 goto cleanup_allocation;
2166
2167 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2168 ha->host_no, entries));
2169 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2170 entries * sizeof(struct gid_list_info)));
2171
2172 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002173 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 if (new_fcport == NULL) {
2175 rval = QLA_MEMORY_ALLOC_FAILED;
2176 goto cleanup_allocation;
2177 }
2178 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2179
2180 /*
2181 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2182 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002183 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2185 fcport->port_type != FCT_BROADCAST &&
2186 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2187
2188 DEBUG(printk("scsi(%ld): Marking port lost, "
2189 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002190 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191
2192 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2193 fcport->flags &= ~FCF_FARP_DONE;
2194 }
2195 }
2196
2197 /* Add devices to port list. */
2198 id_iter = (char *)ha->gid_list;
2199 for (index = 0; index < entries; index++) {
2200 domain = ((struct gid_list_info *)id_iter)->domain;
2201 area = ((struct gid_list_info *)id_iter)->area;
2202 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002203 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 loop_id = (uint16_t)
2205 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002206 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 loop_id = le16_to_cpu(
2208 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002209 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210
2211 /* Bypass reserved domain fields. */
2212 if ((domain & 0xf0) == 0xf0)
2213 continue;
2214
2215 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002216 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002217 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 continue;
2219
2220 /* Bypass invalid local loop ID. */
2221 if (loop_id > LAST_LOCAL_LOOP_ID)
2222 continue;
2223
2224 /* Fill in member data. */
2225 new_fcport->d_id.b.domain = domain;
2226 new_fcport->d_id.b.area = area;
2227 new_fcport->d_id.b.al_pa = al_pa;
2228 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002229 new_fcport->vp_idx = vha->vp_idx;
2230 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 if (rval2 != QLA_SUCCESS) {
2232 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2233 "information -- get_port_database=%x, "
2234 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002235 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002236 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002237 vha->host_no));
2238 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 continue;
2240 }
2241
2242 /* Check for matching device in port list. */
2243 found = 0;
2244 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002245 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 if (memcmp(new_fcport->port_name, fcport->port_name,
2247 WWN_SIZE))
2248 continue;
2249
2250 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2251 FCF_PERSISTENT_BOUND);
2252 fcport->loop_id = new_fcport->loop_id;
2253 fcport->port_type = new_fcport->port_type;
2254 fcport->d_id.b24 = new_fcport->d_id.b24;
2255 memcpy(fcport->node_name, new_fcport->node_name,
2256 WWN_SIZE);
2257
2258 found++;
2259 break;
2260 }
2261
2262 if (!found) {
2263 /* New device, add to fcports list. */
2264 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002265 if (vha->vp_idx) {
2266 new_fcport->vha = vha;
2267 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002268 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002269 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270
2271 /* Allocate a new replacement fcport. */
2272 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002273 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 if (new_fcport == NULL) {
2275 rval = QLA_MEMORY_ALLOC_FAILED;
2276 goto cleanup_allocation;
2277 }
2278 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2279 }
2280
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002281 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002282 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002283
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002284 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285
2286 found_devs++;
2287 }
2288
2289cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002290 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291
2292 if (rval != QLA_SUCCESS) {
2293 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002294 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 }
2296
2297 if (found_devs) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002298 vha->device_flags |= DFLG_LOCAL_DEVICES;
2299 vha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 }
2301
2302 return (rval);
2303}
2304
2305static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002306qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002307{
2308#define LS_UNKNOWN 2
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002309 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002310 int rval;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002311 uint16_t mb[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002312 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002313
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002314 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002315 return;
2316
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002317 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2318 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002319 return;
2320
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002321 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002322 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002323 if (rval != QLA_SUCCESS) {
2324 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2325 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002326 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002327 fcport->port_name[2], fcport->port_name[3],
2328 fcport->port_name[4], fcport->port_name[5],
2329 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002330 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002331 } else {
2332 DEBUG2(qla_printk(KERN_INFO, ha,
2333 "iIDMA adjusted to %s GB/s on "
2334 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002335 link_speeds[fcport->fp_speed], fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002336 fcport->port_name[1], fcport->port_name[2],
2337 fcport->port_name[3], fcport->port_name[4],
2338 fcport->port_name[5], fcport->port_name[6],
2339 fcport->port_name[7]));
2340 }
2341}
2342
Adrian Bunk23be3312006-11-24 02:46:01 +01002343static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002344qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002345{
2346 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002347 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002348 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05002349
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002350 if (fcport->drport)
2351 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002352
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002353 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2354 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002355 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2356 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2357 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002358 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002359 if (!rport) {
2360 qla_printk(KERN_WARNING, ha,
2361 "Unable to allocate fc remote port!\n");
2362 return;
2363 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002364 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002365 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002366 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002367
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002368 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002369
2370 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002371 if (fcport->port_type == FCT_INITIATOR)
2372 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2373 if (fcport->port_type == FCT_TARGET)
2374 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002375 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002376}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377
2378/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002379 * qla2x00_update_fcport
2380 * Updates device on list.
2381 *
2382 * Input:
2383 * ha = adapter block pointer.
2384 * fcport = port structure pointer.
2385 *
2386 * Return:
2387 * 0 - Success
2388 * BIT_0 - error
2389 *
2390 * Context:
2391 * Kernel context.
2392 */
2393void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002394qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002395{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002396 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002397
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002398 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002399 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002400 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002401 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002402 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002403 PORT_RETRY_TIME);
2404 fcport->flags &= ~FCF_LOGIN_NEEDED;
2405
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002406 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002407
2408 atomic_set(&fcport->state, FCS_ONLINE);
2409
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002410 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002411}
2412
2413/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 * qla2x00_configure_fabric
2415 * Setup SNS devices with loop ID's.
2416 *
2417 * Input:
2418 * ha = adapter block pointer.
2419 *
2420 * Returns:
2421 * 0 = success.
2422 * BIT_0 = error
2423 */
2424static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002425qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426{
2427 int rval, rval2;
2428 fc_port_t *fcport, *fcptemp;
2429 uint16_t next_loopid;
2430 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002431 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002433 struct qla_hw_data *ha = vha->hw;
2434 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435
2436 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002437 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002438 loop_id = NPH_F_PORT;
2439 else
2440 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002441 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 if (rval != QLA_SUCCESS) {
2443 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002444 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002446 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 return (QLA_SUCCESS);
2448 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002449 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450
2451 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002452 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 if (rval2 == QLA_RSCNS_HANDLED) {
2454 /* No point doing the scan, just continue. */
2455 return (QLA_SUCCESS);
2456 }
2457 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002458 /* FDMI support. */
2459 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002460 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2461 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002462
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002464 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002465 loop_id = NPH_SNS;
2466 else
2467 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002468 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002469 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 if (mb[0] != MBS_COMMAND_COMPLETE) {
2471 DEBUG2(qla_printk(KERN_INFO, ha,
2472 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002473 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 mb[0], mb[1], mb[2], mb[6], mb[7]));
2475 return (QLA_SUCCESS);
2476 }
2477
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002478 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2479 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 /* EMPTY */
2481 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002482 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002484 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 /* EMPTY */
2486 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002487 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002489 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 /* EMPTY */
2491 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002492 "failed.\n", vha->host_no));
2493 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 /* EMPTY */
2495 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002496 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 }
2498 }
2499
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002500 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 if (rval != QLA_SUCCESS)
2502 break;
2503
2504 /*
2505 * Logout all previous fabric devices marked lost, except
2506 * tape devices.
2507 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002508 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2509 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 break;
2511
2512 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2513 continue;
2514
2515 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002516 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002517 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 if (fcport->loop_id != FC_NO_LOOP_ID &&
2519 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2520 fcport->port_type != FCT_INITIATOR &&
2521 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002522 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002523 fcport->loop_id,
2524 fcport->d_id.b.domain,
2525 fcport->d_id.b.area,
2526 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 fcport->loop_id = FC_NO_LOOP_ID;
2528 }
2529 }
2530 }
2531
2532 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002533 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534
2535 /*
2536 * Scan through our port list and login entries that need to be
2537 * logged in.
2538 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002539 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2540 if (atomic_read(&vha->loop_down_timer) ||
2541 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 break;
2543
2544 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2545 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2546 continue;
2547
2548 if (fcport->loop_id == FC_NO_LOOP_ID) {
2549 fcport->loop_id = next_loopid;
Seokmann Jud4486fd2008-04-03 13:13:28 -07002550 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002551 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 if (rval != QLA_SUCCESS) {
2553 /* Ran out of IDs to use */
2554 break;
2555 }
2556 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002558 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 }
2560
2561 /* Exit if out of loop IDs. */
2562 if (rval != QLA_SUCCESS) {
2563 break;
2564 }
2565
2566 /*
2567 * Login and add the new devices to our port list.
2568 */
2569 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002570 if (atomic_read(&vha->loop_down_timer) ||
2571 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 break;
2573
2574 /* Find a new loop ID to use. */
2575 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002576 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 if (rval != QLA_SUCCESS) {
2578 /* Ran out of IDs to use */
2579 break;
2580 }
2581
bdf79622005-04-17 15:06:53 -05002582 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002583 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002584
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002585 if (vha->vp_idx) {
2586 fcport->vha = vha;
2587 fcport->vp_idx = vha->vp_idx;
2588 }
2589 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 }
2591 } while (0);
2592
2593 /* Free all new device structures not processed. */
2594 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2595 list_del(&fcport->list);
2596 kfree(fcport);
2597 }
2598
2599 if (rval) {
2600 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002601 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 }
2603
2604 return (rval);
2605}
2606
2607
2608/*
2609 * qla2x00_find_all_fabric_devs
2610 *
2611 * Input:
2612 * ha = adapter block pointer.
2613 * dev = database device entry pointer.
2614 *
2615 * Returns:
2616 * 0 = success.
2617 *
2618 * Context:
2619 * Kernel context.
2620 */
2621static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002622qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2623 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624{
2625 int rval;
2626 uint16_t loop_id;
2627 fc_port_t *fcport, *new_fcport, *fcptemp;
2628 int found;
2629
2630 sw_info_t *swl;
2631 int swl_idx;
2632 int first_dev, last_dev;
2633 port_id_t wrap, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002634 struct qla_hw_data *ha = vha->hw;
2635 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002636 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637
2638 rval = QLA_SUCCESS;
2639
2640 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07002641 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002642 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 /*EMPTY*/
2644 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002645 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002647 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 kfree(swl);
2649 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002650 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 kfree(swl);
2652 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002653 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 kfree(swl);
2655 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07002656 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002657 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2658 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 }
2660 }
2661 swl_idx = 0;
2662
2663 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002664 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002666 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 return (QLA_MEMORY_ALLOC_FAILED);
2668 }
2669 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 /* Set start port ID scan at adapter ID. */
2671 first_dev = 1;
2672 last_dev = 0;
2673
2674 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002675 loop_id = ha->min_external_loopid;
2676 for (; loop_id <= ha->max_loop_id; loop_id++) {
2677 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 continue;
2679
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002680 if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 break;
2682
2683 if (swl != NULL) {
2684 if (last_dev) {
2685 wrap.b24 = new_fcport->d_id.b24;
2686 } else {
2687 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2688 memcpy(new_fcport->node_name,
2689 swl[swl_idx].node_name, WWN_SIZE);
2690 memcpy(new_fcport->port_name,
2691 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002692 memcpy(new_fcport->fabric_port_name,
2693 swl[swl_idx].fabric_port_name, WWN_SIZE);
2694 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695
2696 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2697 last_dev = 1;
2698 }
2699 swl_idx++;
2700 }
2701 } else {
2702 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002703 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 if (rval != QLA_SUCCESS) {
2705 qla_printk(KERN_WARNING, ha,
2706 "SNS scan failed -- assuming zero-entry "
2707 "result...\n");
2708 list_for_each_entry_safe(fcport, fcptemp,
2709 new_fcports, list) {
2710 list_del(&fcport->list);
2711 kfree(fcport);
2712 }
2713 rval = QLA_SUCCESS;
2714 break;
2715 }
2716 }
2717
2718 /* If wrap on switch device list, exit. */
2719 if (first_dev) {
2720 wrap.b24 = new_fcport->d_id.b24;
2721 first_dev = 0;
2722 } else if (new_fcport->d_id.b24 == wrap.b24) {
2723 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002724 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2726 break;
2727 }
2728
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002729 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002730 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 continue;
2732
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002733 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002734 found = 0;
2735 if (ha->num_vhosts) {
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002736 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002737 if (new_fcport->d_id.b24 == vp->d_id.b24) {
2738 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002739 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002740 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002741 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002742 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002743 continue;
2744 }
2745
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002746 /* Bypass if same domain and area of adapter. */
2747 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002748 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002749 ISP_CFG_FL)
2750 continue;
2751
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 /* Bypass reserved domain fields. */
2753 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2754 continue;
2755
2756 /* Locate matching device in database. */
2757 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002758 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759 if (memcmp(new_fcport->port_name, fcport->port_name,
2760 WWN_SIZE))
2761 continue;
2762
2763 found++;
2764
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002765 /* Update port state. */
2766 memcpy(fcport->fabric_port_name,
2767 new_fcport->fabric_port_name, WWN_SIZE);
2768 fcport->fp_speed = new_fcport->fp_speed;
2769
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 /*
2771 * If address the same and state FCS_ONLINE, nothing
2772 * changed.
2773 */
2774 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2775 atomic_read(&fcport->state) == FCS_ONLINE) {
2776 break;
2777 }
2778
2779 /*
2780 * If device was not a fabric device before.
2781 */
2782 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2783 fcport->d_id.b24 = new_fcport->d_id.b24;
2784 fcport->loop_id = FC_NO_LOOP_ID;
2785 fcport->flags |= (FCF_FABRIC_DEVICE |
2786 FCF_LOGIN_NEEDED);
2787 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2788 break;
2789 }
2790
2791 /*
2792 * Port ID changed or device was marked to be updated;
2793 * Log it out if still logged in and mark it for
2794 * relogin later.
2795 */
2796 fcport->d_id.b24 = new_fcport->d_id.b24;
2797 fcport->flags |= FCF_LOGIN_NEEDED;
2798 if (fcport->loop_id != FC_NO_LOOP_ID &&
2799 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2800 fcport->port_type != FCT_INITIATOR &&
2801 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002802 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002803 fcport->d_id.b.domain, fcport->d_id.b.area,
2804 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 fcport->loop_id = FC_NO_LOOP_ID;
2806 }
2807
2808 break;
2809 }
2810
2811 if (found)
2812 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 /* If device was not in our fcports list, then add it. */
2814 list_add_tail(&new_fcport->list, new_fcports);
2815
2816 /* Allocate a new replacement fcport. */
2817 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002818 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002820 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 return (QLA_MEMORY_ALLOC_FAILED);
2822 }
2823 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2824 new_fcport->d_id.b24 = nxt_d_id.b24;
2825 }
2826
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002827 kfree(swl);
2828 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829
2830 if (!list_empty(new_fcports))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002831 vha->device_flags |= DFLG_FABRIC_DEVICES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832
2833 return (rval);
2834}
2835
2836/*
2837 * qla2x00_find_new_loop_id
2838 * Scan through our port list and find a new usable loop ID.
2839 *
2840 * Input:
2841 * ha: adapter state pointer.
2842 * dev: port structure pointer.
2843 *
2844 * Returns:
2845 * qla2x00 local function return status code.
2846 *
2847 * Context:
2848 * Kernel context.
2849 */
Adrian Bunk413975a2006-06-30 02:33:06 -07002850static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002851qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852{
2853 int rval;
2854 int found;
2855 fc_port_t *fcport;
2856 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002857 struct qla_hw_data *ha = vha->hw;
2858 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002859 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860
2861 rval = QLA_SUCCESS;
2862
2863 /* Save starting loop ID. */
2864 first_loop_id = dev->loop_id;
2865
2866 for (;;) {
2867 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002868 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870
2871 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002872 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874
2875 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002876 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 /* first loop ID. */
2878 dev->loop_id = ha->min_external_loopid;
2879 }
2880
2881 /* Check for loop ID being already in use. */
2882 found = 0;
2883 fcport = NULL;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002884 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002885 list_for_each_entry(fcport, &vp->vp_fcports, list) {
2886 if (fcport->loop_id == dev->loop_id &&
2887 fcport != dev) {
2888 /* ID possibly in use */
2889 found++;
2890 break;
2891 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002893 if (found)
2894 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895 }
2896
2897 /* If not in use then it is free to use. */
2898 if (!found) {
2899 break;
2900 }
2901
2902 /* ID in use. Try next value. */
2903 dev->loop_id++;
2904
2905 /* If wrap around. No free ID to use. */
2906 if (dev->loop_id == first_loop_id) {
2907 dev->loop_id = FC_NO_LOOP_ID;
2908 rval = QLA_FUNCTION_FAILED;
2909 break;
2910 }
2911 }
2912
2913 return (rval);
2914}
2915
2916/*
2917 * qla2x00_device_resync
2918 * Marks devices in the database that needs resynchronization.
2919 *
2920 * Input:
2921 * ha = adapter block pointer.
2922 *
2923 * Context:
2924 * Kernel context.
2925 */
2926static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002927qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928{
2929 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 uint32_t mask;
2931 fc_port_t *fcport;
2932 uint32_t rscn_entry;
2933 uint8_t rscn_out_iter;
2934 uint8_t format;
2935 port_id_t d_id;
2936
2937 rval = QLA_RSCNS_HANDLED;
2938
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002939 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
2940 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002942 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 format = MSB(MSW(rscn_entry));
2944 d_id.b.domain = LSB(MSW(rscn_entry));
2945 d_id.b.area = MSB(LSW(rscn_entry));
2946 d_id.b.al_pa = LSB(LSW(rscn_entry));
2947
2948 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2949 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002950 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 d_id.b.area, d_id.b.al_pa));
2952
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002953 vha->rscn_out_ptr++;
2954 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
2955 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956
2957 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002958 for (rscn_out_iter = vha->rscn_out_ptr;
2959 !vha->flags.rscn_queue_overflow &&
2960 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 rscn_out_iter = (rscn_out_iter ==
2962 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2963
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002964 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 break;
2966
2967 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002968 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 rscn_out_iter));
2970
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002971 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 }
2973
2974 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002975 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002977 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978
2979 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002980 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 }
2982
2983 switch (format) {
2984 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 mask = 0xffffff;
2986 break;
2987 case 1:
2988 mask = 0xffff00;
2989 break;
2990 case 2:
2991 mask = 0xff0000;
2992 break;
2993 default:
2994 mask = 0x0;
2995 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002996 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 break;
2998 }
2999
3000 rval = QLA_SUCCESS;
3001
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003002 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3004 (fcport->d_id.b24 & mask) != d_id.b24 ||
3005 fcport->port_type == FCT_BROADCAST)
3006 continue;
3007
3008 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3009 if (format != 3 ||
3010 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003011 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003012 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 }
3014 }
3015 fcport->flags &= ~FCF_FARP_DONE;
3016 }
3017 }
3018 return (rval);
3019}
3020
3021/*
3022 * qla2x00_fabric_dev_login
3023 * Login fabric target device and update FC port database.
3024 *
3025 * Input:
3026 * ha: adapter state pointer.
3027 * fcport: port structure list pointer.
3028 * next_loopid: contains value of a new loop ID that can be used
3029 * by the next login attempt.
3030 *
3031 * Returns:
3032 * qla2x00 local function return status code.
3033 *
3034 * Context:
3035 * Kernel context.
3036 */
3037static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003038qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 uint16_t *next_loopid)
3040{
3041 int rval;
3042 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003043 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003044 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045
3046 rval = QLA_SUCCESS;
3047 retry = 0;
3048
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003049 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050 if (rval == QLA_SUCCESS) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003051 /* Send an ADISC to tape devices.*/
3052 opts = 0;
3053 if (fcport->flags & FCF_TAPE_PRESENT)
3054 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003055 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003057 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003058 fcport->d_id.b.domain, fcport->d_id.b.area,
3059 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003060 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003062 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 }
3064 }
3065
3066 return (rval);
3067}
3068
3069/*
3070 * qla2x00_fabric_login
3071 * Issue fabric login command.
3072 *
3073 * Input:
3074 * ha = adapter block pointer.
3075 * device = pointer to FC device type structure.
3076 *
3077 * Returns:
3078 * 0 - Login successfully
3079 * 1 - Login failed
3080 * 2 - Initiator device
3081 * 3 - Fatal error
3082 */
3083int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003084qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085 uint16_t *next_loopid)
3086{
3087 int rval;
3088 int retry;
3089 uint16_t tmp_loopid;
3090 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003091 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092
3093 retry = 0;
3094 tmp_loopid = 0;
3095
3096 for (;;) {
3097 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3098 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003099 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3101
3102 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003103 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104 fcport->d_id.b.domain, fcport->d_id.b.area,
3105 fcport->d_id.b.al_pa, mb, BIT_0);
3106 if (mb[0] == MBS_PORT_ID_USED) {
3107 /*
3108 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003109 * recommends the driver perform an implicit login with
3110 * the specified ID again. The ID we just used is save
3111 * here so we return with an ID that can be tried by
3112 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 */
3114 retry++;
3115 tmp_loopid = fcport->loop_id;
3116 fcport->loop_id = mb[1];
3117
3118 DEBUG(printk("Fabric Login: port in use - next "
3119 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3120 fcport->loop_id, fcport->d_id.b.domain,
3121 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3122
3123 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3124 /*
3125 * Login succeeded.
3126 */
3127 if (retry) {
3128 /* A retry occurred before. */
3129 *next_loopid = tmp_loopid;
3130 } else {
3131 /*
3132 * No retry occurred before. Just increment the
3133 * ID value for next login.
3134 */
3135 *next_loopid = (fcport->loop_id + 1);
3136 }
3137
3138 if (mb[1] & BIT_0) {
3139 fcport->port_type = FCT_INITIATOR;
3140 } else {
3141 fcport->port_type = FCT_TARGET;
3142 if (mb[1] & BIT_1) {
3143 fcport->flags |= FCF_TAPE_PRESENT;
3144 }
3145 }
3146
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003147 if (mb[10] & BIT_0)
3148 fcport->supported_classes |= FC_COS_CLASS2;
3149 if (mb[10] & BIT_1)
3150 fcport->supported_classes |= FC_COS_CLASS3;
3151
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 rval = QLA_SUCCESS;
3153 break;
3154 } else if (mb[0] == MBS_LOOP_ID_USED) {
3155 /*
3156 * Loop ID already used, try next loop ID.
3157 */
3158 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003159 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 if (rval != QLA_SUCCESS) {
3161 /* Ran out of loop IDs to use */
3162 break;
3163 }
3164 } else if (mb[0] == MBS_COMMAND_ERROR) {
3165 /*
3166 * Firmware possibly timed out during login. If NO
3167 * retries are left to do then the device is declared
3168 * dead.
3169 */
3170 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003171 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003172 fcport->d_id.b.domain, fcport->d_id.b.area,
3173 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003174 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175
3176 rval = 1;
3177 break;
3178 } else {
3179 /*
3180 * unrecoverable / not handled error
3181 */
3182 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003183 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003184 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 fcport->d_id.b.domain, fcport->d_id.b.area,
3186 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3187
3188 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003189 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003190 fcport->d_id.b.domain, fcport->d_id.b.area,
3191 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003193 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194
3195 rval = 3;
3196 break;
3197 }
3198 }
3199
3200 return (rval);
3201}
3202
3203/*
3204 * qla2x00_local_device_login
3205 * Issue local device login command.
3206 *
3207 * Input:
3208 * ha = adapter block pointer.
3209 * loop_id = loop id of device to login to.
3210 *
3211 * Returns (Where's the #define!!!!):
3212 * 0 - Login successfully
3213 * 1 - Login failed
3214 * 3 - Fatal error
3215 */
3216int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003217qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218{
3219 int rval;
3220 uint16_t mb[MAILBOX_REGISTER_COUNT];
3221
3222 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003223 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224 if (rval == QLA_SUCCESS) {
3225 /* Interrogate mailbox registers for any errors */
3226 if (mb[0] == MBS_COMMAND_ERROR)
3227 rval = 1;
3228 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3229 /* device not in PCB table */
3230 rval = 3;
3231 }
3232
3233 return (rval);
3234}
3235
3236/*
3237 * qla2x00_loop_resync
3238 * Resync with fibre channel devices.
3239 *
3240 * Input:
3241 * ha = adapter block pointer.
3242 *
3243 * Returns:
3244 * 0 = success
3245 */
3246int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003247qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003249 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250 uint32_t wait_time;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003251 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003252 struct req_que *req = ha->req_q_map[vha->req_ques[0]];
3253 struct rsp_que *rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003255 atomic_set(&vha->loop_state, LOOP_UPDATE);
3256 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3257 if (vha->flags.online) {
3258 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3260 wait_time = 256;
3261 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003262 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003264 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003265 qla2x00_marker(vha, req, rsp, 0, 0,
3266 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003267 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268
3269 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003270 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003272 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003274 } while (!atomic_read(&vha->loop_down_timer) &&
3275 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3276 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3277 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279 }
3280
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003281 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003284 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286
3287 return (rval);
3288}
3289
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003291qla2x00_update_fcports(scsi_qla_host_t *vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003292{
3293 fc_port_t *fcport;
3294
3295 /* Go with deferred removal of rport references. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003296 list_for_each_entry(fcport, &vha->vp_fcports, list)
3297 if (fcport && fcport->drport &&
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07003298 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003299 qla2x00_rport_del(fcport);
3300}
3301
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302/*
3303* qla2x00_abort_isp
3304* Resets ISP and aborts all outstanding commands.
3305*
3306* Input:
3307* ha = adapter block pointer.
3308*
3309* Returns:
3310* 0 = success
3311*/
3312int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003313qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003315 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003317 struct qla_hw_data *ha = vha->hw;
3318 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003319 struct scsi_qla_host *tvp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003320 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003322 if (vha->flags.online) {
3323 vha->flags.online = 0;
3324 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07003325 ha->qla_stats.total_isp_aborts++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326
3327 qla_printk(KERN_INFO, ha,
3328 "Performing ISP error recovery - ha= %p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003329 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003331 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3332 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3333 atomic_set(&vha->loop_state, LOOP_DOWN);
3334 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003335 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003336 qla2x00_mark_all_devices_lost(vp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003338 if (!atomic_read(&vha->loop_down_timer))
3339 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340 LOOP_DOWN_TIME);
3341 }
3342
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343 /* Requeue all commands in outstanding command list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003344 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003346 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003347
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003348 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003350 if (!qla2x00_restart_isp(vha)) {
3351 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003353 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354 /*
3355 * Issue marker command only when we are going
3356 * to start the I/O .
3357 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003358 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 }
3360
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003361 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003363 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003365 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003366 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003367
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003368 if (ha->fce) {
3369 ha->flags.fce_enabled = 1;
3370 memset(ha->fce, 0,
3371 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003372 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003373 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3374 &ha->fce_bufs);
3375 if (rval) {
3376 qla_printk(KERN_WARNING, ha,
3377 "Unable to reinitialize FCE "
3378 "(%d).\n", rval);
3379 ha->flags.fce_enabled = 0;
3380 }
3381 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003382
3383 if (ha->eft) {
3384 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003385 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003386 ha->eft_dma, EFT_NUM_BUFFERS);
3387 if (rval) {
3388 qla_printk(KERN_WARNING, ha,
3389 "Unable to reinitialize EFT "
3390 "(%d).\n", rval);
3391 }
3392 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003394 vha->flags.online = 1;
3395 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396 if (ha->isp_abort_cnt == 0) {
3397 qla_printk(KERN_WARNING, ha,
3398 "ISP error recovery failed - "
3399 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003400 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003401 * The next call disables the board
3402 * completely.
3403 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003404 ha->isp_ops->reset_adapter(vha);
3405 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003407 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003408 status = 0;
3409 } else { /* schedule another ISP abort */
3410 ha->isp_abort_cnt--;
3411 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003412 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003413 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414 status = 1;
3415 }
3416 } else {
3417 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3418 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3419 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003420 vha->host_no, ha->isp_abort_cnt));
3421 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422 status = 1;
3423 }
3424 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003425
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426 }
3427
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003428 if (!status) {
3429 DEBUG(printk(KERN_INFO
3430 "qla2x00_abort_isp(%ld): succeeded.\n",
3431 vha->host_no));
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003432 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003433 if (vp->vp_idx)
3434 qla2x00_vp_abort_isp(vp);
3435 }
3436 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 qla_printk(KERN_INFO, ha,
3438 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439 }
3440
3441 return(status);
3442}
3443
3444/*
3445* qla2x00_restart_isp
3446* restarts the ISP after a reset
3447*
3448* Input:
3449* ha = adapter block pointer.
3450*
3451* Returns:
3452* 0 = success
3453*/
3454static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003455qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003457 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003459 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003460 struct req_que *req = ha->req_q_map[0];
3461 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462
3463 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003464 if (qla2x00_isp_firmware(vha)) {
3465 vha->flags.online = 0;
3466 status = ha->isp_ops->chip_diag(vha);
3467 if (!status)
3468 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469 }
3470
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003471 if (!status && !(status = qla2x00_init_rings(vha))) {
3472 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003473 /* Initialize the queues in use */
3474 qla25xx_init_queues(ha);
3475
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003476 status = qla2x00_fw_ready(vha);
3477 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003478 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003479 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003480
3481 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003482 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003483
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003484 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3486 wait_time = 256;
3487 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003488 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3489 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003491 } while (!atomic_read(&vha->loop_down_timer) &&
3492 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3493 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3494 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495 }
3496
3497 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003498 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499 status = 0;
3500
3501 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3502 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003503 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504 }
3505 return (status);
3506}
3507
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003508static int
3509qla25xx_init_queues(struct qla_hw_data *ha)
3510{
3511 struct rsp_que *rsp = NULL;
3512 struct req_que *req = NULL;
3513 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3514 int ret = -1;
3515 int i;
3516
3517 for (i = 1; i < ha->max_queues; i++) {
3518 rsp = ha->rsp_q_map[i];
3519 if (rsp) {
3520 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003521 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003522 if (ret != QLA_SUCCESS)
3523 DEBUG2_17(printk(KERN_WARNING
3524 "%s Rsp que:%d init failed\n", __func__,
3525 rsp->id));
3526 else
3527 DEBUG2_17(printk(KERN_INFO
3528 "%s Rsp que:%d inited\n", __func__,
3529 rsp->id));
3530 }
3531 req = ha->req_q_map[i];
3532 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003533 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003534 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003535 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003536 if (ret != QLA_SUCCESS)
3537 DEBUG2_17(printk(KERN_WARNING
3538 "%s Req que:%d init failed\n", __func__,
3539 req->id));
3540 else
3541 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003542 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003543 req->id));
3544 }
3545 }
3546 return ret;
3547}
3548
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549/*
3550* qla2x00_reset_adapter
3551* Reset adapter.
3552*
3553* Input:
3554* ha = adapter block pointer.
3555*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003556void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003557qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003558{
3559 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003560 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003561 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003563 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003564 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003565
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566 spin_lock_irqsave(&ha->hardware_lock, flags);
3567 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3568 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3569 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3570 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3571 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3572}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003573
3574void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003575qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003576{
3577 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003578 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003579 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3580
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003581 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003582 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003583
3584 spin_lock_irqsave(&ha->hardware_lock, flags);
3585 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3586 RD_REG_DWORD(&reg->hccr);
3587 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3588 RD_REG_DWORD(&reg->hccr);
3589 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08003590
3591 if (IS_NOPOLLING_TYPE(ha))
3592 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003593}
3594
David Miller4e08df32007-04-16 12:37:43 -07003595/* On sparc systems, obtain port and node WWN from firmware
3596 * properties.
3597 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003598static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3599 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07003600{
3601#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003602 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003603 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003604 struct device_node *dp = pci_device_to_OF_node(pdev);
3605 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003606 int len;
3607
3608 val = of_get_property(dp, "port-wwn", &len);
3609 if (val && len >= WWN_SIZE)
3610 memcpy(nv->port_name, val, WWN_SIZE);
3611
3612 val = of_get_property(dp, "node-wwn", &len);
3613 if (val && len >= WWN_SIZE)
3614 memcpy(nv->node_name, val, WWN_SIZE);
3615#endif
3616}
3617
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003618int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003619qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003620{
David Miller4e08df32007-04-16 12:37:43 -07003621 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003622 struct init_cb_24xx *icb;
3623 struct nvram_24xx *nv;
3624 uint32_t *dptr;
3625 uint8_t *dptr1, *dptr2;
3626 uint32_t chksum;
3627 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003628 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003629
David Miller4e08df32007-04-16 12:37:43 -07003630 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003631 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003632 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003633
3634 /* Determine NVRAM starting address. */
3635 ha->nvram_size = sizeof(struct nvram_24xx);
3636 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003637 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3638 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3639 if (PCI_FUNC(ha->pdev->devfn)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003640 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003641 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3642 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003643
Seokmann Ju281afe12007-07-26 13:43:34 -07003644 /* Get VPD data into cache */
3645 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003646 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07003647 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3648
3649 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003650 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003651 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003652 ha->nvram_size);
3653 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3654 chksum += le32_to_cpu(*dptr++);
3655
3656 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07003657 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003658
3659 /* Bad NVRAM data, set defaults parameters. */
3660 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3661 || nv->id[3] != ' ' ||
3662 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3663 /* Reset NVRAM data. */
3664 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3665 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3666 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07003667 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3668 "invalid -- WWPN) defaults.\n");
3669
3670 /*
3671 * Set default initialization control block.
3672 */
3673 memset(nv, 0, ha->nvram_size);
3674 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3675 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3676 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3677 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3678 nv->exchange_count = __constant_cpu_to_le16(0);
3679 nv->hard_address = __constant_cpu_to_le16(124);
3680 nv->port_name[0] = 0x21;
3681 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3682 nv->port_name[2] = 0x00;
3683 nv->port_name[3] = 0xe0;
3684 nv->port_name[4] = 0x8b;
3685 nv->port_name[5] = 0x1c;
3686 nv->port_name[6] = 0x55;
3687 nv->port_name[7] = 0x86;
3688 nv->node_name[0] = 0x20;
3689 nv->node_name[1] = 0x00;
3690 nv->node_name[2] = 0x00;
3691 nv->node_name[3] = 0xe0;
3692 nv->node_name[4] = 0x8b;
3693 nv->node_name[5] = 0x1c;
3694 nv->node_name[6] = 0x55;
3695 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003696 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07003697 nv->login_retry_count = __constant_cpu_to_le16(8);
3698 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3699 nv->login_timeout = __constant_cpu_to_le16(0);
3700 nv->firmware_options_1 =
3701 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3702 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3703 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3704 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3705 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3706 nv->efi_parameters = __constant_cpu_to_le32(0);
3707 nv->reset_delay = 5;
3708 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3709 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3710 nv->link_down_timeout = __constant_cpu_to_le16(30);
3711
3712 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003713 }
3714
3715 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003716 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003717
3718 /* Copy 1st segment. */
3719 dptr1 = (uint8_t *)icb;
3720 dptr2 = (uint8_t *)&nv->version;
3721 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3722 while (cnt--)
3723 *dptr1++ = *dptr2++;
3724
3725 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07003726 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003727
3728 /* Copy 2nd segment. */
3729 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3730 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3731 cnt = (uint8_t *)&icb->reserved_3 -
3732 (uint8_t *)&icb->interrupt_delay_timer;
3733 while (cnt--)
3734 *dptr1++ = *dptr2++;
3735
3736 /*
3737 * Setup driver NVRAM options.
3738 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003739 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003740 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003741
Andrew Vasquez5341e862006-05-17 15:09:16 -07003742 /* Use alternate WWN? */
3743 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3744 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3745 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3746 }
3747
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003748 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003749 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003750 /*
3751 * Firmware will apply the following mask if the nodename was
3752 * not provided.
3753 */
3754 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3755 icb->node_name[0] &= 0xF0;
3756 }
3757
3758 /* Set host adapter parameters. */
3759 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08003760 ha->flags.enable_lip_reset = 0;
3761 ha->flags.enable_lip_full_login =
3762 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3763 ha->flags.enable_target_reset =
3764 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003765 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07003766 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003767
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003768 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3769 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003770
3771 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3772 sizeof(ha->fw_seriallink_options24));
3773
3774 /* save HBA serial number */
3775 ha->serial0 = icb->port_name[5];
3776 ha->serial1 = icb->port_name[6];
3777 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003778 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
3779 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003780
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08003781 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3782
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003783 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3784
3785 /* Set minimum login_timeout to 4 seconds. */
3786 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3787 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3788 if (le16_to_cpu(nv->login_timeout) < 4)
3789 nv->login_timeout = __constant_cpu_to_le16(4);
3790 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07003791 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003792
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003793 /* Set minimum RATOV to 100 tenths of a second. */
3794 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003795
3796 ha->loop_reset_delay = nv->reset_delay;
3797
3798 /* Link Down Timeout = 0:
3799 *
3800 * When Port Down timer expires we will start returning
3801 * I/O's to OS with "DID_NO_CONNECT".
3802 *
3803 * Link Down Timeout != 0:
3804 *
3805 * The driver waits for the link to come up after link down
3806 * before returning I/Os to OS with "DID_NO_CONNECT".
3807 */
3808 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3809 ha->loop_down_abort_time =
3810 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3811 } else {
3812 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3813 ha->loop_down_abort_time =
3814 (LOOP_DOWN_TIME - ha->link_down_timeout);
3815 }
3816
3817 /* Need enough time to try and get the port back. */
3818 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3819 if (qlport_down_retry)
3820 ha->port_down_retry_count = qlport_down_retry;
3821
3822 /* Set login_retry_count */
3823 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3824 if (ha->port_down_retry_count ==
3825 le16_to_cpu(nv->port_down_retry_count) &&
3826 ha->port_down_retry_count > 3)
3827 ha->login_retry_count = ha->port_down_retry_count;
3828 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3829 ha->login_retry_count = ha->port_down_retry_count;
3830 if (ql2xloginretrycount)
3831 ha->login_retry_count = ql2xloginretrycount;
3832
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003833 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003834 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003835 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3836 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3837 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3838 le16_to_cpu(icb->interrupt_delay_timer): 2;
3839 }
3840 icb->firmware_options_2 &= __constant_cpu_to_le32(
3841 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003842 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003843 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08003844 ha->zio_mode = QLA_ZIO_MODE_6;
3845
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003846 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003847 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003848 ha->zio_timer * 100));
3849 qla_printk(KERN_INFO, ha,
3850 "ZIO mode %d enabled; timer delay (%d us).\n",
3851 ha->zio_mode, ha->zio_timer * 100);
3852
3853 icb->firmware_options_2 |= cpu_to_le32(
3854 (uint32_t)ha->zio_mode);
3855 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003856 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003857 }
3858
David Miller4e08df32007-04-16 12:37:43 -07003859 if (rval) {
3860 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003861 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07003862 }
3863 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003864}
3865
Adrian Bunk413975a2006-06-30 02:33:06 -07003866static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003867qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003868{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003869 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003870 int segments, fragment;
3871 uint32_t faddr;
3872 uint32_t *dcode, dlen;
3873 uint32_t risc_addr;
3874 uint32_t risc_size;
3875 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003876 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003877 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08003878
3879 qla_printk(KERN_INFO, ha,
3880 "FW: Loading from flash (%x)...\n", ha->flt_region_fw);
3881
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003882 rval = QLA_SUCCESS;
3883
3884 segments = FA_RISC_CODE_SEGMENTS;
Andrew Vasquezc00d8992008-09-11 21:22:49 -07003885 faddr = ha->flt_region_fw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003886 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003887 *srisc_addr = 0;
3888
3889 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003890 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003891 for (i = 0; i < 4; i++)
3892 dcode[i] = be32_to_cpu(dcode[i]);
3893 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3894 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3895 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3896 dcode[3] == 0)) {
3897 qla_printk(KERN_WARNING, ha,
3898 "Unable to verify integrity of flash firmware image!\n");
3899 qla_printk(KERN_WARNING, ha,
3900 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3901 dcode[1], dcode[2], dcode[3]);
3902
3903 return QLA_FUNCTION_FAILED;
3904 }
3905
3906 while (segments && rval == QLA_SUCCESS) {
3907 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003908 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003909
3910 risc_addr = be32_to_cpu(dcode[2]);
3911 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3912 risc_size = be32_to_cpu(dcode[3]);
3913
3914 fragment = 0;
3915 while (risc_size > 0 && rval == QLA_SUCCESS) {
3916 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3917 if (dlen > risc_size)
3918 dlen = risc_size;
3919
3920 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3921 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003922 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003923
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003924 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003925 for (i = 0; i < dlen; i++)
3926 dcode[i] = swab32(dcode[i]);
3927
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003928 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003929 dlen);
3930 if (rval) {
3931 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003932 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003933 fragment));
3934 qla_printk(KERN_WARNING, ha,
3935 "[ERROR] Failed to load segment %d of "
3936 "firmware\n", fragment);
3937 break;
3938 }
3939
3940 faddr += dlen;
3941 risc_addr += dlen;
3942 risc_size -= dlen;
3943 fragment++;
3944 }
3945
3946 /* Next segment. */
3947 segments--;
3948 }
3949
3950 return rval;
3951}
3952
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003953#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3954
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003955int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003956qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08003957{
3958 int rval;
3959 int i, fragment;
3960 uint16_t *wcode, *fwcode;
3961 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3962 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003963 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003964 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08003965
3966 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003967 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08003968 if (!blob) {
3969 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003970 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3971 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08003972 return QLA_FUNCTION_FAILED;
3973 }
3974
3975 rval = QLA_SUCCESS;
3976
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003977 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08003978 *srisc_addr = 0;
3979 fwcode = (uint16_t *)blob->fw->data;
3980 fwclen = 0;
3981
3982 /* Validate firmware image by checking version. */
3983 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3984 qla_printk(KERN_WARNING, ha,
3985 "Unable to verify integrity of firmware image (%Zd)!\n",
3986 blob->fw->size);
3987 goto fail_fw_integrity;
3988 }
3989 for (i = 0; i < 4; i++)
3990 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3991 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3992 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3993 wcode[2] == 0 && wcode[3] == 0)) {
3994 qla_printk(KERN_WARNING, ha,
3995 "Unable to verify integrity of firmware image!\n");
3996 qla_printk(KERN_WARNING, ha,
3997 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3998 wcode[1], wcode[2], wcode[3]);
3999 goto fail_fw_integrity;
4000 }
4001
4002 seg = blob->segs;
4003 while (*seg && rval == QLA_SUCCESS) {
4004 risc_addr = *seg;
4005 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4006 risc_size = be16_to_cpu(fwcode[3]);
4007
4008 /* Validate firmware image size. */
4009 fwclen += risc_size * sizeof(uint16_t);
4010 if (blob->fw->size < fwclen) {
4011 qla_printk(KERN_WARNING, ha,
4012 "Unable to verify integrity of firmware image "
4013 "(%Zd)!\n", blob->fw->size);
4014 goto fail_fw_integrity;
4015 }
4016
4017 fragment = 0;
4018 while (risc_size > 0 && rval == QLA_SUCCESS) {
4019 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4020 if (wlen > risc_size)
4021 wlen = risc_size;
4022
4023 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004024 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004025 risc_addr, wlen));
4026
4027 for (i = 0; i < wlen; i++)
4028 wcode[i] = swab16(fwcode[i]);
4029
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004030 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004031 wlen);
4032 if (rval) {
4033 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004034 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004035 fragment));
4036 qla_printk(KERN_WARNING, ha,
4037 "[ERROR] Failed to load segment %d of "
4038 "firmware\n", fragment);
4039 break;
4040 }
4041
4042 fwcode += wlen;
4043 risc_addr += wlen;
4044 risc_size -= wlen;
4045 fragment++;
4046 }
4047
4048 /* Next segment. */
4049 seg++;
4050 }
4051 return rval;
4052
4053fail_fw_integrity:
4054 return QLA_FUNCTION_FAILED;
4055}
4056
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004057static int
4058qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004059{
4060 int rval;
4061 int segments, fragment;
4062 uint32_t *dcode, dlen;
4063 uint32_t risc_addr;
4064 uint32_t risc_size;
4065 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004066 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004067 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004068 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004069 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004070
Andrew Vasquez54333832005-11-09 15:49:04 -08004071 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004072 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004073 if (!blob) {
4074 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004075 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4076 "from: " QLA_FW_URL ".\n");
4077
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004078 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004079 }
4080
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004081 qla_printk(KERN_INFO, ha,
4082 "FW: Loading via request-firmware...\n");
4083
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004084 rval = QLA_SUCCESS;
4085
4086 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004087 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004088 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004089 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004090 fwclen = 0;
4091
4092 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004093 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004094 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004095 "Unable to verify integrity of firmware image (%Zd)!\n",
4096 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004097 goto fail_fw_integrity;
4098 }
4099 for (i = 0; i < 4; i++)
4100 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4101 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4102 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4103 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4104 dcode[3] == 0)) {
4105 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004106 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004107 qla_printk(KERN_WARNING, ha,
4108 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4109 dcode[1], dcode[2], dcode[3]);
4110 goto fail_fw_integrity;
4111 }
4112
4113 while (segments && rval == QLA_SUCCESS) {
4114 risc_addr = be32_to_cpu(fwcode[2]);
4115 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4116 risc_size = be32_to_cpu(fwcode[3]);
4117
4118 /* Validate firmware image size. */
4119 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004120 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004121 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004122 "Unable to verify integrity of firmware image "
4123 "(%Zd)!\n", blob->fw->size);
4124
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004125 goto fail_fw_integrity;
4126 }
4127
4128 fragment = 0;
4129 while (risc_size > 0 && rval == QLA_SUCCESS) {
4130 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4131 if (dlen > risc_size)
4132 dlen = risc_size;
4133
4134 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004135 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004136 risc_addr, dlen));
4137
4138 for (i = 0; i < dlen; i++)
4139 dcode[i] = swab32(fwcode[i]);
4140
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004141 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004142 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004143 if (rval) {
4144 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004145 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004146 fragment));
4147 qla_printk(KERN_WARNING, ha,
4148 "[ERROR] Failed to load segment %d of "
4149 "firmware\n", fragment);
4150 break;
4151 }
4152
4153 fwcode += dlen;
4154 risc_addr += dlen;
4155 risc_size -= dlen;
4156 fragment++;
4157 }
4158
4159 /* Next segment. */
4160 segments--;
4161 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004162 return rval;
4163
4164fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004165 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004166}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004167
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004168int
4169qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4170{
4171 int rval;
4172
4173 /*
4174 * FW Load priority:
4175 * 1) Firmware via request-firmware interface (.bin file).
4176 * 2) Firmware residing in flash.
4177 */
4178 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4179 if (rval == QLA_SUCCESS)
4180 return rval;
4181
4182 return qla24xx_load_risc_flash(vha, srisc_addr);
4183}
4184
4185int
4186qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4187{
4188 int rval;
4189
4190 /*
4191 * FW Load priority:
4192 * 1) Firmware residing in flash.
4193 * 2) Firmware via request-firmware interface (.bin file).
4194 */
4195 rval = qla24xx_load_risc_flash(vha, srisc_addr);
4196 if (rval == QLA_SUCCESS)
4197 return rval;
4198
4199 return qla24xx_load_risc_blob(vha, srisc_addr);
4200}
4201
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004202void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004203qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004204{
4205 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004206 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004207
Andrew Vasqueze4289242007-07-19 15:05:56 -07004208 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004209 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004210 if (!ha->fw_major_version)
4211 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004212
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004213 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004214 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
4215 retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004216 ha->isp_ops->reset_chip(vha);
4217 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004218 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004219 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004220 continue;
4221 qla_printk(KERN_INFO, ha,
4222 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004223 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004224 }
4225}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004226
4227int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004228qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004229{
4230 int rval = QLA_SUCCESS;
4231 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004232 struct qla_hw_data *ha = vha->hw;
4233 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004234 struct req_que *req = ha->req_q_map[vha->req_ques[0]];
4235 struct rsp_que *rsp = req->rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004236
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004237 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004238 return -EINVAL;
4239
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004240 rval = qla2x00_fw_ready(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004241 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004242 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004243 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004244 }
4245
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004246 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004247
4248 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004249 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004250 if (mb[0] != MBS_COMMAND_COMPLETE) {
4251 DEBUG15(qla_printk(KERN_INFO, ha,
4252 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4253 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4254 mb[0], mb[1], mb[2], mb[6], mb[7]));
4255 return (QLA_FUNCTION_FAILED);
4256 }
4257
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004258 atomic_set(&vha->loop_down_timer, 0);
4259 atomic_set(&vha->loop_state, LOOP_UP);
4260 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4261 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4262 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004263
4264 return rval;
4265}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004266
4267/* 84XX Support **************************************************************/
4268
4269static LIST_HEAD(qla_cs84xx_list);
4270static DEFINE_MUTEX(qla_cs84xx_mutex);
4271
4272static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004273qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004274{
4275 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004276 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004277
4278 mutex_lock(&qla_cs84xx_mutex);
4279
4280 /* Find any shared 84xx chip. */
4281 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4282 if (cs84xx->bus == ha->pdev->bus) {
4283 kref_get(&cs84xx->kref);
4284 goto done;
4285 }
4286 }
4287
4288 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4289 if (!cs84xx)
4290 goto done;
4291
4292 kref_init(&cs84xx->kref);
4293 spin_lock_init(&cs84xx->access_lock);
4294 mutex_init(&cs84xx->fw_update_mutex);
4295 cs84xx->bus = ha->pdev->bus;
4296
4297 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4298done:
4299 mutex_unlock(&qla_cs84xx_mutex);
4300 return cs84xx;
4301}
4302
4303static void
4304__qla84xx_chip_release(struct kref *kref)
4305{
4306 struct qla_chip_state_84xx *cs84xx =
4307 container_of(kref, struct qla_chip_state_84xx, kref);
4308
4309 mutex_lock(&qla_cs84xx_mutex);
4310 list_del(&cs84xx->list);
4311 mutex_unlock(&qla_cs84xx_mutex);
4312 kfree(cs84xx);
4313}
4314
4315void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004316qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004317{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004318 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004319 if (ha->cs84xx)
4320 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4321}
4322
4323static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004324qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004325{
4326 int rval;
4327 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004328 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004329
4330 mutex_lock(&ha->cs84xx->fw_update_mutex);
4331
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004332 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004333
4334 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4335
4336 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4337 QLA_SUCCESS;
4338}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004339
4340/* 81XX Support **************************************************************/
4341
4342int
4343qla81xx_nvram_config(scsi_qla_host_t *vha)
4344{
4345 int rval;
4346 struct init_cb_81xx *icb;
4347 struct nvram_81xx *nv;
4348 uint32_t *dptr;
4349 uint8_t *dptr1, *dptr2;
4350 uint32_t chksum;
4351 uint16_t cnt;
4352 struct qla_hw_data *ha = vha->hw;
4353
4354 rval = QLA_SUCCESS;
4355 icb = (struct init_cb_81xx *)ha->init_cb;
4356 nv = ha->nvram;
4357
4358 /* Determine NVRAM starting address. */
4359 ha->nvram_size = sizeof(struct nvram_81xx);
4360 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4361 ha->vpd_size = FA_NVRAM_VPD_SIZE;
4362 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4363 if (PCI_FUNC(ha->pdev->devfn) & 1) {
4364 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
4365 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4366 }
4367
4368 /* Get VPD data into cache */
4369 ha->vpd = ha->nvram + VPD_OFFSET;
4370 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
4371 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4372
4373 /* Get NVRAM data into cache and calculate checksum. */
4374 dptr = (uint32_t *)nv;
4375 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
4376 ha->nvram_size);
4377 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4378 chksum += le32_to_cpu(*dptr++);
4379
4380 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
4381 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4382
4383 /* Bad NVRAM data, set defaults parameters. */
4384 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4385 || nv->id[3] != ' ' ||
4386 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4387 /* Reset NVRAM data. */
4388 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4389 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4390 le16_to_cpu(nv->nvram_version));
4391 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4392 "invalid -- WWPN) defaults.\n");
4393
4394 /*
4395 * Set default initialization control block.
4396 */
4397 memset(nv, 0, ha->nvram_size);
4398 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4399 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4400 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4401 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4402 nv->exchange_count = __constant_cpu_to_le16(0);
4403 nv->port_name[0] = 0x21;
4404 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
4405 nv->port_name[2] = 0x00;
4406 nv->port_name[3] = 0xe0;
4407 nv->port_name[4] = 0x8b;
4408 nv->port_name[5] = 0x1c;
4409 nv->port_name[6] = 0x55;
4410 nv->port_name[7] = 0x86;
4411 nv->node_name[0] = 0x20;
4412 nv->node_name[1] = 0x00;
4413 nv->node_name[2] = 0x00;
4414 nv->node_name[3] = 0xe0;
4415 nv->node_name[4] = 0x8b;
4416 nv->node_name[5] = 0x1c;
4417 nv->node_name[6] = 0x55;
4418 nv->node_name[7] = 0x86;
4419 nv->login_retry_count = __constant_cpu_to_le16(8);
4420 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4421 nv->login_timeout = __constant_cpu_to_le16(0);
4422 nv->firmware_options_1 =
4423 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4424 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4425 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4426 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4427 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4428 nv->efi_parameters = __constant_cpu_to_le32(0);
4429 nv->reset_delay = 5;
4430 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4431 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4432 nv->link_down_timeout = __constant_cpu_to_le16(30);
4433 nv->enode_mac[0] = 0x01;
4434 nv->enode_mac[1] = 0x02;
4435 nv->enode_mac[2] = 0x03;
4436 nv->enode_mac[3] = 0x04;
4437 nv->enode_mac[4] = 0x05;
4438 nv->enode_mac[5] = 0x06 + PCI_FUNC(ha->pdev->devfn);
4439
4440 rval = 1;
4441 }
4442
4443 /* Reset Initialization control block */
4444 memset(icb, 0, sizeof(struct init_cb_81xx));
4445
4446 /* Copy 1st segment. */
4447 dptr1 = (uint8_t *)icb;
4448 dptr2 = (uint8_t *)&nv->version;
4449 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4450 while (cnt--)
4451 *dptr1++ = *dptr2++;
4452
4453 icb->login_retry_count = nv->login_retry_count;
4454
4455 /* Copy 2nd segment. */
4456 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4457 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4458 cnt = (uint8_t *)&icb->reserved_5 -
4459 (uint8_t *)&icb->interrupt_delay_timer;
4460 while (cnt--)
4461 *dptr1++ = *dptr2++;
4462
4463 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
4464 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4465 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
4466 icb->enode_mac[0] = 0x01;
4467 icb->enode_mac[1] = 0x02;
4468 icb->enode_mac[2] = 0x03;
4469 icb->enode_mac[3] = 0x04;
4470 icb->enode_mac[4] = 0x05;
4471 icb->enode_mac[5] = 0x06 + PCI_FUNC(ha->pdev->devfn);
4472 }
4473
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004474 /* Use extended-initialization control block. */
4475 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
4476
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004477 /*
4478 * Setup driver NVRAM options.
4479 */
4480 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
4481 "QLE81XX");
4482
4483 /* Use alternate WWN? */
4484 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4485 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4486 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4487 }
4488
4489 /* Prepare nodename */
4490 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4491 /*
4492 * Firmware will apply the following mask if the nodename was
4493 * not provided.
4494 */
4495 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4496 icb->node_name[0] &= 0xF0;
4497 }
4498
4499 /* Set host adapter parameters. */
4500 ha->flags.disable_risc_code_load = 0;
4501 ha->flags.enable_lip_reset = 0;
4502 ha->flags.enable_lip_full_login =
4503 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4504 ha->flags.enable_target_reset =
4505 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4506 ha->flags.enable_led_scheme = 0;
4507 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4508
4509 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4510 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4511
4512 /* save HBA serial number */
4513 ha->serial0 = icb->port_name[5];
4514 ha->serial1 = icb->port_name[6];
4515 ha->serial2 = icb->port_name[7];
4516 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4517 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4518
4519 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4520
4521 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4522
4523 /* Set minimum login_timeout to 4 seconds. */
4524 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4525 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4526 if (le16_to_cpu(nv->login_timeout) < 4)
4527 nv->login_timeout = __constant_cpu_to_le16(4);
4528 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4529 icb->login_timeout = nv->login_timeout;
4530
4531 /* Set minimum RATOV to 100 tenths of a second. */
4532 ha->r_a_tov = 100;
4533
4534 ha->loop_reset_delay = nv->reset_delay;
4535
4536 /* Link Down Timeout = 0:
4537 *
4538 * When Port Down timer expires we will start returning
4539 * I/O's to OS with "DID_NO_CONNECT".
4540 *
4541 * Link Down Timeout != 0:
4542 *
4543 * The driver waits for the link to come up after link down
4544 * before returning I/Os to OS with "DID_NO_CONNECT".
4545 */
4546 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4547 ha->loop_down_abort_time =
4548 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4549 } else {
4550 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4551 ha->loop_down_abort_time =
4552 (LOOP_DOWN_TIME - ha->link_down_timeout);
4553 }
4554
4555 /* Need enough time to try and get the port back. */
4556 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4557 if (qlport_down_retry)
4558 ha->port_down_retry_count = qlport_down_retry;
4559
4560 /* Set login_retry_count */
4561 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4562 if (ha->port_down_retry_count ==
4563 le16_to_cpu(nv->port_down_retry_count) &&
4564 ha->port_down_retry_count > 3)
4565 ha->login_retry_count = ha->port_down_retry_count;
4566 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4567 ha->login_retry_count = ha->port_down_retry_count;
4568 if (ql2xloginretrycount)
4569 ha->login_retry_count = ql2xloginretrycount;
4570
4571 /* Enable ZIO. */
4572 if (!vha->flags.init_done) {
4573 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4574 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4575 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4576 le16_to_cpu(icb->interrupt_delay_timer): 2;
4577 }
4578 icb->firmware_options_2 &= __constant_cpu_to_le32(
4579 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4580 vha->flags.process_response_queue = 0;
4581 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4582 ha->zio_mode = QLA_ZIO_MODE_6;
4583
4584 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4585 "(%d us).\n", vha->host_no, ha->zio_mode,
4586 ha->zio_timer * 100));
4587 qla_printk(KERN_INFO, ha,
4588 "ZIO mode %d enabled; timer delay (%d us).\n",
4589 ha->zio_mode, ha->zio_timer * 100);
4590
4591 icb->firmware_options_2 |= cpu_to_le32(
4592 (uint32_t)ha->zio_mode);
4593 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4594 vha->flags.process_response_queue = 1;
4595 }
4596
4597 if (rval) {
4598 DEBUG2_3(printk(KERN_WARNING
4599 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4600 }
4601 return (rval);
4602}
4603
4604void
4605qla81xx_update_fw_options(scsi_qla_host_t *ha)
4606{
4607}