blob: bd7dd84c06485b4947ef4f38b66a799ff7230305 [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 Vasquez01071092005-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 Vasquez01071092005-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 Vasquez01071092005-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 Vasquez01071092005-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 Vasquez01071092005-07-06 10:31:37 -0700260{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700261 uint16_t w;
Andrew Vasquez01071092005-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 Vasquez01071092005-07-06 10:31:37 -0700264 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez01071092005-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 Vasquez01071092005-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 Vasquez01071092005-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 Vasquez01071092005-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 Vasquez01071092005-07-06 10:31:37 -0700283
Andrew Vasquez737faec2008-10-24 15:13:45 -0700284 pci_disable_rom(ha->pdev);
Andrew Vasquez01071092005-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 Vasquez01071092005-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 Vasquez01071092005-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 Vasquez01071092005-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 Vasquez01071092005-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 Vasquez01071092005-07-06 10:31:37 -0700521
Andrew Vasquez01071092005-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 Vasquez01071092005-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 Vasquez01071092005-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",
637 ha->host_no));
638
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 */
658 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
659
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 Vasquez01071092005-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 Vasquez01071092005-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 Vasquez01071092005-07-06 10:31:37 -0700732
Andrew Vasquez88c26662005-07-08 17:59:26 -0700733 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800734 qla24xx_reset_risc(vha);
Andrew Vasquez01071092005-07-06 10:31:37 -0700735
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800736 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez01071092005-07-06 10:31:37 -0700737
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800738 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez01071092005-07-06 10:31:37 -0700739 if (rval) {
740 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800741 vha->host_no));
Andrew Vasquez01071092005-07-06 10:31:37 -0700742 qla_printk(KERN_WARNING, ha,
743 "Failed mailbox send register test\n");
744 } else {
745 /* Flag a successful rval */
746 rval = QLA_SUCCESS;
747 }
748
749 return rval;
750}
751
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700752void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800753qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -0700754{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700755 int rval;
756 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800757 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800758 dma_addr_t tc_dma;
759 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800760 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800761 struct req_que *req = ha->req_q_map[0];
762 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700763
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700764 if (ha->fw_dump) {
765 qla_printk(KERN_WARNING, ha,
766 "Firmware dump previously allocated.\n");
767 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700768 }
769
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700770 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800771 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700772 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
773 fixed_size = sizeof(struct qla2100_fw_dump);
774 } else if (IS_QLA23XX(ha)) {
775 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
776 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
777 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -0700778 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800779 if (IS_QLA81XX(ha))
780 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
781 else if (IS_QLA25XX(ha))
782 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
783 else
784 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700785 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
786 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800787 if (ha->mqenable)
788 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700789
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700790 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800791 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700792 goto try_eft;
793
794 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
795 GFP_KERNEL);
796 if (!tc) {
797 qla_printk(KERN_WARNING, ha, "Unable to allocate "
798 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800799 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700800 }
801
802 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800803 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700804 ha->fce_mb, &ha->fce_bufs);
805 if (rval) {
806 qla_printk(KERN_WARNING, ha, "Unable to initialize "
807 "FCE (%d).\n", rval);
808 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
809 tc_dma);
810 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800811 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700812 }
813
814 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
815 FCE_SIZE / 1024);
816
Giridhar Malavali7d9dade2009-03-24 09:07:58 -0700817 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700818 ha->flags.fce_enabled = 1;
819 ha->fce_dma = tc_dma;
820 ha->fce = tc;
821try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700822 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800823 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700824 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800825 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700826 qla_printk(KERN_WARNING, ha, "Unable to allocate "
827 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
828 goto cont_alloc;
829 }
830
Andrew Vasquezfc447652008-01-17 09:02:18 -0800831 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800832 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700833 if (rval) {
834 qla_printk(KERN_WARNING, ha, "Unable to initialize "
835 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800836 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
837 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700838 goto cont_alloc;
839 }
840
841 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
842 EFT_SIZE / 1024);
843
844 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800845 ha->eft_dma = tc_dma;
846 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700847 }
848cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800849 req_q_size = req->length * sizeof(request_t);
850 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700851
852 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
853 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
Andrew Vasquezbb99de62009-01-05 11:18:08 -0800854 eft_size;
855 ha->chain_offset = dump_size;
856 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700857
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700858 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700859 if (!ha->fw_dump) {
Andrew Vasquez01071092005-07-06 10:31:37 -0700860 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700861 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700862
863 if (ha->eft) {
864 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
865 ha->eft_dma);
866 ha->eft = NULL;
867 ha->eft_dma = 0;
868 }
869 return;
870 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700871 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
872 dump_size / 1024);
873
874 ha->fw_dump_len = dump_size;
875 ha->fw_dump->signature[0] = 'Q';
876 ha->fw_dump->signature[1] = 'L';
877 ha->fw_dump->signature[2] = 'G';
878 ha->fw_dump->signature[3] = 'C';
879 ha->fw_dump->version = __constant_htonl(1);
880
881 ha->fw_dump->fixed_size = htonl(fixed_size);
882 ha->fw_dump->mem_size = htonl(mem_size);
883 ha->fw_dump->req_q_size = htonl(req_q_size);
884 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
885
886 ha->fw_dump->eft_size = htonl(eft_size);
887 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
888 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
889
890 ha->fw_dump->header_size =
891 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez01071092005-07-06 10:31:37 -0700892}
893
894/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 * qla2x00_setup_chip() - Load and start RISC firmware.
896 * @ha: HA context
897 *
898 * Returns 0 on success.
899 */
900static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800901qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902{
Andrew Vasquez01071092005-07-06 10:31:37 -0700903 int rval;
904 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800905 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -0800906 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
907 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -0700908 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -0800909
910 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
911 /* Disable SRAM, Instruction RAM and GP RAM parity. */
912 spin_lock_irqsave(&ha->hardware_lock, flags);
913 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
914 RD_REG_WORD(&reg->hccr);
915 spin_unlock_irqrestore(&ha->hardware_lock, flags);
916 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
918 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800919 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez01071092005-07-06 10:31:37 -0700920 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800922 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800924 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 if (rval == QLA_SUCCESS) {
926 /* Start firmware execution. */
927 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800928 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800930 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -0700932 if (rval == QLA_SUCCESS) {
933 fw_major_version = ha->fw_major_version;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800934 qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 &ha->fw_major_version,
936 &ha->fw_minor_version,
937 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800938 &ha->fw_attributes, &ha->fw_memory_size,
Andrew Vasquez55a96152009-03-24 09:08:03 -0700939 ha->mpi_version, &ha->mpi_capabilities,
940 ha->phy_version);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700941 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800942 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -0700943 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700944 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700945 if ((!ha->max_npiv_vports) ||
946 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800947 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700948 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800949 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700950 }
Andrew Vasquez24a08132009-03-24 09:08:16 -0700951 qla2x00_get_resource_cnts(vha, NULL,
952 &ha->fw_xcb_count, NULL, NULL,
953 &ha->max_npiv_vports);
Andrew Vasquezd743de62009-03-24 09:08:15 -0700954
955 if (!fw_major_version && ql2xallocfwdump)
956 qla2x00_alloc_fw_dump(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 }
958 } else {
959 DEBUG2(printk(KERN_INFO
960 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800961 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 }
963 }
964
Andrew Vasquez3db06522008-01-31 12:33:49 -0800965 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
966 /* Enable proper parity. */
967 spin_lock_irqsave(&ha->hardware_lock, flags);
968 if (IS_QLA2300(ha))
969 /* SRAM parity */
970 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
971 else
972 /* SRAM, Instruction RAM and GP RAM parity */
973 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
974 RD_REG_WORD(&reg->hccr);
975 spin_unlock_irqrestore(&ha->hardware_lock, flags);
976 }
977
Joe Carnuccio1d2874d2009-03-24 09:08:06 -0700978 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
979 uint32_t size;
980
981 rval = qla81xx_fac_get_sector_size(vha, &size);
982 if (rval == QLA_SUCCESS) {
983 ha->flags.fac_supported = 1;
984 ha->fdt_block_size = size << 2;
985 } else {
986 qla_printk(KERN_ERR, ha,
987 "Unsupported FAC firmware (%d.%02d.%02d).\n",
988 ha->fw_major_version, ha->fw_minor_version,
989 ha->fw_subminor_version);
990 }
991 }
992
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 if (rval) {
994 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800995 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 }
997
998 return (rval);
999}
1000
1001/**
1002 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1003 * @ha: HA context
1004 *
1005 * Beginning of request ring has initialization control block already built
1006 * by nvram config routine.
1007 *
1008 * Returns 0 on success.
1009 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001010void
1011qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012{
1013 uint16_t cnt;
1014 response_t *pkt;
1015
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001016 pkt = rsp->ring_ptr;
1017 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 pkt->signature = RESPONSE_PROCESSED;
1019 pkt++;
1020 }
1021
1022}
1023
1024/**
1025 * qla2x00_update_fw_options() - Read and process firmware options.
1026 * @ha: HA context
1027 *
1028 * Returns 0 on success.
1029 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001030void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001031qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032{
1033 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001034 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035
1036 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001037 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
1039 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1040 return;
1041
1042 /* Serial Link options. */
1043 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001044 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1046 sizeof(ha->fw_seriallink_options)));
1047
1048 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1049 if (ha->fw_seriallink_options[3] & BIT_2) {
1050 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1051
1052 /* 1G settings */
1053 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1054 emphasis = (ha->fw_seriallink_options[2] &
1055 (BIT_4 | BIT_3)) >> 3;
1056 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001057 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 rx_sens = (ha->fw_seriallink_options[0] &
1059 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1060 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1061 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1062 if (rx_sens == 0x0)
1063 rx_sens = 0x3;
1064 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1065 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1066 ha->fw_options[10] |= BIT_5 |
1067 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1068 (tx_sens & (BIT_1 | BIT_0));
1069
1070 /* 2G settings */
1071 swing = (ha->fw_seriallink_options[2] &
1072 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1073 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1074 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001075 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 rx_sens = (ha->fw_seriallink_options[1] &
1077 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1078 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1079 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1080 if (rx_sens == 0x0)
1081 rx_sens = 0x3;
1082 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1083 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1084 ha->fw_options[11] |= BIT_5 |
1085 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1086 (tx_sens & (BIT_1 | BIT_0));
1087 }
1088
1089 /* FCP2 options. */
1090 /* Return command IOCBs without waiting for an ABTS to complete. */
1091 ha->fw_options[3] |= BIT_13;
1092
1093 /* LED scheme. */
1094 if (ha->flags.enable_led_scheme)
1095 ha->fw_options[2] |= BIT_12;
1096
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001097 /* Detect ISP6312. */
1098 if (IS_QLA6312(ha))
1099 ha->fw_options[2] |= BIT_13;
1100
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001102 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103}
1104
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001105void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001106qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07001107{
1108 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001109 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07001110
1111 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001112 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez01071092005-07-06 10:31:37 -07001113 return;
1114
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001115 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001116 le16_to_cpu(ha->fw_seriallink_options24[1]),
1117 le16_to_cpu(ha->fw_seriallink_options24[2]),
1118 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez01071092005-07-06 10:31:37 -07001119 if (rval != QLA_SUCCESS) {
1120 qla_printk(KERN_WARNING, ha,
1121 "Unable to update Serial Link options (%x).\n", rval);
1122 }
1123}
1124
1125void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001126qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001127{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001128 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001129 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001130 struct req_que *req = ha->req_q_map[0];
1131 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001132
1133 /* Setup ring parameters in initialization control block. */
1134 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1135 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001136 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1137 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1138 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1139 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1140 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1141 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001142
1143 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1144 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1145 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1146 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1147 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1148}
1149
Andrew Vasquez01071092005-07-06 10:31:37 -07001150void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001151qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07001152{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001153 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001154 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1155 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1156 struct qla_msix_entry *msix;
Andrew Vasquez01071092005-07-06 10:31:37 -07001157 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001158 uint16_t rid = 0;
1159 struct req_que *req = ha->req_q_map[0];
1160 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez01071092005-07-06 10:31:37 -07001161
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001162/* Setup ring parameters in initialization control block. */
Andrew Vasquez01071092005-07-06 10:31:37 -07001163 icb = (struct init_cb_24xx *)ha->init_cb;
1164 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1165 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001166 icb->request_q_length = cpu_to_le16(req->length);
1167 icb->response_q_length = cpu_to_le16(rsp->length);
1168 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1169 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1170 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1171 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez01071092005-07-06 10:31:37 -07001172
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001173 if (ha->mqenable) {
1174 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1175 icb->rid = __constant_cpu_to_le16(rid);
1176 if (ha->flags.msix_enabled) {
1177 msix = &ha->msix_entries[1];
1178 DEBUG2_17(printk(KERN_INFO
1179 "Reistering vector 0x%x for base que\n", msix->entry));
1180 icb->msix = cpu_to_le16(msix->entry);
1181 }
1182 /* Use alternate PCI bus number */
1183 if (MSB(rid))
1184 icb->firmware_options_2 |=
1185 __constant_cpu_to_le32(BIT_19);
1186 /* Use alternate PCI devfn */
1187 if (LSB(rid))
1188 icb->firmware_options_2 |=
1189 __constant_cpu_to_le32(BIT_18);
1190
Anirban Chakraborty618a7522009-02-08 20:50:11 -08001191 icb->firmware_options_2 &= __constant_cpu_to_le32(~BIT_22);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001192 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001193
1194 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1195 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1196 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1197 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1198 } else {
1199 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1200 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1201 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1202 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1203 }
1204 /* PCI posting */
1205 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez01071092005-07-06 10:31:37 -07001206}
1207
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208/**
1209 * qla2x00_init_rings() - Initializes firmware.
1210 * @ha: HA context
1211 *
1212 * Beginning of request ring has initialization control block already built
1213 * by nvram config routine.
1214 *
1215 * Returns 0 on success.
1216 */
1217static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001218qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219{
1220 int rval;
1221 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001222 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001223 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001224 struct req_que *req;
1225 struct rsp_que *rsp;
1226 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001227 struct mid_init_cb_24xx *mid_init_cb =
1228 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
1230 spin_lock_irqsave(&ha->hardware_lock, flags);
1231
1232 /* Clear outstanding commands array. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001233 for (que = 0; que < ha->max_queues; que++) {
1234 req = ha->req_q_map[que];
1235 if (!req)
1236 continue;
1237 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1238 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001240 req->current_outstanding_cmd = 0;
1241
1242 /* Initialize firmware. */
1243 req->ring_ptr = req->ring;
1244 req->ring_index = 0;
1245 req->cnt = req->length;
1246 }
1247
1248 for (que = 0; que < ha->max_queues; que++) {
1249 rsp = ha->rsp_q_map[que];
1250 if (!rsp)
1251 continue;
1252 rsp->ring_ptr = rsp->ring;
1253 rsp->ring_index = 0;
1254
1255 /* Initialize response queue entries */
1256 qla2x00_init_response_q_entries(rsp);
1257 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258
1259 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001260 list_for_each_entry(vp, &ha->vp_list, list) {
1261 vp->rscn_in_ptr = 0;
1262 vp->rscn_out_ptr = 0;
1263 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001264 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265
1266 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1267
1268 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001269 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001271 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001272
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001273 if (ha->flags.npiv_supported) {
1274 if (ha->operating_mode == LOOP)
1275 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001276 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001277 }
1278
Andrew Vasquez24a08132009-03-24 09:08:16 -07001279 if (IS_FWI2_CAPABLE(ha)) {
1280 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1281 mid_init_cb->init_cb.execution_throttle =
1282 cpu_to_le16(ha->fw_xcb_count);
1283 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001284
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001285 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 if (rval) {
1287 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001288 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 } else {
1290 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001291 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 }
1293
1294 return (rval);
1295}
1296
1297/**
1298 * qla2x00_fw_ready() - Waits for firmware ready.
1299 * @ha: HA context
1300 *
1301 * Returns 0 on success.
1302 */
1303static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001304qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305{
1306 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001307 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 uint16_t min_wait; /* Minimum wait time if loop is down */
1309 uint16_t wait_time; /* Wait time if loop is coming ready */
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001310 uint16_t state[3];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001311 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312
1313 rval = QLA_SUCCESS;
1314
1315 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001316 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
1318 /*
1319 * Firmware should take at most one RATOV to login, plus 5 seconds for
1320 * our own processing.
1321 */
1322 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1323 wait_time = min_wait;
1324 }
1325
1326 /* Min wait time if loop down */
1327 mtime = jiffies + (min_wait * HZ);
1328
1329 /* wait time before firmware ready */
1330 wtime = jiffies + (wait_time * HZ);
1331
1332 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001333 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1335
1336 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001337 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
1339 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001340 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001342 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001343 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001345 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1346 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001347 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001348 state[2]));
1349 if ((state[2] & FSTATE_LOGGED_IN) &&
1350 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1351 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001352 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001353
1354 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001355 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001356 if (rval != QLA_SUCCESS)
1357 break;
1358
1359 /* Add time taken to initialize. */
1360 cs84xx_time = jiffies - cs84xx_time;
1361 wtime += cs84xx_time;
1362 mtime += cs84xx_time;
1363 DEBUG16(printk("scsi(%ld): Increasing "
1364 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001365 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001366 }
1367 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001369 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001371 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 &ha->login_timeout, &ha->r_a_tov);
1373
1374 rval = QLA_SUCCESS;
1375 break;
1376 }
1377
1378 rval = QLA_FUNCTION_FAILED;
1379
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001380 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001381 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001383 * other than Wait for Login.
1384 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 if (time_after_eq(jiffies, mtime)) {
1386 qla_printk(KERN_INFO, ha,
1387 "Cable is unplugged...\n");
1388
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001389 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 break;
1391 }
1392 }
1393 } else {
1394 /* Mailbox cmd failed. Timeout on min_wait. */
1395 if (time_after_eq(jiffies, mtime))
1396 break;
1397 }
1398
1399 if (time_after_eq(jiffies, wtime))
1400 break;
1401
1402 /* Delay for a while */
1403 msleep(500);
1404
1405 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001406 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 } while (1);
1408
1409 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001410 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411
1412 if (rval) {
1413 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001414 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 }
1416
1417 return (rval);
1418}
1419
1420/*
1421* qla2x00_configure_hba
1422* Setup adapter context.
1423*
1424* Input:
1425* ha = adapter state pointer.
1426*
1427* Returns:
1428* 0 = success
1429*
1430* Context:
1431* Kernel context.
1432*/
1433static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001434qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435{
1436 int rval;
1437 uint16_t loop_id;
1438 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001439 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 uint8_t al_pa;
1441 uint8_t area;
1442 uint8_t domain;
1443 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001444 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445
1446 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001447 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001448 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001450 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001451 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1452 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001453 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08001454 } else {
1455 qla_printk(KERN_WARNING, ha,
1456 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001457 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08001458 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 return (rval);
1460 }
1461
1462 if (topo == 4) {
1463 qla_printk(KERN_INFO, ha,
1464 "Cannot get topology - retrying.\n");
1465 return (QLA_FUNCTION_FAILED);
1466 }
1467
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001468 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
1470 /* initialize */
1471 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1472 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001473 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
1475 switch (topo) {
1476 case 0:
1477 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001478 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 ha->current_topology = ISP_CFG_NL;
1480 strcpy(connect_type, "(Loop)");
1481 break;
1482
1483 case 1:
1484 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001485 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001486 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 ha->current_topology = ISP_CFG_FL;
1488 strcpy(connect_type, "(FL_Port)");
1489 break;
1490
1491 case 2:
1492 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001493 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 ha->operating_mode = P2P;
1495 ha->current_topology = ISP_CFG_N;
1496 strcpy(connect_type, "(N_Port-to-N_Port)");
1497 break;
1498
1499 case 3:
1500 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001501 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001502 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 ha->operating_mode = P2P;
1504 ha->current_topology = ISP_CFG_F;
1505 strcpy(connect_type, "(F_Port)");
1506 break;
1507
1508 default:
1509 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1510 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001511 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 ha->current_topology = ISP_CFG_NL;
1513 strcpy(connect_type, "(Loop)");
1514 break;
1515 }
1516
1517 /* Save Host port and loop ID. */
1518 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001519 vha->d_id.b.domain = domain;
1520 vha->d_id.b.area = area;
1521 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001523 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 qla_printk(KERN_INFO, ha,
1525 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001526 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
1528 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001529 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001531 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 }
1533
1534 return(rval);
1535}
1536
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001537static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001538qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1539 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001540{
1541 char *st, *en;
1542 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001543 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001544
1545 if (memcmp(model, BINZERO, len) != 0) {
1546 strncpy(ha->model_number, model, len);
1547 st = en = ha->model_number;
1548 en += len - 1;
1549 while (en > st) {
1550 if (*en != 0x20 && *en != 0x00)
1551 break;
1552 *en-- = '\0';
1553 }
1554
1555 index = (ha->pdev->subsystem_device & 0xff);
1556 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1557 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001558 strncpy(ha->model_desc,
1559 qla2x00_model_name[index * 2 + 1],
1560 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001561 } else {
1562 index = (ha->pdev->subsystem_device & 0xff);
1563 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1564 index < QLA_MODEL_NAMES) {
1565 strcpy(ha->model_number,
1566 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001567 strncpy(ha->model_desc,
1568 qla2x00_model_name[index * 2 + 1],
1569 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001570 } else {
1571 strcpy(ha->model_number, def);
1572 }
1573 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001574 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001575 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001576 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001577}
1578
David Miller4e08df32007-04-16 12:37:43 -07001579/* On sparc systems, obtain port and node WWN from firmware
1580 * properties.
1581 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001582static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07001583{
1584#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001585 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07001586 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07001587 struct device_node *dp = pci_device_to_OF_node(pdev);
1588 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07001589 int len;
1590
1591 val = of_get_property(dp, "port-wwn", &len);
1592 if (val && len >= WWN_SIZE)
1593 memcpy(nv->port_name, val, WWN_SIZE);
1594
1595 val = of_get_property(dp, "node-wwn", &len);
1596 if (val && len >= WWN_SIZE)
1597 memcpy(nv->node_name, val, WWN_SIZE);
1598#endif
1599}
1600
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601/*
1602* NVRAM configuration for ISP 2xxx
1603*
1604* Input:
1605* ha = adapter block pointer.
1606*
1607* Output:
1608* initialization control block in response_ring
1609* host adapters parameters in host adapter block
1610*
1611* Returns:
1612* 0 = success.
1613*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001614int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001615qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616{
David Miller4e08df32007-04-16 12:37:43 -07001617 int rval;
Andrew Vasquez01071092005-07-06 10:31:37 -07001618 uint8_t chksum = 0;
1619 uint16_t cnt;
1620 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001621 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07001622 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07001623 nvram_t *nv = ha->nvram;
1624 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001625 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626
David Miller4e08df32007-04-16 12:37:43 -07001627 rval = QLA_SUCCESS;
1628
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 /* Determine NVRAM starting address. */
Andrew Vasquez01071092005-07-06 10:31:37 -07001630 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 ha->nvram_base = 0;
1632 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1633 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
1634 ha->nvram_base = 0x80;
1635
1636 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001637 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez01071092005-07-06 10:31:37 -07001638 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1639 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001641 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07001642 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643
1644 /* Bad NVRAM data, set defaults parameters. */
1645 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1646 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1647 /* Reset NVRAM data. */
1648 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1649 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1650 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07001651 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1652 "invalid -- WWPN) defaults.\n");
1653
1654 /*
1655 * Set default initialization control block.
1656 */
1657 memset(nv, 0, ha->nvram_size);
1658 nv->parameter_block_version = ICB_VERSION;
1659
1660 if (IS_QLA23XX(ha)) {
1661 nv->firmware_options[0] = BIT_2 | BIT_1;
1662 nv->firmware_options[1] = BIT_7 | BIT_5;
1663 nv->add_firmware_options[0] = BIT_5;
1664 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1665 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1666 nv->special_options[1] = BIT_7;
1667 } else if (IS_QLA2200(ha)) {
1668 nv->firmware_options[0] = BIT_2 | BIT_1;
1669 nv->firmware_options[1] = BIT_7 | BIT_5;
1670 nv->add_firmware_options[0] = BIT_5;
1671 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1672 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1673 } else if (IS_QLA2100(ha)) {
1674 nv->firmware_options[0] = BIT_3 | BIT_1;
1675 nv->firmware_options[1] = BIT_5;
1676 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1677 }
1678
1679 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1680 nv->execution_throttle = __constant_cpu_to_le16(16);
1681 nv->retry_count = 8;
1682 nv->retry_delay = 1;
1683
1684 nv->port_name[0] = 33;
1685 nv->port_name[3] = 224;
1686 nv->port_name[4] = 139;
1687
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001688 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07001689
1690 nv->login_timeout = 4;
1691
1692 /*
1693 * Set default host adapter parameters
1694 */
1695 nv->host_p[1] = BIT_2;
1696 nv->reset_delay = 5;
1697 nv->port_down_retry_count = 8;
1698 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1699 nv->link_down_timeout = 60;
1700
1701 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 }
1703
1704#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1705 /*
1706 * The SN2 does not provide BIOS emulation which means you can't change
1707 * potentially bogus BIOS settings. Force the use of default settings
1708 * for link rate and frame size. Hope that the rest of the settings
1709 * are valid.
1710 */
1711 if (ia64_platform_is("sn2")) {
1712 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1713 if (IS_QLA23XX(ha))
1714 nv->special_options[1] = BIT_7;
1715 }
1716#endif
1717
1718 /* Reset Initialization control block */
Andrew Vasquez01071092005-07-06 10:31:37 -07001719 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720
1721 /*
1722 * Setup driver NVRAM options.
1723 */
1724 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1725 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1726 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1727 nv->firmware_options[1] &= ~BIT_4;
1728
1729 if (IS_QLA23XX(ha)) {
1730 nv->firmware_options[0] |= BIT_2;
1731 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez01071092005-07-06 10:31:37 -07001732 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733
1734 if (IS_QLA2300(ha)) {
1735 if (ha->fb_rev == FPM_2310) {
1736 strcpy(ha->model_number, "QLA2310");
1737 } else {
1738 strcpy(ha->model_number, "QLA2300");
1739 }
1740 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001741 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001742 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 }
1744 } else if (IS_QLA2200(ha)) {
1745 nv->firmware_options[0] |= BIT_2;
1746 /*
1747 * 'Point-to-point preferred, else loop' is not a safe
1748 * connection mode setting.
1749 */
1750 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1751 (BIT_5 | BIT_4)) {
1752 /* Force 'loop preferred, else point-to-point'. */
1753 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1754 nv->add_firmware_options[0] |= BIT_5;
1755 }
1756 strcpy(ha->model_number, "QLA22xx");
1757 } else /*if (IS_QLA2100(ha))*/ {
1758 strcpy(ha->model_number, "QLA2100");
1759 }
1760
1761 /*
1762 * Copy over NVRAM RISC parameter block to initialization control block.
1763 */
1764 dptr1 = (uint8_t *)icb;
1765 dptr2 = (uint8_t *)&nv->parameter_block_version;
1766 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1767 while (cnt--)
1768 *dptr1++ = *dptr2++;
1769
1770 /* Copy 2nd half. */
1771 dptr1 = (uint8_t *)icb->add_firmware_options;
1772 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1773 while (cnt--)
1774 *dptr1++ = *dptr2++;
1775
Andrew Vasquez5341e862006-05-17 15:09:16 -07001776 /* Use alternate WWN? */
1777 if (nv->host_p[1] & BIT_7) {
1778 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1779 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1780 }
1781
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 /* Prepare nodename */
1783 if ((icb->firmware_options[1] & BIT_6) == 0) {
1784 /*
1785 * Firmware will apply the following mask if the nodename was
1786 * not provided.
1787 */
1788 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1789 icb->node_name[0] &= 0xF0;
1790 }
1791
1792 /*
1793 * Set host adapter parameters.
1794 */
Andrew Vasquez01819442006-06-23 16:11:10 -07001795 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07001796 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1798 /* Always load RISC code on non ISP2[12]00 chips. */
1799 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1800 ha->flags.disable_risc_code_load = 0;
1801 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1802 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1803 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07001804 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001805 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806
1807 ha->operating_mode =
1808 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1809
1810 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1811 sizeof(ha->fw_seriallink_options));
1812
1813 /* save HBA serial number */
1814 ha->serial0 = icb->port_name[5];
1815 ha->serial1 = icb->port_name[6];
1816 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001817 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
1818 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819
1820 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1821
1822 ha->retry_count = nv->retry_count;
1823
1824 /* Set minimum login_timeout to 4 seconds. */
1825 if (nv->login_timeout < ql2xlogintimeout)
1826 nv->login_timeout = ql2xlogintimeout;
1827 if (nv->login_timeout < 4)
1828 nv->login_timeout = 4;
1829 ha->login_timeout = nv->login_timeout;
1830 icb->login_timeout = nv->login_timeout;
1831
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001832 /* Set minimum RATOV to 100 tenths of a second. */
1833 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 ha->loop_reset_delay = nv->reset_delay;
1836
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 /* Link Down Timeout = 0:
1838 *
1839 * When Port Down timer expires we will start returning
1840 * I/O's to OS with "DID_NO_CONNECT".
1841 *
1842 * Link Down Timeout != 0:
1843 *
1844 * The driver waits for the link to come up after link down
1845 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001846 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 if (nv->link_down_timeout == 0) {
1848 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001849 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 } else {
1851 ha->link_down_timeout = nv->link_down_timeout;
1852 ha->loop_down_abort_time =
1853 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001854 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 /*
1857 * Need enough time to try and get the port back.
1858 */
1859 ha->port_down_retry_count = nv->port_down_retry_count;
1860 if (qlport_down_retry)
1861 ha->port_down_retry_count = qlport_down_retry;
1862 /* Set login_retry_count */
1863 ha->login_retry_count = nv->retry_count;
1864 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1865 ha->port_down_retry_count > 3)
1866 ha->login_retry_count = ha->port_down_retry_count;
1867 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1868 ha->login_retry_count = ha->port_down_retry_count;
1869 if (ql2xloginretrycount)
1870 ha->login_retry_count = ql2xloginretrycount;
1871
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 icb->lun_enables = __constant_cpu_to_le16(0);
1873 icb->command_resource_count = 0;
1874 icb->immediate_notify_resource_count = 0;
1875 icb->timeout = __constant_cpu_to_le16(0);
1876
1877 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1878 /* Enable RIO */
1879 icb->firmware_options[0] &= ~BIT_3;
1880 icb->add_firmware_options[0] &=
1881 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1882 icb->add_firmware_options[0] |= BIT_2;
1883 icb->response_accumulation_timer = 3;
1884 icb->interrupt_delay_timer = 5;
1885
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001886 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001888 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001889 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001890 ha->zio_mode = icb->add_firmware_options[0] &
1891 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1892 ha->zio_timer = icb->interrupt_delay_timer ?
1893 icb->interrupt_delay_timer: 2;
1894 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 icb->add_firmware_options[0] &=
1896 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001897 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001898 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001899 ha->zio_mode = QLA_ZIO_MODE_6;
1900
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001901 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001902 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001903 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001905 "ZIO mode %d enabled; timer delay (%d us).\n",
1906 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001908 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1909 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001910 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 }
1912 }
1913
David Miller4e08df32007-04-16 12:37:43 -07001914 if (rval) {
1915 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001916 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07001917 }
1918 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919}
1920
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001921static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001922qla2x00_rport_del(void *data)
1923{
1924 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001925 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001926
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001927 spin_lock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001928 rport = fcport->drport;
1929 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001930 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001931 if (rport)
1932 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001933}
1934
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935/**
1936 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1937 * @ha: HA context
1938 * @flags: allocation flags
1939 *
1940 * Returns a pointer to the allocated fcport, or NULL, if none available.
1941 */
Adrian Bunk413975a2006-06-30 02:33:06 -07001942static fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001943qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944{
1945 fc_port_t *fcport;
1946
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001947 fcport = kzalloc(sizeof(fc_port_t), flags);
1948 if (!fcport)
1949 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950
1951 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001952 fcport->vha = vha;
1953 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 fcport->port_type = FCT_UNKNOWN;
1955 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 atomic_set(&fcport->state, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001957 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001959 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960}
1961
1962/*
1963 * qla2x00_configure_loop
1964 * Updates Fibre Channel Device Database with what is actually on loop.
1965 *
1966 * Input:
1967 * ha = adapter block pointer.
1968 *
1969 * Returns:
1970 * 0 = success.
1971 * 1 = error.
1972 * 2 = database was full and device was not configured.
1973 */
1974static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001975qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976{
1977 int rval;
1978 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001979 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 rval = QLA_SUCCESS;
1981
1982 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001983 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
1984 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 if (rval != QLA_SUCCESS) {
1986 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001987 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 return (rval);
1989 }
1990 }
1991
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001992 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001994 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995
1996 /*
1997 * If we have both an RSCN and PORT UPDATE pending then handle them
1998 * both at the same time.
1999 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002000 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2001 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002
2003 /* Determine what we need to do */
2004 if (ha->current_topology == ISP_CFG_FL &&
2005 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2006
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002007 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 set_bit(RSCN_UPDATE, &flags);
2009
2010 } else if (ha->current_topology == ISP_CFG_F &&
2011 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2012
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002013 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 set_bit(RSCN_UPDATE, &flags);
2015 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2016
Andrew Vasquez21333b42006-05-17 15:09:56 -07002017 } else if (ha->current_topology == ISP_CFG_N) {
2018 clear_bit(RSCN_UPDATE, &flags);
2019
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002020 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2022
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002023 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 set_bit(RSCN_UPDATE, &flags);
2025 set_bit(LOCAL_LOOP_UPDATE, &flags);
2026 }
2027
2028 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002029 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002031 else
2032 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 }
2034
2035 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002036 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002038 else
2039 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 }
2041
2042 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002043 if (atomic_read(&vha->loop_down_timer) ||
2044 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 rval = QLA_FUNCTION_FAILED;
2046 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002047 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002049 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 }
2051 }
2052
2053 if (rval) {
2054 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002055 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 } else {
2057 DEBUG3(printk("%s: exiting normally\n", __func__));
2058 }
2059
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002060 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002061 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002063 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002064 if (test_bit(RSCN_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002065 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 }
2067
2068 return (rval);
2069}
2070
2071
2072
2073/*
2074 * qla2x00_configure_local_loop
2075 * Updates Fibre Channel Device Database with local loop devices.
2076 *
2077 * Input:
2078 * ha = adapter block pointer.
2079 *
2080 * Returns:
2081 * 0 = success.
2082 */
2083static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002084qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085{
2086 int rval, rval2;
2087 int found_devs;
2088 int found;
2089 fc_port_t *fcport, *new_fcport;
2090
2091 uint16_t index;
2092 uint16_t entries;
2093 char *id_iter;
2094 uint16_t loop_id;
2095 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002096 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097
2098 found_devs = 0;
2099 new_fcport = NULL;
2100 entries = MAX_FIBRE_DEVICES;
2101
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002102 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2103 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104
2105 /* Get list of logged in devices. */
2106 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002107 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 &entries);
2109 if (rval != QLA_SUCCESS)
2110 goto cleanup_allocation;
2111
2112 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2113 ha->host_no, entries));
2114 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2115 entries * sizeof(struct gid_list_info)));
2116
2117 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002118 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 if (new_fcport == NULL) {
2120 rval = QLA_MEMORY_ALLOC_FAILED;
2121 goto cleanup_allocation;
2122 }
2123 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2124
2125 /*
2126 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2127 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002128 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2130 fcport->port_type != FCT_BROADCAST &&
2131 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2132
2133 DEBUG(printk("scsi(%ld): Marking port lost, "
2134 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002135 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136
2137 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 }
2139 }
2140
2141 /* Add devices to port list. */
2142 id_iter = (char *)ha->gid_list;
2143 for (index = 0; index < entries; index++) {
2144 domain = ((struct gid_list_info *)id_iter)->domain;
2145 area = ((struct gid_list_info *)id_iter)->area;
2146 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002147 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 loop_id = (uint16_t)
2149 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002150 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 loop_id = le16_to_cpu(
2152 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002153 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154
2155 /* Bypass reserved domain fields. */
2156 if ((domain & 0xf0) == 0xf0)
2157 continue;
2158
2159 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002160 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002161 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 continue;
2163
2164 /* Bypass invalid local loop ID. */
2165 if (loop_id > LAST_LOCAL_LOOP_ID)
2166 continue;
2167
2168 /* Fill in member data. */
2169 new_fcport->d_id.b.domain = domain;
2170 new_fcport->d_id.b.area = area;
2171 new_fcport->d_id.b.al_pa = al_pa;
2172 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002173 new_fcport->vp_idx = vha->vp_idx;
2174 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 if (rval2 != QLA_SUCCESS) {
2176 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2177 "information -- get_port_database=%x, "
2178 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002179 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002180 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002181 vha->host_no));
2182 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 continue;
2184 }
2185
2186 /* Check for matching device in port list. */
2187 found = 0;
2188 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002189 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 if (memcmp(new_fcport->port_name, fcport->port_name,
2191 WWN_SIZE))
2192 continue;
2193
Shyam Sundarddb9b122009-03-24 09:08:10 -07002194 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 fcport->loop_id = new_fcport->loop_id;
2196 fcport->port_type = new_fcport->port_type;
2197 fcport->d_id.b24 = new_fcport->d_id.b24;
2198 memcpy(fcport->node_name, new_fcport->node_name,
2199 WWN_SIZE);
2200
2201 found++;
2202 break;
2203 }
2204
2205 if (!found) {
2206 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002207 if (vha->vp_idx) {
2208 new_fcport->vha = vha;
2209 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002210 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002211 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212
2213 /* Allocate a new replacement fcport. */
2214 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002215 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 if (new_fcport == NULL) {
2217 rval = QLA_MEMORY_ALLOC_FAILED;
2218 goto cleanup_allocation;
2219 }
2220 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2221 }
2222
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002223 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002224 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002225
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002226 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227
2228 found_devs++;
2229 }
2230
2231cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002232 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233
2234 if (rval != QLA_SUCCESS) {
2235 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002236 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 }
2238
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 return (rval);
2240}
2241
2242static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002243qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002244{
2245#define LS_UNKNOWN 2
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002246 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002247 int rval;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002248 uint16_t mb[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002249 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002250
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002251 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002252 return;
2253
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002254 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2255 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002256 return;
2257
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002258 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002259 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002260 if (rval != QLA_SUCCESS) {
2261 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2262 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002263 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002264 fcport->port_name[2], fcport->port_name[3],
2265 fcport->port_name[4], fcport->port_name[5],
2266 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002267 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002268 } else {
2269 DEBUG2(qla_printk(KERN_INFO, ha,
2270 "iIDMA adjusted to %s GB/s on "
2271 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002272 link_speeds[fcport->fp_speed], fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002273 fcport->port_name[1], fcport->port_name[2],
2274 fcport->port_name[3], fcport->port_name[4],
2275 fcport->port_name[5], fcport->port_name[6],
2276 fcport->port_name[7]));
2277 }
2278}
2279
Adrian Bunk23be3312006-11-24 02:46:01 +01002280static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002281qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e112005-04-17 15:04:54 -05002282{
2283 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002284 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002285 struct qla_hw_data *ha = vha->hw;
8482e112005-04-17 15:04:54 -05002286
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002287 if (fcport->drport)
2288 qla2x00_rport_del(fcport);
8482e112005-04-17 15:04:54 -05002289
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002290 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2291 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e112005-04-17 15:04:54 -05002292 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2293 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2294 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002295 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002296 if (!rport) {
2297 qla_printk(KERN_WARNING, ha,
2298 "Unable to allocate fc remote port!\n");
2299 return;
2300 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002301 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002302 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002303 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002304
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002305 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002306
2307 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e112005-04-17 15:04:54 -05002308 if (fcport->port_type == FCT_INITIATOR)
2309 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2310 if (fcport->port_type == FCT_TARGET)
2311 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002312 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e112005-04-17 15:04:54 -05002313}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314
2315/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002316 * qla2x00_update_fcport
2317 * Updates device on list.
2318 *
2319 * Input:
2320 * ha = adapter block pointer.
2321 * fcport = port structure pointer.
2322 *
2323 * Return:
2324 * 0 - Success
2325 * BIT_0 - error
2326 *
2327 * Context:
2328 * Kernel context.
2329 */
2330void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002331qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002332{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002333 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002334
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002335 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002336 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002337 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002338 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002339 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002340 PORT_RETRY_TIME);
2341 fcport->flags &= ~FCF_LOGIN_NEEDED;
2342
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002343 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002344
2345 atomic_set(&fcport->state, FCS_ONLINE);
2346
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002347 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002348}
2349
2350/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 * qla2x00_configure_fabric
2352 * Setup SNS devices with loop ID's.
2353 *
2354 * Input:
2355 * ha = adapter block pointer.
2356 *
2357 * Returns:
2358 * 0 = success.
2359 * BIT_0 = error
2360 */
2361static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002362qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363{
2364 int rval, rval2;
2365 fc_port_t *fcport, *fcptemp;
2366 uint16_t next_loopid;
2367 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez01071092005-07-06 10:31:37 -07002368 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002370 struct qla_hw_data *ha = vha->hw;
2371 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372
2373 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002374 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez01071092005-07-06 10:31:37 -07002375 loop_id = NPH_F_PORT;
2376 else
2377 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002378 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 if (rval != QLA_SUCCESS) {
2380 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002381 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002383 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 return (QLA_SUCCESS);
2385 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002386 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387
2388 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002389 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 if (rval2 == QLA_RSCNS_HANDLED) {
2391 /* No point doing the scan, just continue. */
2392 return (QLA_SUCCESS);
2393 }
2394 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002395 /* FDMI support. */
2396 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002397 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2398 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002399
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002401 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez01071092005-07-06 10:31:37 -07002402 loop_id = NPH_SNS;
2403 else
2404 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002405 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002406 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 if (mb[0] != MBS_COMMAND_COMPLETE) {
2408 DEBUG2(qla_printk(KERN_INFO, ha,
2409 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez01071092005-07-06 10:31:37 -07002410 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 mb[0], mb[1], mb[2], mb[6], mb[7]));
2412 return (QLA_SUCCESS);
2413 }
2414
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002415 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2416 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 /* EMPTY */
2418 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002419 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002421 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 /* EMPTY */
2423 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002424 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002426 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 /* EMPTY */
2428 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002429 "failed.\n", vha->host_no));
2430 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 /* EMPTY */
2432 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002433 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 }
2435 }
2436
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002437 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 if (rval != QLA_SUCCESS)
2439 break;
2440
2441 /*
2442 * Logout all previous fabric devices marked lost, except
2443 * tape devices.
2444 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002445 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2446 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 break;
2448
2449 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2450 continue;
2451
2452 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002453 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002454 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 if (fcport->loop_id != FC_NO_LOOP_ID &&
2456 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2457 fcport->port_type != FCT_INITIATOR &&
2458 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002459 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002460 fcport->loop_id,
2461 fcport->d_id.b.domain,
2462 fcport->d_id.b.area,
2463 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 fcport->loop_id = FC_NO_LOOP_ID;
2465 }
2466 }
2467 }
2468
2469 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002470 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471
2472 /*
2473 * Scan through our port list and login entries that need to be
2474 * logged in.
2475 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002476 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2477 if (atomic_read(&vha->loop_down_timer) ||
2478 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 break;
2480
2481 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2482 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2483 continue;
2484
2485 if (fcport->loop_id == FC_NO_LOOP_ID) {
2486 fcport->loop_id = next_loopid;
Seokmann Jud4486fd2008-04-03 13:13:28 -07002487 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002488 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 if (rval != QLA_SUCCESS) {
2490 /* Ran out of IDs to use */
2491 break;
2492 }
2493 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002495 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 }
2497
2498 /* Exit if out of loop IDs. */
2499 if (rval != QLA_SUCCESS) {
2500 break;
2501 }
2502
2503 /*
2504 * Login and add the new devices to our port list.
2505 */
2506 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002507 if (atomic_read(&vha->loop_down_timer) ||
2508 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 break;
2510
2511 /* Find a new loop ID to use. */
2512 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002513 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 if (rval != QLA_SUCCESS) {
2515 /* Ran out of IDs to use */
2516 break;
2517 }
2518
bdf79622005-04-17 15:06:53 -05002519 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002520 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002521
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002522 if (vha->vp_idx) {
2523 fcport->vha = vha;
2524 fcport->vp_idx = vha->vp_idx;
2525 }
2526 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 }
2528 } while (0);
2529
2530 /* Free all new device structures not processed. */
2531 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2532 list_del(&fcport->list);
2533 kfree(fcport);
2534 }
2535
2536 if (rval) {
2537 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002538 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 }
2540
2541 return (rval);
2542}
2543
2544
2545/*
2546 * qla2x00_find_all_fabric_devs
2547 *
2548 * Input:
2549 * ha = adapter block pointer.
2550 * dev = database device entry pointer.
2551 *
2552 * Returns:
2553 * 0 = success.
2554 *
2555 * Context:
2556 * Kernel context.
2557 */
2558static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002559qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2560 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561{
2562 int rval;
2563 uint16_t loop_id;
2564 fc_port_t *fcport, *new_fcport, *fcptemp;
2565 int found;
2566
2567 sw_info_t *swl;
2568 int swl_idx;
2569 int first_dev, last_dev;
2570 port_id_t wrap, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002571 struct qla_hw_data *ha = vha->hw;
2572 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002573 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574
2575 rval = QLA_SUCCESS;
2576
2577 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07002578 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002579 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 /*EMPTY*/
2581 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002582 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002584 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 kfree(swl);
2586 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002587 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 kfree(swl);
2589 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002590 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 kfree(swl);
2592 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07002593 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002594 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2595 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 }
2597 }
2598 swl_idx = 0;
2599
2600 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002601 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002603 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 return (QLA_MEMORY_ALLOC_FAILED);
2605 }
2606 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 /* Set start port ID scan at adapter ID. */
2608 first_dev = 1;
2609 last_dev = 0;
2610
2611 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002612 loop_id = ha->min_external_loopid;
2613 for (; loop_id <= ha->max_loop_id; loop_id++) {
2614 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 continue;
2616
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002617 if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 break;
2619
2620 if (swl != NULL) {
2621 if (last_dev) {
2622 wrap.b24 = new_fcport->d_id.b24;
2623 } else {
2624 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2625 memcpy(new_fcport->node_name,
2626 swl[swl_idx].node_name, WWN_SIZE);
2627 memcpy(new_fcport->port_name,
2628 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002629 memcpy(new_fcport->fabric_port_name,
2630 swl[swl_idx].fabric_port_name, WWN_SIZE);
2631 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632
2633 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2634 last_dev = 1;
2635 }
2636 swl_idx++;
2637 }
2638 } else {
2639 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002640 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 if (rval != QLA_SUCCESS) {
2642 qla_printk(KERN_WARNING, ha,
2643 "SNS scan failed -- assuming zero-entry "
2644 "result...\n");
2645 list_for_each_entry_safe(fcport, fcptemp,
2646 new_fcports, list) {
2647 list_del(&fcport->list);
2648 kfree(fcport);
2649 }
2650 rval = QLA_SUCCESS;
2651 break;
2652 }
2653 }
2654
2655 /* If wrap on switch device list, exit. */
2656 if (first_dev) {
2657 wrap.b24 = new_fcport->d_id.b24;
2658 first_dev = 0;
2659 } else if (new_fcport->d_id.b24 == wrap.b24) {
2660 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002661 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2663 break;
2664 }
2665
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002666 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002667 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 continue;
2669
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002670 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002671 found = 0;
2672 if (ha->num_vhosts) {
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002673 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002674 if (new_fcport->d_id.b24 == vp->d_id.b24) {
2675 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002676 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002677 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002678 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002679 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002680 continue;
2681 }
2682
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002683 /* Bypass if same domain and area of adapter. */
2684 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002685 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002686 ISP_CFG_FL)
2687 continue;
2688
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 /* Bypass reserved domain fields. */
2690 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2691 continue;
2692
2693 /* Locate matching device in database. */
2694 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002695 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 if (memcmp(new_fcport->port_name, fcport->port_name,
2697 WWN_SIZE))
2698 continue;
2699
2700 found++;
2701
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002702 /* Update port state. */
2703 memcpy(fcport->fabric_port_name,
2704 new_fcport->fabric_port_name, WWN_SIZE);
2705 fcport->fp_speed = new_fcport->fp_speed;
2706
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 /*
2708 * If address the same and state FCS_ONLINE, nothing
2709 * changed.
2710 */
2711 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2712 atomic_read(&fcport->state) == FCS_ONLINE) {
2713 break;
2714 }
2715
2716 /*
2717 * If device was not a fabric device before.
2718 */
2719 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2720 fcport->d_id.b24 = new_fcport->d_id.b24;
2721 fcport->loop_id = FC_NO_LOOP_ID;
2722 fcport->flags |= (FCF_FABRIC_DEVICE |
2723 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 break;
2725 }
2726
2727 /*
2728 * Port ID changed or device was marked to be updated;
2729 * Log it out if still logged in and mark it for
2730 * relogin later.
2731 */
2732 fcport->d_id.b24 = new_fcport->d_id.b24;
2733 fcport->flags |= FCF_LOGIN_NEEDED;
2734 if (fcport->loop_id != FC_NO_LOOP_ID &&
2735 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2736 fcport->port_type != FCT_INITIATOR &&
2737 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002738 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002739 fcport->d_id.b.domain, fcport->d_id.b.area,
2740 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741 fcport->loop_id = FC_NO_LOOP_ID;
2742 }
2743
2744 break;
2745 }
2746
2747 if (found)
2748 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749 /* If device was not in our fcports list, then add it. */
2750 list_add_tail(&new_fcport->list, new_fcports);
2751
2752 /* Allocate a new replacement fcport. */
2753 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002754 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002756 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 return (QLA_MEMORY_ALLOC_FAILED);
2758 }
2759 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2760 new_fcport->d_id.b24 = nxt_d_id.b24;
2761 }
2762
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002763 kfree(swl);
2764 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 return (rval);
2767}
2768
2769/*
2770 * qla2x00_find_new_loop_id
2771 * Scan through our port list and find a new usable loop ID.
2772 *
2773 * Input:
2774 * ha: adapter state pointer.
2775 * dev: port structure pointer.
2776 *
2777 * Returns:
2778 * qla2x00 local function return status code.
2779 *
2780 * Context:
2781 * Kernel context.
2782 */
Adrian Bunk413975a2006-06-30 02:33:06 -07002783static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002784qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785{
2786 int rval;
2787 int found;
2788 fc_port_t *fcport;
2789 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002790 struct qla_hw_data *ha = vha->hw;
2791 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002792 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793
2794 rval = QLA_SUCCESS;
2795
2796 /* Save starting loop ID. */
2797 first_loop_id = dev->loop_id;
2798
2799 for (;;) {
2800 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002801 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803
2804 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002805 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807
2808 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002809 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810 /* first loop ID. */
2811 dev->loop_id = ha->min_external_loopid;
2812 }
2813
2814 /* Check for loop ID being already in use. */
2815 found = 0;
2816 fcport = NULL;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002817 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002818 list_for_each_entry(fcport, &vp->vp_fcports, list) {
2819 if (fcport->loop_id == dev->loop_id &&
2820 fcport != dev) {
2821 /* ID possibly in use */
2822 found++;
2823 break;
2824 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002826 if (found)
2827 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 }
2829
2830 /* If not in use then it is free to use. */
2831 if (!found) {
2832 break;
2833 }
2834
2835 /* ID in use. Try next value. */
2836 dev->loop_id++;
2837
2838 /* If wrap around. No free ID to use. */
2839 if (dev->loop_id == first_loop_id) {
2840 dev->loop_id = FC_NO_LOOP_ID;
2841 rval = QLA_FUNCTION_FAILED;
2842 break;
2843 }
2844 }
2845
2846 return (rval);
2847}
2848
2849/*
2850 * qla2x00_device_resync
2851 * Marks devices in the database that needs resynchronization.
2852 *
2853 * Input:
2854 * ha = adapter block pointer.
2855 *
2856 * Context:
2857 * Kernel context.
2858 */
2859static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002860qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861{
2862 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 uint32_t mask;
2864 fc_port_t *fcport;
2865 uint32_t rscn_entry;
2866 uint8_t rscn_out_iter;
2867 uint8_t format;
2868 port_id_t d_id;
2869
2870 rval = QLA_RSCNS_HANDLED;
2871
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002872 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
2873 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002875 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 format = MSB(MSW(rscn_entry));
2877 d_id.b.domain = LSB(MSW(rscn_entry));
2878 d_id.b.area = MSB(LSW(rscn_entry));
2879 d_id.b.al_pa = LSB(LSW(rscn_entry));
2880
2881 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2882 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002883 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884 d_id.b.area, d_id.b.al_pa));
2885
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002886 vha->rscn_out_ptr++;
2887 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
2888 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889
2890 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002891 for (rscn_out_iter = vha->rscn_out_ptr;
2892 !vha->flags.rscn_queue_overflow &&
2893 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 rscn_out_iter = (rscn_out_iter ==
2895 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2896
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002897 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 break;
2899
2900 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002901 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902 rscn_out_iter));
2903
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002904 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 }
2906
2907 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002908 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002910 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911
2912 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002913 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 }
2915
2916 switch (format) {
2917 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 mask = 0xffffff;
2919 break;
2920 case 1:
2921 mask = 0xffff00;
2922 break;
2923 case 2:
2924 mask = 0xff0000;
2925 break;
2926 default:
2927 mask = 0x0;
2928 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002929 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 break;
2931 }
2932
2933 rval = QLA_SUCCESS;
2934
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002935 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2937 (fcport->d_id.b24 & mask) != d_id.b24 ||
2938 fcport->port_type == FCT_BROADCAST)
2939 continue;
2940
2941 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2942 if (format != 3 ||
2943 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002944 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002945 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 }
2947 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 }
2949 }
2950 return (rval);
2951}
2952
2953/*
2954 * qla2x00_fabric_dev_login
2955 * Login fabric target device and update FC port database.
2956 *
2957 * Input:
2958 * ha: adapter state pointer.
2959 * fcport: port structure list pointer.
2960 * next_loopid: contains value of a new loop ID that can be used
2961 * by the next login attempt.
2962 *
2963 * Returns:
2964 * qla2x00 local function return status code.
2965 *
2966 * Context:
2967 * Kernel context.
2968 */
2969static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002970qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971 uint16_t *next_loopid)
2972{
2973 int rval;
2974 int retry;
Andrew Vasquez01071092005-07-06 10:31:37 -07002975 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002976 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977
2978 rval = QLA_SUCCESS;
2979 retry = 0;
2980
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002981 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 if (rval == QLA_SUCCESS) {
Andrew Vasquez01071092005-07-06 10:31:37 -07002983 /* Send an ADISC to tape devices.*/
2984 opts = 0;
2985 if (fcport->flags & FCF_TAPE_PRESENT)
2986 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002987 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002989 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002990 fcport->d_id.b.domain, fcport->d_id.b.area,
2991 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002992 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002994 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 }
2996 }
2997
2998 return (rval);
2999}
3000
3001/*
3002 * qla2x00_fabric_login
3003 * Issue fabric login command.
3004 *
3005 * Input:
3006 * ha = adapter block pointer.
3007 * device = pointer to FC device type structure.
3008 *
3009 * Returns:
3010 * 0 - Login successfully
3011 * 1 - Login failed
3012 * 2 - Initiator device
3013 * 3 - Fatal error
3014 */
3015int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003016qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 uint16_t *next_loopid)
3018{
3019 int rval;
3020 int retry;
3021 uint16_t tmp_loopid;
3022 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003023 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024
3025 retry = 0;
3026 tmp_loopid = 0;
3027
3028 for (;;) {
3029 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3030 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003031 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3033
3034 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003035 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 fcport->d_id.b.domain, fcport->d_id.b.area,
3037 fcport->d_id.b.al_pa, mb, BIT_0);
3038 if (mb[0] == MBS_PORT_ID_USED) {
3039 /*
3040 * Device has another loop ID. The firmware team
Andrew Vasquez01071092005-07-06 10:31:37 -07003041 * recommends the driver perform an implicit login with
3042 * the specified ID again. The ID we just used is save
3043 * here so we return with an ID that can be tried by
3044 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 */
3046 retry++;
3047 tmp_loopid = fcport->loop_id;
3048 fcport->loop_id = mb[1];
3049
3050 DEBUG(printk("Fabric Login: port in use - next "
3051 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3052 fcport->loop_id, fcport->d_id.b.domain,
3053 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3054
3055 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3056 /*
3057 * Login succeeded.
3058 */
3059 if (retry) {
3060 /* A retry occurred before. */
3061 *next_loopid = tmp_loopid;
3062 } else {
3063 /*
3064 * No retry occurred before. Just increment the
3065 * ID value for next login.
3066 */
3067 *next_loopid = (fcport->loop_id + 1);
3068 }
3069
3070 if (mb[1] & BIT_0) {
3071 fcport->port_type = FCT_INITIATOR;
3072 } else {
3073 fcport->port_type = FCT_TARGET;
3074 if (mb[1] & BIT_1) {
3075 fcport->flags |= FCF_TAPE_PRESENT;
3076 }
3077 }
3078
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003079 if (mb[10] & BIT_0)
3080 fcport->supported_classes |= FC_COS_CLASS2;
3081 if (mb[10] & BIT_1)
3082 fcport->supported_classes |= FC_COS_CLASS3;
3083
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 rval = QLA_SUCCESS;
3085 break;
3086 } else if (mb[0] == MBS_LOOP_ID_USED) {
3087 /*
3088 * Loop ID already used, try next loop ID.
3089 */
3090 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003091 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 if (rval != QLA_SUCCESS) {
3093 /* Ran out of loop IDs to use */
3094 break;
3095 }
3096 } else if (mb[0] == MBS_COMMAND_ERROR) {
3097 /*
3098 * Firmware possibly timed out during login. If NO
3099 * retries are left to do then the device is declared
3100 * dead.
3101 */
3102 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003103 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003104 fcport->d_id.b.domain, fcport->d_id.b.area,
3105 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003106 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107
3108 rval = 1;
3109 break;
3110 } else {
3111 /*
3112 * unrecoverable / not handled error
3113 */
3114 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003115 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003116 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117 fcport->d_id.b.domain, fcport->d_id.b.area,
3118 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3119
3120 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003121 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003122 fcport->d_id.b.domain, fcport->d_id.b.area,
3123 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003125 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126
3127 rval = 3;
3128 break;
3129 }
3130 }
3131
3132 return (rval);
3133}
3134
3135/*
3136 * qla2x00_local_device_login
3137 * Issue local device login command.
3138 *
3139 * Input:
3140 * ha = adapter block pointer.
3141 * loop_id = loop id of device to login to.
3142 *
3143 * Returns (Where's the #define!!!!):
3144 * 0 - Login successfully
3145 * 1 - Login failed
3146 * 3 - Fatal error
3147 */
3148int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003149qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150{
3151 int rval;
3152 uint16_t mb[MAILBOX_REGISTER_COUNT];
3153
3154 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003155 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156 if (rval == QLA_SUCCESS) {
3157 /* Interrogate mailbox registers for any errors */
3158 if (mb[0] == MBS_COMMAND_ERROR)
3159 rval = 1;
3160 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3161 /* device not in PCB table */
3162 rval = 3;
3163 }
3164
3165 return (rval);
3166}
3167
3168/*
3169 * qla2x00_loop_resync
3170 * Resync with fibre channel devices.
3171 *
3172 * Input:
3173 * ha = adapter block pointer.
3174 *
3175 * Returns:
3176 * 0 = success
3177 */
3178int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003179qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003181 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182 uint32_t wait_time;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003183 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003184 struct req_que *req = ha->req_q_map[vha->req_ques[0]];
3185 struct rsp_que *rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003187 atomic_set(&vha->loop_state, LOOP_UPDATE);
3188 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3189 if (vha->flags.online) {
3190 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3192 wait_time = 256;
3193 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003194 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195
Andrew Vasquez01071092005-07-06 10:31:37 -07003196 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003197 qla2x00_marker(vha, req, rsp, 0, 0,
3198 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003199 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200
3201 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003202 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003204 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003206 } while (!atomic_read(&vha->loop_down_timer) &&
3207 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3208 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3209 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211 }
3212
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003213 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003216 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218
3219 return (rval);
3220}
3221
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003223qla2x00_update_fcports(scsi_qla_host_t *vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003224{
3225 fc_port_t *fcport;
3226
3227 /* Go with deferred removal of rport references. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003228 list_for_each_entry(fcport, &vha->vp_fcports, list)
3229 if (fcport && fcport->drport &&
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07003230 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003231 qla2x00_rport_del(fcport);
3232}
3233
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234/*
3235* qla2x00_abort_isp
3236* Resets ISP and aborts all outstanding commands.
3237*
3238* Input:
3239* ha = adapter block pointer.
3240*
3241* Returns:
3242* 0 = success
3243*/
3244int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003245qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003247 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003249 struct qla_hw_data *ha = vha->hw;
3250 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003251 struct scsi_qla_host *tvp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003252 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003254 if (vha->flags.online) {
3255 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -07003256 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003257 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07003258 ha->qla_stats.total_isp_aborts++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259
3260 qla_printk(KERN_INFO, ha,
3261 "Performing ISP error recovery - ha= %p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003262 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003264 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3265 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3266 atomic_set(&vha->loop_state, LOOP_DOWN);
3267 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003268 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003269 qla2x00_mark_all_devices_lost(vp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003271 if (!atomic_read(&vha->loop_down_timer))
3272 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273 LOOP_DOWN_TIME);
3274 }
3275
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 /* Requeue all commands in outstanding command list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003277 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003279 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003280
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003281 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003283 if (!qla2x00_restart_isp(vha)) {
3284 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003286 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287 /*
3288 * Issue marker command only when we are going
3289 * to start the I/O .
3290 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003291 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292 }
3293
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003294 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003296 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003298 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003299 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003300
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003301 if (ha->fce) {
3302 ha->flags.fce_enabled = 1;
3303 memset(ha->fce, 0,
3304 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003305 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003306 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3307 &ha->fce_bufs);
3308 if (rval) {
3309 qla_printk(KERN_WARNING, ha,
3310 "Unable to reinitialize FCE "
3311 "(%d).\n", rval);
3312 ha->flags.fce_enabled = 0;
3313 }
3314 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003315
3316 if (ha->eft) {
3317 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003318 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003319 ha->eft_dma, EFT_NUM_BUFFERS);
3320 if (rval) {
3321 qla_printk(KERN_WARNING, ha,
3322 "Unable to reinitialize EFT "
3323 "(%d).\n", rval);
3324 }
3325 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003327 vha->flags.online = 1;
3328 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329 if (ha->isp_abort_cnt == 0) {
3330 qla_printk(KERN_WARNING, ha,
3331 "ISP error recovery failed - "
3332 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003333 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334 * The next call disables the board
3335 * completely.
3336 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003337 ha->isp_ops->reset_adapter(vha);
3338 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003340 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341 status = 0;
3342 } else { /* schedule another ISP abort */
3343 ha->isp_abort_cnt--;
3344 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez01071092005-07-06 10:31:37 -07003345 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003346 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003347 status = 1;
3348 }
3349 } else {
3350 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3351 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3352 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003353 vha->host_no, ha->isp_abort_cnt));
3354 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 status = 1;
3356 }
3357 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003358
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 }
3360
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003361 if (!status) {
3362 DEBUG(printk(KERN_INFO
3363 "qla2x00_abort_isp(%ld): succeeded.\n",
3364 vha->host_no));
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003365 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003366 if (vp->vp_idx)
3367 qla2x00_vp_abort_isp(vp);
3368 }
3369 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370 qla_printk(KERN_INFO, ha,
3371 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372 }
3373
3374 return(status);
3375}
3376
3377/*
3378* qla2x00_restart_isp
3379* restarts the ISP after a reset
3380*
3381* Input:
3382* ha = adapter block pointer.
3383*
3384* Returns:
3385* 0 = success
3386*/
3387static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003388qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003390 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003392 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003393 struct req_que *req = ha->req_q_map[0];
3394 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395
3396 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003397 if (qla2x00_isp_firmware(vha)) {
3398 vha->flags.online = 0;
3399 status = ha->isp_ops->chip_diag(vha);
3400 if (!status)
3401 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402 }
3403
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003404 if (!status && !(status = qla2x00_init_rings(vha))) {
3405 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07003406 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003407 /* Initialize the queues in use */
3408 qla25xx_init_queues(ha);
3409
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003410 status = qla2x00_fw_ready(vha);
3411 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003413 "status = %d\n", __func__, status));
Andrew Vasquez01071092005-07-06 10:31:37 -07003414
3415 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003416 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez01071092005-07-06 10:31:37 -07003417
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003418 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3420 wait_time = 256;
3421 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003422 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3423 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003425 } while (!atomic_read(&vha->loop_down_timer) &&
3426 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3427 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3428 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429 }
3430
3431 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003432 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433 status = 0;
3434
3435 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3436 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003437 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438 }
3439 return (status);
3440}
3441
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003442static int
3443qla25xx_init_queues(struct qla_hw_data *ha)
3444{
3445 struct rsp_que *rsp = NULL;
3446 struct req_que *req = NULL;
3447 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3448 int ret = -1;
3449 int i;
3450
3451 for (i = 1; i < ha->max_queues; i++) {
3452 rsp = ha->rsp_q_map[i];
3453 if (rsp) {
3454 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003455 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003456 if (ret != QLA_SUCCESS)
3457 DEBUG2_17(printk(KERN_WARNING
3458 "%s Rsp que:%d init failed\n", __func__,
3459 rsp->id));
3460 else
3461 DEBUG2_17(printk(KERN_INFO
3462 "%s Rsp que:%d inited\n", __func__,
3463 rsp->id));
3464 }
3465 req = ha->req_q_map[i];
3466 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003467 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003468 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003469 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003470 if (ret != QLA_SUCCESS)
3471 DEBUG2_17(printk(KERN_WARNING
3472 "%s Req que:%d init failed\n", __func__,
3473 req->id));
3474 else
3475 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003476 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003477 req->id));
3478 }
3479 }
3480 return ret;
3481}
3482
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483/*
3484* qla2x00_reset_adapter
3485* Reset adapter.
3486*
3487* Input:
3488* ha = adapter block pointer.
3489*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003490void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003491qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492{
3493 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003494 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003495 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003497 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003498 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500 spin_lock_irqsave(&ha->hardware_lock, flags);
3501 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3502 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3503 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3504 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3505 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3506}
Andrew Vasquez01071092005-07-06 10:31:37 -07003507
3508void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003509qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07003510{
3511 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003512 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07003513 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3514
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003515 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003516 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez01071092005-07-06 10:31:37 -07003517
3518 spin_lock_irqsave(&ha->hardware_lock, flags);
3519 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3520 RD_REG_DWORD(&reg->hccr);
3521 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3522 RD_REG_DWORD(&reg->hccr);
3523 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08003524
3525 if (IS_NOPOLLING_TYPE(ha))
3526 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez01071092005-07-06 10:31:37 -07003527}
3528
David Miller4e08df32007-04-16 12:37:43 -07003529/* On sparc systems, obtain port and node WWN from firmware
3530 * properties.
3531 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003532static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3533 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07003534{
3535#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003536 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003537 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003538 struct device_node *dp = pci_device_to_OF_node(pdev);
3539 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003540 int len;
3541
3542 val = of_get_property(dp, "port-wwn", &len);
3543 if (val && len >= WWN_SIZE)
3544 memcpy(nv->port_name, val, WWN_SIZE);
3545
3546 val = of_get_property(dp, "node-wwn", &len);
3547 if (val && len >= WWN_SIZE)
3548 memcpy(nv->node_name, val, WWN_SIZE);
3549#endif
3550}
3551
Andrew Vasquez01071092005-07-06 10:31:37 -07003552int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003553qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07003554{
David Miller4e08df32007-04-16 12:37:43 -07003555 int rval;
Andrew Vasquez01071092005-07-06 10:31:37 -07003556 struct init_cb_24xx *icb;
3557 struct nvram_24xx *nv;
3558 uint32_t *dptr;
3559 uint8_t *dptr1, *dptr2;
3560 uint32_t chksum;
3561 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003562 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07003563
David Miller4e08df32007-04-16 12:37:43 -07003564 rval = QLA_SUCCESS;
Andrew Vasquez01071092005-07-06 10:31:37 -07003565 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003566 nv = ha->nvram;
Andrew Vasquez01071092005-07-06 10:31:37 -07003567
3568 /* Determine NVRAM starting address. */
3569 ha->nvram_size = sizeof(struct nvram_24xx);
3570 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003571 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3572 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3573 if (PCI_FUNC(ha->pdev->devfn)) {
Andrew Vasquez01071092005-07-06 10:31:37 -07003574 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003575 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3576 }
Andrew Vasquez01071092005-07-06 10:31:37 -07003577
Seokmann Ju281afe12007-07-26 13:43:34 -07003578 /* Get VPD data into cache */
3579 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003580 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07003581 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3582
3583 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez01071092005-07-06 10:31:37 -07003584 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003585 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez01071092005-07-06 10:31:37 -07003586 ha->nvram_size);
3587 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3588 chksum += le32_to_cpu(*dptr++);
3589
3590 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07003591 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez01071092005-07-06 10:31:37 -07003592
3593 /* Bad NVRAM data, set defaults parameters. */
3594 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3595 || nv->id[3] != ' ' ||
3596 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3597 /* Reset NVRAM data. */
3598 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3599 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3600 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07003601 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3602 "invalid -- WWPN) defaults.\n");
3603
3604 /*
3605 * Set default initialization control block.
3606 */
3607 memset(nv, 0, ha->nvram_size);
3608 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3609 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3610 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3611 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3612 nv->exchange_count = __constant_cpu_to_le16(0);
3613 nv->hard_address = __constant_cpu_to_le16(124);
3614 nv->port_name[0] = 0x21;
3615 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3616 nv->port_name[2] = 0x00;
3617 nv->port_name[3] = 0xe0;
3618 nv->port_name[4] = 0x8b;
3619 nv->port_name[5] = 0x1c;
3620 nv->port_name[6] = 0x55;
3621 nv->port_name[7] = 0x86;
3622 nv->node_name[0] = 0x20;
3623 nv->node_name[1] = 0x00;
3624 nv->node_name[2] = 0x00;
3625 nv->node_name[3] = 0xe0;
3626 nv->node_name[4] = 0x8b;
3627 nv->node_name[5] = 0x1c;
3628 nv->node_name[6] = 0x55;
3629 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003630 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07003631 nv->login_retry_count = __constant_cpu_to_le16(8);
3632 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3633 nv->login_timeout = __constant_cpu_to_le16(0);
3634 nv->firmware_options_1 =
3635 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3636 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3637 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3638 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3639 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3640 nv->efi_parameters = __constant_cpu_to_le32(0);
3641 nv->reset_delay = 5;
3642 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3643 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3644 nv->link_down_timeout = __constant_cpu_to_le16(30);
3645
3646 rval = 1;
Andrew Vasquez01071092005-07-06 10:31:37 -07003647 }
3648
3649 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003650 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez01071092005-07-06 10:31:37 -07003651
3652 /* Copy 1st segment. */
3653 dptr1 = (uint8_t *)icb;
3654 dptr2 = (uint8_t *)&nv->version;
3655 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3656 while (cnt--)
3657 *dptr1++ = *dptr2++;
3658
3659 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07003660 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez01071092005-07-06 10:31:37 -07003661
3662 /* Copy 2nd segment. */
3663 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3664 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3665 cnt = (uint8_t *)&icb->reserved_3 -
3666 (uint8_t *)&icb->interrupt_delay_timer;
3667 while (cnt--)
3668 *dptr1++ = *dptr2++;
3669
3670 /*
3671 * Setup driver NVRAM options.
3672 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003673 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003674 "QLA2462");
Andrew Vasquez01071092005-07-06 10:31:37 -07003675
Andrew Vasquez5341e862006-05-17 15:09:16 -07003676 /* Use alternate WWN? */
3677 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3678 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3679 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3680 }
3681
Andrew Vasquez01071092005-07-06 10:31:37 -07003682 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003683 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez01071092005-07-06 10:31:37 -07003684 /*
3685 * Firmware will apply the following mask if the nodename was
3686 * not provided.
3687 */
3688 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3689 icb->node_name[0] &= 0xF0;
3690 }
3691
3692 /* Set host adapter parameters. */
3693 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08003694 ha->flags.enable_lip_reset = 0;
3695 ha->flags.enable_lip_full_login =
3696 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3697 ha->flags.enable_target_reset =
3698 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez01071092005-07-06 10:31:37 -07003699 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07003700 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez01071092005-07-06 10:31:37 -07003701
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003702 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3703 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez01071092005-07-06 10:31:37 -07003704
3705 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3706 sizeof(ha->fw_seriallink_options24));
3707
3708 /* save HBA serial number */
3709 ha->serial0 = icb->port_name[5];
3710 ha->serial1 = icb->port_name[6];
3711 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003712 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
3713 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez01071092005-07-06 10:31:37 -07003714
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08003715 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3716
Andrew Vasquez01071092005-07-06 10:31:37 -07003717 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3718
3719 /* Set minimum login_timeout to 4 seconds. */
3720 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3721 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3722 if (le16_to_cpu(nv->login_timeout) < 4)
3723 nv->login_timeout = __constant_cpu_to_le16(4);
3724 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07003725 icb->login_timeout = nv->login_timeout;
Andrew Vasquez01071092005-07-06 10:31:37 -07003726
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003727 /* Set minimum RATOV to 100 tenths of a second. */
3728 ha->r_a_tov = 100;
Andrew Vasquez01071092005-07-06 10:31:37 -07003729
3730 ha->loop_reset_delay = nv->reset_delay;
3731
3732 /* Link Down Timeout = 0:
3733 *
3734 * When Port Down timer expires we will start returning
3735 * I/O's to OS with "DID_NO_CONNECT".
3736 *
3737 * Link Down Timeout != 0:
3738 *
3739 * The driver waits for the link to come up after link down
3740 * before returning I/Os to OS with "DID_NO_CONNECT".
3741 */
3742 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3743 ha->loop_down_abort_time =
3744 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3745 } else {
3746 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3747 ha->loop_down_abort_time =
3748 (LOOP_DOWN_TIME - ha->link_down_timeout);
3749 }
3750
3751 /* Need enough time to try and get the port back. */
3752 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3753 if (qlport_down_retry)
3754 ha->port_down_retry_count = qlport_down_retry;
3755
3756 /* Set login_retry_count */
3757 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3758 if (ha->port_down_retry_count ==
3759 le16_to_cpu(nv->port_down_retry_count) &&
3760 ha->port_down_retry_count > 3)
3761 ha->login_retry_count = ha->port_down_retry_count;
3762 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3763 ha->login_retry_count = ha->port_down_retry_count;
3764 if (ql2xloginretrycount)
3765 ha->login_retry_count = ql2xloginretrycount;
3766
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003767 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003768 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003769 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3770 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3771 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3772 le16_to_cpu(icb->interrupt_delay_timer): 2;
3773 }
3774 icb->firmware_options_2 &= __constant_cpu_to_le32(
3775 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003776 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003777 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08003778 ha->zio_mode = QLA_ZIO_MODE_6;
3779
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003780 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003781 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003782 ha->zio_timer * 100));
3783 qla_printk(KERN_INFO, ha,
3784 "ZIO mode %d enabled; timer delay (%d us).\n",
3785 ha->zio_mode, ha->zio_timer * 100);
3786
3787 icb->firmware_options_2 |= cpu_to_le32(
3788 (uint32_t)ha->zio_mode);
3789 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003790 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003791 }
3792
David Miller4e08df32007-04-16 12:37:43 -07003793 if (rval) {
3794 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003795 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07003796 }
3797 return (rval);
Andrew Vasquez01071092005-07-06 10:31:37 -07003798}
3799
Adrian Bunk413975a2006-06-30 02:33:06 -07003800static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003801qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003802{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003803 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003804 int segments, fragment;
3805 uint32_t faddr;
3806 uint32_t *dcode, dlen;
3807 uint32_t risc_addr;
3808 uint32_t risc_size;
3809 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003810 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003811 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08003812
3813 qla_printk(KERN_INFO, ha,
3814 "FW: Loading from flash (%x)...\n", ha->flt_region_fw);
3815
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003816 rval = QLA_SUCCESS;
3817
3818 segments = FA_RISC_CODE_SEGMENTS;
Andrew Vasquezc00d8992008-09-11 21:22:49 -07003819 faddr = ha->flt_region_fw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003820 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003821 *srisc_addr = 0;
3822
3823 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003824 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003825 for (i = 0; i < 4; i++)
3826 dcode[i] = be32_to_cpu(dcode[i]);
3827 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3828 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3829 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3830 dcode[3] == 0)) {
3831 qla_printk(KERN_WARNING, ha,
3832 "Unable to verify integrity of flash firmware image!\n");
3833 qla_printk(KERN_WARNING, ha,
3834 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3835 dcode[1], dcode[2], dcode[3]);
3836
3837 return QLA_FUNCTION_FAILED;
3838 }
3839
3840 while (segments && rval == QLA_SUCCESS) {
3841 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003842 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003843
3844 risc_addr = be32_to_cpu(dcode[2]);
3845 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3846 risc_size = be32_to_cpu(dcode[3]);
3847
3848 fragment = 0;
3849 while (risc_size > 0 && rval == QLA_SUCCESS) {
3850 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3851 if (dlen > risc_size)
3852 dlen = risc_size;
3853
3854 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3855 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003856 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003857
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003858 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003859 for (i = 0; i < dlen; i++)
3860 dcode[i] = swab32(dcode[i]);
3861
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003862 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003863 dlen);
3864 if (rval) {
3865 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003866 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003867 fragment));
3868 qla_printk(KERN_WARNING, ha,
3869 "[ERROR] Failed to load segment %d of "
3870 "firmware\n", fragment);
3871 break;
3872 }
3873
3874 faddr += dlen;
3875 risc_addr += dlen;
3876 risc_size -= dlen;
3877 fragment++;
3878 }
3879
3880 /* Next segment. */
3881 segments--;
3882 }
3883
3884 return rval;
3885}
3886
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003887#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3888
Andrew Vasquez01071092005-07-06 10:31:37 -07003889int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003890qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08003891{
3892 int rval;
3893 int i, fragment;
3894 uint16_t *wcode, *fwcode;
3895 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3896 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003897 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003898 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08003899
3900 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003901 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08003902 if (!blob) {
3903 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003904 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3905 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08003906 return QLA_FUNCTION_FAILED;
3907 }
3908
3909 rval = QLA_SUCCESS;
3910
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003911 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08003912 *srisc_addr = 0;
3913 fwcode = (uint16_t *)blob->fw->data;
3914 fwclen = 0;
3915
3916 /* Validate firmware image by checking version. */
3917 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3918 qla_printk(KERN_WARNING, ha,
3919 "Unable to verify integrity of firmware image (%Zd)!\n",
3920 blob->fw->size);
3921 goto fail_fw_integrity;
3922 }
3923 for (i = 0; i < 4; i++)
3924 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3925 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3926 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3927 wcode[2] == 0 && wcode[3] == 0)) {
3928 qla_printk(KERN_WARNING, ha,
3929 "Unable to verify integrity of firmware image!\n");
3930 qla_printk(KERN_WARNING, ha,
3931 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3932 wcode[1], wcode[2], wcode[3]);
3933 goto fail_fw_integrity;
3934 }
3935
3936 seg = blob->segs;
3937 while (*seg && rval == QLA_SUCCESS) {
3938 risc_addr = *seg;
3939 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3940 risc_size = be16_to_cpu(fwcode[3]);
3941
3942 /* Validate firmware image size. */
3943 fwclen += risc_size * sizeof(uint16_t);
3944 if (blob->fw->size < fwclen) {
3945 qla_printk(KERN_WARNING, ha,
3946 "Unable to verify integrity of firmware image "
3947 "(%Zd)!\n", blob->fw->size);
3948 goto fail_fw_integrity;
3949 }
3950
3951 fragment = 0;
3952 while (risc_size > 0 && rval == QLA_SUCCESS) {
3953 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3954 if (wlen > risc_size)
3955 wlen = risc_size;
3956
3957 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003958 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08003959 risc_addr, wlen));
3960
3961 for (i = 0; i < wlen; i++)
3962 wcode[i] = swab16(fwcode[i]);
3963
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003964 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08003965 wlen);
3966 if (rval) {
3967 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003968 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08003969 fragment));
3970 qla_printk(KERN_WARNING, ha,
3971 "[ERROR] Failed to load segment %d of "
3972 "firmware\n", fragment);
3973 break;
3974 }
3975
3976 fwcode += wlen;
3977 risc_addr += wlen;
3978 risc_size -= wlen;
3979 fragment++;
3980 }
3981
3982 /* Next segment. */
3983 seg++;
3984 }
3985 return rval;
3986
3987fail_fw_integrity:
3988 return QLA_FUNCTION_FAILED;
3989}
3990
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08003991static int
3992qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez01071092005-07-06 10:31:37 -07003993{
3994 int rval;
3995 int segments, fragment;
3996 uint32_t *dcode, dlen;
3997 uint32_t risc_addr;
3998 uint32_t risc_size;
3999 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004000 struct fw_blob *blob;
Andrew Vasquez01071092005-07-06 10:31:37 -07004001 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004002 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004003 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez01071092005-07-06 10:31:37 -07004004
Andrew Vasquez54333832005-11-09 15:49:04 -08004005 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004006 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004007 if (!blob) {
4008 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004009 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4010 "from: " QLA_FW_URL ".\n");
4011
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004012 return QLA_FUNCTION_FAILED;
Andrew Vasquez01071092005-07-06 10:31:37 -07004013 }
4014
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004015 qla_printk(KERN_INFO, ha,
4016 "FW: Loading via request-firmware...\n");
4017
Andrew Vasquez01071092005-07-06 10:31:37 -07004018 rval = QLA_SUCCESS;
4019
4020 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004021 dcode = (uint32_t *)req->ring;
Andrew Vasquez01071092005-07-06 10:31:37 -07004022 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004023 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez01071092005-07-06 10:31:37 -07004024 fwclen = 0;
4025
4026 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004027 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez01071092005-07-06 10:31:37 -07004028 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004029 "Unable to verify integrity of firmware image (%Zd)!\n",
4030 blob->fw->size);
Andrew Vasquez01071092005-07-06 10:31:37 -07004031 goto fail_fw_integrity;
4032 }
4033 for (i = 0; i < 4; i++)
4034 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4035 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4036 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4037 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4038 dcode[3] == 0)) {
4039 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004040 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez01071092005-07-06 10:31:37 -07004041 qla_printk(KERN_WARNING, ha,
4042 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4043 dcode[1], dcode[2], dcode[3]);
4044 goto fail_fw_integrity;
4045 }
4046
4047 while (segments && rval == QLA_SUCCESS) {
4048 risc_addr = be32_to_cpu(fwcode[2]);
4049 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4050 risc_size = be32_to_cpu(fwcode[3]);
4051
4052 /* Validate firmware image size. */
4053 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004054 if (blob->fw->size < fwclen) {
Andrew Vasquez01071092005-07-06 10:31:37 -07004055 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004056 "Unable to verify integrity of firmware image "
4057 "(%Zd)!\n", blob->fw->size);
4058
Andrew Vasquez01071092005-07-06 10:31:37 -07004059 goto fail_fw_integrity;
4060 }
4061
4062 fragment = 0;
4063 while (risc_size > 0 && rval == QLA_SUCCESS) {
4064 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4065 if (dlen > risc_size)
4066 dlen = risc_size;
4067
4068 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004069 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez01071092005-07-06 10:31:37 -07004070 risc_addr, dlen));
4071
4072 for (i = 0; i < dlen; i++)
4073 dcode[i] = swab32(fwcode[i]);
4074
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004075 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004076 dlen);
Andrew Vasquez01071092005-07-06 10:31:37 -07004077 if (rval) {
4078 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004079 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez01071092005-07-06 10:31:37 -07004080 fragment));
4081 qla_printk(KERN_WARNING, ha,
4082 "[ERROR] Failed to load segment %d of "
4083 "firmware\n", fragment);
4084 break;
4085 }
4086
4087 fwcode += dlen;
4088 risc_addr += dlen;
4089 risc_size -= dlen;
4090 fragment++;
4091 }
4092
4093 /* Next segment. */
4094 segments--;
4095 }
Andrew Vasquez01071092005-07-06 10:31:37 -07004096 return rval;
4097
4098fail_fw_integrity:
Andrew Vasquez01071092005-07-06 10:31:37 -07004099 return QLA_FUNCTION_FAILED;
Andrew Vasquez01071092005-07-06 10:31:37 -07004100}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004101
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004102int
4103qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4104{
4105 int rval;
4106
4107 /*
4108 * FW Load priority:
4109 * 1) Firmware via request-firmware interface (.bin file).
4110 * 2) Firmware residing in flash.
4111 */
4112 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4113 if (rval == QLA_SUCCESS)
4114 return rval;
4115
4116 return qla24xx_load_risc_flash(vha, srisc_addr);
4117}
4118
4119int
4120qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4121{
4122 int rval;
4123
4124 /*
4125 * FW Load priority:
4126 * 1) Firmware residing in flash.
4127 * 2) Firmware via request-firmware interface (.bin file).
4128 */
4129 rval = qla24xx_load_risc_flash(vha, srisc_addr);
4130 if (rval == QLA_SUCCESS)
4131 return rval;
4132
4133 return qla24xx_load_risc_blob(vha, srisc_addr);
4134}
4135
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004136void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004137qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004138{
4139 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004140 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004141
Andrew Vasqueze4289242007-07-19 15:05:56 -07004142 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004143 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004144 if (!ha->fw_major_version)
4145 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004146
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004147 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004148 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
4149 retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004150 ha->isp_ops->reset_chip(vha);
4151 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004152 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004153 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004154 continue;
4155 qla_printk(KERN_INFO, ha,
4156 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004157 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004158 }
4159}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004160
4161int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004162qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004163{
4164 int rval = QLA_SUCCESS;
4165 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004166 struct qla_hw_data *ha = vha->hw;
4167 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004168 struct req_que *req = ha->req_q_map[vha->req_ques[0]];
4169 struct rsp_que *rsp = req->rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004170
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004171 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004172 return -EINVAL;
4173
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004174 rval = qla2x00_fw_ready(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004175 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004176 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004177 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004178 }
4179
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004180 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004181
4182 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004183 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004184 if (mb[0] != MBS_COMMAND_COMPLETE) {
4185 DEBUG15(qla_printk(KERN_INFO, ha,
4186 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4187 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4188 mb[0], mb[1], mb[2], mb[6], mb[7]));
4189 return (QLA_FUNCTION_FAILED);
4190 }
4191
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004192 atomic_set(&vha->loop_down_timer, 0);
4193 atomic_set(&vha->loop_state, LOOP_UP);
4194 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4195 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4196 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004197
4198 return rval;
4199}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004200
4201/* 84XX Support **************************************************************/
4202
4203static LIST_HEAD(qla_cs84xx_list);
4204static DEFINE_MUTEX(qla_cs84xx_mutex);
4205
4206static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004207qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004208{
4209 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004210 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004211
4212 mutex_lock(&qla_cs84xx_mutex);
4213
4214 /* Find any shared 84xx chip. */
4215 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4216 if (cs84xx->bus == ha->pdev->bus) {
4217 kref_get(&cs84xx->kref);
4218 goto done;
4219 }
4220 }
4221
4222 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4223 if (!cs84xx)
4224 goto done;
4225
4226 kref_init(&cs84xx->kref);
4227 spin_lock_init(&cs84xx->access_lock);
4228 mutex_init(&cs84xx->fw_update_mutex);
4229 cs84xx->bus = ha->pdev->bus;
4230
4231 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4232done:
4233 mutex_unlock(&qla_cs84xx_mutex);
4234 return cs84xx;
4235}
4236
4237static void
4238__qla84xx_chip_release(struct kref *kref)
4239{
4240 struct qla_chip_state_84xx *cs84xx =
4241 container_of(kref, struct qla_chip_state_84xx, kref);
4242
4243 mutex_lock(&qla_cs84xx_mutex);
4244 list_del(&cs84xx->list);
4245 mutex_unlock(&qla_cs84xx_mutex);
4246 kfree(cs84xx);
4247}
4248
4249void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004250qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004251{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004252 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004253 if (ha->cs84xx)
4254 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4255}
4256
4257static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004258qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004259{
4260 int rval;
4261 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004262 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004263
4264 mutex_lock(&ha->cs84xx->fw_update_mutex);
4265
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004266 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004267
4268 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4269
4270 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4271 QLA_SUCCESS;
4272}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004273
4274/* 81XX Support **************************************************************/
4275
4276int
4277qla81xx_nvram_config(scsi_qla_host_t *vha)
4278{
4279 int rval;
4280 struct init_cb_81xx *icb;
4281 struct nvram_81xx *nv;
4282 uint32_t *dptr;
4283 uint8_t *dptr1, *dptr2;
4284 uint32_t chksum;
4285 uint16_t cnt;
4286 struct qla_hw_data *ha = vha->hw;
4287
4288 rval = QLA_SUCCESS;
4289 icb = (struct init_cb_81xx *)ha->init_cb;
4290 nv = ha->nvram;
4291
4292 /* Determine NVRAM starting address. */
4293 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004294 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004295
4296 /* Get VPD data into cache */
4297 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d790382009-03-24 09:08:14 -07004298 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
4299 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004300
4301 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d790382009-03-24 09:08:14 -07004302 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004303 ha->nvram_size);
Andrew Vasquez3d790382009-03-24 09:08:14 -07004304 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004305 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4306 chksum += le32_to_cpu(*dptr++);
4307
4308 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
4309 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4310
4311 /* Bad NVRAM data, set defaults parameters. */
4312 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4313 || nv->id[3] != ' ' ||
4314 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4315 /* Reset NVRAM data. */
4316 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4317 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4318 le16_to_cpu(nv->nvram_version));
4319 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4320 "invalid -- WWPN) defaults.\n");
4321
4322 /*
4323 * Set default initialization control block.
4324 */
4325 memset(nv, 0, ha->nvram_size);
4326 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4327 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4328 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4329 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4330 nv->exchange_count = __constant_cpu_to_le16(0);
4331 nv->port_name[0] = 0x21;
4332 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
4333 nv->port_name[2] = 0x00;
4334 nv->port_name[3] = 0xe0;
4335 nv->port_name[4] = 0x8b;
4336 nv->port_name[5] = 0x1c;
4337 nv->port_name[6] = 0x55;
4338 nv->port_name[7] = 0x86;
4339 nv->node_name[0] = 0x20;
4340 nv->node_name[1] = 0x00;
4341 nv->node_name[2] = 0x00;
4342 nv->node_name[3] = 0xe0;
4343 nv->node_name[4] = 0x8b;
4344 nv->node_name[5] = 0x1c;
4345 nv->node_name[6] = 0x55;
4346 nv->node_name[7] = 0x86;
4347 nv->login_retry_count = __constant_cpu_to_le16(8);
4348 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4349 nv->login_timeout = __constant_cpu_to_le16(0);
4350 nv->firmware_options_1 =
4351 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4352 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4353 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4354 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4355 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4356 nv->efi_parameters = __constant_cpu_to_le32(0);
4357 nv->reset_delay = 5;
4358 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4359 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4360 nv->link_down_timeout = __constant_cpu_to_le16(30);
4361 nv->enode_mac[0] = 0x01;
4362 nv->enode_mac[1] = 0x02;
4363 nv->enode_mac[2] = 0x03;
4364 nv->enode_mac[3] = 0x04;
4365 nv->enode_mac[4] = 0x05;
4366 nv->enode_mac[5] = 0x06 + PCI_FUNC(ha->pdev->devfn);
4367
4368 rval = 1;
4369 }
4370
4371 /* Reset Initialization control block */
4372 memset(icb, 0, sizeof(struct init_cb_81xx));
4373
4374 /* Copy 1st segment. */
4375 dptr1 = (uint8_t *)icb;
4376 dptr2 = (uint8_t *)&nv->version;
4377 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4378 while (cnt--)
4379 *dptr1++ = *dptr2++;
4380
4381 icb->login_retry_count = nv->login_retry_count;
4382
4383 /* Copy 2nd segment. */
4384 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4385 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4386 cnt = (uint8_t *)&icb->reserved_5 -
4387 (uint8_t *)&icb->interrupt_delay_timer;
4388 while (cnt--)
4389 *dptr1++ = *dptr2++;
4390
4391 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
4392 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4393 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
4394 icb->enode_mac[0] = 0x01;
4395 icb->enode_mac[1] = 0x02;
4396 icb->enode_mac[2] = 0x03;
4397 icb->enode_mac[3] = 0x04;
4398 icb->enode_mac[4] = 0x05;
4399 icb->enode_mac[5] = 0x06 + PCI_FUNC(ha->pdev->devfn);
4400 }
4401
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004402 /* Use extended-initialization control block. */
4403 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
4404
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004405 /*
4406 * Setup driver NVRAM options.
4407 */
4408 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
4409 "QLE81XX");
4410
4411 /* Use alternate WWN? */
4412 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4413 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4414 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4415 }
4416
4417 /* Prepare nodename */
4418 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4419 /*
4420 * Firmware will apply the following mask if the nodename was
4421 * not provided.
4422 */
4423 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4424 icb->node_name[0] &= 0xF0;
4425 }
4426
4427 /* Set host adapter parameters. */
4428 ha->flags.disable_risc_code_load = 0;
4429 ha->flags.enable_lip_reset = 0;
4430 ha->flags.enable_lip_full_login =
4431 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4432 ha->flags.enable_target_reset =
4433 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4434 ha->flags.enable_led_scheme = 0;
4435 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4436
4437 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4438 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4439
4440 /* save HBA serial number */
4441 ha->serial0 = icb->port_name[5];
4442 ha->serial1 = icb->port_name[6];
4443 ha->serial2 = icb->port_name[7];
4444 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4445 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4446
4447 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4448
4449 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4450
4451 /* Set minimum login_timeout to 4 seconds. */
4452 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4453 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4454 if (le16_to_cpu(nv->login_timeout) < 4)
4455 nv->login_timeout = __constant_cpu_to_le16(4);
4456 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4457 icb->login_timeout = nv->login_timeout;
4458
4459 /* Set minimum RATOV to 100 tenths of a second. */
4460 ha->r_a_tov = 100;
4461
4462 ha->loop_reset_delay = nv->reset_delay;
4463
4464 /* Link Down Timeout = 0:
4465 *
4466 * When Port Down timer expires we will start returning
4467 * I/O's to OS with "DID_NO_CONNECT".
4468 *
4469 * Link Down Timeout != 0:
4470 *
4471 * The driver waits for the link to come up after link down
4472 * before returning I/Os to OS with "DID_NO_CONNECT".
4473 */
4474 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4475 ha->loop_down_abort_time =
4476 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4477 } else {
4478 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4479 ha->loop_down_abort_time =
4480 (LOOP_DOWN_TIME - ha->link_down_timeout);
4481 }
4482
4483 /* Need enough time to try and get the port back. */
4484 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4485 if (qlport_down_retry)
4486 ha->port_down_retry_count = qlport_down_retry;
4487
4488 /* Set login_retry_count */
4489 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4490 if (ha->port_down_retry_count ==
4491 le16_to_cpu(nv->port_down_retry_count) &&
4492 ha->port_down_retry_count > 3)
4493 ha->login_retry_count = ha->port_down_retry_count;
4494 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4495 ha->login_retry_count = ha->port_down_retry_count;
4496 if (ql2xloginretrycount)
4497 ha->login_retry_count = ql2xloginretrycount;
4498
4499 /* Enable ZIO. */
4500 if (!vha->flags.init_done) {
4501 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4502 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4503 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4504 le16_to_cpu(icb->interrupt_delay_timer): 2;
4505 }
4506 icb->firmware_options_2 &= __constant_cpu_to_le32(
4507 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4508 vha->flags.process_response_queue = 0;
4509 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4510 ha->zio_mode = QLA_ZIO_MODE_6;
4511
4512 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4513 "(%d us).\n", vha->host_no, ha->zio_mode,
4514 ha->zio_timer * 100));
4515 qla_printk(KERN_INFO, ha,
4516 "ZIO mode %d enabled; timer delay (%d us).\n",
4517 ha->zio_mode, ha->zio_timer * 100);
4518
4519 icb->firmware_options_2 |= cpu_to_le32(
4520 (uint32_t)ha->zio_mode);
4521 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4522 vha->flags.process_response_queue = 1;
4523 }
4524
4525 if (rval) {
4526 DEBUG2_3(printk(KERN_WARNING
4527 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4528 }
4529 return (rval);
4530}
4531
4532void
4533qla81xx_update_fw_options(scsi_qla_host_t *ha)
4534{
4535}