blob: 415fbf60de119a4d61b5e32939f30f33ea91ddc6 [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 int qla2x00_setup_chip(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070024static int qla2x00_init_rings(scsi_qla_host_t *);
25static int qla2x00_fw_ready(scsi_qla_host_t *);
26static int qla2x00_configure_hba(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070027static int qla2x00_configure_loop(scsi_qla_host_t *);
28static int qla2x00_configure_local_loop(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070029static int qla2x00_configure_fabric(scsi_qla_host_t *);
30static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
31static int qla2x00_device_resync(scsi_qla_host_t *);
32static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
33 uint16_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35static int qla2x00_restart_isp(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080037static int qla2x00_find_new_loop_id(scsi_qla_host_t *, fc_port_t *);
Adrian Bunk413975a2006-06-30 02:33:06 -070038
Harihara Kadayam4d4df192008-04-03 13:13:26 -070039static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
40static int qla84xx_init_chip(scsi_qla_host_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080041static int qla25xx_init_queues(struct qla_hw_data *);
Harihara Kadayam4d4df192008-04-03 13:13:26 -070042
Linus Torvalds1da177e2005-04-16 15:20:36 -070043/****************************************************************************/
44/* QLogic ISP2x00 Hardware Support Functions. */
45/****************************************************************************/
46
47/*
48* qla2x00_initialize_adapter
49* Initialize board.
50*
51* Input:
52* ha = adapter block pointer.
53*
54* Returns:
55* 0 = success
56*/
57int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080058qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
60 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080061 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -080062 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -070063
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080065 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -070066 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080067 vha->flags.reset_active = 0;
68 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
69 atomic_set(&vha->loop_state, LOOP_DOWN);
70 vha->device_flags = DFLG_NO_CABLE;
71 vha->dpc_flags = 0;
72 vha->flags.management_server_logged_in = 0;
73 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 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);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700134 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136 return (rval);
137}
138
139/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700140 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 * @ha: HA context
142 *
143 * Returns 0 on success.
144 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700145int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800146qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700148 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700149 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800150 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700151 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700154 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700157 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
159
Andrew Vasquez737faec2008-10-24 15:13:45 -0700160 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700162 /* Get PCI bus information. */
163 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700164 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700165 spin_unlock_irqrestore(&ha->hardware_lock, flags);
166
167 return QLA_SUCCESS;
168}
169
170/**
171 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
172 * @ha: HA context
173 *
174 * Returns 0 on success.
175 */
176int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800177qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700178{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700179 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700180 unsigned long flags = 0;
181 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800182 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700183 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700184
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700185 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700186 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700187
188 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700189 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700190
191 if (IS_QLA2322(ha) || IS_QLA6322(ha))
192 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700193 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700194
195 /*
196 * If this is a 2300 card and not 2312, reset the
197 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
198 * the 2310 also reports itself as a 2300 so we need to get the
199 * fb revision level -- a 6 indicates it really is a 2300 and
200 * not a 2310.
201 */
202 if (IS_QLA2300(ha)) {
203 spin_lock_irqsave(&ha->hardware_lock, flags);
204
205 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700206 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700207 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700208 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700209 break;
210
211 udelay(10);
212 }
213
214 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700215 WRT_REG_WORD(&reg->ctrl_status, 0x20);
216 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700217
218 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700219 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700220
221 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700222 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700223
224 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700225 WRT_REG_WORD(&reg->ctrl_status, 0x0);
226 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700227
228 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700229 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700230 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700231 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700232 break;
233
234 udelay(10);
235 }
236
237 spin_unlock_irqrestore(&ha->hardware_lock, flags);
238 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700239
240 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
241
Andrew Vasquez737faec2008-10-24 15:13:45 -0700242 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700243
244 /* Get PCI bus information. */
245 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700246 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700247 spin_unlock_irqrestore(&ha->hardware_lock, flags);
248
249 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250}
251
252/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700253 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
254 * @ha: HA context
255 *
256 * Returns 0 on success.
257 */
258int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800259qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700260{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700261 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700262 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800263 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700264 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700265
266 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700267 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700268
269 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700270 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700271 w &= ~PCI_COMMAND_INTX_DISABLE;
272 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
273
274 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
275
276 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700277 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
278 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700279
280 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700281 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
282 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700283
Andrew Vasquez737faec2008-10-24 15:13:45 -0700284 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700285
Auke Kok44c10132007-06-08 15:46:36 -0700286 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800287
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700288 /* Get PCI bus information. */
289 spin_lock_irqsave(&ha->hardware_lock, flags);
290 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
291 spin_unlock_irqrestore(&ha->hardware_lock, flags);
292
293 return QLA_SUCCESS;
294}
295
296/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700297 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
298 * @ha: HA context
299 *
300 * Returns 0 on success.
301 */
302int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800303qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700304{
305 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800306 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700307
308 pci_set_master(ha->pdev);
309 pci_try_set_mwi(ha->pdev);
310
311 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
312 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
313 w &= ~PCI_COMMAND_INTX_DISABLE;
314 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
315
316 /* PCIe -- adjust Maximum Read Request Size (2048). */
317 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
318 pcie_set_readrq(ha->pdev, 2048);
319
Andrew Vasquez737faec2008-10-24 15:13:45 -0700320 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700321
322 ha->chip_revision = ha->pdev->revision;
323
324 return QLA_SUCCESS;
325}
326
327/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 * qla2x00_isp_firmware() - Choose firmware image.
329 * @ha: HA context
330 *
331 * Returns 0 on success.
332 */
333static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800334qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335{
336 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700337 uint16_t loop_id, topo, sw_cap;
338 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800339 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
341 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700342 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
344 if (ha->flags.disable_risc_code_load) {
345 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800346 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
348
349 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800350 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700351 if (rval == QLA_SUCCESS) {
352 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800353 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700354 &area, &domain, &topo, &sw_cap);
355 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 }
357
358 if (rval) {
359 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800360 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 }
362
363 return (rval);
364}
365
366/**
367 * qla2x00_reset_chip() - Reset ISP chip.
368 * @ha: HA context
369 *
370 * Returns 0 on success.
371 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700372void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800373qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374{
375 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800376 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700377 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 uint16_t cmd;
380
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700381 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
383 spin_lock_irqsave(&ha->hardware_lock, flags);
384
385 /* Turn off master enable */
386 cmd = 0;
387 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
388 cmd &= ~PCI_COMMAND_MASTER;
389 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
390
391 if (!IS_QLA2100(ha)) {
392 /* Pause RISC. */
393 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
394 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
395 for (cnt = 0; cnt < 30000; cnt++) {
396 if ((RD_REG_WORD(&reg->hccr) &
397 HCCR_RISC_PAUSE) != 0)
398 break;
399 udelay(100);
400 }
401 } else {
402 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
403 udelay(10);
404 }
405
406 /* Select FPM registers. */
407 WRT_REG_WORD(&reg->ctrl_status, 0x20);
408 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
409
410 /* FPM Soft Reset. */
411 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
412 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
413
414 /* Toggle Fpm Reset. */
415 if (!IS_QLA2200(ha)) {
416 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
417 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
418 }
419
420 /* Select frame buffer registers. */
421 WRT_REG_WORD(&reg->ctrl_status, 0x10);
422 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
423
424 /* Reset frame buffer FIFOs. */
425 if (IS_QLA2200(ha)) {
426 WRT_FB_CMD_REG(ha, reg, 0xa000);
427 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
428 } else {
429 WRT_FB_CMD_REG(ha, reg, 0x00fc);
430
431 /* Read back fb_cmd until zero or 3 seconds max */
432 for (cnt = 0; cnt < 3000; cnt++) {
433 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
434 break;
435 udelay(100);
436 }
437 }
438
439 /* Select RISC module registers. */
440 WRT_REG_WORD(&reg->ctrl_status, 0);
441 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
442
443 /* Reset RISC processor. */
444 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
445 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
446
447 /* Release RISC processor. */
448 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
449 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
450 }
451
452 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
453 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
454
455 /* Reset ISP chip. */
456 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
457
458 /* Wait for RISC to recover from reset. */
459 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
460 /*
461 * It is necessary to for a delay here since the card doesn't
462 * respond to PCI reads during a reset. On some architectures
463 * this will result in an MCA.
464 */
465 udelay(20);
466 for (cnt = 30000; cnt; cnt--) {
467 if ((RD_REG_WORD(&reg->ctrl_status) &
468 CSR_ISP_SOFT_RESET) == 0)
469 break;
470 udelay(100);
471 }
472 } else
473 udelay(10);
474
475 /* Reset RISC processor. */
476 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
477
478 WRT_REG_WORD(&reg->semaphore, 0);
479
480 /* Release RISC processor. */
481 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
482 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
483
484 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
485 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700486 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
489 udelay(100);
490 }
491 } else
492 udelay(100);
493
494 /* Turn on master enable */
495 cmd |= PCI_COMMAND_MASTER;
496 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
497
498 /* Disable RISC pause on FPM parity error. */
499 if (!IS_QLA2100(ha)) {
500 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
501 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
502 }
503
504 spin_unlock_irqrestore(&ha->hardware_lock, flags);
505}
506
507/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700508 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700509 * @ha: HA context
510 *
511 * Returns 0 on success.
512 */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700513static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800514qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700515{
516 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 }
545
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800546 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700547 d2 = RD_REG_DWORD(&reg->ctrl_status);
548 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
549 udelay(5);
550 d2 = RD_REG_DWORD(&reg->ctrl_status);
551 barrier();
552 }
553
554 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
555 RD_REG_DWORD(&reg->hccr);
556
557 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
558 RD_REG_DWORD(&reg->hccr);
559
560 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
561 RD_REG_DWORD(&reg->hccr);
562
563 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
564 for (cnt = 6000000 ; cnt && d2; cnt--) {
565 udelay(5);
566 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
567 barrier();
568 }
569
570 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800571
572 if (IS_NOPOLLING_TYPE(ha))
573 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700574}
575
576/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700577 * qla24xx_reset_chip() - Reset ISP24xx chip.
578 * @ha: HA context
579 *
580 * Returns 0 on success.
581 */
582void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800583qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -0700584{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800585 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700586 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700587
588 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800589 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700590}
591
592/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 * qla2x00_chip_diag() - Test chip for proper operation.
594 * @ha: HA context
595 *
596 * Returns 0 on success.
597 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700598int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800599qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600{
601 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800602 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700603 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 unsigned long flags = 0;
605 uint16_t data;
606 uint32_t cnt;
607 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800608 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
610 /* Assume a failed state */
611 rval = QLA_FUNCTION_FAILED;
612
613 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800614 vha->host_no, (u_long)&reg->flash_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
616 spin_lock_irqsave(&ha->hardware_lock, flags);
617
618 /* Reset ISP chip. */
619 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
620
621 /*
622 * We need to have a delay here since the card will not respond while
623 * in reset causing an MCA on some architectures.
624 */
625 udelay(20);
626 data = qla2x00_debounce_register(&reg->ctrl_status);
627 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
628 udelay(5);
629 data = RD_REG_WORD(&reg->ctrl_status);
630 barrier();
631 }
632
633 if (!cnt)
634 goto chip_diag_failed;
635
636 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
Andrew Vasquez76403352009-04-06 22:33:39 -0700637 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
639 /* Reset RISC processor. */
640 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
641 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
642
643 /* Workaround for QLA2312 PCI parity error */
644 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
645 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
646 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
647 udelay(5);
648 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700649 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 }
651 } else
652 udelay(10);
653
654 if (!cnt)
655 goto chip_diag_failed;
656
657 /* Check product ID of chip */
Andrew Vasquez76403352009-04-06 22:33:39 -0700658 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
660 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
661 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
662 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
663 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
664 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
665 mb[3] != PROD_ID_3) {
666 qla_printk(KERN_WARNING, ha,
667 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
668
669 goto chip_diag_failed;
670 }
671 ha->product_id[0] = mb[1];
672 ha->product_id[1] = mb[2];
673 ha->product_id[2] = mb[3];
674 ha->product_id[3] = mb[4];
675
676 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800677 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
679 else
680 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800681 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
683 if (IS_QLA2200(ha) &&
684 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
685 /* Limit firmware transfer size with a 2200A */
686 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800687 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -0800689 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 ha->fw_transfer_size = 128;
691 }
692
693 /* Wrap Incoming Mailboxes Test. */
694 spin_unlock_irqrestore(&ha->hardware_lock, flags);
695
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800696 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
697 rval = qla2x00_mbx_reg_test(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 if (rval) {
699 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800700 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 qla_printk(KERN_WARNING, ha,
702 "Failed mailbox send register test\n");
703 }
704 else {
705 /* Flag a successful rval */
706 rval = QLA_SUCCESS;
707 }
708 spin_lock_irqsave(&ha->hardware_lock, flags);
709
710chip_diag_failed:
711 if (rval)
712 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800713 "****\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
715 spin_unlock_irqrestore(&ha->hardware_lock, flags);
716
717 return (rval);
718}
719
720/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700721 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
722 * @ha: HA context
723 *
724 * Returns 0 on success.
725 */
726int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800727qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700728{
729 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800730 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800731 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700732
Andrew Vasquez88c26662005-07-08 17:59:26 -0700733 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800734 qla24xx_reset_risc(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700735
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800736 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700737
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800738 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700739 if (rval) {
740 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800741 vha->host_no));
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700742 qla_printk(KERN_WARNING, ha,
743 "Failed mailbox send register test\n");
744 } else {
745 /* Flag a successful rval */
746 rval = QLA_SUCCESS;
747 }
748
749 return rval;
750}
751
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700752void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800753qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700754{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700755 int rval;
756 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800757 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800758 dma_addr_t tc_dma;
759 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800760 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800761 struct req_que *req = ha->req_q_map[0];
762 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700763
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700764 if (ha->fw_dump) {
765 qla_printk(KERN_WARNING, ha,
766 "Firmware dump previously allocated.\n");
767 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700768 }
769
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700770 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800771 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700772 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
773 fixed_size = sizeof(struct qla2100_fw_dump);
774 } else if (IS_QLA23XX(ha)) {
775 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
776 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
777 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -0700778 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800779 if (IS_QLA81XX(ha))
780 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
781 else if (IS_QLA25XX(ha))
782 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
783 else
784 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700785 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
786 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800787 if (ha->mqenable)
788 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700789 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800790 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700791 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
Giridhar Malavali7d9dade2009-03-24 09:07:58 -0700816 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700817 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);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700852 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -0800853 ha->chain_offset = dump_size;
854 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700855
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700856 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700857 if (!ha->fw_dump) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700858 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700859 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700860
861 if (ha->eft) {
862 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
863 ha->eft_dma);
864 ha->eft = NULL;
865 ha->eft_dma = 0;
866 }
867 return;
868 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700869 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
870 dump_size / 1024);
871
872 ha->fw_dump_len = dump_size;
873 ha->fw_dump->signature[0] = 'Q';
874 ha->fw_dump->signature[1] = 'L';
875 ha->fw_dump->signature[2] = 'G';
876 ha->fw_dump->signature[3] = 'C';
877 ha->fw_dump->version = __constant_htonl(1);
878
879 ha->fw_dump->fixed_size = htonl(fixed_size);
880 ha->fw_dump->mem_size = htonl(mem_size);
881 ha->fw_dump->req_q_size = htonl(req_q_size);
882 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
883
884 ha->fw_dump->eft_size = htonl(eft_size);
885 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
886 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
887
888 ha->fw_dump->header_size =
889 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700890}
891
892/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 * qla2x00_setup_chip() - Load and start RISC firmware.
894 * @ha: HA context
895 *
896 * Returns 0 on success.
897 */
898static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800899qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900{
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700901 int rval;
902 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800903 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -0800904 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
905 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -0700906 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -0800907
908 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
909 /* Disable SRAM, Instruction RAM and GP RAM parity. */
910 spin_lock_irqsave(&ha->hardware_lock, flags);
911 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
912 RD_REG_WORD(&reg->hccr);
913 spin_unlock_irqrestore(&ha->hardware_lock, flags);
914 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
916 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800917 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700918 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800920 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800922 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 if (rval == QLA_SUCCESS) {
924 /* Start firmware execution. */
925 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800926 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800928 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -0700930 if (rval == QLA_SUCCESS) {
931 fw_major_version = ha->fw_major_version;
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700932 rval = qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 &ha->fw_major_version,
934 &ha->fw_minor_version,
935 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800936 &ha->fw_attributes, &ha->fw_memory_size,
Andrew Vasquez55a96152009-03-24 09:08:03 -0700937 ha->mpi_version, &ha->mpi_capabilities,
938 ha->phy_version);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700939 if (rval != QLA_SUCCESS)
940 goto failed;
941
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700942 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800943 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -0700944 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700945 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700946 if ((!ha->max_npiv_vports) ||
947 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800948 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700949 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800950 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700951 }
Andrew Vasquez24a08132009-03-24 09:08:16 -0700952 qla2x00_get_resource_cnts(vha, NULL,
953 &ha->fw_xcb_count, NULL, NULL,
954 &ha->max_npiv_vports);
Andrew Vasquezd743de62009-03-24 09:08:15 -0700955
956 if (!fw_major_version && ql2xallocfwdump)
957 qla2x00_alloc_fw_dump(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 }
959 } else {
960 DEBUG2(printk(KERN_INFO
961 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800962 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 }
964 }
965
Andrew Vasquez3db06522008-01-31 12:33:49 -0800966 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
967 /* Enable proper parity. */
968 spin_lock_irqsave(&ha->hardware_lock, flags);
969 if (IS_QLA2300(ha))
970 /* SRAM parity */
971 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
972 else
973 /* SRAM, Instruction RAM and GP RAM parity */
974 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
975 RD_REG_WORD(&reg->hccr);
976 spin_unlock_irqrestore(&ha->hardware_lock, flags);
977 }
978
Joe Carnuccio1d2874d2009-03-24 09:08:06 -0700979 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
980 uint32_t size;
981
982 rval = qla81xx_fac_get_sector_size(vha, &size);
983 if (rval == QLA_SUCCESS) {
984 ha->flags.fac_supported = 1;
985 ha->fdt_block_size = size << 2;
986 } else {
987 qla_printk(KERN_ERR, ha,
988 "Unsupported FAC firmware (%d.%02d.%02d).\n",
989 ha->fw_major_version, ha->fw_minor_version,
990 ha->fw_subminor_version);
991 }
992 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700993failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 if (rval) {
995 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800996 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 }
998
999 return (rval);
1000}
1001
1002/**
1003 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1004 * @ha: HA context
1005 *
1006 * Beginning of request ring has initialization control block already built
1007 * by nvram config routine.
1008 *
1009 * Returns 0 on success.
1010 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001011void
1012qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013{
1014 uint16_t cnt;
1015 response_t *pkt;
1016
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001017 rsp->ring_ptr = rsp->ring;
1018 rsp->ring_index = 0;
1019 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001020 pkt = rsp->ring_ptr;
1021 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 pkt->signature = RESPONSE_PROCESSED;
1023 pkt++;
1024 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025}
1026
1027/**
1028 * qla2x00_update_fw_options() - Read and process firmware options.
1029 * @ha: HA context
1030 *
1031 * Returns 0 on success.
1032 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001033void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001034qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035{
1036 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001037 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
1039 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001040 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041
1042 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1043 return;
1044
1045 /* Serial Link options. */
1046 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001047 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1049 sizeof(ha->fw_seriallink_options)));
1050
1051 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1052 if (ha->fw_seriallink_options[3] & BIT_2) {
1053 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1054
1055 /* 1G settings */
1056 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1057 emphasis = (ha->fw_seriallink_options[2] &
1058 (BIT_4 | BIT_3)) >> 3;
1059 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001060 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 rx_sens = (ha->fw_seriallink_options[0] &
1062 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1063 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1064 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1065 if (rx_sens == 0x0)
1066 rx_sens = 0x3;
1067 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1068 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1069 ha->fw_options[10] |= BIT_5 |
1070 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1071 (tx_sens & (BIT_1 | BIT_0));
1072
1073 /* 2G settings */
1074 swing = (ha->fw_seriallink_options[2] &
1075 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1076 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1077 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001078 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 rx_sens = (ha->fw_seriallink_options[1] &
1080 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1081 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1082 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1083 if (rx_sens == 0x0)
1084 rx_sens = 0x3;
1085 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1086 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1087 ha->fw_options[11] |= BIT_5 |
1088 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1089 (tx_sens & (BIT_1 | BIT_0));
1090 }
1091
1092 /* FCP2 options. */
1093 /* Return command IOCBs without waiting for an ABTS to complete. */
1094 ha->fw_options[3] |= BIT_13;
1095
1096 /* LED scheme. */
1097 if (ha->flags.enable_led_scheme)
1098 ha->fw_options[2] |= BIT_12;
1099
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001100 /* Detect ISP6312. */
1101 if (IS_QLA6312(ha))
1102 ha->fw_options[2] |= BIT_13;
1103
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001105 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106}
1107
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001108void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001109qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001110{
1111 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001112 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001113
1114 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001115 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001116 return;
1117
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001118 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001119 le16_to_cpu(ha->fw_seriallink_options24[1]),
1120 le16_to_cpu(ha->fw_seriallink_options24[2]),
1121 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001122 if (rval != QLA_SUCCESS) {
1123 qla_printk(KERN_WARNING, ha,
1124 "Unable to update Serial Link options (%x).\n", rval);
1125 }
1126}
1127
1128void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001129qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001130{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001131 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001132 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001133 struct req_que *req = ha->req_q_map[0];
1134 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001135
1136 /* Setup ring parameters in initialization control block. */
1137 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1138 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001139 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1140 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1141 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1142 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1143 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1144 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001145
1146 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1147 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1148 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1149 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1150 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1151}
1152
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001153void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001154qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001155{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001156 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001157 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1158 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1159 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001160 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001161 uint16_t rid = 0;
1162 struct req_que *req = ha->req_q_map[0];
1163 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001164
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001165/* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001166 icb = (struct init_cb_24xx *)ha->init_cb;
1167 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1168 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001169 icb->request_q_length = cpu_to_le16(req->length);
1170 icb->response_q_length = cpu_to_le16(rsp->length);
1171 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1172 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1173 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1174 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001175
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001176 if (ha->mqenable) {
1177 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1178 icb->rid = __constant_cpu_to_le16(rid);
1179 if (ha->flags.msix_enabled) {
1180 msix = &ha->msix_entries[1];
1181 DEBUG2_17(printk(KERN_INFO
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001182 "Registering vector 0x%x for base que\n", msix->entry));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001183 icb->msix = cpu_to_le16(msix->entry);
1184 }
1185 /* Use alternate PCI bus number */
1186 if (MSB(rid))
1187 icb->firmware_options_2 |=
1188 __constant_cpu_to_le32(BIT_19);
1189 /* Use alternate PCI devfn */
1190 if (LSB(rid))
1191 icb->firmware_options_2 |=
1192 __constant_cpu_to_le32(BIT_18);
1193
Anirban Chakraborty618a7522009-02-08 20:50:11 -08001194 icb->firmware_options_2 &= __constant_cpu_to_le32(~BIT_22);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001195 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001196
1197 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1198 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1199 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1200 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1201 } else {
1202 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1203 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1204 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1205 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1206 }
1207 /* PCI posting */
1208 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001209}
1210
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211/**
1212 * qla2x00_init_rings() - Initializes firmware.
1213 * @ha: HA context
1214 *
1215 * Beginning of request ring has initialization control block already built
1216 * by nvram config routine.
1217 *
1218 * Returns 0 on success.
1219 */
1220static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001221qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222{
1223 int rval;
1224 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001225 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001226 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001227 struct req_que *req;
1228 struct rsp_que *rsp;
1229 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001230 struct mid_init_cb_24xx *mid_init_cb =
1231 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
1233 spin_lock_irqsave(&ha->hardware_lock, flags);
1234
1235 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001236 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001237 req = ha->req_q_map[que];
1238 if (!req)
1239 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001240 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001241 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001243 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001244
1245 /* Initialize firmware. */
1246 req->ring_ptr = req->ring;
1247 req->ring_index = 0;
1248 req->cnt = req->length;
1249 }
1250
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001251 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001252 rsp = ha->rsp_q_map[que];
1253 if (!rsp)
1254 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001255 /* Initialize response queue entries */
1256 qla2x00_init_response_q_entries(rsp);
1257 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258
1259 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001260 list_for_each_entry(vp, &ha->vp_list, list) {
1261 vp->rscn_in_ptr = 0;
1262 vp->rscn_out_ptr = 0;
1263 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001264 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265
1266 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1267
1268 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001269 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001271 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001272
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001273 if (ha->flags.npiv_supported) {
1274 if (ha->operating_mode == LOOP)
1275 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001276 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001277 }
1278
Andrew Vasquez24a08132009-03-24 09:08:16 -07001279 if (IS_FWI2_CAPABLE(ha)) {
1280 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1281 mid_init_cb->init_cb.execution_throttle =
1282 cpu_to_le16(ha->fw_xcb_count);
1283 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001284
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001285 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 if (rval) {
1287 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001288 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 } else {
1290 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001291 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 }
1293
1294 return (rval);
1295}
1296
1297/**
1298 * qla2x00_fw_ready() - Waits for firmware ready.
1299 * @ha: HA context
1300 *
1301 * Returns 0 on success.
1302 */
1303static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001304qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305{
1306 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001307 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 uint16_t min_wait; /* Minimum wait time if loop is down */
1309 uint16_t wait_time; /* Wait time if loop is coming ready */
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001310 uint16_t state[3];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001311 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312
1313 rval = QLA_SUCCESS;
1314
1315 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001316 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
1318 /*
1319 * Firmware should take at most one RATOV to login, plus 5 seconds for
1320 * our own processing.
1321 */
1322 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1323 wait_time = min_wait;
1324 }
1325
1326 /* Min wait time if loop down */
1327 mtime = jiffies + (min_wait * HZ);
1328
1329 /* wait time before firmware ready */
1330 wtime = jiffies + (wait_time * HZ);
1331
1332 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001333 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1335
1336 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001337 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
1339 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001340 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001342 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001343 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001345 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1346 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001347 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001348 state[2]));
1349 if ((state[2] & FSTATE_LOGGED_IN) &&
1350 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1351 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001352 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001353
1354 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001355 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001356 if (rval != QLA_SUCCESS)
1357 break;
1358
1359 /* Add time taken to initialize. */
1360 cs84xx_time = jiffies - cs84xx_time;
1361 wtime += cs84xx_time;
1362 mtime += cs84xx_time;
1363 DEBUG16(printk("scsi(%ld): Increasing "
1364 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001365 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001366 }
1367 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001369 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001371 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 &ha->login_timeout, &ha->r_a_tov);
1373
1374 rval = QLA_SUCCESS;
1375 break;
1376 }
1377
1378 rval = QLA_FUNCTION_FAILED;
1379
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001380 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001381 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001383 * other than Wait for Login.
1384 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 if (time_after_eq(jiffies, mtime)) {
1386 qla_printk(KERN_INFO, ha,
1387 "Cable is unplugged...\n");
1388
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001389 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 break;
1391 }
1392 }
1393 } else {
1394 /* Mailbox cmd failed. Timeout on min_wait. */
1395 if (time_after_eq(jiffies, mtime))
1396 break;
1397 }
1398
1399 if (time_after_eq(jiffies, wtime))
1400 break;
1401
1402 /* Delay for a while */
1403 msleep(500);
1404
1405 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001406 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 } while (1);
1408
1409 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001410 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411
1412 if (rval) {
1413 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001414 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 }
1416
1417 return (rval);
1418}
1419
1420/*
1421* qla2x00_configure_hba
1422* Setup adapter context.
1423*
1424* Input:
1425* ha = adapter state pointer.
1426*
1427* Returns:
1428* 0 = success
1429*
1430* Context:
1431* Kernel context.
1432*/
1433static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001434qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435{
1436 int rval;
1437 uint16_t loop_id;
1438 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001439 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 uint8_t al_pa;
1441 uint8_t area;
1442 uint8_t domain;
1443 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001444 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445
1446 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001447 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001448 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001450 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001451 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1452 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001453 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08001454 } else {
1455 qla_printk(KERN_WARNING, ha,
1456 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001457 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08001458 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 return (rval);
1460 }
1461
1462 if (topo == 4) {
1463 qla_printk(KERN_INFO, ha,
1464 "Cannot get topology - retrying.\n");
1465 return (QLA_FUNCTION_FAILED);
1466 }
1467
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001468 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
1470 /* initialize */
1471 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1472 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001473 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
1475 switch (topo) {
1476 case 0:
1477 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001478 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 ha->current_topology = ISP_CFG_NL;
1480 strcpy(connect_type, "(Loop)");
1481 break;
1482
1483 case 1:
1484 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001485 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001486 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 ha->current_topology = ISP_CFG_FL;
1488 strcpy(connect_type, "(FL_Port)");
1489 break;
1490
1491 case 2:
1492 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001493 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 ha->operating_mode = P2P;
1495 ha->current_topology = ISP_CFG_N;
1496 strcpy(connect_type, "(N_Port-to-N_Port)");
1497 break;
1498
1499 case 3:
1500 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001501 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001502 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 ha->operating_mode = P2P;
1504 ha->current_topology = ISP_CFG_F;
1505 strcpy(connect_type, "(F_Port)");
1506 break;
1507
1508 default:
1509 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1510 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001511 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 ha->current_topology = ISP_CFG_NL;
1513 strcpy(connect_type, "(Loop)");
1514 break;
1515 }
1516
1517 /* Save Host port and loop ID. */
1518 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001519 vha->d_id.b.domain = domain;
1520 vha->d_id.b.area = area;
1521 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001523 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 qla_printk(KERN_INFO, ha,
1525 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001526 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
1528 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001529 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001531 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 }
1533
1534 return(rval);
1535}
1536
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001537static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001538qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1539 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001540{
1541 char *st, *en;
1542 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001543 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez1b91a2e2009-06-03 09:55:15 -07001544 int use_tbl = !IS_QLA25XX(ha) && !IS_QLA81XX(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001545
1546 if (memcmp(model, BINZERO, len) != 0) {
1547 strncpy(ha->model_number, model, len);
1548 st = en = ha->model_number;
1549 en += len - 1;
1550 while (en > st) {
1551 if (*en != 0x20 && *en != 0x00)
1552 break;
1553 *en-- = '\0';
1554 }
1555
1556 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07001557 if (use_tbl &&
1558 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001559 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001560 strncpy(ha->model_desc,
1561 qla2x00_model_name[index * 2 + 1],
1562 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001563 } else {
1564 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07001565 if (use_tbl &&
1566 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001567 index < QLA_MODEL_NAMES) {
1568 strcpy(ha->model_number,
1569 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001570 strncpy(ha->model_desc,
1571 qla2x00_model_name[index * 2 + 1],
1572 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001573 } else {
1574 strcpy(ha->model_number, def);
1575 }
1576 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001577 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001578 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001579 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001580}
1581
David Miller4e08df32007-04-16 12:37:43 -07001582/* On sparc systems, obtain port and node WWN from firmware
1583 * properties.
1584 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001585static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07001586{
1587#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001588 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07001589 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07001590 struct device_node *dp = pci_device_to_OF_node(pdev);
1591 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07001592 int len;
1593
1594 val = of_get_property(dp, "port-wwn", &len);
1595 if (val && len >= WWN_SIZE)
1596 memcpy(nv->port_name, val, WWN_SIZE);
1597
1598 val = of_get_property(dp, "node-wwn", &len);
1599 if (val && len >= WWN_SIZE)
1600 memcpy(nv->node_name, val, WWN_SIZE);
1601#endif
1602}
1603
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604/*
1605* NVRAM configuration for ISP 2xxx
1606*
1607* Input:
1608* ha = adapter block pointer.
1609*
1610* Output:
1611* initialization control block in response_ring
1612* host adapters parameters in host adapter block
1613*
1614* Returns:
1615* 0 = success.
1616*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001617int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001618qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619{
David Miller4e08df32007-04-16 12:37:43 -07001620 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001621 uint8_t chksum = 0;
1622 uint16_t cnt;
1623 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001624 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001625 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07001626 nvram_t *nv = ha->nvram;
1627 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001628 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629
David Miller4e08df32007-04-16 12:37:43 -07001630 rval = QLA_SUCCESS;
1631
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001633 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 ha->nvram_base = 0;
1635 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1636 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
1637 ha->nvram_base = 0x80;
1638
1639 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001640 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001641 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1642 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001644 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07001645 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646
1647 /* Bad NVRAM data, set defaults parameters. */
1648 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1649 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1650 /* Reset NVRAM data. */
1651 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1652 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1653 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07001654 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1655 "invalid -- WWPN) defaults.\n");
1656
1657 /*
1658 * Set default initialization control block.
1659 */
1660 memset(nv, 0, ha->nvram_size);
1661 nv->parameter_block_version = ICB_VERSION;
1662
1663 if (IS_QLA23XX(ha)) {
1664 nv->firmware_options[0] = BIT_2 | BIT_1;
1665 nv->firmware_options[1] = BIT_7 | BIT_5;
1666 nv->add_firmware_options[0] = BIT_5;
1667 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1668 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1669 nv->special_options[1] = BIT_7;
1670 } else if (IS_QLA2200(ha)) {
1671 nv->firmware_options[0] = BIT_2 | BIT_1;
1672 nv->firmware_options[1] = BIT_7 | BIT_5;
1673 nv->add_firmware_options[0] = BIT_5;
1674 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1675 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1676 } else if (IS_QLA2100(ha)) {
1677 nv->firmware_options[0] = BIT_3 | BIT_1;
1678 nv->firmware_options[1] = BIT_5;
1679 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1680 }
1681
1682 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1683 nv->execution_throttle = __constant_cpu_to_le16(16);
1684 nv->retry_count = 8;
1685 nv->retry_delay = 1;
1686
1687 nv->port_name[0] = 33;
1688 nv->port_name[3] = 224;
1689 nv->port_name[4] = 139;
1690
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001691 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07001692
1693 nv->login_timeout = 4;
1694
1695 /*
1696 * Set default host adapter parameters
1697 */
1698 nv->host_p[1] = BIT_2;
1699 nv->reset_delay = 5;
1700 nv->port_down_retry_count = 8;
1701 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1702 nv->link_down_timeout = 60;
1703
1704 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 }
1706
1707#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1708 /*
1709 * The SN2 does not provide BIOS emulation which means you can't change
1710 * potentially bogus BIOS settings. Force the use of default settings
1711 * for link rate and frame size. Hope that the rest of the settings
1712 * are valid.
1713 */
1714 if (ia64_platform_is("sn2")) {
1715 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1716 if (IS_QLA23XX(ha))
1717 nv->special_options[1] = BIT_7;
1718 }
1719#endif
1720
1721 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001722 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723
1724 /*
1725 * Setup driver NVRAM options.
1726 */
1727 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1728 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1729 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1730 nv->firmware_options[1] &= ~BIT_4;
1731
1732 if (IS_QLA23XX(ha)) {
1733 nv->firmware_options[0] |= BIT_2;
1734 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001735 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736
1737 if (IS_QLA2300(ha)) {
1738 if (ha->fb_rev == FPM_2310) {
1739 strcpy(ha->model_number, "QLA2310");
1740 } else {
1741 strcpy(ha->model_number, "QLA2300");
1742 }
1743 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001744 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001745 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 }
1747 } else if (IS_QLA2200(ha)) {
1748 nv->firmware_options[0] |= BIT_2;
1749 /*
1750 * 'Point-to-point preferred, else loop' is not a safe
1751 * connection mode setting.
1752 */
1753 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1754 (BIT_5 | BIT_4)) {
1755 /* Force 'loop preferred, else point-to-point'. */
1756 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1757 nv->add_firmware_options[0] |= BIT_5;
1758 }
1759 strcpy(ha->model_number, "QLA22xx");
1760 } else /*if (IS_QLA2100(ha))*/ {
1761 strcpy(ha->model_number, "QLA2100");
1762 }
1763
1764 /*
1765 * Copy over NVRAM RISC parameter block to initialization control block.
1766 */
1767 dptr1 = (uint8_t *)icb;
1768 dptr2 = (uint8_t *)&nv->parameter_block_version;
1769 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1770 while (cnt--)
1771 *dptr1++ = *dptr2++;
1772
1773 /* Copy 2nd half. */
1774 dptr1 = (uint8_t *)icb->add_firmware_options;
1775 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1776 while (cnt--)
1777 *dptr1++ = *dptr2++;
1778
Andrew Vasquez5341e862006-05-17 15:09:16 -07001779 /* Use alternate WWN? */
1780 if (nv->host_p[1] & BIT_7) {
1781 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1782 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1783 }
1784
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 /* Prepare nodename */
1786 if ((icb->firmware_options[1] & BIT_6) == 0) {
1787 /*
1788 * Firmware will apply the following mask if the nodename was
1789 * not provided.
1790 */
1791 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1792 icb->node_name[0] &= 0xF0;
1793 }
1794
1795 /*
1796 * Set host adapter parameters.
1797 */
Andrew Vasquez01819442006-06-23 16:11:10 -07001798 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07001799 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1801 /* Always load RISC code on non ISP2[12]00 chips. */
1802 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1803 ha->flags.disable_risc_code_load = 0;
1804 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1805 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1806 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07001807 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001808 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809
1810 ha->operating_mode =
1811 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1812
1813 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1814 sizeof(ha->fw_seriallink_options));
1815
1816 /* save HBA serial number */
1817 ha->serial0 = icb->port_name[5];
1818 ha->serial1 = icb->port_name[6];
1819 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001820 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
1821 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822
1823 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1824
1825 ha->retry_count = nv->retry_count;
1826
1827 /* Set minimum login_timeout to 4 seconds. */
1828 if (nv->login_timeout < ql2xlogintimeout)
1829 nv->login_timeout = ql2xlogintimeout;
1830 if (nv->login_timeout < 4)
1831 nv->login_timeout = 4;
1832 ha->login_timeout = nv->login_timeout;
1833 icb->login_timeout = nv->login_timeout;
1834
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001835 /* Set minimum RATOV to 100 tenths of a second. */
1836 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 ha->loop_reset_delay = nv->reset_delay;
1839
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 /* Link Down Timeout = 0:
1841 *
1842 * When Port Down timer expires we will start returning
1843 * I/O's to OS with "DID_NO_CONNECT".
1844 *
1845 * Link Down Timeout != 0:
1846 *
1847 * The driver waits for the link to come up after link down
1848 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001849 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 if (nv->link_down_timeout == 0) {
1851 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001852 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 } else {
1854 ha->link_down_timeout = nv->link_down_timeout;
1855 ha->loop_down_abort_time =
1856 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001857 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 /*
1860 * Need enough time to try and get the port back.
1861 */
1862 ha->port_down_retry_count = nv->port_down_retry_count;
1863 if (qlport_down_retry)
1864 ha->port_down_retry_count = qlport_down_retry;
1865 /* Set login_retry_count */
1866 ha->login_retry_count = nv->retry_count;
1867 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1868 ha->port_down_retry_count > 3)
1869 ha->login_retry_count = ha->port_down_retry_count;
1870 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1871 ha->login_retry_count = ha->port_down_retry_count;
1872 if (ql2xloginretrycount)
1873 ha->login_retry_count = ql2xloginretrycount;
1874
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 icb->lun_enables = __constant_cpu_to_le16(0);
1876 icb->command_resource_count = 0;
1877 icb->immediate_notify_resource_count = 0;
1878 icb->timeout = __constant_cpu_to_le16(0);
1879
1880 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1881 /* Enable RIO */
1882 icb->firmware_options[0] &= ~BIT_3;
1883 icb->add_firmware_options[0] &=
1884 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1885 icb->add_firmware_options[0] |= BIT_2;
1886 icb->response_accumulation_timer = 3;
1887 icb->interrupt_delay_timer = 5;
1888
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001889 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001891 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001892 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001893 ha->zio_mode = icb->add_firmware_options[0] &
1894 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1895 ha->zio_timer = icb->interrupt_delay_timer ?
1896 icb->interrupt_delay_timer: 2;
1897 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 icb->add_firmware_options[0] &=
1899 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001900 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001901 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001902 ha->zio_mode = QLA_ZIO_MODE_6;
1903
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001904 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001905 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001906 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001908 "ZIO mode %d enabled; timer delay (%d us).\n",
1909 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001911 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1912 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001913 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 }
1915 }
1916
David Miller4e08df32007-04-16 12:37:43 -07001917 if (rval) {
1918 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001919 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07001920 }
1921 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922}
1923
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001924static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001925qla2x00_rport_del(void *data)
1926{
1927 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001928 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001929
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001930 spin_lock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001931 rport = fcport->drport;
1932 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001933 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001934 if (rport)
1935 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001936}
1937
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938/**
1939 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1940 * @ha: HA context
1941 * @flags: allocation flags
1942 *
1943 * Returns a pointer to the allocated fcport, or NULL, if none available.
1944 */
Adrian Bunk413975a2006-06-30 02:33:06 -07001945static fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001946qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947{
1948 fc_port_t *fcport;
1949
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001950 fcport = kzalloc(sizeof(fc_port_t), flags);
1951 if (!fcport)
1952 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953
1954 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001955 fcport->vha = vha;
1956 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 fcport->port_type = FCT_UNKNOWN;
1958 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 atomic_set(&fcport->state, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001960 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001962 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963}
1964
1965/*
1966 * qla2x00_configure_loop
1967 * Updates Fibre Channel Device Database with what is actually on loop.
1968 *
1969 * Input:
1970 * ha = adapter block pointer.
1971 *
1972 * Returns:
1973 * 0 = success.
1974 * 1 = error.
1975 * 2 = database was full and device was not configured.
1976 */
1977static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001978qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979{
1980 int rval;
1981 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001982 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 rval = QLA_SUCCESS;
1984
1985 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001986 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
1987 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 if (rval != QLA_SUCCESS) {
1989 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001990 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 return (rval);
1992 }
1993 }
1994
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001995 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001997 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998
1999 /*
2000 * If we have both an RSCN and PORT UPDATE pending then handle them
2001 * both at the same time.
2002 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002003 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2004 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005
2006 /* Determine what we need to do */
2007 if (ha->current_topology == ISP_CFG_FL &&
2008 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2009
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002010 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 set_bit(RSCN_UPDATE, &flags);
2012
2013 } else if (ha->current_topology == ISP_CFG_F &&
2014 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2015
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002016 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 set_bit(RSCN_UPDATE, &flags);
2018 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2019
Andrew Vasquez21333b42006-05-17 15:09:56 -07002020 } else if (ha->current_topology == ISP_CFG_N) {
2021 clear_bit(RSCN_UPDATE, &flags);
2022
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002023 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2025
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002026 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 set_bit(RSCN_UPDATE, &flags);
2028 set_bit(LOCAL_LOOP_UPDATE, &flags);
2029 }
2030
2031 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002032 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002034 else
2035 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 }
2037
2038 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002039 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002041 else
2042 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 }
2044
2045 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002046 if (atomic_read(&vha->loop_down_timer) ||
2047 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 rval = QLA_FUNCTION_FAILED;
2049 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002050 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002052 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 }
2054 }
2055
2056 if (rval) {
2057 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002058 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 } else {
2060 DEBUG3(printk("%s: exiting normally\n", __func__));
2061 }
2062
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002063 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002064 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002066 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002067 if (test_bit(RSCN_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002068 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 }
2070
2071 return (rval);
2072}
2073
2074
2075
2076/*
2077 * qla2x00_configure_local_loop
2078 * Updates Fibre Channel Device Database with local loop devices.
2079 *
2080 * Input:
2081 * ha = adapter block pointer.
2082 *
2083 * Returns:
2084 * 0 = success.
2085 */
2086static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002087qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088{
2089 int rval, rval2;
2090 int found_devs;
2091 int found;
2092 fc_port_t *fcport, *new_fcport;
2093
2094 uint16_t index;
2095 uint16_t entries;
2096 char *id_iter;
2097 uint16_t loop_id;
2098 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002099 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
2101 found_devs = 0;
2102 new_fcport = NULL;
2103 entries = MAX_FIBRE_DEVICES;
2104
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002105 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2106 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107
2108 /* Get list of logged in devices. */
2109 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002110 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 &entries);
2112 if (rval != QLA_SUCCESS)
2113 goto cleanup_allocation;
2114
2115 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07002116 vha->host_no, entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2118 entries * sizeof(struct gid_list_info)));
2119
2120 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002121 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 if (new_fcport == NULL) {
2123 rval = QLA_MEMORY_ALLOC_FAILED;
2124 goto cleanup_allocation;
2125 }
2126 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2127
2128 /*
2129 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2130 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002131 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2133 fcport->port_type != FCT_BROADCAST &&
2134 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2135
2136 DEBUG(printk("scsi(%ld): Marking port lost, "
2137 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002138 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139
2140 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 }
2142 }
2143
2144 /* Add devices to port list. */
2145 id_iter = (char *)ha->gid_list;
2146 for (index = 0; index < entries; index++) {
2147 domain = ((struct gid_list_info *)id_iter)->domain;
2148 area = ((struct gid_list_info *)id_iter)->area;
2149 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002150 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 loop_id = (uint16_t)
2152 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002153 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 loop_id = le16_to_cpu(
2155 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002156 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157
2158 /* Bypass reserved domain fields. */
2159 if ((domain & 0xf0) == 0xf0)
2160 continue;
2161
2162 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002163 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002164 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 continue;
2166
2167 /* Bypass invalid local loop ID. */
2168 if (loop_id > LAST_LOCAL_LOOP_ID)
2169 continue;
2170
2171 /* Fill in member data. */
2172 new_fcport->d_id.b.domain = domain;
2173 new_fcport->d_id.b.area = area;
2174 new_fcport->d_id.b.al_pa = al_pa;
2175 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002176 new_fcport->vp_idx = vha->vp_idx;
2177 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 if (rval2 != QLA_SUCCESS) {
2179 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2180 "information -- get_port_database=%x, "
2181 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002182 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002183 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002184 vha->host_no));
2185 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 continue;
2187 }
2188
2189 /* Check for matching device in port list. */
2190 found = 0;
2191 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002192 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 if (memcmp(new_fcport->port_name, fcport->port_name,
2194 WWN_SIZE))
2195 continue;
2196
Shyam Sundarddb9b122009-03-24 09:08:10 -07002197 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 fcport->loop_id = new_fcport->loop_id;
2199 fcport->port_type = new_fcport->port_type;
2200 fcport->d_id.b24 = new_fcport->d_id.b24;
2201 memcpy(fcport->node_name, new_fcport->node_name,
2202 WWN_SIZE);
2203
2204 found++;
2205 break;
2206 }
2207
2208 if (!found) {
2209 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002210 if (vha->vp_idx) {
2211 new_fcport->vha = vha;
2212 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002213 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002214 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215
2216 /* Allocate a new replacement fcport. */
2217 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002218 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 if (new_fcport == NULL) {
2220 rval = QLA_MEMORY_ALLOC_FAILED;
2221 goto cleanup_allocation;
2222 }
2223 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2224 }
2225
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002226 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002227 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002228
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002229 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230
2231 found_devs++;
2232 }
2233
2234cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002235 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236
2237 if (rval != QLA_SUCCESS) {
2238 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002239 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 }
2241
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 return (rval);
2243}
2244
2245static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002246qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002247{
2248#define LS_UNKNOWN 2
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002249 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002250 int rval;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002251 uint16_t mb[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002252 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002253
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002254 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002255 return;
2256
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002257 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2258 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002259 return;
2260
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002261 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002262 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002263 if (rval != QLA_SUCCESS) {
2264 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2265 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002266 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002267 fcport->port_name[2], fcport->port_name[3],
2268 fcport->port_name[4], fcport->port_name[5],
2269 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002270 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002271 } else {
2272 DEBUG2(qla_printk(KERN_INFO, ha,
2273 "iIDMA adjusted to %s GB/s on "
2274 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002275 link_speeds[fcport->fp_speed], fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002276 fcport->port_name[1], fcport->port_name[2],
2277 fcport->port_name[3], fcport->port_name[4],
2278 fcport->port_name[5], fcport->port_name[6],
2279 fcport->port_name[7]));
2280 }
2281}
2282
Adrian Bunk23be3312006-11-24 02:46:01 +01002283static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002284qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002285{
2286 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002287 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002288 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05002289
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002290 if (fcport->drport)
2291 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002292
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002293 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2294 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002295 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2296 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2297 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002298 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002299 if (!rport) {
2300 qla_printk(KERN_WARNING, ha,
2301 "Unable to allocate fc remote port!\n");
2302 return;
2303 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002304 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002305 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002306 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002307
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002308 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002309
2310 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002311 if (fcport->port_type == FCT_INITIATOR)
2312 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2313 if (fcport->port_type == FCT_TARGET)
2314 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002315 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002316}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317
2318/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002319 * qla2x00_update_fcport
2320 * Updates device on list.
2321 *
2322 * Input:
2323 * ha = adapter block pointer.
2324 * fcport = port structure pointer.
2325 *
2326 * Return:
2327 * 0 - Success
2328 * BIT_0 - error
2329 *
2330 * Context:
2331 * Kernel context.
2332 */
2333void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002334qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002335{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002336 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002337
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002338 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002339 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002340 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002341 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002342 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002343 PORT_RETRY_TIME);
2344 fcport->flags &= ~FCF_LOGIN_NEEDED;
2345
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002346 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002347
2348 atomic_set(&fcport->state, FCS_ONLINE);
2349
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002350 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002351}
2352
2353/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 * qla2x00_configure_fabric
2355 * Setup SNS devices with loop ID's.
2356 *
2357 * Input:
2358 * ha = adapter block pointer.
2359 *
2360 * Returns:
2361 * 0 = success.
2362 * BIT_0 = error
2363 */
2364static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002365qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366{
2367 int rval, rval2;
2368 fc_port_t *fcport, *fcptemp;
2369 uint16_t next_loopid;
2370 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002371 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002373 struct qla_hw_data *ha = vha->hw;
2374 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375
2376 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002377 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002378 loop_id = NPH_F_PORT;
2379 else
2380 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002381 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 if (rval != QLA_SUCCESS) {
2383 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002384 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002386 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 return (QLA_SUCCESS);
2388 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002389 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390
2391 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002392 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 if (rval2 == QLA_RSCNS_HANDLED) {
2394 /* No point doing the scan, just continue. */
2395 return (QLA_SUCCESS);
2396 }
2397 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002398 /* FDMI support. */
2399 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002400 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2401 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002402
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002404 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002405 loop_id = NPH_SNS;
2406 else
2407 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002408 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002409 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 if (mb[0] != MBS_COMMAND_COMPLETE) {
2411 DEBUG2(qla_printk(KERN_INFO, ha,
2412 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002413 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 mb[0], mb[1], mb[2], mb[6], mb[7]));
2415 return (QLA_SUCCESS);
2416 }
2417
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002418 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2419 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 /* EMPTY */
2421 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002422 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002424 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 /* EMPTY */
2426 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002427 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002429 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 /* EMPTY */
2431 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002432 "failed.\n", vha->host_no));
2433 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 /* EMPTY */
2435 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002436 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 }
2438 }
2439
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002440 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 if (rval != QLA_SUCCESS)
2442 break;
2443
2444 /*
2445 * Logout all previous fabric devices marked lost, except
2446 * tape devices.
2447 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002448 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2449 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 break;
2451
2452 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2453 continue;
2454
2455 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002456 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002457 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 if (fcport->loop_id != FC_NO_LOOP_ID &&
2459 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2460 fcport->port_type != FCT_INITIATOR &&
2461 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002462 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002463 fcport->loop_id,
2464 fcport->d_id.b.domain,
2465 fcport->d_id.b.area,
2466 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 fcport->loop_id = FC_NO_LOOP_ID;
2468 }
2469 }
2470 }
2471
2472 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002473 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474
2475 /*
2476 * Scan through our port list and login entries that need to be
2477 * logged in.
2478 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002479 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2480 if (atomic_read(&vha->loop_down_timer) ||
2481 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 break;
2483
2484 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2485 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2486 continue;
2487
2488 if (fcport->loop_id == FC_NO_LOOP_ID) {
2489 fcport->loop_id = next_loopid;
Seokmann Jud4486fd62008-04-03 13:13:28 -07002490 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002491 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 if (rval != QLA_SUCCESS) {
2493 /* Ran out of IDs to use */
2494 break;
2495 }
2496 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002498 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 }
2500
2501 /* Exit if out of loop IDs. */
2502 if (rval != QLA_SUCCESS) {
2503 break;
2504 }
2505
2506 /*
2507 * Login and add the new devices to our port list.
2508 */
2509 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002510 if (atomic_read(&vha->loop_down_timer) ||
2511 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 break;
2513
2514 /* Find a new loop ID to use. */
2515 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002516 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 if (rval != QLA_SUCCESS) {
2518 /* Ran out of IDs to use */
2519 break;
2520 }
2521
bdf79622005-04-17 15:06:53 -05002522 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002523 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002524
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002525 if (vha->vp_idx) {
2526 fcport->vha = vha;
2527 fcport->vp_idx = vha->vp_idx;
2528 }
2529 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 }
2531 } while (0);
2532
2533 /* Free all new device structures not processed. */
2534 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2535 list_del(&fcport->list);
2536 kfree(fcport);
2537 }
2538
2539 if (rval) {
2540 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002541 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 }
2543
2544 return (rval);
2545}
2546
2547
2548/*
2549 * qla2x00_find_all_fabric_devs
2550 *
2551 * Input:
2552 * ha = adapter block pointer.
2553 * dev = database device entry pointer.
2554 *
2555 * Returns:
2556 * 0 = success.
2557 *
2558 * Context:
2559 * Kernel context.
2560 */
2561static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002562qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2563 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564{
2565 int rval;
2566 uint16_t loop_id;
2567 fc_port_t *fcport, *new_fcport, *fcptemp;
2568 int found;
2569
2570 sw_info_t *swl;
2571 int swl_idx;
2572 int first_dev, last_dev;
2573 port_id_t wrap, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002574 struct qla_hw_data *ha = vha->hw;
2575 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002576 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577
2578 rval = QLA_SUCCESS;
2579
2580 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07002581 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002582 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 /*EMPTY*/
2584 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002585 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002587 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 kfree(swl);
2589 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002590 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 kfree(swl);
2592 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002593 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 kfree(swl);
2595 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07002596 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002597 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2598 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 }
2600 }
2601 swl_idx = 0;
2602
2603 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002604 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002606 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 return (QLA_MEMORY_ALLOC_FAILED);
2608 }
2609 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 /* Set start port ID scan at adapter ID. */
2611 first_dev = 1;
2612 last_dev = 0;
2613
2614 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002615 loop_id = ha->min_external_loopid;
2616 for (; loop_id <= ha->max_loop_id; loop_id++) {
2617 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 continue;
2619
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002620 if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 break;
2622
2623 if (swl != NULL) {
2624 if (last_dev) {
2625 wrap.b24 = new_fcport->d_id.b24;
2626 } else {
2627 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2628 memcpy(new_fcport->node_name,
2629 swl[swl_idx].node_name, WWN_SIZE);
2630 memcpy(new_fcport->port_name,
2631 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002632 memcpy(new_fcport->fabric_port_name,
2633 swl[swl_idx].fabric_port_name, WWN_SIZE);
2634 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635
2636 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2637 last_dev = 1;
2638 }
2639 swl_idx++;
2640 }
2641 } else {
2642 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002643 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 if (rval != QLA_SUCCESS) {
2645 qla_printk(KERN_WARNING, ha,
2646 "SNS scan failed -- assuming zero-entry "
2647 "result...\n");
2648 list_for_each_entry_safe(fcport, fcptemp,
2649 new_fcports, list) {
2650 list_del(&fcport->list);
2651 kfree(fcport);
2652 }
2653 rval = QLA_SUCCESS;
2654 break;
2655 }
2656 }
2657
2658 /* If wrap on switch device list, exit. */
2659 if (first_dev) {
2660 wrap.b24 = new_fcport->d_id.b24;
2661 first_dev = 0;
2662 } else if (new_fcport->d_id.b24 == wrap.b24) {
2663 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002664 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2666 break;
2667 }
2668
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002669 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002670 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 continue;
2672
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002673 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002674 found = 0;
2675 if (ha->num_vhosts) {
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002676 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002677 if (new_fcport->d_id.b24 == vp->d_id.b24) {
2678 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002679 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002680 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002681 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002682 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002683 continue;
2684 }
2685
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002686 /* Bypass if same domain and area of adapter. */
2687 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002688 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002689 ISP_CFG_FL)
2690 continue;
2691
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 /* Bypass reserved domain fields. */
2693 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2694 continue;
2695
2696 /* Locate matching device in database. */
2697 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002698 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699 if (memcmp(new_fcport->port_name, fcport->port_name,
2700 WWN_SIZE))
2701 continue;
2702
2703 found++;
2704
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002705 /* Update port state. */
2706 memcpy(fcport->fabric_port_name,
2707 new_fcport->fabric_port_name, WWN_SIZE);
2708 fcport->fp_speed = new_fcport->fp_speed;
2709
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 /*
2711 * If address the same and state FCS_ONLINE, nothing
2712 * changed.
2713 */
2714 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2715 atomic_read(&fcport->state) == FCS_ONLINE) {
2716 break;
2717 }
2718
2719 /*
2720 * If device was not a fabric device before.
2721 */
2722 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2723 fcport->d_id.b24 = new_fcport->d_id.b24;
2724 fcport->loop_id = FC_NO_LOOP_ID;
2725 fcport->flags |= (FCF_FABRIC_DEVICE |
2726 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 break;
2728 }
2729
2730 /*
2731 * Port ID changed or device was marked to be updated;
2732 * Log it out if still logged in and mark it for
2733 * relogin later.
2734 */
2735 fcport->d_id.b24 = new_fcport->d_id.b24;
2736 fcport->flags |= FCF_LOGIN_NEEDED;
2737 if (fcport->loop_id != FC_NO_LOOP_ID &&
2738 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2739 fcport->port_type != FCT_INITIATOR &&
2740 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002741 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002742 fcport->d_id.b.domain, fcport->d_id.b.area,
2743 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 fcport->loop_id = FC_NO_LOOP_ID;
2745 }
2746
2747 break;
2748 }
2749
2750 if (found)
2751 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 /* If device was not in our fcports list, then add it. */
2753 list_add_tail(&new_fcport->list, new_fcports);
2754
2755 /* Allocate a new replacement fcport. */
2756 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002757 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002759 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 return (QLA_MEMORY_ALLOC_FAILED);
2761 }
2762 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2763 new_fcport->d_id.b24 = nxt_d_id.b24;
2764 }
2765
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002766 kfree(swl);
2767 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 return (rval);
2770}
2771
2772/*
2773 * qla2x00_find_new_loop_id
2774 * Scan through our port list and find a new usable loop ID.
2775 *
2776 * Input:
2777 * ha: adapter state pointer.
2778 * dev: port structure pointer.
2779 *
2780 * Returns:
2781 * qla2x00 local function return status code.
2782 *
2783 * Context:
2784 * Kernel context.
2785 */
Adrian Bunk413975a2006-06-30 02:33:06 -07002786static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002787qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788{
2789 int rval;
2790 int found;
2791 fc_port_t *fcport;
2792 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002793 struct qla_hw_data *ha = vha->hw;
2794 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002795 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796
2797 rval = QLA_SUCCESS;
2798
2799 /* Save starting loop ID. */
2800 first_loop_id = dev->loop_id;
2801
2802 for (;;) {
2803 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002804 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806
2807 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002808 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810
2811 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002812 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 /* first loop ID. */
2814 dev->loop_id = ha->min_external_loopid;
2815 }
2816
2817 /* Check for loop ID being already in use. */
2818 found = 0;
2819 fcport = NULL;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002820 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002821 list_for_each_entry(fcport, &vp->vp_fcports, list) {
2822 if (fcport->loop_id == dev->loop_id &&
2823 fcport != dev) {
2824 /* ID possibly in use */
2825 found++;
2826 break;
2827 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002829 if (found)
2830 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 }
2832
2833 /* If not in use then it is free to use. */
2834 if (!found) {
2835 break;
2836 }
2837
2838 /* ID in use. Try next value. */
2839 dev->loop_id++;
2840
2841 /* If wrap around. No free ID to use. */
2842 if (dev->loop_id == first_loop_id) {
2843 dev->loop_id = FC_NO_LOOP_ID;
2844 rval = QLA_FUNCTION_FAILED;
2845 break;
2846 }
2847 }
2848
2849 return (rval);
2850}
2851
2852/*
2853 * qla2x00_device_resync
2854 * Marks devices in the database that needs resynchronization.
2855 *
2856 * Input:
2857 * ha = adapter block pointer.
2858 *
2859 * Context:
2860 * Kernel context.
2861 */
2862static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002863qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864{
2865 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 uint32_t mask;
2867 fc_port_t *fcport;
2868 uint32_t rscn_entry;
2869 uint8_t rscn_out_iter;
2870 uint8_t format;
2871 port_id_t d_id;
2872
2873 rval = QLA_RSCNS_HANDLED;
2874
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002875 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
2876 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002878 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 format = MSB(MSW(rscn_entry));
2880 d_id.b.domain = LSB(MSW(rscn_entry));
2881 d_id.b.area = MSB(LSW(rscn_entry));
2882 d_id.b.al_pa = LSB(LSW(rscn_entry));
2883
2884 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2885 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002886 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 d_id.b.area, d_id.b.al_pa));
2888
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002889 vha->rscn_out_ptr++;
2890 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
2891 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892
2893 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002894 for (rscn_out_iter = vha->rscn_out_ptr;
2895 !vha->flags.rscn_queue_overflow &&
2896 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 rscn_out_iter = (rscn_out_iter ==
2898 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2899
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002900 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 break;
2902
2903 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002904 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 rscn_out_iter));
2906
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002907 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908 }
2909
2910 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002911 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002913 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914
2915 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002916 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 }
2918
2919 switch (format) {
2920 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 mask = 0xffffff;
2922 break;
2923 case 1:
2924 mask = 0xffff00;
2925 break;
2926 case 2:
2927 mask = 0xff0000;
2928 break;
2929 default:
2930 mask = 0x0;
2931 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002932 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 break;
2934 }
2935
2936 rval = QLA_SUCCESS;
2937
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002938 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2940 (fcport->d_id.b24 & mask) != d_id.b24 ||
2941 fcport->port_type == FCT_BROADCAST)
2942 continue;
2943
2944 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2945 if (format != 3 ||
2946 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002947 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002948 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 }
2950 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 }
2952 }
2953 return (rval);
2954}
2955
2956/*
2957 * qla2x00_fabric_dev_login
2958 * Login fabric target device and update FC port database.
2959 *
2960 * Input:
2961 * ha: adapter state pointer.
2962 * fcport: port structure list pointer.
2963 * next_loopid: contains value of a new loop ID that can be used
2964 * by the next login attempt.
2965 *
2966 * Returns:
2967 * qla2x00 local function return status code.
2968 *
2969 * Context:
2970 * Kernel context.
2971 */
2972static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002973qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 uint16_t *next_loopid)
2975{
2976 int rval;
2977 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002978 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002979 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980
2981 rval = QLA_SUCCESS;
2982 retry = 0;
2983
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002984 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 if (rval == QLA_SUCCESS) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002986 /* Send an ADISC to tape devices.*/
2987 opts = 0;
2988 if (fcport->flags & FCF_TAPE_PRESENT)
2989 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002990 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002992 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002993 fcport->d_id.b.domain, fcport->d_id.b.area,
2994 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002995 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002997 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 }
2999 }
3000
3001 return (rval);
3002}
3003
3004/*
3005 * qla2x00_fabric_login
3006 * Issue fabric login command.
3007 *
3008 * Input:
3009 * ha = adapter block pointer.
3010 * device = pointer to FC device type structure.
3011 *
3012 * Returns:
3013 * 0 - Login successfully
3014 * 1 - Login failed
3015 * 2 - Initiator device
3016 * 3 - Fatal error
3017 */
3018int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003019qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 uint16_t *next_loopid)
3021{
3022 int rval;
3023 int retry;
3024 uint16_t tmp_loopid;
3025 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003026 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027
3028 retry = 0;
3029 tmp_loopid = 0;
3030
3031 for (;;) {
3032 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3033 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003034 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3036
3037 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003038 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 fcport->d_id.b.domain, fcport->d_id.b.area,
3040 fcport->d_id.b.al_pa, mb, BIT_0);
3041 if (mb[0] == MBS_PORT_ID_USED) {
3042 /*
3043 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003044 * recommends the driver perform an implicit login with
3045 * the specified ID again. The ID we just used is save
3046 * here so we return with an ID that can be tried by
3047 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048 */
3049 retry++;
3050 tmp_loopid = fcport->loop_id;
3051 fcport->loop_id = mb[1];
3052
3053 DEBUG(printk("Fabric Login: port in use - next "
3054 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3055 fcport->loop_id, fcport->d_id.b.domain,
3056 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3057
3058 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3059 /*
3060 * Login succeeded.
3061 */
3062 if (retry) {
3063 /* A retry occurred before. */
3064 *next_loopid = tmp_loopid;
3065 } else {
3066 /*
3067 * No retry occurred before. Just increment the
3068 * ID value for next login.
3069 */
3070 *next_loopid = (fcport->loop_id + 1);
3071 }
3072
3073 if (mb[1] & BIT_0) {
3074 fcport->port_type = FCT_INITIATOR;
3075 } else {
3076 fcport->port_type = FCT_TARGET;
3077 if (mb[1] & BIT_1) {
3078 fcport->flags |= FCF_TAPE_PRESENT;
3079 }
3080 }
3081
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003082 if (mb[10] & BIT_0)
3083 fcport->supported_classes |= FC_COS_CLASS2;
3084 if (mb[10] & BIT_1)
3085 fcport->supported_classes |= FC_COS_CLASS3;
3086
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 rval = QLA_SUCCESS;
3088 break;
3089 } else if (mb[0] == MBS_LOOP_ID_USED) {
3090 /*
3091 * Loop ID already used, try next loop ID.
3092 */
3093 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003094 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095 if (rval != QLA_SUCCESS) {
3096 /* Ran out of loop IDs to use */
3097 break;
3098 }
3099 } else if (mb[0] == MBS_COMMAND_ERROR) {
3100 /*
3101 * Firmware possibly timed out during login. If NO
3102 * retries are left to do then the device is declared
3103 * dead.
3104 */
3105 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003106 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003107 fcport->d_id.b.domain, fcport->d_id.b.area,
3108 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003109 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110
3111 rval = 1;
3112 break;
3113 } else {
3114 /*
3115 * unrecoverable / not handled error
3116 */
3117 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003118 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003119 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 fcport->d_id.b.domain, fcport->d_id.b.area,
3121 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3122
3123 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003124 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003125 fcport->d_id.b.domain, fcport->d_id.b.area,
3126 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003128 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129
3130 rval = 3;
3131 break;
3132 }
3133 }
3134
3135 return (rval);
3136}
3137
3138/*
3139 * qla2x00_local_device_login
3140 * Issue local device login command.
3141 *
3142 * Input:
3143 * ha = adapter block pointer.
3144 * loop_id = loop id of device to login to.
3145 *
3146 * Returns (Where's the #define!!!!):
3147 * 0 - Login successfully
3148 * 1 - Login failed
3149 * 3 - Fatal error
3150 */
3151int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003152qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153{
3154 int rval;
3155 uint16_t mb[MAILBOX_REGISTER_COUNT];
3156
3157 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003158 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159 if (rval == QLA_SUCCESS) {
3160 /* Interrogate mailbox registers for any errors */
3161 if (mb[0] == MBS_COMMAND_ERROR)
3162 rval = 1;
3163 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3164 /* device not in PCB table */
3165 rval = 3;
3166 }
3167
3168 return (rval);
3169}
3170
3171/*
3172 * qla2x00_loop_resync
3173 * Resync with fibre channel devices.
3174 *
3175 * Input:
3176 * ha = adapter block pointer.
3177 *
3178 * Returns:
3179 * 0 = success
3180 */
3181int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003182qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003184 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003186 struct req_que *req;
3187 struct rsp_que *rsp;
3188
3189 if (ql2xmultique_tag)
3190 req = vha->hw->req_q_map[0];
3191 else
3192 req = vha->req;
3193 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003195 atomic_set(&vha->loop_state, LOOP_UPDATE);
3196 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3197 if (vha->flags.online) {
3198 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3200 wait_time = 256;
3201 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003202 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003204 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003205 qla2x00_marker(vha, req, rsp, 0, 0,
3206 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003207 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208
3209 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003210 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003212 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003214 } while (!atomic_read(&vha->loop_down_timer) &&
3215 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3216 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3217 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 }
3220
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003221 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003224 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226
3227 return (rval);
3228}
3229
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003231qla2x00_update_fcports(scsi_qla_host_t *vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003232{
3233 fc_port_t *fcport;
3234
3235 /* Go with deferred removal of rport references. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003236 list_for_each_entry(fcport, &vha->vp_fcports, list)
3237 if (fcport && fcport->drport &&
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07003238 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003239 qla2x00_rport_del(fcport);
3240}
3241
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242/*
3243* qla2x00_abort_isp
3244* Resets ISP and aborts all outstanding commands.
3245*
3246* Input:
3247* ha = adapter block pointer.
3248*
3249* Returns:
3250* 0 = success
3251*/
3252int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003253qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003255 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003257 struct qla_hw_data *ha = vha->hw;
3258 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003259 struct scsi_qla_host *tvp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003260 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003262 if (vha->flags.online) {
3263 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -07003264 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003265 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07003266 ha->qla_stats.total_isp_aborts++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267
3268 qla_printk(KERN_INFO, ha,
3269 "Performing ISP error recovery - ha= %p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003270 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003272 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3273 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3274 atomic_set(&vha->loop_state, LOOP_DOWN);
3275 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003276 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003277 qla2x00_mark_all_devices_lost(vp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003279 if (!atomic_read(&vha->loop_down_timer))
3280 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281 LOOP_DOWN_TIME);
3282 }
3283
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 /* Requeue all commands in outstanding command list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003285 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003287 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003288
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003289 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003291 if (!qla2x00_restart_isp(vha)) {
3292 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003294 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295 /*
3296 * Issue marker command only when we are going
3297 * to start the I/O .
3298 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003299 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300 }
3301
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003302 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003304 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003306 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003307 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003308
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003309 if (ha->fce) {
3310 ha->flags.fce_enabled = 1;
3311 memset(ha->fce, 0,
3312 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003313 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003314 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3315 &ha->fce_bufs);
3316 if (rval) {
3317 qla_printk(KERN_WARNING, ha,
3318 "Unable to reinitialize FCE "
3319 "(%d).\n", rval);
3320 ha->flags.fce_enabled = 0;
3321 }
3322 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003323
3324 if (ha->eft) {
3325 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003326 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003327 ha->eft_dma, EFT_NUM_BUFFERS);
3328 if (rval) {
3329 qla_printk(KERN_WARNING, ha,
3330 "Unable to reinitialize EFT "
3331 "(%d).\n", rval);
3332 }
3333 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003335 vha->flags.online = 1;
3336 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337 if (ha->isp_abort_cnt == 0) {
3338 qla_printk(KERN_WARNING, ha,
3339 "ISP error recovery failed - "
3340 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003341 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342 * The next call disables the board
3343 * completely.
3344 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003345 ha->isp_ops->reset_adapter(vha);
3346 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003347 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003348 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 status = 0;
3350 } else { /* schedule another ISP abort */
3351 ha->isp_abort_cnt--;
3352 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003353 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003354 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 status = 1;
3356 }
3357 } else {
3358 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3359 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3360 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003361 vha->host_no, ha->isp_abort_cnt));
3362 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363 status = 1;
3364 }
3365 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003366
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367 }
3368
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003369 if (!status) {
3370 DEBUG(printk(KERN_INFO
3371 "qla2x00_abort_isp(%ld): succeeded.\n",
3372 vha->host_no));
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003373 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003374 if (vp->vp_idx)
3375 qla2x00_vp_abort_isp(vp);
3376 }
3377 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378 qla_printk(KERN_INFO, ha,
3379 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 }
3381
3382 return(status);
3383}
3384
3385/*
3386* qla2x00_restart_isp
3387* restarts the ISP after a reset
3388*
3389* Input:
3390* ha = adapter block pointer.
3391*
3392* Returns:
3393* 0 = success
3394*/
3395static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003396qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003398 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003400 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003401 struct req_que *req = ha->req_q_map[0];
3402 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403
3404 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003405 if (qla2x00_isp_firmware(vha)) {
3406 vha->flags.online = 0;
3407 status = ha->isp_ops->chip_diag(vha);
3408 if (!status)
3409 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 }
3411
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003412 if (!status && !(status = qla2x00_init_rings(vha))) {
3413 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07003414 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003415 /* Initialize the queues in use */
3416 qla25xx_init_queues(ha);
3417
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003418 status = qla2x00_fw_ready(vha);
3419 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003421 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003422
3423 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003424 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003425
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003426 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3428 wait_time = 256;
3429 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003430 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3431 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003433 } while (!atomic_read(&vha->loop_down_timer) &&
3434 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3435 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3436 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 }
3438
3439 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003440 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441 status = 0;
3442
3443 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3444 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003445 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446 }
3447 return (status);
3448}
3449
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003450static int
3451qla25xx_init_queues(struct qla_hw_data *ha)
3452{
3453 struct rsp_que *rsp = NULL;
3454 struct req_que *req = NULL;
3455 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3456 int ret = -1;
3457 int i;
3458
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003459 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003460 rsp = ha->rsp_q_map[i];
3461 if (rsp) {
3462 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003463 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003464 if (ret != QLA_SUCCESS)
3465 DEBUG2_17(printk(KERN_WARNING
3466 "%s Rsp que:%d init failed\n", __func__,
3467 rsp->id));
3468 else
3469 DEBUG2_17(printk(KERN_INFO
3470 "%s Rsp que:%d inited\n", __func__,
3471 rsp->id));
3472 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003473 }
3474 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003475 req = ha->req_q_map[i];
3476 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003477 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003478 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003479 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003480 if (ret != QLA_SUCCESS)
3481 DEBUG2_17(printk(KERN_WARNING
3482 "%s Req que:%d init failed\n", __func__,
3483 req->id));
3484 else
3485 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003486 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003487 req->id));
3488 }
3489 }
3490 return ret;
3491}
3492
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493/*
3494* qla2x00_reset_adapter
3495* Reset adapter.
3496*
3497* Input:
3498* ha = adapter block pointer.
3499*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003500void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003501qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003502{
3503 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003504 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003505 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003506
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003507 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003508 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003509
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510 spin_lock_irqsave(&ha->hardware_lock, flags);
3511 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3512 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3513 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3514 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3515 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3516}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003517
3518void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003519qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003520{
3521 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003522 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003523 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3524
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003525 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003526 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003527
3528 spin_lock_irqsave(&ha->hardware_lock, flags);
3529 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3530 RD_REG_DWORD(&reg->hccr);
3531 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3532 RD_REG_DWORD(&reg->hccr);
3533 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08003534
3535 if (IS_NOPOLLING_TYPE(ha))
3536 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003537}
3538
David Miller4e08df32007-04-16 12:37:43 -07003539/* On sparc systems, obtain port and node WWN from firmware
3540 * properties.
3541 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003542static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3543 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07003544{
3545#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003546 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003547 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003548 struct device_node *dp = pci_device_to_OF_node(pdev);
3549 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003550 int len;
3551
3552 val = of_get_property(dp, "port-wwn", &len);
3553 if (val && len >= WWN_SIZE)
3554 memcpy(nv->port_name, val, WWN_SIZE);
3555
3556 val = of_get_property(dp, "node-wwn", &len);
3557 if (val && len >= WWN_SIZE)
3558 memcpy(nv->node_name, val, WWN_SIZE);
3559#endif
3560}
3561
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003562int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003563qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003564{
David Miller4e08df32007-04-16 12:37:43 -07003565 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003566 struct init_cb_24xx *icb;
3567 struct nvram_24xx *nv;
3568 uint32_t *dptr;
3569 uint8_t *dptr1, *dptr2;
3570 uint32_t chksum;
3571 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003572 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003573
David Miller4e08df32007-04-16 12:37:43 -07003574 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003575 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003576 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003577
3578 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07003579 if (ha->flags.port0) {
3580 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3581 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3582 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003583 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003584 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3585 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07003586 ha->nvram_size = sizeof(struct nvram_24xx);
3587 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003588
Seokmann Ju281afe12007-07-26 13:43:34 -07003589 /* Get VPD data into cache */
3590 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003591 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07003592 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3593
3594 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003595 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003596 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003597 ha->nvram_size);
3598 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3599 chksum += le32_to_cpu(*dptr++);
3600
Andrew Vasquez76403352009-04-06 22:33:39 -07003601 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07003602 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003603
3604 /* Bad NVRAM data, set defaults parameters. */
3605 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3606 || nv->id[3] != ' ' ||
3607 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3608 /* Reset NVRAM data. */
3609 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3610 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3611 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07003612 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3613 "invalid -- WWPN) defaults.\n");
3614
3615 /*
3616 * Set default initialization control block.
3617 */
3618 memset(nv, 0, ha->nvram_size);
3619 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3620 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3621 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3622 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3623 nv->exchange_count = __constant_cpu_to_le16(0);
3624 nv->hard_address = __constant_cpu_to_le16(124);
3625 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07003626 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07003627 nv->port_name[2] = 0x00;
3628 nv->port_name[3] = 0xe0;
3629 nv->port_name[4] = 0x8b;
3630 nv->port_name[5] = 0x1c;
3631 nv->port_name[6] = 0x55;
3632 nv->port_name[7] = 0x86;
3633 nv->node_name[0] = 0x20;
3634 nv->node_name[1] = 0x00;
3635 nv->node_name[2] = 0x00;
3636 nv->node_name[3] = 0xe0;
3637 nv->node_name[4] = 0x8b;
3638 nv->node_name[5] = 0x1c;
3639 nv->node_name[6] = 0x55;
3640 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003641 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07003642 nv->login_retry_count = __constant_cpu_to_le16(8);
3643 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3644 nv->login_timeout = __constant_cpu_to_le16(0);
3645 nv->firmware_options_1 =
3646 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3647 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3648 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3649 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3650 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3651 nv->efi_parameters = __constant_cpu_to_le32(0);
3652 nv->reset_delay = 5;
3653 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3654 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3655 nv->link_down_timeout = __constant_cpu_to_le16(30);
3656
3657 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003658 }
3659
3660 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003661 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003662
3663 /* Copy 1st segment. */
3664 dptr1 = (uint8_t *)icb;
3665 dptr2 = (uint8_t *)&nv->version;
3666 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3667 while (cnt--)
3668 *dptr1++ = *dptr2++;
3669
3670 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07003671 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003672
3673 /* Copy 2nd segment. */
3674 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3675 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3676 cnt = (uint8_t *)&icb->reserved_3 -
3677 (uint8_t *)&icb->interrupt_delay_timer;
3678 while (cnt--)
3679 *dptr1++ = *dptr2++;
3680
3681 /*
3682 * Setup driver NVRAM options.
3683 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003684 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003685 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003686
Andrew Vasquez5341e862006-05-17 15:09:16 -07003687 /* Use alternate WWN? */
3688 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3689 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3690 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3691 }
3692
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003693 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003694 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003695 /*
3696 * Firmware will apply the following mask if the nodename was
3697 * not provided.
3698 */
3699 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3700 icb->node_name[0] &= 0xF0;
3701 }
3702
3703 /* Set host adapter parameters. */
3704 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08003705 ha->flags.enable_lip_reset = 0;
3706 ha->flags.enable_lip_full_login =
3707 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3708 ha->flags.enable_target_reset =
3709 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003710 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07003711 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003712
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003713 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3714 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003715
3716 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3717 sizeof(ha->fw_seriallink_options24));
3718
3719 /* save HBA serial number */
3720 ha->serial0 = icb->port_name[5];
3721 ha->serial1 = icb->port_name[6];
3722 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003723 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
3724 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003725
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08003726 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3727
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003728 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3729
3730 /* Set minimum login_timeout to 4 seconds. */
3731 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3732 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3733 if (le16_to_cpu(nv->login_timeout) < 4)
3734 nv->login_timeout = __constant_cpu_to_le16(4);
3735 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07003736 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003737
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003738 /* Set minimum RATOV to 100 tenths of a second. */
3739 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003740
3741 ha->loop_reset_delay = nv->reset_delay;
3742
3743 /* Link Down Timeout = 0:
3744 *
3745 * When Port Down timer expires we will start returning
3746 * I/O's to OS with "DID_NO_CONNECT".
3747 *
3748 * Link Down Timeout != 0:
3749 *
3750 * The driver waits for the link to come up after link down
3751 * before returning I/Os to OS with "DID_NO_CONNECT".
3752 */
3753 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3754 ha->loop_down_abort_time =
3755 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3756 } else {
3757 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3758 ha->loop_down_abort_time =
3759 (LOOP_DOWN_TIME - ha->link_down_timeout);
3760 }
3761
3762 /* Need enough time to try and get the port back. */
3763 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3764 if (qlport_down_retry)
3765 ha->port_down_retry_count = qlport_down_retry;
3766
3767 /* Set login_retry_count */
3768 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3769 if (ha->port_down_retry_count ==
3770 le16_to_cpu(nv->port_down_retry_count) &&
3771 ha->port_down_retry_count > 3)
3772 ha->login_retry_count = ha->port_down_retry_count;
3773 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3774 ha->login_retry_count = ha->port_down_retry_count;
3775 if (ql2xloginretrycount)
3776 ha->login_retry_count = ql2xloginretrycount;
3777
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003778 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003779 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003780 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3781 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3782 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3783 le16_to_cpu(icb->interrupt_delay_timer): 2;
3784 }
3785 icb->firmware_options_2 &= __constant_cpu_to_le32(
3786 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003787 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003788 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08003789 ha->zio_mode = QLA_ZIO_MODE_6;
3790
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003791 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003792 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003793 ha->zio_timer * 100));
3794 qla_printk(KERN_INFO, ha,
3795 "ZIO mode %d enabled; timer delay (%d us).\n",
3796 ha->zio_mode, ha->zio_timer * 100);
3797
3798 icb->firmware_options_2 |= cpu_to_le32(
3799 (uint32_t)ha->zio_mode);
3800 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003801 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003802 }
3803
David Miller4e08df32007-04-16 12:37:43 -07003804 if (rval) {
3805 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003806 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07003807 }
3808 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003809}
3810
Adrian Bunk413975a2006-06-30 02:33:06 -07003811static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003812qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
3813 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003814{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003815 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003816 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003817 uint32_t *dcode, dlen;
3818 uint32_t risc_addr;
3819 uint32_t risc_size;
3820 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003821 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003822 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08003823
3824 qla_printk(KERN_INFO, ha,
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003825 "FW: Loading from flash (%x)...\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08003826
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003827 rval = QLA_SUCCESS;
3828
3829 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003830 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003831 *srisc_addr = 0;
3832
3833 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003834 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003835 for (i = 0; i < 4; i++)
3836 dcode[i] = be32_to_cpu(dcode[i]);
3837 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3838 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3839 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3840 dcode[3] == 0)) {
3841 qla_printk(KERN_WARNING, ha,
3842 "Unable to verify integrity of flash firmware image!\n");
3843 qla_printk(KERN_WARNING, ha,
3844 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3845 dcode[1], dcode[2], dcode[3]);
3846
3847 return QLA_FUNCTION_FAILED;
3848 }
3849
3850 while (segments && rval == QLA_SUCCESS) {
3851 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003852 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003853
3854 risc_addr = be32_to_cpu(dcode[2]);
3855 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3856 risc_size = be32_to_cpu(dcode[3]);
3857
3858 fragment = 0;
3859 while (risc_size > 0 && rval == QLA_SUCCESS) {
3860 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3861 if (dlen > risc_size)
3862 dlen = risc_size;
3863
3864 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3865 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003866 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003867
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003868 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003869 for (i = 0; i < dlen; i++)
3870 dcode[i] = swab32(dcode[i]);
3871
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003872 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003873 dlen);
3874 if (rval) {
3875 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003876 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003877 fragment));
3878 qla_printk(KERN_WARNING, ha,
3879 "[ERROR] Failed to load segment %d of "
3880 "firmware\n", fragment);
3881 break;
3882 }
3883
3884 faddr += dlen;
3885 risc_addr += dlen;
3886 risc_size -= dlen;
3887 fragment++;
3888 }
3889
3890 /* Next segment. */
3891 segments--;
3892 }
3893
3894 return rval;
3895}
3896
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003897#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3898
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003899int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003900qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08003901{
3902 int rval;
3903 int i, fragment;
3904 uint16_t *wcode, *fwcode;
3905 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3906 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003907 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003908 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08003909
3910 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003911 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08003912 if (!blob) {
3913 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003914 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3915 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08003916 return QLA_FUNCTION_FAILED;
3917 }
3918
3919 rval = QLA_SUCCESS;
3920
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003921 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08003922 *srisc_addr = 0;
3923 fwcode = (uint16_t *)blob->fw->data;
3924 fwclen = 0;
3925
3926 /* Validate firmware image by checking version. */
3927 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3928 qla_printk(KERN_WARNING, ha,
3929 "Unable to verify integrity of firmware image (%Zd)!\n",
3930 blob->fw->size);
3931 goto fail_fw_integrity;
3932 }
3933 for (i = 0; i < 4; i++)
3934 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3935 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3936 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3937 wcode[2] == 0 && wcode[3] == 0)) {
3938 qla_printk(KERN_WARNING, ha,
3939 "Unable to verify integrity of firmware image!\n");
3940 qla_printk(KERN_WARNING, ha,
3941 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3942 wcode[1], wcode[2], wcode[3]);
3943 goto fail_fw_integrity;
3944 }
3945
3946 seg = blob->segs;
3947 while (*seg && rval == QLA_SUCCESS) {
3948 risc_addr = *seg;
3949 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3950 risc_size = be16_to_cpu(fwcode[3]);
3951
3952 /* Validate firmware image size. */
3953 fwclen += risc_size * sizeof(uint16_t);
3954 if (blob->fw->size < fwclen) {
3955 qla_printk(KERN_WARNING, ha,
3956 "Unable to verify integrity of firmware image "
3957 "(%Zd)!\n", blob->fw->size);
3958 goto fail_fw_integrity;
3959 }
3960
3961 fragment = 0;
3962 while (risc_size > 0 && rval == QLA_SUCCESS) {
3963 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3964 if (wlen > risc_size)
3965 wlen = risc_size;
3966
3967 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003968 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08003969 risc_addr, wlen));
3970
3971 for (i = 0; i < wlen; i++)
3972 wcode[i] = swab16(fwcode[i]);
3973
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003974 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08003975 wlen);
3976 if (rval) {
3977 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003978 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08003979 fragment));
3980 qla_printk(KERN_WARNING, ha,
3981 "[ERROR] Failed to load segment %d of "
3982 "firmware\n", fragment);
3983 break;
3984 }
3985
3986 fwcode += wlen;
3987 risc_addr += wlen;
3988 risc_size -= wlen;
3989 fragment++;
3990 }
3991
3992 /* Next segment. */
3993 seg++;
3994 }
3995 return rval;
3996
3997fail_fw_integrity:
3998 return QLA_FUNCTION_FAILED;
3999}
4000
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004001static int
4002qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004003{
4004 int rval;
4005 int segments, fragment;
4006 uint32_t *dcode, dlen;
4007 uint32_t risc_addr;
4008 uint32_t risc_size;
4009 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004010 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004011 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004012 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004013 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004014
Andrew Vasquez54333832005-11-09 15:49:04 -08004015 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004016 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004017 if (!blob) {
4018 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004019 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4020 "from: " QLA_FW_URL ".\n");
4021
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004022 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004023 }
4024
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004025 qla_printk(KERN_INFO, ha,
4026 "FW: Loading via request-firmware...\n");
4027
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004028 rval = QLA_SUCCESS;
4029
4030 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004031 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004032 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004033 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004034 fwclen = 0;
4035
4036 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004037 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004038 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004039 "Unable to verify integrity of firmware image (%Zd)!\n",
4040 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004041 goto fail_fw_integrity;
4042 }
4043 for (i = 0; i < 4; i++)
4044 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4045 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4046 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4047 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4048 dcode[3] == 0)) {
4049 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004050 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004051 qla_printk(KERN_WARNING, ha,
4052 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4053 dcode[1], dcode[2], dcode[3]);
4054 goto fail_fw_integrity;
4055 }
4056
4057 while (segments && rval == QLA_SUCCESS) {
4058 risc_addr = be32_to_cpu(fwcode[2]);
4059 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4060 risc_size = be32_to_cpu(fwcode[3]);
4061
4062 /* Validate firmware image size. */
4063 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004064 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004065 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004066 "Unable to verify integrity of firmware image "
4067 "(%Zd)!\n", blob->fw->size);
4068
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004069 goto fail_fw_integrity;
4070 }
4071
4072 fragment = 0;
4073 while (risc_size > 0 && rval == QLA_SUCCESS) {
4074 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4075 if (dlen > risc_size)
4076 dlen = risc_size;
4077
4078 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004079 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004080 risc_addr, dlen));
4081
4082 for (i = 0; i < dlen; i++)
4083 dcode[i] = swab32(fwcode[i]);
4084
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004085 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004086 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004087 if (rval) {
4088 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004089 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004090 fragment));
4091 qla_printk(KERN_WARNING, ha,
4092 "[ERROR] Failed to load segment %d of "
4093 "firmware\n", fragment);
4094 break;
4095 }
4096
4097 fwcode += dlen;
4098 risc_addr += dlen;
4099 risc_size -= dlen;
4100 fragment++;
4101 }
4102
4103 /* Next segment. */
4104 segments--;
4105 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004106 return rval;
4107
4108fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004109 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004110}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004111
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004112int
4113qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4114{
4115 int rval;
4116
Andrew Vasqueze337d902009-04-06 22:33:49 -07004117 if (ql2xfwloadbin == 1)
4118 return qla81xx_load_risc(vha, srisc_addr);
4119
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004120 /*
4121 * FW Load priority:
4122 * 1) Firmware via request-firmware interface (.bin file).
4123 * 2) Firmware residing in flash.
4124 */
4125 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4126 if (rval == QLA_SUCCESS)
4127 return rval;
4128
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004129 return qla24xx_load_risc_flash(vha, srisc_addr,
4130 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004131}
4132
4133int
4134qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4135{
4136 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004137 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004138
Andrew Vasqueze337d902009-04-06 22:33:49 -07004139 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004140 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07004141
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004142 /*
4143 * FW Load priority:
4144 * 1) Firmware residing in flash.
4145 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004146 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004147 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004148 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004149 if (rval == QLA_SUCCESS)
4150 return rval;
4151
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004152try_blob_fw:
4153 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4154 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4155 return rval;
4156
4157 qla_printk(KERN_ERR, ha,
4158 "FW: Attempting to fallback to golden firmware...\n");
4159 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4160 if (rval != QLA_SUCCESS)
4161 return rval;
4162
4163 qla_printk(KERN_ERR, ha,
4164 "FW: Please update operational firmware...\n");
4165 ha->flags.running_gold_fw = 1;
4166
4167 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004168}
4169
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004170void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004171qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004172{
4173 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004174 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004175
Andrew Vasqueze4289242007-07-19 15:05:56 -07004176 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004177 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004178 if (!ha->fw_major_version)
4179 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004180
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004181 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004182 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07004183 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004184 ha->isp_ops->reset_chip(vha);
4185 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004186 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004187 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004188 continue;
4189 qla_printk(KERN_INFO, ha,
4190 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004191 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004192 }
4193}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004194
4195int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004196qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004197{
4198 int rval = QLA_SUCCESS;
4199 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004200 struct qla_hw_data *ha = vha->hw;
4201 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004202 struct req_que *req;
4203 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004204
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004205 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004206 return -EINVAL;
4207
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004208 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004209 if (ql2xmultique_tag)
4210 req = ha->req_q_map[0];
4211 else
4212 req = vha->req;
4213 rsp = req->rsp;
4214
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004215 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004216 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004217 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004218 }
4219
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004220 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004221
4222 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004223 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004224 if (mb[0] != MBS_COMMAND_COMPLETE) {
4225 DEBUG15(qla_printk(KERN_INFO, ha,
4226 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4227 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4228 mb[0], mb[1], mb[2], mb[6], mb[7]));
4229 return (QLA_FUNCTION_FAILED);
4230 }
4231
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004232 atomic_set(&vha->loop_down_timer, 0);
4233 atomic_set(&vha->loop_state, LOOP_UP);
4234 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4235 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4236 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004237
4238 return rval;
4239}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004240
4241/* 84XX Support **************************************************************/
4242
4243static LIST_HEAD(qla_cs84xx_list);
4244static DEFINE_MUTEX(qla_cs84xx_mutex);
4245
4246static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004247qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004248{
4249 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004250 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004251
4252 mutex_lock(&qla_cs84xx_mutex);
4253
4254 /* Find any shared 84xx chip. */
4255 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4256 if (cs84xx->bus == ha->pdev->bus) {
4257 kref_get(&cs84xx->kref);
4258 goto done;
4259 }
4260 }
4261
4262 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4263 if (!cs84xx)
4264 goto done;
4265
4266 kref_init(&cs84xx->kref);
4267 spin_lock_init(&cs84xx->access_lock);
4268 mutex_init(&cs84xx->fw_update_mutex);
4269 cs84xx->bus = ha->pdev->bus;
4270
4271 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4272done:
4273 mutex_unlock(&qla_cs84xx_mutex);
4274 return cs84xx;
4275}
4276
4277static void
4278__qla84xx_chip_release(struct kref *kref)
4279{
4280 struct qla_chip_state_84xx *cs84xx =
4281 container_of(kref, struct qla_chip_state_84xx, kref);
4282
4283 mutex_lock(&qla_cs84xx_mutex);
4284 list_del(&cs84xx->list);
4285 mutex_unlock(&qla_cs84xx_mutex);
4286 kfree(cs84xx);
4287}
4288
4289void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004290qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004291{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004292 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004293 if (ha->cs84xx)
4294 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4295}
4296
4297static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004298qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004299{
4300 int rval;
4301 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004302 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004303
4304 mutex_lock(&ha->cs84xx->fw_update_mutex);
4305
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004306 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004307
4308 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4309
4310 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4311 QLA_SUCCESS;
4312}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004313
4314/* 81XX Support **************************************************************/
4315
4316int
4317qla81xx_nvram_config(scsi_qla_host_t *vha)
4318{
4319 int rval;
4320 struct init_cb_81xx *icb;
4321 struct nvram_81xx *nv;
4322 uint32_t *dptr;
4323 uint8_t *dptr1, *dptr2;
4324 uint32_t chksum;
4325 uint16_t cnt;
4326 struct qla_hw_data *ha = vha->hw;
4327
4328 rval = QLA_SUCCESS;
4329 icb = (struct init_cb_81xx *)ha->init_cb;
4330 nv = ha->nvram;
4331
4332 /* Determine NVRAM starting address. */
4333 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004334 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004335
4336 /* Get VPD data into cache */
4337 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004338 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
4339 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004340
4341 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004342 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004343 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004344 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004345 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4346 chksum += le32_to_cpu(*dptr++);
4347
Andrew Vasquez76403352009-04-06 22:33:39 -07004348 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004349 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4350
4351 /* Bad NVRAM data, set defaults parameters. */
4352 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4353 || nv->id[3] != ' ' ||
4354 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4355 /* Reset NVRAM data. */
4356 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4357 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4358 le16_to_cpu(nv->nvram_version));
4359 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4360 "invalid -- WWPN) defaults.\n");
4361
4362 /*
4363 * Set default initialization control block.
4364 */
4365 memset(nv, 0, ha->nvram_size);
4366 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4367 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4368 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4369 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4370 nv->exchange_count = __constant_cpu_to_le16(0);
4371 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004372 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004373 nv->port_name[2] = 0x00;
4374 nv->port_name[3] = 0xe0;
4375 nv->port_name[4] = 0x8b;
4376 nv->port_name[5] = 0x1c;
4377 nv->port_name[6] = 0x55;
4378 nv->port_name[7] = 0x86;
4379 nv->node_name[0] = 0x20;
4380 nv->node_name[1] = 0x00;
4381 nv->node_name[2] = 0x00;
4382 nv->node_name[3] = 0xe0;
4383 nv->node_name[4] = 0x8b;
4384 nv->node_name[5] = 0x1c;
4385 nv->node_name[6] = 0x55;
4386 nv->node_name[7] = 0x86;
4387 nv->login_retry_count = __constant_cpu_to_le16(8);
4388 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4389 nv->login_timeout = __constant_cpu_to_le16(0);
4390 nv->firmware_options_1 =
4391 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4392 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4393 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4394 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4395 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4396 nv->efi_parameters = __constant_cpu_to_le32(0);
4397 nv->reset_delay = 5;
4398 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4399 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4400 nv->link_down_timeout = __constant_cpu_to_le16(30);
4401 nv->enode_mac[0] = 0x01;
4402 nv->enode_mac[1] = 0x02;
4403 nv->enode_mac[2] = 0x03;
4404 nv->enode_mac[3] = 0x04;
4405 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004406 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004407
4408 rval = 1;
4409 }
4410
4411 /* Reset Initialization control block */
4412 memset(icb, 0, sizeof(struct init_cb_81xx));
4413
4414 /* Copy 1st segment. */
4415 dptr1 = (uint8_t *)icb;
4416 dptr2 = (uint8_t *)&nv->version;
4417 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4418 while (cnt--)
4419 *dptr1++ = *dptr2++;
4420
4421 icb->login_retry_count = nv->login_retry_count;
4422
4423 /* Copy 2nd segment. */
4424 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4425 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4426 cnt = (uint8_t *)&icb->reserved_5 -
4427 (uint8_t *)&icb->interrupt_delay_timer;
4428 while (cnt--)
4429 *dptr1++ = *dptr2++;
4430
4431 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
4432 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4433 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
4434 icb->enode_mac[0] = 0x01;
4435 icb->enode_mac[1] = 0x02;
4436 icb->enode_mac[2] = 0x03;
4437 icb->enode_mac[3] = 0x04;
4438 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004439 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004440 }
4441
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004442 /* Use extended-initialization control block. */
4443 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
4444
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004445 /*
4446 * Setup driver NVRAM options.
4447 */
4448 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
4449 "QLE81XX");
4450
4451 /* Use alternate WWN? */
4452 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4453 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4454 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4455 }
4456
4457 /* Prepare nodename */
4458 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4459 /*
4460 * Firmware will apply the following mask if the nodename was
4461 * not provided.
4462 */
4463 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4464 icb->node_name[0] &= 0xF0;
4465 }
4466
4467 /* Set host adapter parameters. */
4468 ha->flags.disable_risc_code_load = 0;
4469 ha->flags.enable_lip_reset = 0;
4470 ha->flags.enable_lip_full_login =
4471 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4472 ha->flags.enable_target_reset =
4473 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4474 ha->flags.enable_led_scheme = 0;
4475 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4476
4477 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4478 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4479
4480 /* save HBA serial number */
4481 ha->serial0 = icb->port_name[5];
4482 ha->serial1 = icb->port_name[6];
4483 ha->serial2 = icb->port_name[7];
4484 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4485 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4486
4487 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4488
4489 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4490
4491 /* Set minimum login_timeout to 4 seconds. */
4492 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4493 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4494 if (le16_to_cpu(nv->login_timeout) < 4)
4495 nv->login_timeout = __constant_cpu_to_le16(4);
4496 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4497 icb->login_timeout = nv->login_timeout;
4498
4499 /* Set minimum RATOV to 100 tenths of a second. */
4500 ha->r_a_tov = 100;
4501
4502 ha->loop_reset_delay = nv->reset_delay;
4503
4504 /* Link Down Timeout = 0:
4505 *
4506 * When Port Down timer expires we will start returning
4507 * I/O's to OS with "DID_NO_CONNECT".
4508 *
4509 * Link Down Timeout != 0:
4510 *
4511 * The driver waits for the link to come up after link down
4512 * before returning I/Os to OS with "DID_NO_CONNECT".
4513 */
4514 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4515 ha->loop_down_abort_time =
4516 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4517 } else {
4518 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4519 ha->loop_down_abort_time =
4520 (LOOP_DOWN_TIME - ha->link_down_timeout);
4521 }
4522
4523 /* Need enough time to try and get the port back. */
4524 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4525 if (qlport_down_retry)
4526 ha->port_down_retry_count = qlport_down_retry;
4527
4528 /* Set login_retry_count */
4529 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4530 if (ha->port_down_retry_count ==
4531 le16_to_cpu(nv->port_down_retry_count) &&
4532 ha->port_down_retry_count > 3)
4533 ha->login_retry_count = ha->port_down_retry_count;
4534 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4535 ha->login_retry_count = ha->port_down_retry_count;
4536 if (ql2xloginretrycount)
4537 ha->login_retry_count = ql2xloginretrycount;
4538
4539 /* Enable ZIO. */
4540 if (!vha->flags.init_done) {
4541 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4542 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4543 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4544 le16_to_cpu(icb->interrupt_delay_timer): 2;
4545 }
4546 icb->firmware_options_2 &= __constant_cpu_to_le32(
4547 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4548 vha->flags.process_response_queue = 0;
4549 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4550 ha->zio_mode = QLA_ZIO_MODE_6;
4551
4552 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4553 "(%d us).\n", vha->host_no, ha->zio_mode,
4554 ha->zio_timer * 100));
4555 qla_printk(KERN_INFO, ha,
4556 "ZIO mode %d enabled; timer delay (%d us).\n",
4557 ha->zio_mode, ha->zio_timer * 100);
4558
4559 icb->firmware_options_2 |= cpu_to_le32(
4560 (uint32_t)ha->zio_mode);
4561 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4562 vha->flags.process_response_queue = 1;
4563 }
4564
4565 if (rval) {
4566 DEBUG2_3(printk(KERN_WARNING
4567 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4568 }
4569 return (rval);
4570}
4571
4572void
4573qla81xx_update_fw_options(scsi_qla_host_t *ha)
4574{
4575}