blob: 0febfa648c34807134a9bfcf717cd2b694c0c58c [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
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 if (rval) {
1036 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001037 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 }
1039
1040 return (rval);
1041}
1042
1043/**
1044 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1045 * @ha: HA context
1046 *
1047 * Beginning of request ring has initialization control block already built
1048 * by nvram config routine.
1049 *
1050 * Returns 0 on success.
1051 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001052void
1053qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054{
1055 uint16_t cnt;
1056 response_t *pkt;
1057
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001058 pkt = rsp->ring_ptr;
1059 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 pkt->signature = RESPONSE_PROCESSED;
1061 pkt++;
1062 }
1063
1064}
1065
1066/**
1067 * qla2x00_update_fw_options() - Read and process firmware options.
1068 * @ha: HA context
1069 *
1070 * Returns 0 on success.
1071 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001072void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001073qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074{
1075 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001076 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
1078 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001079 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
1081 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1082 return;
1083
1084 /* Serial Link options. */
1085 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001086 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1088 sizeof(ha->fw_seriallink_options)));
1089
1090 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1091 if (ha->fw_seriallink_options[3] & BIT_2) {
1092 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1093
1094 /* 1G settings */
1095 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1096 emphasis = (ha->fw_seriallink_options[2] &
1097 (BIT_4 | BIT_3)) >> 3;
1098 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001099 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 rx_sens = (ha->fw_seriallink_options[0] &
1101 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1102 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1103 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1104 if (rx_sens == 0x0)
1105 rx_sens = 0x3;
1106 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1107 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1108 ha->fw_options[10] |= BIT_5 |
1109 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1110 (tx_sens & (BIT_1 | BIT_0));
1111
1112 /* 2G settings */
1113 swing = (ha->fw_seriallink_options[2] &
1114 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1115 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1116 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001117 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 rx_sens = (ha->fw_seriallink_options[1] &
1119 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1120 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1121 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1122 if (rx_sens == 0x0)
1123 rx_sens = 0x3;
1124 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1125 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1126 ha->fw_options[11] |= BIT_5 |
1127 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1128 (tx_sens & (BIT_1 | BIT_0));
1129 }
1130
1131 /* FCP2 options. */
1132 /* Return command IOCBs without waiting for an ABTS to complete. */
1133 ha->fw_options[3] |= BIT_13;
1134
1135 /* LED scheme. */
1136 if (ha->flags.enable_led_scheme)
1137 ha->fw_options[2] |= BIT_12;
1138
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001139 /* Detect ISP6312. */
1140 if (IS_QLA6312(ha))
1141 ha->fw_options[2] |= BIT_13;
1142
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001144 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145}
1146
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001147void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001148qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001149{
1150 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001151 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001152
1153 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001154 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001155 return;
1156
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001157 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001158 le16_to_cpu(ha->fw_seriallink_options24[1]),
1159 le16_to_cpu(ha->fw_seriallink_options24[2]),
1160 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001161 if (rval != QLA_SUCCESS) {
1162 qla_printk(KERN_WARNING, ha,
1163 "Unable to update Serial Link options (%x).\n", rval);
1164 }
1165}
1166
1167void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001168qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001169{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001170 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001171 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001172 struct req_que *req = ha->req_q_map[0];
1173 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001174
1175 /* Setup ring parameters in initialization control block. */
1176 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1177 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001178 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1179 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1180 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1181 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1182 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1183 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001184
1185 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1186 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1187 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1188 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1189 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1190}
1191
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001192void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001193qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001194{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001195 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001196 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1197 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1198 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001199 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001200 uint16_t rid = 0;
1201 struct req_que *req = ha->req_q_map[0];
1202 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001203
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001204/* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001205 icb = (struct init_cb_24xx *)ha->init_cb;
1206 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1207 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001208 icb->request_q_length = cpu_to_le16(req->length);
1209 icb->response_q_length = cpu_to_le16(rsp->length);
1210 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1211 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1212 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1213 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001214
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001215 if (ha->mqenable) {
1216 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1217 icb->rid = __constant_cpu_to_le16(rid);
1218 if (ha->flags.msix_enabled) {
1219 msix = &ha->msix_entries[1];
1220 DEBUG2_17(printk(KERN_INFO
1221 "Reistering vector 0x%x for base que\n", msix->entry));
1222 icb->msix = cpu_to_le16(msix->entry);
1223 }
1224 /* Use alternate PCI bus number */
1225 if (MSB(rid))
1226 icb->firmware_options_2 |=
1227 __constant_cpu_to_le32(BIT_19);
1228 /* Use alternate PCI devfn */
1229 if (LSB(rid))
1230 icb->firmware_options_2 |=
1231 __constant_cpu_to_le32(BIT_18);
1232
Anirban Chakraborty618a7522009-02-08 20:50:11 -08001233 icb->firmware_options_2 &= __constant_cpu_to_le32(~BIT_22);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001234 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001235
1236 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1237 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1238 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1239 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1240 } else {
1241 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1242 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1243 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1244 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1245 }
1246 /* PCI posting */
1247 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001248}
1249
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250/**
1251 * qla2x00_init_rings() - Initializes firmware.
1252 * @ha: HA context
1253 *
1254 * Beginning of request ring has initialization control block already built
1255 * by nvram config routine.
1256 *
1257 * Returns 0 on success.
1258 */
1259static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001260qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261{
1262 int rval;
1263 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001264 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001265 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001266 struct req_que *req;
1267 struct rsp_que *rsp;
1268 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001269 struct mid_init_cb_24xx *mid_init_cb =
1270 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
1272 spin_lock_irqsave(&ha->hardware_lock, flags);
1273
1274 /* Clear outstanding commands array. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001275 for (que = 0; que < ha->max_queues; que++) {
1276 req = ha->req_q_map[que];
1277 if (!req)
1278 continue;
1279 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1280 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001282 req->current_outstanding_cmd = 0;
1283
1284 /* Initialize firmware. */
1285 req->ring_ptr = req->ring;
1286 req->ring_index = 0;
1287 req->cnt = req->length;
1288 }
1289
1290 for (que = 0; que < ha->max_queues; que++) {
1291 rsp = ha->rsp_q_map[que];
1292 if (!rsp)
1293 continue;
1294 rsp->ring_ptr = rsp->ring;
1295 rsp->ring_index = 0;
1296
1297 /* Initialize response queue entries */
1298 qla2x00_init_response_q_entries(rsp);
1299 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300
1301 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001302 list_for_each_entry(vp, &ha->vp_list, list) {
1303 vp->rscn_in_ptr = 0;
1304 vp->rscn_out_ptr = 0;
1305 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001306 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307
1308 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1309
1310 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001311 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001313 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001314
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001315 if (ha->flags.npiv_supported) {
1316 if (ha->operating_mode == LOOP)
1317 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001318 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001319 }
1320
Seokmann Juc48339d2008-01-17 09:02:19 -08001321
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001322 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001323
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001324 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 if (rval) {
1326 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001327 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 } else {
1329 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001330 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 }
1332
1333 return (rval);
1334}
1335
1336/**
1337 * qla2x00_fw_ready() - Waits for firmware ready.
1338 * @ha: HA context
1339 *
1340 * Returns 0 on success.
1341 */
1342static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001343qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344{
1345 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001346 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 uint16_t min_wait; /* Minimum wait time if loop is down */
1348 uint16_t wait_time; /* Wait time if loop is coming ready */
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001349 uint16_t state[3];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001350 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351
1352 rval = QLA_SUCCESS;
1353
1354 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001355 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356
1357 /*
1358 * Firmware should take at most one RATOV to login, plus 5 seconds for
1359 * our own processing.
1360 */
1361 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1362 wait_time = min_wait;
1363 }
1364
1365 /* Min wait time if loop down */
1366 mtime = jiffies + (min_wait * HZ);
1367
1368 /* wait time before firmware ready */
1369 wtime = jiffies + (wait_time * HZ);
1370
1371 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001372 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1374
1375 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001376 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377
1378 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001379 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001381 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001382 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001384 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1385 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001386 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001387 state[2]));
1388 if ((state[2] & FSTATE_LOGGED_IN) &&
1389 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1390 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001391 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001392
1393 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001394 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001395 if (rval != QLA_SUCCESS)
1396 break;
1397
1398 /* Add time taken to initialize. */
1399 cs84xx_time = jiffies - cs84xx_time;
1400 wtime += cs84xx_time;
1401 mtime += cs84xx_time;
1402 DEBUG16(printk("scsi(%ld): Increasing "
1403 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001404 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001405 }
1406 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001408 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001410 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 &ha->login_timeout, &ha->r_a_tov);
1412
1413 rval = QLA_SUCCESS;
1414 break;
1415 }
1416
1417 rval = QLA_FUNCTION_FAILED;
1418
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001419 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001420 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001422 * other than Wait for Login.
1423 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 if (time_after_eq(jiffies, mtime)) {
1425 qla_printk(KERN_INFO, ha,
1426 "Cable is unplugged...\n");
1427
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001428 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 break;
1430 }
1431 }
1432 } else {
1433 /* Mailbox cmd failed. Timeout on min_wait. */
1434 if (time_after_eq(jiffies, mtime))
1435 break;
1436 }
1437
1438 if (time_after_eq(jiffies, wtime))
1439 break;
1440
1441 /* Delay for a while */
1442 msleep(500);
1443
1444 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001445 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 } while (1);
1447
1448 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001449 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
1451 if (rval) {
1452 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001453 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 }
1455
1456 return (rval);
1457}
1458
1459/*
1460* qla2x00_configure_hba
1461* Setup adapter context.
1462*
1463* Input:
1464* ha = adapter state pointer.
1465*
1466* Returns:
1467* 0 = success
1468*
1469* Context:
1470* Kernel context.
1471*/
1472static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001473qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474{
1475 int rval;
1476 uint16_t loop_id;
1477 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001478 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 uint8_t al_pa;
1480 uint8_t area;
1481 uint8_t domain;
1482 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001483 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484
1485 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001486 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001487 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001489 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001490 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1491 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001492 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08001493 } else {
1494 qla_printk(KERN_WARNING, ha,
1495 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001496 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08001497 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 return (rval);
1499 }
1500
1501 if (topo == 4) {
1502 qla_printk(KERN_INFO, ha,
1503 "Cannot get topology - retrying.\n");
1504 return (QLA_FUNCTION_FAILED);
1505 }
1506
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001507 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508
1509 /* initialize */
1510 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1511 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001512 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513
1514 switch (topo) {
1515 case 0:
1516 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001517 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 ha->current_topology = ISP_CFG_NL;
1519 strcpy(connect_type, "(Loop)");
1520 break;
1521
1522 case 1:
1523 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001524 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001525 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 ha->current_topology = ISP_CFG_FL;
1527 strcpy(connect_type, "(FL_Port)");
1528 break;
1529
1530 case 2:
1531 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001532 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 ha->operating_mode = P2P;
1534 ha->current_topology = ISP_CFG_N;
1535 strcpy(connect_type, "(N_Port-to-N_Port)");
1536 break;
1537
1538 case 3:
1539 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001540 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001541 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 ha->operating_mode = P2P;
1543 ha->current_topology = ISP_CFG_F;
1544 strcpy(connect_type, "(F_Port)");
1545 break;
1546
1547 default:
1548 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1549 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001550 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 ha->current_topology = ISP_CFG_NL;
1552 strcpy(connect_type, "(Loop)");
1553 break;
1554 }
1555
1556 /* Save Host port and loop ID. */
1557 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001558 vha->d_id.b.domain = domain;
1559 vha->d_id.b.area = area;
1560 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001562 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 qla_printk(KERN_INFO, ha,
1564 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001565 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
1567 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001568 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001570 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 }
1572
1573 return(rval);
1574}
1575
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001576static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001577qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1578 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001579{
1580 char *st, *en;
1581 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001582 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001583
1584 if (memcmp(model, BINZERO, len) != 0) {
1585 strncpy(ha->model_number, model, len);
1586 st = en = ha->model_number;
1587 en += len - 1;
1588 while (en > st) {
1589 if (*en != 0x20 && *en != 0x00)
1590 break;
1591 *en-- = '\0';
1592 }
1593
1594 index = (ha->pdev->subsystem_device & 0xff);
1595 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1596 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001597 strncpy(ha->model_desc,
1598 qla2x00_model_name[index * 2 + 1],
1599 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001600 } else {
1601 index = (ha->pdev->subsystem_device & 0xff);
1602 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1603 index < QLA_MODEL_NAMES) {
1604 strcpy(ha->model_number,
1605 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001606 strncpy(ha->model_desc,
1607 qla2x00_model_name[index * 2 + 1],
1608 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001609 } else {
1610 strcpy(ha->model_number, def);
1611 }
1612 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001613 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001614 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001615 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001616}
1617
David Miller4e08df32007-04-16 12:37:43 -07001618/* On sparc systems, obtain port and node WWN from firmware
1619 * properties.
1620 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001621static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07001622{
1623#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001624 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07001625 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07001626 struct device_node *dp = pci_device_to_OF_node(pdev);
1627 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07001628 int len;
1629
1630 val = of_get_property(dp, "port-wwn", &len);
1631 if (val && len >= WWN_SIZE)
1632 memcpy(nv->port_name, val, WWN_SIZE);
1633
1634 val = of_get_property(dp, "node-wwn", &len);
1635 if (val && len >= WWN_SIZE)
1636 memcpy(nv->node_name, val, WWN_SIZE);
1637#endif
1638}
1639
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640/*
1641* NVRAM configuration for ISP 2xxx
1642*
1643* Input:
1644* ha = adapter block pointer.
1645*
1646* Output:
1647* initialization control block in response_ring
1648* host adapters parameters in host adapter block
1649*
1650* Returns:
1651* 0 = success.
1652*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001653int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001654qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655{
David Miller4e08df32007-04-16 12:37:43 -07001656 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001657 uint8_t chksum = 0;
1658 uint16_t cnt;
1659 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001660 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001661 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07001662 nvram_t *nv = ha->nvram;
1663 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001664 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665
David Miller4e08df32007-04-16 12:37:43 -07001666 rval = QLA_SUCCESS;
1667
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001669 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 ha->nvram_base = 0;
1671 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1672 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
1673 ha->nvram_base = 0x80;
1674
1675 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001676 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001677 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1678 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001680 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07001681 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682
1683 /* Bad NVRAM data, set defaults parameters. */
1684 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1685 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1686 /* Reset NVRAM data. */
1687 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1688 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1689 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07001690 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1691 "invalid -- WWPN) defaults.\n");
1692
1693 /*
1694 * Set default initialization control block.
1695 */
1696 memset(nv, 0, ha->nvram_size);
1697 nv->parameter_block_version = ICB_VERSION;
1698
1699 if (IS_QLA23XX(ha)) {
1700 nv->firmware_options[0] = BIT_2 | BIT_1;
1701 nv->firmware_options[1] = BIT_7 | BIT_5;
1702 nv->add_firmware_options[0] = BIT_5;
1703 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1704 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1705 nv->special_options[1] = BIT_7;
1706 } else if (IS_QLA2200(ha)) {
1707 nv->firmware_options[0] = BIT_2 | BIT_1;
1708 nv->firmware_options[1] = BIT_7 | BIT_5;
1709 nv->add_firmware_options[0] = BIT_5;
1710 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1711 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1712 } else if (IS_QLA2100(ha)) {
1713 nv->firmware_options[0] = BIT_3 | BIT_1;
1714 nv->firmware_options[1] = BIT_5;
1715 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1716 }
1717
1718 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1719 nv->execution_throttle = __constant_cpu_to_le16(16);
1720 nv->retry_count = 8;
1721 nv->retry_delay = 1;
1722
1723 nv->port_name[0] = 33;
1724 nv->port_name[3] = 224;
1725 nv->port_name[4] = 139;
1726
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001727 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07001728
1729 nv->login_timeout = 4;
1730
1731 /*
1732 * Set default host adapter parameters
1733 */
1734 nv->host_p[1] = BIT_2;
1735 nv->reset_delay = 5;
1736 nv->port_down_retry_count = 8;
1737 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1738 nv->link_down_timeout = 60;
1739
1740 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 }
1742
1743#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1744 /*
1745 * The SN2 does not provide BIOS emulation which means you can't change
1746 * potentially bogus BIOS settings. Force the use of default settings
1747 * for link rate and frame size. Hope that the rest of the settings
1748 * are valid.
1749 */
1750 if (ia64_platform_is("sn2")) {
1751 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1752 if (IS_QLA23XX(ha))
1753 nv->special_options[1] = BIT_7;
1754 }
1755#endif
1756
1757 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001758 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759
1760 /*
1761 * Setup driver NVRAM options.
1762 */
1763 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1764 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1765 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1766 nv->firmware_options[1] &= ~BIT_4;
1767
1768 if (IS_QLA23XX(ha)) {
1769 nv->firmware_options[0] |= BIT_2;
1770 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001771 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772
1773 if (IS_QLA2300(ha)) {
1774 if (ha->fb_rev == FPM_2310) {
1775 strcpy(ha->model_number, "QLA2310");
1776 } else {
1777 strcpy(ha->model_number, "QLA2300");
1778 }
1779 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001780 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001781 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 }
1783 } else if (IS_QLA2200(ha)) {
1784 nv->firmware_options[0] |= BIT_2;
1785 /*
1786 * 'Point-to-point preferred, else loop' is not a safe
1787 * connection mode setting.
1788 */
1789 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1790 (BIT_5 | BIT_4)) {
1791 /* Force 'loop preferred, else point-to-point'. */
1792 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1793 nv->add_firmware_options[0] |= BIT_5;
1794 }
1795 strcpy(ha->model_number, "QLA22xx");
1796 } else /*if (IS_QLA2100(ha))*/ {
1797 strcpy(ha->model_number, "QLA2100");
1798 }
1799
1800 /*
1801 * Copy over NVRAM RISC parameter block to initialization control block.
1802 */
1803 dptr1 = (uint8_t *)icb;
1804 dptr2 = (uint8_t *)&nv->parameter_block_version;
1805 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1806 while (cnt--)
1807 *dptr1++ = *dptr2++;
1808
1809 /* Copy 2nd half. */
1810 dptr1 = (uint8_t *)icb->add_firmware_options;
1811 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1812 while (cnt--)
1813 *dptr1++ = *dptr2++;
1814
Andrew Vasquez5341e862006-05-17 15:09:16 -07001815 /* Use alternate WWN? */
1816 if (nv->host_p[1] & BIT_7) {
1817 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1818 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1819 }
1820
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 /* Prepare nodename */
1822 if ((icb->firmware_options[1] & BIT_6) == 0) {
1823 /*
1824 * Firmware will apply the following mask if the nodename was
1825 * not provided.
1826 */
1827 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1828 icb->node_name[0] &= 0xF0;
1829 }
1830
1831 /*
1832 * Set host adapter parameters.
1833 */
Andrew Vasquez01819442006-06-23 16:11:10 -07001834 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07001835 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1837 /* Always load RISC code on non ISP2[12]00 chips. */
1838 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1839 ha->flags.disable_risc_code_load = 0;
1840 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1841 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1842 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07001843 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001844 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845
1846 ha->operating_mode =
1847 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1848
1849 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1850 sizeof(ha->fw_seriallink_options));
1851
1852 /* save HBA serial number */
1853 ha->serial0 = icb->port_name[5];
1854 ha->serial1 = icb->port_name[6];
1855 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001856 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
1857 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858
1859 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1860
1861 ha->retry_count = nv->retry_count;
1862
1863 /* Set minimum login_timeout to 4 seconds. */
1864 if (nv->login_timeout < ql2xlogintimeout)
1865 nv->login_timeout = ql2xlogintimeout;
1866 if (nv->login_timeout < 4)
1867 nv->login_timeout = 4;
1868 ha->login_timeout = nv->login_timeout;
1869 icb->login_timeout = nv->login_timeout;
1870
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001871 /* Set minimum RATOV to 100 tenths of a second. */
1872 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 ha->loop_reset_delay = nv->reset_delay;
1875
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 /* Link Down Timeout = 0:
1877 *
1878 * When Port Down timer expires we will start returning
1879 * I/O's to OS with "DID_NO_CONNECT".
1880 *
1881 * Link Down Timeout != 0:
1882 *
1883 * The driver waits for the link to come up after link down
1884 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001885 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 if (nv->link_down_timeout == 0) {
1887 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001888 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 } else {
1890 ha->link_down_timeout = nv->link_down_timeout;
1891 ha->loop_down_abort_time =
1892 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001893 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 /*
1896 * Need enough time to try and get the port back.
1897 */
1898 ha->port_down_retry_count = nv->port_down_retry_count;
1899 if (qlport_down_retry)
1900 ha->port_down_retry_count = qlport_down_retry;
1901 /* Set login_retry_count */
1902 ha->login_retry_count = nv->retry_count;
1903 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1904 ha->port_down_retry_count > 3)
1905 ha->login_retry_count = ha->port_down_retry_count;
1906 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1907 ha->login_retry_count = ha->port_down_retry_count;
1908 if (ql2xloginretrycount)
1909 ha->login_retry_count = ql2xloginretrycount;
1910
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 icb->lun_enables = __constant_cpu_to_le16(0);
1912 icb->command_resource_count = 0;
1913 icb->immediate_notify_resource_count = 0;
1914 icb->timeout = __constant_cpu_to_le16(0);
1915
1916 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1917 /* Enable RIO */
1918 icb->firmware_options[0] &= ~BIT_3;
1919 icb->add_firmware_options[0] &=
1920 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1921 icb->add_firmware_options[0] |= BIT_2;
1922 icb->response_accumulation_timer = 3;
1923 icb->interrupt_delay_timer = 5;
1924
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001925 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001927 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001928 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001929 ha->zio_mode = icb->add_firmware_options[0] &
1930 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1931 ha->zio_timer = icb->interrupt_delay_timer ?
1932 icb->interrupt_delay_timer: 2;
1933 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 icb->add_firmware_options[0] &=
1935 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001936 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001937 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001938 ha->zio_mode = QLA_ZIO_MODE_6;
1939
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001940 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001941 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001942 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001944 "ZIO mode %d enabled; timer delay (%d us).\n",
1945 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001947 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1948 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001949 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 }
1951 }
1952
David Miller4e08df32007-04-16 12:37:43 -07001953 if (rval) {
1954 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001955 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07001956 }
1957 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958}
1959
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001960static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001961qla2x00_rport_del(void *data)
1962{
1963 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001964 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001965
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001966 spin_lock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001967 rport = fcport->drport;
1968 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001969 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001970 if (rport)
1971 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001972}
1973
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974/**
1975 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1976 * @ha: HA context
1977 * @flags: allocation flags
1978 *
1979 * Returns a pointer to the allocated fcport, or NULL, if none available.
1980 */
Adrian Bunk413975a2006-06-30 02:33:06 -07001981static fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001982qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983{
1984 fc_port_t *fcport;
1985
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001986 fcport = kzalloc(sizeof(fc_port_t), flags);
1987 if (!fcport)
1988 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989
1990 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001991 fcport->vha = vha;
1992 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 fcport->port_type = FCT_UNKNOWN;
1994 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1996 fcport->flags = FCF_RLC_SUPPORT;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001997 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001999 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000}
2001
2002/*
2003 * qla2x00_configure_loop
2004 * Updates Fibre Channel Device Database with what is actually on loop.
2005 *
2006 * Input:
2007 * ha = adapter block pointer.
2008 *
2009 * Returns:
2010 * 0 = success.
2011 * 1 = error.
2012 * 2 = database was full and device was not configured.
2013 */
2014static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002015qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016{
2017 int rval;
2018 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002019 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 rval = QLA_SUCCESS;
2021
2022 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002023 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2024 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 if (rval != QLA_SUCCESS) {
2026 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002027 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 return (rval);
2029 }
2030 }
2031
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002032 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002034 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035
2036 /*
2037 * If we have both an RSCN and PORT UPDATE pending then handle them
2038 * both at the same time.
2039 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002040 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2041 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042
2043 /* Determine what we need to do */
2044 if (ha->current_topology == ISP_CFG_FL &&
2045 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2046
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002047 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 set_bit(RSCN_UPDATE, &flags);
2049
2050 } else if (ha->current_topology == ISP_CFG_F &&
2051 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2052
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002053 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 set_bit(RSCN_UPDATE, &flags);
2055 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2056
Andrew Vasquez21333b42006-05-17 15:09:56 -07002057 } else if (ha->current_topology == ISP_CFG_N) {
2058 clear_bit(RSCN_UPDATE, &flags);
2059
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002060 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2062
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002063 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 set_bit(RSCN_UPDATE, &flags);
2065 set_bit(LOCAL_LOOP_UPDATE, &flags);
2066 }
2067
2068 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002069 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002071 else
2072 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 }
2074
2075 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002076 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002078 else
2079 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 }
2081
2082 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002083 if (atomic_read(&vha->loop_down_timer) ||
2084 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 rval = QLA_FUNCTION_FAILED;
2086 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002087 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002089 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 }
2091 }
2092
2093 if (rval) {
2094 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002095 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 } else {
2097 DEBUG3(printk("%s: exiting normally\n", __func__));
2098 }
2099
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002100 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002101 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002103 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002104 if (test_bit(RSCN_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002105 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 }
2107
2108 return (rval);
2109}
2110
2111
2112
2113/*
2114 * qla2x00_configure_local_loop
2115 * Updates Fibre Channel Device Database with local loop devices.
2116 *
2117 * Input:
2118 * ha = adapter block pointer.
2119 *
2120 * Returns:
2121 * 0 = success.
2122 */
2123static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002124qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125{
2126 int rval, rval2;
2127 int found_devs;
2128 int found;
2129 fc_port_t *fcport, *new_fcport;
2130
2131 uint16_t index;
2132 uint16_t entries;
2133 char *id_iter;
2134 uint16_t loop_id;
2135 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002136 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137
2138 found_devs = 0;
2139 new_fcport = NULL;
2140 entries = MAX_FIBRE_DEVICES;
2141
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002142 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2143 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144
2145 /* Get list of logged in devices. */
2146 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002147 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 &entries);
2149 if (rval != QLA_SUCCESS)
2150 goto cleanup_allocation;
2151
2152 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2153 ha->host_no, entries));
2154 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2155 entries * sizeof(struct gid_list_info)));
2156
2157 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002158 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 if (new_fcport == NULL) {
2160 rval = QLA_MEMORY_ALLOC_FAILED;
2161 goto cleanup_allocation;
2162 }
2163 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2164
2165 /*
2166 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2167 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002168 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2170 fcport->port_type != FCT_BROADCAST &&
2171 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2172
2173 DEBUG(printk("scsi(%ld): Marking port lost, "
2174 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002175 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176
2177 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2178 fcport->flags &= ~FCF_FARP_DONE;
2179 }
2180 }
2181
2182 /* Add devices to port list. */
2183 id_iter = (char *)ha->gid_list;
2184 for (index = 0; index < entries; index++) {
2185 domain = ((struct gid_list_info *)id_iter)->domain;
2186 area = ((struct gid_list_info *)id_iter)->area;
2187 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002188 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 loop_id = (uint16_t)
2190 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002191 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 loop_id = le16_to_cpu(
2193 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002194 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195
2196 /* Bypass reserved domain fields. */
2197 if ((domain & 0xf0) == 0xf0)
2198 continue;
2199
2200 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002201 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002202 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 continue;
2204
2205 /* Bypass invalid local loop ID. */
2206 if (loop_id > LAST_LOCAL_LOOP_ID)
2207 continue;
2208
2209 /* Fill in member data. */
2210 new_fcport->d_id.b.domain = domain;
2211 new_fcport->d_id.b.area = area;
2212 new_fcport->d_id.b.al_pa = al_pa;
2213 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002214 new_fcport->vp_idx = vha->vp_idx;
2215 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 if (rval2 != QLA_SUCCESS) {
2217 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2218 "information -- get_port_database=%x, "
2219 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002220 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002221 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002222 vha->host_no));
2223 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 continue;
2225 }
2226
2227 /* Check for matching device in port list. */
2228 found = 0;
2229 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002230 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 if (memcmp(new_fcport->port_name, fcport->port_name,
2232 WWN_SIZE))
2233 continue;
2234
2235 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2236 FCF_PERSISTENT_BOUND);
2237 fcport->loop_id = new_fcport->loop_id;
2238 fcport->port_type = new_fcport->port_type;
2239 fcport->d_id.b24 = new_fcport->d_id.b24;
2240 memcpy(fcport->node_name, new_fcport->node_name,
2241 WWN_SIZE);
2242
2243 found++;
2244 break;
2245 }
2246
2247 if (!found) {
2248 /* New device, add to fcports list. */
2249 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002250 if (vha->vp_idx) {
2251 new_fcport->vha = vha;
2252 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002253 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002254 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255
2256 /* Allocate a new replacement fcport. */
2257 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002258 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 if (new_fcport == NULL) {
2260 rval = QLA_MEMORY_ALLOC_FAILED;
2261 goto cleanup_allocation;
2262 }
2263 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2264 }
2265
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002266 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002267 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002268
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002269 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270
2271 found_devs++;
2272 }
2273
2274cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002275 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276
2277 if (rval != QLA_SUCCESS) {
2278 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002279 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 }
2281
2282 if (found_devs) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002283 vha->device_flags |= DFLG_LOCAL_DEVICES;
2284 vha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 }
2286
2287 return (rval);
2288}
2289
2290static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002291qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002292{
2293#define LS_UNKNOWN 2
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002294 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002295 int rval;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002296 uint16_t mb[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002297 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002298
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002299 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002300 return;
2301
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002302 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2303 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002304 return;
2305
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002306 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002307 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002308 if (rval != QLA_SUCCESS) {
2309 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2310 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002311 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002312 fcport->port_name[2], fcport->port_name[3],
2313 fcport->port_name[4], fcport->port_name[5],
2314 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002315 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002316 } else {
2317 DEBUG2(qla_printk(KERN_INFO, ha,
2318 "iIDMA adjusted to %s GB/s on "
2319 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002320 link_speeds[fcport->fp_speed], fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002321 fcport->port_name[1], fcport->port_name[2],
2322 fcport->port_name[3], fcport->port_name[4],
2323 fcport->port_name[5], fcport->port_name[6],
2324 fcport->port_name[7]));
2325 }
2326}
2327
Adrian Bunk23be3312006-11-24 02:46:01 +01002328static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002329qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002330{
2331 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002332 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002333 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05002334
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002335 if (fcport->drport)
2336 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002337
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002338 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2339 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002340 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2341 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2342 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002343 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002344 if (!rport) {
2345 qla_printk(KERN_WARNING, ha,
2346 "Unable to allocate fc remote port!\n");
2347 return;
2348 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002349 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002350 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002351 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002352
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002353 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002354
2355 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002356 if (fcport->port_type == FCT_INITIATOR)
2357 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2358 if (fcport->port_type == FCT_TARGET)
2359 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002360 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002361}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362
2363/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002364 * qla2x00_update_fcport
2365 * Updates device on list.
2366 *
2367 * Input:
2368 * ha = adapter block pointer.
2369 * fcport = port structure pointer.
2370 *
2371 * Return:
2372 * 0 - Success
2373 * BIT_0 - error
2374 *
2375 * Context:
2376 * Kernel context.
2377 */
2378void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002379qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002380{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002381 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002382
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002383 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002384 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002385 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002386 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002387 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002388 PORT_RETRY_TIME);
2389 fcport->flags &= ~FCF_LOGIN_NEEDED;
2390
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002391 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002392
2393 atomic_set(&fcport->state, FCS_ONLINE);
2394
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002395 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002396}
2397
2398/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 * qla2x00_configure_fabric
2400 * Setup SNS devices with loop ID's.
2401 *
2402 * Input:
2403 * ha = adapter block pointer.
2404 *
2405 * Returns:
2406 * 0 = success.
2407 * BIT_0 = error
2408 */
2409static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002410qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411{
2412 int rval, rval2;
2413 fc_port_t *fcport, *fcptemp;
2414 uint16_t next_loopid;
2415 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002416 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002418 struct qla_hw_data *ha = vha->hw;
2419 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420
2421 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002422 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002423 loop_id = NPH_F_PORT;
2424 else
2425 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002426 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 if (rval != QLA_SUCCESS) {
2428 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002429 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002431 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 return (QLA_SUCCESS);
2433 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002434 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435
2436 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002437 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 if (rval2 == QLA_RSCNS_HANDLED) {
2439 /* No point doing the scan, just continue. */
2440 return (QLA_SUCCESS);
2441 }
2442 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002443 /* FDMI support. */
2444 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002445 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2446 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002447
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002449 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002450 loop_id = NPH_SNS;
2451 else
2452 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002453 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002454 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 if (mb[0] != MBS_COMMAND_COMPLETE) {
2456 DEBUG2(qla_printk(KERN_INFO, ha,
2457 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002458 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 mb[0], mb[1], mb[2], mb[6], mb[7]));
2460 return (QLA_SUCCESS);
2461 }
2462
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002463 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2464 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 /* EMPTY */
2466 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002467 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002469 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 /* EMPTY */
2471 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002472 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002474 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 /* EMPTY */
2476 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002477 "failed.\n", vha->host_no));
2478 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 /* EMPTY */
2480 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002481 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 }
2483 }
2484
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002485 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 if (rval != QLA_SUCCESS)
2487 break;
2488
2489 /*
2490 * Logout all previous fabric devices marked lost, except
2491 * tape devices.
2492 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002493 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2494 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 break;
2496
2497 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2498 continue;
2499
2500 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002501 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002502 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 if (fcport->loop_id != FC_NO_LOOP_ID &&
2504 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2505 fcport->port_type != FCT_INITIATOR &&
2506 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002507 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002508 fcport->loop_id,
2509 fcport->d_id.b.domain,
2510 fcport->d_id.b.area,
2511 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 fcport->loop_id = FC_NO_LOOP_ID;
2513 }
2514 }
2515 }
2516
2517 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002518 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519
2520 /*
2521 * Scan through our port list and login entries that need to be
2522 * logged in.
2523 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002524 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2525 if (atomic_read(&vha->loop_down_timer) ||
2526 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 break;
2528
2529 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2530 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2531 continue;
2532
2533 if (fcport->loop_id == FC_NO_LOOP_ID) {
2534 fcport->loop_id = next_loopid;
Seokmann Jud4486fd2008-04-03 13:13:28 -07002535 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002536 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 if (rval != QLA_SUCCESS) {
2538 /* Ran out of IDs to use */
2539 break;
2540 }
2541 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002543 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 }
2545
2546 /* Exit if out of loop IDs. */
2547 if (rval != QLA_SUCCESS) {
2548 break;
2549 }
2550
2551 /*
2552 * Login and add the new devices to our port list.
2553 */
2554 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002555 if (atomic_read(&vha->loop_down_timer) ||
2556 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 break;
2558
2559 /* Find a new loop ID to use. */
2560 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002561 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 if (rval != QLA_SUCCESS) {
2563 /* Ran out of IDs to use */
2564 break;
2565 }
2566
bdf79622005-04-17 15:06:53 -05002567 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002568 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002569
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002570 if (vha->vp_idx) {
2571 fcport->vha = vha;
2572 fcport->vp_idx = vha->vp_idx;
2573 }
2574 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 }
2576 } while (0);
2577
2578 /* Free all new device structures not processed. */
2579 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2580 list_del(&fcport->list);
2581 kfree(fcport);
2582 }
2583
2584 if (rval) {
2585 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002586 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 }
2588
2589 return (rval);
2590}
2591
2592
2593/*
2594 * qla2x00_find_all_fabric_devs
2595 *
2596 * Input:
2597 * ha = adapter block pointer.
2598 * dev = database device entry pointer.
2599 *
2600 * Returns:
2601 * 0 = success.
2602 *
2603 * Context:
2604 * Kernel context.
2605 */
2606static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002607qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2608 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609{
2610 int rval;
2611 uint16_t loop_id;
2612 fc_port_t *fcport, *new_fcport, *fcptemp;
2613 int found;
2614
2615 sw_info_t *swl;
2616 int swl_idx;
2617 int first_dev, last_dev;
2618 port_id_t wrap, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002619 struct qla_hw_data *ha = vha->hw;
2620 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002621 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622
2623 rval = QLA_SUCCESS;
2624
2625 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07002626 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002627 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 /*EMPTY*/
2629 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002630 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002632 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 kfree(swl);
2634 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002635 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 kfree(swl);
2637 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002638 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 kfree(swl);
2640 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07002641 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002642 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2643 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 }
2645 }
2646 swl_idx = 0;
2647
2648 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002649 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002651 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 return (QLA_MEMORY_ALLOC_FAILED);
2653 }
2654 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 /* Set start port ID scan at adapter ID. */
2656 first_dev = 1;
2657 last_dev = 0;
2658
2659 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002660 loop_id = ha->min_external_loopid;
2661 for (; loop_id <= ha->max_loop_id; loop_id++) {
2662 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 continue;
2664
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002665 if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 break;
2667
2668 if (swl != NULL) {
2669 if (last_dev) {
2670 wrap.b24 = new_fcport->d_id.b24;
2671 } else {
2672 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2673 memcpy(new_fcport->node_name,
2674 swl[swl_idx].node_name, WWN_SIZE);
2675 memcpy(new_fcport->port_name,
2676 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002677 memcpy(new_fcport->fabric_port_name,
2678 swl[swl_idx].fabric_port_name, WWN_SIZE);
2679 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680
2681 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2682 last_dev = 1;
2683 }
2684 swl_idx++;
2685 }
2686 } else {
2687 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002688 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 if (rval != QLA_SUCCESS) {
2690 qla_printk(KERN_WARNING, ha,
2691 "SNS scan failed -- assuming zero-entry "
2692 "result...\n");
2693 list_for_each_entry_safe(fcport, fcptemp,
2694 new_fcports, list) {
2695 list_del(&fcport->list);
2696 kfree(fcport);
2697 }
2698 rval = QLA_SUCCESS;
2699 break;
2700 }
2701 }
2702
2703 /* If wrap on switch device list, exit. */
2704 if (first_dev) {
2705 wrap.b24 = new_fcport->d_id.b24;
2706 first_dev = 0;
2707 } else if (new_fcport->d_id.b24 == wrap.b24) {
2708 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002709 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2711 break;
2712 }
2713
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002714 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002715 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 continue;
2717
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002718 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002719 found = 0;
2720 if (ha->num_vhosts) {
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002721 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002722 if (new_fcport->d_id.b24 == vp->d_id.b24) {
2723 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002724 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002725 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002726 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002727 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002728 continue;
2729 }
2730
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002731 /* Bypass if same domain and area of adapter. */
2732 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002733 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002734 ISP_CFG_FL)
2735 continue;
2736
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 /* Bypass reserved domain fields. */
2738 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2739 continue;
2740
2741 /* Locate matching device in database. */
2742 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002743 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 if (memcmp(new_fcport->port_name, fcport->port_name,
2745 WWN_SIZE))
2746 continue;
2747
2748 found++;
2749
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002750 /* Update port state. */
2751 memcpy(fcport->fabric_port_name,
2752 new_fcport->fabric_port_name, WWN_SIZE);
2753 fcport->fp_speed = new_fcport->fp_speed;
2754
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 /*
2756 * If address the same and state FCS_ONLINE, nothing
2757 * changed.
2758 */
2759 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2760 atomic_read(&fcport->state) == FCS_ONLINE) {
2761 break;
2762 }
2763
2764 /*
2765 * If device was not a fabric device before.
2766 */
2767 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2768 fcport->d_id.b24 = new_fcport->d_id.b24;
2769 fcport->loop_id = FC_NO_LOOP_ID;
2770 fcport->flags |= (FCF_FABRIC_DEVICE |
2771 FCF_LOGIN_NEEDED);
2772 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2773 break;
2774 }
2775
2776 /*
2777 * Port ID changed or device was marked to be updated;
2778 * Log it out if still logged in and mark it for
2779 * relogin later.
2780 */
2781 fcport->d_id.b24 = new_fcport->d_id.b24;
2782 fcport->flags |= FCF_LOGIN_NEEDED;
2783 if (fcport->loop_id != FC_NO_LOOP_ID &&
2784 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2785 fcport->port_type != FCT_INITIATOR &&
2786 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002787 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002788 fcport->d_id.b.domain, fcport->d_id.b.area,
2789 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 fcport->loop_id = FC_NO_LOOP_ID;
2791 }
2792
2793 break;
2794 }
2795
2796 if (found)
2797 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 /* If device was not in our fcports list, then add it. */
2799 list_add_tail(&new_fcport->list, new_fcports);
2800
2801 /* Allocate a new replacement fcport. */
2802 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002803 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002805 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 return (QLA_MEMORY_ALLOC_FAILED);
2807 }
2808 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2809 new_fcport->d_id.b24 = nxt_d_id.b24;
2810 }
2811
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002812 kfree(swl);
2813 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814
2815 if (!list_empty(new_fcports))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002816 vha->device_flags |= DFLG_FABRIC_DEVICES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817
2818 return (rval);
2819}
2820
2821/*
2822 * qla2x00_find_new_loop_id
2823 * Scan through our port list and find a new usable loop ID.
2824 *
2825 * Input:
2826 * ha: adapter state pointer.
2827 * dev: port structure pointer.
2828 *
2829 * Returns:
2830 * qla2x00 local function return status code.
2831 *
2832 * Context:
2833 * Kernel context.
2834 */
Adrian Bunk413975a2006-06-30 02:33:06 -07002835static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002836qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837{
2838 int rval;
2839 int found;
2840 fc_port_t *fcport;
2841 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002842 struct qla_hw_data *ha = vha->hw;
2843 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002844 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845
2846 rval = QLA_SUCCESS;
2847
2848 /* Save starting loop ID. */
2849 first_loop_id = dev->loop_id;
2850
2851 for (;;) {
2852 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002853 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855
2856 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002857 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859
2860 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002861 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862 /* first loop ID. */
2863 dev->loop_id = ha->min_external_loopid;
2864 }
2865
2866 /* Check for loop ID being already in use. */
2867 found = 0;
2868 fcport = NULL;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002869 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002870 list_for_each_entry(fcport, &vp->vp_fcports, list) {
2871 if (fcport->loop_id == dev->loop_id &&
2872 fcport != dev) {
2873 /* ID possibly in use */
2874 found++;
2875 break;
2876 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002878 if (found)
2879 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 }
2881
2882 /* If not in use then it is free to use. */
2883 if (!found) {
2884 break;
2885 }
2886
2887 /* ID in use. Try next value. */
2888 dev->loop_id++;
2889
2890 /* If wrap around. No free ID to use. */
2891 if (dev->loop_id == first_loop_id) {
2892 dev->loop_id = FC_NO_LOOP_ID;
2893 rval = QLA_FUNCTION_FAILED;
2894 break;
2895 }
2896 }
2897
2898 return (rval);
2899}
2900
2901/*
2902 * qla2x00_device_resync
2903 * Marks devices in the database that needs resynchronization.
2904 *
2905 * Input:
2906 * ha = adapter block pointer.
2907 *
2908 * Context:
2909 * Kernel context.
2910 */
2911static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002912qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913{
2914 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 uint32_t mask;
2916 fc_port_t *fcport;
2917 uint32_t rscn_entry;
2918 uint8_t rscn_out_iter;
2919 uint8_t format;
2920 port_id_t d_id;
2921
2922 rval = QLA_RSCNS_HANDLED;
2923
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002924 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
2925 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002927 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 format = MSB(MSW(rscn_entry));
2929 d_id.b.domain = LSB(MSW(rscn_entry));
2930 d_id.b.area = MSB(LSW(rscn_entry));
2931 d_id.b.al_pa = LSB(LSW(rscn_entry));
2932
2933 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2934 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002935 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 d_id.b.area, d_id.b.al_pa));
2937
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002938 vha->rscn_out_ptr++;
2939 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
2940 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941
2942 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002943 for (rscn_out_iter = vha->rscn_out_ptr;
2944 !vha->flags.rscn_queue_overflow &&
2945 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 rscn_out_iter = (rscn_out_iter ==
2947 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2948
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002949 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 break;
2951
2952 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002953 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 rscn_out_iter));
2955
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002956 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 }
2958
2959 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002960 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002962 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963
2964 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002965 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 }
2967
2968 switch (format) {
2969 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 mask = 0xffffff;
2971 break;
2972 case 1:
2973 mask = 0xffff00;
2974 break;
2975 case 2:
2976 mask = 0xff0000;
2977 break;
2978 default:
2979 mask = 0x0;
2980 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002981 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 break;
2983 }
2984
2985 rval = QLA_SUCCESS;
2986
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002987 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2989 (fcport->d_id.b24 & mask) != d_id.b24 ||
2990 fcport->port_type == FCT_BROADCAST)
2991 continue;
2992
2993 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2994 if (format != 3 ||
2995 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002996 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002997 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 }
2999 }
3000 fcport->flags &= ~FCF_FARP_DONE;
3001 }
3002 }
3003 return (rval);
3004}
3005
3006/*
3007 * qla2x00_fabric_dev_login
3008 * Login fabric target device and update FC port database.
3009 *
3010 * Input:
3011 * ha: adapter state pointer.
3012 * fcport: port structure list pointer.
3013 * next_loopid: contains value of a new loop ID that can be used
3014 * by the next login attempt.
3015 *
3016 * Returns:
3017 * qla2x00 local function return status code.
3018 *
3019 * Context:
3020 * Kernel context.
3021 */
3022static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003023qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 uint16_t *next_loopid)
3025{
3026 int rval;
3027 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003028 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003029 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030
3031 rval = QLA_SUCCESS;
3032 retry = 0;
3033
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003034 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 if (rval == QLA_SUCCESS) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003036 /* Send an ADISC to tape devices.*/
3037 opts = 0;
3038 if (fcport->flags & FCF_TAPE_PRESENT)
3039 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003040 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003042 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003043 fcport->d_id.b.domain, fcport->d_id.b.area,
3044 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003045 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003047 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048 }
3049 }
3050
3051 return (rval);
3052}
3053
3054/*
3055 * qla2x00_fabric_login
3056 * Issue fabric login command.
3057 *
3058 * Input:
3059 * ha = adapter block pointer.
3060 * device = pointer to FC device type structure.
3061 *
3062 * Returns:
3063 * 0 - Login successfully
3064 * 1 - Login failed
3065 * 2 - Initiator device
3066 * 3 - Fatal error
3067 */
3068int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003069qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 uint16_t *next_loopid)
3071{
3072 int rval;
3073 int retry;
3074 uint16_t tmp_loopid;
3075 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003076 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077
3078 retry = 0;
3079 tmp_loopid = 0;
3080
3081 for (;;) {
3082 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3083 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003084 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3086
3087 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003088 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 fcport->d_id.b.domain, fcport->d_id.b.area,
3090 fcport->d_id.b.al_pa, mb, BIT_0);
3091 if (mb[0] == MBS_PORT_ID_USED) {
3092 /*
3093 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003094 * recommends the driver perform an implicit login with
3095 * the specified ID again. The ID we just used is save
3096 * here so we return with an ID that can be tried by
3097 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098 */
3099 retry++;
3100 tmp_loopid = fcport->loop_id;
3101 fcport->loop_id = mb[1];
3102
3103 DEBUG(printk("Fabric Login: port in use - next "
3104 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3105 fcport->loop_id, fcport->d_id.b.domain,
3106 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3107
3108 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3109 /*
3110 * Login succeeded.
3111 */
3112 if (retry) {
3113 /* A retry occurred before. */
3114 *next_loopid = tmp_loopid;
3115 } else {
3116 /*
3117 * No retry occurred before. Just increment the
3118 * ID value for next login.
3119 */
3120 *next_loopid = (fcport->loop_id + 1);
3121 }
3122
3123 if (mb[1] & BIT_0) {
3124 fcport->port_type = FCT_INITIATOR;
3125 } else {
3126 fcport->port_type = FCT_TARGET;
3127 if (mb[1] & BIT_1) {
3128 fcport->flags |= FCF_TAPE_PRESENT;
3129 }
3130 }
3131
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003132 if (mb[10] & BIT_0)
3133 fcport->supported_classes |= FC_COS_CLASS2;
3134 if (mb[10] & BIT_1)
3135 fcport->supported_classes |= FC_COS_CLASS3;
3136
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137 rval = QLA_SUCCESS;
3138 break;
3139 } else if (mb[0] == MBS_LOOP_ID_USED) {
3140 /*
3141 * Loop ID already used, try next loop ID.
3142 */
3143 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003144 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145 if (rval != QLA_SUCCESS) {
3146 /* Ran out of loop IDs to use */
3147 break;
3148 }
3149 } else if (mb[0] == MBS_COMMAND_ERROR) {
3150 /*
3151 * Firmware possibly timed out during login. If NO
3152 * retries are left to do then the device is declared
3153 * dead.
3154 */
3155 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003156 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003157 fcport->d_id.b.domain, fcport->d_id.b.area,
3158 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003159 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160
3161 rval = 1;
3162 break;
3163 } else {
3164 /*
3165 * unrecoverable / not handled error
3166 */
3167 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003168 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003169 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170 fcport->d_id.b.domain, fcport->d_id.b.area,
3171 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3172
3173 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003174 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003175 fcport->d_id.b.domain, fcport->d_id.b.area,
3176 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003178 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179
3180 rval = 3;
3181 break;
3182 }
3183 }
3184
3185 return (rval);
3186}
3187
3188/*
3189 * qla2x00_local_device_login
3190 * Issue local device login command.
3191 *
3192 * Input:
3193 * ha = adapter block pointer.
3194 * loop_id = loop id of device to login to.
3195 *
3196 * Returns (Where's the #define!!!!):
3197 * 0 - Login successfully
3198 * 1 - Login failed
3199 * 3 - Fatal error
3200 */
3201int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003202qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203{
3204 int rval;
3205 uint16_t mb[MAILBOX_REGISTER_COUNT];
3206
3207 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003208 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209 if (rval == QLA_SUCCESS) {
3210 /* Interrogate mailbox registers for any errors */
3211 if (mb[0] == MBS_COMMAND_ERROR)
3212 rval = 1;
3213 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3214 /* device not in PCB table */
3215 rval = 3;
3216 }
3217
3218 return (rval);
3219}
3220
3221/*
3222 * qla2x00_loop_resync
3223 * Resync with fibre channel devices.
3224 *
3225 * Input:
3226 * ha = adapter block pointer.
3227 *
3228 * Returns:
3229 * 0 = success
3230 */
3231int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003232qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003234 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235 uint32_t wait_time;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003236 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003237 struct req_que *req = ha->req_q_map[vha->req_ques[0]];
3238 struct rsp_que *rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003240 atomic_set(&vha->loop_state, LOOP_UPDATE);
3241 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3242 if (vha->flags.online) {
3243 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3245 wait_time = 256;
3246 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003247 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003249 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003250 qla2x00_marker(vha, req, rsp, 0, 0,
3251 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003252 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253
3254 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003255 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003257 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003259 } while (!atomic_read(&vha->loop_down_timer) &&
3260 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3261 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3262 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 }
3265
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003266 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003269 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271
3272 return (rval);
3273}
3274
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003276qla2x00_update_fcports(scsi_qla_host_t *vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003277{
3278 fc_port_t *fcport;
3279
3280 /* Go with deferred removal of rport references. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003281 list_for_each_entry(fcport, &vha->vp_fcports, list)
3282 if (fcport && fcport->drport &&
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07003283 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003284 qla2x00_rport_del(fcport);
3285}
3286
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287/*
3288* qla2x00_abort_isp
3289* Resets ISP and aborts all outstanding commands.
3290*
3291* Input:
3292* ha = adapter block pointer.
3293*
3294* Returns:
3295* 0 = success
3296*/
3297int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003298qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003300 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003302 struct qla_hw_data *ha = vha->hw;
3303 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003304 struct scsi_qla_host *tvp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003305 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003307 if (vha->flags.online) {
3308 vha->flags.online = 0;
3309 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07003310 ha->qla_stats.total_isp_aborts++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311
3312 qla_printk(KERN_INFO, ha,
3313 "Performing ISP error recovery - ha= %p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003314 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003316 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3317 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3318 atomic_set(&vha->loop_state, LOOP_DOWN);
3319 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003320 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003321 qla2x00_mark_all_devices_lost(vp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003323 if (!atomic_read(&vha->loop_down_timer))
3324 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325 LOOP_DOWN_TIME);
3326 }
3327
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328 /* Requeue all commands in outstanding command list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003329 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003331 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003332
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003333 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003335 if (!qla2x00_restart_isp(vha)) {
3336 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003338 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339 /*
3340 * Issue marker command only when we are going
3341 * to start the I/O .
3342 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003343 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344 }
3345
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003346 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003347
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003348 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003350 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003351 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003352
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003353 if (ha->fce) {
3354 ha->flags.fce_enabled = 1;
3355 memset(ha->fce, 0,
3356 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003357 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003358 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3359 &ha->fce_bufs);
3360 if (rval) {
3361 qla_printk(KERN_WARNING, ha,
3362 "Unable to reinitialize FCE "
3363 "(%d).\n", rval);
3364 ha->flags.fce_enabled = 0;
3365 }
3366 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003367
3368 if (ha->eft) {
3369 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003370 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003371 ha->eft_dma, EFT_NUM_BUFFERS);
3372 if (rval) {
3373 qla_printk(KERN_WARNING, ha,
3374 "Unable to reinitialize EFT "
3375 "(%d).\n", rval);
3376 }
3377 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003379 vha->flags.online = 1;
3380 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381 if (ha->isp_abort_cnt == 0) {
3382 qla_printk(KERN_WARNING, ha,
3383 "ISP error recovery failed - "
3384 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003385 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386 * The next call disables the board
3387 * completely.
3388 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003389 ha->isp_ops->reset_adapter(vha);
3390 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003392 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393 status = 0;
3394 } else { /* schedule another ISP abort */
3395 ha->isp_abort_cnt--;
3396 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003397 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003398 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399 status = 1;
3400 }
3401 } else {
3402 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3403 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3404 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003405 vha->host_no, ha->isp_abort_cnt));
3406 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407 status = 1;
3408 }
3409 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003410
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411 }
3412
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003413 if (!status) {
3414 DEBUG(printk(KERN_INFO
3415 "qla2x00_abort_isp(%ld): succeeded.\n",
3416 vha->host_no));
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003417 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003418 if (vp->vp_idx)
3419 qla2x00_vp_abort_isp(vp);
3420 }
3421 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422 qla_printk(KERN_INFO, ha,
3423 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424 }
3425
3426 return(status);
3427}
3428
3429/*
3430* qla2x00_restart_isp
3431* restarts the ISP after a reset
3432*
3433* Input:
3434* ha = adapter block pointer.
3435*
3436* Returns:
3437* 0 = success
3438*/
3439static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003440qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003442 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003444 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003445 struct req_que *req = ha->req_q_map[0];
3446 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447
3448 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003449 if (qla2x00_isp_firmware(vha)) {
3450 vha->flags.online = 0;
3451 status = ha->isp_ops->chip_diag(vha);
3452 if (!status)
3453 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454 }
3455
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003456 if (!status && !(status = qla2x00_init_rings(vha))) {
3457 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003458 /* Initialize the queues in use */
3459 qla25xx_init_queues(ha);
3460
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003461 status = qla2x00_fw_ready(vha);
3462 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003464 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003465
3466 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003467 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003468
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003469 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3471 wait_time = 256;
3472 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003473 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3474 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003476 } while (!atomic_read(&vha->loop_down_timer) &&
3477 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3478 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3479 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480 }
3481
3482 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003483 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484 status = 0;
3485
3486 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3487 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003488 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489 }
3490 return (status);
3491}
3492
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003493static int
3494qla25xx_init_queues(struct qla_hw_data *ha)
3495{
3496 struct rsp_que *rsp = NULL;
3497 struct req_que *req = NULL;
3498 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3499 int ret = -1;
3500 int i;
3501
3502 for (i = 1; i < ha->max_queues; i++) {
3503 rsp = ha->rsp_q_map[i];
3504 if (rsp) {
3505 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003506 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003507 if (ret != QLA_SUCCESS)
3508 DEBUG2_17(printk(KERN_WARNING
3509 "%s Rsp que:%d init failed\n", __func__,
3510 rsp->id));
3511 else
3512 DEBUG2_17(printk(KERN_INFO
3513 "%s Rsp que:%d inited\n", __func__,
3514 rsp->id));
3515 }
3516 req = ha->req_q_map[i];
3517 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003518 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003519 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003520 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003521 if (ret != QLA_SUCCESS)
3522 DEBUG2_17(printk(KERN_WARNING
3523 "%s Req que:%d init failed\n", __func__,
3524 req->id));
3525 else
3526 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003527 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003528 req->id));
3529 }
3530 }
3531 return ret;
3532}
3533
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534/*
3535* qla2x00_reset_adapter
3536* Reset adapter.
3537*
3538* Input:
3539* ha = adapter block pointer.
3540*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003541void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003542qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003543{
3544 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003545 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003546 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003548 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003549 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551 spin_lock_irqsave(&ha->hardware_lock, flags);
3552 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3553 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3554 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3555 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3556 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3557}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003558
3559void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003560qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003561{
3562 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003563 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003564 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3565
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003566 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003567 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003568
3569 spin_lock_irqsave(&ha->hardware_lock, flags);
3570 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3571 RD_REG_DWORD(&reg->hccr);
3572 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3573 RD_REG_DWORD(&reg->hccr);
3574 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08003575
3576 if (IS_NOPOLLING_TYPE(ha))
3577 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003578}
3579
David Miller4e08df32007-04-16 12:37:43 -07003580/* On sparc systems, obtain port and node WWN from firmware
3581 * properties.
3582 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003583static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3584 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07003585{
3586#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003587 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003588 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003589 struct device_node *dp = pci_device_to_OF_node(pdev);
3590 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003591 int len;
3592
3593 val = of_get_property(dp, "port-wwn", &len);
3594 if (val && len >= WWN_SIZE)
3595 memcpy(nv->port_name, val, WWN_SIZE);
3596
3597 val = of_get_property(dp, "node-wwn", &len);
3598 if (val && len >= WWN_SIZE)
3599 memcpy(nv->node_name, val, WWN_SIZE);
3600#endif
3601}
3602
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003603int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003604qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003605{
David Miller4e08df32007-04-16 12:37:43 -07003606 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003607 struct init_cb_24xx *icb;
3608 struct nvram_24xx *nv;
3609 uint32_t *dptr;
3610 uint8_t *dptr1, *dptr2;
3611 uint32_t chksum;
3612 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003613 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003614
David Miller4e08df32007-04-16 12:37:43 -07003615 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003616 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003617 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003618
3619 /* Determine NVRAM starting address. */
3620 ha->nvram_size = sizeof(struct nvram_24xx);
3621 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003622 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3623 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3624 if (PCI_FUNC(ha->pdev->devfn)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003625 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003626 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3627 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003628
Seokmann Ju281afe12007-07-26 13:43:34 -07003629 /* Get VPD data into cache */
3630 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003631 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07003632 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3633
3634 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003635 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003636 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003637 ha->nvram_size);
3638 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3639 chksum += le32_to_cpu(*dptr++);
3640
3641 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07003642 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003643
3644 /* Bad NVRAM data, set defaults parameters. */
3645 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3646 || nv->id[3] != ' ' ||
3647 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3648 /* Reset NVRAM data. */
3649 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3650 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3651 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07003652 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3653 "invalid -- WWPN) defaults.\n");
3654
3655 /*
3656 * Set default initialization control block.
3657 */
3658 memset(nv, 0, ha->nvram_size);
3659 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3660 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3661 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3662 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3663 nv->exchange_count = __constant_cpu_to_le16(0);
3664 nv->hard_address = __constant_cpu_to_le16(124);
3665 nv->port_name[0] = 0x21;
3666 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3667 nv->port_name[2] = 0x00;
3668 nv->port_name[3] = 0xe0;
3669 nv->port_name[4] = 0x8b;
3670 nv->port_name[5] = 0x1c;
3671 nv->port_name[6] = 0x55;
3672 nv->port_name[7] = 0x86;
3673 nv->node_name[0] = 0x20;
3674 nv->node_name[1] = 0x00;
3675 nv->node_name[2] = 0x00;
3676 nv->node_name[3] = 0xe0;
3677 nv->node_name[4] = 0x8b;
3678 nv->node_name[5] = 0x1c;
3679 nv->node_name[6] = 0x55;
3680 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003681 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07003682 nv->login_retry_count = __constant_cpu_to_le16(8);
3683 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3684 nv->login_timeout = __constant_cpu_to_le16(0);
3685 nv->firmware_options_1 =
3686 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3687 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3688 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3689 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3690 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3691 nv->efi_parameters = __constant_cpu_to_le32(0);
3692 nv->reset_delay = 5;
3693 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3694 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3695 nv->link_down_timeout = __constant_cpu_to_le16(30);
3696
3697 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003698 }
3699
3700 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003701 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003702
3703 /* Copy 1st segment. */
3704 dptr1 = (uint8_t *)icb;
3705 dptr2 = (uint8_t *)&nv->version;
3706 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3707 while (cnt--)
3708 *dptr1++ = *dptr2++;
3709
3710 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07003711 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003712
3713 /* Copy 2nd segment. */
3714 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3715 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3716 cnt = (uint8_t *)&icb->reserved_3 -
3717 (uint8_t *)&icb->interrupt_delay_timer;
3718 while (cnt--)
3719 *dptr1++ = *dptr2++;
3720
3721 /*
3722 * Setup driver NVRAM options.
3723 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003724 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003725 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003726
Andrew Vasquez5341e862006-05-17 15:09:16 -07003727 /* Use alternate WWN? */
3728 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3729 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3730 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3731 }
3732
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003733 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003734 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003735 /*
3736 * Firmware will apply the following mask if the nodename was
3737 * not provided.
3738 */
3739 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3740 icb->node_name[0] &= 0xF0;
3741 }
3742
3743 /* Set host adapter parameters. */
3744 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08003745 ha->flags.enable_lip_reset = 0;
3746 ha->flags.enable_lip_full_login =
3747 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3748 ha->flags.enable_target_reset =
3749 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003750 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07003751 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003752
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003753 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3754 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003755
3756 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3757 sizeof(ha->fw_seriallink_options24));
3758
3759 /* save HBA serial number */
3760 ha->serial0 = icb->port_name[5];
3761 ha->serial1 = icb->port_name[6];
3762 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003763 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
3764 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003765
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08003766 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3767
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003768 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3769
3770 /* Set minimum login_timeout to 4 seconds. */
3771 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3772 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3773 if (le16_to_cpu(nv->login_timeout) < 4)
3774 nv->login_timeout = __constant_cpu_to_le16(4);
3775 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07003776 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003777
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003778 /* Set minimum RATOV to 100 tenths of a second. */
3779 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003780
3781 ha->loop_reset_delay = nv->reset_delay;
3782
3783 /* Link Down Timeout = 0:
3784 *
3785 * When Port Down timer expires we will start returning
3786 * I/O's to OS with "DID_NO_CONNECT".
3787 *
3788 * Link Down Timeout != 0:
3789 *
3790 * The driver waits for the link to come up after link down
3791 * before returning I/Os to OS with "DID_NO_CONNECT".
3792 */
3793 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3794 ha->loop_down_abort_time =
3795 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3796 } else {
3797 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3798 ha->loop_down_abort_time =
3799 (LOOP_DOWN_TIME - ha->link_down_timeout);
3800 }
3801
3802 /* Need enough time to try and get the port back. */
3803 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3804 if (qlport_down_retry)
3805 ha->port_down_retry_count = qlport_down_retry;
3806
3807 /* Set login_retry_count */
3808 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3809 if (ha->port_down_retry_count ==
3810 le16_to_cpu(nv->port_down_retry_count) &&
3811 ha->port_down_retry_count > 3)
3812 ha->login_retry_count = ha->port_down_retry_count;
3813 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3814 ha->login_retry_count = ha->port_down_retry_count;
3815 if (ql2xloginretrycount)
3816 ha->login_retry_count = ql2xloginretrycount;
3817
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003818 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003819 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003820 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3821 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3822 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3823 le16_to_cpu(icb->interrupt_delay_timer): 2;
3824 }
3825 icb->firmware_options_2 &= __constant_cpu_to_le32(
3826 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003827 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003828 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08003829 ha->zio_mode = QLA_ZIO_MODE_6;
3830
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003831 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003832 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003833 ha->zio_timer * 100));
3834 qla_printk(KERN_INFO, ha,
3835 "ZIO mode %d enabled; timer delay (%d us).\n",
3836 ha->zio_mode, ha->zio_timer * 100);
3837
3838 icb->firmware_options_2 |= cpu_to_le32(
3839 (uint32_t)ha->zio_mode);
3840 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003841 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003842 }
3843
David Miller4e08df32007-04-16 12:37:43 -07003844 if (rval) {
3845 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003846 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07003847 }
3848 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003849}
3850
Adrian Bunk413975a2006-06-30 02:33:06 -07003851static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003852qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003853{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003854 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003855 int segments, fragment;
3856 uint32_t faddr;
3857 uint32_t *dcode, dlen;
3858 uint32_t risc_addr;
3859 uint32_t risc_size;
3860 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003861 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003862 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08003863
3864 qla_printk(KERN_INFO, ha,
3865 "FW: Loading from flash (%x)...\n", ha->flt_region_fw);
3866
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003867 rval = QLA_SUCCESS;
3868
3869 segments = FA_RISC_CODE_SEGMENTS;
Andrew Vasquezc00d8992008-09-11 21:22:49 -07003870 faddr = ha->flt_region_fw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003871 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003872 *srisc_addr = 0;
3873
3874 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003875 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003876 for (i = 0; i < 4; i++)
3877 dcode[i] = be32_to_cpu(dcode[i]);
3878 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3879 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3880 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3881 dcode[3] == 0)) {
3882 qla_printk(KERN_WARNING, ha,
3883 "Unable to verify integrity of flash firmware image!\n");
3884 qla_printk(KERN_WARNING, ha,
3885 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3886 dcode[1], dcode[2], dcode[3]);
3887
3888 return QLA_FUNCTION_FAILED;
3889 }
3890
3891 while (segments && rval == QLA_SUCCESS) {
3892 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003893 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003894
3895 risc_addr = be32_to_cpu(dcode[2]);
3896 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3897 risc_size = be32_to_cpu(dcode[3]);
3898
3899 fragment = 0;
3900 while (risc_size > 0 && rval == QLA_SUCCESS) {
3901 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3902 if (dlen > risc_size)
3903 dlen = risc_size;
3904
3905 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3906 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003907 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003908
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003909 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003910 for (i = 0; i < dlen; i++)
3911 dcode[i] = swab32(dcode[i]);
3912
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003913 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003914 dlen);
3915 if (rval) {
3916 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003917 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003918 fragment));
3919 qla_printk(KERN_WARNING, ha,
3920 "[ERROR] Failed to load segment %d of "
3921 "firmware\n", fragment);
3922 break;
3923 }
3924
3925 faddr += dlen;
3926 risc_addr += dlen;
3927 risc_size -= dlen;
3928 fragment++;
3929 }
3930
3931 /* Next segment. */
3932 segments--;
3933 }
3934
3935 return rval;
3936}
3937
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003938#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3939
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003940int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003941qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08003942{
3943 int rval;
3944 int i, fragment;
3945 uint16_t *wcode, *fwcode;
3946 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3947 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003948 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003949 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08003950
3951 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003952 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08003953 if (!blob) {
3954 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003955 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3956 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08003957 return QLA_FUNCTION_FAILED;
3958 }
3959
3960 rval = QLA_SUCCESS;
3961
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003962 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08003963 *srisc_addr = 0;
3964 fwcode = (uint16_t *)blob->fw->data;
3965 fwclen = 0;
3966
3967 /* Validate firmware image by checking version. */
3968 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3969 qla_printk(KERN_WARNING, ha,
3970 "Unable to verify integrity of firmware image (%Zd)!\n",
3971 blob->fw->size);
3972 goto fail_fw_integrity;
3973 }
3974 for (i = 0; i < 4; i++)
3975 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3976 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3977 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3978 wcode[2] == 0 && wcode[3] == 0)) {
3979 qla_printk(KERN_WARNING, ha,
3980 "Unable to verify integrity of firmware image!\n");
3981 qla_printk(KERN_WARNING, ha,
3982 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3983 wcode[1], wcode[2], wcode[3]);
3984 goto fail_fw_integrity;
3985 }
3986
3987 seg = blob->segs;
3988 while (*seg && rval == QLA_SUCCESS) {
3989 risc_addr = *seg;
3990 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3991 risc_size = be16_to_cpu(fwcode[3]);
3992
3993 /* Validate firmware image size. */
3994 fwclen += risc_size * sizeof(uint16_t);
3995 if (blob->fw->size < fwclen) {
3996 qla_printk(KERN_WARNING, ha,
3997 "Unable to verify integrity of firmware image "
3998 "(%Zd)!\n", blob->fw->size);
3999 goto fail_fw_integrity;
4000 }
4001
4002 fragment = 0;
4003 while (risc_size > 0 && rval == QLA_SUCCESS) {
4004 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4005 if (wlen > risc_size)
4006 wlen = risc_size;
4007
4008 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004009 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004010 risc_addr, wlen));
4011
4012 for (i = 0; i < wlen; i++)
4013 wcode[i] = swab16(fwcode[i]);
4014
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004015 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004016 wlen);
4017 if (rval) {
4018 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004019 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004020 fragment));
4021 qla_printk(KERN_WARNING, ha,
4022 "[ERROR] Failed to load segment %d of "
4023 "firmware\n", fragment);
4024 break;
4025 }
4026
4027 fwcode += wlen;
4028 risc_addr += wlen;
4029 risc_size -= wlen;
4030 fragment++;
4031 }
4032
4033 /* Next segment. */
4034 seg++;
4035 }
4036 return rval;
4037
4038fail_fw_integrity:
4039 return QLA_FUNCTION_FAILED;
4040}
4041
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004042static int
4043qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004044{
4045 int rval;
4046 int segments, fragment;
4047 uint32_t *dcode, dlen;
4048 uint32_t risc_addr;
4049 uint32_t risc_size;
4050 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004051 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004052 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004053 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004054 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004055
Andrew Vasquez54333832005-11-09 15:49:04 -08004056 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004057 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004058 if (!blob) {
4059 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004060 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4061 "from: " QLA_FW_URL ".\n");
4062
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004063 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004064 }
4065
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004066 qla_printk(KERN_INFO, ha,
4067 "FW: Loading via request-firmware...\n");
4068
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004069 rval = QLA_SUCCESS;
4070
4071 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004072 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004073 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004074 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004075 fwclen = 0;
4076
4077 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004078 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004079 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004080 "Unable to verify integrity of firmware image (%Zd)!\n",
4081 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004082 goto fail_fw_integrity;
4083 }
4084 for (i = 0; i < 4; i++)
4085 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4086 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4087 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4088 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4089 dcode[3] == 0)) {
4090 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004091 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004092 qla_printk(KERN_WARNING, ha,
4093 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4094 dcode[1], dcode[2], dcode[3]);
4095 goto fail_fw_integrity;
4096 }
4097
4098 while (segments && rval == QLA_SUCCESS) {
4099 risc_addr = be32_to_cpu(fwcode[2]);
4100 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4101 risc_size = be32_to_cpu(fwcode[3]);
4102
4103 /* Validate firmware image size. */
4104 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004105 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004106 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004107 "Unable to verify integrity of firmware image "
4108 "(%Zd)!\n", blob->fw->size);
4109
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004110 goto fail_fw_integrity;
4111 }
4112
4113 fragment = 0;
4114 while (risc_size > 0 && rval == QLA_SUCCESS) {
4115 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4116 if (dlen > risc_size)
4117 dlen = risc_size;
4118
4119 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004120 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004121 risc_addr, dlen));
4122
4123 for (i = 0; i < dlen; i++)
4124 dcode[i] = swab32(fwcode[i]);
4125
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004126 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004127 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004128 if (rval) {
4129 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004130 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004131 fragment));
4132 qla_printk(KERN_WARNING, ha,
4133 "[ERROR] Failed to load segment %d of "
4134 "firmware\n", fragment);
4135 break;
4136 }
4137
4138 fwcode += dlen;
4139 risc_addr += dlen;
4140 risc_size -= dlen;
4141 fragment++;
4142 }
4143
4144 /* Next segment. */
4145 segments--;
4146 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004147 return rval;
4148
4149fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004150 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004151}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004152
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004153int
4154qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4155{
4156 int rval;
4157
4158 /*
4159 * FW Load priority:
4160 * 1) Firmware via request-firmware interface (.bin file).
4161 * 2) Firmware residing in flash.
4162 */
4163 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4164 if (rval == QLA_SUCCESS)
4165 return rval;
4166
4167 return qla24xx_load_risc_flash(vha, srisc_addr);
4168}
4169
4170int
4171qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4172{
4173 int rval;
4174
4175 /*
4176 * FW Load priority:
4177 * 1) Firmware residing in flash.
4178 * 2) Firmware via request-firmware interface (.bin file).
4179 */
4180 rval = qla24xx_load_risc_flash(vha, srisc_addr);
4181 if (rval == QLA_SUCCESS)
4182 return rval;
4183
4184 return qla24xx_load_risc_blob(vha, srisc_addr);
4185}
4186
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004187void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004188qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004189{
4190 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004191 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004192
Andrew Vasqueze4289242007-07-19 15:05:56 -07004193 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004194 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004195 if (!ha->fw_major_version)
4196 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004197
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004198 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004199 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
4200 retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004201 ha->isp_ops->reset_chip(vha);
4202 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004203 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004204 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004205 continue;
4206 qla_printk(KERN_INFO, ha,
4207 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004208 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004209 }
4210}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004211
4212int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004213qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004214{
4215 int rval = QLA_SUCCESS;
4216 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004217 struct qla_hw_data *ha = vha->hw;
4218 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004219 struct req_que *req = ha->req_q_map[vha->req_ques[0]];
4220 struct rsp_que *rsp = req->rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004221
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004222 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004223 return -EINVAL;
4224
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004225 rval = qla2x00_fw_ready(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004226 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004227 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004228 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004229 }
4230
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004231 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004232
4233 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004234 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004235 if (mb[0] != MBS_COMMAND_COMPLETE) {
4236 DEBUG15(qla_printk(KERN_INFO, ha,
4237 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4238 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4239 mb[0], mb[1], mb[2], mb[6], mb[7]));
4240 return (QLA_FUNCTION_FAILED);
4241 }
4242
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004243 atomic_set(&vha->loop_down_timer, 0);
4244 atomic_set(&vha->loop_state, LOOP_UP);
4245 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4246 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4247 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004248
4249 return rval;
4250}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004251
4252/* 84XX Support **************************************************************/
4253
4254static LIST_HEAD(qla_cs84xx_list);
4255static DEFINE_MUTEX(qla_cs84xx_mutex);
4256
4257static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004258qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004259{
4260 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004261 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004262
4263 mutex_lock(&qla_cs84xx_mutex);
4264
4265 /* Find any shared 84xx chip. */
4266 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4267 if (cs84xx->bus == ha->pdev->bus) {
4268 kref_get(&cs84xx->kref);
4269 goto done;
4270 }
4271 }
4272
4273 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4274 if (!cs84xx)
4275 goto done;
4276
4277 kref_init(&cs84xx->kref);
4278 spin_lock_init(&cs84xx->access_lock);
4279 mutex_init(&cs84xx->fw_update_mutex);
4280 cs84xx->bus = ha->pdev->bus;
4281
4282 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4283done:
4284 mutex_unlock(&qla_cs84xx_mutex);
4285 return cs84xx;
4286}
4287
4288static void
4289__qla84xx_chip_release(struct kref *kref)
4290{
4291 struct qla_chip_state_84xx *cs84xx =
4292 container_of(kref, struct qla_chip_state_84xx, kref);
4293
4294 mutex_lock(&qla_cs84xx_mutex);
4295 list_del(&cs84xx->list);
4296 mutex_unlock(&qla_cs84xx_mutex);
4297 kfree(cs84xx);
4298}
4299
4300void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004301qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004302{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004303 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004304 if (ha->cs84xx)
4305 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4306}
4307
4308static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004309qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004310{
4311 int rval;
4312 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004313 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004314
4315 mutex_lock(&ha->cs84xx->fw_update_mutex);
4316
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004317 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004318
4319 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4320
4321 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4322 QLA_SUCCESS;
4323}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004324
4325/* 81XX Support **************************************************************/
4326
4327int
4328qla81xx_nvram_config(scsi_qla_host_t *vha)
4329{
4330 int rval;
4331 struct init_cb_81xx *icb;
4332 struct nvram_81xx *nv;
4333 uint32_t *dptr;
4334 uint8_t *dptr1, *dptr2;
4335 uint32_t chksum;
4336 uint16_t cnt;
4337 struct qla_hw_data *ha = vha->hw;
4338
4339 rval = QLA_SUCCESS;
4340 icb = (struct init_cb_81xx *)ha->init_cb;
4341 nv = ha->nvram;
4342
4343 /* Determine NVRAM starting address. */
4344 ha->nvram_size = sizeof(struct nvram_81xx);
4345 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4346 ha->vpd_size = FA_NVRAM_VPD_SIZE;
4347 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4348 if (PCI_FUNC(ha->pdev->devfn) & 1) {
4349 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
4350 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4351 }
4352
4353 /* Get VPD data into cache */
4354 ha->vpd = ha->nvram + VPD_OFFSET;
4355 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
4356 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4357
4358 /* Get NVRAM data into cache and calculate checksum. */
4359 dptr = (uint32_t *)nv;
4360 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
4361 ha->nvram_size);
4362 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4363 chksum += le32_to_cpu(*dptr++);
4364
4365 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
4366 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4367
4368 /* Bad NVRAM data, set defaults parameters. */
4369 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4370 || nv->id[3] != ' ' ||
4371 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4372 /* Reset NVRAM data. */
4373 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4374 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4375 le16_to_cpu(nv->nvram_version));
4376 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4377 "invalid -- WWPN) defaults.\n");
4378
4379 /*
4380 * Set default initialization control block.
4381 */
4382 memset(nv, 0, ha->nvram_size);
4383 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4384 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4385 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4386 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4387 nv->exchange_count = __constant_cpu_to_le16(0);
4388 nv->port_name[0] = 0x21;
4389 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
4390 nv->port_name[2] = 0x00;
4391 nv->port_name[3] = 0xe0;
4392 nv->port_name[4] = 0x8b;
4393 nv->port_name[5] = 0x1c;
4394 nv->port_name[6] = 0x55;
4395 nv->port_name[7] = 0x86;
4396 nv->node_name[0] = 0x20;
4397 nv->node_name[1] = 0x00;
4398 nv->node_name[2] = 0x00;
4399 nv->node_name[3] = 0xe0;
4400 nv->node_name[4] = 0x8b;
4401 nv->node_name[5] = 0x1c;
4402 nv->node_name[6] = 0x55;
4403 nv->node_name[7] = 0x86;
4404 nv->login_retry_count = __constant_cpu_to_le16(8);
4405 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4406 nv->login_timeout = __constant_cpu_to_le16(0);
4407 nv->firmware_options_1 =
4408 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4409 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4410 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4411 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4412 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4413 nv->efi_parameters = __constant_cpu_to_le32(0);
4414 nv->reset_delay = 5;
4415 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4416 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4417 nv->link_down_timeout = __constant_cpu_to_le16(30);
4418 nv->enode_mac[0] = 0x01;
4419 nv->enode_mac[1] = 0x02;
4420 nv->enode_mac[2] = 0x03;
4421 nv->enode_mac[3] = 0x04;
4422 nv->enode_mac[4] = 0x05;
4423 nv->enode_mac[5] = 0x06 + PCI_FUNC(ha->pdev->devfn);
4424
4425 rval = 1;
4426 }
4427
4428 /* Reset Initialization control block */
4429 memset(icb, 0, sizeof(struct init_cb_81xx));
4430
4431 /* Copy 1st segment. */
4432 dptr1 = (uint8_t *)icb;
4433 dptr2 = (uint8_t *)&nv->version;
4434 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4435 while (cnt--)
4436 *dptr1++ = *dptr2++;
4437
4438 icb->login_retry_count = nv->login_retry_count;
4439
4440 /* Copy 2nd segment. */
4441 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4442 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4443 cnt = (uint8_t *)&icb->reserved_5 -
4444 (uint8_t *)&icb->interrupt_delay_timer;
4445 while (cnt--)
4446 *dptr1++ = *dptr2++;
4447
4448 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
4449 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4450 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
4451 icb->enode_mac[0] = 0x01;
4452 icb->enode_mac[1] = 0x02;
4453 icb->enode_mac[2] = 0x03;
4454 icb->enode_mac[3] = 0x04;
4455 icb->enode_mac[4] = 0x05;
4456 icb->enode_mac[5] = 0x06 + PCI_FUNC(ha->pdev->devfn);
4457 }
4458
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004459 /* Use extended-initialization control block. */
4460 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
4461
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004462 /*
4463 * Setup driver NVRAM options.
4464 */
4465 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
4466 "QLE81XX");
4467
4468 /* Use alternate WWN? */
4469 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4470 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4471 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4472 }
4473
4474 /* Prepare nodename */
4475 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4476 /*
4477 * Firmware will apply the following mask if the nodename was
4478 * not provided.
4479 */
4480 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4481 icb->node_name[0] &= 0xF0;
4482 }
4483
4484 /* Set host adapter parameters. */
4485 ha->flags.disable_risc_code_load = 0;
4486 ha->flags.enable_lip_reset = 0;
4487 ha->flags.enable_lip_full_login =
4488 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4489 ha->flags.enable_target_reset =
4490 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4491 ha->flags.enable_led_scheme = 0;
4492 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4493
4494 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4495 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4496
4497 /* save HBA serial number */
4498 ha->serial0 = icb->port_name[5];
4499 ha->serial1 = icb->port_name[6];
4500 ha->serial2 = icb->port_name[7];
4501 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4502 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4503
4504 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4505
4506 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4507
4508 /* Set minimum login_timeout to 4 seconds. */
4509 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4510 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4511 if (le16_to_cpu(nv->login_timeout) < 4)
4512 nv->login_timeout = __constant_cpu_to_le16(4);
4513 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4514 icb->login_timeout = nv->login_timeout;
4515
4516 /* Set minimum RATOV to 100 tenths of a second. */
4517 ha->r_a_tov = 100;
4518
4519 ha->loop_reset_delay = nv->reset_delay;
4520
4521 /* Link Down Timeout = 0:
4522 *
4523 * When Port Down timer expires we will start returning
4524 * I/O's to OS with "DID_NO_CONNECT".
4525 *
4526 * Link Down Timeout != 0:
4527 *
4528 * The driver waits for the link to come up after link down
4529 * before returning I/Os to OS with "DID_NO_CONNECT".
4530 */
4531 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4532 ha->loop_down_abort_time =
4533 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4534 } else {
4535 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4536 ha->loop_down_abort_time =
4537 (LOOP_DOWN_TIME - ha->link_down_timeout);
4538 }
4539
4540 /* Need enough time to try and get the port back. */
4541 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4542 if (qlport_down_retry)
4543 ha->port_down_retry_count = qlport_down_retry;
4544
4545 /* Set login_retry_count */
4546 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4547 if (ha->port_down_retry_count ==
4548 le16_to_cpu(nv->port_down_retry_count) &&
4549 ha->port_down_retry_count > 3)
4550 ha->login_retry_count = ha->port_down_retry_count;
4551 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4552 ha->login_retry_count = ha->port_down_retry_count;
4553 if (ql2xloginretrycount)
4554 ha->login_retry_count = ql2xloginretrycount;
4555
4556 /* Enable ZIO. */
4557 if (!vha->flags.init_done) {
4558 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4559 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4560 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4561 le16_to_cpu(icb->interrupt_delay_timer): 2;
4562 }
4563 icb->firmware_options_2 &= __constant_cpu_to_le32(
4564 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4565 vha->flags.process_response_queue = 0;
4566 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4567 ha->zio_mode = QLA_ZIO_MODE_6;
4568
4569 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4570 "(%d us).\n", vha->host_no, ha->zio_mode,
4571 ha->zio_timer * 100));
4572 qla_printk(KERN_INFO, ha,
4573 "ZIO mode %d enabled; timer delay (%d us).\n",
4574 ha->zio_mode, ha->zio_timer * 100);
4575
4576 icb->firmware_options_2 |= cpu_to_le32(
4577 (uint32_t)ha->zio_mode);
4578 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4579 vha->flags.process_response_queue = 1;
4580 }
4581
4582 if (rval) {
4583 DEBUG2_3(printk(KERN_WARNING
4584 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4585 }
4586 return (rval);
4587}
4588
4589void
4590qla81xx_update_fw_options(scsi_qla_host_t *ha)
4591{
4592}