blob: 3ec6eaca96d467030f2a82d29d9fc1b63eb168a3 [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 Vasquezc3a2f0d2007-07-19 20:37:34 -0700781 fixed_size = IS_QLA25XX(ha) ?
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800782 offsetof(struct qla25xx_fw_dump, ext_mem) :
783 offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700784 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
785 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800786 if (ha->mqenable)
787 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700788
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700789 /* Allocate memory for Fibre Channel Event Buffer. */
790 if (!IS_QLA25XX(ha))
791 goto try_eft;
792
793 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
794 GFP_KERNEL);
795 if (!tc) {
796 qla_printk(KERN_WARNING, ha, "Unable to allocate "
797 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800798 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700799 }
800
801 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800802 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700803 ha->fce_mb, &ha->fce_bufs);
804 if (rval) {
805 qla_printk(KERN_WARNING, ha, "Unable to initialize "
806 "FCE (%d).\n", rval);
807 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
808 tc_dma);
809 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800810 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700811 }
812
813 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
814 FCE_SIZE / 1024);
815
816 fce_size = sizeof(struct qla2xxx_fce_chain) + EFT_SIZE;
817 ha->flags.fce_enabled = 1;
818 ha->fce_dma = tc_dma;
819 ha->fce = tc;
820try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700821 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800822 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700823 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800824 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700825 qla_printk(KERN_WARNING, ha, "Unable to allocate "
826 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
827 goto cont_alloc;
828 }
829
Andrew Vasquezfc447652008-01-17 09:02:18 -0800830 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800831 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700832 if (rval) {
833 qla_printk(KERN_WARNING, ha, "Unable to initialize "
834 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800835 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
836 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700837 goto cont_alloc;
838 }
839
840 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
841 EFT_SIZE / 1024);
842
843 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800844 ha->eft_dma = tc_dma;
845 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700846 }
847cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800848 req_q_size = req->length * sizeof(request_t);
849 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700850
851 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
852 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800853 mq_size + eft_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700854
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700855 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700856 if (!ha->fw_dump) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700857 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700858 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700859
860 if (ha->eft) {
861 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
862 ha->eft_dma);
863 ha->eft = NULL;
864 ha->eft_dma = 0;
865 }
866 return;
867 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700868 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
869 dump_size / 1024);
870
871 ha->fw_dump_len = dump_size;
872 ha->fw_dump->signature[0] = 'Q';
873 ha->fw_dump->signature[1] = 'L';
874 ha->fw_dump->signature[2] = 'G';
875 ha->fw_dump->signature[3] = 'C';
876 ha->fw_dump->version = __constant_htonl(1);
877
878 ha->fw_dump->fixed_size = htonl(fixed_size);
879 ha->fw_dump->mem_size = htonl(mem_size);
880 ha->fw_dump->req_q_size = htonl(req_q_size);
881 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
882
883 ha->fw_dump->eft_size = htonl(eft_size);
884 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
885 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
886
887 ha->fw_dump->header_size =
888 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700889}
890
891/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
893 * @ha: HA context
894 *
895 * Returns 0 on success.
896 */
897static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800898qla2x00_resize_request_q(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899{
900 int rval;
901 uint16_t fw_iocb_cnt = 0;
902 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
903 dma_addr_t request_dma;
904 request_t *request_ring;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800905 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800906 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
908 /* Valid only on recent ISPs. */
909 if (IS_QLA2100(ha) || IS_QLA2200(ha))
910 return;
911
912 /* Retrieve IOCB counts available to the firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800913 rval = qla2x00_get_resource_cnts(vha, NULL, NULL, NULL, &fw_iocb_cnt,
914 &ha->max_npiv_vports);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 if (rval)
916 return;
917 /* No point in continuing if current settings are sufficient. */
918 if (fw_iocb_cnt < 1024)
919 return;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800920 if (req->length >= request_q_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 return;
922
923 /* Attempt to claim larger area for request queue. */
924 request_ring = dma_alloc_coherent(&ha->pdev->dev,
925 (request_q_length + 1) * sizeof(request_t), &request_dma,
926 GFP_KERNEL);
927 if (request_ring == NULL)
928 return;
929
930 /* Resize successful, report extensions. */
931 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
932 (ha->fw_memory_size + 1) / 1024);
933 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800934 "(%d -> %d)...\n", req->length, request_q_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
936 /* Clear old allocations. */
937 dma_free_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800938 (req->length + 1) * sizeof(request_t), req->ring,
939 req->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
941 /* Begin using larger queue. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800942 req->length = request_q_length;
943 req->ring = request_ring;
944 req->dma = request_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945}
946
947/**
948 * qla2x00_setup_chip() - Load and start RISC firmware.
949 * @ha: HA context
950 *
951 * Returns 0 on success.
952 */
953static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800954qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955{
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700956 int rval;
957 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800958 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -0800959 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
960 unsigned long flags;
961
962 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
963 /* Disable SRAM, Instruction RAM and GP RAM parity. */
964 spin_lock_irqsave(&ha->hardware_lock, flags);
965 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
966 RD_REG_WORD(&reg->hccr);
967 spin_unlock_irqrestore(&ha->hardware_lock, flags);
968 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
970 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800971 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700972 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800974 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800976 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 if (rval == QLA_SUCCESS) {
978 /* Start firmware execution. */
979 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800980 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800982 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 /* Retrieve firmware information. */
984 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800985 qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 &ha->fw_major_version,
987 &ha->fw_minor_version,
988 &ha->fw_subminor_version,
989 &ha->fw_attributes, &ha->fw_memory_size);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700990 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800991 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -0700992 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700993 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700994 if ((!ha->max_npiv_vports) ||
995 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800996 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700997 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800998 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700999 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001000 qla2x00_resize_request_q(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001001
1002 if (ql2xallocfwdump)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001003 qla2x00_alloc_fw_dump(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 }
1005 } else {
1006 DEBUG2(printk(KERN_INFO
1007 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001008 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 }
1010 }
1011
Andrew Vasquez3db06522008-01-31 12:33:49 -08001012 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1013 /* Enable proper parity. */
1014 spin_lock_irqsave(&ha->hardware_lock, flags);
1015 if (IS_QLA2300(ha))
1016 /* SRAM parity */
1017 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1018 else
1019 /* SRAM, Instruction RAM and GP RAM parity */
1020 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1021 RD_REG_WORD(&reg->hccr);
1022 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1023 }
1024
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 if (rval) {
1026 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001027 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 }
1029
1030 return (rval);
1031}
1032
1033/**
1034 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1035 * @ha: HA context
1036 *
1037 * Beginning of request ring has initialization control block already built
1038 * by nvram config routine.
1039 *
1040 * Returns 0 on success.
1041 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001042void
1043qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044{
1045 uint16_t cnt;
1046 response_t *pkt;
1047
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001048 pkt = rsp->ring_ptr;
1049 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 pkt->signature = RESPONSE_PROCESSED;
1051 pkt++;
1052 }
1053
1054}
1055
1056/**
1057 * qla2x00_update_fw_options() - Read and process firmware options.
1058 * @ha: HA context
1059 *
1060 * Returns 0 on success.
1061 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001062void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001063qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064{
1065 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001066 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
1068 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001069 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070
1071 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1072 return;
1073
1074 /* Serial Link options. */
1075 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001076 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1078 sizeof(ha->fw_seriallink_options)));
1079
1080 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1081 if (ha->fw_seriallink_options[3] & BIT_2) {
1082 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1083
1084 /* 1G settings */
1085 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1086 emphasis = (ha->fw_seriallink_options[2] &
1087 (BIT_4 | BIT_3)) >> 3;
1088 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001089 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 rx_sens = (ha->fw_seriallink_options[0] &
1091 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1092 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1093 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1094 if (rx_sens == 0x0)
1095 rx_sens = 0x3;
1096 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1097 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1098 ha->fw_options[10] |= BIT_5 |
1099 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1100 (tx_sens & (BIT_1 | BIT_0));
1101
1102 /* 2G settings */
1103 swing = (ha->fw_seriallink_options[2] &
1104 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1105 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1106 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001107 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 rx_sens = (ha->fw_seriallink_options[1] &
1109 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1110 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1111 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1112 if (rx_sens == 0x0)
1113 rx_sens = 0x3;
1114 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1115 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1116 ha->fw_options[11] |= BIT_5 |
1117 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1118 (tx_sens & (BIT_1 | BIT_0));
1119 }
1120
1121 /* FCP2 options. */
1122 /* Return command IOCBs without waiting for an ABTS to complete. */
1123 ha->fw_options[3] |= BIT_13;
1124
1125 /* LED scheme. */
1126 if (ha->flags.enable_led_scheme)
1127 ha->fw_options[2] |= BIT_12;
1128
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001129 /* Detect ISP6312. */
1130 if (IS_QLA6312(ha))
1131 ha->fw_options[2] |= BIT_13;
1132
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001134 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135}
1136
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001137void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001138qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001139{
1140 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001141 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001142
1143 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001144 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001145 return;
1146
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001147 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001148 le16_to_cpu(ha->fw_seriallink_options24[1]),
1149 le16_to_cpu(ha->fw_seriallink_options24[2]),
1150 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001151 if (rval != QLA_SUCCESS) {
1152 qla_printk(KERN_WARNING, ha,
1153 "Unable to update Serial Link options (%x).\n", rval);
1154 }
1155}
1156
1157void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001158qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001159{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001160 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001161 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001162 struct req_que *req = ha->req_q_map[0];
1163 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001164
1165 /* Setup ring parameters in initialization control block. */
1166 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1167 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001168 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1169 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1170 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1171 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1172 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1173 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001174
1175 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1176 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1177 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1178 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1179 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1180}
1181
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001182void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001183qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001184{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001185 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001186 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1187 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1188 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001189 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001190 uint16_t rid = 0;
1191 struct req_que *req = ha->req_q_map[0];
1192 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001193
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001194/* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001195 icb = (struct init_cb_24xx *)ha->init_cb;
1196 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1197 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001198 icb->request_q_length = cpu_to_le16(req->length);
1199 icb->response_q_length = cpu_to_le16(rsp->length);
1200 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1201 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1202 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1203 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001204
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001205 if (ha->mqenable) {
1206 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1207 icb->rid = __constant_cpu_to_le16(rid);
1208 if (ha->flags.msix_enabled) {
1209 msix = &ha->msix_entries[1];
1210 DEBUG2_17(printk(KERN_INFO
1211 "Reistering vector 0x%x for base que\n", msix->entry));
1212 icb->msix = cpu_to_le16(msix->entry);
1213 }
1214 /* Use alternate PCI bus number */
1215 if (MSB(rid))
1216 icb->firmware_options_2 |=
1217 __constant_cpu_to_le32(BIT_19);
1218 /* Use alternate PCI devfn */
1219 if (LSB(rid))
1220 icb->firmware_options_2 |=
1221 __constant_cpu_to_le32(BIT_18);
1222
1223 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22);
1224 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
1225 ha->rsp_q_map[0]->options = icb->firmware_options_2;
1226
1227 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1228 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1229 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1230 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1231 } else {
1232 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1233 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1234 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1235 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1236 }
1237 /* PCI posting */
1238 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001239}
1240
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241/**
1242 * qla2x00_init_rings() - Initializes firmware.
1243 * @ha: HA context
1244 *
1245 * Beginning of request ring has initialization control block already built
1246 * by nvram config routine.
1247 *
1248 * Returns 0 on success.
1249 */
1250static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001251qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252{
1253 int rval;
1254 unsigned long flags = 0;
1255 int cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001256 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001257 struct req_que *req = ha->req_q_map[0];
1258 struct rsp_que *rsp = ha->rsp_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001259 struct mid_init_cb_24xx *mid_init_cb =
1260 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
1262 spin_lock_irqsave(&ha->hardware_lock, flags);
1263
1264 /* Clear outstanding commands array. */
1265 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001266 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001268 req->current_outstanding_cmd = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269
1270 /* Clear RSCN queue. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001271 vha->rscn_in_ptr = 0;
1272 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273
1274 /* Initialize firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001275 req->ring_ptr = req->ring;
1276 req->ring_index = 0;
1277 req->cnt = req->length;
1278 rsp->ring_ptr = rsp->ring;
1279 rsp->ring_index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 /* Initialize response queue entries */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001282 qla2x00_init_response_q_entries(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001284 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285
1286 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1287
1288 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001289 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001291 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001292
Seokmann Juc48339d2008-01-17 09:02:19 -08001293 if (ha->flags.npiv_supported)
1294 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
1295
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001296 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001297
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001298 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 if (rval) {
1300 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001301 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 } else {
1303 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001304 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 }
1306
1307 return (rval);
1308}
1309
1310/**
1311 * qla2x00_fw_ready() - Waits for firmware ready.
1312 * @ha: HA context
1313 *
1314 * Returns 0 on success.
1315 */
1316static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001317qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318{
1319 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001320 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 uint16_t min_wait; /* Minimum wait time if loop is down */
1322 uint16_t wait_time; /* Wait time if loop is coming ready */
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001323 uint16_t state[3];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001324 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325
1326 rval = QLA_SUCCESS;
1327
1328 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001329 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
1331 /*
1332 * Firmware should take at most one RATOV to login, plus 5 seconds for
1333 * our own processing.
1334 */
1335 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1336 wait_time = min_wait;
1337 }
1338
1339 /* Min wait time if loop down */
1340 mtime = jiffies + (min_wait * HZ);
1341
1342 /* wait time before firmware ready */
1343 wtime = jiffies + (wait_time * HZ);
1344
1345 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001346 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1348
1349 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001350 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351
1352 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001353 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001355 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001356 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001358 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1359 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001360 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001361 state[2]));
1362 if ((state[2] & FSTATE_LOGGED_IN) &&
1363 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1364 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001365 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001366
1367 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001368 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001369 if (rval != QLA_SUCCESS)
1370 break;
1371
1372 /* Add time taken to initialize. */
1373 cs84xx_time = jiffies - cs84xx_time;
1374 wtime += cs84xx_time;
1375 mtime += cs84xx_time;
1376 DEBUG16(printk("scsi(%ld): Increasing "
1377 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001378 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001379 }
1380 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001382 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001384 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 &ha->login_timeout, &ha->r_a_tov);
1386
1387 rval = QLA_SUCCESS;
1388 break;
1389 }
1390
1391 rval = QLA_FUNCTION_FAILED;
1392
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001393 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001394 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001396 * other than Wait for Login.
1397 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 if (time_after_eq(jiffies, mtime)) {
1399 qla_printk(KERN_INFO, ha,
1400 "Cable is unplugged...\n");
1401
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001402 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 break;
1404 }
1405 }
1406 } else {
1407 /* Mailbox cmd failed. Timeout on min_wait. */
1408 if (time_after_eq(jiffies, mtime))
1409 break;
1410 }
1411
1412 if (time_after_eq(jiffies, wtime))
1413 break;
1414
1415 /* Delay for a while */
1416 msleep(500);
1417
1418 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001419 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 } while (1);
1421
1422 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001423 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
1425 if (rval) {
1426 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001427 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 }
1429
1430 return (rval);
1431}
1432
1433/*
1434* qla2x00_configure_hba
1435* Setup adapter context.
1436*
1437* Input:
1438* ha = adapter state pointer.
1439*
1440* Returns:
1441* 0 = success
1442*
1443* Context:
1444* Kernel context.
1445*/
1446static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001447qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448{
1449 int rval;
1450 uint16_t loop_id;
1451 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001452 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 uint8_t al_pa;
1454 uint8_t area;
1455 uint8_t domain;
1456 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001457 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458
1459 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001460 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001461 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001463 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001464 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1465 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001466 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08001467 } else {
1468 qla_printk(KERN_WARNING, ha,
1469 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001470 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08001471 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 return (rval);
1473 }
1474
1475 if (topo == 4) {
1476 qla_printk(KERN_INFO, ha,
1477 "Cannot get topology - retrying.\n");
1478 return (QLA_FUNCTION_FAILED);
1479 }
1480
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001481 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
1483 /* initialize */
1484 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1485 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001486 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
1488 switch (topo) {
1489 case 0:
1490 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001491 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 ha->current_topology = ISP_CFG_NL;
1493 strcpy(connect_type, "(Loop)");
1494 break;
1495
1496 case 1:
1497 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001498 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001499 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 ha->current_topology = ISP_CFG_FL;
1501 strcpy(connect_type, "(FL_Port)");
1502 break;
1503
1504 case 2:
1505 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001506 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 ha->operating_mode = P2P;
1508 ha->current_topology = ISP_CFG_N;
1509 strcpy(connect_type, "(N_Port-to-N_Port)");
1510 break;
1511
1512 case 3:
1513 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001514 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001515 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 ha->operating_mode = P2P;
1517 ha->current_topology = ISP_CFG_F;
1518 strcpy(connect_type, "(F_Port)");
1519 break;
1520
1521 default:
1522 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1523 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001524 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 ha->current_topology = ISP_CFG_NL;
1526 strcpy(connect_type, "(Loop)");
1527 break;
1528 }
1529
1530 /* Save Host port and loop ID. */
1531 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001532 vha->d_id.b.domain = domain;
1533 vha->d_id.b.area = area;
1534 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001536 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 qla_printk(KERN_INFO, ha,
1538 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001539 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540
1541 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001542 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001544 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 }
1546
1547 return(rval);
1548}
1549
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001550static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001551qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1552 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001553{
1554 char *st, *en;
1555 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001556 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001557
1558 if (memcmp(model, BINZERO, len) != 0) {
1559 strncpy(ha->model_number, model, len);
1560 st = en = ha->model_number;
1561 en += len - 1;
1562 while (en > st) {
1563 if (*en != 0x20 && *en != 0x00)
1564 break;
1565 *en-- = '\0';
1566 }
1567
1568 index = (ha->pdev->subsystem_device & 0xff);
1569 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1570 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001571 strncpy(ha->model_desc,
1572 qla2x00_model_name[index * 2 + 1],
1573 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001574 } else {
1575 index = (ha->pdev->subsystem_device & 0xff);
1576 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1577 index < QLA_MODEL_NAMES) {
1578 strcpy(ha->model_number,
1579 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001580 strncpy(ha->model_desc,
1581 qla2x00_model_name[index * 2 + 1],
1582 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001583 } else {
1584 strcpy(ha->model_number, def);
1585 }
1586 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001587 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001588 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001589 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001590}
1591
David Miller4e08df32007-04-16 12:37:43 -07001592/* On sparc systems, obtain port and node WWN from firmware
1593 * properties.
1594 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001595static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07001596{
1597#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001598 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07001599 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07001600 struct device_node *dp = pci_device_to_OF_node(pdev);
1601 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07001602 int len;
1603
1604 val = of_get_property(dp, "port-wwn", &len);
1605 if (val && len >= WWN_SIZE)
1606 memcpy(nv->port_name, val, WWN_SIZE);
1607
1608 val = of_get_property(dp, "node-wwn", &len);
1609 if (val && len >= WWN_SIZE)
1610 memcpy(nv->node_name, val, WWN_SIZE);
1611#endif
1612}
1613
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614/*
1615* NVRAM configuration for ISP 2xxx
1616*
1617* Input:
1618* ha = adapter block pointer.
1619*
1620* Output:
1621* initialization control block in response_ring
1622* host adapters parameters in host adapter block
1623*
1624* Returns:
1625* 0 = success.
1626*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001627int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001628qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629{
David Miller4e08df32007-04-16 12:37:43 -07001630 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001631 uint8_t chksum = 0;
1632 uint16_t cnt;
1633 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001634 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001635 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07001636 nvram_t *nv = ha->nvram;
1637 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001638 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639
David Miller4e08df32007-04-16 12:37:43 -07001640 rval = QLA_SUCCESS;
1641
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001643 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 ha->nvram_base = 0;
1645 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1646 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
1647 ha->nvram_base = 0x80;
1648
1649 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001650 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001651 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1652 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001654 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07001655 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656
1657 /* Bad NVRAM data, set defaults parameters. */
1658 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1659 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1660 /* Reset NVRAM data. */
1661 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1662 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1663 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07001664 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1665 "invalid -- WWPN) defaults.\n");
1666
1667 /*
1668 * Set default initialization control block.
1669 */
1670 memset(nv, 0, ha->nvram_size);
1671 nv->parameter_block_version = ICB_VERSION;
1672
1673 if (IS_QLA23XX(ha)) {
1674 nv->firmware_options[0] = BIT_2 | BIT_1;
1675 nv->firmware_options[1] = BIT_7 | BIT_5;
1676 nv->add_firmware_options[0] = BIT_5;
1677 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1678 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1679 nv->special_options[1] = BIT_7;
1680 } else if (IS_QLA2200(ha)) {
1681 nv->firmware_options[0] = BIT_2 | BIT_1;
1682 nv->firmware_options[1] = BIT_7 | BIT_5;
1683 nv->add_firmware_options[0] = BIT_5;
1684 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1685 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1686 } else if (IS_QLA2100(ha)) {
1687 nv->firmware_options[0] = BIT_3 | BIT_1;
1688 nv->firmware_options[1] = BIT_5;
1689 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1690 }
1691
1692 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1693 nv->execution_throttle = __constant_cpu_to_le16(16);
1694 nv->retry_count = 8;
1695 nv->retry_delay = 1;
1696
1697 nv->port_name[0] = 33;
1698 nv->port_name[3] = 224;
1699 nv->port_name[4] = 139;
1700
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001701 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07001702
1703 nv->login_timeout = 4;
1704
1705 /*
1706 * Set default host adapter parameters
1707 */
1708 nv->host_p[1] = BIT_2;
1709 nv->reset_delay = 5;
1710 nv->port_down_retry_count = 8;
1711 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1712 nv->link_down_timeout = 60;
1713
1714 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 }
1716
1717#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1718 /*
1719 * The SN2 does not provide BIOS emulation which means you can't change
1720 * potentially bogus BIOS settings. Force the use of default settings
1721 * for link rate and frame size. Hope that the rest of the settings
1722 * are valid.
1723 */
1724 if (ia64_platform_is("sn2")) {
1725 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1726 if (IS_QLA23XX(ha))
1727 nv->special_options[1] = BIT_7;
1728 }
1729#endif
1730
1731 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001732 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733
1734 /*
1735 * Setup driver NVRAM options.
1736 */
1737 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1738 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1739 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1740 nv->firmware_options[1] &= ~BIT_4;
1741
1742 if (IS_QLA23XX(ha)) {
1743 nv->firmware_options[0] |= BIT_2;
1744 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001745 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746
1747 if (IS_QLA2300(ha)) {
1748 if (ha->fb_rev == FPM_2310) {
1749 strcpy(ha->model_number, "QLA2310");
1750 } else {
1751 strcpy(ha->model_number, "QLA2300");
1752 }
1753 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001754 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001755 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 }
1757 } else if (IS_QLA2200(ha)) {
1758 nv->firmware_options[0] |= BIT_2;
1759 /*
1760 * 'Point-to-point preferred, else loop' is not a safe
1761 * connection mode setting.
1762 */
1763 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1764 (BIT_5 | BIT_4)) {
1765 /* Force 'loop preferred, else point-to-point'. */
1766 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1767 nv->add_firmware_options[0] |= BIT_5;
1768 }
1769 strcpy(ha->model_number, "QLA22xx");
1770 } else /*if (IS_QLA2100(ha))*/ {
1771 strcpy(ha->model_number, "QLA2100");
1772 }
1773
1774 /*
1775 * Copy over NVRAM RISC parameter block to initialization control block.
1776 */
1777 dptr1 = (uint8_t *)icb;
1778 dptr2 = (uint8_t *)&nv->parameter_block_version;
1779 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1780 while (cnt--)
1781 *dptr1++ = *dptr2++;
1782
1783 /* Copy 2nd half. */
1784 dptr1 = (uint8_t *)icb->add_firmware_options;
1785 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1786 while (cnt--)
1787 *dptr1++ = *dptr2++;
1788
Andrew Vasquez5341e862006-05-17 15:09:16 -07001789 /* Use alternate WWN? */
1790 if (nv->host_p[1] & BIT_7) {
1791 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1792 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1793 }
1794
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 /* Prepare nodename */
1796 if ((icb->firmware_options[1] & BIT_6) == 0) {
1797 /*
1798 * Firmware will apply the following mask if the nodename was
1799 * not provided.
1800 */
1801 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1802 icb->node_name[0] &= 0xF0;
1803 }
1804
1805 /*
1806 * Set host adapter parameters.
1807 */
Andrew Vasquez01819442006-06-23 16:11:10 -07001808 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07001809 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1811 /* Always load RISC code on non ISP2[12]00 chips. */
1812 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1813 ha->flags.disable_risc_code_load = 0;
1814 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1815 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1816 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07001817 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001818 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819
1820 ha->operating_mode =
1821 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1822
1823 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1824 sizeof(ha->fw_seriallink_options));
1825
1826 /* save HBA serial number */
1827 ha->serial0 = icb->port_name[5];
1828 ha->serial1 = icb->port_name[6];
1829 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001830 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
1831 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832
1833 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1834
1835 ha->retry_count = nv->retry_count;
1836
1837 /* Set minimum login_timeout to 4 seconds. */
1838 if (nv->login_timeout < ql2xlogintimeout)
1839 nv->login_timeout = ql2xlogintimeout;
1840 if (nv->login_timeout < 4)
1841 nv->login_timeout = 4;
1842 ha->login_timeout = nv->login_timeout;
1843 icb->login_timeout = nv->login_timeout;
1844
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001845 /* Set minimum RATOV to 100 tenths of a second. */
1846 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 ha->loop_reset_delay = nv->reset_delay;
1849
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 /* Link Down Timeout = 0:
1851 *
1852 * When Port Down timer expires we will start returning
1853 * I/O's to OS with "DID_NO_CONNECT".
1854 *
1855 * Link Down Timeout != 0:
1856 *
1857 * The driver waits for the link to come up after link down
1858 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001859 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 if (nv->link_down_timeout == 0) {
1861 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001862 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 } else {
1864 ha->link_down_timeout = nv->link_down_timeout;
1865 ha->loop_down_abort_time =
1866 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001867 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 /*
1870 * Need enough time to try and get the port back.
1871 */
1872 ha->port_down_retry_count = nv->port_down_retry_count;
1873 if (qlport_down_retry)
1874 ha->port_down_retry_count = qlport_down_retry;
1875 /* Set login_retry_count */
1876 ha->login_retry_count = nv->retry_count;
1877 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1878 ha->port_down_retry_count > 3)
1879 ha->login_retry_count = ha->port_down_retry_count;
1880 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1881 ha->login_retry_count = ha->port_down_retry_count;
1882 if (ql2xloginretrycount)
1883 ha->login_retry_count = ql2xloginretrycount;
1884
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 icb->lun_enables = __constant_cpu_to_le16(0);
1886 icb->command_resource_count = 0;
1887 icb->immediate_notify_resource_count = 0;
1888 icb->timeout = __constant_cpu_to_le16(0);
1889
1890 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1891 /* Enable RIO */
1892 icb->firmware_options[0] &= ~BIT_3;
1893 icb->add_firmware_options[0] &=
1894 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1895 icb->add_firmware_options[0] |= BIT_2;
1896 icb->response_accumulation_timer = 3;
1897 icb->interrupt_delay_timer = 5;
1898
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001899 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001901 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001902 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001903 ha->zio_mode = icb->add_firmware_options[0] &
1904 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1905 ha->zio_timer = icb->interrupt_delay_timer ?
1906 icb->interrupt_delay_timer: 2;
1907 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 icb->add_firmware_options[0] &=
1909 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001910 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001911 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001912 ha->zio_mode = QLA_ZIO_MODE_6;
1913
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001914 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001915 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001916 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001918 "ZIO mode %d enabled; timer delay (%d us).\n",
1919 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001921 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1922 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001923 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 }
1925 }
1926
David Miller4e08df32007-04-16 12:37:43 -07001927 if (rval) {
1928 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001929 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07001930 }
1931 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932}
1933
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001934static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001935qla2x00_rport_del(void *data)
1936{
1937 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001938 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001939
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001940 spin_lock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001941 rport = fcport->drport;
1942 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001943 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001944 if (rport)
1945 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001946}
1947
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948/**
1949 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1950 * @ha: HA context
1951 * @flags: allocation flags
1952 *
1953 * Returns a pointer to the allocated fcport, or NULL, if none available.
1954 */
Adrian Bunk413975a2006-06-30 02:33:06 -07001955static fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001956qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957{
1958 fc_port_t *fcport;
1959
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001960 fcport = kzalloc(sizeof(fc_port_t), flags);
1961 if (!fcport)
1962 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963
1964 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001965 fcport->vha = vha;
1966 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 fcport->port_type = FCT_UNKNOWN;
1968 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1970 fcport->flags = FCF_RLC_SUPPORT;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001971 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001973 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974}
1975
1976/*
1977 * qla2x00_configure_loop
1978 * Updates Fibre Channel Device Database with what is actually on loop.
1979 *
1980 * Input:
1981 * ha = adapter block pointer.
1982 *
1983 * Returns:
1984 * 0 = success.
1985 * 1 = error.
1986 * 2 = database was full and device was not configured.
1987 */
1988static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001989qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990{
1991 int rval;
1992 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001993 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 rval = QLA_SUCCESS;
1995
1996 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001997 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
1998 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 if (rval != QLA_SUCCESS) {
2000 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002001 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 return (rval);
2003 }
2004 }
2005
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002006 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002008 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009
2010 /*
2011 * If we have both an RSCN and PORT UPDATE pending then handle them
2012 * both at the same time.
2013 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002014 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2015 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016
2017 /* Determine what we need to do */
2018 if (ha->current_topology == ISP_CFG_FL &&
2019 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2020
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002021 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 set_bit(RSCN_UPDATE, &flags);
2023
2024 } else if (ha->current_topology == ISP_CFG_F &&
2025 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2026
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002027 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 set_bit(RSCN_UPDATE, &flags);
2029 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2030
Andrew Vasquez21333b42006-05-17 15:09:56 -07002031 } else if (ha->current_topology == ISP_CFG_N) {
2032 clear_bit(RSCN_UPDATE, &flags);
2033
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002034 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2036
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002037 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 set_bit(RSCN_UPDATE, &flags);
2039 set_bit(LOCAL_LOOP_UPDATE, &flags);
2040 }
2041
2042 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002043 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002045 else
2046 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 }
2048
2049 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002050 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002052 else
2053 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 }
2055
2056 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002057 if (atomic_read(&vha->loop_down_timer) ||
2058 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 rval = QLA_FUNCTION_FAILED;
2060 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002061 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002063 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 }
2065 }
2066
2067 if (rval) {
2068 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002069 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 } else {
2071 DEBUG3(printk("%s: exiting normally\n", __func__));
2072 }
2073
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002074 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002075 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002077 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002078 if (test_bit(RSCN_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002079 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 }
2081
2082 return (rval);
2083}
2084
2085
2086
2087/*
2088 * qla2x00_configure_local_loop
2089 * Updates Fibre Channel Device Database with local loop devices.
2090 *
2091 * Input:
2092 * ha = adapter block pointer.
2093 *
2094 * Returns:
2095 * 0 = success.
2096 */
2097static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002098qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099{
2100 int rval, rval2;
2101 int found_devs;
2102 int found;
2103 fc_port_t *fcport, *new_fcport;
2104
2105 uint16_t index;
2106 uint16_t entries;
2107 char *id_iter;
2108 uint16_t loop_id;
2109 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002110 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111
2112 found_devs = 0;
2113 new_fcport = NULL;
2114 entries = MAX_FIBRE_DEVICES;
2115
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002116 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2117 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118
2119 /* Get list of logged in devices. */
2120 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002121 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 &entries);
2123 if (rval != QLA_SUCCESS)
2124 goto cleanup_allocation;
2125
2126 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2127 ha->host_no, entries));
2128 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2129 entries * sizeof(struct gid_list_info)));
2130
2131 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002132 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 if (new_fcport == NULL) {
2134 rval = QLA_MEMORY_ALLOC_FAILED;
2135 goto cleanup_allocation;
2136 }
2137 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2138
2139 /*
2140 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2141 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002142 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2144 fcport->port_type != FCT_BROADCAST &&
2145 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2146
2147 DEBUG(printk("scsi(%ld): Marking port lost, "
2148 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002149 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150
2151 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2152 fcport->flags &= ~FCF_FARP_DONE;
2153 }
2154 }
2155
2156 /* Add devices to port list. */
2157 id_iter = (char *)ha->gid_list;
2158 for (index = 0; index < entries; index++) {
2159 domain = ((struct gid_list_info *)id_iter)->domain;
2160 area = ((struct gid_list_info *)id_iter)->area;
2161 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002162 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 loop_id = (uint16_t)
2164 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002165 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 loop_id = le16_to_cpu(
2167 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002168 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169
2170 /* Bypass reserved domain fields. */
2171 if ((domain & 0xf0) == 0xf0)
2172 continue;
2173
2174 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002175 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002176 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 continue;
2178
2179 /* Bypass invalid local loop ID. */
2180 if (loop_id > LAST_LOCAL_LOOP_ID)
2181 continue;
2182
2183 /* Fill in member data. */
2184 new_fcport->d_id.b.domain = domain;
2185 new_fcport->d_id.b.area = area;
2186 new_fcport->d_id.b.al_pa = al_pa;
2187 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002188 new_fcport->vp_idx = vha->vp_idx;
2189 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 if (rval2 != QLA_SUCCESS) {
2191 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2192 "information -- get_port_database=%x, "
2193 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002194 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002195 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002196 vha->host_no));
2197 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 continue;
2199 }
2200
2201 /* Check for matching device in port list. */
2202 found = 0;
2203 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002204 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 if (memcmp(new_fcport->port_name, fcport->port_name,
2206 WWN_SIZE))
2207 continue;
2208
2209 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2210 FCF_PERSISTENT_BOUND);
2211 fcport->loop_id = new_fcport->loop_id;
2212 fcport->port_type = new_fcport->port_type;
2213 fcport->d_id.b24 = new_fcport->d_id.b24;
2214 memcpy(fcport->node_name, new_fcport->node_name,
2215 WWN_SIZE);
2216
2217 found++;
2218 break;
2219 }
2220
2221 if (!found) {
2222 /* New device, add to fcports list. */
2223 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002224 if (vha->vp_idx) {
2225 new_fcport->vha = vha;
2226 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002227 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002228 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229
2230 /* Allocate a new replacement fcport. */
2231 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002232 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 if (new_fcport == NULL) {
2234 rval = QLA_MEMORY_ALLOC_FAILED;
2235 goto cleanup_allocation;
2236 }
2237 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2238 }
2239
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002240 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002241 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002242
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002243 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244
2245 found_devs++;
2246 }
2247
2248cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002249 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250
2251 if (rval != QLA_SUCCESS) {
2252 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002253 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 }
2255
2256 if (found_devs) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002257 vha->device_flags |= DFLG_LOCAL_DEVICES;
2258 vha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 }
2260
2261 return (rval);
2262}
2263
2264static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002265qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002266{
2267#define LS_UNKNOWN 2
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002268 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002269 int rval;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002270 uint16_t mb[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002271 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002272
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002273 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002274 return;
2275
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002276 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2277 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002278 return;
2279
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002280 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002281 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002282 if (rval != QLA_SUCCESS) {
2283 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2284 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002285 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002286 fcport->port_name[2], fcport->port_name[3],
2287 fcport->port_name[4], fcport->port_name[5],
2288 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002289 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002290 } else {
2291 DEBUG2(qla_printk(KERN_INFO, ha,
2292 "iIDMA adjusted to %s GB/s on "
2293 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002294 link_speeds[fcport->fp_speed], fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002295 fcport->port_name[1], fcport->port_name[2],
2296 fcport->port_name[3], fcport->port_name[4],
2297 fcport->port_name[5], fcport->port_name[6],
2298 fcport->port_name[7]));
2299 }
2300}
2301
Adrian Bunk23be3312006-11-24 02:46:01 +01002302static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002303qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002304{
2305 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002306 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002307 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05002308
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002309 if (fcport->drport)
2310 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002311
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002312 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2313 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002314 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2315 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2316 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002317 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002318 if (!rport) {
2319 qla_printk(KERN_WARNING, ha,
2320 "Unable to allocate fc remote port!\n");
2321 return;
2322 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002323 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002324 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002325 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002326
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002327 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002328
2329 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002330 if (fcport->port_type == FCT_INITIATOR)
2331 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2332 if (fcport->port_type == FCT_TARGET)
2333 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002334 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002335}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336
2337/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002338 * qla2x00_update_fcport
2339 * Updates device on list.
2340 *
2341 * Input:
2342 * ha = adapter block pointer.
2343 * fcport = port structure pointer.
2344 *
2345 * Return:
2346 * 0 - Success
2347 * BIT_0 - error
2348 *
2349 * Context:
2350 * Kernel context.
2351 */
2352void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002353qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002354{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002355 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002356
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002357 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002358 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002359 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002360 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002361 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002362 PORT_RETRY_TIME);
2363 fcport->flags &= ~FCF_LOGIN_NEEDED;
2364
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002365 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002366
2367 atomic_set(&fcport->state, FCS_ONLINE);
2368
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002369 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002370}
2371
2372/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 * qla2x00_configure_fabric
2374 * Setup SNS devices with loop ID's.
2375 *
2376 * Input:
2377 * ha = adapter block pointer.
2378 *
2379 * Returns:
2380 * 0 = success.
2381 * BIT_0 = error
2382 */
2383static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002384qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385{
2386 int rval, rval2;
2387 fc_port_t *fcport, *fcptemp;
2388 uint16_t next_loopid;
2389 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002390 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002392 struct qla_hw_data *ha = vha->hw;
2393 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394
2395 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002396 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002397 loop_id = NPH_F_PORT;
2398 else
2399 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002400 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 if (rval != QLA_SUCCESS) {
2402 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002403 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002405 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 return (QLA_SUCCESS);
2407 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002408 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409
2410 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002411 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 if (rval2 == QLA_RSCNS_HANDLED) {
2413 /* No point doing the scan, just continue. */
2414 return (QLA_SUCCESS);
2415 }
2416 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002417 /* FDMI support. */
2418 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002419 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2420 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002421
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002423 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002424 loop_id = NPH_SNS;
2425 else
2426 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002427 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002428 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 if (mb[0] != MBS_COMMAND_COMPLETE) {
2430 DEBUG2(qla_printk(KERN_INFO, ha,
2431 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002432 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 mb[0], mb[1], mb[2], mb[6], mb[7]));
2434 return (QLA_SUCCESS);
2435 }
2436
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002437 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2438 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 /* EMPTY */
2440 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002441 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002443 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 /* EMPTY */
2445 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002446 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002448 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 /* EMPTY */
2450 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002451 "failed.\n", vha->host_no));
2452 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 /* EMPTY */
2454 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002455 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 }
2457 }
2458
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002459 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 if (rval != QLA_SUCCESS)
2461 break;
2462
2463 /*
2464 * Logout all previous fabric devices marked lost, except
2465 * tape devices.
2466 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002467 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2468 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 break;
2470
2471 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2472 continue;
2473
2474 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002475 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002476 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 if (fcport->loop_id != FC_NO_LOOP_ID &&
2478 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2479 fcport->port_type != FCT_INITIATOR &&
2480 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002481 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002482 fcport->loop_id,
2483 fcport->d_id.b.domain,
2484 fcport->d_id.b.area,
2485 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 fcport->loop_id = FC_NO_LOOP_ID;
2487 }
2488 }
2489 }
2490
2491 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002492 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493
2494 /*
2495 * Scan through our port list and login entries that need to be
2496 * logged in.
2497 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002498 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2499 if (atomic_read(&vha->loop_down_timer) ||
2500 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 break;
2502
2503 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2504 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2505 continue;
2506
2507 if (fcport->loop_id == FC_NO_LOOP_ID) {
2508 fcport->loop_id = next_loopid;
Seokmann Jud4486fd62008-04-03 13:13:28 -07002509 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002510 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 if (rval != QLA_SUCCESS) {
2512 /* Ran out of IDs to use */
2513 break;
2514 }
2515 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002517 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 }
2519
2520 /* Exit if out of loop IDs. */
2521 if (rval != QLA_SUCCESS) {
2522 break;
2523 }
2524
2525 /*
2526 * Login and add the new devices to our port list.
2527 */
2528 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002529 if (atomic_read(&vha->loop_down_timer) ||
2530 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 break;
2532
2533 /* Find a new loop ID to use. */
2534 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002535 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 if (rval != QLA_SUCCESS) {
2537 /* Ran out of IDs to use */
2538 break;
2539 }
2540
bdf79622005-04-17 15:06:53 -05002541 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002542 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002543
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002544 if (vha->vp_idx) {
2545 fcport->vha = vha;
2546 fcport->vp_idx = vha->vp_idx;
2547 }
2548 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 }
2550 } while (0);
2551
2552 /* Free all new device structures not processed. */
2553 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2554 list_del(&fcport->list);
2555 kfree(fcport);
2556 }
2557
2558 if (rval) {
2559 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002560 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 }
2562
2563 return (rval);
2564}
2565
2566
2567/*
2568 * qla2x00_find_all_fabric_devs
2569 *
2570 * Input:
2571 * ha = adapter block pointer.
2572 * dev = database device entry pointer.
2573 *
2574 * Returns:
2575 * 0 = success.
2576 *
2577 * Context:
2578 * Kernel context.
2579 */
2580static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002581qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2582 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583{
2584 int rval;
2585 uint16_t loop_id;
2586 fc_port_t *fcport, *new_fcport, *fcptemp;
2587 int found;
2588
2589 sw_info_t *swl;
2590 int swl_idx;
2591 int first_dev, last_dev;
2592 port_id_t wrap, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002593 struct qla_hw_data *ha = vha->hw;
2594 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595
2596 rval = QLA_SUCCESS;
2597
2598 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07002599 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002600 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 /*EMPTY*/
2602 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002603 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002605 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 kfree(swl);
2607 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002608 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 kfree(swl);
2610 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002611 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 kfree(swl);
2613 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07002614 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002615 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2616 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 }
2618 }
2619 swl_idx = 0;
2620
2621 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002622 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002624 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 return (QLA_MEMORY_ALLOC_FAILED);
2626 }
2627 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 /* Set start port ID scan at adapter ID. */
2629 first_dev = 1;
2630 last_dev = 0;
2631
2632 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002633 loop_id = ha->min_external_loopid;
2634 for (; loop_id <= ha->max_loop_id; loop_id++) {
2635 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 continue;
2637
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002638 if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 break;
2640
2641 if (swl != NULL) {
2642 if (last_dev) {
2643 wrap.b24 = new_fcport->d_id.b24;
2644 } else {
2645 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2646 memcpy(new_fcport->node_name,
2647 swl[swl_idx].node_name, WWN_SIZE);
2648 memcpy(new_fcport->port_name,
2649 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002650 memcpy(new_fcport->fabric_port_name,
2651 swl[swl_idx].fabric_port_name, WWN_SIZE);
2652 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653
2654 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2655 last_dev = 1;
2656 }
2657 swl_idx++;
2658 }
2659 } else {
2660 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002661 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 if (rval != QLA_SUCCESS) {
2663 qla_printk(KERN_WARNING, ha,
2664 "SNS scan failed -- assuming zero-entry "
2665 "result...\n");
2666 list_for_each_entry_safe(fcport, fcptemp,
2667 new_fcports, list) {
2668 list_del(&fcport->list);
2669 kfree(fcport);
2670 }
2671 rval = QLA_SUCCESS;
2672 break;
2673 }
2674 }
2675
2676 /* If wrap on switch device list, exit. */
2677 if (first_dev) {
2678 wrap.b24 = new_fcport->d_id.b24;
2679 first_dev = 0;
2680 } else if (new_fcport->d_id.b24 == wrap.b24) {
2681 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002682 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2684 break;
2685 }
2686
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002687 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002688 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 continue;
2690
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002691 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002692 found = 0;
2693 if (ha->num_vhosts) {
2694 list_for_each_entry(vp, &ha->vp_list, list) {
2695 if (new_fcport->d_id.b24 == vp->d_id.b24) {
2696 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002697 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002698 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002699 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002700 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002701 continue;
2702 }
2703
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002704 /* Bypass if same domain and area of adapter. */
2705 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002706 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002707 ISP_CFG_FL)
2708 continue;
2709
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 /* Bypass reserved domain fields. */
2711 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2712 continue;
2713
2714 /* Locate matching device in database. */
2715 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002716 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 if (memcmp(new_fcport->port_name, fcport->port_name,
2718 WWN_SIZE))
2719 continue;
2720
2721 found++;
2722
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002723 /* Update port state. */
2724 memcpy(fcport->fabric_port_name,
2725 new_fcport->fabric_port_name, WWN_SIZE);
2726 fcport->fp_speed = new_fcport->fp_speed;
2727
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 /*
2729 * If address the same and state FCS_ONLINE, nothing
2730 * changed.
2731 */
2732 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2733 atomic_read(&fcport->state) == FCS_ONLINE) {
2734 break;
2735 }
2736
2737 /*
2738 * If device was not a fabric device before.
2739 */
2740 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2741 fcport->d_id.b24 = new_fcport->d_id.b24;
2742 fcport->loop_id = FC_NO_LOOP_ID;
2743 fcport->flags |= (FCF_FABRIC_DEVICE |
2744 FCF_LOGIN_NEEDED);
2745 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2746 break;
2747 }
2748
2749 /*
2750 * Port ID changed or device was marked to be updated;
2751 * Log it out if still logged in and mark it for
2752 * relogin later.
2753 */
2754 fcport->d_id.b24 = new_fcport->d_id.b24;
2755 fcport->flags |= FCF_LOGIN_NEEDED;
2756 if (fcport->loop_id != FC_NO_LOOP_ID &&
2757 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2758 fcport->port_type != FCT_INITIATOR &&
2759 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002760 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002761 fcport->d_id.b.domain, fcport->d_id.b.area,
2762 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 fcport->loop_id = FC_NO_LOOP_ID;
2764 }
2765
2766 break;
2767 }
2768
2769 if (found)
2770 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 /* If device was not in our fcports list, then add it. */
2772 list_add_tail(&new_fcport->list, new_fcports);
2773
2774 /* Allocate a new replacement fcport. */
2775 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002776 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002778 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 return (QLA_MEMORY_ALLOC_FAILED);
2780 }
2781 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2782 new_fcport->d_id.b24 = nxt_d_id.b24;
2783 }
2784
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002785 kfree(swl);
2786 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787
2788 if (!list_empty(new_fcports))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002789 vha->device_flags |= DFLG_FABRIC_DEVICES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790
2791 return (rval);
2792}
2793
2794/*
2795 * qla2x00_find_new_loop_id
2796 * Scan through our port list and find a new usable loop ID.
2797 *
2798 * Input:
2799 * ha: adapter state pointer.
2800 * dev: port structure pointer.
2801 *
2802 * Returns:
2803 * qla2x00 local function return status code.
2804 *
2805 * Context:
2806 * Kernel context.
2807 */
Adrian Bunk413975a2006-06-30 02:33:06 -07002808static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002809qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810{
2811 int rval;
2812 int found;
2813 fc_port_t *fcport;
2814 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002815 struct qla_hw_data *ha = vha->hw;
2816 struct scsi_qla_host *vp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817
2818 rval = QLA_SUCCESS;
2819
2820 /* Save starting loop ID. */
2821 first_loop_id = dev->loop_id;
2822
2823 for (;;) {
2824 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002825 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827
2828 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002829 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831
2832 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002833 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 /* first loop ID. */
2835 dev->loop_id = ha->min_external_loopid;
2836 }
2837
2838 /* Check for loop ID being already in use. */
2839 found = 0;
2840 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002841 list_for_each_entry(vp, &ha->vp_list, list) {
2842 list_for_each_entry(fcport, &vp->vp_fcports, list) {
2843 if (fcport->loop_id == dev->loop_id &&
2844 fcport != dev) {
2845 /* ID possibly in use */
2846 found++;
2847 break;
2848 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002850 if (found)
2851 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 }
2853
2854 /* If not in use then it is free to use. */
2855 if (!found) {
2856 break;
2857 }
2858
2859 /* ID in use. Try next value. */
2860 dev->loop_id++;
2861
2862 /* If wrap around. No free ID to use. */
2863 if (dev->loop_id == first_loop_id) {
2864 dev->loop_id = FC_NO_LOOP_ID;
2865 rval = QLA_FUNCTION_FAILED;
2866 break;
2867 }
2868 }
2869
2870 return (rval);
2871}
2872
2873/*
2874 * qla2x00_device_resync
2875 * Marks devices in the database that needs resynchronization.
2876 *
2877 * Input:
2878 * ha = adapter block pointer.
2879 *
2880 * Context:
2881 * Kernel context.
2882 */
2883static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002884qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885{
2886 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 uint32_t mask;
2888 fc_port_t *fcport;
2889 uint32_t rscn_entry;
2890 uint8_t rscn_out_iter;
2891 uint8_t format;
2892 port_id_t d_id;
2893
2894 rval = QLA_RSCNS_HANDLED;
2895
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002896 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
2897 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002899 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900 format = MSB(MSW(rscn_entry));
2901 d_id.b.domain = LSB(MSW(rscn_entry));
2902 d_id.b.area = MSB(LSW(rscn_entry));
2903 d_id.b.al_pa = LSB(LSW(rscn_entry));
2904
2905 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2906 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002907 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908 d_id.b.area, d_id.b.al_pa));
2909
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002910 vha->rscn_out_ptr++;
2911 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
2912 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913
2914 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002915 for (rscn_out_iter = vha->rscn_out_ptr;
2916 !vha->flags.rscn_queue_overflow &&
2917 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 rscn_out_iter = (rscn_out_iter ==
2919 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2920
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002921 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 break;
2923
2924 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002925 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 rscn_out_iter));
2927
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002928 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 }
2930
2931 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002932 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002934 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935
2936 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002937 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 }
2939
2940 switch (format) {
2941 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 mask = 0xffffff;
2943 break;
2944 case 1:
2945 mask = 0xffff00;
2946 break;
2947 case 2:
2948 mask = 0xff0000;
2949 break;
2950 default:
2951 mask = 0x0;
2952 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002953 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 break;
2955 }
2956
2957 rval = QLA_SUCCESS;
2958
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002959 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2961 (fcport->d_id.b24 & mask) != d_id.b24 ||
2962 fcport->port_type == FCT_BROADCAST)
2963 continue;
2964
2965 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2966 if (format != 3 ||
2967 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002968 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002969 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 }
2971 }
2972 fcport->flags &= ~FCF_FARP_DONE;
2973 }
2974 }
2975 return (rval);
2976}
2977
2978/*
2979 * qla2x00_fabric_dev_login
2980 * Login fabric target device and update FC port database.
2981 *
2982 * Input:
2983 * ha: adapter state pointer.
2984 * fcport: port structure list pointer.
2985 * next_loopid: contains value of a new loop ID that can be used
2986 * by the next login attempt.
2987 *
2988 * Returns:
2989 * qla2x00 local function return status code.
2990 *
2991 * Context:
2992 * Kernel context.
2993 */
2994static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002995qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 uint16_t *next_loopid)
2997{
2998 int rval;
2999 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003000 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003001 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002
3003 rval = QLA_SUCCESS;
3004 retry = 0;
3005
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003006 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 if (rval == QLA_SUCCESS) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003008 /* Send an ADISC to tape devices.*/
3009 opts = 0;
3010 if (fcport->flags & FCF_TAPE_PRESENT)
3011 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003012 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003014 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003015 fcport->d_id.b.domain, fcport->d_id.b.area,
3016 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003017 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003019 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 }
3021 }
3022
3023 return (rval);
3024}
3025
3026/*
3027 * qla2x00_fabric_login
3028 * Issue fabric login command.
3029 *
3030 * Input:
3031 * ha = adapter block pointer.
3032 * device = pointer to FC device type structure.
3033 *
3034 * Returns:
3035 * 0 - Login successfully
3036 * 1 - Login failed
3037 * 2 - Initiator device
3038 * 3 - Fatal error
3039 */
3040int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003041qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 uint16_t *next_loopid)
3043{
3044 int rval;
3045 int retry;
3046 uint16_t tmp_loopid;
3047 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003048 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049
3050 retry = 0;
3051 tmp_loopid = 0;
3052
3053 for (;;) {
3054 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3055 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003056 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3058
3059 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003060 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 fcport->d_id.b.domain, fcport->d_id.b.area,
3062 fcport->d_id.b.al_pa, mb, BIT_0);
3063 if (mb[0] == MBS_PORT_ID_USED) {
3064 /*
3065 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003066 * recommends the driver perform an implicit login with
3067 * the specified ID again. The ID we just used is save
3068 * here so we return with an ID that can be tried by
3069 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 */
3071 retry++;
3072 tmp_loopid = fcport->loop_id;
3073 fcport->loop_id = mb[1];
3074
3075 DEBUG(printk("Fabric Login: port in use - next "
3076 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3077 fcport->loop_id, fcport->d_id.b.domain,
3078 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3079
3080 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3081 /*
3082 * Login succeeded.
3083 */
3084 if (retry) {
3085 /* A retry occurred before. */
3086 *next_loopid = tmp_loopid;
3087 } else {
3088 /*
3089 * No retry occurred before. Just increment the
3090 * ID value for next login.
3091 */
3092 *next_loopid = (fcport->loop_id + 1);
3093 }
3094
3095 if (mb[1] & BIT_0) {
3096 fcport->port_type = FCT_INITIATOR;
3097 } else {
3098 fcport->port_type = FCT_TARGET;
3099 if (mb[1] & BIT_1) {
3100 fcport->flags |= FCF_TAPE_PRESENT;
3101 }
3102 }
3103
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003104 if (mb[10] & BIT_0)
3105 fcport->supported_classes |= FC_COS_CLASS2;
3106 if (mb[10] & BIT_1)
3107 fcport->supported_classes |= FC_COS_CLASS3;
3108
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 rval = QLA_SUCCESS;
3110 break;
3111 } else if (mb[0] == MBS_LOOP_ID_USED) {
3112 /*
3113 * Loop ID already used, try next loop ID.
3114 */
3115 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003116 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117 if (rval != QLA_SUCCESS) {
3118 /* Ran out of loop IDs to use */
3119 break;
3120 }
3121 } else if (mb[0] == MBS_COMMAND_ERROR) {
3122 /*
3123 * Firmware possibly timed out during login. If NO
3124 * retries are left to do then the device is declared
3125 * dead.
3126 */
3127 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003128 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003129 fcport->d_id.b.domain, fcport->d_id.b.area,
3130 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003131 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132
3133 rval = 1;
3134 break;
3135 } else {
3136 /*
3137 * unrecoverable / not handled error
3138 */
3139 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003140 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003141 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 fcport->d_id.b.domain, fcport->d_id.b.area,
3143 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3144
3145 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003146 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003147 fcport->d_id.b.domain, fcport->d_id.b.area,
3148 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003150 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151
3152 rval = 3;
3153 break;
3154 }
3155 }
3156
3157 return (rval);
3158}
3159
3160/*
3161 * qla2x00_local_device_login
3162 * Issue local device login command.
3163 *
3164 * Input:
3165 * ha = adapter block pointer.
3166 * loop_id = loop id of device to login to.
3167 *
3168 * Returns (Where's the #define!!!!):
3169 * 0 - Login successfully
3170 * 1 - Login failed
3171 * 3 - Fatal error
3172 */
3173int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003174qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175{
3176 int rval;
3177 uint16_t mb[MAILBOX_REGISTER_COUNT];
3178
3179 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003180 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 if (rval == QLA_SUCCESS) {
3182 /* Interrogate mailbox registers for any errors */
3183 if (mb[0] == MBS_COMMAND_ERROR)
3184 rval = 1;
3185 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3186 /* device not in PCB table */
3187 rval = 3;
3188 }
3189
3190 return (rval);
3191}
3192
3193/*
3194 * qla2x00_loop_resync
3195 * Resync with fibre channel devices.
3196 *
3197 * Input:
3198 * ha = adapter block pointer.
3199 *
3200 * Returns:
3201 * 0 = success
3202 */
3203int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003204qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003206 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 uint32_t wait_time;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003208 struct qla_hw_data *ha = vha->hw;
3209 struct req_que *req = ha->req_q_map[0];
3210 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003212 atomic_set(&vha->loop_state, LOOP_UPDATE);
3213 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3214 if (vha->flags.online) {
3215 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3217 wait_time = 256;
3218 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003219 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003221 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003222 qla2x00_marker(vha, req, rsp, 0, 0,
3223 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003224 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225
3226 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003227 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003229 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003231 } while (!atomic_read(&vha->loop_down_timer) &&
3232 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3233 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3234 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236 }
3237
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003238 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003241 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243
3244 return (rval);
3245}
3246
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003248qla2x00_update_fcports(scsi_qla_host_t *vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003249{
3250 fc_port_t *fcport;
3251
3252 /* Go with deferred removal of rport references. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003253 list_for_each_entry(fcport, &vha->vp_fcports, list)
3254 if (fcport && fcport->drport &&
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07003255 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003256 qla2x00_rport_del(fcport);
3257}
3258
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259/*
3260* qla2x00_abort_isp
3261* Resets ISP and aborts all outstanding commands.
3262*
3263* Input:
3264* ha = adapter block pointer.
3265*
3266* Returns:
3267* 0 = success
3268*/
3269int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003270qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003272 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003274 struct qla_hw_data *ha = vha->hw;
3275 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003276 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003278 if (vha->flags.online) {
3279 vha->flags.online = 0;
3280 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07003281 ha->qla_stats.total_isp_aborts++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282
3283 qla_printk(KERN_INFO, ha,
3284 "Performing ISP error recovery - ha= %p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003285 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003287 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3288 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3289 atomic_set(&vha->loop_state, LOOP_DOWN);
3290 qla2x00_mark_all_devices_lost(vha, 0);
3291 list_for_each_entry(vp, &ha->vp_list, list)
3292 qla2x00_mark_all_devices_lost(vp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003294 if (!atomic_read(&vha->loop_down_timer))
3295 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 LOOP_DOWN_TIME);
3297 }
3298
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299 /* Requeue all commands in outstanding command list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003300 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003302 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003303
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003304 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003306 if (!qla2x00_restart_isp(vha)) {
3307 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003309 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310 /*
3311 * Issue marker command only when we are going
3312 * to start the I/O .
3313 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003314 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 }
3316
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003317 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003319 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003321 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003322 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003323
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003324 if (ha->fce) {
3325 ha->flags.fce_enabled = 1;
3326 memset(ha->fce, 0,
3327 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003328 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003329 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3330 &ha->fce_bufs);
3331 if (rval) {
3332 qla_printk(KERN_WARNING, ha,
3333 "Unable to reinitialize FCE "
3334 "(%d).\n", rval);
3335 ha->flags.fce_enabled = 0;
3336 }
3337 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003338
3339 if (ha->eft) {
3340 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003341 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003342 ha->eft_dma, EFT_NUM_BUFFERS);
3343 if (rval) {
3344 qla_printk(KERN_WARNING, ha,
3345 "Unable to reinitialize EFT "
3346 "(%d).\n", rval);
3347 }
3348 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003350 vha->flags.online = 1;
3351 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352 if (ha->isp_abort_cnt == 0) {
3353 qla_printk(KERN_WARNING, ha,
3354 "ISP error recovery failed - "
3355 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003356 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357 * The next call disables the board
3358 * completely.
3359 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003360 ha->isp_ops->reset_adapter(vha);
3361 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003363 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 status = 0;
3365 } else { /* schedule another ISP abort */
3366 ha->isp_abort_cnt--;
3367 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003368 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003369 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370 status = 1;
3371 }
3372 } else {
3373 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3374 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3375 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003376 vha->host_no, ha->isp_abort_cnt));
3377 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378 status = 1;
3379 }
3380 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003381
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382 }
3383
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003384 if (!status) {
3385 DEBUG(printk(KERN_INFO
3386 "qla2x00_abort_isp(%ld): succeeded.\n",
3387 vha->host_no));
3388 list_for_each_entry(vp, &ha->vp_list, list) {
3389 if (vp->vp_idx)
3390 qla2x00_vp_abort_isp(vp);
3391 }
3392 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393 qla_printk(KERN_INFO, ha,
3394 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395 }
3396
3397 return(status);
3398}
3399
3400/*
3401* qla2x00_restart_isp
3402* restarts the ISP after a reset
3403*
3404* Input:
3405* ha = adapter block pointer.
3406*
3407* Returns:
3408* 0 = success
3409*/
3410static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003411qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412{
3413 uint8_t status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003415 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003416 struct req_que *req = ha->req_q_map[0];
3417 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418
3419 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003420 if (qla2x00_isp_firmware(vha)) {
3421 vha->flags.online = 0;
3422 status = ha->isp_ops->chip_diag(vha);
3423 if (!status)
3424 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003425 }
3426
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003427 if (!status && !(status = qla2x00_init_rings(vha))) {
3428 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003429 /* Initialize the queues in use */
3430 qla25xx_init_queues(ha);
3431
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003432 status = qla2x00_fw_ready(vha);
3433 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003435 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003436
3437 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003438 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003439
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003440 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3442 wait_time = 256;
3443 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003444 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3445 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003447 } while (!atomic_read(&vha->loop_down_timer) &&
3448 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3449 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3450 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451 }
3452
3453 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003454 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 status = 0;
3456
3457 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3458 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003459 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460 }
3461 return (status);
3462}
3463
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003464static int
3465qla25xx_init_queues(struct qla_hw_data *ha)
3466{
3467 struct rsp_que *rsp = NULL;
3468 struct req_que *req = NULL;
3469 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3470 int ret = -1;
3471 int i;
3472
3473 for (i = 1; i < ha->max_queues; i++) {
3474 rsp = ha->rsp_q_map[i];
3475 if (rsp) {
3476 rsp->options &= ~BIT_0;
3477 ret = qla25xx_init_rsp_que(base_vha, rsp, rsp->options);
3478 if (ret != QLA_SUCCESS)
3479 DEBUG2_17(printk(KERN_WARNING
3480 "%s Rsp que:%d init failed\n", __func__,
3481 rsp->id));
3482 else
3483 DEBUG2_17(printk(KERN_INFO
3484 "%s Rsp que:%d inited\n", __func__,
3485 rsp->id));
3486 }
3487 req = ha->req_q_map[i];
3488 if (req) {
3489 req->options &= ~BIT_0;
3490 ret = qla25xx_init_req_que(base_vha, req, req->options);
3491 if (ret != QLA_SUCCESS)
3492 DEBUG2_17(printk(KERN_WARNING
3493 "%s Req que:%d init failed\n", __func__,
3494 req->id));
3495 else
3496 DEBUG2_17(printk(KERN_WARNING
3497 "%s Rsp que:%d inited\n", __func__,
3498 req->id));
3499 }
3500 }
3501 return ret;
3502}
3503
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504/*
3505* qla2x00_reset_adapter
3506* Reset adapter.
3507*
3508* Input:
3509* ha = adapter block pointer.
3510*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003511void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003512qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513{
3514 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003515 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003516 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003518 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003519 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521 spin_lock_irqsave(&ha->hardware_lock, flags);
3522 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3523 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3524 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3525 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3526 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3527}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003528
3529void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003530qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003531{
3532 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003533 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003534 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3535
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003536 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003537 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003538
3539 spin_lock_irqsave(&ha->hardware_lock, flags);
3540 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3541 RD_REG_DWORD(&reg->hccr);
3542 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3543 RD_REG_DWORD(&reg->hccr);
3544 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3545}
3546
David Miller4e08df32007-04-16 12:37:43 -07003547/* On sparc systems, obtain port and node WWN from firmware
3548 * properties.
3549 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003550static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3551 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07003552{
3553#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003554 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003555 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003556 struct device_node *dp = pci_device_to_OF_node(pdev);
3557 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003558 int len;
3559
3560 val = of_get_property(dp, "port-wwn", &len);
3561 if (val && len >= WWN_SIZE)
3562 memcpy(nv->port_name, val, WWN_SIZE);
3563
3564 val = of_get_property(dp, "node-wwn", &len);
3565 if (val && len >= WWN_SIZE)
3566 memcpy(nv->node_name, val, WWN_SIZE);
3567#endif
3568}
3569
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003570int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003571qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003572{
David Miller4e08df32007-04-16 12:37:43 -07003573 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003574 struct init_cb_24xx *icb;
3575 struct nvram_24xx *nv;
3576 uint32_t *dptr;
3577 uint8_t *dptr1, *dptr2;
3578 uint32_t chksum;
3579 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003580 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003581
David Miller4e08df32007-04-16 12:37:43 -07003582 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003583 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003584 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003585
3586 /* Determine NVRAM starting address. */
3587 ha->nvram_size = sizeof(struct nvram_24xx);
3588 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003589 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3590 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3591 if (PCI_FUNC(ha->pdev->devfn)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003592 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003593 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3594 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003595
Seokmann Ju281afe12007-07-26 13:43:34 -07003596 /* Get VPD data into cache */
3597 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003598 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07003599 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3600
3601 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003602 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003603 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003604 ha->nvram_size);
3605 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3606 chksum += le32_to_cpu(*dptr++);
3607
3608 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07003609 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003610
3611 /* Bad NVRAM data, set defaults parameters. */
3612 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3613 || nv->id[3] != ' ' ||
3614 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3615 /* Reset NVRAM data. */
3616 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3617 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3618 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07003619 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3620 "invalid -- WWPN) defaults.\n");
3621
3622 /*
3623 * Set default initialization control block.
3624 */
3625 memset(nv, 0, ha->nvram_size);
3626 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3627 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3628 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3629 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3630 nv->exchange_count = __constant_cpu_to_le16(0);
3631 nv->hard_address = __constant_cpu_to_le16(124);
3632 nv->port_name[0] = 0x21;
3633 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3634 nv->port_name[2] = 0x00;
3635 nv->port_name[3] = 0xe0;
3636 nv->port_name[4] = 0x8b;
3637 nv->port_name[5] = 0x1c;
3638 nv->port_name[6] = 0x55;
3639 nv->port_name[7] = 0x86;
3640 nv->node_name[0] = 0x20;
3641 nv->node_name[1] = 0x00;
3642 nv->node_name[2] = 0x00;
3643 nv->node_name[3] = 0xe0;
3644 nv->node_name[4] = 0x8b;
3645 nv->node_name[5] = 0x1c;
3646 nv->node_name[6] = 0x55;
3647 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003648 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07003649 nv->login_retry_count = __constant_cpu_to_le16(8);
3650 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3651 nv->login_timeout = __constant_cpu_to_le16(0);
3652 nv->firmware_options_1 =
3653 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3654 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3655 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3656 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3657 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3658 nv->efi_parameters = __constant_cpu_to_le32(0);
3659 nv->reset_delay = 5;
3660 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3661 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3662 nv->link_down_timeout = __constant_cpu_to_le16(30);
3663
3664 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003665 }
3666
3667 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003668 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003669
3670 /* Copy 1st segment. */
3671 dptr1 = (uint8_t *)icb;
3672 dptr2 = (uint8_t *)&nv->version;
3673 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3674 while (cnt--)
3675 *dptr1++ = *dptr2++;
3676
3677 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07003678 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003679
3680 /* Copy 2nd segment. */
3681 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3682 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3683 cnt = (uint8_t *)&icb->reserved_3 -
3684 (uint8_t *)&icb->interrupt_delay_timer;
3685 while (cnt--)
3686 *dptr1++ = *dptr2++;
3687
3688 /*
3689 * Setup driver NVRAM options.
3690 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003691 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003692 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003693
Andrew Vasquez5341e862006-05-17 15:09:16 -07003694 /* Use alternate WWN? */
3695 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3696 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3697 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3698 }
3699
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003700 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003701 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003702 /*
3703 * Firmware will apply the following mask if the nodename was
3704 * not provided.
3705 */
3706 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3707 icb->node_name[0] &= 0xF0;
3708 }
3709
3710 /* Set host adapter parameters. */
3711 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08003712 ha->flags.enable_lip_reset = 0;
3713 ha->flags.enable_lip_full_login =
3714 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3715 ha->flags.enable_target_reset =
3716 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003717 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07003718 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003719
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003720 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3721 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003722
3723 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3724 sizeof(ha->fw_seriallink_options24));
3725
3726 /* save HBA serial number */
3727 ha->serial0 = icb->port_name[5];
3728 ha->serial1 = icb->port_name[6];
3729 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003730 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
3731 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003732
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08003733 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3734
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003735 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3736
3737 /* Set minimum login_timeout to 4 seconds. */
3738 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3739 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3740 if (le16_to_cpu(nv->login_timeout) < 4)
3741 nv->login_timeout = __constant_cpu_to_le16(4);
3742 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07003743 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003744
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003745 /* Set minimum RATOV to 100 tenths of a second. */
3746 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003747
3748 ha->loop_reset_delay = nv->reset_delay;
3749
3750 /* Link Down Timeout = 0:
3751 *
3752 * When Port Down timer expires we will start returning
3753 * I/O's to OS with "DID_NO_CONNECT".
3754 *
3755 * Link Down Timeout != 0:
3756 *
3757 * The driver waits for the link to come up after link down
3758 * before returning I/Os to OS with "DID_NO_CONNECT".
3759 */
3760 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3761 ha->loop_down_abort_time =
3762 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3763 } else {
3764 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3765 ha->loop_down_abort_time =
3766 (LOOP_DOWN_TIME - ha->link_down_timeout);
3767 }
3768
3769 /* Need enough time to try and get the port back. */
3770 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3771 if (qlport_down_retry)
3772 ha->port_down_retry_count = qlport_down_retry;
3773
3774 /* Set login_retry_count */
3775 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3776 if (ha->port_down_retry_count ==
3777 le16_to_cpu(nv->port_down_retry_count) &&
3778 ha->port_down_retry_count > 3)
3779 ha->login_retry_count = ha->port_down_retry_count;
3780 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3781 ha->login_retry_count = ha->port_down_retry_count;
3782 if (ql2xloginretrycount)
3783 ha->login_retry_count = ql2xloginretrycount;
3784
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003785 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003786 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003787 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3788 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3789 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3790 le16_to_cpu(icb->interrupt_delay_timer): 2;
3791 }
3792 icb->firmware_options_2 &= __constant_cpu_to_le32(
3793 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003794 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003795 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08003796 ha->zio_mode = QLA_ZIO_MODE_6;
3797
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003798 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003799 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003800 ha->zio_timer * 100));
3801 qla_printk(KERN_INFO, ha,
3802 "ZIO mode %d enabled; timer delay (%d us).\n",
3803 ha->zio_mode, ha->zio_timer * 100);
3804
3805 icb->firmware_options_2 |= cpu_to_le32(
3806 (uint32_t)ha->zio_mode);
3807 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003808 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003809 }
3810
David Miller4e08df32007-04-16 12:37:43 -07003811 if (rval) {
3812 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003813 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07003814 }
3815 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003816}
3817
Adrian Bunk413975a2006-06-30 02:33:06 -07003818static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003819qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003820{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003821 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003822 int segments, fragment;
3823 uint32_t faddr;
3824 uint32_t *dcode, dlen;
3825 uint32_t risc_addr;
3826 uint32_t risc_size;
3827 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003828 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003829 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003830 rval = QLA_SUCCESS;
3831
3832 segments = FA_RISC_CODE_SEGMENTS;
Andrew Vasquezc00d8992008-09-11 21:22:49 -07003833 faddr = ha->flt_region_fw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003834 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003835 *srisc_addr = 0;
3836
3837 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003838 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003839 for (i = 0; i < 4; i++)
3840 dcode[i] = be32_to_cpu(dcode[i]);
3841 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3842 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3843 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3844 dcode[3] == 0)) {
3845 qla_printk(KERN_WARNING, ha,
3846 "Unable to verify integrity of flash firmware image!\n");
3847 qla_printk(KERN_WARNING, ha,
3848 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3849 dcode[1], dcode[2], dcode[3]);
3850
3851 return QLA_FUNCTION_FAILED;
3852 }
3853
3854 while (segments && rval == QLA_SUCCESS) {
3855 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003856 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003857
3858 risc_addr = be32_to_cpu(dcode[2]);
3859 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3860 risc_size = be32_to_cpu(dcode[3]);
3861
3862 fragment = 0;
3863 while (risc_size > 0 && rval == QLA_SUCCESS) {
3864 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3865 if (dlen > risc_size)
3866 dlen = risc_size;
3867
3868 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3869 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003870 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003871
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003872 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003873 for (i = 0; i < dlen; i++)
3874 dcode[i] = swab32(dcode[i]);
3875
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003876 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003877 dlen);
3878 if (rval) {
3879 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003880 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003881 fragment));
3882 qla_printk(KERN_WARNING, ha,
3883 "[ERROR] Failed to load segment %d of "
3884 "firmware\n", fragment);
3885 break;
3886 }
3887
3888 faddr += dlen;
3889 risc_addr += dlen;
3890 risc_size -= dlen;
3891 fragment++;
3892 }
3893
3894 /* Next segment. */
3895 segments--;
3896 }
3897
3898 return rval;
3899}
3900
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003901#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3902
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003903int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003904qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08003905{
3906 int rval;
3907 int i, fragment;
3908 uint16_t *wcode, *fwcode;
3909 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3910 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003911 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003912 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08003913
3914 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003915 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08003916 if (!blob) {
3917 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003918 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3919 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08003920 return QLA_FUNCTION_FAILED;
3921 }
3922
3923 rval = QLA_SUCCESS;
3924
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003925 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08003926 *srisc_addr = 0;
3927 fwcode = (uint16_t *)blob->fw->data;
3928 fwclen = 0;
3929
3930 /* Validate firmware image by checking version. */
3931 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3932 qla_printk(KERN_WARNING, ha,
3933 "Unable to verify integrity of firmware image (%Zd)!\n",
3934 blob->fw->size);
3935 goto fail_fw_integrity;
3936 }
3937 for (i = 0; i < 4; i++)
3938 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3939 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3940 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3941 wcode[2] == 0 && wcode[3] == 0)) {
3942 qla_printk(KERN_WARNING, ha,
3943 "Unable to verify integrity of firmware image!\n");
3944 qla_printk(KERN_WARNING, ha,
3945 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3946 wcode[1], wcode[2], wcode[3]);
3947 goto fail_fw_integrity;
3948 }
3949
3950 seg = blob->segs;
3951 while (*seg && rval == QLA_SUCCESS) {
3952 risc_addr = *seg;
3953 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3954 risc_size = be16_to_cpu(fwcode[3]);
3955
3956 /* Validate firmware image size. */
3957 fwclen += risc_size * sizeof(uint16_t);
3958 if (blob->fw->size < fwclen) {
3959 qla_printk(KERN_WARNING, ha,
3960 "Unable to verify integrity of firmware image "
3961 "(%Zd)!\n", blob->fw->size);
3962 goto fail_fw_integrity;
3963 }
3964
3965 fragment = 0;
3966 while (risc_size > 0 && rval == QLA_SUCCESS) {
3967 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3968 if (wlen > risc_size)
3969 wlen = risc_size;
3970
3971 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003972 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08003973 risc_addr, wlen));
3974
3975 for (i = 0; i < wlen; i++)
3976 wcode[i] = swab16(fwcode[i]);
3977
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003978 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08003979 wlen);
3980 if (rval) {
3981 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003982 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08003983 fragment));
3984 qla_printk(KERN_WARNING, ha,
3985 "[ERROR] Failed to load segment %d of "
3986 "firmware\n", fragment);
3987 break;
3988 }
3989
3990 fwcode += wlen;
3991 risc_addr += wlen;
3992 risc_size -= wlen;
3993 fragment++;
3994 }
3995
3996 /* Next segment. */
3997 seg++;
3998 }
3999 return rval;
4000
4001fail_fw_integrity:
4002 return QLA_FUNCTION_FAILED;
4003}
4004
4005int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004006qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004007{
4008 int rval;
4009 int segments, fragment;
4010 uint32_t *dcode, dlen;
4011 uint32_t risc_addr;
4012 uint32_t risc_size;
4013 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004014 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004015 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004016 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004017 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004018
Andrew Vasquez54333832005-11-09 15:49:04 -08004019 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004020 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004021 if (!blob) {
4022 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004023 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4024 "from: " QLA_FW_URL ".\n");
4025
4026 /* Try to load RISC code from flash. */
4027 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
4028 "outdated) firmware from flash.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004029 return qla24xx_load_risc_flash(vha, srisc_addr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004030 }
4031
4032 rval = QLA_SUCCESS;
4033
4034 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004035 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004036 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004037 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004038 fwclen = 0;
4039
4040 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004041 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004042 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004043 "Unable to verify integrity of firmware image (%Zd)!\n",
4044 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004045 goto fail_fw_integrity;
4046 }
4047 for (i = 0; i < 4; i++)
4048 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4049 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4050 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4051 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4052 dcode[3] == 0)) {
4053 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004054 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004055 qla_printk(KERN_WARNING, ha,
4056 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4057 dcode[1], dcode[2], dcode[3]);
4058 goto fail_fw_integrity;
4059 }
4060
4061 while (segments && rval == QLA_SUCCESS) {
4062 risc_addr = be32_to_cpu(fwcode[2]);
4063 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4064 risc_size = be32_to_cpu(fwcode[3]);
4065
4066 /* Validate firmware image size. */
4067 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004068 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004069 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004070 "Unable to verify integrity of firmware image "
4071 "(%Zd)!\n", blob->fw->size);
4072
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004073 goto fail_fw_integrity;
4074 }
4075
4076 fragment = 0;
4077 while (risc_size > 0 && rval == QLA_SUCCESS) {
4078 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4079 if (dlen > risc_size)
4080 dlen = risc_size;
4081
4082 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004083 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004084 risc_addr, dlen));
4085
4086 for (i = 0; i < dlen; i++)
4087 dcode[i] = swab32(fwcode[i]);
4088
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004089 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004090 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004091 if (rval) {
4092 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004093 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004094 fragment));
4095 qla_printk(KERN_WARNING, ha,
4096 "[ERROR] Failed to load segment %d of "
4097 "firmware\n", fragment);
4098 break;
4099 }
4100
4101 fwcode += dlen;
4102 risc_addr += dlen;
4103 risc_size -= dlen;
4104 fragment++;
4105 }
4106
4107 /* Next segment. */
4108 segments--;
4109 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004110 return rval;
4111
4112fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004113 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004114}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004115
4116void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004117qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004118{
4119 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004120 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004121
Andrew Vasqueze4289242007-07-19 15:05:56 -07004122 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004123 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004124 if (!ha->fw_major_version)
4125 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004126
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004127 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004128 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
4129 retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004130 ha->isp_ops->reset_chip(vha);
4131 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004132 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004133 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004134 continue;
4135 qla_printk(KERN_INFO, ha,
4136 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004137 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004138 }
4139}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004140
4141int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004142qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004143{
4144 int rval = QLA_SUCCESS;
4145 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004146 struct qla_hw_data *ha = vha->hw;
4147 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004148 struct req_que *req = ha->req_q_map[0];
4149 struct rsp_que *rsp = ha->rsp_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004150
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004151 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004152 return -EINVAL;
4153
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004154 rval = qla2x00_fw_ready(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004155 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004156 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004157 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004158 }
4159
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004160 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004161
4162 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004163 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004164 if (mb[0] != MBS_COMMAND_COMPLETE) {
4165 DEBUG15(qla_printk(KERN_INFO, ha,
4166 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4167 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4168 mb[0], mb[1], mb[2], mb[6], mb[7]));
4169 return (QLA_FUNCTION_FAILED);
4170 }
4171
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004172 atomic_set(&vha->loop_down_timer, 0);
4173 atomic_set(&vha->loop_state, LOOP_UP);
4174 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4175 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4176 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004177
4178 return rval;
4179}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004180
4181/* 84XX Support **************************************************************/
4182
4183static LIST_HEAD(qla_cs84xx_list);
4184static DEFINE_MUTEX(qla_cs84xx_mutex);
4185
4186static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004187qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004188{
4189 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004190 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004191
4192 mutex_lock(&qla_cs84xx_mutex);
4193
4194 /* Find any shared 84xx chip. */
4195 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4196 if (cs84xx->bus == ha->pdev->bus) {
4197 kref_get(&cs84xx->kref);
4198 goto done;
4199 }
4200 }
4201
4202 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4203 if (!cs84xx)
4204 goto done;
4205
4206 kref_init(&cs84xx->kref);
4207 spin_lock_init(&cs84xx->access_lock);
4208 mutex_init(&cs84xx->fw_update_mutex);
4209 cs84xx->bus = ha->pdev->bus;
4210
4211 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4212done:
4213 mutex_unlock(&qla_cs84xx_mutex);
4214 return cs84xx;
4215}
4216
4217static void
4218__qla84xx_chip_release(struct kref *kref)
4219{
4220 struct qla_chip_state_84xx *cs84xx =
4221 container_of(kref, struct qla_chip_state_84xx, kref);
4222
4223 mutex_lock(&qla_cs84xx_mutex);
4224 list_del(&cs84xx->list);
4225 mutex_unlock(&qla_cs84xx_mutex);
4226 kfree(cs84xx);
4227}
4228
4229void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004230qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004231{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004232 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004233 if (ha->cs84xx)
4234 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4235}
4236
4237static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004238qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004239{
4240 int rval;
4241 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004242 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004243
4244 mutex_lock(&ha->cs84xx->fw_update_mutex);
4245
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004246 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004247
4248 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4249
4250 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4251 QLA_SUCCESS;
4252}