blob: 55540d2d4e38b32d95f50f5a081d1507c4441dad [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Andrew Vasquez0107109e2005-07-06 10:31:37 -070012#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14#include "qla_devtbl.h"
15
David Miller4e08df32007-04-16 12:37:43 -070016#ifdef CONFIG_SPARC
17#include <asm/prom.h>
David Miller4e08df32007-04-16 12:37:43 -070018#endif
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020/*
21* QLogic ISP2x00 Hardware Support Function Prototypes.
22*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070023static int qla2x00_isp_firmware(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070024static int qla2x00_setup_chip(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070025static int qla2x00_init_rings(scsi_qla_host_t *);
26static int qla2x00_fw_ready(scsi_qla_host_t *);
27static int qla2x00_configure_hba(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028static int qla2x00_configure_loop(scsi_qla_host_t *);
29static int qla2x00_configure_local_loop(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static int qla2x00_configure_fabric(scsi_qla_host_t *);
31static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
32static int qla2x00_device_resync(scsi_qla_host_t *);
33static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
34 uint16_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36static int qla2x00_restart_isp(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080038static int qla2x00_find_new_loop_id(scsi_qla_host_t *, fc_port_t *);
Adrian Bunk413975a2006-06-30 02:33:06 -070039
Harihara Kadayam4d4df192008-04-03 13:13:26 -070040static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
41static int qla84xx_init_chip(scsi_qla_host_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080042static int qla25xx_init_queues(struct qla_hw_data *);
Harihara Kadayam4d4df192008-04-03 13:13:26 -070043
Andrew Vasquezac280b62009-08-20 11:06:05 -070044/* SRB Extensions ---------------------------------------------------------- */
45
46static void
47qla2x00_ctx_sp_timeout(unsigned long __data)
48{
49 srb_t *sp = (srb_t *)__data;
50 struct srb_ctx *ctx;
51 fc_port_t *fcport = sp->fcport;
52 struct qla_hw_data *ha = fcport->vha->hw;
53 struct req_que *req;
54 unsigned long flags;
55
56 spin_lock_irqsave(&ha->hardware_lock, flags);
57 req = ha->req_q_map[0];
58 req->outstanding_cmds[sp->handle] = NULL;
59 ctx = sp->ctx;
60 ctx->timeout(sp);
61 spin_unlock_irqrestore(&ha->hardware_lock, flags);
62
63 ctx->free(sp);
64}
65
Giridhar Malavali9a069e12010-01-12 13:02:47 -080066void
Andrew Vasquezac280b62009-08-20 11:06:05 -070067qla2x00_ctx_sp_free(srb_t *sp)
68{
69 struct srb_ctx *ctx = sp->ctx;
70
71 kfree(ctx);
72 mempool_free(sp, sp->fcport->vha->hw->srb_mempool);
73}
74
75inline srb_t *
76qla2x00_get_ctx_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size,
77 unsigned long tmo)
78{
79 srb_t *sp;
80 struct qla_hw_data *ha = vha->hw;
81 struct srb_ctx *ctx;
82
83 sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
84 if (!sp)
85 goto done;
86 ctx = kzalloc(size, GFP_KERNEL);
87 if (!ctx) {
88 mempool_free(sp, ha->srb_mempool);
89 goto done;
90 }
91
92 memset(sp, 0, sizeof(*sp));
93 sp->fcport = fcport;
94 sp->ctx = ctx;
95 ctx->free = qla2x00_ctx_sp_free;
96
97 init_timer(&ctx->timer);
98 if (!tmo)
99 goto done;
100 ctx->timer.expires = jiffies + tmo * HZ;
101 ctx->timer.data = (unsigned long)sp;
102 ctx->timer.function = qla2x00_ctx_sp_timeout;
103 add_timer(&ctx->timer);
104done:
105 return sp;
106}
107
108/* Asynchronous Login/Logout Routines -------------------------------------- */
109
110#define ELS_TMO_2_RATOV(ha) ((ha)->r_a_tov / 10 * 2)
111
112static void
113qla2x00_async_logio_timeout(srb_t *sp)
114{
115 fc_port_t *fcport = sp->fcport;
116 struct srb_logio *lio = sp->ctx;
117
118 DEBUG2(printk(KERN_WARNING
119 "scsi(%ld:%x): Async-%s timeout.\n",
120 fcport->vha->host_no, sp->handle,
121 lio->ctx.type == SRB_LOGIN_CMD ? "login": "logout"));
122
123 if (lio->ctx.type == SRB_LOGIN_CMD)
124 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
125}
126
127int
128qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
129 uint16_t *data)
130{
131 struct qla_hw_data *ha = vha->hw;
132 srb_t *sp;
133 struct srb_logio *lio;
134 int rval;
135
136 rval = QLA_FUNCTION_FAILED;
137 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_logio),
138 ELS_TMO_2_RATOV(ha) + 2);
139 if (!sp)
140 goto done;
141
142 lio = sp->ctx;
143 lio->ctx.type = SRB_LOGIN_CMD;
144 lio->ctx.timeout = qla2x00_async_logio_timeout;
145 lio->flags |= SRB_LOGIN_COND_PLOGI;
146 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
147 lio->flags |= SRB_LOGIN_RETRIED;
148 rval = qla2x00_start_sp(sp);
149 if (rval != QLA_SUCCESS)
150 goto done_free_sp;
151
152 DEBUG2(printk(KERN_DEBUG
153 "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x "
154 "retries=%d.\n", fcport->vha->host_no, sp->handle, fcport->loop_id,
155 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
156 fcport->login_retry));
157 return rval;
158
159done_free_sp:
160 del_timer_sync(&lio->ctx.timer);
161 lio->ctx.free(sp);
162done:
163 return rval;
164}
165
166int
167qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
168{
169 struct qla_hw_data *ha = vha->hw;
170 srb_t *sp;
171 struct srb_logio *lio;
172 int rval;
173
174 rval = QLA_FUNCTION_FAILED;
175 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_logio),
176 ELS_TMO_2_RATOV(ha) + 2);
177 if (!sp)
178 goto done;
179
180 lio = sp->ctx;
181 lio->ctx.type = SRB_LOGOUT_CMD;
182 lio->ctx.timeout = qla2x00_async_logio_timeout;
183 rval = qla2x00_start_sp(sp);
184 if (rval != QLA_SUCCESS)
185 goto done_free_sp;
186
187 DEBUG2(printk(KERN_DEBUG
188 "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n",
189 fcport->vha->host_no, sp->handle, fcport->loop_id,
190 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
191 return rval;
192
193done_free_sp:
194 del_timer_sync(&lio->ctx.timer);
195 lio->ctx.free(sp);
196done:
197 return rval;
198}
199
200int
201qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
202 uint16_t *data)
203{
204 int rval;
205 uint8_t opts = 0;
206
207 switch (data[0]) {
208 case MBS_COMMAND_COMPLETE:
Andrew Vasquezf08b7252010-01-12 12:59:48 -0800209 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquezac280b62009-08-20 11:06:05 -0700210 opts |= BIT_1;
211 rval = qla2x00_get_port_database(vha, fcport, opts);
212 if (rval != QLA_SUCCESS)
213 qla2x00_mark_device_lost(vha, fcport, 1, 0);
214 else
215 qla2x00_update_fcport(vha, fcport);
216 break;
217 case MBS_COMMAND_ERROR:
218 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
219 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
220 else
221 qla2x00_mark_device_lost(vha, fcport, 1, 0);
222 break;
223 case MBS_PORT_ID_USED:
224 fcport->loop_id = data[1];
225 qla2x00_post_async_login_work(vha, fcport, NULL);
226 break;
227 case MBS_LOOP_ID_USED:
228 fcport->loop_id++;
229 rval = qla2x00_find_new_loop_id(vha, fcport);
230 if (rval != QLA_SUCCESS) {
231 qla2x00_mark_device_lost(vha, fcport, 1, 0);
232 break;
233 }
234 qla2x00_post_async_login_work(vha, fcport, NULL);
235 break;
236 }
237 return QLA_SUCCESS;
238}
239
240int
241qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
242 uint16_t *data)
243{
244 qla2x00_mark_device_lost(vha, fcport, 1, 0);
245 return QLA_SUCCESS;
246}
247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248/****************************************************************************/
249/* QLogic ISP2x00 Hardware Support Functions. */
250/****************************************************************************/
251
252/*
253* qla2x00_initialize_adapter
254* Initialize board.
255*
256* Input:
257* ha = adapter block pointer.
258*
259* Returns:
260* 0 = success
261*/
262int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800263qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264{
265 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800266 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800267 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700268
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800270 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700271 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800272 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -0800273 ha->flags.pci_channel_io_perm_failure = 0;
274 ha->flags.eeh_busy = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800275 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
276 atomic_set(&vha->loop_state, LOOP_DOWN);
277 vha->device_flags = DFLG_NO_CABLE;
278 vha->dpc_flags = 0;
279 vha->flags.management_server_logged_in = 0;
280 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 ha->isp_abort_cnt = 0;
282 ha->beacon_blink_led = 0;
283
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800284 set_bit(0, ha->req_qid_map);
285 set_bit(0, ha->rsp_qid_map);
286
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700287 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800288 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 if (rval) {
Andrew Vasquez7c98a042007-01-29 10:22:29 -0800290 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800291 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 return (rval);
293 }
294
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800295 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800297 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700298 if (rval) {
299 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800300 vha->host_no));
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700301 return (rval);
302 }
303
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800304 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -0800305
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700307
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800308 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700310 if (ha->flags.disable_serdes) {
311 /* Mask HBA via NVRAM settings? */
312 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
313 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800314 vha->port_name[0], vha->port_name[1],
315 vha->port_name[2], vha->port_name[3],
316 vha->port_name[4], vha->port_name[5],
317 vha->port_name[6], vha->port_name[7]);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700318 return QLA_FUNCTION_FAILED;
319 }
320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
322
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800323 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
324 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800325 if (rval)
326 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800327 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800328 if (rval)
329 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700331
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700332 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800333 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700334 if (!ha->cs84xx) {
335 qla_printk(KERN_ERR, ha,
336 "Unable to configure ISP84XX.\n");
337 return QLA_FUNCTION_FAILED;
338 }
339 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800340 rval = qla2x00_init_rings(vha);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700341 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800343 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700344 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800345 rval = qla84xx_init_chip(vha);
346 if (rval != QLA_SUCCESS) {
347 qla_printk(KERN_ERR, ha,
348 "Unable to initialize ISP84XX.\n");
349 qla84xx_put_chip(vha);
350 }
351 }
352
Sarang Radke09ff7012010-03-19 17:03:59 -0700353 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) {
354 if (qla24xx_read_fcp_prio_cfg(vha))
355 qla_printk(KERN_ERR, ha,
356 "Unable to read FCP priority data.\n");
357 }
358
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 return (rval);
360}
361
362/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700363 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 * @ha: HA context
365 *
366 * Returns 0 on success.
367 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700368int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800369qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700371 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700372 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800373 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700374 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700377 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700380 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
382
Andrew Vasquez737faec2008-10-24 15:13:45 -0700383 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700385 /* Get PCI bus information. */
386 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700387 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700388 spin_unlock_irqrestore(&ha->hardware_lock, flags);
389
390 return QLA_SUCCESS;
391}
392
393/**
394 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
395 * @ha: HA context
396 *
397 * Returns 0 on success.
398 */
399int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800400qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700401{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700402 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700403 unsigned long flags = 0;
404 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800405 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700406 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700407
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700408 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700409 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700410
411 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700412 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700413
414 if (IS_QLA2322(ha) || IS_QLA6322(ha))
415 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700416 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700417
418 /*
419 * If this is a 2300 card and not 2312, reset the
420 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
421 * the 2310 also reports itself as a 2300 so we need to get the
422 * fb revision level -- a 6 indicates it really is a 2300 and
423 * not a 2310.
424 */
425 if (IS_QLA2300(ha)) {
426 spin_lock_irqsave(&ha->hardware_lock, flags);
427
428 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700429 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700430 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700431 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700432 break;
433
434 udelay(10);
435 }
436
437 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700438 WRT_REG_WORD(&reg->ctrl_status, 0x20);
439 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700440
441 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700442 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700443
444 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700445 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700446
447 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700448 WRT_REG_WORD(&reg->ctrl_status, 0x0);
449 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700450
451 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700452 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700453 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700454 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700455 break;
456
457 udelay(10);
458 }
459
460 spin_unlock_irqrestore(&ha->hardware_lock, flags);
461 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700462
463 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
464
Andrew Vasquez737faec2008-10-24 15:13:45 -0700465 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700466
467 /* Get PCI bus information. */
468 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700469 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700470 spin_unlock_irqrestore(&ha->hardware_lock, flags);
471
472 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473}
474
475/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700476 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
477 * @ha: HA context
478 *
479 * Returns 0 on success.
480 */
481int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800482qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700483{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700484 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700485 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800486 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700487 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700488
489 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700490 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700491
492 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700493 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700494 w &= ~PCI_COMMAND_INTX_DISABLE;
495 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
496
497 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
498
499 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700500 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
501 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700502
503 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700504 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
505 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700506
Andrew Vasquez737faec2008-10-24 15:13:45 -0700507 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700508
Auke Kok44c10132007-06-08 15:46:36 -0700509 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800510
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700511 /* Get PCI bus information. */
512 spin_lock_irqsave(&ha->hardware_lock, flags);
513 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
514 spin_unlock_irqrestore(&ha->hardware_lock, flags);
515
516 return QLA_SUCCESS;
517}
518
519/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700520 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
521 * @ha: HA context
522 *
523 * Returns 0 on success.
524 */
525int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800526qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700527{
528 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800529 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700530
531 pci_set_master(ha->pdev);
532 pci_try_set_mwi(ha->pdev);
533
534 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
535 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
536 w &= ~PCI_COMMAND_INTX_DISABLE;
537 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
538
539 /* PCIe -- adjust Maximum Read Request Size (2048). */
540 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
541 pcie_set_readrq(ha->pdev, 2048);
542
Andrew Vasquez737faec2008-10-24 15:13:45 -0700543 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700544
545 ha->chip_revision = ha->pdev->revision;
546
547 return QLA_SUCCESS;
548}
549
550/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 * qla2x00_isp_firmware() - Choose firmware image.
552 * @ha: HA context
553 *
554 * Returns 0 on success.
555 */
556static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800557qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558{
559 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700560 uint16_t loop_id, topo, sw_cap;
561 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800562 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
564 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700565 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
567 if (ha->flags.disable_risc_code_load) {
568 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800569 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
571
572 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800573 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700574 if (rval == QLA_SUCCESS) {
575 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800576 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700577 &area, &domain, &topo, &sw_cap);
578 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 }
580
581 if (rval) {
582 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800583 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 }
585
586 return (rval);
587}
588
589/**
590 * qla2x00_reset_chip() - Reset ISP chip.
591 * @ha: HA context
592 *
593 * Returns 0 on success.
594 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700595void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800596qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597{
598 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800599 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700600 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 uint16_t cmd;
603
Andrew Vasquez85880802009-12-15 21:29:46 -0800604 if (unlikely(pci_channel_offline(ha->pdev)))
605 return;
606
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700607 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
609 spin_lock_irqsave(&ha->hardware_lock, flags);
610
611 /* Turn off master enable */
612 cmd = 0;
613 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
614 cmd &= ~PCI_COMMAND_MASTER;
615 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
616
617 if (!IS_QLA2100(ha)) {
618 /* Pause RISC. */
619 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
620 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
621 for (cnt = 0; cnt < 30000; cnt++) {
622 if ((RD_REG_WORD(&reg->hccr) &
623 HCCR_RISC_PAUSE) != 0)
624 break;
625 udelay(100);
626 }
627 } else {
628 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
629 udelay(10);
630 }
631
632 /* Select FPM registers. */
633 WRT_REG_WORD(&reg->ctrl_status, 0x20);
634 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
635
636 /* FPM Soft Reset. */
637 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
638 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
639
640 /* Toggle Fpm Reset. */
641 if (!IS_QLA2200(ha)) {
642 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
643 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
644 }
645
646 /* Select frame buffer registers. */
647 WRT_REG_WORD(&reg->ctrl_status, 0x10);
648 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
649
650 /* Reset frame buffer FIFOs. */
651 if (IS_QLA2200(ha)) {
652 WRT_FB_CMD_REG(ha, reg, 0xa000);
653 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
654 } else {
655 WRT_FB_CMD_REG(ha, reg, 0x00fc);
656
657 /* Read back fb_cmd until zero or 3 seconds max */
658 for (cnt = 0; cnt < 3000; cnt++) {
659 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
660 break;
661 udelay(100);
662 }
663 }
664
665 /* Select RISC module registers. */
666 WRT_REG_WORD(&reg->ctrl_status, 0);
667 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
668
669 /* Reset RISC processor. */
670 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
671 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
672
673 /* Release RISC processor. */
674 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
675 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
676 }
677
678 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
679 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
680
681 /* Reset ISP chip. */
682 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
683
684 /* Wait for RISC to recover from reset. */
685 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
686 /*
687 * It is necessary to for a delay here since the card doesn't
688 * respond to PCI reads during a reset. On some architectures
689 * this will result in an MCA.
690 */
691 udelay(20);
692 for (cnt = 30000; cnt; cnt--) {
693 if ((RD_REG_WORD(&reg->ctrl_status) &
694 CSR_ISP_SOFT_RESET) == 0)
695 break;
696 udelay(100);
697 }
698 } else
699 udelay(10);
700
701 /* Reset RISC processor. */
702 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
703
704 WRT_REG_WORD(&reg->semaphore, 0);
705
706 /* Release RISC processor. */
707 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
708 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
709
710 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
711 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700712 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
715 udelay(100);
716 }
717 } else
718 udelay(100);
719
720 /* Turn on master enable */
721 cmd |= PCI_COMMAND_MASTER;
722 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
723
724 /* Disable RISC pause on FPM parity error. */
725 if (!IS_QLA2100(ha)) {
726 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
727 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
728 }
729
730 spin_unlock_irqrestore(&ha->hardware_lock, flags);
731}
732
733/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700734 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700735 * @ha: HA context
736 *
737 * Returns 0 on success.
738 */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700739static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800740qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700741{
742 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800743 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700744 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
745 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800746 uint16_t wd;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700747
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700748 spin_lock_irqsave(&ha->hardware_lock, flags);
749
750 /* Reset RISC. */
751 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
752 for (cnt = 0; cnt < 30000; cnt++) {
753 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
754 break;
755
756 udelay(10);
757 }
758
759 WRT_REG_DWORD(&reg->ctrl_status,
760 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800761 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700762
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800763 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700764 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700765 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
766 for (cnt = 10000 ; cnt && d2; cnt--) {
767 udelay(5);
768 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
769 barrier();
770 }
771
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800772 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700773 d2 = RD_REG_DWORD(&reg->ctrl_status);
774 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
775 udelay(5);
776 d2 = RD_REG_DWORD(&reg->ctrl_status);
777 barrier();
778 }
779
780 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
781 RD_REG_DWORD(&reg->hccr);
782
783 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
784 RD_REG_DWORD(&reg->hccr);
785
786 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
787 RD_REG_DWORD(&reg->hccr);
788
789 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
790 for (cnt = 6000000 ; cnt && d2; cnt--) {
791 udelay(5);
792 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
793 barrier();
794 }
795
796 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800797
798 if (IS_NOPOLLING_TYPE(ha))
799 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700800}
801
802/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700803 * qla24xx_reset_chip() - Reset ISP24xx chip.
804 * @ha: HA context
805 *
806 * Returns 0 on success.
807 */
808void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800809qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -0700810{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800811 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -0800812
813 if (pci_channel_offline(ha->pdev) &&
814 ha->flags.pci_channel_io_perm_failure) {
815 return;
816 }
817
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700818 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700819
820 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800821 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700822}
823
824/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 * qla2x00_chip_diag() - Test chip for proper operation.
826 * @ha: HA context
827 *
828 * Returns 0 on success.
829 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700830int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800831qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832{
833 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800834 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700835 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 unsigned long flags = 0;
837 uint16_t data;
838 uint32_t cnt;
839 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800840 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841
842 /* Assume a failed state */
843 rval = QLA_FUNCTION_FAILED;
844
845 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800846 vha->host_no, (u_long)&reg->flash_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
848 spin_lock_irqsave(&ha->hardware_lock, flags);
849
850 /* Reset ISP chip. */
851 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
852
853 /*
854 * We need to have a delay here since the card will not respond while
855 * in reset causing an MCA on some architectures.
856 */
857 udelay(20);
858 data = qla2x00_debounce_register(&reg->ctrl_status);
859 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
860 udelay(5);
861 data = RD_REG_WORD(&reg->ctrl_status);
862 barrier();
863 }
864
865 if (!cnt)
866 goto chip_diag_failed;
867
868 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
Andrew Vasquez76403352009-04-06 22:33:39 -0700869 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
871 /* Reset RISC processor. */
872 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
873 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
874
875 /* Workaround for QLA2312 PCI parity error */
876 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
877 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
878 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
879 udelay(5);
880 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700881 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 }
883 } else
884 udelay(10);
885
886 if (!cnt)
887 goto chip_diag_failed;
888
889 /* Check product ID of chip */
Andrew Vasquez76403352009-04-06 22:33:39 -0700890 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
892 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
893 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
894 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
895 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
896 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
897 mb[3] != PROD_ID_3) {
898 qla_printk(KERN_WARNING, ha,
899 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
900
901 goto chip_diag_failed;
902 }
903 ha->product_id[0] = mb[1];
904 ha->product_id[1] = mb[2];
905 ha->product_id[2] = mb[3];
906 ha->product_id[3] = mb[4];
907
908 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800909 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
911 else
912 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800913 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
915 if (IS_QLA2200(ha) &&
916 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
917 /* Limit firmware transfer size with a 2200A */
918 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800919 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -0800921 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 ha->fw_transfer_size = 128;
923 }
924
925 /* Wrap Incoming Mailboxes Test. */
926 spin_unlock_irqrestore(&ha->hardware_lock, flags);
927
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800928 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
929 rval = qla2x00_mbx_reg_test(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 if (rval) {
931 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800932 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 qla_printk(KERN_WARNING, ha,
934 "Failed mailbox send register test\n");
935 }
936 else {
937 /* Flag a successful rval */
938 rval = QLA_SUCCESS;
939 }
940 spin_lock_irqsave(&ha->hardware_lock, flags);
941
942chip_diag_failed:
943 if (rval)
944 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800945 "****\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
947 spin_unlock_irqrestore(&ha->hardware_lock, flags);
948
949 return (rval);
950}
951
952/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700953 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
954 * @ha: HA context
955 *
956 * Returns 0 on success.
957 */
958int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800959qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700960{
961 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800962 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800963 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700964
Giridhar Malavalia9083012010-04-12 17:59:55 -0700965 if (IS_QLA82XX(ha))
966 return QLA_SUCCESS;
967
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800968 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700969
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800970 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700971 if (rval) {
972 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800973 vha->host_no));
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700974 qla_printk(KERN_WARNING, ha,
975 "Failed mailbox send register test\n");
976 } else {
977 /* Flag a successful rval */
978 rval = QLA_SUCCESS;
979 }
980
981 return rval;
982}
983
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700984void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800985qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700986{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700987 int rval;
988 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800989 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800990 dma_addr_t tc_dma;
991 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800992 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800993 struct req_que *req = ha->req_q_map[0];
994 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700995
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700996 if (ha->fw_dump) {
997 qla_printk(KERN_WARNING, ha,
998 "Firmware dump previously allocated.\n");
999 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001000 }
1001
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001002 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001003 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001004 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1005 fixed_size = sizeof(struct qla2100_fw_dump);
1006 } else if (IS_QLA23XX(ha)) {
1007 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1008 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1009 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001010 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001011 if (IS_QLA81XX(ha))
1012 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1013 else if (IS_QLA25XX(ha))
1014 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1015 else
1016 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001017 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1018 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001019 if (ha->mqenable)
1020 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001021 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001022 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001023 goto try_eft;
1024
1025 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1026 GFP_KERNEL);
1027 if (!tc) {
1028 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1029 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001030 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001031 }
1032
1033 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001034 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001035 ha->fce_mb, &ha->fce_bufs);
1036 if (rval) {
1037 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1038 "FCE (%d).\n", rval);
1039 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1040 tc_dma);
1041 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001042 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001043 }
1044
1045 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
1046 FCE_SIZE / 1024);
1047
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001048 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001049 ha->flags.fce_enabled = 1;
1050 ha->fce_dma = tc_dma;
1051 ha->fce = tc;
1052try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001053 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001054 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001055 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001056 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001057 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1058 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
1059 goto cont_alloc;
1060 }
1061
Andrew Vasquezfc447652008-01-17 09:02:18 -08001062 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001063 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001064 if (rval) {
1065 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1066 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001067 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1068 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001069 goto cont_alloc;
1070 }
1071
1072 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
1073 EFT_SIZE / 1024);
1074
1075 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001076 ha->eft_dma = tc_dma;
1077 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001078 }
1079cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001080 req_q_size = req->length * sizeof(request_t);
1081 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001082
1083 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001084 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001085 ha->chain_offset = dump_size;
1086 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001087
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001088 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001089 if (!ha->fw_dump) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001090 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001091 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001092
1093 if (ha->eft) {
1094 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1095 ha->eft_dma);
1096 ha->eft = NULL;
1097 ha->eft_dma = 0;
1098 }
1099 return;
1100 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001101 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
1102 dump_size / 1024);
1103
1104 ha->fw_dump_len = dump_size;
1105 ha->fw_dump->signature[0] = 'Q';
1106 ha->fw_dump->signature[1] = 'L';
1107 ha->fw_dump->signature[2] = 'G';
1108 ha->fw_dump->signature[3] = 'C';
1109 ha->fw_dump->version = __constant_htonl(1);
1110
1111 ha->fw_dump->fixed_size = htonl(fixed_size);
1112 ha->fw_dump->mem_size = htonl(mem_size);
1113 ha->fw_dump->req_q_size = htonl(req_q_size);
1114 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1115
1116 ha->fw_dump->eft_size = htonl(eft_size);
1117 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1118 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1119
1120 ha->fw_dump->header_size =
1121 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001122}
1123
Andrew Vasquez18e75552009-06-03 09:55:30 -07001124static int
1125qla81xx_mpi_sync(scsi_qla_host_t *vha)
1126{
1127#define MPS_MASK 0xe0
1128 int rval;
1129 uint16_t dc;
1130 uint32_t dw;
1131 struct qla_hw_data *ha = vha->hw;
1132
1133 if (!IS_QLA81XX(vha->hw))
1134 return QLA_SUCCESS;
1135
1136 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1137 if (rval != QLA_SUCCESS) {
1138 DEBUG2(qla_printk(KERN_WARNING, ha,
1139 "Sync-MPI: Unable to acquire semaphore.\n"));
1140 goto done;
1141 }
1142
1143 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1144 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1145 if (rval != QLA_SUCCESS) {
1146 DEBUG2(qla_printk(KERN_WARNING, ha,
1147 "Sync-MPI: Unable to read sync.\n"));
1148 goto done_release;
1149 }
1150
1151 dc &= MPS_MASK;
1152 if (dc == (dw & MPS_MASK))
1153 goto done_release;
1154
1155 dw &= ~MPS_MASK;
1156 dw |= dc;
1157 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1158 if (rval != QLA_SUCCESS) {
1159 DEBUG2(qla_printk(KERN_WARNING, ha,
1160 "Sync-MPI: Unable to gain sync.\n"));
1161 }
1162
1163done_release:
1164 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1165 if (rval != QLA_SUCCESS) {
1166 DEBUG2(qla_printk(KERN_WARNING, ha,
1167 "Sync-MPI: Unable to release semaphore.\n"));
1168 }
1169
1170done:
1171 return rval;
1172}
1173
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001174/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 * qla2x00_setup_chip() - Load and start RISC firmware.
1176 * @ha: HA context
1177 *
1178 * Returns 0 on success.
1179 */
1180static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001181qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001183 int rval;
1184 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001185 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001186 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1187 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001188 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001189
Giridhar Malavalia9083012010-04-12 17:59:55 -07001190 if (IS_QLA82XX(ha)) {
1191 rval = ha->isp_ops->load_risc(vha, &srisc_address);
1192 if (rval == QLA_SUCCESS)
1193 goto enable_82xx_npiv;
1194 }
1195
Andrew Vasquez3db06522008-01-31 12:33:49 -08001196 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1197 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1198 spin_lock_irqsave(&ha->hardware_lock, flags);
1199 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1200 RD_REG_WORD(&reg->hccr);
1201 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1202 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
Andrew Vasquez18e75552009-06-03 09:55:30 -07001204 qla81xx_mpi_sync(vha);
1205
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001207 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001208 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001210 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001212 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 if (rval == QLA_SUCCESS) {
1214 /* Start firmware execution. */
1215 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001216 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001218 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001220 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001221enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001222 fw_major_version = ha->fw_major_version;
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001223 rval = qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 &ha->fw_major_version,
1225 &ha->fw_minor_version,
1226 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001227 &ha->fw_attributes, &ha->fw_memory_size,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001228 ha->mpi_version, &ha->mpi_capabilities,
1229 ha->phy_version);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001230 if (rval != QLA_SUCCESS)
1231 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001232 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001233 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001234 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001235 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001236 if ((!ha->max_npiv_vports) ||
1237 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001238 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001239 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001240 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001241 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001242 qla2x00_get_resource_cnts(vha, NULL,
1243 &ha->fw_xcb_count, NULL, NULL,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001244 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001245
Giridhar Malavalia9083012010-04-12 17:59:55 -07001246 if (!fw_major_version && ql2xallocfwdump) {
1247 if (!IS_QLA82XX(ha))
1248 qla2x00_alloc_fw_dump(vha);
1249 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 }
1251 } else {
1252 DEBUG2(printk(KERN_INFO
1253 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001254 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 }
1256 }
1257
Andrew Vasquez3db06522008-01-31 12:33:49 -08001258 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1259 /* Enable proper parity. */
1260 spin_lock_irqsave(&ha->hardware_lock, flags);
1261 if (IS_QLA2300(ha))
1262 /* SRAM parity */
1263 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1264 else
1265 /* SRAM, Instruction RAM and GP RAM parity */
1266 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1267 RD_REG_WORD(&reg->hccr);
1268 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1269 }
1270
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001271 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1272 uint32_t size;
1273
1274 rval = qla81xx_fac_get_sector_size(vha, &size);
1275 if (rval == QLA_SUCCESS) {
1276 ha->flags.fac_supported = 1;
1277 ha->fdt_block_size = size << 2;
1278 } else {
1279 qla_printk(KERN_ERR, ha,
1280 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1281 ha->fw_major_version, ha->fw_minor_version,
1282 ha->fw_subminor_version);
1283 }
1284 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001285failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 if (rval) {
1287 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001288 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 }
1290
1291 return (rval);
1292}
1293
1294/**
1295 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1296 * @ha: HA context
1297 *
1298 * Beginning of request ring has initialization control block already built
1299 * by nvram config routine.
1300 *
1301 * Returns 0 on success.
1302 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001303void
1304qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305{
1306 uint16_t cnt;
1307 response_t *pkt;
1308
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001309 rsp->ring_ptr = rsp->ring;
1310 rsp->ring_index = 0;
1311 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001312 pkt = rsp->ring_ptr;
1313 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 pkt->signature = RESPONSE_PROCESSED;
1315 pkt++;
1316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317}
1318
1319/**
1320 * qla2x00_update_fw_options() - Read and process firmware options.
1321 * @ha: HA context
1322 *
1323 * Returns 0 on success.
1324 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001325void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001326qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327{
1328 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001329 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
1331 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001332 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
1334 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1335 return;
1336
1337 /* Serial Link options. */
1338 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001339 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1341 sizeof(ha->fw_seriallink_options)));
1342
1343 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1344 if (ha->fw_seriallink_options[3] & BIT_2) {
1345 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1346
1347 /* 1G settings */
1348 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1349 emphasis = (ha->fw_seriallink_options[2] &
1350 (BIT_4 | BIT_3)) >> 3;
1351 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001352 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 rx_sens = (ha->fw_seriallink_options[0] &
1354 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1355 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1356 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1357 if (rx_sens == 0x0)
1358 rx_sens = 0x3;
1359 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1360 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1361 ha->fw_options[10] |= BIT_5 |
1362 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1363 (tx_sens & (BIT_1 | BIT_0));
1364
1365 /* 2G settings */
1366 swing = (ha->fw_seriallink_options[2] &
1367 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1368 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1369 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001370 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 rx_sens = (ha->fw_seriallink_options[1] &
1372 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1373 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1374 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1375 if (rx_sens == 0x0)
1376 rx_sens = 0x3;
1377 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1378 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1379 ha->fw_options[11] |= BIT_5 |
1380 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1381 (tx_sens & (BIT_1 | BIT_0));
1382 }
1383
1384 /* FCP2 options. */
1385 /* Return command IOCBs without waiting for an ABTS to complete. */
1386 ha->fw_options[3] |= BIT_13;
1387
1388 /* LED scheme. */
1389 if (ha->flags.enable_led_scheme)
1390 ha->fw_options[2] |= BIT_12;
1391
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001392 /* Detect ISP6312. */
1393 if (IS_QLA6312(ha))
1394 ha->fw_options[2] |= BIT_13;
1395
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001397 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398}
1399
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001400void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001401qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001402{
1403 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001404 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001405
Giridhar Malavalia9083012010-04-12 17:59:55 -07001406 if (IS_QLA82XX(ha))
1407 return;
1408
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001409 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001410 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001411 return;
1412
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001413 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001414 le16_to_cpu(ha->fw_seriallink_options24[1]),
1415 le16_to_cpu(ha->fw_seriallink_options24[2]),
1416 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001417 if (rval != QLA_SUCCESS) {
1418 qla_printk(KERN_WARNING, ha,
1419 "Unable to update Serial Link options (%x).\n", rval);
1420 }
1421}
1422
1423void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001424qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001425{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001426 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001427 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001428 struct req_que *req = ha->req_q_map[0];
1429 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001430
1431 /* Setup ring parameters in initialization control block. */
1432 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1433 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001434 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1435 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1436 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1437 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1438 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1439 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001440
1441 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1442 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1443 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1444 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1445 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1446}
1447
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001448void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001449qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001450{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001451 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001452 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1453 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1454 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001455 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001456 uint16_t rid = 0;
1457 struct req_que *req = ha->req_q_map[0];
1458 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001459
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001460/* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001461 icb = (struct init_cb_24xx *)ha->init_cb;
1462 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1463 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001464 icb->request_q_length = cpu_to_le16(req->length);
1465 icb->response_q_length = cpu_to_le16(rsp->length);
1466 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1467 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1468 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1469 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001470
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001471 if (ha->mqenable) {
1472 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1473 icb->rid = __constant_cpu_to_le16(rid);
1474 if (ha->flags.msix_enabled) {
1475 msix = &ha->msix_entries[1];
1476 DEBUG2_17(printk(KERN_INFO
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001477 "Registering vector 0x%x for base que\n", msix->entry));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001478 icb->msix = cpu_to_le16(msix->entry);
1479 }
1480 /* Use alternate PCI bus number */
1481 if (MSB(rid))
1482 icb->firmware_options_2 |=
1483 __constant_cpu_to_le32(BIT_19);
1484 /* Use alternate PCI devfn */
1485 if (LSB(rid))
1486 icb->firmware_options_2 |=
1487 __constant_cpu_to_le32(BIT_18);
1488
Anirban Chakraborty31557542009-12-02 10:36:55 -08001489 /* Use Disable MSIX Handshake mode for capable adapters */
1490 if (IS_MSIX_NACK_CAPABLE(ha)) {
1491 icb->firmware_options_2 &=
1492 __constant_cpu_to_le32(~BIT_22);
1493 ha->flags.disable_msix_handshake = 1;
1494 qla_printk(KERN_INFO, ha,
1495 "MSIX Handshake Disable Mode turned on\n");
1496 } else {
1497 icb->firmware_options_2 |=
1498 __constant_cpu_to_le32(BIT_22);
1499 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001500 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001501
1502 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1503 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1504 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1505 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1506 } else {
1507 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1508 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1509 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1510 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1511 }
1512 /* PCI posting */
1513 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001514}
1515
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516/**
1517 * qla2x00_init_rings() - Initializes firmware.
1518 * @ha: HA context
1519 *
1520 * Beginning of request ring has initialization control block already built
1521 * by nvram config routine.
1522 *
1523 * Returns 0 on success.
1524 */
1525static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001526qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527{
1528 int rval;
1529 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001530 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001531 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001532 struct req_que *req;
1533 struct rsp_que *rsp;
1534 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001535 struct mid_init_cb_24xx *mid_init_cb =
1536 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
1538 spin_lock_irqsave(&ha->hardware_lock, flags);
1539
1540 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001541 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001542 req = ha->req_q_map[que];
1543 if (!req)
1544 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001545 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001546 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001548 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001549
1550 /* Initialize firmware. */
1551 req->ring_ptr = req->ring;
1552 req->ring_index = 0;
1553 req->cnt = req->length;
1554 }
1555
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001556 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001557 rsp = ha->rsp_q_map[que];
1558 if (!rsp)
1559 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001560 /* Initialize response queue entries */
1561 qla2x00_init_response_q_entries(rsp);
1562 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
1564 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001565 list_for_each_entry(vp, &ha->vp_list, list) {
1566 vp->rscn_in_ptr = 0;
1567 vp->rscn_out_ptr = 0;
1568 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001569 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570
1571 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1572
1573 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001574 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001576 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001577
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001578 if (ha->flags.npiv_supported) {
1579 if (ha->operating_mode == LOOP)
1580 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001581 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001582 }
1583
Andrew Vasquez24a08132009-03-24 09:08:16 -07001584 if (IS_FWI2_CAPABLE(ha)) {
1585 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1586 mid_init_cb->init_cb.execution_throttle =
1587 cpu_to_le16(ha->fw_xcb_count);
1588 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001589
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001590 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 if (rval) {
1592 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001593 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 } else {
1595 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001596 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 }
1598
1599 return (rval);
1600}
1601
1602/**
1603 * qla2x00_fw_ready() - Waits for firmware ready.
1604 * @ha: HA context
1605 *
1606 * Returns 0 on success.
1607 */
1608static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001609qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610{
1611 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001612 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 uint16_t min_wait; /* Minimum wait time if loop is down */
1614 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07001615 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001616 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617
1618 rval = QLA_SUCCESS;
1619
1620 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001621 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622
1623 /*
1624 * Firmware should take at most one RATOV to login, plus 5 seconds for
1625 * our own processing.
1626 */
1627 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1628 wait_time = min_wait;
1629 }
1630
1631 /* Min wait time if loop down */
1632 mtime = jiffies + (min_wait * HZ);
1633
1634 /* wait time before firmware ready */
1635 wtime = jiffies + (wait_time * HZ);
1636
1637 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001638 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1640
1641 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001642 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643
1644 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001645 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001647 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001648 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001650 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1651 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001652 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001653 state[2]));
1654 if ((state[2] & FSTATE_LOGGED_IN) &&
1655 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1656 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001657 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001658
1659 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001660 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001661 if (rval != QLA_SUCCESS)
1662 break;
1663
1664 /* Add time taken to initialize. */
1665 cs84xx_time = jiffies - cs84xx_time;
1666 wtime += cs84xx_time;
1667 mtime += cs84xx_time;
1668 DEBUG16(printk("scsi(%ld): Increasing "
1669 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001670 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001671 }
1672 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001674 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001676 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 &ha->login_timeout, &ha->r_a_tov);
1678
1679 rval = QLA_SUCCESS;
1680 break;
1681 }
1682
1683 rval = QLA_FUNCTION_FAILED;
1684
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001685 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001686 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001688 * other than Wait for Login.
1689 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 if (time_after_eq(jiffies, mtime)) {
1691 qla_printk(KERN_INFO, ha,
1692 "Cable is unplugged...\n");
1693
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001694 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 break;
1696 }
1697 }
1698 } else {
1699 /* Mailbox cmd failed. Timeout on min_wait. */
1700 if (time_after_eq(jiffies, mtime))
1701 break;
1702 }
1703
1704 if (time_after_eq(jiffies, wtime))
1705 break;
1706
1707 /* Delay for a while */
1708 msleep(500);
1709
1710 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001711 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 } while (1);
1713
Andrew Vasquez656e8912009-06-03 09:55:29 -07001714 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1715 vha->host_no, state[0], state[1], state[2], state[3], state[4],
1716 jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717
1718 if (rval) {
1719 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001720 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 }
1722
1723 return (rval);
1724}
1725
1726/*
1727* qla2x00_configure_hba
1728* Setup adapter context.
1729*
1730* Input:
1731* ha = adapter state pointer.
1732*
1733* Returns:
1734* 0 = success
1735*
1736* Context:
1737* Kernel context.
1738*/
1739static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001740qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741{
1742 int rval;
1743 uint16_t loop_id;
1744 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001745 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 uint8_t al_pa;
1747 uint8_t area;
1748 uint8_t domain;
1749 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001750 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751
1752 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001753 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001754 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001756 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001757 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1758 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001759 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08001760 } else {
1761 qla_printk(KERN_WARNING, ha,
1762 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001763 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08001764 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 return (rval);
1766 }
1767
1768 if (topo == 4) {
1769 qla_printk(KERN_INFO, ha,
1770 "Cannot get topology - retrying.\n");
1771 return (QLA_FUNCTION_FAILED);
1772 }
1773
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001774 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775
1776 /* initialize */
1777 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1778 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001779 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780
1781 switch (topo) {
1782 case 0:
1783 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001784 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 ha->current_topology = ISP_CFG_NL;
1786 strcpy(connect_type, "(Loop)");
1787 break;
1788
1789 case 1:
1790 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001791 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001792 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 ha->current_topology = ISP_CFG_FL;
1794 strcpy(connect_type, "(FL_Port)");
1795 break;
1796
1797 case 2:
1798 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001799 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 ha->operating_mode = P2P;
1801 ha->current_topology = ISP_CFG_N;
1802 strcpy(connect_type, "(N_Port-to-N_Port)");
1803 break;
1804
1805 case 3:
1806 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001807 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001808 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 ha->operating_mode = P2P;
1810 ha->current_topology = ISP_CFG_F;
1811 strcpy(connect_type, "(F_Port)");
1812 break;
1813
1814 default:
1815 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1816 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001817 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 ha->current_topology = ISP_CFG_NL;
1819 strcpy(connect_type, "(Loop)");
1820 break;
1821 }
1822
1823 /* Save Host port and loop ID. */
1824 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001825 vha->d_id.b.domain = domain;
1826 vha->d_id.b.area = area;
1827 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001829 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 qla_printk(KERN_INFO, ha,
1831 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001832 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833
1834 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001835 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001837 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 }
1839
1840 return(rval);
1841}
1842
Giridhar Malavalia9083012010-04-12 17:59:55 -07001843inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001844qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1845 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001846{
1847 char *st, *en;
1848 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001849 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07001850 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavalia9083012010-04-12 17:59:55 -07001851 !IS_QLA8XXX_TYPE(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001852
1853 if (memcmp(model, BINZERO, len) != 0) {
1854 strncpy(ha->model_number, model, len);
1855 st = en = ha->model_number;
1856 en += len - 1;
1857 while (en > st) {
1858 if (*en != 0x20 && *en != 0x00)
1859 break;
1860 *en-- = '\0';
1861 }
1862
1863 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07001864 if (use_tbl &&
1865 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001866 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001867 strncpy(ha->model_desc,
1868 qla2x00_model_name[index * 2 + 1],
1869 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001870 } else {
1871 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07001872 if (use_tbl &&
1873 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001874 index < QLA_MODEL_NAMES) {
1875 strcpy(ha->model_number,
1876 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001877 strncpy(ha->model_desc,
1878 qla2x00_model_name[index * 2 + 1],
1879 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001880 } else {
1881 strcpy(ha->model_number, def);
1882 }
1883 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001884 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001885 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001886 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001887}
1888
David Miller4e08df32007-04-16 12:37:43 -07001889/* On sparc systems, obtain port and node WWN from firmware
1890 * properties.
1891 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001892static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07001893{
1894#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001895 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07001896 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07001897 struct device_node *dp = pci_device_to_OF_node(pdev);
1898 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07001899 int len;
1900
1901 val = of_get_property(dp, "port-wwn", &len);
1902 if (val && len >= WWN_SIZE)
1903 memcpy(nv->port_name, val, WWN_SIZE);
1904
1905 val = of_get_property(dp, "node-wwn", &len);
1906 if (val && len >= WWN_SIZE)
1907 memcpy(nv->node_name, val, WWN_SIZE);
1908#endif
1909}
1910
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911/*
1912* NVRAM configuration for ISP 2xxx
1913*
1914* Input:
1915* ha = adapter block pointer.
1916*
1917* Output:
1918* initialization control block in response_ring
1919* host adapters parameters in host adapter block
1920*
1921* Returns:
1922* 0 = success.
1923*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001924int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001925qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926{
David Miller4e08df32007-04-16 12:37:43 -07001927 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001928 uint8_t chksum = 0;
1929 uint16_t cnt;
1930 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001931 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001932 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07001933 nvram_t *nv = ha->nvram;
1934 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001935 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936
David Miller4e08df32007-04-16 12:37:43 -07001937 rval = QLA_SUCCESS;
1938
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001940 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 ha->nvram_base = 0;
1942 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1943 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
1944 ha->nvram_base = 0x80;
1945
1946 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001947 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001948 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1949 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001951 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07001952 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953
1954 /* Bad NVRAM data, set defaults parameters. */
1955 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1956 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1957 /* Reset NVRAM data. */
1958 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1959 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1960 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07001961 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1962 "invalid -- WWPN) defaults.\n");
1963
1964 /*
1965 * Set default initialization control block.
1966 */
1967 memset(nv, 0, ha->nvram_size);
1968 nv->parameter_block_version = ICB_VERSION;
1969
1970 if (IS_QLA23XX(ha)) {
1971 nv->firmware_options[0] = BIT_2 | BIT_1;
1972 nv->firmware_options[1] = BIT_7 | BIT_5;
1973 nv->add_firmware_options[0] = BIT_5;
1974 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1975 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1976 nv->special_options[1] = BIT_7;
1977 } else if (IS_QLA2200(ha)) {
1978 nv->firmware_options[0] = BIT_2 | BIT_1;
1979 nv->firmware_options[1] = BIT_7 | BIT_5;
1980 nv->add_firmware_options[0] = BIT_5;
1981 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1982 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1983 } else if (IS_QLA2100(ha)) {
1984 nv->firmware_options[0] = BIT_3 | BIT_1;
1985 nv->firmware_options[1] = BIT_5;
1986 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1987 }
1988
1989 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1990 nv->execution_throttle = __constant_cpu_to_le16(16);
1991 nv->retry_count = 8;
1992 nv->retry_delay = 1;
1993
1994 nv->port_name[0] = 33;
1995 nv->port_name[3] = 224;
1996 nv->port_name[4] = 139;
1997
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001998 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07001999
2000 nv->login_timeout = 4;
2001
2002 /*
2003 * Set default host adapter parameters
2004 */
2005 nv->host_p[1] = BIT_2;
2006 nv->reset_delay = 5;
2007 nv->port_down_retry_count = 8;
2008 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2009 nv->link_down_timeout = 60;
2010
2011 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 }
2013
2014#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2015 /*
2016 * The SN2 does not provide BIOS emulation which means you can't change
2017 * potentially bogus BIOS settings. Force the use of default settings
2018 * for link rate and frame size. Hope that the rest of the settings
2019 * are valid.
2020 */
2021 if (ia64_platform_is("sn2")) {
2022 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2023 if (IS_QLA23XX(ha))
2024 nv->special_options[1] = BIT_7;
2025 }
2026#endif
2027
2028 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002029 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030
2031 /*
2032 * Setup driver NVRAM options.
2033 */
2034 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2035 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2036 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2037 nv->firmware_options[1] &= ~BIT_4;
2038
2039 if (IS_QLA23XX(ha)) {
2040 nv->firmware_options[0] |= BIT_2;
2041 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002042 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043
2044 if (IS_QLA2300(ha)) {
2045 if (ha->fb_rev == FPM_2310) {
2046 strcpy(ha->model_number, "QLA2310");
2047 } else {
2048 strcpy(ha->model_number, "QLA2300");
2049 }
2050 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002051 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002052 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 }
2054 } else if (IS_QLA2200(ha)) {
2055 nv->firmware_options[0] |= BIT_2;
2056 /*
2057 * 'Point-to-point preferred, else loop' is not a safe
2058 * connection mode setting.
2059 */
2060 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2061 (BIT_5 | BIT_4)) {
2062 /* Force 'loop preferred, else point-to-point'. */
2063 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2064 nv->add_firmware_options[0] |= BIT_5;
2065 }
2066 strcpy(ha->model_number, "QLA22xx");
2067 } else /*if (IS_QLA2100(ha))*/ {
2068 strcpy(ha->model_number, "QLA2100");
2069 }
2070
2071 /*
2072 * Copy over NVRAM RISC parameter block to initialization control block.
2073 */
2074 dptr1 = (uint8_t *)icb;
2075 dptr2 = (uint8_t *)&nv->parameter_block_version;
2076 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2077 while (cnt--)
2078 *dptr1++ = *dptr2++;
2079
2080 /* Copy 2nd half. */
2081 dptr1 = (uint8_t *)icb->add_firmware_options;
2082 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2083 while (cnt--)
2084 *dptr1++ = *dptr2++;
2085
Andrew Vasquez5341e862006-05-17 15:09:16 -07002086 /* Use alternate WWN? */
2087 if (nv->host_p[1] & BIT_7) {
2088 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2089 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2090 }
2091
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 /* Prepare nodename */
2093 if ((icb->firmware_options[1] & BIT_6) == 0) {
2094 /*
2095 * Firmware will apply the following mask if the nodename was
2096 * not provided.
2097 */
2098 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2099 icb->node_name[0] &= 0xF0;
2100 }
2101
2102 /*
2103 * Set host adapter parameters.
2104 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002105 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07002106 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2108 /* Always load RISC code on non ISP2[12]00 chips. */
2109 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2110 ha->flags.disable_risc_code_load = 0;
2111 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2112 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2113 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002114 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002115 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116
2117 ha->operating_mode =
2118 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2119
2120 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2121 sizeof(ha->fw_seriallink_options));
2122
2123 /* save HBA serial number */
2124 ha->serial0 = icb->port_name[5];
2125 ha->serial1 = icb->port_name[6];
2126 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002127 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2128 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129
2130 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2131
2132 ha->retry_count = nv->retry_count;
2133
2134 /* Set minimum login_timeout to 4 seconds. */
2135 if (nv->login_timeout < ql2xlogintimeout)
2136 nv->login_timeout = ql2xlogintimeout;
2137 if (nv->login_timeout < 4)
2138 nv->login_timeout = 4;
2139 ha->login_timeout = nv->login_timeout;
2140 icb->login_timeout = nv->login_timeout;
2141
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002142 /* Set minimum RATOV to 100 tenths of a second. */
2143 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 ha->loop_reset_delay = nv->reset_delay;
2146
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 /* Link Down Timeout = 0:
2148 *
2149 * When Port Down timer expires we will start returning
2150 * I/O's to OS with "DID_NO_CONNECT".
2151 *
2152 * Link Down Timeout != 0:
2153 *
2154 * The driver waits for the link to come up after link down
2155 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002156 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 if (nv->link_down_timeout == 0) {
2158 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002159 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 } else {
2161 ha->link_down_timeout = nv->link_down_timeout;
2162 ha->loop_down_abort_time =
2163 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002164 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 /*
2167 * Need enough time to try and get the port back.
2168 */
2169 ha->port_down_retry_count = nv->port_down_retry_count;
2170 if (qlport_down_retry)
2171 ha->port_down_retry_count = qlport_down_retry;
2172 /* Set login_retry_count */
2173 ha->login_retry_count = nv->retry_count;
2174 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2175 ha->port_down_retry_count > 3)
2176 ha->login_retry_count = ha->port_down_retry_count;
2177 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2178 ha->login_retry_count = ha->port_down_retry_count;
2179 if (ql2xloginretrycount)
2180 ha->login_retry_count = ql2xloginretrycount;
2181
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 icb->lun_enables = __constant_cpu_to_le16(0);
2183 icb->command_resource_count = 0;
2184 icb->immediate_notify_resource_count = 0;
2185 icb->timeout = __constant_cpu_to_le16(0);
2186
2187 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2188 /* Enable RIO */
2189 icb->firmware_options[0] &= ~BIT_3;
2190 icb->add_firmware_options[0] &=
2191 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2192 icb->add_firmware_options[0] |= BIT_2;
2193 icb->response_accumulation_timer = 3;
2194 icb->interrupt_delay_timer = 5;
2195
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002196 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002198 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002199 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002200 ha->zio_mode = icb->add_firmware_options[0] &
2201 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2202 ha->zio_timer = icb->interrupt_delay_timer ?
2203 icb->interrupt_delay_timer: 2;
2204 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 icb->add_firmware_options[0] &=
2206 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002207 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002208 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002209 ha->zio_mode = QLA_ZIO_MODE_6;
2210
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002211 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002212 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002213 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002215 "ZIO mode %d enabled; timer delay (%d us).\n",
2216 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002218 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2219 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002220 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 }
2222 }
2223
David Miller4e08df32007-04-16 12:37:43 -07002224 if (rval) {
2225 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002226 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07002227 }
2228 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229}
2230
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002231static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002232qla2x00_rport_del(void *data)
2233{
2234 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002235 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002236
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002237 spin_lock_irq(fcport->vha->host->host_lock);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002238 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002239 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002240 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002241 if (rport)
2242 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002243}
2244
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245/**
2246 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2247 * @ha: HA context
2248 * @flags: allocation flags
2249 *
2250 * Returns a pointer to the allocated fcport, or NULL, if none available.
2251 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002252fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002253qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254{
2255 fc_port_t *fcport;
2256
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002257 fcport = kzalloc(sizeof(fc_port_t), flags);
2258 if (!fcport)
2259 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260
2261 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002262 fcport->vha = vha;
2263 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 fcport->port_type = FCT_UNKNOWN;
2265 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 atomic_set(&fcport->state, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002267 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002269 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270}
2271
2272/*
2273 * qla2x00_configure_loop
2274 * Updates Fibre Channel Device Database with what is actually on loop.
2275 *
2276 * Input:
2277 * ha = adapter block pointer.
2278 *
2279 * Returns:
2280 * 0 = success.
2281 * 1 = error.
2282 * 2 = database was full and device was not configured.
2283 */
2284static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002285qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286{
2287 int rval;
2288 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002289 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 rval = QLA_SUCCESS;
2291
2292 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002293 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2294 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 if (rval != QLA_SUCCESS) {
2296 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002297 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 return (rval);
2299 }
2300 }
2301
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002302 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002304 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305
2306 /*
2307 * If we have both an RSCN and PORT UPDATE pending then handle them
2308 * both at the same time.
2309 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002310 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2311 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312
Michael Hernandez3064ff32009-12-15 21:29:44 -08002313 qla2x00_get_data_rate(vha);
2314
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 /* Determine what we need to do */
2316 if (ha->current_topology == ISP_CFG_FL &&
2317 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2318
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002319 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 set_bit(RSCN_UPDATE, &flags);
2321
2322 } else if (ha->current_topology == ISP_CFG_F &&
2323 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2324
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002325 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 set_bit(RSCN_UPDATE, &flags);
2327 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2328
Andrew Vasquez21333b42006-05-17 15:09:56 -07002329 } else if (ha->current_topology == ISP_CFG_N) {
2330 clear_bit(RSCN_UPDATE, &flags);
2331
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002332 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2334
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002335 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 set_bit(RSCN_UPDATE, &flags);
2337 set_bit(LOCAL_LOOP_UPDATE, &flags);
2338 }
2339
2340 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002341 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002343 else
2344 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 }
2346
2347 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002348 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002350 else
2351 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 }
2353
2354 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002355 if (atomic_read(&vha->loop_down_timer) ||
2356 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 rval = QLA_FUNCTION_FAILED;
2358 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002359 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002361 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 }
2363 }
2364
2365 if (rval) {
2366 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002367 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 } else {
2369 DEBUG3(printk("%s: exiting normally\n", __func__));
2370 }
2371
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002372 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002373 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002375 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002376 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002377 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002378 vha->flags.rscn_queue_overflow = 1;
2379 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 }
2381
2382 return (rval);
2383}
2384
2385
2386
2387/*
2388 * qla2x00_configure_local_loop
2389 * Updates Fibre Channel Device Database with local loop devices.
2390 *
2391 * Input:
2392 * ha = adapter block pointer.
2393 *
2394 * Returns:
2395 * 0 = success.
2396 */
2397static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002398qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399{
2400 int rval, rval2;
2401 int found_devs;
2402 int found;
2403 fc_port_t *fcport, *new_fcport;
2404
2405 uint16_t index;
2406 uint16_t entries;
2407 char *id_iter;
2408 uint16_t loop_id;
2409 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002410 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411
2412 found_devs = 0;
2413 new_fcport = NULL;
2414 entries = MAX_FIBRE_DEVICES;
2415
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002416 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2417 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418
2419 /* Get list of logged in devices. */
2420 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002421 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 &entries);
2423 if (rval != QLA_SUCCESS)
2424 goto cleanup_allocation;
2425
2426 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07002427 vha->host_no, entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2429 entries * sizeof(struct gid_list_info)));
2430
2431 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002432 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 if (new_fcport == NULL) {
2434 rval = QLA_MEMORY_ALLOC_FAILED;
2435 goto cleanup_allocation;
2436 }
2437 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2438
2439 /*
2440 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2441 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002442 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2444 fcport->port_type != FCT_BROADCAST &&
2445 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2446
2447 DEBUG(printk("scsi(%ld): Marking port lost, "
2448 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002449 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450
2451 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 }
2453 }
2454
2455 /* Add devices to port list. */
2456 id_iter = (char *)ha->gid_list;
2457 for (index = 0; index < entries; index++) {
2458 domain = ((struct gid_list_info *)id_iter)->domain;
2459 area = ((struct gid_list_info *)id_iter)->area;
2460 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002461 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 loop_id = (uint16_t)
2463 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002464 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 loop_id = le16_to_cpu(
2466 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002467 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468
2469 /* Bypass reserved domain fields. */
2470 if ((domain & 0xf0) == 0xf0)
2471 continue;
2472
2473 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002474 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002475 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 continue;
2477
2478 /* Bypass invalid local loop ID. */
2479 if (loop_id > LAST_LOCAL_LOOP_ID)
2480 continue;
2481
2482 /* Fill in member data. */
2483 new_fcport->d_id.b.domain = domain;
2484 new_fcport->d_id.b.area = area;
2485 new_fcport->d_id.b.al_pa = al_pa;
2486 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002487 new_fcport->vp_idx = vha->vp_idx;
2488 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 if (rval2 != QLA_SUCCESS) {
2490 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2491 "information -- get_port_database=%x, "
2492 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002493 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002494 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002495 vha->host_no));
2496 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 continue;
2498 }
2499
2500 /* Check for matching device in port list. */
2501 found = 0;
2502 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002503 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 if (memcmp(new_fcport->port_name, fcport->port_name,
2505 WWN_SIZE))
2506 continue;
2507
Shyam Sundarddb9b122009-03-24 09:08:10 -07002508 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 fcport->loop_id = new_fcport->loop_id;
2510 fcport->port_type = new_fcport->port_type;
2511 fcport->d_id.b24 = new_fcport->d_id.b24;
2512 memcpy(fcport->node_name, new_fcport->node_name,
2513 WWN_SIZE);
2514
2515 found++;
2516 break;
2517 }
2518
2519 if (!found) {
2520 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002521 if (vha->vp_idx) {
2522 new_fcport->vha = vha;
2523 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002524 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002525 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526
2527 /* Allocate a new replacement fcport. */
2528 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002529 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 if (new_fcport == NULL) {
2531 rval = QLA_MEMORY_ALLOC_FAILED;
2532 goto cleanup_allocation;
2533 }
2534 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2535 }
2536
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002537 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002538 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002539
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002540 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541
2542 found_devs++;
2543 }
2544
2545cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002546 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547
2548 if (rval != QLA_SUCCESS) {
2549 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002550 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 }
2552
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 return (rval);
2554}
2555
2556static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002557qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002558{
2559#define LS_UNKNOWN 2
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002560 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2561 char *link_speed;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002562 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002563 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002564 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002565
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002566 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002567 return;
2568
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002569 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2570 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002571 return;
2572
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002573 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002574 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002575 if (rval != QLA_SUCCESS) {
2576 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2577 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002578 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002579 fcport->port_name[2], fcport->port_name[3],
2580 fcport->port_name[4], fcport->port_name[5],
2581 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002582 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002583 } else {
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002584 link_speed = link_speeds[LS_UNKNOWN];
2585 if (fcport->fp_speed < 5)
2586 link_speed = link_speeds[fcport->fp_speed];
2587 else if (fcport->fp_speed == 0x13)
2588 link_speed = link_speeds[5];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002589 DEBUG2(qla_printk(KERN_INFO, ha,
2590 "iIDMA adjusted to %s GB/s on "
2591 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002592 link_speed, fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002593 fcport->port_name[1], fcport->port_name[2],
2594 fcport->port_name[3], fcport->port_name[4],
2595 fcport->port_name[5], fcport->port_name[6],
2596 fcport->port_name[7]));
2597 }
2598}
2599
Adrian Bunk23be3312006-11-24 02:46:01 +01002600static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002601qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002602{
2603 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002604 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002605 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05002606
Andrew Vasquezac280b62009-08-20 11:06:05 -07002607 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002608
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002609 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2610 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002611 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2612 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2613 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002614 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002615 if (!rport) {
2616 qla_printk(KERN_WARNING, ha,
2617 "Unable to allocate fc remote port!\n");
2618 return;
2619 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002620 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002621 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002622 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002623
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002624 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002625
2626 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002627 if (fcport->port_type == FCT_INITIATOR)
2628 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2629 if (fcport->port_type == FCT_TARGET)
2630 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002631 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002632}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633
2634/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002635 * qla2x00_update_fcport
2636 * Updates device on list.
2637 *
2638 * Input:
2639 * ha = adapter block pointer.
2640 * fcport = port structure pointer.
2641 *
2642 * Return:
2643 * 0 - Success
2644 * BIT_0 - error
2645 *
2646 * Context:
2647 * Kernel context.
2648 */
2649void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002650qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002651{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002652 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002653
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002654 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002655 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002656 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002657 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002658 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002659 PORT_RETRY_TIME);
2660 fcport->flags &= ~FCF_LOGIN_NEEDED;
2661
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002662 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002663
2664 atomic_set(&fcport->state, FCS_ONLINE);
2665
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002666 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002667}
2668
2669/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 * qla2x00_configure_fabric
2671 * Setup SNS devices with loop ID's.
2672 *
2673 * Input:
2674 * ha = adapter block pointer.
2675 *
2676 * Returns:
2677 * 0 = success.
2678 * BIT_0 = error
2679 */
2680static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002681qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682{
2683 int rval, rval2;
2684 fc_port_t *fcport, *fcptemp;
2685 uint16_t next_loopid;
2686 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002687 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002689 struct qla_hw_data *ha = vha->hw;
2690 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691
2692 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002693 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002694 loop_id = NPH_F_PORT;
2695 else
2696 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002697 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 if (rval != QLA_SUCCESS) {
2699 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002700 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002702 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 return (QLA_SUCCESS);
2704 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002705 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706
2707 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002708 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 if (rval2 == QLA_RSCNS_HANDLED) {
2710 /* No point doing the scan, just continue. */
2711 return (QLA_SUCCESS);
2712 }
2713 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002714 /* FDMI support. */
2715 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002716 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2717 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002718
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002720 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002721 loop_id = NPH_SNS;
2722 else
2723 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002724 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002725 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 if (mb[0] != MBS_COMMAND_COMPLETE) {
2727 DEBUG2(qla_printk(KERN_INFO, ha,
2728 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002729 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 mb[0], mb[1], mb[2], mb[6], mb[7]));
2731 return (QLA_SUCCESS);
2732 }
2733
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002734 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2735 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 /* EMPTY */
2737 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002738 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002740 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741 /* EMPTY */
2742 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002743 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002745 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 /* EMPTY */
2747 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002748 "failed.\n", vha->host_no));
2749 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 /* EMPTY */
2751 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002752 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 }
2754 }
2755
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002756 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 if (rval != QLA_SUCCESS)
2758 break;
2759
2760 /*
2761 * Logout all previous fabric devices marked lost, except
Andrew Vasquezf08b7252010-01-12 12:59:48 -08002762 * FCP2 devices.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002764 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2765 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 break;
2767
2768 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2769 continue;
2770
2771 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002772 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002773 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08002775 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 fcport->port_type != FCT_INITIATOR &&
2777 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002778 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002779 fcport->loop_id,
2780 fcport->d_id.b.domain,
2781 fcport->d_id.b.area,
2782 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 fcport->loop_id = FC_NO_LOOP_ID;
2784 }
2785 }
2786 }
2787
2788 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002789 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790
2791 /*
2792 * Scan through our port list and login entries that need to be
2793 * logged in.
2794 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002795 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2796 if (atomic_read(&vha->loop_down_timer) ||
2797 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 break;
2799
2800 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2801 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2802 continue;
2803
2804 if (fcport->loop_id == FC_NO_LOOP_ID) {
2805 fcport->loop_id = next_loopid;
Seokmann Jud4486fd62008-04-03 13:13:28 -07002806 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002807 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808 if (rval != QLA_SUCCESS) {
2809 /* Ran out of IDs to use */
2810 break;
2811 }
2812 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002814 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 }
2816
2817 /* Exit if out of loop IDs. */
2818 if (rval != QLA_SUCCESS) {
2819 break;
2820 }
2821
2822 /*
2823 * Login and add the new devices to our port list.
2824 */
2825 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002826 if (atomic_read(&vha->loop_down_timer) ||
2827 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 break;
2829
2830 /* Find a new loop ID to use. */
2831 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002832 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833 if (rval != QLA_SUCCESS) {
2834 /* Ran out of IDs to use */
2835 break;
2836 }
2837
bdf79622005-04-17 15:06:53 -05002838 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002839 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002840
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002841 if (vha->vp_idx) {
2842 fcport->vha = vha;
2843 fcport->vp_idx = vha->vp_idx;
2844 }
2845 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 }
2847 } while (0);
2848
2849 /* Free all new device structures not processed. */
2850 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2851 list_del(&fcport->list);
2852 kfree(fcport);
2853 }
2854
2855 if (rval) {
2856 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002857 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 }
2859
2860 return (rval);
2861}
2862
2863
2864/*
2865 * qla2x00_find_all_fabric_devs
2866 *
2867 * Input:
2868 * ha = adapter block pointer.
2869 * dev = database device entry pointer.
2870 *
2871 * Returns:
2872 * 0 = success.
2873 *
2874 * Context:
2875 * Kernel context.
2876 */
2877static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002878qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2879 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880{
2881 int rval;
2882 uint16_t loop_id;
2883 fc_port_t *fcport, *new_fcport, *fcptemp;
2884 int found;
2885
2886 sw_info_t *swl;
2887 int swl_idx;
2888 int first_dev, last_dev;
2889 port_id_t wrap, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002890 struct qla_hw_data *ha = vha->hw;
2891 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002892 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893
2894 rval = QLA_SUCCESS;
2895
2896 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07002897 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002898 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 /*EMPTY*/
2900 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002901 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002903 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 kfree(swl);
2905 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002906 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 kfree(swl);
2908 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002909 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 kfree(swl);
2911 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07002912 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002913 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2914 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 }
2916 }
2917 swl_idx = 0;
2918
2919 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002920 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002922 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 return (QLA_MEMORY_ALLOC_FAILED);
2924 }
2925 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 /* Set start port ID scan at adapter ID. */
2927 first_dev = 1;
2928 last_dev = 0;
2929
2930 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002931 loop_id = ha->min_external_loopid;
2932 for (; loop_id <= ha->max_loop_id; loop_id++) {
2933 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 continue;
2935
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08002936 if (atomic_read(&vha->loop_down_timer) ||
2937 LOOP_TRANSITION(vha)) {
2938 atomic_set(&vha->loop_down_timer, 0);
2939 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2940 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08002942 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943
2944 if (swl != NULL) {
2945 if (last_dev) {
2946 wrap.b24 = new_fcport->d_id.b24;
2947 } else {
2948 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2949 memcpy(new_fcport->node_name,
2950 swl[swl_idx].node_name, WWN_SIZE);
2951 memcpy(new_fcport->port_name,
2952 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002953 memcpy(new_fcport->fabric_port_name,
2954 swl[swl_idx].fabric_port_name, WWN_SIZE);
2955 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956
2957 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2958 last_dev = 1;
2959 }
2960 swl_idx++;
2961 }
2962 } else {
2963 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002964 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 if (rval != QLA_SUCCESS) {
2966 qla_printk(KERN_WARNING, ha,
2967 "SNS scan failed -- assuming zero-entry "
2968 "result...\n");
2969 list_for_each_entry_safe(fcport, fcptemp,
2970 new_fcports, list) {
2971 list_del(&fcport->list);
2972 kfree(fcport);
2973 }
2974 rval = QLA_SUCCESS;
2975 break;
2976 }
2977 }
2978
2979 /* If wrap on switch device list, exit. */
2980 if (first_dev) {
2981 wrap.b24 = new_fcport->d_id.b24;
2982 first_dev = 0;
2983 } else if (new_fcport->d_id.b24 == wrap.b24) {
2984 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002985 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2987 break;
2988 }
2989
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002990 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002991 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 continue;
2993
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002994 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002995 found = 0;
2996 if (ha->num_vhosts) {
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002997 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002998 if (new_fcport->d_id.b24 == vp->d_id.b24) {
2999 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003000 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003001 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003002 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003003 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003004 continue;
3005 }
3006
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003007 /* Bypass if same domain and area of adapter. */
3008 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003009 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003010 ISP_CFG_FL)
3011 continue;
3012
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 /* Bypass reserved domain fields. */
3014 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3015 continue;
3016
3017 /* Locate matching device in database. */
3018 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003019 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 if (memcmp(new_fcport->port_name, fcport->port_name,
3021 WWN_SIZE))
3022 continue;
3023
3024 found++;
3025
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003026 /* Update port state. */
3027 memcpy(fcport->fabric_port_name,
3028 new_fcport->fabric_port_name, WWN_SIZE);
3029 fcport->fp_speed = new_fcport->fp_speed;
3030
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 /*
3032 * If address the same and state FCS_ONLINE, nothing
3033 * changed.
3034 */
3035 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3036 atomic_read(&fcport->state) == FCS_ONLINE) {
3037 break;
3038 }
3039
3040 /*
3041 * If device was not a fabric device before.
3042 */
3043 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3044 fcport->d_id.b24 = new_fcport->d_id.b24;
3045 fcport->loop_id = FC_NO_LOOP_ID;
3046 fcport->flags |= (FCF_FABRIC_DEVICE |
3047 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048 break;
3049 }
3050
3051 /*
3052 * Port ID changed or device was marked to be updated;
3053 * Log it out if still logged in and mark it for
3054 * relogin later.
3055 */
3056 fcport->d_id.b24 = new_fcport->d_id.b24;
3057 fcport->flags |= FCF_LOGIN_NEEDED;
3058 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003059 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 fcport->port_type != FCT_INITIATOR &&
3061 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003062 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003063 fcport->d_id.b.domain, fcport->d_id.b.area,
3064 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065 fcport->loop_id = FC_NO_LOOP_ID;
3066 }
3067
3068 break;
3069 }
3070
3071 if (found)
3072 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073 /* If device was not in our fcports list, then add it. */
3074 list_add_tail(&new_fcport->list, new_fcports);
3075
3076 /* Allocate a new replacement fcport. */
3077 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003078 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003080 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 return (QLA_MEMORY_ALLOC_FAILED);
3082 }
3083 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3084 new_fcport->d_id.b24 = nxt_d_id.b24;
3085 }
3086
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003087 kfree(swl);
3088 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 return (rval);
3091}
3092
3093/*
3094 * qla2x00_find_new_loop_id
3095 * Scan through our port list and find a new usable loop ID.
3096 *
3097 * Input:
3098 * ha: adapter state pointer.
3099 * dev: port structure pointer.
3100 *
3101 * Returns:
3102 * qla2x00 local function return status code.
3103 *
3104 * Context:
3105 * Kernel context.
3106 */
Adrian Bunk413975a2006-06-30 02:33:06 -07003107static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003108qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109{
3110 int rval;
3111 int found;
3112 fc_port_t *fcport;
3113 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003114 struct qla_hw_data *ha = vha->hw;
3115 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003116 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117
3118 rval = QLA_SUCCESS;
3119
3120 /* Save starting loop ID. */
3121 first_loop_id = dev->loop_id;
3122
3123 for (;;) {
3124 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003125 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127
3128 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003129 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131
3132 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003133 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134 /* first loop ID. */
3135 dev->loop_id = ha->min_external_loopid;
3136 }
3137
3138 /* Check for loop ID being already in use. */
3139 found = 0;
3140 fcport = NULL;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003141 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003142 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3143 if (fcport->loop_id == dev->loop_id &&
3144 fcport != dev) {
3145 /* ID possibly in use */
3146 found++;
3147 break;
3148 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003150 if (found)
3151 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 }
3153
3154 /* If not in use then it is free to use. */
3155 if (!found) {
3156 break;
3157 }
3158
3159 /* ID in use. Try next value. */
3160 dev->loop_id++;
3161
3162 /* If wrap around. No free ID to use. */
3163 if (dev->loop_id == first_loop_id) {
3164 dev->loop_id = FC_NO_LOOP_ID;
3165 rval = QLA_FUNCTION_FAILED;
3166 break;
3167 }
3168 }
3169
3170 return (rval);
3171}
3172
3173/*
3174 * qla2x00_device_resync
3175 * Marks devices in the database that needs resynchronization.
3176 *
3177 * Input:
3178 * ha = adapter block pointer.
3179 *
3180 * Context:
3181 * Kernel context.
3182 */
3183static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003184qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185{
3186 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 uint32_t mask;
3188 fc_port_t *fcport;
3189 uint32_t rscn_entry;
3190 uint8_t rscn_out_iter;
3191 uint8_t format;
3192 port_id_t d_id;
3193
3194 rval = QLA_RSCNS_HANDLED;
3195
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003196 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
3197 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003199 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200 format = MSB(MSW(rscn_entry));
3201 d_id.b.domain = LSB(MSW(rscn_entry));
3202 d_id.b.area = MSB(LSW(rscn_entry));
3203 d_id.b.al_pa = LSB(LSW(rscn_entry));
3204
3205 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3206 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003207 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208 d_id.b.area, d_id.b.al_pa));
3209
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003210 vha->rscn_out_ptr++;
3211 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
3212 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213
3214 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003215 for (rscn_out_iter = vha->rscn_out_ptr;
3216 !vha->flags.rscn_queue_overflow &&
3217 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218 rscn_out_iter = (rscn_out_iter ==
3219 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
3220
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003221 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 break;
3223
3224 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003225 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226 rscn_out_iter));
3227
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003228 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 }
3230
3231 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003232 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003234 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235
3236 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003237 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238 }
3239
3240 switch (format) {
3241 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242 mask = 0xffffff;
3243 break;
3244 case 1:
3245 mask = 0xffff00;
3246 break;
3247 case 2:
3248 mask = 0xff0000;
3249 break;
3250 default:
3251 mask = 0x0;
3252 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003253 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254 break;
3255 }
3256
3257 rval = QLA_SUCCESS;
3258
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003259 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3261 (fcport->d_id.b24 & mask) != d_id.b24 ||
3262 fcport->port_type == FCT_BROADCAST)
3263 continue;
3264
3265 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3266 if (format != 3 ||
3267 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003268 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003269 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270 }
3271 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 }
3273 }
3274 return (rval);
3275}
3276
3277/*
3278 * qla2x00_fabric_dev_login
3279 * Login fabric target device and update FC port database.
3280 *
3281 * Input:
3282 * ha: adapter state pointer.
3283 * fcport: port structure list pointer.
3284 * next_loopid: contains value of a new loop ID that can be used
3285 * by the next login attempt.
3286 *
3287 * Returns:
3288 * qla2x00 local function return status code.
3289 *
3290 * Context:
3291 * Kernel context.
3292 */
3293static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003294qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295 uint16_t *next_loopid)
3296{
3297 int rval;
3298 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003299 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003300 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301
3302 rval = QLA_SUCCESS;
3303 retry = 0;
3304
Andrew Vasquezac280b62009-08-20 11:06:05 -07003305 if (IS_ALOGIO_CAPABLE(ha)) {
3306 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3307 if (!rval)
3308 return rval;
3309 }
3310
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003311 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003313 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003314 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003315 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003316 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003317 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003319 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003320 fcport->d_id.b.domain, fcport->d_id.b.area,
3321 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003322 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003324 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325 }
3326 }
3327
3328 return (rval);
3329}
3330
3331/*
3332 * qla2x00_fabric_login
3333 * Issue fabric login command.
3334 *
3335 * Input:
3336 * ha = adapter block pointer.
3337 * device = pointer to FC device type structure.
3338 *
3339 * Returns:
3340 * 0 - Login successfully
3341 * 1 - Login failed
3342 * 2 - Initiator device
3343 * 3 - Fatal error
3344 */
3345int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003346qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003347 uint16_t *next_loopid)
3348{
3349 int rval;
3350 int retry;
3351 uint16_t tmp_loopid;
3352 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003353 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354
3355 retry = 0;
3356 tmp_loopid = 0;
3357
3358 for (;;) {
3359 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3360 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003361 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3363
3364 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003365 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 fcport->d_id.b.domain, fcport->d_id.b.area,
3367 fcport->d_id.b.al_pa, mb, BIT_0);
3368 if (mb[0] == MBS_PORT_ID_USED) {
3369 /*
3370 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003371 * recommends the driver perform an implicit login with
3372 * the specified ID again. The ID we just used is save
3373 * here so we return with an ID that can be tried by
3374 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375 */
3376 retry++;
3377 tmp_loopid = fcport->loop_id;
3378 fcport->loop_id = mb[1];
3379
3380 DEBUG(printk("Fabric Login: port in use - next "
3381 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3382 fcport->loop_id, fcport->d_id.b.domain,
3383 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3384
3385 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3386 /*
3387 * Login succeeded.
3388 */
3389 if (retry) {
3390 /* A retry occurred before. */
3391 *next_loopid = tmp_loopid;
3392 } else {
3393 /*
3394 * No retry occurred before. Just increment the
3395 * ID value for next login.
3396 */
3397 *next_loopid = (fcport->loop_id + 1);
3398 }
3399
3400 if (mb[1] & BIT_0) {
3401 fcport->port_type = FCT_INITIATOR;
3402 } else {
3403 fcport->port_type = FCT_TARGET;
3404 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003405 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406 }
3407 }
3408
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003409 if (mb[10] & BIT_0)
3410 fcport->supported_classes |= FC_COS_CLASS2;
3411 if (mb[10] & BIT_1)
3412 fcport->supported_classes |= FC_COS_CLASS3;
3413
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414 rval = QLA_SUCCESS;
3415 break;
3416 } else if (mb[0] == MBS_LOOP_ID_USED) {
3417 /*
3418 * Loop ID already used, try next loop ID.
3419 */
3420 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003421 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422 if (rval != QLA_SUCCESS) {
3423 /* Ran out of loop IDs to use */
3424 break;
3425 }
3426 } else if (mb[0] == MBS_COMMAND_ERROR) {
3427 /*
3428 * Firmware possibly timed out during login. If NO
3429 * retries are left to do then the device is declared
3430 * dead.
3431 */
3432 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003433 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003434 fcport->d_id.b.domain, fcport->d_id.b.area,
3435 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003436 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437
3438 rval = 1;
3439 break;
3440 } else {
3441 /*
3442 * unrecoverable / not handled error
3443 */
3444 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003445 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003446 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447 fcport->d_id.b.domain, fcport->d_id.b.area,
3448 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3449
3450 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003451 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003452 fcport->d_id.b.domain, fcport->d_id.b.area,
3453 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003455 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456
3457 rval = 3;
3458 break;
3459 }
3460 }
3461
3462 return (rval);
3463}
3464
3465/*
3466 * qla2x00_local_device_login
3467 * Issue local device login command.
3468 *
3469 * Input:
3470 * ha = adapter block pointer.
3471 * loop_id = loop id of device to login to.
3472 *
3473 * Returns (Where's the #define!!!!):
3474 * 0 - Login successfully
3475 * 1 - Login failed
3476 * 3 - Fatal error
3477 */
3478int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003479qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480{
3481 int rval;
3482 uint16_t mb[MAILBOX_REGISTER_COUNT];
3483
3484 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003485 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486 if (rval == QLA_SUCCESS) {
3487 /* Interrogate mailbox registers for any errors */
3488 if (mb[0] == MBS_COMMAND_ERROR)
3489 rval = 1;
3490 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3491 /* device not in PCB table */
3492 rval = 3;
3493 }
3494
3495 return (rval);
3496}
3497
3498/*
3499 * qla2x00_loop_resync
3500 * Resync with fibre channel devices.
3501 *
3502 * Input:
3503 * ha = adapter block pointer.
3504 *
3505 * Returns:
3506 * 0 = success
3507 */
3508int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003509qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003511 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003513 struct req_que *req;
3514 struct rsp_que *rsp;
3515
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003516 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003517 req = vha->hw->req_q_map[0];
3518 else
3519 req = vha->req;
3520 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003522 atomic_set(&vha->loop_state, LOOP_UPDATE);
3523 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3524 if (vha->flags.online) {
3525 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3527 wait_time = 256;
3528 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003529 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003531 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003532 qla2x00_marker(vha, req, rsp, 0, 0,
3533 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003534 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535
3536 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003537 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003538
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003539 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003541 } while (!atomic_read(&vha->loop_down_timer) &&
3542 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3543 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3544 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546 }
3547
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003548 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003551 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553
3554 return (rval);
3555}
3556
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557void
Andrew Vasquez67becc02009-08-25 11:36:20 -07003558qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003559{
3560 fc_port_t *fcport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003561 struct scsi_qla_host *tvp, *vha;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003562
3563 /* Go with deferred removal of rport references. */
Andrew Vasquez67becc02009-08-25 11:36:20 -07003564 list_for_each_entry_safe(vha, tvp, &base_vha->hw->vp_list, list)
3565 list_for_each_entry(fcport, &vha->vp_fcports, list)
3566 if (fcport && fcport->drport &&
3567 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
3568 qla2x00_rport_del(fcport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003569}
3570
Giridhar Malavalia9083012010-04-12 17:59:55 -07003571void
3572qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
3573{
3574 struct qla_hw_data *ha = vha->hw;
3575 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
3576 struct scsi_qla_host *tvp;
3577
3578 vha->flags.online = 0;
3579 ha->flags.chip_reset_done = 0;
3580 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3581 ha->qla_stats.total_isp_aborts++;
3582
3583 qla_printk(KERN_INFO, ha,
3584 "Performing ISP error recovery - ha= %p.\n", ha);
3585
3586 /* Chip reset does not apply to 82XX */
3587 if (!IS_QLA82XX(ha))
3588 ha->isp_ops->reset_chip(vha);
3589
3590 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3591 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3592 atomic_set(&vha->loop_state, LOOP_DOWN);
3593 qla2x00_mark_all_devices_lost(vha, 0);
3594 list_for_each_entry_safe(vp, tvp, &base_vha->hw->vp_list, list)
3595 qla2x00_mark_all_devices_lost(vp, 0);
3596 } else {
3597 if (!atomic_read(&vha->loop_down_timer))
3598 atomic_set(&vha->loop_down_timer,
3599 LOOP_DOWN_TIME);
3600 }
3601
3602 /* Make sure for ISP 82XX IO DMA is complete */
3603 if (IS_QLA82XX(ha))
3604 qla82xx_wait_for_pending_commands(vha);
3605
3606 /* Requeue all commands in outstanding command list. */
3607 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
3608}
3609
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610/*
3611* qla2x00_abort_isp
3612* Resets ISP and aborts all outstanding commands.
3613*
3614* Input:
3615* ha = adapter block pointer.
3616*
3617* Returns:
3618* 0 = success
3619*/
3620int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003621qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003622{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003623 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003625 struct qla_hw_data *ha = vha->hw;
3626 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003627 struct scsi_qla_host *tvp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003628 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003630 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003631 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632
Andrew Vasquez85880802009-12-15 21:29:46 -08003633 if (unlikely(pci_channel_offline(ha->pdev) &&
3634 ha->flags.pci_channel_io_perm_failure)) {
3635 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3636 status = 0;
3637 return status;
3638 }
3639
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003640 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003641
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003642 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003643
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003644 if (!qla2x00_restart_isp(vha)) {
3645 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003647 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648 /*
3649 * Issue marker command only when we are going
3650 * to start the I/O .
3651 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003652 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003653 }
3654
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003655 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003656
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003657 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003659 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003660 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003661
Lalit Chandivade29c53972009-10-13 15:16:47 -07003662 if (IS_QLA81XX(ha))
3663 qla2x00_get_fw_version(vha,
3664 &ha->fw_major_version,
3665 &ha->fw_minor_version,
3666 &ha->fw_subminor_version,
3667 &ha->fw_attributes, &ha->fw_memory_size,
3668 ha->mpi_version, &ha->mpi_capabilities,
3669 ha->phy_version);
3670
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003671 if (ha->fce) {
3672 ha->flags.fce_enabled = 1;
3673 memset(ha->fce, 0,
3674 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003675 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003676 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3677 &ha->fce_bufs);
3678 if (rval) {
3679 qla_printk(KERN_WARNING, ha,
3680 "Unable to reinitialize FCE "
3681 "(%d).\n", rval);
3682 ha->flags.fce_enabled = 0;
3683 }
3684 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003685
3686 if (ha->eft) {
3687 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003688 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003689 ha->eft_dma, EFT_NUM_BUFFERS);
3690 if (rval) {
3691 qla_printk(KERN_WARNING, ha,
3692 "Unable to reinitialize EFT "
3693 "(%d).\n", rval);
3694 }
3695 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003697 vha->flags.online = 1;
3698 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003699 if (ha->isp_abort_cnt == 0) {
3700 qla_printk(KERN_WARNING, ha,
3701 "ISP error recovery failed - "
3702 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003703 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704 * The next call disables the board
3705 * completely.
3706 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003707 ha->isp_ops->reset_adapter(vha);
3708 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003710 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711 status = 0;
3712 } else { /* schedule another ISP abort */
3713 ha->isp_abort_cnt--;
3714 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003715 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003716 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003717 status = 1;
3718 }
3719 } else {
3720 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3721 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3722 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003723 vha->host_no, ha->isp_abort_cnt));
3724 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003725 status = 1;
3726 }
3727 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003728
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729 }
3730
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003731 if (!status) {
3732 DEBUG(printk(KERN_INFO
3733 "qla2x00_abort_isp(%ld): succeeded.\n",
3734 vha->host_no));
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003735 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003736 if (vp->vp_idx)
3737 qla2x00_vp_abort_isp(vp);
3738 }
3739 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003740 qla_printk(KERN_INFO, ha,
3741 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742 }
3743
3744 return(status);
3745}
3746
3747/*
3748* qla2x00_restart_isp
3749* restarts the ISP after a reset
3750*
3751* Input:
3752* ha = adapter block pointer.
3753*
3754* Returns:
3755* 0 = success
3756*/
3757static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003758qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003760 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003762 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003763 struct req_que *req = ha->req_q_map[0];
3764 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765
3766 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003767 if (qla2x00_isp_firmware(vha)) {
3768 vha->flags.online = 0;
3769 status = ha->isp_ops->chip_diag(vha);
3770 if (!status)
3771 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772 }
3773
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003774 if (!status && !(status = qla2x00_init_rings(vha))) {
3775 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07003776 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003777 /* Initialize the queues in use */
3778 qla25xx_init_queues(ha);
3779
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003780 status = qla2x00_fw_ready(vha);
3781 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003783 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003784
3785 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003786 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003787
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003788 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3790 wait_time = 256;
3791 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003792 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3793 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003795 } while (!atomic_read(&vha->loop_down_timer) &&
3796 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3797 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3798 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003799 }
3800
3801 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003802 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803 status = 0;
3804
3805 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3806 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003807 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808 }
3809 return (status);
3810}
3811
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003812static int
3813qla25xx_init_queues(struct qla_hw_data *ha)
3814{
3815 struct rsp_que *rsp = NULL;
3816 struct req_que *req = NULL;
3817 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3818 int ret = -1;
3819 int i;
3820
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003821 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003822 rsp = ha->rsp_q_map[i];
3823 if (rsp) {
3824 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003825 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003826 if (ret != QLA_SUCCESS)
3827 DEBUG2_17(printk(KERN_WARNING
3828 "%s Rsp que:%d init failed\n", __func__,
3829 rsp->id));
3830 else
3831 DEBUG2_17(printk(KERN_INFO
3832 "%s Rsp que:%d inited\n", __func__,
3833 rsp->id));
3834 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003835 }
3836 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003837 req = ha->req_q_map[i];
3838 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003839 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003840 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003841 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003842 if (ret != QLA_SUCCESS)
3843 DEBUG2_17(printk(KERN_WARNING
3844 "%s Req que:%d init failed\n", __func__,
3845 req->id));
3846 else
3847 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003848 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003849 req->id));
3850 }
3851 }
3852 return ret;
3853}
3854
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855/*
3856* qla2x00_reset_adapter
3857* Reset adapter.
3858*
3859* Input:
3860* ha = adapter block pointer.
3861*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003862void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003863qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864{
3865 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003866 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003867 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003869 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003870 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872 spin_lock_irqsave(&ha->hardware_lock, flags);
3873 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3874 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3875 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3876 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3877 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3878}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003879
3880void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003881qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003882{
3883 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003884 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003885 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3886
Giridhar Malavalia9083012010-04-12 17:59:55 -07003887 if (IS_QLA82XX(ha))
3888 return;
3889
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003890 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003891 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003892
3893 spin_lock_irqsave(&ha->hardware_lock, flags);
3894 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3895 RD_REG_DWORD(&reg->hccr);
3896 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3897 RD_REG_DWORD(&reg->hccr);
3898 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08003899
3900 if (IS_NOPOLLING_TYPE(ha))
3901 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003902}
3903
David Miller4e08df32007-04-16 12:37:43 -07003904/* On sparc systems, obtain port and node WWN from firmware
3905 * properties.
3906 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003907static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3908 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07003909{
3910#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003911 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003912 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003913 struct device_node *dp = pci_device_to_OF_node(pdev);
3914 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003915 int len;
3916
3917 val = of_get_property(dp, "port-wwn", &len);
3918 if (val && len >= WWN_SIZE)
3919 memcpy(nv->port_name, val, WWN_SIZE);
3920
3921 val = of_get_property(dp, "node-wwn", &len);
3922 if (val && len >= WWN_SIZE)
3923 memcpy(nv->node_name, val, WWN_SIZE);
3924#endif
3925}
3926
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003927int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003928qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003929{
David Miller4e08df32007-04-16 12:37:43 -07003930 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003931 struct init_cb_24xx *icb;
3932 struct nvram_24xx *nv;
3933 uint32_t *dptr;
3934 uint8_t *dptr1, *dptr2;
3935 uint32_t chksum;
3936 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003937 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003938
David Miller4e08df32007-04-16 12:37:43 -07003939 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003940 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003941 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003942
3943 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07003944 if (ha->flags.port0) {
3945 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3946 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3947 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003948 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003949 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3950 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07003951 ha->nvram_size = sizeof(struct nvram_24xx);
3952 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003953 if (IS_QLA82XX(ha))
3954 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003955
Seokmann Ju281afe12007-07-26 13:43:34 -07003956 /* Get VPD data into cache */
3957 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003958 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07003959 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3960
3961 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003962 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003963 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003964 ha->nvram_size);
3965 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3966 chksum += le32_to_cpu(*dptr++);
3967
Andrew Vasquez76403352009-04-06 22:33:39 -07003968 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07003969 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003970
3971 /* Bad NVRAM data, set defaults parameters. */
3972 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3973 || nv->id[3] != ' ' ||
3974 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3975 /* Reset NVRAM data. */
3976 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3977 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3978 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07003979 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3980 "invalid -- WWPN) defaults.\n");
3981
3982 /*
3983 * Set default initialization control block.
3984 */
3985 memset(nv, 0, ha->nvram_size);
3986 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3987 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3988 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3989 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3990 nv->exchange_count = __constant_cpu_to_le16(0);
3991 nv->hard_address = __constant_cpu_to_le16(124);
3992 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07003993 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07003994 nv->port_name[2] = 0x00;
3995 nv->port_name[3] = 0xe0;
3996 nv->port_name[4] = 0x8b;
3997 nv->port_name[5] = 0x1c;
3998 nv->port_name[6] = 0x55;
3999 nv->port_name[7] = 0x86;
4000 nv->node_name[0] = 0x20;
4001 nv->node_name[1] = 0x00;
4002 nv->node_name[2] = 0x00;
4003 nv->node_name[3] = 0xe0;
4004 nv->node_name[4] = 0x8b;
4005 nv->node_name[5] = 0x1c;
4006 nv->node_name[6] = 0x55;
4007 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004008 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004009 nv->login_retry_count = __constant_cpu_to_le16(8);
4010 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4011 nv->login_timeout = __constant_cpu_to_le16(0);
4012 nv->firmware_options_1 =
4013 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4014 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4015 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4016 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4017 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4018 nv->efi_parameters = __constant_cpu_to_le32(0);
4019 nv->reset_delay = 5;
4020 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4021 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4022 nv->link_down_timeout = __constant_cpu_to_le16(30);
4023
4024 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004025 }
4026
4027 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004028 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004029
4030 /* Copy 1st segment. */
4031 dptr1 = (uint8_t *)icb;
4032 dptr2 = (uint8_t *)&nv->version;
4033 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4034 while (cnt--)
4035 *dptr1++ = *dptr2++;
4036
4037 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07004038 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004039
4040 /* Copy 2nd segment. */
4041 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4042 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4043 cnt = (uint8_t *)&icb->reserved_3 -
4044 (uint8_t *)&icb->interrupt_delay_timer;
4045 while (cnt--)
4046 *dptr1++ = *dptr2++;
4047
4048 /*
4049 * Setup driver NVRAM options.
4050 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004051 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004052 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004053
Andrew Vasquez5341e862006-05-17 15:09:16 -07004054 /* Use alternate WWN? */
4055 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4056 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4057 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4058 }
4059
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004060 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004061 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004062 /*
4063 * Firmware will apply the following mask if the nodename was
4064 * not provided.
4065 */
4066 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4067 icb->node_name[0] &= 0xF0;
4068 }
4069
4070 /* Set host adapter parameters. */
4071 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08004072 ha->flags.enable_lip_reset = 0;
4073 ha->flags.enable_lip_full_login =
4074 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4075 ha->flags.enable_target_reset =
4076 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004077 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004078 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004079
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004080 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4081 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004082
4083 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4084 sizeof(ha->fw_seriallink_options24));
4085
4086 /* save HBA serial number */
4087 ha->serial0 = icb->port_name[5];
4088 ha->serial1 = icb->port_name[6];
4089 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004090 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4091 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004092
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08004093 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4094
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004095 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4096
4097 /* Set minimum login_timeout to 4 seconds. */
4098 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4099 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4100 if (le16_to_cpu(nv->login_timeout) < 4)
4101 nv->login_timeout = __constant_cpu_to_le16(4);
4102 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07004103 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004104
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004105 /* Set minimum RATOV to 100 tenths of a second. */
4106 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004107
4108 ha->loop_reset_delay = nv->reset_delay;
4109
4110 /* Link Down Timeout = 0:
4111 *
4112 * When Port Down timer expires we will start returning
4113 * I/O's to OS with "DID_NO_CONNECT".
4114 *
4115 * Link Down Timeout != 0:
4116 *
4117 * The driver waits for the link to come up after link down
4118 * before returning I/Os to OS with "DID_NO_CONNECT".
4119 */
4120 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4121 ha->loop_down_abort_time =
4122 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4123 } else {
4124 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4125 ha->loop_down_abort_time =
4126 (LOOP_DOWN_TIME - ha->link_down_timeout);
4127 }
4128
4129 /* Need enough time to try and get the port back. */
4130 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4131 if (qlport_down_retry)
4132 ha->port_down_retry_count = qlport_down_retry;
4133
4134 /* Set login_retry_count */
4135 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4136 if (ha->port_down_retry_count ==
4137 le16_to_cpu(nv->port_down_retry_count) &&
4138 ha->port_down_retry_count > 3)
4139 ha->login_retry_count = ha->port_down_retry_count;
4140 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4141 ha->login_retry_count = ha->port_down_retry_count;
4142 if (ql2xloginretrycount)
4143 ha->login_retry_count = ql2xloginretrycount;
4144
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004145 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004146 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004147 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4148 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4149 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4150 le16_to_cpu(icb->interrupt_delay_timer): 2;
4151 }
4152 icb->firmware_options_2 &= __constant_cpu_to_le32(
4153 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004154 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004155 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004156 ha->zio_mode = QLA_ZIO_MODE_6;
4157
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004158 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004159 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004160 ha->zio_timer * 100));
4161 qla_printk(KERN_INFO, ha,
4162 "ZIO mode %d enabled; timer delay (%d us).\n",
4163 ha->zio_mode, ha->zio_timer * 100);
4164
4165 icb->firmware_options_2 |= cpu_to_le32(
4166 (uint32_t)ha->zio_mode);
4167 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004168 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004169 }
4170
David Miller4e08df32007-04-16 12:37:43 -07004171 if (rval) {
4172 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004173 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07004174 }
4175 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004176}
4177
Adrian Bunk413975a2006-06-30 02:33:06 -07004178static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004179qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4180 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004181{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004182 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004183 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004184 uint32_t *dcode, dlen;
4185 uint32_t risc_addr;
4186 uint32_t risc_size;
4187 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004188 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004189 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004190
4191 qla_printk(KERN_INFO, ha,
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004192 "FW: Loading from flash (%x)...\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004193
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004194 rval = QLA_SUCCESS;
4195
4196 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004197 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004198 *srisc_addr = 0;
4199
4200 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004201 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004202 for (i = 0; i < 4; i++)
4203 dcode[i] = be32_to_cpu(dcode[i]);
4204 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4205 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4206 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4207 dcode[3] == 0)) {
4208 qla_printk(KERN_WARNING, ha,
4209 "Unable to verify integrity of flash firmware image!\n");
4210 qla_printk(KERN_WARNING, ha,
4211 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4212 dcode[1], dcode[2], dcode[3]);
4213
4214 return QLA_FUNCTION_FAILED;
4215 }
4216
4217 while (segments && rval == QLA_SUCCESS) {
4218 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004219 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004220
4221 risc_addr = be32_to_cpu(dcode[2]);
4222 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4223 risc_size = be32_to_cpu(dcode[3]);
4224
4225 fragment = 0;
4226 while (risc_size > 0 && rval == QLA_SUCCESS) {
4227 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4228 if (dlen > risc_size)
4229 dlen = risc_size;
4230
4231 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4232 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004233 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004234
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004235 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004236 for (i = 0; i < dlen; i++)
4237 dcode[i] = swab32(dcode[i]);
4238
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004239 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004240 dlen);
4241 if (rval) {
4242 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004243 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004244 fragment));
4245 qla_printk(KERN_WARNING, ha,
4246 "[ERROR] Failed to load segment %d of "
4247 "firmware\n", fragment);
4248 break;
4249 }
4250
4251 faddr += dlen;
4252 risc_addr += dlen;
4253 risc_size -= dlen;
4254 fragment++;
4255 }
4256
4257 /* Next segment. */
4258 segments--;
4259 }
4260
4261 return rval;
4262}
4263
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004264#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4265
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004266int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004267qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08004268{
4269 int rval;
4270 int i, fragment;
4271 uint16_t *wcode, *fwcode;
4272 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4273 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004274 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004275 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08004276
4277 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004278 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004279 if (!blob) {
4280 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004281 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4282 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08004283 return QLA_FUNCTION_FAILED;
4284 }
4285
4286 rval = QLA_SUCCESS;
4287
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004288 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08004289 *srisc_addr = 0;
4290 fwcode = (uint16_t *)blob->fw->data;
4291 fwclen = 0;
4292
4293 /* Validate firmware image by checking version. */
4294 if (blob->fw->size < 8 * sizeof(uint16_t)) {
4295 qla_printk(KERN_WARNING, ha,
4296 "Unable to verify integrity of firmware image (%Zd)!\n",
4297 blob->fw->size);
4298 goto fail_fw_integrity;
4299 }
4300 for (i = 0; i < 4; i++)
4301 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4302 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4303 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4304 wcode[2] == 0 && wcode[3] == 0)) {
4305 qla_printk(KERN_WARNING, ha,
4306 "Unable to verify integrity of firmware image!\n");
4307 qla_printk(KERN_WARNING, ha,
4308 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
4309 wcode[1], wcode[2], wcode[3]);
4310 goto fail_fw_integrity;
4311 }
4312
4313 seg = blob->segs;
4314 while (*seg && rval == QLA_SUCCESS) {
4315 risc_addr = *seg;
4316 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4317 risc_size = be16_to_cpu(fwcode[3]);
4318
4319 /* Validate firmware image size. */
4320 fwclen += risc_size * sizeof(uint16_t);
4321 if (blob->fw->size < fwclen) {
4322 qla_printk(KERN_WARNING, ha,
4323 "Unable to verify integrity of firmware image "
4324 "(%Zd)!\n", blob->fw->size);
4325 goto fail_fw_integrity;
4326 }
4327
4328 fragment = 0;
4329 while (risc_size > 0 && rval == QLA_SUCCESS) {
4330 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4331 if (wlen > risc_size)
4332 wlen = risc_size;
4333
4334 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004335 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004336 risc_addr, wlen));
4337
4338 for (i = 0; i < wlen; i++)
4339 wcode[i] = swab16(fwcode[i]);
4340
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004341 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004342 wlen);
4343 if (rval) {
4344 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004345 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004346 fragment));
4347 qla_printk(KERN_WARNING, ha,
4348 "[ERROR] Failed to load segment %d of "
4349 "firmware\n", fragment);
4350 break;
4351 }
4352
4353 fwcode += wlen;
4354 risc_addr += wlen;
4355 risc_size -= wlen;
4356 fragment++;
4357 }
4358
4359 /* Next segment. */
4360 seg++;
4361 }
4362 return rval;
4363
4364fail_fw_integrity:
4365 return QLA_FUNCTION_FAILED;
4366}
4367
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004368static int
4369qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004370{
4371 int rval;
4372 int segments, fragment;
4373 uint32_t *dcode, dlen;
4374 uint32_t risc_addr;
4375 uint32_t risc_size;
4376 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004377 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004378 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004379 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004380 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004381
Andrew Vasquez54333832005-11-09 15:49:04 -08004382 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004383 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004384 if (!blob) {
4385 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004386 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4387 "from: " QLA_FW_URL ".\n");
4388
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004389 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004390 }
4391
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004392 qla_printk(KERN_INFO, ha,
4393 "FW: Loading via request-firmware...\n");
4394
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004395 rval = QLA_SUCCESS;
4396
4397 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004398 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004399 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004400 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004401 fwclen = 0;
4402
4403 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004404 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004405 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004406 "Unable to verify integrity of firmware image (%Zd)!\n",
4407 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004408 goto fail_fw_integrity;
4409 }
4410 for (i = 0; i < 4; i++)
4411 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4412 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4413 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4414 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4415 dcode[3] == 0)) {
4416 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004417 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004418 qla_printk(KERN_WARNING, ha,
4419 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4420 dcode[1], dcode[2], dcode[3]);
4421 goto fail_fw_integrity;
4422 }
4423
4424 while (segments && rval == QLA_SUCCESS) {
4425 risc_addr = be32_to_cpu(fwcode[2]);
4426 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4427 risc_size = be32_to_cpu(fwcode[3]);
4428
4429 /* Validate firmware image size. */
4430 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004431 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004432 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004433 "Unable to verify integrity of firmware image "
4434 "(%Zd)!\n", blob->fw->size);
4435
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004436 goto fail_fw_integrity;
4437 }
4438
4439 fragment = 0;
4440 while (risc_size > 0 && rval == QLA_SUCCESS) {
4441 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4442 if (dlen > risc_size)
4443 dlen = risc_size;
4444
4445 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004446 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004447 risc_addr, dlen));
4448
4449 for (i = 0; i < dlen; i++)
4450 dcode[i] = swab32(fwcode[i]);
4451
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004452 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004453 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004454 if (rval) {
4455 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004456 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004457 fragment));
4458 qla_printk(KERN_WARNING, ha,
4459 "[ERROR] Failed to load segment %d of "
4460 "firmware\n", fragment);
4461 break;
4462 }
4463
4464 fwcode += dlen;
4465 risc_addr += dlen;
4466 risc_size -= dlen;
4467 fragment++;
4468 }
4469
4470 /* Next segment. */
4471 segments--;
4472 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004473 return rval;
4474
4475fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004476 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004477}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004478
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004479int
4480qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4481{
4482 int rval;
4483
Andrew Vasqueze337d902009-04-06 22:33:49 -07004484 if (ql2xfwloadbin == 1)
4485 return qla81xx_load_risc(vha, srisc_addr);
4486
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004487 /*
4488 * FW Load priority:
4489 * 1) Firmware via request-firmware interface (.bin file).
4490 * 2) Firmware residing in flash.
4491 */
4492 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4493 if (rval == QLA_SUCCESS)
4494 return rval;
4495
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004496 return qla24xx_load_risc_flash(vha, srisc_addr,
4497 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004498}
4499
4500int
4501qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4502{
4503 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004504 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004505
Andrew Vasqueze337d902009-04-06 22:33:49 -07004506 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004507 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07004508
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004509 /*
4510 * FW Load priority:
4511 * 1) Firmware residing in flash.
4512 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004513 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004514 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004515 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004516 if (rval == QLA_SUCCESS)
4517 return rval;
4518
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004519try_blob_fw:
4520 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4521 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4522 return rval;
4523
4524 qla_printk(KERN_ERR, ha,
4525 "FW: Attempting to fallback to golden firmware...\n");
4526 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4527 if (rval != QLA_SUCCESS)
4528 return rval;
4529
4530 qla_printk(KERN_ERR, ha,
4531 "FW: Please update operational firmware...\n");
4532 ha->flags.running_gold_fw = 1;
4533
4534 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004535}
4536
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004537void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004538qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004539{
4540 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004541 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004542
Andrew Vasquez85880802009-12-15 21:29:46 -08004543 if (ha->flags.pci_channel_io_perm_failure)
4544 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07004545 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004546 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004547 if (!ha->fw_major_version)
4548 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004549
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004550 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004551 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07004552 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004553 ha->isp_ops->reset_chip(vha);
4554 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004555 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004556 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004557 continue;
4558 qla_printk(KERN_INFO, ha,
4559 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004560 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004561 }
4562}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004563
4564int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004565qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004566{
4567 int rval = QLA_SUCCESS;
4568 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004569 struct qla_hw_data *ha = vha->hw;
4570 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004571 struct req_que *req;
4572 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004573
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004574 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004575 return -EINVAL;
4576
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004577 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004578 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004579 req = ha->req_q_map[0];
4580 else
4581 req = vha->req;
4582 rsp = req->rsp;
4583
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004584 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004585 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004586 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004587 }
4588
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004589 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004590
4591 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004592 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004593 if (mb[0] != MBS_COMMAND_COMPLETE) {
4594 DEBUG15(qla_printk(KERN_INFO, ha,
4595 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4596 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4597 mb[0], mb[1], mb[2], mb[6], mb[7]));
4598 return (QLA_FUNCTION_FAILED);
4599 }
4600
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004601 atomic_set(&vha->loop_down_timer, 0);
4602 atomic_set(&vha->loop_state, LOOP_UP);
4603 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4604 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4605 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004606
4607 return rval;
4608}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004609
4610/* 84XX Support **************************************************************/
4611
4612static LIST_HEAD(qla_cs84xx_list);
4613static DEFINE_MUTEX(qla_cs84xx_mutex);
4614
4615static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004616qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004617{
4618 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004619 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004620
4621 mutex_lock(&qla_cs84xx_mutex);
4622
4623 /* Find any shared 84xx chip. */
4624 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4625 if (cs84xx->bus == ha->pdev->bus) {
4626 kref_get(&cs84xx->kref);
4627 goto done;
4628 }
4629 }
4630
4631 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4632 if (!cs84xx)
4633 goto done;
4634
4635 kref_init(&cs84xx->kref);
4636 spin_lock_init(&cs84xx->access_lock);
4637 mutex_init(&cs84xx->fw_update_mutex);
4638 cs84xx->bus = ha->pdev->bus;
4639
4640 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4641done:
4642 mutex_unlock(&qla_cs84xx_mutex);
4643 return cs84xx;
4644}
4645
4646static void
4647__qla84xx_chip_release(struct kref *kref)
4648{
4649 struct qla_chip_state_84xx *cs84xx =
4650 container_of(kref, struct qla_chip_state_84xx, kref);
4651
4652 mutex_lock(&qla_cs84xx_mutex);
4653 list_del(&cs84xx->list);
4654 mutex_unlock(&qla_cs84xx_mutex);
4655 kfree(cs84xx);
4656}
4657
4658void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004659qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004660{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004661 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004662 if (ha->cs84xx)
4663 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4664}
4665
4666static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004667qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004668{
4669 int rval;
4670 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004671 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004672
4673 mutex_lock(&ha->cs84xx->fw_update_mutex);
4674
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004675 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004676
4677 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4678
4679 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4680 QLA_SUCCESS;
4681}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004682
4683/* 81XX Support **************************************************************/
4684
4685int
4686qla81xx_nvram_config(scsi_qla_host_t *vha)
4687{
4688 int rval;
4689 struct init_cb_81xx *icb;
4690 struct nvram_81xx *nv;
4691 uint32_t *dptr;
4692 uint8_t *dptr1, *dptr2;
4693 uint32_t chksum;
4694 uint16_t cnt;
4695 struct qla_hw_data *ha = vha->hw;
4696
4697 rval = QLA_SUCCESS;
4698 icb = (struct init_cb_81xx *)ha->init_cb;
4699 nv = ha->nvram;
4700
4701 /* Determine NVRAM starting address. */
4702 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004703 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004704
4705 /* Get VPD data into cache */
4706 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004707 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
4708 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004709
4710 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004711 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004712 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004713 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004714 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4715 chksum += le32_to_cpu(*dptr++);
4716
Andrew Vasquez76403352009-04-06 22:33:39 -07004717 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004718 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4719
4720 /* Bad NVRAM data, set defaults parameters. */
4721 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4722 || nv->id[3] != ' ' ||
4723 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4724 /* Reset NVRAM data. */
4725 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4726 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4727 le16_to_cpu(nv->nvram_version));
4728 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4729 "invalid -- WWPN) defaults.\n");
4730
4731 /*
4732 * Set default initialization control block.
4733 */
4734 memset(nv, 0, ha->nvram_size);
4735 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4736 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4737 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4738 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4739 nv->exchange_count = __constant_cpu_to_le16(0);
4740 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004741 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004742 nv->port_name[2] = 0x00;
4743 nv->port_name[3] = 0xe0;
4744 nv->port_name[4] = 0x8b;
4745 nv->port_name[5] = 0x1c;
4746 nv->port_name[6] = 0x55;
4747 nv->port_name[7] = 0x86;
4748 nv->node_name[0] = 0x20;
4749 nv->node_name[1] = 0x00;
4750 nv->node_name[2] = 0x00;
4751 nv->node_name[3] = 0xe0;
4752 nv->node_name[4] = 0x8b;
4753 nv->node_name[5] = 0x1c;
4754 nv->node_name[6] = 0x55;
4755 nv->node_name[7] = 0x86;
4756 nv->login_retry_count = __constant_cpu_to_le16(8);
4757 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4758 nv->login_timeout = __constant_cpu_to_le16(0);
4759 nv->firmware_options_1 =
4760 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4761 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4762 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4763 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4764 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4765 nv->efi_parameters = __constant_cpu_to_le32(0);
4766 nv->reset_delay = 5;
4767 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4768 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4769 nv->link_down_timeout = __constant_cpu_to_le16(30);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07004770 nv->enode_mac[0] = 0x00;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004771 nv->enode_mac[1] = 0x02;
4772 nv->enode_mac[2] = 0x03;
4773 nv->enode_mac[3] = 0x04;
4774 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004775 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004776
4777 rval = 1;
4778 }
4779
4780 /* Reset Initialization control block */
4781 memset(icb, 0, sizeof(struct init_cb_81xx));
4782
4783 /* Copy 1st segment. */
4784 dptr1 = (uint8_t *)icb;
4785 dptr2 = (uint8_t *)&nv->version;
4786 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4787 while (cnt--)
4788 *dptr1++ = *dptr2++;
4789
4790 icb->login_retry_count = nv->login_retry_count;
4791
4792 /* Copy 2nd segment. */
4793 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4794 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4795 cnt = (uint8_t *)&icb->reserved_5 -
4796 (uint8_t *)&icb->interrupt_delay_timer;
4797 while (cnt--)
4798 *dptr1++ = *dptr2++;
4799
4800 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
4801 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4802 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
4803 icb->enode_mac[0] = 0x01;
4804 icb->enode_mac[1] = 0x02;
4805 icb->enode_mac[2] = 0x03;
4806 icb->enode_mac[3] = 0x04;
4807 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004808 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004809 }
4810
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004811 /* Use extended-initialization control block. */
4812 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
4813
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004814 /*
4815 * Setup driver NVRAM options.
4816 */
4817 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07004818 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004819
4820 /* Use alternate WWN? */
4821 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4822 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4823 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4824 }
4825
4826 /* Prepare nodename */
4827 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4828 /*
4829 * Firmware will apply the following mask if the nodename was
4830 * not provided.
4831 */
4832 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4833 icb->node_name[0] &= 0xF0;
4834 }
4835
4836 /* Set host adapter parameters. */
4837 ha->flags.disable_risc_code_load = 0;
4838 ha->flags.enable_lip_reset = 0;
4839 ha->flags.enable_lip_full_login =
4840 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4841 ha->flags.enable_target_reset =
4842 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4843 ha->flags.enable_led_scheme = 0;
4844 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4845
4846 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4847 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4848
4849 /* save HBA serial number */
4850 ha->serial0 = icb->port_name[5];
4851 ha->serial1 = icb->port_name[6];
4852 ha->serial2 = icb->port_name[7];
4853 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4854 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4855
4856 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4857
4858 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4859
4860 /* Set minimum login_timeout to 4 seconds. */
4861 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4862 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4863 if (le16_to_cpu(nv->login_timeout) < 4)
4864 nv->login_timeout = __constant_cpu_to_le16(4);
4865 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4866 icb->login_timeout = nv->login_timeout;
4867
4868 /* Set minimum RATOV to 100 tenths of a second. */
4869 ha->r_a_tov = 100;
4870
4871 ha->loop_reset_delay = nv->reset_delay;
4872
4873 /* Link Down Timeout = 0:
4874 *
4875 * When Port Down timer expires we will start returning
4876 * I/O's to OS with "DID_NO_CONNECT".
4877 *
4878 * Link Down Timeout != 0:
4879 *
4880 * The driver waits for the link to come up after link down
4881 * before returning I/Os to OS with "DID_NO_CONNECT".
4882 */
4883 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4884 ha->loop_down_abort_time =
4885 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4886 } else {
4887 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4888 ha->loop_down_abort_time =
4889 (LOOP_DOWN_TIME - ha->link_down_timeout);
4890 }
4891
4892 /* Need enough time to try and get the port back. */
4893 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4894 if (qlport_down_retry)
4895 ha->port_down_retry_count = qlport_down_retry;
4896
4897 /* Set login_retry_count */
4898 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4899 if (ha->port_down_retry_count ==
4900 le16_to_cpu(nv->port_down_retry_count) &&
4901 ha->port_down_retry_count > 3)
4902 ha->login_retry_count = ha->port_down_retry_count;
4903 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4904 ha->login_retry_count = ha->port_down_retry_count;
4905 if (ql2xloginretrycount)
4906 ha->login_retry_count = ql2xloginretrycount;
4907
4908 /* Enable ZIO. */
4909 if (!vha->flags.init_done) {
4910 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4911 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4912 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4913 le16_to_cpu(icb->interrupt_delay_timer): 2;
4914 }
4915 icb->firmware_options_2 &= __constant_cpu_to_le32(
4916 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4917 vha->flags.process_response_queue = 0;
4918 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4919 ha->zio_mode = QLA_ZIO_MODE_6;
4920
4921 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4922 "(%d us).\n", vha->host_no, ha->zio_mode,
4923 ha->zio_timer * 100));
4924 qla_printk(KERN_INFO, ha,
4925 "ZIO mode %d enabled; timer delay (%d us).\n",
4926 ha->zio_mode, ha->zio_timer * 100);
4927
4928 icb->firmware_options_2 |= cpu_to_le32(
4929 (uint32_t)ha->zio_mode);
4930 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4931 vha->flags.process_response_queue = 1;
4932 }
4933
4934 if (rval) {
4935 DEBUG2_3(printk(KERN_WARNING
4936 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4937 }
4938 return (rval);
4939}
4940
Giridhar Malavalia9083012010-04-12 17:59:55 -07004941int
4942qla82xx_restart_isp(scsi_qla_host_t *vha)
4943{
4944 int status, rval;
4945 uint32_t wait_time;
4946 struct qla_hw_data *ha = vha->hw;
4947 struct req_que *req = ha->req_q_map[0];
4948 struct rsp_que *rsp = ha->rsp_q_map[0];
4949 struct scsi_qla_host *vp;
4950 struct scsi_qla_host *tvp;
4951
4952 status = qla2x00_init_rings(vha);
4953 if (!status) {
4954 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
4955 ha->flags.chip_reset_done = 1;
4956
4957 status = qla2x00_fw_ready(vha);
4958 if (!status) {
4959 qla_printk(KERN_INFO, ha,
4960 "%s(): Start configure loop, "
4961 "status = %d\n", __func__, status);
4962
4963 /* Issue a marker after FW becomes ready. */
4964 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
4965
4966 vha->flags.online = 1;
4967 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4968 wait_time = 256;
4969 do {
4970 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4971 qla2x00_configure_loop(vha);
4972 wait_time--;
4973 } while (!atomic_read(&vha->loop_down_timer) &&
4974 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
4975 wait_time &&
4976 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
4977 }
4978
4979 /* if no cable then assume it's good */
4980 if ((vha->device_flags & DFLG_NO_CABLE))
4981 status = 0;
4982
4983 qla_printk(KERN_INFO, ha,
4984 "%s(): Configure loop done, status = 0x%x\n",
4985 __func__, status);
4986 }
4987
4988 if (!status) {
4989 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
4990
4991 if (!atomic_read(&vha->loop_down_timer)) {
4992 /*
4993 * Issue marker command only when we are going
4994 * to start the I/O .
4995 */
4996 vha->marker_needed = 1;
4997 }
4998
4999 vha->flags.online = 1;
5000
5001 ha->isp_ops->enable_intrs(ha);
5002
5003 ha->isp_abort_cnt = 0;
5004 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5005
5006 if (ha->fce) {
5007 ha->flags.fce_enabled = 1;
5008 memset(ha->fce, 0,
5009 fce_calc_size(ha->fce_bufs));
5010 rval = qla2x00_enable_fce_trace(vha,
5011 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5012 &ha->fce_bufs);
5013 if (rval) {
5014 qla_printk(KERN_WARNING, ha,
5015 "Unable to reinitialize FCE "
5016 "(%d).\n", rval);
5017 ha->flags.fce_enabled = 0;
5018 }
5019 }
5020
5021 if (ha->eft) {
5022 memset(ha->eft, 0, EFT_SIZE);
5023 rval = qla2x00_enable_eft_trace(vha,
5024 ha->eft_dma, EFT_NUM_BUFFERS);
5025 if (rval) {
5026 qla_printk(KERN_WARNING, ha,
5027 "Unable to reinitialize EFT "
5028 "(%d).\n", rval);
5029 }
5030 }
5031 } else { /* failed the ISP abort */
5032 vha->flags.online = 1;
5033 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
5034 if (ha->isp_abort_cnt == 0) {
5035 qla_printk(KERN_WARNING, ha,
5036 "ISP error recovery failed - "
5037 "board disabled\n");
5038 /*
5039 * The next call disables the board
5040 * completely.
5041 */
5042 ha->isp_ops->reset_adapter(vha);
5043 vha->flags.online = 0;
5044 clear_bit(ISP_ABORT_RETRY,
5045 &vha->dpc_flags);
5046 status = 0;
5047 } else { /* schedule another ISP abort */
5048 ha->isp_abort_cnt--;
5049 qla_printk(KERN_INFO, ha,
5050 "qla%ld: ISP abort - "
5051 "retry remaining %d\n",
5052 vha->host_no, ha->isp_abort_cnt);
5053 status = 1;
5054 }
5055 } else {
5056 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
5057 qla_printk(KERN_INFO, ha,
5058 "(%ld): ISP error recovery "
5059 "- retrying (%d) more times\n",
5060 vha->host_no, ha->isp_abort_cnt);
5061 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5062 status = 1;
5063 }
5064 }
5065
5066 if (!status) {
5067 DEBUG(printk(KERN_INFO
5068 "qla82xx_restart_isp(%ld): succeeded.\n",
5069 vha->host_no));
5070 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
5071 if (vp->vp_idx)
5072 qla2x00_vp_abort_isp(vp);
5073 }
5074 } else {
5075 qla_printk(KERN_INFO, ha,
5076 "qla82xx_restart_isp: **** FAILED ****\n");
5077 }
5078
5079 return status;
5080}
5081
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005082void
Andrew Vasquezae97c912010-02-18 10:07:28 -08005083qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005084{
Andrew Vasquezae97c912010-02-18 10:07:28 -08005085 struct qla_hw_data *ha = vha->hw;
5086
5087 if (!ql2xetsenable)
5088 return;
5089
5090 /* Enable ETS Burst. */
5091 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5092 ha->fw_options[2] |= BIT_9;
5093 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005094}
Sarang Radke09ff7012010-03-19 17:03:59 -07005095
5096/*
5097 * qla24xx_get_fcp_prio
5098 * Gets the fcp cmd priority value for the logged in port.
5099 * Looks for a match of the port descriptors within
5100 * each of the fcp prio config entries. If a match is found,
5101 * the tag (priority) value is returned.
5102 *
5103 * Input:
5104 * ha = adapter block po
5105 * fcport = port structure pointer.
5106 *
5107 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005108 * non-zero (if found)
Sarang Radke09ff7012010-03-19 17:03:59 -07005109 * 0 (if not found)
5110 *
5111 * Context:
5112 * Kernel context
5113 */
5114uint8_t
5115qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5116{
5117 int i, entries;
5118 uint8_t pid_match, wwn_match;
5119 uint8_t priority;
5120 uint32_t pid1, pid2;
5121 uint64_t wwn1, wwn2;
5122 struct qla_fcp_prio_entry *pri_entry;
5123 struct qla_hw_data *ha = vha->hw;
5124
5125 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
5126 return 0;
5127
5128 priority = 0;
5129 entries = ha->fcp_prio_cfg->num_entries;
5130 pri_entry = &ha->fcp_prio_cfg->entry[0];
5131
5132 for (i = 0; i < entries; i++) {
5133 pid_match = wwn_match = 0;
5134
5135 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5136 pri_entry++;
5137 continue;
5138 }
5139
5140 /* check source pid for a match */
5141 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5142 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5143 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5144 if (pid1 == INVALID_PORT_ID)
5145 pid_match++;
5146 else if (pid1 == pid2)
5147 pid_match++;
5148 }
5149
5150 /* check destination pid for a match */
5151 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5152 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5153 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5154 if (pid1 == INVALID_PORT_ID)
5155 pid_match++;
5156 else if (pid1 == pid2)
5157 pid_match++;
5158 }
5159
5160 /* check source WWN for a match */
5161 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
5162 wwn1 = wwn_to_u64(vha->port_name);
5163 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
5164 if (wwn2 == (uint64_t)-1)
5165 wwn_match++;
5166 else if (wwn1 == wwn2)
5167 wwn_match++;
5168 }
5169
5170 /* check destination WWN for a match */
5171 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
5172 wwn1 = wwn_to_u64(fcport->port_name);
5173 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
5174 if (wwn2 == (uint64_t)-1)
5175 wwn_match++;
5176 else if (wwn1 == wwn2)
5177 wwn_match++;
5178 }
5179
5180 if (pid_match == 2 || wwn_match == 2) {
5181 /* Found a matching entry */
5182 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
5183 priority = pri_entry->tag;
5184 break;
5185 }
5186
5187 pri_entry++;
5188 }
5189
5190 return priority;
5191}
5192
5193/*
5194 * qla24xx_update_fcport_fcp_prio
5195 * Activates fcp priority for the logged in fc port
5196 *
5197 * Input:
5198 * ha = adapter block pointer.
5199 * fcp = port structure pointer.
5200 *
5201 * Return:
5202 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5203 *
5204 * Context:
5205 * Kernel context.
5206 */
5207int
5208qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *ha, fc_port_t *fcport)
5209{
5210 int ret;
5211 uint8_t priority;
5212 uint16_t mb[5];
5213
5214 if (atomic_read(&fcport->state) == FCS_UNCONFIGURED ||
5215 fcport->port_type != FCT_TARGET ||
5216 fcport->loop_id == FC_NO_LOOP_ID)
5217 return QLA_FUNCTION_FAILED;
5218
5219 priority = qla24xx_get_fcp_prio(ha, fcport);
5220 ret = qla24xx_set_fcp_prio(ha, fcport->loop_id, priority, mb);
5221 if (ret == QLA_SUCCESS)
5222 fcport->fcp_prio = priority;
5223 else
5224 DEBUG2(printk(KERN_WARNING
5225 "scsi(%ld): Unable to activate fcp priority, "
5226 " ret=0x%x\n", ha->host_no, ret));
5227
5228 return ret;
5229}
5230
5231/*
5232 * qla24xx_update_all_fcp_prio
5233 * Activates fcp priority for all the logged in ports
5234 *
5235 * Input:
5236 * ha = adapter block pointer.
5237 *
5238 * Return:
5239 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5240 *
5241 * Context:
5242 * Kernel context.
5243 */
5244int
5245qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
5246{
5247 int ret;
5248 fc_port_t *fcport;
5249
5250 ret = QLA_FUNCTION_FAILED;
5251 /* We need to set priority for all logged in ports */
5252 list_for_each_entry(fcport, &vha->vp_fcports, list)
5253 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
5254
5255 return ret;
5256}