blob: 0cbe39e92506e7854a220202d6ca9db2a411f503 [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
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800733 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700734
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800735 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700736 if (rval) {
737 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800738 vha->host_no));
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700739 qla_printk(KERN_WARNING, ha,
740 "Failed mailbox send register test\n");
741 } else {
742 /* Flag a successful rval */
743 rval = QLA_SUCCESS;
744 }
745
746 return rval;
747}
748
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700749void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800750qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700751{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700752 int rval;
753 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800754 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800755 dma_addr_t tc_dma;
756 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800757 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800758 struct req_que *req = ha->req_q_map[0];
759 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700760
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700761 if (ha->fw_dump) {
762 qla_printk(KERN_WARNING, ha,
763 "Firmware dump previously allocated.\n");
764 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700765 }
766
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700767 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800768 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700769 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
770 fixed_size = sizeof(struct qla2100_fw_dump);
771 } else if (IS_QLA23XX(ha)) {
772 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
773 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
774 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -0700775 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800776 if (IS_QLA81XX(ha))
777 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
778 else if (IS_QLA25XX(ha))
779 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
780 else
781 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700782 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
783 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800784 if (ha->mqenable)
785 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700786 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800787 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700788 goto try_eft;
789
790 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
791 GFP_KERNEL);
792 if (!tc) {
793 qla_printk(KERN_WARNING, ha, "Unable to allocate "
794 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800795 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700796 }
797
798 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800799 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700800 ha->fce_mb, &ha->fce_bufs);
801 if (rval) {
802 qla_printk(KERN_WARNING, ha, "Unable to initialize "
803 "FCE (%d).\n", rval);
804 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
805 tc_dma);
806 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800807 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700808 }
809
810 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
811 FCE_SIZE / 1024);
812
Giridhar Malavali7d9dade2009-03-24 09:07:58 -0700813 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700814 ha->flags.fce_enabled = 1;
815 ha->fce_dma = tc_dma;
816 ha->fce = tc;
817try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700818 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800819 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700820 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800821 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700822 qla_printk(KERN_WARNING, ha, "Unable to allocate "
823 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
824 goto cont_alloc;
825 }
826
Andrew Vasquezfc447652008-01-17 09:02:18 -0800827 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800828 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700829 if (rval) {
830 qla_printk(KERN_WARNING, ha, "Unable to initialize "
831 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800832 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
833 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700834 goto cont_alloc;
835 }
836
837 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
838 EFT_SIZE / 1024);
839
840 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800841 ha->eft_dma = tc_dma;
842 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700843 }
844cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800845 req_q_size = req->length * sizeof(request_t);
846 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700847
848 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700849 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -0800850 ha->chain_offset = dump_size;
851 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700852
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700853 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700854 if (!ha->fw_dump) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700855 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700856 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700857
858 if (ha->eft) {
859 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
860 ha->eft_dma);
861 ha->eft = NULL;
862 ha->eft_dma = 0;
863 }
864 return;
865 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700866 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
867 dump_size / 1024);
868
869 ha->fw_dump_len = dump_size;
870 ha->fw_dump->signature[0] = 'Q';
871 ha->fw_dump->signature[1] = 'L';
872 ha->fw_dump->signature[2] = 'G';
873 ha->fw_dump->signature[3] = 'C';
874 ha->fw_dump->version = __constant_htonl(1);
875
876 ha->fw_dump->fixed_size = htonl(fixed_size);
877 ha->fw_dump->mem_size = htonl(mem_size);
878 ha->fw_dump->req_q_size = htonl(req_q_size);
879 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
880
881 ha->fw_dump->eft_size = htonl(eft_size);
882 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
883 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
884
885 ha->fw_dump->header_size =
886 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700887}
888
Andrew Vasquez18e75552009-06-03 09:55:30 -0700889static int
890qla81xx_mpi_sync(scsi_qla_host_t *vha)
891{
892#define MPS_MASK 0xe0
893 int rval;
894 uint16_t dc;
895 uint32_t dw;
896 struct qla_hw_data *ha = vha->hw;
897
898 if (!IS_QLA81XX(vha->hw))
899 return QLA_SUCCESS;
900
901 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
902 if (rval != QLA_SUCCESS) {
903 DEBUG2(qla_printk(KERN_WARNING, ha,
904 "Sync-MPI: Unable to acquire semaphore.\n"));
905 goto done;
906 }
907
908 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
909 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
910 if (rval != QLA_SUCCESS) {
911 DEBUG2(qla_printk(KERN_WARNING, ha,
912 "Sync-MPI: Unable to read sync.\n"));
913 goto done_release;
914 }
915
916 dc &= MPS_MASK;
917 if (dc == (dw & MPS_MASK))
918 goto done_release;
919
920 dw &= ~MPS_MASK;
921 dw |= dc;
922 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
923 if (rval != QLA_SUCCESS) {
924 DEBUG2(qla_printk(KERN_WARNING, ha,
925 "Sync-MPI: Unable to gain sync.\n"));
926 }
927
928done_release:
929 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
930 if (rval != QLA_SUCCESS) {
931 DEBUG2(qla_printk(KERN_WARNING, ha,
932 "Sync-MPI: Unable to release semaphore.\n"));
933 }
934
935done:
936 return rval;
937}
938
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700939/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 * qla2x00_setup_chip() - Load and start RISC firmware.
941 * @ha: HA context
942 *
943 * Returns 0 on success.
944 */
945static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800946qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947{
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700948 int rval;
949 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800950 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -0800951 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
952 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -0700953 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -0800954
955 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
956 /* Disable SRAM, Instruction RAM and GP RAM parity. */
957 spin_lock_irqsave(&ha->hardware_lock, flags);
958 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
959 RD_REG_WORD(&reg->hccr);
960 spin_unlock_irqrestore(&ha->hardware_lock, flags);
961 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962
Andrew Vasquez18e75552009-06-03 09:55:30 -0700963 qla81xx_mpi_sync(vha);
964
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800966 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700967 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800969 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800971 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 if (rval == QLA_SUCCESS) {
973 /* Start firmware execution. */
974 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800975 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800977 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -0700979 if (rval == QLA_SUCCESS) {
980 fw_major_version = ha->fw_major_version;
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700981 rval = qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 &ha->fw_major_version,
983 &ha->fw_minor_version,
984 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800985 &ha->fw_attributes, &ha->fw_memory_size,
Andrew Vasquez55a96152009-03-24 09:08:03 -0700986 ha->mpi_version, &ha->mpi_capabilities,
987 ha->phy_version);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700988 if (rval != QLA_SUCCESS)
989 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700990 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800991 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -0700992 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700993 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700994 if ((!ha->max_npiv_vports) ||
995 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800996 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700997 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800998 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700999 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001000 qla2x00_get_resource_cnts(vha, NULL,
1001 &ha->fw_xcb_count, NULL, NULL,
1002 &ha->max_npiv_vports);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001003
1004 if (!fw_major_version && ql2xallocfwdump)
1005 qla2x00_alloc_fw_dump(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 }
1007 } else {
1008 DEBUG2(printk(KERN_INFO
1009 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001010 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 }
1012 }
1013
Andrew Vasquez3db06522008-01-31 12:33:49 -08001014 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1015 /* Enable proper parity. */
1016 spin_lock_irqsave(&ha->hardware_lock, flags);
1017 if (IS_QLA2300(ha))
1018 /* SRAM parity */
1019 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1020 else
1021 /* SRAM, Instruction RAM and GP RAM parity */
1022 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1023 RD_REG_WORD(&reg->hccr);
1024 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1025 }
1026
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001027 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1028 uint32_t size;
1029
1030 rval = qla81xx_fac_get_sector_size(vha, &size);
1031 if (rval == QLA_SUCCESS) {
1032 ha->flags.fac_supported = 1;
1033 ha->fdt_block_size = size << 2;
1034 } else {
1035 qla_printk(KERN_ERR, ha,
1036 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1037 ha->fw_major_version, ha->fw_minor_version,
1038 ha->fw_subminor_version);
1039 }
1040 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001041failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 if (rval) {
1043 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001044 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 }
1046
1047 return (rval);
1048}
1049
1050/**
1051 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1052 * @ha: HA context
1053 *
1054 * Beginning of request ring has initialization control block already built
1055 * by nvram config routine.
1056 *
1057 * Returns 0 on success.
1058 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001059void
1060qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061{
1062 uint16_t cnt;
1063 response_t *pkt;
1064
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001065 rsp->ring_ptr = rsp->ring;
1066 rsp->ring_index = 0;
1067 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001068 pkt = rsp->ring_ptr;
1069 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 pkt->signature = RESPONSE_PROCESSED;
1071 pkt++;
1072 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073}
1074
1075/**
1076 * qla2x00_update_fw_options() - Read and process firmware options.
1077 * @ha: HA context
1078 *
1079 * Returns 0 on success.
1080 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001081void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001082qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083{
1084 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001085 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
1087 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001088 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
1090 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1091 return;
1092
1093 /* Serial Link options. */
1094 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001095 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1097 sizeof(ha->fw_seriallink_options)));
1098
1099 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1100 if (ha->fw_seriallink_options[3] & BIT_2) {
1101 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1102
1103 /* 1G settings */
1104 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1105 emphasis = (ha->fw_seriallink_options[2] &
1106 (BIT_4 | BIT_3)) >> 3;
1107 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001108 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 rx_sens = (ha->fw_seriallink_options[0] &
1110 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1111 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1112 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1113 if (rx_sens == 0x0)
1114 rx_sens = 0x3;
1115 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1116 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1117 ha->fw_options[10] |= BIT_5 |
1118 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1119 (tx_sens & (BIT_1 | BIT_0));
1120
1121 /* 2G settings */
1122 swing = (ha->fw_seriallink_options[2] &
1123 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1124 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1125 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001126 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 rx_sens = (ha->fw_seriallink_options[1] &
1128 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1129 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1130 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1131 if (rx_sens == 0x0)
1132 rx_sens = 0x3;
1133 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1134 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1135 ha->fw_options[11] |= BIT_5 |
1136 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1137 (tx_sens & (BIT_1 | BIT_0));
1138 }
1139
1140 /* FCP2 options. */
1141 /* Return command IOCBs without waiting for an ABTS to complete. */
1142 ha->fw_options[3] |= BIT_13;
1143
1144 /* LED scheme. */
1145 if (ha->flags.enable_led_scheme)
1146 ha->fw_options[2] |= BIT_12;
1147
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001148 /* Detect ISP6312. */
1149 if (IS_QLA6312(ha))
1150 ha->fw_options[2] |= BIT_13;
1151
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001153 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154}
1155
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001156void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001157qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001158{
1159 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001160 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001161
1162 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001163 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001164 return;
1165
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001166 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001167 le16_to_cpu(ha->fw_seriallink_options24[1]),
1168 le16_to_cpu(ha->fw_seriallink_options24[2]),
1169 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001170 if (rval != QLA_SUCCESS) {
1171 qla_printk(KERN_WARNING, ha,
1172 "Unable to update Serial Link options (%x).\n", rval);
1173 }
1174}
1175
1176void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001177qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001178{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001179 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001180 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001181 struct req_que *req = ha->req_q_map[0];
1182 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001183
1184 /* Setup ring parameters in initialization control block. */
1185 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1186 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001187 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1188 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1189 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1190 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1191 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1192 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001193
1194 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1195 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1196 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1197 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1198 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1199}
1200
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001201void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001202qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001203{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001204 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001205 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1206 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1207 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001208 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001209 uint16_t rid = 0;
1210 struct req_que *req = ha->req_q_map[0];
1211 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001212
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001213/* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001214 icb = (struct init_cb_24xx *)ha->init_cb;
1215 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1216 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001217 icb->request_q_length = cpu_to_le16(req->length);
1218 icb->response_q_length = cpu_to_le16(rsp->length);
1219 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1220 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1221 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1222 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001223
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001224 if (ha->mqenable) {
1225 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1226 icb->rid = __constant_cpu_to_le16(rid);
1227 if (ha->flags.msix_enabled) {
1228 msix = &ha->msix_entries[1];
1229 DEBUG2_17(printk(KERN_INFO
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001230 "Registering vector 0x%x for base que\n", msix->entry));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001231 icb->msix = cpu_to_le16(msix->entry);
1232 }
1233 /* Use alternate PCI bus number */
1234 if (MSB(rid))
1235 icb->firmware_options_2 |=
1236 __constant_cpu_to_le32(BIT_19);
1237 /* Use alternate PCI devfn */
1238 if (LSB(rid))
1239 icb->firmware_options_2 |=
1240 __constant_cpu_to_le32(BIT_18);
1241
Anirban Chakraborty618a7522009-02-08 20:50:11 -08001242 icb->firmware_options_2 &= __constant_cpu_to_le32(~BIT_22);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001243 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001244
1245 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1246 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1247 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1248 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1249 } else {
1250 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1251 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1252 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1253 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1254 }
1255 /* PCI posting */
1256 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001257}
1258
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259/**
1260 * qla2x00_init_rings() - Initializes firmware.
1261 * @ha: HA context
1262 *
1263 * Beginning of request ring has initialization control block already built
1264 * by nvram config routine.
1265 *
1266 * Returns 0 on success.
1267 */
1268static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001269qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270{
1271 int rval;
1272 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001273 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001274 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001275 struct req_que *req;
1276 struct rsp_que *rsp;
1277 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001278 struct mid_init_cb_24xx *mid_init_cb =
1279 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280
1281 spin_lock_irqsave(&ha->hardware_lock, flags);
1282
1283 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001284 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001285 req = ha->req_q_map[que];
1286 if (!req)
1287 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001288 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001289 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001291 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001292
1293 /* Initialize firmware. */
1294 req->ring_ptr = req->ring;
1295 req->ring_index = 0;
1296 req->cnt = req->length;
1297 }
1298
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001299 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001300 rsp = ha->rsp_q_map[que];
1301 if (!rsp)
1302 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001303 /* Initialize response queue entries */
1304 qla2x00_init_response_q_entries(rsp);
1305 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
1307 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001308 list_for_each_entry(vp, &ha->vp_list, list) {
1309 vp->rscn_in_ptr = 0;
1310 vp->rscn_out_ptr = 0;
1311 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001312 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313
1314 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1315
1316 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001317 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001319 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001320
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001321 if (ha->flags.npiv_supported) {
1322 if (ha->operating_mode == LOOP)
1323 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001324 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001325 }
1326
Andrew Vasquez24a08132009-03-24 09:08:16 -07001327 if (IS_FWI2_CAPABLE(ha)) {
1328 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1329 mid_init_cb->init_cb.execution_throttle =
1330 cpu_to_le16(ha->fw_xcb_count);
1331 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001332
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001333 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 if (rval) {
1335 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001336 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 } else {
1338 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001339 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 }
1341
1342 return (rval);
1343}
1344
1345/**
1346 * qla2x00_fw_ready() - Waits for firmware ready.
1347 * @ha: HA context
1348 *
1349 * Returns 0 on success.
1350 */
1351static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001352qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353{
1354 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001355 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 uint16_t min_wait; /* Minimum wait time if loop is down */
1357 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07001358 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001359 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
1361 rval = QLA_SUCCESS;
1362
1363 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001364 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365
1366 /*
1367 * Firmware should take at most one RATOV to login, plus 5 seconds for
1368 * our own processing.
1369 */
1370 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1371 wait_time = min_wait;
1372 }
1373
1374 /* Min wait time if loop down */
1375 mtime = jiffies + (min_wait * HZ);
1376
1377 /* wait time before firmware ready */
1378 wtime = jiffies + (wait_time * HZ);
1379
1380 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001381 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1383
1384 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001385 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386
1387 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001388 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001390 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001391 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001393 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1394 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001395 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001396 state[2]));
1397 if ((state[2] & FSTATE_LOGGED_IN) &&
1398 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1399 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001400 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001401
1402 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001403 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001404 if (rval != QLA_SUCCESS)
1405 break;
1406
1407 /* Add time taken to initialize. */
1408 cs84xx_time = jiffies - cs84xx_time;
1409 wtime += cs84xx_time;
1410 mtime += cs84xx_time;
1411 DEBUG16(printk("scsi(%ld): Increasing "
1412 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001413 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001414 }
1415 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001417 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001419 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 &ha->login_timeout, &ha->r_a_tov);
1421
1422 rval = QLA_SUCCESS;
1423 break;
1424 }
1425
1426 rval = QLA_FUNCTION_FAILED;
1427
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001428 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001429 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001431 * other than Wait for Login.
1432 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 if (time_after_eq(jiffies, mtime)) {
1434 qla_printk(KERN_INFO, ha,
1435 "Cable is unplugged...\n");
1436
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001437 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 break;
1439 }
1440 }
1441 } else {
1442 /* Mailbox cmd failed. Timeout on min_wait. */
1443 if (time_after_eq(jiffies, mtime))
1444 break;
1445 }
1446
1447 if (time_after_eq(jiffies, wtime))
1448 break;
1449
1450 /* Delay for a while */
1451 msleep(500);
1452
1453 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001454 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 } while (1);
1456
Andrew Vasquez656e8912009-06-03 09:55:29 -07001457 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1458 vha->host_no, state[0], state[1], state[2], state[3], state[4],
1459 jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460
1461 if (rval) {
1462 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001463 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 }
1465
1466 return (rval);
1467}
1468
1469/*
1470* qla2x00_configure_hba
1471* Setup adapter context.
1472*
1473* Input:
1474* ha = adapter state pointer.
1475*
1476* Returns:
1477* 0 = success
1478*
1479* Context:
1480* Kernel context.
1481*/
1482static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001483qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484{
1485 int rval;
1486 uint16_t loop_id;
1487 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001488 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 uint8_t al_pa;
1490 uint8_t area;
1491 uint8_t domain;
1492 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001493 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494
1495 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001496 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001497 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001499 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001500 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1501 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001502 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08001503 } else {
1504 qla_printk(KERN_WARNING, ha,
1505 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001506 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08001507 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 return (rval);
1509 }
1510
1511 if (topo == 4) {
1512 qla_printk(KERN_INFO, ha,
1513 "Cannot get topology - retrying.\n");
1514 return (QLA_FUNCTION_FAILED);
1515 }
1516
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001517 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
1519 /* initialize */
1520 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1521 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001522 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
1524 switch (topo) {
1525 case 0:
1526 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001527 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 ha->current_topology = ISP_CFG_NL;
1529 strcpy(connect_type, "(Loop)");
1530 break;
1531
1532 case 1:
1533 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001534 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001535 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 ha->current_topology = ISP_CFG_FL;
1537 strcpy(connect_type, "(FL_Port)");
1538 break;
1539
1540 case 2:
1541 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001542 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 ha->operating_mode = P2P;
1544 ha->current_topology = ISP_CFG_N;
1545 strcpy(connect_type, "(N_Port-to-N_Port)");
1546 break;
1547
1548 case 3:
1549 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001550 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001551 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 ha->operating_mode = P2P;
1553 ha->current_topology = ISP_CFG_F;
1554 strcpy(connect_type, "(F_Port)");
1555 break;
1556
1557 default:
1558 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1559 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001560 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 ha->current_topology = ISP_CFG_NL;
1562 strcpy(connect_type, "(Loop)");
1563 break;
1564 }
1565
1566 /* Save Host port and loop ID. */
1567 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001568 vha->d_id.b.domain = domain;
1569 vha->d_id.b.area = area;
1570 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001572 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 qla_printk(KERN_INFO, ha,
1574 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001575 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576
1577 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001578 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001580 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 }
1582
1583 return(rval);
1584}
1585
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001586static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001587qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1588 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001589{
1590 char *st, *en;
1591 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001592 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez1b91a2e2009-06-03 09:55:15 -07001593 int use_tbl = !IS_QLA25XX(ha) && !IS_QLA81XX(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001594
1595 if (memcmp(model, BINZERO, len) != 0) {
1596 strncpy(ha->model_number, model, len);
1597 st = en = ha->model_number;
1598 en += len - 1;
1599 while (en > st) {
1600 if (*en != 0x20 && *en != 0x00)
1601 break;
1602 *en-- = '\0';
1603 }
1604
1605 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07001606 if (use_tbl &&
1607 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001608 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001609 strncpy(ha->model_desc,
1610 qla2x00_model_name[index * 2 + 1],
1611 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001612 } else {
1613 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07001614 if (use_tbl &&
1615 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001616 index < QLA_MODEL_NAMES) {
1617 strcpy(ha->model_number,
1618 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001619 strncpy(ha->model_desc,
1620 qla2x00_model_name[index * 2 + 1],
1621 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001622 } else {
1623 strcpy(ha->model_number, def);
1624 }
1625 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001626 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001627 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001628 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001629}
1630
David Miller4e08df32007-04-16 12:37:43 -07001631/* On sparc systems, obtain port and node WWN from firmware
1632 * properties.
1633 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001634static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07001635{
1636#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001637 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07001638 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07001639 struct device_node *dp = pci_device_to_OF_node(pdev);
1640 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07001641 int len;
1642
1643 val = of_get_property(dp, "port-wwn", &len);
1644 if (val && len >= WWN_SIZE)
1645 memcpy(nv->port_name, val, WWN_SIZE);
1646
1647 val = of_get_property(dp, "node-wwn", &len);
1648 if (val && len >= WWN_SIZE)
1649 memcpy(nv->node_name, val, WWN_SIZE);
1650#endif
1651}
1652
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653/*
1654* NVRAM configuration for ISP 2xxx
1655*
1656* Input:
1657* ha = adapter block pointer.
1658*
1659* Output:
1660* initialization control block in response_ring
1661* host adapters parameters in host adapter block
1662*
1663* Returns:
1664* 0 = success.
1665*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001666int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001667qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668{
David Miller4e08df32007-04-16 12:37:43 -07001669 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001670 uint8_t chksum = 0;
1671 uint16_t cnt;
1672 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001673 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001674 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07001675 nvram_t *nv = ha->nvram;
1676 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001677 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
David Miller4e08df32007-04-16 12:37:43 -07001679 rval = QLA_SUCCESS;
1680
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001682 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 ha->nvram_base = 0;
1684 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1685 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
1686 ha->nvram_base = 0x80;
1687
1688 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001689 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001690 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1691 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001693 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07001694 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695
1696 /* Bad NVRAM data, set defaults parameters. */
1697 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1698 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1699 /* Reset NVRAM data. */
1700 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1701 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1702 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07001703 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1704 "invalid -- WWPN) defaults.\n");
1705
1706 /*
1707 * Set default initialization control block.
1708 */
1709 memset(nv, 0, ha->nvram_size);
1710 nv->parameter_block_version = ICB_VERSION;
1711
1712 if (IS_QLA23XX(ha)) {
1713 nv->firmware_options[0] = BIT_2 | BIT_1;
1714 nv->firmware_options[1] = BIT_7 | BIT_5;
1715 nv->add_firmware_options[0] = BIT_5;
1716 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1717 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1718 nv->special_options[1] = BIT_7;
1719 } else if (IS_QLA2200(ha)) {
1720 nv->firmware_options[0] = BIT_2 | BIT_1;
1721 nv->firmware_options[1] = BIT_7 | BIT_5;
1722 nv->add_firmware_options[0] = BIT_5;
1723 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1724 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1725 } else if (IS_QLA2100(ha)) {
1726 nv->firmware_options[0] = BIT_3 | BIT_1;
1727 nv->firmware_options[1] = BIT_5;
1728 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1729 }
1730
1731 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1732 nv->execution_throttle = __constant_cpu_to_le16(16);
1733 nv->retry_count = 8;
1734 nv->retry_delay = 1;
1735
1736 nv->port_name[0] = 33;
1737 nv->port_name[3] = 224;
1738 nv->port_name[4] = 139;
1739
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001740 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07001741
1742 nv->login_timeout = 4;
1743
1744 /*
1745 * Set default host adapter parameters
1746 */
1747 nv->host_p[1] = BIT_2;
1748 nv->reset_delay = 5;
1749 nv->port_down_retry_count = 8;
1750 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1751 nv->link_down_timeout = 60;
1752
1753 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 }
1755
1756#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1757 /*
1758 * The SN2 does not provide BIOS emulation which means you can't change
1759 * potentially bogus BIOS settings. Force the use of default settings
1760 * for link rate and frame size. Hope that the rest of the settings
1761 * are valid.
1762 */
1763 if (ia64_platform_is("sn2")) {
1764 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1765 if (IS_QLA23XX(ha))
1766 nv->special_options[1] = BIT_7;
1767 }
1768#endif
1769
1770 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001771 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772
1773 /*
1774 * Setup driver NVRAM options.
1775 */
1776 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1777 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1778 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1779 nv->firmware_options[1] &= ~BIT_4;
1780
1781 if (IS_QLA23XX(ha)) {
1782 nv->firmware_options[0] |= BIT_2;
1783 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001784 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785
1786 if (IS_QLA2300(ha)) {
1787 if (ha->fb_rev == FPM_2310) {
1788 strcpy(ha->model_number, "QLA2310");
1789 } else {
1790 strcpy(ha->model_number, "QLA2300");
1791 }
1792 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001793 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001794 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 }
1796 } else if (IS_QLA2200(ha)) {
1797 nv->firmware_options[0] |= BIT_2;
1798 /*
1799 * 'Point-to-point preferred, else loop' is not a safe
1800 * connection mode setting.
1801 */
1802 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1803 (BIT_5 | BIT_4)) {
1804 /* Force 'loop preferred, else point-to-point'. */
1805 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1806 nv->add_firmware_options[0] |= BIT_5;
1807 }
1808 strcpy(ha->model_number, "QLA22xx");
1809 } else /*if (IS_QLA2100(ha))*/ {
1810 strcpy(ha->model_number, "QLA2100");
1811 }
1812
1813 /*
1814 * Copy over NVRAM RISC parameter block to initialization control block.
1815 */
1816 dptr1 = (uint8_t *)icb;
1817 dptr2 = (uint8_t *)&nv->parameter_block_version;
1818 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1819 while (cnt--)
1820 *dptr1++ = *dptr2++;
1821
1822 /* Copy 2nd half. */
1823 dptr1 = (uint8_t *)icb->add_firmware_options;
1824 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1825 while (cnt--)
1826 *dptr1++ = *dptr2++;
1827
Andrew Vasquez5341e862006-05-17 15:09:16 -07001828 /* Use alternate WWN? */
1829 if (nv->host_p[1] & BIT_7) {
1830 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1831 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1832 }
1833
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 /* Prepare nodename */
1835 if ((icb->firmware_options[1] & BIT_6) == 0) {
1836 /*
1837 * Firmware will apply the following mask if the nodename was
1838 * not provided.
1839 */
1840 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1841 icb->node_name[0] &= 0xF0;
1842 }
1843
1844 /*
1845 * Set host adapter parameters.
1846 */
Andrew Vasquez01819442006-06-23 16:11:10 -07001847 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07001848 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1850 /* Always load RISC code on non ISP2[12]00 chips. */
1851 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1852 ha->flags.disable_risc_code_load = 0;
1853 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1854 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1855 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07001856 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001857 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858
1859 ha->operating_mode =
1860 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1861
1862 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1863 sizeof(ha->fw_seriallink_options));
1864
1865 /* save HBA serial number */
1866 ha->serial0 = icb->port_name[5];
1867 ha->serial1 = icb->port_name[6];
1868 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001869 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
1870 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871
1872 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1873
1874 ha->retry_count = nv->retry_count;
1875
1876 /* Set minimum login_timeout to 4 seconds. */
1877 if (nv->login_timeout < ql2xlogintimeout)
1878 nv->login_timeout = ql2xlogintimeout;
1879 if (nv->login_timeout < 4)
1880 nv->login_timeout = 4;
1881 ha->login_timeout = nv->login_timeout;
1882 icb->login_timeout = nv->login_timeout;
1883
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001884 /* Set minimum RATOV to 100 tenths of a second. */
1885 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 ha->loop_reset_delay = nv->reset_delay;
1888
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 /* Link Down Timeout = 0:
1890 *
1891 * When Port Down timer expires we will start returning
1892 * I/O's to OS with "DID_NO_CONNECT".
1893 *
1894 * Link Down Timeout != 0:
1895 *
1896 * The driver waits for the link to come up after link down
1897 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001898 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 if (nv->link_down_timeout == 0) {
1900 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001901 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 } else {
1903 ha->link_down_timeout = nv->link_down_timeout;
1904 ha->loop_down_abort_time =
1905 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001906 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 /*
1909 * Need enough time to try and get the port back.
1910 */
1911 ha->port_down_retry_count = nv->port_down_retry_count;
1912 if (qlport_down_retry)
1913 ha->port_down_retry_count = qlport_down_retry;
1914 /* Set login_retry_count */
1915 ha->login_retry_count = nv->retry_count;
1916 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1917 ha->port_down_retry_count > 3)
1918 ha->login_retry_count = ha->port_down_retry_count;
1919 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1920 ha->login_retry_count = ha->port_down_retry_count;
1921 if (ql2xloginretrycount)
1922 ha->login_retry_count = ql2xloginretrycount;
1923
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 icb->lun_enables = __constant_cpu_to_le16(0);
1925 icb->command_resource_count = 0;
1926 icb->immediate_notify_resource_count = 0;
1927 icb->timeout = __constant_cpu_to_le16(0);
1928
1929 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1930 /* Enable RIO */
1931 icb->firmware_options[0] &= ~BIT_3;
1932 icb->add_firmware_options[0] &=
1933 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1934 icb->add_firmware_options[0] |= BIT_2;
1935 icb->response_accumulation_timer = 3;
1936 icb->interrupt_delay_timer = 5;
1937
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001938 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001940 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001941 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001942 ha->zio_mode = icb->add_firmware_options[0] &
1943 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1944 ha->zio_timer = icb->interrupt_delay_timer ?
1945 icb->interrupt_delay_timer: 2;
1946 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 icb->add_firmware_options[0] &=
1948 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001949 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001950 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001951 ha->zio_mode = QLA_ZIO_MODE_6;
1952
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001953 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001954 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001955 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001957 "ZIO mode %d enabled; timer delay (%d us).\n",
1958 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001960 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1961 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001962 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 }
1964 }
1965
David Miller4e08df32007-04-16 12:37:43 -07001966 if (rval) {
1967 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001968 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07001969 }
1970 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971}
1972
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001973static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001974qla2x00_rport_del(void *data)
1975{
1976 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001977 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001978
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001979 spin_lock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001980 rport = fcport->drport;
1981 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001982 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001983 if (rport)
1984 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001985}
1986
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987/**
1988 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1989 * @ha: HA context
1990 * @flags: allocation flags
1991 *
1992 * Returns a pointer to the allocated fcport, or NULL, if none available.
1993 */
Adrian Bunk413975a2006-06-30 02:33:06 -07001994static fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001995qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996{
1997 fc_port_t *fcport;
1998
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001999 fcport = kzalloc(sizeof(fc_port_t), flags);
2000 if (!fcport)
2001 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002
2003 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002004 fcport->vha = vha;
2005 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 fcport->port_type = FCT_UNKNOWN;
2007 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 atomic_set(&fcport->state, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002009 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002011 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012}
2013
2014/*
2015 * qla2x00_configure_loop
2016 * Updates Fibre Channel Device Database with what is actually on loop.
2017 *
2018 * Input:
2019 * ha = adapter block pointer.
2020 *
2021 * Returns:
2022 * 0 = success.
2023 * 1 = error.
2024 * 2 = database was full and device was not configured.
2025 */
2026static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002027qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028{
2029 int rval;
2030 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002031 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 rval = QLA_SUCCESS;
2033
2034 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002035 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2036 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 if (rval != QLA_SUCCESS) {
2038 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002039 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 return (rval);
2041 }
2042 }
2043
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002044 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002046 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047
2048 /*
2049 * If we have both an RSCN and PORT UPDATE pending then handle them
2050 * both at the same time.
2051 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002052 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2053 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054
2055 /* Determine what we need to do */
2056 if (ha->current_topology == ISP_CFG_FL &&
2057 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2058
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002059 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 set_bit(RSCN_UPDATE, &flags);
2061
2062 } else if (ha->current_topology == ISP_CFG_F &&
2063 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2064
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002065 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 set_bit(RSCN_UPDATE, &flags);
2067 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2068
Andrew Vasquez21333b42006-05-17 15:09:56 -07002069 } else if (ha->current_topology == ISP_CFG_N) {
2070 clear_bit(RSCN_UPDATE, &flags);
2071
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002072 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2074
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002075 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 set_bit(RSCN_UPDATE, &flags);
2077 set_bit(LOCAL_LOOP_UPDATE, &flags);
2078 }
2079
2080 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002081 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002083 else
2084 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 }
2086
2087 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002088 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002090 else
2091 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 }
2093
2094 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002095 if (atomic_read(&vha->loop_down_timer) ||
2096 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 rval = QLA_FUNCTION_FAILED;
2098 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002099 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002101 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 }
2103 }
2104
2105 if (rval) {
2106 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002107 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 } else {
2109 DEBUG3(printk("%s: exiting normally\n", __func__));
2110 }
2111
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002112 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002113 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002115 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002116 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002117 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002118 vha->flags.rscn_queue_overflow = 1;
2119 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 }
2121
2122 return (rval);
2123}
2124
2125
2126
2127/*
2128 * qla2x00_configure_local_loop
2129 * Updates Fibre Channel Device Database with local loop devices.
2130 *
2131 * Input:
2132 * ha = adapter block pointer.
2133 *
2134 * Returns:
2135 * 0 = success.
2136 */
2137static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002138qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139{
2140 int rval, rval2;
2141 int found_devs;
2142 int found;
2143 fc_port_t *fcport, *new_fcport;
2144
2145 uint16_t index;
2146 uint16_t entries;
2147 char *id_iter;
2148 uint16_t loop_id;
2149 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002150 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151
2152 found_devs = 0;
2153 new_fcport = NULL;
2154 entries = MAX_FIBRE_DEVICES;
2155
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002156 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2157 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158
2159 /* Get list of logged in devices. */
2160 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002161 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 &entries);
2163 if (rval != QLA_SUCCESS)
2164 goto cleanup_allocation;
2165
2166 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07002167 vha->host_no, entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2169 entries * sizeof(struct gid_list_info)));
2170
2171 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002172 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 if (new_fcport == NULL) {
2174 rval = QLA_MEMORY_ALLOC_FAILED;
2175 goto cleanup_allocation;
2176 }
2177 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2178
2179 /*
2180 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2181 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002182 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2184 fcport->port_type != FCT_BROADCAST &&
2185 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2186
2187 DEBUG(printk("scsi(%ld): Marking port lost, "
2188 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002189 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190
2191 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 }
2193 }
2194
2195 /* Add devices to port list. */
2196 id_iter = (char *)ha->gid_list;
2197 for (index = 0; index < entries; index++) {
2198 domain = ((struct gid_list_info *)id_iter)->domain;
2199 area = ((struct gid_list_info *)id_iter)->area;
2200 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002201 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 loop_id = (uint16_t)
2203 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002204 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 loop_id = le16_to_cpu(
2206 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002207 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208
2209 /* Bypass reserved domain fields. */
2210 if ((domain & 0xf0) == 0xf0)
2211 continue;
2212
2213 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002214 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002215 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 continue;
2217
2218 /* Bypass invalid local loop ID. */
2219 if (loop_id > LAST_LOCAL_LOOP_ID)
2220 continue;
2221
2222 /* Fill in member data. */
2223 new_fcport->d_id.b.domain = domain;
2224 new_fcport->d_id.b.area = area;
2225 new_fcport->d_id.b.al_pa = al_pa;
2226 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002227 new_fcport->vp_idx = vha->vp_idx;
2228 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 if (rval2 != QLA_SUCCESS) {
2230 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2231 "information -- get_port_database=%x, "
2232 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002233 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002234 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002235 vha->host_no));
2236 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 continue;
2238 }
2239
2240 /* Check for matching device in port list. */
2241 found = 0;
2242 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002243 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 if (memcmp(new_fcport->port_name, fcport->port_name,
2245 WWN_SIZE))
2246 continue;
2247
Shyam Sundarddb9b122009-03-24 09:08:10 -07002248 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 fcport->loop_id = new_fcport->loop_id;
2250 fcport->port_type = new_fcport->port_type;
2251 fcport->d_id.b24 = new_fcport->d_id.b24;
2252 memcpy(fcport->node_name, new_fcport->node_name,
2253 WWN_SIZE);
2254
2255 found++;
2256 break;
2257 }
2258
2259 if (!found) {
2260 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002261 if (vha->vp_idx) {
2262 new_fcport->vha = vha;
2263 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002264 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002265 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266
2267 /* Allocate a new replacement fcport. */
2268 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002269 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 if (new_fcport == NULL) {
2271 rval = QLA_MEMORY_ALLOC_FAILED;
2272 goto cleanup_allocation;
2273 }
2274 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2275 }
2276
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002277 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002278 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002279
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002280 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281
2282 found_devs++;
2283 }
2284
2285cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002286 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287
2288 if (rval != QLA_SUCCESS) {
2289 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002290 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 }
2292
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 return (rval);
2294}
2295
2296static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002297qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002298{
2299#define LS_UNKNOWN 2
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002300 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2301 char *link_speed;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002302 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002303 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002304 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002305
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002306 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002307 return;
2308
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002309 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2310 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002311 return;
2312
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002313 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002314 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002315 if (rval != QLA_SUCCESS) {
2316 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2317 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002318 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002319 fcport->port_name[2], fcport->port_name[3],
2320 fcport->port_name[4], fcport->port_name[5],
2321 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002322 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002323 } else {
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002324 link_speed = link_speeds[LS_UNKNOWN];
2325 if (fcport->fp_speed < 5)
2326 link_speed = link_speeds[fcport->fp_speed];
2327 else if (fcport->fp_speed == 0x13)
2328 link_speed = link_speeds[5];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002329 DEBUG2(qla_printk(KERN_INFO, ha,
2330 "iIDMA adjusted to %s GB/s on "
2331 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002332 link_speed, fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002333 fcport->port_name[1], fcport->port_name[2],
2334 fcport->port_name[3], fcport->port_name[4],
2335 fcport->port_name[5], fcport->port_name[6],
2336 fcport->port_name[7]));
2337 }
2338}
2339
Adrian Bunk23be3312006-11-24 02:46:01 +01002340static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002341qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002342{
2343 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002344 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002345 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05002346
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002347 if (fcport->drport)
2348 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002349
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002350 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2351 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002352 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2353 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2354 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002355 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002356 if (!rport) {
2357 qla_printk(KERN_WARNING, ha,
2358 "Unable to allocate fc remote port!\n");
2359 return;
2360 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002361 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002362 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002363 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002364
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002365 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002366
2367 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002368 if (fcport->port_type == FCT_INITIATOR)
2369 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2370 if (fcport->port_type == FCT_TARGET)
2371 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002372 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002373}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374
2375/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002376 * qla2x00_update_fcport
2377 * Updates device on list.
2378 *
2379 * Input:
2380 * ha = adapter block pointer.
2381 * fcport = port structure pointer.
2382 *
2383 * Return:
2384 * 0 - Success
2385 * BIT_0 - error
2386 *
2387 * Context:
2388 * Kernel context.
2389 */
2390void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002391qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002392{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002393 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002394
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002395 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002396 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002397 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002398 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002399 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002400 PORT_RETRY_TIME);
2401 fcport->flags &= ~FCF_LOGIN_NEEDED;
2402
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002403 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002404
2405 atomic_set(&fcport->state, FCS_ONLINE);
2406
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002407 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002408}
2409
2410/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 * qla2x00_configure_fabric
2412 * Setup SNS devices with loop ID's.
2413 *
2414 * Input:
2415 * ha = adapter block pointer.
2416 *
2417 * Returns:
2418 * 0 = success.
2419 * BIT_0 = error
2420 */
2421static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002422qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423{
2424 int rval, rval2;
2425 fc_port_t *fcport, *fcptemp;
2426 uint16_t next_loopid;
2427 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002428 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002430 struct qla_hw_data *ha = vha->hw;
2431 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432
2433 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002434 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002435 loop_id = NPH_F_PORT;
2436 else
2437 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002438 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 if (rval != QLA_SUCCESS) {
2440 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002441 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002443 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 return (QLA_SUCCESS);
2445 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002446 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447
2448 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002449 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 if (rval2 == QLA_RSCNS_HANDLED) {
2451 /* No point doing the scan, just continue. */
2452 return (QLA_SUCCESS);
2453 }
2454 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002455 /* FDMI support. */
2456 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002457 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2458 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002459
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002461 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002462 loop_id = NPH_SNS;
2463 else
2464 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002465 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002466 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 if (mb[0] != MBS_COMMAND_COMPLETE) {
2468 DEBUG2(qla_printk(KERN_INFO, ha,
2469 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002470 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 mb[0], mb[1], mb[2], mb[6], mb[7]));
2472 return (QLA_SUCCESS);
2473 }
2474
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002475 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2476 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 /* EMPTY */
2478 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002479 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002481 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 /* EMPTY */
2483 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002484 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002486 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 /* EMPTY */
2488 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002489 "failed.\n", vha->host_no));
2490 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 /* EMPTY */
2492 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002493 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 }
2495 }
2496
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002497 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 if (rval != QLA_SUCCESS)
2499 break;
2500
2501 /*
2502 * Logout all previous fabric devices marked lost, except
2503 * tape devices.
2504 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002505 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2506 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 break;
2508
2509 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2510 continue;
2511
2512 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002513 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002514 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 if (fcport->loop_id != FC_NO_LOOP_ID &&
2516 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2517 fcport->port_type != FCT_INITIATOR &&
2518 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002519 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002520 fcport->loop_id,
2521 fcport->d_id.b.domain,
2522 fcport->d_id.b.area,
2523 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 fcport->loop_id = FC_NO_LOOP_ID;
2525 }
2526 }
2527 }
2528
2529 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002530 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531
2532 /*
2533 * Scan through our port list and login entries that need to be
2534 * logged in.
2535 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002536 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2537 if (atomic_read(&vha->loop_down_timer) ||
2538 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 break;
2540
2541 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2542 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2543 continue;
2544
2545 if (fcport->loop_id == FC_NO_LOOP_ID) {
2546 fcport->loop_id = next_loopid;
Seokmann Jud4486fd2008-04-03 13:13:28 -07002547 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002548 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 if (rval != QLA_SUCCESS) {
2550 /* Ran out of IDs to use */
2551 break;
2552 }
2553 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002555 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 }
2557
2558 /* Exit if out of loop IDs. */
2559 if (rval != QLA_SUCCESS) {
2560 break;
2561 }
2562
2563 /*
2564 * Login and add the new devices to our port list.
2565 */
2566 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002567 if (atomic_read(&vha->loop_down_timer) ||
2568 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 break;
2570
2571 /* Find a new loop ID to use. */
2572 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002573 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 if (rval != QLA_SUCCESS) {
2575 /* Ran out of IDs to use */
2576 break;
2577 }
2578
bdf79622005-04-17 15:06:53 -05002579 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002580 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002581
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002582 if (vha->vp_idx) {
2583 fcport->vha = vha;
2584 fcport->vp_idx = vha->vp_idx;
2585 }
2586 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 }
2588 } while (0);
2589
2590 /* Free all new device structures not processed. */
2591 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2592 list_del(&fcport->list);
2593 kfree(fcport);
2594 }
2595
2596 if (rval) {
2597 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002598 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 }
2600
2601 return (rval);
2602}
2603
2604
2605/*
2606 * qla2x00_find_all_fabric_devs
2607 *
2608 * Input:
2609 * ha = adapter block pointer.
2610 * dev = database device entry pointer.
2611 *
2612 * Returns:
2613 * 0 = success.
2614 *
2615 * Context:
2616 * Kernel context.
2617 */
2618static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002619qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2620 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621{
2622 int rval;
2623 uint16_t loop_id;
2624 fc_port_t *fcport, *new_fcport, *fcptemp;
2625 int found;
2626
2627 sw_info_t *swl;
2628 int swl_idx;
2629 int first_dev, last_dev;
2630 port_id_t wrap, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002631 struct qla_hw_data *ha = vha->hw;
2632 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002633 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634
2635 rval = QLA_SUCCESS;
2636
2637 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07002638 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002639 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 /*EMPTY*/
2641 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002642 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002644 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 kfree(swl);
2646 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002647 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 kfree(swl);
2649 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002650 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 kfree(swl);
2652 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07002653 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002654 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2655 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 }
2657 }
2658 swl_idx = 0;
2659
2660 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002661 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002663 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 return (QLA_MEMORY_ALLOC_FAILED);
2665 }
2666 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 /* Set start port ID scan at adapter ID. */
2668 first_dev = 1;
2669 last_dev = 0;
2670
2671 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002672 loop_id = ha->min_external_loopid;
2673 for (; loop_id <= ha->max_loop_id; loop_id++) {
2674 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 continue;
2676
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002677 if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 break;
2679
2680 if (swl != NULL) {
2681 if (last_dev) {
2682 wrap.b24 = new_fcport->d_id.b24;
2683 } else {
2684 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2685 memcpy(new_fcport->node_name,
2686 swl[swl_idx].node_name, WWN_SIZE);
2687 memcpy(new_fcport->port_name,
2688 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002689 memcpy(new_fcport->fabric_port_name,
2690 swl[swl_idx].fabric_port_name, WWN_SIZE);
2691 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692
2693 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2694 last_dev = 1;
2695 }
2696 swl_idx++;
2697 }
2698 } else {
2699 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002700 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 if (rval != QLA_SUCCESS) {
2702 qla_printk(KERN_WARNING, ha,
2703 "SNS scan failed -- assuming zero-entry "
2704 "result...\n");
2705 list_for_each_entry_safe(fcport, fcptemp,
2706 new_fcports, list) {
2707 list_del(&fcport->list);
2708 kfree(fcport);
2709 }
2710 rval = QLA_SUCCESS;
2711 break;
2712 }
2713 }
2714
2715 /* If wrap on switch device list, exit. */
2716 if (first_dev) {
2717 wrap.b24 = new_fcport->d_id.b24;
2718 first_dev = 0;
2719 } else if (new_fcport->d_id.b24 == wrap.b24) {
2720 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002721 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2723 break;
2724 }
2725
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002726 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002727 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 continue;
2729
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002730 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002731 found = 0;
2732 if (ha->num_vhosts) {
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002733 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002734 if (new_fcport->d_id.b24 == vp->d_id.b24) {
2735 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002736 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002737 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002738 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002739 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002740 continue;
2741 }
2742
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002743 /* Bypass if same domain and area of adapter. */
2744 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002745 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002746 ISP_CFG_FL)
2747 continue;
2748
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749 /* Bypass reserved domain fields. */
2750 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2751 continue;
2752
2753 /* Locate matching device in database. */
2754 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002755 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 if (memcmp(new_fcport->port_name, fcport->port_name,
2757 WWN_SIZE))
2758 continue;
2759
2760 found++;
2761
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002762 /* Update port state. */
2763 memcpy(fcport->fabric_port_name,
2764 new_fcport->fabric_port_name, WWN_SIZE);
2765 fcport->fp_speed = new_fcport->fp_speed;
2766
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 /*
2768 * If address the same and state FCS_ONLINE, nothing
2769 * changed.
2770 */
2771 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2772 atomic_read(&fcport->state) == FCS_ONLINE) {
2773 break;
2774 }
2775
2776 /*
2777 * If device was not a fabric device before.
2778 */
2779 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2780 fcport->d_id.b24 = new_fcport->d_id.b24;
2781 fcport->loop_id = FC_NO_LOOP_ID;
2782 fcport->flags |= (FCF_FABRIC_DEVICE |
2783 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 break;
2785 }
2786
2787 /*
2788 * Port ID changed or device was marked to be updated;
2789 * Log it out if still logged in and mark it for
2790 * relogin later.
2791 */
2792 fcport->d_id.b24 = new_fcport->d_id.b24;
2793 fcport->flags |= FCF_LOGIN_NEEDED;
2794 if (fcport->loop_id != FC_NO_LOOP_ID &&
2795 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2796 fcport->port_type != FCT_INITIATOR &&
2797 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002798 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002799 fcport->d_id.b.domain, fcport->d_id.b.area,
2800 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 fcport->loop_id = FC_NO_LOOP_ID;
2802 }
2803
2804 break;
2805 }
2806
2807 if (found)
2808 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809 /* If device was not in our fcports list, then add it. */
2810 list_add_tail(&new_fcport->list, new_fcports);
2811
2812 /* Allocate a new replacement fcport. */
2813 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002814 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002816 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 return (QLA_MEMORY_ALLOC_FAILED);
2818 }
2819 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2820 new_fcport->d_id.b24 = nxt_d_id.b24;
2821 }
2822
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002823 kfree(swl);
2824 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 return (rval);
2827}
2828
2829/*
2830 * qla2x00_find_new_loop_id
2831 * Scan through our port list and find a new usable loop ID.
2832 *
2833 * Input:
2834 * ha: adapter state pointer.
2835 * dev: port structure pointer.
2836 *
2837 * Returns:
2838 * qla2x00 local function return status code.
2839 *
2840 * Context:
2841 * Kernel context.
2842 */
Adrian Bunk413975a2006-06-30 02:33:06 -07002843static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002844qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845{
2846 int rval;
2847 int found;
2848 fc_port_t *fcport;
2849 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002850 struct qla_hw_data *ha = vha->hw;
2851 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002852 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853
2854 rval = QLA_SUCCESS;
2855
2856 /* Save starting loop ID. */
2857 first_loop_id = dev->loop_id;
2858
2859 for (;;) {
2860 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002861 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863
2864 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002865 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867
2868 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002869 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 /* first loop ID. */
2871 dev->loop_id = ha->min_external_loopid;
2872 }
2873
2874 /* Check for loop ID being already in use. */
2875 found = 0;
2876 fcport = NULL;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002877 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002878 list_for_each_entry(fcport, &vp->vp_fcports, list) {
2879 if (fcport->loop_id == dev->loop_id &&
2880 fcport != dev) {
2881 /* ID possibly in use */
2882 found++;
2883 break;
2884 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002886 if (found)
2887 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 }
2889
2890 /* If not in use then it is free to use. */
2891 if (!found) {
2892 break;
2893 }
2894
2895 /* ID in use. Try next value. */
2896 dev->loop_id++;
2897
2898 /* If wrap around. No free ID to use. */
2899 if (dev->loop_id == first_loop_id) {
2900 dev->loop_id = FC_NO_LOOP_ID;
2901 rval = QLA_FUNCTION_FAILED;
2902 break;
2903 }
2904 }
2905
2906 return (rval);
2907}
2908
2909/*
2910 * qla2x00_device_resync
2911 * Marks devices in the database that needs resynchronization.
2912 *
2913 * Input:
2914 * ha = adapter block pointer.
2915 *
2916 * Context:
2917 * Kernel context.
2918 */
2919static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002920qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921{
2922 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 uint32_t mask;
2924 fc_port_t *fcport;
2925 uint32_t rscn_entry;
2926 uint8_t rscn_out_iter;
2927 uint8_t format;
2928 port_id_t d_id;
2929
2930 rval = QLA_RSCNS_HANDLED;
2931
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002932 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
2933 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002935 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 format = MSB(MSW(rscn_entry));
2937 d_id.b.domain = LSB(MSW(rscn_entry));
2938 d_id.b.area = MSB(LSW(rscn_entry));
2939 d_id.b.al_pa = LSB(LSW(rscn_entry));
2940
2941 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2942 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002943 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 d_id.b.area, d_id.b.al_pa));
2945
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002946 vha->rscn_out_ptr++;
2947 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
2948 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949
2950 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002951 for (rscn_out_iter = vha->rscn_out_ptr;
2952 !vha->flags.rscn_queue_overflow &&
2953 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 rscn_out_iter = (rscn_out_iter ==
2955 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2956
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002957 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958 break;
2959
2960 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002961 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 rscn_out_iter));
2963
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002964 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 }
2966
2967 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002968 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002970 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971
2972 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002973 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 }
2975
2976 switch (format) {
2977 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 mask = 0xffffff;
2979 break;
2980 case 1:
2981 mask = 0xffff00;
2982 break;
2983 case 2:
2984 mask = 0xff0000;
2985 break;
2986 default:
2987 mask = 0x0;
2988 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002989 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 break;
2991 }
2992
2993 rval = QLA_SUCCESS;
2994
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002995 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2997 (fcport->d_id.b24 & mask) != d_id.b24 ||
2998 fcport->port_type == FCT_BROADCAST)
2999 continue;
3000
3001 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3002 if (format != 3 ||
3003 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003004 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003005 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006 }
3007 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008 }
3009 }
3010 return (rval);
3011}
3012
3013/*
3014 * qla2x00_fabric_dev_login
3015 * Login fabric target device and update FC port database.
3016 *
3017 * Input:
3018 * ha: adapter state pointer.
3019 * fcport: port structure list pointer.
3020 * next_loopid: contains value of a new loop ID that can be used
3021 * by the next login attempt.
3022 *
3023 * Returns:
3024 * qla2x00 local function return status code.
3025 *
3026 * Context:
3027 * Kernel context.
3028 */
3029static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003030qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 uint16_t *next_loopid)
3032{
3033 int rval;
3034 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003035 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003036 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037
3038 rval = QLA_SUCCESS;
3039 retry = 0;
3040
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003041 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 if (rval == QLA_SUCCESS) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003043 /* Send an ADISC to tape devices.*/
3044 opts = 0;
3045 if (fcport->flags & FCF_TAPE_PRESENT)
3046 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003047 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003049 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003050 fcport->d_id.b.domain, fcport->d_id.b.area,
3051 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003052 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003054 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 }
3056 }
3057
3058 return (rval);
3059}
3060
3061/*
3062 * qla2x00_fabric_login
3063 * Issue fabric login command.
3064 *
3065 * Input:
3066 * ha = adapter block pointer.
3067 * device = pointer to FC device type structure.
3068 *
3069 * Returns:
3070 * 0 - Login successfully
3071 * 1 - Login failed
3072 * 2 - Initiator device
3073 * 3 - Fatal error
3074 */
3075int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003076qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 uint16_t *next_loopid)
3078{
3079 int rval;
3080 int retry;
3081 uint16_t tmp_loopid;
3082 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003083 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084
3085 retry = 0;
3086 tmp_loopid = 0;
3087
3088 for (;;) {
3089 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3090 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003091 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3093
3094 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003095 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 fcport->d_id.b.domain, fcport->d_id.b.area,
3097 fcport->d_id.b.al_pa, mb, BIT_0);
3098 if (mb[0] == MBS_PORT_ID_USED) {
3099 /*
3100 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003101 * recommends the driver perform an implicit login with
3102 * the specified ID again. The ID we just used is save
3103 * here so we return with an ID that can be tried by
3104 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105 */
3106 retry++;
3107 tmp_loopid = fcport->loop_id;
3108 fcport->loop_id = mb[1];
3109
3110 DEBUG(printk("Fabric Login: port in use - next "
3111 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3112 fcport->loop_id, fcport->d_id.b.domain,
3113 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3114
3115 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3116 /*
3117 * Login succeeded.
3118 */
3119 if (retry) {
3120 /* A retry occurred before. */
3121 *next_loopid = tmp_loopid;
3122 } else {
3123 /*
3124 * No retry occurred before. Just increment the
3125 * ID value for next login.
3126 */
3127 *next_loopid = (fcport->loop_id + 1);
3128 }
3129
3130 if (mb[1] & BIT_0) {
3131 fcport->port_type = FCT_INITIATOR;
3132 } else {
3133 fcport->port_type = FCT_TARGET;
3134 if (mb[1] & BIT_1) {
3135 fcport->flags |= FCF_TAPE_PRESENT;
3136 }
3137 }
3138
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003139 if (mb[10] & BIT_0)
3140 fcport->supported_classes |= FC_COS_CLASS2;
3141 if (mb[10] & BIT_1)
3142 fcport->supported_classes |= FC_COS_CLASS3;
3143
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144 rval = QLA_SUCCESS;
3145 break;
3146 } else if (mb[0] == MBS_LOOP_ID_USED) {
3147 /*
3148 * Loop ID already used, try next loop ID.
3149 */
3150 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003151 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 if (rval != QLA_SUCCESS) {
3153 /* Ran out of loop IDs to use */
3154 break;
3155 }
3156 } else if (mb[0] == MBS_COMMAND_ERROR) {
3157 /*
3158 * Firmware possibly timed out during login. If NO
3159 * retries are left to do then the device is declared
3160 * dead.
3161 */
3162 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003163 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003164 fcport->d_id.b.domain, fcport->d_id.b.area,
3165 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003166 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167
3168 rval = 1;
3169 break;
3170 } else {
3171 /*
3172 * unrecoverable / not handled error
3173 */
3174 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003175 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003176 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 fcport->d_id.b.domain, fcport->d_id.b.area,
3178 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3179
3180 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003181 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003182 fcport->d_id.b.domain, fcport->d_id.b.area,
3183 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003185 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186
3187 rval = 3;
3188 break;
3189 }
3190 }
3191
3192 return (rval);
3193}
3194
3195/*
3196 * qla2x00_local_device_login
3197 * Issue local device login command.
3198 *
3199 * Input:
3200 * ha = adapter block pointer.
3201 * loop_id = loop id of device to login to.
3202 *
3203 * Returns (Where's the #define!!!!):
3204 * 0 - Login successfully
3205 * 1 - Login failed
3206 * 3 - Fatal error
3207 */
3208int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003209qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210{
3211 int rval;
3212 uint16_t mb[MAILBOX_REGISTER_COUNT];
3213
3214 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003215 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216 if (rval == QLA_SUCCESS) {
3217 /* Interrogate mailbox registers for any errors */
3218 if (mb[0] == MBS_COMMAND_ERROR)
3219 rval = 1;
3220 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3221 /* device not in PCB table */
3222 rval = 3;
3223 }
3224
3225 return (rval);
3226}
3227
3228/*
3229 * qla2x00_loop_resync
3230 * Resync with fibre channel devices.
3231 *
3232 * Input:
3233 * ha = adapter block pointer.
3234 *
3235 * Returns:
3236 * 0 = success
3237 */
3238int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003239qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003241 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003243 struct req_que *req;
3244 struct rsp_que *rsp;
3245
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003246 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003247 req = vha->hw->req_q_map[0];
3248 else
3249 req = vha->req;
3250 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003252 atomic_set(&vha->loop_state, LOOP_UPDATE);
3253 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3254 if (vha->flags.online) {
3255 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3257 wait_time = 256;
3258 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003259 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003261 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003262 qla2x00_marker(vha, req, rsp, 0, 0,
3263 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003264 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265
3266 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003267 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003269 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003271 } while (!atomic_read(&vha->loop_down_timer) &&
3272 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3273 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3274 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 }
3277
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003278 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003281 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283
3284 return (rval);
3285}
3286
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003288qla2x00_update_fcports(scsi_qla_host_t *vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003289{
3290 fc_port_t *fcport;
3291
3292 /* Go with deferred removal of rport references. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003293 list_for_each_entry(fcport, &vha->vp_fcports, list)
3294 if (fcport && fcport->drport &&
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07003295 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003296 qla2x00_rport_del(fcport);
3297}
3298
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299/*
3300* qla2x00_abort_isp
3301* Resets ISP and aborts all outstanding commands.
3302*
3303* Input:
3304* ha = adapter block pointer.
3305*
3306* Returns:
3307* 0 = success
3308*/
3309int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003310qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003312 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003314 struct qla_hw_data *ha = vha->hw;
3315 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003316 struct scsi_qla_host *tvp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003317 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003319 if (vha->flags.online) {
3320 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -07003321 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003322 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07003323 ha->qla_stats.total_isp_aborts++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324
3325 qla_printk(KERN_INFO, ha,
3326 "Performing ISP error recovery - ha= %p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003327 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003329 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3330 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3331 atomic_set(&vha->loop_state, LOOP_DOWN);
3332 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003333 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003334 qla2x00_mark_all_devices_lost(vp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003336 if (!atomic_read(&vha->loop_down_timer))
3337 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338 LOOP_DOWN_TIME);
3339 }
3340
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341 /* Requeue all commands in outstanding command list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003342 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003344 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003345
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003346 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003347
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003348 if (!qla2x00_restart_isp(vha)) {
3349 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003351 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352 /*
3353 * Issue marker command only when we are going
3354 * to start the I/O .
3355 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003356 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357 }
3358
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003359 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003361 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003363 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003364 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003365
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003366 if (ha->fce) {
3367 ha->flags.fce_enabled = 1;
3368 memset(ha->fce, 0,
3369 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003370 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003371 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3372 &ha->fce_bufs);
3373 if (rval) {
3374 qla_printk(KERN_WARNING, ha,
3375 "Unable to reinitialize FCE "
3376 "(%d).\n", rval);
3377 ha->flags.fce_enabled = 0;
3378 }
3379 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003380
3381 if (ha->eft) {
3382 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003383 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003384 ha->eft_dma, EFT_NUM_BUFFERS);
3385 if (rval) {
3386 qla_printk(KERN_WARNING, ha,
3387 "Unable to reinitialize EFT "
3388 "(%d).\n", rval);
3389 }
3390 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003392 vha->flags.online = 1;
3393 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394 if (ha->isp_abort_cnt == 0) {
3395 qla_printk(KERN_WARNING, ha,
3396 "ISP error recovery failed - "
3397 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003398 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399 * The next call disables the board
3400 * completely.
3401 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003402 ha->isp_ops->reset_adapter(vha);
3403 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003405 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406 status = 0;
3407 } else { /* schedule another ISP abort */
3408 ha->isp_abort_cnt--;
3409 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003410 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003411 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412 status = 1;
3413 }
3414 } else {
3415 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3416 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3417 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003418 vha->host_no, ha->isp_abort_cnt));
3419 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420 status = 1;
3421 }
3422 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003423
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424 }
3425
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003426 if (!status) {
3427 DEBUG(printk(KERN_INFO
3428 "qla2x00_abort_isp(%ld): succeeded.\n",
3429 vha->host_no));
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003430 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003431 if (vp->vp_idx)
3432 qla2x00_vp_abort_isp(vp);
3433 }
3434 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435 qla_printk(KERN_INFO, ha,
3436 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 }
3438
3439 return(status);
3440}
3441
3442/*
3443* qla2x00_restart_isp
3444* restarts the ISP after a reset
3445*
3446* Input:
3447* ha = adapter block pointer.
3448*
3449* Returns:
3450* 0 = success
3451*/
3452static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003453qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003455 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003457 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003458 struct req_que *req = ha->req_q_map[0];
3459 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460
3461 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003462 if (qla2x00_isp_firmware(vha)) {
3463 vha->flags.online = 0;
3464 status = ha->isp_ops->chip_diag(vha);
3465 if (!status)
3466 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467 }
3468
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003469 if (!status && !(status = qla2x00_init_rings(vha))) {
3470 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07003471 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003472 /* Initialize the queues in use */
3473 qla25xx_init_queues(ha);
3474
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003475 status = qla2x00_fw_ready(vha);
3476 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003478 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003479
3480 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003481 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003482
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003483 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3485 wait_time = 256;
3486 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003487 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3488 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003490 } while (!atomic_read(&vha->loop_down_timer) &&
3491 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3492 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3493 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494 }
3495
3496 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003497 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498 status = 0;
3499
3500 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3501 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003502 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503 }
3504 return (status);
3505}
3506
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003507static int
3508qla25xx_init_queues(struct qla_hw_data *ha)
3509{
3510 struct rsp_que *rsp = NULL;
3511 struct req_que *req = NULL;
3512 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3513 int ret = -1;
3514 int i;
3515
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003516 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003517 rsp = ha->rsp_q_map[i];
3518 if (rsp) {
3519 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003520 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003521 if (ret != QLA_SUCCESS)
3522 DEBUG2_17(printk(KERN_WARNING
3523 "%s Rsp que:%d init failed\n", __func__,
3524 rsp->id));
3525 else
3526 DEBUG2_17(printk(KERN_INFO
3527 "%s Rsp que:%d inited\n", __func__,
3528 rsp->id));
3529 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003530 }
3531 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003532 req = ha->req_q_map[i];
3533 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003534 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003535 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003536 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003537 if (ret != QLA_SUCCESS)
3538 DEBUG2_17(printk(KERN_WARNING
3539 "%s Req que:%d init failed\n", __func__,
3540 req->id));
3541 else
3542 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003543 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003544 req->id));
3545 }
3546 }
3547 return ret;
3548}
3549
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550/*
3551* qla2x00_reset_adapter
3552* Reset adapter.
3553*
3554* Input:
3555* ha = adapter block pointer.
3556*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003557void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003558qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559{
3560 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003561 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003562 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003563
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003564 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003565 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566
Linus Torvalds1da177e2005-04-16 15:20:36 -07003567 spin_lock_irqsave(&ha->hardware_lock, flags);
3568 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3569 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3570 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3571 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3572 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3573}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003574
3575void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003576qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003577{
3578 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003579 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003580 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3581
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003582 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003583 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003584
3585 spin_lock_irqsave(&ha->hardware_lock, flags);
3586 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3587 RD_REG_DWORD(&reg->hccr);
3588 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3589 RD_REG_DWORD(&reg->hccr);
3590 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08003591
3592 if (IS_NOPOLLING_TYPE(ha))
3593 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003594}
3595
David Miller4e08df32007-04-16 12:37:43 -07003596/* On sparc systems, obtain port and node WWN from firmware
3597 * properties.
3598 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003599static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3600 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07003601{
3602#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003603 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003604 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003605 struct device_node *dp = pci_device_to_OF_node(pdev);
3606 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003607 int len;
3608
3609 val = of_get_property(dp, "port-wwn", &len);
3610 if (val && len >= WWN_SIZE)
3611 memcpy(nv->port_name, val, WWN_SIZE);
3612
3613 val = of_get_property(dp, "node-wwn", &len);
3614 if (val && len >= WWN_SIZE)
3615 memcpy(nv->node_name, val, WWN_SIZE);
3616#endif
3617}
3618
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003619int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003620qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003621{
David Miller4e08df32007-04-16 12:37:43 -07003622 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003623 struct init_cb_24xx *icb;
3624 struct nvram_24xx *nv;
3625 uint32_t *dptr;
3626 uint8_t *dptr1, *dptr2;
3627 uint32_t chksum;
3628 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003629 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003630
David Miller4e08df32007-04-16 12:37:43 -07003631 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003632 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003633 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003634
3635 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07003636 if (ha->flags.port0) {
3637 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3638 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3639 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003640 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003641 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3642 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07003643 ha->nvram_size = sizeof(struct nvram_24xx);
3644 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003645
Seokmann Ju281afe12007-07-26 13:43:34 -07003646 /* Get VPD data into cache */
3647 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003648 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07003649 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3650
3651 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003652 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003653 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003654 ha->nvram_size);
3655 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3656 chksum += le32_to_cpu(*dptr++);
3657
Andrew Vasquez76403352009-04-06 22:33:39 -07003658 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07003659 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003660
3661 /* Bad NVRAM data, set defaults parameters. */
3662 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3663 || nv->id[3] != ' ' ||
3664 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3665 /* Reset NVRAM data. */
3666 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3667 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3668 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07003669 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3670 "invalid -- WWPN) defaults.\n");
3671
3672 /*
3673 * Set default initialization control block.
3674 */
3675 memset(nv, 0, ha->nvram_size);
3676 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3677 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3678 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3679 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3680 nv->exchange_count = __constant_cpu_to_le16(0);
3681 nv->hard_address = __constant_cpu_to_le16(124);
3682 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07003683 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07003684 nv->port_name[2] = 0x00;
3685 nv->port_name[3] = 0xe0;
3686 nv->port_name[4] = 0x8b;
3687 nv->port_name[5] = 0x1c;
3688 nv->port_name[6] = 0x55;
3689 nv->port_name[7] = 0x86;
3690 nv->node_name[0] = 0x20;
3691 nv->node_name[1] = 0x00;
3692 nv->node_name[2] = 0x00;
3693 nv->node_name[3] = 0xe0;
3694 nv->node_name[4] = 0x8b;
3695 nv->node_name[5] = 0x1c;
3696 nv->node_name[6] = 0x55;
3697 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003698 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07003699 nv->login_retry_count = __constant_cpu_to_le16(8);
3700 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3701 nv->login_timeout = __constant_cpu_to_le16(0);
3702 nv->firmware_options_1 =
3703 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3704 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3705 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3706 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3707 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3708 nv->efi_parameters = __constant_cpu_to_le32(0);
3709 nv->reset_delay = 5;
3710 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3711 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3712 nv->link_down_timeout = __constant_cpu_to_le16(30);
3713
3714 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003715 }
3716
3717 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003718 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003719
3720 /* Copy 1st segment. */
3721 dptr1 = (uint8_t *)icb;
3722 dptr2 = (uint8_t *)&nv->version;
3723 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3724 while (cnt--)
3725 *dptr1++ = *dptr2++;
3726
3727 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07003728 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003729
3730 /* Copy 2nd segment. */
3731 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3732 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3733 cnt = (uint8_t *)&icb->reserved_3 -
3734 (uint8_t *)&icb->interrupt_delay_timer;
3735 while (cnt--)
3736 *dptr1++ = *dptr2++;
3737
3738 /*
3739 * Setup driver NVRAM options.
3740 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003741 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003742 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003743
Andrew Vasquez5341e862006-05-17 15:09:16 -07003744 /* Use alternate WWN? */
3745 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3746 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3747 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3748 }
3749
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003750 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003751 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003752 /*
3753 * Firmware will apply the following mask if the nodename was
3754 * not provided.
3755 */
3756 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3757 icb->node_name[0] &= 0xF0;
3758 }
3759
3760 /* Set host adapter parameters. */
3761 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08003762 ha->flags.enable_lip_reset = 0;
3763 ha->flags.enable_lip_full_login =
3764 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3765 ha->flags.enable_target_reset =
3766 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003767 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07003768 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003769
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003770 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3771 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003772
3773 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3774 sizeof(ha->fw_seriallink_options24));
3775
3776 /* save HBA serial number */
3777 ha->serial0 = icb->port_name[5];
3778 ha->serial1 = icb->port_name[6];
3779 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003780 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
3781 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003782
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08003783 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3784
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003785 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3786
3787 /* Set minimum login_timeout to 4 seconds. */
3788 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3789 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3790 if (le16_to_cpu(nv->login_timeout) < 4)
3791 nv->login_timeout = __constant_cpu_to_le16(4);
3792 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07003793 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003794
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003795 /* Set minimum RATOV to 100 tenths of a second. */
3796 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003797
3798 ha->loop_reset_delay = nv->reset_delay;
3799
3800 /* Link Down Timeout = 0:
3801 *
3802 * When Port Down timer expires we will start returning
3803 * I/O's to OS with "DID_NO_CONNECT".
3804 *
3805 * Link Down Timeout != 0:
3806 *
3807 * The driver waits for the link to come up after link down
3808 * before returning I/Os to OS with "DID_NO_CONNECT".
3809 */
3810 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3811 ha->loop_down_abort_time =
3812 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3813 } else {
3814 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3815 ha->loop_down_abort_time =
3816 (LOOP_DOWN_TIME - ha->link_down_timeout);
3817 }
3818
3819 /* Need enough time to try and get the port back. */
3820 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3821 if (qlport_down_retry)
3822 ha->port_down_retry_count = qlport_down_retry;
3823
3824 /* Set login_retry_count */
3825 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3826 if (ha->port_down_retry_count ==
3827 le16_to_cpu(nv->port_down_retry_count) &&
3828 ha->port_down_retry_count > 3)
3829 ha->login_retry_count = ha->port_down_retry_count;
3830 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3831 ha->login_retry_count = ha->port_down_retry_count;
3832 if (ql2xloginretrycount)
3833 ha->login_retry_count = ql2xloginretrycount;
3834
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003835 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003836 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003837 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3838 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3839 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3840 le16_to_cpu(icb->interrupt_delay_timer): 2;
3841 }
3842 icb->firmware_options_2 &= __constant_cpu_to_le32(
3843 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003844 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003845 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08003846 ha->zio_mode = QLA_ZIO_MODE_6;
3847
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003848 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003849 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003850 ha->zio_timer * 100));
3851 qla_printk(KERN_INFO, ha,
3852 "ZIO mode %d enabled; timer delay (%d us).\n",
3853 ha->zio_mode, ha->zio_timer * 100);
3854
3855 icb->firmware_options_2 |= cpu_to_le32(
3856 (uint32_t)ha->zio_mode);
3857 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003858 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003859 }
3860
David Miller4e08df32007-04-16 12:37:43 -07003861 if (rval) {
3862 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003863 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07003864 }
3865 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003866}
3867
Adrian Bunk413975a2006-06-30 02:33:06 -07003868static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003869qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
3870 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003871{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003872 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003873 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003874 uint32_t *dcode, dlen;
3875 uint32_t risc_addr;
3876 uint32_t risc_size;
3877 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003878 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003879 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08003880
3881 qla_printk(KERN_INFO, ha,
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003882 "FW: Loading from flash (%x)...\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08003883
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003884 rval = QLA_SUCCESS;
3885
3886 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003887 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003888 *srisc_addr = 0;
3889
3890 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003891 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003892 for (i = 0; i < 4; i++)
3893 dcode[i] = be32_to_cpu(dcode[i]);
3894 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3895 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3896 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3897 dcode[3] == 0)) {
3898 qla_printk(KERN_WARNING, ha,
3899 "Unable to verify integrity of flash firmware image!\n");
3900 qla_printk(KERN_WARNING, ha,
3901 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3902 dcode[1], dcode[2], dcode[3]);
3903
3904 return QLA_FUNCTION_FAILED;
3905 }
3906
3907 while (segments && rval == QLA_SUCCESS) {
3908 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003909 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003910
3911 risc_addr = be32_to_cpu(dcode[2]);
3912 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3913 risc_size = be32_to_cpu(dcode[3]);
3914
3915 fragment = 0;
3916 while (risc_size > 0 && rval == QLA_SUCCESS) {
3917 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3918 if (dlen > risc_size)
3919 dlen = risc_size;
3920
3921 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3922 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003923 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003924
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003925 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003926 for (i = 0; i < dlen; i++)
3927 dcode[i] = swab32(dcode[i]);
3928
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003929 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003930 dlen);
3931 if (rval) {
3932 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003933 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003934 fragment));
3935 qla_printk(KERN_WARNING, ha,
3936 "[ERROR] Failed to load segment %d of "
3937 "firmware\n", fragment);
3938 break;
3939 }
3940
3941 faddr += dlen;
3942 risc_addr += dlen;
3943 risc_size -= dlen;
3944 fragment++;
3945 }
3946
3947 /* Next segment. */
3948 segments--;
3949 }
3950
3951 return rval;
3952}
3953
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003954#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3955
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003956int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003957qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08003958{
3959 int rval;
3960 int i, fragment;
3961 uint16_t *wcode, *fwcode;
3962 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3963 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003964 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003965 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08003966
3967 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003968 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08003969 if (!blob) {
3970 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003971 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3972 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08003973 return QLA_FUNCTION_FAILED;
3974 }
3975
3976 rval = QLA_SUCCESS;
3977
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003978 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08003979 *srisc_addr = 0;
3980 fwcode = (uint16_t *)blob->fw->data;
3981 fwclen = 0;
3982
3983 /* Validate firmware image by checking version. */
3984 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3985 qla_printk(KERN_WARNING, ha,
3986 "Unable to verify integrity of firmware image (%Zd)!\n",
3987 blob->fw->size);
3988 goto fail_fw_integrity;
3989 }
3990 for (i = 0; i < 4; i++)
3991 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3992 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3993 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3994 wcode[2] == 0 && wcode[3] == 0)) {
3995 qla_printk(KERN_WARNING, ha,
3996 "Unable to verify integrity of firmware image!\n");
3997 qla_printk(KERN_WARNING, ha,
3998 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3999 wcode[1], wcode[2], wcode[3]);
4000 goto fail_fw_integrity;
4001 }
4002
4003 seg = blob->segs;
4004 while (*seg && rval == QLA_SUCCESS) {
4005 risc_addr = *seg;
4006 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4007 risc_size = be16_to_cpu(fwcode[3]);
4008
4009 /* Validate firmware image size. */
4010 fwclen += risc_size * sizeof(uint16_t);
4011 if (blob->fw->size < fwclen) {
4012 qla_printk(KERN_WARNING, ha,
4013 "Unable to verify integrity of firmware image "
4014 "(%Zd)!\n", blob->fw->size);
4015 goto fail_fw_integrity;
4016 }
4017
4018 fragment = 0;
4019 while (risc_size > 0 && rval == QLA_SUCCESS) {
4020 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4021 if (wlen > risc_size)
4022 wlen = risc_size;
4023
4024 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004025 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004026 risc_addr, wlen));
4027
4028 for (i = 0; i < wlen; i++)
4029 wcode[i] = swab16(fwcode[i]);
4030
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004031 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004032 wlen);
4033 if (rval) {
4034 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004035 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004036 fragment));
4037 qla_printk(KERN_WARNING, ha,
4038 "[ERROR] Failed to load segment %d of "
4039 "firmware\n", fragment);
4040 break;
4041 }
4042
4043 fwcode += wlen;
4044 risc_addr += wlen;
4045 risc_size -= wlen;
4046 fragment++;
4047 }
4048
4049 /* Next segment. */
4050 seg++;
4051 }
4052 return rval;
4053
4054fail_fw_integrity:
4055 return QLA_FUNCTION_FAILED;
4056}
4057
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004058static int
4059qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004060{
4061 int rval;
4062 int segments, fragment;
4063 uint32_t *dcode, dlen;
4064 uint32_t risc_addr;
4065 uint32_t risc_size;
4066 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004067 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004068 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004069 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004070 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004071
Andrew Vasquez54333832005-11-09 15:49:04 -08004072 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004073 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004074 if (!blob) {
4075 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004076 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4077 "from: " QLA_FW_URL ".\n");
4078
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004079 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004080 }
4081
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004082 qla_printk(KERN_INFO, ha,
4083 "FW: Loading via request-firmware...\n");
4084
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004085 rval = QLA_SUCCESS;
4086
4087 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004088 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004089 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004090 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004091 fwclen = 0;
4092
4093 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004094 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004095 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004096 "Unable to verify integrity of firmware image (%Zd)!\n",
4097 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004098 goto fail_fw_integrity;
4099 }
4100 for (i = 0; i < 4; i++)
4101 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4102 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4103 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4104 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4105 dcode[3] == 0)) {
4106 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004107 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004108 qla_printk(KERN_WARNING, ha,
4109 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4110 dcode[1], dcode[2], dcode[3]);
4111 goto fail_fw_integrity;
4112 }
4113
4114 while (segments && rval == QLA_SUCCESS) {
4115 risc_addr = be32_to_cpu(fwcode[2]);
4116 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4117 risc_size = be32_to_cpu(fwcode[3]);
4118
4119 /* Validate firmware image size. */
4120 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004121 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004122 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004123 "Unable to verify integrity of firmware image "
4124 "(%Zd)!\n", blob->fw->size);
4125
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004126 goto fail_fw_integrity;
4127 }
4128
4129 fragment = 0;
4130 while (risc_size > 0 && rval == QLA_SUCCESS) {
4131 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4132 if (dlen > risc_size)
4133 dlen = risc_size;
4134
4135 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004136 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004137 risc_addr, dlen));
4138
4139 for (i = 0; i < dlen; i++)
4140 dcode[i] = swab32(fwcode[i]);
4141
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004142 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004143 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004144 if (rval) {
4145 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004146 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004147 fragment));
4148 qla_printk(KERN_WARNING, ha,
4149 "[ERROR] Failed to load segment %d of "
4150 "firmware\n", fragment);
4151 break;
4152 }
4153
4154 fwcode += dlen;
4155 risc_addr += dlen;
4156 risc_size -= dlen;
4157 fragment++;
4158 }
4159
4160 /* Next segment. */
4161 segments--;
4162 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004163 return rval;
4164
4165fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004166 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004167}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004168
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004169int
4170qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4171{
4172 int rval;
4173
Andrew Vasqueze337d902009-04-06 22:33:49 -07004174 if (ql2xfwloadbin == 1)
4175 return qla81xx_load_risc(vha, srisc_addr);
4176
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004177 /*
4178 * FW Load priority:
4179 * 1) Firmware via request-firmware interface (.bin file).
4180 * 2) Firmware residing in flash.
4181 */
4182 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4183 if (rval == QLA_SUCCESS)
4184 return rval;
4185
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004186 return qla24xx_load_risc_flash(vha, srisc_addr,
4187 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004188}
4189
4190int
4191qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4192{
4193 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004194 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004195
Andrew Vasqueze337d902009-04-06 22:33:49 -07004196 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004197 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07004198
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004199 /*
4200 * FW Load priority:
4201 * 1) Firmware residing in flash.
4202 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004203 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004204 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004205 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004206 if (rval == QLA_SUCCESS)
4207 return rval;
4208
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004209try_blob_fw:
4210 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4211 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4212 return rval;
4213
4214 qla_printk(KERN_ERR, ha,
4215 "FW: Attempting to fallback to golden firmware...\n");
4216 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4217 if (rval != QLA_SUCCESS)
4218 return rval;
4219
4220 qla_printk(KERN_ERR, ha,
4221 "FW: Please update operational firmware...\n");
4222 ha->flags.running_gold_fw = 1;
4223
4224 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004225}
4226
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004227void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004228qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004229{
4230 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004231 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004232
Andrew Vasqueze4289242007-07-19 15:05:56 -07004233 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004234 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004235 if (!ha->fw_major_version)
4236 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004237
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004238 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004239 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07004240 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004241 ha->isp_ops->reset_chip(vha);
4242 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004243 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004244 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004245 continue;
4246 qla_printk(KERN_INFO, ha,
4247 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004248 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004249 }
4250}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004251
4252int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004253qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004254{
4255 int rval = QLA_SUCCESS;
4256 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004257 struct qla_hw_data *ha = vha->hw;
4258 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004259 struct req_que *req;
4260 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004261
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004262 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004263 return -EINVAL;
4264
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004265 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004266 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004267 req = ha->req_q_map[0];
4268 else
4269 req = vha->req;
4270 rsp = req->rsp;
4271
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004272 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004273 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004274 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004275 }
4276
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004277 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004278
4279 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004280 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004281 if (mb[0] != MBS_COMMAND_COMPLETE) {
4282 DEBUG15(qla_printk(KERN_INFO, ha,
4283 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4284 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4285 mb[0], mb[1], mb[2], mb[6], mb[7]));
4286 return (QLA_FUNCTION_FAILED);
4287 }
4288
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004289 atomic_set(&vha->loop_down_timer, 0);
4290 atomic_set(&vha->loop_state, LOOP_UP);
4291 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4292 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4293 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004294
4295 return rval;
4296}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004297
4298/* 84XX Support **************************************************************/
4299
4300static LIST_HEAD(qla_cs84xx_list);
4301static DEFINE_MUTEX(qla_cs84xx_mutex);
4302
4303static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004304qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004305{
4306 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004307 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004308
4309 mutex_lock(&qla_cs84xx_mutex);
4310
4311 /* Find any shared 84xx chip. */
4312 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4313 if (cs84xx->bus == ha->pdev->bus) {
4314 kref_get(&cs84xx->kref);
4315 goto done;
4316 }
4317 }
4318
4319 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4320 if (!cs84xx)
4321 goto done;
4322
4323 kref_init(&cs84xx->kref);
4324 spin_lock_init(&cs84xx->access_lock);
4325 mutex_init(&cs84xx->fw_update_mutex);
4326 cs84xx->bus = ha->pdev->bus;
4327
4328 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4329done:
4330 mutex_unlock(&qla_cs84xx_mutex);
4331 return cs84xx;
4332}
4333
4334static void
4335__qla84xx_chip_release(struct kref *kref)
4336{
4337 struct qla_chip_state_84xx *cs84xx =
4338 container_of(kref, struct qla_chip_state_84xx, kref);
4339
4340 mutex_lock(&qla_cs84xx_mutex);
4341 list_del(&cs84xx->list);
4342 mutex_unlock(&qla_cs84xx_mutex);
4343 kfree(cs84xx);
4344}
4345
4346void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004347qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004348{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004349 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004350 if (ha->cs84xx)
4351 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4352}
4353
4354static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004355qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004356{
4357 int rval;
4358 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004359 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004360
4361 mutex_lock(&ha->cs84xx->fw_update_mutex);
4362
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004363 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004364
4365 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4366
4367 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4368 QLA_SUCCESS;
4369}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004370
4371/* 81XX Support **************************************************************/
4372
4373int
4374qla81xx_nvram_config(scsi_qla_host_t *vha)
4375{
4376 int rval;
4377 struct init_cb_81xx *icb;
4378 struct nvram_81xx *nv;
4379 uint32_t *dptr;
4380 uint8_t *dptr1, *dptr2;
4381 uint32_t chksum;
4382 uint16_t cnt;
4383 struct qla_hw_data *ha = vha->hw;
4384
4385 rval = QLA_SUCCESS;
4386 icb = (struct init_cb_81xx *)ha->init_cb;
4387 nv = ha->nvram;
4388
4389 /* Determine NVRAM starting address. */
4390 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004391 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004392
4393 /* Get VPD data into cache */
4394 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004395 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
4396 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004397
4398 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004399 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004400 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004401 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004402 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4403 chksum += le32_to_cpu(*dptr++);
4404
Andrew Vasquez76403352009-04-06 22:33:39 -07004405 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004406 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4407
4408 /* Bad NVRAM data, set defaults parameters. */
4409 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4410 || nv->id[3] != ' ' ||
4411 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4412 /* Reset NVRAM data. */
4413 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4414 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4415 le16_to_cpu(nv->nvram_version));
4416 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4417 "invalid -- WWPN) defaults.\n");
4418
4419 /*
4420 * Set default initialization control block.
4421 */
4422 memset(nv, 0, ha->nvram_size);
4423 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4424 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4425 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4426 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4427 nv->exchange_count = __constant_cpu_to_le16(0);
4428 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004429 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004430 nv->port_name[2] = 0x00;
4431 nv->port_name[3] = 0xe0;
4432 nv->port_name[4] = 0x8b;
4433 nv->port_name[5] = 0x1c;
4434 nv->port_name[6] = 0x55;
4435 nv->port_name[7] = 0x86;
4436 nv->node_name[0] = 0x20;
4437 nv->node_name[1] = 0x00;
4438 nv->node_name[2] = 0x00;
4439 nv->node_name[3] = 0xe0;
4440 nv->node_name[4] = 0x8b;
4441 nv->node_name[5] = 0x1c;
4442 nv->node_name[6] = 0x55;
4443 nv->node_name[7] = 0x86;
4444 nv->login_retry_count = __constant_cpu_to_le16(8);
4445 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4446 nv->login_timeout = __constant_cpu_to_le16(0);
4447 nv->firmware_options_1 =
4448 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4449 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4450 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4451 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4452 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4453 nv->efi_parameters = __constant_cpu_to_le32(0);
4454 nv->reset_delay = 5;
4455 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4456 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4457 nv->link_down_timeout = __constant_cpu_to_le16(30);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07004458 nv->enode_mac[0] = 0x00;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004459 nv->enode_mac[1] = 0x02;
4460 nv->enode_mac[2] = 0x03;
4461 nv->enode_mac[3] = 0x04;
4462 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004463 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004464
4465 rval = 1;
4466 }
4467
4468 /* Reset Initialization control block */
4469 memset(icb, 0, sizeof(struct init_cb_81xx));
4470
4471 /* Copy 1st segment. */
4472 dptr1 = (uint8_t *)icb;
4473 dptr2 = (uint8_t *)&nv->version;
4474 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4475 while (cnt--)
4476 *dptr1++ = *dptr2++;
4477
4478 icb->login_retry_count = nv->login_retry_count;
4479
4480 /* Copy 2nd segment. */
4481 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4482 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4483 cnt = (uint8_t *)&icb->reserved_5 -
4484 (uint8_t *)&icb->interrupt_delay_timer;
4485 while (cnt--)
4486 *dptr1++ = *dptr2++;
4487
4488 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
4489 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4490 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
4491 icb->enode_mac[0] = 0x01;
4492 icb->enode_mac[1] = 0x02;
4493 icb->enode_mac[2] = 0x03;
4494 icb->enode_mac[3] = 0x04;
4495 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004496 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004497 }
4498
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004499 /* Use extended-initialization control block. */
4500 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
4501
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004502 /*
4503 * Setup driver NVRAM options.
4504 */
4505 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
4506 "QLE81XX");
4507
4508 /* Use alternate WWN? */
4509 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4510 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4511 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4512 }
4513
4514 /* Prepare nodename */
4515 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4516 /*
4517 * Firmware will apply the following mask if the nodename was
4518 * not provided.
4519 */
4520 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4521 icb->node_name[0] &= 0xF0;
4522 }
4523
4524 /* Set host adapter parameters. */
4525 ha->flags.disable_risc_code_load = 0;
4526 ha->flags.enable_lip_reset = 0;
4527 ha->flags.enable_lip_full_login =
4528 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4529 ha->flags.enable_target_reset =
4530 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4531 ha->flags.enable_led_scheme = 0;
4532 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4533
4534 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4535 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4536
4537 /* save HBA serial number */
4538 ha->serial0 = icb->port_name[5];
4539 ha->serial1 = icb->port_name[6];
4540 ha->serial2 = icb->port_name[7];
4541 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4542 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4543
4544 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4545
4546 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4547
4548 /* Set minimum login_timeout to 4 seconds. */
4549 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4550 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4551 if (le16_to_cpu(nv->login_timeout) < 4)
4552 nv->login_timeout = __constant_cpu_to_le16(4);
4553 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4554 icb->login_timeout = nv->login_timeout;
4555
4556 /* Set minimum RATOV to 100 tenths of a second. */
4557 ha->r_a_tov = 100;
4558
4559 ha->loop_reset_delay = nv->reset_delay;
4560
4561 /* Link Down Timeout = 0:
4562 *
4563 * When Port Down timer expires we will start returning
4564 * I/O's to OS with "DID_NO_CONNECT".
4565 *
4566 * Link Down Timeout != 0:
4567 *
4568 * The driver waits for the link to come up after link down
4569 * before returning I/Os to OS with "DID_NO_CONNECT".
4570 */
4571 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4572 ha->loop_down_abort_time =
4573 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4574 } else {
4575 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4576 ha->loop_down_abort_time =
4577 (LOOP_DOWN_TIME - ha->link_down_timeout);
4578 }
4579
4580 /* Need enough time to try and get the port back. */
4581 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4582 if (qlport_down_retry)
4583 ha->port_down_retry_count = qlport_down_retry;
4584
4585 /* Set login_retry_count */
4586 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4587 if (ha->port_down_retry_count ==
4588 le16_to_cpu(nv->port_down_retry_count) &&
4589 ha->port_down_retry_count > 3)
4590 ha->login_retry_count = ha->port_down_retry_count;
4591 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4592 ha->login_retry_count = ha->port_down_retry_count;
4593 if (ql2xloginretrycount)
4594 ha->login_retry_count = ql2xloginretrycount;
4595
4596 /* Enable ZIO. */
4597 if (!vha->flags.init_done) {
4598 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4599 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4600 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4601 le16_to_cpu(icb->interrupt_delay_timer): 2;
4602 }
4603 icb->firmware_options_2 &= __constant_cpu_to_le32(
4604 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4605 vha->flags.process_response_queue = 0;
4606 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4607 ha->zio_mode = QLA_ZIO_MODE_6;
4608
4609 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4610 "(%d us).\n", vha->host_no, ha->zio_mode,
4611 ha->zio_timer * 100));
4612 qla_printk(KERN_INFO, ha,
4613 "ZIO mode %d enabled; timer delay (%d us).\n",
4614 ha->zio_mode, ha->zio_timer * 100);
4615
4616 icb->firmware_options_2 |= cpu_to_le32(
4617 (uint32_t)ha->zio_mode);
4618 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4619 vha->flags.process_response_queue = 1;
4620 }
4621
4622 if (rval) {
4623 DEBUG2_3(printk(KERN_WARNING
4624 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4625 }
4626 return (rval);
4627}
4628
4629void
4630qla81xx_update_fw_options(scsi_qla_host_t *ha)
4631{
4632}