blob: 0f7ea6cc02f615b58356c34b815a1705f91a8834 [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
Andrew Vasquezac280b62009-08-20 11:06:05 -070043/* SRB Extensions ---------------------------------------------------------- */
44
45static void
46qla2x00_ctx_sp_timeout(unsigned long __data)
47{
48 srb_t *sp = (srb_t *)__data;
49 struct srb_ctx *ctx;
50 fc_port_t *fcport = sp->fcport;
51 struct qla_hw_data *ha = fcport->vha->hw;
52 struct req_que *req;
53 unsigned long flags;
54
55 spin_lock_irqsave(&ha->hardware_lock, flags);
56 req = ha->req_q_map[0];
57 req->outstanding_cmds[sp->handle] = NULL;
58 ctx = sp->ctx;
59 ctx->timeout(sp);
60 spin_unlock_irqrestore(&ha->hardware_lock, flags);
61
62 ctx->free(sp);
63}
64
65static void
66qla2x00_ctx_sp_free(srb_t *sp)
67{
68 struct srb_ctx *ctx = sp->ctx;
69
70 kfree(ctx);
71 mempool_free(sp, sp->fcport->vha->hw->srb_mempool);
72}
73
74inline srb_t *
75qla2x00_get_ctx_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size,
76 unsigned long tmo)
77{
78 srb_t *sp;
79 struct qla_hw_data *ha = vha->hw;
80 struct srb_ctx *ctx;
81
82 sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
83 if (!sp)
84 goto done;
85 ctx = kzalloc(size, GFP_KERNEL);
86 if (!ctx) {
87 mempool_free(sp, ha->srb_mempool);
88 goto done;
89 }
90
91 memset(sp, 0, sizeof(*sp));
92 sp->fcport = fcport;
93 sp->ctx = ctx;
94 ctx->free = qla2x00_ctx_sp_free;
95
96 init_timer(&ctx->timer);
97 if (!tmo)
98 goto done;
99 ctx->timer.expires = jiffies + tmo * HZ;
100 ctx->timer.data = (unsigned long)sp;
101 ctx->timer.function = qla2x00_ctx_sp_timeout;
102 add_timer(&ctx->timer);
103done:
104 return sp;
105}
106
107/* Asynchronous Login/Logout Routines -------------------------------------- */
108
109#define ELS_TMO_2_RATOV(ha) ((ha)->r_a_tov / 10 * 2)
110
111static void
112qla2x00_async_logio_timeout(srb_t *sp)
113{
114 fc_port_t *fcport = sp->fcport;
115 struct srb_logio *lio = sp->ctx;
116
117 DEBUG2(printk(KERN_WARNING
118 "scsi(%ld:%x): Async-%s timeout.\n",
119 fcport->vha->host_no, sp->handle,
120 lio->ctx.type == SRB_LOGIN_CMD ? "login": "logout"));
121
122 if (lio->ctx.type == SRB_LOGIN_CMD)
123 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
124}
125
126int
127qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
128 uint16_t *data)
129{
130 struct qla_hw_data *ha = vha->hw;
131 srb_t *sp;
132 struct srb_logio *lio;
133 int rval;
134
135 rval = QLA_FUNCTION_FAILED;
136 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_logio),
137 ELS_TMO_2_RATOV(ha) + 2);
138 if (!sp)
139 goto done;
140
141 lio = sp->ctx;
142 lio->ctx.type = SRB_LOGIN_CMD;
143 lio->ctx.timeout = qla2x00_async_logio_timeout;
144 lio->flags |= SRB_LOGIN_COND_PLOGI;
145 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
146 lio->flags |= SRB_LOGIN_RETRIED;
147 rval = qla2x00_start_sp(sp);
148 if (rval != QLA_SUCCESS)
149 goto done_free_sp;
150
151 DEBUG2(printk(KERN_DEBUG
152 "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x "
153 "retries=%d.\n", fcport->vha->host_no, sp->handle, fcport->loop_id,
154 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
155 fcport->login_retry));
156 return rval;
157
158done_free_sp:
159 del_timer_sync(&lio->ctx.timer);
160 lio->ctx.free(sp);
161done:
162 return rval;
163}
164
165int
166qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
167{
168 struct qla_hw_data *ha = vha->hw;
169 srb_t *sp;
170 struct srb_logio *lio;
171 int rval;
172
173 rval = QLA_FUNCTION_FAILED;
174 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_logio),
175 ELS_TMO_2_RATOV(ha) + 2);
176 if (!sp)
177 goto done;
178
179 lio = sp->ctx;
180 lio->ctx.type = SRB_LOGOUT_CMD;
181 lio->ctx.timeout = qla2x00_async_logio_timeout;
182 rval = qla2x00_start_sp(sp);
183 if (rval != QLA_SUCCESS)
184 goto done_free_sp;
185
186 DEBUG2(printk(KERN_DEBUG
187 "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n",
188 fcport->vha->host_no, sp->handle, fcport->loop_id,
189 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
190 return rval;
191
192done_free_sp:
193 del_timer_sync(&lio->ctx.timer);
194 lio->ctx.free(sp);
195done:
196 return rval;
197}
198
199int
200qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
201 uint16_t *data)
202{
203 int rval;
204 uint8_t opts = 0;
205
206 switch (data[0]) {
207 case MBS_COMMAND_COMPLETE:
208 if (fcport->flags & FCF_TAPE_PRESENT)
209 opts |= BIT_1;
210 rval = qla2x00_get_port_database(vha, fcport, opts);
211 if (rval != QLA_SUCCESS)
212 qla2x00_mark_device_lost(vha, fcport, 1, 0);
213 else
214 qla2x00_update_fcport(vha, fcport);
215 break;
216 case MBS_COMMAND_ERROR:
217 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
218 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
219 else
220 qla2x00_mark_device_lost(vha, fcport, 1, 0);
221 break;
222 case MBS_PORT_ID_USED:
223 fcport->loop_id = data[1];
224 qla2x00_post_async_login_work(vha, fcport, NULL);
225 break;
226 case MBS_LOOP_ID_USED:
227 fcport->loop_id++;
228 rval = qla2x00_find_new_loop_id(vha, fcport);
229 if (rval != QLA_SUCCESS) {
230 qla2x00_mark_device_lost(vha, fcport, 1, 0);
231 break;
232 }
233 qla2x00_post_async_login_work(vha, fcport, NULL);
234 break;
235 }
236 return QLA_SUCCESS;
237}
238
239int
240qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
241 uint16_t *data)
242{
243 qla2x00_mark_device_lost(vha, fcport, 1, 0);
244 return QLA_SUCCESS;
245}
246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247/****************************************************************************/
248/* QLogic ISP2x00 Hardware Support Functions. */
249/****************************************************************************/
250
251/*
252* qla2x00_initialize_adapter
253* Initialize board.
254*
255* Input:
256* ha = adapter block pointer.
257*
258* Returns:
259* 0 = success
260*/
261int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800262qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263{
264 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800265 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800266 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800269 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700270 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800271 vha->flags.reset_active = 0;
272 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
273 atomic_set(&vha->loop_state, LOOP_DOWN);
274 vha->device_flags = DFLG_NO_CABLE;
275 vha->dpc_flags = 0;
276 vha->flags.management_server_logged_in = 0;
277 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 ha->isp_abort_cnt = 0;
279 ha->beacon_blink_led = 0;
280
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800281 set_bit(0, ha->req_qid_map);
282 set_bit(0, ha->rsp_qid_map);
283
Andrew Vasquez01071092005-07-06 10:31:37 -0700284 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800285 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 if (rval) {
Andrew Vasquez7c98a042007-01-29 10:22:29 -0800287 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800288 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 return (rval);
290 }
291
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800292 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800294 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700295 if (rval) {
296 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800297 vha->host_no));
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700298 return (rval);
299 }
300
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800301 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -0800302
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
Andrew Vasquez01071092005-07-06 10:31:37 -0700304
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800305 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700307 if (ha->flags.disable_serdes) {
308 /* Mask HBA via NVRAM settings? */
309 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
310 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800311 vha->port_name[0], vha->port_name[1],
312 vha->port_name[2], vha->port_name[3],
313 vha->port_name[4], vha->port_name[5],
314 vha->port_name[6], vha->port_name[7]);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700315 return QLA_FUNCTION_FAILED;
316 }
317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
319
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800320 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
321 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800322 if (rval)
323 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800324 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800325 if (rval)
326 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700328 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800329 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700330 if (!ha->cs84xx) {
331 qla_printk(KERN_ERR, ha,
332 "Unable to configure ISP84XX.\n");
333 return QLA_FUNCTION_FAILED;
334 }
335 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800336 rval = qla2x00_init_rings(vha);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700337 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339 return (rval);
340}
341
342/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700343 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 * @ha: HA context
345 *
346 * Returns 0 on success.
347 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700348int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800349qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700351 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700352 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800353 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700354 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700357 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700360 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
362
Andrew Vasquez737faec2008-10-24 15:13:45 -0700363 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700365 /* Get PCI bus information. */
366 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700367 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700368 spin_unlock_irqrestore(&ha->hardware_lock, flags);
369
370 return QLA_SUCCESS;
371}
372
373/**
374 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
375 * @ha: HA context
376 *
377 * Returns 0 on success.
378 */
379int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800380qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700381{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700382 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700383 unsigned long flags = 0;
384 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800385 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700386 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700387
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700388 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700389 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700390
391 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700392 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700393
394 if (IS_QLA2322(ha) || IS_QLA6322(ha))
395 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700396 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700397
398 /*
399 * If this is a 2300 card and not 2312, reset the
400 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
401 * the 2310 also reports itself as a 2300 so we need to get the
402 * fb revision level -- a 6 indicates it really is a 2300 and
403 * not a 2310.
404 */
405 if (IS_QLA2300(ha)) {
406 spin_lock_irqsave(&ha->hardware_lock, flags);
407
408 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700409 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700410 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700411 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700412 break;
413
414 udelay(10);
415 }
416
417 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700418 WRT_REG_WORD(&reg->ctrl_status, 0x20);
419 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700420
421 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700422 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700423
424 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700425 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700426
427 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700428 WRT_REG_WORD(&reg->ctrl_status, 0x0);
429 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700430
431 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700432 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700433 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700434 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700435 break;
436
437 udelay(10);
438 }
439
440 spin_unlock_irqrestore(&ha->hardware_lock, flags);
441 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700442
443 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
444
Andrew Vasquez737faec2008-10-24 15:13:45 -0700445 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700446
447 /* Get PCI bus information. */
448 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700449 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700450 spin_unlock_irqrestore(&ha->hardware_lock, flags);
451
452 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453}
454
455/**
Andrew Vasquez01071092005-07-06 10:31:37 -0700456 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
457 * @ha: HA context
458 *
459 * Returns 0 on success.
460 */
461int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800462qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -0700463{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700464 uint16_t w;
Andrew Vasquez01071092005-07-06 10:31:37 -0700465 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800466 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -0700467 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez01071092005-07-06 10:31:37 -0700468
469 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700470 pci_try_set_mwi(ha->pdev);
Andrew Vasquez01071092005-07-06 10:31:37 -0700471
472 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700473 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez01071092005-07-06 10:31:37 -0700474 w &= ~PCI_COMMAND_INTX_DISABLE;
475 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
476
477 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
478
479 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700480 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
481 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez01071092005-07-06 10:31:37 -0700482
483 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700484 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
485 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez01071092005-07-06 10:31:37 -0700486
Andrew Vasquez737faec2008-10-24 15:13:45 -0700487 pci_disable_rom(ha->pdev);
Andrew Vasquez01071092005-07-06 10:31:37 -0700488
Auke Kok44c10132007-06-08 15:46:36 -0700489 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800490
Andrew Vasquez01071092005-07-06 10:31:37 -0700491 /* Get PCI bus information. */
492 spin_lock_irqsave(&ha->hardware_lock, flags);
493 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
494 spin_unlock_irqrestore(&ha->hardware_lock, flags);
495
496 return QLA_SUCCESS;
497}
498
499/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700500 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
501 * @ha: HA context
502 *
503 * Returns 0 on success.
504 */
505int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800506qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700507{
508 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800509 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700510
511 pci_set_master(ha->pdev);
512 pci_try_set_mwi(ha->pdev);
513
514 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
515 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
516 w &= ~PCI_COMMAND_INTX_DISABLE;
517 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
518
519 /* PCIe -- adjust Maximum Read Request Size (2048). */
520 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
521 pcie_set_readrq(ha->pdev, 2048);
522
Andrew Vasquez737faec2008-10-24 15:13:45 -0700523 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700524
525 ha->chip_revision = ha->pdev->revision;
526
527 return QLA_SUCCESS;
528}
529
530/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 * qla2x00_isp_firmware() - Choose firmware image.
532 * @ha: HA context
533 *
534 * Returns 0 on success.
535 */
536static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800537qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538{
539 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700540 uint16_t loop_id, topo, sw_cap;
541 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800542 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
544 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700545 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
547 if (ha->flags.disable_risc_code_load) {
548 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800549 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
551
552 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800553 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700554 if (rval == QLA_SUCCESS) {
555 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800556 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700557 &area, &domain, &topo, &sw_cap);
558 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 }
560
561 if (rval) {
562 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800563 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 }
565
566 return (rval);
567}
568
569/**
570 * qla2x00_reset_chip() - Reset ISP chip.
571 * @ha: HA context
572 *
573 * Returns 0 on success.
574 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700575void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800576qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577{
578 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800579 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700580 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 uint16_t cmd;
583
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700584 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
586 spin_lock_irqsave(&ha->hardware_lock, flags);
587
588 /* Turn off master enable */
589 cmd = 0;
590 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
591 cmd &= ~PCI_COMMAND_MASTER;
592 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
593
594 if (!IS_QLA2100(ha)) {
595 /* Pause RISC. */
596 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
597 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
598 for (cnt = 0; cnt < 30000; cnt++) {
599 if ((RD_REG_WORD(&reg->hccr) &
600 HCCR_RISC_PAUSE) != 0)
601 break;
602 udelay(100);
603 }
604 } else {
605 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
606 udelay(10);
607 }
608
609 /* Select FPM registers. */
610 WRT_REG_WORD(&reg->ctrl_status, 0x20);
611 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
612
613 /* FPM Soft Reset. */
614 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
615 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
616
617 /* Toggle Fpm Reset. */
618 if (!IS_QLA2200(ha)) {
619 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
620 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
621 }
622
623 /* Select frame buffer registers. */
624 WRT_REG_WORD(&reg->ctrl_status, 0x10);
625 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
626
627 /* Reset frame buffer FIFOs. */
628 if (IS_QLA2200(ha)) {
629 WRT_FB_CMD_REG(ha, reg, 0xa000);
630 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
631 } else {
632 WRT_FB_CMD_REG(ha, reg, 0x00fc);
633
634 /* Read back fb_cmd until zero or 3 seconds max */
635 for (cnt = 0; cnt < 3000; cnt++) {
636 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
637 break;
638 udelay(100);
639 }
640 }
641
642 /* Select RISC module registers. */
643 WRT_REG_WORD(&reg->ctrl_status, 0);
644 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
645
646 /* Reset RISC processor. */
647 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
648 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
649
650 /* Release RISC processor. */
651 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
652 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
653 }
654
655 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
656 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
657
658 /* Reset ISP chip. */
659 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
660
661 /* Wait for RISC to recover from reset. */
662 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
663 /*
664 * It is necessary to for a delay here since the card doesn't
665 * respond to PCI reads during a reset. On some architectures
666 * this will result in an MCA.
667 */
668 udelay(20);
669 for (cnt = 30000; cnt; cnt--) {
670 if ((RD_REG_WORD(&reg->ctrl_status) &
671 CSR_ISP_SOFT_RESET) == 0)
672 break;
673 udelay(100);
674 }
675 } else
676 udelay(10);
677
678 /* Reset RISC processor. */
679 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
680
681 WRT_REG_WORD(&reg->semaphore, 0);
682
683 /* Release RISC processor. */
684 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
685 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
686
687 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
688 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700689 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
692 udelay(100);
693 }
694 } else
695 udelay(100);
696
697 /* Turn on master enable */
698 cmd |= PCI_COMMAND_MASTER;
699 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
700
701 /* Disable RISC pause on FPM parity error. */
702 if (!IS_QLA2100(ha)) {
703 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
704 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
705 }
706
707 spin_unlock_irqrestore(&ha->hardware_lock, flags);
708}
709
710/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700711 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez01071092005-07-06 10:31:37 -0700712 * @ha: HA context
713 *
714 * Returns 0 on success.
715 */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700716static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800717qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -0700718{
719 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800720 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -0700721 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
722 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800723 uint16_t wd;
Andrew Vasquez01071092005-07-06 10:31:37 -0700724
Andrew Vasquez01071092005-07-06 10:31:37 -0700725 spin_lock_irqsave(&ha->hardware_lock, flags);
726
727 /* Reset RISC. */
728 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
729 for (cnt = 0; cnt < 30000; cnt++) {
730 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
731 break;
732
733 udelay(10);
734 }
735
736 WRT_REG_DWORD(&reg->ctrl_status,
737 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800738 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700739
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800740 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700741 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700742 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
743 for (cnt = 10000 ; cnt && d2; cnt--) {
744 udelay(5);
745 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
746 barrier();
747 }
748
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800749 /* Wait for soft-reset to complete. */
Andrew Vasquez01071092005-07-06 10:31:37 -0700750 d2 = RD_REG_DWORD(&reg->ctrl_status);
751 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
752 udelay(5);
753 d2 = RD_REG_DWORD(&reg->ctrl_status);
754 barrier();
755 }
756
757 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
758 RD_REG_DWORD(&reg->hccr);
759
760 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
761 RD_REG_DWORD(&reg->hccr);
762
763 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
764 RD_REG_DWORD(&reg->hccr);
765
766 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
767 for (cnt = 6000000 ; cnt && d2; cnt--) {
768 udelay(5);
769 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
770 barrier();
771 }
772
773 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800774
775 if (IS_NOPOLLING_TYPE(ha))
776 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez01071092005-07-06 10:31:37 -0700777}
778
779/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700780 * qla24xx_reset_chip() - Reset ISP24xx chip.
781 * @ha: HA context
782 *
783 * Returns 0 on success.
784 */
785void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800786qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -0700787{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800788 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700789 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700790
791 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800792 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700793}
794
795/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 * qla2x00_chip_diag() - Test chip for proper operation.
797 * @ha: HA context
798 *
799 * Returns 0 on success.
800 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700801int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800802qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803{
804 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800805 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700806 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 unsigned long flags = 0;
808 uint16_t data;
809 uint32_t cnt;
810 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800811 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
813 /* Assume a failed state */
814 rval = QLA_FUNCTION_FAILED;
815
816 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800817 vha->host_no, (u_long)&reg->flash_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
819 spin_lock_irqsave(&ha->hardware_lock, flags);
820
821 /* Reset ISP chip. */
822 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
823
824 /*
825 * We need to have a delay here since the card will not respond while
826 * in reset causing an MCA on some architectures.
827 */
828 udelay(20);
829 data = qla2x00_debounce_register(&reg->ctrl_status);
830 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
831 udelay(5);
832 data = RD_REG_WORD(&reg->ctrl_status);
833 barrier();
834 }
835
836 if (!cnt)
837 goto chip_diag_failed;
838
839 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
Andrew Vasquez76403352009-04-06 22:33:39 -0700840 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841
842 /* Reset RISC processor. */
843 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
844 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
845
846 /* Workaround for QLA2312 PCI parity error */
847 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
848 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
849 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
850 udelay(5);
851 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700852 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 }
854 } else
855 udelay(10);
856
857 if (!cnt)
858 goto chip_diag_failed;
859
860 /* Check product ID of chip */
Andrew Vasquez76403352009-04-06 22:33:39 -0700861 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
863 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
864 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
865 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
866 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
867 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
868 mb[3] != PROD_ID_3) {
869 qla_printk(KERN_WARNING, ha,
870 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
871
872 goto chip_diag_failed;
873 }
874 ha->product_id[0] = mb[1];
875 ha->product_id[1] = mb[2];
876 ha->product_id[2] = mb[3];
877 ha->product_id[3] = mb[4];
878
879 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800880 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
882 else
883 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800884 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
886 if (IS_QLA2200(ha) &&
887 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
888 /* Limit firmware transfer size with a 2200A */
889 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800890 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -0800892 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 ha->fw_transfer_size = 128;
894 }
895
896 /* Wrap Incoming Mailboxes Test. */
897 spin_unlock_irqrestore(&ha->hardware_lock, flags);
898
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800899 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
900 rval = qla2x00_mbx_reg_test(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 if (rval) {
902 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800903 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 qla_printk(KERN_WARNING, ha,
905 "Failed mailbox send register test\n");
906 }
907 else {
908 /* Flag a successful rval */
909 rval = QLA_SUCCESS;
910 }
911 spin_lock_irqsave(&ha->hardware_lock, flags);
912
913chip_diag_failed:
914 if (rval)
915 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800916 "****\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
918 spin_unlock_irqrestore(&ha->hardware_lock, flags);
919
920 return (rval);
921}
922
923/**
Andrew Vasquez01071092005-07-06 10:31:37 -0700924 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
925 * @ha: HA context
926 *
927 * Returns 0 on success.
928 */
929int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800930qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -0700931{
932 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800933 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800934 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez01071092005-07-06 10:31:37 -0700935
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800936 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez01071092005-07-06 10:31:37 -0700937
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800938 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez01071092005-07-06 10:31:37 -0700939 if (rval) {
940 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800941 vha->host_no));
Andrew Vasquez01071092005-07-06 10:31:37 -0700942 qla_printk(KERN_WARNING, ha,
943 "Failed mailbox send register test\n");
944 } else {
945 /* Flag a successful rval */
946 rval = QLA_SUCCESS;
947 }
948
949 return rval;
950}
951
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700952void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800953qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -0700954{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700955 int rval;
956 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800957 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800958 dma_addr_t tc_dma;
959 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800960 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800961 struct req_que *req = ha->req_q_map[0];
962 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700963
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700964 if (ha->fw_dump) {
965 qla_printk(KERN_WARNING, ha,
966 "Firmware dump previously allocated.\n");
967 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700968 }
969
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700970 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800971 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700972 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
973 fixed_size = sizeof(struct qla2100_fw_dump);
974 } else if (IS_QLA23XX(ha)) {
975 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
976 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
977 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -0700978 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800979 if (IS_QLA81XX(ha))
980 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
981 else if (IS_QLA25XX(ha))
982 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
983 else
984 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700985 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
986 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800987 if (ha->mqenable)
988 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700989 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800990 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700991 goto try_eft;
992
993 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
994 GFP_KERNEL);
995 if (!tc) {
996 qla_printk(KERN_WARNING, ha, "Unable to allocate "
997 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800998 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700999 }
1000
1001 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001002 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001003 ha->fce_mb, &ha->fce_bufs);
1004 if (rval) {
1005 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1006 "FCE (%d).\n", rval);
1007 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1008 tc_dma);
1009 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001010 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001011 }
1012
1013 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
1014 FCE_SIZE / 1024);
1015
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001016 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001017 ha->flags.fce_enabled = 1;
1018 ha->fce_dma = tc_dma;
1019 ha->fce = tc;
1020try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001021 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001022 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001023 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001024 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001025 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1026 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
1027 goto cont_alloc;
1028 }
1029
Andrew Vasquezfc447652008-01-17 09:02:18 -08001030 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001031 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001032 if (rval) {
1033 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1034 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001035 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1036 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001037 goto cont_alloc;
1038 }
1039
1040 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
1041 EFT_SIZE / 1024);
1042
1043 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001044 ha->eft_dma = tc_dma;
1045 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001046 }
1047cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001048 req_q_size = req->length * sizeof(request_t);
1049 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001050
1051 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001052 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001053 ha->chain_offset = dump_size;
1054 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001055
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001056 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001057 if (!ha->fw_dump) {
Andrew Vasquez01071092005-07-06 10:31:37 -07001058 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001059 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001060
1061 if (ha->eft) {
1062 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1063 ha->eft_dma);
1064 ha->eft = NULL;
1065 ha->eft_dma = 0;
1066 }
1067 return;
1068 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001069 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
1070 dump_size / 1024);
1071
1072 ha->fw_dump_len = dump_size;
1073 ha->fw_dump->signature[0] = 'Q';
1074 ha->fw_dump->signature[1] = 'L';
1075 ha->fw_dump->signature[2] = 'G';
1076 ha->fw_dump->signature[3] = 'C';
1077 ha->fw_dump->version = __constant_htonl(1);
1078
1079 ha->fw_dump->fixed_size = htonl(fixed_size);
1080 ha->fw_dump->mem_size = htonl(mem_size);
1081 ha->fw_dump->req_q_size = htonl(req_q_size);
1082 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1083
1084 ha->fw_dump->eft_size = htonl(eft_size);
1085 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1086 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1087
1088 ha->fw_dump->header_size =
1089 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez01071092005-07-06 10:31:37 -07001090}
1091
Andrew Vasquez18e75552009-06-03 09:55:30 -07001092static int
1093qla81xx_mpi_sync(scsi_qla_host_t *vha)
1094{
1095#define MPS_MASK 0xe0
1096 int rval;
1097 uint16_t dc;
1098 uint32_t dw;
1099 struct qla_hw_data *ha = vha->hw;
1100
1101 if (!IS_QLA81XX(vha->hw))
1102 return QLA_SUCCESS;
1103
1104 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1105 if (rval != QLA_SUCCESS) {
1106 DEBUG2(qla_printk(KERN_WARNING, ha,
1107 "Sync-MPI: Unable to acquire semaphore.\n"));
1108 goto done;
1109 }
1110
1111 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1112 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1113 if (rval != QLA_SUCCESS) {
1114 DEBUG2(qla_printk(KERN_WARNING, ha,
1115 "Sync-MPI: Unable to read sync.\n"));
1116 goto done_release;
1117 }
1118
1119 dc &= MPS_MASK;
1120 if (dc == (dw & MPS_MASK))
1121 goto done_release;
1122
1123 dw &= ~MPS_MASK;
1124 dw |= dc;
1125 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1126 if (rval != QLA_SUCCESS) {
1127 DEBUG2(qla_printk(KERN_WARNING, ha,
1128 "Sync-MPI: Unable to gain sync.\n"));
1129 }
1130
1131done_release:
1132 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1133 if (rval != QLA_SUCCESS) {
1134 DEBUG2(qla_printk(KERN_WARNING, ha,
1135 "Sync-MPI: Unable to release semaphore.\n"));
1136 }
1137
1138done:
1139 return rval;
1140}
1141
Andrew Vasquez01071092005-07-06 10:31:37 -07001142/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 * qla2x00_setup_chip() - Load and start RISC firmware.
1144 * @ha: HA context
1145 *
1146 * Returns 0 on success.
1147 */
1148static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001149qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150{
Andrew Vasquez01071092005-07-06 10:31:37 -07001151 int rval;
1152 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001153 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001154 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1155 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001156 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001157
1158 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1159 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1160 spin_lock_irqsave(&ha->hardware_lock, flags);
1161 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1162 RD_REG_WORD(&reg->hccr);
1163 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1164 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
Andrew Vasquez18e75552009-06-03 09:55:30 -07001166 qla81xx_mpi_sync(vha);
1167
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001169 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez01071092005-07-06 10:31:37 -07001170 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001172 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001174 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 if (rval == QLA_SUCCESS) {
1176 /* Start firmware execution. */
1177 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001178 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001180 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001182 if (rval == QLA_SUCCESS) {
1183 fw_major_version = ha->fw_major_version;
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001184 rval = qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 &ha->fw_major_version,
1186 &ha->fw_minor_version,
1187 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001188 &ha->fw_attributes, &ha->fw_memory_size,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001189 ha->mpi_version, &ha->mpi_capabilities,
1190 ha->phy_version);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001191 if (rval != QLA_SUCCESS)
1192 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001193 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001194 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001195 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001196 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001197 if ((!ha->max_npiv_vports) ||
1198 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001199 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001200 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001201 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001202 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001203 qla2x00_get_resource_cnts(vha, NULL,
1204 &ha->fw_xcb_count, NULL, NULL,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001205 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001206
1207 if (!fw_major_version && ql2xallocfwdump)
1208 qla2x00_alloc_fw_dump(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 }
1210 } else {
1211 DEBUG2(printk(KERN_INFO
1212 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001213 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 }
1215 }
1216
Andrew Vasquez3db06522008-01-31 12:33:49 -08001217 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1218 /* Enable proper parity. */
1219 spin_lock_irqsave(&ha->hardware_lock, flags);
1220 if (IS_QLA2300(ha))
1221 /* SRAM parity */
1222 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1223 else
1224 /* SRAM, Instruction RAM and GP RAM parity */
1225 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1226 RD_REG_WORD(&reg->hccr);
1227 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1228 }
1229
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001230 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1231 uint32_t size;
1232
1233 rval = qla81xx_fac_get_sector_size(vha, &size);
1234 if (rval == QLA_SUCCESS) {
1235 ha->flags.fac_supported = 1;
1236 ha->fdt_block_size = size << 2;
1237 } else {
1238 qla_printk(KERN_ERR, ha,
1239 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1240 ha->fw_major_version, ha->fw_minor_version,
1241 ha->fw_subminor_version);
1242 }
1243 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001244failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 if (rval) {
1246 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001247 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 }
1249
1250 return (rval);
1251}
1252
1253/**
1254 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1255 * @ha: HA context
1256 *
1257 * Beginning of request ring has initialization control block already built
1258 * by nvram config routine.
1259 *
1260 * Returns 0 on success.
1261 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001262void
1263qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264{
1265 uint16_t cnt;
1266 response_t *pkt;
1267
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001268 rsp->ring_ptr = rsp->ring;
1269 rsp->ring_index = 0;
1270 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001271 pkt = rsp->ring_ptr;
1272 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 pkt->signature = RESPONSE_PROCESSED;
1274 pkt++;
1275 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276}
1277
1278/**
1279 * qla2x00_update_fw_options() - Read and process firmware options.
1280 * @ha: HA context
1281 *
1282 * Returns 0 on success.
1283 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001284void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001285qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286{
1287 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001288 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289
1290 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001291 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
1293 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1294 return;
1295
1296 /* Serial Link options. */
1297 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001298 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1300 sizeof(ha->fw_seriallink_options)));
1301
1302 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1303 if (ha->fw_seriallink_options[3] & BIT_2) {
1304 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1305
1306 /* 1G settings */
1307 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1308 emphasis = (ha->fw_seriallink_options[2] &
1309 (BIT_4 | BIT_3)) >> 3;
1310 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001311 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 rx_sens = (ha->fw_seriallink_options[0] &
1313 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1314 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1315 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1316 if (rx_sens == 0x0)
1317 rx_sens = 0x3;
1318 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1319 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1320 ha->fw_options[10] |= BIT_5 |
1321 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1322 (tx_sens & (BIT_1 | BIT_0));
1323
1324 /* 2G settings */
1325 swing = (ha->fw_seriallink_options[2] &
1326 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1327 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1328 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001329 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 rx_sens = (ha->fw_seriallink_options[1] &
1331 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1332 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1333 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1334 if (rx_sens == 0x0)
1335 rx_sens = 0x3;
1336 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1337 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1338 ha->fw_options[11] |= BIT_5 |
1339 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1340 (tx_sens & (BIT_1 | BIT_0));
1341 }
1342
1343 /* FCP2 options. */
1344 /* Return command IOCBs without waiting for an ABTS to complete. */
1345 ha->fw_options[3] |= BIT_13;
1346
1347 /* LED scheme. */
1348 if (ha->flags.enable_led_scheme)
1349 ha->fw_options[2] |= BIT_12;
1350
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001351 /* Detect ISP6312. */
1352 if (IS_QLA6312(ha))
1353 ha->fw_options[2] |= BIT_13;
1354
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001356 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357}
1358
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001359void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001360qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07001361{
1362 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001363 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07001364
1365 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001366 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez01071092005-07-06 10:31:37 -07001367 return;
1368
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001369 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001370 le16_to_cpu(ha->fw_seriallink_options24[1]),
1371 le16_to_cpu(ha->fw_seriallink_options24[2]),
1372 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez01071092005-07-06 10:31:37 -07001373 if (rval != QLA_SUCCESS) {
1374 qla_printk(KERN_WARNING, ha,
1375 "Unable to update Serial Link options (%x).\n", rval);
1376 }
1377}
1378
1379void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001380qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001381{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001382 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001383 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001384 struct req_que *req = ha->req_q_map[0];
1385 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001386
1387 /* Setup ring parameters in initialization control block. */
1388 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1389 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001390 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1391 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1392 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1393 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1394 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1395 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001396
1397 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1398 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1399 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1400 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1401 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1402}
1403
Andrew Vasquez01071092005-07-06 10:31:37 -07001404void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001405qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07001406{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001407 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001408 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1409 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1410 struct qla_msix_entry *msix;
Andrew Vasquez01071092005-07-06 10:31:37 -07001411 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001412 uint16_t rid = 0;
1413 struct req_que *req = ha->req_q_map[0];
1414 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez01071092005-07-06 10:31:37 -07001415
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001416/* Setup ring parameters in initialization control block. */
Andrew Vasquez01071092005-07-06 10:31:37 -07001417 icb = (struct init_cb_24xx *)ha->init_cb;
1418 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1419 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001420 icb->request_q_length = cpu_to_le16(req->length);
1421 icb->response_q_length = cpu_to_le16(rsp->length);
1422 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1423 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1424 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1425 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez01071092005-07-06 10:31:37 -07001426
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001427 if (ha->mqenable) {
1428 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1429 icb->rid = __constant_cpu_to_le16(rid);
1430 if (ha->flags.msix_enabled) {
1431 msix = &ha->msix_entries[1];
1432 DEBUG2_17(printk(KERN_INFO
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001433 "Registering vector 0x%x for base que\n", msix->entry));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001434 icb->msix = cpu_to_le16(msix->entry);
1435 }
1436 /* Use alternate PCI bus number */
1437 if (MSB(rid))
1438 icb->firmware_options_2 |=
1439 __constant_cpu_to_le32(BIT_19);
1440 /* Use alternate PCI devfn */
1441 if (LSB(rid))
1442 icb->firmware_options_2 |=
1443 __constant_cpu_to_le32(BIT_18);
1444
Anirban Chakraborty31557542009-12-02 10:36:55 -08001445 /* Use Disable MSIX Handshake mode for capable adapters */
1446 if (IS_MSIX_NACK_CAPABLE(ha)) {
1447 icb->firmware_options_2 &=
1448 __constant_cpu_to_le32(~BIT_22);
1449 ha->flags.disable_msix_handshake = 1;
1450 qla_printk(KERN_INFO, ha,
1451 "MSIX Handshake Disable Mode turned on\n");
1452 } else {
1453 icb->firmware_options_2 |=
1454 __constant_cpu_to_le32(BIT_22);
1455 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001456 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001457
1458 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1459 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1460 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1461 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1462 } else {
1463 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1464 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1465 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1466 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1467 }
1468 /* PCI posting */
1469 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez01071092005-07-06 10:31:37 -07001470}
1471
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472/**
1473 * qla2x00_init_rings() - Initializes firmware.
1474 * @ha: HA context
1475 *
1476 * Beginning of request ring has initialization control block already built
1477 * by nvram config routine.
1478 *
1479 * Returns 0 on success.
1480 */
1481static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001482qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483{
1484 int rval;
1485 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001486 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001487 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001488 struct req_que *req;
1489 struct rsp_que *rsp;
1490 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001491 struct mid_init_cb_24xx *mid_init_cb =
1492 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493
1494 spin_lock_irqsave(&ha->hardware_lock, flags);
1495
1496 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001497 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001498 req = ha->req_q_map[que];
1499 if (!req)
1500 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001501 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001502 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001504 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001505
1506 /* Initialize firmware. */
1507 req->ring_ptr = req->ring;
1508 req->ring_index = 0;
1509 req->cnt = req->length;
1510 }
1511
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001512 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001513 rsp = ha->rsp_q_map[que];
1514 if (!rsp)
1515 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001516 /* Initialize response queue entries */
1517 qla2x00_init_response_q_entries(rsp);
1518 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
1520 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001521 list_for_each_entry(vp, &ha->vp_list, list) {
1522 vp->rscn_in_ptr = 0;
1523 vp->rscn_out_ptr = 0;
1524 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001525 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
1527 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1528
1529 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001530 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001532 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001533
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001534 if (ha->flags.npiv_supported) {
1535 if (ha->operating_mode == LOOP)
1536 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001537 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001538 }
1539
Andrew Vasquez24a08132009-03-24 09:08:16 -07001540 if (IS_FWI2_CAPABLE(ha)) {
1541 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1542 mid_init_cb->init_cb.execution_throttle =
1543 cpu_to_le16(ha->fw_xcb_count);
1544 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001545
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001546 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 if (rval) {
1548 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001549 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 } else {
1551 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001552 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 }
1554
1555 return (rval);
1556}
1557
1558/**
1559 * qla2x00_fw_ready() - Waits for firmware ready.
1560 * @ha: HA context
1561 *
1562 * Returns 0 on success.
1563 */
1564static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001565qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566{
1567 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001568 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 uint16_t min_wait; /* Minimum wait time if loop is down */
1570 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07001571 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001572 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573
1574 rval = QLA_SUCCESS;
1575
1576 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001577 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
1579 /*
1580 * Firmware should take at most one RATOV to login, plus 5 seconds for
1581 * our own processing.
1582 */
1583 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1584 wait_time = min_wait;
1585 }
1586
1587 /* Min wait time if loop down */
1588 mtime = jiffies + (min_wait * HZ);
1589
1590 /* wait time before firmware ready */
1591 wtime = jiffies + (wait_time * HZ);
1592
1593 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001594 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1596
1597 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001598 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599
1600 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001601 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001603 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001604 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001606 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1607 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001608 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001609 state[2]));
1610 if ((state[2] & FSTATE_LOGGED_IN) &&
1611 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1612 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001613 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001614
1615 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001616 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001617 if (rval != QLA_SUCCESS)
1618 break;
1619
1620 /* Add time taken to initialize. */
1621 cs84xx_time = jiffies - cs84xx_time;
1622 wtime += cs84xx_time;
1623 mtime += cs84xx_time;
1624 DEBUG16(printk("scsi(%ld): Increasing "
1625 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001626 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001627 }
1628 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001630 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001632 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 &ha->login_timeout, &ha->r_a_tov);
1634
1635 rval = QLA_SUCCESS;
1636 break;
1637 }
1638
1639 rval = QLA_FUNCTION_FAILED;
1640
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001641 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001642 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001644 * other than Wait for Login.
1645 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 if (time_after_eq(jiffies, mtime)) {
1647 qla_printk(KERN_INFO, ha,
1648 "Cable is unplugged...\n");
1649
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001650 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 break;
1652 }
1653 }
1654 } else {
1655 /* Mailbox cmd failed. Timeout on min_wait. */
1656 if (time_after_eq(jiffies, mtime))
1657 break;
1658 }
1659
1660 if (time_after_eq(jiffies, wtime))
1661 break;
1662
1663 /* Delay for a while */
1664 msleep(500);
1665
1666 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001667 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 } while (1);
1669
Andrew Vasquez656e8912009-06-03 09:55:29 -07001670 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1671 vha->host_no, state[0], state[1], state[2], state[3], state[4],
1672 jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673
1674 if (rval) {
1675 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001676 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 }
1678
1679 return (rval);
1680}
1681
1682/*
1683* qla2x00_configure_hba
1684* Setup adapter context.
1685*
1686* Input:
1687* ha = adapter state pointer.
1688*
1689* Returns:
1690* 0 = success
1691*
1692* Context:
1693* Kernel context.
1694*/
1695static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001696qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697{
1698 int rval;
1699 uint16_t loop_id;
1700 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001701 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 uint8_t al_pa;
1703 uint8_t area;
1704 uint8_t domain;
1705 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001706 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707
1708 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001709 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001710 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001712 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001713 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1714 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001715 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08001716 } else {
1717 qla_printk(KERN_WARNING, ha,
1718 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001719 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08001720 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 return (rval);
1722 }
1723
1724 if (topo == 4) {
1725 qla_printk(KERN_INFO, ha,
1726 "Cannot get topology - retrying.\n");
1727 return (QLA_FUNCTION_FAILED);
1728 }
1729
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001730 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
1732 /* initialize */
1733 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1734 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001735 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736
1737 switch (topo) {
1738 case 0:
1739 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001740 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 ha->current_topology = ISP_CFG_NL;
1742 strcpy(connect_type, "(Loop)");
1743 break;
1744
1745 case 1:
1746 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001747 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001748 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 ha->current_topology = ISP_CFG_FL;
1750 strcpy(connect_type, "(FL_Port)");
1751 break;
1752
1753 case 2:
1754 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001755 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 ha->operating_mode = P2P;
1757 ha->current_topology = ISP_CFG_N;
1758 strcpy(connect_type, "(N_Port-to-N_Port)");
1759 break;
1760
1761 case 3:
1762 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001763 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001764 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 ha->operating_mode = P2P;
1766 ha->current_topology = ISP_CFG_F;
1767 strcpy(connect_type, "(F_Port)");
1768 break;
1769
1770 default:
1771 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1772 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001773 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 ha->current_topology = ISP_CFG_NL;
1775 strcpy(connect_type, "(Loop)");
1776 break;
1777 }
1778
1779 /* Save Host port and loop ID. */
1780 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001781 vha->d_id.b.domain = domain;
1782 vha->d_id.b.area = area;
1783 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001785 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 qla_printk(KERN_INFO, ha,
1787 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001788 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789
1790 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001791 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001793 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 }
1795
1796 return(rval);
1797}
1798
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001799static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001800qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1801 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001802{
1803 char *st, *en;
1804 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001805 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07001806 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
1807 !IS_QLA81XX(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001808
1809 if (memcmp(model, BINZERO, len) != 0) {
1810 strncpy(ha->model_number, model, len);
1811 st = en = ha->model_number;
1812 en += len - 1;
1813 while (en > st) {
1814 if (*en != 0x20 && *en != 0x00)
1815 break;
1816 *en-- = '\0';
1817 }
1818
1819 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07001820 if (use_tbl &&
1821 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001822 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001823 strncpy(ha->model_desc,
1824 qla2x00_model_name[index * 2 + 1],
1825 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001826 } else {
1827 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07001828 if (use_tbl &&
1829 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001830 index < QLA_MODEL_NAMES) {
1831 strcpy(ha->model_number,
1832 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001833 strncpy(ha->model_desc,
1834 qla2x00_model_name[index * 2 + 1],
1835 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001836 } else {
1837 strcpy(ha->model_number, def);
1838 }
1839 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001840 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001841 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001842 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001843}
1844
David Miller4e08df32007-04-16 12:37:43 -07001845/* On sparc systems, obtain port and node WWN from firmware
1846 * properties.
1847 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001848static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07001849{
1850#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001851 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07001852 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07001853 struct device_node *dp = pci_device_to_OF_node(pdev);
1854 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07001855 int len;
1856
1857 val = of_get_property(dp, "port-wwn", &len);
1858 if (val && len >= WWN_SIZE)
1859 memcpy(nv->port_name, val, WWN_SIZE);
1860
1861 val = of_get_property(dp, "node-wwn", &len);
1862 if (val && len >= WWN_SIZE)
1863 memcpy(nv->node_name, val, WWN_SIZE);
1864#endif
1865}
1866
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867/*
1868* NVRAM configuration for ISP 2xxx
1869*
1870* Input:
1871* ha = adapter block pointer.
1872*
1873* Output:
1874* initialization control block in response_ring
1875* host adapters parameters in host adapter block
1876*
1877* Returns:
1878* 0 = success.
1879*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001880int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001881qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882{
David Miller4e08df32007-04-16 12:37:43 -07001883 int rval;
Andrew Vasquez01071092005-07-06 10:31:37 -07001884 uint8_t chksum = 0;
1885 uint16_t cnt;
1886 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001887 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07001888 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07001889 nvram_t *nv = ha->nvram;
1890 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001891 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892
David Miller4e08df32007-04-16 12:37:43 -07001893 rval = QLA_SUCCESS;
1894
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 /* Determine NVRAM starting address. */
Andrew Vasquez01071092005-07-06 10:31:37 -07001896 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 ha->nvram_base = 0;
1898 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1899 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
1900 ha->nvram_base = 0x80;
1901
1902 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001903 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez01071092005-07-06 10:31:37 -07001904 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1905 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001907 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07001908 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909
1910 /* Bad NVRAM data, set defaults parameters. */
1911 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1912 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1913 /* Reset NVRAM data. */
1914 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1915 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1916 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07001917 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1918 "invalid -- WWPN) defaults.\n");
1919
1920 /*
1921 * Set default initialization control block.
1922 */
1923 memset(nv, 0, ha->nvram_size);
1924 nv->parameter_block_version = ICB_VERSION;
1925
1926 if (IS_QLA23XX(ha)) {
1927 nv->firmware_options[0] = BIT_2 | BIT_1;
1928 nv->firmware_options[1] = BIT_7 | BIT_5;
1929 nv->add_firmware_options[0] = BIT_5;
1930 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1931 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1932 nv->special_options[1] = BIT_7;
1933 } else if (IS_QLA2200(ha)) {
1934 nv->firmware_options[0] = BIT_2 | BIT_1;
1935 nv->firmware_options[1] = BIT_7 | BIT_5;
1936 nv->add_firmware_options[0] = BIT_5;
1937 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1938 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1939 } else if (IS_QLA2100(ha)) {
1940 nv->firmware_options[0] = BIT_3 | BIT_1;
1941 nv->firmware_options[1] = BIT_5;
1942 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1943 }
1944
1945 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1946 nv->execution_throttle = __constant_cpu_to_le16(16);
1947 nv->retry_count = 8;
1948 nv->retry_delay = 1;
1949
1950 nv->port_name[0] = 33;
1951 nv->port_name[3] = 224;
1952 nv->port_name[4] = 139;
1953
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001954 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07001955
1956 nv->login_timeout = 4;
1957
1958 /*
1959 * Set default host adapter parameters
1960 */
1961 nv->host_p[1] = BIT_2;
1962 nv->reset_delay = 5;
1963 nv->port_down_retry_count = 8;
1964 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1965 nv->link_down_timeout = 60;
1966
1967 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 }
1969
1970#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1971 /*
1972 * The SN2 does not provide BIOS emulation which means you can't change
1973 * potentially bogus BIOS settings. Force the use of default settings
1974 * for link rate and frame size. Hope that the rest of the settings
1975 * are valid.
1976 */
1977 if (ia64_platform_is("sn2")) {
1978 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1979 if (IS_QLA23XX(ha))
1980 nv->special_options[1] = BIT_7;
1981 }
1982#endif
1983
1984 /* Reset Initialization control block */
Andrew Vasquez01071092005-07-06 10:31:37 -07001985 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986
1987 /*
1988 * Setup driver NVRAM options.
1989 */
1990 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1991 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1992 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1993 nv->firmware_options[1] &= ~BIT_4;
1994
1995 if (IS_QLA23XX(ha)) {
1996 nv->firmware_options[0] |= BIT_2;
1997 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez01071092005-07-06 10:31:37 -07001998 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999
2000 if (IS_QLA2300(ha)) {
2001 if (ha->fb_rev == FPM_2310) {
2002 strcpy(ha->model_number, "QLA2310");
2003 } else {
2004 strcpy(ha->model_number, "QLA2300");
2005 }
2006 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002007 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002008 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 }
2010 } else if (IS_QLA2200(ha)) {
2011 nv->firmware_options[0] |= BIT_2;
2012 /*
2013 * 'Point-to-point preferred, else loop' is not a safe
2014 * connection mode setting.
2015 */
2016 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2017 (BIT_5 | BIT_4)) {
2018 /* Force 'loop preferred, else point-to-point'. */
2019 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2020 nv->add_firmware_options[0] |= BIT_5;
2021 }
2022 strcpy(ha->model_number, "QLA22xx");
2023 } else /*if (IS_QLA2100(ha))*/ {
2024 strcpy(ha->model_number, "QLA2100");
2025 }
2026
2027 /*
2028 * Copy over NVRAM RISC parameter block to initialization control block.
2029 */
2030 dptr1 = (uint8_t *)icb;
2031 dptr2 = (uint8_t *)&nv->parameter_block_version;
2032 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2033 while (cnt--)
2034 *dptr1++ = *dptr2++;
2035
2036 /* Copy 2nd half. */
2037 dptr1 = (uint8_t *)icb->add_firmware_options;
2038 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2039 while (cnt--)
2040 *dptr1++ = *dptr2++;
2041
Andrew Vasquez5341e862006-05-17 15:09:16 -07002042 /* Use alternate WWN? */
2043 if (nv->host_p[1] & BIT_7) {
2044 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2045 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2046 }
2047
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 /* Prepare nodename */
2049 if ((icb->firmware_options[1] & BIT_6) == 0) {
2050 /*
2051 * Firmware will apply the following mask if the nodename was
2052 * not provided.
2053 */
2054 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2055 icb->node_name[0] &= 0xF0;
2056 }
2057
2058 /*
2059 * Set host adapter parameters.
2060 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002061 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07002062 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2064 /* Always load RISC code on non ISP2[12]00 chips. */
2065 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2066 ha->flags.disable_risc_code_load = 0;
2067 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2068 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2069 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002070 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002071 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072
2073 ha->operating_mode =
2074 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2075
2076 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2077 sizeof(ha->fw_seriallink_options));
2078
2079 /* save HBA serial number */
2080 ha->serial0 = icb->port_name[5];
2081 ha->serial1 = icb->port_name[6];
2082 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002083 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2084 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085
2086 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2087
2088 ha->retry_count = nv->retry_count;
2089
2090 /* Set minimum login_timeout to 4 seconds. */
2091 if (nv->login_timeout < ql2xlogintimeout)
2092 nv->login_timeout = ql2xlogintimeout;
2093 if (nv->login_timeout < 4)
2094 nv->login_timeout = 4;
2095 ha->login_timeout = nv->login_timeout;
2096 icb->login_timeout = nv->login_timeout;
2097
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002098 /* Set minimum RATOV to 100 tenths of a second. */
2099 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 ha->loop_reset_delay = nv->reset_delay;
2102
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 /* Link Down Timeout = 0:
2104 *
2105 * When Port Down timer expires we will start returning
2106 * I/O's to OS with "DID_NO_CONNECT".
2107 *
2108 * Link Down Timeout != 0:
2109 *
2110 * The driver waits for the link to come up after link down
2111 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002112 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 if (nv->link_down_timeout == 0) {
2114 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002115 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 } else {
2117 ha->link_down_timeout = nv->link_down_timeout;
2118 ha->loop_down_abort_time =
2119 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002120 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 /*
2123 * Need enough time to try and get the port back.
2124 */
2125 ha->port_down_retry_count = nv->port_down_retry_count;
2126 if (qlport_down_retry)
2127 ha->port_down_retry_count = qlport_down_retry;
2128 /* Set login_retry_count */
2129 ha->login_retry_count = nv->retry_count;
2130 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2131 ha->port_down_retry_count > 3)
2132 ha->login_retry_count = ha->port_down_retry_count;
2133 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2134 ha->login_retry_count = ha->port_down_retry_count;
2135 if (ql2xloginretrycount)
2136 ha->login_retry_count = ql2xloginretrycount;
2137
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 icb->lun_enables = __constant_cpu_to_le16(0);
2139 icb->command_resource_count = 0;
2140 icb->immediate_notify_resource_count = 0;
2141 icb->timeout = __constant_cpu_to_le16(0);
2142
2143 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2144 /* Enable RIO */
2145 icb->firmware_options[0] &= ~BIT_3;
2146 icb->add_firmware_options[0] &=
2147 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2148 icb->add_firmware_options[0] |= BIT_2;
2149 icb->response_accumulation_timer = 3;
2150 icb->interrupt_delay_timer = 5;
2151
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002152 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002154 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002155 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002156 ha->zio_mode = icb->add_firmware_options[0] &
2157 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2158 ha->zio_timer = icb->interrupt_delay_timer ?
2159 icb->interrupt_delay_timer: 2;
2160 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 icb->add_firmware_options[0] &=
2162 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002163 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002164 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002165 ha->zio_mode = QLA_ZIO_MODE_6;
2166
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002167 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002168 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002169 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002171 "ZIO mode %d enabled; timer delay (%d us).\n",
2172 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002174 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2175 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002176 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 }
2178 }
2179
David Miller4e08df32007-04-16 12:37:43 -07002180 if (rval) {
2181 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002182 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07002183 }
2184 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185}
2186
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002187static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002188qla2x00_rport_del(void *data)
2189{
2190 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002191 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002192
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002193 spin_lock_irq(fcport->vha->host->host_lock);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002194 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002195 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002196 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002197 if (rport)
2198 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002199}
2200
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201/**
2202 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2203 * @ha: HA context
2204 * @flags: allocation flags
2205 *
2206 * Returns a pointer to the allocated fcport, or NULL, if none available.
2207 */
Adrian Bunk413975a2006-06-30 02:33:06 -07002208static fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002209qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210{
2211 fc_port_t *fcport;
2212
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002213 fcport = kzalloc(sizeof(fc_port_t), flags);
2214 if (!fcport)
2215 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216
2217 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002218 fcport->vha = vha;
2219 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 fcport->port_type = FCT_UNKNOWN;
2221 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 atomic_set(&fcport->state, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002223 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002225 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226}
2227
2228/*
2229 * qla2x00_configure_loop
2230 * Updates Fibre Channel Device Database with what is actually on loop.
2231 *
2232 * Input:
2233 * ha = adapter block pointer.
2234 *
2235 * Returns:
2236 * 0 = success.
2237 * 1 = error.
2238 * 2 = database was full and device was not configured.
2239 */
2240static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002241qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242{
2243 int rval;
2244 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002245 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 rval = QLA_SUCCESS;
2247
2248 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002249 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2250 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 if (rval != QLA_SUCCESS) {
2252 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002253 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 return (rval);
2255 }
2256 }
2257
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002258 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002260 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261
2262 /*
2263 * If we have both an RSCN and PORT UPDATE pending then handle them
2264 * both at the same time.
2265 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002266 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2267 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268
Michael Hernandez3064ff32009-12-15 21:29:44 -08002269 qla2x00_get_data_rate(vha);
2270
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 /* Determine what we need to do */
2272 if (ha->current_topology == ISP_CFG_FL &&
2273 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2274
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002275 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 set_bit(RSCN_UPDATE, &flags);
2277
2278 } else if (ha->current_topology == ISP_CFG_F &&
2279 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2280
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002281 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 set_bit(RSCN_UPDATE, &flags);
2283 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2284
Andrew Vasquez21333b42006-05-17 15:09:56 -07002285 } else if (ha->current_topology == ISP_CFG_N) {
2286 clear_bit(RSCN_UPDATE, &flags);
2287
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002288 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2290
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002291 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 set_bit(RSCN_UPDATE, &flags);
2293 set_bit(LOCAL_LOOP_UPDATE, &flags);
2294 }
2295
2296 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002297 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002299 else
2300 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 }
2302
2303 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002304 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002306 else
2307 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 }
2309
2310 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002311 if (atomic_read(&vha->loop_down_timer) ||
2312 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 rval = QLA_FUNCTION_FAILED;
2314 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002315 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002317 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 }
2319 }
2320
2321 if (rval) {
2322 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002323 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 } else {
2325 DEBUG3(printk("%s: exiting normally\n", __func__));
2326 }
2327
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002328 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002329 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002331 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002332 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002333 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002334 vha->flags.rscn_queue_overflow = 1;
2335 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 }
2337
2338 return (rval);
2339}
2340
2341
2342
2343/*
2344 * qla2x00_configure_local_loop
2345 * Updates Fibre Channel Device Database with local loop devices.
2346 *
2347 * Input:
2348 * ha = adapter block pointer.
2349 *
2350 * Returns:
2351 * 0 = success.
2352 */
2353static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002354qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355{
2356 int rval, rval2;
2357 int found_devs;
2358 int found;
2359 fc_port_t *fcport, *new_fcport;
2360
2361 uint16_t index;
2362 uint16_t entries;
2363 char *id_iter;
2364 uint16_t loop_id;
2365 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002366 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367
2368 found_devs = 0;
2369 new_fcport = NULL;
2370 entries = MAX_FIBRE_DEVICES;
2371
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002372 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2373 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374
2375 /* Get list of logged in devices. */
2376 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002377 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 &entries);
2379 if (rval != QLA_SUCCESS)
2380 goto cleanup_allocation;
2381
2382 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07002383 vha->host_no, entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2385 entries * sizeof(struct gid_list_info)));
2386
2387 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002388 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 if (new_fcport == NULL) {
2390 rval = QLA_MEMORY_ALLOC_FAILED;
2391 goto cleanup_allocation;
2392 }
2393 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2394
2395 /*
2396 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2397 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002398 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2400 fcport->port_type != FCT_BROADCAST &&
2401 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2402
2403 DEBUG(printk("scsi(%ld): Marking port lost, "
2404 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002405 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406
2407 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 }
2409 }
2410
2411 /* Add devices to port list. */
2412 id_iter = (char *)ha->gid_list;
2413 for (index = 0; index < entries; index++) {
2414 domain = ((struct gid_list_info *)id_iter)->domain;
2415 area = ((struct gid_list_info *)id_iter)->area;
2416 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002417 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 loop_id = (uint16_t)
2419 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002420 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 loop_id = le16_to_cpu(
2422 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002423 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424
2425 /* Bypass reserved domain fields. */
2426 if ((domain & 0xf0) == 0xf0)
2427 continue;
2428
2429 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002430 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002431 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 continue;
2433
2434 /* Bypass invalid local loop ID. */
2435 if (loop_id > LAST_LOCAL_LOOP_ID)
2436 continue;
2437
2438 /* Fill in member data. */
2439 new_fcport->d_id.b.domain = domain;
2440 new_fcport->d_id.b.area = area;
2441 new_fcport->d_id.b.al_pa = al_pa;
2442 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002443 new_fcport->vp_idx = vha->vp_idx;
2444 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 if (rval2 != QLA_SUCCESS) {
2446 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2447 "information -- get_port_database=%x, "
2448 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002449 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002450 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002451 vha->host_no));
2452 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 continue;
2454 }
2455
2456 /* Check for matching device in port list. */
2457 found = 0;
2458 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002459 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 if (memcmp(new_fcport->port_name, fcport->port_name,
2461 WWN_SIZE))
2462 continue;
2463
Shyam Sundarddb9b122009-03-24 09:08:10 -07002464 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 fcport->loop_id = new_fcport->loop_id;
2466 fcport->port_type = new_fcport->port_type;
2467 fcport->d_id.b24 = new_fcport->d_id.b24;
2468 memcpy(fcport->node_name, new_fcport->node_name,
2469 WWN_SIZE);
2470
2471 found++;
2472 break;
2473 }
2474
2475 if (!found) {
2476 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002477 if (vha->vp_idx) {
2478 new_fcport->vha = vha;
2479 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002480 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002481 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482
2483 /* Allocate a new replacement fcport. */
2484 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002485 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 if (new_fcport == NULL) {
2487 rval = QLA_MEMORY_ALLOC_FAILED;
2488 goto cleanup_allocation;
2489 }
2490 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2491 }
2492
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002493 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002494 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002495
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002496 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497
2498 found_devs++;
2499 }
2500
2501cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002502 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503
2504 if (rval != QLA_SUCCESS) {
2505 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002506 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 }
2508
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 return (rval);
2510}
2511
2512static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002513qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002514{
2515#define LS_UNKNOWN 2
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002516 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2517 char *link_speed;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002518 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002519 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002520 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002521
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002522 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002523 return;
2524
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002525 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2526 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002527 return;
2528
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002529 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002530 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002531 if (rval != QLA_SUCCESS) {
2532 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2533 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002534 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002535 fcport->port_name[2], fcport->port_name[3],
2536 fcport->port_name[4], fcport->port_name[5],
2537 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002538 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002539 } else {
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002540 link_speed = link_speeds[LS_UNKNOWN];
2541 if (fcport->fp_speed < 5)
2542 link_speed = link_speeds[fcport->fp_speed];
2543 else if (fcport->fp_speed == 0x13)
2544 link_speed = link_speeds[5];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002545 DEBUG2(qla_printk(KERN_INFO, ha,
2546 "iIDMA adjusted to %s GB/s on "
2547 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002548 link_speed, fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002549 fcport->port_name[1], fcport->port_name[2],
2550 fcport->port_name[3], fcport->port_name[4],
2551 fcport->port_name[5], fcport->port_name[6],
2552 fcport->port_name[7]));
2553 }
2554}
2555
Adrian Bunk23be3312006-11-24 02:46:01 +01002556static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002557qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e112005-04-17 15:04:54 -05002558{
2559 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002560 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002561 struct qla_hw_data *ha = vha->hw;
8482e112005-04-17 15:04:54 -05002562
Andrew Vasquezac280b62009-08-20 11:06:05 -07002563 qla2x00_rport_del(fcport);
8482e112005-04-17 15:04:54 -05002564
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002565 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2566 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e112005-04-17 15:04:54 -05002567 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2568 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2569 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002570 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002571 if (!rport) {
2572 qla_printk(KERN_WARNING, ha,
2573 "Unable to allocate fc remote port!\n");
2574 return;
2575 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002576 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002577 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002578 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002579
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002580 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002581
2582 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e112005-04-17 15:04:54 -05002583 if (fcport->port_type == FCT_INITIATOR)
2584 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2585 if (fcport->port_type == FCT_TARGET)
2586 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002587 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e112005-04-17 15:04:54 -05002588}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589
2590/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002591 * qla2x00_update_fcport
2592 * Updates device on list.
2593 *
2594 * Input:
2595 * ha = adapter block pointer.
2596 * fcport = port structure pointer.
2597 *
2598 * Return:
2599 * 0 - Success
2600 * BIT_0 - error
2601 *
2602 * Context:
2603 * Kernel context.
2604 */
2605void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002606qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002607{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002608 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002609
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002610 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002611 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002612 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002613 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002614 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002615 PORT_RETRY_TIME);
2616 fcport->flags &= ~FCF_LOGIN_NEEDED;
2617
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002618 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002619
2620 atomic_set(&fcport->state, FCS_ONLINE);
2621
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002622 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002623}
2624
2625/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 * qla2x00_configure_fabric
2627 * Setup SNS devices with loop ID's.
2628 *
2629 * Input:
2630 * ha = adapter block pointer.
2631 *
2632 * Returns:
2633 * 0 = success.
2634 * BIT_0 = error
2635 */
2636static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002637qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638{
2639 int rval, rval2;
2640 fc_port_t *fcport, *fcptemp;
2641 uint16_t next_loopid;
2642 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez01071092005-07-06 10:31:37 -07002643 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002645 struct qla_hw_data *ha = vha->hw;
2646 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647
2648 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002649 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez01071092005-07-06 10:31:37 -07002650 loop_id = NPH_F_PORT;
2651 else
2652 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002653 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 if (rval != QLA_SUCCESS) {
2655 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002656 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002658 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 return (QLA_SUCCESS);
2660 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002661 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662
2663 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002664 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 if (rval2 == QLA_RSCNS_HANDLED) {
2666 /* No point doing the scan, just continue. */
2667 return (QLA_SUCCESS);
2668 }
2669 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002670 /* FDMI support. */
2671 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002672 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2673 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002674
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002676 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez01071092005-07-06 10:31:37 -07002677 loop_id = NPH_SNS;
2678 else
2679 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002680 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002681 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 if (mb[0] != MBS_COMMAND_COMPLETE) {
2683 DEBUG2(qla_printk(KERN_INFO, ha,
2684 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez01071092005-07-06 10:31:37 -07002685 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 mb[0], mb[1], mb[2], mb[6], mb[7]));
2687 return (QLA_SUCCESS);
2688 }
2689
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002690 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2691 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 /* EMPTY */
2693 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002694 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002696 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 /* EMPTY */
2698 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002699 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002701 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 /* EMPTY */
2703 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002704 "failed.\n", vha->host_no));
2705 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 /* EMPTY */
2707 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002708 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 }
2710 }
2711
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002712 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713 if (rval != QLA_SUCCESS)
2714 break;
2715
2716 /*
2717 * Logout all previous fabric devices marked lost, except
2718 * tape devices.
2719 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002720 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2721 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 break;
2723
2724 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2725 continue;
2726
2727 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002728 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002729 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 if (fcport->loop_id != FC_NO_LOOP_ID &&
2731 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2732 fcport->port_type != FCT_INITIATOR &&
2733 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002734 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002735 fcport->loop_id,
2736 fcport->d_id.b.domain,
2737 fcport->d_id.b.area,
2738 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 fcport->loop_id = FC_NO_LOOP_ID;
2740 }
2741 }
2742 }
2743
2744 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002745 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746
2747 /*
2748 * Scan through our port list and login entries that need to be
2749 * logged in.
2750 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002751 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2752 if (atomic_read(&vha->loop_down_timer) ||
2753 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 break;
2755
2756 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2757 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2758 continue;
2759
2760 if (fcport->loop_id == FC_NO_LOOP_ID) {
2761 fcport->loop_id = next_loopid;
Seokmann Jud4486fd2008-04-03 13:13:28 -07002762 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002763 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 if (rval != QLA_SUCCESS) {
2765 /* Ran out of IDs to use */
2766 break;
2767 }
2768 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002770 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 }
2772
2773 /* Exit if out of loop IDs. */
2774 if (rval != QLA_SUCCESS) {
2775 break;
2776 }
2777
2778 /*
2779 * Login and add the new devices to our port list.
2780 */
2781 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002782 if (atomic_read(&vha->loop_down_timer) ||
2783 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 break;
2785
2786 /* Find a new loop ID to use. */
2787 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002788 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 if (rval != QLA_SUCCESS) {
2790 /* Ran out of IDs to use */
2791 break;
2792 }
2793
bdf79622005-04-17 15:06:53 -05002794 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002795 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002796
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002797 if (vha->vp_idx) {
2798 fcport->vha = vha;
2799 fcport->vp_idx = vha->vp_idx;
2800 }
2801 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802 }
2803 } while (0);
2804
2805 /* Free all new device structures not processed. */
2806 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2807 list_del(&fcport->list);
2808 kfree(fcport);
2809 }
2810
2811 if (rval) {
2812 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002813 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814 }
2815
2816 return (rval);
2817}
2818
2819
2820/*
2821 * qla2x00_find_all_fabric_devs
2822 *
2823 * Input:
2824 * ha = adapter block pointer.
2825 * dev = database device entry pointer.
2826 *
2827 * Returns:
2828 * 0 = success.
2829 *
2830 * Context:
2831 * Kernel context.
2832 */
2833static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002834qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2835 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836{
2837 int rval;
2838 uint16_t loop_id;
2839 fc_port_t *fcport, *new_fcport, *fcptemp;
2840 int found;
2841
2842 sw_info_t *swl;
2843 int swl_idx;
2844 int first_dev, last_dev;
2845 port_id_t wrap, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002846 struct qla_hw_data *ha = vha->hw;
2847 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002848 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849
2850 rval = QLA_SUCCESS;
2851
2852 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07002853 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002854 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 /*EMPTY*/
2856 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002857 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002859 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 kfree(swl);
2861 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002862 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 kfree(swl);
2864 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002865 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 kfree(swl);
2867 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07002868 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002869 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2870 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 }
2872 }
2873 swl_idx = 0;
2874
2875 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002876 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002878 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 return (QLA_MEMORY_ALLOC_FAILED);
2880 }
2881 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 /* Set start port ID scan at adapter ID. */
2883 first_dev = 1;
2884 last_dev = 0;
2885
2886 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002887 loop_id = ha->min_external_loopid;
2888 for (; loop_id <= ha->max_loop_id; loop_id++) {
2889 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890 continue;
2891
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002892 if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 break;
2894
2895 if (swl != NULL) {
2896 if (last_dev) {
2897 wrap.b24 = new_fcport->d_id.b24;
2898 } else {
2899 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2900 memcpy(new_fcport->node_name,
2901 swl[swl_idx].node_name, WWN_SIZE);
2902 memcpy(new_fcport->port_name,
2903 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002904 memcpy(new_fcport->fabric_port_name,
2905 swl[swl_idx].fabric_port_name, WWN_SIZE);
2906 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907
2908 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2909 last_dev = 1;
2910 }
2911 swl_idx++;
2912 }
2913 } else {
2914 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002915 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 if (rval != QLA_SUCCESS) {
2917 qla_printk(KERN_WARNING, ha,
2918 "SNS scan failed -- assuming zero-entry "
2919 "result...\n");
2920 list_for_each_entry_safe(fcport, fcptemp,
2921 new_fcports, list) {
2922 list_del(&fcport->list);
2923 kfree(fcport);
2924 }
2925 rval = QLA_SUCCESS;
2926 break;
2927 }
2928 }
2929
2930 /* If wrap on switch device list, exit. */
2931 if (first_dev) {
2932 wrap.b24 = new_fcport->d_id.b24;
2933 first_dev = 0;
2934 } else if (new_fcport->d_id.b24 == wrap.b24) {
2935 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002936 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2938 break;
2939 }
2940
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002941 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002942 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 continue;
2944
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002945 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002946 found = 0;
2947 if (ha->num_vhosts) {
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002948 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002949 if (new_fcport->d_id.b24 == vp->d_id.b24) {
2950 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002951 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002952 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002953 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002954 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002955 continue;
2956 }
2957
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002958 /* Bypass if same domain and area of adapter. */
2959 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002960 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002961 ISP_CFG_FL)
2962 continue;
2963
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 /* Bypass reserved domain fields. */
2965 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2966 continue;
2967
2968 /* Locate matching device in database. */
2969 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002970 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971 if (memcmp(new_fcport->port_name, fcport->port_name,
2972 WWN_SIZE))
2973 continue;
2974
2975 found++;
2976
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002977 /* Update port state. */
2978 memcpy(fcport->fabric_port_name,
2979 new_fcport->fabric_port_name, WWN_SIZE);
2980 fcport->fp_speed = new_fcport->fp_speed;
2981
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 /*
2983 * If address the same and state FCS_ONLINE, nothing
2984 * changed.
2985 */
2986 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2987 atomic_read(&fcport->state) == FCS_ONLINE) {
2988 break;
2989 }
2990
2991 /*
2992 * If device was not a fabric device before.
2993 */
2994 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2995 fcport->d_id.b24 = new_fcport->d_id.b24;
2996 fcport->loop_id = FC_NO_LOOP_ID;
2997 fcport->flags |= (FCF_FABRIC_DEVICE |
2998 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 break;
3000 }
3001
3002 /*
3003 * Port ID changed or device was marked to be updated;
3004 * Log it out if still logged in and mark it for
3005 * relogin later.
3006 */
3007 fcport->d_id.b24 = new_fcport->d_id.b24;
3008 fcport->flags |= FCF_LOGIN_NEEDED;
3009 if (fcport->loop_id != FC_NO_LOOP_ID &&
3010 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
3011 fcport->port_type != FCT_INITIATOR &&
3012 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003013 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003014 fcport->d_id.b.domain, fcport->d_id.b.area,
3015 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016 fcport->loop_id = FC_NO_LOOP_ID;
3017 }
3018
3019 break;
3020 }
3021
3022 if (found)
3023 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 /* If device was not in our fcports list, then add it. */
3025 list_add_tail(&new_fcport->list, new_fcports);
3026
3027 /* Allocate a new replacement fcport. */
3028 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003029 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003031 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 return (QLA_MEMORY_ALLOC_FAILED);
3033 }
3034 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3035 new_fcport->d_id.b24 = nxt_d_id.b24;
3036 }
3037
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003038 kfree(swl);
3039 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 return (rval);
3042}
3043
3044/*
3045 * qla2x00_find_new_loop_id
3046 * Scan through our port list and find a new usable loop ID.
3047 *
3048 * Input:
3049 * ha: adapter state pointer.
3050 * dev: port structure pointer.
3051 *
3052 * Returns:
3053 * qla2x00 local function return status code.
3054 *
3055 * Context:
3056 * Kernel context.
3057 */
Adrian Bunk413975a2006-06-30 02:33:06 -07003058static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003059qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060{
3061 int rval;
3062 int found;
3063 fc_port_t *fcport;
3064 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003065 struct qla_hw_data *ha = vha->hw;
3066 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003067 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068
3069 rval = QLA_SUCCESS;
3070
3071 /* Save starting loop ID. */
3072 first_loop_id = dev->loop_id;
3073
3074 for (;;) {
3075 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003076 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078
3079 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003080 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082
3083 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003084 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085 /* first loop ID. */
3086 dev->loop_id = ha->min_external_loopid;
3087 }
3088
3089 /* Check for loop ID being already in use. */
3090 found = 0;
3091 fcport = NULL;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003092 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003093 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3094 if (fcport->loop_id == dev->loop_id &&
3095 fcport != dev) {
3096 /* ID possibly in use */
3097 found++;
3098 break;
3099 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003101 if (found)
3102 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103 }
3104
3105 /* If not in use then it is free to use. */
3106 if (!found) {
3107 break;
3108 }
3109
3110 /* ID in use. Try next value. */
3111 dev->loop_id++;
3112
3113 /* If wrap around. No free ID to use. */
3114 if (dev->loop_id == first_loop_id) {
3115 dev->loop_id = FC_NO_LOOP_ID;
3116 rval = QLA_FUNCTION_FAILED;
3117 break;
3118 }
3119 }
3120
3121 return (rval);
3122}
3123
3124/*
3125 * qla2x00_device_resync
3126 * Marks devices in the database that needs resynchronization.
3127 *
3128 * Input:
3129 * ha = adapter block pointer.
3130 *
3131 * Context:
3132 * Kernel context.
3133 */
3134static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003135qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136{
3137 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138 uint32_t mask;
3139 fc_port_t *fcport;
3140 uint32_t rscn_entry;
3141 uint8_t rscn_out_iter;
3142 uint8_t format;
3143 port_id_t d_id;
3144
3145 rval = QLA_RSCNS_HANDLED;
3146
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003147 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
3148 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003150 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151 format = MSB(MSW(rscn_entry));
3152 d_id.b.domain = LSB(MSW(rscn_entry));
3153 d_id.b.area = MSB(LSW(rscn_entry));
3154 d_id.b.al_pa = LSB(LSW(rscn_entry));
3155
3156 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3157 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003158 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159 d_id.b.area, d_id.b.al_pa));
3160
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003161 vha->rscn_out_ptr++;
3162 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
3163 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164
3165 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003166 for (rscn_out_iter = vha->rscn_out_ptr;
3167 !vha->flags.rscn_queue_overflow &&
3168 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 rscn_out_iter = (rscn_out_iter ==
3170 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
3171
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003172 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173 break;
3174
3175 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003176 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 rscn_out_iter));
3178
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003179 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180 }
3181
3182 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003183 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003185 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186
3187 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003188 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189 }
3190
3191 switch (format) {
3192 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 mask = 0xffffff;
3194 break;
3195 case 1:
3196 mask = 0xffff00;
3197 break;
3198 case 2:
3199 mask = 0xff0000;
3200 break;
3201 default:
3202 mask = 0x0;
3203 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003204 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205 break;
3206 }
3207
3208 rval = QLA_SUCCESS;
3209
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003210 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3212 (fcport->d_id.b24 & mask) != d_id.b24 ||
3213 fcport->port_type == FCT_BROADCAST)
3214 continue;
3215
3216 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3217 if (format != 3 ||
3218 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003219 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003220 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221 }
3222 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223 }
3224 }
3225 return (rval);
3226}
3227
3228/*
3229 * qla2x00_fabric_dev_login
3230 * Login fabric target device and update FC port database.
3231 *
3232 * Input:
3233 * ha: adapter state pointer.
3234 * fcport: port structure list pointer.
3235 * next_loopid: contains value of a new loop ID that can be used
3236 * by the next login attempt.
3237 *
3238 * Returns:
3239 * qla2x00 local function return status code.
3240 *
3241 * Context:
3242 * Kernel context.
3243 */
3244static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003245qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246 uint16_t *next_loopid)
3247{
3248 int rval;
3249 int retry;
Andrew Vasquez01071092005-07-06 10:31:37 -07003250 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003251 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252
3253 rval = QLA_SUCCESS;
3254 retry = 0;
3255
Andrew Vasquezac280b62009-08-20 11:06:05 -07003256 if (IS_ALOGIO_CAPABLE(ha)) {
3257 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3258 if (!rval)
3259 return rval;
3260 }
3261
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003262 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 if (rval == QLA_SUCCESS) {
Andrew Vasquez01071092005-07-06 10:31:37 -07003264 /* Send an ADISC to tape devices.*/
3265 opts = 0;
3266 if (fcport->flags & FCF_TAPE_PRESENT)
3267 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003268 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003270 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003271 fcport->d_id.b.domain, fcport->d_id.b.area,
3272 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003273 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003275 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 }
3277 }
3278
3279 return (rval);
3280}
3281
3282/*
3283 * qla2x00_fabric_login
3284 * Issue fabric login command.
3285 *
3286 * Input:
3287 * ha = adapter block pointer.
3288 * device = pointer to FC device type structure.
3289 *
3290 * Returns:
3291 * 0 - Login successfully
3292 * 1 - Login failed
3293 * 2 - Initiator device
3294 * 3 - Fatal error
3295 */
3296int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003297qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298 uint16_t *next_loopid)
3299{
3300 int rval;
3301 int retry;
3302 uint16_t tmp_loopid;
3303 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003304 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305
3306 retry = 0;
3307 tmp_loopid = 0;
3308
3309 for (;;) {
3310 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3311 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003312 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3314
3315 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003316 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317 fcport->d_id.b.domain, fcport->d_id.b.area,
3318 fcport->d_id.b.al_pa, mb, BIT_0);
3319 if (mb[0] == MBS_PORT_ID_USED) {
3320 /*
3321 * Device has another loop ID. The firmware team
Andrew Vasquez01071092005-07-06 10:31:37 -07003322 * recommends the driver perform an implicit login with
3323 * the specified ID again. The ID we just used is save
3324 * here so we return with an ID that can be tried by
3325 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326 */
3327 retry++;
3328 tmp_loopid = fcport->loop_id;
3329 fcport->loop_id = mb[1];
3330
3331 DEBUG(printk("Fabric Login: port in use - next "
3332 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3333 fcport->loop_id, fcport->d_id.b.domain,
3334 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3335
3336 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3337 /*
3338 * Login succeeded.
3339 */
3340 if (retry) {
3341 /* A retry occurred before. */
3342 *next_loopid = tmp_loopid;
3343 } else {
3344 /*
3345 * No retry occurred before. Just increment the
3346 * ID value for next login.
3347 */
3348 *next_loopid = (fcport->loop_id + 1);
3349 }
3350
3351 if (mb[1] & BIT_0) {
3352 fcport->port_type = FCT_INITIATOR;
3353 } else {
3354 fcport->port_type = FCT_TARGET;
3355 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003356 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357 }
3358 }
3359
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003360 if (mb[10] & BIT_0)
3361 fcport->supported_classes |= FC_COS_CLASS2;
3362 if (mb[10] & BIT_1)
3363 fcport->supported_classes |= FC_COS_CLASS3;
3364
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 rval = QLA_SUCCESS;
3366 break;
3367 } else if (mb[0] == MBS_LOOP_ID_USED) {
3368 /*
3369 * Loop ID already used, try next loop ID.
3370 */
3371 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003372 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373 if (rval != QLA_SUCCESS) {
3374 /* Ran out of loop IDs to use */
3375 break;
3376 }
3377 } else if (mb[0] == MBS_COMMAND_ERROR) {
3378 /*
3379 * Firmware possibly timed out during login. If NO
3380 * retries are left to do then the device is declared
3381 * dead.
3382 */
3383 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003384 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003385 fcport->d_id.b.domain, fcport->d_id.b.area,
3386 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003387 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388
3389 rval = 1;
3390 break;
3391 } else {
3392 /*
3393 * unrecoverable / not handled error
3394 */
3395 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003396 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003397 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 fcport->d_id.b.domain, fcport->d_id.b.area,
3399 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3400
3401 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003402 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003403 fcport->d_id.b.domain, fcport->d_id.b.area,
3404 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003406 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407
3408 rval = 3;
3409 break;
3410 }
3411 }
3412
3413 return (rval);
3414}
3415
3416/*
3417 * qla2x00_local_device_login
3418 * Issue local device login command.
3419 *
3420 * Input:
3421 * ha = adapter block pointer.
3422 * loop_id = loop id of device to login to.
3423 *
3424 * Returns (Where's the #define!!!!):
3425 * 0 - Login successfully
3426 * 1 - Login failed
3427 * 3 - Fatal error
3428 */
3429int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003430qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431{
3432 int rval;
3433 uint16_t mb[MAILBOX_REGISTER_COUNT];
3434
3435 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003436 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 if (rval == QLA_SUCCESS) {
3438 /* Interrogate mailbox registers for any errors */
3439 if (mb[0] == MBS_COMMAND_ERROR)
3440 rval = 1;
3441 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3442 /* device not in PCB table */
3443 rval = 3;
3444 }
3445
3446 return (rval);
3447}
3448
3449/*
3450 * qla2x00_loop_resync
3451 * Resync with fibre channel devices.
3452 *
3453 * Input:
3454 * ha = adapter block pointer.
3455 *
3456 * Returns:
3457 * 0 = success
3458 */
3459int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003460qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003461{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003462 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003464 struct req_que *req;
3465 struct rsp_que *rsp;
3466
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003467 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003468 req = vha->hw->req_q_map[0];
3469 else
3470 req = vha->req;
3471 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003473 atomic_set(&vha->loop_state, LOOP_UPDATE);
3474 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3475 if (vha->flags.online) {
3476 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3478 wait_time = 256;
3479 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003480 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481
Andrew Vasquez01071092005-07-06 10:31:37 -07003482 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003483 qla2x00_marker(vha, req, rsp, 0, 0,
3484 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003485 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486
3487 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003488 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003490 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003491 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003492 } while (!atomic_read(&vha->loop_down_timer) &&
3493 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3494 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3495 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497 }
3498
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003499 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003502 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504
3505 return (rval);
3506}
3507
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508void
Andrew Vasquez67becc02009-08-25 11:36:20 -07003509qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003510{
3511 fc_port_t *fcport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003512 struct scsi_qla_host *tvp, *vha;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003513
3514 /* Go with deferred removal of rport references. */
Andrew Vasquez67becc02009-08-25 11:36:20 -07003515 list_for_each_entry_safe(vha, tvp, &base_vha->hw->vp_list, list)
3516 list_for_each_entry(fcport, &vha->vp_fcports, list)
3517 if (fcport && fcport->drport &&
3518 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
3519 qla2x00_rport_del(fcport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003520}
3521
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522/*
3523* qla2x00_abort_isp
3524* Resets ISP and aborts all outstanding commands.
3525*
3526* Input:
3527* ha = adapter block pointer.
3528*
3529* Returns:
3530* 0 = success
3531*/
3532int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003533qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003535 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003537 struct qla_hw_data *ha = vha->hw;
3538 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003539 struct scsi_qla_host *tvp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003540 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003542 if (vha->flags.online) {
3543 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -07003544 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003545 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07003546 ha->qla_stats.total_isp_aborts++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547
3548 qla_printk(KERN_INFO, ha,
3549 "Performing ISP error recovery - ha= %p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003550 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003552 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3553 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3554 atomic_set(&vha->loop_state, LOOP_DOWN);
3555 qla2x00_mark_all_devices_lost(vha, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003557 if (!atomic_read(&vha->loop_down_timer))
3558 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559 LOOP_DOWN_TIME);
3560 }
3561
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562 /* Requeue all commands in outstanding command list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003563 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003564
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003565 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003566
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003567 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003569 if (!qla2x00_restart_isp(vha)) {
3570 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003572 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573 /*
3574 * Issue marker command only when we are going
3575 * to start the I/O .
3576 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003577 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578 }
3579
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003580 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003582 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003583
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003584 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003585 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003586
Lalit Chandivade29c53972009-10-13 15:16:47 -07003587 if (IS_QLA81XX(ha))
3588 qla2x00_get_fw_version(vha,
3589 &ha->fw_major_version,
3590 &ha->fw_minor_version,
3591 &ha->fw_subminor_version,
3592 &ha->fw_attributes, &ha->fw_memory_size,
3593 ha->mpi_version, &ha->mpi_capabilities,
3594 ha->phy_version);
3595
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003596 if (ha->fce) {
3597 ha->flags.fce_enabled = 1;
3598 memset(ha->fce, 0,
3599 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003600 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003601 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3602 &ha->fce_bufs);
3603 if (rval) {
3604 qla_printk(KERN_WARNING, ha,
3605 "Unable to reinitialize FCE "
3606 "(%d).\n", rval);
3607 ha->flags.fce_enabled = 0;
3608 }
3609 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003610
3611 if (ha->eft) {
3612 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003613 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003614 ha->eft_dma, EFT_NUM_BUFFERS);
3615 if (rval) {
3616 qla_printk(KERN_WARNING, ha,
3617 "Unable to reinitialize EFT "
3618 "(%d).\n", rval);
3619 }
3620 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003622 vha->flags.online = 1;
3623 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624 if (ha->isp_abort_cnt == 0) {
3625 qla_printk(KERN_WARNING, ha,
3626 "ISP error recovery failed - "
3627 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003628 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629 * The next call disables the board
3630 * completely.
3631 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003632 ha->isp_ops->reset_adapter(vha);
3633 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003635 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003636 status = 0;
3637 } else { /* schedule another ISP abort */
3638 ha->isp_abort_cnt--;
3639 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez01071092005-07-06 10:31:37 -07003640 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003641 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003642 status = 1;
3643 }
3644 } else {
3645 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3646 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3647 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003648 vha->host_no, ha->isp_abort_cnt));
3649 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650 status = 1;
3651 }
3652 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003653
Linus Torvalds1da177e2005-04-16 15:20:36 -07003654 }
3655
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003656 if (!status) {
3657 DEBUG(printk(KERN_INFO
3658 "qla2x00_abort_isp(%ld): succeeded.\n",
3659 vha->host_no));
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003660 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003661 if (vp->vp_idx)
3662 qla2x00_vp_abort_isp(vp);
3663 }
3664 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003665 qla_printk(KERN_INFO, ha,
3666 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003667 }
3668
3669 return(status);
3670}
3671
3672/*
3673* qla2x00_restart_isp
3674* restarts the ISP after a reset
3675*
3676* Input:
3677* ha = adapter block pointer.
3678*
3679* Returns:
3680* 0 = success
3681*/
3682static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003683qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003684{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003685 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003687 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003688 struct req_que *req = ha->req_q_map[0];
3689 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003690
3691 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003692 if (qla2x00_isp_firmware(vha)) {
3693 vha->flags.online = 0;
3694 status = ha->isp_ops->chip_diag(vha);
3695 if (!status)
3696 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003697 }
3698
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003699 if (!status && !(status = qla2x00_init_rings(vha))) {
3700 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07003701 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003702 /* Initialize the queues in use */
3703 qla25xx_init_queues(ha);
3704
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003705 status = qla2x00_fw_ready(vha);
3706 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003708 "status = %d\n", __func__, status));
Andrew Vasquez01071092005-07-06 10:31:37 -07003709
3710 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003711 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez01071092005-07-06 10:31:37 -07003712
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003713 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3715 wait_time = 256;
3716 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003717 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3718 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003720 } while (!atomic_read(&vha->loop_down_timer) &&
3721 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3722 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3723 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724 }
3725
3726 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003727 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003728 status = 0;
3729
3730 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3731 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003732 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733 }
3734 return (status);
3735}
3736
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003737static int
3738qla25xx_init_queues(struct qla_hw_data *ha)
3739{
3740 struct rsp_que *rsp = NULL;
3741 struct req_que *req = NULL;
3742 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3743 int ret = -1;
3744 int i;
3745
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003746 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003747 rsp = ha->rsp_q_map[i];
3748 if (rsp) {
3749 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003750 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003751 if (ret != QLA_SUCCESS)
3752 DEBUG2_17(printk(KERN_WARNING
3753 "%s Rsp que:%d init failed\n", __func__,
3754 rsp->id));
3755 else
3756 DEBUG2_17(printk(KERN_INFO
3757 "%s Rsp que:%d inited\n", __func__,
3758 rsp->id));
3759 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003760 }
3761 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003762 req = ha->req_q_map[i];
3763 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003764 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003765 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003766 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003767 if (ret != QLA_SUCCESS)
3768 DEBUG2_17(printk(KERN_WARNING
3769 "%s Req que:%d init failed\n", __func__,
3770 req->id));
3771 else
3772 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003773 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003774 req->id));
3775 }
3776 }
3777 return ret;
3778}
3779
Linus Torvalds1da177e2005-04-16 15:20:36 -07003780/*
3781* qla2x00_reset_adapter
3782* Reset adapter.
3783*
3784* Input:
3785* ha = adapter block pointer.
3786*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003787void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003788qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789{
3790 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003791 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003792 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003794 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003795 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003796
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797 spin_lock_irqsave(&ha->hardware_lock, flags);
3798 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3799 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3800 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3801 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3802 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3803}
Andrew Vasquez01071092005-07-06 10:31:37 -07003804
3805void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003806qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07003807{
3808 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003809 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07003810 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3811
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003812 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003813 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez01071092005-07-06 10:31:37 -07003814
3815 spin_lock_irqsave(&ha->hardware_lock, flags);
3816 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3817 RD_REG_DWORD(&reg->hccr);
3818 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3819 RD_REG_DWORD(&reg->hccr);
3820 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08003821
3822 if (IS_NOPOLLING_TYPE(ha))
3823 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez01071092005-07-06 10:31:37 -07003824}
3825
David Miller4e08df32007-04-16 12:37:43 -07003826/* On sparc systems, obtain port and node WWN from firmware
3827 * properties.
3828 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003829static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3830 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07003831{
3832#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003833 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003834 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003835 struct device_node *dp = pci_device_to_OF_node(pdev);
3836 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003837 int len;
3838
3839 val = of_get_property(dp, "port-wwn", &len);
3840 if (val && len >= WWN_SIZE)
3841 memcpy(nv->port_name, val, WWN_SIZE);
3842
3843 val = of_get_property(dp, "node-wwn", &len);
3844 if (val && len >= WWN_SIZE)
3845 memcpy(nv->node_name, val, WWN_SIZE);
3846#endif
3847}
3848
Andrew Vasquez01071092005-07-06 10:31:37 -07003849int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003850qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07003851{
David Miller4e08df32007-04-16 12:37:43 -07003852 int rval;
Andrew Vasquez01071092005-07-06 10:31:37 -07003853 struct init_cb_24xx *icb;
3854 struct nvram_24xx *nv;
3855 uint32_t *dptr;
3856 uint8_t *dptr1, *dptr2;
3857 uint32_t chksum;
3858 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003859 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07003860
David Miller4e08df32007-04-16 12:37:43 -07003861 rval = QLA_SUCCESS;
Andrew Vasquez01071092005-07-06 10:31:37 -07003862 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003863 nv = ha->nvram;
Andrew Vasquez01071092005-07-06 10:31:37 -07003864
3865 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07003866 if (ha->flags.port0) {
3867 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3868 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3869 } else {
Andrew Vasquez01071092005-07-06 10:31:37 -07003870 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003871 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3872 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07003873 ha->nvram_size = sizeof(struct nvram_24xx);
3874 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez01071092005-07-06 10:31:37 -07003875
Seokmann Ju281afe12007-07-26 13:43:34 -07003876 /* Get VPD data into cache */
3877 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003878 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07003879 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3880
3881 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez01071092005-07-06 10:31:37 -07003882 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003883 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez01071092005-07-06 10:31:37 -07003884 ha->nvram_size);
3885 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3886 chksum += le32_to_cpu(*dptr++);
3887
Andrew Vasquez76403352009-04-06 22:33:39 -07003888 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07003889 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez01071092005-07-06 10:31:37 -07003890
3891 /* Bad NVRAM data, set defaults parameters. */
3892 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3893 || nv->id[3] != ' ' ||
3894 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3895 /* Reset NVRAM data. */
3896 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3897 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3898 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07003899 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3900 "invalid -- WWPN) defaults.\n");
3901
3902 /*
3903 * Set default initialization control block.
3904 */
3905 memset(nv, 0, ha->nvram_size);
3906 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3907 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3908 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3909 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3910 nv->exchange_count = __constant_cpu_to_le16(0);
3911 nv->hard_address = __constant_cpu_to_le16(124);
3912 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07003913 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07003914 nv->port_name[2] = 0x00;
3915 nv->port_name[3] = 0xe0;
3916 nv->port_name[4] = 0x8b;
3917 nv->port_name[5] = 0x1c;
3918 nv->port_name[6] = 0x55;
3919 nv->port_name[7] = 0x86;
3920 nv->node_name[0] = 0x20;
3921 nv->node_name[1] = 0x00;
3922 nv->node_name[2] = 0x00;
3923 nv->node_name[3] = 0xe0;
3924 nv->node_name[4] = 0x8b;
3925 nv->node_name[5] = 0x1c;
3926 nv->node_name[6] = 0x55;
3927 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003928 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07003929 nv->login_retry_count = __constant_cpu_to_le16(8);
3930 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3931 nv->login_timeout = __constant_cpu_to_le16(0);
3932 nv->firmware_options_1 =
3933 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3934 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3935 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3936 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3937 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3938 nv->efi_parameters = __constant_cpu_to_le32(0);
3939 nv->reset_delay = 5;
3940 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3941 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3942 nv->link_down_timeout = __constant_cpu_to_le16(30);
3943
3944 rval = 1;
Andrew Vasquez01071092005-07-06 10:31:37 -07003945 }
3946
3947 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003948 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez01071092005-07-06 10:31:37 -07003949
3950 /* Copy 1st segment. */
3951 dptr1 = (uint8_t *)icb;
3952 dptr2 = (uint8_t *)&nv->version;
3953 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3954 while (cnt--)
3955 *dptr1++ = *dptr2++;
3956
3957 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07003958 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez01071092005-07-06 10:31:37 -07003959
3960 /* Copy 2nd segment. */
3961 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3962 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3963 cnt = (uint8_t *)&icb->reserved_3 -
3964 (uint8_t *)&icb->interrupt_delay_timer;
3965 while (cnt--)
3966 *dptr1++ = *dptr2++;
3967
3968 /*
3969 * Setup driver NVRAM options.
3970 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003971 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003972 "QLA2462");
Andrew Vasquez01071092005-07-06 10:31:37 -07003973
Andrew Vasquez5341e862006-05-17 15:09:16 -07003974 /* Use alternate WWN? */
3975 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3976 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3977 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3978 }
3979
Andrew Vasquez01071092005-07-06 10:31:37 -07003980 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003981 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez01071092005-07-06 10:31:37 -07003982 /*
3983 * Firmware will apply the following mask if the nodename was
3984 * not provided.
3985 */
3986 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3987 icb->node_name[0] &= 0xF0;
3988 }
3989
3990 /* Set host adapter parameters. */
3991 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08003992 ha->flags.enable_lip_reset = 0;
3993 ha->flags.enable_lip_full_login =
3994 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3995 ha->flags.enable_target_reset =
3996 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez01071092005-07-06 10:31:37 -07003997 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07003998 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez01071092005-07-06 10:31:37 -07003999
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004000 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4001 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez01071092005-07-06 10:31:37 -07004002
4003 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4004 sizeof(ha->fw_seriallink_options24));
4005
4006 /* save HBA serial number */
4007 ha->serial0 = icb->port_name[5];
4008 ha->serial1 = icb->port_name[6];
4009 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004010 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4011 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez01071092005-07-06 10:31:37 -07004012
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08004013 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4014
Andrew Vasquez01071092005-07-06 10:31:37 -07004015 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4016
4017 /* Set minimum login_timeout to 4 seconds. */
4018 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4019 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4020 if (le16_to_cpu(nv->login_timeout) < 4)
4021 nv->login_timeout = __constant_cpu_to_le16(4);
4022 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07004023 icb->login_timeout = nv->login_timeout;
Andrew Vasquez01071092005-07-06 10:31:37 -07004024
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004025 /* Set minimum RATOV to 100 tenths of a second. */
4026 ha->r_a_tov = 100;
Andrew Vasquez01071092005-07-06 10:31:37 -07004027
4028 ha->loop_reset_delay = nv->reset_delay;
4029
4030 /* Link Down Timeout = 0:
4031 *
4032 * When Port Down timer expires we will start returning
4033 * I/O's to OS with "DID_NO_CONNECT".
4034 *
4035 * Link Down Timeout != 0:
4036 *
4037 * The driver waits for the link to come up after link down
4038 * before returning I/Os to OS with "DID_NO_CONNECT".
4039 */
4040 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4041 ha->loop_down_abort_time =
4042 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4043 } else {
4044 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4045 ha->loop_down_abort_time =
4046 (LOOP_DOWN_TIME - ha->link_down_timeout);
4047 }
4048
4049 /* Need enough time to try and get the port back. */
4050 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4051 if (qlport_down_retry)
4052 ha->port_down_retry_count = qlport_down_retry;
4053
4054 /* Set login_retry_count */
4055 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4056 if (ha->port_down_retry_count ==
4057 le16_to_cpu(nv->port_down_retry_count) &&
4058 ha->port_down_retry_count > 3)
4059 ha->login_retry_count = ha->port_down_retry_count;
4060 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4061 ha->login_retry_count = ha->port_down_retry_count;
4062 if (ql2xloginretrycount)
4063 ha->login_retry_count = ql2xloginretrycount;
4064
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004065 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004066 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004067 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4068 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4069 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4070 le16_to_cpu(icb->interrupt_delay_timer): 2;
4071 }
4072 icb->firmware_options_2 &= __constant_cpu_to_le32(
4073 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004074 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004075 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004076 ha->zio_mode = QLA_ZIO_MODE_6;
4077
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004078 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004079 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004080 ha->zio_timer * 100));
4081 qla_printk(KERN_INFO, ha,
4082 "ZIO mode %d enabled; timer delay (%d us).\n",
4083 ha->zio_mode, ha->zio_timer * 100);
4084
4085 icb->firmware_options_2 |= cpu_to_le32(
4086 (uint32_t)ha->zio_mode);
4087 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004088 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004089 }
4090
David Miller4e08df32007-04-16 12:37:43 -07004091 if (rval) {
4092 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004093 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07004094 }
4095 return (rval);
Andrew Vasquez01071092005-07-06 10:31:37 -07004096}
4097
Adrian Bunk413975a2006-06-30 02:33:06 -07004098static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004099qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4100 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004101{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004102 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004103 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004104 uint32_t *dcode, dlen;
4105 uint32_t risc_addr;
4106 uint32_t risc_size;
4107 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004108 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004109 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004110
4111 qla_printk(KERN_INFO, ha,
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004112 "FW: Loading from flash (%x)...\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004113
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004114 rval = QLA_SUCCESS;
4115
4116 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004117 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004118 *srisc_addr = 0;
4119
4120 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004121 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004122 for (i = 0; i < 4; i++)
4123 dcode[i] = be32_to_cpu(dcode[i]);
4124 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4125 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4126 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4127 dcode[3] == 0)) {
4128 qla_printk(KERN_WARNING, ha,
4129 "Unable to verify integrity of flash firmware image!\n");
4130 qla_printk(KERN_WARNING, ha,
4131 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4132 dcode[1], dcode[2], dcode[3]);
4133
4134 return QLA_FUNCTION_FAILED;
4135 }
4136
4137 while (segments && rval == QLA_SUCCESS) {
4138 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004139 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004140
4141 risc_addr = be32_to_cpu(dcode[2]);
4142 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4143 risc_size = be32_to_cpu(dcode[3]);
4144
4145 fragment = 0;
4146 while (risc_size > 0 && rval == QLA_SUCCESS) {
4147 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4148 if (dlen > risc_size)
4149 dlen = risc_size;
4150
4151 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4152 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004153 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004154
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004155 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004156 for (i = 0; i < dlen; i++)
4157 dcode[i] = swab32(dcode[i]);
4158
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004159 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004160 dlen);
4161 if (rval) {
4162 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004163 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004164 fragment));
4165 qla_printk(KERN_WARNING, ha,
4166 "[ERROR] Failed to load segment %d of "
4167 "firmware\n", fragment);
4168 break;
4169 }
4170
4171 faddr += dlen;
4172 risc_addr += dlen;
4173 risc_size -= dlen;
4174 fragment++;
4175 }
4176
4177 /* Next segment. */
4178 segments--;
4179 }
4180
4181 return rval;
4182}
4183
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004184#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4185
Andrew Vasquez01071092005-07-06 10:31:37 -07004186int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004187qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08004188{
4189 int rval;
4190 int i, fragment;
4191 uint16_t *wcode, *fwcode;
4192 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4193 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004194 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004195 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08004196
4197 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004198 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004199 if (!blob) {
4200 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004201 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4202 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08004203 return QLA_FUNCTION_FAILED;
4204 }
4205
4206 rval = QLA_SUCCESS;
4207
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004208 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08004209 *srisc_addr = 0;
4210 fwcode = (uint16_t *)blob->fw->data;
4211 fwclen = 0;
4212
4213 /* Validate firmware image by checking version. */
4214 if (blob->fw->size < 8 * sizeof(uint16_t)) {
4215 qla_printk(KERN_WARNING, ha,
4216 "Unable to verify integrity of firmware image (%Zd)!\n",
4217 blob->fw->size);
4218 goto fail_fw_integrity;
4219 }
4220 for (i = 0; i < 4; i++)
4221 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4222 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4223 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4224 wcode[2] == 0 && wcode[3] == 0)) {
4225 qla_printk(KERN_WARNING, ha,
4226 "Unable to verify integrity of firmware image!\n");
4227 qla_printk(KERN_WARNING, ha,
4228 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
4229 wcode[1], wcode[2], wcode[3]);
4230 goto fail_fw_integrity;
4231 }
4232
4233 seg = blob->segs;
4234 while (*seg && rval == QLA_SUCCESS) {
4235 risc_addr = *seg;
4236 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4237 risc_size = be16_to_cpu(fwcode[3]);
4238
4239 /* Validate firmware image size. */
4240 fwclen += risc_size * sizeof(uint16_t);
4241 if (blob->fw->size < fwclen) {
4242 qla_printk(KERN_WARNING, ha,
4243 "Unable to verify integrity of firmware image "
4244 "(%Zd)!\n", blob->fw->size);
4245 goto fail_fw_integrity;
4246 }
4247
4248 fragment = 0;
4249 while (risc_size > 0 && rval == QLA_SUCCESS) {
4250 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4251 if (wlen > risc_size)
4252 wlen = risc_size;
4253
4254 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004255 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004256 risc_addr, wlen));
4257
4258 for (i = 0; i < wlen; i++)
4259 wcode[i] = swab16(fwcode[i]);
4260
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004261 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004262 wlen);
4263 if (rval) {
4264 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004265 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004266 fragment));
4267 qla_printk(KERN_WARNING, ha,
4268 "[ERROR] Failed to load segment %d of "
4269 "firmware\n", fragment);
4270 break;
4271 }
4272
4273 fwcode += wlen;
4274 risc_addr += wlen;
4275 risc_size -= wlen;
4276 fragment++;
4277 }
4278
4279 /* Next segment. */
4280 seg++;
4281 }
4282 return rval;
4283
4284fail_fw_integrity:
4285 return QLA_FUNCTION_FAILED;
4286}
4287
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004288static int
4289qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez01071092005-07-06 10:31:37 -07004290{
4291 int rval;
4292 int segments, fragment;
4293 uint32_t *dcode, dlen;
4294 uint32_t risc_addr;
4295 uint32_t risc_size;
4296 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004297 struct fw_blob *blob;
Andrew Vasquez01071092005-07-06 10:31:37 -07004298 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004299 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004300 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez01071092005-07-06 10:31:37 -07004301
Andrew Vasquez54333832005-11-09 15:49:04 -08004302 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004303 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004304 if (!blob) {
4305 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004306 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4307 "from: " QLA_FW_URL ".\n");
4308
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004309 return QLA_FUNCTION_FAILED;
Andrew Vasquez01071092005-07-06 10:31:37 -07004310 }
4311
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004312 qla_printk(KERN_INFO, ha,
4313 "FW: Loading via request-firmware...\n");
4314
Andrew Vasquez01071092005-07-06 10:31:37 -07004315 rval = QLA_SUCCESS;
4316
4317 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004318 dcode = (uint32_t *)req->ring;
Andrew Vasquez01071092005-07-06 10:31:37 -07004319 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004320 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez01071092005-07-06 10:31:37 -07004321 fwclen = 0;
4322
4323 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004324 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez01071092005-07-06 10:31:37 -07004325 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004326 "Unable to verify integrity of firmware image (%Zd)!\n",
4327 blob->fw->size);
Andrew Vasquez01071092005-07-06 10:31:37 -07004328 goto fail_fw_integrity;
4329 }
4330 for (i = 0; i < 4; i++)
4331 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4332 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4333 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4334 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4335 dcode[3] == 0)) {
4336 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004337 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez01071092005-07-06 10:31:37 -07004338 qla_printk(KERN_WARNING, ha,
4339 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4340 dcode[1], dcode[2], dcode[3]);
4341 goto fail_fw_integrity;
4342 }
4343
4344 while (segments && rval == QLA_SUCCESS) {
4345 risc_addr = be32_to_cpu(fwcode[2]);
4346 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4347 risc_size = be32_to_cpu(fwcode[3]);
4348
4349 /* Validate firmware image size. */
4350 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004351 if (blob->fw->size < fwclen) {
Andrew Vasquez01071092005-07-06 10:31:37 -07004352 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004353 "Unable to verify integrity of firmware image "
4354 "(%Zd)!\n", blob->fw->size);
4355
Andrew Vasquez01071092005-07-06 10:31:37 -07004356 goto fail_fw_integrity;
4357 }
4358
4359 fragment = 0;
4360 while (risc_size > 0 && rval == QLA_SUCCESS) {
4361 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4362 if (dlen > risc_size)
4363 dlen = risc_size;
4364
4365 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004366 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez01071092005-07-06 10:31:37 -07004367 risc_addr, dlen));
4368
4369 for (i = 0; i < dlen; i++)
4370 dcode[i] = swab32(fwcode[i]);
4371
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004372 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004373 dlen);
Andrew Vasquez01071092005-07-06 10:31:37 -07004374 if (rval) {
4375 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004376 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez01071092005-07-06 10:31:37 -07004377 fragment));
4378 qla_printk(KERN_WARNING, ha,
4379 "[ERROR] Failed to load segment %d of "
4380 "firmware\n", fragment);
4381 break;
4382 }
4383
4384 fwcode += dlen;
4385 risc_addr += dlen;
4386 risc_size -= dlen;
4387 fragment++;
4388 }
4389
4390 /* Next segment. */
4391 segments--;
4392 }
Andrew Vasquez01071092005-07-06 10:31:37 -07004393 return rval;
4394
4395fail_fw_integrity:
Andrew Vasquez01071092005-07-06 10:31:37 -07004396 return QLA_FUNCTION_FAILED;
Andrew Vasquez01071092005-07-06 10:31:37 -07004397}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004398
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004399int
4400qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4401{
4402 int rval;
4403
Andrew Vasqueze337d902009-04-06 22:33:49 -07004404 if (ql2xfwloadbin == 1)
4405 return qla81xx_load_risc(vha, srisc_addr);
4406
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004407 /*
4408 * FW Load priority:
4409 * 1) Firmware via request-firmware interface (.bin file).
4410 * 2) Firmware residing in flash.
4411 */
4412 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4413 if (rval == QLA_SUCCESS)
4414 return rval;
4415
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004416 return qla24xx_load_risc_flash(vha, srisc_addr,
4417 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004418}
4419
4420int
4421qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4422{
4423 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004424 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004425
Andrew Vasqueze337d902009-04-06 22:33:49 -07004426 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004427 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07004428
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004429 /*
4430 * FW Load priority:
4431 * 1) Firmware residing in flash.
4432 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004433 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004434 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004435 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004436 if (rval == QLA_SUCCESS)
4437 return rval;
4438
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004439try_blob_fw:
4440 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4441 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4442 return rval;
4443
4444 qla_printk(KERN_ERR, ha,
4445 "FW: Attempting to fallback to golden firmware...\n");
4446 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4447 if (rval != QLA_SUCCESS)
4448 return rval;
4449
4450 qla_printk(KERN_ERR, ha,
4451 "FW: Please update operational firmware...\n");
4452 ha->flags.running_gold_fw = 1;
4453
4454 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004455}
4456
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004457void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004458qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004459{
4460 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004461 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004462
Andrew Vasqueze4289242007-07-19 15:05:56 -07004463 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004464 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004465 if (!ha->fw_major_version)
4466 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004467
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004468 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004469 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07004470 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004471 ha->isp_ops->reset_chip(vha);
4472 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004473 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004474 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004475 continue;
4476 qla_printk(KERN_INFO, ha,
4477 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004478 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004479 }
4480}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004481
4482int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004483qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004484{
4485 int rval = QLA_SUCCESS;
4486 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004487 struct qla_hw_data *ha = vha->hw;
4488 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004489 struct req_que *req;
4490 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004491
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004492 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004493 return -EINVAL;
4494
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004495 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004496 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004497 req = ha->req_q_map[0];
4498 else
4499 req = vha->req;
4500 rsp = req->rsp;
4501
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004502 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004503 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004504 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004505 }
4506
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004507 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004508
4509 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004510 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004511 if (mb[0] != MBS_COMMAND_COMPLETE) {
4512 DEBUG15(qla_printk(KERN_INFO, ha,
4513 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4514 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4515 mb[0], mb[1], mb[2], mb[6], mb[7]));
4516 return (QLA_FUNCTION_FAILED);
4517 }
4518
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004519 atomic_set(&vha->loop_down_timer, 0);
4520 atomic_set(&vha->loop_state, LOOP_UP);
4521 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4522 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4523 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004524
4525 return rval;
4526}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004527
4528/* 84XX Support **************************************************************/
4529
4530static LIST_HEAD(qla_cs84xx_list);
4531static DEFINE_MUTEX(qla_cs84xx_mutex);
4532
4533static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004534qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004535{
4536 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004537 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004538
4539 mutex_lock(&qla_cs84xx_mutex);
4540
4541 /* Find any shared 84xx chip. */
4542 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4543 if (cs84xx->bus == ha->pdev->bus) {
4544 kref_get(&cs84xx->kref);
4545 goto done;
4546 }
4547 }
4548
4549 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4550 if (!cs84xx)
4551 goto done;
4552
4553 kref_init(&cs84xx->kref);
4554 spin_lock_init(&cs84xx->access_lock);
4555 mutex_init(&cs84xx->fw_update_mutex);
4556 cs84xx->bus = ha->pdev->bus;
4557
4558 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4559done:
4560 mutex_unlock(&qla_cs84xx_mutex);
4561 return cs84xx;
4562}
4563
4564static void
4565__qla84xx_chip_release(struct kref *kref)
4566{
4567 struct qla_chip_state_84xx *cs84xx =
4568 container_of(kref, struct qla_chip_state_84xx, kref);
4569
4570 mutex_lock(&qla_cs84xx_mutex);
4571 list_del(&cs84xx->list);
4572 mutex_unlock(&qla_cs84xx_mutex);
4573 kfree(cs84xx);
4574}
4575
4576void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004577qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004578{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004579 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004580 if (ha->cs84xx)
4581 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4582}
4583
4584static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004585qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004586{
4587 int rval;
4588 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004589 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004590
4591 mutex_lock(&ha->cs84xx->fw_update_mutex);
4592
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004593 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004594
4595 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4596
4597 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4598 QLA_SUCCESS;
4599}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004600
4601/* 81XX Support **************************************************************/
4602
4603int
4604qla81xx_nvram_config(scsi_qla_host_t *vha)
4605{
4606 int rval;
4607 struct init_cb_81xx *icb;
4608 struct nvram_81xx *nv;
4609 uint32_t *dptr;
4610 uint8_t *dptr1, *dptr2;
4611 uint32_t chksum;
4612 uint16_t cnt;
4613 struct qla_hw_data *ha = vha->hw;
4614
4615 rval = QLA_SUCCESS;
4616 icb = (struct init_cb_81xx *)ha->init_cb;
4617 nv = ha->nvram;
4618
4619 /* Determine NVRAM starting address. */
4620 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004621 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004622
4623 /* Get VPD data into cache */
4624 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d790382009-03-24 09:08:14 -07004625 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
4626 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004627
4628 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d790382009-03-24 09:08:14 -07004629 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004630 ha->nvram_size);
Andrew Vasquez3d790382009-03-24 09:08:14 -07004631 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004632 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4633 chksum += le32_to_cpu(*dptr++);
4634
Andrew Vasquez76403352009-04-06 22:33:39 -07004635 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004636 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4637
4638 /* Bad NVRAM data, set defaults parameters. */
4639 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4640 || nv->id[3] != ' ' ||
4641 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4642 /* Reset NVRAM data. */
4643 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4644 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4645 le16_to_cpu(nv->nvram_version));
4646 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4647 "invalid -- WWPN) defaults.\n");
4648
4649 /*
4650 * Set default initialization control block.
4651 */
4652 memset(nv, 0, ha->nvram_size);
4653 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4654 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4655 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4656 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4657 nv->exchange_count = __constant_cpu_to_le16(0);
4658 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004659 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004660 nv->port_name[2] = 0x00;
4661 nv->port_name[3] = 0xe0;
4662 nv->port_name[4] = 0x8b;
4663 nv->port_name[5] = 0x1c;
4664 nv->port_name[6] = 0x55;
4665 nv->port_name[7] = 0x86;
4666 nv->node_name[0] = 0x20;
4667 nv->node_name[1] = 0x00;
4668 nv->node_name[2] = 0x00;
4669 nv->node_name[3] = 0xe0;
4670 nv->node_name[4] = 0x8b;
4671 nv->node_name[5] = 0x1c;
4672 nv->node_name[6] = 0x55;
4673 nv->node_name[7] = 0x86;
4674 nv->login_retry_count = __constant_cpu_to_le16(8);
4675 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4676 nv->login_timeout = __constant_cpu_to_le16(0);
4677 nv->firmware_options_1 =
4678 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4679 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4680 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4681 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4682 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4683 nv->efi_parameters = __constant_cpu_to_le32(0);
4684 nv->reset_delay = 5;
4685 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4686 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4687 nv->link_down_timeout = __constant_cpu_to_le16(30);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07004688 nv->enode_mac[0] = 0x00;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004689 nv->enode_mac[1] = 0x02;
4690 nv->enode_mac[2] = 0x03;
4691 nv->enode_mac[3] = 0x04;
4692 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004693 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004694
4695 rval = 1;
4696 }
4697
4698 /* Reset Initialization control block */
4699 memset(icb, 0, sizeof(struct init_cb_81xx));
4700
4701 /* Copy 1st segment. */
4702 dptr1 = (uint8_t *)icb;
4703 dptr2 = (uint8_t *)&nv->version;
4704 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4705 while (cnt--)
4706 *dptr1++ = *dptr2++;
4707
4708 icb->login_retry_count = nv->login_retry_count;
4709
4710 /* Copy 2nd segment. */
4711 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4712 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4713 cnt = (uint8_t *)&icb->reserved_5 -
4714 (uint8_t *)&icb->interrupt_delay_timer;
4715 while (cnt--)
4716 *dptr1++ = *dptr2++;
4717
4718 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
4719 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4720 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
4721 icb->enode_mac[0] = 0x01;
4722 icb->enode_mac[1] = 0x02;
4723 icb->enode_mac[2] = 0x03;
4724 icb->enode_mac[3] = 0x04;
4725 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004726 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004727 }
4728
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004729 /* Use extended-initialization control block. */
4730 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
4731
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004732 /*
4733 * Setup driver NVRAM options.
4734 */
4735 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
4736 "QLE81XX");
4737
4738 /* Use alternate WWN? */
4739 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4740 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4741 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4742 }
4743
4744 /* Prepare nodename */
4745 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4746 /*
4747 * Firmware will apply the following mask if the nodename was
4748 * not provided.
4749 */
4750 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4751 icb->node_name[0] &= 0xF0;
4752 }
4753
4754 /* Set host adapter parameters. */
4755 ha->flags.disable_risc_code_load = 0;
4756 ha->flags.enable_lip_reset = 0;
4757 ha->flags.enable_lip_full_login =
4758 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4759 ha->flags.enable_target_reset =
4760 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4761 ha->flags.enable_led_scheme = 0;
4762 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4763
4764 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4765 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4766
4767 /* save HBA serial number */
4768 ha->serial0 = icb->port_name[5];
4769 ha->serial1 = icb->port_name[6];
4770 ha->serial2 = icb->port_name[7];
4771 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4772 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4773
4774 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4775
4776 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4777
4778 /* Set minimum login_timeout to 4 seconds. */
4779 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4780 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4781 if (le16_to_cpu(nv->login_timeout) < 4)
4782 nv->login_timeout = __constant_cpu_to_le16(4);
4783 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4784 icb->login_timeout = nv->login_timeout;
4785
4786 /* Set minimum RATOV to 100 tenths of a second. */
4787 ha->r_a_tov = 100;
4788
4789 ha->loop_reset_delay = nv->reset_delay;
4790
4791 /* Link Down Timeout = 0:
4792 *
4793 * When Port Down timer expires we will start returning
4794 * I/O's to OS with "DID_NO_CONNECT".
4795 *
4796 * Link Down Timeout != 0:
4797 *
4798 * The driver waits for the link to come up after link down
4799 * before returning I/Os to OS with "DID_NO_CONNECT".
4800 */
4801 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4802 ha->loop_down_abort_time =
4803 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4804 } else {
4805 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4806 ha->loop_down_abort_time =
4807 (LOOP_DOWN_TIME - ha->link_down_timeout);
4808 }
4809
4810 /* Need enough time to try and get the port back. */
4811 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4812 if (qlport_down_retry)
4813 ha->port_down_retry_count = qlport_down_retry;
4814
4815 /* Set login_retry_count */
4816 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4817 if (ha->port_down_retry_count ==
4818 le16_to_cpu(nv->port_down_retry_count) &&
4819 ha->port_down_retry_count > 3)
4820 ha->login_retry_count = ha->port_down_retry_count;
4821 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4822 ha->login_retry_count = ha->port_down_retry_count;
4823 if (ql2xloginretrycount)
4824 ha->login_retry_count = ql2xloginretrycount;
4825
4826 /* Enable ZIO. */
4827 if (!vha->flags.init_done) {
4828 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4829 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4830 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4831 le16_to_cpu(icb->interrupt_delay_timer): 2;
4832 }
4833 icb->firmware_options_2 &= __constant_cpu_to_le32(
4834 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4835 vha->flags.process_response_queue = 0;
4836 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4837 ha->zio_mode = QLA_ZIO_MODE_6;
4838
4839 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4840 "(%d us).\n", vha->host_no, ha->zio_mode,
4841 ha->zio_timer * 100));
4842 qla_printk(KERN_INFO, ha,
4843 "ZIO mode %d enabled; timer delay (%d us).\n",
4844 ha->zio_mode, ha->zio_timer * 100);
4845
4846 icb->firmware_options_2 |= cpu_to_le32(
4847 (uint32_t)ha->zio_mode);
4848 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4849 vha->flags.process_response_queue = 1;
4850 }
4851
4852 if (rval) {
4853 DEBUG2_3(printk(KERN_WARNING
4854 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4855 }
4856 return (rval);
4857}
4858
4859void
4860qla81xx_update_fw_options(scsi_qla_host_t *ha)
4861{
4862}